17 import(
'classes.handler.Handler');
19 use \Firebase\JWT\JWT;
47 function authorize($request, &$args, $roleAssignments) {
49 if ($header = array_search(
'Authorization', array_flip(getallheaders()))) {
50 list($bearer, $jwt) = explode(
' ', $header);
51 if (strcasecmp($bearer,
'Bearer') == 0) {
52 $apiToken = json_decode(JWT::decode($jwt,
Config::getVar(
'security',
'api_key_secret',
''), array(
'HS256')));
57 import(
'lib.pkp.classes.security.authorization.ContextRequiredPolicy');
60 import(
'classes.security.authorization.OjsJournalMustPublishPolicy');
63 return parent::authorize($request, $args, $roleAssignments);
71 $urlPath = empty($args) ? 0 : array_shift($args);
74 $submission =
Services::get(
'submission')->getByUrlPath($urlPath, $request->getContext()->getId());
76 if (!$submission && ctype_digit((
string) $urlPath)) {
78 if (!$submission || $request->getContext()->getId() != $submission->getContextId()) $submission =
null;
81 if (!$submission || $submission->getData(
'status') !== STATUS_PUBLISHED) {
82 $request->getDispatcher()->handle404();
87 $currentUrlPath = $submission->getBestId();
88 if ($currentUrlPath && $currentUrlPath != $urlPath) {
89 $newArgs = array_merge([$currentUrlPath], $args);
90 $request->redirect(
null, $request->getRequestedPage(), $request->getRequestedOp(), $newArgs);
93 $this->article = $submission;
96 $subPath = empty($args) ? 0 : array_shift($args);
97 if ($subPath ===
'version') {
98 $publicationId = (int) array_shift($args);
99 $galleyId = empty($args) ? 0 : array_shift($args);
100 foreach ((array) $this->article->getData(
'publications') as
$publication) {
105 if (!$this->publication) {
106 $request->getDispatcher()->handle404();
109 $this->publication = $this->article->getCurrentPublication();
110 $galleyId = $subPath;
113 if ($this->publication->getData(
'status') !== STATUS_PUBLISHED) {
114 $request->getDispatcher()->handle404();
117 if ($galleyId && in_array($request->getRequestedOp(), [
'view',
'download'])) {
118 $galleys = (array) $this->publication->getData(
'galleys');
119 foreach ($galleys as
$galley) {
120 if (
$galley->getBestGalleyId() == $galleyId) {
128 if (!$this->galley) {
129 $publications = $submission->getPublishedPublications();
132 if (
$galley->getBestGalleyId() == $galleyId) {
133 $request->redirect(
null, $request->getRequestedPage(), $request->getRequestedOp(), [$submission->getBestId()]);
137 $request->getDispatcher()->handle404();
142 $this->fileId = array_shift($args);
146 if ($this->publication->getData(
'issueId')) {
148 $this->issue = $issueDao->getById($this->publication->getData(
'issueId'), $submission->getData(
'contextId'),
true);
157 function view($args, $request) {
159 $user = $request->getUser();
164 $templateMgr->assign(array(
168 'firstPublication' => reset(
$article->getData(
'publications')),
169 'currentPublication' =>
$article->getCurrentPublication(),
170 'galley' => $this->galley,
171 'fileId' => $this->fileId,
176 $templateMgr->assign([
179 'section' => $sectionDao->getById(
$publication->getData(
'sectionId')),
187 $templateMgr->assign([
188 'categories' => $categoryDao->getByPublicationId(
$publication->getId())->toArray()
193 $primaryGalleys = array();
194 $supplementaryGalleys = array();
197 $primaryGenres = $genreDao->getPrimaryByContextId(
$context->getId())->toArray();
198 $primaryGenreIds = array_map(
function($genre) {
199 return $genre->getId();
201 $supplementaryGenres = $genreDao->getBySupplementaryAndContextId(
true,
$context->getId())->toArray();
202 $supplementaryGenreIds = array_map(
function($genre) {
203 return $genre->getId();
204 }, $supplementaryGenres);
206 foreach ($galleys as
$galley) {
207 $remoteUrl =
$galley->getRemoteURL();
209 if (!$remoteUrl && !$file) {
212 if ($remoteUrl || in_array($file->getGenreId(), $primaryGenreIds)) {
214 } elseif (in_array($file->getGenreId(), $supplementaryGenreIds)) {
215 $supplementaryGalleys[] =
$galley;
219 $templateMgr->assign(array(
220 'primaryGalleys' => $primaryGalleys,
221 'supplementaryGalleys' => $supplementaryGalleys,
227 $parsedCitations = $citationDao->getByPublicationId(
$publication->getId());
228 $templateMgr->assign([
229 'parsedCitations' => $parsedCitations->toArray(),
235 $templateMgr->assign([
236 'licenseTerms' =>
$context->getLocalizedData(
'licenseTerms'),
238 'copyrightHolder' =>
$publication->getData(
'copyrightHolder'),
239 'copyrightYear' =>
$publication->getData(
'copyrightYear'),
245 if ($this->galley && $this->galley->getRemoteURL()) $request->redirectUrl($this->galley->getRemoteURL());
247 if (empty($this->galley)) {
252 $templateMgr->addHeader(
'noindex',
'<meta name="robots" content="noindex">');
253 $url = $request->getDispatcher()->url($request, ROUTE_PAGE,
null,
'article',
'view',
$article->getBestId());
254 $templateMgr->addHeader(
'canonical',
'<link rel="canonical" href="' . $url .
'">');
259 import(
'classes.issue.IssueAction');
264 $subscriptionRequired =
false;
266 $subscriptionRequired = $issueAction->subscriptionRequired(
$issue,
$context);
273 $templateMgr->assign(
'hasAccess',
274 !$subscriptionRequired ||
275 $publication->getData(
'accessStatus') == ARTICLE_ACCESS_OPEN ||
276 $subscribedUser || $subscribedDomain ||
277 ($user &&
$issue && $completedPaymentDao->hasPaidPurchaseIssue($user->getId(),
$issue->getId())) ||
278 ($user && $completedPaymentDao->hasPaidPurchaseArticle($user->getId(),
$article->getId()))
282 if ( $paymentManager->onlyPdfEnabled() ) {
283 $templateMgr->assign(
'restrictOnlyPdf',
true);
285 if ( $paymentManager->purchaseArticleEnabled() ) {
286 $templateMgr->assign(
'purchaseArticleEnabled',
true);
290 return $templateMgr->display(
'frontend/pages/article.tpl');
296 $templateMgr->addHeader(
'noindex',
'<meta name="robots" content="noindex">');
301 if ($this->publication->getId() !== $this->article->getCurrentPublication()->getId()) {
306 $this->galley->getBestGalleyId()
311 $this->galley->getBestGalleyId()
314 $request->redirect(
null,
null,
'download', $redirectPath);
326 $articleId = isset($args[0]) ? $args[0] : 0;
327 $galleyId = isset($args[1]) ? $args[1] : 0;
328 $fileId = isset($args[2]) ? (int) $args[2] : 0;
329 header(
'HTTP/1.1 301 Moved Permanently');
330 $request->redirect(
null,
null,
'download', array($articleId, $galleyId,
$fileId));
340 $articleId = isset($args[0]) ? $args[0] : 0;
343 $dispatcher = $request->getDispatcher();
344 $dispatcher->handle404();
346 $suppId = isset($args[1]) ? $args[1] : 0;
348 $submissionFiles = $submissionFileDao->getBySubmissionId($articleId);
349 foreach ($submissionFiles as $submissionFile) {
350 if ($submissionFile->getData(
'old-supp-id') == $suppId) {
352 $articleGalleys = $articleGalleyDao->getByPublicationId(
$article->getCurrentPublication()->getId());
353 while ($articleGalley = $articleGalleys->next()) {
354 $galleyFile = $articleGalley->getFile();
355 if ($galleyFile && $galleyFile->getFileId() == $submissionFile->getFileId()) {
356 header(
'HTTP/1.1 301 Moved Permanently');
357 $request->redirect(
null,
null,
'download', array($articleId, $articleGalley->getId(), $submissionFile->getFileId()));
362 $dispatcher = $request->getDispatcher();
363 $dispatcher->handle404();
373 if (!isset($this->galley)) $request->getDispatcher()->handle404();
374 if ($this->galley->getRemoteURL()) $request->redirectUrl($this->galley->getRemoteURL());
375 else if ($this->
userCanViewGalley($request, $this->article->getId(), $this->galley->getId())) {
376 if (!$this->fileId) {
377 $submissionFile = $this->galley->getFile();
378 if ($submissionFile) {
379 $this->fileId = $submissionFile->getFileId();
385 if (!$this->fileId) $request->getDispatcher()->handle404();
388 if ($this->fileId != $this->galley->getFileId()) {
390 $dependentFileIds = array_map(
391 function($f) {
return $f->getFileId();},
392 $submissionFileDao->getLatestRevisionsByAssocId(ASSOC_TYPE_SUBMISSION_FILE, $this->galley->getFileId(), $this->article->getId(), SUBMISSION_FILE_DEPENDENT)
394 if (!in_array($this->fileId, $dependentFileIds)) $request->getDispatcher()->handle404();
397 if (!
HookRegistry::call(
'ArticleHandler::download', array($this->article, &$this->galley, &$this->fileId))) {
398 import(
'lib.pkp.classes.file.SubmissionFileManager');
399 $submissionFileManager =
new SubmissionFileManager($this->article->getContextId(), $this->article->getId());
400 $submissionFileManager->downloadById($this->fileId,
null, $request->getUserVar(
'inline')?
true:
false);
403 header(
'HTTP/1.0 403 Forbidden');
404 echo
'403 Forbidden<br>';
416 import(
'classes.issue.IssueAction');
423 $user = $request->getUser();
424 $userId = $user?$user->getId():0;
428 if ($submission && $issueAction->allowedPrePublicationAccess(
$context, $submission, $user)) {
433 if (
$issue &&
$issue->getPublished() && $submission->getStatus() == STATUS_PUBLISHED) {
434 $subscriptionRequired = $issueAction->subscriptionRequired(
$issue,
$context);
435 $isSubscribedDomain = $issueAction->subscribedDomain($request,
$context,
$issue->getId(), $submission->getId());
444 if ( (!$isSubscribedDomain && $subscriptionRequired) && (isset($galleyId) && $galleyId) ) {
447 $subscribedUser = $issueAction->subscribedUser($user,
$context,
$issue->getId(), $submission->getId());
449 import(
'classes.payment.ojs.OJSPaymentManager');
452 $purchasedIssue =
false;
453 if (!$subscribedUser && $paymentManager->purchaseIssueEnabled()) {
455 $purchasedIssue = $completedPaymentDao->hasPaidPurchaseIssue($userId,
$issue->getId());
458 if (!(!$subscriptionRequired || $submission->getCurrentPublication()->getData(
'accessStatus') == ARTICLE_ACCESS_OPEN || $subscribedUser || $purchasedIssue)) {
460 if ( $paymentManager->purchaseArticleEnabled() || $paymentManager->membershipEnabled() ) {
463 if ( $paymentManager->onlyPdfEnabled() ) {
465 if ($this->galley && !$this->galley->isPdfGalley() ) {
467 $this->article = $submission;
479 $dateEndMembership = $user->getSetting(
'dateEndMembership', 0);
480 if ($completedPaymentDao->hasPaidPurchaseArticle($userId, $submission->getId())
481 || (!is_null($dateEndMembership) && $dateEndMembership > time())) {
483 $this->article = $submission;
485 } elseif ($paymentManager->purchaseArticleEnabled()) {
486 $queuedPayment = $paymentManager->createQueuedPayment($request, PAYMENT_TYPE_PURCHASE_ARTICLE, $user->getId(), $submission->getId(),
$context->getData(
'purchaseArticleFee'));
487 $paymentManager->queuePayment($queuedPayment);
489 $paymentForm = $paymentManager->getPaymentForm($queuedPayment);
490 $paymentForm->display($request);
495 if (!isset($galleyId) || $galleyId) {
499 $request->redirect(
null,
'about',
'subscriptions');
504 $request->redirect(
null,
'search');
514 parent::setupTemplate($request);