XpressEngine Core  1.11.2
 All Classes Namespaces Files Functions Variables Pages
communication.controller.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) NAVER <http://www.navercorp.com> */
3 
10 {
11 
15  function init()
16  {
17 
18  }
19 
25  {
26  if(!Context::get('is_logged'))
27  {
28  return new BaseObject(-1, 'msg_not_logged');
29  }
30 
31  $args = new stdClass();
32  $args->allow_message = Context::get('allow_message');
33 
34  if(!in_array($args->allow_message, array('Y', 'N', 'F')))
35  {
36  $args->allow_message = 'Y';
37  }
38 
39  $logged_info = Context::get('logged_info');
40  $args->member_srl = $logged_info->member_srl;
41 
42  $output = executeQuery('communication.updateAllowMessage', $args);
43 
44  $returnUrl = Context::get('success_return_url') ? Context::get('success_return_url') : getNotEncodedUrl('', 'mid', Context::get('mid'), 'act', 'dispCommunicationMessages', 'message_type', Context::get('message_type'));
45 
46  return $this->setRedirectUrl($returnUrl, $output);
47  }
48 
54  {
55  // Check login information
56  if(!Context::get('is_logged'))
57  {
58  return new BaseObject(-1, 'msg_not_logged');
59  }
60 
61  $logged_info = Context::get('logged_info');
62 
63  // Check variables
64  $receiver_srl = Context::get('receiver_srl');
65  if(!$receiver_srl)
66  {
67  return new BaseObject(-1, 'msg_not_exists_member');
68  }
69 
70  $title = trim(Context::get('title'));
71  if(!$title)
72  {
73  return new BaseObject(-1, 'msg_title_is_null');
74  }
75 
76  $content = trim(Context::get('content'));
77  if(!$content)
78  {
79  return new BaseObject(-1, 'msg_content_is_null');
80  }
81 
82  $send_mail = Context::get('send_mail');
83  if($send_mail != 'Y')
84  {
85  $send_mail = 'N';
86  }
87 
88  // Check if there is a member to receive a message
89  $oMemberModel = getModel('member');
90  $oCommunicationModel = getModel('communication');
91  $config = $oCommunicationModel->getConfig();
92 
93  if(!$oCommunicationModel->checkGrant($config->grant_write))
94  {
95  return new BaseObject(-1, 'msg_not_permitted');
96  }
97 
98  $receiver_member_info = $oMemberModel->getMemberInfoByMemberSrl($receiver_srl);
99  if($receiver_member_info->member_srl != $receiver_srl)
100  {
101  return new BaseObject(-1, 'msg_not_exists_member');
102  }
103 
104  // check whether to allow to receive the message(pass if a top-administrator)
105  if($logged_info->is_admin != 'Y')
106  {
107  if($receiver_member_info->allow_message == 'F')
108  {
109  if(!$oCommunicationModel->isFriend($receiver_member_info->member_srl))
110  {
111  return new BaseObject(-1, 'msg_allow_message_to_friend');
112  }
113  }
114  else if($receiver_member_info->allow_message == 'N')
115  {
116  return new BaseObject(-1, 'msg_disallow_message');
117  }
118  }
119 
120  // send a message
121  $output = $this->sendMessage($logged_info->member_srl, $receiver_srl, $title, $content);
122 
123  if(!$output->toBool())
124  {
125  return $output;
126  }
127 
128  $message_srl = $output->get('message_srl');
129 
130  // send an e-mail
131  if($send_mail == 'Y')
132  {
133  $view_url = Context::getRequestUri();
134  $content = sprintf("%s<br /><br />From : <a href=\"%s\" target=\"_blank\">%s</a>", $content, $view_url, $view_url);
135  $oMail = new Mail();
136  $oMail->setTitle(htmlspecialchars($title, ENT_COMPAT | ENT_HTML401, 'UTF-8', false));
137  $oMail->setContent(removeHackTag($content));
138  $oMail->setSender($logged_info->nick_name, $logged_info->email_address);
139  $oMail->setReceiptor($receiver_member_info->nick_name, $receiver_member_info->email_address);
140  $oMail->send();
141  }
142 
143  if(!in_array(Context::getRequestMethod(), array('XMLRPC', 'JSON')))
144  {
145  if(Context::get('is_popup') === 'Y')
146  {
147  global $lang;
148  htmlHeader();
149  alertScript($lang->success_sended);
151  htmlFooter();
152  Context::close();
153  exit;
154  }
155  else
156  {
157  $this->setMessage('success_sended');
158  $returnUrl = Context::get('success_return_url') ? Context::get('success_return_url') : getNotEncodedUrl('act', 'dispCommunicationMessages', 'message_type', 'S', 'message_srl', $message_srl);
159  $this->setRedirectUrl($returnUrl);
160  }
161  }
162 
163  return $output;
164  }
165 
175  function sendMessage($sender_srl, $receiver_srl, $title, $content, $sender_log = TRUE)
176  {
177  $content = removeHackTag($content);
178  $title = htmlspecialchars($title, ENT_COMPAT | ENT_HTML401, 'UTF-8', false);
179 
180  $message_srl = getNextSequence();
181  $related_srl = getNextSequence();
182 
183  // messages to save in the sendor's message box
184  $sender_args = new stdClass();
185  $sender_args->sender_srl = $sender_srl;
186  $sender_args->receiver_srl = $receiver_srl;
187  $sender_args->message_type = 'S';
188  $sender_args->title = $title;
189  $sender_args->content = $content;
190  $sender_args->readed = 'N';
191  $sender_args->regdate = date("YmdHis");
192  $sender_args->message_srl = $message_srl;
193  $sender_args->related_srl = $related_srl;
194  $sender_args->list_order = $sender_args->message_srl * -1;
195 
196  // messages to save in the receiver's message box
197  $receiver_args = new stdClass();
198  $receiver_args->message_srl = $related_srl;
199  $receiver_args->related_srl = 0;
200  $receiver_args->list_order = $related_srl * -1;
201  $receiver_args->sender_srl = $sender_srl;
202  if(!$receiver_args->sender_srl)
203  {
204  $receiver_args->sender_srl = $receiver_srl;
205  }
206  $receiver_args->receiver_srl = $receiver_srl;
207  $receiver_args->message_type = 'R';
208  $receiver_args->title = $title;
209  $receiver_args->content = $content;
210  $receiver_args->readed = 'N';
211  $receiver_args->regdate = date("YmdHis");
212 
213  // Call a trigger (before)
214  $trigger_obj = new stdClass();
215  $trigger_obj->sender_srl = $sender_srl;
216  $trigger_obj->receiver_srl = $receiver_srl;
217  $trigger_obj->message_srl = $message_srl;
218  $trigger_obj->related_srl = $related_srl;
219  $trigger_obj->title = $title;
220  $trigger_obj->content = $content;
221  $trigger_obj->sender_log = $sender_log;
222  $triggerOutput = ModuleHandler::triggerCall('communication.sendMessage', 'before', $trigger_obj);
223  if(!$triggerOutput->toBool())
224  {
225  return $triggerOutput;
226  }
227 
228  $oDB = DB::getInstance();
229  $oDB->begin();
230 
231  // messages to save in the sendor's message box
232  if($sender_srl && $sender_log)
233  {
234  $output = executeQuery('communication.sendMessage', $sender_args);
235  if(!$output->toBool())
236  {
237  $oDB->rollback();
238  return $output;
239  }
240  }
241 
242  // messages to save in the receiver's message box
243  $output = executeQuery('communication.sendMessage', $receiver_args);
244  if(!$output->toBool())
245  {
246  $oDB->rollback();
247  return $output;
248  }
249 
250  // Call a trigger (after)
251  $trigger_output = ModuleHandler::triggerCall('communication.sendMessage', 'after', $trigger_obj);
252  if(!$trigger_output->toBool())
253  {
254  $oDB->rollback();
255  return $trigger_output;
256  }
257 
258  // create a flag that message is sent (in file format)
259  $flag_path = './files/member_extra_info/new_message_flags/' . getNumberingPath($receiver_srl);
260  FileHandler::makeDir($flag_path);
261  $flag_file = sprintf('%s%s', $flag_path, $receiver_srl);
262  $flag_count = FileHandler::readFile($flag_file);
263  FileHandler::writeFile($flag_file, ++$flag_count);
264 
265  $oDB->commit();
266 
267  $result = new BaseObject(0, 'success_sended');
268  $result->add('message_srl', $message_srl);
269 
270  return $result;
271  }
272 
278  {
279  // Check login information
280  if(!Context::get('is_logged'))
281  {
282  return new BaseObject(-1, 'msg_not_logged');
283  }
284  $logged_info = Context::get('logged_info');
285 
286  // Check variable
287  $message_srl = Context::get('message_srl');
288  if(!$message_srl)
289  {
290  return new BaseObject(-1, 'msg_invalid_request');
291  }
292 
293  // get the message
294  $oCommunicationModel = getModel('communication');
295  $message = $oCommunicationModel->getSelectedMessage($message_srl);
296  if(!$message || $message->message_type != 'R')
297  {
298  return new BaseObject(-1, 'msg_invalid_request');
299  }
300 
301  $args = new stdClass();
302  $args->message_srl = $message_srl;
303  $args->receiver_srl = $logged_info->member_srl;
304  $output = executeQuery('communication.setMessageStored', $args);
305  if(!$output->toBool())
306  {
307  return $output;
308  }
309 
310  $this->setMessage('success_registed');
311  }
312 
318  {
319  // Check login information
320  if(!Context::get('is_logged'))
321  {
322  return new BaseObject(-1, 'msg_not_logged');
323  }
324 
325  $logged_info = Context::get('logged_info');
326  $member_srl = $logged_info->member_srl;
327 
328  // Check the variable
329  $message_srl = Context::get('message_srl');
330  if(!$message_srl)
331  {
332  return new BaseObject(-1, 'msg_invalid_request');
333  }
334 
335  // Get the message
336  $oCommunicationModel = getModel('communication');
337  $message = $oCommunicationModel->getSelectedMessage($message_srl);
338  if(!$message)
339  {
340  return new BaseObject(-1, 'msg_invalid_request');
341  }
342 
343  // Check the grant
344  switch($message->message_type)
345  {
346  case 'S':
347  if($message->sender_srl != $member_srl)
348  {
349  return new BaseObject(-1, 'msg_invalid_request');
350  }
351  break;
352 
353  case 'R':
354  if($message->receiver_srl != $member_srl)
355  {
356  return new BaseObject(-1, 'msg_invalid_request');
357  }
358  break;
359  }
360 
361  // Delete
362  $args = new stdClass();
363  $args->message_srl = $message_srl;
364  $output = executeQuery('communication.deleteMessage', $args);
365  if(!$output->toBool())
366  {
367  return $output;
368  }
369 
370  $this->setMessage('success_deleted');
371  }
372 
378  {
379  // Check login information
380  if(!Context::get('is_logged'))
381  {
382  return new BaseObject(-1, 'msg_not_logged');
383  }
384 
385  $logged_info = Context::get('logged_info');
386  $member_srl = $logged_info->member_srl;
387 
388  // check variables
389  if(!Context::get('message_srl_list'))
390  {
391  return new BaseObject(-1, 'msg_cart_is_null');
392  }
393 
394  $message_srl_list = Context::get('message_srl_list');
395  if(!is_array($message_srl_list))
396  {
397  $message_srl_list = explode('|@|', trim($message_srl_list));
398  }
399 
400  if(!count($message_srl_list))
401  {
402  return new BaseObject(-1, 'msg_cart_is_null');
403  }
404 
405  $message_type = Context::get('message_type');
406  if(!$message_type || !in_array($message_type, array('R', 'S', 'T')))
407  {
408  return new BaseObject(-1, 'msg_invalid_request');
409  }
410 
411  $message_count = count($message_srl_list);
412  $target = array();
413  for($i = 0; $i < $message_count; $i++)
414  {
415  $message_srl = (int) trim($message_srl_list[$i]);
416  if(!$message_srl)
417  {
418  continue;
419  }
420 
421  $target[] = $message_srl;
422  }
423  if(!count($target))
424  {
425  return new BaseObject(-1, 'msg_cart_is_null');
426  }
427 
428  // Delete
429  $args = new stdClass();
430  $args->message_srls = implode(',', $target);
431  $args->message_type = $message_type;
432 
433  if($message_type == 'S')
434  {
435  $args->sender_srl = $member_srl;
436  }
437  else
438  {
439  $args->receiver_srl = $member_srl;
440  }
441 
442  $output = executeQuery('communication.deleteMessages', $args);
443  if(!$output->toBool())
444  {
445  return $output;
446  }
447 
448  $this->setMessage('success_deleted');
449 
450  $returnUrl = Context::get('success_return_url') ? Context::get('success_return_url') : getNotEncodedUrl('', 'mid', Context::get('mid'), 'act', 'dispCommunicationMessages', 'message_type', Context::get('message_type'));
451  $this->setRedirectUrl($returnUrl);
452  }
453 
459  {
460  // Check login information
461  if(!Context::get('is_logged'))
462  {
463  return new BaseObject(-1, 'msg_not_logged');
464  }
465 
466  $logged_info = Context::get('logged_info');
467 
468  $target_srl = (int) trim(Context::get('target_srl'));
469  if(!$target_srl)
470  {
471  return new BaseObject(-1, 'msg_invalid_request');
472  }
473 
474  // Variable
475  $args = new stdClass();
476  $args->friend_srl = getNextSequence();
477  $args->list_order = $args->friend_srl * -1;
478  $args->friend_group_srl = Context::get('friend_group_srl');
479  $args->member_srl = $logged_info->member_srl;
480  $args->target_srl = $target_srl;
481  $output = executeQuery('communication.addFriend', $args);
482  if(!$output->toBool())
483  {
484  return $output;
485  }
486 
487  $this->add('member_srl', $target_srl);
488  $this->setMessage('success_registed');
489 
490  if(!in_array(Context::getRequestMethod(), array('XMLRPC', 'JSON')))
491  {
492  global $lang;
493  htmlHeader();
494  alertScript($lang->success_registed);
496  htmlFooter();
497  Context::close();
498  exit;
499  }
500  }
501 
507  {
508  // Check login information
509  if(!Context::get('is_logged'))
510  {
511  return new BaseObject(-1, 'msg_not_logged');
512  }
513 
514  $logged_info = Context::get('logged_info');
515 
516  // Check variables
517  $friend_srl_list = Context::get('friend_srl_list');
518  if(!$friend_srl_list)
519  {
520  return new BaseObject(-1, 'msg_cart_is_null');
521  }
522 
523  if(!is_array($friend_srl_list))
524  {
525  $friend_srl_list = explode('|@|', $friend_srl_list);
526  }
527 
528  if(!count($friend_srl_list))
529  {
530  return new BaseObject(-1, 'msg_cart_is_null');
531  }
532 
533  $friend_count = count($friend_srl_list);
534  $target = array();
535  for($i = 0; $i < $friend_count; $i++)
536  {
537  $friend_srl = (int) trim($friend_srl_list[$i]);
538  if(!$friend_srl)
539  {
540  continue;
541  }
542 
543  $target[] = $friend_srl;
544  }
545 
546  if(!count($target))
547  {
548  return new BaseObject(-1, 'msg_cart_is_null');
549  }
550 
551  // Variables
552  $args = new stdClass();
553  $args->friend_srls = implode(',', $target);
554  $args->member_srl = $logged_info->member_srl;
555  $args->friend_group_srl = Context::get('target_friend_group_srl');
556 
557  $output = executeQuery('communication.moveFriend', $args);
558  if(!$output->toBool())
559  {
560  return $output;
561  }
562 
563  $this->setMessage('success_moved');
564 
565  $returnUrl = Context::get('success_return_url') ? Context::get('success_return_url') : getNotEncodedUrl('', 'mid', Context::get('mid'), 'act', 'dispCommunicationFriend');
566  $this->setRedirectUrl($returnUrl);
567  }
568 
574  {
575  // Check login information
576  if(!Context::get('is_logged'))
577  {
578  return new BaseObject(-1, 'msg_not_logged');
579  }
580 
581  $logged_info = Context::get('logged_info');
582  $member_srl = $logged_info->member_srl;
583 
584  // Check variables
585  $friend_srl_list = Context::get('friend_srl_list');
586 
587  if(!is_array($friend_srl_list))
588  {
589  $friend_srl_list = explode('|@|', $friend_srl_list);
590  }
591 
592  if(!count($friend_srl_list))
593  {
594  return new BaseObject(-1, 'msg_cart_is_null');
595  }
596 
597  $friend_count = count($friend_srl_list);
598  $target = array();
599 
600  for($i = 0; $i < $friend_count; $i++)
601  {
602  $friend_srl = (int) trim($friend_srl_list[$i]);
603  if(!$friend_srl)
604  {
605  continue;
606  }
607 
608  $target[] = $friend_srl;
609  }
610 
611  if(!count($target))
612  {
613  return new BaseObject(-1, 'msg_cart_is_null');
614  }
615 
616  // Delete
617  $args = new stdClass();
618  $args->friend_srls = implode(',', $target);
619  $args->member_srl = $logged_info->member_srl;
620  $output = executeQuery('communication.deleteFriend', $args);
621  if(!$output->toBool())
622  {
623  return $output;
624  }
625 
626  $this->setMessage('success_deleted');
627 
628  $returnUrl = Context::get('success_return_url') ? Context::get('success_return_url') : getNotEncodedUrl('', 'mid', Context::get('mid'), 'act', 'dispCommunicationFriend');
629  $this->setRedirectUrl($returnUrl);
630  }
631 
637  {
638  // Check login information
639  if(!Context::get('is_logged'))
640  {
641  return new BaseObject(-1, 'msg_not_logged');
642  }
643 
644  $logged_info = Context::get('logged_info');
645 
646  // Variables
647  $args = new stdClass();
648  $args->friend_group_srl = trim(Context::get('friend_group_srl'));
649  $args->member_srl = $logged_info->member_srl;
650  $args->title = Context::get('title');
651  $args->title = htmlspecialchars($args->title, ENT_COMPAT | ENT_HTML401, 'UTF-8', false);
652 
653  if(!$args->title)
654  {
655  return new BaseObject(-1, 'msg_invalid_request');
656  }
657 
658  // modify if friend_group_srl exists.
659  if($args->friend_group_srl)
660  {
661  $output = executeQuery('communication.renameFriendGroup', $args);
662  $msg_code = 'success_updated';
663  // add if not exists
664  }
665  else
666  {
667  $output = executeQuery('communication.addFriendGroup', $args);
668  $msg_code = 'success_registed';
669  }
670 
671  if(!$output->toBool())
672  {
673  if(!in_array(Context::getRequestMethod(), array('XMLRPC', 'JSON')))
674  {
675  global $lang;
676  htmlHeader();
677  alertScript($lang->fail_to_registed);
679  htmlFooter();
680  Context::close();
681  exit;
682  }
683  else
684  {
685  return $output;
686  }
687  }
688  else
689  {
690  if(!in_array(Context::getRequestMethod(), array('XMLRPC', 'JSON')))
691  {
692  global $lang;
693  htmlHeader();
694  alertScript($lang->success_registed);
695  reload(true);
697  htmlFooter();
698  Context::close();
699  exit;
700  }
701  else
702  {
703  $this->setMessage($msg_code);
704  }
705  }
706  }
707 
713  {
714  // Check login information
715  if(!Context::get('is_logged'))
716  {
717  return new BaseObject(-1, 'msg_not_logged');
718  }
719 
720  $logged_info = Context::get('logged_info');
721 
722  // Variables
723  $args = new stdClass();
724  $args->friend_group_srl = Context::get('friend_group_srl');
725  $args->member_srl = $logged_info->member_srl;
726  $args->title = Context::get('title');
727  $args->title = htmlspecialchars($args->title, ENT_COMPAT | ENT_HTML401, 'UTF-8', false);
728 
729  if(!$args->title)
730  {
731  return new BaseObject(-1, 'msg_invalid_request');
732  }
733 
734  $output = executeQuery('communication.renameFriendGroup', $args);
735  if(!$output->toBool())
736  {
737  return $output;
738  }
739 
740  $this->setMessage('success_updated');
741  }
742 
748  {
749  // Check login information
750  if(!Context::get('is_logged'))
751  {
752  return new BaseObject(-1, 'msg_not_logged');
753  }
754 
755  $logged_info = Context::get('logged_info');
756 
757  // Variables
758  $args = new stdClass();
759  $args->friend_group_srl = Context::get('friend_group_srl');
760  $args->member_srl = $logged_info->member_srl;
761  $output = executeQuery('communication.deleteFriendGroup', $args);
762  if(!$output->toBool())
763  {
764  return $output;
765  }
766 
767  $this->setMessage('success_deleted');
768  }
769 
775  function setMessageReaded($message_srl)
776  {
777  $args = new stdClass();
778  $args->message_srl = $message_srl;
779  $args->related_srl = $message_srl;
780  return executeQuery('communication.setMessageReaded', $args);
781  }
782 
783 }
784 /* End of file communication.controller.php */
785 /* Location: ./modules/comment/communication.controller.php */
setMessage($message= 'success', $type=NULL)
getNumberingPath($no, $size=3)
Definition: func.inc.php:1081
$output
Definition: ko.install.php:193
add($key, $val)
getNotEncodedUrl()
Definition: func.inc.php:316
writeFile($filename, $buff, $mode="w")
closePopupScript()
Definition: func.inc.php:1757
reload($isOpener=FALSE)
Definition: func.inc.php:1772
$args
Definition: ko.install.php:185
setRedirectUrl($url= './', $output=NULL)
alertScript($msg)
Definition: func.inc.php:1738
getInstance($db_type=NULL)
Definition: DB.class.php:142
htmlFooter()
Definition: func.inc.php:1727
makeDir($path_string)
removeHackTag($content)
Definition: func.inc.php:1123
readFile($filename)
getNextSequence()
Definition: func.inc.php:236
getRequestUri($ssl_mode=FOLLOW_REQUEST_SSL, $domain=null)
getModel($module_name)
Definition: func.inc.php:145
htmlHeader()
Definition: func.inc.php:1712
executeQuery($query_id, $args=NULL, $arg_columns=NULL)
Definition: func.inc.php:203
triggerCall($trigger_name, $called_position, &$obj)
sendMessage($sender_srl, $receiver_srl, $title, $content, $sender_log=TRUE)
if(isset($_REQUEST['encode'])) if(isset($_REQUEST['decode'])) $lang
Definition: example.php:23