-
Notifications
You must be signed in to change notification settings - Fork 24
/
FullTextArticleHandler.inc.php
68 lines (54 loc) · 2.16 KB
/
FullTextArticleHandler.inc.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<?php
import('pages.article.ArticleHandler');
class FullTextArticleHandler extends ArticleHandler {
var $_plugin;
/**
* Constructor
*/
function __construct() {
parent::__construct();
$this->_plugin = PluginRegistry::getPlugin('generic', JATSPARSER_PLUGIN_NAME);
}
/**
* @param $args
* @param $request
* @brief download supplementary files for article's full-text
*/
function downloadFullTextAssoc($args, $request) {
$fileId = $args[2];
$dispatcher = $request->getDispatcher(); /** @var $dispatcher Dispatcher */
if (empty($fileId) || !$this->article || !$this->publication) $dispatcher->handle404();
if (!$this->userCanViewGalley($request, $this->article->getId())) {
header('HTTP/1.0 403 Forbidden');
echo '403 Forbidden<br>';
exit;
}
$fullTextFileIds = $this->publication->getData('jatsParser::fullTextFileId');
if (empty($fullTextFileIds)) $dispatcher->handle404();
// Find if the file is an image dependent from the XML file, from which full-text was generated.
import('lib.pkp.classes.submission.SubmissionFile'); // const
$dependentFilesIterator = Services::get('submissionFile')->getMany([
'assocTypes' => [ASSOC_TYPE_SUBMISSION_FILE],
'assocIds' => array_values($fullTextFileIds),
'submissionIds' => [$this->article->getId()],
'fileStages' => [SUBMISSION_FILE_DEPENDENT],
'includeDependentFiles' => true,
]);
if (is_null($dependentFilesIterator->current())) $dispatcher->handle404();
$submissionFile = null;
foreach ($dependentFilesIterator as $dependentFile) {
if ($fileId == $dependentFile->getData('fileId')) {
$submissionFile = $dependentFile;
break;
}
}
if (!$submissionFile) $dispatcher->handle404();
if (!in_array($submissionFile->getData('mimetype'), $this->_plugin::getSupportedSupplFileTypes())) $dispatcher->handle404();
// Download file if exists
if (!Services::get('file')->fs->has($submissionFile->getData('path'))) {
$request->getDispatcher()->handle404();
}
$filename = Services::get('file')->formatFilename($submissionFile->getData('path'), $submissionFile->getLocalizedData('name'));
Services::get('file')->download($submissionFile->getData('fileId'), $filename);
}
}