@@ -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 | } |
@@ -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 | } |
@@ -1,207 +1,207 @@ |
||
| 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 | - * @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 | - */ |
|
| 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 | + * @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'; |
|
| 59 | - |
|
| 60 | - /** |
|
| 61 | - * Include of the file containing the BaseClass |
|
| 62 | - */ |
|
| 63 | - require_once CORE_CLASSES_PATH . 'BaseClass.php'; |
|
| 64 | - |
|
| 65 | - /** |
|
| 66 | - * Include of the file containing the BaseClass |
|
| 67 | - */ |
|
| 68 | - require_once CORE_CLASSES_PATH . 'BaseStaticClass.php'; |
|
| 69 | - |
|
| 70 | - /** |
|
| 71 | - * The Benchmark class |
|
| 72 | - */ |
|
| 73 | - $BENCHMARK =& class_loader('Benchmark'); |
|
| 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 | + |
|
| 60 | + /** |
|
| 61 | + * Include of the file containing the BaseClass |
|
| 62 | + */ |
|
| 63 | + require_once CORE_CLASSES_PATH . 'BaseClass.php'; |
|
| 64 | + |
|
| 65 | + /** |
|
| 66 | + * Include of the file containing the BaseClass |
|
| 67 | + */ |
|
| 68 | + require_once CORE_CLASSES_PATH . 'BaseStaticClass.php'; |
|
| 69 | + |
|
| 70 | + /** |
|
| 71 | + * The Benchmark class |
|
| 72 | + */ |
|
| 73 | + $BENCHMARK =& class_loader('Benchmark'); |
|
| 74 | 74 | |
| 75 | - $BENCHMARK->mark('APP_EXECUTION_START'); |
|
| 75 | + $BENCHMARK->mark('APP_EXECUTION_START'); |
|
| 76 | 76 | |
| 77 | - /** |
|
| 78 | - * instance of the Log class |
|
| 79 | - */ |
|
| 77 | + /** |
|
| 78 | + * instance of the Log class |
|
| 79 | + */ |
|
| 80 | 80 | $LOGGER =& class_loader('Log', 'classes'); |
| 81 | 81 | |
| 82 | 82 | $LOGGER->setLogger('ApplicationBootstrap'); |
| 83 | 83 | |
| 84 | 84 | $LOGGER->debug('Checking PHP version ...'); |
| 85 | 85 | |
| 86 | - /** |
|
| 87 | - * Verification of the PHP environment: minimum and maximum version |
|
| 88 | - */ |
|
| 89 | - if (version_compare(phpversion(), TNH_REQUIRED_PHP_MIN_VERSION, '<')){ |
|
| 90 | - 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'); |
|
| 91 | - } |
|
| 92 | - else if(version_compare(phpversion(), TNH_REQUIRED_PHP_MAX_VERSION, '>')){ |
|
| 93 | - 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'); |
|
| 94 | - } |
|
| 95 | - $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'); |
|
| 96 | - |
|
| 97 | - /** |
|
| 98 | - * Setting of the PHP error message handling function |
|
| 99 | - */ |
|
| 100 | - set_error_handler('php_error_handler'); |
|
| 101 | - |
|
| 102 | - /** |
|
| 103 | - * Setting of the PHP error exception handling function |
|
| 104 | - */ |
|
| 105 | - set_exception_handler('php_exception_handler'); |
|
| 106 | - |
|
| 107 | - /** |
|
| 108 | - * Setting of the PHP shutdown handling function |
|
| 109 | - */ |
|
| 110 | - register_shutdown_function('php_shudown_handler'); |
|
| 86 | + /** |
|
| 87 | + * Verification of the PHP environment: minimum and maximum version |
|
| 88 | + */ |
|
| 89 | + if (version_compare(phpversion(), TNH_REQUIRED_PHP_MIN_VERSION, '<')){ |
|
| 90 | + 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'); |
|
| 91 | + } |
|
| 92 | + else if(version_compare(phpversion(), TNH_REQUIRED_PHP_MAX_VERSION, '>')){ |
|
| 93 | + 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'); |
|
| 94 | + } |
|
| 95 | + $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'); |
|
| 96 | + |
|
| 97 | + /** |
|
| 98 | + * Setting of the PHP error message handling function |
|
| 99 | + */ |
|
| 100 | + set_error_handler('php_error_handler'); |
|
| 101 | + |
|
| 102 | + /** |
|
| 103 | + * Setting of the PHP error exception handling function |
|
| 104 | + */ |
|
| 105 | + set_exception_handler('php_exception_handler'); |
|
| 106 | + |
|
| 107 | + /** |
|
| 108 | + * Setting of the PHP shutdown handling function |
|
| 109 | + */ |
|
| 110 | + register_shutdown_function('php_shudown_handler'); |
|
| 111 | 111 | |
| 112 | - //if user have some composer packages |
|
| 113 | - $LOGGER->debug('Check for composer autoload'); |
|
| 114 | - if(file_exists(VENDOR_PATH . 'autoload.php')){ |
|
| 115 | - $LOGGER->info('The composer autoload file exists include it'); |
|
| 116 | - require_once VENDOR_PATH . 'autoload.php'; |
|
| 117 | - } |
|
| 118 | - else{ |
|
| 119 | - $LOGGER->info('The composer autoload file does not exist skipping'); |
|
| 120 | - } |
|
| 112 | + //if user have some composer packages |
|
| 113 | + $LOGGER->debug('Check for composer autoload'); |
|
| 114 | + if(file_exists(VENDOR_PATH . 'autoload.php')){ |
|
| 115 | + $LOGGER->info('The composer autoload file exists include it'); |
|
| 116 | + require_once VENDOR_PATH . 'autoload.php'; |
|
| 117 | + } |
|
| 118 | + else{ |
|
| 119 | + $LOGGER->info('The composer autoload file does not exist skipping'); |
|
| 120 | + } |
|
| 121 | 121 | |
| 122 | - $LOGGER->debug('Begin to load the required resources'); |
|
| 123 | - |
|
| 124 | - /** |
|
| 125 | - * Load the EventInfo class file |
|
| 126 | - */ |
|
| 127 | - require_once CORE_CLASSES_PATH . 'EventInfo.php'; |
|
| 128 | - |
|
| 129 | - |
|
| 130 | - $BENCHMARK->mark('CONFIG_INIT_START'); |
|
| 131 | - /** |
|
| 132 | - * Load configurations and using the |
|
| 133 | - * static method "init()" to initialize the Config class . |
|
| 134 | - */ |
|
| 135 | - $CONFIG =& class_loader('Config', 'classes'); |
|
| 136 | - $CONFIG->init(); |
|
| 137 | - $BENCHMARK->mark('CONFIG_INIT_END'); |
|
| 138 | - |
|
| 139 | - $BENCHMARK->mark('MODULE_INIT_START'); |
|
| 140 | - /** |
|
| 141 | - * Load modules and using the |
|
| 142 | - * static method "init()" to initialize the Module class. |
|
| 143 | - */ |
|
| 144 | - $MODULE =& class_loader('Module', 'classes'); |
|
| 145 | - $MODULE->init(); |
|
| 146 | - $BENCHMARK->mark('MODULE_INIT_END'); |
|
| 147 | - |
|
| 148 | - $LOGGER->debug('Loading Base Controller ...'); |
|
| 149 | - /** |
|
| 150 | - * Include of the file containing the Base Controller class |
|
| 151 | - */ |
|
| 152 | - require_once CORE_CLASSES_PATH . 'Controller.php'; |
|
| 153 | - $LOGGER->info('Base Controller loaded successfully'); |
|
| 154 | - |
|
| 155 | - /** |
|
| 156 | - * Register controllers autoload function |
|
| 157 | - */ |
|
| 158 | - spl_autoload_register('autoload_controller'); |
|
| 159 | - |
|
| 160 | - /** |
|
| 161 | - * Loading Security class |
|
| 162 | - */ |
|
| 163 | - $SECURITY =& class_loader('Security', 'classes'); |
|
| 164 | - $SECURITY->checkWhiteListIpAccess(); |
|
| 122 | + $LOGGER->debug('Begin to load the required resources'); |
|
| 123 | + |
|
| 124 | + /** |
|
| 125 | + * Load the EventInfo class file |
|
| 126 | + */ |
|
| 127 | + require_once CORE_CLASSES_PATH . 'EventInfo.php'; |
|
| 128 | + |
|
| 129 | + |
|
| 130 | + $BENCHMARK->mark('CONFIG_INIT_START'); |
|
| 131 | + /** |
|
| 132 | + * Load configurations and using the |
|
| 133 | + * static method "init()" to initialize the Config class . |
|
| 134 | + */ |
|
| 135 | + $CONFIG =& class_loader('Config', 'classes'); |
|
| 136 | + $CONFIG->init(); |
|
| 137 | + $BENCHMARK->mark('CONFIG_INIT_END'); |
|
| 138 | + |
|
| 139 | + $BENCHMARK->mark('MODULE_INIT_START'); |
|
| 140 | + /** |
|
| 141 | + * Load modules and using the |
|
| 142 | + * static method "init()" to initialize the Module class. |
|
| 143 | + */ |
|
| 144 | + $MODULE =& class_loader('Module', 'classes'); |
|
| 145 | + $MODULE->init(); |
|
| 146 | + $BENCHMARK->mark('MODULE_INIT_END'); |
|
| 147 | + |
|
| 148 | + $LOGGER->debug('Loading Base Controller ...'); |
|
| 149 | + /** |
|
| 150 | + * Include of the file containing the Base Controller class |
|
| 151 | + */ |
|
| 152 | + require_once CORE_CLASSES_PATH . 'Controller.php'; |
|
| 153 | + $LOGGER->info('Base Controller loaded successfully'); |
|
| 154 | + |
|
| 155 | + /** |
|
| 156 | + * Register controllers autoload function |
|
| 157 | + */ |
|
| 158 | + spl_autoload_register('autoload_controller'); |
|
| 159 | + |
|
| 160 | + /** |
|
| 161 | + * Loading Security class |
|
| 162 | + */ |
|
| 163 | + $SECURITY =& class_loader('Security', 'classes'); |
|
| 164 | + $SECURITY->checkWhiteListIpAccess(); |
|
| 165 | 165 | |
| 166 | - /** |
|
| 167 | - * Loading Url class |
|
| 168 | - */ |
|
| 169 | - $URL =& class_loader('Url', 'classes'); |
|
| 166 | + /** |
|
| 167 | + * Loading Url class |
|
| 168 | + */ |
|
| 169 | + $URL =& class_loader('Url', 'classes'); |
|
| 170 | 170 | |
| 171 | - if(get_config('cache_enable', false)){ |
|
| 172 | - /** |
|
| 173 | - * Load Cache interface file |
|
| 174 | - */ |
|
| 175 | - require_once CORE_CLASSES_CACHE_PATH . 'CacheInterface.php'; |
|
| 176 | - $cacheHandler = get_config('cache_handler'); |
|
| 177 | - if(! $cacheHandler){ |
|
| 178 | - show_error('The cache feature is enabled in the configuration but the cache handler class is not set.'); |
|
| 179 | - } |
|
| 180 | - $CACHE = null; |
|
| 181 | - //first check if the cache handler is the system driver |
|
| 182 | - if(file_exists(CORE_CLASSES_CACHE_PATH . $cacheHandler . '.php')){ |
|
| 183 | - $CACHE =& class_loader($cacheHandler, 'classes/cache'); |
|
| 184 | - } |
|
| 185 | - else{ |
|
| 186 | - //it's not a system driver use user library |
|
| 187 | - $CACHE =& class_loader($cacheHandler); |
|
| 188 | - } |
|
| 189 | - //check if the page already cached |
|
| 190 | - if(! empty($_SERVER['REQUEST_METHOD']) && strtolower($_SERVER['REQUEST_METHOD']) == 'get'){ |
|
| 191 | - $RESPONSE = & class_loader('Response', 'classes'); |
|
| 192 | - if ($RESPONSE->renderFinalPageFromCache($CACHE)){ |
|
| 193 | - return; |
|
| 194 | - } |
|
| 195 | - } |
|
| 196 | - } |
|
| 171 | + if(get_config('cache_enable', false)){ |
|
| 172 | + /** |
|
| 173 | + * Load Cache interface file |
|
| 174 | + */ |
|
| 175 | + require_once CORE_CLASSES_CACHE_PATH . 'CacheInterface.php'; |
|
| 176 | + $cacheHandler = get_config('cache_handler'); |
|
| 177 | + if(! $cacheHandler){ |
|
| 178 | + show_error('The cache feature is enabled in the configuration but the cache handler class is not set.'); |
|
| 179 | + } |
|
| 180 | + $CACHE = null; |
|
| 181 | + //first check if the cache handler is the system driver |
|
| 182 | + if(file_exists(CORE_CLASSES_CACHE_PATH . $cacheHandler . '.php')){ |
|
| 183 | + $CACHE =& class_loader($cacheHandler, 'classes/cache'); |
|
| 184 | + } |
|
| 185 | + else{ |
|
| 186 | + //it's not a system driver use user library |
|
| 187 | + $CACHE =& class_loader($cacheHandler); |
|
| 188 | + } |
|
| 189 | + //check if the page already cached |
|
| 190 | + if(! empty($_SERVER['REQUEST_METHOD']) && strtolower($_SERVER['REQUEST_METHOD']) == 'get'){ |
|
| 191 | + $RESPONSE = & class_loader('Response', 'classes'); |
|
| 192 | + if ($RESPONSE->renderFinalPageFromCache($CACHE)){ |
|
| 193 | + return; |
|
| 194 | + } |
|
| 195 | + } |
|
| 196 | + } |
|
| 197 | 197 | |
| 198 | - //load model class |
|
| 199 | - require_once CORE_CLASSES_MODEL_PATH . 'Model.php'; |
|
| 198 | + //load model class |
|
| 199 | + require_once CORE_CLASSES_MODEL_PATH . 'Model.php'; |
|
| 200 | 200 | |
| 201 | - $LOGGER->info('Everything is OK load Router library and dispatch the request to the corresponding controller'); |
|
| 202 | - /** |
|
| 203 | - * Routing |
|
| 204 | - * instantiation of the "Router" class and request processing. |
|
| 205 | - */ |
|
| 206 | - $ROUTER = & class_loader('Router', 'classes'); |
|
| 207 | - $ROUTER->processRequest(); |
|
| 201 | + $LOGGER->info('Everything is OK load Router library and dispatch the request to the corresponding controller'); |
|
| 202 | + /** |
|
| 203 | + * Routing |
|
| 204 | + * instantiation of the "Router" class and request processing. |
|
| 205 | + */ |
|
| 206 | + $ROUTER = & class_loader('Router', 'classes'); |
|
| 207 | + $ROUTER->processRequest(); |
|
@@ -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 | } |
@@ -1,150 +1,150 @@ |
||
| 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 extends BaseStaticClass{ |
|
| 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 extends BaseStaticClass{ |
|
| 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 | - * Get the session item value |
|
| 36 | - * @param string $item the session item name to get |
|
| 37 | - * @param mixed $default the default value to use if can not find the session item in the list |
|
| 38 | - * @return mixed the session value if exist or the default value |
|
| 39 | - */ |
|
| 40 | - public static function get($item, $default = null){ |
|
| 41 | - $logger = self::getLogger(); |
|
| 42 | - $logger->debug('Getting session data for item [' .$item. '] ...'); |
|
| 43 | - if(array_key_exists($item, $_SESSION)){ |
|
| 44 | - $logger->info('Found session data for item [' . $item . '] the vaue is : [' . stringfy_vars($_SESSION[$item]) . ']'); |
|
| 45 | - return $_SESSION[$item]; |
|
| 46 | - } |
|
| 47 | - $logger->warning('Cannot find session item [' . $item . '] using the default value ['. $default . ']'); |
|
| 48 | - return $default; |
|
| 49 | - } |
|
| 34 | + /** |
|
| 35 | + * Get the session item value |
|
| 36 | + * @param string $item the session item name to get |
|
| 37 | + * @param mixed $default the default value to use if can not find the session item in the list |
|
| 38 | + * @return mixed the session value if exist or the default value |
|
| 39 | + */ |
|
| 40 | + public static function get($item, $default = null){ |
|
| 41 | + $logger = self::getLogger(); |
|
| 42 | + $logger->debug('Getting session data for item [' .$item. '] ...'); |
|
| 43 | + if(array_key_exists($item, $_SESSION)){ |
|
| 44 | + $logger->info('Found session data for item [' . $item . '] the vaue is : [' . stringfy_vars($_SESSION[$item]) . ']'); |
|
| 45 | + return $_SESSION[$item]; |
|
| 46 | + } |
|
| 47 | + $logger->warning('Cannot find session item [' . $item . '] using the default value ['. $default . ']'); |
|
| 48 | + return $default; |
|
| 49 | + } |
|
| 50 | 50 | |
| 51 | - /** |
|
| 52 | - * Set the session item value |
|
| 53 | - * @param string $item the session item name to set |
|
| 54 | - * @param mixed $value the session item value |
|
| 55 | - */ |
|
| 56 | - public static function set($item, $value){ |
|
| 57 | - $logger = self::getLogger(); |
|
| 58 | - $logger->debug('Setting session data for item [' . $item . '], value [' . stringfy_vars($value) . ']'); |
|
| 59 | - $_SESSION[$item] = $value; |
|
| 60 | - } |
|
| 51 | + /** |
|
| 52 | + * Set the session item value |
|
| 53 | + * @param string $item the session item name to set |
|
| 54 | + * @param mixed $value the session item value |
|
| 55 | + */ |
|
| 56 | + public static function set($item, $value){ |
|
| 57 | + $logger = self::getLogger(); |
|
| 58 | + $logger->debug('Setting session data for item [' . $item . '], value [' . stringfy_vars($value) . ']'); |
|
| 59 | + $_SESSION[$item] = $value; |
|
| 60 | + } |
|
| 61 | 61 | |
| 62 | - /** |
|
| 63 | - * Get the session flash item value |
|
| 64 | - * @param string $item the session flash item name to get |
|
| 65 | - * @param mixed $default the default value to use if can not find the session flash item in the list |
|
| 66 | - * @return mixed the session flash value if exist or the default value |
|
| 67 | - */ |
|
| 68 | - public static function getFlash($item, $default = null){ |
|
| 69 | - $logger = self::getLogger(); |
|
| 70 | - $key = self::SESSION_FLASH_KEY.'_'.$item; |
|
| 71 | - $return = array_key_exists($key, $_SESSION) ? |
|
| 72 | - ($_SESSION[$key]) : $default; |
|
| 73 | - if(array_key_exists($key, $_SESSION)){ |
|
| 74 | - unset($_SESSION[$key]); |
|
| 75 | - } |
|
| 76 | - else{ |
|
| 77 | - $logger->warning('Cannot find session flash item ['. $key .'] using the default value ['. $default .']'); |
|
| 78 | - } |
|
| 79 | - return $return; |
|
| 80 | - } |
|
| 62 | + /** |
|
| 63 | + * Get the session flash item value |
|
| 64 | + * @param string $item the session flash item name to get |
|
| 65 | + * @param mixed $default the default value to use if can not find the session flash item in the list |
|
| 66 | + * @return mixed the session flash value if exist or the default value |
|
| 67 | + */ |
|
| 68 | + public static function getFlash($item, $default = null){ |
|
| 69 | + $logger = self::getLogger(); |
|
| 70 | + $key = self::SESSION_FLASH_KEY.'_'.$item; |
|
| 71 | + $return = array_key_exists($key, $_SESSION) ? |
|
| 72 | + ($_SESSION[$key]) : $default; |
|
| 73 | + if(array_key_exists($key, $_SESSION)){ |
|
| 74 | + unset($_SESSION[$key]); |
|
| 75 | + } |
|
| 76 | + else{ |
|
| 77 | + $logger->warning('Cannot find session flash item ['. $key .'] using the default value ['. $default .']'); |
|
| 78 | + } |
|
| 79 | + return $return; |
|
| 80 | + } |
|
| 81 | 81 | |
| 82 | - /** |
|
| 83 | - * Check whether the given session flash item exists |
|
| 84 | - * @param string $item the session flash item name |
|
| 85 | - * @return boolean |
|
| 86 | - */ |
|
| 87 | - public static function hasFlash($item){ |
|
| 88 | - $key = self::SESSION_FLASH_KEY.'_'.$item; |
|
| 89 | - return array_key_exists($key, $_SESSION); |
|
| 90 | - } |
|
| 82 | + /** |
|
| 83 | + * Check whether the given session flash item exists |
|
| 84 | + * @param string $item the session flash item name |
|
| 85 | + * @return boolean |
|
| 86 | + */ |
|
| 87 | + public static function hasFlash($item){ |
|
| 88 | + $key = self::SESSION_FLASH_KEY.'_'.$item; |
|
| 89 | + return array_key_exists($key, $_SESSION); |
|
| 90 | + } |
|
| 91 | 91 | |
| 92 | - /** |
|
| 93 | - * Set the session flash item value |
|
| 94 | - * @param string $item the session flash item name to set |
|
| 95 | - * @param mixed $value the session flash item value |
|
| 96 | - */ |
|
| 97 | - public static function setFlash($item, $value){ |
|
| 98 | - $key = self::SESSION_FLASH_KEY.'_'.$item; |
|
| 99 | - $_SESSION[$key] = $value; |
|
| 100 | - } |
|
| 92 | + /** |
|
| 93 | + * Set the session flash item value |
|
| 94 | + * @param string $item the session flash item name to set |
|
| 95 | + * @param mixed $value the session flash item value |
|
| 96 | + */ |
|
| 97 | + public static function setFlash($item, $value){ |
|
| 98 | + $key = self::SESSION_FLASH_KEY.'_'.$item; |
|
| 99 | + $_SESSION[$key] = $value; |
|
| 100 | + } |
|
| 101 | 101 | |
| 102 | - /** |
|
| 103 | - * Clear the session item in the list |
|
| 104 | - * @param string $item the session item name to be deleted |
|
| 105 | - */ |
|
| 106 | - public static function clear($item){ |
|
| 107 | - $logger = self::getLogger(); |
|
| 108 | - if(array_key_exists($item, $_SESSION)){ |
|
| 109 | - $logger->info('Deleting of session for item ['.$item.' ]'); |
|
| 110 | - unset($_SESSION[$item]); |
|
| 111 | - } |
|
| 112 | - else{ |
|
| 113 | - $logger->warning('Session item ['.$item.'] to be deleted does not exists'); |
|
| 114 | - } |
|
| 115 | - } |
|
| 102 | + /** |
|
| 103 | + * Clear the session item in the list |
|
| 104 | + * @param string $item the session item name to be deleted |
|
| 105 | + */ |
|
| 106 | + public static function clear($item){ |
|
| 107 | + $logger = self::getLogger(); |
|
| 108 | + if(array_key_exists($item, $_SESSION)){ |
|
| 109 | + $logger->info('Deleting of session for item ['.$item.' ]'); |
|
| 110 | + unset($_SESSION[$item]); |
|
| 111 | + } |
|
| 112 | + else{ |
|
| 113 | + $logger->warning('Session item ['.$item.'] to be deleted does not exists'); |
|
| 114 | + } |
|
| 115 | + } |
|
| 116 | 116 | |
| 117 | - /** |
|
| 118 | - * Clear the session flash item in the list |
|
| 119 | - * @param string $item the session flash item name to be deleted |
|
| 120 | - */ |
|
| 121 | - public static function clearFlash($item){ |
|
| 122 | - $logger = self::getLogger(); |
|
| 123 | - $key = self::SESSION_FLASH_KEY.'_'.$item; |
|
| 124 | - if(array_key_exists($key, $_SESSION)){ |
|
| 125 | - $logger->info('Delete session flash for item ['.$item.']'); |
|
| 126 | - unset($_SESSION[$item]); |
|
| 127 | - } |
|
| 128 | - else{ |
|
| 129 | - $logger->warning('Dession flash item ['.$item.'] to be deleted does not exists'); |
|
| 130 | - } |
|
| 131 | - } |
|
| 117 | + /** |
|
| 118 | + * Clear the session flash item in the list |
|
| 119 | + * @param string $item the session flash item name to be deleted |
|
| 120 | + */ |
|
| 121 | + public static function clearFlash($item){ |
|
| 122 | + $logger = self::getLogger(); |
|
| 123 | + $key = self::SESSION_FLASH_KEY.'_'.$item; |
|
| 124 | + if(array_key_exists($key, $_SESSION)){ |
|
| 125 | + $logger->info('Delete session flash for item ['.$item.']'); |
|
| 126 | + unset($_SESSION[$item]); |
|
| 127 | + } |
|
| 128 | + else{ |
|
| 129 | + $logger->warning('Dession flash item ['.$item.'] to be deleted does not exists'); |
|
| 130 | + } |
|
| 131 | + } |
|
| 132 | 132 | |
| 133 | - /** |
|
| 134 | - * Check whether the given session item exists |
|
| 135 | - * @param string $item the session item name |
|
| 136 | - * @return boolean |
|
| 137 | - */ |
|
| 138 | - public static function exists($item){ |
|
| 139 | - return array_key_exists($item, $_SESSION); |
|
| 140 | - } |
|
| 133 | + /** |
|
| 134 | + * Check whether the given session item exists |
|
| 135 | + * @param string $item the session item name |
|
| 136 | + * @return boolean |
|
| 137 | + */ |
|
| 138 | + public static function exists($item){ |
|
| 139 | + return array_key_exists($item, $_SESSION); |
|
| 140 | + } |
|
| 141 | 141 | |
| 142 | - /** |
|
| 143 | - * Destroy all session data values |
|
| 144 | - */ |
|
| 145 | - public static function clearAll(){ |
|
| 146 | - session_unset(); |
|
| 147 | - session_destroy(); |
|
| 148 | - } |
|
| 142 | + /** |
|
| 143 | + * Destroy all session data values |
|
| 144 | + */ |
|
| 145 | + public static function clearAll(){ |
|
| 146 | + session_unset(); |
|
| 147 | + session_destroy(); |
|
| 148 | + } |
|
| 149 | 149 | |
| 150 | - } |
|
| 150 | + } |
|
@@ -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 extends BaseStaticClass{ |
|
| 26 | + class Session extends BaseStaticClass { |
|
| 27 | 27 | |
| 28 | 28 | /** |
| 29 | 29 | * The session flash key to use |
@@ -37,14 +37,14 @@ discard block |
||
| 37 | 37 | * @param mixed $default the default value to use if can not find the session item in the list |
| 38 | 38 | * @return mixed the session value if exist or the default value |
| 39 | 39 | */ |
| 40 | - public static function get($item, $default = null){ |
|
| 40 | + public static function get($item, $default = null) { |
|
| 41 | 41 | $logger = self::getLogger(); |
| 42 | - $logger->debug('Getting session data for item [' .$item. '] ...'); |
|
| 43 | - if(array_key_exists($item, $_SESSION)){ |
|
| 42 | + $logger->debug('Getting session data for item [' . $item . '] ...'); |
|
| 43 | + if (array_key_exists($item, $_SESSION)) { |
|
| 44 | 44 | $logger->info('Found session data for item [' . $item . '] the vaue is : [' . stringfy_vars($_SESSION[$item]) . ']'); |
| 45 | 45 | return $_SESSION[$item]; |
| 46 | 46 | } |
| 47 | - $logger->warning('Cannot find session item [' . $item . '] using the default value ['. $default . ']'); |
|
| 47 | + $logger->warning('Cannot find session item [' . $item . '] using the default value [' . $default . ']'); |
|
| 48 | 48 | return $default; |
| 49 | 49 | } |
| 50 | 50 | |
@@ -53,7 +53,7 @@ discard block |
||
| 53 | 53 | * @param string $item the session item name to set |
| 54 | 54 | * @param mixed $value the session item value |
| 55 | 55 | */ |
| 56 | - public static function set($item, $value){ |
|
| 56 | + public static function set($item, $value) { |
|
| 57 | 57 | $logger = self::getLogger(); |
| 58 | 58 | $logger->debug('Setting session data for item [' . $item . '], value [' . stringfy_vars($value) . ']'); |
| 59 | 59 | $_SESSION[$item] = $value; |
@@ -65,16 +65,16 @@ discard block |
||
| 65 | 65 | * @param mixed $default the default value to use if can not find the session flash item in the list |
| 66 | 66 | * @return mixed the session flash value if exist or the default value |
| 67 | 67 | */ |
| 68 | - public static function getFlash($item, $default = null){ |
|
| 68 | + public static function getFlash($item, $default = null) { |
|
| 69 | 69 | $logger = self::getLogger(); |
| 70 | - $key = self::SESSION_FLASH_KEY.'_'.$item; |
|
| 70 | + $key = self::SESSION_FLASH_KEY . '_' . $item; |
|
| 71 | 71 | $return = array_key_exists($key, $_SESSION) ? |
| 72 | 72 | ($_SESSION[$key]) : $default; |
| 73 | - if(array_key_exists($key, $_SESSION)){ |
|
| 73 | + if (array_key_exists($key, $_SESSION)) { |
|
| 74 | 74 | unset($_SESSION[$key]); |
| 75 | 75 | } |
| 76 | - else{ |
|
| 77 | - $logger->warning('Cannot find session flash item ['. $key .'] using the default value ['. $default .']'); |
|
| 76 | + else { |
|
| 77 | + $logger->warning('Cannot find session flash item [' . $key . '] using the default value [' . $default . ']'); |
|
| 78 | 78 | } |
| 79 | 79 | return $return; |
| 80 | 80 | } |
@@ -84,8 +84,8 @@ discard block |
||
| 84 | 84 | * @param string $item the session flash item name |
| 85 | 85 | * @return boolean |
| 86 | 86 | */ |
| 87 | - public static function hasFlash($item){ |
|
| 88 | - $key = self::SESSION_FLASH_KEY.'_'.$item; |
|
| 87 | + public static function hasFlash($item) { |
|
| 88 | + $key = self::SESSION_FLASH_KEY . '_' . $item; |
|
| 89 | 89 | return array_key_exists($key, $_SESSION); |
| 90 | 90 | } |
| 91 | 91 | |
@@ -94,8 +94,8 @@ discard block |
||
| 94 | 94 | * @param string $item the session flash item name to set |
| 95 | 95 | * @param mixed $value the session flash item value |
| 96 | 96 | */ |
| 97 | - public static function setFlash($item, $value){ |
|
| 98 | - $key = self::SESSION_FLASH_KEY.'_'.$item; |
|
| 97 | + public static function setFlash($item, $value) { |
|
| 98 | + $key = self::SESSION_FLASH_KEY . '_' . $item; |
|
| 99 | 99 | $_SESSION[$key] = $value; |
| 100 | 100 | } |
| 101 | 101 | |
@@ -103,14 +103,14 @@ discard block |
||
| 103 | 103 | * Clear the session item in the list |
| 104 | 104 | * @param string $item the session item name to be deleted |
| 105 | 105 | */ |
| 106 | - public static function clear($item){ |
|
| 106 | + public static function clear($item) { |
|
| 107 | 107 | $logger = self::getLogger(); |
| 108 | - if(array_key_exists($item, $_SESSION)){ |
|
| 109 | - $logger->info('Deleting of session for item ['.$item.' ]'); |
|
| 108 | + if (array_key_exists($item, $_SESSION)) { |
|
| 109 | + $logger->info('Deleting of session for item [' . $item . ' ]'); |
|
| 110 | 110 | unset($_SESSION[$item]); |
| 111 | 111 | } |
| 112 | - else{ |
|
| 113 | - $logger->warning('Session item ['.$item.'] to be deleted does not exists'); |
|
| 112 | + else { |
|
| 113 | + $logger->warning('Session item [' . $item . '] to be deleted does not exists'); |
|
| 114 | 114 | } |
| 115 | 115 | } |
| 116 | 116 | |
@@ -118,15 +118,15 @@ discard block |
||
| 118 | 118 | * Clear the session flash item in the list |
| 119 | 119 | * @param string $item the session flash item name to be deleted |
| 120 | 120 | */ |
| 121 | - public static function clearFlash($item){ |
|
| 121 | + public static function clearFlash($item) { |
|
| 122 | 122 | $logger = self::getLogger(); |
| 123 | - $key = self::SESSION_FLASH_KEY.'_'.$item; |
|
| 124 | - if(array_key_exists($key, $_SESSION)){ |
|
| 125 | - $logger->info('Delete session flash for item ['.$item.']'); |
|
| 123 | + $key = self::SESSION_FLASH_KEY . '_' . $item; |
|
| 124 | + if (array_key_exists($key, $_SESSION)) { |
|
| 125 | + $logger->info('Delete session flash for item [' . $item . ']'); |
|
| 126 | 126 | unset($_SESSION[$item]); |
| 127 | 127 | } |
| 128 | - else{ |
|
| 129 | - $logger->warning('Dession flash item ['.$item.'] to be deleted does not exists'); |
|
| 128 | + else { |
|
| 129 | + $logger->warning('Dession flash item [' . $item . '] to be deleted does not exists'); |
|
| 130 | 130 | } |
| 131 | 131 | } |
| 132 | 132 | |
@@ -135,14 +135,14 @@ discard block |
||
| 135 | 135 | * @param string $item the session item name |
| 136 | 136 | * @return boolean |
| 137 | 137 | */ |
| 138 | - public static function exists($item){ |
|
| 138 | + public static function exists($item) { |
|
| 139 | 139 | return array_key_exists($item, $_SESSION); |
| 140 | 140 | } |
| 141 | 141 | |
| 142 | 142 | /** |
| 143 | 143 | * Destroy all session data values |
| 144 | 144 | */ |
| 145 | - public static function clearAll(){ |
|
| 145 | + public static function clearAll() { |
|
| 146 | 146 | session_unset(); |
| 147 | 147 | session_destroy(); |
| 148 | 148 | } |
@@ -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 | } |
@@ -1,201 +1,201 @@ |
||
| 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 extends BaseClass{ |
|
| 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 extends BaseClass{ |
|
| 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 | - * Construct new Lang instance |
|
| 63 | - */ |
|
| 64 | - public function __construct(){ |
|
| 65 | - parent::__construct(); |
|
| 66 | - |
|
| 67 | - $this->default = get_config('default_language', 'en'); |
|
| 68 | - $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 | + * Construct new Lang instance |
|
| 63 | + */ |
|
| 64 | + public function __construct(){ |
|
| 65 | + parent::__construct(); |
|
| 66 | + |
|
| 67 | + $this->default = get_config('default_language', 'en'); |
|
| 68 | + $this->logger->debug('Setting the supported languages'); |
|
| 69 | 69 | |
| 70 | - //add the supported languages ('key', 'display name') |
|
| 71 | - $languages = get_config('languages', null); |
|
| 72 | - if(! empty($languages)){ |
|
| 73 | - foreach($languages as $key => $displayName){ |
|
| 74 | - $this->addLang($key, $displayName); |
|
| 75 | - } |
|
| 76 | - } |
|
| 77 | - unset($languages); |
|
| 78 | - |
|
| 79 | - //if the language exists in cookie use it |
|
| 80 | - $cfgKey = get_config('language_cookie_name'); |
|
| 81 | - $this->logger->debug('Getting current language from cookie [' .$cfgKey. ']'); |
|
| 82 | - $objCookie = & class_loader('Cookie'); |
|
| 83 | - $cookieLang = $objCookie->get($cfgKey); |
|
| 84 | - if($cookieLang && $this->isValid($cookieLang)){ |
|
| 85 | - $this->current = $cookieLang; |
|
| 86 | - $this->logger->info('Language from cookie [' .$cfgKey. '] is valid so we will set the language using the cookie value [' .$cookieLang. ']'); |
|
| 87 | - } |
|
| 88 | - else{ |
|
| 89 | - $this->logger->info('Language from cookie [' .$cfgKey. '] is not set, use the default value [' .$this->getDefault(). ']'); |
|
| 90 | - $this->current = $this->getDefault(); |
|
| 91 | - } |
|
| 92 | - } |
|
| 93 | - |
|
| 94 | - /** |
|
| 95 | - * Get the all languages messages |
|
| 96 | - * |
|
| 97 | - * @return array the language message list |
|
| 98 | - */ |
|
| 99 | - public function getAll(){ |
|
| 100 | - return $this->languages; |
|
| 101 | - } |
|
| 102 | - |
|
| 103 | - /** |
|
| 104 | - * Set the language message |
|
| 105 | - * |
|
| 106 | - * @param string $key the language key to identify |
|
| 107 | - * @param string $value the language message value |
|
| 108 | - */ |
|
| 109 | - public function set($key, $value){ |
|
| 110 | - $this->languages[$key] = $value; |
|
| 111 | - } |
|
| 112 | - |
|
| 113 | - /** |
|
| 114 | - * Get the language message for the given key. If can't find return the default value |
|
| 115 | - * |
|
| 116 | - * @param string $key the message language key |
|
| 117 | - * @param string $default the default value to return if can not found the language message key |
|
| 118 | - * |
|
| 119 | - * @return string the language message value |
|
| 120 | - */ |
|
| 121 | - public function get($key, $default = 'LANGUAGE_ERROR'){ |
|
| 122 | - if(isset($this->languages[$key])){ |
|
| 123 | - return $this->languages[$key]; |
|
| 124 | - } |
|
| 125 | - $this->logger->warning('Language key [' .$key. '] does not exist use the default value [' .$default. ']'); |
|
| 126 | - return $default; |
|
| 127 | - } |
|
| 128 | - |
|
| 129 | - /** |
|
| 130 | - * Check whether the language file for given name exists |
|
| 131 | - * |
|
| 132 | - * @param string $language the language name like "fr", "en", etc. |
|
| 133 | - * |
|
| 134 | - * @return boolean true if the language directory exists, false or not |
|
| 135 | - */ |
|
| 136 | - public function isValid($language){ |
|
| 137 | - $searchDir = array(CORE_LANG_PATH, APP_LANG_PATH); |
|
| 138 | - foreach($searchDir as $dir){ |
|
| 139 | - if(file_exists($dir . $language) && is_dir($dir . $language)){ |
|
| 140 | - return true; |
|
| 141 | - } |
|
| 142 | - } |
|
| 143 | - return false; |
|
| 144 | - } |
|
| 145 | - |
|
| 146 | - /** |
|
| 147 | - * Get the default language value like "en" , "fr", etc. |
|
| 148 | - * |
|
| 149 | - * @return string the default language |
|
| 150 | - */ |
|
| 151 | - public function getDefault(){ |
|
| 152 | - return $this->default; |
|
| 153 | - } |
|
| 154 | - |
|
| 155 | - /** |
|
| 156 | - * Get the current language defined by cookie or the default value |
|
| 157 | - * |
|
| 158 | - * @return string the current language |
|
| 159 | - */ |
|
| 160 | - public function getCurrent(){ |
|
| 161 | - return $this->current; |
|
| 162 | - } |
|
| 163 | - |
|
| 164 | - /** |
|
| 165 | - * Add new supported or available language |
|
| 166 | - * |
|
| 167 | - * @param string $name the short language name like "en", "fr". |
|
| 168 | - * @param string $description the human readable description of this language |
|
| 169 | - */ |
|
| 170 | - public function addLang($name, $description){ |
|
| 171 | - if(isset($this->availables[$name])){ |
|
| 172 | - return; //already added cost in performance |
|
| 173 | - } |
|
| 174 | - if($this->isValid($name)){ |
|
| 175 | - $this->availables[$name] = $description; |
|
| 176 | - } |
|
| 177 | - else{ |
|
| 178 | - show_error('The language [' . $name . '] is not valid or does not exists.'); |
|
| 179 | - } |
|
| 180 | - } |
|
| 181 | - |
|
| 182 | - /** |
|
| 183 | - * Get the list of the application supported language |
|
| 184 | - * |
|
| 185 | - * @return array the list of the application language |
|
| 186 | - */ |
|
| 187 | - public function getSupported(){ |
|
| 188 | - return $this->availables; |
|
| 189 | - } |
|
| 190 | - |
|
| 191 | - /** |
|
| 192 | - * Add new language messages |
|
| 193 | - * |
|
| 194 | - * @param array $langs the languages array of the messages to be added |
|
| 195 | - */ |
|
| 196 | - public function addLangMessages(array $langs){ |
|
| 197 | - foreach ($langs as $key => $value) { |
|
| 198 | - $this->set($key, $value); |
|
| 199 | - } |
|
| 200 | - } |
|
| 201 | - } |
|
| 70 | + //add the supported languages ('key', 'display name') |
|
| 71 | + $languages = get_config('languages', null); |
|
| 72 | + if(! empty($languages)){ |
|
| 73 | + foreach($languages as $key => $displayName){ |
|
| 74 | + $this->addLang($key, $displayName); |
|
| 75 | + } |
|
| 76 | + } |
|
| 77 | + unset($languages); |
|
| 78 | + |
|
| 79 | + //if the language exists in cookie use it |
|
| 80 | + $cfgKey = get_config('language_cookie_name'); |
|
| 81 | + $this->logger->debug('Getting current language from cookie [' .$cfgKey. ']'); |
|
| 82 | + $objCookie = & class_loader('Cookie'); |
|
| 83 | + $cookieLang = $objCookie->get($cfgKey); |
|
| 84 | + if($cookieLang && $this->isValid($cookieLang)){ |
|
| 85 | + $this->current = $cookieLang; |
|
| 86 | + $this->logger->info('Language from cookie [' .$cfgKey. '] is valid so we will set the language using the cookie value [' .$cookieLang. ']'); |
|
| 87 | + } |
|
| 88 | + else{ |
|
| 89 | + $this->logger->info('Language from cookie [' .$cfgKey. '] is not set, use the default value [' .$this->getDefault(). ']'); |
|
| 90 | + $this->current = $this->getDefault(); |
|
| 91 | + } |
|
| 92 | + } |
|
| 93 | + |
|
| 94 | + /** |
|
| 95 | + * Get the all languages messages |
|
| 96 | + * |
|
| 97 | + * @return array the language message list |
|
| 98 | + */ |
|
| 99 | + public function getAll(){ |
|
| 100 | + return $this->languages; |
|
| 101 | + } |
|
| 102 | + |
|
| 103 | + /** |
|
| 104 | + * Set the language message |
|
| 105 | + * |
|
| 106 | + * @param string $key the language key to identify |
|
| 107 | + * @param string $value the language message value |
|
| 108 | + */ |
|
| 109 | + public function set($key, $value){ |
|
| 110 | + $this->languages[$key] = $value; |
|
| 111 | + } |
|
| 112 | + |
|
| 113 | + /** |
|
| 114 | + * Get the language message for the given key. If can't find return the default value |
|
| 115 | + * |
|
| 116 | + * @param string $key the message language key |
|
| 117 | + * @param string $default the default value to return if can not found the language message key |
|
| 118 | + * |
|
| 119 | + * @return string the language message value |
|
| 120 | + */ |
|
| 121 | + public function get($key, $default = 'LANGUAGE_ERROR'){ |
|
| 122 | + if(isset($this->languages[$key])){ |
|
| 123 | + return $this->languages[$key]; |
|
| 124 | + } |
|
| 125 | + $this->logger->warning('Language key [' .$key. '] does not exist use the default value [' .$default. ']'); |
|
| 126 | + return $default; |
|
| 127 | + } |
|
| 128 | + |
|
| 129 | + /** |
|
| 130 | + * Check whether the language file for given name exists |
|
| 131 | + * |
|
| 132 | + * @param string $language the language name like "fr", "en", etc. |
|
| 133 | + * |
|
| 134 | + * @return boolean true if the language directory exists, false or not |
|
| 135 | + */ |
|
| 136 | + public function isValid($language){ |
|
| 137 | + $searchDir = array(CORE_LANG_PATH, APP_LANG_PATH); |
|
| 138 | + foreach($searchDir as $dir){ |
|
| 139 | + if(file_exists($dir . $language) && is_dir($dir . $language)){ |
|
| 140 | + return true; |
|
| 141 | + } |
|
| 142 | + } |
|
| 143 | + return false; |
|
| 144 | + } |
|
| 145 | + |
|
| 146 | + /** |
|
| 147 | + * Get the default language value like "en" , "fr", etc. |
|
| 148 | + * |
|
| 149 | + * @return string the default language |
|
| 150 | + */ |
|
| 151 | + public function getDefault(){ |
|
| 152 | + return $this->default; |
|
| 153 | + } |
|
| 154 | + |
|
| 155 | + /** |
|
| 156 | + * Get the current language defined by cookie or the default value |
|
| 157 | + * |
|
| 158 | + * @return string the current language |
|
| 159 | + */ |
|
| 160 | + public function getCurrent(){ |
|
| 161 | + return $this->current; |
|
| 162 | + } |
|
| 163 | + |
|
| 164 | + /** |
|
| 165 | + * Add new supported or available language |
|
| 166 | + * |
|
| 167 | + * @param string $name the short language name like "en", "fr". |
|
| 168 | + * @param string $description the human readable description of this language |
|
| 169 | + */ |
|
| 170 | + public function addLang($name, $description){ |
|
| 171 | + if(isset($this->availables[$name])){ |
|
| 172 | + return; //already added cost in performance |
|
| 173 | + } |
|
| 174 | + if($this->isValid($name)){ |
|
| 175 | + $this->availables[$name] = $description; |
|
| 176 | + } |
|
| 177 | + else{ |
|
| 178 | + show_error('The language [' . $name . '] is not valid or does not exists.'); |
|
| 179 | + } |
|
| 180 | + } |
|
| 181 | + |
|
| 182 | + /** |
|
| 183 | + * Get the list of the application supported language |
|
| 184 | + * |
|
| 185 | + * @return array the list of the application language |
|
| 186 | + */ |
|
| 187 | + public function getSupported(){ |
|
| 188 | + return $this->availables; |
|
| 189 | + } |
|
| 190 | + |
|
| 191 | + /** |
|
| 192 | + * Add new language messages |
|
| 193 | + * |
|
| 194 | + * @param array $langs the languages array of the messages to be added |
|
| 195 | + */ |
|
| 196 | + public function addLangMessages(array $langs){ |
|
| 197 | + foreach ($langs as $key => $value) { |
|
| 198 | + $this->set($key, $value); |
|
| 199 | + } |
|
| 200 | + } |
|
| 201 | + } |
|
@@ -27,7 +27,7 @@ discard block |
||
| 27 | 27 | /** |
| 28 | 28 | * For application languages management |
| 29 | 29 | */ |
| 30 | - class Lang extends BaseClass{ |
|
| 30 | + class Lang extends BaseClass { |
|
| 31 | 31 | |
| 32 | 32 | /** |
| 33 | 33 | * The supported available language for this application. |
@@ -61,7 +61,7 @@ discard block |
||
| 61 | 61 | /** |
| 62 | 62 | * Construct new Lang instance |
| 63 | 63 | */ |
| 64 | - public function __construct(){ |
|
| 64 | + public function __construct() { |
|
| 65 | 65 | parent::__construct(); |
| 66 | 66 | |
| 67 | 67 | $this->default = get_config('default_language', 'en'); |
@@ -69,8 +69,8 @@ discard block |
||
| 69 | 69 | |
| 70 | 70 | //add the supported languages ('key', 'display name') |
| 71 | 71 | $languages = get_config('languages', null); |
| 72 | - if(! empty($languages)){ |
|
| 73 | - foreach($languages as $key => $displayName){ |
|
| 72 | + if (!empty($languages)) { |
|
| 73 | + foreach ($languages as $key => $displayName) { |
|
| 74 | 74 | $this->addLang($key, $displayName); |
| 75 | 75 | } |
| 76 | 76 | } |
@@ -78,15 +78,15 @@ discard block |
||
| 78 | 78 | |
| 79 | 79 | //if the language exists in cookie use it |
| 80 | 80 | $cfgKey = get_config('language_cookie_name'); |
| 81 | - $this->logger->debug('Getting current language from cookie [' .$cfgKey. ']'); |
|
| 81 | + $this->logger->debug('Getting current language from cookie [' . $cfgKey . ']'); |
|
| 82 | 82 | $objCookie = & class_loader('Cookie'); |
| 83 | 83 | $cookieLang = $objCookie->get($cfgKey); |
| 84 | - if($cookieLang && $this->isValid($cookieLang)){ |
|
| 84 | + if ($cookieLang && $this->isValid($cookieLang)) { |
|
| 85 | 85 | $this->current = $cookieLang; |
| 86 | - $this->logger->info('Language from cookie [' .$cfgKey. '] is valid so we will set the language using the cookie value [' .$cookieLang. ']'); |
|
| 86 | + $this->logger->info('Language from cookie [' . $cfgKey . '] is valid so we will set the language using the cookie value [' . $cookieLang . ']'); |
|
| 87 | 87 | } |
| 88 | - else{ |
|
| 89 | - $this->logger->info('Language from cookie [' .$cfgKey. '] is not set, use the default value [' .$this->getDefault(). ']'); |
|
| 88 | + else { |
|
| 89 | + $this->logger->info('Language from cookie [' . $cfgKey . '] is not set, use the default value [' . $this->getDefault() . ']'); |
|
| 90 | 90 | $this->current = $this->getDefault(); |
| 91 | 91 | } |
| 92 | 92 | } |
@@ -96,7 +96,7 @@ discard block |
||
| 96 | 96 | * |
| 97 | 97 | * @return array the language message list |
| 98 | 98 | */ |
| 99 | - public function getAll(){ |
|
| 99 | + public function getAll() { |
|
| 100 | 100 | return $this->languages; |
| 101 | 101 | } |
| 102 | 102 | |
@@ -106,7 +106,7 @@ discard block |
||
| 106 | 106 | * @param string $key the language key to identify |
| 107 | 107 | * @param string $value the language message value |
| 108 | 108 | */ |
| 109 | - public function set($key, $value){ |
|
| 109 | + public function set($key, $value) { |
|
| 110 | 110 | $this->languages[$key] = $value; |
| 111 | 111 | } |
| 112 | 112 | |
@@ -118,11 +118,11 @@ discard block |
||
| 118 | 118 | * |
| 119 | 119 | * @return string the language message value |
| 120 | 120 | */ |
| 121 | - public function get($key, $default = 'LANGUAGE_ERROR'){ |
|
| 122 | - if(isset($this->languages[$key])){ |
|
| 121 | + public function get($key, $default = 'LANGUAGE_ERROR') { |
|
| 122 | + if (isset($this->languages[$key])) { |
|
| 123 | 123 | return $this->languages[$key]; |
| 124 | 124 | } |
| 125 | - $this->logger->warning('Language key [' .$key. '] does not exist use the default value [' .$default. ']'); |
|
| 125 | + $this->logger->warning('Language key [' . $key . '] does not exist use the default value [' . $default . ']'); |
|
| 126 | 126 | return $default; |
| 127 | 127 | } |
| 128 | 128 | |
@@ -133,10 +133,10 @@ discard block |
||
| 133 | 133 | * |
| 134 | 134 | * @return boolean true if the language directory exists, false or not |
| 135 | 135 | */ |
| 136 | - public function isValid($language){ |
|
| 136 | + public function isValid($language) { |
|
| 137 | 137 | $searchDir = array(CORE_LANG_PATH, APP_LANG_PATH); |
| 138 | - foreach($searchDir as $dir){ |
|
| 139 | - if(file_exists($dir . $language) && is_dir($dir . $language)){ |
|
| 138 | + foreach ($searchDir as $dir) { |
|
| 139 | + if (file_exists($dir . $language) && is_dir($dir . $language)) { |
|
| 140 | 140 | return true; |
| 141 | 141 | } |
| 142 | 142 | } |
@@ -148,7 +148,7 @@ discard block |
||
| 148 | 148 | * |
| 149 | 149 | * @return string the default language |
| 150 | 150 | */ |
| 151 | - public function getDefault(){ |
|
| 151 | + public function getDefault() { |
|
| 152 | 152 | return $this->default; |
| 153 | 153 | } |
| 154 | 154 | |
@@ -157,7 +157,7 @@ discard block |
||
| 157 | 157 | * |
| 158 | 158 | * @return string the current language |
| 159 | 159 | */ |
| 160 | - public function getCurrent(){ |
|
| 160 | + public function getCurrent() { |
|
| 161 | 161 | return $this->current; |
| 162 | 162 | } |
| 163 | 163 | |
@@ -167,14 +167,14 @@ discard block |
||
| 167 | 167 | * @param string $name the short language name like "en", "fr". |
| 168 | 168 | * @param string $description the human readable description of this language |
| 169 | 169 | */ |
| 170 | - public function addLang($name, $description){ |
|
| 171 | - if(isset($this->availables[$name])){ |
|
| 170 | + public function addLang($name, $description) { |
|
| 171 | + if (isset($this->availables[$name])) { |
|
| 172 | 172 | return; //already added cost in performance |
| 173 | 173 | } |
| 174 | - if($this->isValid($name)){ |
|
| 174 | + if ($this->isValid($name)) { |
|
| 175 | 175 | $this->availables[$name] = $description; |
| 176 | 176 | } |
| 177 | - else{ |
|
| 177 | + else { |
|
| 178 | 178 | show_error('The language [' . $name . '] is not valid or does not exists.'); |
| 179 | 179 | } |
| 180 | 180 | } |
@@ -184,7 +184,7 @@ discard block |
||
| 184 | 184 | * |
| 185 | 185 | * @return array the list of the application language |
| 186 | 186 | */ |
| 187 | - public function getSupported(){ |
|
| 187 | + public function getSupported() { |
|
| 188 | 188 | return $this->availables; |
| 189 | 189 | } |
| 190 | 190 | |
@@ -193,7 +193,7 @@ discard block |
||
| 193 | 193 | * |
| 194 | 194 | * @param array $langs the languages array of the messages to be added |
| 195 | 195 | */ |
| 196 | - public function addLangMessages(array $langs){ |
|
| 196 | + public function addLangMessages(array $langs) { |
|
| 197 | 197 | foreach ($langs as $key => $value) { |
| 198 | 198 | $this->set($key, $value); |
| 199 | 199 | } |
@@ -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 | + } |
|
@@ -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,80 +1,80 @@ |
||
| 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 extends BaseClass{ |
|
| 27 | + /** |
|
| 28 | + * PDF library to generate PDF document using the library DOMPDF |
|
| 29 | + */ |
|
| 30 | + class PDF extends BaseClass{ |
|
| 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 | - * Create PDF library instance |
|
| 40 | - */ |
|
| 41 | - public function __construct(){ |
|
| 42 | - parent::__construct(); |
|
| 38 | + /** |
|
| 39 | + * Create PDF library instance |
|
| 40 | + */ |
|
| 41 | + public function __construct(){ |
|
| 42 | + parent::__construct(); |
|
| 43 | 43 | |
| 44 | - require_once VENDOR_PATH.'dompdf/dompdf_config.inc.php'; |
|
| 45 | - $this->dompdf = new Dompdf(); |
|
| 46 | - } |
|
| 44 | + require_once VENDOR_PATH.'dompdf/dompdf_config.inc.php'; |
|
| 45 | + $this->dompdf = new Dompdf(); |
|
| 46 | + } |
|
| 47 | 47 | |
| 48 | - /** |
|
| 49 | - * Generate PDF document |
|
| 50 | - * @param string $html the HTML content to use for generation |
|
| 51 | - * @param string $filename the generated PDF document filename |
|
| 52 | - * @param boolean $stream if need send the generated PDF to browser for download |
|
| 53 | - * @param string $paper the PDF document paper type like 'A4', 'A5', 'letter', etc. |
|
| 54 | - * @param string $orientation the PDF document orientation like 'portrait', 'landscape' |
|
| 55 | - * @return string|void if $stream is true send PDF document to browser for download, else return the generated PDF |
|
| 56 | - * content like to join in Email attachment of for other purpose use. |
|
| 57 | - */ |
|
| 58 | - public function generate($html, $filename = 'output.pdf', $stream = true, $paper = 'A4', $orientation = 'portrait'){ |
|
| 59 | - $this->logger->info('Generating of PDF document: filename [' .$filename. '], stream [' .($stream ? 'TRUE':'FALSE'). '], paper [' .$paper. '], orientation [' .$orientation. ']'); |
|
| 60 | - $this->dompdf->load_html($html); |
|
| 61 | - $this->dompdf->set_paper($paper, $orientation); |
|
| 62 | - $this->dompdf->render(); |
|
| 63 | - if($stream){ |
|
| 64 | - $this->dompdf->stream($filename); |
|
| 65 | - } |
|
| 66 | - else{ |
|
| 67 | - return $this->dompdf->output(); |
|
| 68 | - } |
|
| 69 | - } |
|
| 48 | + /** |
|
| 49 | + * Generate PDF document |
|
| 50 | + * @param string $html the HTML content to use for generation |
|
| 51 | + * @param string $filename the generated PDF document filename |
|
| 52 | + * @param boolean $stream if need send the generated PDF to browser for download |
|
| 53 | + * @param string $paper the PDF document paper type like 'A4', 'A5', 'letter', etc. |
|
| 54 | + * @param string $orientation the PDF document orientation like 'portrait', 'landscape' |
|
| 55 | + * @return string|void if $stream is true send PDF document to browser for download, else return the generated PDF |
|
| 56 | + * content like to join in Email attachment of for other purpose use. |
|
| 57 | + */ |
|
| 58 | + public function generate($html, $filename = 'output.pdf', $stream = true, $paper = 'A4', $orientation = 'portrait'){ |
|
| 59 | + $this->logger->info('Generating of PDF document: filename [' .$filename. '], stream [' .($stream ? 'TRUE':'FALSE'). '], paper [' .$paper. '], orientation [' .$orientation. ']'); |
|
| 60 | + $this->dompdf->load_html($html); |
|
| 61 | + $this->dompdf->set_paper($paper, $orientation); |
|
| 62 | + $this->dompdf->render(); |
|
| 63 | + if($stream){ |
|
| 64 | + $this->dompdf->stream($filename); |
|
| 65 | + } |
|
| 66 | + else{ |
|
| 67 | + return $this->dompdf->output(); |
|
| 68 | + } |
|
| 69 | + } |
|
| 70 | 70 | |
| 71 | - /** |
|
| 72 | - * Return the instance of Dompdf |
|
| 73 | - * |
|
| 74 | - * @return object the dompdf instance |
|
| 75 | - */ |
|
| 76 | - public function getDompdf(){ |
|
| 77 | - return $this->dompdf; |
|
| 78 | - } |
|
| 71 | + /** |
|
| 72 | + * Return the instance of Dompdf |
|
| 73 | + * |
|
| 74 | + * @return object the dompdf instance |
|
| 75 | + */ |
|
| 76 | + public function getDompdf(){ |
|
| 77 | + return $this->dompdf; |
|
| 78 | + } |
|
| 79 | 79 | |
| 80 | - } |
|
| 80 | + } |
|
@@ -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 extends BaseClass{ |
|
| 30 | + class PDF extends BaseClass { |
|
| 31 | 31 | |
| 32 | 32 | /** |
| 33 | 33 | * The dompdf instance |
@@ -38,10 +38,10 @@ discard block |
||
| 38 | 38 | /** |
| 39 | 39 | * Create PDF library instance |
| 40 | 40 | */ |
| 41 | - public function __construct(){ |
|
| 41 | + public function __construct() { |
|
| 42 | 42 | parent::__construct(); |
| 43 | 43 | |
| 44 | - require_once VENDOR_PATH.'dompdf/dompdf_config.inc.php'; |
|
| 44 | + require_once VENDOR_PATH . 'dompdf/dompdf_config.inc.php'; |
|
| 45 | 45 | $this->dompdf = new Dompdf(); |
| 46 | 46 | } |
| 47 | 47 | |
@@ -55,15 +55,15 @@ discard block |
||
| 55 | 55 | * @return string|void if $stream is true send PDF document to browser for download, else return the generated PDF |
| 56 | 56 | * content like to join in Email attachment of for other purpose use. |
| 57 | 57 | */ |
| 58 | - public function generate($html, $filename = 'output.pdf', $stream = true, $paper = 'A4', $orientation = 'portrait'){ |
|
| 59 | - $this->logger->info('Generating of PDF document: filename [' .$filename. '], stream [' .($stream ? 'TRUE':'FALSE'). '], paper [' .$paper. '], orientation [' .$orientation. ']'); |
|
| 58 | + public function generate($html, $filename = 'output.pdf', $stream = true, $paper = 'A4', $orientation = 'portrait') { |
|
| 59 | + $this->logger->info('Generating of PDF document: filename [' . $filename . '], stream [' . ($stream ? 'TRUE' : 'FALSE') . '], paper [' . $paper . '], orientation [' . $orientation . ']'); |
|
| 60 | 60 | $this->dompdf->load_html($html); |
| 61 | 61 | $this->dompdf->set_paper($paper, $orientation); |
| 62 | 62 | $this->dompdf->render(); |
| 63 | - if($stream){ |
|
| 63 | + if ($stream) { |
|
| 64 | 64 | $this->dompdf->stream($filename); |
| 65 | 65 | } |
| 66 | - else{ |
|
| 66 | + else { |
|
| 67 | 67 | return $this->dompdf->output(); |
| 68 | 68 | } |
| 69 | 69 | } |
@@ -73,7 +73,7 @@ discard block |
||
| 73 | 73 | * |
| 74 | 74 | * @return object the dompdf instance |
| 75 | 75 | */ |
| 76 | - public function getDompdf(){ |
|
| 76 | + public function getDompdf() { |
|
| 77 | 77 | return $this->dompdf; |
| 78 | 78 | } |
| 79 | 79 | |
@@ -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 | } |
@@ -1,733 +1,733 @@ |
||
| 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 extends BaseClass |
|
| 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 extends BaseClass |
|
| 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 | - /** |
|
| 78 | - * __construct |
|
| 79 | - * |
|
| 80 | - * Resets the class properties. |
|
| 81 | - */ |
|
| 82 | - public function __construct() |
|
| 83 | - { |
|
| 84 | - parent::__construct(); |
|
| 85 | - $this->reset(); |
|
| 86 | - } |
|
| 87 | - |
|
| 88 | - /** |
|
| 89 | - * reset |
|
| 90 | - * |
|
| 91 | - * Resets all properties to initial state. |
|
| 92 | - * |
|
| 93 | - * @return self |
|
| 94 | - */ |
|
| 95 | - public function reset() |
|
| 96 | - { |
|
| 97 | - $this->_to = array(); |
|
| 98 | - $this->_headers = array(); |
|
| 99 | - $this->_subject = null; |
|
| 100 | - $this->_message = null; |
|
| 101 | - $this->_wrap = 78; |
|
| 102 | - $this->_params = null; |
|
| 103 | - $this->_attachments = array(); |
|
| 104 | - $this->_uid = $this->getUniqueId(); |
|
| 105 | - return $this; |
|
| 106 | - } |
|
| 77 | + /** |
|
| 78 | + * __construct |
|
| 79 | + * |
|
| 80 | + * Resets the class properties. |
|
| 81 | + */ |
|
| 82 | + public function __construct() |
|
| 83 | + { |
|
| 84 | + parent::__construct(); |
|
| 85 | + $this->reset(); |
|
| 86 | + } |
|
| 87 | + |
|
| 88 | + /** |
|
| 89 | + * reset |
|
| 90 | + * |
|
| 91 | + * Resets all properties to initial state. |
|
| 92 | + * |
|
| 93 | + * @return self |
|
| 94 | + */ |
|
| 95 | + public function reset() |
|
| 96 | + { |
|
| 97 | + $this->_to = array(); |
|
| 98 | + $this->_headers = array(); |
|
| 99 | + $this->_subject = null; |
|
| 100 | + $this->_message = null; |
|
| 101 | + $this->_wrap = 78; |
|
| 102 | + $this->_params = null; |
|
| 103 | + $this->_attachments = array(); |
|
| 104 | + $this->_uid = $this->getUniqueId(); |
|
| 105 | + return $this; |
|
| 106 | + } |
|
| 107 | 107 | |
| 108 | - /** |
|
| 109 | - * setFrom |
|
| 110 | - * |
|
| 111 | - * @param string $email The email to send as from. |
|
| 112 | - * @param string $name The name to send as from. |
|
| 113 | - * |
|
| 114 | - * @return self |
|
| 115 | - */ |
|
| 116 | - public function setFrom($email, $name = null) |
|
| 117 | - { |
|
| 118 | - $this->addMailHeader('From', (string) $email, (string) $name); |
|
| 119 | - return $this; |
|
| 120 | - } |
|
| 121 | - |
|
| 122 | - /** |
|
| 123 | - * setTo |
|
| 124 | - * |
|
| 125 | - * @param string $email The email address to send to. |
|
| 126 | - * @param string $name The name of the person to send to. |
|
| 127 | - * |
|
| 128 | - * @return self |
|
| 129 | - */ |
|
| 130 | - public function setTo($email, $name = null) |
|
| 131 | - { |
|
| 132 | - $this->_to[] = $this->formatHeader((string) $email, (string) $name); |
|
| 133 | - return $this; |
|
| 134 | - } |
|
| 108 | + /** |
|
| 109 | + * setFrom |
|
| 110 | + * |
|
| 111 | + * @param string $email The email to send as from. |
|
| 112 | + * @param string $name The name to send as from. |
|
| 113 | + * |
|
| 114 | + * @return self |
|
| 115 | + */ |
|
| 116 | + public function setFrom($email, $name = null) |
|
| 117 | + { |
|
| 118 | + $this->addMailHeader('From', (string) $email, (string) $name); |
|
| 119 | + return $this; |
|
| 120 | + } |
|
| 121 | + |
|
| 122 | + /** |
|
| 123 | + * setTo |
|
| 124 | + * |
|
| 125 | + * @param string $email The email address to send to. |
|
| 126 | + * @param string $name The name of the person to send to. |
|
| 127 | + * |
|
| 128 | + * @return self |
|
| 129 | + */ |
|
| 130 | + public function setTo($email, $name = null) |
|
| 131 | + { |
|
| 132 | + $this->_to[] = $this->formatHeader((string) $email, (string) $name); |
|
| 133 | + return $this; |
|
| 134 | + } |
|
| 135 | 135 | |
| 136 | - /** |
|
| 137 | - * Set destination using array |
|
| 138 | - * @params array $emails the list of recipient. This is an associative array name => email |
|
| 139 | - * @example array('John Doe' => '[email protected]') |
|
| 140 | - * @return Object the current instance |
|
| 141 | - */ |
|
| 142 | - public function setTos(array $emails) |
|
| 143 | - { |
|
| 144 | - foreach ($emails as $name => $email) { |
|
| 145 | - if(is_numeric($name)){ |
|
| 146 | - $this->setTo($email); |
|
| 147 | - } |
|
| 148 | - else{ |
|
| 149 | - $this->setTo($email, $name); |
|
| 150 | - } |
|
| 151 | - } |
|
| 152 | - return $this; |
|
| 153 | - } |
|
| 154 | - |
|
| 155 | - |
|
| 156 | - /** |
|
| 157 | - * getTo |
|
| 158 | - * |
|
| 159 | - * Return an array of formatted To addresses. |
|
| 160 | - * |
|
| 161 | - * @return array |
|
| 162 | - */ |
|
| 163 | - public function getTo() |
|
| 164 | - { |
|
| 165 | - return $this->_to; |
|
| 166 | - } |
|
| 167 | - |
|
| 168 | - |
|
| 169 | - /** |
|
| 170 | - * setCc |
|
| 171 | - * |
|
| 172 | - * @param array $pairs An array of name => email pairs. |
|
| 173 | - * |
|
| 174 | - * @return self |
|
| 175 | - */ |
|
| 176 | - public function setCc(array $pairs) |
|
| 177 | - { |
|
| 178 | - return $this->addMailHeaders('Cc', $pairs); |
|
| 179 | - } |
|
| 180 | - |
|
| 181 | - /** |
|
| 182 | - * setBcc |
|
| 183 | - * |
|
| 184 | - * @param array $pairs An array of name => email pairs. |
|
| 185 | - * |
|
| 186 | - * @return self |
|
| 187 | - */ |
|
| 188 | - public function setBcc(array $pairs) |
|
| 189 | - { |
|
| 190 | - return $this->addMailHeaders('Bcc', $pairs); |
|
| 191 | - } |
|
| 192 | - |
|
| 193 | - /** |
|
| 194 | - * setReplyTo |
|
| 195 | - * |
|
| 196 | - * @param string $email |
|
| 197 | - * @param string $name |
|
| 198 | - * |
|
| 199 | - * @return self |
|
| 200 | - */ |
|
| 201 | - public function setReplyTo($email, $name = null) |
|
| 202 | - { |
|
| 203 | - return $this->addMailHeader('Reply-To', $email, $name); |
|
| 204 | - } |
|
| 205 | - |
|
| 206 | - /** |
|
| 207 | - * setHtml |
|
| 208 | - * |
|
| 209 | - * @return self |
|
| 210 | - */ |
|
| 211 | - public function setHtml() |
|
| 212 | - { |
|
| 213 | - $this->addGenericHeader( |
|
| 214 | - 'Content-Type', 'text/html; charset="utf-8"' |
|
| 215 | - ); |
|
| 216 | - return $this; |
|
| 217 | - } |
|
| 218 | - |
|
| 219 | - /** |
|
| 220 | - * setSubject |
|
| 221 | - * |
|
| 222 | - * @param string $subject The email subject |
|
| 223 | - * |
|
| 224 | - * @return self |
|
| 225 | - */ |
|
| 226 | - public function setSubject($subject) |
|
| 227 | - { |
|
| 228 | - $this->_subject = $this->encodeUtf8( |
|
| 229 | - $this->filterOther((string) $subject) |
|
| 230 | - ); |
|
| 231 | - return $this; |
|
| 232 | - } |
|
| 233 | - |
|
| 234 | - /** |
|
| 235 | - * getSubject function. |
|
| 236 | - * |
|
| 237 | - * @return string |
|
| 238 | - */ |
|
| 239 | - public function getSubject() |
|
| 240 | - { |
|
| 241 | - return $this->_subject; |
|
| 242 | - } |
|
| 243 | - |
|
| 244 | - /** |
|
| 245 | - * setMessage |
|
| 246 | - * |
|
| 247 | - * @param string $message The message to send. |
|
| 248 | - * |
|
| 249 | - * @return self |
|
| 250 | - */ |
|
| 251 | - public function setMessage($message) |
|
| 252 | - { |
|
| 253 | - $this->_message = str_replace("\n.", "\n..", (string) $message); |
|
| 254 | - return $this; |
|
| 255 | - } |
|
| 256 | - |
|
| 257 | - /** |
|
| 258 | - * getMessage |
|
| 259 | - * |
|
| 260 | - * @return string |
|
| 261 | - */ |
|
| 262 | - public function getMessage() |
|
| 263 | - { |
|
| 264 | - return $this->_message; |
|
| 265 | - } |
|
| 266 | - |
|
| 267 | - /** |
|
| 268 | - * addAttachment |
|
| 269 | - * |
|
| 270 | - * @param string $path The file path to the attachment. |
|
| 271 | - * @param string $filename The filename of the attachment when emailed. |
|
| 272 | - * @param string $data |
|
| 273 | - * |
|
| 274 | - * @return self |
|
| 275 | - */ |
|
| 276 | - public function addAttachment($path, $filename = null, $data = null) |
|
| 277 | - { |
|
| 278 | - if(! file_exists($path)){ |
|
| 279 | - show_error('The file [' .$path. '] does not exists.'); |
|
| 280 | - } |
|
| 281 | - $filename = empty($filename) ? basename($path) : $filename; |
|
| 282 | - $filename = $this->encodeUtf8($this->filterOther((string) $filename)); |
|
| 283 | - $data = empty($data) ? $this->getAttachmentData($path) : $data; |
|
| 284 | - $this->_attachments[] = array( |
|
| 285 | - 'path' => $path, |
|
| 286 | - 'file' => $filename, |
|
| 287 | - 'data' => chunk_split(base64_encode($data)) |
|
| 288 | - ); |
|
| 289 | - return $this; |
|
| 290 | - } |
|
| 291 | - |
|
| 292 | - /** |
|
| 293 | - * getAttachmentData |
|
| 294 | - * |
|
| 295 | - * @param string $path The path to the attachment file. |
|
| 296 | - * |
|
| 297 | - * @return string |
|
| 298 | - */ |
|
| 299 | - public function getAttachmentData($path) |
|
| 300 | - { |
|
| 301 | - if(! file_exists($path)){ |
|
| 302 | - show_error('The file [' .$path. '] does not exists.'); |
|
| 303 | - } |
|
| 304 | - $filesize = filesize($path); |
|
| 305 | - $handle = fopen($path, "r"); |
|
| 306 | - $attachment = null; |
|
| 307 | - if(is_resource($handle)){ |
|
| 308 | - $attachment = fread($handle, $filesize); |
|
| 309 | - fclose($handle); |
|
| 310 | - } |
|
| 311 | - return $attachment; |
|
| 312 | - } |
|
| 313 | - |
|
| 314 | - /** |
|
| 315 | - * addMailHeader |
|
| 316 | - * |
|
| 317 | - * @param string $header The header to add. |
|
| 318 | - * @param string $email The email to add. |
|
| 319 | - * @param string $name The name to add. |
|
| 320 | - * |
|
| 321 | - * @return self |
|
| 322 | - */ |
|
| 323 | - public function addMailHeader($header, $email, $name = null) |
|
| 324 | - { |
|
| 325 | - $address = $this->formatHeader((string) $email, (string) $name); |
|
| 326 | - $this->_headers[] = sprintf('%s: %s', (string) $header, $address); |
|
| 327 | - return $this; |
|
| 328 | - } |
|
| 329 | - |
|
| 330 | - /** |
|
| 331 | - * addMailHeaders |
|
| 332 | - * |
|
| 333 | - * @param string $header The header to add. |
|
| 334 | - * @param array $pairs An array of name => email pairs. |
|
| 335 | - * |
|
| 336 | - * @return self |
|
| 337 | - */ |
|
| 338 | - public function addMailHeaders($header, array $pairs) |
|
| 339 | - { |
|
| 340 | - if (count($pairs) === 0) { |
|
| 341 | - show_error('You must pass at least one name => email pair.'); |
|
| 342 | - } |
|
| 343 | - $addresses = array(); |
|
| 344 | - foreach ($pairs as $name => $email) { |
|
| 345 | - $name = is_numeric($name) ? null : $name; |
|
| 346 | - $addresses[] = $this->formatHeader($email, $name); |
|
| 347 | - } |
|
| 348 | - $this->addGenericHeader($header, implode(',', $addresses)); |
|
| 349 | - return $this; |
|
| 350 | - } |
|
| 351 | - |
|
| 352 | - /** |
|
| 353 | - * addGenericHeader |
|
| 354 | - * |
|
| 355 | - * @param string $name The generic header to add. |
|
| 356 | - * @param mixed $value The value of the header. |
|
| 357 | - * |
|
| 358 | - * @return self |
|
| 359 | - */ |
|
| 360 | - public function addGenericHeader($name, $value) |
|
| 361 | - { |
|
| 362 | - $this->_headers[] = sprintf( |
|
| 363 | - '%s: %s', |
|
| 364 | - (string) $name, |
|
| 365 | - (string) $value |
|
| 366 | - ); |
|
| 367 | - return $this; |
|
| 368 | - } |
|
| 369 | - |
|
| 370 | - /** |
|
| 371 | - * getHeaders |
|
| 372 | - * |
|
| 373 | - * Return the headers registered so far as an array. |
|
| 374 | - * |
|
| 375 | - * @return array |
|
| 376 | - */ |
|
| 377 | - public function getHeaders() |
|
| 378 | - { |
|
| 379 | - return $this->_headers; |
|
| 380 | - } |
|
| 381 | - |
|
| 382 | - /** |
|
| 383 | - * setAdditionalParameters |
|
| 384 | - * |
|
| 385 | - * Such as "[email protected] |
|
| 386 | - * |
|
| 387 | - * @param string $additionalParameters The addition mail parameter. |
|
| 388 | - * |
|
| 389 | - * @return self |
|
| 390 | - */ |
|
| 391 | - public function setParameters($additionalParameters) |
|
| 392 | - { |
|
| 393 | - $this->_params = (string) $additionalParameters; |
|
| 394 | - return $this; |
|
| 395 | - } |
|
| 396 | - |
|
| 397 | - /** |
|
| 398 | - * getAdditionalParameters |
|
| 399 | - * |
|
| 400 | - * @return string |
|
| 401 | - */ |
|
| 402 | - public function getParameters() |
|
| 403 | - { |
|
| 404 | - return $this->_params; |
|
| 405 | - } |
|
| 406 | - |
|
| 407 | - /** |
|
| 408 | - * setWrap |
|
| 409 | - * |
|
| 410 | - * @param int $wrap The number of characters at which the message will wrap. |
|
| 411 | - * |
|
| 412 | - * @return self |
|
| 413 | - */ |
|
| 414 | - public function setWrap($wrap = 78) |
|
| 415 | - { |
|
| 416 | - $wrap = (int) $wrap; |
|
| 417 | - if ($wrap < 1) { |
|
| 418 | - $wrap = 78; |
|
| 419 | - } |
|
| 420 | - $this->_wrap = $wrap; |
|
| 421 | - return $this; |
|
| 422 | - } |
|
| 423 | - |
|
| 424 | - /** |
|
| 425 | - * getWrap |
|
| 426 | - * |
|
| 427 | - * @return int |
|
| 428 | - */ |
|
| 429 | - public function getWrap() |
|
| 430 | - { |
|
| 431 | - return $this->_wrap; |
|
| 432 | - } |
|
| 433 | - |
|
| 434 | - /** |
|
| 435 | - * hasAttachments |
|
| 436 | - * |
|
| 437 | - * Checks if the email has any registered attachments. |
|
| 438 | - * |
|
| 439 | - * @return bool |
|
| 440 | - */ |
|
| 441 | - public function hasAttachments() |
|
| 442 | - { |
|
| 443 | - return !empty($this->_attachments); |
|
| 444 | - } |
|
| 445 | - |
|
| 446 | - /** |
|
| 447 | - * assembleAttachment |
|
| 448 | - * |
|
| 449 | - * @return string |
|
| 450 | - */ |
|
| 451 | - public function assembleAttachmentHeaders() |
|
| 452 | - { |
|
| 453 | - $head = array(); |
|
| 454 | - $head[] = "MIME-Version: 1.0"; |
|
| 455 | - $head[] = "Content-Type: multipart/mixed; boundary=\"{$this->_uid}\""; |
|
| 456 | - |
|
| 457 | - return join(PHP_EOL, $head); |
|
| 458 | - } |
|
| 459 | - |
|
| 460 | - /** |
|
| 461 | - * assembleAttachmentBody |
|
| 462 | - * |
|
| 463 | - * @return string |
|
| 464 | - */ |
|
| 465 | - public function assembleAttachmentBody() |
|
| 466 | - { |
|
| 467 | - $body = array(); |
|
| 468 | - $body[] = "This is a multi-part message in MIME format."; |
|
| 469 | - $body[] = "--{$this->_uid}"; |
|
| 470 | - $body[] = "Content-Type: text/html; charset=\"utf-8\""; |
|
| 471 | - $body[] = "Content-Transfer-Encoding: quoted-printable"; |
|
| 472 | - $body[] = ""; |
|
| 473 | - $body[] = quoted_printable_encode($this->_message); |
|
| 474 | - $body[] = ""; |
|
| 475 | - $body[] = "--{$this->_uid}"; |
|
| 476 | - |
|
| 477 | - foreach ($this->_attachments as $attachment) { |
|
| 478 | - $body[] = $this->getAttachmentMimeTemplate($attachment); |
|
| 479 | - } |
|
| 480 | - |
|
| 481 | - return implode(PHP_EOL, $body) . '--'; |
|
| 482 | - } |
|
| 483 | - |
|
| 484 | - /** |
|
| 485 | - * getAttachmentMimeTemplate |
|
| 486 | - * |
|
| 487 | - * @param array $attachment An array containing 'file' and 'data' keys. |
|
| 488 | - * |
|
| 489 | - * @return string |
|
| 490 | - */ |
|
| 491 | - public function getAttachmentMimeTemplate($attachment) |
|
| 492 | - { |
|
| 493 | - $file = $attachment['file']; |
|
| 494 | - $data = $attachment['data']; |
|
| 495 | - |
|
| 496 | - $head = array(); |
|
| 497 | - $head[] = "Content-Type: application/octet-stream; name=\"{$file}\""; |
|
| 498 | - $head[] = "Content-Transfer-Encoding: base64"; |
|
| 499 | - $head[] = "Content-Disposition: attachment; filename=\"{$file}\""; |
|
| 500 | - $head[] = ""; |
|
| 501 | - $head[] = $data; |
|
| 502 | - $head[] = ""; |
|
| 503 | - $head[] = "--{$this->_uid}"; |
|
| 504 | - |
|
| 505 | - return implode(PHP_EOL, $head); |
|
| 506 | - } |
|
| 507 | - |
|
| 508 | - /** |
|
| 509 | - * send the email |
|
| 510 | - * |
|
| 511 | - * @return boolean |
|
| 512 | - */ |
|
| 513 | - public function send() |
|
| 514 | - { |
|
| 515 | - $to = $this->getToForSend(); |
|
| 516 | - $headers = $this->getHeadersForSend(); |
|
| 517 | - |
|
| 518 | - if (empty($to)) { |
|
| 519 | - show_error('Unable to send, no To address has been set.'); |
|
| 520 | - } |
|
| 521 | - |
|
| 522 | - if ($this->hasAttachments()) { |
|
| 523 | - $message = $this->assembleAttachmentBody(); |
|
| 524 | - $headers .= PHP_EOL . $this->assembleAttachmentHeaders(); |
|
| 525 | - } else { |
|
| 526 | - $message = $this->getWrapMessage(); |
|
| 527 | - } |
|
| 528 | - $this->logger->info('Sending new mail, the information are listed below: destination: ' . $to . ', headers: ' . $headers . ', message: ' . $message); |
|
| 529 | - return mail($to, $this->_subject, $message, $headers, $this->_params); |
|
| 530 | - } |
|
| 531 | - |
|
| 532 | - /** |
|
| 533 | - * debug |
|
| 534 | - * |
|
| 535 | - * @return string |
|
| 536 | - */ |
|
| 537 | - public function debug() |
|
| 538 | - { |
|
| 539 | - return '<pre>' . print_r($this, true) . '</pre>'; |
|
| 540 | - } |
|
| 541 | - |
|
| 542 | - /** |
|
| 543 | - * magic __toString function |
|
| 544 | - * |
|
| 545 | - * @return string |
|
| 546 | - */ |
|
| 547 | - public function __toString() |
|
| 548 | - { |
|
| 549 | - return print_r($this, true); |
|
| 550 | - } |
|
| 551 | - |
|
| 552 | - /** |
|
| 553 | - * formatHeader |
|
| 554 | - * |
|
| 555 | - * Formats a display address for emails according to RFC2822 e.g. |
|
| 556 | - * Name <[email protected]> |
|
| 557 | - * |
|
| 558 | - * @param string $email The email address. |
|
| 559 | - * @param string $name The display name. |
|
| 560 | - * |
|
| 561 | - * @return string |
|
| 562 | - */ |
|
| 563 | - public function formatHeader($email, $name = null) |
|
| 564 | - { |
|
| 565 | - $email = $this->filterEmail((string) $email); |
|
| 566 | - if (empty($name)) { |
|
| 567 | - return $email; |
|
| 568 | - } |
|
| 569 | - $name = $this->encodeUtf8($this->filterName((string) $name)); |
|
| 570 | - return sprintf('"%s" <%s>', $name, $email); |
|
| 571 | - } |
|
| 572 | - |
|
| 573 | - /** |
|
| 574 | - * encodeUtf8 |
|
| 575 | - * |
|
| 576 | - * @param string $value The value to encode. |
|
| 577 | - * |
|
| 578 | - * @return string |
|
| 579 | - */ |
|
| 580 | - public function encodeUtf8($value) |
|
| 581 | - { |
|
| 582 | - $value = trim($value); |
|
| 583 | - if (preg_match('/(\s)/', $value)) { |
|
| 584 | - return $this->encodeUtf8Words($value); |
|
| 585 | - } |
|
| 586 | - return $this->encodeUtf8Word($value); |
|
| 587 | - } |
|
| 588 | - |
|
| 589 | - /** |
|
| 590 | - * encodeUtf8Word |
|
| 591 | - * |
|
| 592 | - * @param string $value The word to encode. |
|
| 593 | - * |
|
| 594 | - * @return string |
|
| 595 | - */ |
|
| 596 | - public function encodeUtf8Word($value) |
|
| 597 | - { |
|
| 598 | - return sprintf('=?UTF-8?B?%s?=', base64_encode($value)); |
|
| 599 | - } |
|
| 600 | - |
|
| 601 | - /** |
|
| 602 | - * encodeUtf8Words |
|
| 603 | - * |
|
| 604 | - * @param string $value The words to encode. |
|
| 605 | - * |
|
| 606 | - * @return string |
|
| 607 | - */ |
|
| 608 | - public function encodeUtf8Words($value) |
|
| 609 | - { |
|
| 610 | - $words = explode(' ', $value); |
|
| 611 | - $encoded = array(); |
|
| 612 | - foreach ($words as $word) { |
|
| 613 | - $encoded[] = $this->encodeUtf8Word($word); |
|
| 614 | - } |
|
| 615 | - return join($this->encodeUtf8Word(' '), $encoded); |
|
| 616 | - } |
|
| 617 | - |
|
| 618 | - /** |
|
| 619 | - * filterEmail |
|
| 620 | - * |
|
| 621 | - * Removes any carriage return, line feed, tab, double quote, comma |
|
| 622 | - * and angle bracket characters before sanitizing the email address. |
|
| 623 | - * |
|
| 624 | - * @param string $email The email to filter. |
|
| 625 | - * |
|
| 626 | - * @return string |
|
| 627 | - */ |
|
| 628 | - public function filterEmail($email) |
|
| 629 | - { |
|
| 630 | - $rule = array( |
|
| 631 | - "\r" => '', |
|
| 632 | - "\n" => '', |
|
| 633 | - "\t" => '', |
|
| 634 | - '"' => '', |
|
| 635 | - ',' => '', |
|
| 636 | - '<' => '', |
|
| 637 | - '>' => '' |
|
| 638 | - ); |
|
| 639 | - $email = strtr($email, $rule); |
|
| 640 | - $email = filter_var($email, FILTER_SANITIZE_EMAIL); |
|
| 641 | - return $email; |
|
| 642 | - } |
|
| 643 | - |
|
| 644 | - /** |
|
| 645 | - * filterName |
|
| 646 | - * |
|
| 647 | - * Removes any carriage return, line feed or tab characters. Replaces |
|
| 648 | - * double quotes with single quotes and angle brackets with square |
|
| 649 | - * brackets, before sanitizing the string and stripping out html tags. |
|
| 650 | - * |
|
| 651 | - * @param string $name The name to filter. |
|
| 652 | - * |
|
| 653 | - * @return string |
|
| 654 | - */ |
|
| 655 | - public function filterName($name) |
|
| 656 | - { |
|
| 657 | - $rule = array( |
|
| 658 | - "\r" => '', |
|
| 659 | - "\n" => '', |
|
| 660 | - "\t" => '', |
|
| 661 | - '"' => "'", |
|
| 662 | - '<' => '[', |
|
| 663 | - '>' => ']', |
|
| 664 | - ); |
|
| 665 | - $filtered = filter_var( |
|
| 666 | - $name, |
|
| 667 | - FILTER_SANITIZE_STRING, |
|
| 668 | - FILTER_FLAG_NO_ENCODE_QUOTES |
|
| 669 | - ); |
|
| 670 | - return trim(strtr($filtered, $rule)); |
|
| 671 | - } |
|
| 672 | - |
|
| 673 | - /** |
|
| 674 | - * filterOther |
|
| 675 | - * |
|
| 676 | - * Removes ASCII control characters including any carriage return, line |
|
| 677 | - * feed or tab characters. |
|
| 678 | - * |
|
| 679 | - * @param string $data The data to filter. |
|
| 680 | - * |
|
| 681 | - * @return string |
|
| 682 | - */ |
|
| 683 | - public function filterOther($data) |
|
| 684 | - { |
|
| 685 | - return filter_var($data, FILTER_UNSAFE_RAW, FILTER_FLAG_STRIP_LOW); |
|
| 686 | - } |
|
| 687 | - |
|
| 688 | - /** |
|
| 689 | - * getHeadersForSend |
|
| 690 | - * |
|
| 691 | - * @return string |
|
| 692 | - */ |
|
| 693 | - public function getHeadersForSend() |
|
| 694 | - { |
|
| 695 | - if (empty($this->_headers)) { |
|
| 696 | - return ''; |
|
| 697 | - } |
|
| 698 | - return join(PHP_EOL, $this->_headers); |
|
| 699 | - } |
|
| 700 | - |
|
| 701 | - /** |
|
| 702 | - * getToForSend |
|
| 703 | - * |
|
| 704 | - * @return string |
|
| 705 | - */ |
|
| 706 | - public function getToForSend() |
|
| 707 | - { |
|
| 708 | - if (empty($this->_to)) { |
|
| 709 | - return ''; |
|
| 710 | - } |
|
| 711 | - return join(', ', $this->_to); |
|
| 712 | - } |
|
| 713 | - |
|
| 714 | - /** |
|
| 715 | - * getUniqueId |
|
| 716 | - * |
|
| 717 | - * @return string |
|
| 718 | - */ |
|
| 719 | - public function getUniqueId() |
|
| 720 | - { |
|
| 721 | - return md5(uniqid(time())); |
|
| 722 | - } |
|
| 723 | - |
|
| 724 | - /** |
|
| 725 | - * getWrapMessage |
|
| 726 | - * |
|
| 727 | - * @return string |
|
| 728 | - */ |
|
| 729 | - public function getWrapMessage() |
|
| 730 | - { |
|
| 731 | - return wordwrap($this->_message, $this->_wrap); |
|
| 732 | - } |
|
| 733 | - } |
|
| 136 | + /** |
|
| 137 | + * Set destination using array |
|
| 138 | + * @params array $emails the list of recipient. This is an associative array name => email |
|
| 139 | + * @example array('John Doe' => '[email protected]') |
|
| 140 | + * @return Object the current instance |
|
| 141 | + */ |
|
| 142 | + public function setTos(array $emails) |
|
| 143 | + { |
|
| 144 | + foreach ($emails as $name => $email) { |
|
| 145 | + if(is_numeric($name)){ |
|
| 146 | + $this->setTo($email); |
|
| 147 | + } |
|
| 148 | + else{ |
|
| 149 | + $this->setTo($email, $name); |
|
| 150 | + } |
|
| 151 | + } |
|
| 152 | + return $this; |
|
| 153 | + } |
|
| 154 | + |
|
| 155 | + |
|
| 156 | + /** |
|
| 157 | + * getTo |
|
| 158 | + * |
|
| 159 | + * Return an array of formatted To addresses. |
|
| 160 | + * |
|
| 161 | + * @return array |
|
| 162 | + */ |
|
| 163 | + public function getTo() |
|
| 164 | + { |
|
| 165 | + return $this->_to; |
|
| 166 | + } |
|
| 167 | + |
|
| 168 | + |
|
| 169 | + /** |
|
| 170 | + * setCc |
|
| 171 | + * |
|
| 172 | + * @param array $pairs An array of name => email pairs. |
|
| 173 | + * |
|
| 174 | + * @return self |
|
| 175 | + */ |
|
| 176 | + public function setCc(array $pairs) |
|
| 177 | + { |
|
| 178 | + return $this->addMailHeaders('Cc', $pairs); |
|
| 179 | + } |
|
| 180 | + |
|
| 181 | + /** |
|
| 182 | + * setBcc |
|
| 183 | + * |
|
| 184 | + * @param array $pairs An array of name => email pairs. |
|
| 185 | + * |
|
| 186 | + * @return self |
|
| 187 | + */ |
|
| 188 | + public function setBcc(array $pairs) |
|
| 189 | + { |
|
| 190 | + return $this->addMailHeaders('Bcc', $pairs); |
|
| 191 | + } |
|
| 192 | + |
|
| 193 | + /** |
|
| 194 | + * setReplyTo |
|
| 195 | + * |
|
| 196 | + * @param string $email |
|
| 197 | + * @param string $name |
|
| 198 | + * |
|
| 199 | + * @return self |
|
| 200 | + */ |
|
| 201 | + public function setReplyTo($email, $name = null) |
|
| 202 | + { |
|
| 203 | + return $this->addMailHeader('Reply-To', $email, $name); |
|
| 204 | + } |
|
| 205 | + |
|
| 206 | + /** |
|
| 207 | + * setHtml |
|
| 208 | + * |
|
| 209 | + * @return self |
|
| 210 | + */ |
|
| 211 | + public function setHtml() |
|
| 212 | + { |
|
| 213 | + $this->addGenericHeader( |
|
| 214 | + 'Content-Type', 'text/html; charset="utf-8"' |
|
| 215 | + ); |
|
| 216 | + return $this; |
|
| 217 | + } |
|
| 218 | + |
|
| 219 | + /** |
|
| 220 | + * setSubject |
|
| 221 | + * |
|
| 222 | + * @param string $subject The email subject |
|
| 223 | + * |
|
| 224 | + * @return self |
|
| 225 | + */ |
|
| 226 | + public function setSubject($subject) |
|
| 227 | + { |
|
| 228 | + $this->_subject = $this->encodeUtf8( |
|
| 229 | + $this->filterOther((string) $subject) |
|
| 230 | + ); |
|
| 231 | + return $this; |
|
| 232 | + } |
|
| 233 | + |
|
| 234 | + /** |
|
| 235 | + * getSubject function. |
|
| 236 | + * |
|
| 237 | + * @return string |
|
| 238 | + */ |
|
| 239 | + public function getSubject() |
|
| 240 | + { |
|
| 241 | + return $this->_subject; |
|
| 242 | + } |
|
| 243 | + |
|
| 244 | + /** |
|
| 245 | + * setMessage |
|
| 246 | + * |
|
| 247 | + * @param string $message The message to send. |
|
| 248 | + * |
|
| 249 | + * @return self |
|
| 250 | + */ |
|
| 251 | + public function setMessage($message) |
|
| 252 | + { |
|
| 253 | + $this->_message = str_replace("\n.", "\n..", (string) $message); |
|
| 254 | + return $this; |
|
| 255 | + } |
|
| 256 | + |
|
| 257 | + /** |
|
| 258 | + * getMessage |
|
| 259 | + * |
|
| 260 | + * @return string |
|
| 261 | + */ |
|
| 262 | + public function getMessage() |
|
| 263 | + { |
|
| 264 | + return $this->_message; |
|
| 265 | + } |
|
| 266 | + |
|
| 267 | + /** |
|
| 268 | + * addAttachment |
|
| 269 | + * |
|
| 270 | + * @param string $path The file path to the attachment. |
|
| 271 | + * @param string $filename The filename of the attachment when emailed. |
|
| 272 | + * @param string $data |
|
| 273 | + * |
|
| 274 | + * @return self |
|
| 275 | + */ |
|
| 276 | + public function addAttachment($path, $filename = null, $data = null) |
|
| 277 | + { |
|
| 278 | + if(! file_exists($path)){ |
|
| 279 | + show_error('The file [' .$path. '] does not exists.'); |
|
| 280 | + } |
|
| 281 | + $filename = empty($filename) ? basename($path) : $filename; |
|
| 282 | + $filename = $this->encodeUtf8($this->filterOther((string) $filename)); |
|
| 283 | + $data = empty($data) ? $this->getAttachmentData($path) : $data; |
|
| 284 | + $this->_attachments[] = array( |
|
| 285 | + 'path' => $path, |
|
| 286 | + 'file' => $filename, |
|
| 287 | + 'data' => chunk_split(base64_encode($data)) |
|
| 288 | + ); |
|
| 289 | + return $this; |
|
| 290 | + } |
|
| 291 | + |
|
| 292 | + /** |
|
| 293 | + * getAttachmentData |
|
| 294 | + * |
|
| 295 | + * @param string $path The path to the attachment file. |
|
| 296 | + * |
|
| 297 | + * @return string |
|
| 298 | + */ |
|
| 299 | + public function getAttachmentData($path) |
|
| 300 | + { |
|
| 301 | + if(! file_exists($path)){ |
|
| 302 | + show_error('The file [' .$path. '] does not exists.'); |
|
| 303 | + } |
|
| 304 | + $filesize = filesize($path); |
|
| 305 | + $handle = fopen($path, "r"); |
|
| 306 | + $attachment = null; |
|
| 307 | + if(is_resource($handle)){ |
|
| 308 | + $attachment = fread($handle, $filesize); |
|
| 309 | + fclose($handle); |
|
| 310 | + } |
|
| 311 | + return $attachment; |
|
| 312 | + } |
|
| 313 | + |
|
| 314 | + /** |
|
| 315 | + * addMailHeader |
|
| 316 | + * |
|
| 317 | + * @param string $header The header to add. |
|
| 318 | + * @param string $email The email to add. |
|
| 319 | + * @param string $name The name to add. |
|
| 320 | + * |
|
| 321 | + * @return self |
|
| 322 | + */ |
|
| 323 | + public function addMailHeader($header, $email, $name = null) |
|
| 324 | + { |
|
| 325 | + $address = $this->formatHeader((string) $email, (string) $name); |
|
| 326 | + $this->_headers[] = sprintf('%s: %s', (string) $header, $address); |
|
| 327 | + return $this; |
|
| 328 | + } |
|
| 329 | + |
|
| 330 | + /** |
|
| 331 | + * addMailHeaders |
|
| 332 | + * |
|
| 333 | + * @param string $header The header to add. |
|
| 334 | + * @param array $pairs An array of name => email pairs. |
|
| 335 | + * |
|
| 336 | + * @return self |
|
| 337 | + */ |
|
| 338 | + public function addMailHeaders($header, array $pairs) |
|
| 339 | + { |
|
| 340 | + if (count($pairs) === 0) { |
|
| 341 | + show_error('You must pass at least one name => email pair.'); |
|
| 342 | + } |
|
| 343 | + $addresses = array(); |
|
| 344 | + foreach ($pairs as $name => $email) { |
|
| 345 | + $name = is_numeric($name) ? null : $name; |
|
| 346 | + $addresses[] = $this->formatHeader($email, $name); |
|
| 347 | + } |
|
| 348 | + $this->addGenericHeader($header, implode(',', $addresses)); |
|
| 349 | + return $this; |
|
| 350 | + } |
|
| 351 | + |
|
| 352 | + /** |
|
| 353 | + * addGenericHeader |
|
| 354 | + * |
|
| 355 | + * @param string $name The generic header to add. |
|
| 356 | + * @param mixed $value The value of the header. |
|
| 357 | + * |
|
| 358 | + * @return self |
|
| 359 | + */ |
|
| 360 | + public function addGenericHeader($name, $value) |
|
| 361 | + { |
|
| 362 | + $this->_headers[] = sprintf( |
|
| 363 | + '%s: %s', |
|
| 364 | + (string) $name, |
|
| 365 | + (string) $value |
|
| 366 | + ); |
|
| 367 | + return $this; |
|
| 368 | + } |
|
| 369 | + |
|
| 370 | + /** |
|
| 371 | + * getHeaders |
|
| 372 | + * |
|
| 373 | + * Return the headers registered so far as an array. |
|
| 374 | + * |
|
| 375 | + * @return array |
|
| 376 | + */ |
|
| 377 | + public function getHeaders() |
|
| 378 | + { |
|
| 379 | + return $this->_headers; |
|
| 380 | + } |
|
| 381 | + |
|
| 382 | + /** |
|
| 383 | + * setAdditionalParameters |
|
| 384 | + * |
|
| 385 | + * Such as "[email protected] |
|
| 386 | + * |
|
| 387 | + * @param string $additionalParameters The addition mail parameter. |
|
| 388 | + * |
|
| 389 | + * @return self |
|
| 390 | + */ |
|
| 391 | + public function setParameters($additionalParameters) |
|
| 392 | + { |
|
| 393 | + $this->_params = (string) $additionalParameters; |
|
| 394 | + return $this; |
|
| 395 | + } |
|
| 396 | + |
|
| 397 | + /** |
|
| 398 | + * getAdditionalParameters |
|
| 399 | + * |
|
| 400 | + * @return string |
|
| 401 | + */ |
|
| 402 | + public function getParameters() |
|
| 403 | + { |
|
| 404 | + return $this->_params; |
|
| 405 | + } |
|
| 406 | + |
|
| 407 | + /** |
|
| 408 | + * setWrap |
|
| 409 | + * |
|
| 410 | + * @param int $wrap The number of characters at which the message will wrap. |
|
| 411 | + * |
|
| 412 | + * @return self |
|
| 413 | + */ |
|
| 414 | + public function setWrap($wrap = 78) |
|
| 415 | + { |
|
| 416 | + $wrap = (int) $wrap; |
|
| 417 | + if ($wrap < 1) { |
|
| 418 | + $wrap = 78; |
|
| 419 | + } |
|
| 420 | + $this->_wrap = $wrap; |
|
| 421 | + return $this; |
|
| 422 | + } |
|
| 423 | + |
|
| 424 | + /** |
|
| 425 | + * getWrap |
|
| 426 | + * |
|
| 427 | + * @return int |
|
| 428 | + */ |
|
| 429 | + public function getWrap() |
|
| 430 | + { |
|
| 431 | + return $this->_wrap; |
|
| 432 | + } |
|
| 433 | + |
|
| 434 | + /** |
|
| 435 | + * hasAttachments |
|
| 436 | + * |
|
| 437 | + * Checks if the email has any registered attachments. |
|
| 438 | + * |
|
| 439 | + * @return bool |
|
| 440 | + */ |
|
| 441 | + public function hasAttachments() |
|
| 442 | + { |
|
| 443 | + return !empty($this->_attachments); |
|
| 444 | + } |
|
| 445 | + |
|
| 446 | + /** |
|
| 447 | + * assembleAttachment |
|
| 448 | + * |
|
| 449 | + * @return string |
|
| 450 | + */ |
|
| 451 | + public function assembleAttachmentHeaders() |
|
| 452 | + { |
|
| 453 | + $head = array(); |
|
| 454 | + $head[] = "MIME-Version: 1.0"; |
|
| 455 | + $head[] = "Content-Type: multipart/mixed; boundary=\"{$this->_uid}\""; |
|
| 456 | + |
|
| 457 | + return join(PHP_EOL, $head); |
|
| 458 | + } |
|
| 459 | + |
|
| 460 | + /** |
|
| 461 | + * assembleAttachmentBody |
|
| 462 | + * |
|
| 463 | + * @return string |
|
| 464 | + */ |
|
| 465 | + public function assembleAttachmentBody() |
|
| 466 | + { |
|
| 467 | + $body = array(); |
|
| 468 | + $body[] = "This is a multi-part message in MIME format."; |
|
| 469 | + $body[] = "--{$this->_uid}"; |
|
| 470 | + $body[] = "Content-Type: text/html; charset=\"utf-8\""; |
|
| 471 | + $body[] = "Content-Transfer-Encoding: quoted-printable"; |
|
| 472 | + $body[] = ""; |
|
| 473 | + $body[] = quoted_printable_encode($this->_message); |
|
| 474 | + $body[] = ""; |
|
| 475 | + $body[] = "--{$this->_uid}"; |
|
| 476 | + |
|
| 477 | + foreach ($this->_attachments as $attachment) { |
|
| 478 | + $body[] = $this->getAttachmentMimeTemplate($attachment); |
|
| 479 | + } |
|
| 480 | + |
|
| 481 | + return implode(PHP_EOL, $body) . '--'; |
|
| 482 | + } |
|
| 483 | + |
|
| 484 | + /** |
|
| 485 | + * getAttachmentMimeTemplate |
|
| 486 | + * |
|
| 487 | + * @param array $attachment An array containing 'file' and 'data' keys. |
|
| 488 | + * |
|
| 489 | + * @return string |
|
| 490 | + */ |
|
| 491 | + public function getAttachmentMimeTemplate($attachment) |
|
| 492 | + { |
|
| 493 | + $file = $attachment['file']; |
|
| 494 | + $data = $attachment['data']; |
|
| 495 | + |
|
| 496 | + $head = array(); |
|
| 497 | + $head[] = "Content-Type: application/octet-stream; name=\"{$file}\""; |
|
| 498 | + $head[] = "Content-Transfer-Encoding: base64"; |
|
| 499 | + $head[] = "Content-Disposition: attachment; filename=\"{$file}\""; |
|
| 500 | + $head[] = ""; |
|
| 501 | + $head[] = $data; |
|
| 502 | + $head[] = ""; |
|
| 503 | + $head[] = "--{$this->_uid}"; |
|
| 504 | + |
|
| 505 | + return implode(PHP_EOL, $head); |
|
| 506 | + } |
|
| 507 | + |
|
| 508 | + /** |
|
| 509 | + * send the email |
|
| 510 | + * |
|
| 511 | + * @return boolean |
|
| 512 | + */ |
|
| 513 | + public function send() |
|
| 514 | + { |
|
| 515 | + $to = $this->getToForSend(); |
|
| 516 | + $headers = $this->getHeadersForSend(); |
|
| 517 | + |
|
| 518 | + if (empty($to)) { |
|
| 519 | + show_error('Unable to send, no To address has been set.'); |
|
| 520 | + } |
|
| 521 | + |
|
| 522 | + if ($this->hasAttachments()) { |
|
| 523 | + $message = $this->assembleAttachmentBody(); |
|
| 524 | + $headers .= PHP_EOL . $this->assembleAttachmentHeaders(); |
|
| 525 | + } else { |
|
| 526 | + $message = $this->getWrapMessage(); |
|
| 527 | + } |
|
| 528 | + $this->logger->info('Sending new mail, the information are listed below: destination: ' . $to . ', headers: ' . $headers . ', message: ' . $message); |
|
| 529 | + return mail($to, $this->_subject, $message, $headers, $this->_params); |
|
| 530 | + } |
|
| 531 | + |
|
| 532 | + /** |
|
| 533 | + * debug |
|
| 534 | + * |
|
| 535 | + * @return string |
|
| 536 | + */ |
|
| 537 | + public function debug() |
|
| 538 | + { |
|
| 539 | + return '<pre>' . print_r($this, true) . '</pre>'; |
|
| 540 | + } |
|
| 541 | + |
|
| 542 | + /** |
|
| 543 | + * magic __toString function |
|
| 544 | + * |
|
| 545 | + * @return string |
|
| 546 | + */ |
|
| 547 | + public function __toString() |
|
| 548 | + { |
|
| 549 | + return print_r($this, true); |
|
| 550 | + } |
|
| 551 | + |
|
| 552 | + /** |
|
| 553 | + * formatHeader |
|
| 554 | + * |
|
| 555 | + * Formats a display address for emails according to RFC2822 e.g. |
|
| 556 | + * Name <[email protected]> |
|
| 557 | + * |
|
| 558 | + * @param string $email The email address. |
|
| 559 | + * @param string $name The display name. |
|
| 560 | + * |
|
| 561 | + * @return string |
|
| 562 | + */ |
|
| 563 | + public function formatHeader($email, $name = null) |
|
| 564 | + { |
|
| 565 | + $email = $this->filterEmail((string) $email); |
|
| 566 | + if (empty($name)) { |
|
| 567 | + return $email; |
|
| 568 | + } |
|
| 569 | + $name = $this->encodeUtf8($this->filterName((string) $name)); |
|
| 570 | + return sprintf('"%s" <%s>', $name, $email); |
|
| 571 | + } |
|
| 572 | + |
|
| 573 | + /** |
|
| 574 | + * encodeUtf8 |
|
| 575 | + * |
|
| 576 | + * @param string $value The value to encode. |
|
| 577 | + * |
|
| 578 | + * @return string |
|
| 579 | + */ |
|
| 580 | + public function encodeUtf8($value) |
|
| 581 | + { |
|
| 582 | + $value = trim($value); |
|
| 583 | + if (preg_match('/(\s)/', $value)) { |
|
| 584 | + return $this->encodeUtf8Words($value); |
|
| 585 | + } |
|
| 586 | + return $this->encodeUtf8Word($value); |
|
| 587 | + } |
|
| 588 | + |
|
| 589 | + /** |
|
| 590 | + * encodeUtf8Word |
|
| 591 | + * |
|
| 592 | + * @param string $value The word to encode. |
|
| 593 | + * |
|
| 594 | + * @return string |
|
| 595 | + */ |
|
| 596 | + public function encodeUtf8Word($value) |
|
| 597 | + { |
|
| 598 | + return sprintf('=?UTF-8?B?%s?=', base64_encode($value)); |
|
| 599 | + } |
|
| 600 | + |
|
| 601 | + /** |
|
| 602 | + * encodeUtf8Words |
|
| 603 | + * |
|
| 604 | + * @param string $value The words to encode. |
|
| 605 | + * |
|
| 606 | + * @return string |
|
| 607 | + */ |
|
| 608 | + public function encodeUtf8Words($value) |
|
| 609 | + { |
|
| 610 | + $words = explode(' ', $value); |
|
| 611 | + $encoded = array(); |
|
| 612 | + foreach ($words as $word) { |
|
| 613 | + $encoded[] = $this->encodeUtf8Word($word); |
|
| 614 | + } |
|
| 615 | + return join($this->encodeUtf8Word(' '), $encoded); |
|
| 616 | + } |
|
| 617 | + |
|
| 618 | + /** |
|
| 619 | + * filterEmail |
|
| 620 | + * |
|
| 621 | + * Removes any carriage return, line feed, tab, double quote, comma |
|
| 622 | + * and angle bracket characters before sanitizing the email address. |
|
| 623 | + * |
|
| 624 | + * @param string $email The email to filter. |
|
| 625 | + * |
|
| 626 | + * @return string |
|
| 627 | + */ |
|
| 628 | + public function filterEmail($email) |
|
| 629 | + { |
|
| 630 | + $rule = array( |
|
| 631 | + "\r" => '', |
|
| 632 | + "\n" => '', |
|
| 633 | + "\t" => '', |
|
| 634 | + '"' => '', |
|
| 635 | + ',' => '', |
|
| 636 | + '<' => '', |
|
| 637 | + '>' => '' |
|
| 638 | + ); |
|
| 639 | + $email = strtr($email, $rule); |
|
| 640 | + $email = filter_var($email, FILTER_SANITIZE_EMAIL); |
|
| 641 | + return $email; |
|
| 642 | + } |
|
| 643 | + |
|
| 644 | + /** |
|
| 645 | + * filterName |
|
| 646 | + * |
|
| 647 | + * Removes any carriage return, line feed or tab characters. Replaces |
|
| 648 | + * double quotes with single quotes and angle brackets with square |
|
| 649 | + * brackets, before sanitizing the string and stripping out html tags. |
|
| 650 | + * |
|
| 651 | + * @param string $name The name to filter. |
|
| 652 | + * |
|
| 653 | + * @return string |
|
| 654 | + */ |
|
| 655 | + public function filterName($name) |
|
| 656 | + { |
|
| 657 | + $rule = array( |
|
| 658 | + "\r" => '', |
|
| 659 | + "\n" => '', |
|
| 660 | + "\t" => '', |
|
| 661 | + '"' => "'", |
|
| 662 | + '<' => '[', |
|
| 663 | + '>' => ']', |
|
| 664 | + ); |
|
| 665 | + $filtered = filter_var( |
|
| 666 | + $name, |
|
| 667 | + FILTER_SANITIZE_STRING, |
|
| 668 | + FILTER_FLAG_NO_ENCODE_QUOTES |
|
| 669 | + ); |
|
| 670 | + return trim(strtr($filtered, $rule)); |
|
| 671 | + } |
|
| 672 | + |
|
| 673 | + /** |
|
| 674 | + * filterOther |
|
| 675 | + * |
|
| 676 | + * Removes ASCII control characters including any carriage return, line |
|
| 677 | + * feed or tab characters. |
|
| 678 | + * |
|
| 679 | + * @param string $data The data to filter. |
|
| 680 | + * |
|
| 681 | + * @return string |
|
| 682 | + */ |
|
| 683 | + public function filterOther($data) |
|
| 684 | + { |
|
| 685 | + return filter_var($data, FILTER_UNSAFE_RAW, FILTER_FLAG_STRIP_LOW); |
|
| 686 | + } |
|
| 687 | + |
|
| 688 | + /** |
|
| 689 | + * getHeadersForSend |
|
| 690 | + * |
|
| 691 | + * @return string |
|
| 692 | + */ |
|
| 693 | + public function getHeadersForSend() |
|
| 694 | + { |
|
| 695 | + if (empty($this->_headers)) { |
|
| 696 | + return ''; |
|
| 697 | + } |
|
| 698 | + return join(PHP_EOL, $this->_headers); |
|
| 699 | + } |
|
| 700 | + |
|
| 701 | + /** |
|
| 702 | + * getToForSend |
|
| 703 | + * |
|
| 704 | + * @return string |
|
| 705 | + */ |
|
| 706 | + public function getToForSend() |
|
| 707 | + { |
|
| 708 | + if (empty($this->_to)) { |
|
| 709 | + return ''; |
|
| 710 | + } |
|
| 711 | + return join(', ', $this->_to); |
|
| 712 | + } |
|
| 713 | + |
|
| 714 | + /** |
|
| 715 | + * getUniqueId |
|
| 716 | + * |
|
| 717 | + * @return string |
|
| 718 | + */ |
|
| 719 | + public function getUniqueId() |
|
| 720 | + { |
|
| 721 | + return md5(uniqid(time())); |
|
| 722 | + } |
|
| 723 | + |
|
| 724 | + /** |
|
| 725 | + * getWrapMessage |
|
| 726 | + * |
|
| 727 | + * @return string |
|
| 728 | + */ |
|
| 729 | + public function getWrapMessage() |
|
| 730 | + { |
|
| 731 | + return wordwrap($this->_message, $this->_wrap); |
|
| 732 | + } |
|
| 733 | + } |
|
@@ -142,10 +142,10 @@ discard block |
||
| 142 | 142 | public function setTos(array $emails) |
| 143 | 143 | { |
| 144 | 144 | foreach ($emails as $name => $email) { |
| 145 | - if(is_numeric($name)){ |
|
| 145 | + if (is_numeric($name)) { |
|
| 146 | 146 | $this->setTo($email); |
| 147 | 147 | } |
| 148 | - else{ |
|
| 148 | + else { |
|
| 149 | 149 | $this->setTo($email, $name); |
| 150 | 150 | } |
| 151 | 151 | } |
@@ -275,8 +275,8 @@ discard block |
||
| 275 | 275 | */ |
| 276 | 276 | public function addAttachment($path, $filename = null, $data = null) |
| 277 | 277 | { |
| 278 | - if(! file_exists($path)){ |
|
| 279 | - show_error('The file [' .$path. '] does not exists.'); |
|
| 278 | + if (!file_exists($path)) { |
|
| 279 | + show_error('The file [' . $path . '] does not exists.'); |
|
| 280 | 280 | } |
| 281 | 281 | $filename = empty($filename) ? basename($path) : $filename; |
| 282 | 282 | $filename = $this->encodeUtf8($this->filterOther((string) $filename)); |
@@ -298,13 +298,13 @@ discard block |
||
| 298 | 298 | */ |
| 299 | 299 | public function getAttachmentData($path) |
| 300 | 300 | { |
| 301 | - if(! file_exists($path)){ |
|
| 302 | - show_error('The file [' .$path. '] does not exists.'); |
|
| 301 | + if (!file_exists($path)) { |
|
| 302 | + show_error('The file [' . $path . '] does not exists.'); |
|
| 303 | 303 | } |
| 304 | 304 | $filesize = filesize($path); |
| 305 | 305 | $handle = fopen($path, "r"); |
| 306 | 306 | $attachment = null; |
| 307 | - if(is_resource($handle)){ |
|
| 307 | + if (is_resource($handle)) { |
|
| 308 | 308 | $attachment = fread($handle, $filesize); |
| 309 | 309 | fclose($handle); |
| 310 | 310 | } |