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