tripal_pub.module 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423
  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 pubs'),
  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 pubs'),
  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 pubs'),
  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 pubs'),
  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 pubs'),
  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 pubs'),
  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 pubs'),
  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 pubs'),
  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 pubs'),
  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 pubs'),
  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 pubs'),
  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 pubs'),
  155. 'type ' => MENU_CALLBACK,
  156. );
  157. $items['tripal_pub/chado/properties/add'] = array(
  158. 'page callback' => 'tripal_pub_property_add',
  159. 'access arguments' => array('edit chado_pub content'),
  160. 'type ' => MENU_CALLBACK,
  161. );
  162. $items['tripal_pub/chado/properties/description'] = array(
  163. 'page callback' => 'tripal_pub_property_get_description',
  164. 'access arguments' => array('edit chado_pub content'),
  165. 'type ' => MENU_CALLBACK,
  166. );
  167. $items['tripal_pub/chado/properties/minus/%/%'] = array(
  168. 'page callback' => 'tripal_pub_property_delete',
  169. 'page arguments' => array(3, 4),
  170. 'access arguments' => array('edit chado_pub content'),
  171. 'type ' => MENU_CALLBACK,
  172. );
  173. return $items;
  174. }
  175. /**
  176. * Implements hook_theme(): Register themeing functions for this module
  177. *
  178. *
  179. * @return
  180. * An array of themeing functions to register
  181. *
  182. */
  183. function tripal_pub_theme($existing, $type, $theme, $path) {
  184. $core_path = drupal_get_path('module', 'tripal_core');
  185. $items = array(
  186. 'node__chado_pub' => array(
  187. 'template' => 'node--chado-generic',
  188. 'render element' => 'node',
  189. 'base hook' => 'node',
  190. 'path' => "$core_path/theme",
  191. ),
  192. // node templates
  193. 'tripal_pub_authors' => array(
  194. 'arguments' => array('node' => NULL),
  195. 'template' => 'tripal_pub_authors',
  196. 'path' => "$path/theme/tripal_pub",
  197. ),
  198. 'tripal_pub_base' => array(
  199. 'arguments' => array('node' => NULL),
  200. 'template' => 'tripal_pub_base',
  201. 'path' => "$path/theme/tripal_pub",
  202. ),
  203. 'tripal_pub_featuremaps' => array(
  204. 'arguments' => array('node' => NULL),
  205. 'template' => 'tripal_pub_featuremaps',
  206. 'path' => "$path/theme/tripal_pub",
  207. ),
  208. 'tripal_pub_features' => array(
  209. 'arguments' => array('node' => NULL),
  210. 'template' => 'tripal_pub_features',
  211. 'path' => "$path/theme/tripal_pub",
  212. ),
  213. 'tripal_pub_libraries' => array(
  214. 'arguments' => array('node' => NULL),
  215. 'template' => 'tripal_pub_libraries',
  216. 'path' => "$path/theme/tripal_pub",
  217. ),
  218. 'tripal_pub_projects' => array(
  219. 'arguments' => array('node' => NULL),
  220. 'template' => 'tripal_pub_projects',
  221. 'path' => "$path/theme/tripal_pub",
  222. ),
  223. 'tripal_pub_properties' => array(
  224. 'arguments' => array('node' => NULL),
  225. 'template' => 'tripal_pub_properties',
  226. 'path' => "$path/theme/tripal_pub",
  227. ),
  228. 'tripal_pub_references' => array(
  229. 'arguments' => array('node' => NULL),
  230. 'template' => 'tripal_pub_references',
  231. 'path' => "$path/theme/tripal_pub",
  232. ),
  233. 'tripal_pub_relationships' => array(
  234. 'arguments' => array('node' => NULL),
  235. 'template' => 'tripal_pub_relationships',
  236. 'path' => "$path/theme/tripal_pub",
  237. ),
  238. 'tripal_pub_stocks' => array(
  239. 'arguments' => array('node' => NULL),
  240. 'template' => 'tripal_pub_stocks',
  241. 'path' => "$path/theme/tripal_pub",
  242. ),
  243. // instructions page for the pub module
  244. 'tripal_pub_help' => array(
  245. 'template' => 'tripal_pub_help',
  246. 'arguments' => array(NULL),
  247. 'path' => "$path/theme",
  248. ),
  249. // themed forms
  250. 'tripal_pub_importer_setup_form_elements' => array(
  251. 'render element' => 'form',
  252. ),
  253. 'tripal_pub_search_setup_form_elements' => array(
  254. 'render element' => 'form',
  255. ),
  256. // teaser
  257. 'tripal_pub_teaser' => array(
  258. 'variables' => array('node' => NULL),
  259. 'template' => 'tripal_pub_teaser',
  260. 'path' => "$path/theme/tripal_pub",
  261. ),
  262. );
  263. return $items;
  264. }
  265. /**
  266. * Implements hook_help()
  267. * Purpose: Adds a help page to the module list
  268. */
  269. function tripal_pub_help ($path, $arg) {
  270. if ($path == 'admin/help#tripal_pub') {
  271. return theme('tripal_pub_help', array());
  272. }
  273. }
  274. /**
  275. * Implements hook_views_api()
  276. * Purpose: Essentially this hook tells drupal that there is views support for
  277. * for this module which then includes tripal_db.views.inc where all the
  278. * views integration code is
  279. *
  280. * @ingroup tripal_pub
  281. */
  282. function tripal_pub_views_api() {
  283. return array(
  284. 'api' => 3.0,
  285. );
  286. }
  287. /**
  288. * Implement hook_permissions().
  289. */
  290. function tripal_pub_permissions() {
  291. return array(
  292. 'access chado_pub content' => array(
  293. 'title' => t('View Publications'),
  294. 'description' => t('Allow users to view publication pages.'),
  295. ),
  296. 'create chado_pub content' => array(
  297. 'title' => t('Create Publication'),
  298. 'description' => t('Allow users to create new publication pages.'),
  299. ),
  300. 'delete chado_pub content' => array(
  301. 'title' => t('Delete Publication'),
  302. 'description' => t('Allow users to delete publication pages.'),
  303. ),
  304. 'edit chado_pub content' => array(
  305. 'title' => t('Edit Publications'),
  306. 'description' => t('Allow users to edit publication pages.'),
  307. ),
  308. 'adminster tripal pub' => array(
  309. 'title' => t('Administer Publications'),
  310. 'description' => t('Allow users to administer all publications.'),
  311. ),
  312. );
  313. }
  314. /**
  315. *
  316. */
  317. function tripal_pub_mail($key, &$message, $params) {
  318. $language = $message['language'];
  319. $variables = user_mail_tokens($params['account'], $language);
  320. switch($key) {
  321. case 'import_report':
  322. $headers = array(
  323. 'MIME-Version' => '1.0',
  324. 'Content-Type' => 'text/html; charset=UTF-8; format=flowed',
  325. 'Content-Transfer-Encoding' => '8Bit',
  326. 'X-Mailer' => 'Drupal'
  327. );
  328. foreach ($headers as $key => $value) {
  329. $message['headers'][$key] = $value;
  330. }
  331. $message['subject'] = t('Publication import from !site', $variables, $language->language);
  332. $message['body'][] = $params['message'];
  333. break;
  334. }
  335. }
  336. /**
  337. * Implementation of hook_form_alter()
  338. *
  339. * @param $form
  340. * @param $form_state
  341. * @param $form_id
  342. */
  343. function tripal_pub_form_alter(&$form, &$form_state, $form_id) {
  344. // turn of preview button for insert/updates
  345. if ($form_id == "chado_pub_node_form") {
  346. $form['actions']['preview']['#access'] = FALSE;
  347. }
  348. if ($form_id == "tripal_pub_importer_setup_form") {
  349. /* // updating the form through the ahah callback sets the action of
  350. // the form to the ahah callback URL. We need to set it back
  351. // to the normal form URL
  352. if (array_key_exists('values', $form_state) and $form_state['values']['action'] == 'edit') {
  353. $form['#action'] = url("admin/tripal/chado/tripal_pub/import/edit/" . $form_state['values']['pub_import_id']);
  354. }
  355. if (array_key_exists('values', $form_state) and $form_state['values']['action'] == 'new') {
  356. $form['#action'] = url("admin/tripal/chado/tripal_pub/import/new");
  357. }
  358. */
  359. }
  360. if ($form_id == "tripal_pub_search_form") {
  361. $form['#action'] = url("find/publications");
  362. }
  363. if ($form_id == "chado_pub_node_form") {
  364. }
  365. }
  366. /**
  367. *
  368. * @param $callback
  369. * @param $args
  370. */
  371. function tripal_pub_job_describe_args($callback, $args) {
  372. $new_args = array();
  373. if ($callback == 'tripal_pub_import_publications_by_import_id') {
  374. // get all of the loaders
  375. $qargs = array(':import_id' => $args[0]);
  376. $sql = "SELECT * FROM {tripal_pub_import} WHERE pub_import_id = :import_id ";
  377. $import = db_query($sql, $qargs)->fetchObject();
  378. $new_args['Importer'] = $import->name;
  379. }
  380. return $new_args;
  381. }