Open Journal Systems  3.3.0
ResolverPlugin.inc.php
1 <?php
2 
16 import('lib.pkp.classes.plugins.GatewayPlugin');
17 
22  function register($category, $path, $mainContextId = null) {
23  $success = parent::register($category, $path, $mainContextId);
24  $this->addLocaleData();
25  return $success;
26  }
27 
34  return $this->getPluginPath() . '/settings.xml';
35  }
36 
42  function getName() {
43  return 'ResolverPlugin';
44  }
45 
46  function getDisplayName() {
47  return __('plugins.gateways.resolver.displayName');
48  }
49 
50  function getDescription() {
51  return __('plugins.gateways.resolver.description');
52  }
53 
57  function fetch($args, $request) {
58  if (!$this->getEnabled()) {
59  return false;
60  }
61 
62  $scheme = array_shift($args);
63  switch ($scheme) {
64  case 'doi':
65  $doi = implode('/', $args);
66  $submissionDao = DAORegistry::getDAO('SubmissionDAO'); /* @var $submissionDao SubmissionDAO */
67  $article = $submissionDao->getByPubId('doi', $doi, $request->getJournal());
68  if($article) {
69  $request->redirect(null, 'article', 'view', $article->getBestId());
70  }
71  break;
72  case 'vnp': // Volume, number, page
73  case 'ynp': // Volume, number, year, page
74  // This can only be used from within a journal context
75  $journal = $request->getJournal();
76  if (!$journal) break;
77 
78  if ($scheme == 'vnp') {
79  $volume = (int) array_shift($args);
80  $year = null;
81  } elseif ($scheme == 'ynp') {
82  $year = (int) array_shift($args);
83  $volume = null;
84  } else {
85  return; // Suppress scrutinizer warn
86  }
87  $number = array_shift($args);
88  $page = (int) array_shift($args);
89 
90  $issueDao = DAORegistry::getDAO('IssueDAO'); /* @var $issueDao IssueDAO */
91  $issues = $issueDao->getPublishedIssuesByNumber($journal->getId(), $volume, $number, $year);
92 
93  // Ensure only one issue matched, and fetch it.
94  $issue = $issues->next();
95  if (!$issue || $issues->next()) break;
96  unset($issues);
97 
98  $submissionsIterator = Services::get('submission')->getMany([
99  'issueIds' => $issue->getId(),
100  ]);
101  foreach ($submissionsIterator as $submission) {
102  // Look for the correct page in the list of articles.
103  $matches = null;
104  if (PKPString::regexp_match_get('/^[Pp][Pp]?[.]?[ ]?(\d+)$/', $submission->getPages(), $matches)) {
105  $matchedPage = $matches[1];
106  if ($page == $matchedPage) $request->redirect(null, 'article', 'view', $submission->getBestId());
107  }
108  if (PKPString::regexp_match_get('/^[Pp][Pp]?[.]?[ ]?(\d+)[ ]?-[ ]?([Pp][Pp]?[.]?[ ]?)?(\d+)$/', $submission->getPages(), $matches)) {
109  $matchedPageFrom = $matches[1];
110  $matchedPageTo = $matches[3];
111  if ($page >= $matchedPageFrom && ($page < $matchedPageTo || ($page == $matchedPageTo && $matchedPageFrom = $matchedPageTo))) $request->redirect(null, 'article', 'view', $submission->getBestId());
112  }
113  unset($submission);
114  }
115  break;
116  }
117 
118  // Failure.
119  header('HTTP/1.0 404 Not Found');
120  $templateMgr = TemplateManager::getManager($request);
121  AppLocale::requireComponents(LOCALE_COMPONENT_APP_COMMON);
122  $templateMgr->assign('message', 'plugins.gateways.resolver.errors.errorMessage');
123  $templateMgr->display('frontend/pages/message.tpl');
124  exit;
125  }
126 
127  function sanitize($string) {
128  return str_replace("\t", " ", strip_tags($string));
129  }
130 
131  function exportHoldings() {
132  $journalDao = DAORegistry::getDAO('JournalDAO'); /* @var $journalDao JournalDAO */
133  $issueDao = DAORegistry::getDAO('IssueDAO'); /* @var $issueDao IssueDAO */
134  $journals = $journalDao->getAll(true);
135  $request = Application::get()->getRequest();
136  header('content-type: text/plain');
137  header('content-disposition: attachment; filename=holdings.txt');
138  echo "title\tissn\te_issn\tstart_date\tend_date\tembargo_months\tembargo_days\tjournal_url\tvol_start\tvol_end\tiss_start\tiss_end\n";
139  while ($journal = $journals->next()) {
140  $issues = $issueDao->getPublishedIssues($journal->getId());
141  $startDate = $endDate = null;
142  $startNumber = $endNumber = null;
143  $startVolume = $endVolume = null;
144  while ($issue = $issues->next()) {
145  $datePublished = $issue->getDatePublished();
146  if ($datePublished !== null) $datePublished = strtotime($datePublished);
147  if ($startDate === null || $startDate > $datePublished) $startDate = $datePublished;
148  if ($endDate === null || $endDate < $datePublished) $endDate = $datePublished;
149  $volume = $issue->getVolume();
150  if ($startVolume === null || $startVolume > $volume) $startVolume = $volume;
151  if ($endVolume === null || $endVolume < $volume) $endVolume = $volume;
152  $number = $issue->getNumber();
153  if ($startNumber === null || $startNumber > $number) $startNumber = $number;
154  if ($endNumber === null || $endNumber < $number) $endNumber = $number;
155  }
156 
157  echo $this->sanitize($journal->getLocalizedName()) . "\t";
158  echo $this->sanitize($journal->getData('printIssn')) . "\t";
159  echo $this->sanitize($journal->getData('onlineIssn')) . "\t";
160  echo $this->sanitize($startDate===null?'':strftime('%Y-%m-%d', $startDate)) . "\t"; // start_date
161  echo $this->sanitize($endDate===null?'':strftime('%Y-%m-%d', $endDate)) . "\t"; // end_date
162  echo $this->sanitize('') . "\t"; // embargo_months
163  echo $this->sanitize('') . "\t"; // embargo_days
164  echo $request->url($journal->getPath()) . "\t"; // journal_url
165  echo $this->sanitize($startVolume) . "\t"; // vol_start
166  echo $this->sanitize($endVolume) . "\t"; // vol_end
167  echo $this->sanitize($startNumber) . "\t"; // iss_start
168  echo $this->sanitize($endNumber) . "\n"; // iss_end
169 
170  }
171  }
172 }
173 
174 
AppLocale\requireComponents
static requireComponents()
Definition: env1/MockAppLocale.inc.php:56
PKPString\regexp_match_get
static regexp_match_get($pattern, $subject, &$matches)
Definition: PKPString.inc.php:256
DAORegistry\getDAO
static & getDAO($name, $dbconn=null)
Definition: DAORegistry.inc.php:57
ResolverPlugin
Simple resolver gateway plugin.
Definition: ResolverPlugin.inc.php:18
ResolverPlugin\exportHoldings
exportHoldings()
Definition: ResolverPlugin.inc.php:131
ResolverPlugin\getDescription
getDescription()
Definition: ResolverPlugin.inc.php:50
ResolverPlugin\getContextSpecificPluginSettingsFile
getContextSpecificPluginSettingsFile()
Definition: ResolverPlugin.inc.php:33
ResolverPlugin\getDisplayName
getDisplayName()
Definition: ResolverPlugin.inc.php:46
GatewayPlugin\getEnabled
getEnabled()
Definition: GatewayPlugin.inc.php:47
ResolverPlugin\getName
getName()
Definition: ResolverPlugin.inc.php:42
ResolverPlugin\sanitize
sanitize($string)
Definition: ResolverPlugin.inc.php:127
ResolverPlugin\fetch
fetch($args, $request)
Definition: ResolverPlugin.inc.php:57
PKPTemplateManager\getManager
static & getManager($request=null)
Definition: PKPTemplateManager.inc.php:1239
Plugin\getPluginPath
getPluginPath()
Definition: Plugin.inc.php:330
Plugin\$request
$request
Definition: Plugin.inc.php:68
Plugin\addLocaleData
addLocaleData($locale=null)
Definition: Plugin.inc.php:454
PKPApplication\get
static get()
Definition: PKPApplication.inc.php:235
GatewayPlugin
Abstract class for gateway plugins.
Definition: GatewayPlugin.inc.php:18
PKPServices\get
static get($service)
Definition: PKPServices.inc.php:49