@@ -25,15 +25,15 @@ discard block |
||
| 25 | 25 | */ |
| 26 | 26 | |
| 27 | 27 | |
| 28 | - class Url{ |
|
| 28 | + class Url { |
|
| 29 | 29 | |
| 30 | 30 | /** |
| 31 | 31 | * Return the link using base_url config without front controller "index.php" |
| 32 | 32 | * @param string $path the link path or full URL |
| 33 | 33 | * @return string the full link URL |
| 34 | 34 | */ |
| 35 | - public static function base_url($path = ''){ |
|
| 36 | - if(is_url($path)){ |
|
| 35 | + public static function base_url($path = '') { |
|
| 36 | + if (is_url($path)) { |
|
| 37 | 37 | return $path; |
| 38 | 38 | } |
| 39 | 39 | return get_config('base_url') . $path; |
@@ -44,26 +44,26 @@ discard block |
||
| 44 | 44 | * @param string $path the link path or full URL |
| 45 | 45 | * @return string the full link URL |
| 46 | 46 | */ |
| 47 | - public static function site_url($path = ''){ |
|
| 48 | - if(is_url($path)){ |
|
| 47 | + public static function site_url($path = '') { |
|
| 48 | + if (is_url($path)) { |
|
| 49 | 49 | return $path; |
| 50 | 50 | } |
| 51 | 51 | $path = rtrim($path, '/'); |
| 52 | 52 | $baseUrl = get_config('base_url'); |
| 53 | 53 | $frontController = get_config('front_controller'); |
| 54 | 54 | $url = $baseUrl; |
| 55 | - if($frontController){ |
|
| 55 | + if ($frontController) { |
|
| 56 | 56 | $url .= $frontController . '/'; |
| 57 | 57 | } |
| 58 | - if(($suffix = get_config('url_suffix')) && $path){ |
|
| 59 | - if(strpos($path, '?') !== false){ |
|
| 58 | + if (($suffix = get_config('url_suffix')) && $path) { |
|
| 59 | + if (strpos($path, '?') !== false) { |
|
| 60 | 60 | $query = explode('?', $path); |
| 61 | 61 | $query[0] = str_ireplace($suffix, '', $query[0]); |
| 62 | 62 | $query[0] = rtrim($query[0], '/'); |
| 63 | 63 | $query[0] .= $suffix; |
| 64 | 64 | $path = implode('?', $query); |
| 65 | 65 | } |
| 66 | - else{ |
|
| 66 | + else { |
|
| 67 | 67 | $path .= $suffix; |
| 68 | 68 | } |
| 69 | 69 | } |
@@ -74,10 +74,10 @@ discard block |
||
| 74 | 74 | * Return the current site URL |
| 75 | 75 | * @return string |
| 76 | 76 | */ |
| 77 | - public static function current(){ |
|
| 77 | + public static function current() { |
|
| 78 | 78 | $current = '/'; |
| 79 | 79 | $requestUri = get_instance()->request->requestUri(); |
| 80 | - if($requestUri){ |
|
| 80 | + if ($requestUri) { |
|
| 81 | 81 | $current = $requestUri; |
| 82 | 82 | } |
| 83 | 83 | return static::domain() . $current; |
@@ -90,18 +90,18 @@ discard block |
||
| 90 | 90 | * @param boolean $lowercase whether to set the final text to lowe case or not |
| 91 | 91 | * @return string the friendly generated text |
| 92 | 92 | */ |
| 93 | - public static function title($str = null, $separator = '-', $lowercase = true){ |
|
| 93 | + public static function title($str = null, $separator = '-', $lowercase = true) { |
|
| 94 | 94 | $str = trim($str); |
| 95 | - $from = array('ç','À','Á','Â','Ã','Ä','Å','à','á','â','ã','ä','å','Ò','Ó','Ô','Õ','Ö','Ø','ò','ó','ô','õ','ö','ø','È','É','Ê','Ë','è','é','ê','ë','Ç','ç','Ì','Í','Î','Ï','ì','í','î','ï','Ù','Ú','Û','Ü','ù','ú','û','ü','ÿ','Ñ','ñ'); |
|
| 96 | - $to = array('c','a','a','a','a','a','a','a','a','a','a','a','a','o','o','o','o','o','o','o','o','o','o','o','o','e','e','e','e','e','e','e','e','e','e','i','i','i','i','i','i','i','i','u','u','u','u','u','u','u','u','y','n','n'); |
|
| 95 | + $from = array('ç', 'À', 'Á', 'Â', 'Ã', 'Ä', 'Å', 'à', 'á', 'â', 'ã', 'ä', 'å', 'Ò', 'Ó', 'Ô', 'Õ', 'Ö', 'Ø', 'ò', 'ó', 'ô', 'õ', 'ö', 'ø', 'È', 'É', 'Ê', 'Ë', 'è', 'é', 'ê', 'ë', 'Ç', 'ç', 'Ì', 'Í', 'Î', 'Ï', 'ì', 'í', 'î', 'ï', 'Ù', 'Ú', 'Û', 'Ü', 'ù', 'ú', 'û', 'ü', 'ÿ', 'Ñ', 'ñ'); |
|
| 96 | + $to = array('c', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'e', 'e', 'e', 'e', 'e', 'e', 'e', 'e', 'e', 'e', 'i', 'i', 'i', 'i', 'i', 'i', 'i', 'i', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'y', 'n', 'n'); |
|
| 97 | 97 | $str = str_replace($from, $to, $str); |
| 98 | 98 | $str = preg_replace('#([^a-z0-9]+)#i', $separator, $str); |
| 99 | 99 | $str = str_replace('--', $separator, $str); |
| 100 | 100 | //if after process we get something like one-two-three-, need truncate the last separator "-" |
| 101 | - if(substr($str, -1) == $separator){ |
|
| 101 | + if (substr($str, -1) == $separator) { |
|
| 102 | 102 | $str = substr($str, 0, -1); |
| 103 | 103 | } |
| 104 | - if($lowercase){ |
|
| 104 | + if ($lowercase) { |
|
| 105 | 105 | $str = strtolower($str); |
| 106 | 106 | } |
| 107 | 107 | return $str; |
@@ -111,12 +111,12 @@ discard block |
||
| 111 | 111 | * Get the current application domain with protocol |
| 112 | 112 | * @return string the domain name |
| 113 | 113 | */ |
| 114 | - public static function domain(){ |
|
| 114 | + public static function domain() { |
|
| 115 | 115 | $obj = & get_instance(); |
| 116 | 116 | $domain = 'localhost'; |
| 117 | 117 | $port = $obj->request->server('SERVER_PORT'); |
| 118 | 118 | $protocol = 'http'; |
| 119 | - if(is_https()){ |
|
| 119 | + if (is_https()) { |
|
| 120 | 120 | $protocol = 'https'; |
| 121 | 121 | } |
| 122 | 122 | |
@@ -128,27 +128,27 @@ discard block |
||
| 128 | 128 | |
| 129 | 129 | foreach ($domainserverVars as $var) { |
| 130 | 130 | $value = $obj->request->server($var); |
| 131 | - if($value){ |
|
| 131 | + if ($value) { |
|
| 132 | 132 | $domain = $value; |
| 133 | 133 | break; |
| 134 | 134 | } |
| 135 | 135 | } |
| 136 | 136 | |
| 137 | - if($port && ((is_https() && $port != 443) || (!is_https() && $port != 80))){ |
|
| 137 | + if ($port && ((is_https() && $port != 443) || (!is_https() && $port != 80))) { |
|
| 138 | 138 | //some server use SSL but the port doesn't equal 443 sometime is 80 if is the case put the port at this end |
| 139 | 139 | //of the domain like https://my.domain.com:787 |
| 140 | - if(is_https() && $port != 80){ |
|
| 141 | - $domain .= ':'.$port; |
|
| 140 | + if (is_https() && $port != 80) { |
|
| 141 | + $domain .= ':' . $port; |
|
| 142 | 142 | } |
| 143 | 143 | } |
| 144 | - return $protocol.'://'.$domain; |
|
| 144 | + return $protocol . '://' . $domain; |
|
| 145 | 145 | } |
| 146 | 146 | |
| 147 | 147 | /** |
| 148 | 148 | * Get the current request query string |
| 149 | 149 | * @return string |
| 150 | 150 | */ |
| 151 | - public static function queryString(){ |
|
| 151 | + public static function queryString() { |
|
| 152 | 152 | return get_instance()->request->server('QUERY_STRING'); |
| 153 | 153 | } |
| 154 | 154 | } |
@@ -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 Config{ |
|
| 27 | + class Config { |
|
| 28 | 28 | |
| 29 | 29 | /** |
| 30 | 30 | * The list of loaded configuration |
@@ -42,10 +42,10 @@ discard block |
||
| 42 | 42 | * The signleton of the logger |
| 43 | 43 | * @return Object the Log instance |
| 44 | 44 | */ |
| 45 | - private static function getLogger(){ |
|
| 46 | - if(self::$logger == null){ |
|
| 45 | + private static function getLogger() { |
|
| 46 | + if (self::$logger == null) { |
|
| 47 | 47 | $logger = array(); |
| 48 | - $logger[0] =& class_loader('Log', 'classes'); |
|
| 48 | + $logger[0] = & class_loader('Log', 'classes'); |
|
| 49 | 49 | $logger[0]->setLogger('Library::Config'); |
| 50 | 50 | self::$logger = $logger[0]; |
| 51 | 51 | } |
@@ -57,7 +57,7 @@ discard block |
||
| 57 | 57 | * @param Log $logger the log object |
| 58 | 58 | * @return Log the log instance |
| 59 | 59 | */ |
| 60 | - public static function setLogger($logger){ |
|
| 60 | + public static function setLogger($logger) { |
|
| 61 | 61 | self::$logger = $logger; |
| 62 | 62 | return self::$logger; |
| 63 | 63 | } |
@@ -65,12 +65,12 @@ discard block |
||
| 65 | 65 | /** |
| 66 | 66 | * Initialize the configuration by loading all the configuration from config file |
| 67 | 67 | */ |
| 68 | - public static function init(){ |
|
| 68 | + public static function init() { |
|
| 69 | 69 | $logger = static::getLogger(); |
| 70 | 70 | $logger->debug('Initialization of the configuration'); |
| 71 | 71 | self::$config = & load_configurations(); |
| 72 | 72 | self::setBaseUrlUsingServerVar(); |
| 73 | - if(ENVIRONMENT == 'production' && in_array(strtolower(self::$config['log_level']), array('debug', 'info','all'))){ |
|
| 73 | + if (ENVIRONMENT == 'production' && in_array(strtolower(self::$config['log_level']), array('debug', 'info', 'all'))) { |
|
| 74 | 74 | $logger->warning('You are in production environment, please set log level to WARNING, ERROR, FATAL to increase the application performance'); |
| 75 | 75 | } |
| 76 | 76 | $logger->info('Configuration initialized successfully'); |
@@ -83,12 +83,12 @@ discard block |
||
| 83 | 83 | * @param mixed $default the default value to use if can not find the config item in the list |
| 84 | 84 | * @return mixed the config value if exist or the default value |
| 85 | 85 | */ |
| 86 | - public static function get($item, $default = null){ |
|
| 86 | + public static function get($item, $default = null) { |
|
| 87 | 87 | $logger = static::getLogger(); |
| 88 | - if(array_key_exists($item, self::$config)){ |
|
| 88 | + if (array_key_exists($item, self::$config)) { |
|
| 89 | 89 | return self::$config[$item]; |
| 90 | 90 | } |
| 91 | - $logger->warning('Cannot find config item ['.$item.'] using the default value ['.$default.']'); |
|
| 91 | + $logger->warning('Cannot find config item [' . $item . '] using the default value [' . $default . ']'); |
|
| 92 | 92 | return $default; |
| 93 | 93 | } |
| 94 | 94 | |
@@ -97,7 +97,7 @@ discard block |
||
| 97 | 97 | * @param string $item the config item name to set |
| 98 | 98 | * @param mixed $value the config item value |
| 99 | 99 | */ |
| 100 | - public static function set($item, $value){ |
|
| 100 | + public static function set($item, $value) { |
|
| 101 | 101 | self::$config[$item] = $value; |
| 102 | 102 | } |
| 103 | 103 | |
@@ -105,7 +105,7 @@ discard block |
||
| 105 | 105 | * Get all the configuration values |
| 106 | 106 | * @return array the config values |
| 107 | 107 | */ |
| 108 | - public static function getAll(){ |
|
| 108 | + public static function getAll() { |
|
| 109 | 109 | return self::$config; |
| 110 | 110 | } |
| 111 | 111 | |
@@ -113,7 +113,7 @@ discard block |
||
| 113 | 113 | * Set the configuration values bu merged with the existing configuration |
| 114 | 114 | * @param array $config the config values to add in the configuration list |
| 115 | 115 | */ |
| 116 | - public static function setAll(array $config = array()){ |
|
| 116 | + public static function setAll(array $config = array()) { |
|
| 117 | 117 | self::$config = array_merge(self::$config, $config); |
| 118 | 118 | } |
| 119 | 119 | |
@@ -122,15 +122,15 @@ discard block |
||
| 122 | 122 | * @param string $item the config item name to be deleted |
| 123 | 123 | * @return boolean true if the item exists and is deleted successfully otherwise will return false. |
| 124 | 124 | */ |
| 125 | - public static function delete($item){ |
|
| 125 | + public static function delete($item) { |
|
| 126 | 126 | $logger = static::getLogger(); |
| 127 | - if(array_key_exists($item, self::$config)){ |
|
| 128 | - $logger->info('Delete config item ['.$item.']'); |
|
| 127 | + if (array_key_exists($item, self::$config)) { |
|
| 128 | + $logger->info('Delete config item [' . $item . ']'); |
|
| 129 | 129 | unset(self::$config[$item]); |
| 130 | 130 | return true; |
| 131 | 131 | } |
| 132 | - else{ |
|
| 133 | - $logger->warning('Config item ['.$item.'] to be deleted does not exists'); |
|
| 132 | + else { |
|
| 133 | + $logger->warning('Config item [' . $item . '] to be deleted does not exists'); |
|
| 134 | 134 | return false; |
| 135 | 135 | } |
| 136 | 136 | } |
@@ -139,40 +139,40 @@ discard block |
||
| 139 | 139 | * Load the configuration file. This an alias to Loader::config() |
| 140 | 140 | * @param string $config the config name to be loaded |
| 141 | 141 | */ |
| 142 | - public static function load($config){ |
|
| 142 | + public static function load($config) { |
|
| 143 | 143 | Loader::config($config); |
| 144 | 144 | } |
| 145 | 145 | |
| 146 | 146 | /** |
| 147 | 147 | * Set the configuration for "base_url" if is not set in the configuration |
| 148 | 148 | */ |
| 149 | - private static function setBaseUrlUsingServerVar(){ |
|
| 149 | + private static function setBaseUrlUsingServerVar() { |
|
| 150 | 150 | $logger = static::getLogger(); |
| 151 | - if (! isset(self::$config['base_url']) || ! is_url(self::$config['base_url'])){ |
|
| 152 | - if(ENVIRONMENT == 'production'){ |
|
| 151 | + if (!isset(self::$config['base_url']) || !is_url(self::$config['base_url'])) { |
|
| 152 | + if (ENVIRONMENT == 'production') { |
|
| 153 | 153 | $logger->warning('Application base URL is not set or invalid, please set application base URL to increase the application loading time'); |
| 154 | 154 | } |
| 155 | 155 | $baseUrl = null; |
| 156 | - if (isset($_SERVER['SERVER_ADDR'])){ |
|
| 156 | + if (isset($_SERVER['SERVER_ADDR'])) { |
|
| 157 | 157 | $baseUrl = $_SERVER['SERVER_ADDR']; |
| 158 | 158 | //check if the server is running under IPv6 |
| 159 | - if (strpos($_SERVER['SERVER_ADDR'], ':') !== FALSE){ |
|
| 160 | - $baseUrl = '['.$_SERVER['SERVER_ADDR'].']'; |
|
| 159 | + if (strpos($_SERVER['SERVER_ADDR'], ':') !== FALSE) { |
|
| 160 | + $baseUrl = '[' . $_SERVER['SERVER_ADDR'] . ']'; |
|
| 161 | 161 | } |
| 162 | 162 | $serverPort = 80; |
| 163 | 163 | if (isset($_SERVER['SERVER_PORT'])) { |
| 164 | 164 | $serverPort = $_SERVER['SERVER_PORT']; |
| 165 | 165 | } |
| 166 | - $port = ((($serverPort != '80' && ! is_https()) || ($serverPort != '443' && is_https())) ? ':' . $serverPort : ''); |
|
| 167 | - $baseUrl = (is_https() ? 'https' : 'http').'://' . $baseUrl . $port |
|
| 166 | + $port = ((($serverPort != '80' && !is_https()) || ($serverPort != '443' && is_https())) ? ':' . $serverPort : ''); |
|
| 167 | + $baseUrl = (is_https() ? 'https' : 'http') . '://' . $baseUrl . $port |
|
| 168 | 168 | . substr($_SERVER['SCRIPT_NAME'], 0, strpos($_SERVER['SCRIPT_NAME'], basename($_SERVER['SCRIPT_FILENAME']))); |
| 169 | 169 | } |
| 170 | - else{ |
|
| 170 | + else { |
|
| 171 | 171 | $logger->warning('Can not determine the application base URL automatically, use http://localhost as default'); |
| 172 | 172 | $baseUrl = 'http://localhost/'; |
| 173 | 173 | } |
| 174 | 174 | self::set('base_url', $baseUrl); |
| 175 | 175 | } |
| 176 | - self::$config['base_url'] = rtrim(self::$config['base_url'], '/') .'/'; |
|
| 176 | + self::$config['base_url'] = rtrim(self::$config['base_url'], '/') . '/'; |
|
| 177 | 177 | } |
| 178 | 178 | } |
@@ -41,7 +41,7 @@ discard block |
||
| 41 | 41 | */ |
| 42 | 42 | |
| 43 | 43 | |
| 44 | - if(! function_exists('get_ip')){ |
|
| 44 | + if (!function_exists('get_ip')) { |
|
| 45 | 45 | /** |
| 46 | 46 | * Retrieves the user's IP address |
| 47 | 47 | * |
@@ -50,7 +50,7 @@ discard block |
||
| 50 | 50 | * |
| 51 | 51 | * @return string the IP address. |
| 52 | 52 | */ |
| 53 | - function get_ip(){ |
|
| 53 | + function get_ip() { |
|
| 54 | 54 | $ip = '127.0.0.1'; |
| 55 | 55 | $ipServerVars = array( |
| 56 | 56 | 'REMOTE_ADDR', |
@@ -61,7 +61,7 @@ discard block |
||
| 61 | 61 | 'HTTP_FORWARDED' |
| 62 | 62 | ); |
| 63 | 63 | foreach ($ipServerVars as $var) { |
| 64 | - if(isset($_SERVER[$var])){ |
|
| 64 | + if (isset($_SERVER[$var])) { |
|
| 65 | 65 | $ip = $_SERVER[$var]; |
| 66 | 66 | break; |
| 67 | 67 | } |
@@ -38,7 +38,7 @@ discard block |
||
| 38 | 38 | * @since 1.0.0 |
| 39 | 39 | * @filesource |
| 40 | 40 | */ |
| 41 | - class Assets{ |
|
| 41 | + class Assets { |
|
| 42 | 42 | |
| 43 | 43 | /** |
| 44 | 44 | * The logger instance |
@@ -50,10 +50,10 @@ discard block |
||
| 50 | 50 | * The signleton of the logger |
| 51 | 51 | * @return Object the Log instance |
| 52 | 52 | */ |
| 53 | - private static function getLogger(){ |
|
| 54 | - if(self::$logger == null){ |
|
| 53 | + private static function getLogger() { |
|
| 54 | + if (self::$logger == null) { |
|
| 55 | 55 | //can't assign reference to static variable |
| 56 | - self::$logger[0] =& class_loader('Log', 'classes'); |
|
| 56 | + self::$logger[0] = & class_loader('Log', 'classes'); |
|
| 57 | 57 | self::$logger[0]->setLogger('Library::Assets'); |
| 58 | 58 | } |
| 59 | 59 | return self::$logger[0]; |
@@ -72,13 +72,13 @@ discard block |
||
| 72 | 72 | * @param string $asset the name of the assets file path with the extension. |
| 73 | 73 | * @return string|null the absolute path of the assets file, if it exists otherwise returns null if the file does not exist. |
| 74 | 74 | */ |
| 75 | - public static function path($asset){ |
|
| 75 | + public static function path($asset) { |
|
| 76 | 76 | $logger = self::getLogger(); |
| 77 | 77 | $path = ASSETS_PATH . $asset; |
| 78 | 78 | |
| 79 | 79 | $logger->debug('Including the Assets file [' . $path . ']'); |
| 80 | 80 | //Check if the file exists |
| 81 | - if(file_exists($path)){ |
|
| 81 | + if (file_exists($path)) { |
|
| 82 | 82 | $logger->info('Assets file [' . $path . '] included successfully'); |
| 83 | 83 | return Url::base_url($path); |
| 84 | 84 | } |
@@ -98,7 +98,7 @@ discard block |
||
| 98 | 98 | * @param string $path the name of the css file without the extension. |
| 99 | 99 | * @return string|null the absolute path of the css file, if it exists otherwise returns null if the file does not exist. |
| 100 | 100 | */ |
| 101 | - public static function css($path){ |
|
| 101 | + public static function css($path) { |
|
| 102 | 102 | $logger = self::getLogger(); |
| 103 | 103 | /* |
| 104 | 104 | * if the file name contains the ".css" extension, replace it with |
@@ -109,7 +109,7 @@ discard block |
||
| 109 | 109 | |
| 110 | 110 | $logger->debug('Including the Assets file [' . $path . '] for CSS'); |
| 111 | 111 | //Check if the file exists |
| 112 | - if(file_exists($path)){ |
|
| 112 | + if (file_exists($path)) { |
|
| 113 | 113 | $logger->info('Assets file [' . $path . '] for CSS included successfully'); |
| 114 | 114 | return Url::base_url($path); |
| 115 | 115 | } |
@@ -129,12 +129,12 @@ discard block |
||
| 129 | 129 | * @param string $path the name of the javascript file without the extension. |
| 130 | 130 | * @return string|null the absolute path of the javascript file, if it exists otherwise returns null if the file does not exist. |
| 131 | 131 | */ |
| 132 | - public static function js($path){ |
|
| 132 | + public static function js($path) { |
|
| 133 | 133 | $logger = self::getLogger(); |
| 134 | 134 | $path = str_ireplace('.js', '', $path); |
| 135 | 135 | $path = ASSETS_PATH . 'js/' . $path . '.js'; |
| 136 | 136 | $logger->debug('Including the Assets file [' . $path . '] for javascript'); |
| 137 | - if(file_exists($path)){ |
|
| 137 | + if (file_exists($path)) { |
|
| 138 | 138 | $logger->info('Assets file [' . $path . '] for Javascript included successfully'); |
| 139 | 139 | return Url::base_url($path); |
| 140 | 140 | } |
@@ -154,11 +154,11 @@ discard block |
||
| 154 | 154 | * @param string $path the name of the image file with the extension. |
| 155 | 155 | * @return string|null the absolute path of the image file, if it exists otherwise returns null if the file does not exist. |
| 156 | 156 | */ |
| 157 | - public static function img($path){ |
|
| 157 | + public static function img($path) { |
|
| 158 | 158 | $logger = self::getLogger(); |
| 159 | 159 | $path = ASSETS_PATH . 'images/' . $path; |
| 160 | 160 | $logger->debug('Including the Assets file [' . $path . '] for image'); |
| 161 | - if(file_exists($path)){ |
|
| 161 | + if (file_exists($path)) { |
|
| 162 | 162 | $logger->info('Assets file [' . $path . '] for image included successfully'); |
| 163 | 163 | return Url::base_url($path); |
| 164 | 164 | } |