4cb2db0e033b1cf5f2407e90e4e5bcf1e5d9fb9a
[Packages/TYPO3.CMS.git] / typo3 / sysext / wizard_sortpages / Classes / View / SortPagesWizardModuleFunction.php
1 <?php
2 namespace TYPO3\CMS\WizardSortpages\View;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 use TYPO3\CMS\Backend\Utility\BackendUtility;
18 use TYPO3\CMS\Core\Imaging\Icon;
19 use TYPO3\CMS\Core\Imaging\IconFactory;
20 use TYPO3\CMS\Core\Messaging\FlashMessage;
21 use TYPO3\CMS\Core\Messaging\FlashMessageService;
22 use TYPO3\CMS\Core\Page\PageRenderer;
23 use TYPO3\CMS\Core\Utility\GeneralUtility;
24
25 /**
26 * Creates the "Sort pages" wizard
27 */
28 class SortPagesWizardModuleFunction extends \TYPO3\CMS\Backend\Module\AbstractFunctionModule
29 {
30 /**
31 * Main function creating the content for the module.
32 *
33 * @return string HTML content for the module, actually a "section" made through the parent object in $this->pObj
34 */
35 public function main()
36 {
37 $lang = $this->getLanguageService();
38 $lang->includeLLFile('EXT:wizard_sortpages/Resources/Private/Language/locallang.xlf');
39 $pageRenderer = GeneralUtility::makeInstance(PageRenderer::class);
40 $pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/Modal');
41 $out = '<h1>' . htmlspecialchars($lang->getLL('wiz_sort')) . '</h1>';
42 if ($this->getBackendUser()->workspace === 0) {
43 $theCode = '';
44 // Check if user has modify permissions to
45 $sys_pages = GeneralUtility::makeInstance(\TYPO3\CMS\Frontend\Page\PageRepository::class);
46 $sortByField = GeneralUtility::_GP('sortByField');
47 if ($sortByField) {
48 $menuItems = [];
49 if ($sortByField === 'title' || $sortByField === 'subtitle' || $sortByField === 'crdate' || $sortByField === 'tstamp') {
50 $menuItems = $sys_pages->getMenu($this->pObj->id, 'uid,pid,title', $sortByField, '', false);
51 } elseif ($sortByField === 'REV') {
52 $menuItems = $sys_pages->getMenu($this->pObj->id, 'uid,pid,title', 'sorting', '', false);
53 $menuItems = array_reverse($menuItems);
54 }
55 if (!empty($menuItems)) {
56 $tce = GeneralUtility::makeInstance(\TYPO3\CMS\Core\DataHandling\DataHandler::class);
57 $menuItems = array_reverse($menuItems);
58 $cmd = [];
59 foreach ($menuItems as $r) {
60 $cmd['pages'][$r['uid']]['move'] = $this->pObj->id;
61 }
62 $tce->start([], $cmd);
63 $tce->process_cmdmap();
64 BackendUtility::setUpdateSignal('updatePageTree');
65 }
66 }
67 $menuItems = $sys_pages->getMenu($this->pObj->id, '*', 'sorting', '', false);
68
69 if (!empty($menuItems)) {
70 $lines = [];
71 $lines[] = '<thead><tr>';
72 $lines[] = '<th>' . $lang->getLL('wiz_changeOrder_title') . '</th>';
73 $lines[] = '<th>' . $lang->getLL('wiz_changeOrder_subtitle') . '</th>';
74 $lines[] = '<th>' . $lang->getLL('wiz_changeOrder_tChange') . '</th>';
75 $lines[] = '<th>' . $lang->getLL('wiz_changeOrder_tCreate') . '</th>';
76 $lines[] = '</tr></thead>';
77
78 $iconFactory = GeneralUtility::makeInstance(IconFactory::class);
79 foreach ($menuItems as $rec) {
80 $m_perms_clause = $this->getBackendUser()->getPagePermsClause(2);
81 // edit permissions for that page!
82 $pRec = BackendUtility::getRecord('pages', $rec['uid'], 'uid', ' AND ' . $m_perms_clause);
83 $lines[] = '<tr><td nowrap="nowrap">' . $iconFactory->getIconForRecord('pages', $rec, Icon::SIZE_SMALL)->render() . (!is_array($pRec) ? '<strong class="text-danger">' . htmlspecialchars($lang->getLL('wiz_W')) . '</strong></span> ' : '') . htmlspecialchars(GeneralUtility::fixed_lgd_cs($rec['title'], $GLOBALS['BE_USER']->uc['titleLen'])) . '</td>
84 <td nowrap="nowrap">' . htmlspecialchars(GeneralUtility::fixed_lgd_cs($rec['subtitle'], $this->getBackendUser()->uc['titleLen'])) . '</td>
85 <td nowrap="nowrap">' . BackendUtility::datetime($rec['tstamp']) . '</td>
86 <td nowrap="nowrap">' . BackendUtility::datetime($rec['crdate']) . '</td>
87 </tr>';
88 }
89 $theCode .= '<h2>' . htmlspecialchars($lang->getLL('wiz_currentPageOrder')) . '</h2>';
90 $theCode .= '<div class="table-fit"><table class="table table-striped table-hover">' . implode('', $lines) . '</table></div>';
91
92 // Menu:
93 $lines = [];
94 $lines[] = $this->wiz_linkOrder($lang->getLL('wiz_changeOrder_title'), 'title');
95 $lines[] = $this->wiz_linkOrder($lang->getLL('wiz_changeOrder_subtitle'), 'subtitle');
96 $lines[] = $this->wiz_linkOrder($lang->getLL('wiz_changeOrder_tChange'), 'tstamp');
97 $lines[] = $this->wiz_linkOrder($lang->getLL('wiz_changeOrder_tCreate'), 'crdate');
98 $lines[] = '';
99 $lines[] = $this->wiz_linkOrder($lang->getLL('wiz_changeOrder_REVERSE'), 'REV');
100 $theCode .= '<h4>' . $lang->getLL('wiz_changeOrder') . '</h4><p>' . implode(' ', $lines) . '</p>';
101 } else {
102 $flashMessage = GeneralUtility::makeInstance(FlashMessage::class, $lang->getLL('no_subpages'), '', FlashMessage::NOTICE);
103 /** @var $flashMessageService \TYPO3\CMS\Core\Messaging\FlashMessageService */
104 $flashMessageService = GeneralUtility::makeInstance(FlashMessageService::class);
105 /** @var $defaultFlashMessageQueue \TYPO3\CMS\Core\Messaging\FlashMessageQueue */
106 $defaultFlashMessageQueue = $flashMessageService->getMessageQueueByIdentifier();
107 $defaultFlashMessageQueue->enqueue($flashMessage);
108 }
109 // CSH:
110 $theCode .= BackendUtility::cshItem('_MOD_web_func', 'tx_wizardsortpages', null, '<span class="btn btn-default btn-sm">|</span>');
111 $out .= '<div>' . $theCode . '</div>';
112 } else {
113 $out .= '<div>' . htmlspecialchars($lang->getLL('not_available_in_draft_workspace')) . '</div>';
114 }
115 return $out;
116 }
117
118 /**
119 * Creates a link for the sorting order
120 *
121 * @param string $title Title of the link
122 * @param string $order Field to sort by
123 * @return string HTML string
124 */
125 protected function wiz_linkOrder($title, $order)
126 {
127 $href = BackendUtility::getModuleUrl('web_func',
128 [
129 'id' => $GLOBALS['SOBE']->id,
130 'sortByField' => $order
131 ]
132 );
133 return '<a class="btn btn-default t3js-modal-trigger" href="' . htmlspecialchars($href) . '" '
134 . ' data-severity="warning"'
135 . ' data-title="' . htmlspecialchars($this->getLanguageService()->sL('LLL:EXT:lang/locallang_common.xlf:pleaseConfirm')) . '"'
136 . ' data-button-close-text="' . htmlspecialchars($this->getLanguageService()->sL('LLL:EXT:lang/locallang_common.xlf:cancel')) . '"'
137 . ' data-content="' . htmlspecialchars($this->getLanguageService()->getLL('wiz_changeOrder_msg1')) . '"'
138 . ' >' . htmlspecialchars($title) . '</a>';
139 }
140
141 /**
142 * Returns LanguageService
143 *
144 * @return \TYPO3\CMS\Lang\LanguageService
145 */
146 protected function getLanguageService()
147 {
148 return $GLOBALS['LANG'];
149 }
150
151 /**
152 * Returns the current BE user.
153 *
154 * @return \TYPO3\CMS\Core\Authentication\BackendUserAuthentication
155 */
156 protected function getBackendUser()
157 {
158 return $GLOBALS['BE_USER'];
159 }
160 }