1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10:
11:
12: 13: 14: 15: 16: 17: 18: 19:
20:
21: function b_comments_show($options)
22: {
23: $xoops = Xoops::getInstance();
24: $helper = $xoops->getModuleHelper('comments');
25:
26: $block = array();
27: $available_modules = \Xoops\Module\Plugin::getPlugins('comments');
28: if (empty($available_modules)) {
29: return $block;
30: }
31:
32: $comment_handler = $helper->getHandlerComment();
33: $criteria = new CriteriaCompo(new Criteria('status', Comments::STATUS_ACTIVE));
34: $criteria->setLimit((int)($options[0]));
35: $criteria->setSort('created');
36: $criteria->setOrder('DESC');
37:
38:
39: $moduleperm_handler = $xoops->getHandlerGroupPermission();
40: $gperm_groupid = $xoops->getUserGroups();
41: $criteria1 = new CriteriaCompo(new Criteria('gperm_name', 'module_read', '='));
42: $criteria1->add(new Criteria('gperm_groupid', '(' . implode(',', $gperm_groupid) . ')', 'IN'));
43: $perms = $moduleperm_handler->getObjects($criteria1, true);
44: $modIds = array();
45: foreach ($perms as $item) {
46: $modIds[] = $item->getVar('gperm_itemid');
47: }
48: if (count($modIds) > 0) {
49: $modIds = array_unique($modIds);
50: $criteria->add(new Criteria('modid', '(' . implode(',', $modIds) . ')', 'IN'));
51: } else {
52: return $block;
53: }
54:
55: $comments = $comment_handler->getObjects($criteria, true);
56: $member_handler = $xoops->getHandlerMember();
57: $module_handler = $xoops->getHandlerModule();
58: $modules = $module_handler->getObjectsArray(new Criteria('dirname', "('" . implode("','", array_keys($available_modules)) ."')", 'IN'), true);
59: $comment_config = array();
60: foreach (array_keys($comments) as $i) {
61: $mid = $comments[$i]->getVar('modid');
62: $com['module'] = '<a href="' . \XoopsBaseConfig::get('url') . '/modules/' . $modules[$mid]->getVar('dirname') . '/">' . $modules[$mid]->getVar('name') . '</a>';
63: if (!isset($comment_config[$mid])) {
64: $comment_config[$mid] = \Xoops\Module\Plugin::getPlugin($modules[$mid]->getVar('dirname'), 'comments');
65: }
66: $com['id'] = $i;
67: $com['title'] = '<a href="' . \XoopsBaseConfig::get('url') . '/modules/' . $modules[$mid]->getVar('dirname') . '/' . $comment_config[$mid]->pageName() . '?' . $comment_config[$mid]->itemName() . '=' . $comments[$i]->getVar('itemid') . '&com_id=' . $i . '&com_rootid=' . $comments[$i]->getVar('rootid') . '&' . htmlspecialchars($comments[$i]->getVar('exparams')) . '#comment' . $i . '">' . $comments[$i]->getVar('title') . '</a>';
68: $com['icon'] = htmlspecialchars($comments[$i]->getVar('icon'), ENT_QUOTES);
69: $com['icon'] = ($com['icon'] != '') ? $com['icon'] : 'icon1.gif';
70: $com['time'] = XoopsLocale::formatTimestamp($comments[$i]->getVar('created'), 'm');
71: if ($comments[$i]->getVar('uid') > 0) {
72: $poster = $member_handler->getUser($comments[$i]->getVar('uid'));
73: if (is_object($poster)) {
74: $com['poster'] = '<a href="' . \XoopsBaseConfig::get('url') . '/userinfo.php?uid=' . $comments[$i]->getVar('uid') . '">' . $poster->getVar('uname') . '</a>';
75: } else {
76: $com['poster'] = $xoops->getConfig('anonymous');
77: }
78: } else {
79: $com['poster'] = $xoops->getConfig('anonymous');
80: }
81: $block['comments'][] = $com;
82: unset($com);
83: }
84: return $block;
85: }
86:
87: function b_comments_edit($options)
88: {
89: $block_form = new Xoops\Form\BlockForm();
90: $block_form->addElement(new Xoops\Form\Text(_MB_SYSTEM_DISPLAYC, 'options[0]', 1, 3, $options[0]), true);
91: return $block_form->render();
92: }
93: