From 991aefea4a314c492833d235aa6967168c0e434f Mon Sep 17 00:00:00 2001 From: Dayson Pais Date: Mon, 22 Jul 2013 12:32:34 +0530 Subject: [PATCH 1/5] Use relative path for all assets in markup --- index.php | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/index.php b/index.php index ee9354e..c03501b 100644 --- a/index.php +++ b/index.php @@ -81,16 +81,15 @@ if ($homepage && $homepage_url !== '/') { - <?php echo $options['title']; ?> - + - + @@ -105,20 +104,20 @@ if ($homepage && $homepage_url !== '/') { $v) { ?> @: ; - @import "/less/import/daux-base.less"; + @import "less/import/daux-base.less"; - + - + - + - + From db6fa416acb2c075d8fd424197667d3f025b2426 Mon Sep 17 00:00:00 2001 From: Dayson Pais Date: Mon, 22 Jul 2013 12:34:32 +0530 Subject: [PATCH 2/5] Remove RewriteBase definition as its redundant in most use-cases. --- .htaccess | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.htaccess b/.htaccess index cb4e5ca..1239126 100644 --- a/.htaccess +++ b/.htaccess @@ -3,7 +3,7 @@ php_flag display_errors on php_flag html_errors on RewriteEngine On -RewriteBase / +#RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d From caa3c95332fe159f15e16400a60090f0c43e3bc6 Mon Sep 17 00:00:00 2001 From: Dayson Pais Date: Mon, 22 Jul 2013 15:05:56 +0530 Subject: [PATCH 3/5] - Introduced get_uri function which retrieves the URL parts from the clean url. This works across all server configurations and also helps build relative URLs support - Improvised methodology to check if homepage - Introduced the $base_url variable which holds the base URL of the daux. Can be used in index.php to make URLs relative --- libs/functions.php | 84 ++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 77 insertions(+), 7 deletions(-) diff --git a/libs/functions.php b/libs/functions.php index 0283e0f..6c88c15 100644 --- a/libs/functions.php +++ b/libs/functions.php @@ -16,11 +16,15 @@ error_reporting(E_ALL); require_once('libs/markdown_extended.php'); // Check for homepage -$path = url_path(); -if ($path === '/' || $path === '') { - $homepage = true; -} else { - $homepage = false; +$homepage = (get_uri(false) === "") ? true : false; + +// Stores the base url under which daux is running +$base_url = '/'; + +// Set the base url of where the script is located +if (isset($_SERVER['SCRIPT_NAME'])) +{ + $base_url = substr($_SERVER['SCRIPT_NAME'], 0, strrpos($_SERVER['SCRIPT_NAME'] , '/')); // find the full URL to this application from server root } // Daux.io Functions @@ -136,7 +140,7 @@ function url_path() { } function url_params() { - $url = url_path(); + $url = get_uri(); $params = explode('/', trim($url, '/')); return $params; } @@ -261,4 +265,70 @@ function get_tree($path = '.', $clean_path = '', $title = ''){ return $tree; } -?> \ No newline at end of file + +/** + * Get's the current "pretty" URI from the URL. It will also correct the QUERY_STRING server var and the $_GET array. + * It supports all forms of mod_rewrite and the following forms of URL: + * + * http://example.com/index.php/foo (returns '/foo') + * http://example.com/index.php?/foo (returns '/foo') + * http://example.com/index.php/foo?baz=bar (returns '/foo') + * http://example.com/index.php?/foo?baz=bar (returns '/foo') + * + * Similarly using mod_rewrite to remove index.php: + * http://example.com/foo (returns '/foo') + * http://example.com/foo?baz=bar (returns '/foo') + * + * @author Dan Horrigan + * @copyright Dan Horrigan + * @license MIT License + * @param bool $prefix_slash whether to return the uri with a '/' in front + * @return string the uri + */ +function get_uri($prefix_slash = true) +{ + if (isset($_SERVER['PATH_INFO'])) + { + $uri = $_SERVER['PATH_INFO']; + } + elseif (isset($_SERVER['REQUEST_URI'])) + { + $uri = $_SERVER['REQUEST_URI']; + if (strpos($uri, $_SERVER['SCRIPT_NAME']) === 0) + { + $uri = substr($uri, strlen($_SERVER['SCRIPT_NAME'])); + } + elseif (strpos($uri, dirname($_SERVER['SCRIPT_NAME'])) === 0) + { + $uri = substr($uri, strlen(dirname($_SERVER['SCRIPT_NAME']))); + } + + // This section ensures that even on servers that require the URI to be in the query string (Nginx) a correct + // URI is found, and also fixes the QUERY_STRING server var and $_GET array. + 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 + { + // Couldn't determine the URI, so just return false + return false; + } + + // Do some final cleaning of the URI and return it + return ($prefix_slash ? '/' : '').str_replace(array('//', '../'), '/', trim($uri, '/')); +} \ No newline at end of file From 746b28d261f0e5d952c805c1160423ec5f5b9775 Mon Sep 17 00:00:00 2001 From: Dayson Pais Date: Mon, 22 Jul 2013 15:06:44 +0530 Subject: [PATCH 4/5] Converted all URLs to be truly relative using the $base_url variable to render all URLs. --- index.php | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/index.php b/index.php index c03501b..dcee4d6 100644 --- a/index.php +++ b/index.php @@ -66,7 +66,7 @@ software, even if advised of the possibility of such damage. require_once('libs/functions.php'); $options = get_options(); -$tree = get_tree("docs"); +$tree = get_tree("docs", $base_url); $homepage_url = homepage_url($tree); $docs_url = docs_url($tree); @@ -87,9 +87,9 @@ if ($homepage && $homepage_url !== '/') { - + img/favicon.png" type="image/x-icon"> - + @@ -104,20 +104,20 @@ if ($homepage && $homepage_url !== '/') { $v) { ?> @: ; - @import "less/import/daux-base.less"; + @import "/less/import/daux-base.less"; - + - + - + - + @@ -128,7 +128,7 @@ if ($homepage && $homepage_url !== '/') {