Documentation TYPO3 par Ameos

showpic.php

00001 <?php
00002 /***************************************************************
00003 *  Copyright notice
00004 *
00005 *  (c) 1999-2005 Kasper Skaarhoj (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 ***************************************************************/
00052 // *******************************
00053 // Set error reporting
00054 // *******************************
00055 error_reporting (E_ALL ^ E_NOTICE);
00056 
00057 
00058 // ***********************
00059 // Paths are setup
00060 // ***********************
00061 define('TYPO3_OS', stristr(PHP_OS,'win')&&!stristr(PHP_OS,'darwin')?'WIN':'');
00062 define('TYPO3_MODE','FE');
00063 define('PATH_thisScript',str_replace('//','/', str_replace('\\','/', (php_sapi_name()=='cgi'||php_sapi_name()=='isapi' ||php_sapi_name()=='cgi-fcgi')&&($_SERVER['ORIG_PATH_TRANSLATED']?$_SERVER['ORIG_PATH_TRANSLATED']:$_SERVER['PATH_TRANSLATED'])? ($_SERVER['ORIG_PATH_TRANSLATED']?$_SERVER['ORIG_PATH_TRANSLATED']:$_SERVER['PATH_TRANSLATED']):($_SERVER['ORIG_SCRIPT_FILENAME']?$_SERVER['ORIG_SCRIPT_FILENAME']:$_SERVER['SCRIPT_FILENAME']))));
00064 
00065 define('PATH_site', dirname(PATH_thisScript).'/');
00066 define('PATH_t3lib', PATH_site.'t3lib/');
00067 define('PATH_tslib', PATH_site.'tslib/');
00068 define('PATH_typo3conf', PATH_site.'typo3conf/');
00069 define('TYPO3_mainDir', 'typo3/');              // This is the directory of the backend administration for the sites of this TYPO3 installation.
00070 
00071 require_once(PATH_t3lib.'class.t3lib_div.php');
00072 require_once(PATH_t3lib.'class.t3lib_extmgm.php');
00073 
00074 // ******************
00075 // Including config
00076 // ******************
00077 require_once(PATH_t3lib.'config_default.php');
00078 if (!defined ('TYPO3_db'))      die ('The configuration file was not included.');
00079 
00080 require_once(PATH_t3lib.'class.t3lib_db.php');
00081 $TYPO3_DB = t3lib_div::makeInstance('t3lib_DB');
00082 
00083 require_once(PATH_t3lib.'class.t3lib_stdgraphic.php');
00084 
00085 
00086 
00087 
00088 
00097 class SC_tslib_showpic {
00098         var $content;           // Page content accumulated here.
00099 
00100                 // Parameters loaded into these internal variables:
00101         var $file;
00102         var $width;
00103         var $height;
00104         var $sample;
00105         var $alternativeTempPath;
00106         var $effects;
00107         var $frame;
00108         var $bodyTag;
00109         var $title;
00110         var $wrap;
00111         var $md5;
00112 
00118         function init() {
00119                         // Loading internal vars with the GET/POST parameters from outside:
00120                 $this->file = t3lib_div::_GP('file');
00121                 $this->width = t3lib_div::_GP('width');
00122                 $this->height = t3lib_div::_GP('height');
00123                 $this->sample = t3lib_div::_GP('sample');
00124                 $this->alternativeTempPath = t3lib_div::_GP('alternativeTempPath');
00125                 $this->effects = t3lib_div::_GP('effects');
00126                 $this->frame = t3lib_div::_GP('frame');
00127                 $this->bodyTag = t3lib_div::_GP('bodyTag');
00128                 $this->title = t3lib_div::_GP('title');
00129                 $this->wrap = t3lib_div::_GP('wrap');
00130                 $this->md5 = t3lib_div::_GP('md5');
00131 
00132                 // ***********************
00133                 // Check parameters
00134                 // ***********************
00135                         // If no file-param is given, we must exit
00136                 if (!$this->file)       {
00137                         die('Parameter Error: No file given.');
00138                 }
00139 
00140                         // 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
00141                 $md5_value = md5(
00142                                 $this->file.'|'.
00143                                 $this->width.'|'.
00144                                 $this->height.'|'.
00145                                 $this->effects.'|'.
00146                                 $this->bodyTag.'|'.
00147                                 $this->title.'|'.
00148                                 $this->wrap.'|'.
00149                                 $GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey'].'|');
00150 
00151                 if ($md5_value!=$this->md5) {
00152                         die('Parameter Error: Wrong parameters sent.');
00153                 }
00154 
00155                 // ***********************
00156                 // Check the file. If must be in a directory beneath the dir of this script...
00157                 // $this->file remains unchanged, because of the code in stdgraphic, but we do check if the file exists within the current path
00158                 // ***********************
00159 
00160                 $test_file=PATH_site.$this->file;
00161                 if (!t3lib_div::validPathStr($test_file))       {
00162                         die('Parameter Error: No valid filepath');
00163                 }
00164                 if (!@is_file($test_file))      {
00165                         die('The given file was not found');
00166                 }
00167         }
00168 
00175         function main() {
00176 
00177                         // Creating stdGraphic object, initialize it and make image:
00178                 $img = t3lib_div::makeInstance('t3lib_stdGraphic');
00179                 $img->mayScaleUp = 0;
00180                 $img->init();
00181                 if ($this->sample)      {$img->scalecmd = '-sample';}
00182                 if ($this->alternativeTempPath && t3lib_div::inList($GLOBALS['TYPO3_CONF_VARS']['FE']['allowedTempPaths'],$this->alternativeTempPath))  {
00183                         $img->tempPath = $this->alternativeTempPath;
00184                 }
00185 
00186                         // Need to connect to database, because this is used (typo3temp_db_tracking, cached image dimensions).
00187                 $GLOBALS['TYPO3_DB']->sql_pconnect(TYPO3_db_host, TYPO3_db_username, TYPO3_db_password);
00188                 $GLOBALS['TYPO3_DB']->sql_select_db(TYPO3_db);
00189 
00190                 if (strstr($this->width.$this->height, 'm')) {$max='m';} else {$max='';}
00191 
00192                 $this->height = t3lib_div::intInRange($this->height,0,1000);
00193                 $this->width = t3lib_div::intInRange($this->width,0,1000);
00194                 if ($this->frame)       {$this->frame = intval($this->frame);}
00195                 $imgInfo = $img->imageMagickConvert($this->file,'web',$this->width.$max,$this->height,$img->IMparams($this->effects),$this->frame,'');
00196 
00197 
00198                         // Create HTML output:
00199                 $this->content='';
00200                 $this->content.='
00201 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
00202 
00203 <html>
00204 <head>
00205         <title>'.htmlspecialchars($this->title ? $this->title : "Image").'</title>
00206 </head>
00207                 '.($this->bodyTag ? $this->bodyTag : '<body>');
00208 
00209                 if (is_array($imgInfo)) {
00210                         $wrapParts = explode('|',$this->wrap);
00211                         $this->content.=trim($wrapParts[0]).$img->imgTag($imgInfo).trim($wrapParts[1]);
00212                 }
00213                 $this->content.='
00214                 </body>
00215                 </html>';
00216         }
00217 
00223         function printContent() {
00224                 echo $this->content;
00225         }
00226 }
00227 
00228 // Include extension?
00229 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['tslib/showpic.php'])       {
00230         include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['tslib/showpic.php']);
00231 }
00232 
00233 
00234 
00235 
00236 
00237 
00238 
00239 
00240 
00241 
00242 
00243 
00244 // Make instance:
00245 $SOBE = t3lib_div::makeInstance('SC_tslib_showpic');
00246 $SOBE->init();
00247 $SOBE->main();
00248 $SOBE->printContent();
00249 ?>


Généré par TYPO3 Ameos avec  doxygen 1.4.6