tripal_pub.module 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399
  1. <?php
  2. /**
  3. * @file
  4. * Basic functionality of the pub module
  5. */
  6. require_once 'api/tripal_pub.api.inc';
  7. require_once 'api/tripal_pub.DEPRECATED.inc';
  8. require_once 'theme/tripal_pub.theme.inc';
  9. require_once 'includes/tripal_pub.admin.inc';
  10. require_once 'includes/tripal_pub.chado_node.inc';
  11. require_once 'includes/tripal_pub.pub_search.inc';
  12. require_once 'includes/tripal_pub.pub_citation.inc';
  13. /**
  14. * @defgroup tripal_pub Publication Module
  15. * @ingroup tripal_modules
  16. * @{
  17. * Integrates the Chado Publication module with Drupal Nodes & Views, as well as, provides
  18. * the ability to import publication from PubMed
  19. *
  20. * The Tripal Publication module allows you to search the PubMed database for academic articles,
  21. * that relate to user specified topic\s. As well, it allows management of publications so that
  22. * a user can enter specified details regarding a desired publication. This allows all of the important
  23. * information that is unique to a Academic Publication to be stored for access.
  24. * @}
  25. */
  26. /**
  27. * Implements hook_menu().
  28. *
  29. * Adds menu items for the tripal_pub module menu. This section
  30. * gives the outline for the main menu of the Tripal-Publication module
  31. *
  32. * @return
  33. * An array of menu items that is visible within the Drupal Menu, returned as soon
  34. * as the program is ran
  35. *
  36. * @ingroup tripal_pub
  37. */
  38. function tripal_pub_menu() {
  39. $items = array();
  40. // because the publication search is not views we need to manually add
  41. // it to the Search Data list in the navigation menu
  42. $items['chado/publication' ]= array(
  43. 'title' => 'Publications',
  44. 'description' => ('Publications such as journal articles, conference proceedings, or other media.'),
  45. 'page callback' => 'tripal_pub_search_page',
  46. 'access arguments' => array('access chado_pub content'),
  47. 'type' => MENU_NORMAL_ITEM
  48. );
  49. // for backwards compatibility the same chado/publications is also found
  50. // at find/publications
  51. $items['find/publications' ]= array(
  52. 'title' => 'Publication Search',
  53. 'description' => ('Search for publications'),
  54. 'page callback' => 'tripal_pub_search_page',
  55. 'access arguments' => array('access chado_pub content'),
  56. 'type' => MENU_CALLBACK
  57. );
  58. $items['find/publications/criteria/%/%'] = array(
  59. 'page callback' => 'tripal_pub_search_page_update_criteria',
  60. 'page arguments' => array(5, 6),
  61. 'access arguments' => array('access chado_pub content'),
  62. 'type ' => MENU_CALLBACK,
  63. );
  64. $items['admin/tripal/chado/tripal_pub']= array(
  65. 'title' => 'Publications',
  66. 'description' => ('A documented provenance artefact - publications, documents, personal communication.'),
  67. 'page callback' => 'tripal_pub_admin_pub_view',
  68. 'access arguments' => array('administer tripal pub'),
  69. 'type' => MENU_NORMAL_ITEM
  70. );
  71. $items['admin/tripal/chado/tripal_pub/help']= array(
  72. 'title' => 'Help',
  73. 'description' => ('A module for interfacing the GMOD chado database with Drupal, providing viewing of publications'),
  74. 'page callback' => 'theme',
  75. 'page arguments' => array('tripal_pub_help'),
  76. 'access arguments' => array('administer tripal pub'),
  77. 'type' => MENU_LOCAL_TASK,
  78. 'weight' => 10
  79. );
  80. $items['admin/tripal/chado/tripal_pub/configuration'] = array(
  81. 'title' => 'Settings',
  82. 'description' => 'Configure the Tripal publication module.',
  83. 'page callback' => 'drupal_get_form',
  84. 'page arguments' => array('tripal_pub_admin'),
  85. 'access arguments' => array('administer tripal pub'),
  86. 'type' => MENU_LOCAL_TASK,
  87. 'weight' => 5
  88. );
  89. $items['admin/tripal/chado/tripal_pub/sync'] = array(
  90. 'title' => ' Sync',
  91. 'description' => 'Create pages on this site for libraries stored in Chado',
  92. 'page callback' => 'drupal_get_form',
  93. 'page arguments' => array('chado_node_sync_form', 'tripal_pub', 'chado_pub'),
  94. 'access arguments' => array('administer tripal pub'),
  95. 'type' => MENU_LOCAL_TASK,
  96. 'weight' => 2
  97. );
  98. $items['admin/tripal/chado/tripal_pub/chado_pub_toc'] = array(
  99. 'title' => ' TOC',
  100. 'description' => 'Manage the table of contents for pub nodes.',
  101. 'page callback' => 'drupal_get_form',
  102. 'page arguments' => array('tripal_core_content_type_toc_form', 'chado_pub'),
  103. 'access arguments' => array('administer tripal pub'),
  104. 'type' => MENU_LOCAL_TASK,
  105. 'file' => 'includes/tripal_core.toc.inc',
  106. 'file path' => drupal_get_path('module', 'tripal_core'),
  107. 'weight' => 3
  108. );
  109. $items['admin/tripal/chado/tripal_pub/citation'] = array(
  110. 'title' => 'Citations',
  111. 'description' => 'Update publication citations',
  112. 'page callback' => 'drupal_get_form',
  113. 'page arguments' => array('tripal_pub_citation_form'),
  114. 'access arguments' => array('administer tripal pub'),
  115. 'type' => MENU_LOCAL_TASK,
  116. 'weight' => 1
  117. );
  118. return $items;
  119. }
  120. /**
  121. * Implements hook_theme().
  122. * Register themeing functions for this module
  123. *
  124. * @return
  125. * An array of themeing functions to register
  126. *
  127. * @ingroup tripal_pub
  128. */
  129. function tripal_pub_theme($existing, $type, $theme, $path) {
  130. $core_path = drupal_get_path('module', 'tripal_core');
  131. $items = array(
  132. 'node__chado_pub' => array(
  133. 'template' => 'node--chado-generic',
  134. 'render element' => 'node',
  135. 'base hook' => 'node',
  136. 'path' => "$core_path/theme/templates",
  137. ),
  138. // node templates
  139. 'tripal_pub_authors' => array(
  140. 'variables' => array('node' => NULL),
  141. 'template' => 'tripal_pub_authors',
  142. 'path' => "$path/theme/templates",
  143. ),
  144. 'tripal_pub_base' => array(
  145. 'variables' => array('node' => NULL),
  146. 'template' => 'tripal_pub_base',
  147. 'path' => "$path/theme/templates",
  148. ),
  149. 'tripal_pub_featuremaps' => array(
  150. 'variables' => array('node' => NULL),
  151. 'template' => 'tripal_pub_featuremaps',
  152. 'path' => "$path/theme/templates",
  153. ),
  154. 'tripal_pub_features' => array(
  155. 'variables' => array('node' => NULL),
  156. 'template' => 'tripal_pub_features',
  157. 'path' => "$path/theme/templates",
  158. ),
  159. 'tripal_pub_libraries' => array(
  160. 'variables' => array('node' => NULL),
  161. 'template' => 'tripal_pub_libraries',
  162. 'path' => "$path/theme/templates",
  163. ),
  164. 'tripal_pub_projects' => array(
  165. 'variables' => array('node' => NULL),
  166. 'template' => 'tripal_pub_projects',
  167. 'path' => "$path/theme/templates",
  168. ),
  169. 'tripal_pub_properties' => array(
  170. 'variables' => array('node' => NULL),
  171. 'template' => 'tripal_pub_properties',
  172. 'path' => "$path/theme/templates",
  173. ),
  174. 'tripal_pub_references' => array(
  175. 'variables' => array('node' => NULL),
  176. 'template' => 'tripal_pub_references',
  177. 'path' => "$path/theme/templates",
  178. ),
  179. 'tripal_pub_relationships' => array(
  180. 'variables' => array('node' => NULL),
  181. 'template' => 'tripal_pub_relationships',
  182. 'path' => "$path/theme/templates",
  183. ),
  184. 'tripal_pub_stocks' => array(
  185. 'variables' => array('node' => NULL),
  186. 'template' => 'tripal_pub_stocks',
  187. 'path' => "$path/theme/templates",
  188. ),
  189. // instructions page for the pub module
  190. 'tripal_pub_help' => array(
  191. 'variables' => array(NULL),
  192. 'template' => 'tripal_pub_help',
  193. 'path' => "$path/theme/templates",
  194. ),
  195. // teaser
  196. 'tripal_pub_teaser' => array(
  197. 'variables' => array('node' => NULL),
  198. 'template' => 'tripal_pub_teaser',
  199. 'path' => "$path/theme/templates",
  200. ),
  201. );
  202. return $items;
  203. }
  204. /**
  205. * Implements hook_help().
  206. * Adds a help page to the module list
  207. *
  208. * @ingroup tripal_pub
  209. */
  210. function tripal_pub_help ($path, $arg) {
  211. if ($path == 'admin/help#tripal_pub') {
  212. return theme('tripal_pub_help', array());
  213. }
  214. }
  215. /**
  216. * Implements hook_views_api().
  217. *
  218. * Essentially this hook tells drupal that there is views support for
  219. * for this module which then includes tripal_db.views.inc where all the
  220. * views integration code is
  221. *
  222. * @ingroup tripal_pub
  223. */
  224. function tripal_pub_views_api() {
  225. return array(
  226. 'api' => 3.0,
  227. );
  228. }
  229. /**
  230. * Implement hook_permission().
  231. *
  232. * @ingroup tripal_pub
  233. */
  234. function tripal_pub_permission() {
  235. return array(
  236. 'access chado_pub content' => array(
  237. 'title' => t('View Publications'),
  238. 'description' => t('Allow users to view publication pages.'),
  239. ),
  240. 'create chado_pub content' => array(
  241. 'title' => t('Create Publication'),
  242. 'description' => t('Allow users to create new publication pages.'),
  243. ),
  244. 'delete chado_pub content' => array(
  245. 'title' => t('Delete Publication'),
  246. 'description' => t('Allow users to delete publication pages.'),
  247. ),
  248. 'edit chado_pub content' => array(
  249. 'title' => t('Edit Publications'),
  250. 'description' => t('Allow users to edit publication pages.'),
  251. ),
  252. 'administer tripal pub' => array(
  253. 'title' => t('Administer Publications'),
  254. 'description' => t('Allow users to administer all publications.'),
  255. ),
  256. );
  257. }
  258. /**
  259. * Implements hook_mail().
  260. *
  261. * @ingroup tripal_pub
  262. */
  263. function tripal_pub_mail($key, &$message, $params) {
  264. $language = $message['language'];
  265. $variables = user_mail_tokens($params['account'], $language);
  266. switch($key) {
  267. case 'import_report':
  268. $headers = array(
  269. 'MIME-Version' => '1.0',
  270. 'Content-Type' => 'text/html; charset=UTF-8; format=flowed',
  271. 'Content-Transfer-Encoding' => '8Bit',
  272. 'X-Mailer' => 'Drupal'
  273. );
  274. foreach ($headers as $key => $value) {
  275. $message['headers'][$key] = $value;
  276. }
  277. $message['subject'] = t('Publication import from !site', $variables, $language->language);
  278. $message['body'][] = $params['message'];
  279. break;
  280. }
  281. }
  282. /**
  283. * Implementation of hook_form_alter().
  284. *
  285. * @param $form
  286. * @param $form_state
  287. * @param $form_id
  288. *
  289. * @ingroup tripal_pub
  290. */
  291. function tripal_pub_form_alter(&$form, &$form_state, $form_id) {
  292. // turn of preview button for insert/updates
  293. if ($form_id == "chado_pub_node_form") {
  294. // turn of preview button for insert/updates
  295. $form['actions']['preview']['#access'] = FALSE;
  296. //remove the body field
  297. unset($form['body']);
  298. }
  299. if ($form_id == "tripal_pub_importer_setup_form") {
  300. /* // updating the form through the ahah callback sets the action of
  301. // the form to the ahah callback URL. We need to set it back
  302. // to the normal form URL
  303. if (array_key_exists('values', $form_state) and $form_state['values']['action'] == 'edit') {
  304. $form['#action'] = url("admin/tripal/chado/tripal_pub/import/edit/" . $form_state['values']['pub_import_id']);
  305. }
  306. if (array_key_exists('values', $form_state) and $form_state['values']['action'] == 'new') {
  307. $form['#action'] = url("admin/tripal/chado/tripal_pub/import/new");
  308. }
  309. */
  310. }
  311. if ($form_id == "tripal_pub_search_form") {
  312. $form['#action'] = url("find/publications");
  313. }
  314. if ($form_id == "chado_pub_node_form") {
  315. }
  316. }
  317. /**
  318. * Implements hook_job_describe_args().
  319. *
  320. * @param $callback
  321. * @param $args
  322. *
  323. * @ingroup tripal_pub
  324. */
  325. function tripal_pub_job_describe_args($callback, $args) {
  326. $new_args = array();
  327. if ($callback == 'tripal_execute_pub_importer') {
  328. // get all of the loaders
  329. $qargs = array(':import_id' => $args[0]);
  330. $sql = "SELECT * FROM {tripal_pub_import} WHERE pub_import_id = :import_id ";
  331. $import = db_query($sql, $qargs)->fetchObject();
  332. $new_args['Importer'] = $import->name;
  333. }
  334. return $new_args;
  335. }
  336. /**
  337. * A simple wrapper function to put <pre> tags around the raw results
  338. * returned by the
  339. * @param unknown $dbxref
  340. * @return string
  341. */
  342. function tripal_get_remote_pub_raw_page($dbxref) {
  343. $pub = tripal_get_remote_pub($dbxref);
  344. if ($pub) {
  345. $page = "<strong>Raw results for $dbxref:</strong><br><br>";
  346. $page.= '<textarea cols=80 rows=20>' . $pub['raw'] . '</textarea>';
  347. return $page;
  348. }
  349. return "Cound not find the requested publication ($dbxref)";
  350. }
  351. /**
  352. *
  353. */
  354. function tripal_pub_search_biological_data_views() {
  355. return array(
  356. 'publications' => array(
  357. 'machine_name' => 'publications',
  358. 'human_name' => 'Publications',
  359. 'description' => 'Publications such as journal articles, conference proceedings, or other media.',
  360. 'link' => 'find/publications'
  361. ),
  362. );
  363. }