Changeset 2848
- Timestamp:
- 11/23/08 19:57:54 (7 weeks ago)
- Location:
- trunk/htdocs/system/classes
- Files:
-
- 2 modified
-
acl.php (modified) (2 diffs)
-
bitmask.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/htdocs/system/classes/acl.php
r2834 r2848 32 32 public static function __static() 33 33 { 34 self::$access_ids = DB::get_keyvalue( 'SELECT name, id FROM {permissions};' );34 /*self::$access_ids = DB::get_keyvalue( 'SELECT name, id FROM {permissions};' ); 35 35 36 36 if ( ! isset(self::$access_ids) ) { 37 37 self::$access_ids = array(); 38 38 } 39 */ 40 self::$access_ids = array( 0 => 'read', 1 => 'write', 2 => 'deny' ); 39 41 self::$access_names = array_flip( self::$access_ids ); 40 42 } 41 43 42 44 /** 43 * Convert a permission access name (read, write, full,denied) into an ID45 * Convert a permission access name (read, write, denied) into an ID 44 46 * @param string The access name 45 47 * @return mixed the ID of the permission, or boolean FALSE if it does not exist … … 351 353 352 354 /** 355 * Get all the tokens for a given user with a particular kind of access 356 * @param mixed $user A user object, user ID or a username 357 * @param string $access Check for 'read', 'write', or 'full' access 358 * @return array of token IDs 359 **/ 360 public static function user_tokens( $user, $access = 'write' ) 361 { 362 // convert $user and $access to IDs 363 if ( is_numeric( $user ) ) { 364 $user_id = $user; 365 } else { 366 if ( ! $user instanceof User ) { 367 $user = User::get( $user ); 368 } 369 $user_id = $user->id; 370 } 371 $access_id = self::access_id( $access ); 372 373 $tokens = DB::get_results( 'SELECT token_id FROM {user_token_permissions} WHERE user_id = ? AND permission_id = ?', array( $user_id, $access_id) ); 374 return $tokens; 375 } 376 377 /** 353 378 * Grant a permission to a group 354 379 * @param integer $group_id The group ID -
trunk/htdocs/system/classes/bitmask.php
r2847 r2848 4 4 */ 5 5 class Bitmask { 6 public $flags = array(); // set of flag bit masks7 protected $value = 0; // internal integer value of the bitmask6 public $flags = array(); // set of flag bit masks 7 protected $value = 0; // internal integer value of the bitmask 8 8 9 /**10 * Constructor. Takes an optional array parameter11 * of bit flags to mask on.12 *13 * @param array $flags An array of flag names9 /** 10 * Constructor. Takes an optional array parameter 11 * of bit flags to mask on. 12 * 13 * @param array $flags An array of flag names 14 14 * @param integer $value (optional) a combined bitmask value 15 15 */ 16 public function __construct($flags = null, $value = null) {17 if ( ! is_array($flags))16 public function __construct( $flags = null, $value = null ) { 17 if ( ! is_array( $flags ) ) { 18 18 throw new InvalidArgumentException(_t('Bitmask constructor expects either no arguments or an array as a first argument')); 19 } 19 20 20 21 $this->flags = $flags; 21 if( !is_null($value)) {22 if( ! is_null( $value ) ) { 22 23 $this->value = $value; 23 24 } 24 25 25 }26 } 26 27 27 /**28 * Magic setter method for flag values.29 *30 * @param bit integer representing the mask bit31 * @param on on or off?32 */33 public function __set($bit, $on) {34 switch( $bit) {28 /** 29 * Magic setter method for flag values. 30 * 31 * @param bit integer representing the mask bit 32 * @param on on or off? 33 */ 34 public function __set( $bit, $on ) { 35 switch( $bit ) { 35 36 case 'value': 36 37 $this->value = $on; 37 38 break; 38 39 default: 39 if ( ! is_bool($flags))40 if ( ! is_bool( $flags ) ) 40 41 throw new InvalidArgumentException(_t('Bitmask values must be boolean')); 41 if( is_string( $bit) ) {42 $bit = array_search( $bit, $this->value);42 if( is_string( $bit ) ) { 43 $bit = array_search( $bit, $this->value ); 43 44 } 44 if( !is_int( $bit))45 if( !is_int( $bit ) ) 45 46 throw new InvalidArgumentException(_t('Bitmask names must be pre-defined strings or bitmask indexes')); 46 if( $on) {47 $this->value |= pow( 2, $bit);47 if( $on ) { 48 $this->value |= pow( 2, $bit ); 48 49 } 49 50 else { 50 $this->value &= ~pow( 2, $bit);51 $this->value &= ~pow( 2, $bit ); 51 52 } 52 53 break; … … 55 56 } 56 57 57 /**58 * Magic getter method for flag status59 *60 * @param bit integer representing th emask bit to test61 * @return boolean62 */63 public function __get($bit) {64 if ( is_int($bit) ) {65 $flags = array_values($this->flags);66 }58 /** 59 * Magic getter method for flag status 60 * 61 * @param bit integer representing th emask bit to test 62 * @return boolean 63 */ 64 public function __get( $bi t) { 65 if ( is_int( $bit ) ) { 66 $flags = array_values( $this->flags ); 67 } 67 68 else { 68 69 $flags = $this->flags; 69 70 } 70 if (!isset($flags[$bit])) 71 return false; 72 return (($this->value & $this->flags[$bit]) == $this->flags[$bit]); 73 } 71 if ( ! isset( $flags[$bit] ) ) { 72 return false; 73 } 74 return ( ( $this->value & $this->flags[$bit] ) == $this->flags[$bit] ); 75 } 74 76 75 77 }
