Browse Source

No more need to set the SUBDIR in config, its getting extracted from the FRONTEND_BASE_PATH

ohartl 9 năm trước cách đây
mục cha
commit
d3c56b815c
3 tập tin đã thay đổi với 24 bổ sung18 xóa
  1. 3 9
      README.md
  2. 0 1
      config/config.inc.php.example
  3. 21 8
      index.php

+ 3 - 9
README.md

@@ -215,25 +215,19 @@ WebMUM will then show a larger field for source addresses in the frontend and yo
 
 ### Paths
 
-Define the URL of the web application, and it's subfolder:
+The `FRONTEND_BASE_PATH` is the URL your WebMUM installation is accessible from outside, this also includes subfolders if you installed it in a subfolder for that specific domain.
 
 ```php
-/*
- * Frontend paths
- */
-
 define("FRONTEND_BASE_PATH", "http://mydomain.tld/webmum/");
-define("SUBDIR", "webmum/");
 ```
 
-In the example above, WebMUM is located in a subfolder named "webmum/". If you don't want to use a subfolder, but install WebMUM directly into the domain root,
-set the settings like this:
+In the example above, WebMUM is located in a subfolder named "webmum/". If your WebMUM installation is directly accessible from a domain (has its own domain), then set the `FRONTEND_BASE_PATH` to something like this:
 
 ```php
 define("FRONTEND_BASE_PATH", "http://webmum.mydomain.tld/");
-define("SUBDIR", "");
 ```
 
+
 ### Admin e-mail address
 
 Only users with one of the specified email addresses will have access to the administrator's dashboard and will be able to create, edit and delete users, domains and redirects.

+ 0 - 1
config/config.inc.php.example

@@ -57,7 +57,6 @@ define("DBC_ALIASES_DESTINATION", "destination");
  */
 
 define("FRONTEND_BASE_PATH", "http://localhost/webmum/");
-define("SUBDIR", "webmum/");
 
 
 /*

+ 21 - 8
index.php

@@ -94,26 +94,39 @@ function loadPageByRoute($url)
 }
 
 /**
+ * @param bool $removeGetParameters
+ *
  * @return string
  */
-function preparedUrlForRouting()
+function getCurrentUrlPath($removeGetParameters = true)
 {
+	$baseUrl = parse_url(FRONTEND_BASE_PATH);
+	$basePath = isset($baseUrl['path']) ? rtrim($baseUrl['path'], '/') : '';
+
 	$url = $_SERVER['REQUEST_URI'];
 
-	// Remove GET Parameters
-	$url = preg_replace('/\?.*/', '', $url);
+	if($removeGetParameters) {
+		$url = preg_replace('/\?.*/', '', $url); // Trim GET Parameters
+	}
 
-	// Remove prescending directory part e.g. webmum/ defined in SUBDIR
-	$url = preg_replace("#".SUBDIR."#", '', $url);
+	// Trim all leading slashes
+	$url = rtrim($url, '/');
 
-	// Webserver should add trailing slash, but if there is no trailing slash for any reason, add one ;)
-	if(strrpos($url, '/') != strlen($url) - 1){
-		$url = $url.'/';
+	if(!empty($basePath) && ($basePathPos = strpos($url, $basePath)) === 0){
+		$url = substr($url, strlen($basePath));
 	}
 
 	return $url;
 }
 
+/**
+ * @return string
+ */
+function preparedUrlForRouting()
+{
+	return getCurrentUrlPath(true).'/';
+}
+
 
 /*
  * Build page