tripal_pub.module 12 KB

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