DirectoryPlugin - Hijack router mapping for normal groups page to substitute a directory page

This commit is contained in:
Zach Copley 2011-04-12 21:08:02 -07:00
parent 409550e1dc
commit 0f9d6f4c82
3 changed files with 77 additions and 11 deletions

View File

@ -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 </u
StartGroupProfileElements: Start showing stuff about the group on its profile page
- $action: action being executed (for output and params)
- $group: group for the page
EndGroupProfileElements: Start showing stuff about the group on its profile page
- $action: action being executed (for output and params)
- $group: group for the page
@ -1351,3 +1351,18 @@ EndValidateEmailInvite: after validating an email address for invitations
- $user: user doing the invite
- $email: email address
- &$valid: flag for if it's valid; can be modified
StartLocalURL: before resolving a local url for an action
- &$action: action to find a path for
- &$paramsi: parameters to pass to the action
- &$fragment: any url fragement
- &$addSession: whether to add session variable
- &$url: resulting URL to local resource
EndLocalURL: before resolving a local url for an action
- &$action: action to find a path for
- &$paramsi: parameters to pass to the action
- &$fragment: any url fragement
- &$addSession: whether to add session variable
- &$url: resulting URL to local resource

View File

@ -1221,19 +1221,22 @@ function common_relative_profile($sender, $nickname, $dt=null)
function common_local_url($action, $args=null, $params=null, $fragment=null, $addSession=true)
{
$r = Router::get();
$path = $r->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;
}

View File

@ -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;
}