<?php
/*
'**************************************************************************************************
' 软件名称: 盘锦DJ舞曲网CMS Content Management PjRen.Net
' 版本编号: Version 2.5
' 盘锦舞曲: http://www.pj57.com
' 官方网站: http://www.pjren.net
' 小说网站: http://www.hx39.com
' 0427DJ网: http://www.0427dj.net
' 官方论坛: http://www.tianjiazhen.com
' 版权所有: 盘锦舞曲开发团队    盘锦人(QQ:814006710)
' 郑重声明:
'    1、任何个人或组织不得在未经授权的情况下删除、修改、拷贝本软件及其他副本上一切关于版权的信息；
'    2、盘锦网络事业部保留此软件的法律追究权利
'**************************************************************************************************
*/
include "../../include/conn.php";
include "../../include/function.php";
include "../admin_version.php";
include "../admin_loginstate.php";
set_time_limit(0);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<link href="../images/style.css" rel="stylesheet" type="text/css" />
<link type="text/css" href="../images/alerts.css" rel="stylesheet" media="screen">
<script type="text/javascript" language="javascript">var tentpath='<?php echo S_SitePath?>';</script>
<script language="javascript" src="../js/jquery.js"></script>
<script language="javascript" src="../js/alerts.js"></script>
<title>伪原创工具</title>
</head>

<body>
<?php
	SystemPer(10);
	function main(){
		echo "
		<form name=formg action=\"?action=go\" method=\"post\">
		<table width=\"100%\" border=\"0\" align=\"center\" cellpadding=\"0\" cellspacing=\"0\"  class=\"tb_style\" >
				<tr>
					<td class=\"td_title\">						
						&nbsp;伪原创处理(同义词量大的话,需要较多的时间)
					</td>
				</tr>
				<tr>
					<td class=\"td_border\" height=\"40\">
						&nbsp;类型选择
						<select name=\"type\">
							<option value=1>舞曲伪原创</option>
							<option value=2>文章伪原创</option>
						</select>
						&nbsp;生成最近&nbsp;
						<select name=\"day\">
							<option value=0>不限</option>
							<option value=1>1天</option>
							<option value=2>2天</option>
							<option value=3>3天</option>
							<option value=4>4天</option>
							<option value=5>5天</option>
						</select>&nbsp;内的舞曲
						&nbsp;每页执行&nbsp;<input type=text size=4 value=20 name=\"count\">&nbsp;条
						<input name=\"go\" value=\"开始执行\" type=\"submit\" class=rb1>
					</td>
				</tr>
			</table>
			</form>
		"; 
		}
	
	function add(){
		$oricontent=@file_get_contents("ori.txt");
		echo "
		<table width=\"100%\" border=\"0\" align=\"center\" cellpadding=\"0\" cellspacing=\"0\"  class=\"tb_style\" >
		<form name=from2 action=\"?action=save\" method=post>
					<tr>	
						<td class=td_title>格式说明:每一条同义词用回车隔开,<font color=red>往返</font>--><font color=green>来回</font>,‘往返’替换成了‘来回’</td>
					</tr>
					<tr>
						<td>
						<textarea name=content rows=20 cols=120 style=\"font-family: Arial, Helvetica, sans-serif;\">$oricontent</textarea>
						<br/>
						<input type=submit value=\"更新同义词替换\" class=rb1>
						</td>
					</tr>
						</form>
						</table>
						";
		}
		
	function save(){
		$ocontent=SafeRequest("content","post");
		chmod("ori.txt",0777);
		fwrite(fopen("ori.txt","wb"),$ocontent);
		die("<script>alert('词库更细完毕!');window.location='?action=add';</script>");
		}	

	function go(){
		global $db;
		$type=SafeRequest("type","auto");
		$count=SafeRequest("count","auto");
		$pages=SafeRequest("pages","auto");
		$day=SafeRequest("day","auto");
		if(!IsNul($pages)) $pages=1;
		if(!IsNul($count)) $count=20;
		if($type=='1'){ $table="s_video";}else{$table="s_article";}
		if($day=='0' or $day==""){
			$sqlori="select S_Name,S_ID,S_Content from $table";
			}
		else{
			$sqlori="select S_Name,S_ID,S_Content from $table where DATEDIFF(DATE(S_AddTime),'".date('Y-m-d')."')>=-$day";
			}
		$Arr=getpagerow($sqlori,$count);//sql,每页显示条数
		$result=$db->query($Arr[2]);
		echo("<div style=' width:100%; background: #F9FBFD; border-top:4px solid #DEEFFA; border-bottom:1px solid #DEEFFA;color:#008EBD; font-size:10pt; height:30px; line-height:30px;font-weight:bold; margin:0 auto;'>&nbsp;正在开始执行第<font style='color:red; font-size:16px; font-style:italic'>".$pages."</font>页数据，共<font style='color:red; font-size:16px; font-style:italic'>".$Arr[3]."</font>页</div>");
		 if($result){
			while ($row = $db ->fetch_array($result)){
				$row['S_Content']=gorep($row['S_Content']);
				$sql="update $table set S_Content='".$row['S_Content']."' where S_ID=".$row['S_ID']."";
				if($db->query($sql)){
					echo "&nbsp;&nbsp;".$row['S_Name']."<font color=green>执行完毕!!</font><br/>";
					}
				}
			if($pages>=$Arr[3]){
				die("&nbsp;&nbsp;<font color=red>恭喜全部执行完毕!</font>");
				}
			else{
				die("&nbsp;&nbsp;第".$pages."页执行完毕,继续下一页...<script language='javascript'>setTimeout('ReadGo();',1000);function ReadGo(){location.href='?action=go&day=".$day."&type=".$type."&count=".$count."&pages=".($pages+1)."';}</script>");
				}					
		 }	
		}

	function gorep($body){
		$repContent=@file_get_contents("ori.txt");
		$th=explode("\n",$repContent);//分割同意词 
		for($i=0;$i<count($th);$i++){  
			$ss = explode("-->",$th[$i]);  
			$body = str_replace("\r","",$body);  
			$body = str_replace("$ss[0]","$ss[1]",$body); 
			}
			return $body;
		}

	$action=SafeRequest("action","get");
	switch($action){
		case 'add':
			add();
			break;
		case 'save':
			save();
			break;
		case 'go':
			go();
			break;
		default:
			main();
		}
?>
</body>
</html>