<?php
/*
'**************************************************************************************************
' 软件名称: 搜一次 Content Management System
' 版本编号: Version 1.X
' 官方网站: http://www.syccms.com
' 官方论坛：http://bbs.syccms.com
' 版权所有: 搜一次运营团队
' 法律顾问: 杭州市元茂律师事务所 严飞律师
' 郑重声明:
'    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" />
<title>伪原创工具</title>
</head>

<body>
<?php
	
	function main(){
		echo "
		<form name=formg action=\"?action=go&pages=0\" 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;
						<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);
		file_put_contents("ori.txt",$ocontent);
		die("<script>alert('词库更细完毕!');window.location='?action=add';</script>");
		}	

	function go(){
		global $db;
		$type=SafeRequest("type","auto");
		$day=SafeRequest("day","auto");
		$pages=SafeRequest("pages","get");
		
		$array=file("ori.txt");
		print_r($array[$pages]);
		$count=count($array)-1;
		
		$ori=array();
		$ori=explode("-->",$array[$pages]);
		
		$sql="";
		if($type==1){
			$sql.=" UPDATE s_video SET S_Content = replace(S_Content,'".$ori[0]."','".trim($ori[1])."') ";
		}
		if($type==2){
			$sql.=" UPDATE s_article SET S_Content = replace(S_Content,'".$ori[0]."','".trim($ori[1])."') ";
		}
		if($day!=0){
			$sql.=" WHERE DATEDIFF(S_AddTime,CURDATE())<='".$day."' ";
		}
		
		$db->query($sql);
		
		if($pages<=$count){
			die('&nbsp;&nbsp;第'.$pages.'页执行完毕,继续下一页...<script type="text/javascript">setTimeout("ReadGo();",1000);function ReadGo(){location.href="?action=go&day='.$day.'&type='.$type.'&pages='.($pages+1).'";}</script>');
		}else{
			die('恭喜，执行完毕');
		}

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