TYPO3 CMS  TYPO3_8-7
MetaInformation.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 
26 
31 {
38  protected $recordArray = [];
39 
45  public function setRecordArray(array $recordArray)
46  {
47  $this->recordArray = $recordArray;
48  }
49 
55  public function getPath()
56  {
57  $pageRecord = $this->recordArray;
58  $title = '';
59  // Is this a real page
60  if (is_array($pageRecord) && $pageRecord['uid']) {
61  $title = substr($pageRecord['_thePathFull'], 0, -1);
62  // Remove current page title
63  $pos = strrpos($title, $pageRecord['title']);
64  if ($pos !== false) {
65  $title = substr($title, 0, $pos);
66  }
67  } elseif (!empty($pageRecord['combined_identifier'])) {
68  try {
69  $resourceObject = ResourceFactory::getInstance()->getInstance()->getObjectFromCombinedIdentifier($pageRecord['combined_identifier']);
70  $title = $resourceObject->getStorage()->getName() . ':';
71  $title .= $resourceObject->getParentFolder()->getReadablePath();
72  } catch (ResourceDoesNotExistException $e) {
74  }
75  }
76  // Setting the path of the page
77  // crop the title to title limit (or 50, if not defined)
78  $beUser = $this->getBackendUser();
79  $cropLength = empty($beUser->uc['titleLen']) ? 50 : $beUser->uc['titleLen'];
80  $croppedTitle = GeneralUtility::fixed_lgd_cs($title, -$cropLength);
81  if ($croppedTitle !== $title) {
82  $pagePath = '<abbr title="' . htmlspecialchars($title) . '">' . htmlspecialchars($croppedTitle) . '</abbr>';
83  } else {
84  $pagePath = htmlspecialchars($title);
85  }
86  return $pagePath;
87  }
88 
94  public function getRecordInformation()
95  {
96  $recordInformations = $this->getRecordInformations();
97  if (!empty($recordInformations)) {
98  $recordInformation = $recordInformations['icon'] .
99  ' <strong>' . htmlspecialchars($recordInformations['title']) . ($recordInformations['uid'] !== '' ? '&nbsp;[' . $recordInformations['uid'] . ']' : '') . '</strong>' .
100  (!empty($recordInformations['additionalInfo']) ? ' ' . htmlspecialchars($recordInformations['additionalInfo']) : '');
101  } else {
102  $recordInformation = '';
103  }
104  return $recordInformation;
105  }
106 
112  public function getRecordInformationIcon()
113  {
114  $recordInformations = $this->getRecordInformations();
115  if (!empty($recordInformations)) {
116  $recordInformationIcon = $recordInformations['icon'];
117  } else {
118  $recordInformationIcon = null;
119  }
120  return $recordInformationIcon;
121  }
122 
128  public function getRecordInformationTitle()
129  {
130  $recordInformations = $this->getRecordInformations();
131  if (!empty($recordInformations)) {
132  $title = $recordInformations['title'];
133  } else {
134  $title = '';
135  }
136 
137  // crop the title to title limit (or 50, if not defined)
138  $beUser = $this->getBackendUser();
139  $cropLength = empty($beUser->uc['titleLen']) ? 50 : $beUser->uc['titleLen'];
140  return htmlspecialchars(GeneralUtility::fixed_lgd_cs($title, $cropLength));
141  }
142 
148  public function getRecordInformationUid()
149  {
150  $recordInformations = $this->getRecordInformations();
151  if (!empty($recordInformations)) {
152  $recordInformationUid = $recordInformations['uid'];
153  } else {
154  $recordInformationUid = null;
155  }
156  return $recordInformationUid;
157  }
158 
164  public function getRecordInformationAdditionalInfo(): string
165  {
166  $recordInformations = $this->getRecordInformations();
167  return $recordInformations['additionalInfo'] ?? '';
168  }
169 
175  protected function getRecordInformations()
176  {
177  $pageRecord = $this->recordArray;
178  if (empty($pageRecord)) {
179  return [];
180  }
181 
182  $iconFactory = GeneralUtility::makeInstance(IconFactory::class);
183  $uid = '';
184  $title = '';
185  $additionalInfo = (!empty($pageRecord['_additional_info']) ? $pageRecord['_additional_info'] : '');
186  // Add icon with context menu, etc:
187  // If there IS a real page
188  if (is_array($pageRecord) && $pageRecord['uid']) {
189  $toolTip = BackendUtility::getRecordToolTip($pageRecord, 'pages');
190  $iconImg = '<span ' . $toolTip . '>' . $iconFactory->getIconForRecord('pages', $pageRecord, Icon::SIZE_SMALL)->render() . '</span>';
191  // Make Icon:
192  $theIcon = BackendUtility::wrapClickMenuOnIcon($iconImg, 'pages', $pageRecord['uid']);
193  $uid = $pageRecord['uid'];
194  $title = BackendUtility::getRecordTitle('pages', $pageRecord);
195  } elseif (is_array($pageRecord) && !empty($pageRecord['combined_identifier'])) {
196  // If the module is about a FAL resource
197  try {
198  $resourceObject = ResourceFactory::getInstance()->getInstance()->getObjectFromCombinedIdentifier($pageRecord['combined_identifier']);
199  $fileMountTitle = $resourceObject->getStorage()->getFileMounts()[$resourceObject->getIdentifier()]['title'];
200  $title = $fileMountTitle ?: $resourceObject->getName();
201  // If this is a folder but not in within file mount boundaries this is the root folder
202  if ($resourceObject instanceof FolderInterface && !$resourceObject->getStorage()->isWithinFileMountBoundaries($resourceObject)) {
203  $iconImg = '<span title="' . htmlspecialchars($title) . '">' . $iconFactory->getIconForResource(
204  $resourceObject,
206  null,
207  ['mount-root' => true]
208  )->render() . '</span>';
209  } else {
210  $iconImg = '<span title="' . htmlspecialchars($title) . '">' . $iconFactory->getIconForResource(
211  $resourceObject,
213  )->render() . '</span>';
214  }
215  $theIcon = BackendUtility::wrapClickMenuOnIcon($iconImg, 'sys_file', $pageRecord['combined_identifier']);
216  } catch (ResourceDoesNotExistException $e) {
217  $theIcon = '';
218  }
219  } else {
220  // On root-level of page tree
221  // Make Icon
222  $iconImg = '<span title="' .
223  htmlspecialchars($GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename']) .
224  '">' .
225  $iconFactory->getIcon('apps-pagetree-root', Icon::SIZE_SMALL)->render() . '</span>';
226  if ($this->getBackendUser()->isAdmin()) {
227  $theIcon = BackendUtility::wrapClickMenuOnIcon($iconImg, 'pages', 0);
228  } else {
229  $theIcon = $iconImg;
230  }
231  $uid = '0';
232  $title = $GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename'];
233  }
234  // returns array for icon, title, uid and additional info
235  return [
236  'uid' => $uid,
237  'icon' => $theIcon,
238  'title' => $title,
239  'additionalInfo' => $additionalInfo
240  ];
241  }
242 
248  protected function getLanguageService()
249  {
250  return $GLOBALS['LANG'];
251  }
252 
258  protected function getBackendUser()
259  {
260  return $GLOBALS['BE_USER'];
261  }
262 }
static wrapClickMenuOnIcon( $content, $table, $uid=0, $context='', $_addParams='', $_enDisItems='', $returnTagParameters=false)
static getRecordToolTip(array $row, $table='pages')
static makeInstance($className,... $constructorArguments)
static getRecordTitle($table, $row, $prep=false, $forceResult=true)
static fixed_lgd_cs($string, $chars, $appendString='...')
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']