@@ -29,14 +29,14 @@ discard block |
||
| 29 | 29 | //put the first letter of class to upper case |
| 30 | 30 | $class = ucfirst($class); |
| 31 | 31 | static $classes = array(); |
| 32 | - if(isset($classes[$class]) /*hack for duplicate log Logger name*/ && $class != 'Log'){ |
|
| 32 | + if (isset($classes[$class]) /*hack for duplicate log Logger name*/ && $class != 'Log') { |
|
| 33 | 33 | return $classes[$class]; |
| 34 | 34 | } |
| 35 | 35 | $found = false; |
| 36 | 36 | foreach (array(ROOT_PATH, CORE_PATH) as $path) { |
| 37 | 37 | $file = $path . $dir . '/' . $class . '.php'; |
| 38 | - if(file_exists($file)){ |
|
| 39 | - if(class_exists($class, false) === false){ |
|
| 38 | + if (file_exists($file)) { |
|
| 39 | + if (class_exists($class, false) === false) { |
|
| 40 | 40 | require_once $file; |
| 41 | 41 | } |
| 42 | 42 | //already found |
@@ -44,7 +44,7 @@ discard block |
||
| 44 | 44 | break; |
| 45 | 45 | } |
| 46 | 46 | } |
| 47 | - if(! $found){ |
|
| 47 | + if (!$found) { |
|
| 48 | 48 | //can't use show_error() at this time because some dependencies not yet loaded |
| 49 | 49 | set_http_status_header(503); |
| 50 | 50 | echo 'Cannot find the class [' . $class . ']'; |
@@ -54,7 +54,7 @@ discard block |
||
| 54 | 54 | /* |
| 55 | 55 | TODO use the best method to get the Log instance |
| 56 | 56 | */ |
| 57 | - if($class == 'Log'){ |
|
| 57 | + if ($class == 'Log') { |
|
| 58 | 58 | //can't use the instruction like "return new Log()" |
| 59 | 59 | //because we need return the reference instance of the loaded class. |
| 60 | 60 | $log = new Log(); |
@@ -72,7 +72,7 @@ discard block |
||
| 72 | 72 | |
| 73 | 73 | function & class_loaded($class = null){ |
| 74 | 74 | static $list = array(); |
| 75 | - if($class != null){ |
|
| 75 | + if ($class != null) { |
|
| 76 | 76 | $list[strtolower($class)] = $class; |
| 77 | 77 | } |
| 78 | 78 | return $list; |
@@ -80,7 +80,7 @@ discard block |
||
| 80 | 80 | |
| 81 | 81 | function & load_configurations(array $overwrite_values = array()){ |
| 82 | 82 | static $config; |
| 83 | - if(empty($config)){ |
|
| 83 | + if (empty($config)) { |
|
| 84 | 84 | $file = CONFIG_PATH . 'config.php'; |
| 85 | 85 | require_once $file; |
| 86 | 86 | |
@@ -94,53 +94,53 @@ discard block |
||
| 94 | 94 | /** |
| 95 | 95 | * @test |
| 96 | 96 | */ |
| 97 | - function get_config($key, $default = null){ |
|
| 97 | + function get_config($key, $default = null) { |
|
| 98 | 98 | static $cfg; |
| 99 | - if(empty($cfg)){ |
|
| 99 | + if (empty($cfg)) { |
|
| 100 | 100 | $cfg[0] = & load_configurations(); |
| 101 | 101 | } |
| 102 | 102 | return array_key_exists($key, $cfg[0]) ? $cfg[0][$key] : $default; |
| 103 | 103 | } |
| 104 | 104 | |
| 105 | - function save_to_log($level, $message, $logger = null){ |
|
| 106 | - echo 'save_to_log('.$level . ',' . $message . ',' . $logger . ")\n"; |
|
| 105 | + function save_to_log($level, $message, $logger = null) { |
|
| 106 | + echo 'save_to_log(' . $level . ',' . $message . ',' . $logger . ")\n"; |
|
| 107 | 107 | } |
| 108 | 108 | |
| 109 | 109 | |
| 110 | - function set_http_status_header($code = 200, $text = null){ |
|
| 110 | + function set_http_status_header($code = 200, $text = null) { |
|
| 111 | 111 | echo 'header(' . $code . ', ' . $text . ')'; |
| 112 | 112 | return true; |
| 113 | 113 | } |
| 114 | 114 | |
| 115 | 115 | |
| 116 | - function show_error($msg, $title = 'error', $logging = true){ |
|
| 116 | + function show_error($msg, $title = 'error', $logging = true) { |
|
| 117 | 117 | //show only and continue to help track of some error occured |
| 118 | 118 | echo 'show_error(' . $msg . ', ' . $title . ', ' . ($logging ? 'Y' : 'N') . ")\n"; |
| 119 | 119 | } |
| 120 | 120 | |
| 121 | - function is_https(){ |
|
| 121 | + function is_https() { |
|
| 122 | 122 | return false; |
| 123 | 123 | } |
| 124 | 124 | |
| 125 | 125 | /** |
| 126 | 126 | * @test |
| 127 | 127 | */ |
| 128 | - function is_url($url){ |
|
| 128 | + function is_url($url) { |
|
| 129 | 129 | return preg_match('/^(http|https|ftp):\/\/(.*)/', $url); |
| 130 | 130 | } |
| 131 | 131 | |
| 132 | - function php_exception_handler($ex){ |
|
| 132 | + function php_exception_handler($ex) { |
|
| 133 | 133 | //show only and continue to help track of some error occured |
| 134 | - echo 'php_exception_handler('.$ex->getMessage().', '.$ex->getFile().', '.$ex->getLine() . ")\n"; |
|
| 134 | + echo 'php_exception_handler(' . $ex->getMessage() . ', ' . $ex->getFile() . ', ' . $ex->getLine() . ")\n"; |
|
| 135 | 135 | } |
| 136 | 136 | |
| 137 | 137 | |
| 138 | - function php_error_handler($errno , $errstr, $errfile , $errline){ |
|
| 138 | + function php_error_handler($errno, $errstr, $errfile, $errline) { |
|
| 139 | 139 | //show only and continue to help track of some error occured |
| 140 | - echo 'php_error_handler('.$errno .', ' . $errstr.', ' . $errfile.', '.$errline . ")\n"; |
|
| 140 | + echo 'php_error_handler(' . $errno . ', ' . $errstr . ', ' . $errfile . ', ' . $errline . ")\n"; |
|
| 141 | 141 | } |
| 142 | 142 | |
| 143 | - function php_shudown_handler(){ |
|
| 143 | + function php_shudown_handler() { |
|
| 144 | 144 | return true; |
| 145 | 145 | } |
| 146 | 146 | |
@@ -148,11 +148,11 @@ discard block |
||
| 148 | 148 | /** |
| 149 | 149 | * @test |
| 150 | 150 | */ |
| 151 | - function attributes_to_string(array $attributes){ |
|
| 151 | + function attributes_to_string(array $attributes) { |
|
| 152 | 152 | $str = ' '; |
| 153 | 153 | //we check that the array passed as an argument is not empty. |
| 154 | - if(! empty($attributes)){ |
|
| 155 | - foreach($attributes as $key => $value){ |
|
| 154 | + if (!empty($attributes)) { |
|
| 155 | + foreach ($attributes as $key => $value) { |
|
| 156 | 156 | $key = trim(htmlspecialchars($key)); |
| 157 | 157 | $value = trim(htmlspecialchars($value)); |
| 158 | 158 | /* |
@@ -162,35 +162,35 @@ discard block |
||
| 162 | 162 | * $attr = array('placeholder' => 'I am a "puple"') |
| 163 | 163 | * $str = attributes_to_string($attr); => placeholder = "I am a \"puple\"" |
| 164 | 164 | */ |
| 165 | - if($value && strpos('"', $value) !== false){ |
|
| 165 | + if ($value && strpos('"', $value) !== false) { |
|
| 166 | 166 | $value = addslashes($value); |
| 167 | 167 | } |
| 168 | - $str .= $key.' = "'.$value.'" '; |
|
| 168 | + $str .= $key . ' = "' . $value . '" '; |
|
| 169 | 169 | } |
| 170 | 170 | } |
| 171 | 171 | //remove the space after using rtrim() |
| 172 | 172 | return rtrim($str); |
| 173 | 173 | } |
| 174 | 174 | |
| 175 | - function stringfy_vars($var){ |
|
| 175 | + function stringfy_vars($var) { |
|
| 176 | 176 | return print_r($var, true); |
| 177 | 177 | } |
| 178 | 178 | |
| 179 | 179 | /** |
| 180 | 180 | * @test |
| 181 | 181 | */ |
| 182 | - function clean_input($str){ |
|
| 183 | - if(is_array($str)){ |
|
| 182 | + function clean_input($str) { |
|
| 183 | + if (is_array($str)) { |
|
| 184 | 184 | $str = array_map('clean_input', $str); |
| 185 | 185 | } |
| 186 | - else if(is_object($str)){ |
|
| 186 | + else if (is_object($str)) { |
|
| 187 | 187 | $obj = $str; |
| 188 | 188 | foreach ($str as $var => $value) { |
| 189 | 189 | $obj->$var = clean_input($value); |
| 190 | 190 | } |
| 191 | 191 | $str = $obj; |
| 192 | 192 | } |
| 193 | - else{ |
|
| 193 | + else { |
|
| 194 | 194 | $str = htmlspecialchars(strip_tags($str), ENT_QUOTES, 'UTF-8'); |
| 195 | 195 | } |
| 196 | 196 | return $str; |
@@ -199,11 +199,11 @@ discard block |
||
| 199 | 199 | /** |
| 200 | 200 | * @test |
| 201 | 201 | */ |
| 202 | - function string_hidden($str, $startCount = 0, $endCount = 0, $hiddenChar = '*'){ |
|
| 202 | + function string_hidden($str, $startCount = 0, $endCount = 0, $hiddenChar = '*') { |
|
| 203 | 203 | //get the string length |
| 204 | 204 | $len = strlen($str); |
| 205 | 205 | //if str is empty |
| 206 | - if($len <= 0){ |
|
| 206 | + if ($len <= 0) { |
|
| 207 | 207 | return str_repeat($hiddenChar, 6); |
| 208 | 208 | } |
| 209 | 209 | //if the length is less than startCount and endCount |
@@ -211,14 +211,14 @@ discard block |
||
| 211 | 211 | //or startCount is negative or endCount is negative |
| 212 | 212 | //return the full string hidden |
| 213 | 213 | |
| 214 | - if((($startCount + $endCount) > $len) || ($startCount == 0 && $endCount == 0) || ($startCount < 0 || $endCount < 0)){ |
|
| 214 | + if ((($startCount + $endCount) > $len) || ($startCount == 0 && $endCount == 0) || ($startCount < 0 || $endCount < 0)) { |
|
| 215 | 215 | return str_repeat($hiddenChar, $len); |
| 216 | 216 | } |
| 217 | 217 | //the start non hidden string |
| 218 | 218 | $startNonHiddenStr = substr($str, 0, $startCount); |
| 219 | 219 | //the end non hidden string |
| 220 | 220 | $endNonHiddenStr = null; |
| 221 | - if($endCount > 0){ |
|
| 221 | + if ($endCount > 0) { |
|
| 222 | 222 | $endNonHiddenStr = substr($str, - $endCount); |
| 223 | 223 | } |
| 224 | 224 | //the hidden string |
@@ -227,12 +227,12 @@ discard block |
||
| 227 | 227 | return $startNonHiddenStr . $hiddenStr . $endNonHiddenStr; |
| 228 | 228 | } |
| 229 | 229 | |
| 230 | - function set_session_config(){ |
|
| 230 | + function set_session_config() { |
|
| 231 | 231 | return true; |
| 232 | 232 | } |
| 233 | 233 | |
| 234 | 234 | function & get_instance(){ |
| 235 | - if(! Controller::get_instance()){ |
|
| 235 | + if (!Controller::get_instance()) { |
|
| 236 | 236 | $c = new Controller(); |
| 237 | 237 | return $c; |
| 238 | 238 | } |