/** * Export a journal's content * @param $journal object * @param $outputFile string */ function exportJournal(&$journal, $outputFile = null) { $this->import('DOAJExportDom'); $doc =& XMLCustomWriter::createDocument(); $journalNode =& DOAJExportDom::generateJournalDom($doc, $journal); $journalNode->setAttribute('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance'); $journalNode->setAttribute('xsi:noNamespaceSchemaLocation', DOAJ_XSD_URL); XMLCustomWriter::appendChild($doc, $journalNode); if (!empty($outputFile)) { if (($h = fopen($outputFile, 'wb')) === 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=\"journal-" . $journal->getId() . ".xml\""); XMLCustomWriter::printXML($doc); } return true; }
/** * Generate the DOM tree for a given article. * @param $doc object DOM object * @param $journal object Journal * @param $issue object Issue * @param $section object Section * @param $article object Article */ function &generateArticleDom(&$doc, &$journal, &$issue, &$section, &$article) { $root =& XMLCustomWriter::createElement($doc, 'record'); /* --- Article Language --- */ XMLCustomWriter::createChildWithText($doc, $root, 'language', DOAJExportDom::mapLang($article->getLanguage()), false); /* --- Publisher name (i.e. institution name) --- */ XMLCustomWriter::createChildWithText($doc, $root, 'publisher', $journal->getSetting('publisherInstitution'), false); /* --- Journal's title --- */ XMLCustomWriter::createChildWithText($doc, $root, 'journalTitle', $journal->getLocalizedTitle(), false); /* --- Identification Numbers --- */ XMLCustomWriter::createChildWithText($doc, $root, 'issn', $journal->getSetting('printIssn'), false); XMLCustomWriter::createChildWithText($doc, $root, 'eissn', $journal->getSetting('onlineIssn'), false); /* --- Article's publication date, volume, issue, DOI --- */ XMLCustomWriter::createChildWithText($doc, $root, 'publicationDate', DOAJExportDom::formatDate($issue->getDatePublished()), false); XMLCustomWriter::createChildWithText($doc, $root, 'volume', $issue->getVolume(), false); XMLCustomWriter::createChildWithText($doc, $root, 'issue', $issue->getNumber(), false); /** --- FirstPage / LastPage (from PubMed plugin)--- * there is some ambiguity for online journals as to what * "page numbers" are; for example, some journals (eg. JMIR) * use the "e-location ID" as the "page numbers" in PubMed */ $pages = $article->getPages(); if (preg_match("/([0-9]+)\\s*-\\s*([0-9]+)/i", $pages, $matches)) { // simple pagination (eg. "pp. 3-8") XMLCustomWriter::createChildWithText($doc, $root, 'startPage', $matches[1]); XMLCustomWriter::createChildWithText($doc, $root, 'endPage', $matches[2]); } elseif (preg_match("/(e[0-9]+)/i", $pages, $matches)) { // elocation-id (eg. "e12") XMLCustomWriter::createChildWithText($doc, $root, 'startPage', $matches[1]); XMLCustomWriter::createChildWithText($doc, $root, 'endPage', $matches[1]); } XMLCustomWriter::createChildWithText($doc, $root, 'doi', $article->getPubId('doi'), false); /* --- Article's publication date, volume, issue, DOI --- */ XMLCustomWriter::createChildWithText($doc, $root, 'publisherRecordId', $article->getPublishedArticleId(), false); XMLCustomWriter::createChildWithText($doc, $root, 'documentType', $article->getLocalizedType(), false); /* --- Article title --- */ foreach ((array) $article->getTitle(null) as $locale => $title) { if (empty($title)) { continue; } $titleNode =& XMLCustomWriter::createChildWithText($doc, $root, 'title', $title); if (strlen($locale) == 5) { XMLCustomWriter::setAttribute($titleNode, 'language', DOAJExportDom::mapLang(String::substr($locale, 0, 2))); } } /* --- Authors and affiliations --- */ $authors =& XMLCustomWriter::createElement($doc, 'authors'); XMLCustomWriter::appendChild($root, $authors); $affilList = DOAJExportDom::generateAffiliationsList($article->getAuthors()); foreach ($article->getAuthors() as $author) { $authorNode =& DOAJExportDom::generateAuthorDom($doc, $root, $issue, $article, $author, $affilList); XMLCustomWriter::appendChild($authors, $authorNode); unset($authorNode); } if (!empty($affilList[0])) { $affils =& XMLCustomWriter::createElement($doc, 'affiliationsList'); XMLCustomWriter::appendChild($root, $affils); for ($i = 0; $i < count($affilList); $i++) { $affilNode =& XMLCustomWriter::createChildWithText($doc, $affils, 'affiliationName', $affilList[$i]); XMLCustomWriter::setAttribute($affilNode, 'affiliationId', $i); unset($affilNode); } } /* --- Abstract --- */ foreach ((array) $article->getAbstract(null) as $locale => $abstract) { if (empty($abstract)) { continue; } $abstractNode =& XMLCustomWriter::createChildWithText($doc, $root, 'abstract', $abstract); if (strlen($locale) == 5) { XMLCustomWriter::setAttribute($abstractNode, 'language', DOAJExportDom::mapLang(String::substr($locale, 0, 2))); } } /* --- FullText URL --- */ $fullTextUrl =& XMLCustomWriter::createChildWithText($doc, $root, 'fullTextUrl', Request::url(null, 'article', 'view', $article->getId())); XMLCustomWriter::setAttribute($fullTextUrl, 'format', 'html'); /* --- Keywords --- */ $keywords =& XMLCustomWriter::createElement($doc, 'keywords'); XMLCustomWriter::appendChild($root, $keywords); $subjects = array_map('trim', explode(';', $article->getLocalizedSubject())); foreach ($subjects as $keyword) { XMLCustomWriter::createChildWithText($doc, $keywords, 'keyword', $keyword, false); } return $root; }
/** * Export a journal's content * @param $journal object * @param $outputFile string */ function exportJournal(&$journal, $outputFile = null) { $this->import('DOAJExportDom'); $doc =& XMLCustomWriter::createDocument('journal', DOAJ_XSD_URL); $journalNode =& DOAJExportDom::generateJournalDom($doc, $journal); XMLCustomWriter::appendChild($doc, $journalNode); if (!empty($outputFile)) { if (($h = fopen($outputFile, 'wb')) === 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=\"journal-" . $journal->getJournalId() . ".xml\""); XMLCustomWriter::printXML($doc); } return true; }