[CLEANUP] Use Permission constants consistently
[Packages/TYPO3.CMS.git] / typo3 / sysext / fluid / Classes / ViewHelpers / Be / PagePathViewHelper.php
1 <?php
2 namespace TYPO3\CMS\Fluid\ViewHelpers\Be;
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 use TYPO3\CMS\Core\Type\Bitmask\Permission;
19 use TYPO3\CMS\Core\Utility\GeneralUtility;
20 use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
21
22 /**
23 * View helper which returns the current page path as known from TYPO3 backend modules
24 * Note: This view helper is experimental!
25 *
26 * = Examples =
27 *
28 * <code>
29 * <f:be.pagePath />
30 * </code>
31 * <output>
32 * Current page path, prefixed with "Path:" and wrapped in a span with the class "typo3-docheader-pagePath"
33 * </output>
34 */
35 class PagePathViewHelper extends AbstractBackendViewHelper
36 {
37
38 /**
39 * This view helper renders HTML, thus output must not be escaped
40 *
41 * @var bool
42 */
43 protected $escapeOutput = false;
44
45 /**
46 * Renders the current page path
47 *
48 * @return string the rendered page path
49 * @see \TYPO3\CMS\Backend\Template\DocumentTemplate::getPagePath() Note: can't call this method as it's protected!
50 */
51 public function render()
52 {
53 return static::renderStatic(
54 [],
55 $this->buildRenderChildrenClosure(),
56 $this->renderingContext
57 );
58 }
59
60 /**
61 * @param array $arguments
62 * @param \Closure $renderChildrenClosure
63 * @param RenderingContextInterface $renderingContext
64 *
65 * @return string
66 */
67 public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
68 {
69 $id = GeneralUtility::_GP('id');
70 $pageRecord = BackendUtility::readPageAccess($id, $GLOBALS['BE_USER']->getPagePermsClause(Permission::PAGE_SHOW));
71 // Is this a real page
72 if ($pageRecord['uid']) {
73 $title = $pageRecord['_thePathFull'];
74 } else {
75 $title = $GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename'];
76 }
77 // Setting the path of the page
78 $pagePath = htmlspecialchars($GLOBALS['LANG']->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.path')) . ': <span class="typo3-docheader-pagePath">';
79 // crop the title to title limit (or 50, if not defined)
80 $cropLength = empty($GLOBALS['BE_USER']->uc['titleLen']) ? 50 : $GLOBALS['BE_USER']->uc['titleLen'];
81 $croppedTitle = GeneralUtility::fixed_lgd_cs($title, -$cropLength);
82 if ($croppedTitle !== $title) {
83 $pagePath .= '<abbr title="' . htmlspecialchars($title) . '">' . htmlspecialchars($croppedTitle) . '</abbr>';
84 } else {
85 $pagePath .= htmlspecialchars($title);
86 }
87 $pagePath .= '</span>';
88 return $pagePath;
89 }
90 }