$comment->setVar('type', $type); $comment->setVar('parent', isset($parent) ? $parent : 0); $comment->setVar('params', $params); $comment->setVar('content', $text); $comment->setVar('user', $uid); $comment->setVar('ip', $_SERVER['REMOTE_ADDR']); $comment->setVar('posted', time()); // Check if comment must be approved if ($xoopsUser && $rmc_config['approve_reg_coms']) { $comment->setVar('status', 'approved'); } elseif (!$xoopsUser && $rmc_config['approve_anon_coms']) { $comment->setVar('status', 'approved'); } elseif ($xoopsUser && $xoopsUser->isAdmin()) { $comment->setVar('status', 'approved'); } if (!$comment->save()) { redirect_header($uri, 1, __('Comment could not be posted!', 'rmcommon') . '<br />' . $comment->errors()); } if ($xoopsUser) { $xoopsUser->incrementPost(); } RMEvents::get()->run_event('rmcommon.comment.saved', $comment, $uri); // Update comments number if object accepts this functionallity if (is_file(XOOPS_ROOT_PATH . '/modules/' . $object . '/class/' . $object . 'controller.php')) { include_once XOOPS_ROOT_PATH . '/modules/' . $object . '/class/' . $object . 'controller.php'; $class = ucfirst($object) . 'Controller'; if (class_exists($class)) { $controller = new $class(); if (method_exists($controller, 'increment_comments_number')) { $controller->increment_comments_number($comment); }
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); } }