From 767b496c69817f2a8121d51705a39d2f7892e55c Mon Sep 17 00:00:00 2001 From: Cameron Date: Thu, 4 Feb 2016 12:42:48 -0800 Subject: [PATCH] Issue #1257 Added SEF Thumb Urls for Avatar images. --- e107.htaccess | 1 + e107_handlers/e_parse_class.php | 28 ++++++++++++++++++++++------ thumb.php | 3 +++ 3 files changed, 26 insertions(+), 6 deletions(-) diff --git a/e107.htaccess b/e107.htaccess index d97254b09..56611dc95 100644 --- a/e107.htaccess +++ b/e107.htaccess @@ -61,6 +61,7 @@ ### Rewrite for Image URLs ReWriteRule ^media\/img\/(a)?([\d]*)x(a)?([\d]*)\/(.*)?$ thumb.php?src=e_MEDIA_IMAGE/$5&$1w=$2&$3h=$4 [NC,L] + ReWriteRule ^media\/avatar\/(a)?([\d]*)x(a)?([\d]*)\/(.*)?$ thumb.php?src=e_AVATAR/$5&$1w=$2&$3h=$4 [NC,L] RewriteRule ^media\/img\/([-A-Za-z0-9+/]*={0,3})\.(jpg|gif|png)?$ thumb.php?id=$1 [NC,L] ### send 404 on missing files in these folders diff --git a/e107_handlers/e_parse_class.php b/e107_handlers/e_parse_class.php index 812ad3cc4..2fbf4f4b9 100644 --- a/e107_handlers/e_parse_class.php +++ b/e107_handlers/e_parse_class.php @@ -2268,12 +2268,16 @@ class e_parse extends e_parser } - if(e_MOD_REWRITE_MEDIA == true && (strstr($thurl, 'e_MEDIA_IMAGE') || !empty($options['x'])))// Experimental SEF URL support. + if(e_MOD_REWRITE_MEDIA == true)// Experimental SEF URL support. { $options['full'] = $full; $options['ext'] = substr($url,-3); $options['thurl'] = $thurl; - return $this->thumbUrlSEF($url,$options); + + if($sefUrl = $this->thumbUrlSEF($url,$options)) + { + return $sefUrl; + } } if(vartrue($options['x']))//base64 encode url @@ -2292,19 +2296,31 @@ class e_parse extends e_parser */ private function thumbUrlSEF($url='', $options=array()) { - $clean = array('{e_MEDIA_IMAGE}','e_MEDIA_IMAGE/'); $base = (!empty($options['full'])) ? SITEURL : e_HTTP; - // Build URL for: RewriteRule ^media\/img\/([-A-Za-z0-9+/]*={0,3})\.(jpg|gif|png)?$ thumb.php?id=$1 - if(!empty($options['x']) && !empty($options['ext'])) + if(!empty($options['x']) && !empty($options['ext'])) // base64 encoded. Build URL for: RewriteRule ^media\/img\/([-A-Za-z0-9+/]*={0,3})\.(jpg|gif|png)?$ thumb.php?id=$1 { $ext = strtolower($options['ext']); return $base.'media/img/'.base64_encode($options['thurl']).'.'.str_replace("jpeg", "jpg", $ext); } + elseif(strstr($url, 'e_MEDIA_IMAGE')) // media images. + { + $sefPath = 'media/img/'; + $clean = array('{e_MEDIA_IMAGE}','e_MEDIA_IMAGE/'); + } + elseif(strstr($url, 'e_AVATAR')) // avatars + { + $sefPath = 'media/avatar/'; + $clean = array('{e_AVATAR}','e_AVATAR/'); + } + else + { + return false; + } // Build URL for ReWriteRule ^media\/img\/(a)?([\d]*)x(a)?([\d]*)\/(.*)?$ thumb.php?src=e_MEDIA_IMAGE/$5&$1w=$2&$3h=$4 - $sefUrl = $base.'media/img/'; + $sefUrl = $base.$sefPath; if(vartrue($options['aw']) || vartrue($options['ah'])) { diff --git a/thumb.php b/thumb.php index 2384e904a..bc2b95e05 100644 --- a/thumb.php +++ b/thumb.php @@ -258,6 +258,8 @@ class e_thumbpage $this->sendHeaders($thumbnfo); + //$bench->end()->logResult('thumb.php', $_GET['src'].' - 304 not modified'); + // exit; // check browser cache if (@$_SERVER['HTTP_IF_MODIFIED_SINCE'] && ($thumbnfo['lmodified'] <= strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE'])) && (isset($_SERVER['HTTP_IF_NONE_MATCH']) && trim($_SERVER['HTTP_IF_NONE_MATCH']) == $thumbnfo['md5s'])) { @@ -362,6 +364,7 @@ class e_thumbpage } //header('Pragma:'); header('Cache-Control: must-revalidate'); + // header('Cache-Control: public, max-age=3600'); header('Last-Modified: '.gmdate('D, d M Y H:i:s', $thumbnfo['lmodified']).' GMT'); header('Content-Length: '.$thumbnfo['fsize']); header('Content-Disposition: filename='.$thumbnfo['basename']); // important for right-click save-as.