コード例 #1
0
ファイル: comdofun.php プロジェクト: novnan/meiju
function DoRepNewstext($start,$oldword,$newword,$field,$classid,$tid,$tbname,$over,$dozz,$dotxt,$userid,$username){
	global $empire,$public_r,$class_r,$fun_r,$dbtbpre,$emod_r;
	$tbname=RepPostVar($tbname);
	$field=RepPostVar($field);
	$tid=(int)$tid;
	$dotype=(int)$_POST['dotype'];
	$classid=(int)$classid;
	if(!$field||empty($tbname)||!$tid)
	{
		printerror("FailCX","history.go(-1)");
	}
	if($dotype==0&&strlen($oldword)==0)
	{
		printerror("FailCX","history.go(-1)");
	}
	CheckLevel($userid,$username,$classid,"repnewstext");//验证权限
	//变量替换
	$postoldword=ClearAddsData($oldword);
	$postnewword=ClearAddsData($newword);
	//替换条件
	if($classid)//按栏目替换
	{
		if(empty($class_r[$classid][islast]))//中级栏目
		{
			$where=ReturnClass($class_r[$classid][sonclass]);
		}
		else//终极栏目
		{
			$where="classid='$classid'";
		}
		$add1=" and (".$where.")";
		$add2=" where (".$where.")";
    }
	$fr=$empire->fetch1("select tid,savetxt,tbdataf from {$dbtbpre}enewsf where tbname='$tbname' and f='$field' limit 1");
	//系统字段
	$specialdatafield=',keyid,dokey,newstempid,closepl,haveaddfen,infotags,';
	if(!$fr['tid']&&stristr($specialdatafield,','.$field.','))
	{
		$fr['tbdataf']=1;
	}
	//覆盖方式
	if($dotype==1)
	{
		$repoldword=addslashes($oldword);
		$repnewword=addslashes($newword);
		if($over==1)//完全替换
		{
			if(empty($add2))
			{
				$and=" where ";
			}
			else
			{
				$and=" and ";
			}
			$add2.=$and.$field."='".$repoldword."'";
		}
		if($fr['tbdataf'])//副表
		{
			//已审核
			$tbr=$empire->fetch1("select datatbs from {$dbtbpre}enewstable where tbname='$tbname' limit 1");
			if($tbr['datatbs'])
			{
				$dtbr=explode(',',$tbr['datatbs']);
				$count=count($dtbr);
				for($i=1;$i<$count-1;$i++)
				{
					$empire->query("update {$dbtbpre}ecms_".$tbname."_data_".$dtbr[$i]." set ".$field."='$repnewword'".$add2);
				}
			}
			//未审核
			$empire->query("update {$dbtbpre}ecms_".$tbname."_check_data set ".$field."='$repnewword'".$add2);
		}
		else//主表
		{
			$empire->query("update {$dbtbpre}ecms_".$tbname." set ".$field."='$repnewword'".$add2);
			//未审核
			$empire->query("update {$dbtbpre}ecms_".$tbname."_check set ".$field."='$repnewword'".$add2);
		}
		//替换完毕
		insert_dolog("tbname=".$tbname."&field=".$field."&dotype=1<br>oldword=".$oldword."<br>newword=".$newword);//操作日志
		printerror("DoRepNewstextSuccess","db/RepNewstext.php?tid=$tid".hReturnEcmsHashStrHref2(0));
	}
	//存文本替换
	elseif($fr['savetxt'])
	{
		$repoldword=addslashes($postoldword);
		$repnewword=addslashes($postnewword);
		//字段
		$selectf=$fr['tbdataf']?',stb':','.$field;
		$fieldform="<input type='hidden' name='field' value='".$field."'>";
		if(empty($public_r[dorepnum]))
		{
			$public_r[dorepnum]=600;
		}
		$start=(int)$start;
		$b=0;
		$sql=$empire->query("select id,checked from {$dbtbpre}ecms_".$tbname."_index where id>$start".$add1." order by id limit ".$public_r[dorepnum]);
		while($r=$empire->fetch($sql))
		{
			$b=1;
			$newstart=$r[id];
			//返回表
			$infotb=ReturnInfoMainTbname($tbname,$r['checked']);
			//主表
			$infor=$empire->fetch1("select isurl".$selectf." from ".$infotb." where id='$r[id]' limit 1");
			if($infor['isurl'])
			{
				continue;
			}
			//副表
			if($fr['tbdataf'])
			{
				//返回表信息
				$infodatatb=ReturnInfoDataTbname($tbname,$r['checked'],$infor['stb']);
				$finfor=$empire->fetch1("select ".$field." from ".$infodatatb." where id='$r[id]' limit 1");
				$infor[$field]=$finfor[$field];
			}
			$value=GetTxtFieldText($infor[$field]);
			if(empty($value))
			{
				continue;
			}
			if($dozz==1)//正则
			{
				$newvalue=DoRepNewstextZz($repoldword,$repnewword,$value);//正则替换
			}
			else//普通
			{
				if(!stristr($value,$repoldword))
				{
					continue;
				}
				$newvalue=str_replace($repoldword,$repnewword,$value);
			}
			EditTxtFieldText($infor[$field],$newvalue);
		}
		//替换完毕
		if(empty($b))
		{
			insert_dolog("tbname=".$tbname."&field=".$field."<br>oldword=".$oldword."<br>newword=".$newword);//操作日志
			printerror("DoRepNewstextSuccess","db/RepNewstext.php?tid=$tid".hReturnEcmsHashStrHref2(0));
		}
		EchoRepFieldForm($tid,$tbname,$over,$dozz,$dotxt,$newstart,$fieldform,$classid,$postoldword,$postnewword);
	}
	//正则替换
	elseif($dozz==1)
	{
		//字段
		$selectf=$fr['tbdataf']?',stb':','.$field;
		$fieldform="<input type='hidden' name='field' value='".$field."'>";
		if(empty($public_r[dorepnum]))
		{
			$public_r[dorepnum]=600;
		}
		$start=(int)$start;
		$b=0;
		$sql=$empire->query("select id,checked from {$dbtbpre}ecms_".$tbname."_index where id>$start".$add1." order by id limit ".$public_r[dorepnum]);
		while($r=$empire->fetch($sql))
		{
			$b=1;
			$newstart=$r[id];
			//返回表
			$infotb=ReturnInfoMainTbname($tbname,$r['checked']);
			//主表
			$infor=$empire->fetch1("select isurl".$selectf." from ".$infotb." where id='$r[id]' limit 1");
			if($infor['isurl'])
			{
				continue;
			}
			if($fr['tbdataf'])//副表
			{
				//返回表信息
				$infodatatb=ReturnInfoDataTbname($tbname,$r['checked'],$infor['stb']);
				$finfor=$empire->fetch1("select ".$field." from ".$infodatatb." where id='$r[id]' limit 1");
				$newvalue=DoRepNewstextZz($oldword,$newword,stripSlashes($finfor[$field]));//正则替换
				$empire->query("update ".$infodatatb." set ".$field."='".addslashes($newvalue)."' where id='$r[id]'");
			}
			else//主表
			{
				$newvalue=DoRepNewstextZz($oldword,$newword,stripSlashes($infor[$field]));//正则替换
				$empire->query("update ".$infotb." set ".$field."='".addslashes($newvalue)."' where id='$r[id]'");
			}
		}
		//替换完毕
		if(empty($b))
		{
			insert_dolog("tbname=".$tbname."&field=".$field."<br>oldword=".$oldword."<br>newword=".$newword);//操作日志
			printerror("DoRepNewstextSuccess","db/RepNewstext.php?tid=$tid".hReturnEcmsHashStrHref2(0));
		}
		EchoRepFieldForm($tid,$tbname,$over,$dozz,$dotxt,$newstart,$fieldform,$classid,$postoldword,$postnewword);
	}
	//普通替换
	else
	{
		$repoldword=eaddslashes2($oldword);
		$repnewword=eaddslashes2($newword);
		if($over==1)//完全替换
		{
			if(empty($add2))
			{
				$and=" where ";
			}
			else
			{
				$and=" and ";
			}
			$add2.=$and.$field."='".$repoldword."'";
		}
		if($fr['tbdataf'])//副表
		{
			//已审核
			$tbr=$empire->fetch1("select datatbs from {$dbtbpre}enewstable where tbname='$tbname' limit 1");
			if($tbr['datatbs'])
			{
				$dtbr=explode(',',$tbr['datatbs']);
				$count=count($dtbr);
				for($i=1;$i<$count-1;$i++)
				{
					$empire->query("update {$dbtbpre}ecms_".$tbname."_data_".$dtbr[$i]." set ".$field."=REPLACE(".$field.",'$repoldword','$repnewword')".$add2);
				}
			}
			//未审核
			$empire->query("update {$dbtbpre}ecms_".$tbname."_check_data set ".$field."=REPLACE(".$field.",'$repoldword','$repnewword')".$add2);
		}
		else//主表
		{
			$empire->query("update {$dbtbpre}ecms_".$tbname." set ".$field."=REPLACE(".$field.",'$repoldword','$repnewword')".$add2);
			//未审核
			$empire->query("update {$dbtbpre}ecms_".$tbname."_check set ".$field."=REPLACE(".$field.",'$repoldword','$repnewword')".$add2);
		}
		//替换完毕
		insert_dolog("tbname=".$tbname."&field=".$field."<br>oldword=".$oldword."<br>newword=".$newword);//操作日志
		printerror("DoRepNewstextSuccess","db/RepNewstext.php?tid=$tid".hReturnEcmsHashStrHref2(0));
	}
}
コード例 #2
0
function DoRepNewstext($start, $oldword, $newword, $field, $classid, $tid, $tbname, $over, $dozz, $dotxt, $userid, $username)
{
    global $empire, $public_r, $class_r, $fun_r, $dbtbpre, $emod_r;
    $tbname = RepPostVar($tbname);
    $field = RepPostVar($field);
    $tid = (int) $tid;
    $dotype = (int) $_POST['dotype'];
    if (!$field || empty($tbname) || !$tid) {
        printerror("FailCX", "history.go(-1)");
    }
    if ($dotype == 0 && strlen($oldword) == 0) {
        printerror("FailCX", "history.go(-1)");
    }
    CheckLevel($userid, $username, $classid, "repnewstext");
    //验证权限
    //变量替换
    $postoldword = ClearAddsData($oldword);
    $postnewword = ClearAddsData($newword);
    //替换条件
    if ($classid) {
        if (empty($class_r[$classid][islast])) {
            $where = ReturnClass($class_r[$classid][sonclass]);
        } else {
            $where = "classid='{$classid}'";
        }
        $add1 = " and (" . $where . ")";
        $add2 = " where (" . $where . ")";
    }
    $fr = $empire->fetch1("select tid,savetxt,tbdataf from {$dbtbpre}enewsf where tbname='{$tbname}' and f='{$field}' limit 1");
    //覆盖方式
    if ($dotype == 1) {
        $repoldword = addslashes($oldword);
        $repnewword = addslashes($newword);
        if ($over == 1) {
            if (empty($add2)) {
                $and = " where ";
            } else {
                $and = " and ";
            }
            $add2 .= $and . $field . "='" . $repoldword . "'";
        }
        if ($fr['tbdataf']) {
            $tbr = $empire->fetch1("select datatbs from {$dbtbpre}enewstable where tbname='{$tbname}' limit 1");
            if ($tbr['datatbs']) {
                $dtbr = explode(',', $tbr['datatbs']);
                $count = count($dtbr);
                for ($i = 1; $i < $count - 1; $i++) {
                    $empire->query("update {$dbtbpre}ecms_" . $tbname . "_data_" . $dtbr[$i] . " set " . $field . "='{$repnewword}'" . $add2);
                }
            }
        } else {
            $empire->query("update {$dbtbpre}ecms_" . $tbname . " set " . $field . "='{$repnewword}'" . $add2);
        }
        //替换完毕
        insert_dolog("tbname=" . $tbname . "&field=" . $field . "&dotype=1<br>oldword=" . $oldword . "<br>newword=" . $newword);
        //操作日志
        printerror("DoRepNewstextSuccess", "db/RepNewstext.php?tid={$tid}");
    } elseif ($fr['savetxt']) {
        $repoldword = addslashes($postoldword);
        $repnewword = addslashes($postnewword);
        //字段
        $selectf = $fr['tbdataf'] ? ',stb' : ',' . $field;
        $fieldform = "<input type='hidden' name='field' value='" . $field . "'>";
        if (empty($public_r[dorepnum])) {
            $public_r[dorepnum] = 600;
        }
        $start = (int) $start;
        $b = 0;
        $sql = $empire->query("select id" . $selectf . " from {$dbtbpre}ecms_" . $tbname . " where id>{$start}" . $add1 . " and titleurl='' order by id limit " . $public_r[dorepnum]);
        while ($r = $empire->fetch($sql)) {
            $b = 1;
            $newstart = $r[id];
            //副表
            if ($fr['tbdataf']) {
                $finfor = $empire->fetch1("select " . $field . " from {$dbtbpre}ecms_" . $tbname . "_data_" . $r[stb] . " where id='{$r['id']}'");
                $r[$field] = $finfor[$field];
            }
            $value = GetTxtFieldText($r[$field]);
            if (empty($value)) {
                continue;
            }
            if ($dozz == 1) {
                $newvalue = DoRepNewstextZz($repoldword, $repnewword, $value);
                //正则替换
            } else {
                if (!stristr($value, $repoldword)) {
                    continue;
                }
                $newvalue = str_replace($repoldword, $repnewword, $value);
            }
            EditTxtFieldText($r[$field], $newvalue);
        }
        //替换完毕
        if (empty($b)) {
            insert_dolog("tbname=" . $tbname . "&field=" . $field . "<br>oldword=" . $oldword . "<br>newword=" . $newword);
            //操作日志
            printerror("DoRepNewstextSuccess", "db/RepNewstext.php?tid={$tid}");
        }
        EchoRepFieldForm($tid, $tbname, $over, $dozz, $dotxt, $newstart, $fieldform, $classid, $postoldword, $postnewword);
    } elseif ($dozz == 1) {
        //字段
        $selectf = $fr['tbdataf'] ? ',stb' : ',' . $field;
        $fieldform = "<input type='hidden' name='field' value='" . $field . "'>";
        if (empty($public_r[dorepnum])) {
            $public_r[dorepnum] = 600;
        }
        $start = (int) $start;
        $b = 0;
        $sql = $empire->query("select id" . $selectf . " from {$dbtbpre}ecms_" . $tbname . " where id>{$start}" . $add1 . " and titleurl='' order by id limit " . $public_r[dorepnum]);
        while ($r = $empire->fetch($sql)) {
            $b = 1;
            $newstart = $r[id];
            if ($fr['tbdataf']) {
                $finfor = $empire->fetch1("select " . $field . " from {$dbtbpre}ecms_" . $tbname . "_data_" . $r[stb] . " where id='{$r['id']}'");
                $newvalue = DoRepNewstextZz($oldword, $newword, stripSlashes($finfor[$field]));
                //正则替换
                $empire->query("update {$dbtbpre}ecms_" . $tbname . "_data_" . $r[stb] . " set " . $field . "='" . addslashes($newvalue) . "' where id='{$r['id']}'");
            } else {
                $newvalue = DoRepNewstextZz($oldword, $newword, stripSlashes($r[$field]));
                //正则替换
                $empire->query("update {$dbtbpre}ecms_" . $tbname . " set " . $field . "='" . addslashes($newvalue) . "' where id='{$r['id']}'");
            }
        }
        //替换完毕
        if (empty($b)) {
            insert_dolog("tbname=" . $tbname . "&field=" . $field . "<br>oldword=" . $oldword . "<br>newword=" . $newword);
            //操作日志
            printerror("DoRepNewstextSuccess", "db/RepNewstext.php?tid={$tid}");
        }
        EchoRepFieldForm($tid, $tbname, $over, $dozz, $dotxt, $newstart, $fieldform, $classid, $postoldword, $postnewword);
    } else {
        $repoldword = addslashes($oldword);
        $repnewword = addslashes($newword);
        if ($over == 1) {
            if (empty($add2)) {
                $and = " where ";
            } else {
                $and = " and ";
            }
            $add2 .= $and . $field . "='" . $repoldword . "'";
        }
        if ($fr['tbdataf']) {
            $tbr = $empire->fetch1("select datatbs from {$dbtbpre}enewstable where tbname='{$tbname}' limit 1");
            if ($tbr['datatbs']) {
                $dtbr = explode(',', $tbr['datatbs']);
                $count = count($dtbr);
                for ($i = 1; $i < $count - 1; $i++) {
                    $empire->query("update {$dbtbpre}ecms_" . $tbname . "_data_" . $dtbr[$i] . " set " . $field . "=REPLACE(" . $field . ",'{$repoldword}','{$repnewword}')" . $add2);
                }
            }
        } else {
            $empire->query("update {$dbtbpre}ecms_" . $tbname . " set " . $field . "=REPLACE(" . $field . ",'{$repoldword}','{$repnewword}')" . $add2);
        }
        //替换完毕
        insert_dolog("tbname=" . $tbname . "&field=" . $field . "<br>oldword=" . $oldword . "<br>newword=" . $newword);
        //操作日志
        printerror("DoRepNewstextSuccess", "db/RepNewstext.php?tid={$tid}");
    }
}