00001 <?php
00002
00015
00016
00017
00018 import('classes.plugins.GatewayPlugin');
00019
00020 class ResolverPlugin extends GatewayPlugin {
00027 function register($category, $path) {
00028 $success = parent::register($category, $path);
00029 $this->addLocaleData();
00030 return $success;
00031 }
00032
00038 function getNewJournalPluginSettingsFile() {
00039 return $this->getPluginPath() . '/settings.xml';
00040 }
00041
00047 function getName() {
00048 return 'ResolverPlugin';
00049 }
00050
00051 function getDisplayName() {
00052 return Locale::translate('plugins.gateways.resolver.displayName');
00053 }
00054
00055 function getDescription() {
00056 return Locale::translate('plugins.gateways.resolver.description');
00057 }
00058
00062 function fetch($args) {
00063 if (!$this->getEnabled()) {
00064 return false;
00065 }
00066
00067 $scheme = array_shift($args);
00068 switch ($scheme) {
00069 case 'vnp':
00070 case 'ynp':
00071
00072 $journal =& Request::getJournal();
00073 if (!$journal) break;
00074
00075 if ($scheme == 'vnp') {
00076 $volume = (int) array_shift($args);
00077 $year = null;
00078 } elseif ($scheme == 'ynp') {
00079 $year = (int) array_shift($args);
00080 $volume = null;
00081 }
00082 $number = array_shift($args);
00083 $page = (int) array_shift($args);
00084
00085 $issueDao =& DAORegistry::getDAO('IssueDAO');
00086 $issues =& $issueDao->getPublishedIssuesByNumber($journal->getJournalId(), $volume, $number, $year);
00087
00088
00089 $issue =& $issues->next();
00090 if (!$issue || $issues->next()) break;
00091 unset($issues);
00092
00093 $publishedArticleDao =& DAORegistry::getDAO('PublishedArticleDAO');
00094 $articles =& $publishedArticleDao->getPublishedArticles($issue->getIssueId());
00095 foreach ($articles as $article) {
00096
00097 $matches = null;
00098 if (String::regexp_match_get('/^[Pp][Pp]?[.]?[ ]?(\d+)$/', $article->getPages(), $matches)) {
00099 $matchedPage = $matches[1];
00100 if ($page == $matchedPage) Request::redirect(null, 'article', 'view', $article->getBestArticleId());
00101 }
00102 if (String::regexp_match_get('/^[Pp][Pp]?[.]?[ ]?(\d+)[ ]?-[ ]?([Pp][Pp]?[.]?[ ]?)?(\d+)$/', $article->getPages(), $matches)) {
00103 $matchedPageFrom = $matches[1];
00104 $matchedPageTo = $matches[3];
00105 if ($page >= $matchedPageFrom && ($page < $matchedPageTo || ($page == $matchedPageTo && $matchedPageFrom = $matchedPageTo))) Request::redirect(null, 'article', 'view', $article->getBestArticleId());
00106 }
00107 unset($article);
00108 }
00109 }
00110
00111
00112 header("HTTP/1.0 500 Internal Server Error");
00113 $templateMgr =& TemplateManager::getManager();
00114 $templateMgr->assign('message', 'plugins.gateways.resolver.errors.errorMessage');
00115 $templateMgr->display('common/message.tpl');
00116 exit;
00117 }
00118
00119 function sanitize($string) {
00120 return str_replace("\t", " ", strip_tags($string));
00121 }
00122
00123 function exportHoldings() {
00124 $journalDao =& DAORegistry::getDAO('JournalDAO');
00125 $issueDao =& DAORegistry::getDAO('IssueDAO');
00126 $journals =& $journalDao->getEnabledJournals();
00127 header('content-type: text/plain');
00128 header('content-disposition: attachment; filename=holdings.txt');
00129 echo "title\tissn\te_issn\tstart_date\tend_date\tembargo_months\tembargo_days\tjournal_url\tvol_start\tvol_end\tiss_start\tiss_end\n";
00130 while ($journal =& $journals->next()) {
00131 $issues =& $issueDao->getPublishedIssues($journal->getJournalId());
00132 $startDate = $endDate = null;
00133 $startNumber = $endNumber = null;
00134 $startVolume = $endVolume = null;
00135 while ($issue =& $issues->next()) {
00136 $datePublished = $issue->getDatePublished();
00137 if ($datePublished !== null) $datePublished = strtotime($datePublished);
00138 if ($startDate === null || $startDate > $datePublished) $startDate = $datePublished;
00139 if ($endDate === null || $endDate < $datePublished) $endDate = $datePublished;
00140 $volume = $issue->getVolume();
00141 if ($startVolume === null || $startVolume > $volume) $startVolume = $volume;
00142 if ($endVolume === null || $endVolume < $volume) $endVolume = $volume;
00143 $number = $issue->getNumber();
00144 if ($startNumber === null || $startNumber > $number) $startNumber = $number;
00145 if ($endNumber === null || $endNumber < $number) $endNumber = $number;
00146 unset($issue);
00147 }
00148 unset($issues);
00149
00150 echo $this->sanitize($journal->getJournalTitle()) . "\t";
00151 echo $this->sanitize($journal->getSetting('printIssn')) . "\t";
00152 echo $this->sanitize($journal->getSetting('onlineIssn')) . "\t";
00153 echo $this->sanitize($startDate===null?'':strftime('%Y-%m-%d', $startDate)) . "\t";
00154 echo $this->sanitize($endDate===null?'':strftime('%Y-%m-%d', $endDate)) . "\t";
00155 echo $this->sanitize('') . "\t";
00156 echo $this->sanitize('') . "\t";
00157 echo Request::url($journal->getPath()) . "\t";
00158 echo $this->sanitize($startVolume) . "\t";
00159 echo $this->sanitize($endVolume) . "\t";
00160 echo $this->sanitize($startNumber) . "\t";
00161 echo $this->sanitize($endNumber) . "\n";
00162
00163 unset($journal);
00164 }
00165 }
00166
00167 function getManagementVerbs() {
00168 $verbs = parent::getManagementVerbs();
00169 if (Validation::isSiteAdmin() && $this->getEnabled()) {
00170 $verbs[] = array(
00171 'exportHoldings',
00172 Locale::translate('plugins.gateways.resolver.exportHoldings')
00173 );
00174 }
00175 return $verbs;
00176 }
00177
00178 function manage($verb, $args) {
00179 switch ($verb) {
00180 case 'exportHoldings':
00181 if (Validation::isSiteAdmin() && $this->getEnabled()) {
00182 $this->exportHoldings();
00183 return true;
00184 }
00185 break;
00186 }
00187 return parent::manage($verb, $args);
00188 }
00189 }
00190
00191 ?>