raw
mp-wp_genesis           1 <?php
mp-wp_genesis 2 /**
mp-wp_genesis 3 * WordPress implementation for PHP functions missing from older PHP versions.
mp-wp_genesis 4 *
mp-wp_genesis 5 * @package PHP
mp-wp_genesis 6 * @access private
mp-wp_genesis 7 */
mp-wp_genesis 8
mp-wp_genesis 9 // Added in PHP 5.0
mp-wp_genesis 10
mp-wp_genesis 11 if (!function_exists('http_build_query')) {
mp-wp_genesis 12 function http_build_query($data, $prefix=null, $sep=null) {
mp-wp_genesis 13 return _http_build_query($data, $prefix, $sep);
mp-wp_genesis 14 }
mp-wp_genesis 15 }
mp-wp_genesis 16
mp-wp_genesis 17 // from php.net (modified by Mark Jaquith to behave like the native PHP5 function)
mp-wp_genesis 18 function _http_build_query($data, $prefix=null, $sep=null, $key='', $urlencode=true) {
mp-wp_genesis 19 $ret = array();
mp-wp_genesis 20
mp-wp_genesis 21 foreach ( (array) $data as $k => $v ) {
mp-wp_genesis 22 if ( $urlencode)
mp-wp_genesis 23 $k = urlencode($k);
mp-wp_genesis 24 if ( is_int($k) && $prefix != null )
mp-wp_genesis 25 $k = $prefix.$k;
mp-wp_genesis 26 if ( !empty($key) )
mp-wp_genesis 27 $k = $key . '%5B' . $k . '%5D';
mp-wp_genesis 28 if ( $v === NULL )
mp-wp_genesis 29 continue;
mp-wp_genesis 30 elseif ( $v === FALSE )
mp-wp_genesis 31 $v = '0';
mp-wp_genesis 32
mp-wp_genesis 33 if ( is_array($v) || is_object($v) )
mp-wp_genesis 34 array_push($ret,_http_build_query($v, '', $sep, $k, $urlencode));
mp-wp_genesis 35 elseif ( $urlencode )
mp-wp_genesis 36 array_push($ret, $k.'='.urlencode($v));
mp-wp_genesis 37 else
mp-wp_genesis 38 array_push($ret, $k.'='.$v);
mp-wp_genesis 39 }
mp-wp_genesis 40
mp-wp_genesis 41 if ( NULL === $sep )
mp-wp_genesis 42 $sep = ini_get('arg_separator.output');
mp-wp_genesis 43
mp-wp_genesis 44 return implode($sep, $ret);
mp-wp_genesis 45 }
mp-wp_genesis 46
mp-wp_genesis 47 if ( !function_exists('_') ) {
mp-wp_genesis 48 function _($string) {
mp-wp_genesis 49 return $string;
mp-wp_genesis 50 }
mp-wp_genesis 51 }
mp-wp_genesis 52
mp-wp_genesis 53 if (!function_exists('stripos')) {
mp-wp_genesis 54 function stripos($haystack, $needle, $offset = 0) {
mp-wp_genesis 55 return strpos(strtolower($haystack), strtolower($needle), $offset);
mp-wp_genesis 56 }
mp-wp_genesis 57 }
mp-wp_genesis 58
mp-wp_genesis 59 if ( ! function_exists('hash_hmac') ):
mp-wp_genesis 60 function hash_hmac($algo, $data, $key, $raw_output = false) {
mp-wp_genesis 61 $packs = array('md5' => 'H32', 'sha1' => 'H40');
mp-wp_genesis 62
mp-wp_genesis 63 if ( !isset($packs[$algo]) )
mp-wp_genesis 64 return false;
mp-wp_genesis 65
mp-wp_genesis 66 $pack = $packs[$algo];
mp-wp_genesis 67
mp-wp_genesis 68 if (strlen($key) > 64)
mp-wp_genesis 69 $key = pack($pack, $algo($key));
mp-wp_genesis 70 else if (strlen($key) < 64)
mp-wp_genesis 71 $key = str_pad($key, 64, chr(0));
mp-wp_genesis 72
mp-wp_genesis 73 $ipad = (substr($key, 0, 64) ^ str_repeat(chr(0x36), 64));
mp-wp_genesis 74 $opad = (substr($key, 0, 64) ^ str_repeat(chr(0x5C), 64));
mp-wp_genesis 75
mp-wp_genesis 76 return $algo($opad . pack($pack, $algo($ipad . $data)));
mp-wp_genesis 77 }
mp-wp_genesis 78 endif;
mp-wp_genesis 79
mp-wp_genesis 80 if ( ! function_exists('mb_strcut') ):
mp-wp_genesis 81 function mb_strcut( $str, $start, $length=null, $encoding=null ) {
mp-wp_genesis 82 return _mb_strcut($str, $start, $length, $encoding);
mp-wp_genesis 83 }
mp-wp_genesis 84 endif;
mp-wp_genesis 85
mp-wp_genesis 86 function _mb_strcut( $str, $start, $length=null, $encoding=null ) {
mp-wp_genesis 87 // the solution below, works only for utf-8, so in case of a different
mp-wp_genesis 88 // charset, just use built-in substr
mp-wp_genesis 89 $charset = get_option( 'blog_charset' );
mp-wp_genesis 90 if ( !in_array( $charset, array('utf8', 'utf-8', 'UTF8', 'UTF-8') ) ) {
mp-wp_genesis 91 return is_null( $length )? substr( $str, $start ) : substr( $str, $start, $length);
mp-wp_genesis 92 }
mp-wp_genesis 93 // use the regex unicode support to separate the UTF-8 characters into an array
mp-wp_genesis 94 preg_match_all( '/./us', $str, $match );
mp-wp_genesis 95 $chars = is_null( $length )? array_slice( $match[0], $start ) : array_slice( $match[0], $start, $length );
mp-wp_genesis 96 return implode( '', $chars );
mp-wp_genesis 97 }
mp-wp_genesis 98
mp-wp_genesis 99 ?>