PageRenderTime 25ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/ojs/ojs-2.2/plugins/gateways/resolver/ResolverPlugin.inc.php

https://github.com/mcrider/pkpUpgradeTestSuite
PHP | 190 lines | 133 code | 21 blank | 36 comment | 37 complexity | f4449e2d9b5e215d3a6a9d0f61691639 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1
  1. <?php
  2. /**
  3. * @file ResolverPlugin.inc.php
  4. *
  5. * Copyright (c) 2003-2007 John Willinsky
  6. * Distributed under the GNU GPL v2. For full terms see the file docs/COPYING.
  7. *
  8. * @package plugins.gateways.resolver
  9. * @class ResolverPlugin
  10. *
  11. * Simple resolver gateway plugin
  12. *
  13. * $Id: ResolverPlugin.inc.php,v 1.10 2007/09/21 16:38:35 asmecher Exp $
  14. */
  15. import('classes.plugins.GatewayPlugin');
  16. class ResolverPlugin extends GatewayPlugin {
  17. /**
  18. * Called as a plugin is registered to the registry
  19. * @param @category String Name of category plugin was registered to
  20. * @return boolean True iff plugin initialized successfully; if false,
  21. * the plugin will not be registered.
  22. */
  23. function register($category, $path) {
  24. $success = parent::register($category, $path);
  25. $this->addLocaleData();
  26. return $success;
  27. }
  28. /**
  29. * Get the name of the settings file to be installed on new journal
  30. * creation.
  31. * @return string
  32. */
  33. function getNewJournalPluginSettingsFile() {
  34. return $this->getPluginPath() . '/settings.xml';
  35. }
  36. /**
  37. * Get the name of this plugin. The name must be unique within
  38. * its category.
  39. * @return String name of plugin
  40. */
  41. function getName() {
  42. return 'ResolverPlugin';
  43. }
  44. function getDisplayName() {
  45. return Locale::translate('plugins.gateways.resolver.displayName');
  46. }
  47. function getDescription() {
  48. return Locale::translate('plugins.gateways.resolver.description');
  49. }
  50. /**
  51. * Handle fetch requests for this plugin.
  52. */
  53. function fetch($args) {
  54. if (!$this->getEnabled()) {
  55. return false;
  56. }
  57. $scheme = array_shift($args);
  58. switch ($scheme) {
  59. case 'vnp': // Volume, number, page
  60. case 'ynp': // Volume, number, year, page
  61. // This can only be used from within a journal context
  62. $journal =& Request::getJournal();
  63. if (!$journal) break;
  64. if ($scheme == 'vnp') {
  65. $volume = (int) array_shift($args);
  66. $year = null;
  67. } elseif ($scheme == 'ynp') {
  68. $year = (int) array_shift($args);
  69. $volume = null;
  70. }
  71. $number = array_shift($args);
  72. $page = (int) array_shift($args);
  73. $issueDao =& DAORegistry::getDAO('IssueDAO');
  74. $issues =& $issueDao->getPublishedIssuesByNumber($journal->getJournalId(), $volume, $number, $year);
  75. // Ensure only one issue matched, and fetch it.
  76. $issue =& $issues->next();
  77. if (!$issue || $issues->next()) break;
  78. unset($issues);
  79. $publishedArticleDao =& DAORegistry::getDAO('PublishedArticleDAO');
  80. $articles =& $publishedArticleDao->getPublishedArticles($issue->getIssueId());
  81. foreach ($articles as $article) {
  82. // Look for the correct page in the list of articles.
  83. $matches = null;
  84. if (String::regexp_match_get('/^[Pp][Pp]?[.]?[ ]?(\d+)$/', $article->getPages(), $matches)) {
  85. $matchedPage = $matches[1];
  86. if ($page == $matchedPage) Request::redirect(null, 'article', 'view', $article->getBestArticleId());
  87. }
  88. if (String::regexp_match_get('/^[Pp][Pp]?[.]?[ ]?(\d+)[ ]?-[ ]?([Pp][Pp]?[.]?[ ]?)?(\d+)$/', $article->getPages(), $matches)) {
  89. $matchedPageFrom = $matches[1];
  90. $matchedPageTo = $matches[3];
  91. if ($page >= $matchedPageFrom && ($page < $matchedPageTo || ($page == $matchedPageTo && $matchedPageFrom = $matchedPageTo))) Request::redirect(null, 'article', 'view', $article->getBestArticleId());
  92. }
  93. unset($article);
  94. }
  95. }
  96. // Failure.
  97. header("HTTP/1.0 500 Internal Server Error");
  98. $templateMgr =& TemplateManager::getManager();
  99. $templateMgr->assign('message', 'plugins.gateways.resolver.errors.errorMessage');
  100. $templateMgr->display('common/message.tpl');
  101. exit;
  102. }
  103. function sanitize($string) {
  104. return str_replace("\t", " ", strip_tags($string));
  105. }
  106. function exportHoldings() {
  107. $journalDao =& DAORegistry::getDAO('JournalDAO');
  108. $issueDao =& DAORegistry::getDAO('IssueDAO');
  109. $journals =& $journalDao->getEnabledJournals();
  110. header('content-type: text/plain');
  111. header('content-disposition: attachment; filename=holdings.txt');
  112. echo "title\tissn\te_issn\tstart_date\tend_date\tembargo_months\tembargo_days\tjournal_url\tvol_start\tvol_end\tiss_start\tiss_end\n";
  113. while ($journal =& $journals->next()) {
  114. $issues =& $issueDao->getPublishedIssues($journal->getJournalId());
  115. $startDate = $endDate = null;
  116. $startNumber = $endNumber = null;
  117. $startVolume = $endVolume = null;
  118. while ($issue =& $issues->next()) {
  119. $datePublished = $issue->getDatePublished();
  120. if ($datePublished !== null) $datePublished = strtotime($datePublished);
  121. if ($startDate === null || $startDate > $datePublished) $startDate = $datePublished;
  122. if ($endDate === null || $endDate < $datePublished) $endDate = $datePublished;
  123. $volume = $issue->getVolume();
  124. if ($startVolume === null || $startVolume > $volume) $startVolume = $volume;
  125. if ($endVolume === null || $endVolume < $volume) $endVolume = $volume;
  126. $number = $issue->getNumber();
  127. if ($startNumber === null || $startNumber > $number) $startNumber = $number;
  128. if ($endNumber === null || $endNumber < $number) $endNumber = $number;
  129. unset($issue);
  130. }
  131. unset($issues);
  132. echo $this->sanitize($journal->getJournalTitle()) . "\t";
  133. echo $this->sanitize($journal->getSetting('printIssn')) . "\t";
  134. echo $this->sanitize($journal->getSetting('onlineIssn')) . "\t";
  135. echo $this->sanitize($startDate===null?'':strftime('%Y-%m-%d', $startDate)) . "\t"; // start_date
  136. echo $this->sanitize($endDate===null?'':strftime('%Y-%m-%d', $endDate)) . "\t"; // end_date
  137. echo $this->sanitize('') . "\t"; // embargo_months
  138. echo $this->sanitize('') . "\t"; // embargo_days
  139. echo Request::url($journal->getPath()) . "\t"; // journal_url
  140. echo $this->sanitize($startVolume) . "\t"; // vol_start
  141. echo $this->sanitize($endVolume) . "\t"; // vol_end
  142. echo $this->sanitize($startNumber) . "\t"; // iss_start
  143. echo $this->sanitize($endNumber) . "\n"; // iss_end
  144. unset($journal);
  145. }
  146. }
  147. function getManagementVerbs() {
  148. $verbs = parent::getManagementVerbs();
  149. if (Validation::isSiteAdmin() && $this->getEnabled()) {
  150. $verbs[] = array(
  151. 'exportHoldings',
  152. Locale::translate('plugins.gateways.resolver.exportHoldings')
  153. );
  154. }
  155. return $verbs;
  156. }
  157. function manage($verb, $args) {
  158. switch ($verb) {
  159. case 'exportHoldings':
  160. if (Validation::isSiteAdmin() && $this->getEnabled()) {
  161. $this->exportHoldings();
  162. return true;
  163. }
  164. break;
  165. }
  166. return parent::manage($verb, $args);
  167. }
  168. }
  169. ?>