diff options
author | brettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544> | 2009-10-13 03:31:16 +0000 |
---|---|---|
committer | brettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544> | 2009-10-13 03:31:16 +0000 |
commit | a818e6fc766efa996df2841d63f1c943f97513b5 (patch) | |
tree | abd8001026ee52b181e9584f96c44acb110a737f /engine | |
parent | c499b05093744813a04fe537e0b588a547f3a784 (diff) | |
download | elgg-a818e6fc766efa996df2841d63f1c943f97513b5.tar.gz elgg-a818e6fc766efa996df2841d63f1c943f97513b5.tar.bz2 |
First pass at removing $is_admin global.
git-svn-id: http://code.elgg.org/elgg/trunk@3528 36083f99-b078-4883-b0ff-0f9b5a30f544
Diffstat (limited to 'engine')
-rw-r--r-- | engine/lib/access.php | 91 | ||||
-rw-r--r-- | engine/lib/admin.php | 8 | ||||
-rw-r--r-- | engine/lib/sessions.php | 38 |
3 files changed, 114 insertions, 23 deletions
diff --git a/engine/lib/access.php b/engine/lib/access.php index b39cb1455..73fb5e82c 100644 --- a/engine/lib/access.php +++ b/engine/lib/access.php @@ -12,6 +12,39 @@ */ /** + * 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. * * @uses get_access_array @@ -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; diff --git a/engine/lib/admin.php b/engine/lib/admin.php index 0c687e255..c598295be 100644 --- a/engine/lib/admin.php +++ b/engine/lib/admin.php @@ -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; +// } } /** diff --git a/engine/lib/sessions.php b/engine/lib/sessions.php index d3e4a499d..914f3701a 100644 --- a/engine/lib/sessions.php +++ b/engine/lib/sessions.php @@ -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; } |