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