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