[ticket/572] Use json_decode/encode instead of serializing data
B3P-572
This commit is contained in:
@@ -21,6 +21,7 @@ class v210 extends \phpbb\db\migration\migration
|
|||||||
return array(
|
return array(
|
||||||
array('config.update', array('board3_portal_version', '2.1.0')),
|
array('config.update', array('board3_portal_version', '2.1.0')),
|
||||||
array('custom', array(array($this, 'add_donation_setting'))),
|
array('custom', array(array($this, 'add_donation_setting'))),
|
||||||
|
array('custom', array(array($this, 'convert_serialize_to_json'))),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -39,4 +40,66 @@ class v210 extends \phpbb\db\migration\migration
|
|||||||
}
|
}
|
||||||
$this->db->sql_freeresult($result);
|
$this->db->sql_freeresult($result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function convert_serialize_to_json()
|
||||||
|
{
|
||||||
|
if (!function_exists('obtain_portal_config'))
|
||||||
|
{
|
||||||
|
include ($this->phpbb_root_path . 'ext/board3/portal/includes/functions.' . $this->php_ext);
|
||||||
|
define('PORTAL_CONFIG_TABLE', $this->table_prefix . 'portal_config');
|
||||||
|
}
|
||||||
|
|
||||||
|
$portal_config = obtain_portal_config();
|
||||||
|
|
||||||
|
$sql = 'SELECT module_id, module_classname
|
||||||
|
FROM ' . $this->table_prefix . 'portal_modules
|
||||||
|
WHERE ' . $this->db->sql_in_set('module_classname', array(
|
||||||
|
'\board3\portal\modules\calendar',
|
||||||
|
'\board3\portal\modules\links',
|
||||||
|
'\board3\portal\modules\main_menu',
|
||||||
|
));
|
||||||
|
$result = $this->db->sql_query($sql);
|
||||||
|
while ($row = $this->db->sql_fetchrow($result))
|
||||||
|
{
|
||||||
|
switch ($row['module_classname'])
|
||||||
|
{
|
||||||
|
case '\board3\portal\modules\calendar':
|
||||||
|
$setting = 'board3_calendar_events_' . $row['module_id'];
|
||||||
|
break;
|
||||||
|
case '\board3\portal\modules\links':
|
||||||
|
$setting = 'board3_links_array_' . $row['module_id'];
|
||||||
|
break;
|
||||||
|
case '\board3\portal\modules\main_menu':
|
||||||
|
$setting = 'board3_menu_array_' . $row['module_id'];
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
// nothing
|
||||||
|
}
|
||||||
|
|
||||||
|
// Do not try to unserialize empty data
|
||||||
|
if (empty($setting) || empty($portal_config[$setting]))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save json encoded setting
|
||||||
|
set_portal_config($setting, json_encode($this->utf_unserialize($portal_config[$setting])));
|
||||||
|
}
|
||||||
|
$this->db->sql_freeresult($result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Unserialize links array
|
||||||
|
*
|
||||||
|
* @param string $serial_str Serialized string
|
||||||
|
*
|
||||||
|
* @return array Unserialized string
|
||||||
|
*/
|
||||||
|
private function utf_unserialize($serial_str)
|
||||||
|
{
|
||||||
|
$out = preg_replace_callback('!s:(\d+):"(.*?)";!s', function ($result) {
|
||||||
|
return 's:' . strlen($result[2]) . ":\"{$result[2]}\";";
|
||||||
|
}, $serial_str);
|
||||||
|
return unserialize($out);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -265,7 +265,7 @@ class calendar extends module_base
|
|||||||
* Let's start displaying the events
|
* Let's start displaying the events
|
||||||
* make sure we only display events in the future
|
* make sure we only display events in the future
|
||||||
*/
|
*/
|
||||||
$events = $this->utf_unserialize($portal_config['board3_calendar_events_' . $module_id]);
|
$events = json_decode($portal_config['board3_calendar_events_' . $module_id], true);
|
||||||
|
|
||||||
if (!empty($events) && $this->config['board3_display_events_' . $module_id])
|
if (!empty($events) && $this->config['board3_display_events_' . $module_id])
|
||||||
{
|
{
|
||||||
@@ -423,7 +423,7 @@ class calendar extends module_base
|
|||||||
$link_id = $this->request->variable('id', 99999999); // 0 will trigger unwanted behavior, therefore we set a number we should never reach
|
$link_id = $this->request->variable('id', 99999999); // 0 will trigger unwanted behavior, therefore we set a number we should never reach
|
||||||
$portal_config = obtain_portal_config();
|
$portal_config = obtain_portal_config();
|
||||||
|
|
||||||
$events = (strlen($portal_config['board3_calendar_events_' . $module_id]) >= 1) ? $this->utf_unserialize($portal_config['board3_calendar_events_' . $module_id]) : array();
|
$events = (strlen($portal_config['board3_calendar_events_' . $module_id]) >= 1) ? json_decode($portal_config['board3_calendar_events_' . $module_id], true) : array();
|
||||||
|
|
||||||
// append_sid() adds adm/ already, no need to add it here
|
// append_sid() adds adm/ already, no need to add it here
|
||||||
$u_action = append_sid('index.' . $this->php_ext, 'i=\board3\portal\acp\portal_module&mode=config&module_id=' . $module_id);
|
$u_action = append_sid('index.' . $this->php_ext, 'i=\board3\portal\acp\portal_module&mode=config&module_id=' . $module_id);
|
||||||
@@ -533,7 +533,7 @@ class calendar extends module_base
|
|||||||
$time_ary[$key] = $cur_event['start_time'];
|
$time_ary[$key] = $cur_event['start_time'];
|
||||||
}
|
}
|
||||||
array_multisort($time_ary, SORT_NUMERIC, $events);
|
array_multisort($time_ary, SORT_NUMERIC, $events);
|
||||||
$board3_events_array = serialize($events);
|
$board3_events_array = json_encode($events);
|
||||||
set_portal_config('board3_calendar_events_' . $module_id, $board3_events_array);
|
set_portal_config('board3_calendar_events_' . $module_id, $board3_events_array);
|
||||||
|
|
||||||
trigger_error($message . adm_back_link($u_action));
|
trigger_error($message . adm_back_link($u_action));
|
||||||
@@ -555,7 +555,7 @@ class calendar extends module_base
|
|||||||
array_splice($events, $link_id, 1);
|
array_splice($events, $link_id, 1);
|
||||||
$events = array_merge($events);
|
$events = array_merge($events);
|
||||||
|
|
||||||
$board3_events_array = serialize($events);
|
$board3_events_array = json_encode($events);
|
||||||
set_portal_config('board3_calendar_events_' . $module_id, $board3_events_array);
|
set_portal_config('board3_calendar_events_' . $module_id, $board3_events_array);
|
||||||
|
|
||||||
$this->log->add('admin', $this->user->data['user_id'], $this->user->data['user_ip'], 'LOG_PORTAL_EVENT_REMOVED', false, array($cur_event_title));
|
$this->log->add('admin', $this->user->data['user_id'], $this->user->data['user_ip'], 'LOG_PORTAL_EVENT_REMOVED', false, array($cur_event_title));
|
||||||
@@ -711,21 +711,6 @@ class calendar extends module_base
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Unserialize links array
|
|
||||||
*
|
|
||||||
* @param string $serial_str Serialized string
|
|
||||||
*
|
|
||||||
* @return array Unserialized string
|
|
||||||
*/
|
|
||||||
private function utf_unserialize($serial_str)
|
|
||||||
{
|
|
||||||
$out = preg_replace_callback('!s:(\d+):"(.*?)";!s', function ($result) {
|
|
||||||
return 's:' . strlen($result[2]) . ":\"{$result[2]}\";";
|
|
||||||
}, $serial_str);
|
|
||||||
return unserialize($out);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Validate URLs and execute apppend_sid if necessary
|
* Validate URLs and execute apppend_sid if necessary
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -111,7 +111,7 @@ class links extends module_base
|
|||||||
{
|
{
|
||||||
$portal_config = obtain_portal_config();
|
$portal_config = obtain_portal_config();
|
||||||
|
|
||||||
$links = $this->utf_unserialize($portal_config['board3_links_array_' . $module_id]);
|
$links = json_decode($portal_config['board3_links_array_' . $module_id], true);
|
||||||
|
|
||||||
// get user's groups
|
// get user's groups
|
||||||
$groups_ary = get_user_groups();
|
$groups_ary = get_user_groups();
|
||||||
@@ -200,7 +200,7 @@ class links extends module_base
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
$board3_menu_array = serialize($links);
|
$board3_menu_array = json_encode($links);
|
||||||
set_portal_config('board3_links_array_' . $module_id, $board3_menu_array);
|
set_portal_config('board3_links_array_' . $module_id, $board3_menu_array);
|
||||||
$this->config->set('board3_links_' . $module_id, '');
|
$this->config->set('board3_links_' . $module_id, '');
|
||||||
$this->config->set('board3_links_url_new_window_' . $module_id, 0);
|
$this->config->set('board3_links_url_new_window_' . $module_id, 0);
|
||||||
@@ -247,7 +247,7 @@ class links extends module_base
|
|||||||
$link_id = $this->request->variable('id', 99999999); // 0 will trigger unwanted behavior, therefore we set a number we should never reach
|
$link_id = $this->request->variable('id', 99999999); // 0 will trigger unwanted behavior, therefore we set a number we should never reach
|
||||||
$portal_config = obtain_portal_config();
|
$portal_config = obtain_portal_config();
|
||||||
|
|
||||||
$links = $this->utf_unserialize($portal_config['board3_links_array_' . $module_id]);
|
$links = json_decode($portal_config['board3_links_array_' . $module_id], true);
|
||||||
|
|
||||||
$u_action = append_sid('index.' . $this->php_ext, 'i=\board3\portal\acp\portal_module&mode=config&module_id=' . $module_id);
|
$u_action = append_sid('index.' . $this->php_ext, 'i=\board3\portal\acp\portal_module&mode=config&module_id=' . $module_id);
|
||||||
|
|
||||||
@@ -319,7 +319,7 @@ class links extends module_base
|
|||||||
$this->log->add('admin', $this->user->data['user_id'], $this->user->data['user_ip'],'LOG_PORTAL_LINK_ADDED', false, array($link_title));
|
$this->log->add('admin', $this->user->data['user_id'], $this->user->data['user_ip'],'LOG_PORTAL_LINK_ADDED', false, array($link_title));
|
||||||
}
|
}
|
||||||
|
|
||||||
$board3_links_array = serialize($links);
|
$board3_links_array = json_encode($links);
|
||||||
set_portal_config('board3_links_array_' . $module_id, $board3_links_array);
|
set_portal_config('board3_links_array_' . $module_id, $board3_links_array);
|
||||||
|
|
||||||
trigger_error($message . adm_back_link($u_action));
|
trigger_error($message . adm_back_link($u_action));
|
||||||
@@ -341,7 +341,7 @@ class links extends module_base
|
|||||||
array_splice($links, $link_id, 1);
|
array_splice($links, $link_id, 1);
|
||||||
$links = array_merge($links);
|
$links = array_merge($links);
|
||||||
|
|
||||||
$board3_links_array = serialize($links);
|
$board3_links_array = json_encode($links);
|
||||||
set_portal_config('board3_links_array_' . $module_id, $board3_links_array);
|
set_portal_config('board3_links_array_' . $module_id, $board3_links_array);
|
||||||
|
|
||||||
$this->log->add('admin', $this->user->data['user_id'], $this->user->data['user_ip'], 'LOG_PORTAL_LINK_REMOVED', false, array($cur_link_title));
|
$this->log->add('admin', $this->user->data['user_id'], $this->user->data['user_ip'], 'LOG_PORTAL_LINK_REMOVED', false, array($cur_link_title));
|
||||||
@@ -397,7 +397,7 @@ class links extends module_base
|
|||||||
// insert the info of the moved link
|
// insert the info of the moved link
|
||||||
$links[$switch_order_id] = $cur_link;
|
$links[$switch_order_id] = $cur_link;
|
||||||
|
|
||||||
$board3_links_array = serialize($links);
|
$board3_links_array = json_encode($links);
|
||||||
set_portal_config('board3_links_array_' . $module_id, $board3_links_array);
|
set_portal_config('board3_links_array_' . $module_id, $board3_links_array);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
@@ -460,19 +460,4 @@ class links extends module_base
|
|||||||
{
|
{
|
||||||
$this->manage_links('', $key, $module_id);
|
$this->manage_links('', $key, $module_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Unserialize links array
|
|
||||||
*
|
|
||||||
* @param string $serial_str Serialized string
|
|
||||||
*
|
|
||||||
* @return array Unserialized string
|
|
||||||
*/
|
|
||||||
private function utf_unserialize($serial_str)
|
|
||||||
{
|
|
||||||
$out = preg_replace_callback('!s:(\d+):"(.*?)";!s', function ($result) {
|
|
||||||
return 's:' . strlen($result[2]) . ":\"{$result[2]}\";";
|
|
||||||
}, $serial_str);
|
|
||||||
return unserialize($out);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -112,7 +112,7 @@ class main_menu extends module_base
|
|||||||
{
|
{
|
||||||
$portal_config = obtain_portal_config();
|
$portal_config = obtain_portal_config();
|
||||||
|
|
||||||
$links = $this->utf_unserialize($portal_config['board3_menu_array_' . $module_id]);
|
$links = json_decode($portal_config['board3_menu_array_' . $module_id], true);
|
||||||
|
|
||||||
$this->template->assign_block_vars('portal_menu', array('MODULE_ID' => $module_id));
|
$this->template->assign_block_vars('portal_menu', array('MODULE_ID' => $module_id));
|
||||||
|
|
||||||
@@ -255,7 +255,7 @@ class main_menu extends module_base
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
$board3_menu_array = serialize($links);
|
$board3_menu_array = json_encode($links);
|
||||||
set_portal_config('board3_menu_array_' . $module_id, $board3_menu_array);
|
set_portal_config('board3_menu_array_' . $module_id, $board3_menu_array);
|
||||||
$this->config->set('board3_menu_' . $module_id, '');
|
$this->config->set('board3_menu_' . $module_id, '');
|
||||||
$this->config->set('board3_menu_url_new_window_' . $module_id, 0);
|
$this->config->set('board3_menu_url_new_window_' . $module_id, 0);
|
||||||
@@ -302,7 +302,7 @@ class main_menu extends module_base
|
|||||||
$link_id = $this->request->variable('id', 99999999); // 0 will trigger unwanted behavior, therefore we set a number we should never reach
|
$link_id = $this->request->variable('id', 99999999); // 0 will trigger unwanted behavior, therefore we set a number we should never reach
|
||||||
$portal_config = obtain_portal_config();
|
$portal_config = obtain_portal_config();
|
||||||
|
|
||||||
$links = $this->utf_unserialize($portal_config['board3_menu_array_' . $module_id]);
|
$links = json_decode($portal_config['board3_menu_array_' . $module_id], true);
|
||||||
|
|
||||||
$u_action = append_sid('index.' . $this->php_ext, 'i=%5Cboard3%5Cportal%5Cacp%5Cportal_module&mode=config&module_id=' . $module_id);
|
$u_action = append_sid('index.' . $this->php_ext, 'i=%5Cboard3%5Cportal%5Cacp%5Cportal_module&mode=config&module_id=' . $module_id);
|
||||||
|
|
||||||
@@ -379,7 +379,7 @@ class main_menu extends module_base
|
|||||||
$this->log->add('admin', $this->user->data['user_id'], $this->user->data['user_ip'], 'LOG_PORTAL_LINK_ADDED', false, array($link_title));
|
$this->log->add('admin', $this->user->data['user_id'], $this->user->data['user_ip'], 'LOG_PORTAL_LINK_ADDED', false, array($link_title));
|
||||||
}
|
}
|
||||||
|
|
||||||
$board3_menu_array = serialize($links);
|
$board3_menu_array = json_encode($links);
|
||||||
set_portal_config('board3_menu_array_' . $module_id, $board3_menu_array);
|
set_portal_config('board3_menu_array_' . $module_id, $board3_menu_array);
|
||||||
|
|
||||||
trigger_error($message . adm_back_link($u_action));
|
trigger_error($message . adm_back_link($u_action));
|
||||||
@@ -401,7 +401,7 @@ class main_menu extends module_base
|
|||||||
array_splice($links, $link_id, 1);
|
array_splice($links, $link_id, 1);
|
||||||
$links = array_merge($links);
|
$links = array_merge($links);
|
||||||
|
|
||||||
$board3_menu_array = serialize($links);
|
$board3_menu_array = json_encode($links);
|
||||||
set_portal_config('board3_menu_array_' . $module_id, $board3_menu_array);
|
set_portal_config('board3_menu_array_' . $module_id, $board3_menu_array);
|
||||||
|
|
||||||
$this->log->add('admin', $this->user->data['user_id'], $this->user->data['user_ip'], 'LOG_PORTAL_LINK_REMOVED', false, array($cur_link_title));
|
$this->log->add('admin', $this->user->data['user_id'], $this->user->data['user_ip'], 'LOG_PORTAL_LINK_REMOVED', false, array($cur_link_title));
|
||||||
@@ -457,7 +457,7 @@ class main_menu extends module_base
|
|||||||
// insert the info of the moved link
|
// insert the info of the moved link
|
||||||
$links[$switch_order_id] = $cur_link;
|
$links[$switch_order_id] = $cur_link;
|
||||||
|
|
||||||
$board3_menu_array = serialize($links);
|
$board3_menu_array = json_encode($links);
|
||||||
set_portal_config('board3_menu_array_' . $module_id, $board3_menu_array);
|
set_portal_config('board3_menu_array_' . $module_id, $board3_menu_array);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
@@ -524,19 +524,4 @@ class main_menu extends module_base
|
|||||||
{
|
{
|
||||||
$this->manage_links('', $key, $module_id);
|
$this->manage_links('', $key, $module_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Unserialize links array
|
|
||||||
*
|
|
||||||
* @param string $serial_str Serialized string
|
|
||||||
*
|
|
||||||
* @return array Unserialized string
|
|
||||||
*/
|
|
||||||
private function utf_unserialize($serial_str)
|
|
||||||
{
|
|
||||||
$out = preg_replace_callback('!s:(\d+):"(.*?)";!s', function ($result) {
|
|
||||||
return 's:' . strlen($result[2]) . ":\"{$result[2]}\";";
|
|
||||||
}, $serial_str);
|
|
||||||
return unserialize($out);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user