mirror of
https://github.com/e107inc/e107.git
synced 2025-04-21 05:02:02 +02:00
Fixes #2037 Menu-Cache encoding changed to json for more reliable handling of array data. Error catching added on eval() code with syntax errors when PHP7 is being used.
This commit is contained in:
parent
cae2b0721e
commit
74221c1cd5
@ -412,7 +412,7 @@ if (!function_exists('multiarray_sort'))
|
||||
class e_array {
|
||||
|
||||
/**
|
||||
* Returns an array from stored array data.
|
||||
* Returns an array from stored array data in php serialized, e107 var_export and json-encoded data.
|
||||
*
|
||||
* @param string $ArrayData
|
||||
* @return array stored data
|
||||
@ -429,12 +429,31 @@ class e_array {
|
||||
}
|
||||
|
||||
// Saftety mechanism for 0.7 -> 0.8 transition.
|
||||
if(substr($ArrayData,0,2)=='a:' || substr($ArrayData,0,2)=='s:')
|
||||
if(substr($ArrayData,0,2)=='a:' || substr($ArrayData,0,2)=='s:') // php serialize.
|
||||
{
|
||||
$dat = unserialize($ArrayData);
|
||||
$ArrayData = $this->WriteArray($dat,FALSE);
|
||||
}
|
||||
|
||||
if(substr($ArrayData,0,1) === '{' || substr($ArrayData,0,1) === '[') // json
|
||||
{
|
||||
$dat = json_decode($ArrayData, true);
|
||||
|
||||
// e107::getDebug()->log("Json data found");
|
||||
|
||||
if(json_last_error() != JSON_ERROR_NONE && (e_DEBUG === true))
|
||||
{
|
||||
echo "<div class='alert alert-danger'><h4>e107::unserialize() Parser Error (json)</h4></div>";
|
||||
echo "<pre>";
|
||||
debug_print_backtrace();
|
||||
echo "</pre>";
|
||||
}
|
||||
|
||||
return $dat;
|
||||
}
|
||||
|
||||
// below is var_export() format using eval();
|
||||
|
||||
$ArrayData = trim($ArrayData);
|
||||
|
||||
if(strtolower(substr($ArrayData,0,5)) != 'array')
|
||||
@ -461,13 +480,43 @@ class e_array {
|
||||
$data = "";
|
||||
$ArrayData = '$data = '.$ArrayData.';';
|
||||
|
||||
if(PHP_MAJOR_VERSION > 6) // catch parser error.
|
||||
{
|
||||
try
|
||||
{
|
||||
@eval($ArrayData);
|
||||
}
|
||||
catch (ParseError $e)
|
||||
{
|
||||
|
||||
if(e_DEBUG === true)
|
||||
{
|
||||
$message = $e->getMessage();
|
||||
$message .= print_a($ArrayData,true);
|
||||
echo "<div class='alert alert-danger'><h4>e107::unserialize() Parser Error</h4>". $message. "</div>";
|
||||
echo "<pre>";
|
||||
debug_print_backtrace();
|
||||
echo "</pre>";
|
||||
}
|
||||
|
||||
return array();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@eval($ArrayData);
|
||||
if (!isset($data) || !is_array($data))
|
||||
{
|
||||
trigger_error("Bad stored array data - <br /><br />".htmlentities($ArrayData), E_USER_ERROR);
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@eval($ArrayData);
|
||||
if (!isset($data) || !is_array($data))
|
||||
{
|
||||
trigger_error("Bad stored array data - <br /><br />".htmlentities($ArrayData), E_USER_ERROR);
|
||||
return false;
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
@ -476,18 +525,24 @@ class e_array {
|
||||
* Return a string containg exported array data.
|
||||
*
|
||||
* @param array $ArrayData array to be stored
|
||||
* @param bool $AddSlashes default true, add slashes for db storage, else false
|
||||
* @param bool|string $mode true = var_export with addedslashes, false = var_export (default), 'json' = json encoded
|
||||
* @return string
|
||||
*/
|
||||
public function serialize($ArrayData, $AddSlashes = false)
|
||||
public function serialize($ArrayData, $mode = false)
|
||||
{
|
||||
if (!is_array($ArrayData)) {
|
||||
if (!is_array($ArrayData) || empty($ArrayData))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if($mode === 'json')
|
||||
{
|
||||
return json_encode($ArrayData, JSON_PRETTY_PRINT);
|
||||
}
|
||||
|
||||
$Array = var_export($ArrayData, true);
|
||||
|
||||
if ($AddSlashes == true)
|
||||
if ($mode == true)
|
||||
{
|
||||
$Array = addslashes($Array);
|
||||
}
|
||||
|
@ -222,19 +222,19 @@ class e_menu
|
||||
$menu_layout_field = THEME_LAYOUT!=e107::getPref('sitetheme_deflayout') ? THEME_LAYOUT : "";
|
||||
|
||||
// e107::getCache()->CachePageMD5 = md5(e_LANGUAGE.$menu_layout_field); // Disabled by line 93 of Cache class.
|
||||
//FIXME add a function to the cache class for this.
|
||||
|
||||
$menu_data = e107::getCache()->retrieve_sys("menus_".USERCLASS_LIST."_".md5(e_LANGUAGE.$menu_layout_field));
|
||||
// $menu_data = e107::getCache()->retrieve_sys("menus_".USERCLASS_LIST);
|
||||
$menu_data = e107::getArrayStorage()->ReadArray($menu_data);
|
||||
// $menu_data = e107::getArrayStorage()->ReadArray($menu_data);
|
||||
|
||||
//FIXME add a function to the cache class for this.
|
||||
|
||||
$cacheData = e107::getCache()->retrieve_sys("menus_".USERCLASS_LIST."_".md5(e_LANGUAGE.$menu_layout_field));
|
||||
|
||||
// $menu_data = json_decode($cacheData,true);
|
||||
$menu_data = e107::unserialize($cacheData);
|
||||
|
||||
$eMenuArea = array();
|
||||
// $eMenuList = array();
|
||||
// $eMenuActive = array(); // DEPRECATED
|
||||
|
||||
|
||||
if(!is_array($menu_data))
|
||||
if(empty($menu_data) || !is_array($menu_data))
|
||||
{
|
||||
$menu_qry = 'SELECT * FROM #menus WHERE menu_location > 0 AND menu_class IN ('.USERCLASS_LIST.') AND menu_layout = "'.$menu_layout_field.'" ORDER BY menu_location,menu_order';
|
||||
|
||||
@ -247,10 +247,9 @@ class e_menu
|
||||
}
|
||||
|
||||
$menu_data['menu_area'] = $eMenuArea;
|
||||
|
||||
$menuData = e107::getArrayStorage()->WriteArray($menu_data, false);
|
||||
|
||||
// e107::getCache()->set_sys('menus_'.USERCLASS_LIST, $menuData);
|
||||
|
||||
$menuData = e107::serialize($menu_data,'json');
|
||||
|
||||
e107::getCache()->set_sys('menus_'.USERCLASS_LIST.'_'.md5(e_LANGUAGE.$menu_layout_field), $menuData);
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user