{ $var[$varController] = parse_name($var[$varController]); } $module = ''; if(!empty($path)) { $var[$varModule] = implode($depr,$path); }else{ if(C('MULTI_MODULE')) { if(MODULE_NAME != C('DEFAULT_MODULE') || !C('MODULE_ALLOW_LIST')){ $var[$varModule]= MODULE_NAME; } } } if($maps = C('URL_MODULE_MAP')) { if($_module = array_search(strtolower($var[$varModule]),$maps)){ $var[$varModule] = $_module; } } if(isset($var[$varModule])){ $module = $var[$varModule]; unset($var[$varModule]); } } } if(C('URL_MODEL') == 0) { $url = __APP__.'?'.C('VAR_MODULE')."={$module}&".http_build_query(array_reverse($var)); if($urlCase){ $url = strtolower($url); } if(!empty($vars)) { $vars = http_build_query($vars); $url .= '&'.$vars; } }else{ if(isset($route)) { $url = __APP__.'/'.rtrim($url,$depr); }else{ $module = (defined('BIND_MODULE') && BIND_MODULE==$module )? '' : $module; $url = __APP__.'/'.($module?$module.MODULE_PATHINFO_DEPR:'').implode($depr,array_reverse($var)); } if($urlCase){ $url = strtolower($url); } if(!empty($vars)) { foreach ($vars as $var => $val){ if('' !== trim($val)) $url .= $depr . $var . $depr . urlencode($val); } } if($suffix) { $suffix = $suffix===true?C('URL_HTML_SUFFIX'):$suffix; if($pos = strpos($suffix, '|')){ $suffix = substr($suffix, 0, $pos); } if($suffix && '/' != substr($url,-1)){ $url .= '.'.ltrim($suffix,'.'); } } } if(isset($anchor)){ $url .= '#'.$anchor; } if($domain) { $url = (is_ssl()?'https://':'http://').$domain.$url; } return $url; } function W($name, $data=array()) { return R($name,$data,'Widget'); } function is_ssl() { if(isset($_SERVER['HTTPS']) && ('1' == $_SERVER['HTTPS'] || 'on' == strtolower($_SERVER['HTTPS']))){ return true; }elseif(isset($_SERVER['SERVER_PORT']) && ('443' == $_SERVER['SERVER_PORT'] )) { return true; } return false; } function redirect($url, $time=0, $msg='') { $url = str_replace(array("\n", "\r"), '', $url); if (empty($msg)) $msg = "系统将在{$time}秒之后自动跳转到{$url}!"; if (!headers_sent()) { if (0 === $time) { header('Location: ' . $url); } else { header("refresh:{$time};url={$url}"); echo($msg); } exit(); } else { $str = ""; if ($time != 0) $str .= $msg; exit($str); } } function S($name,$value='',$options=null) { static $cache = ''; if(is_array($options)){ $type = isset($options['type'])?$options['type']:''; $cache = Think\Cache::getInstance($type,$options); }elseif(is_array($name)) { $type = isset($name['type'])?$name['type']:''; $cache = Think\Cache::getInstance($type,$name); return $cache; }elseif(empty($cache)) { $cache = Think\Cache::getInstance(); } if(''=== $value){ return $cache->get($name); }elseif(is_null($value)) { return $cache->rm($name); }else { if(is_array($options)) { $expire = isset($options['expire'])?$options['expire']:NULL; }else{ $expire = is_numeric($options)?$options:NULL; } return $cache->set($name, $value, $expire); } } function F($name, $value='', $path=DATA_PATH) { static $_cache = array(); $filename = $path . $name . '.php'; if ('' !== $value) { if (is_null($value)) { if(false !== strpos($name,'*')){ return false; }else{ unset($_cache[$name]); return Think\Storage::unlink($filename,'F'); } } else { Think\Storage::put($filename,serialize($value),'F'); $_cache[$name] = $value; return null; } } if (isset($_cache[$name])) return $_cache[$name]; if (Think\Storage::has($filename,'F')){ $value = unserialize(Think\Storage::read($filename,'F')); $_cache[$name] = $value; } else { $value = false; } return $value; } function to_guid_string($mix) { if (is_object($mix)) { return spl_object_hash($mix); } elseif (is_resource($mix)) { $mix = get_resource_type($mix) . strval($mix); } else { $mix = serialize($mix); } return md5($mix); } function xml_encode($data, $root='think', $item='item', $attr='', $id='id', $encoding='utf-8') { if(is_array($attr)){ $_attr = array(); foreach ($attr as $key => $value) { $_attr[] = "{$key}=\"{$value}\""; } $attr = implode(' ', $_attr); } $attr = trim($attr); $attr = empty($attr) ? '' : " {$attr}"; $xml = ""; $xml .= "<{$root}{$attr}>"; $xml .= data_to_xml($data, $item, $id); $xml .= ""; return $xml; } function data_to_xml($data, $item='item', $id='id') { $xml = $attr = ''; foreach ($data as $key => $val) { if(is_numeric($key)){ $id && $attr = " {$id}=\"{$key}\""; $key = $item; } $xml .= "<{$key}{$attr}>"; $xml .= (is_array($val) || is_object($val)) ? data_to_xml($val, $item, $id) : $val; $xml .= ""; } return $xml; } function session($name='',$value='') { $prefix = C('SESSION_PREFIX'); if(is_array($name)) { if(isset($name['prefix'])) C('SESSION_PREFIX',$name['prefix']); if(C('VAR_SESSION_ID') && isset($_REQUEST[C('VAR_SESSION_ID')])){ session_id($_REQUEST[C('VAR_SESSION_ID')]); }elseif(isset($name['id'])) { session_id($name['id']); } if('common' == APP_MODE){ ini_set('session.auto_start', 0); } if(isset($name['name'])) session_name($name['name']); if(isset($name['path'])) session_save_path($name['path']); if(isset($name['domain'])) ini_set('session.cookie_domain', $name['domain']); if(isset($name['expire'])) { ini_set('session.gc_maxlifetime', $name['expire']); ini_set('session.cookie_lifetime', $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')) { $type = C('SESSION_TYPE'); $class = strpos($type,'\\')? $type : 'Think\\Session\\Driver\\'. ucwords(strtolower($type)); $hander = new $class(); session_set_save_handler( array(&$hander,"open"), array(&$hander,"close"), array(&$hander,"read"), array(&$hander,"write"), array(&$hander,"destroy"), array(&$hander,"gc")); } if(C('SESSION_AUTO_START')) session_start(); }elseif('' === $value){ if(''===$name){ return $prefix ? $_SESSION[$prefix] : $_SESSION; }elseif(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(strpos($name,'.')){ list($name1,$name2) = explode('.',$name); if($prefix){ unset($_SESSION[$prefix][$name1][$name2]); }else{ unset($_SESSION[$name1][$name2]); } }else{ if($prefix){ unset($_SESSION[$prefix][$name]); }else{ unset($_SESSION[$name]); } } }else{ if(strpos($name,'.')){ list($name1,$name2) = explode('.',$name); if($prefix){ $_SESSION[$prefix][$name1][$name2] = $value; }else{ $_SESSION[$name1][$name2] = $value; } }else{ if($prefix){ $_SESSION[$prefix][$name] = $value; }else{ $_SESSION[$name] = $value; } } } return null; } 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'), 'httponly' => C('COOKIE_HTTPONLY'), ); if (!is_null($option)) { if (is_numeric($option)) $option = array('expire' => $option); elseif (is_string($option)) pa','desc'))){ return ''; } $keysvalue=array(); foreach($array as $key=>$val){ $val[$keys] = str_replace('-','',$val[$keys]); $val[$keys] = str_replace(' ','',$val[$keys]); $val[$keys] = str_replace(':','',$val[$keys]); $keysvalue[] =$val[$keys]; } asort($keysvalue); reset($keysvalue); foreach($keysvalue as $key=>$vals) { $keysort[] = $key; } $keysvalue = array(); $count=count($keysort); if(strtolower($type) != 'asc'){ for($i=$count-1; $i>=0; $i--) { $keysvalue[] = $array[$keysort[$i]]; } }else{ for($i=0; $i<$count; $i++){ $keysvalue[] = $array[$keysort[$i]]; } } return $keysvalue; } function isMobile() { if (isset ($_SERVER['HTTP_X_WAP_PROFILE'])) { return true; } if (isset ($_SERVER['HTTP_VIA'])) { return stristr($_SERVER['HTTP_VIA'], "wap") ? true : false; } if (isset ($_SERVER['HTTP_USER_AGENT'])) { $clientkeywords = array ('nokia', 'sony', 'ericsson', 'mot', 'samsung', 'htc', 'sgh', 'lg', 'sharp', 'sie-', 'philips', 'panasonic', 'alcatel', 'lenovo', 'iphone', 'ipod', 'blackberry', 'meizu', 'android', 'netfront', 'symbian', 'ucweb', 'windowsce', 'palm', 'operamini', 'operamobi', 'openwave', 'nexusone', 'cldc', 'midp', 'wap', 'mobile' ); if (preg_match("/(" . implode('|', $clientkeywords) . ")/i", strtolower($_SERVER['HTTP_USER_AGENT']))) { return true; } } if (isset ($_SERVER['HTTP_ACCEPT'])) { if ((strpos($_SERVER['HTTP_ACCEPT'], 'vnd.wap.wml') !== false) && (strpos($_SERVER['HTTP_ACCEPT'], 'text/html') === false || (strpos($_SERVER['HTTP_ACCEPT'], 'vnd.wap.wml') < strpos($_SERVER['HTTP_ACCEPT'], 'text/html')))) { return true; } } return false; } function UpImage($callBack = "image", $width = 100, $height = 100, $image = "") { echo ' '; } function BatchImage($callBack = "image", $width = 100, $height = 100, $image = "") { echo ' '; } function format_html($str){ $str = str_replace('“', '“',$str); $str = str_replace('”', '”',$str); $str = str_replace('·', '·',$str); $str = str_replace('‘', '‘',$str); $str = str_replace('’', '’',$str); $str = str_replace('…', '…', $str); $str = str_replace('—', '—', $str); return $str; } function str_replace_limit($search, $replace, $subject, $limit=-1){ if(is_array($search)){ foreach($search as $k=>$v){ $search[$k] = '`'. preg_quote($search[$k], '`'). '`'; } }else{ $search = '`'. preg_quote($search, '`'). '`'; } return preg_replace($search, $replace, $subject, $limit); } function Getlist($cate = 1, $catenum = 1, $num = 10, $css = 1,$rq = 1){ $News = M("news"); if($cate==1) { $dalei = M("categorya")->where("id='$catenum'")->find(); $daleirule = $dalei['rules']; $newslist=$News->field('id,title,post_date')->where("type in ('$daleirule')")->order('id desc')->limit($num)->select(); } if($cate==2) { $newslist=$News->field('id,title,post_date')->where("type='$catenum'")->order('id desc')->limit($num)->select(); } if($cate==3) { $News = M("keywords"); $newslist=$News->field('tid as id,title,post_date')->where("name='$catenum'")->order('tid desc')->limit($num)->select(); } if($css==1) { foreach($newslist as $value) { if($rq==1) {echo '
  • '.$value['title'].''.date("d",strtotime($value['post_date'])).'日
  • ';} if($rq==2) {echo '
  • '.$value['title'].'
  • ';} } } if($css==2) { foreach($newslist as $value) { if($rq==1) {echo ''.$value['title'].''.date("d",strtotime($value['post_date'])).'日
    ';} if($rq==2) {echo ''.$value['title'].'
    ';} } } if($css==3) { foreach($newslist as $value) { if($rq==1) {echo ''.$value['title'].''.date("d",strtotime($value['post_date'])).'日';} if($rq==2) {echo ''.$value['title'].'';} } } } function b2b_search($q,$p,$page_record) { if(!$page_record) $page_record = 50; $start = ($p-1)*$page_record; $rows = $page_record; $url = "http://10.103.33.116:8983/solr/new_core/select?indent=on&q=$q&wt=json&sort=post_date+desc&start=$start&rows=$rows&defType=edismax&mm=100%25"; $json = file_get_contents($url); $query = json_decode($json); $res = array();$final = array(); foreach ( $query->response->docs as $val ) { $val = json_decode(json_encode($val),TRUE); array_push($res,$val); } array_push($final,$res);array_push($final,$query->response->numFound);array_push($final,$start); return $final; } function b2b_data_delete_id($id) { $query ="id:".$id.""; $url = "http://10.103.33.116:8983/solr/new_core/update/?stream.body=".$query."&stream.contentType=text/xml;charset=utf-8&commit=true"; $json =file_get_contents($url); return $json; } function b2b_data_delete() { $query ="*:*"; $url = "http://10.103.33.116:8983/solr/new_core/update/?stream.body=".$query."&stream.contentType=text/xml;charset=utf-8&commit=true"; $json =file_get_contents($url); return $json; } function b2b_insert($maxid,$limit) { $news = b2b_get_news($maxid,$limit); $post = ' '; foreach( $news as $val) { $val['title'] = unhtml($val['title']); $val['keywords'] = unhtml($val['keywords']); $post .=' '; $maxid = $val['id']; } $post .= ''; b2b_data_post($post); return $maxid; } function b2b_insert_id($maxid) { $news = b2b_get_news_id($maxid); $post = ' '; foreach( $news as $val) { $val['title'] = unhtml($val['title']); $val['keywords'] = unhtml($val['keywords']); $post .=' '; $maxid = $val['id']; } $post .= ''; b2b_data_post($post); return $maxid; } function b2b_get_news($id,$limit) { $news =array(); if(!$id) { exit; } $new = M("news")->field('id,title,keywords,post_date,pubDate')->where("id > $id and status = 1")->order('id asc')->limit($limit)->select(); foreach($new as $k=>$value){ array_push($news,$value); } return $news; } function b2b_get_news_id($id) { $news =array(); if(!$id) { exit; } $new = M("news")->field('id,title,keywords,post_date,pubDate')->where("id = $id and status = 1")->order('id asc')->limit(1)->select(); foreach($new as $k=>$value){ array_push($news,$value); } return $news; } function b2b_data_post($post) { $header = array("Content-type:text/xml","charset:utf-8"); $url = "http://10.103.33.116:8983/solr/new_core/update?wt=json"; $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_HEADER, 0); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 0); curl_setopt($curl, CURLOPT_HTTPHEADER, $header); curl_setopt($curl, CURLOPT_POST, 1); curl_setopt($curl, CURLOPT_POSTFIELDS, $post); curl_exec($curl); curl_close($curl); } function get_maxid() { $new = M("maxid")->where("type='news'")->find(); return $new['maxid']; } function get_sum($condition = null) { $new = M("news")->where("status = 1 $condition")->count(); return $new; } function update_maxid($maxid) { date_default_timezone_set('Asia/Shanghai'); $time = date("Y-m-d H:i:s",time()); $data['maxid'] = $maxid; $data['ctime'] = $time; M('maxid')->data($data)->where("type = 'news'")->save(); } function unhtml($content) { $content = preg_replace('/\<\!\[CDATA\[|\/\/\]\]\>|||||||| |\r\n/','',$content); $content = strip_tags($content); $content = htmlspecialchars($content); return trim($content); } function solr_insert($f) { $limit = 10000; if($f == 'update') { $maxid = get_maxid(); $condition = " and id > $maxid "; $sum = get_sum($condition); if(!$sum) {return false;exit;} for($i=0;$i< ceil($sum/$limit);$i++) { $maxid = get_maxid(); $sid = b2b_insert($maxid,$limit); update_maxid($sid); } return true; } else if($f == 'all') { b2b_data_delete(); update_maxid(100); $condition = " and 1 "; $sum = get_sum($condition); for($i=0;$i< ceil($sum/$limit);$i++) { $maxid = get_maxid(); $sid = b2b_insert($maxid,$limit); update_maxid($sid); } return true; } } function yang_gbk2utf8($str) { $charset = mb_detect_encoding($str,array('ASCII','GB2312','UTF-8','GBK')); $w = isset($_REQUEST['w']) ? strip_tags($_REQUEST['w']) : null; if($w=='zh') { $charset = "UTF-8"; } $charset = strtolower($charset); if('cp936' == $charset || 'EUC-CN' == $charset){ $charset='GBK'; } if("utf-8" != $charset){ $str = iconv($charset,"UTF-8//IGNORE",$str); } return $str; } function get_pageinfo($p,$sumPage,$terms) { $pageinfo = "
    "; } function solr_search($f,$p,$terms) { if($f == 'search') { $page_record = 50; $term = $terms; $term = preg_replace("/\s+/",' ',$term); if(preg_match("/\s/", $term)) { $arr = explode(" ",$term); $q = ""; foreach ($arr as $k => $val) { if($k >0 ) { $q .= " and title:".$val; } else $q .= "title:".$val; } $q = urlencode($q); } else { $q = "title:".urlencode($term); } $search = b2b_search($q,$p,$page_record); $hot = b2b_search("*:*",1,10); foreach($search[0] as $k=>$v) { $search[0][$k]['title'] = str_replace($terms,"$terms",$v['title']);; } foreach($hot[0] as $k=>$v) { $hot[0][$k]['title'] = mb_substr($v['title'],0,18,'utf-8'); $hot[0][$k]['pubDate'] = substr($v['pubDate'],5,9); } $res['list'] = $search[0]; $res['total'] = $search[1]; $res['hot'] = $hot[0]; $res['to_page'] = ceil($search[1]/$page_record); $res['terms'] = $terms; $res['pageinfo'] = get_pageinfo($p,$res['to_page'],$terms); return $res; } else if ($f == 'keyword'){ $page_record = 50; $q = "keyword:".urlencode($terms); $search = b2b_search($q,$p,$page_record); $hot = b2b_search("*:*",1,10); foreach($search[0] as $k=>$v) { $search[0][$k]['title'] = str_replace($terms,"$terms",$v['title']);; } foreach($hot[0] as $k=>$v) { $hot[0][$k]['title'] = mb_substr($v['title'],0,18,'utf-8'); $hot[0][$k]['pubDate'] = substr($v['pubDate'],5,9); } $res['list'] = $search[0]; $res['total'] = $search[1]; $res['hot'] = $hot[0]; $res['to_page'] = ceil($search[1]/$page_record); $res['terms'] = $terms; $res['pageinfo'] = get_pageinfo($p,$res['to_page'],$terms); return $res; } } function solr_search_home($p,$terms,$page_record) { $term = $terms; $term = preg_replace("/\s+/",' ',$term); if(preg_match("/\s/", $term)) { $arr = explode(" ",$term); $q = ""; foreach ($arr as $k => $val) { if($k >0 ) { $q .= " and title:".$val; } else $q .= "title:".$val; } $q = urlencode($q); } else { $q = "title:".urlencode($term); } $search = b2b_search($q,$p,$page_record); $hot = b2b_search("*:*",1,10); foreach($search[0] as $k=>$v) { $search[0][$k]['title'] = str_replace($terms,"$terms",$v['title']); } foreach($hot[0] as $k=>$v) { $hot[0][$k]['title'] = mb_substr($v['title'],0,18,'utf-8'); $hot[0][$k]['pubDate'] = substr($v['pubDate'],5,9); } $res['list'] = $search[0]; $res['total'] = $search[1]; $res['hot'] = $hot[0]; $res['to_page'] = ceil($search[1]/$page_record); $res['terms'] = $terms; $res['pageinfo'] = get_pageinfo($p,$res['to_page'],$terms); return $res; } function solr_search_homejson($p,$terms,$page_record) { $term = $terms; $term = preg_replace("/\s+/",' ',$term); if(preg_match("/\s/", $term)) { $arr = explode(" ",$term); $q = ""; foreach ($arr as $k => $val) { if($k >0 ) { $q .= " and title:".$val; } else $q .= "title:".$val; } $q = urlencode($q); } else { $q = "title:".urlencode($term); } $search = b2b_search($q,$p,$page_record); $hot = b2b_search("*:*",1,10); foreach($search[0] as $k=>$v) { $search[0][$k]['title'] = $v['title']; } foreach($hot[0] as $k=>$v) { $hot[0][$k]['title'] = mb_substr($v['title'],0,18,'utf-8'); $hot[0][$k]['pubDate'] = substr($v['pubDate'],5,9); } $res['list'] = $search[0]; $res['total'] = $search[1]; $res['hot'] = $hot[0]; $res['to_page'] = ceil($search[1]/$page_record); $res['terms'] = $terms; $res['pageinfo'] = get_pageinfo($p,$res['to_page'],$terms); return $res; } function get_ip(){ if(isset($_SERVER)){ if(isset($_SERVER[HTTP_X_FORWARDED_FOR])){ $realip = $_SERVER[HTTP_X_FORWARDED_FOR]; }elseif(isset($_SERVER[HTTP_CLIENT_IP])) { $realip = $_SERVER[HTTP_CLIENT_IP]; }else{ $realip = $_SERVER[REMOTE_ADDR]; } }else{ if(getenv("HTTP_X_FORWARDED_FOR")){ $realip = getenv( "HTTP_X_FORWARDED_FOR"); }elseif(getenv("HTTP_CLIENT_IP")) { $realip = getenv("HTTP_CLIENT_IP"); }else{ $realip = getenv("REMOTE_ADDR"); } } return $realip; } function search_log($log) { $l_log = strip_tags(trim($log)); if(strlen($l_log)>2) { if(strlen($l_log)<20) { $Model = M('search_log'); $data['ip'] = get_ip(); $data['log'] = $l_log; $Model->data($data)->add(); $get_headers = header_info(); $agent = $get_headers['USER-AGENT']; if (isCrawler($agent)){ $robot = 1; } else { $robot = 0; } if(strpos($agent,'Scrapy') !== false){ $robot=1; } if($robot==0) { M('search_log_top')->data($data)->add(); $count = M('search_log_top')->count(); if($count>1000000) { $first = M('search_log_top')->order('id desc')->find(); $ls_id = $first['id']-1000000; $map['id'] = array('lt',$ls_id); M('search_log_top')->where($map)->delete(); } } } } } function getpz($key) { $peizi=M('peizi')->where("name='$key'")->find(); $group=explode('|',$peizi['value']); return $group; } function authcode($string, $operation = 'DECODE', $key = '', $expiry = 0) { $ckey_length = 4; $key = md5($key ? $key : '100ec9999'); $keya = md5(substr($key, 0, 16)); $keyb = md5(substr($key, 16, 16)); $keyc = $ckey_length ? ($operation == 'DECODE' ? substr($string, 0, $ckey_length): substr(md5(microtime()), -$ckey_length)) : ''; $cryptkey = $keya.md5($keya.$keyc); $key_length = strlen($cryptkey); $string = $operation == 'DECODE' ? base64_decode(substr($string, $ckey_length)) : sprintf('%010d', $expiry ? $expiry + time() : 0).substr(md5($string.$keyb), 0, 16).$string; $string_length = strlen($string); $result = ''; $box = range(0, 255); $rndkey = array(); for($i = 0; $i <= 255; $i++) { $rndkey[$i] = ord($cryptkey[$i % $key_length]); } for($j = $i = 0; $i < 256; $i++) { $j = ($j + $box[$i] + $rndkey[$i]) % 256; $tmp = $box[$i]; $box[$i] = $box[$j]; $box[$j] = $tmp; } for($a = $j = $i = 0; $i < $string_length; $i++) { $a = ($a + 1) % 256; $j = ($j + $box[$a]) % 256; $tmp = $box[$a]; $box[$a] = $box[$j]; $box[$j] = $tmp; $result .= chr(ord($string[$i]) ^ ($box[($box[$a] + $box[$j]) % 256])); } if($operation == 'DECODE') { if((substr($result, 0, 10) == 0 || substr($result, 0, 10) - time() > 0) && substr($result, 10, 16) == substr(md5(substr($result, 26).$keyb), 0, 16)) { return substr($result, 26); } else { return ''; } } else { return $keyc.str_replace('=', '', base64_encode($result)); } } function exportExcel($expTitle,$expCellName,$expTableData){ $xlsTitle = iconv('utf-8', 'gb2312', $expTitle); $fileName = $expTitle.date('_YmdHis'); $cellNum = count($expCellName); $dataNum = count($expTableData); vendor("PHPExcel.PHPExcel"); $objPHPExcel = new \PHPExcel(); $cellName = array('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','AA','AB','AC','AD','AE','AF','AG','AH','AI','AJ','AK','AL','AM','AN','AO','AP','AQ','AR','AS','AT','AU','AV','AW','AX','AY','AZ'); $objPHPExcel->getActiveSheet(0)->mergeCells('A1:'.$cellName[$cellNum-1].'1'); $objPHPExcel->setActiveSheetIndex(0)->setCellValue('A1', $expTitle.' 导出时间:'.date('Y-m-d H:i:s')); for($i=0;$i<$cellNum;$i++){ $objPHPExcel->setActiveSheetIndex(0)->setCellValue($cellName[$i].'2', $expCellName[$i][1]); } for($i=0;$i<$dataNum;$i++){ for($j=0;$j<$cellNum;$j++){ $objPHPExcel->getActiveSheet(0)->setCellValue($cellName[$j].($i+3), $expTableData[$i][$expCellName[$j][0]]); } } header('pragma:public'); header('Content-type:application/vnd.ms-excel;charset=utf-8;name="'.$xlsTitle.'.xls"'); header("Content-Disposition:attachment;filename=$fileName.xls"); $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5'); $objWriter->save('php://output'); exit; } function header_info(){ $headers = array(); foreach ($_SERVER as $key => $value) { if ('HTTP_' == substr($key, 0, 5)) { $headers[str_replace('_', '-', substr($key, 5))] = $value; } } return $headers; } function send_msg_dx($phone,$content,$channel=14,$type=1){ $type=2; if($type==2) { if($channel==13) { if (strpos($content,'|') !== false) { $TemplateId = '70234476'; } else { $TemplateId = '70234385'; } $param = array( 'siteid' => '100ec', 'userid' => '', 'secret' => 'sH23dFsad34P23', 'mobile' => $phone, 'content' => $content, 'TemplateId'=>$TemplateId, 'sms_sign'=>'【网经社】' ); } if($channel==15) { $TemplateId = '70234771'; $param = array( 'siteid' => '100ec', 'userid' => '', 'secret' => 'sH23dFsad34P23', 'mobile' => $phone, 'content' => $content, 'TemplateId'=>$TemplateId, 'sms_sign'=>'【网经社】' ); } if($channel==14) { $param = array( 'siteid' => '100ec', 'userid' => '', 'secret' => 'sH23dFsad34P23', 'mobile' => $phone, 'content' => $content, 'sms_sign'=>'【网经社】' ); } $url = 'http://api.sms.w2.hi2000.com/lianlu_send.php'; } else { $param = array( 'siteid' => '100ec', 'userid' => '', 'secret' => 'sH23dFsad34P23', 'mobile' => $phone, 'content' => $content, 'type' => '0', 'channel'=>$channel ); $url = 'http://api.sms.w2.hi2000.com/send.php'; } $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $param); $response = curl_exec($ch); curl_close($ch); $rarr = explode('|',$response); $jieguo = $rarr[1]; $res['back'] = $response; $res['result'] = $jieguo; return $res; } function get_access_token($qid){ $peizhi=M('xcx_peizhi')->where("id='$qid'")->find(); $APPID = $peizhi['appid']; $AppSecret = $peizhi['appsecret']; $access_token = $peizhi['access_token']; $expires_in = $peizhi['expires_in']; $dtime = $peizhi['dtime']; $nowtime = time(); $oldtime = $dtime+$expires_in; if($nowtime>$oldtime) { $url="https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=".$APPID."&secret=".$AppSecret; $arr = curlget($url); $access_token = $arr['access_token']; $expires_in = $arr['expires_in']; $js['access_token'] = $access_token; $js['expires_in'] = $expires_in; $js['dtime'] = $nowtime; $aid = M('xcx_peizhi')->data($js)->where("id='$qid'")->save(); } return $access_token; } function app_browselog($poster,$qid,$url,$log,$cansu) { if($qid>0) { $Model = M('xcx_app_browselog'); $data['appid'] = $qid; $data['poster'] = $poster; $data['url'] = $url; $data['ip'] = get_ip(); $data['log'] = $log; $data['cansu'] = $cansu; $data['post_time'] = date("Y-m-d H:i:s"); $data['year'] = date("Y"); $data['month'] = date("m"); $data['day'] = date("d"); $Model->data($data)->add(); } } function add_app($name){ $data['name'] = $name; $data['sui'] = randCode(6); $data['dtime'] = time(); $kws = M("xcx_app_member"); $aid = $kws->data($data)->add(); if($aid) { $updata['appsecret'] = authcode($aid.'|'.$data['sui'],'CODE'); $lsid = $kws->data($updata)->where('id='.$aid)->save(); $res['code'] = 1; $res['msg'] = '恭喜!APP配置新增成功!'; } else { $res['code'] = 2; $res['msg'] = '新增APP失败!'; } return $res; } function app_check() { $headers = header_info(); $appid = $headers['APPID']; $appsecret = $headers['APPSECRET']; $qid = $headers['QID']; $userid = $headers['USERID']; $jiemi = authcode($appsecret,'DECODE'); $arr = explode("|",$jiemi); $sui = $arr[1]; $app_member=M('xcx_app_member')->where("id='$appid' and sui='$sui'")->find(); if($app_member) { $res['code'] = 1; $res['appid'] = $appid; $res['appsecret'] = $appsecret; $res['qid'] = $qid; $res['userid'] = $userid; } else { $res['code'] = 2; $res['appid'] = ''; $res['appsecret'] = ''; $res['qid'] = 0; $res['userid'] = ''; } return $res; } function shortUrl2($link){ $result = sprintf("%u",crc32($link)); $show = ''; while($result >0){ $s = $result % 62; if($s > 35){ $s=chr($s+61); }elseif($s>9 && $s<=35){ $s=chr($s+55); } $show .= $s; $result = floor($result / 62); } $map['dwz'] = $show; $data['url'] = $link; $data['dwz'] = $show; $dwz = M('xcx_url')->where($map)->find(); if($dwz) { if($dwz['url']==$link) { $res['code'] = 1; $res['url'] = $show; } else { $res['code'] = 2; $res['url'] = 0; } return $res; } else { M('xcx_url')->data($data)->add(); $res['code'] = 1; $res['url'] = $show; return $res; } } function curlpost($url,$post){ $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE ); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE ); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $post); $response = curl_exec($ch); curl_close( $ch ); $rest = json_decode($response,true); return $rest; } function curlget($url){ $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, FALSE ); curl_setopt( $ch, CURLOPT_SSL_VERIFYHOST, FALSE ); $response = curl_exec($ch); curl_close( $ch ); $rest = json_decode($response,true); return $rest; } function curlget_headers($url,$headers){ $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, FALSE ); curl_setopt( $ch, CURLOPT_SSL_VERIFYHOST, FALSE ); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); $response = curl_exec($ch); curl_close( $ch ); $rest = json_decode($response,true); return $rest; } function curlpost_headers($url,$post,$headers){ $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE ); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE ); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $post); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); $response = curl_exec($ch); curl_close( $ch ); $rest = json_decode($response,true); return $rest; } function ff($var){ return mb_strlen($var,'utf-8')>1; } function scwsnum($title,$num){ Vendor('scws.pscws4'); $pscws = new \PSCWS4('utf8'); $pscws->set_dict(VENDOR_PATH.'scws/lib/dict.utf8.xdb'); $pscws->set_rule(VENDOR_PATH.'scws/lib/rules.utf8.ini'); $pscws->set_multi(15); $pscws->set_ignore(true); $pscws->set_duality(true); $pscws->send_text($title); $words = $pscws->get_tops($num); $tags = array(); foreach ($words as $val) { $tags[] = $val['word']; } $pscws->close(); return $tags; } function get_wx_code_com($path,$file_path,$new_file,$width,$access_token){ $post_dataewm = '{ "path":"'.$path.'","width":"'.$width.'","auto_color":false,"line_color":{"r":44,"g":154,"b":201},"is_hyaline":true }'; $url="https://api.weixin.qq.com/wxa/getwxacode?access_token=".$access_token; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE ); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE ); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $post_dataewm); $response = curl_exec($ch); curl_close( $ch ); $rest = json_decode($response,true); if($rest['errcode']==41030 or $rest['errcode']==45009) { $res['code'] = 2; $res['list'] = $rest; $res['ewm'] = $new_file; } else { $imgs = $response; if(!is_dir($file_path)){ mkdir($file_path); } if(!empty($imgs)){ $file = fopen($new_file,"w"); fwrite($file,$imgs); fclose($file); } $res['code'] = 1; $res['list'] = $new_file; } return $res; } function add_score($poster,$info_cate){ $score_option=M('xcx_score_option')->where("id='$info_cate'")->find(); if($score_option) { $data['poster'] = $poster; if($score_option['score']>0) { $data['cate'] = 1; } else { $data['cate'] = 2; } $data['num'] = $score_option['score']; $data['info_cate'] = $info_cate; $data['info'] = $score_option['name']; $data['date'] = date("Y-m-d"); if($data['cate']==2) { $total_map['poster'] = $poster; $total_score = M('xcx_user_score')->where($total_map)->sum('num'); $jf = $total_score+$score_option['score']; if($jf<0) { $res['code'] = 2; $res['msg'] = '积分不够'; return $res; } } if($score_option['cate']==2) { $map['poster'] = $poster; $map['info_cate'] = $info_cate; $find_score = M('xcx_user_score')->where($map)->find(); if($find_score) { $res['code'] = 2; $res['msg'] = '一次性积分,已经有记录'; } else { $rs=M('xcx_user_score')->add($data); if($rs) { $res['code'] = 1; $res['msg'] = '积分操作成功'; } else { $res['code'] = 2; $res['msg'] = '积分操作失败'; } } } else { if($score_option['toplimit']==0) { $rs=M('xcx_user_score')->add($data); if($rs) { $res['code'] = 1; $res['msg'] = '积分操作成功'; } else { $res['code'] = 2; $res['msg'] = '积分操作失败'; } } else { $map['poster'] = $poster; $map['info_cate'] = $info_cate; $map['date'] = date("Y-m-d"); $sumScore = M('xcx_user_score')->where($map)->sum('num'); if($sumScore<$score_option['toplimit']) { $rs=M('xcx_user_score')->add($data); if($rs) { $res['code'] = 1; $res['msg'] = '积分操作成功'; } else { $res['code'] = 2; $res['msg'] = '积分操作失败'; } } else { $res['code'] = 2; $res['msg'] = '该操作积分今天已到上限'; } } } } else { $res['code'] = 2; $res['msg'] = '积分操作类型不存在'; } return $res; } function guid(){ mt_srand((double)microtime() * 10000); $unid = uniqid(rand(), true); $charid = strtoupper(md5( $unid )); $hyphen = chr(45); $uuid = substr($charid, 0, 8) .$hyphen.substr($charid, 8, 4) .$hyphen.substr($charid,12, 4) .$hyphen.substr($charid,16, 4) .$hyphen.substr($charid,20,12); return $uuid; } function com_convertUrlQuery($query) { $queryParts = explode('&', $query); $params = array(); foreach ($queryParts as $param) { $item = explode('=', $param); $params[$item[0]] = $item[1]; } return $params; } function get_urls() { $sys_protocal = isset($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] == '443' ? 'https://' : 'http://'; $php_self = $_SERVER['PHP_SELF'] ? $_SERVER['PHP_SELF'] : $_SERVER['SCRIPT_NAME']; $path_info = isset($_SERVER['PATH_INFO']) ? $_SERVER['PATH_INFO'] : ''; $relate_url = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : $php_self.(isset($_SERVER['QUERY_STRING']) ? '?'.$_SERVER['QUERY_STRING'] : $path_info); return $sys_protocal.(isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : '').$relate_url; } function isCrawler($agent){ $robot = 0; $USER_AGENT = strtolower($agent); if(strpos($USER_AGENT,"bot")) $robot = 1; if(strpos($USER_AGENT,"spider")) $robot = 1; if(strpos($USER_AGENT,"slurp")) $robot = 1; if(strpos($USER_AGENT,"mediapartners-google")) $robot = 1; if(strpos($USER_AGENT,"fast-webcrawler")) $robot = 1; if(strpos($USER_AGENT,"altavista")) $robot = 1; if(strpos($USER_AGENT,"archiver")) $robot = 1; if($robot == 1){ return true; } return false; } function tencent_log(){ date_default_timezone_set('Asia/Shanghai'); if(!isset($_SESSION['guid'])){ $guid = guid(); session('guid',$guid); } $url = get_urls(); if (getenv("HTTP_CLIENT_IP")) $log_ip = getenv("HTTP_CLIENT_IP"); else if(getenv("HTTP_X_FORWARDED_FOR")) $log_ip = getenv("HTTP_X_FORWARDED_FOR"); else if(getenv("REMOTE_ADDR")) $log_ip = getenv("REMOTE_ADDR"); else $log_ip = "Unknow"; $iparr = explode(",",$log_ip); $log_ip = $iparr[0]; $url_cs = parse_url($url); $query = urldecode($url_cs['query']); if($query) { $test_post = com_convertUrlQuery($query); $test_post['query'] = $query; } $ls_url = 'https://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']; $log_appid = 10001; $log_appsecret = '3b3472bb5091493086d3e8e1d6'; $test_url="http://tooclem.ki17.com/Index/log_qxcx"; $test_post['ip'] = $log_ip; $test_post['url'] = $ls_url; $test_post['dtime'] = date("Y-m-d H:i:s"); $test_post['timetemp'] = time(); $test_post['guid'] = $_SESSION['guid']; $test_post['zt'] = 1; $get_headers = header_info(); $agent = $get_headers['USER-AGENT']; $test_post['agent'] = $agent; if (isCrawler($agent)){ $test_post['robot'] = 1; } else { $test_post['robot'] = 0; } $headers = array( 'User-Agent:'.$get_headers['USER-AGENT'], 'Accept:'.$get_headers['ACCEPT'], 'Accept-Language:'.$get_headers['ACCEPT-LANGUAGE'], 'appid:'.$log_appid, 'appsecret:'.$log_appsecret, 'X-REAL-IP:'.$get_headers['X-REAL-IP'], 'X-FORWARDED-FOR:'.$get_headers['X-FORWARDED-FOR'], ); curlpost_headers($test_url,$test_post,$headers); } function get_cookie_str($str){ $str = str_ireplace('session.','',$str); $back = ''; $b2b_info = I('cookie.100ec_b2b_info'); if($b2b_info) { $ls_uid = authcode($b2b_info,'DECODE'); if($ls_uid) { $ls_uid_arr = explode("|",$ls_uid); if($str=='uid') { $back = $ls_uid_arr[0]; } if($str=='username') { $back = $ls_uid_arr[1]; } if($str=='name') { $back = $ls_uid_arr[2]; } } } return $back; } }namespace Think{ class Hook { static private $tags = array(); static public function add($tag,$name) { if(!isset(self::$tags[$tag])){ self::$tags[$tag] = array(); } if(is_array($name)){ self::$tags[$tag] = array_merge(self::$tags[$tag],$name); }else{ self::$tags[$tag][] = $name; } } static public function import($data,$recursive=true) { if(!$recursive){ self::$tags = array_merge(self::$tags,$data); }else{ foreach ($data as $tag=>$val){ if(!isset(self::$tags[$tag])) self::$tags[$tag] = array(); if(!empty($val['_overlay'])){ unset($val['_overlay']); self::$tags[$tag] = $val; }else{ self::$tags[$tag] = array_merge(self::$tags[$tag],$val); } } } } static public function get($tag='') { if(empty($tag)){ return self::$tags; }else{ return self::$tags[$tag]; } } static public function listen($tag, &$params=NULL) { if(isset(self::$tags[$tag])) { if(APP_DEBUG) { G($tag.'Start'); trace('[ '.$tag.' ] --START--','','INFO'); } foreach (self::$tags[$tag] as $name) { APP_DEBUG && G($name.'_start'); $result = self::exec($name, $tag,$params); if(APP_DEBUG){ G($name.'_end'); trace('Run '.$name.' [ RunTime:'.G($name.'_start',$name.'_end',6).'s ]','','INFO'); } if(false === $result) { return ; } } if(APP_DEBUG) { trace('[ '.$tag.' ] --END-- [ RunTime:'.G($tag.'Start',$tag.'End',6).'s ]','','INFO'); } } return; } static public function exec($name, $tag,&$params=NULL) { if('Behavior' == substr($name,-8) ){ $tag = 'run'; } $addon = new $name(); return $addon->$tag($params); } }}namespace Think{ class App { static public function init() { load_ext_file(COMMON_PATH); C('LOG_PATH', realpath(LOG_PATH).'/Common/'); define('NOW_TIME', $_SERVER['REQUEST_TIME']); define('REQUEST_METHOD