<?php
/**************************************************
*  Created:  2010-06-08
*
*  框架兼容类
*
*  @Xweibo (C)1996-2099 SINA Inc.
*  @Author xionghui <xionghui1@staff.sina.com.cn>
*
***************************************************/
//JSON LIB
if (!function_exists('json_decode')){
	function json_decode($s, $ass = false){
		$assoc = ($ass) ? 16 : 32;
		$gloJSON = APP::N('servicesJSON', $assoc);

		return $gloJSON->decode($s);
	}
}
if (!function_exists('json_encode')){
	function json_encode($s){
		$gloJSON = APP::O('servicesJSON');

		return $gloJSON->encode($s);
	}
}
if (!function_exists('hash_hmac')) {
	function hash_hmac($algo, $data, $key, $raw = false) {
		if (empty($algo)) {
			return false;
		}
		switch ($algo) {
			case 'md5':
				return mhash(MHASH_MD5, $data, $key);
				break;
			case 'sha1':
				return mhash(MHASH_SHA1, $data, $key);
				break;
		}
	}
}
if (!function_exists('array_combine')) {
	function array_combine( $keys, $values ) {
	   if( !is_array($keys) || !is_array($values) || empty($keys) || empty($values) || count($keys) != count($values)) {
		 trigger_error( "array_combine() expects parameters 1 and 2 to be non-empty arrays with an equal number of elements", E_USER_WARNING);
		 return false;
	   }
	   $keys = array_values($keys);
	   $values = array_values($values);
	   $result = array();
	   foreach( $keys as $index => $key ) {
		 $result[$key] = $values[$index];
	   }
	   return $result;
	}
}
if (!function_exists('http_build_query')) {
	function http_build_query($array) {
		if (empty($array)) {
			return false;
		}

		if (!is_array($array)) {
			return $array;
		}

		$result = array();
		foreach ($array as $index => $var) {
			if (is_array($var)) {
				foreach ($var as $k => $v) {
					$result[] = $index.'['.$k.']='.urlencode($v); 
				}
			} else {
				$result[] = $index.'='.urlencode($var);
			}
		}

		$string = implode('&', $result);
		return $string;
	}
}
?>
