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