コード例 #1
0
 function handleSuppFileNode(&$journal, &$suppNode, &$issue, &$section, &$article, &$errors, $isCommandLine, &$articleFileManager)
 {
     $errors = array();
     $journalSupportedLocales = array_keys($journal->getSupportedLocaleNames());
     // => journal locales must be set up before
     $suppFileDao =& DAORegistry::getDAO('SuppFileDAO');
     $suppFile = new SuppFile();
     $suppFile->setArticleId($article->getId());
     /* --- Set IDs --- */
     if (!NativeImportDom::handlePubIds($suppNode, $suppFile, $journal, $issue, $article, $errors)) {
         return false;
     }
     for ($index = 0; $node = $suppNode->getChildByName('title', $index); $index++) {
         $locale = $node->getAttribute('locale');
         if ($locale == '') {
             $locale = $article->getLocale();
         } elseif (!in_array($locale, $journalSupportedLocales)) {
             $errors[] = array('plugins.importexport.native.import.error.articleSuppFileTitleLocaleUnsupported', array('suppFileTitle' => $node->getValue(), 'articleTitle' => $article->getLocalizedTitle(), 'issueTitle' => $issue->getIssueIdentification(), 'locale' => $locale));
             return false;
         }
         $suppFile->setTitle($node->getValue(), $locale);
     }
     for ($index = 0; $node = $suppNode->getChildByName('creator', $index); $index++) {
         $locale = $node->getAttribute('locale');
         if ($locale == '') {
             $locale = $article->getLocale();
         } elseif (!in_array($locale, $journalSupportedLocales)) {
             $errors[] = array('plugins.importexport.native.import.error.articleSuppFileCreatorLocaleUnsupported', array('suppFileTitle' => $node->getValue(), 'articleTitle' => $article->getLocalizedTitle(), 'issueTitle' => $issue->getIssueIdentification(), 'locale' => $locale));
             return false;
         }
         $suppFile->setCreator($node->getValue(), $locale);
     }
     for ($index = 0; $node = $suppNode->getChildByName('subject', $index); $index++) {
         $locale = $node->getAttribute('locale');
         if ($locale == '') {
             $locale = $article->getLocale();
         } elseif (!in_array($locale, $journalSupportedLocales)) {
             $errors[] = array('plugins.importexport.native.import.error.articleSuppFileSubjectLocaleUnsupported', array('suppFileTitle' => $node->getValue(), 'articleTitle' => $article->getLocalizedTitle(), 'issueTitle' => $issue->getIssueIdentification(), 'locale' => $locale));
             return false;
         }
         $suppFile->setSubject($node->getValue(), $locale);
     }
     for ($index = 0; $node = $suppNode->getChildByName('type_other', $index); $index++) {
         $locale = $node->getAttribute('locale');
         if ($locale == '') {
             $locale = $article->getLocale();
         } elseif (!in_array($locale, $journalSupportedLocales)) {
             $errors[] = array('plugins.importexport.native.import.error.articleSuppFileTypeOtherLocaleUnsupported', array('suppFileTitle' => $node->getValue(), 'articleTitle' => $article->getLocalizedTitle(), 'issueTitle' => $issue->getIssueIdentification(), 'locale' => $locale));
             return false;
         }
         $suppFile->setTypeOther($node->getValue(), $locale);
     }
     for ($index = 0; $node = $suppNode->getChildByName('description', $index); $index++) {
         $locale = $node->getAttribute('locale');
         if ($locale == '') {
             $locale = $article->getLocale();
         } elseif (!in_array($locale, $journalSupportedLocales)) {
             $errors[] = array('plugins.importexport.native.import.error.articleSuppFileDescriptionLocaleUnsupported', array('suppFileTitle' => $node->getValue(), 'articleTitle' => $article->getLocalizedTitle(), 'issueTitle' => $issue->getIssueIdentification(), 'locale' => $locale));
             return false;
         }
         $suppFile->setDescription($node->getValue(), $locale);
     }
     for ($index = 0; $node = $suppNode->getChildByName('publisher', $index); $index++) {
         $locale = $node->getAttribute('locale');
         if ($locale == '') {
             $locale = $article->getLocale();
         } elseif (!in_array($locale, $journalSupportedLocales)) {
             $errors[] = array('plugins.importexport.native.import.error.articleSuppFilePublisherLocaleUnsupported', array('suppFileTitle' => $node->getValue(), 'articleTitle' => $article->getLocalizedTitle(), 'issueTitle' => $issue->getIssueIdentification(), 'locale' => $locale));
             return false;
         }
         $suppFile->setPublisher($node->getValue(), $locale);
     }
     for ($index = 0; $node = $suppNode->getChildByName('sponsor', $index); $index++) {
         $locale = $node->getAttribute('locale');
         if ($locale == '') {
             $locale = $article->getLocale();
         } elseif (!in_array($locale, $journalSupportedLocales)) {
             $errors[] = array('plugins.importexport.native.import.error.articleSuppFileSponsorLocaleUnsupported', array('suppFileTitle' => $node->getValue(), 'articleTitle' => $article->getLocalizedTitle(), 'issueTitle' => $issue->getIssueIdentification(), 'locale' => $locale));
             return false;
         }
         $suppFile->setSponsor($node->getValue(), $locale);
     }
     for ($index = 0; $node = $suppNode->getChildByName('source', $index); $index++) {
         $locale = $node->getAttribute('locale');
         if ($locale == '') {
             $locale = $article->getLocale();
         } elseif (!in_array($locale, $journalSupportedLocales)) {
             $errors[] = array('plugins.importexport.native.import.error.articleSuppFileSourceLocaleUnsupported', array('suppFileTitle' => $node->getValue(), 'articleTitle' => $article->getLocalizedTitle(), 'issueTitle' => $issue->getIssueIdentification(), 'locale' => $locale));
             return false;
         }
         $suppFile->setSource($node->getValue(), $locale);
     }
     if ($node = $suppNode->getChildByName('date_created')) {
         $createdDate = strtotime($node->getValue());
         if ($createdDate !== -1) {
             $suppFile->setDateCreated($createdDate);
         }
     }
     switch ($suppType = $suppNode->getAttribute('type')) {
         case 'research_instrument':
             $suppFile->setType(__('author.submit.suppFile.researchInstrument'));
             break;
         case 'research_materials':
             $suppFile->setType(__('author.submit.suppFile.researchMaterials'));
             break;
         case 'research_results':
             $suppFile->setType(__('author.submit.suppFile.researchResults'));
             break;
         case 'transcripts':
             $suppFile->setType(__('author.submit.suppFile.transcripts'));
             break;
         case 'data_analysis':
             $suppFile->setType(__('author.submit.suppFile.dataAnalysis'));
             break;
         case 'data_set':
             $suppFile->setType(__('author.submit.suppFile.dataSet'));
             break;
         case 'source_text':
             $suppFile->setType(__('author.submit.suppFile.sourceText'));
             break;
         case 'other':
             $suppFile->setType('');
             break;
         default:
             $errors[] = array('plugins.importexport.native.import.error.unknownSuppFileType', array('suppFileType' => $suppType));
             return false;
     }
     $suppFile->setShowReviewers($suppNode->getAttribute('show_reviewers') == 'true');
     $suppFile->setLanguage($suppNode->getAttribute('language'));
     if (($value = $suppNode->getAttribute('public_id')) != '') {
         $anotherSuppFile = $suppFileDao->getSuppFileByPubId('publisher-id', $value, $article->getId());
         if ($anotherSuppFile) {
             $errors[] = array('plugins.importexport.native.import.error.duplicatePublicSuppFileId', array('suppFileTitle' => $suppFile->getLocalizedTitle(), 'otherSuppFileTitle' => $anotherSuppFile->getLocalizedTitle()));
             $hasErrors = true;
         } else {
             $suppFile->setStoredPubId('publisher-id', $value);
         }
     }
     if (!($fileNode = $suppNode->getChildByName('file'))) {
         $errors[] = array('plugins.importexport.native.import.error.suppFileMissing', array('articleTitle' => $article->getLocalizedTitle(), 'sectionTitle' => $section->getLocalizedTitle(), 'issueTitle' => $issue->getIssueIdentification()));
         return false;
     }
     if ($href = $fileNode->getChildByName('href')) {
         $url = $href->getAttribute('src');
         if ($isCommandLine || NativeImportDom::isAllowedMethod($url)) {
             if ($isCommandLine && NativeImportDom::isRelativePath($url)) {
                 // The command-line tool does a chdir; we need to prepend the original pathname to relative paths so we're not looking in the wrong place.
                 $url = PWD . '/' . $url;
             }
             if (($fileId = $articleFileManager->copySuppFile($url, $href->getAttribute('mime_type'))) === false) {
                 $errors[] = array('plugins.importexport.native.import.error.couldNotCopy', array('url' => $url));
                 return false;
             }
         }
     }
     if ($embed = $fileNode->getChildByName('embed')) {
         if (($type = $embed->getAttribute('encoding')) !== 'base64') {
             $errors[] = array('plugins.importexport.native.import.error.unknownEncoding', array('type' => $type));
             return false;
         }
         $originalName = $embed->getAttribute('filename');
         if (($fileId = $articleFileManager->writeSuppFile($originalName, base64_decode($embed->getValue()), $embed->getAttribute('mime_type'))) === false) {
             $errors[] = array('plugins.importexport.native.import.error.couldNotWriteFile', array('originalName' => $originalName));
             return false;
         }
     }
     if (!$fileId) {
         $errors[] = array('plugins.importexport.native.import.error.suppFileMissing', array('articleTitle' => $article->getLocalizedTitle(), 'sectionTitle' => $section->getLocalizedTitle(), 'issueTitle' => $issue->getIssueIdentification()));
         return false;
     }
     $suppFile->setFileId($fileId);
     $suppFileDao->insertSuppFile($suppFile);
     return true;
 }