11 include
'../../mainfile.php';
21 redirect_header(
rmc_server_var($_REQUEST,
'comment_url', XOOPS_URL), 1,
__(
'Sorry, comments has been disabled by administrator',
'rmcommon'));
28 redirect_header(XOOPS_URL, 2,
__(
'You are not allowed to do this action!',
'rmcommon'));
52 header(
'loaction: '.XOOPS_URL);
56 if ($name==
'' || $email==
''){
57 redirect_header($uri, 2,
__(
'You must provide your name and email in order to can post comments',
'rmcommon'));
62 redirect_header($uri, 2,
__(
'Sorry, you are not allowed to post comments!',
'rmcommon'));
68 if (trim($params)==
''){
69 redirect_header($uri, 2,
__(
'There are not params to save!',
'rmcommon'));
76 redirect_header($uri, 2,
__(
'Object type missing!',
'rmcommon'));
82 if (trim($object)==
''){
83 redirect_header($uri, 2,
__(
'Object name missing!',
'rmcommon'));
90 redirect_header($uri, 2,
__(
'You must write a message!',
'rmcommon'));
94 RMEvents::get()->run_event(
'rmcommon.comment.postdata', $uri);
97 $db = XoopsDatabaseFactory::getDatabaseConnection();
100 $sql =
"SELECT id_user FROM ".$db->prefix(
"rmc_comusers").
" WHERE xuid=".
$xoopsUser->uid();
104 $sql =
"SELECT id_user FROM ".$db->prefix(
"rmc_comusers").
" WHERE email='$email'";
113 $db->queryF(
"INSERT INTO ".
$db->prefix(
"rmc_comusers").
" (`xuid`,`name`,`email`,`url`) VALUES ('$xuid','$name','$email','$url')");
114 $uid =
$db->getInsertId();
118 $db->queryF(
"UPDATE ".
$db->prefix(
"rmc_comusers").
" SET `name`='$name',`email`='$email',`url`='$url' WHERE id_user='$uid'");
123 $comment->setVar(
'id_obj', $object);
124 $comment->setVar(
'type',
$type);
125 $comment->setVar(
'parent', isset($parent) ? $parent : 0);
126 $comment->setVar(
'params', $params);
127 $comment->setVar(
'content', $text);
128 $comment->setVar(
'user', $uid);
129 $comment->setVar(
'ip', $_SERVER[
'REMOTE_ADDR']);
130 $comment->setVar(
'posted', time());
134 $comment->setVar(
'status',
'approved');
136 $comment->setVar(
'status',
'approved');
138 $comment->setVar(
'status',
'approved');
141 if (!$comment->save()){
143 redirect_header($uri, 1,
__(
'Comment could not be posted!',
'rmcommon').
'<br />'.$comment->errors());
148 RMEvents::get()->run_event(
'rmcommon.comment.saved', $comment, $uri);
151 if (is_file(XOOPS_ROOT_PATH.
'/modules/'.$object.
'/class/'.$object.
'controller.php')){
152 include_once XOOPS_ROOT_PATH.
'/modules/'.$object.
'/class/'.$object.
'controller.php';
153 $class = ucfirst($object).
'Controller';
155 $controller =
new $class();
156 if (method_exists($controller,
'increment_comments_number')){
157 $controller->increment_comments_number($comment);
163 redirect_header($uri.
'#comment-'.$comment->id(), 1,
__(
'Comment posted successfully!',
'rmcommon'));
168 redirect_header(XOOPS_URL, 2,
__(
'Invalid operation',
'rmcommon'));
174 redirect_header(
rmc_server_var($_REQUEST,
'comment_url', XOOPS_URL), 1,
__(
'You are not allowed to edit this comment!',
'rmcommon'));
180 redirect_header(
rmc_server_var($_REQUEST,
'ret', XOOPS_URL), 1,
__(
'Please specify a comment',
'rmcommon'));
185 if ($comment->isNew()){
186 redirect_header(
rmc_server_var($_REQUEST,
'ret', XOOPS_URL), 1,
__(
'Specified comment does not exist!',
'rmcommon'));
192 if (
$xoopsUser->uid()!=$editor->getVar(
'xuid') && !
$xoopsUser->isAdmin($comment->getVar(
'id_obj'))){
193 redirect_header(
rmc_server_var($_REQUEST,
'ret', XOOPS_URL), 1,
__(
'You are not allowed to edit this comment!',
'rmcommon'));
197 include
'../../header.php';
199 $cpath = XOOPS_ROOT_PATH.
'/modules/'.$comment->getVar(
'id_obj').
'/class/'.$comment->getVar(
'id_obj').
'controller.php';
203 $class = ucfirst($comment->getVar(
'id_obj')).
'Controller';
204 $controller =
new $class();
207 $form =
new RMForm(
__(
'Edit Comment',
'rmcommon'),
'editComment',
'post_comment.php');
208 $form->addElement(
new RMFormLabel(
__(
'In reply to',
'rmcommon'), $controller ? $controller->get_item($comment->getVar(
'params'), $comment):
''));
209 $form->addElement(
new RMFormLabel(
__(
'Posted date',
'rmcommon'), formatTimestamp($comment->getVar(
'posted'),
'mysql')));
210 $form->addElement(
new RMFormLabel(
__(
'Module',
'rmcommon'), $comment->getVar(
'id_obj')));
214 $ele =
new RMFormUser(
__(
'Poster',
'rmcommon'),
'user',
false, $user->getVar(
'xuid')>0 ? $user->getVar(
'xuid') : 0);
215 $form->addElement($ele);
218 if(
$xoopsUser->isAdmin($comment->getVAr(
'id_obj'))){
219 $ele =
new RMFormRadio(
__(
'Status',
'rmcommon'),
'status', 1, 0, 2);
220 $ele->addOption(
__(
'Approved',
'rmcommon'),
'approved', $comment->getVar(
'status')==
'approved'?1:0);
221 $ele->addOption(
__(
'Unapproved',
'rmcommon'),
'waiting', $comment->getVar(
'status')==
'waiting'?1:0);
222 $form->addElement($ele);
225 $form->addElement(
new RMFormTextArea(
__(
'Content',
'rmcommon'),
'content', null, null, $comment->getVar(
'content',
'e'),
'100%',
'150px'),
true);
226 $form->addElement(
new RMFormHidden(
'action',
'saveedit'));
228 $ele->addButton(
'sbt',
__(
'Update Comment',
'rmcommon'),
'submit');
229 $ele->addButton(
'cancel',
__(
'Cancel',
'rmcommon'),
'button',
'onclick="history.go(-1);"');
230 $form->addElement($ele);
236 $form =
RMEvents::get()->run_event(
'rmcommon.edit.comment.form', $form);
240 include
'../../footer.php';
251 redirect_header(XOOPS_URL, 1,
__(
'Invalid Operation',
'rmcommon'));
257 redirect_header(
$ret, 1,
__(
'You are not allowed to edit this comment!',
'rmcommon'));
262 redirect_header(
$ret, 1,
__(
'You are not allowed to edit this comment!',
'rmcommon'));
267 redirect_header(XOOPS_URL, 1,
__(
'Please specify a comment',
'rmcommon'));
272 if($comment->isNew()){
273 redirect_header(XOOPS_URL, 1,
__(
'Specified comment does not exist!',
'rmcommon'));
277 $status =
$xoopsUser->isAdmin($comment->getVar(
'id_obj')) ?
rmc_server_var($_POST,
'status', $comment->getVar(
'status')) : $comment->getVar(
'status');
278 $status = $status==
'approved'?$status:
'unapproved';
284 redirect_header(
'post_comment.php?id='.
$id.
'&ret='.urlencode(
$ret).
'&action=edit', 2,
__(
'You must provide a text for comment!',
'rmcommon'));
289 $comment->setVar(
'content',
$content);
290 $comment->setVar(
'status', $status);
293 if ($cuser->getVar(
'xuid')!=$user){
296 $cuser->
setVar(
'xuid', 0);
299 $xuser =
new XoopsUser($user);
301 $cuser->
setVar(
'name', $xuser->getVar(
'uname'));
302 $cuser->setVar(
'email', $xuser->getVar(
'email'));
303 $cuser->setVar(
'xuid', $user);
304 $cuser->setVar(
'url', $xuser->getVar(
'url'));
308 $comment->setVar(
'user', $cuser->id());
314 if ($comment->save()){
315 redirect_header(
$ret.
'#comment-'.$comment->id(), 2,
__(
'Comment updated successfully!',
'rmcommon'));
317 redirect_header(
$ret.
'#comment-'.$comment->id(), 2,
__(
'Errros ocurrs while trying to update comment!',
'rmcommon'));