Completed
Push — master ( 2f1237...aca9f4 )
by Justin
05:22 queued 01:58
created
system/packages/com.jukusoft.cms.domain/classes/domainutils.php 1 patch
Indentation   +137 added lines, -137 removed lines patch added patch discarded remove patch
@@ -27,155 +27,155 @@
 block discarded – undo
27 27
 
28 28
 class DomainUtils {
29 29
 
30
-	public static function getTLD ($url) {
31
-		$domain_tld = "";
32
-
33
-		//http://news.mullerdigital.com/2013/10/30/how-to-get-the-domain-and-tld-from-a-url-using-php-and-regular-expression/
34
-
35
-		preg_match("/[a-z0-9\-]{1,63}\.[a-z\.]{2,6}$/", parse_url($url, PHP_URL_HOST), $domain_tld);
30
+    public static function getTLD ($url) {
31
+        $domain_tld = "";
32
+
33
+        //http://news.mullerdigital.com/2013/10/30/how-to-get-the-domain-and-tld-from-a-url-using-php-and-regular-expression/
34
+
35
+        preg_match("/[a-z0-9\-]{1,63}\.[a-z\.]{2,6}$/", parse_url($url, PHP_URL_HOST), $domain_tld);
36 36
 
37
-		return $domain_tld[0];
38
-	}
37
+        return $domain_tld[0];
38
+    }
39 39
 
40
-	public static function isHTTPS () {
41
-		return isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] && $_SERVER['HTTPS'] != "off";
42
-	}
40
+    public static function isHTTPS () {
41
+        return isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] && $_SERVER['HTTPS'] != "off";
42
+    }
43 43
 
44
-	public static function getPort () {
45
-		return (int) $_SERVER['SERVER_PORT'];
46
-	}
44
+    public static function getPort () {
45
+        return (int) $_SERVER['SERVER_PORT'];
46
+    }
47 47
 
48
-	public static function isProxyUsed () {
49
-		return isset($_SERVER['HTTP_X_FORWARDED_HOST']) && !empty($_SERVER['HTTP_X_FORWARDED_HOST']);
50
-	}
48
+    public static function isProxyUsed () {
49
+        return isset($_SERVER['HTTP_X_FORWARDED_HOST']) && !empty($_SERVER['HTTP_X_FORWARDED_HOST']);
50
+    }
51 51
 
52
-	public static function getHost () {
53
-		$host = "";
54
-
55
-		if (isset($_SERVER['HTTP_X_FORWARDED_HOST']) && !empty($_SERVER['HTTP_X_FORWARDED_HOST'])) {
56
-			$host = $_SERVER['HTTP_X_FORWARDED_HOST'];
57
-
58
-			//because HTTP_X_FORWARDED_HOST can contains more than 1 host, we only want to get the last host name
59
-			$elements = explode(',', $host);
60
-			$host = end($elements);
61
-		} else if (isset($_SERVER['SERVER_NAME']) && !empty($_SERVER['SERVER_NAME'])) {
62
-			$host = $_SERVER['SERVER_NAME'];
63
-		} else if (isset($_SERVER['HTTP_HOST']) && !empty($_SERVER['HTTP_HOST'])) {
64
-			$host = $_SERVER['HTTP_HOST'];
65
-		} else {
66
-			//unknown host
67
-
68
-			//use server ip
69
-			return htmlentities($_SERVER['SERVER_ADDR']);
70
-		}
71
-
72
-		if ($host == "cms.chipbyte.de") {
73
-			var_dump($_SERVER);
74
-		}
75
-
76
-		// Remove port number from host
77
-		$host = preg_replace("%:\d+$%", "", $host);
78
-
79
-		return trim($host);
80
-	}
81
-
82
-	/**
83
-	 * get domain
84
-	 *
85
-	 * alias to getHost()
86
-	 */
87
-	public static function getDomain () {
88
-		return self::getHost();
89
-	}
90
-
91
-	public static function getReferer () {
92
-		return htmlentities($_SERVER['HTTP_REFERER']);
93
-	}
94
-
95
-	public static function getRequestMethod () {
96
-		return htmlspecialchars($_SERVER['REQUEST_METHOD']);
97
-	}
98
-
99
-	public static function getRequestURI () {
100
-		return htmlentities($_SERVER['REQUEST_URI']);
101
-	}
102
-
103
-	public static function getBaseURL (bool $without_protocol = false) {
104
-		$url = "";
105
-
106
-		if (!$without_protocol) {//add protocol
107
-			if (self::isHTTPS()) {
108
-				$url .= "https://";
109
-			} else {
110
-				$url .= "http://";
111
-			}
112
-		}
113
-
114
-		//add domain
115
-		$url .= self::getDomain();
116
-
117
-		//check, if an specific server port is used
118
-		if (self::getPort() != 80 && self::getPort() != 433) {
119
-			$url .= ":" . self::getPort();
120
-		}
121
-
122
-		return $url;
123
-	}
124
-
125
-	/**
126
-	 * generate an url for a page in this form: http(s)://<Domain><Base URL><Page>
127
-	 */
128
-	public static function generateURL (string $page, array $params = array()) : string {
129
-		$params_str = "";
130
-
131
-		if (count($params) > 0) {
132
-			$params_str = "?";
133
-
134
-			$array = "";
135
-
136
-			foreach ($params as $key=>$value) {
137
-				$array[] = $key . "=" . $value;
138
-			}
139
-
140
-			$params_str .= implode("&amp;", $array);
141
-		}
142
-
143
-		return self::getBaseURL() . "/" . $page . $params_str;
144
-	}
145
-
146
-	public static function getURL () {
147
-		return self::getBaseURL() . self::getRequestURI();
148
-	}
149
-
150
-	/**
151
-	 * faster implementation of getTld()
152
-	 */
153
-	public static function getCurrentDomain () {
154
-		$host = $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
155
-		$domain = explode("?", $host);
156
-		$host = $domain[0];
157
-		$array = explode("/", $host);
158
-		$host = $array[0];
159
-
160
-		/*$domain = "";
52
+    public static function getHost () {
53
+        $host = "";
54
+
55
+        if (isset($_SERVER['HTTP_X_FORWARDED_HOST']) && !empty($_SERVER['HTTP_X_FORWARDED_HOST'])) {
56
+            $host = $_SERVER['HTTP_X_FORWARDED_HOST'];
57
+
58
+            //because HTTP_X_FORWARDED_HOST can contains more than 1 host, we only want to get the last host name
59
+            $elements = explode(',', $host);
60
+            $host = end($elements);
61
+        } else if (isset($_SERVER['SERVER_NAME']) && !empty($_SERVER['SERVER_NAME'])) {
62
+            $host = $_SERVER['SERVER_NAME'];
63
+        } else if (isset($_SERVER['HTTP_HOST']) && !empty($_SERVER['HTTP_HOST'])) {
64
+            $host = $_SERVER['HTTP_HOST'];
65
+        } else {
66
+            //unknown host
67
+
68
+            //use server ip
69
+            return htmlentities($_SERVER['SERVER_ADDR']);
70
+        }
71
+
72
+        if ($host == "cms.chipbyte.de") {
73
+            var_dump($_SERVER);
74
+        }
75
+
76
+        // Remove port number from host
77
+        $host = preg_replace("%:\d+$%", "", $host);
78
+
79
+        return trim($host);
80
+    }
81
+
82
+    /**
83
+     * get domain
84
+     *
85
+     * alias to getHost()
86
+     */
87
+    public static function getDomain () {
88
+        return self::getHost();
89
+    }
90
+
91
+    public static function getReferer () {
92
+        return htmlentities($_SERVER['HTTP_REFERER']);
93
+    }
94
+
95
+    public static function getRequestMethod () {
96
+        return htmlspecialchars($_SERVER['REQUEST_METHOD']);
97
+    }
98
+
99
+    public static function getRequestURI () {
100
+        return htmlentities($_SERVER['REQUEST_URI']);
101
+    }
102
+
103
+    public static function getBaseURL (bool $without_protocol = false) {
104
+        $url = "";
105
+
106
+        if (!$without_protocol) {//add protocol
107
+            if (self::isHTTPS()) {
108
+                $url .= "https://";
109
+            } else {
110
+                $url .= "http://";
111
+            }
112
+        }
113
+
114
+        //add domain
115
+        $url .= self::getDomain();
116
+
117
+        //check, if an specific server port is used
118
+        if (self::getPort() != 80 && self::getPort() != 433) {
119
+            $url .= ":" . self::getPort();
120
+        }
121
+
122
+        return $url;
123
+    }
124
+
125
+    /**
126
+     * generate an url for a page in this form: http(s)://<Domain><Base URL><Page>
127
+     */
128
+    public static function generateURL (string $page, array $params = array()) : string {
129
+        $params_str = "";
130
+
131
+        if (count($params) > 0) {
132
+            $params_str = "?";
133
+
134
+            $array = "";
135
+
136
+            foreach ($params as $key=>$value) {
137
+                $array[] = $key . "=" . $value;
138
+            }
139
+
140
+            $params_str .= implode("&amp;", $array);
141
+        }
142
+
143
+        return self::getBaseURL() . "/" . $page . $params_str;
144
+    }
145
+
146
+    public static function getURL () {
147
+        return self::getBaseURL() . self::getRequestURI();
148
+    }
149
+
150
+    /**
151
+     * faster implementation of getTld()
152
+     */
153
+    public static function getCurrentDomain () {
154
+        $host = $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
155
+        $domain = explode("?", $host);
156
+        $host = $domain[0];
157
+        $array = explode("/", $host);
158
+        $host = $array[0];
159
+
160
+        /*$domain = "";
161 161
 
162 162
 		for ($i = 0; $i < count($array) - 1; $i++) {
163 163
 			$domain .= $array[$i];
164 164
 		}*/
165 165
 
166
-		$array1 = explode(":", $host);
167
-		$host = $array1[0];
166
+        $array1 = explode(":", $host);
167
+        $host = $array1[0];
168 168
 
169
-		return /*$domain*/$host;
170
-	}
169
+        return /*$domain*/$host;
170
+    }
171 171
 
172
-	public static function getProtocol () : string {
173
-		if (self::isHTTPS()) {
174
-			return "https://";
175
-		} else {
176
-			return "http://";
177
-		}
178
-	}
172
+    public static function getProtocol () : string {
173
+        if (self::isHTTPS()) {
174
+            return "https://";
175
+        } else {
176
+            return "http://";
177
+        }
178
+    }
179 179
 
180 180
 }
181 181
 
Please login to merge, or discard this patch.