mirror of
https://github.com/e107inc/e107.git
synced 2025-01-17 04:38:27 +01:00
Issue #3912 - Reverse lookup e_ROUTE from e_url.php 'legacy' entry.
This commit is contained in:
parent
55de6b1533
commit
e425349661
13
class2.php
13
class2.php
@ -1748,6 +1748,19 @@ if($fpUrl === $fpPref)
|
||||
}
|
||||
unset($fpUrl, $fpPref);
|
||||
|
||||
$dbg->logTime('Legacy Route detection');
|
||||
// Reverse lookup of current URI against legacy e_url entry to determine route.
|
||||
if(!deftrue('e_SINGLE_ENTRY') && deftrue('e_CURRENT_PLUGIN'))
|
||||
{
|
||||
if($route = e107::detectRoute(e_CURRENT_PLUGIN, e_REQUEST_URI))
|
||||
{
|
||||
e107::route($route);
|
||||
}
|
||||
|
||||
unset($route);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -4032,6 +4032,65 @@ class e107
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse lookup of current URI against legacy e_url entry for the specified plugin.
|
||||
* Useful for when SEF (e_SINGLE_ENTRY) is not in use.
|
||||
* @param string $route eg. forum/index (must match SEF route )
|
||||
*/
|
||||
public static function detectRoute($plugin=null, $uri=null)
|
||||
{
|
||||
if(empty($plugin) || empty($uri))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
if(!$addon = e107::getAddon($plugin,'e_url'))
|
||||
{
|
||||
trigger_error("Couldn't load e_url for ".$plugin);
|
||||
return null;
|
||||
}
|
||||
|
||||
if(!$result = e107::callMethod($addon, 'config'))
|
||||
{
|
||||
trigger_error($plugin.' - e_url::config() method returned nothing');
|
||||
return null;
|
||||
}
|
||||
|
||||
foreach($result as $key=>$var)
|
||||
{
|
||||
if(empty($var['legacy']))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
$legacy = self::getParser()->replaceConstants($var['legacy'], 'abs'); // remove {e_PLUGIN}
|
||||
$legacy = preg_replace('/\{[\w]*\}/', '__XXX__', $legacy); // replace {fields} with placeholder.
|
||||
$legacy = preg_quote($legacy,'/'); // add slashes
|
||||
|
||||
$pattern = '/'. str_replace('__XXX__', '([\w]*)', $legacy) .'/'; // replace placeholder with regexp
|
||||
|
||||
if(preg_match($pattern, $uri))
|
||||
{
|
||||
return $plugin.'/'.$key;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public static function route($route)
|
||||
{
|
||||
if(defined('e_ROUTE'))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
define('e_ROUTE', $route);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Generate a plugin's search engine-friendly URL with HTML special characters escaped
|
||||
*
|
||||
|
@ -29,18 +29,21 @@ class forum_url // plugin-folder + '_url'
|
||||
'regex' => '^forum/rules/?',
|
||||
'sef' => 'forum/rules',
|
||||
'redirect' => '{e_PLUGIN}forum/forum.php?f=rules',
|
||||
'legacy' => '{e_PLUGIN}forum/forum.php?f=rules',
|
||||
);
|
||||
|
||||
$config['stats'] = array(
|
||||
'regex' => '^forum/stats/?',
|
||||
'sef' => 'forum/stats',
|
||||
'redirect' => '{e_PLUGIN}forum/forum_stats.php',
|
||||
'legacy' => '{e_PLUGIN}forum/forum_stats.php',
|
||||
);
|
||||
|
||||
$config['track'] = array(
|
||||
'regex' => '^forum/track/?',
|
||||
'sef' => 'forum/track',
|
||||
'redirect' => '{e_PLUGIN}forum/forum.php?f=track',
|
||||
'legacy' => '{e_PLUGIN}forum/forum.php?f=track',
|
||||
);
|
||||
|
||||
$config['markread'] = array(
|
||||
@ -53,13 +56,15 @@ class forum_url // plugin-folder + '_url'
|
||||
$config['new'] = array(
|
||||
'regex' => '^forum/new$/?',
|
||||
'sef' => 'forum/new',
|
||||
'redirect' => '{e_PLUGIN}forum/forum.php?new'
|
||||
'redirect' => '{e_PLUGIN}forum/forum.php?new',
|
||||
'legacy' => '{e_PLUGIN}forum/forum.php?new'
|
||||
);
|
||||
|
||||
$config['post'] = array(
|
||||
'regex' => '^forum/post/?',
|
||||
'sef' => 'forum/post/',
|
||||
'redirect' => '{e_PLUGIN}forum/forum_post.php',
|
||||
'legacy' => '{e_PLUGIN}forum/forum_post.php',
|
||||
);
|
||||
|
||||
// only create url - parsed above.
|
||||
@ -94,7 +99,7 @@ class forum_url // plugin-folder + '_url'
|
||||
'regex' => '^forum\/?$', // matched against url, and if true, redirected to 'redirect' below.
|
||||
'sef' => 'forum', // used by e107::url(); to create a url from the db table.
|
||||
'redirect' => '{e_PLUGIN}forum/forum.php', // file-path of what to load when the regex returns true.
|
||||
|
||||
'legacy' => '{e_PLUGIN}forum/forum.php',
|
||||
);
|
||||
|
||||
|
||||
@ -106,8 +111,6 @@ class forum_url // plugin-folder + '_url'
|
||||
);
|
||||
|
||||
|
||||
|
||||
|
||||
return $config;
|
||||
}
|
||||
|
||||
|
@ -97,7 +97,6 @@ class forum_front
|
||||
|
||||
case 'rules':
|
||||
include_once(HEADERF);
|
||||
|
||||
$this->forum_rules('show');
|
||||
include_once(FOOTERF);
|
||||
exit;
|
||||
|
@ -1314,13 +1314,51 @@ class e107Test extends \Codeception\Test\Unit
|
||||
|
||||
}
|
||||
|
||||
function testDetectRoute()
|
||||
{
|
||||
e107::getPlugin()->install('forum');
|
||||
|
||||
$tests = array(
|
||||
0 => array(
|
||||
'plugin' => 'forum',
|
||||
'uri' => '/e107_plugins/forum/forum.php?f=rules',
|
||||
'expected' => 'forum/rules',
|
||||
),
|
||||
1 => array(
|
||||
'plugin' => 'forum',
|
||||
'uri' => '/e107_plugins/forum/forum_viewforum.php?id=543123',
|
||||
'expected' => 'forum/forum',
|
||||
),
|
||||
|
||||
);
|
||||
|
||||
foreach($tests as $index => $var)
|
||||
{
|
||||
$result = e107::detectRoute($var['plugin'], $var['uri']);
|
||||
if(empty($var['expected']))
|
||||
{
|
||||
echo $result."\n";
|
||||
continue;
|
||||
}
|
||||
|
||||
$this->assertSame($var['expected'], $result);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
e107::getPlugin()->uninstall('forum');
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
public function testThemeLan()
|
||||
{
|
||||
$result = e107::themeLan(null, 'basic-light');
|
||||
var_dump($result);
|
||||
|
||||
}
|
||||
}*/
|
||||
/*
|
||||
public function testLan()
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user