00001 <?php
00002
00015
00016
00017
00018 import('classes.plugins.ImportExportPlugin');
00019
00020 class CrossRefExportPlugin extends ImportExportPlugin {
00027 function register($category, $path) {
00028 $success = parent::register($category, $path);
00029 $this->addLocaleData();
00030 return $success;
00031 }
00032
00038 function getName() {
00039 return 'CrossRefExportPlugin';
00040 }
00041
00042 function getDisplayName() {
00043 return Locale::translate('plugins.importexport.crossref.displayName');
00044 }
00045
00046 function getDescription() {
00047 return Locale::translate('plugins.importexport.crossref.description');
00048 }
00049
00050 function display(&$args) {
00051 $templateMgr = &TemplateManager::getManager();
00052 parent::display($args);
00053
00054 $issueDao = &DAORegistry::getDAO('IssueDAO');
00055
00056 $journal = &Request::getJournal();
00057
00058 switch (array_shift($args)) {
00059 case 'exportIssues':
00060 $issueIds = Request::getUserVar('issueId');
00061 if (!isset($issueIds)) $issueIds = array();
00062 $issues = array();
00063 foreach ($issueIds as $issueId) {
00064 $issue = &$issueDao->getIssueById($issueId);
00065 if (!$issue) Request::redirect();
00066 $issues[] = &$issue;
00067 }
00068 $this->exportIssues($journal, $issues);
00069 break;
00070 case 'exportIssue':
00071 $issueId = array_shift($args);
00072 $issue = &$issueDao->getIssueById($issueId);
00073 if (!$issue) Request::redirect();
00074 $issues = array($issue);
00075 $this->exportIssues($journal, $issues);
00076 break;
00077 case 'exportArticle':
00078 $articleIds = array(array_shift($args));
00079 $result = ArticleSearch::formatResults($articleIds);
00080 $this->exportArticles($journal, $result);
00081 break;
00082 case 'exportArticles':
00083 $articleIds = Request::getUserVar('articleId');
00084 if (!isset($articleIds)) $articleIds = array();
00085 $results = &ArticleSearch::formatResults($articleIds);
00086 $this->exportArticles($journal, $results);
00087 break;
00088 case 'issues':
00089
00090 $this->setBreadcrumbs(array(), true);
00091 $issueDao = &DAORegistry::getDAO('IssueDAO');
00092 $issues =& $issueDao->getPublishedIssues($journal->getJournalId(), Handler::getRangeInfo('issues'));
00093
00094 $templateMgr->assign_by_ref('issues', $issues);
00095 $templateMgr->display($this->getTemplatePath() . 'issues.tpl');
00096 break;
00097 case 'articles':
00098
00099 $this->setBreadcrumbs(array(), true);
00100 $publishedArticleDao = &DAORegistry::getDAO('PublishedArticleDAO');
00101 $rangeInfo = Handler::getRangeInfo('articles');
00102 $articleIds = $publishedArticleDao->getPublishedArticleIdsByJournal($journal->getJournalId(), false);
00103 $totalArticles = count($articleIds);
00104 if ($rangeInfo->isValid()) $articleIds = array_slice($articleIds, $rangeInfo->getCount() * ($rangeInfo->getPage()-1), $rangeInfo->getCount());
00105 $iterator = &new VirtualArrayIterator(ArticleSearch::formatResults($articleIds), $totalArticles, $rangeInfo->getPage(), $rangeInfo->getCount());
00106 $templateMgr->assign_by_ref('articles', $iterator);
00107 $templateMgr->display($this->getTemplatePath() . 'articles.tpl');
00108 break;
00109 default:
00110 $this->setBreadcrumbs();
00111 $templateMgr->assign_by_ref('journal', $journal);
00112 $templateMgr->display($this->getTemplatePath() . 'index.tpl');
00113 }
00114 }
00115
00116 function exportArticles(&$journal, &$results, $outputFile = null) {
00117 $this->import('CrossRefExportDom');
00118
00119 $doc = &CrossRefExportDom::generateCrossRefDom();
00120 $doiBatchNode = &CrossRefExportDom::generateDoiBatchDom($doc);
00121
00122
00123 $head = &CrossRefExportDom::generateHeadDom($doc, $journal);
00124
00125
00126 XMLCustomWriter::appendChild($doiBatchNode, $head);
00127
00128
00129 $bodyNode = &XMLCustomWriter::createElement($doc, 'body');
00130 XMLCustomWriter::appendChild($doiBatchNode, $bodyNode);
00131
00132
00133 foreach ($results as $result) {
00134 $journal = &$result['journal'];
00135 $issue = &$result['issue'];
00136 $section = &$result['section'];
00137 $article = &$result['publishedArticle'];
00138
00139
00140
00141
00142 $journalNode = &XMLCustomWriter::createElement($doc, 'journal');
00143 $journalMetadataNode = &CrossRefExportDom::generateJournalMetadataDom($doc, $journal);
00144 XMLCustomWriter::appendChild($journalNode, $journalMetadataNode);
00145
00146
00147 $journalIssueNode = &CrossRefExportDom::generateJournalIssueDom($doc, $journal, $issue, $section, $article);
00148 XMLCustomWriter::appendChild($journalNode, $journalIssueNode);
00149
00150
00151 $journalArticleNode = &CrossRefExportDom::generateJournalArticleDom($doc, $journal, $issue, $section, $article);
00152 XMLCustomWriter::appendChild($journalNode, $journalArticleNode);
00153
00154
00155 $DOIdataNode = &CrossRefExportDom::generateDOIdataDom($doc, $article->getDOI(), Request::url(null, 'article', 'view', $article->getArticleId()));
00156 XMLCustomWriter::appendChild($journalArticleNode, $DOIdataNode);
00157 XMLCustomWriter::appendChild($bodyNode, $journalNode);
00158 }
00159
00160
00161
00162 if (!empty($outputFile)) {
00163 if (($h = fopen($outputFile, 'w'))===false) return false;
00164 fwrite($h, XMLCustomWriter::getXML($doc));
00165 fclose($h);
00166 } else {
00167 header("Content-Type: application/xml");
00168 header("Cache-Control: private");
00169 header("Content-Disposition: attachment; filename=\"crossref.xml\"");
00170 XMLCustomWriter::printXML($doc);
00171 }
00172 return true;
00173 }
00174
00175 function exportIssues(&$journal, &$issues, $outputFile = null) {
00176 $this->import('CrossRefExportDom');
00177
00178 $doc = &CrossRefExportDom::generateCrossRefDom();
00179 $doiBatchNode = &CrossRefExportDom::generateDoiBatchDom($doc);
00180
00181 $journal = &Request::getJournal();
00182
00183
00184 $head = &CrossRefExportDom::generateHeadDom($doc, $journal);
00185
00186
00187 XMLCustomWriter::appendChild($doiBatchNode, $head);
00188
00189 $bodyNode = &XMLCustomWriter::createElement($doc, 'body');
00190 XMLCustomWriter::appendChild($doiBatchNode, $bodyNode);
00191
00192 $sectionDao = &DAORegistry::getDAO('SectionDAO');
00193 $publishedArticleDao = &DAORegistry::getDAO('PublishedArticleDAO');
00194
00195 foreach ($issues as $issue) {
00196 foreach ($sectionDao->getSectionsForIssue($issue->getIssueId()) as $section) {
00197 foreach ($publishedArticleDao->getPublishedArticlesBySectionId($section->getSectionId(), $issue->getIssueId()) as $article) {
00198
00199
00200
00201 $journalNode = &XMLCustomWriter::createElement($doc, 'journal');
00202 $journalMetadataNode = &CrossRefExportDom::generateJournalMetadataDom($doc, $journal);
00203 XMLCustomWriter::appendChild($journalNode, $journalMetadataNode);
00204
00205 $journalIssueNode = &CrossRefExportDom::generateJournalIssueDom($doc, $journal, $issue, $section, $article);
00206 XMLCustomWriter::appendChild($journalNode, $journalIssueNode);
00207
00208
00209 $journalArticleNode = &CrossRefExportDom::generateJournalArticleDom($doc, $journal, $issue, $section, $article);
00210 XMLCustomWriter::appendChild($journalNode, $journalArticleNode);
00211
00212
00213 $DOIdataNode = &CrossRefExportDom::generateDOIdataDom($doc, $article->getDOI(), Request::url(null, 'article', 'view', $article->getArticleId()));
00214 XMLCustomWriter::appendChild($journalArticleNode, $DOIdataNode);
00215 XMLCustomWriter::appendChild($bodyNode, $journalNode);
00216
00217 }
00218 }
00219 }
00220
00221
00222 if (!empty($outputFile)) {
00223 if (($h = fopen($outputFile, 'w'))===false) return false;
00224 fwrite($h, XMLCustomWriter::getXML($doc));
00225 fclose($h);
00226 } else {
00227 header("Content-Type: application/xml");
00228 header("Cache-Control: private");
00229 header("Content-Disposition: attachment; filename=\"crossref.xml\"");
00230 XMLCustomWriter::printXML($doc);
00231 }
00232
00233 return true;
00234 }
00235
00240 function executeCLI($scriptName, &$args) {
00241
00242 $xmlFile = array_shift($args);
00243 $journalPath = array_shift($args);
00244
00245 $journalDao = &DAORegistry::getDAO('JournalDAO');
00246 $issueDao = &DAORegistry::getDAO('IssueDAO');
00247 $sectionDao = &DAORegistry::getDAO('SectionDAO');
00248 $userDao = &DAORegistry::getDAO('UserDAO');
00249 $publishedArticleDao = &DAORegistry::getDAO('PublishedArticleDAO');
00250
00251 $journal = &$journalDao->getJournalByPath($journalPath);
00252
00253 if (!$journal) {
00254 if ($journalPath != '') {
00255 echo Locale::translate('plugins.importexport.crossref.cliError') . "\n";
00256 echo Locale::translate('plugins.importexport.crossref.error.unknownJournal', array('journalPath' => $journalPath)) . "\n\n";
00257 }
00258 $this->usage($scriptName);
00259 return;
00260 }
00261
00262 if ($xmlFile != '') switch (array_shift($args)) {
00263 case 'articles':
00264 $results = &ArticleSearch::formatResults($args);
00265 if (!$this->exportArticles($journal, $results, $xmlFile)) {
00266 echo Locale::translate('plugins.importexport.crossref.cliError') . "\n";
00267 echo Locale::translate('plugins.importexport.crossref.export.error.couldNotWrite', array('fileName' => $xmlFile)) . "\n\n";
00268 }
00269 return;
00270 case 'issue':
00271 $issueId = array_shift($args);
00272 $issue = &$issueDao->getIssueByBestIssueId($issueId, $journal->getJournalId());
00273 if ($issue == null) {
00274 echo Locale::translate('plugins.importexport.crossref.cliError') . "\n";
00275 echo Locale::translate('plugins.importexport.crossref.export.error.issueNotFound', array('issueId' => $issueId)) . "\n\n";
00276 return;
00277 }
00278 $issues = array($issue);
00279 if (!$this->exportIssues($journal, $issues, $xmlFile)) {
00280 echo Locale::translate('plugins.importexport.crossref.cliError') . "\n";
00281 echo Locale::translate('plugins.importexport.crossref.export.error.couldNotWrite', array('fileName' => $xmlFile)) . "\n\n";
00282 }
00283 return;
00284 }
00285 $this->usage($scriptName);
00286
00287 }
00288
00292 function usage($scriptName) {
00293 echo Locale::translate('plugins.importexport.crossref.cliUsage', array(
00294 'scriptName' => $scriptName,
00295 'pluginName' => $this->getName()
00296 )) . "\n";
00297 }
00298 }
00299
00300 ?>