Guest User

Untitled

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