XOOPS  2.6.0
comments_blocks.php
Go to the documentation of this file.
1 <?php
2 /*
3  You may not change or alter any portion of this comment or credits
4  of supporting developers from this source code or any supporting source code
5  which is considered copyrighted (c) material of the original comment or credit authors.
6 
7  This program is distributed in the hope that it will be useful,
8  but WITHOUT ANY WARRANTY; without even the implied warranty of
9  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 */
11 
22 {
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_ACTIVE));
34  $criteria->setLimit(intval($options[0]));
35  $criteria->setSort('created');
36  $criteria->setOrder('DESC');
37 
38  // Check modules permissions
39  $moduleperm_handler = $xoops->getHandlerGroupperm();
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') . '&amp;com_id=' . $i . '&amp;com_rootid=' . $comments[$i]->getVar('rootid') . '&amp;' . 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 
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 }
$mid
Definition: index.php:39
static formatTimestamp($time, $format= 'l', $timeoffset=null)
Definition: Abstract.php:289
if($uname== ''||$pass== '') $member_handler
Definition: checklogin.php:44
$i
Definition: dialog.php:68
static getInstance()
Definition: Xoops.php:160
static getInstance()
Definition: helper.php:46
$options['editor']
$comment_handler
Definition: main.php:64
$available_modules
Definition: index.php:65
$xoops
Definition: admin.php:25
b_comments_show($options)
static get($name)
$comments
Definition: main.php:48
b_comments_edit($options)
$modules
Definition: userinfo.php:185
$helper
$criteria
$module_handler
Definition: main.php:55
$moduleperm_handler
Definition: cp_header.php:31