Fixed bug 10056: Misspelling english word "guesbooks"
[Packages/TYPO3.CMS.git] / typo3 / show_item.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 1999-2008 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,$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
213 // Starting the page by creating page header stuff:
214 $this->content.=$this->doc->startPage($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:show_item.php.viewItem'));
215 $this->content.=$this->doc->header($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:show_item.php.viewItem'));
216 $this->content.=$this->doc->spacer(5);
217 }
218
219 /**
220 * Main function. Will generate the information to display for the item set internally.
221 *
222 * @return void
223 */
224 function main() {
225
226 if ($this->access) {
227 $returnLinkTag = t3lib_div::_GP('returnUrl') ? '<a href="'.t3lib_div::_GP('returnUrl').'" class="typo3-goBack">' : '<a href="#" onclick="window.close();">';
228
229 // render type by user func
230 $typeRendered = false;
231 if (is_array ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/show_item.php']['typeRendering'])) {
232 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/show_item.php']['typeRendering'] as $classRef) {
233 $typeRenderObj = t3lib_div::getUserObj($classRef);
234 if(is_object($typeRenderObj) && method_exists($typeRenderObj, 'isValid') && method_exists($typeRenderObj, 'render')) {
235 if ($typeRenderObj->isValid($this->type, $this)) {
236 $this->content .= $typeRenderObj->render($this->type, $this);
237 $typeRendered = true;
238 break;
239 }
240 }
241 }
242 }
243
244 // if type was not rendered use default rendering functions
245 if(!$typeRendered) {
246 // Branch out based on type:
247 switch($this->type) {
248 case 'db':
249 $this->renderDBInfo();
250 break;
251 case 'file':
252 $this->renderFileInfo($returnLinkTag);
253 break;
254 }
255 }
256
257 // If return Url is set, output link to go back:
258 if (t3lib_div::_GP('returnUrl')) {
259 $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;
260
261 $this->content .= $this->doc->section('','<br />'.$returnLinkTag.'<strong>'.$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:labels.goBack',1).'</strong></a>');
262 }
263 }
264 }
265
266 /**
267 * Main function. Will generate the information to display for the item set internally.
268 *
269 * @return void
270 */
271 function renderDBInfo() {
272 global $TCA;
273
274 // Print header, path etc:
275 $code = $this->doc->getHeader($this->table,$this->row,$this->pageinfo['_thePath'],1).'<br />';
276 $this->content.= $this->doc->section('',$code);
277
278 // Initialize variables:
279 $tableRows = Array();
280 $i = 0;
281
282 // Traverse the list of fields to display for the record:
283 $fieldList = t3lib_div::trimExplode(',',$TCA[$this->table]['interface']['showRecordFieldList'],1);
284 foreach($fieldList as $name) {
285 $name = trim($name);
286 if ($TCA[$this->table]['columns'][$name]) {
287 if (!$TCA[$this->table]['columns'][$name]['exclude'] || $GLOBALS['BE_USER']->check('non_exclude_fields',$this->table.':'.$name)) {
288 $i++;
289 $tableRows[] = '
290 <tr>
291 <td class="bgColor5">'.$GLOBALS['LANG']->sL(t3lib_BEfunc::getItemLabel($this->table,$name),1).'</td>
292 <td class="bgColor4">'.htmlspecialchars(t3lib_BEfunc::getProcessedValue($this->table,$name,$this->row[$name])).'</td>
293 </tr>';
294 }
295 }
296 }
297
298 // Create table from the information:
299 $tableCode = '
300 <table border="0" cellpadding="1" cellspacing="1" id="typo3-showitem">
301 '.implode('',$tableRows).'
302 </table>';
303 $this->content.=$this->doc->section('',$tableCode);
304 $this->content.=$this->doc->divider(2);
305
306 // Add path and table information in the bottom:
307 $code = '';
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($TCA[$this->table]['ctrl']['title']).' ('.$this->table.') - UID: '.$this->uid.'<br />';
310 $this->content.= $this->doc->section('', $code);
311
312 // References:
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']));
314
315 // References:
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']));
317 }
318
319 /**
320 * Main function. Will generate the information to display for the item set internally.
321 *
322 * @param string <a> tag closing/returning.
323 * @return void
324 */
325 function renderFileInfo($returnLinkTag) {
326
327 // Initialize object to work on the image:
328 require_once(PATH_t3lib.'class.t3lib_stdgraphic.php');
329 $imgObj = t3lib_div::makeInstance('t3lib_stdGraphic');
330 $imgObj->init();
331 $imgObj->mayScaleUp = 0;
332 $imgObj->absPrefix = PATH_site;
333
334 // Read Image Dimensions (returns false if file was not an image type, otherwise dimensions in an array)
335 $imgInfo = '';
336 $imgInfo = $imgObj->getImageDimensions($this->file);
337
338 // File information
339 $fI = t3lib_div::split_fileref($this->file);
340 $ext = $fI['fileext'];
341
342 $code = '';
343
344 // Setting header:
345 $icon = t3lib_BEfunc::getFileIcon($ext);
346 $url = 'gfx/fileicons/'.$icon;
347 $fileName = '<img src="'.$url.'" width="18" height="16" align="top" alt="" /><strong>'.$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:show_item.php.file', 1).':</strong> '.$fI['file'];
348 if (t3lib_div::isFirstPartOfStr($this->file,PATH_site)) {
349 $code.= '<a href="../'.substr($this->file,strlen(PATH_site)).'" target="_blank">'.$fileName.'</a>';
350 } else {
351 $code.= $fileName;
352 }
353 $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 />
354 ';
355 if (is_array($imgInfo)) {
356 $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');
357 }
358 $this->content.=$this->doc->section('',$code);
359 $this->content.=$this->doc->divider(2);
360
361 // If the file was an image...:
362 if (is_array($imgInfo)) {
363
364 $imgInfo = $imgObj->imageMagickConvert($this->file,'web','346','200m','','','',1);
365 $imgInfo[3] = '../'.substr($imgInfo[3],strlen(PATH_site));
366 $code = '<br />
367 <div align="center">'.$returnLinkTag.$imgObj->imgTag($imgInfo).'</a></div>';
368 $this->content.= $this->doc->section('', $code);
369 } else {
370 $this->content.= $this->doc->spacer(10);
371 $lowerFilename = strtolower($this->file);
372
373 // Archive files:
374 if (TYPO3_OS!='WIN' && !$GLOBALS['TYPO3_CONF_VARS']['BE']['disable_exec_function']) {
375 if ($ext=='zip') {
376 $code = '';
377 $t = array();
378 exec('unzip -l '.$this->file, $t);
379 if (is_array($t)) {
380 reset($t);
381 next($t);
382 next($t);
383 next($t);
384 while(list(,$val)=each($t)) {
385 $parts = explode(' ',trim($val),7);
386 $code.= '
387 '.$parts[6].'<br />';
388 }
389 $code = '
390 <span class="nobr">'.$code.'
391 </span>
392 <br /><br />';
393 }
394 $this->content.= $this->doc->section('', $code);
395 } elseif($ext=='tar' || $ext=='tgz' || substr($lowerFilename,-6)=='tar.gz' || substr($lowerFilename,-5)=='tar.z') {
396 $code = '';
397 if ($ext=='tar') {
398 $compr = '';
399 } else {
400 $compr = 'z';
401 }
402 $t = array();
403 exec('tar t'.$compr.'f '.$this->file, $t);
404 if (is_array($t)) {
405 foreach($t as $val) {
406 $code.='
407 '.$val.'<br />';
408 }
409
410 $code.='
411 -------<br/>
412 '.count($t).' '.$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:show_item.php.files');
413
414 $code = '
415 <span class="nobr">'.$code.'
416 </span>
417 <br /><br />';
418 }
419 $this->content.= $this->doc->section('',$code);
420 }
421 } elseif ($GLOBALS['TYPO3_CONF_VARS']['BE']['disable_exec_function']) {
422 $this->content.= $this->doc->section('',$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:show_item.php.cannotDisplayArchive'));
423 }
424
425 // Font files:
426 if ($ext=='ttf') {
427 $thumbScript = 'thumbs.php';
428 $check = basename($this->file).':'.filemtime($this->file).':'.$GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey'];
429 $params = '&file='.rawurlencode($this->file);
430 $params.= '&md5sum='.t3lib_div::shortMD5($check);
431 $url = $thumbScript.'?&dummy='.$GLOBALS['EXEC_TIME'].$params;
432 $thumb = '<br />
433 <div align="center">'.$returnLinkTag.'<img src="'.htmlspecialchars($url).'" border="0" title="'.htmlspecialchars(trim($this->file)).'" alt="" /></a></div>';
434 $this->content.= $this->doc->section('',$thumb);
435 }
436 }
437
438
439 // References:
440 $this->content.= $this->doc->section($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:show_item.php.referencesToThisItem'),$this->makeRef('_FILE',$this->file));
441 }
442
443 /**
444 * End page and print content
445 *
446 * @return void
447 */
448 function printContent() {
449 $this->content.= $this->doc->endPage();
450 $this->content = $this->doc->insertStylesAndJS($this->content);
451 echo $this->content;
452 }
453
454 /**
455 * Make reference display
456 *
457 * @param string Table name
458 * @param string Filename or uid
459 * @return string HTML
460 */
461 function makeRef($table,$ref) {
462
463 if ($table==='_FILE') {
464 // First, fit path to match what is stored in the refindex:
465 $fullIdent = $ref;
466
467 if (t3lib_div::isFirstPartOfStr($fullIdent,PATH_site)) {
468 $fullIdent = substr($fullIdent,strlen(PATH_site));
469 }
470
471 // Look up the path:
472 $rows = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
473 '*',
474 'sys_refindex',
475 'ref_table='.$GLOBALS['TYPO3_DB']->fullQuoteStr('_FILE','sys_refindex').
476 ' AND ref_string='.$GLOBALS['TYPO3_DB']->fullQuoteStr($fullIdent,'sys_refindex').
477 ' AND deleted=0'
478 );
479 } else {
480 // Look up the path:
481 $rows = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
482 '*',
483 'sys_refindex',
484 'ref_table='.$GLOBALS['TYPO3_DB']->fullQuoteStr($table,'sys_refindex').
485 ' AND ref_uid='.intval($ref).
486 ' AND deleted=0'
487 );
488 }
489
490 // Compile information for title tag:
491 $infoData = array();
492 if (count($rows)) {
493 $infoData[] = '<tr class="bgColor5 tableheader">' .
494 '<td>'.$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:show_item.php.table').'</td>' .
495 '<td>'.$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:show_item.php.uid').'</td>' .
496 '<td>'.$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:show_item.php.field').'</td>'.
497 '<td>'.$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:show_item.php.flexpointer').'</td>'.
498 '<td>'.$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:show_item.php.softrefKey').'</td>'.
499 '<td>'.$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:show_item.php.sorting').'</td>'.
500 '</tr>';
501 }
502 foreach($rows as $row) {
503 $infoData[] = '<tr class="bgColor4"">' .
504 '<td>'.$row['tablename'].'</td>' .
505 '<td>'.$row['recuid'].'</td>' .
506 '<td>'.$row['field'].'</td>'.
507 '<td>'.$row['flexpointer'].'</td>'.
508 '<td>'.$row['softref_key'].'</td>'.
509 '<td>'.$row['sorting'].'</td>'.
510 '</tr>';
511 }
512
513 return count($infoData) ? '<table border="0" cellpadding="1" cellspacing="1">'.implode('',$infoData).'</table>' : '';
514 }
515
516 /**
517 * Make reference display (what this elements points to)
518 *
519 * @param string Table name
520 * @param string Filename or uid
521 * @return string HTML
522 */
523 function makeRefFrom($table,$ref) {
524
525 // Look up the path:
526 $rows = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
527 '*',
528 'sys_refindex',
529 'tablename='.$GLOBALS['TYPO3_DB']->fullQuoteStr($table,'sys_refindex').
530 ' AND recuid='.intval($ref)
531 );
532
533 // Compile information for title tag:
534 $infoData = array();
535 if (count($rows)) {
536 $infoData[] = '<tr class="bgColor5 tableheader">' .
537 '<td>'.$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:show_item.php.field').'</td>'.
538 '<td>'.$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:show_item.php.flexpointer').'</td>'.
539 '<td>'.$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:show_item.php.softrefKey').'</td>'.
540 '<td>'.$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:show_item.php.sorting').'</td>'.
541 '<td>'.$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:show_item.php.refTable').'</td>' .
542 '<td>'.$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:show_item.php.refUid').'</td>' .
543 '<td>'.$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:show_item.php.refString').'</td>' .
544 '</tr>';
545 }
546 foreach($rows as $row) {
547 $infoData[] = '<tr class="bgColor4"">' .
548 '<td>'.$row['field'].'</td>'.
549 '<td>'.$row['flexpointer'].'</td>'.
550 '<td>'.$row['softref_key'].'</td>'.
551 '<td>'.$row['sorting'].'</td>'.
552 '<td>'.$row['ref_table'].'</td>' .
553 '<td>'.$row['ref_uid'].'</td>' .
554 '<td>'.$row['ref_string'].'</td>' .
555 '</tr>';
556 }
557
558 return count($infoData) ? '<table border="0" cellpadding="1" cellspacing="1">'.implode('',$infoData).'</table>' : '';
559 }
560 }
561
562
563 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/show_item.php']) {
564 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/show_item.php']);
565 }
566
567
568
569 // Make instance:
570 $SOBE = t3lib_div::makeInstance('SC_show_item');
571 $SOBE->init();
572 $SOBE->main();
573 $SOBE->printContent();
574
575 ?>