/ojs/ojs-2.1.1/classes/article/ArticleHTMLGalley.inc.php

https://github.com/mcrider/pkpUpgradeTestSuite · PHP · 185 lines · 103 code · 21 blank · 61 comment · 10 complexity · aefe4a39fc2cde2bb738628f129ed597 MD5 · raw file

  1. <?php
  2. /**
  3. * ArticleHTMLGalley.inc.php
  4. *
  5. * Copyright (c) 2003-2006 John Willinsky
  6. * Distributed under the GNU GPL v2. For full terms see the file docs/COPYING.
  7. *
  8. * @package article
  9. *
  10. * ArticleHTMLGalley class.
  11. * An HTML galley may include an optional stylesheet and set of images.
  12. *
  13. * $Id: ArticleHTMLGalley.inc.php,v 1.12 2006/06/12 23:25:48 alec Exp $
  14. */
  15. import('article.ArticleGalley');
  16. class ArticleHTMLGalley extends ArticleGalley {
  17. /**
  18. * Constructor.
  19. */
  20. function ArticleHTMLGalley() {
  21. parent::ArticleGalley();
  22. }
  23. /**
  24. * Check if galley is an HTML galley.
  25. * @return boolean
  26. */
  27. function isHTMLGalley() {
  28. return true;
  29. }
  30. /**
  31. * Return string containing the contents of the HTML file.
  32. * This function performs any necessary filtering, like image URL replacement.
  33. * @param $baseImageUrl string base URL for image references
  34. * @return string
  35. */
  36. function getHTMLContents() {
  37. import('file.ArticleFileManager');
  38. $fileManager = &new ArticleFileManager($this->getArticleId());
  39. $contents = $fileManager->readFile($this->getFileId());
  40. // Replace image references
  41. $images = &$this->getImageFiles();
  42. foreach ($images as $image) {
  43. $imageUrl = Request::url(null, 'article', 'viewFile', array($this->getArticleId(), $this->getGalleyId(), $image->getFileId()));
  44. $contents = preg_replace(
  45. '/[Ss][Rr][Cc]\s*=\s*"([^"]*' . preg_quote($image->getOriginalFileName()) . ')"/',
  46. 'src="' . $imageUrl . '"',
  47. $contents,
  48. 1
  49. );
  50. }
  51. // Perform replacement for ojs://... URLs
  52. $contents = String::regexp_replace_callback(
  53. '/(<[^<>]*")[Oo][Jj][Ss]:\/\/([^"]+)("[^<>]*>)/',
  54. array(&$this, '_handleOjsUrl'),
  55. $contents
  56. );
  57. return $contents;
  58. }
  59. function _handleOjsUrl($matchArray) {
  60. $url = $matchArray[2];
  61. $urlParts = explode('/', $url);
  62. if (isset($urlParts[0])) switch(String::strtolower($urlParts[0])) {
  63. case 'journal':
  64. $url = Request::url(
  65. isset($urlParts[1]) ?
  66. $urlParts[1] :
  67. Request::getRequestedJournalPath()
  68. );
  69. break;
  70. case 'article':
  71. if (isset($urlParts[1])) {
  72. $url = Request::url(null, 'article', 'view', $urlParts[1]);
  73. }
  74. break;
  75. case 'issue':
  76. if (isset($urlParts[1])) {
  77. $url = Request::url(null, 'issue', 'view', $urlParts[1]);
  78. } else {
  79. $url = Request::url(null, 'issue', 'current');
  80. }
  81. break;
  82. case 'suppfile':
  83. if (isset($urlParts[1]) && isset($urlParts[2])) {
  84. $url = Request::url(null, 'article', 'downloadSuppFile', array($urlParts[1], $urlParts[2]));
  85. }
  86. break;
  87. case 'sitepublic':
  88. array_shift($urlParts);
  89. import ('file.PublicFileManager');
  90. $publicFileManager = &new PublicFileManager();
  91. $url = Request::getBaseUrl() . '/' . $publicFileManager->getSiteFilesPath() . '/' . implode('/', $urlParts);
  92. break;
  93. case 'public':
  94. array_shift($urlParts);
  95. $journal = &Request::getJournal();
  96. import ('file.PublicFileManager');
  97. $publicFileManager = &new PublicFileManager();
  98. $url = Request::getBaseUrl() . '/' . $publicFileManager->getJournalFilesPath($journal->getJournalId()) . '/' . implode('/', $urlParts);
  99. break;
  100. }
  101. return $matchArray[1] . $url . $matchArray[3];
  102. }
  103. /**
  104. * Check if the specified file is a dependent file.
  105. * @param $fileId int
  106. * @return boolean
  107. */
  108. function isDependentFile($fileId) {
  109. if ($this->getStyleFileId() == $fileId) return true;
  110. foreach ($this->getImageFiles() as $image) {
  111. if ($image->getFileId() == $fileId) return true;
  112. }
  113. return false;
  114. }
  115. //
  116. // Get/set methods
  117. //
  118. /**
  119. * Get ID of associated stylesheet file, if applicable.
  120. * @return int
  121. */
  122. function getStyleFileId() {
  123. return $this->getData('styleFileId');
  124. }
  125. /**
  126. * Set ID of associated stylesheet file.
  127. * @param $styleFileId int
  128. */
  129. function setStyleFileId($styleFileId) {
  130. return $this->setData('styleFileId', $styleFileId);
  131. }
  132. /**
  133. * Return the stylesheet file associated with this HTML galley, if applicable.
  134. * @return ArticleFile
  135. */
  136. function &getStyleFile() {
  137. $styleFile = &$this->getData('styleFile');
  138. return $styleFile;
  139. }
  140. /**
  141. * Set the stylesheet file for this HTML galley.
  142. * @param ArticleFile $styleFile
  143. */
  144. function setStyleFile(&$styleFile) {
  145. $this->setData('styleFile', $styleFile);
  146. }
  147. /**
  148. * Return array of image files for this HTML galley.
  149. * @return array
  150. */
  151. function &getImageFiles() {
  152. $images = &$this->getData('images');
  153. return $images;
  154. }
  155. /**
  156. * Set array of image files for this HTML galley.
  157. * @param $images array
  158. * @return array
  159. */
  160. function setImageFiles(&$images) {
  161. return $this->setData('images', $images);
  162. }
  163. }
  164. ?>