00001 <?php
00002
00020
00021
00022
00023 import('form.Form');
00024
00025 class CommentForm extends Form {
00026
00028 var $commentId;
00029
00031 var $captchaEnabled;
00032
00034 var $paperId;
00035
00037 var $comment;
00038
00040 var $parentId;
00041
00043 var $galleyId;
00044
00048 function CommentForm($commentId, $paperId, $galleyId, $parentId = null) {
00049 parent::Form('comment/comment.tpl');
00050
00051 $this->paperId = $paperId;
00052
00053 $commentDao =& DAORegistry::getDAO('CommentDAO');
00054 $this->comment =& $commentDao->getComment($commentId, $paperId);
00055
00056 import('captcha.CaptchaManager');
00057 $captchaManager = new CaptchaManager();
00058 $this->captchaEnabled = ($captchaManager->isEnabled() && Config::getVar('captcha', 'captcha_on_comments'))?true:false;
00059
00060 if (isset($this->comment)) {
00061 $this->commentId = $commentId;
00062 }
00063
00064 $this->parentId = $parentId;
00065 $this->galleyId = $galleyId;
00066
00067 $this->addCheck(new FormValidator($this, 'title', 'required', 'comments.titleRequired'));
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 $commentDao =& DAORegistry::getDAO('CommentDAO');
00088 $comment =& $commentDao->getComment($this->parentId, $this->paperId);
00089 $this->_data = array();
00090 $user = Request::getUser();
00091 if ($user) {
00092 $this->_data['posterName'] = $user->getFullName();
00093 $this->_data['posterEmail'] = $user->getEmail();
00094 $this->_data['title'] = ($comment?__('common.re') . ' ' . $comment->getTitle():'');
00095 }
00096 }
00097 }
00098
00102 function display() {
00103 $conference = Request::getConference();
00104 $schedConf = Request::getSchedConf();
00105
00106 $templateMgr =& TemplateManager::getManager();
00107
00108 if (isset($this->comment)) {
00109 $templateMgr->assign_by_ref('comment', $this->comment);
00110 $templateMgr->assign('commentId', $this->commentId);
00111 }
00112
00113 $user = Request::getUser();
00114 if ($user) {
00115 $templateMgr->assign('userName', $user->getFullName());
00116 $templateMgr->assign('userEmail', $user->getEmail());
00117 }
00118
00119 if ($this->captchaEnabled) {
00120 import('captcha.CaptchaManager');
00121 $captchaManager = new CaptchaManager();
00122 $captcha =& $captchaManager->createCaptcha();
00123 if ($captcha) {
00124 $templateMgr->assign('captchaEnabled', $this->captchaEnabled);
00125 $this->setData('captchaId', $captcha->getId());
00126 }
00127 }
00128
00129 $templateMgr->assign('parentId', $this->parentId);
00130 $templateMgr->assign('paperId', $this->paperId);
00131 $templateMgr->assign('galleyId', $this->galleyId);
00132 $closeCommentsDate = $schedConf->getSetting('closeCommentsDate');
00133 $commentsClosed = $schedConf->getSetting('closeComments')?true:false && (strtotime($closeCommentsDate < time()));
00134 $templateMgr->assign('closeCommentsDate', $closeCommentsDate);
00135 $templateMgr->assign('commentsClosed', $commentsClosed);
00136 $templateMgr->assign('enableComments', $conference->getSetting('enableComments'));
00137 $templateMgr->assign('commentsRequireRegistration', $conference->getSetting('commentsRequireRegistration'));
00138 $templateMgr->assign('commentsAllowAnonymous', $conference->getSetting('commentsAllowAnonymous'));
00139
00140 parent::display();
00141 }
00142
00143
00147 function readInputData() {
00148 $userVars = array(
00149 'body',
00150 'title',
00151 'posterName',
00152 'posterEmail'
00153 );
00154 if ($this->captchaEnabled) {
00155 $userVars[] = 'captchaId';
00156 $userVars[] = 'captcha';
00157 }
00158
00159 $this->readUserVars($userVars);
00160 }
00161
00166 function execute() {
00167 $conference =& Request::getConference();
00168 $schedConf =& Request::getSchedConf();
00169 $enableComments = $conference->getSetting('enableComments');
00170 $commentsRequireRegistration = $conference->getSetting('commentsRequireRegistration');
00171 $commentsAllowAnonymous = $conference->getSetting('commentsAllowAnonymous');
00172
00173 $commentDao =& DAORegistry::getDAO('CommentDAO');
00174
00175 $comment = $this->comment;
00176 if (!isset($comment)) {
00177 $comment = new Comment();
00178 }
00179
00180 $user =& Request::getUser();
00181
00182 $comment->setTitle($this->getData('title'));
00183 $comment->setBody($this->getData('body'));
00184
00185 if (($commentsAllowAnonymous || !$commentsRequireRegistration) && (Request::getUserVar('anonymous') || $user == null)) {
00186 $comment->setPosterName($this->getData('posterName'));
00187 $comment->setPosterEmail($this->getData('posterEmail'));
00188 $comment->setUser(null);
00189 } else {
00190 $comment->setPosterName($user->getFullName());
00191 $comment->setPosterEmail($user->getEmail());
00192 $comment->setUser($user);
00193 }
00194
00195 $comment->setParentCommentId($this->parentId);
00196
00197 if (isset($this->comment)) {
00198 $commentDao->updateComment($comment);
00199 } else {
00200 $comment->setPaperId($this->paperId);
00201 $comment->setChildCommentCount(0);
00202 $commentDao->insertComment($comment);
00203 $this->commentId = $comment->getId();
00204 }
00205
00206 return $this->commentId;
00207 }
00208
00209 }
00210
00211 ?>