Advertisement
Guest User

CloCkWeRX

a guest
Dec 6th, 2008
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 92.94 KB | None | 0 0
  1. ? phpcs-r619.diff
  2. ? phpcs.xml
  3. Index: AJAX.php
  4. ===================================================================
  5. RCS file: /repository/pear/HTML_AJAX/AJAX.php,v
  6. retrieving revision 1.12
  7. diff -u -r1.12 AJAX.php
  8. --- AJAX.php 7 May 2008 21:26:19 -0000 1.12
  9. +++ AJAX.php 6 Dec 2008 14:31:57 -0000
  10. @@ -305,7 +305,7 @@
  11. $client .= "}\n\n";
  12.  
  13. if ($this->packJavaScript) {
  14. - $client = $this->packJavaScript($client);
  15. + $client = $this->packJavaScript($client);
  16. }
  17. return $client;
  18. }
  19. Index: AJAX/Helper.php
  20. ===================================================================
  21. RCS file: /repository/pear/HTML_AJAX/AJAX/Helper.php,v
  22. retrieving revision 1.5
  23. diff -u -r1.5 Helper.php
  24. --- AJAX/Helper.php 7 May 2008 21:26:19 -0000 1.5
  25. +++ AJAX/Helper.php 6 Dec 2008 14:31:57 -0000
  26. @@ -23,58 +23,58 @@
  27. */
  28.  
  29. class HTML_AJAX_Helper
  30.  
  31. {
  32.  
  33. - /**
  34.  
  35. - * URL where an HTML_AJAX_Server instance is serving up clients and taking ajax requests
  36.  
  37. - */
  38.  
  39. - var $serverUrl = 'server.php';
  40.  
  41. -
  42.  
  43. - /**
  44.  
  45. - * JS libraries to include
  46.  
  47. - *
  48.  
  49. - * @var array
  50.  
  51. - */
  52.  
  53. - var $jsLibraries = array('Util','Main','Request','HttpClient','Dispatcher','Behavior','Loading','JSON','iframe');
  54.  
  55. -
  56.  
  57. - /**
  58.  
  59. - * Remote class stubs to include
  60.  
  61. - */
  62.  
  63. - var $stubs = array();
  64.  
  65. + /**
  66.  
  67. + * URL where an HTML_AJAX_Server instance is serving up clients and taking ajax requests
  68.  
  69. + */
  70.  
  71. + var $serverUrl = 'server.php';
  72.  
  73. +
  74.  
  75. + /**
  76.  
  77. + * JS libraries to include
  78.  
  79. + *
  80.  
  81. + * @var array
  82.  
  83. + */
  84.  
  85. + var $jsLibraries = array('Util','Main','Request','HttpClient','Dispatcher','Behavior','Loading','JSON','iframe');
  86.  
  87. +
  88.  
  89. + /**
  90.  
  91. + * Remote class stubs to include
  92.  
  93. + */
  94.  
  95. + var $stubs = array();
  96.  
  97.  
  98.  
  99. /**
  100.  
  101. * Combine jsLibraries into a single require and remove duplicates
  102.  
  103. */
  104.  
  105. var $combineJsIncludes = false;
  106.  
  107.  
  108.  
  109. - /**
  110.  
  111. - * Include all needed libraries, stubs, and set defaultServer
  112.  
  113. - *
  114.  
  115. - * @return string
  116.  
  117. - */
  118.  
  119. - function setupAJAX()
  120.  
  121. - {
  122.  
  123. - $libs = array(0=>array());
  124.  
  125. + /**
  126.  
  127. + * Include all needed libraries, stubs, and set defaultServer
  128.  
  129. + *
  130.  
  131. + * @return string
  132.  
  133. + */
  134.  
  135. + function setupAJAX()
  136.  
  137. + {
  138.  
  139. + $libs = array(0=>array());
  140.  
  141. $combinedLibs = array();
  142.  
  143.  
  144.  
  145. $this->jsLibraries = array_unique($this->jsLibraries);
  146.  
  147. - foreach($this->jsLibraries as $library) {
  148.  
  149. - if (is_array($library)) {
  150.  
  151. + foreach($this->jsLibraries as $library) {
  152.  
  153. + if (is_array($library)) {
  154.  
  155. $library = array_unique($library);
  156.  
  157. $combinedLibs = array_merge($combinedLibs,$library);
  158.  
  159. - $libs[] = implode(',',$library);
  160.  
  161. - }
  162.  
  163. - else {
  164.  
  165. - $libs[0][] = $library;
  166.  
  167. + $libs[] = implode(',',$library);
  168.  
  169. + }
  170.  
  171. + else {
  172.  
  173. + $libs[0][] = $library;
  174.  
  175. $combinedLibs[] = $library;
  176.  
  177. - }
  178.  
  179. - }
  180.  
  181. - $libs[0] = implode(',',$libs[0]);
  182.  
  183. + }
  184.  
  185. + }
  186.  
  187. + $libs[0] = implode(',',$libs[0]);
  188.  
  189.  
  190.  
  191. $sep = '?';
  192.  
  193. if (strstr($this->serverUrl,'?')) {
  194.  
  195. $sep = '&';
  196.  
  197. }
  198.  
  199.  
  200.  
  201. - $ret = '';
  202.  
  203. + $ret = '';
  204.  
  205. if ($this->combineJsIncludes == true) {
  206.  
  207. $list = implode(',',$combinedLibs);
  208.  
  209. $ret .= "<script type='text/javascript' src='{$this->serverUrl}{$sep}client={$list}'></script>\n";
  210.  
  211. @@ -85,91 +85,91 @@
  212. }
  213.  
  214. }
  215.  
  216.  
  217.  
  218. - if (count($this->stubs) > 0) {
  219.  
  220. - $stubs = implode(',',$this->stubs);
  221.  
  222. - $ret .= "<script type='text/javascript' src='{$this->serverUrl}{$sep}stub={$stubs}'></script>\n";
  223.  
  224. - }
  225.  
  226. - $ret .= $this->encloseInScript('HTML_AJAX.defaultServerUrl = '.$this->escape($this->serverUrl));
  227.  
  228. - return $ret;
  229.  
  230. - }
  231.  
  232. -
  233.  
  234. - /**
  235.  
  236. - * Create a custom Loading message
  237.  
  238. - *
  239.  
  240. - * @param string $body HTML body of the loading div
  241.  
  242. - * @param string $class CSS class of the div
  243.  
  244. - * @param string $style style tag of the loading div
  245.  
  246. - */
  247.  
  248. - function loadingMessage($body, $class = 'HTML_AJAX_Loading',
  249.  
  250. - $style = 'position: absolute; top: 0; right: 0; background-color: red; width: 80px; padding: 4px; display: none')
  251.  
  252. - {
  253.  
  254. - return "<div id='HTML_AJAX_LOADING' class='{$class}' style=\"{$style}\">{$body}</div>\n";
  255.  
  256. - }
  257.  
  258. -
  259.  
  260. - /**
  261.  
  262. - * Update the contents of an element using ajax
  263.  
  264. - *
  265.  
  266. - * @param string $id id of the element to update
  267.  
  268. - * @param string|array $update Either a url to update with or a array like array('class','method')
  269.  
  270. - * @param string $type replace or append
  271.  
  272. - * @param boolean $enclose
  273.  
  274. - */
  275.  
  276. - function updateElement($id, $update, $type, $enclose = false) {
  277.  
  278. - if (is_array($update)) {
  279.  
  280. - $updateStr = "";
  281.  
  282. - $comma = '';
  283.  
  284. - foreach($update as $item) {
  285.  
  286. - $updateStr .= $comma.$this->escape($item);
  287.  
  288. - $comma = ',';
  289.  
  290. - }
  291.  
  292. - }
  293.  
  294. - else {
  295.  
  296. - $updateStr = $this->escape($update);
  297.  
  298. - }
  299.  
  300. -
  301.  
  302. - $ret = "HTML_AJAX.{$type}(".$this->escape($id).",{$updateStr});\n";
  303.  
  304. - if ($enclose) {
  305.  
  306. - $ret = $this->encloseInScript($ret);
  307.  
  308. - }
  309.  
  310. - return $ret;
  311.  
  312. - }
  313.  
  314. -
  315.  
  316. - /**
  317.  
  318. - * Escape a string and add quotes allowing it to be a javascript paramater
  319.  
  320. - *
  321.  
  322. - * @param string $input
  323.  
  324. - * @return string
  325.  
  326. - * @todo do something here besides a quick hack
  327.  
  328. - */
  329.  
  330. - function escape($input) {
  331.  
  332. - return "'".addslashes($input)."'";
  333.  
  334. - }
  335.  
  336. -
  337.  
  338. - /**
  339.  
  340. - * Enclose a string in a script block
  341.  
  342. - *
  343.  
  344. - * @param string $input
  345.  
  346. - * @return string
  347.  
  348. - */
  349.  
  350. - function encloseInScript($input) {
  351.  
  352. - return '<script type="text/javascript">'.$input."</script>\n";
  353.  
  354. - }
  355.  
  356. -
  357.  
  358. - /**
  359.  
  360. - * Generate a JSON String
  361.  
  362. - *
  363.  
  364. - * @param string $input
  365.  
  366. - * @return string
  367.  
  368. - */
  369.  
  370. - function jsonEncode($input) {
  371.  
  372. - require_once 'HTML/AJAX/Serializer/JSON.php';
  373.  
  374. -
  375.  
  376. - $s = new HTML_AJAX_Serializer_JSON();
  377.  
  378. - return $s->serialize($input);
  379.  
  380. - }
  381.  
  382. + if (count($this->stubs) > 0) {
  383.  
  384. + $stubs = implode(',',$this->stubs);
  385.  
  386. + $ret .= "<script type='text/javascript' src='{$this->serverUrl}{$sep}stub={$stubs}'></script>\n";
  387.  
  388. + }
  389.  
  390. + $ret .= $this->encloseInScript('HTML_AJAX.defaultServerUrl = '.$this->escape($this->serverUrl));
  391.  
  392. + return $ret;
  393.  
  394. + }
  395.  
  396. +
  397.  
  398. + /**
  399.  
  400. + * Create a custom Loading message
  401.  
  402. + *
  403.  
  404. + * @param string $body HTML body of the loading div
  405.  
  406. + * @param string $class CSS class of the div
  407.  
  408. + * @param string $style style tag of the loading div
  409.  
  410. + */
  411.  
  412. + function loadingMessage($body, $class = 'HTML_AJAX_Loading',
  413.  
  414. + $style = 'position: absolute; top: 0; right: 0; background-color: red; width: 80px; padding: 4px; display: none')
  415.  
  416. + {
  417.  
  418. + return "<div id='HTML_AJAX_LOADING' class='{$class}' style=\"{$style}\">{$body}</div>\n";
  419.  
  420. + }
  421.  
  422. +
  423.  
  424. + /**
  425.  
  426. + * Update the contents of an element using ajax
  427.  
  428. + *
  429.  
  430. + * @param string $id id of the element to update
  431.  
  432. + * @param string|array $update Either a url to update with or a array like array('class','method')
  433.  
  434. + * @param string $type replace or append
  435.  
  436. + * @param boolean $enclose
  437.  
  438. + */
  439.  
  440. + function updateElement($id, $update, $type, $enclose = false) {
  441.  
  442. + if (is_array($update)) {
  443.  
  444. + $updateStr = "";
  445.  
  446. + $comma = '';
  447.  
  448. + foreach($update as $item) {
  449.  
  450. + $updateStr .= $comma.$this->escape($item);
  451.  
  452. + $comma = ',';
  453.  
  454. + }
  455.  
  456. + }
  457.  
  458. + else {
  459.  
  460. + $updateStr = $this->escape($update);
  461.  
  462. + }
  463.  
  464. +
  465.  
  466. + $ret = "HTML_AJAX.{$type}(".$this->escape($id).",{$updateStr});\n";
  467.  
  468. + if ($enclose) {
  469.  
  470. + $ret = $this->encloseInScript($ret);
  471.  
  472. + }
  473.  
  474. + return $ret;
  475.  
  476. + }
  477.  
  478. +
  479.  
  480. + /**
  481.  
  482. + * Escape a string and add quotes allowing it to be a javascript paramater
  483.  
  484. + *
  485.  
  486. + * @param string $input
  487.  
  488. + * @return string
  489.  
  490. + * @todo do something here besides a quick hack
  491.  
  492. + */
  493.  
  494. + function escape($input) {
  495.  
  496. + return "'".addslashes($input)."'";
  497.  
  498. + }
  499.  
  500.  
  501.  
  502. - /**
  503.  
  504. - * Check the request headers to see if this is an AJAX request
  505.  
  506. + /**
  507.  
  508. + * Enclose a string in a script block
  509.  
  510. + *
  511.  
  512. + * @param string $input
  513.  
  514. + * @return string
  515.  
  516. + */
  517.  
  518. + function encloseInScript($input) {
  519.  
  520. + return '<script type="text/javascript">'.$input."</script>\n";
  521.  
  522. + }
  523.  
  524. +
  525.  
  526. + /**
  527.  
  528. + * Generate a JSON String
  529.  
  530. + *
  531.  
  532. + * @param string $input
  533.  
  534. + * @return string
  535.  
  536. + */
  537.  
  538. + function jsonEncode($input) {
  539.  
  540. + require_once 'HTML/AJAX/Serializer/JSON.php';
  541.  
  542. +
  543.  
  544. + $s = new HTML_AJAX_Serializer_JSON();
  545.  
  546. + return $s->serialize($input);
  547.  
  548. + }
  549.  
  550. +
  551.  
  552. + /**
  553.  
  554. + * Check the request headers to see if this is an AJAX request
  555.  
  556. *
  557.  
  558. * @return boolean
  559.  
  560. */
  561.  
  562. Index: AJAX/JSON.php
  563. ===================================================================
  564. RCS file: /repository/pear/HTML_AJAX/AJAX/JSON.php,v
  565. retrieving revision 1.11
  566. diff -u -r1.11 JSON.php
  567. --- AJAX/JSON.php 7 May 2008 21:26:19 -0000 1.11
  568. +++ AJAX/JSON.php 6 Dec 2008 14:31:58 -0000
  569. @@ -1,19 +1,13 @@
  570. <?php
  571. /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
  572. -/**
  573. - * This is an embedded version of HTML_AJAX_JSON since it has yet to have a PEAR release
  574. - * it has been renamed to HTML_AJAX_JSON so no problems will be caused by an eventual release
  575. - * Feel free to report bugs against it to HTML_AJAX
  576. - */
  577. -
  578. -/**
  579. - * Needed for compat functions
  580. - */
  581. -require_once 'HTML/AJAX.php';
  582.  
  583. /**
  584. * Converts to and from JSON format.
  585. *
  586. + * This is an embedded version of HTML_AJAX_JSON since it has yet to have a PEAR release
  587. + * it has been renamed to HTML_AJAX_JSON so no problems will be caused by an eventual release
  588. + * Feel free to report bugs against it to HTML_AJAX
  589. + *
  590. * JSON (JavaScript Object Notation) is a lightweight data-interchange
  591. * format. It is easy for humans to read and write. It is easy for machines
  592. * to parse and generate. It is based on a subset of the JavaScript
  593. @@ -55,35 +49,40 @@
  594. * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  595. * DAMAGE.
  596. *
  597. - * @category
  598. - * @package HTML_AJAX_JSON
  599. - * @author Michal Migurski <mike-json@teczno.com>
  600. - * @author Matt Knapp <mdknapp[at]gmail[dot]com>
  601. - * @author Brett Stimmerman <brettstimmerman[at]gmail[dot]com>
  602. - * @copyright 2005 Michal Migurski
  603. - * @license http://www.opensource.org/licenses/bsd-license.php
  604. - * @link http://pear.php.net/pepr/pepr-proposal-show.php?id=198
  605. + * @category HTML
  606. + * @package HTML_AJAX_JSON
  607. + * @author Michal Migurski <mike-json@teczno.com>
  608. + * @author Matt Knapp <mdknapp@gmail.com>
  609. + * @author Brett Stimmerman <brettstimmerman@gmail.com>
  610. + * @copyright 2005 Michal Migurski
  611. + * @license http://www.opensource.org/licenses/bsd-license.php BSD
  612. + * @link http://pear.php.net/pepr/pepr-proposal-show.php?id=198
  613. */
  614.  
  615. /**
  616. + * Needed for compat functions
  617. + */
  618. +require_once 'HTML/AJAX.php';
  619. +
  620. +/**
  621. * Marker constant for HTML_AJAX_JSON::decode(), used to flag stack state
  622. */
  623. -define('SERVICES_JSON_SLICE', 1);
  624. +define('SERVICES_JSON_SLICE', 1);
  625.  
  626. /**
  627. * Marker constant for HTML_AJAX_JSON::decode(), used to flag stack state
  628. */
  629. -define('SERVICES_JSON_IN_STR', 2);
  630. +define('SERVICES_JSON_IN_STR', 2);
  631.  
  632. /**
  633. * Marker constant for HTML_AJAX_JSON::decode(), used to flag stack state
  634. */
  635. -define('SERVICES_JSON_IN_ARR', 3);
  636. +define('SERVICES_JSON_IN_ARR', 3);
  637.  
  638. /**
  639. * Marker constant for HTML_AJAX_JSON::decode(), used to flag stack state
  640. */
  641. -define('SERVICES_JSON_IN_OBJ', 4);
  642. +define('SERVICES_JSON_IN_OBJ', 4);
  643.  
  644. /**
  645. * Marker constant for HTML_AJAX_JSON::decode(), used to flag stack state
  646. @@ -120,25 +119,34 @@
  647. * $input = file_get_contents('php://input', 1000000);
  648. * $value = $json->decode($input);
  649. * </code>
  650. + *
  651. + * @category HTML
  652. + * @package HTML_AJAX_JSON
  653. + * @author Michal Migurski <mike-json@teczno.com>
  654. + * @author Matt Knapp <mdknapp@gmail.com>
  655. + * @author Brett Stimmerman <brettstimmerman@gmail.com>
  656. + * @copyright 2005 Michal Migurski
  657. + * @license http://www.opensource.org/licenses/bsd-license.php BSD
  658. + * @link http://pear.php.net/pepr/pepr-proposal-show.php?id=198
  659. */
  660. class HTML_AJAX_JSON
  661. {
  662. - /**
  663. - * constructs a new JSON instance
  664. - *
  665. - * @param int $use object behavior flags; combine with boolean-OR
  666. - *
  667. - * possible values:
  668. - * - SERVICES_JSON_LOOSE_TYPE: loose typing.
  669. - * "{...}" syntax creates associative arrays
  670. - * instead of objects in decode().
  671. - * - SERVICES_JSON_SUPPRESS_ERRORS: error suppression.
  672. - * Values which can't be encoded (e.g. resources)
  673. - * appear as NULL instead of throwing errors.
  674. - * By default, a deeply-nested resource will
  675. - * bubble up with an error, so all return values
  676. - * from encode() should be checked with isError()
  677. - */
  678. + /**
  679. + * constructs a new JSON instance
  680. + *
  681. + * @param int $use object behavior flags; combine with boolean-OR
  682. + *
  683. + * possible values:
  684. + * - SERVICES_JSON_LOOSE_TYPE: loose typing.
  685. + * "{...}" syntax creates associative arrays
  686. + * instead of objects in decode().
  687. + * - SERVICES_JSON_SUPPRESS_ERRORS: error suppression.
  688. + * Values which can't be encoded (e.g. resources)
  689. + * appear as NULL instead of throwing errors.
  690. + * By default, a deeply-nested resource will
  691. + * bubble up with an error, so all return values
  692. + * from encode() should be checked with isError()
  693. + */
  694. function HTML_AJAX_JSON($use = 0)
  695. {
  696. $this->use = $use;
  697. @@ -151,7 +159,8 @@
  698. * provides a slower PHP-only method for installations
  699. * that lack the multibye string extension.
  700. *
  701. - * @param string $utf16 UTF-16 character
  702. + * @param string $utf16 UTF-16 character
  703. + *
  704. * @return string UTF-8 character
  705. * @access private
  706. */
  707. @@ -164,23 +173,23 @@
  708. $bytes = (ord($utf16{0}) << 8) | ord($utf16{1});
  709.  
  710. switch(true) {
  711. - case ((0x7F & $bytes) == $bytes):
  712. - // this case should never be reached, because we are in ASCII range
  713. - // see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
  714. - return chr(0x7F & $bytes);
  715. -
  716. - case (0x07FF & $bytes) == $bytes:
  717. - // return a 2-byte UTF-8 character
  718. - // see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
  719. - return chr(0xC0 | (($bytes >> 6) & 0x1F))
  720. - . chr(0x80 | ($bytes & 0x3F));
  721. -
  722. - case (0xFFFF & $bytes) == $bytes:
  723. - // return a 3-byte UTF-8 character
  724. - // see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
  725. - return chr(0xE0 | (($bytes >> 12) & 0x0F))
  726. - . chr(0x80 | (($bytes >> 6) & 0x3F))
  727. - . chr(0x80 | ($bytes & 0x3F));
  728. + case ((0x7F & $bytes) == $bytes):
  729. + // this case should never be reached, because we are in ASCII range
  730. + // see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
  731. + return chr(0x7F & $bytes);
  732. +
  733. + case (0x07FF & $bytes) == $bytes:
  734. + // return a 2-byte UTF-8 character
  735. + // see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
  736. + return chr(0xC0 | (($bytes >> 6) & 0x1F))
  737. + . chr(0x80 | ($bytes & 0x3F));
  738. +
  739. + case (0xFFFF & $bytes) == $bytes:
  740. + // return a 3-byte UTF-8 character
  741. + // see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
  742. + return chr(0xE0 | (($bytes >> 12) & 0x0F))
  743. + . chr(0x80 | (($bytes >> 6) & 0x3F))
  744. + . chr(0x80 | ($bytes & 0x3F));
  745. }
  746.  
  747. // ignoring UTF-32 for now, sorry
  748. @@ -194,36 +203,38 @@
  749. * provides a slower PHP-only method for installations
  750. * that lack the multibye string extension.
  751. *
  752. - * @param string $utf8 UTF-8 character
  753. + * @param string $utf8 UTF-8 character
  754. + *
  755. * @return string UTF-16 character
  756. * @access private
  757. */
  758. function utf82utf16($utf8)
  759. {
  760. // oh please oh please oh please oh please oh please
  761. - if(function_exists('mb_convert_encoding'))
  762. + if (function_exists('mb_convert_encoding')) {
  763. return mb_convert_encoding($utf8, 'UTF-16', 'UTF-8');
  764. + }
  765.  
  766. switch(strlen($utf8)) {
  767. - case 1:
  768. - // this case should never be reached, because we are in ASCII range
  769. - // see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
  770. - return $ut8;
  771. -
  772. - case 2:
  773. - // return a UTF-16 character from a 2-byte UTF-8 char
  774. - // see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
  775. - return chr(0x07 & (ord($utf8{0}) >> 2))
  776. - . chr((0xC0 & (ord($utf8{0}) << 6))
  777. - | (0x3F & ord($utf8{1})));
  778. -
  779. - case 3:
  780. - // return a UTF-16 character from a 3-byte UTF-8 char
  781. - // see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
  782. - return chr((0xF0 & (ord($utf8{0}) << 4))
  783. - | (0x0F & (ord($utf8{1}) >> 2)))
  784. - . chr((0xC0 & (ord($utf8{1}) << 6))
  785. - | (0x7F & ord($utf8{2})));
  786. + case 1:
  787. + // this case should never be reached, because we are in ASCII range
  788. + // see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
  789. + return $ut8;
  790. +
  791. + case 2:
  792. + // return a UTF-16 character from a 2-byte UTF-8 char
  793. + // see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
  794. + return chr(0x07 & (ord($utf8{0}) >> 2))
  795. + . chr((0xC0 & (ord($utf8{0}) << 6))
  796. + | (0x3F & ord($utf8{1})));
  797. +
  798. + case 3:
  799. + // return a UTF-16 character from a 3-byte UTF-8 char
  800. + // see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
  801. + return chr((0xF0 & (ord($utf8{0}) << 4))
  802. + | (0x0F & (ord($utf8{1}) >> 2)))
  803. + . chr((0xC0 & (ord($utf8{1}) << 6))
  804. + | (0x7F & ord($utf8{2})));
  805. }
  806.  
  807. // ignoring UTF-32 for now, sorry
  808. @@ -233,10 +244,10 @@
  809. /**
  810. * encodes an arbitrary variable into JSON format
  811. *
  812. - * @param mixed $var any number, boolean, string, array, or object to be encoded.
  813. - * see argument 1 to HTML_AJAX_JSON() above for array-parsing behavior.
  814. - * if var is a strng, note that encode() always expects it
  815. - * to be in ASCII or UTF-8 format!
  816. + * @param mixed $var any number, boolean, string, array, or object to be encoded.
  817. + * see argument 1 to HTML_AJAX_JSON() above for array-parsing behavior.
  818. + * if var is a strng, note that encode() always expects it
  819. + * to be in ASCII or UTF-8 format!
  820. *
  821. * @return mixed JSON string representation of input var or an error if a problem occurs
  822. * @access public
  823. @@ -244,190 +255,196 @@
  824. function encode($var)
  825. {
  826. switch (gettype($var)) {
  827. - case 'boolean':
  828. - return $var ? 'true' : 'false';
  829. + case 'boolean':
  830. + return $var ? 'true' : 'false';
  831. +
  832. + case 'NULL':
  833. + return 'null';
  834. +
  835. + case 'integer':
  836. + return (int) $var;
  837.  
  838. - case 'NULL':
  839. - return 'null';
  840. + case 'double':
  841. + case 'float':
  842. + return (float) $var;
  843. +
  844. + case 'string':
  845. + // STRINGS ARE EXPECTED TO BE IN ASCII OR UTF-8 FORMAT
  846. + $ascii = '';
  847. + $strlen_var = strlen($var);
  848. +
  849. + /*
  850. + * Iterate over every character in the string,
  851. + * escaping with a slash or encoding to UTF-8 where necessary
  852. + */
  853. + for ($c = 0; $c < $strlen_var; ++$c) {
  854. +
  855. + $ord_var_c = ord($var{$c});
  856. +
  857. + switch (true) {
  858. + case $ord_var_c == 0x08:
  859. + $ascii .= '\b';
  860. + break;
  861. + case $ord_var_c == 0x09:
  862. + $ascii .= '\t';
  863. + break;
  864. + case $ord_var_c == 0x0A:
  865. + $ascii .= '\n';
  866. + break;
  867. + case $ord_var_c == 0x0C:
  868. + $ascii .= '\f';
  869. + break;
  870. + case $ord_var_c == 0x0D:
  871. + $ascii .= '\r';
  872. + break;
  873. +
  874. + case $ord_var_c == 0x22:
  875. + case $ord_var_c == 0x2F:
  876. + case $ord_var_c == 0x5C:
  877. + // double quote, slash, slosh
  878. + $ascii .= '\\'.$var{$c};
  879. + break;
  880. +
  881. + case (($ord_var_c >= 0x20) && ($ord_var_c <= 0x7F)):
  882. + // characters U-00000000 - U-0000007F (same as ASCII)
  883. + $ascii .= $var{$c};
  884. + break;
  885. +
  886. + case (($ord_var_c & 0xE0) == 0xC0):
  887. + // characters U-00000080 - U-000007FF, mask 110XXXXX
  888. + // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
  889. + $char = pack('C*', $ord_var_c, ord($var{$c + 1}));
  890. + $c += 1;
  891. + $utf16 = $this->utf82utf16($char);
  892. + $ascii .= sprintf('\u%04s', bin2hex($utf16));
  893. + break;
  894. +
  895. + case (($ord_var_c & 0xF0) == 0xE0):
  896. + // characters U-00000800 - U-0000FFFF, mask 1110XXXX
  897. + // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
  898. + $char = pack('C*', $ord_var_c,
  899. + ord($var{$c + 1}),
  900. + ord($var{$c + 2}));
  901. + $c += 2;
  902. + $utf16 = $this->utf82utf16($char);
  903. + $ascii .= sprintf('\u%04s', bin2hex($utf16));
  904. + break;
  905. +
  906. + case (($ord_var_c & 0xF8) == 0xF0):
  907. + // characters U-00010000 - U-001FFFFF, mask 11110XXX
  908. + // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
  909. + $char = pack('C*', $ord_var_c,
  910. + ord($var{$c + 1}),
  911. + ord($var{$c + 2}),
  912. + ord($var{$c + 3}));
  913. + $c += 3;
  914. + $utf16 = $this->utf82utf16($char);
  915. + $ascii .= sprintf('\u%04s', bin2hex($utf16));
  916. + break;
  917. +
  918. + case (($ord_var_c & 0xFC) == 0xF8):
  919. + // characters U-00200000 - U-03FFFFFF, mask 111110XX
  920. + // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
  921. + $char = pack('C*', $ord_var_c,
  922. + ord($var{$c + 1}),
  923. + ord($var{$c + 2}),
  924. + ord($var{$c + 3}),
  925. + ord($var{$c + 4}));
  926. + $c += 4;
  927. + $utf16 = $this->utf82utf16($char);
  928. + $ascii .= sprintf('\u%04s', bin2hex($utf16));
  929. + break;
  930. +
  931. + case (($ord_var_c & 0xFE) == 0xFC):
  932. + // characters U-04000000 - U-7FFFFFFF, mask 1111110X
  933. + // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
  934. + $char = pack('C*', $ord_var_c,
  935. + ord($var{$c + 1}),
  936. + ord($var{$c + 2}),
  937. + ord($var{$c + 3}),
  938. + ord($var{$c + 4}),
  939. + ord($var{$c + 5}));
  940. + $c += 5;
  941. + $utf16 = $this->utf82utf16($char);
  942. + $ascii .= sprintf('\u%04s', bin2hex($utf16));
  943. + break;
  944. + }
  945. + }
  946.  
  947. - case 'integer':
  948. - return (int) $var;
  949. + return '"'.$ascii.'"';
  950.  
  951. - case 'double':
  952. - case 'float':
  953. - return (float) $var;
  954. -
  955. - case 'string':
  956. - // STRINGS ARE EXPECTED TO BE IN ASCII OR UTF-8 FORMAT
  957. - $ascii = '';
  958. - $strlen_var = strlen($var);
  959. -
  960. - /*
  961. - * Iterate over every character in the string,
  962. - * escaping with a slash or encoding to UTF-8 where necessary
  963. - */
  964. - for ($c = 0; $c < $strlen_var; ++$c) {
  965. -
  966. - $ord_var_c = ord($var{$c});
  967. -
  968. - switch (true) {
  969. - case $ord_var_c == 0x08:
  970. - $ascii .= '\b';
  971. - break;
  972. - case $ord_var_c == 0x09:
  973. - $ascii .= '\t';
  974. - break;
  975. - case $ord_var_c == 0x0A:
  976. - $ascii .= '\n';
  977. - break;
  978. - case $ord_var_c == 0x0C:
  979. - $ascii .= '\f';
  980. - break;
  981. - case $ord_var_c == 0x0D:
  982. - $ascii .= '\r';
  983. - break;
  984. -
  985. - case $ord_var_c == 0x22:
  986. - case $ord_var_c == 0x2F:
  987. - case $ord_var_c == 0x5C:
  988. - // double quote, slash, slosh
  989. - $ascii .= '\\'.$var{$c};
  990. - break;
  991. -
  992. - case (($ord_var_c >= 0x20) && ($ord_var_c <= 0x7F)):
  993. - // characters U-00000000 - U-0000007F (same as ASCII)
  994. - $ascii .= $var{$c};
  995. - break;
  996. -
  997. - case (($ord_var_c & 0xE0) == 0xC0):
  998. - // characters U-00000080 - U-000007FF, mask 110XXXXX
  999. - // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
  1000. - $char = pack('C*', $ord_var_c, ord($var{$c + 1}));
  1001. - $c += 1;
  1002. - $utf16 = $this->utf82utf16($char);
  1003. - $ascii .= sprintf('\u%04s', bin2hex($utf16));
  1004. - break;
  1005. -
  1006. - case (($ord_var_c & 0xF0) == 0xE0):
  1007. - // characters U-00000800 - U-0000FFFF, mask 1110XXXX
  1008. - // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
  1009. - $char = pack('C*', $ord_var_c,
  1010. - ord($var{$c + 1}),
  1011. - ord($var{$c + 2}));
  1012. - $c += 2;
  1013. - $utf16 = $this->utf82utf16($char);
  1014. - $ascii .= sprintf('\u%04s', bin2hex($utf16));
  1015. - break;
  1016. -
  1017. - case (($ord_var_c & 0xF8) == 0xF0):
  1018. - // characters U-00010000 - U-001FFFFF, mask 11110XXX
  1019. - // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
  1020. - $char = pack('C*', $ord_var_c,
  1021. - ord($var{$c + 1}),
  1022. - ord($var{$c + 2}),
  1023. - ord($var{$c + 3}));
  1024. - $c += 3;
  1025. - $utf16 = $this->utf82utf16($char);
  1026. - $ascii .= sprintf('\u%04s', bin2hex($utf16));
  1027. - break;
  1028. -
  1029. - case (($ord_var_c & 0xFC) == 0xF8):
  1030. - // characters U-00200000 - U-03FFFFFF, mask 111110XX
  1031. - // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
  1032. - $char = pack('C*', $ord_var_c,
  1033. - ord($var{$c + 1}),
  1034. - ord($var{$c + 2}),
  1035. - ord($var{$c + 3}),
  1036. - ord($var{$c + 4}));
  1037. - $c += 4;
  1038. - $utf16 = $this->utf82utf16($char);
  1039. - $ascii .= sprintf('\u%04s', bin2hex($utf16));
  1040. - break;
  1041. -
  1042. - case (($ord_var_c & 0xFE) == 0xFC):
  1043. - // characters U-04000000 - U-7FFFFFFF, mask 1111110X
  1044. - // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
  1045. - $char = pack('C*', $ord_var_c,
  1046. - ord($var{$c + 1}),
  1047. - ord($var{$c + 2}),
  1048. - ord($var{$c + 3}),
  1049. - ord($var{$c + 4}),
  1050. - ord($var{$c + 5}));
  1051. - $c += 5;
  1052. - $utf16 = $this->utf82utf16($char);
  1053. - $ascii .= sprintf('\u%04s', bin2hex($utf16));
  1054. - break;
  1055. + case 'array':
  1056. + /*
  1057. + * As per JSON spec if any array key is not an integer
  1058. + * we must treat the the whole array as an object. We
  1059. + * also try to catch a sparsely populated associative
  1060. + * array with numeric keys here because some JS engines
  1061. + * will create an array with empty indexes up to
  1062. + * max_index which can cause memory issues and because
  1063. + * the keys, which may be relevant, will be remapped
  1064. + * otherwise.
  1065. + *
  1066. + * As per the ECMA and JSON specification an object may
  1067. + * have any string as a property. Unfortunately due to
  1068. + * a hole in the ECMA specification if the key is a
  1069. + * ECMA reserved word or starts with a digit the
  1070. + * parameter is only accessible using ECMAScript's
  1071. + * bracket notation.
  1072. + */
  1073. +
  1074. + // treat as a JSON object
  1075. + if (is_array($var) && count($var) && (array_keys($var) !== range(0, sizeof($var) - 1))) {
  1076. + $properties = array_map(array($this, 'name_value'),
  1077. + array_keys($var),
  1078. + array_values($var));
  1079. +
  1080. + foreach ($properties as $property) {
  1081. + if (HTML_AJAX_JSON::isError($property)) {
  1082. + return $property;
  1083. }
  1084. }
  1085.  
  1086. - return '"'.$ascii.'"';
  1087. -
  1088. - case 'array':
  1089. - /*
  1090. - * As per JSON spec if any array key is not an integer
  1091. - * we must treat the the whole array as an object. We
  1092. - * also try to catch a sparsely populated associative
  1093. - * array with numeric keys here because some JS engines
  1094. - * will create an array with empty indexes up to
  1095. - * max_index which can cause memory issues and because
  1096. - * the keys, which may be relevant, will be remapped
  1097. - * otherwise.
  1098. - *
  1099. - * As per the ECMA and JSON specification an object may
  1100. - * have any string as a property. Unfortunately due to
  1101. - * a hole in the ECMA specification if the key is a
  1102. - * ECMA reserved word or starts with a digit the
  1103. - * parameter is only accessible using ECMAScript's
  1104. - * bracket notation.
  1105. - */
  1106. -
  1107. - // treat as a JSON object
  1108. - if (is_array($var) && count($var) && (array_keys($var) !== range(0, sizeof($var) - 1))) {
  1109. - $properties = array_map(array($this, 'name_value'),
  1110. - array_keys($var),
  1111. - array_values($var));
  1112. -
  1113. - foreach($properties as $property)
  1114. - if(HTML_AJAX_JSON::isError($property))
  1115. - return $property;
  1116. -
  1117. - return '{' . join(',', $properties) . '}';
  1118. - }
  1119. + return '{' . join(',', $properties) . '}';
  1120. + }
  1121.  
  1122. - // treat it like a regular array
  1123. - $elements = array_map(array($this, 'encode'), $var);
  1124. -
  1125. - foreach($elements as $element)
  1126. - if(HTML_AJAX_JSON::isError($element))
  1127. - return $element;
  1128. -
  1129. - return '[' . join(',', $elements) . ']';
  1130. + // treat it like a regular array
  1131. + $elements = array_map(array($this, 'encode'), $var);
  1132. +
  1133. + foreach ($elements as $element) {
  1134. + if (HTML_AJAX_JSON::isError($element)) {
  1135. + return $element;
  1136. + }
  1137. + }
  1138. +
  1139. + return '[' . join(',', $elements) . ']';
  1140.  
  1141. - case 'object':
  1142. - $vars = get_object_vars($var);
  1143. + case 'object':
  1144. + $vars = get_object_vars($var);
  1145.  
  1146. - $properties = array_map(array($this, 'name_value'),
  1147. - array_keys($vars),
  1148. - array_values($vars));
  1149. + $properties = array_map(array($this, 'name_value'),
  1150. + array_keys($vars),
  1151. + array_values($vars));
  1152. +
  1153. + foreach ($properties as $property) {
  1154. + if (HTML_AJAX_JSON::isError($property)) {
  1155. + return $property;
  1156. + }
  1157. + }
  1158.  
  1159. - foreach($properties as $property)
  1160. - if(HTML_AJAX_JSON::isError($property))
  1161. - return $property;
  1162. -
  1163. - return '{' . join(',', $properties) . '}';
  1164. + return '{' . join(',', $properties) . '}';
  1165.  
  1166. - default:
  1167. - return ($this->use & SERVICES_JSON_SUPPRESS_ERRORS)
  1168. - ? 'null'
  1169. - : new HTML_AJAX_JSON_Error(gettype($var)." can not be encoded as JSON string");
  1170. + default:
  1171. + return ($this->use & SERVICES_JSON_SUPPRESS_ERRORS)
  1172. + ? 'null'
  1173. + : new HTML_AJAX_JSON_Error(gettype($var)." can not be encoded as JSON string");
  1174. }
  1175. }
  1176.  
  1177. /**
  1178. * array-walking function for use in generating JSON-formatted name-value pairs
  1179. *
  1180. - * @param string $name name of key to use
  1181. - * @param mixed $value reference to an array element to be encoded
  1182. + * @param string $name name of key to use
  1183. + * @param mixed $value reference to an array element to be encoded
  1184. *
  1185. * @return string JSON-formatted name-value pair, like '"name":value'
  1186. * @access private
  1187. @@ -445,7 +462,7 @@
  1188. /**
  1189. * reduce a string by removing leading and trailing comments and whitespace
  1190. *
  1191. - * @param $str string string value to strip of comments and whitespace
  1192. + * @param $str string string value to strip of comments and whitespace
  1193. *
  1194. * @return string string value stripped of comments and whitespace
  1195. * @access private
  1196. @@ -472,7 +489,7 @@
  1197. /**
  1198. * decodes a JSON string into appropriate variable
  1199. *
  1200. - * @param string $str JSON-formatted string
  1201. + * @param string $str JSON-formatted string
  1202. *
  1203. * @return mixed number, boolean, string, array, or object
  1204. * corresponding to given JSON input string.
  1205. @@ -486,272 +503,272 @@
  1206. $str = $this->reduce_string($str);
  1207.  
  1208. switch (strtolower($str)) {
  1209. - case 'true':
  1210. - return true;
  1211. + case 'true':
  1212. + return true;
  1213.  
  1214. - case 'false':
  1215. - return false;
  1216. -
  1217. - case 'null':
  1218. - return null;
  1219. -
  1220. - default:
  1221. - if (is_numeric($str)) {
  1222. - // Lookie-loo, it's a number
  1223. -
  1224. - // This would work on its own, but I'm trying to be
  1225. - // good about returning integers where appropriate:
  1226. - // return (float)$str;
  1227. -
  1228. - // Return float or int, as appropriate
  1229. - return ((float)$str == (integer)$str)
  1230. - ? (integer)$str
  1231. - : (float)$str;
  1232. -
  1233. - } elseif (preg_match('/^("|\').*(\1)$/s', $str, $m) && $m[1] == $m[2]) {
  1234. - // STRINGS RETURNED IN UTF-8 FORMAT
  1235. - $delim = substr($str, 0, 1);
  1236. - $chrs = substr($str, 1, -1);
  1237. - $utf8 = '';
  1238. - $strlen_chrs = strlen($chrs);
  1239. -
  1240. - for ($c = 0; $c < $strlen_chrs; ++$c) {
  1241. + case 'false':
  1242. + return false;
  1243. +
  1244. + case 'null':
  1245. + return null;
  1246. +
  1247. + default:
  1248. + if (is_numeric($str)) {
  1249. + // Lookie-loo, it's a number
  1250. +
  1251. + // This would work on its own, but I'm trying to be
  1252. + // good about returning integers where appropriate:
  1253. + // return (float)$str;
  1254. +
  1255. + // Return float or int, as appropriate
  1256. + return ((float)$str == (integer)$str)
  1257. + ? (integer)$str
  1258. + : (float)$str;
  1259. +
  1260. + } elseif (preg_match('/^("|\').*(\1)$/s', $str, $m) && $m[1] == $m[2]) {
  1261. + // STRINGS RETURNED IN UTF-8 FORMAT
  1262. + $delim = substr($str, 0, 1);
  1263. + $chrs = substr($str, 1, -1);
  1264. + $utf8 = '';
  1265. + $strlen_chrs = strlen($chrs);
  1266. +
  1267. + for ($c = 0; $c < $strlen_chrs; ++$c) {
  1268. +
  1269. + $substr_chrs_c_2 = substr($chrs, $c, 2);
  1270. + $ord_chrs_c = ord($chrs{$c});
  1271.  
  1272. - $substr_chrs_c_2 = substr($chrs, $c, 2);
  1273. - $ord_chrs_c = ord($chrs{$c});
  1274. -
  1275. - switch (true) {
  1276. - case $substr_chrs_c_2 == '\b':
  1277. - $utf8 .= chr(0x08);
  1278. - ++$c;
  1279. - break;
  1280. - case $substr_chrs_c_2 == '\t':
  1281. - $utf8 .= chr(0x09);
  1282. - ++$c;
  1283. - break;
  1284. - case $substr_chrs_c_2 == '\n':
  1285. - $utf8 .= chr(0x0A);
  1286. - ++$c;
  1287. - break;
  1288. - case $substr_chrs_c_2 == '\f':
  1289. - $utf8 .= chr(0x0C);
  1290. - ++$c;
  1291. - break;
  1292. - case $substr_chrs_c_2 == '\r':
  1293. - $utf8 .= chr(0x0D);
  1294. - ++$c;
  1295. - break;
  1296. -
  1297. - case $substr_chrs_c_2 == '\\"':
  1298. - case $substr_chrs_c_2 == '\\\'':
  1299. - case $substr_chrs_c_2 == '\\\\':
  1300. - case $substr_chrs_c_2 == '\\/':
  1301. - if (($delim == '"' && $substr_chrs_c_2 != '\\\'') ||
  1302. - ($delim == "'" && $substr_chrs_c_2 != '\\"')) {
  1303. - $utf8 .= $chrs{++$c};
  1304. - }
  1305. - break;
  1306. -
  1307. - case preg_match('/\\\u[0-9A-F]{4}/i', substr($chrs, $c, 6)):
  1308. - // single, escaped unicode character
  1309. - $utf16 = chr(hexdec(substr($chrs, ($c + 2), 2)))
  1310. - . chr(hexdec(substr($chrs, ($c + 4), 2)));
  1311. - $utf8 .= $this->utf162utf8($utf16);
  1312. - $c += 5;
  1313. - break;
  1314. -
  1315. - case ($ord_chrs_c >= 0x20) && ($ord_chrs_c <= 0x7F):
  1316. - $utf8 .= $chrs{$c};
  1317. - break;
  1318. -
  1319. - case ($ord_chrs_c & 0xE0) == 0xC0:
  1320. - // characters U-00000080 - U-000007FF, mask 110XXXXX
  1321. - //see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
  1322. - $utf8 .= substr($chrs, $c, 2);
  1323. - ++$c;
  1324. - break;
  1325. -
  1326. - case ($ord_chrs_c & 0xF0) == 0xE0:
  1327. - // characters U-00000800 - U-0000FFFF, mask 1110XXXX
  1328. - // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
  1329. - $utf8 .= substr($chrs, $c, 3);
  1330. - $c += 2;
  1331. - break;
  1332. -
  1333. - case ($ord_chrs_c & 0xF8) == 0xF0:
  1334. - // characters U-00010000 - U-001FFFFF, mask 11110XXX
  1335. - // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
  1336. - $utf8 .= substr($chrs, $c, 4);
  1337. - $c += 3;
  1338. - break;
  1339. -
  1340. - case ($ord_chrs_c & 0xFC) == 0xF8:
  1341. - // characters U-00200000 - U-03FFFFFF, mask 111110XX
  1342. - // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
  1343. - $utf8 .= substr($chrs, $c, 5);
  1344. - $c += 4;
  1345. - break;
  1346. -
  1347. - case ($ord_chrs_c & 0xFE) == 0xFC:
  1348. - // characters U-04000000 - U-7FFFFFFF, mask 1111110X
  1349. - // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
  1350. - $utf8 .= substr($chrs, $c, 6);
  1351. - $c += 5;
  1352. - break;
  1353. -
  1354. + switch (true) {
  1355. + case $substr_chrs_c_2 == '\b':
  1356. + $utf8 .= chr(0x08);
  1357. + ++$c;
  1358. + break;
  1359. + case $substr_chrs_c_2 == '\t':
  1360. + $utf8 .= chr(0x09);
  1361. + ++$c;
  1362. + break;
  1363. + case $substr_chrs_c_2 == '\n':
  1364. + $utf8 .= chr(0x0A);
  1365. + ++$c;
  1366. + break;
  1367. + case $substr_chrs_c_2 == '\f':
  1368. + $utf8 .= chr(0x0C);
  1369. + ++$c;
  1370. + break;
  1371. + case $substr_chrs_c_2 == '\r':
  1372. + $utf8 .= chr(0x0D);
  1373. + ++$c;
  1374. + break;
  1375. +
  1376. + case $substr_chrs_c_2 == '\\"':
  1377. + case $substr_chrs_c_2 == '\\\'':
  1378. + case $substr_chrs_c_2 == '\\\\':
  1379. + case $substr_chrs_c_2 == '\\/':
  1380. + if (($delim == '"' && $substr_chrs_c_2 != '\\\'') ||
  1381. + ($delim == "'" && $substr_chrs_c_2 != '\\"')) {
  1382. + $utf8 .= $chrs{++$c};
  1383. }
  1384. + break;
  1385. +
  1386. + case preg_match('/\\\u[0-9A-F]{4}/i', substr($chrs, $c, 6)):
  1387. + // single, escaped unicode character
  1388. + $utf16 = chr(hexdec(substr($chrs, ($c + 2), 2)))
  1389. + . chr(hexdec(substr($chrs, ($c + 4), 2)));
  1390. + $utf8 .= $this->utf162utf8($utf16);
  1391. + $c += 5;
  1392. + break;
  1393. +
  1394. + case ($ord_chrs_c >= 0x20) && ($ord_chrs_c <= 0x7F):
  1395. + $utf8 .= $chrs{$c};
  1396. + break;
  1397. +
  1398. + case ($ord_chrs_c & 0xE0) == 0xC0:
  1399. + // characters U-00000080 - U-000007FF, mask 110XXXXX
  1400. + //see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
  1401. + $utf8 .= substr($chrs, $c, 2);
  1402. + ++$c;
  1403. + break;
  1404. +
  1405. + case ($ord_chrs_c & 0xF0) == 0xE0:
  1406. + // characters U-00000800 - U-0000FFFF, mask 1110XXXX
  1407. + // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
  1408. + $utf8 .= substr($chrs, $c, 3);
  1409. + $c += 2;
  1410. + break;
  1411. +
  1412. + case ($ord_chrs_c & 0xF8) == 0xF0:
  1413. + // characters U-00010000 - U-001FFFFF, mask 11110XXX
  1414. + // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
  1415. + $utf8 .= substr($chrs, $c, 4);
  1416. + $c += 3;
  1417. + break;
  1418. +
  1419. + case ($ord_chrs_c & 0xFC) == 0xF8:
  1420. + // characters U-00200000 - U-03FFFFFF, mask 111110XX
  1421. + // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
  1422. + $utf8 .= substr($chrs, $c, 5);
  1423. + $c += 4;
  1424. + break;
  1425. +
  1426. + case ($ord_chrs_c & 0xFE) == 0xFC:
  1427. + // characters U-04000000 - U-7FFFFFFF, mask 1111110X
  1428. + // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
  1429. + $utf8 .= substr($chrs, $c, 6);
  1430. + $c += 5;
  1431. + break;
  1432.  
  1433. }
  1434. -
  1435. - return $utf8;
  1436. +
  1437. + }
  1438.  
  1439. - } elseif (preg_match('/^\[.*\]$/s', $str) || preg_match('/^\{.*\}$/s', $str)) {
  1440. - // array, or object notation
  1441. + return $utf8;
  1442. +
  1443. + } elseif (preg_match('/^\[.*\]$/s', $str) || preg_match('/^\{.*\}$/s', $str)) {
  1444. + // array, or object notation
  1445.  
  1446. - if ($str{0} == '[') {
  1447. - $stk = array(SERVICES_JSON_IN_ARR);
  1448. - $arr = array();
  1449. + if ($str{0} == '[') {
  1450. + $stk = array(SERVICES_JSON_IN_ARR);
  1451. + $arr = array();
  1452. + } else {
  1453. + if ($this->use & SERVICES_JSON_LOOSE_TYPE) {
  1454. + $stk = array(SERVICES_JSON_IN_OBJ);
  1455. + $obj = array();
  1456. } else {
  1457. - if ($this->use & SERVICES_JSON_LOOSE_TYPE) {
  1458. - $stk = array(SERVICES_JSON_IN_OBJ);
  1459. - $obj = array();
  1460. - } else {
  1461. - $stk = array(SERVICES_JSON_IN_OBJ);
  1462. - $obj = new stdClass();
  1463. - }
  1464. + $stk = array(SERVICES_JSON_IN_OBJ);
  1465. + $obj = new stdClass();
  1466. }
  1467. -
  1468. - array_push($stk, array('what' => SERVICES_JSON_SLICE,
  1469. - 'where' => 0,
  1470. - 'delim' => false));
  1471. + }
  1472. +
  1473. + array_push($stk, array('what' => SERVICES_JSON_SLICE,
  1474. + 'where' => 0,
  1475. + 'delim' => false));
  1476.  
  1477. - $chrs = substr($str, 1, -1);
  1478. - $chrs = $this->reduce_string($chrs);
  1479. -
  1480. - if ($chrs == '') {
  1481. - if (reset($stk) == SERVICES_JSON_IN_ARR) {
  1482. - return $arr;
  1483. + $chrs = substr($str, 1, -1);
  1484. + $chrs = $this->reduce_string($chrs);
  1485. +
  1486. + if ($chrs == '') {
  1487. + if (reset($stk) == SERVICES_JSON_IN_ARR) {
  1488. + return $arr;
  1489.  
  1490. - } else {
  1491. - return $obj;
  1492. + } else {
  1493. + return $obj;
  1494.  
  1495. - }
  1496. }
  1497. + }
  1498.  
  1499. - //print("\nparsing {$chrs}\n");
  1500. -
  1501. - $strlen_chrs = strlen($chrs);
  1502. -
  1503. - for ($c = 0; $c <= $strlen_chrs; ++$c) {
  1504. -
  1505. - $top = end($stk);
  1506. - $substr_chrs_c_2 = substr($chrs, $c, 2);
  1507. -
  1508. - if (($c == $strlen_chrs) || (($chrs{$c} == ',') && ($top['what'] == SERVICES_JSON_SLICE))) {
  1509. - // found a comma that is not inside a string, array, etc.,
  1510. - // OR we've reached the end of the character list
  1511. - $slice = substr($chrs, $top['where'], ($c - $top['where']));
  1512. - array_push($stk, array('what' => SERVICES_JSON_SLICE, 'where' => ($c + 1), 'delim' => false));
  1513. - //print("Found split at {$c}: ".substr($chrs, $top['where'], (1 + $c - $top['where']))."\n");
  1514. -
  1515. - if (reset($stk) == SERVICES_JSON_IN_ARR) {
  1516. - // we are in an array, so just push an element onto the stack
  1517. - array_push($arr, $this->decode($slice));
  1518. -
  1519. - } elseif (reset($stk) == SERVICES_JSON_IN_OBJ) {
  1520. - // we are in an object, so figure
  1521. - // out the property name and set an
  1522. - // element in an associative array,
  1523. - // for now
  1524. - if (preg_match('/^\s*(["\'].*[^\\\]["\'])\s*:\s*(\S.*),?$/Uis', $slice, $parts)) {
  1525. - // "name":value pair
  1526. - $key = $this->decode($parts[1]);
  1527. - $val = $this->decode($parts[2]);
  1528. -
  1529. - if ($this->use & SERVICES_JSON_LOOSE_TYPE) {
  1530. - $obj[$key] = $val;
  1531. - } else {
  1532. - $obj->$key = $val;
  1533. - }
  1534. - } elseif (preg_match('/^\s*(\w+)\s*:\s*(\S.*),?$/Uis', $slice, $parts)) {
  1535. - // name:value pair, where name is unquoted
  1536. - $key = $parts[1];
  1537. - $val = $this->decode($parts[2]);
  1538. -
  1539. - if ($this->use & SERVICES_JSON_LOOSE_TYPE) {
  1540. - $obj[$key] = $val;
  1541. - } else {
  1542. - $obj->$key = $val;
  1543. - }
  1544. - }
  1545. + //print("\nparsing {$chrs}\n");
  1546. +
  1547. + $strlen_chrs = strlen($chrs);
  1548. +
  1549. + for ($c = 0; $c <= $strlen_chrs; ++$c) {
  1550. +
  1551. + $top = end($stk);
  1552. + $substr_chrs_c_2 = substr($chrs, $c, 2);
  1553. +
  1554. + if (($c == $strlen_chrs) || (($chrs{$c} == ',') && ($top['what'] == SERVICES_JSON_SLICE))) {
  1555. + // found a comma that is not inside a string, array, etc.,
  1556. + // OR we've reached the end of the character list
  1557. + $slice = substr($chrs, $top['where'], ($c - $top['where']));
  1558. + array_push($stk, array('what' => SERVICES_JSON_SLICE, 'where' => ($c + 1), 'delim' => false));
  1559. + //print("Found split at {$c}: ".substr($chrs, $top['where'], (1 + $c - $top['where']))."\n");
  1560.  
  1561. - }
  1562. + if (reset($stk) == SERVICES_JSON_IN_ARR) {
  1563. + // we are in an array, so just push an element onto the stack
  1564. + array_push($arr, $this->decode($slice));
  1565.  
  1566. - } elseif ((($chrs{$c} == '"') || ($chrs{$c} == "'")) && ($top['what'] != SERVICES_JSON_IN_STR)) {
  1567. - // found a quote, and we are not inside a string
  1568. - array_push($stk, array('what' => SERVICES_JSON_IN_STR, 'where' => $c, 'delim' => $chrs{$c}));
  1569. - //print("Found start of string at {$c}\n");
  1570. -
  1571. - } elseif (($chrs{$c} == $top['delim']) &&
  1572. - ($top['what'] == SERVICES_JSON_IN_STR) &&
  1573. - (($chrs{$c - 1} != '\\') ||
  1574. - ($chrs{$c - 1} == '\\' && $chrs{$c - 2} == '\\'))) {
  1575. - // found a quote, we're in a string, and it's not escaped
  1576. - array_pop($stk);
  1577. - //print("Found end of string at {$c}: ".substr($chrs, $top['where'], (1 + 1 + $c - $top['where']))."\n");
  1578. -
  1579. - } elseif (($chrs{$c} == '[') &&
  1580. - in_array($top['what'], array(SERVICES_JSON_SLICE, SERVICES_JSON_IN_ARR, SERVICES_JSON_IN_OBJ))) {
  1581. - // found a left-bracket, and we are in an array, object, or slice
  1582. - array_push($stk, array('what' => SERVICES_JSON_IN_ARR, 'where' => $c, 'delim' => false));
  1583. - //print("Found start of array at {$c}\n");
  1584. -
  1585. - } elseif (($chrs{$c} == ']') && ($top['what'] == SERVICES_JSON_IN_ARR)) {
  1586. - // found a right-bracket, and we're in an array
  1587. - array_pop($stk);
  1588. - //print("Found end of array at {$c}: ".substr($chrs, $top['where'], (1 + $c - $top['where']))."\n");
  1589. -
  1590. - } elseif (($chrs{$c} == '{') &&
  1591. - in_array($top['what'], array(SERVICES_JSON_SLICE, SERVICES_JSON_IN_ARR, SERVICES_JSON_IN_OBJ))) {
  1592. - // found a left-brace, and we are in an array, object, or slice
  1593. - array_push($stk, array('what' => SERVICES_JSON_IN_OBJ, 'where' => $c, 'delim' => false));
  1594. - //print("Found start of object at {$c}\n");
  1595. -
  1596. - } elseif (($chrs{$c} == '}') && ($top['what'] == SERVICES_JSON_IN_OBJ)) {
  1597. - // found a right-brace, and we're in an object
  1598. - array_pop($stk);
  1599. - //print("Found end of object at {$c}: ".substr($chrs, $top['where'], (1 + $c - $top['where']))."\n");
  1600. -
  1601. - } elseif (($substr_chrs_c_2 == '/*') &&
  1602. - in_array($top['what'], array(SERVICES_JSON_SLICE, SERVICES_JSON_IN_ARR, SERVICES_JSON_IN_OBJ))) {
  1603. - // found a comment start, and we are in an array, object, or slice
  1604. - array_push($stk, array('what' => SERVICES_JSON_IN_CMT, 'where' => $c, 'delim' => false));
  1605. - $c++;
  1606. - //print("Found start of comment at {$c}\n");
  1607. -
  1608. - } elseif (($substr_chrs_c_2 == '*/') && ($top['what'] == SERVICES_JSON_IN_CMT)) {
  1609. - // found a comment end, and we're in one now
  1610. - array_pop($stk);
  1611. - $c++;
  1612. -
  1613. - for ($i = $top['where']; $i <= $c; ++$i)
  1614. - $chrs = substr_replace($chrs, ' ', $i, 1);
  1615. -
  1616. - //print("Found end of comment at {$c}: ".substr($chrs, $top['where'], (1 + $c - $top['where']))."\n");
  1617. + } elseif (reset($stk) == SERVICES_JSON_IN_OBJ) {
  1618. + // we are in an object, so figure
  1619. + // out the property name and set an
  1620. + // element in an associative array,
  1621. + // for now
  1622. + if (preg_match('/^\s*(["\'].*[^\\\]["\'])\s*:\s*(\S.*),?$/Uis', $slice, $parts)) {
  1623. + // "name":value pair
  1624. + $key = $this->decode($parts[1]);
  1625. + $val = $this->decode($parts[2]);
  1626. +
  1627. + if ($this->use & SERVICES_JSON_LOOSE_TYPE) {
  1628. + $obj[$key] = $val;
  1629. + } else {
  1630. + $obj->$key = $val;
  1631. + }
  1632. + } elseif (preg_match('/^\s*(\w+)\s*:\s*(\S.*),?$/Uis', $slice, $parts)) {
  1633. + // name:value pair, where name is unquoted
  1634. + $key = $parts[1];
  1635. + $val = $this->decode($parts[2]);
  1636. +
  1637. + if ($this->use & SERVICES_JSON_LOOSE_TYPE) {
  1638. + $obj[$key] = $val;
  1639. + } else {
  1640. + $obj->$key = $val;
  1641. + }
  1642. + }
  1643.  
  1644. }
  1645. -
  1646. - }
  1647. -
  1648. - if (reset($stk) == SERVICES_JSON_IN_ARR) {
  1649. - return $arr;
  1650.  
  1651. - } elseif (reset($stk) == SERVICES_JSON_IN_OBJ) {
  1652. - return $obj;
  1653. + } elseif ((($chrs{$c} == '"') || ($chrs{$c} == "'")) && ($top['what'] != SERVICES_JSON_IN_STR)) {
  1654. + // found a quote, and we are not inside a string
  1655. + array_push($stk, array('what' => SERVICES_JSON_IN_STR, 'where' => $c, 'delim' => $chrs{$c}));
  1656. + //print("Found start of string at {$c}\n");
  1657. +
  1658. + } elseif (($chrs{$c} == $top['delim']) &&
  1659. + ($top['what'] == SERVICES_JSON_IN_STR) &&
  1660. + (($chrs{$c - 1} != '\\') ||
  1661. + ($chrs{$c - 1} == '\\' && $chrs{$c - 2} == '\\'))) {
  1662. + // found a quote, we're in a string, and it's not escaped
  1663. + array_pop($stk);
  1664. + //print("Found end of string at {$c}: ".substr($chrs, $top['where'], (1 + 1 + $c - $top['where']))."\n");
  1665. +
  1666. + } elseif (($chrs{$c} == '[') &&
  1667. + in_array($top['what'], array(SERVICES_JSON_SLICE, SERVICES_JSON_IN_ARR, SERVICES_JSON_IN_OBJ))) {
  1668. + // found a left-bracket, and we are in an array, object, or slice
  1669. + array_push($stk, array('what' => SERVICES_JSON_IN_ARR, 'where' => $c, 'delim' => false));
  1670. + //print("Found start of array at {$c}\n");
  1671. +
  1672. + } elseif (($chrs{$c} == ']') && ($top['what'] == SERVICES_JSON_IN_ARR)) {
  1673. + // found a right-bracket, and we're in an array
  1674. + array_pop($stk);
  1675. + //print("Found end of array at {$c}: ".substr($chrs, $top['where'], (1 + $c - $top['where']))."\n");
  1676. +
  1677. + } elseif (($chrs{$c} == '{') &&
  1678. + in_array($top['what'], array(SERVICES_JSON_SLICE, SERVICES_JSON_IN_ARR, SERVICES_JSON_IN_OBJ))) {
  1679. + // found a left-brace, and we are in an array, object, or slice
  1680. + array_push($stk, array('what' => SERVICES_JSON_IN_OBJ, 'where' => $c, 'delim' => false));
  1681. + //print("Found start of object at {$c}\n");
  1682. +
  1683. + } elseif (($chrs{$c} == '}') && ($top['what'] == SERVICES_JSON_IN_OBJ)) {
  1684. + // found a right-brace, and we're in an object
  1685. + array_pop($stk);
  1686. + //print("Found end of object at {$c}: ".substr($chrs, $top['where'], (1 + $c - $top['where']))."\n");
  1687. +
  1688. + } elseif (($substr_chrs_c_2 == '/*') &&
  1689. + in_array($top['what'], array(SERVICES_JSON_SLICE, SERVICES_JSON_IN_ARR, SERVICES_JSON_IN_OBJ))) {
  1690. + // found a comment start, and we are in an array, object, or slice
  1691. + array_push($stk, array('what' => SERVICES_JSON_IN_CMT, 'where' => $c, 'delim' => false));
  1692. + $c++;
  1693. + //print("Found start of comment at {$c}\n");
  1694. +
  1695. + } elseif (($substr_chrs_c_2 == '*/') && ($top['what'] == SERVICES_JSON_IN_CMT)) {
  1696. + // found a comment end, and we're in one now
  1697. + array_pop($stk);
  1698. + $c++;
  1699. +
  1700. + for ($i = $top['where']; $i <= $c; ++$i)
  1701. + $chrs = substr_replace($chrs, ' ', $i, 1);
  1702. +
  1703. + //print("Found end of comment at {$c}: ".substr($chrs, $top['where'], (1 + $c - $top['where']))."\n");
  1704.  
  1705. }
  1706.  
  1707. }
  1708. +
  1709. + if (reset($stk) == SERVICES_JSON_IN_ARR) {
  1710. + return $arr;
  1711. +
  1712. + } elseif (reset($stk) == SERVICES_JSON_IN_OBJ) {
  1713. + return $obj;
  1714. +
  1715. + }
  1716. +
  1717. + }
  1718. }
  1719. }
  1720.  
  1721. Index: AJAX/Server.php
  1722. ===================================================================
  1723. RCS file: /repository/pear/HTML_AJAX/AJAX/Server.php,v
  1724. retrieving revision 1.12
  1725. diff -u -r1.12 Server.php
  1726. --- AJAX/Server.php 7 May 2008 21:26:19 -0000 1.12
  1727. +++ AJAX/Server.php 6 Dec 2008 14:31:58 -0000
  1728. @@ -470,7 +470,7 @@
  1729. /**
  1730.  
  1731. * Run readfile on input with basic error checking
  1732.  
  1733. *
  1734.  
  1735. - * @param string $file file to read
  1736.  
  1737. + * @param string $file file to read
  1738.  
  1739. * @access private
  1740.  
  1741. * @todo is addslashes enough encoding for js?
  1742.  
  1743. */
  1744.  
  1745. @@ -508,7 +508,7 @@
  1746. * Set the location of the client js
  1747.  
  1748. *
  1749.  
  1750. * @access public
  1751.  
  1752. - * @param string $location Location
  1753.  
  1754. + * @param string $location Location
  1755.  
  1756. * @return void
  1757.  
  1758. */
  1759.  
  1760. function setClientJsLocation($location)
  1761.  
  1762. @@ -520,8 +520,8 @@
  1763. * Set the path to a Javascript libraries
  1764.  
  1765. *
  1766.  
  1767. * @access public
  1768.  
  1769. - * @param string $library Library name
  1770.  
  1771. - * @param string $path Path
  1772.  
  1773. + * @param string $library Library name
  1774.  
  1775. + * @param string $path Path
  1776.  
  1777. * @return void
  1778.  
  1779. */
  1780.  
  1781. function setJavascriptLibraryPath($library, $path)
  1782.  
  1783. @@ -533,7 +533,7 @@
  1784. * Set the path to more than one Javascript libraries at once
  1785.  
  1786. *
  1787.  
  1788. * @access public
  1789.  
  1790. - * @param array $paths Paths
  1791.  
  1792. + * @param array $paths Paths
  1793.  
  1794. * @return void
  1795.  
  1796. */
  1797.  
  1798. function setJavascriptLibraryPaths($paths)
  1799.  
  1800. @@ -584,7 +584,7 @@
  1801. /**
  1802.  
  1803. * Clean an identifier like a class name making it safe to use
  1804.  
  1805. *
  1806.  
  1807. - * @param string $input
  1808.  
  1809. + * @param string $input
  1810.  
  1811. * @return string
  1812.  
  1813. * @access private
  1814.  
  1815. */
  1816.  
  1817. @@ -609,7 +609,7 @@
  1818. /**
  1819.  
  1820. * Init one class
  1821.  
  1822. *
  1823.  
  1824. - * @param string $className
  1825.  
  1826. + * @param string $className
  1827.  
  1828. * @access private
  1829.  
  1830. */
  1831.  
  1832. function _init($className)
  1833.  
  1834. @@ -633,7 +633,7 @@
  1835. /**
  1836.  
  1837. * Generate a hash from a list of files
  1838.  
  1839. *
  1840.  
  1841. - * @param array $files file list
  1842.  
  1843. + * @param array $files file list
  1844.  
  1845. * @return string a hash that can be used as an etag
  1846.  
  1847. * @access private
  1848.  
  1849. */
  1850.  
  1851. @@ -650,7 +650,7 @@
  1852. /**
  1853.  
  1854. * Generate a hash from the api of registered classes
  1855.  
  1856. *
  1857.  
  1858. - * @param array $classes class list
  1859.  
  1860. + * @param array $classes class list
  1861.  
  1862. * @return string a hash that can be used as an etag
  1863.  
  1864. * @access private
  1865.  
  1866. */
  1867.  
  1868. @@ -667,7 +667,7 @@
  1869. /**
  1870.  
  1871. * Generate a hash from the raw content
  1872.  
  1873. *
  1874.  
  1875. - * @param array $content
  1876.  
  1877. + * @param array $content
  1878.  
  1879. * @return string a hash that can be used as an etag
  1880.  
  1881. * @access private
  1882.  
  1883. */
  1884.  
  1885. @@ -690,17 +690,17 @@
  1886. /**
  1887.  
  1888. * Compare eTags
  1889.  
  1890. *
  1891.  
  1892. - * @param string $serverETag server eTag
  1893.  
  1894. + * @param string $serverETag server eTag
  1895.  
  1896. * @return boolean
  1897.  
  1898. * @access private
  1899.  
  1900. */
  1901.  
  1902. function _compareEtags($serverETag) {
  1903.  
  1904. if (isset($_SERVER['HTTP_IF_NONE_MATCH'])) {
  1905.  
  1906. - if (strcmp($this->ajax->_getServer('HTTP_IF_NONE_MATCH'),$serverETag) == 0) {
  1907.  
  1908. + if (strcmp($this->ajax->_getServer('HTTP_IF_NONE_MATCH'),$serverETag) == 0) {
  1909.  
  1910. $this->_sendCacheHeaders($serverETag,true);
  1911.  
  1912. return true;
  1913.  
  1914. }
  1915.  
  1916. - }
  1917.  
  1918. + }
  1919.  
  1920. $this->_sendCacheHeaders($serverETag,false);
  1921.  
  1922. return false;
  1923.  
  1924. }
  1925.  
  1926. @@ -708,8 +708,8 @@
  1927. /**
  1928.  
  1929. * Call a cache rule and return its retusn
  1930.  
  1931. *
  1932.  
  1933. - * @param string $rule Stub|Client
  1934.  
  1935. - * @param mixed $payload
  1936.  
  1937. + * @param string $rule Stub|Client
  1938.  
  1939. + * @param mixed $payload
  1940.  
  1941. * @return boolean
  1942.  
  1943. * @access private
  1944.  
  1945. * @todo decide if error checking is needed
  1946.  
  1947. Index: AJAX/Serializer/Error.php
  1948. ===================================================================
  1949. RCS file: /repository/pear/HTML_AJAX/AJAX/Serializer/Error.php,v
  1950. retrieving revision 1.7
  1951. diff -u -r1.7 Error.php
  1952. --- AJAX/Serializer/Error.php 13 Oct 2006 15:31:22 -0000 1.7
  1953. +++ AJAX/Serializer/Error.php 6 Dec 2008 14:31:58 -0000
  1954. @@ -1,20 +1,20 @@
  1955. -<?php
  1956.  
  1957. -require_once 'HTML/AJAX/Serializer/JSON.php';
  1958.  
  1959. -// $Id
  1960.  
  1961. -/**
  1962.  
  1963. - * Error Serializer, for now just uses JSON
  1964.  
  1965. - *
  1966.  
  1967. - * @category HTML
  1968.  
  1969. - * @package AJAX
  1970.  
  1971. - * @author Joshua Eichorn <josh@bluga.net>
  1972.  
  1973. - * @copyright 2005 Joshua Eichorn
  1974.  
  1975. - * @license http://www.php.net/license/3_0.txt PHP License 3.0
  1976.  
  1977. - * @version Release: @package_version@
  1978.  
  1979. - * @link http://pear.php.net/package/HTML_AJAX
  1980.  
  1981. - */
  1982.  
  1983. -class HTML_AJAX_Serializer_Error extends HTML_AJAX_Serializer_JSON
  1984.  
  1985. -{
  1986.  
  1987. -
  1988.  
  1989. -}
  1990.  
  1991. -/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
  1992.  
  1993. -?>
  1994.  
  1995. +<?php
  1996. +require_once 'HTML/AJAX/Serializer/JSON.php';
  1997. +// $Id
  1998. +/**
  1999. + * Error Serializer, for now just uses JSON
  2000. + *
  2001. + * @category HTML
  2002. + * @package AJAX
  2003. + * @author Joshua Eichorn <josh@bluga.net>
  2004. + * @copyright 2005 Joshua Eichorn
  2005. + * @license http://www.php.net/license/3_0.txt PHP License 3.0
  2006. + * @version Release: @package_version@
  2007. + * @link http://pear.php.net/package/HTML_AJAX
  2008. + */
  2009. +class HTML_AJAX_Serializer_Error extends HTML_AJAX_Serializer_JSON
  2010. +{
  2011. +
  2012. +}
  2013. +/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
  2014. +?>
  2015. Index: AJAX/Serializer/JSON.php
  2016. ===================================================================
  2017. RCS file: /repository/pear/HTML_AJAX/AJAX/Serializer/JSON.php,v
  2018. retrieving revision 1.12
  2019. diff -u -r1.12 JSON.php
  2020. --- AJAX/Serializer/JSON.php 7 May 2008 21:26:19 -0000 1.12
  2021. +++ AJAX/Serializer/JSON.php 6 Dec 2008 14:31:58 -0000
  2022. @@ -1,96 +1,102 @@
  2023. -<?php
  2024.  
  2025. -require_once 'HTML/AJAX/JSON.php';
  2026.  
  2027. -// $Id: JSON.php,v 1.12 2008/05/07 21:26:19 jeichorn Exp $
  2028.  
  2029. -/**
  2030.  
  2031. - * JSON Serializer
  2032.  
  2033. - *
  2034.  
  2035. - * @category HTML
  2036.  
  2037. - * @package AJAX
  2038.  
  2039. - * @author Joshua Eichorn <josh@bluga.net>
  2040.  
  2041. - * @copyright 2005 Joshua Eichorn
  2042.  
  2043. - * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
  2044.  
  2045. - * @version Release: @package_version@
  2046.  
  2047. - * @link http://pear.php.net/package/PackageName
  2048.  
  2049. - */
  2050.  
  2051. -// {{{ class HTMLA_AJAX_Serialize_JSON
  2052.  
  2053. -class HTML_AJAX_Serializer_JSON
  2054.  
  2055. -{
  2056.  
  2057. - // {{{ variables-properties
  2058.  
  2059. - /**
  2060.  
  2061. - * JSON instance
  2062.  
  2063. - * @var HTML_AJAX_JSON
  2064.  
  2065. - * @access private
  2066.  
  2067. - */
  2068.  
  2069. - var $_json;
  2070.  
  2071. -
  2072.  
  2073. - /**
  2074.  
  2075. - * use json php extension http://www.aurore.net/projects/php-json/
  2076.  
  2077. - * @access private
  2078.  
  2079. - */
  2080.  
  2081. - var $_jsonext;
  2082.  
  2083. -
  2084.  
  2085. - /**
  2086.  
  2087. - * use loose typing to decode js objects into php associative arrays
  2088.  
  2089. - * @access public
  2090.  
  2091. - */
  2092.  
  2093. - var $loose_type;
  2094.  
  2095. -
  2096.  
  2097. - // }}}
  2098.  
  2099. - // {{{ constructor
  2100.  
  2101. - function HTML_AJAX_Serializer_JSON($use_loose_type = true)
  2102.  
  2103. - {
  2104.  
  2105. - $this->loose_type = (bool) $use_loose_type;
  2106.  
  2107. - $this->_jsonext = $this->_detect();
  2108.  
  2109. - if(!$this->_jsonext) {
  2110.  
  2111. - $use_loose_type = ($this->loose_type) ? SERVICES_JSON_LOOSE_TYPE : 0;
  2112.  
  2113. - $this->_json = new HTML_AJAX_JSON($use_loose_type);
  2114.  
  2115. - }
  2116.  
  2117. - }
  2118.  
  2119. - // }}}
  2120.  
  2121. - // {{{ serialize
  2122.  
  2123. - /**
  2124.  
  2125. - * This function serializes and input passed to it.
  2126.  
  2127. - *
  2128.  
  2129. - * @access public
  2130.  
  2131. - * @param string $input The input to serialize.
  2132.  
  2133. - * @return string $input The serialized input.
  2134.  
  2135. - */
  2136.  
  2137. - function serialize($input)
  2138.  
  2139. - {
  2140.  
  2141. - if($this->_jsonext) {
  2142.  
  2143. - return json_encode($input);
  2144.  
  2145. - } else {
  2146.  
  2147. - return $this->_json->encode($input);
  2148.  
  2149. - }
  2150.  
  2151. - }
  2152.  
  2153. - // }}}
  2154.  
  2155. - // {{{ unserialize
  2156.  
  2157. - /**
  2158.  
  2159. - * this function unserializes the input passed to it.
  2160.  
  2161. - *
  2162.  
  2163. - * @access public
  2164.  
  2165. - * @param string $input The input to unserialize
  2166.  
  2167. - * @return string $input The unserialized input.
  2168.  
  2169. - */
  2170.  
  2171. - function unserialize($input)
  2172.  
  2173. - {
  2174.  
  2175. - if($this->_jsonext) {
  2176.  
  2177. - return json_decode($input, $this->loose_type);
  2178.  
  2179. - } else {
  2180.  
  2181. - return $this->_json->decode($input);
  2182.  
  2183. - }
  2184.  
  2185. - }
  2186.  
  2187. - // }}}
  2188.  
  2189. - // {{{ _detect
  2190.  
  2191. - /**
  2192.  
  2193. - * detects the loaded extension
  2194.  
  2195. - */
  2196.  
  2197. - function _detect()
  2198.  
  2199. - {
  2200.  
  2201. - return extension_loaded('json');
  2202.  
  2203. - }
  2204.  
  2205. - // }}}
  2206.  
  2207. -}
  2208.  
  2209. -// }}}
  2210.  
  2211. -/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
  2212.  
  2213. -?>
  2214.  
  2215. +<?php
  2216. +require_once 'HTML/AJAX/JSON.php';
  2217. +// $Id: JSON.php,v 1.12 2008/05/07 21:26:19 jeichorn Exp $
  2218. +/**
  2219. + * JSON Serializer
  2220. + *
  2221. + * @category HTML
  2222. + * @package AJAX
  2223. + * @author Joshua Eichorn <josh@bluga.net>
  2224. + * @copyright 2005 Joshua Eichorn
  2225. + * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
  2226. + * @version Release: @package_version@
  2227. + * @link http://pear.php.net/package/HTML_AJAX
  2228. + */
  2229. +// {{{ class HTMLA_AJAX_Serialize_JSON
  2230. +class HTML_AJAX_Serializer_JSON
  2231. +{
  2232. + // {{{ variables-properties
  2233. + /**
  2234. + * JSON instance
  2235. + * @var HTML_AJAX_JSON
  2236. + * @access private
  2237. + */
  2238. + var $_json;
  2239. +
  2240. + /**
  2241. + * use json php extension http://www.aurore.net/projects/php-json/
  2242. + * @access private
  2243. + */
  2244. + var $_jsonext;
  2245. +
  2246. + /**
  2247. + * use loose typing to decode js objects into php associative arrays
  2248. + * @access public
  2249. + */
  2250. + var $loose_type;
  2251. +
  2252. + // }}}
  2253. + // {{{ constructor
  2254. + function HTML_AJAX_Serializer_JSON($use_loose_type = true)
  2255. + {
  2256. + $this->loose_type = (bool) $use_loose_type;
  2257. + $this->_jsonext = $this->_detect();
  2258. +
  2259. + if (!$this->_jsonext) {
  2260. + $use_loose_type = $this->loose_type ? SERVICES_JSON_LOOSE_TYPE : 0;
  2261. +
  2262. + $this->_json = new HTML_AJAX_JSON($use_loose_type);
  2263. + }
  2264. + }
  2265. + // }}}
  2266. + // {{{ serialize
  2267. + /**
  2268. + * This function serializes and input passed to it.
  2269. + *
  2270. + * @param string $input The input to serialize.
  2271. + *
  2272. + * @access public
  2273. + * @return string $input The serialized input.
  2274. + */
  2275. + function serialize($input)
  2276. + {
  2277. + if ($this->_jsonext) {
  2278. + return json_encode($input);
  2279. + }
  2280. +
  2281. + return $this->_json->encode($input);
  2282. + }
  2283. + // }}}
  2284. + // {{{ unserialize
  2285. + /**
  2286. + * this function unserializes the input passed to it.
  2287. + *
  2288. + * @param string $input The input to unserialize
  2289. + *
  2290. + * @access public
  2291. + * @return string $input The unserialized input.
  2292. + */
  2293. + function unserialize($input)
  2294. + {
  2295. + if ($this->_jsonext) {
  2296. + return json_decode($input, $this->loose_type);
  2297. + }
  2298. +
  2299. + return $this->_json->decode($input);
  2300. + }
  2301. + // }}}
  2302. + // {{{ _detect
  2303. + /**
  2304. + * detects the loaded extension
  2305. + *
  2306. + * @return bool
  2307. + */
  2308. + function _detect()
  2309. + {
  2310. + return extension_loaded('json');
  2311. + }
  2312. + // }}}
  2313. +}
  2314. +// }}}
  2315. +/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
  2316. +?>
  2317. Index: AJAX/Serializer/Null.php
  2318. ===================================================================
  2319. RCS file: /repository/pear/HTML_AJAX/AJAX/Serializer/Null.php,v
  2320. retrieving revision 1.11
  2321. diff -u -r1.11 Null.php
  2322. --- AJAX/Serializer/Null.php 7 May 2008 21:26:19 -0000 1.11
  2323. +++ AJAX/Serializer/Null.php 6 Dec 2008 14:31:58 -0000
  2324. @@ -1,28 +1,28 @@
  2325. -<?php
  2326.  
  2327. -// $Id: Null.php,v 1.11 2008/05/07 21:26:19 jeichorn Exp $
  2328.  
  2329. -/**
  2330.  
  2331. - * Null Serializer
  2332.  
  2333. - *
  2334.  
  2335. - * @category HTML
  2336.  
  2337. - * @package AJAX
  2338.  
  2339. - * @author Joshua Eichorn <josh@bluga.net>
  2340.  
  2341. - * @copyright 2005 Joshua Eichorn
  2342.  
  2343. - * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
  2344.  
  2345. - * @version Release: @package_version@
  2346.  
  2347. - * @link http://pear.php.net/package/PackageName
  2348.  
  2349. - */
  2350.  
  2351. -class HTML_AJAX_Serializer_Null
  2352.  
  2353. -{
  2354.  
  2355. -
  2356.  
  2357. - function serialize($input)
  2358.  
  2359. - {
  2360.  
  2361. - return $input;
  2362.  
  2363. - }
  2364.  
  2365. -
  2366.  
  2367. - function unserialize($input)
  2368.  
  2369. - {
  2370.  
  2371. - return $input;
  2372.  
  2373. - }
  2374.  
  2375. -}
  2376.  
  2377. -/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
  2378.  
  2379. -?>
  2380.  
  2381. +<?php
  2382. +// $Id: Null.php,v 1.11 2008/05/07 21:26:19 jeichorn Exp $
  2383. +/**
  2384. + * Null Serializer
  2385. + *
  2386. + * @category HTML
  2387. + * @package AJAX
  2388. + * @author Joshua Eichorn <josh@bluga.net>
  2389. + * @copyright 2005 Joshua Eichorn
  2390. + * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
  2391. + * @version Release: @package_version@
  2392. + * @link http://pear.php.net/package/HTML_AJAX
  2393. + */
  2394. +class HTML_AJAX_Serializer_Null
  2395. +{
  2396. +
  2397. + function serialize($input)
  2398. + {
  2399. + return $input;
  2400. + }
  2401. +
  2402. + function unserialize($input)
  2403. + {
  2404. + return $input;
  2405. + }
  2406. +}
  2407. +/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
  2408. +?>
  2409. Index: AJAX/Serializer/PHP.php
  2410. ===================================================================
  2411. RCS file: /repository/pear/HTML_AJAX/AJAX/Serializer/PHP.php,v
  2412. retrieving revision 1.3
  2413. diff -u -r1.3 PHP.php
  2414. --- AJAX/Serializer/PHP.php 7 May 2008 21:26:19 -0000 1.3
  2415. +++ AJAX/Serializer/PHP.php 6 Dec 2008 14:31:58 -0000
  2416. @@ -1,88 +1,89 @@
  2417. -<?php
  2418.  
  2419. -// $Id: PHP.php,v 1.3 2008/05/07 21:26:19 jeichorn Exp $
  2420.  
  2421. -/**
  2422.  
  2423. - * PHP Serializer
  2424.  
  2425. - *
  2426.  
  2427. - * @category HTML
  2428.  
  2429. - * @package AJAX
  2430.  
  2431. - * @author Arpad Ray <arpad@php.net>
  2432.  
  2433. - * @copyright 2005 Arpad Ray
  2434.  
  2435. - * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
  2436.  
  2437. - * @version Release: @package_version@
  2438.  
  2439. - * @link http://pear.php.net/package/HTML_AJAX
  2440.  
  2441. - */
  2442.  
  2443. -class HTML_AJAX_Serializer_PHP
  2444.  
  2445. -{
  2446.  
  2447. - function serialize($input)
  2448.  
  2449. - {
  2450.  
  2451. - return serialize($input);
  2452.  
  2453. - }
  2454.  
  2455. -
  2456.  
  2457. - /**
  2458.  
  2459. - * Unserializes the given string
  2460.  
  2461. - *
  2462.  
  2463. - * Triggers an error if a class is found which is not
  2464.  
  2465. - * in the provided array of allowed class names.
  2466.  
  2467. - *
  2468.  
  2469. - * @param string $input
  2470.  
  2471. - * the serialized string to process
  2472.  
  2473. - * @param array $allowedClasses
  2474.  
  2475. - * an array of class names to check objects against
  2476.  
  2477. - * before instantion
  2478.  
  2479. - * @return mixed
  2480.  
  2481. - * the unserialized variable on success, or false on
  2482.  
  2483. - * failure. If this method fails it will also trigger
  2484.  
  2485. - * a warning.
  2486.  
  2487. - */
  2488.  
  2489. - function unserialize($input, $allowedClasses)
  2490.  
  2491. - {
  2492.  
  2493. - if (version_compare(PHP_VERSION, '4.3.10', '<')
  2494.  
  2495. - || (substr(PHP_VERSION, 0, 1) == '5' && version_compare(PHP_VERSION, '5.0.3', '<'))) {
  2496.  
  2497. - trigger_error('Unsafe version of PHP for native unserialization');
  2498.  
  2499. - return false;
  2500.  
  2501. - }
  2502.  
  2503. - $classes = $this->_getSerializedClassNames($input);
  2504.  
  2505. - if ($classes === false) {
  2506.  
  2507. - trigger_error('Invalidly serialized string');
  2508.  
  2509. - return false;
  2510.  
  2511. - }
  2512.  
  2513. - $diff = array_diff($classes, $allowedClasses);
  2514.  
  2515. - if (!empty($diff)) {
  2516.  
  2517. - trigger_error('Class(es) not allowed to be serialized');
  2518.  
  2519. - return false;
  2520.  
  2521. - }
  2522.  
  2523. - return unserialize($input);
  2524.  
  2525. - }
  2526.  
  2527. -
  2528.  
  2529. - /**
  2530.  
  2531. - * Extract class names from serialized string
  2532.  
  2533. - *
  2534.  
  2535. - * Adapted from code by Harry Fuecks
  2536.  
  2537. - *
  2538.  
  2539. - * @param string $string
  2540.  
  2541. - * the serialized string to process
  2542.  
  2543. - * @return mixed
  2544.  
  2545. - * an array of class names found, or false if the input
  2546.  
  2547. - * is invalidly formed
  2548.  
  2549. - */
  2550.  
  2551. - function _getSerializedClassNames($string) {
  2552.  
  2553. - // Strip any string representations (which might contain object syntax)
  2554.  
  2555. - while (($pos = strpos($string, 's:')) !== false) {
  2556.  
  2557. - $pos2 = strpos($string, ':', $pos + 2);
  2558.  
  2559. - if ($pos2 === false) {
  2560.  
  2561. - // invalidly serialized string
  2562.  
  2563. - return false;
  2564.  
  2565. - }
  2566.  
  2567. - $end = $pos + 2 + substr($string, $pos + 2, $pos2) + 1;
  2568.  
  2569. - $string = substr($string, 0, $pos) . substr($string, $end);
  2570.  
  2571. - }
  2572.  
  2573. -
  2574.  
  2575. - // Pull out the class names
  2576.  
  2577. - preg_match_all('/O:[0-9]+:"(.*)"/U', $string, $matches);
  2578.  
  2579. -
  2580.  
  2581. - // Make sure names are unique (same object serialized twice)
  2582.  
  2583. - return array_unique($matches[1]);
  2584.  
  2585. - }
  2586.  
  2587. -}
  2588.  
  2589. -/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
  2590.  
  2591. -?>
  2592.  
  2593. +<?php
  2594. +// $Id: PHP.php,v 1.3 2008/05/07 21:26:19 jeichorn Exp $
  2595. +/**
  2596. + * PHP Serializer
  2597. + *
  2598. + * @category HTML
  2599. + * @package AJAX
  2600. + * @author Arpad Ray <arpad@php.net>
  2601. + * @copyright 2005 Arpad Ray
  2602. + * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
  2603. + * @version Release: @package_version@
  2604. + * @link http://pear.php.net/package/HTML_AJAX
  2605. + */
  2606. +class HTML_AJAX_Serializer_PHP
  2607. +{
  2608. + function serialize($input)
  2609. + {
  2610. + return serialize($input);
  2611. + }
  2612. +
  2613. + /**
  2614. + * Unserializes the given string
  2615. + *
  2616. + * Triggers an error if a class is found which is not
  2617. + * in the provided array of allowed class names.
  2618. + *
  2619. + * @param string $input the serialized string to process
  2620. + * @param array $allowedClasses an array of class names to check objects
  2621. + * against before instantion
  2622. + *
  2623. + * @return mixed
  2624. + * the unserialized variable on success, or false on
  2625. + * failure. If this method fails it will also trigger
  2626. + * a warning.
  2627. + */
  2628. + function unserialize($input, $allowedClasses)
  2629. + {
  2630. + if (version_compare(PHP_VERSION, '4.3.10', '<')
  2631. + || (substr(PHP_VERSION, 0, 1) == '5'
  2632. + && version_compare(PHP_VERSION, '5.0.3', '<'))) {
  2633. + trigger_error('Unsafe version of PHP for native unserialization');
  2634. + return false;
  2635. + }
  2636. + $classes = $this->_getSerializedClassNames($input);
  2637. + if ($classes === false) {
  2638. + trigger_error('Invalidly serialized string');
  2639. + return false;
  2640. + }
  2641. + $diff = array_diff($classes, $allowedClasses);
  2642. + if (!empty($diff)) {
  2643. + trigger_error('Class(es) not allowed to be serialized');
  2644. + return false;
  2645. + }
  2646. + return unserialize($input);
  2647. + }
  2648. +
  2649. + /**
  2650. + * Extract class names from serialized string
  2651. + *
  2652. + * Adapted from code by Harry Fuecks
  2653. + *
  2654. + * @param string $string the serialized string to process
  2655. + *
  2656. + * @return mixed
  2657. + * an array of class names found, or false if the input
  2658. + * is invalidly formed
  2659. + */
  2660. + function _getSerializedClassNames($string)
  2661. + {
  2662. + // Strip any string representations (which might contain object syntax)
  2663. + while (($pos = strpos($string, 's:')) !== false) {
  2664. + $pos2 = strpos($string, ':', $pos + 2);
  2665. + if ($pos2 === false) {
  2666. + // invalidly serialized string
  2667. + return false;
  2668. + }
  2669. + $end = $pos + 2 + substr($string, $pos + 2, $pos2) + 1;
  2670. + $string = substr($string, 0, $pos) . substr($string, $end);
  2671. + }
  2672. +
  2673. + // Pull out the class names
  2674. + preg_match_all('/O:[0-9]+:"(.*)"/U', $string, $matches);
  2675. +
  2676. + // Make sure names are unique (same object serialized twice)
  2677. + return array_unique($matches[1]);
  2678. + }
  2679. +}
  2680. +/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
  2681. +?>
  2682. Index: AJAX/Serializer/Urlencoded.php
  2683. ===================================================================
  2684. RCS file: /repository/pear/HTML_AJAX/AJAX/Serializer/Urlencoded.php,v
  2685. retrieving revision 1.3
  2686. diff -u -r1.3 Urlencoded.php
  2687. --- AJAX/Serializer/Urlencoded.php 7 May 2008 21:26:19 -0000 1.3
  2688. +++ AJAX/Serializer/Urlencoded.php 6 Dec 2008 14:31:58 -0000
  2689. @@ -1,67 +1,67 @@
  2690. -<?php
  2691.  
  2692. -// $Id: Urlencoded.php,v 1.3 2008/05/07 21:26:19 jeichorn Exp $
  2693.  
  2694. -
  2695.  
  2696. -// {{{ http_build_query
  2697.  
  2698. -/**
  2699.  
  2700. - * Replacement for http_build_query()
  2701.  
  2702. - *
  2703.  
  2704. - * @link http://php.net/function.http-build-query
  2705.  
  2706. - * @author vlad_mustafin@ukr.net
  2707.  
  2708. - * @author Arpad Ray <arpad@php.net>
  2709.  
  2710. - */
  2711.  
  2712. -if (!function_exists('http_build_query')) {
  2713.  
  2714. - function http_build_query($formdata, $numeric_prefix = null, $key = null)
  2715.  
  2716. - {
  2717.  
  2718. - $res = array();
  2719.  
  2720. - foreach ((array)$formdata as $k => $v) {
  2721.  
  2722. - if (is_resource($v)) {
  2723.  
  2724. - return null;
  2725.  
  2726. - }
  2727.  
  2728. - $tmp_key = urlencode(is_int($k) ? $numeric_prefix . $k : $k);
  2729.  
  2730. - if (!is_null($key)) {
  2731.  
  2732. - $tmp_key = $key . '[' . $tmp_key . ']';
  2733.  
  2734. - }
  2735.  
  2736. - $res[] = (is_scalar($v))
  2737.  
  2738. - ? $tmp_key . '=' . urlencode($v)
  2739.  
  2740. - : http_build_query($v, null , $tmp_key);
  2741.  
  2742. - }
  2743.  
  2744. - $separator = ini_get('arg_separator.output');
  2745.  
  2746. - if (strlen($separator) == 0) {
  2747.  
  2748. - $separator = '&';
  2749.  
  2750. - }
  2751.  
  2752. - return implode($separator, $res);
  2753.  
  2754. - }
  2755.  
  2756. -}
  2757.  
  2758. -// }}}
  2759.  
  2760. -// {{{ class HTML_AJAX_Serialize_Urlencoded
  2761.  
  2762. -/**
  2763.  
  2764. - * URL Encoding Serializer
  2765.  
  2766. - *
  2767.  
  2768. - * @category HTML
  2769.  
  2770. - * @package AJAX
  2771.  
  2772. - * @author Arpad Ray <arpad@php.net>
  2773.  
  2774. - * @author David Coallier <davidc@php.net>
  2775.  
  2776. - * @copyright 2005 Arpad Ray
  2777.  
  2778. - * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
  2779.  
  2780. - * @version Release: @package_version@
  2781.  
  2782. - * @link http://pear.php.net/package/HTML_AJAX
  2783.  
  2784. - */
  2785.  
  2786. -class HTML_AJAX_Serializer_Urlencoded
  2787.  
  2788. -{
  2789.  
  2790. - // {{{ serialize
  2791.  
  2792. - function serialize($input)
  2793.  
  2794. - {
  2795.  
  2796. - return http_build_query(array('_HTML_AJAX' => $input));
  2797.  
  2798. - }
  2799.  
  2800. - // }}}
  2801.  
  2802. - // {{{ unserialize
  2803.  
  2804. - function unserialize($input)
  2805.  
  2806. - {
  2807.  
  2808. - parse_str($input, $ret);
  2809.  
  2810. - return (isset($ret['_HTML_AJAX']) ? $ret['_HTML_AJAX'] : $ret);
  2811.  
  2812. - }
  2813.  
  2814. - // }}}
  2815.  
  2816. -}
  2817.  
  2818. -// }}}
  2819.  
  2820. -/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
  2821.  
  2822. -?>
  2823.  
  2824. +<?php
  2825. +// $Id: Urlencoded.php,v 1.3 2008/05/07 21:26:19 jeichorn Exp $
  2826. +
  2827. +// {{{ http_build_query
  2828. +/**
  2829. + * Replacement for http_build_query()
  2830. + *
  2831. + * @link http://php.net/function.http-build-query
  2832. + * @author vlad_mustafin@ukr.net
  2833. + * @author Arpad Ray <arpad@php.net>
  2834. + */
  2835. +if (!function_exists('http_build_query')) {
  2836. + function http_build_query($formdata, $numeric_prefix = null, $key = null)
  2837. + {
  2838. + $res = array();
  2839. + foreach ((array)$formdata as $k => $v) {
  2840. + if (is_resource($v)) {
  2841. + return null;
  2842. + }
  2843. + $tmp_key = urlencode(is_int($k) ? $numeric_prefix . $k : $k);
  2844. + if (!is_null($key)) {
  2845. + $tmp_key = $key . '[' . $tmp_key . ']';
  2846. + }
  2847. + $res[] = (is_scalar($v))
  2848. + ? $tmp_key . '=' . urlencode($v)
  2849. + : http_build_query($v, null, $tmp_key);
  2850. + }
  2851. + $separator = ini_get('arg_separator.output');
  2852. + if (strlen($separator) == 0) {
  2853. + $separator = '&';
  2854. + }
  2855. + return implode($separator, $res);
  2856. + }
  2857. +}
  2858. +// }}}
  2859. +// {{{ class HTML_AJAX_Serialize_Urlencoded
  2860. +/**
  2861. + * URL Encoding Serializer
  2862. + *
  2863. + * @category HTML
  2864. + * @package AJAX
  2865. + * @author Arpad Ray <arpad@php.net>
  2866. + * @author David Coallier <davidc@php.net>
  2867. + * @copyright 2005 Arpad Ray
  2868. + * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
  2869. + * @version Release: @package_version@
  2870. + * @link http://pear.php.net/package/HTML_AJAX
  2871. + */
  2872. +class HTML_AJAX_Serializer_Urlencoded
  2873. +{
  2874. + // {{{ serialize
  2875. + function serialize($input)
  2876. + {
  2877. + return http_build_query(array('_HTML_AJAX' => $input));
  2878. + }
  2879. + // }}}
  2880. + // {{{ unserialize
  2881. + function unserialize($input)
  2882. + {
  2883. + parse_str($input, $ret);
  2884. + return (isset($ret['_HTML_AJAX']) ? $ret['_HTML_AJAX'] : $ret);
  2885. + }
  2886. + // }}}
  2887. +}
  2888. +// }}}
  2889. +/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
  2890. +?>
  2891. Index: AJAX/Serializer/XML.php
  2892. ===================================================================
  2893. RCS file: /repository/pear/HTML_AJAX/AJAX/Serializer/XML.php,v
  2894. retrieving revision 1.1
  2895. diff -u -r1.1 XML.php
  2896. --- AJAX/Serializer/XML.php 7 May 2008 21:28:11 -0000 1.1
  2897. +++ AJAX/Serializer/XML.php 6 Dec 2008 14:31:58 -0000
  2898. @@ -1,88 +1,83 @@
  2899. -<?php
  2900.  
  2901. -// $Id: XML.php,v 1.1 2008/05/07 21:28:11 jeichorn Exp $
  2902.  
  2903. -/**
  2904.  
  2905. - * XML Serializer - does NOT need a js serializer, use responseXML property in XmlHttpRequest
  2906.  
  2907. - *
  2908.  
  2909. - * @category HTML
  2910.  
  2911. - * @package AJAX
  2912.  
  2913. - * @author Elizabeth Smith <auroraeosrose@gmail.com>
  2914.  
  2915. - * @copyright 2005-2006 Elizabeth Smith
  2916.  
  2917. - * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
  2918.  
  2919. - * @version Release: @package_version@
  2920.  
  2921. - * @link http://pear.php.net/package/PackageName
  2922.  
  2923. - */
  2924.  
  2925. -class HTML_AJAX_Serializer_XML
  2926.  
  2927. -{
  2928.  
  2929. -
  2930.  
  2931. - /**
  2932.  
  2933. - * Serializes a domdocument into an xml string
  2934.  
  2935. - *
  2936.  
  2937. - * Uses dom or domxml to dump a string from a DomDocument instance
  2938.  
  2939. - * remember dom is always the default and this will die horribly without
  2940.  
  2941. - * a domdocument instance
  2942.  
  2943. - *
  2944.  
  2945. - * @access public
  2946.  
  2947. - * @param object $input instanceof DomDocument
  2948.  
  2949. - * @return string xml string of DomDocument
  2950.  
  2951. - */
  2952.  
  2953. - function serialize($input)
  2954.  
  2955. - {
  2956.  
  2957. - if(empty($input))
  2958.  
  2959. - {
  2960.  
  2961. - return $input;
  2962.  
  2963. - }
  2964.  
  2965. - // we check for the dom extension
  2966.  
  2967. - elseif (extension_loaded('Dom'))
  2968.  
  2969. - {
  2970.  
  2971. - return $input->saveXml();
  2972.  
  2973. - }
  2974.  
  2975. - // then will check for domxml
  2976.  
  2977. - elseif (extension_loaded('Domxml'))
  2978.  
  2979. - {
  2980.  
  2981. - return $input->dump_mem();
  2982.  
  2983. - }
  2984.  
  2985. - // will throw an error
  2986.  
  2987. - else {
  2988.  
  2989. - $error = new HTML_AJAX_Serializer_Error();
  2990.  
  2991. - $this->serializerNewType = 'Error';
  2992.  
  2993. - return $error->serialize(array('errStr'=>"Missing PHP Dom extension direct XML won't work"));
  2994.  
  2995. - }
  2996.  
  2997. - }
  2998.  
  2999. -
  3000.  
  3001. - /**
  3002.  
  3003. - * Unserializes the xml string sent from the document
  3004.  
  3005. - *
  3006.  
  3007. - * Uses dom or domxml to pump a string into a DomDocument instance
  3008.  
  3009. - * remember dom is always the default and this will die horribly without
  3010.  
  3011. - * one or the other, and will throw warnings if you have bad xml
  3012.  
  3013. - *
  3014.  
  3015. - * @access public
  3016.  
  3017. - * @param string $input The input to serialize.
  3018.  
  3019. - * @return object instanceofDomDocument
  3020.  
  3021. - */
  3022.  
  3023. - function unserialize($input)
  3024.  
  3025. - {
  3026.  
  3027. - if(empty($input))
  3028.  
  3029. - {
  3030.  
  3031. - return $input;
  3032.  
  3033. - }
  3034.  
  3035. - // we check for the dom extension
  3036.  
  3037. - elseif (extension_loaded('Dom'))
  3038.  
  3039. - {
  3040.  
  3041. - $doc = new DOMDocument();
  3042.  
  3043. - $doc->loadXML($input);
  3044.  
  3045. - return $doc;
  3046.  
  3047. - }
  3048.  
  3049. - // then we check for the domxml extensions
  3050.  
  3051. - elseif (extension_loaded('Domxml'))
  3052.  
  3053. - {
  3054.  
  3055. - return domxml_open_mem($input);
  3056.  
  3057. - }
  3058.  
  3059. - // we give up and just return the xml directly
  3060.  
  3061. - else
  3062.  
  3063. - {
  3064.  
  3065. - return $input;
  3066.  
  3067. - }
  3068.  
  3069. - }
  3070.  
  3071. -}
  3072.  
  3073. -?>
  3074.  
  3075. +<?php
  3076. +// $Id: XML.php,v 1.1 2008/05/07 21:28:11 jeichorn Exp $
  3077. +/**
  3078. + * XML Serializer - does NOT need a js serializer,
  3079. + * use responseXML property in XmlHttpRequest
  3080. + *
  3081. + * @category HTML
  3082. + * @package AJAX
  3083. + * @author Elizabeth Smith <auroraeosrose@gmail.com>
  3084. + * @copyright 2005-2006 Elizabeth Smith
  3085. + * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
  3086. + * @version Release: @package_version@
  3087. + * @link http://pear.php.net/package/PackageName
  3088. + */
  3089. +class HTML_AJAX_Serializer_XML
  3090. +{
  3091. +
  3092. + /**
  3093. + * Serializes a domdocument into an xml string
  3094. + *
  3095. + * Uses dom or domxml to dump a string from a DomDocument instance
  3096. + * remember dom is always the default and this will die horribly without
  3097. + * a domdocument instance
  3098. + *
  3099. + * @param object $input instanceof DomDocument
  3100. + *
  3101. + * @access public
  3102. + * @return string xml string of DomDocument
  3103. + */
  3104. + function serialize($input)
  3105. + {
  3106. + if (empty($input)) {
  3107. + return $input;
  3108. + }
  3109. +
  3110. + if (extension_loaded('Dom')) {
  3111. + return $input->saveXml();
  3112. + }
  3113. + if (extension_loaded('Domxml')) {
  3114. + return $input->dump_mem();
  3115. + }
  3116. +
  3117. + $error = new HTML_AJAX_Serializer_Error();
  3118. + $this->serializerNewType = 'Error';
  3119. +
  3120. + $message = "Missing PHP Dom extension direct XML won't work";
  3121. +
  3122. + return $error->serialize(array('errStr'=> $message));
  3123. + }
  3124. +
  3125. + /**
  3126. + * Unserializes the xml string sent from the document
  3127. + *
  3128. + * Uses dom or domxml to pump a string into a DomDocument instance
  3129. + * remember dom is always the default and this will die horribly without
  3130. + * one or the other, and will throw warnings if you have bad xml
  3131. + *
  3132. + * @param string $input The input to serialize.
  3133. + *
  3134. + * @access public
  3135. + * @return object instanceofDomDocument
  3136. + */
  3137. + function unserialize($input)
  3138. + {
  3139. + if (empty($input)) {
  3140. + return $input;
  3141. + }
  3142. +
  3143. + if (extension_loaded('Dom')) {
  3144. + $doc = new DOMDocument();
  3145. + $doc->loadXML($input);
  3146. + return $doc;
  3147. + }
  3148. +
  3149. + if (extension_loaded('Domxml')) {
  3150. + return domxml_open_mem($input);
  3151. + }
  3152. +
  3153. + // we give up and just return the xml directly
  3154. + return $input;
  3155. + }
  3156. +}
  3157. +?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement