?php /** * extention.func.php 用户自定义函数库 * * @copyright (C) 2005-2010 OLCMS * @license http://www.olcms.cn/license/ * @lastmodify 2010-10-27 */ /*去除空格,包括中文字符*/ function _trim($str) { if (is_array ( $str )) { foreach ( $str as $key => $val ) { $str [$key] = _trim ( $val ); } } else { $str = str_replace ( '&', '&', $str ); $str = preg_replace ( '/([\n\r\t ]+)/is', ' ', $str ); $str = str_replace ( array (' ', ' ', ' ' ), ' ', $str ); $str = trim ( $str ); } return $str; } //转换选项字段为数组 function getboxname($modelid, $field) { $fulltext_array = getcache ( 'model_field_' . $modelid, 'model' ); $m = $fulltext_array [$field] ['setting']; $m = string2array ( $m ); $options = explode ( "\n", $m ['options'] ); foreach ( $options as $_k ) { $v = explode ( "|", $_k ); $k = trim ( $v [1] ); $option [$k] = $v [0]; } return $option; } //字数统计,汉字1个,字母0.5个 function get_num($string) { $string = strip_tags ( $string ); $strlen = strlen ( $string ); $string = str_replace ( array (' ', ' ', ' ', ' ', '&', '"', ''', '“', '”', '—', '<', '>', '·', '…' ), array (' ', ' ', ' ', ' ', '&', '"', "'", '“', '”', '—', '<', '>', '·', '…' ), $string ); $strcut = ''; $n = $tn = $noc = 0; while ( $n < $strlen ) { $t = ord ( $string [$n] ); if ($t == 9 || $t == 10 || (32 <= $t && $t <= 126)) { $tn = 1; ++ $n; $noc += 0.5; } elseif (194 <= $t && $t <= 223) { $tn = 2; $n += 2; $noc += 1; } elseif (224 <= $t && $t <= 239) { $tn = 3; $n += 3; $noc += 1; } elseif (240 <= $t && $t <= 247) { $tn = 4; $n += 4; $noc += 1; } elseif (248 <= $t && $t <= 251) { $tn = 5; $n += 5; $noc += 1; } elseif ($t == 252 || $t == 253) { $tn = 6; $n += 6; $noc += 1; } else { ++ $n; } } return $noc; } //根据modelid得出catid function modelid_to_catid($modelid) { $categorys = getcache ( 'category_content', 'commons' ); foreach ( $categorys as $c => $v ) { if ($v ['modelid'] == $modelid) $m [] = $c; } return $m; } //获取一个字段调用的type信息 function get_content_type($typeid, $catid) { $CATEGORYS = getcache ( 'category_content', 'commons' ); $usable_type = $CATEGORYS [$catid] ['usable_type']; $usable_array = array (); if ($usable_type) $usable_array = explode ( ',', $usable_type ); $type_data = getcache ( 'type_content', 'commons' ); foreach ( $type_data as $_key => $_value ) { if (in_array ( $_key, $usable_array ) && $_value ['parentid'] == $typeid) $data [$_key] = $_value ['name']; } return $data; } function cache_hit($name, $modelid, $id, $fields, $delay = '55') { $logfile = './caches/caches_content/caches_data/' . $name . '.log'; if (substr ( SYS_TIME, - 2 ) == $delay) { $viewlog = $viewarray = array (); $contentdb = pc_base::load_model ( 'content_model' ); $CATEGORYS = getcache ( 'category_content', 'commons' ); $contentdb->set_model ( $modelid ); $newlog = OLCMS_PATH . $logfile . random ( 6 ); if (@rename ( OLCMS_PATH . $logfile, $newlog )) { $viewlog = file ( $newlog ); @unlink ( $newlog ); if (is_array ( $viewlog ) && ! empty ( $viewlog )) { $viewlog = array_count_values ( $viewlog ); foreach ( $viewlog as $contentid => $views ) { $viewarray [$views] .= ($contentid > 0) ? ',' . intval ( $contentid ) : ''; } foreach ( $viewarray as $views => $ids ) { $contentdb->update ( array ($fields => '+=' . $views ), 'id IN (0' . $ids . ')' ); } } } } if (@$fp = fopen ( OLCMS_PATH . $logfile, 'a' )) { fwrite ( $fp, "$id\n" ); fclose ( $fp ); } } Function clearhtml($content) { $content = preg_replace ( "/]*>/i", "", $content ); $content = preg_replace ( "/<\/a>/i", "", $content ); $content = preg_replace ( "/]*>/i", "", $content ); $content = preg_replace ( "/<\/div>/i", "", $content ); $content = preg_replace ( "//i", "", $content ); //注释内容 $content = preg_replace ( "/style=.+?['|\"]/i", '', $content ); //去除样式 $content = preg_replace ( "/class=.+?['|\"]/i", '', $content ); //去除样式 $content = preg_replace ( "/id=.+?['|\"]/i", '', $content ); //去除样式 $content = preg_replace ( "/lang=.+?['|\"]/i", '', $content ); //去除样式 $content = preg_replace ( "/width=.+?['|\"]/i", '', $content ); //去除样式 $content = preg_replace ( "/height=.+?['|\"]/i", '', $content ); //去除样式 $content = preg_replace ( "/border=.+?['|\"]/i", '', $content ); //去除样式 $content = preg_replace ( "/face=.+?['|\"]/i", '', $content ); //去除样式 $content = preg_replace ( "/face=.+?['|\"]/", '', $content ); //去除样式 只允许小写 正则匹配没有带 i 参数 return $content; } //判断数组(多维)数值是否为空的函数 function array_is_null($arr = null) { if (is_array ( $arr )) { foreach ( $arr as $k => $v ) { if ($v && ! is_array ( $v )) { return false; } $t = self::array_is_null ( $v ); // $t = this->array_is_null ( $v ); if (! $t) { return false; } } return true; } elseif (! $arr) { return true; } else { return false; } } function set_search_record($modelid, $word = '', $url = '') { $writefile = './caches/caches_content/caches_log/w_' . $modelid . '.log'; $readfile = './caches/caches_content/caches_log/r_' . $modelid . '.log'; if (! empty ( $word )) { if (substr ( SYS_TIME, - 2 ) == '00') { $records = array (); $newlog = OLCMS_PATH . $writefile . random ( 6 ); if (@rename ( OLCMS_PATH . $writefile, $newlog )) { $records = file ( $newlog ); if (is_array ( $records ) && ! empty ( $records [0] )) { @unlink ( $readfile ); @rename ( $newlog, OLCMS_PATH . $readfile ); } } } if (@$fp = fopen ( OLCMS_PATH . $writefile, 'a' )) { fwrite ( $fp, "{$word}|{$url}\n" ); fclose ( $fp ); } } } function get_search_record($modelid, $num = 10) { $readfile = './caches/caches_content/caches_log/r_' . $modelid . '.log'; if (! file_exists ( OLCMS_PATH . $readfile )) return false; $rs = file ( $readfile ); $i = 1; $data = array (); foreach ( $rs as $v ) { $record = explode ( '|', $v ); if (isset ( $data [$record [0]] )) continue; ++ $i; $data [$record [0]] = $record [1]; if ($i >= $num) break; } return $data; } //判断是否是搜索爬虫 function getrobot($useragent = '') { static $kw_spiders = array('bot', 'crawl', 'spider' ,'slurp', 'sohu-search', 'lycos', 'robozilla'); static $kw_browsers = array('msie', 'netscape', 'opera', 'konqueror', 'mozilla'); $useragent = strtolower(empty($useragent) ? $_SERVER['HTTP_USER_AGENT'] : $useragent); if(strpos($useragent, 'http://') === false && dstrpos($useragent, $kw_browsers)) return false; if(dstrpos($useragent, $kw_spiders)) return true; return false; } function checkmobile() { $mobile = array(); static $mobilebrowser_list =array('iphone', 'android', 'phone', 'mobile', 'wap', 'netfront', 'java', 'opera mobi', 'opera mini', 'ucweb', 'windows ce', 'symbian', 'series', 'webos', 'sony', 'blackberry', 'dopod', 'nokia', 'samsung', 'palmsource', 'xda', 'pieplus', 'meizu', 'midp', 'cldc', 'motorola', 'foma', 'docomo', 'up.browser', 'up.link', 'blazer', 'helio', 'hosin', 'huawei', 'novarra', 'coolpad', 'webos', 'techfaith', 'palmsource', 'alcatel', 'amoi', 'ktouch', 'nexian', 'ericsson', 'philips', 'sagem', 'wellcom', 'bunjalloo', 'maui', 'smartphone', 'iemobile', 'spice', 'bird', 'zte-', 'longcos', 'pantech', 'gionee', 'portalmmm', 'jig browser', 'hiptop', 'benq', 'haier', '^lct', '320x320', '240x320', '176x220'); $pad_list = array('pad', 'gt-p1000'); $useragent = strtolower($_SERVER['HTTP_USER_AGENT']); if(dstrpos($useragent, $pad_list)) { return false; } if(dstrpos($useragent, $mobilebrowser_list, true)) { return true; } $brower = array('mozilla', 'chrome', 'safari', 'opera', 'm3gate', 'winwap', 'openwave', 'myop'); if(dstrpos($useragent, $brower)) return false; } function dstrpos($string, &$arr, $returnvalue = false) { if(empty($string)) return false; foreach((array)$arr as $v) { if(strpos($string, $v) !== false) { $return = $returnvalue ? $v : true; return $return; } } return false; } function lunar_calendar($date) { $Calendar = pc_base::load_sys_class ( 'calendar' ); $Ltype=0; $Ldate=$Calendar->S2L($date,$Ltype); $Year = $Calendar->Cal ( date('Y-m-d',$Ldate),$Ltype); //var_dump($Year); return $Year ["month"] . $Year ["day"]; } function _ip2long($strIP) { if (empty ( $strIP )) return false; $lngIP = ip2long ( $strIP ); if ($lngIP == - 1) return false; else return sprintf ( "%u", $lngIP ); } function match_value($str, $array,$first=1) { if (empty ( $str )) return 0; if (! is_array ( $array )) return 0; $str = strtr ( $str, $array ); preg_match_all ( '/\[(\d+)\]/', $str, $info ); if ($info [1] [0]) { if($first==1) return $info [1] [0]; foreach ( $info [1] as $v ) { $vaule = $v; } return $vaule; } else return 0; } function format_date($format,$value){ if($value<1000) return false; $day=intval(substr($value, -2)); $month=intval(substr($value, 4,2)); $year=intval(substr($value, 4,2)); $format=str_ireplace(array('y','m','d'), array($year,$month,$day), $format); return $format; } //对像转数组 function object_to_array($obj) { $_arr = is_object ( $obj ) ? get_object_vars ( $obj ) : $obj; if(!is_array ( $_arr )) return $_arr; foreach ( $_arr as $key => $val ) { $val = (is_array ( $val ) || is_object ( $val )) ? object_to_array ( $val ) : $val; $arr [$key] = $val; } return $arr; } /** * Curl版本 * 使用方法: * $post_string = "app=request&version=beta"; * request_by_curl('http://facebook.cn/restServer.php',$post_string); */ function request_by_curl($remote_server, $post_string) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $remote_server); curl_setopt($ch, CURLOPT_POSTFIELDS, $post_string); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']); $data = curl_exec($ch); curl_close($ch); return $data; } function vpost($url,$data){ // 模拟提交数据函数 $curl = curl_init(); // 启动一个CURL会话 curl_setopt($curl, CURLOPT_URL, $url); // 要访问的地址 curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0); // 对认证证书来源的检查 curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 1); // 从证书中检查SSL加密算法是否存在 curl_setopt($curl, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']); // 模拟用户使用的浏览器 curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1); // 使用自动跳转 curl_setopt($curl, CURLOPT_AUTOREFERER, 1); // 自动设置Referer curl_setopt($curl, CURLOPT_POST, 1); // 发送一个常规的Post请求 curl_setopt($curl, CURLOPT_POSTFIELDS, $data); // Post提交的数据包 curl_setopt($curl, CURLOPT_TIMEOUT, 10); // 设置超时限制防止死循环 curl_setopt($curl, CURLOPT_HEADER, 0); // 显示返回的Header区域内容 curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); // 获取的信息以文件流的形式返回 $tmpInfo = curl_exec($curl); // 执行操作 if (curl_errno($curl)) { return false; } curl_close($curl); // 关闭CURL会话 return $tmpInfo; // 返回数据 } function vget($url){ // 模拟提交数据函数 $curl = curl_init(); // 启动一个CURL会话 curl_setopt($curl, CURLOPT_URL, $url); // 要访问的地址 curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0); // 对认证证书来源的检查 curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 1); // 从证书中检查SSL加密算法是否存在 curl_setopt($curl, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']); // 模拟用户使用的浏览器 curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1); // 使用自动跳转 curl_setopt($curl, CURLOPT_AUTOREFERER, 1); // 自动设置Referer curl_setopt($curl, CURLOPT_TIMEOUT, 10); // 设置超时限制防止死循环 curl_setopt($curl, CURLOPT_HEADER, 0); // 显示返回的Header区域内容 curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); // 获取的信息以文件流的形式返回 $tmpInfo = curl_exec($curl); // 执行操作 if (curl_errno($curl)) { return false; } curl_close($curl); // 关闭CURL会话 return $tmpInfo; // 返回数据 } //获取百度access_token 值; function get_access_token(){ $array_access_token=getcache('access_token','content'); if(!$array_access_token['expires_in'] || $array_access_token['expires_time']$array_access_token['access_token'],'lcid'=>'miad','clientip'=>ip(),'user_agent'=>$_SERVER['HTTP_USER_AGENT'],'accept'=>$_SERVER['HTTP_ACCEPT'])); $array_user_agent=object_to_array(json_decode($array_user_agent)); param::set_cookie ( 'user_agent', $array_user_agent['device_type'].','.$array_user_agent['tn'], SYS_TIME + 2592000); }else{ $array_user_agent['device_type']=2; $array_user_agent['tn']=''; } } return $array_user_agent; } //文章关键词替换 function StringAddKeywordUrl($String, $Keywords) { if (! $String) return $String; if (! $Keywords [0]) return $String; $search = "/(alt\s*=\s*|title\s*=\s*)[\"|\'](.*?)[\"|\']/ise"; $replace = "_base64_encode('\\1','\\2')"; $replace1 = "_base64_decode('\\1','\\2')"; $String = preg_replace ( $search, $replace, $String ); foreach ( $Keywords as $v ) { $String = preg_replace ( "/>([^<]+)<\/a>/ise", "a_base64_encode ( '\\1' )", $String ); $String_arr = explode ( $v ['word'], $String ); $count = count ( $String_arr ) - 1; //var_dump( $page_value); exit(); if ($count < 1) continue; $str = ''; foreach ( $String_arr as $k => $value ) { if (empty ( $value )) continue; if ($k == 1) { $str .= $v ['replacecode'] . $value; } else { $str .= $k == 0 ? $value : $v ['word'] . $value; } } $String = $str; $String = preg_replace ( "/>\[\[([^<]+)\]\]<\/a>/ise", "a_base64_decode ( '\\1' )", $String ); } $String = preg_replace ( $search, $replace1, $String ); return $String; } function keylink($content) { $linkword = getcache ( 'keylink', 'commons' ); $replace_str = strtr ( strip_tags ( $content ), $linkword ); unset ( $linkword ); preg_match_all ( '/\[([^\]]+)\|([^\]]+)\]/is', $replace_str, $info ); if ($info [1] [0]) { foreach ( $info [1] as $k => $v ) { $data [$v] = $info [2] [$k]; } foreach ( $data as $key => $v ) { if (substr ( $v, 0, 4 ) != 'http') $v = 'http://www.tianqibaidu.com/' . $v . '/'; $replaceTag [] = array ('len' => strlen ( $key ), 'word' => $key, 'replacecode' => '' . $key . '' ); } rsort ( $replaceTag ); } return StringAddKeywordUrl ( $content, $replaceTag ); } function _base64_encode($t, $str) { return $t . "\"" . base64_encode ( $str ) . "\""; } function _base64_decode($t, $str) { return $t . "\"" . base64_decode ( $str ) . "\""; } function a_base64_encode($str) { return ">[[" . base64_encode ( $str ) . "]]"; } function a_base64_decode($str) { return ">" . base64_decode ( $str ) . ""; } function paragraph($content,&$array){ $array['content']=''; if(!isset($content{1000})){ $array['content']=$content; return false; } $String_arr = explode ( '

', $content ); $count = count ( $String_arr ); if($count<4){ $array['content']=$content; return false; } $endkey=-1; for($i=$count;$i>0;$i--){ $thekey=$i-1; if(isset($String_arr[$thekey]{100}) && !isset($String_arr[$thekey]{800})){ $endkey=$thekey; break; } } $fist_paragraph=0; foreach ($String_arr as $key=>$value){ if(empty($value)) continue; if($fist_paragraph<1 && isset($value{100}) && !isset($value{800})){ $array['first_paragraph']=preg_replace ( '/]{0,200})>/is', '', $value ); $array['content'].= '

'; $fist_paragraph=$key+1; }elseif ($key==$endkey && $count-4>$fist_paragraph){ $array['last_paragraph']=preg_replace ( '/]{0,200})>/is', '', $value ); $array['content'].= '

'; }else{ $array['content'].= $value.'

'; } } } function format_content($content) { $content = preg_replace ( '/\s(?=\s)/', '', $content ); // 接着去掉两个空格以上的 $content = preg_replace ( '/[\n\r\t]/', '', $content ); // 最后将非空格替换为一个空格 $content = str_ireplace ( array ('', ' ', '', '' ), array ('', ' ', '', '' ), $content ); $content = preg_replace ( '/]+)>/is', '', $content ); $content = preg_replace ( '//is', '', $content ); $content = preg_replace ( '/]+)>/is', '', $content ); $content = preg_replace ( '/]+)>/is', '', $content ); $content = preg_replace ( '/ style="([^"]+)"/is', '', $content ); $content = preg_replace ( '/class=([^>]+)>/is', '>', $content ); $content = preg_replace ( '/([\n\r\t ]+)>/is', '>', $content ); $content = preg_replace ( '/>([\n\r\t ]+)/is', '>', $content ); $content = preg_replace ( '/]+)><\/p>/is', '', $content ); $content = str_ireplace ( array ('

', '

','

', '

','

', '

', '

','' ), array ('

', '

', '

','' ), $content ); $content = str_replace ( array ("\\", "

" ), '', $content ); $content = str_replace ( array ("" ), array(''), $content ); return $content; } function string2pic($string){ $array_pic = array ('晴' => '00', '晴间多云'=>'01','多云' => '01', '阴' => '02', '阵雨' => '03', '雷阵雨' => '04', '小雨' => '07', '小到中雨' => '21', '中雨' => '08', '中到大雨' => '22', '大雨' => '09', '大到暴雨' => '23', '暴雨' => '10', '暴雨到大暴雨' => '24', '大暴雨' => '11', '大暴雨到特大暴雨' => '25', '特大暴雨' => '12', '阵雪' => '13', '小雪' => '14', '小到中雪' => '26', '中雪' => '15', '中到大雪' => '27', '大雪' => '16', '大到暴雪' => '27', '暴雪' => '17', '雨夹雪' => '06', '雾' => '18', '大雾' => '18', '浮尘' => '29', '雷阵雨伴有冰雹' => '05', '冻雨' => '19', '扬沙' => '20', '沙尘暴' => '30', '雷阵雨伴有冰雹' => '05', '强沙尘暴' => '31' ); return $array_pic [$string]; } //编码转换 function m_iconv($s, $t) { if (is_array ( $s )) { foreach ( $s as $k => $v ) { $s [$k] = m_iconv ( $v, $t ); } } else { $encoding = mb_detect_encoding ( $s, array ('ASCII', 'UTF-8', 'GB2312', 'GBK', 'BIG5' ) ); $s = mb_convert_encoding ( $s, $t, $encoding ); } return $s; } //格式化文件大小格式 function formatSize($size,$digits=2){ $unit= array('','K','M','G','T','P'); $base= 1024; $i = floor(log($size,$base)); $n = count($unit); if($i >= $n) $i=$n-1; $division=pow($base,$i); $value= $division?($size/$division):0; return round($value,$digits).' '.$unit[$i] . 'B'; } function downbaiduimg($path,$title,$picture){ $url='http://image.baidu.com/i?tn=baiduimage&ie=utf-8&word='.$title; $referer_url='http://image.baidu.com/'; $curl = curl_init(); curl_setopt($curl, CURLOPT_REFERER,$referer_url );// Referer的地址 curl_setopt($curl, CURLOPT_USERAGENT, $_SERVER ['HTTP_USER_AGENT']); // 模拟用户使用的浏览器 curl_setopt($curl, CURLOPT_URL, $url); //curl_setopt($curl, CURLOPT_INTERFACE, '218.85.110.18'); curl_setopt($curl, CURLOPT_HEADER, 0); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); $body = curl_exec($curl); curl_close($curl); if(!$body) return false; preg_match_all('/"largeTnImageUrl":"([^"]+)"/is', $body,$match); if(!$match[1][4]) return false; $downimg=$match[1][4]; unset($body,$match); $picture=dwimg($path,$referer_url,$picture.substr($downimg, -4),$downimg); return $picture; } function dwimg($path,$referer_url,$picture,$pic){ $curl = curl_init(); curl_setopt($curl, CURLOPT_REFERER,$referer_url );// Referer的地址 curl_setopt($curl, CURLOPT_USERAGENT, $_SERVER ['HTTP_USER_AGENT']); // 模拟用户使用的浏览器 curl_setopt($curl, CURLOPT_URL, $pic); curl_setopt($curl, CURLOPT_HEADER, 0); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); $data = curl_exec($curl); if(!$data) return false; curl_close($curl); $write = @fopen($path.$picture,"w"); fwrite($write,$data); fclose($write); return '/'.$picture; } function update_areaUrl($areaid, $typeid,$groupid=0) { if(!$areaid || !$typeid) return false; $isrobot=getrobot(); if(!$isrobot) return false; $db = pc_base::load_model ( 'model_model' ); $db->set_table('url'); $where = 'areaid=' . $areaid . ' AND typeid=' . $typeid.' AND groupid='.$groupid; $weburl = $db->get_one ( $where,'isembodied' ); if(!$weburl) return false; if ($weburl ['isembodied'] < 3) { $user_agent = strtolower ( $_SERVER ['HTTP_USER_AGENT'] ); if (strpos ( $user_agent, 'baiduspider' ) !== false) { $d ['isembodied'] = 3; $db->update ( $d, $where ); } elseif($weburl ['isembodied']<2) { $d ['isembodied'] = 2; $db->update ( $d, $where ); } } } ?>
Warning: date() expects parameter 2 to be long, string given in /www/wwwroot/tianqibaidu.com/default/olcms/libs/functions/global.func.php on line 441

Fatal error: Call to undefined function getrobot() in /www/wwwroot/tianqibaidu.com/default/olcms/base.php on line 44