Fixed bug #11267: Use PHP5 version of function microtime()
[Packages/TYPO3.CMS.git] / typo3 / sysext / cms / tslib / showpic.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 1999-2009 Kasper Skaarhoj (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 a picture from uploads/* in enlarged format in a separate window.
29 * Picture file and settings is supplied by GET-parameters: file, width, height, sample, alternativeTempPath, effects, frame, bodyTag, title, wrap, md5
30 *
31 * $Id$
32 * Revised for TYPO3 3.6 June/2003 by Kasper Skaarhoj
33 *
34 * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
35 */
36 /**
37 * [CLASS/FUNCTION INDEX of SCRIPT]
38 *
39 *
40 *
41 * 112: class SC_tslib_showpic
42 * 133: function init()
43 * 190: function main()
44 * 237: function printContent()
45 *
46 * TOTAL FUNCTIONS: 3
47 * (This index is automatically created/updated by the extension "extdeveval")
48 *
49 */
50
51
52
53
54 // *******************************
55 // Set error reporting
56 // *******************************
57 error_reporting (E_ALL ^ E_NOTICE);
58
59
60 // ***********************
61 // Paths are setup
62 // ***********************
63 define('TYPO3_OS', stristr(PHP_OS,'win')&&!stristr(PHP_OS,'darwin')?'WIN':'');
64 define('TYPO3_MODE','FE');
65 if (!defined('PATH_thisScript')) define('PATH_thisScript',str_replace('//','/', str_replace('\\','/', (PHP_SAPI=='cgi'||PHP_SAPI=='isapi' ||PHP_SAPI=='cgi-fcgi')&&($_SERVER['ORIG_PATH_TRANSLATED']?$_SERVER['ORIG_PATH_TRANSLATED']:$_SERVER['PATH_TRANSLATED'])? ($_SERVER['ORIG_PATH_TRANSLATED']?$_SERVER['ORIG_PATH_TRANSLATED']:$_SERVER['PATH_TRANSLATED']):($_SERVER['ORIG_SCRIPT_FILENAME']?$_SERVER['ORIG_SCRIPT_FILENAME']:$_SERVER['SCRIPT_FILENAME']))));
66
67 if (!defined('PATH_site')) define('PATH_site', dirname(PATH_thisScript).'/');
68 if (!defined('PATH_t3lib')) define('PATH_t3lib', PATH_site.'t3lib/');
69 define('PATH_tslib', PATH_site.'tslib/');
70 define('PATH_typo3conf', PATH_site.'typo3conf/');
71 define('TYPO3_mainDir', 'typo3/'); // This is the directory of the backend administration for the sites of this TYPO3 installation.
72
73 if (!@is_dir(PATH_typo3conf)) die('Cannot find configuration. This file is probably executed from the wrong location.');
74
75 require_once(PATH_t3lib.'class.t3lib_div.php');
76 require_once(PATH_t3lib.'class.t3lib_extmgm.php');
77
78 // ******************
79 // Including config
80 // ******************
81 require_once(PATH_t3lib.'config_default.php');
82 if (!defined ('TYPO3_db')) die ('The configuration file was not included.');
83
84 require_once(PATH_t3lib.'class.t3lib_db.php');
85 $TYPO3_DB = t3lib_div::makeInstance('t3lib_DB');
86
87
88
89
90
91
92
93
94 # NOTICE: ALL LINES above can be commented out since this script is now used via the ?eID=tx_cms_showpic parameter passed to index.php!
95 # For backwards compatibility in extensions using showpic.php directly this is kept for the version 4.0 until 4.5 where it is planned removed!
96
97 if (!defined ('PATH_typo3conf')) die ('The configuration path was not properly defined!');
98 require_once(PATH_t3lib.'class.t3lib_stdgraphic.php');
99
100
101
102
103
104 /**
105 * Script Class, generating the page output.
106 * Instantiated in the bottom of this script.
107 *
108 * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
109 * @package TYPO3
110 * @subpackage tslib
111 */
112 class SC_tslib_showpic {
113 var $content; // Page content accumulated here.
114
115 // Parameters loaded into these internal variables:
116 var $file;
117 var $width;
118 var $height;
119 var $sample;
120 var $alternativeTempPath;
121 var $effects;
122 var $frame;
123 var $bodyTag;
124 var $title;
125 var $wrap;
126 var $md5;
127
128 /**
129 * Init function, setting the input vars in the global space.
130 *
131 * @return void
132 */
133 function init() {
134 // Loading internal vars with the GET/POST parameters from outside:
135 $this->file = t3lib_div::_GP('file');
136 $this->width = t3lib_div::_GP('width');
137 $this->height = t3lib_div::_GP('height');
138 $this->sample = t3lib_div::_GP('sample');
139 $this->alternativeTempPath = t3lib_div::_GP('alternativeTempPath');
140 $this->effects = t3lib_div::_GP('effects');
141 $this->frame = t3lib_div::_GP('frame');
142 $this->bodyTag = t3lib_div::_GP('bodyTag');
143 $this->title = t3lib_div::_GP('title');
144 $this->wrap = t3lib_div::_GP('wrap');
145 $this->md5 = t3lib_div::_GP('md5');
146
147 // ***********************
148 // Check parameters
149 // ***********************
150 // If no file-param is given, we must exit
151 if (!$this->file) {
152 die('Parameter Error: No file given.');
153 }
154
155 // Chech md5-checksum: If this md5-value does not match the one submitted, then we fail... (this is a kind of security that somebody don't just hit the script with a lot of different parameters
156 $md5_value = md5(
157 $this->file.'|'.
158 $this->width.'|'.
159 $this->height.'|'.
160 $this->effects.'|'.
161 $this->bodyTag.'|'.
162 $this->title.'|'.
163 $this->wrap.'|'.
164 $GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey'].'|');
165
166 if ($md5_value!=$this->md5) {
167 die('Parameter Error: Wrong parameters sent.');
168 }
169
170 // ***********************
171 // Check the file. If must be in a directory beneath the dir of this script...
172 // $this->file remains unchanged, because of the code in stdgraphic, but we do check if the file exists within the current path
173 // ***********************
174
175 $test_file=PATH_site.$this->file;
176 if (!t3lib_div::validPathStr($test_file)) {
177 die('Parameter Error: No valid filepath');
178 }
179 if (!@is_file($test_file)) {
180 die('The given file was not found');
181 }
182 }
183
184 /**
185 * Main function which creates the image if needed and outputs the HTML code for the page displaying the image.
186 * Accumulates the content in $this->content
187 *
188 * @return void
189 */
190 function main() {
191
192 // Creating stdGraphic object, initialize it and make image:
193 $img = t3lib_div::makeInstance('t3lib_stdGraphic');
194 $img->mayScaleUp = 0;
195 $img->init();
196 if ($this->sample) {$img->scalecmd = '-sample';}
197 if ($this->alternativeTempPath && t3lib_div::inList($GLOBALS['TYPO3_CONF_VARS']['FE']['allowedTempPaths'],$this->alternativeTempPath)) {
198 $img->tempPath = $this->alternativeTempPath;
199 }
200
201 // Need to connect to database, because this is used (typo3temp_db_tracking, cached image dimensions).
202 $GLOBALS['TYPO3_DB']->sql_pconnect(TYPO3_db_host, TYPO3_db_username, TYPO3_db_password);
203 $GLOBALS['TYPO3_DB']->sql_select_db(TYPO3_db);
204
205 if (strstr($this->width.$this->height, 'm')) {$max='m';} else {$max='';}
206
207 $this->height = t3lib_div::intInRange($this->height,0);
208 $this->width = t3lib_div::intInRange($this->width,0);
209 if ($this->frame) {$this->frame = intval($this->frame);}
210 $imgInfo = $img->imageMagickConvert($this->file,'web',$this->width.$max,$this->height,$img->IMparams($this->effects),$this->frame,'');
211
212 // Create HTML output:
213 $this->content='';
214 $this->content.='
215 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
216
217 <html>
218 <head>
219 <title>'.htmlspecialchars($this->title ? $this->title : "Image").'</title>
220 ' . ($this->title ? '' : '<meta name="robots" content="noindex,follow" />') . '
221 </head>
222 '.($this->bodyTag ? $this->bodyTag : '<body>');
223
224 if (is_array($imgInfo)) {
225 $wrapParts = explode('|',$this->wrap);
226 $this->content.=trim($wrapParts[0]).$img->imgTag($imgInfo).trim($wrapParts[1]);
227 }
228 $this->content.='
229 </body>
230 </html>';
231 }
232
233 /**
234 * Outputs the content from $this->content
235 *
236 * @return void
237 */
238 function printContent() {
239 echo $this->content;
240 }
241 }
242
243
244 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['tslib/showpic.php']) {
245 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['tslib/showpic.php']);
246 }
247
248
249
250 // Make instance:
251 $SOBE = t3lib_div::makeInstance('SC_tslib_showpic');
252 $SOBE->init();
253 $SOBE->main();
254 $SOBE->printContent();
255 ?>