DirectoryPlugin - Hijack router mapping for normal groups page to substitute a directory page
This commit is contained in:
parent
409550e1dc
commit
0f9d6f4c82
15
EVENTS.txt
15
EVENTS.txt
|
@ -1351,3 +1351,18 @@ EndValidateEmailInvite: after validating an email address for invitations
|
||||||
- $user: user doing the invite
|
- $user: user doing the invite
|
||||||
- $email: email address
|
- $email: email address
|
||||||
- &$valid: flag for if it's valid; can be modified
|
- &$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
|
||||||
|
|
||||||
|
|
|
@ -1221,6 +1221,7 @@ function common_relative_profile($sender, $nickname, $dt=null)
|
||||||
|
|
||||||
function common_local_url($action, $args=null, $params=null, $fragment=null, $addSession=true)
|
function common_local_url($action, $args=null, $params=null, $fragment=null, $addSession=true)
|
||||||
{
|
{
|
||||||
|
if (Event::handle('StartLocalURL', array(&$action, &$params, &$fragment, &$addSession, &$url))) {
|
||||||
$r = Router::get();
|
$r = Router::get();
|
||||||
$path = $r->build($action, $args, $params, $fragment);
|
$path = $r->build($action, $args, $params, $fragment);
|
||||||
|
|
||||||
|
@ -1235,6 +1236,8 @@ function common_local_url($action, $args=null, $params=null, $fragment=null, $ad
|
||||||
$url = common_path('index.php'.$path, $ssl, $addSession);
|
$url = common_path('index.php'.$path, $ssl, $addSession);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Event::handle('EndLocalURL', array(&$action, &$params, &$fragment, &$addSession, &$url));
|
||||||
|
}
|
||||||
return $url;
|
return $url;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -85,6 +85,7 @@ class DirectoryPlugin extends Plugin
|
||||||
switch ($cls)
|
switch ($cls)
|
||||||
{
|
{
|
||||||
case 'UserdirectoryAction':
|
case 'UserdirectoryAction':
|
||||||
|
case 'GroupdirectoryAction':
|
||||||
include_once $dir
|
include_once $dir
|
||||||
. '/actions/' . strtolower(mb_substr($cls, 0, -6)) . '.php';
|
. '/actions/' . strtolower(mb_substr($cls, 0, -6)) . '.php';
|
||||||
return false;
|
return false;
|
||||||
|
@ -111,6 +112,7 @@ class DirectoryPlugin extends Plugin
|
||||||
*/
|
*/
|
||||||
function onRouterInitialized($m)
|
function onRouterInitialized($m)
|
||||||
{
|
{
|
||||||
|
|
||||||
$m->connect(
|
$m->connect(
|
||||||
'directory/users',
|
'directory/users',
|
||||||
array('action' => 'userdirectory'),
|
array('action' => 'userdirectory'),
|
||||||
|
@ -123,6 +125,52 @@ class DirectoryPlugin extends Plugin
|
||||||
array('filter' => '([0-9a-zA-Z_]{1,64}|0-9)')
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user