예제 #1
0
 public function eventRmcommonSavingComment(RMComment $com)
 {
     global $name, $url, $xuid, $xoopsUser, $email, $text, $xoopsConfig;
     $config = RMFunctions::get()->plugin_settings('akismet', true);
     if ($config['key'] == '') {
         return;
     }
     $akismet = new Akismet(XOOPS_URL, $config['key']);
     $akismet->setCommentAuthor($name);
     $akismet->setCommentAuthorEmail($email);
     $akismet->setCommentAuthorURL($url);
     $akismet->setCommentContent($text);
     $akismet->setUserIP($_SERVER['REMOTE_ADDR']);
     $cpath = XOOPS_ROOT_PATH . '/modules/' . $com->getVar('id_obj') . '/class/' . $com->getVar('id_obj') . 'controller.php';
     if (is_file($cpath)) {
         if (!class_exists(ucfirst($com->getVar('id_obj')) . 'Controller')) {
             include_once $cpath;
         }
         $class = ucfirst($com->getVar('id_obj')) . 'Controller';
         $controller = new $class();
         $permalink = $controller->get_item($com->getVar('params'), $com, true);
         $akismet->setPermalink($permalink);
     }
     if ($akismet->isCommentSpam()) {
         $com->setVar('status', 'spam');
         return false;
     }
     return true;
 }
예제 #2
0
 /**
  * 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&amp;id=' . $com->id() . '&amp;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;
     }
 }
예제 #3
0
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;
}
예제 #4
0
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();
}
예제 #5
0
     die;
 }
 // Check if user is allowed to edit this comment
 if (!$xoopsUser) {
     redirect_header($ret, 1, __('You are not allowed to edit this comment!', 'rmcommon'));
     die;
 }
 if (!$xoopsSecurity->check()) {
     redirect_header($ret, 1, __('You are not allowed to edit this comment!', 'rmcommon'));
     die;
 }
 if ($id <= 0) {
     redirect_header(XOOPS_URL, 1, __('Please specify a comment', 'rmcommon'));
     die;
 }
 $comment = new RMComment($id);
 if ($comment->isNew()) {
     redirect_header(XOOPS_URL, 1, __('Specified comment does not exist!', 'rmcommon'));
     die;
 }
 $status = $xoopsUser->isAdmin($comment->getVar('id_obj')) ? rmc_server_var($_POST, 'status', $comment->getVar('status')) : $comment->getVar('status');
 $status = $status == 'approved' ? $status : 'unapproved';
 $user = $xoopsUser->isAdmin($comment->getVar('id_obj')) ? rmc_server_var($_POST, 'user', $xoopsUser->getVar('uid')) : $xoopsUser->getVar('uid');
 $content = rmc_server_var($_POST, 'content', '');
 if ($content == '') {
     redirect_header('post_comment.php?id=' . $id . '&ret=' . urlencode($ret) . '&action=edit', 2, __('You must provide a text for comment!', 'rmcommon'));
     die;
 }
 // save basic info in comment object
 $comment->setVar('content', $content);
 $comment->setVar('status', $status);
예제 #6
0
function save_comment()
{
    global $xoopsSecurity;
    $id = rmc_server_var($_POST, 'id', 0);
    $page = rmc_server_var($_POST, 'page', 1);
    $filter = rmc_server_var($_POST, 'filter', '');
    $w = rmc_server_var($_POST, 'w', '1');
    $qs = "id={$id}&w={$w}&page={$page}&filter={$filter}";
    if (!$xoopsSecurity->check()) {
        redirectMsg('comments.php?action=edit&' . $qs, __('Sorry, session token expired!', 'rmcommon'), 1);
        die;
    }
    if ($id <= 0) {
        redirectMsg('comments.php', __('Comment ID not specified!', 'rmcommon'), 1);
        die;
    }
    $comment = new RMComment($id);
    if ($comment->isNew()) {
        redirectMsg('comments.php?' . $qs, __('Specified comment does not exist!', 'rmcommon'), 1);
        die;
    }
    $status = rmc_server_var($_POST, 'status', 'unapproved');
    $status = $status == 'approved' ? $status : 'unapproved';
    $user = rmc_server_var($_POST, 'user', 0);
    $content = rmc_server_var($_POST, 'content', '');
    // save basic info in comment object
    $comment->setVar('content', $content);
    $comment->setVar('status', $status);
    // Modify, if neccessary, the user
    $cuser = new RMCommentUser($comment->getVar('user'));
    if ($cuser->getVar('xuid') != $user) {
        if ($user == 0) {
            $cuser->setVar('xuid', 0);
            $cuser->save();
        } else {
            $xuser = new XoopsUser($user);
            $cuser = new RMCommentUser($xuser->getVar('email'));
            $cuser->setVar('name', $xuser->getVar('uname'));
            $cuser->setVar('email', $xuser->getVar('email'));
            $cuser->setVar('xuid', $user);
            $cuser->setVar('url', $xuser->getVar('url'));
            $cuser->save();
        }
        $comment->setVar('user', $cuser->id());
    }
    if ($comment->save()) {
        redirectMsg('comments.php?' . $qs, __('Comment updated successfully!', 'rmcommon'), 0);
    } else {
        redirectMsg('comments.php?action=edit&' . $qs, __('Errros ocurrs while trying to update comment!', 1) . '<br />' . $comment->errors(), 1);
    }
}