|
TYPO3 API
SVNRelease
|
00001 <?php 00002 /*************************************************************** 00003 * Copyright notice 00004 * 00005 * (c) 1999-2011 Kasper Skårhøj (kasperYYYY@typo3.com) 00006 * All rights reserved 00007 * 00008 * This script is part of the TYPO3 project. The TYPO3 project is 00009 * free software; you can redistribute it and/or modify 00010 * it under the terms of the GNU General Public License as published by 00011 * the Free Software Foundation; either version 2 of the License, or 00012 * (at your option) any later version. 00013 * 00014 * The GNU General Public License can be found at 00015 * http://www.gnu.org/copyleft/gpl.html. 00016 * A copy is found in the textfile GPL.txt and important notices to the license 00017 * from the author is found in LICENSE.txt distributed with these scripts. 00018 * 00019 * 00020 * This script is distributed in the hope that it will be useful, 00021 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00022 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00023 * GNU General Public License for more details. 00024 * 00025 * This copyright notice MUST APPEAR in all copies of the script! 00026 ***************************************************************/ 00027 /** 00028 * Shows a picture from uploads/* in enlarged format in a separate window. 00029 * Picture file and settings is supplied by GET-parameters: file, width, height, sample, alternativeTempPath, effects, frame, bodyTag, title, wrap, md5 00030 * 00031 * $Id: showpic.php 10531 2011-02-22 15:17:58Z nxpthx $ 00032 * Revised for TYPO3 3.6 June/2003 by Kasper Skårhøj 00033 * 00034 * @author Kasper Skårhøj <kasperYYYY@typo3.com> 00035 */ 00036 /** 00037 * [CLASS/FUNCTION INDEX of SCRIPT] 00038 * 00039 * 00040 * 00041 * 112: class SC_tslib_showpic 00042 * 133: function init() 00043 * 190: function main() 00044 * 237: function printContent() 00045 * 00046 * TOTAL FUNCTIONS: 3 00047 * (This index is automatically created/updated by the extension "extdeveval") 00048 * 00049 */ 00050 00051 00052 00053 00054 // ******************************* 00055 // Set error reporting 00056 // ******************************* 00057 if (defined('E_DEPRECATED')) { 00058 error_reporting(E_ALL ^ E_NOTICE ^ E_DEPRECATED); 00059 } else { 00060 error_reporting(E_ALL ^ E_NOTICE); 00061 } 00062 00063 00064 // *********************** 00065 // Paths are setup 00066 // *********************** 00067 define('TYPO3_OS', stristr(PHP_OS,'win')&&!stristr(PHP_OS,'darwin')?'WIN':''); 00068 define('TYPO3_MODE','FE'); 00069 00070 if(!defined('PATH_thisScript')) { 00071 define('PATH_thisScript', str_replace('//', '/', str_replace('\\', '/', 00072 (PHP_SAPI == 'fpm-fcgi' || PHP_SAPI == 'cgi' || PHP_SAPI == 'isapi' || PHP_SAPI == 'cgi-fcgi') && 00073 ($_SERVER['ORIG_PATH_TRANSLATED'] ? $_SERVER['ORIG_PATH_TRANSLATED'] : $_SERVER['PATH_TRANSLATED']) ? 00074 ($_SERVER['ORIG_PATH_TRANSLATED'] ? $_SERVER['ORIG_PATH_TRANSLATED'] : $_SERVER['PATH_TRANSLATED']) : 00075 ($_SERVER['ORIG_SCRIPT_FILENAME'] ? $_SERVER['ORIG_SCRIPT_FILENAME'] : $_SERVER['SCRIPT_FILENAME'])))); 00076 } 00077 00078 if (!defined('PATH_site')) define('PATH_site', dirname(PATH_thisScript).'/'); 00079 if (!defined('PATH_t3lib')) define('PATH_t3lib', PATH_site.'t3lib/'); 00080 define('PATH_tslib', PATH_site.'tslib/'); 00081 define('PATH_typo3conf', PATH_site.'typo3conf/'); 00082 define('TYPO3_mainDir', 'typo3/'); // This is the directory of the backend administration for the sites of this TYPO3 installation. 00083 00084 if (!@is_dir(PATH_typo3conf)) die('Cannot find configuration. This file is probably executed from the wrong location.'); 00085 00086 require_once(PATH_t3lib.'class.t3lib_div.php'); 00087 require_once(PATH_t3lib.'class.t3lib_extmgm.php'); 00088 00089 // ****************** 00090 // Including config 00091 // ****************** 00092 require_once(PATH_t3lib.'config_default.php'); 00093 if (!defined ('TYPO3_db')) die ('The configuration file was not included.'); 00094 00095 require_once(PATH_t3lib.'class.t3lib_db.php'); 00096 $TYPO3_DB = t3lib_div::makeInstance('t3lib_DB'); 00097 00098 00099 // ********************* 00100 // Error & Exception handling 00101 // ********************* 00102 if ($TYPO3_CONF_VARS['SC_OPTIONS']['errors']['exceptionHandler'] !== '') { 00103 if ($TYPO3_CONF_VARS['SYS']['errorHandler'] !== '') { 00104 // register an error handler for the given errorHandlerErrors 00105 $errorHandler = t3lib_div::makeInstance($TYPO3_CONF_VARS['SYS']['errorHandler'], $TYPO3_CONF_VARS['SYS']['errorHandlerErrors']); 00106 // set errors which will be converted in an exception 00107 $errorHandler->setExceptionalErrors($TYPO3_CONF_VARS['SC_OPTIONS']['errors']['exceptionalErrors']); 00108 } 00109 $exceptionHandler = t3lib_div::makeInstance($TYPO3_CONF_VARS['SC_OPTIONS']['errors']['exceptionHandler']); 00110 } 00111 00112 00113 00114 00115 00116 00117 # 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! 00118 # 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! 00119 00120 if (!defined ('PATH_typo3conf')) die ('The configuration path was not properly defined!'); 00121 require_once(PATH_t3lib.'class.t3lib_stdgraphic.php'); 00122 00123 00124 00125 00126 00127 /** 00128 * Script Class, generating the page output. 00129 * Instantiated in the bottom of this script. 00130 * 00131 * @author Kasper Skårhøj <kasperYYYY@typo3.com> 00132 * @package TYPO3 00133 * @subpackage tslib 00134 */ 00135 class SC_tslib_showpic { 00136 var $content; // Page content accumulated here. 00137 00138 // Parameters loaded into these internal variables: 00139 var $file; 00140 var $width; 00141 var $height; 00142 var $sample; 00143 var $alternativeTempPath; 00144 var $effects; 00145 var $frame; 00146 var $bodyTag; 00147 var $title; 00148 var $wrap; 00149 var $md5; 00150 00151 /** 00152 * @var string 00153 */ 00154 protected $parametersEncoded; 00155 00156 /** 00157 * Init function, setting the input vars in the global space. 00158 * 00159 * @return void 00160 */ 00161 function init() { 00162 // Loading internal vars with the GET/POST parameters from outside: 00163 $this->file = t3lib_div::_GP('file'); 00164 $parametersArray = t3lib_div::_GP('parameters'); 00165 $this->frame = t3lib_div::_GP('frame'); 00166 $this->md5 = t3lib_div::_GP('md5'); 00167 00168 // *********************** 00169 // Check parameters 00170 // *********************** 00171 // If no file-param or parameters are given, we must exit 00172 if (!$this->file || !isset($parametersArray) || !is_array($parametersArray)) { 00173 throw new UnexpectedValueException('Parameter Error: No file or no parameters given.'); 00174 } 00175 00176 $this->parametersEncoded = implode($parametersArray); 00177 00178 // 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 00179 $md5_value = t3lib_div::hmac( 00180 implode( 00181 '|', 00182 array($this->file, $this->parametersEncoded) 00183 ) 00184 ); 00185 00186 if ($md5_value!=$this->md5) { 00187 throw new UnexpectedValueException('Parameter Error: Wrong parameters sent.'); 00188 } 00189 00190 $parameters = unserialize(base64_decode($this->parametersEncoded)); 00191 foreach ($parameters as $parameterName => $parameterValue) { 00192 $this->$parameterName = $parameterValue; 00193 } 00194 00195 // *********************** 00196 // Check the file. If must be in a directory beneath the dir of this script... 00197 // $this->file remains unchanged, because of the code in stdgraphic, but we do check if the file exists within the current path 00198 // *********************** 00199 00200 $test_file=PATH_site.$this->file; 00201 if (!t3lib_div::validPathStr($test_file)) { 00202 throw new UnexpectedValueException('Parameter Error: No valid filepath'); 00203 } 00204 if (!@is_file($test_file)) { 00205 throw new UnexpectedValueException('The given file was not found'); 00206 } 00207 } 00208 00209 /** 00210 * Main function which creates the image if needed and outputs the HTML code for the page displaying the image. 00211 * Accumulates the content in $this->content 00212 * 00213 * @return void 00214 */ 00215 function main() { 00216 00217 // Creating stdGraphic object, initialize it and make image: 00218 $img = t3lib_div::makeInstance('t3lib_stdGraphic'); 00219 $img->mayScaleUp = 0; 00220 $img->init(); 00221 if ($this->sample) {$img->scalecmd = '-sample';} 00222 if ($this->alternativeTempPath && t3lib_div::inList($GLOBALS['TYPO3_CONF_VARS']['FE']['allowedTempPaths'],$this->alternativeTempPath)) { 00223 $img->tempPath = $this->alternativeTempPath; 00224 } 00225 00226 // Need to connect to database, because this is used (typo3temp_db_tracking, cached image dimensions). 00227 $GLOBALS['TYPO3_DB']->sql_pconnect(TYPO3_db_host, TYPO3_db_username, TYPO3_db_password); 00228 $GLOBALS['TYPO3_DB']->sql_select_db(TYPO3_db); 00229 00230 if (strstr($this->width.$this->height, 'm')) {$max='m';} else {$max='';} 00231 00232 $this->height = t3lib_div::intInRange($this->height,0); 00233 $this->width = t3lib_div::intInRange($this->width,0); 00234 if ($this->frame) {$this->frame = intval($this->frame);} 00235 $imgInfo = $img->imageMagickConvert($this->file,'web',$this->width.$max,$this->height,$img->IMparams($this->effects),$this->frame,''); 00236 00237 // Create HTML output: 00238 $this->content=''; 00239 $this->content.=' 00240 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> 00241 00242 <html> 00243 <head> 00244 <title>'.htmlspecialchars($this->title ? $this->title : "Image").'</title> 00245 ' . ($this->title ? '' : '<meta name="robots" content="noindex,follow" />') . ' 00246 </head> 00247 '.($this->bodyTag ? $this->bodyTag : '<body>'); 00248 00249 if (is_array($imgInfo)) { 00250 $wrapParts = explode('|',$this->wrap); 00251 $this->content.=trim($wrapParts[0]).$img->imgTag($imgInfo).trim($wrapParts[1]); 00252 } 00253 $this->content.=' 00254 </body> 00255 </html>'; 00256 } 00257 00258 /** 00259 * Outputs the content from $this->content 00260 * 00261 * @return void 00262 */ 00263 function printContent() { 00264 echo $this->content; 00265 } 00266 } 00267 00268 00269 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['tslib/showpic.php'])) { 00270 include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['tslib/showpic.php']); 00271 } 00272 00273 00274 00275 // Make instance: 00276 $SOBE = t3lib_div::makeInstance('SC_tslib_showpic'); 00277 $SOBE->init(); 00278 $SOBE->main(); 00279 $SOBE->printContent(); 00280 ?>
1.8.0