public function indexAction()
 {
     $config = Zend_Registry::get('config');
     $bookName = $this->_getParam('book', $config->defaultBook);
     $pageName = $this->_getParam('page');
     // FIXME: Security check for $bookName and $pageName
     $messanger = new HHLib_FlashMessanger(new HHLib_FlashMessanger_Backend_Cookie(), array('cookiePath' => $this->view->baseUrl . '/'));
     $book = new HumanHelp_Model_Book($bookName);
     $book->setBaseUrl($this->view->baseUrl);
     if ($pageName) {
         $page = $book->getPage($pageName);
     } else {
         $page = $book->getDefaultPage();
         $pageName = $page->getName();
     }
     $commentForm = new HumanHelp_Form_Comment(array('action' => '#post-comment'));
     if ($this->_request->isPost()) {
         $formData = $this->_request->getPost();
         if ($commentForm->isValid($formData)) {
             $comment = new HumanHelp_Model_Comment(array('author_name' => $commentForm->getValue('name'), 'author_email' => $commentForm->getValue('email'), 'created_at' => $_SERVER['REQUEST_TIME'], 'book' => $bookName, 'page' => $pageName, 'comment' => $commentForm->getValue('comment'), 'token' => HumanHelp_Model_Comment::generateToken()));
             if (!$config->moderateComments) {
                 $comment->setFlags(HumanHelp_Model_Comment::FLAG_APPROVED);
             }
             try {
                 $comment->save();
                 $this->_sendNewCommentEmail($comment, $page);
                 // Set a message
                 if ($config->moderateComments) {
                     $message = "Thank you for commenting. Your comment will appear on this page after it is  reviewed by our staff";
                 } else {
                     $message = "Thank you for commenting on this page!";
                 }
                 $messanger->add($message);
                 // Redirect back to page
                 $this->_redirect("/content/{$bookName}/{$pageName}");
             } catch (Exception $ex) {
                 throw $ex;
             }
         }
     }
     $this->view->contentOnly = $this->_getParam('layout') == 'contentOnly';
     $this->view->messages = $messanger->getAllMessages();
     $this->view->book = $book;
     $this->view->page = $page;
     $this->view->commentForm = $commentForm;
     $this->view->commentsAreModerated = $config->moderateComments;
 }
Exemple #2
0
 /**
  * Get comments for this page
  * 
  * @param  boolean $approvedOnly
  * @return array
  */
 public function getComments($approvedOnly = true)
 {
     return HumanHelp_Model_Comment::getCommentsForPage($this->_book->getName(), $this->_pageName, $approvedOnly);
 }
 public function tableOfContents(HumanHelp_Model_Book $book, HumanHelp_Model_Page $page = null)
 {
     $this->_baseUrl = $this->view->baseUrl . '/content/' . $book->getName() . '/';
     $html = '<ul class="toc">' . $this->_getSubTree($book->getToc()) . '</ul>';
     return $html;
 }