tripal_pub.module 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408
  1. <?php
  2. require_once "api/tripal_pub.api.inc";
  3. require_once "theme/tripal_pub.theme.inc";
  4. require_once "includes/tripal_pub.admin.inc";
  5. require_once "includes/tripal_pub.chado_node.inc";
  6. require_once "includes/tripal_pub.pub_importers.inc";
  7. require_once "includes/tripal_pub.pub_search.inc";
  8. require_once "includes/tripal_pub.pub_citation.inc";
  9. require_once "includes/importers/tripal_pub.PMID.inc";
  10. require_once "includes/importers/tripal_pub.AGL.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. *
  26. * @ingroup tripal_pub
  27. */
  28. function tripal_pub_init() {
  29. }
  30. /**
  31. * Tripal-Publication-Menu
  32. *
  33. * Implements hook_menu(): Adds menu items for the tripal_pub module menu. This section
  34. * gives the outline for the main menu of the Tripal-Publication module
  35. *
  36. * @return
  37. * An array of menu items that is visible within the Drupal Menu, returned as soon
  38. * as the program is ran
  39. */
  40. function tripal_pub_menu() {
  41. $items = array();
  42. $items['find/publications' ]= array(
  43. 'title' => 'Publication Search',
  44. 'description' => ('Search for publications'),
  45. 'page callback' => 'tripal_pub_search_page',
  46. 'access arguments' => array('access chado_pub content'),
  47. 'type' => MENU_CALLBACK
  48. );
  49. $items['find/publications/criteria/%/%'] = array(
  50. 'page callback' => 'tripal_pub_search_page_update_criteria',
  51. 'page arguments' => array(5, 6),
  52. 'access arguments' => array('access chado_pub content'),
  53. 'type ' => MENU_CALLBACK,
  54. );
  55. $items['admin/tripal/chado/tripal_pub']= array(
  56. 'title' => 'Publications',
  57. 'description' => ('A documented provenance artefact - publications, documents, personal communication.'),
  58. 'page callback' => 'tripal_pub_admin_pub_view',
  59. 'access arguments' => array('administer tripal pub'),
  60. 'type' => MENU_NORMAL_ITEM
  61. );
  62. $items['admin/tripal/chado/tripal_pub/help']= array(
  63. 'title' => 'Help',
  64. 'description' => ('A module for interfacing the GMOD chado database with Drupal, providing viewing of publications'),
  65. 'page callback' => 'theme',
  66. 'page arguments' => array('tripal_pub_help'),
  67. 'access arguments' => array('administer tripal pub'),
  68. 'type' => MENU_LOCAL_TASK,
  69. 'weight' => 10
  70. );
  71. $items['admin/tripal/chado/tripal_pub/configuration'] = array(
  72. 'title' => 'Settings',
  73. 'description' => 'Configure the Tripal publication module.',
  74. 'page callback' => 'drupal_get_form',
  75. 'page arguments' => array('tripal_pub_admin'),
  76. 'access arguments' => array('administer tripal pub'),
  77. 'type' => MENU_LOCAL_TASK,
  78. 'weight' => 5
  79. );
  80. $items['admin/tripal/chado/tripal_pub/sync'] = array(
  81. 'title' => ' Sync',
  82. 'description' => 'Create pages on this site for libraries stored in Chado',
  83. 'page callback' => 'drupal_get_form',
  84. 'page arguments' => array('tripal_core_chado_node_sync_form', 'tripal_pub', 'chado_pub'),
  85. 'access arguments' => array('administer tripal pub'),
  86. 'type' => MENU_LOCAL_TASK,
  87. 'weight' => 2
  88. );
  89. return $items;
  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('Importers'),
  101. 'description' => t('List all publication importers'),
  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' => 'Publications Importers',
  110. 'description' => 'Create importers that can periodically import publications from remote online publication 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. 'page callback' => 'tripal_pub_get_raw_data',
  124. 'page arguments' => array(6),
  125. 'access arguments' => array('administer tripal pub'),
  126. 'type ' => MENU_CALLBACK,
  127. );
  128. $items['admin/tripal/chado/tripal_pub/import/edit/%'] = array(
  129. 'page callback' => 'tripal_pub_importer_setup_page',
  130. 'page arguments' => array(5, 6),
  131. 'access arguments' => array('administer tripal pub'),
  132. 'type ' => MENU_CALLBACK,
  133. );
  134. $items['admin/tripal/chado/tripal_pub/import/submit/%'] = array(
  135. 'page callback' => 'tripal_pub_importer_submit_job',
  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/delete/%'] = array(
  141. 'page callback' => 'tripal_pub_importer_delete',
  142. 'page arguments' => array(5),
  143. 'access arguments' => array('administer tripal pub'),
  144. 'type ' => MENU_CALLBACK,
  145. );
  146. $items['admin/tripal/chado/tripal_pub/import/changedb'] = array(
  147. 'page callback' => 'tripal_pub_importer_setup_page_update_remotedb',
  148. 'page arguments' => array(),
  149. 'access arguments' => array('administer tripal pub'),
  150. 'type ' => MENU_CALLBACK,
  151. );
  152. $items['admin/tripal/chado/tripal_pub/import/criteria/%/%'] = array(
  153. 'page callback' => 'tripal_pub_importer_setup_page_update_criteria',
  154. 'page arguments' => array(5, 6),
  155. 'access arguments' => array('administer tripal pub'),
  156. 'type ' => MENU_CALLBACK,
  157. );
  158. return $items;
  159. }
  160. /**
  161. * Implements hook_theme(): Register themeing functions for this module
  162. *
  163. *
  164. * @return
  165. * An array of themeing functions to register
  166. *
  167. */
  168. function tripal_pub_theme($existing, $type, $theme, $path) {
  169. $core_path = drupal_get_path('module', 'tripal_core');
  170. $items = array(
  171. 'node__chado_pub' => array(
  172. 'template' => 'node--chado-generic',
  173. 'render element' => 'node',
  174. 'base hook' => 'node',
  175. 'path' => "$core_path/theme",
  176. ),
  177. // node templates
  178. 'tripal_pub_authors' => array(
  179. 'arguments' => array('node' => NULL),
  180. 'template' => 'tripal_pub_authors',
  181. 'path' => "$path/theme/tripal_pub",
  182. ),
  183. 'tripal_pub_base' => array(
  184. 'arguments' => array('node' => NULL),
  185. 'template' => 'tripal_pub_base',
  186. 'path' => "$path/theme/tripal_pub",
  187. ),
  188. 'tripal_pub_featuremaps' => array(
  189. 'arguments' => array('node' => NULL),
  190. 'template' => 'tripal_pub_featuremaps',
  191. 'path' => "$path/theme/tripal_pub",
  192. ),
  193. 'tripal_pub_features' => array(
  194. 'arguments' => array('node' => NULL),
  195. 'template' => 'tripal_pub_features',
  196. 'path' => "$path/theme/tripal_pub",
  197. ),
  198. 'tripal_pub_libraries' => array(
  199. 'arguments' => array('node' => NULL),
  200. 'template' => 'tripal_pub_libraries',
  201. 'path' => "$path/theme/tripal_pub",
  202. ),
  203. 'tripal_pub_projects' => array(
  204. 'arguments' => array('node' => NULL),
  205. 'template' => 'tripal_pub_projects',
  206. 'path' => "$path/theme/tripal_pub",
  207. ),
  208. 'tripal_pub_properties' => array(
  209. 'arguments' => array('node' => NULL),
  210. 'template' => 'tripal_pub_properties',
  211. 'path' => "$path/theme/tripal_pub",
  212. ),
  213. 'tripal_pub_references' => array(
  214. 'arguments' => array('node' => NULL),
  215. 'template' => 'tripal_pub_references',
  216. 'path' => "$path/theme/tripal_pub",
  217. ),
  218. 'tripal_pub_relationships' => array(
  219. 'arguments' => array('node' => NULL),
  220. 'template' => 'tripal_pub_relationships',
  221. 'path' => "$path/theme/tripal_pub",
  222. ),
  223. 'tripal_pub_stocks' => array(
  224. 'arguments' => array('node' => NULL),
  225. 'template' => 'tripal_pub_stocks',
  226. 'path' => "$path/theme/tripal_pub",
  227. ),
  228. // instructions page for the pub module
  229. 'tripal_pub_help' => array(
  230. 'template' => 'tripal_pub_help',
  231. 'arguments' => array(NULL),
  232. 'path' => "$path/theme",
  233. ),
  234. // themed forms
  235. 'tripal_pub_importer_setup_form_elements' => array(
  236. 'render element' => 'form',
  237. ),
  238. 'tripal_pub_search_setup_form_elements' => array(
  239. 'render element' => 'form',
  240. ),
  241. // teaser
  242. 'tripal_pub_teaser' => array(
  243. 'variables' => array('node' => NULL),
  244. 'template' => 'tripal_pub_teaser',
  245. 'path' => "$path/theme/tripal_pub",
  246. ),
  247. );
  248. return $items;
  249. }
  250. /**
  251. * Implements hook_help()
  252. * Purpose: Adds a help page to the module list
  253. */
  254. function tripal_pub_help ($path, $arg) {
  255. if ($path == 'admin/help#tripal_pub') {
  256. return theme('tripal_pub_help', array());
  257. }
  258. }
  259. /**
  260. * Implements hook_views_api()
  261. * Purpose: Essentially this hook tells drupal that there is views support for
  262. * for this module which then includes tripal_db.views.inc where all the
  263. * views integration code is
  264. *
  265. * @ingroup tripal_pub
  266. */
  267. function tripal_pub_views_api() {
  268. return array(
  269. 'api' => 3.0,
  270. );
  271. }
  272. /**
  273. * Implement hook_permissions().
  274. */
  275. function tripal_pub_permissions() {
  276. return array(
  277. 'access chado_pub content' => array(
  278. 'title' => t('View Publications'),
  279. 'description' => t('Allow users to view publication pages.'),
  280. ),
  281. 'create chado_pub content' => array(
  282. 'title' => t('Create Publication'),
  283. 'description' => t('Allow users to create new publication pages.'),
  284. ),
  285. 'delete chado_pub content' => array(
  286. 'title' => t('Delete Publication'),
  287. 'description' => t('Allow users to delete publication pages.'),
  288. ),
  289. 'edit chado_pub content' => array(
  290. 'title' => t('Edit Publications'),
  291. 'description' => t('Allow users to edit publication pages.'),
  292. ),
  293. 'adminster tripal pub' => array(
  294. 'title' => t('Administer Publications'),
  295. 'description' => t('Allow users to administer all publications.'),
  296. ),
  297. );
  298. }
  299. /**
  300. *
  301. */
  302. function tripal_pub_mail($key, &$message, $params) {
  303. $language = $message['language'];
  304. $variables = user_mail_tokens($params['account'], $language);
  305. switch($key) {
  306. case 'import_report':
  307. $headers = array(
  308. 'MIME-Version' => '1.0',
  309. 'Content-Type' => 'text/html; charset=UTF-8; format=flowed',
  310. 'Content-Transfer-Encoding' => '8Bit',
  311. 'X-Mailer' => 'Drupal'
  312. );
  313. foreach ($headers as $key => $value) {
  314. $message['headers'][$key] = $value;
  315. }
  316. $message['subject'] = t('Publication import from !site', $variables, $language->language);
  317. $message['body'][] = $params['message'];
  318. break;
  319. }
  320. }
  321. /**
  322. * Implementation of hook_form_alter()
  323. *
  324. * @param $form
  325. * @param $form_state
  326. * @param $form_id
  327. */
  328. function tripal_pub_form_alter(&$form, &$form_state, $form_id) {
  329. // turn of preview button for insert/updates
  330. if ($form_id == "chado_pub_node_form") {
  331. $form['actions']['preview']['#access'] = FALSE;
  332. }
  333. if ($form_id == "tripal_pub_importer_setup_form") {
  334. /* // updating the form through the ahah callback sets the action of
  335. // the form to the ahah callback URL. We need to set it back
  336. // to the normal form URL
  337. if (array_key_exists('values', $form_state) and $form_state['values']['action'] == 'edit') {
  338. $form['#action'] = url("admin/tripal/chado/tripal_pub/import/edit/" . $form_state['values']['pub_import_id']);
  339. }
  340. if (array_key_exists('values', $form_state) and $form_state['values']['action'] == 'new') {
  341. $form['#action'] = url("admin/tripal/chado/tripal_pub/import/new");
  342. }
  343. */
  344. }
  345. if ($form_id == "tripal_pub_search_form") {
  346. $form['#action'] = url("find/publications");
  347. }
  348. if ($form_id == "chado_pub_node_form") {
  349. }
  350. }
  351. /**
  352. *
  353. * @param $callback
  354. * @param $args
  355. */
  356. function tripal_pub_job_describe_args($callback, $args) {
  357. $new_args = array();
  358. if ($callback == 'tripal_pub_import_publications_by_import_id') {
  359. // get all of the loaders
  360. $qargs = array(':import_id' => $args[0]);
  361. $sql = "SELECT * FROM {tripal_pub_import} WHERE pub_import_id = :import_id ";
  362. $import = db_query($sql, $qargs)->fetchObject();
  363. $new_args['Importer'] = $import->name;
  364. }
  365. return $new_args;
  366. }