web/wp-includes/compat.php
branchwordpress
changeset 132 4d4862461b8d
parent 109 03b0d1493584
equal deleted inserted replaced
131:a4642baaf829 132:4d4862461b8d
    54 	function stripos($haystack, $needle, $offset = 0) {
    54 	function stripos($haystack, $needle, $offset = 0) {
    55 		return strpos(strtolower($haystack), strtolower($needle), $offset);
    55 		return strpos(strtolower($haystack), strtolower($needle), $offset);
    56 	}
    56 	}
    57 }
    57 }
    58 
    58 
    59 if ( ! function_exists('hash_hmac') ):
    59 if ( !function_exists('hash_hmac') ):
    60 function hash_hmac($algo, $data, $key, $raw_output = false) {
    60 function hash_hmac($algo, $data, $key, $raw_output = false) {
       
    61 	return _hash_hmac($algo, $data, $key, $raw_output);
       
    62 }
       
    63 endif;
       
    64 
       
    65 function _hash_hmac($algo, $data, $key, $raw_output = false) {
    61 	$packs = array('md5' => 'H32', 'sha1' => 'H40');
    66 	$packs = array('md5' => 'H32', 'sha1' => 'H40');
    62 
    67 
    63 	if ( !isset($packs[$algo]) )
    68 	if ( !isset($packs[$algo]) )
    64 		return false;
    69 		return false;
    65 
    70 
    66 	$pack = $packs[$algo];
    71 	$pack = $packs[$algo];
    67 
    72 
    68 	if (strlen($key) > 64)
    73 	if (strlen($key) > 64)
    69 		$key = pack($pack, $algo($key));
    74 		$key = pack($pack, $algo($key));
    70 	else if (strlen($key) < 64)
    75 
    71 		$key = str_pad($key, 64, chr(0));
    76 	$key = str_pad($key, 64, chr(0));
    72 
    77 
    73 	$ipad = (substr($key, 0, 64) ^ str_repeat(chr(0x36), 64));
    78 	$ipad = (substr($key, 0, 64) ^ str_repeat(chr(0x36), 64));
    74 	$opad = (substr($key, 0, 64) ^ str_repeat(chr(0x5C), 64));
    79 	$opad = (substr($key, 0, 64) ^ str_repeat(chr(0x5C), 64));
    75 
    80 
    76 	return $algo($opad . pack($pack, $algo($ipad . $data)));
    81 	$hmac = $algo($opad . pack($pack, $algo($ipad . $data)));
       
    82 
       
    83 	if ( $raw_output )
       
    84 		return pack( $pack, $hmac );
       
    85 	return $hmac;
    77 }
    86 }
    78 endif;
       
    79 
    87 
    80 if ( ! function_exists('mb_substr') ):
    88 if ( !function_exists('mb_substr') ):
    81 	function mb_substr( $str, $start, $length=null, $encoding=null ) {
    89 	function mb_substr( $str, $start, $length=null, $encoding=null ) {
    82 		return _mb_substr($str, $start, $length, $encoding);
    90 		return _mb_substr($str, $start, $length, $encoding);
    83 	}
    91 	}
    84 endif;
    92 endif;
    85 
    93 
   113 
   121 
   114 		return wp_specialchars_decode( $string, $quote_style );
   122 		return wp_specialchars_decode( $string, $quote_style );
   115 	}
   123 	}
   116 }
   124 }
   117 
   125 
   118 ?>
   126 // For PHP < 5.2.0
       
   127 if ( !function_exists('json_encode') ) {
       
   128 	function json_encode( $string ) {
       
   129 		global $wp_json;
       
   130 
       
   131 		if ( !is_a($wp_json, 'Services_JSON') ) {
       
   132 			require_once( 'class-json.php' );
       
   133 			$wp_json = new Services_JSON();
       
   134 		}
       
   135 
       
   136 		return $wp_json->encodeUnsafe( $string );
       
   137 	}
       
   138 }
       
   139 
       
   140 if ( !function_exists('json_decode') ) {
       
   141 	function json_decode( $string ) {
       
   142 		global $wp_json;
       
   143 
       
   144 		if ( !is_a($wp_json, 'Services_JSON') ) {
       
   145 			require_once( 'class-json.php' );
       
   146 			$wp_json = new Services_JSON();
       
   147 		}
       
   148 
       
   149 		return $wp_json->decode( $string );
       
   150 	}
       
   151 }
       
   152 
       
   153 // pathinfo that fills 'filename' without extension like in PHP 5.2+
       
   154 function pathinfo52($path) {
       
   155 	$parts = pathinfo($path);
       
   156 	if ( !isset($parts['filename']) ) {
       
   157 		$parts['filename'] = substr( $parts['basename'], 0, strrpos($parts['basename'], '.') );
       
   158 		if ( empty($parts['filename']) ) // there's no extension
       
   159 			$parts['filename'] = $parts['basename'];
       
   160 	}
       
   161 	return $parts;
       
   162 }