ession.cookie_domain', $name['domain']); if(isset($name['expire'])) ini_set('session.gc_maxlifetime', $name['expire']); if(isset($name['use_trans_sid'])) ini_set('session.use_trans_sid', $name['use_trans_sid']?1:0); if(isset($name['use_cookies'])) ini_set('session.use_cookies', $name['use_cookies']?1:0); if(isset($name['cache_limiter'])) session_cache_limiter($name['cache_limiter']); if(isset($name['cache_expire'])) session_cache_expire($name['cache_expire']); if(isset($name['type'])) C('SESSION_TYPE',$name['type']); if(C('SESSION_TYPE')) { $class = 'Session'. ucwords(strtolower(C('SESSION_TYPE'))); if(require_cache(EXTEND_PATH.'Driver/Session/'.$class.'.class.php')) { $hander = new $class(); $hander->execute(); }else { throw_exception(L('_CLASS_NOT_EXIST_').': ' . $class); } } if(C('SESSION_AUTO_START')) session_start(); }elseif('' === $value){ if(0===strpos($name,'[')) { if('[pause]'==$name){ session_write_close(); }elseif('[start]'==$name){ session_start(); }elseif('[destroy]'==$name){ $_SESSION = array(); session_unset(); session_destroy(); }elseif('[regenerate]'==$name){ session_regenerate_id(); } }elseif(0===strpos($name,'?')){ $name = substr($name,1); if(strpos($name,'.')){ list($name1,$name2) = explode('.',$name); return $prefix?isset($_SESSION[$prefix][$name1][$name2]):isset($_SESSION[$name1][$name2]); }else{ return $prefix?isset($_SESSION[$prefix][$name]):isset($_SESSION[$name]); } }elseif(is_null($name)){ if($prefix) { unset($_SESSION[$prefix]); }else{ $_SESSION = array(); } }elseif($prefix){ if(strpos($name,'.')){ list($name1,$name2) = explode('.',$name); return isset($_SESSION[$prefix][$name1][$name2])?$_SESSION[$prefix][$name1][$name2]:null; }else{ return isset($_SESSION[$prefix][$name])?$_SESSION[$prefix][$name]:null; } }else{ if(strpos($name,'.')){ list($name1,$name2) = explode('.',$name); return isset($_SESSION[$name1][$name2])?$_SESSION[$name1][$name2]:null; }else{ return isset($_SESSION[$name])?$_SESSION[$name]:null; } } }elseif(is_null($value)){ if($prefix){ unset($_SESSION[$prefix][$name]); }else{ unset($_SESSION[$name]); } }else{ if($prefix){ if (!is_array($_SESSION[$prefix])) { $_SESSION[$prefix] = array(); } $_SESSION[$prefix][$name] = $value; }else{ $_SESSION[$name] = $value; } } } function cookie($name, $value='', $option=null) { $config = array( 'prefix' => C('COOKIE_PREFIX'), 'expire' => C('COOKIE_EXPIRE'), 'path' => C('COOKIE_PATH'), 'domain' => C('COOKIE_DOMAIN'), 'secure' => C('COOKIE_SECURE') ); if (!is_null($option)) { if (is_numeric($option)) $option = array('expire' => $option); elseif (is_string($option)) parse_str($option, $option); $config = array_merge($config, array_change_key_case($option)); } if (is_null($name)) { if (empty($_COOKIE)) return; $prefix = empty($value) ? $config['prefix'] : $value; if (!empty($prefix)) { $ack=false; foreach ($_COOKIE as $key => $val) { if (0 === stripos($key, $prefix)) { $ack=true; setcookie($key, '', time() - 3600, $config['path'], $config['domain']); unset($_COOKIE[$key]); } } if(!$ack){ setcookie($prefix, '', time() - 3600, $config['path'], $config['domain']); } } return; } $name = $config['prefix'] . $name; if ('' === $value) { if(isset($_COOKIE[$name])){ $value = $_COOKIE[$name]; if(0===strpos($value,'think:')){ $value = substr($value,6); return array_map('urldecode',json_decode(MAGIC_QUOTES_GPC?stripslashes($value):$value,true)); }else{ return $value; } }else{ return null; } } else { if (is_null($value)) { setcookie($name, '', time() - 3600, $config['path'], $config['domain']); unset($_COOKIE[$name]); } else { if(is_array($value)){ $value = 'think:'.json_encode(array_map('urlencode',$value)); } $expire = !empty($config['expire']) ? time() + intval($config['expire']) : 0; setcookie($name, $value, $expire, $config['path'], $config['domain'],$config['secure'],true); $_COOKIE[$name] = $value; } } } function load_ext_file() { if(C('LOAD_EXT_FILE')) { $files = explode(',',C('LOAD_EXT_FILE')); foreach ($files as $file){ $file = COMMON_PATH.$file.'.php'; if(is_file($file)) include $file; } } if(C('LOAD_EXT_CONFIG')) { $configs = C('LOAD_EXT_CONFIG'); if(is_string($configs)) $configs = explode(',',$configs); foreach ($configs as $key=>$config){ $file = CONF_PATH.$config.'.php'; if(is_file($file)) { is_numeric($key)?C(include $file):C($key,include $file); } } } } function get_client_ip($type = 0) { $type = $type ? 1 : 0; static $ip = NULL; if ($ip !== NULL) return $ip[$type]; if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) { $arr = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']); $pos = array_search('unknown',$arr); if(false !== $pos) unset($arr[$pos]); $ip = trim($arr[0]); }elseif (isset($_SERVER['HTTP_CLIENT_IP'])) { $ip = $_SERVER['HTTP_CLIENT_IP']; }elseif (isset($_SERVER['REMOTE_ADDR'])) { $ip = $_SERVER['REMOTE_ADDR']; } $long = sprintf("%u",ip2long($ip)); $ip = $long ? array($ip, $long) : array('0.0.0.0', 0); return $ip[$type]; } function send_http_status($code) { static $_status = array( 100 => 'Continue', 101 => 'Switching Protocols', 200 => 'OK', 201 => 'Created', 202 => 'Accepted', 203 => 'Non-Authoritative Information', 204 => 'No Content', 205 => 'Reset Content', 206 => 'Partial Content', 300 => 'Multiple Choices', 301 => 'Moved Permanently', 302 => 'Moved Temporarily ', 303 => 'See Other', 304 => 'Not Modified', 305 => 'Use Proxy', 307 => 'Temporary Redirect', 400 => 'Bad Request', 401 => 'Unauthorized', 402 => 'Payment Required', 403 => 'Forbidden', 404 => 'Not Found', 405 => 'Method Not Allowed', 406 => 'Not Acceptable', 407 => 'Proxy Authentication Required', 408 => 'Request Timeout', 409 => 'Conflict', 410 => 'Gone', 411 => 'Length Required', 412 => 'Precondition Failed', 413 => 'Request Entity Too Large', 414 => 'Request-URI Too Long', 415 => 'Unsupported Media Type', 416 => 'Requested Range Not Satisfiable', 417 => 'Expectation Failed', 500 => 'Internal Server Error', 501 => 'Not Implemented', 502 => 'Bad Gateway', 503 => 'Service Unavailable', 504 => 'Gateway Timeout', 505 => 'HTTP Version Not Supported', 509 => 'Bandwidth Limit Exceeded' ); if(isset($_status[$code])) { header('HTTP/1.1 '.$code.' '.$_status[$code]); header('Status:'.$code.' '.$_status[$code]); } } function filter_exp(&$value){ if (in_array(strtolower($value),array('exp','or'))){ $value .= ' '; } } function config($key, $value=NULL) { if(empty($key)) return ''; $key = trim($key, '.'); if($value===NULL) { return D('base://redis')->get($key); } else { return D('base://redis')->set($key, $value); } } function config_arr($key, $value=NULL) { return config($key, $value); } function config_all($key, $value=NULL) { if(empty($key)) return ''; $key = trim($key, '.'); if(SYS_VISTION == 2){ if(SITE_TYPE == 'en'){ $key = '$%#englist#%$'.$key; }else if(SITE_TYPE == 'm'){ $key = '$%#mobile#%$'.$key; } } if($value===NULL) { return D('base://redis')->get('all.' . $key); } else { return D('base://redis')->set('all.' . $key, $value); } } function config_new($key, $value=NULL) { if(empty($key)) return ''; $key = trim($key, '.'); if($value===NULL) { return D('base://redis')->get($key); } else { return D('base://redis')->set($key, $value); } } function keywords_replace($content) { $param_keyword['field'] = 'id,weight,web,rate,name'; $param_keyword['order'] = 'weight desc,id'; $param_keyword['where'] = array( 'type'=>6, 'disabled'=>'false' ); $keyword_list =D('tag')->getlist($param_keyword); $keywords = $keyword_list['rows']; $temp_content = $content; foreach ($keywords as $key => $value) { $pattern = '/'.$value['name'].'/'; $replacement = "#%@".$value['id']."#%@"; $temp_content = preg_replace ($pattern, $replacement,$temp_content,$value['rate']); } foreach ($keywords as $k => $v) { $patt = "/#%@".$v['id']."#%@/"; if(strstr($v['web'],'http://')){ $rep_ment = "".$v['name'].""; }else{ $rep_ment = "".$v['name'].""; } $temp_content = preg_replace ($patt, $rep_ment, $temp_content,$v['rate']); } return $temp_content; } function dateTime($timestamp=null){ if($timestamp) return gmdate('Y-m-d\TH:i:s.Z\Z',$timestamp); else return gmdate('Y-m-d\TH:i:s.Z\Z'); } function apiserver_url($uri='',$vars=array(),$domain=true){ $i=strrpos(_PHP_FILE_, '/'); $basepath=rtrim(substr(_PHP_FILE_,0,$i),'/').'/api.php'; $uri = trim($uri,'/'); $path = explode('/',$uri); Helper_Array::removeEmpty($path); $var = array(); $var['a'] = !empty($path)?array_pop($path):'empty'; $var['m'] = strtolower(!empty($path)?array_pop($path):'empty'); $var['app'] = !empty($path)?array_pop($path):APP_NAME; $url = $basepath.'?method='.implode('.',array_reverse($var)); if(!empty($vars)) { $vars = urldecode(http_build_query($vars)); $url .= '&'.$vars; } if($domain===true){ $domain = $_SERVER['HTTP_HOST']; } if($domain) { $url = (is_ssl()?'https://':'http://').$domain.$url; } return $url; } function array_sort($arr, $keys, $type='asc') { $keysvalue = $new_array = array(); foreach ($arr as $k => $v) { $keysvalue[$k] = $v[$keys]; } if($type == 'asc') { asort($keysvalue); } else { arsort($keysvalue); } reset($keysvalue); foreach ($keysvalue as $k => $v) { $new_array[$k] = $arr[$k]; } return $new_array; } function amount_currency($amout,$with_currency=true){ $amout=floatval($amout); $decimal_place=config('decimal_place'); if(empty($decimal_place)){ $decimal_place = '2'; } $default_currency=config('default_currency'); if(empty($default_currency)){ $default_currency = 'CNY'; } $site_money_carryset=config('site_setbuy.site_money_carryset'); if(empty($site_money_carryset)){ $site_money_carryset = 1; } $decimal_place_mum=pow(10,$decimal_place); if($site_money_carryset==3){ $amout=floor($amout*$decimal_place_mum)/$decimal_place_mum; } elseif($site_money_carryset==2){ $amout=ceil($amout*$decimal_place_mum)/$decimal_place_mum; } else{ $amout=round($amout*$decimal_place_mum)/$decimal_place_mum; } if($with_currency) { $amout=number_format($amout,$decimal_place,'.',''); if($default_currency=='USD'){ $amout='$'.$amout; }else{ $amout='¥'.$amout; } } return $amout; } function get_pic($ids='', $size='', $app='site') { static $pics = array(); $retrun_pic = $find_pic = array(); if(!is_array($ids)) { $ids = explode(',', $ids); } foreach($ids as $id) { if(empty($id)) { continue; } if(isset($pics[$id])) { $retrun_pic[$id] = $pics[$id]; } else { $find_pic[$id] = $id; } } if(!empty($find_pic)) { $album = D('base://filemanage')->getlist(array('app'=>$app,'getfield'=>true,'where'=>array('id'=>array('in', $find_pic)))); if(!empty($album)) { foreach($album as $id=>$pic) { $pics[$id] = $pic; $retrun_pic[$id] = $pic; } } } if($size) { foreach($retrun_pic as $k=>$v) { $retrun_pic[$k] = str_replace('.', '_'.$size.'.', $v); } } return $retrun_pic; } function make_image($params, $pic, $type, &$image) { $image->setSrcImg(PUBLIC_ROOT.'/'.$pic); $image->setDstImg(PUBLIC_ROOT.'/'.str_replace('.', '_'.$type.'.', $pic)); static $mark_img = array(); if(!isset($mark_img[$type])) { $mark_img[$type] = is_file(PUBLIC_ROOT.'/'.$params['mark']['img'])?true:false; } $image->setMaskWord(''); $image->setMaskImg(null); $image->setMaskImgPct(null); if($params['mark']['type']=='img' && $mark_img[$type]) { $image->setMaskPosition($params['mark']['position']); $params['mark']['trans'] = $params['mark']['trans']?$params['mark']['trans']:40; $image->setMaskImgPct($params['mark']['trans']); $image->setMaskImg(PUBLIC_ROOT.'/'.$params['mark']['img']); } elseif ($params['mark']['type']=='text' && $params['mark']['text']) { $image->setMaskPosition($params['mark']['position']); $params['mark']['size'] = $params['mark']['size']?$params['mark']['size']:12; $image->setMaskFontSize($params['mark']['size']); if($params['mark']['font']) { $font = strpos($params['mark']['font'], 'http://')===false?(PUBLIC_ROOT.'/'.$params['mark']['font']):$params['mark']['font']; } else { $font = PUBLIC_ROOT.'/static/font/SIMHEI.TTF'; } $image->setMaskFont($font); $params['mark']['trans'] = $params['mark']['trans']?$params['mark']['trans']:40; $image->setMaskTxtPct($params['mark']['trans']); $image->setMaskWord($params['mark']['text']); } $res = $image->createImg($params['width'], $params['height']); if(!$res){ echo ""; echo $image->msg;return false; } } function password($key='') { $md5 = md5($key); $num = substr(ord($md5[3]), -1); return str_replace(substr($md5, $num, 1), 'e'