You are here

function theme_lexicon_overview_item in Lexicon 6

3 theme calls to theme_lexicon_overview_item()
lexicon_overview in ./lexicon.module
lexicon_search_results in ./lexicon.module
lexicon_term in ./lexicon.module

File

./lexicon.module, line 878
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 theme_lexicon_overview_item($vid, $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, $page_per_letter;
  if (!isset($click_option)) {
    $click_option = variable_get('lexicon_click_option', 0);
    $link_related = variable_get('lexicon_link_related', TRUE);
    $show_detailed = variable_get('lexicon_show_detailed', FALSE);
    $show_edit = variable_get('lexicon_show_edit', TRUE);
    $show_search = variable_get('lexicon_show_search', TRUE);
    $one_way = variable_get('lexicon_link_related_how', FALSE);
    $tax_img_avail = module_exists('taxonomy_image');
    $access_tax = user_access('administer taxonomy');
    $access_search = user_access('search content');
    $page_per_letter = variable_get('lexicon_page_per_letter', FALSE);
  }
  $path = variable_get('lexicon_path_' . $vid, 'lexicon/' . $vid);
  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;

  //Make sure the id of the anchor is a valid one and doe not contain illegal characters or format
  $allowed_chars = '-A-Za-z0-9._:';
  $id = _lexicon_create_valid_id($term->name);
  $output .= '<a id="' . $id . '"></a>';
  if ($show_desc) {
    $output .= str_repeat('--', $term->depth) . filter_xss_admin($term->name);
  }
  else {
    $output .= l($term->name, $path . '/term/' . $term->tid) . ' ';
  }
  if ($show_edit && $access_tax) {
    $output .= ' ' . l(t('edit term'), 'admin/content/taxonomy/edit/term/' . $term->tid, array(
      'attributes' => array(
        'class' => 'lexicon-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' => 'lexicon-search-term',
        'title' => t('search for content using this term'),
      ),
    ));
  }
  $output .= '</dt>';
  if ($show_desc) {
    if ($term->description || $term->synonyms) {
      $output .= '<dd class="depth' . $term->depth . '"><p>' . htmlspecialchars($term->description) . '</p>';
      if ($relations = lexicon_get_related($term->tid, 'name', $one_way)) {
        $output .= "<p><span class=\"lexicon-related\">" . t("See also") . ": ";
        foreach ($relations as $related) {
          if ($link_related) {
            if ($click_option == 1) {
              $fragment = _lexicon_create_valid_id($related->name);
              if ($page_per_letter) {
                $items[] .= l($related->name, $path . '/letter_' . drupal_strtolower(drupal_substr($related->name, 0, 1)), array(
                  'fragment' => $fragment,
                ));
              }
              else {
                $items[] .= l($related->name, $path, array(
                  'fragment' => $fragment,
                ));
              }
            }
            else {
              $items[] .= l($related->name, 'taxonomy/term/' . $related->tid);
            }
          }
          else {
            $items[] .= check_plain($related->name);
          }
        }
        $output .= implode(', ', $items) . "</span></p>\n";
        unset($items);
      }
      if ($term->synonyms) {
        $output .= '<p><span class="lexicon-synonyms">' . t('Synonyms') . ': ' . implode(', ', $term->synonyms) . "</span></p>\n";
      }
      $output .= '</dd>';
    }
    $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="lexicon-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="lexicon-detailed-link">' . l(t('Detailed definition of @term', array(
          '@term' => $term->name,
        )), taxonomy_term_path($term)) . '</div>';
      }
    }
  }
  return decode_entities($output);
}