网站一定要每天都更新用户体验才会好,但站长的时间有限不可能天天都打开电脑发布新内容,那我们就需要一个自动发布程序,将我们录入好的内容每天按时自动发布。下面我就将具体的方法交给大家,需要配合宝塔一起使用。
1. 找到/e/extend/ 在该目录下新建文件夹已经建一个php文件:
/e/extend/DoTimeRepage/doZyz.php
doZyz.php文件代码:
<?php
require("../../class/connect.php");
require("../../class/db_sql.php");
require("../../class/functions.php");
require '../'.LoadLang("pub/fun.php");
require("../../class/t_functions.php");
require("../../data/dbcache/class.php");
require("../../data/dbcache/MemberLevel.php");
$link=db_connect();
$empire=new mysqlquery();
$editor=1;
@set_time_limit(0);
//定时刷新任务
function user_DoTimeRepage(){
global $empire,$dbtbpre;
auto_checkInfo(2);
$todaytime=time();
$b=0;
$sql=$empire->query("select doing,classid,doid from {$dbtbpre}enewsdo where isopen=1 and lasttime+dotime*60<$todaytime");
while($r=$empire->fetch($sql))
{
$b=1;
if($r[doing]==1)//生成栏目
{
$cr=explode(',',$r[classid]);
$count=count($cr)-1;
for($i=1;$i<$count;$i++)
{
if(empty($cr[$i]))
{
continue;
}
ReListHtml($cr[$i],1);
}
}
elseif($r[doing]==2)//生成专题
{
$cr=explode(',',$r[classid]);
$count=count($cr)-1;
for($i=1;$i<$count;$i++)
{
if(empty($cr[$i]))
{
continue;
}
ListHtmlIndex($cr[$i],$ret_r[0],0);
}
}
elseif($r[doing]==3)//生成自定义列表
{
$cr=explode(',',$r[classid]);
$count=count($cr)-1;
for($i=1;$i<$count;$i++)
{
if(empty($cr[$i]))
{
continue;
}
$ur=$empire->fetch1("select listid,pagetitle,filepath,filetype,totalsql,listsql,maxnum,lencord,listtempid,pagekeywords,pagedescription from {$dbtbpre}enewsuserlist where listid='".$cr[$i]."'");
ReUserlist($ur,"../");
}
}
elseif($r[doing]==4)//生成自定义页面
{
$cr=explode(',',$r[classid]);
$count=count($cr)-1;
for($i=1;$i<$count;$i++)
{
if(empty($cr[$i]))
{
continue;
}
$ur=$empire->fetch1("select id,path,pagetext,title,pagetitle,pagekeywords,pagedescription,tempid from {$dbtbpre}enewspage where id='".$cr[$i]."'");
ReUserpage($ur[id],$ur[pagetext],'../'.$ur[path],$ur[title],$ur[pagetitle],$ur[pagekeywords],$ur[pagedescription],$ur[tempid]);
}
}
elseif($r[doing]==5)//生成自定义JS
{
$cr=explode(',',$r[classid]);
$count=count($cr)-1;
for($i=1;$i<$count;$i++)
{
if(empty($cr[$i]))
{
continue;
}
$ur=$empire->fetch1("select jsid,jsname,jssql,jstempid,jsfilename from {$dbtbpre}enewsuserjs where jsid='".$cr[$i]."'");
ReUserjs($ur,'../');
}
}
else//生成首页
{
$indextemp=GetIndextemp();
NewsBq($classid,$indextemp,1,0);
}
$empire->query("update {$dbtbpre}enewsdo set lasttime=$todaytime where doid='$r[doid]'");
}
if($b)
{
echo "最后执行时间:".date("Y-m-d H:i:s",$todaytime)."<br><br>";
}
}
//自动生成未审核的文章,每次生成5条
function auto_checkInfo($num=5){
global $empire,$dbtbpre,$class_r,$emod_r,$public_r;
$todaytime=time();
$sql="select id,classid from {$dbtbpre}ecms_news_index where checked=0 order by id asc limit ".$num;
$sql=$empire->query($sql);
while($r=$empire->fetch($sql)){
$empire->query("update {$dbtbpre}ecms_news_index set checked=1 where id='$r[id]' limit 1");
$pubid=ReturnInfoPubid($r['classid'],$r['id']);
$infor=$empire->fetch1("select * from {$dbtbpre}ecms_news_check where id='$r[id]' limit 1");
//互转
MoveCheckInfoData('news',0,$infor['stb'],"id='$r[id]'");
AddClassInfos($r['classid'],'','+1');
//刷新信息
GetHtml($infor['classid'],$infor['id'],$infor,1);
//刷新列表
ReListHtml($r[classid],1);
}
}
user_DoTimeRepage();//自动刷新页面
db_close();
$empire=null;
?>
2.在栏目自定义页面新建一个自定义页面,命名:auto_pub.html
auto_pub.html代码如下:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>auto_pub</title>
<script src="/e/extend/DoTimeRepage/doZyz.php"></script>
</head>
<body>
孟垂博官网详细教程之自动审核插件
</body>
</html>
到这里算是完成了80%,只要是访问这个自定义页面就相当于做了一次代码执行,随机审核5篇文章。
如果想要达到间隔某个时段自定审核的功能,这里运用宝塔面板自带功能进行操作。(这一步也是小白不懂得地方)