Here is a patch that adds db_rewrite_sql() to quick results. This will respect the users permissions to acctually access the nodes in quick find results.

/**
 * Autocomplete callback
 *
 * @param mixed $delta
 *    Provides the unqiue ID for the block provided by this module
 * @param string $string
 *    The string to lookup
 */
function node_quick_find_autocomplete($delta = 0, $string = '') {
  $settings = variable_get('node_quick_find_'. $delta, array());

  $matches = array();
  if ($string) {
    $string = drupal_strtolower($string);
    if (empty($settings['node_types'])) {
      $result = db_query_range(db_rewrite_sql('SELECT title FROM {node} WHERE title LIKE "%s%%"', $string), 0, 10);
    }
    else {
      $result = db_query_range(db_rewrite_sql('SELECT title FROM {node} WHERE type IN('. db_placeholders($settings['node_types'], 'varchar') .') AND title LIKE "%s%%"', array_merge($settings['node_types'], array($string))), 0, 10);
    }
    while ($node = db_fetch_object($result)) {
      $matches[$node->title] = check_plain($node->title);
    }
  }
  print drupal_to_js($matches);
  exit();
}

Comments

derjochenmeyer’s picture

StatusFileSize
new1.18 KB

Patch above does not work! I didnt test the patch above before posting it. Here is a tested version that works on my installation (lots of permissions with Content Access Module).

/**
 * Autocomplete callback
 *
 * @param mixed $delta
 *    Provides the unqiue ID for the block provided by this module
 * @param string $string
 *    The string to lookup
 */
function node_quick_find_autocomplete($delta = 0, $string = '') {
  $settings = variable_get('node_quick_find_'. $delta, array());

  $matches = array();
  if ($string) {
    $string = drupal_strtolower($string);
    if (empty($settings['node_types'])) {
      $db_rewrite_result = db_rewrite_sql('SELECT n.title FROM {node} n WHERE n.title LIKE "%s%%"');
      $result = db_query_range($db_rewrite_result, $string , 0, 10);
    }
    else {
      $db_rewrite_result = db_rewrite_sql('SELECT n.title FROM {node} n WHERE n.type IN('. db_placeholders($settings['node_types'], 'varchar') .') AND n.title LIKE "%s%%"');
      $result = db_query_range($db_rewrite_result, array_merge($settings['node_types'], array($string)) , 0, 10);
    }
    while ($node = db_fetch_object($result)) {
      $matches[$node->title] = check_plain($node->title);
    }
  }
  print drupal_to_js($matches);
  exit();
}
derjochenmeyer’s picture

This patch is identical to the one above but also adds the feature (#415244: search any part of the title (not just beginnig)) to search within any part of the node title.

Apply the patch or replace the function node_quick_find_autocomplete() in function node_quick_find.module

/**
 * Autocomplete callback
 *
 * @param mixed $delta
 *    Provides the unqiue ID for the block provided by this module
 * @param string $string
 *    The string to lookup
 */
function node_quick_find_autocomplete($delta = 0, $string = '') {
  $settings = variable_get('node_quick_find_'. $delta, array());

  $matches = array();
  if ($string) {
    $string = drupal_strtolower($string);
    if (empty($settings['node_types'])) {
      $db_rewrite_result = db_rewrite_sql('SELECT n.title FROM {node} n WHERE n.title LIKE "%%%s%%"');
      $result = db_query_range($db_rewrite_result, $string , 0, 10);
    }
    else {
      $db_rewrite_result = db_rewrite_sql('SELECT n.title FROM {node} n WHERE n.type IN('. db_placeholders($settings['node_types'], 'varchar') .') AND n.title LIKE "%%%s%%"');
      $result = db_query_range($db_rewrite_result, array_merge($settings['node_types'], array($string)) , 0, 10);
    }
    while ($node = db_fetch_object($result)) {
      $matches[$node->title] = check_plain($node->title);
    }
  }
  print drupal_to_js($matches);
  exit();
}
nicholasthompson’s picture

Category: feature » bug
Status: Needs review » Fixed

Fixed in 1.2 as part of the Security Release.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.