You are here

function _glossary_get_terms in Glossary 6

Same name and namespace in other branches
  1. 5.2 glossary.module \_glossary_get_terms()
  2. 5 glossary.module \_glossary_get_terms()
  3. 7 glossary.module \_glossary_get_terms()
1 call to _glossary_get_terms()
_glossary_filter_process in ./glossary.module

File

./glossary.module, line 1154
Glossary terms will be automatically marked with links to their descriptions.

Code

function _glossary_get_terms($format) {
  static $got = array();
  $show_all = variable_get('glossary_allow_no_description', FALSE);
  $taxonomy_image_enabled = module_exists('taxonomy_image');
  if (!($terms = $got[$format])) {
    $terms = $synonyms = array();
    $vids = variable_get("glossary_vids_{$format}", 0);
    foreach ($vids as $vid) {
      $synonyms = _glossary_get_synonyms($vid);

      // Get all glossary terms and attach synonyms.
      // Omit terms without a description. those are usually container terms.
      // If multilingual taxonomy is enabled only show terms in current or no language
      if (module_exists('i18ntaxonomy')) {
        global $language;
        $result = db_query(db_rewrite_sql("SELECT t.tid, t.name, t.description, COUNT(tn.nid) as nodes FROM {term_data} t LEFT JOIN {term_node} tn USING(tid) WHERE t.vid=%d AND t.language in ('', '%s') GROUP BY t.tid, t.name, t.description ORDER BY LENGTH(t.name) DESC", 't', 'tid'), $vid, $language->language);
      }
      else {
        $result = db_query(db_rewrite_sql("SELECT t.tid, t.name, t.description, COUNT(tn.nid) as nodes FROM {term_data} t LEFT JOIN {term_node} tn USING(tid) WHERE t.vid=%d GROUP BY t.tid, t.name, t.description ORDER BY LENGTH(t.name) DESC", 't', 'tid'), $vid);
      }
      while ($term = db_fetch_object($result)) {
        if ($term->nodes) {

          // If there were any nodes attached, we need to see if they were unpublished.
          $unpubs = db_result(db_query(db_rewrite_sql("SELECT COUNT(n.nid) FROM {term_node} tn JOIN {node} n USING (nid) WHERE tn.tid=%d AND n.status=0"), $term->tid));
          $term->nodes -= $unpubs;
        }
        if ($term->description || $show_all) {
          $term->synonyms = $synonyms[$term->tid];
          $term->synonyms[] = $term->name;
          $term->vid = $vid;
          $terms[] = $term;
        }
        if ($taxonomy_image_enabled) {
          $term->image = taxonomy_image_display($term->tid);
        }
        else {
          $term->image = NULL;
        }
      }
    }
    $got[$format] = $terms;
  }
  return $terms;
}