function fast_404_ext_check in Fast 404 7
Same name and namespace in other branches
- 6 fast_404.inc \fast_404_ext_check()
1 call to fast_404_ext_check()
- fast_404_boot in ./
fast_404.module - Implements hook_boot().
File
- ./
fast_404.inc, line 3
Code
function fast_404_ext_check() {
// Check to see if Fast 404 checks are disabled.
if (!variable_get('fast_404_extension_check', TRUE)) {
return TRUE;
}
// Ignores if the current script is running in a command-line environment.
if (drupal_is_cli()) {
return TRUE;
}
// Determine the request uri. We are only interested in the path component,
// so strip out any other information. Since parse_url() is does not work well
// with relative URLs, we temporarily prepend a dummy scheme and domain name.
$uri = request_uri();
$path = parse_url('http://example.com' . $uri, PHP_URL_PATH);
// Ignore calls to the homepage, to avoid unnecessary processing.
if ($path == '/') {
return TRUE;
}
// Check to see if the URL is an imagecache URL, those are handled via
// Drupal.
if (strpos($path, 'styles/')) {
// Check to see if we will allow anon users to access this page.
if (!variable_get('fast_404_allow_anon_imagecache', TRUE)) {
$found_session = FALSE;
// At this stage of the game we don't know if the user is logged in via
// regular function calls. Simply look for a session cookie. If we find
// one we'll assume they're logged in.
foreach ($_COOKIE as $k => $v) {
if (stristr($k, 'SESS')) {
$found_session = TRUE;
break;
}
}
// Found a session. We're going to assume they're logged in.
if ($found_session) {
return TRUE;
}
}
else {
return TRUE;
}
}
// If we are using URL whitelisting then determine if the current URL is
// whitelisted before running the extension check.
if (variable_get('fast_404_url_whitelisting', FALSE)) {
$allowed = variable_get('fast_404_whitelist', array());
if (in_array($path, $allowed)) {
// URL is whitelisted. Assumed good.
return TRUE;
}
}
// Check for whitelisted strings in the URL.
if (is_array(variable_get('fast_404_string_whitelisting', FALSE))) {
foreach (variable_get('fast_404_string_whitelisting', array()) as $str) {
if (strstr($path, $str) !== FALSE) {
return TRUE;
}
}
}
// Load up the blacklisted extensions.
$exts = variable_get('fast_404_exts', '/^(?!robots).*\\.(txt|png|gif|jpe?g|css|js|ico|swf|flv|cgi|bat|pl|dll|exe|asp)$/i');
// Determine if URL is in blacklisted extensions.
if ($exts && preg_match($exts, $path, $m)) {
fast_404_error_return(FALSE, variable_get('fast_404_return_gone', FALSE));
}
define('FAST_404_EXT_CHECKED', TRUE);
}