dedeCMS 织梦执行入库 PHP代码

<?php
//dedeCMS 织梦执行入库
set_time_limit(0);
date_default_timezone_set("PRC");
function getData(){
$finaldata = array();
$content=@file_get_contents('data.txt');
$key=explode('=e=',$content);
for($i=0;$i<count($key)-1;$i++){
	$keys=explode('=t=',$key[$i]);
	$j=0;
	foreach($keys as $keyes){
		$finaldata[$i][$j]=$keyes;
		$j++;
		if($j>=2)break;
	}
}
return $finaldata;
}

 
 include_once ($_SERVER['DOCUMENT_ROOT']."/data/common.inc.php"); 
//dede数据库连接信�?
// $cfg_dbhost = 'localhost';
// $cfg_dbname = '789dede.com';
// $cfg_dbuser = 'root';
// $cfg_dbpwd = 'root';
// $cfg_dbprefix = 'tf_';
// $cfg_db_language = 'utf8';
 
 $archives= $cfg_dbprefix."archives";
 $arctiny= $cfg_dbprefix."arctiny";
 $addonarticle= $cfg_dbprefix."addonarticle" ; 

 
//echo DB_HOST;
	$link=mysqli_connect($cfg_dbhost,$cfg_dbuser,$cfg_dbpwd) or die("database connect wrong".mysql_error());//自己设置
  mysqli_select_db($link,$cfg_dbname)  or die("database wrong".mysql_error());//自己设置
	mysqli_set_charset($link,'utf8');  
	$datatitle="";
	$postcontent="";
    $id=mysqli_query($link,"select max(id) from $archives");//得到当前最大信息id以免信息id重复
		 
 
	while($t_result = mysqli_fetch_array($id) ){
 	$testarr=$t_result;
	}
	$dataid=$testarr[0]+1;
	$mm=getData();
	$tt=(array_values($mm));
	//print_r ($tt);
 

	for($i=0; $i<count($mm); $i++){
	        $posttitle =$tt[$i][0];   
			$postcontent = $tt[$i][1].$posttitle; // echo "$postcontent ";
 
  			//$postname = preg_replace("/[^\w]/i","-",$posttitle);//得到 postname (url)
  			//$postname = preg_replace("/[^\x{4e00}-\x{9fa5}a-zA-Z0-9]/i","",$postname); //hanzi汉字 
 	        $postname= urlencode ($posttitle ) ;
 	        $postname = preg_replace("/^[\W]/i","",$postname);//把开头为非[\W].替换成空'
 	        $postname = preg_replace("/\+/i","-",$postname);//把+.替换成'
			$postname = preg_replace("/-{2,}/i","-",$postname);
			$postname = preg_replace("/\+{2,}/i","-",$postname);
			$postname = preg_replace("/-$/i","",$postname);//把最后的-.替换成空''
			$postname = preg_replace("/^-/i","",$postname);//把开头为-.替换成空'
			$postname = preg_replace("/\+$/i","",$postname);//把为+.替换成空'
			$postname = preg_replace("/^\+/i","",$postname);//把开头为+.替换成空'
			$postname = preg_replace("/^0A/i","",$postname);//把开头为+.替换成空'
			

			
             
            $intime=  "1646982832"; //strtotime(date("Y/m/d"));  echo $intime ; // strtotime(date("Y/m/d"));
            $fenlei="62"; //分类ID
            
//INSERT INTO `789dede.com`.`tf_archives` (`id`, `typeid`, `typeid2`, `sortrank`, `flag`, `ismake`, `channel`, `arcrank`, `click`, `money`, `title`, `shorttitle`, `color`, `writer`, `source`, `litpic`, `pubdate`, `senddate`, `mid`, `keywords`, `lastpost`, `scores`, `goodpost`, `badpost`, `voteid`, `notpost`, `description`, `filename`, `dutyadmin`, `tackid`, `mtype`, `weight`) VALUES ('0', '0', '0', '0', NULL, '0', '62', '0', '0', '0', 'titl', '', '', '', '', '', '0', '0', '0', '', '0', '0', '0', '0', '', '0', '455', '', '0', '0', '0', '0');
//
//INSERT INTO `789dede.com`.`tf_arctiny` (`id`, `typeid`, `typeid2`, `arcrank`, `channel`, `senddate`, `sortrank`, `mid`) VALUES (NULL, '62', '0', '0', '1', '1646982832', '1646982742', '2');
//
//INSERT INTO `789dede.com`.`tf_addonarticle` (`aid`, `typeid`, `body`, `redirecturl`, `templet`, `userip`) VALUES ('903', '62', ' ', '', '', '127.0.0.1');

$result=mysqli_query($link," INSERT INTO `$archives` (`id`, `title`,`description`,`typeid`,`pubdate`, `senddate`,`ismake`,`mid`   ) VALUES ( '$dataid' ,' $posttitle' ,' $posttitle ', '$fenlei' ,'$intime','$intime','1','2'   )  ");

$result2=mysqli_query($link,"INSERT INTO `$arctiny` (`id`, `typeid`,  `senddate`, `sortrank`, `mid` ) VALUES ('$dataid' ,' $fenlei' ,'$intime','$intime' , '2' ) " ) ;
$result3=mysqli_query($link,"INSERT INTO `$addonarticle` (`aid`, `typeid`, `body`  ) VALUES ('$dataid' ,' $fenlei' ,'$postcontent' ) " ) ;
 

 $dataid++;
			
  
	} //for
	 
if($result3){
//unlink('data.txt');
echo 'yes<br>';
rename("data.txt", "data-1.txt");
}else{
echo 'error <br>';
}
  

 mysqli_close($link);
?>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值