View | Details | Raw Unified | Return to bug 4934 | Differences between
and this patch

Collapse All | Expand All

(-)pages/article/ArticleHandler.inc.php (-55 / +83 lines)
 Lines 24-55    Link Here 
24
class ArticleHandler extends Handler {
24
class ArticleHandler extends Handler {
25
	/** journal associated with the request **/
25
	/** journal associated with the request **/
26
	var $journal;
26
	var $journal;
27
	
27
28
	/** issue associated with the request **/
28
	/** issue associated with the request **/
29
	var $issue;
29
	var $issue;
30
	
30
31
	/** article associated with the request **/
31
	/** article associated with the request **/
32
	var $article;
32
	var $article;
33
33
34
	/**
34
	/**
35
	 * Constructor
35
	 * Constructor
36
	 **/
36
	 * @param $request Request
37
	function ArticleHandler() {
37
	 */
38
		parent::Handler();
38
	function ArticleHandler(&$request) {
39
		
39
		parent::Handler($request);
40
		$router =& $request->getRouter();
41
40
		$this->addCheck(new HandlerValidatorJournal($this));
42
		$this->addCheck(new HandlerValidatorJournal($this));
41
		$this->addCheck(new HandlerValidatorCustom($this, false, null, null, create_function('$journal', 'return $journal->getSetting(\'publishingMode\') != PUBLISHING_MODE_NONE;'), array(Request::getJournal())));
43
		$this->addCheck(new HandlerValidatorCustom($this, false, null, null, create_function('$journal', 'return $journal->getSetting(\'publishingMode\') != PUBLISHING_MODE_NONE;'), array($router->getContext($request))));
42
	}
44
	}
43
45
44
	/**
46
	/**
45
	 * View Article.
47
	 * View Article.
48
	 * @param $args array
49
	 * @param $request Request
46
	 */
50
	 */
47
	function view($args) {
51
	function view($args, &$request) {
52
		$router =& $request->getRouter();
53
48
		$articleId = isset($args[0]) ? $args[0] : 0;
54
		$articleId = isset($args[0]) ? $args[0] : 0;
49
		$galleyId = isset($args[1]) ? $args[1] : 0;
55
		$galleyId = isset($args[1]) ? $args[1] : 0;
50
56
51
		$this->setupTemplate();
57
		$this->setupTemplate();
52
		$this->validate($articleId, $galleyId);
58
		$this->validate($request, $articleId, $galleyId);
53
59
54
		$journal =& $this->journal;
60
		$journal =& $this->journal;
55
		$issue =& $this->issue;
61
		$issue =& $this->issue;
 Lines 66-82    Link Here 
66
		}
72
		}
67
73
68
		if (!$journalRt->getEnabled()) {
74
		if (!$journalRt->getEnabled()) {
69
			if (!$galley || $galley->isHtmlGalley()) return $this->viewArticle($args);
75
			if (!$galley || $galley->isHtmlGalley()) return $this->viewArticle($args, $request);
70
			else if ($galley->isPdfGalley()) return $this->viewPDFInterstitial($args, $galley);
76
			else if ($galley->isPdfGalley()) return $this->viewPDFInterstitial($args, $request, $galley);
71
			else if ($galley->isInlineable()) {
77
			else if ($galley->isInlineable()) {
72
				import('file.ArticleFileManager');
78
				import('file.ArticleFileManager');
73
				$articleFileManager = new ArticleFileManager($article->getArticleId());
79
				$articleFileManager = new ArticleFileManager($article->getArticleId());
74
				return $articleFileManager->viewFile($galley->getFileId());
80
				return $articleFileManager->viewFile($galley->getFileId());
75
			} else return $this->viewDownloadInterstitial($args, $galley);
81
			} else return $this->viewDownloadInterstitial($args, $request, $galley);
76
		}
82
		}
77
83
78
		if (!$article) {
84
		if (!$article) {
79
			Request::redirect(null, Request::getRequestedPage());
85
			$request->redirect(null, $router->getRequestedPage($request));
80
			return;
86
			return;
81
		}
87
		}
82
88
 Lines 91-108    Link Here 
91
97
92
	/**
98
	/**
93
	 * Article interstitial page before PDF is shown
99
	 * Article interstitial page before PDF is shown
100
	 * @param $args array
101
	 * @param $request Request
102
	 * @param $galley ArticleGalley
94
	 */
103
	 */
95
	function viewPDFInterstitial($args, $galley = null) {
104
	function viewPDFInterstitial($args, &$request, $galley = null) {
96
		$articleId = isset($args[0]) ? $args[0] : 0;
105
		$articleId = isset($args[0]) ? $args[0] : 0;
97
		$galleyId = isset($args[1]) ? $args[1] : 0;
106
		$galleyId = isset($args[1]) ? $args[1] : 0;
98
		$this->validate($articleId, $galleyId);
107
		$this->validate($request, $articleId, $galleyId);
99
		$journal =& $this->journal;
108
		$journal =& $this->journal;
100
		$issue =& $this->issue;
109
		$issue =& $this->issue;
101
		$article =& $this->article;		
110
		$article =& $this->article;
102
		$this->setupTemplate();
111
		$this->setupTemplate();
103
112
104
		if (!$galley || !is_a($galley, 'ArticleGalley')) {
113
		if (!$galley) {
105
			unset($galley);
106
			$galleyDao =& DAORegistry::getDAO('ArticleGalleyDAO');
114
			$galleyDao =& DAORegistry::getDAO('ArticleGalleyDAO');
107
			if ($journal->getSetting('enablePublicGalleyId')) {
115
			if ($journal->getSetting('enablePublicGalleyId')) {
108
				$galley =& $galleyDao->getGalleyByBestGalleyId($galleyId, $article->getArticleId());
116
				$galley =& $galleyDao->getGalleyByBestGalleyId($galleyId, $article->getArticleId());
 Lines 111-117    Link Here 
111
			}
119
			}
112
		}
120
		}
113
121
114
		if (!$galley) Request::redirect(null, null, 'view', $articleId);
122
		if (!$galley) $request->redirect(null, null, 'view', $articleId);
115
123
116
		$templateMgr =& TemplateManager::getManager();
124
		$templateMgr =& TemplateManager::getManager();
117
		$templateMgr->assign('articleId', $articleId);
125
		$templateMgr->assign('articleId', $articleId);
 Lines 125-142    Link Here 
125
	/**
133
	/**
126
	 * Article interstitial page before a non-PDF, non-HTML galley is
134
	 * Article interstitial page before a non-PDF, non-HTML galley is
127
	 * downloaded
135
	 * downloaded
136
	 * @param $args array
137
	 * @param $request Request
138
	 * @param $galley ArticleGalley
128
	 */
139
	 */
129
	function viewDownloadInterstitial($args, $galley = null) {
140
	function viewDownloadInterstitial($args, &$request, $galley = null) {
130
		$articleId = isset($args[0]) ? $args[0] : 0;
141
		$articleId = isset($args[0]) ? $args[0] : 0;
131
		$galleyId = isset($args[1]) ? $args[1] : 0;
142
		$galleyId = isset($args[1]) ? $args[1] : 0;
132
		$this->validate($articleId, $galleyId);
143
		$this->validate($request, $articleId, $galleyId);
133
		$journal =& $this->journal;
144
		$journal =& $this->journal;
134
		$issue =& $this->issue;
145
		$issue =& $this->issue;
135
		$article =& $this->article;		
146
		$article =& $this->article;
136
		$this->setupTemplate();
147
		$this->setupTemplate();
137
148
138
		if (!$galley || !is_a($galley, 'ArticleGalley')) {
149
		if (!$galley) {
139
			unset($galley);
140
			$galleyDao =& DAORegistry::getDAO('ArticleGalleyDAO');
150
			$galleyDao =& DAORegistry::getDAO('ArticleGalleyDAO');
141
			if ($journal->getSetting('enablePublicGalleyId')) {
151
			if ($journal->getSetting('enablePublicGalleyId')) {
142
				$galley =& $galleyDao->getGalleyByBestGalleyId($galleyId, $article->getArticleId());
152
				$galley =& $galleyDao->getGalleyByBestGalleyId($galleyId, $article->getArticleId());
 Lines 145-151    Link Here 
145
			}
155
			}
146
		}
156
		}
147
157
148
		if (!$galley) Request::redirect(null, null, 'view', $articleId);
158
		if (!$galley) $request->redirect(null, null, 'view', $articleId);
149
159
150
		$templateMgr =& TemplateManager::getManager();
160
		$templateMgr =& TemplateManager::getManager();
151
		$templateMgr->assign('articleId', $articleId);
161
		$templateMgr->assign('articleId', $articleId);
 Lines 158-172    Link Here 
158
168
159
	/**
169
	/**
160
	 * Article view
170
	 * Article view
171
	 * @param $args array
172
	 * @param $request Request
161
	 */
173
	 */
162
	function viewArticle($args) {
174
	function viewArticle($args, &$request) {
175
		$router =& $request->getRouter();
163
		$articleId = isset($args[0]) ? $args[0] : 0;
176
		$articleId = isset($args[0]) ? $args[0] : 0;
164
		$galleyId = isset($args[1]) ? $args[1] : 0;
177
		$galleyId = isset($args[1]) ? $args[1] : 0;
165
178
166
		$this->validate($articleId, $galleyId);
179
		$this->validate($request, $articleId, $galleyId);
167
		$journal =& $this->journal;
180
		$journal =& $this->journal;
168
		$issue =& $this->issue;
181
		$issue =& $this->issue;
169
		$article =& $this->article;		
182
		$article =& $this->article;
170
		$this->setupTemplate();
183
		$this->setupTemplate();
171
184
172
		$rtDao =& DAORegistry::getDAO('RTDAO');
185
		$rtDao =& DAORegistry::getDAO('RTDAO');
 Lines 232-238    Link Here 
232
			if (isset($article) && $article->getLocalizedFileName() && $article->getLocalizedShowCoverPage() && !$article->getLocalizedHideCoverPageAbstract($locale)) {
245
			if (isset($article) && $article->getLocalizedFileName() && $article->getLocalizedShowCoverPage() && !$article->getLocalizedHideCoverPageAbstract($locale)) {
233
				import('file.PublicFileManager');
246
				import('file.PublicFileManager');
234
				$publicFileManager = new PublicFileManager();
247
				$publicFileManager = new PublicFileManager();
235
				$coverPagePath = Request::getBaseUrl() . '/';
248
				$coverPagePath = $request->getBaseUrl() . '/';
236
				$coverPagePath .= $publicFileManager->getJournalFilesPath($journal->getJournalId()) . '/';
249
				$coverPagePath .= $publicFileManager->getJournalFilesPath($journal->getJournalId()) . '/';
237
				$templateMgr->assign('coverPagePath', $coverPagePath);
250
				$templateMgr->assign('coverPagePath', $coverPagePath);
238
				$templateMgr->assign('coverPageFileName', $article->getLocalizedFileName());
251
				$templateMgr->assign('coverPageFileName', $article->getLocalizedFileName());
 Lines 242-260    Link Here 
242
			}
255
			}
243
256
244
			// Increment the published article's abstract views count
257
			// Increment the published article's abstract views count
245
			if (!Request::isBot()) {
258
			if (!$request->isBot()) {
246
				$publishedArticleDao =& DAORegistry::getDAO('PublishedArticleDAO');
259
				$publishedArticleDao =& DAORegistry::getDAO('PublishedArticleDAO');
247
				$publishedArticleDao->incrementViewsByArticleId($article->getArticleId());
260
				$publishedArticleDao->incrementViewsByArticleId($article->getArticleId());
248
			}
261
			}
249
		} else {
262
		} else {
250
			if (!Request::isBot()) {
263
			if (!$request->isBot()) {
251
				// Increment the galley's views count
264
				// Increment the galley's views count
252
				$galleyDao->incrementViews($galley->getGalleyId());
265
				$galleyDao->incrementViews($galley->getGalleyId());
253
			}
266
			}
254
267
255
			// Use the article's CSS file, if set.
268
			// Use the article's CSS file, if set.
256
			if ($galley->isHTMLGalley() && $styleFile =& $galley->getStyleFile()) {
269
			if ($galley->isHTMLGalley() && $styleFile =& $galley->getStyleFile()) {
257
				$templateMgr->addStyleSheet(Request::url(null, 'article', 'viewFile', array(
270
				$templateMgr->addStyleSheet($router->url(null, 'article', 'viewFile', array(
258
					$article->getArticleId(),
271
					$article->getArticleId(),
259
					$galley->getBestGalleyId($journal),
272
					$galley->getBestGalleyId($journal),
260
					$styleFile->getFileId()
273
					$styleFile->getFileId()
 Lines 284-294    Link Here 
284
		$templateMgr->assign('galleyId', $galleyId);
297
		$templateMgr->assign('galleyId', $galleyId);
285
		$templateMgr->assign('defineTermsContextId', isset($defineTermsContextId)?$defineTermsContextId:null);
298
		$templateMgr->assign('defineTermsContextId', isset($defineTermsContextId)?$defineTermsContextId:null);
286
		$templateMgr->assign('comments', isset($comments)?$comments:null);
299
		$templateMgr->assign('comments', isset($comments)?$comments:null);
287
		
300
288
		$templateMgr->assign('sharingEnabled', $journalRt->getSharingEnabled());
301
		$templateMgr->assign('sharingEnabled', $journalRt->getSharingEnabled());
289
		
302
290
		if($journalRt->getSharingEnabled()) {
303
		if($journalRt->getSharingEnabled()) {
291
			$templateMgr->assign('sharingRequestURL', Request::getRequestURL());
304
			$templateMgr->assign('sharingRequestURL', $request->getRequestURL());
292
			$templateMgr->assign('sharingArticleTitle', $article->getArticleTitle());
305
			$templateMgr->assign('sharingArticleTitle', $article->getArticleTitle());
293
			$templateMgr->assign_by_ref('sharingUserName', $journalRt->getSharingUserName());
306
			$templateMgr->assign_by_ref('sharingUserName', $journalRt->getSharingUserName());
294
			$templateMgr->assign_by_ref('sharingButtonStyle', $journalRt->getSharingButtonStyle());
307
			$templateMgr->assign_by_ref('sharingButtonStyle', $journalRt->getSharingButtonStyle());
 Lines 309-323    Link Here 
309
322
310
	/**
323
	/**
311
	 * Article Reading tools
324
	 * Article Reading tools
325
	 * @param $args array
326
	 * @param $request Request
312
	 */
327
	 */
313
	function viewRST($args) {
328
	function viewRST($args, &$request) {
314
		$articleId = isset($args[0]) ? $args[0] : 0;
329
		$articleId = isset($args[0]) ? $args[0] : 0;
315
		$galleyId = isset($args[1]) ? $args[1] : 0;
330
		$galleyId = isset($args[1]) ? $args[1] : 0;
316
331
317
		$this->validate($articleId, $galleyId);
332
		$this->validate($request, $articleId, $galleyId);
318
		$journal =& $this->journal;
333
		$journal =& $this->journal;
319
		$issue =& $this->issue;
334
		$issue =& $this->issue;
320
		$article =& $this->article;		
335
		$article =& $this->article;
321
		$this->setupTemplate();
336
		$this->setupTemplate();
322
337
323
		$rtDao =& DAORegistry::getDAO('RTDAO');
338
		$rtDao =& DAORegistry::getDAO('RTDAO');
 Lines 381-396    Link Here 
381
	/**
396
	/**
382
	 * View a file (inlines file).
397
	 * View a file (inlines file).
383
	 * @param $args array ($articleId, $galleyId, $fileId [optional])
398
	 * @param $args array ($articleId, $galleyId, $fileId [optional])
399
	 * @param $request Request
384
	 */
400
	 */
385
	function viewFile($args) {
401
	function viewFile($args, &$request) {
386
		$articleId = isset($args[0]) ? $args[0] : 0;
402
		$articleId = isset($args[0]) ? $args[0] : 0;
387
		$galleyId = isset($args[1]) ? $args[1] : 0;
403
		$galleyId = isset($args[1]) ? $args[1] : 0;
388
		$fileId = isset($args[2]) ? (int) $args[2] : 0;
404
		$fileId = isset($args[2]) ? (int) $args[2] : 0;
389
405
390
		$this->validate($articleId, $galleyId);
406
		$this->validate($request, $articleId, $galleyId);
391
		$journal =& $this->journal;
407
		$journal =& $this->journal;
392
		$issue =& $this->issue;
408
		$issue =& $this->issue;
393
		$article =& $this->article;		
409
		$article =& $this->article;
394
410
395
		$galleyDao =& DAORegistry::getDAO('ArticleGalleyDAO');
411
		$galleyDao =& DAORegistry::getDAO('ArticleGalleyDAO');
396
		if ($journal->getSetting('enablePublicGalleyId')) {
412
		if ($journal->getSetting('enablePublicGalleyId')) {
 Lines 399-412    Link Here 
399
			$galley =& $galleyDao->getGalley($galleyId, $article->getArticleId());
415
			$galley =& $galleyDao->getGalley($galleyId, $article->getArticleId());
400
		}
416
		}
401
417
402
		if (!$galley) Request::redirect(null, null, 'view', $articleId);
418
		if (!$galley) $request->redirect(null, null, 'view', $articleId);
403
419
404
		if (!$fileId) {
420
		if (!$fileId) {
405
			$galleyDao->incrementViews($galley->getGalleyId());
421
			$galleyDao->incrementViews($galley->getGalleyId());
406
			$fileId = $galley->getFileId();
422
			$fileId = $galley->getFileId();
407
		} else {
423
		} else {
408
			if (!$galley->isDependentFile($fileId)) {
424
			if (!$galley->isDependentFile($fileId)) {
409
				Request::redirect(null, null, 'view', $articleId);
425
				$request->redirect(null, null, 'view', $articleId);
410
			}
426
			}
411
		}
427
		}
412
428
 Lines 418-431    Link Here 
418
434
419
	/**
435
	/**
420
	 * Downloads the document
436
	 * Downloads the document
437
	 * @param $args array
438
	 * @param $request Request
421
	 */
439
	 */
422
	function download($args) {
440
	function download($args, &$request) {
423
		$articleId = isset($args[0]) ? $args[0] : 0;
441
		$articleId = isset($args[0]) ? $args[0] : 0;
424
		$galleyId = isset($args[1]) ? $args[1] : 0;
442
		$galleyId = isset($args[1]) ? $args[1] : 0;
425
		$this->validate($articleId, $galleyId);
443
		$this->validate($request, $articleId, $galleyId);
426
		$journal =& $this->journal;
444
		$journal =& $this->journal;
427
		$issue =& $this->issue;
445
		$issue =& $this->issue;
428
		$article =& $this->article;		
446
		$article =& $this->article;
429
447
430
		$galleyDao =& DAORegistry::getDAO('ArticleGalleyDAO');
448
		$galleyDao =& DAORegistry::getDAO('ArticleGalleyDAO');
431
		if ($journal->getSetting('enablePublicGalleyId')) {
449
		if ($journal->getSetting('enablePublicGalleyId')) {
 Lines 442-454    Link Here 
442
		}
460
		}
443
	}
461
	}
444
462
445
	function downloadSuppFile($args) {
463
	/**
464
	 * Download a supplementary file
465
	 * @param $args array
466
	 * @param $request Request
467
	 */
468
	function downloadSuppFile($args, &$request) {
446
		$articleId = isset($args[0]) ? $args[0] : 0;
469
		$articleId = isset($args[0]) ? $args[0] : 0;
447
		$suppId = isset($args[1]) ? $args[1] : 0;
470
		$suppId = isset($args[1]) ? $args[1] : 0;
448
		$this->validate($articleId);
471
		$this->validate($request, $articleId);
449
		$journal =& $this->journal;
472
		$journal =& $this->journal;
450
		$issue =& $this->issue;
473
		$issue =& $this->issue;
451
		$article =& $this->article;		
474
		$article =& $this->article;
452
475
453
		$suppFileDao =& DAORegistry::getDAO('SuppFileDAO');
476
		$suppFileDao =& DAORegistry::getDAO('SuppFileDAO');
454
		if ($journal->getSetting('enablePublicSuppFileId')) {
477
		if ($journal->getSetting('enablePublicSuppFileId')) {
 Lines 470-485    Link Here 
470
493
471
	/**
494
	/**
472
	 * Validation
495
	 * Validation
496
	 * @see lib/pkp/classes/handler/PKPHandler#validate()
497
	 * @param $request Request
498
	 * @param $articleId integer
499
	 * @param $galleyId integer
473
	 */
500
	 */
474
	function validate($articleId, $galleyId = null) {
501
	function validate(&$request, $articleId, $galleyId = null) {
475
		parent::validate();
502
		$router =& $request->getRouter();
503
		parent::validate(null, $request);
476
504
477
		import('issue.IssueAction');
505
		import('issue.IssueAction');
478
506
479
		$journal =& Request::getJournal();
507
		$journal =& $router->getContext($request);
480
		$journalId = $journal->getJournalId();
508
		$journalId = $journal->getJournalId();
481
		$article = $publishedArticle = $issue = null;
509
		$article = $publishedArticle = $issue = null;
482
		$user =& Request::getUser();
510
		$user =& $request->getUser();
483
		$userId = $user?$user->getId():0;
511
		$userId = $user?$user->getId():0;
484
512
485
		$publishedArticleDao =& DAORegistry::getDAO('PublishedArticleDAO');
513
		$publishedArticleDao =& DAORegistry::getDAO('PublishedArticleDAO');
 Lines 575-586    Link Here 
575
						if (!Validation::isLoggedIn()) {
603
						if (!Validation::isLoggedIn()) {
576
							Validation::redirectLogin("reader.subscriptionRequiredLoginText");
604
							Validation::redirectLogin("reader.subscriptionRequiredLoginText");
577
						}
605
						}
578
						Request::redirect(null, 'about', 'subscriptions');
606
						$request->redirect(null, 'about', 'subscriptions');
579
					}
607
					}
580
				}
608
				}
581
			}
609
			}
582
		} else {
610
		} else {
583
			Request::redirect(null, 'index');
611
			$request->redirect(null, 'index');
584
		}
612
		}
585
		$this->journal =& $journal;
613
		$this->journal =& $journal;
586
		$this->issue =& $issue;
614
		$this->issue =& $issue;

Return to bug 4934