8c1db8f24f6fa603dc52f5c395f18eb69e61f4e8
[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
19 /**
20 * Creates the "Sort pages" wizard
21 *
22 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
23 */
24 class SortPagesWizardModuleFunction extends \TYPO3\CMS\Backend\Module\AbstractFunctionModule {
25
26 /**
27 * Adds menu items... but I think this is not used at all. Looks very much like some testing code. If anyone cares to check it we can remove it some day...
28 *
29 * @return array
30 * @ignore
31 * @todo Define visibility
32 */
33 public function modMenu() {
34 global $LANG;
35 $modMenuAdd = array();
36 return $modMenuAdd;
37 }
38
39 /**
40 * Main function creating the content for the module.
41 *
42 * @return string HTML content for the module, actually a "section" made through the parent object in $this->pObj
43 * @todo Define visibility
44 */
45 public function main() {
46 $GLOBALS['LANG']->includeLLFile('EXT:wizard_sortpages/locallang.xlf');
47 $out = $this->pObj->doc->header($GLOBALS['LANG']->getLL('wiz_sort'));
48 if ($GLOBALS['BE_USER']->workspace === 0) {
49 $theCode = '';
50 // Check if user has modify permissions to
51 $sys_pages = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Frontend\\Page\\PageRepository');
52 $sortByField = \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('sortByField');
53 if ($sortByField) {
54 $menuItems = array();
55 if (\TYPO3\CMS\Core\Utility\GeneralUtility::inList('title,subtitle,crdate,tstamp', $sortByField)) {
56 $menuItems = $sys_pages->getMenu($this->pObj->id, 'uid,pid,title', $sortByField, '', FALSE);
57 } elseif ($sortByField == 'REV') {
58 $menuItems = $sys_pages->getMenu($this->pObj->id, 'uid,pid,title', 'sorting', '', FALSE);
59 $menuItems = array_reverse($menuItems);
60 }
61 if (count($menuItems)) {
62 $tce = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\DataHandling\\DataHandler');
63 $tce->stripslashes_values = 0;
64 $menuItems = array_reverse($menuItems);
65 $cmd = array();
66 foreach ($menuItems as $r) {
67 $cmd['pages'][$r['uid']]['move'] = $this->pObj->id;
68 }
69 $tce->start(array(), $cmd);
70 $tce->process_cmdmap();
71 BackendUtility::setUpdateSignal('updatePageTree');
72 }
73 }
74 $menuItems = $sys_pages->getMenu($this->pObj->id, '*', 'sorting', '', FALSE);
75
76 if (count($menuItems)) {
77 $lines = array();
78 $lines[] = '<thead><tr>';
79 $lines[] = '<th>' . $this->wiz_linkOrder($GLOBALS['LANG']->getLL('wiz_changeOrder_title'), 'title') . '</th>';
80 $lines[] = '<th> ' . $this->wiz_linkOrder($GLOBALS['LANG']->getLL('wiz_changeOrder_subtitle'), 'subtitle') . '</th>';
81 $lines[] = '<th>' . $this->wiz_linkOrder($GLOBALS['LANG']->getLL('wiz_changeOrder_tChange'), 'tstamp') . '</th>';
82 $lines[] = '<th>' . $this->wiz_linkOrder($GLOBALS['LANG']->getLL('wiz_changeOrder_tCreate'), 'crdate') . '</th>';
83 $lines[] = '</tr></thead>';
84
85 foreach ($menuItems as $rec) {
86 $m_perms_clause = $GLOBALS['BE_USER']->getPagePermsClause(2);
87 // edit permissions for that page!
88 $pRec = BackendUtility::getRecord('pages', $rec['uid'], 'uid', ' AND ' . $m_perms_clause);
89 $lines[] = '<tr class="db_list_normal"><td nowrap="nowrap">' . \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIconForRecord('pages', $rec) . (!is_array($pRec) ? $GLOBALS['TBE_TEMPLATE']->rfw('<strong>' . $GLOBALS['LANG']->getLL('wiz_W', TRUE) . '</strong> ') : '') . htmlspecialchars(\TYPO3\CMS\Core\Utility\GeneralUtility::fixed_lgd_cs($rec['title'], $GLOBALS['BE_USER']->uc['titleLen'])) . '</td>
90 <td nowrap="nowrap">' . htmlspecialchars(\TYPO3\CMS\Core\Utility\GeneralUtility::fixed_lgd_cs($rec['subtitle'], $GLOBALS['BE_USER']->uc['titleLen'])) . '</td>
91 <td nowrap="nowrap">' . BackendUtility::datetime($rec['tstamp']) . '</td>
92 <td nowrap="nowrap">' . BackendUtility::datetime($rec['crdate']) . '</td>
93 </tr>';
94 }
95 $theCode .= '<h2>' . $GLOBALS['LANG']->getLL('wiz_currentPageOrder', TRUE) . '</h2>';
96 $theCode .= '<table class="t3-table">' . implode('', $lines) . '</table>';
97
98 // Menu:
99 $lines = array();
100 $lines[] = $this->wiz_linkOrder($GLOBALS['LANG']->getLL('wiz_changeOrder_title'), 'title');
101 $lines[] = $this->wiz_linkOrder($GLOBALS['LANG']->getLL('wiz_changeOrder_subtitle'), 'subtitle');
102 $lines[] = $this->wiz_linkOrder($GLOBALS['LANG']->getLL('wiz_changeOrder_tChange'), 'tstamp');
103 $lines[] = $this->wiz_linkOrder($GLOBALS['LANG']->getLL('wiz_changeOrder_tCreate'), 'crdate');
104 $lines[] = '';
105 $lines[] = $this->wiz_linkOrder($GLOBALS['LANG']->getLL('wiz_changeOrder_REVERSE'), 'REV');
106 $theCode .= '<h4>' . $GLOBALS['LANG']->getLL('wiz_changeOrder') . '</h4>' . implode('<br />', $lines);
107 } else {
108 $flashMessage = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Messaging\\FlashMessage', $GLOBALS['LANG']->getLL('no_subpages'), '', \TYPO3\CMS\Core\Messaging\FlashMessage::NOTICE);
109 $theCode .= $flashMessage->render();
110 }
111 // CSH:
112 $theCode .= BackendUtility::cshItem('_MOD_web_func', 'tx_wizardsortpages', $GLOBALS['BACK_PATH'], '<br />|');
113 $out .= $this->pObj->doc->section('', $theCode, 0, 1);
114 } else {
115 $out .= $this->pObj->doc->section('', 'Sorry, this function is not available in the current draft workspace!', 0, 1, 1);
116 }
117 return $out;
118 }
119
120 /**
121 * Creates a link for the sorting order
122 *
123 * @param string $title Title of the link
124 * @param string $order Field to sort by
125 * @return string HTML string
126 * @todo Define visibility
127 */
128 public function wiz_linkOrder($title, $order) {
129 return '<a class="t3-link" href="' . htmlspecialchars(
130 BackendUtility::getModuleUrl('web_func',
131 array(
132 'id' => $GLOBALS['SOBE']->id,
133 'sortByField' => $order
134 )
135 )
136 ) . '" onclick="return confirm(' . \TYPO3\CMS\Core\Utility\GeneralUtility::quoteJSvalue($GLOBALS['LANG']->getLL('wiz_changeOrder_msg1')) . ')">' . htmlspecialchars($title) . '</a>';
137 }
138
139 }