Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

#81 Serialize block options

Patches
closed
Jan Pedersen
5
2012-09-25
2004-12-27
Jan Pedersen
No

I think it would be a better solution to serialize
block options prior to saving them in the database
instead of as now, where they are imploded with a
delimiting |

Files affected would be:
modules/system/admin/blocksadmin/blocksadmin.php around
line 256, where

if (isset($options)) {
$options_count = count($options);
if ($options_count > 0) {
//Convert array values to comma-separated
for ( $i = 0; $i < $options_count; $i++ ) {
if (is_array($options[$i])) {
$options[$i] = implode(',', $options[$i]);
}
}
$options = implode('|', $options);
$myblock->setVar('options', $options);
}
}

should be changed to

if (isset($options)) {
$options_count = count($options);
if ($options_count > 0) {
$options = serialize($options);
$myblock->setVar('options', $options);
}
}

and when editing a block:
in the getOptions() method in class/xoopsblock.php line
260:
$options = explode("|", $this->getVar("options"));

changed to
$options = unserialize($this->getVar("options"));

And for displaying the block properly, in
class/xoopsblock.php, buildBlock() method line 186:
$options = explode("|", $this->getVar("options"));

changed to
$options = unserialize($this->getVar("options"));

Discussion

  • Jan Pedersen
    Jan Pedersen
    2004-12-27

    Logged In: YES
    user_id=841117

    Whoops - forgot to think about module
    installation/update/uninstallation

    modules/system/admin/modulesadmin/modulesadmin.php:
    line 277:

    Change
    $options = trim($block['options']);

    to
    $options = serialize(explode('|', trim($block['options'])));

    And in modules/system/admin/modulesadmin/main.php, line 345:
    change
    $options = $blocks[$i]['options'];

    to
    $options = serialize(explode('|',
    trim($blocks[$i]['options'])));

     
  • Jan Pedersen
    Jan Pedersen
    2004-12-27

    Logged In: YES
    user_id=841117

    Fixed in CVS and waiting for review before merging to the trunk.