function fast_404_validate_path_mysql in Fast 404 6
1 call to fast_404_validate_path_mysql()
File
- ./
fast_404.inc, line 123
Code
function fast_404_validate_path_mysql() {
global $db_url, $db_prefix;
// Handle $db_url if it's either a string or the default element of a $db_url array
$db_conn = !is_array($db_url) ? $db_url : (isset($db_url['default']) ? $db_url['default'] : NULL);
if (!$db_conn) {
return TRUE;
// We can't check this URL here. Return TRUE to let Drupal continue bootstrapping.
}
$sql = "SELECT path FROM menu_router WHERE '%s' LIKE CONCAT(path,'%')";
$sql2 = "SELECT pid FROM url_alias WHERE '%s' LIKE CONCAT(dst,'%')";
$sql3 = "SELECT rid FROM path_redirect WHERE '%s' LIKE source";
$url = parse_url($db_conn);
// Decode url-encoded information in the db connection string
$url['user'] = urldecode($url['user']);
// Test if database url has a password.
$url['pass'] = isset($url['pass']) ? urldecode($url['pass']) : '';
$url['host'] = urldecode($url['host']);
$url['path'] = str_replace('/', '', urldecode($url['path']));
// Query the database via either mysql or mysqli
if (strstr($db_conn, 'mysqli')) {
$conn = mysqli_connect($url['host'], $url['user'], $url['pass'], $url['path'], $url['port']);
//check if path_redirect module is installed
if (mysqli_fetch_row(mysqli_query($conn, "SELECT name FROM system WHERE type = 'module' AND status = 1 AND name = 'path_redirect'"))) {
//check if path exits in path_redirect table
$sql3 = str_replace('%s', mysqli_real_escape_string($conn, $_GET['q']), $sql3);
if (mysqli_fetch_row(mysqli_query($conn, $sql3))) {
return TRUE;
}
}
$sql = str_replace('%s', mysqli_real_escape_string($conn, $_GET['q']), $sql);
$res = mysqli_query($conn, $sql);
$row = mysqli_fetch_row($res);
if (!is_array($row)) {
$sql2 = str_replace('%s', mysqli_real_escape_string($conn, $_GET['q']), $sql2);
$res = mysqli_query($conn, $sql2);
$row = mysqli_fetch_row($res);
return is_array($row) > 0 ? TRUE : FALSE;
}
else {
return TRUE;
}
}
elseif (strstr($db_conn, 'mysql')) {
if (isset($url['port'])) {
$url['host'] = $url['host'] . ':' . $url['port'];
}
$conn = mysql_connect($url['host'], $url['user'], $url['pass']);
mysql_select_db($url['path'], $conn);
//check if path_redirect module is installed
if (mysql_fetch_row(mysql_query("SELECT name FROM system WHERE type = 'module' AND status = 1 AND name = 'path_redirect'", $conn))) {
//check if path exits in path_redirect table
$sql3 = str_replace('%s', mysql_escape_string($_GET['q']), $sql3);
if (mysql_fetch_row(mysql_query($sql3))) {
return TRUE;
}
}
$sql = str_replace('%s', mysql_escape_string($_GET['q']), $sql);
$res = mysql_query($sql);
$row = mysql_fetch_array($res);
if (!is_array($row)) {
$sql2 = str_replace('%s', mysql_escape_string($_GET['q']), $sql2);
$res = mysql_query($sql2);
$row = mysql_fetch_array($res);
return is_array($row) > 0 ? TRUE : FALSE;
}
else {
return TRUE;
}
}
else {
return TRUE;
// We can't check this URL here. Return TRUE to let Drupal continue bootstrapping.
}
return TRUE;
}