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