PHPCMS v9定时发布的简单实现方法[支持静态生成]
将以下代码放到 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( !emptyempty($r) ){ //执行update操作
$content_db->update( array('status'=>99),$where );
}这样就行了,然后记得修改文字发布需要审核才能通过,不然发出去直接就通过了,另外就是发布时间要设置为未来的时间,这样才能定时.
不是严格意义上的定时发布,当有用户访问你的内容页时,触发了内容页的:
<script language="JavaScript" src="{APP_PATH}api.php?op=count&id={$id}&modelid={$modelid}"></script>js,就会执行上面的通过审核代码.
注意,仅适用于伪静态.生成静态的需要额外的静态化操作.可跟帖说明是否需要,需求大可以提供代码.
静态方法:
//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( !emptyempty($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文件已经提供:
<?php
defined('IN_PHPCMS') or exit('No permission resources.');
/**
* 点击统计
*/
$db = '';
$db = pc_base::load_model('hits_model');
if($_GET['modelid'] && $_GET['id']) {
$model_arr = array();
$model_arr = getcache('model','commons');
$modelid = intval($_GET['modelid']);
$hitsid = 'c-'.$modelid.'-'.intval($_GET['id']);
$r = get_count($hitsid);
if(!$r) exit;
extract($r);
hits($hitsid);
echo "$('#todaydowns').html('$dayviews');";
echo "$('#weekdowns').html('$weekviews');";
echo "$('#monthdowns').html('$monthviews');";
} elseif($_GET['module'] && $_GET['id']) {
$module = $_GET['module'];
if((preg_match('/([^a-z0-9_-]+)/i',$module))) exit('1');
$hitsid = $module.'-'.intval($_GET['id']);
$r = get_count($hitsid);
if(!$r) exit;
extract($r);
hits($hitsid);
}
/**
* 获取点击数量
* @param $hitsid
*/
function get_count($hitsid) {
global $db;
$r = $db->get_one(array('hitsid'=>$hitsid));
if(!$r) return false;
return $r;
}
/**
* 点击次数统计
* @param $contentid
*/
function hits($hitsid) {
global $db;
$r = $db->get_one(array('hitsid'=>$hitsid));
if(!$r) return false;
$views = $r['views'] + 1;
$yesterdayviews = (date('Ymd', $r['updatetime']) == date('Ymd', strtotime('-1 day'))) ? $r['dayviews'] : $r['yesterdayviews'];
$dayviews = (date('Ymd', $r['updatetime']) == date('Ymd', SYS_TIME)) ? ($r['dayviews'] + 1) : 1;
$weekviews = (date('YW', $r['updatetime']) == date('YW', SYS_TIME)) ? ($r['weekviews'] + 1) : 1;
$monthviews = (date('Ym', $r['updatetime']) == date('Ym', SYS_TIME)) ? ($r['monthviews'] + 1) : 1;
$sql = array('views'=>$views,'yesterdayviews'=>$yesterdayviews,'dayviews'=>$dayviews,'weekviews'=>$weekviews,'monthviews'=>$monthviews,'updatetime'=>SYS_TIME);
return $db->update($sql, array('hitsid'=>$hitsid));
}
//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( !emptyempty($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 );
}
?>
$('#hits').html('<?php echo $views?>');注意:生成静态的网站请看14楼代码或者上面的附件, 需要访问了待定时发布的文章所在模型的任意一篇可正常浏览的文章即可,主要是为了触发上面的js,搜索引擎访问的无效,必须是人为访问,js能得以执行.
您可能感兴趣的文章
- 11-16phpcms全站最新文章和随机文章
- 11-16PHPCMS v9远程附件功能
- 11-16PHPCMS V9相关文章自动调用的实现方法
- 11-16PHPCMS V9 ckeditor编辑器代码高亮显示(附插件)
- 11-16phpcms v9取组图的第一张或第N张图为缩略图
- 11-16phpcms v9如何更改分页显示条数?
- 11-16Phpcms V9单页添加自定义字段
- 11-16PHPCMS V9静态化HTML生成设置及URL规则优化
- 11-16PHPCMS V9 全站通用日期时间标签
- 11-16phpcms v9调用多个栏目下文章的方法


阅读排行
推荐教程
- 09-22phpcms是什么框架
- 09-22phpcms手机端如何取消伪静态
- 11-12phpcms如何使用水印功能
- 11-12phpcms不限制模型进行全站搜索
- 11-12phpcms栏目标签调用代码大全
- 11-12phpcms二次开发用拼音作为tags列表页路径的方法
- 11-12如何用phpcms调取指定位置的新闻列表
- 11-16Phpcms V9列表分页自定义页码文字(改成中文)
- 11-16phpcms ajax列表分页加载更多
- 11-16Phpcms v9翻页增加下拉跳转的自定义方法





