]> gitweb.fluxo.info Git - lorea/elgg.git/commitdiff
First pass at removing $is_admin global.
authorbrettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544>
Tue, 13 Oct 2009 03:31:16 +0000 (03:31 +0000)
committerbrettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544>
Tue, 13 Oct 2009 03:31:16 +0000 (03:31 +0000)
git-svn-id: http://code.elgg.org/elgg/trunk@3528 36083f99-b078-4883-b0ff-0f9b5a30f544

engine/lib/access.php
engine/lib/admin.php
engine/lib/sessions.php

index b39cb145505720617205582356f8f3277afb83f2..73fb5e82c4c94bb3177ff6a2f9c5685c13325f00 100644 (file)
  * @link http://elgg.org/
  */
 
+/**
+ * Temporary class used to determing if access is being ignored
+ */
+class ElggAccess {
+       /**
+        * Bypass Elgg's access control if true.
+        * @var bool
+        */
+       private $ignore_access;
+
+       /**
+        * Get current ignore access setting.
+        * @return bool
+        */
+       public function get_ignore_access() {
+               return $ignore_access;
+       }
+
+       /**
+        * Set ignore access.
+        *
+        * @param $ignore bool true || false to ignore
+        * @return bool Previous setting
+        */
+       public function set_ignore_access($ignore = true) {
+               $prev = $this->ignore_access;
+               $this->ignore_access = $ignore;
+
+               return $prev;
+       }
+}
+
+
 /**
  * Return a string of access_ids for $user_id appropriate for inserting into an SQL IN clause.
  *
@@ -109,9 +142,9 @@ function get_access_array($user_id = 0, $site_id = 0, $flush = false) {
                                }
                        }
 
-                       $is_admin = is_admin_user($user_id);
+                       $ignore_access = elgg_is_ignore_access($user_id);
 
-                       if ($is_admin == true) {
+                       if ($ignore_access == true) {
                                $tmp_access_array[] = ACCESS_PRIVATE;
                        }
 
@@ -239,10 +272,10 @@ function get_access_sql_suffix($table_prefix = "", $owner = null) {
                $owner = -1;
        }
 
-       $is_admin = is_admin_user($owner);
+       $ignore_access = elgg_get_ignore_access($owner);
        $access = get_access_list($owner);
 
-       if ($is_admin) {
+       if ($ignore_access) {
                $sql = " (1 = 1) ";
        } else if ($owner != -1) {
                $friends_bit = "{$table_prefix}access_id = " . ACCESS_FRIENDS . "
@@ -742,6 +775,56 @@ function get_readable_access_level($entity_accessid){
        return false;
 }
 
+/**
+ * Set if entity access system should be ignored.
+ *
+ * @return bool Previous ignore_access setting.
+ */
+function elgg_set_ignore_access($ignore = true) {
+       $elgg_access = elgg_get_access_object();
+
+       return $elgg_access->set_ignore_access($ignore);
+}
+
+/**
+ * Get current ignore access setting.
+ *
+ * @return bool
+ */
+function elgg_get_ignore_access() {
+       return elgg_get_access_object()->get_ignore_access();
+}
+
+/**
+ * Decides if the access system is being ignored.
+ *
+ * @return bool
+ */
+function elgg_is_ignore_access($user_guid = null) {
+       if (!$user_guid || $user_guid <= 0) {
+               $is_admin = false;
+       } else {
+               $is_admin = elgg_is_admin_user($user_guid);
+       }
+
+       return ($is_admin || elgg_get_ignore_access());
+}
+
+/**
+ * Returns the ElggAccess object.
+ *
+ * @return ElggAccess
+ */
+function elgg_get_access_object() {
+       static $elgg_access;
+
+       if (!$elgg_access) {
+               $elgg_access = new ElggAccess();
+       }
+
+       return $elgg_access;
+}
+
 global $init_finished;
 $init_finished = false;
 
index 0c687e25520c929e51a465e064ffe54ae4720fb7..c598295bef6c420105febbdbaeca643c0d89da79 100644 (file)
@@ -55,10 +55,10 @@ function admin_init() {
        // Page handler
        register_page_handler('admin','admin_settings_page_handler');
 
-       if (isadminloggedin()) {
-               global $is_admin;
-               $is_admin = true;
-       }
+//     if (isadminloggedin()) {
+//             global $is_admin;
+//             $is_admin = true;
+//     }
 }
 
 /**
index d3e4a499d1cee9bb20d32a264ce4aab4192fce38..914f3701a39b2acc54e7de23d650a3cd1cff6b0a 100644 (file)
@@ -171,26 +171,34 @@ function isadminloggedin() {
  * @param $user_guid
  * @return bool
  */
-function is_admin_user($user_guid) {
+function elgg_is_admin_user($user_guid) {
        global $CONFIG;
 
-       // cannot use metadata here because
+       // cannot use metadata here because of recursion
+
        // caching is done at the db level so no need to here.
-       $query = "SELECT * FROM {$CONFIG->dbprefix}users_entity as e, {$CONFIG->dbprefix}metastrings as ms1, {$CONFIG->dbprefix}metastrings as ms2, {$CONFIG->dbprefix}metadata as md
+       $query = "SELECT * FROM {$CONFIG->dbprefix}users_entity as e,
+               {$CONFIG->dbprefix}metastrings as ms1,
+               {$CONFIG->dbprefix}metastrings as ms2,
+               {$CONFIG->dbprefix}metadata as md
                WHERE (
-                       ms1.string = 'admin' AND ms2.string = 'yes'
-                       AND md.name_id = ms1.id AND md.value_id = ms2.id
-                       AND e.guid = md.entity_guid
-                       AND e.guid = {$user_guid}
-                       AND e.banned = 'no'
+                       (
+                               (ms1.string = 'admin' AND ms2.string = 'yes')
+                               OR (ms1.string = 'admin' AND ms2.string = '1')
                        )
-               OR (
-                       ms1.string = 'admin' AND ms2.string = '1'
                        AND md.name_id = ms1.id AND md.value_id = ms2.id
                        AND e.guid = md.entity_guid
                        AND e.guid = {$user_guid}
                        AND e.banned = 'no'
                        )";
+//             OR (
+//                     ms1.string = 'admin' AND ms2.string = '1'
+//                     AND md.name_id = ms1.id AND md.value_id = ms2.id
+//                     AND e.guid = md.entity_guid
+//                     AND e.guid = {$user_guid}
+//                     AND e.banned = 'no'
+//                     )";
+
 
        // normalizing the results from get_data()
        // See #1242
@@ -399,11 +407,11 @@ function login(ElggUser $user, $persistent = false) {
        reset_login_failure_count($user->guid); // Reset any previous failed login attempts
 
        // Set admin shortcut flag if this is an admin
-       if (isadminloggedin()) {
-               //@todo REMOVE THIS.
-               global $is_admin;
-               $is_admin = true;
-       }
+//     if (isadminloggedin()) {
+//             //@todo REMOVE THIS.
+//             global $is_admin;
+//             $is_admin = true;
+//     }
 
        return true;
 }