16 import(
'lib.pkp.classes.plugins.GenericPlugin');
22 function register($category, $path, $mainContextId =
null) {
23 if (parent::register($category, $path, $mainContextId)) {
27 HookRegistry::register(
'ArticleHandler::download', array($this,
'articleDownloadCallback'), HOOK_SEQUENCE_LATE);
47 return __(
'plugins.generic.lensGalley.displayName');
54 return __(
'plugins.generic.lensGalley.description');
67 $submission =& $args[3];
70 if ($galley && in_array($galley->getFileType(), array(
'application/xml',
'text/xml'))) {
71 $galleyPublication =
null;
72 foreach ($submission->getData(
'publications') as $publication) {
73 if ($publication->getId() === $galley->getData(
'publicationId')) {
74 $galleyPublication = $publication;
78 $templateMgr->assign(array(
81 'pluginUrl' =>
$request->getBaseUrl() .
'/' . $this->getPluginPath(),
82 'galleyFile' => $galley->getFile(),
84 'article' => $submission,
85 'bestId' => $submission->getBestId(),
86 'isLatestPublication' => $submission->getData(
'currentPublicationId') === $galley->getData(
'publicationId'),
87 'galleyPublication' => $galleyPublication,
89 'jQueryUrl' => $this->_getJQueryUrl(
$request),
110 if ($galley && in_array($galley->getFileType(), array(
'application/xml',
'text/xml'))) {
111 $templateMgr->assign(array(
114 'pluginUrl' =>
$request->getBaseUrl() .
'/' . $this->getPluginPath(),
115 'galleyFile' => $galley->getFile(),
118 'jQueryUrl' => $this->_getJQueryUrl(
$request),
120 $templateMgr->addJavaScript(
124 'priority' => STYLE_SEQUENCE_CORE,
125 'contexts' =>
'frontend',
140 private function _getJQueryUrl(
$request) {
141 $min =
Config::getVar(
'general',
'enable_minified') ?
'.min' :
'';
143 return '//ajax.googleapis.com/ajax/libs/jquery/' . CDN_JQUERY_VERSION .
'/jquery' . $min .
'.js';
145 return $request->getBaseUrl() .
'/lib/pkp/lib/vendor/components/jquery/jquery' . $min .
'.js';
164 $article =& $args[0];
169 if ($galley && in_array($galley->getFileType(), array(
'application/xml',
'text/xml')) && $galley->getFileId() == $fileId) {
170 if (!
HookRegistry::call(
'LensGalleyPlugin::articleDownload', array($article, &$galley, &$fileId))) {
172 header(
'Content-Type: application/xml');
173 header(
'Content-Length: ' . strlen($xmlContents));
174 header(
'Content-Disposition: inline');
175 header(
'Cache-Control: private');
176 header(
'Pragma: public');
196 $submissionFile = $galley->getFile();
197 $contents = file_get_contents($submissionFile->getFilePath());
201 import(
'lib.pkp.classes.submission.SubmissionFile');
202 $embeddableFiles = array_merge(
203 $submissionFileDao->getLatestRevisions($submissionFile->getData(
'submissionId'), SUBMISSION_FILE_PROOF),
204 $submissionFileDao->getLatestRevisionsByAssocId(ASSOC_TYPE_SUBMISSION_FILE, $submissionFile->getFileId(), $submissionFile->getData(
'submissionId'), SUBMISSION_FILE_DEPENDENT)
206 $referredArticle = $referredPublication =
null;
209 foreach ($embeddableFiles as $embeddableFile) {
211 if (!$referredArticle || !$referredPublication || $referredPublication->getData(
'submissionId') != $referredArticle->getId() || $referredPublication->getId() != $galley->getData(
'publicationId')) {
212 $referredPublication = $publicationService->get($galley->getData(
'publicationId'));
213 $referredArticle = $submissionDao->getById($referredPublication->getData(
'submissionId'));
215 $fileUrl =
$request->url(
null,
'article',
'download', array($referredArticle->getBestArticleId(), $galley->getBestGalleyId(), $embeddableFile->getFileId()));
216 $pattern = preg_quote($embeddableFile->getOriginalFileName());
218 $contents = preg_replace(
219 $pattern=
'/([Ss][Rr][Cc]|[Hh][Rr][Ee][Ff]|[Dd][Aa][Tt][Aa])\s*=\s*"([^"]*' . $pattern .
')"/',
220 '\1="' . $fileUrl .
'"',
226 $contents = preg_replace_callback(
227 '/(<[^<>]*")[Oo][Jj][Ss]:\/\/([^"]+)("[^<>]*>)/',
228 array($this,
'_handleOjsUrl'),
234 $issue = $issueDao->getBySubmissionId($galley->getData(
'submissionId'));
240 'issueTitle' => $issue?$issue->getIssueIdentification():__(
'editor.article.scheduleForPublication.toBeAssigned'),
241 'journalTitle' => $journal->getLocalizedName(),
242 'siteTitle' => $site->getLocalizedTitle(),
243 'currentUrl' =>
$request->getRequestUrl(),
246 foreach ($paramArray as $key => $value) {
247 $contents = str_replace(
'{$' . $key .
'}', $value, $contents);
255 $url = $matchArray[2];
257 if (($i = strpos($url,
'#')) !==
false) {
258 $anchor = substr($url, $i+1);
259 $url = substr($url, 0, $i);
261 $urlParts = explode(
'/', $url);
265 isset($urlParts[1]) ?
267 $request->getRequestedJournalPath(),
276 if (isset($urlParts[1])) {
288 if (isset($urlParts[1])) {
309 array_shift($urlParts);
310 import (
'classes.file.PublicFileManager');
312 $url =
$request->getBaseUrl() .
'/' . $publicFileManager->getSiteFilesPath() .
'/' . implode(
'/', $urlParts) . ($anchor?
'#' . $anchor:
'');
315 array_shift($urlParts);
317 import (
'classes.file.PublicFileManager');
319 $url =
$request->getBaseUrl() .
'/' . $publicFileManager->getContextFilesPath($journal->getId()) .
'/' . implode(
'/', $urlParts) . ($anchor?
'#' . $anchor:
'');
322 return $matchArray[1] . $url . $matchArray[3];