3
* The Group_hooks:: class provides the Horde groups system with the
4
* addition of adding support for hook functions to define if a user
7
* $Horde: framework/Group/Group/hooks.php,v 1.7.2.1 2005/01/03 12:19:01 jan Exp $
9
* Copyright 2003-2005 Jason Rust <jrust@rustyparts.com>
11
* See the enclosed file COPYING for license information (LGPL). If you
12
* did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
14
* @author Jason Rust <jrust@rustyparts.com>
16
* @package Horde_Group
18
class Group_hooks extends Group {
23
function Group_hooks()
26
require $GLOBALS['registry']->get('fileroot', 'horde') . '/config/hooks.php';
30
* Get a list of every group that $user is in.
32
* @param string $user The user to get groups for.
34
* @return array An array of all groups the user is in.
36
function getGroupMemberships($user)
38
$memberships = parent::getGroupMemberships($user);
39
$funcs = get_defined_functions();
40
foreach ($funcs['user'] as $funcName) {
41
if (strpos($funcName, '_group_hook_') === 0) {
42
$groupName = substr($funcName, 12);
43
if (!in_array($groupName, $memberships) &&
44
$this->exists($groupName) &&
45
call_user_func($funcName, $user)) {
46
$memberships[] = $groupName;
55
* Say if a user is a member of a group or not.
57
* @param string $user The name of the user.
58
* @param string $group The name of the group.
59
* @param optional boolean $subgroups Return true if the user is in any subgroups
65
function userIsInGroup($user, $group, $subgroups = false)
67
if ($this->hasHook($group)) {
68
if (call_user_func($this->_getGroupHookName($group), $user)) {
77
if ($inGroup || parent::userIsInGroup($user, $group, $subgroups)) {
85
* Determines if a group has a hook associated with it.
87
* @param string $name The group name.
90
* @return boolean True if the group has a hook, false otherwise
92
function hasHook($name)
94
return function_exists($this->_getGroupHookName($name));
98
* Returns the name of the hook function.
100
* @param string $name The group name.
103
* @return string The function name for the hook for this group
105
function _getGroupHookName($name)
107
return '_group_hook_' . str_replace(':', '__', $name);