diff options
author | Andreas Fischer <bantu@phpbb.com> | 2011-12-25 15:13:02 +0100 |
---|---|---|
committer | Andreas Fischer <bantu@phpbb.com> | 2011-12-25 15:13:02 +0100 |
commit | 71698996caab075e333b2ca70fdeff8dedbe52b2 (patch) | |
tree | 9ad3ec6be5d71c1354138baf4659dd57eaae1f9c /phpBB/includes | |
parent | 0f974f94946b9e23f289ac70dc971a026ba588c0 (diff) | |
parent | b0fd3b2bf092658290db7eb062a3e25899fb5dec (diff) | |
download | forums-71698996caab075e333b2ca70fdeff8dedbe52b2.tar forums-71698996caab075e333b2ca70fdeff8dedbe52b2.tar.gz forums-71698996caab075e333b2ca70fdeff8dedbe52b2.tar.bz2 forums-71698996caab075e333b2ca70fdeff8dedbe52b2.tar.xz forums-71698996caab075e333b2ca70fdeff8dedbe52b2.zip |
Merge branch 'develop-olympus' into develop
* develop-olympus:
[ticket/10428] Documentation for optionget/optionset functions.
[ticket/10428] Use phpbb_optionget/set in optionget/set for DRYness.
[ticket/10428] Dispose of $this->keyvalues cache for optionget.
[ticket/10428] Compare $data to false strictly.
Diffstat (limited to 'phpBB/includes')
-rw-r--r-- | phpBB/includes/acp/acp_users.php | 57 | ||||
-rw-r--r-- | phpBB/includes/session.php | 57 |
2 files changed, 66 insertions, 48 deletions
diff --git a/phpBB/includes/acp/acp_users.php b/phpBB/includes/acp/acp_users.php index 631d3bf272..48c5f44ae8 100644 --- a/phpBB/includes/acp/acp_users.php +++ b/phpBB/includes/acp/acp_users.php @@ -2339,46 +2339,61 @@ class acp_users } /** - * Optionset replacement for this module based on $user->optionset + * Set option bit field for user options in a user row array. + * + * Optionset replacement for this module based on $user->optionset. + * + * @param array $user_row Row from the users table. + * @param int $key Option key, as defined in $user->keyoptions property. + * @param bool $value True to set the option, false to clear the option. + * @param int $data Current bit field value, or false to use $user_row['user_options'] + * @return int|bool If $data is false, the bit field is modified and + * written back to $user_row['user_options'], and + * return value is true if the bit field changed and + * false otherwise. If $data is not false, the new + * bitfield value is returned. */ function optionset(&$user_row, $key, $value, $data = false) { global $user; - $var = ($data) ? $data : $user_row['user_options']; + $var = ($data !== false) ? $data : $user_row['user_options']; - if ($value && !($var & 1 << $user->keyoptions[$key])) - { - $var += 1 << $user->keyoptions[$key]; - } - else if (!$value && ($var & 1 << $user->keyoptions[$key])) - { - $var -= 1 << $user->keyoptions[$key]; - } - else - { - return ($data) ? $var : false; - } + $new_var = phpbb_optionset($user->keyoptions[$key], $value, $var); - if (!$data) + if ($data === false) { - $user_row['user_options'] = $var; - return true; + if ($new_var != $var) + { + $user_row['user_options'] = $new_var; + return true; + } + else + { + return false; + } } else { - return $var; + return $new_var; } } /** - * Optionget replacement for this module based on $user->optionget + * Get option bit field from user options in a user row array. + * + * Optionget replacement for this module based on $user->optionget. + * + * @param array $user_row Row from the users table. + * @param int $key option key, as defined in $user->keyoptions property. + * @param int $data bit field value to use, or false to use $user_row['user_options'] + * @return bool true if the option is set in the bit field, false otherwise */ function optionget(&$user_row, $key, $data = false) { global $user; - $var = ($data) ? $data : $user_row['user_options']; - return ($var & 1 << $user->keyoptions[$key]) ? true : false; + $var = ($data !== false) ? $data : $user_row['user_options']; + return phpbb_optionget($user->keyoptions[$key], $var); } } diff --git a/phpBB/includes/session.php b/phpBB/includes/session.php index fcbe8aed2c..f04326e97e 100644 --- a/phpBB/includes/session.php +++ b/phpBB/includes/session.php @@ -1539,7 +1539,6 @@ class user extends session // Able to add new options (up to id 31) var $keyoptions = array('viewimg' => 0, 'viewflash' => 1, 'viewsmilies' => 2, 'viewsigs' => 3, 'viewavatars' => 4, 'viewcensors' => 5, 'attachsig' => 6, 'bbcode' => 8, 'smilies' => 9, 'popuppm' => 10, 'sig_bbcode' => 15, 'sig_smilies' => 16, 'sig_links' => 17); - var $keyvalues = array(); /** * Constructor to set the lang path @@ -2242,47 +2241,51 @@ class user extends session } /** - * Get option bit field from user options + * Get option bit field from user options. + * + * @param int $key option key, as defined in $keyoptions property. + * @param int $data bit field value to use, or false to use $this->data['user_options'] + * @return bool true if the option is set in the bit field, false otherwise */ function optionget($key, $data = false) { - if (!isset($this->keyvalues[$key])) - { - $var = ($data) ? $data : $this->data['user_options']; - $this->keyvalues[$key] = ($var & 1 << $this->keyoptions[$key]) ? true : false; - } - - return $this->keyvalues[$key]; + $var = ($data !== false) ? $data : $this->data['user_options']; + return phpbb_optionget($this->keyoptions[$key], $var); } /** - * Set option bit field for user options + * Set option bit field for user options. + * + * @param int $key Option key, as defined in $keyoptions property. + * @param bool $value True to set the option, false to clear the option. + * @param int $data Current bit field value, or false to use $this->data['user_options'] + * @return int|bool If $data is false, the bit field is modified and + * written back to $this->data['user_options'], and + * return value is true if the bit field changed and + * false otherwise. If $data is not false, the new + * bitfield value is returned. */ function optionset($key, $value, $data = false) { - $var = ($data) ? $data : $this->data['user_options']; + $var = ($data !== false) ? $data : $this->data['user_options']; - if ($value && !($var & 1 << $this->keyoptions[$key])) - { - $var += 1 << $this->keyoptions[$key]; - } - else if (!$value && ($var & 1 << $this->keyoptions[$key])) - { - $var -= 1 << $this->keyoptions[$key]; - } - else - { - return ($data) ? $var : false; - } + $new_var = phpbb_optionset($this->keyoptions[$key], $value, $var); - if (!$data) + if ($data === false) { - $this->data['user_options'] = $var; - return true; + if ($new_var != $var) + { + $this->data['user_options'] = $new_var; + return true; + } + else + { + return false; + } } else { - return $var; + return $new_var; } } |