00001 <?php
00002
00021
00022
00023
00024 import('form.Form');
00025
00026 class CommentForm extends Form {
00027
00029 var $commentId;
00030
00032 var $captchaEnabled;
00033
00035 var $articleId;
00036
00038 var $comment;
00039
00041 var $parentId;
00042
00044 var $galleyId;
00045
00049 function CommentForm($commentId, $articleId, $galleyId, $parentId = null) {
00050 parent::Form('comment/comment.tpl');
00051
00052 $this->articleId = $articleId;
00053
00054 $commentDao = &DAORegistry::getDAO('CommentDAO');
00055 $this->comment = &$commentDao->getComment($commentId, $articleId);
00056
00057 import('captcha.CaptchaManager');
00058 $captchaManager =& new CaptchaManager();
00059 $this->captchaEnabled = ($captchaManager->isEnabled() && Config::getVar('captcha', 'captcha_on_comments'))?true:false;
00060
00061 if (isset($this->comment)) {
00062 $this->commentId = $commentId;
00063 }
00064
00065 $this->parentId = $parentId;
00066 $this->galleyId = $galleyId;
00067
00068 if ($this->captchaEnabled) {
00069 $this->addCheck(new FormValidatorCaptcha($this, 'captcha', 'captchaId', 'common.captchaField.badCaptcha'));
00070 }
00071 $this->addCheck(new FormValidatorPost($this));
00072 }
00073
00077 function initData() {
00078 if (isset($this->comment)) {
00079 $comment = &$this->comment;
00080 $this->_data = array(
00081 'title' => $comment->getTitle(),
00082 'body' => $comment->getBody(),
00083 'posterName' => $comment->getPosterName(),
00084 'posterEmail' => $comment->getPosterEmail()
00085 );
00086 } else {
00087 $this->_data = array();
00088 $user = Request::getUser();
00089 if ($user) {
00090 $this->_data['posterName'] = $user->getFullName();
00091 $this->_data['posterEmail'] = $user->getEmail();
00092 }
00093 }
00094 }
00095
00099 function display() {
00100 $journal = Request::getJournal();
00101
00102 $templateMgr = &TemplateManager::getManager();
00103
00104 if (isset($this->comment)) {
00105 $templateMgr->assign_by_ref('comment', $this->comment);
00106 $templateMgr->assign('commentId', $this->commentId);
00107 }
00108
00109 $user = Request::getUser();
00110 if ($user) {
00111 $templateMgr->assign('userName', $user->getFullName());
00112 $templateMgr->assign('userEmail', $user->getEmail());
00113 }
00114
00115 if ($this->captchaEnabled) {
00116 import('captcha.CaptchaManager');
00117 $captchaManager =& new CaptchaManager();
00118 $captcha =& $captchaManager->createCaptcha();
00119 if ($captcha) {
00120 $templateMgr->assign('captchaEnabled', $this->captchaEnabled);
00121 $this->setData('captchaId', $captcha->getCaptchaId());
00122 }
00123 }
00124
00125 $templateMgr->assign('parentId', $this->parentId);
00126 $templateMgr->assign('articleId', $this->articleId);
00127 $templateMgr->assign('galleyId', $this->galleyId);
00128 $templateMgr->assign('enableComments', $journal->getSetting('enableComments'));
00129
00130 parent::display();
00131 }
00132
00133
00137 function readInputData() {
00138 $userVars = array(
00139 'body',
00140 'title',
00141 'posterName',
00142 'posterEmail'
00143 );
00144 if ($this->captchaEnabled) {
00145 $userVars[] = 'captchaId';
00146 $userVars[] = 'captcha';
00147 }
00148
00149 $this->readUserVars($userVars);
00150 }
00151
00156 function execute() {
00157 $journal = &Request::getJournal();
00158 $enableComments = $journal->getSetting('enableComments');
00159
00160 $commentDao = &DAORegistry::getDAO('CommentDAO');
00161
00162 $comment = $this->comment;
00163 if (!isset($comment)) {
00164 $comment = &new Comment();
00165 }
00166
00167 $user = &Request::getUser();
00168
00169 $comment->setTitle($this->getData('title'));
00170 $comment->setBody($this->getData('body'));
00171
00172 if (($enableComments == COMMENTS_ANONYMOUS || $enableComments == COMMENTS_UNAUTHENTICATED) && (Request::getUserVar('anonymous') || $user == null)) {
00173 $comment->setPosterName($this->getData('posterName'));
00174 $comment->setPosterEmail($this->getData('posterEmail'));
00175 $comment->setUser(null);
00176 } else {
00177 $comment->setPosterName($user->getFullName());
00178 $comment->setPosterEmail($user->getEmail());
00179 $comment->setUser($user);
00180 }
00181
00182 $comment->setParentCommentId($this->parentId);
00183
00184 if (isset($this->comment)) {
00185 $commentDao->updateComment($comment);
00186 } else {
00187 $comment->setArticleId($this->articleId);
00188 $comment->setChildCommentCount(0);
00189 $commentDao->insertComment($comment);
00190 $this->commentId = $comment->getCommentId();
00191 }
00192
00193 return $this->commentId;
00194 }
00195
00196 }
00197
00198 ?>