mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-01-05 17:51:40 +09:00
Allow standalone routes from other modules to be used
This commit is contained in:
parent
2feba015f4
commit
bb3d1f08a1
3 changed files with 73 additions and 9 deletions
|
|
@ -136,6 +136,18 @@ class Router
|
|||
}
|
||||
}
|
||||
|
||||
// Check other modules.
|
||||
$all_routes = self::_getAllCachedRoutes();
|
||||
foreach ($all_routes->{$method} as $regexp => $action)
|
||||
{
|
||||
if (preg_match($regexp, $internal_url, $matches))
|
||||
{
|
||||
$matches = array_filter($matches, 'is_string', \ARRAY_FILTER_USE_KEY);
|
||||
$allargs = array_merge(['mid' => $prefix, 'act' => $action[1]], $matches, $args);
|
||||
return $allargs;
|
||||
}
|
||||
}
|
||||
|
||||
// Try the generic mid/act pattern.
|
||||
if (preg_match('#^[a-zA-Z0-9_]+$#', $internal_url))
|
||||
{
|
||||
|
|
@ -223,6 +235,18 @@ class Router
|
|||
}
|
||||
}
|
||||
|
||||
// Check other modules for $act.
|
||||
$all_routes = self::_getAllCachedRoutes();
|
||||
if (isset($all_routes->reverse[$act]))
|
||||
{
|
||||
$result = self::_getBestMatchingRoute($all_routes->reverse[$act], $args2);
|
||||
if ($result !== false)
|
||||
{
|
||||
self::$_route_cache[$keys_string] = '$mid/' . $result . '$act:delete';
|
||||
return $args['mid'] . '/' . self::_insertRouteVars($result, $args2);
|
||||
}
|
||||
}
|
||||
|
||||
// Check XE-compatible routes that start with $mid and contain no $act.
|
||||
if (!isset($args['act']) || ($args['act'] === 'rss' || $args['act'] === 'atom' || $args['act'] === 'api'))
|
||||
{
|
||||
|
|
@ -300,6 +324,23 @@ class Router
|
|||
return self::$_action_cache_module[$module] = $action_info ?: false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the list of all cached routes from all modules.
|
||||
*
|
||||
* @return object
|
||||
*/
|
||||
protected static function _getAllCachedRoutes()
|
||||
{
|
||||
$cache_key = 'site_and_module:action_with_routes';
|
||||
$result = Cache::get($cache_key);
|
||||
if ($result === null)
|
||||
{
|
||||
$result = (object)array('GET' => [], 'POST' => [], 'reverse' => []);
|
||||
Cache::set($cache_key, $result, 0, true);
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find the best matching route for an array of variables.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -2,20 +2,20 @@
|
|||
<module>
|
||||
<grants />
|
||||
<actions>
|
||||
<action name="dispMemberSignUpForm" type="view" meta-noindex="true" />
|
||||
<action name="dispMemberLoginForm" type="view" meta-noindex="true" />
|
||||
<action name="dispMemberSignUpForm" type="view" meta-noindex="true" route="signup" />
|
||||
<action name="dispMemberLoginForm" type="view" meta-noindex="true" route="login" />
|
||||
<action name="dispMemberFindAccount" type="view" meta-noindex="true" />
|
||||
<action name="dispMemberResendAuthMail" type="view" meta-noindex="true" />
|
||||
<action name="dispMemberInfo" type="view" permission="member" meta-noindex="true" />
|
||||
<action name="dispMemberInfo" type="view" permission="member" meta-noindex="true" route="member_info" />
|
||||
<action name="dispMemberModifyInfo" type="view" permission="member" meta-noindex="true" />
|
||||
<action name="dispMemberModifyPassword" type="view" permission="member" meta-noindex="true" />
|
||||
<action name="dispMemberModifyEmailAddress" type="view" permission="member" meta-noindex="true" />
|
||||
<action name="dispMemberLeave" type="view" permission="member" meta-noindex="true" />
|
||||
<action name="dispMemberScrappedDocument" type="view" permission="member" meta-noindex="true" />
|
||||
<action name="dispMemberSavedDocument" type="view" permission="member" meta-noindex="true" />
|
||||
<action name="dispMemberOwnDocument" type="view" permission="member" meta-noindex="true" />
|
||||
<action name="dispMemberOwnComment" type="view" permission="member" meta-noindex="true" />
|
||||
<action name="dispMemberActiveLogins" type="view" permission="member" meta-noindex="true" />
|
||||
<action name="dispMemberScrappedDocument" type="view" permission="member" meta-noindex="true" route="my_scrap" />
|
||||
<action name="dispMemberSavedDocument" type="view" permission="member" meta-noindex="true" route="my_saved_documents" />
|
||||
<action name="dispMemberOwnDocument" type="view" permission="member" meta-noindex="true" route="my_documents" />
|
||||
<action name="dispMemberOwnComment" type="view" permission="member" meta-noindex="true" route="my_comments" />
|
||||
<action name="dispMemberActiveLogins" type="view" permission="member" meta-noindex="true" route="active_logins" />
|
||||
<action name="dispMemberModifyNicknameLog" type="view" permission="member" meta-noindex="true" />
|
||||
<action name="dispMemberLogout" type="view" permission="member" meta-noindex="true" />
|
||||
<action name="dispMemberSpammer" type="view" permission="manager" check_var="module_srl" meta-noindex="true" />
|
||||
|
|
|
|||
|
|
@ -723,13 +723,36 @@ class moduleModel extends module
|
|||
$info = Rhymix\Framework\Cache::get($cache_key);
|
||||
if($info === null)
|
||||
{
|
||||
// Load the XML file.
|
||||
$info = Rhymix\Framework\Parsers\ModuleActionParser::loadXML($xml_file);
|
||||
|
||||
// Add all routes from the module to a global list.
|
||||
$action_cache_key = 'site_and_module:action_with_routes';
|
||||
$action_with_routes = Rhymix\Framework\Cache::get($action_cache_key) ?: (object)array('GET' => [], 'POST' => [], 'reverse' => []);
|
||||
foreach ($info->route->GET as $regexp => $action)
|
||||
{
|
||||
$action_with_routes->GET[$regexp] = [$module, $action];
|
||||
}
|
||||
foreach ($info->route->POST as $regexp => $action)
|
||||
{
|
||||
$action_with_routes->POST[$regexp] = [$module, $action];
|
||||
}
|
||||
foreach ($info->action as $action_name => $action_info)
|
||||
{
|
||||
if (count($action_info->route) && $action_info->standalone !== 'false')
|
||||
{
|
||||
$action_with_routes->reverse[$action_name] = $action_info->route;
|
||||
}
|
||||
}
|
||||
|
||||
// Set cache entries.
|
||||
Rhymix\Framework\Cache::set($action_cache_key, $action_with_routes, 0, true);
|
||||
Rhymix\Framework\Cache::set($cache_key, $info, 0, true);
|
||||
}
|
||||
|
||||
return $info;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get a skin list for js API.
|
||||
* return void
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue