1
0
mirror of https://github.com/e107inc/e107.git synced 2025-03-14 01:19:44 +01:00

Fixes #1257 SEFURLs for thumb images. Needs testing. See e107.htaccess for required additions/modifications - Set HTTP_MOD_REWRITE_MEDIA to "On"

This commit is contained in:
Cameron 2016-02-03 18:17:14 -08:00
parent 84550d7390
commit b3bb493f69
3 changed files with 61 additions and 4 deletions

View File

@ -41,6 +41,7 @@
<IfModule mod_env.c>
SetEnv HTTP_MOD_REWRITE On
SetEnv HTTP_MOD_REWRITE_MEDIA Off
</IfModule>
### 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)/

View File

@ -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'])))
{

View File

@ -2266,18 +2266,62 @@ class e_parse extends e_parser
}
$thurl .= 'w='.((integer) vartrue($options['w'], 0)).'&amp;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 "<br /><br />".$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