TYPO3 CMS  TYPO3_7-6
SortPagesWizardModuleFunction.php
Go to the documentation of this file.
1 <?php
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 
24 
29 {
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 = $this->pObj->doc->header($lang->getLL('wiz_sort'));
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  $tce->stripslashes_values = 0;
58  $menuItems = array_reverse($menuItems);
59  $cmd = [];
60  foreach ($menuItems as $r) {
61  $cmd['pages'][$r['uid']]['move'] = $this->pObj->id;
62  }
63  $tce->start([], $cmd);
64  $tce->process_cmdmap();
65  BackendUtility::setUpdateSignal('updatePageTree');
66  }
67  }
68  $menuItems = $sys_pages->getMenu($this->pObj->id, '*', 'sorting', '', false);
69 
70  if (!empty($menuItems)) {
71  $lines = [];
72  $lines[] = '<thead><tr>';
73  $lines[] = '<th>' . $lang->getLL('wiz_changeOrder_title') . '</th>';
74  $lines[] = '<th>' . $lang->getLL('wiz_changeOrder_subtitle') . '</th>';
75  $lines[] = '<th>' . $lang->getLL('wiz_changeOrder_tChange') . '</th>';
76  $lines[] = '<th>' . $lang->getLL('wiz_changeOrder_tCreate') . '</th>';
77  $lines[] = '</tr></thead>';
78 
79  $iconFactory = GeneralUtility::makeInstance(IconFactory::class);
80  foreach ($menuItems as $rec) {
81  $m_perms_clause = $this->getBackendUser()->getPagePermsClause(2);
82  // edit permissions for that page!
83  $pRec = BackendUtility::getRecord('pages', $rec['uid'], 'uid', ' AND ' . $m_perms_clause);
84  $lines[] = '<tr><td nowrap="nowrap">' . $iconFactory->getIconForRecord('pages', $rec, Icon::SIZE_SMALL)->render() . (!is_array($pRec) ? '<strong class="text-danger">' . $lang->getLL('wiz_W', true) . '</strong></span> ' : '') . htmlspecialchars(GeneralUtility::fixed_lgd_cs($rec['title'], $GLOBALS['BE_USER']->uc['titleLen'])) . '</td>
85  <td nowrap="nowrap">' . htmlspecialchars(GeneralUtility::fixed_lgd_cs($rec['subtitle'], $this->getBackendUser()->uc['titleLen'])) . '</td>
86  <td nowrap="nowrap">' . BackendUtility::datetime($rec['tstamp']) . '</td>
87  <td nowrap="nowrap">' . BackendUtility::datetime($rec['crdate']) . '</td>
88  </tr>';
89  }
90  $theCode .= '<h2>' . $lang->getLL('wiz_currentPageOrder', true) . '</h2>';
91  $theCode .= '<div class="table-fit"><table class="table table-striped table-hover">' . implode('', $lines) . '</table></div>';
92 
93  // Menu:
94  $lines = [];
95  $lines[] = $this->wiz_linkOrder($lang->getLL('wiz_changeOrder_title'), 'title');
96  $lines[] = $this->wiz_linkOrder($lang->getLL('wiz_changeOrder_subtitle'), 'subtitle');
97  $lines[] = $this->wiz_linkOrder($lang->getLL('wiz_changeOrder_tChange'), 'tstamp');
98  $lines[] = $this->wiz_linkOrder($lang->getLL('wiz_changeOrder_tCreate'), 'crdate');
99  $lines[] = '';
100  $lines[] = $this->wiz_linkOrder($lang->getLL('wiz_changeOrder_REVERSE'), 'REV');
101  $theCode .= '<h4>' . $lang->getLL('wiz_changeOrder') . '</h4><p>' . implode(' ', $lines) . '</p>';
102  } else {
103  $flashMessage = GeneralUtility::makeInstance(FlashMessage::class, $lang->getLL('no_subpages'), '', FlashMessage::NOTICE);
105  $flashMessageService = GeneralUtility::makeInstance(FlashMessageService::class);
107  $defaultFlashMessageQueue = $flashMessageService->getMessageQueueByIdentifier();
108  $defaultFlashMessageQueue->enqueue($flashMessage);
109  }
110  // CSH:
111  $theCode .= BackendUtility::cshItem('_MOD_web_func', 'tx_wizardsortpages', null, '<span class="btn btn-default btn-sm">|</span>');
112  $out .= '<div>' . $theCode . '</div>';
113  } else {
114  $out .= '<div>Sorry, this function is not available in the current draft workspace!</div>';
115  }
116  return $out;
117  }
118 
126  protected function wiz_linkOrder($title, $order)
127  {
128  $href = BackendUtility::getModuleUrl('web_func',
129  [
130  'id' => $GLOBALS['SOBE']->id,
131  'sortByField' => $order
132  ]
133  );
134  return '<a class="btn btn-default t3js-modal-trigger" href="' . htmlspecialchars($href) . '" '
135  . ' data-severity="warning"'
136  . ' data-title="' . $this->getLanguageService()->sL('LLL:EXT:lang/locallang_common.xlf:pleaseConfirm', true) . '"'
137  . ' data-button-close-text="' . $this->getLanguageService()->sL('LLL:EXT:lang/locallang_common.xlf:cancel', true) . '"'
138  . ' data-content="' . $this->getLanguageService()->getLL('wiz_changeOrder_msg1', true) . '"'
139  . ' >' . htmlspecialchars($title) . '</a>';
140  }
141 
147  protected function getLanguageService()
148  {
149  return $GLOBALS['LANG'];
150  }
151 
157  protected function getBackendUser()
158  {
159  return $GLOBALS['BE_USER'];
160  }
161 }
static setUpdateSignal($set='', $params='')
static cshItem($table, $field, $_='', $wrap='')
static fixed_lgd_cs($string, $chars, $appendString='...')
static getRecord($table, $uid, $fields=' *', $where='', $useDeleteClause=true)
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']