You are here

function taxonomy_list_show in Taxonomy List 5.2

Same name and namespace in other branches
  1. 5 taxonomy_list.module \taxonomy_list_show()
  2. 6.2 taxonomy_list.module \taxonomy_list_show()
  3. 6 taxonomy_list.module \taxonomy_list_show()
  4. 7 taxonomy_list.module \taxonomy_list_show()

Show the category list

1 string reference to 'taxonomy_list_show'
taxonomy_list_menu in ./taxonomy_list.module
Implementation of hook_menu().

File

./taxonomy_list.module, line 289
List all terms in a vocabulary.

Code

function taxonomy_list_show($str_vids, $max_depth = 'all', $op = NULL, $columns = NULL, $type = NULL) {
  $params = array(
    'max_depth' => 'all',
    'op' => NULL,
    'type' => NULL,
    'columns' => variable_get('taxonomy_list_cell_per_row', 2),
    'format' => variable_get('taxonomy_list_format', 'table'),
    'list_mode' => variable_get('taxonomy_list_list_mode', 0),
  );
  $params = array_merge($params, $_GET);
  unset($params['q']);
  if (isset($params['cols'])) {
    $params['columns'] = $params['cols'];
    unset($params['cols']);
  }
  if (isset($params['depth'])) {
    $params['max_depth'] = $params['depth'];
    unset($params['depth']);
  }
  if (isset($params['mode'])) {
    $params['list_mode'] = $params['mode'];
    unset($params['mode']);
  }
  array_walk($params, 'check_plain');

  //  $params['max_depth'] = $params['max_depth'] == 'all' ? 9999999 : $params['max_depth'];
  if ($params['max_depth'] == 'all') {
    $params['max_depth'] = 9999999;
  }

  // drupal_set_message(print_r($params, true));
  if ($str_vids == 'all') {
    $vocs = taxonomy_get_vocabularies();
    $vids = array();
    foreach ($vocs as $vid => $vocab) {
      $vids[] = $vid;
    }
  }
  else {
    if (preg_match('/^([0-9]+[+ ])+[0-9]+$/', $str_vids)) {

      // The '+' character in a query string may be parsed as ' '.
      $vids = preg_split('/[+ ]/', $str_vids);
    }
    else {
      if (preg_match('/^[0-9]+$/', $str_vids)) {
        $vids = array(
          $str_vids,
        );
      }
    }
  }
  if (count($vids) <= 0) {
    drupal_not_found();
    return;
  }

  // Do we want to list the nodes?
  if ($params['op'] == 'list') {
    return taxonomy_list_nodes_render($vids, $params['max_depth'], $params['type']);
  }
  $vocab_titles = array();
  $total_terms = 0;
  $output = '<div class="taxonomy-list">';
  foreach ($vids as $vid) {
    $vocab = taxonomy_vocabulary_load($vid);
    $vocab_titles[] = $vocab->name;
    $terms = taxonomy_list_get_tree($vid, 0, $params['max_depth']);
    $c = count($terms);
    if ($c <= 0) {

      // This vocab has no term, skip.
      continue;
    }
    $total_terms += $c;
    $output .= theme('taxonomy_list_vocabulary', $vocab, variable_get('taxonomy_list_types', FALSE), count($vids) > 1);
    $output .= theme(array(
      'taxonomy_list_' . $params['format'],
      'taxonomy_list_table',
    ), $terms, $params['columns'], $params['list_mode']);
  }
  $output .= '</div>';

  // class="taxonomy-list"
  if ($total_terms == 0) {
    drupal_not_found();
    return;
  }
  drupal_set_title(implode(variable_get('taxonomy_list_title_separator', ' & '), $vocab_titles));
  $output = theme('taxonomy_list_admin_links', $vids) . $output;
  return $output;
}