function _lexicon_get_terms in Lexicon 6
Same name and namespace in other branches
- 7 lexicon.module \_lexicon_get_terms()
1 call to _lexicon_get_terms()
- _lexicon_filter_process in ./
lexicon.module - Mark lexicon vocabulary terms in the body text.
File
- ./
lexicon.module, line 1145 - Lexicon is used to create lists of terms and definitions to use on a website and optionally mark them in the content with an indicator.
Code
function _lexicon_get_terms() {
static $got = array();
$show_all = variable_get('lexicon_allow_no_description', FALSE);
$taxonomy_image_enabled = module_exists('taxonomy_image');
if (!$got) {
$terms = array();
$synonyms = array();
$vids = variable_get("lexicon_vids", 0);
foreach ($vids as $vid) {
$synonyms = _lexicon_get_synonyms($vid);
// Get all lexicon 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) {
$term->description = htmlspecialchars($term->description, ENT_QUOTES);
}
if ($term->description || $show_all) {
$term->synonyms = $synonyms[$term->tid];
$term->synonyms[] = filter_xss($term->name);
$term->vid = $vid;
$terms[] = $term;
}
if ($taxonomy_image_enabled) {
$term->image = taxonomy_image_display($term->tid);
}
else {
$term->image = NULL;
}
}
}
$got = $terms;
}
else {
// Use the already loaded terms
$terms = $got;
}
return $terms;
}