From 0935f7b858e1a628ca8c5e446d99db8fdf164fb9 Mon Sep 17 00:00:00 2001 From: Cameron Date: Mon, 27 Mar 2017 10:38:51 -0700 Subject: [PATCH] Support for root namespaces using e_url addon configuration. --- e107_admin/eurl.php | 18 ++++++-- e107_handlers/e107_class.php | 85 ++++++++++++++++++++++++++++++++++-- index.php | 23 +++++++++- 3 files changed, 117 insertions(+), 9 deletions(-) diff --git a/e107_admin/eurl.php b/e107_admin/eurl.php index b74f04fe6..565927dad 100644 --- a/e107_admin/eurl.php +++ b/e107_admin/eurl.php @@ -207,7 +207,7 @@ class eurl_admin_ui extends e_admin_controller_ui protected function simplePage() { // $this->addTitle("Simple Redirects"); - $eUrl =e107::getAddonConfig('e_url'); + $eUrl =e107::getUrlConfig(); $frm = e107::getForm(); $tp = e107::getParser(); $cfg = e107::getConfig(); @@ -315,8 +315,17 @@ class eurl_admin_ui extends e_admin_controller_ui { // main module pref dropdown $this->prefs['url_main_module']['writeParms'][''] = 'None'; + + // e_url.php aliases + $tmp = e107::getUrlConfig('alias'); + foreach($tmp as $plugin=>$alias) + { + $this->prefs['url_main_module']['writeParms'][$alias] = eHelper::labelize($plugin); + } + + // legacy URL (news, pages ) $modules = e107::getPref('url_config', array()); - ksort($modules); + foreach ($modules as $module => $location) { $labels = array(); @@ -326,10 +335,11 @@ class eurl_admin_ui extends e_admin_controller_ui if(!$config || !vartrue($config['config']['allowMain'])) continue; $admin = $obj->admin(); $labels = vartrue($admin['labels'], array()); - - + $this->prefs['url_main_module']['writeParms'][$module] = vartrue($section['name'], eHelper::labelize($module)); } + + ksort($this->prefs['url_main_module']['writeParms']); // title2sef transform type pref $types = explode('|', 'none|dashl|dashc|dash|underscorel|underscorec|underscore|plusl|plusc|plus'); diff --git a/e107_handlers/e107_class.php b/e107_handlers/e107_class.php index 30a85f4dd..6013776bc 100644 --- a/e107_handlers/e107_class.php +++ b/e107_handlers/e107_class.php @@ -2416,6 +2416,73 @@ class e107 return FALSE; } + /** + * Retrieves the e_url config - new v2.1.6 + * @return array + */ + public static function getUrlConfig($mode='config') + { + $new_addon = array(); + + $filename = 'e_url'; + $elist = self::getPref($filename.'_list'); + $className = substr($filename, 2); // remove 'e_' + $methodName = 'config'; + + $profile = null; // for future use. + + if(!empty($elist)) + { + foreach(array_keys($elist) as $key) + { + if(is_readable(e_PLUGIN.$key.'/'.$filename.'.php')) + { + include_once(e_PLUGIN.$key.'/'.$filename.'.php'); + + $class_name = $key.'_'.$className; + + if(is_object($class_name)) + { + $obj = $class_name; + $class_name = get_class($obj); + } + else + { + $obj = new $class_name; + } + + if($mode === 'alias') + { + if(!empty($obj->alias)) + { + $new_addon[$key] = $obj->alias; + } + + continue; + } + + $array = self::callMethod($obj, $methodName,$profile); + + if($array) + { + foreach($array as $k=>$v) + { + if(empty($v['alias']) && !empty($obj->alias)) + { + $v['alias'] = $obj->alias; + } + $new_addon[$key][$k] = $v; + + } + + } + + } + } + } + + return $new_addon; + } /** * Get theme name or path. @@ -3157,7 +3224,7 @@ class e107 if(!$tmp = self::getRegistry('core/e107/addons/e_url')) { - $tmp = self::getAddonConfig('e_url'); + $tmp = self::getUrlConfig(); self::setRegistry('core/e107/addons/e_url',$tmp); } @@ -3165,6 +3232,8 @@ class e107 $pref = self::getPref('e_url_alias'); $sefActive = self::getPref('e_url_list'); + $rootNamespace = self::getPref('url_main_module'); + if(is_string($options)) // backwards compat. { @@ -3185,12 +3254,22 @@ class e107 $options['fragment'] = '#' . $options['fragment']; } - if(varset($tmp[$plugin][$key]['sef'])) + if(!empty($tmp[$plugin][$key]['sef'])) { if(!empty($tmp[$plugin][$key]['alias'])) { $alias = (!empty($pref[e_LAN][$plugin][$key])) ? $pref[e_LAN][$plugin][$key] : $tmp[$plugin][$key]['alias']; - $tmp[$plugin][$key]['sef'] = str_replace('{alias}', $alias, $tmp[$plugin][$key]['sef']); + + if(!empty($rootNamespace) && $rootNamespace === $plugin) + { + $replaceAlias = array('{alias}\/','{alias}/'); + $tmp[$plugin][$key]['sef'] = str_replace($replaceAlias, '', $tmp[$plugin][$key]['sef']); + } + else + { + $tmp[$plugin][$key]['sef'] = str_replace('{alias}', $alias, $tmp[$plugin][$key]['sef']); + } + } diff --git a/index.php b/index.php index b9bae8c0f..77481ecdf 100644 --- a/index.php +++ b/index.php @@ -95,7 +95,8 @@ } else*/ { - $tmp = e107::getAddonConfig('e_url'); + // $tmp = e107::getAddonConfig('e_url'); + $tmp = e107::getUrlConfig(); // e107::getCache()->set('Addon_url',e107::serialize($tmp,'json'),true,true,true); } @@ -104,6 +105,8 @@ if(count($tmp)) { + $rootNamespace = e107::getPref('url_main_module'); + $replaceAlias = array('{alias}\/?','{alias}/?','{alias}\/','{alias}/',); foreach($tmp as $plug=>$cfg) { @@ -127,7 +130,15 @@ { $alias = (!empty($pref['e_url_alias'][e_LAN][$plug][$k])) ? $pref['e_url_alias'][e_LAN][$plug][$k] : $v['alias']; // e107::getMessage()->addDebug("e_url alias found: ".$alias.""); - $v['regex'] = str_replace('{alias}', $alias, $v['regex']); + if(!empty($rootNamespace) && $rootNamespace === $plug) + { + $v['regex'] = str_replace($replaceAlias, '', $v['regex']); + } + else + { + + $v['regex'] = str_replace('{alias}', $alias, $v['regex']); + } } @@ -163,7 +174,15 @@ } elseif(getperms('0')) { + require_once(HEADERF); + echo "
"; + echo "

SEF Debug Info

"; echo "File missing: ".$file; + echo "
Matched key: ".$k.""; + + print_a($v); + echo "
"; + require_once(FOOTERF); exit; }