2 /***************************************************************
5 * (c) 1999-2011 Kasper Skårhøj (kasperYYYY@typo3.com)
8 * This script is part of the TYPO3 project. The TYPO3 project is
9 * free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
16 * A copy is found in the textfile GPL.txt and important notices to the license
17 * from the author is found in LICENSE.txt distributed with these scripts.
20 * This script is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
28 * Shows information about a database or file item
30 * Revised for TYPO3 3.7 May/2004 by Kasper Skårhøj
32 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
36 $GLOBALS['BACK_PATH'] = '';
37 require_once('init.php');
38 require_once('template.php');
41 * Extension of transfer data class
43 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
47 class transferData
extends t3lib_transferData
{
49 var $formname = 'loadform';
52 // Extra for show_item.php:
53 var $theRecord = Array();
56 * Register item function.
58 * @param string $table Table name
59 * @param integer $id Record uid
60 * @param string $field Field name
61 * @param string $content Content string.
64 function regItem($table, $id, $field, $content) {
65 t3lib_div
::loadTCA($table);
66 $config = $GLOBALS['TCA'][$table]['columns'][$field]['config'];
67 switch($config['type']) {
69 if (isset($config['checkbox']) && $content == $config['checkbox']) {
73 if (t3lib_div
::inList($config['eval'], 'date')) {
74 $content = Date($GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy'], $content);
82 $this->theRecord
[$field]=$content;
87 * Script Class for showing information about an item.
89 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
96 // Record table (or filename)
98 // Record uid (or '' when filename)
102 // Page select clause
104 // If TRUE, access to element is granted
106 // Which type of element: "file" or "db"
108 // Document Template Object
111 // Internal, dynamic:
112 // Content Accumulation
114 // For type "db": Set to page record of the parent page of the item set (if type="db")
116 // For type "db": The database record row.
120 * The fileObject if present
122 * @var t3lib_file_AbstractFile
124 protected $fileObject;
127 * The folder obejct if present
129 * @var t3lib_file_Folder
131 protected $folderObject;
134 * Initialization of the class
135 * Will determine if table/uid GET vars are database record or a file and if the user has access to view information about the item.
140 // Setting input variables.
141 $this->table
= t3lib_div
::_GET('table');
142 $this->uid
= t3lib_div
::_GET('uid');
145 $this->perms_clause
= $GLOBALS['BE_USER']->getPagePermsClause(1);
146 // Set to TRUE if there is access to the record / file.
147 $this->access
= FALSE
;
148 // Sets the type, "db" or "file". If blank, nothing can be shown.
151 // Checking if the $table value is really a table and if the user has access to it.
152 if (isset($GLOBALS['TCA'][$this->table
])) {
153 t3lib_div
::loadTCA($this->table
);
155 $this->uid
= intval($this->uid
);
157 // Check permissions and uid value:
158 if ($this->uid
&& $GLOBALS['BE_USER']->check('tables_select', $this->table
)) {
159 if ((string)$this->table
== 'pages') {
160 $this->pageinfo
= t3lib_BEfunc
::readPageAccess($this->uid
, $this->perms_clause
);
161 $this->access
= is_array($this->pageinfo
) ?
1 : 0;
162 $this->row
= $this->pageinfo
;
164 $this->row
= t3lib_BEfunc
::getRecordWSOL($this->table
, $this->uid
);
166 $this->pageinfo
= t3lib_BEfunc
::readPageAccess($this->row
['pid'], $this->perms_clause
);
167 $this->access
= is_array($this->pageinfo
) ?
1 : 0;
171 $treatData = t3lib_div
::makeInstance('t3lib_transferData');
172 $treatData->renderRecord($this->table
, $this->uid
, 0, $this->row
);
173 $cRow = $treatData->theRecord
;
175 } elseif ($this->table
== '_FILE' ||
$this->table
== '_FOLDER' ||
$this->table
== 'sys_file') {
176 $fileOrFolderObject = t3lib_file_Factory
::getInstance()->retrieveFileOrFolderObject($this->uid
);
178 if ($fileOrFolderObject instanceof t3lib_file_Folder
) {
179 $this->folderObject
= $fileOrFolderObject;
180 $this->access
= $this->folderObject
->checkActionPermission('read');
181 $this->type
= 'folder';
183 $this->fileObject
= $fileOrFolderObject;
184 $this->access
= $this->fileObject
->checkActionPermission('read');
185 $this->type
= 'file';
186 $this->table
= 'sys_file';
187 t3lib_div
::loadTCA($this->table
);
189 $this->row
= t3lib_BEfunc
::getRecordWSOL($this->table
, $this->fileObject
->getUid());
190 } catch (Exception
$e) {
191 $this->row
= array();
198 // Initialize document template object:
199 $this->doc
= t3lib_div
::makeInstance('template');
200 $this->doc
->backPath
= $GLOBALS['BACK_PATH'];
202 // Starting the page by creating page header stuff:
203 $this->content
.= $this->doc
->startPage($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:show_item.php.viewItem'));
204 $this->content
.= '<h3 class="t3-row-header">' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:show_item.php.viewItem') . '</h3>';
205 $this->content
.= $this->doc
->spacer(5);
209 * Main function. Will generate the information to display for the item set internally.
216 $returnLink = t3lib_div
::sanitizeLocalUrl(t3lib_div
::_GP('returnUrl'));
217 $returnLinkTag = $returnLink ?
'<a href="' . $returnLink . '" class="typo3-goBack">' : '<a href="#" onclick="window.close();">';
218 // render type by user func
219 $typeRendered = FALSE
;
220 if (is_array ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/show_item.php']['typeRendering'])) {
221 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/show_item.php']['typeRendering'] as $classRef) {
222 $typeRenderObj = t3lib_div
::getUserObj($classRef);
223 if (is_object($typeRenderObj) && method_exists($typeRenderObj, 'isValid') && method_exists($typeRenderObj, 'render')) {
224 if ($typeRenderObj->isValid($this->type
, $this)) {
225 $this->content
.= $typeRenderObj->render($this->type
, $this);
226 $typeRendered = TRUE
;
233 // If type was not rendered use default rendering functions
234 if (!$typeRendered) {
235 // Branch out based on type:
236 switch ($this->type
) {
238 $this->renderDBInfo();
241 $this->renderFileInfo($returnLinkTag);
244 // @todo: implement a info about a folder
249 // If return Url is set, output link to go back:
250 if (t3lib_div
::sanitizeLocalUrl(t3lib_div
::_GP('returnUrl'))) {
251 $this->content
= $this->doc
->section('', $returnLinkTag.'<strong>'.$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:labels.goBack', 1).'</strong></a><br /><br />').$this->content
;
253 $this->content
.= $this->doc
->section('', '<br />'.$returnLinkTag.'<strong>'.$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:labels.goBack', 1).'</strong></a>');
259 * Main function. Will generate the information to display for the item set internally.
263 function renderDBInfo() {
265 // Print header, path etc:
266 $code = $this->doc
->getHeader($this->table
, $this->row
, $this->pageinfo
['_thePath'], 1).'<br />';
267 $this->content
.= $this->doc
->section('', $code);
269 // Initialize variables:
270 $tableRows = array();
273 // Traverse the list of fields to display for the record:
274 $fieldList = t3lib_div
::trimExplode(',', $GLOBALS['TCA'][$this->table
]['interface']['showRecordFieldList'], 1);
275 foreach ($fieldList as $name) {
277 if ($GLOBALS['TCA'][$this->table
]['columns'][$name]) {
278 if (!$GLOBALS['TCA'][$this->table
]['columns'][$name]['exclude'] ||
$GLOBALS['BE_USER']->check('non_exclude_fields', $this->table
. ':' . $name)) {
282 <td class="t3-col-header">' . $GLOBALS['LANG']->sL(t3lib_BEfunc
::getItemLabel($this->table
, $name), 1) . '</td>
283 <td>' . htmlspecialchars(t3lib_BEfunc
::getProcessedValue($this->table
, $name, $this->row
[$name], 0, 0, FALSE
, $this->row
['uid'])) . '</td>
289 // Create table from the information:
291 <table border="0" cellpadding="0" cellspacing="0" id="typo3-showitem" class="t3-table-info">
292 '.implode('', $tableRows).'
294 $this->content
.= $this->doc
->section('', $tableCode);
296 // Add path and table information in the bottom:
298 $code .= $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:labels.path') . ': ' . t3lib_div
::fixed_lgd_cs($this->pageinfo
['_thePath'], -48) . '<br />';
299 $code .= $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:labels.table') . ': ' . $GLOBALS['LANG']->sL($GLOBALS['TCA'][$this->table
]['ctrl']['title']) . ' (' . $this->table
. ') - UID: ' . $this->uid
. '<br />';
300 $this->content
.= $this->doc
->section('', $code);
303 $this->content
.= $this->doc
->section($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:show_item.php.referencesToThisItem'), $this->makeRef($this->table
, $this->row
['uid']));
306 $this->content
.= $this->doc
->section($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:show_item.php.referencesFromThisItem'), $this->makeRefFrom($this->table
, $this->row
['uid']));
310 * Main function. Will generate the information to display for the item set internally.
312 * @param string $returnLinkTag <a> tag closing/returning.
315 function renderFileInfo($returnLinkTag) {
316 $fileExtension = $this->fileObject
->getExtension();
318 $code = '<div class="fileInfoContainer">'
319 . t3lib_iconWorks
::getSpriteIconForFile($fileExtension) . '<strong>' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:show_item.php.file', TRUE
) . ':</strong> ' . $this->fileObject
->getName()
321 . '<strong>' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:show_item.php.filesize') . ':</strong> '
322 . t3lib_div
::formatSize($this->fileObject
->getSize())
325 $this->content
.= $this->doc
->section('', $code);
326 $this->content
.= $this->doc
->divider(2);
328 // If the file was an image...
329 // @todo: add this check in the domain model in some kind of way, or in the processing folder
330 if (t3lib_div
::inList($GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'], $fileExtension)) {
331 // @todo: find a way to make getimagesize part of the t3lib_file object
332 $imgInfo = @getimagesize
($this->fileObject
->getForLocalProcessing(FALSE
));
334 $thumbUrl = $this->fileObject
->process(
335 t3lib_file_ProcessedFile
::CONTEXT_IMAGEPREVIEW
,
336 array('width' => '150m', 'height' => '150m')
337 )->getPublicUrl(TRUE
);
338 $code = '<div class="fileInfoContainer fileDimensions">'
339 . '<strong>' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:show_item.php.dimensions')
340 . ':</strong> ' . $imgInfo[0] . 'x' . $imgInfo[1] . ' '
341 . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:show_item.php.pixels') . '</div>';
343 <div align="center">' . $returnLinkTag . '<img src="' . $thumbUrl . '" alt="' . htmlspecialchars(trim($this->fileObject
->getName())) . '" title="' . htmlspecialchars(trim($this->fileObject
->getName())) . '" /></a></div>';
344 $this->content
.= $this->doc
->section('', $code);
345 } elseif ($fileExtension == 'ttf') {
346 $thumbUrl = $this->fileObject
->process(
347 t3lib_file_ProcessedFile
::CONTEXT_IMAGEPREVIEW
,
348 array('width' => '530m', 'height' => '600m')
349 )->getPublicUrl(TRUE
);
351 <div align="center">' . $returnLinkTag . '<img src="' . $thumbUrl . '" border="0" title="' . htmlspecialchars(trim($this->fileObject
->getName())) . '" alt="" /></a></div>';
352 $this->content
.= $this->doc
->section('', $thumb);
355 // Initialize variables:
356 $tableRows = array();
359 // Traverse the list of fields to display for the record:
360 $fieldList = t3lib_div
::trimExplode(',', $GLOBALS['TCA'][$this->table
]['interface']['showRecordFieldList'], TRUE
);
361 foreach ($fieldList as $name) {
363 if ($GLOBALS['TCA'][$this->table
]['columns'][$name]) {
364 if (!$GLOBALS['TCA'][$this->table
]['columns'][$name]['exclude'] ||
$GLOBALS['BE_USER']->check('non_exclude_fields', $this->table
. ':' . $name)) {
368 <td class="t3-col-header">' . $GLOBALS['LANG']->sL(t3lib_BEfunc
::getItemLabel($this->table
, $name), 1) . '</td>
369 <td>' . htmlspecialchars(t3lib_BEfunc
::getProcessedValue($this->table
, $name, $this->row
[$name], 0, 0, FALSE
, $this->row
['uid'])) . '</td>
375 // Create table from the information:
377 <table border="0" cellpadding="0" cellspacing="0" id="typo3-showitem" class="t3-table-info">
378 ' . implode('', $tableRows) . '
380 $this->content
.= $this->doc
->section('', $tableCode);
383 if ($this->fileObject
->isIndexed()) {
385 $this->content
.= $this->doc
->section($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:show_item.php.referencesToThisItem'), $this->makeRef('_FILE', $this->fileObject
));
390 * End page and print content
394 function printContent() {
395 $this->content
.= $this->doc
->endPage();
396 $this->content
= $this->doc
->insertStylesAndJS($this->content
);
401 * Get table field name
403 * @param string $tableName Table name
404 * @param string $fieldName Field name
405 * @return string Field name
407 public function getFieldName($tableName, $fieldName) {
408 t3lib_div
::loadTCA($tableName);
409 if ($GLOBALS['TCA'][$tableName]['columns'][$fieldName]['label'] !== NULL
) {
410 $field = $GLOBALS['LANG']->sL($GLOBALS['TCA'][$tableName]['columns'][$fieldName]['label']);
411 if (trim($field) === '') {
421 * Make reference display
423 * @param string $table Table name
424 * @param string $ref Filename or uid
425 * @return string HTML
427 function makeRef($table, $ref) {
429 if ($table === '_FILE') {
431 $rows = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
433 'sys_file_reference',
434 'uid_local=' . $ref->getUid()
438 $rows = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
441 'ref_table=' . $GLOBALS['TYPO3_DB']->fullQuoteStr($table, 'sys_refindex') . ' AND ref_uid=' . intval($ref) .
445 // Compile information for title tag:
448 $infoData[] = '<tr class="t3-row-header">' .
449 '<td>' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:show_item.php.table') . '</td>' .
450 '<td>' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:show_item.php.title') . '</td>' .
452 '<td>' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:show_item.php.field') . '</td>' .
453 '<td>' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:show_item.php.flexpointer') . '</td>' .
454 '<td>' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:show_item.php.softrefKey') . '</td>' .
455 '<td>' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:show_item.php.sorting') . '</td>' .
458 foreach ($rows as $row) {
459 if($table === '_FILE') {
460 $row = $this->mapFileReferenceOnRefIndex($row);
462 $record = t3lib_BEfunc
::getRecord($row['tablename'], $row['recuid']);
463 $infoData[] = '<tr class="bgColor4">' .
464 '<td>' . $GLOBALS['LANG']->sL($GLOBALS['TCA'][$row['tablename']]['ctrl']['title'], TRUE
) . '</td>' .
465 '<td>' . t3lib_BEfunc
::getRecordTitle($row['tablename'], $record, TRUE
) . '</td>' .
466 '<td><span title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_common.xlf:page') . ': ' .
467 htmlspecialchars(t3lib_BEfunc
::getRecordTitle('pages', t3lib_BEfunc
::getRecord('pages', $record['pid']))) .
468 ' (uid=' . $record['pid'] . ')">' . $record['uid'] . '</span></td>' .
469 '<td>' . htmlspecialchars($this->getFieldName($row['tablename'], $row['field'])) . '</td>' .
470 '<td>' . htmlspecialchars($row['flexpointer']) . '</td>' .
471 '<td>' . htmlspecialchars($row['softref_key']) . '</td>' .
472 '<td>' . htmlspecialchars($row['sorting']) . '</td>' .
476 return count($infoData)
477 ?
'<table border="0" cellpadding="0" cellspacing="0" class="typo3-dblist">' . implode('', $infoData) . '</table>'
482 * Maps results from the fal file reference table on the
483 * structure of the normal reference index table.
485 * @param array $fileReference
488 protected function mapFileReferenceOnRefIndex(array $fileReference) {
490 'recuid' => $fileReference['uid_foreign'],
491 'tablename' => $fileReference['tablenames'],
492 'field' => $fileReference['fieldname'],
495 'sorting' => $fileReference['sorting_foreign']
500 * Make reference display (what this elements points to)
502 * @param string $table Table name
503 * @param string $ref Filename or uid
504 * @return string HTML
506 function makeRefFrom($table, $ref) {
509 $rows = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
512 'tablename=' . $GLOBALS['TYPO3_DB']->fullQuoteStr($table, 'sys_refindex') .
513 ' AND recuid=' . intval($ref)
516 // Compile information for title tag:
519 $infoData[] = '<tr class="t3-row-header">' .
520 '<td>' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:show_item.php.field') . '</td>' .
521 '<td>' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:show_item.php.flexpointer') . '</td>' .
522 '<td>' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:show_item.php.softrefKey') . '</td>' .
523 '<td>' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:show_item.php.sorting') . '</td>' .
524 '<td>' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:show_item.php.refTable') . '</td>' .
525 '<td>' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:show_item.php.refUid') . '</td>' .
526 '<td>' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:show_item.php.refString') . '</td>' .
529 foreach ($rows as $row) {
530 $infoData[] = '<tr class="bgColor4">' .
531 '<td>' . htmlspecialchars($this->getFieldName($table, $row['field'])) . '</td>' .
532 '<td>' . htmlspecialchars($row['flexpointer']) . '</td>' .
533 '<td>' . htmlspecialchars($row['softref_key']) . '</td>' .
534 '<td>' . htmlspecialchars($row['sorting']) . '</td>' .
535 '<td>' . $GLOBALS['LANG']->sL($GLOBALS['TCA'][$row['ref_table']]['ctrl']['title'], TRUE
) . '</td>' .
536 '<td>' . htmlspecialchars($row['ref_uid']) . '</td>' .
537 '<td>' . htmlspecialchars($row['ref_string']) . '</td>' .
541 return count($infoData)
542 ?
'<table border="0" cellpadding="0" cellspacing="0" class="typo3-dblist">' . implode('', $infoData) . '</table>'
548 $SOBE = t3lib_div
::makeInstance('SC_show_item');
551 $SOBE->printContent();