Skip to content

Commit

Permalink
Use json for serialization
Browse files Browse the repository at this point in the history
  • Loading branch information
xgin committed Nov 22, 2021
1 parent 90d956a commit 2682273
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
11 changes: 8 additions & 3 deletions lib/Ftree/Prefs/Expanded.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,13 @@ public function __construct()
{
global $prefs;

if (($folders = @unserialize($prefs->getValue('expanded_folders'), array('allowed_classes' => false))) &&
is_array($folders)) {
$value = $prefs->getValue('expanded_folders');
$folders = $value ? json_decode($value, true) : array();
if (null === $folders && json_last_error() === JSON_ERROR_SYNTAX) {
// TODO: Remove backward compatibility with stored values
$folders = @unserialize($value, array('allowed_classes' => false));
}
if (is_array($folders)) {
$this->_data = $folders;
}

Expand All @@ -54,7 +59,7 @@ public function __construct()
*/
public function shutdown()
{
$GLOBALS['prefs']->setValue('expanded_folders', serialize($this->_data));
$GLOBALS['prefs']->setValue('expanded_folders', json_encode($this->_data, JSON_FORCE_OBJECT));
}

/**
Expand Down
10 changes: 8 additions & 2 deletions lib/Ftree/Prefs/Poll.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,13 @@ public function __construct(IMP_Ftree $ftree)
$this->_data = array('INBOX' => 1);

/* Add the list of polled mailboxes from the prefs. */
if ($nav_poll = @unserialize($prefs->getValue('nav_poll'), array('allowed_classes' => false))) {
$value = $prefs->getValue('nav_poll');
$nav_poll = $value ? json_decode($value, true) : array();
if (null === $nav_poll && json_last_error() === JSON_ERROR_SYNTAX) {
// TODO: Remove backward compatibility with stored values
$nav_poll = @unserialize($value, array('allowed_classes' => false));
}
if ($nav_poll) {
$this->_data += $nav_poll;
}

Expand All @@ -59,7 +65,7 @@ public function __construct(IMP_Ftree $ftree)
*/
public function shutdown()
{
$GLOBALS['prefs']->setValue('nav_poll', serialize($this->_data));
$GLOBALS['prefs']->setValue('nav_poll', json_encode($this->_data, JSON_FORCE_OBJECT));
}

/**
Expand Down
9 changes: 7 additions & 2 deletions lib/Prefs/Sort.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,12 @@ public function __construct()
{
global $prefs;

$sortpref = @unserialize($prefs->getValue(self::SORTPREF), array('allowed_classes' => false));
$value = $prefs->getValue(self::SORTPREF);
$sortpref = $value ? json_decode($value, true) : array();
if (null === $sortpref && json_last_error() === JSON_ERROR_SYNTAX) {
// TODO: Remove backward compatibility with stored values
$sortpref = @unserialize($value, array('allowed_classes' => false));
}
if (is_array($sortpref)) {
$this->_sortpref = $sortpref;
}
Expand Down Expand Up @@ -106,7 +111,7 @@ public function newSortbyValue($sortby)
*/
protected function _save()
{
$GLOBALS['prefs']->setValue(self::SORTPREF, serialize($this->_sortpref));
$GLOBALS['prefs']->setValue(self::SORTPREF, json_encode($this->_sortpref, JSON_FORCE_OBJECT));
}

/* ArrayAccess methods. */
Expand Down

0 comments on commit 2682273

Please sign in to comment.