@@ -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); |
@@ -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; |
@@ -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,50 +94,50 @@ 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 | //show only and continue to help track of some error occured |
| 117 | - echo 'TNHFW Error: '.$msg . "\n"; |
|
| 117 | + echo 'TNHFW Error: ' . $msg . "\n"; |
|
| 118 | 118 | } |
| 119 | 119 | |
| 120 | - function is_https(){ |
|
| 120 | + function is_https() { |
|
| 121 | 121 | return false; |
| 122 | 122 | } |
| 123 | 123 | |
| 124 | 124 | /** |
| 125 | 125 | * @test |
| 126 | 126 | */ |
| 127 | - function is_url($url){ |
|
| 127 | + function is_url($url) { |
|
| 128 | 128 | return preg_match('/^(http|https|ftp):\/\/(.*)/', $url); |
| 129 | 129 | } |
| 130 | 130 | |
| 131 | - function php_exception_handler($ex){ |
|
| 132 | - throw new RuntimeException('PHP Exception : '.$ex->getMessage().' | '.$ex->getFile().' | '.$ex->getLine()); |
|
| 131 | + function php_exception_handler($ex) { |
|
| 132 | + throw new RuntimeException('PHP Exception : ' . $ex->getMessage() . ' | ' . $ex->getFile() . ' | ' . $ex->getLine()); |
|
| 133 | 133 | } |
| 134 | 134 | |
| 135 | 135 | |
| 136 | - function php_error_handler($errno , $errstr, $errfile , $errline, array $errcontext = array()){ |
|
| 137 | - throw new RuntimeException('TNHFW Exception Error : '.$errstr.' | '.$errfile.' | '.$errline); |
|
| 136 | + function php_error_handler($errno, $errstr, $errfile, $errline, array $errcontext = array()) { |
|
| 137 | + throw new RuntimeException('TNHFW Exception Error : ' . $errstr . ' | ' . $errfile . ' | ' . $errline); |
|
| 138 | 138 | } |
| 139 | 139 | |
| 140 | - function php_shudown_handler(){ |
|
| 140 | + function php_shudown_handler() { |
|
| 141 | 141 | return true; |
| 142 | 142 | } |
| 143 | 143 | |
@@ -145,11 +145,11 @@ discard block |
||
| 145 | 145 | /** |
| 146 | 146 | * @test |
| 147 | 147 | */ |
| 148 | - function attributes_to_string(array $attributes){ |
|
| 148 | + function attributes_to_string(array $attributes) { |
|
| 149 | 149 | $str = ' '; |
| 150 | 150 | //we check that the array passed as an argument is not empty. |
| 151 | - if(! empty($attributes)){ |
|
| 152 | - foreach($attributes as $key => $value){ |
|
| 151 | + if (!empty($attributes)) { |
|
| 152 | + foreach ($attributes as $key => $value) { |
|
| 153 | 153 | $key = trim(htmlspecialchars($key)); |
| 154 | 154 | $value = trim(htmlspecialchars($value)); |
| 155 | 155 | /* |
@@ -159,35 +159,35 @@ discard block |
||
| 159 | 159 | * $attr = array('placeholder' => 'I am a "puple"') |
| 160 | 160 | * $str = attributes_to_string($attr); => placeholder = "I am a \"puple\"" |
| 161 | 161 | */ |
| 162 | - if($value && strpos('"', $value) !== false){ |
|
| 162 | + if ($value && strpos('"', $value) !== false) { |
|
| 163 | 163 | $value = addslashes($value); |
| 164 | 164 | } |
| 165 | - $str .= $key.' = "'.$value.'" '; |
|
| 165 | + $str .= $key . ' = "' . $value . '" '; |
|
| 166 | 166 | } |
| 167 | 167 | } |
| 168 | 168 | //remove the space after using rtrim() |
| 169 | 169 | return rtrim($str); |
| 170 | 170 | } |
| 171 | 171 | |
| 172 | - function stringfy_vars($var){ |
|
| 172 | + function stringfy_vars($var) { |
|
| 173 | 173 | return print_r($var, true); |
| 174 | 174 | } |
| 175 | 175 | |
| 176 | 176 | /** |
| 177 | 177 | * @test |
| 178 | 178 | */ |
| 179 | - function clean_input($str){ |
|
| 180 | - if(is_array($str)){ |
|
| 179 | + function clean_input($str) { |
|
| 180 | + if (is_array($str)) { |
|
| 181 | 181 | $str = array_map('clean_input', $str); |
| 182 | 182 | } |
| 183 | - else if(is_object($str)){ |
|
| 183 | + else if (is_object($str)) { |
|
| 184 | 184 | $obj = $str; |
| 185 | 185 | foreach ($str as $var => $value) { |
| 186 | 186 | $obj->$var = clean_input($value); |
| 187 | 187 | } |
| 188 | 188 | $str = $obj; |
| 189 | 189 | } |
| 190 | - else{ |
|
| 190 | + else { |
|
| 191 | 191 | $str = htmlspecialchars(strip_tags($str), ENT_QUOTES, 'UTF-8'); |
| 192 | 192 | } |
| 193 | 193 | return $str; |
@@ -196,11 +196,11 @@ discard block |
||
| 196 | 196 | /** |
| 197 | 197 | * @test |
| 198 | 198 | */ |
| 199 | - function string_hidden($str, $startCount = 0, $endCount = 0, $hiddenChar = '*'){ |
|
| 199 | + function string_hidden($str, $startCount = 0, $endCount = 0, $hiddenChar = '*') { |
|
| 200 | 200 | //get the string length |
| 201 | 201 | $len = strlen($str); |
| 202 | 202 | //if str is empty |
| 203 | - if($len <= 0){ |
|
| 203 | + if ($len <= 0) { |
|
| 204 | 204 | return str_repeat($hiddenChar, 6); |
| 205 | 205 | } |
| 206 | 206 | //if the length is less than startCount and endCount |
@@ -208,14 +208,14 @@ discard block |
||
| 208 | 208 | //or startCount is negative or endCount is negative |
| 209 | 209 | //return the full string hidden |
| 210 | 210 | |
| 211 | - if((($startCount + $endCount) > $len) || ($startCount == 0 && $endCount == 0) || ($startCount < 0 || $endCount < 0)){ |
|
| 211 | + if ((($startCount + $endCount) > $len) || ($startCount == 0 && $endCount == 0) || ($startCount < 0 || $endCount < 0)) { |
|
| 212 | 212 | return str_repeat($hiddenChar, $len); |
| 213 | 213 | } |
| 214 | 214 | //the start non hidden string |
| 215 | 215 | $startNonHiddenStr = substr($str, 0, $startCount); |
| 216 | 216 | //the end non hidden string |
| 217 | 217 | $endNonHiddenStr = null; |
| 218 | - if($endCount > 0){ |
|
| 218 | + if ($endCount > 0) { |
|
| 219 | 219 | $endNonHiddenStr = substr($str, - $endCount); |
| 220 | 220 | } |
| 221 | 221 | //the hidden string |
@@ -224,12 +224,12 @@ discard block |
||
| 224 | 224 | return $startNonHiddenStr . $hiddenStr . $endNonHiddenStr; |
| 225 | 225 | } |
| 226 | 226 | |
| 227 | - function set_session_config(){ |
|
| 227 | + function set_session_config() { |
|
| 228 | 228 | return true; |
| 229 | 229 | } |
| 230 | 230 | |
| 231 | 231 | function & get_instance(){ |
| 232 | - if(! Controller::get_instance()){ |
|
| 232 | + if (!Controller::get_instance()) { |
|
| 233 | 233 | $c = new Controller(); |
| 234 | 234 | } |
| 235 | 235 | return Controller::get_instance(); |
@@ -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 |
@@ -25,7 +25,7 @@ discard block |
||
| 25 | 25 | |
| 26 | 26 | |
| 27 | 27 | |
| 28 | - public function testDefaultValue(){ |
|
| 28 | + public function testDefaultValue() { |
|
| 29 | 29 | $e = new Event('foo'); |
| 30 | 30 | $this->assertSame($e->name, 'foo'); |
| 31 | 31 | $this->assertSame($e->payload, array()); |
@@ -33,7 +33,7 @@ discard block |
||
| 33 | 33 | $this->assertFalse($e->stop); |
| 34 | 34 | } |
| 35 | 35 | |
| 36 | - public function testPayloadValueIsSet(){ |
|
| 36 | + public function testPayloadValueIsSet() { |
|
| 37 | 37 | $e = new Event('foo', array('bar')); |
| 38 | 38 | $this->assertSame($e->name, 'foo'); |
| 39 | 39 | $this->assertSame($e->payload, array('bar')); |
@@ -41,7 +41,7 @@ discard block |
||
| 41 | 41 | $this->assertFalse($e->stop); |
| 42 | 42 | } |
| 43 | 43 | |
| 44 | - public function testReturnBackValueIsSetToTrue(){ |
|
| 44 | + public function testReturnBackValueIsSetToTrue() { |
|
| 45 | 45 | $e = new Event('foo', array('bar'), true); |
| 46 | 46 | $this->assertSame($e->name, 'foo'); |
| 47 | 47 | $this->assertSame($e->payload, array('bar')); |
@@ -49,7 +49,7 @@ discard block |
||
| 49 | 49 | $this->assertFalse($e->stop); |
| 50 | 50 | } |
| 51 | 51 | |
| 52 | - public function testStopValueIsSetToTue(){ |
|
| 52 | + public function testStopValueIsSetToTue() { |
|
| 53 | 53 | $e = new Event('foo', array('bar'), true, true); |
| 54 | 54 | $this->assertSame($e->name, 'foo'); |
| 55 | 55 | $this->assertSame($e->payload, array('bar')); |