11 include_once
'../../include/cp_header.php';
12 define(
'RMCLOCATION',
'comments');
17 $db = XoopsDatabaseFactory::getDatabaseConnection();
22 $sql =
"SELECT COUNT(*) FROM ".$db->prefix(
"rmc_comments");
23 $sql .= $keyw!=
'' || $filter!=
'' ?
' WHERE ' :
'';
24 $sql .= $keyw!=
'' ?
"(content LIKE '%$keyw%' OR ip LIKE '%$keyw%')" :
'';
25 $sql .= $filter!=
'' ? ($keyw!=
''?
' AND':
'').
" status='$filter'" :
'';
39 $nav->target_url(
'comments.php?page={PAGE_NUM}');
41 $sql = str_replace(
"COUNT(*)",
'*',
$sql);
42 $sql .=
" ORDER BY posted DESC LIMIT $start,$limit";
51 $com->assignVars($row);
54 if(!isset($ecache[$com->getVar(
'user')])){
55 $ecache[$com->getVar(
'user')] =
new RMCommentUser($com->getVar(
'user'));
58 $editor = $ecache[$com->getVar(
'user')];
60 if($editor->getVar(
'xuid')>0){
62 if(!isset($ucache[$editor->getVar(
'xuid')])){
63 $ucache[$editor->getVar(
'xuid')] =
new XoopsUser($editor->getVar(
'xuid'));
66 $user = $ucache[$editor->getVar(
'xuid')];
69 'id' => $user->getVar(
'uid'),
70 'name' => $user->getVar(
'uname'),
71 'email' => $user->getVar(
'email'),
72 'posts' => $user->getVar(
'posts'),
73 'avatar'=> $user->getVar(
'user_avatar')!=
'' && $user->getVar(
'user_avatar')!=
'blank.gif' ? XOOPS_UPLOAD_URL.
'/'.$user->getVar(
'user_avatar') :
RMCURL.
'/images/avatar.gif',
74 'rank' => $user->rank(),
81 'name' => $editor->getVar(
'name'),
82 'email' => $editor->getVar(
'email'),
84 'avatar'=>
RMCURL.
'/images/avatar.gif',
91 $cpath = XOOPS_ROOT_PATH.
'/modules/'.$row[
'id_obj'].
'/class/'.$row[
'id_obj'].
'controller.php';
94 if(!class_exists(ucfirst($row[
'id_obj']).
'Controller'))
97 $class = ucfirst($row[
'id_obj']).
'Controller';
98 $controller =
new $class();
99 $item = $controller->get_item($row[
'params'], $com);
100 if(method_exists($controller,
'get_item_url'))
101 $item_url = $controller->get_item_url($row[
'params'], $com);
105 $item =
__(
'Unknow',
'rmcommon');
111 'id' => $row[
'id_com'],
114 'posted' => sprintf(
__(
'Posted on %s',
'rmcommon'), formatTimestamp($com->getVar(
'posted'),
'l')),
115 'ip' => $com->getVar(
'ip'),
117 'item_url' => $item_url,
118 'module' => $row[
'id_obj'],
119 'status' => $com->getVar(
'status')
123 $comments =
RMEvents::get()->run_event(
'rmcommon.loading.admin.comments', $comments);
131 $script =
'<script type="text/javascript">delmes = "'.__(
'Do you really want to delete this comment?',
'rmcommon').
'";</script>';
133 include
RMTemplate::get()->get_template(
'rmc_comments.php',
'module',
'rmcommon');
145 if ($status!=
'waiting' && $status!=
'approved' && $status!=
'spam'){
146 redirectMsg(
'comments.php',
__(
'Invalid operation',
'rmcommon'), 1);
155 $qs =
"page=$page&filter=$filter&w=$w";
157 if(!$xoopsSecurity->check()){
158 redirectMsg(
'comments.php?'.$qs,
__(
'Sorry, session token expired!',
'rmcommon'), 1);
162 if(!is_array($coms)){
163 redirectMsg(
'comments.php?'.$qs,
__(
'Unrecognized data!',
'rmcommon'), 1);
167 $db = XoopsDatabaseFactory::getDatabaseConnection();
168 $sql =
"UPDATE ".$db->prefix(
"rmc_comments").
" SET status='$status' WHERE id_com IN (".implode(
",",$coms).
")";
172 RMEvents::get()->run_event(
'rmcommon.updated.comments',$coms, $status);
174 redirectMsg(
'comments.php?'.$qs,
__(
'Comments updated successfully!',
'rmcommon'), 0);
179 redirectMsg(
'comments.php?'.$qs,
__(
'Errors occurrs while trying to update comments!',
'rmcommon'), 1);
194 $qs =
"page=$page&filter=$filter&w=$w";
196 if(!$xoopsSecurity->check()){
197 redirectMsg(
'comments.php?'.$qs,
__(
'Sorry, session token expired!',
'rmcommon'), 1);
201 if(!is_array($coms)){
202 redirectMsg(
'comments.php?'.$qs,
__(
'Unrecognized data!',
'rmcommon'), 1);
207 foreach ($coms as
$id){
210 if($com->isNew())
continue;
212 $cpath = XOOPS_ROOT_PATH.
'/modules/'.$com->getVar(
'id_obj').
'/class/'.$com->getVar(
'id_obj').
'controller.php';
214 if(!$com->delete())
return;
217 if(!class_exists(ucfirst($com->getVar(
'id_obj')).
'Controller'))
220 $class = ucfirst($com->getVar(
'id_obj')).
'Controller';
221 $controller =
new $class();
222 $item = $controller->reduce_comments_number($com);
226 $item =
__(
'Unknow',
'rmcommon');
232 redirectMsg(
'comments.php',
__(
'Comments deleted successfully!',
'rmcommon'), 0);
243 $qs =
"w=$w&page=$page&filter=$filter";
246 redirectMsg(
'comments.php?'.$qs,
__(
'Sorry, comment id is not valid',
'rmcommon'), 1);
251 if($comment->isNew()){
252 redirectMsg(
'comments.php?'.$qs,
__(
'Sorry, comment does not found',
'rmcommon'), 1);
256 $cpath = XOOPS_ROOT_PATH.
'/modules/'.$comment->getVar(
'id_obj').
'/class/'.$comment->getVar(
'id_obj').
'controller.php';
260 $class = ucfirst($comment->getVar(
'id_obj')).
'Controller';
261 $controller =
new $class();
264 $form =
new RMForm(
__(
'Edit Comment',
'rmcommon'),
'editComment',
'comments.php');
265 $form->addElement(
new RMFormLabel(
__(
'In reply to',
'rmcommon'), $controller ? $controller->get_item($comment->getVar(
'params'), $comment):
''));
266 $form->addElement(
new RMFormLabel(
__(
'Posted date',
'rmcommon'), formatTimestamp($comment->getVar(
'posted'),
'mysql')));
267 $form->addElement(
new RMFormLabel(
__(
'Module',
'rmcommon'), $comment->getVar(
'id_obj')));
268 $form->addElement(
new RMFormLabel(
__(
'IP',
'rmcommon'), $comment->getVar(
'ip')));
271 $ele =
new RMFormUser(
__(
'Poster',
'rmcommon'),
'user',
false, $user->getVar(
'xuid')>0 ? $user->getVar(
'xuid') : 0);
272 $form->addElement($ele);
274 $ele =
new RMFormRadio(
__(
'Status',
'rmcommon'),
'status', 1, 0, 2);
275 $ele->addOption(
__(
'Approved',
'rmcommon'),
'approved', $comment->getVar(
'status')==
'approved'?1:0);
276 $ele->addOption(
__(
'Unapproved',
'rmcommon'),
'waiting', $comment->getVar(
'status')==
'waiting'?1:0);
277 $form->addElement($ele);
279 $form->addElement(
new RMFormTextArea(
__(
'Content',
'rmcommon'),
'content', null, null, $comment->getVar(
'content',
'e'),
'100%',
'150px'),
true);
286 $ele->addButton(
'sbt',
__(
'Update Comment',
'rmcommon'),
'submit');
287 $ele->addButton(
'cancel',
__(
'Cancel',
'rmcommon'),
'button',
'onclick="history.go(-1);"');
288 $form->addElement($ele);
305 $qs =
"id=$id&w=$w&page=$page&filter=$filter";
307 if(!$xoopsSecurity->check()){
308 redirectMsg(
'comments.php?action=edit&'.$qs,
__(
'Sorry, session token expired!',
'rmcommon'), 1);
313 redirectMsg(
'comments.php',
__(
'Comment ID not specified!',
'rmcommon'), 1);
318 if($comment->isNew()){
319 redirectMsg(
'comments.php?'.$qs,
__(
'Specified comment does not exist!',
'rmcommon'), 1);
324 $status = $status==
'approved'?$status:
'unapproved';
330 $comment->setVar(
'content',
$content);
331 $comment->setVar(
'status', $status);
334 if ($cuser->getVar(
'xuid')!=$user){
337 $cuser->
setVar(
'xuid', 0);
340 $xuser =
new XoopsUser($user);
342 $cuser->
setVar(
'name', $xuser->getVar(
'uname'));
343 $cuser->setVar(
'email', $xuser->getVar(
'email'));
344 $cuser->setVar(
'xuid', $user);
345 $cuser->setVar(
'url', $xuser->getVar(
'url'));
349 $comment->setVar(
'user', $cuser->id());
353 if ($comment->save()){
354 redirectMsg(
'comments.php?'.$qs,
__(
'Comment updated successfully!',
'rmcommon'), 0);
356 redirectMsg(
'comments.php?action=edit&'.$qs,
__(
'Errros ocurrs while trying to update comment!', 1).
'<br />'.$comment->errors(), 1);