00001 <?php
00002
00015
00016
00017 import('xml.XMLCustomWriter');
00018
00019 class NativeExportDom {
00020 function &generateTrackDom(&$doc, &$schedConf, &$track) {
00021 $root =& XMLCustomWriter::createElement($doc, 'track');
00022
00023 if (is_array($track->getTitle(null))) foreach ($track->getTitle(null) as $locale => $title) {
00024 $titleNode =& XMLCustomWriter::createChildWithText($doc, $root, 'title', $title, false);
00025 if ($titleNode) XMLCustomWriter::setAttribute($titleNode, 'locale', $locale);
00026 unset($titleNode);
00027 }
00028
00029 if (is_array($track->getAbbrev(null))) foreach ($track->getAbbrev(null) as $locale => $abbrev) {
00030 $abbrevNode =& XMLCustomWriter::createChildWithText($doc, $root, 'abbrev', $abbrev, false);
00031 if ($abbrevNode) XMLCustomWriter::setAttribute($abbrevNode, 'locale', $locale);
00032 unset($abbrevNode);
00033 }
00034
00035 if (is_array($track->getIdentifyType(null))) foreach ($track->getIdentifyType(null) as $locale => $identifyType) {
00036 $identifyTypeNode =& XMLCustomWriter::createChildWithText($doc, $root, 'identify_type', $identifyType, false);
00037 if ($identifyTypeNode) XMLCustomWriter::setAttribute($identifyTypeNode, 'locale', $locale);
00038 unset($identifyTypeNode);
00039 }
00040
00041 if (is_array($track->getPolicy(null))) foreach ($track->getPolicy(null) as $locale => $policy) {
00042 $policyNode =& XMLCustomWriter::createChildWithText($doc, $root, 'policy', $policy, false);
00043 if ($policyNode) XMLCustomWriter::setAttribute($policyNode, 'locale', $locale);
00044 unset($policyNode);
00045 }
00046
00047 $publishedPaperDao =& DAORegistry::getDAO('PublishedPaperDAO');
00048 foreach ($publishedPaperDao->getPublishedPapersByTrackId($track->getId(), $schedConf->getId()) as $paper) {
00049 $paperNode =& NativeExportDom::generatePaperDom($doc, $schedConf, $track, $paper);
00050 XMLCustomWriter::appendChild($root, $paperNode);
00051 unset($paperNode);
00052 }
00053
00054 return $root;
00055 }
00056
00057 function &generatePaperDom(&$doc, &$schedConf, &$track, &$paper) {
00058 $root =& XMLCustomWriter::createElement($doc, 'paper');
00059
00060
00061 XMLCustomWriter::createChildWithText($doc, $root, 'id', $paper->getId());
00062
00063
00064 if (is_array($paper->getTitle(null))) foreach ($paper->getTitle(null) as $locale => $title) {
00065 $titleNode =& XMLCustomWriter::createChildWithText($doc, $root, 'title', $title, false);
00066 if ($titleNode) XMLCustomWriter::setAttribute($titleNode, 'locale', $locale);
00067 unset($titleNode);
00068 }
00069
00070 if (is_array($paper->getAbstract(null))) foreach ($paper->getAbstract(null) as $locale => $abstract) {
00071 $abstractNode =& XMLCustomWriter::createChildWithText($doc, $root, 'abstract', $abstract, false);
00072 if ($abstractNode) XMLCustomWriter::setAttribute($abstractNode, 'locale', $locale);
00073 unset($abstractNode);
00074 }
00075
00076
00077
00078 $indexingNode =& XMLCustomWriter::createElement($doc, 'indexing');
00079 $isIndexingNecessary = false;
00080
00081 if (is_array($paper->getDiscipline(null))) foreach ($paper->getDiscipline(null) as $locale => $discipline) {
00082 $disciplineNode =& XMLCustomWriter::createChildWithText($doc, $indexingNode, 'discipline', $discipline, false);
00083 if ($disciplineNode) {
00084 XMLCustomWriter::setAttribute($disciplineNode, 'locale', $locale);
00085 $isIndexingNecessary = true;
00086 }
00087 unset($disciplineNode);
00088 }
00089 if (is_array($paper->getType(null))) foreach ($paper->getType(null) as $locale => $type) {
00090 $typeNode =& XMLCustomWriter::createChildWithText($doc, $indexingNode, 'type', $type, false);
00091 if ($typeNode) {
00092 XMLCustomWriter::setAttribute($typeNode, 'locale', $locale);
00093 $isIndexingNecessary = true;
00094 }
00095 unset($typeNode);
00096 }
00097 if (is_array($paper->getSubject(null))) foreach ($paper->getSubject(null) as $locale => $subject) {
00098 $subjectNode =& XMLCustomWriter::createChildWithText($doc, $indexingNode, 'subject', $subject, false);
00099 if ($subjectNode) {
00100 XMLCustomWriter::setAttribute($subjectNode, 'locale', $locale);
00101 $isIndexingNecessary = true;
00102 }
00103 unset($subjectNode);
00104 }
00105 if (is_array($paper->getSubjectClass(null))) foreach ($paper->getSubjectClass(null) as $locale => $subjectClass) {
00106 $subjectClassNode =& XMLCustomWriter::createChildWithText($doc, $indexingNode, 'subject_class', $subjectClass, false);
00107 if ($subjectClassNode) {
00108 XMLCustomWriter::setAttribute($subjectClassNode, 'locale', $locale);
00109 $isIndexingNecessary = true;
00110 }
00111 unset($subjectClassNode);
00112 }
00113
00114 $coverageNode =& XMLCustomWriter::createElement($doc, 'coverage');
00115 $isCoverageNecessary = false;
00116
00117 if (is_array($paper->getCoverageGeo(null))) foreach ($paper->getCoverageGeo(null) as $locale => $geographical) {
00118 $geographicalNode =& XMLCustomWriter::createChildWithText($doc, $coverageNode, 'geographical', $geographical, false);
00119 if ($geographicalNode) {
00120 XMLCustomWriter::setAttribute($geographicalNode, 'locale', $locale);
00121 $isCoverageNecessary = true;
00122 }
00123 unset($geographicalNode);
00124 }
00125 if (is_array($paper->getCoverageChron(null))) foreach ($paper->getCoverageChron(null) as $locale => $chronological) {
00126 $chronologicalNode =& XMLCustomWriter::createChildWithText($doc, $coverageNode, 'chronological', $chronological, false);
00127 if ($chronologicalNode) {
00128 XMLCustomWriter::setAttribute($chronologicalNode, 'locale', $locale);
00129 $isCoverageNecessary = true;
00130 }
00131 unset($chronologicalNode);
00132 }
00133 if (is_array($paper->getCoverageSample(null))) foreach ($paper->getCoverageSample(null) as $locale => $sample) {
00134 $sampleNode =& XMLCustomWriter::createChildWithText($doc, $coverageNode, 'sample', $sample, false);
00135 if ($sampleNode) {
00136 XMLCustomWriter::setAttribute($sampleNode, 'locale', $locale);
00137 $isCoverageNecessary = true;
00138 }
00139 unset($sampleNode);
00140 }
00141
00142 if ($isCoverageNecessary) {
00143 XMLCustomWriter::appendChild($indexingNode, $coverageNode);
00144 $isIndexingNecessary = true;
00145 }
00146
00147 if ($isIndexingNecessary) XMLCustomWriter::appendChild($root, $indexingNode);
00148
00149
00150
00151
00152
00153 foreach ($paper->getAuthors() as $author) {
00154 $authorNode =& NativeExportDom::generateAuthorDom($doc, $schedConf, $paper, $author);
00155 XMLCustomWriter::appendChild($root, $authorNode);
00156 unset($authorNode);
00157 }
00158
00159
00160
00161 XMLCustomWriter::createChildWithText($doc, $root, 'pages', $paper->getPages(), false);
00162
00163 XMLCustomWriter::createChildWithText($doc, $root, 'date_published', NativeExportDom::formatDate($paper->getDatePublished()), false);
00164
00165
00166
00167 foreach ($paper->getGalleys() as $galley) {
00168 $galleyNode =& NativeExportDom::generateGalleyDom($doc, $schedConf, $paper, $galley);
00169 if ($galleyNode !== null) XMLCustomWriter::appendChild($root, $galleyNode);
00170 unset($galleyNode);
00171
00172 }
00173
00174
00175 foreach ($paper->getSuppFiles() as $suppFile) {
00176 $suppNode =& NativeExportDom::generateSuppFileDom($doc, $schedConf, $paper, $suppFile);
00177 if ($suppNode !== null) XMLCustomWriter::appendChild($root, $suppNode);
00178 unset($suppNode);
00179 }
00180
00181 return $root;
00182 }
00183
00184 function &generateAuthorDom(&$doc, &$schedConf, &$paper, &$author) {
00185 $root =& XMLCustomWriter::createElement($doc, 'author');
00186 if ($author->getPrimaryContact()) XMLCustomWriter::setAttribute($root, 'primary_contact', 'true');
00187
00188 XMLCustomWriter::createChildWithText($doc, $root, 'firstname', $author->getFirstName());
00189 XMLCustomWriter::createChildWithText($doc, $root, 'middlename', $author->getMiddleName(), false);
00190 XMLCustomWriter::createChildWithText($doc, $root, 'lastname', $author->getLastName());
00191
00192 XMLCustomWriter::createChildWithText($doc, $root, 'affiliation', $author->getAffiliation(), false);
00193 XMLCustomWriter::createChildWithText($doc, $root, 'country', $author->getCountry(), false);
00194 XMLCustomWriter::createChildWithText($doc, $root, 'email', $author->getEmail(), false);
00195 XMLCustomWriter::createChildWithText($doc, $root, 'url', $author->getUrl(), false);
00196 if (is_array($author->getBiography(null))) foreach ($author->getBiography(null) as $locale => $biography) {
00197 $biographyNode =& XMLCustomWriter::createChildWithText($doc, $root, 'biography', strip_tags($biography), false);
00198 if ($biographyNode) XMLCustomWriter::setAttribute($biographyNode, 'locale', $locale);
00199 unset($biographyNode);
00200 }
00201
00202 return $root;
00203 }
00204
00205 function &generateGalleyDom(&$doc, &$schedConf, &$paper, &$galley) {
00206 $isHtml = $galley->isHTMLGalley();
00207
00208 import('file.PaperFileManager');
00209 $paperFileManager = new PaperFileManager($paper->getId());
00210 $paperFileDao =& DAORegistry::getDAO('PaperFileDAO');
00211
00212 $root =& XMLCustomWriter::createElement($doc, $isHtml?'htmlgalley':'galley');
00213 if ($root) XMLCustomWriter::setAttribute($root, 'locale', $galley->getLocale());
00214
00215 XMLCustomWriter::createChildWithText($doc, $root, 'label', $galley->getLabel());
00216
00217
00218 $fileNode =& XMLCustomWriter::createElement($doc, 'file');
00219 XMLCustomWriter::appendChild($root, $fileNode);
00220 $embedNode =& XMLCustomWriter::createChildWithText($doc, $fileNode, 'embed', base64_encode($paperFileManager->readFile($galley->getFileId())));
00221 $paperFile =& $paperFileDao->getPaperFile($galley->getFileId());
00222 if (!$paperFile) return $paperFile;
00223 XMLCustomWriter::setAttribute($embedNode, 'filename', $paperFile->getOriginalFileName());
00224 XMLCustomWriter::setAttribute($embedNode, 'encoding', 'base64');
00225 XMLCustomWriter::setAttribute($embedNode, 'mime_type', $paperFile->getFileType());
00226
00227
00228
00229 if ($isHtml) {
00230 $styleFile = $galley->getStyleFile();
00231 if ($styleFile) {
00232 $styleNode =& XMLCustomWriter::createElement($doc, 'stylesheet');
00233 XMLCustomWriter::appendChild($root, $styleNode);
00234 $embedNode =& XMLCustomWriter::createChildWithText($doc, $styleNode, 'embed', base64_encode($paperFileManager->readFile($styleFile->getFileId())));
00235 XMLCustomWriter::setAttribute($embedNode, 'filename', $styleFile->getOriginalFileName());
00236 XMLCustomWriter::setAttribute($embedNode, 'encoding', 'base64');
00237 XMLCustomWriter::setAttribute($embedNode, 'mime_type', 'text/css');
00238 }
00239
00240 foreach ($galley->getImageFiles() as $imageFile) {
00241 $imageNode =& XMLCustomWriter::createElement($doc, 'image');
00242 XMLCustomWriter::appendChild($root, $imageNode);
00243 $embedNode =& XMLCustomWriter::createChildWithText($doc, $imageNode, 'embed', base64_encode($paperFileManager->readFile($imageFile->getFileId())));
00244 XMLCustomWriter::setAttribute($embedNode, 'filename', $imageFile->getOriginalFileName());
00245 XMLCustomWriter::setAttribute($embedNode, 'encoding', 'base64');
00246 XMLCustomWriter::setAttribute($embedNode, 'mime_type', $imageFile->getFileType());
00247 unset($imageNode);
00248 unset($embedNode);
00249 }
00250 }
00251
00252 return $root;
00253 }
00254
00255 function &generateSuppFileDom(&$doc, &$schedConf, &$paper, &$suppFile) {
00256 $root =& XMLCustomWriter::createElement($doc, 'supplemental_file');
00257
00258
00259 switch ($suppFile->getType()) {
00260 case __('author.submit.suppFile.researchInstrument'):
00261 $suppFileType = 'research_instrument';
00262 break;
00263 case __('author.submit.suppFile.researchMaterials'):
00264 $suppFileType = 'research_materials';
00265 break;
00266 case __('author.submit.suppFile.researchResults'):
00267 $suppFileType = 'research_results';
00268 break;
00269 case __('author.submit.suppFile.transcripts'):
00270 $suppFileType = 'transcripts';
00271 break;
00272 case __('author.submit.suppFile.dataAnalysis'):
00273 $suppFileType = 'data_analysis';
00274 break;
00275 case __('author.submit.suppFile.dataSet'):
00276 $suppFileType = 'data_set';
00277 break;
00278 case __('author.submit.suppFile.sourceText'):
00279 $suppFileType = 'source_text';
00280 break;
00281 default:
00282 $suppFileType = 'other';
00283 break;
00284 }
00285
00286 XMLCustomWriter::setAttribute($root, 'type', $suppFileType);
00287 XMLCustomWriter::setAttribute($root, 'public_id', $suppFile->getPublicSuppFileId(), false);
00288 XMLCustomWriter::setAttribute($root, 'language', $suppFile->getLanguage(), false);
00289
00290 if (is_array($suppFile->getTitle(null))) foreach ($suppFile->getTitle(null) as $locale => $title) {
00291 $titleNode =& XMLCustomWriter::createChildWithText($doc, $root, 'title', $title, false);
00292 if ($titleNode) XMLCustomWriter::setAttribute($titleNode, 'locale', $locale);
00293 unset($titleNode);
00294 }
00295 if (is_array($suppFile->getCreator(null))) foreach ($suppFile->getCreator(null) as $locale => $creator) {
00296 $creatorNode =& XMLCustomWriter::createChildWithText($doc, $root, 'creator', $creator, false);
00297 if ($creatorNode) XMLCustomWriter::setAttribute($creatorNode, 'locale', $locale);
00298 unset($creatorNode);
00299 }
00300 if (is_array($suppFile->getSubject(null))) foreach ($suppFile->getSubject(null) as $locale => $subject) {
00301 $subjectNode =& XMLCustomWriter::createChildWithText($doc, $root, 'subject', $subject, false);
00302 if ($subjectNode) XMLCustomWriter::setAttribute($subjectNode, 'locale', $locale);
00303 unset($subjectNode);
00304 }
00305 if ($suppFileType == 'other') {
00306 if (is_array($suppFile->getTypeOther(null))) foreach ($suppFile->getTypeOther(null) as $locale => $typeOther) {
00307 $typeOtherNode =& XMLCustomWriter::createChildWithText($doc, $root, 'type_other', $typeOther, false);
00308 if ($typeOtherNode) XMLCustomWriter::setAttribute($typeOtherNode, 'locale', $locale);
00309 unset($typeOtherNode);
00310 }
00311 }
00312 if (is_array($suppFile->getDescription(null))) foreach ($suppFile->getDescription(null) as $locale => $description) {
00313 $descriptionNode =& XMLCustomWriter::createChildWithText($doc, $root, 'description', $description, false);
00314 if ($descriptionNode) XMLCustomWriter::setAttribute($descriptionNode, 'locale', $locale);
00315 unset($descriptionNode);
00316 }
00317 if (is_array($suppFile->getPublisher(null))) foreach ($suppFile->getPublisher(null) as $locale => $publisher) {
00318 $publisherNode =& XMLCustomWriter::createChildWithText($doc, $root, 'publisher', $publisher, false);
00319 if ($publisherNode) XMLCustomWriter::setAttribute($publisherNode, 'locale', $locale);
00320 unset($publisherNode);
00321 }
00322 if (is_array($suppFile->getSponsor(null))) foreach ($suppFile->getSponsor(null) as $locale => $sponsor) {
00323 $sponsorNode =& XMLCustomWriter::createChildWithText($doc, $root, 'sponsor', $sponsor, false);
00324 if ($sponsorNode) XMLCustomWriter::setAttribute($sponsorNode, 'locale', $locale);
00325 unset($sponsorNode);
00326 }
00327 XMLCustomWriter::createChildWithText($doc, $root, 'date_created', NativeExportDom::formatDate($suppFile->getDateCreated()), false);
00328 if (is_array($suppFile->getSource(null))) foreach ($suppFile->getSource(null) as $locale => $source) {
00329 $sourceNode =& XMLCustomWriter::createChildWithText($doc, $root, 'source', $source, false);
00330 if ($sourceNode) XMLCustomWriter::setAttribute($sourceNode, 'locale', $locale);
00331 unset($sourceNode);
00332 }
00333
00334 import('file.PaperFileManager');
00335 $paperFileManager = new PaperFileManager($paper->getId());
00336 $fileNode =& XMLCustomWriter::createElement($doc, 'file');
00337 XMLCustomWriter::appendChild($root, $fileNode);
00338 $embedNode =& XMLCustomWriter::createChildWithText($doc, $fileNode, 'embed', base64_encode($paperFileManager->readFile($suppFile->getFileId())));
00339 XMLCustomWriter::setAttribute($embedNode, 'filename', $suppFile->getOriginalFileName());
00340 XMLCustomWriter::setAttribute($embedNode, 'encoding', 'base64');
00341 XMLCustomWriter::setAttribute($embedNode, 'mime_type', $suppFile->getFileType());
00342
00343 return $root;
00344 }
00345
00346 function formatDate($date) {
00347 if ($date == '') return null;
00348 return date('Y-m-d', strtotime($date));
00349 }
00350 }
00351
00352 ?>