XpressEngine Core  1.11.2
 All Classes Namespaces Files Functions Variables Pages
board.controller.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) NAVER <http://www.navercorp.com> */
3 
10 class boardController extends board
11 {
12 
16  function init()
17  {
18  }
19 
24  {
25  // check grant
26  if($this->module_info->module != "board")
27  {
28  return new BaseObject(-1, "msg_invalid_request");
29  }
30  if(!$this->grant->write_document)
31  {
32  return new BaseObject(-1, 'msg_not_permitted');
33  }
34  $logged_info = Context::get('logged_info');
35 
36  // setup variables
38  $obj->module_srl = $this->module_srl;
39  if($obj->is_notice!='Y'||!$this->grant->manager) $obj->is_notice = 'N';
40  $obj->commentStatus = $obj->comment_status;
41 
42  $oModuleModel = getModel('module');
43  $module_config = $oModuleModel->getModuleInfoByModuleSrl($obj->module_srl);
44  if($module_config->mobile_use_editor === 'Y')
45  {
46  if(!isset($obj->use_editor)) $obj->use_editor = 'Y';
47  if(!isset($obj->use_html)) $obj->use_html = 'Y';
48  }
49  else
50  {
51  if(!isset($obj->use_editor)) $obj->use_editor = 'N';
52  if(!isset($obj->use_html)) $obj->use_html = 'N';
53  }
54 
55  settype($obj->title, "string");
56  if($obj->title == '') $obj->title = cut_str(trim(strip_tags(nl2br($obj->content))),20,'...');
57  //setup dpcument title tp 'Untitled'
58  if($obj->title == '') $obj->title = 'Untitled';
59 
60  // unset document style if the user is not the document manager
61  if(!$this->grant->manager)
62  {
63  unset($obj->title_color);
64  unset($obj->title_bold);
65  }
66 
67  // generate document module model object
68  $oDocumentModel = getModel('document');
69 
70  // generate document moduleģ˜ controller object
71  $oDocumentController = getController('document');
72 
73  // check if the document is existed
74  $oDocument = $oDocumentModel->getDocument($obj->document_srl, $this->grant->manager);
75 
76  // update the document if it is existed
77  $is_update = false;
78  if($oDocument->isExists() && $oDocument->document_srl == $obj->document_srl)
79  {
80  $is_update = true;
81  }
82 
83  // if use anonymous is true
84  if($this->module_info->use_anonymous == 'Y')
85  {
86  $this->module_info->admin_mail = '';
87  $obj->notify_message = 'N';
88  if($is_update===false)
89  {
90  $obj->member_srl = -1*$logged_info->member_srl;
91  }
92  $obj->email_address = $obj->homepage = $obj->user_id = '';
93  $obj->user_name = $obj->nick_name = 'anonymous';
94  $bAnonymous = true;
95  if($is_update===false)
96  {
97  $oDocument->add('member_srl', $obj->member_srl);
98  }
99  }
100  else
101  {
102  $bAnonymous = false;
103  }
104 
105  if($obj->is_secret == 'Y' || strtoupper($obj->status == 'SECRET'))
106  {
107  $use_status = explode('|@|', $this->module_info->use_status);
108  if(!is_array($use_status) || !in_array('SECRET', $use_status))
109  {
110  unset($obj->is_secret);
111  $obj->status = 'PUBLIC';
112  }
113  }
114 
115  // update the document if it is existed
116  if($is_update)
117  {
118  if(!$oDocument->isGranted())
119  {
120  return new BaseObject(-1,'msg_not_permitted');
121  }
122 
123  if($this->module_info->use_anonymous == 'Y') {
124  $obj->member_srl = abs($oDocument->get('member_srl')) * -1;
125  $oDocument->add('member_srl', $obj->member_srl);
126  }
127 
128  if($this->module_info->protect_content=="Y" && $oDocument->get('comment_count')>0 && $this->grant->manager==false)
129  {
130  return new BaseObject(-1,'msg_protect_content');
131  }
132 
133  if(!$this->grant->manager)
134  {
135  // notice & document style same as before if not manager
136  $obj->is_notice = $oDocument->get('is_notice');
137  $obj->title_color = $oDocument->get('title_color');
138  $obj->title_bold = $oDocument->get('title_bold');
139  }
140 
141  // modify list_order if document status is temp
142  if($oDocument->get('status') == 'TEMP')
143  {
144  $obj->last_update = $obj->regdate = date('YmdHis');
145  $obj->update_order = $obj->list_order = (getNextSequence() * -1);
146  }
147 
148  $output = $oDocumentController->updateDocument($oDocument, $obj, true);
149  $msg_code = 'success_updated';
150 
151  // insert a new document otherwise
152  } else {
153  $output = $oDocumentController->insertDocument($obj, $bAnonymous);
154  $msg_code = 'success_registed';
155  $obj->document_srl = $output->get('document_srl');
156 
157  // send an email to admin user
158  if($output->toBool() && $this->module_info->admin_mail)
159  {
160  $oModuleModel = getModel('module');
161  $member_config = $oModuleModel->getModuleConfig('member');
162 
163  $oMail = new Mail();
164  $oMail->setTitle($obj->title);
165  $oMail->setContent( sprintf("From : <a href=\"%s\">%s</a><br/>\r\n%s", getFullUrl('','document_srl',$obj->document_srl), getFullUrl('','document_srl',$obj->document_srl), $obj->content));
166  $oMail->setSender($obj->user_name ? $obj->user_name : 'anonymous', $obj->email_address ? $obj->email_address : $member_config->webmaster_email);
167 
168  $target_mail = explode(',',$this->module_info->admin_mail);
169  for($i=0;$i<count($target_mail);$i++)
170  {
171  $email_address = trim($target_mail[$i]);
172  if(!$email_address) continue;
173  $oMail->setReceiptor($email_address, $email_address);
174  $oMail->send();
175  }
176  }
177  }
178 
179  // if there is an error
180  if(!$output->toBool())
181  {
182  return $output;
183  }
184 
185  // return the results
186  $this->add('mid', Context::get('mid'));
187  $this->add('document_srl', $output->get('document_srl'));
188 
189  // alert a message
190  if(Context::get('xeVirtualRequestMethod') !== 'xml')
191  {
192  $this->setMessage($msg_code);
193  }
194  }
195 
200  {
201  // get the document_srl
202  $document_srl = Context::get('document_srl');
203 
204  // if the document is not existed
205  if(!$document_srl)
206  {
207  return $this->doError('msg_invalid_document');
208  }
209 
210  $oDocumentModel = &getModel('document');
211  $oDocument = $oDocumentModel->getDocument($document_srl);
212  // check protect content
213  if($this->module_info->protect_content=="Y" && $oDocument->get('comment_count')>0 && $this->grant->manager==false)
214  {
215  return new BaseObject(-1, 'msg_protect_content');
216  }
217 
218  // generate document module controller object
219  $oDocumentController = getController('document');
220 
221  // delete the document
222  $output = $oDocumentController->deleteDocument($document_srl, $this->grant->manager);
223  if(!$output->toBool())
224  {
225  return $output;
226  }
227 
228  // alert an message
229  $this->setRedirectUrl(getNotEncodedUrl('', 'mid', Context::get('mid'), 'act', '', 'page', Context::get('page'), 'document_srl', ''));
230  $this->add('mid', Context::get('mid'));
231  $this->add('page', Context::get('page'));
232  if(Context::get('xeVirtualRequestMethod') !== 'xml')
233  {
234  $this->setMessage('success_deleted');
235  }
236  }
237 
242  {
243  // generate document module controller object
244  $oDocumentController = getController('document');
245 
246  $document_srl = Context::get('document_srl');
247  return $oDocumentController->updateVotedCount($document_srl);
248  }
249 
254  {
255  // check grant
256  if(!$this->grant->write_comment)
257  {
258  return new BaseObject(-1, 'msg_not_permitted');
259  }
260  $logged_info = Context::get('logged_info');
261 
262  // get the relevant data for inserting comment
264  $obj->module_srl = $this->module_srl;
265 
266  if(!$this->module_info->use_status) $this->module_info->use_status = 'PUBLIC';
267  if(!is_array($this->module_info->use_status))
268  {
269  $this->module_info->use_status = explode('|@|', $this->module_info->use_status);
270  }
271 
272  if(in_array('SECRET', $this->module_info->use_status))
273  {
274  $this->module_info->secret = 'Y';
275  }
276  else
277  {
278  unset($obj->is_secret);
279  $this->module_info->secret = 'N';
280  }
281 
282  $oModuleModel = getModel('module');
283  $module_config = $oModuleModel->getModuleInfoByModuleSrl($obj->module_srl);
284  if($module_config->mobile_use_editor === 'Y')
285  {
286  if(!isset($obj->use_editor)) $obj->use_editor = 'Y';
287  if(!isset($obj->use_html)) $obj->use_html = 'Y';
288  }
289  else
290  {
291  if(!isset($obj->use_editor)) $obj->use_editor = 'N';
292  if(!isset($obj->use_html)) $obj->use_html = 'N';
293  }
294 
295  // check if the doument is existed
296  $oDocumentModel = getModel('document');
297  $oDocument = $oDocumentModel->getDocument($obj->document_srl);
298  if(!$oDocument->isExists())
299  {
300  return new BaseObject(-1,'msg_not_founded');
301  }
302 
303  // For anonymous use, remove writer's information and notifying information
304  if($this->module_info->use_anonymous == 'Y')
305  {
306  $this->module_info->admin_mail = '';
307  $obj->notify_message = 'N';
308  $obj->member_srl = -1*$logged_info->member_srl;
309  $obj->email_address = $obj->homepage = $obj->user_id = '';
310  $obj->user_name = $obj->nick_name = 'anonymous';
311  $bAnonymous = true;
312  }
313  else
314  {
315  $bAnonymous = false;
316  }
317 
318  // generate comment module model object
319  $oCommentModel = getModel('comment');
320 
321  // generate comment module controller object
322  $oCommentController = getController('comment');
323 
324  // check the comment is existed
325  // if the comment is not existed, then generate a new sequence
326  if(!$obj->comment_srl)
327  {
328  $obj->comment_srl = getNextSequence();
329  } else {
330  $comment = $oCommentModel->getComment($obj->comment_srl, $this->grant->manager);
331  }
332 
333  // if comment_srl is not existed, then insert the comment
334  if($comment->comment_srl != $obj->comment_srl)
335  {
336 
337  // parent_srl is existed
338  if($obj->parent_srl)
339  {
340  $parent_comment = $oCommentModel->getComment($obj->parent_srl);
341  if(!$parent_comment->comment_srl)
342  {
343  return new BaseObject(-1, 'msg_invalid_request');
344  }
345 
346  $output = $oCommentController->insertComment($obj, $bAnonymous);
347 
348  // parent_srl is not existed
349  } else {
350  $output = $oCommentController->insertComment($obj, $bAnonymous);
351  }
352  // update the comment if it is not existed
353  } else {
354  // check the grant
355  if(!$comment->isGranted())
356  {
357  return new BaseObject(-1,'msg_not_permitted');
358  }
359 
360  $obj->parent_srl = $comment->parent_srl;
361  $output = $oCommentController->updateComment($obj, $this->grant->manager);
362  $comment_srl = $obj->comment_srl;
363  }
364 
365  if(!$output->toBool())
366  {
367  return $output;
368  }
369 
370  if(Context::get('xeVirtualRequestMethod') !== 'xml')
371  {
372  $this->setMessage('success_registed');
373  }
374  $this->add('mid', Context::get('mid'));
375  $this->add('document_srl', $obj->document_srl);
376  $this->add('comment_srl', $obj->comment_srl);
377  }
378 
383  {
384  // get the comment_srl
385  $comment_srl = Context::get('comment_srl');
386  if(!$comment_srl)
387  {
388  return $this->doError('msg_invalid_request');
389  }
390 
391  // generate comment controller object
392  $oCommentController = getController('comment');
393 
394  $output = $oCommentController->deleteComment($comment_srl, $this->grant->manager);
395  if(!$output->toBool())
396  {
397  return $output;
398  }
399 
400  $this->add('mid', Context::get('mid'));
401  $this->add('page', Context::get('page'));
402  $this->add('document_srl', $output->get('document_srl'));
403  if(Context::get('xeVirtualRequestMethod') !== 'xml')
404  {
405  $this->setMessage('success_deleted');
406  }
407  }
408 
413  {
414  $trackback_srl = Context::get('trackback_srl');
415 
416  // generate trackback module controller object
417  $oTrackbackController = getController('trackback');
418 
419  if(!$oTrackbackController) return;
420 
421  $output = $oTrackbackController->deleteTrackback($trackback_srl, $this->grant->manager);
422  if(!$output->toBool())
423  {
424  return $output;
425  }
426 
427  $this->add('mid', Context::get('mid'));
428  $this->add('page', Context::get('page'));
429  $this->add('document_srl', $output->get('document_srl'));
430  if(Context::get('xeVirtualRequestMethod') !== 'xml')
431  {
432  $this->setMessage('success_deleted');
433  }
434  }
435 
440  {
441  // get the id number of the document and the comment
442  $password = Context::get('password');
443  $document_srl = Context::get('document_srl');
444  $comment_srl = Context::get('comment_srl');
445 
446  $oMemberModel = getModel('member');
447 
448  // if the comment exists
449  if($comment_srl)
450  {
451  // get the comment information
452  $oCommentModel = getModel('comment');
453  $oComment = $oCommentModel->getComment($comment_srl);
454  if(!$oComment->isExists())
455  {
456  return new BaseObject(-1, 'msg_invalid_request');
457  }
458 
459  // compare the comment password and the user input password
460  if(!$oMemberModel->isValidPassword($oComment->get('password'),$password))
461  {
462  return new BaseObject(-1, 'msg_invalid_password');
463  }
464 
465  $oComment->setGrant();
466  } else {
467  // get the document information
468  $oDocumentModel = getModel('document');
469  $oDocument = $oDocumentModel->getDocument($document_srl);
470  if(!$oDocument->isExists())
471  {
472  return new BaseObject(-1, 'msg_invalid_request');
473  }
474 
475  // compare the document password and the user input password
476  if(!$oMemberModel->isValidPassword($oDocument->get('password'),$password))
477  {
478  return new BaseObject(-1, 'msg_invalid_password');
479  }
480 
481  $oDocument->setGrant();
482  }
483  }
484 
489  {
490  $member_srl = Context::get('target_srl');
491  $mid = Context::get('cur_mid');
492 
493  if(!$member_srl || !$mid)
494  {
495  return new BaseObject();
496  }
497 
498  $logged_info = Context::get('logged_info');
499 
500  // get the module information
501  $oModuleModel = getModel('module');
502  $columnList = array('module');
503  $cur_module_info = $oModuleModel->getModuleInfoByMid($mid, 0, $columnList);
504 
505  if($cur_module_info->module != 'board')
506  {
507  return new BaseObject();
508  }
509 
510  // get the member information
511  if($member_srl == $logged_info->member_srl)
512  {
513  $member_info = $logged_info;
514  } else {
515  $oMemberModel = getModel('member');
516  $member_info = $oMemberModel->getMemberInfoByMemberSrl($member_srl);
517  }
518 
519  if(!$member_info->user_id)
520  {
521  return new BaseObject();
522  }
523 
524  //search
525  $url = getUrl('','mid',$mid,'search_target','nick_name','search_keyword',$member_info->nick_name);
526  $oMemberController = getController('member');
527  $oMemberController->addMemberPopupMenu($url, 'cmd_view_own_document', '');
528 
529  return new BaseObject();
530  }
531 }
procBoardInsertComment()
insert comments
$oModuleModel
Definition: ko.install.php:236
setMessage($message= 'success', $type=NULL)
getController($module_name)
Definition: func.inc.php:90
triggerMemberMenu(&$obj)
the trigger for displaying &#39;view document&#39; link when click the user ID
$obj
Definition: ko.install.php:262
$output
Definition: ko.install.php:193
add($key, $val)
getNotEncodedUrl()
Definition: func.inc.php:316
procBoardDeleteComment()
delete the comment
procBoardDeleteDocument()
delete the document
$module_srl
integer value to represent a run-time instance of Module (XE Module)
$mid
string to represent run-time instance of Module (XE Module)
setRedirectUrl($url= './', $output=NULL)
$document_srl
Definition: ko.install.php:279
init()
initialization
$oDocumentModel
Definition: ko.install.php:259
board module Controller class
$oDocumentController
Definition: ko.install.php:260
getNextSequence()
Definition: func.inc.php:236
getModel($module_name)
Definition: func.inc.php:145
procBoardDeleteTrackback()
delete the tracjback
cut_str($string, $cut_size=0, $tail= '...')
Definition: func.inc.php:508
getUrl()
Definition: func.inc.php:297
procBoardInsertDocument()
insert document
getFullUrl()
Definition: func.inc.php:361
board module high class
Definition: board.class.php:10
procBoardVerificationPassword()
check the password for document and comment