forked from Wavyzz/dolibarr
Fix: carriage return
This commit is contained in:
@@ -25,60 +25,60 @@
|
||||
|
||||
if (! function_exists('json_encode'))
|
||||
{
|
||||
/**
|
||||
* Implement json_encode for PHP that does not support it
|
||||
*
|
||||
* @param mixed $elements PHP Object to json encode
|
||||
* @return string Json encoded string
|
||||
*/
|
||||
function json_encode($elements)
|
||||
/**
|
||||
* Implement json_encode for PHP that does not support it
|
||||
*
|
||||
* @param mixed $elements PHP Object to json encode
|
||||
* @return string Json encoded string
|
||||
*/
|
||||
function json_encode($elements)
|
||||
{
|
||||
return dol_json_encode($elements);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implement json_encode for PHP that does not support it
|
||||
*
|
||||
* @param mixed $elements PHP Object to json encode
|
||||
* @return string Json encoded string
|
||||
*/
|
||||
function dol_json_encode($elements)
|
||||
{
|
||||
$num = count($elements);
|
||||
|
||||
// determine type
|
||||
if (is_numeric(key($elements)))
|
||||
{
|
||||
// indexed (list)
|
||||
$output = '[';
|
||||
for ($i = 0, $last = ($num - 1); isset($elements[$i]); ++$i)
|
||||
{
|
||||
if (is_array($elements[$i])) $output.= json_encode($elements[$i]);
|
||||
else $output .= _val($elements[$i]);
|
||||
if($i !== $last) $output.= ',';
|
||||
}
|
||||
$output.= ']';
|
||||
}
|
||||
else
|
||||
{
|
||||
// associative (object)
|
||||
$output = '{';
|
||||
$last = $num - 1;
|
||||
$i = 0;
|
||||
foreach($elements as $key => $value)
|
||||
{
|
||||
$output .= '"'.$key.'":';
|
||||
if (is_array($value)) $output.= json_encode($value);
|
||||
else $output .= _val($value);
|
||||
if ($i !== $last) $output.= ',';
|
||||
++$i;
|
||||
}
|
||||
$output.= '}';
|
||||
}
|
||||
|
||||
// return
|
||||
return $output;
|
||||
/**
|
||||
* Implement json_encode for PHP that does not support it
|
||||
*
|
||||
* @param mixed $elements PHP Object to json encode
|
||||
* @return string Json encoded string
|
||||
*/
|
||||
function dol_json_encode($elements)
|
||||
{
|
||||
$num = count($elements);
|
||||
|
||||
// determine type
|
||||
if (is_numeric(key($elements)))
|
||||
{
|
||||
// indexed (list)
|
||||
$output = '[';
|
||||
for ($i = 0, $last = ($num - 1); isset($elements[$i]); ++$i)
|
||||
{
|
||||
if (is_array($elements[$i])) $output.= json_encode($elements[$i]);
|
||||
else $output .= _val($elements[$i]);
|
||||
if($i !== $last) $output.= ',';
|
||||
}
|
||||
$output.= ']';
|
||||
}
|
||||
else
|
||||
{
|
||||
// associative (object)
|
||||
$output = '{';
|
||||
$last = $num - 1;
|
||||
$i = 0;
|
||||
foreach($elements as $key => $value)
|
||||
{
|
||||
$output .= '"'.$key.'":';
|
||||
if (is_array($value)) $output.= json_encode($value);
|
||||
else $output .= _val($value);
|
||||
if ($i !== $last) $output.= ',';
|
||||
++$i;
|
||||
}
|
||||
$output.= '}';
|
||||
}
|
||||
|
||||
// return
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -189,69 +189,69 @@ function _val($val)
|
||||
|
||||
if (! function_exists('json_decode'))
|
||||
{
|
||||
/**
|
||||
* Implement json_decode for PHP that does not support it
|
||||
*
|
||||
* @param string $json Json encoded to PHP Object or Array
|
||||
* @param bool $assoc False return an object, true return an array
|
||||
* @return mixed Object or Array
|
||||
*/
|
||||
function json_decode($json, $assoc=false)
|
||||
/**
|
||||
* Implement json_decode for PHP that does not support it
|
||||
*
|
||||
* @param string $json Json encoded to PHP Object or Array
|
||||
* @param bool $assoc False return an object, true return an array
|
||||
* @return mixed Object or Array
|
||||
*/
|
||||
function json_decode($json, $assoc=false)
|
||||
{
|
||||
return dol_json_decode($json, $assoc);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implement json_decode for PHP that does not support it
|
||||
*
|
||||
* @param string $json Json encoded to PHP Object or Array
|
||||
* @param bool $assoc False return an object, true return an array
|
||||
* @return mixed Object or Array
|
||||
*/
|
||||
function dol_json_decode($json, $assoc=false)
|
||||
{
|
||||
$comment = false;
|
||||
|
||||
$strLength = strlen($json); // Must stay strlen and not dol_strlen because we want technical length, not visible length
|
||||
for ($i=0; $i<$strLength; $i++)
|
||||
{
|
||||
if (! $comment)
|
||||
{
|
||||
if (($json[$i] == '{') || ($json[$i] == '[')) $out.= 'array(';
|
||||
else if (($json[$i] == '}') || ($json[$i] == ']')) $out.= ')';
|
||||
else if ($json[$i] == ':') $out.= ' => ';
|
||||
else $out.=$json[$i];
|
||||
}
|
||||
else $out.= $json[$i];
|
||||
if ($json[$i] == '"' && $json[($i-1)]!="\\") $comment = !$comment;
|
||||
}
|
||||
|
||||
$out=_unval($out);
|
||||
|
||||
// Return an array
|
||||
/**
|
||||
* Implement json_decode for PHP that does not support it
|
||||
*
|
||||
* @param string $json Json encoded to PHP Object or Array
|
||||
* @param bool $assoc False return an object, true return an array
|
||||
* @return mixed Object or Array
|
||||
*/
|
||||
function dol_json_decode($json, $assoc=false)
|
||||
{
|
||||
$comment = false;
|
||||
|
||||
$strLength = strlen($json); // Must stay strlen and not dol_strlen because we want technical length, not visible length
|
||||
for ($i=0; $i<$strLength; $i++)
|
||||
{
|
||||
if (! $comment)
|
||||
{
|
||||
if (($json[$i] == '{') || ($json[$i] == '[')) $out.= 'array(';
|
||||
else if (($json[$i] == '}') || ($json[$i] == ']')) $out.= ')';
|
||||
else if ($json[$i] == ':') $out.= ' => ';
|
||||
else $out.=$json[$i];
|
||||
}
|
||||
else $out.= $json[$i];
|
||||
if ($json[$i] == '"' && $json[($i-1)]!="\\") $comment = !$comment;
|
||||
}
|
||||
|
||||
$out=_unval($out);
|
||||
|
||||
// Return an array
|
||||
if ($out != '') eval('$array = '.$out.';');
|
||||
else $array=array();
|
||||
|
||||
// Return an object
|
||||
if (! $assoc)
|
||||
{
|
||||
if (! empty($array))
|
||||
{
|
||||
$object = false;
|
||||
|
||||
foreach ($array as $key => $value)
|
||||
{
|
||||
$object->{$key} = $value;
|
||||
}
|
||||
|
||||
return $object;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return $array;
|
||||
else $array=array();
|
||||
|
||||
// Return an object
|
||||
if (! $assoc)
|
||||
{
|
||||
if (! empty($array))
|
||||
{
|
||||
$object = false;
|
||||
|
||||
foreach ($array as $key => $value)
|
||||
{
|
||||
$object->{$key} = $value;
|
||||
}
|
||||
|
||||
return $object;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return $array;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user