A-A+

phpcms 某个模型下 全部文章列表 包括评论数和浏览量

2014年12月10日 PHP开源系统 暂无评论 阅读 27 views 次

phpcms 调取 某个 模型下所有内容列表

action = "mlists"

modelid 模型id,必须,1是文章
siteid 必须
caitid 可以是 2,3,4形式的字符串,也可以是单个catid值

如果要views,comments的数据,moreinfo必须设置成1,只有评论数,没有点击量:

{pc:content action="mlists" modelid="1" siteid="$siteid" catid="2,3,4,5" limit="30" moreinfo="1" comments="1"}

只有点击量,没有评论数:

{pc:content action="mlists" modelid="1" siteid="$siteid" catid="3" limit="30" moreinfo="1" views="1"}

没有浏览量和评论数:

{pc:content action="mlists" modelid="1" siteid="$siteid" catid="$catids" limit="30" views="1"}

浏览数和评论数都有:

{pc:content action="mlists" modelid="1" siteid="$siteid" catid="$catids" limit="30" moreinfo="1" views="1" comments="1"}
{loop $data $r}
{/loop}
{/pc}

php中加入: phpcms/modules/content/classes/content_tag.class.php

public function mlists($data){
if(!isset($data['modelid']) || intval($data['modelid']) <=0 ) return false;
$catid = "1,". $data['catid'];
$siteid = intval($data['siteid']);
static $CATS;
if ($CATS[$siteid]) {
$this->category = $CATS[$siteid];
} else {
$CATS[$siteid] = $this->category = getcache('category_content_'.$siteid,'commons');
}
$this->modelid = $data['modelid'];
$this->db->set_model($this->modelid);
$this->tablename = $this->db->table_name;
if(isset($data['where'])) {
$sql = $data['where'];
} else {
$thumb = intval($data['thumb']) ? " AND thumb != ''" : '';
if($cat_array=explode(',',$catid) ){
$catids_str = $catid;
foreach($cat_array as $k => $v){
if($this->category[$v]['child']) {
$catids_str .= ','.$this->category[$v]['arrchildid'];
}
}
$sql = "status=99 AND catid IN ($catids_str)".$thumb;
}
}
$order = $data['order'];

$return = $this->db->select($sql, '*', $data['limit'], $order, '', 'id');

//调用副表的数据
if (isset($data['moreinfo']) && intval($data['moreinfo']) == 1) {
$ids = array();
foreach ($return as $v) {
if (isset($v['id']) && !emptyempty($v['id'])) {
$ids[] = $v['id'];
$hitsids[$v['id']] = 'c-'.$this->modelid.'-'.$v['id'];
$commentids[$v['id']] = 'content_'.$v['catid'].'-'.$v['id'].'-'.$this->modelid;
} else {
continue;
}
}
if (!emptyempty($ids)) {
$this->db->table_name = $this->db->table_name.'_data';
$ids = implode('\',\'', $ids);
$r = $this->db->select("`id` IN ('$ids')", '*', '', '', '', 'id');
if (!emptyempty($r)) {
foreach ($r as $k=>$v) {
if (isset($return[$k])) $return[$k] = array_merge($v, $return[$k]);
}
}
//查询点击
if (isset($data['views']) && intval($data['views']) == 1) {
$this->db->table_name = "xmlc_hits";
$hitsids_str = implode('\',\'', $hitsids);
$r = $this->db->select("`hitsid` IN ('$hitsids_str')", 'views,hitsid', '', '', '', 'hitsid');
foreach ($r as $k=>$v) {
$id = array_search($k,$hitsids);
if (isset($return[$id])) $return[$id] = array_merge($v, $return[$id]);
}
}
//查询评论数
if (isset($data['comments']) && intval($data['comments']) == 1) {
$this->comment_db = pc_base::load_model('comment_model');
$commentids_str = implode('\',\'', $commentids);
$r = $this->comment_db->select("`commentid` IN ('$commentids_str')", 'count(commentid) as comment_num,commentid', '', '', 'commentid', 'commentid');
if (emptyempty($r)) {
foreach ($return as $k=>$v) {
$return[$k]['comment_num']=0;
}
} else {
foreach ($r as $k=>$v) {
$id = array_search($k,$commentids);
if (isset($return[$id])) $return[$id]['comment_num'] = $v['comment_num'];
}
}
}
}
}
return $return;
}

返回数据单个是:下面是var_dump出来的结果

array(31) {
["views"]=>
string(1) "0"
["hitsid"]=>
string(5) "c-1-1"
["id"]=>
string(1) "1"
["content"]=>
string(1010) " "
["readpoint"]=>
string(1) "0"
["groupids_view"]=>
string(0) ""
["paginationtype"]=>
string(1) "2"
["maxcharperpage"]=>
string(1) "0"
["template"]=>
string(0) ""
["paytype"]=>
string(1) "0"
["relation"]=>
string(0) ""
["voteid"]=>
string(1) "0"
["allow_comment"]=>
string(1) "1"
["copyfrom"]=>
string(9) "人民网"
["catid"]=>
string(2) "15"
["typeid"]=>
string(1) "0"
["title"]=>
string(60) "温州苍南被曝暴力强拆:抗议村民当场被拉走"
["style"]=>
string(0) ""
["thumb"]=>
string(0) ""
["keywords"]=>string(20) ""
["description"]=>string(196) ""
["posids"]=> string(1) "0"
["url"]=>
string(78) "http://127.0.0.1/index.php?m=content&c=index&a=show&catid=9&id=1"
["listorder"]=>string(1) "0"
["status"]=>string(2) "99"
["sysadd"]=>string(1) "1"
["islink"]=> string(1) "0"
["username"]=>string(8) "wangchao"
["inputtime"]=>string(10) "1369276174"
["updatetime"]=>string(10) "1369276174"
["comment_num"]=> int(0)
}

标签:

给我留言