Initial revision
[Packages/TYPO3.CMS.git] / typo3 / sysext / cms / tslib / showpic.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 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 <kasper@typo3.com>
34 */
35 /**
36 * [CLASS/FUNCTION INDEX of SCRIPT]
37 *
38 *
39 *
40 * 91: class SC_tslib_showpic
41 * 112: function init()
42 * 160: function main()
43 * 208: function printContent()
44 *
45 * TOTAL FUNCTIONS: 3
46 * (This index is automatically created/updated by the extension "extdeveval")
47 *
48 */
49
50
51 // *******************************
52 // Set error reporting
53 // *******************************
54 error_reporting (E_ALL ^ E_NOTICE);
55
56
57 // ***********************
58 // Paths are setup
59 // ***********************
60 define('TYPO3_OS', stristr(PHP_OS,'win')&&!stristr(PHP_OS,'darwin')?'WIN':'');
61 define('TYPO3_MODE','FE');
62 define('PATH_thisScript',str_replace('//','/', str_replace('\\','/', php_sapi_name()=='cgi'||php_sapi_name()=='isapi' ? $HTTP_SERVER_VARS['PATH_TRANSLATED']:$HTTP_SERVER_VARS['SCRIPT_FILENAME'])));
63
64 define('PATH_site', dirname(PATH_thisScript).'/');
65 define('PATH_t3lib', PATH_site.'t3lib/');
66 define('PATH_tslib', PATH_site.'tslib/');
67 define('PATH_typo3conf', PATH_site.'typo3conf/');
68 define('TYPO3_mainDir', 'typo3/'); // This is the directory of the backend administration for the sites of this TYPO3 installation.
69
70 require(PATH_t3lib.'class.t3lib_div.php');
71 require(PATH_t3lib.'class.t3lib_extmgm.php');
72
73 // ******************
74 // Including config
75 // ******************
76 require(PATH_t3lib.'config_default.php');
77 if (!defined ('TYPO3_db')) die ('The configuration file was not included.');
78
79 require(PATH_t3lib.'class.t3lib_stdgraphic.php');
80
81
82
83
84
85 /**
86 * Script Class, generating the page output.
87 * Instantiated in the bottom of this script.
88 *
89 * @author Kasper Skårhøj <kasper@typo3.com>
90 */
91 class SC_tslib_showpic {
92 var $content; // Page content accumulated here.
93
94 // Parameters loaded into these internal variables:
95 var $file;
96 var $width;
97 var $height;
98 var $sample;
99 var $alternativeTempPath;
100 var $effects;
101 var $frame;
102 var $bodyTag;
103 var $title;
104 var $wrap;
105 var $md5;
106
107 /**
108 * Init function, setting the input vars in the global space.
109 *
110 * @return void
111 */
112 function init() {
113 // Loading internal vars with the GET/POST parameters from outside:
114 $this->file = t3lib_div::GPvar('file');
115 $this->width = t3lib_div::GPvar('width');
116 $this->height = t3lib_div::GPvar('height');
117 $this->sample = t3lib_div::GPvar('sample');
118 $this->alternativeTempPath = t3lib_div::GPvar('alternativeTempPath');
119 $this->effects = t3lib_div::GPvar('effects');
120 $this->frame = t3lib_div::GPvar('frame');
121 $this->bodyTag = t3lib_div::GPvar('bodyTag');
122 $this->title = t3lib_div::GPvar('title');
123 $this->wrap = t3lib_div::GPvar('wrap');
124 $this->md5 = t3lib_div::GPvar('md5');
125
126 // ***********************
127 // Check parameters
128 // ***********************
129 // If no file-param is given, we must exit
130 if (!$this->file) {
131 die('Parameter Error: No file given.');
132 }
133
134 // 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
135 $md5_value = md5($this->file.'|'.$this->width.'|'.$this->height.'|'.$this->effects.'|'.$GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey'].'|');
136 if ($md5_value!=$this->md5) {
137 die('Parameter Error: Wrong parameters sent.');
138 }
139
140 // ***********************
141 // Check the file. If must be in a directory beneath the dir of this script...
142 // $this->file remains unchanged, because of the code in stdgraphic, but we do check if the file exists within the current path
143 // ***********************
144
145 $test_file=PATH_site.$this->file;
146 if (!t3lib_div::validPathStr($test_file)) {
147 die('Parameter Error: No valid filepath');
148 }
149 if (!@is_file($test_file)) {
150 die('The given file was not found');
151 }
152 }
153
154 /**
155 * Main function which creates the image if needed and outputs the HTML code for the page displaying the image.
156 * Accumulates the content in $this->content
157 *
158 * @return void
159 */
160 function main() {
161
162 // Creating stdGraphic object, initialize it and make image:
163 $img = t3lib_div::makeInstance('t3lib_stdGraphic');
164 $img->mayScaleUp = 0;
165 $img->init();
166 if ($this->sample) {$img->scalecmd = '-sample';}
167 if ($this->alternativeTempPath && t3lib_div::inList($GLOBALS['TYPO3_CONF_VARS']['FE']['allowedTempPaths'],$this->alternativeTempPath)) {
168 $img->tempPath = $this->alternativeTempPath;
169 }
170 if ($GLOBALS['TYPO3_CONF_VARS']['GFX']['enable_typo3temp_db_tracking']) {
171 // Need to connect to database, because this may be used.
172 mysql_pconnect(TYPO3_db_host, TYPO3_db_username, TYPO3_db_password);
173 }
174
175 if (strstr($this->width.$this->height, 'm')) {$max='m';} else {$max='';}
176
177 $this->height = t3lib_div::intInRange($this->height,0,1000);
178 $this->width = t3lib_div::intInRange($this->width,0,1000);
179 if ($this->frame) {$this->frame = intval($this->frame);}
180 $imgInfo = $img->imageMagickConvert($this->file,'web',$this->width.$max,$this->height,$img->IMparams($this->effects),$this->frame,'');
181
182
183 // Create HTML output:
184 $this->content='';
185 $this->content.='
186 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
187
188 <html>
189 <head>
190 <title>'.htmlspecialchars($this->title ? $this->title : "Image").'</title>
191 </head>
192 '.($this->bodyTag ? $this->bodyTag : '<body>');
193
194 if (is_array($imgInfo)) {
195 $wrapParts = explode('|',$this->wrap);
196 $this->content.=trim($wrapParts[0]).$img->imgTag($imgInfo).trim($wrapParts[1]);
197 }
198 $this->content.='
199 </body>
200 </html>';
201 }
202
203 /**
204 * Outputs the content from $this->content
205 *
206 * @return void
207 */
208 function printContent() {
209 echo $this->content;
210 }
211 }
212
213 // Include extension?
214 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['tslib/showpic.php']) {
215 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['tslib/showpic.php']);
216 }
217
218
219
220
221
222
223
224
225
226
227
228
229 // Make instance:
230 $SOBE = t3lib_div::makeInstance('SC_tslib_showpic');
231 $SOBE->init();
232 $SOBE->main();
233 $SOBE->printContent();
234 ?>