56ac0ce2b22cfcf6855f91fa5f94b2fb7e8bccc9
[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 $processedFile = $this->fileObject->process(
283 ProcessedFile::CONTEXT_IMAGEPREVIEW,
284 array(
285 'width' => '590m',
286 'height' => '400m'
287 )
288 );
289 // Create thumbnail image?
290 if ($processedFile) {
291 $thumbUrl = $processedFile->getPublicUrl(TRUE);
292 $previewTag .= '<img class="img-responsive img-thumbnail" src="' . $thumbUrl . '" ' .
293 'width="' . $processedFile->getProperty('width') . '" ' .
294 'height="' . $processedFile->getProperty('height') . '" ' .
295 'alt="' . htmlspecialchars(trim($this->fileObject->getName())) . '" ' .
296 'title="' . htmlspecialchars(trim($this->fileObject->getName())) . '" />';
297 }
298 }
299
300 // Download
301 if ($url) {
302 $downloadLink .= '
303 <a class="btn btn-primary" href="' . htmlspecialchars($url) . '" target="_blank">
304 ' . IconUtility::getSpriteIcon('actions-edit-download') . '
305 ' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_common.xlf:download', TRUE) . '
306 </a>';
307 }
308 }
309
310 return ($previewTag ? '<p>' . $previewTag . '</p>' : '') .
311 ($downloadLink ? '<p>' . $downloadLink . '</p>' : '');
312 }
313
314 /**
315 * Render property array as html table
316 *
317 * @return string
318 */
319 protected function renderPropertiesAsTable() {
320 $tableRows = array();
321 $extraFields = array();
322
323 if (in_array($this->type, array('folder', 'file'), TRUE)) {
324 if ($this->type === 'file') {
325 $extraFields['creation_date'] = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_general.xlf:LGL.creationDate', TRUE);
326 $extraFields['modification_date'] = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_general.xlf:LGL.timestamp', TRUE);
327 }
328 $extraFields['storage'] = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_tca.xlf:sys_file.storage', TRUE);
329 $extraFields['folder'] = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_common.xlf:folder', TRUE);
330 } else {
331 $extraFields['crdate'] = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_general.xlf:LGL.creationDate', TRUE);
332 $extraFields['cruser_id'] = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_general.xlf:LGL.creationUserId', TRUE);
333 $extraFields['tstamp'] = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_general.xlf:LGL.timestamp', TRUE);
334
335 // check if the special fields are defined in the TCA ctrl section of the table
336 foreach ($extraFields as $fieldName => $fieldLabel) {
337 if (isset($GLOBALS['TCA'][$this->table]['ctrl'][$fieldName])) {
338 $extraFields[$GLOBALS['TCA'][$this->table]['ctrl'][$fieldName]] = $fieldLabel;
339 } else {
340 unset($extraFields[$fieldName]);
341 }
342 }
343 }
344
345 foreach ($extraFields as $name => $fieldLabel) {
346 $rowValue = '';
347 if (!isset($this->row[$name])) {
348 $resourceObject = $this->fileObject ?: $this->folderObject;
349 if ($name === 'storage') {
350 $rowValue = $resourceObject->getStorage()->getName();
351 } elseif ($name === 'folder') {
352 $rowValue = $resourceObject->getParentFolder()->getIdentifier();
353 }
354 } elseif (in_array($name, array('creation_date', 'modification_date'), TRUE)) {
355 $rowValue = BackendUtility::datetime($this->row[$name]);
356 } else {
357 $rowValue = BackendUtility::getProcessedValueExtra($this->table, $name, $this->row[$name]);
358 }
359 // show the backend username who created the issue
360 if ($name === 'cruser_id' && $rowValue) {
361 $userTemp = $GLOBALS['TYPO3_DB']->exec_SELECTgetSingleRow('username, realName', 'be_users', 'uid = ' . (int)$rowValue);
362 if ($userTemp[0]['username'] !== '') {
363 $rowValue = $userTemp[0]['username'];
364 if ($userTemp[0]['realName'] !== '') {
365 $rowValue .= ' - ' . $userTemp[0]['realName'];
366 }
367 }
368 }
369 $tableRows[] = '
370 <tr>
371 <th>' . rtrim($fieldLabel, ':') . '</th>
372 <td>' . htmlspecialchars($rowValue) . '</td>
373 </tr>';
374 }
375
376 // Traverse the list of fields to display for the record:
377 $fieldList = GeneralUtility::trimExplode(',', $GLOBALS['TCA'][$this->table]['interface']['showRecordFieldList'], TRUE);
378 foreach ($fieldList as $name) {
379 $name = trim($name);
380 $uid = $this->row['uid'];
381
382 if (!isset($GLOBALS['TCA'][$this->table]['columns'][$name])) {
383 continue;
384 }
385
386 // Storage is already handled above
387 if ($this->type === 'file' && $name === 'storage') {
388 continue;
389 }
390
391 $isExcluded = !(!$GLOBALS['TCA'][$this->table]['columns'][$name]['exclude'] || $GLOBALS['BE_USER']->check('non_exclude_fields', $this->table . ':' . $name));
392 if ($isExcluded) {
393 continue;
394 }
395
396 $itemValue = BackendUtility::getProcessedValue($this->table, $name, $this->row[$name], 0, 0, FALSE, $uid);
397 $itemLabel = $GLOBALS['LANG']->sL(BackendUtility::getItemLabel($this->table, $name), TRUE);
398 $tableRows[] = '
399 <tr>
400 <th>' . $itemLabel . '</th>
401 <td>' . htmlspecialchars($itemValue) . '</td>
402 </tr>';
403 }
404
405 return '
406 <div class="table-fit table-fit-wrap">
407 <table class="table table-striped table-hover">
408 ' . implode('', $tableRows) . '
409 </table>
410 </div>';
411 }
412
413 /**
414 * Render references section (references from and references to current record)
415 *
416 * @return string
417 */
418 protected function renderReferences() {
419 $content = '';
420
421 switch ($this->type) {
422 case 'db': {
423 $references = $this->makeRef($this->table, $this->row['uid']);
424 if (!empty($references)) {
425 $content .= $this->doc->section($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:show_item.php.referencesToThisItem'), $references);
426 }
427
428 $referencesFrom = $this->makeRefFrom($this->table, $this->row['uid']);
429 if (!empty($referencesFrom)) {
430 $content .= $this->doc->section($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:show_item.php.referencesFromThisItem'), $referencesFrom);
431 }
432 break;
433 }
434
435 case 'file': {
436 if ($this->fileObject && $this->fileObject->isIndexed()) {
437 $references = $this->makeRef('_FILE', $this->fileObject);
438
439 if (!empty($references)) {
440 $header = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:show_item.php.referencesToThisItem');
441 $content .= $this->doc->section($header, $references);
442 }
443 }
444 break;
445 }
446 }
447
448 return $content;
449 }
450
451 /**
452 * Render a back button, if a returnUrl was provided
453 *
454 * @return string
455 */
456 protected function renderBackButton() {
457 $backLink = '';
458 $returnUrl = GeneralUtility::_GET('returnUrl');
459 if ($returnUrl) {
460 $backLink .= '
461 <a class="btn btn-primary" href="' . htmlspecialchars($returnUrl) . '>
462 ' . IconUtility::getSpriteIcon('actions-view-go-back') . '
463 ' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_common.xlf:back', TRUE) . '
464 </a>';
465 }
466 return $backLink;
467 }
468
469 /**
470 * Renders file properties as html table
471 *
472 * @param array $fieldList
473 * @return string
474 */
475 protected function renderFileInformationAsTable($fieldList) {
476 $tableRows = array();
477 foreach ($fieldList as $name) {
478 if (!isset($GLOBALS['TCA'][$this->table]['columns'][$name])) {
479 continue;
480 }
481 $isExcluded = !(!$GLOBALS['TCA'][$this->table]['columns'][$name]['exclude'] || $GLOBALS['BE_USER']->check('non_exclude_fields', $this->table . ':' . $name));
482 if ($isExcluded) {
483 continue;
484 }
485 $uid = $this->row['uid'];
486 $itemValue = BackendUtility::getProcessedValue($this->table, $name, $this->row[$name], 0, 0, FALSE, $uid);
487 $itemLabel = $GLOBALS['LANG']->sL(BackendUtility::getItemLabel($this->table, $name), TRUE);
488 $tableRows[] = '
489 <tr>
490 <th>' . $itemLabel . '</th>
491 <td>' . htmlspecialchars($itemValue) . '</td>
492 </tr>';
493 }
494
495 if (!$tableRows) {
496 return '';
497 }
498
499 return '
500 <div class="table-fit table-fit-wrap">
501 <table class="table table-striped table-hover">
502 ' . implode('', $tableRows) . '
503 </table>
504 </div>';
505 }
506
507 /**
508 * End page and print content
509 *
510 * @return void
511 */
512 public function printContent() {
513 echo $this->doc->startPage($this->titleTag) .
514 $this->doc->insertStylesAndJS($this->content) .
515 $this->doc->endPage();
516 }
517
518 /**
519 * Get field name for specified table/column name
520 *
521 * @param string $tableName Table name
522 * @param string $fieldName Column name
523 * @return string label
524 */
525 public function getLabelForTableColumn($tableName, $fieldName) {
526 if ($GLOBALS['TCA'][$tableName]['columns'][$fieldName]['label'] !== NULL) {
527 $field = $GLOBALS['LANG']->sL($GLOBALS['TCA'][$tableName]['columns'][$fieldName]['label']);
528 if (trim($field) === '') {
529 $field = $fieldName;
530 }
531 } else {
532 $field = $fieldName;
533 }
534 return $field;
535 }
536
537 /**
538 * Returns the rendered record actions
539 *
540 * @param string $table
541 * @param int $uid
542 * @return string
543 */
544 protected function getRecordActions($table, $uid) {
545 if ($table === '' || $uid < 0) {
546 return '';
547 }
548
549 // Edit button
550 $editOnClick = BackendUtility::editOnClick('&edit[' . $table . '][' . $uid . ']=edit');
551 $pageActionIcons = '
552 <a class="btn btn-default btn-sm" href="#" onclick="' . htmlspecialchars($editOnClick) . '">
553 ' . IconUtility::getSpriteIcon('actions-document-open') . '
554 </a>';
555
556 // History button
557 $historyOnClick = 'window.location.href=' .
558 GeneralUtility::quoteJSvalue(
559 BackendUtility::getModuleUrl(
560 'record_history',
561 array(
562 'element' => $table . ':' . $uid,
563 'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI')
564 )
565 )
566 ) . '; return false;';
567 $pageActionIcons .= '
568 <a class="btn btn-default btn-sm" href="#" onclick="' . htmlspecialchars($historyOnClick) . '">
569 ' . IconUtility::getSpriteIcon('actions-document-history-open') . '
570 </a>';
571
572 if ($table === 'pages') {
573 // Recordlist button
574 $url = BackendUtility::getModuleUrl('web_list', array('id' => $uid, 'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI')));
575 $pageActionIcons .= '
576 <a class="btn btn-default btn-sm" href="' . htmlspecialchars($url) . '" title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:labels.showList') . '">
577 ' . IconUtility::getSpriteIcon('actions-system-list-open') . '
578 </a>';
579
580 // View page button
581 $viewOnClick = BackendUtility::viewOnClick($uid, '', BackendUtility::BEgetRootLine($uid));
582 $pageActionIcons .= '
583 <a class="btn btn-default btn-sm" href="#" onclick="' . htmlspecialchars($viewOnClick) . '" title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:labels.showPage', TRUE) . '">
584 ' . IconUtility::getSpriteIcon('actions-document-view') . '
585 </a>';
586 }
587
588 return '
589 <div class="btn-group" role="group">
590 ' . $pageActionIcons . '
591 </div>';
592 }
593
594 /**
595 * Make reference display
596 *
597 * @param string $table Table name
598 * @param string|\TYPO3\CMS\Core\Resource\File $ref Filename or uid
599 * @return string HTML
600 */
601 protected function makeRef($table, $ref) {
602 // Files reside in sys_file table
603 if ($table === '_FILE') {
604 $selectTable = 'sys_file';
605 $selectUid = $ref->getUid();
606 } else {
607 $selectTable = $table;
608 $selectUid = $ref;
609 }
610 $rows = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
611 '*',
612 'sys_refindex',
613 'ref_table=' . $GLOBALS['TYPO3_DB']->fullQuoteStr($selectTable, 'sys_refindex') . ' AND ref_uid=' . (int)$selectUid . ' AND deleted=0'
614 );
615
616 // Compile information for title tag:
617 $infoData = array();
618 $infoDataHeader = '';
619 if (count($rows)) {
620 $infoDataHeader = '
621 <tr>
622 <th class="col-icon"></th>
623 <th class="col-title">' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:show_item.php.title') . '</th>
624 <th>' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:show_item.php.table') . '</th>
625 <th>' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:show_item.php.uid') . '</th>
626 <th>' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:show_item.php.field') . '</th>
627 <th>' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:show_item.php.flexpointer') . '</th>
628 <th>' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:show_item.php.softrefKey') . '</th>
629 <th>' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:show_item.php.sorting') . '</th>
630 <th class="col-control"></th>
631 </tr>';
632 }
633 foreach ($rows as $row) {
634 if ($row['tablename'] === 'sys_file_reference') {
635 $row = $this->transformFileReferenceToRecordReference($row);
636 if ($row['tablename'] === NULL || $row['recuid'] === NULL) {
637 return '';
638 }
639 }
640 $record = BackendUtility::getRecord($row['tablename'], $row['recuid']);
641 if ($record) {
642 $parentRecord = BackendUtility::getRecord('pages', $record['pid']);
643 $parentRecordTitle = is_array($parentRecord)
644 ? BackendUtility::getRecordTitle('pages', $parentRecord)
645 : '';
646 $icon = IconUtility::getSpriteIconForRecord($row['tablename'], $record);
647 $actions = $this->getRecordActions($row['tablename'], $row['recuid']);
648 $editOnClick = BackendUtility::editOnClick('&edit[' . $row['tablename'] . '][' . $row['recuid'] . ']=edit');
649 $infoData[] = '
650 <tr>
651 <td class="col-icon">
652 <a href="#" onclick="' . htmlspecialchars($editOnClick) . '" title="id=' . $record['uid'] . '">
653 ' . $icon . '
654 </a>
655 </td>
656 <td class="col-title">
657 <a href="#" onclick="' . htmlspecialchars($editOnClick) . '" title="id=' . $record['uid'] . '" >
658 ' . BackendUtility::getRecordTitle($row['tablename'], $record, TRUE) . '
659 </a>
660 </td>
661 <td>' . $GLOBALS['LANG']->sL($GLOBALS['TCA'][$row['tablename']]['ctrl']['title'], TRUE) . '</td>
662 <td>
663 <span title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_common.xlf:page') . ': '
664 . htmlspecialchars($parentRecordTitle) . ' (uid=' . $record['pid'] . ')">
665 ' . $record['uid'] . '
666 </span>
667 </td>
668 <td>' . htmlspecialchars($this->getLabelForTableColumn($row['tablename'], $row['field'])) . '</td>
669 <td>' . htmlspecialchars($row['flexpointer']) . '</td>
670 <td>' . htmlspecialchars($row['softref_key']) . '</td>
671 <td>' . htmlspecialchars($row['sorting']) . '</td>
672 <td class="col-control">' . $actions . '</td>
673 </tr>';
674 } else {
675 $infoData[] = '
676 <tr>
677 <td class="col-icon"></td>
678 <td class="col-title">' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:show_item.php.missing_record') . ' (uid=' . $row['recuid'] . ')</td>
679 <td>' . htmlspecialchars($GLOBALS['LANG']->sL($GLOBALS['TCA'][$row['tablename']]['ctrl']['title']) ?: $row['tablename']) . '</td>
680 <td></td>
681 <td>' . htmlspecialchars($this->getLabelForTableColumn($row['tablename'], $row['field'])) . '</td>
682 <td>' . htmlspecialchars($row['flexpointer']) . '</td>
683 <td>' . htmlspecialchars($row['softref_key']) . '</td>
684 <td>' . htmlspecialchars($row['sorting']) . '</td>
685 <td class="col-control"></td>
686 </tr>';
687 }
688 }
689 $referenceLine = '';
690 if (count($infoData)) {
691 $referenceLine = '
692 <div class="table-fit">
693 <table class="table table-striped table-hover">
694 <thead>' . $infoDataHeader . '</thead>
695 <tbody>' . implode('', $infoData) . '</tbody>
696 </table>
697 </div>';
698 }
699 return $referenceLine;
700 }
701
702 /**
703 * Make reference display (what this elements points to)
704 *
705 * @param string $table Table name
706 * @param string $ref Filename or uid
707 * @return string HTML
708 */
709 protected function makeRefFrom($table, $ref) {
710 $rows = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
711 '*',
712 'sys_refindex',
713 'tablename=' . $GLOBALS['TYPO3_DB']->fullQuoteStr($table, 'sys_refindex') . ' AND recuid=' . (int)$ref
714 );
715
716 // Compile information for title tag:
717 $infoData = array();
718 if (count($rows)) {
719 $infoDataHeader = '
720 <tr>
721 <th class="col-icon"></th>
722 <th class="col-title">' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:show_item.php.title') . '</th>
723 <th>' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:show_item.php.table') . '</th>
724 <th>' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:show_item.php.uid') . '</th>
725 <th>' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:show_item.php.field') . '</th>
726 <th>' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:show_item.php.flexpointer') . '</th>
727 <th>' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:show_item.php.softrefKey') . '</th>
728 <th>' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:show_item.php.sorting') . '</th>
729 <th>' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:show_item.php.refString') . '</th>
730 <th class="col-control"></th>
731 </tr>';
732 }
733 foreach ($rows as $row) {
734 $record = BackendUtility::getRecord($row['ref_table'], $row['ref_uid']);
735 $parentRecord = BackendUtility::getRecord('pages', $record['pid']);
736 $icon = IconUtility::getSpriteIconForRecord($row['tablename'], $record);
737 $actions = $this->getRecordActions($row['ref_table'], $row['ref_uid']);
738 $editOnClick = BackendUtility::editOnClick('&edit[' . $row['ref_table'] . '][' . $row['ref_uid'] . ']=edit');
739 $infoData[] = '
740 <tr>
741 <td class="col-icon">
742 <a href="#" onclick="' . htmlspecialchars($editOnClick) . '" title="id=' . $record['uid'] . '">
743 ' . $icon . '
744 </a>
745 </td>
746 <td class="col-title">
747 <a href="#" onclick="' . htmlspecialchars($editOnClick) . '" title="id=' . $record['uid'] . '" >
748 ' . BackendUtility::getRecordTitle($row['ref_table'], $record, TRUE) . '
749 </a>
750 </td>
751 <td>' . $GLOBALS['LANG']->sL($GLOBALS['TCA'][$row['ref_table']]['ctrl']['title'], TRUE) . '</td>
752 <td>' . htmlspecialchars($row['ref_uid']) . '</td>
753 <td>' . htmlspecialchars($this->getLabelForTableColumn($table, $row['field'])) . '</td>
754 <td>' . htmlspecialchars($row['flexpointer']) . '</td>
755 <td>' . htmlspecialchars($row['softref_key']) . '</td>
756 <td>' . htmlspecialchars($row['sorting']) . '</td>
757 <td>' . htmlspecialchars($row['ref_string']) . '</td>
758 <td class="col-control">' . $actions . '</td>
759 </tr>';
760 }
761
762 if (empty($infoData)) {
763 return;
764 }
765
766 return '
767 <div class="table-fit">
768 <table class="table table-striped table-hover">
769 <thead>' . $infoDataHeader . '</thead>
770 <tbody>' . implode('', $infoData) . '</tbody>
771 </table>
772 </div>';
773 }
774
775 /**
776 * Convert FAL file reference (sys_file_reference) to reference index (sys_refindex) table format
777 *
778 * @param array $referenceRecord
779 * @return array
780 */
781 protected function transformFileReferenceToRecordReference(array $referenceRecord) {
782 $fileReference = $GLOBALS['TYPO3_DB']->exec_SELECTgetSingleRow(
783 '*',
784 'sys_file_reference',
785 'uid=' . (int)$referenceRecord['recuid']
786 );
787 return array(
788 'recuid' => $fileReference['uid_foreign'],
789 'tablename' => $fileReference['tablenames'],
790 'field' => $fileReference['fieldname'],
791 'flexpointer' => '',
792 'softref_key' => '',
793 'sorting' => $fileReference['sorting_foreign']
794 );
795 }
796
797 }