mirror of
https://github.com/e107inc/e107.git
synced 2025-08-09 16:17:14 +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:
@@ -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);
|
||||
}
|
||||
|
Reference in New Issue
Block a user