[TASK] Replace icon by the IconFactory actions-system-refresh
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Classes / Controller / PageTreeNavigationController.php
1 <?php
2 namespace TYPO3\CMS\Backend\Controller;
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\Template\DocumentTemplate;
18 use TYPO3\CMS\Backend\Utility\BackendUtility;
19 use TYPO3\CMS\Backend\Utility\IconUtility;
20 use TYPO3\CMS\Backend\View\PageTreeView;
21 use TYPO3\CMS\Core\Imaging\Icon;
22 use TYPO3\CMS\Core\Imaging\IconFactory;
23 use TYPO3\CMS\Core\Messaging\FlashMessage;
24 use TYPO3\CMS\Core\Page\PageRenderer;
25 use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
26 use TYPO3\CMS\Core\Utility\GeneralUtility;
27 use TYPO3\CMS\Core\Utility\MathUtility;
28 use TYPO3\CMS\Workspaces\Service\WorkspaceService;
29
30 /**
31 * Main script class for the page tree navigation frame
32 * This is the class for rendering the "page tree" navigation frame without ExtJS, used prior to TYPO3 CMS 4.5.
33 * This functionality is deprecated since TYPO3 CMS 7, and will be removed with TYPO3 CMS 8
34 */
35 class PageTreeNavigationController {
36
37 /**
38 * @var string
39 */
40 public $content;
41
42 /**
43 * @var \TYPO3\CMS\Backend\View\PageTreeView
44 */
45 public $pagetree;
46
47 /**
48 * document template object
49 *
50 * @var \TYPO3\CMS\Backend\Template\DocumentTemplate
51 */
52 public $doc;
53
54 /**
55 * Temporary mount point (record), if any
56 *
57 * @var int
58 */
59 public $active_tempMountPoint = 0;
60
61 /**
62 * @var string
63 */
64 public $currentSubScript;
65
66 /**
67 * @var bool
68 */
69 public $cMR;
70
71 /**
72 * If not '' (blank) then it will clear (0) or set (>0) Temporary DB mount.
73 *
74 * @var string
75 */
76 public $setTempDBmount;
77
78 /**
79 * @var string
80 * @deprecated since TYPO3 CMS 7, will be removed in TYPO3 CMS 8
81 */
82 public $template;
83
84 /**
85 * Constructor
86 */
87 public function __construct() {
88 GeneralUtility::deprecationLog('PageTreeNavigationController is deprecated in favor of new pagetrees');
89 $GLOBALS['SOBE'] = $this;
90 $this->init();
91 }
92
93 /**
94 * Initialization of the class
95 *
96 * @return void
97 */
98 protected function init() {
99 // Setting GPvars:
100 $this->cMR = (bool)GeneralUtility::_GP('cMR');
101 $this->currentSubScript = GeneralUtility::_GP('currentSubScript');
102 $this->setTempDBmount = GeneralUtility::_GP('setTempDBmount');
103 // Create page tree object:
104 $beUser = $this->getBackendUser();
105 $this->pagetree = GeneralUtility::makeInstance(PageTreeView::class);
106 $this->pagetree->ext_IconMode = $beUser->getTSConfigVal('options.pageTree.disableIconLinkToContextmenu');
107 $this->pagetree->ext_showPageId = (bool)$beUser->getTSConfigVal('options.pageTree.showPageIdWithTitle');
108 $this->pagetree->ext_showNavTitle = (bool)$beUser->getTSConfigVal('options.pageTree.showNavTitle');
109 $this->pagetree->ext_separateNotinmenuPages = $beUser->getTSConfigVal('options.pageTree.separateNotinmenuPages');
110 $this->pagetree->ext_alphasortNotinmenuPages = $beUser->getTSConfigVal('options.pageTree.alphasortNotinmenuPages');
111 $this->pagetree->thisScript = 'alt_db_navframe.php';
112 $this->pagetree->addField('alias');
113 $this->pagetree->addField('shortcut');
114 $this->pagetree->addField('shortcut_mode');
115 $this->pagetree->addField('mount_pid');
116 $this->pagetree->addField('mount_pid_ol');
117 $this->pagetree->addField('url');
118 // Temporary DB mounts:
119 $this->initializeTemporaryDBmount();
120 }
121
122 /**
123 * Initialization for the visual parts of the class
124 * Use template rendering only if this is a non-AJAX call
125 *
126 * @return void
127 */
128 public function initPage() {
129 // Setting highlight mode:
130 $doHighlight = !$this->getBackendUser()->getTSConfigVal('options.pageTree.disableTitleHighlight');
131 // Create template object:
132 $this->doc = GeneralUtility::makeInstance(DocumentTemplate::class);
133 $this->doc->setModuleTemplate('EXT:backend/Resources/Private/Templates/alt_db_navframe.html');
134 $this->doc->showFlashMessages = FALSE;
135 // Get HTML-Template
136
137 // Adding javascript for drag & drop activation and highlighting
138 $dragDropCode = 'Tree.registerDragDropHandlers();';
139
140 // If highlighting is active, define the CSS class for the active item depending on the workspace
141 if ($doHighlight) {
142 $hlClass = $this->getBackendUser()->workspace === 0 ? 'active' : 'active active-ws wsver' . $this->getBackendUser()->workspace;
143 $dragDropCode .= '
144 Tree.highlightClass = "' . $hlClass . '";
145 Tree.highlightActiveItem("",top.fsMod.navFrameHighlightedID["web"]);';
146 }
147 // Adding javascript code for drag&drop and the pagetree as well as the click menu code
148 $this->doc->getDragDropCode('pages', $dragDropCode);
149 $this->doc->getContextMenuCode();
150 /** @var $pageRenderer PageRenderer */
151 $pageRenderer = GeneralUtility::makeInstance(PageRenderer::class);
152 $pageRenderer->loadExtJS();
153 $this->doc->JScode .= $this->doc->wrapScriptTags(($this->currentSubScript ? 'top.currentSubScript=unescape("' . rawurlencode($this->currentSubScript) . '");' : '') . '
154 // Function, loading the list frame from navigation tree:
155 function jumpTo(id, linkObj, highlightID, bank) { //
156 var theUrl = top.currentSubScript ;
157 if (theUrl.indexOf("?") != -1) {
158 theUrl += "&id=" + id
159 } else {
160 theUrl += "?id=" + id
161 }
162 top.fsMod.currentBank = bank;
163 top.TYPO3.Backend.ContentContainer.setUrl(theUrl);
164
165 ' . ($doHighlight ? 'Tree.highlightActiveItem("web", highlightID + "_" + bank);' : '') . '
166 if (linkObj) { linkObj.blur(); }
167 return false;
168 }
169 ' . ($this->cMR ? 'jumpTo(top.fsMod.recentIds[\'web\'],\'\');' : '') . '
170
171 ');
172 $this->doc->bodyTagId = 'typo3-pagetree';
173 }
174
175 /**
176 * Main function, rendering the browsable page tree
177 *
178 * @return void
179 */
180 public function main() {
181 // Produce browse-tree:
182 $tree = $this->pagetree->getBrowsableTree();
183 // Outputting Temporary DB mount notice:
184 if ($this->active_tempMountPoint) {
185 $flashText = '
186 <a href="' . htmlspecialchars(GeneralUtility::linkThisScript(array('setTempDBmount' => 0))) . '">' . $this->getLanguageService()->sl('LLL:EXT:lang/locallang_core.xlf:labels.temporaryDBmount', TRUE) . '</a> <br />' . $this->getLanguageService()->sl('LLL:EXT:lang/locallang_core.xlf:labels.path', TRUE) . ': <span title="' . htmlspecialchars($this->active_tempMountPoint['_thePathFull']) . '">' . htmlspecialchars(GeneralUtility::fixed_lgd_cs($this->active_tempMountPoint['_thePath'], -50)) . '</span>
187 ';
188 $flashMessage = GeneralUtility::makeInstance(FlashMessage::class, $flashText, '', FlashMessage::INFO);
189 $this->content .= $flashMessage->render();
190 }
191 // Outputting page tree:
192 $this->content .= '<div id="PageTreeDiv">' . $tree . '</div>';
193 // Setting up the buttons and markers for docheader
194 $docHeaderButtons = $this->getButtons();
195 $markers = array(
196 'WORKSPACEINFO' => $this->getWorkspaceInfo(),
197 'CONTENT' => $this->content
198 );
199 // Build the <body> for the module
200 $this->content = $this->doc->startPage('TYPO3 Page Tree');
201 $this->content .= $this->doc->moduleBody(array(), $docHeaderButtons, $markers);
202 $this->content .= $this->doc->endPage();
203 $this->content = $this->doc->insertStylesAndJS($this->content);
204 }
205
206 /**
207 * Outputting the accumulated content to screen
208 *
209 * @return void
210 */
211 public function printContent() {
212 echo $this->content;
213 }
214
215 /**
216 * Create the panel of buttons for submitting the form or otherwise perform operations.
217 *
218 * @return array All available buttons as an assoc. array
219 */
220 protected function getButtons() {
221 $buttons = array(
222 'csh' => '',
223 'new_page' => '',
224 'refresh' => ''
225 );
226 $iconFactory = GeneralUtility::makeInstance(IconFactory::class);
227 // New Page
228 $onclickNewPageWizard = 'top.content.list_frame.location.href=' . GeneralUtility::quoteJSvalue(BackendUtility::getModuleUrl('db_new', ['pagesOnly' => 1, 'id' => ''])) . '+Tree.pageID;';
229 $buttons['new_page'] = '<a href="#" onclick="' . $onclickNewPageWizard . '" title="' . $this->getLanguageService()->sL('LLL:EXT:backend/Resources/Private/Language/locallang_layout.xlf:newPage', TRUE) . '">' . IconUtility::getSpriteIcon('actions-page-new') . '</a>';
230 // Refresh
231 $buttons['refresh'] = '<a href="' . htmlspecialchars(GeneralUtility::getIndpEnv('REQUEST_URI')) . '" title="' . $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:labels.refresh', TRUE) . '">' . $iconFactory->getIcon('actions-system-refresh', Icon::SIZE_SMALL)->render() . '</a>';
232 // CSH
233 $buttons['csh'] = str_replace('typo3-csh-inline', 'typo3-csh-inline show-right', BackendUtility::cshItem('xMOD_csh_corebe', 'pagetree'));
234 return $buttons;
235 }
236
237 /**
238 * Create the workspace information
239 *
240 * @return string HTML containing workspace info
241 */
242 protected function getWorkspaceInfo() {
243 if (ExtensionManagementUtility::isLoaded('workspaces') && ($this->getBackendUser()->workspace !== 0 || $this->getBackendUser()->getTSConfigVal('options.pageTree.onlineWorkspaceInfo'))) {
244 $wsTitle = htmlspecialchars(WorkspaceService::getWorkspaceTitle($this->getBackendUser()->workspace));
245 $workspaceInfo = '
246 <div class="bgColor4 workspace-info">' . IconUtility::getSpriteIcon('apps-toolbar-menu-workspace', array(
247 'title' => $wsTitle,
248 'onclick' => 'top.goToModule(\'web_WorkspacesWorkspaces\');',
249 'style' => 'cursor:pointer;'
250 )) . $wsTitle . '</div>
251 ';
252 } else {
253 $workspaceInfo = '';
254 }
255 return $workspaceInfo;
256 }
257
258 /**********************************
259 *
260 * Temporary DB mounts
261 *
262 **********************************/
263 /**
264 * Getting temporary DB mount
265 *
266 * @return void
267 */
268 public function initializeTemporaryDBmount() {
269 $beUser = $this->getBackendUser();
270 // Set/Cancel Temporary DB Mount:
271 if ((string)$this->setTempDBmount !== '') {
272 $set = MathUtility::forceIntegerInRange($this->setTempDBmount, 0);
273 if ($set > 0 && $beUser->isInWebMount($set)) {
274 // Setting...:
275 $this->settingTemporaryMountPoint($set);
276 } else {
277 // Clear:
278 $this->settingTemporaryMountPoint(0);
279 }
280 }
281 // Getting temporary mount point ID:
282 $temporaryMountPoint = (int)$beUser->getSessionData('pageTree_temporaryMountPoint');
283 // If mount point ID existed and is within users real mount points, then set it temporarily:
284 if ($temporaryMountPoint > 0 && $beUser->isInWebMount($temporaryMountPoint)) {
285 if ($this->active_tempMountPoint = BackendUtility::readPageAccess($temporaryMountPoint, $beUser->getPagePermsClause(1))) {
286 $this->pagetree->MOUNTS = array($temporaryMountPoint);
287 } else {
288 // Clear temporary mount point as we have no access to it any longer
289 $this->settingTemporaryMountPoint(0);
290 }
291 }
292 }
293
294 /**
295 * Setting temporary page id as DB mount
296 *
297 * @param int $pageId The page id to set as DB mount
298 * @return void
299 */
300 public function settingTemporaryMountPoint($pageId) {
301 $this->getBackendUser()->setAndSaveSessionData('pageTree_temporaryMountPoint', (int)$pageId);
302 }
303
304 /**********************************
305 *
306 * AJAX Calls
307 *
308 **********************************/
309 /**
310 * Makes the AJAX call to expand or collapse the pagetree.
311 * Called by typo3/ajax.php
312 *
313 * @param array $params Additional parameters (not used here)
314 * @param \TYPO3\CMS\Core\Http\AjaxRequestHandler $ajaxObj The AjaxRequestHandler object of this request
315 * @return void
316 */
317 public function ajaxExpandCollapse($params, $ajaxObj) {
318 $this->init();
319 $tree = $this->pagetree->getBrowsableTree();
320 if (!$this->pagetree->ajaxStatus) {
321 $ajaxObj->setError($tree);
322 } else {
323 $ajaxObj->addContent('tree', $tree);
324 }
325 }
326
327 /**
328 * Returns LanguageService
329 *
330 * @return \TYPO3\CMS\Lang\LanguageService
331 */
332 protected function getLanguageService() {
333 return $GLOBALS['LANG'];
334 }
335
336 /**
337 * Returns the current BE user.
338 *
339 * @return \TYPO3\CMS\Core\Authentication\BackendUserAuthentication
340 */
341 protected function getBackendUser() {
342 return $GLOBALS['BE_USER'];
343 }
344
345 }