You are here

function theme_glossary_overview_item in Glossary 6

Same name and namespace in other branches
  1. 5.2 glossary.module \theme_glossary_overview_item()
  2. 5 glossary.module \theme_glossary_overview_item()
  3. 7 glossary.module \theme_glossary_overview_item()
3 theme calls to theme_glossary_overview_item()
glossary_overview in ./glossary.module
glossary_search_results in ./glossary.module
glossary_term in ./glossary.module

File

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

Code

function theme_glossary_overview_item($term, $show_desc = TRUE, $destination = NULL) {
  global $base_url;
  static $click_option, $link_related, $show_detailed, $one_way, $tax_img_avail, $access_tax, $access_search, $show_edit, $show_search, $format;
  if (!isset($click_option)) {
    $click_option = variable_get('glossary_click_option', 0);
    $link_related = variable_get('glossary_link_related', TRUE);
    $show_detailed = variable_get('glossary_show_detailed', FALSE);
    $show_edit = variable_get('glossary_show_edit', TRUE);
    $show_search = variable_get('glossary_show_search', TRUE);
    $one_way = variable_get('glossary_link_related_how', FALSE);
    $tax_img_avail = module_exists('taxonomy_image');
    $access_tax = user_access('administer taxonomy');
    $access_search = user_access('search content');
    $format = variable_get('glossary_default_filter', FILTER_FORMAT_DEFAULT);
  }
  if ($tax_img_avail && $show_desc) {
    $img = taxonomy_image_display($term->tid);
    if ($img) {
      $obj = taxonomy_image_get_object($term->tid);
      $img = '<a href="' . $obj->url . '">' . $img . '</a>';
    }
  }
  else {
    $img = NULL;
  }
  $output .= '<dt class="depth' . $term->depth . '">' . $img;
  $output .= '<a id="term' . $term->tid . '"></a>';
  if ($show_desc) {
    $output .= str_repeat('--', $term->depth) . filter_xss_admin($term->name);
  }
  else {
    $output .= l($term->name, 'glossary/term/' . $term->tid) . ' ';
  }
  if ($show_edit && $access_tax) {
    $output .= ' ' . l(t('edit term'), 'admin/content/taxonomy/edit/term/' . $term->tid, array(
      'attributes' => array(
        'class' => 'glossary-edit-term',
        'title' => t('edit this term and definition'),
      ),
      'query' => $destination,
    ));
  }
  if ($show_search && $access_search) {
    $output .= l(t('search for term'), 'search/node/"' . $term->name . '"', array(
      'attributes' => array(
        'class' => 'glossary-search-term',
        'title' => t('search for content using this term'),
      ),
    ));
  }
  $output .= '</dt><dd class="depth' . $term->depth . '">';
  if ($show_desc) {
    if ($term->description) {
      $output .= check_markup($term->description, $format);
    }
    if ($relations = glossary_get_related($term->tid, 'name', $one_way)) {
      $output .= '<span class="glossary-related">' . t('See also') . ': ';
      foreach ($relations as $related) {
        $related->name = filter_xss($related->name);
        if ($link_related) {
          if ($click_option == 1) {
            $items[] .= l($related->name, "glossary/{$term->vid}", array(
              'fragment' => "term{$related->tid}",
            ));
          }
          else {
            $items[] .= l($related->name, "glossary/term/{$related->tid}");
          }
        }
        else {
          $items[] .= check_plain($related->name);
        }
      }
      $output .= implode(', ', $items) . "</span>\n";
      unset($items);
    }
    if ($term->synonyms) {
      $output .= '<span class="glossary-synonyms"><strong>' . t('Synonyms') . '</strong>: ';
      $output .= implode(', ', $term->synonyms) . "</span>\n";
    }
    $detailed_exists = db_result(db_query(db_rewrite_sql('SELECT COUNT(t.nid) FROM {term_node} t JOIN {node} n USING (nid) WHERE t.tid=%d AND n.status=1'), $term->tid));
    if ($detailed_exists) {

      // Do we want to show the teasers?
      if ($show_detailed) {
        $output .= '<div class="glossary-detailed">';
        $text = NULL;
        $detailed = db_query(db_rewrite_sql('SELECT t.nid FROM {term_node} t JOIN {node} n USING (nid) WHERE t.tid=%d AND n.status=1'), $term->tid);
        while ($row = db_fetch_array($detailed)) {
          $node = node_load($row['nid']);

          // Format as teaser view with links.
          $text .= node_view($node, TRUE, FALSE, TRUE);
        }
        if ($text) {
          $fieldset = array(
            '#title' => t('Detailed definition of @term', array(
              '@term' => $term->name,
            )),
            '#collapsible' => TRUE,
            '#collapsed' => TRUE,
            '#value' => $text,
          );
          $output .= theme('fieldset', $fieldset);
        }
        $output .= "</div>\n";
      }
      else {
        $output .= '<div class="glossary-detailed-link">' . l(t('Detailed definition of @term', array(
          '@term' => $term->name,
        )), taxonomy_term_path($term)) . '</div>';
      }
    }
  }
  return $output;
}