Changeset 550 for trunk/lib/Validator.inc.php
- Timestamp:
- Nov 24, 2015 5:38:54 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/lib/Validator.inc.php
r534 r550 54 54 55 55 /** 56 * Check if a value is not empty (just the opposite of isEmpty()). 57 * 58 * @param string $val The input data to validate. 59 * @return bool true if form is not empty, false otherwise. 60 */ 61 static public function notEmpty($val) 62 { 63 return !self::isEmpty($val); 64 } 65 66 /** 67 * Check if a value is empty. 68 * 69 * @param string $val The input data to validate. 70 * @return bool true if form is empty, false otherwise. 71 */ 72 static public function isEmpty($val) 73 { 56 * Check if a value is not empty (the opposite of isEmpty()). 57 * 58 * @param string $val The input data to validate. 59 * @param const $type A LOG_* constant (see App->logMsg()) 60 * @param string $file Filename to log (usually __FILE__) 61 * @param int $line Line number to log (usually __LINE__) 62 * @return bool true if form is not empty, false otherwise. 63 */ 64 static public function notEmpty($val, $type=LOG_NOTICE, $file=null, $line=null) 65 { 66 $app =& App::getInstance(); 74 67 if (is_array($val)) { 75 return empty($val); 76 } else { 77 return '' == trim((string)$val); 78 } 79 } 80 81 /** 82 * Check whether input is a string. 83 * 84 * @param string $val The input data to validate. 85 * @return bool true if form is a string, false otherwise. 86 */ 87 static public function isString($val) 88 { 89 return '' == trim((string)$val) || is_string($val); 90 } 91 92 /** 93 * Check whether input is a number. Allows negative numbers. 94 * 95 * @param string $val The input data to validate. 96 * @return bool True if no errors found, false otherwise. 97 */ 98 static public function isNumber($val) 99 { 100 return '' == trim((string)$val) || is_numeric($val); 101 } 102 103 /** 104 * addError if input is NOT an integer. Don't just use is_int() because the 105 * data coming from the user is *really* a string. 106 * 107 * @param string $val The input data to validate. 108 * @return bool true if value is an integer 109 */ 110 static public function isInteger($val, $negative_ok=false) 111 { 68 if (!empty($val)) { 69 return true; 70 } else { 71 $app->logMsg(sprintf('%s (line %s) failed: %s', __METHOD__, __LINE__, getDump($val)), $type, $file, $line); 72 return false; 73 } 74 } else { 75 if ('' != trim((string)$val)) { 76 return true; 77 } else { 78 $app->logMsg(sprintf('%s (line %s) failed: %s', __METHOD__, __LINE__, getDump($val)), $type, $file, $line); 79 return false; 80 } 81 } 82 } 83 84 /* 85 * We were using the isEmpty method *wrong* for years and should have been using notEmpty becuase it is more grammatically correct. 86 * Because the only use is to ensure a value is not empty, we're simply going to alias this method to notEmpty(). 87 * 88 * @param string $val The input data to validate. 89 * @param const $type A LOG_* constant (see App->logMsg()) 90 * @param string $file Filename to log (usually __FILE__) 91 * @param int $line Line number to log (usually __LINE__) 92 * @return bool true if form is empty, false otherwise. 93 */ 94 static public function isEmpty($val, $type=LOG_NOTICE, $file=null, $line=null) 95 { 96 return !self::notEmpty($val, $type, $file, $line); 97 } 98 99 /** 100 * Check whether input is a string. 101 * 102 * @param string $val The input data to validate. 103 * @param const $type A LOG_* constant (see App->logMsg()) 104 * @param string $file Filename to log (usually __FILE__) 105 * @param int $line Line number to log (usually __LINE__) 106 * @return bool true if form is a string, false otherwise. 107 */ 108 static public function isString($val, $type=LOG_NOTICE, $file=null, $line=null) 109 { 110 $app =& App::getInstance(); 111 if ('' == trim((string)$val) || is_string($val)) { 112 return true; 113 } else { 114 $app->logMsg(sprintf('%s (line %s) failed: %s', __METHOD__, __LINE__, getDump($val)), $type, $file, $line); 115 return false; 116 } 117 } 118 119 /** 120 * Check whether input is a number. Allows negative numbers. 121 * 122 * @param string $val The input data to validate. 123 * @param const $type A LOG_* constant (see App->logMsg()) 124 * @param string $file Filename to log (usually __FILE__) 125 * @param int $line Line number to log (usually __LINE__) 126 * @return bool True if no errors found, false otherwise. 127 */ 128 static public function isNumber($val, $type=LOG_NOTICE, $file=null, $line=null) 129 { 130 $app =& App::getInstance(); 131 if ('' == trim((string)$val) || is_numeric($val)) { 132 return true; 133 } else { 134 $app->logMsg(sprintf('%s (line %s) failed: %s', __METHOD__, __LINE__, getDump($val)), $type, $file, $line); 135 return false; 136 } 137 } 138 139 /** 140 * addError if input is NOT an integer. Don't just use is_int() because the 141 * data coming from the user is *really* a string. 142 * 143 * @param string $val The input data to validate. 144 * @param const $type A LOG_* constant (see App->logMsg()) 145 * @param string $file Filename to log (usually __FILE__) 146 * @param int $line Line number to log (usually __LINE__) 147 * @return bool true if value is an integer 148 */ 149 static public function isInteger($val, $negative_ok=false, $type=LOG_NOTICE, $file=null, $line=null) 150 { 151 $app =& App::getInstance(); 112 152 $pattern = $negative_ok ? '/^-?[[:digit:]]+$/' : '/^[[:digit:]]+$/'; 113 return '' == trim((string)$val) || (is_numeric($val) && preg_match($pattern, $val)); 114 } 115 116 /** 117 * Check whether input is a float. Don't just use is_float() because the 118 * data coming from the user is *really* a string. Integers will also 119 * pass this test. 120 * 121 * @param string $val The input data to validate. 122 * @param bool $negative_ok If the value can be unsigned. 123 * @return bool true if value is a float 124 */ 125 static public function isFloat($val, $negative_ok=false) 126 { 153 if ('' == trim((string)$val) || (is_numeric($val) && preg_match($pattern, $val))) { 154 return true; 155 } else { 156 $app->logMsg(sprintf('%s (line %s) failed: %s', __METHOD__, __LINE__, getDump($val)), $type, $file, $line); 157 return false; 158 } 159 } 160 161 /** 162 * Check whether input is a float. Don't just use is_float() because the 163 * data coming from the user is *really* a string. Integers will also 164 * pass this test. 165 * 166 * @param string $val The input data to validate. 167 * @param bool $negative_ok If the value can be unsigned. 168 * @param const $type A LOG_* constant (see App->logMsg()) 169 * @param string $file Filename to log (usually __FILE__) 170 * @param int $line Line number to log (usually __LINE__) 171 * @return bool true if value is a float 172 */ 173 static public function isFloat($val, $negative_ok=false, $type=LOG_NOTICE, $file=null, $line=null) 174 { 175 $app =& App::getInstance(); 127 176 $pattern = $negative_ok ? '/^-?[[:digit:]]*(?:\.?[[:digit:]]+)$/' : '/^[[:digit:]]*(?:\.?[[:digit:]]+)$/'; 128 return '' == trim((string)$val) || (is_numeric($val) && preg_match($pattern, $val)); 129 } 130 131 /** 132 * Check whether input is a Decimal or Fixed type. Check values to be stored in mysql decimal, numeric, num, or fixed types. 133 * Note: some integers and floats will also pass this test. 134 * https://dev.mysql.com/doc/refman/5.5/en/fixed-point-types.html 135 * 136 * @param string $val The input data to validate. 137 * @param bool $negative_ok If the value can be unsigned. 138 * @param int $max Total max number of digits (for mysql max is 65). 139 * @param int $dec Total max number of digits after the decimal place (for mysql max is 30). 140 * @return bool true if value is a float 141 */ 142 static public function isDecimal($val, $negative_ok=false, $max=10, $dec=2) 143 { 177 if ('' == trim((string)$val) || (is_numeric($val) && preg_match($pattern, $val))) { 178 return true; 179 } else { 180 $app->logMsg(sprintf('%s (line %s) failed: %s', __METHOD__, __LINE__, getDump($val)), $type, $file, $line); 181 return false; 182 } 183 } 184 185 /** 186 * Check whether input is a Decimal or Fixed type. Check values to be stored in mysql decimal, numeric, num, or fixed types. 187 * Note: some integers and floats will also pass this test. 188 * https://dev.mysql.com/doc/refman/5.5/en/fixed-point-types.html 189 * 190 * @param string $val The input data to validate. 191 * @param bool $negative_ok If the value can be unsigned. 192 * @param int $max Total max number of digits (for mysql max is 65). 193 * @param int $dec Total max number of digits after the decimal place (for mysql max is 30). 194 * @param const $type A LOG_* constant (see App->logMsg()) 195 * @param string $file Filename to log (usually __FILE__) 196 * @param int $line Line number to log (usually __LINE__) 197 * @return bool true if value is a float 198 */ 199 static public function isDecimal($val, $max=10, $dec=2, $negative_ok=false, $type=LOG_NOTICE, $file=null, $line=null) 200 { 201 $app =& App::getInstance(); 144 202 if ('' == trim((string)$val)) { 145 203 return true; 146 204 } 147 205 if (!$negative_ok && is_numeric($val) && $val < 0) { 206 $app->logMsg(sprintf('%s (line %s) failed: %s', __METHOD__, __LINE__, getDump($val)), $type, $file, $line); 148 207 return false; 149 208 } … … 152 211 $dec_count = sizeof($num_parts) <= 1 ? 0 : mb_strlen(end($num_parts)); 153 212 // Must be numeric, total digits <= $max, dec digits <= $dec. 154 return is_numeric($val) && mb_strlen(str_replace(['-', '.'], '', $val)) <= $max && $dec_count <= $dec; 155 } 156 157 /** 158 * Check whether input is an array. 159 * 160 * @param string $val The input data to validate. 161 * @return bool true if value is a float 162 */ 163 static public function isArray($val) 164 { 165 return (is_string($val) && '' == trim((string)$val)) || is_array($val); 166 } 167 168 /** 169 * Check whether input matches the specified perl regular expression 170 * pattern. 171 * 172 * @param string $val The input data to validate. 173 * @param int $regex PREG that the string must match 174 * @param bool $valid_on_match Set to true to be valid if match, or false to be valid if the match fails. 175 * @return bool true if value passes regex test 176 */ 177 static public function checkRegex($val, $regex, $valid_on_match=true) 178 { 179 return $valid_on_match ? preg_match($regex, $val) : !preg_match($regex, $val); 180 } 181 182 /** 183 * Tests if the string length is between specified values. Whitespace excluded for min. 184 * 185 * @param string $val The input data to validate. 186 * @param int $min minimum length of string, inclusive 187 * @param int $max maximum length of string, inclusive 188 * @return bool true if string length is within given boundaries 189 */ 190 static public function stringLength($val, $min, $max) 191 { 192 return mb_strlen((string)$val) >= $min && mb_strlen((string)$val) <= $max; 193 } 194 195 /** 196 * Check whether input is within a valid numeric range. 197 * 198 * @param string $val The input data to validate. 199 * @param int $min minimum value of number, inclusive 200 * @param int $max maximum value of number, inclusive 201 * @return bool True if no errors found, false otherwise. 202 */ 203 static public function numericRange($val, $min, $max) 204 { 205 return '' == trim((string)$val) || (is_numeric($val) && $val >= $min && $val <= $max); 206 } 207 208 /** 209 * Validates an email address based on the recommendations in RFC 3696. 210 * Is more loose than restrictive, to allow the many valid variants of 211 * email addresses while catching the most common mistakes. 212 * http://www.faqs.org/rfcs/rfc822.html 213 * http://www.faqs.org/rfcs/rfc2822.html 214 * http://www.faqs.org/rfcs/rfc3696.html 215 * http://www.faqs.org/rfcs/rfc1035.html 216 * 217 * @access public 218 * @param string $val The input data to validate.. 219 * @param bool $strict Do we run strict tests? 220 * @return const One of the constant values: Validate::EMAIL_SUCCESS|Validate::EMAIL_REGEX_FAIL|Validate::EMAIL_LENGTH_FAIL|Validate::EMAIL_MX_FAIL 221 * @author Quinn Comendant <quinn@strangecode.com> 222 */ 223 static public function validateEmail($val, $strict=false) 224 { 213 if (is_numeric($val) && mb_strlen(str_replace(['-', '.'], '', $val)) <= $max && $dec_count <= $dec) { 214 return true; 215 } else { 216 $app->logMsg(sprintf('%s (line %s) failed: %s', __METHOD__, __LINE__, getDump($val)), $type, $file, $line); 217 return false; 218 } 219 } 220 221 /** 222 * Check whether input is an array. 223 * 224 * @param string $val The input data to validate. 225 * @param const $type A LOG_* constant (see App->logMsg()) 226 * @param string $file Filename to log (usually __FILE__) 227 * @param int $line Line number to log (usually __LINE__) 228 * @return bool true if value is a float 229 */ 230 static public function isArray($val, $type=LOG_NOTICE, $file=null, $line=null) 231 { 232 $app =& App::getInstance(); 233 if ((is_string($val) && '' == trim((string)$val)) || is_array($val)) { 234 return true; 235 } else { 236 $app->logMsg(sprintf('%s (line %s) failed: %s', __METHOD__, __LINE__, getDump($val)), $type, $file, $line); 237 return false; 238 } 239 } 240 241 /** 242 * Check whether input matches the specified perl regular expression 243 * pattern. 244 * 245 * @param string $val The input data to validate. 246 * @param int $regex PREG that the string must match 247 * @param bool $valid_on_match Set to true to be valid if match, or false to be valid if the match fails. 248 * @param const $type A LOG_* constant (see App->logMsg()) 249 * @param string $file Filename to log (usually __FILE__) 250 * @param int $line Line number to log (usually __LINE__) 251 * @return bool true if value passes regex test 252 */ 253 static public function checkRegex($val, $regex, $valid_on_match=true, $type=LOG_NOTICE, $file=null, $line=null) 254 { 255 $app =& App::getInstance(); 256 if ($valid_on_match ? preg_match($regex, $val) : !preg_match($regex, $val)) { 257 return true; 258 } else { 259 $app->logMsg(sprintf('%s (line %s) failed: %s', __METHOD__, __LINE__, getDump($val)), $type, $file, $line); 260 return false; 261 } 262 } 263 264 /** 265 * Tests if the string length is between specified values. Whitespace excluded for min. 266 * 267 * @param string $val The input data to validate. 268 * @param int $min minimum length of string, inclusive 269 * @param int $max maximum length of string, inclusive 270 * @param const $type A LOG_* constant (see App->logMsg()) 271 * @param string $file Filename to log (usually __FILE__) 272 * @param int $line Line number to log (usually __LINE__) 273 * @return bool true if string length is within given boundaries 274 */ 275 static public function stringLength($val, $min, $max, $type=LOG_NOTICE, $file=null, $line=null) 276 { 277 $app =& App::getInstance(); 278 if (mb_strlen((string)$val) >= $min && mb_strlen((string)$val) <= $max) { 279 return true; 280 } else { 281 $app->logMsg(sprintf('%s (line %s) failed: %s', __METHOD__, __LINE__, getDump($val)), $type, $file, $line); 282 return false; 283 } 284 } 285 286 /** 287 * Check whether input is within a valid numeric range. 288 * 289 * @param string $val The input data to validate. 290 * @param int $min minimum value of number, inclusive 291 * @param int $max maximum value of number, inclusive 292 * @param const $type A LOG_* constant (see App->logMsg()) 293 * @param string $file Filename to log (usually __FILE__) 294 * @param int $line Line number to log (usually __LINE__) 295 * @return bool True if no errors found, false otherwise. 296 */ 297 static public function numericRange($val, $min, $max, $type=LOG_NOTICE, $file=null, $line=null) 298 { 299 $app =& App::getInstance(); 300 if ('' == trim((string)$val) || (is_numeric($val) && $val >= $min && $val <= $max)) { 301 return true; 302 } else { 303 $app->logMsg(sprintf('%s (line %s) failed: %s', __METHOD__, __LINE__, getDump($val)), $type, $file, $line); 304 return false; 305 } 306 } 307 308 /** 309 * Validates an email address based on the recommendations in RFC 3696. 310 * Is more loose than restrictive, to allow the many valid variants of 311 * email addresses while catching the most common mistakes. 312 * http://www.faqs.org/rfcs/rfc822.html 313 * http://www.faqs.org/rfcs/rfc2822.html 314 * http://www.faqs.org/rfcs/rfc3696.html 315 * http://www.faqs.org/rfcs/rfc1035.html 316 * 317 * @access public 318 * @param string $val The input data to validate.. 319 * @param bool $strict Run strict tests (check if the domain exists and has an MX record assigned) 320 * @param const $type A LOG_* constant (see App->logMsg()) 321 * @param string $file Filename to log (usually __FILE__) 322 * @param int $line Line number to log (usually __LINE__) 323 * @return const One of the constant values: Validate::EMAIL_SUCCESS|Validate::EMAIL_REGEX_FAIL|Validate::EMAIL_LENGTH_FAIL|Validate::EMAIL_MX_FAIL 324 * @author Quinn Comendant <quinn@strangecode.com> 325 */ 326 static public function validateEmail($val, $strict=false, $type=LOG_NOTICE, $file=null, $line=null) 327 { 328 $app =& App::getInstance(); 225 329 require_once 'codebase/lib/Email.inc.php'; 226 330 $e = new Email(); … … 228 332 // Test email address format. 229 333 if (!preg_match($e->getParam('regex'), $val, $e_parts)) { 334 $app->logMsg(sprintf('%s (line %s) failed: %s', __METHOD__, __LINE__, getDump($val)), $type, $file, $line); 230 335 return self::EMAIL_REGEX_FAIL; 231 336 } … … 241 346 // Test length. 242 347 if (mb_strlen($local) > 64 || mb_strlen($domain) > 191) { 348 $app->logMsg(sprintf('%s (line %s) failed: %s', __METHOD__, __LINE__, getDump($val)), $type, $file, $line); 243 349 return self::EMAIL_LENGTH_FAIL; 244 350 } 245 351 246 // Strict tests below. 247 248 // Check domain exists: It's a domain if ip2long fails; checkdnsrr ensures a MX record exists; gethostbyname() ensures the domain exists. 249 if ($strict && ip2long($domain) === false && function_exists('checkdnsrr') && !checkdnsrr($domain . '.', 'MX') && gethostbyname($domain) == $domain) { 250 return self::EMAIL_MX_FAIL; 352 if ($strict) { 353 // Strict tests. 354 if (ip2long($domain) === false && function_exists('checkdnsrr') && !checkdnsrr($domain . '.', 'MX') && gethostbyname($domain) == $domain) { 355 // Check domain exists: It's a domain if ip2long fails; checkdnsrr ensures a MX record exists; gethostbyname() ensures the domain exists. 356 $app->logMsg(sprintf('%s (line %s) failed: %s', __METHOD__, __LINE__, getDump($val)), $type, $file, $line); 357 return self::EMAIL_MX_FAIL; 358 } 251 359 } 252 360 … … 255 363 256 364 /** 257 * Check whether input is a valid phone number. Notice: it is now set 258 * to allow characters like - or () or + so people can type in a phone 259 * number that looks like: +1 (530) 555-1212 260 * 261 * @param string $form_name the name of the incoming form variable 262 * 263 * @return bool true if no errors found, false otherwise 264 */ 265 static public function validatePhone($val) 266 { 267 if (!self::checkRegex($val, '/^[0-9 +().-]*$/', true)) { 365 * Check whether input is a valid phone number. Notice: it is now set 366 * to allow characters like - or () or + so people can type in a phone 367 * number that looks like: +1 (530) 555-1212 368 * 369 * @param string $form_name the name of the incoming form variable 370 * 371 * @param const $type A LOG_* constant (see App->logMsg()) 372 * @param string $file Filename to log (usually __FILE__) 373 * @param int $line Line number to log (usually __LINE__) 374 * @return bool true if no errors found, false otherwise 375 */ 376 static public function validatePhone($val, $type=LOG_NOTICE, $file=null, $line=null) 377 { 378 $app =& App::getInstance(); 379 if (!self::checkRegex($val, '/^[0-9 +().-]*$/', true, $type, $file, $line)) { 380 $app->logMsg(sprintf('%s (line %s) failed: %s', __METHOD__, __LINE__, getDump($val)), $type, $file, $line); 268 381 return self::PHONE_REGEX_FAIL; 269 382 } 270 if (!self::stringLength($val, 0, 25)) { 383 if (!self::stringLength($val, 0, 25, $type, $file, $line)) { 384 $app->logMsg(sprintf('%s (line %s) failed: %s', __METHOD__, __LINE__, getDump($val)), $type, $file, $line); 271 385 return self::PHONE_LENGTH_FAIL; 272 386 } … … 275 389 276 390 /** 277 * Verifies that date can be processed by the strtotime function. 278 * Empty strings are considered valid. Other values are tested on their return value from strtotime(). Null values will fail. 279 * 280 * @param string $val The input data to validate. 281 * @return bool True if no errors found, false otherwise. 282 */ 283 static public function validateStrDate($val) 284 { 391 * Verifies that date can be processed by the strtotime function. 392 * Empty strings are considered valid. Other values are tested on their return value from strtotime(). Null values will fail. 393 * 394 * @param string $val The input data to validate. 395 * @param const $type A LOG_* constant (see App->logMsg()) 396 * @param string $file Filename to log (usually __FILE__) 397 * @param int $line Line number to log (usually __LINE__) 398 * @return bool True if no errors found, false otherwise. 399 */ 400 static public function validateStrDate($val, $type=LOG_NOTICE, $file=null, $line=null) 401 { 402 $app =& App::getInstance(); 285 403 if (is_string($val) && '' === trim($val)) { 286 404 // Don't be too bothered about empty strings. … … 290 408 $timestamp = strtotime($val); 291 409 if (!$timestamp || $timestamp < 1) { 410 $app->logMsg(sprintf('%s (line %s) failed: %s', __METHOD__, __LINE__, getDump($val)), $type, $file, $line); 292 411 return false; 293 412 } else { … … 301 420 * @access public 302 421 * @param string $val String to check. 422 * @param const $type A LOG_* constant (see App->logMsg()) 423 * @param string $file Filename to log (usually __FILE__) 424 * @param int $line Line number to log (usually __LINE__) 303 425 * @return bool True if value is an empty date. 304 426 * @author Quinn Comendant <quinn@strangecode.com> … … 306 428 * @since 19 May 2015 09:57:27 307 429 */ 308 static public function isEmptyDate($val) 309 { 430 static public function isEmptyDate($val, $type=LOG_NOTICE, $file=null, $line=null) 431 { 432 $app =& App::getInstance(); 310 433 if (empty($val) || '0000-00-00 00:00:00' == $val || '0000-00-00' == $val || '00:00:00' == $val) { 311 434 return true; 312 435 } 436 $app->logMsg(sprintf('%s (line %s) failed: %s', __METHOD__, __LINE__, getDump($val)), $type, $file, $line); 313 437 return false; 314 438 } 315 439 316 440 /** 317 * Verifies credit card number using the Luhn (mod 10) algorithm. 318 * http://en.wikipedia.org/wiki/Luhn_algorithm 319 * 320 * @param string $val The input data to validate.. 321 * @param string $cc_num Card number to verify. 322 * @param string $cc_type Optional, card type to do specific checks. 323 * @return bool True if no errors found, false otherwise. 324 */ 325 static public function validateCCNumber($val, $cc_type=null) 326 { 441 * Verifies credit card number using the Luhn (mod 10) algorithm. 442 * http://en.wikipedia.org/wiki/Luhn_algorithm 443 * 444 * @param string $val The input data to validate.. 445 * @param string $cc_num Card number to verify. 446 * @param string $cc_type Optional, card type to do specific checks. 447 * @param const $type A LOG_* constant (see App->logMsg()) 448 * @param string $file Filename to log (usually __FILE__) 449 * @param int $line Line number to log (usually __LINE__) 450 * @return bool True if no errors found, false otherwise. 451 */ 452 static public function validateCCNumber($val, $cc_type=null, $type=LOG_NOTICE, $file=null, $line=null) 453 { 454 $app =& App::getInstance(); 327 455 // Get rid of any non-digits 328 456 $cc_num = preg_replace('/[^\d]/', '', $val); … … 355 483 if ('' != $regex && !preg_match($regex, $cc_num)) { 356 484 // Invalid format. 485 $app->logMsg(sprintf('%s (line %s) failed: %s', __METHOD__, __LINE__, getDump($val)), $type, $file, $line); 357 486 return false; 358 487 } … … 383 512 384 513 // If the Total is evenly divisible by 10, it's cool! 385 return $luhn_total % 10 == 0; 386 } 387 388 /** 389 * Check whether a file was selected for uploading. If file is missing, it's an error. 390 * 391 * @param string $form_name The input data to validate. 392 * @return bool True if no errors found, false otherwise. 393 */ 394 static public function fileUploaded($form_name) 395 { 514 if ($luhn_total % 10 == 0) { 515 return true; 516 } else { 517 $app->logMsg(sprintf('%s (line %s) failed: %s', __METHOD__, __LINE__, getDump($val)), $type, $file, $line); 518 return false; 519 } 520 } 521 522 /** 523 * Check whether a file was selected for uploading. If file is missing, it's an error. 524 * 525 * @param string $form_name The input data to validate. 526 * @param const $type A LOG_* constant (see App->logMsg()) 527 * @param string $file Filename to log (usually __FILE__) 528 * @param int $line Line number to log (usually __LINE__) 529 * @return bool True if no errors found, false otherwise. 530 */ 531 static public function fileUploaded($form_name, $type=LOG_NOTICE, $file=null, $line=null) 532 { 533 $app =& App::getInstance(); 396 534 if (!isset($_FILES[$form_name]['name']) || empty($_FILES[$form_name]['name'])) { 535 $app->logMsg(sprintf('%s (line %s) failed: %s', __METHOD__, __LINE__, 'no _FILES'), $type, $file, $line); 397 536 return false; 398 537 } … … 401 540 foreach($_FILES[$form_name]['name'] as $f) { 402 541 if ('' == $f) { 542 $app->logMsg(sprintf('%s (line %s) failed: %s', __METHOD__, __LINE__, getDump($_FILES)), $type, $file, $line); 403 543 return false; 404 544 } … … 406 546 } else { 407 547 if ('' == $_FILES[$form_name]['name']) { 548 $app->logMsg(sprintf('%s (line %s) failed: %s', __METHOD__, __LINE__, getDump($_FILES)), $type, $file, $line); 408 549 return false; 409 550 } … … 419 560 * @access public 420 561 * @param string $form_name The input data to validate. 562 * @param const $type A LOG_* constant (see App->logMsg()) 563 * @param string $file Filename to log (usually __FILE__) 564 * @param int $line Line number to log (usually __LINE__) 421 565 * @return bool True if no errors found, false otherwise. 422 566 * @author Quinn Comendant <quinn@strangecode.com> … … 424 568 * @since 20 Aug 2014 14:44:23 425 569 */ 426 static public function fileUploadSize($form_name) 427 { 570 static public function fileUploadSize($form_name, $type=LOG_NOTICE, $file=null, $line=null) 571 { 572 $app =& App::getInstance(); 428 573 $upload_max_filesize = phpIniGetBytes('upload_max_filesize'); 429 574 if (isset($_SERVER['CONTENT_LENGTH']) && 0 != $upload_max_filesize && $_SERVER['CONTENT_LENGTH'] > $upload_max_filesize) { 575 $app->logMsg(sprintf('%s (line %s) failed: %s', __METHOD__, __LINE__, getDump($val)), $type, $file, $line); 430 576 return false; 431 577 }
Note: See TracChangeset
for help on using the changeset viewer.