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');
52 * Extension of transfer data class
54 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
58 class transferData
extends t3lib_transferData
{
60 var $formname = 'loadform';
63 // Extra for show_item.php:
64 var $theRecord = Array();
67 * Register item function.
69 * @param string Table name
70 * @param integer Record uid
71 * @param string Field name
72 * @param string Content string.
75 function regItem($table, $id, $field, $content) {
76 t3lib_div
::loadTCA($table);
77 $config = $GLOBALS['TCA'][$table]['columns'][$field]['config'];
78 switch($config['type']) {
80 if (isset($config['checkbox']) && $content == $config['checkbox']) {
84 if (t3lib_div
::inList($config['eval'],'date')) {
85 $content = Date($GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy'], $content);
93 $this->theRecord
[$field]=$content;
108 * Script Class for showing information about an item.
110 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
117 var $table; // Record table (or filename)
118 var $uid; // Record uid (or '' when filename)
121 var $perms_clause; // Page select clause
122 var $access; // If TRUE, access to element is granted
123 var $type; // Which type of element: "file" or "db"
124 var $doc; // Document Template Object
126 // Internal, dynamic:
127 var $content; // Content Accumulation
128 var $pageinfo; // For type "db": Set to page record of the parent page of the item set (if type="db")
129 var $row; // For type "db": The database record row.
132 * The fileObject if present
134 * @var t3lib_file_AbstractFile
136 protected $fileObject;
139 * The folder obejct if present
141 * @var t3lib_file_Folder
143 protected $folderObject;
146 * Initialization of the class
147 * 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.
152 // Setting input variables.
153 $this->table
= t3lib_div
::_GET('table');
154 $this->uid
= t3lib_div
::_GET('uid');
157 $this->perms_clause
= $GLOBALS['BE_USER']->getPagePermsClause(1);
158 $this->access
= FALSE; // Set to TRUE if there is access to the record / file.
159 $this->type
= ''; // Sets the type, "db" or "file". If blank, nothing can be shown.
161 // Checking if the $table value is really a table and if the user has access to it.
162 if (isset($GLOBALS['TCA'][$this->table
])) {
163 t3lib_div
::loadTCA($this->table
);
165 $this->uid
= intval($this->uid
);
167 // Check permissions and uid value:
168 if ($this->uid
&& $GLOBALS['BE_USER']->check('tables_select',$this->table
)) {
169 if ((string)$this->table
== 'pages') {
170 $this->pageinfo
= t3lib_BEfunc
::readPageAccess($this->uid
,$this->perms_clause
);
171 $this->access
= is_array($this->pageinfo
) ?
1 : 0;
172 $this->row
= $this->pageinfo
;
174 $this->row
= t3lib_BEfunc
::getRecordWSOL($this->table
, $this->uid
);
176 $this->pageinfo
= t3lib_BEfunc
::readPageAccess($this->row
['pid'],$this->perms_clause
);
177 $this->access
= is_array($this->pageinfo
) ?
1 : 0;
181 $treatData = t3lib_div
::makeInstance('t3lib_transferData');
182 $treatData->renderRecord($this->table
, $this->uid
, 0, $this->row
);
183 $cRow = $treatData->theRecord
;
185 } elseif ($this->table
== '_FILE' ||
$this->table
== '_FOLDER' ||
$this->table
== 'sys_file') {
186 $fileOrFolderObject = t3lib_file_Factory
::getInstance()->retrieveFileOrFolderObject($this->uid
);
188 if ($fileOrFolderObject instanceof t3lib_file_Folder
) {
189 $this->folderObject
= $fileOrFolderObject;
190 $this->access
= $this->folderObject
->checkActionPermission('read');
191 $this->type
= 'folder';
193 $this->fileObject
= $fileOrFolderObject;
194 $this->access
= $this->fileObject
->checkActionPermission('read');
195 $this->type
= 'file';
196 $this->table
= 'sys_file';
197 t3lib_div
::loadTCA($this->table
);
199 $this->row
= t3lib_BEfunc
::getRecordWSOL($this->table
, $this->fileObject
->getUid());
200 } catch (Exception
$e) {
201 $this->row
= array();
208 // Initialize document template object:
209 $this->doc
= t3lib_div
::makeInstance('template');
210 $this->doc
->backPath
= $GLOBALS['BACK_PATH'];
212 // Starting the page by creating page header stuff:
213 $this->content
.=$this->doc
->startPage($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:show_item.php.viewItem'));
214 $this->content
.='<h3 class="t3-row-header">' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:show_item.php.viewItem') . '</h3>';
215 $this->content
.=$this->doc
->spacer(5);
219 * Main function. Will generate the information to display for the item set internally.
226 $returnLink = t3lib_div
::sanitizeLocalUrl(t3lib_div
::_GP('returnUrl'));
227 $returnLinkTag = $returnLink ?
'<a href="' . $returnLink . '" class="typo3-goBack">' : '<a href="#" onclick="window.close();">';
228 // render type by user func
229 $typeRendered = FALSE;
230 if (is_array ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/show_item.php']['typeRendering'])) {
231 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/show_item.php']['typeRendering'] as $classRef) {
232 $typeRenderObj = t3lib_div
::getUserObj($classRef);
233 if (is_object($typeRenderObj) && method_exists($typeRenderObj, 'isValid') && method_exists($typeRenderObj, 'render')) {
234 if ($typeRenderObj->isValid($this->type
, $this)) {
235 $this->content
.= $typeRenderObj->render($this->type
, $this);
236 $typeRendered = TRUE;
243 // if type was not rendered use default rendering functions
245 // Branch out based on type:
246 switch ($this->type
) {
248 $this->renderDBInfo();
251 $this->renderFileInfo($returnLinkTag);
254 // @todo: implement a info about a folder
259 // If return Url is set, output link to go back:
260 if (t3lib_div
::sanitizeLocalUrl(t3lib_div
::_GP('returnUrl'))) {
261 $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
;
263 $this->content
.= $this->doc
->section('','<br />'.$returnLinkTag.'<strong>'.$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:labels.goBack',1).'</strong></a>');
269 * Main function. Will generate the information to display for the item set internally.
273 function renderDBInfo() {
275 // Print header, path etc:
276 $code = $this->doc
->getHeader($this->table
,$this->row
,$this->pageinfo
['_thePath'],1).'<br />';
277 $this->content
.= $this->doc
->section('',$code);
279 // Initialize variables:
280 $tableRows = Array();
283 // Traverse the list of fields to display for the record:
284 $fieldList = t3lib_div
::trimExplode(',', $GLOBALS['TCA'][$this->table
]['interface']['showRecordFieldList'], 1);
285 foreach ($fieldList as $name) {
287 if ($GLOBALS['TCA'][$this->table
]['columns'][$name]) {
288 if (!$GLOBALS['TCA'][$this->table
]['columns'][$name]['exclude'] ||
$GLOBALS['BE_USER']->check('non_exclude_fields', $this->table
. ':' . $name)) {
292 <td class="t3-col-header">' . $GLOBALS['LANG']->sL(t3lib_BEfunc
::getItemLabel($this->table
, $name), 1) . '</td>
293 <td>' . htmlspecialchars(t3lib_BEfunc
::getProcessedValue($this->table
, $name, $this->row
[$name], 0, 0, FALSE, $this->row
['uid'])) . '</td>
299 // Create table from the information:
301 <table border="0" cellpadding="0" cellspacing="0" id="typo3-showitem" class="t3-table-info">
302 '.implode('',$tableRows).'
304 $this->content
.=$this->doc
->section('',$tableCode);
306 // Add path and table information in the bottom:
308 $code .= $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:labels.path') . ': ' . t3lib_div
::fixed_lgd_cs($this->pageinfo
['_thePath'], -48) . '<br />';
309 $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 />';
310 $this->content
.= $this->doc
->section('', $code);
313 $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']));
316 $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']));
320 * Main function. Will generate the information to display for the item set internally.
322 * @param string $returnLinkTag <a> tag closing/returning.
325 function renderFileInfo($returnLinkTag) {
326 $fileExtension = $this->fileObject
->getExtension();
328 $code = '<div class="fileInfoContainer">'
329 . t3lib_iconWorks
::getSpriteIconForFile($fileExtension) . '<strong>' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:show_item.php.file', TRUE) . ':</strong> ' . $this->fileObject
->getName()
331 . '<strong>' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:show_item.php.filesize') . ':</strong> '
332 . t3lib_div
::formatSize($this->fileObject
->getSize())
335 $this->content
.= $this->doc
->section('', $code);
336 $this->content
.= $this->doc
->divider(2);
338 // If the file was an image...
339 // @todo: add this check in the domain model in some kind of way, or in the processing folder
340 if (t3lib_div
::inList($GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'], $fileExtension)) {
341 // @todo: find a way to make getimagesize part of the t3lib_file object
342 $imgInfo = @getimagesize
($this->fileObject
->getForLocalProcessing(FALSE));
344 $thumbUrl = $this->fileObject
->process(
345 t3lib_file_ProcessedFile
::CONTEXT_IMAGEPREVIEW
,
346 array('width' => '150m', 'height' => '150m')
347 )->getPublicUrl(TRUE);
348 $code = '<div class="fileInfoContainer fileDimensions">'
349 . '<strong>' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:show_item.php.dimensions')
350 . ':</strong> ' . $imgInfo[0] . 'x' . $imgInfo[1] . ' '
351 . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:show_item.php.pixels') . '</div>';
353 <div align="center">' . $returnLinkTag . '<img src="' . $thumbUrl . '" alt="' . htmlspecialchars(trim($this->fileObject
->getName())) . '" title="' . htmlspecialchars(trim($this->fileObject
->getName())) . '" /></a></div>';
354 $this->content
.= $this->doc
->section('', $code);
355 } elseif ($fileExtension == 'ttf') {
356 $thumbUrl = $this->fileObject
->process(
357 t3lib_file_ProcessedFile
::CONTEXT_IMAGEPREVIEW
,
358 array('width' => '530m', 'height' => '600m')
359 )->getPublicUrl(TRUE);
361 <div align="center">' . $returnLinkTag . '<img src="' . $thumbUrl . '" border="0" title="' . htmlspecialchars(trim($this->fileObject
->getName())) . '" alt="" /></a></div>';
362 $this->content
.= $this->doc
->section('', $thumb);
365 // Initialize variables:
366 $tableRows = array();
369 // Traverse the list of fields to display for the record:
370 $fieldList = t3lib_div
::trimExplode(',', $GLOBALS['TCA'][$this->table
]['interface']['showRecordFieldList'], TRUE);
371 foreach ($fieldList as $name) {
373 if ($GLOBALS['TCA'][$this->table
]['columns'][$name]) {
374 if (!$GLOBALS['TCA'][$this->table
]['columns'][$name]['exclude'] ||
$GLOBALS['BE_USER']->check('non_exclude_fields', $this->table
. ':' . $name)) {
378 <td class="t3-col-header">' . $GLOBALS['LANG']->sL(t3lib_BEfunc
::getItemLabel($this->table
, $name), 1) . '</td>
379 <td>' . htmlspecialchars(t3lib_BEfunc
::getProcessedValue($this->table
, $name, $this->row
[$name], 0, 0, FALSE, $this->row
['uid'])) . '</td>
385 // Create table from the information:
387 <table border="0" cellpadding="0" cellspacing="0" id="typo3-showitem" class="t3-table-info">
388 ' . implode('', $tableRows) . '
390 $this->content
.= $this->doc
->section('', $tableCode);
393 if ($this->fileObject
->isIndexed()) {
395 $this->content
.= $this->doc
->section($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:show_item.php.referencesToThisItem'), $this->makeRef('_FILE', $this->fileObject
));
400 * End page and print content
404 function printContent() {
405 $this->content
.= $this->doc
->endPage();
406 $this->content
= $this->doc
->insertStylesAndJS($this->content
);
411 * Get table field name
413 * @param string $tableName Table name
414 * @param string $fieldName Field name
415 * @return string Field name
417 public function getFieldName($tableName, $fieldName) {
418 t3lib_div
::loadTCA($tableName);
419 if ($GLOBALS['TCA'][$tableName]['columns'][$fieldName]['label'] !== NULL) {
420 $field = $GLOBALS['LANG']->sL($GLOBALS['TCA'][$tableName]['columns'][$fieldName]['label']);
421 if (trim($field) === '') {
431 * Make reference display
433 * @param string $table Table name
434 * @param string $ref Filename or uid
435 * @return string HTML
437 function makeRef($table, $ref) {
439 if ($table === '_FILE') {
441 $rows = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
443 'sys_file_reference',
444 'uid_local=' . $ref->getUid()
448 $rows = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
451 'ref_table=' . $GLOBALS['TYPO3_DB']->fullQuoteStr($table,'sys_refindex') . ' AND ref_uid=' . intval($ref) .
455 // Compile information for title tag:
458 $infoData[] = '<tr class="t3-row-header">' .
459 '<td>' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:show_item.php.table') . '</td>' .
460 '<td>' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:show_item.php.title') . '</td>' .
462 '<td>' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:show_item.php.field') . '</td>' .
463 '<td>' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:show_item.php.flexpointer') . '</td>' .
464 '<td>' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:show_item.php.softrefKey') . '</td>' .
465 '<td>' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:show_item.php.sorting') . '</td>' .
468 foreach($rows as $row) {
469 if($table === '_FILE') {
470 $row = $this->mapFileReferenceOnRefIndex($row);
472 $record = t3lib_BEfunc
::getRecord($row['tablename'], $row['recuid']);
473 $infoData[] = '<tr class="bgColor4">' .
474 '<td>' . $GLOBALS['LANG']->sL($GLOBALS['TCA'][$row['tablename']]['ctrl']['title'], TRUE) . '</td>' .
475 '<td>' . t3lib_BEfunc
::getRecordTitle($row['tablename'], $record, TRUE) . '</td>' .
476 '<td><span title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_common.xlf:page') . ': ' .
477 htmlspecialchars(t3lib_BEfunc
::getRecordTitle('pages', t3lib_BEfunc
::getRecord('pages', $record['pid']))) .
478 " (uid=" . $record['pid'] . ')">' . $record['uid'] . '</span></td>' .
479 '<td>' . htmlspecialchars($this->getFieldName($row['tablename'], $row['field'])) . '</td>' .
480 '<td>' . htmlspecialchars($row['flexpointer']) . '</td>' .
481 '<td>' . htmlspecialchars($row['softref_key']) . '</td>' .
482 '<td>' . htmlspecialchars($row['sorting']) . '</td>' .
486 return count($infoData)
487 ?
'<table border="0" cellpadding="0" cellspacing="0" class="typo3-dblist">' . implode('', $infoData) . '</table>'
492 * Maps results from the fal file reference table on the
493 * structure of the normal reference index table.
495 * @param array $fileReference
498 protected function mapFileReferenceOnRefIndex(array $fileReference) {
500 'recuid' => $fileReference['uid_foreign'],
501 'tablename' => $fileReference['tablenames'],
502 'field' => $fileReference['fieldname'],
505 'sorting' => $fileReference['sorting_foreign']
510 * Make reference display (what this elements points to)
512 * @param $table string Table name
513 * @param $ref string Filename or uid
514 * @return string HTML
516 function makeRefFrom($table, $ref) {
519 $rows = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
522 'tablename=' . $GLOBALS['TYPO3_DB']->fullQuoteStr($table, 'sys_refindex') .
523 ' AND recuid=' . intval($ref)
526 // Compile information for title tag:
529 $infoData[] = '<tr class="t3-row-header">' .
530 '<td>' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:show_item.php.field') . '</td>' .
531 '<td>' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:show_item.php.flexpointer') . '</td>' .
532 '<td>' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:show_item.php.softrefKey') . '</td>' .
533 '<td>' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:show_item.php.sorting') . '</td>' .
534 '<td>' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:show_item.php.refTable') . '</td>' .
535 '<td>' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:show_item.php.refUid') . '</td>' .
536 '<td>' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:show_item.php.refString') . '</td>' .
539 foreach($rows as $row) {
540 $infoData[] = '<tr class="bgColor4">' .
541 '<td>' . htmlspecialchars($this->getFieldName($table, $row['field'])) . '</td>' .
542 '<td>' . htmlspecialchars($row['flexpointer']) . '</td>' .
543 '<td>' . htmlspecialchars($row['softref_key']) . '</td>' .
544 '<td>' . htmlspecialchars($row['sorting']) . '</td>' .
545 '<td>' . $GLOBALS['LANG']->sL($GLOBALS['TCA'][$row['ref_table']]['ctrl']['title'], TRUE) . '</td>' .
546 '<td>' . htmlspecialchars($row['ref_uid']) . '</td>' .
547 '<td>' . htmlspecialchars($row['ref_string']) . '</td>' .
551 return count($infoData)
552 ?
'<table border="0" cellpadding="0" cellspacing="0" class="typo3-dblist">' . implode('', $infoData) . '</table>'
558 $SOBE = t3lib_div
::makeInstance('SC_show_item');
561 $SOBE->printContent();