Passed
Push — 1.0.0-dev ( d422fd...3d5bea )
by nguereza
02:49
created
core/classes/Url.php 3 patches
Indentation   +142 added lines, -142 removed lines patch added patch discarded remove patch
@@ -1,154 +1,154 @@
 block discarded – undo
1 1
 <?php
2
-	defined('ROOT_PATH') or exit('Access denied');
3
-	/**
4
-	 * TNH Framework
5
-	 *
6
-	 * A simple PHP framework using HMVC architecture
7
-	 *
8
-	 * This content is released under the GNU GPL License (GPL)
9
-	 *
10
-	 * Copyright (C) 2017 Tony NGUEREZA
11
-	 *
12
-	 * This program is free software; you can redistribute it and/or
13
-	 * modify it under the terms of the GNU General Public License
14
-	 * as published by the Free Software Foundation; either version 3
15
-	 * of the License, or (at your option) any later version.
16
-	 *
17
-	 * This program is distributed in the hope that it will be useful,
18
-	 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
-	 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
-	 * GNU General Public License for more details.
21
-	 *
22
-	 * You should have received a copy of the GNU General Public License
23
-	 * along with this program; if not, write to the Free Software
24
-	 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25
-	*/
2
+    defined('ROOT_PATH') or exit('Access denied');
3
+    /**
4
+     * TNH Framework
5
+     *
6
+     * A simple PHP framework using HMVC architecture
7
+     *
8
+     * This content is released under the GNU GPL License (GPL)
9
+     *
10
+     * Copyright (C) 2017 Tony NGUEREZA
11
+     *
12
+     * This program is free software; you can redistribute it and/or
13
+     * modify it under the terms of the GNU General Public License
14
+     * as published by the Free Software Foundation; either version 3
15
+     * of the License, or (at your option) any later version.
16
+     *
17
+     * This program is distributed in the hope that it will be useful,
18
+     * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
+     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
+     * GNU General Public License for more details.
21
+     *
22
+     * You should have received a copy of the GNU General Public License
23
+     * along with this program; if not, write to the Free Software
24
+     * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25
+     */
26 26
 
27 27
 
28
-	class Url{
28
+    class Url{
29 29
 
30
-		/**
31
-		 * Return the link using base_url config without front controller "index.php"
32
-		 * @param  string $path the link path or full URL
33
-		 * @return string the full link URL
34
-		 */
35
-		public static function base_url($path = ''){
36
-			if(is_url($path)){
37
-				return $path;
38
-			}
39
-			return get_config('base_url') . $path;
40
-		}
30
+        /**
31
+         * Return the link using base_url config without front controller "index.php"
32
+         * @param  string $path the link path or full URL
33
+         * @return string the full link URL
34
+         */
35
+        public static function base_url($path = ''){
36
+            if(is_url($path)){
37
+                return $path;
38
+            }
39
+            return get_config('base_url') . $path;
40
+        }
41 41
 
42
-		/**
43
-		 * Return the link using base_url config with front controller "index.php"
44
-		 * @param  string $path the link path or full URL
45
-		 * @return string the full link URL
46
-		 */
47
-		public static function site_url($path = ''){
48
-			if(is_url($path)){
49
-				return $path;
50
-			}
51
-			$path = rtrim($path, '/');
52
-			$baseUrl = get_config('base_url');
53
-			$frontController = get_config('front_controller');
54
-			$url = $baseUrl;
55
-			if($frontController){
56
-				$url .= $frontController . '/';
57
-			}
58
-			if(($suffix = get_config('url_suffix')) && $path){
59
-				if(strpos($path, '?') !== false){
60
-					$query = explode('?', $path);
61
-					$query[0] = str_ireplace($suffix, '', $query[0]);
62
-					$query[0] = rtrim($query[0], '/');
63
-					$query[0] .= $suffix;
64
-					$path = implode('?', $query);
65
-				}
66
-				else{
67
-					$path .= $suffix;
68
-				}
69
-			}
70
-			return $url . $path;
71
-		}
42
+        /**
43
+         * Return the link using base_url config with front controller "index.php"
44
+         * @param  string $path the link path or full URL
45
+         * @return string the full link URL
46
+         */
47
+        public static function site_url($path = ''){
48
+            if(is_url($path)){
49
+                return $path;
50
+            }
51
+            $path = rtrim($path, '/');
52
+            $baseUrl = get_config('base_url');
53
+            $frontController = get_config('front_controller');
54
+            $url = $baseUrl;
55
+            if($frontController){
56
+                $url .= $frontController . '/';
57
+            }
58
+            if(($suffix = get_config('url_suffix')) && $path){
59
+                if(strpos($path, '?') !== false){
60
+                    $query = explode('?', $path);
61
+                    $query[0] = str_ireplace($suffix, '', $query[0]);
62
+                    $query[0] = rtrim($query[0], '/');
63
+                    $query[0] .= $suffix;
64
+                    $path = implode('?', $query);
65
+                }
66
+                else{
67
+                    $path .= $suffix;
68
+                }
69
+            }
70
+            return $url . $path;
71
+        }
72 72
 
73
-		/**
74
-		 * Return the current site URL
75
-		 * @return string
76
-		 */
77
-		public static function current(){
78
-			$current = '/';
79
-			$requestUri = get_instance()->request->requestUri();
80
-			if($requestUri){
81
-				$current = $requestUri;
82
-			}
83
-			return static::domain() . $current;
84
-		}
73
+        /**
74
+         * Return the current site URL
75
+         * @return string
76
+         */
77
+        public static function current(){
78
+            $current = '/';
79
+            $requestUri = get_instance()->request->requestUri();
80
+            if($requestUri){
81
+                $current = $requestUri;
82
+            }
83
+            return static::domain() . $current;
84
+        }
85 85
 
86
-		/**
87
-		 * Generate a friendly  text to use in link (slugs)
88
-		 * @param  string  $str       the title or text to use to get the friendly text
89
-		 * @param  string  $separator the caracters separator
90
-		 * @param  boolean $lowercase whether to set the final text to lowe case or not
91
-		 * @return string the friendly generated text
92
-		 */
93
-		public static function title($str = null, $separator = '-', $lowercase = true){
94
-			$str = trim($str);
95
-			$from = array('ç','À','Á','Â','Ã','Ä','Å','à','á','â','ã','ä','å','Ò','Ó','Ô','Õ','Ö','Ø','ò','ó','ô','õ','ö','ø','È','É','Ê','Ë','è','é','ê','ë','Ç','ç','Ì','Í','Î','Ï','ì','í','î','ï','Ù','Ú','Û','Ü','ù','ú','û','ü','ÿ','Ñ','ñ');
96
-			$to = array('c','a','a','a','a','a','a','a','a','a','a','a','a','o','o','o','o','o','o','o','o','o','o','o','o','e','e','e','e','e','e','e','e','e','e','i','i','i','i','i','i','i','i','u','u','u','u','u','u','u','u','y','n','n');
97
-			$str = str_replace($from, $to, $str);
98
-			$str = preg_replace('#([^a-z0-9]+)#i', $separator, $str);
99
-			$str = str_replace('--', $separator, $str);
100
-			//if after process we get something like one-two-three-, need truncate the last separator "-"
101
-			if(substr($str, -1) == $separator){
102
-				$str = substr($str, 0, -1);
103
-			}
104
-			if($lowercase){
105
-				$str = strtolower($str);
106
-			}
107
-			return $str;
108
-		}
86
+        /**
87
+         * Generate a friendly  text to use in link (slugs)
88
+         * @param  string  $str       the title or text to use to get the friendly text
89
+         * @param  string  $separator the caracters separator
90
+         * @param  boolean $lowercase whether to set the final text to lowe case or not
91
+         * @return string the friendly generated text
92
+         */
93
+        public static function title($str = null, $separator = '-', $lowercase = true){
94
+            $str = trim($str);
95
+            $from = array('ç','À','Á','Â','Ã','Ä','Å','à','á','â','ã','ä','å','Ò','Ó','Ô','Õ','Ö','Ø','ò','ó','ô','õ','ö','ø','È','É','Ê','Ë','è','é','ê','ë','Ç','ç','Ì','Í','Î','Ï','ì','í','î','ï','Ù','Ú','Û','Ü','ù','ú','û','ü','ÿ','Ñ','ñ');
96
+            $to = array('c','a','a','a','a','a','a','a','a','a','a','a','a','o','o','o','o','o','o','o','o','o','o','o','o','e','e','e','e','e','e','e','e','e','e','i','i','i','i','i','i','i','i','u','u','u','u','u','u','u','u','y','n','n');
97
+            $str = str_replace($from, $to, $str);
98
+            $str = preg_replace('#([^a-z0-9]+)#i', $separator, $str);
99
+            $str = str_replace('--', $separator, $str);
100
+            //if after process we get something like one-two-three-, need truncate the last separator "-"
101
+            if(substr($str, -1) == $separator){
102
+                $str = substr($str, 0, -1);
103
+            }
104
+            if($lowercase){
105
+                $str = strtolower($str);
106
+            }
107
+            return $str;
108
+        }
109 109
 
110
-		/**
111
-		 * Get the current application domain with protocol
112
-		 * @return string the domain name
113
-		 */
114
-		public static function domain(){
115
-			$obj = & get_instance();
116
-			$domain = 'localhost';
117
-			$port = $obj->request->server('SERVER_PORT');
118
-			$protocol = 'http';
119
-			if(is_https()){
120
-				$protocol = 'https';
121
-			}
110
+        /**
111
+         * Get the current application domain with protocol
112
+         * @return string the domain name
113
+         */
114
+        public static function domain(){
115
+            $obj = & get_instance();
116
+            $domain = 'localhost';
117
+            $port = $obj->request->server('SERVER_PORT');
118
+            $protocol = 'http';
119
+            if(is_https()){
120
+                $protocol = 'https';
121
+            }
122 122
 
123
-			$domainserverVars = array(
124
-				'HTTP_HOST',
125
-				'SERVER_NAME',
126
-				'SERVER_ADDR'
127
-			);
123
+            $domainserverVars = array(
124
+                'HTTP_HOST',
125
+                'SERVER_NAME',
126
+                'SERVER_ADDR'
127
+            );
128 128
 
129
-			foreach ($domainserverVars as $var) {
130
-				$value = $obj->request->server($var);
131
-				if($value){
132
-					$domain = $value;
133
-					break;
134
-				}
135
-			}
129
+            foreach ($domainserverVars as $var) {
130
+                $value = $obj->request->server($var);
131
+                if($value){
132
+                    $domain = $value;
133
+                    break;
134
+                }
135
+            }
136 136
 			
137
-			if($port && ((is_https() && $port != 443) || (!is_https() && $port != 80))){
138
-				//some server use SSL but the port doesn't equal 443 sometime is 80 if is the case put the port at this end
139
-				//of the domain like https://my.domain.com:787
140
-				if(is_https() && $port != 80){
141
-					$domain .= ':'.$port;
142
-				}
143
-			}
144
-			return $protocol.'://'.$domain;
145
-		}
137
+            if($port && ((is_https() && $port != 443) || (!is_https() && $port != 80))){
138
+                //some server use SSL but the port doesn't equal 443 sometime is 80 if is the case put the port at this end
139
+                //of the domain like https://my.domain.com:787
140
+                if(is_https() && $port != 80){
141
+                    $domain .= ':'.$port;
142
+                }
143
+            }
144
+            return $protocol.'://'.$domain;
145
+        }
146 146
 
147
-		/**
148
-		 * Get the current request query string
149
-		 * @return string
150
-		 */
151
-		public static function queryString(){
152
-			return get_instance()->request->server('QUERY_STRING');
153
-		}
154
-	}
147
+        /**
148
+         * Get the current request query string
149
+         * @return string
150
+         */
151
+        public static function queryString(){
152
+            return get_instance()->request->server('QUERY_STRING');
153
+        }
154
+    }
Please login to merge, or discard this patch.
Spacing   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -25,15 +25,15 @@  discard block
 block discarded – undo
25 25
 	*/
26 26
 
27 27
 
28
-	class Url{
28
+	class Url {
29 29
 
30 30
 		/**
31 31
 		 * Return the link using base_url config without front controller "index.php"
32 32
 		 * @param  string $path the link path or full URL
33 33
 		 * @return string the full link URL
34 34
 		 */
35
-		public static function base_url($path = ''){
36
-			if(is_url($path)){
35
+		public static function base_url($path = '') {
36
+			if (is_url($path)) {
37 37
 				return $path;
38 38
 			}
39 39
 			return get_config('base_url') . $path;
@@ -44,26 +44,26 @@  discard block
 block discarded – undo
44 44
 		 * @param  string $path the link path or full URL
45 45
 		 * @return string the full link URL
46 46
 		 */
47
-		public static function site_url($path = ''){
48
-			if(is_url($path)){
47
+		public static function site_url($path = '') {
48
+			if (is_url($path)) {
49 49
 				return $path;
50 50
 			}
51 51
 			$path = rtrim($path, '/');
52 52
 			$baseUrl = get_config('base_url');
53 53
 			$frontController = get_config('front_controller');
54 54
 			$url = $baseUrl;
55
-			if($frontController){
55
+			if ($frontController) {
56 56
 				$url .= $frontController . '/';
57 57
 			}
58
-			if(($suffix = get_config('url_suffix')) && $path){
59
-				if(strpos($path, '?') !== false){
58
+			if (($suffix = get_config('url_suffix')) && $path) {
59
+				if (strpos($path, '?') !== false) {
60 60
 					$query = explode('?', $path);
61 61
 					$query[0] = str_ireplace($suffix, '', $query[0]);
62 62
 					$query[0] = rtrim($query[0], '/');
63 63
 					$query[0] .= $suffix;
64 64
 					$path = implode('?', $query);
65 65
 				}
66
-				else{
66
+				else {
67 67
 					$path .= $suffix;
68 68
 				}
69 69
 			}
@@ -74,10 +74,10 @@  discard block
 block discarded – undo
74 74
 		 * Return the current site URL
75 75
 		 * @return string
76 76
 		 */
77
-		public static function current(){
77
+		public static function current() {
78 78
 			$current = '/';
79 79
 			$requestUri = get_instance()->request->requestUri();
80
-			if($requestUri){
80
+			if ($requestUri) {
81 81
 				$current = $requestUri;
82 82
 			}
83 83
 			return static::domain() . $current;
@@ -90,18 +90,18 @@  discard block
 block discarded – undo
90 90
 		 * @param  boolean $lowercase whether to set the final text to lowe case or not
91 91
 		 * @return string the friendly generated text
92 92
 		 */
93
-		public static function title($str = null, $separator = '-', $lowercase = true){
93
+		public static function title($str = null, $separator = '-', $lowercase = true) {
94 94
 			$str = trim($str);
95
-			$from = array('ç','À','Á','Â','Ã','Ä','Å','à','á','â','ã','ä','å','Ò','Ó','Ô','Õ','Ö','Ø','ò','ó','ô','õ','ö','ø','È','É','Ê','Ë','è','é','ê','ë','Ç','ç','Ì','Í','Î','Ï','ì','í','î','ï','Ù','Ú','Û','Ü','ù','ú','û','ü','ÿ','Ñ','ñ');
96
-			$to = array('c','a','a','a','a','a','a','a','a','a','a','a','a','o','o','o','o','o','o','o','o','o','o','o','o','e','e','e','e','e','e','e','e','e','e','i','i','i','i','i','i','i','i','u','u','u','u','u','u','u','u','y','n','n');
95
+			$from = array('ç', 'À', 'Á', 'Â', 'Ã', 'Ä', 'Å', 'à', 'á', 'â', 'ã', 'ä', 'å', 'Ò', 'Ó', 'Ô', 'Õ', 'Ö', 'Ø', 'ò', 'ó', 'ô', 'õ', 'ö', 'ø', 'È', 'É', 'Ê', 'Ë', 'è', 'é', 'ê', 'ë', 'Ç', 'ç', 'Ì', 'Í', 'Î', 'Ï', 'ì', 'í', 'î', 'ï', 'Ù', 'Ú', 'Û', 'Ü', 'ù', 'ú', 'û', 'ü', 'ÿ', 'Ñ', 'ñ');
96
+			$to = array('c', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'e', 'e', 'e', 'e', 'e', 'e', 'e', 'e', 'e', 'e', 'i', 'i', 'i', 'i', 'i', 'i', 'i', 'i', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'y', 'n', 'n');
97 97
 			$str = str_replace($from, $to, $str);
98 98
 			$str = preg_replace('#([^a-z0-9]+)#i', $separator, $str);
99 99
 			$str = str_replace('--', $separator, $str);
100 100
 			//if after process we get something like one-two-three-, need truncate the last separator "-"
101
-			if(substr($str, -1) == $separator){
101
+			if (substr($str, -1) == $separator) {
102 102
 				$str = substr($str, 0, -1);
103 103
 			}
104
-			if($lowercase){
104
+			if ($lowercase) {
105 105
 				$str = strtolower($str);
106 106
 			}
107 107
 			return $str;
@@ -111,12 +111,12 @@  discard block
 block discarded – undo
111 111
 		 * Get the current application domain with protocol
112 112
 		 * @return string the domain name
113 113
 		 */
114
-		public static function domain(){
114
+		public static function domain() {
115 115
 			$obj = & get_instance();
116 116
 			$domain = 'localhost';
117 117
 			$port = $obj->request->server('SERVER_PORT');
118 118
 			$protocol = 'http';
119
-			if(is_https()){
119
+			if (is_https()) {
120 120
 				$protocol = 'https';
121 121
 			}
122 122
 
@@ -128,27 +128,27 @@  discard block
 block discarded – undo
128 128
 
129 129
 			foreach ($domainserverVars as $var) {
130 130
 				$value = $obj->request->server($var);
131
-				if($value){
131
+				if ($value) {
132 132
 					$domain = $value;
133 133
 					break;
134 134
 				}
135 135
 			}
136 136
 			
137
-			if($port && ((is_https() && $port != 443) || (!is_https() && $port != 80))){
137
+			if ($port && ((is_https() && $port != 443) || (!is_https() && $port != 80))) {
138 138
 				//some server use SSL but the port doesn't equal 443 sometime is 80 if is the case put the port at this end
139 139
 				//of the domain like https://my.domain.com:787
140
-				if(is_https() && $port != 80){
141
-					$domain .= ':'.$port;
140
+				if (is_https() && $port != 80) {
141
+					$domain .= ':' . $port;
142 142
 				}
143 143
 			}
144
-			return $protocol.'://'.$domain;
144
+			return $protocol . '://' . $domain;
145 145
 		}
146 146
 
147 147
 		/**
148 148
 		 * Get the current request query string
149 149
 		 * @return string
150 150
 		 */
151
-		public static function queryString(){
151
+		public static function queryString() {
152 152
 			return get_instance()->request->server('QUERY_STRING');
153 153
 		}
154 154
 	}
Please login to merge, or discard this patch.
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -62,8 +62,7 @@
 block discarded – undo
62 62
 					$query[0] = rtrim($query[0], '/');
63 63
 					$query[0] .= $suffix;
64 64
 					$path = implode('?', $query);
65
-				}
66
-				else{
65
+				} else{
67 66
 					$path .= $suffix;
68 67
 				}
69 68
 			}
Please login to merge, or discard this patch.
core/classes/Config.php 3 patches
Indentation   +164 added lines, -164 removed lines patch added patch discarded remove patch
@@ -1,178 +1,178 @@
 block discarded – undo
1 1
 <?php
2
-	defined('ROOT_PATH') || exit('Access denied');
3
-	/**
4
-	 * TNH Framework
5
-	 *
6
-	 * A simple PHP framework using HMVC architecture
7
-	 *
8
-	 * This content is released under the GNU GPL License (GPL)
9
-	 *
10
-	 * Copyright (C) 2017 Tony NGUEREZA
11
-	 *
12
-	 * This program is free software; you can redistribute it and/or
13
-	 * modify it under the terms of the GNU General Public License
14
-	 * as published by the Free Software Foundation; either version 3
15
-	 * of the License, or (at your option) any later version.
16
-	 *
17
-	 * This program is distributed in the hope that it will be useful,
18
-	 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
-	 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
-	 * GNU General Public License for more details.
21
-	 *
22
-	 * You should have received a copy of the GNU General Public License
23
-	 * along with this program; if not, write to the Free Software
24
-	 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25
-	*/
2
+    defined('ROOT_PATH') || exit('Access denied');
3
+    /**
4
+     * TNH Framework
5
+     *
6
+     * A simple PHP framework using HMVC architecture
7
+     *
8
+     * This content is released under the GNU GPL License (GPL)
9
+     *
10
+     * Copyright (C) 2017 Tony NGUEREZA
11
+     *
12
+     * This program is free software; you can redistribute it and/or
13
+     * modify it under the terms of the GNU General Public License
14
+     * as published by the Free Software Foundation; either version 3
15
+     * of the License, or (at your option) any later version.
16
+     *
17
+     * This program is distributed in the hope that it will be useful,
18
+     * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
+     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
+     * GNU General Public License for more details.
21
+     *
22
+     * You should have received a copy of the GNU General Public License
23
+     * along with this program; if not, write to the Free Software
24
+     * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25
+     */
26 26
 
27
-	class Config{
27
+    class Config{
28 28
 		
29
-		/**
30
-		 * The list of loaded configuration
31
-		 * @var array
32
-		 */
33
-		private static $config = array();
29
+        /**
30
+         * The list of loaded configuration
31
+         * @var array
32
+         */
33
+        private static $config = array();
34 34
 
35
-		/**
36
-		 * The logger instance
37
-		 * @var Log
38
-		 */
39
-		private static $logger;
35
+        /**
36
+         * The logger instance
37
+         * @var Log
38
+         */
39
+        private static $logger;
40 40
 
41
-		/**
42
-		 * The signleton of the logger
43
-		 * @return Object the Log instance
44
-		 */
45
-		private static function getLogger(){
46
-			if(self::$logger == null){
47
-				$logger = array();
48
-				$logger[0] =& class_loader('Log', 'classes');
49
-				$logger[0]->setLogger('Library::Config');
50
-				self::$logger = $logger[0];
51
-			}
52
-			return self::$logger;			
53
-		}
41
+        /**
42
+         * The signleton of the logger
43
+         * @return Object the Log instance
44
+         */
45
+        private static function getLogger(){
46
+            if(self::$logger == null){
47
+                $logger = array();
48
+                $logger[0] =& class_loader('Log', 'classes');
49
+                $logger[0]->setLogger('Library::Config');
50
+                self::$logger = $logger[0];
51
+            }
52
+            return self::$logger;			
53
+        }
54 54
 
55
-		/**
56
-		 * Set the log instance for future use
57
-		 * @param Log $logger the log object
58
-		 * @return Log the log instance
59
-		 */
60
-		public static function setLogger($logger){
61
-			self::$logger = $logger;
62
-			return self::$logger;
63
-		}
55
+        /**
56
+         * Set the log instance for future use
57
+         * @param Log $logger the log object
58
+         * @return Log the log instance
59
+         */
60
+        public static function setLogger($logger){
61
+            self::$logger = $logger;
62
+            return self::$logger;
63
+        }
64 64
 
65
-		/**
66
-		 * Initialize the configuration by loading all the configuration from config file
67
-		 */
68
-		public static function init(){
69
-			$logger = static::getLogger();
70
-			$logger->debug('Initialization of the configuration');
71
-			self::$config = & load_configurations();
72
-			self::setBaseUrlUsingServerVar();
73
-			if(ENVIRONMENT == 'production' && in_array(strtolower(self::$config['log_level']), array('debug', 'info','all'))){
74
-				$logger->warning('You are in production environment, please set log level to WARNING, ERROR, FATAL to increase the application performance');
75
-			}
76
-			$logger->info('Configuration initialized successfully');
77
-			$logger->info('The application configuration are listed below: ' . stringfy_vars(self::$config));
78
-		}
65
+        /**
66
+         * Initialize the configuration by loading all the configuration from config file
67
+         */
68
+        public static function init(){
69
+            $logger = static::getLogger();
70
+            $logger->debug('Initialization of the configuration');
71
+            self::$config = & load_configurations();
72
+            self::setBaseUrlUsingServerVar();
73
+            if(ENVIRONMENT == 'production' && in_array(strtolower(self::$config['log_level']), array('debug', 'info','all'))){
74
+                $logger->warning('You are in production environment, please set log level to WARNING, ERROR, FATAL to increase the application performance');
75
+            }
76
+            $logger->info('Configuration initialized successfully');
77
+            $logger->info('The application configuration are listed below: ' . stringfy_vars(self::$config));
78
+        }
79 79
 
80
-		/**
81
-		 * Get the configuration item value
82
-		 * @param  string $item    the configuration item name to get
83
-		 * @param  mixed $default the default value to use if can not find the config item in the list
84
-		 * @return mixed          the config value if exist or the default value
85
-		 */
86
-		public static function get($item, $default = null){
87
-			$logger = static::getLogger();
88
-			if(array_key_exists($item, self::$config)){
89
-				return self::$config[$item];
90
-			}
91
-			$logger->warning('Cannot find config item ['.$item.'] using the default value ['.$default.']');
92
-			return $default;
93
-		}
80
+        /**
81
+         * Get the configuration item value
82
+         * @param  string $item    the configuration item name to get
83
+         * @param  mixed $default the default value to use if can not find the config item in the list
84
+         * @return mixed          the config value if exist or the default value
85
+         */
86
+        public static function get($item, $default = null){
87
+            $logger = static::getLogger();
88
+            if(array_key_exists($item, self::$config)){
89
+                return self::$config[$item];
90
+            }
91
+            $logger->warning('Cannot find config item ['.$item.'] using the default value ['.$default.']');
92
+            return $default;
93
+        }
94 94
 
95
-		/**
96
-		 * Set the configuration item value
97
-		 * @param string $item  the config item name to set
98
-		 * @param mixed $value the config item value
99
-		 */
100
-		public static function set($item, $value){
101
-			self::$config[$item] = $value;
102
-		}
95
+        /**
96
+         * Set the configuration item value
97
+         * @param string $item  the config item name to set
98
+         * @param mixed $value the config item value
99
+         */
100
+        public static function set($item, $value){
101
+            self::$config[$item] = $value;
102
+        }
103 103
 
104
-		/**
105
-		 * Get all the configuration values
106
-		 * @return array the config values
107
-		 */
108
-		public static function getAll(){
109
-			return self::$config;
110
-		}
104
+        /**
105
+         * Get all the configuration values
106
+         * @return array the config values
107
+         */
108
+        public static function getAll(){
109
+            return self::$config;
110
+        }
111 111
 
112
-		/**
113
-		 * Set the configuration values bu merged with the existing configuration
114
-		 * @param array $config the config values to add in the configuration list
115
-		 */
116
-		public static function setAll(array $config = array()){
117
-			self::$config = array_merge(self::$config, $config);
118
-		}
112
+        /**
113
+         * Set the configuration values bu merged with the existing configuration
114
+         * @param array $config the config values to add in the configuration list
115
+         */
116
+        public static function setAll(array $config = array()){
117
+            self::$config = array_merge(self::$config, $config);
118
+        }
119 119
 
120
-		/**
121
-		 * Delete the configuration item in the list
122
-		 * @param  string $item the config item name to be deleted
123
-		 * @return boolean true if the item exists and is deleted successfully otherwise will return false.
124
-		 */
125
-		public static function delete($item){
126
-			$logger = static::getLogger();
127
-			if(array_key_exists($item, self::$config)){
128
-				$logger->info('Delete config item ['.$item.']');
129
-				unset(self::$config[$item]);
130
-				return true;
131
-			}
132
-			else{
133
-				$logger->warning('Config item ['.$item.'] to be deleted does not exists');
134
-				return false;
135
-			}
136
-		}
120
+        /**
121
+         * Delete the configuration item in the list
122
+         * @param  string $item the config item name to be deleted
123
+         * @return boolean true if the item exists and is deleted successfully otherwise will return false.
124
+         */
125
+        public static function delete($item){
126
+            $logger = static::getLogger();
127
+            if(array_key_exists($item, self::$config)){
128
+                $logger->info('Delete config item ['.$item.']');
129
+                unset(self::$config[$item]);
130
+                return true;
131
+            }
132
+            else{
133
+                $logger->warning('Config item ['.$item.'] to be deleted does not exists');
134
+                return false;
135
+            }
136
+        }
137 137
 
138
-		/**
139
-		 * Load the configuration file. This an alias to Loader::config()
140
-		 * @param  string $config the config name to be loaded
141
-		 */
142
-		public static function load($config){
143
-			Loader::config($config);
144
-		}
138
+        /**
139
+         * Load the configuration file. This an alias to Loader::config()
140
+         * @param  string $config the config name to be loaded
141
+         */
142
+        public static function load($config){
143
+            Loader::config($config);
144
+        }
145 145
 
146
-		/**
147
-		 * Set the configuration for "base_url" if is not set in the configuration
148
-		 */
149
-		private static function setBaseUrlUsingServerVar(){
150
-			$logger = static::getLogger();
151
-			if (! isset(self::$config['base_url']) || ! is_url(self::$config['base_url'])){
152
-				if(ENVIRONMENT == 'production'){
153
-					$logger->warning('Application base URL is not set or invalid, please set application base URL to increase the application loading time');
154
-				}
155
-				$baseUrl = null;
156
-				if (isset($_SERVER['SERVER_ADDR'])){
157
-					$baseUrl = $_SERVER['SERVER_ADDR'];
158
-					//check if the server is running under IPv6
159
-					if (strpos($_SERVER['SERVER_ADDR'], ':') !== FALSE){
160
-						$baseUrl = '['.$_SERVER['SERVER_ADDR'].']';
161
-					}
162
-					$serverPort = 80;
163
-					if (isset($_SERVER['SERVER_PORT'])) {
164
-						$serverPort = $_SERVER['SERVER_PORT'];
165
-					}
166
-					$port = ((($serverPort != '80' && ! is_https()) || ($serverPort != '443' && is_https())) ? ':' . $serverPort : '');
167
-					$baseUrl = (is_https() ? 'https' : 'http').'://' . $baseUrl . $port
168
-						. substr($_SERVER['SCRIPT_NAME'], 0, strpos($_SERVER['SCRIPT_NAME'], basename($_SERVER['SCRIPT_FILENAME'])));
169
-				}
170
-				else{
171
-					$logger->warning('Can not determine the application base URL automatically, use http://localhost as default');
172
-					$baseUrl = 'http://localhost/';
173
-				}
174
-				self::set('base_url', $baseUrl);
175
-			}
176
-			self::$config['base_url'] = rtrim(self::$config['base_url'], '/') .'/';
177
-		}
178
-	}
146
+        /**
147
+         * Set the configuration for "base_url" if is not set in the configuration
148
+         */
149
+        private static function setBaseUrlUsingServerVar(){
150
+            $logger = static::getLogger();
151
+            if (! isset(self::$config['base_url']) || ! is_url(self::$config['base_url'])){
152
+                if(ENVIRONMENT == 'production'){
153
+                    $logger->warning('Application base URL is not set or invalid, please set application base URL to increase the application loading time');
154
+                }
155
+                $baseUrl = null;
156
+                if (isset($_SERVER['SERVER_ADDR'])){
157
+                    $baseUrl = $_SERVER['SERVER_ADDR'];
158
+                    //check if the server is running under IPv6
159
+                    if (strpos($_SERVER['SERVER_ADDR'], ':') !== FALSE){
160
+                        $baseUrl = '['.$_SERVER['SERVER_ADDR'].']';
161
+                    }
162
+                    $serverPort = 80;
163
+                    if (isset($_SERVER['SERVER_PORT'])) {
164
+                        $serverPort = $_SERVER['SERVER_PORT'];
165
+                    }
166
+                    $port = ((($serverPort != '80' && ! is_https()) || ($serverPort != '443' && is_https())) ? ':' . $serverPort : '');
167
+                    $baseUrl = (is_https() ? 'https' : 'http').'://' . $baseUrl . $port
168
+                        . substr($_SERVER['SCRIPT_NAME'], 0, strpos($_SERVER['SCRIPT_NAME'], basename($_SERVER['SCRIPT_FILENAME'])));
169
+                }
170
+                else{
171
+                    $logger->warning('Can not determine the application base URL automatically, use http://localhost as default');
172
+                    $baseUrl = 'http://localhost/';
173
+                }
174
+                self::set('base_url', $baseUrl);
175
+            }
176
+            self::$config['base_url'] = rtrim(self::$config['base_url'], '/') .'/';
177
+        }
178
+    }
Please login to merge, or discard this patch.
Spacing   +29 added lines, -29 removed lines patch added patch discarded remove patch
@@ -24,7 +24,7 @@  discard block
 block discarded – undo
24 24
 	 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25 25
 	*/
26 26
 
27
-	class Config{
27
+	class Config {
28 28
 		
29 29
 		/**
30 30
 		 * The list of loaded configuration
@@ -42,10 +42,10 @@  discard block
 block discarded – undo
42 42
 		 * The signleton of the logger
43 43
 		 * @return Object the Log instance
44 44
 		 */
45
-		private static function getLogger(){
46
-			if(self::$logger == null){
45
+		private static function getLogger() {
46
+			if (self::$logger == null) {
47 47
 				$logger = array();
48
-				$logger[0] =& class_loader('Log', 'classes');
48
+				$logger[0] = & class_loader('Log', 'classes');
49 49
 				$logger[0]->setLogger('Library::Config');
50 50
 				self::$logger = $logger[0];
51 51
 			}
@@ -57,7 +57,7 @@  discard block
 block discarded – undo
57 57
 		 * @param Log $logger the log object
58 58
 		 * @return Log the log instance
59 59
 		 */
60
-		public static function setLogger($logger){
60
+		public static function setLogger($logger) {
61 61
 			self::$logger = $logger;
62 62
 			return self::$logger;
63 63
 		}
@@ -65,12 +65,12 @@  discard block
 block discarded – undo
65 65
 		/**
66 66
 		 * Initialize the configuration by loading all the configuration from config file
67 67
 		 */
68
-		public static function init(){
68
+		public static function init() {
69 69
 			$logger = static::getLogger();
70 70
 			$logger->debug('Initialization of the configuration');
71 71
 			self::$config = & load_configurations();
72 72
 			self::setBaseUrlUsingServerVar();
73
-			if(ENVIRONMENT == 'production' && in_array(strtolower(self::$config['log_level']), array('debug', 'info','all'))){
73
+			if (ENVIRONMENT == 'production' && in_array(strtolower(self::$config['log_level']), array('debug', 'info', 'all'))) {
74 74
 				$logger->warning('You are in production environment, please set log level to WARNING, ERROR, FATAL to increase the application performance');
75 75
 			}
76 76
 			$logger->info('Configuration initialized successfully');
@@ -83,12 +83,12 @@  discard block
 block discarded – undo
83 83
 		 * @param  mixed $default the default value to use if can not find the config item in the list
84 84
 		 * @return mixed          the config value if exist or the default value
85 85
 		 */
86
-		public static function get($item, $default = null){
86
+		public static function get($item, $default = null) {
87 87
 			$logger = static::getLogger();
88
-			if(array_key_exists($item, self::$config)){
88
+			if (array_key_exists($item, self::$config)) {
89 89
 				return self::$config[$item];
90 90
 			}
91
-			$logger->warning('Cannot find config item ['.$item.'] using the default value ['.$default.']');
91
+			$logger->warning('Cannot find config item [' . $item . '] using the default value [' . $default . ']');
92 92
 			return $default;
93 93
 		}
94 94
 
@@ -97,7 +97,7 @@  discard block
 block discarded – undo
97 97
 		 * @param string $item  the config item name to set
98 98
 		 * @param mixed $value the config item value
99 99
 		 */
100
-		public static function set($item, $value){
100
+		public static function set($item, $value) {
101 101
 			self::$config[$item] = $value;
102 102
 		}
103 103
 
@@ -105,7 +105,7 @@  discard block
 block discarded – undo
105 105
 		 * Get all the configuration values
106 106
 		 * @return array the config values
107 107
 		 */
108
-		public static function getAll(){
108
+		public static function getAll() {
109 109
 			return self::$config;
110 110
 		}
111 111
 
@@ -113,7 +113,7 @@  discard block
 block discarded – undo
113 113
 		 * Set the configuration values bu merged with the existing configuration
114 114
 		 * @param array $config the config values to add in the configuration list
115 115
 		 */
116
-		public static function setAll(array $config = array()){
116
+		public static function setAll(array $config = array()) {
117 117
 			self::$config = array_merge(self::$config, $config);
118 118
 		}
119 119
 
@@ -122,15 +122,15 @@  discard block
 block discarded – undo
122 122
 		 * @param  string $item the config item name to be deleted
123 123
 		 * @return boolean true if the item exists and is deleted successfully otherwise will return false.
124 124
 		 */
125
-		public static function delete($item){
125
+		public static function delete($item) {
126 126
 			$logger = static::getLogger();
127
-			if(array_key_exists($item, self::$config)){
128
-				$logger->info('Delete config item ['.$item.']');
127
+			if (array_key_exists($item, self::$config)) {
128
+				$logger->info('Delete config item [' . $item . ']');
129 129
 				unset(self::$config[$item]);
130 130
 				return true;
131 131
 			}
132
-			else{
133
-				$logger->warning('Config item ['.$item.'] to be deleted does not exists');
132
+			else {
133
+				$logger->warning('Config item [' . $item . '] to be deleted does not exists');
134 134
 				return false;
135 135
 			}
136 136
 		}
@@ -139,40 +139,40 @@  discard block
 block discarded – undo
139 139
 		 * Load the configuration file. This an alias to Loader::config()
140 140
 		 * @param  string $config the config name to be loaded
141 141
 		 */
142
-		public static function load($config){
142
+		public static function load($config) {
143 143
 			Loader::config($config);
144 144
 		}
145 145
 
146 146
 		/**
147 147
 		 * Set the configuration for "base_url" if is not set in the configuration
148 148
 		 */
149
-		private static function setBaseUrlUsingServerVar(){
149
+		private static function setBaseUrlUsingServerVar() {
150 150
 			$logger = static::getLogger();
151
-			if (! isset(self::$config['base_url']) || ! is_url(self::$config['base_url'])){
152
-				if(ENVIRONMENT == 'production'){
151
+			if (!isset(self::$config['base_url']) || !is_url(self::$config['base_url'])) {
152
+				if (ENVIRONMENT == 'production') {
153 153
 					$logger->warning('Application base URL is not set or invalid, please set application base URL to increase the application loading time');
154 154
 				}
155 155
 				$baseUrl = null;
156
-				if (isset($_SERVER['SERVER_ADDR'])){
156
+				if (isset($_SERVER['SERVER_ADDR'])) {
157 157
 					$baseUrl = $_SERVER['SERVER_ADDR'];
158 158
 					//check if the server is running under IPv6
159
-					if (strpos($_SERVER['SERVER_ADDR'], ':') !== FALSE){
160
-						$baseUrl = '['.$_SERVER['SERVER_ADDR'].']';
159
+					if (strpos($_SERVER['SERVER_ADDR'], ':') !== FALSE) {
160
+						$baseUrl = '[' . $_SERVER['SERVER_ADDR'] . ']';
161 161
 					}
162 162
 					$serverPort = 80;
163 163
 					if (isset($_SERVER['SERVER_PORT'])) {
164 164
 						$serverPort = $_SERVER['SERVER_PORT'];
165 165
 					}
166
-					$port = ((($serverPort != '80' && ! is_https()) || ($serverPort != '443' && is_https())) ? ':' . $serverPort : '');
167
-					$baseUrl = (is_https() ? 'https' : 'http').'://' . $baseUrl . $port
166
+					$port = ((($serverPort != '80' && !is_https()) || ($serverPort != '443' && is_https())) ? ':' . $serverPort : '');
167
+					$baseUrl = (is_https() ? 'https' : 'http') . '://' . $baseUrl . $port
168 168
 						. substr($_SERVER['SCRIPT_NAME'], 0, strpos($_SERVER['SCRIPT_NAME'], basename($_SERVER['SCRIPT_FILENAME'])));
169 169
 				}
170
-				else{
170
+				else {
171 171
 					$logger->warning('Can not determine the application base URL automatically, use http://localhost as default');
172 172
 					$baseUrl = 'http://localhost/';
173 173
 				}
174 174
 				self::set('base_url', $baseUrl);
175 175
 			}
176
-			self::$config['base_url'] = rtrim(self::$config['base_url'], '/') .'/';
176
+			self::$config['base_url'] = rtrim(self::$config['base_url'], '/') . '/';
177 177
 		}
178 178
 	}
Please login to merge, or discard this patch.
Braces   +2 added lines, -4 removed lines patch added patch discarded remove patch
@@ -128,8 +128,7 @@  discard block
 block discarded – undo
128 128
 				$logger->info('Delete config item ['.$item.']');
129 129
 				unset(self::$config[$item]);
130 130
 				return true;
131
-			}
132
-			else{
131
+			} else{
133 132
 				$logger->warning('Config item ['.$item.'] to be deleted does not exists');
134 133
 				return false;
135 134
 			}
@@ -166,8 +165,7 @@  discard block
 block discarded – undo
166 165
 					$port = ((($serverPort != '80' && ! is_https()) || ($serverPort != '443' && is_https())) ? ':' . $serverPort : '');
167 166
 					$baseUrl = (is_https() ? 'https' : 'http').'://' . $baseUrl . $port
168 167
 						. substr($_SERVER['SCRIPT_NAME'], 0, strpos($_SERVER['SCRIPT_NAME'], basename($_SERVER['SCRIPT_FILENAME'])));
169
-				}
170
-				else{
168
+				} else{
171 169
 					$logger->warning('Can not determine the application base URL automatically, use http://localhost as default');
172 170
 					$baseUrl = 'http://localhost/';
173 171
 				}
Please login to merge, or discard this patch.
core/functions/function_user_agent.php 2 patches
Indentation   +70 added lines, -70 removed lines patch added patch discarded remove patch
@@ -1,75 +1,75 @@
 block discarded – undo
1 1
 <?php
2
-	defined('ROOT_PATH') || exit('Access denied');
3
-	/**
4
-	 * TNH Framework
5
-	 *
6
-	 * A simple PHP framework using HMVC architecture
7
-	 *
8
-	 * This content is released under the GNU GPL License (GPL)
9
-	 *
10
-	 * Copyright (C) 2017 Tony NGUEREZA
11
-	 *
12
-	 * This program is free software; you can redistribute it and/or
13
-	 * modify it under the terms of the GNU General Public License
14
-	 * as published by the Free Software Foundation; either version 3
15
-	 * of the License, or (at your option) any later version.
16
-	 *
17
-	 * This program is distributed in the hope that it will be useful,
18
-	 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
-	 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
-	 * GNU General Public License for more details.
21
-	 *
22
-	 * You should have received a copy of the GNU General Public License
23
-	 * along with this program; if not, write to the Free Software
24
-	 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25
-	*/
2
+    defined('ROOT_PATH') || exit('Access denied');
3
+    /**
4
+     * TNH Framework
5
+     *
6
+     * A simple PHP framework using HMVC architecture
7
+     *
8
+     * This content is released under the GNU GPL License (GPL)
9
+     *
10
+     * Copyright (C) 2017 Tony NGUEREZA
11
+     *
12
+     * This program is free software; you can redistribute it and/or
13
+     * modify it under the terms of the GNU General Public License
14
+     * as published by the Free Software Foundation; either version 3
15
+     * of the License, or (at your option) any later version.
16
+     *
17
+     * This program is distributed in the hope that it will be useful,
18
+     * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
+     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
+     * GNU General Public License for more details.
21
+     *
22
+     * You should have received a copy of the GNU General Public License
23
+     * along with this program; if not, write to the Free Software
24
+     * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25
+     */
26 26
 
27 27
 
28
-	/**
29
-	 *  @file function_user_agent.php
30
-	 *    
31
-	 *  Contains most of the utility functions for agent, platform, mobile, browser, and other management.
32
-	 *  
33
-	 *  @package	core
34
-	 *  @author	Tony NGUEREZA
35
-	 *  @copyright	Copyright (c) 2017
36
-	 *  @license	https://opensource.org/licenses/gpl-3.0.html GNU GPL License (GPL)
37
-	 *  @link	http://www.iacademy.cf
38
-	 *  @version 1.0.0
39
-	 *  @since 1.0.0
40
-	 *  @filesource
41
-	 */
28
+    /**
29
+     *  @file function_user_agent.php
30
+     *    
31
+     *  Contains most of the utility functions for agent, platform, mobile, browser, and other management.
32
+     *  
33
+     *  @package	core
34
+     *  @author	Tony NGUEREZA
35
+     *  @copyright	Copyright (c) 2017
36
+     *  @license	https://opensource.org/licenses/gpl-3.0.html GNU GPL License (GPL)
37
+     *  @link	http://www.iacademy.cf
38
+     *  @version 1.0.0
39
+     *  @since 1.0.0
40
+     *  @filesource
41
+     */
42 42
 	
43 43
 	 
44
-	if(! function_exists('get_ip')){
45
-		/**
46
-		 *  Retrieves the user's IP address
47
-		 *  
48
-		 *  This function allows to retrieve the IP address of the client
49
-		 *  even if it uses a proxy, the actual IP address is retrieved.
50
-		 *  
51
-		 *  @return string the IP address.
52
-		 */
53
-		function get_ip(){
54
-			$ip = '127.0.0.1';
55
-			$ipServerVars = array(
56
-								'REMOTE_ADDR',
57
-								'HTTP_CLIENT_IP',
58
-								'HTTP_X_FORWARDED_FOR',
59
-								'HTTP_X_FORWARDED',
60
-								'HTTP_FORWARDED_FOR',
61
-								'HTTP_FORWARDED'
62
-							);
63
-			foreach ($ipServerVars as $var) {
64
-				if(isset($_SERVER[$var])){
65
-					$ip = $_SERVER[$var];
66
-					break;
67
-				}
68
-			}
69
-			// Strip any secondary IP etc from the IP address
70
-			if (strpos($ip, ',') > 0) {
71
-				$ip = substr($ip, 0, strpos($ip, ','));
72
-			}
73
-			return $ip;
74
-		}
75
-	}
44
+    if(! function_exists('get_ip')){
45
+        /**
46
+         *  Retrieves the user's IP address
47
+         *  
48
+         *  This function allows to retrieve the IP address of the client
49
+         *  even if it uses a proxy, the actual IP address is retrieved.
50
+         *  
51
+         *  @return string the IP address.
52
+         */
53
+        function get_ip(){
54
+            $ip = '127.0.0.1';
55
+            $ipServerVars = array(
56
+                                'REMOTE_ADDR',
57
+                                'HTTP_CLIENT_IP',
58
+                                'HTTP_X_FORWARDED_FOR',
59
+                                'HTTP_X_FORWARDED',
60
+                                'HTTP_FORWARDED_FOR',
61
+                                'HTTP_FORWARDED'
62
+                            );
63
+            foreach ($ipServerVars as $var) {
64
+                if(isset($_SERVER[$var])){
65
+                    $ip = $_SERVER[$var];
66
+                    break;
67
+                }
68
+            }
69
+            // Strip any secondary IP etc from the IP address
70
+            if (strpos($ip, ',') > 0) {
71
+                $ip = substr($ip, 0, strpos($ip, ','));
72
+            }
73
+            return $ip;
74
+        }
75
+    }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -41,7 +41,7 @@  discard block
 block discarded – undo
41 41
 	 */
42 42
 	
43 43
 	 
44
-	if(! function_exists('get_ip')){
44
+	if (!function_exists('get_ip')) {
45 45
 		/**
46 46
 		 *  Retrieves the user's IP address
47 47
 		 *  
@@ -50,7 +50,7 @@  discard block
 block discarded – undo
50 50
 		 *  
51 51
 		 *  @return string the IP address.
52 52
 		 */
53
-		function get_ip(){
53
+		function get_ip() {
54 54
 			$ip = '127.0.0.1';
55 55
 			$ipServerVars = array(
56 56
 								'REMOTE_ADDR',
@@ -61,7 +61,7 @@  discard block
 block discarded – undo
61 61
 								'HTTP_FORWARDED'
62 62
 							);
63 63
 			foreach ($ipServerVars as $var) {
64
-				if(isset($_SERVER[$var])){
64
+				if (isset($_SERVER[$var])) {
65 65
 					$ip = $_SERVER[$var];
66 66
 					break;
67 67
 				}
Please login to merge, or discard this patch.
core/libraries/Assets.php 2 patches
Indentation   +154 added lines, -154 removed lines patch added patch discarded remove patch
@@ -1,168 +1,168 @@
 block discarded – undo
1 1
 <?php
2
-	defined('ROOT_PATH') || exit('Access denied');
3
-	/**
4
-	 * TNH Framework
5
-	 *
6
-	 * A simple PHP framework using HMVC architecture
7
-	 *
8
-	 * This content is released under the GNU GPL License (GPL)
9
-	 *
10
-	 * Copyright (C) 2017 Tony NGUEREZA
11
-	 *
12
-	 * This program is free software; you can redistribute it and/or
13
-	 * modify it under the terms of the GNU General Public License
14
-	 * as published by the Free Software Foundation; either version 3
15
-	 * of the License, or (at your option) any later version.
16
-	 *
17
-	 * This program is distributed in the hope that it will be useful,
18
-	 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
-	 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
-	 * GNU General Public License for more details.
21
-	 *
22
-	 * You should have received a copy of the GNU General Public License
23
-	 * along with this program; if not, write to the Free Software
24
-	 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25
-	*/
2
+    defined('ROOT_PATH') || exit('Access denied');
3
+    /**
4
+     * TNH Framework
5
+     *
6
+     * A simple PHP framework using HMVC architecture
7
+     *
8
+     * This content is released under the GNU GPL License (GPL)
9
+     *
10
+     * Copyright (C) 2017 Tony NGUEREZA
11
+     *
12
+     * This program is free software; you can redistribute it and/or
13
+     * modify it under the terms of the GNU General Public License
14
+     * as published by the Free Software Foundation; either version 3
15
+     * of the License, or (at your option) any later version.
16
+     *
17
+     * This program is distributed in the hope that it will be useful,
18
+     * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
+     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
+     * GNU General Public License for more details.
21
+     *
22
+     * You should have received a copy of the GNU General Public License
23
+     * along with this program; if not, write to the Free Software
24
+     * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25
+     */
26 26
 
27
-	/**
28
-	 *  @file Assets.php
29
-	 *    
30
-	 *  This class contains static methods for generating static content links (images, Javascript, CSS, etc.).
31
-	 *  
32
-	 *  @package	core	
33
-	 *  @author	Tony NGUEREZA
34
-	 *  @copyright	Copyright (c) 2017
35
-	 *  @license	https://opensource.org/licenses/gpl-3.0.html GNU GPL License (GPL)
36
-	 *  @link	http://www.iacademy.cf
37
-	 *  @version 1.0.0
38
-	 *  @since 1.0.0
39
-	 *  @filesource
40
-	 */
41
-	class Assets{
27
+    /**
28
+     *  @file Assets.php
29
+     *    
30
+     *  This class contains static methods for generating static content links (images, Javascript, CSS, etc.).
31
+     *  
32
+     *  @package	core	
33
+     *  @author	Tony NGUEREZA
34
+     *  @copyright	Copyright (c) 2017
35
+     *  @license	https://opensource.org/licenses/gpl-3.0.html GNU GPL License (GPL)
36
+     *  @link	http://www.iacademy.cf
37
+     *  @version 1.0.0
38
+     *  @since 1.0.0
39
+     *  @filesource
40
+     */
41
+    class Assets{
42 42
 		
43
-		/**
44
-		 * The logger instance
45
-		 * @var object
46
-		 */
47
-		private static $logger;
43
+        /**
44
+         * The logger instance
45
+         * @var object
46
+         */
47
+        private static $logger;
48 48
 
49
-		/**
50
-		 * The signleton of the logger
51
-		 * @return Object the Log instance
52
-		 */
53
-		private static function getLogger(){
54
-			if(self::$logger == null){
55
-				//can't assign reference to static variable
56
-				self::$logger[0] =& class_loader('Log', 'classes');
57
-				self::$logger[0]->setLogger('Library::Assets');
58
-			}
59
-			return self::$logger[0];
60
-		}
49
+        /**
50
+         * The signleton of the logger
51
+         * @return Object the Log instance
52
+         */
53
+        private static function getLogger(){
54
+            if(self::$logger == null){
55
+                //can't assign reference to static variable
56
+                self::$logger[0] =& class_loader('Log', 'classes');
57
+                self::$logger[0]->setLogger('Library::Assets');
58
+            }
59
+            return self::$logger[0];
60
+        }
61 61
 
62 62
 
63
-		/**
64
-		 *  Generate the link of the assets file.
65
-		 *  
66
-		 *  Generates the absolute link of a file inside ASSETS_PATH folder.
67
-		 *  For example :
68
-		 *  	echo Assets::path('foo/bar/css/style.css'); => http://mysite.com/assets/foo/bar/css/style.css
69
-		 *  Note:
70
-		 *  The argument passed to this function must be the relative link to the folder that contains the static contents defined by the constant ASSETS_PATH.
71
-		 *  
72
-		 *  @param string $asset the name of the assets file path with the extension.
73
-		 *  @return string|null the absolute path of the assets file, if it exists otherwise returns null if the file does not exist.
74
-		 */
75
-		public static function path($asset){
76
-			$logger = self::getLogger();	
77
-			$path = ASSETS_PATH . $asset;
63
+        /**
64
+         *  Generate the link of the assets file.
65
+         *  
66
+         *  Generates the absolute link of a file inside ASSETS_PATH folder.
67
+         *  For example :
68
+         *  	echo Assets::path('foo/bar/css/style.css'); => http://mysite.com/assets/foo/bar/css/style.css
69
+         *  Note:
70
+         *  The argument passed to this function must be the relative link to the folder that contains the static contents defined by the constant ASSETS_PATH.
71
+         *  
72
+         *  @param string $asset the name of the assets file path with the extension.
73
+         *  @return string|null the absolute path of the assets file, if it exists otherwise returns null if the file does not exist.
74
+         */
75
+        public static function path($asset){
76
+            $logger = self::getLogger();	
77
+            $path = ASSETS_PATH . $asset;
78 78
 			
79
-			$logger->debug('Including the Assets file [' . $path . ']');
80
-			//Check if the file exists
81
-			if(file_exists($path)){
82
-				$logger->info('Assets file [' . $path . '] included successfully');
83
-				return Url::base_url($path);
84
-			}
85
-			$logger->warning('Assets file [' . $path . '] does not exist');
86
-			return null;
87
-		}
79
+            $logger->debug('Including the Assets file [' . $path . ']');
80
+            //Check if the file exists
81
+            if(file_exists($path)){
82
+                $logger->info('Assets file [' . $path . '] included successfully');
83
+                return Url::base_url($path);
84
+            }
85
+            $logger->warning('Assets file [' . $path . '] does not exist');
86
+            return null;
87
+        }
88 88
 		
89
-		/**
90
-		 *  Generate the link of the css file.
91
-		 *  
92
-		 *  Generates the absolute link of a file containing the CSS style.
93
-		 *  For example :
94
-		 *  	echo Assets::css('mystyle'); => http://mysite.com/assets/css/mystyle.css
95
-		 *  Note:
96
-		 *  The argument passed to this function must be the relative link to the folder that contains the static contents defined by the constant ASSETS_PATH.
97
-		 *  
98
-		 *  @param string $path the name of the css file without the extension.
99
-		 *  @return string|null the absolute path of the css file, if it exists otherwise returns null if the file does not exist.
100
-		 */
101
-		public static function css($path){
102
-			$logger = self::getLogger();
103
-			/*
89
+        /**
90
+         *  Generate the link of the css file.
91
+         *  
92
+         *  Generates the absolute link of a file containing the CSS style.
93
+         *  For example :
94
+         *  	echo Assets::css('mystyle'); => http://mysite.com/assets/css/mystyle.css
95
+         *  Note:
96
+         *  The argument passed to this function must be the relative link to the folder that contains the static contents defined by the constant ASSETS_PATH.
97
+         *  
98
+         *  @param string $path the name of the css file without the extension.
99
+         *  @return string|null the absolute path of the css file, if it exists otherwise returns null if the file does not exist.
100
+         */
101
+        public static function css($path){
102
+            $logger = self::getLogger();
103
+            /*
104 104
 			* if the file name contains the ".css" extension, replace it with 
105 105
 			* an empty string for better processing.
106 106
 			*/
107
-			$path = str_ireplace('.css', '', $path);
108
-			$path = ASSETS_PATH . 'css/' . $path . '.css';
107
+            $path = str_ireplace('.css', '', $path);
108
+            $path = ASSETS_PATH . 'css/' . $path . '.css';
109 109
 			
110
-			$logger->debug('Including the Assets file [' . $path . '] for CSS');
111
-			//Check if the file exists
112
-			if(file_exists($path)){
113
-				$logger->info('Assets file [' . $path . '] for CSS included successfully');
114
-				return Url::base_url($path);
115
-			}
116
-			$logger->warning('Assets file [' . $path . '] for CSS does not exist');
117
-			return null;
118
-		}
110
+            $logger->debug('Including the Assets file [' . $path . '] for CSS');
111
+            //Check if the file exists
112
+            if(file_exists($path)){
113
+                $logger->info('Assets file [' . $path . '] for CSS included successfully');
114
+                return Url::base_url($path);
115
+            }
116
+            $logger->warning('Assets file [' . $path . '] for CSS does not exist');
117
+            return null;
118
+        }
119 119
 
120
-		/**
121
-		 *  Generate the link of the javascript file.
122
-		 *  
123
-		 *  Generates the absolute link of a file containing the javascript.
124
-		 *  For example :
125
-		 *  	echo Assets::js('myscript'); => http://mysite.com/assets/js/myscript.js
126
-		 *  Note:
127
-		 *  The argument passed to this function must be the relative link to the folder that contains the static contents defined by the constant ASSETS_PATH.
128
-		 *  
129
-		 *  @param string $path the name of the javascript file without the extension.
130
-		 *  @return string|null the absolute path of the javascript file, if it exists otherwise returns null if the file does not exist.
131
-		 */
132
-		public static function js($path){
133
-			$logger = self::getLogger();
134
-			$path = str_ireplace('.js', '', $path);
135
-			$path = ASSETS_PATH . 'js/' . $path . '.js';
136
-			$logger->debug('Including the Assets file [' . $path . '] for javascript');
137
-			if(file_exists($path)){
138
-				$logger->info('Assets file [' . $path . '] for Javascript included successfully');
139
-				return Url::base_url($path);
140
-			}
141
-			$logger->warning('Assets file [' . $path . '] for Javascript does not exist');
142
-			return null;
143
-		}
120
+        /**
121
+         *  Generate the link of the javascript file.
122
+         *  
123
+         *  Generates the absolute link of a file containing the javascript.
124
+         *  For example :
125
+         *  	echo Assets::js('myscript'); => http://mysite.com/assets/js/myscript.js
126
+         *  Note:
127
+         *  The argument passed to this function must be the relative link to the folder that contains the static contents defined by the constant ASSETS_PATH.
128
+         *  
129
+         *  @param string $path the name of the javascript file without the extension.
130
+         *  @return string|null the absolute path of the javascript file, if it exists otherwise returns null if the file does not exist.
131
+         */
132
+        public static function js($path){
133
+            $logger = self::getLogger();
134
+            $path = str_ireplace('.js', '', $path);
135
+            $path = ASSETS_PATH . 'js/' . $path . '.js';
136
+            $logger->debug('Including the Assets file [' . $path . '] for javascript');
137
+            if(file_exists($path)){
138
+                $logger->info('Assets file [' . $path . '] for Javascript included successfully');
139
+                return Url::base_url($path);
140
+            }
141
+            $logger->warning('Assets file [' . $path . '] for Javascript does not exist');
142
+            return null;
143
+        }
144 144
 
145
-		/**
146
-		 *  Generate the link of the image file.
147
-		 *  
148
-		 *  Generates the absolute link of a file containing the image.
149
-		 *  For example :
150
-		 *  	echo Assets::img('myimage.png'); => http://mysite.com/assets/images/myimage.png
151
-		 *  Note:
152
-		 *  The argument passed to this function must be the relative link to the folder that contains the static contents defined by the constant ASSETS_PATH.
153
-		 *  
154
-		 *  @param string $path the name of the image file with the extension.
155
-		 *  @return string|null the absolute path of the image file, if it exists otherwise returns null if the file does not exist.
156
-		 */
157
-		public static function img($path){
158
-			$logger = self::getLogger();
159
-			$path = ASSETS_PATH . 'images/' . $path;
160
-			$logger->debug('Including the Assets file [' . $path . '] for image');
161
-			if(file_exists($path)){
162
-				$logger->info('Assets file [' . $path . '] for image included successfully');
163
-				return Url::base_url($path);
164
-			}
165
-			$logger->warning('Assets file [' . $path . '] for image does not exist');
166
-			return null;
167
-		}
168
-	}
145
+        /**
146
+         *  Generate the link of the image file.
147
+         *  
148
+         *  Generates the absolute link of a file containing the image.
149
+         *  For example :
150
+         *  	echo Assets::img('myimage.png'); => http://mysite.com/assets/images/myimage.png
151
+         *  Note:
152
+         *  The argument passed to this function must be the relative link to the folder that contains the static contents defined by the constant ASSETS_PATH.
153
+         *  
154
+         *  @param string $path the name of the image file with the extension.
155
+         *  @return string|null the absolute path of the image file, if it exists otherwise returns null if the file does not exist.
156
+         */
157
+        public static function img($path){
158
+            $logger = self::getLogger();
159
+            $path = ASSETS_PATH . 'images/' . $path;
160
+            $logger->debug('Including the Assets file [' . $path . '] for image');
161
+            if(file_exists($path)){
162
+                $logger->info('Assets file [' . $path . '] for image included successfully');
163
+                return Url::base_url($path);
164
+            }
165
+            $logger->warning('Assets file [' . $path . '] for image does not exist');
166
+            return null;
167
+        }
168
+    }
Please login to merge, or discard this patch.
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -38,7 +38,7 @@  discard block
 block discarded – undo
38 38
 	 *  @since 1.0.0
39 39
 	 *  @filesource
40 40
 	 */
41
-	class Assets{
41
+	class Assets {
42 42
 		
43 43
 		/**
44 44
 		 * The logger instance
@@ -50,10 +50,10 @@  discard block
 block discarded – undo
50 50
 		 * The signleton of the logger
51 51
 		 * @return Object the Log instance
52 52
 		 */
53
-		private static function getLogger(){
54
-			if(self::$logger == null){
53
+		private static function getLogger() {
54
+			if (self::$logger == null) {
55 55
 				//can't assign reference to static variable
56
-				self::$logger[0] =& class_loader('Log', 'classes');
56
+				self::$logger[0] = & class_loader('Log', 'classes');
57 57
 				self::$logger[0]->setLogger('Library::Assets');
58 58
 			}
59 59
 			return self::$logger[0];
@@ -72,13 +72,13 @@  discard block
 block discarded – undo
72 72
 		 *  @param string $asset the name of the assets file path with the extension.
73 73
 		 *  @return string|null the absolute path of the assets file, if it exists otherwise returns null if the file does not exist.
74 74
 		 */
75
-		public static function path($asset){
75
+		public static function path($asset) {
76 76
 			$logger = self::getLogger();	
77 77
 			$path = ASSETS_PATH . $asset;
78 78
 			
79 79
 			$logger->debug('Including the Assets file [' . $path . ']');
80 80
 			//Check if the file exists
81
-			if(file_exists($path)){
81
+			if (file_exists($path)) {
82 82
 				$logger->info('Assets file [' . $path . '] included successfully');
83 83
 				return Url::base_url($path);
84 84
 			}
@@ -98,7 +98,7 @@  discard block
 block discarded – undo
98 98
 		 *  @param string $path the name of the css file without the extension.
99 99
 		 *  @return string|null the absolute path of the css file, if it exists otherwise returns null if the file does not exist.
100 100
 		 */
101
-		public static function css($path){
101
+		public static function css($path) {
102 102
 			$logger = self::getLogger();
103 103
 			/*
104 104
 			* if the file name contains the ".css" extension, replace it with 
@@ -109,7 +109,7 @@  discard block
 block discarded – undo
109 109
 			
110 110
 			$logger->debug('Including the Assets file [' . $path . '] for CSS');
111 111
 			//Check if the file exists
112
-			if(file_exists($path)){
112
+			if (file_exists($path)) {
113 113
 				$logger->info('Assets file [' . $path . '] for CSS included successfully');
114 114
 				return Url::base_url($path);
115 115
 			}
@@ -129,12 +129,12 @@  discard block
 block discarded – undo
129 129
 		 *  @param string $path the name of the javascript file without the extension.
130 130
 		 *  @return string|null the absolute path of the javascript file, if it exists otherwise returns null if the file does not exist.
131 131
 		 */
132
-		public static function js($path){
132
+		public static function js($path) {
133 133
 			$logger = self::getLogger();
134 134
 			$path = str_ireplace('.js', '', $path);
135 135
 			$path = ASSETS_PATH . 'js/' . $path . '.js';
136 136
 			$logger->debug('Including the Assets file [' . $path . '] for javascript');
137
-			if(file_exists($path)){
137
+			if (file_exists($path)) {
138 138
 				$logger->info('Assets file [' . $path . '] for Javascript included successfully');
139 139
 				return Url::base_url($path);
140 140
 			}
@@ -154,11 +154,11 @@  discard block
 block discarded – undo
154 154
 		 *  @param string $path the name of the image file with the extension.
155 155
 		 *  @return string|null the absolute path of the image file, if it exists otherwise returns null if the file does not exist.
156 156
 		 */
157
-		public static function img($path){
157
+		public static function img($path) {
158 158
 			$logger = self::getLogger();
159 159
 			$path = ASSETS_PATH . 'images/' . $path;
160 160
 			$logger->debug('Including the Assets file [' . $path . '] for image');
161
-			if(file_exists($path)){
161
+			if (file_exists($path)) {
162 162
 				$logger->info('Assets file [' . $path . '] for image included successfully');
163 163
 				return Url::base_url($path);
164 164
 			}
Please login to merge, or discard this patch.