00001 <?php
00002
00016
00017
00018
00019 import('rt.ojs.RTDAO');
00020 import('rt.ojs.JournalRT');
00021
00022 class ArticleHandler extends Handler {
00023
00027 function view($args) {
00028 $articleId = isset($args[0]) ? $args[0] : 0;
00029 $galleyId = isset($args[1]) ? $args[1] : 0;
00030
00031 list($journal, $issue, $article) = ArticleHandler::validate($articleId, $galleyId);
00032
00033 $rtDao = &DAORegistry::getDAO('RTDAO');
00034 $journalRt = $rtDao->getJournalRTByJournal($journal);
00035
00036 $galleyDao =& DAORegistry::getDAO('ArticleGalleyDAO');
00037 if ($journal->getSetting('enablePublicGalleyId')) {
00038 $galley =& $galleyDao->getGalleyByBestGalleyId($galleyId, $article->getArticleId());
00039 } else {
00040 $galley =& $galleyDao->getGalley($galleyId, $article->getArticleId());
00041 }
00042
00043 if (!$journalRt->getEnabled()) {
00044 if (!$galley || $galley->isHtmlGalley()) return ArticleHandler::viewArticle($args);
00045 else if ($galley->isPdfGalley()) return ArticleHandler::viewPDFInterstitial($args, $galley);
00046 else if ($galley->isInlineable()) {
00047 import('file.ArticleFileManager');
00048 $articleFileManager = &new ArticleFileManager($article->getArticleId());
00049 return $articleFileManager->viewFile($galley->getFileId());
00050 } else return ArticleHandler::viewDownloadInterstitial($args, $galley);
00051 }
00052
00053 if (!$article) {
00054 Request::redirect(null, Request::getRequestedPage());
00055 return;
00056 }
00057
00058 $templateMgr = &TemplateManager::getManager();
00059 $templateMgr->assign('articleId', $articleId);
00060 $templateMgr->assign_by_ref('article', $article);
00061 $templateMgr->assign('galleyId', $galleyId);
00062 $templateMgr->assign_by_ref('galley', $galley);
00063
00064 $templateMgr->display('article/view.tpl');
00065 }
00066
00070 function viewPDFInterstitial($args, $galley = null) {
00071 $articleId = isset($args[0]) ? $args[0] : 0;
00072 $galleyId = isset($args[1]) ? $args[1] : 0;
00073 list($journal, $issue, $article) = ArticleHandler::validate($articleId, $galleyId);
00074
00075 if (!$galley) {
00076 $galleyDao = &DAORegistry::getDAO('ArticleGalleyDAO');
00077 if ($journal->getSetting('enablePublicGalleyId')) {
00078 $galley =& $galleyDao->getGalleyByBestGalleyId($galleyId, $article->getArticleId());
00079 } else {
00080 $galley =& $galleyDao->getGalley($galleyId, $article->getArticleId());
00081 }
00082 }
00083
00084 $templateMgr = &TemplateManager::getManager();
00085 $templateMgr->assign('articleId', $articleId);
00086 $templateMgr->assign('galleyId', $galleyId);
00087 $templateMgr->assign_by_ref('galley', $galley);
00088 $templateMgr->assign_by_ref('article', $article);
00089
00090 $templateMgr->display('article/pdfInterstitial.tpl');
00091 }
00092
00097 function viewDownloadInterstitial($args, $galley = null) {
00098 $articleId = isset($args[0]) ? $args[0] : 0;
00099 $galleyId = isset($args[1]) ? $args[1] : 0;
00100 list($journal, $issue, $article) = ArticleHandler::validate($articleId, $galleyId);
00101
00102 if (!$galley) {
00103 $galleyDao = &DAORegistry::getDAO('ArticleGalleyDAO');
00104 if ($journal->getSetting('enablePublicGalleyId')) {
00105 $galley =& $galleyDao->getGalleyByBestGalleyId($galleyId, $article->getArticleId());
00106 } else {
00107 $galley =& $galleyDao->getGalley($galleyId, $article->getArticleId());
00108 }
00109 }
00110
00111 $templateMgr = &TemplateManager::getManager();
00112 $templateMgr->assign('articleId', $articleId);
00113 $templateMgr->assign('galleyId', $galleyId);
00114 $templateMgr->assign_by_ref('galley', $galley);
00115 $templateMgr->assign_by_ref('article', $article);
00116
00117 $templateMgr->display('article/interstitial.tpl');
00118 }
00119
00123 function viewArticle($args) {
00124 $articleId = isset($args[0]) ? $args[0] : 0;
00125 $galleyId = isset($args[1]) ? $args[1] : 0;
00126
00127 list($journal, $issue, $article) = ArticleHandler::validate($articleId, $galleyId);
00128
00129 $rtDao = &DAORegistry::getDAO('RTDAO');
00130 $journalRt = $rtDao->getJournalRTByJournal($journal);
00131
00132 $sectionDao = &DAORegistry::getDAO('SectionDAO');
00133 $section = &$sectionDao->getSection($article->getSectionId());
00134
00135 if ($journalRt->getVersion()!=null && $journalRt->getDefineTerms()) {
00136
00137 $version = $rtDao->getVersion($journalRt->getVersion(), $journalRt->getJournalId());
00138 if ($version) foreach ($version->getContexts() as $context) {
00139 if ($context->getDefineTerms()) {
00140 $defineTermsContextId = $context->getContextId();
00141 break;
00142 }
00143 }
00144 }
00145
00146 $commentDao = &DAORegistry::getDAO('CommentDAO');
00147 $enableComments = $journal->getSetting('enableComments');
00148
00149 if (($article->getEnableComments()) && ($enableComments == COMMENTS_AUTHENTICATED || $enableComments == COMMENTS_UNAUTHENTICATED || $enableComments == COMMENTS_ANONYMOUS)) {
00150 $comments = &$commentDao->getRootCommentsByArticleId($article->getArticleId());
00151 }
00152
00153 $galleyDao =& DAORegistry::getDAO('ArticleGalleyDAO');
00154 if ($journal->getSetting('enablePublicGalleyId')) {
00155 $galley =& $galleyDao->getGalleyByBestGalleyId($galleyId, $article->getArticleId());
00156 } else {
00157 $galley =& $galleyDao->getGalley($galleyId, $article->getArticleId());
00158 }
00159
00160 $templateMgr = &TemplateManager::getManager();
00161
00162 if (!$galley) {
00163
00164
00165 import('issue.IssueAction');
00166
00167
00168
00169 if ($issue) {
00170 $templateMgr->assign('subscriptionRequired', IssueAction::subscriptionRequired($issue));
00171 }
00172
00173 $templateMgr->assign('subscribedUser', IssueAction::subscribedUser($journal, isset($issue) ? $issue->getIssueId() : null, isset($article) ? $article->getArticleId() : null));
00174 $templateMgr->assign('subscribedDomain', IssueAction::subscribedDomain($journal, isset($issue) ? $issue->getIssueId() : null, isset($article) ? $article->getArticleId() : null));
00175
00176 $templateMgr->assign('showGalleyLinks', $journal->getSetting('showGalleyLinks'));
00177
00178 import('payment.ojs.OJSPaymentManager');
00179 $paymentManager =& OJSPaymentManager::getManager();
00180 if ( $paymentManager->onlyPdfEnabled() ) {
00181 $templateMgr->assign('restrictOnlyPdf', true);
00182 }
00183 if ( $paymentManager->purchaseArticleEnabled() ) {
00184 $templateMgr->assign('purchaseArticleEnabled', true);
00185 }
00186
00187
00188 $locale = Locale::getLocale();
00189 if (isset($article) && $article->getFileName($locale) && $article->getShowCoverPage($locale) && !$article->getHideCoverPageAbstract($locale)) {
00190 import('file.PublicFileManager');
00191 $publicFileManager = &new PublicFileManager();
00192 $coverPagePath = Request::getBaseUrl() . '/';
00193 $coverPagePath .= $publicFileManager->getJournalFilesPath($journal->getJournalId()) . '/';
00194 $templateMgr->assign('coverPagePath', $coverPagePath);
00195 $templateMgr->assign('coverPageFileName', $article->getFileName($locale));
00196 $templateMgr->assign('width', $article->getWidth($locale));
00197 $templateMgr->assign('height', $article->getHeight($locale));
00198 $templateMgr->assign('coverPageAltText', $article->getCoverPageAltText($locale));
00199 }
00200
00201
00202 if (!Request::isBot()) {
00203 $publishedArticleDao = &DAORegistry::getDAO('PublishedArticleDAO');
00204 $publishedArticleDao->incrementViewsByArticleId($article->getArticleId());
00205 }
00206 } else {
00207 if (!Request::isBot()) {
00208
00209 $galleyDao->incrementViews($galley->getGalleyId());
00210 }
00211
00212
00213 if ($galley->isHTMLGalley() && $styleFile =& $galley->getStyleFile()) {
00214 $templateMgr->addStyleSheet(Request::url(null, 'article', 'viewFile', array(
00215 $article->getArticleId(),
00216 $galley->getBestGalleyId($journal),
00217 $styleFile->getFileId()
00218 )));
00219 }
00220 }
00221
00222
00223 $additionalHeadData = $templateMgr->get_template_vars('additionalHeadData');
00224 if (strpos(strtolower($additionalHeadData), 'sizer.js') === false) {
00225 $additionalHeadData .= $templateMgr->fetch('common/sizer.tpl');
00226 $templateMgr->assign('additionalHeadData', $additionalHeadData);
00227 }
00228
00229 $templateMgr->assign_by_ref('issue', $issue);
00230 $templateMgr->assign_by_ref('article', $article);
00231 $templateMgr->assign_by_ref('galley', $galley);
00232 $templateMgr->assign_by_ref('section', $section);
00233 $templateMgr->assign('articleId', $articleId);
00234 $templateMgr->assign('postingAllowed', (
00235 ($article->getEnableComments()) && (
00236 $enableComments == COMMENTS_UNAUTHENTICATED ||
00237 (($enableComments == COMMENTS_AUTHENTICATED ||
00238 $enableComments == COMMENTS_ANONYMOUS) &&
00239 Validation::isLoggedIn()))
00240 ));
00241 $templateMgr->assign('galleyId', $galleyId);
00242 $templateMgr->assign('defineTermsContextId', isset($defineTermsContextId)?$defineTermsContextId:null);
00243 $templateMgr->assign('comments', isset($comments)?$comments:null);
00244 $templateMgr->display('article/article.tpl');
00245 }
00246
00250 function viewRST($args) {
00251 $articleId = isset($args[0]) ? $args[0] : 0;
00252 $galleyId = isset($args[1]) ? $args[1] : 0;
00253
00254 list($journal, $issue, $article) = ArticleHandler::validate($articleId, $galleyId);
00255
00256 $rtDao = &DAORegistry::getDAO('RTDAO');
00257 $journalRt = $rtDao->getJournalRTByJournal($journal);
00258
00259
00260 $galleyDao =& DAORegistry::getDAO('ArticleGalleyDAO');
00261 if ($journal->getSetting('enablePublicGalleyId')) {
00262 $galley =& $galleyDao->getGalleyByBestGalleyId($galleyId, $article->getArticleId());
00263 } else {
00264 $galley =& $galleyDao->getGalley($galleyId, $article->getArticleId());
00265 }
00266
00267 $sectionDao = &DAORegistry::getDAO('SectionDAO');
00268 $section = &$sectionDao->getSection($article->getSectionId());
00269
00270 $templateMgr = &TemplateManager::getManager();
00271 $templateMgr->assign_by_ref('issue', $issue);
00272 $templateMgr->assign_by_ref('article', $article);
00273 $templateMgr->assign('articleId', $articleId);
00274 $templateMgr->assign('galleyId', $galleyId);
00275 $templateMgr->assign_by_ref('galley', $galley);
00276 $templateMgr->assign_by_ref('journal', $journal);
00277 $templateMgr->assign_by_ref('section', $section);
00278
00279 $templateMgr->assign('articleSearchByOptions', array(
00280 '' => 'search.allFields',
00281 ARTICLE_SEARCH_AUTHOR => 'search.author',
00282 ARTICLE_SEARCH_TITLE => 'article.title',
00283 ARTICLE_SEARCH_ABSTRACT => 'search.abstract',
00284 ARTICLE_SEARCH_INDEX_TERMS => 'search.indexTerms',
00285 ARTICLE_SEARCH_GALLEY_FILE => 'search.fullText'
00286 ));
00287
00288
00289 $commentDao = &DAORegistry::getDAO('CommentDAO');
00290
00291 $enableComments = $journal->getSetting('enableComments');
00292 $templateMgr->assign('postingAllowed', (
00293 $article->getEnableComments() &&
00294 $enableComments != COMMENTS_DISABLED
00295 ));
00296
00297 $templateMgr->assign('postingDisabled', (
00298 ($enableComments == COMMENTS_AUTHENTICATED ||
00299 $enableComments == COMMENTS_ANONYMOUS) &&
00300 !Validation::isLoggedIn())
00301 );
00302
00303 $templateMgr->assign_by_ref('journalRt', $journalRt);
00304 if ($journalRt->getEnabled()) {
00305 $version = $rtDao->getVersion($journalRt->getVersion(), $journalRt->getJournalId());
00306 if ($version) {
00307 $templateMgr->assign_by_ref('version', $version);
00308 }
00309 }
00310
00311 $templateMgr->display('rt/rt.tpl');
00312 }
00313
00318 function viewFile($args) {
00319 $articleId = isset($args[0]) ? $args[0] : 0;
00320 $galleyId = isset($args[1]) ? $args[1] : 0;
00321 $fileId = isset($args[2]) ? (int) $args[2] : 0;
00322
00323 list($journal, $issue, $article) = ArticleHandler::validate($articleId, $galleyId);
00324
00325 $galleyDao = &DAORegistry::getDAO('ArticleGalleyDAO');
00326 if ($journal->getSetting('enablePublicGalleyId')) {
00327 $galley =& $galleyDao->getGalleyByBestGalleyId($galleyId, $article->getArticleId());
00328 } else {
00329 $galley =& $galleyDao->getGalley($galleyId, $article->getArticleId());
00330 }
00331
00332 if (!$galley) Request::redirect(null, null, 'view', $articleId);
00333
00334 if (!$fileId) {
00335 $galleyDao->incrementViews($galleyId);
00336 $fileId = $galley->getFileId();
00337 } else {
00338 if (!$galley->isDependentFile($fileId)) {
00339 Request::redirect(null, null, 'view', $articleId);
00340 }
00341 }
00342
00343 if (!HookRegistry::call('ArticleHandler::viewFile', array(&$article, &$galley, &$fileId))) {
00344
00345 import('submission.sectionEditor.SectionEditorAction');
00346 SectionEditorAction::viewFile($article->getArticleId(), $fileId);
00347 }
00348 }
00349
00353 function download($args) {
00354 $articleId = isset($args[0]) ? $args[0] : 0;
00355 $galleyId = isset($args[1]) ? $args[1] : 0;
00356 list($journal, $issue, $article) = ArticleHandler::validate($articleId, $galleyId);
00357
00358 $galleyDao = &DAORegistry::getDAO('ArticleGalleyDAO');
00359 if ($journal->getSetting('enablePublicGalleyId')) {
00360 $galley =& $galleyDao->getGalleyByBestGalleyId($galleyId, $article->getArticleId());
00361 } else {
00362 $galley =& $galleyDao->getGalley($galleyId, $article->getArticleId());
00363 }
00364 $galleyDao->incrementViews($galleyId);
00365
00366 if ($article && $galley && !HookRegistry::call('ArticleHandler::downloadFile', array(&$article, &$galley))) {
00367 import('file.ArticleFileManager');
00368 $articleFileManager = &new ArticleFileManager($article->getArticleId());
00369 $articleFileManager->downloadFile($galley->getFileId());
00370 }
00371 }
00372
00373 function downloadSuppFile($args) {
00374 $articleId = isset($args[0]) ? $args[0] : 0;
00375 $suppId = isset($args[1]) ? $args[1] : 0;
00376 list($journal, $issue, $article) = ArticleHandler::validate($articleId);
00377
00378 $suppFileDao = &DAORegistry::getDAO('SuppFileDAO');
00379 if ($journal->getSetting('enablePublicSuppFileId')) {
00380 $suppFile = &$suppFileDao->getSuppFileByBestSuppFileId($article->getArticleId(), $suppId);
00381 } else {
00382 $suppFile = &$suppFileDao->getSuppFile((int) $suppId, $article->getArticleId());
00383 }
00384
00385 if ($article && $suppFile) {
00386 import('file.ArticleFileManager');
00387 $articleFileManager = &new ArticleFileManager($article->getArticleId());
00388 if ($suppFile->isInlineable()) {
00389 $articleFileManager->viewFile($suppFile->getFileId());
00390 } else {
00391 $articleFileManager->downloadFile($suppFile->getFileId());
00392 }
00393 }
00394 }
00395
00399 function validate($articleId, $galleyId = null) {
00400 parent::validate(true);
00401
00402 import('issue.IssueAction');
00403
00404 $journal = &Request::getJournal();
00405 $journalId = $journal->getJournalId();
00406 $article = $publishedArticle = $issue = null;
00407
00408 $publishedArticleDao = &DAORegistry::getDAO('PublishedArticleDAO');
00409 if ($journal->getSetting('enablePublicArticleId')) {
00410 $publishedArticle = &$publishedArticleDao->getPublishedArticleByBestArticleId($journalId, $articleId);
00411 } else {
00412 $publishedArticle = &$publishedArticleDao->getPublishedArticleByArticleId((int) $articleId, $journalId);
00413 }
00414
00415 $issueDao = &DAORegistry::getDAO('IssueDAO');
00416 if (isset($publishedArticle)) {
00417 $issue = &$issueDao->getIssueByArticleId($publishedArticle->getArticleId(), $journalId);
00418 } else {
00419 $articleDao =& DAORegistry::getDAO('ArticleDAO');
00420 $article =& $articleDao->getArticle((int) $articleId, $journalId);
00421 }
00422
00423
00424
00425 if (($article || $publishedArticle) && IssueAction::allowedPrePublicationAccess($journal)) {
00426 return array($journal, $issue, $publishedArticle?$publishedArticle:$article);
00427 }
00428
00429
00430 if ($issue && $issue->getPublished()) {
00431 $subscriptionRequired = IssueAction::subscriptionRequired($issue);
00432 $isSubscribedDomain = IssueAction::subscribedDomain($journal, $issue->getIssueId(), $articleId);
00433
00434
00435 if (!$isSubscribedDomain && !Validation::isLoggedIn() && $journal->getSetting('restrictArticleAccess') && isset($galleyId) && $galleyId != 0) {
00436 Validation::redirectLogin();
00437 }
00438
00439
00440
00441 if ( (!$isSubscribedDomain && $subscriptionRequired) &&
00442 (isset($galleyId) && $galleyId!=0) ) {
00443
00444
00445 $subscribedUser = IssueAction::subscribedUser($journal, $issue->getIssueId(), $articleId);
00446
00447 if (!(!$subscriptionRequired || $publishedArticle->getAccessStatus() || $subscribedUser)) {
00448
00449 import('payment.ojs.OJSPaymentManager');
00450 $paymentManager =& OJSPaymentManager::getManager();
00451
00452 if ( $paymentManager->purchaseArticleEnabled() || $paymentManager->membershipEnabled() ) {
00453
00454
00455 if ( $paymentManager->onlyPdfEnabled() ) {
00456 $galleyDAO =& DAORegistry::getDAO('ArticleGalleyDAO');
00457 if ($journal->getSetting('enablePublicGalleyId')) {
00458 $galley =& $galleyDAO->getGalley($galleyId, $articleId);
00459 } else {
00460 $galley =& $galleyDAO->getGalleyByBestGalleyId($galleyId, $articleId);
00461 }
00462 if ( $galley && !$galley->isPdfGalley() ) {
00463 return array($journal, $issue, $publishedArticle);
00464 }
00465 }
00466
00467 if (!Validation::isLoggedIn()) {
00468 Validation::redirectLogin("payment.loginRequired.forArticle");
00469 }
00470 $user = &Request::getUser();
00471 $userId = $user->getUserId();
00472
00473
00474
00475 $completedPaymentDAO =& DAORegistry::getDAO('OJSCompletedPaymentDAO');
00476 if ( $completedPaymentDAO->hasPaidPerViewArticle($userId, $articleId)
00477 || (!is_null($user->getDateEndMembership()) && strtotime($user->getDateEndMembership()) > time()) ) {
00478 return array($journal, $issue, $publishedArticle);
00479 } else {
00480 $queuedPayment =& $paymentManager->createQueuedPayment($journalId, PAYMENT_TYPE_PURCHASE_ARTICLE, $user->getUserId(), $articleId, $journal->getSetting('purchaseArticleFee'));
00481 $queuedPaymentId = $paymentManager->queuePayment($queuedPayment);
00482
00483 $templateMgr =& TemplateManager::getManager();
00484 $paymentManager->displayPaymentForm($queuedPaymentId, $queuedPayment);
00485 exit;
00486 }
00487 }
00488
00489 if (!isset($galleyId) || $galleyId) {
00490 if (!Validation::isLoggedIn()) {
00491 Validation::redirectLogin("reader.subscriptionRequiredLoginText");
00492 }
00493 Request::redirect(null, 'about', 'subscriptions');
00494 }
00495 }
00496 }
00497 } else {
00498 Request::redirect(null, 'index');
00499 }
00500 return array($journal, $issue, $publishedArticle);
00501 }
00502
00503 }
00504
00505 ?>