Changeset 121
- Timestamp:
- 08/27/08 18:50:48 (3 months ago)
- Files:
-
- trunk/includes/class.bp-roles.php (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/includes/class.bp-roles.php
r65 r121 2 2 3 3 class BP_Roles { 4 var $db;5 6 var $roles;7 8 4 var $role_objects = array(); 9 5 var $role_names = array(); 10 var $role_key;11 var $use_db = true;12 6 13 function BP_Roles( &$db) {7 function BP_Roles() { 14 8 $this->__construct(); 15 9 } 16 10 17 function __construct() { 18 $this->db =& $db; 19 $this->role_key =& $this->db->prefix; 20 21 $this->get_roles(); 22 23 if ( empty($this->roles) ) 24 return; 25 26 $this->role_objects = array(); 27 $this->role_names = array(); 28 foreach ($this->roles as $role => $data) { 29 $this->role_objects[$role] = new BP_Role($role, $this->roles[$role]['capabilities'], $this); 30 $this->role_names[$role] = $this->roles[$role]['name']; 31 } 32 } 33 34 function get_roles() { 35 $this->roles = apply_filters( 'get_roles', array() ); 11 function __construct( &$db ) { 12 do_action_ref_array('init_roles', array(&$this) ); 36 13 } 37 14 … … 39 16 if ( isset($this->roles[$role]) ) 40 17 return; 41 42 $this->roles[$role] = array(43 'name' => $display_name,44 'capabilities' => $capabilities);45 18 46 19 $this->role_objects[$role] = new BP_Role($role, $capabilities, $this); … … 55 28 unset($this->role_objects[$role]); 56 29 unset($this->role_names[$role]); 57 unset($this->roles[$role]);58 30 } 59 31 60 32 function add_cap($role, $cap, $grant = true) { 61 $this->roles[$role]['capabilities'][$cap] = $grant; 33 if ( isset($this->role_objects[$role]) ) 34 $this->role_objects[$role]->add_cap($cap, $grant); 62 35 } 63 36 64 37 function remove_cap($role, $cap) { 65 unset($this->roles[$role]['capabilities'][$cap]); 38 if ( isset($this->role_objects[$role]) ) 39 $this->role_objects[$role]->remove_cap($cap, $grant); 66 40 } 67 41 … … 88 62 89 63 class BP_Role { 90 var $bp_roles;91 92 64 var $name; 93 65 var $capabilities; 94 66 95 function BP_Role($role, $capabilities, &$bp_roles) { 96 $this->bp_roles =& $bp_roles; 67 function BP_Role($role, $capabilities) { 97 68 $this->name = $role; 98 69 $this->capabilities = $capabilities; … … 101 72 function add_cap($cap, $grant = true) { 102 73 $this->capabilities[$cap] = $grant; 103 $this->bp_roles->add_cap($this->name, $cap, $grant);104 74 } 105 75 106 76 function remove_cap($cap) { 107 77 unset($this->capabilities[$cap]); 108 $this->bp_roles->remove_cap($this->name, $cap);109 78 } 110 79 111 80 function has_cap($cap) { 112 81 $capabilities = apply_filters('role_has_cap', $this->capabilities, $cap, $this->name); 113 if ( !empty($capabilities[$cap]) ) 114 return $capabilities[$cap]; 115 else 116 return false; 82 $grant = !empty( $capabilities[$cap] ); 83 return apply_filters("{$this->name}_has_cap", $grant); 117 84 } 118 85 119 86 } 120 121 ?>
