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