From 9f96a5bbd34f2b74e50de01ed3d31ec3e6399f05 Mon Sep 17 00:00:00 2001 From: secretr Date: Wed, 10 Mar 2010 12:48:05 +0000 Subject: [PATCH] IN PROGRESS - Tasks EONE-10, EONE-11: more paths added, 'nice' urls are supported now (see thumb.php) --- e107_handlers/e107_class.php | 18 +++++++---- e107_handlers/e_parse_class.php | 57 +++++++++++++++++++++++++++++++++ thumb.php | 12 +++---- 3 files changed, 74 insertions(+), 13 deletions(-) diff --git a/e107_handlers/e107_class.php b/e107_handlers/e107_class.php index 53fcce76a..657442b76 100644 --- a/e107_handlers/e107_class.php +++ b/e107_handlers/e107_class.php @@ -8,10 +8,8 @@ * * e107 Main * - * $Source: /cvs_backup/e107_0.8/e107_handlers/e107_class.php,v $ - * $Revision$ - * $Date$ - * $Author$ + * $URL$ + * $Id$ */ if (!defined('e107_INIT')) { exit; } @@ -21,8 +19,8 @@ if (!defined('e107_INIT')) { exit; } * * @package e107 * @subpackage e107_handlers - * @version $Revision$ - * @author $Author$ + * @version $Id$ + * @author e107inc * * e107_class - core class with many system-related methods */ @@ -335,6 +333,7 @@ class e107 $ret['WEB_JS_DIRECTORY'] = $ret['MEDIA_DIRECTORY'].'js/'; $ret['WEB_CSS_DIRECTORY'] = $ret['MEDIA_DIRECTORY'].'css/'; $ret['WEB_IMAGES_DIRECTORY'] = $ret['MEDIA_DIRECTORY'].'images/'; + $ret['WEB_PACKS_DIRECTORY'] = $ret['MEDIA_DIRECTORY'].'packages/'; $ret['DOWNLOADS_DIRECTORY'] = $ret['MEDIA_FILES_DIRECTORY']; $ret['UPLOADS_DIRECTORY'] = $ret['MEDIA_UPLOAD_DIRECTORY']; @@ -1881,6 +1880,7 @@ class e107 define('e_WEB_JS', $this->get_override_rel('WEB_JS')); define('e_WEB_CSS', $this->get_override_rel('WEB_CSS')); define('e_WEB_IMAGE', $this->get_override_rel('WEB_IMAGES')); + define('e_WEB_PACK', $this->get_override_rel('WEB_PACKS')); define('e_CACHE', $this->get_override_rel('CACHE')); define('e_CACHE_CONTENT', $this->get_override_rel('CACHE_CONTENT')); @@ -1912,10 +1912,14 @@ class e107 define('e_MEDIA_ICON_ABS', $this->get_override_http('MEDIA_ICONS')); define('e_MEDIA_AVATAR_ABS', $this->get_override_http('MEDIA_AVATARS')); + // XXX DISCUSSS - e_JS_ABS, e_CSS_ABS etc is not following the naming standards but they're more usable. + // Example: e_JS_ABS vs e_WEB_JS_ABS define('e_WEB_ABS', $this->get_override_http('WEB')); - define('e_JS_ABS', $this->get_override_http('WEB_JS')); // XXX - could stay so? + define('e_JS_ABS', $this->get_override_http('WEB_JS')); define('e_CSS_ABS', $this->get_override_http('WEB_CSS')); + define('e_PACK_ABS', $this->get_override_http('WEB_PACKS')); define('e_WEB_IMAGE_ABS', $this->get_override_http('WEB_IMAGES')); + } return $this; } diff --git a/e107_handlers/e_parse_class.php b/e107_handlers/e_parse_class.php index f4cf91316..9c55486cb 100644 --- a/e107_handlers/e_parse_class.php +++ b/e107_handlers/e_parse_class.php @@ -1635,6 +1635,57 @@ class e_parse return $thurl; } + /** + * Help for converting to more safe URLs + * e.g. {e_MEDIA_FILE}path/to/video.flv => e_MEDIA_FILE/path/to/video.flv + * + * @todo support for ALL URL shortcodes (replacement methods) + * @param string $type sc|raw|rev|all + * @return array + */ + public function getUrlConstants($type = 'sc') + { + static $array = array( + 'e_BASE/' => '{e_BASE}', + 'e_ADMIN/' => '{e_ADMIN}', + 'e_IMAGE/' => '{e_IMAGE}', + 'e_THEME/' => '{e_THEME}', + 'e_PLUGIN/' => '{e_PLUGIN}', + 'e_HANDLER/' => '{e_WEB_PACK}', // BC + 'e_MEDIA/' => '{e_MEDIA}', + 'e_MEDIA_FILE/' => '{e_MEDIA_FILE}', + 'e_MEDIA_VIDEO/' => '{e_MEDIA_VIDEO}', + 'e_MEDIA_IMAGE/' => '{e_MEDIA_IMAGE}', + 'e_MEDIA_ICON/' => '{e_MEDIA_ICON}', + 'e_MEDIA_AVATAR/' => '{e_MEDIA_AVATAR}', + 'e_WEB/' => '{e_ADMIN}', + 'e_WEB_JS/' => '{e_WEB_JS}', + 'e_WEB_CSS/' => '{e_WEB_CSS}', + 'e_WEB_IMAGE/' => '{e_WEB_IMAGE}', + 'e_WEB_PACK/' => '{e_WEB_PACK}', + ); + + switch ($type) + { + case 'sc': + return array_values($array); + break; + + case 'raw': + return array_keys($array); + break; + + case 'rev': + return array_reverse($array, true); + break; + + case 'all': + return $array; + break; + } + return array(); + } + /** * Replace e107 path constants * Note: only an ADMIN user can convert {e_ADMIN} @@ -1785,6 +1836,7 @@ class e_parse case 'abs' : $mode = 2; break; case 'full' : $mode = 3; break; case 'mix' : $mode = 4; break; + case 'nice': $mode = 5; break; } } $e107 = e107::getInstance(); @@ -1853,6 +1905,11 @@ class e_parse return $url; break; + case 5: // nice urls - e.g. e_MEDIA_VIDEO/mystream.flv + $url = $this->createConstants($url, 4); + return str_replace($this->getUrlConstants('sc'), $this->getUrlConstants('raw'), $url); + break; + default: $tmp = array(); break; diff --git a/thumb.php b/thumb.php index bdbbf9b6b..9e903b815 100644 --- a/thumb.php +++ b/thumb.php @@ -128,11 +128,11 @@ class e_thumbpage } $tp = e107::getParser(); - // FIXME - better way, maybe additional e_parse method, returning path SC array only - $search = array('e_BASE/', 'e_IMAGE/', 'e_MEDIA/', 'e_PLUGIN/', 'e_THEME/', 'e_WEB/'); - $replace = array('{e_BASE}', '{e_IMAGE}', '{e_MEDIA}', '{e_PLUGIN}', '{e_THEME}', '{e_WEB}'); - $this->_request['src'] = str_replace($search, $replace,$this->_request['src']); + // convert raw to SC path + $this->_request['src'] = str_replace($tp->getUrlConstants('raw'), $tp->getUrlConstants('sc'), $this->_request['src']); + + // convert absolute and full url to SC URL $this->_src = $tp->createConstants($this->_request['src'], 'mix'); if(preg_match('#^(https?|ftps?|file)://#i', $this->_request['src'])) @@ -146,8 +146,8 @@ class e_thumbpage return false; } - // should be safe enough - $path = $tp->replaceConstants(str_replace('..', '', $this->_src)); + // convert to relative server path + $path = $tp->replaceConstants(str_replace('..', '', $this->_src)); //should be safe enough if(is_file($path) && is_readable($path)) {