Skip to content

Commit 9992f93

Browse files
committed
Use json for serialization
1 parent 90d956a commit 9992f93

File tree

3 files changed

+20
-7
lines changed

3 files changed

+20
-7
lines changed

lib/Ftree/Prefs/Expanded.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,12 @@ public function __construct()
4141
{
4242
global $prefs;
4343

44-
if (($folders = @unserialize($prefs->getValue('expanded_folders'), array('allowed_classes' => false))) &&
45-
is_array($folders)) {
44+
$value = $prefs->getValue('expanded_folders');
45+
$folders = $value ? json_decode($value, true) : array();
46+
if (null === $folders && json_last_error() === JSON_ERROR_SYNTAX) {
47+
$folders = @unserialize($value, array('allowed_classes' => false));
48+
}
49+
if (is_array($folders)) {
4650
$this->_data = $folders;
4751
}
4852

@@ -54,7 +58,7 @@ public function __construct()
5458
*/
5559
public function shutdown()
5660
{
57-
$GLOBALS['prefs']->setValue('expanded_folders', serialize($this->_data));
61+
$GLOBALS['prefs']->setValue('expanded_folders', json_encode($this->_data, JSON_FORCE_OBJECT));
5862
}
5963

6064
/**

lib/Ftree/Prefs/Poll.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,12 @@ public function __construct(IMP_Ftree $ftree)
4747
$this->_data = array('INBOX' => 1);
4848

4949
/* Add the list of polled mailboxes from the prefs. */
50-
if ($nav_poll = @unserialize($prefs->getValue('nav_poll'), array('allowed_classes' => false))) {
50+
$value = $prefs->getValue('nav_poll');
51+
$nav_poll = $value ? json_decode($value, true) : array();
52+
if (null === $nav_poll && json_last_error() === JSON_ERROR_SYNTAX) {
53+
$nav_poll = @unserialize($value, array('allowed_classes' => false));
54+
}
55+
if ($nav_poll) {
5156
$this->_data += $nav_poll;
5257
}
5358

@@ -59,7 +64,7 @@ public function __construct(IMP_Ftree $ftree)
5964
*/
6065
public function shutdown()
6166
{
62-
$GLOBALS['prefs']->setValue('nav_poll', serialize($this->_data));
67+
$GLOBALS['prefs']->setValue('nav_poll', json_encode($this->_data, JSON_FORCE_OBJECT));
6368
}
6469

6570
/**

lib/Prefs/Sort.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,11 @@ public function __construct()
3939
{
4040
global $prefs;
4141

42-
$sortpref = @unserialize($prefs->getValue(self::SORTPREF), array('allowed_classes' => false));
42+
$value = $prefs->getValue(self::SORTPREF);
43+
$sortpref = $value ? json_decode($value, true) : array();
44+
if (null === $sortpref && json_last_error() === JSON_ERROR_SYNTAX) {
45+
$sortpref = @unserialize($value, array('allowed_classes' => false));
46+
}
4347
if (is_array($sortpref)) {
4448
$this->_sortpref = $sortpref;
4549
}
@@ -106,7 +110,7 @@ public function newSortbyValue($sortby)
106110
*/
107111
protected function _save()
108112
{
109-
$GLOBALS['prefs']->setValue(self::SORTPREF, serialize($this->_sortpref));
113+
$GLOBALS['prefs']->setValue(self::SORTPREF, json_encode($this->_sortpref, JSON_FORCE_OBJECT));
110114
}
111115

112116
/* ArrayAccess methods. */

0 commit comments

Comments
 (0)