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