*** empty log message ***
[Packages/TYPO3.CMS.git] / typo3 / show_item.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 1999-2004 Kasper Skaarhoj (kasper@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 <kasper@typo3.com>
34 */
35 /**
36 * [CLASS/FUNCTION INDEX of SCRIPT]
37 *
38 *
39 *
40 * 81: class transferData extends t3lib_transferData
41 * 98: function regItem($table, $id, $field, $content)
42 *
43 *
44 * 132: class SC_show_item
45 * 157: function init()
46 * 224: function main()
47 * 252: function renderDBInfo()
48 * 300: function renderFileInfo($returnLinkTag)
49 * 414: function printContent()
50 *
51 * TOTAL FUNCTIONS: 6
52 * (This index is automatically created/updated by the extension "extdeveval")
53 *
54 */
55
56
57 $BACK_PATH = '';
58 require($BACK_PATH.'init.php');
59 require($BACK_PATH.'template.php');
60 require_once(PATH_t3lib.'class.t3lib_page.php');
61 require_once(PATH_t3lib.'class.t3lib_loaddbgroup.php');
62 require_once(PATH_t3lib.'class.t3lib_transferdata.php');
63
64
65
66
67
68
69
70
71
72
73
74
75 /**
76 * Extension of transfer data class
77 *
78 * @author Kasper Skaarhoj <kasper@typo3.com>
79 * @package TYPO3
80 * @subpackage core
81 */
82 class transferData extends t3lib_transferData {
83
84 var $formname = 'loadform';
85 var $loading = 1;
86
87 // Extra for show_item.php:
88 var $theRecord = Array();
89
90 /**
91 * Register item function.
92 *
93 * @param string Table name
94 * @param integer Record uid
95 * @param string Field name
96 * @param string Content string.
97 * @return void
98 */
99 function regItem($table, $id, $field, $content) {
100 t3lib_div::loadTCA($table);
101 $config = $GLOBALS['TCA'][$table]['columns'][$field]['config'];
102 switch($config['type']) {
103 case 'input':
104 if (isset($config['checkbox']) && $content==$config['checkbox']) {$content=''; break;}
105 if (t3lib_div::inList($config['eval'],'date')) {$content = Date($GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy'],$content); }
106 break;
107 case 'group':
108 break;
109 case 'select':
110 break;
111 }
112 $this->theRecord[$field]=$content;
113 }
114 }
115
116
117
118
119
120
121
122
123
124
125
126 /**
127 * Script Class for showing information about an item.
128 *
129 * @author Kasper Skaarhoj <kasper@typo3.com>
130 * @package TYPO3
131 * @subpackage core
132 */
133 class SC_show_item {
134
135 // GET vars:
136 var $table; // Record table (or filename)
137 var $uid; // Record uid (or '' when filename)
138
139 // Internal, static:
140 var $perms_clause; // Page select clause
141 var $access; // If true, access to element is granted
142 var $type; // Which type of element: "file" or "db"
143 var $doc; // Document Template Object
144
145 // Internal, dynamic:
146 var $content; // Content Accumulation
147 var $file; // For type "file": Filename
148 var $pageinfo; // For type "db": Set to page record of the parent page of the item set (if type="db")
149 var $row; // For type "db": The database record row.
150
151
152 /**
153 * Initialization of the class
154 * 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.
155 *
156 * @return void
157 */
158 function init() {
159 global $BE_USER,$LANG,$BACK_PATH,$TCA;
160
161 // Setting input variables.
162 $this->table = t3lib_div::_GET('table');
163 $this->uid = t3lib_div::_GET('uid');
164
165 // Initialize:
166 $this->perms_clause = $BE_USER->getPagePermsClause(1);
167 $this->access = 0; // Set to true if there is access to the record / file.
168 $this->type = ''; // Sets the type, "db" or "file". If blank, nothing can be shown.
169
170 // Checking if the $table value is really a table and if the user has access to it.
171 if (isset($TCA[$this->table])) {
172 t3lib_div::loadTCA($this->table);
173 $this->type = 'db';
174 $this->uid = intval($this->uid);
175
176 // Check permissions and uid value:
177 if ($this->uid && $BE_USER->check('tables_select',$this->table)) {
178 if ((string)$this->table=='pages') {
179 $this->pageinfo = t3lib_BEfunc::readPageAccess($this->uid,$this->perms_clause);
180 $this->access = is_array($this->pageinfo) ? 1 : 0;
181 $this->row = $this->pageinfo;
182 } else {
183 $this->row = t3lib_BEfunc::getRecord($this->table,$this->uid);
184 if ($this->row) {
185 $this->pageinfo = t3lib_BEfunc::readPageAccess($this->row['pid'],$this->perms_clause);
186 $this->access = is_array($this->pageinfo) ? 1 : 0;
187 }
188 }
189
190 $treatData = t3lib_div::makeInstance('t3lib_transferData');
191 $treatData->renderRecord($this->table, $this->uid, 0, $this->row);
192 $cRow = $treatData->theRecord;
193 }
194 } else {
195 // if the filereference $this->file is relative, we correct the path
196 if (substr($this->table,0,3)=='../') {
197 $this->file = PATH_site.ereg_replace('^\.\./','',$this->table);
198 } else {
199 $this->file = $this->table;
200 }
201 if (@is_file($this->file) && t3lib_div::isAllowedAbsPath($this->file)) {
202 $this->type = 'file';
203 $this->access = 1;
204
205 require_once(PATH_t3lib.'class.t3lib_stdgraphic.php');
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 // Branch out based on type:
232 switch($this->type) {
233 case 'db':
234 $this->renderDBInfo();
235 break;
236 case 'file':
237 $this->renderFileInfo($returnLinkTag);
238 break;
239 }
240
241 // If return Url is set, output link to go back:
242 if (t3lib_div::_GP('returnUrl')) {
243 $this->content.= $this->doc->section('','<br />'.$returnLinkTag.'<strong>'.$LANG->sL('LLL:EXT:lang/locallang_core.php:labels.goBack',1).'</strong></a>');
244 }
245 }
246 }
247
248 /**
249 * Main function. Will generate the information to display for the item set internally.
250 *
251 * @return void
252 */
253 function renderDBInfo() {
254 global $LANG,$TCA;
255
256 // Print header, path etc:
257 $code = $this->doc->getHeader($this->table,$this->row,$this->pageinfo['_thePath'],1).'<br />';
258 $this->content.= $this->doc->section('',$code);
259
260 // Initialize variables:
261 $tableRows = Array();
262 $i = 0;
263
264 // Traverse the list of fields to display for the record:
265 $fieldList = t3lib_div::trimExplode(',',$TCA[$this->table]['interface']['showRecordFieldList'],1);
266 foreach($fieldList as $name) {
267 $name = trim($name);
268 if ($TCA[$this->table]['columns'][$name]) {
269 if (!$TCA[$this->table]['columns'][$name]['exclude'] || $GLOBALS['BE_USER']->check('non_exclude_fields',$this->table.':'.$name)) {
270 $i++;
271 $tableRows[] = '
272 <tr>
273 <td class="bgColor5">'.$LANG->sL(t3lib_BEfunc::getItemLabel($this->table,$name),1).'</td>
274 <td class="bgColor4">'.htmlspecialchars(t3lib_BEfunc::getProcessedValue($this->table,$name,$this->row[$name])).'</td>
275 </tr>';
276 }
277 }
278 }
279
280 // Create table from the information:
281 $tableCode = '
282 <table border="0" cellpadding="1" cellspacing="1" id="typo3-showitem">
283 '.implode('',$tableRows).'
284 </table>';
285 $this->content.=$this->doc->section('',$tableCode);
286 $this->content.=$this->doc->divider(2);
287
288 // Add path and table information in the bottom:
289 $code = '';
290 $code.= $LANG->sL('LLL:EXT:lang/locallang_core.php:labels.path').': '.t3lib_div::fixed_lgd_cs($this->pageinfo['_thePath'],-48).'<br />';
291 $code.= $LANG->sL('LLL:EXT:lang/locallang_core.php:labels.table').': '.$LANG->sL($TCA[$this->table]['ctrl']['title']).' ('.$this->table.') - UID: '.$this->uid.'<br />';
292 $this->content.= $this->doc->section('', $code);
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 global $LANG;
303
304 // Initialize object to work on the image:
305 $imgObj = t3lib_div::makeInstance('t3lib_stdGraphic');
306 $imgObj->init();
307 $imgObj->mayScaleUp = 0;
308 $imgObj->tempPath = PATH_site.$imgObj->tempPath;
309
310 // Read Image Dimensions (returns false if file was not an image type, otherwise dimensions in an array)
311 $imgInfo = '';
312 $imgInfo = $imgObj->getImageDimensions($this->file);
313
314 // File information
315 $fI = t3lib_div::split_fileref($this->file);
316 $ext = $fI['fileext'];
317
318 $code = '';
319
320 // Setting header:
321 $icon = t3lib_BEfunc::getFileIcon($ext);
322 $url = 'gfx/fileicons/'.$icon;
323 $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'];
324 if (t3lib_div::isFirstPartOfStr($this->file,PATH_site)) {
325 $code.= '<a href="../'.substr($this->file,strlen(PATH_site)).'" target="_blank">'.$fileName.'</a>';
326 } else {
327 $code.= $fileName;
328 }
329 $code.=' &nbsp;&nbsp;<b>'.$LANG->sL('LLL:EXT:lang/locallang_core.php:show_item.php.filesize').':</b> '.t3lib_div::formatSize(@filesize($this->file)).'<br />
330 ';
331 if (is_array($imgInfo)) {
332 $code.= '<b>'.$LANG->sL('LLL:EXT:lang/locallang_core.php:show_item.php.dimensions').':</b> '.$imgInfo[0].'x'.$imgInfo[1].' pixels';
333 }
334 $this->content.=$this->doc->section('',$code);
335 $this->content.=$this->doc->divider(2);
336
337 // If the file was an image...:
338 if (is_array($imgInfo)) {
339 $imgInfo = $imgObj->imageMagickConvert($this->file,'web','346','200m','','','',1);
340 $imgInfo[3] = '../'.substr($imgInfo[3],strlen(PATH_site));
341 $code = '<br />
342 <div align="center">'.$returnLinkTag.$imgObj->imgTag($imgInfo).'</a></div>';
343 $this->content.= $this->doc->section('', $code);
344 } else {
345 $this->content.= $this->doc->spacer(10);
346 $lowerFilename = strtolower($this->file);
347
348 // Archive files:
349 if (TYPO3_OS!='WIN' && !$GLOBALS['TYPO3_CONF_VARS']['BE']['disable_exec_function']) {
350 if ($ext=='zip') {
351 $code = '';
352 exec('unzip -l '.$this->file, $t);
353 if (is_array($t)) {
354 reset($t);
355 next($t);
356 next($t);
357 next($t);
358 while(list(,$val)=each($t)) {
359 $parts = explode(' ',trim($val),7);
360 $code.= '
361 '.$parts[6].'<br />';
362 }
363 $code = '
364 <span class="nobr">'.$code.'
365 </span>
366 <br /><br />';
367 }
368 $this->content.= $this->doc->section('', $code);
369 } elseif($ext=='tar' || $ext=='tgz' || substr($lowerFilename,-6)=='tar.gz' || substr($lowerFilename,-5)=='tar.z') {
370 $code = '';
371 if ($ext=='tar') {
372 $compr = '';
373 } else {
374 $compr = 'z';
375 }
376 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).' 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('','Sorry, TYPO3_CONF_VARS[BE][disable_exec_function] was set, so cannot display content of archive file.');
396 }
397
398 // Font files:
399 if ($ext=='ttf') {
400 $thumbScript = 'thumbs.php';
401 $params = '&file='.rawurlencode($this->file);
402 $url = $thumbScript.'?&dummy='.$GLOBALS['EXEC_TIME'].$params;
403 $thumb = '<br />
404 <div align="center">'.$returnLinkTag.'<img src="'.htmlspecialchars($url).'" border="0" title="'.htmlspecialchars(trim($this->file)).'" alt="" /></a></div>';
405 $this->content.= $this->doc->section('',$thumb);
406 }
407 }
408 }
409
410 /**
411 * End page and print content
412 *
413 * @return void
414 */
415 function printContent() {
416 $this->content.= $this->doc->endPage();
417 echo $this->content;
418 }
419 }
420
421 // Include extension?
422 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/show_item.php']) {
423 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/show_item.php']);
424 }
425
426
427
428
429
430
431
432
433
434
435
436
437 // Make instance:
438 $SOBE = t3lib_div::makeInstance('SC_show_item');
439 $SOBE->init();
440 $SOBE->main();
441 $SOBE->printContent();
442 ?>