@@ -1,178 +1,178 @@ |
||
| 1 | 1 | <?php |
| 2 | - defined('ROOT_PATH') || exit('Access denied'); |
|
| 3 | - /** |
|
| 4 | - * TNH Framework |
|
| 5 | - * |
|
| 6 | - * A simple PHP framework using HMVC architecture |
|
| 7 | - * |
|
| 8 | - * This content is released under the GNU GPL License (GPL) |
|
| 9 | - * |
|
| 10 | - * Copyright (C) 2017 Tony NGUEREZA |
|
| 11 | - * |
|
| 12 | - * This program is free software; you can redistribute it and/or |
|
| 13 | - * modify it under the terms of the GNU General Public License |
|
| 14 | - * as published by the Free Software Foundation; either version 3 |
|
| 15 | - * of the License, or (at your option) any later version. |
|
| 16 | - * |
|
| 17 | - * This program is distributed in the hope that it will be useful, |
|
| 18 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 19 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 20 | - * GNU General Public License for more details. |
|
| 21 | - * |
|
| 22 | - * You should have received a copy of the GNU General Public License |
|
| 23 | - * along with this program; if not, write to the Free Software |
|
| 24 | - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
| 25 | - */ |
|
| 2 | + defined('ROOT_PATH') || exit('Access denied'); |
|
| 3 | + /** |
|
| 4 | + * TNH Framework |
|
| 5 | + * |
|
| 6 | + * A simple PHP framework using HMVC architecture |
|
| 7 | + * |
|
| 8 | + * This content is released under the GNU GPL License (GPL) |
|
| 9 | + * |
|
| 10 | + * Copyright (C) 2017 Tony NGUEREZA |
|
| 11 | + * |
|
| 12 | + * This program is free software; you can redistribute it and/or |
|
| 13 | + * modify it under the terms of the GNU General Public License |
|
| 14 | + * as published by the Free Software Foundation; either version 3 |
|
| 15 | + * of the License, or (at your option) any later version. |
|
| 16 | + * |
|
| 17 | + * This program is distributed in the hope that it will be useful, |
|
| 18 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 19 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 20 | + * GNU General Public License for more details. |
|
| 21 | + * |
|
| 22 | + * You should have received a copy of the GNU General Public License |
|
| 23 | + * along with this program; if not, write to the Free Software |
|
| 24 | + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
| 25 | + */ |
|
| 26 | 26 | |
| 27 | - class Config{ |
|
| 27 | + class Config{ |
|
| 28 | 28 | |
| 29 | - /** |
|
| 30 | - * The list of loaded configuration |
|
| 31 | - * @var array |
|
| 32 | - */ |
|
| 33 | - private static $config = array(); |
|
| 29 | + /** |
|
| 30 | + * The list of loaded configuration |
|
| 31 | + * @var array |
|
| 32 | + */ |
|
| 33 | + private static $config = array(); |
|
| 34 | 34 | |
| 35 | - /** |
|
| 36 | - * The logger instance |
|
| 37 | - * @var Log |
|
| 38 | - */ |
|
| 39 | - private static $logger; |
|
| 35 | + /** |
|
| 36 | + * The logger instance |
|
| 37 | + * @var Log |
|
| 38 | + */ |
|
| 39 | + private static $logger; |
|
| 40 | 40 | |
| 41 | - /** |
|
| 42 | - * The signleton of the logger |
|
| 43 | - * @return Object the Log instance |
|
| 44 | - */ |
|
| 45 | - private static function getLogger(){ |
|
| 46 | - if(self::$logger == null){ |
|
| 47 | - $logger = array(); |
|
| 48 | - $logger[0] =& class_loader('Log', 'classes'); |
|
| 49 | - $logger[0]->setLogger('Library::Config'); |
|
| 50 | - self::$logger = $logger[0]; |
|
| 51 | - } |
|
| 52 | - return self::$logger; |
|
| 53 | - } |
|
| 41 | + /** |
|
| 42 | + * The signleton of the logger |
|
| 43 | + * @return Object the Log instance |
|
| 44 | + */ |
|
| 45 | + private static function getLogger(){ |
|
| 46 | + if(self::$logger == null){ |
|
| 47 | + $logger = array(); |
|
| 48 | + $logger[0] =& class_loader('Log', 'classes'); |
|
| 49 | + $logger[0]->setLogger('Library::Config'); |
|
| 50 | + self::$logger = $logger[0]; |
|
| 51 | + } |
|
| 52 | + return self::$logger; |
|
| 53 | + } |
|
| 54 | 54 | |
| 55 | - /** |
|
| 56 | - * Set the log instance for future use |
|
| 57 | - * @param Log $logger the log object |
|
| 58 | - * @return Log the log instance |
|
| 59 | - */ |
|
| 60 | - public static function setLogger($logger){ |
|
| 61 | - self::$logger = $logger; |
|
| 62 | - return self::$logger; |
|
| 63 | - } |
|
| 55 | + /** |
|
| 56 | + * Set the log instance for future use |
|
| 57 | + * @param Log $logger the log object |
|
| 58 | + * @return Log the log instance |
|
| 59 | + */ |
|
| 60 | + public static function setLogger($logger){ |
|
| 61 | + self::$logger = $logger; |
|
| 62 | + return self::$logger; |
|
| 63 | + } |
|
| 64 | 64 | |
| 65 | - /** |
|
| 66 | - * Initialize the configuration by loading all the configuration from config file |
|
| 67 | - */ |
|
| 68 | - public static function init(){ |
|
| 69 | - $logger = static::getLogger(); |
|
| 70 | - $logger->debug('Initialization of the configuration'); |
|
| 71 | - self::$config = & load_configurations(); |
|
| 72 | - self::setBaseUrlUsingServerVar(); |
|
| 73 | - if(ENVIRONMENT == 'production' && in_array(strtolower(self::$config['log_level']), array('debug', 'info','all'))){ |
|
| 74 | - $logger->warning('You are in production environment, please set log level to WARNING, ERROR, FATAL to increase the application performance'); |
|
| 75 | - } |
|
| 76 | - $logger->info('Configuration initialized successfully'); |
|
| 77 | - $logger->info('The application configuration are listed below: ' . stringfy_vars(self::$config)); |
|
| 78 | - } |
|
| 65 | + /** |
|
| 66 | + * Initialize the configuration by loading all the configuration from config file |
|
| 67 | + */ |
|
| 68 | + public static function init(){ |
|
| 69 | + $logger = static::getLogger(); |
|
| 70 | + $logger->debug('Initialization of the configuration'); |
|
| 71 | + self::$config = & load_configurations(); |
|
| 72 | + self::setBaseUrlUsingServerVar(); |
|
| 73 | + if(ENVIRONMENT == 'production' && in_array(strtolower(self::$config['log_level']), array('debug', 'info','all'))){ |
|
| 74 | + $logger->warning('You are in production environment, please set log level to WARNING, ERROR, FATAL to increase the application performance'); |
|
| 75 | + } |
|
| 76 | + $logger->info('Configuration initialized successfully'); |
|
| 77 | + $logger->info('The application configuration are listed below: ' . stringfy_vars(self::$config)); |
|
| 78 | + } |
|
| 79 | 79 | |
| 80 | - /** |
|
| 81 | - * Get the configuration item value |
|
| 82 | - * @param string $item the configuration item name to get |
|
| 83 | - * @param mixed $default the default value to use if can not find the config item in the list |
|
| 84 | - * @return mixed the config value if exist or the default value |
|
| 85 | - */ |
|
| 86 | - public static function get($item, $default = null){ |
|
| 87 | - $logger = static::getLogger(); |
|
| 88 | - if(array_key_exists($item, self::$config)){ |
|
| 89 | - return self::$config[$item]; |
|
| 90 | - } |
|
| 91 | - $logger->warning('Cannot find config item ['.$item.'] using the default value ['.$default.']'); |
|
| 92 | - return $default; |
|
| 93 | - } |
|
| 80 | + /** |
|
| 81 | + * Get the configuration item value |
|
| 82 | + * @param string $item the configuration item name to get |
|
| 83 | + * @param mixed $default the default value to use if can not find the config item in the list |
|
| 84 | + * @return mixed the config value if exist or the default value |
|
| 85 | + */ |
|
| 86 | + public static function get($item, $default = null){ |
|
| 87 | + $logger = static::getLogger(); |
|
| 88 | + if(array_key_exists($item, self::$config)){ |
|
| 89 | + return self::$config[$item]; |
|
| 90 | + } |
|
| 91 | + $logger->warning('Cannot find config item ['.$item.'] using the default value ['.$default.']'); |
|
| 92 | + return $default; |
|
| 93 | + } |
|
| 94 | 94 | |
| 95 | - /** |
|
| 96 | - * Set the configuration item value |
|
| 97 | - * @param string $item the config item name to set |
|
| 98 | - * @param mixed $value the config item value |
|
| 99 | - */ |
|
| 100 | - public static function set($item, $value){ |
|
| 101 | - self::$config[$item] = $value; |
|
| 102 | - } |
|
| 95 | + /** |
|
| 96 | + * Set the configuration item value |
|
| 97 | + * @param string $item the config item name to set |
|
| 98 | + * @param mixed $value the config item value |
|
| 99 | + */ |
|
| 100 | + public static function set($item, $value){ |
|
| 101 | + self::$config[$item] = $value; |
|
| 102 | + } |
|
| 103 | 103 | |
| 104 | - /** |
|
| 105 | - * Get all the configuration values |
|
| 106 | - * @return array the config values |
|
| 107 | - */ |
|
| 108 | - public static function getAll(){ |
|
| 109 | - return self::$config; |
|
| 110 | - } |
|
| 104 | + /** |
|
| 105 | + * Get all the configuration values |
|
| 106 | + * @return array the config values |
|
| 107 | + */ |
|
| 108 | + public static function getAll(){ |
|
| 109 | + return self::$config; |
|
| 110 | + } |
|
| 111 | 111 | |
| 112 | - /** |
|
| 113 | - * Set the configuration values bu merged with the existing configuration |
|
| 114 | - * @param array $config the config values to add in the configuration list |
|
| 115 | - */ |
|
| 116 | - public static function setAll(array $config = array()){ |
|
| 117 | - self::$config = array_merge(self::$config, $config); |
|
| 118 | - } |
|
| 112 | + /** |
|
| 113 | + * Set the configuration values bu merged with the existing configuration |
|
| 114 | + * @param array $config the config values to add in the configuration list |
|
| 115 | + */ |
|
| 116 | + public static function setAll(array $config = array()){ |
|
| 117 | + self::$config = array_merge(self::$config, $config); |
|
| 118 | + } |
|
| 119 | 119 | |
| 120 | - /** |
|
| 121 | - * Delete the configuration item in the list |
|
| 122 | - * @param string $item the config item name to be deleted |
|
| 123 | - * @return boolean true if the item exists and is deleted successfully otherwise will return false. |
|
| 124 | - */ |
|
| 125 | - public static function delete($item){ |
|
| 126 | - $logger = static::getLogger(); |
|
| 127 | - if(array_key_exists($item, self::$config)){ |
|
| 128 | - $logger->info('Delete config item ['.$item.']'); |
|
| 129 | - unset(self::$config[$item]); |
|
| 130 | - return true; |
|
| 131 | - } |
|
| 132 | - else{ |
|
| 133 | - $logger->warning('Config item ['.$item.'] to be deleted does not exists'); |
|
| 134 | - return false; |
|
| 135 | - } |
|
| 136 | - } |
|
| 120 | + /** |
|
| 121 | + * Delete the configuration item in the list |
|
| 122 | + * @param string $item the config item name to be deleted |
|
| 123 | + * @return boolean true if the item exists and is deleted successfully otherwise will return false. |
|
| 124 | + */ |
|
| 125 | + public static function delete($item){ |
|
| 126 | + $logger = static::getLogger(); |
|
| 127 | + if(array_key_exists($item, self::$config)){ |
|
| 128 | + $logger->info('Delete config item ['.$item.']'); |
|
| 129 | + unset(self::$config[$item]); |
|
| 130 | + return true; |
|
| 131 | + } |
|
| 132 | + else{ |
|
| 133 | + $logger->warning('Config item ['.$item.'] to be deleted does not exists'); |
|
| 134 | + return false; |
|
| 135 | + } |
|
| 136 | + } |
|
| 137 | 137 | |
| 138 | - /** |
|
| 139 | - * Load the configuration file. This an alias to Loader::config() |
|
| 140 | - * @param string $config the config name to be loaded |
|
| 141 | - */ |
|
| 142 | - public static function load($config){ |
|
| 143 | - Loader::config($config); |
|
| 144 | - } |
|
| 138 | + /** |
|
| 139 | + * Load the configuration file. This an alias to Loader::config() |
|
| 140 | + * @param string $config the config name to be loaded |
|
| 141 | + */ |
|
| 142 | + public static function load($config){ |
|
| 143 | + Loader::config($config); |
|
| 144 | + } |
|
| 145 | 145 | |
| 146 | - /** |
|
| 147 | - * Set the configuration for "base_url" if is not set in the configuration |
|
| 148 | - */ |
|
| 149 | - private static function setBaseUrlUsingServerVar(){ |
|
| 150 | - $logger = static::getLogger(); |
|
| 151 | - if (! isset(self::$config['base_url']) || ! is_url(self::$config['base_url'])){ |
|
| 152 | - if(ENVIRONMENT == 'production'){ |
|
| 153 | - $logger->warning('Application base URL is not set or invalid, please set application base URL to increase the application loading time'); |
|
| 154 | - } |
|
| 155 | - $baseUrl = null; |
|
| 156 | - if (isset($_SERVER['SERVER_ADDR'])){ |
|
| 157 | - $baseUrl = $_SERVER['SERVER_ADDR']; |
|
| 158 | - //check if the server is running under IPv6 |
|
| 159 | - if (strpos($_SERVER['SERVER_ADDR'], ':') !== FALSE){ |
|
| 160 | - $baseUrl = '['.$_SERVER['SERVER_ADDR'].']'; |
|
| 161 | - } |
|
| 162 | - $serverPort = 80; |
|
| 163 | - if (isset($_SERVER['SERVER_PORT'])) { |
|
| 164 | - $serverPort = $_SERVER['SERVER_PORT']; |
|
| 165 | - } |
|
| 166 | - $port = ((($serverPort != '80' && ! is_https()) || ($serverPort != '443' && is_https())) ? ':' . $serverPort : ''); |
|
| 167 | - $baseUrl = (is_https() ? 'https' : 'http').'://' . $baseUrl . $port |
|
| 168 | - . substr($_SERVER['SCRIPT_NAME'], 0, strpos($_SERVER['SCRIPT_NAME'], basename($_SERVER['SCRIPT_FILENAME']))); |
|
| 169 | - } |
|
| 170 | - else{ |
|
| 171 | - $logger->warning('Can not determine the application base URL automatically, use http://localhost as default'); |
|
| 172 | - $baseUrl = 'http://localhost/'; |
|
| 173 | - } |
|
| 174 | - self::set('base_url', $baseUrl); |
|
| 175 | - } |
|
| 176 | - self::$config['base_url'] = rtrim(self::$config['base_url'], '/') .'/'; |
|
| 177 | - } |
|
| 178 | - } |
|
| 146 | + /** |
|
| 147 | + * Set the configuration for "base_url" if is not set in the configuration |
|
| 148 | + */ |
|
| 149 | + private static function setBaseUrlUsingServerVar(){ |
|
| 150 | + $logger = static::getLogger(); |
|
| 151 | + if (! isset(self::$config['base_url']) || ! is_url(self::$config['base_url'])){ |
|
| 152 | + if(ENVIRONMENT == 'production'){ |
|
| 153 | + $logger->warning('Application base URL is not set or invalid, please set application base URL to increase the application loading time'); |
|
| 154 | + } |
|
| 155 | + $baseUrl = null; |
|
| 156 | + if (isset($_SERVER['SERVER_ADDR'])){ |
|
| 157 | + $baseUrl = $_SERVER['SERVER_ADDR']; |
|
| 158 | + //check if the server is running under IPv6 |
|
| 159 | + if (strpos($_SERVER['SERVER_ADDR'], ':') !== FALSE){ |
|
| 160 | + $baseUrl = '['.$_SERVER['SERVER_ADDR'].']'; |
|
| 161 | + } |
|
| 162 | + $serverPort = 80; |
|
| 163 | + if (isset($_SERVER['SERVER_PORT'])) { |
|
| 164 | + $serverPort = $_SERVER['SERVER_PORT']; |
|
| 165 | + } |
|
| 166 | + $port = ((($serverPort != '80' && ! is_https()) || ($serverPort != '443' && is_https())) ? ':' . $serverPort : ''); |
|
| 167 | + $baseUrl = (is_https() ? 'https' : 'http').'://' . $baseUrl . $port |
|
| 168 | + . substr($_SERVER['SCRIPT_NAME'], 0, strpos($_SERVER['SCRIPT_NAME'], basename($_SERVER['SCRIPT_FILENAME']))); |
|
| 169 | + } |
|
| 170 | + else{ |
|
| 171 | + $logger->warning('Can not determine the application base URL automatically, use http://localhost as default'); |
|
| 172 | + $baseUrl = 'http://localhost/'; |
|
| 173 | + } |
|
| 174 | + self::set('base_url', $baseUrl); |
|
| 175 | + } |
|
| 176 | + self::$config['base_url'] = rtrim(self::$config['base_url'], '/') .'/'; |
|
| 177 | + } |
|
| 178 | + } |
|
@@ -1,75 +1,75 @@ |
||
| 1 | 1 | <?php |
| 2 | - defined('ROOT_PATH') || exit('Access denied'); |
|
| 3 | - /** |
|
| 4 | - * TNH Framework |
|
| 5 | - * |
|
| 6 | - * A simple PHP framework using HMVC architecture |
|
| 7 | - * |
|
| 8 | - * This content is released under the GNU GPL License (GPL) |
|
| 9 | - * |
|
| 10 | - * Copyright (C) 2017 Tony NGUEREZA |
|
| 11 | - * |
|
| 12 | - * This program is free software; you can redistribute it and/or |
|
| 13 | - * modify it under the terms of the GNU General Public License |
|
| 14 | - * as published by the Free Software Foundation; either version 3 |
|
| 15 | - * of the License, or (at your option) any later version. |
|
| 16 | - * |
|
| 17 | - * This program is distributed in the hope that it will be useful, |
|
| 18 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 19 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 20 | - * GNU General Public License for more details. |
|
| 21 | - * |
|
| 22 | - * You should have received a copy of the GNU General Public License |
|
| 23 | - * along with this program; if not, write to the Free Software |
|
| 24 | - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
| 25 | - */ |
|
| 2 | + defined('ROOT_PATH') || exit('Access denied'); |
|
| 3 | + /** |
|
| 4 | + * TNH Framework |
|
| 5 | + * |
|
| 6 | + * A simple PHP framework using HMVC architecture |
|
| 7 | + * |
|
| 8 | + * This content is released under the GNU GPL License (GPL) |
|
| 9 | + * |
|
| 10 | + * Copyright (C) 2017 Tony NGUEREZA |
|
| 11 | + * |
|
| 12 | + * This program is free software; you can redistribute it and/or |
|
| 13 | + * modify it under the terms of the GNU General Public License |
|
| 14 | + * as published by the Free Software Foundation; either version 3 |
|
| 15 | + * of the License, or (at your option) any later version. |
|
| 16 | + * |
|
| 17 | + * This program is distributed in the hope that it will be useful, |
|
| 18 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 19 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 20 | + * GNU General Public License for more details. |
|
| 21 | + * |
|
| 22 | + * You should have received a copy of the GNU General Public License |
|
| 23 | + * along with this program; if not, write to the Free Software |
|
| 24 | + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
| 25 | + */ |
|
| 26 | 26 | |
| 27 | 27 | |
| 28 | - /** |
|
| 29 | - * @file function_user_agent.php |
|
| 30 | - * |
|
| 31 | - * Contains most of the utility functions for agent, platform, mobile, browser, and other management. |
|
| 32 | - * |
|
| 33 | - * @package core |
|
| 34 | - * @author Tony NGUEREZA |
|
| 35 | - * @copyright Copyright (c) 2017 |
|
| 36 | - * @license https://opensource.org/licenses/gpl-3.0.html GNU GPL License (GPL) |
|
| 37 | - * @link http://www.iacademy.cf |
|
| 38 | - * @version 1.0.0 |
|
| 39 | - * @since 1.0.0 |
|
| 40 | - * @filesource |
|
| 41 | - */ |
|
| 28 | + /** |
|
| 29 | + * @file function_user_agent.php |
|
| 30 | + * |
|
| 31 | + * Contains most of the utility functions for agent, platform, mobile, browser, and other management. |
|
| 32 | + * |
|
| 33 | + * @package core |
|
| 34 | + * @author Tony NGUEREZA |
|
| 35 | + * @copyright Copyright (c) 2017 |
|
| 36 | + * @license https://opensource.org/licenses/gpl-3.0.html GNU GPL License (GPL) |
|
| 37 | + * @link http://www.iacademy.cf |
|
| 38 | + * @version 1.0.0 |
|
| 39 | + * @since 1.0.0 |
|
| 40 | + * @filesource |
|
| 41 | + */ |
|
| 42 | 42 | |
| 43 | 43 | |
| 44 | - if(! function_exists('get_ip')){ |
|
| 45 | - /** |
|
| 46 | - * Retrieves the user's IP address |
|
| 47 | - * |
|
| 48 | - * This function allows to retrieve the IP address of the client |
|
| 49 | - * even if it uses a proxy, the actual IP address is retrieved. |
|
| 50 | - * |
|
| 51 | - * @return string the IP address. |
|
| 52 | - */ |
|
| 53 | - function get_ip(){ |
|
| 54 | - $ip = '127.0.0.1'; |
|
| 55 | - $ipServerVars = array( |
|
| 56 | - 'REMOTE_ADDR', |
|
| 57 | - 'HTTP_CLIENT_IP', |
|
| 58 | - 'HTTP_X_FORWARDED_FOR', |
|
| 59 | - 'HTTP_X_FORWARDED', |
|
| 60 | - 'HTTP_FORWARDED_FOR', |
|
| 61 | - 'HTTP_FORWARDED' |
|
| 62 | - ); |
|
| 63 | - foreach ($ipServerVars as $var) { |
|
| 64 | - if(isset($_SERVER[$var])){ |
|
| 65 | - $ip = $_SERVER[$var]; |
|
| 66 | - break; |
|
| 67 | - } |
|
| 68 | - } |
|
| 69 | - // Strip any secondary IP etc from the IP address |
|
| 70 | - if (strpos($ip, ',') > 0) { |
|
| 71 | - $ip = substr($ip, 0, strpos($ip, ',')); |
|
| 72 | - } |
|
| 73 | - return $ip; |
|
| 74 | - } |
|
| 75 | - } |
|
| 44 | + if(! function_exists('get_ip')){ |
|
| 45 | + /** |
|
| 46 | + * Retrieves the user's IP address |
|
| 47 | + * |
|
| 48 | + * This function allows to retrieve the IP address of the client |
|
| 49 | + * even if it uses a proxy, the actual IP address is retrieved. |
|
| 50 | + * |
|
| 51 | + * @return string the IP address. |
|
| 52 | + */ |
|
| 53 | + function get_ip(){ |
|
| 54 | + $ip = '127.0.0.1'; |
|
| 55 | + $ipServerVars = array( |
|
| 56 | + 'REMOTE_ADDR', |
|
| 57 | + 'HTTP_CLIENT_IP', |
|
| 58 | + 'HTTP_X_FORWARDED_FOR', |
|
| 59 | + 'HTTP_X_FORWARDED', |
|
| 60 | + 'HTTP_FORWARDED_FOR', |
|
| 61 | + 'HTTP_FORWARDED' |
|
| 62 | + ); |
|
| 63 | + foreach ($ipServerVars as $var) { |
|
| 64 | + if(isset($_SERVER[$var])){ |
|
| 65 | + $ip = $_SERVER[$var]; |
|
| 66 | + break; |
|
| 67 | + } |
|
| 68 | + } |
|
| 69 | + // Strip any secondary IP etc from the IP address |
|
| 70 | + if (strpos($ip, ',') > 0) { |
|
| 71 | + $ip = substr($ip, 0, strpos($ip, ',')); |
|
| 72 | + } |
|
| 73 | + return $ip; |
|
| 74 | + } |
|
| 75 | + } |
|
@@ -1,168 +1,168 @@ |
||
| 1 | 1 | <?php |
| 2 | - defined('ROOT_PATH') || exit('Access denied'); |
|
| 3 | - /** |
|
| 4 | - * TNH Framework |
|
| 5 | - * |
|
| 6 | - * A simple PHP framework using HMVC architecture |
|
| 7 | - * |
|
| 8 | - * This content is released under the GNU GPL License (GPL) |
|
| 9 | - * |
|
| 10 | - * Copyright (C) 2017 Tony NGUEREZA |
|
| 11 | - * |
|
| 12 | - * This program is free software; you can redistribute it and/or |
|
| 13 | - * modify it under the terms of the GNU General Public License |
|
| 14 | - * as published by the Free Software Foundation; either version 3 |
|
| 15 | - * of the License, or (at your option) any later version. |
|
| 16 | - * |
|
| 17 | - * This program is distributed in the hope that it will be useful, |
|
| 18 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 19 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 20 | - * GNU General Public License for more details. |
|
| 21 | - * |
|
| 22 | - * You should have received a copy of the GNU General Public License |
|
| 23 | - * along with this program; if not, write to the Free Software |
|
| 24 | - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
| 25 | - */ |
|
| 2 | + defined('ROOT_PATH') || exit('Access denied'); |
|
| 3 | + /** |
|
| 4 | + * TNH Framework |
|
| 5 | + * |
|
| 6 | + * A simple PHP framework using HMVC architecture |
|
| 7 | + * |
|
| 8 | + * This content is released under the GNU GPL License (GPL) |
|
| 9 | + * |
|
| 10 | + * Copyright (C) 2017 Tony NGUEREZA |
|
| 11 | + * |
|
| 12 | + * This program is free software; you can redistribute it and/or |
|
| 13 | + * modify it under the terms of the GNU General Public License |
|
| 14 | + * as published by the Free Software Foundation; either version 3 |
|
| 15 | + * of the License, or (at your option) any later version. |
|
| 16 | + * |
|
| 17 | + * This program is distributed in the hope that it will be useful, |
|
| 18 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 19 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 20 | + * GNU General Public License for more details. |
|
| 21 | + * |
|
| 22 | + * You should have received a copy of the GNU General Public License |
|
| 23 | + * along with this program; if not, write to the Free Software |
|
| 24 | + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
| 25 | + */ |
|
| 26 | 26 | |
| 27 | - /** |
|
| 28 | - * @file Assets.php |
|
| 29 | - * |
|
| 30 | - * This class contains static methods for generating static content links (images, Javascript, CSS, etc.). |
|
| 31 | - * |
|
| 32 | - * @package core |
|
| 33 | - * @author Tony NGUEREZA |
|
| 34 | - * @copyright Copyright (c) 2017 |
|
| 35 | - * @license https://opensource.org/licenses/gpl-3.0.html GNU GPL License (GPL) |
|
| 36 | - * @link http://www.iacademy.cf |
|
| 37 | - * @version 1.0.0 |
|
| 38 | - * @since 1.0.0 |
|
| 39 | - * @filesource |
|
| 40 | - */ |
|
| 41 | - class Assets{ |
|
| 27 | + /** |
|
| 28 | + * @file Assets.php |
|
| 29 | + * |
|
| 30 | + * This class contains static methods for generating static content links (images, Javascript, CSS, etc.). |
|
| 31 | + * |
|
| 32 | + * @package core |
|
| 33 | + * @author Tony NGUEREZA |
|
| 34 | + * @copyright Copyright (c) 2017 |
|
| 35 | + * @license https://opensource.org/licenses/gpl-3.0.html GNU GPL License (GPL) |
|
| 36 | + * @link http://www.iacademy.cf |
|
| 37 | + * @version 1.0.0 |
|
| 38 | + * @since 1.0.0 |
|
| 39 | + * @filesource |
|
| 40 | + */ |
|
| 41 | + class Assets{ |
|
| 42 | 42 | |
| 43 | - /** |
|
| 44 | - * The logger instance |
|
| 45 | - * @var object |
|
| 46 | - */ |
|
| 47 | - private static $logger; |
|
| 43 | + /** |
|
| 44 | + * The logger instance |
|
| 45 | + * @var object |
|
| 46 | + */ |
|
| 47 | + private static $logger; |
|
| 48 | 48 | |
| 49 | - /** |
|
| 50 | - * The signleton of the logger |
|
| 51 | - * @return Object the Log instance |
|
| 52 | - */ |
|
| 53 | - private static function getLogger(){ |
|
| 54 | - if(self::$logger == null){ |
|
| 55 | - //can't assign reference to static variable |
|
| 56 | - self::$logger[0] =& class_loader('Log', 'classes'); |
|
| 57 | - self::$logger[0]->setLogger('Library::Assets'); |
|
| 58 | - } |
|
| 59 | - return self::$logger[0]; |
|
| 60 | - } |
|
| 49 | + /** |
|
| 50 | + * The signleton of the logger |
|
| 51 | + * @return Object the Log instance |
|
| 52 | + */ |
|
| 53 | + private static function getLogger(){ |
|
| 54 | + if(self::$logger == null){ |
|
| 55 | + //can't assign reference to static variable |
|
| 56 | + self::$logger[0] =& class_loader('Log', 'classes'); |
|
| 57 | + self::$logger[0]->setLogger('Library::Assets'); |
|
| 58 | + } |
|
| 59 | + return self::$logger[0]; |
|
| 60 | + } |
|
| 61 | 61 | |
| 62 | 62 | |
| 63 | - /** |
|
| 64 | - * Generate the link of the assets file. |
|
| 65 | - * |
|
| 66 | - * Generates the absolute link of a file inside ASSETS_PATH folder. |
|
| 67 | - * For example : |
|
| 68 | - * echo Assets::path('foo/bar/css/style.css'); => http://mysite.com/assets/foo/bar/css/style.css |
|
| 69 | - * Note: |
|
| 70 | - * The argument passed to this function must be the relative link to the folder that contains the static contents defined by the constant ASSETS_PATH. |
|
| 71 | - * |
|
| 72 | - * @param string $asset the name of the assets file path with the extension. |
|
| 73 | - * @return string|null the absolute path of the assets file, if it exists otherwise returns null if the file does not exist. |
|
| 74 | - */ |
|
| 75 | - public static function path($asset){ |
|
| 76 | - $logger = self::getLogger(); |
|
| 77 | - $path = ASSETS_PATH . $asset; |
|
| 63 | + /** |
|
| 64 | + * Generate the link of the assets file. |
|
| 65 | + * |
|
| 66 | + * Generates the absolute link of a file inside ASSETS_PATH folder. |
|
| 67 | + * For example : |
|
| 68 | + * echo Assets::path('foo/bar/css/style.css'); => http://mysite.com/assets/foo/bar/css/style.css |
|
| 69 | + * Note: |
|
| 70 | + * The argument passed to this function must be the relative link to the folder that contains the static contents defined by the constant ASSETS_PATH. |
|
| 71 | + * |
|
| 72 | + * @param string $asset the name of the assets file path with the extension. |
|
| 73 | + * @return string|null the absolute path of the assets file, if it exists otherwise returns null if the file does not exist. |
|
| 74 | + */ |
|
| 75 | + public static function path($asset){ |
|
| 76 | + $logger = self::getLogger(); |
|
| 77 | + $path = ASSETS_PATH . $asset; |
|
| 78 | 78 | |
| 79 | - $logger->debug('Including the Assets file [' . $path . ']'); |
|
| 80 | - //Check if the file exists |
|
| 81 | - if(file_exists($path)){ |
|
| 82 | - $logger->info('Assets file [' . $path . '] included successfully'); |
|
| 83 | - return Url::base_url($path); |
|
| 84 | - } |
|
| 85 | - $logger->warning('Assets file [' . $path . '] does not exist'); |
|
| 86 | - return null; |
|
| 87 | - } |
|
| 79 | + $logger->debug('Including the Assets file [' . $path . ']'); |
|
| 80 | + //Check if the file exists |
|
| 81 | + if(file_exists($path)){ |
|
| 82 | + $logger->info('Assets file [' . $path . '] included successfully'); |
|
| 83 | + return Url::base_url($path); |
|
| 84 | + } |
|
| 85 | + $logger->warning('Assets file [' . $path . '] does not exist'); |
|
| 86 | + return null; |
|
| 87 | + } |
|
| 88 | 88 | |
| 89 | - /** |
|
| 90 | - * Generate the link of the css file. |
|
| 91 | - * |
|
| 92 | - * Generates the absolute link of a file containing the CSS style. |
|
| 93 | - * For example : |
|
| 94 | - * echo Assets::css('mystyle'); => http://mysite.com/assets/css/mystyle.css |
|
| 95 | - * Note: |
|
| 96 | - * The argument passed to this function must be the relative link to the folder that contains the static contents defined by the constant ASSETS_PATH. |
|
| 97 | - * |
|
| 98 | - * @param string $path the name of the css file without the extension. |
|
| 99 | - * @return string|null the absolute path of the css file, if it exists otherwise returns null if the file does not exist. |
|
| 100 | - */ |
|
| 101 | - public static function css($path){ |
|
| 102 | - $logger = self::getLogger(); |
|
| 103 | - /* |
|
| 89 | + /** |
|
| 90 | + * Generate the link of the css file. |
|
| 91 | + * |
|
| 92 | + * Generates the absolute link of a file containing the CSS style. |
|
| 93 | + * For example : |
|
| 94 | + * echo Assets::css('mystyle'); => http://mysite.com/assets/css/mystyle.css |
|
| 95 | + * Note: |
|
| 96 | + * The argument passed to this function must be the relative link to the folder that contains the static contents defined by the constant ASSETS_PATH. |
|
| 97 | + * |
|
| 98 | + * @param string $path the name of the css file without the extension. |
|
| 99 | + * @return string|null the absolute path of the css file, if it exists otherwise returns null if the file does not exist. |
|
| 100 | + */ |
|
| 101 | + public static function css($path){ |
|
| 102 | + $logger = self::getLogger(); |
|
| 103 | + /* |
|
| 104 | 104 | * if the file name contains the ".css" extension, replace it with |
| 105 | 105 | * an empty string for better processing. |
| 106 | 106 | */ |
| 107 | - $path = str_ireplace('.css', '', $path); |
|
| 108 | - $path = ASSETS_PATH . 'css/' . $path . '.css'; |
|
| 107 | + $path = str_ireplace('.css', '', $path); |
|
| 108 | + $path = ASSETS_PATH . 'css/' . $path . '.css'; |
|
| 109 | 109 | |
| 110 | - $logger->debug('Including the Assets file [' . $path . '] for CSS'); |
|
| 111 | - //Check if the file exists |
|
| 112 | - if(file_exists($path)){ |
|
| 113 | - $logger->info('Assets file [' . $path . '] for CSS included successfully'); |
|
| 114 | - return Url::base_url($path); |
|
| 115 | - } |
|
| 116 | - $logger->warning('Assets file [' . $path . '] for CSS does not exist'); |
|
| 117 | - return null; |
|
| 118 | - } |
|
| 110 | + $logger->debug('Including the Assets file [' . $path . '] for CSS'); |
|
| 111 | + //Check if the file exists |
|
| 112 | + if(file_exists($path)){ |
|
| 113 | + $logger->info('Assets file [' . $path . '] for CSS included successfully'); |
|
| 114 | + return Url::base_url($path); |
|
| 115 | + } |
|
| 116 | + $logger->warning('Assets file [' . $path . '] for CSS does not exist'); |
|
| 117 | + return null; |
|
| 118 | + } |
|
| 119 | 119 | |
| 120 | - /** |
|
| 121 | - * Generate the link of the javascript file. |
|
| 122 | - * |
|
| 123 | - * Generates the absolute link of a file containing the javascript. |
|
| 124 | - * For example : |
|
| 125 | - * echo Assets::js('myscript'); => http://mysite.com/assets/js/myscript.js |
|
| 126 | - * Note: |
|
| 127 | - * The argument passed to this function must be the relative link to the folder that contains the static contents defined by the constant ASSETS_PATH. |
|
| 128 | - * |
|
| 129 | - * @param string $path the name of the javascript file without the extension. |
|
| 130 | - * @return string|null the absolute path of the javascript file, if it exists otherwise returns null if the file does not exist. |
|
| 131 | - */ |
|
| 132 | - public static function js($path){ |
|
| 133 | - $logger = self::getLogger(); |
|
| 134 | - $path = str_ireplace('.js', '', $path); |
|
| 135 | - $path = ASSETS_PATH . 'js/' . $path . '.js'; |
|
| 136 | - $logger->debug('Including the Assets file [' . $path . '] for javascript'); |
|
| 137 | - if(file_exists($path)){ |
|
| 138 | - $logger->info('Assets file [' . $path . '] for Javascript included successfully'); |
|
| 139 | - return Url::base_url($path); |
|
| 140 | - } |
|
| 141 | - $logger->warning('Assets file [' . $path . '] for Javascript does not exist'); |
|
| 142 | - return null; |
|
| 143 | - } |
|
| 120 | + /** |
|
| 121 | + * Generate the link of the javascript file. |
|
| 122 | + * |
|
| 123 | + * Generates the absolute link of a file containing the javascript. |
|
| 124 | + * For example : |
|
| 125 | + * echo Assets::js('myscript'); => http://mysite.com/assets/js/myscript.js |
|
| 126 | + * Note: |
|
| 127 | + * The argument passed to this function must be the relative link to the folder that contains the static contents defined by the constant ASSETS_PATH. |
|
| 128 | + * |
|
| 129 | + * @param string $path the name of the javascript file without the extension. |
|
| 130 | + * @return string|null the absolute path of the javascript file, if it exists otherwise returns null if the file does not exist. |
|
| 131 | + */ |
|
| 132 | + public static function js($path){ |
|
| 133 | + $logger = self::getLogger(); |
|
| 134 | + $path = str_ireplace('.js', '', $path); |
|
| 135 | + $path = ASSETS_PATH . 'js/' . $path . '.js'; |
|
| 136 | + $logger->debug('Including the Assets file [' . $path . '] for javascript'); |
|
| 137 | + if(file_exists($path)){ |
|
| 138 | + $logger->info('Assets file [' . $path . '] for Javascript included successfully'); |
|
| 139 | + return Url::base_url($path); |
|
| 140 | + } |
|
| 141 | + $logger->warning('Assets file [' . $path . '] for Javascript does not exist'); |
|
| 142 | + return null; |
|
| 143 | + } |
|
| 144 | 144 | |
| 145 | - /** |
|
| 146 | - * Generate the link of the image file. |
|
| 147 | - * |
|
| 148 | - * Generates the absolute link of a file containing the image. |
|
| 149 | - * For example : |
|
| 150 | - * echo Assets::img('myimage.png'); => http://mysite.com/assets/images/myimage.png |
|
| 151 | - * Note: |
|
| 152 | - * The argument passed to this function must be the relative link to the folder that contains the static contents defined by the constant ASSETS_PATH. |
|
| 153 | - * |
|
| 154 | - * @param string $path the name of the image file with the extension. |
|
| 155 | - * @return string|null the absolute path of the image file, if it exists otherwise returns null if the file does not exist. |
|
| 156 | - */ |
|
| 157 | - public static function img($path){ |
|
| 158 | - $logger = self::getLogger(); |
|
| 159 | - $path = ASSETS_PATH . 'images/' . $path; |
|
| 160 | - $logger->debug('Including the Assets file [' . $path . '] for image'); |
|
| 161 | - if(file_exists($path)){ |
|
| 162 | - $logger->info('Assets file [' . $path . '] for image included successfully'); |
|
| 163 | - return Url::base_url($path); |
|
| 164 | - } |
|
| 165 | - $logger->warning('Assets file [' . $path . '] for image does not exist'); |
|
| 166 | - return null; |
|
| 167 | - } |
|
| 168 | - } |
|
| 145 | + /** |
|
| 146 | + * Generate the link of the image file. |
|
| 147 | + * |
|
| 148 | + * Generates the absolute link of a file containing the image. |
|
| 149 | + * For example : |
|
| 150 | + * echo Assets::img('myimage.png'); => http://mysite.com/assets/images/myimage.png |
|
| 151 | + * Note: |
|
| 152 | + * The argument passed to this function must be the relative link to the folder that contains the static contents defined by the constant ASSETS_PATH. |
|
| 153 | + * |
|
| 154 | + * @param string $path the name of the image file with the extension. |
|
| 155 | + * @return string|null the absolute path of the image file, if it exists otherwise returns null if the file does not exist. |
|
| 156 | + */ |
|
| 157 | + public static function img($path){ |
|
| 158 | + $logger = self::getLogger(); |
|
| 159 | + $path = ASSETS_PATH . 'images/' . $path; |
|
| 160 | + $logger->debug('Including the Assets file [' . $path . '] for image'); |
|
| 161 | + if(file_exists($path)){ |
|
| 162 | + $logger->info('Assets file [' . $path . '] for image included successfully'); |
|
| 163 | + return Url::base_url($path); |
|
| 164 | + } |
|
| 165 | + $logger->warning('Assets file [' . $path . '] for image does not exist'); |
|
| 166 | + return null; |
|
| 167 | + } |
|
| 168 | + } |
|