c23d0dbad24d5e77b884aeeba94ef6afbdb51e95
[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 * $Id$
32 * Revised for TYPO3 3.6 June/2003 by Kasper Skårhøj
33 *
34 * @author Kasper Skårhøj <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 if (defined('E_DEPRECATED')) {
58 error_reporting(E_ALL ^ E_NOTICE ^ E_DEPRECATED);
59 } else {
60 error_reporting(E_ALL ^ E_NOTICE);
61 }
62
63
64 // ***********************
65 // Paths are setup
66 // ***********************
67 define('TYPO3_OS', stristr(PHP_OS,'win')&&!stristr(PHP_OS,'darwin')?'WIN':'');
68 define('TYPO3_MODE','FE');
69
70 if(!defined('PATH_thisScript')) {
71 define('PATH_thisScript', str_replace('//', '/', str_replace('\\', '/',
72 (PHP_SAPI == 'fpm-fcgi' || PHP_SAPI == 'cgi' || PHP_SAPI == 'isapi' || PHP_SAPI == 'cgi-fcgi') &&
73 ($_SERVER['ORIG_PATH_TRANSLATED'] ? $_SERVER['ORIG_PATH_TRANSLATED'] : $_SERVER['PATH_TRANSLATED']) ?
74 ($_SERVER['ORIG_PATH_TRANSLATED'] ? $_SERVER['ORIG_PATH_TRANSLATED'] : $_SERVER['PATH_TRANSLATED']) :
75 ($_SERVER['ORIG_SCRIPT_FILENAME'] ? $_SERVER['ORIG_SCRIPT_FILENAME'] : $_SERVER['SCRIPT_FILENAME']))));
76 }
77
78 if (!defined('PATH_site')) define('PATH_site', dirname(PATH_thisScript).'/');
79 if (!defined('PATH_t3lib')) define('PATH_t3lib', PATH_site.'t3lib/');
80 define('PATH_tslib', PATH_site.'tslib/');
81 define('PATH_typo3conf', PATH_site.'typo3conf/');
82 define('TYPO3_mainDir', 'typo3/'); // This is the directory of the backend administration for the sites of this TYPO3 installation.
83
84 if (!@is_dir(PATH_typo3conf)) die('Cannot find configuration. This file is probably executed from the wrong location.');
85
86 require_once(PATH_t3lib.'class.t3lib_div.php');
87 require_once(PATH_t3lib.'class.t3lib_extmgm.php');
88
89 // ******************
90 // Including config
91 // ******************
92 require_once(PATH_t3lib.'config_default.php');
93 if (!defined ('TYPO3_db')) die ('The configuration file was not included.');
94
95 require_once(PATH_t3lib.'class.t3lib_db.php');
96 $TYPO3_DB = t3lib_div::makeInstance('t3lib_DB');
97
98
99
100
101
102
103
104
105 # 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!
106 # 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!
107
108 if (!defined ('PATH_typo3conf')) die ('The configuration path was not properly defined!');
109 require_once(PATH_t3lib.'class.t3lib_stdgraphic.php');
110
111
112
113
114
115 /**
116 * Script Class, generating the page output.
117 * Instantiated in the bottom of this script.
118 *
119 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
120 * @package TYPO3
121 * @subpackage tslib
122 */
123 class SC_tslib_showpic {
124 var $content; // Page content accumulated here.
125
126 // Parameters loaded into these internal variables:
127 var $file;
128 var $width;
129 var $height;
130 var $sample;
131 var $alternativeTempPath;
132 var $effects;
133 var $frame;
134 var $bodyTag;
135 var $title;
136 var $wrap;
137 var $md5;
138
139 /**
140 * @var string
141 */
142 protected $parametersEncoded;
143
144 /**
145 * Init function, setting the input vars in the global space.
146 *
147 * @return void
148 */
149 function init() {
150 // Loading internal vars with the GET/POST parameters from outside:
151 $this->file = t3lib_div::_GP('file');
152 $this->parametersEncoded = implode(t3lib_div::_GP('parameters'));
153 $this->frame = t3lib_div::_GP('frame');
154 $this->md5 = t3lib_div::_GP('md5');
155
156 // ***********************
157 // Check parameters
158 // ***********************
159 // If no file-param is given, we must exit
160 if (!$this->file) {
161 die('Parameter Error: No file given.');
162 }
163
164 // 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
165 $md5_value = t3lib_div::hmac(
166 implode(
167 '|',
168 array($this->file, $this->parametersEncoded)
169 )
170 );
171
172 if ($md5_value!=$this->md5) {
173 die('Parameter Error: Wrong parameters sent.');
174 }
175
176 $parameters = unserialize(base64_decode($this->parametersEncoded));
177 foreach ($parameters as $parameterName => $parameterValue) {
178 $this->$parameterName = $parameterValue;
179 }
180
181 // ***********************
182 // Check the file. If must be in a directory beneath the dir of this script...
183 // $this->file remains unchanged, because of the code in stdgraphic, but we do check if the file exists within the current path
184 // ***********************
185
186 $test_file=PATH_site.$this->file;
187 if (!t3lib_div::validPathStr($test_file)) {
188 die('Parameter Error: No valid filepath');
189 }
190 if (!@is_file($test_file)) {
191 die('The given file was not found');
192 }
193 }
194
195 /**
196 * Main function which creates the image if needed and outputs the HTML code for the page displaying the image.
197 * Accumulates the content in $this->content
198 *
199 * @return void
200 */
201 function main() {
202
203 // Creating stdGraphic object, initialize it and make image:
204 $img = t3lib_div::makeInstance('t3lib_stdGraphic');
205 $img->mayScaleUp = 0;
206 $img->init();
207 if ($this->sample) {$img->scalecmd = '-sample';}
208 if ($this->alternativeTempPath && t3lib_div::inList($GLOBALS['TYPO3_CONF_VARS']['FE']['allowedTempPaths'],$this->alternativeTempPath)) {
209 $img->tempPath = $this->alternativeTempPath;
210 }
211
212 // Need to connect to database, because this is used (typo3temp_db_tracking, cached image dimensions).
213 $GLOBALS['TYPO3_DB']->sql_pconnect(TYPO3_db_host, TYPO3_db_username, TYPO3_db_password);
214 $GLOBALS['TYPO3_DB']->sql_select_db(TYPO3_db);
215
216 if (strstr($this->width.$this->height, 'm')) {$max='m';} else {$max='';}
217
218 $this->height = t3lib_div::intInRange($this->height,0);
219 $this->width = t3lib_div::intInRange($this->width,0);
220 if ($this->frame) {$this->frame = intval($this->frame);}
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 ?>