pages/paper/PaperHandler.inc.php

Go to the documentation of this file.
00001 <?php
00002 
00016 // $Id$
00017 
00018 
00019 import('rt.ocs.RTDAO');
00020 import('rt.ocs.ConferenceRT');
00021 import('handler.Handler');
00022 
00023 class PaperHandler extends Handler {
00025    var $paper;
00026 
00031    function PaperHandler(&$request) {
00032       parent::Handler($request);
00033 
00034       $this->addCheck(new HandlerValidatorConference($this));
00035       $this->addCheck(new HandlerValidatorSchedConf($this));
00036    }
00037 
00043    function view($args, &$request) {
00044       $router =& $request->getRouter();
00045       $paperId = isset($args[0]) ? $args[0] : 0;
00046       $galleyId = isset($args[1]) ? (int) $args[1] : 0;
00047 
00048       $this->validate($request, $paperId, $galleyId);
00049       $conference =& $router->getContext($request, CONTEXT_CONFERENCE);
00050       $paper =& $this->paper;
00051       $this->setupTemplate();
00052 
00053       // manager.scheduler.building / manager.scheduler.room
00054       AppLocale::requireComponents(array(LOCALE_COMPONENT_OCS_MANAGER));
00055 
00056       $rtDao =& DAORegistry::getDAO('RTDAO');
00057       $conferenceRt = $rtDao->getConferenceRTByConference($conference);
00058 
00059       $galleyDao =& DAORegistry::getDAO('PaperGalleyDAO');
00060       $galley =& $galleyDao->getGalley($galleyId, $paper->getId());
00061 
00062       if (!$conferenceRt->getEnabled()) {
00063          if (!$galley || $galley->isHtmlGalley()) return PaperHandler::viewPaper($args, $request);
00064          else if ($galley->isPdfGalley()) return PaperHandler::viewPDFInterstitial($args, $request, $galley);
00065          else return PaperHandler::viewDownloadInterstitial($args, $request, $galley);
00066       }
00067 
00068       if (!$paper) {
00069          $request->redirect(null, null, null, $router->getRequestedPage($request));
00070          return;
00071       }
00072 
00073       $templateMgr =& TemplateManager::getManager();
00074       $templateMgr->assign('paperId', $paperId);
00075       $templateMgr->assign_by_ref('paper', $paper);
00076       $templateMgr->assign('galleyId', $galleyId);
00077       $templateMgr->assign_by_ref('galley', $galley);
00078 
00079       $templateMgr->display('paper/view.tpl');
00080    }
00081 
00088    function viewPDFInterstitial($args, &$request, $galley = null) {
00089       $paperId = isset($args[0]) ? $args[0] : 0;
00090       $galleyId = isset($args[1]) ? (int) $args[1] : 0;
00091       $this->validate($request, $paperId, $galleyId);
00092       $paper =& $this->paper;
00093       $this->setupTemplate();
00094 
00095       if (!$galley) {
00096          $galleyDao =& DAORegistry::getDAO('PaperGalleyDAO');
00097          $galley =& $galleyDao->getGalley($galleyId, $paper->getId());
00098       }
00099 
00100       if (!$galley) $request->redirect(null, null, 'view', $paperId);
00101 
00102       $templateMgr =& TemplateManager::getManager();
00103       $templateMgr->assign('paperId', $paperId);
00104       $templateMgr->assign('galleyId', $galleyId);
00105       $templateMgr->assign_by_ref('galley', $galley);
00106 
00107       $templateMgr->display('paper/pdfInterstitial.tpl');
00108    }
00109 
00117    function viewDownloadInterstitial($args, &$request, $galley = null) {
00118       $paperId = isset($args[0]) ? $args[0] : 0;
00119       $galleyId = isset($args[1]) ? (int) $args[1] : 0;
00120 
00121       $this->validate($request, $paperId, $galleyId);
00122       $paper =& $this->paper;
00123       $this->setupTemplate();
00124 
00125       if (!$galley) {
00126          $galleyDao =& DAORegistry::getDAO('PaperGalleyDAO');
00127          $galley =& $galleyDao->getGalley($galleyId, $paper->getId());
00128       }
00129 
00130       if (!$galley) $request->redirect(null, null, 'view', $paperId);
00131 
00132       $templateMgr =& TemplateManager::getManager();
00133       $templateMgr->assign('paperId', $paperId);
00134       $templateMgr->assign('galleyId', $galleyId);
00135       $templateMgr->assign_by_ref('galley', $galley);
00136 
00137       $templateMgr->display('paper/interstitial.tpl');
00138    }
00139 
00145    function viewPaper($args, &$request) {
00146       $router =& $request->getRouter();
00147       $paperId = isset($args[0]) ? $args[0] : 0;
00148       $galleyId = isset($args[1]) ? (int) $args[1] : 0;
00149 
00150       $this->validate($request, $paperId, $galleyId);
00151       $conference =& $router->getContext($request, CONTEXT_CONFERENCE);
00152       $schedConf =& $router->getContext($request, CONTEXT_SCHED_CONF);
00153       $paper =& $this->paper;
00154       $this->setupTemplate();
00155 
00156       $rtDao =& DAORegistry::getDAO('RTDAO');
00157       $conferenceRt = $rtDao->getConferenceRTByConference($conference);
00158 
00159       $trackDao =& DAORegistry::getDAO('TrackDAO');
00160       $track =& $trackDao->getTrack($paper->getTrackId());
00161 
00162       if ($conferenceRt->getVersion()!=null && $conferenceRt->getDefineTerms()) {
00163          // Determine the "Define Terms" context ID.
00164          $version = $rtDao->getVersion($conferenceRt->getVersion(), $conferenceRt->getConferenceId());
00165          if ($version) foreach ($version->getContexts() as $context) {
00166             if ($context->getDefineTerms()) {
00167                $defineTermsContextId = $context->getContextId();
00168                break;
00169             }
00170          }
00171       }
00172 
00173       $commentDao =& DAORegistry::getDAO('CommentDAO');
00174       $enableComments = $conference->getSetting('enableComments');
00175       $commentsRequireRegistration = $conference->getSetting('commentsRequireRegistration');
00176       $commentsAllowAnonymous = $conference->getSetting('commentsAllowAnonymous');
00177 
00178       if ($enableComments && $paper->getEnableComments()) {
00179          $comments =& $commentDao->getRootCommentsByPaperId($paper->getId());
00180       }
00181 
00182       $paperGalleyDao =& DAORegistry::getDAO('PaperGalleyDAO');
00183       $galley =& $paperGalleyDao->getGalley($galleyId, $paper->getId());
00184 
00185       $templateMgr =& TemplateManager::getManager();
00186 
00187       if (!$galley) {
00188          // Get the registration status if displaying the abstract;
00189          // if access is open, we can display links to the full text.
00190          import('schedConf.SchedConfAction');
00191          $templateMgr->assign('mayViewPaper', SchedConfAction::mayViewPapers($schedConf, $conference));
00192          $templateMgr->assign('registeredUser', SchedConfAction::registeredUser($schedConf));
00193          $templateMgr->assign('registeredDomain', SchedConfAction::registeredDomain($schedConf));
00194 
00195          // Increment the published paper's abstract views count
00196          $publishedPaperDao =& DAORegistry::getDAO('PublishedPaperDAO');
00197          $publishedPaperDao->incrementViewsByPaperId($paper->getId());
00198       } else {
00199          // Increment the galley's views count
00200          $paperGalleyDao->incrementViews($galleyId);
00201 
00202          // Use the paper's CSS file, if set.
00203          if ($galley->isHTMLGalley() && $styleFile =& $galley->getStyleFile()) {
00204             $templateMgr->addStyleSheet($router->url($request, null, null, 'paper', 'viewFile', array(
00205                $paper->getId(),
00206                $galley->getId(),
00207                $styleFile->getFileId()
00208             )));
00209          }
00210       }
00211 
00212       // Add font sizer js and css if not already in header
00213       $additionalHeadData = $templateMgr->get_template_vars('additionalHeadData');
00214       if (strpos(strtolower($additionalHeadData), 'sizer.js') === false) {
00215          $additionalHeadData .= $templateMgr->fetch('common/sizer.tpl');
00216          $templateMgr->assign('additionalHeadData', $additionalHeadData);
00217       }
00218 
00219       $templateMgr->assign_by_ref('schedConf', $schedConf);
00220       $templateMgr->assign_by_ref('conference', $conference);
00221       $templateMgr->assign_by_ref('paper', $paper);
00222       $templateMgr->assign_by_ref('galley', $galley);
00223       $templateMgr->assign_by_ref('track', $track);
00224       $templateMgr->assign('paperId', $paperId);
00225 
00226       $closeCommentsDate = $schedConf->getSetting('closeCommentsDate');
00227       $commentsClosed = $schedConf->getSetting('closeComments')?true:false && (strtotime($closeCommentsDate < time()));
00228       $templateMgr->assign('closeCommentsDate', $closeCommentsDate);
00229       $templateMgr->assign('commentsClosed', $commentsClosed);
00230       $templateMgr->assign('postingAllowed', ($enableComments && !$commentsClosed && $paper->getEnableComments()) && (!$commentsRequireRegistration || Validation::isLoggedIn()));
00231       $templateMgr->assign('galleyId', $galleyId);
00232       $templateMgr->assign('defineTermsContextId', isset($defineTermsContextId)?$defineTermsContextId:null);
00233       $templateMgr->assign('comments', isset($comments)?$comments:null);
00234 
00235       if ($paper->getRoomId()) {
00236          $roomDao =& DAORegistry::getDAO('RoomDAO');
00237          $buildingDao =& DAORegistry::getDAO('BuildingDAO');
00238 
00239          $room =& $roomDao->getRoom($paper->getRoomId());
00240          if (!$room) break;
00241 
00242          $building =& $buildingDao->getBuilding($room->getBuildingId());
00243          $templateMgr->assign_by_ref('room', $room);
00244          $templateMgr->assign_by_ref('building', $building);
00245       }
00246 
00247       $templateMgr->display('paper/paper.tpl');
00248    }
00249 
00255    function viewRST($args, &$request) {
00256       $router =& $request->getRouter();
00257       $paperId = isset($args[0]) ? $args[0] : 0;
00258       $galleyId = isset($args[1]) ? (int) $args[1] : 0;
00259 
00260       $this->validate($request, $paperId, $galleyId);
00261 
00262       $conference =& $router->getContext($request, CONTEXT_CONFERENCE);
00263       $schedConf =& $router->getContext($request, CONTEXT_SCHED_CONF);
00264       $paper =& $this->paper;
00265       $this->setupTemplate();
00266 
00267       $rtDao =& DAORegistry::getDAO('RTDAO');
00268       $conferenceRt = $rtDao->getConferenceRTByConference($conference);
00269 
00270       // The RST needs to know whether this galley is HTML or not. Fetch the galley.
00271       $paperGalleyDao =& DAORegistry::getDAO('PaperGalleyDAO');
00272       $galley =& $paperGalleyDao->getGalley($galleyId, $paper->getId());
00273 
00274       $trackDao =& DAORegistry::getDAO('TrackDAO');
00275       $track =& $trackDao->getTrack($paper->getTrackId());
00276 
00277       $templateMgr =& TemplateManager::getManager();
00278 
00279       $templateMgr->assign_by_ref('schedConf', $schedConf);
00280       $templateMgr->assign_by_ref('paper', $paper);
00281       $templateMgr->assign('paperId', $paperId);
00282       $templateMgr->assign('galleyId', $galleyId);
00283       $templateMgr->assign_by_ref('galley', $galley);
00284       $templateMgr->assign_by_ref('conference', $conference);
00285       $templateMgr->assign_by_ref('track', $track);
00286 
00287       $templateMgr->assign('paperSearchByOptions', array(
00288          '' => 'search.allFields',
00289          PAPER_SEARCH_AUTHOR => 'search.author',
00290          PAPER_SEARCH_TITLE => 'paper.title',
00291          PAPER_SEARCH_ABSTRACT => 'search.abstract',
00292          PAPER_SEARCH_INDEX_TERMS => 'search.indexTerms',
00293          PAPER_SEARCH_GALLEY_FILE => 'search.fullText'
00294       ));
00295 
00296       // Bring in comment constants.
00297       $commentDao =& DAORegistry::getDAO('CommentDAO');
00298 
00299       $enableComments = $conference->getSetting('enableComments');
00300       $commentsRequireRegistration = $conference->getSetting('commentsRequireRegistration');
00301       $commentsAllowAnonymous = $conference->getSetting('commentsAllowAnonymous');
00302 
00303       $closeCommentsDate = $schedConf->getSetting('closeCommentsDate');
00304       $commentsClosed = $schedConf->getSetting('closeComments')?true:false && (strtotime($closeCommentsDate < time()));
00305 
00306       $postingAllowed = $enableComments && $paper->getEnableComments() && !$commentsClosed ? true : false;
00307       $templateMgr->assign('closeCommentsDate', $closeCommentsDate);
00308       $templateMgr->assign('commentsClosed', $commentsClosed);
00309       $templateMgr->assign('postingAllowed', $postingAllowed);
00310       $templateMgr->assign('postingDisabled', $postingAllowed && ($commentsRequireRegistration && !Validation::isLoggedIn()));
00311 
00312       $templateMgr->assign_by_ref('conferenceRt', $conferenceRt);
00313       if ($conferenceRt->getEnabled()) {
00314          $version = $rtDao->getVersion($conferenceRt->getVersion(), $conferenceRt->getConferenceId());
00315          if ($version) {
00316             $templateMgr->assign_by_ref('version', $version);
00317          }
00318       }
00319 
00320       $templateMgr->display('rt/rt.tpl');
00321    }
00322 
00328    function viewFile($args, &$request) {
00329       $paperId = isset($args[0]) ? $args[0] : 0;
00330       $galleyId = isset($args[1]) ? $args[1] : 0;
00331       $fileId = isset($args[2]) ? (int) $args[2] : 0;
00332 
00333       $this->validate($request, $paperId, $galleyId);
00334       $paper =& $this->paper;
00335       $this->setupTemplate();
00336 
00337       $galleyDao =& DAORegistry::getDAO('PaperGalleyDAO');
00338       $galley =& $galleyDao->getGalley($galleyId, $paper->getId());
00339 
00340       if (!$galley) $request->redirect(null, null, null, null, 'view', $paperId);
00341 
00342       if (!$fileId) {
00343          $galleyDao->incrementViews($galleyId);
00344          $fileId = $galley->getFileId();
00345       } else {
00346          if (!$galley->isDependentFile($fileId)) {
00347             $request->redirect(null, null, null, null, 'view', $paperId);
00348          }
00349       }
00350 
00351       // reuse track director's view file function
00352       import('submission.trackDirector.TrackDirectorAction');
00353       TrackDirectorAction::viewFile($paper->getId(), $fileId);
00354    }
00355 
00361    function download($args, &$request) {
00362       $paperId = isset($args[0]) ? $args[0] : 0;
00363       $galleyId = isset($args[1]) ? (int)$args[1] : 0;
00364 
00365       $this->validate($request, $paperId, $galleyId);
00366       $paper =& $this->paper;
00367 
00368       $galleyDao =& DAORegistry::getDAO('PaperGalleyDAO');
00369       $galley =& $galleyDao->getGalley($galleyId, $paper->getId());
00370       $galleyDao->incrementViews($galleyId);
00371 
00372       if ($paper && $galley) {
00373          import('file.PaperFileManager');
00374          $paperFileManager = new PaperFileManager($paper->getId());
00375          $paperFileManager->downloadFile($galley->getFileId());
00376       }
00377    }
00378 
00384    function downloadSuppFile($args, &$request) {
00385       $router =& $request->getRouter();
00386       $paperId = isset($args[0]) ? $args[0] : 0;
00387       $suppId = isset($args[1]) ? $args[1] : 0;
00388 
00389       $schedConf =& $router->getContext($request, CONTEXT_SCHED_CONF);
00390 
00391       $this->validate($request, $paperId);
00392       $paper =& $this->paper;
00393 
00394       $suppFileDao =& DAORegistry::getDAO('SuppFileDAO');
00395       if ($schedConf->getSetting('enablePublicSuppFileId')) {
00396          $suppFile =& $suppFileDao->getSuppFileByBestSuppFileId($paper->getId(), $suppId);
00397       } else {
00398          $suppFile =& $suppFileDao->getSuppFile((int) $suppId, $paper->getId());
00399       }
00400 
00401       if ($paper && $suppFile) {
00402          import('file.PaperFileManager');
00403          $paperFileManager = new PaperFileManager($paper->getId());
00404          if ($suppFile->isInlineable()) {
00405             $paperFileManager->viewFile($suppFile->getFileId());
00406          } else {
00407             $paperFileManager->downloadFile($suppFile->getFileId());
00408          }
00409       }
00410    }
00411 
00419    function validate(&$request, $paperId, $galleyId = null) {
00420       $router =& $request->getRouter();
00421       parent::validate(null, $request);
00422 
00423       $conference =& $router->getContext($request, CONTEXT_CONFERENCE);
00424       $schedConf =& $router->getContext($request, CONTEXT_SCHED_CONF);
00425 
00426       $conferenceId = $conference->getId();
00427       $publishedPaperDao =& DAORegistry::getDAO('PublishedPaperDAO');
00428 
00429       if ($schedConf->getSetting('enablePublicPaperId')) {
00430          $paper =& $publishedPaperDao->getPublishedPaperByBestPaperId(
00431             $schedConf->getId(),
00432             $paperId,
00433             $schedConf->getSetting('previewAbstracts')?true:false
00434          );
00435       } else {
00436          $paper =& $publishedPaperDao->getPublishedPaperByPaperId(
00437             (int) $paperId,
00438             $schedConf->getId(),
00439             $schedConf->getSetting('previewAbstracts')?true:false
00440          );
00441       }
00442 
00443       // if paper does not exist, is not published, or is not part of
00444       // the right conference & sched conf, redirect to index.
00445       if (isset($schedConf) && isset($paper) && isset($conference) &&
00446             $paper->getSchedConfId() == $schedConf->getId() &&
00447             $schedConf->getConferenceId() == $conference->getId()) {
00448 
00449          // Check if login is required for viewing.
00450          if (!Validation::isLoggedIn() && $schedConf->getSetting('restrictPaperAccess')) {
00451             Validation::redirectLogin();
00452          }
00453 
00454          import('schedConf.SchedConfAction');
00455          $mayViewPaper = SchedConfAction::mayViewPapers($schedConf, $conference);
00456 
00457          if (
00458             // Bar access to paper?
00459             ((isset($galleyId) && $galleyId!=0) && !$mayViewPaper) ||
00460             // Bar access to abstract?
00461             ((!isset($galleyId) || $galleyId==0) && !SchedConfAction::mayViewProceedings($schedConf))
00462          ) {
00463             $this->setupTemplate();          
00464             $templateMgr =& TemplateManager::getManager();
00465             $templateMgr->assign_by_ref('paper', $paper);
00466             $templateMgr->assign_by_ref('schedConf', $schedConf);
00467             $templateMgr->assign_by_ref('conference', $conference);
00468             $templateMgr->display('paper/accessDenied.tpl');
00469             exit;
00470          }
00471 
00472       } else {
00473          $request->redirect(null, null, 'index');
00474       }
00475 
00476       $this->paper =& $paper;
00477       return true;
00478    }
00479 
00480    function setupTemplate() {
00481       parent::setupTemplate();
00482       AppLocale::requireComponents(array(LOCALE_COMPONENT_PKP_READER, LOCALE_COMPONENT_PKP_SUBMISSION));
00483    }
00484 }
00485 
00486 ?>

Generated on 25 Jul 2013 for Open Conference Systems by  doxygen 1.4.7