PageRenderTime 46ms CodeModel.GetById 14ms RepoModel.GetById 1ms app.codeStats 0ms

/pages/paper/PaperHandler.inc.php

https://github.com/lib-uoguelph-ca/ocs
PHP | 486 lines | 314 code | 88 blank | 84 comment | 63 complexity | 52db31bd66a2415f9d4dd97b1b86cb77 MD5 | raw file
Possible License(s): GPL-2.0
  1. <?php
  2. /**
  3. * @file PaperHandler.inc.php
  4. *
  5. * Copyright (c) 2000-2012 John Willinsky
  6. * Distributed under the GNU GPL v2. For full terms see the file docs/COPYING.
  7. *
  8. * @class PaperHandler
  9. * @ingroup pages_paper
  10. *
  11. * Handle requests for paper functions.
  12. *
  13. */
  14. // $Id$
  15. import('rt.ocs.RTDAO');
  16. import('rt.ocs.ConferenceRT');
  17. import('handler.Handler');
  18. class PaperHandler extends Handler {
  19. /** the paper associated with this request **/
  20. var $paper;
  21. /**
  22. * Constructor
  23. * @param $request Request
  24. */
  25. function PaperHandler(&$request) {
  26. parent::Handler($request);
  27. $this->addCheck(new HandlerValidatorConference($this));
  28. $this->addCheck(new HandlerValidatorSchedConf($this));
  29. }
  30. /**
  31. * View Paper.
  32. * @param $args array
  33. * @param $request Request
  34. */
  35. function view($args, &$request) {
  36. $router =& $request->getRouter();
  37. $paperId = isset($args[0]) ? $args[0] : 0;
  38. $galleyId = isset($args[1]) ? (int) $args[1] : 0;
  39. $this->validate($request, $paperId, $galleyId);
  40. $conference =& $router->getContext($request, CONTEXT_CONFERENCE);
  41. $paper =& $this->paper;
  42. $this->setupTemplate();
  43. // manager.scheduler.building / manager.scheduler.room
  44. AppLocale::requireComponents(array(LOCALE_COMPONENT_OCS_MANAGER));
  45. $rtDao =& DAORegistry::getDAO('RTDAO');
  46. $conferenceRt = $rtDao->getConferenceRTByConference($conference);
  47. $galleyDao =& DAORegistry::getDAO('PaperGalleyDAO');
  48. $galley =& $galleyDao->getGalley($galleyId, $paper->getId());
  49. if (!$conferenceRt->getEnabled()) {
  50. if (!$galley || $galley->isHtmlGalley()) return PaperHandler::viewPaper($args, $request);
  51. else if ($galley->isPdfGalley()) return PaperHandler::viewPDFInterstitial($args, $request, $galley);
  52. else return PaperHandler::viewDownloadInterstitial($args, $request, $galley);
  53. }
  54. if (!$paper) {
  55. $request->redirect(null, null, null, $router->getRequestedPage($request));
  56. return;
  57. }
  58. $templateMgr =& TemplateManager::getManager();
  59. $templateMgr->assign('paperId', $paperId);
  60. $templateMgr->assign_by_ref('paper', $paper);
  61. $templateMgr->assign('galleyId', $galleyId);
  62. $templateMgr->assign_by_ref('galley', $galley);
  63. $templateMgr->display('paper/view.tpl');
  64. }
  65. /**
  66. * Paper interstitial page before PDF is shown
  67. * @param $args array
  68. * @param $request Request
  69. * @param $galley PaperGalley
  70. */
  71. function viewPDFInterstitial($args, &$request, $galley = null) {
  72. $paperId = isset($args[0]) ? $args[0] : 0;
  73. $galleyId = isset($args[1]) ? (int) $args[1] : 0;
  74. $this->validate($request, $paperId, $galleyId);
  75. $paper =& $this->paper;
  76. $this->setupTemplate();
  77. if (!$galley) {
  78. $galleyDao =& DAORegistry::getDAO('PaperGalleyDAO');
  79. $galley =& $galleyDao->getGalley($galleyId, $paper->getId());
  80. }
  81. if (!$galley) $request->redirect(null, null, 'view', $paperId);
  82. $templateMgr =& TemplateManager::getManager();
  83. $templateMgr->assign('paperId', $paperId);
  84. $templateMgr->assign('galleyId', $galleyId);
  85. $templateMgr->assign_by_ref('galley', $galley);
  86. $templateMgr->display('paper/pdfInterstitial.tpl');
  87. }
  88. /**
  89. * Paper interstitial page before a non-PDF, non-HTML galley is
  90. * downloaded
  91. * @param $args array
  92. * @param $request Request
  93. * @param $galley PaperGalley
  94. */
  95. function viewDownloadInterstitial($args, &$request, $galley = null) {
  96. $paperId = isset($args[0]) ? $args[0] : 0;
  97. $galleyId = isset($args[1]) ? (int) $args[1] : 0;
  98. $this->validate($request, $paperId, $galleyId);
  99. $paper =& $this->paper;
  100. $this->setupTemplate();
  101. if (!$galley) {
  102. $galleyDao =& DAORegistry::getDAO('PaperGalleyDAO');
  103. $galley =& $galleyDao->getGalley($galleyId, $paper->getId());
  104. }
  105. if (!$galley) $request->redirect(null, null, 'view', $paperId);
  106. $templateMgr =& TemplateManager::getManager();
  107. $templateMgr->assign('paperId', $paperId);
  108. $templateMgr->assign('galleyId', $galleyId);
  109. $templateMgr->assign_by_ref('galley', $galley);
  110. $templateMgr->display('paper/interstitial.tpl');
  111. }
  112. /**
  113. * Paper view
  114. * @param $args array
  115. * @param $request Request
  116. */
  117. function viewPaper($args, &$request) {
  118. $router =& $request->getRouter();
  119. $paperId = isset($args[0]) ? $args[0] : 0;
  120. $galleyId = isset($args[1]) ? (int) $args[1] : 0;
  121. $this->validate($request, $paperId, $galleyId);
  122. $conference =& $router->getContext($request, CONTEXT_CONFERENCE);
  123. $schedConf =& $router->getContext($request, CONTEXT_SCHED_CONF);
  124. $paper =& $this->paper;
  125. $this->setupTemplate();
  126. $rtDao =& DAORegistry::getDAO('RTDAO');
  127. $conferenceRt = $rtDao->getConferenceRTByConference($conference);
  128. $trackDao =& DAORegistry::getDAO('TrackDAO');
  129. $track =& $trackDao->getTrack($paper->getTrackId());
  130. if ($conferenceRt->getVersion()!=null && $conferenceRt->getDefineTerms()) {
  131. // Determine the "Define Terms" context ID.
  132. $version = $rtDao->getVersion($conferenceRt->getVersion(), $conferenceRt->getConferenceId());
  133. if ($version) foreach ($version->getContexts() as $context) {
  134. if ($context->getDefineTerms()) {
  135. $defineTermsContextId = $context->getContextId();
  136. break;
  137. }
  138. }
  139. }
  140. $commentDao =& DAORegistry::getDAO('CommentDAO');
  141. $enableComments = $conference->getSetting('enableComments');
  142. $commentsRequireRegistration = $conference->getSetting('commentsRequireRegistration');
  143. $commentsAllowAnonymous = $conference->getSetting('commentsAllowAnonymous');
  144. if ($enableComments && $paper->getEnableComments()) {
  145. $comments =& $commentDao->getRootCommentsByPaperId($paper->getId());
  146. }
  147. $paperGalleyDao =& DAORegistry::getDAO('PaperGalleyDAO');
  148. $galley =& $paperGalleyDao->getGalley($galleyId, $paper->getId());
  149. $templateMgr =& TemplateManager::getManager();
  150. if (!$galley) {
  151. // Get the registration status if displaying the abstract;
  152. // if access is open, we can display links to the full text.
  153. import('schedConf.SchedConfAction');
  154. $templateMgr->assign('mayViewPaper', SchedConfAction::mayViewPapers($schedConf, $conference));
  155. $templateMgr->assign('registeredUser', SchedConfAction::registeredUser($schedConf));
  156. $templateMgr->assign('registeredDomain', SchedConfAction::registeredDomain($schedConf));
  157. // Increment the published paper's abstract views count
  158. $publishedPaperDao =& DAORegistry::getDAO('PublishedPaperDAO');
  159. $publishedPaperDao->incrementViewsByPaperId($paper->getId());
  160. } else {
  161. // Increment the galley's views count
  162. $paperGalleyDao->incrementViews($galleyId);
  163. // Use the paper's CSS file, if set.
  164. if ($galley->isHTMLGalley() && $styleFile =& $galley->getStyleFile()) {
  165. $templateMgr->addStyleSheet($router->url($request, null, null, 'paper', 'viewFile', array(
  166. $paper->getId(),
  167. $galley->getId(),
  168. $styleFile->getFileId()
  169. )));
  170. }
  171. }
  172. // Add font sizer js and css if not already in header
  173. $additionalHeadData = $templateMgr->get_template_vars('additionalHeadData');
  174. if (strpos(strtolower($additionalHeadData), 'sizer.js') === false) {
  175. $additionalHeadData .= $templateMgr->fetch('common/sizer.tpl');
  176. $templateMgr->assign('additionalHeadData', $additionalHeadData);
  177. }
  178. $templateMgr->assign_by_ref('schedConf', $schedConf);
  179. $templateMgr->assign_by_ref('conference', $conference);
  180. $templateMgr->assign_by_ref('paper', $paper);
  181. $templateMgr->assign_by_ref('galley', $galley);
  182. $templateMgr->assign_by_ref('track', $track);
  183. $templateMgr->assign('paperId', $paperId);
  184. $closeCommentsDate = $schedConf->getSetting('closeCommentsDate');
  185. $commentsClosed = $schedConf->getSetting('closeComments')?true:false && (strtotime($closeCommentsDate < time()));
  186. $templateMgr->assign('closeCommentsDate', $closeCommentsDate);
  187. $templateMgr->assign('commentsClosed', $commentsClosed);
  188. $templateMgr->assign('postingAllowed', ($enableComments && !$commentsClosed && $paper->getEnableComments()) && (!$commentsRequireRegistration || Validation::isLoggedIn()));
  189. $templateMgr->assign('galleyId', $galleyId);
  190. $templateMgr->assign('defineTermsContextId', isset($defineTermsContextId)?$defineTermsContextId:null);
  191. $templateMgr->assign('comments', isset($comments)?$comments:null);
  192. if ($paper->getRoomId()) {
  193. $roomDao =& DAORegistry::getDAO('RoomDAO');
  194. $buildingDao =& DAORegistry::getDAO('BuildingDAO');
  195. $room =& $roomDao->getRoom($paper->getRoomId());
  196. if (!$room) break;
  197. $building =& $buildingDao->getBuilding($room->getBuildingId());
  198. $templateMgr->assign_by_ref('room', $room);
  199. $templateMgr->assign_by_ref('building', $building);
  200. }
  201. $templateMgr->display('paper/paper.tpl');
  202. }
  203. /**
  204. * Paper Reading tools
  205. * @param $args array
  206. * @param $request Request
  207. */
  208. function viewRST($args, &$request) {
  209. $router =& $request->getRouter();
  210. $paperId = isset($args[0]) ? $args[0] : 0;
  211. $galleyId = isset($args[1]) ? (int) $args[1] : 0;
  212. $this->validate($request, $paperId, $galleyId);
  213. $conference =& $router->getContext($request, CONTEXT_CONFERENCE);
  214. $schedConf =& $router->getContext($request, CONTEXT_SCHED_CONF);
  215. $paper =& $this->paper;
  216. $this->setupTemplate();
  217. $rtDao =& DAORegistry::getDAO('RTDAO');
  218. $conferenceRt = $rtDao->getConferenceRTByConference($conference);
  219. // The RST needs to know whether this galley is HTML or not. Fetch the galley.
  220. $paperGalleyDao =& DAORegistry::getDAO('PaperGalleyDAO');
  221. $galley =& $paperGalleyDao->getGalley($galleyId, $paper->getId());
  222. $trackDao =& DAORegistry::getDAO('TrackDAO');
  223. $track =& $trackDao->getTrack($paper->getTrackId());
  224. $templateMgr =& TemplateManager::getManager();
  225. $templateMgr->assign_by_ref('schedConf', $schedConf);
  226. $templateMgr->assign_by_ref('paper', $paper);
  227. $templateMgr->assign('paperId', $paperId);
  228. $templateMgr->assign('galleyId', $galleyId);
  229. $templateMgr->assign_by_ref('galley', $galley);
  230. $templateMgr->assign_by_ref('conference', $conference);
  231. $templateMgr->assign_by_ref('track', $track);
  232. $templateMgr->assign('paperSearchByOptions', array(
  233. '' => 'search.allFields',
  234. PAPER_SEARCH_AUTHOR => 'search.author',
  235. PAPER_SEARCH_TITLE => 'paper.title',
  236. PAPER_SEARCH_ABSTRACT => 'search.abstract',
  237. PAPER_SEARCH_INDEX_TERMS => 'search.indexTerms',
  238. PAPER_SEARCH_GALLEY_FILE => 'search.fullText'
  239. ));
  240. // Bring in comment constants.
  241. $commentDao =& DAORegistry::getDAO('CommentDAO');
  242. $enableComments = $conference->getSetting('enableComments');
  243. $commentsRequireRegistration = $conference->getSetting('commentsRequireRegistration');
  244. $commentsAllowAnonymous = $conference->getSetting('commentsAllowAnonymous');
  245. $closeCommentsDate = $schedConf->getSetting('closeCommentsDate');
  246. $commentsClosed = $schedConf->getSetting('closeComments')?true:false && (strtotime($closeCommentsDate < time()));
  247. $postingAllowed = $enableComments && $paper->getEnableComments() && !$commentsClosed ? true : false;
  248. $templateMgr->assign('closeCommentsDate', $closeCommentsDate);
  249. $templateMgr->assign('commentsClosed', $commentsClosed);
  250. $templateMgr->assign('postingAllowed', $postingAllowed);
  251. $templateMgr->assign('postingDisabled', $postingAllowed && ($commentsRequireRegistration && !Validation::isLoggedIn()));
  252. $templateMgr->assign_by_ref('conferenceRt', $conferenceRt);
  253. if ($conferenceRt->getEnabled()) {
  254. $version = $rtDao->getVersion($conferenceRt->getVersion(), $conferenceRt->getConferenceId());
  255. if ($version) {
  256. $templateMgr->assign_by_ref('version', $version);
  257. }
  258. }
  259. $templateMgr->display('rt/rt.tpl');
  260. }
  261. /**
  262. * View a file (inlines file).
  263. * @param $args array ($paperId, $galleyId, $fileId [optional])
  264. * @param $request Request
  265. */
  266. function viewFile($args, &$request) {
  267. $paperId = isset($args[0]) ? $args[0] : 0;
  268. $galleyId = isset($args[1]) ? $args[1] : 0;
  269. $fileId = isset($args[2]) ? (int) $args[2] : 0;
  270. $this->validate($request, $paperId, $galleyId);
  271. $paper =& $this->paper;
  272. $this->setupTemplate();
  273. $galleyDao =& DAORegistry::getDAO('PaperGalleyDAO');
  274. $galley =& $galleyDao->getGalley($galleyId, $paper->getId());
  275. if (!$galley) $request->redirect(null, null, null, null, 'view', $paperId);
  276. if (!$fileId) {
  277. $galleyDao->incrementViews($galleyId);
  278. $fileId = $galley->getFileId();
  279. } else {
  280. if (!$galley->isDependentFile($fileId)) {
  281. $request->redirect(null, null, null, null, 'view', $paperId);
  282. }
  283. }
  284. // reuse track director's view file function
  285. import('submission.trackDirector.TrackDirectorAction');
  286. TrackDirectorAction::viewFile($paper->getId(), $fileId);
  287. }
  288. /**
  289. * Downloads the document
  290. * @param $args array
  291. * @param $request Request
  292. */
  293. function download($args, &$request) {
  294. $paperId = isset($args[0]) ? $args[0] : 0;
  295. $galleyId = isset($args[1]) ? (int)$args[1] : 0;
  296. $this->validate($request, $paperId, $galleyId);
  297. $paper =& $this->paper;
  298. $galleyDao =& DAORegistry::getDAO('PaperGalleyDAO');
  299. $galley =& $galleyDao->getGalley($galleyId, $paper->getId());
  300. $galleyDao->incrementViews($galleyId);
  301. if ($paper && $galley) {
  302. import('file.PaperFileManager');
  303. $paperFileManager = new PaperFileManager($paper->getId());
  304. $paperFileManager->downloadFile($galley->getFileId());
  305. }
  306. }
  307. /**
  308. * Downloads a supplementary file
  309. * @param $args array
  310. * @param $request Request
  311. */
  312. function downloadSuppFile($args, &$request) {
  313. $router =& $request->getRouter();
  314. $paperId = isset($args[0]) ? $args[0] : 0;
  315. $suppId = isset($args[1]) ? $args[1] : 0;
  316. $schedConf =& $router->getContext($request, CONTEXT_SCHED_CONF);
  317. $this->validate($request, $paperId);
  318. $paper =& $this->paper;
  319. $suppFileDao =& DAORegistry::getDAO('SuppFileDAO');
  320. if ($schedConf->getSetting('enablePublicSuppFileId')) {
  321. $suppFile =& $suppFileDao->getSuppFileByBestSuppFileId($paper->getId(), $suppId);
  322. } else {
  323. $suppFile =& $suppFileDao->getSuppFile((int) $suppId, $paper->getId());
  324. }
  325. if ($paper && $suppFile) {
  326. import('file.PaperFileManager');
  327. $paperFileManager = new PaperFileManager($paper->getId());
  328. if ($suppFile->isInlineable()) {
  329. $paperFileManager->viewFile($suppFile->getFileId());
  330. } else {
  331. $paperFileManager->downloadFile($suppFile->getFileId());
  332. }
  333. }
  334. }
  335. /**
  336. * Validation
  337. * @see lib/pkp/classes/handler/PKPHandler#validate()
  338. * @param $request Request
  339. * @param $paperId integer
  340. * @param $galleyId integer
  341. */
  342. function validate(&$request, $paperId, $galleyId = null) {
  343. $router =& $request->getRouter();
  344. parent::validate(null, $request);
  345. $conference =& $router->getContext($request, CONTEXT_CONFERENCE);
  346. $schedConf =& $router->getContext($request, CONTEXT_SCHED_CONF);
  347. $conferenceId = $conference->getId();
  348. $publishedPaperDao =& DAORegistry::getDAO('PublishedPaperDAO');
  349. if ($schedConf->getSetting('enablePublicPaperId')) {
  350. $paper =& $publishedPaperDao->getPublishedPaperByBestPaperId(
  351. $schedConf->getId(),
  352. $paperId,
  353. $schedConf->getSetting('previewAbstracts')?true:false
  354. );
  355. } else {
  356. $paper =& $publishedPaperDao->getPublishedPaperByPaperId(
  357. (int) $paperId,
  358. $schedConf->getId(),
  359. $schedConf->getSetting('previewAbstracts')?true:false
  360. );
  361. }
  362. // if paper does not exist, is not published, or is not part of
  363. // the right conference & sched conf, redirect to index.
  364. if (isset($schedConf) && isset($paper) && isset($conference) &&
  365. $paper->getSchedConfId() == $schedConf->getId() &&
  366. $schedConf->getConferenceId() == $conference->getId()) {
  367. // Check if login is required for viewing.
  368. if (!Validation::isLoggedIn() && $schedConf->getSetting('restrictPaperAccess')) {
  369. Validation::redirectLogin();
  370. }
  371. import('schedConf.SchedConfAction');
  372. $mayViewPaper = SchedConfAction::mayViewPapers($schedConf, $conference);
  373. if (
  374. // Bar access to paper?
  375. ((isset($galleyId) && $galleyId!=0) && !$mayViewPaper) ||
  376. // Bar access to abstract?
  377. ((!isset($galleyId) || $galleyId==0) && !SchedConfAction::mayViewProceedings($schedConf))
  378. ) {
  379. $this->setupTemplate();
  380. $templateMgr =& TemplateManager::getManager();
  381. $templateMgr->assign_by_ref('paper', $paper);
  382. $templateMgr->assign_by_ref('schedConf', $schedConf);
  383. $templateMgr->assign_by_ref('conference', $conference);
  384. $templateMgr->display('paper/accessDenied.tpl');
  385. exit;
  386. }
  387. } else {
  388. $request->redirect(null, null, 'index');
  389. }
  390. $this->paper =& $paper;
  391. return true;
  392. }
  393. function setupTemplate() {
  394. parent::setupTemplate();
  395. AppLocale::requireComponents(array(LOCALE_COMPONENT_PKP_READER, LOCALE_COMPONENT_PKP_SUBMISSION));
  396. }
  397. }
  398. ?>