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