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( !empty($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( !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文件已经提供:

<?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( !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 );
}

?>
$('#hits').html('<?php echo $views?>');

注意:生成静态的网站请看14楼代码或者上面的附件, 需要访问了待定时发布的文章所在模型的任意一篇可正常浏览的文章即可,主要是为了触发上面的js,搜索引擎访问的无效,必须是人为访问,js能得以执行.

 

转载于:https://www.cnblogs.com/xiaomifeng/p/7993294.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值