PageRenderTime 30ms CodeModel.GetById 5ms RepoModel.GetById 0ms app.codeStats 0ms

/typo3/sysext/cms/tslib/showpic.php

https://bitbucket.org/linxpinx/mercurial
PHP | 259 lines | 164 code | 22 blank | 73 comment | 15 complexity | f210593a2425470605085906f87da4b4 MD5 | raw file
Possible License(s): BSD-3-Clause, GPL-2.0, Unlicense, LGPL-2.1, Apache-2.0
  1. <?php
  2. /***************************************************************
  3. * Copyright notice
  4. *
  5. * (c) 1999-2010 Kasper Skaarhoj (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. * $Id: showpic.php 7905 2010-06-13 14:42:33Z ohader $
  32. * Revised for TYPO3 3.6 June/2003 by Kasper Skaarhoj
  33. *
  34. * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
  35. */
  36. /**
  37. * [CLASS/FUNCTION INDEX of SCRIPT]
  38. *
  39. *
  40. *
  41. * 112: class SC_tslib_showpic
  42. * 133: function init()
  43. * 190: function main()
  44. * 237: function printContent()
  45. *
  46. * TOTAL FUNCTIONS: 3
  47. * (This index is automatically created/updated by the extension "extdeveval")
  48. *
  49. */
  50. // *******************************
  51. // Set error reporting
  52. // *******************************
  53. if (defined('E_DEPRECATED')) {
  54. error_reporting(E_ALL ^ E_NOTICE ^ E_DEPRECATED);
  55. } else {
  56. error_reporting(E_ALL ^ E_NOTICE);
  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. if (!defined('PATH_thisScript')) define('PATH_thisScript',str_replace('//','/', str_replace('\\','/', (PHP_SAPI=='cgi'||PHP_SAPI=='isapi' ||PHP_SAPI=='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']))));
  64. if (!defined('PATH_site')) define('PATH_site', dirname(PATH_thisScript).'/');
  65. if (!defined('PATH_t3lib')) define('PATH_t3lib', PATH_site.'t3lib/');
  66. define('PATH_tslib', PATH_site.'tslib/');
  67. define('PATH_typo3conf', PATH_site.'typo3conf/');
  68. define('TYPO3_mainDir', 'typo3/'); // This is the directory of the backend administration for the sites of this TYPO3 installation.
  69. if (!@is_dir(PATH_typo3conf)) die('Cannot find configuration. This file is probably executed from the wrong location.');
  70. require_once(PATH_t3lib.'class.t3lib_div.php');
  71. require_once(PATH_t3lib.'class.t3lib_extmgm.php');
  72. // ******************
  73. // Including config
  74. // ******************
  75. require_once(PATH_t3lib.'config_default.php');
  76. if (!defined ('TYPO3_db')) die ('The configuration file was not included.');
  77. require_once(PATH_t3lib.'class.t3lib_db.php');
  78. $TYPO3_DB = t3lib_div::makeInstance('t3lib_DB');
  79. # 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!
  80. # 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!
  81. if (!defined ('PATH_typo3conf')) die ('The configuration path was not properly defined!');
  82. require_once(PATH_t3lib.'class.t3lib_stdgraphic.php');
  83. /**
  84. * Script Class, generating the page output.
  85. * Instantiated in the bottom of this script.
  86. *
  87. * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
  88. * @package TYPO3
  89. * @subpackage tslib
  90. */
  91. class SC_tslib_showpic {
  92. var $content; // Page content accumulated here.
  93. // Parameters loaded into these internal variables:
  94. var $file;
  95. var $width;
  96. var $height;
  97. var $sample;
  98. var $alternativeTempPath;
  99. var $effects;
  100. var $frame;
  101. var $bodyTag;
  102. var $title;
  103. var $wrap;
  104. var $md5;
  105. /**
  106. * Init function, setting the input vars in the global space.
  107. *
  108. * @return void
  109. */
  110. function init() {
  111. // Loading internal vars with the GET/POST parameters from outside:
  112. $this->file = t3lib_div::_GP('file');
  113. $this->width = t3lib_div::_GP('width');
  114. $this->height = t3lib_div::_GP('height');
  115. $this->sample = t3lib_div::_GP('sample');
  116. $this->alternativeTempPath = t3lib_div::_GP('alternativeTempPath');
  117. $this->effects = t3lib_div::_GP('effects');
  118. $this->frame = t3lib_div::_GP('frame');
  119. $this->bodyTag = t3lib_div::_GP('bodyTag');
  120. $this->title = t3lib_div::_GP('title');
  121. $this->wrap = t3lib_div::_GP('wrap');
  122. $this->md5 = t3lib_div::_GP('md5');
  123. // ***********************
  124. // Check parameters
  125. // ***********************
  126. // If no file-param is given, we must exit
  127. if (!$this->file) {
  128. die('Parameter Error: No file given.');
  129. }
  130. // 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
  131. $md5_value = md5(
  132. $this->file.'|'.
  133. $this->width.'|'.
  134. $this->height.'|'.
  135. $this->effects.'|'.
  136. $this->bodyTag.'|'.
  137. $this->title.'|'.
  138. $this->wrap.'|'.
  139. $GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey'].'|');
  140. if ($md5_value!=$this->md5) {
  141. die('Parameter Error: Wrong parameters sent.');
  142. }
  143. // ***********************
  144. // Check the file. If must be in a directory beneath the dir of this script...
  145. // $this->file remains unchanged, because of the code in stdgraphic, but we do check if the file exists within the current path
  146. // ***********************
  147. $test_file=PATH_site.$this->file;
  148. if (!t3lib_div::validPathStr($test_file)) {
  149. die('Parameter Error: No valid filepath');
  150. }
  151. if (!@is_file($test_file)) {
  152. die('The given file was not found');
  153. }
  154. }
  155. /**
  156. * Main function which creates the image if needed and outputs the HTML code for the page displaying the image.
  157. * Accumulates the content in $this->content
  158. *
  159. * @return void
  160. */
  161. function main() {
  162. // Creating stdGraphic object, initialize it and make image:
  163. $img = t3lib_div::makeInstance('t3lib_stdGraphic');
  164. $img->mayScaleUp = 0;
  165. $img->init();
  166. if ($this->sample) {$img->scalecmd = '-sample';}
  167. if ($this->alternativeTempPath && t3lib_div::inList($GLOBALS['TYPO3_CONF_VARS']['FE']['allowedTempPaths'],$this->alternativeTempPath)) {
  168. $img->tempPath = $this->alternativeTempPath;
  169. }
  170. // Need to connect to database, because this is used (typo3temp_db_tracking, cached image dimensions).
  171. $GLOBALS['TYPO3_DB']->sql_pconnect(TYPO3_db_host, TYPO3_db_username, TYPO3_db_password);
  172. $GLOBALS['TYPO3_DB']->sql_select_db(TYPO3_db);
  173. if (strstr($this->width.$this->height, 'm')) {$max='m';} else {$max='';}
  174. $this->height = t3lib_div::intInRange($this->height,0);
  175. $this->width = t3lib_div::intInRange($this->width,0);
  176. if ($this->frame) {$this->frame = intval($this->frame);}
  177. $imgInfo = $img->imageMagickConvert($this->file,'web',$this->width.$max,$this->height,$img->IMparams($this->effects),$this->frame,'');
  178. // Create HTML output:
  179. $this->content='';
  180. $this->content.='
  181. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
  182. <html>
  183. <head>
  184. <title>'.htmlspecialchars($this->title ? $this->title : "Image").'</title>
  185. ' . ($this->title ? '' : '<meta name="robots" content="noindex,follow" />') . '
  186. </head>
  187. '.($this->bodyTag ? $this->bodyTag : '<body>');
  188. if (is_array($imgInfo)) {
  189. $wrapParts = explode('|',$this->wrap);
  190. $this->content.=trim($wrapParts[0]).$img->imgTag($imgInfo).trim($wrapParts[1]);
  191. }
  192. $this->content.='
  193. </body>
  194. </html>';
  195. }
  196. /**
  197. * Outputs the content from $this->content
  198. *
  199. * @return void
  200. */
  201. function printContent() {
  202. echo $this->content;
  203. }
  204. }
  205. if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['tslib/showpic.php']) {
  206. include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['tslib/showpic.php']);
  207. }
  208. // Make instance:
  209. $SOBE = t3lib_div::makeInstance('SC_tslib_showpic');
  210. $SOBE->init();
  211. $SOBE->main();
  212. $SOBE->printContent();
  213. ?>