Exemplo n.º 1
0
 /**
  * Send email notification to moderators when a new comment is posted
  * 
  * @todo move logic to model / library class
  * 
  * @param HumanHelp_Model_Comment $comment
  * @param HumanHelp_Model_Page $page
  */
 public function _sendNewCommentEmail(HumanHelp_Model_Comment $comment, HumanHelp_Model_Page $page)
 {
     $config = Zend_Registry::get('config');
     $emailTemplate = new Zend_View();
     $emailTemplate->setScriptPath(APPLICATION_PATH . '/views/emails');
     $emailTemplate->addHelperPath(APPLICATION_PATH . '/views/helpers', 'HumanHelp_View_Helper_');
     $emailTemplate->setEncoding('UTF-8');
     $emailTemplate->comment = $comment;
     $emailTemplate->page = $page;
     $emailTemplate->baseUrl = 'http://' . $_SERVER['HTTP_HOST'] . $this->view->baseUrl;
     $bodyHtml = $emailTemplate->render('newComment.phtml');
     $bodyText = $emailTemplate->render('newComment.ptxt');
     $mail = new Zend_Mail();
     $mail->setType(Zend_Mime::MULTIPART_ALTERNATIVE)->setBodyHtml($bodyHtml, 'UTF-8')->setBodyText($bodyText, 'UTF-8')->setSubject("New comment on '{$page->getTitle()}' in '{$page->getBook()->getTitle()}'")->setFrom($config->fromAddress, $config->fromName);
     if (is_object($config->notifyComments)) {
         foreach ($config->notifyComments->toArray() as $rcpt) {
             $mail->addTo($rcpt);
         }
     } else {
         $mail->addTo($config->notifyComments);
     }
     if ($config->smtpServer) {
         $transport = new Zend_Mail_Transport_Smtp($config->smtpServer, $config->smtpOptions->toArray());
     } else {
         $transport = new Zend_Mail_Transport_Sendmail();
     }
     $mail->send($transport);
 }
Exemplo n.º 2
0
 public function userComments(HumanHelp_Model_Page $page)
 {
     $comments = $page->getComments();
     if (empty($comments)) {
         return 'There are currently no user contributed comments for this page';
     } else {
         $html = '';
         foreach ($comments as $comment) {
             $html .= $this->_buildCommentHtml($comment);
         }
         return $html;
     }
 }
Exemplo n.º 3
0
 /**
  * Get a specific page for this book
  * 
  * @param string $pageName
  * @return HumanHelp_Model_Page
  */
 public function getPage($pageName)
 {
     $page = new HumanHelp_Model_Page($pageName);
     $page->setBook($this);
     // Load page content
     $contentFile = $this->_bookDataPath . 'content' . DIRECTORY_SEPARATOR . $pageName;
     if (!is_readable($contentFile)) {
         throw new ErrorException("Page {$pageName} does not exist {$contentFile}");
     }
     $contentXml = new DOMDocument();
     if (!$contentXml->load($contentFile)) {
         throw new ErrorException("Unable to load content file {$contentFile}");
     }
     $contentBody = $contentXml->getElementsByTagName('body');
     if ($contentBody->length != 1) {
         throw new ErrorException("Expecting exactly 1 body element, found {$contentBody->length}");
     }
     $contentBody = $contentBody->item(0);
     // Process document through XHTML filters
     foreach ($this->_getXhtmlFilters() as $filter) {
         /* @var $filter HHLib_XhtmlFilter_Abstract */
         $filter->setDomDocument($contentXml);
         $filter->filter($contentBody);
     }
     $content = '';
     foreach ($contentBody->childNodes as $bodyChild) {
         /* @var $bodyChild DOMNode */
         $content .= $contentXml->saveXML($bodyChild);
     }
     $page->setContent($content);
     // Set page title
     $contentXml = simplexml_import_dom($contentXml);
     $title = (string) $contentXml->head->title;
     $page->setTitle($title);
     return $page;
 }