You are here

function _lexicon_term_add_info in Lexicon 7

Lexicon function to add extra information to a term object.

3 calls to _lexicon_term_add_info()
lexicon_block_view in ./lexicon.module
Implements hook_block_view().
_lexicon_get_terms in ./lexicon.module
Function that returns all Lexicon terms and synonyms from the Lexicon vocabularies indicated by $vids as used by the input filter.
_lexicon_overview in includes/lexicon.pages.inc
Lexicon overview function that creates all the data end renders the output through the various theme templates.

File

./lexicon.module, line 1093
The Lexicon module is used to create lists of terms and definitions to use on a website and optionally mark those terms in the content of the website.

Code

function _lexicon_term_add_info(&$term, $filter = FALSE) {

  // Check if the info has already been set.
  if (!isset($term->info_added)) {
    global $base_url;
    $destination = drupal_get_destination();
    static $click_option, $link_related, $image_field, $synonyms_field, $page_per_letter, $show_edit, $show_desc, $show_search, $edit_voc, $access_search;
    if (!isset($click_option)) {
      $click_option = variable_get('lexicon_click_option', 0);
      $link_related = variable_get('lexicon_link_related', TRUE);
      $image_field = variable_get('lexicon_image_field_' . $term->vid, '');
      $synonyms_field = variable_get("lexicon_synonyms_field_" . $term->vid, '');
      $page_per_letter = variable_get('lexicon_page_per_letter', FALSE);
      $show_edit = variable_get('lexicon_show_edit', TRUE);
      $show_search = variable_get('lexicon_show_search', TRUE);
      $edit_voc = user_access('edit terms in ' . $term->vid);
      $access_search = user_access('search content');
    }

    // Set the id for the term.
    $term->id = _lexicon_create_valid_id($term->name);

    // Set the safe values of the title and description to prevent XSS.
    $term->safe_name = check_plain($term->name);

    // If this function is called from the filter use "strip_tags" to prevent
    // an infinte loop due to recursive calls and remove all HTML to use the
    // description in the title attribute.
    if ($filter) {
      $term->safe_description = strip_tags($term->description);
    }
    else {
      $term->safe_description = check_markup($term->description, $term->format);
    }

    // If there is an image for the term add the image information to the $term
    // object.
    if ($image_field != '') {
      $image_field_items = field_get_items('taxonomy_term', $term, $image_field);
      if (!empty($image_field_items)) {
        $term->image['uri'] = $image_field_items[0]['uri'];
        $term->image['alt'] = check_plain($image_field_items[0]['alt']);
        $term->image['title'] = check_plain($image_field_items[0]['title']);
      }
    }

    // If there are synonyms add them to the $term object.
    if ($synonyms_field != '') {
      $synonyms_field_items = field_get_items('taxonomy_term', $term, $synonyms_field);
      if (!empty($synonyms_field_items)) {
        foreach ($synonyms_field_items as $item) {
          $term->synonyms[] = $item['safe_value'];
        }
      }
    }
    $path = variable_get('lexicon_path_' . $term->vid, 'lexicon/' . $term->vid);

    // If the Lexicon is spread over separate pages per letter the link must
    // lead to the appropriate page with the correct anchor.
    if ($page_per_letter) {
      $term->link['path'] = $path . '/letter_' . drupal_strtolower(drupal_substr($term->name, 0, 1));
    }
    else {
      $term->link['path'] = $path;
    }
    $term->link['fragment'] = _lexicon_create_valid_id($term->name);

    // If there are related terms add the information of each related term.
    if ($relations = _lexicon_get_related_terms($term)) {
      foreach ($relations as $related) {
        $term->related[$related->tid]['name'] = check_plain($related->name);
        $related_path = variable_get('lexicon_path_' . $related->vid, 'lexicon/' . $related->vid);

        // If the related terms have to be linked add the link information.
        if ($link_related) {
          if ($click_option == 1) {

            // The link has to point to the term on the Lexicon page.
            if ($page_per_letter) {
              $term->related[$related->tid]['link']['path'] = $related_path . '/letter_' . drupal_strtolower(drupal_substr($related->name, 0, 1));
            }
            else {
              $term->related[$related->tid]['link']['path'] = $related_path;
            }
            $term->related[$related->tid]['link']['fragment'] = _lexicon_create_valid_id($related->name);
          }
          else {

            // The link has to point to the page of the term itself.
            $term->related[$related->tid]['link']['path'] = 'taxonomy/term/' . $related->tid;
            $term->related[$related->tid]['link']['fragment'] = '';
          }
        }
      }
    }
    if ($show_edit && $edit_voc) {
      $term->extralinks['edit term']['name'] = t('edit term');
      $term->extralinks['edit term']['path'] = 'taxonomy/term/' . $term->tid . '/edit';
      $term->extralinks['edit term']['attributes'] = array(
        'class' => 'lexicon-edit-term',
        'title' => t('edit this term and definition'),
        'query' => $destination,
      );
    }
    if ($show_search && $access_search) {
      $term->extralinks['search for term']['name'] = t('search for term');
      $term->extralinks['search for term']['path'] = 'search/node/' . $term->name;
      $term->extralinks['search for term']['attributes'] = array(
        'class' => 'lexicon-search-term',
        'title' => t('search for content using this term'),
        'query' => $destination,
      );
    }
    $term->info_added = TRUE;
  }
  return $term;
}