Changes in trunk/wp-includes/compat.php [14151:18111]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/compat.php
- Property svn:keywords deleted
r14151 r18111 1 1 <?php 2 2 /** 3 * WordPress implementation for PHP functions missing from older PHP versions.3 * WordPress implementation for PHP functions either missing from older PHP versions or not included by default. 4 4 * 5 5 * @package PHP … … 7 7 */ 8 8 9 // Added in PHP 5.0 10 11 if (!function_exists('http_build_query')) { 12 function http_build_query($data, $prefix=null, $sep=null) { 13 return _http_build_query($data, $prefix, $sep); 14 } 15 } 16 17 // from php.net (modified by Mark Jaquith to behave like the native PHP5 function) 18 function _http_build_query($data, $prefix=null, $sep=null, $key='', $urlencode=true) { 19 $ret = array(); 20 21 foreach ( (array) $data as $k => $v ) { 22 if ( $urlencode) 23 $k = urlencode($k); 24 if ( is_int($k) && $prefix != null ) 25 $k = $prefix.$k; 26 if ( !empty($key) ) 27 $k = $key . '%5B' . $k . '%5D'; 28 if ( $v === NULL ) 29 continue; 30 elseif ( $v === FALSE ) 31 $v = '0'; 32 33 if ( is_array($v) || is_object($v) ) 34 array_push($ret,_http_build_query($v, '', $sep, $k, $urlencode)); 35 elseif ( $urlencode ) 36 array_push($ret, $k.'='.urlencode($v)); 37 else 38 array_push($ret, $k.'='.$v); 39 } 40 41 if ( NULL === $sep ) 42 $sep = ini_get('arg_separator.output'); 43 44 return implode($sep, $ret); 45 } 46 9 // If gettext isn't available 47 10 if ( !function_exists('_') ) { 48 11 function _($string) { … … 51 14 } 52 15 53 if ( !function_exists('stripos')) {54 function stripos($haystack, $needle, $offset = 0) {55 return strpos(strtolower($haystack), strtolower($needle), $offset);16 if ( !function_exists('mb_substr') ): 17 function mb_substr( $str, $start, $length=null, $encoding=null ) { 18 return _mb_substr($str, $start, $length, $encoding); 56 19 } 20 endif; 21 22 function _mb_substr( $str, $start, $length=null, $encoding=null ) { 23 // the solution below, works only for utf-8, so in case of a different 24 // charset, just use built-in substr 25 $charset = get_option( 'blog_charset' ); 26 if ( !in_array( $charset, array('utf8', 'utf-8', 'UTF8', 'UTF-8') ) ) { 27 return is_null( $length )? substr( $str, $start ) : substr( $str, $start, $length); 28 } 29 // use the regex unicode support to separate the UTF-8 characters into an array 30 preg_match_all( '/./us', $str, $match ); 31 $chars = is_null( $length )? array_slice( $match[0], $start ) : array_slice( $match[0], $start, $length ); 32 return implode( '', $chars ); 57 33 } 58 34 … … 85 61 return $hmac; 86 62 } 87 88 if ( !function_exists('mb_substr') ):89 function mb_substr( $str, $start, $length=null, $encoding=null ) {90 return _mb_substr($str, $start, $length, $encoding);91 }92 endif;93 94 function _mb_substr( $str, $start, $length=null, $encoding=null ) {95 // the solution below, works only for utf-8, so in case of a different96 // charset, just use built-in substr97 $charset = get_option( 'blog_charset' );98 if ( !in_array( $charset, array('utf8', 'utf-8', 'UTF8', 'UTF-8') ) ) {99 return is_null( $length )? substr( $str, $start ) : substr( $str, $start, $length);100 }101 // use the regex unicode support to separate the UTF-8 characters into an array102 preg_match_all( '/./us', $str, $match );103 $chars = is_null( $length )? array_slice( $match[0], $start ) : array_slice( $match[0], $start, $length );104 return implode( '', $chars );105 }106 107 if ( !function_exists( 'htmlspecialchars_decode' ) ) {108 // Added in PHP 5.1.0109 // Error checks from PEAR::PHP_Compat110 function htmlspecialchars_decode( $string, $quote_style = ENT_COMPAT )111 {112 if ( !is_scalar( $string ) ) {113 trigger_error( 'htmlspecialchars_decode() expects parameter 1 to be string, ' . gettype( $string ) . ' given', E_USER_WARNING );114 return;115 }116 117 if ( !is_int( $quote_style ) && $quote_style !== null ) {118 trigger_error( 'htmlspecialchars_decode() expects parameter 2 to be integer, ' . gettype( $quote_style ) . ' given', E_USER_WARNING );119 return;120 }121 122 return wp_specialchars_decode( $string, $quote_style );123 }124 }125 126 // For PHP < 5.2.0127 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( ABSPATH . WPINC . '/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, $assoc_array = false ) {142 global $wp_json;143 144 if ( !is_a($wp_json, 'Services_JSON') ) {145 require_once( ABSPATH . WPINC . '/class-json.php' );146 $wp_json = new Services_JSON();147 }148 149 $res = $wp_json->decode( $string );150 if ( $assoc_array )151 $res = _json_decode_object_helper( $res );152 return $res;153 }154 function _json_decode_object_helper($data) {155 if ( is_object($data) )156 $data = get_object_vars($data);157 return is_array($data) ? array_map(__FUNCTION__, $data) : $data;158 }159 }160 161 // pathinfo that fills 'filename' without extension like in PHP 5.2+162 function pathinfo52($path) {163 $parts = pathinfo($path);164 if ( !isset($parts['filename']) ) {165 $parts['filename'] = substr( $parts['basename'], 0, strrpos($parts['basename'], '.') );166 if ( empty($parts['filename']) ) // there's no extension167 $parts['filename'] = $parts['basename'];168 }169 return $parts;170 }
Note: See TracChangeset
for help on using the changeset viewer.