aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/includes/session.php
diff options
context:
space:
mode:
authorAndreas Fischer <bantu@phpbb.com>2011-12-25 15:12:03 +0100
committerAndreas Fischer <bantu@phpbb.com>2011-12-25 15:12:03 +0100
commitb0fd3b2bf092658290db7eb062a3e25899fb5dec (patch)
tree5139305609f6e1d1b4ad43e56687fc2a7228e353 /phpBB/includes/session.php
parentccd2ca55d49d71ad693e821dcfbf509cfcf936bd (diff)
parent10453b67525a0e26a3c859df4dab46907189af72 (diff)
downloadforums-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.
Diffstat (limited to 'phpBB/includes/session.php')
-rw-r--r--phpBB/includes/session.php57
1 files changed, 30 insertions, 27 deletions
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;
}
}