1
0
mirror of https://github.com/e107inc/e107.git synced 2025-07-09 09:13:25 +02:00

Experimental Image-Caching performance enhancement.

This commit is contained in:
Cameron
2017-10-25 15:17:53 -07:00
parent 028e43d80b
commit a2d49a1ce5
3 changed files with 79 additions and 6 deletions

View File

@ -344,7 +344,7 @@ class ecache {
if($type === 'image') if($type === 'image')
{ {
$path = e_CACHE_IMAGE; $path = e_CACHE_IMAGE;
$mask = ($mask == null) ? '.*\.cache\.bin' : $mask; $mask = ($mask == null) ? '.*(\.cache\.bin|\.jpg|\.jpeg|\.png|\.gif)' : $mask;
} }
if($type === 'js') if($type === 'js')

View File

@ -416,6 +416,11 @@ class e107
mkdir(e_SYSTEM, 0755); mkdir(e_SYSTEM, 0755);
} }
if(!is_dir(e_CACHE_IMAGE))
{
mkdir(e_CACHE_IMAGE, 0755);
}
// Prepare essential directories. // Prepare essential directories.
$this->prepareDirs(); $this->prepareDirs();
} }
@ -571,7 +576,16 @@ class e107
$ret['CACHE_DIRECTORY'] = $ret['SYSTEM_DIRECTORY'].'cache/'; $ret['CACHE_DIRECTORY'] = $ret['SYSTEM_DIRECTORY'].'cache/';
$ret['CACHE_CONTENT_DIRECTORY'] = $ret['CACHE_DIRECTORY'].'content/'; $ret['CACHE_CONTENT_DIRECTORY'] = $ret['CACHE_DIRECTORY'].'content/';
$ret['CACHE_IMAGE_DIRECTORY'] = $ret['CACHE_DIRECTORY'].'images/'; //TODO Change to MEDIA Directory.
if(defined('e_MEDIA_STATIC')) // experimental - subject to change.
{
$ret['CACHE_IMAGE_DIRECTORY'] = $ret['MEDIA_IMAGES_DIRECTORY'].'cache/';
}
else
{
$ret['CACHE_IMAGE_DIRECTORY'] = $ret['CACHE_DIRECTORY'].'images/';
}
$ret['CACHE_DB_DIRECTORY'] = $ret['CACHE_DIRECTORY'].'db/'; $ret['CACHE_DB_DIRECTORY'] = $ret['CACHE_DIRECTORY'].'db/';
$ret['CACHE_URL_DIRECTORY'] = $ret['CACHE_DIRECTORY'].'url/'; $ret['CACHE_URL_DIRECTORY'] = $ret['CACHE_DIRECTORY'].'url/';
@ -4212,6 +4226,11 @@ class e107
define('e_AVATAR_ABS', $this->get_override_http('AVATARS')); define('e_AVATAR_ABS', $this->get_override_http('AVATARS'));
define('e_AVATAR_UPLOAD_ABS', $this->get_override_http('AVATARS_UPLOAD')); define('e_AVATAR_UPLOAD_ABS', $this->get_override_http('AVATARS_UPLOAD'));
define('e_AVATAR_DEFAULT_ABS', $this->get_override_http('AVATARS_DEFAULT')); define('e_AVATAR_DEFAULT_ABS', $this->get_override_http('AVATARS_DEFAULT'));
if(defined('e_MEDIA_STATIC')) // experimental - subject to change.
{
define('e_CACHE_IMAGE_ABS', $this->get_override_http('CACHE_IMAGE'));
}
// Special // Special

View File

@ -2493,19 +2493,47 @@ class e_parse extends e_parser
* @param array $options * @param array $options
* @return null|string * @return null|string
*/ */
public function thumbCacheFile($path, $options=array()) public function thumbCacheFile($path, $options=null, $log=null)
{ {
if(empty($path)) if(empty($path))
{ {
return null; return null;
} }
if(is_string($options))
{
parse_str($options,$options);
}
$path = str_replace($this->getUrlConstants('raw'), $this->getUrlConstants('sc'), $path);
$path = $this->replaceConstants(str_replace('..', '', $path));
$filename = basename($path); $filename = basename($path);
$tmp = explode('.',$filename); $tmp = explode('.',$filename);
$ext = end($tmp); $ext = end($tmp);
$len = strlen($ext) + 1; $len = strlen($ext) + 1;
$start = substr($filename,0,- $len); $start = substr($filename,0,- $len);
// cleanup.
$newOpts = array(
'w' => (string) intval($options['w']),
'h' => (string) intval($options['h']),
'aw' => (string) intval($options['aw']),
'ah' => (string) intval($options['ah']),
'c' => strtoupper(vartrue($options['c'],'0'))
);
if($log !== null)
{
file_put_contents(e_LOG.$log, "\n++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n\n", FILE_APPEND);
$message = $path."\n".print_r($newOpts,true)."\n\n\n";
file_put_contents(e_LOG.$log, $message, FILE_APPEND);
// file_put_contents(e_LOG.$log, "\t\tFOUND!!\n\n\n", FILE_APPEND);
}
if(!empty($options['aw'])) if(!empty($options['aw']))
{ {
$options['w'] = $options['aw']; $options['w'] = $options['aw'];
@ -2516,16 +2544,23 @@ class e_parse extends e_parser
$options['h'] = $options['ah']; $options['h'] = $options['ah'];
} }
$size = varset($options['w'],0).'x'.varset($options['h'],0); $size = varset($options['w'],0).'x'.varset($options['h'],0);
$thumbQuality = e107::getPref('thumbnail_quality',65); $thumbQuality = e107::getPref('thumbnail_quality',65);
$cache_str = md5(serialize($options).$path. $thumbQuality); $cache_str = md5(serialize($newOpts).$path. $thumbQuality);
// TODO Remove these.
$pre = 'thumb_'; $pre = 'thumb_';
$post = '.cache.bin'; $post = '.cache.bin';
// $post = '';
// $cache_str = http_build_query($newOpts,null,'_'); // testing files.
if(defined('e_MEDIA_STATIC')) // experimental - subject to change.
{
$pre = '';
$post = '';
}
$fname = $pre.strtolower($start.'_'.$cache_str.'_'.$size.'.'.$ext).$post; $fname = $pre.strtolower($start.'_'.$cache_str.'_'.$size.'.'.$ext).$post;
@ -2635,6 +2670,23 @@ class e_parse extends e_parser
} }
if(defined('e_MEDIA_STATIC')) // experimental - subject to change.
{
$opts = str_replace('&', '&', $thurl);
$staticFile = $this->thumbCacheFile($url, $opts);
if(!empty($staticFile) && is_readable(e_CACHE_IMAGE.$staticFile))
{
//file_put_contents(e_LOG."thumbCache.log",$staticFile."\n",FILE_APPEND);
return e_CACHE_IMAGE_ABS.$staticFile;
}
$options['nosef'] = true;
// file_put_contents(e_LOG."thumb.log", "\n++++++++++++++++++++++++++++++++++\n\n", FILE_APPEND);
}
if(e_MOD_REWRITE_MEDIA == true && empty($options['nosef']) )// Experimental SEF URL support. if(e_MOD_REWRITE_MEDIA == true && empty($options['nosef']) )// Experimental SEF URL support.
{ {
$options['full'] = $full; $options['full'] = $full;
@ -2657,6 +2709,8 @@ class e_parse extends e_parser
} }
/** /**
* Experimental: Generate a Thumb URL for use in the img srcset attribute. * Experimental: Generate a Thumb URL for use in the img srcset attribute.
* @param string $src eg. {e_MEDIA_IMAGE}myimage.jpg * @param string $src eg. {e_MEDIA_IMAGE}myimage.jpg