[TASK] Remove deprecated usages of intInRange, intval_positive and int_from_ver
[Packages/TYPO3.CMS.git] / typo3 / sysext / cms / tslib / showpic.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 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 * Revised for TYPO3 3.6 June/2003 by Kasper Skårhøj
32 *
33 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
34 */
35
36
37
38
39 // *******************************
40 // Set error reporting
41 // *******************************
42 error_reporting(E_ALL ^ E_NOTICE ^ E_DEPRECATED);
43
44
45 // ***********************
46 // Paths are setup
47 // ***********************
48 define('TYPO3_OS', stristr(PHP_OS,'win')&&!stristr(PHP_OS,'darwin')?'WIN':'');
49 define('TYPO3_MODE','FE');
50
51 if(!defined('PATH_thisScript')) {
52 define('PATH_thisScript', str_replace('//', '/', str_replace('\\', '/',
53 (PHP_SAPI == 'fpm-fcgi' || PHP_SAPI == 'cgi' || PHP_SAPI == 'isapi' || PHP_SAPI == 'cgi-fcgi') &&
54 ($_SERVER['ORIG_PATH_TRANSLATED'] ? $_SERVER['ORIG_PATH_TRANSLATED'] : $_SERVER['PATH_TRANSLATED']) ?
55 ($_SERVER['ORIG_PATH_TRANSLATED'] ? $_SERVER['ORIG_PATH_TRANSLATED'] : $_SERVER['PATH_TRANSLATED']) :
56 ($_SERVER['ORIG_SCRIPT_FILENAME'] ? $_SERVER['ORIG_SCRIPT_FILENAME'] : $_SERVER['SCRIPT_FILENAME']))));
57 }
58
59 if (!defined('PATH_site')) define('PATH_site', dirname(PATH_thisScript).'/');
60 if (!defined('PATH_t3lib')) define('PATH_t3lib', PATH_site.'t3lib/');
61 define('PATH_tslib', PATH_site.'tslib/');
62 define('PATH_typo3conf', PATH_site.'typo3conf/');
63 define('TYPO3_mainDir', 'typo3/'); // This is the directory of the backend administration for the sites of this TYPO3 installation.
64
65 if (!@is_dir(PATH_typo3conf)) die('Cannot find configuration. This file is probably executed from the wrong location.');
66
67 require_once(PATH_t3lib.'class.t3lib_div.php');
68 require_once(PATH_t3lib.'class.t3lib_extmgm.php');
69
70 // ******************
71 // Including config
72 // ******************
73 require_once(PATH_t3lib.'config_default.php');
74 if (!defined ('TYPO3_db')) die ('The configuration file was not included.');
75
76 require_once(PATH_t3lib.'class.t3lib_db.php');
77 $TYPO3_DB = t3lib_div::makeInstance('t3lib_DB');
78
79
80 // *********************
81 // Error & Exception handling
82 // *********************
83 if ($TYPO3_CONF_VARS['SC_OPTIONS']['errors']['exceptionHandler'] !== '') {
84 if ($TYPO3_CONF_VARS['SYS']['errorHandler'] !== '') {
85 // register an error handler for the given errorHandlerErrors
86 $errorHandler = t3lib_div::makeInstance($TYPO3_CONF_VARS['SYS']['errorHandler'], $TYPO3_CONF_VARS['SYS']['errorHandlerErrors']);
87 // set errors which will be converted in an exception
88 $errorHandler->setExceptionalErrors($TYPO3_CONF_VARS['SC_OPTIONS']['errors']['exceptionalErrors']);
89 }
90 $exceptionHandler = t3lib_div::makeInstance($TYPO3_CONF_VARS['SC_OPTIONS']['errors']['exceptionHandler']);
91 }
92
93
94
95
96
97
98 # 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!
99 # 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!
100
101 if (!defined ('PATH_typo3conf')) die ('The configuration path was not properly defined!');
102 require_once(PATH_t3lib.'class.t3lib_stdgraphic.php');
103
104
105
106
107
108 /**
109 * Script Class, generating the page output.
110 * Instantiated in the bottom of this script.
111 *
112 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
113 * @package TYPO3
114 * @subpackage tslib
115 */
116 class SC_tslib_showpic {
117 var $content; // Page content accumulated here.
118
119 // Parameters loaded into these internal variables:
120 var $file;
121 var $width;
122 var $height;
123 var $sample;
124 var $alternativeTempPath;
125 var $effects;
126 var $frame;
127 var $bodyTag;
128 var $title;
129 var $wrap;
130 var $md5;
131
132 /**
133 * @var string
134 */
135 protected $parametersEncoded;
136
137 /**
138 * Init function, setting the input vars in the global space.
139 *
140 * @return void
141 */
142 function init() {
143 // Loading internal vars with the GET/POST parameters from outside:
144 $this->file = t3lib_div::_GP('file');
145 $parametersArray = t3lib_div::_GP('parameters');
146 $this->frame = t3lib_div::_GP('frame');
147 $this->md5 = t3lib_div::_GP('md5');
148
149 // ***********************
150 // Check parameters
151 // ***********************
152 // If no file-param or parameters are given, we must exit
153 if (!$this->file || !isset($parametersArray) || !is_array($parametersArray)) {
154 throw new UnexpectedValueException('Parameter Error: No file or no parameters given.', 1299514081);
155 }
156
157 $this->parametersEncoded = implode($parametersArray);
158
159 // 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
160 $md5_value = t3lib_div::hmac(
161 implode(
162 '|',
163 array($this->file, $this->parametersEncoded)
164 )
165 );
166
167 if ($md5_value!=$this->md5) {
168 throw new UnexpectedValueException('Parameter Error: Wrong parameters sent.', 1299514082);
169 }
170
171 $parameters = unserialize(base64_decode($this->parametersEncoded));
172 foreach ($parameters as $parameterName => $parameterValue) {
173 $this->$parameterName = $parameterValue;
174 }
175
176 // ***********************
177 // Check the file. If must be in a directory beneath the dir of this script...
178 // $this->file remains unchanged, because of the code in stdgraphic, but we do check if the file exists within the current path
179 // ***********************
180
181 $test_file=PATH_site.$this->file;
182 if (!t3lib_div::validPathStr($test_file)) {
183 throw new UnexpectedValueException('Parameter Error: No valid filepath', 1299514083);
184 }
185 if (!@is_file($test_file)) {
186 throw new UnexpectedValueException('The given file was not found', 1299514084);
187 }
188 }
189
190 /**
191 * Main function which creates the image if needed and outputs the HTML code for the page displaying the image.
192 * Accumulates the content in $this->content
193 *
194 * @return void
195 */
196 function main() {
197
198 // Creating stdGraphic object, initialize it and make image:
199 $img = t3lib_div::makeInstance('t3lib_stdGraphic');
200 $img->mayScaleUp = 0;
201 $img->init();
202 if ($this->sample) {$img->scalecmd = '-sample';}
203 if ($this->alternativeTempPath && t3lib_div::inList($GLOBALS['TYPO3_CONF_VARS']['FE']['allowedTempPaths'],$this->alternativeTempPath)) {
204 $img->tempPath = $this->alternativeTempPath;
205 }
206
207 // Need to connect to database, because this is used (typo3temp_db_tracking, cached image dimensions).
208 $GLOBALS['TYPO3_DB']->connectDB();
209
210 if (strstr($this->width . $this->height, 'm')) {
211 $max = 'm';
212 } else {
213 $max = '';
214 }
215
216 $this->height = t3lib_utility_Math::forceIntegerInRange($this->height,0);
217 $this->width = t3lib_utility_Math::forceIntegerInRange($this->width,0);
218 if ($this->frame) {
219 $this->frame = intval($this->frame);
220 }
221 $imgInfo = $img->imageMagickConvert($this->file,'web',$this->width.$max,$this->height,$img->IMparams($this->effects),$this->frame,'');
222
223 // Create HTML output:
224 $this->content='';
225 $this->content.='
226 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
227
228 <html>
229 <head>
230 <title>'.htmlspecialchars($this->title ? $this->title : "Image").'</title>
231 ' . ($this->title ? '' : '<meta name="robots" content="noindex,follow" />') . '
232 </head>
233 '.($this->bodyTag ? $this->bodyTag : '<body>');
234
235 if (is_array($imgInfo)) {
236 $wrapParts = explode('|',$this->wrap);
237 $this->content.=trim($wrapParts[0]).$img->imgTag($imgInfo).trim($wrapParts[1]);
238 }
239 $this->content.='
240 </body>
241 </html>';
242 }
243
244 /**
245 * Outputs the content from $this->content
246 *
247 * @return void
248 */
249 function printContent() {
250 echo $this->content;
251 }
252 }
253
254
255 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['tslib/showpic.php'])) {
256 include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['tslib/showpic.php']);
257 }
258
259
260
261 // Make instance:
262 $SOBE = t3lib_div::makeInstance('SC_tslib_showpic');
263 $SOBE->init();
264 $SOBE->main();
265 $SOBE->printContent();
266 ?>