Esempio n. 1
0
 /**
  * Return string containing an XHTML fragment generated from the XML/XSL source
  * This function performs any necessary filtering, like image URL replacement.
  * @param $baseImageUrl string base URL for image references
  * @return string
  */
 function getHTMLContents()
 {
     $xmlGalleyPlugin =& PluginRegistry::getPlugin('generic', $this->parentPluginName);
     // if the XML Galley plugin is not installed or enabled,
     // then pass through to ArticleHTMLGalley
     if (!$xmlGalleyPlugin) {
         return parent::getHTMLContents();
     }
     if (!$xmlGalleyPlugin->getEnabled()) {
         return parent::getHTMLContents();
     }
     $cache =& $this->_getXSLTCache($this->getFileName() . '-' . $this->getId());
     $contents = $cache->getContents();
     // if contents is false/empty, then we have an XSLT error
     // return the straight XML contents instead
     if ($contents == "") {
         return parent::getHTMLContents();
     }
     // Replace image references
     $images =& $this->getImageFiles();
     $journal =& Request::getJournal();
     if ($images !== null) {
         foreach ($images as $image) {
             $imageUrl = Request::url(null, 'article', 'viewFile', array($this->getArticleId(), $this->getBestGalleyId($journal), $image->getFileId()));
             $contents = preg_replace('/(src|href)\\s*=\\s*"([^"]*' . preg_quote($image->getOriginalFileName()) . ')"/i', '$1="' . $imageUrl . '"', $contents);
         }
     }
     // Perform replacement for ojs://... URLs
     $contents = String::regexp_replace_callback('/(<[^<>]*")[Oo][Jj][Ss]:\\/\\/([^"]+)("[^<>]*>)/', array(&$this, '_handleOjsUrl'), $contents);
     // Replace supplementary file references
     $this->suppFileDao =& DAORegistry::getDAO('SuppFileDAO');
     $suppFiles = $this->suppFileDao->getSuppFilesByArticle($this->getArticleId());
     if ($suppFiles) {
         foreach ($suppFiles as $supp) {
             $journal =& Request::getJournal();
             $suppUrl = Request::url(null, 'article', 'downloadSuppFile', array($this->getArticleId(), $supp->getBestSuppFileId($journal)));
             $contents = preg_replace('/href="' . preg_quote($supp->getOriginalFileName()) . '"/', 'href="' . $suppUrl . '"', $contents);
         }
     }
     // if client encoding is set to iso-8859-1, transcode string to HTML entities
     // since we transform all XML in utf8 and can't rely on built-in PHP functions
     if (LOCALE_ENCODING == "iso-8859-1") {
         $contents =& String::utf2html($contents);
     }
     return $contents;
 }