[TASK] Whitespace CGL
[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 if (!defined ('PATH_typo3conf')) die ('The configuration path was not properly defined!');
37 require_once(PATH_t3lib.'class.t3lib_stdgraphic.php');
38
39 /**
40 * Script Class, generating the page output.
41 * Instantiated in the bottom of this script.
42 *
43 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
44 * @package TYPO3
45 * @subpackage tslib
46 */
47 class SC_tslib_showpic {
48 var $content; // Page content accumulated here.
49
50 // Parameters loaded into these internal variables:
51 var $file;
52 var $width;
53 var $height;
54 var $sample;
55 var $alternativeTempPath;
56 var $effects;
57 var $frame;
58 var $bodyTag;
59 var $title;
60 var $wrap;
61 var $md5;
62
63 /**
64 * @var string
65 */
66 protected $parametersEncoded;
67
68 /**
69 * Init function, setting the input vars in the global space.
70 *
71 * @return void
72 */
73 function init() {
74 // Loading internal vars with the GET/POST parameters from outside:
75 $this->file = t3lib_div::_GP('file');
76 $parametersArray = t3lib_div::_GP('parameters');
77 $this->frame = t3lib_div::_GP('frame');
78 $this->md5 = t3lib_div::_GP('md5');
79
80 // ***********************
81 // Check parameters
82 // ***********************
83 // If no file-param or parameters are given, we must exit
84 if (!$this->file || !isset($parametersArray) || !is_array($parametersArray)) {
85 throw new UnexpectedValueException('Parameter Error: No file or no parameters given.', 1299514081);
86 }
87
88 $this->parametersEncoded = implode('', $parametersArray);
89
90 // 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
91 $md5_value = t3lib_div::hmac(
92 implode(
93 '|',
94 array($this->file, $this->parametersEncoded)
95 )
96 );
97
98 if ($md5_value !== $this->md5) {
99 throw new UnexpectedValueException('Parameter Error: Wrong parameters sent.', 1299514082);
100 }
101
102 $parameters = unserialize(base64_decode($this->parametersEncoded));
103 foreach ($parameters as $parameterName => $parameterValue) {
104 $this->$parameterName = $parameterValue;
105 }
106
107 // ***********************
108 // Check the file. If must be in a directory beneath the dir of this script...
109 // $this->file remains unchanged, because of the code in stdgraphic, but we do check if the file exists within the current path
110 // ***********************
111
112 $test_file=PATH_site.$this->file;
113 if (!t3lib_div::validPathStr($test_file)) {
114 throw new UnexpectedValueException('Parameter Error: No valid filepath', 1299514083);
115 }
116 if (!@is_file($test_file)) {
117 throw new UnexpectedValueException('The given file was not found', 1299514084);
118 }
119 }
120
121 /**
122 * Main function which creates the image if needed and outputs the HTML code for the page displaying the image.
123 * Accumulates the content in $this->content
124 *
125 * @return void
126 */
127 function main() {
128
129 // Creating stdGraphic object, initialize it and make image:
130 $img = t3lib_div::makeInstance('t3lib_stdGraphic');
131 $img->mayScaleUp = 0;
132 $img->init();
133 if ($this->sample) {$img->scalecmd = '-sample';}
134 if ($this->alternativeTempPath && t3lib_div::inList($GLOBALS['TYPO3_CONF_VARS']['FE']['allowedTempPaths'],$this->alternativeTempPath)) {
135 $img->tempPath = $this->alternativeTempPath;
136 }
137
138 // Need to connect to database, because this is used (typo3temp_db_tracking, cached image dimensions).
139 $GLOBALS['TYPO3_DB']->connectDB();
140
141 if (strstr($this->width . $this->height, 'm')) {
142 $max = 'm';
143 } else {
144 $max = '';
145 }
146
147 $this->height = t3lib_utility_Math::forceIntegerInRange($this->height,0);
148 $this->width = t3lib_utility_Math::forceIntegerInRange($this->width,0);
149 if ($this->frame) {
150 $this->frame = intval($this->frame);
151 }
152 $imgInfo = $img->imageMagickConvert($this->file,'web',$this->width.$max,$this->height,$img->IMparams($this->effects),$this->frame,'');
153
154 // Create HTML output:
155 $this->content='';
156 $this->content.='
157 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
158
159 <html>
160 <head>
161 <title>'.htmlspecialchars($this->title ? $this->title : "Image").'</title>
162 ' . ($this->title ? '' : '<meta name="robots" content="noindex,follow" />') . '
163 </head>
164 '.($this->bodyTag ? $this->bodyTag : '<body>');
165
166 if (is_array($imgInfo)) {
167 $wrapParts = explode('|',$this->wrap);
168 $this->content.=trim($wrapParts[0]).$img->imgTag($imgInfo).trim($wrapParts[1]);
169 }
170 $this->content.='
171 </body>
172 </html>';
173 }
174
175 /**
176 * Outputs the content from $this->content
177 *
178 * @return void
179 */
180 function printContent() {
181 echo $this->content;
182 }
183 }
184
185 // Make instance:
186 $SOBE = t3lib_div::makeInstance('SC_tslib_showpic');
187 $SOBE->init();
188 $SOBE->main();
189 $SOBE->printContent();
190 ?>