/** * 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('classes.file.ArticleFileManager'); $fileManager = new ArticleFileManager($this->getArticleId()); $contents = $fileManager->readFile($this->getFileId()); $journal =& Request::getJournal(); // Replace media file references $images =& $this->getImageFiles(); foreach ($images as $image) { $imageUrl = Request::url(null, 'article', 'viewFile', array($this->getArticleId(), $this->getBestGalleyId($journal), $image->getFileId())); $pattern = preg_quote(rawurlencode($image->getOriginalFileName())); $contents = preg_replace('/([Ss][Rr][Cc]|[Hh][Rr][Ee][Ff]|[Dd][Aa][Tt][Aa])\\s*=\\s*"([^"]*' . $pattern . ')"/', '\\1="' . $imageUrl . '"', $contents); // Replacement for Flowplayer $contents = preg_replace('/[Uu][Rr][Ll]\\s*\\:\\s*\'(' . $pattern . ')\'/', 'url:\'' . $imageUrl . '\'', $contents); // Replacement for other players (ested with odeo; yahoo and google player won't work w/ OJS URLs, might work for others) $contents = preg_replace('/[Uu][Rr][Ll]=([^"]*' . $pattern . ')/', 'url=' . $imageUrl, $contents); } // Perform replacement for ojs://... URLs $contents = String::regexp_replace_callback('/(<[^<>]*")[Oo][Jj][Ss]:\\/\\/([^"]+)("[^<>]*>)/', array(&$this, '_handleOjsUrl'), $contents); // Perform variable replacement for journal, issue, site info $issueDao =& DAORegistry::getDAO('IssueDAO'); $issue =& $issueDao->getIssueByArticleId($this->getArticleId()); $journal =& Request::getJournal(); $site =& Request::getSite(); $paramArray = array('issueTitle' => $issue ? $issue->getIssueIdentification() : Locale::translate('editor.article.scheduleForPublication.toBeAssigned'), 'journalTitle' => $journal->getLocalizedTitle(), 'siteTitle' => $site->getLocalizedTitle(), 'currentUrl' => Request::getRequestUrl()); foreach ($paramArray as $key => $value) { $contents = str_replace('{$' . $key . '}', $value, $contents); } return $contents; }
function &generateSuppFileDom(&$doc, &$journal, &$issue, &$article, &$suppFile) { $root =& XMLCustomWriter::createElement($doc, 'supplemental_file'); NativeExportDom::generatePubId($doc, $root, $suppFile, $issue); // 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->getPubId('publisher-id'), false); XMLCustomWriter::setAttribute($root, 'language', $suppFile->getLanguage(), false); XMLCustomWriter::setAttribute($root, 'show_reviewers', $suppFile->getShowReviewers() ? 'true' : '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.ArticleFileManager'); $articleFileManager = new ArticleFileManager($article->getId()); $fileNode =& XMLCustomWriter::createElement($doc, 'file'); XMLCustomWriter::appendChild($root, $fileNode); if ($suppFile->getRemoteURL()) { $remoteNode =& XMLCustomWriter::createElement($doc, 'remote'); XMLCustomWriter::appendChild($fileNode, $remoteNode); XMLCustomWriter::setAttribute($remoteNode, 'src', $suppFile->getRemoteURL()); } else { $embedNode =& XMLCustomWriter::createChildWithText($doc, $fileNode, 'embed', base64_encode($articleFileManager->readFile($suppFile->getFileId()))); XMLCustomWriter::setAttribute($embedNode, 'filename', $suppFile->getOriginalFileName()); XMLCustomWriter::setAttribute($embedNode, 'encoding', 'base64'); XMLCustomWriter::setAttribute($embedNode, 'mime_type', $suppFile->getFileType()); } return $root; }
/** * Return string containing the contents of the HTML file. * This function performs any necessary filtering, like image URL replacement. * @param $fileId int optional file id, otherwise the 'best' file will be chosen. * @return string */ function _getHTMLContents($request, $galley, $fileId = null) { import('classes.file.ArticleFileManager'); $fileManager = new ArticleFileManager($galley->getSubmissionId()); if (!$fileId) { // Note: Some HTML file uploads may be stored with incorrect file_type settings // due to incorrect finfo or mime.magic entries. As such, we examine the file extension // of the original file name for 'htm'. This will match .html, .htm, .xhtml, etc. // The file_type isn't important since the plugin includes the HTML content inline rather // than including a URL loaded in an iframe. $file = $galley->getFirstGalleyFile('htm'); if ($file) { $fileId = $file->getFileId(); } else { assert(false); // No HTML file in this HTML Article galley? return false; } } $contents = $fileManager->readFile($fileId); $journal = $request->getJournal(); // Replace media file references $images = $this->_getImageFiles($galley, $fileId, $journal); foreach ($images as $image) { $imageUrl = $request->url(null, 'article', 'viewFile', array($galley->getSubmissionId(), $galley->getBestGalleyId($journal), $image->getFileId())); $pattern = preg_quote($image->getOriginalFileName()); $contents = preg_replace('/([Ss][Rr][Cc]|[Hh][Rr][Ee][Ff]|[Dd][Aa][Tt][Aa])\\s*=\\s*"([^"]*' . $pattern . ')"/', '\\1="' . $imageUrl . '"', $contents); // Replacement for Flowplayer $contents = preg_replace('/[Uu][Rr][Ll]\\s*\\:\\s*\'(' . $pattern . ')\'/', 'url:\'' . $imageUrl . '\'', $contents); // Replacement for other players (ested with odeo; yahoo and google player won't work w/ OJS URLs, might work for others) $contents = preg_replace('/[Uu][Rr][Ll]=([^"]*' . $pattern . ')/', 'url=' . $imageUrl, $contents); } // Perform replacement for ojs://... URLs $contents = preg_replace_callback('/(<[^<>]*")[Oo][Jj][Ss]:\\/\\/([^"]+)("[^<>]*>)/', array(&$this, '_handleOjsUrl'), $contents); // Perform variable replacement for journal, issue, site info $issueDao = DAORegistry::getDAO('IssueDAO'); $issue = $issueDao->getIssueByArticleId($galley->getSubmissionId()); $journal = $request->getJournal(); $site = $request->getSite(); $paramArray = array('issueTitle' => $issue ? $issue->getIssueIdentification() : __('editor.article.scheduleForPublication.toBeAssigned'), 'journalTitle' => $journal->getLocalizedName(), 'siteTitle' => $site->getLocalizedTitle(), 'currentUrl' => $request->getRequestUrl()); foreach ($paramArray as $key => $value) { $contents = str_replace('{$' . $key . '}', $value, $contents); } return $contents; }