From 7f1992b749bd265d956ff768460bdae57a5fb019 Mon Sep 17 00:00:00 2001 From: Gautham Warrier Date: Wed, 29 Oct 2014 13:14:20 +0530 Subject: [PATCH] Fix URL resolving errors. Also fix Grunt task for local server --- libs/daux.php | 18 ++++++++---------- libs/daux_helper.php | 31 ++++++++++++++++++++++++++++++- 2 files changed, 38 insertions(+), 11 deletions(-) diff --git a/libs/daux.php b/libs/daux.php index f07fe8b..305d6dd 100644 --- a/libs/daux.php +++ b/libs/daux.php @@ -42,8 +42,8 @@ public function handle_request($url, $query = array()) { if ($this->error) return $this->error_page; - if (!$this->params['clean_urls']) $this->params['base_page'] .= 'index.php?request='; - $request = DauxHelper::get_request_from_url($url, $this->base_url); + if (!$this->params['clean_urls']) $this->params['base_page'] .= 'index.php/'; + $request = DauxHelper::get_request(); $request = urldecode($request); $request_type = isset($query['method']) ? $query['method'] : ''; switch ($request_type) { @@ -74,12 +74,10 @@ } $this->mode = Daux::LIVE_MODE; $this->host = $_SERVER['HTTP_HOST']; - //Fixes for pages within pages - //$this->base_url = $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']; - $this->base_url = $_SERVER['HTTP_HOST']; - //$this->base_url = substr($this->base_url, 0, strrpos($this->base_url, '/')); - //adding this replace, which replaces the /index.php with nothing seems to resolve the issue with serving static content - $this->base_url = str_replace("/index.php", "", $this->base_url); + $this->base_url = $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']); + $t = strrpos($this->base_url, '/index.php'); + if ($t != FALSE) $this->base_url = substr($this->base_url, 0, $t); + if (substr($this->base_url, -1) !== '/') $this->base_url .= '/'; } private function load_global_config($global_config_file) { @@ -206,7 +204,7 @@ $params['index_key'] = 'index'; $params['docs_path'] = $this->docs_path; $protocol = '//'; - $params['base_url'] = $protocol . $this->base_url . '/'; + $params['base_url'] = $protocol . $this->base_url; $params['base_page'] = $params['base_url']; $params['host'] = $this->host; $params['tree'] = $this->tree; @@ -236,7 +234,7 @@ $params['docs_path'] = $this->docs_path; $params['index_key'] = 'index'; $protocol = '//'; - $params['base_url'] = $protocol . $this->base_url . '/'; + $params['base_url'] = $protocol . $this->base_url; $params['base_page'] = $params['base_url']; $params['host'] = $this->host; $params['tree'] = $this->tree; diff --git a/libs/daux_helper.php b/libs/daux_helper.php index 7a941b8..c330832 100644 --- a/libs/daux_helper.php +++ b/libs/daux_helper.php @@ -59,8 +59,10 @@ return static::directory_tree_builder($dir, $ignore, $mode); } + + //Depreciated public static function get_request_from_url($url, $base_url) { - $url = substr($url, strlen($base_url) + 1); + $url = substr($url, strlen($base_url)); if (strpos($url, 'index.php') === 0) { $request = (($i = strpos($url, 'request=')) !== false) ? $request = substr($url, $i + 8) : ''; if ($end = strpos($request, '&')) $request = substr($request, 0, $end); @@ -72,6 +74,33 @@ return $request; } + + + public static function get_request($prefix_slash = false) + { + if (isset($_SERVER['PATH_INFO'])) $uri = $_SERVER['PATH_INFO']; + else if (isset($_SERVER['REQUEST_URI'])) { + $uri = $_SERVER['REQUEST_URI']; + if (strpos($uri, $_SERVER['SCRIPT_NAME']) === 0) $uri = substr($uri, strlen($_SERVER['SCRIPT_NAME'])); + else if (strpos($uri, dirname($_SERVER['SCRIPT_NAME'])) === 0) $uri = substr($uri, strlen(dirname($_SERVER['SCRIPT_NAME']))); + if (strncmp($uri, '?/', 2) === 0) $uri = substr($uri, 2); + $parts = preg_split('#\?#i', $uri, 2); + $uri = $parts[0]; + if (isset($parts[1])) { + $_SERVER['QUERY_STRING'] = $parts[1]; + parse_str($_SERVER['QUERY_STRING'], $_GET); + } else { + $_SERVER['QUERY_STRING'] = ''; + $_GET = array(); + } + $uri = parse_url($uri, PHP_URL_PATH); + } + else return false; + $uri = str_replace(array('//', '../'), '/', trim($uri, '/')); + if ($uri == "") $uri = "index"; + return $uri; + } + public static function configure_theme($theme, $base_url, $local_base, $theme_url, $mode = Daux::LIVE_MODE) { $name = static::pathinfo($theme); if (is_file($theme)) {