/[drupal]/drupal/modules/taxonomy/taxonomy.pages.inc
ViewVC logotype

Contents of /drupal/modules/taxonomy/taxonomy.pages.inc

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.44 - (show annotations) (download) (as text)
Sat Nov 7 14:18:07 2009 UTC (2 weeks, 5 days ago) by webchick
Branch: MAIN
CVS Tags: DRUPAL-7-0-UNSTABLE-10
Changes since 1.43: +9 -11 lines
File MIME type: text/x-php
#625460 by sun: Add input format to taxonomy term descriptions.
1 <?php
2 // $Id: taxonomy.pages.inc,v 1.43 2009/10/24 05:13:44 webchick Exp $
3
4 /**
5 * @file
6 * Page callbacks for the taxonomy module.
7 */
8
9 /**
10 * Menu callback; displays all nodes associated with a term.
11 *
12 * @param $term
13 * The taxonomy term.
14 * @return
15 * The page content.
16 */
17 function taxonomy_term_page($term) {
18 // Build breadcrumb based on the hierarchy of the term.
19 $current = (object) array(
20 'tid' => $term->tid,
21 );
22 $breadcrumb = array();
23 while ($parents = taxonomy_get_parents($current->tid)) {
24 $current = array_shift($parents);
25 $breadcrumb[] = l($current->name, 'taxonomy/term/' . $current->tid);
26 }
27 $breadcrumb[] = l(t('Home'), NULL);
28 $breadcrumb = array_reverse($breadcrumb);
29 drupal_set_breadcrumb($breadcrumb);
30 drupal_add_feed(url('taxonomy/term/' . $term->tid . '/feed'), 'RSS - ' . $term->name);
31 drupal_add_css(drupal_get_path('module', 'taxonomy') . '/taxonomy.css');
32
33 field_attach_prepare_view('taxonomy_term', array($term->tid => $term), 'full');
34 $build = array();
35 $build += field_attach_view('taxonomy_term', $term);
36 $build['term_description'] = array(
37 '#markup' => check_markup($term->description, $term->format, '', TRUE),
38 '#weight' => -1,
39 '#prefix' => '<div class="taxonomy-term-description">',
40 '#suffix' => '</div>',
41 );
42 if ($nids = taxonomy_select_nodes($term->tid, TRUE, variable_get('default_nodes_main', 10))) {
43 $nodes = node_load_multiple($nids);
44 $build += node_build_multiple($nodes);
45 $build['pager'] = array(
46 '#markup' => theme('pager', array('tags' => NULL)),
47 '#weight' => 5,
48 );
49 }
50 else {
51 $build['no_content'] = array(
52 '#prefix' => '<p>',
53 '#markup' => t('There are currently no posts in this category.'),
54 '#suffix' => '</p>',
55 );
56 }
57 return $build;
58 }
59
60 /**
61 * Generate the content feed for a taxonomy term.
62 *
63 * @param $term
64 * The taxonomy term.
65 */
66 function taxonomy_term_feed($term) {
67 $channel['link'] = url('taxonomy/term/' . $term->tid, array('absolute' => TRUE));
68 $channel['title'] = variable_get('site_name', 'Drupal') . ' - ' . $term->name;
69 // Only display the description if we have a single term, to avoid clutter and confusion.
70 // HTML will be removed from feed description.
71 $channel['description'] = check_markup($term->description, $term->format, '', TRUE);
72 $nids = taxonomy_select_nodes($term->tid, FALSE, variable_get('feed_default_items', 10));
73
74 node_feed($nids, $channel);
75 }
76
77 /**
78 * Helper function for autocompletion
79 */
80 function taxonomy_autocomplete($field_name, $bundle, $tags_typed = '') {
81 $instance = field_info_instance($field_name, $bundle);
82 $field = field_info_field($field_name);
83
84 // The user enters a comma-separated list of tags. We only autocomplete the last tag.
85 $tags_typed = drupal_explode_tags($tags_typed);
86 $tag_last = drupal_strtolower(array_pop($tags_typed));
87
88 $matches = array();
89 if ($tag_last != '') {
90
91 // Part of the criteria for the query come from the field's own settings.
92 $vids = array();
93 foreach ($field['settings']['allowed_values'] as $tree) {
94 $vids[] = $tree['vid'];
95 }
96
97 $query = db_select('taxonomy_term_data', 't');
98 $query->addTag('translatable');
99 $query->addTag('term_access');
100
101 // Do not select already entered terms.
102 if (!empty($tags_typed)) {
103 $query->condition('t.name', $tags_typed, 'NOT IN');
104 }
105 $tags_return = $query
106 ->fields('t', array('tid', 'name'))
107 ->condition('t.vid', $vids)
108 // Select rows that match by term name.
109 ->condition(db_or()
110 ->where("t.name LIKE :last_string", array(':last_string' => '%' . $tag_last . '%'))
111 )
112 ->range(0, 10)
113 ->execute()
114 ->fetchAllKeyed();
115
116 $prefix = count($tags_typed) ? implode(', ', $tags_typed) . ', ' : '';
117
118 $term_matches = array();
119 foreach ($tags_return as $tid => $name) {
120 $n = $name;
121 // Term names containing commas or quotes must be wrapped in quotes.
122 if (strpos($name, ',') !== FALSE || strpos($name, '"') !== FALSE) {
123 $n = '"' . str_replace('"', '""', $name) . '"';
124 }
125 else {
126 $term_matches[$prefix . $n] = filter_xss($name);
127 }
128 }
129 }
130
131 drupal_json_output($term_matches);
132 }

  ViewVC Help
Powered by ViewVC 1.1.2