PageRenderTime 39ms CodeModel.GetById 10ms RepoModel.GetById 0ms app.codeStats 1ms

/ojs/ojs-2.3.2-1/plugins/oaiMetadataFormats/nlm/OAIMetadataFormat_NLM.inc.php

https://github.com/mcrider/pkpUpgradeTestSuite
PHP | 253 lines | 183 code | 32 blank | 38 comment | 33 complexity | 830b0462c072dbd4b071d8864a9fe84a MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1
  1. <?php
  2. /**
  3. * @defgroup oai_format_nlm
  4. */
  5. /**
  6. * @file classes/oai/format/OAIMetadataFormat_NLM.inc.php
  7. *
  8. * Copyright (c) 2003-2009 John Willinsky
  9. * Distributed under the GNU GPL v2. For full terms see the file docs/COPYING.
  10. *
  11. * @class OAIMetadataFormat_NLM
  12. * @ingroup oai_format
  13. * @see OAI
  14. *
  15. * @brief OAI metadata format class -- NLM 2.3
  16. */
  17. // $Id: OAIMetadataFormat_NLM.inc.php,v 1.1 2009/11/19 14:51:38 asmecher Exp $
  18. class OAIMetadataFormat_NLM extends OAIMetadataFormat {
  19. /**
  20. * @see OAIMetadataFormat#toXml
  21. * TODO:
  22. * <copyright-holder>
  23. * In Isabelle's mapping document:
  24. * Article order in the issue's Table of Contents
  25. */
  26. function toXml(&$record, $format = null) {
  27. $article =& $record->getData('article');
  28. $journal =& $record->getData('journal');
  29. $section =& $record->getData('section');
  30. $issue =& $record->getData('issue');
  31. $galleys =& $record->getData('galleys');
  32. $articleId = $article->getArticleId();
  33. // Cache issue ordering information.
  34. static $issueId;
  35. static $sectionSeq;
  36. if (!isset($issueId) || $issueId != $issue->getIssueId()) {
  37. $sectionDao =& DAORegistry::getDAO('SectionDAO');
  38. $issueId = $issue->getIssueId();
  39. $sections =& $sectionDao->getSectionsForIssue($issueId);
  40. $sectionSeq = array();
  41. $i=0;
  42. foreach ($sections as $thisSection) {
  43. $sectionSeq[$thisSection->getSectionId()] = $i++;
  44. }
  45. unset($sections);
  46. }
  47. $abbreviation = $journal->getLocalizedSetting('abbreviation');
  48. $printIssn = $journal->getSetting('printIssn');
  49. $onlineIssn = $journal->getSetting('onlineIssn');
  50. $primaryLocale = $journal->getPrimaryLocale();
  51. $publisherInstitution = $journal->getSetting('publisherInstitution');
  52. $datePublished = strtotime($article->getDatePublished());
  53. $response = "<article\n" .
  54. "\txmlns=\"http://dtd.nlm.nih.gov/publishing/2.3\"\n" .
  55. "\txmlns:xlink=\"http://www.w3.org/1999/xlink\"\n" .
  56. "\txmlns:mml=\"http://www.w3.org/1998/Math/MathML\"\n" .
  57. "\txmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n" .
  58. "\txsi:schemaLocation=\"http://dtd.nlm.nih.gov/publishing/2.3\n" .
  59. "\thttp://dtd.nlm.nih.gov/publishing/2.3/xsd/journalpublishing.xsd\"\n" .
  60. (($s = $section->getSectionIdentifyType())!=''?"\tarticle-type=\"" . htmlspecialchars(Core::cleanVar($s)) . "\"":'') .
  61. "\txml:lang=\"" . strtoupper(substr($primaryLocale, 0, 2)) . "\">\n" .
  62. "\t<front>\n" .
  63. "\t\t<journal-meta>\n" .
  64. "\t\t\t<journal-id journal-id-type=\"other\">" . htmlspecialchars(Core::cleanVar(($s = Config::getVar('oai', 'nlm_journal_id'))!=''?$s:$journal->getPath())) . "</journal-id>\n" .
  65. "\t\t\t<journal-title>" . htmlspecialchars(Core::cleanVar($journal->getJournalTitle())) . "</journal-title>\n";
  66. // Include translated journal titles
  67. foreach ($journal->getTitle(null) as $locale => $title) {
  68. if ($locale == $primaryLocale) continue;
  69. $response .= "\t\t\t<trans-title xml:lang=\"" . strtoupper(substr($locale, 0, 2)) . "\">" . htmlspecialchars(Core::cleanVar($title)) . "</trans-title>\n";
  70. }
  71. $response .=
  72. (!empty($onlineIssn)?"\t\t\t<issn pub-type=\"epub\">" . htmlspecialchars(Core::cleanVar($onlineIssn)) . "</issn>":'') .
  73. (!empty($printIssn)?"\t\t\t<issn pub-type=\"ppub\">" . htmlspecialchars(Core::cleanVar($printIssn)) . "</issn>":'') .
  74. ($publisherInstitution != ''?"\t\t\t<publisher><publisher-name>" . htmlspecialchars(Core::cleanVar($publisherInstitution)) . "</publisher-name></publisher>\n":'') .
  75. "\t\t</journal-meta>\n" .
  76. "\t\t<article-meta>\n" .
  77. "\t\t\t<article-id pub-id-type=\"other\">" . htmlspecialchars(Core::cleanVar($article->getBestArticleId())) . "</article-id>\n" .
  78. (($s = $article->getDOI()) != ''?"\t\t\t<article-id pub-id-type=\"doi\">" . htmlspecialchars(Core::cleanVar($s)) . "</article-id>\n":'') .
  79. "\t\t\t<article-categories><subj-group subj-group-type=\"heading\"><subject>" . htmlspecialchars(Core::cleanVar($section->getSectionTitle())) . "</subject></subj-group></article-categories>\n" .
  80. "\t\t\t<title-group>\n" .
  81. "\t\t\t\t<article-title>" . htmlspecialchars(Core::cleanVar(strip_tags($article->getArticleTitle()))) . "</article-title>\n";
  82. // Include translated journal titles
  83. foreach ($article->getTitle(null) as $locale => $title) {
  84. if ($locale == $primaryLocale) continue;
  85. $response .= "\t\t\t\t<trans-title xml:lang=\"" . strtoupper(substr($locale, 0, 2)) . "\">" . htmlspecialchars(Core::cleanVar(strip_tags($title))) . "</trans-title>\n";
  86. }
  87. $response .=
  88. "\t\t\t</title-group>\n" .
  89. "\t\t\t<contrib-group>\n";
  90. // Include authors
  91. foreach ($article->getAuthors() as $author) {
  92. $response .=
  93. "\t\t\t\t<contrib " . ($author->getPrimaryContact()?'corresp="yes" ':'') . "contrib-type=\"author\">\n" .
  94. "\t\t\t\t\t<name name-style=\"western\">\n" .
  95. "\t\t\t\t\t\t<surname>" . htmlspecialchars(Core::cleanVar($author->getLastName())) . "</surname>\n" .
  96. "\t\t\t\t\t\t<given-names>" . htmlspecialchars(Core::cleanVar($author->getFirstName()) . (($s = $author->getMiddleName()) != ''?" $s":'')) . "</given-names>\n" .
  97. "\t\t\t\t\t</name>\n" .
  98. (($s = $author->getAffiliation()) != ''?"\t\t\t\t\t<aff>" . htmlspecialchars(Core::cleanVar($s)) . "</aff>\n":'') .
  99. "\t\t\t\t\t<email>" . htmlspecialchars(Core::cleanVar($author->getEmail())) . "</email>\n" .
  100. (($s = $author->getUrl()) != ''?"\t\t\t\t\t<uri>" . htmlspecialchars(Core::cleanVar($s)) . "</uri>\n":'') .
  101. "\t\t\t\t</contrib>\n";
  102. }
  103. // Include editorships (optimized)
  104. $response .= $this->getEditorialInfo($journal->getJournalId());
  105. $response .=
  106. "\t\t\t</contrib-group>\n" .
  107. "\t\t\t<pub-date pub-type=\"epub\">\n" .
  108. "\t\t\t\t<day>" . strftime('%d', $datePublished) . "</day>\n" .
  109. "\t\t\t\t<month>" . strftime('%m', $datePublished) . "</month>\n" .
  110. "\t\t\t\t<year>" . strftime('%Y', $datePublished) . "</year>\n" .
  111. "\t\t\t</pub-date>\n" .
  112. ($issue->getShowYear()?"\t\t\t<pub-date pub-type=\"collection\"><year>" . htmlspecialchars(Core::cleanVar($issue->getYear())) . "</year></pub-date>\n":'') .
  113. ($issue->getShowVolume()?"\t\t\t<volume>" . htmlspecialchars(Core::cleanVar($issue->getVolume())) . "</volume>\n":'') .
  114. ($issue->getShowNumber()?"\t\t\t<issue seq=\"" . htmlspecialchars(Core::cleanVar(($sectionSeq[$section->getSectionId()]*100) + $article->getSeq())) . "\">" . htmlspecialchars(Core::cleanVar($issue->getNumber())) . "</issue>\n":'') .
  115. "\t\t\t<issue-id pub-id-type=\"other\">" . htmlspecialchars(Core::cleanVar($issue->getBestIssueId())) . "</issue-id>\n" .
  116. ($issue->getShowTitle()?"\t\t\t<issue-title>" . htmlspecialchars(Core::cleanVar($issue->getIssueTitle())) . "</issue-title>\n":'');
  117. // Include page info, if available and parseable.
  118. $matches = null;
  119. if (String::regexp_match_get('/^[Pp][Pp]?[.]?[ ]?(\d+)$/', $article->getPages(), $matches)) {
  120. $matchedPage = htmlspecialchars(Core::cleanVar($matches[1]));
  121. $response .= "\t\t\t\t<fpage>$matchedPage</fpage><lpage>$matchedPage</lpage>\n";
  122. $pageCount = 1;
  123. } elseif (String::regexp_match_get('/^[Pp][Pp]?[.]?[ ]?(\d+)[ ]?-[ ]?([Pp][Pp]?[.]?[ ]?)?(\d+)$/', $article->getPages(), $matches)) {
  124. $matchedPageFrom = htmlspecialchars(Core::cleanVar($matches[1]));
  125. $matchedPageTo = htmlspecialchars(Core::cleanVar($matches[3]));
  126. $response .=
  127. "\t\t\t\t<fpage>$matchedPageFrom</fpage>\n" .
  128. "\t\t\t\t<lpage>$matchedPageTo</lpage>\n";
  129. $pageCount = $matchedPageTo - $matchedPageFrom + 1;
  130. }
  131. $response .=
  132. "\t\t\t<permissions>\n" .
  133. ((($s = $journal->getLocalizedSetting('copyrightNotice')) != '')?"\t\t\t\t<copyright-statement>" . htmlspecialchars(Core::cleanVar($s)) . "</copyright-statement>\n":'') .
  134. "\t\t\t\t<copyright-year>" . strftime('%Y', $datePublished) . "</copyright-year>\n" .
  135. "\t\t\t</permissions>\n" .
  136. "\t\t\t<self-uri xlink:href=\"" . htmlspecialchars(Core::cleanVar(Request::url($journal->getPath(), 'article', 'view', $article->getBestArticleId()))) . "\" />\n";
  137. // Include galley links
  138. foreach ($article->getGalleys() as $galley) {
  139. $response .= "\t\t\t<self-uri content-type=\"" . htmlspecialchars(Core::cleanVar($galley->getFileType())) . "\" xlink:href=\"" . htmlspecialchars(Core::cleanVar(Request::url($journal->getPath(), 'article', 'view', array($article->getBestArticleId(), $galley->getGalleyId())))) . "\" />\n";
  140. }
  141. // Include abstract(s)
  142. $abstract = htmlspecialchars(Core::cleanVar(strip_tags($article->getArticleAbstract())));
  143. if (!empty($abstract)) {
  144. $abstract = "<p>$abstract</p>";
  145. // $abstract = '<p>' . String::regexp_replace('/\n+/', '</p><p>', $abstract) . '</p>';
  146. $response .= "\t\t\t<abstract xml:lang=\"" . strtoupper(substr($primaryLocale, 0, 2)) . "\">$abstract</abstract>\n";
  147. }
  148. if (is_array($article->getAbstract(null))) foreach ($article->getAbstract(null) as $locale => $abstract) {
  149. if ($locale == $primaryLocale || empty($abstract)) continue;
  150. $abstract = htmlspecialchars(Core::cleanVar(strip_tags($abstract)));
  151. if (empty($abstract)) continue;
  152. $abstract = "<p>$abstract</p>";
  153. //$abstract = '<p>' . String::regexp_replace('/\n+/', '</p><p>', $abstract) . '</p>';
  154. $response .= "\t\t\t<abstract-trans xml:lang=\"" . strtoupper(substr($locale, 0, 2)) . "\">$abstract</abstract-trans>\n";
  155. }
  156. $subjects = array();
  157. if (is_array($article->getSubject(null))) foreach ($article->getSubject(null) as $locale => $subject) {
  158. $s = array_map('trim', explode(';', Core::cleanVar($subject)));
  159. if (!empty($s)) $subjects[$locale] = $s;
  160. }
  161. if (!empty($subjects)) foreach ($subjects as $locale => $s) {
  162. $response .= "\t\t\t<kwd-group xml:lang=\"" . strtoupper(substr($locale, 0, 2)) . "\">\n";
  163. foreach ($s as $subject) $response .= "\t\t\t\t<kwd>" . htmlspecialchars($subject) . "</kwd>\n";
  164. $response .= "\t\t\t</kwd-group>\n";
  165. }
  166. $response .=
  167. (isset($pageCount)?"\t\t\t<counts><page-count count=\"" . (int) $pageCount. "\" /></counts>\n":'') .
  168. "\t\t</article-meta>\n" .
  169. "\t</front>\n";
  170. // Include body text (for search indexing only)
  171. import('search.ArticleSearchIndex');
  172. $text = '';
  173. $galleys = $article->getGalleys();
  174. // Give precedence to HTML galleys, as they're quickest to parse
  175. usort($galleys, create_function('$a, $b', 'return $a->isHtmlGalley()?-1:1;'));
  176. // Determine any access limitations. If there are, do not
  177. // provide the full-text.
  178. import('issue.IssueAction');
  179. $subscriptionRequired = IssueAction::subscriptionRequired($issue);
  180. $isSubscribedDomain = IssueAction::subscribedDomain($journal, $issue->getIssueId(), $article->getArticleId());
  181. if (!$subscriptionRequired || $isSubscribedDomain) foreach ($galleys as $galley) {
  182. $parser =& SearchFileParser::fromFile($galley);
  183. if ($parser && $parser->open()) {
  184. while(($s = $parser->read()) !== false) $text .= $s;
  185. $parser->close();
  186. }
  187. if ($galley->isHtmlGalley()) $text = strip_tags($text);
  188. unset($galley);
  189. // Use the first parseable galley.
  190. if (!empty($text)) break;
  191. }
  192. if (!empty($text)) $response .= "\t<body><p>" . htmlspecialchars(Core::cleanVar(Core::cleanVar($text))) . "</p></body>\n";
  193. $response .=
  194. "</article>";
  195. return $response;
  196. }
  197. function getEditorialInfo($journalId) {
  198. static $editorialInfo = array();
  199. if (isset($editorialInfo[$journalId])) return $editorialInfo[$journalId];
  200. $response = '';
  201. $roleDao =& DAORegistry::getDAO('RoleDAO');
  202. $roleMap = array(ROLE_ID_EDITOR => 'editor', ROLE_ID_SECTION_EDITOR> 'secteditor', ROLE_ID_JOURNAL_MANAGER => 'jmanager');
  203. foreach ($roleMap as $roleId => $roleName) {
  204. $users =& $roleDao->getUsersByRoleId($roleId, $journalId);
  205. $isFirst = true;
  206. while ($user =& $users->next()) {
  207. $response .= "\t\t\t\t<contrib contrib-type=\"$roleName\">\n" .
  208. "\t\t\t\t\t<name>\n" .
  209. "\t\t\t\t\t\t<surname>" . htmlspecialchars(Core::cleanVar($user->getLastName())) . "</surname>\n" .
  210. "\t\t\t\t\t\t<given-names>" . htmlspecialchars(Core::cleanVar($user->getFirstName() . ($user->getMiddleName() != ''?' ' . $user->getMiddleName():''))) . "</given-names>\n" .
  211. "\t\t\t\t\t</name>\n" .
  212. "\t\t\t\t</contrib>\n";
  213. unset($user);
  214. }
  215. unset($users);
  216. }
  217. $editorialInfo[$journalId] =& $response;
  218. return $response;
  219. }
  220. }
  221. ?>