tripal_pub.module 13 KB

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