Open Journal Systems  3.3.0
DOAJXmlFilter.inc.php
1 <?php
2 
16 import('lib.pkp.plugins.importexport.native.filter.NativeExportFilter');
17 
18 
24  function __construct($filterGroup) {
25  $this->setDisplayName('DOAJ XML export');
26  parent::__construct($filterGroup);
27  }
28 
29  //
30  // Implement template methods from PersistableFilter
31  //
35  function getClassName() {
36  return 'plugins.importexport.doaj.filter.DOAJXmlFilter';
37  }
38 
39  //
40  // Implement template methods from Filter
41  //
47  function &process(&$pubObjects) {
48  // Create the XML document
49  $doc = new DOMDocument('1.0', 'utf-8');
50  $doc->preserveWhiteSpace = false;
51  $doc->formatOutput = true;
52  $deployment = $this->getDeployment();
53  $context = $deployment->getContext();
54  $plugin = $deployment->getPlugin();
55  $cache = $plugin->getCache();
56 
57  // Create the root node
58  $rootNode = $this->createRootNode($doc);
59  $doc->appendChild($rootNode);
60 
61  foreach($pubObjects as $pubObject) {
62  $publication = $pubObject->getCurrentPublication();
63  $issueId = $publication->getData('issueId');
64  if ($cache->isCached('issues', $issueId)) {
65  $issue = $cache->get('issues', $issueId);
66  } else {
67  $issueDao = DAORegistry::getDAO('IssueDAO'); /* @var $issueDao IssueDAO */
68  $issue = $issueDao->getById($issueId, $context->getId());
69  if ($issue) $cache->add($issue, null);
70  }
71 
72  // Record
73  $recordNode = $doc->createElement('record');
74  $rootNode->appendChild($recordNode);
75  // Language
76  $language = AppLocale::get3LetterIsoFromLocale($publication->getData('locale'));
77  if (!empty($language)) $recordNode->appendChild($node = $doc->createElement('language', $language));
78  // Publisher name (i.e. institution name)
79  $publisher = $context->getData('publisherInstitution');
80  if (!empty($publisher)) $recordNode->appendChild($node = $doc->createElement('publisher', htmlspecialchars($publisher, ENT_COMPAT, 'UTF-8')));
81  // Journal's title (M)
82  $journalTitle = $context->getName($context->getPrimaryLocale());
83  $recordNode->appendChild($node = $doc->createElement('journalTitle', htmlspecialchars($journalTitle, ENT_COMPAT, 'UTF-8')));
84  // Identification Numbers
85  $issn = $context->getData('printIssn');
86  if (!empty($issn)) $recordNode->appendChild($node = $doc->createElement('issn', $issn));
87  $eissn = $context->getData('onlineIssn');
88  if (!empty($eissn)) $recordNode->appendChild($node = $doc->createElement('eissn', $eissn));
89  // Article's publication date, volume, issue
90  if ($publication->getData('datePublished')) {
91  $recordNode->appendChild($node = $doc->createElement('publicationDate', $this->formatDate($publication->getData('datePublished'))));
92  } else {
93  $recordNode->appendChild($node = $doc->createElement('publicationDate', $this->formatDate($issue->getDatePublished())));
94  }
95  $volume = $issue->getVolume();
96  if (!empty($volume) && $issue->getShowVolume()) $recordNode->appendChild($node = $doc->createElement('volume', htmlspecialchars($volume, ENT_COMPAT, 'UTF-8')));
97  $issueNumber = $issue->getNumber();
98  if (!empty($issueNumber) && $issue->getShowNumber()) $recordNode->appendChild($node = $doc->createElement('issue', htmlspecialchars($issueNumber, ENT_COMPAT, 'UTF-8')));
104  $startPage = $publication->getStartingPage();
105  $endPage = $publication->getEndingPage();
106  if (isset($startPage) && $startPage !== "") {
107  $recordNode->appendChild($node = $doc->createElement('startPage', htmlspecialchars($startPage, ENT_COMPAT, 'UTF-8')));
108  $recordNode->appendChild($node = $doc->createElement('endPage', htmlspecialchars($endPage, ENT_COMPAT, 'UTF-8')));
109  }
110  // DOI
111  $doi = $publication->getStoredPubId('doi');
112  if (!empty($doi)) $recordNode->appendChild($node = $doc->createElement('doi', htmlspecialchars($doi, ENT_COMPAT, 'UTF-8')));
113  // publisherRecordId
114  $recordNode->appendChild($node = $doc->createElement('publisherRecordId', htmlspecialchars($publication->getId(), ENT_COMPAT, 'UTF-8')));
115  // documentType
116  $type = $publication->getLocalizedData('type', $publication->getData('locale'));
117  if (!empty($type)) $recordNode->appendChild($node = $doc->createElement('documentType', htmlspecialchars($type, ENT_COMPAT, 'UTF-8')));
118  // Article title
119  $articleTitles = (array) $publication->getData('title');
120  if (array_key_exists($publication->getData('locale'), $articleTitles)) {
121  $titleInArticleLocale = $articleTitles[$publication->getData('locale')];
122  unset($articleTitles[$publication->getData('locale')]);
123  $articleTitles = array_merge(array($publication->getData('locale') => $titleInArticleLocale), $articleTitles);
124  }
125  foreach ($articleTitles as $locale => $title) {
126  if (!empty($title)) {
127  $recordNode->appendChild($node = $doc->createElement('title', htmlspecialchars($title, ENT_COMPAT, 'UTF-8')));
128  $node->setAttribute('language', AppLocale::get3LetterIsoFromLocale($locale));
129  }
130  }
131  // Authors and affiliations
132  $authorsNode = $doc->createElement('authors');
133  $recordNode->appendChild($authorsNode);
134  $affilList = $this->createAffiliationsList((array) $publication->getData('authors'), $publication);
135  foreach ((array) $publication->getData('authors') as $author) {
136  $authorsNode->appendChild($this->createAuthorNode($doc, $publication, $author, $affilList));
137  }
138  if (!empty($affilList[0])) {
139  $affilsNode = $doc->createElement('affiliationsList');
140  $recordNode->appendChild($affilsNode);
141  for ($i = 0; $i < count($affilList); $i++) {
142  $affilsNode->appendChild($node = $doc->createElement('affiliationName', htmlspecialchars($affilList[$i], ENT_COMPAT, 'UTF-8')));
143  $node->setAttribute('affiliationId', $i);
144  }
145  }
146  // Abstract
147  $articleAbstracts = (array) $publication->getData('abstract');
148  if (array_key_exists($publication->getData('locale'), $articleAbstracts)) {
149  $abstractInArticleLocale = $articleAbstracts[$publication->getData('locale')];
150  unset($articleAbstracts[$publication->getData('locale')]);
151  $articleAbstracts = array_merge(array($publication->getData('locale') => $abstractInArticleLocale), $articleAbstracts);
152  }
153  foreach ($articleAbstracts as $locale => $abstract) {
154  if (!empty($abstract)) {
155  $recordNode->appendChild($node = $doc->createElement('abstract', htmlspecialchars(PKPString::html2text($abstract), ENT_COMPAT, 'UTF-8')));
156  $node->setAttribute('language', AppLocale::get3LetterIsoFromLocale($locale));
157  }
158  }
159  // FullText URL
160  $request = Application::get()->getRequest();
161  $recordNode->appendChild($node = $doc->createElement('fullTextUrl', htmlspecialchars($request->url(null, 'article', 'view', $pubObject->getId()), ENT_COMPAT, 'UTF-8')));
162  $node->setAttribute('format', 'html');
163  // Keywords
164  $supportedLocales = array_keys(AppLocale::getSupportedFormLocales());
165  $dao = DAORegistry::getDAO('SubmissionKeywordDAO');
166  $articleKeywords = $dao->getKeywords($publication->getId(), $supportedLocales);
167  if (array_key_exists($publication->getData('locale'), $articleKeywords)) {
168  $keywordsInArticleLocale = $articleKeywords[$publication->getData('locale')];
169  unset($articleKeywords[$publication->getData('locale')]);
170  $articleKeywords = array_merge(array($publication->getData('locale') => $keywordsInArticleLocale), $articleKeywords);
171  }
172  foreach ($articleKeywords as $locale => $keywords) {
173  $keywordsNode = $doc->createElement('keywords');
174  $keywordsNode->setAttribute('language', AppLocale::get3LetterIsoFromLocale($locale));
175  $recordNode->appendChild($keywordsNode);
176  foreach ($keywords as $keyword) {
177  if (!empty($keyword)) $keywordsNode->appendChild($node = $doc->createElement('keyword', htmlspecialchars($keyword, ENT_COMPAT, 'UTF-8')));
178  }
179  }
180  }
181  return $doc;
182  }
183 
189  function createRootNode($doc) {
190  $deployment = $this->getDeployment();
191  $rootNode = $doc->createElement($deployment->getRootElementName());
192  $rootNode->setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance');
193  $rootNode->setAttribute('xsi:noNamespaceSchemaLocation', $deployment->getXmlSchemaLocation());
194  return $rootNode;
195  }
196 
205  function createAuthorNode($doc, $publication, $author, $affilList) {
206  $deployment = $this->getDeployment();
207  $authorNode = $doc->createElement('author');
208  $authorNode->appendChild($node = $doc->createElement('name', htmlspecialchars($author->getFullName(false), ENT_COMPAT, 'UTF-8')));
209  if(in_array($author->getAffiliation($publication->getData('locale')), $affilList) && !empty($affilList[0])) {
210  $authorNode->appendChild($node = $doc->createElement('affiliationId', htmlspecialchars(current(array_keys($affilList, $author->getAffiliation($publication->getData('locale')))), ENT_COMPAT, 'UTF-8')));
211  }
212  if ($orcid = $author->getData('orcid')) {
213  $authorNode->appendChild($doc->createElement('orcid_id'))->appendChild($doc->createTextNode($orcid));
214  }
215  return $authorNode;
216  }
217 
224  function createAffiliationsList($authors, $publication) {
225  $affilList = array();
226  foreach ($authors as $author) {
227  if(!in_array($author->getAffiliation($publication->getData('locale')), $affilList)) {
228  $affilList[] = $author->getAffiliation($publication->getData('locale')) ;
229  }
230  }
231  return $affilList;
232  }
233 
239  function formatDate($date) {
240  if ($date == '') return null;
241  return date('Y-m-d', strtotime($date));
242  }
243 
244 }
245 
246 
DOAJXmlFilter\process
& process(&$pubObjects)
Definition: DOAJXmlFilter.inc.php:47
DAORegistry\getDAO
static & getDAO($name, $dbconn=null)
Definition: DAORegistry.inc.php:57
DOAJXmlFilter\formatDate
formatDate($date)
Definition: DOAJXmlFilter.inc.php:239
PKPLocale\get3LetterIsoFromLocale
static get3LetterIsoFromLocale($locale)
Definition: PKPLocale.inc.php:651
NativeImportExportFilter\getDeployment
getDeployment()
Definition: NativeImportExportFilter.inc.php:49
DOAJXmlFilter\getClassName
getClassName()
Definition: DOAJXmlFilter.inc.php:35
NativeExportFilter
Base class that converts a DataObject to a Native XML document.
Definition: NativeExportFilter.inc.php:18
PKPString\html2text
static html2text($html)
Definition: PKPString.inc.php:395
DOAJXmlFilter\__construct
__construct($filterGroup)
Definition: DOAJXmlFilter.inc.php:24
DOAJXmlFilter\createAffiliationsList
createAffiliationsList($authors, $publication)
Definition: DOAJXmlFilter.inc.php:224
DOAJXmlFilter\createRootNode
createRootNode($doc)
Definition: DOAJXmlFilter.inc.php:189
DOAJXmlFilter
Class that converts an Article to a DOAJ XML document.
Definition: DOAJXmlFilter.inc.php:19
PKPApplication\get
static get()
Definition: PKPApplication.inc.php:235
DOAJXmlFilter\createAuthorNode
createAuthorNode($doc, $publication, $author, $affilList)
Definition: DOAJXmlFilter.inc.php:205
Filter\setDisplayName
setDisplayName($displayName)
Definition: Filter.inc.php:140
AppLocale\getSupportedFormLocales
static getSupportedFormLocales()
Definition: env1/MockAppLocale.inc.php:124