PageRenderTime 48ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/board.controller.php

http://xe-board.googlecode.com/
PHP | 353 lines | 192 code | 66 blank | 95 comment | 55 complexity | 62ce5bb3d71f3f320d1bb3558527f388 MD5 | raw file
  1. <?php
  2. /**
  3. * @class boardController
  4. * @author NHN (developers@xpressengine.com)
  5. * @brief board module Controller class
  6. **/
  7. class boardController extends board {
  8. /**
  9. * @brief initialization
  10. **/
  11. function init() {
  12. }
  13. /**
  14. * @brief insert document
  15. **/
  16. function procBoardInsertDocument() {
  17. // check grant
  18. if($this->module_info->module != "board") return new Object(-1, "msg_invalid_request");
  19. if(!$this->grant->write_document) return new Object(-1, 'msg_not_permitted');
  20. $logged_info = Context::get('logged_info');
  21. // setup variables
  22. $obj = Context::getRequestVars();
  23. $obj->module_srl = $this->module_srl;
  24. if($obj->is_notice!='Y'||!$this->grant->manager) $obj->is_notice = 'N';
  25. $obj->commentStatus = $obj->comment_status;
  26. settype($obj->title, "string");
  27. if($obj->title == '') $obj->title = cut_str(strip_tags($obj->content),20,'...');
  28. //setup dpcument title tp 'Untitled'
  29. if($obj->title == '') $obj->title = 'Untitled';
  30. // unset document style if the user is not the document manager
  31. if(!$this->grant->manager) {
  32. unset($obj->title_color);
  33. unset($obj->title_bold);
  34. }
  35. // generate document module model object
  36. $oDocumentModel = &getModel('document');
  37. // generate document module??&#x2DC; controller object
  38. $oDocumentController = &getController('document');
  39. // check if the document is existed
  40. $oDocument = $oDocumentModel->getDocument($obj->document_srl, $this->grant->manager);
  41. // if use anonymous is true
  42. if($this->module_info->use_anonymous == 'Y') {
  43. $obj->notify_message = 'N';
  44. $this->module_info->admin_mail = '';
  45. $obj->member_srl = -1*$logged_info->member_srl;
  46. $obj->email_address = $obj->homepage = $obj->user_id = '';
  47. $obj->user_name = $obj->nick_name = 'anonymous';
  48. $bAnonymous = true;
  49. $oDocument->add('member_srl', $obj->member_srl);
  50. }
  51. else
  52. {
  53. $bAnonymous = false;
  54. }
  55. // update the document if it is existed
  56. if($oDocument->isExists() && $oDocument->document_srl == $obj->document_srl) {
  57. if(!$oDocument->isGranted()) return new Object(-1,'msg_not_permitted');
  58. if(!$this->grant->manager) {
  59. // notice & document style same as before if not manager
  60. $obj->is_notice = $oDocument->get('is_notice');
  61. $obj->title_color = $oDocument->get('title_color');
  62. $obj->title_bold = $oDocument->get('title_bold');
  63. }
  64. $output = $oDocumentController->updateDocument($oDocument, $obj);
  65. $msg_code = 'success_updated';
  66. // insert a new document otherwise
  67. } else {
  68. $output = $oDocumentController->insertDocument($obj, $bAnonymous);
  69. $msg_code = 'success_registed';
  70. $obj->document_srl = $output->get('document_srl');
  71. // send an email to admin user
  72. if($output->toBool() && $this->module_info->admin_mail) {
  73. $oMail = new Mail();
  74. $oMail->setTitle($obj->title);
  75. $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));
  76. $oMail->setSender($obj->user_name, $obj->email_address);
  77. $target_mail = explode(',',$this->module_info->admin_mail);
  78. for($i=0;$i<count($target_mail);$i++) {
  79. $email_address = trim($target_mail[$i]);
  80. if(!$email_address) continue;
  81. $oMail->setReceiptor($email_address, $email_address);
  82. $oMail->send();
  83. }
  84. }
  85. }
  86. // if there is an error
  87. if(!$output->toBool()) return $output;
  88. // return the results
  89. $this->add('mid', Context::get('mid'));
  90. $this->add('document_srl', $output->get('document_srl'));
  91. // alert a message
  92. $this->setMessage($msg_code);
  93. }
  94. /**
  95. * @brief delete the document
  96. **/
  97. function procBoardDeleteDocument() {
  98. // get the document_srl
  99. $document_srl = Context::get('document_srl');
  100. // if the document is not existed
  101. if(!$document_srl) return $this->doError('msg_invalid_document');
  102. // generate document module controller object
  103. $oDocumentController = &getController('document');
  104. // delete the document
  105. $output = $oDocumentController->deleteDocument($document_srl, $this->grant->manager);
  106. if(!$output->toBool()) return $output;
  107. // alert an message
  108. $this->add('mid', Context::get('mid'));
  109. $this->add('page', $output->get('page'));
  110. $this->setMessage('success_deleted');
  111. }
  112. /**
  113. * @brief vote
  114. **/
  115. function procBoardVoteDocument() {
  116. // generate document module controller object
  117. $oDocumentController = &getController('document');
  118. $document_srl = Context::get('document_srl');
  119. return $oDocumentController->updateVotedCount($document_srl);
  120. }
  121. /**
  122. * @brief insert comments
  123. **/
  124. function procBoardInsertComment() {
  125. // check grant
  126. if(!$this->grant->write_comment) return new Object(-1, 'msg_not_permitted');
  127. $logged_info = Context::get('logged_info');
  128. // get the relevant data for inserting comment
  129. $obj = Context::gets('document_srl','comment_srl','parent_srl','content','password','nick_name','member_srl','email_address','homepage','is_secret','notify_message','use_html');
  130. $obj->module_srl = $this->module_srl;
  131. // check if the doument is existed
  132. $oDocumentModel = &getModel('document');
  133. $oDocument = $oDocumentModel->getDocument($obj->document_srl);
  134. if(!$oDocument->isExists()) return new Object(-1,'msg_not_permitted');
  135. // For anonymous use, remove writer's information and notifying information
  136. if($this->module_info->use_anonymous == 'Y') {
  137. $obj->notify_message = 'N';
  138. $this->module_info->admin_mail = '';
  139. $obj->member_srl = -1*$logged_info->member_srl;
  140. $obj->email_address = $obj->homepage = $obj->user_id = '';
  141. $obj->user_name = $obj->nick_name = 'anonymous';
  142. $bAnonymous = true;
  143. }
  144. else
  145. {
  146. $bAnonymous = false;
  147. }
  148. // generate comment module model object
  149. $oCommentModel = &getModel('comment');
  150. // generate comment module controller object
  151. $oCommentController = &getController('comment');
  152. // check the comment is existed
  153. // if the comment is not existed, then generate a new sequence
  154. if(!$obj->comment_srl) {
  155. $obj->comment_srl = getNextSequence();
  156. } else {
  157. $comment = $oCommentModel->getComment($obj->comment_srl, $this->grant->manager);
  158. }
  159. // if comment_srl is not existed, then insert the comment
  160. if($comment->comment_srl != $obj->comment_srl) {
  161. // parent_srl is existed
  162. if($obj->parent_srl) {
  163. $parent_comment = $oCommentModel->getComment($obj->parent_srl);
  164. if(!$parent_comment->comment_srl) return new Object(-1, 'msg_invalid_request');
  165. $output = $oCommentController->insertComment($obj, $bAnonymous);
  166. // parent_srl is not existed
  167. } else {
  168. $output = $oCommentController->insertComment($obj, $bAnonymous);
  169. }
  170. /*
  171. // send an email
  172. if($output->toBool() && $this->module_info->admin_mail) {
  173. $oMail = new Mail();
  174. $oMail->setTitle($oDocument->getTitleText());
  175. $oMail->setContent( sprintf("From : <a href=\"%s#comment_%d\">%s#comment_%d</a><br/>\r\n%s", getFullUrl('','document_srl',$obj->document_srl),$obj->comment_srl, getFullUrl('','document_srl',$obj->document_srl), $obj->comment_srl, $obj->content));
  176. $oMail->setSender($obj->user_name, $obj->email_address);
  177. $target_mail = explode(',',$this->module_info->admin_mail);
  178. for($i=0;$i<count($target_mail);$i++) {
  179. $email_address = trim($target_mail[$i]);
  180. if(!$email_address) continue;
  181. $oMail->setReceiptor($email_address, $email_address);
  182. $oMail->send();
  183. }
  184. }
  185. */
  186. // update the comment if it is not existed
  187. } else {
  188. // check the grant
  189. if(!$comment->isGranted()) return new Object(-1,'msg_not_permitted');
  190. $obj->parent_srl = $comment->parent_srl;
  191. $output = $oCommentController->updateComment($obj, $this->grant->manager);
  192. $comment_srl = $obj->comment_srl;
  193. }
  194. if(!$output->toBool()) return $output;
  195. $this->setMessage('success_registed');
  196. $this->add('mid', Context::get('mid'));
  197. $this->add('document_srl', $obj->document_srl);
  198. $this->add('comment_srl', $obj->comment_srl);
  199. }
  200. /**
  201. * @brief delete the comment
  202. **/
  203. function procBoardDeleteComment() {
  204. // get the comment_srl
  205. $comment_srl = Context::get('comment_srl');
  206. if(!$comment_srl) return $this->doError('msg_invalid_request');
  207. // generate comment controller object
  208. $oCommentController = &getController('comment');
  209. $output = $oCommentController->deleteComment($comment_srl, $this->grant->manager);
  210. if(!$output->toBool()) return $output;
  211. $this->add('mid', Context::get('mid'));
  212. $this->add('page', Context::get('page'));
  213. $this->add('document_srl', $output->get('document_srl'));
  214. $this->setMessage('success_deleted');
  215. }
  216. /**
  217. * @brief delete the tracjback
  218. **/
  219. function procBoardDeleteTrackback() {
  220. $trackback_srl = Context::get('trackback_srl');
  221. // generate trackback module controller object
  222. $oTrackbackController = &getController('trackback');
  223. $output = $oTrackbackController->deleteTrackback($trackback_srl, $this->grant->manager);
  224. if(!$output->toBool()) return $output;
  225. $this->add('mid', Context::get('mid'));
  226. $this->add('page', Context::get('page'));
  227. $this->add('document_srl', $output->get('document_srl'));
  228. $this->setMessage('success_deleted');
  229. }
  230. /**
  231. * @brief check the password for document and comment
  232. **/
  233. function procBoardVerificationPassword() {
  234. // get the id number of the document and the comment
  235. $password = Context::get('password');
  236. $document_srl = Context::get('document_srl');
  237. $comment_srl = Context::get('comment_srl');
  238. $oMemberModel = &getModel('member');
  239. // if the comment exists
  240. if($comment_srl) {
  241. // get the comment information
  242. $oCommentModel = &getModel('comment');
  243. $oComment = $oCommentModel->getComment($comment_srl);
  244. if(!$oComment->isExists()) return new Object(-1, 'msg_invalid_request');
  245. // compare the comment password and the user input password
  246. if(!$oMemberModel->isValidPassword($oComment->get('password'),$password)) return new Object(-1, 'msg_invalid_password');
  247. $oComment->setGrant();
  248. } else {
  249. // get the document information
  250. $oDocumentModel = &getModel('document');
  251. $oDocument = $oDocumentModel->getDocument($document_srl);
  252. if(!$oDocument->isExists()) return new Object(-1, 'msg_invalid_request');
  253. // compare the document password and the user input password
  254. if(!$oMemberModel->isValidPassword($oDocument->get('password'),$password)) return new Object(-1, 'msg_invalid_password');
  255. $oDocument->setGrant();
  256. }
  257. }
  258. /**
  259. * @brief the trigger for displaying 'view document' link when click the user ID
  260. **/
  261. function triggerMemberMenu(&$obj) {
  262. $member_srl = Context::get('target_srl');
  263. $mid = Context::get('cur_mid');
  264. if(!$member_srl || !$mid) return new Object();
  265. $logged_info = Context::get('logged_info');
  266. // get the module information
  267. $oModuleModel = &getModel('module');
  268. $columnList = array('module');
  269. $cur_module_info = $oModuleModel->getModuleInfoByMid($mid, 0, $columnList);
  270. if($cur_module_info->module != 'board') return new Object();
  271. // get the member information
  272. if($member_srl == $logged_info->member_srl) {
  273. $member_info = $logged_info;
  274. } else {
  275. $oMemberModel = &getModel('member');
  276. $member_info = $oMemberModel->getMemberInfoByMemberSrl($member_srl);
  277. }
  278. if(!$member_info->user_id) return new Object();
  279. //search
  280. $url = getUrl('','mid',$mid,'search_target','nick_name','search_keyword',$member_info->nick_name);
  281. $oMemberController = &getController('member');
  282. $oMemberController->addMemberPopupMenu($url, 'cmd_view_own_document', '');
  283. return new Object();
  284. }
  285. }
  286. ?>