From b3bb493f698584fa8c2baa422daa0c1e0da8ed41 Mon Sep 17 00:00:00 2001 From: Cameron Date: Wed, 3 Feb 2016 18:17:14 -0800 Subject: [PATCH] Fixes #1257 SEFURLs for thumb images. Needs testing. See e107.htaccess for required additions/modifications - Set HTTP_MOD_REWRITE_MEDIA to "On" --- e107.htaccess | 7 +++++ e107_handlers/e107_class.php | 6 ++++ e107_handlers/e_parse_class.php | 52 ++++++++++++++++++++++++++++++--- 3 files changed, 61 insertions(+), 4 deletions(-) diff --git a/e107.htaccess b/e107.htaccess index 47f632dc3..d97254b09 100644 --- a/e107.htaccess +++ b/e107.htaccess @@ -41,6 +41,7 @@ SetEnv HTTP_MOD_REWRITE On + SetEnv HTTP_MOD_REWRITE_MEDIA Off ### enable rewrites @@ -54,8 +55,14 @@ ### Allow only GET and POST methods RewriteCond %{REQUEST_METHOD} ^(TRACE|TRACK|OPTIONS|HEAD) + + RewriteRule .* - [F] +### 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\/img\/([-A-Za-z0-9+/]*={0,3})\.(jpg|gif|png)?$ thumb.php?id=$1 [NC,L] + ### send 404 on missing files in these folders RewriteCond %{REQUEST_URI} !^/(e107_images|e107_files)/ diff --git a/e107_handlers/e107_class.php b/e107_handlers/e107_class.php index bfd0a2655..bd1f49b68 100644 --- a/e107_handlers/e107_class.php +++ b/e107_handlers/e107_class.php @@ -3218,6 +3218,12 @@ class e107 { define('e_MOD_REWRITE', (getenv('HTTP_MOD_REWRITE')=='On' ? true : false)); } + + if(!defined('e_MOD_REWRITE_MEDIA')) // Allow e107_config.php to override. + { + define('e_MOD_REWRITE_MEDIA', (getenv('HTTP_MOD_REWRITE_MEDIA')=='On' ? true : false)); + } + // Define the domain name and subdomain name. if(is_numeric(str_replace(".","",$_SERVER['HTTP_HOST']))) { diff --git a/e107_handlers/e_parse_class.php b/e107_handlers/e_parse_class.php index 0aaf94358..812ad3cc4 100644 --- a/e107_handlers/e_parse_class.php +++ b/e107_handlers/e_parse_class.php @@ -2266,18 +2266,62 @@ class e_parse extends e_parser } $thurl .= 'w='.((integer) vartrue($options['w'], 0)).'&h='.((integer) vartrue($options['h'], 0)); } - - + + + if(e_MOD_REWRITE_MEDIA == true && (strstr($thurl, 'e_MEDIA_IMAGE') || !empty($options['x'])))// Experimental SEF URL support. + { + $options['full'] = $full; + $options['ext'] = substr($url,-3); + $options['thurl'] = $thurl; + return $this->thumbUrlSEF($url,$options); + } + if(vartrue($options['x']))//base64 encode url { $thurl = 'id='.base64_encode($thurl); } - // echo "

".$thurl; - return $baseurl.$thurl; } + /** + * Used by thumbUrl when SEF Image URLS is active. @see e107.htaccess + * @param $url + * @param array $options + * @return string + */ + 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'])) + { + $ext = strtolower($options['ext']); + return $base.'media/img/'.base64_encode($options['thurl']).'.'.str_replace("jpeg", "jpg", $ext); + } + + // 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/'; + + if(vartrue($options['aw']) || vartrue($options['ah'])) + { + $sefUrl .= 'a'.intval($options['aw']) .'xa'. intval($options['ah']); + } + else + { + $sefUrl .= intval($options['w']) .'x'. intval($options['h']); + } + + $sefUrl .= '/'; + $sefUrl .= str_replace($clean,'',$url); + + return $sefUrl; + + } + /** * Help for converting to more safe URLs * e.g. {e_MEDIA_FILE}path/to/video.flv => e_MEDIA_FILE/path/to/video.flv