PageRenderTime 26ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/ojs/ojs-2.2.2/pages/rt/RTHandler.inc.php

https://github.com/mcrider/pkpUpgradeTestSuite
PHP | 414 lines | 283 code | 72 blank | 59 comment | 45 complexity | 09ebac4b3b51747b3ccb5e05be72c24a MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1
  1. <?php
  2. /**
  3. * @file RTHandler.inc.php
  4. *
  5. * Copyright (c) 2003-2008 John Willinsky
  6. * Distributed under the GNU GPL v2. For full terms see the file docs/COPYING.
  7. *
  8. * @class RTHandler
  9. * @ingroup pages_rt
  10. *
  11. * @brief Handle Reading Tools requests.
  12. */
  13. // $Id: RTHandler.inc.php,v 1.55 2008/07/01 01:16:12 asmecher Exp $
  14. import('rt.RT');
  15. import('rt.ojs.RTDAO');
  16. import('rt.ojs.JournalRT');
  17. import('article.ArticleHandler');
  18. class RTHandler extends ArticleHandler {
  19. /**
  20. * Display an author biography
  21. */
  22. function bio($args) {
  23. $articleId = isset($args[0]) ? $args[0] : 0;
  24. $galleyId = isset($args[1]) ? (int) $args[1] : 0;
  25. list($journal, $issue, $article) = RTHandler::validate($articleId, $galleyId);
  26. $rtDao = &DAORegistry::getDAO('RTDAO');
  27. $journalRt = &$rtDao->getJournalRTByJournal($journal);
  28. if (!$journalRt || !$journalRt->getAuthorBio()) {
  29. Request::redirect(null, Request::getRequestedPage());
  30. }
  31. $templateMgr = &TemplateManager::getManager();
  32. $templateMgr->assign('articleId', $articleId);
  33. $templateMgr->assign_by_ref('article', $article);
  34. $templateMgr->assign('galleyId', $galleyId);
  35. $templateMgr->display('rt/bio.tpl');
  36. }
  37. /**
  38. * Display the article metadata
  39. */
  40. function metadata($args) {
  41. $articleId = isset($args[0]) ? $args[0] : 0;
  42. $galleyId = isset($args[1]) ? (int) $args[1] : 0;
  43. list($journal, $issue, $article) = RTHandler::validate($articleId, $galleyId);
  44. $rtDao = &DAORegistry::getDAO('RTDAO');
  45. $journalRt = &$rtDao->getJournalRTByJournal($journal);
  46. if (!$journalRt || !$journalRt->getViewMetadata()) {
  47. Request::redirect(null, Request::getRequestedPage());
  48. }
  49. $sectionDao = &DAORegistry::getDAO('SectionDAO');
  50. $section = &$sectionDao->getSection($article->getSectionId());
  51. $templateMgr = &TemplateManager::getManager();
  52. $templateMgr->assign('articleId', $articleId);
  53. $templateMgr->assign('galleyId', $galleyId);
  54. $templateMgr->assign_by_ref('journalRt', $journalRt);
  55. $templateMgr->assign_by_ref('article', $article);
  56. $templateMgr->assign_by_ref('issue', $issue);
  57. $templateMgr->assign_by_ref('section', $section);
  58. $templateMgr->assign_by_ref('journalSettings', $journal->getSettings());
  59. $templateMgr->display('rt/metadata.tpl');
  60. }
  61. /**
  62. * Display an RT search context
  63. */
  64. function context($args) {
  65. $articleId = isset($args[0]) ? $args[0] : 0;
  66. $galleyId = isset($args[1]) ? (int) $args[1] : 0;
  67. $contextId = Isset($args[2]) ? (int) $args[2] : 0;
  68. list($journal, $issue, $article) = RTHandler::validate($articleId, $galleyId);
  69. $rtDao = &DAORegistry::getDAO('RTDAO');
  70. $journalRt = &$rtDao->getJournalRTByJournal($journal);
  71. $context = &$rtDao->getContext($contextId);
  72. if ($context) $version = &$rtDao->getVersion($context->getVersionId(), $journal->getJournalId());
  73. if (!$context || !$version || !$journalRt || $journalRt->getVersion()==null || $journalRt->getVersion() != $context->getVersionId()) {
  74. Request::redirect(null, 'article', 'view', array($articleId, $galleyId));
  75. }
  76. // Deal with the post and URL parameters for each search
  77. // so that the client browser can properly submit the forms
  78. // with a minimum of client-side processing.
  79. $searches = array();
  80. // Some searches use parameters other than the "default" for
  81. // the search (i.e. keywords, author name, etc). If additional
  82. // parameters are used, they should be displayed as part of the
  83. // form for ALL searches in that context.
  84. $searchParams = array();
  85. foreach ($context->getSearches() as $search) {
  86. $params = array();
  87. $searchParams += RTHandler::getParameterNames($search->getSearchUrl());
  88. if ($search->getSearchPost()) {
  89. $searchParams += RTHandler::getParameterNames($search->getSearchPost());
  90. $postParams = explode('&', $search->getSearchPost());
  91. foreach ($postParams as $param) {
  92. // Split name and value from each parameter
  93. $nameValue = explode('=', $param);
  94. if (!isset($nameValue[0])) break;
  95. $name = $nameValue[0];
  96. $value = trim(isset($nameValue[1])?$nameValue[1]:'');
  97. if (!empty($name)) $params[] = array('name' => $name, 'value' => $value);
  98. }
  99. }
  100. $search->postParams = $params;
  101. $searches[] = $search;
  102. }
  103. // Remove duplicate extra form elements and get their values
  104. $searchParams = array_unique($searchParams);
  105. $searchValues = array();
  106. foreach ($searchParams as $key => $param) switch ($param) {
  107. case 'author':
  108. $searchValues[$param] = $article->getAuthorString();
  109. break;
  110. case 'coverageGeo':
  111. $searchValues[$param] = $article->getArticleCoverageGeo();
  112. break;
  113. case 'title':
  114. $searchValues[$param] = $article->getArticleTitle();
  115. break;
  116. default:
  117. // UNKNOWN parameter! Remove it from the list.
  118. unset($searchParams[$key]);
  119. break;
  120. }
  121. $templateMgr = &TemplateManager::getManager();
  122. $templateMgr->assign('articleId', $articleId);
  123. $templateMgr->assign('galleyId', $galleyId);
  124. $templateMgr->assign_by_ref('article', $article);
  125. $templateMgr->assign_by_ref('version', $version);
  126. $templateMgr->assign_by_ref('context', $context);
  127. $templateMgr->assign_by_ref('searches', $searches);
  128. $templateMgr->assign('searchParams', $searchParams);
  129. $templateMgr->assign('searchValues', $searchValues);
  130. $templateMgr->assign('defineTerm', Request::getUserVar('defineTerm'));
  131. $templateMgr->assign('keywords', explode(';', $article->getArticleSubject()));
  132. $templateMgr->assign('coverageGeo', $article->getArticleCoverageGeo());
  133. $templateMgr->assign_by_ref('journalSettings', $journal->getSettings());
  134. $templateMgr->display('rt/context.tpl');
  135. }
  136. /**
  137. * Display citation information
  138. */
  139. function captureCite($args) {
  140. $articleId = isset($args[0]) ? $args[0] : 0;
  141. $galleyId = isset($args[1]) ? (int) $args[1] : 0;
  142. $citeType = isset($args[2]) ? $args[2] : null;
  143. list($journal, $issue, $article) = RTHandler::validate($articleId, $galleyId);
  144. $rtDao = &DAORegistry::getDAO('RTDAO');
  145. $journalRt = &$rtDao->getJournalRTByJournal($journal);
  146. if (!$journalRt || !$journalRt->getCaptureCite()) {
  147. Request::redirect(null, Request::getRequestedPage());
  148. }
  149. $templateMgr = &TemplateManager::getManager();
  150. $templateMgr->assign('articleId', $articleId);
  151. $templateMgr->assign('galleyId', $galleyId);
  152. $templateMgr->assign_by_ref('journalRt', $journalRt);
  153. $templateMgr->assign_by_ref('journal', $journal);
  154. $templateMgr->assign_by_ref('issue', $issue);
  155. $templateMgr->assign_by_ref('article', $article);
  156. $templateMgr->assign_by_ref('journalSettings', $journal->getSettings());
  157. $citationPlugins =& PluginRegistry::loadCategory('citationFormats');
  158. uasort($citationPlugins, create_function('$a, $b', 'return strcmp($a->getDisplayName(), $b->getDisplayName());'));
  159. $templateMgr->assign_by_ref('citationPlugins', $citationPlugins);
  160. if (isset($citationPlugins[$citeType])) {
  161. // A citation type has been selected; display citation.
  162. $citationPlugin =& $citationPlugins[$citeType];
  163. } else {
  164. // No citation type chosen; choose a default off the top of the list.
  165. $citationPlugin = $citationPlugins[array_shift(array_keys($citationPlugins))];
  166. }
  167. $citationPlugin->cite($article, $issue);
  168. }
  169. /**
  170. * Display a printer-friendly version of the article
  171. */
  172. function printerFriendly($args) {
  173. $articleId = isset($args[0]) ? $args[0] : 0;
  174. $galleyId = isset($args[1]) ? (int) $args[1] : 0;
  175. list($journal, $issue, $article) = RTHandler::validate($articleId, $galleyId);
  176. $rtDao = &DAORegistry::getDAO('RTDAO');
  177. $journalRt = &$rtDao->getJournalRTByJournal($journal);
  178. if (!$journalRt || !$journalRt->getPrinterFriendly()) {
  179. Request::redirect(null, Request::getRequestedPage());
  180. }
  181. $articleGalleyDao = &DAORegistry::getDAO('ArticleGalleyDAO');
  182. $galley = &$articleGalleyDao->getGalley($galleyId, $article->getArticleId());
  183. $sectionDao = &DAORegistry::getDAO('SectionDAO');
  184. $section = &$sectionDao->getSection($article->getSectionId());
  185. $templateMgr = &TemplateManager::getManager();
  186. $templateMgr->assign_by_ref('galley', $galley);
  187. $templateMgr->assign_by_ref('article', $article);
  188. $templateMgr->assign_by_ref('section', $section);
  189. $templateMgr->assign_by_ref('issue', $issue);
  190. $templateMgr->assign_by_ref('journal', $journal);
  191. $templateMgr->assign('articleId', $articleId);
  192. $templateMgr->assign('galleyId', $galleyId);
  193. // Use the article's CSS file, if set.
  194. if ($galley && $galley->isHTMLGalley() && $styleFile =& $galley->getStyleFile()) {
  195. $templateMgr->addStyleSheet(Request::url(null, 'article', 'viewFile', array(
  196. $article->getArticleId(),
  197. $galley->getBestGalleyId($journal),
  198. $styleFile->getFileId()
  199. )));
  200. }
  201. $templateMgr->display('rt/printerFriendly.tpl');
  202. }
  203. /**
  204. * Display the "Email Colleague" form
  205. */
  206. function emailColleague($args) {
  207. $articleId = isset($args[0]) ? $args[0] : 0;
  208. $galleyId = isset($args[1]) ? (int) $args[1] : 0;
  209. list($journal, $issue, $article) = RTHandler::validate($articleId, $galleyId);
  210. $rtDao = &DAORegistry::getDAO('RTDAO');
  211. $journalRt = &$rtDao->getJournalRTByJournal($journal);
  212. $user = &Request::getUser();
  213. if (!$journalRt || !$journalRt->getEmailOthers() || !$user) {
  214. Request::redirect(null, Request::getRequestedPage());
  215. }
  216. import('mail.MailTemplate');
  217. $email = &new MailTemplate('EMAIL_LINK');
  218. if (Request::getUserVar('send') && !$email->hasErrors()) {
  219. $email->send();
  220. $templateMgr = &TemplateManager::getManager();
  221. $templateMgr->display('rt/sent.tpl');
  222. } else {
  223. if (!Request::getUserVar('continued')) {
  224. $primaryAuthor = $article->getAuthors();
  225. $primaryAuthor = $primaryAuthor[0];
  226. $email->setSubject('[' . $journal->getLocalizedSetting('initials') . '] ' . strip_tags($article->getArticleTitle()));
  227. $email->assignParams(array(
  228. 'articleTitle' => strip_tags($article->getArticleTitle()),
  229. 'volume' => $issue?$issue->getVolume():null,
  230. 'number' => $issue?$issue->getNumber():null,
  231. 'year' => $issue?$issue->getYear():null,
  232. 'authorName' => $primaryAuthor->getFullName(),
  233. 'articleUrl' => Request::url(null, 'article', 'view', $article->getBestArticleId())
  234. ));
  235. }
  236. $email->displayEditForm(Request::url(null, null, 'emailColleague', array($articleId, $galleyId)), null, 'rt/email.tpl', array('op' => 'emailColleague'));
  237. }
  238. }
  239. /**
  240. * Display the "email author" form
  241. */
  242. function emailAuthor($args) {
  243. $articleId = isset($args[0]) ? $args[0] : 0;
  244. $galleyId = isset($args[1]) ? (int) $args[1] : 0;
  245. list($journal, $issue, $article) = RTHandler::validate($articleId, $galleyId);
  246. $rtDao = &DAORegistry::getDAO('RTDAO');
  247. $journalRt = &$rtDao->getJournalRTByJournal($journal);
  248. $user = &Request::getUser();
  249. if (!$journalRt || !$journalRt->getEmailAuthor() || !$user) {
  250. Request::redirect(null, Request::getRequestedPage());
  251. }
  252. import('mail.MailTemplate');
  253. $email = &new MailTemplate();
  254. $email->setAddressFieldsEnabled(false);
  255. if (Request::getUserVar('send') && !$email->hasErrors()) {
  256. $authors = &$article->getAuthors();
  257. $author = &$authors[0];
  258. $email->addRecipient($author->getEmail(), $author->getFullName());
  259. $email->send();
  260. $templateMgr = &TemplateManager::getManager();
  261. $templateMgr->display('rt/sent.tpl');
  262. } else {
  263. if (!Request::getUserVar('continued')) {
  264. $email->setSubject('[' . $journal->getLocalizedSetting('initials') . '] ' . strip_tags($article->getArticleTitle()));
  265. }
  266. $email->displayEditForm(Request::url(null, null, 'emailAuthor', array($articleId, $galleyId)), null, 'rt/email.tpl', array('op' => 'emailAuthor'));
  267. }
  268. }
  269. /**
  270. * Display a list of supplementary files
  271. */
  272. function suppFiles($args) {
  273. $articleId = isset($args[0]) ? $args[0] : 0;
  274. $galleyId = isset($args[1]) ? (int) $args[1] : 0;
  275. list($journal, $issue, $article) = RTHandler::validate($articleId, $galleyId);
  276. $rtDao = &DAORegistry::getDAO('RTDAO');
  277. $journalRt = &$rtDao->getJournalRTByJournal($journal);
  278. if (!$journalRt || !$journalRt->getSupplementaryFiles()) {
  279. Request::redirect(null, Request::getRequestedPage());
  280. }
  281. $templateMgr = &TemplateManager::getManager();
  282. $templateMgr->assign('articleId', $articleId);
  283. $templateMgr->assign('galleyId', $galleyId);
  284. $templateMgr->assign_by_ref('journalRt', $journalRt);
  285. $templateMgr->assign_by_ref('article', $article);
  286. $templateMgr->assign_by_ref('journalSettings', $journal->getSettings());
  287. $templateMgr->display('rt/suppFiles.tpl');
  288. }
  289. /**
  290. * Display the metadata of a supplementary file
  291. */
  292. function suppFileMetadata($args) {
  293. $articleId = isset($args[0]) ? $args[0] : 0;
  294. $galleyId = isset($args[1]) ? (int) $args[1] : 0;
  295. $suppFileId = isset($args[2]) ? (int) $args[2] : 0;
  296. list($journal, $issue, $article) = RTHandler::validate($articleId, $galleyId);
  297. $rtDao = &DAORegistry::getDAO('RTDAO');
  298. $journalRt = &$rtDao->getJournalRTByJournal($journal);
  299. $suppFileDao = &DAORegistry::getDAO('SuppFileDAO');
  300. $suppFile = $suppFileDao->getSuppFile($suppFileId, $article->getArticleId());
  301. if (!$journalRt || !$journalRt->getSupplementaryFiles() || !$suppFile) {
  302. Request::redirect(null, Request::getRequestedPage());
  303. }
  304. $templateMgr = &TemplateManager::getManager();
  305. $templateMgr->assign('articleId', $articleId);
  306. $templateMgr->assign('galleyId', $galleyId);
  307. $templateMgr->assign_by_ref('suppFile', $suppFile);
  308. $templateMgr->assign_by_ref('journalRt', $journalRt);
  309. $templateMgr->assign_by_ref('article', $article);
  310. $templateMgr->assign_by_ref('journalSettings', $journal->getSettings());
  311. $templateMgr->display('rt/suppFileView.tpl');
  312. }
  313. /**
  314. * Display the "finding references" search engine list
  315. */
  316. function findingReferences($args) {
  317. $articleId = isset($args[0]) ? $args[0] : 0;
  318. $galleyId = isset($args[1]) ? (int) $args[1] : 0;
  319. list($journal, $issue, $article) = RTHandler::validate($articleId, $galleyId);
  320. $rtDao = &DAORegistry::getDAO('RTDAO');
  321. $journalRt = &$rtDao->getJournalRTByJournal($journal);
  322. if (!$journalRt || !$journalRt->getFindingReferences()) {
  323. Request::redirect(null, Request::getRequestedPage());
  324. }
  325. $templateMgr = &TemplateManager::getManager();
  326. $templateMgr->assign('articleId', $articleId);
  327. $templateMgr->assign('galleyId', $galleyId);
  328. $templateMgr->assign_by_ref('journalRt', $journalRt);
  329. $templateMgr->assign_by_ref('article', $article);
  330. $templateMgr->display('rt/findingReferences.tpl');
  331. }
  332. /**
  333. * Get parameter values: Used internally for RT searches
  334. */
  335. function getParameterNames($value) {
  336. $matches = null;
  337. String::regexp_match_all('/\{\$([a-zA-Z0-9]+)\}/', $value, $matches);
  338. // Remove the entire string from the matches list
  339. return $matches[1];
  340. }
  341. }
  342. ?>