- 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
This commit is contained in:
parent
db6fa416ac
commit
caa3c95332
@ -16,11 +16,15 @@ error_reporting(E_ALL);
|
|||||||
require_once('libs/markdown_extended.php');
|
require_once('libs/markdown_extended.php');
|
||||||
|
|
||||||
// Check for homepage
|
// Check for homepage
|
||||||
$path = url_path();
|
$homepage = (get_uri(false) === "") ? true : false;
|
||||||
if ($path === '/' || $path === '') {
|
|
||||||
$homepage = true;
|
// Stores the base url under which daux is running
|
||||||
} else {
|
$base_url = '/';
|
||||||
$homepage = false;
|
|
||||||
|
// 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
|
// Daux.io Functions
|
||||||
@ -136,7 +140,7 @@ function url_path() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function url_params() {
|
function url_params() {
|
||||||
$url = url_path();
|
$url = get_uri();
|
||||||
$params = explode('/', trim($url, '/'));
|
$params = explode('/', trim($url, '/'));
|
||||||
return $params;
|
return $params;
|
||||||
}
|
}
|
||||||
@ -261,4 +265,70 @@ function get_tree($path = '.', $clean_path = '', $title = ''){
|
|||||||
|
|
||||||
return $tree;
|
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 <http://dhorrigan.com>
|
||||||
|
* @copyright Dan Horrigan
|
||||||
|
* @license MIT License <http://www.opensource.org/licenses/mit-license.php>
|
||||||
|
* @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, '/'));
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user