@@ -224,16 +224,14 @@ discard block |
||
224 | 224 | ); |
225 | 225 | if(isset($http_status[$code])){ |
226 | 226 | $text = $http_status[$code]; |
227 | - } |
|
228 | - else{ |
|
227 | + } else{ |
|
229 | 228 | show_error('No HTTP status text found for your code please check it.'); |
230 | 229 | } |
231 | 230 | } |
232 | 231 | |
233 | 232 | if(strpos(php_sapi_name(), 'cgi') === 0){ |
234 | 233 | header('Status: ' . $code . ' ' . $text, TRUE); |
235 | - } |
|
236 | - else{ |
|
234 | + } else{ |
|
237 | 235 | $proto = isset($_SERVER['SERVER_PROTOCOL']) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.1'; |
238 | 236 | header($proto . ' ' . $code . ' ' . $text, TRUE, $code); |
239 | 237 | } |
@@ -271,11 +269,9 @@ discard block |
||
271 | 269 | */ |
272 | 270 | if(isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) !== 'off'){ |
273 | 271 | return true; |
274 | - } |
|
275 | - else if(isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https'){ |
|
272 | + } else if(isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https'){ |
|
276 | 273 | return true; |
277 | - } |
|
278 | - else if(isset($_SERVER['HTTP_FRONT_END_HTTPS']) && strtolower($_SERVER['HTTP_FRONT_END_HTTPS']) !== 'off'){ |
|
274 | + } else if(isset($_SERVER['HTTP_FRONT_END_HTTPS']) && strtolower($_SERVER['HTTP_FRONT_END_HTTPS']) !== 'off'){ |
|
279 | 275 | return true; |
280 | 276 | } |
281 | 277 | return false; |
@@ -313,8 +309,7 @@ discard block |
||
313 | 309 | function php_exception_handler($ex){ |
314 | 310 | if (str_ireplace(array('off', 'none', 'no', 'false', 'null'), '', ini_get('display_errors'))){ |
315 | 311 | show_error('An exception is occured in file '. $ex->getFile() .' at line ' . $ex->getLine() . ' raison : ' . $ex->getMessage(), 'PHP Exception #' . $ex->getCode()); |
316 | - } |
|
317 | - else{ |
|
312 | + } else{ |
|
318 | 313 | save_to_log('error', 'An exception is occured in file ' . $ex->getFile() . ' at line ' . $ex->getLine() . ' raison : ' . $ex->getMessage(), 'PHP Exception'); |
319 | 314 | } |
320 | 315 | exit(1); |
@@ -431,15 +426,13 @@ discard block |
||
431 | 426 | function clean_input($str){ |
432 | 427 | if(is_array($str)){ |
433 | 428 | $str = array_map('clean_input', $str); |
434 | - } |
|
435 | - else if(is_object($str)){ |
|
429 | + } else if(is_object($str)){ |
|
436 | 430 | $obj = $str; |
437 | 431 | foreach ($str as $var => $value) { |
438 | 432 | $obj->$var = clean_input($value); |
439 | 433 | } |
440 | 434 | $str = $obj; |
441 | - } |
|
442 | - else{ |
|
435 | + } else{ |
|
443 | 436 | $str = htmlspecialchars(strip_tags($str), ENT_QUOTES, 'UTF-8'); |
444 | 437 | } |
445 | 438 | return $str; |
@@ -510,8 +503,7 @@ discard block |
||
510 | 503 | session_save_path($sessionSavePath); |
511 | 504 | $logger->info('Session save path: ' . $sessionSavePath); |
512 | 505 | } |
513 | - } |
|
514 | - else if($sessionHandler == 'database'){ |
|
506 | + } else if($sessionHandler == 'database'){ |
|
515 | 507 | //load database session handle library |
516 | 508 | //Model |
517 | 509 | require_once CORE_CLASSES_MODEL_PATH . 'Model.php'; |
@@ -522,8 +514,7 @@ discard block |
||
522 | 514 | $DBS =& class_loader('DBSessionHandler', 'classes'); |
523 | 515 | session_set_save_handler($DBS, true); |
524 | 516 | $logger->info('session save path: ' . get_config('session_save_path')); |
525 | - } |
|
526 | - else{ |
|
517 | + } else{ |
|
527 | 518 | show_error('Invalid session handler configuration'); |
528 | 519 | } |
529 | 520 | $lifetime = get_config('session_cookie_lifetime', 0); |
@@ -22,7 +22,7 @@ discard block |
||
22 | 22 | * You should have received a copy of the GNU General Public License |
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 | 26 | |
27 | 27 | /** |
28 | 28 | * @file common.php |
@@ -438,13 +438,13 @@ discard block |
||
438 | 438 | |
439 | 439 | |
440 | 440 | /** |
441 | - * Function to stringfy PHP variable, useful in debug situation |
|
442 | - * |
|
443 | - * @param mixed $var the variable to stringfy |
|
444 | - * @codeCoverageIgnore |
|
445 | - * |
|
446 | - * @return string the stringfy value |
|
447 | - */ |
|
441 | + * Function to stringfy PHP variable, useful in debug situation |
|
442 | + * |
|
443 | + * @param mixed $var the variable to stringfy |
|
444 | + * @codeCoverageIgnore |
|
445 | + * |
|
446 | + * @return string the stringfy value |
|
447 | + */ |
|
448 | 448 | function stringfy_vars($var){ |
449 | 449 | return print_r($var, true); |
450 | 450 | } |
@@ -586,15 +586,15 @@ discard block |
||
586 | 586 | } |
587 | 587 | |
588 | 588 | /** |
589 | - * This function is very useful, it allows to recover the instance of the global controller. |
|
590 | - * Note this function always returns the address of the super instance. |
|
591 | - * For example : |
|
592 | - * $obj = & get_instance(); |
|
593 | - * |
|
594 | - * @codeCoverageIgnore |
|
595 | - * |
|
596 | - * @return object the instance of the "Controller" class |
|
597 | - */ |
|
589 | + * This function is very useful, it allows to recover the instance of the global controller. |
|
590 | + * Note this function always returns the address of the super instance. |
|
591 | + * For example : |
|
592 | + * $obj = & get_instance(); |
|
593 | + * |
|
594 | + * @codeCoverageIgnore |
|
595 | + * |
|
596 | + * @return object the instance of the "Controller" class |
|
597 | + */ |
|
598 | 598 | function & get_instance(){ |
599 | 599 | return Controller::get_instance(); |
600 | 600 | } |
@@ -53,14 +53,14 @@ discard block |
||
53 | 53 | //put the first letter of class to upper case |
54 | 54 | $class = ucfirst($class); |
55 | 55 | static $classes = array(); |
56 | - if(isset($classes[$class]) /*hack for duplicate log Logger name*/ && $class != 'Log'){ |
|
56 | + if (isset($classes[$class]) /*hack for duplicate log Logger name*/ && $class != 'Log') { |
|
57 | 57 | return $classes[$class]; |
58 | 58 | } |
59 | 59 | $found = false; |
60 | 60 | foreach (array(ROOT_PATH, CORE_PATH) as $path) { |
61 | 61 | $file = $path . $dir . '/' . $class . '.php'; |
62 | - if(file_exists($file)){ |
|
63 | - if(class_exists($class, false) == false){ |
|
62 | + if (file_exists($file)) { |
|
63 | + if (class_exists($class, false) == false) { |
|
64 | 64 | require_once $file; |
65 | 65 | } |
66 | 66 | //already found |
@@ -68,7 +68,7 @@ discard block |
||
68 | 68 | break; |
69 | 69 | } |
70 | 70 | } |
71 | - if(! $found){ |
|
71 | + if (!$found) { |
|
72 | 72 | //can't use show_error() at this time because some dependencies not yet loaded |
73 | 73 | set_http_status_header(503); |
74 | 74 | echo 'Cannot find the class [' . $class . ']'; |
@@ -78,7 +78,7 @@ discard block |
||
78 | 78 | /* |
79 | 79 | TODO use the best method to get the Log instance |
80 | 80 | */ |
81 | - if($class == 'Log'){ |
|
81 | + if ($class == 'Log') { |
|
82 | 82 | //can't use the instruction like "return new Log()" |
83 | 83 | //because we need return the reference instance of the loaded class. |
84 | 84 | $log = new Log(); |
@@ -102,7 +102,7 @@ discard block |
||
102 | 102 | */ |
103 | 103 | function & class_loaded($class = null){ |
104 | 104 | static $list = array(); |
105 | - if($class != null){ |
|
105 | + if ($class != null) { |
|
106 | 106 | $list[strtolower($class)] = $class; |
107 | 107 | } |
108 | 108 | return $list; |
@@ -117,22 +117,22 @@ discard block |
||
117 | 117 | */ |
118 | 118 | function & load_configurations(array $overwrite_values = array()){ |
119 | 119 | static $config; |
120 | - if(empty($config)){ |
|
120 | + if (empty($config)) { |
|
121 | 121 | $file = CONFIG_PATH . 'config.php'; |
122 | 122 | $found = false; |
123 | - if(file_exists($file)){ |
|
123 | + if (file_exists($file)) { |
|
124 | 124 | require_once $file; |
125 | 125 | $found = true; |
126 | 126 | } |
127 | - if(! $found){ |
|
127 | + if (!$found) { |
|
128 | 128 | set_http_status_header(503); |
129 | 129 | echo 'Unable to find the configuration file [' . $file . ']'; |
130 | 130 | exit(1); |
131 | 131 | } |
132 | 132 | |
133 | - if(! isset($config) || !is_array($config)){ |
|
133 | + if (!isset($config) || !is_array($config)) { |
|
134 | 134 | set_http_status_header(503); |
135 | - echo 'No configuration found in file [' . $file . ']'; |
|
135 | + echo 'No configuration found in file [' . $file . ']'; |
|
136 | 136 | exit(1); |
137 | 137 | } |
138 | 138 | } |
@@ -150,9 +150,9 @@ discard block |
||
150 | 150 | * |
151 | 151 | * @return mixed the config value |
152 | 152 | */ |
153 | - function get_config($key, $default = null){ |
|
153 | + function get_config($key, $default = null) { |
|
154 | 154 | static $cfg; |
155 | - if(empty($cfg)){ |
|
155 | + if (empty($cfg)) { |
|
156 | 156 | $cfg[0] = & load_configurations(); |
157 | 157 | } |
158 | 158 | return array_key_exists($key, $cfg[0]) ? $cfg[0][$key] : $default; |
@@ -166,9 +166,9 @@ discard block |
||
166 | 166 | * |
167 | 167 | * @codeCoverageIgnore |
168 | 168 | */ |
169 | - function save_to_log($level, $message, $logger = null){ |
|
170 | - $log =& class_loader('Log', 'classes'); |
|
171 | - if($logger){ |
|
169 | + function save_to_log($level, $message, $logger = null) { |
|
170 | + $log = & class_loader('Log', 'classes'); |
|
171 | + if ($logger) { |
|
172 | 172 | $log->setLogger($logger); |
173 | 173 | } |
174 | 174 | $log->writeLog($message, $level); |
@@ -181,11 +181,11 @@ discard block |
||
181 | 181 | * |
182 | 182 | * @codeCoverageIgnore |
183 | 183 | */ |
184 | - function set_http_status_header($code = 200, $text = null){ |
|
185 | - if(! $code || !is_numeric($code)){ |
|
184 | + function set_http_status_header($code = 200, $text = null) { |
|
185 | + if (!$code || !is_numeric($code)) { |
|
186 | 186 | show_error('HTTP status code must be an integer'); |
187 | 187 | } |
188 | - if(empty($text)){ |
|
188 | + if (empty($text)) { |
|
189 | 189 | $code = abs($code); |
190 | 190 | $http_status = array( |
191 | 191 | 100 => 'Continue', |
@@ -234,18 +234,18 @@ discard block |
||
234 | 234 | 504 => 'Gateway Timeout', |
235 | 235 | 505 => 'HTTP Version Not Supported', |
236 | 236 | ); |
237 | - if(isset($http_status[$code])){ |
|
237 | + if (isset($http_status[$code])) { |
|
238 | 238 | $text = $http_status[$code]; |
239 | 239 | } |
240 | - else{ |
|
240 | + else { |
|
241 | 241 | show_error('No HTTP status text found for your code please check it.'); |
242 | 242 | } |
243 | 243 | } |
244 | 244 | |
245 | - if(strpos(php_sapi_name(), 'cgi') === 0){ |
|
245 | + if (strpos(php_sapi_name(), 'cgi') === 0) { |
|
246 | 246 | header('Status: ' . $code . ' ' . $text, TRUE); |
247 | 247 | } |
248 | - else{ |
|
248 | + else { |
|
249 | 249 | $proto = isset($_SERVER['SERVER_PROTOCOL']) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.1'; |
250 | 250 | header($proto . ' ' . $code . ' ' . $text, TRUE, $code); |
251 | 251 | } |
@@ -260,12 +260,12 @@ discard block |
||
260 | 260 | * |
261 | 261 | * @codeCoverageIgnore |
262 | 262 | */ |
263 | - function show_error($msg, $title = 'error', $logging = true){ |
|
263 | + function show_error($msg, $title = 'error', $logging = true) { |
|
264 | 264 | $title = strtoupper($title); |
265 | 265 | $data['error'] = $msg; |
266 | 266 | $data['title'] = $title; |
267 | - if($logging){ |
|
268 | - save_to_log('error', '['.$title.'] '.strip_tags($msg), 'GLOBAL::ERROR'); |
|
267 | + if ($logging) { |
|
268 | + save_to_log('error', '[' . $title . '] ' . strip_tags($msg), 'GLOBAL::ERROR'); |
|
269 | 269 | } |
270 | 270 | $response = & class_loader('Response', 'classes'); |
271 | 271 | $response->sendError($data); |
@@ -279,18 +279,18 @@ discard block |
||
279 | 279 | * |
280 | 280 | * @return boolean true if the web server uses the https protocol, false if not. |
281 | 281 | */ |
282 | - function is_https(){ |
|
282 | + function is_https() { |
|
283 | 283 | /* |
284 | 284 | * some servers pass the "HTTPS" parameter in the server variable, |
285 | 285 | * if is the case, check if the value is "on", "true", "1". |
286 | 286 | */ |
287 | - if(isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) !== 'off'){ |
|
287 | + if (isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) !== 'off') { |
|
288 | 288 | return true; |
289 | 289 | } |
290 | - else if(isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https'){ |
|
290 | + else if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https') { |
|
291 | 291 | return true; |
292 | 292 | } |
293 | - else if(isset($_SERVER['HTTP_FRONT_END_HTTPS']) && strtolower($_SERVER['HTTP_FRONT_END_HTTPS']) !== 'off'){ |
|
293 | + else if (isset($_SERVER['HTTP_FRONT_END_HTTPS']) && strtolower($_SERVER['HTTP_FRONT_END_HTTPS']) !== 'off') { |
|
294 | 294 | return true; |
295 | 295 | } |
296 | 296 | return false; |
@@ -305,7 +305,7 @@ discard block |
||
305 | 305 | * |
306 | 306 | * @return boolean true if is a valid URL address or false. |
307 | 307 | */ |
308 | - function is_url($url){ |
|
308 | + function is_url($url) { |
|
309 | 309 | return preg_match('/^(http|https|ftp):\/\/(.*)/', $url); |
310 | 310 | } |
311 | 311 | |
@@ -315,8 +315,8 @@ discard block |
||
315 | 315 | * @param string $controllerClass the controller class name to be loaded |
316 | 316 | * @codeCoverageIgnore |
317 | 317 | */ |
318 | - function autoload_controller($controllerClass){ |
|
319 | - if(file_exists($path = APPS_CONTROLLER_PATH . $controllerClass . '.php')){ |
|
318 | + function autoload_controller($controllerClass) { |
|
319 | + if (file_exists($path = APPS_CONTROLLER_PATH . $controllerClass . '.php')) { |
|
320 | 320 | require_once $path; |
321 | 321 | } |
322 | 322 | } |
@@ -330,11 +330,11 @@ discard block |
||
330 | 330 | * |
331 | 331 | * @return boolean |
332 | 332 | */ |
333 | - function php_exception_handler($ex){ |
|
334 | - if (str_ireplace(array('off', 'none', 'no', 'false', 'null'), '', ini_get('display_errors'))){ |
|
335 | - show_error('An exception is occured in file '. $ex->getFile() .' at line ' . $ex->getLine() . ' raison : ' . $ex->getMessage(), 'PHP Exception #' . $ex->getCode()); |
|
333 | + function php_exception_handler($ex) { |
|
334 | + if (str_ireplace(array('off', 'none', 'no', 'false', 'null'), '', ini_get('display_errors'))) { |
|
335 | + show_error('An exception is occured in file ' . $ex->getFile() . ' at line ' . $ex->getLine() . ' raison : ' . $ex->getMessage(), 'PHP Exception #' . $ex->getCode()); |
|
336 | 336 | } |
337 | - else{ |
|
337 | + else { |
|
338 | 338 | save_to_log('error', 'An exception is occured in file ' . $ex->getFile() . ' at line ' . $ex->getLine() . ' raison : ' . $ex->getMessage(), 'PHP Exception'); |
339 | 339 | } |
340 | 340 | exit(1); |
@@ -353,16 +353,16 @@ discard block |
||
353 | 353 | * |
354 | 354 | * @return boolean |
355 | 355 | */ |
356 | - function php_error_handler($errno , $errstr, $errfile , $errline, array $errcontext = array()){ |
|
356 | + function php_error_handler($errno, $errstr, $errfile, $errline, array $errcontext = array()) { |
|
357 | 357 | $isError = (((E_ERROR | E_COMPILE_ERROR | E_CORE_ERROR | E_USER_ERROR) & $errno) === $errno); |
358 | - if($isError){ |
|
358 | + if ($isError) { |
|
359 | 359 | set_http_status_header(500); |
360 | 360 | } |
361 | - if (! (error_reporting() & $errno)) { |
|
361 | + if (!(error_reporting() & $errno)) { |
|
362 | 362 | save_to_log('error', 'An error is occurred in the file ' . $errfile . ' at line ' . $errline . ' raison : ' . $errstr, 'PHP ' . $error_type, 'PHP ERROR'); |
363 | 363 | return; |
364 | 364 | } |
365 | - if (str_ireplace(array('off', 'none', 'no', 'false', 'null'), '', ini_get('display_errors'))){ |
|
365 | + if (str_ireplace(array('off', 'none', 'no', 'false', 'null'), '', ini_get('display_errors'))) { |
|
366 | 366 | $errorType = 'error'; |
367 | 367 | switch ($errno) { |
368 | 368 | case E_USER_ERROR: |
@@ -378,9 +378,9 @@ discard block |
||
378 | 378 | $errorType = 'error'; |
379 | 379 | break; |
380 | 380 | } |
381 | - show_error('An error is occurred in the file <b>' . $errfile . '</b> at line <b>' . $errline .'</b> raison : ' . $errstr, 'PHP ' . $errorType); |
|
381 | + show_error('An error is occurred in the file <b>' . $errfile . '</b> at line <b>' . $errline . '</b> raison : ' . $errstr, 'PHP ' . $errorType); |
|
382 | 382 | } |
383 | - if ($isError){ |
|
383 | + if ($isError) { |
|
384 | 384 | exit(1); |
385 | 385 | } |
386 | 386 | return true; |
@@ -390,10 +390,10 @@ discard block |
||
390 | 390 | * This function is used to run in shutdown situation of the script |
391 | 391 | * @codeCoverageIgnore |
392 | 392 | */ |
393 | - function php_shudown_handler(){ |
|
393 | + function php_shudown_handler() { |
|
394 | 394 | $lastError = error_get_last(); |
395 | 395 | if (isset($lastError) && |
396 | - ($lastError['type'] & (E_ERROR | E_PARSE | E_CORE_ERROR | E_CORE_WARNING | E_COMPILE_ERROR | E_COMPILE_WARNING))){ |
|
396 | + ($lastError['type'] & (E_ERROR | E_PARSE | E_CORE_ERROR | E_CORE_WARNING | E_COMPILE_ERROR | E_COMPILE_WARNING))) { |
|
397 | 397 | php_error_handler($lastError['type'], $lastError['message'], $lastError['file'], $lastError['line']); |
398 | 398 | } |
399 | 399 | } |
@@ -412,11 +412,11 @@ discard block |
||
412 | 412 | * |
413 | 413 | * @return string string of the HTML attribute. |
414 | 414 | */ |
415 | - function attributes_to_string(array $attributes){ |
|
415 | + function attributes_to_string(array $attributes) { |
|
416 | 416 | $str = ' '; |
417 | 417 | //we check that the array passed as an argument is not empty. |
418 | - if(! empty($attributes)){ |
|
419 | - foreach($attributes as $key => $value){ |
|
418 | + if (!empty($attributes)) { |
|
419 | + foreach ($attributes as $key => $value) { |
|
420 | 420 | $key = trim(htmlspecialchars($key)); |
421 | 421 | $value = trim(htmlspecialchars($value)); |
422 | 422 | /* |
@@ -426,10 +426,10 @@ discard block |
||
426 | 426 | * $attr = array('placeholder' => 'I am a "puple"') |
427 | 427 | * $str = attributes_to_string($attr); => placeholder = "I am a \"puple\"" |
428 | 428 | */ |
429 | - if($value && strpos('"', $value) !== false){ |
|
429 | + if ($value && strpos('"', $value) !== false) { |
|
430 | 430 | $value = addslashes($value); |
431 | 431 | } |
432 | - $str .= $key.' = "'.$value.'" '; |
|
432 | + $str .= $key . ' = "' . $value . '" '; |
|
433 | 433 | } |
434 | 434 | } |
435 | 435 | //remove the space after using rtrim() |
@@ -445,7 +445,7 @@ discard block |
||
445 | 445 | * |
446 | 446 | * @return string the stringfy value |
447 | 447 | */ |
448 | - function stringfy_vars($var){ |
|
448 | + function stringfy_vars($var) { |
|
449 | 449 | return print_r($var, true); |
450 | 450 | } |
451 | 451 | |
@@ -456,18 +456,18 @@ discard block |
||
456 | 456 | * |
457 | 457 | * @return mixed the sanitize value |
458 | 458 | */ |
459 | - function clean_input($str){ |
|
460 | - if(is_array($str)){ |
|
459 | + function clean_input($str) { |
|
460 | + if (is_array($str)) { |
|
461 | 461 | $str = array_map('clean_input', $str); |
462 | 462 | } |
463 | - else if(is_object($str)){ |
|
463 | + else if (is_object($str)) { |
|
464 | 464 | $obj = $str; |
465 | 465 | foreach ($str as $var => $value) { |
466 | 466 | $obj->$var = clean_input($value); |
467 | 467 | } |
468 | 468 | $str = $obj; |
469 | 469 | } |
470 | - else{ |
|
470 | + else { |
|
471 | 471 | $str = htmlspecialchars(strip_tags($str), ENT_QUOTES, 'UTF-8'); |
472 | 472 | } |
473 | 473 | return $str; |
@@ -485,11 +485,11 @@ discard block |
||
485 | 485 | * |
486 | 486 | * @return string the string with the hidden part. |
487 | 487 | */ |
488 | - function string_hidden($str, $startCount = 0, $endCount = 0, $hiddenChar = '*'){ |
|
488 | + function string_hidden($str, $startCount = 0, $endCount = 0, $hiddenChar = '*') { |
|
489 | 489 | //get the string length |
490 | 490 | $len = strlen($str); |
491 | 491 | //if str is empty |
492 | - if($len <= 0){ |
|
492 | + if ($len <= 0) { |
|
493 | 493 | return str_repeat($hiddenChar, 6); |
494 | 494 | } |
495 | 495 | //if the length is less than startCount and endCount |
@@ -497,14 +497,14 @@ discard block |
||
497 | 497 | //or startCount is negative or endCount is negative |
498 | 498 | //return the full string hidden |
499 | 499 | |
500 | - if((($startCount + $endCount) > $len) || ($startCount == 0 && $endCount == 0) || ($startCount < 0 || $endCount < 0)){ |
|
500 | + if ((($startCount + $endCount) > $len) || ($startCount == 0 && $endCount == 0) || ($startCount < 0 || $endCount < 0)) { |
|
501 | 501 | return str_repeat($hiddenChar, $len); |
502 | 502 | } |
503 | 503 | //the start non hidden string |
504 | 504 | $startNonHiddenStr = substr($str, 0, $startCount); |
505 | 505 | //the end non hidden string |
506 | 506 | $endNonHiddenStr = null; |
507 | - if($endCount > 0){ |
|
507 | + if ($endCount > 0) { |
|
508 | 508 | $endNonHiddenStr = substr($str, - $endCount); |
509 | 509 | } |
510 | 510 | //the hidden string |
@@ -517,31 +517,31 @@ discard block |
||
517 | 517 | * This function is used to set the initial session config regarding the configuration |
518 | 518 | * @codeCoverageIgnore |
519 | 519 | */ |
520 | - function set_session_config(){ |
|
520 | + function set_session_config() { |
|
521 | 521 | //$_SESSION is not available on cli mode |
522 | - if(! IS_CLI){ |
|
523 | - $logger =& class_loader('Log', 'classes'); |
|
522 | + if (!IS_CLI) { |
|
523 | + $logger = & class_loader('Log', 'classes'); |
|
524 | 524 | $logger->setLogger('PHPSession'); |
525 | 525 | //set session params |
526 | 526 | $sessionHandler = get_config('session_handler', 'files'); //the default is to store in the files |
527 | 527 | $sessionName = get_config('session_name'); |
528 | - if($sessionName){ |
|
528 | + if ($sessionName) { |
|
529 | 529 | session_name($sessionName); |
530 | 530 | } |
531 | 531 | $logger->info('Session handler: ' . $sessionHandler); |
532 | 532 | $logger->info('Session name: ' . $sessionName); |
533 | 533 | |
534 | - if($sessionHandler == 'files'){ |
|
534 | + if ($sessionHandler == 'files') { |
|
535 | 535 | $sessionSavePath = get_config('session_save_path'); |
536 | - if($sessionSavePath){ |
|
537 | - if(! is_dir($sessionSavePath)){ |
|
536 | + if ($sessionSavePath) { |
|
537 | + if (!is_dir($sessionSavePath)) { |
|
538 | 538 | mkdir($sessionSavePath, 1773); |
539 | 539 | } |
540 | 540 | session_save_path($sessionSavePath); |
541 | 541 | $logger->info('Session save path: ' . $sessionSavePath); |
542 | 542 | } |
543 | 543 | } |
544 | - else if($sessionHandler == 'database'){ |
|
544 | + else if ($sessionHandler == 'database') { |
|
545 | 545 | //load database session handle library |
546 | 546 | //Model |
547 | 547 | require_once CORE_CLASSES_MODEL_PATH . 'Model.php'; |
@@ -549,11 +549,11 @@ discard block |
||
549 | 549 | //Database Session handler Model |
550 | 550 | require_once CORE_CLASSES_MODEL_PATH . 'DBSessionHandlerModel.php'; |
551 | 551 | |
552 | - $DBS =& class_loader('DBSessionHandler', 'classes'); |
|
552 | + $DBS = & class_loader('DBSessionHandler', 'classes'); |
|
553 | 553 | session_set_save_handler($DBS, true); |
554 | 554 | $logger->info('session save path: ' . get_config('session_save_path')); |
555 | 555 | } |
556 | - else{ |
|
556 | + else { |
|
557 | 557 | show_error('Invalid session handler configuration'); |
558 | 558 | } |
559 | 559 | $lifetime = get_config('session_cookie_lifetime', 0); |
@@ -576,9 +576,9 @@ discard block |
||
576 | 576 | $logger->info('Session lifetime: ' . $lifetime); |
577 | 577 | $logger->info('Session cookie path: ' . $path); |
578 | 578 | $logger->info('Session domain: ' . $domain); |
579 | - $logger->info('Session is secure: ' . ($secure ? 'TRUE':'FALSE')); |
|
579 | + $logger->info('Session is secure: ' . ($secure ? 'TRUE' : 'FALSE')); |
|
580 | 580 | |
581 | - if((function_exists('session_status') && session_status() !== PHP_SESSION_ACTIVE) || !session_id()){ |
|
581 | + if ((function_exists('session_status') && session_status() !== PHP_SESSION_ACTIVE) || !session_id()) { |
|
582 | 582 | $logger->info('Session not yet start, start it now'); |
583 | 583 | session_start(); |
584 | 584 | } |
@@ -1,24 +1,24 @@ |
||
1 | 1 | <?php |
2 | - defined('ROOT_PATH') || exit('Access denied'); |
|
2 | + defined('ROOT_PATH') || exit('Access denied'); |
|
3 | 3 | /** |
4 | 4 | * Form validation language message (English) |
5 | 5 | */ |
6 | 6 | $lang['fv_required'] = 'Field %1 is required.'; |
7 | - $lang['fv_min_length'] = 'Field %1 must contain at least %2 characters.'; |
|
8 | - $lang['fv_max_length'] = 'Field %1 must contain at most %2 characters.'; |
|
9 | - $lang['fv_exact_length'] = 'Field %1 must contain exactly %2 characters.'; |
|
10 | - $lang['fv_less_than'] = 'Field %1 must less than %2.'; |
|
11 | - $lang['fv_greater_than'] = 'Field %1 must greater than %2.'; |
|
12 | - $lang['fv_matches'] = 'Field %1 must be identical to field %2.'; |
|
13 | - $lang['fv_valid_email'] = 'Field %1 must contain a valid E-mail address.'; |
|
14 | - $lang['fv_not_equal_post_key'] = 'Field %1 must not be the same as field %2.'; |
|
15 | - $lang['fv_not_equal_string'] = 'Field %1 must not contain the value %2.'; |
|
16 | - $lang['fv_depends'] = 'Field %1 depends on field %2 which is not valid.'; |
|
7 | + $lang['fv_min_length'] = 'Field %1 must contain at least %2 characters.'; |
|
8 | + $lang['fv_max_length'] = 'Field %1 must contain at most %2 characters.'; |
|
9 | + $lang['fv_exact_length'] = 'Field %1 must contain exactly %2 characters.'; |
|
10 | + $lang['fv_less_than'] = 'Field %1 must less than %2.'; |
|
11 | + $lang['fv_greater_than'] = 'Field %1 must greater than %2.'; |
|
12 | + $lang['fv_matches'] = 'Field %1 must be identical to field %2.'; |
|
13 | + $lang['fv_valid_email'] = 'Field %1 must contain a valid E-mail address.'; |
|
14 | + $lang['fv_not_equal_post_key'] = 'Field %1 must not be the same as field %2.'; |
|
15 | + $lang['fv_not_equal_string'] = 'Field %1 must not contain the value %2.'; |
|
16 | + $lang['fv_depends'] = 'Field %1 depends on field %2 which is not valid.'; |
|
17 | 17 | $lang['fv_is_unique'] = 'The value of field %1 already exists.'; |
18 | 18 | $lang['fv_is_unique_update'] = 'The value of field %1 already exists for another record.'; |
19 | - $lang['fv_exists'] = 'The value of the field %1 does not exist.'; |
|
20 | - $lang['fv_regex'] = 'The value of the field %1 does not use the correct format.'; |
|
21 | - $lang['fv_in_list'] = 'The value of field %1 must be one of the list (%2).'; |
|
22 | - $lang['fv_numeric'] = 'The value of field %1 must be a number.'; |
|
23 | - $lang['fv_callback'] = 'The value of field %1 is not valid.'; |
|
19 | + $lang['fv_exists'] = 'The value of the field %1 does not exist.'; |
|
20 | + $lang['fv_regex'] = 'The value of the field %1 does not use the correct format.'; |
|
21 | + $lang['fv_in_list'] = 'The value of field %1 must be one of the list (%2).'; |
|
22 | + $lang['fv_numeric'] = 'The value of field %1 must be a number.'; |
|
23 | + $lang['fv_callback'] = 'The value of field %1 is not valid.'; |
|
24 | 24 |
@@ -3,11 +3,11 @@ discard block |
||
3 | 3 | /** |
4 | 4 | * Form validation language message (English) |
5 | 5 | */ |
6 | - $lang['fv_required'] = 'Field %1 is required.'; |
|
6 | + $lang['fv_required'] = 'Field %1 is required.'; |
|
7 | 7 | $lang['fv_min_length'] = 'Field %1 must contain at least %2 characters.'; |
8 | 8 | $lang['fv_max_length'] = 'Field %1 must contain at most %2 characters.'; |
9 | 9 | $lang['fv_exact_length'] = 'Field %1 must contain exactly %2 characters.'; |
10 | - $lang['fv_less_than'] = 'Field %1 must less than %2.'; |
|
10 | + $lang['fv_less_than'] = 'Field %1 must less than %2.'; |
|
11 | 11 | $lang['fv_greater_than'] = 'Field %1 must greater than %2.'; |
12 | 12 | $lang['fv_matches'] = 'Field %1 must be identical to field %2.'; |
13 | 13 | $lang['fv_valid_email'] = 'Field %1 must contain a valid E-mail address.'; |
@@ -16,7 +16,7 @@ discard block |
||
16 | 16 | $lang['fv_depends'] = 'Field %1 depends on field %2 which is not valid.'; |
17 | 17 | $lang['fv_is_unique'] = 'The value of field %1 already exists.'; |
18 | 18 | $lang['fv_is_unique_update'] = 'The value of field %1 already exists for another record.'; |
19 | - $lang['fv_exists'] = 'The value of the field %1 does not exist.'; |
|
19 | + $lang['fv_exists'] = 'The value of the field %1 does not exist.'; |
|
20 | 20 | $lang['fv_regex'] = 'The value of the field %1 does not use the correct format.'; |
21 | 21 | $lang['fv_in_list'] = 'The value of field %1 must be one of the list (%2).'; |
22 | 22 | $lang['fv_numeric'] = 'The value of field %1 must be a number.'; |
@@ -1,17 +1,17 @@ |
||
1 | 1 | <?php |
2 | - defined('ROOT_PATH') || exit('Access denied'); |
|
2 | + defined('ROOT_PATH') || exit('Access denied'); |
|
3 | 3 | /** |
4 | 4 | * File upload language messages (English) |
5 | 5 | */ |
6 | 6 | $lang['fu_upload_err_ini_size'] = 'The uploaded file exceeds the upload_max_filesize directive in php.ini.'; |
7 | - $lang['fu_upload_err_form_size'] = 'The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form.'; |
|
8 | - $lang['fu_upload_err_partial'] = 'The uploaded file was only partially uploaded.'; |
|
9 | - $lang['fu_upload_err_no_file'] = 'No file was choosed. Please select one.'; |
|
10 | - $lang['fu_upload_err_no_tmp_dir'] = 'Missing a temporary folder.'; |
|
11 | - $lang['fu_upload_err_cant_write'] = 'Failed to write file to disk.'; |
|
12 | - $lang['fu_upload_err_extension'] = 'A PHP extension stopped the file upload.'; |
|
13 | - $lang['fu_accept_file_types'] = 'Filetype not allowed'; |
|
14 | - $lang['fu_file_uploads_disabled'] = 'File uploading option is disabled in php.ini'; |
|
15 | - $lang['fu_max_file_size'] = 'The uploaded file size is too big max size is %s'; |
|
16 | - $lang['fu_overwritten_not_allowed'] = 'You don\'t allow overwriting existing file'; |
|
7 | + $lang['fu_upload_err_form_size'] = 'The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form.'; |
|
8 | + $lang['fu_upload_err_partial'] = 'The uploaded file was only partially uploaded.'; |
|
9 | + $lang['fu_upload_err_no_file'] = 'No file was choosed. Please select one.'; |
|
10 | + $lang['fu_upload_err_no_tmp_dir'] = 'Missing a temporary folder.'; |
|
11 | + $lang['fu_upload_err_cant_write'] = 'Failed to write file to disk.'; |
|
12 | + $lang['fu_upload_err_extension'] = 'A PHP extension stopped the file upload.'; |
|
13 | + $lang['fu_accept_file_types'] = 'Filetype not allowed'; |
|
14 | + $lang['fu_file_uploads_disabled'] = 'File uploading option is disabled in php.ini'; |
|
15 | + $lang['fu_max_file_size'] = 'The uploaded file size is too big max size is %s'; |
|
16 | + $lang['fu_overwritten_not_allowed'] = 'You don\'t allow overwriting existing file'; |
|
17 | 17 |
@@ -6,11 +6,11 @@ |
||
6 | 6 | $lang['fu_upload_err_ini_size'] = 'The uploaded file exceeds the upload_max_filesize directive in php.ini.'; |
7 | 7 | $lang['fu_upload_err_form_size'] = 'The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form.'; |
8 | 8 | $lang['fu_upload_err_partial'] = 'The uploaded file was only partially uploaded.'; |
9 | - $lang['fu_upload_err_no_file'] = 'No file was choosed. Please select one.'; |
|
9 | + $lang['fu_upload_err_no_file'] = 'No file was choosed. Please select one.'; |
|
10 | 10 | $lang['fu_upload_err_no_tmp_dir'] = 'Missing a temporary folder.'; |
11 | - $lang['fu_upload_err_cant_write'] = 'Failed to write file to disk.'; |
|
11 | + $lang['fu_upload_err_cant_write'] = 'Failed to write file to disk.'; |
|
12 | 12 | $lang['fu_upload_err_extension'] = 'A PHP extension stopped the file upload.'; |
13 | - $lang['fu_accept_file_types'] = 'Filetype not allowed'; |
|
13 | + $lang['fu_accept_file_types'] = 'Filetype not allowed'; |
|
14 | 14 | $lang['fu_file_uploads_disabled'] = 'File uploading option is disabled in php.ini'; |
15 | 15 | $lang['fu_max_file_size'] = 'The uploaded file size is too big max size is %s'; |
16 | 16 | $lang['fu_overwritten_not_allowed'] = 'You don\'t allow overwriting existing file'; |
@@ -22,7 +22,7 @@ |
||
22 | 22 | * You should have received a copy of the GNU General Public License |
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 | 26 | |
27 | 27 | /** |
28 | 28 | * @file constants.php |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | //Autoload function |
3 | - function test_autoload($class){ |
|
3 | + function test_autoload($class) { |
|
4 | 4 | $classesMap = array( |
5 | 5 | //Caches |
6 | 6 | 'ApcCache' => CORE_CLASSES_CACHE_PATH . 'ApcCache.php', |
@@ -39,11 +39,11 @@ discard block |
||
39 | 39 | 'StringHash' => CORE_LIBRARY_PATH . 'StringHash.php', |
40 | 40 | 'Upload' => CORE_LIBRARY_PATH . 'Upload.php', |
41 | 41 | ); |
42 | - if(isset($classesMap[$class])){ |
|
43 | - if(file_exists($classesMap[$class])){ |
|
42 | + if (isset($classesMap[$class])) { |
|
43 | + if (file_exists($classesMap[$class])) { |
|
44 | 44 | include_once $classesMap[$class]; |
45 | 45 | } |
46 | - else{ |
|
46 | + else { |
|
47 | 47 | echo 'File for class ' . $class . ' not found'; |
48 | 48 | } |
49 | 49 | } |
@@ -42,8 +42,7 @@ |
||
42 | 42 | if(isset($classesMap[$class])){ |
43 | 43 | if(file_exists($classesMap[$class])){ |
44 | 44 | include_once $classesMap[$class]; |
45 | - } |
|
46 | - else{ |
|
45 | + } else{ |
|
47 | 46 | echo 'File for class ' . $class . ' not found'; |
48 | 47 | } |
49 | 48 | } |
@@ -22,7 +22,7 @@ discard block |
||
22 | 22 | * You should have received a copy of the GNU General Public License |
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 | 26 | |
27 | 27 | |
28 | 28 | function & class_loader($class, $dir = 'libraries', $params = null){ |
@@ -92,8 +92,8 @@ discard block |
||
92 | 92 | } |
93 | 93 | |
94 | 94 | /** |
95 | - * @test |
|
96 | - */ |
|
95 | + * @test |
|
96 | + */ |
|
97 | 97 | function get_config($key, $default = null){ |
98 | 98 | static $cfg; |
99 | 99 | if(empty($cfg)){ |
@@ -121,8 +121,8 @@ discard block |
||
121 | 121 | } |
122 | 122 | |
123 | 123 | /** |
124 | - * @test |
|
125 | - */ |
|
124 | + * @test |
|
125 | + */ |
|
126 | 126 | function is_url($url){ |
127 | 127 | return preg_match('/^(http|https|ftp):\/\/(.*)/', $url); |
128 | 128 | } |
@@ -142,8 +142,8 @@ discard block |
||
142 | 142 | |
143 | 143 | |
144 | 144 | /** |
145 | - * @test |
|
146 | - */ |
|
145 | + * @test |
|
146 | + */ |
|
147 | 147 | function attributes_to_string(array $attributes){ |
148 | 148 | $str = ' '; |
149 | 149 | //we check that the array passed as an argument is not empty. |
@@ -173,8 +173,8 @@ discard block |
||
173 | 173 | } |
174 | 174 | |
175 | 175 | /** |
176 | - * @test |
|
177 | - */ |
|
176 | + * @test |
|
177 | + */ |
|
178 | 178 | function clean_input($str){ |
179 | 179 | if(is_array($str)){ |
180 | 180 | $str = array_map('clean_input', $str); |
@@ -193,8 +193,8 @@ discard block |
||
193 | 193 | } |
194 | 194 | |
195 | 195 | /** |
196 | - * @test |
|
197 | - */ |
|
196 | + * @test |
|
197 | + */ |
|
198 | 198 | function string_hidden($str, $startCount = 0, $endCount = 0, $hiddenChar = '*'){ |
199 | 199 | //get the string length |
200 | 200 | $len = strlen($str); |
@@ -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,49 +94,49 @@ 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){ |
|
105 | + function save_to_log($level, $message, $logger = null) { |
|
106 | 106 | return true; |
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 | return true; |
112 | 112 | } |
113 | 113 | |
114 | 114 | |
115 | - function show_error($msg, $title = 'error', $logging = true){ |
|
115 | + function show_error($msg, $title = 'error', $logging = true) { |
|
116 | 116 | //throw new RuntimeException('TNHFW Error: '.$msg); |
117 | 117 | } |
118 | 118 | |
119 | - function is_https(){ |
|
119 | + function is_https() { |
|
120 | 120 | return false; |
121 | 121 | } |
122 | 122 | |
123 | 123 | /** |
124 | 124 | * @test |
125 | 125 | */ |
126 | - function is_url($url){ |
|
126 | + function is_url($url) { |
|
127 | 127 | return preg_match('/^(http|https|ftp):\/\/(.*)/', $url); |
128 | 128 | } |
129 | 129 | |
130 | - function php_exception_handler($ex){ |
|
131 | - throw new RuntimeException('PHP Exception : '.$ex->getMessage().' | '.$ex->getFile().' | '.$ex->getLine()); |
|
130 | + function php_exception_handler($ex) { |
|
131 | + throw new RuntimeException('PHP Exception : ' . $ex->getMessage() . ' | ' . $ex->getFile() . ' | ' . $ex->getLine()); |
|
132 | 132 | } |
133 | 133 | |
134 | 134 | |
135 | - function php_error_handler($errno , $errstr, $errfile , $errline, array $errcontext = array()){ |
|
136 | - throw new RuntimeException('TNHFW Exception Error : '.$errstr.' | '.$errfile.' | '.$errline); |
|
135 | + function php_error_handler($errno, $errstr, $errfile, $errline, array $errcontext = array()) { |
|
136 | + throw new RuntimeException('TNHFW Exception Error : ' . $errstr . ' | ' . $errfile . ' | ' . $errline); |
|
137 | 137 | } |
138 | 138 | |
139 | - function php_shudown_handler(){ |
|
139 | + function php_shudown_handler() { |
|
140 | 140 | return true; |
141 | 141 | } |
142 | 142 | |
@@ -144,11 +144,11 @@ discard block |
||
144 | 144 | /** |
145 | 145 | * @test |
146 | 146 | */ |
147 | - function attributes_to_string(array $attributes){ |
|
147 | + function attributes_to_string(array $attributes) { |
|
148 | 148 | $str = ' '; |
149 | 149 | //we check that the array passed as an argument is not empty. |
150 | - if(! empty($attributes)){ |
|
151 | - foreach($attributes as $key => $value){ |
|
150 | + if (!empty($attributes)) { |
|
151 | + foreach ($attributes as $key => $value) { |
|
152 | 152 | $key = trim(htmlspecialchars($key)); |
153 | 153 | $value = trim(htmlspecialchars($value)); |
154 | 154 | /* |
@@ -158,35 +158,35 @@ discard block |
||
158 | 158 | * $attr = array('placeholder' => 'I am a "puple"') |
159 | 159 | * $str = attributes_to_string($attr); => placeholder = "I am a \"puple\"" |
160 | 160 | */ |
161 | - if($value && strpos('"', $value) !== false){ |
|
161 | + if ($value && strpos('"', $value) !== false) { |
|
162 | 162 | $value = addslashes($value); |
163 | 163 | } |
164 | - $str .= $key.' = "'.$value.'" '; |
|
164 | + $str .= $key . ' = "' . $value . '" '; |
|
165 | 165 | } |
166 | 166 | } |
167 | 167 | //remove the space after using rtrim() |
168 | 168 | return rtrim($str); |
169 | 169 | } |
170 | 170 | |
171 | - function stringfy_vars($var){ |
|
171 | + function stringfy_vars($var) { |
|
172 | 172 | return print_r($var, true); |
173 | 173 | } |
174 | 174 | |
175 | 175 | /** |
176 | 176 | * @test |
177 | 177 | */ |
178 | - function clean_input($str){ |
|
179 | - if(is_array($str)){ |
|
178 | + function clean_input($str) { |
|
179 | + if (is_array($str)) { |
|
180 | 180 | $str = array_map('clean_input', $str); |
181 | 181 | } |
182 | - else if(is_object($str)){ |
|
182 | + else if (is_object($str)) { |
|
183 | 183 | $obj = $str; |
184 | 184 | foreach ($str as $var => $value) { |
185 | 185 | $obj->$var = clean_input($value); |
186 | 186 | } |
187 | 187 | $str = $obj; |
188 | 188 | } |
189 | - else{ |
|
189 | + else { |
|
190 | 190 | $str = htmlspecialchars(strip_tags($str), ENT_QUOTES, 'UTF-8'); |
191 | 191 | } |
192 | 192 | return $str; |
@@ -195,11 +195,11 @@ discard block |
||
195 | 195 | /** |
196 | 196 | * @test |
197 | 197 | */ |
198 | - function string_hidden($str, $startCount = 0, $endCount = 0, $hiddenChar = '*'){ |
|
198 | + function string_hidden($str, $startCount = 0, $endCount = 0, $hiddenChar = '*') { |
|
199 | 199 | //get the string length |
200 | 200 | $len = strlen($str); |
201 | 201 | //if str is empty |
202 | - if($len <= 0){ |
|
202 | + if ($len <= 0) { |
|
203 | 203 | return str_repeat($hiddenChar, 6); |
204 | 204 | } |
205 | 205 | //if the length is less than startCount and endCount |
@@ -207,14 +207,14 @@ discard block |
||
207 | 207 | //or startCount is negative or endCount is negative |
208 | 208 | //return the full string hidden |
209 | 209 | |
210 | - if((($startCount + $endCount) > $len) || ($startCount == 0 && $endCount == 0) || ($startCount < 0 || $endCount < 0)){ |
|
210 | + if ((($startCount + $endCount) > $len) || ($startCount == 0 && $endCount == 0) || ($startCount < 0 || $endCount < 0)) { |
|
211 | 211 | return str_repeat($hiddenChar, $len); |
212 | 212 | } |
213 | 213 | //the start non hidden string |
214 | 214 | $startNonHiddenStr = substr($str, 0, $startCount); |
215 | 215 | //the end non hidden string |
216 | 216 | $endNonHiddenStr = null; |
217 | - if($endCount > 0){ |
|
217 | + if ($endCount > 0) { |
|
218 | 218 | $endNonHiddenStr = substr($str, - $endCount); |
219 | 219 | } |
220 | 220 | //the hidden string |
@@ -223,12 +223,12 @@ discard block |
||
223 | 223 | return $startNonHiddenStr . $hiddenStr . $endNonHiddenStr; |
224 | 224 | } |
225 | 225 | |
226 | - function set_session_config(){ |
|
226 | + function set_session_config() { |
|
227 | 227 | return true; |
228 | 228 | } |
229 | 229 | |
230 | 230 | function & get_instance(){ |
231 | - if(! Controller::get_instance()){ |
|
231 | + if (!Controller::get_instance()) { |
|
232 | 232 | $c = new Controller(); |
233 | 233 | } |
234 | 234 | return Controller::get_instance(); |
@@ -178,15 +178,13 @@ |
||
178 | 178 | function clean_input($str){ |
179 | 179 | if(is_array($str)){ |
180 | 180 | $str = array_map('clean_input', $str); |
181 | - } |
|
182 | - else if(is_object($str)){ |
|
181 | + } else if(is_object($str)){ |
|
183 | 182 | $obj = $str; |
184 | 183 | foreach ($str as $var => $value) { |
185 | 184 | $obj->$var = clean_input($value); |
186 | 185 | } |
187 | 186 | $str = $obj; |
188 | - } |
|
189 | - else{ |
|
187 | + } else{ |
|
190 | 188 | $str = htmlspecialchars(strip_tags($str), ENT_QUOTES, 'UTF-8'); |
191 | 189 | } |
192 | 190 | return $str; |
@@ -1,8 +1,8 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | 3 | /** |
4 | - * Function to test private & protected method |
|
5 | - */ |
|
4 | + * Function to test private & protected method |
|
5 | + */ |
|
6 | 6 | function runPrivateOrProtectedMethod($object, $method, array $args = array()){ |
7 | 7 | $r = new ReflectionClass(get_class($object)); |
8 | 8 | $m = $r->getMethod($method); |
@@ -3,7 +3,7 @@ |
||
3 | 3 | /** |
4 | 4 | * Function to test private & protected method |
5 | 5 | */ |
6 | - function runPrivateOrProtectedMethod($object, $method, array $args = array()){ |
|
6 | + function runPrivateOrProtectedMethod($object, $method, array $args = array()) { |
|
7 | 7 | $r = new ReflectionClass(get_class($object)); |
8 | 8 | $m = $r->getMethod($method); |
9 | 9 | $m->setAccessible(true); |
@@ -3,66 +3,66 @@ discard block |
||
3 | 3 | class FormValidationTest extends TestCase |
4 | 4 | { |
5 | 5 | public static function setUpBeforeClass() |
6 | - { |
|
6 | + { |
|
7 | 7 | |
8 | - } |
|
8 | + } |
|
9 | 9 | |
10 | 10 | public static function tearDownAfterClass() |
11 | - { |
|
11 | + { |
|
12 | 12 | |
13 | - } |
|
13 | + } |
|
14 | 14 | |
15 | - protected function setUp() |
|
16 | - { |
|
15 | + protected function setUp() |
|
16 | + { |
|
17 | 17 | |
18 | - } |
|
18 | + } |
|
19 | 19 | |
20 | - protected function tearDown() |
|
21 | - { |
|
20 | + protected function tearDown() |
|
21 | + { |
|
22 | 22 | |
23 | - } |
|
23 | + } |
|
24 | 24 | |
25 | 25 | |
26 | 26 | |
27 | - // tests |
|
28 | - public function testValidationDataIsEmpty() |
|
29 | - { |
|
27 | + // tests |
|
28 | + public function testValidationDataIsEmpty() |
|
29 | + { |
|
30 | 30 | $fv = new FormValidation(); |
31 | 31 | $this->assertEmpty($fv->getData()); |
32 | - } |
|
32 | + } |
|
33 | 33 | |
34 | 34 | public function testValidationDataIsNotEmpty() |
35 | - { |
|
35 | + { |
|
36 | 36 | $fv = new FormValidation(); |
37 | 37 | $fv->setData(array('name' => 'mike')); |
38 | 38 | $this->assertNotEmpty($fv->getData()); |
39 | 39 | $this->assertArrayHasKey('name', $fv->getData()); |
40 | - } |
|
40 | + } |
|
41 | 41 | |
42 | 42 | public function testCannotDoValidation() |
43 | - { |
|
43 | + { |
|
44 | 44 | $fv = new FormValidation(); |
45 | 45 | $this->assertFalse($fv->canDoValidation()); |
46 | - } |
|
46 | + } |
|
47 | 47 | |
48 | 48 | public function testSettingErrorDelimiter() |
49 | - { |
|
49 | + { |
|
50 | 50 | $fv = new FormValidation(); |
51 | 51 | $fv->setErrorDelimiter('<a>', '</b>'); |
52 | 52 | $this->assertContains('<a>', $fv->getErrorDelimiter()); |
53 | 53 | $this->assertContains('</b>', $fv->getErrorDelimiter()); |
54 | - } |
|
54 | + } |
|
55 | 55 | |
56 | 56 | public function testSettingErrorsDelimiter() |
57 | - { |
|
57 | + { |
|
58 | 58 | $fv = new FormValidation(); |
59 | 59 | $fv->setErrorsDelimiter('<foo>', '</bar>'); |
60 | 60 | $this->assertContains('<foo>', $fv->getErrorsDelimiter()); |
61 | 61 | $this->assertContains('</bar>', $fv->getErrorsDelimiter()); |
62 | - } |
|
62 | + } |
|
63 | 63 | |
64 | 64 | public function testSettingErrorMessageOverride() |
65 | - { |
|
65 | + { |
|
66 | 66 | |
67 | 67 | //field specific message for the rule |
68 | 68 | $fv = new FormValidation(); |
@@ -82,10 +82,10 @@ discard block |
||
82 | 82 | |
83 | 83 | $this->assertFalse($fv->run()); |
84 | 84 | $this->assertContains('global required message error', $fv->returnErrors()); |
85 | - } |
|
85 | + } |
|
86 | 86 | |
87 | 87 | public function testSettingCustomErrorMessage() |
88 | - { |
|
88 | + { |
|
89 | 89 | |
90 | 90 | $fv = new FormValidation(); |
91 | 91 | $fv->setData(array('foo' => '')); |
@@ -103,20 +103,20 @@ discard block |
||
103 | 103 | |
104 | 104 | $this->assertFalse($fv->run()); |
105 | 105 | $this->assertContains('custom "bar" message error', $fv->returnErrors()); |
106 | - } |
|
106 | + } |
|
107 | 107 | |
108 | 108 | public function testReturnErrorsArray() |
109 | - { |
|
109 | + { |
|
110 | 110 | $fv = new FormValidation(); |
111 | 111 | $fv->setRule('name', 'name', 'required'); |
112 | 112 | $fv->setData(array('name' => '')); |
113 | 113 | $this->assertFalse($fv->run()); |
114 | 114 | $this->assertNotEmpty($fv->returnErrors()); |
115 | - } |
|
115 | + } |
|
116 | 116 | |
117 | 117 | |
118 | 118 | public function testRequiredRule() |
119 | - { |
|
119 | + { |
|
120 | 120 | $fv = new FormValidation(); |
121 | 121 | $fv->setRule('name', 'name', 'required'); |
122 | 122 | $fv->setData(array('name' => '')); |
@@ -131,5 +131,5 @@ discard block |
||
131 | 131 | $fv->setRule('name', 'name', 'required'); |
132 | 132 | $fv->setData(array('name' => 'tony')); |
133 | 133 | $this->assertTrue($fv->run()); |
134 | - } |
|
134 | + } |
|
135 | 135 | } |
136 | 136 | \ No newline at end of file |
@@ -30,15 +30,15 @@ discard block |
||
30 | 30 | // tests |
31 | 31 | public function testSomeFeature() |
32 | 32 | { |
33 | - $config['driver'] = 'mysql'; |
|
34 | - $config['username'] = 'root'; |
|
35 | - $config['password'] = ''; |
|
36 | - $config['database'] = 'db_gesco'; |
|
37 | - $config['hostname'] = 'localhost:3307'; |
|
33 | + $config['driver'] = 'mysql'; |
|
34 | + $config['username'] = 'root'; |
|
35 | + $config['password'] = ''; |
|
36 | + $config['database'] = 'db_gesco'; |
|
37 | + $config['hostname'] = 'localhost:3307'; |
|
38 | 38 | $config['charset'] = 'utf8'; |
39 | 39 | $config['collation'] = 'utf8_general_ci'; |
40 | - $config['prefix'] = ''; |
|
41 | - $config['port'] = 3307; |
|
40 | + $config['prefix'] = ''; |
|
41 | + $config['port'] = 3307; |
|
42 | 42 | |
43 | 43 | $l = new Log(); |
44 | 44 | $l->setLogger('TNHBIS'); |
@@ -92,21 +92,21 @@ discard block |
||
92 | 92 | |
93 | 93 | |
94 | 94 | |
95 | - public function testConfigChange(){ |
|
95 | + public function testConfigChange() { |
|
96 | 96 | //echo Config::get('base_url'); |
97 | 97 | $c = new Config(); |
98 | 98 | $c->set('base_url', 'foo'); |
99 | 99 | //echo get_config('base_url'); |
100 | 100 | } |
101 | 101 | |
102 | - public function testCallPrivateProtectedMethod(){ |
|
102 | + public function testCallPrivateProtectedMethod() { |
|
103 | 103 | $c = new FileCache(); |
104 | 104 | $expected = CACHE_PATH . md5('foo') . '.cache'; |
105 | 105 | $result = runPrivateOrProtectedMethod($c, 'getFilePath', array('foo')); |
106 | 106 | $this->assertEquals($expected, $result); |
107 | 107 | } |
108 | 108 | |
109 | - public function testMocks(){ |
|
109 | + public function testMocks() { |
|
110 | 110 | $mock = $this->getMockBuilder('Model')->getMock(); |
111 | 111 | $mock->expects($this->any())->method('get')->will($this->returnValue('foobar')); |
112 | 112 | $this->assertEquals('foobar', $mock->get(1)); |