You are here

function taxonomy_manager_autocomplete_load in Taxonomy Manager 6

Same name and namespace in other branches
  1. 6.2 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 1434

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(db_rewrite_sql("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%%'))", 't', 'tid'), $vid, $last_string, $last_string, 0, 10);
    $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);
}