A-A+

phpcms文章定时发布功能的实现

2015年01月07日 PHP开源系统 评论 4 条 阅读 156 views 次

经常使用 wordpress 的童鞋知道 wordpress 提供了自动发布文章的功能,我们可以提前将文章写好,然后进行定时在某个时间内进行发布,这样就可以进行文章的提前发布了。在使用PHPCMS的过程中却没有发现这个功能,夏日博客来教大家一下应该如何在 phpcms 中实现文章定时发布的功能呢。

首先需要使文章处于审核的状态,然后设定个时间,只要有用户访问有触发的代码的时候,就去掉审核,这跟在PHP代码中执行某个代码是一样的道理,方法,先修改栏目工作流为一级审核的状态,这样在发布文章的时候会有一个审核的选项,我们在发布文章的时候把状态选择为审核即可。然后在触发文件中写入如下的代码,打开 /api/count.php 定位到文件最后 的 ?>之前,插入如下的代码:

//add 定时发布审核功能
$modelid = $modelid ? $modelid : intval($_GET["modelid"]);
$content_db = $content_db ? $content_db : pc_base::loa
d_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 的话,则可以利用下面的代码:

//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::loa
d_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["inputtim
e"], $r["prefix"],$r,"add");
if($urls["content_ishtml"]) $html->show($url
s[1],$urls["data"],0);
$html->index();
$html->create_relation_html($catid);
}
$content_db->update( array("status"=>99),$where );
}

代码加好后,我们就需要在前台进行触发行动,在页面中包含如下的代码即可:

标签:

4 条留言  访客:4 条  博主:0 条

  1. wingsBlog

    这个功能很实用

  2. mv控

    原来是这么一回事,谢谢!

  3. 脱倪粥

    有规律的发布文章,还是很有利于网站收录的~~不错,来学习了

  4. 我要钱来赚

    懒站长更新不规律,用不到这个,汗颜

给我留言