You are here

function path_redirect_js_autocomplete_404 in Path redirect 6

Autocompletion callback for the add/edit redirect form. Returns a list of current 404s on the site.

1 string reference to 'path_redirect_js_autocomplete_404'
path_redirect_menu in ./path_redirect.module
Implements hook_menu().

File

./path_redirect.admin.inc, line 546
Administrative page callbacks for the path_redirect module.

Code

function path_redirect_js_autocomplete_404() {
  $args = func_get_args();
  $string = drupal_strtolower(implode('/', $args));
  $matches = array();

  // Get a list of 404s, sorted by the number of times each 404 was processed.
  $paths = db_query("SELECT message, COUNT(message) AS count FROM {watchdog} WHERE type = 'page not found' AND LOWER(message) LIKE '%%%s%%' GROUP BY message ORDER BY count DESC", drupal_strtolower($string));
  while ($path = db_result($paths)) {

    // If the 404 is now a valid path or already has a redirect, discard it.
    if (!menu_get_item($path) && !path_redirect_load_by_source($path)) {
      $matches[$path] = check_plain($path);
    }
  }

  // Limit the output to 10 results and return the JSON.
  $matches = array_slice($matches, 0, 10);
  drupal_json($matches);
}