XpressEngine Core  1.11.2
 All Classes Namespaces Files Functions Variables Pages
comment.admin.controller.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) NAVER <http://www.navercorp.com> */
3 
13 {
14 
19  function init()
20  {
21 
22  }
23 
29  {
30  // Error display if none is selected
31  $cart = Context::get('cart');
32  if(!is_array($cart))
33  {
34  $comment_srl_list = explode('|@|', $cart);
35  }
36  else
37  {
38  $comment_srl_list = $cart;
39  }
40 
42 
43  $returnUrl = Context::get('success_return_url') ? Context::get('success_return_url') : getNotEncodedUrl('', 'module', 'admin', 'act', 'dispCommentAdminList', 'search_keyword', '');
44  $this->setRedirectUrl($returnUrl);
45  }
46 
52  {
53  $will_publish = Context::get('will_publish');
54 
55  // Error display if none is selected
56  $cart = Context::get('cart');
57  if(!$cart)
58  {
59  return $this->stop('msg_cart_is_null');
60  }
61  if(!is_array($cart))
62  {
63  $comment_srl_list = explode('|@|', $cart);
64  }
65  else
66  {
67  $comment_srl_list = $cart;
68  }
69 
70  $args = new stdClass();
71  $args->status = $will_publish;
72  $args->comment_srls_list = $comment_srl_list;
73  $output = executeQuery('comment.updatePublishedStatus', $args);
74  if(!$output->toBool())
75  {
76  return $output;
77  }
78  else
79  {
80  //update comment count for document
81  $updated_documents_arr = array();
82  // create the controller object of the document
83  $oDocumentController = getController('document');
84  // create the model object of the document
85  $oDocumentModel = getModel('document');
86  // create the comment model object
87  $oCommentModel = getModel('comment');
88  //get admin info
89  $logged_info = Context::get('logged_info');
90  //$oMemberModule = getModel("member");
91  //$logged_info = $oMemberModule->getMemberInfoByMemberSrl($logged_member_srl);
92  $new_status = ($will_publish) ? "published" : "unpublished";
93  foreach($comment_srl_list as $comment_srl)
94  {
95  // check if comment already exists
96  $comment = $oCommentModel->getComment($comment_srl);
97  if($comment->comment_srl != $comment_srl)
98  {
99  return new BaseObject(-1, 'msg_invalid_request');
100  }
101  $document_srl = $comment->document_srl;
102  if(!in_array($document_srl, $updated_documents_arr))
103  {
104  $updated_documents_arr[] = $document_srl;
105  // update the number of comments
106  $comment_count = $oCommentModel->getCommentCount($document_srl);
107  // update comment count of the article posting
108  $output = $oDocumentController->updateCommentCount($document_srl, $comment_count, NULL, FALSE);
109 
110  $oDocument = $oDocumentModel->getDocument($document_srl);
111  $author_email = $oDocument->variables['email_address'];
112 
113  $oModuleModel = getModel("module");
114  $module_info = $oModuleModel->getModuleInfoByModuleSrl($comment->module_srl);
115  $already_sent = array();
116 
117  // send email to comment's author, all admins and thread(document) subscribers - START
118  // -------------------------------------------------------
119  $oMail = new Mail();
120  $mail_title = "[XE - " . $module_info->mid . "] comment(s) status changed to " . $new_status . " on document: \"" . $oDocument->getTitleText() . "\"";
121  $oMail->setTitle($mail_title);
122  $mail_content = "
123  The comment #" . $comment_srl . " on document \"" . $oDocument->getTitleText() . "\" has been " . $new_status . " by admin of <strong><i>" . strtoupper($module_info->mid) . "</i></strong> module.
124  <br />
125  <br />Comment content:
126  " . $comment->content . "
127  <br />
128  ";
129  $oMail->setContent($mail_content);
130  $oMail->setSender($logged_info->user_name, $logged_info->email_address);
131 
132  $document_author_email = $oDocument->variables['email_address'];
133 
134  //mail to author of thread - START
138  /*
139  if($document_author_email != $comment->email_address && $logged_info->email_address != $document_author_email)
140  {
141  $oMail->setReceiptor($document_author_email, $document_author_email);
142  $oMail->send();
143  $already_sent[] = $document_author_email;
144  }
145  */
146  //mail to author of thread - STOP
147  //mail to all emails set for administrators - START
148  if($module_info->admin_mail)
149  {
150  $target_mail = explode(',', $module_info->admin_mail);
151  for($i = 0; $i < count($target_mail); $i++)
152  {
153  $email_address = trim($target_mail[$i]);
154  if(!$email_address)
155  {
156  continue;
157  }
158  if($author_email != $email_address)
159  {
160  $oMail->setReceiptor($email_address, $email_address);
161  $oMail->send();
162  }
163  }
164  }
165  //mail to all emails set for administrators - STOP
166  }
167  // ----------------------------------------------------------
168  // send email to comment's author, all admins and thread(document) subscribers - STOP
169  }
170  // call a trigger for calling "send mail to subscribers" (for moment just for forum)
171  ModuleHandler::triggerCall("comment.procCommentAdminChangeStatus", "after", $comment_srl_list);
172  }
173 
174  // for message send - start
175  $message_content = Context::get('message_content');
176  if($message_content)
177  {
178  $message_content = nl2br($message_content);
179  }
180 
181  if($message_content)
182  {
183  $this->_sendMessageForComment($message_content, $comment_srl_list);
184  }
185  // for message send - end
186  }
187 
193  {
194  $isTrash = Context::get('is_trash');
195 
196  // Error display if none is selected
197  $cart = Context::get('cart');
198  if(!$cart)
199  {
200  return $this->stop('msg_cart_is_null');
201  }
202  if(!is_array($cart))
203  {
204  $comment_srl_list = explode('|@|', $cart);
205  }
206  else
207  {
208  $comment_srl_list = $cart;
209  }
210  $comment_count = count($comment_srl_list);
211  if(!$comment_count)
212  {
213  return $this->stop('msg_cart_is_null');
214  }
215 
216  $oCommentController = getController('comment');
217  // begin transaction
218  $oDB = DB::getInstance();
219  $oDB->begin();
220 
221  // for message send - start
222  $message_content = Context::get('message_content');
223  if($message_content)
224  {
225  $message_content = nl2br($message_content);
226  }
227 
228  if($message_content)
229  {
230  $this->_sendMessageForComment($message_content, $comment_srl_list);
231  }
232  // for message send - end
233  // comment into trash
234  if($isTrash == 'true')
235  {
236  $this->_moveCommentToTrash($comment_srl_list, $oCommentController, $oDB, $message_content);
237  }
238 
239  $deleted_count = 0;
240  // Delete the comment posting
241  for($i = 0; $i < $comment_count; $i++)
242  {
243  $comment_srl = trim($comment_srl_list[$i]);
244  if(!$comment_srl)
245  {
246  continue;
247  }
248 
249  $output = $oCommentController->deleteComment($comment_srl, TRUE, $isTrash);
250  if(!$output->toBool())
251  {
252  $oDB->rollback();
253  return $output;
254  }
255 
256  $deleted_count++;
257  }
258 
259  $oDB->commit();
260 
261  $msgCode = '';
262  if($isTrash == 'true')
263  {
264  $msgCode = 'success_trashed';
265  }
266  else
267  {
268  $msgCode = 'success_deleted';
269  }
270  //$this->setMessage( sprintf(Context::getLang('msg_checked_comment_is_deleted'), $deleted_count) );
271  $this->setMessage($msgCode, 'info');
272 
273  //set url params
274  $search_keyword = Context::get('search_keyword');
275  $search_target = Context::get('search_target');
276  $page = Context::get('page');
277 
278  $returnUrl = Context::get('success_return_url') ? Context::get('success_return_url') : getNotEncodedUrl('', 'module', 'admin', 'act', 'dispCommentAdminList', 'search_keyword', $search_keyword, 'search_target', $search_target, 'page', $page);
279  $this->setRedirectUrl($returnUrl);
280  }
281 
282  private function _sendMessageForComment($message_content, $comment_srl_list)
283  {
284  $oCommunicationController = getController('communication');
285  $oCommentModel = getModel('comment');
286 
287  $logged_info = Context::get('logged_info');
288 
289  $title = cut_str($message_content, 10, '...');
290  $sender_member_srl = $logged_info->member_srl;
291 
292  $comment_count = count($comment_srl_list);
293  for($i = 0; $i < $comment_count; $i++)
294  {
295  $comment_srl = $comment_srl_list[$i];
296  $oComment = $oCommentModel->getComment($comment_srl, TRUE);
297 
298  if(!$oComment->get('member_srl') || $oComment->get('member_srl') == $sender_member_srl)
299  {
300  continue;
301  }
302 
303  $content = sprintf("<div>%s</div><hr /><div style=\"font-weight:bold\">%s</div>", $message_content, $oComment->getContentText(20));
304 
305  $oCommunicationController->sendMessage($sender_member_srl, $oComment->get('member_srl'), $title, $content, FALSE);
306  }
307  }
308 
313  function _moveCommentToTrash($commentSrlList, &$oCommentController, &$oDB, $message_content = NULL)
314  {
315  require_once(_XE_PATH_ . 'modules/trash/model/TrashVO.php');
316 
317  if(is_array($commentSrlList))
318  {
319  $logged_info = Context::get('logged_info');
320  $oCommentModel = getModel('comment');
321  $commentItemList = $oCommentModel->getComments($commentSrlList);
322  $oTrashAdminController = getAdminController('trash');
323 
324  foreach($commentItemList AS $key => $oComment)
325  {
326  $oTrashVO = new TrashVO();
327  $oTrashVO->setTrashSrl(getNextSequence());
328  $oTrashVO->setTitle(trim(strip_tags($oComment->variables['content'])));
329  $oTrashVO->setOriginModule('comment');
330  $oTrashVO->setSerializedObject(serialize($oComment->variables));
331  $oTrashVO->setDescription($message_content);
332 
333  $output = $oTrashAdminController->insertTrash($oTrashVO);
334  if(!$output->toBool())
335  {
336  $oDB->rollback();
337  return $output;
338  }
339  }
340  }
341  }
342 
349  {
350  $oDB = DB::getInstance();
351  $oDB->begin();
352 
353  $comment_srl = Context::get('comment_srl');
354  $oCommentModel = getModel('comment');
355  $oCommentController = getController('comment');
356  $oComment = $oCommentModel->getComment($comment_srl, false);
357 
358  if(!$oComment->isGranted()) return $this->stop('msg_not_permitted');
359 
360  $message_content = "";
361  $this->_moveCommentToTrash(array($comment_srl), $oCommentController, $oDB, $message_content);
362 
363  $isTrash = true;
364  $output = $oCommentController->deleteComment($comment_srl, TRUE, $isTrash);
365 
366  $oDB->commit();
367 
368  $returnUrl = Context::get('cur_url');
369  $this->add('redirect_url', $returnUrl);
370  }
371 
377  {
378  $comment_srl = trim(Context::get('comment_srl'));
379 
380  if($comment_srl)
381  {
382  $args = new stdClass();
383  $args->comment_srl = $comment_srl;
384  $output = executeQuery('comment.deleteDeclaredComments', $args);
385  if(!$output->toBool())
386  {
387  return $output;
388  }
389  }
390  }
391 
397  {
398  $comment_srl = (int) Context::get('comment_srl');
399 
400  $oCommentModel = getModel('comment');
401  $columnList = array('comment_srl');
402  $commentSrlList = array($comment_srl);
403 
404  $output = $oCommentModel->getComments($commentSrlList);
405 
406  if(is_array($output))
407  {
408  foreach($output AS $key => $value)
409  {
410  if($_SESSION['comment_management'][$key])
411  {
412  unset($_SESSION['comment_management'][$key]);
413  }
414  else
415  {
416  $_SESSION['comment_management'][$key] = TRUE;
417  }
418  }
419  }
420  }
421 
427  {
428  $args = new stdClass();
429  $args->module_srl = $module_srl;
430  $output = executeQuery('comment.deleteModuleComments', $args);
431  if(!$output->toBool())
432  {
433  return $output;
434  }
435 
436  $output = executeQuery('comment.deleteModuleCommentsList', $args);
437 
438  //remove from cache
439  $oCacheHandler = CacheHandler::getInstance('object');
440  if($oCacheHandler->isSupport())
441  {
442  // Invalidate newest comments. Per document cache is invalidated inside document admin controller.
443  $oCacheHandler->invalidateGroupKey('newestCommentsList');
444  }
445  return $output;
446  }
447 
453  function restoreTrash($originObject)
454  {
455  if(is_array($originObject))
456  {
457  $originObject = (object) $originObject;
458  }
459 
460  $obj = new stdClass();
461  $obj->document_srl = $originObject->document_srl;
462  $obj->comment_srl = $originObject->comment_srl;
463  $obj->parent_srl = $originObject->parent_srl;
464  $obj->content = $originObject->content;
465  $obj->password = $originObject->password;
466  $obj->nick_name = $originObject->nick_name;
467  $obj->member_srl = $originObject->member_srl;
468  $obj->email_address = $originObject->email_address;
469  $obj->homepage = $originObject->homepage;
470  $obj->is_secret = $originObject->is_secret;
471  $obj->notify_message = $originObject->notify_message;
472  $obj->module_srl = $originObject->module_srl;
473 
474  $oCommentController = getController('comment');
475  $output = $oCommentController->insertComment($obj, true);
476 
477  return $output;
478  }
479 
485  function emptyTrash($originObject)
486  {
487  $originObject = unserialize($originObject);
488  if(is_array($originObject))
489  {
490  $originObject = (object) $originObject;
491  }
492 
493  $oComment = new commentItem();
494  $oComment->setAttribute($originObject);
495 
496  //already comment deleted, therefore only comment log delete
497  $oCommentController = getController('comment');
498  $args = new stdClass();
499  $args->comment_srl = $oComment->get('comment_srl');
500  $output = $oCommentController->deleteCommentLog($args);
501  return $output;
502  }
503 
504 }
505 /* End of file comment.admin.controller.php */
506 /* Location: ./modules/comment/comment.admin.controller.php */
$oModuleModel
Definition: ko.install.php:236
setMessage($message= 'success', $type=NULL)
getController($module_name)
Definition: func.inc.php:90
$obj
Definition: ko.install.php:262
$output
Definition: ko.install.php:193
add($key, $val)
& getInstance($target= 'object', $info=null, $always_use_file=false)
getNotEncodedUrl()
Definition: func.inc.php:316
$module_srl
integer value to represent a run-time instance of Module (XE Module)
$args
Definition: ko.install.php:185
$module_info
an object containing the module information
setRedirectUrl($url= './', $output=NULL)
$document_srl
Definition: ko.install.php:279
$oDocumentModel
Definition: ko.install.php:259
getInstance($db_type=NULL)
Definition: DB.class.php:142
procCommentAdminMoveToTrash()
move a comment to trash
const _XE_PATH_
Definition: config.inc.php:49
$oDocumentController
Definition: ko.install.php:260
getNextSequence()
Definition: func.inc.php:236
getModel($module_name)
Definition: func.inc.php:145
getAdminController($module_name)
Definition: func.inc.php:101
cut_str($string, $cut_size=0, $tail= '...')
Definition: func.inc.php:508
executeQuery($query_id, $args=NULL, $arg_columns=NULL)
Definition: func.inc.php:203
_moveCommentToTrash($commentSrlList, &$oCommentController, &$oDB, $message_content=NULL)
triggerCall($trigger_name, $called_position, &$obj)