16 import(
'lib.pkp.classes.plugins.GenericPlugin');
22 function register($category, $path, $mainContextId =
null) {
23 if (!parent::register($category, $path, $mainContextId))
return false;
25 HookRegistry::register(
'ArticleHandler::view::galley', array($this,
'articleViewCallback'), HOOK_SEQUENCE_LATE);
26 HookRegistry::register(
'ArticleHandler::download', array($this,
'articleDownloadCallback'), HOOK_SEQUENCE_LATE);
44 return __(
'plugins.generic.htmlArticleGalley.displayName');
51 return __(
'plugins.generic.htmlArticleGalley.description');
65 if ($galley && $galley->getFileType() ==
'text/html') {
66 foreach ($article->getData(
'publications') as $publication) {
67 if ($publication->getId() === $galley->getData(
'publicationId')) {
68 $galleyPublication = $publication;
73 $templateMgr->assign(array(
75 'article' => $article,
77 'isLatestPublication' => $article->getData(
'currentPublicationId') === $galley->getData(
'publicationId'),
78 'galleyPublication' => $galleyPublication,
99 if ($galley && $galley->getFileType() ==
'text/html' && $galley->getFileId() == $fileId) {
100 if (!
HookRegistry::call(
'HtmlArticleGalleyPlugin::articleDownload', array($article, &$galley, &$fileId))) {
103 HookRegistry::call(
'HtmlArticleGalleyPlugin::articleDownloadFinished', array(&$returner));
120 $submissionFile = $galley->getFile();
121 $submissionId = $submissionFile->getSubmissionId();
122 $contents = file_get_contents($submissionFile->getFilePath());
126 import(
'lib.pkp.classes.submission.SubmissionFile');
127 $embeddableFiles = array_merge(
128 $submissionFileDao->getLatestRevisions($submissionId, SUBMISSION_FILE_PROOF),
129 $submissionFileDao->getLatestRevisionsByAssocId(ASSOC_TYPE_SUBMISSION_FILE, $submissionFile->getFileId(), $submissionId, SUBMISSION_FILE_DEPENDENT)
131 $referredArticle =
null;
134 foreach ($embeddableFiles as $embeddableFile) {
137 if ($embeddableFile->getFileType()==
'text/plain' || $embeddableFile->getFileType()==
'text/css') $params[
'inline']=
'true';
140 if (!$referredArticle || $referredArticle->getId() != $submissionId) {
141 $referredArticle = $submissionDao->getById($submissionId);
143 $fileUrl =
$request->url(
null,
'article',
'download', array($referredArticle->getBestId(), $galley->getBestGalleyId(), $embeddableFile->getFileId()), $params);
144 $pattern = preg_quote(rawurlencode($embeddableFile->getOriginalFileName()));
146 $contents = preg_replace(
147 '/([Ss][Rr][Cc]|[Hh][Rr][Ee][Ff]|[Dd][Aa][Tt][Aa])\s*=\s*"([^"]*' . $pattern .
')"/',
148 '\1="' . $fileUrl .
'"',
153 $contents = preg_replace(
154 '/[Uu][Rr][Ll]\s*\:\s*\'(' . $pattern .
')\'/',
155 'url:\'' . $fileUrl .
'\'',
160 $contents = preg_replace(
161 '/[Uu][Rr][Ll]=([^"]*' . $pattern .
')/',
169 $contents = preg_replace_callback(
170 '/(<[^<>]*")[Oo][Jj][Ss]:\/\/([^"]+)("[^<>]*>)/',
171 array($this,
'_handleOjsUrl'),
176 $contents = $templateMgr->loadHtmlGalleyStyles($contents, $embeddableFiles);
180 $issue = $issueDao->getBySubmissionId($submissionId);
186 'issueTitle' => $issue?$issue->getIssueIdentification():__(
'editor.article.scheduleForPublication.toBeAssigned'),
187 'journalTitle' => $journal->getLocalizedName(),
188 'siteTitle' => $site->getLocalizedTitle(),
189 'currentUrl' =>
$request->getRequestUrl()
192 foreach ($paramArray as $key => $value) {
193 $contents = str_replace(
'{$' . $key .
'}', $value, $contents);
201 $url = $matchArray[2];
203 if (($i = strpos($url,
'#')) !==
false) {
204 $anchor = substr($url, $i+1);
205 $url = substr($url, 0, $i);
207 $urlParts = explode(
'/', $url);
211 isset($urlParts[1]) ?
213 $request->getRequestedJournalPath(),
222 if (isset($urlParts[1])) {
234 if (isset($urlParts[1])) {
255 array_shift($urlParts);
256 import (
'classes.file.PublicFileManager');
258 $url =
$request->getBaseUrl() .
'/' . $publicFileManager->getSiteFilesPath() .
'/' . implode(
'/', $urlParts) . ($anchor?
'#' . $anchor:
'');
261 array_shift($urlParts);
263 import (
'classes.file.PublicFileManager');
265 $url =
$request->getBaseUrl() .
'/' . $publicFileManager->getContextFilesPath($journal->getId()) .
'/' . implode(
'/', $urlParts) . ($anchor?
'#' . $anchor:
'');
268 return $matchArray[1] . $url . $matchArray[3];