📄 正在查看:twcms/block/kp_block_global_comment.lib.php
1<?php
2defined('KONG_PATH') || exit;
3
4/**
5 * 评论页模块
6 * @param int pagenum 每页显示条数
7 * @param string dateformat 时间格式
8 * @param int humandate 人性化时间显示 默认开启 (开启: 1 关闭: 0)
9 * @param int orderway 降序(-1),升序(1)
10 * @return array
11 */
12function kp_block_global_comment($conf) {
13 global $run, $_show;
14
15 // hook kp_block_global_comment_before.php
16
17 $pagenum = empty($conf['pagenum']) ? 20 : max(1, (int)$conf['pagenum']);
18 $dateformat = empty($conf['dateformat']) ? 'Y-m-d H:i:s' : $conf['dateformat'];
19 $humandate = isset($conf['humandate']) ? ($conf['humandate'] == 1 ? TRUE : FALSE) : TRUE;
20 $orderway = isset($conf['orderway']) && $conf['orderway'] == 1 ? 1 : -1;
21
22 $id = &$_show['id'];
23 $mid = &$run->_var['mid'];
24
25 // 排除单页模型
26 if($mid == 1) return FALSE;
27
28 // 格式化
29 $run->cms_content->format($_show, $mid, $dateformat);
30
31 // 分页相关
32 $total = &$_show['comments'];
33 $maxpage = max(1, ceil($total/$pagenum));
34 $page = min($maxpage, max(1, (int) R('page')));
35 $_show['pages'] = pages($page, $maxpage, $run->cms_content->comment_url($run->_var['cid'], $id, TRUE));
36
37 // 初始模型表名
38 $run->cms_content_comment->table = 'cms_'.$run->_var['table'].'_comment';
39
40 // 获取评论列表
41 $_show['list'] = $run->cms_content_comment->list_arr(array('id' => $id), $orderway, ($page-1)*$pagenum, $pagenum, $total);
42 foreach($_show['list'] as &$v) {
43 $run->cms_content_comment->format($v, $dateformat, $humandate);
44 }
45
46 // hook kp_block_global_comment_after.php
47
48 return $_show;
49}
50