Changed lots of stuff...
[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 *
32 * @author Kasper Skaarhoj <kasper@typo3.com>
33 */
34 /**
35 * [CLASS/FUNCTION INDEX of SCRIPT]
36 *
37 *
38 *
39 * 79: class transferData extends t3lib_transferData
40 * 95: function regItem($table, $id, $field, $content)
41 *
42 *
43 * 133: class SC_show_item
44 * 151: function init()
45 * 220: function main()
46 * 348: function printContent()
47 *
48 * TOTAL FUNCTIONS: 4
49 * (This index is automatically created/updated by the extension "extdeveval")
50 *
51 */
52
53
54 $BACK_PATH='';
55 require ($BACK_PATH.'init.php');
56 require ($BACK_PATH.'template.php');
57 require_once (PATH_t3lib.'class.t3lib_page.php');
58 require_once (PATH_t3lib.'class.t3lib_loaddbgroup.php');
59 require_once (PATH_t3lib.'class.t3lib_transferdata.php');
60
61
62
63
64
65
66
67
68
69
70
71
72 /**
73 * Extension of transfer data class
74 *
75 * @author Kasper Skaarhoj <kasper@typo3.com>
76 * @package TYPO3
77 * @subpackage core
78 */
79 class transferData extends t3lib_transferData {
80 var $formname = 'loadform';
81 var $loading = 1;
82
83 // Extra for show_item.php:
84 var $theRecord = Array();
85
86 /**
87 * Register item function.
88 *
89 * @param [type] $table: ...
90 * @param [type] $id: ...
91 * @param [type] $field: ...
92 * @param [type] $content: ...
93 * @return [type] ...
94 */
95 function regItem($table, $id, $field, $content) {
96 t3lib_div::loadTCA($table);
97 $config = $GLOBALS['TCA'][$table]['columns'][$field]['config'];
98 switch($config['type']) {
99 case 'input':
100 if (isset($config['checkbox']) && $content==$config['checkbox']) {$content=''; break;}
101 if (t3lib_div::inList($config['eval'],'date')) {$content = Date($GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy'],$content); }
102 break;
103 case 'group':
104 break;
105 case 'select':
106 break;
107 }
108 $this->theRecord[$field]=$content;
109 }
110 }
111
112
113
114
115
116
117
118
119
120
121
122 /**
123 * Script Class
124 *
125 * GPvars:
126 * $table : Record table (or filename)
127 * $uid : Record uid (or '' when filename)
128 *
129 * @author Kasper Skaarhoj <kasper@typo3.com>
130 * @package TYPO3
131 * @subpackage core
132 */
133 class SC_show_item {
134 var $include_once=array();
135 var $content;
136
137 var $perms_clause;
138 var $access;
139 var $pageinfo;
140 var $type;
141 var $file;
142 var $relPath;
143 var $row;
144 var $table;
145 var $uid;
146 var $doc;
147
148 /**
149 * @return [type] ...
150 */
151 function init() {
152 global $BE_USER,$LANG,$BACK_PATH,$TCA_DESCR,$TCA,$CLIENT,$TYPO3_CONF_VARS;
153
154 $this->perms_clause = $BE_USER->getPagePermsClause(1);
155 $this->table = t3lib_div::_GP('table');
156 $this->uid = t3lib_div::_GP("uid");
157
158 $this->access=0;
159 $this->type="";
160 if (isset($TCA[$this->table]) && $BE_USER->check("tables_select",$this->table)) {
161 t3lib_div::loadTCA($this->table);
162 $this->type="db";
163 $this->uid=intval($this->uid);
164 if ($this->uid) {
165 if ((string)$this->table=="pages") {
166 $this->pageinfo = t3lib_BEfunc::readPageAccess($this->uid,$this->perms_clause);
167 $this->access = is_array($this->pageinfo) ? 1 : 0;
168 $this->row=$this->pageinfo;
169 } else {
170 $this->row=t3lib_BEfunc::getRecord ($this->table,$this->uid);
171 if ($this->row) {
172 $this->pageinfo = t3lib_BEfunc::readPageAccess($this->row["pid"],$this->perms_clause);
173 $this->access = is_array($this->pageinfo) ? 1 : 0;
174 }
175 }
176
177
178 $treatData = t3lib_div::makeInstance("t3lib_transferData");
179 $treatData->renderRecord($this->table, $this->uid, 0, $this->row);
180 $cRow = $treatData->theRecord;
181 }
182 } else {
183 // if the filereference $this->file is relative, we correct the path
184 if (substr($this->table,0,3)=="../") {
185 $this->file = PATH_site.ereg_replace("^\.\./","",$this->table);
186 $this->relPath=1;
187 } else {
188 $this->file = $this->table;
189 $this->relPath=0;
190 }
191 if (@is_file($this->file)) {
192 $this->type="file";
193 $this->access=1;
194
195 $this->include_once[]=PATH_t3lib."class.t3lib_stdgraphic.php";
196 }
197 }
198
199
200 $this->doc = t3lib_div::makeInstance("smallDoc");
201 $this->doc->backPath = $BACK_PATH;
202 $this->doc->tableLayout = Array (
203 "defRow" => Array (
204 "0" => Array('<TD valign="top">','</td>'),
205 "defCol" => Array('<TD><img src="'.$this->backPath.'clear.gif" width=15 height=1></td><td valign="top">','</td>')
206 )
207 );
208
209
210 $this->content.=$this->doc->startPage($LANG->sL("LLL:EXT:lang/locallang_core.php:show_item.php.viewItem"));
211 $this->content.=$this->doc->header($LANG->sL("LLL:EXT:lang/locallang_core.php:show_item.php.viewItem"));
212 $this->content.=$this->doc->spacer(5);
213 }
214
215 /**
216 * [Describe function...]
217 *
218 * @return [type] ...
219 */
220 function main() {
221 global $BE_USER,$LANG,$BACK_PATH,$TCA_DESCR,$TCA,$CLIENT,$TYPO3_CONF_VARS;
222
223 if ($this->access) {
224 $returnLinkTag = t3lib_div::_GP("returnUrl") ? '<a href="'.t3lib_div::_GP("returnUrl").'" class="typo3-goBack">' : '<a href="#" onClick="window.close();">';
225
226 if ($this->type=="db") {
227 $code=$this->doc->getHeader($this->table,$this->row,$this->pageinfo["_thePath"],1).'<br />';
228 $this->content.=$this->doc->section('',$code);
229
230 $codeArr=Array();
231 $i=0;
232
233 $fieldList=explode(",",$TCA[$this->table]["interface"]["showRecordFieldList"]);
234 while(list(,$name)=each($fieldList)) {
235 $name=trim($name);
236 if ($TCA[$this->table]["columns"][$name]) {
237 if (!$TCA[$this->table]["columns"][$name]["exclude"] || $GLOBALS["BE_USER"]->check("non_exclude_fields",$this->table.":".$name)) {
238 $i++;
239 $codeArr[$i][]=$LANG->sL(t3lib_BEfunc::getItemLabel($this->table,$name));
240 $codeArr[$i][]=t3lib_BEfunc::getProcessedValue($this->table,$name,$this->row[$name]);
241 }
242 }
243 }
244 $this->content.=$this->doc->section('',$this->doc->table($codeArr));
245 $this->content.=$this->doc->divider(2);
246
247 $code="";
248 $code.='Path: '.t3lib_div::fixed_lgd_pre($this->pageinfo["_thePath"],48).'<br />';
249 $code.='Table: '.$LANG->sL($TCA[$this->table]["ctrl"]["title"]).' ('.$this->table.') - UID: '.$this->uid.'<br />';
250 $this->content.=$this->doc->section('',$code);
251 }
252 if ($this->type=="file") {
253 $imgInfo="";
254
255 $imgObj = t3lib_div::makeInstance("t3lib_stdGraphic");
256 $imgObj->init();
257 $imgObj->mayScaleUp=0;
258 $imgObj->tempPath=PATH_site.$imgObj->tempPath;
259
260 $imgInfo = $imgObj->getImageDimensions($this->file);
261
262 $fI = t3lib_div::split_fileref($this->file);
263 $ext = $fI["fileext"];
264 // debug($fI);
265 if ($imgInfo) {
266 $code="";
267 if ($this->relPath || t3lib_div::isFirstPartOfStr($this->file,PATH_site)) {
268 $code.='<a href="../'.substr($this->file,strlen(PATH_site)).'" target="_blank"><b>'.$LANG->sL("LLL:EXT:lang/locallang_core.php:show_item.php.file").':</b> '.$fI["file"].'</a>';
269 } else {
270 $code.='<b>'.$LANG->sL("LLL:EXT:lang/locallang_core.php:show_item.php.file").':</b> '.$fI["file"];
271 }
272 $code.=' &nbsp;&nbsp;<b>'.$LANG->sL("LLL:EXT:lang/locallang_core.php:show_item.php.filesize").':</b> '.t3lib_div::formatSize(@filesize($this->file));
273 $code.='<br />';
274 $code.='<b>'.$LANG->sL("LLL:EXT:lang/locallang_core.php:show_item.php.dimensions").':</b> '.$imgInfo[0].'x'.$imgInfo[1].' pixels';
275 $this->content.=$this->doc->section('',$code);
276
277 $this->content.=$this->doc->divider(2);
278
279 $imgInfo = $imgObj->imageMagickConvert($this->file,"web","346","200m","","","",1);
280 $imgInfo[3] = "../".substr($imgInfo[3],strlen(PATH_site));
281 $code= '<br /><div align="center">'.$returnLinkTag.$imgObj->imgTag($imgInfo).'</a></div>';
282 $this->content.=$this->doc->section('',$code);
283 } else {
284 $code="";
285 $icon = t3lib_BEfunc::getFileIcon($ext);
286 $url = 'gfx/fileicons/'.$icon;
287 $code.='<a href="../'.substr($this->file,strlen(PATH_site)).'" target="_blank"><img src="'.$url.'" width=18 height=16 align="top" border=0> <b>File:</b> '.$fI["file"].'</a> &nbsp;&nbsp;<b>Size:</b> '.t3lib_div::formatSize(@filesize($this->file)).'<br />';
288 $this->content.=$this->doc->section('',$code);
289
290 $lowerFilename = strtolower($this->file);
291 if (TYPO3_OS!="WIN" && !$GLOBALS["TYPO3_CONF_VARS"]["BE"]["disable_exec_function"]) {
292 if ($ext=="zip") {
293 $this->content.=$this->doc->divider(10);
294 $code="";
295 exec("unzip -l ".$this->file, $t);
296 if (is_array($t)) {
297 reset($t);
298 next($t);
299 next($t);
300 next($t);
301 while(list(,$val)=each($t)) {
302 $parts = explode(" ",trim($val),7);
303 $code.=$parts[6]."<br />";
304 }
305 $code='<span class="nobr">'.$code.'</span>';
306 }
307 $this->content.=$this->doc->section('',$code);
308 } elseif($ext=="tar" || $ext=="tgz" || substr($lowerFilename,-6)=="tar.gz" || substr($lowerFilename,-5)=="tar.z") {
309 $this->content.=$this->doc->divider(10);
310 $code="";
311 if ($ext=="tar") {
312 $compr="";
313 } else {
314 $compr="z";
315 }
316 exec("tar t".$compr."f ".$this->file, $t);
317 if (is_array($t)) {
318 reset($t);
319 while(list(,$val)=each($t)) {
320 $code.=$val."<br />";
321 }
322 $code='<span class="nobr">'.$code.'</span>';
323 }
324 $this->content.=$this->doc->section('',$code);
325 }
326 }
327 if ($ext=="ttf") {
328 $thumbScript="thumbs.php";
329 $params = "&file=".rawurlencode($this->file);
330 $url = $thumbScript.'?&dummy='.$GLOBALS['EXEC_TIME'].$params;
331 $thumb='<br /><img src="'.$url.'" hspace=40 border=0 title="'.trim($this->file).'">';
332 $this->content.=$this->doc->section('',$thumb);
333 }
334 }
335 }
336
337 if (t3lib_div::_GP("returnUrl")) {
338 $this->content.=$this->doc->section('','<br />'.$returnLinkTag.'<strong>&lt; '.$LANG->sL("LLL:EXT:lang/locallang_core.php:labels.goBack").'</strong></a>');
339 }
340 }
341 }
342
343 /**
344 * [Describe function...]
345 *
346 * @return [type] ...
347 */
348 function printContent() {
349 $this->content.=$this->doc->spacer(8);
350 $this->content.=$this->doc->endPage();
351 echo $this->content;
352 }
353 }
354
355 // Include extension?
356 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/show_item.php']) {
357 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/show_item.php']);
358 }
359
360
361
362
363
364
365
366
367
368
369
370
371 // Make instance:
372 $SOBE = t3lib_div::makeInstance('SC_show_item');
373 $SOBE->init();
374
375 // Include files?
376 foreach($SOBE->include_once as $INC_FILE) include_once($INC_FILE);
377
378 $SOBE->main();
379 $SOBE->printContent();
380 ?>