Esempio n. 1
0
 function SetCacheFilename()
 {
     if (!is_null($this->cache_filename)) {
         $this->DebugMessage('$this->cache_filename already set, skipping SetCacheFilename()', __FILE__, __LINE__);
         return true;
     }
     $this->setOutputFormat();
     $this->setCacheDirectory();
     if (!$this->config_cache_directory) {
         $this->DebugMessage('SetCacheFilename() failed because $this->config_cache_directory is empty', __FILE__, __LINE__);
         return false;
     }
     if (!$this->sourceFilename && !$this->rawImageData && $this->src) {
         $this->sourceFilename = $this->ResolveFilenameToAbsolute($this->src);
     }
     if ($this->config_cache_default_only_suffix && $this->sourceFilename) {
         // simplified cache filenames:
         // only use default parameters in phpThumb.config.php
         // substitute source filename into * in $this->config_cache_default_only_suffix
         // (eg: '*_thumb' becomes 'picture_thumb.jpg')
         if (strpos($this->config_cache_default_only_suffix, '*') === false) {
             $this->DebugMessage('aborting simplified caching filename because no * in "' . $this->config_cache_default_only_suffix . '"', __FILE__, __LINE__);
         } else {
             preg_match('/(.+)(\\.[a-z0-9]+)?$/iU', basename($this->sourceFilename), $matches);
             $this->cache_filename = $this->config_cache_directory . $this->osslash . str_replace('*', $matches[1], $this->config_cache_default_only_suffix) . '.' . strtolower($this->thumbnailFormat);
             return true;
         }
     }
     $this->cache_filename = $this->config_cache_directory . $this->osslash . 'phpThumb_cache_' . @$_SERVER['SERVER_NAME'];
     if ($this->new) {
         $this->cache_filename .= '_new' . strtolower(md5($this->new));
     } elseif ($this->md5s) {
         // source image MD5 hash provided
         $this->cache_filename .= '_raw' . $this->md5s;
     } elseif (!$this->src && $this->rawImageData) {
         $this->cache_filename .= '_raw' . strtolower(md5($this->rawImageData));
     } else {
         $this->cache_filename .= '_src' . strtolower(md5($this->sourceFilename));
     }
     if (@$_SERVER['HTTP_REFERER'] && $this->config_cache_differentiate_offsite) {
         $parsed_url1 = @parse_url(@$_SERVER['HTTP_REFERER']);
         $parsed_url2 = @parse_url('http://' . @$_SERVER['HTTP_HOST']);
         if (@$parsed_url1['host'] && @$parsed_url2['host'] && $parsed_url1['host'] != $parsed_url2['host']) {
             // include refering domain only if it doesn't match the domain of the current server
             //$this->cache_filename .= '_ref'.strtolower(md5(@$parsed_url2['host']));
             $this->cache_filename .= '_offsite';
         }
     }
     $ParametersString = '';
     if ($this->fltr && is_array($this->fltr)) {
         $ParametersString .= '_fltr' . implode('_fltr', $this->fltr);
     }
     $FilenameParameters1 = array('ar', 'bg', 'bc', 'far');
     foreach ($FilenameParameters1 as $key) {
         if ($this->{$key}) {
             $ParametersString .= '_' . $key . $this->{$key};
         }
     }
     $FilenameParameters2 = array('h', 'w', 'wl', 'wp', 'ws', 'hp', 'hs', 'sx', 'sy', 'sw', 'sh', 'xto', 'ra', 'iar', 'aoe', 'maxb');
     foreach ($FilenameParameters2 as $key) {
         if ($this->{$key}) {
             $ParametersString .= '_' . $key . intval($this->{$key});
         }
     }
     if ($this->thumbnailFormat == 'jpeg') {
         // only JPEG output has variable quality option
         $ParametersString .= '_q' . intval($this->thumbnailQuality);
     }
     $this->DebugMessage('SetCacheFilename() _par set from md5(' . $ParametersString . ')', __FILE__, __LINE__);
     $this->cache_filename .= '_par' . strtolower(md5($ParametersString));
     if ($this->md5s) {
         // source image MD5 hash provided
         // do not source image modification date --
         // cached image will be used even if file was modified or removed
     } elseif (!$this->config_cache_source_filemtime_ignore_remote && eregi('^(f|ht)tps?://', $this->src)) {
         $this->cache_filename .= '_dat' . intval(phpthumb_functions::filedate_remote($this->src));
     } elseif (!$this->config_cache_source_filemtime_ignore_local && $this->src && !$this->rawImageData) {
         $this->cache_filename .= '_dat' . intval(@filemtime($this->sourceFilename));
     }
     $this->cache_filename .= '.' . strtolower($this->thumbnailFormat);
     return true;
 }
Esempio n. 2
0
 function SetCacheFilename()
 {
     if (!is_null($this->cache_filename)) {
         $this->DebugMessage('$this->cache_filename already set, skipping SetCacheFilename()', __FILE__, __LINE__);
         return true;
     }
     $this->setOutputFormat();
     $this->setCacheDirectory();
     if (!$this->config_cache_directory) {
         $this->DebugMessage('SetCacheFilename() failed because $this->config_cache_directory is empty', __FILE__, __LINE__);
         return false;
     }
     if (!$this->sourceFilename && !$this->rawImageData && $this->src) {
         $this->sourceFilename = $this->ResolveFilenameToAbsolute($this->src);
     }
     if ($this->config_cache_default_only_suffix && $this->sourceFilename) {
         // simplified cache filenames:
         // only use default parameters in phpThumb.config.php
         // substitute source filename into * in $this->config_cache_default_only_suffix
         // (eg: '*_thumb' becomes 'picture_thumb.jpg')
         if (strpos($this->config_cache_default_only_suffix, '*') === false) {
             $this->DebugMessage('aborting simplified caching filename because no * in "' . $this->config_cache_default_only_suffix . '"', __FILE__, __LINE__);
         } else {
             preg_match('#(.+)(\\.[a-z0-9]+)?$#i', basename($this->sourceFilename), $matches);
             $this->cache_filename = $this->config_cache_directory . DIRECTORY_SEPARATOR . rawurlencode(str_replace('*', @$matches[1], $this->config_cache_default_only_suffix)) . '.' . strtolower($this->thumbnailFormat);
             return true;
         }
     }
     $this->cache_filename = '';
     $broad_directory_name = '';
     if ($this->new) {
         $broad_directory_name = strtolower(md5($this->new));
         $this->cache_filename .= '_new' . $broad_directory_name;
     } elseif ($this->md5s) {
         // source image MD5 hash provided
         $this->DebugMessage('SetCacheFilename() _raw set from $this->md5s = "' . $this->md5s . '"', __FILE__, __LINE__);
         $broad_directory_name = $this->md5s;
         $this->cache_filename .= '_raw' . $this->md5s;
     } elseif (!$this->src && $this->rawImageData) {
         $this->DebugMessage('SetCacheFilename() _raw set from md5($this->rawImageData) = "' . md5($this->rawImageData) . '"', __FILE__, __LINE__);
         $broad_directory_name = strtolower(md5($this->rawImageData));
         $this->cache_filename .= '_raw' . $broad_directory_name;
     } else {
         $this->DebugMessage('SetCacheFilename() _src set from md5($this->sourceFilename) "' . $this->sourceFilename . '" = "' . md5($this->sourceFilename) . '"', __FILE__, __LINE__);
         $broad_directory_name = strtolower(md5($this->sourceFilename));
         $this->cache_filename .= '_src' . $broad_directory_name;
     }
     if (@$_SERVER['HTTP_REFERER'] && $this->config_nooffsitelink_enabled) {
         $parsed_url1 = @phpthumb_functions::ParseURLbetter(@$_SERVER['HTTP_REFERER']);
         $parsed_url2 = @phpthumb_functions::ParseURLbetter('http://' . @$_SERVER['HTTP_HOST']);
         if (@$parsed_url1['host'] && @$parsed_url2['host'] && $parsed_url1['host'] != $parsed_url2['host']) {
             // include "_offsite" only if nooffsitelink_enabled and if referrer doesn't match the domain of the current server
             $this->cache_filename .= '_offsite';
         }
     }
     $ParametersString = '';
     if ($this->fltr && is_array($this->fltr)) {
         $ParametersString .= '_fltr' . implode('_fltr', $this->fltr);
     }
     $FilenameParameters1 = array('ar', 'bg', 'bc', 'far', 'sx', 'sy', 'sw', 'sh', 'zc');
     foreach ($FilenameParameters1 as $key) {
         if ($this->{$key}) {
             $ParametersString .= '_' . $key . $this->{$key};
         }
     }
     $FilenameParameters2 = array('h', 'w', 'wl', 'wp', 'ws', 'hp', 'hs', 'xto', 'ra', 'iar', 'aoe', 'maxb', 'sfn', 'dpi');
     foreach ($FilenameParameters2 as $key) {
         if ($this->{$key}) {
             $ParametersString .= '_' . $key . intval($this->{$key});
         }
     }
     if ($this->thumbnailFormat == 'jpeg') {
         // only JPEG output has variable quality option
         $ParametersString .= '_q' . intval($this->thumbnailQuality);
     }
     $this->DebugMessage('SetCacheFilename() _par set from md5(' . $ParametersString . ')', __FILE__, __LINE__);
     $this->cache_filename .= '_par' . strtolower(md5($ParametersString));
     if ($this->md5s) {
         // source image MD5 hash provided
         // do not source image modification date --
         // cached image will be used even if file was modified or removed
     } elseif (!$this->config_cache_source_filemtime_ignore_remote && preg_match('#^(f|ht)tps?\\://#i', $this->src)) {
         $this->cache_filename .= '_dat' . intval(phpthumb_functions::filedate_remote($this->src));
     } elseif (!$this->config_cache_source_filemtime_ignore_local && $this->src && !$this->rawImageData) {
         $this->cache_filename .= '_dat' . intval(@filemtime($this->sourceFilename));
     }
     $this->cache_filename .= '.' . strtolower($this->thumbnailFormat);
     $broad_directories = '';
     for ($i = 0; $i < $this->config_cache_directory_depth; $i++) {
         $broad_directories .= DIRECTORY_SEPARATOR . substr($broad_directory_name, 0, $i + 1);
     }
     $this->cache_filename = $this->config_cache_directory . $broad_directories . DIRECTORY_SEPARATOR . $this->config_cache_prefix . rawurlencode($this->cache_filename);
     return true;
 }
 function SetCacheFilename()
 {
     if (!is_null($this->cache_filename)) {
         // $this->cache_filename already set, no need to re-set it
         return true;
     }
     $this->setOutputFormat();
     $this->setCacheDirectory();
     if (empty($this->config_cache_directory)) {
         $this->DebugMessage('SetCacheFilename() failed because $this->config_cache_directory is empty', __FILE__, __LINE__);
         return false;
     }
     if (empty($this->sourceFilename) && empty($this->rawImageData) && !empty($this->src)) {
         $this->sourceFilename = $this->ResolveFilenameToAbsolute($this->src);
     }
     $this->cache_filename = $this->config_cache_directory . '/phpThumb_cache';
     if ($this->new) {
         $this->cache_filename .= '_new' . $this->new;
     } elseif (!$this->src && $this->rawImageData) {
         $this->cache_filename .= '_' . strtolower(md5($this->rawImageData));
     } else {
         $this->cache_filename .= '_' . urlencode($this->src);
     }
     if (!empty($_SERVER['HTTP_REFERER'])) {
         $parsed_url1 = @parse_url(@$_SERVER['HTTP_REFERER']);
         $parsed_url2 = @parse_url('http://' . @$_SERVER['HTTP_HOST']);
         if (@$parsed_url1['host'] && @$parsed_url2['host'] && $parsed_url1['host'] != $parsed_url2['host']) {
             // include refering domain only if it doesn't match the domain of the current server
             $this->cache_filename .= '_httpreferer' . urlencode(@$parsed_url2['host']);
         }
     }
     if (!empty($_REQUEST['fltr']) && is_array($_REQUEST['fltr'])) {
         $this->cache_filename .= '_fltr' . urlencode(str_replace('|', '¦', implode('_fltr', $_REQUEST['fltr'])));
     }
     $FilenameParameters = array('h', 'w', 'sx', 'sy', 'sw', 'sh', 'far', 'bg', 'bgt', 'bc', 'xto', 'ra', 'ar', 'iar', 'maxb');
     foreach ($FilenameParameters as $key) {
         if (isset($this->{$key})) {
             if ($this->{$key} === true) {
                 $this->cache_filename .= '_' . $key . '1';
             } else {
                 $this->cache_filename .= '_' . $key . $this->{$key};
             }
         }
     }
     if (eregi('^(f|ht)tp[s]?://', $this->src)) {
         $this->cache_filename .= '_' . intval(phpthumb_functions::filedate_remote($this->src));
     } elseif ($this->src && !$this->rawImageData) {
         $this->cache_filename .= '_' . intval(@filemtime($this->sourceFilename));
     }
     $this->cache_filename .= '_q' . $this->thumbnailQuality;
     $this->cache_filename .= '_' . $this->thumbnailFormat;
     return true;
 }