Open Journal Systems  2.4.8
 All Classes Namespaces Functions Variables Groups Pages
ArticleHandler.inc.php
1 <?php
2 
18 import('classes.rt.ojs.RTDAO');
19 import('classes.rt.ojs.JournalRT');
20 import('classes.handler.Handler');
21 import('classes.rt.ojs.SharingRT');
22 
23 class ArticleHandler extends Handler {
25  var $journal;
26 
28  var $issue;
29 
31  var $article;
32 
37  function ArticleHandler(&$request) {
38  parent::Handler($request);
39  $router =& $request->getRouter();
40 
41  $this->addCheck(new HandlerValidatorJournal($this));
42  $this->addCheck(new HandlerValidatorCustom($this, false, null, null, create_function('$journal', 'return $journal->getSetting(\'publishingMode\') != PUBLISHING_MODE_NONE;'), array($router->getContext($request))));
43  }
44 
50  function view($args, &$request) {
51  $router =& $request->getRouter();
52  $articleId = isset($args[0]) ? $args[0] : 0;
53  $galleyId = isset($args[1]) ? $args[1] : 0;
54 
55  $this->validate($request, $articleId, $galleyId);
59  $this->setupTemplate($request);
60 
61  $rtDao =& DAORegistry::getDAO('RTDAO');
62  $journalRt = $rtDao->getJournalRTByJournal($journal);
63 
64  $sectionDao =& DAORegistry::getDAO('SectionDAO');
65  $section =& $sectionDao->getSection($article->getSectionId(), $journal->getId(), true);
66 
67  $version = null;
68  if ($journalRt->getVersion()!=null && $journalRt->getDefineTerms()) {
69  // Determine the "Define Terms" context ID.
70  $version = $rtDao->getVersion($journalRt->getVersion(), $journalRt->getJournalId(), true);
71  if ($version) foreach ($version->getContexts() as $context) {
72  if ($context->getDefineTerms()) {
73  $defineTermsContextId = $context->getContextId();
74  break;
75  }
76  }
77  }
78 
79  $commentDao =& DAORegistry::getDAO('CommentDAO');
80  $enableComments = $journal->getSetting('enableComments');
81 
82  if (($article->getEnableComments()) && ($enableComments == COMMENTS_AUTHENTICATED || $enableComments == COMMENTS_UNAUTHENTICATED || $enableComments == COMMENTS_ANONYMOUS)) {
83  $comments =& $commentDao->getRootCommentsBySubmissionId($article->getId());
84  }
85 
86  $galleyDao =& DAORegistry::getDAO('ArticleGalleyDAO');
87  if ($journal->getSetting('enablePublicGalleyId')) {
88  $galley =& $galleyDao->getGalleyByBestGalleyId($galleyId, $article->getId());
89  } else {
90  $galley =& $galleyDao->getGalley($galleyId, $article->getId());
91  }
92 
93  if ($galley && !$galley->isHtmlGalley() && !$galley->isPdfGalley()) {
94  if ($galley->getRemoteURL()) {
95  if (!HookRegistry::call('ArticleHandler::viewRemoteGalley', array(&$article, &$galley))) {
96  $request->redirectUrl($galley->getRemoteURL());
97  }
98  }
99  if ($galley->isInlineable()) {
100  return $this->viewFile(
101  array($galley->getArticleId(), $galley->getId()),
102  $request
103  );
104  } else {
105  return $this->download(
106  array($galley->getArticleId(), $galley->getId()),
107  $request
108  );
109  }
110  }
111 
112  $templateMgr =& TemplateManager::getManager($request);
113  $templateMgr->addJavaScript('js/relatedItems.js');
114  $templateMgr->addJavaScript('js/inlinePdf.js');
115  $templateMgr->addJavaScript('js/pdfobject.js');
116 
117  if (!$galley) {
118  // Get the subscription status if displaying the abstract;
119  // if access is open, we can display links to the full text.
120  import('classes.issue.IssueAction');
121 
122  // The issue may not exist, if this is an editorial user
123  // and scheduling hasn't been completed yet for the article.
124  if ($issue) {
125  $templateMgr->assign('subscriptionRequired', IssueAction::subscriptionRequired($issue));
126  }
127 
128  $templateMgr->assign('subscribedUser', IssueAction::subscribedUser($journal, isset($issue) ? $issue->getId() : null, isset($article) ? $article->getId() : null));
129  $templateMgr->assign('subscribedDomain', IssueAction::subscribedDomain($journal, isset($issue) ? $issue->getId() : null, isset($article) ? $article->getId() : null));
130 
131  $templateMgr->assign('showGalleyLinks', $journal->getSetting('showGalleyLinks'));
132 
133  import('classes.payment.ojs.OJSPaymentManager');
134  $paymentManager = new OJSPaymentManager($request);
135  if ( $paymentManager->onlyPdfEnabled() ) {
136  $templateMgr->assign('restrictOnlyPdf', true);
137  }
138  if ( $paymentManager->purchaseArticleEnabled() ) {
139  $templateMgr->assign('purchaseArticleEnabled', true);
140  }
141 
142  // Article cover page.
143  $locale = AppLocale::getLocale();
144  if (isset($article) && $article->getLocalizedFileName() && $article->getLocalizedShowCoverPage() && !$article->getLocalizedHideCoverPageAbstract()) {
145  import('classes.file.PublicFileManager');
146  $publicFileManager = new PublicFileManager();
147  $coverPagePath = $request->getBaseUrl() . '/';
148  $coverPagePath .= $publicFileManager->getJournalFilesPath($journal->getId()) . '/';
149  $templateMgr->assign('coverPagePath', $coverPagePath);
150  $templateMgr->assign('coverPageFileName', $article->getLocalizedFileName());
151  $templateMgr->assign('width', $article->getLocalizedWidth());
152  $templateMgr->assign('height', $article->getLocalizedHeight());
153  $templateMgr->assign('coverPageAltText', $article->getLocalizedCoverPageAltText());
154  }
155 
156  // References list.
157  // FIXME: We only display the edited raw citations right now. We also want
158  // to allow for generated citations to be displayed here (including a way for
159  // the reader to choose any of the installed citation styles for output), see #5938.
160  $citationDao =& DAORegistry::getDAO('CitationDAO'); /* @var $citationDao CitationDAO */
161  $citationFactory =& $citationDao->getObjectsByAssocId(ASSOC_TYPE_ARTICLE, $article->getId());
162  $templateMgr->assign('citationFactory', $citationFactory);
163  } else {
164  // Use the article's CSS file, if set.
165  if ($galley->isHTMLGalley() && $styleFile =& $galley->getStyleFile()) {
166  $templateMgr->addStyleSheet($router->url($request, null, 'article', 'viewFile', array(
167  $article->getId(),
168  $galley->getBestGalleyId($journal),
169  $styleFile->getFileId()
170  )));
171  }
172  }
173 
174  $templateMgr->assign_by_ref('issue', $issue);
175  $templateMgr->assign_by_ref('article', $article);
176  $templateMgr->assign_by_ref('galley', $galley);
177  $templateMgr->assign_by_ref('section', $section);
178  $templateMgr->assign_by_ref('journalRt', $journalRt);
179  $templateMgr->assign_by_ref('version', $version);
180  $templateMgr->assign_by_ref('journal', $journal);
181  $templateMgr->assign('articleId', $articleId);
182  $templateMgr->assign('postingAllowed', (
183  ($article->getEnableComments()) && (
184  $enableComments == COMMENTS_UNAUTHENTICATED ||
185  (($enableComments == COMMENTS_AUTHENTICATED ||
186  $enableComments == COMMENTS_ANONYMOUS) &&
188  ));
189  $templateMgr->assign('enableComments', $enableComments);
190  $templateMgr->assign('postingLoginRequired', ($enableComments != COMMENTS_UNAUTHENTICATED && !Validation::isLoggedIn()));
191  $templateMgr->assign('galleyId', $galleyId);
192  $templateMgr->assign('defineTermsContextId', isset($defineTermsContextId)?$defineTermsContextId:null);
193  $templateMgr->assign('comments', isset($comments)?$comments:null);
194 
195  $templateMgr->assign('sharingEnabled', $journalRt->getSharingEnabled());
196 
197  if($journalRt->getSharingEnabled()) {
198  $templateMgr->assign('sharingRequestURL', $request->getRequestURL());
199  $templateMgr->assign('sharingArticleTitle', $article->getLocalizedTitle());
200  $templateMgr->assign_by_ref('sharingUserName', $journalRt->getSharingUserName());
201  $templateMgr->assign_by_ref('sharingButtonStyle', $journalRt->getSharingButtonStyle());
202  $templateMgr->assign_by_ref('sharingDropDownMenu', $journalRt->getSharingDropDownMenu());
203  $templateMgr->assign_by_ref('sharingBrand', $journalRt->getSharingBrand());
204  $templateMgr->assign_by_ref('sharingDropDown', $journalRt->getSharingDropDown());
205  $templateMgr->assign_by_ref('sharingLanguage', $journalRt->getSharingLanguage());
206  $templateMgr->assign_by_ref('sharingLogo', $journalRt->getSharingLogo());
207  $templateMgr->assign_by_ref('sharingLogoBackground', $journalRt->getSharingLogoBackground());
208  $templateMgr->assign_by_ref('sharingLogoColor', $journalRt->getSharingLogoColor());
209  list($btnUrl, $btnWidth, $btnHeight) = SharingRT::sharingButtonImage($journalRt);
210  $templateMgr->assign('sharingButtonUrl', $btnUrl);
211  $templateMgr->assign('sharingButtonWidth', $btnWidth);
212  $templateMgr->assign('sharingButtonHeight', $btnHeight);
213  }
214 
215  $templateMgr->assign('articleSearchByOptions', array(
216  'query' => 'search.allFields',
217  'authors' => 'search.author',
218  'title' => 'article.title',
219  'abstract' => 'search.abstract',
220  'indexTerms' => 'search.indexTerms',
221  'galleyFullText' => 'search.fullText'
222  ));
223  // consider public identifiers
224  $pubIdPlugins =& PluginRegistry::loadCategory('pubIds', true);
225  $templateMgr->assign('pubIdPlugins', $pubIdPlugins);
226  $templateMgr->display('article/article.tpl');
227  }
228 
235  function viewPDFInterstitial($args, &$request, $galley = null) {
236  $articleId = isset($args[0]) ? $args[0] : 0;
237  $galleyId = isset($args[1]) ? $args[1] : 0;
238  $this->validate($request, $articleId, $galleyId);
240  $issue =& $this->issue;
242  $this->setupTemplate($request);
243 
244  if (!$galley) {
245  $galleyDao =& DAORegistry::getDAO('ArticleGalleyDAO');
246  if ($journal->getSetting('enablePublicGalleyId')) {
247  $galley =& $galleyDao->getGalleyByBestGalleyId($galleyId, $article->getId());
248  } else {
249  $galley =& $galleyDao->getGalley($galleyId, $article->getId());
250  }
251  }
252 
253  if (!$galley) $request->redirect(null, null, 'view', $articleId);
254 
255  $templateMgr =& TemplateManager::getManager();
256  $templateMgr->assign('articleId', $articleId);
257  $templateMgr->assign('galleyId', $galleyId);
258  $templateMgr->assign_by_ref('galley', $galley);
259  $templateMgr->assign_by_ref('article', $article);
260 
261  $templateMgr->display('article/pdfInterstitial.tpl');
262  }
263 
271  function viewDownloadInterstitial($args, &$request, $galley = null) {
272  $articleId = isset($args[0]) ? $args[0] : 0;
273  $galleyId = isset($args[1]) ? $args[1] : 0;
274  $this->validate($request, $articleId, $galleyId);
276  $issue =& $this->issue;
278  $this->setupTemplate($request);
279 
280  if (!$galley) {
281  $galleyDao =& DAORegistry::getDAO('ArticleGalleyDAO');
282  if ($journal->getSetting('enablePublicGalleyId')) {
283  $galley =& $galleyDao->getGalleyByBestGalleyId($galleyId, $article->getId());
284  } else {
285  $galley =& $galleyDao->getGalley($galleyId, $article->getId());
286  }
287  }
288 
289  if (!$galley) $request->redirect(null, null, 'view', $articleId);
290 
291  $templateMgr =& TemplateManager::getManager();
292  $templateMgr->assign('articleId', $articleId);
293  $templateMgr->assign('galleyId', $galleyId);
294  $templateMgr->assign_by_ref('galley', $galley);
295  $templateMgr->assign_by_ref('article', $article);
296 
297  $templateMgr->display('article/interstitial.tpl');
298  }
299 
305  function viewArticle($args, &$request) {
306  // This function is deprecated since the Reading Tools frameset was removed.
307  return $this->view($args, $request);
308  }
309 
315  function viewFile($args, &$request) {
316  $articleId = isset($args[0]) ? $args[0] : 0;
317  $galleyId = isset($args[1]) ? $args[1] : 0;
318  $fileId = isset($args[2]) ? (int) $args[2] : 0;
319 
320  $this->validate($request, $articleId, $galleyId);
322  $issue =& $this->issue;
324 
325  $galleyDao =& DAORegistry::getDAO('ArticleGalleyDAO');
326  if ($journal->getSetting('enablePublicGalleyId')) {
327  $galley =& $galleyDao->getGalleyByBestGalleyId($galleyId, $article->getId());
328  } else {
329  $galley =& $galleyDao->getGalley($galleyId, $article->getId());
330  }
331 
332  if (!$galley) $request->redirect(null, null, 'view', $articleId);
333 
334  if (!$fileId) {
335  $fileId = $galley->getFileId();
336  } else {
337  if (!$galley->isDependentFile($fileId)) {
338  $request->redirect(null, null, 'view', $articleId);
339  }
340  }
341 
342  if (!HookRegistry::call('ArticleHandler::viewFile', array(&$article, &$galley, &$fileId))) {
343  import('classes.submission.common.Action');
344  Action::viewFile($article->getId(), $fileId);
345  }
346  }
347 
353  function download($args, &$request) {
354  $articleId = isset($args[0]) ? $args[0] : 0;
355  $galleyId = isset($args[1]) ? $args[1] : 0;
356  $this->validate($request, $articleId, $galleyId);
358  $issue =& $this->issue;
360 
361  $galleyDao =& DAORegistry::getDAO('ArticleGalleyDAO');
362  if ($journal->getSetting('enablePublicGalleyId')) {
363  $galley =& $galleyDao->getGalleyByBestGalleyId($galleyId, $article->getId());
364  } else {
365  $galley =& $galleyDao->getGalley($galleyId, $article->getId());
366  }
367 
368  if ($article && $galley && !HookRegistry::call('ArticleHandler::downloadFile', array(&$article, &$galley))) {
369  import('classes.file.ArticleFileManager');
370  $articleFileManager = new ArticleFileManager($article->getId());
371  $articleFileManager->downloadFile($galley->getFileId());
372  }
373  }
374 
380  function downloadSuppFile($args, &$request) {
381  $articleId = isset($args[0]) ? $args[0] : 0;
382  $suppId = isset($args[1]) ? $args[1] : 0;
383  $this->validate($request, $articleId);
385  $issue =& $this->issue;
387 
388  $suppFileDao =& DAORegistry::getDAO('SuppFileDAO');
389  if ($journal->getSetting('enablePublicSuppFileId')) {
390  $suppFile =& $suppFileDao->getSuppFileByBestSuppFileId($suppId, $article->getId());
391  } else {
392  $suppFile =& $suppFileDao->getSuppFile((int) $suppId, $article->getId());
393  }
394 
395  if ($article && $suppFile && !HookRegistry::call('ArticleHandler::downloadSuppFile', array(&$article, &$suppFile))) {
396  import('classes.file.ArticleFileManager');
397  $articleFileManager = new ArticleFileManager($article->getId());
398  if ($suppFile->getRemoteURL()) {
399  $request->redirectUrl($suppFile->getRemoteURL());
400  }
401  $articleFileManager->downloadFile($suppFile->getFileId(), null, $suppFile->isInlineable());
402  }
403  }
404 
412  function validate(&$request, $articleId, $galleyId = null) {
413  parent::validate(null, $request);
414 
415  import('classes.issue.IssueAction');
416 
417  $router =& $request->getRouter();
418  $journal =& $router->getContext($request);
419  $journalId = $journal->getId();
420  $article = $publishedArticle = $issue = null;
421  $user =& $request->getUser();
422  $userId = $user?$user->getId():0;
423 
424  $publishedArticleDao =& DAORegistry::getDAO('PublishedArticleDAO');
425  if ($journal->getSetting('enablePublicArticleId')) {
426  $publishedArticle =& $publishedArticleDao->getPublishedArticleByBestArticleId((int) $journalId, $articleId, true);
427  } else {
428  $publishedArticle =& $publishedArticleDao->getPublishedArticleByArticleId((int) $articleId, (int) $journalId, true);
429  }
430 
431  $issueDao =& DAORegistry::getDAO('IssueDAO');
432  if (isset($publishedArticle)) {
433  $issue =& $issueDao->getIssueById($publishedArticle->getIssueId(), $publishedArticle->getJournalId(), true);
434  } else {
435  $articleDao =& DAORegistry::getDAO('ArticleDAO');
436  $article =& $articleDao->getArticle((int) $articleId, $journalId, true);
437  }
438 
439  // If this is an editorial user who can view unpublished/unscheduled
440  // articles, bypass further validation. Likewise for its author.
441  if (($article || $publishedArticle) && (($article && IssueAction::allowedPrePublicationAccess($journal, $article) || ($publishedArticle && IssueAction::allowedPrePublicationAccess($journal, $publishedArticle))))) {
442  $this->journal =& $journal;
443  $this->issue =& $issue;
444  if(isset($publishedArticle)) {
445  $this->article =& $publishedArticle;
446  } else $this->article =& $article;
447 
448  return true;
449  }
450 
451  // Make sure the reader has rights to view the article/issue.
452  if ($issue && $issue->getPublished() && $publishedArticle->getStatus() == STATUS_PUBLISHED) {
453  $subscriptionRequired = IssueAction::subscriptionRequired($issue);
454  $isSubscribedDomain = IssueAction::subscribedDomain($journal, $issue->getId(), $publishedArticle->getId());
455 
456  // Check if login is required for viewing.
457  if (!$isSubscribedDomain && !Validation::isLoggedIn() && $journal->getSetting('restrictArticleAccess') && isset($galleyId) && $galleyId) {
459  }
460 
461  // bypass all validation if subscription based on domain or ip is valid
462  // or if the user is just requesting the abstract
463  if ( (!$isSubscribedDomain && $subscriptionRequired) &&
464  (isset($galleyId) && $galleyId) ) {
465 
466  // Subscription Access
467  $subscribedUser = IssueAction::subscribedUser($journal, $issue->getId(), $publishedArticle->getId());
468 
469  import('classes.payment.ojs.OJSPaymentManager');
470  $paymentManager = new OJSPaymentManager($request);
471 
472  $purchasedIssue = false;
473  if (!$subscribedUser && $paymentManager->purchaseIssueEnabled()) {
474  $completedPaymentDao =& DAORegistry::getDAO('OJSCompletedPaymentDAO');
475  $purchasedIssue = $completedPaymentDao->hasPaidPurchaseIssue($userId, $issue->getId());
476  }
477 
478  if (!(!$subscriptionRequired || $publishedArticle->getAccessStatus() == ARTICLE_ACCESS_OPEN || $subscribedUser || $purchasedIssue)) {
479 
480  if ( $paymentManager->purchaseArticleEnabled() || $paymentManager->membershipEnabled() ) {
481  /* if only pdf files are being restricted, then approve all non-pdf galleys
482  * and continue checking if it is a pdf galley */
483  if ( $paymentManager->onlyPdfEnabled() ) {
484  $galleyDao =& DAORegistry::getDAO('ArticleGalleyDAO');
485  if ($journal->getSetting('enablePublicGalleyId')) {
486  $galley =& $galleyDao->getGalleyByBestGalleyId($galleyId, $publishedArticle->getId());
487  } else {
488  $galley =& $galleyDao->getGalley($galleyId, $publishedArticle->getId());
489  }
490  if ( $galley && !$galley->isPdfGalley() ) {
491  $this->journal =& $journal;
492  $this->issue =& $issue;
493  $this->article =& $publishedArticle;
494  return true;
495  }
496  }
497 
498  if (!Validation::isLoggedIn()) {
499  Validation::redirectLogin("payment.loginRequired.forArticle");
500  }
501 
502  /* if the article has been paid for then forget about everything else
503  * and just let them access the article */
504  $completedPaymentDao =& DAORegistry::getDAO('OJSCompletedPaymentDAO');
505  $dateEndMembership = $user->getSetting('dateEndMembership', 0);
506  if ($completedPaymentDao->hasPaidPurchaseArticle($userId, $publishedArticle->getId())
507  || (!is_null($dateEndMembership) && $dateEndMembership > time())) {
508  $this->journal =& $journal;
509  $this->issue =& $issue;
510  $this->article =& $publishedArticle;
511  return true;
512  } else {
513  $queuedPayment =& $paymentManager->createQueuedPayment($journalId, PAYMENT_TYPE_PURCHASE_ARTICLE, $user->getId(), $publishedArticle->getId(), $journal->getSetting('purchaseArticleFee'));
514  $queuedPaymentId = $paymentManager->queuePayment($queuedPayment);
515 
516  $paymentManager->displayPaymentForm($queuedPaymentId, $queuedPayment);
517  exit;
518  }
519  }
520 
521  if (!isset($galleyId) || $galleyId) {
522  if (!Validation::isLoggedIn()) {
523  Validation::redirectLogin("reader.subscriptionRequiredLoginText");
524  }
525  $request->redirect(null, 'about', 'subscriptions');
526  }
527  }
528  }
529  } else {
530  $request->redirect(null, 'index');
531  }
532  $this->journal =& $journal;
533  $this->issue =& $issue;
534  $this->article =& $publishedArticle;
535  return true;
536  }
537 
542  function setupTemplate($request) {
543  parent::setupTemplate();
544  AppLocale::requireComponents(LOCALE_COMPONENT_PKP_READER, LOCALE_COMPONENT_PKP_SUBMISSION);
545  if ($this->article) {
546  $templateMgr =& TemplateManager::getManager($request);
547  $templateMgr->assign('ccLicenseBadge', Application::getCCLicenseBadge($this->article->getLicenseURL()));
548  }
549  }
550 }
551 
552 ?>
viewPDFInterstitial($args, &$request, $galley=null)
allowedPrePublicationAccess(&$journal, &$article)
Wrapper class for uploading files to a site/journal&#39;s public directory.
viewFile($args, &$request)
downloadFile($fileId, $revision=null, $inline=false)
getCCLicenseBadge($ccLicenseURL)
downloadSuppFile($args, &$request)
download($args, &$request)
view($args, &$request)
subscribedDomain(&$journal, $issueId=null, $articleId=null)
sharingButtonImage($journalRt)
viewFile($articleId, $fileId, $revision=null)
Definition: Action.inc.php:192
redirectLogin($message=null)
subscribedUser(&$journal, $issueId=null, $articleId=null)
ArticleHandler(&$request)
subscriptionRequired(&$issue, $journal=null)
Base request handler application class.
Definition: Handler.inc.php:21
addCheck(&$handlerValidator)
& getDAO($name, $dbconn=null)
Class defining operations for article file management.
Handle requests for article functions.
call($hookName, $args=null)
& loadCategory($category, $enabledOnly=false, $mainContextId=null)
Class to validate if a Journal is present.
Provides payment management functions.
viewArticle($args, &$request)
validate(&$request, $articleId, $galleyId=null)
viewDownloadInterstitial($args, &$request, $galley=null)