tripal_pub.module 14 KB

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