diff options
author | Andreas Fischer <bantu@phpbb.com> | 2011-12-25 15:12:03 +0100 |
---|---|---|
committer | Andreas Fischer <bantu@phpbb.com> | 2011-12-25 15:12:03 +0100 |
commit | b0fd3b2bf092658290db7eb062a3e25899fb5dec (patch) | |
tree | 5139305609f6e1d1b4ad43e56687fc2a7228e353 | |
parent | ccd2ca55d49d71ad693e821dcfbf509cfcf936bd (diff) | |
parent | 10453b67525a0e26a3c859df4dab46907189af72 (diff) | |
download | forums-b0fd3b2bf092658290db7eb062a3e25899fb5dec.tar forums-b0fd3b2bf092658290db7eb062a3e25899fb5dec.tar.gz forums-b0fd3b2bf092658290db7eb062a3e25899fb5dec.tar.bz2 forums-b0fd3b2bf092658290db7eb062a3e25899fb5dec.tar.xz forums-b0fd3b2bf092658290db7eb062a3e25899fb5dec.zip |
Merge remote-tracking branch 'p/ticket/10428' into develop-olympus
* p/ticket/10428:
[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.
-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 4f58434a43..363c900edc 100644 --- a/phpBB/includes/acp/acp_users.php +++ b/phpBB/includes/acp/acp_users.php @@ -2339,47 +2339,62 @@ 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 caadcbafaa..a894242a39 100644 --- a/phpBB/includes/session.php +++ b/phpBB/includes/session.php @@ -1507,7 +1507,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 @@ -2337,47 +2336,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; } } |