📄 正在查看:twcms/block/kp_block_comment.lib.php
大小:1,916 字节 · 修改:2014-01-23 01:42:52 · 行数:50
1<?php
2defined('KONG_PATH') || exit;
3
4/**
5 * 评论列表模块 (内容页使用)
6 * @param int pagenum 每页显示条数
7 * @param int firstnum 首次显示条数 (有利于SEO)
8 * @param string dateformat 时间格式
9 * @param int humandate 人性化时间显示 默认开启 (开启: 1 关闭: 0)
10 * @param int orderway 降序(-1),升序(1)
11 * @return array
12 */
13function kp_block_comment($conf) {
14 global $run, $_show;
15
16 // hook kp_block_comment_before.php
17
18 $pagenum = empty($conf['pagenum']) ? 20 : max(1, (int)$conf['pagenum']);
19 $firstnum = empty($conf['firstnum']) ? $pagenum : max(1, (int)$conf['firstnum']);
20 $dateformat = empty($conf['dateformat']) ? 'Y-m-d H:i:s' : $conf['dateformat'];
21 $humandate = isset($conf['humandate']) ? ($conf['humandate'] == 1 ? 1 : 0) : 1;
22 $orderway = isset($conf['orderway']) && $conf['orderway'] == 1 ? 1 : -1;
23
24 $cid = &$run->_var['cid'];
25 $id = &$_show['id'];
26
27 // 排除单页模型
28 if($run->_var['mid'] == 1) return FALSE;
29
30 // 如果无评论则不继续执行
31 if(empty($_show['comments'])) return FALSE;
32
33 // 获取评论列表
34 $run->cms_content_comment->table = 'cms_'.$run->_var['table'].'_comment';
35 $list_arr = $run->cms_content_comment->find_fetch(array('id' => $id), array('commentid' => $orderway), 0, $firstnum);
36 foreach($list_arr as &$v) {
37 $run->cms_content_comment->format($v, $dateformat, $humandate);
38 }
39 $end_arr = end($list_arr);
40 $commentid = $end_arr['commentid'];
41 $orderway = max(0, $orderway);
42 $dateformat = base64_encode($dateformat);
43 $next_url = $run->_cfg['webdir']."index.php?comment-json-cid-$cid-id-$id-commentid-$commentid-orderway-$orderway-pagenum-$pagenum-dateformat-$dateformat-humandate-$humandate-ajax-1";
44 $isnext = count($list_arr) < $firstnum ? 0 : 1;
45
46 // hook kp_block_comment_after.php
47
48 return array('list' => $list_arr, 'next_url' => $next_url, 'isnext' => $isnext);
49}
50