[ Index ]

PHP Cross Reference of phpwcms V1.4.7 _r403 (01.11.10)

title

Body

[close]

/img/ -> cmsimage.php (source)

   1  <?php
   2  /*************************************************************************************
   3     Copyright notice
   4     
   5     (c) 2002-2010 Oliver Georgi (oliver@phpwcms.de) // All rights reserved.
   6   
   7     This script is part of PHPWCMS. The PHPWCMS web content management system is
   8     free software; you can redistribute it and/or modify it under the terms of
   9     the GNU General Public License as published by the Free Software Foundation;
  10     either version 2 of the License, or (at your option) any later version.
  11    
  12     The GNU General Public License can be found at http://www.gnu.org/copyleft/gpl.html
  13     A copy is found in the textfile GPL.txt and important notices to the license 
  14     from the author is found in LICENSE.txt distributed with these scripts.
  15    
  16     This script is distributed in the hope that it will be useful, but WITHOUT ANY 
  17     WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
  18     PARTICULAR PURPOSE.  See the GNU General Public License for more details.
  19   
  20     This copyright notice MUST APPEAR in all copies of the script!
  21  *************************************************************************************/
  22  
  23  
  24  $phpwcms    = array();
  25  $root        = rtrim(str_replace('\\', '/', realpath(dirname(__FILE__).'/../') ), '/').'/';
  26  require($root.'/config/phpwcms/conf.inc.php');
  27  require ($root.'/include/inc_lib/default.inc.php');
  28  require ($root.'/include/inc_lib/general.inc.php');
  29  require ($root.'/include/inc_lib/imagick.convert.inc.php');
  30  
  31  // get segments: cmsimage.php/%WIDTH%x%HEIGHT%x%CROP%x%QUALITY%/%HASH%.%EXT%
  32  // by default this should be enough: cmsimage.php/%WIDTH%x%HEIGHT/%HASH%.%EXT%
  33  $request_uri        = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : $_SERVER['PHP_SELF'];
  34  
  35  // strip out PHPSESSNAME=...
  36  if(session_id() && session_name()) {
  37      // session expected at the end of REQUEST URI when added by PHP
  38      $session_name_pos = strpos($request_uri, session_name().'=');
  39      if($session_name_pos !== FALSE) {
  40          $request_uri = trim(trim(substr($request_uri, 0, $session_name_pos), '&'), '?');
  41      }
  42  }
  43  
  44  $query_separator    = strpos($request_uri, 'cmsimage.php?') !== FALSE ? '?' : '/';
  45  $data                = explode('cmsimage.php'.$query_separator, $request_uri, 2);
  46  if(isset($data[1]) && !preg_match('/[^a-fgijpnxA-FGIJPN0-9\/\.]/', $data[1])) {
  47  
  48      $data = explode('/', $data[1]);
  49  
  50      // first check hashed data
  51      if(isset($data[1])) {
  52      
  53          $data[0]    = preg_replace('/[^0-9x]/', '', $data[0]);
  54          $data[1]    = preg_replace('/[^a-fgijpn0-9\.]/i', '', $data[1]);
  55  
  56          $value        = array();
  57  
  58          $hash        = cut_ext($data[1]);
  59          $ext        = which_ext($data[1]);
  60          
  61          if(is_numeric($hash)) {
  62          
  63              require_once (PHPWCMS_ROOT.'/include/inc_lib/dbcon.inc.php');
  64          
  65              $sql   = 'SELECT f_hash, f_ext FROM '.DB_PREPEND.'phpwcms_file WHERE ';
  66              $sql  .= 'f_id='.intval($hash)." AND ";
  67              if(!$phpwcms['imagick']) {
  68                  $sql .= "f_ext IN ('jpg','jpeg','png','gif','bmp') AND ";
  69              }
  70              $sql  .= 'f_trash=0 AND f_aktiv=1 AND f_public=1';
  71              $hash  = _dbQuery($sql);
  72              if(isset($hash[0]['f_hash'])) {
  73                  $ext  = $hash[0]['f_ext'];
  74                  $hash = $hash[0]['f_hash'];
  75              } else {
  76                  $hash = '';
  77                  $ext  = '';
  78              }
  79              
  80          } elseif($hash && strlen($hash) == 32 && $ext && !is_file(PHPWCMS_ROOT.'/'.PHPWCMS_FILES.$hash.'.'.$ext)) {
  81              
  82              require_once (PHPWCMS_ROOT.'/include/inc_lib/dbcon.inc.php');
  83          
  84              $sql   = 'SELECT f_hash, f_ext FROM '.DB_PREPEND.'phpwcms_file WHERE ';
  85              $sql  .= 'f_hash='._dbEscape($hash)." AND ";
  86              if(!$phpwcms['imagick']) {
  87                  $sql .= "f_ext IN ('jpg','jpeg','png','gif','bmp') AND ";
  88              }
  89              $sql  .= 'f_trash=0 AND f_aktiv=1 AND f_public=1';
  90              $hash  = _dbQuery($sql);
  91              if(isset($hash[0]['f_hash'])) {
  92                  $ext  = $hash[0]['f_ext'];
  93                  $hash = $hash[0]['f_hash'];
  94              } else {
  95                  $hash = '';
  96                  $ext  = '';
  97              }
  98              
  99          }
 100          
 101          if($hash && strlen($hash) == 32 && $ext) {
 102          
 103              $attribute    = explode('x', $data[0]);
 104              $width        = intval($attribute[0]);
 105              $height        = isset($attribute[1]) ? intval($attribute[1]) : 0;
 106              $crop        = isset($attribute[2]) ? (intval($attribute[2]) ? 1 : 0) : 0;
 107              
 108              // quality
 109              if(isset($attribute[3]) && ($quality = intval($attribute[3])) ) {
 110                  if($quality < 10 || $quality > 100) {
 111                      $quality = '';
 112                  } else {
 113                      $value['jpg_quality'] = $quality;
 114                  }
 115              } else {
 116                  $quality = '';
 117              }
 118          
 119              if($width) {
 120                  $value["max_width"]        = $width;
 121              } else {
 122                  $width                    = '';
 123              }
 124              if($height) {
 125                  $value["max_height"]    = $height;
 126              } else {
 127                  $height                    = '';
 128              }
 129              $value['target_ext']        = $ext;
 130              $value['image_name']        = $hash . '.' . $ext;
 131              $value['image_name']        = $hash . '.' . $ext;
 132              $value['thumb_name']        = md5($hash.$width.$height.$phpwcms['sharpen_level'].$crop.$quality);
 133              $value['crop_image']        = $crop;
 134              
 135              $image = get_cached_image( $value, false, false );
 136              
 137              if(!empty($image[0])) {
 138                  headerRedirect(PHPWCMS_URL.PHPWCMS_IMAGES.$image[0], 301);
 139              }
 140              
 141          }
 142      
 143      }
 144  
 145  }
 146  
 147  // something did not work - redirect to transparent pixel image
 148  headerRedirect(PHPWCMS_URL.'img/leer.gif', 301);
 149  
 150  
 151  ?>


Generated: Tue Nov 16 22:51:00 2010 Cross-referenced by PHPXref 0.7