You are here

function taxonomy_manager_autocomplete_load in Taxonomy Manager 6.2

Same name and namespace in other branches
  1. 6 taxonomy_manager.admin.inc \taxonomy_manager_autocomplete_load()
  2. 7 taxonomy_manager.admin.inc \taxonomy_manager_autocomplete_load()

Retrieve a pipe delimited string of autocomplete suggestions (+synonyms)

1 string reference to 'taxonomy_manager_autocomplete_load'
taxonomy_manager_menu in ./taxonomy_manager.module
Implementation of hook_menu

File

./taxonomy_manager.admin.inc, line 2452
Taxonomy Manager Admin

Code

function taxonomy_manager_autocomplete_load($vid, $string = '') {

  // The user enters a comma-separated list of tags. We only autocomplete the last tag.
  $array = drupal_explode_tags($string);

  // Fetch last tag
  $last_string = trim(array_pop($array));
  $matches = array();
  if ($last_string != '') {
    $result = db_query_range("SELECT t.name FROM {term_data} t\n      LEFT JOIN {term_synonym} s ON t.tid = s.tid\n      WHERE t.vid = %d\n      AND (LOWER(t.name) LIKE LOWER('%%%s%%') OR LOWER(s.name) LIKE LOWER('%%%s%%'))", $vid, $last_string, $last_string, 0, 30);
    $prefix = count($array) ? '"' . implode('", "', $array) . '", ' : '';
    while ($tag = db_fetch_object($result)) {
      $n = $tag->name;

      // Commas and quotes in terms are special cases, so encode 'em.
      if (strpos($tag->name, ',') !== FALSE || strpos($tag->name, '"') !== FALSE) {
        $n = '"' . str_replace('"', '""', $tag->name) . '"';
      }
      $matches[$prefix . $n] = check_plain($tag->name);
    }
  }
  drupal_json($matches);
}