[TASK] Remove global declarations inside methods
[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 $GLOBALS['BACK_PATH'] = '';
59 require('init.php');
60 require('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']) {
103 $content = '';
104 break;
105 }
106 if (t3lib_div::inList($config['eval'],'date')) {
107 $content = Date($GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy'], $content);
108 }
109 break;
110 case 'group':
111 break;
112 case 'select':
113 break;
114 }
115 $this->theRecord[$field]=$content;
116 }
117 }
118
119
120
121
122
123
124
125
126
127
128
129 /**
130 * Script Class for showing information about an item.
131 *
132 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
133 * @package TYPO3
134 * @subpackage core
135 */
136 class SC_show_item {
137
138 // GET vars:
139 var $table; // Record table (or filename)
140 var $uid; // Record uid (or '' when filename)
141
142 // Internal, static:
143 var $perms_clause; // Page select clause
144 var $access; // If TRUE, access to element is granted
145 var $type; // Which type of element: "file" or "db"
146 var $doc; // Document Template Object
147
148 // Internal, dynamic:
149 var $content; // Content Accumulation
150 var $file; // For type "file": Filename
151 var $pageinfo; // For type "db": Set to page record of the parent page of the item set (if type="db")
152 var $row; // For type "db": The database record row.
153
154
155 /**
156 * Initialization of the class
157 * 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.
158 *
159 * @return void
160 */
161 function init() {
162 // Setting input variables.
163 $this->table = t3lib_div::_GET('table');
164 $this->uid = t3lib_div::_GET('uid');
165
166 // Initialize:
167 $this->perms_clause = $GLOBALS['BE_USER']->getPagePermsClause(1);
168 $this->access = 0; // Set to TRUE if there is access to the record / file.
169 $this->type = ''; // Sets the type, "db" or "file". If blank, nothing can be shown.
170
171 // Checking if the $table value is really a table and if the user has access to it.
172 if (isset($GLOBALS['TCA'][$this->table])) {
173 t3lib_div::loadTCA($this->table);
174 $this->type = 'db';
175 $this->uid = intval($this->uid);
176
177 // Check permissions and uid value:
178 if ($this->uid && $GLOBALS['BE_USER']->check('tables_select',$this->table)) {
179 if ((string)$this->table=='pages') {
180 $this->pageinfo = t3lib_BEfunc::readPageAccess($this->uid,$this->perms_clause);
181 $this->access = is_array($this->pageinfo) ? 1 : 0;
182 $this->row = $this->pageinfo;
183 } else {
184 $this->row = t3lib_BEfunc::getRecordWSOL($this->table, $this->uid);
185 if ($this->row) {
186 $this->pageinfo = t3lib_BEfunc::readPageAccess($this->row['pid'],$this->perms_clause);
187 $this->access = is_array($this->pageinfo) ? 1 : 0;
188 }
189 }
190
191 $treatData = t3lib_div::makeInstance('t3lib_transferData');
192 $treatData->renderRecord($this->table, $this->uid, 0, $this->row);
193 $cRow = $treatData->theRecord;
194 }
195 } else {
196 // if the filereference $this->file is relative, we correct the path
197 if (substr($this->table,0,3)=='../') {
198 $this->file = PATH_site.preg_replace('/^\.\.\//','',$this->table);
199 } else {
200 $this->file = $this->table;
201 }
202 if (@is_file($this->file) && t3lib_div::isAllowedAbsPath($this->file)) {
203 $this->type = 'file';
204 $this->access = 1;
205 }
206 }
207
208 // Initialize document template object:
209 $this->doc = t3lib_div::makeInstance('template');
210 $this->doc->backPath = $GLOBALS['BACK_PATH'];
211
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);
216 }
217
218 /**
219 * Main function. Will generate the information to display for the item set internally.
220 *
221 * @return void
222 */
223 function main() {
224
225 if ($this->access) {
226 $returnLink = t3lib_div::sanitizeLocalUrl(t3lib_div::_GP('returnUrl'));
227 $returnLinkTag = $returnLink ? '<a href="' . $returnLink . '" 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::sanitizeLocalUrl(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
273 // Print header, path etc:
274 $code = $this->doc->getHeader($this->table,$this->row,$this->pageinfo['_thePath'],1).'<br />';
275 $this->content.= $this->doc->section('',$code);
276
277 // Initialize variables:
278 $tableRows = Array();
279 $i = 0;
280
281 // Traverse the list of fields to display for the record:
282 $fieldList = t3lib_div::trimExplode(',', $GLOBALS['TCA'][$this->table]['interface']['showRecordFieldList'], 1);
283 foreach ($fieldList as $name) {
284 $name = trim($name);
285 if ($GLOBALS['TCA'][$this->table]['columns'][$name]) {
286 if (!$GLOBALS['TCA'][$this->table]['columns'][$name]['exclude'] || $GLOBALS['BE_USER']->check('non_exclude_fields', $this->table . ':' . $name)) {
287 $i++;
288 $tableRows[] = '
289 <tr>
290 <td class="t3-col-header">' . $GLOBALS['LANG']->sL(t3lib_BEfunc::getItemLabel($this->table, $name), 1) . '</td>
291 <td>' . htmlspecialchars(t3lib_BEfunc::getProcessedValue($this->table, $name, $this->row[$name], 0, 0, FALSE, $this->row['uid'])) . '</td>
292 </tr>';
293 }
294 }
295 }
296
297 // Create table from the information:
298 $tableCode = '
299 <table border="0" cellpadding="0" cellspacing="0" id="typo3-showitem" class="t3-table-info">
300 '.implode('',$tableRows).'
301 </table>';
302 $this->content.=$this->doc->section('',$tableCode);
303
304 // Add path and table information in the bottom:
305 $code = '';
306 $code .= $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:labels.path') . ': ' . t3lib_div::fixed_lgd_cs($this->pageinfo['_thePath'], -48) . '<br />';
307 $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 />';
308 $this->content.= $this->doc->section('', $code);
309
310 // References:
311 $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']));
312
313 // References:
314 $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']));
315 }
316
317 /**
318 * Main function. Will generate the information to display for the item set internally.
319 *
320 * @param string <a> tag closing/returning.
321 * @return void
322 */
323 function renderFileInfo($returnLinkTag) {
324
325 // Initialize object to work on the image:
326 $imgObj = t3lib_div::makeInstance('t3lib_stdGraphic');
327 $imgObj->init();
328 $imgObj->mayScaleUp = 0;
329 $imgObj->absPrefix = PATH_site;
330
331 // Read Image Dimensions (returns FALSE if file was not an image type, otherwise dimensions in an array)
332 $imgInfo = '';
333 $imgInfo = $imgObj->getImageDimensions($this->file);
334
335 // File information
336 $fI = t3lib_div::split_fileref($this->file);
337 $ext = $fI['fileext'];
338
339 $code = '';
340
341 // Setting header:
342 $fileName = t3lib_iconWorks::getSpriteIconForFile($ext) . '<strong>' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:show_item.php.file', TRUE) . ':</strong> ' . $fI['file'];
343 if (t3lib_div::isFirstPartOfStr($this->file,PATH_site)) {
344 $code.= '<a href="../'.substr($this->file,strlen(PATH_site)).'" target="_blank">'.$fileName.'</a>';
345 } else {
346 $code.= $fileName;
347 }
348 $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 />
349 ';
350 if (is_array($imgInfo)) {
351 $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');
352 }
353 $this->content.=$this->doc->section('',$code);
354 $this->content.=$this->doc->divider(2);
355
356 // If the file was an image...:
357 if (is_array($imgInfo)) {
358
359 $imgInfo = $imgObj->imageMagickConvert($this->file,'web','346','200m','','','',1);
360 $imgInfo[3] = '../'.substr($imgInfo[3],strlen(PATH_site));
361 $code = '<br />
362 <div align="center">'.$returnLinkTag.$imgObj->imgTag($imgInfo).'</a></div>';
363 $this->content.= $this->doc->section('', $code);
364 } else {
365 $this->content.= $this->doc->spacer(10);
366 $lowerFilename = strtolower($this->file);
367
368 // Archive files:
369 if (TYPO3_OS!='WIN' && !$GLOBALS['TYPO3_CONF_VARS']['BE']['disable_exec_function']) {
370 if ($ext=='zip') {
371 $code = '';
372 $t = array();
373 t3lib_utility_Command::exec('unzip -l ' . $this->file, $t);
374 if (is_array($t)) {
375 reset($t);
376 next($t);
377 next($t);
378 next($t);
379 while(list(,$val)=each($t)) {
380 $parts = explode(' ',trim($val),7);
381 $code.= '
382 '.$parts[6].'<br />';
383 }
384 $code = '
385 <span class="nobr">'.$code.'
386 </span>
387 <br /><br />';
388 }
389 $this->content.= $this->doc->section('', $code);
390 } elseif($ext=='tar' || $ext=='tgz' || substr($lowerFilename,-6)=='tar.gz' || substr($lowerFilename,-5)=='tar.z') {
391 $code = '';
392 if ($ext=='tar') {
393 $compr = '';
394 } else {
395 $compr = 'z';
396 }
397 $t = array();
398 t3lib_utility_Command::exec('tar t' . $compr . 'f ' . $this->file, $t);
399 if (is_array($t)) {
400 foreach($t as $val) {
401 $code.='
402 '.$val.'<br />';
403 }
404
405 $code.='
406 -------<br/>
407 '.count($t).' '.$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:show_item.php.files');
408
409 $code = '
410 <span class="nobr">'.$code.'
411 </span>
412 <br /><br />';
413 }
414 $this->content.= $this->doc->section('',$code);
415 }
416 } elseif ($GLOBALS['TYPO3_CONF_VARS']['BE']['disable_exec_function']) {
417 $this->content.= $this->doc->section('',$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:show_item.php.cannotDisplayArchive'));
418 }
419
420 // Font files:
421 if ($ext=='ttf') {
422 $thumbScript = 'thumbs.php';
423 $check = basename($this->file).':'.filemtime($this->file).':'.$GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey'];
424 $params = '&file='.rawurlencode($this->file);
425 $params.= '&md5sum='.t3lib_div::shortMD5($check);
426 $url = $thumbScript.'?&dummy='.$GLOBALS['EXEC_TIME'].$params;
427 $thumb = '<br />
428 <div align="center">'.$returnLinkTag.'<img src="'.htmlspecialchars($url).'" border="0" title="'.htmlspecialchars(trim($this->file)).'" alt="" /></a></div>';
429 $this->content.= $this->doc->section('',$thumb);
430 }
431 }
432
433
434 // References:
435 $this->content.= $this->doc->section($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:show_item.php.referencesToThisItem'),$this->makeRef('_FILE',$this->file));
436 }
437
438 /**
439 * End page and print content
440 *
441 * @return void
442 */
443 function printContent() {
444 $this->content.= $this->doc->endPage();
445 $this->content = $this->doc->insertStylesAndJS($this->content);
446 echo $this->content;
447 }
448
449 /**
450 * Make reference display
451 *
452 * @param string Table name
453 * @param string Filename or uid
454 * @return string HTML
455 */
456 function makeRef($table,$ref) {
457
458 if ($table==='_FILE') {
459 // First, fit path to match what is stored in the refindex:
460 $fullIdent = $ref;
461
462 if (t3lib_div::isFirstPartOfStr($fullIdent,PATH_site)) {
463 $fullIdent = substr($fullIdent,strlen(PATH_site));
464 }
465
466 // Look up the path:
467 $rows = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
468 '*',
469 'sys_refindex',
470 'ref_table='.$GLOBALS['TYPO3_DB']->fullQuoteStr('_FILE','sys_refindex').
471 ' AND ref_string='.$GLOBALS['TYPO3_DB']->fullQuoteStr($fullIdent,'sys_refindex').
472 ' AND deleted=0'
473 );
474 } else {
475 // Look up the path:
476 $rows = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
477 '*',
478 'sys_refindex',
479 'ref_table='.$GLOBALS['TYPO3_DB']->fullQuoteStr($table,'sys_refindex').
480 ' AND ref_uid='.intval($ref).
481 ' AND deleted=0'
482 );
483 }
484
485 // Compile information for title tag:
486 $infoData = array();
487 if (count($rows)) {
488 $infoData[] = '<tr class="t3-row-header">' .
489 '<td>'.$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:show_item.php.table').'</td>' .
490 '<td>'.$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:show_item.php.uid').'</td>' .
491 '<td>'.$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:show_item.php.field').'</td>'.
492 '<td>'.$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:show_item.php.flexpointer').'</td>'.
493 '<td>'.$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:show_item.php.softrefKey').'</td>'.
494 '<td>'.$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:show_item.php.sorting').'</td>'.
495 '</tr>';
496 }
497 foreach($rows as $row) {
498 $infoData[] = '<tr class="bgColor4"">' .
499 '<td>'.$row['tablename'].'</td>' .
500 '<td>'.$row['recuid'].'</td>' .
501 '<td>'.$row['field'].'</td>'.
502 '<td>'.$row['flexpointer'].'</td>'.
503 '<td>'.$row['softref_key'].'</td>'.
504 '<td>'.$row['sorting'].'</td>'.
505 '</tr>';
506 }
507
508 return count($infoData) ? '<table border="0" cellpadding="0" cellspacing="0" class="typo3-dblist">' . implode('', $infoData) . '</table>' : '';
509 }
510
511 /**
512 * Make reference display (what this elements points to)
513 *
514 * @param string Table name
515 * @param string Filename or uid
516 * @return string HTML
517 */
518 function makeRefFrom($table,$ref) {
519
520 // Look up the path:
521 $rows = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
522 '*',
523 'sys_refindex',
524 'tablename='.$GLOBALS['TYPO3_DB']->fullQuoteStr($table,'sys_refindex').
525 ' AND recuid='.intval($ref)
526 );
527
528 // Compile information for title tag:
529 $infoData = array();
530 if (count($rows)) {
531 $infoData[] = '<tr class="t3-row-header">' .
532 '<td>'.$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:show_item.php.field').'</td>'.
533 '<td>'.$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:show_item.php.flexpointer').'</td>'.
534 '<td>'.$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:show_item.php.softrefKey').'</td>'.
535 '<td>'.$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:show_item.php.sorting').'</td>'.
536 '<td>'.$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:show_item.php.refTable').'</td>' .
537 '<td>'.$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:show_item.php.refUid').'</td>' .
538 '<td>'.$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:show_item.php.refString').'</td>' .
539 '</tr>';
540 }
541 foreach($rows as $row) {
542 $infoData[] = '<tr class="bgColor4"">' .
543 '<td>'.$row['field'].'</td>'.
544 '<td>'.$row['flexpointer'].'</td>'.
545 '<td>'.$row['softref_key'].'</td>'.
546 '<td>'.$row['sorting'].'</td>'.
547 '<td>'.$row['ref_table'].'</td>' .
548 '<td>'.$row['ref_uid'].'</td>' .
549 '<td>'.$row['ref_string'].'</td>' .
550 '</tr>';
551 }
552
553 return count($infoData) ? '<table border="0" cellpadding="0" cellspacing="0" class="typo3-dblist">' . implode('', $infoData) . '</table>' : '';
554 }
555 }
556
557
558 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['typo3/show_item.php'])) {
559 include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['typo3/show_item.php']);
560 }
561
562
563
564 // Make instance:
565 $SOBE = t3lib_div::makeInstance('SC_show_item');
566 $SOBE->init();
567 $SOBE->main();
568 $SOBE->printContent();
569
570 ?>