[ Index ]

PHP Cross Reference of Drupal 6 (yi-drupal)

title

Body

[close]

/modules/taxonomy/ -> taxonomy.pages.inc (source)

   1  <?php
   2  
   3  /**
   4   * @file
   5   * Page callbacks for the taxonomy module.
   6   */
   7  
   8  /**
   9   * Menu callback; displays all nodes associated with a term.
  10   */
  11  function taxonomy_term_page($str_tids = '', $depth = 0, $op = 'page') {
  12    $terms = taxonomy_terms_parse_string($str_tids);
  13    if ($terms['operator'] != 'and' && $terms['operator'] != 'or') {
  14      drupal_not_found();
  15    }
  16  
  17    if ($terms['tids']) {
  18      $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']);
  19      $tids = array(); // we rebuild the $tids-array so it only contains terms the user has access to.
  20      $names = array();
  21      while ($term = db_fetch_object($result)) {
  22        $tids[] = $term->tid;
  23        $names[] = $term->name;
  24      }
  25  
  26      if ($names) {
  27        $title = implode(', ', $names);
  28        drupal_set_title(check_plain($title));
  29  
  30        switch ($op) {
  31          case 'page':
  32            // Build breadcrumb based on first hierarchy of first term:
  33            $current->tid = $tids[0];
  34            $breadcrumb = array();
  35            while ($parents = taxonomy_get_parents($current->tid)) {
  36              $current = array_shift($parents);
  37              $breadcrumb[] = l($current->name, 'taxonomy/term/'. $current->tid);
  38            }
  39            $breadcrumb[] = l(t('Home'), NULL);
  40            $breadcrumb = array_reverse($breadcrumb);
  41            drupal_set_breadcrumb($breadcrumb);
  42  
  43            $output = theme('taxonomy_term_page', $tids, taxonomy_select_nodes($tids, $terms['operator'], $depth, TRUE));
  44            drupal_add_feed(url('taxonomy/term/'. $str_tids .'/'. $depth .'/feed'), 'RSS - '. $title);
  45            return $output;
  46            break;
  47  
  48          case 'feed':
  49            $channel['link'] = url('taxonomy/term/'. $str_tids .'/'. $depth, array('absolute' => TRUE));
  50            $channel['title'] = variable_get('site_name', 'Drupal') .' - '. $title;
  51            // Only display the description if we have a single term, to avoid clutter and confusion.
  52            if (count($tids) == 1) {
  53              $term = taxonomy_get_term($tids[0]);
  54              // HTML will be removed from feed description, so no need to filter here.
  55              $channel['description'] = $term->description;
  56            }
  57  
  58            $result = taxonomy_select_nodes($tids, $terms['operator'], $depth, FALSE);
  59            $items = array(); 
  60            while ($row = db_fetch_object($result)) {
  61              $items[] = $row->nid;
  62            }
  63  
  64            node_feed($items, $channel);
  65            break;
  66  
  67          default:
  68            drupal_not_found();
  69        }
  70      }
  71      else {
  72        drupal_not_found();
  73      }
  74    }
  75  }
  76  
  77  /**
  78   * Render a taxonomy term page HTML output.
  79   *
  80   * @param $tids
  81   *   An array of term ids.
  82   * @param $result
  83   *   A pager_query() result, such as that performed by taxonomy_select_nodes().
  84   *
  85   * @ingroup themeable
  86   */
  87  function theme_taxonomy_term_page($tids, $result) {
  88    drupal_add_css(drupal_get_path('module', 'taxonomy') .'/taxonomy.css');
  89  
  90    $output = '';
  91  
  92    // Only display the description if we have a single term, to avoid clutter and confusion.
  93    if (count($tids) == 1) {
  94      $term = taxonomy_get_term($tids[0]);
  95      $description = $term->description;
  96  
  97      // Check that a description is set.
  98      if (!empty($description)) {
  99        $output .= '<div class="taxonomy-term-description">';
 100        $output .= filter_xss_admin($description);
 101        $output .= '</div>';
 102      }
 103    }
 104  
 105    $output .= taxonomy_render_nodes($result);
 106  
 107    return $output;
 108  }
 109  
 110  /**
 111   * Helper function for autocompletion
 112   */
 113  function taxonomy_autocomplete($vid, $string = '') {
 114    // The user enters a comma-separated list of tags. We only autocomplete the last tag.
 115    $array = drupal_explode_tags($string);
 116  
 117    // Fetch last tag
 118    $last_string = trim(array_pop($array));
 119    $matches = array();
 120    if ($last_string != '') {
 121      $result = db_query_range(db_rewrite_sql("SELECT t.tid, t.name FROM {term_data} t WHERE t.vid = %d AND LOWER(t.name) LIKE LOWER('%%%s%%')", 't', 'tid'), $vid, $last_string, 0, 10);
 122  
 123      $prefix = count($array) ? implode(', ', $array) .', ' : '';
 124  
 125      while ($tag = db_fetch_object($result)) {
 126        $n = $tag->name;
 127        // Commas and quotes in terms are special cases, so encode 'em.
 128        if (strpos($tag->name, ',') !== FALSE || strpos($tag->name, '"') !== FALSE) {
 129          $n = '"'. str_replace('"', '""', $tag->name) .'"';
 130        }
 131        $matches[$prefix . $n] = check_plain($tag->name);
 132      }
 133    }
 134  
 135    drupal_json($matches);
 136  }


Generated: Mon Jul 9 18:01:44 2012 Cross-referenced by PHPXref 0.7