[TASK] Change "true" into "TRUE"
[Packages/TYPO3.CMS.git] / typo3 / show_item.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 1999-2011 Kasper Skårhøj (kasperYYYY@typo3.com)
6 * All rights reserved
7 *
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.
13 *
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.
18 *
19 *
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.
24 *
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
27 /**
28 * Shows information about a database or file item
29 *
30 * Revised for TYPO3 3.7 May/2004 by Kasper Skårhøj
31 *
32 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
33 */
34 /**
35 * [CLASS/FUNCTION INDEX of SCRIPT]
36 *
37 *
38 *
39 * 84: class transferData extends t3lib_transferData
40 * 101: function regItem($table, $id, $field, $content)
41 *
42 *
43 * 135: class SC_show_item
44 * 160: function init()
45 * 225: function main()
46 * 273: function renderDBInfo()
47 * 327: function renderFileInfo($returnLinkTag)
48 * 449: function printContent()
49 * 462: function makeRef($table,$ref)
50 * 524: function makeRefFrom($table,$ref)
51 *
52 * TOTAL FUNCTIONS: 8
53 * (This index is automatically created/updated by the extension "extdeveval")
54 *
55 */
56
57
58 $BACK_PATH = '';
59 require($BACK_PATH.'init.php');
60 require($BACK_PATH.'template.php');
61
62
63
64
65
66
67
68
69
70
71
72
73 /**
74 * Extension of transfer data class
75 *
76 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
77 * @package TYPO3
78 * @subpackage core
79 */
80 class transferData extends t3lib_transferData {
81
82 var $formname = 'loadform';
83 var $loading = 1;
84
85 // Extra for show_item.php:
86 var $theRecord = Array();
87
88 /**
89 * Register item function.
90 *
91 * @param string Table name
92 * @param integer Record uid
93 * @param string Field name
94 * @param string Content string.
95 * @return void
96 */
97 function regItem($table, $id, $field, $content) {
98 t3lib_div::loadTCA($table);
99 $config = $GLOBALS['TCA'][$table]['columns'][$field]['config'];
100 switch($config['type']) {
101 case 'input':
102 if (isset($config['checkbox']) && $content==$config['checkbox']) {$content=''; break;}
103 if (t3lib_div::inList($config['eval'],'date')) {$content = Date($GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy'],$content); }
104 break;
105 case 'group':
106 break;
107 case 'select':
108 break;
109 }
110 $this->theRecord[$field]=$content;
111 }
112 }
113
114
115
116
117
118
119
120
121
122
123
124 /**
125 * Script Class for showing information about an item.
126 *
127 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
128 * @package TYPO3
129 * @subpackage core
130 */
131 class SC_show_item {
132
133 // GET vars:
134 var $table; // Record table (or filename)
135 var $uid; // Record uid (or '' when filename)
136
137 // Internal, static:
138 var $perms_clause; // Page select clause
139 var $access; // If TRUE, access to element is granted
140 var $type; // Which type of element: "file" or "db"
141 var $doc; // Document Template Object
142
143 // Internal, dynamic:
144 var $content; // Content Accumulation
145 var $file; // For type "file": Filename
146 var $pageinfo; // For type "db": Set to page record of the parent page of the item set (if type="db")
147 var $row; // For type "db": The database record row.
148
149
150 /**
151 * Initialization of the class
152 * 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.
153 *
154 * @return void
155 */
156 function init() {
157 global $BACK_PATH;
158
159 // Setting input variables.
160 $this->table = t3lib_div::_GET('table');
161 $this->uid = t3lib_div::_GET('uid');
162
163 // Initialize:
164 $this->perms_clause = $GLOBALS['BE_USER']->getPagePermsClause(1);
165 $this->access = 0; // Set to TRUE if there is access to the record / file.
166 $this->type = ''; // Sets the type, "db" or "file". If blank, nothing can be shown.
167
168 // Checking if the $table value is really a table and if the user has access to it.
169 if (isset($GLOBALS['TCA'][$this->table])) {
170 t3lib_div::loadTCA($this->table);
171 $this->type = 'db';
172 $this->uid = intval($this->uid);
173
174 // Check permissions and uid value:
175 if ($this->uid && $GLOBALS['BE_USER']->check('tables_select',$this->table)) {
176 if ((string)$this->table=='pages') {
177 $this->pageinfo = t3lib_BEfunc::readPageAccess($this->uid,$this->perms_clause);
178 $this->access = is_array($this->pageinfo) ? 1 : 0;
179 $this->row = $this->pageinfo;
180 } else {
181 $this->row = t3lib_BEfunc::getRecordWSOL($this->table, $this->uid);
182 if ($this->row) {
183 $this->pageinfo = t3lib_BEfunc::readPageAccess($this->row['pid'],$this->perms_clause);
184 $this->access = is_array($this->pageinfo) ? 1 : 0;
185 }
186 }
187
188 $treatData = t3lib_div::makeInstance('t3lib_transferData');
189 $treatData->renderRecord($this->table, $this->uid, 0, $this->row);
190 $cRow = $treatData->theRecord;
191 }
192 } else {
193 // if the filereference $this->file is relative, we correct the path
194 if (substr($this->table,0,3)=='../') {
195 $this->file = PATH_site.preg_replace('/^\.\.\//','',$this->table);
196 } else {
197 $this->file = $this->table;
198 }
199 if (@is_file($this->file) && t3lib_div::isAllowedAbsPath($this->file)) {
200 $this->type = 'file';
201 $this->access = 1;
202 }
203 }
204
205 // Initialize document template object:
206 $this->doc = t3lib_div::makeInstance('template');
207 $this->doc->backPath = $BACK_PATH;
208
209 // Starting the page by creating page header stuff:
210 $this->content.=$this->doc->startPage($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:show_item.php.viewItem'));
211 $this->content.='<h3 class="t3-row-header">' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:show_item.php.viewItem') . '</h3>';
212 $this->content.=$this->doc->spacer(5);
213 }
214
215 /**
216 * Main function. Will generate the information to display for the item set internally.
217 *
218 * @return void
219 */
220 function main() {
221
222 if ($this->access) {
223 $returnLink = t3lib_div::sanitizeLocalUrl(t3lib_div::_GP('returnUrl'));
224 $returnLinkTag = $returnLink ? '<a href="' . $returnLink . '" class="typo3-goBack">' : '<a href="#" onclick="window.close();">';
225
226 // render type by user func
227 $typeRendered = false;
228 if (is_array ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/show_item.php']['typeRendering'])) {
229 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/show_item.php']['typeRendering'] as $classRef) {
230 $typeRenderObj = t3lib_div::getUserObj($classRef);
231 if(is_object($typeRenderObj) && method_exists($typeRenderObj, 'isValid') && method_exists($typeRenderObj, 'render')) {
232 if ($typeRenderObj->isValid($this->type, $this)) {
233 $this->content .= $typeRenderObj->render($this->type, $this);
234 $typeRendered = TRUE;
235 break;
236 }
237 }
238 }
239 }
240
241 // if type was not rendered use default rendering functions
242 if(!$typeRendered) {
243 // Branch out based on type:
244 switch($this->type) {
245 case 'db':
246 $this->renderDBInfo();
247 break;
248 case 'file':
249 $this->renderFileInfo($returnLinkTag);
250 break;
251 }
252 }
253
254 // If return Url is set, output link to go back:
255 if (t3lib_div::sanitizeLocalUrl(t3lib_div::_GP('returnUrl'))) {
256 $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;
257
258 $this->content .= $this->doc->section('','<br />'.$returnLinkTag.'<strong>'.$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:labels.goBack',1).'</strong></a>');
259 }
260 }
261 }
262
263 /**
264 * Main function. Will generate the information to display for the item set internally.
265 *
266 * @return void
267 */
268 function renderDBInfo() {
269
270 // Print header, path etc:
271 $code = $this->doc->getHeader($this->table,$this->row,$this->pageinfo['_thePath'],1).'<br />';
272 $this->content.= $this->doc->section('',$code);
273
274 // Initialize variables:
275 $tableRows = Array();
276 $i = 0;
277
278 // Traverse the list of fields to display for the record:
279 $fieldList = t3lib_div::trimExplode(',', $GLOBALS['TCA'][$this->table]['interface']['showRecordFieldList'], 1);
280 foreach ($fieldList as $name) {
281 $name = trim($name);
282 if ($GLOBALS['TCA'][$this->table]['columns'][$name]) {
283 if (!$GLOBALS['TCA'][$this->table]['columns'][$name]['exclude'] || $GLOBALS['BE_USER']->check('non_exclude_fields', $this->table . ':' . $name)) {
284 $i++;
285 $tableRows[] = '
286 <tr>
287 <td class="t3-col-header">' . $GLOBALS['LANG']->sL(t3lib_BEfunc::getItemLabel($this->table, $name), 1) . '</td>
288 <td>' . htmlspecialchars(t3lib_BEfunc::getProcessedValue($this->table, $name, $this->row[$name], 0, 0, FALSE, $this->row['uid'])) . '</td>
289 </tr>';
290 }
291 }
292 }
293
294 // Create table from the information:
295 $tableCode = '
296 <table border="0" cellpadding="0" cellspacing="0" id="typo3-showitem" class="t3-table-info">
297 '.implode('',$tableRows).'
298 </table>';
299 $this->content.=$this->doc->section('',$tableCode);
300
301 // Add path and table information in the bottom:
302 $code = '';
303 $code .= $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:labels.path') . ': ' . t3lib_div::fixed_lgd_cs($this->pageinfo['_thePath'], -48) . '<br />';
304 $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 />';
305 $this->content.= $this->doc->section('', $code);
306
307 // References:
308 $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']));
309
310 // References:
311 $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']));
312 }
313
314 /**
315 * Main function. Will generate the information to display for the item set internally.
316 *
317 * @param string <a> tag closing/returning.
318 * @return void
319 */
320 function renderFileInfo($returnLinkTag) {
321
322 // Initialize object to work on the image:
323 $imgObj = t3lib_div::makeInstance('t3lib_stdGraphic');
324 $imgObj->init();
325 $imgObj->mayScaleUp = 0;
326 $imgObj->absPrefix = PATH_site;
327
328 // Read Image Dimensions (returns false if file was not an image type, otherwise dimensions in an array)
329 $imgInfo = '';
330 $imgInfo = $imgObj->getImageDimensions($this->file);
331
332 // File information
333 $fI = t3lib_div::split_fileref($this->file);
334 $ext = $fI['fileext'];
335
336 $code = '';
337
338 // Setting header:
339 $fileName = t3lib_iconWorks::getSpriteIconForFile($ext) . '<strong>' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:show_item.php.file', TRUE) . ':</strong> ' . $fI['file'];
340 if (t3lib_div::isFirstPartOfStr($this->file,PATH_site)) {
341 $code.= '<a href="../'.substr($this->file,strlen(PATH_site)).'" target="_blank">'.$fileName.'</a>';
342 } else {
343 $code.= $fileName;
344 }
345 $code.=' &nbsp;&nbsp;<strong>'.$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:show_item.php.filesize').':</strong> '.t3lib_div::formatSize(@filesize($this->file)).'<br />
346 ';
347 if (is_array($imgInfo)) {
348 $code.= '<strong>'.$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:show_item.php.dimensions').':</strong> '.$imgInfo[0].'x'.$imgInfo[1].' '.$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:show_item.php.pixels');
349 }
350 $this->content.=$this->doc->section('',$code);
351 $this->content.=$this->doc->divider(2);
352
353 // If the file was an image...:
354 if (is_array($imgInfo)) {
355
356 $imgInfo = $imgObj->imageMagickConvert($this->file,'web','346','200m','','','',1);
357 $imgInfo[3] = '../'.substr($imgInfo[3],strlen(PATH_site));
358 $code = '<br />
359 <div align="center">'.$returnLinkTag.$imgObj->imgTag($imgInfo).'</a></div>';
360 $this->content.= $this->doc->section('', $code);
361 } else {
362 $this->content.= $this->doc->spacer(10);
363 $lowerFilename = strtolower($this->file);
364
365 // Archive files:
366 if (TYPO3_OS!='WIN' && !$GLOBALS['TYPO3_CONF_VARS']['BE']['disable_exec_function']) {
367 if ($ext=='zip') {
368 $code = '';
369 $t = array();
370 t3lib_utility_Command::exec('unzip -l ' . $this->file, $t);
371 if (is_array($t)) {
372 reset($t);
373 next($t);
374 next($t);
375 next($t);
376 while(list(,$val)=each($t)) {
377 $parts = explode(' ',trim($val),7);
378 $code.= '
379 '.$parts[6].'<br />';
380 }
381 $code = '
382 <span class="nobr">'.$code.'
383 </span>
384 <br /><br />';
385 }
386 $this->content.= $this->doc->section('', $code);
387 } elseif($ext=='tar' || $ext=='tgz' || substr($lowerFilename,-6)=='tar.gz' || substr($lowerFilename,-5)=='tar.z') {
388 $code = '';
389 if ($ext=='tar') {
390 $compr = '';
391 } else {
392 $compr = 'z';
393 }
394 $t = array();
395 t3lib_utility_Command::exec('tar t' . $compr . 'f ' . $this->file, $t);
396 if (is_array($t)) {
397 foreach($t as $val) {
398 $code.='
399 '.$val.'<br />';
400 }
401
402 $code.='
403 -------<br/>
404 '.count($t).' '.$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:show_item.php.files');
405
406 $code = '
407 <span class="nobr">'.$code.'
408 </span>
409 <br /><br />';
410 }
411 $this->content.= $this->doc->section('',$code);
412 }
413 } elseif ($GLOBALS['TYPO3_CONF_VARS']['BE']['disable_exec_function']) {
414 $this->content.= $this->doc->section('',$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:show_item.php.cannotDisplayArchive'));
415 }
416
417 // Font files:
418 if ($ext=='ttf') {
419 $thumbScript = 'thumbs.php';
420 $check = basename($this->file).':'.filemtime($this->file).':'.$GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey'];
421 $params = '&file='.rawurlencode($this->file);
422 $params.= '&md5sum='.t3lib_div::shortMD5($check);
423 $url = $thumbScript.'?&dummy='.$GLOBALS['EXEC_TIME'].$params;
424 $thumb = '<br />
425 <div align="center">'.$returnLinkTag.'<img src="'.htmlspecialchars($url).'" border="0" title="'.htmlspecialchars(trim($this->file)).'" alt="" /></a></div>';
426 $this->content.= $this->doc->section('',$thumb);
427 }
428 }
429
430
431 // References:
432 $this->content.= $this->doc->section($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:show_item.php.referencesToThisItem'),$this->makeRef('_FILE',$this->file));
433 }
434
435 /**
436 * End page and print content
437 *
438 * @return void
439 */
440 function printContent() {
441 $this->content.= $this->doc->endPage();
442 $this->content = $this->doc->insertStylesAndJS($this->content);
443 echo $this->content;
444 }
445
446 /**
447 * Make reference display
448 *
449 * @param string Table name
450 * @param string Filename or uid
451 * @return string HTML
452 */
453 function makeRef($table,$ref) {
454
455 if ($table==='_FILE') {
456 // First, fit path to match what is stored in the refindex:
457 $fullIdent = $ref;
458
459 if (t3lib_div::isFirstPartOfStr($fullIdent,PATH_site)) {
460 $fullIdent = substr($fullIdent,strlen(PATH_site));
461 }
462
463 // Look up the path:
464 $rows = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
465 '*',
466 'sys_refindex',
467 'ref_table='.$GLOBALS['TYPO3_DB']->fullQuoteStr('_FILE','sys_refindex').
468 ' AND ref_string='.$GLOBALS['TYPO3_DB']->fullQuoteStr($fullIdent,'sys_refindex').
469 ' AND deleted=0'
470 );
471 } else {
472 // Look up the path:
473 $rows = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
474 '*',
475 'sys_refindex',
476 'ref_table='.$GLOBALS['TYPO3_DB']->fullQuoteStr($table,'sys_refindex').
477 ' AND ref_uid='.intval($ref).
478 ' AND deleted=0'
479 );
480 }
481
482 // Compile information for title tag:
483 $infoData = array();
484 if (count($rows)) {
485 $infoData[] = '<tr class="t3-row-header">' .
486 '<td>'.$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:show_item.php.table').'</td>' .
487 '<td>'.$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:show_item.php.uid').'</td>' .
488 '<td>'.$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:show_item.php.field').'</td>'.
489 '<td>'.$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:show_item.php.flexpointer').'</td>'.
490 '<td>'.$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:show_item.php.softrefKey').'</td>'.
491 '<td>'.$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:show_item.php.sorting').'</td>'.
492 '</tr>';
493 }
494 foreach($rows as $row) {
495 $infoData[] = '<tr class="bgColor4"">' .
496 '<td>'.$row['tablename'].'</td>' .
497 '<td>'.$row['recuid'].'</td>' .
498 '<td>'.$row['field'].'</td>'.
499 '<td>'.$row['flexpointer'].'</td>'.
500 '<td>'.$row['softref_key'].'</td>'.
501 '<td>'.$row['sorting'].'</td>'.
502 '</tr>';
503 }
504
505 return count($infoData) ? '<table border="0" cellpadding="0" cellspacing="0" class="typo3-dblist">' . implode('', $infoData) . '</table>' : '';
506 }
507
508 /**
509 * Make reference display (what this elements points to)
510 *
511 * @param string Table name
512 * @param string Filename or uid
513 * @return string HTML
514 */
515 function makeRefFrom($table,$ref) {
516
517 // Look up the path:
518 $rows = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
519 '*',
520 'sys_refindex',
521 'tablename='.$GLOBALS['TYPO3_DB']->fullQuoteStr($table,'sys_refindex').
522 ' AND recuid='.intval($ref)
523 );
524
525 // Compile information for title tag:
526 $infoData = array();
527 if (count($rows)) {
528 $infoData[] = '<tr class="t3-row-header">' .
529 '<td>'.$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:show_item.php.field').'</td>'.
530 '<td>'.$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:show_item.php.flexpointer').'</td>'.
531 '<td>'.$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:show_item.php.softrefKey').'</td>'.
532 '<td>'.$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:show_item.php.sorting').'</td>'.
533 '<td>'.$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:show_item.php.refTable').'</td>' .
534 '<td>'.$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:show_item.php.refUid').'</td>' .
535 '<td>'.$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:show_item.php.refString').'</td>' .
536 '</tr>';
537 }
538 foreach($rows as $row) {
539 $infoData[] = '<tr class="bgColor4"">' .
540 '<td>'.$row['field'].'</td>'.
541 '<td>'.$row['flexpointer'].'</td>'.
542 '<td>'.$row['softref_key'].'</td>'.
543 '<td>'.$row['sorting'].'</td>'.
544 '<td>'.$row['ref_table'].'</td>' .
545 '<td>'.$row['ref_uid'].'</td>' .
546 '<td>'.$row['ref_string'].'</td>' .
547 '</tr>';
548 }
549
550 return count($infoData) ? '<table border="0" cellpadding="0" cellspacing="0" class="typo3-dblist">' . implode('', $infoData) . '</table>' : '';
551 }
552 }
553
554
555 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['typo3/show_item.php'])) {
556 include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['typo3/show_item.php']);
557 }
558
559
560
561 // Make instance:
562 $SOBE = t3lib_div::makeInstance('SC_show_item');
563 $SOBE->init();
564 $SOBE->main();
565 $SOBE->printContent();
566
567 ?>