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