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