/** * 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; } }
function show_dashboard() { global $xoopsModule, $cuSettings, $cuIcons; //RMFunctions::create_toolbar(); $db = XoopsDatabaseFactory::getDatabaseConnection(); $sql = 'SELECT * FROM ' . $db->prefix('modules'); $result = $db->query($sql); $installed_mods = array(); while ($row = $db->fetchArray($result)) { $installed_mods[] = $row['dirname']; } require_once XOOPS_ROOT_PATH . "/class/xoopslists.php"; $dirlist = XoopsLists::getModulesList(); $available_mods = array(); $module_handler =& xoops_gethandler('module'); foreach ($dirlist as $file) { clearstatcache(); $file = trim($file); if (!in_array($file, $installed_mods)) { $module =& $module_handler->create(); if (!$module->loadInfo($file, false)) { continue; } $available_mods[] = $module; } } $installed_modules = get_modules_list(); // Modules counter $counterModules = new Common\Widgets\Counter(['id' => 'counter-modules', 'color' => 'red', 'icon' => 'svg-rmcommon-module', 'class' => 'animated bounceIn']); $counterModules->addCell(__('Modules', 'rmcommon'), count($available_mods) + count($installed_modules)); $counterModules->addCell(__('Installed', 'rmcommon'), count($installed_modules)); $counterModules->addCell(__('Available', 'rmcommon'), count($available_mods)); // Users counter $sql = "SELECT COUNT(*) FROM " . $db->prefix("users") . " WHERE level > 0"; list($active) = $db->fetchRow($db->query($sql)); $sql = "SELECT COUNT(*) FROM " . $db->prefix("users") . " WHERE level <= 0"; list($inactive) = $db->fetchRow($db->query($sql)); $counterUsers = new Common\Widgets\Counter(['id' => 'counter-users', 'color' => 'blue', 'icon' => 'svg-rmcommon-users2', 'class' => 'animated bounceIn']); $total = $active + $inactive; $counterUsers->addCell(__('Users', 'rmcommon'), $total); $counterUsers->addCell(__('Active', 'rmcommon'), $active); $counterUsers->addCell(__('Inactive', 'rmcommon'), $inactive); $ratio = $active / ($active + $inactive); if ($ratio < 1) { $ratio = number_format($ratio, 2); } $counterUsers->addCell(__('Ratio', 'rmcommon'), $ratio * 100 . '%'); // Comments counter $counterComments = new Common\Widgets\Counter(['id' => 'counter-comments', 'color' => 'green', 'icon' => 'svg-rmcommon-comments', 'class' => 'animated bounceIn']); list($approved) = $db->fetchRow($db->query("SELECT COUNT(*) FROM " . $db->prefix("mod_rmcommon_comments") . " WHERE status = 'approved'")); list($waiting) = $db->fetchRow($db->query("SELECT COUNT(*) FROM " . $db->prefix("mod_rmcommon_comments") . " WHERE status != 'approved'")); $counterComments->addCell(__('Comments', 'rmcommon'), $approved > 0 || $waiting > 0 ? $approved + $waiting : '0'); $counterComments->addCell(__('Approved', 'rmcommon'), $approved); $counterComments->addCell(__('Waiting', 'rmcommon'), $waiting); $ratio = $approved / ($approved + $waiting); if ($ratio < 1) { $ratio = number_format($ratio, 2); } $counterComments->addCell(__('Ratio', 'rmcommon'), $ratio * 100 . '%'); $counterSystem = new Common\Widgets\Counter(['id' => 'counter-system', 'color' => 'deep-orange', 'icon' => 'svg-rmcommon-rmcommon', 'class' => 'animated bounceIn']); $counterSystem->addCell(__('Current Version', 'rmcommon'), RMModules::get_module_version('rmcommon', false)); $counterSystem->addCell('XOOPS', str_replace('XOOPS ', '', XOOPS_VERSION)); $version = explode('-', phpversion()); $counterSystem->addCell('PHP', $version[0]); unset($version); if (method_exists($db, 'getServerVersion')) { $version = explode("-", $db->getServerVersion()); } else { $version = '--'; } $counterSystem->addCell('MySQL', $version[0]); // Management Tools $managementTools[] = (object) ['caption' => __('Modules', 'rmcommon'), 'link' => 'modules.php', 'icon' => 'svg-rmcommon-module', 'color' => 'pink']; $managementTools[] = (object) ['caption' => __('Blocks', 'rmcommon'), 'link' => 'blocks.php', 'icon' => 'svg-rmcommon-blocks', 'color' => 'blue']; $managementTools[] = (object) ['caption' => __('Users', 'rmcommon'), 'link' => 'users.php', 'icon' => 'svg-rmcommon-user2', 'color' => 'deep-orange']; $managementTools[] = (object) ['caption' => __('Groups', 'rmcommon'), 'link' => 'groups.php', 'icon' => 'svg-rmcommon-users2', 'color' => 'green']; $managementTools[] = (object) ['caption' => __('Images', 'rmcommon'), 'link' => 'images.php', 'icon' => 'svg-rmcommon-images', 'color' => 'purple']; $managementTools[] = (object) ['caption' => __('Comments', 'rmcommon'), 'link' => 'comments.php', 'icon' => 'svg-rmcommon-comments', 'color' => 'red']; $managementTools[] = (object) ['caption' => __('Plugins', 'rmcommon'), 'link' => 'plugins.php', 'icon' => 'svg-rmcommon-plug', 'color' => 'orange']; $managementTools[] = (object) ['caption' => __('Updates', 'rmcommon'), 'link' => 'updates.php', 'icon' => 'svg-rmcommon-update', 'color' => 'teal']; $managementTools[] = (object) ['caption' => __('Preferences', 'rmcommon'), 'link' => 'settings.php?action=configure&mod=rmcommon', 'icon' => 'svg-rmcommon-wrench', 'color' => 'light-blue']; $managementTools = RMEvents::get()->trigger('rmcommon.get.system.tools', $managementTools); // Load recent comments $sql = "SELECT * FROM " . $db->prefix("mod_rmcommon_comments") . " ORDER BY `posted` DESC LIMIT 0, 5"; $result = $db->query($sql); $comments = []; 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 = (object) array('id' => $user->getVar('uid'), 'name' => $user->getVar('uname'), 'email' => $user->getVar('email'), 'posts' => $user->getVar('posts'), 'avatar' => $user->getVar('image') != '' && $user->getVar('image') != 'blank.gif' ? XOOPS_UPLOAD_URL . '/' . $user->getVar('image') : RMCURL . '/images/avatar.gif', 'rank' => $user->rank()); } else { $poster = (object) array('id' => 0, 'name' => $editor->getVar('name'), 'email' => $editor->getVar('email'), 'posts' => 0, 'avatar' => RMCURL . '/images/avatar.gif', 'rank' => ''); } // Get item $cpath = XOOPS_ROOT_PATH . '/modules/' . $row['id_obj'] . '/class/' . $row['id_obj'] . 'controller.php'; if (is_file($cpath)) { if (!class_exists(ucfirst($row['id_obj']) . 'Controller')) { include_once $cpath; } $class = ucfirst($row['id_obj']) . 'Controller'; $controller = new $class(); $item = $controller->get_item($row['params'], $com); if (method_exists($controller, 'get_item_url')) { $item_url = $controller->get_item_url($row['params'], $com); } } else { $item = __('Unknow', 'rmcommon'); $item_url = ''; } $text = TextCleaner::getInstance()->clean_disabled_tags(TextCleaner::getInstance()->popuplinks(TextCleaner::getInstance()->nofollow(TextCleaner::getInstance()->truncate($com->getVar('content'), 100)))); $comments[] = (object) array('id' => $row['id_com'], 'text' => $text, 'poster' => $poster, 'date' => formatTimestamp($com->getVar('posted'), 'l'), 'ip' => $com->getVar('ip'), 'item' => $item, 'item_url' => $item_url, 'module' => $row['id_obj'], 'status' => $com->getVar('status')); } // Get dashboard widgets $dashboardPanels = []; $dashboardPanels = RMEvents::get()->trigger('rmcommon.dashboard.panels', $dashboardPanels); RMTemplate::getInstance()->add_body_class('dashboard'); xoops_cp_header(); //RMTemplate::get()->add_style('dashboard.min.css', 'rmcommon'); RMTemplate::get()->add_style('pagenav.css', 'rmcommon'); RMTemplate::get()->add_help(__('Dashboard Help', 'rmcommon'), 'http://www.xoopsmexico.net/docs/common-utilities/uso-de-common-utilities/standalone/1/#dashboard'); include RMTemplate::get()->path('rmc-dashboard.php', 'module', 'rmcommon'); xoops_cp_footer(); }
function rmc_bkcomments_show($options) { $db = XoopsDatabaseFactory::getDatabaseConnection(); $sql = "SELECT * FROM " . $db->prefix("rmc_comments") . " ORDER BY id_com DESC"; $limit = $options[0] > 0 ? $options[0] : 10; $sql .= " LIMIT 0,{$limit}"; $result = $db->query($sql); $comments = array(); $ucache = array(); $ecache = array(); $mods = array(); while ($row = $db->fetchArray($result)) { $com = new RMComment(); $com->assignVars($row); if ($options[3]) { // 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' => $user->getVar('user_avatar') != '' && $user->getVar('user_avatar') != 'blank.gif' ? XOOPS_UPLOAD_URL . '/' . $user->getVar('user_avatar') : RMCURL . '/images/avatar.gif', 'rank' => $user->rank()); } else { $poster = array('id' => 0, 'name' => $editor->getVar('name'), 'email' => $editor->getVar('email'), 'posts' => 0, 'avatar' => RMCURL . '/images/avatar.gif', 'rank' => ''); } } // Get item $cpath = XOOPS_ROOT_PATH . '/modules/' . $row['id_obj'] . '/class/' . $row['id_obj'] . 'controller.php'; if (is_file($cpath)) { if (!class_exists(ucfirst($row['id_obj']) . 'Controller')) { include_once $cpath; } $class = ucfirst($row['id_obj']) . 'Controller'; $controller = new $class(); $item = $controller->get_item($row['params'], $com); $item_url = $controller->get_item_url($row['params'], $com); } else { $item = __('Unknow', 'rmcommon'); $item_url = ''; } if (isset($mods[$row['id_obj']])) { $mod = $mods[$row['id_obj']]; } else { $m = RMFunctions::load_module($row['id_obj']); $mod = $m->getVar('name'); $mods[$row['id_obj']] = $mod; } $comments[] = array('id' => $row['id_com'], 'text' => TextCleaner::truncate(TextCleaner::getInstance()->clean_disabled_tags(TextCleaner::getInstance()->popuplinks(TextCleaner::getInstance()->nofollow($com->getVar('content')))), 50), 'poster' => isset($poster) ? $poster : null, 'posted' => formatTimestamp($com->getVar('posted'), 'l'), 'item' => $item, 'item_url' => $item_url, 'module' => $row['id_obj'], 'status' => $com->getVar('status'), 'module' => $mod); } $comments = RMEvents::get()->run_event('rmcommon.loading.block.comments', $comments); $block['comments'] = $comments; $block['show_module'] = $options[1]; $block['show_name'] = $options[2]; $block['show_user'] = $options[3]; $block['show_date'] = $options[4]; $num = $options[2] + $options[3] + $options[4]; $block['data_width'] = floor(100 / $num); RMTemplate::get()->add_xoops_style('bk_comments.css', 'rmcommon'); return $block; }
function show_comments() { global $xoopsSecurity; $db = Database::getInstance(); $keyw = rmc_server_var($_REQUEST, 'w', ''); $filter = rmc_server_var($_REQUEST, 'filter', ''); $sql = "SELECT COUNT(*) FROM " . $db->prefix("rmc_comments"); $sql .= $keyw != '' || $filter != '' ? ' WHERE ' : ''; $sql .= $keyw != '' ? "(content LIKE '%{$keyw}%' OR ip LIKE '%{$keyw}%')" : ''; $sql .= $filter != '' ? ($keyw != '' ? ' AND' : '') . " status='{$filter}'" : ''; /** * Paginacion de Resultados */ $page = rmc_server_var($_GET, 'page', 1); $limit = 15; list($num) = $db->fetchRow($db->query($sql)); $tpages = ceil($num / $limit); $page = $page > $tpages ? $tpages : $page; $start = $num <= 0 ? 0 : ($page - 1) * $limit; $nav = new RMPageNav($num, $limit, $page, 5); $nav->target_url('comments.php?page={PAGE_NUM}'); $sql = str_replace("COUNT(*)", '*', $sql); $sql .= " ORDER BY posted DESC LIMIT {$start},{$limit}"; $result = $db->query($sql); $comments = array(); $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' => $user->getVar('user_avatar') != '' && $user->getVar('user_avatar') != 'blank.gif' ? XOOPS_UPLOAD_URL . '/' . $user->getVar('user_avatar') : RMCURL . '/images/avatar.gif', 'rank' => $user->rank()); } else { $poster = array('id' => 0, 'name' => $editor->getVar('name'), 'email' => $editor->getVar('email'), 'posts' => 0, 'avatar' => RMCURL . '/images/avatar.gif', 'rank' => ''); } // Get item $cpath = XOOPS_ROOT_PATH . '/modules/' . $row['id_obj'] . '/class/' . $row['id_obj'] . 'controller.php'; if (is_file($cpath)) { if (!class_exists(ucfirst($row['id_obj']) . 'Controller')) { include_once $cpath; } $class = ucfirst($row['id_obj']) . 'Controller'; $controller = new $class(); $item = $controller->get_item($row['params'], $com); $item_url = $controller->get_item_url($row['params'], $com); } else { $item = __('Unknow', 'rmcommon'); $item_url = ''; } $comments[] = 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', 'rmcommon'), formatTimestamp($com->getVar('posted'), 'l')), 'ip' => $com->getVar('ip'), 'item' => $item, 'item_url' => $item_url, 'module' => $row['id_obj'], 'status' => $com->getVar('status')); } $comments = RMEvents::get()->run_event('rmcommon.loading.admin.comments', $comments); xoops_cp_header(); RMFunctions::create_toolbar(); RMTemplate::get()->add_style('comms-admin.css', 'rmcommon'); RMTemplate::get()->add_style('general.css', 'rmcommon'); RMTemplate::get()->add_script('include/js/jquery.checkboxes.js'); RMTemplate::get()->add_script('include/js/comments.js'); $script = '<script type="text/javascript">delmes = "' . __('Do you really wish to delete this comment?', 'rmcommon') . '";</script>'; RMTemplate::get()->add_head($script); include RMTemplate::get()->get_template('rmc_comments.php', 'module', 'rmcommon'); xoops_cp_footer(); }