00001 <?php
00002
00015
00016
00017 import('xml.XMLCustomWriter');
00018
00019 class NativeImportDom {
00020 function importPapers(&$conference, &$schedConf, &$nodes, &$track, &$papers, &$errors, &$user, $isCommandLine) {
00021 $papers = array();
00022 $dependentItems = array();
00023 $hasErrors = false;
00024 foreach ($nodes as $node) {
00025 $result = NativeImportDom::handlePaperNode($conference, $schedConf, $node, $track, $paper, $publishedPaper, $paperErrors, $user, $isCommandLine, $dependentItems);
00026 if ($result) {
00027 $papers[] = $paper;
00028 } else {
00029 $errors = array_merge($errors, $paperErrors);
00030 $hasErrors = true;
00031 }
00032 }
00033 if ($hasErrors) {
00034 NativeImportDom::cleanupFailure ($dependentItems);
00035 return false;
00036 }
00037 return true;
00038 }
00039
00040 function importPaper(&$conference, &$schedConf, &$node, &$track, &$paper, &$errors, &$user, $isCommandLine) {
00041 $dependentItems = array();
00042 $result = NativeImportDom::handlePaperNode($conference, $schedConf, $node, $track, $paper, $publishedPaper, $errors, $user, $isCommandLine, $dependentItems);
00043 if (!$result) {
00044 NativeImportDom::cleanupFailure ($dependentItems);
00045 }
00046 return $result;
00047 }
00048
00049 function isRelativePath($url) {
00050
00051 if (NativeImportDom::isAllowedMethod($url)) return false;
00052 if ($url[0] == '/') return false;
00053 return true;
00054 }
00055
00056 function isAllowedMethod($url) {
00057 $allowedPrefixes = array(
00058 'http:
00059 'ftp:
00060 'https:
00061 'ftps:
00062 );
00063 foreach ($allowedPrefixes as $prefix) {
00064 if (substr($url, 0, strlen($prefix)) === $prefix) return true;
00065 }
00066 return false;
00067 }
00068
00069 function handleTrackNode(&$conference, &$schedConf, &$trackNode, &$errors, &$user, $isCommandLine, &$dependentItems, $trackIndex = null) {
00070 $trackDao =& DAORegistry::getDAO('TrackDAO');
00071
00072 $errors = array();
00073
00074 $schedConfSupportedLocales = array_keys($schedConf->getSupportedLocaleNames());
00075 $schedConfPrimaryLocale = $schedConf->getPrimaryLocale();
00076
00077
00078
00079
00080
00081 $titles = array();
00082 for ($index=0; ($node = $trackNode->getChildByName('title', $index)); $index++) {
00083 $locale = $node->getAttribute('locale');
00084 if ($locale == '') {
00085 $locale = $schedConfPrimaryLocale;
00086 } elseif (!in_array($locale, $schedConfSupportedLocales)) {
00087 $errors[] = array('plugins.importexport.native.import.error.trackTitleLocaleUnsupported', array('trackTitle' => $node->getValue(), 'locale' => $locale));
00088 return false;
00089 }
00090 $titles[$locale] = $node->getValue();
00091 }
00092 if (empty($titles)) {
00093 $errors[] = array('plugins.importexport.native.import.error.trackTitleMissing');
00094 return false;
00095 }
00096
00097 $abbrevs = array();
00098 for ($index=0; ($node = $trackNode->getChildByName('abbrev', $index)); $index++) {
00099 $locale = $node->getAttribute('locale');
00100 if ($locale == '') {
00101 $locale = $schedConfPrimaryLocale;
00102 } elseif (!in_array($locale, $schedConfSupportedLocales)) {
00103 $errors[] = array('plugins.importexport.native.import.error.trackAbbrevLocaleUnsupported', array('trackAbbrev' => $node->getValue(), 'locale' => $locale));
00104 return false;
00105 }
00106 $abbrevs[$locale] = $node->getValue();
00107 }
00108
00109 $identifyTypes = array();
00110 for ($index=0; ($node = $trackNode->getChildByName('identify_type', $index)); $index++) {
00111 $locale = $node->getAttribute('locale');
00112 if ($locale == '') {
00113 $locale = $schedConfPrimaryLocale;
00114 } elseif (!in_array($locale, $schedConfSupportedLocales)) {
00115 $errors[] = array('plugins.importexport.native.import.error.trackIdentifyTypeLocaleUnsupported', array('trackIdentifyType' => $node->getValue(), 'locale' => $locale));
00116 return false;
00117 }
00118 $identifyTypes[$locale] = $node->getValue();
00119 }
00120
00121 $policies = array();
00122 for ($index=0; ($node = $trackNode->getChildByName('policy', $index)); $index++) {
00123 $locale = $node->getAttribute('locale');
00124 if ($locale == '') {
00125 $locale = $schedConfPrimaryLocale;
00126 } elseif (!in_array($locale, $schedConfSupportedLocales)) {
00127 $errors[] = array('plugins.importexport.native.import.error.trackPolicyLocaleUnsupported', array('trackPolicy' => $node->getValue(), 'locale' => $locale));
00128 return false;
00129 }
00130 $policies[$locale] = $node->getValue();
00131 }
00132
00133
00134
00135
00136
00137 $track = null;
00138 $foundTrackId = $foundTrackTitle = null;
00139 $index = 0;
00140 foreach($titles as $locale => $title) {
00141 $track = $trackDao->getTrackByTitle($title, $schedConf->getId());
00142 if ($track) {
00143 $trackId = $track->getId();
00144 if ($foundTrackId) {
00145 if ($foundTrackId != $trackId) {
00146
00147 $errors[] = array('plugins.importexport.native.import.error.trackTitleMismatch', array('track1Title' => $title, 'track2Title' => $foundTrackTitle));
00148 return false;
00149 }
00150 } else if ($index > 0) {
00151
00152 $errors[] = array('plugins.importexport.native.import.error.trackTitleMatch', array('trackTitle' => $title));
00153 return false;
00154 }
00155 $foundTrackId = $trackId;
00156 $foundTrackTitle = $title;
00157 } else {
00158 if ($foundTrackId) {
00159
00160 $errors[] = array('plugins.importexport.native.import.error.trackTitleMatch', array('trackTitle' => $foundTrackTitle));
00161 return false;
00162 }
00163 }
00164 $index++;
00165 }
00166
00167
00168 $abbrevTrack = null;
00169 $foundTrackId = $foundTrackAbbrev = null;
00170 $index = 0;
00171 foreach($abbrevs as $locale => $abbrev) {
00172 $abbrevTrack = $trackDao->getTrackByAbbrev($abbrev, $schedConf->getId());
00173 if ($abbrevTrack) {
00174 $trackId = $abbrevTrack->getTrackId();
00175 if ($foundTrackId) {
00176 if ($foundTrackId != $trackId) {
00177
00178 $errors[] = array('plugins.importexport.native.import.error.trackAbbrevMismatch', array('track1Abbrev' => $abbrev, 'track2Abbrev' => $foundTrackAbbrev));
00179 return false;
00180 }
00181 } else if ($index > 0) {
00182
00183 $errors[] = array('plugins.importexport.native.import.error.trackAbbrevMatch', array('trackAbbrev' => $trackAbbrev));
00184 return false;
00185 }
00186 $foundTrackId = $trackId;
00187 $foundTrackAbbrev = $abbrev;
00188 } else {
00189 if ($foundTrackId) {
00190
00191 $errors[] = array('plugins.importexport.native.import.error.trackAbbrevMatch', array('trackAbbrev' => $foundTrackAbbrev));
00192 return false;
00193 }
00194 }
00195 $index++;
00196 }
00197
00198 if (!$track && !$abbrevTrack) {
00199
00200
00201
00202
00203 unset($track);
00204 $track = new Track();
00205
00206 $track->setTitle($titles, null);
00207 $track->setAbbrev($abbrevs, null);
00208 $track->setIdentifyType($identifyTypes, null);
00209 $track->setPolicy($policies, null);
00210 $track->setSchedConfId($schedConf->getId());
00211 $track->setSequence(REALLY_BIG_NUMBER);
00212 $track->setMetaIndexed(1);
00213 $track->setEditorRestricted(1);
00214 $track->setTrackId($trackDao->insertTrack($track));
00215 $trackDao->resequenceTracks($schedConf>getSchedConfId());
00216 }
00217
00218 if (!$track && $abbrevTrack) {
00219 unset($track);
00220 $track =& $abbrevTrack;
00221 }
00222
00223
00224
00225
00226 $hasErrors = false;
00227 for ($index = 0; ($node = $trackNode->getChildByName('paper', $index)); $index++) {
00228 if (!NativeImportDom::handlePaperNode($conference, $schedConf, $node, $track, $paper, $publishedPaper, $paperErrors, $user, $isCommandLine, $dependentItems)) {
00229 $errors = array_merge($errors, $paperErrors);
00230 $hasErrors = true;
00231 }
00232 }
00233 if ($hasErrors) return false;
00234
00235 return true;
00236 }
00237
00238 function handlePaperNode(&$conference, &$schedConf, &$paperNode, &$track, &$paper, &$publishedPaper, &$errors, &$user, $isCommandLine, &$dependentItems) {
00239 $errors = array();
00240
00241 $conferenceSupportedLocales = array_keys($conference->getSupportedLocaleNames());
00242 $conferencePrimaryLocale = $conference->getPrimaryLocale();
00243
00244 $publishedPaperDao =& DAORegistry::getDAO('PublishedPaperDAO');
00245 $paperDao =& DAORegistry::getDAO('PaperDAO');
00246
00247 $paper = new Paper();
00248 $paper->setSchedConfId($schedConf->getId());
00249 $paper->setUserId($user->getId());
00250 $paper->setTrackId($track->getId());
00251 $paper->setStatus(STATUS_PUBLISHED);
00252 $paper->setSubmissionProgress(0);
00253 $paper->setCurrentStage(REVIEW_STAGE_ABSTRACT);
00254 $paper->setReviewMode(REVIEW_MODE_ABSTRACTS_ALONE);
00255 $paper->setDateSubmitted(Core::getCurrentDate());
00256 $paper->stampStatusModified();
00257
00258 $titleExists = false;
00259 for ($index=0; ($node = $paperNode->getChildByName('title', $index)); $index++) {
00260 $locale = $node->getAttribute('locale');
00261 if ($locale == '') {
00262 $locale = $conferencePrimaryLocale;
00263 } elseif (!in_array($locale, $conferenceSupportedLocales)) {
00264 $errors[] = array('plugins.importexport.native.import.error.paperTitleLocaleUnsupported', array('paperTitle' => $node->getValue(), 'locale' => $locale));
00265 return false;
00266 }
00267 $paper->setTitle($node->getValue(), $locale);
00268 $titleExists = true;
00269 }
00270 if (!$titleExists || $paper->getTitle($conferencePrimaryLocale) == "") {
00271 $errors[] = array('plugins.importexport.native.import.error.paperTitleMissing', array('trackTitle' => $track->getLocalizedTitle()));
00272 return false;
00273 }
00274
00275 for ($index=0; ($node = $paperNode->getChildByName('abstract', $index)); $index++) {
00276 $locale = $node->getAttribute('locale');
00277 if ($locale == '') {
00278 $locale = $conferencePrimaryLocale;
00279 } elseif (!in_array($locale, $conferenceSupportedLocales)) {
00280 $errors[] = array('plugins.importexport.native.import.error.paperAbstractLocaleUnsupported', array('paperTitle' => $paper->getLocalizedTitle(), 'locale' => $locale));
00281 return false;
00282 }
00283 $paper->setAbstract($node->getValue(), $locale);
00284 }
00285
00286 if (($indexingNode = $paperNode->getChildByName('indexing'))) {
00287 for ($index=0; ($node = $indexingNode->getChildByName('discipline', $index)); $index++) {
00288 $locale = $node->getAttribute('locale');
00289 if ($locale == '') {
00290 $locale = $conferencePrimaryLocale;
00291 } elseif (!in_array($locale, $conferenceSupportedLocales)) {
00292 $errors[] = array('plugins.importexport.native.import.error.paperDisciplineLocaleUnsupported', array('paperTitle' => $paper->getLocalizedTitle(), 'locale' => $locale));
00293 return false;
00294 }
00295 $paper->setDiscipline($node->getValue(), $locale);
00296 }
00297 for ($index=0; ($node = $indexingNode->getChildByName('type', $index)); $index++) {
00298 $locale = $node->getAttribute('locale');
00299 if ($locale == '') {
00300 $locale = $conferencePrimaryLocale;
00301 } elseif (!in_array($locale, $conferenceSupportedLocales)) {
00302 $errors[] = array('plugins.importexport.native.import.error.paperTypeLocaleUnsupported', array('paperTitle' => $paper->getLocalizedTitle(), 'locale' => $locale));
00303 return false;
00304 }
00305 $paper->setType($node->getValue(), $locale);
00306 }
00307 for ($index=0; ($node = $indexingNode->getChildByName('subject', $index)); $index++) {
00308 $locale = $node->getAttribute('locale');
00309 if ($locale == '') {
00310 $locale = $conferencePrimaryLocale;
00311 } elseif (!in_array($locale, $conferenceSupportedLocales)) {
00312 $errors[] = array('plugins.importexport.native.import.error.paperSubjectLocaleUnsupported', array('paperTitle' => $paper->getLocalizedTitle(), 'locale' => $locale));
00313 return false;
00314 }
00315 $paper->setSubject($node->getValue(), $locale);
00316 }
00317 for ($index=0; ($node = $indexingNode->getChildByName('subject_class', $index)); $index++) {
00318 $locale = $node->getAttribute('locale');
00319 if ($locale == '') {
00320 $locale = $conferencePrimaryLocale;
00321 } elseif (!in_array($locale, $conferenceSupportedLocales)) {
00322 $errors[] = array('plugins.importexport.native.import.error.paperSubjectClassLocaleUnsupported', array('paperTitle' => $paper->getLocalizedTitle(), 'locale' => $locale));
00323 return false;
00324 }
00325 $paper->setSubjectClass($node->getValue(), $locale);
00326 }
00327
00328 if (($coverageNode = $indexingNode->getChildByName('coverage'))) {
00329 for ($index=0; ($node = $coverageNode->getChildByName('geographical', $index)); $index++) {
00330 $locale = $node->getAttribute('locale');
00331 if ($locale == '') {
00332 $locale = $conferencePrimaryLocale;
00333 } elseif (!in_array($locale, $conferenceSupportedLocales)) {
00334 $errors[] = array('plugins.importexport.native.import.error.paperCoverageGeoLocaleUnsupported', array('paperTitle' => $paper->getLocalizedTitle(), 'locale' => $locale));
00335 return false;
00336 }
00337 $paper->setCoverageGeo($node->getValue(), $locale);
00338 }
00339 for ($index=0; ($node = $coverageNode->getChildByName('chronological', $index)); $index++) {
00340 $locale = $node->getAttribute('locale');
00341 if ($locale == '') {
00342 $locale = $conferencePrimaryLocale;
00343 } elseif (!in_array($locale, $conferenceSupportedLocales)) {
00344 $errors[] = array('plugins.importexport.native.import.error.paperCoverageChronLocaleUnsupported', array('paperTitle' => $paper->getLocalizedTitle(), 'locale' => $locale));
00345 return false;
00346 }
00347 $paper->setCoverageChron($node->getValue(), $locale);
00348 }
00349 for ($index=0; ($node = $coverageNode->getChildByName('sample', $index)); $index++) {
00350 $locale = $node->getAttribute('locale');
00351 if ($locale == '') {
00352 $locale = $conferencePrimaryLocale;
00353 } elseif (!in_array($locale, $conferenceSupportedLocales)) {
00354 $errors[] = array('plugins.importexport.native.import.error.paperCoverageSampleLocaleUnsupported', array('paperTitle' => $paper->getLocalizedTitle(), 'locale' => $locale));
00355 return false;
00356 }
00357 $paper->setCoverageSample($node->getValue(), $locale);
00358 }
00359 }
00360 }
00361
00362 for ($index=0; ($node = $paperNode->getChildByName('sponsor', $index)); $index++) {
00363 $locale = $node->getAttribute('locale');
00364 if ($locale == '') {
00365 $locale = $conferencePrimaryLocale;
00366 } elseif (!in_array($locale, $conferenceSupportedLocales)) {
00367 $errors[] = array('plugins.importexport.native.import.error.paperSponsorLocaleUnsupported', array('paperTitle' => $paper->getLocalizedTitle(), 'locale' => $locale));
00368 return false;
00369 }
00370 $paper->setSponsor($node->getValue(), $locale);
00371 }
00372
00373 if (($node = $paperNode->getChildByName('pages'))) $paper->setPages($node->getValue());
00374 if (($language = $paperNode->getAttribute('language'))) $paper->setLanguage($language);
00375
00376
00377 $hasErrors = false;
00378 for ($index = 0; ($node = $paperNode->getChildByName('author', $index)); $index++) {
00379 if (!NativeImportDom::handleAuthorNode($conference, $schedConf, $node, $track, $paper, $authorErrors)) {
00380 $errors = array_merge($errors, $authorErrors);
00381 $hasErrors = true;
00382 }
00383 }
00384 if ($hasErrors) return false;
00385
00386 $paperDao->insertPaper($paper);
00387 $dependentItems[] = array('paper', $paper);
00388
00389
00390 import('paper.log.PaperLog');
00391 import('paper.log.PaperEventLogEntry');
00392 PaperLog::logEvent(
00393 $paper->getId(),
00394 PAPER_LOG_PAPER_IMPORT,
00395 PAPER_LOG_DEFAULT,
00396 0,
00397 'log.imported',
00398 array('userName' => $user->getFullName(), 'paperId' => $paper->getId())
00399 );
00400
00401
00402 $publishedPaper = new PublishedPaper();
00403 $publishedPaper->setPaperId($paper->getId());
00404 $publishedPaper->setSchedConfId($schedConf->getId());
00405
00406 if (($node = $paperNode->getChildByName('date_published'))) {
00407 $publishedDate = strtotime($node->getValue());
00408 if ($publishedDate === -1) {
00409 $errors[] = array('plugins.importexport.native.import.error.invalidDate', array('value' => $node->getValue()));
00410 return false;
00411 } else {
00412 $publishedPaper->setDatePublished($publishedDate);
00413 }
00414 }
00415 $node = $paperNode->getChildByName('open_access');
00416 $publishedPaper->setSeq(REALLY_BIG_NUMBER);
00417 $publishedPaper->setViews(0);
00418 $publishedPaper->setPublicPaperId($paperNode->getAttribute('public_id'));
00419
00420 $publishedPaper->setPubId($publishedPaperDao->insertPublishedPaper($publishedPaper));
00421
00422 $publishedPaperDao->resequencePublishedPapers($track->getId(), $schedConf->getId());
00423
00424
00425 import('file.PaperFileManager');
00426 $paperFileManager = new PaperFileManager($paper->getId());
00427
00428
00429 $hasErrors = false;
00430 $galleyCount = 0;
00431 for ($index=0; $index < count($paperNode->children); $index++) {
00432 $node = $paperNode->children[$index];
00433
00434 if ($node->getName() == 'htmlgalley') $isHtml = true;
00435 elseif ($node->getName() == 'galley') $isHtml = false;
00436 else continue;
00437
00438 if (!NativeImportDom::handleGalleyNode($conference, $schedConf, $node, $track, $paper, $galleyErrors, $isCommandLine, $isHtml, $galleyCount, $paperFileManager)) {
00439 $errors = array_merge($errors, $galleyErrors);
00440 $hasErrors = true;
00441 }
00442 $galleyCount++;
00443 }
00444 if ($hasErrors) return false;
00445
00446
00447 $hasErrors = false;
00448 for ($index = 0; ($node = $paperNode->getChildByName('supplemental_file', $index)); $index++) {
00449 if (!NativeImportDom::handleSuppFileNode($conference, $schedConf, $node, $track, $paper, $suppFileErrors, $isCommandLine, $paperFileManager)) {
00450 $errors = array_merge($errors, $suppFileErrors);
00451 $hasErrors = true;
00452 }
00453 }
00454 if ($hasErrors) return false;
00455
00456
00457 import('search.PaperSearchIndex');
00458 PaperSearchIndex::indexPaperMetadata($paper);
00459 PaperSearchIndex::indexPaperFiles($paper);
00460
00461 return true;
00462 }
00463
00464 function handleAuthorNode(&$conference, &$schedConf, &$authorNode, &$track, &$paper, &$errors) {
00465 $errors = array();
00466
00467 $conferenceSupportedLocales = array_keys($conference->getSupportedLocaleNames());
00468 $conferencePrimaryLocale = $conference->getPrimaryLocale();
00469
00470 $author = new Author();
00471 if (($node = $authorNode->getChildByName('firstname'))) $author->setFirstName($node->getValue());
00472 if (($node = $authorNode->getChildByName('middlename'))) $author->setMiddleName($node->getValue());
00473 if (($node = $authorNode->getChildByName('lastname'))) $author->setLastName($node->getValue());
00474 if (($node = $authorNode->getChildByName('affiliation'))) $author->setAffiliation($node->getValue());
00475 if (($node = $authorNode->getChildByName('country'))) $author->setCountry($node->getValue());
00476 if (($node = $authorNode->getChildByName('email'))) $author->setEmail($node->getValue());
00477 if (($node = $authorNode->getChildByName('url'))) $author->setUrl($node->getValue());
00478 for ($index=0; ($node = $authorNode->getChildByName('biography', $index)); $index++) {
00479 $locale = $node->getAttribute('locale');
00480 if ($locale == '') {
00481 $locale = $conferencePrimaryLocale;
00482 } elseif (!in_array($locale, $conferenceSupportedLocales)) {
00483 $errors[] = array('plugins.importexport.native.import.error.paperAuthorBiographyLocaleUnsupported', array('authorFullName' => $author->getFullName(), 'paperTitle' => $paper->getLocalizedTitle(), 'locale' => $locale));
00484 return false;
00485 }
00486 $author->setBiography($node->getValue(), $locale);
00487 }
00488
00489 $author->setPrimaryContact($authorNode->getAttribute('primary_contact')==='true'?1:0);
00490 $paper->addAuthor($author);
00491
00492 return true;
00493
00494 }
00495
00496 function handleGalleyNode(&$conference, &$schedConf, &$galleyNode, &$track, &$paper, &$errors, $isCommandLine, $isHtml, $galleyCount, &$paperFileManager) {
00497 $errors = array();
00498
00499 $conferenceSupportedLocales = array_keys($conference->getSupportedLocaleNames());
00500 $conferencePrimaryLocale = $conference->getPrimaryLocale();
00501
00502 $galleyDao =& DAORegistry::getDAO('PaperGalleyDAO');
00503
00504 if ($isHtml) $galley = new PaperHtmlGalley();
00505 else $galley = new PaperGalley();
00506
00507 $galley->setPaperId($paper->getId());
00508 $galley->setSequence($galleyCount);
00509
00510
00511 $locale = $galleyNode->getAttribute('locale');
00512 if ($locale == '') {
00513 $locale = $conferencePrimaryLocale;
00514 } elseif (!in_array($locale, $conferenceSupportedLocales)) {
00515 $errors[] = array('plugins.importexport.native.import.error.galleyLocaleUnsupported', array('paperTitle' => $paper->getLocalizedTitle(), 'locale' => $locale));
00516 return false;
00517 }
00518 $galley->setLocale($locale);
00519
00520
00521 if (!($node = $galleyNode->getChildByName('label'))) {
00522 $errors[] = array('plugins.importexport.native.import.error.galleyLabelMissing', array('paperTitle' => $paper->getLocalizedTitle(), 'trackTitle' => $track->getLocalizedTitle()));
00523 return false;
00524 }
00525 $galley->setLabel($node->getValue());
00526
00527
00528 if (!($node = $galleyNode->getChildByName('file'))) {
00529 $errors[] = array('plugins.importexport.native.import.error.galleyFileMissing', array('paperTitle' => $paper->getLocalizedTitle(), 'trackTitle' => $track->getLocalizedTitle()));
00530 return false;
00531 }
00532
00533 if (($href = $node->getChildByName('href'))) {
00534 $url = $href->getAttribute('src');
00535 if ($isCommandLine || NativeImportDom::isAllowedMethod($url)) {
00536 if ($isCommandLine && NativeImportDom::isRelativePath($url)) {
00537
00538 $url = PWD . '/' . $url;
00539 }
00540
00541 if (($fileId = $paperFileManager->copyPublicFile($url, $href->getAttribute('mime_type')))===false) {
00542 $errors[] = array('plugins.importexport.native.import.error.couldNotCopy', array('url' => $url));
00543 return false;
00544 }
00545 }
00546 }
00547 if (($embed = $node->getChildByName('embed'))) {
00548 if (($type = $embed->getAttribute('encoding')) !== 'base64') {
00549 $errors[] = array('plugins.importexport.native.import.error.unknownEncoding', array('type' => $type));
00550 return false;
00551 }
00552 $originalName = $embed->getAttribute('filename');
00553 if (($fileId = $paperFileManager->writePublicFile($originalName, base64_decode($embed->getValue()), $embed->getAttribute('mime_type')))===false) {
00554 $errors[] = array('plugins.importexport.native.import.error.couldNotWriteFile', array('originalName' => $originalName));
00555 return false;
00556 }
00557 }
00558 if (!isset($fileId)) {
00559 $errors[] = array('plugins.importexport.native.import.error.galleyFileMissing', array('paperTitle' => $paper->getLocalizedTitle(), 'trackTitle' => $track->getLocalizedTitle()));
00560 return false;
00561 }
00562 $galley->setFileId($fileId);
00563 $galleyDao->insertGalley($galley);
00564
00565 if ($isHtml) {
00566 $result = NativeImportDom::handleHtmlGalleyNodes($galleyNode, $paperFileManager, $galley, $errors, $isCommandLine);
00567 if (!$result) return false;
00568 }
00569
00570 return true;
00571
00572 }
00573
00579 function handleHtmlGalleyNodes(&$galleyNode, &$paperFileManager, &$galley, &$errors, &$isCommandLine) {
00580 $paperGalleyDao =& DAORegistry::getDAO('PaperGalleyDAO');
00581
00582 foreach ($galleyNode->children as $node) {
00583 $isStylesheet = ($node->getName() == 'stylesheet');
00584 $isImage = ($node->getName() == 'image');
00585 if (!$isStylesheet && !$isImage) continue;
00586
00587 if (($href = $node->getChildByName('href'))) {
00588 $url = $href->getAttribute('src');
00589 if ($isCommandLine || NativeImportDom::isAllowedMethod($url)) {
00590 if ($isCommandLine && NativeImportDom::isRelativePath($url)) {
00591
00592 $url = PWD . '/' . $url;
00593 }
00594
00595 if (($fileId = $paperFileManager->copyPublicFile($url, $href->getAttribute('mime_type')))===false) {
00596 $errors[] = array('plugins.importexport.native.import.error.couldNotCopy', array('url' => $url));
00597 return false;
00598 }
00599 }
00600 }
00601 if (($embed = $node->getChildByName('embed'))) {
00602 if (($type = $embed->getAttribute('encoding')) !== 'base64') {
00603 $errors[] = array('plugins.importexport.native.import.error.unknownEncoding', array('type' => $type));
00604 return false;
00605 }
00606 $originalName = $embed->getAttribute('filename');
00607 if (($fileId = $paperFileManager->writePublicFile($originalName, base64_decode($embed->getValue()), $embed->getAttribute('mime_type')))===false) {
00608 $errors[] = array('plugins.importexport.native.import.error.couldNotWriteFile', array('originalName' => $originalName));
00609 return false;
00610 }
00611 }
00612
00613 if (!isset($fileId)) continue;
00614
00615 if ($isStylesheet) {
00616 $galley->setStyleFileId($fileId);
00617 $paperGalleyDao->updateGalley($galley);
00618 } else {
00619 $paperGalleyDao->insertGalleyImage($galley->getId(), $fileId);
00620 }
00621 }
00622 return true;
00623 }
00624
00625 function handleSuppFileNode(&$conference, &$schedConf, &$suppNode, &$track, &$paper, &$errors, $isCommandLine, &$paperFileManager) {
00626 $errors = array();
00627
00628 $conferenceSupportedLocales = array_keys($conference->getSupportedLocaleNames());
00629 $conferencePrimaryLocale = $conference->getPrimaryLocale();
00630
00631 $suppFileDao =& DAORegistry::getDAO('SuppFileDAO');
00632
00633 $suppFile = new SuppFile();
00634 $suppFile->setPaperId($paper->getId());
00635
00636 for ($index=0; ($node = $suppNode->getChildByName('title', $index)); $index++) {
00637 $locale = $node->getAttribute('locale');
00638 if ($locale == '') {
00639 $locale = $conferencePrimaryLocale;
00640 } elseif (!in_array($locale, $conferenceSupportedLocales)) {
00641 $errors[] = array('plugins.importexport.native.import.error.paperSuppFileTitleLocaleUnsupported', array('suppFileTitle' => $node->getValue(), 'paperTitle' => $paper->getLocalizedTitle(), 'locale' => $locale));
00642 return false;
00643 }
00644 $suppFile->setTitle($node->getValue(), $locale);
00645 }
00646 for ($index=0; ($node = $suppNode->getChildByName('creator', $index)); $index++) {
00647 $locale = $node->getAttribute('locale');
00648 if ($locale == '') {
00649 $locale = $conferencePrimaryLocale;
00650 } elseif (!in_array($locale, $conferenceSupportedLocales)) {
00651 $errors[] = array('plugins.importexport.native.import.error.paperSuppFileCreatorLocaleUnsupported', array('suppFileTitle' => $node->getValue(), 'paperTitle' => $paper->getLocalizedTitle(), 'locale' => $locale));
00652 return false;
00653 }
00654 $suppFile->setCreator($node->getValue(), $locale);
00655 }
00656 for ($index=0; ($node = $suppNode->getChildByName('subject', $index)); $index++) {
00657 $locale = $node->getAttribute('locale');
00658 if ($locale == '') {
00659 $locale = $conferencePrimaryLocale;
00660 } elseif (!in_array($locale, $conferenceSupportedLocales)) {
00661 $errors[] = array('plugins.importexport.native.import.error.paperSuppFileSubjectLocaleUnsupported', array('suppFileTitle' => $node->getValue(), 'paperTitle' => $paper->getLocalizedTitle(), 'locale' => $locale));
00662 return false;
00663 }
00664 $suppFile->setSubject($node->getValue(), $locale);
00665 }
00666 for ($index=0; ($node = $suppNode->getChildByName('type_other', $index)); $index++) {
00667 $locale = $node->getAttribute('locale');
00668 if ($locale == '') {
00669 $locale = $conferencePrimaryLocale;
00670 } elseif (!in_array($locale, $conferenceSupportedLocales)) {
00671 $errors[] = array('plugins.importexport.native.import.error.paperSuppFileTypeOtherLocaleUnsupported', array('suppFileTitle' => $node->getValue(), 'paperTitle' => $paper->getLocalizedTitle(), 'locale' => $locale));
00672 return false;
00673 }
00674 $suppFile->setTypeOther($node->getValue(), $locale);
00675 }
00676 for ($index=0; ($node = $suppNode->getChildByName('description', $index)); $index++) {
00677 $locale = $node->getAttribute('locale');
00678 if ($locale == '') {
00679 $locale = $conferencePrimaryLocale;
00680 } elseif (!in_array($locale, $conferenceSupportedLocales)) {
00681 $errors[] = array('plugins.importexport.native.import.error.paperSuppFileDescriptionLocaleUnsupported', array('suppFileTitle' => $node->getValue(), 'paperTitle' => $paper->getLocalizedTitle(), 'locale' => $locale));
00682 return false;
00683 }
00684 $suppFile->setDescription($node->getValue(), $locale);
00685 }
00686 for ($index=0; ($node = $suppNode->getChildByName('publisher', $index)); $index++) {
00687 $locale = $node->getAttribute('locale');
00688 if ($locale == '') {
00689 $locale = $conferencePrimaryLocale;
00690 } elseif (!in_array($locale, $conferenceSupportedLocales)) {
00691 $errors[] = array('plugins.importexport.native.import.error.paperSuppFilePublisherLocaleUnsupported', array('suppFileTitle' => $node->getValue(), 'paperTitle' => $paper->getLocalizedTitle(), 'locale' => $locale));
00692 return false;
00693 }
00694 $suppFile->setPublisher($node->getValue(), $locale);
00695 }
00696 for ($index=0; ($node = $suppNode->getChildByName('sponsor', $index)); $index++) {
00697 $locale = $node->getAttribute('locale');
00698 if ($locale == '') {
00699 $locale = $conferencePrimaryLocale;
00700 } elseif (!in_array($locale, $conferenceSupportedLocales)) {
00701 $errors[] = array('plugins.importexport.native.import.error.paperSuppFileSponsorLocaleUnsupported', array('suppFileTitle' => $node->getValue(), 'paperTitle' => $paper->getLocalizedTitle(), 'locale' => $locale));
00702 return false;
00703 }
00704 $suppFile->setSponsor($node->getValue(), $locale);
00705 }
00706 for ($index=0; ($node = $suppNode->getChildByName('source', $index)); $index++) {
00707 $locale = $node->getAttribute('locale');
00708 if ($locale == '') {
00709 $locale = $conferencePrimaryLocale;
00710 } elseif (!in_array($locale, $conferenceSupportedLocales)) {
00711 $errors[] = array('plugins.importexport.native.import.error.paperSuppFileSourceLocaleUnsupported', array('suppFileTitle' => $node->getValue(), 'paperTitle' => $paper->getLocalizedTitle(), 'locale' => $locale));
00712 return false;
00713 }
00714 $suppFile->setSource($node->getValue(), $locale);
00715 }
00716 if (($node = $suppNode->getChildByName('date_created'))) {
00717 $createdDate = strtotime($node->getValue());
00718 if ($createdDate !== -1) $suppFile->setDateCreated($createdDate);
00719 }
00720
00721 switch (($suppType = $suppNode->getAttribute('type'))) {
00722 case 'research_instrument': $suppFile->setType(__('author.submit.suppFile.researchInstrument')); break;
00723 case 'research_materials': $suppFile->setType(__('author.submit.suppFile.researchMaterials')); break;
00724 case 'research_results': $suppFile->setType(__('author.submit.suppFile.researchResults')); break;
00725 case 'transcripts': $suppFile->setType(__('author.submit.suppFile.transcripts')); break;
00726 case 'data_analysis': $suppFile->setType(__('author.submit.suppFile.dataAnalysis')); break;
00727 case 'data_set': $suppFile->setType(__('author.submit.suppFile.dataSet')); break;
00728 case 'source_text': $suppFile->setType(__('author.submit.suppFile.sourceText')); break;
00729 case 'other': $suppFile->setType(''); break;
00730 default:
00731 $errors[] = array('plugins.importexport.native.import.error.unknownSuppFileType', array('suppFileType' => $suppType));
00732 return false;
00733 }
00734
00735 $suppFile->setLanguage($suppNode->getAttribute('language'));
00736 $suppFile->setPublicSuppFileId($suppNode->getAttribute('public_id'));
00737
00738 if (!($fileNode = $suppNode->getChildByName('file'))) {
00739 $errors[] = array('plugins.importexport.native.import.error.suppFileMissing', array('paperTitle' => $paper->getLocalizedTitle(), 'trackTitle' => $track->getLocalizedTitle()));
00740 return false;
00741 }
00742
00743 if (($href = $fileNode->getChildByName('href'))) {
00744 $url = $href->getAttribute('src');
00745 if ($isCommandLine || NativeImportDom::isAllowedMethod($url)) {
00746 if ($isCommandLine && NativeImportDom::isRelativePath($url)) {
00747
00748 $url = PWD . '/' . $url;
00749 }
00750
00751 if (($fileId = $paperFileManager->copySuppFile($url, $href->getAttribute('mime_type')))===false) {
00752 $errors[] = array('plugins.importexport.native.import.error.couldNotCopy', array('url' => $url));
00753 return false;
00754 }
00755 }
00756 }
00757 if (($embed = $fileNode->getChildByName('embed'))) {
00758 if (($type = $embed->getAttribute('encoding')) !== 'base64') {
00759 $errors[] = array('plugins.importexport.native.import.error.unknownEncoding', array('type' => $type));
00760 return false;
00761 }
00762 $originalName = $embed->getAttribute('filename');
00763 if (($fileId = $paperFileManager->writeSuppFile($originalName, base64_decode($embed->getValue()), $embed->getAttribute('mime_type')))===false) {
00764 $errors[] = array('plugins.importexport.native.import.error.couldNotWriteFile', array('originalName' => $originalName));
00765 return false;
00766 }
00767 }
00768
00769 if (!$fileId) {
00770 $errors[] = array('plugins.importexport.native.import.error.suppFileMissing', array('paperTitle' => $paper->getLocalizedTitle(), 'trackTitle' => $track->getLocalizedTitle()));
00771 return false;
00772 }
00773
00774 $suppFile->setFileId($fileId);
00775 $suppFileDao->insertSuppFile($suppFile);
00776
00777 return true;
00778
00779 }
00780
00781 function cleanupFailure (&$dependentItems) {
00782 $paperDao =& DAORegistry::getDAO('PaperDAO');
00783
00784 foreach ($dependentItems as $dependentItem) {
00785 $type = array_shift($dependentItem);
00786 $object = array_shift($dependentItem);
00787
00788 switch ($type) {
00789 case 'paper':
00790 $paperDao->deletePaper($object);
00791 break;
00792 default:
00793 fatalError ('cleanupFailure: Unimplemented type');
00794 }
00795 }
00796 }
00797 }
00798
00799 ?>