/
ArticleHandler.inc.php
542 lines (469 loc) · 19.9 KB
/
ArticleHandler.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
<?php
/**
* @file ArticleHandler.inc.php
*
* Copyright (c) 2003-2010 John Willinsky
* Distributed under the GNU GPL v2. For full terms see the file docs/COPYING.
*
* @class ArticleHandler
* @ingroup pages_article
*
* @brief Handle requests for article functions.
*
*/
import('classes.rt.ojs.RTDAO');
import('classes.rt.ojs.JournalRT');
import('classes.handler.Handler');
import('classes.rt.ojs.SharingRT');
class ArticleHandler extends Handler {
/** journal associated with the request **/
var $journal;
/** issue associated with the request **/
var $issue;
/** article associated with the request **/
var $article;
/**
* Constructor
* @param $request Request
*/
function ArticleHandler(&$request) {
parent::Handler($request);
$router =& $request->getRouter();
$this->addCheck(new HandlerValidatorJournal($this));
$this->addCheck(new HandlerValidatorCustom($this, false, null, null, create_function('$journal', 'return $journal->getSetting(\'publishingMode\') != PUBLISHING_MODE_NONE;'), array($router->getContext($request))));
}
/**
* View Article.
* @param $args array
* @param $request Request
*/
function view($args, &$request) {
$router =& $request->getRouter();
$articleId = isset($args[0]) ? $args[0] : 0;
$galleyId = isset($args[1]) ? $args[1] : 0;
$this->validate($request, $articleId, $galleyId);
$journal =& $this->journal;
$issue =& $this->issue;
$article =& $this->article;
$this->setupTemplate();
$rtDao =& DAORegistry::getDAO('RTDAO');
$journalRt = $rtDao->getJournalRTByJournal($journal);
$sectionDao =& DAORegistry::getDAO('SectionDAO');
$section =& $sectionDao->getSection($article->getSectionId(), $journal->getId(), true);
$version = null;
if ($journalRt->getVersion()!=null && $journalRt->getDefineTerms()) {
// Determine the "Define Terms" context ID.
$version = $rtDao->getVersion($journalRt->getVersion(), $journalRt->getJournalId(), true);
if ($version) foreach ($version->getContexts() as $context) {
if ($context->getDefineTerms()) {
$defineTermsContextId = $context->getContextId();
break;
}
}
}
$commentDao =& DAORegistry::getDAO('CommentDAO');
$enableComments = $journal->getSetting('enableComments');
if (($article->getEnableComments()) && ($enableComments == COMMENTS_AUTHENTICATED || $enableComments == COMMENTS_UNAUTHENTICATED || $enableComments == COMMENTS_ANONYMOUS)) {
$comments =& $commentDao->getRootCommentsBySubmissionId($article->getId());
}
$galleyDao =& DAORegistry::getDAO('ArticleGalleyDAO');
if ($journal->getSetting('enablePublicGalleyId')) {
$galley =& $galleyDao->getGalleyByBestGalleyId($galleyId, $article->getId());
} else {
$galley =& $galleyDao->getGalley($galleyId, $article->getId());
}
if ($galley && !$galley->isHtmlGalley() && !$galley->isPdfGalley()) {
if ($galley->isInlineable()) {
$this->viewFile(
array($galley->getArticleId(), $galley->getId()),
$request
);
} else {
$this->download(
array($galley->getArticleId(), $galley->getId()),
$request
);
}
}
$templateMgr =& TemplateManager::getManager();
$templateMgr->addJavaScript('js/articleView.js');
$templateMgr->addJavaScript('js/pdfobject.js');
if (!$galley) {
// Get the subscription status if displaying the abstract;
// if access is open, we can display links to the full text.
import('classes.issue.IssueAction');
// The issue may not exist, if this is an editorial user
// and scheduling hasn't been completed yet for the article.
if ($issue) {
$templateMgr->assign('subscriptionRequired', IssueAction::subscriptionRequired($issue));
}
$templateMgr->assign('subscribedUser', IssueAction::subscribedUser($journal, isset($issue) ? $issue->getId() : null, isset($article) ? $article->getId() : null));
$templateMgr->assign('subscribedDomain', IssueAction::subscribedDomain($journal, isset($issue) ? $issue->getId() : null, isset($article) ? $article->getId() : null));
$templateMgr->assign('showGalleyLinks', $journal->getSetting('showGalleyLinks'));
import('classes.payment.ojs.OJSPaymentManager');
$paymentManager =& OJSPaymentManager::getManager();
if ( $paymentManager->onlyPdfEnabled() ) {
$templateMgr->assign('restrictOnlyPdf', true);
}
if ( $paymentManager->purchaseArticleEnabled() ) {
$templateMgr->assign('purchaseArticleEnabled', true);
}
// Article cover page.
$locale = Locale::getLocale();
if (isset($article) && $article->getLocalizedFileName() && $article->getLocalizedShowCoverPage() && !$article->getLocalizedHideCoverPageAbstract()) {
import('classes.file.PublicFileManager');
$publicFileManager = new PublicFileManager();
$coverPagePath = $request->getBaseUrl() . '/';
$coverPagePath .= $publicFileManager->getJournalFilesPath($journal->getId()) . '/';
$templateMgr->assign('coverPagePath', $coverPagePath);
$templateMgr->assign('coverPageFileName', $article->getLocalizedFileName());
$templateMgr->assign('width', $article->getLocalizedWidth());
$templateMgr->assign('height', $article->getLocalizedHeight());
$templateMgr->assign('coverPageAltText', $article->getLocalizedCoverPageAltText());
}
// References list.
// FIXME: We only display the edited raw citations right now. We also want
// to allow for generated citations to be displayed here (including a way for
// the reader to choose any of the installed citation styles for output), see #5938.
$citationDao =& DAORegistry::getDAO('CitationDAO'); /* @var $citationDao CitationDAO */
$citationFactory =& $citationDao->getObjectsByAssocId(ASSOC_TYPE_ARTICLE, $article->getId());
$templateMgr->assign('citationFactory', $citationFactory);
// Increment the published article's abstract views count
if (!$request->isBot()) {
$publishedArticleDao =& DAORegistry::getDAO('PublishedArticleDAO');
$publishedArticleDao->incrementViewsByArticleId($article->getId());
}
} else {
if (!$request->isBot() && !$galley->isPdfGalley()) {
// Increment the galley's views count.
// PDF galley views are counted in viewFile.
$galleyDao->incrementViews($galley->getId());
}
// Use the article's CSS file, if set.
if ($galley->isHTMLGalley() && $styleFile =& $galley->getStyleFile()) {
$templateMgr->addStyleSheet($router->url($request, null, 'article', 'viewFile', array(
$article->getId(),
$galley->getBestGalleyId($journal),
$styleFile->getFileId()
)));
}
}
$templateMgr->assign_by_ref('issue', $issue);
$templateMgr->assign_by_ref('article', $article);
$templateMgr->assign_by_ref('galley', $galley);
$templateMgr->assign_by_ref('section', $section);
$templateMgr->assign_by_ref('journalRt', $journalRt);
$templateMgr->assign_by_ref('version', $version);
$templateMgr->assign_by_ref('journal', $journal);
$templateMgr->assign('articleId', $articleId);
$templateMgr->assign('postingAllowed', (
($article->getEnableComments()) && (
$enableComments == COMMENTS_UNAUTHENTICATED ||
(($enableComments == COMMENTS_AUTHENTICATED ||
$enableComments == COMMENTS_ANONYMOUS) &&
Validation::isLoggedIn()))
));
$templateMgr->assign('enableComments', $enableComments);
$templateMgr->assign('postingLoginRequired', ($enableComments != COMMENTS_ANONYMOUS && !Validation::isLoggedIn()));
$templateMgr->assign('galleyId', $galleyId);
$templateMgr->assign('defineTermsContextId', isset($defineTermsContextId)?$defineTermsContextId:null);
$templateMgr->assign('comments', isset($comments)?$comments:null);
$templateMgr->assign('sharingEnabled', $journalRt->getSharingEnabled());
if($journalRt->getSharingEnabled()) {
$templateMgr->assign('sharingRequestURL', $request->getRequestURL());
$templateMgr->assign('sharingArticleTitle', $article->getArticleTitle());
$templateMgr->assign_by_ref('sharingUserName', $journalRt->getSharingUserName());
$templateMgr->assign_by_ref('sharingButtonStyle', $journalRt->getSharingButtonStyle());
$templateMgr->assign_by_ref('sharingDropDownMenu', $journalRt->getSharingDropDownMenu());
$templateMgr->assign_by_ref('sharingBrand', $journalRt->getSharingBrand());
$templateMgr->assign_by_ref('sharingDropDown', $journalRt->getSharingDropDown());
$templateMgr->assign_by_ref('sharingLanguage', $journalRt->getSharingLanguage());
$templateMgr->assign_by_ref('sharingLogo', $journalRt->getSharingLogo());
$templateMgr->assign_by_ref('sharingLogoBackground', $journalRt->getSharingLogoBackground());
$templateMgr->assign_by_ref('sharingLogoColor', $journalRt->getSharingLogoColor());
list($btnUrl, $btnWidth, $btnHeight) = SharingRT::sharingButtonImage($journalRt);
$templateMgr->assign('sharingButtonUrl', $btnUrl);
$templateMgr->assign('sharingButtonWidth', $btnWidth);
$templateMgr->assign('sharingButtonHeight', $btnHeight);
}
$templateMgr->assign('articleSearchByOptions', array(
'' => 'search.allFields',
ARTICLE_SEARCH_AUTHOR => 'search.author',
ARTICLE_SEARCH_TITLE => 'article.title',
ARTICLE_SEARCH_ABSTRACT => 'search.abstract',
ARTICLE_SEARCH_INDEX_TERMS => 'search.indexTerms',
ARTICLE_SEARCH_GALLEY_FILE => 'search.fullText'
));
$templateMgr->display('article/article.tpl');
}
/**
* Article interstitial page before PDF is shown
* @param $args array
* @param $request Request
* @param $galley ArticleGalley
*/
function viewPDFInterstitial($args, &$request, $galley = null) {
$articleId = isset($args[0]) ? $args[0] : 0;
$galleyId = isset($args[1]) ? $args[1] : 0;
$this->validate($request, $articleId, $galleyId);
$journal =& $this->journal;
$issue =& $this->issue;
$article =& $this->article;
$this->setupTemplate();
if (!$galley) {
$galleyDao =& DAORegistry::getDAO('ArticleGalleyDAO');
if ($journal->getSetting('enablePublicGalleyId')) {
$galley =& $galleyDao->getGalleyByBestGalleyId($galleyId, $article->getId());
} else {
$galley =& $galleyDao->getGalley($galleyId, $article->getId());
}
}
if (!$galley) $request->redirect(null, null, 'view', $articleId);
$templateMgr =& TemplateManager::getManager();
$templateMgr->assign('articleId', $articleId);
$templateMgr->assign('galleyId', $galleyId);
$templateMgr->assign_by_ref('galley', $galley);
$templateMgr->assign_by_ref('article', $article);
$templateMgr->display('article/pdfInterstitial.tpl');
}
/**
* Article interstitial page before a non-PDF, non-HTML galley is
* downloaded
* @param $args array
* @param $request Request
* @param $galley ArticleGalley
*/
function viewDownloadInterstitial($args, &$request, $galley = null) {
$articleId = isset($args[0]) ? $args[0] : 0;
$galleyId = isset($args[1]) ? $args[1] : 0;
$this->validate($request, $articleId, $galleyId);
$journal =& $this->journal;
$issue =& $this->issue;
$article =& $this->article;
$this->setupTemplate();
if (!$galley) {
$galleyDao =& DAORegistry::getDAO('ArticleGalleyDAO');
if ($journal->getSetting('enablePublicGalleyId')) {
$galley =& $galleyDao->getGalleyByBestGalleyId($galleyId, $article->getId());
} else {
$galley =& $galleyDao->getGalley($galleyId, $article->getId());
}
}
if (!$galley) $request->redirect(null, null, 'view', $articleId);
$templateMgr =& TemplateManager::getManager();
$templateMgr->assign('articleId', $articleId);
$templateMgr->assign('galleyId', $galleyId);
$templateMgr->assign_by_ref('galley', $galley);
$templateMgr->assign_by_ref('article', $article);
$templateMgr->display('article/interstitial.tpl');
}
/**
* Article view
* @param $args array
* @param $request Request
*/
function viewArticle($args, &$request) {
// This function is deprecated since the Reading Tools frameset was removed.
return $this->view($args, $request);
}
/**
* View a file (inlines file).
* @param $args array ($articleId, $galleyId, $fileId [optional])
* @param $request Request
*/
function viewFile($args, &$request) {
$articleId = isset($args[0]) ? $args[0] : 0;
$galleyId = isset($args[1]) ? $args[1] : 0;
$fileId = isset($args[2]) ? (int) $args[2] : 0;
$this->validate($request, $articleId, $galleyId);
$journal =& $this->journal;
$issue =& $this->issue;
$article =& $this->article;
$galleyDao =& DAORegistry::getDAO('ArticleGalleyDAO');
if ($journal->getSetting('enablePublicGalleyId')) {
$galley =& $galleyDao->getGalleyByBestGalleyId($galleyId, $article->getId());
} else {
$galley =& $galleyDao->getGalley($galleyId, $article->getId());
}
if (!$galley) $request->redirect(null, null, 'view', $articleId);
if (!$fileId) {
$galleyDao->incrementViews($galley->getId());
$fileId = $galley->getFileId();
} else {
if (!$galley->isDependentFile($fileId)) {
$request->redirect(null, null, 'view', $articleId);
}
}
if (!HookRegistry::call('ArticleHandler::viewFile', array(&$article, &$galley, &$fileId))) {
import('classes.submission.common.Action');
Action::viewFile($article->getId(), $fileId);
}
}
/**
* Downloads the document
* @param $args array
* @param $request Request
*/
function download($args, &$request) {
$articleId = isset($args[0]) ? $args[0] : 0;
$galleyId = isset($args[1]) ? $args[1] : 0;
$this->validate($request, $articleId, $galleyId);
$journal =& $this->journal;
$issue =& $this->issue;
$article =& $this->article;
$galleyDao =& DAORegistry::getDAO('ArticleGalleyDAO');
if ($journal->getSetting('enablePublicGalleyId')) {
$galley =& $galleyDao->getGalleyByBestGalleyId($galleyId, $article->getId());
} else {
$galley =& $galleyDao->getGalley($galleyId, $article->getId());
}
if ($galley) $galleyDao->incrementViews($galley->getId());
if ($article && $galley && !HookRegistry::call('$this->downloadFile', array(&$article, &$galley))) {
import('classes.file.ArticleFileManager');
$articleFileManager = new ArticleFileManager($article->getId());
$articleFileManager->downloadFile($galley->getFileId());
}
}
/**
* Download a supplementary file
* @param $args array
* @param $request Request
*/
function downloadSuppFile($args, &$request) {
$articleId = isset($args[0]) ? $args[0] : 0;
$suppId = isset($args[1]) ? $args[1] : 0;
$this->validate($request, $articleId);
$journal =& $this->journal;
$issue =& $this->issue;
$article =& $this->article;
$suppFileDao =& DAORegistry::getDAO('SuppFileDAO');
if ($journal->getSetting('enablePublicSuppFileId')) {
$suppFile =& $suppFileDao->getSuppFileByBestSuppFileId($article->getId(), $suppId);
} else {
$suppFile =& $suppFileDao->getSuppFile((int) $suppId, $article->getId());
}
if ($article && $suppFile) {
import('classes.file.ArticleFileManager');
$articleFileManager = new ArticleFileManager($article->getId());
if ($suppFile->isInlineable()) {
$articleFileManager->viewFile($suppFile->getFileId());
} else {
$articleFileManager->downloadFile($suppFile->getFileId());
}
}
}
/**
* Validation
* @see lib/pkp/classes/handler/PKPHandler#validate()
* @param $request Request
* @param $articleId integer
* @param $galleyId integer
*/
function validate(&$request, $articleId, $galleyId = null) {
$router =& $request->getRouter();
parent::validate(null, $request);
import('classes.issue.IssueAction');
$journal =& $router->getContext($request);
$journalId = $journal->getId();
$article = $publishedArticle = $issue = null;
$user =& $request->getUser();
$userId = $user?$user->getId():0;
$publishedArticleDao =& DAORegistry::getDAO('PublishedArticleDAO');
if ($journal->getSetting('enablePublicArticleId')) {
$publishedArticle =& $publishedArticleDao->getPublishedArticleByBestArticleId((int) $journalId, $articleId, true);
} else {
$publishedArticle =& $publishedArticleDao->getPublishedArticleByArticleId((int) $articleId, (int) $journalId, true);
}
$issueDao =& DAORegistry::getDAO('IssueDAO');
if (isset($publishedArticle)) {
$issue =& $issueDao->getIssueById($publishedArticle->getIssueId(), $publishedArticle->getJournalId(), true);
} else {
$articleDao =& DAORegistry::getDAO('ArticleDAO');
$article =& $articleDao->getArticle((int) $articleId, $journalId, true);
}
// If this is an editorial user who can view unpublished/unscheduled
// articles, bypass further validation. Likewise for its author.
if (($article || $publishedArticle) && (($article && IssueAction::allowedPrePublicationAccess($journal, $article) || ($publishedArticle && IssueAction::allowedPrePublicationAccess($journal, $publishedArticle))))) {
$this->journal =& $journal;
$this->issue =& $issue;
$this->article =& $publishedArticle?$publishedArticle:$article;
return true;
}
// Make sure the reader has rights to view the article/issue.
if ($issue && $issue->getPublished()) {
$subscriptionRequired = IssueAction::subscriptionRequired($issue);
$isSubscribedDomain = IssueAction::subscribedDomain($journal, $issue->getId(), $articleId);
// Check if login is required for viewing.
if (!$isSubscribedDomain && !Validation::isLoggedIn() && $journal->getSetting('restrictArticleAccess') && isset($galleyId) && $galleyId != 0) {
Validation::redirectLogin();
}
// bypass all validation if subscription based on domain or ip is valid
// or if the user is just requesting the abstract
if ( (!$isSubscribedDomain && $subscriptionRequired) &&
(isset($galleyId) && $galleyId!=0) ) {
// Subscription Access
$subscribedUser = IssueAction::subscribedUser($journal, $issue->getId(), $articleId);
if (!(!$subscriptionRequired || $publishedArticle->getAccessStatus() == ARTICLE_ACCESS_OPEN || $subscribedUser)) {
// if payment information is enabled,
import('classes.payment.ojs.OJSPaymentManager');
$paymentManager =& OJSPaymentManager::getManager();
if ( $paymentManager->purchaseArticleEnabled() || $paymentManager->membershipEnabled() ) {
/* if only pdf files are being restricted, then approve all non-pdf galleys
* and continue checking if it is a pdf galley */
if ( $paymentManager->onlyPdfEnabled() ) {
$galleyDAO =& DAORegistry::getDAO('ArticleGalleyDAO');
if ($journal->getSetting('enablePublicGalleyId')) {
$galley =& $galleyDAO->getGalley($galleyId, $articleId);
} else {
$galley =& $galleyDAO->getGalleyByBestGalleyId($galleyId, $articleId);
}
if ( $galley && !$galley->isPdfGalley() ) {
$this->journal =& $journal;
$this->issue =& $issue;
$this->article =& $publishedArticle;
return true;
}
}
if (!Validation::isLoggedIn()) {
Validation::redirectLogin("payment.loginRequired.forArticle");
}
/* if the article has been paid for then forget about everything else
* and just let them access the article */
$completedPaymentDAO =& DAORegistry::getDAO('OJSCompletedPaymentDAO');
$dateEndMembership = $user->getSetting('dateEndMembership', 0);
if ( $completedPaymentDAO->hasPaidPerViewArticle($userId, $articleId)
|| (!is_null($dateEndMembership) && $dateEndMembership > time()) ) {
$this->journal =& $journal;
$this->issue =& $issue;
$this->article =& $publishedArticle;
return true;
} else {
$queuedPayment =& $paymentManager->createQueuedPayment($journalId, PAYMENT_TYPE_PURCHASE_ARTICLE, $user->getId(), $articleId, $journal->getSetting('purchaseArticleFee'));
$queuedPaymentId = $paymentManager->queuePayment($queuedPayment);
$templateMgr =& TemplateManager::getManager();
$paymentManager->displayPaymentForm($queuedPaymentId, $queuedPayment);
exit;
}
}
if (!isset($galleyId) || $galleyId) {
if (!Validation::isLoggedIn()) {
Validation::redirectLogin("reader.subscriptionRequiredLoginText");
}
$request->redirect(null, 'about', 'subscriptions');
}
}
}
} else {
$request->redirect(null, 'index');
}
$this->journal =& $journal;
$this->issue =& $issue;
$this->article =& $publishedArticle;
return true;
}
function setupTemplate() {
parent::setupTemplate();
Locale::requireComponents(array(LOCALE_COMPONENT_PKP_READER, LOCALE_COMPONENT_PKP_SUBMISSION));
}
}
?>