TYPO3CMS  8
 All Classes Namespaces Files Functions Variables Pages
recordlist/Classes/LinkHandler/PageLinkHandler.php
Go to the documentation of this file.
1 <?php
2 namespace TYPO3\CMS\Recordlist\LinkHandler;
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 Psr\Http\Message\ServerRequestInterface;
29 
34 {
38  protected $expandPage = 0;
39 
45  protected $linkParts = [];
46 
56  public function canHandleLink(array $linkParts)
57  {
58  if (!$linkParts['url']) {
59  return false;
60  }
61 
62  $data = $linkParts['url'];
63  // Checking if the id-parameter is an alias.
64  if (isset($data['pagealias'])) {
65  $records = BackendUtility::getRecordsByField('pages', 'alias', $data['pagealias']);
66  if (empty($records)) {
67  return false;
68  }
69  $data['pageuid'] = (int)$records[0]['uid'];
70  }
71  // Check if the page still exists
72  if ((int)$data['pageuid'] > 0) {
73  $pageRow = BackendUtility::getRecordWSOL('pages', $data['pageuid']);
74  if (!$pageRow) {
75  return false;
76  }
77  } elseif ($data['pageuid'] !== 'current') {
78  return false;
79  }
80 
81  $this->linkParts = $linkParts;
82  return true;
83  }
84 
90  public function formatCurrentUrl()
91  {
92  $lang = $this->getLanguageService();
93  $titleLen = (int)$this->getBackendUser()->uc['titleLen'];
94 
95  $id = $this->linkParts['url']['pageuid'];
96  $pageRow = BackendUtility::getRecordWSOL('pages', $id);
97 
98  return htmlspecialchars($lang->getLL('page'))
99  . ' \'' . htmlspecialchars(GeneralUtility::fixed_lgd_cs($pageRow['title'], $titleLen)) . '\''
100  . ' (ID: ' . $id . ($this->linkParts['url']['fragment'] ? ', #' . $this->linkParts['url']['fragment'] : '') . ')';
101  }
102 
110  public function render(ServerRequestInterface $request)
111  {
112  GeneralUtility::makeInstance(PageRenderer::class)->loadRequireJsModule('TYPO3/CMS/Recordlist/PageLinkHandler');
113 
114  $this->expandPage = isset($request->getQueryParams()['expandPage']) ? (int)$request->getQueryParams()['expandPage'] : 0;
115  $this->setTemporaryDbMounts();
116 
117  $backendUser = $this->getBackendUser();
118 
120  $pageTree = GeneralUtility::makeInstance(ElementBrowserPageTreeView::class);
121  $pageTree->setLinkParameterProvider($this);
122  $pageTree->ext_showNavTitle = (bool)$backendUser->getTSConfigVal('options.pageTree.showNavTitle');
123  $pageTree->ext_showPageId = (bool)$backendUser->getTSConfigVal('options.pageTree.showPageIdWithTitle');
124  $pageTree->ext_showPathAboveMounts = (bool)$backendUser->getTSConfigVal('options.pageTree.showPathAboveMounts');
125  $pageTree->addField('nav_title');
126 
127  $this->view->assign('temporaryTreeMountCancelLink', $this->getTemporaryTreeMountCancelNotice());
128  $this->view->assign('tree', $pageTree->getBrowsableTree());
129  $this->getRecordsOnExpandedPage($this->expandPage);
130  return $this->view->render('Page');
131  }
132 
140  protected function getRecordsOnExpandedPage($pageId)
141  {
142  // If there is an anchor value (content element reference) in the element reference, then force an ID to expand:
143  if (!$pageId && isset($this->linkParts['url']['fragment'])) {
144  // Set to the current link page id.
145  $pageId = $this->linkParts['url']['pageuid'];
146  }
147  // Draw the record list IF there is a page id to expand:
148  if ($pageId && MathUtility::canBeInterpretedAsInteger($pageId) && $this->getBackendUser()->isInWebMount($pageId)) {
149  $pageId = (int)$pageId;
150 
151  $activePageRecord = BackendUtility::getRecordWSOL('pages', $pageId);
152  $this->view->assign('expandActivePage', true);
153 
154  // Create header for listing, showing the page title/icon
155  $this->view->assign('activePage', $activePageRecord);
156  $this->view->assign('activePageTitle', BackendUtility::getRecordTitle('pages', $activePageRecord, true));
157  $this->view->assign('activePageIcon', $this->iconFactory->getIconForRecord('pages', $activePageRecord, Icon::SIZE_SMALL)->render());
158 
159  // Look up tt_content elements from the expanded page
160  $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
161  ->getQueryBuilderForTable('tt_content');
162 
163  $queryBuilder->getRestrictions()
164  ->removeAll()
165  ->add(GeneralUtility::makeInstance(DeletedRestriction::class))
166  ->add(GeneralUtility::makeInstance(BackendWorkspaceRestriction::class));
167 
168  $contentElements = $queryBuilder
169  ->select('*')
170  ->from('tt_content')
171  ->where(
172  $queryBuilder->expr()->eq(
173  'pid',
174  $queryBuilder->createNamedParameter($pageId, \PDO::PARAM_INT)
175  )
176  )
177  ->orderBy('colPos')
178  ->addOrderBy('sorting')
179  ->execute()
180  ->fetchAll();
181 
182  // Enrich list of records
183  foreach ($contentElements as &$contentElement) {
184  $contentElement['url'] = GeneralUtility::makeInstance(LinkService::class)->asString(['type' => LinkService::TYPE_PAGE, 'pageuid' => (int)$pageId, 'fragment' => $contentElement['uid']]);
185  $contentElement['isSelected'] = !empty($this->linkParts) && (int)$this->linkParts['url']['fragment'] === (int)$contentElement['uid'];
186  $contentElement['icon'] = $this->iconFactory->getIconForRecord('tt_content', $contentElement, Icon::SIZE_SMALL)->render();
187  $contentElement['title'] = BackendUtility::getRecordTitle('tt_content', $contentElement, true);
188  }
189  $this->view->assign('contentElements', $contentElements);
190  }
191  }
192 
199  {
200  if ((int)$this->getBackendUser()->getSessionData('pageTree_temporaryMountPoint') > 0) {
201  return GeneralUtility::linkThisScript(['setTempDBmount' => 0]);
202  } else {
203  return '';
204  }
205  }
206 
210  protected function setTemporaryDbMounts()
211  {
212  $backendUser = $this->getBackendUser();
213 
214  // Clear temporary DB mounts
215  $tmpMount = GeneralUtility::_GET('setTempDBmount');
216  if (isset($tmpMount)) {
217  $backendUser->setAndSaveSessionData('pageTree_temporaryMountPoint', (int)$tmpMount);
218  }
219  // Set temporary DB mounts
220  $alternativeWebmountPoint = (int)$backendUser->getSessionData('pageTree_temporaryMountPoint');
221  if ($alternativeWebmountPoint) {
222  $alternativeWebmountPoint = GeneralUtility::intExplode(',', $alternativeWebmountPoint);
223  $backendUser->setWebmounts($alternativeWebmountPoint);
224  } else {
225  // Setting alternative browsing mounts (ONLY local to browse_links.php this script so they stay "read-only")
226  $alternativeWebmountPoints = trim($backendUser->getTSConfigVal('options.pageTree.altElementBrowserMountPoints'));
227  $appendAlternativeWebmountPoints = $backendUser->getTSConfigVal('options.pageTree.altElementBrowserMountPoints.append');
228  if ($alternativeWebmountPoints) {
229  $alternativeWebmountPoints = GeneralUtility::intExplode(',', $alternativeWebmountPoints);
230  $this->getBackendUser()->setWebmounts($alternativeWebmountPoints, $appendAlternativeWebmountPoints);
231  }
232  }
233  }
234 
238  public function getBodyTagAttributes()
239  {
240  if (count($this->linkParts) === 0 || empty($this->linkParts['url']['pageuid'])) {
241  return [];
242  }
243  return [
244  'data-current-link' => GeneralUtility::makeInstance(LinkService::class)->asString([
245  'type' => LinkService::TYPE_PAGE,
246  'pageuid' => (int)$this->linkParts['url']['pageuid'],
247  'fragment' => $this->linkParts['url']['fragment']
248  ])
249  ];
250  }
251 
257  public function getUrlParameters(array $values)
258  {
259  $parameters = [
260  'expandPage' => isset($values['pid']) ? (int)$values['pid'] : $this->expandPage
261  ];
262  return array_merge($this->linkBrowser->getUrlParameters($values), $parameters);
263  }
264 
270  public function isCurrentlySelectedItem(array $values)
271  {
272  return !empty($this->linkParts) && (int)$this->linkParts['url']['pageuid'] === (int)$values['pid'];
273  }
274 
280  public function getScriptUrl()
281  {
282  return $this->linkBrowser->getScriptUrl();
283  }
284 
289  public function modifyLinkAttributes(array $fieldDefinitions)
290  {
291  $configuration = $this->linkBrowser->getConfiguration();
292  if (!empty($configuration['pageIdSelector.']['enabled'])) {
293  array_push($this->linkAttributes, 'pageIdSelector');
294  $fieldDefinitions['pageIdSelector'] = '
295  <tr>
296  <td>
297  <label>
298  ' . htmlspecialchars($this->getLanguageService()->getLL('page_id')) . ':
299  </label>
300  </td>
301  <td colspan="3">
302  <input type="text" size="6" name="luid" id="luid" /> <input class="btn btn-default t3js-pageLink" type="submit" value="'
303  . htmlspecialchars($this->getLanguageService()->getLL('setLink')) . '" />
304  </td>
305  </tr>';
306  }
307  return $fieldDefinitions;
308  }
309 }
return[ 'sc_alt_file_navframe_expandtoggle'=>[ 'path'=> '/folder/tree/expand', 'target'=> Controller\FileSystemNavigationFrameController::class. '::ajaxExpandCollapse'], 'file_process'=>[ 'path'=> '/file/process', 'target'=> Controller\File\FileController::class. '::processAjaxRequest'], 'file_exists'=>[ 'path'=> '/file/exists', 'target'=> Controller\File\FileController::class. '::fileExistsInFolderAction'], 'record_inline_details'=>[ 'path'=> '/record/inline/details', 'target'=> Controller\FormInlineAjaxController::class. '::detailsAction'], 'record_inline_create'=>[ 'path'=> '/record/inline/create', 'target'=> Controller\FormInlineAjaxController::class. '::createAction'], 'record_inline_synchronizelocalize'=>[ 'path'=> '/record/inline/synchronizelocalize', 'target'=> Controller\FormInlineAjaxController::class. '::synchronizeLocalizeAction'], 'record_inline_expandcollapse'=>[ 'path'=> '/record/inline/expandcollapse', 'target'=> Controller\FormInlineAjaxController::class. '::expandOrCollapseAction'], 'record_suggest'=>[ 'path'=> '/wizard/suggest/search', 'target'=>\TYPO3\CMS\Backend\Controller\Wizard\SuggestWizardController::class. '::searchAction'], 'record_tree_data'=>[ 'path'=> '/record/tree/fetchData', 'target'=> Controller\SelectTreeController::class. '::fetchDataAction'], 'shortcut_editform'=>[ 'path'=> '/shortcut/editform', 'target'=>\TYPO3\CMS\Backend\Backend\ToolbarItems\ShortcutToolbarItem::class. '::editFormAction'], 'shortcut_saveform'=>[ 'path'=> '/shortcut/saveform', 'target'=>\TYPO3\CMS\Backend\Backend\ToolbarItems\ShortcutToolbarItem::class. '::saveFormAction'], 'shortcut_list'=>[ 'path'=> '/shortcut/list', 'target'=>\TYPO3\CMS\Backend\Backend\ToolbarItems\ShortcutToolbarItem::class. '::menuAction'], 'shortcut_remove'=>[ 'path'=> '/shortcut/remove', 'target'=>\TYPO3\CMS\Backend\Backend\ToolbarItems\ShortcutToolbarItem::class. '::removeShortcutAction'], 'shortcut_create'=>[ 'path'=> '/shortcut/create', 'target'=>\TYPO3\CMS\Backend\Backend\ToolbarItems\ShortcutToolbarItem::class. '::createShortcutAction'], 'systeminformation_render'=>[ 'path'=> '/system-information/render', 'target'=>\TYPO3\CMS\Backend\Backend\ToolbarItems\SystemInformationToolbarItem::class. '::renderMenuAction'], 'modulemenu'=>[ 'path'=> '/module-menu', 'target'=> Controller\BackendController::class. '::getModuleMenu'], 'login'=>[ 'path'=> '/login', 'target'=>\TYPO3\CMS\Backend\AjaxLoginHandler::class. '::loginAction', 'access'=> 'public'], 'logout'=>[ 'path'=> '/logout', 'target'=>\TYPO3\CMS\Backend\AjaxLoginHandler::class. '::logoutAction', 'access'=> 'public'], 'login_refresh'=>[ 'path'=> '/login/refresh', 'target'=>\TYPO3\CMS\Backend\AjaxLoginHandler::class. '::refreshAction',], 'login_timedout'=>[ 'path'=> '/login/timedout', 'target'=>\TYPO3\CMS\Backend\AjaxLoginHandler::class. '::isTimedOutAction', 'access'=> 'public'], 'ext_direct_route'=>[ 'path'=> '/ext-direct/route', 'target'=>\TYPO3\CMS\Core\ExtDirect\ExtDirectRouter::class. '::routeAction', 'access'=> 'public'], 'ext_direct_api'=>[ 'path'=> '/ext-direct/api', 'target'=>\TYPO3\CMS\Core\ExtDirect\ExtDirectApi::class. '::getAPI'], 'flashmessages_render'=>[ 'path'=> '/flashmessages/render', 'target'=>\TYPO3\CMS\Backend\Template\DocumentTemplate::class. '::renderQueuedFlashMessages'], 'contextmenu'=>[ 'path'=> '/context-menu', 'target'=> Controller\ClickMenuController::class. '::getContextMenuAction'], 'record_process'=>[ 'path'=> '/record/process', 'target'=> Controller\SimpleDataHandlerController::class. '::processAjaxRequest'], 'usersettings_process'=>[ 'path'=> '/usersettings/process', 'target'=> Controller\UserSettingsController::class. '::processAjaxRequest'], 'wizard_image_manipulation'=>[ 'path'=> '/wizard/image-manipulation', 'target'=>\TYPO3\CMS\Backend\Form\Wizard\ImageManipulationWizard::class. '::getWizardAction'], 'livesearch'=>[ 'path'=> '/livesearch', 'target'=> Controller\LiveSearchController::class. '::liveSearchAction'], 'online_media_create'=>[ 'path'=> '/online-media/create', 'target'=> Controller\OnlineMediaController::class. '::createAction'], 'icons'=>[ 'path'=> '/icons', 'target'=>\TYPO3\CMS\Core\Imaging\IconFactory::class. '::processAjaxRequest'], 'link_browser_encodetypolink'=>[ 'path'=> '/link-browser/encode-typolink', 'target'=>\TYPO3\CMS\Backend\Controller\LinkBrowserController::class. '::encodeTypoLink',], 'languages_page_colpos'=>[ 'path'=> '/records/localize/get-languages', 'target'=> Controller\Page\LocalizationController::class. '::getUsedLanguagesInPageAndColumn'], 'records_localize_summary'=>[ 'path'=> '/records/localize/summary', 'target'=> Controller\Page\LocalizationController::class. '::getRecordLocalizeSummary'], 'records_localize'=>[ 'path'=> '/records/localize', 'target'=> Controller\Page\LocalizationController::class. '::localizeRecords']]
static getRecordWSOL($table, $uid, $fields= '*', $where= '', $useDeleteClause=true, $unsetMovePointers=false)
static getRecordTitle($table, $row, $prep=false, $forceResult=true)
static getRecordsByField($theTable, $theField, $theValue, $whereClause= '', $groupBy= '', $orderBy= '', $limit= '', $useDeleteClause=true, $queryBuilder=null)
static linkThisScript(array $getParams=[])
static makeInstance($className,...$constructorArguments)
static intExplode($delimiter, $string, $removeEmptyValues=false, $limit=0)