[ Index ]

PHP Cross Reference of phpwcms V1.4.3 _r380 (23.11.09)

title

Body

[close]

/img/ -> cmsimage.php (source)

   1  <?php
   2  /*************************************************************************************
   3     Copyright notice
   4     
   5     (c) 2002-2009 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          
  81          if($hash && strlen($hash) == 32 && $ext) {
  82          
  83              $attribute    = explode('x', $data[0]);
  84              $width        = intval($attribute[0]);
  85              $height        = isset($attribute[1]) ? intval($attribute[1]) : 0;
  86              $crop        = isset($attribute[2]) ? (intval($attribute[2]) ? 1 : 0) : 0;
  87              
  88              // quality
  89              if(isset($attribute[3]) && ($quality = intval($attribute[3])) ) {
  90                  if($quality < 10 || $quality > 100) {
  91                      $quality = '';
  92                  } else {
  93                      $value['jpg_quality'] = $quality;
  94                  }
  95              } else {
  96                  $quality = '';
  97              }
  98          
  99              if($width) {
 100                  $value["max_width"]        = $width;
 101              } else {
 102                  $width                    = '';
 103              }
 104              if($height) {
 105                  $value["max_height"]    = $height;
 106              } else {
 107                  $height                    = '';
 108              }
 109              $value['target_ext']        = $ext;
 110              $value['image_name']        = $hash . '.' . $ext;
 111              $value['image_name']        = $hash . '.' . $ext;
 112              $value['thumb_name']        = md5($hash.$width.$height.$phpwcms['sharpen_level'].$crop.$quality);
 113              $value['crop_image']        = $crop;
 114              
 115              $image = get_cached_image( $value, false, false );
 116              
 117              if(!empty($image[0])) {
 118                  headerRedirect(PHPWCMS_URL.PHPWCMS_IMAGES.$image[0], 301);
 119              }
 120              
 121          }
 122      
 123      }
 124  
 125  }
 126  
 127  // something did not work - redirect to transparent pixel image
 128  headerRedirect(PHPWCMS_URL.'img/leer.gif', 301);
 129  
 130  
 131  ?>


Generated: Wed Dec 30 05:55:15 2009 Cross-referenced by PHPXref 0.7