コード例 #1
0
ファイル: UserBase.php プロジェクト: hotarucms/hotarucms
 /**
  * Default permissions
  *
  * @param string $role or 'all'
  * @param string $field 'site' for site defaults and 'base' for base defaults
  * @param book $options_only returns just the options if true
  * @return array $perms
  */
 public function getDefaultPermissions($h, $role = '', $defaults = 'site', $options_only = false)
 {
     $perms = array();
     // to be filled with default permissions for this user
     if ($defaults == 'site') {
         //$field = 'miscdata_value';
         //$db_perms = \HotaruModels\Miscdata::getCurrentValue('permissions');
         $db_perms = \Hotaru\Models2\Miscdata::getCurrentValue($h, 'permissions');
     } else {
         //$field = 'miscdata_default';
         //$db_perms = \HotaruModels\Miscdata::getDefaultValue('permissions');
         $db_perms = \Hotaru\Models2\Miscdata::getDefaultValue($h, 'permissions');
     }
     // get default permissions from the database:
     //		$query = "SELECT " . $field . " FROM " . TABLE_MISCDATA . " WHERE miscdata_key = %s LIMIT 1";
     //		$sql = $h->db->prepare($query, 'permissions');
     //
     //		// Create temp cache array
     //		if (!isset($h->vars['tempPermissionsCache'])) { $h->vars['tempPermissionsCache'] = array(); }
     //
     //		// If this query has already been read once this page load, we should have it in memory...
     //		if (array_key_exists($sql, $h->vars['tempPermissionsCache'])) {
     //			// Fetch from memory
     //			$db_perms = $h->vars['tempPermissionsCache'][$sql];
     //		} else {
     //			// Fetch from database
     //			$db_perms = $h->db->get_var($sql);
     //			$h->vars['tempPermissionsCache'][$sql] = $db_perms;
     //		}
     $permissions = unserialize($db_perms);
     if (!$permissions) {
         return array();
     }
     // must return an empty array for array_merge, not false.
     if ($options_only) {
         return $permissions['options'];
         // the editPermissions function in the Users plugin needs these
     }
     if ($role == 'all') {
         return $permissions;
     }
     // plugins need all permissions and options when installed
     unset($permissions['options']);
     // don't need the options anymore
     foreach ($permissions as $perm => $roles) {
         if (isset($roles[$role])) {
             $perms[$perm] = $roles[$role];
             // perm for this role
         } else {
             $perms[$perm] = $roles['default'];
             // default perm because nothing specified for this role
         }
     }
     return $perms;
 }