@@ -8,13 +8,13 @@ discard block |
||
8 | 8 | <meta name="description" content="A simple PHP framework using HMVC architecture"> |
9 | 9 | <meta name="author" content="Tony NGUEREZA"> |
10 | 10 | <title>TNH Framework</title> |
11 | - <link href="<?php echo Assets::css('bootstrap.min');?>" rel="stylesheet" type = "text/css" > |
|
12 | - <link href="<?php echo Assets::css('font-awesome.min');?>" rel="stylesheet" type = "text/css" > |
|
13 | - <link href="<?php echo Assets::css('responsive');?>" rel="stylesheet" type = "text/css" > |
|
14 | - <link rel="icon" href="<?php echo Assets::img('favicon.ico');?>"> |
|
11 | + <link href="<?php echo Assets::css('bootstrap.min'); ?>" rel="stylesheet" type = "text/css" > |
|
12 | + <link href="<?php echo Assets::css('font-awesome.min'); ?>" rel="stylesheet" type = "text/css" > |
|
13 | + <link href="<?php echo Assets::css('responsive'); ?>" rel="stylesheet" type = "text/css" > |
|
14 | + <link rel="icon" href="<?php echo Assets::img('favicon.ico'); ?>"> |
|
15 | 15 | <!--[if lt IE 9]> |
16 | - <script src="<?php echo Assets::js('html5shiv');?>"></script> |
|
17 | - <script src="<?php echo Assets::js('respond.min');?>"></script> |
|
16 | + <script src="<?php echo Assets::js('html5shiv'); ?>"></script> |
|
17 | + <script src="<?php echo Assets::js('respond.min'); ?>"></script> |
|
18 | 18 | <![endif]--> |
19 | 19 | <style type = "text/css"> |
20 | 20 | |
@@ -28,15 +28,15 @@ discard block |
||
28 | 28 | <div class = "col-md-offset-2 col-md-8 col-md-offset-2"> |
29 | 29 | <div class = "panel panel-primary"> |
30 | 30 | <div class = "panel-heading"> |
31 | - <h2>Welcome on <?php echo TNH_NAME;?> v<?php echo TNH_VERSION;?></h2> |
|
31 | + <h2>Welcome on <?php echo TNH_NAME; ?> v<?php echo TNH_VERSION; ?></h2> |
|
32 | 32 | </div> |
33 | 33 | <div class = "panel-body"> |
34 | - <img src = "<?php echo Assets::img('logo.png');?>" class = "img-responsive" style = "float:left;" /> |
|
34 | + <img src = "<?php echo Assets::img('logo.png'); ?>" class = "img-responsive" style = "float:left;" /> |
|
35 | 35 | <h3> |
36 | 36 | A simple PHP framework using HMVC architecture |
37 | 37 | </h3> |
38 | 38 | <br /> |
39 | - <p><?php echo Html::a('https://github.com/tnhfw/tnh-fw', 'Framework on Github', array('class' => 'btn btn-default', 'target' => '_blank'));?></p> |
|
39 | + <p><?php echo Html::a('https://github.com/tnhfw/tnh-fw', 'Framework on Github', array('class' => 'btn btn-default', 'target' => '_blank')); ?></p> |
|
40 | 40 | </div> |
41 | 41 | </div> |
42 | 42 | <div class = "panel panel-primary"> |
@@ -44,10 +44,10 @@ discard block |
||
44 | 44 | <h2>Server information</h2> |
45 | 45 | </div> |
46 | 46 | <div class = "panel-body"> |
47 | - <h4>Running on : <b><?php echo php_uname();?></b></h4> |
|
48 | - <h4>PHP server SAPI : <b><?php echo php_sapi_name();?></b></h4> |
|
49 | - <h4>PHP Version : <b><?php echo phpversion();?></b></h4> |
|
50 | - <h4>PHP Loaded extensions : (<?php echo count(get_loaded_extensions());?> extensions)</h4> |
|
47 | + <h4>Running on : <b><?php echo php_uname(); ?></b></h4> |
|
48 | + <h4>PHP server SAPI : <b><?php echo php_sapi_name(); ?></b></h4> |
|
49 | + <h4>PHP Version : <b><?php echo phpversion(); ?></b></h4> |
|
50 | + <h4>PHP Loaded extensions : (<?php echo count(get_loaded_extensions()); ?> extensions)</h4> |
|
51 | 51 | <table class = "table table-striped table-condensed table-bordered table-responsive"> |
52 | 52 | <tr> |
53 | 53 | <th>Name</th> |
@@ -55,10 +55,10 @@ discard block |
||
55 | 55 | </tr> |
56 | 56 | <?php foreach (get_loaded_extensions() as $e):?> |
57 | 57 | <tr> |
58 | - <td><?php echo $e;?></td> |
|
59 | - <td><?php echo phpversion($e);?></td> |
|
58 | + <td><?php echo $e; ?></td> |
|
59 | + <td><?php echo phpversion($e); ?></td> |
|
60 | 60 | </tr> |
61 | - <?php endforeach;?> |
|
61 | + <?php endforeach; ?> |
|
62 | 62 | </table> |
63 | 63 | </div> |
64 | 64 | </div> |
@@ -67,30 +67,30 @@ discard block |
||
67 | 67 | <h2>Framework information</h2> |
68 | 68 | </div> |
69 | 69 | <div class = "panel-body"> |
70 | - <h4>Version : <b><?php echo TNH_VERSION;?></b></h4> |
|
71 | - <h4>Required PHP version : <b>PHP >= <?php echo TNH_REQUIRED_PHP_MIN_VERSION;?>, PHP <= <?php echo TNH_REQUIRED_PHP_MAX_VERSION;?></b></h4> |
|
72 | - <h4>Build date : <b><?php echo TNH_RELEASE_DATE;?></b></h4> |
|
73 | - <h4>Author : <b><?php echo TNH_AUTHOR;?></b></h4> |
|
74 | - <h4>Author E-mail : <b><?php echo TNH_AUTHOR_EMAIL;?></b></h4> |
|
75 | - <h4>Loaded files : (<?php echo count(get_included_files());?> files)</h4> |
|
70 | + <h4>Version : <b><?php echo TNH_VERSION; ?></b></h4> |
|
71 | + <h4>Required PHP version : <b>PHP >= <?php echo TNH_REQUIRED_PHP_MIN_VERSION; ?>, PHP <= <?php echo TNH_REQUIRED_PHP_MAX_VERSION; ?></b></h4> |
|
72 | + <h4>Build date : <b><?php echo TNH_RELEASE_DATE; ?></b></h4> |
|
73 | + <h4>Author : <b><?php echo TNH_AUTHOR; ?></b></h4> |
|
74 | + <h4>Author E-mail : <b><?php echo TNH_AUTHOR_EMAIL; ?></b></h4> |
|
75 | + <h4>Loaded files : (<?php echo count(get_included_files()); ?> files)</h4> |
|
76 | 76 | <table class = "table table-striped table-condensed table-bordered table-responsive"> |
77 | 77 | <tr> |
78 | 78 | <th>Path</th> |
79 | 79 | <th>File</th> |
80 | 80 | </tr> |
81 | - <?php foreach(get_included_files() as $file):?> |
|
81 | + <?php foreach (get_included_files() as $file):?> |
|
82 | 82 | <tr> |
83 | - <td><?php echo $file;?></td> |
|
84 | - <td><?php echo basename($file);?></td> |
|
83 | + <td><?php echo $file; ?></td> |
|
84 | + <td><?php echo basename($file); ?></td> |
|
85 | 85 | </tr> |
86 | - <?php endforeach;?> |
|
86 | + <?php endforeach; ?> |
|
87 | 87 | </table> |
88 | 88 | </div> |
89 | 89 | </div> |
90 | 90 | </div> |
91 | 91 | </div> |
92 | 92 | </div> |
93 | - <script src="<?php echo Assets::js('jquery');?>"></script> |
|
94 | - <script src="<?php echo Assets::js('bootstrap.min');?>"></script> |
|
93 | + <script src="<?php echo Assets::js('jquery'); ?>"></script> |
|
94 | + <script src="<?php echo Assets::js('bootstrap.min'); ?>"></script> |
|
95 | 95 | </body> |
96 | 96 | </html> |
@@ -243,7 +243,7 @@ |
||
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 | 245 | } |
246 | - else{ |
|
246 | + else { |
|
247 | 247 | error_reporting(E_ALL & ~E_NOTICE & ~E_STRICT & ~E_USER_NOTICE); |
248 | 248 | } |
249 | 249 | break; |
@@ -242,8 +242,7 @@ |
||
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; |
@@ -1,267 +1,267 @@ |
||
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 | 116 | /** |
117 | - * The path to the directory of core classes for the database used by the system. |
|
118 | - * |
|
119 | - * It contains PHP classes for the database library, drivers, etc. |
|
120 | - */ |
|
121 | - define('CORE_CLASSES_DATABASE_PATH', CORE_CLASSES_PATH . 'database' . DS); |
|
117 | + * The path to the directory of core classes for the database used by the system. |
|
118 | + * |
|
119 | + * It contains PHP classes for the database library, drivers, etc. |
|
120 | + */ |
|
121 | + define('CORE_CLASSES_DATABASE_PATH', CORE_CLASSES_PATH . 'database' . DS); |
|
122 | 122 | |
123 | - /** |
|
124 | - * The path to the directory of core classes for the model used by the system. |
|
125 | - * |
|
126 | - * It contains PHP classes for the models. |
|
127 | - */ |
|
128 | - define('CORE_CLASSES_MODEL_PATH', CORE_CLASSES_PATH . 'model' . DS); |
|
123 | + /** |
|
124 | + * The path to the directory of core classes for the model used by the system. |
|
125 | + * |
|
126 | + * It contains PHP classes for the models. |
|
127 | + */ |
|
128 | + define('CORE_CLASSES_MODEL_PATH', CORE_CLASSES_PATH . 'model' . DS); |
|
129 | 129 | |
130 | - /** |
|
131 | - * The path to the directory of functions or helper systems. |
|
132 | - * |
|
133 | - * It contains PHP functions that perform a particular task: character string processing, URL, etc. |
|
134 | - */ |
|
135 | - define('CORE_FUNCTIONS_PATH', CORE_PATH . 'functions' . DS); |
|
130 | + /** |
|
131 | + * The path to the directory of functions or helper systems. |
|
132 | + * |
|
133 | + * It contains PHP functions that perform a particular task: character string processing, URL, etc. |
|
134 | + */ |
|
135 | + define('CORE_FUNCTIONS_PATH', CORE_PATH . 'functions' . DS); |
|
136 | 136 | |
137 | - /** |
|
138 | - * The path to the core directory of languages files. |
|
139 | - * |
|
140 | - */ |
|
141 | - define('CORE_LANG_PATH', CORE_PATH . 'lang' . DS); |
|
137 | + /** |
|
138 | + * The path to the core directory of languages files. |
|
139 | + * |
|
140 | + */ |
|
141 | + define('CORE_LANG_PATH', CORE_PATH . 'lang' . DS); |
|
142 | 142 | |
143 | - /** |
|
144 | - * The path to the system library directory. |
|
145 | - * |
|
146 | - * Which contains the libraries most often used in your web application, as for the |
|
147 | - * core directory it is advisable to put it out of the root directory of your application. |
|
148 | - */ |
|
149 | - define('CORE_LIBRARY_PATH', CORE_PATH . 'libraries' . DS); |
|
143 | + /** |
|
144 | + * The path to the system library directory. |
|
145 | + * |
|
146 | + * Which contains the libraries most often used in your web application, as for the |
|
147 | + * core directory it is advisable to put it out of the root directory of your application. |
|
148 | + */ |
|
149 | + define('CORE_LIBRARY_PATH', CORE_PATH . 'libraries' . DS); |
|
150 | 150 | |
151 | - /** |
|
152 | - * The path to the system view directory. |
|
153 | - * |
|
154 | - * That contains the views used for the system, such as error messages, and so on. |
|
155 | - */ |
|
156 | - define('CORE_VIEWS_PATH', CORE_PATH . 'views' . DS); |
|
151 | + /** |
|
152 | + * The path to the system view directory. |
|
153 | + * |
|
154 | + * That contains the views used for the system, such as error messages, and so on. |
|
155 | + */ |
|
156 | + define('CORE_VIEWS_PATH', CORE_PATH . 'views' . DS); |
|
157 | 157 | |
158 | - /** |
|
159 | - * The path to the directory of your PHP personal functions or helper. |
|
160 | - * |
|
161 | - * It contains your PHP functions that perform a particular task: utilities, etc. |
|
162 | - * Note: Do not put your personal functions or helpers in the system functions directory, |
|
163 | - * because if you update the system you may lose them. |
|
164 | - */ |
|
165 | - define('FUNCTIONS_PATH', ROOT_PATH . 'functions' . DS); |
|
158 | + /** |
|
159 | + * The path to the directory of your PHP personal functions or helper. |
|
160 | + * |
|
161 | + * It contains your PHP functions that perform a particular task: utilities, etc. |
|
162 | + * Note: Do not put your personal functions or helpers in the system functions directory, |
|
163 | + * because if you update the system you may lose them. |
|
164 | + */ |
|
165 | + define('FUNCTIONS_PATH', ROOT_PATH . 'functions' . DS); |
|
166 | 166 | |
167 | - /** |
|
168 | - * The path to the app directory of personal language. |
|
169 | - * |
|
170 | - * This feature is not yet available. |
|
171 | - * You can help us do this if you are nice or wish to see the developed framework. |
|
172 | - */ |
|
173 | - define('APP_LANG_PATH', ROOT_PATH . 'lang' . DS); |
|
167 | + /** |
|
168 | + * The path to the app directory of personal language. |
|
169 | + * |
|
170 | + * This feature is not yet available. |
|
171 | + * You can help us do this if you are nice or wish to see the developed framework. |
|
172 | + */ |
|
173 | + define('APP_LANG_PATH', ROOT_PATH . 'lang' . DS); |
|
174 | 174 | |
175 | - /** |
|
176 | - * The path to the directory of your personal libraries |
|
177 | - * |
|
178 | - * It contains your PHP classes, package, etc. |
|
179 | - * Note: you should not put your personal libraries in the system library directory, |
|
180 | - * because it is recalled in case of updating the system you might have surprises. |
|
181 | - */ |
|
182 | - define('LIBRARY_PATH', ROOT_PATH . 'libraries' . DS); |
|
175 | + /** |
|
176 | + * The path to the directory of your personal libraries |
|
177 | + * |
|
178 | + * It contains your PHP classes, package, etc. |
|
179 | + * Note: you should not put your personal libraries in the system library directory, |
|
180 | + * because it is recalled in case of updating the system you might have surprises. |
|
181 | + */ |
|
182 | + define('LIBRARY_PATH', ROOT_PATH . 'libraries' . DS); |
|
183 | 183 | |
184 | - /** |
|
185 | - * The path to the directory that contains the log files. |
|
186 | - * |
|
187 | - * Note: This directory must be available in writing and if possible must have as owner the user who launches your web server, |
|
188 | - * under unix or linux most often with the apache web server it is "www-data" or "httpd" even "nobody" for more |
|
189 | - * details see the documentation of your web server. |
|
190 | - * Example for Unix or linux with apache web server: |
|
191 | - * # chmod -R 700 /path/to/your/logs/directory/ |
|
192 | - * # chown -R www-data:www-data /path/to/your/logs/directory/ |
|
193 | - */ |
|
194 | - define('LOGS_PATH', ROOT_PATH . 'logs' . DS); |
|
184 | + /** |
|
185 | + * The path to the directory that contains the log files. |
|
186 | + * |
|
187 | + * Note: This directory must be available in writing and if possible must have as owner the user who launches your web server, |
|
188 | + * under unix or linux most often with the apache web server it is "www-data" or "httpd" even "nobody" for more |
|
189 | + * details see the documentation of your web server. |
|
190 | + * Example for Unix or linux with apache web server: |
|
191 | + * # chmod -R 700 /path/to/your/logs/directory/ |
|
192 | + * # chown -R www-data:www-data /path/to/your/logs/directory/ |
|
193 | + */ |
|
194 | + define('LOGS_PATH', ROOT_PATH . 'logs' . DS); |
|
195 | 195 | |
196 | - /** |
|
197 | - * The path to the modules directory. |
|
198 | - * |
|
199 | - * It contains your modules used files (config, controllers, libraries, etc.) that is to say which contains your files of the modules, |
|
200 | - * in HMVC architecture (hierichical, controllers, models, views). |
|
201 | - */ |
|
202 | - define('MODULE_PATH', ROOT_PATH . 'modules' . DS); |
|
196 | + /** |
|
197 | + * The path to the modules directory. |
|
198 | + * |
|
199 | + * It contains your modules used files (config, controllers, libraries, etc.) that is to say which contains your files of the modules, |
|
200 | + * in HMVC architecture (hierichical, controllers, models, views). |
|
201 | + */ |
|
202 | + define('MODULE_PATH', ROOT_PATH . 'modules' . DS); |
|
203 | 203 | |
204 | - /** |
|
205 | - * The path to the directory of sources external to your application. |
|
206 | - * |
|
207 | - * If you have already used "composer" you know what that means. |
|
208 | - */ |
|
209 | - define('VENDOR_PATH', ROOT_PATH . 'vendor' . DS); |
|
204 | + /** |
|
205 | + * The path to the directory of sources external to your application. |
|
206 | + * |
|
207 | + * If you have already used "composer" you know what that means. |
|
208 | + */ |
|
209 | + define('VENDOR_PATH', ROOT_PATH . 'vendor' . DS); |
|
210 | 210 | |
211 | - /** |
|
212 | - * The front controller of your application. |
|
213 | - * |
|
214 | - * "index.php" it is through this file that all the requests come, there is a possibility to hidden it in the url of |
|
215 | - * your application by using the rewrite module URL of your web server . |
|
216 | - * For example, under apache web server, there is a configuration example file that is located at the root |
|
217 | - * of your framework folder : "htaccess.txt" rename it to ".htaccess". |
|
218 | - */ |
|
219 | - define('SELF', pathinfo(__FILE__, PATHINFO_BASENAME)); |
|
211 | + /** |
|
212 | + * The front controller of your application. |
|
213 | + * |
|
214 | + * "index.php" it is through this file that all the requests come, there is a possibility to hidden it in the url of |
|
215 | + * your application by using the rewrite module URL of your web server . |
|
216 | + * For example, under apache web server, there is a configuration example file that is located at the root |
|
217 | + * of your framework folder : "htaccess.txt" rename it to ".htaccess". |
|
218 | + */ |
|
219 | + define('SELF', pathinfo(__FILE__, PATHINFO_BASENAME)); |
|
220 | 220 | |
221 | - /** |
|
222 | - * Check if user run the application under CLI |
|
223 | - */ |
|
224 | - define('IS_CLI', stripos('cli', php_sapi_name()) !== false); |
|
221 | + /** |
|
222 | + * Check if user run the application under CLI |
|
223 | + */ |
|
224 | + define('IS_CLI', stripos('cli', php_sapi_name()) !== false); |
|
225 | 225 | |
226 | - /** |
|
227 | - * The environment of your application (production, test, development). |
|
228 | - * |
|
229 | - * if your application is still in development you use the value "development" |
|
230 | - * so you will have the display of the error messages, etc. |
|
231 | - * Once you finish the development of your application that is to put it online |
|
232 | - * you change this value to "production" or "testing", in this case there will be deactivation of error messages, |
|
233 | - * the loading of the system, will be fast. |
|
234 | - */ |
|
235 | - define('ENVIRONMENT', 'development'); |
|
226 | + /** |
|
227 | + * The environment of your application (production, test, development). |
|
228 | + * |
|
229 | + * if your application is still in development you use the value "development" |
|
230 | + * so you will have the display of the error messages, etc. |
|
231 | + * Once you finish the development of your application that is to put it online |
|
232 | + * you change this value to "production" or "testing", in this case there will be deactivation of error messages, |
|
233 | + * the loading of the system, will be fast. |
|
234 | + */ |
|
235 | + define('ENVIRONMENT', 'development'); |
|
236 | 236 | |
237 | - /* ---------------------------------------------------------------------------------- */ |
|
238 | - /////////////////////////////////////////////////////////////////////////////////////// |
|
239 | - /******************** DO NOT CHANGE THE LINES BELOW *********************************/ |
|
240 | - ///////////////////////////////////////////////////////////////////////////////////// |
|
237 | + /* ---------------------------------------------------------------------------------- */ |
|
238 | + /////////////////////////////////////////////////////////////////////////////////////// |
|
239 | + /******************** DO NOT CHANGE THE LINES BELOW *********************************/ |
|
240 | + ///////////////////////////////////////////////////////////////////////////////////// |
|
241 | 241 | |
242 | - switch (ENVIRONMENT) { |
|
243 | - case 'development': |
|
244 | - error_reporting(-1); |
|
245 | - ini_set('display_errors', 1); |
|
246 | - break; |
|
247 | - case 'testing': |
|
248 | - case 'production': |
|
249 | - ini_set('display_errors', 0); |
|
250 | - if (version_compare(PHP_VERSION, '5.3', '>=')) { |
|
251 | - error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED & ~E_STRICT & ~E_USER_NOTICE & ~E_USER_DEPRECATED); |
|
252 | - } |
|
253 | - else{ |
|
254 | - error_reporting(E_ALL & ~E_NOTICE & ~E_STRICT & ~E_USER_NOTICE); |
|
255 | - } |
|
256 | - break; |
|
257 | - default: |
|
258 | - header('HTTP/1.1 503 Service Unavailable.', TRUE, 503); |
|
259 | - echo 'The application environment is not set correctly.'; |
|
260 | - exit(1); |
|
261 | - } |
|
242 | + switch (ENVIRONMENT) { |
|
243 | + case 'development': |
|
244 | + error_reporting(-1); |
|
245 | + ini_set('display_errors', 1); |
|
246 | + break; |
|
247 | + case 'testing': |
|
248 | + case 'production': |
|
249 | + ini_set('display_errors', 0); |
|
250 | + if (version_compare(PHP_VERSION, '5.3', '>=')) { |
|
251 | + error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED & ~E_STRICT & ~E_USER_NOTICE & ~E_USER_DEPRECATED); |
|
252 | + } |
|
253 | + else{ |
|
254 | + error_reporting(E_ALL & ~E_NOTICE & ~E_STRICT & ~E_USER_NOTICE); |
|
255 | + } |
|
256 | + break; |
|
257 | + default: |
|
258 | + header('HTTP/1.1 503 Service Unavailable.', TRUE, 503); |
|
259 | + echo 'The application environment is not set correctly.'; |
|
260 | + exit(1); |
|
261 | + } |
|
262 | 262 | |
263 | - /** |
|
264 | - * let's go. |
|
265 | - * Everything is OK now we launch our application. |
|
266 | - */ |
|
267 | - require_once CORE_PATH . 'bootstrap.php'; |
|
268 | 263 | \ No newline at end of file |
264 | + /** |
|
265 | + * let's go. |
|
266 | + * Everything is OK now we launch our application. |
|
267 | + */ |
|
268 | + require_once CORE_PATH . 'bootstrap.php'; |
|
269 | 269 | \ No newline at end of file |
@@ -78,8 +78,7 @@ discard block |
||
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 |
||
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 |
||
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 | } |
@@ -1,197 +1,197 @@ |
||
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 | - if($RESPONSE->renderFinalPageFromCache($CACHE)){ |
|
183 | - return; |
|
184 | - } |
|
185 | - } |
|
186 | - } |
|
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 | + if($RESPONSE->renderFinalPageFromCache($CACHE)){ |
|
183 | + return; |
|
184 | + } |
|
185 | + } |
|
186 | + } |
|
187 | 187 | |
188 | - //load model class |
|
189 | - require_once CORE_CLASSES_MODEL_PATH . 'Model.php'; |
|
188 | + //load model class |
|
189 | + require_once CORE_CLASSES_MODEL_PATH . 'Model.php'; |
|
190 | 190 | |
191 | - $LOGGER->info('Everything is OK load Router library and dispatch the request to the corresponding controller'); |
|
192 | - /** |
|
193 | - * Routing |
|
194 | - * instantiation of the "Router" class and request processing. |
|
195 | - */ |
|
196 | - $ROUTER = & class_loader('Router', 'classes'); |
|
197 | - $ROUTER->processRequest(); |
|
191 | + $LOGGER->info('Everything is OK load Router library and dispatch the request to the corresponding controller'); |
|
192 | + /** |
|
193 | + * Routing |
|
194 | + * instantiation of the "Router" class and request processing. |
|
195 | + */ |
|
196 | + $ROUTER = & class_loader('Router', 'classes'); |
|
197 | + $ROUTER->processRequest(); |
@@ -41,7 +41,7 @@ discard block |
||
41 | 41 | */ |
42 | 42 | |
43 | 43 | //if the application is running in CLI mode $_SESSION global variable is not available |
44 | - if(IS_CLI){ |
|
44 | + if (IS_CLI) { |
|
45 | 45 | $_SESSION = array(); |
46 | 46 | } |
47 | 47 | |
@@ -60,14 +60,14 @@ discard block |
||
60 | 60 | /** |
61 | 61 | * The Benchmark class |
62 | 62 | */ |
63 | - $BENCHMARK =& class_loader('Benchmark'); |
|
63 | + $BENCHMARK = & class_loader('Benchmark'); |
|
64 | 64 | |
65 | 65 | $BENCHMARK->mark('APP_EXECUTION_START'); |
66 | 66 | |
67 | 67 | /** |
68 | 68 | * instance of the Log class |
69 | 69 | */ |
70 | - $LOGGER =& class_loader('Log', 'classes'); |
|
70 | + $LOGGER = & class_loader('Log', 'classes'); |
|
71 | 71 | |
72 | 72 | $LOGGER->setLogger('ApplicationBootstrap'); |
73 | 73 | |
@@ -76,10 +76,10 @@ discard block |
||
76 | 76 | /** |
77 | 77 | * Verification of the PHP environment: minimum and maximum version |
78 | 78 | */ |
79 | - if (version_compare(phpversion(), TNH_REQUIRED_PHP_MIN_VERSION, '<')){ |
|
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 | 81 | } |
82 | - else if(version_compare(phpversion(), TNH_REQUIRED_PHP_MAX_VERSION, '>')){ |
|
82 | + else if (version_compare(phpversion(), TNH_REQUIRED_PHP_MAX_VERSION, '>')) { |
|
83 | 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 | 84 | } |
85 | 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'); |
@@ -101,11 +101,11 @@ discard block |
||
101 | 101 | |
102 | 102 | //if user have some composer packages |
103 | 103 | $LOGGER->debug('Check for composer autoload'); |
104 | - if(file_exists(VENDOR_PATH . 'autoload.php')){ |
|
104 | + if (file_exists(VENDOR_PATH . 'autoload.php')) { |
|
105 | 105 | $LOGGER->info('The composer autoload file exists include it'); |
106 | 106 | require_once VENDOR_PATH . 'autoload.php'; |
107 | 107 | } |
108 | - else{ |
|
108 | + else { |
|
109 | 109 | $LOGGER->info('The composer autoload file does not exist skipping'); |
110 | 110 | } |
111 | 111 | |
@@ -122,7 +122,7 @@ discard block |
||
122 | 122 | * Load configurations and using the |
123 | 123 | * static method "init()" to initialize the Config class . |
124 | 124 | */ |
125 | - $CONFIG =& class_loader('Config', 'classes'); |
|
125 | + $CONFIG = & class_loader('Config', 'classes'); |
|
126 | 126 | $CONFIG->init(); |
127 | 127 | $BENCHMARK->mark('CONFIG_INIT_END'); |
128 | 128 | |
@@ -131,7 +131,7 @@ discard block |
||
131 | 131 | * Load modules and using the |
132 | 132 | * static method "init()" to initialize the Module class. |
133 | 133 | */ |
134 | - $MODULE =& class_loader('Module', 'classes'); |
|
134 | + $MODULE = & class_loader('Module', 'classes'); |
|
135 | 135 | $MODULE->init(); |
136 | 136 | $BENCHMARK->mark('MODULE_INIT_END'); |
137 | 137 | |
@@ -150,36 +150,36 @@ discard block |
||
150 | 150 | /** |
151 | 151 | * Loading Security class |
152 | 152 | */ |
153 | - $SECURITY =& class_loader('Security', 'classes'); |
|
153 | + $SECURITY = & class_loader('Security', 'classes'); |
|
154 | 154 | $SECURITY->checkWhiteListIpAccess(); |
155 | 155 | |
156 | 156 | /** |
157 | 157 | * Loading Url class |
158 | 158 | */ |
159 | - $URL =& class_loader('Url', 'classes'); |
|
159 | + $URL = & class_loader('Url', 'classes'); |
|
160 | 160 | |
161 | - if(get_config('cache_enable', false)){ |
|
161 | + if (get_config('cache_enable', false)) { |
|
162 | 162 | /** |
163 | 163 | * Load Cache interface file |
164 | 164 | */ |
165 | 165 | require_once CORE_CLASSES_CACHE_PATH . 'CacheInterface.php'; |
166 | 166 | $cacheHandler = get_config('cache_handler'); |
167 | - if(! $cacheHandler){ |
|
167 | + if (!$cacheHandler) { |
|
168 | 168 | show_error('The cache feature is enabled in the configuration but the cache handler class is not set.'); |
169 | 169 | } |
170 | 170 | $CACHE = null; |
171 | 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'); |
|
172 | + if (file_exists(CORE_CLASSES_CACHE_PATH . $cacheHandler . '.php')) { |
|
173 | + $CACHE = & class_loader($cacheHandler, 'classes/cache'); |
|
174 | 174 | } |
175 | - else{ |
|
175 | + else { |
|
176 | 176 | //it's not a system driver use user library |
177 | - $CACHE =& class_loader($cacheHandler); |
|
177 | + $CACHE = & class_loader($cacheHandler); |
|
178 | 178 | } |
179 | 179 | //check if the page already cached |
180 | - if(! empty($_SERVER['REQUEST_METHOD']) && strtolower($_SERVER['REQUEST_METHOD']) == 'get'){ |
|
180 | + if (!empty($_SERVER['REQUEST_METHOD']) && strtolower($_SERVER['REQUEST_METHOD']) == 'get') { |
|
181 | 181 | $RESPONSE = & class_loader('Response', 'classes'); |
182 | - if($RESPONSE->renderFinalPageFromCache($CACHE)){ |
|
182 | + if ($RESPONSE->renderFinalPageFromCache($CACHE)) { |
|
183 | 183 | return; |
184 | 184 | } |
185 | 185 | } |
@@ -24,7 +24,7 @@ |
||
24 | 24 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
25 | 25 | */ |
26 | 26 | |
27 | - interface CacheInterface{ |
|
27 | + interface CacheInterface { |
|
28 | 28 | |
29 | 29 | /** |
30 | 30 | * This is used to get the cache data using the key |
@@ -1,84 +1,84 @@ |
||
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 | - interface CacheInterface{ |
|
27 | + interface CacheInterface{ |
|
28 | 28 | |
29 | - /** |
|
30 | - * This is used to get the cache data using the key |
|
31 | - * @param string $key the key to identify the cache data |
|
32 | - * @return mixed the cache data if exists else return false |
|
33 | - */ |
|
34 | - public function get($key); |
|
29 | + /** |
|
30 | + * This is used to get the cache data using the key |
|
31 | + * @param string $key the key to identify the cache data |
|
32 | + * @return mixed the cache data if exists else return false |
|
33 | + */ |
|
34 | + public function get($key); |
|
35 | 35 | |
36 | 36 | |
37 | - /** |
|
38 | - * Save data to the cache |
|
39 | - * @param string $key the key to identify this cache data |
|
40 | - * @param mixed $data the cache data to be saved |
|
41 | - * @param integer $ttl the cache life time |
|
42 | - * @return boolean true if success otherwise will return false |
|
43 | - */ |
|
44 | - public function set($key, $data, $ttl = 0); |
|
37 | + /** |
|
38 | + * Save data to the cache |
|
39 | + * @param string $key the key to identify this cache data |
|
40 | + * @param mixed $data the cache data to be saved |
|
41 | + * @param integer $ttl the cache life time |
|
42 | + * @return boolean true if success otherwise will return false |
|
43 | + */ |
|
44 | + public function set($key, $data, $ttl = 0); |
|
45 | 45 | |
46 | 46 | |
47 | - /** |
|
48 | - * Delete the cache data for given key |
|
49 | - * @param string $key the key for cache to be deleted |
|
50 | - * @return boolean true if the cache is deleted, false if can't delete |
|
51 | - * the cache or the cache with the given key not exist |
|
52 | - */ |
|
53 | - public function delete($key); |
|
47 | + /** |
|
48 | + * Delete the cache data for given key |
|
49 | + * @param string $key the key for cache to be deleted |
|
50 | + * @return boolean true if the cache is deleted, false if can't delete |
|
51 | + * the cache or the cache with the given key not exist |
|
52 | + */ |
|
53 | + public function delete($key); |
|
54 | 54 | |
55 | 55 | |
56 | - /** |
|
57 | - * Get the cache information for given key |
|
58 | - * @param string $key the key for cache to get the information for |
|
59 | - * @return boolean|array the cache information. The associative array and must contains the following information: |
|
60 | - * 'mtime' => creation time of the cache (Unix timestamp), |
|
61 | - * 'expire' => expiration time of the cache (Unix timestamp), |
|
62 | - * 'ttl' => the time to live of the cache in second |
|
63 | - */ |
|
64 | - public function getInfo($key); |
|
56 | + /** |
|
57 | + * Get the cache information for given key |
|
58 | + * @param string $key the key for cache to get the information for |
|
59 | + * @return boolean|array the cache information. The associative array and must contains the following information: |
|
60 | + * 'mtime' => creation time of the cache (Unix timestamp), |
|
61 | + * 'expire' => expiration time of the cache (Unix timestamp), |
|
62 | + * 'ttl' => the time to live of the cache in second |
|
63 | + */ |
|
64 | + public function getInfo($key); |
|
65 | 65 | |
66 | 66 | |
67 | - /** |
|
68 | - * Used to delete expired cache data |
|
69 | - */ |
|
70 | - public function deleteExpiredCache(); |
|
67 | + /** |
|
68 | + * Used to delete expired cache data |
|
69 | + */ |
|
70 | + public function deleteExpiredCache(); |
|
71 | 71 | |
72 | - /** |
|
73 | - * Remove all cache data |
|
74 | - */ |
|
75 | - public function clean(); |
|
72 | + /** |
|
73 | + * Remove all cache data |
|
74 | + */ |
|
75 | + public function clean(); |
|
76 | 76 | |
77 | 77 | |
78 | - /** |
|
79 | - * Check whether the cache feature for the handle is supported |
|
80 | - * |
|
81 | - * @return bool |
|
82 | - */ |
|
83 | - public function isSupported(); |
|
84 | - } |
|
78 | + /** |
|
79 | + * Check whether the cache feature for the handle is supported |
|
80 | + * |
|
81 | + * @return bool |
|
82 | + */ |
|
83 | + public function isSupported(); |
|
84 | + } |
@@ -90,8 +90,7 @@ discard block |
||
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 |
||
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 |
||
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 | } |
@@ -23,7 +23,7 @@ discard block |
||
23 | 23 | * along with this program; if not, write to the Free Software |
24 | 24 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
25 | 25 | */ |
26 | - class Session{ |
|
26 | + class Session { |
|
27 | 27 | |
28 | 28 | /** |
29 | 29 | * The session flash key to use |
@@ -41,9 +41,9 @@ discard block |
||
41 | 41 | * Get the logger singleton instance |
42 | 42 | * @return Log the logger instance |
43 | 43 | */ |
44 | - private static function getLogger(){ |
|
45 | - if(self::$logger == null){ |
|
46 | - self::$logger[0] =& class_loader('Log', 'classes'); |
|
44 | + private static function getLogger() { |
|
45 | + if (self::$logger == null) { |
|
46 | + self::$logger[0] = & class_loader('Log', 'classes'); |
|
47 | 47 | self::$logger[0]->setLogger('Library::Session'); |
48 | 48 | } |
49 | 49 | return self::$logger[0]; |
@@ -55,14 +55,14 @@ discard block |
||
55 | 55 | * @param mixed $default the default value to use if can not find the session item in the list |
56 | 56 | * @return mixed the session value if exist or the default value |
57 | 57 | */ |
58 | - public static function get($item, $default = null){ |
|
58 | + public static function get($item, $default = null) { |
|
59 | 59 | $logger = self::getLogger(); |
60 | - $logger->debug('Getting session data for item [' .$item. '] ...'); |
|
61 | - if(array_key_exists($item, $_SESSION)){ |
|
60 | + $logger->debug('Getting session data for item [' . $item . '] ...'); |
|
61 | + if (array_key_exists($item, $_SESSION)) { |
|
62 | 62 | $logger->info('Found session data for item [' . $item . '] the vaue is : [' . stringfy_vars($_SESSION[$item]) . ']'); |
63 | 63 | return $_SESSION[$item]; |
64 | 64 | } |
65 | - $logger->warning('Cannot find session item [' . $item . '] using the default value ['. $default . ']'); |
|
65 | + $logger->warning('Cannot find session item [' . $item . '] using the default value [' . $default . ']'); |
|
66 | 66 | return $default; |
67 | 67 | } |
68 | 68 | |
@@ -71,7 +71,7 @@ discard block |
||
71 | 71 | * @param string $item the session item name to set |
72 | 72 | * @param mixed $value the session item value |
73 | 73 | */ |
74 | - public static function set($item, $value){ |
|
74 | + public static function set($item, $value) { |
|
75 | 75 | $logger = self::getLogger(); |
76 | 76 | $logger->debug('Setting session data for item [' . $item . '], value [' . stringfy_vars($value) . ']'); |
77 | 77 | $_SESSION[$item] = $value; |
@@ -83,16 +83,16 @@ discard block |
||
83 | 83 | * @param mixed $default the default value to use if can not find the session flash item in the list |
84 | 84 | * @return mixed the session flash value if exist or the default value |
85 | 85 | */ |
86 | - public static function getFlash($item, $default = null){ |
|
86 | + public static function getFlash($item, $default = null) { |
|
87 | 87 | $logger = self::getLogger(); |
88 | - $key = self::SESSION_FLASH_KEY.'_'.$item; |
|
88 | + $key = self::SESSION_FLASH_KEY . '_' . $item; |
|
89 | 89 | $return = array_key_exists($key, $_SESSION) ? |
90 | 90 | ($_SESSION[$key]) : $default; |
91 | - if(array_key_exists($key, $_SESSION)){ |
|
91 | + if (array_key_exists($key, $_SESSION)) { |
|
92 | 92 | unset($_SESSION[$key]); |
93 | 93 | } |
94 | - else{ |
|
95 | - $logger->warning('Cannot find session flash item ['. $key .'] using the default value ['. $default .']'); |
|
94 | + else { |
|
95 | + $logger->warning('Cannot find session flash item [' . $key . '] using the default value [' . $default . ']'); |
|
96 | 96 | } |
97 | 97 | return $return; |
98 | 98 | } |
@@ -102,8 +102,8 @@ discard block |
||
102 | 102 | * @param string $item the session flash item name |
103 | 103 | * @return boolean |
104 | 104 | */ |
105 | - public static function hasFlash($item){ |
|
106 | - $key = self::SESSION_FLASH_KEY.'_'.$item; |
|
105 | + public static function hasFlash($item) { |
|
106 | + $key = self::SESSION_FLASH_KEY . '_' . $item; |
|
107 | 107 | return array_key_exists($key, $_SESSION); |
108 | 108 | } |
109 | 109 | |
@@ -112,8 +112,8 @@ discard block |
||
112 | 112 | * @param string $item the session flash item name to set |
113 | 113 | * @param mixed $value the session flash item value |
114 | 114 | */ |
115 | - public static function setFlash($item, $value){ |
|
116 | - $key = self::SESSION_FLASH_KEY.'_'.$item; |
|
115 | + public static function setFlash($item, $value) { |
|
116 | + $key = self::SESSION_FLASH_KEY . '_' . $item; |
|
117 | 117 | $_SESSION[$key] = $value; |
118 | 118 | } |
119 | 119 | |
@@ -121,14 +121,14 @@ discard block |
||
121 | 121 | * Clear the session item in the list |
122 | 122 | * @param string $item the session item name to be deleted |
123 | 123 | */ |
124 | - public static function clear($item){ |
|
124 | + public static function clear($item) { |
|
125 | 125 | $logger = self::getLogger(); |
126 | - if(array_key_exists($item, $_SESSION)){ |
|
127 | - $logger->info('Deleting of session for item ['.$item.' ]'); |
|
126 | + if (array_key_exists($item, $_SESSION)) { |
|
127 | + $logger->info('Deleting of session for item [' . $item . ' ]'); |
|
128 | 128 | unset($_SESSION[$item]); |
129 | 129 | } |
130 | - else{ |
|
131 | - $logger->warning('Session item ['.$item.'] to be deleted does not exists'); |
|
130 | + else { |
|
131 | + $logger->warning('Session item [' . $item . '] to be deleted does not exists'); |
|
132 | 132 | } |
133 | 133 | } |
134 | 134 | |
@@ -136,15 +136,15 @@ discard block |
||
136 | 136 | * Clear the session flash item in the list |
137 | 137 | * @param string $item the session flash item name to be deleted |
138 | 138 | */ |
139 | - public static function clearFlash($item){ |
|
139 | + public static function clearFlash($item) { |
|
140 | 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.']'); |
|
141 | + $key = self::SESSION_FLASH_KEY . '_' . $item; |
|
142 | + if (array_key_exists($key, $_SESSION)) { |
|
143 | + $logger->info('Delete session flash for item [' . $item . ']'); |
|
144 | 144 | unset($_SESSION[$item]); |
145 | 145 | } |
146 | - else{ |
|
147 | - $logger->warning('Dession flash item ['.$item.'] to be deleted does not exists'); |
|
146 | + else { |
|
147 | + $logger->warning('Dession flash item [' . $item . '] to be deleted does not exists'); |
|
148 | 148 | } |
149 | 149 | } |
150 | 150 | |
@@ -153,14 +153,14 @@ discard block |
||
153 | 153 | * @param string $item the session item name |
154 | 154 | * @return boolean |
155 | 155 | */ |
156 | - public static function exists($item){ |
|
156 | + public static function exists($item) { |
|
157 | 157 | return array_key_exists($item, $_SESSION); |
158 | 158 | } |
159 | 159 | |
160 | 160 | /** |
161 | 161 | * Destroy all session data values |
162 | 162 | */ |
163 | - public static function clearAll(){ |
|
163 | + public static function clearAll() { |
|
164 | 164 | session_unset(); |
165 | 165 | session_destroy(); |
166 | 166 | } |
@@ -1,168 +1,168 @@ |
||
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 | + } |
@@ -82,8 +82,7 @@ discard block |
||
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 |
||
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 | } |
@@ -27,7 +27,7 @@ discard block |
||
27 | 27 | /** |
28 | 28 | * For application languages management |
29 | 29 | */ |
30 | - class Lang{ |
|
30 | + class Lang { |
|
31 | 31 | |
32 | 32 | /** |
33 | 33 | * The supported available language for this application. |
@@ -67,8 +67,8 @@ discard block |
||
67 | 67 | /** |
68 | 68 | * Construct new Lang instance |
69 | 69 | */ |
70 | - public function __construct(){ |
|
71 | - $this->logger =& class_loader('Log', 'classes'); |
|
70 | + public function __construct() { |
|
71 | + $this->logger = & class_loader('Log', 'classes'); |
|
72 | 72 | $this->logger->setLogger('Library::Lang'); |
73 | 73 | |
74 | 74 | $this->default = get_config('default_language', 'en'); |
@@ -76,8 +76,8 @@ discard block |
||
76 | 76 | |
77 | 77 | //add the supported languages ('key', 'display name') |
78 | 78 | $languages = get_config('languages', null); |
79 | - if(! empty($languages)){ |
|
80 | - foreach($languages as $key => $displayName){ |
|
79 | + if (!empty($languages)) { |
|
80 | + foreach ($languages as $key => $displayName) { |
|
81 | 81 | $this->addLang($key, $displayName); |
82 | 82 | } |
83 | 83 | } |
@@ -85,15 +85,15 @@ discard block |
||
85 | 85 | |
86 | 86 | //if the language exists in cookie use it |
87 | 87 | $cfgKey = get_config('language_cookie_name'); |
88 | - $this->logger->debug('Getting current language from cookie [' .$cfgKey. ']'); |
|
88 | + $this->logger->debug('Getting current language from cookie [' . $cfgKey . ']'); |
|
89 | 89 | $objCookie = & class_loader('Cookie'); |
90 | 90 | $cookieLang = $objCookie->get($cfgKey); |
91 | - if($cookieLang && $this->isValid($cookieLang)){ |
|
91 | + if ($cookieLang && $this->isValid($cookieLang)) { |
|
92 | 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. ']'); |
|
93 | + $this->logger->info('Language from cookie [' . $cfgKey . '] is valid so we will set the language using the cookie value [' . $cookieLang . ']'); |
|
94 | 94 | } |
95 | - else{ |
|
96 | - $this->logger->info('Language from cookie [' .$cfgKey. '] is not set, use the default value [' .$this->getDefault(). ']'); |
|
95 | + else { |
|
96 | + $this->logger->info('Language from cookie [' . $cfgKey . '] is not set, use the default value [' . $this->getDefault() . ']'); |
|
97 | 97 | $this->current = $this->getDefault(); |
98 | 98 | } |
99 | 99 | } |
@@ -103,7 +103,7 @@ discard block |
||
103 | 103 | * |
104 | 104 | * @return array the language message list |
105 | 105 | */ |
106 | - public function getAll(){ |
|
106 | + public function getAll() { |
|
107 | 107 | return $this->languages; |
108 | 108 | } |
109 | 109 | |
@@ -113,7 +113,7 @@ discard block |
||
113 | 113 | * @param string $key the language key to identify |
114 | 114 | * @param string $value the language message value |
115 | 115 | */ |
116 | - public function set($key, $value){ |
|
116 | + public function set($key, $value) { |
|
117 | 117 | $this->languages[$key] = $value; |
118 | 118 | } |
119 | 119 | |
@@ -125,11 +125,11 @@ discard block |
||
125 | 125 | * |
126 | 126 | * @return string the language message value |
127 | 127 | */ |
128 | - public function get($key, $default = 'LANGUAGE_ERROR'){ |
|
129 | - if(isset($this->languages[$key])){ |
|
128 | + public function get($key, $default = 'LANGUAGE_ERROR') { |
|
129 | + if (isset($this->languages[$key])) { |
|
130 | 130 | return $this->languages[$key]; |
131 | 131 | } |
132 | - $this->logger->warning('Language key [' .$key. '] does not exist use the default value [' .$default. ']'); |
|
132 | + $this->logger->warning('Language key [' . $key . '] does not exist use the default value [' . $default . ']'); |
|
133 | 133 | return $default; |
134 | 134 | } |
135 | 135 | |
@@ -140,10 +140,10 @@ discard block |
||
140 | 140 | * |
141 | 141 | * @return boolean true if the language directory exists, false or not |
142 | 142 | */ |
143 | - public function isValid($language){ |
|
143 | + public function isValid($language) { |
|
144 | 144 | $searchDir = array(CORE_LANG_PATH, APP_LANG_PATH); |
145 | - foreach($searchDir as $dir){ |
|
146 | - if(file_exists($dir . $language) && is_dir($dir . $language)){ |
|
145 | + foreach ($searchDir as $dir) { |
|
146 | + if (file_exists($dir . $language) && is_dir($dir . $language)) { |
|
147 | 147 | return true; |
148 | 148 | } |
149 | 149 | } |
@@ -155,7 +155,7 @@ discard block |
||
155 | 155 | * |
156 | 156 | * @return string the default language |
157 | 157 | */ |
158 | - public function getDefault(){ |
|
158 | + public function getDefault() { |
|
159 | 159 | return $this->default; |
160 | 160 | } |
161 | 161 | |
@@ -164,7 +164,7 @@ discard block |
||
164 | 164 | * |
165 | 165 | * @return string the current language |
166 | 166 | */ |
167 | - public function getCurrent(){ |
|
167 | + public function getCurrent() { |
|
168 | 168 | return $this->current; |
169 | 169 | } |
170 | 170 | |
@@ -174,14 +174,14 @@ discard block |
||
174 | 174 | * @param string $name the short language name like "en", "fr". |
175 | 175 | * @param string $description the human readable description of this language |
176 | 176 | */ |
177 | - public function addLang($name, $description){ |
|
178 | - if(isset($this->availables[$name])){ |
|
177 | + public function addLang($name, $description) { |
|
178 | + if (isset($this->availables[$name])) { |
|
179 | 179 | return; //already added cost in performance |
180 | 180 | } |
181 | - if($this->isValid($name)){ |
|
181 | + if ($this->isValid($name)) { |
|
182 | 182 | $this->availables[$name] = $description; |
183 | 183 | } |
184 | - else{ |
|
184 | + else { |
|
185 | 185 | show_error('The language [' . $name . '] is not valid or does not exists.'); |
186 | 186 | } |
187 | 187 | } |
@@ -191,7 +191,7 @@ discard block |
||
191 | 191 | * |
192 | 192 | * @return array the list of the application language |
193 | 193 | */ |
194 | - public function getSupported(){ |
|
194 | + public function getSupported() { |
|
195 | 195 | return $this->availables; |
196 | 196 | } |
197 | 197 | |
@@ -200,7 +200,7 @@ discard block |
||
200 | 200 | * |
201 | 201 | * @param array $langs the languages array of the messages to be added |
202 | 202 | */ |
203 | - public function addLangMessages(array $langs){ |
|
203 | + public function addLangMessages(array $langs) { |
|
204 | 204 | foreach ($langs as $key => $value) { |
205 | 205 | $this->set($key, $value); |
206 | 206 | } |
@@ -1,208 +1,208 @@ |
||
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 | + } |
@@ -103,8 +103,7 @@ |
||
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 | } |
@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
25 | 25 | */ |
26 | 26 | |
27 | - class Request{ |
|
27 | + class Request { |
|
28 | 28 | |
29 | 29 | /** |
30 | 30 | * The value for the super global $_GET |
@@ -90,21 +90,21 @@ discard block |
||
90 | 90 | /** |
91 | 91 | * Construct new request instance |
92 | 92 | */ |
93 | - public function __construct(){ |
|
93 | + public function __construct() { |
|
94 | 94 | $this->get = $_GET; |
95 | 95 | $this->post = $_POST; |
96 | 96 | $this->server = $_SERVER; |
97 | 97 | $this->query = $_REQUEST; |
98 | 98 | $this->cookie = $_COOKIE; |
99 | 99 | $this->file = $_FILES; |
100 | - $this->session =& class_loader('Session', 'classes'); |
|
100 | + $this->session = & class_loader('Session', 'classes'); |
|
101 | 101 | $this->method = $this->server('REQUEST_METHOD'); |
102 | 102 | $this->requestUri = $this->server('REQUEST_URI'); |
103 | 103 | $this->header = array(); |
104 | - if(function_exists('apache_request_headers')){ |
|
104 | + if (function_exists('apache_request_headers')) { |
|
105 | 105 | $this->header = apache_request_headers(); |
106 | 106 | } |
107 | - else if(function_exists('getallheaders')){ |
|
107 | + else if (function_exists('getallheaders')) { |
|
108 | 108 | $this->header = getallheaders(); |
109 | 109 | } |
110 | 110 | } |
@@ -113,7 +113,7 @@ discard block |
||
113 | 113 | * Get the request method |
114 | 114 | * @return string |
115 | 115 | */ |
116 | - public function method(){ |
|
116 | + public function method() { |
|
117 | 117 | return $this->method; |
118 | 118 | } |
119 | 119 | |
@@ -121,7 +121,7 @@ discard block |
||
121 | 121 | * Get the request URI |
122 | 122 | * @return string |
123 | 123 | */ |
124 | - public function requestUri(){ |
|
124 | + public function requestUri() { |
|
125 | 125 | return $this->requestUri; |
126 | 126 | } |
127 | 127 | |
@@ -131,13 +131,13 @@ discard block |
||
131 | 131 | * @param boolean $xss if need apply some XSS attack rule on the value |
132 | 132 | * @return array|mixed the item value if the key exists or all array if the key does not exists or is empty |
133 | 133 | */ |
134 | - public function query($key = null, $xss = true){ |
|
135 | - if(empty($key)){ |
|
134 | + public function query($key = null, $xss = true) { |
|
135 | + if (empty($key)) { |
|
136 | 136 | //return all |
137 | 137 | return $xss ? clean_input($this->query) : $this->query; |
138 | 138 | } |
139 | 139 | $query = array_key_exists($key, $this->query) ? $this->query[$key] : null; |
140 | - if($xss){ |
|
140 | + if ($xss) { |
|
141 | 141 | $query = clean_input($query); |
142 | 142 | } |
143 | 143 | return $query; |
@@ -149,13 +149,13 @@ discard block |
||
149 | 149 | * @param boolean $xss if need apply some XSS attack rule on the value |
150 | 150 | * @return array|mixed the item value if the key exists or all array if the key does not exists or is empty |
151 | 151 | */ |
152 | - public function get($key = null, $xss = true){ |
|
153 | - if(empty($key)){ |
|
152 | + public function get($key = null, $xss = true) { |
|
153 | + if (empty($key)) { |
|
154 | 154 | //return all |
155 | 155 | return $xss ? clean_input($this->get) : $this->get; |
156 | 156 | } |
157 | 157 | $get = array_key_exists($key, $this->get) ? $this->get[$key] : null; |
158 | - if($xss){ |
|
158 | + if ($xss) { |
|
159 | 159 | $get = clean_input($get); |
160 | 160 | } |
161 | 161 | return $get; |
@@ -167,13 +167,13 @@ discard block |
||
167 | 167 | * @param boolean $xss if need apply some XSS attack rule on the value |
168 | 168 | * @return array|mixed the item value if the key exists or all array if the key does not exists or is empty |
169 | 169 | */ |
170 | - public function post($key = null, $xss = true){ |
|
171 | - if(empty($key)){ |
|
170 | + public function post($key = null, $xss = true) { |
|
171 | + if (empty($key)) { |
|
172 | 172 | //return all |
173 | 173 | return $xss ? clean_input($this->post) : $this->post; |
174 | 174 | } |
175 | 175 | $post = array_key_exists($key, $this->post) ? $this->post[$key] : null; |
176 | - if($xss){ |
|
176 | + if ($xss) { |
|
177 | 177 | $post = clean_input($post); |
178 | 178 | } |
179 | 179 | return $post; |
@@ -185,13 +185,13 @@ discard block |
||
185 | 185 | * @param boolean $xss if need apply some XSS attack rule on the value |
186 | 186 | * @return array|mixed the item value if the key exists or all array if the key does not exists or is empty |
187 | 187 | */ |
188 | - public function server($key = null, $xss = true){ |
|
189 | - if(empty($key)){ |
|
188 | + public function server($key = null, $xss = true) { |
|
189 | + if (empty($key)) { |
|
190 | 190 | //return all |
191 | 191 | return $xss ? clean_input($this->server) : $this->server; |
192 | 192 | } |
193 | 193 | $server = array_key_exists($key, $this->server) ? $this->server[$key] : null; |
194 | - if($xss){ |
|
194 | + if ($xss) { |
|
195 | 195 | $server = clean_input($server); |
196 | 196 | } |
197 | 197 | return $server; |
@@ -203,13 +203,13 @@ discard block |
||
203 | 203 | * @param boolean $xss if need apply some XSS attack rule on the value |
204 | 204 | * @return array|mixed the item value if the key exists or all array if the key does not exists or is empty |
205 | 205 | */ |
206 | - public function cookie($key = null, $xss = true){ |
|
207 | - if(empty($key)){ |
|
206 | + public function cookie($key = null, $xss = true) { |
|
207 | + if (empty($key)) { |
|
208 | 208 | //return all |
209 | 209 | return $xss ? clean_input($this->cookie) : $this->cookie; |
210 | 210 | } |
211 | 211 | $cookie = array_key_exists($key, $this->cookie) ? $this->cookie[$key] : null; |
212 | - if($xss){ |
|
212 | + if ($xss) { |
|
213 | 213 | $cookie = clean_input($cookie); |
214 | 214 | } |
215 | 215 | return $cookie; |
@@ -220,7 +220,7 @@ discard block |
||
220 | 220 | * @param string $key the item key to be fetched |
221 | 221 | * @return array|mixed the item value if the key exists or all array if the key does not exists or is empty |
222 | 222 | */ |
223 | - public function file($key){ |
|
223 | + public function file($key) { |
|
224 | 224 | $file = array_key_exists($key, $this->file) ? $this->file[$key] : null; |
225 | 225 | return $file; |
226 | 226 | } |
@@ -231,9 +231,9 @@ discard block |
||
231 | 231 | * @param boolean $xss if need apply some XSS attack rule on the value |
232 | 232 | * @return array|mixed the item value if the key exists or null if the key does not exists |
233 | 233 | */ |
234 | - public function session($key, $xss = true){ |
|
234 | + public function session($key, $xss = true) { |
|
235 | 235 | $session = $this->session->get($key); |
236 | - if($xss){ |
|
236 | + if ($xss) { |
|
237 | 237 | $session = clean_input($session); |
238 | 238 | } |
239 | 239 | return $session; |
@@ -245,9 +245,9 @@ discard block |
||
245 | 245 | * @param boolean $xss if need apply some XSS attack rule on the value |
246 | 246 | * @return mixed the item value if the key exists or null if the key does not exists |
247 | 247 | */ |
248 | - public function header($key, $xss = true){ |
|
248 | + public function header($key, $xss = true) { |
|
249 | 249 | $header = array_key_exists($key, $this->header) ? $this->header[$key] : null; |
250 | - if($xss){ |
|
250 | + if ($xss) { |
|
251 | 251 | $header = clean_input($header); |
252 | 252 | } |
253 | 253 | return $header; |
@@ -1,256 +1,256 @@ |
||
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 | + } |
@@ -27,7 +27,7 @@ discard block |
||
27 | 27 | /** |
28 | 28 | * PDF library to generate PDF document using the library DOMPDF |
29 | 29 | */ |
30 | - class PDF{ |
|
30 | + class PDF { |
|
31 | 31 | |
32 | 32 | /** |
33 | 33 | * The dompdf instance |
@@ -44,11 +44,11 @@ discard block |
||
44 | 44 | /** |
45 | 45 | * Create PDF library instance |
46 | 46 | */ |
47 | - public function __construct(){ |
|
48 | - $this->logger =& class_loader('Log', 'classes'); |
|
47 | + public function __construct() { |
|
48 | + $this->logger = & class_loader('Log', 'classes'); |
|
49 | 49 | $this->logger->setLogger('Library::PDF'); |
50 | 50 | |
51 | - require_once VENDOR_PATH.'dompdf/dompdf_config.inc.php'; |
|
51 | + require_once VENDOR_PATH . 'dompdf/dompdf_config.inc.php'; |
|
52 | 52 | $this->dompdf = new Dompdf(); |
53 | 53 | } |
54 | 54 | |
@@ -62,15 +62,15 @@ discard block |
||
62 | 62 | * @return string|void if $stream is true send PDF document to browser for download, else return the generated PDF |
63 | 63 | * content like to join in Email attachment of for other purpose use. |
64 | 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. ']'); |
|
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 | 67 | $this->dompdf->load_html($html); |
68 | 68 | $this->dompdf->set_paper($paper, $orientation); |
69 | 69 | $this->dompdf->render(); |
70 | - if($stream){ |
|
70 | + if ($stream) { |
|
71 | 71 | $this->dompdf->stream($filename); |
72 | 72 | } |
73 | - else{ |
|
73 | + else { |
|
74 | 74 | return $this->dompdf->output(); |
75 | 75 | } |
76 | 76 | } |
@@ -80,7 +80,7 @@ discard block |
||
80 | 80 | * |
81 | 81 | * @return object the dompdf instance |
82 | 82 | */ |
83 | - public function getDompdf(){ |
|
83 | + public function getDompdf() { |
|
84 | 84 | return $this->dompdf; |
85 | 85 | } |
86 | 86 |
@@ -69,8 +69,7 @@ |
||
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 | } |
@@ -1,87 +1,87 @@ |
||
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 | + } |
@@ -150,8 +150,7 @@ |
||
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 | } |
@@ -86,7 +86,7 @@ discard block |
||
86 | 86 | */ |
87 | 87 | public function __construct() |
88 | 88 | { |
89 | - $this->logger =& class_loader('Log', 'classes'); |
|
89 | + $this->logger = & class_loader('Log', 'classes'); |
|
90 | 90 | $this->logger->setLogger('Library::Email'); |
91 | 91 | $this->reset(); |
92 | 92 | } |
@@ -148,10 +148,10 @@ discard block |
||
148 | 148 | public function setTos(array $emails) |
149 | 149 | { |
150 | 150 | foreach ($emails as $name => $email) { |
151 | - if(is_numeric($name)){ |
|
151 | + if (is_numeric($name)) { |
|
152 | 152 | $this->setTo($email); |
153 | 153 | } |
154 | - else{ |
|
154 | + else { |
|
155 | 155 | $this->setTo($email, $name); |
156 | 156 | } |
157 | 157 | } |
@@ -281,8 +281,8 @@ discard block |
||
281 | 281 | */ |
282 | 282 | public function addAttachment($path, $filename = null, $data = null) |
283 | 283 | { |
284 | - if(! file_exists($path)){ |
|
285 | - show_error('The file [' .$path. '] does not exists.'); |
|
284 | + if (!file_exists($path)) { |
|
285 | + show_error('The file [' . $path . '] does not exists.'); |
|
286 | 286 | } |
287 | 287 | $filename = empty($filename) ? basename($path) : $filename; |
288 | 288 | $filename = $this->encodeUtf8($this->filterOther((string) $filename)); |
@@ -304,13 +304,13 @@ discard block |
||
304 | 304 | */ |
305 | 305 | public function getAttachmentData($path) |
306 | 306 | { |
307 | - if(! file_exists($path)){ |
|
308 | - show_error('The file [' .$path. '] does not exists.'); |
|
307 | + if (!file_exists($path)) { |
|
308 | + show_error('The file [' . $path . '] does not exists.'); |
|
309 | 309 | } |
310 | 310 | $filesize = filesize($path); |
311 | 311 | $handle = fopen($path, "r"); |
312 | 312 | $attachment = null; |
313 | - if(is_resource($handle)){ |
|
313 | + if (is_resource($handle)) { |
|
314 | 314 | $attachment = fread($handle, $filesize); |
315 | 315 | fclose($handle); |
316 | 316 | } |
@@ -1,739 +1,739 @@ |
||
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 | + } |