function exportIssues(&$journal, &$issues, $outputFile = null) { $this->import('CrossRefExportDom'); $doc =& CrossRefExportDom::generateCrossRefDom(); $doiBatchNode =& CrossRefExportDom::generateDoiBatchDom($doc); $journal =& Request::getJournal(); // Create Head Node and all parts inside it $head =& CrossRefExportDom::generateHeadDom($doc, $journal); // attach it to the root node XMLCustomWriter::appendChild($doiBatchNode, $head); $bodyNode =& XMLCustomWriter::createElement($doc, 'body'); XMLCustomWriter::appendChild($doiBatchNode, $bodyNode); $sectionDao =& DAORegistry::getDAO('SectionDAO'); $publishedArticleDao =& DAORegistry::getDAO('PublishedArticleDAO'); foreach ($issues as $issue) { foreach ($sectionDao->getSectionsForIssue($issue->getId()) as $section) { foreach ($publishedArticleDao->getPublishedArticlesBySectionId($section->getId(), $issue->getId()) as $article) { // Create the metadata node // this does not need to be repeated for every article // but its allowed to be and its simpler to do so $journalNode =& XMLCustomWriter::createElement($doc, 'journal'); $journalMetadataNode =& CrossRefExportDom::generateJournalMetadataDom($doc, $journal); XMLCustomWriter::appendChild($journalNode, $journalMetadataNode); $journalIssueNode =& CrossRefExportDom::generateJournalIssueDom($doc, $journal, $issue, $section, $article); XMLCustomWriter::appendChild($journalNode, $journalIssueNode); // Article node $journalArticleNode =& CrossRefExportDom::generateJournalArticleDom($doc, $journal, $issue, $section, $article); XMLCustomWriter::appendChild($journalNode, $journalArticleNode); // DOI data node $DOIdataNode =& CrossRefExportDom::generateDOIdataDom($doc, $article->getDOI(), Request::url(null, 'article', 'view', $article->getId())); XMLCustomWriter::appendChild($journalArticleNode, $DOIdataNode); XMLCustomWriter::appendChild($bodyNode, $journalNode); } } } // dump out results if (!empty($outputFile)) { if (($h = fopen($outputFile, 'w')) === false) { return false; } fwrite($h, XMLCustomWriter::getXML($doc)); fclose($h); } else { header("Content-Type: application/xml"); header("Cache-Control: private"); header("Content-Disposition: attachment; filename=\"crossref.xml\""); XMLCustomWriter::printXML($doc); } return true; }
/** * Generate the journal_article node (the heart of the file). * @param $doc XMLNode * @param $journal Journal * @param $issue Issue * @param $section Section * @param $article Article * @return XMLNode */ function &generateJournalArticleDom(&$doc, &$journal, &$issue, &$section, &$article) { // Create the base node $journalArticleNode =& XMLCustomWriter::createElement($doc, 'journal_article'); XMLCustomWriter::setAttribute($journalArticleNode, 'publication_type', 'full_text'); /* Titles */ $titlesNode =& XMLCustomWriter::createElement($doc, 'titles'); XMLCustomWriter::createChildWithText($doc, $titlesNode, 'title', $article->getLocalizedTitle()); XMLCustomWriter::appendChild($journalArticleNode, $titlesNode); $contributorsNode =& XMLCustomWriter::createElement($doc, 'contributors'); /* AuthorList */ $isFirst = true; foreach ($article->getAuthors() as $author) { $authorNode =& CrossRefExportDom::generateAuthorDom($doc, $author, $isFirst); $isFirst = false; XMLCustomWriter::appendChild($contributorsNode, $authorNode); } XMLCustomWriter::appendChild($journalArticleNode, $contributorsNode); /* publication date of issue */ if ($issue->getDatePublished()) { $publicationDateNode =& CrossRefExportDom::generatePublisherDateDom($doc, $issue->getDatePublished()); XMLCustomWriter::appendChild($journalArticleNode, $publicationDateNode); } /* publisher_item is the article pages */ if ($article->getPages() != '') { $publisherItemNode =& XMLCustomWriter::createElement($doc, 'publisher_item'); XMLCustomWriter::createChildWithText($doc, $publisherItemNode, 'item_number', $article->getPages()); XMLCustomWriter::appendChild($journalArticleNode, $publisherItemNode); } return $journalArticleNode; }
/** * @see DOIExportPlugin::processMarkRegistered() */ function processMarkRegistered(&$request, $exportType, &$objects, &$journal) { $this->import('classes.CrossRefExportDom'); $dom = new CrossRefExportDom($request, $this, $journal, $this->getCache()); foreach ($objects as $object) { if (is_a($object, 'Issue')) { $articlesByIssue =& $dom->retrieveArticlesByIssue($object); foreach ($articlesByIssue as $article) { if ($article->getPubId('doi')) { $this->markRegistered($request, $article); } } } else { if ($object->getPubId('doi')) { $this->markRegistered($request, $object); } } } }
/** * Generate the component_list node (supplementary files). * @param $doc XMLNode * @param $journal Journal * @param $issue Issue * @param $section Section * @param $article Article * @return XMLNode */ function &generateComponentListDom(&$doc, &$journal, &$article) { $suppFiles =& $article->getSuppFiles(); if ($suppFiles) { // Create the base node $componentListNode =& XMLCustomWriter::createElement($doc, 'component_list'); // Run through supp files and add component nodes. foreach ($suppFiles as $suppFile) { $componentNode =& XMLCustomWriter::createElement($doc, 'component'); XMLCustomWriter::setAttribute($componentNode, 'parent_relation', 'isPartOf'); /* Titles */ $suppFileTitle = $suppFile->getSuppFileTitle(); if (!empty($suppFileTitle)) { $titlesNode =& XMLCustomWriter::createElement($doc, 'titles'); XMLCustomWriter::createChildWithText($doc, $titlesNode, 'title', $suppFileTitle); XMLCustomWriter::appendChild($componentNode, $titlesNode); } // DOI data node if ($suppFile->getPubId('doi')) { $suppFileUrl = Request::url(null, 'article', 'downloadSuppFile', array($article->getId(), $suppFile->getBestSuppFileId($journal))); $suppFileDoiNode = CrossRefExportDom::generateDOIdataDom($doc, $suppFile->getPubId('doi'), $suppFileUrl); XMLCustomWriter::appendChild($componentNode, $suppFileDoiNode); } XMLCustomWriter::appendChild($componentListNode, $componentNode); unset($componentNode); } } return $componentListNode; }
/** * Generate the journal_article node (the heart of the file). * @param $doc XMLNode * @param $journal Journal * @param $issue Issue * @param $section Section * @param $article Article * @return XMLNode */ function &generateJournalArticleDom(&$doc, &$journal, &$issue, &$section, &$article) { // Create the base node $journalArticleNode =& XMLCustomWriter::createElement($doc, 'journal_article'); XMLCustomWriter::setAttribute($journalArticleNode, 'publication_type', 'full_text'); /* Titles */ $titlesNode =& XMLCustomWriter::createElement($doc, 'titles'); XMLCustomWriter::createChildWithText($doc, $titlesNode, 'title', $article->getLocalizedTitle()); XMLCustomWriter::appendChild($journalArticleNode, $titlesNode); /* AuthorList */ $contributorsNode =& XMLCustomWriter::createElement($doc, 'contributors'); $isFirst = true; foreach ($article->getAuthors() as $author) { $authorNode =& CrossRefExportDom::generateAuthorDom($doc, $author, $isFirst); $isFirst = false; XMLCustomWriter::appendChild($contributorsNode, $authorNode); } XMLCustomWriter::appendChild($journalArticleNode, $contributorsNode); /* publication date of article */ if ($article->getDatePublished()) { $publicationDateNode =& CrossRefExportDom::generatePublisherDateDom($doc, $article->getDatePublished()); XMLCustomWriter::appendChild($journalArticleNode, $publicationDateNode); } elseif ($issue->getDatePublished()) { $publicationDateNode =& CrossRefExportDom::generatePublisherDateDom($doc, $issue->getDatePublished()); XMLCustomWriter::appendChild($journalArticleNode, $publicationDateNode); } else { echo __('plugins.importexport.crossref.articleDatePublishedError', array('articleId' => $article->getId())) . "\n\n"; } /* publisher_item is the article pages */ if ($article->getPages() != '') { $pageNode =& XMLCustomWriter::createElement($doc, 'pages'); // extract the first page for the first_page element, store the remaining bits in otherPages, // after removing any preceding non-numerical characters. if (preg_match('/^[^\\d]*(\\d+)\\D*(.*)$/', $article->getPages(), $matches)) { $firstPage = $matches[1]; $otherPages = $matches[2]; XMLCustomWriter::createChildWithText($doc, $pageNode, 'first_page', $firstPage); if ($otherPages != '') { XMLCustomWriter::createChildWithText($doc, $pageNode, 'other_pages', $otherPages); } } XMLCustomWriter::appendChild($journalArticleNode, $pageNode); } // DOI data node $articleGalleyDao = DAORegistry::getDAO('ArticleGalleyDAO'); $DOIdataNode =& CrossRefExportDom::generateDOIdataDom($doc, $article->getPubId('doi'), Request::url(null, 'article', 'view', $article->getBestArticleId()), $articleGalleyDao->getGalleysByArticle($article->getId())); XMLCustomWriter::appendChild($journalArticleNode, $DOIdataNode); /* Component list (supplementary files) */ $componentListNode =& CrossRefExportDom::generateComponentListDom($doc, $journal, $article); if ($componentListNode) { XMLCustomWriter::appendChild($journalArticleNode, $componentListNode); } return $journalArticleNode; }