MediaWiki
REL1_19
|
00001 <?php 00008 if ( !defined( 'MEDIAWIKI' ) ) { 00009 die( 1 ); 00010 } 00011 00012 require_once dirname( __FILE__ ) . '/Services_JSON.php'; 00013 00017 class FormatJson { 00018 00032 public static function encode( $value, $isHtml = false ) { 00033 // Some versions of PHP have a broken json_encode, see PHP bug 00034 // 46944. Test encoding an affected character (U+20000) to 00035 // avoid this. 00036 if ( !function_exists( 'json_encode' ) || $isHtml || strtolower( json_encode( "\xf0\xa0\x80\x80" ) ) != '"\ud840\udc00"' ) { 00037 $json = new Services_JSON(); 00038 return $json->encode( $value, $isHtml ); 00039 } else { 00040 return json_encode( $value ); 00041 } 00042 } 00043 00055 public static function decode( $value, $assoc = false ) { 00056 if ( !function_exists( 'json_decode' ) ) { 00057 $json = $assoc ? new Services_JSON( SERVICES_JSON_LOOSE_TYPE ) : 00058 new Services_JSON(); 00059 $jsonDec = $json->decode( $value ); 00060 return $jsonDec; 00061 } else { 00062 return json_decode( $value, $assoc ); 00063 } 00064 } 00065 00066 }