Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ? phpcs-r619.diff
- ? phpcs.xml
- Index: AJAX.php
- ===================================================================
- RCS file: /repository/pear/HTML_AJAX/AJAX.php,v
- retrieving revision 1.12
- diff -u -r1.12 AJAX.php
- --- AJAX.php 7 May 2008 21:26:19 -0000 1.12
- +++ AJAX.php 6 Dec 2008 14:31:57 -0000
- @@ -305,7 +305,7 @@
- $client .= "}\n\n";
- if ($this->packJavaScript) {
- - $client = $this->packJavaScript($client);
- + $client = $this->packJavaScript($client);
- }
- return $client;
- }
- Index: AJAX/Helper.php
- ===================================================================
- RCS file: /repository/pear/HTML_AJAX/AJAX/Helper.php,v
- retrieving revision 1.5
- diff -u -r1.5 Helper.php
- --- AJAX/Helper.php 7 May 2008 21:26:19 -0000 1.5
- +++ AJAX/Helper.php 6 Dec 2008 14:31:57 -0000
- @@ -23,58 +23,58 @@
- */
- class HTML_AJAX_Helper
- {
- - /**
- - * URL where an HTML_AJAX_Server instance is serving up clients and taking ajax requests
- - */
- - var $serverUrl = 'server.php';
- -
- - /**
- - * JS libraries to include
- - *
- - * @var array
- - */
- - var $jsLibraries = array('Util','Main','Request','HttpClient','Dispatcher','Behavior','Loading','JSON','iframe');
- -
- - /**
- - * Remote class stubs to include
- - */
- - var $stubs = array();
- + /**
- + * URL where an HTML_AJAX_Server instance is serving up clients and taking ajax requests
- + */
- + var $serverUrl = 'server.php';
- +
- + /**
- + * JS libraries to include
- + *
- + * @var array
- + */
- + var $jsLibraries = array('Util','Main','Request','HttpClient','Dispatcher','Behavior','Loading','JSON','iframe');
- +
- + /**
- + * Remote class stubs to include
- + */
- + var $stubs = array();
- /**
- * Combine jsLibraries into a single require and remove duplicates
- */
- var $combineJsIncludes = false;
- - /**
- - * Include all needed libraries, stubs, and set defaultServer
- - *
- - * @return string
- - */
- - function setupAJAX()
- - {
- - $libs = array(0=>array());
- + /**
- + * Include all needed libraries, stubs, and set defaultServer
- + *
- + * @return string
- + */
- + function setupAJAX()
- + {
- + $libs = array(0=>array());
- $combinedLibs = array();
- $this->jsLibraries = array_unique($this->jsLibraries);
- - foreach($this->jsLibraries as $library) {
- - if (is_array($library)) {
- + foreach($this->jsLibraries as $library) {
- + if (is_array($library)) {
- $library = array_unique($library);
- $combinedLibs = array_merge($combinedLibs,$library);
- - $libs[] = implode(',',$library);
- - }
- - else {
- - $libs[0][] = $library;
- + $libs[] = implode(',',$library);
- + }
- + else {
- + $libs[0][] = $library;
- $combinedLibs[] = $library;
- - }
- - }
- - $libs[0] = implode(',',$libs[0]);
- + }
- + }
- + $libs[0] = implode(',',$libs[0]);
- $sep = '?';
- if (strstr($this->serverUrl,'?')) {
- $sep = '&';
- }
- - $ret = '';
- + $ret = '';
- if ($this->combineJsIncludes == true) {
- $list = implode(',',$combinedLibs);
- $ret .= "<script type='text/javascript' src='{$this->serverUrl}{$sep}client={$list}'></script>\n";
- @@ -85,91 +85,91 @@
- }
- }
- - if (count($this->stubs) > 0) {
- - $stubs = implode(',',$this->stubs);
- - $ret .= "<script type='text/javascript' src='{$this->serverUrl}{$sep}stub={$stubs}'></script>\n";
- - }
- - $ret .= $this->encloseInScript('HTML_AJAX.defaultServerUrl = '.$this->escape($this->serverUrl));
- - return $ret;
- - }
- -
- - /**
- - * Create a custom Loading message
- - *
- - * @param string $body HTML body of the loading div
- - * @param string $class CSS class of the div
- - * @param string $style style tag of the loading div
- - */
- - function loadingMessage($body, $class = 'HTML_AJAX_Loading',
- - $style = 'position: absolute; top: 0; right: 0; background-color: red; width: 80px; padding: 4px; display: none')
- - {
- - return "<div id='HTML_AJAX_LOADING' class='{$class}' style=\"{$style}\">{$body}</div>\n";
- - }
- -
- - /**
- - * Update the contents of an element using ajax
- - *
- - * @param string $id id of the element to update
- - * @param string|array $update Either a url to update with or a array like array('class','method')
- - * @param string $type replace or append
- - * @param boolean $enclose
- - */
- - function updateElement($id, $update, $type, $enclose = false) {
- - if (is_array($update)) {
- - $updateStr = "";
- - $comma = '';
- - foreach($update as $item) {
- - $updateStr .= $comma.$this->escape($item);
- - $comma = ',';
- - }
- - }
- - else {
- - $updateStr = $this->escape($update);
- - }
- -
- - $ret = "HTML_AJAX.{$type}(".$this->escape($id).",{$updateStr});\n";
- - if ($enclose) {
- - $ret = $this->encloseInScript($ret);
- - }
- - return $ret;
- - }
- -
- - /**
- - * Escape a string and add quotes allowing it to be a javascript paramater
- - *
- - * @param string $input
- - * @return string
- - * @todo do something here besides a quick hack
- - */
- - function escape($input) {
- - return "'".addslashes($input)."'";
- - }
- -
- - /**
- - * Enclose a string in a script block
- - *
- - * @param string $input
- - * @return string
- - */
- - function encloseInScript($input) {
- - return '<script type="text/javascript">'.$input."</script>\n";
- - }
- -
- - /**
- - * Generate a JSON String
- - *
- - * @param string $input
- - * @return string
- - */
- - function jsonEncode($input) {
- - require_once 'HTML/AJAX/Serializer/JSON.php';
- -
- - $s = new HTML_AJAX_Serializer_JSON();
- - return $s->serialize($input);
- - }
- + if (count($this->stubs) > 0) {
- + $stubs = implode(',',$this->stubs);
- + $ret .= "<script type='text/javascript' src='{$this->serverUrl}{$sep}stub={$stubs}'></script>\n";
- + }
- + $ret .= $this->encloseInScript('HTML_AJAX.defaultServerUrl = '.$this->escape($this->serverUrl));
- + return $ret;
- + }
- +
- + /**
- + * Create a custom Loading message
- + *
- + * @param string $body HTML body of the loading div
- + * @param string $class CSS class of the div
- + * @param string $style style tag of the loading div
- + */
- + function loadingMessage($body, $class = 'HTML_AJAX_Loading',
- + $style = 'position: absolute; top: 0; right: 0; background-color: red; width: 80px; padding: 4px; display: none')
- + {
- + return "<div id='HTML_AJAX_LOADING' class='{$class}' style=\"{$style}\">{$body}</div>\n";
- + }
- +
- + /**
- + * Update the contents of an element using ajax
- + *
- + * @param string $id id of the element to update
- + * @param string|array $update Either a url to update with or a array like array('class','method')
- + * @param string $type replace or append
- + * @param boolean $enclose
- + */
- + function updateElement($id, $update, $type, $enclose = false) {
- + if (is_array($update)) {
- + $updateStr = "";
- + $comma = '';
- + foreach($update as $item) {
- + $updateStr .= $comma.$this->escape($item);
- + $comma = ',';
- + }
- + }
- + else {
- + $updateStr = $this->escape($update);
- + }
- +
- + $ret = "HTML_AJAX.{$type}(".$this->escape($id).",{$updateStr});\n";
- + if ($enclose) {
- + $ret = $this->encloseInScript($ret);
- + }
- + return $ret;
- + }
- +
- + /**
- + * Escape a string and add quotes allowing it to be a javascript paramater
- + *
- + * @param string $input
- + * @return string
- + * @todo do something here besides a quick hack
- + */
- + function escape($input) {
- + return "'".addslashes($input)."'";
- + }
- - /**
- - * Check the request headers to see if this is an AJAX request
- + /**
- + * Enclose a string in a script block
- + *
- + * @param string $input
- + * @return string
- + */
- + function encloseInScript($input) {
- + return '<script type="text/javascript">'.$input."</script>\n";
- + }
- +
- + /**
- + * Generate a JSON String
- + *
- + * @param string $input
- + * @return string
- + */
- + function jsonEncode($input) {
- + require_once 'HTML/AJAX/Serializer/JSON.php';
- +
- + $s = new HTML_AJAX_Serializer_JSON();
- + return $s->serialize($input);
- + }
- +
- + /**
- + * Check the request headers to see if this is an AJAX request
- *
- * @return boolean
- */
- Index: AJAX/JSON.php
- ===================================================================
- RCS file: /repository/pear/HTML_AJAX/AJAX/JSON.php,v
- retrieving revision 1.11
- diff -u -r1.11 JSON.php
- --- AJAX/JSON.php 7 May 2008 21:26:19 -0000 1.11
- +++ AJAX/JSON.php 6 Dec 2008 14:31:58 -0000
- @@ -1,19 +1,13 @@
- <?php
- /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
- -/**
- - * This is an embedded version of HTML_AJAX_JSON since it has yet to have a PEAR release
- - * it has been renamed to HTML_AJAX_JSON so no problems will be caused by an eventual release
- - * Feel free to report bugs against it to HTML_AJAX
- - */
- -
- -/**
- - * Needed for compat functions
- - */
- -require_once 'HTML/AJAX.php';
- /**
- * Converts to and from JSON format.
- *
- + * This is an embedded version of HTML_AJAX_JSON since it has yet to have a PEAR release
- + * it has been renamed to HTML_AJAX_JSON so no problems will be caused by an eventual release
- + * Feel free to report bugs against it to HTML_AJAX
- + *
- * JSON (JavaScript Object Notation) is a lightweight data-interchange
- * format. It is easy for humans to read and write. It is easy for machines
- * to parse and generate. It is based on a subset of the JavaScript
- @@ -55,35 +49,40 @@
- * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
- * DAMAGE.
- *
- - * @category
- - * @package HTML_AJAX_JSON
- - * @author Michal Migurski <mike-json@teczno.com>
- - * @author Matt Knapp <mdknapp[at]gmail[dot]com>
- - * @author Brett Stimmerman <brettstimmerman[at]gmail[dot]com>
- - * @copyright 2005 Michal Migurski
- - * @license http://www.opensource.org/licenses/bsd-license.php
- - * @link http://pear.php.net/pepr/pepr-proposal-show.php?id=198
- + * @category HTML
- + * @package HTML_AJAX_JSON
- + * @author Michal Migurski <mike-json@teczno.com>
- + * @author Matt Knapp <mdknapp@gmail.com>
- + * @author Brett Stimmerman <brettstimmerman@gmail.com>
- + * @copyright 2005 Michal Migurski
- + * @license http://www.opensource.org/licenses/bsd-license.php BSD
- + * @link http://pear.php.net/pepr/pepr-proposal-show.php?id=198
- */
- /**
- + * Needed for compat functions
- + */
- +require_once 'HTML/AJAX.php';
- +
- +/**
- * Marker constant for HTML_AJAX_JSON::decode(), used to flag stack state
- */
- -define('SERVICES_JSON_SLICE', 1);
- +define('SERVICES_JSON_SLICE', 1);
- /**
- * Marker constant for HTML_AJAX_JSON::decode(), used to flag stack state
- */
- -define('SERVICES_JSON_IN_STR', 2);
- +define('SERVICES_JSON_IN_STR', 2);
- /**
- * Marker constant for HTML_AJAX_JSON::decode(), used to flag stack state
- */
- -define('SERVICES_JSON_IN_ARR', 3);
- +define('SERVICES_JSON_IN_ARR', 3);
- /**
- * Marker constant for HTML_AJAX_JSON::decode(), used to flag stack state
- */
- -define('SERVICES_JSON_IN_OBJ', 4);
- +define('SERVICES_JSON_IN_OBJ', 4);
- /**
- * Marker constant for HTML_AJAX_JSON::decode(), used to flag stack state
- @@ -120,25 +119,34 @@
- * $input = file_get_contents('php://input', 1000000);
- * $value = $json->decode($input);
- * </code>
- + *
- + * @category HTML
- + * @package HTML_AJAX_JSON
- + * @author Michal Migurski <mike-json@teczno.com>
- + * @author Matt Knapp <mdknapp@gmail.com>
- + * @author Brett Stimmerman <brettstimmerman@gmail.com>
- + * @copyright 2005 Michal Migurski
- + * @license http://www.opensource.org/licenses/bsd-license.php BSD
- + * @link http://pear.php.net/pepr/pepr-proposal-show.php?id=198
- */
- class HTML_AJAX_JSON
- {
- - /**
- - * constructs a new JSON instance
- - *
- - * @param int $use object behavior flags; combine with boolean-OR
- - *
- - * possible values:
- - * - SERVICES_JSON_LOOSE_TYPE: loose typing.
- - * "{...}" syntax creates associative arrays
- - * instead of objects in decode().
- - * - SERVICES_JSON_SUPPRESS_ERRORS: error suppression.
- - * Values which can't be encoded (e.g. resources)
- - * appear as NULL instead of throwing errors.
- - * By default, a deeply-nested resource will
- - * bubble up with an error, so all return values
- - * from encode() should be checked with isError()
- - */
- + /**
- + * constructs a new JSON instance
- + *
- + * @param int $use object behavior flags; combine with boolean-OR
- + *
- + * possible values:
- + * - SERVICES_JSON_LOOSE_TYPE: loose typing.
- + * "{...}" syntax creates associative arrays
- + * instead of objects in decode().
- + * - SERVICES_JSON_SUPPRESS_ERRORS: error suppression.
- + * Values which can't be encoded (e.g. resources)
- + * appear as NULL instead of throwing errors.
- + * By default, a deeply-nested resource will
- + * bubble up with an error, so all return values
- + * from encode() should be checked with isError()
- + */
- function HTML_AJAX_JSON($use = 0)
- {
- $this->use = $use;
- @@ -151,7 +159,8 @@
- * provides a slower PHP-only method for installations
- * that lack the multibye string extension.
- *
- - * @param string $utf16 UTF-16 character
- + * @param string $utf16 UTF-16 character
- + *
- * @return string UTF-8 character
- * @access private
- */
- @@ -164,23 +173,23 @@
- $bytes = (ord($utf16{0}) << 8) | ord($utf16{1});
- switch(true) {
- - case ((0x7F & $bytes) == $bytes):
- - // this case should never be reached, because we are in ASCII range
- - // see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
- - return chr(0x7F & $bytes);
- -
- - case (0x07FF & $bytes) == $bytes:
- - // return a 2-byte UTF-8 character
- - // see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
- - return chr(0xC0 | (($bytes >> 6) & 0x1F))
- - . chr(0x80 | ($bytes & 0x3F));
- -
- - case (0xFFFF & $bytes) == $bytes:
- - // return a 3-byte UTF-8 character
- - // see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
- - return chr(0xE0 | (($bytes >> 12) & 0x0F))
- - . chr(0x80 | (($bytes >> 6) & 0x3F))
- - . chr(0x80 | ($bytes & 0x3F));
- + case ((0x7F & $bytes) == $bytes):
- + // this case should never be reached, because we are in ASCII range
- + // see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
- + return chr(0x7F & $bytes);
- +
- + case (0x07FF & $bytes) == $bytes:
- + // return a 2-byte UTF-8 character
- + // see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
- + return chr(0xC0 | (($bytes >> 6) & 0x1F))
- + . chr(0x80 | ($bytes & 0x3F));
- +
- + case (0xFFFF & $bytes) == $bytes:
- + // return a 3-byte UTF-8 character
- + // see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
- + return chr(0xE0 | (($bytes >> 12) & 0x0F))
- + . chr(0x80 | (($bytes >> 6) & 0x3F))
- + . chr(0x80 | ($bytes & 0x3F));
- }
- // ignoring UTF-32 for now, sorry
- @@ -194,36 +203,38 @@
- * provides a slower PHP-only method for installations
- * that lack the multibye string extension.
- *
- - * @param string $utf8 UTF-8 character
- + * @param string $utf8 UTF-8 character
- + *
- * @return string UTF-16 character
- * @access private
- */
- function utf82utf16($utf8)
- {
- // oh please oh please oh please oh please oh please
- - if(function_exists('mb_convert_encoding'))
- + if (function_exists('mb_convert_encoding')) {
- return mb_convert_encoding($utf8, 'UTF-16', 'UTF-8');
- + }
- switch(strlen($utf8)) {
- - case 1:
- - // this case should never be reached, because we are in ASCII range
- - // see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
- - return $ut8;
- -
- - case 2:
- - // return a UTF-16 character from a 2-byte UTF-8 char
- - // see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
- - return chr(0x07 & (ord($utf8{0}) >> 2))
- - . chr((0xC0 & (ord($utf8{0}) << 6))
- - | (0x3F & ord($utf8{1})));
- -
- - case 3:
- - // return a UTF-16 character from a 3-byte UTF-8 char
- - // see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
- - return chr((0xF0 & (ord($utf8{0}) << 4))
- - | (0x0F & (ord($utf8{1}) >> 2)))
- - . chr((0xC0 & (ord($utf8{1}) << 6))
- - | (0x7F & ord($utf8{2})));
- + case 1:
- + // this case should never be reached, because we are in ASCII range
- + // see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
- + return $ut8;
- +
- + case 2:
- + // return a UTF-16 character from a 2-byte UTF-8 char
- + // see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
- + return chr(0x07 & (ord($utf8{0}) >> 2))
- + . chr((0xC0 & (ord($utf8{0}) << 6))
- + | (0x3F & ord($utf8{1})));
- +
- + case 3:
- + // return a UTF-16 character from a 3-byte UTF-8 char
- + // see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
- + return chr((0xF0 & (ord($utf8{0}) << 4))
- + | (0x0F & (ord($utf8{1}) >> 2)))
- + . chr((0xC0 & (ord($utf8{1}) << 6))
- + | (0x7F & ord($utf8{2})));
- }
- // ignoring UTF-32 for now, sorry
- @@ -233,10 +244,10 @@
- /**
- * encodes an arbitrary variable into JSON format
- *
- - * @param mixed $var any number, boolean, string, array, or object to be encoded.
- - * see argument 1 to HTML_AJAX_JSON() above for array-parsing behavior.
- - * if var is a strng, note that encode() always expects it
- - * to be in ASCII or UTF-8 format!
- + * @param mixed $var any number, boolean, string, array, or object to be encoded.
- + * see argument 1 to HTML_AJAX_JSON() above for array-parsing behavior.
- + * if var is a strng, note that encode() always expects it
- + * to be in ASCII or UTF-8 format!
- *
- * @return mixed JSON string representation of input var or an error if a problem occurs
- * @access public
- @@ -244,190 +255,196 @@
- function encode($var)
- {
- switch (gettype($var)) {
- - case 'boolean':
- - return $var ? 'true' : 'false';
- + case 'boolean':
- + return $var ? 'true' : 'false';
- +
- + case 'NULL':
- + return 'null';
- +
- + case 'integer':
- + return (int) $var;
- - case 'NULL':
- - return 'null';
- + case 'double':
- + case 'float':
- + return (float) $var;
- +
- + case 'string':
- + // STRINGS ARE EXPECTED TO BE IN ASCII OR UTF-8 FORMAT
- + $ascii = '';
- + $strlen_var = strlen($var);
- +
- + /*
- + * Iterate over every character in the string,
- + * escaping with a slash or encoding to UTF-8 where necessary
- + */
- + for ($c = 0; $c < $strlen_var; ++$c) {
- +
- + $ord_var_c = ord($var{$c});
- +
- + switch (true) {
- + case $ord_var_c == 0x08:
- + $ascii .= '\b';
- + break;
- + case $ord_var_c == 0x09:
- + $ascii .= '\t';
- + break;
- + case $ord_var_c == 0x0A:
- + $ascii .= '\n';
- + break;
- + case $ord_var_c == 0x0C:
- + $ascii .= '\f';
- + break;
- + case $ord_var_c == 0x0D:
- + $ascii .= '\r';
- + break;
- +
- + case $ord_var_c == 0x22:
- + case $ord_var_c == 0x2F:
- + case $ord_var_c == 0x5C:
- + // double quote, slash, slosh
- + $ascii .= '\\'.$var{$c};
- + break;
- +
- + case (($ord_var_c >= 0x20) && ($ord_var_c <= 0x7F)):
- + // characters U-00000000 - U-0000007F (same as ASCII)
- + $ascii .= $var{$c};
- + break;
- +
- + case (($ord_var_c & 0xE0) == 0xC0):
- + // characters U-00000080 - U-000007FF, mask 110XXXXX
- + // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
- + $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):
- + // characters U-00000800 - U-0000FFFF, mask 1110XXXX
- + // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
- + $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):
- + // characters U-00010000 - U-001FFFFF, mask 11110XXX
- + // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
- + $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):
- + // characters U-00200000 - U-03FFFFFF, mask 111110XX
- + // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
- + $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):
- + // characters U-04000000 - U-7FFFFFFF, mask 1111110X
- + // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
- + $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;
- + }
- + }
- - case 'integer':
- - return (int) $var;
- + return '"'.$ascii.'"';
- - case 'double':
- - case 'float':
- - return (float) $var;
- -
- - case 'string':
- - // STRINGS ARE EXPECTED TO BE IN ASCII OR UTF-8 FORMAT
- - $ascii = '';
- - $strlen_var = strlen($var);
- -
- - /*
- - * Iterate over every character in the string,
- - * escaping with a slash or encoding to UTF-8 where necessary
- - */
- - for ($c = 0; $c < $strlen_var; ++$c) {
- -
- - $ord_var_c = ord($var{$c});
- -
- - switch (true) {
- - case $ord_var_c == 0x08:
- - $ascii .= '\b';
- - break;
- - case $ord_var_c == 0x09:
- - $ascii .= '\t';
- - break;
- - case $ord_var_c == 0x0A:
- - $ascii .= '\n';
- - break;
- - case $ord_var_c == 0x0C:
- - $ascii .= '\f';
- - break;
- - case $ord_var_c == 0x0D:
- - $ascii .= '\r';
- - break;
- -
- - case $ord_var_c == 0x22:
- - case $ord_var_c == 0x2F:
- - case $ord_var_c == 0x5C:
- - // double quote, slash, slosh
- - $ascii .= '\\'.$var{$c};
- - break;
- -
- - case (($ord_var_c >= 0x20) && ($ord_var_c <= 0x7F)):
- - // characters U-00000000 - U-0000007F (same as ASCII)
- - $ascii .= $var{$c};
- - break;
- -
- - case (($ord_var_c & 0xE0) == 0xC0):
- - // characters U-00000080 - U-000007FF, mask 110XXXXX
- - // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
- - $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):
- - // characters U-00000800 - U-0000FFFF, mask 1110XXXX
- - // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
- - $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):
- - // characters U-00010000 - U-001FFFFF, mask 11110XXX
- - // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
- - $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):
- - // characters U-00200000 - U-03FFFFFF, mask 111110XX
- - // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
- - $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):
- - // characters U-04000000 - U-7FFFFFFF, mask 1111110X
- - // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
- - $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;
- + case 'array':
- + /*
- + * As per JSON spec if any array key is not an integer
- + * we must treat the the whole array as an object. We
- + * also try to catch a sparsely populated associative
- + * array with numeric keys here because some JS engines
- + * will create an array with empty indexes up to
- + * max_index which can cause memory issues and because
- + * the keys, which may be relevant, will be remapped
- + * otherwise.
- + *
- + * As per the ECMA and JSON specification an object may
- + * have any string as a property. Unfortunately due to
- + * a hole in the ECMA specification if the key is a
- + * ECMA reserved word or starts with a digit the
- + * parameter is only accessible using ECMAScript's
- + * bracket notation.
- + */
- +
- + // treat as a JSON object
- + 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 (HTML_AJAX_JSON::isError($property)) {
- + return $property;
- }
- }
- - return '"'.$ascii.'"';
- -
- - case 'array':
- - /*
- - * As per JSON spec if any array key is not an integer
- - * we must treat the the whole array as an object. We
- - * also try to catch a sparsely populated associative
- - * array with numeric keys here because some JS engines
- - * will create an array with empty indexes up to
- - * max_index which can cause memory issues and because
- - * the keys, which may be relevant, will be remapped
- - * otherwise.
- - *
- - * As per the ECMA and JSON specification an object may
- - * have any string as a property. Unfortunately due to
- - * a hole in the ECMA specification if the key is a
- - * ECMA reserved word or starts with a digit the
- - * parameter is only accessible using ECMAScript's
- - * bracket notation.
- - */
- -
- - // treat as a JSON object
- - 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(HTML_AJAX_JSON::isError($property))
- - return $property;
- -
- - return '{' . join(',', $properties) . '}';
- - }
- + return '{' . join(',', $properties) . '}';
- + }
- - // treat it like a regular array
- - $elements = array_map(array($this, 'encode'), $var);
- -
- - foreach($elements as $element)
- - if(HTML_AJAX_JSON::isError($element))
- - return $element;
- -
- - return '[' . join(',', $elements) . ']';
- + // treat it like a regular array
- + $elements = array_map(array($this, 'encode'), $var);
- +
- + foreach ($elements as $element) {
- + if (HTML_AJAX_JSON::isError($element)) {
- + return $element;
- + }
- + }
- +
- + return '[' . join(',', $elements) . ']';
- - case 'object':
- - $vars = get_object_vars($var);
- + case 'object':
- + $vars = get_object_vars($var);
- - $properties = array_map(array($this, 'name_value'),
- - array_keys($vars),
- - array_values($vars));
- + $properties = array_map(array($this, 'name_value'),
- + array_keys($vars),
- + array_values($vars));
- +
- + foreach ($properties as $property) {
- + if (HTML_AJAX_JSON::isError($property)) {
- + return $property;
- + }
- + }
- - foreach($properties as $property)
- - if(HTML_AJAX_JSON::isError($property))
- - return $property;
- -
- - return '{' . join(',', $properties) . '}';
- + return '{' . join(',', $properties) . '}';
- - default:
- - return ($this->use & SERVICES_JSON_SUPPRESS_ERRORS)
- - ? 'null'
- - : new HTML_AJAX_JSON_Error(gettype($var)." can not be encoded as JSON string");
- + default:
- + return ($this->use & SERVICES_JSON_SUPPRESS_ERRORS)
- + ? 'null'
- + : new HTML_AJAX_JSON_Error(gettype($var)." can not be encoded as JSON string");
- }
- }
- /**
- * array-walking function for use in generating JSON-formatted name-value pairs
- *
- - * @param string $name name of key to use
- - * @param mixed $value reference to an array element to be encoded
- + * @param string $name name of key to use
- + * @param mixed $value reference to an array element to be encoded
- *
- * @return string JSON-formatted name-value pair, like '"name":value'
- * @access private
- @@ -445,7 +462,7 @@
- /**
- * reduce a string by removing leading and trailing comments and whitespace
- *
- - * @param $str string string value to strip of comments and whitespace
- + * @param $str string string value to strip of comments and whitespace
- *
- * @return string string value stripped of comments and whitespace
- * @access private
- @@ -472,7 +489,7 @@
- /**
- * decodes a JSON string into appropriate variable
- *
- - * @param string $str JSON-formatted string
- + * @param string $str JSON-formatted string
- *
- * @return mixed number, boolean, string, array, or object
- * corresponding to given JSON input string.
- @@ -486,272 +503,272 @@
- $str = $this->reduce_string($str);
- switch (strtolower($str)) {
- - case 'true':
- - return true;
- + case 'true':
- + return true;
- - case 'false':
- - return false;
- -
- - case 'null':
- - return null;
- -
- - default:
- - if (is_numeric($str)) {
- - // Lookie-loo, it's a number
- -
- - // This would work on its own, but I'm trying to be
- - // good about returning integers where appropriate:
- - // return (float)$str;
- -
- - // Return float or int, as appropriate
- - return ((float)$str == (integer)$str)
- - ? (integer)$str
- - : (float)$str;
- -
- - } elseif (preg_match('/^("|\').*(\1)$/s', $str, $m) && $m[1] == $m[2]) {
- - // STRINGS RETURNED IN UTF-8 FORMAT
- - $delim = substr($str, 0, 1);
- - $chrs = substr($str, 1, -1);
- - $utf8 = '';
- - $strlen_chrs = strlen($chrs);
- -
- - for ($c = 0; $c < $strlen_chrs; ++$c) {
- + case 'false':
- + return false;
- +
- + case 'null':
- + return null;
- +
- + default:
- + if (is_numeric($str)) {
- + // Lookie-loo, it's a number
- +
- + // This would work on its own, but I'm trying to be
- + // good about returning integers where appropriate:
- + // return (float)$str;
- +
- + // Return float or int, as appropriate
- + return ((float)$str == (integer)$str)
- + ? (integer)$str
- + : (float)$str;
- +
- + } elseif (preg_match('/^("|\').*(\1)$/s', $str, $m) && $m[1] == $m[2]) {
- + // STRINGS RETURNED IN UTF-8 FORMAT
- + $delim = substr($str, 0, 1);
- + $chrs = substr($str, 1, -1);
- + $utf8 = '';
- + $strlen_chrs = strlen($chrs);
- +
- + for ($c = 0; $c < $strlen_chrs; ++$c) {
- +
- + $substr_chrs_c_2 = substr($chrs, $c, 2);
- + $ord_chrs_c = ord($chrs{$c});
- - $substr_chrs_c_2 = substr($chrs, $c, 2);
- - $ord_chrs_c = ord($chrs{$c});
- -
- - switch (true) {
- - case $substr_chrs_c_2 == '\b':
- - $utf8 .= chr(0x08);
- - ++$c;
- - break;
- - case $substr_chrs_c_2 == '\t':
- - $utf8 .= chr(0x09);
- - ++$c;
- - break;
- - case $substr_chrs_c_2 == '\n':
- - $utf8 .= chr(0x0A);
- - ++$c;
- - break;
- - case $substr_chrs_c_2 == '\f':
- - $utf8 .= chr(0x0C);
- - ++$c;
- - break;
- - case $substr_chrs_c_2 == '\r':
- - $utf8 .= chr(0x0D);
- - ++$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', substr($chrs, $c, 6)):
- - // single, escaped unicode character
- - $utf16 = chr(hexdec(substr($chrs, ($c + 2), 2)))
- - . chr(hexdec(substr($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:
- - // characters U-00000080 - U-000007FF, mask 110XXXXX
- - //see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
- - $utf8 .= substr($chrs, $c, 2);
- - ++$c;
- - break;
- -
- - case ($ord_chrs_c & 0xF0) == 0xE0:
- - // characters U-00000800 - U-0000FFFF, mask 1110XXXX
- - // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
- - $utf8 .= substr($chrs, $c, 3);
- - $c += 2;
- - break;
- -
- - case ($ord_chrs_c & 0xF8) == 0xF0:
- - // characters U-00010000 - U-001FFFFF, mask 11110XXX
- - // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
- - $utf8 .= substr($chrs, $c, 4);
- - $c += 3;
- - break;
- -
- - case ($ord_chrs_c & 0xFC) == 0xF8:
- - // characters U-00200000 - U-03FFFFFF, mask 111110XX
- - // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
- - $utf8 .= substr($chrs, $c, 5);
- - $c += 4;
- - break;
- -
- - case ($ord_chrs_c & 0xFE) == 0xFC:
- - // characters U-04000000 - U-7FFFFFFF, mask 1111110X
- - // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
- - $utf8 .= substr($chrs, $c, 6);
- - $c += 5;
- - break;
- -
- + switch (true) {
- + case $substr_chrs_c_2 == '\b':
- + $utf8 .= chr(0x08);
- + ++$c;
- + break;
- + case $substr_chrs_c_2 == '\t':
- + $utf8 .= chr(0x09);
- + ++$c;
- + break;
- + case $substr_chrs_c_2 == '\n':
- + $utf8 .= chr(0x0A);
- + ++$c;
- + break;
- + case $substr_chrs_c_2 == '\f':
- + $utf8 .= chr(0x0C);
- + ++$c;
- + break;
- + case $substr_chrs_c_2 == '\r':
- + $utf8 .= chr(0x0D);
- + ++$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', substr($chrs, $c, 6)):
- + // single, escaped unicode character
- + $utf16 = chr(hexdec(substr($chrs, ($c + 2), 2)))
- + . chr(hexdec(substr($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:
- + // characters U-00000080 - U-000007FF, mask 110XXXXX
- + //see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
- + $utf8 .= substr($chrs, $c, 2);
- + ++$c;
- + break;
- +
- + case ($ord_chrs_c & 0xF0) == 0xE0:
- + // characters U-00000800 - U-0000FFFF, mask 1110XXXX
- + // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
- + $utf8 .= substr($chrs, $c, 3);
- + $c += 2;
- + break;
- +
- + case ($ord_chrs_c & 0xF8) == 0xF0:
- + // characters U-00010000 - U-001FFFFF, mask 11110XXX
- + // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
- + $utf8 .= substr($chrs, $c, 4);
- + $c += 3;
- + break;
- +
- + case ($ord_chrs_c & 0xFC) == 0xF8:
- + // characters U-00200000 - U-03FFFFFF, mask 111110XX
- + // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
- + $utf8 .= substr($chrs, $c, 5);
- + $c += 4;
- + break;
- +
- + case ($ord_chrs_c & 0xFE) == 0xFC:
- + // characters U-04000000 - U-7FFFFFFF, mask 1111110X
- + // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
- + $utf8 .= substr($chrs, $c, 6);
- + $c += 5;
- + break;
- }
- -
- - return $utf8;
- +
- + }
- - } elseif (preg_match('/^\[.*\]$/s', $str) || preg_match('/^\{.*\}$/s', $str)) {
- - // array, or object notation
- + return $utf8;
- +
- + } elseif (preg_match('/^\[.*\]$/s', $str) || preg_match('/^\{.*\}$/s', $str)) {
- + // array, or object notation
- - if ($str{0} == '[') {
- - $stk = array(SERVICES_JSON_IN_ARR);
- - $arr = array();
- + 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 {
- - 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();
- - }
- + $stk = array(SERVICES_JSON_IN_OBJ);
- + $obj = new stdClass();
- }
- -
- - array_push($stk, array('what' => SERVICES_JSON_SLICE,
- - 'where' => 0,
- - 'delim' => false));
- + }
- +
- + array_push($stk, array('what' => SERVICES_JSON_SLICE,
- + 'where' => 0,
- + 'delim' => false));
- - $chrs = substr($str, 1, -1);
- - $chrs = $this->reduce_string($chrs);
- -
- - if ($chrs == '') {
- - if (reset($stk) == SERVICES_JSON_IN_ARR) {
- - return $arr;
- + $chrs = substr($str, 1, -1);
- + $chrs = $this->reduce_string($chrs);
- +
- + if ($chrs == '') {
- + if (reset($stk) == SERVICES_JSON_IN_ARR) {
- + return $arr;
- - } else {
- - return $obj;
- + } else {
- + return $obj;
- - }
- }
- + }
- - //print("\nparsing {$chrs}\n");
- -
- - $strlen_chrs = strlen($chrs);
- -
- - for ($c = 0; $c <= $strlen_chrs; ++$c) {
- -
- - $top = end($stk);
- - $substr_chrs_c_2 = substr($chrs, $c, 2);
- -
- - if (($c == $strlen_chrs) || (($chrs{$c} == ',') && ($top['what'] == SERVICES_JSON_SLICE))) {
- - // found a comma that is not inside a string, array, etc.,
- - // OR we've reached the end of the character list
- - $slice = substr($chrs, $top['where'], ($c - $top['where']));
- - array_push($stk, array('what' => SERVICES_JSON_SLICE, 'where' => ($c + 1), 'delim' => false));
- - //print("Found split at {$c}: ".substr($chrs, $top['where'], (1 + $c - $top['where']))."\n");
- -
- - if (reset($stk) == SERVICES_JSON_IN_ARR) {
- - // we are in an array, so just push an element onto the stack
- - array_push($arr, $this->decode($slice));
- -
- - } elseif (reset($stk) == SERVICES_JSON_IN_OBJ) {
- - // we are in an object, so figure
- - // out the property name and set an
- - // element in an associative array,
- - // for now
- - if (preg_match('/^\s*(["\'].*[^\\\]["\'])\s*:\s*(\S.*),?$/Uis', $slice, $parts)) {
- - // "name":value pair
- - $key = $this->decode($parts[1]);
- - $val = $this->decode($parts[2]);
- -
- - if ($this->use & SERVICES_JSON_LOOSE_TYPE) {
- - $obj[$key] = $val;
- - } else {
- - $obj->$key = $val;
- - }
- - } elseif (preg_match('/^\s*(\w+)\s*:\s*(\S.*),?$/Uis', $slice, $parts)) {
- - // name:value pair, where name is unquoted
- - $key = $parts[1];
- - $val = $this->decode($parts[2]);
- -
- - if ($this->use & SERVICES_JSON_LOOSE_TYPE) {
- - $obj[$key] = $val;
- - } else {
- - $obj->$key = $val;
- - }
- - }
- + //print("\nparsing {$chrs}\n");
- +
- + $strlen_chrs = strlen($chrs);
- +
- + for ($c = 0; $c <= $strlen_chrs; ++$c) {
- +
- + $top = end($stk);
- + $substr_chrs_c_2 = substr($chrs, $c, 2);
- +
- + if (($c == $strlen_chrs) || (($chrs{$c} == ',') && ($top['what'] == SERVICES_JSON_SLICE))) {
- + // found a comma that is not inside a string, array, etc.,
- + // OR we've reached the end of the character list
- + $slice = substr($chrs, $top['where'], ($c - $top['where']));
- + array_push($stk, array('what' => SERVICES_JSON_SLICE, 'where' => ($c + 1), 'delim' => false));
- + //print("Found split at {$c}: ".substr($chrs, $top['where'], (1 + $c - $top['where']))."\n");
- - }
- + if (reset($stk) == SERVICES_JSON_IN_ARR) {
- + // we are in an array, so just push an element onto the stack
- + array_push($arr, $this->decode($slice));
- - } elseif ((($chrs{$c} == '"') || ($chrs{$c} == "'")) && ($top['what'] != SERVICES_JSON_IN_STR)) {
- - // found a quote, and we are not inside a string
- - array_push($stk, array('what' => SERVICES_JSON_IN_STR, 'where' => $c, 'delim' => $chrs{$c}));
- - //print("Found start of string at {$c}\n");
- -
- - } elseif (($chrs{$c} == $top['delim']) &&
- - ($top['what'] == SERVICES_JSON_IN_STR) &&
- - (($chrs{$c - 1} != '\\') ||
- - ($chrs{$c - 1} == '\\' && $chrs{$c - 2} == '\\'))) {
- - // found a quote, we're in a string, and it's not escaped
- - array_pop($stk);
- - //print("Found end of string at {$c}: ".substr($chrs, $top['where'], (1 + 1 + $c - $top['where']))."\n");
- -
- - } elseif (($chrs{$c} == '[') &&
- - in_array($top['what'], array(SERVICES_JSON_SLICE, SERVICES_JSON_IN_ARR, SERVICES_JSON_IN_OBJ))) {
- - // found a left-bracket, and we are in an array, object, or slice
- - array_push($stk, array('what' => SERVICES_JSON_IN_ARR, 'where' => $c, 'delim' => false));
- - //print("Found start of array at {$c}\n");
- -
- - } elseif (($chrs{$c} == ']') && ($top['what'] == SERVICES_JSON_IN_ARR)) {
- - // found a right-bracket, and we're in an array
- - array_pop($stk);
- - //print("Found end of array at {$c}: ".substr($chrs, $top['where'], (1 + $c - $top['where']))."\n");
- -
- - } elseif (($chrs{$c} == '{') &&
- - in_array($top['what'], array(SERVICES_JSON_SLICE, SERVICES_JSON_IN_ARR, SERVICES_JSON_IN_OBJ))) {
- - // found a left-brace, and we are in an array, object, or slice
- - array_push($stk, array('what' => SERVICES_JSON_IN_OBJ, 'where' => $c, 'delim' => false));
- - //print("Found start of object at {$c}\n");
- -
- - } elseif (($chrs{$c} == '}') && ($top['what'] == SERVICES_JSON_IN_OBJ)) {
- - // found a right-brace, and we're in an object
- - array_pop($stk);
- - //print("Found end of object at {$c}: ".substr($chrs, $top['where'], (1 + $c - $top['where']))."\n");
- -
- - } elseif (($substr_chrs_c_2 == '/*') &&
- - in_array($top['what'], array(SERVICES_JSON_SLICE, SERVICES_JSON_IN_ARR, SERVICES_JSON_IN_OBJ))) {
- - // found a comment start, and we are in an array, object, or slice
- - array_push($stk, array('what' => SERVICES_JSON_IN_CMT, 'where' => $c, 'delim' => false));
- - $c++;
- - //print("Found start of comment at {$c}\n");
- -
- - } elseif (($substr_chrs_c_2 == '*/') && ($top['what'] == SERVICES_JSON_IN_CMT)) {
- - // found a comment end, and we're in one now
- - array_pop($stk);
- - $c++;
- -
- - for ($i = $top['where']; $i <= $c; ++$i)
- - $chrs = substr_replace($chrs, ' ', $i, 1);
- -
- - //print("Found end of comment at {$c}: ".substr($chrs, $top['where'], (1 + $c - $top['where']))."\n");
- + } elseif (reset($stk) == SERVICES_JSON_IN_OBJ) {
- + // we are in an object, so figure
- + // out the property name and set an
- + // element in an associative array,
- + // for now
- + if (preg_match('/^\s*(["\'].*[^\\\]["\'])\s*:\s*(\S.*),?$/Uis', $slice, $parts)) {
- + // "name":value pair
- + $key = $this->decode($parts[1]);
- + $val = $this->decode($parts[2]);
- +
- + if ($this->use & SERVICES_JSON_LOOSE_TYPE) {
- + $obj[$key] = $val;
- + } else {
- + $obj->$key = $val;
- + }
- + } elseif (preg_match('/^\s*(\w+)\s*:\s*(\S.*),?$/Uis', $slice, $parts)) {
- + // name:value pair, where name is unquoted
- + $key = $parts[1];
- + $val = $this->decode($parts[2]);
- +
- + if ($this->use & SERVICES_JSON_LOOSE_TYPE) {
- + $obj[$key] = $val;
- + } else {
- + $obj->$key = $val;
- + }
- + }
- }
- -
- - }
- -
- - if (reset($stk) == SERVICES_JSON_IN_ARR) {
- - return $arr;
- - } elseif (reset($stk) == SERVICES_JSON_IN_OBJ) {
- - return $obj;
- + } elseif ((($chrs{$c} == '"') || ($chrs{$c} == "'")) && ($top['what'] != SERVICES_JSON_IN_STR)) {
- + // found a quote, and we are not inside a string
- + array_push($stk, array('what' => SERVICES_JSON_IN_STR, 'where' => $c, 'delim' => $chrs{$c}));
- + //print("Found start of string at {$c}\n");
- +
- + } elseif (($chrs{$c} == $top['delim']) &&
- + ($top['what'] == SERVICES_JSON_IN_STR) &&
- + (($chrs{$c - 1} != '\\') ||
- + ($chrs{$c - 1} == '\\' && $chrs{$c - 2} == '\\'))) {
- + // found a quote, we're in a string, and it's not escaped
- + array_pop($stk);
- + //print("Found end of string at {$c}: ".substr($chrs, $top['where'], (1 + 1 + $c - $top['where']))."\n");
- +
- + } elseif (($chrs{$c} == '[') &&
- + in_array($top['what'], array(SERVICES_JSON_SLICE, SERVICES_JSON_IN_ARR, SERVICES_JSON_IN_OBJ))) {
- + // found a left-bracket, and we are in an array, object, or slice
- + array_push($stk, array('what' => SERVICES_JSON_IN_ARR, 'where' => $c, 'delim' => false));
- + //print("Found start of array at {$c}\n");
- +
- + } elseif (($chrs{$c} == ']') && ($top['what'] == SERVICES_JSON_IN_ARR)) {
- + // found a right-bracket, and we're in an array
- + array_pop($stk);
- + //print("Found end of array at {$c}: ".substr($chrs, $top['where'], (1 + $c - $top['where']))."\n");
- +
- + } elseif (($chrs{$c} == '{') &&
- + in_array($top['what'], array(SERVICES_JSON_SLICE, SERVICES_JSON_IN_ARR, SERVICES_JSON_IN_OBJ))) {
- + // found a left-brace, and we are in an array, object, or slice
- + array_push($stk, array('what' => SERVICES_JSON_IN_OBJ, 'where' => $c, 'delim' => false));
- + //print("Found start of object at {$c}\n");
- +
- + } elseif (($chrs{$c} == '}') && ($top['what'] == SERVICES_JSON_IN_OBJ)) {
- + // found a right-brace, and we're in an object
- + array_pop($stk);
- + //print("Found end of object at {$c}: ".substr($chrs, $top['where'], (1 + $c - $top['where']))."\n");
- +
- + } elseif (($substr_chrs_c_2 == '/*') &&
- + in_array($top['what'], array(SERVICES_JSON_SLICE, SERVICES_JSON_IN_ARR, SERVICES_JSON_IN_OBJ))) {
- + // found a comment start, and we are in an array, object, or slice
- + array_push($stk, array('what' => SERVICES_JSON_IN_CMT, 'where' => $c, 'delim' => false));
- + $c++;
- + //print("Found start of comment at {$c}\n");
- +
- + } elseif (($substr_chrs_c_2 == '*/') && ($top['what'] == SERVICES_JSON_IN_CMT)) {
- + // found a comment end, and we're in one now
- + array_pop($stk);
- + $c++;
- +
- + for ($i = $top['where']; $i <= $c; ++$i)
- + $chrs = substr_replace($chrs, ' ', $i, 1);
- +
- + //print("Found end of comment at {$c}: ".substr($chrs, $top['where'], (1 + $c - $top['where']))."\n");
- }
- }
- +
- + if (reset($stk) == SERVICES_JSON_IN_ARR) {
- + return $arr;
- +
- + } elseif (reset($stk) == SERVICES_JSON_IN_OBJ) {
- + return $obj;
- +
- + }
- +
- + }
- }
- }
- Index: AJAX/Server.php
- ===================================================================
- RCS file: /repository/pear/HTML_AJAX/AJAX/Server.php,v
- retrieving revision 1.12
- diff -u -r1.12 Server.php
- --- AJAX/Server.php 7 May 2008 21:26:19 -0000 1.12
- +++ AJAX/Server.php 6 Dec 2008 14:31:58 -0000
- @@ -470,7 +470,7 @@
- /**
- * Run readfile on input with basic error checking
- *
- - * @param string $file file to read
- + * @param string $file file to read
- * @access private
- * @todo is addslashes enough encoding for js?
- */
- @@ -508,7 +508,7 @@
- * Set the location of the client js
- *
- * @access public
- - * @param string $location Location
- + * @param string $location Location
- * @return void
- */
- function setClientJsLocation($location)
- @@ -520,8 +520,8 @@
- * Set the path to a Javascript libraries
- *
- * @access public
- - * @param string $library Library name
- - * @param string $path Path
- + * @param string $library Library name
- + * @param string $path Path
- * @return void
- */
- function setJavascriptLibraryPath($library, $path)
- @@ -533,7 +533,7 @@
- * Set the path to more than one Javascript libraries at once
- *
- * @access public
- - * @param array $paths Paths
- + * @param array $paths Paths
- * @return void
- */
- function setJavascriptLibraryPaths($paths)
- @@ -584,7 +584,7 @@
- /**
- * Clean an identifier like a class name making it safe to use
- *
- - * @param string $input
- + * @param string $input
- * @return string
- * @access private
- */
- @@ -609,7 +609,7 @@
- /**
- * Init one class
- *
- - * @param string $className
- + * @param string $className
- * @access private
- */
- function _init($className)
- @@ -633,7 +633,7 @@
- /**
- * Generate a hash from a list of files
- *
- - * @param array $files file list
- + * @param array $files file list
- * @return string a hash that can be used as an etag
- * @access private
- */
- @@ -650,7 +650,7 @@
- /**
- * Generate a hash from the api of registered classes
- *
- - * @param array $classes class list
- + * @param array $classes class list
- * @return string a hash that can be used as an etag
- * @access private
- */
- @@ -667,7 +667,7 @@
- /**
- * Generate a hash from the raw content
- *
- - * @param array $content
- + * @param array $content
- * @return string a hash that can be used as an etag
- * @access private
- */
- @@ -690,17 +690,17 @@
- /**
- * Compare eTags
- *
- - * @param string $serverETag server eTag
- + * @param string $serverETag server eTag
- * @return boolean
- * @access private
- */
- function _compareEtags($serverETag) {
- if (isset($_SERVER['HTTP_IF_NONE_MATCH'])) {
- - if (strcmp($this->ajax->_getServer('HTTP_IF_NONE_MATCH'),$serverETag) == 0) {
- + if (strcmp($this->ajax->_getServer('HTTP_IF_NONE_MATCH'),$serverETag) == 0) {
- $this->_sendCacheHeaders($serverETag,true);
- return true;
- }
- - }
- + }
- $this->_sendCacheHeaders($serverETag,false);
- return false;
- }
- @@ -708,8 +708,8 @@
- /**
- * Call a cache rule and return its retusn
- *
- - * @param string $rule Stub|Client
- - * @param mixed $payload
- + * @param string $rule Stub|Client
- + * @param mixed $payload
- * @return boolean
- * @access private
- * @todo decide if error checking is needed
- Index: AJAX/Serializer/Error.php
- ===================================================================
- RCS file: /repository/pear/HTML_AJAX/AJAX/Serializer/Error.php,v
- retrieving revision 1.7
- diff -u -r1.7 Error.php
- --- AJAX/Serializer/Error.php 13 Oct 2006 15:31:22 -0000 1.7
- +++ AJAX/Serializer/Error.php 6 Dec 2008 14:31:58 -0000
- @@ -1,20 +1,20 @@
- -<?php
- -require_once 'HTML/AJAX/Serializer/JSON.php';
- -// $Id
- -/**
- - * Error Serializer, for now just uses JSON
- - *
- - * @category HTML
- - * @package AJAX
- - * @author Joshua Eichorn <josh@bluga.net>
- - * @copyright 2005 Joshua Eichorn
- - * @license http://www.php.net/license/3_0.txt PHP License 3.0
- - * @version Release: @package_version@
- - * @link http://pear.php.net/package/HTML_AJAX
- - */
- -class HTML_AJAX_Serializer_Error extends HTML_AJAX_Serializer_JSON
- -{
- -
- -}
- -/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
- -?>
- +<?php
- +require_once 'HTML/AJAX/Serializer/JSON.php';
- +// $Id
- +/**
- + * Error Serializer, for now just uses JSON
- + *
- + * @category HTML
- + * @package AJAX
- + * @author Joshua Eichorn <josh@bluga.net>
- + * @copyright 2005 Joshua Eichorn
- + * @license http://www.php.net/license/3_0.txt PHP License 3.0
- + * @version Release: @package_version@
- + * @link http://pear.php.net/package/HTML_AJAX
- + */
- +class HTML_AJAX_Serializer_Error extends HTML_AJAX_Serializer_JSON
- +{
- +
- +}
- +/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
- +?>
- Index: AJAX/Serializer/JSON.php
- ===================================================================
- RCS file: /repository/pear/HTML_AJAX/AJAX/Serializer/JSON.php,v
- retrieving revision 1.12
- diff -u -r1.12 JSON.php
- --- AJAX/Serializer/JSON.php 7 May 2008 21:26:19 -0000 1.12
- +++ AJAX/Serializer/JSON.php 6 Dec 2008 14:31:58 -0000
- @@ -1,96 +1,102 @@
- -<?php
- -require_once 'HTML/AJAX/JSON.php';
- -// $Id: JSON.php,v 1.12 2008/05/07 21:26:19 jeichorn Exp $
- -/**
- - * JSON Serializer
- - *
- - * @category HTML
- - * @package AJAX
- - * @author Joshua Eichorn <josh@bluga.net>
- - * @copyright 2005 Joshua Eichorn
- - * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
- - * @version Release: @package_version@
- - * @link http://pear.php.net/package/PackageName
- - */
- -// {{{ class HTMLA_AJAX_Serialize_JSON
- -class HTML_AJAX_Serializer_JSON
- -{
- - // {{{ variables-properties
- - /**
- - * JSON instance
- - * @var HTML_AJAX_JSON
- - * @access private
- - */
- - var $_json;
- -
- - /**
- - * use json php extension http://www.aurore.net/projects/php-json/
- - * @access private
- - */
- - var $_jsonext;
- -
- - /**
- - * use loose typing to decode js objects into php associative arrays
- - * @access public
- - */
- - var $loose_type;
- -
- - // }}}
- - // {{{ constructor
- - function HTML_AJAX_Serializer_JSON($use_loose_type = true)
- - {
- - $this->loose_type = (bool) $use_loose_type;
- - $this->_jsonext = $this->_detect();
- - if(!$this->_jsonext) {
- - $use_loose_type = ($this->loose_type) ? SERVICES_JSON_LOOSE_TYPE : 0;
- - $this->_json = new HTML_AJAX_JSON($use_loose_type);
- - }
- - }
- - // }}}
- - // {{{ serialize
- - /**
- - * This function serializes and input passed to it.
- - *
- - * @access public
- - * @param string $input The input to serialize.
- - * @return string $input The serialized input.
- - */
- - function serialize($input)
- - {
- - if($this->_jsonext) {
- - return json_encode($input);
- - } else {
- - return $this->_json->encode($input);
- - }
- - }
- - // }}}
- - // {{{ unserialize
- - /**
- - * this function unserializes the input passed to it.
- - *
- - * @access public
- - * @param string $input The input to unserialize
- - * @return string $input The unserialized input.
- - */
- - function unserialize($input)
- - {
- - if($this->_jsonext) {
- - return json_decode($input, $this->loose_type);
- - } else {
- - return $this->_json->decode($input);
- - }
- - }
- - // }}}
- - // {{{ _detect
- - /**
- - * detects the loaded extension
- - */
- - function _detect()
- - {
- - return extension_loaded('json');
- - }
- - // }}}
- -}
- -// }}}
- -/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
- -?>
- +<?php
- +require_once 'HTML/AJAX/JSON.php';
- +// $Id: JSON.php,v 1.12 2008/05/07 21:26:19 jeichorn Exp $
- +/**
- + * JSON Serializer
- + *
- + * @category HTML
- + * @package AJAX
- + * @author Joshua Eichorn <josh@bluga.net>
- + * @copyright 2005 Joshua Eichorn
- + * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
- + * @version Release: @package_version@
- + * @link http://pear.php.net/package/HTML_AJAX
- + */
- +// {{{ class HTMLA_AJAX_Serialize_JSON
- +class HTML_AJAX_Serializer_JSON
- +{
- + // {{{ variables-properties
- + /**
- + * JSON instance
- + * @var HTML_AJAX_JSON
- + * @access private
- + */
- + var $_json;
- +
- + /**
- + * use json php extension http://www.aurore.net/projects/php-json/
- + * @access private
- + */
- + var $_jsonext;
- +
- + /**
- + * use loose typing to decode js objects into php associative arrays
- + * @access public
- + */
- + var $loose_type;
- +
- + // }}}
- + // {{{ constructor
- + function HTML_AJAX_Serializer_JSON($use_loose_type = true)
- + {
- + $this->loose_type = (bool) $use_loose_type;
- + $this->_jsonext = $this->_detect();
- +
- + if (!$this->_jsonext) {
- + $use_loose_type = $this->loose_type ? SERVICES_JSON_LOOSE_TYPE : 0;
- +
- + $this->_json = new HTML_AJAX_JSON($use_loose_type);
- + }
- + }
- + // }}}
- + // {{{ serialize
- + /**
- + * This function serializes and input passed to it.
- + *
- + * @param string $input The input to serialize.
- + *
- + * @access public
- + * @return string $input The serialized input.
- + */
- + function serialize($input)
- + {
- + if ($this->_jsonext) {
- + return json_encode($input);
- + }
- +
- + return $this->_json->encode($input);
- + }
- + // }}}
- + // {{{ unserialize
- + /**
- + * this function unserializes the input passed to it.
- + *
- + * @param string $input The input to unserialize
- + *
- + * @access public
- + * @return string $input The unserialized input.
- + */
- + function unserialize($input)
- + {
- + if ($this->_jsonext) {
- + return json_decode($input, $this->loose_type);
- + }
- +
- + return $this->_json->decode($input);
- + }
- + // }}}
- + // {{{ _detect
- + /**
- + * detects the loaded extension
- + *
- + * @return bool
- + */
- + function _detect()
- + {
- + return extension_loaded('json');
- + }
- + // }}}
- +}
- +// }}}
- +/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
- +?>
- Index: AJAX/Serializer/Null.php
- ===================================================================
- RCS file: /repository/pear/HTML_AJAX/AJAX/Serializer/Null.php,v
- retrieving revision 1.11
- diff -u -r1.11 Null.php
- --- AJAX/Serializer/Null.php 7 May 2008 21:26:19 -0000 1.11
- +++ AJAX/Serializer/Null.php 6 Dec 2008 14:31:58 -0000
- @@ -1,28 +1,28 @@
- -<?php
- -// $Id: Null.php,v 1.11 2008/05/07 21:26:19 jeichorn Exp $
- -/**
- - * Null Serializer
- - *
- - * @category HTML
- - * @package AJAX
- - * @author Joshua Eichorn <josh@bluga.net>
- - * @copyright 2005 Joshua Eichorn
- - * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
- - * @version Release: @package_version@
- - * @link http://pear.php.net/package/PackageName
- - */
- -class HTML_AJAX_Serializer_Null
- -{
- -
- - function serialize($input)
- - {
- - return $input;
- - }
- -
- - function unserialize($input)
- - {
- - return $input;
- - }
- -}
- -/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
- -?>
- +<?php
- +// $Id: Null.php,v 1.11 2008/05/07 21:26:19 jeichorn Exp $
- +/**
- + * Null Serializer
- + *
- + * @category HTML
- + * @package AJAX
- + * @author Joshua Eichorn <josh@bluga.net>
- + * @copyright 2005 Joshua Eichorn
- + * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
- + * @version Release: @package_version@
- + * @link http://pear.php.net/package/HTML_AJAX
- + */
- +class HTML_AJAX_Serializer_Null
- +{
- +
- + function serialize($input)
- + {
- + return $input;
- + }
- +
- + function unserialize($input)
- + {
- + return $input;
- + }
- +}
- +/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
- +?>
- Index: AJAX/Serializer/PHP.php
- ===================================================================
- RCS file: /repository/pear/HTML_AJAX/AJAX/Serializer/PHP.php,v
- retrieving revision 1.3
- diff -u -r1.3 PHP.php
- --- AJAX/Serializer/PHP.php 7 May 2008 21:26:19 -0000 1.3
- +++ AJAX/Serializer/PHP.php 6 Dec 2008 14:31:58 -0000
- @@ -1,88 +1,89 @@
- -<?php
- -// $Id: PHP.php,v 1.3 2008/05/07 21:26:19 jeichorn Exp $
- -/**
- - * PHP Serializer
- - *
- - * @category HTML
- - * @package AJAX
- - * @author Arpad Ray <arpad@php.net>
- - * @copyright 2005 Arpad Ray
- - * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
- - * @version Release: @package_version@
- - * @link http://pear.php.net/package/HTML_AJAX
- - */
- -class HTML_AJAX_Serializer_PHP
- -{
- - function serialize($input)
- - {
- - return serialize($input);
- - }
- -
- - /**
- - * Unserializes the given string
- - *
- - * Triggers an error if a class is found which is not
- - * in the provided array of allowed class names.
- - *
- - * @param string $input
- - * the serialized string to process
- - * @param array $allowedClasses
- - * an array of class names to check objects against
- - * before instantion
- - * @return mixed
- - * the unserialized variable on success, or false on
- - * failure. If this method fails it will also trigger
- - * a warning.
- - */
- - function unserialize($input, $allowedClasses)
- - {
- - if (version_compare(PHP_VERSION, '4.3.10', '<')
- - || (substr(PHP_VERSION, 0, 1) == '5' && version_compare(PHP_VERSION, '5.0.3', '<'))) {
- - trigger_error('Unsafe version of PHP for native unserialization');
- - return false;
- - }
- - $classes = $this->_getSerializedClassNames($input);
- - if ($classes === false) {
- - trigger_error('Invalidly serialized string');
- - return false;
- - }
- - $diff = array_diff($classes, $allowedClasses);
- - if (!empty($diff)) {
- - trigger_error('Class(es) not allowed to be serialized');
- - return false;
- - }
- - return unserialize($input);
- - }
- -
- - /**
- - * Extract class names from serialized string
- - *
- - * Adapted from code by Harry Fuecks
- - *
- - * @param string $string
- - * the serialized string to process
- - * @return mixed
- - * an array of class names found, or false if the input
- - * is invalidly formed
- - */
- - function _getSerializedClassNames($string) {
- - // Strip any string representations (which might contain object syntax)
- - while (($pos = strpos($string, 's:')) !== false) {
- - $pos2 = strpos($string, ':', $pos + 2);
- - if ($pos2 === false) {
- - // invalidly serialized string
- - return false;
- - }
- - $end = $pos + 2 + substr($string, $pos + 2, $pos2) + 1;
- - $string = substr($string, 0, $pos) . substr($string, $end);
- - }
- -
- - // Pull out the class names
- - preg_match_all('/O:[0-9]+:"(.*)"/U', $string, $matches);
- -
- - // Make sure names are unique (same object serialized twice)
- - return array_unique($matches[1]);
- - }
- -}
- -/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
- -?>
- +<?php
- +// $Id: PHP.php,v 1.3 2008/05/07 21:26:19 jeichorn Exp $
- +/**
- + * PHP Serializer
- + *
- + * @category HTML
- + * @package AJAX
- + * @author Arpad Ray <arpad@php.net>
- + * @copyright 2005 Arpad Ray
- + * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
- + * @version Release: @package_version@
- + * @link http://pear.php.net/package/HTML_AJAX
- + */
- +class HTML_AJAX_Serializer_PHP
- +{
- + function serialize($input)
- + {
- + return serialize($input);
- + }
- +
- + /**
- + * Unserializes the given string
- + *
- + * Triggers an error if a class is found which is not
- + * in the provided array of allowed class names.
- + *
- + * @param string $input the serialized string to process
- + * @param array $allowedClasses an array of class names to check objects
- + * against before instantion
- + *
- + * @return mixed
- + * the unserialized variable on success, or false on
- + * failure. If this method fails it will also trigger
- + * a warning.
- + */
- + function unserialize($input, $allowedClasses)
- + {
- + if (version_compare(PHP_VERSION, '4.3.10', '<')
- + || (substr(PHP_VERSION, 0, 1) == '5'
- + && version_compare(PHP_VERSION, '5.0.3', '<'))) {
- + trigger_error('Unsafe version of PHP for native unserialization');
- + return false;
- + }
- + $classes = $this->_getSerializedClassNames($input);
- + if ($classes === false) {
- + trigger_error('Invalidly serialized string');
- + return false;
- + }
- + $diff = array_diff($classes, $allowedClasses);
- + if (!empty($diff)) {
- + trigger_error('Class(es) not allowed to be serialized');
- + return false;
- + }
- + return unserialize($input);
- + }
- +
- + /**
- + * Extract class names from serialized string
- + *
- + * Adapted from code by Harry Fuecks
- + *
- + * @param string $string the serialized string to process
- + *
- + * @return mixed
- + * an array of class names found, or false if the input
- + * is invalidly formed
- + */
- + function _getSerializedClassNames($string)
- + {
- + // Strip any string representations (which might contain object syntax)
- + while (($pos = strpos($string, 's:')) !== false) {
- + $pos2 = strpos($string, ':', $pos + 2);
- + if ($pos2 === false) {
- + // invalidly serialized string
- + return false;
- + }
- + $end = $pos + 2 + substr($string, $pos + 2, $pos2) + 1;
- + $string = substr($string, 0, $pos) . substr($string, $end);
- + }
- +
- + // Pull out the class names
- + preg_match_all('/O:[0-9]+:"(.*)"/U', $string, $matches);
- +
- + // Make sure names are unique (same object serialized twice)
- + return array_unique($matches[1]);
- + }
- +}
- +/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
- +?>
- Index: AJAX/Serializer/Urlencoded.php
- ===================================================================
- RCS file: /repository/pear/HTML_AJAX/AJAX/Serializer/Urlencoded.php,v
- retrieving revision 1.3
- diff -u -r1.3 Urlencoded.php
- --- AJAX/Serializer/Urlencoded.php 7 May 2008 21:26:19 -0000 1.3
- +++ AJAX/Serializer/Urlencoded.php 6 Dec 2008 14:31:58 -0000
- @@ -1,67 +1,67 @@
- -<?php
- -// $Id: Urlencoded.php,v 1.3 2008/05/07 21:26:19 jeichorn Exp $
- -
- -// {{{ http_build_query
- -/**
- - * Replacement for http_build_query()
- - *
- - * @link http://php.net/function.http-build-query
- - * @author vlad_mustafin@ukr.net
- - * @author Arpad Ray <arpad@php.net>
- - */
- -if (!function_exists('http_build_query')) {
- - function http_build_query($formdata, $numeric_prefix = null, $key = null)
- - {
- - $res = array();
- - foreach ((array)$formdata as $k => $v) {
- - if (is_resource($v)) {
- - return null;
- - }
- - $tmp_key = urlencode(is_int($k) ? $numeric_prefix . $k : $k);
- - if (!is_null($key)) {
- - $tmp_key = $key . '[' . $tmp_key . ']';
- - }
- - $res[] = (is_scalar($v))
- - ? $tmp_key . '=' . urlencode($v)
- - : http_build_query($v, null , $tmp_key);
- - }
- - $separator = ini_get('arg_separator.output');
- - if (strlen($separator) == 0) {
- - $separator = '&';
- - }
- - return implode($separator, $res);
- - }
- -}
- -// }}}
- -// {{{ class HTML_AJAX_Serialize_Urlencoded
- -/**
- - * URL Encoding Serializer
- - *
- - * @category HTML
- - * @package AJAX
- - * @author Arpad Ray <arpad@php.net>
- - * @author David Coallier <davidc@php.net>
- - * @copyright 2005 Arpad Ray
- - * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
- - * @version Release: @package_version@
- - * @link http://pear.php.net/package/HTML_AJAX
- - */
- -class HTML_AJAX_Serializer_Urlencoded
- -{
- - // {{{ serialize
- - function serialize($input)
- - {
- - return http_build_query(array('_HTML_AJAX' => $input));
- - }
- - // }}}
- - // {{{ unserialize
- - function unserialize($input)
- - {
- - parse_str($input, $ret);
- - return (isset($ret['_HTML_AJAX']) ? $ret['_HTML_AJAX'] : $ret);
- - }
- - // }}}
- -}
- -// }}}
- -/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
- -?>
- +<?php
- +// $Id: Urlencoded.php,v 1.3 2008/05/07 21:26:19 jeichorn Exp $
- +
- +// {{{ http_build_query
- +/**
- + * Replacement for http_build_query()
- + *
- + * @link http://php.net/function.http-build-query
- + * @author vlad_mustafin@ukr.net
- + * @author Arpad Ray <arpad@php.net>
- + */
- +if (!function_exists('http_build_query')) {
- + function http_build_query($formdata, $numeric_prefix = null, $key = null)
- + {
- + $res = array();
- + foreach ((array)$formdata as $k => $v) {
- + if (is_resource($v)) {
- + return null;
- + }
- + $tmp_key = urlencode(is_int($k) ? $numeric_prefix . $k : $k);
- + if (!is_null($key)) {
- + $tmp_key = $key . '[' . $tmp_key . ']';
- + }
- + $res[] = (is_scalar($v))
- + ? $tmp_key . '=' . urlencode($v)
- + : http_build_query($v, null, $tmp_key);
- + }
- + $separator = ini_get('arg_separator.output');
- + if (strlen($separator) == 0) {
- + $separator = '&';
- + }
- + return implode($separator, $res);
- + }
- +}
- +// }}}
- +// {{{ class HTML_AJAX_Serialize_Urlencoded
- +/**
- + * URL Encoding Serializer
- + *
- + * @category HTML
- + * @package AJAX
- + * @author Arpad Ray <arpad@php.net>
- + * @author David Coallier <davidc@php.net>
- + * @copyright 2005 Arpad Ray
- + * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
- + * @version Release: @package_version@
- + * @link http://pear.php.net/package/HTML_AJAX
- + */
- +class HTML_AJAX_Serializer_Urlencoded
- +{
- + // {{{ serialize
- + function serialize($input)
- + {
- + return http_build_query(array('_HTML_AJAX' => $input));
- + }
- + // }}}
- + // {{{ unserialize
- + function unserialize($input)
- + {
- + parse_str($input, $ret);
- + return (isset($ret['_HTML_AJAX']) ? $ret['_HTML_AJAX'] : $ret);
- + }
- + // }}}
- +}
- +// }}}
- +/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
- +?>
- Index: AJAX/Serializer/XML.php
- ===================================================================
- RCS file: /repository/pear/HTML_AJAX/AJAX/Serializer/XML.php,v
- retrieving revision 1.1
- diff -u -r1.1 XML.php
- --- AJAX/Serializer/XML.php 7 May 2008 21:28:11 -0000 1.1
- +++ AJAX/Serializer/XML.php 6 Dec 2008 14:31:58 -0000
- @@ -1,88 +1,83 @@
- -<?php
- -// $Id: XML.php,v 1.1 2008/05/07 21:28:11 jeichorn Exp $
- -/**
- - * XML Serializer - does NOT need a js serializer, use responseXML property in XmlHttpRequest
- - *
- - * @category HTML
- - * @package AJAX
- - * @author Elizabeth Smith <auroraeosrose@gmail.com>
- - * @copyright 2005-2006 Elizabeth Smith
- - * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
- - * @version Release: @package_version@
- - * @link http://pear.php.net/package/PackageName
- - */
- -class HTML_AJAX_Serializer_XML
- -{
- -
- - /**
- - * Serializes a domdocument into an xml string
- - *
- - * Uses dom or domxml to dump a string from a DomDocument instance
- - * remember dom is always the default and this will die horribly without
- - * a domdocument instance
- - *
- - * @access public
- - * @param object $input instanceof DomDocument
- - * @return string xml string of DomDocument
- - */
- - function serialize($input)
- - {
- - if(empty($input))
- - {
- - return $input;
- - }
- - // we check for the dom extension
- - elseif (extension_loaded('Dom'))
- - {
- - return $input->saveXml();
- - }
- - // then will check for domxml
- - elseif (extension_loaded('Domxml'))
- - {
- - return $input->dump_mem();
- - }
- - // will throw an error
- - else {
- - $error = new HTML_AJAX_Serializer_Error();
- - $this->serializerNewType = 'Error';
- - return $error->serialize(array('errStr'=>"Missing PHP Dom extension direct XML won't work"));
- - }
- - }
- -
- - /**
- - * Unserializes the xml string sent from the document
- - *
- - * Uses dom or domxml to pump a string into a DomDocument instance
- - * remember dom is always the default and this will die horribly without
- - * one or the other, and will throw warnings if you have bad xml
- - *
- - * @access public
- - * @param string $input The input to serialize.
- - * @return object instanceofDomDocument
- - */
- - function unserialize($input)
- - {
- - if(empty($input))
- - {
- - return $input;
- - }
- - // we check for the dom extension
- - elseif (extension_loaded('Dom'))
- - {
- - $doc = new DOMDocument();
- - $doc->loadXML($input);
- - return $doc;
- - }
- - // then we check for the domxml extensions
- - elseif (extension_loaded('Domxml'))
- - {
- - return domxml_open_mem($input);
- - }
- - // we give up and just return the xml directly
- - else
- - {
- - return $input;
- - }
- - }
- -}
- -?>
- +<?php
- +// $Id: XML.php,v 1.1 2008/05/07 21:28:11 jeichorn Exp $
- +/**
- + * XML Serializer - does NOT need a js serializer,
- + * use responseXML property in XmlHttpRequest
- + *
- + * @category HTML
- + * @package AJAX
- + * @author Elizabeth Smith <auroraeosrose@gmail.com>
- + * @copyright 2005-2006 Elizabeth Smith
- + * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
- + * @version Release: @package_version@
- + * @link http://pear.php.net/package/PackageName
- + */
- +class HTML_AJAX_Serializer_XML
- +{
- +
- + /**
- + * Serializes a domdocument into an xml string
- + *
- + * Uses dom or domxml to dump a string from a DomDocument instance
- + * remember dom is always the default and this will die horribly without
- + * a domdocument instance
- + *
- + * @param object $input instanceof DomDocument
- + *
- + * @access public
- + * @return string xml string of DomDocument
- + */
- + function serialize($input)
- + {
- + if (empty($input)) {
- + return $input;
- + }
- +
- + if (extension_loaded('Dom')) {
- + return $input->saveXml();
- + }
- + if (extension_loaded('Domxml')) {
- + return $input->dump_mem();
- + }
- +
- + $error = new HTML_AJAX_Serializer_Error();
- + $this->serializerNewType = 'Error';
- +
- + $message = "Missing PHP Dom extension direct XML won't work";
- +
- + return $error->serialize(array('errStr'=> $message));
- + }
- +
- + /**
- + * Unserializes the xml string sent from the document
- + *
- + * Uses dom or domxml to pump a string into a DomDocument instance
- + * remember dom is always the default and this will die horribly without
- + * one or the other, and will throw warnings if you have bad xml
- + *
- + * @param string $input The input to serialize.
- + *
- + * @access public
- + * @return object instanceofDomDocument
- + */
- + function unserialize($input)
- + {
- + if (empty($input)) {
- + return $input;
- + }
- +
- + if (extension_loaded('Dom')) {
- + $doc = new DOMDocument();
- + $doc->loadXML($input);
- + return $doc;
- + }
- +
- + if (extension_loaded('Domxml')) {
- + return domxml_open_mem($input);
- + }
- +
- + // we give up and just return the xml directly
- + return $input;
- + }
- +}
- +?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement