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