00001 <?php
00002
00015
00016
00017
00018 import('xml.XMLCustomWriter');
00019
00020 class NativeImportDom {
00021 function importArticles(&$journal, &$nodes, &$issue, &$section, &$articles, &$errors, &$user, $isCommandLine) {
00022 $articles = array();
00023 $dependentItems = array();
00024 $hasErrors = false;
00025 foreach ($nodes as $node) {
00026 $result = NativeImportDom::handleArticleNode($journal, $node, $issue, $section, $article, $publishedArticle, $articleErrors, $user, $isCommandLine, $dependentItems);
00027 if ($result) {
00028 $articles[] = $article;
00029 } else {
00030 $errors = array_merge($errors, $articleErrors);
00031 $hasErrors = true;
00032 }
00033 }
00034 if ($hasErrors) {
00035 NativeImportDom::cleanupFailure ($dependentItems);
00036 return false;
00037 }
00038 return true;
00039 }
00040
00041 function importArticle(&$journal, &$node, &$issue, &$section, &$article, &$errors, &$user, $isCommandLine) {
00042 $dependentItems = array();
00043 $result = NativeImportDom::handleArticleNode($journal, $node, $issue, $section, $article, $publishedArticle, $errors, $user, $isCommandLine, $dependentItems);
00044 if (!$result) {
00045 NativeImportDom::cleanupFailure ($dependentItems);
00046 }
00047 return $result;
00048 }
00049
00050 function importIssues(&$journal, &$issueNodes, &$issues, &$errors, &$user, $isCommandLine) {
00051 $dependentItems = array();
00052 $errors = array();
00053 $issues = array();
00054 $hasErrors = false;
00055 foreach ($issueNodes as $issueNode) {
00056 $result = NativeImportDom::importIssue($journal, $issueNode, $issue, $issueErrors, $user, $isCommandLine, $dependentItems, false);
00057 if ($result) {
00058
00059
00060 $issues[] = $issue;
00061 } else {
00062
00063
00064
00065
00066
00067 $errors = array_merge($errors, $issueErrors);
00068 $hasErrors = true;
00069 }
00070 }
00071 if ($hasErrors) {
00072
00073
00074 NativeImportDom::cleanupFailure ($dependentItems);
00075 $issueDao = &DAORegistry::getDAO('IssueDAO');
00076 foreach ($issues as $issue) {
00077 $issueDao->deleteIssue($issue);
00078 }
00079 return false;
00080 }
00081 return true;
00082 }
00083
00084 function importIssue(&$journal, &$issueNode, &$issue, &$errors, &$user, $isCommandLine, &$dependentItems, $cleanupErrors = true) {
00085 $errors = array();
00086 $issue = null;
00087 $hasErrors = false;
00088
00089 $issueDao = &DAORegistry::getDAO('IssueDAO');
00090 $issue = new Issue();
00091 $issue->setJournalId($journal->getJournalId());
00092
00093 $journalSupportedLocales = array_keys($journal->getSupportedLocaleNames());
00094 $journalPrimaryLocale = $journal->getPrimaryLocale();
00095
00096
00097
00098 $titleExists = false;
00099 for ($index=0; ($node = $issueNode->getChildByName('title', $index)); $index++) {
00100 $locale = $node->getAttribute('locale');
00101 if ($locale == '') {
00102 $locale = $journalPrimaryLocale;
00103 } elseif (!in_array($locale, $journalSupportedLocales)) {
00104 $errors[] = array('plugins.importexport.native.import.error.issueTitleLocaleUnsupported', array('issueTitle' => $node->getValue(), 'locale' => $locale));
00105 $hasErrors = true;
00106 continue;
00107 }
00108 $issue->setTitle($node->getValue(), $locale);
00109 $titleExists = true;
00110 }
00111 if (!$titleExists) {
00112 $errors[] = array('plugins.importexport.native.import.error.titleMissing', array());
00113
00114
00115
00116 $issue->setTitle(Locale::translate('plugins.importexport.native.import.error.defaultTitle'));
00117 $hasErrors = true;
00118 }
00119
00120 for ($index=0; ($node = $issueNode->getChildByName('description', $index)); $index++) {
00121 $locale = $node->getAttribute('locale');
00122 if ($locale == '') {
00123 $locale = $journalPrimaryLocale;
00124 } elseif (!in_array($locale, $journalSupportedLocales)) {
00125 $errors[] = array('plugins.importexport.native.import.error.issueDescriptionLocaleUnsupported', array('issueTitle' => $issue->getIssueTitle(), 'locale' => $locale));
00126 $hasErrors = true;
00127 continue;
00128 }
00129 $issue->setDescription($node->getValue(), $locale);
00130 }
00131
00132 if (($node = $issueNode->getChildByName('volume'))) $issue->setVolume($node->getValue());
00133 if (($node = $issueNode->getChildByName('number'))) $issue->setNumber($node->getValue());
00134 if (($node = $issueNode->getChildByName('year'))) $issue->setYear($node->getValue());
00135
00136
00137
00138 if (($node = $issueNode->getChildByName('date_published'))) {
00139 $publishedDate = strtotime($node->getValue());
00140 if ($publishedDate === -1) {
00141 $errors[] = array('plugins.importexport.native.import.error.invalidDate', array('value' => $node->getValue()));
00142 if ($cleanupErrors) {
00143 NativeImportDom::cleanupFailure ($dependentItems);
00144 }
00145 return false;
00146 } else {
00147 $issue->setDatePublished($publishedDate);
00148 }
00149 }
00150
00151
00152
00153 switch(($value = $issueNode->getAttribute('identification'))) {
00154 case 'num_vol_year':
00155 $issue->setShowVolume(1);
00156 $issue->setShowNumber(1);
00157 $issue->setShowYear(1);
00158 $issue->setShowTitle(0);
00159 break;
00160 case 'vol_year':
00161 $issue->setShowVolume(1);
00162 $issue->setShowNumber(0);
00163 $issue->setShowYear(1);
00164 $issue->setShowTitle(0);
00165 break;
00166 case 'year':
00167 $issue->setShowVolume(0);
00168 $issue->setShowNumber(0);
00169 $issue->setShowYear(1);
00170 $issue->setShowTitle(0);
00171 break;
00172 case 'title':
00173 case '':
00174 case null:
00175 $issue->setShowVolume(0);
00176 $issue->setShowNumber(0);
00177 $issue->setShowYear(0);
00178 $issue->setShowTitle(1);
00179 break;
00180 default:
00181 $errors[] = array('plugins.importexport.native.import.error.unknownIdentificationType', array('identificationType' => $value, 'issueTitle' => $issue->getIssueTitle()));
00182 $hasErrors = true;
00183 break;
00184 }
00185
00186 switch(($value = $issueNode->getAttribute('published'))) {
00187 case 'true':
00188 $issue->setPublished(1);
00189 break;
00190 case 'false':
00191 case '':
00192 case null:
00193 $issue->setPublished(0);
00194 break;
00195 default:
00196 $errors[] = array('plugins.importexport.native.import.error.invalidBooleanValue', array('value' => $value));
00197 $hasErrors = true;
00198 break;
00199 }
00200
00201 switch(($value = $issueNode->getAttribute('current'))) {
00202 case 'true':
00203 $issue->setCurrent(1);
00204 break;
00205 case 'false':
00206 case '':
00207 case null:
00208 $issue->setCurrent(0);
00209 break;
00210 default:
00211 $errors[] = array('plugins.importexport.native.import.error.invalidBooleanValue', array('value' => $value));
00212 $hasErrors = true;
00213 break;
00214 }
00215
00216 if (($value = $issueNode->getAttribute('public_id')) != '') {
00217 $anotherIssue = $issueDao->getIssueByPublicIssueId($value, $journal->getJournalId());
00218 if ($anotherIssue) {
00219 $errors[] = array('plugins.importexport.native.import.error.duplicatePublicId', array('issueTitle' => $issue->getIssueIdentification(), 'otherIssueTitle' => $anotherIssue->getIssueIdentification()));
00220 $hasErrors = true;
00221 } else {
00222 $issue->setPublicIssueId($value);
00223 }
00224 }
00225
00226
00227
00228 $node = $issueNode->getChildByName('open_access');
00229 $issue->setAccessStatus($node?OPEN_ACCESS:SUBSCRIPTION);
00230
00231 if (($node = $issueNode->getChildByName('access_date'))) {
00232 $accessDate = strtotime($node->getValue());
00233 if ($accessDate === -1) {
00234 $errors[] = array('plugins.importexport.native.import.error.invalidDate', array('value' => $node->getValue()));
00235 $hasErrors = true;
00236 } else {
00237 $issue->setOpenAccessDate($accessDate);
00238 }
00239 }
00240
00241
00242
00243
00244
00245
00246 if ($hasErrors) {
00247 $issue = null;
00248 if ($cleanupErrors) {
00249 NativeImportDom::cleanupFailure ($dependentItems);
00250 }
00251 return false;
00252 } else {
00253 if ($issue->getCurrent()) {
00254 $issueDao->updateCurrentIssue($journal->getJournalId());
00255 }
00256 $issue->setIssueId($issueDao->insertIssue($issue));
00257 $dependentItems[] = array('issue', $issue);
00258 }
00259
00260
00261
00262 for ($index = 0; ($node = $issueNode->getChildByName('cover', $index)); $index++) {
00263 if (!NativeImportDom::handleCoverNode($journal, $node, $issue, $coverErrors, $isCommandLine)) {
00264 $errors = array_merge($errors, $coverErrors);
00265 $hasErrors = true;
00266 }
00267 }
00268
00269
00270 for ($index = 0; ($node = $issueNode->getChildByName('section', $index)); $index++) {
00271 if (!NativeImportDom::handleSectionNode($journal, $node, $issue, $sectionErrors, $user, $isCommandLine, $dependentItems, $index)) {
00272 $errors = array_merge($errors, $sectionErrors);
00273 $hasErrors = true;
00274 }
00275 }
00276
00277
00278
00279
00280
00281 if ($hasErrors) {
00282 $issueDao->deleteIssue($issue);
00283 $issue = null;
00284 if ($cleanupErrors) {
00285 NativeImportDom::cleanupFailure ($dependentItems);
00286 }
00287 return false;
00288 }
00289
00290 $issueDao->updateIssue($issue);
00291 return true;
00292 }
00293
00294 function handleCoverNode(&$journal, &$coverNode, &$issue, &$errors, $isCommandLine) {
00295 $errors = array();
00296 $hasErrors = false;
00297
00298 $journalSupportedLocales = array_keys($journal->getSupportedLocaleNames());
00299 $journalPrimaryLocale = $journal->getPrimaryLocale();
00300
00301 $locale = $coverNode->getAttribute('locale');
00302 if ($locale == '') {
00303 $locale = $journalPrimaryLocale;
00304 } elseif (!in_array($locale, $journalSupportedLocales)) {
00305 $errors[] = array('plugins.importexport.native.import.error.coverLocaleUnsupported', array('issueTitle' => $issue->getIssueIdentification(), 'locale' => $locale));
00306 return false;
00307 }
00308
00309 $issue->setShowCoverPage(1, $locale);
00310
00311 if (($node = $coverNode->getChildByName('caption'))) $issue->setCoverPageDescription($node->getValue(), $locale);
00312
00313 if (($node = $coverNode->getChildByName('image'))) {
00314 import('file.PublicFileManager');
00315 $publicFileManager = &new PublicFileManager();
00316 $newName = 'cover_issue_' . $issue->getIssueId()."_{$locale}" . '.';
00317
00318 if (($href = $node->getChildByName('href'))) {
00319 $url = $href->getAttribute('src');
00320 if ($isCommandLine || NativeImportDom::isAllowedMethod($url)) {
00321 if ($isCommandLine && NativeImportDom::isRelativePath($url)) {
00322
00323 $url = PWD . '/' . $url;
00324 }
00325
00326 $originalName = basename($url);
00327 $newName .= $publicFileManager->getExtension($originalName);
00328 if (!$publicFileManager->copyJournalFile($journal->getJournalId(), $url, $newName)) {
00329 $errors[] = array('plugins.importexport.native.import.error.couldNotCopy', array('url' => $url));
00330 $hasErrors = true;
00331 }
00332 $issue->setFileName($newName, $locale);
00333 $issue->setOriginalFileName($publicFileManager->truncateFileName($originalName, 127), $locale);
00334 }
00335 }
00336 if (($embed = $node->getChildByName('embed'))) {
00337 if (($type = $embed->getAttribute('encoding')) !== 'base64') {
00338 $errors[] = array('plugins.importexport.native.import.error.unknownEncoding', array('type' => $type));
00339 $hasErrors = true;
00340 } else {
00341 $originalName = $embed->getAttribute('filename');
00342 $newName .= $publicFileManager->getExtension($originalName);
00343 $issue->setFileName($newName, $locale);
00344 $issue->setOriginalFileName($publicFileManager->truncateFileName($originalName, 127), $locale);
00345 if ($publicFileManager->writeJournalFile($journal->getJournalId(), $newName, base64_decode($embed->getValue()))===false) {
00346 $errors[] = array('plugins.importexport.native.import.error.couldNotWriteFile', array('originalName' => $originalName));
00347 $hasErrors = true;
00348 }
00349 }
00350 }
00351
00352 list($width, $height) = getimagesize($publicFileManager->getJournalFilesPath($journal->getJournalId()) . '/' . $newName);
00353 $issue->setWidth($width, $locale);
00354 $issue->setHeight($height, $locale);
00355
00356 }
00357
00358 if ($hasErrors) {
00359 return false;
00360 }
00361 return true;
00362 }
00363
00364 function isRelativePath($url) {
00365
00366 if (NativeImportDom::isAllowedMethod($url)) return false;
00367 if ($url[0] == '/') return false;
00368 return true;
00369 }
00370
00371 function isAllowedMethod($url) {
00372 $allowedPrefixes = array(
00373 'http://',
00374 'ftp://',
00375 'https://',
00376 'ftps://'
00377 );
00378 foreach ($allowedPrefixes as $prefix) {
00379 if (substr($url, 0, strlen($prefix)) === $prefix) return true;
00380 }
00381 return false;
00382 }
00383
00384 function handleSectionNode(&$journal, &$sectionNode, &$issue, &$errors, &$user, $isCommandLine, &$dependentItems, $sectionIndex = null) {
00385 $sectionDao = &DAORegistry::getDAO('SectionDAO');
00386
00387 $errors = array();
00388
00389 $journalSupportedLocales = array_keys($journal->getSupportedLocaleNames());
00390 $journalPrimaryLocale = $journal->getPrimaryLocale();
00391
00392
00393
00394
00395
00396 $titles = array();
00397 for ($index=0; ($node = $sectionNode->getChildByName('title', $index)); $index++) {
00398 $locale = $node->getAttribute('locale');
00399 if ($locale == '') {
00400 $locale = $journalPrimaryLocale;
00401 } elseif (!in_array($locale, $journalSupportedLocales)) {
00402 $errors[] = array('plugins.importexport.native.import.error.sectionTitleLocaleUnsupported', array('sectionTitle' => $node->getValue(), 'issueTitle' => $issue->getIssueIdentification(), 'locale' => $locale));
00403 return false;
00404 }
00405 $titles[$locale] = $node->getValue();
00406 }
00407 if (empty($titles)) {
00408 $errors[] = array('plugins.importexport.native.import.error.sectionTitleMissing', array('issueTitle' => $issue->getIssueIdentification()));
00409 return false;
00410 }
00411
00412 $abbrevs = array();
00413 for ($index=0; ($node = $sectionNode->getChildByName('abbrev', $index)); $index++) {
00414 $locale = $node->getAttribute('locale');
00415 if ($locale == '') {
00416 $locale = $journalPrimaryLocale;
00417 } elseif (!in_array($locale, $journalSupportedLocales)) {
00418 $errors[] = array('plugins.importexport.native.import.error.sectionAbbrevLocaleUnsupported', array('sectionAbbrev' => $node->getValue(), 'issueTitle' => $issue->getIssueIdentification(), 'locale' => $locale));
00419 return false;
00420 }
00421 $abbrevs[$locale] = $node->getValue();
00422 }
00423
00424 $identifyTypes = array();
00425 for ($index=0; ($node = $sectionNode->getChildByName('identify_type', $index)); $index++) {
00426 $locale = $node->getAttribute('locale');
00427 if ($locale == '') {
00428 $locale = $journalPrimaryLocale;
00429 } elseif (!in_array($locale, $journalSupportedLocales)) {
00430 $errors[] = array('plugins.importexport.native.import.error.sectionIdentifyTypeLocaleUnsupported', array('sectionIdentifyType' => $node->getValue(), 'issueTitle' => $issue->getIssueIdentification(), 'locale' => $locale));
00431 return false;
00432 }
00433 $identifyTypes[$locale] = $node->getValue();
00434 }
00435
00436 $policies = array();
00437 for ($index=0; ($node = $sectionNode->getChildByName('policy', $index)); $index++) {
00438 $locale = $node->getAttribute('locale');
00439 if ($locale == '') {
00440 $locale = $journalPrimaryLocale;
00441 } elseif (!in_array($locale, $journalSupportedLocales)) {
00442 $errors[] = array('plugins.importexport.native.import.error.sectionPolicyLocaleUnsupported', array('sectionPolicy' => $node->getValue(), 'issueTitle' => $issue->getIssueIdentification(), 'locale' => $locale));
00443 return false;
00444 }
00445 $policies[$locale] = $node->getValue();
00446 }
00447
00448
00449
00450
00451
00452 $section = null;
00453 $foundSectionId = $foundSectionTitle = null;
00454 $index = 0;
00455 foreach($titles as $locale => $title) {
00456 $section = $sectionDao->getSectionByTitle($title, $journal->getJournalId());
00457 if ($section) {
00458 $sectionId = $section->getSectionId();
00459 if ($foundSectionId) {
00460 if ($foundSectionId != $sectionId) {
00461
00462 $errors[] = array('plugins.importexport.native.import.error.sectionTitleMismatch', array('section1Title' => $title, 'section2Title' => $foundSectionTitle, 'issueTitle' => $issue->getIssueIdentification()));
00463 return false;
00464 }
00465 } else if ($index > 0) {
00466
00467 $errors[] = array('plugins.importexport.native.import.error.sectionTitleMatch', array('sectionTitle' => $title, 'issueTitle' => $issue->getIssueIdentification()));
00468 return false;
00469 }
00470 $foundSectionId = $sectionId;
00471 $foundSectionTitle = $title;
00472 } else {
00473 if ($foundSectionId) {
00474
00475 $errors[] = array('plugins.importexport.native.import.error.sectionTitleMatch', array('sectionTitle' => $foundSectionTitle, 'issueTitle' => $issue->getIssueIdentification()));
00476 return false;
00477 }
00478 }
00479 $index++;
00480 }
00481
00482
00483 $abbrevSection = null;
00484 $foundSectionId = $foundSectionAbbrev = null;
00485 $index = 0;
00486 foreach($abbrevs as $locale => $abbrev) {
00487 $abbrevSection = $sectionDao->getSectionByAbbrev($abbrev, $journal->getJournalId());
00488 if ($abbrevSection) {
00489 $sectionId = $abbrevSection->getSectionId();
00490 if ($foundSectionId) {
00491 if ($foundSectionId != $sectionId) {
00492
00493 $errors[] = array('plugins.importexport.native.import.error.sectionAbbrevMismatch', array('section1Abbrev' => $abbrev, 'section2Abbrev' => $foundSectionAbbrev, 'issueTitle' => $issue->getIssueIdentification()));
00494 return false;
00495 }
00496 } else if ($index > 0) {
00497
00498 $errors[] = array('plugins.importexport.native.import.error.sectionAbbrevMatch', array('sectionAbbrev' => $sectionAbbrev, 'issueTitle' => $issue->getIssueIdentification()));
00499 return false;
00500 }
00501 $foundSectionId = $sectionId;
00502 $foundSectionAbbrev = $abbrev;
00503 } else {
00504 if ($foundSectionId) {
00505
00506 $errors[] = array('plugins.importexport.native.import.error.sectionAbbrevMatch', array('sectionAbbrev' => $foundSectionAbbrev, 'issueTitle' => $issue->getIssueIdentification()));
00507 return false;
00508 }
00509 }
00510 $index++;
00511 }
00512
00513 if (!$section && !$abbrevSection) {
00514
00515
00516
00517
00518 unset($section);
00519 $section = &new Section();
00520
00521 $section->setTitle($titles, null);
00522 $section->setAbbrev($abbrevs, null);
00523 $section->setIdentifyType($identifyTypes, null);
00524 $section->setPolicy($policies, null);
00525 $section->setJournalId($journal->getJournalId());
00526 $section->setSequence(REALLY_BIG_NUMBER);
00527 $section->setMetaIndexed(1);
00528 $section->setEditorRestricted(1);
00529 $section->setSectionId($sectionDao->insertSection($section));
00530 $sectionDao->resequenceSections($journal->getJournalId());
00531 }
00532
00533 if (!$section && $abbrevSection) {
00534 unset($section);
00535 $section =& $abbrevSection;
00536 }
00537
00538
00539
00540
00541
00542 if ($sectionIndex !== null) {
00543 $sectionDao->insertCustomSectionOrder($issue->getIssueId(), $section->getSectionId(), $sectionIndex);
00544 }
00545
00546 $hasErrors = false;
00547 for ($index = 0; ($node = $sectionNode->getChildByName('article', $index)); $index++) {
00548 if (!NativeImportDom::handleArticleNode($journal, $node, $issue, $section, $article, $publishedArticle, $articleErrors, $user, $isCommandLine, $dependentItems)) {
00549 $errors = array_merge($errors, $articleErrors);
00550 $hasErrors = true;
00551 }
00552 }
00553 if ($hasErrors) return false;
00554
00555 return true;
00556 }
00557
00558 function handleArticleNode(&$journal, &$articleNode, &$issue, &$section, &$article, &$publishedArticle, &$errors, &$user, $isCommandLine, &$dependentItems) {
00559 $errors = array();
00560
00561 $journalSupportedLocales = array_keys($journal->getSupportedLocaleNames());
00562 $journalPrimaryLocale = $journal->getPrimaryLocale();
00563
00564 $publishedArticleDao = &DAORegistry::getDAO('PublishedArticleDAO');
00565 $articleDao = &DAORegistry::getDAO('ArticleDAO');
00566
00567 $article = new Article();
00568 $article->setJournalId($journal->getJournalId());
00569 $article->setUserId($user->getUserId());
00570 $article->setSectionId($section->getSectionId());
00571 $article->setStatus(STATUS_PUBLISHED);
00572 $article->setSubmissionProgress(0);
00573 $article->setDateSubmitted(Core::getCurrentDate());
00574 $article->stampStatusModified();
00575
00576 $titleExists = false;
00577 for ($index=0; ($node = $articleNode->getChildByName('title', $index)); $index++) {
00578 $locale = $node->getAttribute('locale');
00579 if ($locale == '') {
00580 $locale = $journalPrimaryLocale;
00581 } elseif (!in_array($locale, $journalSupportedLocales)) {
00582 $errors[] = array('plugins.importexport.native.import.error.articleTitleLocaleUnsupported', array('articleTitle' => $node->getValue(), 'issueTitle' => $issue->getIssueIdentification(), 'locale' => $locale));
00583 return false;
00584 }
00585 $article->setTitle($node->getValue(), $locale);
00586 $titleExists = true;
00587 }
00588 if (!$titleExists || $article->getTitle($journalPrimaryLocale) == "") {
00589 $errors[] = array('plugins.importexport.native.import.error.articleTitleMissing', array('issueTitle' => $issue->getIssueIdentification(), 'sectionTitle' => $section->getSectionTitle()));
00590 return false;
00591 }
00592
00593 for ($index=0; ($node = $articleNode->getChildByName('abstract', $index)); $index++) {
00594 $locale = $node->getAttribute('locale');
00595 if ($locale == '') {
00596 $locale = $journalPrimaryLocale;
00597 } elseif (!in_array($locale, $journalSupportedLocales)) {
00598 $errors[] = array('plugins.importexport.native.import.error.articleAbstractLocaleUnsupported', array('articleTitle' => $article->getArticleTitle(), 'issueTitle' => $issue->getIssueIdentification(), 'locale' => $locale));
00599 return false;
00600 }
00601 $article->setAbstract($node->getValue(), $locale);
00602 }
00603
00604 if (($indexingNode = $articleNode->getChildByName('indexing'))) {
00605 for ($index=0; ($node = $indexingNode->getChildByName('discipline', $index)); $index++) {
00606 $locale = $node->getAttribute('locale');
00607 if ($locale == '') {
00608 $locale = $journalPrimaryLocale;
00609 } elseif (!in_array($locale, $journalSupportedLocales)) {
00610 $errors[] = array('plugins.importexport.native.import.error.articleDisciplineLocaleUnsupported', array('articleTitle' => $article->getArticleTitle(), 'issueTitle' => $issue->getIssueIdentification(), 'locale' => $locale));
00611 return false;
00612 }
00613 $article->setDiscipline($node->getValue(), $locale);
00614 }
00615 for ($index=0; ($node = $indexingNode->getChildByName('type', $index)); $index++) {
00616 $locale = $node->getAttribute('locale');
00617 if ($locale == '') {
00618 $locale = $journalPrimaryLocale;
00619 } elseif (!in_array($locale, $journalSupportedLocales)) {
00620 $errors[] = array('plugins.importexport.native.import.error.articleTypeLocaleUnsupported', array('articleTitle' => $article->getArticleTitle(), 'issueTitle' => $issue->getIssueIdentification(), 'locale' => $locale));
00621 return false;
00622 }
00623 $article->setType($node->getValue(), $locale);
00624 }
00625 for ($index=0; ($node = $indexingNode->getChildByName('subject', $index)); $index++) {
00626 $locale = $node->getAttribute('locale');
00627 if ($locale == '') {
00628 $locale = $journalPrimaryLocale;
00629 } elseif (!in_array($locale, $journalSupportedLocales)) {
00630 $errors[] = array('plugins.importexport.native.import.error.articleSubjectLocaleUnsupported', array('articleTitle' => $article->getArticleTitle(), 'issueTitle' => $issue->getIssueIdentification(), 'locale' => $locale));
00631 return false;
00632 }
00633 $article->setSubject($node->getValue(), $locale);
00634 }
00635 for ($index=0; ($node = $indexingNode->getChildByName('subject_class', $index)); $index++) {
00636 $locale = $node->getAttribute('locale');
00637 if ($locale == '') {
00638 $locale = $journalPrimaryLocale;
00639 } elseif (!in_array($locale, $journalSupportedLocales)) {
00640 $errors[] = array('plugins.importexport.native.import.error.articleSubjectClassLocaleUnsupported', array('articleTitle' => $article->getArticleTitle(), 'issueTitle' => $issue->getIssueIdentification(), 'locale' => $locale));
00641 return false;
00642 }
00643 $article->setSubjectClass($node->getValue(), $locale);
00644 }
00645
00646 if (($coverageNode = $indexingNode->getChildByName('coverage'))) {
00647 for ($index=0; ($node = $coverageNode->getChildByName('geographical', $index)); $index++) {
00648 $locale = $node->getAttribute('locale');
00649 if ($locale == '') {
00650 $locale = $journalPrimaryLocale;
00651 } elseif (!in_array($locale, $journalSupportedLocales)) {
00652 $errors[] = array('plugins.importexport.native.import.error.articleCoverageGeoLocaleUnsupported', array('articleTitle' => $article->getArticleTitle(), 'issueTitle' => $issue->getIssueIdentification(), 'locale' => $locale));
00653 return false;
00654 }
00655 $article->setCoverageGeo($node->getValue(), $locale);
00656 }
00657 for ($index=0; ($node = $coverageNode->getChildByName('chronological', $index)); $index++) {
00658 $locale = $node->getAttribute('locale');
00659 if ($locale == '') {
00660 $locale = $journalPrimaryLocale;
00661 } elseif (!in_array($locale, $journalSupportedLocales)) {
00662 $errors[] = array('plugins.importexport.native.import.error.articleCoverageChronLocaleUnsupported', array('articleTitle' => $article->getArticleTitle(), 'issueTitle' => $issue->getIssueIdentification(), 'locale' => $locale));
00663 return false;
00664 }
00665 $article->setCoverageChron($node->getValue(), $locale);
00666 }
00667 for ($index=0; ($node = $coverageNode->getChildByName('sample', $index)); $index++) {
00668 $locale = $node->getAttribute('locale');
00669 if ($locale == '') {
00670 $locale = $journalPrimaryLocale;
00671 } elseif (!in_array($locale, $journalSupportedLocales)) {
00672 $errors[] = array('plugins.importexport.native.import.error.articleCoverageSampleLocaleUnsupported', array('articleTitle' => $article->getArticleTitle(), 'issueTitle' => $issue->getIssueIdentification(), 'locale' => $locale));
00673 return false;
00674 }
00675 $article->setCoverageSample($node->getValue(), $locale);
00676 }
00677 }
00678 }
00679
00680 for ($index=0; ($node = $articleNode->getChildByName('sponsor', $index)); $index++) {
00681 $locale = $node->getAttribute('locale');
00682 if ($locale == '') {
00683 $locale = $journalPrimaryLocale;
00684 } elseif (!in_array($locale, $journalSupportedLocales)) {
00685 $errors[] = array('plugins.importexport.native.import.error.articleSponsorLocaleUnsupported', array('articleTitle' => $article->getArticleTitle(), 'issueTitle' => $issue->getIssueIdentification(), 'locale' => $locale));
00686 return false;
00687 }
00688 $article->setSponsor($node->getValue(), $locale);
00689 }
00690
00691 if (($node = $articleNode->getChildByName('pages'))) $article->setPages($node->getValue());
00692 if (($language = $articleNode->getAttribute('language'))) $article->setLanguage($language);
00693
00694
00695 $hasErrors = false;
00696 for ($index = 0; ($node = $articleNode->getChildByName('author', $index)); $index++) {
00697 if (!NativeImportDom::handleAuthorNode($journal, $node, $issue, $section, $article, $authorErrors)) {
00698 $errors = array_merge($errors, $authorErrors);
00699 $hasErrors = true;
00700 }
00701 }
00702 if ($hasErrors) return false;
00703
00704 $articleDao->insertArticle($article);
00705 $dependentItems[] = array('article', $article);
00706
00707
00708 $copyeditorSubmissionDao = &DAORegistry::getDAO('CopyeditorSubmissionDAO');
00709 $copyeditorSubmission = &new CopyeditorSubmission();
00710 $copyeditorSubmission->setArticleId($article->getArticleId());
00711 $copyeditorSubmission->setCopyeditorId(0);
00712 $copyeditorSubmissionDao->insertCopyeditorSubmission($copyeditorSubmission);
00713
00714 $layoutDao = &DAORegistry::getDAO('LayoutAssignmentDAO');
00715 $layoutAssignment = &new LayoutAssignment();
00716 $layoutAssignment->setArticleId($article->getArticleId());
00717 $layoutAssignment->setEditorId(0);
00718 $layoutAssignment->setDateAcknowledged(Core::getCurrentDate());
00719 $layoutDao->insertLayoutAssignment($layoutAssignment);
00720
00721 $proofAssignmentDao = &DAORegistry::getDAO('ProofAssignmentDAO');
00722 $proofAssignment = &new ProofAssignment();
00723 $proofAssignment->setArticleId($article->getArticleId());
00724 $proofAssignment->setProofreaderId(0);
00725 $proofAssignmentDao->insertProofAssignment($proofAssignment);
00726
00727
00728 import('article.log.ArticleLog');
00729 import('article.log.ArticleEventLogEntry');
00730 ArticleLog::logEvent(
00731 $article->getArticleId(),
00732 ARTICLE_LOG_ARTICLE_IMPORT,
00733 ARTICLE_LOG_TYPE_DEFAULT,
00734 0,
00735 'log.imported',
00736 array('userName' => $user->getFullName(), 'articleId' => $article->getArticleId())
00737 );
00738
00739
00740 $publishedArticle = &new PublishedArticle();
00741 $publishedArticle->setArticleId($article->getArticleId());
00742 $publishedArticle->setIssueId($issue->getIssueId());
00743
00744 if (($node = $articleNode->getChildByName('date_published'))) {
00745 $publishedDate = strtotime($node->getValue());
00746 if ($publishedDate === -1) {
00747 $errors[] = array('plugins.importexport.native.import.error.invalidDate', array('value' => $node->getValue()));
00748 return false;
00749 } else {
00750 $publishedArticle->setDatePublished($publishedDate);
00751 }
00752 }
00753 $node = $articleNode->getChildByName('open_access');
00754 $publishedArticle->setAccessStatus($node?1:0);
00755 $publishedArticle->setSeq(REALLY_BIG_NUMBER);
00756 $publishedArticle->setViews(0);
00757 $publishedArticle->setPublicArticleId($articleNode->getAttribute('public_id'));
00758
00759 $publishedArticle->setPubId($publishedArticleDao->insertPublishedArticle($publishedArticle));
00760
00761 $publishedArticleDao->resequencePublishedArticles($section->getSectionId(), $issue->getIssueId());
00762
00763
00764 import('file.ArticleFileManager');
00765 $articleFileManager = &new ArticleFileManager($article->getArticleId());
00766
00767
00768 $hasErrors = false;
00769 $galleyCount = 0;
00770 for ($index=0; $index < count($articleNode->children); $index++) {
00771 $node = &$articleNode->children[$index];
00772
00773 if ($node->getName() == 'htmlgalley') $isHtml = true;
00774 elseif ($node->getName() == 'galley') $isHtml = false;
00775 else continue;
00776
00777 if (!NativeImportDom::handleGalleyNode($journal, $node, $issue, $section, $article, $galleyErrors, $isCommandLine, $isHtml, $galleyCount, $articleFileManager)) {
00778 $errors = array_merge($errors, $galleyErrors);
00779 $hasErrors = true;
00780 }
00781 $galleyCount++;
00782 }
00783 if ($hasErrors) return false;
00784
00785
00786 $hasErrors = false;
00787 for ($index = 0; ($node = $articleNode->getChildByName('supplemental_file', $index)); $index++) {
00788 if (!NativeImportDom::handleSuppFileNode($journal, $node, $issue, $section, $article, $suppFileErrors, $isCommandLine, $articleFileManager)) {
00789 $errors = array_merge($errors, $suppFileErrors);
00790 $hasErrors = true;
00791 }
00792 }
00793 if ($hasErrors) return false;
00794
00795
00796 import('search.ArticleSearchIndex');
00797 ArticleSearchIndex::indexArticleMetadata($article);
00798 ArticleSearchIndex::indexArticleFiles($article);
00799
00800 return true;
00801 }
00802
00803 function handleAuthorNode(&$journal, &$authorNode, &$issue, &$section, &$article, &$errors) {
00804 $errors = array();
00805
00806 $journalSupportedLocales = array_keys($journal->getSupportedLocaleNames());
00807 $journalPrimaryLocale = $journal->getPrimaryLocale();
00808
00809 $author = &new Author();
00810 if (($node = $authorNode->getChildByName('firstname'))) $author->setFirstName($node->getValue());
00811 if (($node = $authorNode->getChildByName('middlename'))) $author->setMiddleName($node->getValue());
00812 if (($node = $authorNode->getChildByName('lastname'))) $author->setLastName($node->getValue());
00813 if (($node = $authorNode->getChildByName('affiliation'))) $author->setAffiliation($node->getValue());
00814 if (($node = $authorNode->getChildByName('country'))) $author->setCountry($node->getValue());
00815 if (($node = $authorNode->getChildByName('email'))) $author->setEmail($node->getValue());
00816 if (($node = $authorNode->getChildByName('url'))) $author->setUrl($node->getValue());
00817 for ($index=0; ($node = $authorNode->getChildByName('competing_interests', $index)); $index++) {
00818 $locale = $node->getAttribute('locale');
00819 if ($locale == '') {
00820 $locale = $journalPrimaryLocale;
00821 } elseif (!in_array($locale, $journalSupportedLocales)) {
00822 $errors[] = array('plugins.importexport.native.import.error.articleAuthorCompetingInterestsLocaleUnsupported', array('authorFullName' => $author->getFullName(), 'articleTitle' => $article->getArticleTitle(), 'issueTitle' => $issue->getIssueIdentification(), 'locale' => $locale));
00823 return false;
00824 }
00825 $author->setCompetingInterests($node->getValue(), $locale);
00826 }
00827 for ($index=0; ($node = $authorNode->getChildByName('biography', $index)); $index++) {
00828 $locale = $node->getAttribute('locale');
00829 if ($locale == '') {
00830 $locale = $journalPrimaryLocale;
00831 } elseif (!in_array($locale, $journalSupportedLocales)) {
00832 $errors[] = array('plugins.importexport.native.import.error.articleAuthorBiographyLocaleUnsupported', array('authorFullName' => $author->getFullName(), 'articleTitle' => $article->getArticleTitle(), 'issueTitle' => $issue->getIssueIdentification(), 'locale' => $locale));
00833 return false;
00834 }
00835 $author->setBiography($node->getValue(), $locale);
00836 }
00837
00838 $author->setPrimaryContact($authorNode->getAttribute('primary_contact')==='true'?1:0);
00839 $article->addAuthor($author);
00840
00841 return true;
00842
00843 }
00844
00845 function handleGalleyNode(&$journal, &$galleyNode, &$issue, &$section, &$article, &$errors, $isCommandLine, $isHtml, $galleyCount, &$articleFileManager) {
00846 $errors = array();
00847
00848 $journalSupportedLocales = array_keys($journal->getSupportedLocaleNames());
00849 $journalPrimaryLocale = $journal->getPrimaryLocale();
00850
00851 $galleyDao = &DAORegistry::getDAO('ArticleGalleyDAO');
00852
00853 if ($isHtml) $galley = &new ArticleHtmlGalley();
00854 else $galley = &new ArticleGalley();
00855
00856 $galley->setArticleId($article->getArticleId());
00857 $galley->setSequence($galleyCount);
00858
00859
00860 $locale = $galleyNode->getAttribute('locale');
00861 if ($locale == '') {
00862 $locale = $journalPrimaryLocale;
00863 } elseif (!in_array($locale, $journalSupportedLocales)) {
00864 $errors[] = array('plugins.importexport.native.import.error.galleyLocaleUnsupported', array('articleTitle' => $article->getArticleTitle(), 'issueTitle' => $issue->getIssueIdentification(), 'locale' => $locale));
00865 return false;
00866 }
00867 $galley->setLocale($locale);
00868
00869
00870 if (!($node = $galleyNode->getChildByName('label'))) {
00871 $errors[] = array('plugins.importexport.native.import.error.galleyLabelMissing', array('articleTitle' => $article->getArticleTitle(), 'sectionTitle' => $section->getSectionTitle(), 'issueTitle' => $issue->getIssueIdentification()));
00872 return false;
00873 }
00874 $galley->setLabel($node->getValue());
00875
00876
00877 if (!($node = $galleyNode->getChildByName('file'))) {
00878 $errors[] = array('plugins.importexport.native.import.error.galleyFileMissing', array('articleTitle' => $article->getArticleTitle(), 'sectionTitle' => $section->getSectionTitle(), 'issueTitle' => $issue->getIssueIdentification()));
00879 return false;
00880 }
00881
00882 if (($href = $node->getChildByName('href'))) {
00883 $url = $href->getAttribute('src');
00884 if ($isCommandLine || NativeImportDom::isAllowedMethod($url)) {
00885 if ($isCommandLine && NativeImportDom::isRelativePath($url)) {
00886
00887 $url = PWD . '/' . $url;
00888 }
00889
00890 if (($fileId = $articleFileManager->copyPublicFile($url, $href->getAttribute('mime_type')))===false) {
00891 $errors[] = array('plugins.importexport.native.import.error.couldNotCopy', array('url' => $url));
00892 return false;
00893 }
00894 }
00895 }
00896 if (($embed = $node->getChildByName('embed'))) {
00897 if (($type = $embed->getAttribute('encoding')) !== 'base64') {
00898 $errors[] = array('plugins.importexport.native.import.error.unknownEncoding', array('type' => $type));
00899 return false;
00900 }
00901 $originalName = $embed->getAttribute('filename');
00902 if (($fileId = $articleFileManager->writePublicFile($originalName, base64_decode($embed->getValue()), $embed->getAttribute('mime_type')))===false) {
00903 $errors[] = array('plugins.importexport.native.import.error.couldNotWriteFile', array('originalName' => $originalName));
00904 return false;
00905 }
00906 }
00907 if (!isset($fileId)) {
00908 $errors[] = array('plugins.importexport.native.import.error.galleyFileMissing', array('articleTitle' => $article->getArticleTitle(), 'sectionTitle' => $section->getSectionTitle(), 'issueTitle' => $issue->getIssueIdentification()));
00909 return false;
00910 }
00911 $galley->setFileId($fileId);
00912 $galleyDao->insertGalley($galley);
00913
00914 if ($isHtml) {
00915 $result = NativeImportDom::handleHtmlGalleyNodes($galleyNode, $articleFileManager, $galley, $errors, $isCommandLine);
00916 if (!$result) return false;
00917 }
00918
00919 return true;
00920
00921 }
00922
00928 function handleHtmlGalleyNodes(&$galleyNode, &$articleFileManager, &$galley, &$errors, &$isCommandLine) {
00929 $articleGalleyDao = &DAORegistry::getDAO('ArticleGalleyDAO');
00930
00931 foreach ($galleyNode->children as $node) {
00932 $isStylesheet = ($node->getName() == 'stylesheet');
00933 $isImage = ($node->getName() == 'image');
00934 if (!$isStylesheet && !$isImage) continue;
00935
00936 if (($href = $node->getChildByName('href'))) {
00937 $url = $href->getAttribute('src');
00938 if ($isCommandLine || NativeImportDom::isAllowedMethod($url)) {
00939 if ($isCommandLine && NativeImportDom::isRelativePath($url)) {
00940
00941 $url = PWD . '/' . $url;
00942 }
00943
00944 if (($fileId = $articleFileManager->copyPublicFile($url, $href->getAttribute('mime_type')))===false) {
00945 $errors[] = array('plugins.importexport.native.import.error.couldNotCopy', array('url' => $url));
00946 return false;
00947 }
00948 }
00949 }
00950 if (($embed = $node->getChildByName('embed'))) {
00951 if (($type = $embed->getAttribute('encoding')) !== 'base64') {
00952 $errors[] = array('plugins.importexport.native.import.error.unknownEncoding', array('type' => $type));
00953 return false;
00954 }
00955 $originalName = $embed->getAttribute('filename');
00956 if (($fileId = $articleFileManager->writePublicFile($originalName, base64_decode($embed->getValue()), $embed->getAttribute('mime_type')))===false) {
00957 $errors[] = array('plugins.importexport.native.import.error.couldNotWriteFile', array('originalName' => $originalName));
00958 return false;
00959 }
00960 }
00961
00962 if (!isset($fileId)) continue;
00963
00964 if ($isStylesheet) {
00965 $galley->setStyleFileId($fileId);
00966 $articleGalleyDao->updateGalley($galley);
00967 } else {
00968 $articleGalleyDao->insertGalleyImage($galley->getGalleyId(), $fileId);
00969 }
00970 }
00971 return true;
00972 }
00973
00974 function handleSuppFileNode(&$journal, &$suppNode, &$issue, &$section, &$article, &$errors, $isCommandLine, &$articleFileManager) {
00975 $errors = array();
00976
00977 $journalSupportedLocales = array_keys($journal->getSupportedLocaleNames());
00978 $journalPrimaryLocale = $journal->getPrimaryLocale();
00979
00980 $suppFileDao = &DAORegistry::getDAO('SuppFileDAO');
00981
00982 $suppFile = &new SuppFile();
00983 $suppFile->setArticleId($article->getArticleId());
00984
00985 for ($index=0; ($node = $suppNode->getChildByName('title', $index)); $index++) {
00986 $locale = $node->getAttribute('locale');
00987 if ($locale == '') {
00988 $locale = $journalPrimaryLocale;
00989 } elseif (!in_array($locale, $journalSupportedLocales)) {
00990 $errors[] = array('plugins.importexport.native.import.error.articleSuppFileTitleLocaleUnsupported', array('suppFileTitle' => $node->getValue(), 'articleTitle' => $article->getArticleTitle(), 'issueTitle' => $issue->getIssueIdentification(), 'locale' => $locale));
00991 return false;
00992 }
00993 $suppFile->setTitle($node->getValue(), $locale);
00994 }
00995 for ($index=0; ($node = $suppNode->getChildByName('creator', $index)); $index++) {
00996 $locale = $node->getAttribute('locale');
00997 if ($locale == '') {
00998 $locale = $journalPrimaryLocale;
00999 } elseif (!in_array($locale, $journalSupportedLocales)) {
01000 $errors[] = array('plugins.importexport.native.import.error.articleSuppFileCreatorLocaleUnsupported', array('suppFileTitle' => $node->getValue(), 'articleTitle' => $article->getArticleTitle(), 'issueTitle' => $issue->getIssueIdentification(), 'locale' => $locale));
01001 return false;
01002 }
01003 $suppFile->setCreator($node->getValue(), $locale);
01004 }
01005 for ($index=0; ($node = $suppNode->getChildByName('subject', $index)); $index++) {
01006 $locale = $node->getAttribute('locale');
01007 if ($locale == '') {
01008 $locale = $journalPrimaryLocale;
01009 } elseif (!in_array($locale, $journalSupportedLocales)) {
01010 $errors[] = array('plugins.importexport.native.import.error.articleSuppFileSubjectLocaleUnsupported', array('suppFileTitle' => $node->getValue(), 'articleTitle' => $article->getArticleTitle(), 'issueTitle' => $issue->getIssueIdentification(), 'locale' => $locale));
01011 return false;
01012 }
01013 $suppFile->setSubject($node->getValue(), $locale);
01014 }
01015 for ($index=0; ($node = $suppNode->getChildByName('type_other', $index)); $index++) {
01016 $locale = $node->getAttribute('locale');
01017 if ($locale == '') {
01018 $locale = $journalPrimaryLocale;
01019 } elseif (!in_array($locale, $journalSupportedLocales)) {
01020 $errors[] = array('plugins.importexport.native.import.error.articleSuppFileTypeOtherLocaleUnsupported', array('suppFileTitle' => $node->getValue(), 'articleTitle' => $article->getArticleTitle(), 'issueTitle' => $issue->getIssueIdentification(), 'locale' => $locale));
01021 return false;
01022 }
01023 $suppFile->setTypeOther($node->getValue(), $locale);
01024 }
01025 for ($index=0; ($node = $suppNode->getChildByName('description', $index)); $index++) {
01026 $locale = $node->getAttribute('locale');
01027 if ($locale == '') {
01028 $locale = $journalPrimaryLocale;
01029 } elseif (!in_array($locale, $journalSupportedLocales)) {
01030 $errors[] = array('plugins.importexport.native.import.error.articleSuppFileDescriptionLocaleUnsupported', array('suppFileTitle' => $node->getValue(), 'articleTitle' => $article->getArticleTitle(), 'issueTitle' => $issue->getIssueIdentification(), 'locale' => $locale));
01031 return false;
01032 }
01033 $suppFile->setDescription($node->getValue(), $locale);
01034 }
01035 for ($index=0; ($node = $suppNode->getChildByName('publisher', $index)); $index++) {
01036 $locale = $node->getAttribute('locale');
01037 if ($locale == '') {
01038 $locale = $journalPrimaryLocale;
01039 } elseif (!in_array($locale, $journalSupportedLocales)) {
01040 $errors[] = array('plugins.importexport.native.import.error.articleSuppFilePublisherLocaleUnsupported', array('suppFileTitle' => $node->getValue(), 'articleTitle' => $article->getArticleTitle(), 'issueTitle' => $issue->getIssueIdentification(), 'locale' => $locale));
01041 return false;
01042 }
01043 $suppFile->setPublisher($node->getValue(), $locale);
01044 }
01045 for ($index=0; ($node = $suppNode->getChildByName('sponsor', $index)); $index++) {
01046 $locale = $node->getAttribute('locale');
01047 if ($locale == '') {
01048 $locale = $journalPrimaryLocale;
01049 } elseif (!in_array($locale, $journalSupportedLocales)) {
01050 $errors[] = array('plugins.importexport.native.import.error.articleSuppFileSponsorLocaleUnsupported', array('suppFileTitle' => $node->getValue(), 'articleTitle' => $article->getArticleTitle(), 'issueTitle' => $issue->getIssueIdentification(), 'locale' => $locale));
01051 return false;
01052 }
01053 $suppFile->setSponsor($node->getValue(), $locale);
01054 }
01055 for ($index=0; ($node = $suppNode->getChildByName('source', $index)); $index++) {
01056 $locale = $node->getAttribute('locale');
01057 if ($locale == '') {
01058 $locale = $journalPrimaryLocale;
01059 } elseif (!in_array($locale, $journalSupportedLocales)) {
01060 $errors[] = array('plugins.importexport.native.import.error.articleSuppFileSourceLocaleUnsupported', array('suppFileTitle' => $node->getValue(), 'articleTitle' => $article->getArticleTitle(), 'issueTitle' => $issue->getIssueIdentification(), 'locale' => $locale));
01061 return false;
01062 }
01063 $suppFile->setSource($node->getValue(), $locale);
01064 }
01065 if (($node = $suppNode->getChildByName('date_created'))) {
01066 $createdDate = strtotime($node->getValue());
01067 if ($createdDate !== -1) $suppFile->setDateCreated($createdDate);
01068 }
01069
01070 switch (($suppType = $suppNode->getAttribute('type'))) {
01071 case 'research_instrument': $suppFile->setType(Locale::translate('author.submit.suppFile.researchInstrument')); break;
01072 case 'research_materials': $suppFile->setType(Locale::translate('author.submit.suppFile.researchMaterials')); break;
01073 case 'research_results': $suppFile->setType(Locale::translate('author.submit.suppFile.researchResults')); break;
01074 case 'transcripts': $suppFile->setType(Locale::translate('author.submit.suppFile.transcripts')); break;
01075 case 'data_analysis': $suppFile->setType(Locale::translate('author.submit.suppFile.dataAnalysis')); break;
01076 case 'data_set': $suppFile->setType(Locale::translate('author.submit.suppFile.dataSet')); break;
01077 case 'source_text': $suppFile->setType(Locale::translate('author.submit.suppFile.sourceText')); break;
01078 case 'other': $suppFile->setType(''); break;
01079 default:
01080 $errors[] = array('plugins.importexport.native.import.error.unknownSuppFileType', array('suppFileType' => $suppType));
01081 return false;
01082 }
01083
01084 $suppFile->setLanguage($suppNode->getAttribute('language'));
01085 $suppFile->setPublicSuppFileId($suppNode->getAttribute('public_id'));
01086
01087 if (!($fileNode = $suppNode->getChildByName('file'))) {
01088 $errors[] = array('plugins.importexport.native.import.error.suppFileMissing', array('articleTitle' => $article->getArticleTitle(), 'sectionTitle' => $section->getSectionTitle(), 'issueTitle' => $issue->getIssueIdentification()));
01089 return false;
01090 }
01091
01092 if (($href = $fileNode->getChildByName('href'))) {
01093 $url = $href->getAttribute('src');
01094 if ($isCommandLine || NativeImportDom::isAllowedMethod($url)) {
01095 if ($isCommandLine && NativeImportDom::isRelativePath($url)) {
01096
01097 $url = PWD . '/' . $url;
01098 }
01099
01100 if (($fileId = $articleFileManager->copySuppFile($url, $href->getAttribute('mime_type')))===false) {
01101 $errors[] = array('plugins.importexport.native.import.error.couldNotCopy', array('url' => $url));
01102 return false;
01103 }
01104 }
01105 }
01106 if (($embed = $fileNode->getChildByName('embed'))) {
01107 if (($type = $embed->getAttribute('encoding')) !== 'base64') {
01108 $errors[] = array('plugins.importexport.native.import.error.unknownEncoding', array('type' => $type));
01109 return false;
01110 }
01111 $originalName = $embed->getAttribute('filename');
01112 if (($fileId = $articleFileManager->writeSuppFile($originalName, base64_decode($embed->getValue()), $embed->getAttribute('mime_type')))===false) {
01113 $errors[] = array('plugins.importexport.native.import.error.couldNotWriteFile', array('originalName' => $originalName));
01114 return false;
01115 }
01116 }
01117
01118 if (!$fileId) {
01119 $errors[] = array('plugins.importexport.native.import.error.suppFileMissing', array('articleTitle' => $article->getArticleTitle(), 'sectionTitle' => $section->getSectionTitle(), 'issueTitle' => $issue->getIssueIdentification()));
01120 return false;
01121 }
01122
01123 $suppFile->setFileId($fileId);
01124 $suppFileDao->insertSuppFile($suppFile);
01125
01126 return true;
01127
01128 }
01129
01130 function cleanupFailure (&$dependentItems) {
01131 $issueDao = &DAORegistry::getDAO('IssueDAO');
01132 $articleDao = &DAORegistry::getDAO('ArticleDAO');
01133
01134 foreach ($dependentItems as $dependentItem) {
01135 $type = array_shift($dependentItem);
01136 $object = array_shift($dependentItem);
01137
01138 switch ($type) {
01139 case 'issue':
01140 $issueDao->deleteIssue($object);
01141 break;
01142 case 'article':
01143 $articleDao->deleteArticle($object);
01144 break;
01145 default:
01146 fatalError ('cleanupFailure: Unimplemented type');
01147 }
01148 }
01149 }
01150 }
01151
01152 ?>