Add support to baseURLresource used in the HTML page to the modules
git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@2154 bf3deb0d-5f1a-0410-827f-c0cc1f45334c
This commit is contained in:
42
route.php
42
route.php
@@ -59,6 +59,11 @@ class route
|
|||||||
if (substr ($this->baseURL, -1) !== "/")
|
if (substr ($this->baseURL, -1) !== "/")
|
||||||
$this->baseURL .= "/";
|
$this->baseURL .= "/";
|
||||||
}
|
}
|
||||||
|
elseif (isset ($_SERVER["REQUEST_URI"]) &&
|
||||||
|
strpos ($_SERVER["REQUEST_URI"], "index.php?url=") !== false)
|
||||||
|
{
|
||||||
|
$this->baseURL = "";
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Calculate the root in relative
|
// Calculate the root in relative
|
||||||
@@ -80,6 +85,21 @@ class route
|
|||||||
return $this->baseURL;
|
return $this->baseURL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Return the baseURL for a resource (add a index.php?url= if there is no
|
||||||
|
mod_rewrite support. Used to link to modules in the HTML page.
|
||||||
|
The baseURL is the real base of the project, which is different when not
|
||||||
|
using the mod_rewrite. They are equal when using the mod_rewrite */
|
||||||
|
function baseURLresource ()
|
||||||
|
{
|
||||||
|
if ($this->baseURL === "")
|
||||||
|
$this->baseURL ();
|
||||||
|
if (isset ($_SERVER["REQUEST_URI"]) &&
|
||||||
|
strpos ($_SERVER["REQUEST_URI"], "index.php?url=") !== false)
|
||||||
|
return "index.php?url=".$this->baseURL;
|
||||||
|
return $this->baseURL;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/** Return the baseURL of the module
|
/** Return the baseURL of the module
|
||||||
Always finish with a slash */
|
Always finish with a slash */
|
||||||
function baseURLmodule ()
|
function baseURLmodule ()
|
||||||
@@ -119,7 +139,17 @@ class route
|
|||||||
$url .= "//".$_SERVER["SERVER_NAME"].$port;
|
$url .= "//".$_SERVER["SERVER_NAME"].$port;
|
||||||
}
|
}
|
||||||
if (isset ($_SERVER["REQUEST_URI"]))
|
if (isset ($_SERVER["REQUEST_URI"]))
|
||||||
$url .= substr ($_SERVER["REQUEST_URI"], 1+strlen (dirname ($_SERVER["SCRIPT_NAME"])));
|
{
|
||||||
|
// If there is a directory before the index.php file, must remove the
|
||||||
|
// directory structure
|
||||||
|
if (dirname ($_SERVER["SCRIPT_NAME"]) !== "/")
|
||||||
|
$url .= substr ($_SERVER["REQUEST_URI"],
|
||||||
|
1+strlen (dirname ($_SERVER["SCRIPT_NAME"])));
|
||||||
|
else
|
||||||
|
// If there is no directory before the index.php (root of the Web server),
|
||||||
|
// just remove the /
|
||||||
|
$url = substr ($_SERVER["REQUEST_URI"], 1);
|
||||||
|
}
|
||||||
return $url;
|
return $url;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -147,6 +177,13 @@ class route
|
|||||||
$destURL = $baseURL.substr ($destURL, 1);
|
$destURL = $baseURL.substr ($destURL, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (strpos ($requestURL, "index.php?url=") !== false)
|
||||||
|
{
|
||||||
|
// If not using the mod_rewrite, force the index.php?url=
|
||||||
|
$destURL = substr ($destURL, strlen ($baseURL));
|
||||||
|
$destURL = "index.php?url=".$destURL;
|
||||||
|
}
|
||||||
|
|
||||||
// Else http : keep the complete URL
|
// Else http : keep the complete URL
|
||||||
if ($destURL === "")
|
if ($destURL === "")
|
||||||
throw new Exception ("Destination URL is empty", 500);
|
throw new Exception ("Destination URL is empty", 500);
|
||||||
@@ -307,8 +344,7 @@ class route
|
|||||||
@param function $function Function to be executed if the route match */
|
@param function $function Function to be executed if the route match */
|
||||||
public function map ($route, $function)
|
public function map ($route, $function)
|
||||||
{
|
{
|
||||||
$url = substr ($this->requestURL (), strlen ($this->baseURLmodule ()));
|
$url = str_replace ("index.php?url=", "", $this->requestURL ());
|
||||||
$url = $this->requestURL ();
|
|
||||||
if ($this->debug)
|
if ($this->debug)
|
||||||
echo "$url ";
|
echo "$url ";
|
||||||
if ($url === $route)
|
if ($url === $route)
|
||||||
|
|||||||
Reference in New Issue
Block a user