Esempio n. 1
0
function doload($dir, $allow_directory = true, $may_execute = true)
{
    if (file_exists($dir)) {
        if (is_file($dir)) {
            load_local_file($dir, EXTENSION, $may_execute);
            return true;
        } elseif (is_dir($dir) && !TRAILING_SLASH && REDIRECT_TRAILING_SLASH) {
            if ($_SERVER['REQUEST_METHOD'] == "POST") {
                load_page("404", 503);
            } else {
                header('Location: ' . URL . '/');
            }
            return true;
        } elseif ($allow_directory && is_dir($dir) && (TRAILING_SLASH || FILENAME == '' || HANDLE_TRAILING_SLASH)) {
            require "defaults.php";
            foreach ($defaults as $default => $execute) {
                # TODO: Optimize this!
                $extension = explode('.', $default);
                $extension = $extension[1];
                if (file_exists("{$dir}/{$default}")) {
                    if ($execute && $may_execute) {
                        load_script_file("{$dir}/{$default}");
                    } else {
                        load_local_file("{$dir}/{$default}", $extension);
                    }
                    return true;
                }
            }
        }
    }
    if (REQUESTED_FILE == "favicon.ico") {
        return serve_favicon();
    }
    return false;
}
Esempio n. 2
0
        }
        // Try one last-ditch attempt to load a default file.
        if ($method_level == 0) {
            load_defaultmethodfile();
        }
        // If the methods class implements a default method, call that and don't fail.
        if ($method_level == 1 && method_exists($method_base, '__default')) {
            $method_name = '__default';
            $method_level++;
        }
        # TODO : This might not fire if the error occurs on the last item;
        // Throw a 404 if the URL doesn't specify a class and method
        if ($method_level < 2) {
            load_page("404", 404);
        } else {
            // Otherwise, call the method in the class
            $result = call_user_func_array(array($method_base, $method_name), $method_arguments);
            if ($result !== false) {
                // This should have Django-like output (HttpResponse, etc.)
                $result->output();
            }
        }
    } elseif (is_file(PATH_PREFIX . '/endpoint.php')) {
        load_script_file(PATH_PREFIX . '/endpoint.php');
    } else {
        ini_set("include_path", PATH_PREFIX . ':' . ini_get("include_path"));
        if (!doload(PATH_PREFIX . '/' . REQUESTED_FILE)) {
            load_page("404", 404);
        }
    }
}