tripal_pub.module 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464
  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/citation'] = array(
  102. 'title' => 'Citations',
  103. 'description' => 'Update publication citations',
  104. 'page callback' => 'drupal_get_form',
  105. 'page arguments' => array('tripal_pub_citation_form'),
  106. 'access arguments' => array('administer tripal pub'),
  107. 'type' => MENU_LOCAL_TASK,
  108. 'weight' => 1
  109. );
  110. $items['admin/tripal/chado/tripal_pub/import_list'] = array(
  111. 'title' => t('Publication Importers'),
  112. 'description' => t('Create and modify importers that can connect to and retreive publications from remote databases.'),
  113. 'page callback' => 'tripal_pub_importers_list',
  114. 'access arguments' => array('administer tripal pub'),
  115. 'type' => MENU_LOCAL_TASK,
  116. 'weight' => 0
  117. );
  118. // add a second link for the importer on the data loaders page
  119. $items['admin/tripal/loaders/pub_import'] = array(
  120. 'title' => t('Publication Importers'),
  121. 'description' => t('Create and modify importers that can connect to and retreive publications from remote databases.'),
  122. 'page callback' => 'tripal_pub_importers_list',
  123. 'access arguments' => array('administer tripal pub'),
  124. 'type' => MENU_NORMAL_ITEM,
  125. );
  126. $items['admin/tripal/chado/tripal_pub/import/new'] = array(
  127. 'title' => t('Add an Importer'),
  128. 'description' => t('Add a new publication importer.'),
  129. 'page callback' => 'tripal_pub_importer_setup_page',
  130. 'access arguments' => array('administer tripal pub'),
  131. 'type ' => MENU_CALLBACK,
  132. );
  133. $items['admin/tripal/chado/tripal_pub/import/raw/%'] = array(
  134. 'title' => t('Raw Data From Publication Import'),
  135. 'page callback' => 'tripal_get_remote_pub_raw_page',
  136. 'page arguments' => array(6),
  137. 'access arguments' => array('administer tripal pub'),
  138. 'type ' => MENU_CALLBACK,
  139. );
  140. $items['admin/tripal/chado/tripal_pub/import/edit/%'] = array(
  141. 'page callback' => 'tripal_pub_importer_setup_page',
  142. 'page arguments' => array(5, 6),
  143. 'access arguments' => array('administer tripal pub'),
  144. 'type ' => MENU_CALLBACK,
  145. );
  146. $items['admin/tripal/chado/tripal_pub/import/submit/%'] = array(
  147. 'page callback' => 'tripal_pub_importer_submit_job',
  148. 'page arguments' => array(6),
  149. 'access arguments' => array('administer tripal pub'),
  150. 'type ' => MENU_CALLBACK,
  151. );
  152. $items['admin/tripal/chado/tripal_pub/import/delete/%'] = array(
  153. 'page callback' => 'tripal_pub_importer_delete',
  154. 'page arguments' => array(5),
  155. 'access arguments' => array('administer tripal pub'),
  156. 'type ' => MENU_CALLBACK,
  157. );
  158. $items['admin/tripal/chado/tripal_pub/import/changedb'] = array(
  159. 'page callback' => 'tripal_pub_importer_setup_page_update_remotedb',
  160. 'page arguments' => array(),
  161. 'access arguments' => array('administer tripal pub'),
  162. 'type ' => MENU_CALLBACK,
  163. );
  164. $items['admin/tripal/chado/tripal_pub/import/criteria/%/%'] = array(
  165. 'page callback' => 'tripal_pub_importer_setup_page_update_criteria',
  166. 'page arguments' => array(5, 6),
  167. 'access arguments' => array('administer tripal pub'),
  168. 'type ' => MENU_CALLBACK,
  169. );
  170. return $items;
  171. }
  172. /**
  173. * Implements hook_theme().
  174. * Register themeing functions for this module
  175. *
  176. * @return
  177. * An array of themeing functions to register
  178. *
  179. * @ingroup tripal_pub
  180. */
  181. function tripal_pub_theme($existing, $type, $theme, $path) {
  182. $core_path = drupal_get_path('module', 'tripal_core');
  183. $items = array(
  184. 'node__chado_pub' => array(
  185. 'template' => 'node--chado-generic',
  186. 'render element' => 'node',
  187. 'base hook' => 'node',
  188. 'path' => "$core_path/theme/templates",
  189. ),
  190. // node templates
  191. 'tripal_pub_authors' => array(
  192. 'arguments' => array('node' => NULL),
  193. 'template' => 'tripal_pub_authors',
  194. 'path' => "$path/theme/templates",
  195. ),
  196. 'tripal_pub_base' => array(
  197. 'arguments' => array('node' => NULL),
  198. 'template' => 'tripal_pub_base',
  199. 'path' => "$path/theme/templates",
  200. ),
  201. 'tripal_pub_featuremaps' => array(
  202. 'arguments' => array('node' => NULL),
  203. 'template' => 'tripal_pub_featuremaps',
  204. 'path' => "$path/theme/templates",
  205. ),
  206. 'tripal_pub_features' => array(
  207. 'arguments' => array('node' => NULL),
  208. 'template' => 'tripal_pub_features',
  209. 'path' => "$path/theme/templates",
  210. ),
  211. 'tripal_pub_libraries' => array(
  212. 'arguments' => array('node' => NULL),
  213. 'template' => 'tripal_pub_libraries',
  214. 'path' => "$path/theme/templates",
  215. ),
  216. 'tripal_pub_projects' => array(
  217. 'arguments' => array('node' => NULL),
  218. 'template' => 'tripal_pub_projects',
  219. 'path' => "$path/theme/templates",
  220. ),
  221. 'tripal_pub_properties' => array(
  222. 'arguments' => array('node' => NULL),
  223. 'template' => 'tripal_pub_properties',
  224. 'path' => "$path/theme/templates",
  225. ),
  226. 'tripal_pub_references' => array(
  227. 'arguments' => array('node' => NULL),
  228. 'template' => 'tripal_pub_references',
  229. 'path' => "$path/theme/templates",
  230. ),
  231. 'tripal_pub_relationships' => array(
  232. 'arguments' => array('node' => NULL),
  233. 'template' => 'tripal_pub_relationships',
  234. 'path' => "$path/theme/templates",
  235. ),
  236. 'tripal_pub_stocks' => array(
  237. 'arguments' => array('node' => NULL),
  238. 'template' => 'tripal_pub_stocks',
  239. 'path' => "$path/theme/templates",
  240. ),
  241. // instructions page for the pub module
  242. 'tripal_pub_help' => array(
  243. 'template' => 'tripal_pub_help',
  244. 'arguments' => array(NULL),
  245. 'path' => "$path/theme/templates",
  246. ),
  247. // themed forms
  248. 'tripal_pub_importer_setup_form_elements' => array(
  249. 'render element' => 'form',
  250. ),
  251. 'tripal_pub_search_setup_form_elements' => array(
  252. 'render element' => 'form',
  253. ),
  254. // teaser
  255. 'tripal_pub_teaser' => array(
  256. 'variables' => array('node' => NULL),
  257. 'template' => 'tripal_pub_teaser',
  258. 'path' => "$path/theme/templates",
  259. ),
  260. );
  261. return $items;
  262. }
  263. /**
  264. * Implements hook_help().
  265. * Adds a help page to the module list
  266. *
  267. * @ingroup tripal_pub
  268. */
  269. function tripal_pub_help ($path, $arg) {
  270. if ($path == 'admin/help#tripal_pub') {
  271. return theme('tripal_pub_help', array());
  272. }
  273. }
  274. /**
  275. * Implements hook_views_api().
  276. *
  277. * Essentially this hook tells drupal that there is views support for
  278. * for this module which then includes tripal_db.views.inc where all the
  279. * views integration code is
  280. *
  281. * @ingroup tripal_pub
  282. */
  283. function tripal_pub_views_api() {
  284. return array(
  285. 'api' => 3.0,
  286. );
  287. }
  288. /**
  289. * Implement hook_permission().
  290. *
  291. * @ingroup tripal_pub
  292. */
  293. function tripal_pub_permission() {
  294. return array(
  295. 'access chado_pub content' => array(
  296. 'title' => t('View Publications'),
  297. 'description' => t('Allow users to view publication pages.'),
  298. ),
  299. 'create chado_pub content' => array(
  300. 'title' => t('Create Publication'),
  301. 'description' => t('Allow users to create new publication pages.'),
  302. ),
  303. 'delete chado_pub content' => array(
  304. 'title' => t('Delete Publication'),
  305. 'description' => t('Allow users to delete publication pages.'),
  306. ),
  307. 'edit chado_pub content' => array(
  308. 'title' => t('Edit Publications'),
  309. 'description' => t('Allow users to edit publication pages.'),
  310. ),
  311. 'administer tripal pub' => array(
  312. 'title' => t('Administer Publications'),
  313. 'description' => t('Allow users to administer all publications.'),
  314. ),
  315. );
  316. }
  317. /**
  318. * Implements hook_mail().
  319. *
  320. * @ingroup tripal_pub
  321. */
  322. function tripal_pub_mail($key, &$message, $params) {
  323. $language = $message['language'];
  324. $variables = user_mail_tokens($params['account'], $language);
  325. switch($key) {
  326. case 'import_report':
  327. $headers = array(
  328. 'MIME-Version' => '1.0',
  329. 'Content-Type' => 'text/html; charset=UTF-8; format=flowed',
  330. 'Content-Transfer-Encoding' => '8Bit',
  331. 'X-Mailer' => 'Drupal'
  332. );
  333. foreach ($headers as $key => $value) {
  334. $message['headers'][$key] = $value;
  335. }
  336. $message['subject'] = t('Publication import from !site', $variables, $language->language);
  337. $message['body'][] = $params['message'];
  338. break;
  339. }
  340. }
  341. /**
  342. * Implementation of hook_form_alter().
  343. *
  344. * @param $form
  345. * @param $form_state
  346. * @param $form_id
  347. *
  348. * @ingroup tripal_pub
  349. */
  350. function tripal_pub_form_alter(&$form, &$form_state, $form_id) {
  351. // turn of preview button for insert/updates
  352. if ($form_id == "chado_pub_node_form") {
  353. // turn of preview button for insert/updates
  354. $form['actions']['preview']['#access'] = FALSE;
  355. //remove the body field
  356. unset($form['body']);
  357. }
  358. if ($form_id == "tripal_pub_importer_setup_form") {
  359. /* // updating the form through the ahah callback sets the action of
  360. // the form to the ahah callback URL. We need to set it back
  361. // to the normal form URL
  362. if (array_key_exists('values', $form_state) and $form_state['values']['action'] == 'edit') {
  363. $form['#action'] = url("admin/tripal/chado/tripal_pub/import/edit/" . $form_state['values']['pub_import_id']);
  364. }
  365. if (array_key_exists('values', $form_state) and $form_state['values']['action'] == 'new') {
  366. $form['#action'] = url("admin/tripal/chado/tripal_pub/import/new");
  367. }
  368. */
  369. }
  370. if ($form_id == "tripal_pub_search_form") {
  371. $form['#action'] = url("find/publications");
  372. }
  373. if ($form_id == "chado_pub_node_form") {
  374. }
  375. }
  376. /**
  377. * Implements hook_job_describe_args().
  378. *
  379. * @param $callback
  380. * @param $args
  381. *
  382. * @ingroup tripal_pub
  383. */
  384. function tripal_pub_job_describe_args($callback, $args) {
  385. $new_args = array();
  386. if ($callback == 'tripal_execute_pub_importer') {
  387. // get all of the loaders
  388. $qargs = array(':import_id' => $args[0]);
  389. $sql = "SELECT * FROM {tripal_pub_import} WHERE pub_import_id = :import_id ";
  390. $import = db_query($sql, $qargs)->fetchObject();
  391. $new_args['Importer'] = $import->name;
  392. }
  393. return $new_args;
  394. }
  395. /**
  396. * A simple wrapper function to put <pre> tags around the raw results
  397. * returned by the
  398. * @param unknown $dbxref
  399. * @return string
  400. */
  401. function tripal_get_remote_pub_raw_page($dbxref) {
  402. $pub = tripal_get_remote_pub($dbxref);
  403. if ($pub) {
  404. $page = "<strong>Raw results for $dbxref:</strong><br><br>";
  405. $page.= '<textarea cols=80 rows=20>' . $pub['raw'] . '</textarea>';
  406. return $page;
  407. }
  408. return "Cound not find the requested publication ($dbxref)";
  409. }
  410. /**
  411. *
  412. */
  413. function tripal_pub_search_biological_data_views() {
  414. return array(
  415. 'publications' => array(
  416. 'machine_name' => 'publications',
  417. 'human_name' => 'Publications',
  418. 'description' => 'Publications such as journal articles, conference proceedings, or other media.',
  419. 'link' => 'find/publications'
  420. ),
  421. );
  422. }