wp/wp-includes/class-json.php
changeset 21 48c4eec2b7e6
parent 18 be944660c56a
equal deleted inserted replaced
20:7b1b88e27a20 21:48c4eec2b7e6
    52  * @author      Michal Migurski <mike-json@teczno.com>
    52  * @author      Michal Migurski <mike-json@teczno.com>
    53  * @author      Matt Knapp <mdknapp[at]gmail[dot]com>
    53  * @author      Matt Knapp <mdknapp[at]gmail[dot]com>
    54  * @author      Brett Stimmerman <brettstimmerman[at]gmail[dot]com>
    54  * @author      Brett Stimmerman <brettstimmerman[at]gmail[dot]com>
    55  * @copyright   2005 Michal Migurski
    55  * @copyright   2005 Michal Migurski
    56  * @version     CVS: $Id: JSON.php 305040 2010-11-02 23:19:03Z alan_k $
    56  * @version     CVS: $Id: JSON.php 305040 2010-11-02 23:19:03Z alan_k $
    57  * @license     http://www.opensource.org/licenses/bsd-license.php
    57  * @license     https://www.opensource.org/licenses/bsd-license.php
    58  * @link        http://pear.php.net/pepr/pepr-proposal-show.php?id=198
    58  * @link        https://pear.php.net/pepr/pepr-proposal-show.php?id=198
    59  */
    59  */
    60 
    60 
    61 /**
    61 /**
    62  * Marker constant for Services_JSON::decode(), used to flag stack state
    62  * Marker constant for Services_JSON::decode(), used to flag stack state
    63  */
    63  */
   120  * </code>
   120  * </code>
   121  */
   121  */
   122 class Services_JSON
   122 class Services_JSON
   123 {
   123 {
   124    /**
   124    /**
       
   125     * Object behavior flags.
       
   126     *
       
   127     * @var int
       
   128     */
       
   129     public $use;
       
   130 
       
   131     // private - cache the mbstring lookup results..
       
   132     var $_mb_strlen = false;
       
   133     var $_mb_substr = false;
       
   134     var $_mb_convert_encoding = false;
       
   135 
       
   136    /**
   125     * constructs a new JSON instance
   137     * constructs a new JSON instance
   126     *
   138     *
   127     * @deprecated 5.3.0 Use the PHP native JSON extension instead.
   139     * @deprecated 5.3.0 Use the PHP native JSON extension instead.
   128     *
   140     *
   129     * @param    int     $use    object behavior flags; combine with boolean-OR
   141     * @param    int     $use    object behavior flags; combine with boolean-OR
   152         $this->_mb_strlen            = function_exists('mb_strlen');
   164         $this->_mb_strlen            = function_exists('mb_strlen');
   153         $this->_mb_convert_encoding  = function_exists('mb_convert_encoding');
   165         $this->_mb_convert_encoding  = function_exists('mb_convert_encoding');
   154         $this->_mb_substr            = function_exists('mb_substr');
   166         $this->_mb_substr            = function_exists('mb_substr');
   155     }
   167     }
   156 
   168 
   157 	/**
   169     /**
   158 	 * PHP4 constructor.
   170      * PHP4 constructor.
   159      *
   171      *
   160      * @deprecated 5.3.0 Use __construct() instead.
   172      * @deprecated 5.3.0 Use __construct() instead.
   161      *
   173      *
   162      * @see Services_JSON::__construct()
   174      * @see Services_JSON::__construct()
   163 	 */
   175      */
   164 	public function Services_JSON( $use = 0 ) {
   176     public function Services_JSON( $use = 0 ) {
   165 		_deprecated_constructor( 'Services_JSON', '5.3.0', get_class( $this ) );
   177         _deprecated_constructor( 'Services_JSON', '5.3.0', get_class( $this ) );
   166 		self::__construct( $use );
   178         self::__construct( $use );
   167 	}
   179     }
   168     // private - cache the mbstring lookup results..
   180 
   169     var $_mb_strlen = false;
       
   170     var $_mb_substr = false;
       
   171     var $_mb_convert_encoding = false;
       
   172     
       
   173    /**
   181    /**
   174     * convert a string from one UTF-16 char to one UTF-8 char
   182     * convert a string from one UTF-16 char to one UTF-8 char
   175     *
   183     *
   176     * Normally should be handled by mb_convert_encoding, but
   184     * Normally should be handled by mb_convert_encoding, but
   177     * provides a slower PHP-only method for installations
   185     * provides a slower PHP-only method for installations
   281     */
   289     */
   282     function encode($var)
   290     function encode($var)
   283     {
   291     {
   284         _deprecated_function( __METHOD__, '5.3.0', 'The PHP native JSON extension' );
   292         _deprecated_function( __METHOD__, '5.3.0', 'The PHP native JSON extension' );
   285 
   293 
   286         header('Content-type: application/json');
   294         header('Content-Type: application/json');
   287         return $this->encodeUnsafe($var);
   295         return $this->encodeUnsafe($var);
   288     }
   296     }
   289     /**
   297     /**
   290     * encodes an arbitrary variable into JSON format without JSON Header - warning - may allow XSS!!!!)
   298     * encodes an arbitrary variable into JSON format without JSON Header - warning - may allow XSS!!!!)
   291     *
   299     *
   971 
   979 
   972 if (class_exists('PEAR_Error')) {
   980 if (class_exists('PEAR_Error')) {
   973 
   981 
   974     class Services_JSON_Error extends PEAR_Error
   982     class Services_JSON_Error extends PEAR_Error
   975     {
   983     {
   976 	    /**
   984         /**
   977 	     * PHP5 constructor.
   985          * PHP5 constructor.
   978 	     *
   986          *
   979 	     * @deprecated 5.3.0 Use the PHP native JSON extension instead.
   987          * @deprecated 5.3.0 Use the PHP native JSON extension instead.
   980 	     */
   988          */
   981         function __construct($message = 'unknown error', $code = null,
   989         function __construct($message = 'unknown error', $code = null,
   982                                      $mode = null, $options = null, $userinfo = null)
   990                                      $mode = null, $options = null, $userinfo = null)
   983         {
   991         {
   984             _deprecated_function( __METHOD__, '5.3.0', 'The PHP native JSON extension' );
   992             _deprecated_function( __METHOD__, '5.3.0', 'The PHP native JSON extension' );
   985 
   993 
   986             parent::PEAR_Error($message, $code, $mode, $options, $userinfo);
   994             parent::PEAR_Error($message, $code, $mode, $options, $userinfo);
   987         }
   995         }
   988 
   996 
   989 	    /**
   997         /**
   990 	     * PHP4 constructor.
   998          * PHP4 constructor.
   991 	     *
   999          *
   992 	     * @deprecated 5.3.0 Use __construct() instead.
  1000          * @deprecated 5.3.0 Use __construct() instead.
   993 	     *
  1001          *
   994 	     * @see Services_JSON_Error::__construct()
  1002          * @see Services_JSON_Error::__construct()
   995 	     */
  1003          */
   996 		public function Services_JSON_Error($message = 'unknown error', $code = null,
  1004         public function Services_JSON_Error($message = 'unknown error', $code = null,
   997                                      $mode = null, $options = null, $userinfo = null) {
  1005                                      $mode = null, $options = null, $userinfo = null) {
   998 			_deprecated_constructor( 'Services_JSON_Error', '5.3.0', get_class( $this ) );
  1006             _deprecated_constructor( 'Services_JSON_Error', '5.3.0', get_class( $this ) );
   999 			self::__construct($message, $code, $mode, $options, $userinfo);
  1007             self::__construct($message, $code, $mode, $options, $userinfo);
  1000 		}
  1008         }
  1001     }
  1009     }
  1002 
  1010 
  1003 } else {
  1011 } else {
  1004 
  1012 
  1005     /**
  1013     /**
  1006      * @todo Ultimately, this class shall be descended from PEAR_Error
  1014      * @todo Ultimately, this class shall be descended from PEAR_Error
  1007      */
  1015      */
  1008     class Services_JSON_Error
  1016     class Services_JSON_Error
  1009     {
  1017     {
  1010 	    /**
  1018         /**
  1011 	     * PHP5 constructor.
  1019          * PHP5 constructor.
  1012 	     *
  1020          *
  1013 	     * @deprecated 5.3.0 Use the PHP native JSON extension instead.
  1021          * @deprecated 5.3.0 Use the PHP native JSON extension instead.
  1014 	     */
  1022          */
  1015         function __construct( $message = 'unknown error', $code = null,
  1023         function __construct( $message = 'unknown error', $code = null,
  1016                                      $mode = null, $options = null, $userinfo = null )
  1024                                      $mode = null, $options = null, $userinfo = null )
  1017         {
  1025         {
  1018             _deprecated_function( __METHOD__, '5.3.0', 'The PHP native JSON extension' );
  1026             _deprecated_function( __METHOD__, '5.3.0', 'The PHP native JSON extension' );
  1019         }
  1027         }
  1020 
  1028 
  1021 	    /**
  1029         /**
  1022 	     * PHP4 constructor.
  1030          * PHP4 constructor.
  1023 	     *
  1031          *
  1024 	     * @deprecated 5.3.0 Use __construct() instead.
  1032          * @deprecated 5.3.0 Use __construct() instead.
  1025 	     *
  1033          *
  1026 	     * @see Services_JSON_Error::__construct()
  1034          * @see Services_JSON_Error::__construct()
  1027 	     */
  1035          */
  1028 		public function Services_JSON_Error( $message = 'unknown error', $code = null,
  1036         public function Services_JSON_Error( $message = 'unknown error', $code = null,
  1029 	                                     $mode = null, $options = null, $userinfo = null ) {
  1037                                          $mode = null, $options = null, $userinfo = null ) {
  1030 			_deprecated_constructor( 'Services_JSON_Error', '5.3.0', get_class( $this ) );
  1038             _deprecated_constructor( 'Services_JSON_Error', '5.3.0', get_class( $this ) );
  1031 			self::__construct( $message, $code, $mode, $options, $userinfo );
  1039             self::__construct( $message, $code, $mode, $options, $userinfo );
  1032 		}
  1040         }
  1033     }
  1041     }
  1034 
  1042 
  1035 }
  1043 }
  1036 
  1044 
  1037 endif;
  1045 endif;