public function executeAddComment(sfWebRequest $request) { $this->commentForm = new sfNestedCommentFrontForm(null, $this->getUser()); $bindValues = $request->getParameter($this->commentForm->getName()); if (sfNestedCommentConfig::isRecaptchaEnabled()) { $captcha = array( 'recaptcha_challenge_field' => $request->getParameter('recaptcha_challenge_field'), 'recaptcha_response_field' => $request->getParameter('recaptcha_response_field'), ); $bindValues = array_merge($bindValues, array('captcha' => $captcha)); } $this->commentForm->bind($bindValues); if ($this->commentForm->isValid()) { $comment = $this->commentForm->save(); $this->getUser()->setFlash('add_comment', $comment->getIsModerated() ? 'moderated' : 'normal'); $this->dispatcher->notify(new sfEvent($this, 'sf_nested_comment.add', array('object' => $comment))); $email_pref = sfNestedCommentConfig::isMailEnabled(); if($email_pref == true || ($email_pref == 'moderated' && $comment->getIsModerated())) { $params = $this->prepareMailParameter($comment); sfNestedCommentTools::sendEmail($this->getMailer(), $params); } if($request->isXmlHttpRequest()) { $this->setLayout(false); sfConfig::set('sf_web_debug', false); $commentableObject = $comment->getCommentableObject(); $comments = sfNestedCommentTools::getComments($commentableObject, $request); return $this->renderPartial('sfNestedComment/comments', array('object' => $commentableObject, 'comments' => $comments, 'commentForm' => sfNestedCommentTools::createCommentForm($commentableObject))); } else { return $this->redirect($request->getReferer()); } } else { if($request->isXmlHttpRequest()) { $this->getResponse()->setStatusCode(404); $this->setLayout(false); sfConfig::set('sf_web_debug', false); return $this->renderPartial('sfNestedComment/add_comment', array('commentForm' => $this->commentForm)); } else { return 'Error'; } } }
public function configure() { parent::configure(); $user = $this->getOption('user', null); if ($user && $user->isAuthenticated()) { $this->useFields(array('id', 'author_name', 'author_email', 'author_url', 'content', 'sf_comment_id', 'user_id')); $this->widgetSchema['author_name'] = new sfWidgetFormInputHidden(); $this->widgetSchema['author_email'] = new sfWidgetFormInputHidden(); $this->widgetSchema['author_url'] = new sfWidgetFormInputHidden(); $this->widgetSchema['user_id'] = new sfWidgetFormInputHidden(); } else { $this->useFields(array('id', 'author_name', 'author_email', 'author_url', 'content', 'sf_comment_id')); $this->widgetSchema['author_name']->setLabel('Name (required)'); $this->widgetSchema['author_email']->setLabel('Mail (required) (will not be published)'); $this->widgetSchema['author_url']->setLabel('Website'); } $this->validatorSchema['author_name'] = new sfValidatorString(array('required' => true)); $this->validatorSchema['author_email'] = new sfValidatorEmail(array('required' => true)); $this->validatorSchema['author_url'] = new sfValidatorUrl(array('required' => false)); $this->validatorSchema['content'] = new sfValidatorString(array('required' => true)); $this->widgetSchema['content']->setAttributes(array('rows' => 10, 'class' => 'resizable')); $this->widgetSchema['content']->setLabel('Comment (required)'); if ($allowedTags = sfNestedCommentConfig::getAllowedTags()) { $this->widgetSchema->setHelp('content', 'You may use these HTML tags and attributes: '.htmlentities(implode(' ', $allowedTags))); } $this->widgetSchema['commentable_model'] = new sfWidgetFormInputHidden(); $this->widgetSchema['commentable_id'] = new sfWidgetFormInputHidden(); $this->validatorSchema['commentable_model'] = new sfValidatorString(); $this->validatorSchema['commentable_id'] = new sfValidatorInteger(); if (sfNestedCommentConfig::isRecaptchaEnabled()) { $this->widgetSchema['captcha'] = new sfWidgetFormReCaptcha(array( 'public_key' => sfConfig::get('app_recaptcha_public_key') )); $this->validatorSchema['captcha'] = new sfValidatorReCaptcha(array( 'private_key' => sfConfig::get('app_recaptcha_private_key') )); } $this->validatorSchema->setOption('allow_extra_fields', true); $this->validatorSchema->setOption('filter_extra_fields', true); $this->getWidgetSchema()->setFormFormatterName('comment'); }