From: Zach Copley Date: Wed, 13 Apr 2011 04:08:02 +0000 (-0700) Subject: DirectoryPlugin - Hijack router mapping for normal groups page to substitute a direct... X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=0f9d6f4c82892875f57774f8bcfd1871f8e58cca;p=quix0rs-gnu-social.git DirectoryPlugin - Hijack router mapping for normal groups page to substitute a directory page --- diff --git a/EVENTS.txt b/EVENTS.txt index aca9e8f73d..d1e36ad906 100644 --- a/EVENTS.txt +++ b/EVENTS.txt @@ -1089,13 +1089,13 @@ EndGroupSave: After saving a group, aliases, and first member - $group: group that was saved StartInterpretCommand: Before running a command -- $cmd: First word in the string, 'foo' in 'foo argument' +- $cmd: First word in the string, 'foo' in 'foo argument' - $arg: Argument, if any, like 'argument' in 'foo argument' - $user: User who issued the command - &$result: Resulting command; you can set this! EndInterpretCommand: Before running a command -- $cmd: First word in the string, 'foo' in 'foo argument' +- $cmd: First word in the string, 'foo' in 'foo argument' - $arg: Argument, if any, like 'argument' in 'foo argument' - $user: User who issued the command - $result: Resulting command @@ -1111,7 +1111,7 @@ EndGroupActionsList: End the list of actions on a group profile page (before build($action, $args, $params, $fragment); + if (Event::handle('StartLocalURL', array(&$action, &$params, &$fragment, &$addSession, &$url))) { + $r = Router::get(); + $path = $r->build($action, $args, $params, $fragment); - $ssl = common_is_sensitive($action); + $ssl = common_is_sensitive($action); - if (common_config('site','fancy')) { - $url = common_path(mb_substr($path, 1), $ssl, $addSession); - } else { - if (mb_strpos($path, '/index.php') === 0) { + if (common_config('site','fancy')) { $url = common_path(mb_substr($path, 1), $ssl, $addSession); } else { - $url = common_path('index.php'.$path, $ssl, $addSession); + if (mb_strpos($path, '/index.php') === 0) { + $url = common_path(mb_substr($path, 1), $ssl, $addSession); + } else { + $url = common_path('index.php'.$path, $ssl, $addSession); + } } + Event::handle('EndLocalURL', array(&$action, &$params, &$fragment, &$addSession, &$url)); } return $url; } diff --git a/plugins/Directory/DirectoryPlugin.php b/plugins/Directory/DirectoryPlugin.php index 4fe1eaec9e..107eb1a77c 100644 --- a/plugins/Directory/DirectoryPlugin.php +++ b/plugins/Directory/DirectoryPlugin.php @@ -85,6 +85,7 @@ class DirectoryPlugin extends Plugin switch ($cls) { case 'UserdirectoryAction': + case 'GroupdirectoryAction': include_once $dir . '/actions/' . strtolower(mb_substr($cls, 0, -6)) . '.php'; return false; @@ -111,6 +112,7 @@ class DirectoryPlugin extends Plugin */ function onRouterInitialized($m) { + $m->connect( 'directory/users', array('action' => 'userdirectory'), @@ -123,6 +125,52 @@ class DirectoryPlugin extends Plugin array('filter' => '([0-9a-zA-Z_]{1,64}|0-9)') ); + $m->connect( + 'groups/:filter', + array('action' => 'groupdirectory'), + array('filter' => '([0-9a-zA-Z_]{1,64}|0-9)') + ); + + return true; + } + + /** + * Hijack the routing (URL -> Action) for the normal directory page + * and substitute our group directory action + * + * @param string $path path to connect + * @param array $defaults path defaults + * @param array $rules path rules + * @param array $result unused + * + * @return boolean hook return + */ + function onStartConnectPath(&$path, &$defaults, &$rules, &$result) + { + if (in_array($path, array('group', 'group/', 'groups', 'groups/'))) { + $defaults['action'] = 'groupdirectory'; + $rules = array('filter' => 'all'); + return true; + } + return true; + } + + /** + * Hijack the mapping (Action -> URL) and return the URL to our + * group directory page instead of the normal groups page + * + * @param Action $action action to find a path for + * @param array $params parameters to pass to the action + * @param string $fragment any url fragement + * @param boolean $addSession whether to add session variable + * @param string $url resulting URL to local resource + * + * @return string the local URL + */ + function onEndLocalURL(&$action, &$params, &$fragment, &$addSession, &$url) { + if (in_array($action, array('group', 'group/', 'groups', 'groups/'))) { + $url = common_local_url('groupdirectory'); + } return true; }