PageRenderTime 75ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 0ms

/trunk/Drupal/modules/taxonomy/taxonomy.pages.inc

http://goldcat.googlecode.com/
Pascal | 127 lines | 58 code | 12 blank | 57 comment | 6 complexity | 90dc821a862c6075d1595ff77e9108ae MD5 | raw file
Possible License(s): AGPL-3.0, AGPL-1.0, BSD-3-Clause
  1. <?php
  2. /**
  3. * @file
  4. * Page callbacks for the taxonomy module.
  5. */
  6. /**
  7. * Menu callback; displays all nodes associated with a term.
  8. *
  9. * @param $term
  10. * The taxonomy term.
  11. * @return
  12. * The page content.
  13. */
  14. function taxonomy_term_page($term) {
  15. // Build breadcrumb based on the hierarchy of the term.
  16. $current = (object) array(
  17. 'tid' => $term->tid,
  18. );
  19. // @todo This overrides any other possible breadcrumb and is a pure hard-coded
  20. // presumption. Make this behavior configurable per vocabulary or term.
  21. $breadcrumb = array();
  22. while ($parents = taxonomy_get_parents($current->tid)) {
  23. $current = array_shift($parents);
  24. $breadcrumb[] = l($current->name, 'taxonomy/term/' . $current->tid);
  25. }
  26. $breadcrumb[] = l(t('Home'), NULL);
  27. $breadcrumb = array_reverse($breadcrumb);
  28. drupal_set_breadcrumb($breadcrumb);
  29. drupal_add_feed('taxonomy/term/' . $term->tid . '/feed', 'RSS - ' . $term->name);
  30. $build = array();
  31. $build['term_heading'] = array(
  32. '#prefix' => '<div class="term-listing-heading">',
  33. '#suffix' => '</div>',
  34. 'term' => taxonomy_term_view($term, 'full'),
  35. );
  36. if ($nids = taxonomy_select_nodes($term->tid, TRUE, variable_get('default_nodes_main', 10))) {
  37. $nodes = node_load_multiple($nids);
  38. $build += node_view_multiple($nodes);
  39. $build['pager'] = array(
  40. '#theme' => 'pager',
  41. '#weight' => 5,
  42. );
  43. }
  44. else {
  45. $build['no_content'] = array(
  46. '#prefix' => '<p>',
  47. '#markup' => t('There is currently no content classified with this term.'),
  48. '#suffix' => '</p>',
  49. );
  50. }
  51. return $build;
  52. }
  53. /**
  54. * Generate the content feed for a taxonomy term.
  55. *
  56. * @param $term
  57. * The taxonomy term.
  58. */
  59. function taxonomy_term_feed($term) {
  60. $channel['link'] = url('taxonomy/term/' . $term->tid, array('absolute' => TRUE));
  61. $channel['title'] = variable_get('site_name', 'Drupal') . ' - ' . $term->name;
  62. // Only display the description if we have a single term, to avoid clutter and confusion.
  63. // HTML will be removed from feed description.
  64. $channel['description'] = check_markup($term->description, $term->format, '', TRUE);
  65. $nids = taxonomy_select_nodes($term->tid, FALSE, variable_get('feed_default_items', 10));
  66. node_feed($nids, $channel);
  67. }
  68. /**
  69. * Helper function for autocompletion
  70. */
  71. function taxonomy_autocomplete($field_name, $tags_typed = '') {
  72. $field = field_info_field($field_name);
  73. // The user enters a comma-separated list of tags. We only autocomplete the last tag.
  74. $tags_typed = drupal_explode_tags($tags_typed);
  75. $tag_last = drupal_strtolower(array_pop($tags_typed));
  76. $matches = array();
  77. if ($tag_last != '') {
  78. // Part of the criteria for the query come from the field's own settings.
  79. $vids = array();
  80. $vocabularies = taxonomy_vocabulary_get_names();
  81. foreach ($field['settings']['allowed_values'] as $tree) {
  82. $vids[] = $vocabularies[$tree['vocabulary']]->vid;
  83. }
  84. $query = db_select('taxonomy_term_data', 't');
  85. $query->addTag('translatable');
  86. $query->addTag('term_access');
  87. // Do not select already entered terms.
  88. if (!empty($tags_typed)) {
  89. $query->condition('t.name', $tags_typed, 'NOT IN');
  90. }
  91. // Select rows that match by term name.
  92. $tags_return = $query
  93. ->fields('t', array('tid', 'name'))
  94. ->condition('t.vid', $vids)
  95. ->condition('t.name', '%' . db_like($tag_last) . '%', 'LIKE')
  96. ->range(0, 10)
  97. ->execute()
  98. ->fetchAllKeyed();
  99. $prefix = count($tags_typed) ? drupal_implode_tags($tags_typed) . ', ' : '';
  100. $term_matches = array();
  101. foreach ($tags_return as $tid => $name) {
  102. $n = $name;
  103. // Term names containing commas or quotes must be wrapped in quotes.
  104. if (strpos($name, ',') !== FALSE || strpos($name, '"') !== FALSE) {
  105. $n = '"' . str_replace('"', '""', $name) . '"';
  106. }
  107. $term_matches[$prefix . $n] = check_plain($name);
  108. }
  109. }
  110. drupal_json_output($term_matches);
  111. }