1
0
mirror of https://github.com/e107inc/e107.git synced 2025-07-30 19:30:25 +02:00

e_url detection moved to application.php . Resolved conflicts between older URL scheme and new one when rootnamespace is in use.

This commit is contained in:
Cameron
2017-04-19 13:20:59 -07:00
parent 2dfd20c54b
commit 905fb0208b
4 changed files with 269 additions and 154 deletions

158
index.php
View File

@@ -56,161 +56,21 @@
require_once("class2.php");
// ----------------------------
/**
* Simple URL ReWrite (experimental) //TODO test, discuss, benchmark, enhance and include in eFront etc. if all goes well.
* Why?:
* - To make simple url rewrites as quick and easy for plugin developers to implement as it currently is to do the same with .htaccess
* - To use the same familiar standard as used by e_cron, e_status, e_rss etc. etc. so even a novice developer can understand it.
*
* @example (.httaccess):
* RewriteRule ^ref-(.*)/?$ e107_plugins/myplugin/myplugin.php?ref=$1 [NC,L]
*
* @example (e_url.php file - in the 'myplugin' folder)
*
* class myplugin_url // plugin-folder + '_url'
{
function config()
{
$config = array();
$config[] = array(
'regex' => '^ref-(.*)/?$',
'redirect' => '{e_PLUGIN}myplugin/myplugin.php?ref=$1',
);
return $config;
}
}
*/
$sql->db_Mark_Time("Start Simple URL-ReWrite Routine");
// XXX Cache didn't bring much benefit.
$eUrl = e_url::instance();
$eUrl->run();
/*if($cached = e107::getCache()->retrieve('Addon_url',5,true,true))
if($file = $eUrl->getInclude())
{
$tmp = e107::unserialize($cached);
}
else*/
{
// $tmp = e107::getAddonConfig('e_url');
$tmp = e107::getUrlConfig();
// e107::getCache()->set('Addon_url',e107::serialize($tmp,'json'),true,true,true);
include_once(HEADERF);
include_once($file);
include_once(FOOTERF);
exit;
}
$req = (e_HTTP === '/') ? ltrim(e_REQUEST_URI,'/') : str_replace(e_HTTP,'', e_REQUEST_URI) ;
if(count($tmp) && !empty($req) && $req !== 'index.php')
{
$rootNamespace = e107::getPref('url_main_module');
$replaceAlias = array('{alias}\/?','{alias}/?','{alias}\/','{alias}/',);
$plugs = array_keys($tmp);
if(in_array($rootNamespace,$plugs)) // Move rootnamespace check to the end of the list.
{
$v = $tmp[$rootNamespace];
unset($tmp[$rootNamespace]);
$tmp[$rootNamespace] = $v;
}
foreach($tmp as $plug=>$cfg)
{
if(empty($pref['e_url_list'][$plug])) // disabled.
{
e107::getDebug()->log('e_URL for <b>'.$plug.'</b> is disabled.');
continue;
}
foreach($cfg as $k=>$v)
{
if(empty($v['regex']))
{
// e107::getMessage()->addDebug("Skipping empty regex: <b>".$k."</b>");
continue;
}
if(!empty($v['alias']))
{
$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: <b>".$alias."</b>");
if(!empty($rootNamespace) && $rootNamespace === $plug)
{
$v['regex'] = str_replace($replaceAlias, '', $v['regex']);
}
else
{
$v['regex'] = str_replace('{alias}', $alias, $v['regex']);
}
}
$regex = '#'.$v['regex'].'#';
if(empty($v['redirect']))
{
continue;
}
$newLocation = preg_replace($regex, $v['redirect'], $req);
if($newLocation != $req)
{
$redirect = e107::getParser()->replaceConstants($newLocation);
list($file,$query) = explode("?",$redirect,2);
$get = array();
if(!empty($query))
{
parse_str($query,$get);
}
foreach($get as $gk=>$gv)
{
$_GET[$gk] = $gv;
}
e107::getDebug()->log('e_URL in <b>'.$plug.'</b> with key: <b>'.$k.'</b> matched <b>'.$v['regex'].'</b> and included: <b>'.$file.'</b> with $_GET: '.print_a($_GET,true),1);
if(file_exists($file))
{
define('e_CURRENT_PLUGIN', $plug);
define('e_QUERY', $query); // do not add to e107_class.php
define('e_URL_LEGACY', $redirect);
include_once($file);
exit;
}
elseif(getperms('0'))
{
require_once(HEADERF);
echo "<div class='alert alert-warning'>";
echo "<h3>SEF Debug Info</h3>";
echo "File missing: ".$file;
echo "<br />Matched key: <b>".$k."</b>";
print_a($v);
echo "</div>";
require_once(FOOTERF);
exit;
}
}
}
}
unset($tmp,$redirect,$regex);
}
// -----------------------------------------
@@ -226,7 +86,9 @@
// If not already done - define legacy constants
$request->setLegacyQstring();
$request->setLegacyPage();
$request->setLegacyPage();
$inc = $front->isLegacy();
if($inc)