~canonical-sysadmins/wordpress/3.9.x

« back to all changes in this revision

Viewing changes to wp-includes/compat.php

  • Committer: Chris Jones
  • Date: 2010-01-19 13:17:33 UTC
  • Revision ID: cmsj@tenshu.net-20100119131733-rf31jv9k1v0xzo2h
[CJ] Import wordpress 2.9.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
56
56
        }
57
57
}
58
58
 
59
 
if ( ! function_exists('hash_hmac') ):
 
59
if ( !function_exists('hash_hmac') ):
60
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
66
        $packs = array('md5' => 'H32', 'sha1' => 'H40');
62
67
 
63
68
        if ( !isset($packs[$algo]) )
67
72
 
68
73
        if (strlen($key) > 64)
69
74
                $key = pack($pack, $algo($key));
70
 
        else if (strlen($key) < 64)
71
 
                $key = str_pad($key, 64, chr(0));
 
75
 
 
76
        $key = str_pad($key, 64, chr(0));
72
77
 
73
78
        $ipad = (substr($key, 0, 64) ^ str_repeat(chr(0x36), 64));
74
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
89
        function mb_substr( $str, $start, $length=null, $encoding=null ) {
82
90
                return _mb_substr($str, $start, $length, $encoding);
83
91
        }
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
}