tripal_pub.module

  1. 2.x tripal_pub/tripal_pub.module
  2. 3.x legacy/tripal_pub/tripal_pub.module
  3. 1.x tripal_pub/tripal_pub.module

Basic functionality of the pub module

File

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