原理

使文章处于审核状态,只要到了设定的时间,一旦有用户访问有触发代码的页面,则自动通过审核,时间不到则不会通过审核。
用户访问最多的一般是文章内页,所以通常我们会把这个触发代码加入统计文章浏览次数的文件中去。

方法

修改栏目工作流为 一级审核,这时在发布内容时会有一个审核的选项,我们在发布文章时要把状态选择为 审核。
然后就是触发文件中写入代码,打开/api/count.php 定位到文件最后 的 ?>之前,分为以下两种情况插入代码
动态页面插入以下代码即可

//add 定时发布审核功能
$modelid = $modelid ? $modelid : intval($_GET["modelid"]);
$content_db = $content_db ? $content_db : pc_base::load_model("content_model");
$content_db->set_model($modelid);
$where = " status = 1 and inputtime <= ".SYS_TIME;
$r = $content_db->count($where);
if( !empty($r) ){ //执行update操作
$content_db->update( array("status"=>99),$where );
}

如果要支持生成静态HTML文件的话,就不要用上面的代码了。下面是来自PHPCMS官方论坛的代码,动态,静态都可以完美执行。
支持静态或动态的定时代码


//add 定时发布审核功能
$urlobj = pc_base::load_app_class("url", "content");
$html = pc_base::load_app_class("html", "content");
$modelid = $modelid ? $modelid : intval($_GET["modelid"]);
$content_db = $content_db ? $content_db : pc_base::load_model("content_model");
$content_db->set_model($modelid);
$where = " status = 1 and inputtime <= ".SYS_TIME;
$r = $content_db->count($where);
if( !empty($r) ){ //执行update操作
$ids = $content_db->select($where, "id,catid", $r, "", "", "id");
foreach($ids AS $kid=>$v){
$catid = $v["catid"];
$id = $kid;
$r = $content_db->get_content($catid,$id);
$urls = $urlobj->show($id, 0, $catid, $r["inputtime"], $r["prefix"],$r,"add");
if($urls["content_ishtml"]) $html->show($urls[1],$urls["data"],0);
$html->index();
$html->create_relation_html($catid);
}
$content_db->update( array("status"=>99),$where );
}

修改过的count.php文件已经提供:点此下载
要触发定时功能,必须加入统计文章浏览次数的代码,搜索引擎很少回去访问js内容,所以一般人工访问,js才能执行。

<script language="JavaScript" src="{APP_PATH}api.php?op=count&id={$id}&modelid={$modelid}"></script>

结语

注意:静态列表页并不会实时更新,只有在下一篇定时文章发布成功后,列表页才会更新上一篇的文章。不过这根本不影响大局。
如果是新站,没有人访问,自己又懒得去访问,那么只好用VPS的计划任务了,定时访问网站内页即可。或者用其他类似流量精灵什么的软件,总之可以让她定时访问页面即可。
参考文献:http://bbs.phpcms.cn/thread-713552-1-1.html

版权声明:本文为李维亮博主的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:http://www.liweiliang.com/116.html

标签: phpcms实现文章定时发布功能(支持静态)

评论已关闭