phpcms v9 让点击数自动加到排序

文章由爱资料原创本文地址:

 

函数的使用实例

 

<?php
if (inject_check($_GET[‘id’]))
{
exit(‘提交的数据非法!’);
}
else
{
$id = $_GET[‘id’];
}
?>

 

 

 1 <?php   2 defined('IN_PHPCMS') or exit('No permission resources.');    3 /**   4  * 点击统计   5  */   6 $db = '';   7 $db = pc_base::load_model('hits_model');   8 if($_GET['modelid'] && $_GET['id']) {   9     $model_arr = array();  10     $model_arr = getcache('model','commons');  11     $modelid = intval($_GET['modelid']);  12     $id = intval($_GET['id']);  13     $hitsid = 'c-'.$modelid.'-'.intval($_GET['id']);  14     $r = get_count($hitsid);  15     if(!$r) exit;  16     extract($r);  17     hits($hitsid,$id);  18     echo "$('#todaydowns').html('$dayviews');";  19     echo "$('#weekdowns').html('$weekviews');";  20     echo "$('#monthdowns').html('$monthviews');";  21 } elseif($_GET['module'] && $_GET['id']) {  22     $module = $_GET['module'];  23     if((preg_match('/([^a-z0-9_-]+)/i',$module))) exit('1');  24     $id = intval($_GET['id']);  25     $hitsid = $module.'-'.intval($_GET['id']);  26     $r = get_count($hitsid);  27     if(!$r) exit;  28     extract($r);  29     hits($hitsid,$id);  30 }  31   32   33   34 /**  35  * 获取点击数量  36  * @param $hitsid  37  */  38 function get_count($hitsid) {  39     global $db;  40     $r = $db->get_one(array('hitsid'=>$hitsid));    41     if(!$r) return false;      42     return $r;      43 }  44   45 /**  46  * 点击次数统计  47  * @param $contentid  48  */  49 function hits($hitsid,$id) {  50     global $db;  51     $r = $db->get_one(array('hitsid'=>$hitsid));  52     if(!$r) return false;  53     $views = $r['views'] + 1;  54     $yesterdayviews = (date('Ymd', $r['updatetime']) == date('Ymd', strtotime('-1 day'))) ? $r['dayviews'] : $r['yesterdayviews'];  55     $dayviews = (date('Ymd', $r['updatetime']) == date('Ymd', SYS_TIME)) ? ($r['dayviews'] + 1) : 1;  56     $weekviews = (date('YW', $r['updatetime']) == date('YW', SYS_TIME)) ? ($r['weekviews'] + 1) : 1;  57     $monthviews = (date('Ym', $r['updatetime']) == date('Ym', SYS_TIME)) ? ($r['monthviews'] + 1) : 1;  58     $sql = array('views'=>$views,'yesterdayviews'=>$yesterdayviews,'dayviews'=>$dayviews,'weekviews'=>$weekviews,'monthviews'=>$monthviews,'updatetime'=>SYS_TIME);  59   60 $db2 = pc_base::load_model('content_model');  61 $db2->table_name='v9_news';  62 $sql2 = array('listorder'=>$monthviews);  63 $db2->update($sql2, array('id'=>$id));  64     return $db->update($sql, array('hitsid'=>$hitsid));  65 }  66   67 ?>  68 $('#hits').html('<?php echo $views?>');

/**
 * 点击次数统计
 * @param $contentid
 */
function hits($hitsid,$id) {
 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);

<?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’]);
 $id = intval($_GET[‘id’]);
 $hitsid = ‘c-‘.$modelid.’-‘.intval($_GET[‘id’]);
 $r = get_count($hitsid);
 if(!$r) exit;
    extract($r);
    hits($hitsid,$id);
    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’);
 $id = intval($_GET[‘id’]);
 $hitsid = $module.’-‘.intval($_GET[‘id’]);
 $r = get_count($hitsid);
 if(!$r) exit;
    extract($r);
    hits($hitsid,$id);
}