PageRenderTime 41ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 0ms

/ojs/ojs-2.3.1-2/classes/article/ArticleHTMLGalley.inc.php

https://github.com/mcrider/pkpUpgradeTestSuite
PHP | 259 lines | 165 code | 31 blank | 63 comment | 11 complexity | a78b5739b761f6c5ec5da61f0c1423f1 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1
  1. <?php
  2. /**
  3. * @file classes/article/ArticleHTMLGalley.inc.php
  4. *
  5. * Copyright (c) 2003-2009 John Willinsky
  6. * Distributed under the GNU GPL v2. For full terms see the file docs/COPYING.
  7. *
  8. * @class ArticleHTMLGalley
  9. * @ingroup article
  10. *
  11. * @brief An HTML galley may include an optional stylesheet and set of images.
  12. */
  13. // $Id: ArticleHTMLGalley.inc.php,v 1.33 2009/05/12 16:57:20 asmecher Exp $
  14. import('article.ArticleGalley');
  15. class ArticleHTMLGalley extends ArticleGalley {
  16. /**
  17. * Constructor.
  18. */
  19. function ArticleHTMLGalley() {
  20. parent::ArticleGalley();
  21. }
  22. /**
  23. * Check if galley is an HTML galley.
  24. * @return boolean
  25. */
  26. function isHTMLGalley() {
  27. return true;
  28. }
  29. /**
  30. * Return string containing the contents of the HTML file.
  31. * This function performs any necessary filtering, like image URL replacement.
  32. * @param $baseImageUrl string base URL for image references
  33. * @return string
  34. */
  35. function getHTMLContents() {
  36. import('file.ArticleFileManager');
  37. $fileManager = new ArticleFileManager($this->getArticleId());
  38. $contents = $fileManager->readFile($this->getFileId());
  39. $journal =& Request::getJournal();
  40. // Replace media file references
  41. $images =& $this->getImageFiles();
  42. foreach ($images as $image) {
  43. $imageUrl = Request::url(null, 'article', 'viewFile', array($this->getArticleId(), $this->getBestGalleyId($journal), $image->getFileId()));
  44. $pattern = preg_quote(rawurlencode($image->getOriginalFileName()));
  45. $contents = preg_replace(
  46. '/([Ss][Rr][Cc]|[Hh][Rr][Ee][Ff]|[Dd][Aa][Tt][Aa])\s*=\s*"([^"]*' . $pattern . ')"/',
  47. '\1="' . $imageUrl . '"',
  48. $contents
  49. );
  50. // Replacement for Flowplayer
  51. $contents = preg_replace(
  52. '/[Uu][Rr][Ll]\s*\:\s*\'(' . $pattern . ')\'/',
  53. 'url:\'' . $imageUrl . '\'',
  54. $contents
  55. );
  56. // Replacement for other players (ested with odeo; yahoo and google player won't work w/ OJS URLs, might work for others)
  57. $contents = preg_replace(
  58. '/[Uu][Rr][Ll]=([^"]*' . $pattern . ')/',
  59. 'url=' . $imageUrl ,
  60. $contents
  61. );
  62. }
  63. // Perform replacement for ojs://... URLs
  64. $contents = String::regexp_replace_callback(
  65. '/(<[^<>]*")[Oo][Jj][Ss]:\/\/([^"]+)("[^<>]*>)/',
  66. array(&$this, '_handleOjsUrl'),
  67. $contents
  68. );
  69. // Perform variable replacement for journal, issue, site info
  70. $issueDao =& DAORegistry::getDAO('IssueDAO');
  71. $issue =& $issueDao->getIssueByArticleId($this->getArticleId());
  72. $journal =& Request::getJournal();
  73. $site =& Request::getSite();
  74. $paramArray = array(
  75. 'issueTitle' => $issue?$issue->getIssueIdentification():Locale::translate('editor.article.scheduleForPublication.toBeAssigned'),
  76. 'journalTitle' => $journal->getLocalizedTitle(),
  77. 'siteTitle' => $site->getLocalizedTitle(),
  78. 'currentUrl' => Request::getRequestUrl()
  79. );
  80. foreach ($paramArray as $key => $value) {
  81. $contents = str_replace('{$' . $key . '}', $value, $contents);
  82. }
  83. return $contents;
  84. }
  85. function _handleOjsUrl($matchArray) {
  86. $url = $matchArray[2];
  87. $anchor = null;
  88. if (($i = strpos($url, '#')) !== false) {
  89. $anchor = substr($url, $i+1);
  90. $url = substr($url, 0, $i);
  91. }
  92. $urlParts = explode('/', $url);
  93. if (isset($urlParts[0])) switch(String::strtolower($urlParts[0])) {
  94. case 'journal':
  95. $url = Request::url(
  96. isset($urlParts[1]) ?
  97. $urlParts[1] :
  98. Request::getRequestedJournalPath(),
  99. null,
  100. null,
  101. null,
  102. null,
  103. $anchor
  104. );
  105. break;
  106. case 'article':
  107. if (isset($urlParts[1])) {
  108. $url = Request::url(
  109. null,
  110. 'article',
  111. 'view',
  112. $urlParts[1],
  113. null,
  114. $anchor
  115. );
  116. }
  117. break;
  118. case 'issue':
  119. if (isset($urlParts[1])) {
  120. $url = Request::url(
  121. null,
  122. 'issue',
  123. 'view',
  124. $urlParts[1],
  125. null,
  126. $anchor
  127. );
  128. } else {
  129. $url = Request::url(
  130. null,
  131. 'issue',
  132. 'current',
  133. null,
  134. null,
  135. $anchor
  136. );
  137. }
  138. break;
  139. case 'suppfile':
  140. if (isset($urlParts[1]) && isset($urlParts[2])) {
  141. $url = Request::url(
  142. null,
  143. 'article',
  144. 'downloadSuppFile',
  145. array($urlParts[1], $urlParts[2]),
  146. null,
  147. $anchor
  148. );
  149. }
  150. break;
  151. case 'sitepublic':
  152. array_shift($urlParts);
  153. import ('file.PublicFileManager');
  154. $publicFileManager = new PublicFileManager();
  155. $url = Request::getBaseUrl() . '/' . $publicFileManager->getSiteFilesPath() . '/' . implode('/', $urlParts) . ($anchor?'#' . $anchor:'');
  156. break;
  157. case 'public':
  158. array_shift($urlParts);
  159. $journal =& Request::getJournal();
  160. import ('file.PublicFileManager');
  161. $publicFileManager = new PublicFileManager();
  162. $url = Request::getBaseUrl() . '/' . $publicFileManager->getJournalFilesPath($journal->getJournalId()) . '/' . implode('/', $urlParts) . ($anchor?'#' . $anchor:'');
  163. break;
  164. }
  165. return $matchArray[1] . $url . $matchArray[3];
  166. }
  167. /**
  168. * Check if the specified file is a dependent file.
  169. * @param $fileId int
  170. * @return boolean
  171. */
  172. function isDependentFile($fileId) {
  173. if ($this->getStyleFileId() == $fileId) return true;
  174. foreach ($this->getImageFiles() as $image) {
  175. if ($image->getFileId() == $fileId) return true;
  176. }
  177. return false;
  178. }
  179. //
  180. // Get/set methods
  181. //
  182. /**
  183. * Get ID of associated stylesheet file, if applicable.
  184. * @return int
  185. */
  186. function getStyleFileId() {
  187. return $this->getData('styleFileId');
  188. }
  189. /**
  190. * Set ID of associated stylesheet file.
  191. * @param $styleFileId int
  192. */
  193. function setStyleFileId($styleFileId) {
  194. return $this->setData('styleFileId', $styleFileId);
  195. }
  196. /**
  197. * Return the stylesheet file associated with this HTML galley, if applicable.
  198. * @return ArticleFile
  199. */
  200. function &getStyleFile() {
  201. $styleFile =& $this->getData('styleFile');
  202. return $styleFile;
  203. }
  204. /**
  205. * Set the stylesheet file for this HTML galley.
  206. * @param ArticleFile $styleFile
  207. */
  208. function setStyleFile(&$styleFile) {
  209. $this->setData('styleFile', $styleFile);
  210. }
  211. /**
  212. * Return array of image files for this HTML galley.
  213. * @return array
  214. */
  215. function &getImageFiles() {
  216. $images =& $this->getData('images');
  217. return $images;
  218. }
  219. /**
  220. * Set array of image files for this HTML galley.
  221. * @param $images array
  222. * @return array
  223. */
  224. function setImageFiles(&$images) {
  225. return $this->setData('images', $images);
  226. }
  227. }
  228. ?>