summaryrefslogtreecommitdiff
path: root/inc/common.php
diff options
context:
space:
mode:
authorChristopher Smith <chris@jalakai.co.uk>2013-02-03 13:26:12 -0800
committerChristopher Smith <chris@jalakai.co.uk>2013-02-03 13:26:12 -0800
commit2509b6f19785d4c179c3957c17bdde2e2e9d0149 (patch)
tree4ab13af08e8d769e6ef2931579eae282cc0fff49 /inc/common.php
parent6ecd102555022984aa926a4d423a98c775a06ca4 (diff)
parent646a531a33fe5c5e32a932e2a889c43702505c48 (diff)
downloadrpg-2509b6f19785d4c179c3957c17bdde2e2e9d0149.tar.gz
rpg-2509b6f19785d4c179c3957c17bdde2e2e9d0149.tar.bz2
Merge pull request #164 from splitbrain/diff_recent_prefs
store choices for recent changes and diff views in cookie
Diffstat (limited to 'inc/common.php')
-rw-r--r--inc/common.php38
1 files changed, 35 insertions, 3 deletions
diff --git a/inc/common.php b/inc/common.php
index db39affc6..28b527633 100644
--- a/inc/common.php
+++ b/inc/common.php
@@ -1551,18 +1551,50 @@ function valid_input_set($param, $valid_values, $array, $exc = '') {
/**
* Read a preference from the DokuWiki cookie
+ * (remembering both keys & values are urlencoded)
*/
function get_doku_pref($pref, $default) {
- if(strpos($_COOKIE['DOKU_PREFS'], $pref) !== false) {
+ $enc_pref = urlencode($pref);
+ if(strpos($_COOKIE['DOKU_PREFS'], $enc_pref) !== false) {
$parts = explode('#', $_COOKIE['DOKU_PREFS']);
$cnt = count($parts);
for($i = 0; $i < $cnt; $i += 2) {
- if($parts[$i] == $pref) {
- return $parts[$i + 1];
+ if($parts[$i] == $enc_pref) {
+ return urldecode($parts[$i + 1]);
}
}
}
return $default;
}
+/**
+ * Add a preference to the DokuWiki cookie
+ * (remembering $_COOKIE['DOKU_PREFS'] is urlencoded)
+ */
+function set_doku_pref($pref, $val) {
+ global $conf;
+ $orig = get_doku_pref($pref, false);
+ $cookieVal = '';
+
+ if($orig && ($orig != $val)) {
+ $parts = explode('#', $_COOKIE['DOKU_PREFS']);
+ $cnt = count($parts);
+ // urlencode $pref for the comparison
+ $enc_pref = rawurlencode($pref);
+ for($i = 0; $i < $cnt; $i += 2) {
+ if($parts[$i] == $enc_pref) {
+ $parts[$i + 1] = rawurlencode($val);
+ break;
+ }
+ }
+ $cookieVal = implode('#', $parts);
+ } else if (!$orig) {
+ $cookieVal = ($_COOKIE['DOKU_PREFS'] ? $_COOKIE['DOKU_PREFS'].'#' : '').rawurlencode($pref).'#'.rawurlencode($val);
+ }
+
+ if (!empty($cookieVal)) {
+ setcookie('DOKU_PREFS', $cookieVal, time()+365*24*3600, DOKU_BASE, '', ($conf['securecookie'] && is_ssl()));
+ }
+}
+
//Setup VIM: ex: et ts=2 :