|
|
|
@ -108,97 +108,6 @@ function send_modified_header($mdate, $etag=null, $skip_check=false)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns whether an $str is a reserved word for any of the version of Javascript or ECMAScript
|
|
|
|
|
* @param str String to check
|
|
|
|
|
* @return boolean True if $str is a reserver word, False if not
|
|
|
|
|
*/
|
|
|
|
|
function is_js_reserved_word($str)
|
|
|
|
|
{
|
|
|
|
|
return in_array($str, array(
|
|
|
|
|
// ECMASript ver 4 reserved words
|
|
|
|
|
'as','break','case','catch','class','const','continue',
|
|
|
|
|
'default','delete','do','else','export','extends','false','finally','for','function',
|
|
|
|
|
'if','import','in','instanceof','is','namespace','new','null','package','private',
|
|
|
|
|
'public','return','super','switch','this','throw','true','try','typeof','use','var',
|
|
|
|
|
'void','while','with',
|
|
|
|
|
// ECMAScript ver 4 future reserved words
|
|
|
|
|
'abstract','debugger','enum','goto','implements','interface','native','protected',
|
|
|
|
|
'synchronized','throws','transient','volatile',
|
|
|
|
|
// special meaning in some contexts
|
|
|
|
|
'get','set',
|
|
|
|
|
// were reserved in ECMAScript ver 3
|
|
|
|
|
'boolean','byte','char','double','final','float','int','long','short','static'
|
|
|
|
|
));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Convert a variable into a javascript object notation
|
|
|
|
|
*
|
|
|
|
|
* @param mixed Input value
|
|
|
|
|
* @return string Serialized JSON string
|
|
|
|
|
*/
|
|
|
|
|
function json_serialize($var)
|
|
|
|
|
{
|
|
|
|
|
if (is_object($var))
|
|
|
|
|
$var = get_object_vars($var);
|
|
|
|
|
|
|
|
|
|
if (is_array($var))
|
|
|
|
|
{
|
|
|
|
|
// empty array
|
|
|
|
|
if (!sizeof($var))
|
|
|
|
|
return '[]';
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
$keys_arr = array_keys($var);
|
|
|
|
|
$is_assoc = $have_numeric = 0;
|
|
|
|
|
|
|
|
|
|
for ($i=0; $i<sizeof($keys_arr); ++$i)
|
|
|
|
|
{
|
|
|
|
|
if (is_numeric($keys_arr[$i]))
|
|
|
|
|
$have_numeric = 1;
|
|
|
|
|
if (!is_numeric($keys_arr[$i]) || $keys_arr[$i] != $i)
|
|
|
|
|
$is_assoc = 1;
|
|
|
|
|
if ($is_assoc && $have_numeric)
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$brackets = $is_assoc ? '{}' : '[]';
|
|
|
|
|
$pairs = array();
|
|
|
|
|
|
|
|
|
|
foreach ($var as $key => $value)
|
|
|
|
|
{
|
|
|
|
|
// enclose key with quotes if it is not variable-name conform
|
|
|
|
|
if (!preg_match('/^[_a-zA-Z]{1}[_a-zA-Z0-9]*$/', $key) || is_js_reserved_word($key))
|
|
|
|
|
$key = "'$key'";
|
|
|
|
|
|
|
|
|
|
$pairs[] = sprintf("%s%s", $is_assoc ? "$key:" : '', json_serialize($value));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $brackets{0} . implode(',', $pairs) . $brackets{1};
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (!is_string($var) && strval(intval($var)) === strval($var))
|
|
|
|
|
return $var;
|
|
|
|
|
else if (is_bool($var))
|
|
|
|
|
return $var ? '1' : '0';
|
|
|
|
|
else
|
|
|
|
|
return "'".JQ($var)."'";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Function to convert an array to a javascript array
|
|
|
|
|
* Actually an alias function for json_serialize()
|
|
|
|
|
* @deprecated
|
|
|
|
|
*/
|
|
|
|
|
function array2js($arr, $type='')
|
|
|
|
|
{
|
|
|
|
|
return json_serialize($arr);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Similar function as in_array() but case-insensitive
|
|
|
|
|
*
|
|
|
|
|