function.global.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713
  1. <?php
  2. function show_seotool_window($title,$html,$args = ''){
  3. global $_G;
  4. $charset = GBK ? 'gb2312' : 'UTF-8';
  5. $big5 = $_G['config']['output']['language'] == 'zh_tw' && $_G['config']['output']['charset'] == 'big5' ? TRUE : FALSE;
  6. if($big5) $charset = 'big5';
  7. if(!$args['no_show']) header('Content-Type: text/xml ');
  8. global $_G;
  9. ob_clean();
  10. ob_end_flush();
  11. $show_footer = $args['f'] && !$args['js_func'] ? false : true;
  12. $args['js_func'] = $args['js_func'] ? $args['js_func'] : 'hideWindow(\''.$_GET['handlekey'].'\')';
  13. if(!$args['w']) $args['w'] = 'auto';
  14. if(!$args['h']) $args['h'] = 'auto';
  15. $args['y'] = $args['y'] ? 'hidden' : 'scroll';
  16. if(!$args['no_show']){
  17. $show_html = '<?xml version="1.0" encoding="'.$charset.'"?>';
  18. $show_html .= "<root>";
  19. $show_html .= '<![CDATA[';
  20. }
  21. $show_html .= '<h3 class="flb">
  22. <em>'.$title.'</em>
  23. <span><a href="javascript:;" onclick="hideWindow(\''.$_GET['handlekey'].'\');" class="flbc" title="'.stlang('close').'">'.stlang('close').'</a></span>
  24. </h3>
  25. <div class="article_detail c" id="return_'.$_GET['handlekey'].'">
  26. <div class="c bart">
  27. <div style="width:'.$args['w'].'px; height:'.$args['h'].'px;overflow-y:'.$args['y'].';">'.$html.'</div>
  28. </div>';
  29. if($show_footer){
  30. $show_html .= '<p class="o pns">
  31. <button type="submit" name="dsf" style="width:50px; height:25px;" class="pn pnc" onclick="'.$args['js_func'].';"><span>'.stlang('ok').'</span></button>
  32. <button type="reset" style="width:50px; height:25px;" name="dsf" class="pn" onclick="hideWindow(\''.$_GET['handlekey'].'\');"><em>'.stlang('cancel').'</em></button>
  33. </p>';
  34. }
  35. $show_html .= "</div>";
  36. if(!$args['no_show']){
  37. $show_html .= "]]></root>";
  38. }
  39. if($args['no_show'] == 1){
  40. return $show_html;
  41. }else{
  42. echo $show_html;
  43. }
  44. //echo st_str_iconv($show_html);
  45. define(FOOTERDISABLED, false);
  46. exit();
  47. }
  48. function st_str_cut($content, $start, $end){//取出所有匹配,效率最快,因为只读一次,字符串越大越明显
  49. $m = explode($start,$content);
  50. $result = array();
  51. for( $i = 1;$i < count($m);$i++ ){
  52. $my = explode($end,$m[$i]);
  53. $result[] = $my[0];
  54. unset($my);
  55. }
  56. return $result;
  57. }
  58. //由此函数调ajax函数
  59. function seotool_ajax_func(){
  60. global $_G;
  61. $seotool_ajax_func = $_GET['af'];
  62. $allow_func_arr = array('tips_no', 'flink_ask_detail', 'flink_ask_to', 'flink_ask_op', 'st_ajax_keyword', 'st_redirect_zhishu', 'st_redirect_zhishu', 'st_ajax_keyword_list');
  63. if(strexists($seotool_ajax_func, ':')){
  64. $temp_arr = explode(':', $seotool_ajax_func);
  65. $file_name = $temp_arr[0];
  66. $seotool_ajax_func = $temp_arr[1];
  67. sload('F:'.$file_name);
  68. if(!function_exists($seotool_ajax_func)){
  69. if(!in_array($seotool_ajax_func, $allow_func_arr)) exit('Access Denied:sb360');
  70. sload('C:'.$file_name);
  71. if(!function_exists($seotool_ajax_func)){
  72. exit(stlang('no_found_ajaxfunc'));
  73. }
  74. }
  75. }
  76. $inajax = $_GET['inajax'];
  77. $xml = empty($_GET['xml']) ? 0 : $_GET['xml'];
  78. if(!function_exists($seotool_ajax_func)) exit(stlang('no_found_ajaxfunc'));
  79. $output = $seotool_ajax_func();
  80. ob_clean();
  81. ob_end_flush();
  82. if($xml == 1) include template('common/header_ajax');
  83. echo $output;
  84. if($xml == 1) include template('common/footer_ajax');
  85. define(FOOTERDISABLED, false);
  86. exit();
  87. }
  88. function st_get_contents($url, $args = array()){
  89. extract($args);
  90. $cache = isset($cache) ? $cache : 3600;
  91. if($cache > 0 && $content = st_load_cache($url)){
  92. }else{
  93. $snoopy = st_get_snoopy_obj($args);
  94. if(!$snoopy->fetch($url)) return FALSE;
  95. $header = $snoopy->headers;
  96. $key = array_search("Content-Encoding: gzip\r\n", $header);
  97. if($header[0] == 'HTTP/1.1 404 Not Found
  98. ' || $header[0] == 'HTTP/1.1 500 Internal Server Error') return FALSE;
  99. $content = $snoopy->results;
  100. $content = st_str_iconv($content);
  101. if($content) st_cache_data($url, $content, $cache);
  102. }
  103. return $content;
  104. }
  105. function st_get_snoopy_obj($args = array()){
  106. extract($args);
  107. require_once(PLUGIN_DIR.'/lib/Snoopy.class.php');
  108. $snoopy = new Snoopy;
  109. $snoopy->maxredirs = $maxredirs ? $maxredirs : 3;
  110. $snoopy->expandlinks = TRUE;
  111. $snoopy->offsiteok = TRUE;//是否允许向别的域名重定向
  112. $snoopy->agent = $_SERVER['HTTP_USER_AGENT'];
  113. if($referer) $snoopy->referer = $referer;
  114. $snoopy->rawheaders["COOKIE"]= $cookie;
  115. return $snoopy;
  116. }
  117. function st_ischinese($s){
  118. $allen = preg_match("/^[^\x80-\xff]+$/", $s); //判断是否是英文
  119. $allcn = preg_match("/^[".chr(0xa1)."-".chr(0xff)."]+$/",$s); //判断是否是中文
  120. if($allen){
  121. return 'allen';
  122. }else{
  123. if($allcn){
  124. return 'allcn';
  125. }else{
  126. return 'encn';
  127. }
  128. }
  129. }
  130. function st_format_wrap($str, $exp_type = WRAP){
  131. if(!defined('WRAP')) {
  132. define('WRAP', PHP_EOL);
  133. $exp_type = WRAP;
  134. }
  135. if(!$str) return false;
  136. $arr = explode($exp_type, trim($str));
  137. return $arr;
  138. }
  139. function st_num_size($data){
  140. if($data >100000000){
  141. $data = round(($data /100000000),2).stlang('_yi');
  142. }elseif($data >10000){
  143. $data = round(($data /10000),2).stlang('_wan');
  144. }elseif($data >1000){
  145. //$data = round(($data /1000),2).stlang('_qian');
  146. $data = $data;
  147. }
  148. if($data <0){
  149. if($data < -100000000){
  150. $data = round(($data /100000000),2).stlang('_yi');
  151. }elseif($data < -10000){
  152. $data = round(($data /10000),2).stlang('_wan');
  153. }elseif($data < -1000){
  154. $data = round(($data /1000),2).stlang('_qian');
  155. }
  156. }
  157. return $data;
  158. }
  159. //获取插件的全局设置
  160. function st_get_pluin_set(){
  161. global $_G;
  162. loadcache('plugin');
  163. return $_G['cache']['plugin']['milu_seotool'];
  164. }
  165. function st_ajax_decode($str){
  166. return json_decode(base64_decode($str));
  167. }
  168. function st_get_domain($url){
  169. if(empty($url)) return;
  170. $d = RootDomain::instace();
  171. $d->setUrl($url);
  172. return $d->getDomain();
  173. }
  174. function st_check_rpc_data($data){
  175. if(!is_object($data)) {
  176. if($data == 'rpclimit') exit(stlang('rpclimit'));
  177. return $data;
  178. }
  179. if($data->Message || $data->Number == 0) {
  180. cpmsg_error(stlang('phprpc_error_text', array('msg' => $data->Message)));
  181. }
  182. }
  183. function st_get_rpc_error($data){
  184. if(!is_object($data)) return FALSE;
  185. if($data->Message || $data->Number == 0) {
  186. return stlang('phprpc_error', array('msg' => $data->Message));
  187. }
  188. return FALSE;
  189. }
  190. function seo_tpl($args = array()){
  191. global $_S,$_G;
  192. extract((array)$args);
  193. $head_url = '?'.PLUGIN_GO.$_GET['pmod'].'&myac=';
  194. $myac = $_GET['myac'];
  195. $tpl = $_GET['tpl'];
  196. if(empty($myac)) $myac = $default_ac ? $default_ac : $_GET['pmod'].'_run';
  197. if($_G['adminid'] < 1 && !in_array($myac, array('flink_ask_api', 'milu_seotool_cron'))) exit('Access Denied:sb360');
  198. sload('C:seoOutput');
  199. if(!in_array($myac, array('keyword_set', 'forum_keyword', 'portal_keyword', 'trend_data_count', 'flink_onlie', 'trend_data_count', 'milu_seotool_cron', 'flink_ask_api' , 'seo_word_set', 'seo_word_import', 'seo_word_download', 'rpcServer', 'seotool_ajax_func', 'update_info', 'base_data_count', 'trend_data_count', 'article_seo_set', 'flink_set', 'flink_to', 'flink_get', 'flink_onlie', 'included_set', 'included_forum_list', 'included_portal_list', 'spider_set', 'spider_list', 'area_data_count', 'spider_data_clear', 'sitemap_set'))) exit('Access Denied:sb360');
  200. if(function_exists($myac)) $info = $myac();
  201. $_GET['mytemp'] = $_GET['mytemp'] ? $_GET['mytemp'] : $info['tpl'];
  202. $mytemp = $_GET['mytemp'] ? $_GET['mytemp'] : $myac;
  203. $tpl = $info['tpl'] ? $info['tpl'] : $tpl;
  204. if(!$_GET['inajax']){
  205. $_S['set'] = st_get_pluin_set();
  206. $submit_pmod = $info['submit_pmod'] ? $info['submit_pmod'] : $_GET['pmod'];
  207. $submit_action = $info['submit_action'] ? $info['submit_action'] : $myac;
  208. $info['header'] = seoOutput::pick_header_output();
  209. if(!$tpl || $tpl!= 'no') include template('milu_seotool:'.$mytemp);
  210. }
  211. }
  212. //转换不同编码的序列化数组
  213. function st_serialize_iconv($thevalue){
  214. global $_G;
  215. if(!is_array($thevalue)) return $thevalue;
  216. foreach((array)$thevalue as $k => $v){//防止编码不同造成的错误
  217. $v_s = dunserialize($v);
  218. if(!$v_s){//不是序列化
  219. if(is_array($v)){//如果是数组
  220. $thevalue[$k] = st_serialize_iconv($v);
  221. }else{
  222. $thevalue[$k] = $_G['config']['output']['language'] == 'zh_tw' && $_G['config']['output']['charset'] == 'big5' ? st_gb2big5($v) : st_str_iconv($v);
  223. }
  224. }else{
  225. $v = st_serialize_iconv($v_s);
  226. $thevalue[$k] = serialize($v);
  227. }
  228. }
  229. return $thevalue;
  230. }
  231. function st_rpcClient($rpc_url = ''){
  232. include_once (PLUGIN_DIR."/lib/phprpc/phprpc_client.php");
  233. $client = new PHPRPC_Client();
  234. $client->setProxy(NULL);
  235. $rpc_url = $rpc_url ? $rpc_url : GET_URL.'plugin.php?id=seotool_server:flink&tpl=no&myac=rpcServer&inajax=1';
  236. $client->useService($rpc_url);
  237. //$client->setKeyLength(10);
  238. //$client->setEncryptMode(3);
  239. $client->setCharset('GBK');
  240. $client->setTimeout(10);
  241. return $client;
  242. }
  243. function st_str_iconv($str, $charset = ''){
  244. global $_G;
  245. $is_big = $_G['cache']['evn_milu_pick']['pick_config']['is_big'];//是否utf-8环境下将繁体转换为简体
  246. if(!$str) return false;
  247. $charset = $charset ? $charset : strtoupper(st_get_charset($str));
  248. $big5 = $_G['config']['output']['language'] == 'zh_tw' && $_G['config']['output']['charset'] == 'big5' ? TRUE : FALSE;
  249. if(GBK){
  250. if($charset == 'UTF-8'){
  251. if($is_big){
  252. return st_big5_gbk($str);
  253. }
  254. $str = st_iconv($str, 'UTF-8', 'GBK');
  255. return $str;
  256. }else if($charset == 'BIG5'){//繁体
  257. return st_big52gb($str);
  258. }
  259. }else{
  260. if($charset != 'UTF-8'){
  261. if($charset == 'BIG5') {
  262. if($_G['config']['output']['language'] != 'zh_tw'){//简体
  263. $str = st_big52gb($str);
  264. return st_iconv($str, 'GBK', 'UTF-8');
  265. }
  266. if($big5) return $str;
  267. }
  268. if($big5) return st_gb2big5($str);
  269. $str = st_iconv($str, $charset, 'UTF-8');
  270. return $str;
  271. }else{
  272. if($big5){
  273. $str = st_iconv($str, 'UTF-8', 'GBK');
  274. $str = st_gb2big5($str);
  275. return $str;
  276. }
  277. }
  278. }
  279. return $str;
  280. }
  281. function st_serialize($arr){
  282. return serialize(dstripslashes($arr));
  283. }
  284. //utf-8环境下 繁体装成简体 只用于gbk程序
  285. function st_big5_gbk($str){
  286. global $_G;
  287. $is_big = $_G['cache']['milu_seotool']['config']['is_big'];//是否utf-8环境下将繁体转换为简体
  288. if(!$is_big) return $str;
  289. $str = st_iconv($str, 'UTF-8', 'BIG5');
  290. $str = st_big52gb($str);
  291. return $str;
  292. }
  293. function st_gb2big5($Text){
  294. $fp = fopen(PLUGIN_DIR."/data/gb-big5.table", "r");
  295. $max = strlen($Text)-1;
  296. for($i=0; $i<$max; $i++){
  297. $h = ord($Text[$i]);
  298. if($h >= 160){
  299. $l=ord($Text[$i+1]);
  300. if($h == 161 && $l==64){
  301. $gb = " ";
  302. }else{
  303. fseek($fp, ($h-160)*510+($l-1)*2);
  304. $gb = fread($fp,2);
  305. }
  306. $Text[$i] = $gb[0];
  307. $Text[$i+1] = $gb[1]; $i++;
  308. }
  309. }
  310. fclose($fp);
  311. return $Text;
  312. }
  313. function st_big52gb($Text){
  314. $fp = fopen(PLUGIN_DIR."/data/big5-gb.table", "r");
  315. $max = strlen($Text)-1;
  316. for($i=0;$i<$max;$i++){
  317. $h = ord($Text[$i]);
  318. if($h>=160){
  319. $l = ord($Text[$i+1]);
  320. if($h == 161 && $l==64){
  321. $gb = " ";
  322. }else{
  323. fseek($fp, ($h-160)*510+($l-1)*2);
  324. $gb = fread($fp,2);
  325. }
  326. $Text[$i] = $gb[0];
  327. $Text[$i+1] = $gb[1];
  328. $i++;
  329. }
  330. }
  331. fclose($fp);
  332. return $Text;
  333. }
  334. function st_iconv($str, $in, $out){
  335. global $_G;
  336. $is_win = strtoupper(substr(PHP_OS, 0, 3)) == 'WIN' ? TRUE : FALSE;
  337. if($is_win) return diconv($str, $in, $out);
  338. if(function_exists('mb_convert_encoding')) {
  339. $str = mb_convert_encoding($str, $out, $in);
  340. }else{
  341. $str = diconv($str, $in, $out);
  342. }
  343. return $str;
  344. }
  345. function st_get_charset($web_str){
  346. preg_match("/<meta[^>]+charset=\"?'?([^'\"\>]+)\"?[^>]+\>/is", $web_str, $arr);
  347. //if($arr[1]) return $arr[1];
  348. $arr[1] = strtoupper($arr[1]);
  349. if($arr[1] == 'GBK' || $arr[1] == 'BIG5') return $arr[1];
  350. $charset = st_is_utf8($web_str) ? 'UTF-8' : 'GB2312';
  351. if($arr[1] && $arr[1] == $charset) return $arr[1];
  352. return $charset;
  353. }
  354. function st_is_utf8($string) {
  355. if (preg_match("/^([".chr(228)."-".chr(233)."]{1}[".chr(128)."-".chr(191)."]{1}[".chr(128)."-".chr(191)."]{1}){1}/",$string) == true || preg_match("/([".chr(228)."-".chr(233)."]{1}[".chr(128)."-".chr(191)."]{1}[".chr(128)."-".chr(191)."]{1}){1}$/",$string) == true || preg_match("/([".chr(228)."-".chr(233)."]{1}[".chr(128)."-".chr(191)."]{1}[".chr(128)."-".chr(191)."]{1}){2,}/",$string) == true) {
  356. return true;
  357. }else{
  358. return false;
  359. }
  360. }
  361. if(!function_exists('dunserialize')){//这个函数是DZ2.5新加入的
  362. function dunserialize($data) {
  363. if(($ret = unserialize($data)) === false) {
  364. $ret = unserialize(stripslashes($data));
  365. }
  366. return $ret;
  367. }
  368. }
  369. function get_site_category(){
  370. global $pluin_info,$_G;
  371. $cache_key = 'milu_seotool_site_category';
  372. loadcache($cache_key);
  373. $big5 = $_G['config']['output']['language'] == 'zh_tw' && $_G['config']['output']['charset'] == 'big5' ? TRUE : FALSE;
  374. if( !($data = $_G['cache'][$cache_key] )){
  375. $cate_str = stlang('site_category');
  376. if(!$big5){
  377. $cate_arr = explode('|', $cate_str);
  378. foreach((array)$cate_arr as $k => $v){
  379. $temp_arr = explode('=', $v);
  380. $data[$temp_arr[0]] = $temp_arr[1];
  381. }
  382. }else{//不这样繁体分割会乱码
  383. preg_match_all("/([\x81-\xfe][\x40-\xfe])+/", $cate_str, $matches);
  384. $value_arr = $matches[0];
  385. $key_arr = range(1, count($value_arr));
  386. $data = array_combine($key_arr, $value_arr);
  387. }
  388. save_syscache($cache_key, $data);
  389. }
  390. return $data;
  391. }
  392. function tool_common_set($name, $value, $flag = ''){
  393. $conf_arr = tool_common_get();
  394. $setting = $conf_arr[$name];
  395. $value = (array)$value;
  396. $setting = (array)$setting;
  397. $value += $setting;
  398. $conf_arr[$name] = $value;
  399. save_syscache('milu_seotool_setting', $conf_arr);
  400. }
  401. function tool_common_get($key = ''){
  402. global $_G;
  403. loadcache('milu_seotool_setting');
  404. $setting = $_G['cache']['milu_seotool_setting'];
  405. $setting = dstripslashes($setting);
  406. $setting = $key ? $setting[$key] : $setting;
  407. return $setting;
  408. }
  409. function get_flash_obj($args = array()){
  410. global $_G;
  411. $set = st_get_pluin_set();
  412. $palette = $set['palette'] ? $set['palette'] : 1;
  413. include_once(PLUGIN_DIR."/lib/MyFCPHPClassCharts/class/FusionCharts_Gen.php");
  414. $args['flash_type'] = $args['flash_type'] ? $args['flash_type'] : 'MSLine';
  415. $args['width'] = $args['width'] ? $args['width'] : 500;
  416. $args['height'] = $args['height'] ? $args['height'] : 350;
  417. $FC = new FusionCharts($args['flash_type'], $args['width'], $args['height']);
  418. $FC->setSWFPath(PLUGIN_URL."lib/MyFCPHPClassCharts/FusionCharts/");
  419. $caption_title = $args['caption_title'];
  420. $decimals = isset($args['decimals']) ? $args['decimals'] : 0;
  421. $strParam = "caption=$args[title] ;subCaption=$caption_title;decimals=$decimals;lang=CN;yAxisName=$args[yAxisName];palette=$palette;showAboutMenuItem=0;pieSliceDepth=20;numberPrefix=;showToolTipShadow=1;baseFontSize=12;decimalPrecision=0;formatNumberScale=0;showNames=1";
  422. $FC->setChartParams($strParam);
  423. return $FC;
  424. }
  425. function st_stripslashes($data){
  426. if(DISCUZ_VERSION == 'X2') return $data;
  427. return dstripslashes($data);
  428. }
  429. function st_addslashes($data){
  430. if(DISCUZ_VERSION != 'X2') return $data;
  431. return daddslashes($data);
  432. }
  433. function stlang($name, $val_arr = array()){
  434. return lang('plugin/milu_seotool', $name, $val_arr);
  435. }
  436. function list_data_format($data, $field_arr = array(), $in = 'GBK', $out = ''){
  437. if(!$data || !is_array($data)) return $data;
  438. $out = $out ? $out : CHARSET;
  439. $in = strtoupper($in);
  440. $out = strtoupper($out);
  441. if($in == $out) return $data;
  442. foreach($data as $k => $v){
  443. if(is_array($v)){
  444. foreach($v as $k2 => $v2){
  445. $data[$k][$k2] = (!$field_arr || ($field_arr && in_array($k2, $field_arr))) && !is_array($v2) ? st_str_iconv($v2, $in) : $v2;
  446. }
  447. }else{
  448. $data[$k] = st_str_iconv($v, $in);
  449. }
  450. }
  451. return $data;
  452. }
  453. function s_s($name = 'default') {
  454. global $ss_timing_start_times;
  455. $ss_timing_start_times[$name] = explode(' ', microtime());
  456. }
  457. function s_e($show=1,$name = 'default') {
  458. global $ss_timing_stop_times;
  459. $ss_timing_stop_times[$name] = explode(' ', microtime());
  460. if($show == 1){
  461. echo '<p>'.st_timing_current($name).'</p>';
  462. }else{
  463. return st_timing_current($name);
  464. }
  465. }
  466. function st_timing_current ($name = 'default') {
  467. global $ss_timing_start_times, $ss_timing_stop_times;
  468. if (!isset($ss_timing_start_times[$name])) {
  469. return 0;
  470. }
  471. if (!isset($ss_timing_stop_times[$name])) {
  472. $stop_time = explode(' ', microtime());
  473. } else {
  474. $stop_time = $ss_timing_stop_times[$name];
  475. }
  476. $current = $stop_time[1] - $ss_timing_start_times[$name][1];
  477. $current += $stop_time[0] - $ss_timing_start_times[$name][0];
  478. return $current;
  479. }
  480. function sload($name){
  481. $arr = explode(',', $name);
  482. $temp_arr = array();
  483. $pick_dir = DISCUZ_ROOT.'source/plugin/milu_seotool';
  484. foreach($arr as $k => $v){
  485. $temp_arr = explode(':', $v);
  486. $type = strtolower($temp_arr[0]);
  487. $name = $temp_arr[1];
  488. $func_file = $pick_dir.'/lib/function.'.$name.'.php';
  489. $class_file = $pick_dir.'/lib/'.$name.'.class.php';
  490. if( (!$type || $type == 'f')){//函数库
  491. require_once($func_file);
  492. }else if($type == 'c'){//类库
  493. require_once($class_file);
  494. }
  495. }
  496. }
  497. function st_format_url($url, $flag = 1, $iconv = 1){
  498. if($iconv == 1) $url = st_str_iconv($url);
  499. $url = trim($url);
  500. $url = stripslashes($url);
  501. $url = stripslashes($url);
  502. if(!$url || ($flag == 1 && $url == 'undefined')) return false;
  503. $url = str_replace(array('[[JK%', 'JK%]]', '[YH123', 'K_L123', 'K_R123', 'XH123', 'DY123', 'XG123', 'SY123'), array('<', '>', '"','(', ')', '*','\'', '\\'), $url);
  504. //if(strtoupper(substr(PHP_OS, 0, 3)) == 'WIN') {
  505. $url = str_replace("\r\n", "\r\m", $url);
  506. $url = str_replace("\n", "\r\n", $url);
  507. $url = str_replace("\r\m", "\r\n", $url);
  508. //}
  509. return $url;
  510. }
  511. function st_load_cache($key,$clearStaticKey = FALSE){
  512. require_once(PLUGIN_DIR.'/lib/cache.class.php');
  513. $cache = new serialize_cache();
  514. return $cache->get($key,$clearStaticKey);
  515. }
  516. function st_cache_data($key,$value,$ttl = 3600){
  517. if($ttl < 0 || $ttl == 0) return FALSE;
  518. require_once(PLUGIN_DIR.'/lib/cache.class.php');
  519. $cache = new serialize_cache();
  520. $value = is_array($value) ? $value : rawurlencode($value);
  521. $cache->set($key,$value,$ttl);
  522. }
  523. function st_cache_del($key){
  524. require_once(PLUGIN_DIR.'/lib/cache.class.php');
  525. $cache = new serialize_cache();
  526. $cache->delete($key);
  527. }
  528. function get_args_str($args){
  529. $str = '';
  530. foreach((array)$args as $k => $v){
  531. $str .= isset($v) ? '&'.$k.'='.$v : '';
  532. }
  533. return $str;
  534. }
  535. //获得每一日的时间范围 比如2010-12-29日的范围应该是2010-12-29 00:00:00到2010-12-29 23:59:59
  536. function st_dayRange($from_time,$end_time){
  537. $time_lang_arr = explode('|', stlang('time_str'));
  538. $y_f = date("Y", $from_time);
  539. $y_e = date("Y", $end_time);
  540. $m_f = date("m", $from_time);
  541. $m_e = date("m", $end_time);
  542. $d_f = date("d", $from_time);
  543. $d_e = date("d", $end_time);
  544. $day_bet = 3600*24;
  545. $from = $from_time;
  546. $end = $end_time;
  547. $from_time = strtotime($y_f."-".$m_f."-".$d_f." 00:00:00");//起始那天
  548. $end_time = strtotime($y_f."-".$m_f."-".$d_f." 23:59:59");//结束那天
  549. $bet_day = ($end-$from) / $day_bet;//相隔几天?
  550. $bet_day = round($bet_day, 0);
  551. for($i=1;$i<$bet_day+2;$i++){
  552. $hour[$i]["from"] = $from_time + $day_bet*($i-1);
  553. $hour[$i]["end"] = $end_time + $day_bet*($i-1);
  554. $m = date("m", $hour[$i]["end"]);
  555. $d = date("d", $hour[$i]["end"]);
  556. if($i==1 || (date("m", $hour[$i-1]["end"]) != date("m", $hour[$i]["end"]))){
  557. $show_name = $m.$time_lang_arr[1].$d.$time_lang_arr[2];
  558. }else{
  559. $show_name = $d.$time_lang_arr[2];
  560. }
  561. $hour[$i]["name"] = $show_name;
  562. }
  563. return $hour;
  564. }
  565. function st_striptext($document) {
  566. if (!$document) return $document;
  567. $search = array("'<script[^>]*?>.*?</script>'si", // strip out javascript
  568. "'<style[^>]*?>.*?</style>'si", //去掉css
  569. "'<!--.*?-->'si", //去掉注释
  570. "'<[\/\!]*?[^<>]*?>'si", // strip out html tags
  571. "'([\r\n])[\s]+'", // strip out white space
  572. "'&(quot|#34|#034|#x22);'i", // replace html entities
  573. "'&(amp|#38|#038|#x26);'i", // added hexadecimal values
  574. "'&(lt|#60|#060|#x3c);'i",
  575. "'&(nbsp|#160|#xa0);'i",
  576. "'&(gt|#62|#062|#x3e);'i",
  577. "'&(iexcl|#161);'i",
  578. "'&(cent|#162);'i",
  579. "'&(pound|#163);'i",
  580. "'&(copy|#169);'i",
  581. "'&(reg|#174);'i",
  582. "'&(deg|#176);'i",
  583. "'&(#39|#039|#x27);'",
  584. "'&(euro|#8364);'i", // europe
  585. "'&a(uml|UML);'", // german
  586. "'&o(uml|UML);'",
  587. "'&u(uml|UML);'",
  588. "'&A(uml|UML);'",
  589. "'&O(uml|UML);'",
  590. "'&U(uml|UML);'",
  591. "' '",
  592. "'&szlig;'i",
  593. );
  594. $replace = array( "",
  595. "",
  596. "",
  597. "",
  598. "\\1",
  599. "\"",
  600. "&",
  601. "<",
  602. ">",
  603. " ",
  604. chr(161),
  605. chr(162),
  606. chr(163),
  607. chr(169),
  608. chr(174),
  609. chr(176),
  610. chr(39),
  611. chr(128),
  612. "?",
  613. "?",
  614. "?",
  615. "?",
  616. "?",
  617. "?",
  618. "",
  619. "?",
  620. );
  621. $text = preg_replace($search,$replace,$document);
  622. return strip_tags($text);
  623. }
  624. function st_convertrule($rule) {
  625. $rule = dstripslashes($rule);
  626. $rule = preg_quote($rule, "/"); //转义正则表达式
  627. $rule = str_replace('\*', '.*?', $rule);
  628. $rule = str_replace("\(.*?\)", '(.*?)', $rule);
  629. //$rule = str_replace('\|', '|', $rule);
  630. return $rule;
  631. }
  632. function st_get_host_info($gurl){
  633. $gurl = preg_replace("/^http:\/\//i", "", trim($gurl));
  634. $garr['host'] = preg_replace("/\/(.*)$/i", "", $gurl);
  635. $garr['query'] = "/".preg_replace("/^([^\/]*)\//i", "", $gurl);
  636. return $garr;
  637. }
  638. ?>