Code coverage for /20081101/modules/taxonomy/taxonomy.pages.inc

Line #Times calledCode
1
<?php
2
// $Id: taxonomy.pages.inc,v 1.18 2008/10/13 00:33:05 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
 */
124
function taxonomy_term_page($terms, $depth = 0, $op = 'page') {
131
  if ($terms['operator'] != 'and' && $terms['operator'] != 'or') {
140
    drupal_not_found();
150
  }
161
  $str_tids = $terms['str_tids'];
17
181
  if ($terms['tids']) {
191
    $result = db_query(db_rewrite_sql('SELECT t.tid, t.name FROM
{term_data} t WHERE t.tid IN (' . db_placeholders($terms['tids']) . ')',
't', 'tid'), $terms['tids']);
201
    $tids = array(); // we rebuild the $tids-array so it only contains
terms the user has access to.
211
    $names = array();
221
    while ($term = db_fetch_object($result)) {
231
      $tids[] = $term->tid;
241
      $names[] = $term->name;
251
    }
26
271
    if ($names) {
281
      $title = check_plain(implode(', ', $names));
291
      drupal_set_title($title);
30
31
      switch ($op) {
321
        case 'page':
33
          // Build breadcrumb based on first hierarchy of first term:
341
          $current->tid = $tids[0];
351
          $breadcrumb = array();
361
          while ($parents = taxonomy_get_parents($current->tid)) {
370
            $current = array_shift($parents);
380
            $breadcrumb[] = l($current->name,
taxonomy_term_path($current));
390
          }
401
          $breadcrumb[] = l(t('Home'), NULL);
411
          $breadcrumb = array_reverse($breadcrumb);
421
          drupal_set_breadcrumb($breadcrumb);
43
441
          $output = theme('taxonomy_term_page', $tids,
taxonomy_select_nodes($tids, $terms['operator'], $depth, TRUE));
451
          drupal_add_feed(url('taxonomy/term/' . $str_tids . '/' . $depth .
'/feed'), 'RSS - ' . $title);
461
          return $output;
470
          break;
48
490
        case 'feed':
500
          $channel['link'] = url('taxonomy/term/' . $str_tids . '/' .
$depth, array('absolute' => TRUE));
510
          $channel['title'] = variable_get('site_name', 'Drupal') . ' - ' .
$title;
52
          // Only display the description if we have a single term, to
avoid clutter and confusion.
530
          if (count($tids) == 1) {
540
            $term = taxonomy_term_load($tids[0]);
55
            // HTML will be removed from feed description, so no need to
filter here.
560
            $channel['description'] = $term->description;
570
          }
58
590
          $result = taxonomy_select_nodes($tids, $terms['operator'],
$depth, FALSE);
600
          $items = array();
610
          while ($row = db_fetch_object($result)) {
620
            $items[] = $row->nid;
630
          }
64
650
          node_feed($items, $channel);
660
          break;
67
680
        default:
690
          drupal_not_found();
700
      }
710
    }
72
    else {
730
      drupal_not_found();
74
    }
750
  }
760
}
77
78
/**
79
 * Render a taxonomy term page HTML output.
80
 *
81
 * @param $tids
82
 *   An array of term ids.
83
 * @param $result
84
 *   A pager_query() result, such as that performed by
taxonomy_select_nodes().
85
 *
86
 * @ingroup themeable
87
 */
884
function theme_taxonomy_term_page($tids, $result) {
891
  drupal_add_css(drupal_get_path('module', 'taxonomy') . '/taxonomy.css');
901
  $output = '';
91
92
  // Only display the description if we have a single term, to avoid
clutter and confusion.
931
  if (count($tids) == 1) {
941
    $term = taxonomy_term_load($tids[0]);
951
    $description = $term->description;
96
97
    // Check that a description is set.
981
    if (!empty($description)) {
991
      $output .= '<div class="taxonomy-term-description">';
1001
      $output .= filter_xss_admin($description);
1011
      $output .= '</div>';
1021
    }
1031
  }
104
1051
  $output .= taxonomy_render_nodes($result);
106
1071
  return $output;
1080
}
109
110
/**
111
 * Page to edit a vocabulary term.
112
 */
1134
function taxonomy_term_edit($term) {
1143
  if (isset($term)) {
1153
    drupal_set_title($term->name);
1163
    return drupal_get_form('taxonomy_form_term',
taxonomy_vocabulary_load($term->vid), (array)$term);
1170
  }
1180
  return drupal_not_found();
1190
}
120
121
/**
122
 * Helper function for autocompletion
123
 */
1244
function taxonomy_autocomplete($vid, $string = '') {
125
  // The user enters a comma-separated list of tags. We only autocomplete
the last tag.
1260
  $array = drupal_explode_tags($string);
127
128
  // Fetch last tag
1290
  $last_string = trim(array_pop($array));
1300
  $matches = array();
1310
  if ($last_string != '') {
1320
    $result = db_query_range(db_rewrite_sql("SELECT t.tid, t.name FROM
{term_data} t WHERE t.vid = :vid AND LOWER(t.name) LIKE
LOWER(:last_string)", 't', 'tid'), array(
1330
      ':vid' => $vid,
1340
      ':last_string' => '%'. $last_string .'%',
1350
    ), 0, 10);
136
1370
    $prefix = count($array) ? implode(', ', $array) . ', ' : '';
138
1390
    while ($tag = db_fetch_object($result)) {
1400
      $n = $tag->name;
141
      // Commas and quotes in terms are special cases, so encode 'em.
1420
      if (strpos($tag->name, ',') !== FALSE || strpos($tag->name, '"') !==
FALSE) {
1430
        $n = '"' . str_replace('"', '""', $tag->name) . '"';
1440
      }
1450
      $matches[$prefix . $n] = check_plain($tag->name);
1460
    }
1470
  }
148
1490
  drupal_json($matches);
1500
}
1514