public function showAction()
 {
     $comment_mapper = new Application_Model_CommentMapper();
     $comment = $comment_mapper->find($this->_getParam('id'));
     $comment->hide = 0;
     $comment_mapper->save($comment);
     return $this->_response->setRedirect('/admin/entry/list');
 }
 protected function _getCommentsForm($id)
 {
     // Get the comment form
     $form = new Application_Form_CommentAdd(array('entry' => $id));
     if (!$this->getRequest()->isPost()) {
         $this->view->form = $form;
         return;
     }
     if ($_POST['submit'] == 'Comment') {
         if (!$form->isValid($_POST)) {
             $this->view->errors = $form->getMessages();
             $form->setElementFilters(array());
             // disable all element filters
             $this->_repopulateForm($form, $form->getValues());
             $this->view->form = $form;
             return;
         }
         $values = $form->getValues();
         $data = array('username' => $values['username'], 'email' => $values['email'], 'url' => $values['url'], 'comment' => $values['comment'], 'published_date' => $values['published_date'], 'entry' => $values['entry']);
         $comment = new Application_Model_Comment($data);
         $comment_mapper = new Application_Model_CommentMapper();
         $comment_mapper->save($comment);
         $this->view->blog->addComment($comment);
         // Send email notification
         $mail = new Zend_Mail();
         $mail->setFrom($values['email'], $values['username']);
         $mail->addTo($this->message_details['email'], $this->message_details['name']);
         $mail->setSubject($this->message_details['commentSubject']);
         $mail->setBodyText("{$values['comment']}");
         $mail->setBodyHtml("<p>{$values['comment']}</p>");
         $mail->send();
     }
     // Add the form to the view
     $form->reset();
     $this->view->form = $form;
 }
 public function commentAction()
 {
     $request = $this->getRequest();
     $post_id = $request->getParam('post_id');
     $user_id = get_user_id();
     $content = $request->getParam('content');
     $comment_mapper = new Application_Model_CommentMapper();
     $comment_model = new Application_Model_Comment();
     $comment_model->_fields['post_id'] = $post_id;
     $comment_model->_fields['user_id'] = $user_id;
     $comment_model->_fields['content'] = $content;
     $comment_mapper->save($comment_model);
     $db = Zend_Registry::get('db');
     $sql = "update user_post set comment_number = comment_number+1 where id = " . $post_id . ";";
     $db->query($sql);
     $notification_mapper = new Application_Model_NotificationMapper();
     $notification_model = new Application_Model_Notification();
     $post_mapper = new Application_Model_PostMapper();
     $post = $post_mapper->find($post_id);
     $notification_model->_fields['user_id'] = $post['user_id'];
     $notification_model->_fields['is_seen'] = 0;
     $notification_model->_fields['content'] = get_username() . " Comment on your post with id = {$post_id}";
     $notification_mapper->save($notification_model);
     $this->_redirect('/post/home');
 }
示例#4
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;
 }