mirror of
https://github.com/e107inc/e107.git
synced 2025-06-03 17:34:59 +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:
parent
2dfd20c54b
commit
905fb0208b
@ -10,11 +10,261 @@
|
||||
|
||||
|
||||
/**
|
||||
* e107 Single Entry Point handling
|
||||
*
|
||||
* Currently this file contains all classes required for single entry point functionallity
|
||||
* They will be separated in different files in a proper way (soon)
|
||||
* Class e_url
|
||||
* New v2.1.6
|
||||
*/
|
||||
class e_url
|
||||
{
|
||||
|
||||
private static $_instance;
|
||||
|
||||
private $_request = null;
|
||||
|
||||
private $_config = array();
|
||||
|
||||
private $_include = null;
|
||||
|
||||
private $_rootnamespace = null;
|
||||
|
||||
private $_legacy = array();
|
||||
|
||||
private $_legacyAliases = array();
|
||||
|
||||
|
||||
/**
|
||||
* e_url constructor.
|
||||
*/
|
||||
function __construct()
|
||||
{
|
||||
$this->_request = (e_HTTP === '/') ? ltrim(e_REQUEST_URI,'/') : str_replace(e_HTTP,'', e_REQUEST_URI) ;
|
||||
$this->_config = e107::getUrlConfig();
|
||||
$this->_rootnamespace = e107::getPref('url_main_module');
|
||||
$this->_legacy = e107::getPref('url_config');
|
||||
$this->_legacyAliases = e107::getPref('url_aliases');
|
||||
|
||||
$this->setRootNamespace();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Detect older e_url system.
|
||||
* @return bool
|
||||
*/
|
||||
private function isLegacy()
|
||||
{
|
||||
|
||||
$arr = (!empty($this->_legacyAliases[e_LAN])) ? array_merge($this->_legacy,$this->_legacyAliases[e_LAN]) : $this->_legacy;
|
||||
|
||||
$list = array_keys($arr);
|
||||
|
||||
foreach($list as $leg)
|
||||
{
|
||||
if(strpos($this->_request,$leg.'/') === 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getInclude()
|
||||
{
|
||||
return $this->_include;
|
||||
}
|
||||
|
||||
|
||||
|
||||
private function setRootNamespace()
|
||||
{
|
||||
|
||||
$plugs = array_keys($this->_config);
|
||||
|
||||
if(!empty($this->_rootnamespace) && in_array($this->_rootnamespace,$plugs)) // Move rootnamespace check to the end of the list.
|
||||
{
|
||||
$v = $this->_config[$this->_rootnamespace];
|
||||
unset($this->_config[$this->_rootnamespace]);
|
||||
$this->_config[$this->_rootnamespace] = $v;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function run()
|
||||
{
|
||||
$pref = e107::getPref();
|
||||
$tp = e107::getParser();
|
||||
|
||||
if(empty($this->_config) || empty($this->_request) || $this->_request === 'index.php' || $this->isLegacy() === true)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/*if($cached = e107::getCache()->retrieve('Addon_url',5,true,true))
|
||||
{
|
||||
$tmp = e107::unserialize($cached);
|
||||
}
|
||||
else*/
|
||||
{
|
||||
// $tmp = e107::getAddonConfig('e_url');
|
||||
|
||||
// e107::getCache()->set('Addon_url',e107::serialize($tmp,'json'),true,true,true);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// if(count($this->_config) && !empty($this->_request) && $this->_request !== 'index.php')
|
||||
{
|
||||
|
||||
|
||||
|
||||
/*
|
||||
|
||||
$legacyConfig = array_keys(e107::getPref('url_config'));
|
||||
foreach($legacyConfig as $leg)
|
||||
{
|
||||
if(strpos($this->req,$leg.'/') === 0)
|
||||
{
|
||||
var_dump("Found ".$leg);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
*/
|
||||
|
||||
$replaceAlias = array('{alias}\/?','{alias}/?','{alias}\/','{alias}/',);
|
||||
|
||||
foreach($this->_config 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($this->_rootnamespace) && $this->_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'], $this->_request);
|
||||
|
||||
if($newLocation != $this->_request)
|
||||
{
|
||||
$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);
|
||||
|
||||
$this->_include= $file;
|
||||
return true;
|
||||
// exit;
|
||||
}
|
||||
elseif(getperms('0'))
|
||||
{
|
||||
|
||||
|
||||
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>";
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
unset($tmp,$redirect,$regex);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Singleton implementation
|
||||
* @return e_url
|
||||
*/
|
||||
public static function instance()
|
||||
{
|
||||
if(null == self::$_instance)
|
||||
{
|
||||
self::$_instance = new self();
|
||||
}
|
||||
return self::$_instance;
|
||||
}
|
||||
|
||||
|
||||
public function getConfig()
|
||||
{
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
|
@ -212,6 +212,7 @@ class e107
|
||||
'e_userperms' => '{e_HANDLER}user_handler.php',
|
||||
'e_validator' => '{e_HANDLER}validator_class.php',
|
||||
'e_vars' => '{e_HANDLER}model_class.php',
|
||||
'e_url' => '{e_HANDLER}application.php',
|
||||
'ecache' => '{e_HANDLER}cache_handler.php',
|
||||
'eController' => '{e_HANDLER}application.php',
|
||||
'eDispatcher' => '{e_HANDLER}application.php',
|
||||
|
@ -2610,6 +2610,8 @@ class e_parse extends e_parser
|
||||
*/
|
||||
function thumbSrcSet($src='', $width=null)
|
||||
{
|
||||
$multiply = null;
|
||||
|
||||
if(is_array($width))
|
||||
{
|
||||
$parm = $width;
|
||||
@ -2648,8 +2650,8 @@ class e_parse extends e_parser
|
||||
return $this->thumbUrl($src, $parm)." ".$parm['h']."h ".$multiply;
|
||||
}
|
||||
|
||||
$width = (!empty($parm['w']) || !empty($parm['h'])) ? (intval($parm['w']) * $multiply) : ($this->thumbWidth * $multiply);
|
||||
$height = (!empty($parm['h']) || !empty($parm['w'])) ? (intval($parm['h']) * $multiply) : ($this->thumbHeight * $multiply);
|
||||
$width = (!empty($parm['w']) || !empty($parm['h'])) ? (intval($parm['w']) * $multiply) : (intval($this->thumbWidth) * $multiply);
|
||||
$height = (!empty($parm['h']) || !empty($parm['w'])) ? (intval($parm['h']) * $multiply) : (intval($this->thumbHeight) * $multiply);
|
||||
|
||||
}
|
||||
else
|
||||
|
158
index.php
158
index.php
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user