TYPO3 CMS  TYPO3_7-6
PageTreeNavigationController.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 
30 
37 {
41  public $content;
42 
46  public $pagetree;
47 
53  public $doc;
54 
61 
66 
70  public $cMR;
71 
78 
83  public $template;
84 
88  protected $iconFactory;
89 
93  public function __construct()
94  {
95  $this->iconFactory = GeneralUtility::makeInstance(IconFactory::class);
96  GeneralUtility::deprecationLog('PageTreeNavigationController is deprecated in favor of new pagetrees');
97  $GLOBALS['SOBE'] = $this;
98  $this->init();
99  }
100 
106  protected function init()
107  {
108  // Setting GPvars:
109  $this->cMR = (bool)GeneralUtility::_GP('cMR');
110  $this->currentSubScript = GeneralUtility::_GP('currentSubScript');
111  $this->setTempDBmount = GeneralUtility::_GP('setTempDBmount');
112  // Create page tree object:
113  $beUser = $this->getBackendUser();
114  $this->pagetree = GeneralUtility::makeInstance(PageTreeView::class);
115  $this->pagetree->ext_IconMode = $beUser->getTSConfigVal('options.pageTree.disableIconLinkToContextmenu');
116  $this->pagetree->ext_showPageId = (bool)$beUser->getTSConfigVal('options.pageTree.showPageIdWithTitle');
117  $this->pagetree->ext_showNavTitle = (bool)$beUser->getTSConfigVal('options.pageTree.showNavTitle');
118  $this->pagetree->ext_separateNotinmenuPages = $beUser->getTSConfigVal('options.pageTree.separateNotinmenuPages');
119  $this->pagetree->ext_alphasortNotinmenuPages = $beUser->getTSConfigVal('options.pageTree.alphasortNotinmenuPages');
120  $this->pagetree->thisScript = 'alt_db_navframe.php';
121  $this->pagetree->addField('alias');
122  $this->pagetree->addField('shortcut');
123  $this->pagetree->addField('shortcut_mode');
124  $this->pagetree->addField('mount_pid');
125  $this->pagetree->addField('mount_pid_ol');
126  $this->pagetree->addField('url');
127  // Temporary DB mounts:
129  }
130 
137  public function initPage()
138  {
139  // Setting highlight mode:
140  $doHighlight = !$this->getBackendUser()->getTSConfigVal('options.pageTree.disableTitleHighlight');
141  // Create template object:
142  $this->doc = GeneralUtility::makeInstance(DocumentTemplate::class);
143  $this->doc->setModuleTemplate('EXT:backend/Resources/Private/Templates/alt_db_navframe.html');
144  $this->doc->showFlashMessages = false;
145  // Get HTML-Template
146 
147  // Adding javascript for drag & drop activation and highlighting
148  $dragDropCode = 'Tree.registerDragDropHandlers();';
149 
150  // If highlighting is active, define the CSS class for the active item depending on the workspace
151  if ($doHighlight) {
152  $hlClass = $this->getBackendUser()->workspace === 0 ? 'active' : 'active active-ws wsver' . $this->getBackendUser()->workspace;
153  $dragDropCode .= '
154  Tree.highlightClass = "' . $hlClass . '";
155  Tree.highlightActiveItem("",top.fsMod.navFrameHighlightedID["web"]);';
156  }
157  // Adding javascript code for drag&drop and the pagetree as well as the click menu code
158  $this->doc->getDragDropCode('pages', $dragDropCode);
159  $this->doc->getContextMenuCode();
161  $pageRenderer = GeneralUtility::makeInstance(PageRenderer::class);
162  $pageRenderer->loadExtJS();
163  $this->doc->JScode .= $this->doc->wrapScriptTags(($this->currentSubScript ? 'top.currentSubScript=unescape("' . rawurlencode($this->currentSubScript) . '");' : '') . '
164  // Function, loading the list frame from navigation tree:
165  function jumpTo(id, linkObj, highlightID, bank) { //
166  var theUrl = top.currentSubScript ;
167  if (theUrl.indexOf("?") != -1) {
168  theUrl += "&id=" + id
169  } else {
170  theUrl += "?id=" + id
171  }
172  top.fsMod.currentBank = bank;
173  top.TYPO3.Backend.ContentContainer.setUrl(theUrl);
174 
175  ' . ($doHighlight ? 'Tree.highlightActiveItem("web", highlightID + "_" + bank);' : '') . '
176  if (linkObj) { linkObj.blur(); }
177  return false;
178  }
179  ' . ($this->cMR ? 'jumpTo(top.fsMod.recentIds[\'web\'],\'\');' : '') . '
180 
181  ');
182  $this->doc->bodyTagId = 'typo3-pagetree';
183  }
184 
190  public function main()
191  {
192  // Produce browse-tree:
193  $tree = $this->pagetree->getBrowsableTree();
194  // Outputting Temporary DB mount notice:
195  if ($this->active_tempMountPoint) {
196  $flashText = '
197  <a href="' . htmlspecialchars(GeneralUtility::linkThisScript(['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>
198  ';
199  $flashMessage = GeneralUtility::makeInstance(FlashMessage::class, $flashText, '', FlashMessage::INFO);
200  $this->content .= $flashMessage->render();
201  }
202  // Outputting page tree:
203  $this->content .= '<div id="PageTreeDiv">' . $tree . '</div>';
204  // Setting up the buttons and markers for docheader
205  $docHeaderButtons = $this->getButtons();
206  $markers = [
207  'WORKSPACEINFO' => $this->getWorkspaceInfo(),
208  'CONTENT' => $this->content
209  ];
210  // Build the <body> for the module
211  $this->content = $this->doc->startPage('TYPO3 Page Tree');
212  $this->content .= $this->doc->moduleBody([], $docHeaderButtons, $markers);
213  $this->content .= $this->doc->endPage();
214  $this->content = $this->doc->insertStylesAndJS($this->content);
215  }
216 
222  public function printContent()
223  {
224  echo $this->content;
225  }
226 
232  protected function getButtons()
233  {
234  $buttons = [
235  'csh' => '',
236  'new_page' => '',
237  'refresh' => ''
238  ];
239  // New Page
240  $onclickNewPageWizard = 'top.content.list_frame.location.href=' . GeneralUtility::quoteJSvalue(BackendUtility::getModuleUrl('db_new', ['pagesOnly' => 1, 'id' => ''])) . '+Tree.pageID;';
241  $buttons['new_page'] = '<a href="#" onclick="' . $onclickNewPageWizard . '" title="' . $this->getLanguageService()->sL('LLL:EXT:backend/Resources/Private/Language/locallang_layout.xlf:newPage', true) . '">'
242  . $this->iconFactory->getIcon('actions-page-new', Icon::SIZE_SMALL)->render()
243  . '</a>';
244  // Refresh
245  $buttons['refresh'] = '<a href="' . htmlspecialchars(GeneralUtility::getIndpEnv('REQUEST_URI')) . '" title="' . $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:labels.refresh', true) . '">' . $this->iconFactory->getIcon('actions-refresh', Icon::SIZE_SMALL)->render() . '</a>';
246  // CSH
247  $buttons['csh'] = str_replace('typo3-csh-inline', 'typo3-csh-inline show-right', BackendUtility::cshItem('xMOD_csh_corebe', 'pagetree'));
248  return $buttons;
249  }
250 
256  protected function getWorkspaceInfo()
257  {
258  if (ExtensionManagementUtility::isLoaded('workspaces') && ($this->getBackendUser()->workspace !== 0 || $this->getBackendUser()->getTSConfigVal('options.pageTree.onlineWorkspaceInfo'))) {
259  $wsTitle = htmlspecialchars(WorkspaceService::getWorkspaceTitle($this->getBackendUser()->workspace));
260 
261  $workspaceInfo = '<div class="bgColor4 workspace-info"><span title="' . $wsTitle . '" onclick="top.goToModule(\'web_WorkspacesWorkspaces\');" style="cursor:pointer;">'
262  . $this->iconFactory->getIcon('apps-toolbar-menu-workspace', Icon::SIZE_SMALL)->render() . '</span>'
263  . $wsTitle . '</div>';
264  } else {
265  $workspaceInfo = '';
266  }
267  return $workspaceInfo;
268  }
269 
270  /**********************************
271  *
272  * Temporary DB mounts
273  *
274  **********************************/
280  public function initializeTemporaryDBmount()
281  {
282  $beUser = $this->getBackendUser();
283  // Set/Cancel Temporary DB Mount:
284  if ((string)$this->setTempDBmount !== '') {
285  $set = MathUtility::forceIntegerInRange($this->setTempDBmount, 0);
286  if ($set > 0 && $beUser->isInWebMount($set)) {
287  // Setting...:
288  $this->settingTemporaryMountPoint($set);
289  } else {
290  // Clear:
291  $this->settingTemporaryMountPoint(0);
292  }
293  }
294  // Getting temporary mount point ID:
295  $temporaryMountPoint = (int)$beUser->getSessionData('pageTree_temporaryMountPoint');
296  // If mount point ID existed and is within users real mount points, then set it temporarily:
297  if ($temporaryMountPoint > 0 && $beUser->isInWebMount($temporaryMountPoint)) {
298  if ($this->active_tempMountPoint = BackendUtility::readPageAccess($temporaryMountPoint, $beUser->getPagePermsClause(1))) {
299  $this->pagetree->MOUNTS = [$temporaryMountPoint];
300  } else {
301  // Clear temporary mount point as we have no access to it any longer
302  $this->settingTemporaryMountPoint(0);
303  }
304  }
305  }
306 
313  public function settingTemporaryMountPoint($pageId)
314  {
315  $this->getBackendUser()->setAndSaveSessionData('pageTree_temporaryMountPoint', (int)$pageId);
316  }
317 
318  /**********************************
319  *
320  * AJAX Calls
321  *
322  **********************************/
331  public function ajaxExpandCollapse(ServerRequestInterface $request, ResponseInterface $response)
332  {
333  $this->init();
334  $tree = $this->pagetree->getBrowsableTree();
335  if (!$this->pagetree->ajaxStatus) {
336  $response = $response->withStatus(500);
337  } else {
338  $response->getBody()->write(json_encode($tree));
339  }
340 
341  return $response;
342  }
343 
349  protected function getLanguageService()
350  {
351  return $GLOBALS['LANG'];
352  }
353 
359  protected function getBackendUser()
360  {
361  return $GLOBALS['BE_USER'];
362  }
363 }
static readPageAccess($id, $perms_clause)
static forceIntegerInRange($theInt, $min, $max=2000000000, $defaultValue=0)
Definition: MathUtility.php:31
ajaxExpandCollapse(ServerRequestInterface $request, ResponseInterface $response)
static linkThisScript(array $getParams=[])
static cshItem($table, $field, $_='', $wrap='')
static fixed_lgd_cs($string, $chars, $appendString='...')
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']