Ejemplo n.º 1
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;
 }