[ Index ] |
|
Code source de Horde 3.1.3 |
1 <?php 2 /** 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 5 * is in a group. 6 * 7 * $Horde: framework/Group/Group/hooks.php,v 1.7.2.10 2006/01/01 21:28:19 jan Exp $ 8 * 9 * Copyright 2003-2006 Jason Rust <jrust@rustyparts.com> 10 * 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. 13 * 14 * @author Jason Rust <jrust@rustyparts.com> 15 * @since Horde 3.0 16 * @package Horde_Group 17 */ 18 class Group_hooks extends Group { 19 20 /** 21 * Constructor. 22 */ 23 function Group_hooks() 24 { 25 parent::Group(); 26 require $GLOBALS['registry']->get('fileroot', 'horde') . '/config/hooks.php'; 27 } 28 29 /** 30 * Get a list of every group that $user is in. 31 * 32 * @param string $user The user to get groups for. 33 * @param boolean $parentGroups Also return the parents of any groups? 34 * 35 * @return array An array of all groups the user is in. 36 */ 37 function getGroupMemberships($user, $parentGroups = false) 38 { 39 $memberships = parent::getGroupMemberships($user, $parentGroups); 40 $groups = $this->listGroups(); 41 foreach ($groups as $gid => $group) { 42 if ($this->hasHook($group) && 43 call_user_func($this->_getGroupHookName($group), $user)) { 44 $memberships += array($gid => $group); 45 } 46 if ($parentGroups) { 47 $parents = $this->getGroupParentList($gid); 48 foreach ($parents as $pid => $parent) { 49 if ($this->hasHook($parent) && 50 call_user_func($this->_getGroupHookName($group), $user)) { 51 $memberships += array($pid => $parent); 52 } 53 } 54 } 55 } 56 57 return $memberships; 58 } 59 60 /** 61 * Say if a user is a member of a group or not. 62 * 63 * @param string $user The name of the user. 64 * @param integer $gid The ID of the group. 65 * @param boolean $subgroups Return true if the user is in any subgroups 66 * of $group, also. 67 * 68 * @return boolean 69 */ 70 function userIsInGroup($user, $gid, $subgroups = true) 71 { 72 $group = $this->getGroupName($gid); 73 if ($this->hasHook($group)) { 74 if (call_user_func($this->_getGroupHookName($group), $user)) { 75 $inGroup = true; 76 } else { 77 $inGroup = false; 78 } 79 } else { 80 $inGroup = false; 81 } 82 83 if ($inGroup || parent::userIsInGroup($user, $gid, $subgroups)) { 84 return true; 85 } else { 86 return false; 87 } 88 } 89 90 /** 91 * Determines if a group has a hook associated with it. 92 * 93 * @param string $name The group name. 94 * 95 * @return boolean True if the group has a hook, false otherwise 96 */ 97 function hasHook($name) 98 { 99 return function_exists($this->_getGroupHookName($name)); 100 } 101 102 /** 103 * Returns the name of the hook function. 104 * 105 * @param string $name The group name. 106 * 107 * @return string The function name for the hook for this group 108 */ 109 function _getGroupHookName($name) 110 { 111 return '_group_hook_' . str_replace(':', '__', $name); 112 } 113 114 }
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sun Feb 25 18:01:28 2007 | par Balluche grâce à PHPXref 0.7 |