You are here

function fast_404_validate_path_drupal in Fast 404 7

Same name and namespace in other branches
  1. 6 fast_404.inc \fast_404_validate_path_drupal()

Check to see if a path works using Drupal MySQL functions.

Return value

bool

1 call to fast_404_validate_path_drupal()
fast_404_path_check in ./fast_404.inc
Check a Drupal path to see if it really exists and load a fast 404 if not.

File

./fast_404.inc, line 119

Code

function fast_404_validate_path_drupal() {
  $query = $_GET['q'];

  // Check if redirect module is installed.
  if (db_query("SELECT name FROM {system} WHERE type = 'module' AND status = 1 AND name = 'redirect'")
    ->fetchField()) {

    // Check if path exits in redirect table.
    if (db_query("SELECT rid FROM {redirect} WHERE :path = source", array(
      ':path' => $query,
    ))
      ->fetchField()) {
      return TRUE;
    }
  }

  // Act only when locale is enabled.
  // TODO: Need to actually check if url negotiator is enabled.
  if (db_query("SELECT status FROM {system} WHERE type = 'module' AND name = 'locale' AND status = 1")
    ->fetchField()) {
    $prefixes = db_query("SELECT prefix FROM {languages} WHERE enabled = 1 AND prefix != ''");
    $lang_prefixes = $prefixes
      ->fetchCol();
    $path_parts = explode('/', $query);
    if (in_array($path_parts[0], $lang_prefixes)) {
      if (count($path_parts) == 1) {
        return TRUE;
      }
      $query = substr($query, strlen($path_parts[0]) + 1);
    }
  }
  $sql = "SELECT path FROM {menu_router} WHERE :path LIKE CONCAT(path, '%')";
  $res = db_query($sql, array(
    ':path' => $query,
  ))
    ->fetchField();
  if ($res) {
    return TRUE;
  }
  else {
    $res = db_query("SELECT pid FROM {url_alias} WHERE alias = :alias", array(
      ':alias' => $query,
    ))
      ->fetchField();
    return $res == 0 ? FALSE : TRUE;
  }
  return FALSE;
}