774b5acacc636ae7adf9f44c17610711594edfa6
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Classes / Controller / ContentElement / ElementInformationController.php
1 <?php
2 namespace TYPO3\CMS\Backend\Controller\ContentElement;
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\Backend\Utility\IconUtility;
19 use TYPO3\CMS\Core\Resource\Folder;
20 use TYPO3\CMS\Core\Resource\ProcessedFile;
21 use TYPO3\CMS\Core\Resource\ResourceFactory;
22 use TYPO3\CMS\Core\Utility\GeneralUtility;
23
24 /**
25 * Script Class for showing information about an item.
26 *
27 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
28 */
29 class ElementInformationController {
30
31 /**
32 * Record table name
33 *
34 * @var string
35 */
36 public $table;
37
38 /**
39 * Record uid
40 *
41 * @var int
42 */
43 public $uid;
44
45 /**
46 * @var string
47 */
48 protected $permsClause;
49
50 /**
51 * @var bool
52 */
53 public $access = FALSE;
54
55 /**
56 * Which type of element:
57 * - "file"
58 * - "db"
59 *
60 * @var string
61 */
62 public $type = '';
63
64 /**
65 * @var \TYPO3\CMS\Backend\Template\DocumentTemplate
66 */
67 public $doc;
68
69 /**
70 * @var string
71 */
72 protected $content = '';
73
74 /**
75 * For type "db": Set to page record of the parent page of the item set
76 * (if type="db")
77 *
78 * @var array
79 */
80 public $pageinfo;
81
82 /**
83 * Database records identified by table/uid
84 *
85 * @var array
86 */
87 protected $row;
88
89 /**
90 * @var \TYPO3\CMS\Core\Resource\File
91 */
92 protected $fileObject;
93
94 /**
95 * @var Folder
96 */
97 protected $folderObject;
98
99 /**
100 * The HTML title tag
101 *
102 * @var string
103 */
104 protected $titleTag;
105
106 /**
107 * Constructor
108 */
109 public function __construct() {
110 $GLOBALS['BACK_PATH'] = '';
111 $GLOBALS['SOBE'] = $this;
112
113 $this->init();
114 }
115
116 /**
117 * Determines if table/uid point to database record or file and
118 * if user has access to view information
119 *
120 * @return void
121 */
122 public function init() {
123 $this->table = GeneralUtility::_GET('table');
124 $this->uid = GeneralUtility::_GET('uid');
125
126 $this->perms_clause = $GLOBALS['BE_USER']->getPagePermsClause(1);
127 $this->doc = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Template\DocumentTemplate::class);
128 $this->doc->divClass = 'container';
129
130 if (isset($GLOBALS['TCA'][$this->table])) {
131 $this->initDatabaseRecord();
132 } elseif ($this->table == '_FILE' || $this->table == '_FOLDER' || $this->table == 'sys_file') {
133 $this->initFileOrFolderRecord();
134 }
135 }
136
137 /**
138 * Init database records (table)
139 */
140 protected function initDatabaseRecord() {
141 $this->type = 'db';
142 $this->uid = (int)$this->uid;
143
144 // Check permissions and uid value:
145 if ($this->uid && $GLOBALS['BE_USER']->check('tables_select', $this->table)) {
146 if ((string)$this->table == 'pages') {
147 $this->pageinfo = BackendUtility::readPageAccess($this->uid, $this->perms_clause);
148 $this->access = is_array($this->pageinfo) ? 1 : 0;
149 $this->row = $this->pageinfo;
150 } else {
151 $this->row = BackendUtility::getRecordWSOL($this->table, $this->uid);
152 if ($this->row) {
153 $this->pageinfo = BackendUtility::readPageAccess($this->row['pid'], $this->perms_clause);
154 $this->access = is_array($this->pageinfo) ? 1 : 0;
155 }
156 }
157 /** @var $treatData \TYPO3\CMS\Backend\Form\DataPreprocessor */
158 $treatData = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Form\DataPreprocessor::class);
159 $treatData->renderRecord($this->table, $this->uid, 0, $this->row);
160 }
161 }
162
163 /**
164 * Init file/folder parameters
165 */
166 protected function initFileOrFolderRecord() {
167 $fileOrFolderObject = ResourceFactory::getInstance()->retrieveFileOrFolderObject($this->uid);
168
169 if ($fileOrFolderObject instanceof Folder) {
170 $this->folderObject = $fileOrFolderObject;
171 $this->access = $this->folderObject->checkActionPermission('read');
172 $this->type = 'folder';
173 } else {
174 $this->fileObject = $fileOrFolderObject;
175 $this->access = $this->fileObject->checkActionPermission('read');
176 $this->type = 'file';
177 $this->table = 'sys_file';
178
179 try {
180 $this->row = BackendUtility::getRecordWSOL($this->table, $fileOrFolderObject->getUid());
181 } catch (\Exception $e) {
182 $this->row = array();
183 }
184 }
185 }
186
187 /**
188 * @return void
189 */
190 public function main() {
191 if (!$this->access) {
192 return;
193 }
194
195 // render type by user func
196 $typeRendered = FALSE;
197 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/show_item.php']['typeRendering'])) {
198 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/show_item.php']['typeRendering'] as $classRef) {
199 $typeRenderObj = GeneralUtility::getUserObj($classRef);
200 // @todo should have an interface
201 if (is_object($typeRenderObj) && method_exists($typeRenderObj, 'isValid') && method_exists($typeRenderObj, 'render')) {
202 if ($typeRenderObj->isValid($this->type, $this)) {
203 $this->content .= $typeRenderObj->render($this->type, $this);
204 $typeRendered = TRUE;
205 break;
206 }
207 }
208 }
209 }
210
211 if (!$typeRendered) {
212 $this->content .= $this->renderPageTitle();
213 $this->content .= $this->renderPreview();
214 $this->content .= $this->renderPropertiesAsTable();
215 $this->content .= $this->renderReferences();
216 $this->content .= $this->renderBackButton();
217 }
218 }
219
220 /**
221 * Render page title with icon, table title and record title
222 *
223 * @return string
224 */
225 protected function renderPageTitle() {
226 if ($this->type === 'folder') {
227 $table = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_common.xlf:folder');
228 $title = $this->doc->getResourceHeader($this->folderObject, array(' ', ''), FALSE);
229 } elseif ($this->type === 'file') {
230 $table = $GLOBALS['LANG']->sL($GLOBALS['TCA'][$this->table]['ctrl']['title']);
231 $title = $this->doc->getResourceHeader($this->fileObject, array(' ', ''), FALSE);
232 } else {
233 $table = $GLOBALS['LANG']->sL($GLOBALS['TCA'][$this->table]['ctrl']['title']);
234 $title = $this->doc->getHeader($this->table, $this->row, $this->pageinfo['_thePath'], 1, array(' ', ''), FALSE);
235 }
236 // Set HTML title tag
237 $this->titleTag = $table . ': ' . strip_tags(BackendUtility::getRecordTitle($this->table, $this->row));
238 return '<h1>' .
239 ($table ? '<small>' . $table . '</small><br />' : '') .
240 $title .
241 '</h1>';
242 }
243
244 /**
245 * Render preview for current record
246 *
247 * @return string
248 */
249 protected function renderPreview() {
250 // Perhaps @todo in future: Also display preview for records - without fileObject
251 if (!$this->fileObject) {
252 return;
253 }
254
255 $previewTag = '';
256 $downloadLink = '';
257
258 // check if file is marked as missing
259 if ($this->fileObject->isMissing()) {
260 $flashMessage = \TYPO3\CMS\Core\Resource\Utility\BackendUtility::getFlashMessageForMissingFile($this->fileObject);
261 $previewTag .= $flashMessage->render();
262
263 } else {
264
265 /** @var \TYPO3\CMS\Core\Resource\Rendering\RendererRegistry $rendererRegistry */
266 $rendererRegistry = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Resource\Rendering\RendererRegistry::class);
267 $fileRenderer = $rendererRegistry->getRenderer($this->fileObject);
268 $fileExtension = $this->fileObject->getExtension();
269 $url = $this->fileObject->getPublicUrl(TRUE);
270
271 // Check if there is a FileRenderer
272 if ($fileRenderer !== NULL) {
273 $previewTag = $fileRenderer->render(
274 $this->fileObject,
275 '590m',
276 '400m',
277 array(),
278 TRUE
279 );
280
281 // else check if we can create an Image preview
282 } elseif (GeneralUtility::inList($GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'], $fileExtension)) {
283 $processedFile = $this->fileObject->process(
284 ProcessedFile::CONTEXT_IMAGEPREVIEW,
285 array(
286 'width' => '590m',
287 'height' => '400m'
288 )
289 );
290 // Create thumbnail image?
291 if ($processedFile) {
292 $thumbUrl = $processedFile->getPublicUrl(TRUE);
293 $previewTag .= '<img class="img-responsive img-thumbnail" src="' . $thumbUrl . '" ' .
294 'width="' . $processedFile->getProperty('width') . '" ' .
295 'height="' . $processedFile->getProperty('height') . '" ' .
296 'alt="' . htmlspecialchars(trim($this->fileObject->getName())) . '" ' .
297 'title="' . htmlspecialchars(trim($this->fileObject->getName())) . '" />';
298 }
299 }
300
301 // Download
302 if ($url) {
303 $downloadLink .= '
304 <a class="btn btn-primary" href="' . htmlspecialchars($url) . '" target="_blank">
305 ' . IconUtility::getSpriteIcon('actions-edit-download') . '
306 ' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_common.xlf:download', TRUE) . '
307 </a>';
308 }
309 }
310
311 return ($previewTag ? '<p>' . $previewTag . '</p>' : '') .
312 ($downloadLink ? '<p>' . $downloadLink . '</p>' : '');
313 }
314
315 /**
316 * Render property array as html table
317 *
318 * @return string
319 */
320 protected function renderPropertiesAsTable() {
321 $tableRows = array();
322 $extraFields = array();
323
324 if (in_array($this->type, array('folder', 'file'), TRUE)) {
325 if ($this->type === 'file') {
326 $extraFields['creation_date'] = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_general.xlf:LGL.creationDate', TRUE);
327 $extraFields['modification_date'] = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_general.xlf:LGL.timestamp', TRUE);
328 }
329 $extraFields['storage'] = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_tca.xlf:sys_file.storage', TRUE);
330 $extraFields['folder'] = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_common.xlf:folder', TRUE);
331 } else {
332 $extraFields['crdate'] = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_general.xlf:LGL.creationDate', TRUE);
333 $extraFields['cruser_id'] = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_general.xlf:LGL.creationUserId', TRUE);
334 $extraFields['tstamp'] = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_general.xlf:LGL.timestamp', TRUE);
335
336 // check if the special fields are defined in the TCA ctrl section of the table
337 foreach ($extraFields as $fieldName => $fieldLabel) {
338 if (isset($GLOBALS['TCA'][$this->table]['ctrl'][$fieldName])) {
339 $extraFields[$GLOBALS['TCA'][$this->table]['ctrl'][$fieldName]] = $fieldLabel;
340 } else {
341 unset($extraFields[$fieldName]);
342 }
343 }
344 }
345
346 foreach ($extraFields as $name => $fieldLabel) {
347 $rowValue = '';
348 if (!isset($this->row[$name])) {
349 $resourceObject = $this->fileObject ?: $this->folderObject;
350 if ($name === 'storage') {
351 $rowValue = $resourceObject->getStorage()->getName();
352 } elseif ($name === 'folder') {
353 $rowValue = $resourceObject->getParentFolder()->getIdentifier();
354 }
355 } elseif (in_array($name, array('creation_date', 'modification_date'), TRUE)) {
356 $rowValue = BackendUtility::datetime($this->row[$name]);
357 } else {
358 $rowValue = BackendUtility::getProcessedValueExtra($this->table, $name, $this->row[$name]);
359 }
360 // show the backend username who created the issue
361 if ($name === 'cruser_id' && $rowValue) {
362 $userTemp = $GLOBALS['TYPO3_DB']->exec_SELECTgetSingleRow('username, realName', 'be_users', 'uid = ' . (int)$rowValue);
363 if ($userTemp[0]['username'] !== '') {
364 $rowValue = $userTemp[0]['username'];
365 if ($userTemp[0]['realName'] !== '') {
366 $rowValue .= ' - ' . $userTemp[0]['realName'];
367 }
368 }
369 }
370 $tableRows[] = '
371 <tr>
372 <th>' . rtrim($fieldLabel, ':') . '</th>
373 <td>' . htmlspecialchars($rowValue) . '</td>
374 </tr>';
375 }
376
377 // Traverse the list of fields to display for the record:
378 $fieldList = GeneralUtility::trimExplode(',', $GLOBALS['TCA'][$this->table]['interface']['showRecordFieldList'], TRUE);
379 foreach ($fieldList as $name) {
380 $name = trim($name);
381 $uid = $this->row['uid'];
382
383 if (!isset($GLOBALS['TCA'][$this->table]['columns'][$name])) {
384 continue;
385 }
386
387 // Storage is already handled above
388 if ($this->type === 'file' && $name === 'storage') {
389 continue;
390 }
391
392 $isExcluded = !(!$GLOBALS['TCA'][$this->table]['columns'][$name]['exclude'] || $GLOBALS['BE_USER']->check('non_exclude_fields', $this->table . ':' . $name));
393 if ($isExcluded) {
394 continue;
395 }
396
397 $itemValue = BackendUtility::getProcessedValue($this->table, $name, $this->row[$name], 0, 0, FALSE, $uid);
398 $itemLabel = $GLOBALS['LANG']->sL(BackendUtility::getItemLabel($this->table, $name), TRUE);
399 $tableRows[] = '
400 <tr>
401 <th>' . $itemLabel . '</th>
402 <td>' . htmlspecialchars($itemValue) . '</td>
403 </tr>';
404 }
405
406 return '
407 <div class="table-fit table-fit-wrap">
408 <table class="table table-striped table-hover">
409 ' . implode('', $tableRows) . '
410 </table>
411 </div>';
412 }
413
414 /**
415 * Render references section (references from and references to current record)
416 *
417 * @return string
418 */
419 protected function renderReferences() {
420 $content = '';
421
422 switch ($this->type) {
423 case 'db': {
424 $references = $this->makeRef($this->table, $this->row['uid']);
425 if (!empty($references)) {
426 $content .= $this->doc->section($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:show_item.php.referencesToThisItem'), $references);
427 }
428
429 $referencesFrom = $this->makeRefFrom($this->table, $this->row['uid']);
430 if (!empty($referencesFrom)) {
431 $content .= $this->doc->section($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:show_item.php.referencesFromThisItem'), $referencesFrom);
432 }
433 break;
434 }
435
436 case 'file': {
437 if ($this->fileObject && $this->fileObject->isIndexed()) {
438 $references = $this->makeRef('_FILE', $this->fileObject);
439
440 if (!empty($references)) {
441 $header = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:show_item.php.referencesToThisItem');
442 $content .= $this->doc->section($header, $references);
443 }
444 }
445 break;
446 }
447 }
448
449 return $content;
450 }
451
452 /**
453 * Render a back button, if a returnUrl was provided
454 *
455 * @return string
456 */
457 protected function renderBackButton() {
458 $backLink = '';
459 $returnUrl = GeneralUtility::_GET('returnUrl');
460 if ($returnUrl) {
461 $backLink .= '
462 <a class="btn btn-primary" href="' . htmlspecialchars($returnUrl) . '>
463 ' . IconUtility::getSpriteIcon('actions-view-go-back') . '
464 ' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_common.xlf:back', TRUE) . '
465 </a>';
466 }
467 return $backLink;
468 }
469
470 /**
471 * Renders file properties as html table
472 *
473 * @param array $fieldList
474 * @return string
475 */
476 protected function renderFileInformationAsTable($fieldList) {
477 $tableRows = array();
478 foreach ($fieldList as $name) {
479 if (!isset($GLOBALS['TCA'][$this->table]['columns'][$name])) {
480 continue;
481 }
482 $isExcluded = !(!$GLOBALS['TCA'][$this->table]['columns'][$name]['exclude'] || $GLOBALS['BE_USER']->check('non_exclude_fields', $this->table . ':' . $name));
483 if ($isExcluded) {
484 continue;
485 }
486 $uid = $this->row['uid'];
487 $itemValue = BackendUtility::getProcessedValue($this->table, $name, $this->row[$name], 0, 0, FALSE, $uid);
488 $itemLabel = $GLOBALS['LANG']->sL(BackendUtility::getItemLabel($this->table, $name), TRUE);
489 $tableRows[] = '
490 <tr>
491 <th>' . $itemLabel . '</th>
492 <td>' . htmlspecialchars($itemValue) . '</td>
493 </tr>';
494 }
495
496 if (!$tableRows) {
497 return '';
498 }
499
500 return '
501 <div class="table-fit table-fit-wrap">
502 <table class="table table-striped table-hover">
503 ' . implode('', $tableRows) . '
504 </table>
505 </div>';
506 }
507
508 /**
509 * End page and print content
510 *
511 * @return void
512 */
513 public function printContent() {
514 echo $this->doc->startPage($this->titleTag) .
515 $this->doc->insertStylesAndJS($this->content) .
516 $this->doc->endPage();
517 }
518
519 /**
520 * Get field name for specified table/column name
521 *
522 * @param string $tableName Table name
523 * @param string $fieldName Column name
524 * @return string label
525 */
526 public function getLabelForTableColumn($tableName, $fieldName) {
527 if ($GLOBALS['TCA'][$tableName]['columns'][$fieldName]['label'] !== NULL) {
528 $field = $GLOBALS['LANG']->sL($GLOBALS['TCA'][$tableName]['columns'][$fieldName]['label']);
529 if (trim($field) === '') {
530 $field = $fieldName;
531 }
532 } else {
533 $field = $fieldName;
534 }
535 return $field;
536 }
537
538 /**
539 * Returns the rendered record actions
540 *
541 * @param string $table
542 * @param int $uid
543 * @return string
544 */
545 protected function getRecordActions($table, $uid) {
546 if ($table === '' || $uid < 0) {
547 return '';
548 }
549
550 // Edit button
551 $editOnClick = BackendUtility::editOnClick('&edit[' . $table . '][' . $uid . ']=edit');
552 $pageActionIcons = '
553 <a class="btn btn-default btn-sm" href="#" onclick="' . htmlspecialchars($editOnClick) . '">
554 ' . IconUtility::getSpriteIcon('actions-document-open') . '
555 </a>';
556
557 // History button
558 $historyOnClick = 'window.location.href=' .
559 GeneralUtility::quoteJSvalue(
560 BackendUtility::getModuleUrl(
561 'record_history',
562 array(
563 'element' => $table . ':' . $uid,
564 'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI')
565 )
566 )
567 ) . '; return false;';
568 $pageActionIcons .= '
569 <a class="btn btn-default btn-sm" href="#" onclick="' . htmlspecialchars($historyOnClick) . '">
570 ' . IconUtility::getSpriteIcon('actions-document-history-open') . '
571 </a>';
572
573 if ($table === 'pages') {
574 // Recordlist button
575 $url = BackendUtility::getModuleUrl('web_list', array('id' => $uid, 'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI')));
576 $pageActionIcons .= '
577 <a class="btn btn-default btn-sm" href="' . htmlspecialchars($url) . '" title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:labels.showList') . '">
578 ' . IconUtility::getSpriteIcon('actions-system-list-open') . '
579 </a>';
580
581 // View page button
582 $viewOnClick = BackendUtility::viewOnClick($uid, '', BackendUtility::BEgetRootLine($uid));
583 $pageActionIcons .= '
584 <a class="btn btn-default btn-sm" href="#" onclick="' . htmlspecialchars($viewOnClick) . '" title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:labels.showPage', TRUE) . '">
585 ' . IconUtility::getSpriteIcon('actions-document-view') . '
586 </a>';
587 }
588
589 return '
590 <div class="btn-group" role="group">
591 ' . $pageActionIcons . '
592 </div>';
593 }
594
595 /**
596 * Make reference display
597 *
598 * @param string $table Table name
599 * @param string|\TYPO3\CMS\Core\Resource\File $ref Filename or uid
600 * @return string HTML
601 */
602 protected function makeRef($table, $ref) {
603 // Files reside in sys_file table
604 if ($table === '_FILE') {
605 $selectTable = 'sys_file';
606 $selectUid = $ref->getUid();
607 } else {
608 $selectTable = $table;
609 $selectUid = $ref;
610 }
611 $rows = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
612 '*',
613 'sys_refindex',
614 'ref_table=' . $GLOBALS['TYPO3_DB']->fullQuoteStr($selectTable, 'sys_refindex') . ' AND ref_uid=' . (int)$selectUid . ' AND deleted=0'
615 );
616
617 // Compile information for title tag:
618 $infoData = array();
619 $infoDataHeader = '';
620 if (count($rows)) {
621 $infoDataHeader = '
622 <tr>
623 <th class="col-icon"></th>
624 <th class="col-title">' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:show_item.php.title') . '</th>
625 <th>' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:show_item.php.table') . '</th>
626 <th>' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:show_item.php.uid') . '</th>
627 <th>' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:show_item.php.field') . '</th>
628 <th>' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:show_item.php.flexpointer') . '</th>
629 <th>' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:show_item.php.softrefKey') . '</th>
630 <th>' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:show_item.php.sorting') . '</th>
631 <th class="col-control"></th>
632 </tr>';
633 }
634 foreach ($rows as $row) {
635 if ($row['tablename'] === 'sys_file_reference') {
636 $row = $this->transformFileReferenceToRecordReference($row);
637 if ($row['tablename'] === NULL || $row['recuid'] === NULL) {
638 return '';
639 }
640 }
641 $record = BackendUtility::getRecord($row['tablename'], $row['recuid']);
642 if ($record) {
643 $parentRecord = BackendUtility::getRecord('pages', $record['pid']);
644 $parentRecordTitle = is_array($parentRecord)
645 ? BackendUtility::getRecordTitle('pages', $parentRecord)
646 : '';
647 $icon = IconUtility::getSpriteIconForRecord($row['tablename'], $record);
648 $actions = $this->getRecordActions($row['tablename'], $row['recuid']);
649 $editOnClick = BackendUtility::editOnClick('&edit[' . $row['tablename'] . '][' . $row['recuid'] . ']=edit');
650 $infoData[] = '
651 <tr>
652 <td class="col-icon">
653 <a href="#" onclick="' . htmlspecialchars($editOnClick) . '" title="id=' . $record['uid'] . '">
654 ' . $icon . '
655 </a>
656 </td>
657 <td class="col-title">
658 <a href="#" onclick="' . htmlspecialchars($editOnClick) . '" title="id=' . $record['uid'] . '" >
659 ' . BackendUtility::getRecordTitle($row['tablename'], $record, TRUE) . '
660 </a>
661 </td>
662 <td>' . $GLOBALS['LANG']->sL($GLOBALS['TCA'][$row['tablename']]['ctrl']['title'], TRUE) . '</td>
663 <td>
664 <span title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_common.xlf:page') . ': '
665 . htmlspecialchars($parentRecordTitle) . ' (uid=' . $record['pid'] . ')">
666 ' . $record['uid'] . '
667 </span>
668 </td>
669 <td>' . htmlspecialchars($this->getLabelForTableColumn($row['tablename'], $row['field'])) . '</td>
670 <td>' . htmlspecialchars($row['flexpointer']) . '</td>
671 <td>' . htmlspecialchars($row['softref_key']) . '</td>
672 <td>' . htmlspecialchars($row['sorting']) . '</td>
673 <td class="col-control">' . $actions . '</td>
674 </tr>';
675 } else {
676 $infoData[] = '
677 <tr>
678 <td class="col-icon"></td>
679 <td class="col-title">' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:show_item.php.missing_record') . ' (uid=' . $row['recuid'] . ')</td>
680 <td>' . htmlspecialchars($GLOBALS['LANG']->sL($GLOBALS['TCA'][$row['tablename']]['ctrl']['title']) ?: $row['tablename']) . '</td>
681 <td></td>
682 <td>' . htmlspecialchars($this->getLabelForTableColumn($row['tablename'], $row['field'])) . '</td>
683 <td>' . htmlspecialchars($row['flexpointer']) . '</td>
684 <td>' . htmlspecialchars($row['softref_key']) . '</td>
685 <td>' . htmlspecialchars($row['sorting']) . '</td>
686 <td class="col-control"></td>
687 </tr>';
688 }
689 }
690 $referenceLine = '';
691 if (count($infoData)) {
692 $referenceLine = '
693 <div class="table-fit">
694 <table class="table table-striped table-hover">
695 <thead>' . $infoDataHeader . '</thead>
696 <tbody>' . implode('', $infoData) . '</tbody>
697 </table>
698 </div>';
699 }
700 return $referenceLine;
701 }
702
703 /**
704 * Make reference display (what this elements points to)
705 *
706 * @param string $table Table name
707 * @param string $ref Filename or uid
708 * @return string HTML
709 */
710 protected function makeRefFrom($table, $ref) {
711 $rows = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
712 '*',
713 'sys_refindex',
714 'tablename=' . $GLOBALS['TYPO3_DB']->fullQuoteStr($table, 'sys_refindex') . ' AND recuid=' . (int)$ref
715 );
716
717 // Compile information for title tag:
718 $infoData = array();
719 if (count($rows)) {
720 $infoDataHeader = '
721 <tr>
722 <th class="col-icon"></th>
723 <th class="col-title">' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:show_item.php.title') . '</th>
724 <th>' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:show_item.php.table') . '</th>
725 <th>' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:show_item.php.uid') . '</th>
726 <th>' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:show_item.php.field') . '</th>
727 <th>' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:show_item.php.flexpointer') . '</th>
728 <th>' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:show_item.php.softrefKey') . '</th>
729 <th>' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:show_item.php.sorting') . '</th>
730 <th>' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:show_item.php.refString') . '</th>
731 <th class="col-control"></th>
732 </tr>';
733 }
734 foreach ($rows as $row) {
735 $record = BackendUtility::getRecord($row['ref_table'], $row['ref_uid']);
736 $parentRecord = BackendUtility::getRecord('pages', $record['pid']);
737 $icon = IconUtility::getSpriteIconForRecord($row['tablename'], $record);
738 $actions = $this->getRecordActions($row['ref_table'], $row['ref_uid']);
739 $editOnClick = BackendUtility::editOnClick('&edit[' . $row['ref_table'] . '][' . $row['ref_uid'] . ']=edit');
740 $infoData[] = '
741 <tr>
742 <td class="col-icon">
743 <a href="#" onclick="' . htmlspecialchars($editOnClick) . '" title="id=' . $record['uid'] . '">
744 ' . $icon . '
745 </a>
746 </td>
747 <td class="col-title">
748 <a href="#" onclick="' . htmlspecialchars($editOnClick) . '" title="id=' . $record['uid'] . '" >
749 ' . BackendUtility::getRecordTitle($row['ref_table'], $record, TRUE) . '
750 </a>
751 </td>
752 <td>' . $GLOBALS['LANG']->sL($GLOBALS['TCA'][$row['ref_table']]['ctrl']['title'], TRUE) . '</td>
753 <td>' . htmlspecialchars($row['ref_uid']) . '</td>
754 <td>' . htmlspecialchars($this->getLabelForTableColumn($table, $row['field'])) . '</td>
755 <td>' . htmlspecialchars($row['flexpointer']) . '</td>
756 <td>' . htmlspecialchars($row['softref_key']) . '</td>
757 <td>' . htmlspecialchars($row['sorting']) . '</td>
758 <td>' . htmlspecialchars($row['ref_string']) . '</td>
759 <td class="col-control">' . $actions . '</td>
760 </tr>';
761 }
762
763 if (empty($infoData)) {
764 return;
765 }
766
767 return '
768 <div class="table-fit">
769 <table class="table table-striped table-hover">
770 <thead>' . $infoDataHeader . '</thead>
771 <tbody>' . implode('', $infoData) . '</tbody>
772 </table>
773 </div>';
774 }
775
776 /**
777 * Convert FAL file reference (sys_file_reference) to reference index (sys_refindex) table format
778 *
779 * @param array $referenceRecord
780 * @return array
781 */
782 protected function transformFileReferenceToRecordReference(array $referenceRecord) {
783 $fileReference = $GLOBALS['TYPO3_DB']->exec_SELECTgetSingleRow(
784 '*',
785 'sys_file_reference',
786 'uid=' . (int)$referenceRecord['recuid']
787 );
788 return array(
789 'recuid' => $fileReference['uid_foreign'],
790 'tablename' => $fileReference['tablenames'],
791 'field' => $fileReference['fieldname'],
792 'flexpointer' => '',
793 'softref_key' => '',
794 'sorting' => $fileReference['sorting_foreign']
795 );
796 }
797
798 }