<?php
@header("Expires: -1");
@header("Cache-Control: no-store, private, post-check=0, pre-check=0, max-age=0", FALSE);
@header("Pragma: no-cache");
header("Content-type: image/jpeg");
header("Content-type: image/gif");
header("Content-type: image/bmp");
header("Content-type: image/png");
define('THIS_SCRIPT', 'gather');
include_once 'global.php';
include_once CACHE_PATH.'board/board_all.php';
include_once CACHE_PATH.'forum_setting.php';
include_once INC_PATH.'filehandle.misc.php';
include_once 'inc/httpdown.class.php';
$lang = load_lang($lang, 'gather' );
checklogin();
header("content-Type: text/html; charset=".$charset);
head();
if ( strpos($sysinfo['flag'],'47,') === false ){
	show_msg($lang['readme_tit'],$lang['error.str1'],0,'','','','');
	exit;
}
PageLoad($_FILES['inportrule'],$_POST['MAX_FILE_SIZE']);
footer();
function add_note(){//添加节点;
	global $lang,$dv,$db,$uploaddir;
	$note_name=$_POST['note_name'];
	$bordertype=$_POST['bordertype'];
	$from_url=$_POST['from_url'];
	$rulelist=read_gather_rulefile();
	$nowdate=time();
	if(empty($rulelist)){
		$sql=$db->query("INSERT INTO {$dv}note_info (note_name,bordertype,from_url,note_datetime) values ('".$note_name."',".$bordertype.",'".$from_url."','".$nowdate."')");
		if($sql){
			show_msg($lang['sys.info'],$lang['gather.info3'],1,'','','gather.php?action=manage',$lang['cmdback']);
			exit;
		}
	}else{
		$sql=$db->query("INSERT INTO {$dv}note_info ( note_name,bordertype,from_url,article_title,article_from,article_write,article_time,article_body,color_style,board_setup,includeurl,title_inhere_swap,body_inhere_swap,script_leach,coding,down_pic,news_time,keyword,page_class,pagevar,sp_page,note_datetime) values ('".$note_name."',".$rulelist[1].",'".$rulelist[2]."','".$rulelist[3]."','".$rulelist[4]."','".$rulelist[5]."','".$rulelist[6]."','".$rulelist[7]."',".$rulelist[8].",".$rulelist[9].",'".$rulelist[10]."','".$rulelist[11]."','".$rulelist[12]."','".$rulelist[13]."',".$rulelist[14].",".$rulelist[15].",".$rulelist[16].",'".$rulelist[17]."','".$rulelist[18]."','".$rulelist[19]."','".$rulelist[20]."',".$nowdate.")");
		$filename='../'.$uploaddir.'/upimg/'.$lang['gather_rulefile'];
		@chmod($filename,0777);
		@unlink($filename);
		if($sql){
			show_msg($lang['sys.info'],$lang['gather.info3'],1,'','','gather.php?action=manage',$lang['cmdback']);
			exit;
		}
	}
}
function note_list(){//列表所有节点;
	global $dv,$db,$note_arr,$_DCACHE,$page_size,$page,$total,$page_count,$offset,$p;
	$note_arr=array();
	$total=$db->scalar("SELECT count(1) FROM {$dv}note_info");
	page_info(20);
	$sql=$db->query("SELECT id,note_name,coding,bordertype,from_url,last_gather_date,note_datetime,down_pic,web_num,sp_page,article_title,article_from,article_write,article_time,article_body,gatherid,includeurl,pagevar,color_style,board_setup,title_inhere_swap,body_inhere_swap,script_leach,news_time,keyword,page_class FROM {$dv}note_info order by id",array('absolutePage'=>$offset,'pageSize'=>$page_size));
	while ($arr=$db->fetch_array($sql)){
		$note_arr[]=$arr;
	}
}
function rejigger_curr_node_list(){//读出当前节点信息进行修改;
	global $lang,$dv,$db,$note_arr;
	$note_arr=array();
	$id=$_GET['id'];
	if($id==""){
		show_msg($lang['sys.info'],$lang['gather.info9'],0,'','','gather.php?action=manage',$lang['cmdback']);
		exit;
	}
	else{
		$sql=$db->query("SELECT id,note_name,coding,bordertype,from_url,last_gather_date,note_datetime,down_pic,web_num,sp_page,article_title,article_from,article_write,article_time,article_body,gatherid,includeurl,pagevar,color_style,board_setup,title_inhere_swap,body_inhere_swap,script_leach,news_time,keyword,page_class FROM {$dv}note_info WHERE id=".intval($id)."");
		while($arr=$db->fetch_array($sql)){
			$note_arr[]=$arr;
		}
	}
}
function rejigger_curr_node($sort){//修改当前节点信息;
	global $lang,$dv,$db,$id;
	$id=$_GET['id'];
	//basic;
	$note_name=$_POST['note_name'];
	$bordertype=$_POST['bordertype'];
	$from_url=$_POST['from_url'];
	//rule;
	$article_title_start=$_POST['article_title_start'];
	$article_title_end=$_POST['article_title_end'];
	$article_from_start=$_POST['article_from_start'];
	$article_from_end=$_POST['article_from_end'];
	$article_write_start=$_POST['article_write_start'];
	$article_write_end=$_POST['article_write_end'];
	$article_time_start=$_POST['article_time_start'];
	$article_time_end=$_POST['article_time_end'];
	$article_body_start=$_POST['article_body_start'];
	$article_body_end=$_POST['article_body_end'];
	$article_title=$article_title_start.'|||'.$article_title_end;
	$article_from=$article_from_start.'|||'.$article_from_end;
	$article_write=$article_write_start.'|||'.$article_write_end;
	$article_time=$article_time_start.'|||'.$article_time_end;
	$article_body=$article_body_start.'|||'.$article_body_end;
	//leach;
	$color_style=$_POST['color_style'];//配色风格
	$board_setup=$_POST['board_setup'];//board_setup
	$include_url=$_POST['include_url'];
	$no_include_url=$_POST['no_include_url'];
	$includeurl=$include_url."|||".$no_include_url;
	$inhere_title=$_POST['inhere_title'];//原新闻标题
	$swap_title=$_POST['swap_title'];//新新闻标题
	$title_inhere_swap=$inhere_title.'|||'.$swap_title;
	$inhere_body=$_POST['inhere_body'];//原新闻内容
	$inhere_bodyarr= preg_split('/\r\n|\n/i',$inhere_body);
	foreach($inhere_bodyarr as $inhere_bodylist){
		$tmpinhere_body.=$inhere_bodylist.'@@@';
	}
	$tmpinhere_body=substr($tmpinhere_body,0,-3);
	$swap_body=$_POST['swap_body'];//新新闻内容
	$swap_bodyarr= preg_split('/\r\n|\n/i',$swap_body);
	foreach($swap_bodyarr as $swap_bodylist){
		$tmpswap_body.=$swap_bodylist.'@@@';
	}
	$tmpswap_body=substr($tmpswap_body,0,-3);
	if(count($inhere_bodyarr)!=count($swap_bodyarr)){
		show_msg($lang['sys.info'],$lang['gather.info220'],0,'','',$geturl,$lang['cmdback']);
		exit;
	}
	$body_inhere_swap=$tmpinhere_body.'|||'.$tmpswap_body;
	$script_iframe=$_POST['script_iframe'];
	$script_object=$_POST['script_object'];
	$script_script=$_POST['script_script'];
	$script_div=$_POST['script_div'];
	$script_class=$_POST['script_class'];
	$script_table=$_POST['script_table'];
	$script_tr=$_POST['script_tr'];
	$script_span=$_POST['script_span'];
	$script_img=$_POST['script_img'];
	$script_font=$_POST['script_font'];
	$script_a=$_POST['script_a'];
	$script_html=$_POST['script_html'];
	$script_td=$_POST['script_td'];
	$script_p=$_POST['script_p'];
	$script_br=$_POST['script_br'];
	$script_leach=$script_iframe.'|||'.$script_object.'|||'.$script_script.'|||'.$script_div.'|||'.$script_class.'|||'.$script_table.'|||'.$script_tr.'|||'.$script_span.'|||'.$script_img.'|||'.$script_font.'|||'.$script_a.'|||'.$script_html.'|||'.$script_td.'|||'.$script_p.'|||'.$script_br;
	//other;
	$coding=$_POST['coding'];
	$down_pic=$_POST['down_pic'];
	$news_time=$_POST['news_time'];//信息录入时间
	$keyword=$_POST['keyword'];
	$page_class=$_POST['page_class'];
	$pagestart=$_POST['pagestart'];
	$pageend=$_POST['pageend'];
	$sp_page=$_POST['sp_page'];
	$pagevar=$pagestart."|||".$pageend;
	$geturl=$_SERVER['HTTP_REFERER'];
	if(empty($id)){
		show_msg($lang['sys.info'],$lang['gather.info9'],0,'','',$geturl,$lang['cmdback']);
		exit;
	}
	if($sort=="basic"){
		$sql=$db->query("UPDATE {$dv}note_info SET note_name='".$note_name."',bordertype=".$bordertype.",from_url='".$from_url."' where id=".$id."");
		if($sql){
			show_msg($lang['sys.info'],$lang['gather.info10'],1,'','',$geturl,$lang['cmdback']);
			exit;
		}
	}
	elseif($sort=="rule"){
		$sql=$db->query("UPDATE {$dv}note_info SET article_title='".$article_title."',article_from='".$article_from."',article_write='".$article_write."',article_time='".$article_time."',article_body='".$article_body."' where id=".$id."");
		if($sql){
			show_msg($lang['sys.info'],$lang['gather.info10'],1,'','',$geturl,$lang['cmdback']);
			exit;
		}
	}
	elseif($sort=="leach"){
		$sql=$db->query("UPDATE {$dv}note_info SET color_style=".$color_style.",board_setup=".$board_setup.",title_inhere_swap='".$title_inhere_swap."',body_inhere_swap='".$body_inhere_swap."',script_leach='".$script_leach."',includeurl='".$includeurl."' where id=".$id."");
		if($sql){
			show_msg($lang['sys.info'],$lang['gather.info10'],1,'','',$geturl,$lang['cmdback']);
			exit;
		}
	}
	elseif($sort=="other"){
		if($pagestart<>''){
			if($pageend=='' or $sp_page==''){
				show_msg($lang['sys.info'],$lang['gather.info139'],0,'','',$geturl,$lang['cmdback']);
				exit;
			}
		}
		elseif($pageend<>''){
			if($pagestart=='' or $sp_page==''){
				show_msg($lang['sys.info'],$lang['gather.info139'],0,'','',$geturl,$lang['cmdback']);
				exit;
			}
		}
		elseif($sp_page<>''){
			if($pagestart=='' or $pageend==''){
				show_msg($lang['sys.info'],$lang['gather.info139'],0,'','',$geturl,$lang['cmdback']);
				exit;
			}
		}
		$sql=$db->query("UPDATE {$dv}note_info SET coding=".$coding.",down_pic=".$down_pic.",sp_page='".$sp_page."',news_time=".$news_time.",keyword='".$keyword."',page_class=".$page_class.",pagevar='".$pagevar."' WHERE id=".$id."");
		if($sql){
			show_msg($lang['sys.info'],$lang['gather.info10'],1,'','',$geturl,$lang['cmdback']);
			exit;
		}
	}
}
function view_gather(){//采集当前节点;
	global $lang,$dv,$db,$note_info,$_DCACHE,$note_link,$bordertype,$gatheridarr,$notename,$rule_expression,$get_serverurl,$gatherurls;
	global $pre,$page_size,$page,$total,$page_count,$offset,$p,$start,$next,$ten_page;
	global $pagevarlist_start,$pagevarlist_end,$full_url;
	$note_info=array();
	$note_link=array();
	$id=$_GET['id']?$_GET['id']:$_POST['id'];
	$id=intval($id);
	if($id==""){
		show_msg($lang['sys.info'],$lang['gather.info9'],0,'','','gather.php?action=manage',$lang['cmdback']);
		exit;
	}

	if($db->scalar("select count(1) from {$dv}gather_url where noteid=$id"))return true;
	ini_set('allow_url_fopen', 1);
	$sql=$db->query("SELECT id,note_name,coding,bordertype,from_url,last_gather_date,note_datetime,down_pic,web_num,sp_page,article_title,article_from,article_write,article_time,article_body,gatherid,includeurl,pagevar,color_style,board_setup,title_inhere_swap,body_inhere_swap,script_leach,news_time,keyword,page_class FROM {$dv}note_info WHERE id=".$id."");
	$arr=$db->fetch_array($sql);
	$get_server_url=explode('/',$arr['from_url']);
	if($arr['sp_page']<>'' and $arr['pagevar']<>''){
		$pagevarlist=explode('|||',$arr['pagevar']);
		$pagevarlist_start=$pagevarlist[0];
		$pagevarlist_end=$pagevarlist[1];
	}
	if($arr['includeurl']<>''){	//新闻网址是否包含;
		$includeurllist=explode('|||',$arr['includeurl']);
		if(!empty($includeurllist[0])){
			$includeurllist_yes=$includeurllist[0];
		}
		else{
			$includeurllist_yes='';
		}
		if(!empty($includeurllist[1])){
			$includeurllist_no=$includeurllist[1];
		}
		else{
			$includeurllist_no='';
		}
	}//新闻网址是否包含 end
	$url_count=count($get_server_url)-1;
	if(strpos($get_server_url[$url_count],'.php')!==false){
		for($i=2;$i<=$url_count-1;$i++){
			$get_serverurl.='http://'.$get_server_url[$i]."/";
		}
	}elseif(strpos($get_server_url[$url_count],'.asp')!==false){
		for($i=2;$i<=$url_count-1;$i++){
			$get_serverurl.='http://'.$get_server_url[$i]."/";
		}
	}elseif(strpos($get_server_url[$url_count],'.html')!==false){
		for($i=2;$i<=$url_count-1;$i++){
			$get_serverurl.='http://'.$get_server_url[$i]."/";
		}
	}
	elseif(strpos($get_server_url[$url_count],'.shtml')!==false){
		for($i=2;$i<=$url_count-1;$i++){
			$get_serverurl.='http://'.$get_server_url[$i]."/";
		}
	}
	elseif(strpos($get_server_url[$url_count],'.htm')!==false){
		for($i=2;$i<=$url_count-1;$i++){
			$get_serverurl.='http://'.$get_server_url[$i]."/";
		}
	}
	else{
		$get_serverurl="";
	}
	$notename=$arr['note_name'];
	$gatheridarr=$arr['gatherid'];
	$arr['bordertype']=intval($arr['bordertype']);
	$board_type=&$_DCACHE['all_forums'][$arr['bordertype']];
	$bordertype=intval($board_type['boardtype']);
	$rule_expre='#<a(?:.*?)href\s*=\s*(?:["\'\s]?)([^"\'\s]+)(?:.*?)>(.*?)</a>#is';
	$j=0;
	//在URL中找到分页的变量;
	if($arr['page_class']==1) {
		if($arr['pagevar']<>'' and $arr['sp_page']<>''){
			if(strpos($arr['from_url'],$arr['sp_page'])!==false) {
				$page_explode=explode($arr['sp_page']."=",$arr['from_url']);
				if(strpos($page_explode[1],'&')!==false){
					$page_var=explode('&',$page_explode[1]);
					for ($i=1;$i<count($page_var);$i++) {
						$para_other.=$page_var[$i].'&';
					}
					$para_other=substr($para_other,0,-1);
				}
				if(strpos($page_explode[0],'?')!==false && strpos($page_explode[0],'&')===false && strpos($page_explode[1],'&')===false){//URL参数中只有分页变量;
					$full_url=$page_explode[0].$arr['sp_page']."="."vari";
				}
				elseif(strpos($page_explode[0],'?')!==false && strpos($page_explode[0],'&')===false && strpos($page_explode[1],'&')!==false){
					$full_url=$page_explode[0].$arr['sp_page']."="."vari"."&".$para_other;
				}
				elseif(strpos($page_explode[0],'?')!==false && strpos($page_explode[0],'&')!==false && strpos($page_explode[1],'&')===false){
					$full_url=$page_explode[0].$arr['sp_page']."="."vari";
				}
				elseif(strpos($page_explode[0],'?')!==false && strpos($page_explode[0],'&')!==false && strpos($page_explode[1],'&')!==false){
					$full_url=$page_explode[0].$arr['sp_page']."="."vari"."&".$para_other;
				}
			}else{
				$full_url=$arr['from_url']."&".$arr['sp_page']."="."vari";
			}
			for ($n=$pagevarlist_start;$n<=$pagevarlist_end;$n++) {
				$fullurl=str_replace('vari',$n,$full_url);
				$filecontents.=@getfileurl($fullurl);
			}
		}else{
			$filecontents = @getfileurl($arr['from_url']);
		}
	}else{
		if($arr['sp_page']<>'' and $arr['pagevar']<>''){
			$fullurl=$arr['from_url'];
			$urlfilename=basename($fullurl);
			$ext=explode('.',$urlfilename);
			$fullurlstr=str_replace($urlfilename,'',$fullurl);
			for ($m=$pagevarlist_start;$m<=$pagevarlist_end;$m++) {
				$fullurl=$fullurlstr.$arr['sp_page'].$m.'.'.$ext[1];
				$filecontents.=@getfileurl($fullurl);
			}
		}
		else{
			$filecontents = @getfileurl($arr['from_url']);
		}
		//$filecontents = @getfileurl($arr['from_url']);
	}//在URL中找到分页的变量 end
    if(!$filecontents)return false;
	if (preg_match_all($rule_expre,$filecontents, $matches)) {//分析所有URL，并获得需要的连接;
		$count = count($matches[0]);
		for ($i = 0 ; $i < $count ; $i++ ) {
			if(!empty($includeurllist_yes) and empty($includeurllist_no)){//包含网址
				if(strpos($matches[1][$i],strtolower($includeurllist_yes))===false){
					continue;
				}elseif($matches[2][$i]=="" or empty($matches[2][$i])){
					continue;
				}elseif(strlen(strip_tags($matches[2][$i]))<10){
					continue;
				}elseif(preg_match_all('#[0-9]{4}-[0-9]{1,2}-[0-9]{1,2} [0-9]{1,2}:[0-9]{1,2}:[0-9]{1,2}#is',$matches[2][$i],$matche)){
					continue;
				}else{
					$note_info[$j]=$matches[2][$i];
					$link=explode(" target",$matches[1][$i]);
					$note_link[$j]=fillurl($arr['from_url'],$matches[1][$i]);
					$j++;
				}
			}elseif(empty($includeurllist_yes) and !empty($includeurllist_no)){//不包含网址
				if(strpos($matches[1][$i],strtolower($includeurllist_no))!==false){
					continue;
				}elseif($matches[2][$i]=="" or empty($matches[2][$i])){
					continue;
				}elseif(strlen(strip_tags($matches[2][$i]))<10){
					continue;
				}elseif(preg_match_all('#[0-9]{4}-[0-9]{1,2}-[0-9]{1,2} [0-9]{1,2}:[0-9]{1,2}:[0-9]{1,2}#is',$matches[2][$i],$matche)){
					continue;
				}else{
					$note_info[$j]=$matches[2][$i];
					$link=explode(" target",$matches[1][$i]);
					$note_link[$j]=fillurl($arr['from_url'],$matches[1][$i]);
					$j++;
				}
			}elseif(!empty($includeurllist_yes) and !empty($includeurllist_no)){//既包含网址又不包含;
				if(strpos($matches[1][$i],strtolower($includeurllist_yes))===false and strpos($matches[1][$i],strtolower($includeurllist_no))!==false){
					continue;
				}elseif($matches[2][$i]=="" or empty($matches[2][$i])){
					continue;
				}elseif(strlen(strip_tags($matches[2][$i]))<10){
					continue;
				}
				elseif(preg_match_all('#[0-9]{4}-[0-9]{1,2}-[0-9]{1,2} [0-9]{1,2}:[0-9]{1,2}:[0-9]{1,2}#is',$matches[2][$i],$matche)){
					continue;
				}else{
					$note_info[$j]=$matches[2][$i];
					$link=explode(" target",$matches[1][$i]);
					$note_link[$j]=fillurl($arr['from_url'],$matches[1][$i]);
					$j++;
				}
			}else{
				if(empty($matches[2][$i])){
					continue;
				}elseif(strlen(strip_tags($matches[2][$i]))<10){
					continue;
				}elseif(preg_match_all('#[0-9]{4}-[0-9]{1,2}-[0-9]{1,2} [0-9]{1,2}:[0-9]{1,2}:[0-9]{1,2}#is',$matches[2][$i],$matche)){
					continue;
				}else{
					$note_info[$j]=$matches[2][$i];
					$link=explode(" target",$matches[1][$i]);
					$note_link[$j]=fillurl($arr['from_url'],$matches[1][$i]);
					$j++;

				}
			}
		}
		for($i=0;$i<count($note_link);$i++){
			$title=str_replace("'","\'",$note_info[$i]);
			$url=str_replace(array('"',","),array('&lt;','&gt;'),$note_link[$i]);
			if(intval($db->scalar("select count(*) from {$dv}gather_url where url='$url'"))==0){
				$db->query("insert into {$dv}gather_url (boardtype,noteid,url,title,gatherdate,isdone) values({$arr['bordertype']},$id,'$url','$title',".time().",0)");
			}
		}
	}
	$total=intval(count($note_link));
	$gather_date=time();
	$stmt=$db->query("UPDATE {$dv}note_info SET last_gather_date='".$gather_date."',web_num=".$total." WHERE id=".intval($id)."");
}
function delete_curr_note(){
	global $lang,$dv,$db,$noteid;
	$id=$_POST['noteid'];
	if(empty($id)){
		show_msg($lang['sys.info'],$lang['gather.info7'],0,'','','gather.php?action=manage',$lang['cmdback']);
		exit;
	}else{
		$sql=$db->query("DELETE FROM {$dv}note_info WHERE id=".intval($id)."");
		if($sql){
			$sql=$db->query("DELETE FROM {$dv}gather_url WHERE noteid=".intval($id)."");
			show_msg($lang['sys.info'],$lang['gather.info8'],1,'','','gather.php?action=manage',$lang['cmdback']);
			exit;
		}
	}
}
function geturl(){
	global $comp_url;
	if(!empty($_SERVER["REQUEST_URI"])){
		$url=$_SERVER["REQUEST_URI"];
		$nowurls=explode("?",$url);
		$url=$nowurls[0];
	}
	else{
		$url=$_SERVER["PHP_SELF"];
	}
	$curls = explode("/",$url);
	for($i=0;$i<count($curls)-2;$i++){
		if($i!=0){
			$comp_url.= "/".$curls[$i];
		}
	}
	$comp_url .= "/upimg/";
	return ($comp_url);
}
function begin_gather_note(){//采集入库;
	global $lang,$dv,$db,$n_id,$note_link,$rule_expression,$labelobj,$baseurl;
	$id=intval($_GET['id']);
	if($id<=0){
		exit("@@@@@@@@@alert('{$lang['gather.info9']}')@@@");
	}else{
		ini_set('allow_url_fopen',1);
		if($query=$db->query("select noteid,url,isdone from {$dv}gather_url where id=$id order by isdone asc")){
			$gatherurl=$db->fetch_array($query);
			if($gatherurl['isdone']!=0)exit("@@@@@@@@@alert('{$lang['gather.info226']}')@@@");
		}else{
			exit("@@@@@@@@@alert('{$lang['gather.info224']}')@@@");
		}
		
		$sql=$db->query("SELECT id,note_name,coding,bordertype,from_url,last_gather_date,note_datetime,down_pic,web_num,sp_page,article_title,article_from,article_write,article_time,article_body,gatherid,includeurl,pagevar,color_style,board_setup,title_inhere_swap,body_inhere_swap,script_leach,news_time,keyword,page_class FROM {$dv}note_info WHERE id={$gatherurl['noteid']}");
		$arr=$db->fetch_array($sql);
		
		$rule_expre='#<a(?:.*?)href\s*=\s*(?:["\'\s]?)([^"\'\s]+)(?:.*?)>(.*?)</a>#is';//ok
		$gather_link=$gatherurl['url'];
		$baseurl=$gather_link;
		$file_content=@getfileurl($gather_link);
		 if($file_content!='') {
			$gatheridlist.=$n_id[$i].",";
				if($arr['article_title']<>"" and $arr['article_title']!="|||"){
					$bonded_title_var=explode ('|||',$arr['article_title']);
					$bonded_title_1=@explode($bonded_title_var[0],$file_content);
					$bonded_title_2=@explode($bonded_title_var[1],$bonded_title_1[1]);
					$bonded_title=$bonded_title_2[0];//得到标题;
					if($arr['title_inhere_swap']<>'' and $arr['title_inhere_swap']<>'|||'){
						$title_arr=explode('|||',$arr['title_inhere_swap']);
						$bonded_title=str_replace($title_arr[0],$title_arr[1],$bonded_title);
					}
				}else{
					$bonded_title=" ";
				}
				$bonded_title=trim($bonded_title);
				if($arr['article_body']<>"" and $arr['article_body']!="|||"){
					$body_title_var=explode ('|||',$arr['article_body']);
					$body_title_1=@explode($body_title_var[0],$file_content);
					$body_title_2=@explode($body_title_var[1],$body_title_1[1]);
					$body_contents=$body_title_2[0];//得到内容;
					if($arr['body_inhere_swap']<>'' and $arr['body_inhere_swap']<>'|||'){
						$body_arr=explode('|||',$arr['body_inhere_swap']);
						if(strpos($body_arr[0],'@@@')!==false){//被替换的
							$bodyswap_1=explode('@@@',$body_arr[0]);
							$bodyswap_2=explode('@@@',$body_arr[1]);
							$numjjj=count($bodyswap_1);
							for ($jjj=0;$jjj<$numjjj;$jjj++) {
								$body_contents=str_replace($bodyswap_1[$jjj],$bodyswap_2[$jjj],$body_contents);
							}
						}
						else{
							$body_contents=str_replace($body_arr[0],$body_arr[1],$body_contents);
						}//end
					}
				}else{
					$body_contents=" ";
				}
				if($arr['article_write']<>"" and $arr['article_write']!="|||"){
					$write_title_var=@explode ('|||',$arr['article_write']);
					$write_title_1=@explode($write_title_var[0],$file_content);
					if($write_title_1[1]==""){
						$write_contents=" ";
					}else{
						$write_title_2=explode($write_title_var[1],$write_title_1[1]);
					}
					$write_contents=$write_title_2[0];//得到作者;
				}else{
					$write_contents=" ";
				}
				$write_contents=trim(strip_tags($write_contents));
				if($arr['article_from']<>"" and $arr['article_from']!="|||"){
					$from_title_var=explode ('|||',$arr['article_from']);
					$from_title_1=@explode($from_title_var[0],$file_content);
					$from_title_2=@explode($from_title_var[1],$from_title_1[1]);
					$from_contents=$from_title_2[0];//得到来源;
				}
				else{
					$from_contents=" ";
				}
				$from_contents=strip_tags($from_contents);
				if(intval($arr['news_time'])==2){
					if($arr['article_time']<>"" and $arr['article_time']!="|||"){
						$time_title_var=explode ('|||',$arr['article_time']);
						$time_title_1=@explode($time_title_var[0],$file_content);
						$time_title_2=@explode($time_title_var[1],$time_title_1[1]);
						$now_date=$time_title_2[0];//得到时间;
					}
					else{
						$now_date=gmdate('Y-m-d', time()+getUserTimeZoneOffset());
					}
				}else{
					$now_date=gmdate('Y-m-d', time()+getUserTimeZoneOffset());
				}
				if($arr['down_pic']==0){
					$body_contents=down_longpic($body_contents);
				}else{
					if(strpos(strtolower($body_contents),'<img src=')!==false){												if(preg_match_all('#<img.*?src\s*=\s*["\'](.*?)["\'].*?>#is',$body_contents,$picarr)){
						for ($jj=0;$jj<count($picarr[0]);$jj++) {
							$body_contents=str_replace($picarr[0][$jj],'',$body_contents);
						}
					}
					}
				}
				if(strpos($arr['script_leach'],'html')!==false){
					$labelobj=new label();
					$body_contents=$labelobj->func_html($body_contents);
				}
				else{
					$labelarr=explode('|||',$arr['script_leach']);
					foreach ($labelarr as $labelvalue){
						if($labelvalue<>''){
							if($labelvalue<>'img'){
								$body_contents=strip_tags($labelvalue,$body_contents);
							}
						}
					}
				}
				if(strpos($bonded_title,'</title>')!==false){
					$str_tmp=explode('</title>',$bonded_title);
					$bonded_title=$str_tmp[0];
				}
				else{
					$bonded_title=$bonded_title;
				}
				$board_type=$arr['bordertype'];
				$sql=$db->query("INSERT INTO {$dv}gather_info (g_title,g_body,g_write,g_from,g_datetime,g_notename,board_type) values ('".$db->escape_string(htmlspecialchars($bonded_title))."','".$db->escape_string(htmlspecialchars($body_contents))."','".$db->escape_string(htmlspecialchars($write_contents))."','".$db->escape_string(htmlspecialchars($from_contents))."','".$now_date."','".$arr['note_name']."',".$board_type.")");
				$db->query("update {$dv}gather_url set isdone=1 where id=$id");
				exit('@@@@@@@@@
				document.getElementById("n_id_"+id).value=0;
				document.getElementById("cur_gather").innerHTML="<font color=green>'.$lang['gather.info228'].'</font>";
		        document.getElementById("downstatu_"+id).innerHTML="<font color=green>'.$lang['gather.info228'].'</font>";
				@@@');
			}else{
				exit('@@@@@@@@@
				document.getElementById("cur_gather").innerHTML="<font color=red>'.$lang['gather.info227'].'</font>";
		        document.getElementById("downstatu_"+id).innerHTML="<font color=red>'.$lang['gather.info227'].'</font>";
				@@@');
			}
	}
}
function  loog_url($urlstr){//得到服务器的URL；
	$arr=explode('/',$urlstr);
	$count=count($arr)-1;
	for ($i=2;$i<$count;$i++){
		$s_url.=$arr[$i]."/";
	}
	$s_url=substr($s_url,0,-1);
	return $s_url;
}
function pic_url($picstr,$host_url){//图片的URL;
	if(strpos($picstr,'http')===false){//picurl_1;
		$arr=explode('/',$picstr);
		if(!empty($arr[0]) && strpos($arr[0],'..')===false){//picurl_3;
			$server_url=loog_url($host_url);
			$full_url=$server_url."/".$picstr;
			$picname=$arr[count($arr)-1];
		}
		elseif(!empty($arr[0]) && strpos($arr[0],'..')!==false){//picurl_2;
			$server_url=loog_url($host_url);
			if(strpos($server_url,'/')!==false){
				$set=explode('/',$server_url);
				$count=count($set)-1;
				for ($j=0;$j<$count;$j++){
					$s_url.=$set[$j]."/";
				}
			}
			else{
				$s_url=$server_url;
			}
			$s_url=substr($s_url,0,-1);
			for ($i=1;$i<count($arr);$i++){
				$picurl.=$arr[$i]."/";
			}
			$picurl=substr($picurl,0,-1);
			$full_url=$s_url."/".$picurl;
			$picname=$arr[count($arr)-1];
		}
		elseif(empty($arr[0])){//picurl_4;
			$server_url=loog_url($host_url);
			if(strpos($server_url,'/')!==false){
				$set=explode('/',$server_url);
				$s_url=$set[0];
			}
			else{
				$s_url=$server_url;
			}
			for ($i=1;$i<count($arr);$i++){
				$picurl.=$arr[$i]."/";
			}
			$picurl=substr($picurl,0,-1);
			$full_url=$s_url."/".$picurl;
			$picname=$arr[count($arr)-1];
		}
		else{
			$server_url=loog_url($host_url);
			$full_url=$server_url."/".$picstr;
			$picname=$arr[count($arr)-1];
		}
	}
	else{
		$full_url=$picstr;
		$arr=explode('/',$picstr);
		$picname=$arr[count($arr)-1];
	}
	if(strpos($full_url,'http')===false){
		$full_url="http://".$full_url;
	}
	return ($full_url."||".$picname);
}


function down_longpic($filemem){
	global $baseurl,$uploaddir;
	$pic_dir="../".$uploaddir."/upimg/";
	if(preg_match_all('#<img.*?src\s*=\s*["\'](.*?)["\'].*?>#is',$filemem,$pic_arr)){
		for ($i=0;$i<count($pic_arr[0]);$i++) {
			$pic_file_url=$pic_arr[1][$i];
			$picurl=fillurl($baseurl,$pic_file_url);
			$picname=(false!==$pos=strrpos($picurl,'/'))?substr($picurl,$pos+1):$picurl;
			if(file_exists($pic_dir.$picname)){
				$filemem=str_replace($pic_file_url,ROOT_PATH.$uploaddir."/upimg/".$picname,$filemem);
				continue;
			}
			$file = &getfileurl($picurl);
			if(strpos(strtolower($picname),'gif')!==false or strpos(strtolower($picname),'jpg')!==false or strpos(strtolower($picname),'bmp')!==false or strpos(strtolower($picname),'png')!==false){
				if(!$fp=@fopen($pic_dir.$picname,"wb"))continue;
				chmod($pic_dir.$picname, 0777);
				flock($fp,2);
				fwrite($fp, $file);
				fclose($fp);
				if(!empty($filemem) && !empty($pic_file_url)){
					if(strpos($filemem,$pic_file_url)!==false){
						$filemem=str_replace($pic_file_url,ROOT_PATH.$uploaddir."/upimg/".$picname,$filemem);
					}

				}
			}
			else{
				continue;
			}
		}
	}
	return $filemem;
}

function test_curr_note(){
	global $lang,$dv,$db,$id,$note_info,$note_link,$test_info,$note_name;
	$note_info=array();
	$note_link=array();
	$id=$_GET['id'];
	if($id==""){
		show_msg($lang['sys.info'],$lang['gather.info7'],0,'','','gather.php?action=manage',$lang['cmdback']);
		exit;
	}
	ini_set('allow_url_fopen', 1);
	$sql=$db->query("SELECT id,note_name,coding,bordertype,from_url,last_gather_date,note_datetime,down_pic,web_num,sp_page,article_title,article_from,article_write,article_time,article_body,gatherid,includeurl,pagevar,color_style,board_setup,title_inhere_swap,body_inhere_swap,script_leach,news_time,keyword,page_class FROM {$dv}note_info WHERE id=".$id."");
	$arr=$db->fetch_array($sql);
	$note_name=$arr['note_name'];
	$filecontents = @getfileurl($arr['from_url']);
	$test_info=$filecontents;
	//#<a href=?(.*?)?\s*>(.*?)</a>#is
	if (preg_match_all('#<a(?:.*?)href\s*=\s*(?:["\'\s]?)([^"\'\s]+)(?:.*?)>(.*?)</a>#is',$filecontents, $matches)) {
		$count = count($matches[0]);
		for ($i = 0 ; $i < $count ; $i++ ) {
			if($matches[1][$i]==""){
				continue;
			}
			else{
				$img=strtolower(substr($matches[2][$i],-3));
				if($img=="jpg" or $img=="gif"){
					continue;
				}
				else{
					$note_info[$i]=$matches[2][$i];
					$link=explode(" target",$matches[1][$i]);
					$note_link[$i]=$link[0];
				}
			}
		}
	}
}
function save_cur_note(){
	return true;
}


function storeroom_info(){
	global $lang,$dv,$db,$db_info,$page_size,$page,$total,$page_count,$offset,$p;
	$db_info=array();
	$total=$db->scalar("SELECT count(1) FROM {$dv}gather_info");
	page_info(20);
	$sql=$db->query("SELECT g_id,g_title,g_body,g_write,g_datetime,g_from,g_notename,board_type FROM {$dv}gather_info order by g_id",array('absolutePage'=>$offset,'pageSize'=>$page_size));
	while ($arr=$db->fetch_array($sql)){
		$db_info[]=$arr;
	}
}
function del_storeroom_info(){
	global $lang,$db,$dv,$dbid;
	$dbid=$_POST['dbid'];
	if(count($dbid)<=0){
		show_msg($lang['sys.info'],$lang['gather.info7'],0,'','','gather.php?action=get_gather',$lang['cmdback']);
		exit;
	}
	else{
		$count=count($dbid);
		for ($i=0;$i<$count;$i++){
			$sql=$db->query("DELETE FROM {$dv}gather_info WHERE g_id=".intval($dbid[$i])."");
			$n++;
		}
		if($n>0){
			show_msg($lang['sys.info'],$lang['gather.info8'],1,'','','gather.php?action=get_gather',$lang['cmdback']);
			exit;
		}
	}
}
function edit_storeroom_info(){
	global $lang,$dv,$db,$id,$db_info;
	$db_info=array();
	$id=$_GET['id'];
	if($id=="" or $id==0){
		show_msg($lang['sys.info'],$lang['gather.info7'],0,'','','gather.php?action=manage',$lang['cmdback']);
		exit;
	}
	else{
		$sql=$db->query("SELECT g_id,g_title,g_body,g_write,g_datetime,g_from,g_notename FROM {$dv}gather_info WHERE g_id=".intval($id)."");
		while ($arr=$db->fetch_array($sql)){
			$db_info[]=$arr;
		}
	}
}
function save_storeroom_info(){
	global $lang,$dv,$db,$id;
	$id=$_GET['id'];
	$title=trim($_POST['title']);
	$body=$_POST['body'];
	$write=trim($_POST['write']);
	$from=trim($_POST['from']);
	if($id=="" or $id==0){
		show_msg($lang['sys.info'],$lang['gather.info7'],0,'','','gather.php?action=get_gather',$lang['cmdback']);
		exit;
	}
	else{
		$sql=$db->query("UPDATE {$dv}gather_info SET g_title='".$title."',g_body='".$body."',g_write='".$write."',g_from='".$from."' WHERE g_id=".intval($id)."");
		if($sql){
			show_msg($lang['sys.info'],$lang['gather.info10'],1,'','','gather.php?action=get_gather',$lang['cmdback']);
			exit;
		}
	}
}
function note_infolist(){
	global $dv,$db,$notearr;
	$notearr=array();
	$sql=$db->query("SELECT note_name FROM {$dv}note_info");
	while ($arr=$db->fetch_array($sql)){
		$notearr[]=$arr;
	}
}
function dat_storeroom_info(){
	global $lang,$db,$dv,$swap_title,$swap_write,$swap_from,$swap_body,$fielt_title,$fielt_write,$fielt_from,$fielt_body;
	$notename=str_replace(" ","",$_POST['notename']);
	$fielt_title=intval($_POST['fielt_title']);
	$fielt_write=intval($_POST['fielt_write']);
	$fielt_frow=intval($_POST['fielt_frow']);
	$fielt_body=intval($_POST['fielt_body']);
	$swap_title=$_POST['swap_title'];
	$swap_write=$_POST['swap_write'];
	$swap_from=$_POST['swap_from'];
	$swap_body=$_POST['swap_body'];
	$time=gmdate('Y-m-d', time()+getUserTimeZoneOffset());
	if($notename==""){
		show_msg($lang['sys.info'],$lang['gather.info9'],0,'','','gather.php?action=manage',$lang['cmdback']);
		exit;
	}
	else{
		if($fielt_title<>"" or $fielt_title<>0){
			$sql1=$db->query("UPDATE {$dv}gather_info SET g_title='".$swap_title."',g_datetime='".$time."' WHERE g_notename='".$notename."'");
		}
		if($fielt_write<>"" or $fielt_write<>0){
			$sql2=$db->query("UPDATE {$dv}gather_info SET g_write='".$swap_write."',g_datetime='".$time."' WHERE g_notename='".$notename."'");
		}
		if($fielt_frow<>"" or $fielt_frow<>0){
			$sql3=$db->query("UPDATE {$dv}gather_info SET g_from='".$swap_from."',g_datetime='".$time."' WHERE g_notename='".$notename."'");
		}
		if($fielt_body<>"" or $fielt_body<>0){
			$sql4=$db->query("UPDATE {$dv}gather_info SET g_body='".$swap_body."',g_datetime='".$time."' WHERE g_notename='".$notename."'");
		}
		if($sql1 or $sql2 or $sql3 or $sql4){
			show_msg($lang['sys.info'],$lang['gather.info10'],1,'','','gather.php?action=manage',$lang['cmdback']);
			exit;
		}
	}
}
function put_foruminfo() {//采集信息转到论坛库;
	global $dv,$db,$lang,$dbid,$_DCACHE,$sysusername,$uploaddir;
	$dbid=$_POST['dbid'];
	$ip=forumusertrueip();
	if(count($dbid)<=0){
		show_msg($lang['sys.info'],$lang['gather.info7'],0,'','','gather.php?action=get_gather',$lang['cmdback']);
		exit;
	}
	else{
		ini_set('allow_url_fopen', 1);
		foreach($dbid as $infoid){
			$nowdate=time();
			$expression="0|face1.gif";
			$bbs_expression="face1.gif";
			$forum_adduser=$db->scalar("select adduser from {$dv}admin where username='".$sysusername."'");
			$forum_nowusebbs=$db->scalar("select forum_nowusebbs from {$dv}setup");
			$bbs_announceid=$db->scalar("select max(announceid) from ".$forum_nowusebbs."");
			$topicid=$db->scalar("select max(topicid) from {$dv}topic");
			$topicid=$topicid+1;
			$ubblist=",39,";
			$post_userid=$db->scalar("select userid from {$dv}user where username='".$forum_adduser."'");
			$sql=$db->query("select g_id,g_title,g_body,g_write,g_from,g_datetime,g_notename,board_type from {$dv}gather_info where g_id=".$infoid."");
			$arr=$db->fetch_array($sql);
			$title=str_replace('nbsp','&nbsp',str_replace('"','',str_replace('\n','',$arr['g_title'])));
			$dv_boardid=$arr['board_type'];
			$length=ceil(strlen($arr['g_body'])/2);	$lastpostinfo=$forum_adduser.'${AnnounceID}$'.$nowdate."$".$arr['g_title']."$$".$post_userid."$".$topicid."$".$arr['board_type'];
			$lastpostinfo=str_replace('"','',str_replace('\n','',$lastpostinfo));
			$topic_table=$db->query("INSERT INTO {$dv}topic (title,boardid,postusername,postuserid,dateandtime,expression,lastpost,lastposttime,posttable,locktopic,istop,topicmode,isvote,pollid,mode,getmoney,usetools,getmoneytype,issmstopic,hidename) VALUES ('".$title."',".$arr['board_type'].",'".$forum_adduser."',".$post_userid.",'".$nowdate."','".$expression."','".$db->escape_string(htmlspecialchars($lastpostinfo))."','".$nowdate."','".$forum_nowusebbs."',0,0,0,0,0,0,0,'','',0,0)");
			$insertedtopicid = $db->insert_id();
			$bbsbody=str_replace('../'.$uploaddir,$uploaddir,str_replace('nbsp','&nbsp',$arr['g_body']));
			$bbsbody=fixjs($bbsbody);
			$bbsbody=str_replace('\'','"',$bbsbody);
			$bbsbody=str_replace('&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;','',$bbsbody);
			$updir="../";
			$bbsbody=str_replace('&&nbsp;','&nbsp;',str_replace('\r\n\r\n ','',$bbsbody));
			$bbs_table=$db->query("INSERT INTO ".$forum_nowusebbs." (rootid,parentid,boardid,username,postuserid,topic,body,dateandtime,length,layer,orders,isbest,ip,expression,locktopic,signflag,emailflag,isagree,isaudit,isupload,postbuyuser,ubblist,getmoney,usetools,getmoneytype) VALUES (".$insertedtopicid.",0,".$arr['board_type'].",'".$forum_adduser."',".$post_userid.",'".$db->escape_string(htmlspecialchars($arr['g_title']))."','".$bbsbody."','".$nowdate."','".$length."',0,0,0,'".$ip."','".$bbs_expression."',0,1,0,'',0,0,'','".$ubblist."',0,'',0)");
			$insertedAnnounceID = $db->insert_id();
			$lastpostinfo = str_replace('${AnnounceID}$', '$'.$insertedAnnounceID.'$', $lastpostinfo);
			$db->query("update {$dv}topic set lastpost='".$db->escape_string(htmlspecialchars($lastpostinfo))."' where topicid='".$insertedtopicid."'");
			$del_sql=$db->query("DELETE from {$dv}gather_info where g_id=".$infoid."");
			$count++;
		}
		if($count>0){
			$sql=$db->query("update {$dv}board set postnum=postnum+".$count.",topicnum=topicnum+".$count.",todaynum=todaynum+".$count.",lastpost='".$db->escape_string(htmlspecialchars($lastpostinfo))."' where boardid=".$dv_boardid."");
			$backinfo='gather.php?action=get_gather';	show_msg($lang['sys.info'],$lang['gather.info128'],1,'','',$backinfo,$lang['cmdback']);
			exit;
		}
	}
}
function head_portrait(){
	global $dv,$lang,$db,$file_list,$facesdir,$uploaddir;
	global $pre,$page_size,$page,$total,$page_count,$offset,$p,$start,$next,$ten_page,$file_total;
	$file_list=array();
	$facesdir=$uploaddir;
	$facesdir="../".$facesdir.$lang['gather.info158'];
	if (is_dir($facesdir)) {
		if ($dir_hand = opendir($facesdir)) {
			while (($file = readdir($dir_hand)) !== false) {
				if($file=="." or $file==".."){
					continue;
				}
				elseif(strpos($file,'.txt')!==false){
					continue;
				}
				else{
					$file_list[]=$dir.$file;
					$file_total+=1;
				}
			}
			$page_size=20;
			$page_count=ceil($file_total/$page_size);
			$total=$file_total;
			closedir($dir_hand);
		}
	}
	else{
		show_msg($lang['sys.info'],$lang['gather.info159'],0,'','','?action=manage',$lang['cmdback']);
		exit;
	}
}
function delall_head_portrait(){//删除所有采集图片;
	global $lang,$facesdir,$uploaddir;
	$geturl=$_SERVER['HTTP_REFERER'];
	$facesdir="../".$uploaddir.$lang['gather.info158'];
	if(is_dir($facesdir)){
		if($dir_fp=opendir($facesdir)){
			while(($filename=readdir($dir_fp))!==false){
				if($filename=="." or $filename==".."){
					continue;
				}
				else{
					unlink($facesdir.$filename);
				}
			}
			show_msg($lang['sys.info'],$lang['gather.info169'],1,'','',$geturl,$lang['cmdback']);
			exit;
		}
		else{
			show_msg($lang['sys.info'],$lang['gather.info170'],0,'','',$geturl,$lang['cmdback']);
			exit;
		}
	}
	else{
		show_msg($lang['sys.info'],$lang['gather.info171'],0,'','',$geturl,$lang['cmdback']);
		exit;
	}
}
function del_head_portrait($filename){
	global $lang,$facesdir;
	$geturl=$_SERVER['HTTP_REFERER'];
	if($filename!=""){
		if(unlink($filename)){
			show_msg($lang['sys.info'],$lang['gather.info169'],1,'','',$geturl,$lang['cmdback']);
			exit;
		}
		else{
			show_msg($lang['sys.info'],$lang['gather.info170'],0,'','',$geturl,$lang['cmdback']);
			exit;
		}
	}
	else{
		show_msg($lang['sys.info'],$lang['gather.info171'],0,'','',$geturl,$lang['cmdback']);
		exit;
	}
}
function uploadrule($file,$size) {//导入规则文件;
	global $inportrule,$geturl,$uploaddir,$lang,$file_list,$_POST;
	$geturl=$_SERVER['HTTP_REFERER'];
	$inportrule=array();
	$inportrule=$file;
	$uploadruledir='../'.$uploaddir.'/upimg/';
	if(empty($size)){
		show_msg($lang['sys.info'],$lang['gather.info172'],0,'','',$geturl,$lang['cmdback']);
		exit;
	}
	else{
		$name_str='gather_rulefile';
		$filebase=strtolower(strrchr($inportrule['name'],'.'));
		if($filebase<>'.txt'){
			show_msg($lang['sys.info'],$lang['gather.info172'],0,'','',$geturl,$lang['cmdback']);
			exit;
		}
		else{
			$attachstr=$uploadruledir.$name_str.$filebase;
			@chmod($uploadruledir,0777);
			$inportrule['tmp_name']=str_replace('\\\\', '/', $inportrule['tmp_name']);
			if (@move_uploaded_file($inportrule['tmp_name'],$attachstr)){
				@chmod($attachstr,0777);
				show_msg($lang['sys.info'],$lang['gather.info173'],1,'','',$geturl,$lang['cmdback']);
				exit;
			}
			else{
				show_msg($lang['sys.info'],$lang['gather.info171'],0,'','',$geturl,$lang['cmdback']);
				exit;
			}
			@unlink($inportrule);
		}
	}
	return $recordset;
}
function export_file() {//导出规则文件;
	global $id,$export_rule,$uploaddir,$lang,$dv,$db;
	$geturl=$_SERVER['HTTP_REFERER'];
	$id=$_GET['id'];
	$export_rule=$_POST['export_rule'];
	$exportdir='../'.$uploaddir.'/upimg/';
	$sql=$db->query("SELECT note_name,bordertype,from_url,article_title,article_from,article_write,article_time,article_body,color_style,board_setup,includeurl,title_inhere_swap,body_inhere_swap,script_leach,coding,down_pic,news_time,keyword,page_class,pagevar,sp_page FROM {$dv}note_info WHERE id=".$id."");
	$arr=$db->fetch_array($sql);
	$i=0;
	foreach ($arr as $list){
		$content.=$list.',';
	}
	$content=substr($content,0,-1);
	$filename=$exportdir.$export_rule.'.txt';
	if(file_exists($filename)){
		show_msg($lang['sys.info'],$lang['gather.info174'],0,'','',$geturl,$lang['cmdback']);
		exit;
	}
	else{
		$content=base64_encode($content);
		@chmod($exportdir,0777);
		@chmod($filename,0777);
		if($fp=fopen($filename,'w')){
			if(fwrite($fp,$content)!==false){
				show_msg($lang['sys.info'],$lang['gather.info175'],1,'','',$geturl,$lang['cmdback']);
				exit;
			}
		}
		@chmod($filename,0777);
		fclose($fp);
	}
}
function read_gather_rulefile() {//读出采集规则文件;
	global $uploaddir;
	$filename='../'.$uploaddir.'/upimg/gather_rulefile.txt';
	$gather_rulefile_contentarr=array();
	if(file_exists($filename)){
		@chmod($filename,0777);
		if($fp=fopen($filename,'r')){
			$gather_rulefile_content=base64_decode(fread($fp,filesize($filename)));
			$gather_rulefile_contentarr=explode(',',$gather_rulefile_content);
		}
		fclose($fp);
	}
	return $gather_rulefile_contentarr;
}
function view_source($targetUrl) {
	global $lang;
	$backinfo='gather.php?action=get_gather';
	if($targetUrl=="" or $targetUrl==="http://"){																			show_msg($lang['sys.info'],$lang['gather.info141'],0,'','',$backinfo,$lang['cmdback']);
	exit;
	}
	else{
		$str=@getfileurl($targetUrl);
		//header("Content-Type: text/html");
		echo $str;
	}
}
function fixjs($strings){
	return str_replace(array('&gt;', '&lt;', '&quot;','&amp;','\\','"', "\r", "\n"), array('>', '<','"','&','\\\\', '"', '\r', '\n'), $strings);
}
function Pageload($file,$size){
	global $dv,$db,$lang,$action,$doaction,$bordertype,$_DCACHE,$note_arr,$page_size,$page,$total,$page_count,$offset,$p,$id;
	global $note_link,$note_info,$start,$next,$pre,$test_info,$db_info,$note_name,$notearr,$gatheridarr,$notename;
	global $ten_page,$forum_note,$sysusername,$rule_expression,$host_url,$get_serverurl,$fsetting,$uploaddir,$item,$sort;
	global $file_total,$file_list,$facesdir,$filename;
	$uploaddir=basename($_DCACHE['settings']['forumuploadname']);
	$host_url="http://".$_SERVER['HTTP_HOST']."/";
	$id=$_GET['id']?$_GET['id']:intval($_POST['id']);
	$page_size=20;
	if($page<1)$page=1;
	$offset=($page-1)*$page_size;
	switch ($action){
		case "note_addok":
			add_note();
			break;
		case "view":
			view_gather();
			$total=intval($db->scalar("select count(1) from {$dv}gather_url where noteid=$id"));
			$gatherurls=$db->getResultSet("select id,boardtype,noteid,url,title,isdone from {$dv}gather_url where noteid=$id limit $offset,$page_size");
			break;
		case "editok":
			rejigger_curr_node($sort);
			break;
		case "test":
			test_curr_note();
			break;
		case "save":
			save_cur_note();
			break;
		case "get_gather":
			storeroom_info();
			break;
		case "odd_editok":
			save_storeroom_info();
			break;
		case "dat_editok":
			dat_storeroom_info();
			break;
		case "gather_edit":
			rejigger_curr_node_list();
			break;
		case "gather_del":
			delete_curr_note();
			break;
		case "pic_manager":
			head_portrait();
			break;
		case "clear":
			delall_head_portrait();
			break;
		case "delfile":
			del_head_portrait($filename);
			break;
		case "inport":
			uploadrule($file,$size);
			break;
		case "export":
			export_file();
			break;
		default :
			note_list();
			break;
	}
	switch ($doaction){
		case "view":
			view_gather();
			break;
		case "gather_web":
			begin_gather_note();
			break;
		case "del_dbinfo":
			del_storeroom_info();
			break;
		case "dbedit":
			edit_storeroom_info();
			break;
		case "edit_datinfo":
			note_infolist();
			break;
		case "put_forumtable":
			put_foruminfo();
			break;
		case "viewsource":
			view_source($_GET['url']);
			break;
	}
	include printout('gather');
}

function fillurl($baseurl,$url){
	if(strtolower(substr($url,0,7))=='http://')return $url;
	$baseurl=str_replace('\\','/',$baseurl);

	if(substr($url,0,1)=='/'){
		if(false!==$pos=strpos($baseurl,'/',7)){
			$baseurl=substr($baseurl,0,$pos);
		}
	}else{
		if(false!==$pos=strrpos($baseurl,'/')){
			$baseurl=substr($baseurl,0,$pos+1);
		}
	}
	$urls=explode('/',$url);
	foreach ($urls as $k=>$v){
		$v=trim($v);
		if(empty($v))unset($urls[$k]);
	}
	$url=join('/',$urls);
	if(substr($baseurl,-1,1)!='/')$baseurl.="/";
	return $baseurl.$url;
}
?>