Edit File by line
/home/barbar84/public_h.../wp-inclu...
File: class-json.php
<?php
[0] Fix | Delete
_deprecated_file( basename( __FILE__ ), '5.3.0', '', 'The PHP native JSON extension is now a requirement.' );
[1] Fix | Delete
[2] Fix | Delete
if ( ! class_exists( 'Services_JSON' ) ) :
[3] Fix | Delete
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
[4] Fix | Delete
/**
[5] Fix | Delete
* Converts to and from JSON format.
[6] Fix | Delete
*
[7] Fix | Delete
* JSON (JavaScript Object Notation) is a lightweight data-interchange
[8] Fix | Delete
* format. It is easy for humans to read and write. It is easy for machines
[9] Fix | Delete
* to parse and generate. It is based on a subset of the JavaScript
[10] Fix | Delete
* Programming Language, Standard ECMA-262 3rd Edition - December 1999.
[11] Fix | Delete
* This feature can also be found in Python. JSON is a text format that is
[12] Fix | Delete
* completely language independent but uses conventions that are familiar
[13] Fix | Delete
* to programmers of the C-family of languages, including C, C++, C#, Java,
[14] Fix | Delete
* JavaScript, Perl, TCL, and many others. These properties make JSON an
[15] Fix | Delete
* ideal data-interchange language.
[16] Fix | Delete
*
[17] Fix | Delete
* This package provides a simple encoder and decoder for JSON notation. It
[18] Fix | Delete
* is intended for use with client-side JavaScript applications that make
[19] Fix | Delete
* use of HTTPRequest to perform server communication functions - data can
[20] Fix | Delete
* be encoded into JSON notation for use in a client-side javaScript, or
[21] Fix | Delete
* decoded from incoming JavaScript requests. JSON format is native to
[22] Fix | Delete
* JavaScript, and can be directly eval()'ed with no further parsing
[23] Fix | Delete
* overhead
[24] Fix | Delete
*
[25] Fix | Delete
* All strings should be in ASCII or UTF-8 format!
[26] Fix | Delete
*
[27] Fix | Delete
* LICENSE: Redistribution and use in source and binary forms, with or
[28] Fix | Delete
* without modification, are permitted provided that the following
[29] Fix | Delete
* conditions are met: Redistributions of source code must retain the
[30] Fix | Delete
* above copyright notice, this list of conditions and the following
[31] Fix | Delete
* disclaimer. Redistributions in binary form must reproduce the above
[32] Fix | Delete
* copyright notice, this list of conditions and the following disclaimer
[33] Fix | Delete
* in the documentation and/or other materials provided with the
[34] Fix | Delete
* distribution.
[35] Fix | Delete
*
[36] Fix | Delete
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
[37] Fix | Delete
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
[38] Fix | Delete
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
[39] Fix | Delete
* NO EVENT SHALL CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
[40] Fix | Delete
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
[41] Fix | Delete
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
[42] Fix | Delete
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
[43] Fix | Delete
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
[44] Fix | Delete
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
[45] Fix | Delete
* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
[46] Fix | Delete
* DAMAGE.
[47] Fix | Delete
*
[48] Fix | Delete
* @category
[49] Fix | Delete
* @package Services_JSON
[50] Fix | Delete
* @author Michal Migurski <mike-json@teczno.com>
[51] Fix | Delete
* @author Matt Knapp <mdknapp[at]gmail[dot]com>
[52] Fix | Delete
* @author Brett Stimmerman <brettstimmerman[at]gmail[dot]com>
[53] Fix | Delete
* @copyright 2005 Michal Migurski
[54] Fix | Delete
* @version CVS: $Id: JSON.php 305040 2010-11-02 23:19:03Z alan_k $
[55] Fix | Delete
* @license http://www.opensource.org/licenses/bsd-license.php
[56] Fix | Delete
* @link http://pear.php.net/pepr/pepr-proposal-show.php?id=198
[57] Fix | Delete
*/
[58] Fix | Delete
[59] Fix | Delete
/**
[60] Fix | Delete
* Marker constant for Services_JSON::decode(), used to flag stack state
[61] Fix | Delete
*/
[62] Fix | Delete
define('SERVICES_JSON_SLICE', 1);
[63] Fix | Delete
[64] Fix | Delete
/**
[65] Fix | Delete
* Marker constant for Services_JSON::decode(), used to flag stack state
[66] Fix | Delete
*/
[67] Fix | Delete
define('SERVICES_JSON_IN_STR', 2);
[68] Fix | Delete
[69] Fix | Delete
/**
[70] Fix | Delete
* Marker constant for Services_JSON::decode(), used to flag stack state
[71] Fix | Delete
*/
[72] Fix | Delete
define('SERVICES_JSON_IN_ARR', 3);
[73] Fix | Delete
[74] Fix | Delete
/**
[75] Fix | Delete
* Marker constant for Services_JSON::decode(), used to flag stack state
[76] Fix | Delete
*/
[77] Fix | Delete
define('SERVICES_JSON_IN_OBJ', 4);
[78] Fix | Delete
[79] Fix | Delete
/**
[80] Fix | Delete
* Marker constant for Services_JSON::decode(), used to flag stack state
[81] Fix | Delete
*/
[82] Fix | Delete
define('SERVICES_JSON_IN_CMT', 5);
[83] Fix | Delete
[84] Fix | Delete
/**
[85] Fix | Delete
* Behavior switch for Services_JSON::decode()
[86] Fix | Delete
*/
[87] Fix | Delete
define('SERVICES_JSON_LOOSE_TYPE', 16);
[88] Fix | Delete
[89] Fix | Delete
/**
[90] Fix | Delete
* Behavior switch for Services_JSON::decode()
[91] Fix | Delete
*/
[92] Fix | Delete
define('SERVICES_JSON_SUPPRESS_ERRORS', 32);
[93] Fix | Delete
[94] Fix | Delete
/**
[95] Fix | Delete
* Behavior switch for Services_JSON::decode()
[96] Fix | Delete
*/
[97] Fix | Delete
define('SERVICES_JSON_USE_TO_JSON', 64);
[98] Fix | Delete
[99] Fix | Delete
/**
[100] Fix | Delete
* Converts to and from JSON format.
[101] Fix | Delete
*
[102] Fix | Delete
* Brief example of use:
[103] Fix | Delete
*
[104] Fix | Delete
* <code>
[105] Fix | Delete
* // create a new instance of Services_JSON
[106] Fix | Delete
* $json = new Services_JSON();
[107] Fix | Delete
*
[108] Fix | Delete
* // convert a complex value to JSON notation, and send it to the browser
[109] Fix | Delete
* $value = array('foo', 'bar', array(1, 2, 'baz'), array(3, array(4)));
[110] Fix | Delete
* $output = $json->encode($value);
[111] Fix | Delete
*
[112] Fix | Delete
* print($output);
[113] Fix | Delete
* // prints: ["foo","bar",[1,2,"baz"],[3,[4]]]
[114] Fix | Delete
*
[115] Fix | Delete
* // accept incoming POST data, assumed to be in JSON notation
[116] Fix | Delete
* $input = file_get_contents('php://input', 1000000);
[117] Fix | Delete
* $value = $json->decode($input);
[118] Fix | Delete
* </code>
[119] Fix | Delete
*/
[120] Fix | Delete
class Services_JSON
[121] Fix | Delete
{
[122] Fix | Delete
/**
[123] Fix | Delete
* constructs a new JSON instance
[124] Fix | Delete
*
[125] Fix | Delete
* @deprecated 5.3.0 Use the PHP native JSON extension instead.
[126] Fix | Delete
*
[127] Fix | Delete
* @param int $use object behavior flags; combine with boolean-OR
[128] Fix | Delete
*
[129] Fix | Delete
* possible values:
[130] Fix | Delete
* - SERVICES_JSON_LOOSE_TYPE: loose typing.
[131] Fix | Delete
* "{...}" syntax creates associative arrays
[132] Fix | Delete
* instead of objects in decode().
[133] Fix | Delete
* - SERVICES_JSON_SUPPRESS_ERRORS: error suppression.
[134] Fix | Delete
* Values which can't be encoded (e.g. resources)
[135] Fix | Delete
* appear as NULL instead of throwing errors.
[136] Fix | Delete
* By default, a deeply-nested resource will
[137] Fix | Delete
* bubble up with an error, so all return values
[138] Fix | Delete
* from encode() should be checked with isError()
[139] Fix | Delete
* - SERVICES_JSON_USE_TO_JSON: call toJSON when serializing objects
[140] Fix | Delete
* It serializes the return value from the toJSON call rather
[141] Fix | Delete
* than the object itself, toJSON can return associative arrays,
[142] Fix | Delete
* strings or numbers, if you return an object, make sure it does
[143] Fix | Delete
* not have a toJSON method, otherwise an error will occur.
[144] Fix | Delete
*/
[145] Fix | Delete
function __construct( $use = 0 )
[146] Fix | Delete
{
[147] Fix | Delete
_deprecated_function( __METHOD__, '5.3.0', 'The PHP native JSON extension' );
[148] Fix | Delete
[149] Fix | Delete
$this->use = $use;
[150] Fix | Delete
$this->_mb_strlen = function_exists('mb_strlen');
[151] Fix | Delete
$this->_mb_convert_encoding = function_exists('mb_convert_encoding');
[152] Fix | Delete
$this->_mb_substr = function_exists('mb_substr');
[153] Fix | Delete
}
[154] Fix | Delete
[155] Fix | Delete
/**
[156] Fix | Delete
* PHP4 constructor.
[157] Fix | Delete
*
[158] Fix | Delete
* @deprecated 5.3.0 Use __construct() instead.
[159] Fix | Delete
*
[160] Fix | Delete
* @see Services_JSON::__construct()
[161] Fix | Delete
*/
[162] Fix | Delete
public function Services_JSON( $use = 0 ) {
[163] Fix | Delete
_deprecated_constructor( 'Services_JSON', '5.3.0', get_class( $this ) );
[164] Fix | Delete
self::__construct( $use );
[165] Fix | Delete
}
[166] Fix | Delete
// private - cache the mbstring lookup results..
[167] Fix | Delete
var $_mb_strlen = false;
[168] Fix | Delete
var $_mb_substr = false;
[169] Fix | Delete
var $_mb_convert_encoding = false;
[170] Fix | Delete
[171] Fix | Delete
/**
[172] Fix | Delete
* convert a string from one UTF-16 char to one UTF-8 char
[173] Fix | Delete
*
[174] Fix | Delete
* Normally should be handled by mb_convert_encoding, but
[175] Fix | Delete
* provides a slower PHP-only method for installations
[176] Fix | Delete
* that lack the multibye string extension.
[177] Fix | Delete
*
[178] Fix | Delete
* @deprecated 5.3.0 Use the PHP native JSON extension instead.
[179] Fix | Delete
*
[180] Fix | Delete
* @param string $utf16 UTF-16 character
[181] Fix | Delete
* @return string UTF-8 character
[182] Fix | Delete
* @access private
[183] Fix | Delete
*/
[184] Fix | Delete
function utf162utf8($utf16)
[185] Fix | Delete
{
[186] Fix | Delete
_deprecated_function( __METHOD__, '5.3.0', 'The PHP native JSON extension' );
[187] Fix | Delete
[188] Fix | Delete
// oh please oh please oh please oh please oh please
[189] Fix | Delete
if($this->_mb_convert_encoding) {
[190] Fix | Delete
return mb_convert_encoding($utf16, 'UTF-8', 'UTF-16');
[191] Fix | Delete
}
[192] Fix | Delete
[193] Fix | Delete
$bytes = (ord($utf16[0]) << 8) | ord($utf16[1]);
[194] Fix | Delete
[195] Fix | Delete
switch(true) {
[196] Fix | Delete
case ((0x7F & $bytes) == $bytes):
[197] Fix | Delete
// this case should never be reached, because we are in ASCII range
[198] Fix | Delete
// see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
[199] Fix | Delete
return chr(0x7F & $bytes);
[200] Fix | Delete
[201] Fix | Delete
case (0x07FF & $bytes) == $bytes:
[202] Fix | Delete
// return a 2-byte UTF-8 character
[203] Fix | Delete
// see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
[204] Fix | Delete
return chr(0xC0 | (($bytes >> 6) & 0x1F))
[205] Fix | Delete
. chr(0x80 | ($bytes & 0x3F));
[206] Fix | Delete
[207] Fix | Delete
case (0xFFFF & $bytes) == $bytes:
[208] Fix | Delete
// return a 3-byte UTF-8 character
[209] Fix | Delete
// see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
[210] Fix | Delete
return chr(0xE0 | (($bytes >> 12) & 0x0F))
[211] Fix | Delete
. chr(0x80 | (($bytes >> 6) & 0x3F))
[212] Fix | Delete
. chr(0x80 | ($bytes & 0x3F));
[213] Fix | Delete
}
[214] Fix | Delete
[215] Fix | Delete
// ignoring UTF-32 for now, sorry
[216] Fix | Delete
return '';
[217] Fix | Delete
}
[218] Fix | Delete
[219] Fix | Delete
/**
[220] Fix | Delete
* convert a string from one UTF-8 char to one UTF-16 char
[221] Fix | Delete
*
[222] Fix | Delete
* Normally should be handled by mb_convert_encoding, but
[223] Fix | Delete
* provides a slower PHP-only method for installations
[224] Fix | Delete
* that lack the multibyte string extension.
[225] Fix | Delete
*
[226] Fix | Delete
* @deprecated 5.3.0 Use the PHP native JSON extension instead.
[227] Fix | Delete
*
[228] Fix | Delete
* @param string $utf8 UTF-8 character
[229] Fix | Delete
* @return string UTF-16 character
[230] Fix | Delete
* @access private
[231] Fix | Delete
*/
[232] Fix | Delete
function utf82utf16($utf8)
[233] Fix | Delete
{
[234] Fix | Delete
_deprecated_function( __METHOD__, '5.3.0', 'The PHP native JSON extension' );
[235] Fix | Delete
[236] Fix | Delete
// oh please oh please oh please oh please oh please
[237] Fix | Delete
if($this->_mb_convert_encoding) {
[238] Fix | Delete
return mb_convert_encoding($utf8, 'UTF-16', 'UTF-8');
[239] Fix | Delete
}
[240] Fix | Delete
[241] Fix | Delete
switch($this->strlen8($utf8)) {
[242] Fix | Delete
case 1:
[243] Fix | Delete
// this case should never be reached, because we are in ASCII range
[244] Fix | Delete
// see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
[245] Fix | Delete
return $utf8;
[246] Fix | Delete
[247] Fix | Delete
case 2:
[248] Fix | Delete
// return a UTF-16 character from a 2-byte UTF-8 char
[249] Fix | Delete
// see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
[250] Fix | Delete
return chr(0x07 & (ord($utf8[0]) >> 2))
[251] Fix | Delete
. chr((0xC0 & (ord($utf8[0]) << 6))
[252] Fix | Delete
| (0x3F & ord($utf8[1])));
[253] Fix | Delete
[254] Fix | Delete
case 3:
[255] Fix | Delete
// return a UTF-16 character from a 3-byte UTF-8 char
[256] Fix | Delete
// see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
[257] Fix | Delete
return chr((0xF0 & (ord($utf8[0]) << 4))
[258] Fix | Delete
| (0x0F & (ord($utf8[1]) >> 2)))
[259] Fix | Delete
. chr((0xC0 & (ord($utf8[1]) << 6))
[260] Fix | Delete
| (0x7F & ord($utf8[2])));
[261] Fix | Delete
}
[262] Fix | Delete
[263] Fix | Delete
// ignoring UTF-32 for now, sorry
[264] Fix | Delete
return '';
[265] Fix | Delete
}
[266] Fix | Delete
[267] Fix | Delete
/**
[268] Fix | Delete
* encodes an arbitrary variable into JSON format (and sends JSON Header)
[269] Fix | Delete
*
[270] Fix | Delete
* @deprecated 5.3.0 Use the PHP native JSON extension instead.
[271] Fix | Delete
*
[272] Fix | Delete
* @param mixed $var any number, boolean, string, array, or object to be encoded.
[273] Fix | Delete
* see argument 1 to Services_JSON() above for array-parsing behavior.
[274] Fix | Delete
* if var is a string, note that encode() always expects it
[275] Fix | Delete
* to be in ASCII or UTF-8 format!
[276] Fix | Delete
*
[277] Fix | Delete
* @return mixed JSON string representation of input var or an error if a problem occurs
[278] Fix | Delete
* @access public
[279] Fix | Delete
*/
[280] Fix | Delete
function encode($var)
[281] Fix | Delete
{
[282] Fix | Delete
_deprecated_function( __METHOD__, '5.3.0', 'The PHP native JSON extension' );
[283] Fix | Delete
[284] Fix | Delete
header('Content-type: application/json');
[285] Fix | Delete
return $this->encodeUnsafe($var);
[286] Fix | Delete
}
[287] Fix | Delete
/**
[288] Fix | Delete
* encodes an arbitrary variable into JSON format without JSON Header - warning - may allow XSS!!!!)
[289] Fix | Delete
*
[290] Fix | Delete
* @deprecated 5.3.0 Use the PHP native JSON extension instead.
[291] Fix | Delete
*
[292] Fix | Delete
* @param mixed $var any number, boolean, string, array, or object to be encoded.
[293] Fix | Delete
* see argument 1 to Services_JSON() above for array-parsing behavior.
[294] Fix | Delete
* if var is a string, note that encode() always expects it
[295] Fix | Delete
* to be in ASCII or UTF-8 format!
[296] Fix | Delete
*
[297] Fix | Delete
* @return mixed JSON string representation of input var or an error if a problem occurs
[298] Fix | Delete
* @access public
[299] Fix | Delete
*/
[300] Fix | Delete
function encodeUnsafe($var)
[301] Fix | Delete
{
[302] Fix | Delete
_deprecated_function( __METHOD__, '5.3.0', 'The PHP native JSON extension' );
[303] Fix | Delete
[304] Fix | Delete
// see bug #16908 - regarding numeric locale printing
[305] Fix | Delete
$lc = setlocale(LC_NUMERIC, 0);
[306] Fix | Delete
setlocale(LC_NUMERIC, 'C');
[307] Fix | Delete
$ret = $this->_encode($var);
[308] Fix | Delete
setlocale(LC_NUMERIC, $lc);
[309] Fix | Delete
return $ret;
[310] Fix | Delete
[311] Fix | Delete
}
[312] Fix | Delete
/**
[313] Fix | Delete
* PRIVATE CODE that does the work of encodes an arbitrary variable into JSON format
[314] Fix | Delete
*
[315] Fix | Delete
* @deprecated 5.3.0 Use the PHP native JSON extension instead.
[316] Fix | Delete
*
[317] Fix | Delete
* @param mixed $var any number, boolean, string, array, or object to be encoded.
[318] Fix | Delete
* see argument 1 to Services_JSON() above for array-parsing behavior.
[319] Fix | Delete
* if var is a string, note that encode() always expects it
[320] Fix | Delete
* to be in ASCII or UTF-8 format!
[321] Fix | Delete
*
[322] Fix | Delete
* @return mixed JSON string representation of input var or an error if a problem occurs
[323] Fix | Delete
* @access public
[324] Fix | Delete
*/
[325] Fix | Delete
function _encode($var)
[326] Fix | Delete
{
[327] Fix | Delete
_deprecated_function( __METHOD__, '5.3.0', 'The PHP native JSON extension' );
[328] Fix | Delete
[329] Fix | Delete
switch (gettype($var)) {
[330] Fix | Delete
case 'boolean':
[331] Fix | Delete
return $var ? 'true' : 'false';
[332] Fix | Delete
[333] Fix | Delete
case 'NULL':
[334] Fix | Delete
return 'null';
[335] Fix | Delete
[336] Fix | Delete
case 'integer':
[337] Fix | Delete
return (int) $var;
[338] Fix | Delete
[339] Fix | Delete
case 'double':
[340] Fix | Delete
case 'float':
[341] Fix | Delete
return (float) $var;
[342] Fix | Delete
[343] Fix | Delete
case 'string':
[344] Fix | Delete
// STRINGS ARE EXPECTED TO BE IN ASCII OR UTF-8 FORMAT
[345] Fix | Delete
$ascii = '';
[346] Fix | Delete
$strlen_var = $this->strlen8($var);
[347] Fix | Delete
[348] Fix | Delete
/*
[349] Fix | Delete
* Iterate over every character in the string,
[350] Fix | Delete
* escaping with a slash or encoding to UTF-8 where necessary
[351] Fix | Delete
*/
[352] Fix | Delete
for ($c = 0; $c < $strlen_var; ++$c) {
[353] Fix | Delete
[354] Fix | Delete
$ord_var_c = ord($var[$c]);
[355] Fix | Delete
[356] Fix | Delete
switch (true) {
[357] Fix | Delete
case $ord_var_c == 0x08:
[358] Fix | Delete
$ascii .= '\b';
[359] Fix | Delete
break;
[360] Fix | Delete
case $ord_var_c == 0x09:
[361] Fix | Delete
$ascii .= '\t';
[362] Fix | Delete
break;
[363] Fix | Delete
case $ord_var_c == 0x0A:
[364] Fix | Delete
$ascii .= '\n';
[365] Fix | Delete
break;
[366] Fix | Delete
case $ord_var_c == 0x0C:
[367] Fix | Delete
$ascii .= '\f';
[368] Fix | Delete
break;
[369] Fix | Delete
case $ord_var_c == 0x0D:
[370] Fix | Delete
$ascii .= '\r';
[371] Fix | Delete
break;
[372] Fix | Delete
[373] Fix | Delete
case $ord_var_c == 0x22:
[374] Fix | Delete
case $ord_var_c == 0x2F:
[375] Fix | Delete
case $ord_var_c == 0x5C:
[376] Fix | Delete
// double quote, slash, slosh
[377] Fix | Delete
$ascii .= '\\'.$var[$c];
[378] Fix | Delete
break;
[379] Fix | Delete
[380] Fix | Delete
case (($ord_var_c >= 0x20) && ($ord_var_c <= 0x7F)):
[381] Fix | Delete
// characters U-00000000 - U-0000007F (same as ASCII)
[382] Fix | Delete
$ascii .= $var[$c];
[383] Fix | Delete
break;
[384] Fix | Delete
[385] Fix | Delete
case (($ord_var_c & 0xE0) == 0xC0):
[386] Fix | Delete
// characters U-00000080 - U-000007FF, mask 110XXXXX
[387] Fix | Delete
// see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
[388] Fix | Delete
if ($c+1 >= $strlen_var) {
[389] Fix | Delete
$c += 1;
[390] Fix | Delete
$ascii .= '?';
[391] Fix | Delete
break;
[392] Fix | Delete
}
[393] Fix | Delete
[394] Fix | Delete
$char = pack('C*', $ord_var_c, ord($var[$c + 1]));
[395] Fix | Delete
$c += 1;
[396] Fix | Delete
$utf16 = $this->utf82utf16($char);
[397] Fix | Delete
$ascii .= sprintf('\u%04s', bin2hex($utf16));
[398] Fix | Delete
break;
[399] Fix | Delete
[400] Fix | Delete
case (($ord_var_c & 0xF0) == 0xE0):
[401] Fix | Delete
if ($c+2 >= $strlen_var) {
[402] Fix | Delete
$c += 2;
[403] Fix | Delete
$ascii .= '?';
[404] Fix | Delete
break;
[405] Fix | Delete
}
[406] Fix | Delete
// characters U-00000800 - U-0000FFFF, mask 1110XXXX
[407] Fix | Delete
// see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
[408] Fix | Delete
$char = pack('C*', $ord_var_c,
[409] Fix | Delete
@ord($var[$c + 1]),
[410] Fix | Delete
@ord($var[$c + 2]));
[411] Fix | Delete
$c += 2;
[412] Fix | Delete
$utf16 = $this->utf82utf16($char);
[413] Fix | Delete
$ascii .= sprintf('\u%04s', bin2hex($utf16));
[414] Fix | Delete
break;
[415] Fix | Delete
[416] Fix | Delete
case (($ord_var_c & 0xF8) == 0xF0):
[417] Fix | Delete
if ($c+3 >= $strlen_var) {
[418] Fix | Delete
$c += 3;
[419] Fix | Delete
$ascii .= '?';
[420] Fix | Delete
break;
[421] Fix | Delete
}
[422] Fix | Delete
// characters U-00010000 - U-001FFFFF, mask 11110XXX
[423] Fix | Delete
// see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
[424] Fix | Delete
$char = pack('C*', $ord_var_c,
[425] Fix | Delete
ord($var[$c + 1]),
[426] Fix | Delete
ord($var[$c + 2]),
[427] Fix | Delete
ord($var[$c + 3]));
[428] Fix | Delete
$c += 3;
[429] Fix | Delete
$utf16 = $this->utf82utf16($char);
[430] Fix | Delete
$ascii .= sprintf('\u%04s', bin2hex($utf16));
[431] Fix | Delete
break;
[432] Fix | Delete
[433] Fix | Delete
case (($ord_var_c & 0xFC) == 0xF8):
[434] Fix | Delete
// characters U-00200000 - U-03FFFFFF, mask 111110XX
[435] Fix | Delete
// see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
[436] Fix | Delete
if ($c+4 >= $strlen_var) {
[437] Fix | Delete
$c += 4;
[438] Fix | Delete
$ascii .= '?';
[439] Fix | Delete
break;
[440] Fix | Delete
}
[441] Fix | Delete
$char = pack('C*', $ord_var_c,
[442] Fix | Delete
ord($var[$c + 1]),
[443] Fix | Delete
ord($var[$c + 2]),
[444] Fix | Delete
ord($var[$c + 3]),
[445] Fix | Delete
ord($var[$c + 4]));
[446] Fix | Delete
$c += 4;
[447] Fix | Delete
$utf16 = $this->utf82utf16($char);
[448] Fix | Delete
$ascii .= sprintf('\u%04s', bin2hex($utf16));
[449] Fix | Delete
break;
[450] Fix | Delete
[451] Fix | Delete
case (($ord_var_c & 0xFE) == 0xFC):
[452] Fix | Delete
if ($c+5 >= $strlen_var) {
[453] Fix | Delete
$c += 5;
[454] Fix | Delete
$ascii .= '?';
[455] Fix | Delete
break;
[456] Fix | Delete
}
[457] Fix | Delete
// characters U-04000000 - U-7FFFFFFF, mask 1111110X
[458] Fix | Delete
// see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
[459] Fix | Delete
$char = pack('C*', $ord_var_c,
[460] Fix | Delete
ord($var[$c + 1]),
[461] Fix | Delete
ord($var[$c + 2]),
[462] Fix | Delete
ord($var[$c + 3]),
[463] Fix | Delete
ord($var[$c + 4]),
[464] Fix | Delete
ord($var[$c + 5]));
[465] Fix | Delete
$c += 5;
[466] Fix | Delete
$utf16 = $this->utf82utf16($char);
[467] Fix | Delete
$ascii .= sprintf('\u%04s', bin2hex($utf16));
[468] Fix | Delete
break;
[469] Fix | Delete
}
[470] Fix | Delete
}
[471] Fix | Delete
return '"'.$ascii.'"';
[472] Fix | Delete
[473] Fix | Delete
case 'array':
[474] Fix | Delete
/*
[475] Fix | Delete
* As per JSON spec if any array key is not an integer
[476] Fix | Delete
* we must treat the whole array as an object. We
[477] Fix | Delete
* also try to catch a sparsely populated associative
[478] Fix | Delete
* array with numeric keys here because some JS engines
[479] Fix | Delete
* will create an array with empty indexes up to
[480] Fix | Delete
* max_index which can cause memory issues and because
[481] Fix | Delete
* the keys, which may be relevant, will be remapped
[482] Fix | Delete
* otherwise.
[483] Fix | Delete
*
[484] Fix | Delete
* As per the ECMA and JSON specification an object may
[485] Fix | Delete
* have any string as a property. Unfortunately due to
[486] Fix | Delete
* a hole in the ECMA specification if the key is a
[487] Fix | Delete
* ECMA reserved word or starts with a digit the
[488] Fix | Delete
* parameter is only accessible using ECMAScript's
[489] Fix | Delete
* bracket notation.
[490] Fix | Delete
*/
[491] Fix | Delete
[492] Fix | Delete
// treat as a JSON object
[493] Fix | Delete
if (is_array($var) && count($var) && (array_keys($var) !== range(0, sizeof($var) - 1))) {
[494] Fix | Delete
$properties = array_map(array($this, 'name_value'),
[495] Fix | Delete
array_keys($var),
[496] Fix | Delete
array_values($var));
[497] Fix | Delete
[498] Fix | Delete
foreach($properties as $property) {
[499] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function