Passed
Push — 1.0.0-dev ( 407604...83bedf )
by nguereza
03:26
created
index.php 2 patches
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -242,8 +242,7 @@
 block discarded – undo
242 242
 			ini_set('display_errors', 0);
243 243
 			if (version_compare(PHP_VERSION, '5.3', '>=')) {
244 244
 				error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED & ~E_STRICT & ~E_USER_NOTICE & ~E_USER_DEPRECATED);
245
-			}
246
-			else{
245
+			} else{
247 246
 				error_reporting(E_ALL & ~E_NOTICE & ~E_STRICT & ~E_USER_NOTICE);
248 247
 			}
249 248
 		break;
Please login to merge, or discard this patch.
Indentation   +230 added lines, -230 removed lines patch added patch discarded remove patch
@@ -1,260 +1,260 @@
 block discarded – undo
1 1
 <?php
2
-	/**
3
-	 * TNH Framework
4
-	 *
5
-	 * A simple PHP framework using HMVC architecture
6
-	 *
7
-	 * This content is released under the GNU GPL License (GPL)
8
-	 *
9
-	 * Copyright (C) 2017 Tony NGUEREZA
10
-	 *
11
-	 * This program is free software; you can redistribute it and/or
12
-	 * modify it under the terms of the GNU General Public License
13
-	 * as published by the Free Software Foundation; either version 3
14
-	 * of the License, or (at your option) any later version.
15
-	 *
16
-	 * This program is distributed in the hope that it will be useful,
17
-	 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18
-	 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19
-	 * GNU General Public License for more details.
20
-	 *
21
-	 * You should have received a copy of the GNU General Public License
22
-	 * along with this program; if not, write to the Free Software
23
-	 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
24
-	*/
2
+    /**
3
+     * TNH Framework
4
+     *
5
+     * A simple PHP framework using HMVC architecture
6
+     *
7
+     * This content is released under the GNU GPL License (GPL)
8
+     *
9
+     * Copyright (C) 2017 Tony NGUEREZA
10
+     *
11
+     * This program is free software; you can redistribute it and/or
12
+     * modify it under the terms of the GNU General Public License
13
+     * as published by the Free Software Foundation; either version 3
14
+     * of the License, or (at your option) any later version.
15
+     *
16
+     * This program is distributed in the hope that it will be useful,
17
+     * but WITHOUT ANY WARRANTY; without even the implied warranty of
18
+     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19
+     * GNU General Public License for more details.
20
+     *
21
+     * You should have received a copy of the GNU General Public License
22
+     * along with this program; if not, write to the Free Software
23
+     * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
24
+     */
25 25
 
26
-	/**
27
-	* the directory separator, under windows it is \ and unix, linux /
28
-	*/
29
-	define('DS', DIRECTORY_SEPARATOR);
26
+    /**
27
+     * the directory separator, under windows it is \ and unix, linux /
28
+     */
29
+    define('DS', DIRECTORY_SEPARATOR);
30 30
 
31
-	/**
32
-	* The root directory of the application.
33
-	*
34
-	* you can place this directory outside of your web directory, for example "/home/your_app", etc.
35
-	*/
36
-	define('ROOT_PATH', dirname(realpath(__FILE__)) . DS);
31
+    /**
32
+     * The root directory of the application.
33
+     *
34
+     * you can place this directory outside of your web directory, for example "/home/your_app", etc.
35
+     */
36
+    define('ROOT_PATH', dirname(realpath(__FILE__)) . DS);
37 37
 
38
-	/**
39
-	* The path to the directory.
40
-	*
41
-	* That contains your static files (javascript, css, images, etc.)
42
-	* Note: the path must be relative to the file index.php (the front-end controller).
43
-	*/
44
-	define('ASSETS_PATH', 'assets/');
38
+    /**
39
+     * The path to the directory.
40
+     *
41
+     * That contains your static files (javascript, css, images, etc.)
42
+     * Note: the path must be relative to the file index.php (the front-end controller).
43
+     */
44
+    define('ASSETS_PATH', 'assets/');
45 45
 
46
-	/**
47
-	* The path to the directory of your cache files.
48
-	*
49
-	* This feature is available currently for database and views.
50
-	*/
51
-	define('CACHE_PATH', ROOT_PATH . 'cache' . DS);
46
+    /**
47
+     * The path to the directory of your cache files.
48
+     *
49
+     * This feature is available currently for database and views.
50
+     */
51
+    define('CACHE_PATH', ROOT_PATH . 'cache' . DS);
52 52
 
53
-	/**
54
-	* The path to the application directory. 
55
-	*
56
-	* It contains your most often used files that is to say which contains your files of the application, 
57
-	* in MVC architecture (controllers, models, views).
58
-	*/
59
-	define('APPS_PATH', ROOT_PATH . 'classes' . DS);
53
+    /**
54
+     * The path to the application directory. 
55
+     *
56
+     * It contains your most often used files that is to say which contains your files of the application, 
57
+     * in MVC architecture (controllers, models, views).
58
+     */
59
+    define('APPS_PATH', ROOT_PATH . 'classes' . DS);
60 60
 
61
-	/**
62
-	* The path to the controller directory of your application.
63
-	*
64
-	* If you already know the MVC architecture you know what a controller means; 
65
-	* it is he who makes the business logic of your application in general.
66
-	*/
67
-	define('APPS_CONTROLLER_PATH', APPS_PATH . 'controllers' . DS);
61
+    /**
62
+     * The path to the controller directory of your application.
63
+     *
64
+     * If you already know the MVC architecture you know what a controller means; 
65
+     * it is he who makes the business logic of your application in general.
66
+     */
67
+    define('APPS_CONTROLLER_PATH', APPS_PATH . 'controllers' . DS);
68 68
 
69
-	/**
70
-	* The path to the directory of your model classes of your application. 
71
-	*
72
-	* If you already know the MVC architecture you know what a model means; 
73
-	* it's the one who interacts with the database, in one word persistent data from your application.
74
-	*/
75
-	define('APPS_MODEL_PATH', APPS_PATH . 'models' . DS);
69
+    /**
70
+     * The path to the directory of your model classes of your application. 
71
+     *
72
+     * If you already know the MVC architecture you know what a model means; 
73
+     * it's the one who interacts with the database, in one word persistent data from your application.
74
+     */
75
+    define('APPS_MODEL_PATH', APPS_PATH . 'models' . DS);
76 76
 
77
-	/**
78
-	* The path to the directory of your views.
79
-	*
80
-	* If you already know the MVC architecture you know what a view means, 
81
-	* a view is just a user interface (html page, form, etc.) that is to say 
82
-	* everything displayed in the browser interface, etc.
83
-	*/
84
-	define('APPS_VIEWS_PATH', APPS_PATH . 'views' . DS);
77
+    /**
78
+     * The path to the directory of your views.
79
+     *
80
+     * If you already know the MVC architecture you know what a view means, 
81
+     * a view is just a user interface (html page, form, etc.) that is to say 
82
+     * everything displayed in the browser interface, etc.
83
+     */
84
+    define('APPS_VIEWS_PATH', APPS_PATH . 'views' . DS);
85 85
 
86
-	/**
87
-	* The path to the configuration directory.
88
-	*
89
-	* That contains most of the configuration files for your 
90
-	* application (database, class loading file, functions, etc.)
91
-	*/
92
-	define('CONFIG_PATH', ROOT_PATH . 'config' . DS);
86
+    /**
87
+     * The path to the configuration directory.
88
+     *
89
+     * That contains most of the configuration files for your 
90
+     * application (database, class loading file, functions, etc.)
91
+     */
92
+    define('CONFIG_PATH', ROOT_PATH . 'config' . DS);
93 93
 
94
-	/** 
95
-	* The core directory
96
-	*
97
-	* It is recommended to put this folder out of the web directory of your server and 
98
-	* you should not change its content because in case of update you could lose the modified files.
99
-	*/
100
-	define('CORE_PATH', ROOT_PATH . 'core' . DS);
94
+    /** 
95
+     * The core directory
96
+     *
97
+     * It is recommended to put this folder out of the web directory of your server and 
98
+     * you should not change its content because in case of update you could lose the modified files.
99
+     */
100
+    define('CORE_PATH', ROOT_PATH . 'core' . DS);
101 101
 	
102
-	/**
103
-	* The path to the directory of core classes that used by the system.
104
-	*
105
-	* It contains PHP classes that are used by the framework internally.
106
-	*/
107
-	define('CORE_CLASSES_PATH', CORE_PATH . 'classes' . DS);
102
+    /**
103
+     * The path to the directory of core classes that used by the system.
104
+     *
105
+     * It contains PHP classes that are used by the framework internally.
106
+     */
107
+    define('CORE_CLASSES_PATH', CORE_PATH . 'classes' . DS);
108 108
 	
109
-	/**
110
-	* The path to the directory of core classes for the cache used by the system.
111
-	*
112
-	* It contains PHP classes for the cache drivers.
113
-	*/
114
-	define('CORE_CLASSES_CACHE_PATH', CORE_CLASSES_PATH . 'cache' . DS);
109
+    /**
110
+     * The path to the directory of core classes for the cache used by the system.
111
+     *
112
+     * It contains PHP classes for the cache drivers.
113
+     */
114
+    define('CORE_CLASSES_CACHE_PATH', CORE_CLASSES_PATH . 'cache' . DS);
115 115
 	
116
-	/**
117
-	* The path to the directory of core classes for the model used by the system.
118
-	*
119
-	* It contains PHP classes for the models.
120
-	*/
121
-	define('CORE_CLASSES_MODEL_PATH', CORE_CLASSES_PATH . 'model' . DS);
116
+    /**
117
+     * The path to the directory of core classes for the model used by the system.
118
+     *
119
+     * It contains PHP classes for the models.
120
+     */
121
+    define('CORE_CLASSES_MODEL_PATH', CORE_CLASSES_PATH . 'model' . DS);
122 122
 
123
-	/**
124
-	* The path to the directory of functions or helper systems.
125
-	*
126
-	* It contains PHP functions that perform a particular task: character string processing, URL, etc.
127
-	*/
128
-	define('CORE_FUNCTIONS_PATH', CORE_PATH . 'functions' . DS);
123
+    /**
124
+     * The path to the directory of functions or helper systems.
125
+     *
126
+     * It contains PHP functions that perform a particular task: character string processing, URL, etc.
127
+     */
128
+    define('CORE_FUNCTIONS_PATH', CORE_PATH . 'functions' . DS);
129 129
 
130
-	/**
131
-	* The path to the core directory of languages files. 
132
-	*
133
-	*/
134
-	define('CORE_LANG_PATH', CORE_PATH . 'lang' . DS);
130
+    /**
131
+     * The path to the core directory of languages files. 
132
+     *
133
+     */
134
+    define('CORE_LANG_PATH', CORE_PATH . 'lang' . DS);
135 135
 
136
-	/**
137
-	* The path to the system library directory.
138
-	*
139
-	* Which contains the libraries most often used in your web application, as for the 
140
-	* core directory it is advisable to put it out of the root directory of your application.
141
-	*/
142
-	define('CORE_LIBRARY_PATH', CORE_PATH . 'libraries' . DS);
136
+    /**
137
+     * The path to the system library directory.
138
+     *
139
+     * Which contains the libraries most often used in your web application, as for the 
140
+     * core directory it is advisable to put it out of the root directory of your application.
141
+     */
142
+    define('CORE_LIBRARY_PATH', CORE_PATH . 'libraries' . DS);
143 143
 
144
-	/**
145
-	* The path to the system view directory.
146
-	*
147
-	* That contains the views used for the system, such as error messages, and so on.
148
-	*/
149
-	define('CORE_VIEWS_PATH', CORE_PATH . 'views' . DS);
144
+    /**
145
+     * The path to the system view directory.
146
+     *
147
+     * That contains the views used for the system, such as error messages, and so on.
148
+     */
149
+    define('CORE_VIEWS_PATH', CORE_PATH . 'views' . DS);
150 150
 	
151
-	/**
152
-	* The path to the directory of your PHP personal functions or helper.
153
-	*
154
-	* It contains your PHP functions that perform a particular task: utilities, etc.
155
-	* Note: Do not put your personal functions or helpers in the system functions directory, 
156
-	* because if you update the system you may lose them.
157
-	*/
158
-	define('FUNCTIONS_PATH', ROOT_PATH . 'functions' . DS);
151
+    /**
152
+     * The path to the directory of your PHP personal functions or helper.
153
+     *
154
+     * It contains your PHP functions that perform a particular task: utilities, etc.
155
+     * Note: Do not put your personal functions or helpers in the system functions directory, 
156
+     * because if you update the system you may lose them.
157
+     */
158
+    define('FUNCTIONS_PATH', ROOT_PATH . 'functions' . DS);
159 159
 
160
-	/**
161
-	* The path to the app directory of personal language. 
162
-	*
163
-	* This feature is not yet available. 
164
-	* You can help us do this if you are nice or wish to see the developed framework.
165
-	*/
166
-	define('APP_LANG_PATH', ROOT_PATH . 'lang' . DS);
160
+    /**
161
+     * The path to the app directory of personal language. 
162
+     *
163
+     * This feature is not yet available. 
164
+     * You can help us do this if you are nice or wish to see the developed framework.
165
+     */
166
+    define('APP_LANG_PATH', ROOT_PATH . 'lang' . DS);
167 167
 
168
-	/**
169
-	* The path to the directory of your personal libraries
170
-	*
171
-	* It contains your PHP classes, package, etc.
172
-	* Note: you should not put your personal libraries in the system library directory, 
173
-	* because it is recalled in case of updating the system you might have surprises.
174
-	*/
175
-	define('LIBRARY_PATH', ROOT_PATH . 'libraries' . DS);
168
+    /**
169
+     * The path to the directory of your personal libraries
170
+     *
171
+     * It contains your PHP classes, package, etc.
172
+     * Note: you should not put your personal libraries in the system library directory, 
173
+     * because it is recalled in case of updating the system you might have surprises.
174
+     */
175
+    define('LIBRARY_PATH', ROOT_PATH . 'libraries' . DS);
176 176
 
177
-	/**
178
-	* The path to the directory that contains the log files.
179
-	*
180
-	* Note: This directory must be available in writing and if possible must have as owner the user who launches your web server, 
181
-	* under unix or linux most often with the apache web server it is "www-data" or "httpd" even "nobody" for more
182
-	* details see the documentation of your web server.
183
-	* Example for Unix or linux with apache web server:
184
-	* # chmod -R 700 /path/to/your/logs/directory/
185
-	* # chown -R www-data:www-data /path/to/your/logs/directory/
186
-	*/
187
-	define('LOGS_PATH', ROOT_PATH . 'logs' . DS);
177
+    /**
178
+     * The path to the directory that contains the log files.
179
+     *
180
+     * Note: This directory must be available in writing and if possible must have as owner the user who launches your web server, 
181
+     * under unix or linux most often with the apache web server it is "www-data" or "httpd" even "nobody" for more
182
+     * details see the documentation of your web server.
183
+     * Example for Unix or linux with apache web server:
184
+     * # chmod -R 700 /path/to/your/logs/directory/
185
+     * # chown -R www-data:www-data /path/to/your/logs/directory/
186
+     */
187
+    define('LOGS_PATH', ROOT_PATH . 'logs' . DS);
188 188
 
189
-	/**
190
-	* The path to the modules directory. 
191
-	*
192
-	* It contains your modules used files (config, controllers, libraries, etc.) that is to say which contains your files of the modules, 
193
-	* in HMVC architecture (hierichical, controllers, models, views).
194
-	*/
195
-	define('MODULE_PATH', ROOT_PATH . 'modules' . DS);
189
+    /**
190
+     * The path to the modules directory. 
191
+     *
192
+     * It contains your modules used files (config, controllers, libraries, etc.) that is to say which contains your files of the modules, 
193
+     * in HMVC architecture (hierichical, controllers, models, views).
194
+     */
195
+    define('MODULE_PATH', ROOT_PATH . 'modules' . DS);
196 196
 
197
-	/**
198
-	* The path to the directory of sources external to your application.
199
-	*
200
-	* If you have already used "composer" you know what that means.
201
-	*/
202
-	define('VENDOR_PATH', ROOT_PATH . 'vendor' . DS);
197
+    /**
198
+     * The path to the directory of sources external to your application.
199
+     *
200
+     * If you have already used "composer" you know what that means.
201
+     */
202
+    define('VENDOR_PATH', ROOT_PATH . 'vendor' . DS);
203 203
 
204
-	/**
205
-	* The front controller of your application.
206
-	*
207
-	* "index.php" it is through this file that all the requests come, there is a possibility to hidden it in the url of 
208
-	* your application by using the rewrite module URL of your web server .
209
-	* For example, under apache web server, there is a configuration example file that is located at the root 
210
-	* of your framework folder : "htaccess.txt" rename it to ".htaccess".
211
-	*/
212
-	define('SELF', pathinfo(__FILE__, PATHINFO_BASENAME));
204
+    /**
205
+     * The front controller of your application.
206
+     *
207
+     * "index.php" it is through this file that all the requests come, there is a possibility to hidden it in the url of 
208
+     * your application by using the rewrite module URL of your web server .
209
+     * For example, under apache web server, there is a configuration example file that is located at the root 
210
+     * of your framework folder : "htaccess.txt" rename it to ".htaccess".
211
+     */
212
+    define('SELF', pathinfo(__FILE__, PATHINFO_BASENAME));
213 213
 	
214
-	/**
215
-	 * Check if user run the application under CLI
216
-	 */
217
-	define('IS_CLI', stripos('cli', php_sapi_name()) !== false);
214
+    /**
215
+     * Check if user run the application under CLI
216
+     */
217
+    define('IS_CLI', stripos('cli', php_sapi_name()) !== false);
218 218
 
219
-	/**
220
-	* The environment of your application (production, test, development). 
221
-	*
222
-	* if your application is still in development you use the value "development" 
223
-	* so you will have the display of the error messages, etc. 
224
-	* Once you finish the development of your application that is to put it online 
225
-	* you change this value to "production" or "testing", in this case there will be deactivation of error messages, 
226
-	* the loading of the system, will be fast.
227
-	*/
228
-	define('ENVIRONMENT', 'development');
219
+    /**
220
+     * The environment of your application (production, test, development). 
221
+     *
222
+     * if your application is still in development you use the value "development" 
223
+     * so you will have the display of the error messages, etc. 
224
+     * Once you finish the development of your application that is to put it online 
225
+     * you change this value to "production" or "testing", in this case there will be deactivation of error messages, 
226
+     * the loading of the system, will be fast.
227
+     */
228
+    define('ENVIRONMENT', 'development');
229 229
 
230
-	/* ---------------------------------------------------------------------------------- */
231
-	///////////////////////////////////////////////////////////////////////////////////////
232
-	/******************** DO NOT CHANGE THE LINES BELOW *********************************/
233
-	/////////////////////////////////////////////////////////////////////////////////////
230
+    /* ---------------------------------------------------------------------------------- */
231
+    ///////////////////////////////////////////////////////////////////////////////////////
232
+    /******************** DO NOT CHANGE THE LINES BELOW *********************************/
233
+    /////////////////////////////////////////////////////////////////////////////////////
234 234
 
235
-	switch (ENVIRONMENT) {
236
-		case 'development':
237
-			error_reporting(-1);
238
-			ini_set('display_errors', 1);
239
-		break;
240
-		case 'testing':
241
-		case 'production':
242
-			ini_set('display_errors', 0);
243
-			if (version_compare(PHP_VERSION, '5.3', '>=')) {
244
-				error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED & ~E_STRICT & ~E_USER_NOTICE & ~E_USER_DEPRECATED);
245
-			}
246
-			else{
247
-				error_reporting(E_ALL & ~E_NOTICE & ~E_STRICT & ~E_USER_NOTICE);
248
-			}
249
-		break;
250
-		default:
251
-			header('HTTP/1.1 503 Service Unavailable.', TRUE, 503);
252
-			echo 'The application environment is not set correctly.';
253
-			exit(1);
254
-	}
235
+    switch (ENVIRONMENT) {
236
+        case 'development':
237
+            error_reporting(-1);
238
+            ini_set('display_errors', 1);
239
+        break;
240
+        case 'testing':
241
+        case 'production':
242
+            ini_set('display_errors', 0);
243
+            if (version_compare(PHP_VERSION, '5.3', '>=')) {
244
+                error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED & ~E_STRICT & ~E_USER_NOTICE & ~E_USER_DEPRECATED);
245
+            }
246
+            else{
247
+                error_reporting(E_ALL & ~E_NOTICE & ~E_STRICT & ~E_USER_NOTICE);
248
+            }
249
+        break;
250
+        default:
251
+            header('HTTP/1.1 503 Service Unavailable.', TRUE, 503);
252
+            echo 'The application environment is not set correctly.';
253
+            exit(1);
254
+    }
255 255
 	
256
-	/**
257
-	* let's go.
258
-	* Everything is OK now we launch our application.
259
-	*/
260
-	require_once CORE_PATH . 'bootstrap.php';
261 256
\ No newline at end of file
257
+    /**
258
+     * let's go.
259
+     * Everything is OK now we launch our application.
260
+     */
261
+    require_once CORE_PATH . 'bootstrap.php';
262 262
\ No newline at end of file
Please login to merge, or discard this patch.
core/bootstrap.php 2 patches
Braces   +3 added lines, -6 removed lines patch added patch discarded remove patch
@@ -78,8 +78,7 @@  discard block
 block discarded – undo
78 78
 	*/
79 79
 	if (version_compare(phpversion(), TNH_REQUIRED_PHP_MIN_VERSION, '<')){
80 80
 		show_error('Your PHP Version [' . phpversion() . '] is less than [' . TNH_REQUIRED_PHP_MIN_VERSION . '], please install a new version or update your PHP to the latest.', 'PHP Error environment');	
81
-	}
82
-	else if(version_compare(phpversion(), TNH_REQUIRED_PHP_MAX_VERSION, '>')){
81
+	} else if(version_compare(phpversion(), TNH_REQUIRED_PHP_MAX_VERSION, '>')){
83 82
 		show_error('Your PHP Version [' . phpversion() . '] is greather than [' . TNH_REQUIRED_PHP_MAX_VERSION . '] please install a PHP version that is compatible.', 'PHP Error environment');	
84 83
 	}
85 84
 	$LOGGER->info('PHP version [' . phpversion() . '] is OK [REQUIRED MINIMUM: ' . TNH_REQUIRED_PHP_MIN_VERSION . ', REQUIRED MAXIMUM: ' . TNH_REQUIRED_PHP_MAX_VERSION . '], application can work without any issue');
@@ -104,8 +103,7 @@  discard block
 block discarded – undo
104 103
 	if(file_exists(VENDOR_PATH . 'autoload.php')){
105 104
 		$LOGGER->info('The composer autoload file exists include it');
106 105
 		require_once VENDOR_PATH . 'autoload.php';
107
-	}
108
-	else{
106
+	} else{
109 107
 		$LOGGER->info('The composer autoload file does not exist skipping');
110 108
 	}
111 109
 	
@@ -176,8 +174,7 @@  discard block
 block discarded – undo
176 174
 		//first check if the cache handler is the system driver
177 175
 		if(file_exists(CORE_CLASSES_CACHE_PATH . $cacheHandler . '.php')){
178 176
 			$CACHE =& class_loader($cacheHandler, 'classes/cache');
179
-		}
180
-		else{
177
+		} else{
181 178
 			//it's not a system driver use user library
182 179
 			$CACHE =& class_loader($cacheHandler);
183 180
 		}
Please login to merge, or discard this patch.
Indentation   +165 added lines, -165 removed lines patch added patch discarded remove patch
@@ -1,195 +1,195 @@
 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 bootstrap.php
29
-	 *  
30
-	 *  Contains the loading process: loading of constants, common functions, libraries 
31
-	 *  configurations, etc
32
-	 *  verification of the environment and the routing of the request.
33
-	 *  
34
-	 *  @package	core	
35
-	 *  @author	Tony NGUEREZA
36
-	 *  @copyright	Copyright (c) 2017
37
-	 *  @license	https://opensource.org/licenses/gpl-3.0.html GNU GPL License (GPL)
38
-	 *  @link	http://www.iacademy.cf
39
-	 *  @version 1.0.0
40
-	 *  @filesource
41
-	 */
27
+    /**
28
+     *  @file bootstrap.php
29
+     *  
30
+     *  Contains the loading process: loading of constants, common functions, libraries 
31
+     *  configurations, etc
32
+     *  verification of the environment and the routing of the request.
33
+     *  
34
+     *  @package	core	
35
+     *  @author	Tony NGUEREZA
36
+     *  @copyright	Copyright (c) 2017
37
+     *  @license	https://opensource.org/licenses/gpl-3.0.html GNU GPL License (GPL)
38
+     *  @link	http://www.iacademy.cf
39
+     *  @version 1.0.0
40
+     *  @filesource
41
+     */
42 42
 	
43
-	//if the application is running in CLI mode $_SESSION global variable is not available
44
-	if(IS_CLI){
45
-		$_SESSION = array();
46
-	}
43
+    //if the application is running in CLI mode $_SESSION global variable is not available
44
+    if(IS_CLI){
45
+        $_SESSION = array();
46
+    }
47 47
 		
48
-	/**
49
-	*  inclusion of global constants of the environment that contain : name of the framework,
50
-	*  version, release date, version of PHP required, etc.
51
-	*/
52
-	require_once CORE_PATH . 'constants.php';	
48
+    /**
49
+     *  inclusion of global constants of the environment that contain : name of the framework,
50
+     *  version, release date, version of PHP required, etc.
51
+     */
52
+    require_once CORE_PATH . 'constants.php';	
53 53
 	
54
-	/**
55
-	 *  include file containing commons functions used in the framework such: show_error, 
56
-	 *  php_exception_handler, php_error_handler, get_instance, etc.
57
-	 */
58
-	require_once CORE_PATH . 'common.php';
54
+    /**
55
+     *  include file containing commons functions used in the framework such: show_error, 
56
+     *  php_exception_handler, php_error_handler, get_instance, etc.
57
+     */
58
+    require_once CORE_PATH . 'common.php';
59 59
 
60
-	/**
61
-	 * The Benchmark class
62
-	 */
63
-	$BENCHMARK =& class_loader('Benchmark');
60
+    /**
61
+     * The Benchmark class
62
+     */
63
+    $BENCHMARK =& class_loader('Benchmark');
64 64
 	
65
-	$BENCHMARK->mark('APP_EXECUTION_START');
65
+    $BENCHMARK->mark('APP_EXECUTION_START');
66 66
 	
67
-	/**
68
-    * instance of the Log class
69
-    */
67
+    /**
68
+     * instance of the Log class
69
+     */
70 70
     $LOGGER =& class_loader('Log', 'classes');
71 71
 
72 72
     $LOGGER->setLogger('ApplicationBootstrap');
73 73
 
74 74
     $LOGGER->debug('Checking PHP version ...');	
75 75
 	
76
-	/**
77
-	* Verification of the PHP environment: minimum and maximum version
78
-	*/
79
-	if (version_compare(phpversion(), TNH_REQUIRED_PHP_MIN_VERSION, '<')){
80
-		show_error('Your PHP Version [' . phpversion() . '] is less than [' . TNH_REQUIRED_PHP_MIN_VERSION . '], please install a new version or update your PHP to the latest.', 'PHP Error environment');	
81
-	}
82
-	else if(version_compare(phpversion(), TNH_REQUIRED_PHP_MAX_VERSION, '>')){
83
-		show_error('Your PHP Version [' . phpversion() . '] is greather than [' . TNH_REQUIRED_PHP_MAX_VERSION . '] please install a PHP version that is compatible.', 'PHP Error environment');	
84
-	}
85
-	$LOGGER->info('PHP version [' . phpversion() . '] is OK [REQUIRED MINIMUM: ' . TNH_REQUIRED_PHP_MIN_VERSION . ', REQUIRED MAXIMUM: ' . TNH_REQUIRED_PHP_MAX_VERSION . '], application can work without any issue');
76
+    /**
77
+     * Verification of the PHP environment: minimum and maximum version
78
+     */
79
+    if (version_compare(phpversion(), TNH_REQUIRED_PHP_MIN_VERSION, '<')){
80
+        show_error('Your PHP Version [' . phpversion() . '] is less than [' . TNH_REQUIRED_PHP_MIN_VERSION . '], please install a new version or update your PHP to the latest.', 'PHP Error environment');	
81
+    }
82
+    else if(version_compare(phpversion(), TNH_REQUIRED_PHP_MAX_VERSION, '>')){
83
+        show_error('Your PHP Version [' . phpversion() . '] is greather than [' . TNH_REQUIRED_PHP_MAX_VERSION . '] please install a PHP version that is compatible.', 'PHP Error environment');	
84
+    }
85
+    $LOGGER->info('PHP version [' . phpversion() . '] is OK [REQUIRED MINIMUM: ' . TNH_REQUIRED_PHP_MIN_VERSION . ', REQUIRED MAXIMUM: ' . TNH_REQUIRED_PHP_MAX_VERSION . '], application can work without any issue');
86 86
 
87
-	/**
88
-	* Setting of the PHP error message handling function
89
-	*/
90
-	set_error_handler('php_error_handler');
87
+    /**
88
+     * Setting of the PHP error message handling function
89
+     */
90
+    set_error_handler('php_error_handler');
91 91
 
92
-	/**
93
-	* Setting of the PHP error exception handling function
94
-	*/
95
-	set_exception_handler('php_exception_handler');
92
+    /**
93
+     * Setting of the PHP error exception handling function
94
+     */
95
+    set_exception_handler('php_exception_handler');
96 96
 
97
-	/**
98
-	 * Setting of the PHP shutdown handling function
99
-	 */
100
-	register_shutdown_function('php_shudown_handler');
97
+    /**
98
+     * Setting of the PHP shutdown handling function
99
+     */
100
+    register_shutdown_function('php_shudown_handler');
101 101
 	
102
-	//if user have some composer packages
103
-	$LOGGER->debug('Check for composer autoload');
104
-	if(file_exists(VENDOR_PATH . 'autoload.php')){
105
-		$LOGGER->info('The composer autoload file exists include it');
106
-		require_once VENDOR_PATH . 'autoload.php';
107
-	}
108
-	else{
109
-		$LOGGER->info('The composer autoload file does not exist skipping');
110
-	}
102
+    //if user have some composer packages
103
+    $LOGGER->debug('Check for composer autoload');
104
+    if(file_exists(VENDOR_PATH . 'autoload.php')){
105
+        $LOGGER->info('The composer autoload file exists include it');
106
+        require_once VENDOR_PATH . 'autoload.php';
107
+    }
108
+    else{
109
+        $LOGGER->info('The composer autoload file does not exist skipping');
110
+    }
111 111
 	
112
-	$LOGGER->debug('Begin to load the required resources');
112
+    $LOGGER->debug('Begin to load the required resources');
113 113
 
114
-	/**
115
-	 * Load the EventInfo class file
116
-	 */
117
-	require_once CORE_CLASSES_PATH . 'EventInfo.php';
114
+    /**
115
+     * Load the EventInfo class file
116
+     */
117
+    require_once CORE_CLASSES_PATH . 'EventInfo.php';
118 118
 
119 119
 
120
-	$BENCHMARK->mark('CONFIG_INIT_START');
121
-	/**
122
-	* Load configurations and using the 
123
-	* static method "init()" to initialize the Config class .
124
-	*/
125
-	$CONFIG =& class_loader('Config', 'classes');	
126
-	$CONFIG->init();
127
-	$BENCHMARK->mark('CONFIG_INIT_END');
120
+    $BENCHMARK->mark('CONFIG_INIT_START');
121
+    /**
122
+     * Load configurations and using the 
123
+     * static method "init()" to initialize the Config class .
124
+     */
125
+    $CONFIG =& class_loader('Config', 'classes');	
126
+    $CONFIG->init();
127
+    $BENCHMARK->mark('CONFIG_INIT_END');
128 128
 
129
-	$BENCHMARK->mark('MODULE_INIT_START');
130
-	/**
131
-	* Load modules and using the 
132
-	* static method "init()" to initialize the Module class.
133
-	*/
134
-	$MODULE =& class_loader('Module', 'classes');
135
-	$MODULE->init();
136
-	$BENCHMARK->mark('MODULE_INIT_END');
129
+    $BENCHMARK->mark('MODULE_INIT_START');
130
+    /**
131
+     * Load modules and using the 
132
+     * static method "init()" to initialize the Module class.
133
+     */
134
+    $MODULE =& class_loader('Module', 'classes');
135
+    $MODULE->init();
136
+    $BENCHMARK->mark('MODULE_INIT_END');
137 137
 
138
-	$LOGGER->debug('Loading Base Controller ...');
139
-	/**
140
-	 * Include of the file containing the Base Controller class 
141
-	 */
142
-	require_once CORE_CLASSES_PATH . 'Controller.php';
143
-	$LOGGER->info('Base Controller loaded successfully');
138
+    $LOGGER->debug('Loading Base Controller ...');
139
+    /**
140
+     * Include of the file containing the Base Controller class 
141
+     */
142
+    require_once CORE_CLASSES_PATH . 'Controller.php';
143
+    $LOGGER->info('Base Controller loaded successfully');
144 144
 
145
-	/**
146
-	* Register controllers autoload function
147
-	*/
148
-	 spl_autoload_register('autoload_controller');
145
+    /**
146
+     * Register controllers autoload function
147
+     */
148
+        spl_autoload_register('autoload_controller');
149 149
 
150
-	/**
151
-	* Loading Security class
152
-	*/
153
-	$SECURITY =& class_loader('Security', 'classes');
154
-	$SECURITY->checkWhiteListIpAccess();
150
+    /**
151
+     * Loading Security class
152
+     */
153
+    $SECURITY =& class_loader('Security', 'classes');
154
+    $SECURITY->checkWhiteListIpAccess();
155 155
 	
156
-	/**
157
-	* Loading Url class
158
-	*/
159
-	$URL =& class_loader('Url', 'classes');
156
+    /**
157
+     * Loading Url class
158
+     */
159
+    $URL =& class_loader('Url', 'classes');
160 160
 	
161
-	if(get_config('cache_enable', false)){
162
-		/**
163
-		 * Load Cache interface file
164
-		 */
165
-		require_once CORE_CLASSES_CACHE_PATH . 'CacheInterface.php';
166
-		$cacheHandler = get_config('cache_handler');
167
-		if(! $cacheHandler){
168
-			show_error('The cache feature is enabled in the configuration but the cache handler class is not set.');
169
-		}
170
-		$CACHE = null;
171
-		//first check if the cache handler is the system driver
172
-		if(file_exists(CORE_CLASSES_CACHE_PATH . $cacheHandler . '.php')){
173
-			$CACHE =& class_loader($cacheHandler, 'classes/cache');
174
-		}
175
-		else{
176
-			//it's not a system driver use user library
177
-			$CACHE =& class_loader($cacheHandler);
178
-		}
179
-		//check if the page already cached
180
-		if(! empty($_SERVER['REQUEST_METHOD']) && strtolower($_SERVER['REQUEST_METHOD']) == 'get'){
181
-			$RESPONSE = & class_loader('Response', 'classes');
182
-			$RESPONSE->renderFinalPageFromCache($CACHE);
183
-		}
184
-	}
161
+    if(get_config('cache_enable', false)){
162
+        /**
163
+         * Load Cache interface file
164
+         */
165
+        require_once CORE_CLASSES_CACHE_PATH . 'CacheInterface.php';
166
+        $cacheHandler = get_config('cache_handler');
167
+        if(! $cacheHandler){
168
+            show_error('The cache feature is enabled in the configuration but the cache handler class is not set.');
169
+        }
170
+        $CACHE = null;
171
+        //first check if the cache handler is the system driver
172
+        if(file_exists(CORE_CLASSES_CACHE_PATH . $cacheHandler . '.php')){
173
+            $CACHE =& class_loader($cacheHandler, 'classes/cache');
174
+        }
175
+        else{
176
+            //it's not a system driver use user library
177
+            $CACHE =& class_loader($cacheHandler);
178
+        }
179
+        //check if the page already cached
180
+        if(! empty($_SERVER['REQUEST_METHOD']) && strtolower($_SERVER['REQUEST_METHOD']) == 'get'){
181
+            $RESPONSE = & class_loader('Response', 'classes');
182
+            $RESPONSE->renderFinalPageFromCache($CACHE);
183
+        }
184
+    }
185 185
 	
186
-	//load model class
187
-	require_once CORE_CLASSES_MODEL_PATH . 'Model.php';
186
+    //load model class
187
+    require_once CORE_CLASSES_MODEL_PATH . 'Model.php';
188 188
 	
189
-	$LOGGER->info('Everything is OK load Router library and dispatch the request to the corresponding controller');
190
-	/**
191
-	* Routing
192
-	* instantiation of the "Router" class and request processing.
193
-	*/
194
-	$ROUTER = & class_loader('Router', 'classes');
195
-	$ROUTER->processRequest();
189
+    $LOGGER->info('Everything is OK load Router library and dispatch the request to the corresponding controller');
190
+    /**
191
+     * Routing
192
+     * instantiation of the "Router" class and request processing.
193
+     */
194
+    $ROUTER = & class_loader('Router', 'classes');
195
+    $ROUTER->processRequest();
Please login to merge, or discard this patch.
core/classes/Session.php 2 patches
Braces   +3 added lines, -6 removed lines patch added patch discarded remove patch
@@ -90,8 +90,7 @@  discard block
 block discarded – undo
90 90
 			($_SESSION[$key]) : $default;
91 91
 			if(array_key_exists($key, $_SESSION)){
92 92
 				unset($_SESSION[$key]);
93
-			}
94
-			else{
93
+			} else{
95 94
 				$logger->warning('Cannot find session flash item ['. $key .'] using the default value ['. $default .']');
96 95
 			}
97 96
 			return $return;
@@ -126,8 +125,7 @@  discard block
 block discarded – undo
126 125
 			if(array_key_exists($item, $_SESSION)){
127 126
 				$logger->info('Deleting of session for item ['.$item.' ]');
128 127
 				unset($_SESSION[$item]);
129
-			}
130
-			else{
128
+			} else{
131 129
 				$logger->warning('Session item ['.$item.'] to be deleted does not exists');
132 130
 			}
133 131
 		}
@@ -142,8 +140,7 @@  discard block
 block discarded – undo
142 140
 			if(array_key_exists($key, $_SESSION)){
143 141
 				$logger->info('Delete session flash for item ['.$item.']');
144 142
 				unset($_SESSION[$item]);
145
-			}
146
-			else{
143
+			} else{
147 144
 				$logger->warning('Dession flash item ['.$item.'] to be deleted does not exists');
148 145
 			}
149 146
 		}
Please login to merge, or discard this patch.
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') 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
-	class Session{
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
+    class Session{
27 27
 		
28
-		/**
29
-		 * The session flash key to use
30
-		 * @const
31
-		 */
32
-		const SESSION_FLASH_KEY = 'session_flash';
28
+        /**
29
+         * The session flash key to use
30
+         * @const
31
+         */
32
+        const SESSION_FLASH_KEY = 'session_flash';
33 33
 
34
-		/**
35
-		 * The logger instance
36
-		 * @var Log
37
-		 */
38
-		private static $logger;
34
+        /**
35
+         * The logger instance
36
+         * @var Log
37
+         */
38
+        private static $logger;
39 39
 
40
-		/**
41
-		 * Get the logger singleton instance
42
-		 * @return Log the logger instance
43
-		 */
44
-		private static function getLogger(){
45
-			if(self::$logger == null){
46
-				self::$logger[0] =& class_loader('Log', 'classes');
47
-				self::$logger[0]->setLogger('Library::Session');
48
-			}
49
-			return self::$logger[0];
50
-		}
40
+        /**
41
+         * Get the logger singleton instance
42
+         * @return Log the logger instance
43
+         */
44
+        private static function getLogger(){
45
+            if(self::$logger == null){
46
+                self::$logger[0] =& class_loader('Log', 'classes');
47
+                self::$logger[0]->setLogger('Library::Session');
48
+            }
49
+            return self::$logger[0];
50
+        }
51 51
 
52
-		/**
53
-		 * Get the session item value
54
-		 * @param  string $item    the session item name to get
55
-		 * @param  mixed $default the default value to use if can not find the session item in the list
56
-		 * @return mixed          the session value if exist or the default value
57
-		 */
58
-		public static function get($item, $default = null){
59
-			$logger = self::getLogger();
60
-			$logger->debug('Getting session data for item [' .$item. '] ...');
61
-			if(array_key_exists($item, $_SESSION)){
62
-				$logger->info('Found session data for item [' . $item . '] the vaue is : [' . stringfy_vars($_SESSION[$item]) . ']');
63
-				return $_SESSION[$item];
64
-			}
65
-			$logger->warning('Cannot find session item [' . $item . '] using the default value ['. $default . ']');
66
-			return $default;
67
-		}
52
+        /**
53
+         * Get the session item value
54
+         * @param  string $item    the session item name to get
55
+         * @param  mixed $default the default value to use if can not find the session item in the list
56
+         * @return mixed          the session value if exist or the default value
57
+         */
58
+        public static function get($item, $default = null){
59
+            $logger = self::getLogger();
60
+            $logger->debug('Getting session data for item [' .$item. '] ...');
61
+            if(array_key_exists($item, $_SESSION)){
62
+                $logger->info('Found session data for item [' . $item . '] the vaue is : [' . stringfy_vars($_SESSION[$item]) . ']');
63
+                return $_SESSION[$item];
64
+            }
65
+            $logger->warning('Cannot find session item [' . $item . '] using the default value ['. $default . ']');
66
+            return $default;
67
+        }
68 68
 
69
-		/**
70
-		 * Set the session item value
71
-		 * @param string $item  the session item name to set
72
-		 * @param mixed $value the session item value
73
-		 */
74
-		public static function set($item, $value){
75
-			$logger = self::getLogger();
76
-			$logger->debug('Setting session data for item [' . $item . '], value [' . stringfy_vars($value) . ']');
77
-			$_SESSION[$item] = $value;
78
-		}
69
+        /**
70
+         * Set the session item value
71
+         * @param string $item  the session item name to set
72
+         * @param mixed $value the session item value
73
+         */
74
+        public static function set($item, $value){
75
+            $logger = self::getLogger();
76
+            $logger->debug('Setting session data for item [' . $item . '], value [' . stringfy_vars($value) . ']');
77
+            $_SESSION[$item] = $value;
78
+        }
79 79
 
80
-		/**
81
-		 * Get the session flash item value
82
-		 * @param  string $item    the session flash item name to get
83
-		 * @param  mixed $default the default value to use if can not find the session flash item in the list
84
-		 * @return mixed          the session flash value if exist or the default value
85
-		 */
86
-		public static function getFlash($item, $default = null){
87
-			$logger = self::getLogger();
88
-			$key = self::SESSION_FLASH_KEY.'_'.$item;
89
-			$return = array_key_exists($key, $_SESSION) ?
90
-			($_SESSION[$key]) : $default;
91
-			if(array_key_exists($key, $_SESSION)){
92
-				unset($_SESSION[$key]);
93
-			}
94
-			else{
95
-				$logger->warning('Cannot find session flash item ['. $key .'] using the default value ['. $default .']');
96
-			}
97
-			return $return;
98
-		}
80
+        /**
81
+         * Get the session flash item value
82
+         * @param  string $item    the session flash item name to get
83
+         * @param  mixed $default the default value to use if can not find the session flash item in the list
84
+         * @return mixed          the session flash value if exist or the default value
85
+         */
86
+        public static function getFlash($item, $default = null){
87
+            $logger = self::getLogger();
88
+            $key = self::SESSION_FLASH_KEY.'_'.$item;
89
+            $return = array_key_exists($key, $_SESSION) ?
90
+            ($_SESSION[$key]) : $default;
91
+            if(array_key_exists($key, $_SESSION)){
92
+                unset($_SESSION[$key]);
93
+            }
94
+            else{
95
+                $logger->warning('Cannot find session flash item ['. $key .'] using the default value ['. $default .']');
96
+            }
97
+            return $return;
98
+        }
99 99
 
100
-		/**
101
-		 * Check whether the given session flash item exists
102
-		 * @param  string  $item the session flash item name
103
-		 * @return boolean 
104
-		 */
105
-		public static function hasFlash($item){
106
-			$key = self::SESSION_FLASH_KEY.'_'.$item;
107
-			return array_key_exists($key, $_SESSION);
108
-		}
100
+        /**
101
+         * Check whether the given session flash item exists
102
+         * @param  string  $item the session flash item name
103
+         * @return boolean 
104
+         */
105
+        public static function hasFlash($item){
106
+            $key = self::SESSION_FLASH_KEY.'_'.$item;
107
+            return array_key_exists($key, $_SESSION);
108
+        }
109 109
 
110
-		/**
111
-		 * Set the session flash item value
112
-		 * @param string $item  the session flash item name to set
113
-		 * @param mixed $value the session flash item value
114
-		 */
115
-		public static function setFlash($item, $value){
116
-			$key = self::SESSION_FLASH_KEY.'_'.$item;
117
-			$_SESSION[$key] = $value;
118
-		}
110
+        /**
111
+         * Set the session flash item value
112
+         * @param string $item  the session flash item name to set
113
+         * @param mixed $value the session flash item value
114
+         */
115
+        public static function setFlash($item, $value){
116
+            $key = self::SESSION_FLASH_KEY.'_'.$item;
117
+            $_SESSION[$key] = $value;
118
+        }
119 119
 
120
-		/**
121
-		 * Clear the session item in the list
122
-		 * @param  string $item the session item name to be deleted
123
-		 */
124
-		public static function clear($item){
125
-			$logger = self::getLogger();
126
-			if(array_key_exists($item, $_SESSION)){
127
-				$logger->info('Deleting of session for item ['.$item.' ]');
128
-				unset($_SESSION[$item]);
129
-			}
130
-			else{
131
-				$logger->warning('Session item ['.$item.'] to be deleted does not exists');
132
-			}
133
-		}
120
+        /**
121
+         * Clear the session item in the list
122
+         * @param  string $item the session item name to be deleted
123
+         */
124
+        public static function clear($item){
125
+            $logger = self::getLogger();
126
+            if(array_key_exists($item, $_SESSION)){
127
+                $logger->info('Deleting of session for item ['.$item.' ]');
128
+                unset($_SESSION[$item]);
129
+            }
130
+            else{
131
+                $logger->warning('Session item ['.$item.'] to be deleted does not exists');
132
+            }
133
+        }
134 134
 		
135
-		/**
136
-		 * Clear the session flash item in the list
137
-		 * @param  string $item the session flash item name to be deleted
138
-		 */
139
-		public static function clearFlash($item){
140
-			$logger = self::getLogger();
141
-			$key = self::SESSION_FLASH_KEY.'_'.$item;
142
-			if(array_key_exists($key, $_SESSION)){
143
-				$logger->info('Delete session flash for item ['.$item.']');
144
-				unset($_SESSION[$item]);
145
-			}
146
-			else{
147
-				$logger->warning('Dession flash item ['.$item.'] to be deleted does not exists');
148
-			}
149
-		}
135
+        /**
136
+         * Clear the session flash item in the list
137
+         * @param  string $item the session flash item name to be deleted
138
+         */
139
+        public static function clearFlash($item){
140
+            $logger = self::getLogger();
141
+            $key = self::SESSION_FLASH_KEY.'_'.$item;
142
+            if(array_key_exists($key, $_SESSION)){
143
+                $logger->info('Delete session flash for item ['.$item.']');
144
+                unset($_SESSION[$item]);
145
+            }
146
+            else{
147
+                $logger->warning('Dession flash item ['.$item.'] to be deleted does not exists');
148
+            }
149
+        }
150 150
 
151
-		/**
152
-		 * Check whether the given session item exists
153
-		 * @param  string  $item the session item name
154
-		 * @return boolean 
155
-		 */
156
-		public static function exists($item){
157
-			return array_key_exists($item, $_SESSION);
158
-		}
151
+        /**
152
+         * Check whether the given session item exists
153
+         * @param  string  $item the session item name
154
+         * @return boolean 
155
+         */
156
+        public static function exists($item){
157
+            return array_key_exists($item, $_SESSION);
158
+        }
159 159
 
160
-		/**
161
-		 * Destroy all session data values
162
-		 */
163
-		public static function clearAll(){
164
-			session_unset();
165
-			session_destroy();
166
-		}
160
+        /**
161
+         * Destroy all session data values
162
+         */
163
+        public static function clearAll(){
164
+            session_unset();
165
+            session_destroy();
166
+        }
167 167
 
168
-	}
168
+    }
Please login to merge, or discard this patch.
core/classes/Lang.php 2 patches
Braces   +2 added lines, -4 removed lines patch added patch discarded remove patch
@@ -82,8 +82,7 @@  discard block
 block discarded – undo
82 82
 			if($cookieLang && $this->isValid($cookieLang)){
83 83
 				$this->current = $cookieLang;
84 84
 				$this->logger->info('Language from cookie [' .$cfgKey. '] is valid so we will set the language using the cookie value [' .$cookieLang. ']');
85
-			}
86
-			else{
85
+			} else{
87 86
 				$this->logger->info('Language from cookie [' .$cfgKey. '] is not set, use the default value [' .$this->getDefault(). ']');
88 87
 				$this->current = $this->getDefault();
89 88
 			}
@@ -171,8 +170,7 @@  discard block
 block discarded – undo
171 170
 			}
172 171
 			if($this->isValid($name)){
173 172
 				$this->availables[$name] = $description;
174
-			}
175
-			else{
173
+			} else{
176 174
 				show_error('The language [' . $name . '] is not valid or does not exists.');
177 175
 			}
178 176
 		}
Please login to merge, or discard this patch.
Indentation   +205 added lines, -205 removed lines patch added patch discarded remove patch
@@ -1,208 +1,208 @@
 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
-	*/
26
-
27
-	/**
28
-	 * For application languages management
29
-	 */
30
-	class Lang{
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
+
27
+    /**
28
+     * For application languages management
29
+     */
30
+    class Lang{
31 31
 		
32
-		/**
33
-		 * The supported available language for this application.
34
-		 * @example "en" => "english" 
35
-		 * @see Lang::addLang()
36
-		 * @var array
37
-		 */
38
-		protected $availables = array();
39
-
40
-		/**
41
-		 * The all messages language
42
-		 * @var array
43
-		 */
44
-		protected $languages = array();
45
-
46
-		/**
47
-		 * The default language to use if can not
48
-		 *  determine the client language
49
-		 *  
50
-		 * @example $default = 'en'
51
-		 * @var string
52
-		 */
53
-		protected $default = null;
54
-
55
-		/**
56
-		 * The current client language
57
-		 * @var string
58
-		 */
59
-		protected $current = null;
60
-
61
-		/**
62
-		 * The logger instance
63
-		 * @var Log
64
-		 */
65
-		private $logger;
66
-
67
-		/**
68
-		 * Construct new Lang instance
69
-		 */
70
-		public function __construct(){
71
-	        $this->logger =& class_loader('Log', 'classes');
72
-	        $this->logger->setLogger('Library::Lang');
73
-
74
-			$this->default = get_config('default_language', 'en');
75
-			$this->logger->debug('Setting the supported languages');
32
+        /**
33
+         * The supported available language for this application.
34
+         * @example "en" => "english" 
35
+         * @see Lang::addLang()
36
+         * @var array
37
+         */
38
+        protected $availables = array();
39
+
40
+        /**
41
+         * The all messages language
42
+         * @var array
43
+         */
44
+        protected $languages = array();
45
+
46
+        /**
47
+         * The default language to use if can not
48
+         *  determine the client language
49
+         *  
50
+         * @example $default = 'en'
51
+         * @var string
52
+         */
53
+        protected $default = null;
54
+
55
+        /**
56
+         * The current client language
57
+         * @var string
58
+         */
59
+        protected $current = null;
60
+
61
+        /**
62
+         * The logger instance
63
+         * @var Log
64
+         */
65
+        private $logger;
66
+
67
+        /**
68
+         * Construct new Lang instance
69
+         */
70
+        public function __construct(){
71
+            $this->logger =& class_loader('Log', 'classes');
72
+            $this->logger->setLogger('Library::Lang');
73
+
74
+            $this->default = get_config('default_language', 'en');
75
+            $this->logger->debug('Setting the supported languages');
76 76
 			
77
-			//add the supported languages ('key', 'display name')
78
-			$languages = get_config('languages', null);
79
-			if(! empty($languages)){
80
-				foreach($languages as $key => $displayName){
81
-					$this->addLang($key, $displayName);
82
-				}
83
-			}
84
-			unset($languages);
85
-
86
-			//if the language exists in cookie use it
87
-			$cfgKey = get_config('language_cookie_name');
88
-			$this->logger->debug('Getting current language from cookie [' .$cfgKey. ']');
89
-			$objCookie = & class_loader('Cookie');
90
-			$cookieLang = $objCookie->get($cfgKey);
91
-			if($cookieLang && $this->isValid($cookieLang)){
92
-				$this->current = $cookieLang;
93
-				$this->logger->info('Language from cookie [' .$cfgKey. '] is valid so we will set the language using the cookie value [' .$cookieLang. ']');
94
-			}
95
-			else{
96
-				$this->logger->info('Language from cookie [' .$cfgKey. '] is not set, use the default value [' .$this->getDefault(). ']');
97
-				$this->current = $this->getDefault();
98
-			}
99
-		}
100
-
101
-		/**
102
-		 * Get the all languages messages
103
-		 *
104
-		 * @return array the language message list
105
-		 */
106
-		public function getAll(){
107
-			return $this->languages;
108
-		}
109
-
110
-		/**
111
-		 * Set the language message
112
-		 *
113
-		 * @param string $key the language key to identify
114
-		 * @param string $value the language message value
115
-		 */
116
-		public function set($key, $value){
117
-			$this->languages[$key] = $value;
118
-		}
119
-
120
-		/**
121
-		 * Get the language message for the given key. If can't find return the default value
122
-		 *
123
-		 * @param  string $key the message language key
124
-		 * @param  string $default the default value to return if can not found the language message key
125
-		 *
126
-		 * @return string the language message value
127
-		 */
128
-		public function get($key, $default = 'LANGUAGE_ERROR'){
129
-			if(isset($this->languages[$key])){
130
-				return $this->languages[$key];
131
-			}
132
-			$this->logger->warning('Language key  [' .$key. '] does not exist use the default value [' .$default. ']');
133
-			return $default;
134
-		}
135
-
136
-		/**
137
-		 * Check whether the language file for given name exists
138
-		 *
139
-		 * @param  string  $language the language name like "fr", "en", etc.
140
-		 *
141
-		 * @return boolean true if the language directory exists, false or not
142
-		 */
143
-		public function isValid($language){
144
-			$searchDir = array(CORE_LANG_PATH, APP_LANG_PATH);
145
-			foreach($searchDir as $dir){
146
-				if(file_exists($dir . $language) && is_dir($dir . $language)){
147
-					return true;
148
-				}
149
-			}
150
-			return false;
151
-		}
152
-
153
-		/**
154
-		 * Get the default language value like "en" , "fr", etc.
155
-		 *
156
-		 * @return string the default language
157
-		 */
158
-		public function getDefault(){
159
-			return $this->default;
160
-		}
161
-
162
-		/**
163
-		 * Get the current language defined by cookie or the default value
164
-		 *
165
-		 * @return string the current language
166
-		 */
167
-		public function getCurrent(){
168
-			return $this->current;
169
-		}
170
-
171
-		/**
172
-		 * Add new supported or available language
173
-		 *
174
-		 * @param string $name the short language name like "en", "fr".
175
-		 * @param string $description the human readable description of this language
176
-		 */
177
-		public function addLang($name, $description){
178
-			if(isset($this->availables[$name])){
179
-				return; //already added cost in performance
180
-			}
181
-			if($this->isValid($name)){
182
-				$this->availables[$name] = $description;
183
-			}
184
-			else{
185
-				show_error('The language [' . $name . '] is not valid or does not exists.');
186
-			}
187
-		}
188
-
189
-		/**
190
-		 * Get the list of the application supported language
191
-		 *
192
-		 * @return array the list of the application language
193
-		 */
194
-		public function getSupported(){
195
-			return $this->availables;
196
-		}
197
-
198
-		/**
199
-		 * Add new language messages
200
-		 *
201
-		 * @param array $langs the languages array of the messages to be added
202
-		 */
203
-		public function addLangMessages(array $langs){
204
-			foreach ($langs as $key => $value) {
205
-				$this->set($key, $value);
206
-			}
207
-		}
208
-	}
77
+            //add the supported languages ('key', 'display name')
78
+            $languages = get_config('languages', null);
79
+            if(! empty($languages)){
80
+                foreach($languages as $key => $displayName){
81
+                    $this->addLang($key, $displayName);
82
+                }
83
+            }
84
+            unset($languages);
85
+
86
+            //if the language exists in cookie use it
87
+            $cfgKey = get_config('language_cookie_name');
88
+            $this->logger->debug('Getting current language from cookie [' .$cfgKey. ']');
89
+            $objCookie = & class_loader('Cookie');
90
+            $cookieLang = $objCookie->get($cfgKey);
91
+            if($cookieLang && $this->isValid($cookieLang)){
92
+                $this->current = $cookieLang;
93
+                $this->logger->info('Language from cookie [' .$cfgKey. '] is valid so we will set the language using the cookie value [' .$cookieLang. ']');
94
+            }
95
+            else{
96
+                $this->logger->info('Language from cookie [' .$cfgKey. '] is not set, use the default value [' .$this->getDefault(). ']');
97
+                $this->current = $this->getDefault();
98
+            }
99
+        }
100
+
101
+        /**
102
+         * Get the all languages messages
103
+         *
104
+         * @return array the language message list
105
+         */
106
+        public function getAll(){
107
+            return $this->languages;
108
+        }
109
+
110
+        /**
111
+         * Set the language message
112
+         *
113
+         * @param string $key the language key to identify
114
+         * @param string $value the language message value
115
+         */
116
+        public function set($key, $value){
117
+            $this->languages[$key] = $value;
118
+        }
119
+
120
+        /**
121
+         * Get the language message for the given key. If can't find return the default value
122
+         *
123
+         * @param  string $key the message language key
124
+         * @param  string $default the default value to return if can not found the language message key
125
+         *
126
+         * @return string the language message value
127
+         */
128
+        public function get($key, $default = 'LANGUAGE_ERROR'){
129
+            if(isset($this->languages[$key])){
130
+                return $this->languages[$key];
131
+            }
132
+            $this->logger->warning('Language key  [' .$key. '] does not exist use the default value [' .$default. ']');
133
+            return $default;
134
+        }
135
+
136
+        /**
137
+         * Check whether the language file for given name exists
138
+         *
139
+         * @param  string  $language the language name like "fr", "en", etc.
140
+         *
141
+         * @return boolean true if the language directory exists, false or not
142
+         */
143
+        public function isValid($language){
144
+            $searchDir = array(CORE_LANG_PATH, APP_LANG_PATH);
145
+            foreach($searchDir as $dir){
146
+                if(file_exists($dir . $language) && is_dir($dir . $language)){
147
+                    return true;
148
+                }
149
+            }
150
+            return false;
151
+        }
152
+
153
+        /**
154
+         * Get the default language value like "en" , "fr", etc.
155
+         *
156
+         * @return string the default language
157
+         */
158
+        public function getDefault(){
159
+            return $this->default;
160
+        }
161
+
162
+        /**
163
+         * Get the current language defined by cookie or the default value
164
+         *
165
+         * @return string the current language
166
+         */
167
+        public function getCurrent(){
168
+            return $this->current;
169
+        }
170
+
171
+        /**
172
+         * Add new supported or available language
173
+         *
174
+         * @param string $name the short language name like "en", "fr".
175
+         * @param string $description the human readable description of this language
176
+         */
177
+        public function addLang($name, $description){
178
+            if(isset($this->availables[$name])){
179
+                return; //already added cost in performance
180
+            }
181
+            if($this->isValid($name)){
182
+                $this->availables[$name] = $description;
183
+            }
184
+            else{
185
+                show_error('The language [' . $name . '] is not valid or does not exists.');
186
+            }
187
+        }
188
+
189
+        /**
190
+         * Get the list of the application supported language
191
+         *
192
+         * @return array the list of the application language
193
+         */
194
+        public function getSupported(){
195
+            return $this->availables;
196
+        }
197
+
198
+        /**
199
+         * Add new language messages
200
+         *
201
+         * @param array $langs the languages array of the messages to be added
202
+         */
203
+        public function addLangMessages(array $langs){
204
+            foreach ($langs as $key => $value) {
205
+                $this->set($key, $value);
206
+            }
207
+        }
208
+    }
Please login to merge, or discard this patch.
core/classes/Security.php 2 patches
Braces   +5 added lines, -10 removed lines patch added patch discarded remove patch
@@ -60,8 +60,7 @@  discard block
 block discarded – undo
60 60
 			if(Session::exists($key) && Session::exists($keyExpire) && Session::get($keyExpire) > $currentTime){
61 61
 				$logger->info('The CSRF token not yet expire just return it');
62 62
 				return Session::get($key);
63
-			}
64
-			else{
63
+			} else{
65 64
 				$newTime = $currentTime + $expire;
66 65
 				$token = sha1(uniqid()) . sha1(uniqid());
67 66
 				$logger->info('The CSRF informations are listed below: key [' .$key. '], key expire [' .$keyExpire. '], expire time [' .$expire. '], token [' .$token. ']');
@@ -87,8 +86,7 @@  discard block
 block discarded – undo
87 86
 			if(! Session::exists($key) || Session::get($keyExpire) <= $currentTime){
88 87
 				$logger->warning('The CSRF session data is not valide');
89 88
 				return false;
90
-			}
91
-			else{
89
+			} else{
92 90
 				//perform form data
93 91
 				//need use request->query() for best retrieve
94 92
 				//super instance
@@ -97,8 +95,7 @@  discard block
 block discarded – undo
97 95
 				if(! $token || $token !== Session::get($key) || Session::get($keyExpire) <= $currentTime){
98 96
 					$logger->warning('The CSRF data [' .$token. '] is not valide may be attacker do his job');
99 97
 					return false;
100
-				}
101
-				else{
98
+				} else{
102 99
 					$logger->info('The CSRF data [' .$token. '] is valide the form data is safe continue');
103 100
 					//remove the token from session
104 101
 					Session::clear($key);
@@ -127,8 +124,7 @@  discard block
 block discarded – undo
127 124
 						$logger->info('IP address ' . $ip . ' allowed using the wildcard "*" or the full IP');
128 125
 						//wildcard to access all ip address
129 126
 						return;
130
-					}
131
-					else{
127
+					} else{
132 128
 						// go through all whitelisted ips
133 129
 						foreach ($list as $ipaddr) {
134 130
 							// find the wild card * in whitelisted ip (f.e. find position in "127.0.*" or "127*")
@@ -153,8 +149,7 @@  discard block
 block discarded – undo
153 149
 						show_error('Access to this application is not allowed');
154 150
 					}
155 151
 				}
156
-			}
157
-			else{
152
+			} else{
158 153
 				$logger->info('Whitelist IP access is not enabled in the configuration, ignore checking');
159 154
 			}
160 155
 		 }
Please login to merge, or discard this patch.
Indentation   +151 added lines, -151 removed lines patch added patch discarded remove patch
@@ -1,161 +1,161 @@
 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
-	class Security{
27
+    class Security{
28 28
 		
29
-		/**
30
-		 * The logger instance
31
-		 * @var Log
32
-		 */
33
-		private static $logger;
29
+        /**
30
+         * The logger instance
31
+         * @var Log
32
+         */
33
+        private static $logger;
34 34
 
35
-		/**
36
-		 * Get the logger singleton instance
37
-		 * @return Log the logger instance
38
-		 */
39
-		private static function getLogger(){
40
-			if(self::$logger == null){
41
-				self::$logger[0] =& class_loader('Log', 'classes');
42
-				self::$logger[0]->setLogger('Library::Security');
43
-			}
44
-			return self::$logger[0];
45
-		}
35
+        /**
36
+         * Get the logger singleton instance
37
+         * @return Log the logger instance
38
+         */
39
+        private static function getLogger(){
40
+            if(self::$logger == null){
41
+                self::$logger[0] =& class_loader('Log', 'classes');
42
+                self::$logger[0]->setLogger('Library::Security');
43
+            }
44
+            return self::$logger[0];
45
+        }
46 46
 
47 47
 
48
-		/**
49
-		 * This method is used to generate the CSRF token
50
-		 * @return string the generated CSRF token
51
-		 */
52
-		public static function generateCSRF(){
53
-			$logger = self::getLogger();
54
-			$logger->debug('Generation of CSRF ...');
48
+        /**
49
+         * This method is used to generate the CSRF token
50
+         * @return string the generated CSRF token
51
+         */
52
+        public static function generateCSRF(){
53
+            $logger = self::getLogger();
54
+            $logger->debug('Generation of CSRF ...');
55 55
 			
56
-			$key = get_config('csrf_key', 'csrf_key');
57
-			$expire = get_config('csrf_expire', 60);
58
-			$keyExpire = 'csrf_expire';
59
-			$currentTime = time();
60
-			if(Session::exists($key) && Session::exists($keyExpire) && Session::get($keyExpire) > $currentTime){
61
-				$logger->info('The CSRF token not yet expire just return it');
62
-				return Session::get($key);
63
-			}
64
-			else{
65
-				$newTime = $currentTime + $expire;
66
-				$token = sha1(uniqid()) . sha1(uniqid());
67
-				$logger->info('The CSRF informations are listed below: key [' .$key. '], key expire [' .$keyExpire. '], expire time [' .$expire. '], token [' .$token. ']');
68
-				Session::set($keyExpire, $newTime);
69
-				Session::set($key, $token);
70
-				return Session::get($key);
71
-			}
72
-		}
56
+            $key = get_config('csrf_key', 'csrf_key');
57
+            $expire = get_config('csrf_expire', 60);
58
+            $keyExpire = 'csrf_expire';
59
+            $currentTime = time();
60
+            if(Session::exists($key) && Session::exists($keyExpire) && Session::get($keyExpire) > $currentTime){
61
+                $logger->info('The CSRF token not yet expire just return it');
62
+                return Session::get($key);
63
+            }
64
+            else{
65
+                $newTime = $currentTime + $expire;
66
+                $token = sha1(uniqid()) . sha1(uniqid());
67
+                $logger->info('The CSRF informations are listed below: key [' .$key. '], key expire [' .$keyExpire. '], expire time [' .$expire. '], token [' .$token. ']');
68
+                Session::set($keyExpire, $newTime);
69
+                Session::set($key, $token);
70
+                return Session::get($key);
71
+            }
72
+        }
73 73
 
74
-		/**
75
-		 * This method is used to check the CSRF if is valid, not yet expire, etc.
76
-		 * @return boolean true if valid, false if not valid
77
-		 */
78
-		public static function validateCSRF(){
79
-			$logger = self::getLogger();
80
-			$logger->debug('Validation of CSRF ...');
74
+        /**
75
+         * This method is used to check the CSRF if is valid, not yet expire, etc.
76
+         * @return boolean true if valid, false if not valid
77
+         */
78
+        public static function validateCSRF(){
79
+            $logger = self::getLogger();
80
+            $logger->debug('Validation of CSRF ...');
81 81
 				
82
-			$key = get_config('csrf_key', 'csrf_key');
83
-			$expire = get_config('csrf_expire', 60);
84
-			$keyExpire = 'csrf_expire';
85
-			$currentTime = time();
86
-			$logger->info('The CSRF informations are listed below: key [' .$key. '], key expire [' .$keyExpire. '], expire time [' .$expire. ']');
87
-			if(! Session::exists($key) || Session::get($keyExpire) <= $currentTime){
88
-				$logger->warning('The CSRF session data is not valide');
89
-				return false;
90
-			}
91
-			else{
92
-				//perform form data
93
-				//need use request->query() for best retrieve
94
-				//super instance
95
-				$obj = & get_instance();
96
-				$token = $obj->request->query($key);
97
-				if(! $token || $token !== Session::get($key) || Session::get($keyExpire) <= $currentTime){
98
-					$logger->warning('The CSRF data [' .$token. '] is not valide may be attacker do his job');
99
-					return false;
100
-				}
101
-				else{
102
-					$logger->info('The CSRF data [' .$token. '] is valide the form data is safe continue');
103
-					//remove the token from session
104
-					Session::clear($key);
105
-					Session::clear($keyExpire);
106
-					return true;
107
-				}
108
-			}
109
-		}
82
+            $key = get_config('csrf_key', 'csrf_key');
83
+            $expire = get_config('csrf_expire', 60);
84
+            $keyExpire = 'csrf_expire';
85
+            $currentTime = time();
86
+            $logger->info('The CSRF informations are listed below: key [' .$key. '], key expire [' .$keyExpire. '], expire time [' .$expire. ']');
87
+            if(! Session::exists($key) || Session::get($keyExpire) <= $currentTime){
88
+                $logger->warning('The CSRF session data is not valide');
89
+                return false;
90
+            }
91
+            else{
92
+                //perform form data
93
+                //need use request->query() for best retrieve
94
+                //super instance
95
+                $obj = & get_instance();
96
+                $token = $obj->request->query($key);
97
+                if(! $token || $token !== Session::get($key) || Session::get($keyExpire) <= $currentTime){
98
+                    $logger->warning('The CSRF data [' .$token. '] is not valide may be attacker do his job');
99
+                    return false;
100
+                }
101
+                else{
102
+                    $logger->info('The CSRF data [' .$token. '] is valide the form data is safe continue');
103
+                    //remove the token from session
104
+                    Session::clear($key);
105
+                    Session::clear($keyExpire);
106
+                    return true;
107
+                }
108
+            }
109
+        }
110 110
 		
111
-		/**
112
-		 * This method is used to check the whitelist IP address access
113
-		 */
114
-		 public static function checkWhiteListIpAccess(){
115
-			$logger = self::getLogger();
116
-			$logger->debug('Validation of the IP address access ...');
117
-			$logger->debug('Check if whitelist IP access is enabled in the configuration ...');
118
-			$isEnable = get_config('white_list_ip_enable', false);
119
-			if($isEnable){
120
-				$logger->info('Whitelist IP access is enabled in the configuration');
121
-				$list = get_config('white_list_ip_addresses', array());
122
-				if(! empty($list)){
123
-					//Can't use Loader::functions() at this time because teh "Loader" library is loader after the security prossessing
124
-					require_once CORE_FUNCTIONS_PATH . 'function_user_agent.php';
125
-					$ip = get_ip();
126
-					if((count($list) == 1 && $list[0] == '*') || in_array($ip, $list)){
127
-						$logger->info('IP address ' . $ip . ' allowed using the wildcard "*" or the full IP');
128
-						//wildcard to access all ip address
129
-						return;
130
-					}
131
-					else{
132
-						// go through all whitelisted ips
133
-						foreach ($list as $ipaddr) {
134
-							// find the wild card * in whitelisted ip (f.e. find position in "127.0.*" or "127*")
135
-							$wildcardPosition = strpos($ipaddr, '*');
136
-							if ($wildcardPosition === false) {
137
-								// no wild card in whitelisted ip --continue searching
138
-								continue;
139
-							}
140
-							// cut ip at the position where we got the wild card on the whitelisted ip
141
-							// and add the wold card to get the same pattern
142
-							if (substr($ip, 0, $wildcardPosition) . '*' === $ipaddr) {
143
-								// f.e. we got
144
-								//  ip "127.0.0.1"
145
-								//  whitelisted ip "127.0.*"
146
-								// then we compared "127.0.*" with "127.0.*"
147
-								// return success
148
-								$logger->info('IP address ' . $ip . ' allowed using the wildcard like "x.x.x.*"');
149
-								return;
150
-							}
151
-						}
152
-						$logger->warning('IP address ' . $ip . ' is not allowed to access to this application');
153
-						show_error('Access to this application is not allowed');
154
-					}
155
-				}
156
-			}
157
-			else{
158
-				$logger->info('Whitelist IP access is not enabled in the configuration, ignore checking');
159
-			}
160
-		 }
161
-	}
111
+        /**
112
+         * This method is used to check the whitelist IP address access
113
+         */
114
+            public static function checkWhiteListIpAccess(){
115
+            $logger = self::getLogger();
116
+            $logger->debug('Validation of the IP address access ...');
117
+            $logger->debug('Check if whitelist IP access is enabled in the configuration ...');
118
+            $isEnable = get_config('white_list_ip_enable', false);
119
+            if($isEnable){
120
+                $logger->info('Whitelist IP access is enabled in the configuration');
121
+                $list = get_config('white_list_ip_addresses', array());
122
+                if(! empty($list)){
123
+                    //Can't use Loader::functions() at this time because teh "Loader" library is loader after the security prossessing
124
+                    require_once CORE_FUNCTIONS_PATH . 'function_user_agent.php';
125
+                    $ip = get_ip();
126
+                    if((count($list) == 1 && $list[0] == '*') || in_array($ip, $list)){
127
+                        $logger->info('IP address ' . $ip . ' allowed using the wildcard "*" or the full IP');
128
+                        //wildcard to access all ip address
129
+                        return;
130
+                    }
131
+                    else{
132
+                        // go through all whitelisted ips
133
+                        foreach ($list as $ipaddr) {
134
+                            // find the wild card * in whitelisted ip (f.e. find position in "127.0.*" or "127*")
135
+                            $wildcardPosition = strpos($ipaddr, '*');
136
+                            if ($wildcardPosition === false) {
137
+                                // no wild card in whitelisted ip --continue searching
138
+                                continue;
139
+                            }
140
+                            // cut ip at the position where we got the wild card on the whitelisted ip
141
+                            // and add the wold card to get the same pattern
142
+                            if (substr($ip, 0, $wildcardPosition) . '*' === $ipaddr) {
143
+                                // f.e. we got
144
+                                //  ip "127.0.0.1"
145
+                                //  whitelisted ip "127.0.*"
146
+                                // then we compared "127.0.*" with "127.0.*"
147
+                                // return success
148
+                                $logger->info('IP address ' . $ip . ' allowed using the wildcard like "x.x.x.*"');
149
+                                return;
150
+                            }
151
+                        }
152
+                        $logger->warning('IP address ' . $ip . ' is not allowed to access to this application');
153
+                        show_error('Access to this application is not allowed');
154
+                    }
155
+                }
156
+            }
157
+            else{
158
+                $logger->info('Whitelist IP access is not enabled in the configuration, ignore checking');
159
+            }
160
+            }
161
+    }
Please login to merge, or discard this patch.
core/classes/Request.php 2 patches
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -103,8 +103,7 @@
 block discarded – undo
103 103
 			$this->header = array();
104 104
 			if(function_exists('apache_request_headers')){
105 105
 				$this->header = apache_request_headers();
106
-			}
107
-			else if(function_exists('getallheaders')){
106
+			} else if(function_exists('getallheaders')){
108 107
 				$this->header = getallheaders();
109 108
 			}
110 109
 		}
Please login to merge, or discard this patch.
Indentation   +231 added lines, -231 removed lines patch added patch discarded remove patch
@@ -1,256 +1,256 @@
 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
-	class Request{
27
+    class Request{
28 28
 		
29
-		/**
30
-		 * The value for the super global $_GET
31
-		 * @var array
32
-		 */
33
-		public $get = null;
29
+        /**
30
+         * The value for the super global $_GET
31
+         * @var array
32
+         */
33
+        public $get = null;
34 34
 
35
-		/**
36
-		 * The value for the super global $_POST
37
-		 * @var array
38
-		 */
39
-		public $post = null;
35
+        /**
36
+         * The value for the super global $_POST
37
+         * @var array
38
+         */
39
+        public $post = null;
40 40
 
41
-		/**
42
-		 * The value for the super global $_SERVER
43
-		 * @var array
44
-		 */
45
-		public $server = null;
41
+        /**
42
+         * The value for the super global $_SERVER
43
+         * @var array
44
+         */
45
+        public $server = null;
46 46
 
47
-		/**
48
-		 * The value for the super global $_COOKIE
49
-		 * @var array
50
-		 */
51
-		public $cookie = null;
47
+        /**
48
+         * The value for the super global $_COOKIE
49
+         * @var array
50
+         */
51
+        public $cookie = null;
52 52
 
53
-		/**
54
-		 * The value for the super global $_FILES
55
-		 * @var array
56
-		 */
57
-		public $file = null;
53
+        /**
54
+         * The value for the super global $_FILES
55
+         * @var array
56
+         */
57
+        public $file = null;
58 58
 
59
-		/**
60
-		 * The value for the super global $_REQUEST
61
-		 * @var array
62
-		 */
63
-		public $query = null;
59
+        /**
60
+         * The value for the super global $_REQUEST
61
+         * @var array
62
+         */
63
+        public $query = null;
64 64
 		
65
-		/**
66
-		 * The session instance
67
-		 * @var Session
68
-		 */
69
-		public $session = null;
65
+        /**
66
+         * The session instance
67
+         * @var Session
68
+         */
69
+        public $session = null;
70 70
 		
71
-		/**
72
-		 * The request headers
73
-		 * @var array
74
-		 */
75
-		public $header = null;
71
+        /**
72
+         * The request headers
73
+         * @var array
74
+         */
75
+        public $header = null;
76 76
 
77
-		/**
78
-		 * The current request method 'GET', 'POST', 'PUT', etc.
79
-		 * @var null
80
-		 */
81
-		private $method = null;
77
+        /**
78
+         * The current request method 'GET', 'POST', 'PUT', etc.
79
+         * @var null
80
+         */
81
+        private $method = null;
82 82
 
83
-		/**
84
-		 * The current request URI
85
-		 * @var string
86
-		 */
87
-		private $requestUri = null;
83
+        /**
84
+         * The current request URI
85
+         * @var string
86
+         */
87
+        private $requestUri = null;
88 88
 		
89 89
 		
90
-		/**
91
-		 * Construct new request instance
92
-		 */
93
-		public function __construct(){
94
-			$this->get = $_GET;
95
-			$this->post = $_POST;
96
-			$this->server = $_SERVER;
97
-			$this->query = $_REQUEST;
98
-			$this->cookie = $_COOKIE;
99
-			$this->file = $_FILES;
100
-			$this->session =& class_loader('Session', 'classes');
101
-			$this->method = $this->server('REQUEST_METHOD');
102
-			$this->requestUri = $this->server('REQUEST_URI');
103
-			$this->header = array();
104
-			if(function_exists('apache_request_headers')){
105
-				$this->header = apache_request_headers();
106
-			}
107
-			else if(function_exists('getallheaders')){
108
-				$this->header = getallheaders();
109
-			}
110
-		}
90
+        /**
91
+         * Construct new request instance
92
+         */
93
+        public function __construct(){
94
+            $this->get = $_GET;
95
+            $this->post = $_POST;
96
+            $this->server = $_SERVER;
97
+            $this->query = $_REQUEST;
98
+            $this->cookie = $_COOKIE;
99
+            $this->file = $_FILES;
100
+            $this->session =& class_loader('Session', 'classes');
101
+            $this->method = $this->server('REQUEST_METHOD');
102
+            $this->requestUri = $this->server('REQUEST_URI');
103
+            $this->header = array();
104
+            if(function_exists('apache_request_headers')){
105
+                $this->header = apache_request_headers();
106
+            }
107
+            else if(function_exists('getallheaders')){
108
+                $this->header = getallheaders();
109
+            }
110
+        }
111 111
 
112
-		/**
113
-		 * Get the request method
114
-		 * @return string
115
-		 */
116
-		public function method(){
117
-			return $this->method;
118
-		}
112
+        /**
113
+         * Get the request method
114
+         * @return string
115
+         */
116
+        public function method(){
117
+            return $this->method;
118
+        }
119 119
 		
120
-		/**
121
-		 * Get the request URI
122
-		 * @return string
123
-		 */
124
-		public function requestUri(){
125
-			return $this->requestUri;
126
-		}
120
+        /**
121
+         * Get the request URI
122
+         * @return string
123
+         */
124
+        public function requestUri(){
125
+            return $this->requestUri;
126
+        }
127 127
 
128
-		/**
129
-		 * Get the value from $_REQUEST for given key. if the key is empty will return the all values
130
-		 * @param  string  $key the item key to be fetched
131
-		 * @param  boolean $xss if need apply some XSS attack rule on the value
132
-		 * @return array|mixed       the item value if the key exists or all array if the key does not exists or is empty
133
-		 */
134
-		public function query($key = null, $xss = true){
135
-			if(empty($key)){
136
-				//return all
137
-				return $xss ? clean_input($this->query) : $this->query;
138
-			}
139
-			$query = array_key_exists($key, $this->query) ? $this->query[$key] : null;
140
-			if($xss){
141
-				$query = clean_input($query);
142
-			}
143
-			return $query;
144
-		}
128
+        /**
129
+         * Get the value from $_REQUEST for given key. if the key is empty will return the all values
130
+         * @param  string  $key the item key to be fetched
131
+         * @param  boolean $xss if need apply some XSS attack rule on the value
132
+         * @return array|mixed       the item value if the key exists or all array if the key does not exists or is empty
133
+         */
134
+        public function query($key = null, $xss = true){
135
+            if(empty($key)){
136
+                //return all
137
+                return $xss ? clean_input($this->query) : $this->query;
138
+            }
139
+            $query = array_key_exists($key, $this->query) ? $this->query[$key] : null;
140
+            if($xss){
141
+                $query = clean_input($query);
142
+            }
143
+            return $query;
144
+        }
145 145
 		
146
-		/**
147
-		 * Get the value from $_GET for given key. if the key is empty will return the all values
148
-		 * @param  string  $key the item key to be fetched
149
-		 * @param  boolean $xss if need apply some XSS attack rule on the value
150
-		 * @return array|mixed       the item value if the key exists or all array if the key does not exists or is empty
151
-		 */
152
-		public function get($key = null, $xss = true){
153
-			if(empty($key)){
154
-				//return all
155
-				return $xss ? clean_input($this->get) : $this->get;
156
-			}
157
-			$get = array_key_exists($key, $this->get) ? $this->get[$key] : null;
158
-			if($xss){
159
-				$get = clean_input($get);
160
-			}
161
-			return $get;
162
-		}
146
+        /**
147
+         * Get the value from $_GET for given key. if the key is empty will return the all values
148
+         * @param  string  $key the item key to be fetched
149
+         * @param  boolean $xss if need apply some XSS attack rule on the value
150
+         * @return array|mixed       the item value if the key exists or all array if the key does not exists or is empty
151
+         */
152
+        public function get($key = null, $xss = true){
153
+            if(empty($key)){
154
+                //return all
155
+                return $xss ? clean_input($this->get) : $this->get;
156
+            }
157
+            $get = array_key_exists($key, $this->get) ? $this->get[$key] : null;
158
+            if($xss){
159
+                $get = clean_input($get);
160
+            }
161
+            return $get;
162
+        }
163 163
 		
164
-		/**
165
-		 * Get the value from $_POST for given key. if the key is empty will return the all values
166
-		 * @param  string  $key the item key to be fetched
167
-		 * @param  boolean $xss if need apply some XSS attack rule on the value
168
-		 * @return array|mixed       the item value if the key exists or all array if the key does not exists or is empty
169
-		 */
170
-		public function post($key = null, $xss = true){
171
-			if(empty($key)){
172
-				//return all
173
-				return $xss ? clean_input($this->post) : $this->post;
174
-			}
175
-			$post = array_key_exists($key, $this->post) ? $this->post[$key] : null;
176
-			if($xss){
177
-				$post = clean_input($post);
178
-			}
179
-			return $post;
180
-		}
164
+        /**
165
+         * Get the value from $_POST for given key. if the key is empty will return the all values
166
+         * @param  string  $key the item key to be fetched
167
+         * @param  boolean $xss if need apply some XSS attack rule on the value
168
+         * @return array|mixed       the item value if the key exists or all array if the key does not exists or is empty
169
+         */
170
+        public function post($key = null, $xss = true){
171
+            if(empty($key)){
172
+                //return all
173
+                return $xss ? clean_input($this->post) : $this->post;
174
+            }
175
+            $post = array_key_exists($key, $this->post) ? $this->post[$key] : null;
176
+            if($xss){
177
+                $post = clean_input($post);
178
+            }
179
+            return $post;
180
+        }
181 181
 		
182
-		/**
183
-		 * Get the value from $_SERVER for given key. if the key is empty will return the all values
184
-		 * @param  string  $key the item key to be fetched
185
-		 * @param  boolean $xss if need apply some XSS attack rule on the value
186
-		 * @return array|mixed       the item value if the key exists or all array if the key does not exists or is empty
187
-		 */
188
-		public function server($key = null, $xss = true){
189
-			if(empty($key)){
190
-				//return all
191
-				return $xss ? clean_input($this->server) : $this->server;
192
-			}
193
-			$server = array_key_exists($key, $this->server) ? $this->server[$key] : null;
194
-			if($xss){
195
-				$server = clean_input($server);
196
-			}
197
-			return $server;
198
-		}
182
+        /**
183
+         * Get the value from $_SERVER for given key. if the key is empty will return the all values
184
+         * @param  string  $key the item key to be fetched
185
+         * @param  boolean $xss if need apply some XSS attack rule on the value
186
+         * @return array|mixed       the item value if the key exists or all array if the key does not exists or is empty
187
+         */
188
+        public function server($key = null, $xss = true){
189
+            if(empty($key)){
190
+                //return all
191
+                return $xss ? clean_input($this->server) : $this->server;
192
+            }
193
+            $server = array_key_exists($key, $this->server) ? $this->server[$key] : null;
194
+            if($xss){
195
+                $server = clean_input($server);
196
+            }
197
+            return $server;
198
+        }
199 199
 		
200
-		/**
201
-		 * Get the value from $_COOKIE for given key. if the key is empty will return the all values
202
-		 * @param  string  $key the item key to be fetched
203
-		 * @param  boolean $xss if need apply some XSS attack rule on the value
204
-		 * @return array|mixed       the item value if the key exists or all array if the key does not exists or is empty
205
-		 */
206
-		public function cookie($key = null, $xss = true){
207
-			if(empty($key)){
208
-				//return all
209
-				return $xss ? clean_input($this->cookie) : $this->cookie;
210
-			}
211
-			$cookie = array_key_exists($key, $this->cookie) ? $this->cookie[$key] : null;
212
-			if($xss){
213
-				$cookie = clean_input($cookie);
214
-			}
215
-			return $cookie;
216
-		}
200
+        /**
201
+         * Get the value from $_COOKIE for given key. if the key is empty will return the all values
202
+         * @param  string  $key the item key to be fetched
203
+         * @param  boolean $xss if need apply some XSS attack rule on the value
204
+         * @return array|mixed       the item value if the key exists or all array if the key does not exists or is empty
205
+         */
206
+        public function cookie($key = null, $xss = true){
207
+            if(empty($key)){
208
+                //return all
209
+                return $xss ? clean_input($this->cookie) : $this->cookie;
210
+            }
211
+            $cookie = array_key_exists($key, $this->cookie) ? $this->cookie[$key] : null;
212
+            if($xss){
213
+                $cookie = clean_input($cookie);
214
+            }
215
+            return $cookie;
216
+        }
217 217
 		
218
-		/**
219
-		 * Get the value from $_FILES for given key. if the key is empty will return the all values
220
-		 * @param  string  $key the item key to be fetched
221
-		 * @return array|mixed       the item value if the key exists or all array if the key does not exists or is empty
222
-		 */
223
-		public function file($key){
224
-			$file = array_key_exists($key, $this->file) ? $this->file[$key] : null;
225
-			return $file;
226
-		}
218
+        /**
219
+         * Get the value from $_FILES for given key. if the key is empty will return the all values
220
+         * @param  string  $key the item key to be fetched
221
+         * @return array|mixed       the item value if the key exists or all array if the key does not exists or is empty
222
+         */
223
+        public function file($key){
224
+            $file = array_key_exists($key, $this->file) ? $this->file[$key] : null;
225
+            return $file;
226
+        }
227 227
 		
228
-		/**
229
-		 * Get the value from $_SESSION for given key. if the key is empty will return the all values
230
-		 * @param  string  $key the item key to be fetched
231
-		 * @param  boolean $xss if need apply some XSS attack rule on the value
232
-		 * @return array|mixed       the item value if the key exists or null if the key does not exists
233
-		 */
234
-		public function session($key, $xss = true){
235
-			$session = $this->session->get($key);
236
-			if($xss){
237
-				$session = clean_input($session);
238
-			}
239
-			return $session;
240
-		}
228
+        /**
229
+         * Get the value from $_SESSION for given key. if the key is empty will return the all values
230
+         * @param  string  $key the item key to be fetched
231
+         * @param  boolean $xss if need apply some XSS attack rule on the value
232
+         * @return array|mixed       the item value if the key exists or null if the key does not exists
233
+         */
234
+        public function session($key, $xss = true){
235
+            $session = $this->session->get($key);
236
+            if($xss){
237
+                $session = clean_input($session);
238
+            }
239
+            return $session;
240
+        }
241 241
 
242
-		/**
243
-		 * Get the value from header array for given key.
244
-		 * @param  string  $key the item key to be fetched
245
-		 * @param  boolean $xss if need apply some XSS attack rule on the value
246
-		 * @return mixed       the item value if the key exists or null if the key does not exists
247
-		 */
248
-		public function header($key, $xss = true){
249
-			$header = array_key_exists($key, $this->header) ? $this->header[$key] : null;
250
-			if($xss){
251
-				$header = clean_input($header);
252
-			}
253
-			return $header;
254
-		}
242
+        /**
243
+         * Get the value from header array for given key.
244
+         * @param  string  $key the item key to be fetched
245
+         * @param  boolean $xss if need apply some XSS attack rule on the value
246
+         * @return mixed       the item value if the key exists or null if the key does not exists
247
+         */
248
+        public function header($key, $xss = true){
249
+            $header = array_key_exists($key, $this->header) ? $this->header[$key] : null;
250
+            if($xss){
251
+                $header = clean_input($header);
252
+            }
253
+            return $header;
254
+        }
255 255
 		
256
-	}
256
+    }
Please login to merge, or discard this patch.
core/libraries/PDF.php 2 patches
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -69,8 +69,7 @@
 block discarded – undo
69 69
 			$this->dompdf->render();
70 70
 			if($stream){
71 71
 				$this->dompdf->stream($filename);
72
-			}
73
-			else{
72
+			} else{
74 73
 				return $this->dompdf->output();
75 74
 			}
76 75
 		}
Please login to merge, or discard this patch.
Indentation   +78 added lines, -78 removed lines patch added patch discarded remove patch
@@ -1,87 +1,87 @@
 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
-	/**
28
-	 * PDF library to generate PDF document using the library DOMPDF
29
-	 */
30
-	class PDF{
27
+    /**
28
+     * PDF library to generate PDF document using the library DOMPDF
29
+     */
30
+    class PDF{
31 31
 		
32
-		/**
33
-		 * The dompdf instance
34
-		 * @var Dompdf
35
-		 */
36
-		private $dompdf = null;
32
+        /**
33
+         * The dompdf instance
34
+         * @var Dompdf
35
+         */
36
+        private $dompdf = null;
37 37
 
38
-		/**
39
-		 * The logger instance
40
-		 * @var Log
41
-		 */
42
-		private $logger;
38
+        /**
39
+         * The logger instance
40
+         * @var Log
41
+         */
42
+        private $logger;
43 43
 		
44
-		/**
45
-		 * Create PDF library instance
46
-		 */
47
-		public function __construct(){
48
-	        $this->logger =& class_loader('Log', 'classes');
49
-	        $this->logger->setLogger('Library::PDF');
44
+        /**
45
+         * Create PDF library instance
46
+         */
47
+        public function __construct(){
48
+            $this->logger =& class_loader('Log', 'classes');
49
+            $this->logger->setLogger('Library::PDF');
50 50
 
51
-			require_once VENDOR_PATH.'dompdf/dompdf_config.inc.php';
52
-			$this->dompdf = new Dompdf();
53
-		}
51
+            require_once VENDOR_PATH.'dompdf/dompdf_config.inc.php';
52
+            $this->dompdf = new Dompdf();
53
+        }
54 54
 
55
-		/**
56
-		 * Generate PDF document
57
-		 * @param  string  $html        the HTML content to use for generation
58
-		 * @param  string  $filename    the generated PDF document filename
59
-		 * @param  boolean $stream      if need send the generated PDF to browser for download
60
-		 * @param  string  $paper       the PDF document paper type like 'A4', 'A5', 'letter', etc.
61
-		 * @param  string  $orientation the PDF document orientation like 'portrait', 'landscape'
62
-		 * @return string|void               if $stream is true send PDF document to browser for download, else return the generated PDF
63
-		 * content like to join in Email attachment of for other purpose use.
64
-		 */
65
-		public function generate($html, $filename = 'output.pdf', $stream = true, $paper = 'A4', $orientation = 'portrait'){
66
-			$this->logger->info('Generating of PDF document: filename [' .$filename. '], stream [' .($stream ? 'TRUE':'FALSE'). '], paper [' .$paper. '], orientation [' .$orientation. ']');
67
-			$this->dompdf->load_html($html);
68
-			$this->dompdf->set_paper($paper, $orientation);
69
-			$this->dompdf->render();
70
-			if($stream){
71
-				$this->dompdf->stream($filename);
72
-			}
73
-			else{
74
-				return $this->dompdf->output();
75
-			}
76
-		}
55
+        /**
56
+         * Generate PDF document
57
+         * @param  string  $html        the HTML content to use for generation
58
+         * @param  string  $filename    the generated PDF document filename
59
+         * @param  boolean $stream      if need send the generated PDF to browser for download
60
+         * @param  string  $paper       the PDF document paper type like 'A4', 'A5', 'letter', etc.
61
+         * @param  string  $orientation the PDF document orientation like 'portrait', 'landscape'
62
+         * @return string|void               if $stream is true send PDF document to browser for download, else return the generated PDF
63
+         * content like to join in Email attachment of for other purpose use.
64
+         */
65
+        public function generate($html, $filename = 'output.pdf', $stream = true, $paper = 'A4', $orientation = 'portrait'){
66
+            $this->logger->info('Generating of PDF document: filename [' .$filename. '], stream [' .($stream ? 'TRUE':'FALSE'). '], paper [' .$paper. '], orientation [' .$orientation. ']');
67
+            $this->dompdf->load_html($html);
68
+            $this->dompdf->set_paper($paper, $orientation);
69
+            $this->dompdf->render();
70
+            if($stream){
71
+                $this->dompdf->stream($filename);
72
+            }
73
+            else{
74
+                return $this->dompdf->output();
75
+            }
76
+        }
77 77
 		
78
-		/**
79
-		* Return the instance of Dompdf
80
-		*
81
-		* @return object the dompdf instance
82
-		*/
83
-		public function getDompdf(){
84
-			return $this->dompdf;
85
-		}
78
+        /**
79
+         * Return the instance of Dompdf
80
+         *
81
+         * @return object the dompdf instance
82
+         */
83
+        public function getDompdf(){
84
+            return $this->dompdf;
85
+        }
86 86
 		
87
-	}
87
+    }
Please login to merge, or discard this patch.
core/libraries/Email.php 2 patches
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -150,8 +150,7 @@
 block discarded – undo
150 150
 			foreach ($emails as $name => $email) {
151 151
 				if(is_numeric($name)){
152 152
 					$this->setTo($email);
153
-				}
154
-				else{
153
+				} else{
155 154
 					$this->setTo($email, $name);
156 155
 				}
157 156
 			}
Please login to merge, or discard this patch.
Indentation   +730 added lines, -730 removed lines patch added patch discarded remove patch
@@ -1,739 +1,739 @@
 block discarded – undo
1 1
 <?php
2
-	defined('ROOT_PATH') || exit('Access denied');
3
-	/**
4
-	 * Simple Mail
5
-	 *
6
-	 * A simple PHP wrapper class for sending email using the mail() method.
7
-	 *
8
-	 * PHP version > 5.2
9
-	 *
10
-	 * LICENSE: This source file is subject to the MIT license, which is
11
-	 * available through the world-wide-web at the following URI:
12
-	 * http://github.com/eoghanobrien/php-simple-mail/LICENCE.txt
13
-	 *
14
-	 * @category  SimpleMail
15
-	 * @package   SimpleMail
16
-	 * @author    Eoghan O'Brien <[email protected]>
17
-	 * @copyright 2009 - 2017 Eoghan O'Brien
18
-	 * @license   http://github.com/eoghanobrien/php-simple-mail/LICENCE.txt MIT
19
-	 * @version   1.7.1
20
-	 * @link      http://github.com/eoghanobrien/php-simple-mail
21
-	 */
22
-
23
-	/**
24
-	 * Simple Mail class.
25
-	 *
26
-	 * @category  SimpleMail
27
-	 * @package   SimpleMail
28
-	 * @author    Eoghan O'Brien <[email protected]>
29
-	 * @copyright 2009 - 2017 Eoghan O'Brien
30
-	 * @license   http://github.com/eoghanobrien/php-simple-mail/LICENCE.txt MIT
31
-	 * @version   1.7.1
32
-	 * @link      http://github.com/eoghanobrien/php-simple-mail
33
-	 */
34
-	class Email
35
-	{
36
-		/**
37
-		 * @var int $_wrap
38
-		 */
39
-		protected $_wrap = 78;
40
-
41
-		/**
42
-		 * @var array $_to
43
-		 */
44
-		protected $_to = array();
45
-
46
-		/**
47
-		 * @var string $_subject
48
-		 */
49
-		protected $_subject;
50
-
51
-		/**
52
-		 * @var string $_message
53
-		 */
54
-		protected $_message;
55
-
56
-		/**
57
-		 * @var array $_headers
58
-		 */
59
-		protected $_headers = array();
60
-
61
-		/**
62
-		 * @var string $_parameters
63
-		 */
64
-		protected $_params;
65
-
66
-		/**
67
-		 * @var array $_attachments
68
-		 */
69
-		protected $_attachments = array();
70
-
71
-		/**
72
-		 * @var string $_uid
73
-		 */
74
-		protected $_uid;
2
+    defined('ROOT_PATH') || exit('Access denied');
3
+    /**
4
+     * Simple Mail
5
+     *
6
+     * A simple PHP wrapper class for sending email using the mail() method.
7
+     *
8
+     * PHP version > 5.2
9
+     *
10
+     * LICENSE: This source file is subject to the MIT license, which is
11
+     * available through the world-wide-web at the following URI:
12
+     * http://github.com/eoghanobrien/php-simple-mail/LICENCE.txt
13
+     *
14
+     * @category  SimpleMail
15
+     * @package   SimpleMail
16
+     * @author    Eoghan O'Brien <[email protected]>
17
+     * @copyright 2009 - 2017 Eoghan O'Brien
18
+     * @license   http://github.com/eoghanobrien/php-simple-mail/LICENCE.txt MIT
19
+     * @version   1.7.1
20
+     * @link      http://github.com/eoghanobrien/php-simple-mail
21
+     */
22
+
23
+    /**
24
+     * Simple Mail class.
25
+     *
26
+     * @category  SimpleMail
27
+     * @package   SimpleMail
28
+     * @author    Eoghan O'Brien <[email protected]>
29
+     * @copyright 2009 - 2017 Eoghan O'Brien
30
+     * @license   http://github.com/eoghanobrien/php-simple-mail/LICENCE.txt MIT
31
+     * @version   1.7.1
32
+     * @link      http://github.com/eoghanobrien/php-simple-mail
33
+     */
34
+    class Email
35
+    {
36
+        /**
37
+         * @var int $_wrap
38
+         */
39
+        protected $_wrap = 78;
40
+
41
+        /**
42
+         * @var array $_to
43
+         */
44
+        protected $_to = array();
45
+
46
+        /**
47
+         * @var string $_subject
48
+         */
49
+        protected $_subject;
50
+
51
+        /**
52
+         * @var string $_message
53
+         */
54
+        protected $_message;
55
+
56
+        /**
57
+         * @var array $_headers
58
+         */
59
+        protected $_headers = array();
60
+
61
+        /**
62
+         * @var string $_parameters
63
+         */
64
+        protected $_params;
65
+
66
+        /**
67
+         * @var array $_attachments
68
+         */
69
+        protected $_attachments = array();
70
+
71
+        /**
72
+         * @var string $_uid
73
+         */
74
+        protected $_uid;
75 75
 		
76
-		/**
76
+        /**
77 77
          * The logger instance
78 78
          * @var Log
79 79
          */
80
-		private $logger;
80
+        private $logger;
81 81
 
82
-		/**
83
-		 * __construct
84
-		 *
85
-		 * Resets the class properties.
86
-		 */
87
-		public function __construct()
88
-		{
89
-			$this->logger =& class_loader('Log', 'classes');
82
+        /**
83
+         * __construct
84
+         *
85
+         * Resets the class properties.
86
+         */
87
+        public function __construct()
88
+        {
89
+            $this->logger =& class_loader('Log', 'classes');
90 90
             $this->logger->setLogger('Library::Email');
91
-			$this->reset();
92
-		}
93
-
94
-		/**
95
-		 * reset
96
-		 *
97
-		 * Resets all properties to initial state.
98
-		 *
99
-		 * @return self
100
-		 */
101
-		public function reset()
102
-		{
103
-			$this->_to = array();
104
-			$this->_headers = array();
105
-			$this->_subject = null;
106
-			$this->_message = null;
107
-			$this->_wrap = 78;
108
-			$this->_params = null;
109
-			$this->_attachments = array();
110
-			$this->_uid = $this->getUniqueId();
111
-			return $this;
112
-		}
91
+            $this->reset();
92
+        }
93
+
94
+        /**
95
+         * reset
96
+         *
97
+         * Resets all properties to initial state.
98
+         *
99
+         * @return self
100
+         */
101
+        public function reset()
102
+        {
103
+            $this->_to = array();
104
+            $this->_headers = array();
105
+            $this->_subject = null;
106
+            $this->_message = null;
107
+            $this->_wrap = 78;
108
+            $this->_params = null;
109
+            $this->_attachments = array();
110
+            $this->_uid = $this->getUniqueId();
111
+            return $this;
112
+        }
113 113
 		
114
-		 /**
115
-		 * setFrom
116
-		 *
117
-		 * @param string $email The email to send as from.
118
-		 * @param string $name  The name to send as from.
119
-		 *
120
-		 * @return self
121
-		 */
122
-		public function setFrom($email, $name = null)
123
-		{
124
-			$this->addMailHeader('From', (string) $email, (string) $name);
125
-			return $this;
126
-		}
127
-
128
-		/**
129
-		 * setTo
130
-		 *
131
-		 * @param string $email The email address to send to.
132
-		 * @param string $name  The name of the person to send to.
133
-		 *
134
-		 * @return self
135
-		 */
136
-		public function setTo($email, $name = null)
137
-		{
138
-			$this->_to[] = $this->formatHeader((string) $email, (string) $name);
139
-			return $this;
140
-		}
114
+            /**
115
+             * setFrom
116
+             *
117
+             * @param string $email The email to send as from.
118
+             * @param string $name  The name to send as from.
119
+             *
120
+             * @return self
121
+             */
122
+        public function setFrom($email, $name = null)
123
+        {
124
+            $this->addMailHeader('From', (string) $email, (string) $name);
125
+            return $this;
126
+        }
127
+
128
+        /**
129
+         * setTo
130
+         *
131
+         * @param string $email The email address to send to.
132
+         * @param string $name  The name of the person to send to.
133
+         *
134
+         * @return self
135
+         */
136
+        public function setTo($email, $name = null)
137
+        {
138
+            $this->_to[] = $this->formatHeader((string) $email, (string) $name);
139
+            return $this;
140
+        }
141 141
 		
142
-		/**
143
-		* Set destination using array
144
-		* @params array $emails the list of recipient. This is an associative array name => email
145
-		* @example array('John Doe' => '[email protected]')
146
-		* @return Object the current instance
147
-		*/
148
-		public function setTos(array $emails)
149
-		{
150
-			foreach ($emails as $name => $email) {
151
-				if(is_numeric($name)){
152
-					$this->setTo($email);
153
-				}
154
-				else{
155
-					$this->setTo($email, $name);
156
-				}
157
-			}
158
-			return $this;
159
-		}
160
-
161
-
162
-		/**
163
-		 * getTo
164
-		 *
165
-		 * Return an array of formatted To addresses.
166
-		 *
167
-		 * @return array
168
-		 */
169
-		public function getTo()
170
-		{
171
-			return $this->_to;
172
-		}
173
-
174
-
175
-		/**
176
-		 * setCc
177
-		 *
178
-		 * @param array  $pairs  An array of name => email pairs.
179
-		 *
180
-		 * @return self
181
-		 */
182
-		public function setCc(array $pairs)
183
-		{
184
-			return $this->addMailHeaders('Cc', $pairs);
185
-		}
186
-
187
-		/**
188
-		 * setBcc
189
-		 *
190
-		 * @param array  $pairs  An array of name => email pairs.
191
-		 *
192
-		 * @return self
193
-		 */
194
-		public function setBcc(array $pairs)
195
-		{
196
-			return $this->addMailHeaders('Bcc', $pairs);
197
-		}
198
-
199
-		/**
200
-		 * setReplyTo
201
-		 *
202
-		 * @param string $email
203
-		 * @param string $name
204
-		 *
205
-		 * @return self
206
-		 */
207
-		public function setReplyTo($email, $name = null)
208
-		{
209
-			return $this->addMailHeader('Reply-To', $email, $name);
210
-		}
211
-
212
-		/**
213
-		 * setHtml
214
-		 *
215
-		 * @return self
216
-		 */
217
-		public function setHtml()
218
-		{
219
-			$this->addGenericHeader(
220
-				'Content-Type', 'text/html; charset="utf-8"'
221
-			);
222
-			return $this;
223
-		}
224
-
225
-		/**
226
-		 * setSubject
227
-		 *
228
-		 * @param string $subject The email subject
229
-		 *
230
-		 * @return self
231
-		 */
232
-		public function setSubject($subject)
233
-		{
234
-			$this->_subject = $this->encodeUtf8(
235
-				$this->filterOther((string) $subject)
236
-			);
237
-			return $this;
238
-		}
239
-
240
-		/**
241
-		 * getSubject function.
242
-		 *
243
-		 * @return string
244
-		 */
245
-		public function getSubject()
246
-		{
247
-			return $this->_subject;
248
-		}
249
-
250
-		/**
251
-		 * setMessage
252
-		 *
253
-		 * @param string $message The message to send.
254
-		 *
255
-		 * @return self
256
-		 */
257
-		public function setMessage($message)
258
-		{
259
-			$this->_message = str_replace("\n.", "\n..", (string) $message);
260
-			return $this;
261
-		}
262
-
263
-		/**
264
-		 * getMessage
265
-		 *
266
-		 * @return string
267
-		 */
268
-		public function getMessage()
269
-		{
270
-			return $this->_message;
271
-		}
272
-
273
-		/**
274
-		 * addAttachment
275
-		 *
276
-		 * @param string $path The file path to the attachment.
277
-		 * @param string $filename The filename of the attachment when emailed.
278
-		 * @param string $data
279
-		 * 
280
-		 * @return self
281
-		 */
282
-		public function addAttachment($path, $filename = null, $data = null)
283
-		{
284
-			if(! file_exists($path)){
285
-				show_error('The file [' .$path. '] does not exists.');
286
-			}
287
-			$filename = empty($filename) ? basename($path) : $filename;
288
-			$filename = $this->encodeUtf8($this->filterOther((string) $filename));
289
-			$data = empty($data) ? $this->getAttachmentData($path) : $data;
290
-			$this->_attachments[] = array(
291
-				'path' => $path,
292
-				'file' => $filename,
293
-				'data' => chunk_split(base64_encode($data))
294
-			);
295
-			return $this;
296
-		}
297
-
298
-		/**
299
-		 * getAttachmentData
300
-		 *
301
-		 * @param string $path The path to the attachment file.
302
-		 *
303
-		 * @return string
304
-		 */
305
-		public function getAttachmentData($path)
306
-		{
307
-			if(! file_exists($path)){
308
-				show_error('The file [' .$path. '] does not exists.');
309
-			}
310
-			$filesize = filesize($path);
311
-			$handle = fopen($path, "r");
312
-			$attachment = null;
313
-			if(is_resource($handle)){
314
-				$attachment = fread($handle, $filesize);
315
-				fclose($handle);
316
-			}
317
-			return $attachment;
318
-		}
319
-
320
-		/**
321
-		 * addMailHeader
322
-		 *
323
-		 * @param string $header The header to add.
324
-		 * @param string $email  The email to add.
325
-		 * @param string $name   The name to add.
326
-		 *
327
-		 * @return self
328
-		 */
329
-		public function addMailHeader($header, $email, $name = null)
330
-		{
331
-			$address = $this->formatHeader((string) $email, (string) $name);
332
-			$this->_headers[] = sprintf('%s: %s', (string) $header, $address);
333
-			return $this;
334
-		}
335
-
336
-		/**
337
-		 * addMailHeaders
338
-		 *
339
-		 * @param string $header The header to add.
340
-		 * @param array  $pairs  An array of name => email pairs.
341
-		 *
342
-		 * @return self
343
-		 */
344
-		public function addMailHeaders($header, array $pairs)
345
-		{
346
-			if (count($pairs) === 0) {
347
-				show_error('You must pass at least one name => email pair.');
348
-			}
349
-			$addresses = array();
350
-			foreach ($pairs as $name => $email) {
351
-				$name = is_numeric($name) ? null : $name;
352
-				$addresses[] = $this->formatHeader($email, $name);
353
-			}
354
-			$this->addGenericHeader($header, implode(',', $addresses));
355
-			return $this;
356
-		}
357
-
358
-		/**
359
-		 * addGenericHeader
360
-		 *
361
-		 * @param string $name The generic header to add.
362
-		 * @param mixed  $value  The value of the header.
363
-		 *
364
-		 * @return self
365
-		 */
366
-		public function addGenericHeader($name, $value)
367
-		{
368
-			$this->_headers[] = sprintf(
369
-				'%s: %s',
370
-				(string) $name,
371
-				(string) $value
372
-			);
373
-			return $this;
374
-		}
375
-
376
-		/**
377
-		 * getHeaders
378
-		 *
379
-		 * Return the headers registered so far as an array.
380
-		 *
381
-		 * @return array
382
-		 */
383
-		public function getHeaders()
384
-		{
385
-			return $this->_headers;
386
-		}
387
-
388
-		/**
389
-		 * setAdditionalParameters
390
-		 *
391
-		 * Such as "[email protected]
392
-		 *
393
-		 * @param string $additionalParameters The addition mail parameter.
394
-		 *
395
-		 * @return self
396
-		 */
397
-		public function setParameters($additionalParameters)
398
-		{
399
-			$this->_params = (string) $additionalParameters;
400
-			return $this;
401
-		}
402
-
403
-		/**
404
-		 * getAdditionalParameters
405
-		 *
406
-		 * @return string
407
-		 */
408
-		public function getParameters()
409
-		{
410
-			return $this->_params;
411
-		}
412
-
413
-		/**
414
-		 * setWrap
415
-		 *
416
-		 * @param int $wrap The number of characters at which the message will wrap.
417
-		 *
418
-		 * @return self
419
-		 */
420
-		public function setWrap($wrap = 78)
421
-		{
422
-			$wrap = (int) $wrap;
423
-			if ($wrap < 1) {
424
-				$wrap = 78;
425
-			}
426
-			$this->_wrap = $wrap;
427
-			return $this;
428
-		}
429
-
430
-		/**
431
-		 * getWrap
432
-		 *
433
-		 * @return int
434
-		 */
435
-		public function getWrap()
436
-		{
437
-			return $this->_wrap;
438
-		}
439
-
440
-		/**
441
-		 * hasAttachments
442
-		 * 
443
-		 * Checks if the email has any registered attachments.
444
-		 *
445
-		 * @return bool
446
-		 */
447
-		public function hasAttachments()
448
-		{
449
-			return !empty($this->_attachments);
450
-		}
451
-
452
-		/**
453
-		 * assembleAttachment
454
-		 *
455
-		 * @return string
456
-		 */
457
-		public function assembleAttachmentHeaders()
458
-		{
459
-			$head = array();
460
-			$head[] = "MIME-Version: 1.0";
461
-			$head[] = "Content-Type: multipart/mixed; boundary=\"{$this->_uid}\"";
462
-
463
-			return join(PHP_EOL, $head);
464
-		}
465
-
466
-		/**
467
-		 * assembleAttachmentBody
468
-		 *
469
-		 * @return string
470
-		 */
471
-		public function assembleAttachmentBody()
472
-		{
473
-			$body = array();
474
-			$body[] = "This is a multi-part message in MIME format.";
475
-			$body[] = "--{$this->_uid}";
476
-			$body[] = "Content-Type: text/html; charset=\"utf-8\"";
477
-			$body[] = "Content-Transfer-Encoding: quoted-printable";
478
-			$body[] = "";
479
-			$body[] = quoted_printable_encode($this->_message);
480
-			$body[] = "";
481
-			$body[] = "--{$this->_uid}";
482
-
483
-			foreach ($this->_attachments as $attachment) {
484
-				$body[] = $this->getAttachmentMimeTemplate($attachment);
485
-			}
486
-
487
-			return implode(PHP_EOL, $body) . '--';
488
-		}
489
-
490
-		/**
491
-		 * getAttachmentMimeTemplate
492
-		 *
493
-		 * @param array  $attachment An array containing 'file' and 'data' keys.
494
-		 *
495
-		 * @return string
496
-		 */
497
-		public function getAttachmentMimeTemplate($attachment)
498
-		{
499
-			$file = $attachment['file'];
500
-			$data = $attachment['data'];
501
-
502
-			$head = array();
503
-			$head[] = "Content-Type: application/octet-stream; name=\"{$file}\"";
504
-			$head[] = "Content-Transfer-Encoding: base64";
505
-			$head[] = "Content-Disposition: attachment; filename=\"{$file}\"";
506
-			$head[] = "";
507
-			$head[] = $data;
508
-			$head[] = "";
509
-			$head[] = "--{$this->_uid}";
510
-
511
-			return implode(PHP_EOL, $head);
512
-		}
513
-
514
-		/**
515
-		 * send the email
516
-		 *
517
-		 * @return boolean
518
-		 */
519
-		public function send()
520
-		{
521
-			$to = $this->getToForSend();
522
-			$headers = $this->getHeadersForSend();
523
-
524
-			if (empty($to)) {
525
-				show_error('Unable to send, no To address has been set.');
526
-			}
527
-
528
-			if ($this->hasAttachments()) {
529
-				$message  = $this->assembleAttachmentBody();
530
-				$headers .= PHP_EOL . $this->assembleAttachmentHeaders();
531
-			} else {
532
-				$message = $this->getWrapMessage();
533
-			}
534
-			$this->logger->info('Sending new mail, the information are listed below: destination: ' . $to . ', headers: ' . $headers . ', message: ' . $message);
535
-			return mail($to, $this->_subject, $message, $headers, $this->_params);
536
-		}
537
-
538
-		/**
539
-		 * debug
540
-		 *
541
-		 * @return string
542
-		 */
543
-		public function debug()
544
-		{
545
-			return '<pre>' . print_r($this, true) . '</pre>';
546
-		}
547
-
548
-		/**
549
-		 * magic __toString function
550
-		 *
551
-		 * @return string
552
-		 */
553
-		public function __toString()
554
-		{
555
-			return print_r($this, true);
556
-		}
557
-
558
-		/**
559
-		 * formatHeader
560
-		 *
561
-		 * Formats a display address for emails according to RFC2822 e.g.
562
-		 * Name <[email protected]>
563
-		 *
564
-		 * @param string $email The email address.
565
-		 * @param string $name  The display name.
566
-		 *
567
-		 * @return string
568
-		 */
569
-		public function formatHeader($email, $name = null)
570
-		{
571
-			$email = $this->filterEmail((string) $email);
572
-			if (empty($name)) {
573
-				return $email;
574
-			}
575
-			$name = $this->encodeUtf8($this->filterName((string) $name));
576
-			return sprintf('"%s" <%s>', $name, $email);
577
-		}
578
-
579
-		/**
580
-		 * encodeUtf8
581
-		 *
582
-		 * @param string $value The value to encode.
583
-		 *
584
-		 * @return string
585
-		 */
586
-		public function encodeUtf8($value)
587
-		{
588
-			$value = trim($value);
589
-			if (preg_match('/(\s)/', $value)) {
590
-				return $this->encodeUtf8Words($value);
591
-			}
592
-			return $this->encodeUtf8Word($value);
593
-		}
594
-
595
-		/**
596
-		 * encodeUtf8Word
597
-		 *
598
-		 * @param string $value The word to encode.
599
-		 *
600
-		 * @return string
601
-		 */
602
-		public function encodeUtf8Word($value)
603
-		{
604
-			return sprintf('=?UTF-8?B?%s?=', base64_encode($value));
605
-		}
606
-
607
-		/**
608
-		 * encodeUtf8Words
609
-		 *
610
-		 * @param string $value The words to encode.
611
-		 *
612
-		 * @return string
613
-		 */
614
-		public function encodeUtf8Words($value)
615
-		{
616
-			$words = explode(' ', $value);
617
-			$encoded = array();
618
-			foreach ($words as $word) {
619
-				$encoded[] = $this->encodeUtf8Word($word);
620
-			}
621
-			return join($this->encodeUtf8Word(' '), $encoded);
622
-		}
623
-
624
-		/**
625
-		 * filterEmail
626
-		 *
627
-		 * Removes any carriage return, line feed, tab, double quote, comma
628
-		 * and angle bracket characters before sanitizing the email address.
629
-		 *
630
-		 * @param string $email The email to filter.
631
-		 *
632
-		 * @return string
633
-		 */
634
-		public function filterEmail($email)
635
-		{
636
-			$rule = array(
637
-				"\r" => '',
638
-				"\n" => '',
639
-				"\t" => '',
640
-				'"'  => '',
641
-				','  => '',
642
-				'<'  => '',
643
-				'>'  => ''
644
-			);
645
-			$email = strtr($email, $rule);
646
-			$email = filter_var($email, FILTER_SANITIZE_EMAIL);
647
-			return $email;
648
-		}
649
-
650
-		/**
651
-		 * filterName
652
-		 *
653
-		 * Removes any carriage return, line feed or tab characters. Replaces
654
-		 * double quotes with single quotes and angle brackets with square
655
-		 * brackets, before sanitizing the string and stripping out html tags.
656
-		 *
657
-		 * @param string $name The name to filter.
658
-		 *
659
-		 * @return string
660
-		 */
661
-		public function filterName($name)
662
-		{
663
-			$rule = array(
664
-				"\r" => '',
665
-				"\n" => '',
666
-				"\t" => '',
667
-				'"'  => "'",
668
-				'<'  => '[',
669
-				'>'  => ']',
670
-			);
671
-			$filtered = filter_var(
672
-				$name,
673
-				FILTER_SANITIZE_STRING,
674
-				FILTER_FLAG_NO_ENCODE_QUOTES
675
-			);
676
-			return trim(strtr($filtered, $rule));
677
-		}
678
-
679
-		/**
680
-		 * filterOther
681
-		 *
682
-		 * Removes ASCII control characters including any carriage return, line
683
-		 * feed or tab characters.
684
-		 *
685
-		 * @param string $data The data to filter.
686
-		 *
687
-		 * @return string
688
-		 */
689
-		public function filterOther($data)
690
-		{
691
-			return filter_var($data, FILTER_UNSAFE_RAW, FILTER_FLAG_STRIP_LOW);
692
-		}
693
-
694
-		/**
695
-		 * getHeadersForSend
696
-		 *
697
-		 * @return string
698
-		 */
699
-		public function getHeadersForSend()
700
-		{
701
-			if (empty($this->_headers)) {
702
-				return '';
703
-			}
704
-			return join(PHP_EOL, $this->_headers);
705
-		}
706
-
707
-		/**
708
-		 * getToForSend
709
-		 *
710
-		 * @return string
711
-		 */
712
-		public function getToForSend()
713
-		{
714
-			if (empty($this->_to)) {
715
-				return '';
716
-			}
717
-			return join(', ', $this->_to);
718
-		}
719
-
720
-		/**
721
-		 * getUniqueId
722
-		 *
723
-		 * @return string
724
-		 */
725
-		public function getUniqueId()
726
-		{
727
-			return md5(uniqid(time()));
728
-		}
729
-
730
-		/**
731
-		 * getWrapMessage
732
-		 *
733
-		 * @return string
734
-		 */
735
-		public function getWrapMessage()
736
-		{
737
-			return wordwrap($this->_message, $this->_wrap);
738
-		}
739
-	}
142
+        /**
143
+         * Set destination using array
144
+         * @params array $emails the list of recipient. This is an associative array name => email
145
+         * @example array('John Doe' => '[email protected]')
146
+         * @return Object the current instance
147
+         */
148
+        public function setTos(array $emails)
149
+        {
150
+            foreach ($emails as $name => $email) {
151
+                if(is_numeric($name)){
152
+                    $this->setTo($email);
153
+                }
154
+                else{
155
+                    $this->setTo($email, $name);
156
+                }
157
+            }
158
+            return $this;
159
+        }
160
+
161
+
162
+        /**
163
+         * getTo
164
+         *
165
+         * Return an array of formatted To addresses.
166
+         *
167
+         * @return array
168
+         */
169
+        public function getTo()
170
+        {
171
+            return $this->_to;
172
+        }
173
+
174
+
175
+        /**
176
+         * setCc
177
+         *
178
+         * @param array  $pairs  An array of name => email pairs.
179
+         *
180
+         * @return self
181
+         */
182
+        public function setCc(array $pairs)
183
+        {
184
+            return $this->addMailHeaders('Cc', $pairs);
185
+        }
186
+
187
+        /**
188
+         * setBcc
189
+         *
190
+         * @param array  $pairs  An array of name => email pairs.
191
+         *
192
+         * @return self
193
+         */
194
+        public function setBcc(array $pairs)
195
+        {
196
+            return $this->addMailHeaders('Bcc', $pairs);
197
+        }
198
+
199
+        /**
200
+         * setReplyTo
201
+         *
202
+         * @param string $email
203
+         * @param string $name
204
+         *
205
+         * @return self
206
+         */
207
+        public function setReplyTo($email, $name = null)
208
+        {
209
+            return $this->addMailHeader('Reply-To', $email, $name);
210
+        }
211
+
212
+        /**
213
+         * setHtml
214
+         *
215
+         * @return self
216
+         */
217
+        public function setHtml()
218
+        {
219
+            $this->addGenericHeader(
220
+                'Content-Type', 'text/html; charset="utf-8"'
221
+            );
222
+            return $this;
223
+        }
224
+
225
+        /**
226
+         * setSubject
227
+         *
228
+         * @param string $subject The email subject
229
+         *
230
+         * @return self
231
+         */
232
+        public function setSubject($subject)
233
+        {
234
+            $this->_subject = $this->encodeUtf8(
235
+                $this->filterOther((string) $subject)
236
+            );
237
+            return $this;
238
+        }
239
+
240
+        /**
241
+         * getSubject function.
242
+         *
243
+         * @return string
244
+         */
245
+        public function getSubject()
246
+        {
247
+            return $this->_subject;
248
+        }
249
+
250
+        /**
251
+         * setMessage
252
+         *
253
+         * @param string $message The message to send.
254
+         *
255
+         * @return self
256
+         */
257
+        public function setMessage($message)
258
+        {
259
+            $this->_message = str_replace("\n.", "\n..", (string) $message);
260
+            return $this;
261
+        }
262
+
263
+        /**
264
+         * getMessage
265
+         *
266
+         * @return string
267
+         */
268
+        public function getMessage()
269
+        {
270
+            return $this->_message;
271
+        }
272
+
273
+        /**
274
+         * addAttachment
275
+         *
276
+         * @param string $path The file path to the attachment.
277
+         * @param string $filename The filename of the attachment when emailed.
278
+         * @param string $data
279
+         * 
280
+         * @return self
281
+         */
282
+        public function addAttachment($path, $filename = null, $data = null)
283
+        {
284
+            if(! file_exists($path)){
285
+                show_error('The file [' .$path. '] does not exists.');
286
+            }
287
+            $filename = empty($filename) ? basename($path) : $filename;
288
+            $filename = $this->encodeUtf8($this->filterOther((string) $filename));
289
+            $data = empty($data) ? $this->getAttachmentData($path) : $data;
290
+            $this->_attachments[] = array(
291
+                'path' => $path,
292
+                'file' => $filename,
293
+                'data' => chunk_split(base64_encode($data))
294
+            );
295
+            return $this;
296
+        }
297
+
298
+        /**
299
+         * getAttachmentData
300
+         *
301
+         * @param string $path The path to the attachment file.
302
+         *
303
+         * @return string
304
+         */
305
+        public function getAttachmentData($path)
306
+        {
307
+            if(! file_exists($path)){
308
+                show_error('The file [' .$path. '] does not exists.');
309
+            }
310
+            $filesize = filesize($path);
311
+            $handle = fopen($path, "r");
312
+            $attachment = null;
313
+            if(is_resource($handle)){
314
+                $attachment = fread($handle, $filesize);
315
+                fclose($handle);
316
+            }
317
+            return $attachment;
318
+        }
319
+
320
+        /**
321
+         * addMailHeader
322
+         *
323
+         * @param string $header The header to add.
324
+         * @param string $email  The email to add.
325
+         * @param string $name   The name to add.
326
+         *
327
+         * @return self
328
+         */
329
+        public function addMailHeader($header, $email, $name = null)
330
+        {
331
+            $address = $this->formatHeader((string) $email, (string) $name);
332
+            $this->_headers[] = sprintf('%s: %s', (string) $header, $address);
333
+            return $this;
334
+        }
335
+
336
+        /**
337
+         * addMailHeaders
338
+         *
339
+         * @param string $header The header to add.
340
+         * @param array  $pairs  An array of name => email pairs.
341
+         *
342
+         * @return self
343
+         */
344
+        public function addMailHeaders($header, array $pairs)
345
+        {
346
+            if (count($pairs) === 0) {
347
+                show_error('You must pass at least one name => email pair.');
348
+            }
349
+            $addresses = array();
350
+            foreach ($pairs as $name => $email) {
351
+                $name = is_numeric($name) ? null : $name;
352
+                $addresses[] = $this->formatHeader($email, $name);
353
+            }
354
+            $this->addGenericHeader($header, implode(',', $addresses));
355
+            return $this;
356
+        }
357
+
358
+        /**
359
+         * addGenericHeader
360
+         *
361
+         * @param string $name The generic header to add.
362
+         * @param mixed  $value  The value of the header.
363
+         *
364
+         * @return self
365
+         */
366
+        public function addGenericHeader($name, $value)
367
+        {
368
+            $this->_headers[] = sprintf(
369
+                '%s: %s',
370
+                (string) $name,
371
+                (string) $value
372
+            );
373
+            return $this;
374
+        }
375
+
376
+        /**
377
+         * getHeaders
378
+         *
379
+         * Return the headers registered so far as an array.
380
+         *
381
+         * @return array
382
+         */
383
+        public function getHeaders()
384
+        {
385
+            return $this->_headers;
386
+        }
387
+
388
+        /**
389
+         * setAdditionalParameters
390
+         *
391
+         * Such as "[email protected]
392
+         *
393
+         * @param string $additionalParameters The addition mail parameter.
394
+         *
395
+         * @return self
396
+         */
397
+        public function setParameters($additionalParameters)
398
+        {
399
+            $this->_params = (string) $additionalParameters;
400
+            return $this;
401
+        }
402
+
403
+        /**
404
+         * getAdditionalParameters
405
+         *
406
+         * @return string
407
+         */
408
+        public function getParameters()
409
+        {
410
+            return $this->_params;
411
+        }
412
+
413
+        /**
414
+         * setWrap
415
+         *
416
+         * @param int $wrap The number of characters at which the message will wrap.
417
+         *
418
+         * @return self
419
+         */
420
+        public function setWrap($wrap = 78)
421
+        {
422
+            $wrap = (int) $wrap;
423
+            if ($wrap < 1) {
424
+                $wrap = 78;
425
+            }
426
+            $this->_wrap = $wrap;
427
+            return $this;
428
+        }
429
+
430
+        /**
431
+         * getWrap
432
+         *
433
+         * @return int
434
+         */
435
+        public function getWrap()
436
+        {
437
+            return $this->_wrap;
438
+        }
439
+
440
+        /**
441
+         * hasAttachments
442
+         * 
443
+         * Checks if the email has any registered attachments.
444
+         *
445
+         * @return bool
446
+         */
447
+        public function hasAttachments()
448
+        {
449
+            return !empty($this->_attachments);
450
+        }
451
+
452
+        /**
453
+         * assembleAttachment
454
+         *
455
+         * @return string
456
+         */
457
+        public function assembleAttachmentHeaders()
458
+        {
459
+            $head = array();
460
+            $head[] = "MIME-Version: 1.0";
461
+            $head[] = "Content-Type: multipart/mixed; boundary=\"{$this->_uid}\"";
462
+
463
+            return join(PHP_EOL, $head);
464
+        }
465
+
466
+        /**
467
+         * assembleAttachmentBody
468
+         *
469
+         * @return string
470
+         */
471
+        public function assembleAttachmentBody()
472
+        {
473
+            $body = array();
474
+            $body[] = "This is a multi-part message in MIME format.";
475
+            $body[] = "--{$this->_uid}";
476
+            $body[] = "Content-Type: text/html; charset=\"utf-8\"";
477
+            $body[] = "Content-Transfer-Encoding: quoted-printable";
478
+            $body[] = "";
479
+            $body[] = quoted_printable_encode($this->_message);
480
+            $body[] = "";
481
+            $body[] = "--{$this->_uid}";
482
+
483
+            foreach ($this->_attachments as $attachment) {
484
+                $body[] = $this->getAttachmentMimeTemplate($attachment);
485
+            }
486
+
487
+            return implode(PHP_EOL, $body) . '--';
488
+        }
489
+
490
+        /**
491
+         * getAttachmentMimeTemplate
492
+         *
493
+         * @param array  $attachment An array containing 'file' and 'data' keys.
494
+         *
495
+         * @return string
496
+         */
497
+        public function getAttachmentMimeTemplate($attachment)
498
+        {
499
+            $file = $attachment['file'];
500
+            $data = $attachment['data'];
501
+
502
+            $head = array();
503
+            $head[] = "Content-Type: application/octet-stream; name=\"{$file}\"";
504
+            $head[] = "Content-Transfer-Encoding: base64";
505
+            $head[] = "Content-Disposition: attachment; filename=\"{$file}\"";
506
+            $head[] = "";
507
+            $head[] = $data;
508
+            $head[] = "";
509
+            $head[] = "--{$this->_uid}";
510
+
511
+            return implode(PHP_EOL, $head);
512
+        }
513
+
514
+        /**
515
+         * send the email
516
+         *
517
+         * @return boolean
518
+         */
519
+        public function send()
520
+        {
521
+            $to = $this->getToForSend();
522
+            $headers = $this->getHeadersForSend();
523
+
524
+            if (empty($to)) {
525
+                show_error('Unable to send, no To address has been set.');
526
+            }
527
+
528
+            if ($this->hasAttachments()) {
529
+                $message  = $this->assembleAttachmentBody();
530
+                $headers .= PHP_EOL . $this->assembleAttachmentHeaders();
531
+            } else {
532
+                $message = $this->getWrapMessage();
533
+            }
534
+            $this->logger->info('Sending new mail, the information are listed below: destination: ' . $to . ', headers: ' . $headers . ', message: ' . $message);
535
+            return mail($to, $this->_subject, $message, $headers, $this->_params);
536
+        }
537
+
538
+        /**
539
+         * debug
540
+         *
541
+         * @return string
542
+         */
543
+        public function debug()
544
+        {
545
+            return '<pre>' . print_r($this, true) . '</pre>';
546
+        }
547
+
548
+        /**
549
+         * magic __toString function
550
+         *
551
+         * @return string
552
+         */
553
+        public function __toString()
554
+        {
555
+            return print_r($this, true);
556
+        }
557
+
558
+        /**
559
+         * formatHeader
560
+         *
561
+         * Formats a display address for emails according to RFC2822 e.g.
562
+         * Name <[email protected]>
563
+         *
564
+         * @param string $email The email address.
565
+         * @param string $name  The display name.
566
+         *
567
+         * @return string
568
+         */
569
+        public function formatHeader($email, $name = null)
570
+        {
571
+            $email = $this->filterEmail((string) $email);
572
+            if (empty($name)) {
573
+                return $email;
574
+            }
575
+            $name = $this->encodeUtf8($this->filterName((string) $name));
576
+            return sprintf('"%s" <%s>', $name, $email);
577
+        }
578
+
579
+        /**
580
+         * encodeUtf8
581
+         *
582
+         * @param string $value The value to encode.
583
+         *
584
+         * @return string
585
+         */
586
+        public function encodeUtf8($value)
587
+        {
588
+            $value = trim($value);
589
+            if (preg_match('/(\s)/', $value)) {
590
+                return $this->encodeUtf8Words($value);
591
+            }
592
+            return $this->encodeUtf8Word($value);
593
+        }
594
+
595
+        /**
596
+         * encodeUtf8Word
597
+         *
598
+         * @param string $value The word to encode.
599
+         *
600
+         * @return string
601
+         */
602
+        public function encodeUtf8Word($value)
603
+        {
604
+            return sprintf('=?UTF-8?B?%s?=', base64_encode($value));
605
+        }
606
+
607
+        /**
608
+         * encodeUtf8Words
609
+         *
610
+         * @param string $value The words to encode.
611
+         *
612
+         * @return string
613
+         */
614
+        public function encodeUtf8Words($value)
615
+        {
616
+            $words = explode(' ', $value);
617
+            $encoded = array();
618
+            foreach ($words as $word) {
619
+                $encoded[] = $this->encodeUtf8Word($word);
620
+            }
621
+            return join($this->encodeUtf8Word(' '), $encoded);
622
+        }
623
+
624
+        /**
625
+         * filterEmail
626
+         *
627
+         * Removes any carriage return, line feed, tab, double quote, comma
628
+         * and angle bracket characters before sanitizing the email address.
629
+         *
630
+         * @param string $email The email to filter.
631
+         *
632
+         * @return string
633
+         */
634
+        public function filterEmail($email)
635
+        {
636
+            $rule = array(
637
+                "\r" => '',
638
+                "\n" => '',
639
+                "\t" => '',
640
+                '"'  => '',
641
+                ','  => '',
642
+                '<'  => '',
643
+                '>'  => ''
644
+            );
645
+            $email = strtr($email, $rule);
646
+            $email = filter_var($email, FILTER_SANITIZE_EMAIL);
647
+            return $email;
648
+        }
649
+
650
+        /**
651
+         * filterName
652
+         *
653
+         * Removes any carriage return, line feed or tab characters. Replaces
654
+         * double quotes with single quotes and angle brackets with square
655
+         * brackets, before sanitizing the string and stripping out html tags.
656
+         *
657
+         * @param string $name The name to filter.
658
+         *
659
+         * @return string
660
+         */
661
+        public function filterName($name)
662
+        {
663
+            $rule = array(
664
+                "\r" => '',
665
+                "\n" => '',
666
+                "\t" => '',
667
+                '"'  => "'",
668
+                '<'  => '[',
669
+                '>'  => ']',
670
+            );
671
+            $filtered = filter_var(
672
+                $name,
673
+                FILTER_SANITIZE_STRING,
674
+                FILTER_FLAG_NO_ENCODE_QUOTES
675
+            );
676
+            return trim(strtr($filtered, $rule));
677
+        }
678
+
679
+        /**
680
+         * filterOther
681
+         *
682
+         * Removes ASCII control characters including any carriage return, line
683
+         * feed or tab characters.
684
+         *
685
+         * @param string $data The data to filter.
686
+         *
687
+         * @return string
688
+         */
689
+        public function filterOther($data)
690
+        {
691
+            return filter_var($data, FILTER_UNSAFE_RAW, FILTER_FLAG_STRIP_LOW);
692
+        }
693
+
694
+        /**
695
+         * getHeadersForSend
696
+         *
697
+         * @return string
698
+         */
699
+        public function getHeadersForSend()
700
+        {
701
+            if (empty($this->_headers)) {
702
+                return '';
703
+            }
704
+            return join(PHP_EOL, $this->_headers);
705
+        }
706
+
707
+        /**
708
+         * getToForSend
709
+         *
710
+         * @return string
711
+         */
712
+        public function getToForSend()
713
+        {
714
+            if (empty($this->_to)) {
715
+                return '';
716
+            }
717
+            return join(', ', $this->_to);
718
+        }
719
+
720
+        /**
721
+         * getUniqueId
722
+         *
723
+         * @return string
724
+         */
725
+        public function getUniqueId()
726
+        {
727
+            return md5(uniqid(time()));
728
+        }
729
+
730
+        /**
731
+         * getWrapMessage
732
+         *
733
+         * @return string
734
+         */
735
+        public function getWrapMessage()
736
+        {
737
+            return wordwrap($this->_message, $this->_wrap);
738
+        }
739
+    }
Please login to merge, or discard this patch.
core/libraries/Cookie.php 2 patches
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -93,8 +93,7 @@
 block discarded – undo
93 93
 				$logger->info('Delete cookie item ['.$item.']');
94 94
 				unset($_COOKIE[$item]);
95 95
 				return true;
96
-			}
97
-			else{
96
+			} else{
98 97
 				$logger->warning('Cookie item ['.$item.'] to be deleted does not exists');
99 98
 				return false;
100 99
 			}
Please login to merge, or discard this patch.
Indentation   +101 added lines, -101 removed lines patch added patch discarded remove patch
@@ -1,112 +1,112 @@
 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 Cookie{
27
+    class Cookie{
28 28
 		
29
-		/**
30
-		 * The logger instance
31
-		 * @var Log
32
-		 */
33
-		private static $logger;
29
+        /**
30
+         * The logger instance
31
+         * @var Log
32
+         */
33
+        private static $logger;
34 34
 
35
-		/**
36
-		 * The signleton of the logger
37
-		 * @return Object the Log instance
38
-		 */
39
-		private static function getLogger(){
40
-			if(self::$logger == null){
41
-				self::$logger[0] =& class_loader('Log', 'classes');
42
-				self::$logger[0]->setLogger('Library::Cookie');
43
-			}
44
-			return self::$logger[0];
45
-		}
35
+        /**
36
+         * The signleton of the logger
37
+         * @return Object the Log instance
38
+         */
39
+        private static function getLogger(){
40
+            if(self::$logger == null){
41
+                self::$logger[0] =& class_loader('Log', 'classes');
42
+                self::$logger[0]->setLogger('Library::Cookie');
43
+            }
44
+            return self::$logger[0];
45
+        }
46 46
 
47
-		/**
48
-		 * Get the cookie item value
49
-		 * @param  string $item    the cookie item name to get
50
-		 * @param  mixed $default the default value to use if can not find the cokkie item in the list
51
-		 * @return mixed          the cookie value if exist or the default value
52
-		 */
53
-		public static function get($item, $default = null){
54
-			$logger = self::getLogger();
55
-			if(array_key_exists($item, $_COOKIE)){
56
-				return $_COOKIE[$item];
57
-			}
58
-			$logger->warning('Cannot find cookie item [' . $item . '], using the default value [' . $default . ']');
59
-			return $default;
60
-		}
47
+        /**
48
+         * Get the cookie item value
49
+         * @param  string $item    the cookie item name to get
50
+         * @param  mixed $default the default value to use if can not find the cokkie item in the list
51
+         * @return mixed          the cookie value if exist or the default value
52
+         */
53
+        public static function get($item, $default = null){
54
+            $logger = self::getLogger();
55
+            if(array_key_exists($item, $_COOKIE)){
56
+                return $_COOKIE[$item];
57
+            }
58
+            $logger->warning('Cannot find cookie item [' . $item . '], using the default value [' . $default . ']');
59
+            return $default;
60
+        }
61 61
 
62
-		/**
63
-		 * Set the cookie item value
64
-		 * @param string  $name     the cookie item name
65
-		 * @param string  $value    the cookie value to set
66
-		 * @param integer $expire   the time to live for this cookie
67
-		 * @param string  $path     the path that the cookie will be available
68
-		 * @param string  $domain   the domain that the cookie will be available
69
-		 * @param boolean $secure   if this cookie will be available on secure connection or not
70
-		 * @param boolean $httponly if this cookie will be available under HTTP protocol.
71
-		 */
72
-		public static function set($name, $value = '', $expire = 0, $path = '/', $domain = '', $secure = false, $httponly = false){
73
-			if(headers_sent()){
74
-				show_error('There exists a cookie that we wanted to create that we couldn\'t 
62
+        /**
63
+         * Set the cookie item value
64
+         * @param string  $name     the cookie item name
65
+         * @param string  $value    the cookie value to set
66
+         * @param integer $expire   the time to live for this cookie
67
+         * @param string  $path     the path that the cookie will be available
68
+         * @param string  $domain   the domain that the cookie will be available
69
+         * @param boolean $secure   if this cookie will be available on secure connection or not
70
+         * @param boolean $httponly if this cookie will be available under HTTP protocol.
71
+         */
72
+        public static function set($name, $value = '', $expire = 0, $path = '/', $domain = '', $secure = false, $httponly = false){
73
+            if(headers_sent()){
74
+                show_error('There exists a cookie that we wanted to create that we couldn\'t 
75 75
 						    because headers was already sent. Make sure to do this first 
76 76
 							before outputing anything.');
77
-			}
78
-			$timestamp = $expire;
79
-			if($expire){
80
-				$timestamp = time() + $expire;
81
-			}
82
-			setcookie($name, $value, $timestamp, $path, $domain, $secure, $httponly);
83
-		}
77
+            }
78
+            $timestamp = $expire;
79
+            if($expire){
80
+                $timestamp = time() + $expire;
81
+            }
82
+            setcookie($name, $value, $timestamp, $path, $domain, $secure, $httponly);
83
+        }
84 84
 
85
-		/**
86
-		 * Delete the cookie item in the list
87
-		 * @param  string $item the cookie item name to be cleared
88
-		 * @return boolean true if the item exists and is deleted successfully otherwise will return false.
89
-		 */
90
-		public static function delete($item){
91
-			$logger = self::getLogger();
92
-			if(array_key_exists($item, $_COOKIE)){
93
-				$logger->info('Delete cookie item ['.$item.']');
94
-				unset($_COOKIE[$item]);
95
-				return true;
96
-			}
97
-			else{
98
-				$logger->warning('Cookie item ['.$item.'] to be deleted does not exists');
99
-				return false;
100
-			}
101
-		}
85
+        /**
86
+         * Delete the cookie item in the list
87
+         * @param  string $item the cookie item name to be cleared
88
+         * @return boolean true if the item exists and is deleted successfully otherwise will return false.
89
+         */
90
+        public static function delete($item){
91
+            $logger = self::getLogger();
92
+            if(array_key_exists($item, $_COOKIE)){
93
+                $logger->info('Delete cookie item ['.$item.']');
94
+                unset($_COOKIE[$item]);
95
+                return true;
96
+            }
97
+            else{
98
+                $logger->warning('Cookie item ['.$item.'] to be deleted does not exists');
99
+                return false;
100
+            }
101
+        }
102 102
 
103
-		/**
104
-		 * Check if the given cookie item exists
105
-		 * @param  string $item the cookie item name
106
-		 * @return boolean       true if the cookie item is set, false or not
107
-		 */
108
-		public static function exists($item){
109
-			return array_key_exists($item, $_COOKIE);
110
-		}
103
+        /**
104
+         * Check if the given cookie item exists
105
+         * @param  string $item the cookie item name
106
+         * @return boolean       true if the cookie item is set, false or not
107
+         */
108
+        public static function exists($item){
109
+            return array_key_exists($item, $_COOKIE);
110
+        }
111 111
 
112
-	}
112
+    }
Please login to merge, or discard this patch.