public function replyAction()
 {
     $this->view->form = $form = new Application_Form_Comment();
     // id post
     $id = $this->_request->getParam('id', 0);
     $post = $this->_request->getParam('post', 0);
     if ($this->_request->isPost() && $id > 0) {
         $formData = $this->_request->getPost();
         if ($form->isValid($formData)) {
             $c = new Application_Model_DbTable_Comments();
             $c->addComment($form->getValues());
             $this->_redirect('/post/index');
         } else {
             $form->populate($formData);
         }
     } else {
         if ($id > 0) {
             $form->parent->setValue($id);
             $form->post->setValue($post);
         }
     }
 }
Example #2
0
 public function init()
 {
     $this->setAction('/news/comment');
     parent::init();
 }
Example #3
0
 public function submitAction()
 {
     /*****************************************************
      * Add a new comment to the database from a form,
      * or if there's none supplied return the form.
      * We then do a poll and send back the whole lot
      * as JSON.
      */
     //IE doesn't sent a content-type header with X site requests,
     //And PHP doesn't fill in $_POST if that happens. Fix it:
     $request_body = urldecode(file_get_contents("php://input"));
     parse_str($request_body, $_POST);
     $this->view->title = "Submit Conversation";
     $this->allowAccessControl();
     $request = $this->getRequest();
     $form = new Application_Form_Comment();
     if ($this->getRequest()->isPost()) {
         if ($form->isValid($_POST)) {
             $initVals = $form->getValues();
             $initVals = $this->formDataToObjectData($initVals);
             if (!is_array($initVals)) {
                 throw new Exception("Can't initialize form data");
             }
             if (substr($initVals['content'], 0, 1) == "/") {
                 //Oh, special command!
                 $reply = $this->processCommand($initVals);
                 $this->doPollingStuffAndOutputJSON(array("command" => $initVals['content'], "content" => $reply));
             } else {
                 //Just submit the comment.
                 $comment = new Application_Model_Comment($initVals);
                 $mapper = new Application_Model_CommentMapper();
                 $mapper->save($comment);
                 $urlcachemapper = new Application_Model_UrlcacheMapper();
                 $urlcache = $urlcachemapper->findOneWhere($comment->getDomain(), $comment->getPath());
                 $urlcache->incPostcount();
                 $urlcachemapper->save($urlcache);
             }
             $this->doPollingStuffAndOutputJSON(array("content" => $comment->getContent(), "nick" => $comment->getNick(), "email" => $comment->getEmail()));
         }
     }
     $this->view->form = $form;
 }