tripal_pub.module 13 KB

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