tripal_pub.module 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544
  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.pub_sync.inc";
  6. require_once "includes/tripal_pub.chado_node.inc";
  7. require_once "includes/tripal_pub.pub_importers.inc";
  8. require_once "includes/tripal_pub.pub_search.inc";
  9. require_once "includes/tripal_pub.pub_citation.inc";
  10. require_once "includes/importers/tripal_pub.PMID.inc";
  11. require_once "includes/importers/tripal_pub.AGL.inc";
  12. /**
  13. * @file
  14. *
  15. * The Tripal Publication module allows you to search the PubMed databse for academic articles,
  16. * that relate to user specified tpoic\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. * @ingroup tripal_pub
  23. */
  24. function tripal_pub_init() {
  25. drupal_add_css(drupal_get_path('module', 'tripal_pub') . '/theme/css/tripal_pub.css');
  26. drupal_add_js(drupal_get_path('module', 'tripal_pub') . '/theme/js/tripal_pub.js');
  27. }
  28. /**
  29. * Implementation of hook_tripal_pub_node_info().
  30. *
  31. * This node_info, is a simple node that describes the functionallity of the module.
  32. *
  33. */
  34. function tripal_pub_node_info() {
  35. return array(
  36. 'chado_pub' => array(
  37. 'name' => t('Publication'),
  38. 'base' => 'chado_pub',
  39. 'description' => t('A publication from the Chado database'),
  40. 'title_label' => t('Article Title'),
  41. 'body_label' => t('Abstract'),
  42. 'has_title' => TRUE,
  43. 'has_body' => FALSE,
  44. ),
  45. );
  46. }
  47. /**
  48. * Tripal-Publication-Menu
  49. *
  50. * Implements hook_menu(): Adds menu items for the tripal_pub module menu. This section
  51. * gives the outline for the main menu of the Tripal-Publication module
  52. *
  53. * @return
  54. * An array of menu items that is visible within the Drupal Menu, returned as soon
  55. * as the program is ran
  56. */
  57. function tripal_pub_menu() {
  58. $items = array();
  59. $items['find/publications' ]= array(
  60. 'title' => 'Publication Search',
  61. 'description' => ('Search for publications'),
  62. 'page callback' => 'tripal_pub_search_page',
  63. 'access arguments' => array('access chado_pub content'),
  64. 'type' => MENU_CALLBACK
  65. );
  66. $items['find/publications/criteria/%/%'] = array(
  67. 'page callback' => 'tripal_pub_search_page_update_criteria',
  68. 'page arguments' => array(5, 6),
  69. 'access arguments' => array('access chado_pub content'),
  70. 'type ' => MENU_CALLBACK,
  71. );
  72. $items['admin/tripal/chado/tripal_pub']= array(
  73. 'title' => 'Publications',
  74. 'description' => ('A documented provenance artefact - publications, documents, personal communication.'),
  75. 'page callback' => 'tripal_pub_admin_pub_view',
  76. 'access arguments' => array('administer tripal pubs'),
  77. 'type' => MENU_NORMAL_ITEM
  78. );
  79. $items['admin/tripal/chado/tripal_pub/help']= array(
  80. 'title' => 'Help',
  81. 'description' => ('A module for interfacing the GMOD chado database with Drupal, providing viewing of publications'),
  82. 'page callback' => 'theme',
  83. 'page arguments' => array('tripal_pub_help'),
  84. 'access arguments' => array('administer tripal pubs'),
  85. 'type' => MENU_LOCAL_TASK,
  86. 'weight' => 10
  87. );
  88. $items['admin/tripal/chado/tripal_pub/configuration'] = array(
  89. 'title' => 'Settings',
  90. 'description' => 'Configure the Tripal publication module.',
  91. 'page callback' => 'drupal_get_form',
  92. 'page arguments' => array('tripal_pub_admin'),
  93. 'access arguments' => array('administer tripal pubs'),
  94. 'type' => MENU_LOCAL_TASK,
  95. 'weight' => 5
  96. );
  97. $items['admin/tripal/chado/tripal_pub/sync'] = array(
  98. 'title' => ' Sync',
  99. 'description' => 'Sync publications in Chado with Drupal',
  100. 'page callback' => 'drupal_get_form',
  101. 'page arguments' => array('tripal_pub_sync_form'),
  102. 'access arguments' => array('administer tripal pubs'),
  103. 'type' => MENU_LOCAL_TASK,
  104. 'weight' => 2
  105. );
  106. $items['admin/tripal/chado/tripal_pub/citation'] = array(
  107. 'title' => 'Citations',
  108. 'description' => 'Update publication citations',
  109. 'page callback' => 'drupal_get_form',
  110. 'page arguments' => array('tripal_pub_citation_form'),
  111. 'access arguments' => array('administer tripal pubs'),
  112. 'type' => MENU_LOCAL_TASK,
  113. 'weight' => 1
  114. );
  115. $items['admin/tripal/chado/tripal_pub/import_list'] = array(
  116. 'title' => t('Importers'),
  117. 'description' => t('List all publication importers'),
  118. 'page callback' => 'tripal_pub_importers_list',
  119. 'access arguments' => array('administer tripal pubs'),
  120. 'type' => MENU_LOCAL_TASK,
  121. 'weight' => 0
  122. );
  123. // add a second link for the importer on the data loaders page
  124. $items['admin/tripal/loaders/pub_import'] = array(
  125. 'title' => 'Publications Importers',
  126. 'description' => 'Create importers that can periodically import publications from remote online publication databases.',
  127. 'page callback' => 'tripal_pub_importers_list',
  128. 'access arguments' => array('administer tripal pubs'),
  129. 'type' => MENU_NORMAL_ITEM,
  130. );
  131. $items['admin/tripal/chado/tripal_pub/import/new'] = array(
  132. 'title' => t('Add an Importer'),
  133. 'description' => t('Add a new publication importer.'),
  134. 'page callback' => 'tripal_pub_importer_setup_page',
  135. 'access arguments' => array('administer tripal pubs'),
  136. 'type ' => MENU_CALLBACK,
  137. );
  138. $items['admin/tripal/chado/tripal_pub/import/raw/%'] = array(
  139. 'page callback' => 'tripal_pub_get_raw_data',
  140. 'page arguments' => array(6),
  141. 'access arguments' => array('administer tripal pubs'),
  142. 'type ' => MENU_CALLBACK,
  143. );
  144. $items['admin/tripal/chado/tripal_pub/import/edit/%'] = array(
  145. 'page callback' => 'tripal_pub_importer_setup_page',
  146. 'page arguments' => array(5, 6),
  147. 'access arguments' => array('administer tripal pubs'),
  148. 'type ' => MENU_CALLBACK,
  149. );
  150. $items['admin/tripal/chado/tripal_pub/import/submit/%'] = array(
  151. 'page callback' => 'tripal_pub_importer_submit_job',
  152. 'page arguments' => array(6),
  153. 'access arguments' => array('administer tripal pubs'),
  154. 'type ' => MENU_CALLBACK,
  155. );
  156. $items['admin/tripal/chado/tripal_pub/import/delete/%'] = array(
  157. 'page callback' => 'tripal_pub_importer_delete',
  158. 'page arguments' => array(5),
  159. 'access arguments' => array('administer tripal pubs'),
  160. 'type ' => MENU_CALLBACK,
  161. );
  162. $items['admin/tripal/chado/tripal_pub/import/changedb'] = array(
  163. 'page callback' => 'tripal_pub_importer_setup_page_update_remotedb',
  164. 'page arguments' => array(),
  165. 'access arguments' => array('administer tripal pubs'),
  166. 'type ' => MENU_CALLBACK,
  167. );
  168. $items['admin/tripal/chado/tripal_pub/import/criteria/%/%'] = array(
  169. 'page callback' => 'tripal_pub_importer_setup_page_update_criteria',
  170. 'page arguments' => array(5, 6),
  171. 'access arguments' => array('administer tripal pubs'),
  172. 'type ' => MENU_CALLBACK,
  173. );
  174. $items['tripal_pub/chado/properties/add'] = array(
  175. 'page callback' => 'tripal_pub_property_add',
  176. 'access arguments' => array('edit chado_pub content'),
  177. 'type ' => MENU_CALLBACK,
  178. );
  179. $items['tripal_pub/chado/properties/description'] = array(
  180. 'page callback' => 'tripal_pub_property_get_description',
  181. 'access arguments' => array('edit chado_pub content'),
  182. 'type ' => MENU_CALLBACK,
  183. );
  184. $items['tripal_pub/chado/properties/minus/%/%'] = array(
  185. 'page callback' => 'tripal_pub_property_delete',
  186. 'page arguments' => array(3, 4),
  187. 'access arguments' => array('edit chado_pub content'),
  188. 'type ' => MENU_CALLBACK,
  189. );
  190. return $items;
  191. }
  192. /**
  193. * Implements hook_theme(): Register themeing functions for this module
  194. *
  195. *
  196. * @return
  197. * An array of themeing functions to register
  198. *
  199. */
  200. function tripal_pub_theme($existing, $type, $theme, $path) {
  201. $core_path = drupal_get_path('module', 'tripal_core');
  202. $items = array(
  203. 'node__chado_pub' => array(
  204. 'template' => 'node--chado-generic',
  205. 'render element' => 'node',
  206. 'base hook' => 'node',
  207. 'path' => "$core_path/theme",
  208. ),
  209. // node templates
  210. 'tripal_pub_authors' => array(
  211. 'arguments' => array('node' => NULL),
  212. 'template' => 'tripal_pub_authors',
  213. 'path' => "$path/theme/tripal_pub",
  214. ),
  215. 'tripal_pub_base' => array(
  216. 'arguments' => array('node' => NULL),
  217. 'template' => 'tripal_pub_base',
  218. 'path' => "$path/theme/tripal_pub",
  219. ),
  220. 'tripal_pub_featuremaps' => array(
  221. 'arguments' => array('node' => NULL),
  222. 'template' => 'tripal_pub_featuremaps',
  223. 'path' => "$path/theme/tripal_pub",
  224. ),
  225. 'tripal_pub_features' => array(
  226. 'arguments' => array('node' => NULL),
  227. 'template' => 'tripal_pub_features',
  228. 'path' => "$path/theme/tripal_pub",
  229. ),
  230. 'tripal_pub_libraries' => array(
  231. 'arguments' => array('node' => NULL),
  232. 'template' => 'tripal_pub_libraries',
  233. 'path' => "$path/theme/tripal_pub",
  234. ),
  235. 'tripal_pub_projects' => array(
  236. 'arguments' => array('node' => NULL),
  237. 'template' => 'tripal_pub_projects',
  238. 'path' => "$path/theme/tripal_pub",
  239. ),
  240. 'tripal_pub_properties' => array(
  241. 'arguments' => array('node' => NULL),
  242. 'template' => 'tripal_pub_properties',
  243. 'path' => "$path/theme/tripal_pub",
  244. ),
  245. 'tripal_pub_references' => array(
  246. 'arguments' => array('node' => NULL),
  247. 'template' => 'tripal_pub_references',
  248. 'path' => "$path/theme/tripal_pub",
  249. ),
  250. 'tripal_pub_relationships' => array(
  251. 'arguments' => array('node' => NULL),
  252. 'template' => 'tripal_pub_relationships',
  253. 'path' => "$path/theme/tripal_pub",
  254. ),
  255. 'tripal_pub_stocks' => array(
  256. 'arguments' => array('node' => NULL),
  257. 'template' => 'tripal_pub_stocks',
  258. 'path' => "$path/theme/tripal_pub",
  259. ),
  260. // instructions page for the pub module
  261. 'tripal_pub_help' => array(
  262. 'template' => 'tripal_pub_help',
  263. 'arguments' => array(NULL),
  264. 'path' => "$path/theme",
  265. ),
  266. // themed forms
  267. 'tripal_pub_importer_setup_form_elements' => array(
  268. 'render element' => 'form',
  269. ),
  270. 'tripal_pub_search_setup_form_elements' => array(
  271. 'render element' => 'form',
  272. ),
  273. // teaser
  274. 'tripal_pub_teaser' => array(
  275. 'variables' => array('node' => NULL),
  276. 'template' => 'tripal_pub_teaser',
  277. 'path' => "$path/theme/tripal_pub",
  278. ),
  279. );
  280. return $items;
  281. }
  282. /**
  283. * Implements hook_help()
  284. * Purpose: Adds a help page to the module list
  285. */
  286. function tripal_pub_help ($path, $arg) {
  287. if ($path == 'admin/help#tripal_pub') {
  288. return theme('tripal_pub_help', array());
  289. }
  290. }
  291. /**
  292. * Implements hook_views_api()
  293. * Purpose: Essentially this hook tells drupal that there is views support for
  294. * for this module which then includes tripal_db.views.inc where all the
  295. * views integration code is
  296. *
  297. * @ingroup tripal_pub
  298. */
  299. function tripal_pub_views_api() {
  300. return array(
  301. 'api' => 3.0,
  302. );
  303. }
  304. /**
  305. * Implement hook_permissions().
  306. */
  307. function tripal_pub_permissions() {
  308. return array(
  309. 'access chado_pub content' => array(
  310. 'title' => t('View Publications'),
  311. 'description' => t('Allow users to view publication pages.'),
  312. ),
  313. 'create chado_pub content' => array(
  314. 'title' => t('Create Publication'),
  315. 'description' => t('Allow users to create new publication pages.'),
  316. ),
  317. 'delete chado_pub content' => array(
  318. 'title' => t('Delete Publication'),
  319. 'description' => t('Allow users to delete publication pages.'),
  320. ),
  321. 'edit chado_pub content' => array(
  322. 'title' => t('Edit Publications'),
  323. 'description' => t('Allow users to edit publication pages.'),
  324. ),
  325. 'adminster tripal pub' => array(
  326. 'title' => t('Administer Publications'),
  327. 'description' => t('Allow users to administer all publications.'),
  328. ),
  329. );
  330. }
  331. /**
  332. *
  333. */
  334. function tripal_pub_mail($key, &$message, $params) {
  335. $language = $message['language'];
  336. $variables = user_mail_tokens($params['account'], $language);
  337. switch($key) {
  338. case 'import_report':
  339. $headers = array(
  340. 'MIME-Version' => '1.0',
  341. 'Content-Type' => 'text/html; charset=UTF-8; format=flowed',
  342. 'Content-Transfer-Encoding' => '8Bit',
  343. 'X-Mailer' => 'Drupal'
  344. );
  345. foreach ($headers as $key => $value) {
  346. $message['headers'][$key] = $value;
  347. }
  348. $message['subject'] = t('Publication import from !site', $variables, $language->language);
  349. $message['body'][] = $params['message'];
  350. break;
  351. }
  352. }
  353. /**
  354. *
  355. * @ingroup tripal_feature
  356. */
  357. function tripal_pub_node_view($node, $view_mode, $langcode) {
  358. switch ($node->type) {
  359. case 'chado_pub':
  360. // Show feature browser and counts
  361. if ($view_mode == 'full') {
  362. $node->content['tripal_pub_authors'] = array(
  363. '#value' => theme('tripal_pub_authors', array('node' => $node)),
  364. );
  365. $node->content['tripal_pub_base'] = array(
  366. '#value' => theme('tripal_pub_base', array('node' => $node)),
  367. );
  368. $node->content['tripal_pub_featuremaps'] = array(
  369. '#value' => theme('tripal_pub_featuremaps', array('node' => $node)),
  370. );
  371. $node->content['tripal_pub_features'] = array(
  372. '#value' => theme('tripal_pub_features', array('node' => $node)),
  373. );
  374. $node->content['tripal_pub_libraries'] = array(
  375. '#value' => theme('tripal_pub_libraries', array('node' => $node)),
  376. );
  377. $node->content['tripal_pub_projects'] = array(
  378. '#value' => theme('tripal_pub_projects', array('node' => $node)),
  379. );
  380. $node->content['tripal_pub_properties'] = array(
  381. '#value' => theme('tripal_pub_properties', array('node' => $node)),
  382. );
  383. $node->content['tripal_pub_references'] = array(
  384. '#value' => theme('tripal_pub_references', array('node' => $node)),
  385. );
  386. $node->content['tripal_pub_relationships'] = array(
  387. '#value' => theme('tripal_pub_relationships', array('node' => $node)),
  388. );
  389. $node->content['tripal_pub_stocks'] = array(
  390. '#value' => theme('tripal_pub_stocks', array('node' => $node)),
  391. );
  392. }
  393. if ($view_mode == 'teaser') {
  394. $node->content['tripal_pub_teaser'] = array(
  395. '#value' => theme('tripal_pub_teaser', array('node' => $node)),
  396. );
  397. }
  398. break;
  399. }
  400. }
  401. /**
  402. *
  403. * @param $node
  404. */
  405. function tripal_pub_node_insert($node) {
  406. // we want the publications to always have a URL of http://[base url]/pub/[pub id]
  407. // where [pub id] is the Chado publication ID. This will allow for easy linking
  408. // into the publication without needing to know the node. Of course if you know the
  409. // node that will still work too (e.g. http://[base url]/node/[node id]
  410. // so the nodeapi function ensures that the URL path is set after insert or update
  411. // of the node and when the node is loaded if it hasn't yet been set.
  412. if ($node->type == 'chado_pub') {
  413. $pub_id = chado_get_id_for_node('pub', $node->nid);
  414. tripal_pub_set_pub_url($node, $pub_id);
  415. }
  416. }
  417. /**
  418. *
  419. * @param $node
  420. * @param $types
  421. */
  422. function tripal_pub_node_load($nodes, $types) {
  423. // we want the publications to always have a URL of http://[base url]/pub/[pub id]
  424. // where [pub id] is the Chado publication ID. This will allow for easy linking
  425. // into the publication without needing to know the node. Of course if you know the
  426. // node that will still work too (e.g. http://[base url]/node/[node id]
  427. // so the nodeapi function ensures that the URL path is set after insert or update
  428. // of the node and when the node is loaded if it hasn't yet been set.
  429. if (count(array_intersect(array('chado_pub'), $types))) {
  430. foreach ($nodes as $nid => $node) {
  431. if ($node->type == 'chado_pub' and !property_exists($node, 'path')) {
  432. $pub_id = chado_get_id_for_node('pub', $node->nid);
  433. $path = tripal_pub_set_pub_url($node, $pub_id);
  434. }
  435. }
  436. }
  437. }
  438. /**
  439. *
  440. * @param $node
  441. */
  442. function tripal_pub_node_update($node) {
  443. // we want the publications to always have a URL of http://[base url]/pub/[pub id]
  444. // where [pub id] is the Chado publication ID. This will allow for easy linking
  445. // into the publication without needing to know the node. Of course if you know the
  446. // node that will still work too (e.g. http://[base url]/node/[node id]
  447. // so the nodeapi function ensures that the URL path is set after insert or update
  448. // of the node and when the node is loaded if it hasn't yet been set.
  449. if ($node->type == 'chado_pub') {
  450. $pub_id = chado_get_id_for_node('pub', $node->nid);
  451. tripal_pub_set_pub_url($node, $pub_id);
  452. }
  453. }
  454. /**
  455. * Implementation of hook_form_alter()
  456. *
  457. * @param $form
  458. * @param $form_state
  459. * @param $form_id
  460. */
  461. function tripal_pub_form_alter(&$form, &$form_state, $form_id) {
  462. // turn of preview button for insert/updates
  463. if ($form_id == "chado_pub_node_form") {
  464. $form['actions']['preview']['#access'] = FALSE;
  465. }
  466. if ($form_id == "tripal_pub_importer_setup_form") {
  467. /* // updating the form through the ahah callback sets the action of
  468. // the form to the ahah callback URL. We need to set it back
  469. // to the normal form URL
  470. if (array_key_exists('values', $form_state) and $form_state['values']['action'] == 'edit') {
  471. $form['#action'] = url("admin/tripal/chado/tripal_pub/import/edit/" . $form_state['values']['pub_import_id']);
  472. }
  473. if (array_key_exists('values', $form_state) and $form_state['values']['action'] == 'new') {
  474. $form['#action'] = url("admin/tripal/chado/tripal_pub/import/new");
  475. }
  476. */
  477. }
  478. if ($form_id == "tripal_pub_search_form") {
  479. $form['#action'] = url("find/publications");
  480. }
  481. if ($form_id == "chado_pub_node_form") {
  482. }
  483. }
  484. /**
  485. *
  486. * @param $callback
  487. * @param $args
  488. */
  489. function tripal_pub_job_describe_args($callback, $args) {
  490. $new_args = array();
  491. if ($callback == 'tripal_pub_import_publications_by_import_id') {
  492. // get all of the loaders
  493. $qargs = array(':import_id' => $args[0]);
  494. $sql = "SELECT * FROM {tripal_pub_import} WHERE pub_import_id = :import_id ";
  495. $import = db_query($sql, $qargs)->fetchObject();
  496. $new_args['Importer'] = $import->name;
  497. }
  498. return $new_args;
  499. }