-
+
Generated by Daux.io
diff --git a/libs/functions.php b/libs/functions.php
index 97a6b30..ab6b437 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
@@ -138,7 +142,7 @@ function url_path() {
}
function url_params() {
- $url = url_path();
+ $url = get_uri();
$params = explode('/', trim($url, '/'));
return $params;
}
@@ -288,4 +292,70 @@ function get_tree($path = '.', $clean_path = '', $title = ''){
return $tree;
}
-?>
+
+/**
+ * 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, '/'));
+}