00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058 if (defined('E_DEPRECATED')) {
00059 error_reporting(E_ALL ^ E_NOTICE ^ E_DEPRECATED);
00060 } else {
00061 error_reporting(E_ALL ^ E_NOTICE);
00062 }
00063
00064
00065
00066
00067
00068
00069 define('TYPO3_OS', stristr(PHP_OS,'win')&&!stristr(PHP_OS,'darwin')?'WIN':'');
00070 define('TYPO3_MODE','BE');
00071 if(!defined('PATH_thisScript')) define('PATH_thisScript',str_replace('
00072 if(!defined('PATH_site')) define('PATH_site', preg_replace('/[^\/]*.[^\/]*$/','',PATH_thisScript));
00073 if(!defined('PATH_t3lib')) define('PATH_t3lib', PATH_site.'t3lib/');
00074 define('PATH_typo3conf', PATH_site.'typo3conf/');
00075 define('TYPO3_mainDir', 'typo3/');
00076 define('PATH_typo3', PATH_site.TYPO3_mainDir);
00077
00078
00079
00080
00081
00082 require_once(PATH_t3lib.'class.t3lib_div.php');
00083 require_once(PATH_t3lib.'class.t3lib_extmgm.php');
00084
00085 require(PATH_t3lib.'config_default.php');
00086 if (!defined ('TYPO3_db')) die ('The configuration file was not included.');
00087 if (!$TYPO3_CONF_VARS['GFX']['image_processing']) die ('ImageProcessing was disabled!');
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117 class SC_t3lib_thumbs {
00118 var $include_once = array();
00119
00120 var $outdir = 'typo3temp/';
00121 var $output = '';
00122 var $sizeDefault='56x56';
00123
00124 var $imageList;
00125 var $input;
00126
00127
00128 var $file;
00129 var $size;
00130 var $mtime = 0;
00131
00132
00133
00134
00135
00136
00137
00138
00139 function init() {
00140 global $TYPO3_CONF_VARS;
00141
00142
00143 $file = t3lib_div::_GP('file');
00144 $size = t3lib_div::_GP('size');
00145 $md5sum = t3lib_div::_GP('md5sum');
00146
00147
00148 $this->imageList = $TYPO3_CONF_VARS['GFX']['imagefile_ext'];
00149
00150
00151 if (substr($file,0,3)=='../') {
00152 $file = PATH_site.substr($file,3);
00153 }
00154
00155
00156
00157 if (t3lib_div::isAllowedAbsPath($file)) {
00158 $mtime = filemtime($file);
00159 }
00160
00161
00162 $OK = FALSE;
00163 if ($mtime) {
00164
00165 $check = basename($file).':'.$mtime.':'.$GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey'];
00166 $md5_real = t3lib_div::shortMD5($check);
00167 if (!strcmp($md5_real,$md5sum)) {
00168 $OK = TRUE;
00169 }
00170 }
00171
00172 if ($OK) {
00173 $this->input = $file;
00174 $this->size = $size;
00175 $this->mtime = $mtime;
00176 } else {
00177 throw new RuntimeException(
00178 'TYPO3 Fatal Error: Image does not exist and/or MD5 checksum did not match.',
00179 1270853950
00180 );
00181 }
00182 }
00183
00184
00185
00186
00187
00188
00189
00190 function main() {
00191 global $TYPO3_CONF_VARS;
00192
00193
00194 if ($this->input && file_exists($this->input)) {
00195
00196
00197 $reg = array();
00198 if (preg_match('/(.*)\.([^\.]*$)/',$this->input,$reg)) {
00199 $ext=strtolower($reg[2]);
00200 $ext=($ext=='jpeg')?'jpg':$ext;
00201 if ($ext=='ttf') {
00202 $this->fontGif($this->input);
00203 } elseif (!t3lib_div::inList($this->imageList, $ext)) {
00204 $this->errorGif('Not imagefile!',$ext,basename($this->input));
00205 }
00206 } else {
00207 $this->errorGif('Not imagefile!','No ext!',basename($this->input));
00208 }
00209
00210
00211 if (!$this->size) $this->size = $this->sizeDefault;
00212
00213
00214 $sizeParts = explode('x', $this->size.'x'.$this->size);
00215 $sizeParts = array(t3lib_div::intInRange($sizeParts[0],1,1000),t3lib_div::intInRange($sizeParts[1],1,1000));
00216 $this->size = implode('x',$sizeParts);
00217 $sizeMax = max($sizeParts);
00218
00219
00220 $outpath = PATH_site.$this->outdir;
00221
00222
00223
00224 $thmMode = t3lib_div::intInRange($TYPO3_CONF_VARS['GFX']['thumbnails_png'],0);
00225 $outext = ($ext!='jpg' || ($thmMode & 2)) ? ($thmMode & 1 ? 'png' : 'gif') : 'jpg';
00226
00227 $outfile = 'tmb_'.substr(md5($this->input.$this->mtime.$this->size),0,10).'.'.$outext;
00228 $this->output = $outpath.$outfile;
00229
00230 if ($TYPO3_CONF_VARS['GFX']['im']) {
00231
00232 if (!file_exists($this->output)) {
00233 $parameters = '-sample ' . $this->size . ' ' . $this->wrapFileName($this->input) . '[0] ' . $this->wrapFileName($this->output);
00234 $cmd = t3lib_div::imageMagickCommand('convert', $parameters);
00235 exec($cmd);
00236 if (!file_exists($this->output)) {
00237 $this->errorGif('No thumb','generated!',basename($this->input));
00238 }
00239 }
00240
00241 if($fd = @fopen($this->output,'rb')) {
00242 header('Content-type: image/'.$outext);
00243 fpassthru($fd);
00244 fclose($fd);
00245 } else {
00246 $this->errorGif('Read problem!','',$this->output);
00247 }
00248 } else exit;
00249 } else {
00250 $this->errorGif('No valid','inputfile!',basename($this->input));
00251 }
00252 }
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280 function errorGif($l1,$l2,$l3) {
00281 global $TYPO3_CONF_VARS;
00282
00283 if (!$TYPO3_CONF_VARS['GFX']['gdlib']) {
00284 throw new RuntimeException(
00285 'TYPO3 Fatal Error: No gdlib. ' . $l1 . ' ' . $l2 . ' ' . $l3,
00286 1270853952
00287 );
00288 }
00289
00290
00291 if ($TYPO3_CONF_VARS['GFX']['gdlib_png']) {
00292 header('Content-type: image/png');
00293 $im = imagecreatefrompng(PATH_typo3.'gfx/notfound_thumb.png');
00294 } else {
00295 header('Content-type: image/gif');
00296 $im = imagecreatefromgif(PATH_typo3.'gfx/notfound_thumb.gif');
00297 }
00298
00299 $white = imageColorAllocate($im, 0,0,0);
00300 $black = imageColorAllocate($im, 255,255,0);
00301
00302
00303 $x=0;
00304 $font=0;
00305 if ($l1) {
00306 imagefilledrectangle($im, $x, 9, 56, 16, $black);
00307 imageString($im,$font,$x,9,$l1,$white);
00308 }
00309 if ($l2) {
00310 imagefilledrectangle($im, $x, 19, 56, 26, $black);
00311 imageString($im,$font,$x,19,$l2,$white);
00312 }
00313 if ($l3) {
00314 imagefilledrectangle($im, $x, 29, 56, 36, $black);
00315 imageString($im,$font,$x,29,substr($l3,-14),$white);
00316 }
00317
00318
00319 if ($TYPO3_CONF_VARS['GFX']['gdlib_png']) {
00320 imagePng($im);
00321 } else {
00322 imageGif($im);
00323 }
00324 imagedestroy($im);
00325 exit;
00326 }
00327
00328
00329
00330
00331
00332
00333
00334
00335
00336
00337 function fontGif($font) {
00338 global $TYPO3_CONF_VARS;
00339
00340 if (!$TYPO3_CONF_VARS['GFX']['gdlib']) {
00341 throw new RuntimeException(
00342 'TYPO3 Fatal Error: No gdlib.',
00343 1270853953
00344 );
00345 }
00346
00347
00348 $im = imageCreate(250,76);
00349 $white = imageColorAllocate($im, 255,255,255);
00350 $col = imageColorAllocate($im, 0,0,0);
00351
00352
00353 $string = 'AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZzÆæØøÅåÄäÖöÜüß';
00354 $x=13;
00355
00356
00357 imagestring ($im, 1, 0, 2, '10', $col);
00358 imagestring ($im, 1, 0, 15, '12', $col);
00359 imagestring ($im, 1, 0, 30, '14', $col);
00360 imagestring ($im, 1, 0, 47, '18', $col);
00361 imagestring ($im, 1, 0, 68, '24', $col);
00362
00363
00364 imagettftext ($im, t3lib_div::freetypeDpiComp(10), 0, $x, 8, $col, $font, $string);
00365 imagettftext ($im, t3lib_div::freetypeDpiComp(12), 0, $x, 21, $col, $font, $string);
00366 imagettftext ($im, t3lib_div::freetypeDpiComp(14), 0, $x, 36, $col, $font, $string);
00367 imagettftext ($im, t3lib_div::freetypeDpiComp(18), 0, $x, 53, $col, $font, $string);
00368 imagettftext ($im, t3lib_div::freetypeDpiComp(24), 0, $x, 74, $col, $font, $string);
00369
00370
00371 if ($TYPO3_CONF_VARS['GFX']['gdlib_png']) {
00372 header('Content-type: image/png');
00373 imagePng($im);
00374 } else {
00375 header('Content-type: image/gif');
00376 imageGif($im);
00377 }
00378 imagedestroy($im);
00379 exit;
00380 }
00381
00382
00383
00384
00385
00386
00387
00388
00389 protected function wrapFileName($inputName) {
00390 return escapeshellarg($inputName);
00391 }
00392 }
00393
00394 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/thumbs.php']) {
00395 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/thumbs.php']);
00396 }
00397
00398
00399
00400
00401
00402 $SOBE = t3lib_div::makeInstance('SC_t3lib_thumbs');
00403 $SOBE->init();
00404 $SOBE->main();
00405
00406 ?>