/** * Get all comments for given parameters * @param string Object id (can be a module name) * @param string Params for comment item * @param string Object type (eg. module, plugin, etc) * @param int Comment parent id, will return all comments under a given parent * @param int User that has been posted the comments * @return array */ public function get_comments($obj, $params, $type = 'module', $parent = 0, $user = null, $assign = true) { global $xoopsUser; define('COMMENTS_INCLUDED', 1); $db = Database::getInstance(); $rmc_config = RMFunctions::configs(); $params = urlencode($params); $sql = "SELECT * FROM " . $db->prefix("rmc_comments") . " WHERE status='approved' AND id_obj='{$obj}' AND params='{$params}' AND type='{$type}' AND parent='{$parent}'" . ($user == null ? '' : " AND user='******'") . " ORDER BY posted"; $result = $db->query($sql); $ucache = array(); $ecache = array(); while ($row = $db->fetchArray($result)) { $com = new RMComment(); $com->assignVars($row); // Editor data if (!isset($ecache[$com->getVar('user')])) { $ecache[$com->getVar('user')] = new RMCommentUser($com->getVar('user')); } $editor = $ecache[$com->getVar('user')]; if ($editor->getVar('xuid') > 0) { if (!isset($ucache[$editor->getVar('xuid')])) { $ucache[$editor->getVar('xuid')] = new XoopsUser($editor->getVar('xuid')); } $user = $ucache[$editor->getVar('xuid')]; $poster = array('id' => $user->getVar('uid'), 'name' => $user->getVar('uname'), 'email' => $user->getVar('email'), 'posts' => $user->getVar('posts'), 'avatar' => XOOPS_UPLOAD_URL . '/' . $user->getVar('user_avatar'), 'rank' => $user->rank(), 'url' => $user->getVar('url') != 'http://' ? $user->getVar('url') : ''); } else { $poster = array('id' => 0, 'name' => $editor->getVar('name'), 'email' => $editor->getVar('email'), 'posts' => 0, 'avatar' => '', 'rank' => '', 'url' => $editor->getVar('url') != 'http://' ? $editor->getVar('url') : ''); } if ($xoopsUser && $xoopsUser->isAdmin()) { $editlink = RMCURL . '/comments.php?action=edit&id=' . $com->id() . '&ret=' . urlencode(self::current_url()); } elseif ($rmc_config['allow_edit']) { $time_limit = time() - $com->getVar('posted'); if ($xoopsUser && $xoopsUser->getVar('uid') == $editor->getVar('xuid') && $time_limit < $rmc_config['edit_limit'] * 3600) { $editlink = RMCURL . '/post_comment.php?action=edit&id=' . $com->id() . '&ret=' . urlencode(self::current_url()); } else { $editlink = ''; } } $comms[] = array('id' => $row['id_com'], 'text' => TextCleaner::getInstance()->clean_disabled_tags(TextCleaner::getInstance()->popuplinks(TextCleaner::getInstance()->nofollow($com->getVar('content')))), 'poster' => $poster, 'posted' => sprintf(__('Posted on %s'), formatTimestamp($com->getVar('posted'), 'l')), 'ip' => $com->getVar('ip'), 'edit' => $editlink); unset($editor); } $comms = RMEvents::get()->run_event('rmcommon.loading.comments', $comms, $obj, $params, $type, $parent, $user); global $xoopsTpl; $xoopsTpl->assign('lang_edit', __('Edit', 'rmcommon')); if ($assign) { $xoopsTpl->assign('comments', $comms); return true; } else { return $comms; } }