includes/sessions.php
changeset 556 63e131c38876
parent 555 ac4c6a7f01d8
child 557 26479224936a
equal deleted inserted replaced
555:ac4c6a7f01d8 556:63e131c38876
   270       USER_LEVEL_ADMIN  => RANK_ID_ADMIN,
   270       USER_LEVEL_ADMIN  => RANK_ID_ADMIN,
   271       USER_LEVEL_MOD    => RANK_ID_MOD,
   271       USER_LEVEL_MOD    => RANK_ID_MOD,
   272       USER_LEVEL_MEMBER => RANK_ID_MEMBER,
   272       USER_LEVEL_MEMBER => RANK_ID_MEMBER,
   273       USER_LEVEL_CHPREF => RANK_ID_MEMBER,
   273       USER_LEVEL_CHPREF => RANK_ID_MEMBER,
   274       USER_LEVEL_GUEST  => RANK_ID_GUEST
   274       USER_LEVEL_GUEST  => RANK_ID_GUEST
       
   275     );
       
   276   
       
   277   /**
       
   278    * A constant array that maps precedence constants to language strings
       
   279    * @var array
       
   280    */
       
   281   
       
   282   var $acl_inherit_lang_table = array(
       
   283       ACL_INHERIT_ENANO_DEFAULT   => 'acl_inherit_enano_default',
       
   284       ACL_INHERIT_GLOBAL_EVERYONE => 'acl_inherit_global_everyone',
       
   285       ACL_INHERIT_GLOBAL_GROUP    => 'acl_inherit_global_group',
       
   286       ACL_INHERIT_GLOBAL_USER     => 'acl_inherit_global_user',
       
   287       ACL_INHERIT_PG_EVERYONE     => 'acl_inherit_pg_everyone',
       
   288       ACL_INHERIT_PG_GROUP        => 'acl_inherit_pg_group',
       
   289       ACL_INHERIT_PG_USER         => 'acl_inherit_pg_user',
       
   290       ACL_INHERIT_LOCAL_EVERYONE  => 'acl_inherit_local_everyone',
       
   291       ACL_INHERIT_LOCAL_GROUP     => 'acl_inherit_local_group',
       
   292       ACL_INHERIT_LOCAL_USER      => 'acl_inherit_local_user'
   275     );
   293     );
   276   
   294   
   277   # Basic functions
   295   # Basic functions
   278    
   296    
   279   /**
   297   /**
  2820     {
  2838     {
  2821       $base_cache[$user_id_or_name] = $this->acl_types;
  2839       $base_cache[$user_id_or_name] = $this->acl_types;
  2822       $current_perms =& $base_cache[$user_id_or_name];
  2840       $current_perms =& $base_cache[$user_id_or_name];
  2823       $current_perms['__resolve_table'] = array();
  2841       $current_perms['__resolve_table'] = array();
  2824       
  2842       
  2825       $bs = 'SELECT rules, target_type, target_id, rule_id, page_id, namespace FROM '.table_prefix.'acl' . "\n"
  2843       $bs = 'SELECT rules, target_type, target_id, rule_id, page_id, namespace, g.group_name FROM '.table_prefix."acl AS a\n"
  2826              . '  WHERE page_id IS NULL AND namespace IS NULL AND' . "\n"
  2844           . "  LEFT JOIN " . table_prefix . "groups AS g\n"
  2827              . '  ( ';
  2845           . "    ON ( ( a.target_type = " . ACL_TYPE_GROUP . " AND a.target_id = g.group_id ) OR ( a.target_type != " . ACL_TYPE_GROUP . " ) )\n"
       
  2846           . '  WHERE page_id IS NULL AND namespace IS NULL AND' . "\n"
       
  2847           . '  ( ';
  2828     
  2848     
  2829       $q = Array();
  2849       $q = Array();
  2830       $q[] = '( target_type='.ACL_TYPE_USER.' AND target_id= ' . $user_id . ' )';
  2850       $q[] = '( target_type='.ACL_TYPE_USER.' AND target_id= ' . $user_id . ' )';
  2831       if(count($groups) > 0)
  2851       if(count($groups) > 0)
  2832       {
  2852       {
  2839       $q = $this->sql($bs);
  2859       $q = $this->sql($bs);
  2840       foreach ( $this->acl_types as $perm_type => $_ )
  2860       foreach ( $this->acl_types as $perm_type => $_ )
  2841       {
  2861       {
  2842         // init the resolver table with blanks
  2862         // init the resolver table with blanks
  2843         $current_perms['__resolve_table'][$perm_type] = array(
  2863         $current_perms['__resolve_table'][$perm_type] = array(
  2844             'src' => ACL_INHERIT_GLOBAL_EVERYONE,
  2864             'src' => ACL_INHERIT_ENANO_DEFAULT,
  2845             'rule_id' => -1
  2865             'rule_id' => -1
  2846           );
  2866           );
  2847       }
  2867       }
  2848       if ( $row = $db->fetchrow() )
  2868       if ( $row = $db->fetchrow() )
  2849       {
  2869       {
  2856           {
  2876           {
  2857             $current_perms['__resolve_table'][$perm_type] = array(
  2877             $current_perms['__resolve_table'][$perm_type] = array(
  2858                 'src' => $src,
  2878                 'src' => $src,
  2859                 'rule_id' => $row['rule_id']
  2879                 'rule_id' => $row['rule_id']
  2860               );
  2880               );
       
  2881             if ( $row['group_name'] )
       
  2882             {
       
  2883               $current_perms['__resolve_table'][$perm_type]['group_name'] = $row['group_name'];
       
  2884             }
  2861           }
  2885           }
  2862           // merge it in
  2886           // merge it in
  2863           $current_perms = $this->acl_merge($current_perms, $rules, $is_everyone, $_defaults_used);
  2887           $current_perms = $this->acl_merge($current_perms, $rules, $is_everyone, $_defaults_used);
  2864         } while ( $row = $db->fetchrow() );
  2888         } while ( $row = $db->fetchrow() );
  2865       }
  2889       }
  3916     {
  3940     {
  3917       $pg_info .= ' ( page_id=\'' . $g_id . '\' AND namespace=\'__PageGroup\' ) OR';
  3941       $pg_info .= ' ( page_id=\'' . $g_id . '\' AND namespace=\'__PageGroup\' ) OR';
  3918     }
  3942     }
  3919     
  3943     
  3920     // Build a query to grab ACL info
  3944     // Build a query to grab ACL info
  3921     $bs = 'SELECT rules,target_type,target_id,page_id,namespace,rule_id FROM '.table_prefix.'acl WHERE ' . "\n"
  3945     $bs = 'SELECT rules,target_type,target_id,page_id,namespace,rule_id,pg.pg_name,g.group_name FROM '.table_prefix."acl AS a\n"
       
  3946         . "  LEFT JOIN " . table_prefix . "page_groups AS pg\n"
       
  3947         . "    ON ( ( a.page_id = pg.pg_id AND a.namespace = '__PageGroup' ) OR ( a.namespace != '__PageGroup' ) )\n"
       
  3948         . "  LEFT JOIN " . table_prefix . "groups AS g\n"
       
  3949         . "    ON ( ( a.target_type = " . ACL_TYPE_GROUP . " AND a.target_id = g.group_id ) OR ( a.target_type != " . ACL_TYPE_GROUP . " ) )\n";
       
  3950     
       
  3951     $bs .= '  WHERE ' . "\n"
  3922           . '  ( ';
  3952           . '  ( ';
  3923     $q = Array();
  3953     $q = Array();
  3924     $q[] = '( target_type='.ACL_TYPE_USER.' AND target_id='.$this->user_id.' )';
  3954     $q[] = '( target_type='.ACL_TYPE_USER.' AND target_id='.$this->user_id.' )';
  3925     if(count($this->groups) > 0)
  3955     if(count($this->groups) > 0)
  3926     {
  3956     {
  3931     }
  3961     }
  3932     // The reason we're using an ORDER BY statement here is because ACL_TYPE_GROUP is less than ACL_TYPE_USER, causing the user's individual
  3962     // The reason we're using an ORDER BY statement here is because ACL_TYPE_GROUP is less than ACL_TYPE_USER, causing the user's individual
  3933     // permissions to override group permissions.
  3963     // permissions to override group permissions.
  3934     $bs .= implode(" OR\n    ", $q) . ' ) AND (' . $pg_info . ' ( page_id=\''.$db->escape($page_id).'\' AND namespace=\''.$db->escape($namespace).'\' ) )     
  3964     $bs .= implode(" OR\n    ", $q) . ' ) AND (' . $pg_info . ' ( page_id=\''.$db->escape($page_id).'\' AND namespace=\''.$db->escape($namespace).'\' ) )     
  3935       ORDER BY target_type ASC, page_id ASC, namespace ASC;';
  3965       ORDER BY target_type ASC, page_id ASC, namespace ASC;';
       
  3966       
  3936     $q = $session->sql($bs);
  3967     $q = $session->sql($bs);
  3937     if ( $row = $db->fetchrow() )
  3968     if ( $row = $db->fetchrow() )
  3938     {
  3969     {
  3939       do {
  3970       do {
  3940         $rules = $session->string_to_perm($row['rules']);
  3971         $rules = $session->string_to_perm($row['rules']);
  3941         $is_everyone = ( $row['target_type'] == ACL_TYPE_GROUP && $row['target_id'] == 1 );
  3972         $is_everyone = ( $row['target_type'] == ACL_TYPE_GROUP && $row['target_id'] == 1 );
  3942         // log where this comes from
  3973         // log where this comes from
  3943         if ( $row['namespace'] == '__PageGroup' )
  3974         if ( $row['namespace'] == '__PageGroup' )
  3944         {
  3975         {
  3945           $src = ( $is_everyone ) ? ACL_INHERIT_PG_EVERYONE : ( $row['target_type'] == ACL_TYPE_GROUP ? ACL_INHERIT_PG_GROUP : ACL_INHERIT_PG_USER );
  3976           $src = ( $is_everyone ) ? ACL_INHERIT_PG_EVERYONE : ( $row['target_type'] == ACL_TYPE_GROUP ? ACL_INHERIT_PG_GROUP : ACL_INHERIT_PG_USER );
       
  3977           $pg_name = $row['pg_name'];
  3946         }
  3978         }
  3947         else
  3979         else
  3948         {
  3980         {
  3949           $src = ( $is_everyone ) ? ACL_INHERIT_LOCAL_EVERYONE : ( $row['target_type'] == ACL_TYPE_GROUP ? ACL_INHERIT_LOCAL_GROUP : ACL_INHERIT_LOCAL_USER );
  3981           $src = ( $is_everyone ) ? ACL_INHERIT_LOCAL_EVERYONE : ( $row['target_type'] == ACL_TYPE_GROUP ? ACL_INHERIT_LOCAL_GROUP : ACL_INHERIT_LOCAL_USER );
       
  3982         }
       
  3983         if ( $row['group_name'] )
       
  3984         {
       
  3985           $group_name = $row['group_name'];
  3950         }
  3986         }
  3951         foreach ( $rules as $perm_type => $perm_value )
  3987         foreach ( $rules as $perm_type => $perm_value )
  3952         {
  3988         {
  3953           if ( $this->perms[$perm_type] == AUTH_DENY )
  3989           if ( $this->perms[$perm_type] == AUTH_DENY )
  3954             continue;
  3990             continue;
  3955           
  3991           
  3956           $this->perm_resolve_table[$perm_type] = array(
  3992           $this->perm_resolve_table[$perm_type] = array(
  3957               'src' => $src,
  3993               'src' => $src,
  3958               'rule_id' => $row['rule_id']
  3994               'rule_id' => $row['rule_id']
  3959             );
  3995             );
       
  3996           if ( isset($pg_name) )
       
  3997           {
       
  3998             $this->perm_resolve_table[$perm_type]['pg_name'] = $pg_name;
       
  3999           }
       
  4000           if ( isset($group_name) )
       
  4001           {
       
  4002             $this->perm_resolve_table[$perm_type]['group_name'] = $group_name;
       
  4003           }
  3960         }
  4004         }
  3961         $this->acl_merge_with_current($rules, $is_everyone);
  4005         $this->acl_merge_with_current($rules, $is_everyone);
  3962       } while ( $row = $db->fetchrow() );
  4006       } while ( $row = $db->fetchrow() );
  3963     }
  4007     }
  3964     
  4008