/** * Return string containing the contents of the HTML file. * This function performs any necessary filtering, like image URL replacement. * @param $baseImageUrl string base URL for image references * @return string */ function getHTMLContents() { import('file.PaperFileManager'); $fileManager = new PaperFileManager($this->getPaperId()); $contents = $fileManager->readFile($this->getFileId()); // Replace image references $images =& $this->getImageFiles(); foreach ($images as $image) { $imageUrl = Request::url(null, 'paper', 'viewFile', array($this->getPaperId(), $this->getGalleyId(), $image->getFileId())); $pattern = preg_quote(rawurlencode($image->getOriginalFileName())); $contents = preg_replace('/[Ss][Rr][Cc]\\s*=\\s*"([^"]*' . $pattern . ')"/', 'src="' . $imageUrl . '"', $contents); $contents = preg_replace('/[Hh][Rr][Ee][Ff]\\s*=\\s*"([^"]*' . $pattern . ')"/', 'href="' . $imageUrl . '"', $contents); } // Perform replacement for ocs://... URLs $contents = preg_replace_callback('/(<[^<>]*")[Oo][Jj][Ss]:\\/\\/([^"]+)("[^<>]*>)/', array(&$this, '_handleOcsUrl'), $contents); // Perform variable replacement for site info etc. $schedConf =& Request::getSchedConf(); $site =& Request::getSite(); $paramArray = array('confTitle' => $schedConf->getSchedConfTitle(), 'siteTitle' => $site->getLocalizedTitle(), 'currentUrl' => Request::getRequestUrl()); foreach ($paramArray as $key => $value) { $contents = str_replace('{$' . $key . '}', $value, $contents); } return $contents; }
function &generateSuppFileDom(&$doc, &$schedConf, &$paper, &$suppFile) { $root =& XMLCustomWriter::createElement($doc, 'supplemental_file'); // FIXME: These should be constants! switch ($suppFile->getType()) { case __('author.submit.suppFile.researchInstrument'): $suppFileType = 'research_instrument'; break; case __('author.submit.suppFile.researchMaterials'): $suppFileType = 'research_materials'; break; case __('author.submit.suppFile.researchResults'): $suppFileType = 'research_results'; break; case __('author.submit.suppFile.transcripts'): $suppFileType = 'transcripts'; break; case __('author.submit.suppFile.dataAnalysis'): $suppFileType = 'data_analysis'; break; case __('author.submit.suppFile.dataSet'): $suppFileType = 'data_set'; break; case __('author.submit.suppFile.sourceText'): $suppFileType = 'source_text'; break; default: $suppFileType = 'other'; break; } XMLCustomWriter::setAttribute($root, 'type', $suppFileType); XMLCustomWriter::setAttribute($root, 'public_id', $suppFile->getPublicSuppFileId(), false); XMLCustomWriter::setAttribute($root, 'language', $suppFile->getLanguage(), false); if (is_array($suppFile->getTitle(null))) { foreach ($suppFile->getTitle(null) as $locale => $title) { $titleNode =& XMLCustomWriter::createChildWithText($doc, $root, 'title', $title, false); if ($titleNode) { XMLCustomWriter::setAttribute($titleNode, 'locale', $locale); } unset($titleNode); } } if (is_array($suppFile->getCreator(null))) { foreach ($suppFile->getCreator(null) as $locale => $creator) { $creatorNode =& XMLCustomWriter::createChildWithText($doc, $root, 'creator', $creator, false); if ($creatorNode) { XMLCustomWriter::setAttribute($creatorNode, 'locale', $locale); } unset($creatorNode); } } if (is_array($suppFile->getSubject(null))) { foreach ($suppFile->getSubject(null) as $locale => $subject) { $subjectNode =& XMLCustomWriter::createChildWithText($doc, $root, 'subject', $subject, false); if ($subjectNode) { XMLCustomWriter::setAttribute($subjectNode, 'locale', $locale); } unset($subjectNode); } } if ($suppFileType == 'other') { if (is_array($suppFile->getTypeOther(null))) { foreach ($suppFile->getTypeOther(null) as $locale => $typeOther) { $typeOtherNode =& XMLCustomWriter::createChildWithText($doc, $root, 'type_other', $typeOther, false); if ($typeOtherNode) { XMLCustomWriter::setAttribute($typeOtherNode, 'locale', $locale); } unset($typeOtherNode); } } } if (is_array($suppFile->getDescription(null))) { foreach ($suppFile->getDescription(null) as $locale => $description) { $descriptionNode =& XMLCustomWriter::createChildWithText($doc, $root, 'description', $description, false); if ($descriptionNode) { XMLCustomWriter::setAttribute($descriptionNode, 'locale', $locale); } unset($descriptionNode); } } if (is_array($suppFile->getPublisher(null))) { foreach ($suppFile->getPublisher(null) as $locale => $publisher) { $publisherNode =& XMLCustomWriter::createChildWithText($doc, $root, 'publisher', $publisher, false); if ($publisherNode) { XMLCustomWriter::setAttribute($publisherNode, 'locale', $locale); } unset($publisherNode); } } if (is_array($suppFile->getSponsor(null))) { foreach ($suppFile->getSponsor(null) as $locale => $sponsor) { $sponsorNode =& XMLCustomWriter::createChildWithText($doc, $root, 'sponsor', $sponsor, false); if ($sponsorNode) { XMLCustomWriter::setAttribute($sponsorNode, 'locale', $locale); } unset($sponsorNode); } } XMLCustomWriter::createChildWithText($doc, $root, 'date_created', NativeExportDom::formatDate($suppFile->getDateCreated()), false); if (is_array($suppFile->getSource(null))) { foreach ($suppFile->getSource(null) as $locale => $source) { $sourceNode =& XMLCustomWriter::createChildWithText($doc, $root, 'source', $source, false); if ($sourceNode) { XMLCustomWriter::setAttribute($sourceNode, 'locale', $locale); } unset($sourceNode); } } import('classes.file.PaperFileManager'); $paperFileManager = new PaperFileManager($paper->getId()); $fileNode =& XMLCustomWriter::createElement($doc, 'file'); XMLCustomWriter::appendChild($root, $fileNode); $embedNode =& XMLCustomWriter::createChildWithText($doc, $fileNode, 'embed', base64_encode($paperFileManager->readFile($suppFile->getFileId()))); XMLCustomWriter::setAttribute($embedNode, 'filename', $suppFile->getOriginalFileName()); XMLCustomWriter::setAttribute($embedNode, 'encoding', 'base64'); XMLCustomWriter::setAttribute($embedNode, 'mime_type', $suppFile->getFileType()); return $root; }