You are here

function _fetch_possible_keywords in Glossify 6.3

Same name and namespace in other branches
  1. 6 glossify.module \_fetch_possible_keywords()

Helper function that fetches the possible keywords for a given configuration and nid.

4 calls to _fetch_possible_keywords()
glossify_nodeapi in ./glossify.module
Implementation of hook_nodeapi().
_glossify_comment_hovertips in ./glossify.module
Helper function to generate hovertips from comment matches.
_glossify_replace_terms_phpdom in ./glossify.module
Uses PHP's built in DOM extension if available. Adapted from http://stackoverflow.com/questions/3151064/find-and-replace-keywords-by-...
_glossify_replace_terms_simplehtmldom in ./glossify.module

File

./glossify.module, line 863

Code

function _fetch_possible_keywords($config_name, $configuration, $nid) {
  $glossify_dict = array();
  static $keyword_lists = array();
  if (isset($keyword_lists[$config_name][$nid])) {
    return $keyword_lists[$config_name][$nid];
  }
  $methods = array();
  if ($configuration['methods']['use_title']) {
    $methods[] = 'title';
  }
  if ($configuration['methods']['use_internal']) {
    $methods[] = 'internal';
  }
  if ($configuration['methods']['use_cck']) {
    $methods[] = 'cck';
  }
  if ($configuration['methods']['use_taxonomy']) {
    $methods[] = 'taxonomy';
  }
  $query = "SELECT g.term, g.nid, g.alternate, g.language, g.method FROM {node} n INNER JOIN {glossify} g ON g.nid = n.nid WHERE n.type IN (" . db_placeholders($configuration['to'], 'varchar') . ") AND g.method IN (" . db_placeholders($methods, 'varchar') . ") AND g.configuration = '%s' AND n.status = 1";
  if ($configuration['language']) {
    $query .= " AND g.language = n.language";
  }
  if (!$configuration['link_self']) {
    $query .= " AND g.nid != %d";
    $q = db_query($query, array_merge($configuration['to'], $methods, (array) $config_name, (array) $nid));
  }
  else {
    $q = db_query($query, array_merge($configuration['to'], $methods, (array) $config_name));
  }
  while ($r = db_fetch_array($q)) {
    if ($configuration['methods']['link_term'] && $r['method'] == 'taxonomy') {
      $term = db_fetch_array(db_query("SELECT tid FROM {term_data} WHERE name = '%s'", $r['term']));
      $glossify_dict[] = array(
        $r['term'],
        drupal_lookup_path('alias', 'taxonomy/term/' . $term['tid'], $r['language']),
      );
    }
    else {
      if (!empty($r['alternate'])) {
        if (is_numeric($r['alternate'])) {
          $glossify_dict[] = array(
            $r['term'],
            drupal_lookup_path('alias', 'node/' . $r['alternate'], $r['language']),
          );
        }
        elseif ($path = drupal_lookup_path('alias', $r['alternate'], $r['language'])) {
          $glossify_dict[] = array(
            $r['term'],
            $path,
          );
        }
        else {
          $glossify_dict[] = array(
            $r['term'],
            $r['alternate'],
          );
        }
      }
      else {
        $glossify_dict[] = array(
          $r['term'],
          drupal_lookup_path('alias', 'node/' . $r['nid'], $r['language']),
        );
      }
    }
  }

  // Add to cache.
  $keyword_lists[$config_name][$nid] = $glossify_dict;
  return $glossify_dict;
}