cobalttaxonomy.module 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. function cobalttaxonomy_init() {
  3. if (user_access('use cobalt')) {
  4. drupal_add_js(drupal_get_path('module', 'cobalt') . '/js/cobalt.taxonomy.js');
  5. }
  6. }
  7. function cobalttaxonomy_menu() {
  8. $items = array();
  9. $items['cobalt/data/taxonomy_json'] = array(
  10. 'title' => 'Serialized taxonomies',
  11. 'page callback' => 'cobalttaxonomy_json',
  12. 'page arguments' => array('update', 3),
  13. 'access arguments' => array('use cobalt'),
  14. 'type' => MENU_CALLBACK,
  15. );
  16. return $items;
  17. }
  18. function cobalttaxonomy_json($op, $value) {
  19. global $user;
  20. $vocabularies = taxonomy_get_vocabularies();
  21. $voc_data = array();
  22. foreach ($vocabularies as $vocabulary) {
  23. $voc_data[$vocabulary->vid] = $vocabulary->name;
  24. }
  25. $term_tree = array();
  26. foreach ($vocabularies as $vocabulary) {
  27. $term_tree += taxonomy_get_tree($vocabulary->vid);
  28. }
  29. $term_data = array();
  30. foreach ($term_tree as $term) {
  31. $term_data[$term->tid] = array($term->name, $term->vid);
  32. }
  33. $data = array('vocabularies' => $voc_data, 'terms' => $term_data, 'access' => user_access('administer taxonomy'));
  34. print drupal_json_output($data);
  35. exit;
  36. }