query("update {$tablepre}xna_site set uptime='$uptime' WHERE siteid='$sid'"); $siterow = $db->fetch_one_array("SELECT siteid,uid,site_title,rss_cate,rss_url,site_count FROM {$tablepre}xna_site WHERE siteid='$sid'"); $cid = $siterow["rss_cate"]; $uid = $siterow["uid"]; $rss_limit= $siterow["site_count"]; $rssread = $options[collect]; if ($rssread == "magpierss") { include_once (_ROOT . "/include/magpierss/rss_fetch.inc"); define('MAGPIE_CACHE_DIR', _ROOT . '/cache/'); define('MAGPIE_OUTPUT_ENCODING', 'UTF-8'); If( remote_file_exists($siterow["rss_url"])==false){ echo ("" . _LANG_0307 . ""); return false; } else { $rss = fetch_rss($siterow["rss_url"]); } $cnum = $sum = 0; $num = 10; if ($num == 0) { echo "" . _LANG_0310 . ""; return false; } $ccnum = 0; foreach ($rss->items as $item) { if (empty($rss_limit)){ $ccnum++; }elseif ($ccnum > $rss_limit){ continue; }else{ $ccnum++; } $val[feed_url] = $item["link"]; $val[feed_url_hash] = sha1($item["link"]); $val[siteid] = $siterow[siteid]; $val[site_name] = $siterow[site_title]; $addtime = $item['dc']['date'] ? $item['dc']['date'] : ($item['published'] ? $item['published'] : $item['pubdate']); $content = $item['atom_content'] ? $item['atom_content'] : $item['description']; $val[addtime] = $addtime = date("Y-m-d H:i:s", strtotime($addtime)); $cnum=$db->fetch_one_array("SELECT feed_url_hash FROM {$tablepre}xna_feed WHERE feed_url_hash = '$val[feed_url_hash]' "); if ($cnum > 0) continue; $val[feed_title] = addslashes($item["title"]); $row=$db->fetch_one_array("SELECT count(*) as sum,feedid FROM {$tablepre}xna_feed WHERE feed_title='" . $val[feed_title] . "' and siteid=" . $sid . " group by feedid"); $cnum=$row["sum"]; $rid = $row["feedid"]; $feed_title = clearHtml($val["feed_title"]); $feed_content = clearHtml($content); $feed_description = msubstr(strip_tags($feed_content),0,200)."..."; $addtime = strtotime($val["addtime"]); $feed_url = $val["feed_url"]; $feed_url_sum = $val["feed_url_hash"]; $feed_siteid = $val["siteid"]; $feed_site_name = $val["site_name"]; if ($cnum > "0"){ $db->query(" UPDATE {$tablepre}xna_feed SET cid='$cid', uid='$uid', feed_title='$feed_title' , feed_description='$feed_description', feed_content='$feed_content' , addtime='$addtime' , feed_url='$feed_url', feed_url_hash='$feed_url_sum', siteid='$feed_siteid', site_name='$feed_site_name' WHERE feedid=$rid"); echo "" . $siteid . ":" . $val[feed_title] . "" . _LANG_0314 . "
"; } if ($cnum == 0) { $db->query("INSERT INTO {$tablepre}xna_feed (cid,uid,feed_title,feed_description,feed_content,addtime,feed_url,feed_url_hash,siteid,site_name,state) VALUES ('$cid','$uid','$feed_title','$feed_description','$feed_content','$feed_ctime','$feed_url','$feed_url_sum','$feed_siteid','$feed_site_name','1')"); $sum = $sum + 1; } } } if ($rssread == "simplepie") { include_once (_ROOT . "/include/simplepie/simplepie.inc"); include_once (_ROOT . "/include/simplepie/idn/idna_convert.class.php"); $rss = new SimplePie(); $rss->set_cache_location(_ROOT . '/cache'); if (remote_file_exists($siterow["rss_url"]) == false) { echo ("" . _LANG_0307 . ""); return false; } else { $rss->set_feed_url($siterow["rss_url"]); } $rss->init(); //print_r($rss); $cnum = $sum = 0; $num = 10; if ($num == 0) { echo "" . _LANG_0310 . ""; return false; } $ccnum = 0; $items = $rss->get_items(); foreach($items as $rss){ if (empty($rss_limit)){ $ccnum++; }elseif ($ccnum > $rss_limit){ continue; }else{ $ccnum++; } $val[feed_url] = $rss->get_permalink(); $val[feed_url_hash] = md5($rss->get_permalink()); $val[siteid] = $siterow[siteid]; $val[site_name] = $siterow[site_title]; $addtime = $rss->get_date(); $content = $rss->get_content(); $val[addtime] = $ctime = date("Y-m-d H:i:s", strtotime($addtime)); $cnum=$db->fetch_one_array("SELECT feed_url_hash FROM {$tablepre}xna_feed WHERE feed_url_hash = '$val[feed_url_hash]' "); if ($cnum > 0) continue; $val[feed_title] = addslashes($rss->get_title()); //echo $val[feed_title]; $row=$db->fetch_one_array("SELECT count(*) as sum,feedid FROM {$tablepre}xna_feed WHERE feed_title='" . $val[feed_title] . "' and siteid=" . $sid . " group by feedid"); $cnum=$row["sum"]; $rid = $row["feedid"]; $feed_title = clearHtml($val["feed_title"]); $feed_content = clearHtml($content); $feed_description = msubstr(strip_tags($feed_content),0,200)."..."; $addtime = strtotime($val["addtime"]); $feed_url = $val["feed_url"]; $feed_url_sum = $val["feed_url_hash"]; $feed_siteid = $val["siteid"]; $feed_site_name = $val["site_name"]; if ($cnum > "0"){ $db->query(" UPDATE {$tablepre}xna_feed SET cid='$cid', uid='$uid', feed_title='$feed_title' , feed_description='$feed_description', feed_content='$feed_content' , addtime='$addtime' , feed_url='$feed_url', feed_url_hash='$feed_url_sum', siteid='$feed_siteid', site_name='$feed_site_name' WHERE feedid=$rid"); //echo "" . $siteid . ":" . $val[feed_title] . "" . _LANG_0314 . "
"; //continue; } if ($cnum == 0){ $db->query("INSERT INTO {$tablepre}xna_feed (cid,uid,feed_title,feed_description,feed_content,addtime,feed_url,feed_url_hash,siteid,site_name,state) VALUES ('$cid','$uid','$feed_title','$feed_description','$feed_content','$addtime','$feed_url','$feed_url_sum','$feed_siteid','$feed_site_name','1')"); $sum = $sum + 1; } } } $db->query("UPDATE {$tablepre}xna_site SET feed_count=feed_count+'$sum' WHERE siteid=$id"); $db->query("UPDATE {$tablepre}xna_statistics SET feed_count=feed_count+'$sum'"); statistics_recache(); sites_recache(); //redirect('' . $sum . ' ' . _LANG_0311 . '', 'index.php?job=site'); // echo "" . $sum . " " . _LANG_0311 . "
"; } /*function unescape($str){ $str = rawurldecode($str); preg_match_all("/(?:%u.{4})|&#x.{4};|&#\d+;|.+/U", $str, $r); $ar = $r[0]; foreach ($ar as $k => $v){ if (substr($v, 0, 2) == "%u") $ar[$k] = iconv("UCS-2", "GBK", pack("H4", substr($v, -4))); elseif (substr($v, 0, 3) == "&#x") $ar[$k] = iconv("UCS-2", "GBK", pack("H4", substr($v, 3, -1))); elseif (substr($v, 0, 2) == "&#") { $ar[$k] = iconv("UCS-2", "GBK", pack("n", substr($v, 2, -1))); } } return join("", $ar); }*/ function clearHtml($document){ $search = array( "/onload\=([\"|\'|\\\"|\\\']*)([^\"\']+)([\"|\'|\\\"|\\\']*)/si", "/(\]*href\=[\"|\'|\\\"|\\\']*)([^\"\'\s\>\\]+)([\"|\'|\\\"|\\\']*)([^\<\>]*\>)(.*?)\<\/a\>/si",//a tag "/(\]*)(src)(\=[\"|\'|\\\"|\\\']*)([^\"\'\s\>\\]+)([\"|\'|\\\"|\\\']*)([^\<\>]*)(\>)/si",//img tag "'[^>]*?>.*?/Feedsky flare -->'si", //Feedsky ad "']*)>'si", "']*)>'si", "'

'si", "']*?>.*?'si", // strip out javascript "'<[\/\!]*?[^<>]*?>'si", // strip out html tags "'([\r\n])[\s]+'", // strip out white space "'&(quot|#34|#034|#x22);'i", // replace html entities "'&(amp|#38|#038|#x26);'i", // added hexadecimal values "'&(lt|#60|#060|#x3c);'i", "'&(gt|#62|#062|#x3e);'i", "'&(nbsp|#160|#xa0);'i", "'&(iexcl|#161);'i", "'&(cent|#162);'i", "'&(pound|#163);'i", "'&(copy|#169);'i", "'&(reg|#174);'i", "'&(deg|#176);'i", "'&(#39|#039|#x27);'", "'&(euro|#8364);'i", // europe "'&a(uml|UML);'", // german "'&o(uml|UML);'", "'&u(uml|UML);'", "'&A(uml|UML);'", "'&O(uml|UML);'", "'&U(uml|UML);'", "'ß'i", "'@@@'i", "'###'i", "/'/i", ); $replace = array( "", '@@@a href="\\2" rel="external"###\\4@@@/a###', '@@@img src="\\4" alt="photo"###', "", '@@@br /###', '@@@p###', '@@@/p###', "", "", "\\1", "\"", "&", "<", ">", " ", chr(161), chr(162), chr(163), chr(169), chr(174), chr(176), chr(39), chr(128), "", "", "", "", "", "", "", "<", ">", "", ); $text = preg_replace($search,$replace,$document); return $text; } function remote_copy($src_file, $dst_file){ $fd_src = @fopen($src_file, "r"); if (!$fd_src) return false; $fd_dst = fopen($dst_file, "wb+"); if (!$fd_dst) { fclose($fd_src); return false; } while (!feof($fd_src)) { $buffer = fread($fd_src, 1024); fwrite($fd_dst, $buffer); } fclose($fd_src); fclose($fd_dst); return true; } /*function RunTime_Begin(){ global $_starttime; $_nowtime = explode(" ", microtime()); $_starttime = $_nowtime[1] + $_nowtime[0]; } function RunTime_End(){ global $_starttime; $_nowtime = explode(" ", microtime()); $_endtime = $_nowtime[1] + $_nowtime[0]; $_totaltime = $_endtime - $_starttime; return $_totaltime; }*/ /*function c_iconv($s_code, $t_code, $str){ if (function_exists("iconv")){ $s_code = str_replace("UTF8", "UTF-8", $s_code); $t_code = str_replace("UTF8", "UTF-8", $t_code); $str = iconv($s_code, $t_code, $str); if ($s_code == "UTF-8") $str = unescape($str); } else { $conv = new ChangeCode($s_code, $t_code); $str = $conv->ConvertIt($str); } return $str; }*/ function remote_file_exists($url_file){ $url_file = trim($url_file); if (empty($url_file)){ return false; } $url_arr = parse_url($url_file); if (!is_array($url_arr) || empty($url_arr)){ return false; } $host = $url_arr['host']; $path = $url_arr['path'] . "?" . $url_arr['query']; $port = isset($url_arr['port']) ? $url_arr['port'] : "80"; $fp = fsockopen($host, $port, $err_no, $err_str, 30); if (!$fp) { return false; } $request_str = "GET " . $path . " HTTP/1.1\r\n"; $request_str .= "Host: " . $host . "\r\n"; $request_str .= "Connection: Close\r\n\r\n"; fwrite($fp, $request_str); $first_header = fgets($fp, 1024); fclose($fp); if (trim($first_header) == "") { return false; } if (!preg_match("/200/", $first_header)) { return false; } return true; } function jsread($var){ $js = $var["js"]; echo $js; $content = file_get_contents($js); $sp = array("document.writeln(\"","\");","document.write(\""); $rp = array("","",""); $content = stripslashes(str_replace($sp,$rp,$content)); return $content; } function DateDiff($interval, $date1, $date2) { $time_difference = $date2 - $date1; switch ($interval) { case "w": $retval = bcdiv($time_difference, 604800); break; case "d": $retval = bcdiv($time_difference, 86400); break; case "h": $retval = bcdiv($time_difference, 3600); break; case "n": $retval = bcdiv($time_difference, 60); break; case "s": $retval = $time_difference; break; } return $retval; } function message($msg,$returnurl='javascript:history.go(-1);',$min='3') { global $options, $stylevar; include template("message", _ROOT ."/template/digg/"); exit; } //页面输出 function PageEnd() { global $options; $output = str_replace(array('',''),array('',''),ob_get_contents()); ob_end_clean(); $options['gzipcompress'] ? ob_start('ob_gzhandler') : ob_start(); if ($options['rewrite_enable']) { require_once(_ROOT.'include/rewrite.inc.php'); $searcharray = array ( "/\/e", "/\/e", "/\/e", "/\/e", "/\/e", "/\/e", "/\/e", ); $replacearray = array ( "rewrite_tags('\\1', '\\2', '\\3', '\\4', '\\6')", "rewrite_category('\\1', '\\2', '\\3', '\\4', '\\6')", "rewrite_date('\\1', '\\2', '\\3', '\\4', '\\5', '\\7')", "rewrite_archives('\\1', '\\2', '\\4', '\\6')", "rewrite_show('\\1', '\\2', '\\3', '\\4', '\\6', '\\8')", "rewrite_page('\\1', '\\2', '\\4', '\\6')", "rewrite_newcm('\\1', '\\2', '\\3','\\4', '\\6')", ); $output = preg_replace($searcharray, $replacearray, $output); } echo $output; exit; } function multi($num, $perpage, $curpage, $mpurl) { $multipage = ''; $mpurl .= strpos($mpurl, '?') ? '&' : '?'; if($num > $perpage) { $page = 10; $offset = 5; $pages = @ceil($num / $perpage); if($page > $pages) { $FROM = 1; $to = $pages; } else { $FROM = $curpage - $offset; $to = $curpage + $page - $offset - 1; if($FROM < 1) { $to = $curpage + 1 - $FROM; $FROM = 1; if(($to - $FROM) < $page && ($to - $FROM) < $pages) { $to = $page; } } elseif($to > $pages) { $FROM = $curpage - $pages + $to; $to = $pages; if(($to - $FROM) < $page && ($to - $FROM) < $pages) { $FROM = $pages - $page + 1; } } } $multipage = ($curpage - $offset > 1 && $pages > $page ? '«' : '').($curpage > 1 ? '' : ''); for($i = $FROM; $i <= $to; $i++) { $multipage .= $i == $curpage ? ''.$i.'' : ''.$i.''; } $multipage .= ($curpage < $pages ? '' : '').($to < $pages ? '»' : ''); $multipage = $multipage ? '
Records:'.$num.''.$multipage.'
' : ''; } return $multipage; } function template($tplfile, $tplpath = '', $tplcachepath = '', $userpack = '', $userpackpath = '', $cachelimit = '') { $tplpath = $tplpath != '' ? $tplpath : (defined("_TPLPath_") ? _TPLPath_ : ''); $tplfile = $tplpath.$tplfile.'.html'; $tplcachelimit = 1800 ? _TPLCacheLimit_ : 0; $cachefile = ($tplcachepath !== '' ? $tplcachepath : (defined("_TPLCachePath_") ? _TPLCachePath_ : '')).str_replace(array('/', '.'), '_', $tplfile.($userpack ? '.'.($userpackpath ? $userpackpath : '').$userpack : '')).'.php'; if ($tplcachelimit || !($cachetime = @filemtime($cachefile))) { if (time() - $cachetime > $tplcachezlimit || @filemtime($tplfile) > $cachetime) { $nemotpl = new templates; $nemotpl->userpack = $userpack ? ($userpackpath ? $userpackpath : $tplpath).$userpack.'.php' : ''; $nemotpl->template = file_get_contents($tplfile); $nemotpl->tplpath = $tplpath; $nemotpl->cachefile = $cachefile; $nemotpl->extraparms = ',\\\''.$tplpath.'\\\',\\\''.$tplcachepath.'\\\',\\\''.$userpack.'\\\',\\\''.$userpackpath.'\\\''; return $nemotpl->compile(); } } return $cachefile; } // 后台管理记录 function getlog() { global $timestamp, $onlineip, $ixnauser; if ($_POST['action']) { $action = $_POST['action']; $script = str_replace('job=', '', $_SERVER['QUERY_STRING']); writelog(_ROOT.'cache/log/adminlog.php', "\t$timestamp\t".htmlspecialchars($ixnauser)."\t$onlineip\t".htmlspecialchars(trim($action))."\t".htmlspecialchars(trim($script))."\n"); } } // 写日至 function writelog($filename,$filedata) { @$fp=fopen($filename, 'a'); @flock($fp, 2); @fwrite($fp, $filedata); @fclose($fp); @chmod($filename, 0777); } // 连接多个ID function implode_ids($array){ $ids = $comma = ''; if (is_array($array) && count($array)){ foreach($array as $id) { $ids .= "$comma'".intval($id)."'"; $comma = ', '; } } return $ids; } // 转换时间单位:秒 to XXX function format_timespan($seconds = '') { if ($seconds == '') $seconds = 1; $str = ''; $years = floor($seconds / 31536000); if ($years > 0) { $str .= $years.' 年, '; } $seconds -= $years * 31536000; $months = floor($seconds / 2628000); if ($years > 0 || $months > 0) { if ($months > 0) { $str .= $months.' 月, '; } $seconds -= $months * 2628000; } $weeks = floor($seconds / 604800); if ($years > 0 || $months > 0 || $weeks > 0) { if ($weeks > 0) { $str .= $weeks.' 周, '; } $seconds -= $weeks * 604800; } $days = floor($seconds / 86400); if ($months > 0 || $weeks > 0 || $days > 0) { if ($days > 0) { $str .= $days.' 天, '; } $seconds -= $days * 86400; } $hours = floor($seconds / 3600); if ($days > 0 || $hours > 0) { if ($hours > 0) { $str .= $hours.' 小时, '; } $seconds -= $hours * 3600; } $minutes = floor($seconds / 60); if ($days > 0 || $hours > 0 || $minutes > 0) { if ($minutes > 0) { $str .= $minutes.' 分钟, '; } $seconds -= $minutes * 60; } if ($str == '') { $str .= $seconds.' 秒, '; } $str = substr(trim($str), 0, -1); return $str; } // 获取数据库大小单位 function get_real_size($size) { $kb = 1024; // Kilobyte $mb = 1024 * $kb; // Megabyte $gb = 1024 * $mb; // Gigabyte $tb = 1024 * $gb; // Terabyte if($size < $kb) { return $size.' Byte'; }else if($size < $mb) { return round($size/$kb,2).' KB'; }else if($size < $gb) { return round($size/$mb,2).' MB'; }else if($size < $tb) { return round($size/$gb,2).' GB'; }else { return round($size/$tb,2).' TB'; } } // 获取管理员散列 function getadminhash($uid,$username,$password,$count) { global $timestamp; return substr(md5(substr($timestamp, 0, -7).$username.$uid.$password.$count), 8, 8); } // 获取管理员的信息 function getadmininfo($password) { return md5($_SERVER["HTTP_USER_AGENT"].$password); } function getextension($filename) { $pathinfo = pathinfo($filename); return $pathinfo['extension']; } function ifselected($var, $out) { global ${$out.'_Y'},${$out.'_N'}; if($var) { ${$out.'_Y'} = 'selected'; } else { ${$out.'_N'} = 'selected'; } } // 检查链接URL是否符合逻辑 function checkurl($url,$allownull=1) { if($url) { if (isemail($url)) { return false; } else { if (!preg_match("#^(http|news|https|ftp|ed2k|rtsp|mms)://#", $url)) { $result .= '网站URL错误.
'; return $result; } $key = array("\\",' ',"'",'"','*',',','<','>',"\r","\t","\n",'(',')','+',';'); foreach($key as $value){ if (strpos($url,$value) !== false){ $result .= '网站URL错误.
'; return $result; } } } } else { if (!$allownull) { $result .= '网站URL不允许为空.
'; return $result; } } } //判断是否为邮件地址 function isemail($email) { return strlen($email) > 6 && preg_match("/^[\w\-\.]+@[\w\-\.]+(\.\w+)+$/", $email); } function upfile($source, $target) { // 如果一种函数上传失败,还可以用其他函数上传 if (function_exists('move_uploaded_file') && @move_uploaded_file($source, $target)) { @chmod($target, 0666); return $target; } elseif (@copy($source, $target)) { @chmod($target, 0666); return $target; } elseif (@is_readable($source)) { if ($fp = @fopen($source,'rb')) { @flock($fp,2); $filedata = @fread($fp,@filesize($source)); @fclose($fp); } if ($fp = @fopen($target, 'wb')) { @flock($fp, 2); @fwrite($fp, $filedata); @fclose($fp); @chmod ($target, 0666); return $target; } else { return false; } } } // 操作提示页面 function redirect($msg, $url = 'javascript:history.go(-1);', $min='2') { include template("redirect", _ROOT . "/template/admin/"); exit; } // 后台登陆入口页面 function loginpage(){ global $ixnauid, $ixnauser, $ixnagroup, $IXNA_VERSION, $IXNA_RELEASE; setcookie('ixnaadmin', ''); cpheader(0); include template("login", _ROOT . "/template/admin/"); exit; } // 控制面板各页面页眉 function cpheader($shownav = 1) { global $options,$adminitem,$ixnauser,$job,$IXNA_VERSION, $IXNA_RELEASE, $navlink_L, $userinfo; include template("header", _ROOT . "/template/admin/"); } // 检查权限 function permission() { global $ixnagroup; if ($ixnagroup != 1) { redirect('你没有此功能的管理权限','index.php'); } } // 检查权限 function userission() { global $ixnagroup,$ixnauid; if (!$ixnagroup || !$ixnauid) { redirect('你没有此功能的管理权限','../index.php'); } } // 后台登录记录 function loginresult($result) { global $timestamp,$onlineip,$ixnauser; writelog(_ROOT.'cache/log/loginlog.php', "\t$ixnauser\t$timestamp\t$onlineip\t$result\n"); } // 重建所有缓存 function restats() { links_recache(); //newcomments_recache(); settings_recache(); categories_recache(); statistics_recache(); } ?>