tripal_pub.module 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419
  1. <?php
  2. /**
  3. * @file
  4. * Basic functionality of the pub module
  5. */
  6. require_once 'api/tripal_pub.api.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_importers.inc';
  11. require_once 'includes/tripal_pub.pub_search.inc';
  12. require_once 'includes/tripal_pub.pub_citation.inc';
  13. require_once 'includes/importers/tripal_pub.PMID.inc';
  14. require_once 'includes/importers/tripal_pub.AGL.inc';
  15. /**
  16. * @defgroup tripal_pub Publication Module
  17. * @ingroup tripal_modules
  18. * @{
  19. * Integrates the Chado Publication module with Drupal Nodes & Views, as well as, provides
  20. * the ability to import publication from PubMed
  21. *
  22. * The Tripal Publication module allows you to search the PubMed database for academic articles,
  23. * that relate to user specified topic\s. As well, it allows management of publications so that
  24. * a user can enter specified details regarding a desired publication. This allows all of the important
  25. * information that is unique to a Academic Publication to be stored for access.
  26. * @}
  27. */
  28. /**
  29. * Implements hook_menu().
  30. *
  31. * Adds menu items for the tripal_pub module menu. This section
  32. * gives the outline for the main menu of the Tripal-Publication module
  33. *
  34. * @return
  35. * An array of menu items that is visible within the Drupal Menu, returned as soon
  36. * as the program is ran
  37. *
  38. * @ingroup tripal_pub
  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().
  162. * Register themeing functions for this module
  163. *
  164. * @return
  165. * An array of themeing functions to register
  166. *
  167. * @ingroup tripal_pub
  168. */
  169. function tripal_pub_theme($existing, $type, $theme, $path) {
  170. $core_path = drupal_get_path('module', 'tripal_core');
  171. $items = array(
  172. 'node__chado_pub' => array(
  173. 'template' => 'node--chado-generic',
  174. 'render element' => 'node',
  175. 'base hook' => 'node',
  176. 'path' => "$core_path/theme",
  177. ),
  178. // node templates
  179. 'tripal_pub_authors' => array(
  180. 'arguments' => array('node' => NULL),
  181. 'template' => 'tripal_pub_authors',
  182. 'path' => "$path/theme/tripal_pub",
  183. ),
  184. 'tripal_pub_base' => array(
  185. 'arguments' => array('node' => NULL),
  186. 'template' => 'tripal_pub_base',
  187. 'path' => "$path/theme/tripal_pub",
  188. ),
  189. 'tripal_pub_featuremaps' => array(
  190. 'arguments' => array('node' => NULL),
  191. 'template' => 'tripal_pub_featuremaps',
  192. 'path' => "$path/theme/tripal_pub",
  193. ),
  194. 'tripal_pub_features' => array(
  195. 'arguments' => array('node' => NULL),
  196. 'template' => 'tripal_pub_features',
  197. 'path' => "$path/theme/tripal_pub",
  198. ),
  199. 'tripal_pub_libraries' => array(
  200. 'arguments' => array('node' => NULL),
  201. 'template' => 'tripal_pub_libraries',
  202. 'path' => "$path/theme/tripal_pub",
  203. ),
  204. 'tripal_pub_projects' => array(
  205. 'arguments' => array('node' => NULL),
  206. 'template' => 'tripal_pub_projects',
  207. 'path' => "$path/theme/tripal_pub",
  208. ),
  209. 'tripal_pub_properties' => array(
  210. 'arguments' => array('node' => NULL),
  211. 'template' => 'tripal_pub_properties',
  212. 'path' => "$path/theme/tripal_pub",
  213. ),
  214. 'tripal_pub_references' => array(
  215. 'arguments' => array('node' => NULL),
  216. 'template' => 'tripal_pub_references',
  217. 'path' => "$path/theme/tripal_pub",
  218. ),
  219. 'tripal_pub_relationships' => array(
  220. 'arguments' => array('node' => NULL),
  221. 'template' => 'tripal_pub_relationships',
  222. 'path' => "$path/theme/tripal_pub",
  223. ),
  224. 'tripal_pub_stocks' => array(
  225. 'arguments' => array('node' => NULL),
  226. 'template' => 'tripal_pub_stocks',
  227. 'path' => "$path/theme/tripal_pub",
  228. ),
  229. // instructions page for the pub module
  230. 'tripal_pub_help' => array(
  231. 'template' => 'tripal_pub_help',
  232. 'arguments' => array(NULL),
  233. 'path' => "$path/theme",
  234. ),
  235. // themed forms
  236. 'tripal_pub_importer_setup_form_elements' => array(
  237. 'render element' => 'form',
  238. ),
  239. 'tripal_pub_search_setup_form_elements' => array(
  240. 'render element' => 'form',
  241. ),
  242. // teaser
  243. 'tripal_pub_teaser' => array(
  244. 'variables' => array('node' => NULL),
  245. 'template' => 'tripal_pub_teaser',
  246. 'path' => "$path/theme/tripal_pub",
  247. ),
  248. );
  249. return $items;
  250. }
  251. /**
  252. * Implements hook_help().
  253. * Adds a help page to the module list
  254. *
  255. * @ingroup tripal_pub
  256. */
  257. function tripal_pub_help ($path, $arg) {
  258. if ($path == 'admin/help#tripal_pub') {
  259. return theme('tripal_pub_help', array());
  260. }
  261. }
  262. /**
  263. * Implements hook_views_api().
  264. *
  265. * Essentially this hook tells drupal that there is views support for
  266. * for this module which then includes tripal_db.views.inc where all the
  267. * views integration code is
  268. *
  269. * @ingroup tripal_pub
  270. */
  271. function tripal_pub_views_api() {
  272. return array(
  273. 'api' => 3.0,
  274. );
  275. }
  276. /**
  277. * Implement hook_permission().
  278. *
  279. * @ingroup tripal_pub
  280. */
  281. function tripal_pub_permission() {
  282. return array(
  283. 'access chado_pub content' => array(
  284. 'title' => t('View Publications'),
  285. 'description' => t('Allow users to view publication pages.'),
  286. ),
  287. 'create chado_pub content' => array(
  288. 'title' => t('Create Publication'),
  289. 'description' => t('Allow users to create new publication pages.'),
  290. ),
  291. 'delete chado_pub content' => array(
  292. 'title' => t('Delete Publication'),
  293. 'description' => t('Allow users to delete publication pages.'),
  294. ),
  295. 'edit chado_pub content' => array(
  296. 'title' => t('Edit Publications'),
  297. 'description' => t('Allow users to edit publication pages.'),
  298. ),
  299. 'adminster tripal pub' => array(
  300. 'title' => t('Administer Publications'),
  301. 'description' => t('Allow users to administer all publications.'),
  302. ),
  303. );
  304. }
  305. /**
  306. * Implements hook_mail().
  307. *
  308. * @ingroup tripal_pub
  309. */
  310. function tripal_pub_mail($key, &$message, $params) {
  311. $language = $message['language'];
  312. $variables = user_mail_tokens($params['account'], $language);
  313. switch($key) {
  314. case 'import_report':
  315. $headers = array(
  316. 'MIME-Version' => '1.0',
  317. 'Content-Type' => 'text/html; charset=UTF-8; format=flowed',
  318. 'Content-Transfer-Encoding' => '8Bit',
  319. 'X-Mailer' => 'Drupal'
  320. );
  321. foreach ($headers as $key => $value) {
  322. $message['headers'][$key] = $value;
  323. }
  324. $message['subject'] = t('Publication import from !site', $variables, $language->language);
  325. $message['body'][] = $params['message'];
  326. break;
  327. }
  328. }
  329. /**
  330. * Implementation of hook_form_alter().
  331. *
  332. * @param $form
  333. * @param $form_state
  334. * @param $form_id
  335. *
  336. * @ingroup tripal_pub
  337. */
  338. function tripal_pub_form_alter(&$form, &$form_state, $form_id) {
  339. // turn of preview button for insert/updates
  340. if ($form_id == "chado_pub_node_form") {
  341. // turn of preview button for insert/updates
  342. $form['actions']['preview']['#access'] = FALSE;
  343. //remove the body field
  344. unset($form['body']);
  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. * Implements hook_job_describe_args().
  366. *
  367. * @param $callback
  368. * @param $args
  369. *
  370. * @ingroup tripal_pub
  371. */
  372. function tripal_pub_job_describe_args($callback, $args) {
  373. $new_args = array();
  374. if ($callback == 'tripal_pub_import_publications_by_import_id') {
  375. // get all of the loaders
  376. $qargs = array(':import_id' => $args[0]);
  377. $sql = "SELECT * FROM {tripal_pub_import} WHERE pub_import_id = :import_id ";
  378. $import = db_query($sql, $qargs)->fetchObject();
  379. $new_args['Importer'] = $import->name;
  380. }
  381. return $new_args;
  382. }