/** * Article view */ function viewArticle($args) { $articleId = isset($args[0]) ? $args[0] : 0; $galleyId = isset($args[1]) ? (int) $args[1] : 0; list($journal, $issue, $article) = ArticleHandler::validate($articleId, $galleyId); $rtDao =& DAORegistry::getDAO('RTDAO'); $journalRt = $rtDao->getJournalRTByJournal($journal); $sectionDao =& DAORegistry::getDAO('SectionDAO'); $section =& $sectionDao->getSection($article->getSectionId()); if ($journalRt->getVersion() != null && $journalRt->getDefineTerms()) { // Determine the "Define Terms" context ID. $version = $rtDao->getVersion($journalRt->getVersion(), $journalRt->getJournalId()); if ($version) { foreach ($version->getContexts() as $context) { if ($context->getDefineTerms()) { $defineTermsContextId = $context->getContextId(); break; } } } } $commentDao =& DAORegistry::getDAO('CommentDAO'); $enableComments = $journal->getSetting('enableComments'); if ($enableComments == COMMENTS_AUTHENTICATED || $enableComments == COMMENTS_UNAUTHENTICATED || $enableComments == COMMENTS_ANONYMOUS) { $comments =& $commentDao->getRootCommentsByArticleId($article->getArticleId()); } $articleGalleyDao =& DAORegistry::getDAO('ArticleGalleyDAO'); $galley =& $articleGalleyDao->getGalley($galleyId, $article->getArticleId()); $templateMgr =& TemplateManager::getManager(); if (!$galley) { // Get the subscription status if displaying the abstract; // if access is open, we can display links to the full text. import('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->getIssueId() : null, isset($article) ? $article->getArticleId() : null)); $templateMgr->assign('subscribedDomain', IssueAction::subscribedDomain($journal, isset($issue) ? $issue->getIssueId() : null, isset($article) ? $article->getArticleId() : null)); $templateMgr->assign('showGalleyLinks', $journal->getSetting('showGalleyLinks')); import('payment.ojs.OJSPaymentManager'); $paymentManager =& OJSPaymentManager::getManager(); if ($paymentManager->onlyPdfEnabled()) { $templateMgr->assign('restrictOnlyPdf', true); } if ($paymentManager->purchaseArticleEnabled()) { $templateMgr->assign('purchaseArticleEnabled', true); } // Increment the published article's abstract views count if (!Request::isBot()) { $publishedArticleDao =& DAORegistry::getDAO('PublishedArticleDAO'); $publishedArticleDao->incrementViewsByArticleId($article->getArticleId()); } } else { if (!Request::isBot()) { // Increment the galley's views count $articleGalleyDao->incrementViews($galleyId); } // Use the article's CSS file, if set. if ($galley->isHTMLGalley() && ($styleFile =& $galley->getStyleFile())) { $templateMgr->addStyleSheet(Request::url(null, 'article', 'viewFile', array($article->getArticleId(), $galley->getGalleyId(), $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('articleId', $articleId); $templateMgr->assign('postingAllowed', $enableComments == COMMENTS_UNAUTHENTICATED || ($enableComments == COMMENTS_AUTHENTICATED || $enableComments == COMMENTS_ANONYMOUS) && Validation::isLoggedIn()); $templateMgr->assign('galleyId', $galleyId); $templateMgr->assign('defineTermsContextId', isset($defineTermsContextId) ? $defineTermsContextId : null); $templateMgr->assign('comments', isset($comments) ? $comments : null); $templateMgr->display('article/article.tpl'); }
/** * Log the request. * This follows a convoluted execution path in order to obtain the * page title *after* the template has been displayed, even though * the hook is called before execution. */ function logRequest($hookName, $args) { $templateManager =& $args[0]; $template =& $args[1]; $site =& Request::getSite(); $journal =& Request::getJournal(); $session =& Request::getSession(); if (!$journal) { return false; } /* NOTE: Project COUNTER has a list of robots on their site unfortunately not in a very accessible format: http://www.projectcounter.org/r3/r3_K.doc */ if (Request::isBot()) { return false; } // TODO: consider the effect of LOCKSS on COUNTER recording switch ($template) { case 'article/article.tpl': case 'article/interstitial.tpl': case 'article/pdfInterstitial.tpl': // Log the request as an article view. $article = $templateManager->get_template_vars('article'); $galley = $templateManager->get_template_vars('galley'); // If no galley exists, this is an abstract // view -- don't include it. (FIXME?) if (!$galley) { return false; } $lastRequestGap = time() - $session->getSessionVar('lastRequest'); // if last request was less than 10 seconds ago then return without recording this view if ($lastRequestGap < 10) { return false; } // if last request was less than 30 seconds ago AND is PDF then return without recording this view if ($galley->isPdfGalley() && $lastRequestGap < 30) { return false; } $session->setSessionVar('lastRequest', time()); $counterReportDao =& DAORegistry::getDAO('CounterReportDAO'); $counterReportDao->incrementCount($article->getJournalId(), (int) strftime('%Y'), (int) strftime('%m'), $galley->isPdfGalley(), $galley->isHTMLGalley()); break; } return false; }
/** * Article view */ function viewArticle($args) { $articleId = isset($args[0]) ? $args[0] : 0; $galleyId = isset($args[1]) ? $args[1] : 0; list($journal, $issue, $article) = ArticleHandler::validate($articleId, $galleyId); $rtDao =& DAORegistry::getDAO('RTDAO'); $journalRt = $rtDao->getJournalRTByJournal($journal); $sectionDao =& DAORegistry::getDAO('SectionDAO'); $section =& $sectionDao->getSection($article->getSectionId()); if ($journalRt->getVersion() != null && $journalRt->getDefineTerms()) { // Determine the "Define Terms" context ID. $version = $rtDao->getVersion($journalRt->getVersion(), $journalRt->getJournalId()); 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->getRootCommentsByArticleId($article->getArticleId()); } $galleyDao =& DAORegistry::getDAO('ArticleGalleyDAO'); if ($journal->getSetting('enablePublicGalleyId')) { $galley =& $galleyDao->getGalleyByBestGalleyId($galleyId, $article->getArticleId()); } else { $galley =& $galleyDao->getGalley($galleyId, $article->getArticleId()); } $templateMgr =& TemplateManager::getManager(); if (!$galley) { // Get the subscription status if displaying the abstract; // if access is open, we can display links to the full text. import('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->getIssueId() : null, isset($article) ? $article->getArticleId() : null)); $templateMgr->assign('subscribedDomain', IssueAction::subscribedDomain($journal, isset($issue) ? $issue->getIssueId() : null, isset($article) ? $article->getArticleId() : null)); $templateMgr->assign('showGalleyLinks', $journal->getSetting('showGalleyLinks')); import('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->getFileName($locale) && $article->getShowCoverPage($locale) && !$article->getHideCoverPageAbstract($locale)) { import('file.PublicFileManager'); $publicFileManager =& new PublicFileManager(); $coverPagePath = Request::getBaseUrl() . '/'; $coverPagePath .= $publicFileManager->getJournalFilesPath($journal->getJournalId()) . '/'; $templateMgr->assign('coverPagePath', $coverPagePath); $templateMgr->assign('coverPageFileName', $article->getFileName($locale)); $templateMgr->assign('width', $article->getWidth($locale)); $templateMgr->assign('height', $article->getHeight($locale)); $templateMgr->assign('coverPageAltText', $article->getCoverPageAltText($locale)); } // Increment the published article's abstract views count if (!Request::isBot()) { $publishedArticleDao =& DAORegistry::getDAO('PublishedArticleDAO'); $publishedArticleDao->incrementViewsByArticleId($article->getArticleId()); } } else { if (!Request::isBot()) { // Increment the galley's views count $galleyDao->incrementViews($galley->getGalleyId()); } // Use the article's CSS file, if set. if ($galley->isHTMLGalley() && ($styleFile =& $galley->getStyleFile())) { $templateMgr->addStyleSheet(Request::url(null, 'article', 'viewFile', array($article->getArticleId(), $galley->getBestGalleyId($journal), $styleFile->getFileId()))); } } // Add font sizer js and css if not already in header $additionalHeadData = $templateMgr->get_template_vars('additionalHeadData'); if (strpos(strtolower($additionalHeadData), 'sizer.js') === false) { $additionalHeadData .= $templateMgr->fetch('common/sizer.tpl'); $templateMgr->assign('additionalHeadData', $additionalHeadData); } $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('articleId', $articleId); $templateMgr->assign('postingAllowed', $article->getEnableComments() && ($enableComments == COMMENTS_UNAUTHENTICATED || ($enableComments == COMMENTS_AUTHENTICATED || $enableComments == COMMENTS_ANONYMOUS) && Validation::isLoggedIn())); $templateMgr->assign('galleyId', $galleyId); $templateMgr->assign('defineTermsContextId', isset($defineTermsContextId) ? $defineTermsContextId : null); $templateMgr->assign('comments', isset($comments) ? $comments : null); $templateMgr->display('article/article.tpl'); }