3 * WordPress implementation for PHP functions missing from older PHP versions.
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);
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) {
21 foreach ( (array) $data as $k => $v ) {
24 if ( is_int($k) && $prefix != null )
27 $k = $key . '%5B' . $k . '%5D';
30 elseif ( $v === FALSE )
33 if ( is_array($v) || is_object($v) )
34 array_push($ret,_http_build_query($v, '', $sep, $k, $urlencode));
36 array_push($ret, $k.'='.urlencode($v));
38 array_push($ret, $k.'='.$v);
42 $sep = ini_get('arg_separator.output');
44 return implode($sep, $ret);
47 if ( !function_exists('_') ) {
53 if (!function_exists('stripos')) {
54 function stripos($haystack, $needle, $offset = 0) {
55 return strpos(strtolower($haystack), strtolower($needle), $offset);
59 if ( ! function_exists('hash_hmac') ):
60 function hash_hmac($algo, $data, $key, $raw_output = false) {
61 $packs = array('md5' => 'H32', 'sha1' => 'H40');
63 if ( !isset($packs[$algo]) )
66 $pack = $packs[$algo];
68 if (strlen($key) > 64)
69 $key = pack($pack, $algo($key));
70 else if (strlen($key) < 64)
71 $key = str_pad($key, 64, chr(0));
73 $ipad = (substr($key, 0, 64) ^ str_repeat(chr(0x36), 64));
74 $opad = (substr($key, 0, 64) ^ str_repeat(chr(0x5C), 64));
76 return $algo($opad . pack($pack, $algo($ipad . $data)));
80 if ( ! function_exists('mb_substr') ):
81 function mb_substr( $str, $start, $length=null, $encoding=null ) {
82 return _mb_substr($str, $start, $length, $encoding);
86 function _mb_substr( $str, $start, $length=null, $encoding=null ) {
87 // the solution below, works only for utf-8, so in case of a different
88 // charset, just use built-in substr
89 $charset = get_option( 'blog_charset' );
90 if ( !in_array( $charset, array('utf8', 'utf-8', 'UTF8', 'UTF-8') ) ) {
91 return is_null( $length )? substr( $str, $start ) : substr( $str, $start, $length);
93 // use the regex unicode support to separate the UTF-8 characters into an array
94 preg_match_all( '/./us', $str, $match );
95 $chars = is_null( $length )? array_slice( $match[0], $start ) : array_slice( $match[0], $start, $length );
96 return implode( '', $chars );
99 if ( !function_exists( 'htmlspecialchars_decode' ) ) {
100 // Added in PHP 5.1.0
101 // Error checks from PEAR::PHP_Compat
102 function htmlspecialchars_decode( $string, $quote_style = ENT_COMPAT )
104 if ( !is_scalar( $string ) ) {
105 trigger_error( 'htmlspecialchars_decode() expects parameter 1 to be string, ' . gettype( $string ) . ' given', E_USER_WARNING );
109 if ( !is_int( $quote_style ) && $quote_style !== null ) {
110 trigger_error( 'htmlspecialchars_decode() expects parameter 2 to be integer, ' . gettype( $quote_style ) . ' given', E_USER_WARNING );
114 return wp_specialchars_decode( $string, $quote_style );