d17b9051 by Marty Penner

Format and translate various methods/classes

1 parent 212a1099
...@@ -59,11 +59,11 @@ function login($username, $password, $remember = false) { ...@@ -59,11 +59,11 @@ function login($username, $password, $remember = false) {
59 throw new LogicException('Unable to login because headers have been sent'); 59 throw new LogicException('Unable to login because headers have been sent');
60 } 60 }
61 61
62 $auth = _signon(Array( 62 $auth = _signon([
63 'user_login' => esc_sql($username) 63 'user_login' => esc_sql($username)
64 , 'user_password' => esc_sql($password) 64 , 'user_password' => esc_sql($password)
65 , 'remember' => $remember 65 , 'remember' => $remember
66 )); 66 ]);
67 67
68 if (get_class($auth) == 'WP_User') { 68 if (get_class($auth) == 'WP_User') {
69 // This is done to ensure the auth'd user is logged in; cookie is not yet readable, redirect needed 69 // This is done to ensure the auth'd user is logged in; cookie is not yet readable, redirect needed
...@@ -124,7 +124,7 @@ function logout() { ...@@ -124,7 +124,7 @@ function logout() {
124 * @global $wpdb 124 * @global $wpdb
125 * @see wpmu_signup_user 125 * @see wpmu_signup_user
126 */ 126 */
127 function register($username, $email, $password, $meta = Array()) { 127 function register($username, $email, $password, $meta = []) {
128 global $wpdb; 128 global $wpdb;
129 require_once(ABSPATH . WPINC . DIRECTORY_SEPARATOR . 'registration.php'); 129 require_once(ABSPATH . WPINC . DIRECTORY_SEPARATOR . 'registration.php');
130 130
...@@ -138,11 +138,11 @@ function register($username, $email, $password, $meta = Array()) { ...@@ -138,11 +138,11 @@ function register($username, $email, $password, $meta = Array()) {
138 */ 138 */
139 $wpdb->query("DELETE FROM {$wpdb->signups} WHERE user_email='$email' AND active=0"); 139 $wpdb->query("DELETE FROM {$wpdb->signups} WHERE user_email='$email' AND active=0");
140 140
141 $user_data = Array( 141 $user_data = [
142 'username' => $username 142 'username' => $username
143 , 'password' => $password 143 , 'password' => $password
144 , 'email' => $email 144 , 'email' => $email
145 ); 145 ];
146 $meta['password'] = $password; 146 $meta['password'] = $password;
147 // array_filter($user_data, 'esc_sql'); 147 // array_filter($user_data, 'esc_sql');
148 148
...@@ -158,7 +158,7 @@ function register($username, $email, $password, $meta = Array()) { ...@@ -158,7 +158,7 @@ function register($username, $email, $password, $meta = Array()) {
158 $key = substr(md5(time() . rand() . $email ), 0, 16); 158 $key = substr(md5(time() . rand() . $email ), 0, 16);
159 $meta = serialize($meta); 159 $meta = serialize($meta);
160 160
161 $wpdb->insert($wpdb->signups, Array( 161 $wpdb->insert($wpdb->signups, [
162 'domain' => '', 162 'domain' => '',
163 'path' => '', 163 'path' => '',
164 'title' => '', 164 'title' => '',
...@@ -167,7 +167,7 @@ function register($username, $email, $password, $meta = Array()) { ...@@ -167,7 +167,7 @@ function register($username, $email, $password, $meta = Array()) {
167 'registered' => current_time('mysql', true), 167 'registered' => current_time('mysql', true),
168 'activation_key' => $key, 168 'activation_key' => $key,
169 'meta' => $meta 169 'meta' => $meta
170 )); 170 ]);
171 171
172 // do_action('ACTION_REGISTER'); ??? 172 // do_action('ACTION_REGISTER'); ???
173 173
...@@ -209,7 +209,7 @@ function activate($key, $password_validation = null) { ...@@ -209,7 +209,7 @@ function activate($key, $password_validation = null) {
209 throw new Exception('Unable to create user'); 209 throw new Exception('Unable to create user');
210 } 210 }
211 211
212 $wpdb->update($wpdb->signups, Array('active' => 1, 'activated' => current_time('mysql', true)), Array('activation_key' => $key)); 212 $wpdb->update($wpdb->signups, ['active' => 1, 'activated' => current_time('mysql', true)], ['activation_key' => $key]);
213 // $user_site = get_site_option('dashboard_blog', $current_site->blog_id); 213 // $user_site = get_site_option('dashboard_blog', $current_site->blog_id);
214 214
215 if (function_exists('add_user_to_blog')) { 215 if (function_exists('add_user_to_blog')) {
...@@ -240,16 +240,18 @@ class Validation extends Common\Validation { ...@@ -240,16 +240,18 @@ class Validation extends Common\Validation {
240 */ 240 */
241 protected function username($val) { 241 protected function username($val) {
242 if (empty($val)) { 242 if (empty($val)) {
243 throw new Exception('<li>Username is blank</li>'); 243 throw new Exception('<li>'.__('Username is blank', CBV_DOMAIN).'</li>');
244 } 244 }
245 245
246 require_once(ABSPATH . WPINC . DIRECTORY_SEPARATOR . 'registration.php'); 246 require_once(ABSPATH . WPINC . DIRECTORY_SEPARATOR . 'registration.php');
247 if (!validate_username($val)) { 247 if (!validate_username($val)) {
248 throw new Exception('<li>Username must be at least 4 characters, letters and numbers only</li>'); 248 throw new Exception(
249 '<li>'.__('Username must be at least 4 characters, letters and numbers only', CBV_DOMAIN).'</li>'
250 );
249 } 251 }
250 252
251 if (username_exists($val)) { 253 if (username_exists($val)) {
252 throw new Exception('<li>Username already exists</li>'); 254 throw new Exception('<li>'.__('Username already exists', CBV_DOMAIN).'</li>');
253 } 255 }
254 } 256 }
255 257
...@@ -260,15 +262,19 @@ class Validation extends Common\Validation { ...@@ -260,15 +262,19 @@ class Validation extends Common\Validation {
260 */ 262 */
261 protected function password($val) { 263 protected function password($val) {
262 if (empty($val)) { 264 if (empty($val)) {
263 throw new Exception('<li>Password can not be blank</li>'); 265 throw new Exception('<li>'.__('Password can not be blank', CBV_DOMAIN).'</li>');
264 } 266 }
265 267
266 if (isset($val[PASS_MAX_LEN])) { 268 if (isset($val[PASS_MAX_LEN])) {
267 throw new Exception('<li>Password can not be longer than ' . PASS_MAX_LEN . ' characters.</li>'); 269 throw new Exception(
270 '<li>'.sprintf(__('Password can not be longer than %d characters.', CBV_DOMAIN), PASS_MAX_LEN).'</li>'
271 );
268 } 272 }
269 273
270 if (preg_match('/(\\\\|\\\'|"| )+/i', $val)) { 274 if (preg_match('/(\\\\|\\\'|"| )+/i', $val)) {
271 throw new Exception('<li>Password can not contain spaces, backslashes (\) or quotes</li>'); 275 throw new Exception(
276 '<li>'.__('Password can not contain spaces, backslashes (\) or quotes', CBV_DOMAIN).'</li>'
277 );
272 } 278 }
273 } 279 }
274 280
...@@ -278,11 +284,11 @@ class Validation extends Common\Validation { ...@@ -278,11 +284,11 @@ class Validation extends Common\Validation {
278 */ 284 */
279 protected function email($val) { 285 protected function email($val) {
280 if (!(boolean)filter_var($val, FILTER_VALIDATE_EMAIL)) { 286 if (!(boolean)filter_var($val, FILTER_VALIDATE_EMAIL)) {
281 throw new Exception('<li>Invalid email address</li>'); 287 throw new Exception('<li>'.__('Invalid email address', CBV_DOMAIN).'</li>');
282 } 288 }
283 289
284 if (false !== email_exists($val)) { 290 if (false !== email_exists($val)) {
285 throw new Exception('<li>Email address already registered</li>'); 291 throw new Exception('<li>'.__('Email address already registered', CBV_DOMAIN).' </li > ');
286 } 292 }
287 } 293 }
288 } 294 }
...@@ -294,4 +300,3 @@ class Vars { ...@@ -294,4 +300,3 @@ class Vars {
294 */ 300 */
295 public static $options; 301 public static $options;
296 } 302 }
297 ?>
...\ No newline at end of file ...\ No newline at end of file
......
1 <?php 1 <?php
2 namespace Tz\WordPress\Tools\HTML; 2 namespace Tz\WordPress\Tools\HTML;
3 3
4 function select_opts(Array $options, $selected = null, $echo = true) 4 /**
5 * @param array $options
6 * @param null $selected
7 * @param bool $echo
8 *
9 * @return string
10 */
11 function selectOpts(array $options, $selected = null, $echo = true)
5 { 12 {
6 $return = ''; 13 $return = '';
7 14
...@@ -23,40 +30,82 @@ function select_opts(Array $options, $selected = null, $echo = true) ...@@ -23,40 +30,82 @@ function select_opts(Array $options, $selected = null, $echo = true)
23 } 30 }
24 } 31 }
25 32
26 function select_opts_provinces($selected = null, $echo = true) 33 /**
34 * @param null $selected
35 *
36 * @return string
37 */
38 function selectOptsProvinces($selected = null)
27 { 39 {
28 $return = "<option>Select a State/Province</option>"; 40 $return = '<option>'.__('Select a State/Province', CBV_DOMAIN).'</option>';
29 41
30 $return .= '<optgroup label="Canada">'; 42 $return .= '<optgroup label="Canada">';
31 $return .= select_opts(Vars::$provinces['CA'], $selected, false); 43 $return .= selectOpts(Vars::$provinces['CA'], $selected, false);
32 $return .= '</optgroup>'; 44 $return .= '</optgroup>';
33 45
34 $return .= '<optgroup label="United States">'; 46 $return .= '<optgroup label="United States">';
35 $return .= select_opts(Vars::$provinces['US'], $selected, false); 47 $return .= selectOpts(Vars::$provinces['US'], $selected, false);
36 $return .= '</optgroup>'; 48 $return .= '</optgroup>';
37 49
38 $return .= '<optgroup label="Other">'; 50 $return .= '<optgroup label="Other">';
39 $return .= '<option value="other">Outside Canada/USA</option>'; 51 $return .= '<option value="other">'.__('Outside Canada/USA', CBV_DOMAIN).'</option>';
40 $return .= '</optgroup>'; 52 $return .= '</optgroup>';
41 53
42 return $return; 54 return $return;
43 } 55 }
44 56
45 function select_opts_cards($selected = null, $echo = true) 57 /**
58 * @param null $selected
59 * @param bool $echo
60 *
61 * @return string
62 */
63 function selectOptsCards($selected = null, $echo = true)
46 { 64 {
47 return select_opts(Vars::$creditcards, $selected, $echo); 65 $cards = array_map(
66 function ($card) {
67 return tz_($card);
68 },
69 Vars::$creditcards
70 );
71
72 return selectOpts($cards, $selected, $echo);
48 } 73 }
49 74
50 function select_opts_states($selected = null, $echo = true) 75 /**
76 * @param null $selected
77 * @param bool $echo
78 *
79 * @return string
80 */
81 function selectOptsStates($selected = null, $echo = true)
51 { 82 {
52 return select_opts(Vars::$states, $selected, $echo); 83 return selectOpts(Vars::$states, $selected, $echo);
53 } 84 }
54 85
55 function select_opts_prefixes($selected = null, $echo = true) 86 /**
87 * @param null $selected
88 * @param bool $echo
89 *
90 * @return string
91 */
92 function selectOptsPrefixes($selected = null, $echo = true)
56 { 93 {
57 return select_opts(Vars::$prefixes, $selected, $echo); 94 $prefixes = array_map(
95 function ($prefix) {
96 return tz_($prefix);
97 },
98 Vars::$prefixes
99 );
100
101 return selectOpts($prefixes, $selected, $echo);
58 } 102 }
59 103
104 /**
105 * @param null $selected
106 *
107 * @return string
108 */
60 function selectOptsPrefixesNoBlank($selected = null) 109 function selectOptsPrefixesNoBlank($selected = null)
61 { 110 {
62 $return = ''; 111 $return = '';
...@@ -77,16 +126,42 @@ function selectOptsPrefixesNoBlank($selected = null) ...@@ -77,16 +126,42 @@ function selectOptsPrefixesNoBlank($selected = null)
77 return $return; 126 return $return;
78 } 127 }
79 128
80 function select_opts_countries($selected = null, $echo = true) 129 /**
130 * @param null $selected
131 * @param bool $echo
132 *
133 * @return string
134 */
135 function selectOptsCountries($selected = null, $echo = true)
81 { 136 {
82 return select_opts(Vars::$countries, $selected, $echo); 137 return selectOpts(Vars::$countries, $selected, $echo);
83 } 138 }
84 139
85 function select_opts_securities($selected = null, $echo = true) 140 /**
141 * @param null $selected
142 * @param bool $echo
143 *
144 * @return string
145 */
146 function selectOptsSecurities($selected = null, $echo = true)
86 { 147 {
87 return select_opts(Vars::$securities, $selected, $echo); 148 $securities = array_map(
149 function ($security) {
150 return tz_($security);
151 },
152 Vars::$securities
153 );
154
155 return selectOpts($securities, $selected, $echo);
88 } 156 }
89 157
158 /**
159 * @param $date
160 * @param string $format
161 *
162 * @return bool
163 * @throws \Exception
164 */
90 function validateDate($date, $format = 'YYYY-MM-DD') 165 function validateDate($date, $format = 'YYYY-MM-DD')
91 { 166 {
92 switch ($format) { 167 switch ($format) {
...@@ -123,34 +198,32 @@ function validateDate($date, $format = 'YYYY-MM-DD') ...@@ -123,34 +198,32 @@ function validateDate($date, $format = 'YYYY-MM-DD')
123 break; 198 break;
124 199
125 default: 200 default:
126 throw new Exception("Invalid Date Format"); 201 throw new \Exception('Invalid Date Format');
127 } 202 }
128 203
129 return checkdate($m, $d, $y); 204 return checkdate($m, $d, $y);
130
131
132 } 205 }
133 206
134 function validate_creditcard($cc_num, $type) 207 function validateCreditcard($ccNum, $type)
135 { 208 {
136 209
137 if ($type == "amex") { 210 if ($type == "amex") {
138 $pattern = "/^([34|37]{2})([0-9]{13})$/"; //American Express 211 $pattern = "/^([34|37]{2})([0-9]{13})$/"; //American Express
139 if (preg_match($pattern, $cc_num)) { 212 if (preg_match($pattern, $ccNum)) {
140 $verified = true; 213 $verified = true;
141 } else { 214 } else {
142 $verified = false; 215 $verified = false;
143 } 216 }
144 } elseif ($type == "mc") { 217 } elseif ($type == "mc") {
145 $pattern = "/^([51|52|53|54|55]{2})([0-9]{14})$/"; //Mastercard 218 $pattern = "/^([51|52|53|54|55]{2})([0-9]{14})$/"; //Mastercard
146 if (preg_match($pattern, $cc_num)) { 219 if (preg_match($pattern, $ccNum)) {
147 $verified = true; 220 $verified = true;
148 } else { 221 } else {
149 $verified = false; 222 $verified = false;
150 } 223 }
151 } elseif ($type == "visa") { 224 } elseif ($type == "visa") {
152 $pattern = "/^([4]{1})([0-9]{12,15})$/"; //Visa 225 $pattern = "/^([4]{1})([0-9]{12,15})$/"; //Visa
153 if (preg_match($pattern, $cc_num)) { 226 if (preg_match($pattern, $ccNum)) {
154 $verified = true; 227 $verified = true;
155 } else { 228 } else {
156 $verified = false; 229 $verified = false;
...@@ -248,7 +321,7 @@ function form_linked_dropdown( ...@@ -248,7 +321,7 @@ function form_linked_dropdown(
248 jQuery("#'.$name.'").show(); 321 jQuery("#'.$name.'").show();
249 322
250 323
251 var options = new Array(); 324 var options = new [];
252 var select = document.getElementById("'.$name.'"); 325 var select = document.getElementById("'.$name.'");
253 select.disabled = false; 326 select.disabled = false;
254 while (select.firstChild) 327 while (select.firstChild)
...@@ -349,7 +422,7 @@ if (!function_exists('formLinkedDropdownWithExtra')) { ...@@ -349,7 +422,7 @@ if (!function_exists('formLinkedDropdownWithExtra')) {
349 jQuery("#'.$name.'_custom").attr("disabled", "disabled").hide(); 422 jQuery("#'.$name.'_custom").attr("disabled", "disabled").hide();
350 jQuery("#'.$name.'").show(); 423 jQuery("#'.$name.'").show();
351 424
352 var options = new Array(); 425 var options =[]ray();
353 var select = document.getElementById("'.$name.'"); 426 var select = document.getElementById("'.$name.'");
354 select.disabled = false; 427 select.disabled = false;
355 while (select.firstChild) 428 while (select.firstChild)
...@@ -451,420 +524,3 @@ if (!function_exists('url_title')) { ...@@ -451,420 +524,3 @@ if (!function_exists('url_title')) {
451 return trim(stripslashes($str)); 524 return trim(stripslashes($str));
452 } 525 }
453 } 526 }
454
455 class Vars
456 {
457 public static $prefixes = [
458 '' => '-- select --',
459 'Mr.' => 'Mr.',
460 'Mrs.' => 'Mrs.',
461 'Ms.' => 'Ms.',
462 'Miss' => 'Miss',
463 'Master' => 'Master',
464 'Dr.' => 'Dr.',
465 'Prof.' => 'Prof.'
466 ];
467
468 public static $company_types = [
469 'advisory_firm' => "Advisory Firm",
470 'litigation_firm' => "Litigation Firm",
471 'venture_capital_firm' => "Venture Capital Firm",
472 'public_practice' => "Public Practice",
473 'government' => "Government",
474 '' => "None",
475 'accounting_firm' => "Accounting Firm",
476 'special_valuation' => "Special Valuation",
477 'investment_bank' => "Investment Bank",
478 'academia' => "Academia",
479 'financial_institution' => "Financial Institution",
480 'pension_fund_co' => "Pension Fund Management Company",
481 'mutual_fund_co' => "Mutual Fund Management Company",
482 'merchant_bank' => "Merchant Bank"
483 ];
484
485 public static $countries = [
486 'CA' => 'Canada',
487 'US' => 'United States',
488 'MX' => 'Mexico',
489 'AF' => 'Afghanistan',
490 'AR' => 'Argentina',
491 'AX' => 'Åland Islands',
492 'AL' => 'Albania',
493 'DZ' => 'Algeria',
494 'AS' => 'American Samoa',
495 'AD' => 'Andorra',
496 'AO' => 'Angola',
497 'AI' => 'Anguilla',
498 'AQ' => 'Antarctica',
499 'AG' => 'Antigua and Barbuda',
500 'AM' => 'Armenia',
501 'AW' => 'Aruba',
502 'AU' => 'Australia',
503 'AT' => 'Austria',
504 'AZ' => 'Azerbaijan',
505 'BS' => 'Bahamas',
506 'BH' => 'Bahrain',
507 'BD' => 'Bangladesh',
508 'BB' => 'Barbados',
509 'BY' => 'Belarus',
510 'BE' => 'Belgium',
511 'BZ' => 'Belize',
512 'BJ' => 'Benin',
513 'BM' => 'Bermuda',
514 'BT' => 'Bhutan',
515 'BO' => 'Bolivia',
516 'BA' => 'Bosnia and Herzegovina',
517 'BW' => 'Botswana',
518 'BV' => 'Bouvet Island',
519 'BR' => 'Brazil',
520 'IO' => 'British Indian Ocean Territory',
521 'BN' => 'Brunei Darussalam',
522 'BG' => 'Bulgaria',
523 'BF' => 'Burkina Faso',
524 'BI' => 'Burundi',
525 'KH' => 'Cambodia',
526 'CM' => 'Cameroon',
527 'CV' => 'Cape Verde',
528 'KY' => 'Cayman Islands',
529 'CF' => 'Central African Republic',
530 'TD' => 'Chad',
531 'CL' => 'Chile',
532 'CN' => 'China',
533 'CX' => 'Christmas Island',
534 'CC' => 'Cocos (Keeling) Islands',
535 'CO' => 'Columbia',
536 'KM' => 'Comoros',
537 'CG' => 'Congo',
538 'CD' => 'Congo, The Democratic Republic',
539 'CK' => 'Cook Islands',
540 'CR' => 'Costa Rica',
541 'CI' => 'Cote d’Ivoire – Really Ivory Coast',
542 'HR' => 'Croatia',
543 'CU' => 'Cuba',
544 'CY' => 'Cyprus',
545 'CZ' => 'Czech Republic',
546 'DK' => 'Denmark',
547 'DJ' => 'Djibouti',
548 'DM' => 'Dominica',
549 'DO' => 'Dominican Republic',
550 'TL' => 'East Timor',
551 'EC' => 'Ecuador',
552 'EG' => 'Egypt',
553 'SV' => 'El Salvador',
554 'GQ' => 'Equatorial Guinea',
555 'ER' => 'Eritrea',
556 'EE' => 'Estonia',
557 'ET' => 'Ethiopia',
558 'FK' => 'Falkland Islands',
559 'FO' => 'Faroe Islands',
560 'FJ' => 'Fiji',
561 'FI' => 'Finland',
562 'FR' => 'France',
563 'GF' => 'French Guiana',
564 'PF' => 'French Polynesia',
565 'TF' => 'French Southern Territories',
566 'GA' => 'Gabon',
567 'GM' => 'Gambia',
568 'GE' => 'Georgia',
569 'DE' => 'Germany',
570 'GH' => 'Ghana',
571 'GI' => 'Gibraltar',
572 'GB' => 'Great Britain',
573 'GR' => 'Greece',
574 'GL' => 'Greenland',
575 'GD' => 'Grenada',
576 'GP' => 'Guadeloupe',
577 'GU' => 'Guam',
578 'GT' => 'Guatemala',
579 'GN' => 'Guinea',
580 'GW' => 'Guinea Bissau',
581 'GY' => 'Guyana',
582 'HT' => 'Haiti',
583 'HM' => 'Heard and McDonald Islands',
584 'HN' => 'Honduras',
585 'HK' => 'Hong Kong',
586 'HU' => 'Hungary',
587 'IS' => 'Iceland',
588 'IN' => 'India',
589 'ID' => 'Indonesia',
590 'IR' => 'Iran, Islamic Republic of',
591 'IQ' => 'Iraq',
592 'IE' => 'Ireland',
593 'IL' => 'Israel',
594 'IT' => 'Italy',
595 'JM' => 'Jamaica',
596 'JP' => 'Japan',
597 'JO' => 'Jordan',
598 'KZ' => 'Kazakhstan',
599 'KE' => 'Kenya',
600 'KI' => 'Kiribati',
601 'KP' => "Korea, Democratic People's Republic",
602 'KR' => 'Korea, Republic of',
603 'KW' => 'Kuwait',
604 'KG' => 'Kyrgyzstan',
605 'LA' => "Lao People's Democratic Republic",
606 'LV' => 'Latvia',
607 'LB' => 'Lebanon',
608 'LI' => 'Liechtenstein',
609 'LS' => 'Lesotho',
610 'LR' => 'Liberia',
611 'LY' => 'Libyan Arab Jamahiriya',
612 'LT' => 'Lithuania',
613 'LU' => 'Luxembourg',
614 'MO' => 'Macau',
615 'MK' => 'Macedonia',
616 'MG' => 'Madagascar',
617 'MW' => 'Malawi',
618 'MY' => 'Malaysia',
619 'MV' => 'Maldives',
620 'ML' => 'Mali',
621 'MT' => 'Malta',
622 'MH' => 'Marshall Islands',
623 'MQ' => 'Martinique',
624 'MR' => 'Mauritania',
625 'MU' => 'Mauritius',
626 'YT' => 'Mayotte',
627 'FM' => "Micronesia, Federated States of",
628 'MD' => 'Moldova, Republic of',
629 'MC' => 'Monaco',
630 'MN' => 'Mongolia',
631 'MS' => 'Montserrat',
632 'MA' => 'Morocco',
633 'MZ' => "Mozambique",
634 'MM' => 'Myanmar',
635 'NA' => 'Namibia',
636 'NR' => 'Nauru',
637 'NP' => 'Nepal',
638 'NL' => 'Netherlands',
639 'AN' => 'Netherlands Antilles',
640 'NC' => 'New Caledonia',
641 'NZ' => 'New Zealand',
642 'NI' => 'Nicaragua',
643 'NE' => 'Niger',
644 'NG' => 'Nigeria',
645 'NU' => 'Niue',
646 'NF' => 'Norfolk Island',
647 'MP' => 'Northern Mariana Islands',
648 'NO' => "Norway",
649 'OM' => 'Oman',
650 'PK' => 'Pakistan',
651 'PW' => 'Palau',
652 'PS' => 'Palestinian Territory, Occupied',
653 'PA' => 'Panama',
654 'PG' => 'Papua New Guinea',
655 'PY' => 'Paraguay',
656 'PE' => 'Peru',
657 'PH' => 'Philippines',
658 'PN' => 'Pitcairn',
659 'PL' => 'Poland',
660 'PT' => 'Portugal',
661 'PR' => 'Puerto Rico',
662 'QA' => 'Qatar',
663 'RE' => 'Reunion',
664 'RO' => 'Romania',
665 'RU' => 'Russian Federation',
666 'RW' => 'Rwanda',
667 'KN' => 'Saint Kitts and Nevis',
668 'LC' => 'Saint Lucia',
669 'VC' => 'Saint Vincent and the Grenadines',
670 'WS' => 'Samoa',
671 'SM' => 'San Marino',
672 'ST' => 'Sao Tome and Principe',
673 'SA' => 'Saudi Arabia',
674 'SN' => 'Senegal',
675 'CS' => 'Serbia and Montenegro',
676 'SC' => 'Seychelles',
677 'SL' => 'Sierra Leone',
678 'SG' => 'Singapore',
679 'SK' => 'Slovakia',
680 'SI' => 'Slovenia',
681 'SB' => 'Solomon Islands',
682 'SO' => 'Somalia',
683 'ZA' => 'South Africa',
684 'GS' => 'South Georgia – South Sandwich Islands',
685 'ES' => 'Spain',
686 'LK' => 'Sri Lanka',
687 'SH' => 'St. Helena',
688 'PM' => 'St. Pierre and Miquelon',
689 'SD' => 'Sudan',
690 'SR' => 'Suriname',
691 'SJ' => 'Svalbard and Jan Mayen',
692 'SZ' => 'Swaziland',
693 'SE' => 'Sweden',
694 'CH' => 'Switzerland',
695 'SY' => 'Syrian Arab Republic',
696 'TW' => 'Taiwan',
697 'TJ' => 'Tajikistan',
698 'TZ' => 'Tanzania, United Republic of',
699 'TH' => 'Thailand',
700 'TG' => 'Togo',
701 'TK' => 'Tokelau',
702 'TO' => 'Tonga',
703 'TT' => 'Trinidad and Tobago',
704 'TN' => 'Tunisia',
705 'TR' => 'Turkey',
706 'TM' => 'Turkmenistan',
707 'TC' => 'Turks and Caicos Islands',
708 'TV' => 'Tuvalu',
709 'UG' => 'Uganda',
710 'UA' => 'Ukraine',
711 'AE' => 'United Arab Emirates',
712 'UM' => 'United States Minor Outlying Islands',
713 'UY' => 'Uruguay',
714 'UZ' => 'Uzbekistan',
715 'VU' => 'Vanuatu',
716 'VA' => 'Vatican City state',
717 'VE' => 'Venezuela',
718 'VN' => 'Viet Nam',
719 'VG' => 'Virgin Islands (British)',
720 'VI' => 'Virgin Islands (US)',
721 'WF' => 'Wallis and Futuna',
722 'EH' => 'Western Sahara',
723 'YE' => 'Yemen',
724 'ZM' => 'Zambia',
725 'ZW' => 'Zimbabwe'
726 ];
727
728 public static $provinces = [
729 'CA' => [
730 'AB' => 'Alberta',
731 'BC' => 'British Columbia',
732 'MB' => 'Manitoba',
733 'NB' => 'New Brunswick',
734 'NL' => 'Newfoundland and Labrador',
735 'NT' => 'Northwest Territories',
736 'NS' => 'Nova Scotia',
737 'NU' => 'Nunavut',
738 'PE' => 'Prince Edward Island',
739 'SK' => 'Saskatchewan',
740 'ON' => 'Ontario',
741 'QC' => 'Quebec',
742 'YT' => 'Yukon'
743 ],
744 'US' => [
745 'AL' => 'Alabama',
746 'AK' => 'Alaska',
747 'AZ' => 'Arizona',
748 'AR' => 'Arkansas',
749 'CA' => 'California',
750 'CO' => 'Colorado',
751 'CT' => 'Connecticut',
752 'DE' => 'Delaware',
753 'DC' => 'District of Columbia',
754 'FL' => 'Florida',
755 'GA' => 'Georgia',
756 'GU' => 'Guam',
757 'HI' => 'Hawaii',
758 'ID' => 'Idaho',
759 'IL' => 'Illinois',
760 'IN' => 'Indiana',
761 'IA' => 'Iowa',
762 'KS' => 'Kansas',
763 'KY' => 'Kentucky',
764 'LA' => 'Louisiana',
765 'ME' => 'Maine',
766 'MD' => 'Maryland',
767 'MA' => 'Massachusetts',
768 'MI' => 'Michigan',
769 'MN' => 'Minnesota',
770 'MS' => 'Mississippi',
771 'MO' => 'Missouri',
772 'MT' => 'Montana',
773 'NE' => 'Nebraska',
774 'NV' => 'Nevada',
775 'NH' => 'New Hampshire',
776 'NJ' => 'New Jersey',
777 'NM' => 'New Mexico',
778 'NY' => 'New York',
779 'NC' => 'North Carolina',
780 'ND' => 'North Dakota',
781 'OH' => 'Ohio',
782 'OK' => 'Oklahoma',
783 'OR' => 'Oregon',
784 'PA' => 'Pennsylvania',
785 'PR' => 'Puerto Rico',
786 'RI' => 'Rhode Island',
787 'SC' => 'South Carolina',
788 'SD' => 'South Dakota',
789 'TN' => 'Tennessee',
790 'TX' => 'Texas',
791 'UT' => 'Utah',
792 'VT' => 'Vermont',
793 'VA' => 'Virginia',
794 'VI' => 'Virgin Islands',
795 'WA' => 'Washington',
796 'WV' => 'West Virginia',
797 'WI' => 'Wisconsin',
798 'WY' => 'Wyoming'
799 ]
800 ];
801
802 public static $securities = [
803 'S01' => "What is your Mother's maiden name?",
804 'S02' => "Who was you childhood hero?",
805 'S03' => "What is/was the name of your first pet?"
806 ];
807
808 public static $creditcards = [
809 'visa' => "Visa",
810 'mc' => "MasterCard",
811 'amex' => "American Express"
812 ];
813
814 public static $states = [
815 'AL' => 'Alabama',
816 'AK' => 'Alaska',
817 'AZ' => 'Arizona',
818 'AR' => 'Arkansas',
819 'CA' => 'California',
820 'CO' => 'Colorado',
821 'CT' => 'Connecticut',
822 'DE' => 'Delaware',
823 'DC' => 'District of Columbia',
824 'FL' => 'Florida',
825 'GA' => 'Georgia',
826 'GU' => 'Guam',
827 'HI' => 'Hawaii',
828 'ID' => 'Idaho',
829 'IL' => 'Illinois',
830 'IN' => 'Indiana',
831 'IA' => 'Iowa',
832 'KS' => 'Kansas',
833 'KY' => 'Kentucky',
834 'LA' => 'Louisiana',
835 'ME' => 'Maine',
836 'MD' => 'Maryland',
837 'MA' => 'Massachusetts',
838 'MI' => 'Michigan',
839 'MN' => 'Minnesota',
840 'MS' => 'Mississippi',
841 'MO' => 'Missouri',
842 'MT' => 'Montana',
843 'NE' => 'Nebraska',
844 'NV' => 'Nevada',
845 'NH' => 'New Hampshire',
846 'NJ' => 'New Jersey',
847 'NM' => 'New Mexico',
848 'NY' => 'New York',
849 'NC' => 'North Carolina',
850 'ND' => 'North Dakota',
851 'OH' => 'Ohio',
852 'OK' => 'Oklahoma',
853 'OR' => 'Oregon',
854 'PA' => 'Pennyslvania',
855 'PR' => 'Puerto Rico',
856 'RI' => 'Rhode Island',
857 'SC' => 'South Carolina',
858 'SD' => 'South Dakota',
859 'TN' => 'Tennessee',
860 'TX' => 'Texas',
861 'UT' => 'Utah',
862 'VT' => 'Vermont',
863 'VA' => 'Virginia',
864 'VI' => 'Virgin Islands',
865 'WA' => 'Washington',
866 'WV' => 'West Virginia',
867 'WI' => 'Wisconsin',
868 'WY' => 'Wyoming'
869 ];
870 }
......
1 <?php 1 <?php
2 namespace Tz\WordPress\Tools\Notifications; 2 namespace Tz\WordPress\Tools\Notifications;
3 error_reporting(E_ALL^E_DEPRECATED); 3 error_reporting(E_ALL ^ E_DEPRECATED);
4 4
5 use Tz\WordPress\Tools;
6 use Tz\Common; 5 use Tz\Common;
6 use Tz\WordPress\Tools;
7 use Tz\WordPress\Tools\Notifications; 7 use Tz\WordPress\Tools\Notifications;
8 8
9 class Validation
10 {
9 11
10 class Validation { 12 protected $_field_data = [];
11 13 protected $_config_rules = [];
12 protected $_field_data = array(); 14 protected $_error_array = [];
13 protected $_config_rules = array(); 15 protected $_error_messages = [];
14 protected $_error_array = array();
15 protected $_error_messages = array();
16 protected $_error_prefix = '<div class="lblError">'; 16 protected $_error_prefix = '<div class="lblError">';
17 protected $_error_suffix = '</div>'; 17 protected $_error_suffix = '</div>';
18 protected $error_string = ''; 18 protected $error_string = '';
19 protected $_safe_form_data = FALSE; 19 protected $_safe_form_data = false;
20 20
21 function __construct($rules = array()) 21 function __construct($rules = [])
22 { 22 {
23 // Validation rules can be stored in a config file. 23 // Validation rules can be stored in a config file.
24 $this->_config_rules = $rules; 24 $this->_config_rules = $rules;
25 } 25 }
26 26
27 public function get_error_message($key) { 27 public function get_error_message($key)
28 $lang = array(); 28 {
29 $lang = [];
29 $lang['required'] = "The %s field is required."; 30 $lang['required'] = "The %s field is required.";
30 $lang['isset'] = "The %s field must have a value."; 31 $lang['isset'] = "The %s field must have a value.";
31 $lang['valid_email'] = "The %s field must contain a valid email address."; 32 $lang['valid_email'] = "The %s field must contain a valid email address.";
...@@ -45,13 +46,11 @@ class Validation { ...@@ -45,13 +46,11 @@ class Validation {
45 $lang['is_natural'] = "The %s field must contain only positive numbers."; 46 $lang['is_natural'] = "The %s field must contain only positive numbers.";
46 $lang['is_natural_no_zero'] = "The %s field must contain a number greater than zero."; 47 $lang['is_natural_no_zero'] = "The %s field must contain a number greater than zero.";
47 48
48
49 if (isset($lang[$key])) { 49 if (isset($lang[$key])) {
50 return $lang[$key]; 50 return $lang[$key];
51 } else { 51 } else {
52 return FALSE; 52 return false;
53 } 53 }
54
55 } 54 }
56 55
57 56
...@@ -64,42 +63,40 @@ class Validation { ...@@ -64,42 +63,40 @@ class Validation {
64 * rules as input, validates the info, and stores it 63 * rules as input, validates the info, and stores it
65 * 64 *
66 * @access public 65 * @access public
66 *
67 * @param mixed 67 * @param mixed
68 * @param string 68 * @param string
69 *
69 * @return void 70 * @return void
70 */ 71 */
71 function set_rules($field, $label = '', $rules = '') 72 function set_rules($field, $label = '', $rules = '')
72 { 73 {
73 // No reason to set rules if we have no POST data 74 // No reason to set rules if we have no POST data
74 if (count($_POST) == 0) 75 if (count($_POST) == 0) {
75 {
76 return; 76 return;
77 } 77 }
78 78
79 // If an array was passed via the first parameter instead of indidual string 79 // If an array was passed via the first parameter instead of indidual string
80 // values we cycle through it and recursively call this function. 80 // values we cycle through it and recursively call this function.
81 if (is_array($field)) 81 if (is_array($field)) {
82 { 82 foreach ($field as $row) {
83 foreach ($field as $row)
84 {
85 // Houston, we have a problem... 83 // Houston, we have a problem...
86 if ( ! isset($row['field']) OR ! isset($row['rules'])) 84 if (!isset($row['field']) OR !isset($row['rules'])) {
87 {
88 continue; 85 continue;
89 } 86 }
90 87
91 // If the field label wasn't passed we use the field name 88 // If the field label wasn't passed we use the field name
92 $label = ( ! isset($row['label'])) ? $row['field'] : $row['label']; 89 $label = (!isset($row['label'])) ? $row['field'] : $row['label'];
93 90
94 // Here we go! 91 // Here we go!
95 $this->set_rules($row['field'], $label, $row['rules']); 92 $this->set_rules($row['field'], $label, $row['rules']);
96 } 93 }
94
97 return; 95 return;
98 } 96 }
99 97
100 // No fields? Nothing to do... 98 // No fields? Nothing to do...
101 if ( ! is_string($field) OR ! is_string($rules) OR $field == '') 99 if (!is_string($field) OR !is_string($rules) OR $field == '') {
102 {
103 return; 100 return;
104 } 101 }
105 102
...@@ -109,39 +106,34 @@ class Validation { ...@@ -109,39 +106,34 @@ class Validation {
109 // Is the field name an array? We test for the existence of a bracket "[" in 106 // Is the field name an array? We test for the existence of a bracket "[" in
110 // the field name to determine this. If it is an array, we break it apart 107 // the field name to determine this. If it is an array, we break it apart
111 // into its components so that we can fetch the corresponding POST data later 108 // into its components so that we can fetch the corresponding POST data later
112 if (strpos($field, '[') !== FALSE AND preg_match_all('/\[(.*?)\]/', $field, $matches)) 109 if (strpos($field, '[') !== false AND preg_match_all('/\[(.*?)\]/', $field, $matches)) {
113 {
114 // Note: Due to a bug in current() that affects some versions 110 // Note: Due to a bug in current() that affects some versions
115 // of PHP we can not pass function call directly into it 111 // of PHP we can not pass function call directly into it
116 $x = explode('[', $field); 112 $x = explode('[', $field);
117 $indexes[] = current($x); 113 $indexes[] = current($x);
118 114
119 for ($i = 0; $i < count($matches['0']); $i++) 115 for ($i = 0; $i < count($matches['0']); $i++) {
120 { 116 if ($matches['1'][$i] != '') {
121 if ($matches['1'][$i] != '')
122 {
123 $indexes[] = $matches['1'][$i]; 117 $indexes[] = $matches['1'][$i];
124 } 118 }
125 } 119 }
126 120
127 $is_array = TRUE; 121 $is_array = true;
128 } 122 } else {
129 else 123 $indexes = [];
130 { 124 $is_array = false;
131 $indexes = array();
132 $is_array = FALSE;
133 } 125 }
134 126
135 // Build our master array 127 // Build our master array
136 $this->_field_data[$field] = array( 128 $this->_field_data[$field] = [
137 'field' => $field, 129 'field' => $field,
138 'label' => $label, 130 'label' => $label,
139 'rules' => $rules, 131 'rules' => $rules,
140 'is_array' => $is_array, 132 'is_array' => $is_array,
141 'keys' => $indexes, 133 'keys' => $indexes,
142 'postdata' => NULL, 134 'postdata' => null,
143 'error' => '' 135 'error' => ''
144 ); 136 ];
145 } 137 }
146 138
147 // -------------------------------------------------------------------- 139 // --------------------------------------------------------------------
...@@ -153,15 +145,16 @@ class Validation { ...@@ -153,15 +145,16 @@ class Validation {
153 * name has to match the function name that it corresponds to. 145 * name has to match the function name that it corresponds to.
154 * 146 *
155 * @access public 147 * @access public
148 *
156 * @param string 149 * @param string
157 * @param string 150 * @param string
151 *
158 * @return string 152 * @return string
159 */ 153 */
160 function set_message($lang, $val = '') 154 function set_message($lang, $val = '')
161 { 155 {
162 if ( ! is_array($lang)) 156 if (!is_array($lang)) {
163 { 157 $lang = [$lang => $val];
164 $lang = array($lang => $val);
165 } 158 }
166 159
167 $this->_error_messages = array_merge($this->_error_messages, $lang); 160 $this->_error_messages = array_merge($this->_error_messages, $lang);
...@@ -175,8 +168,10 @@ class Validation { ...@@ -175,8 +168,10 @@ class Validation {
175 * Permits a prefix/suffix to be added to each error message 168 * Permits a prefix/suffix to be added to each error message
176 * 169 *
177 * @access public 170 * @access public
171 *
178 * @param string 172 * @param string
179 * @param string 173 * @param string
174 *
180 * @return void 175 * @return void
181 */ 176 */
182 function set_error_delimiters($prefix = '<p>', $suffix = '</p>') 177 function set_error_delimiters($prefix = '<p>', $suffix = '</p>')
...@@ -193,23 +188,22 @@ class Validation { ...@@ -193,23 +188,22 @@ class Validation {
193 * Gets the error message associated with a particular field 188 * Gets the error message associated with a particular field
194 * 189 *
195 * @access public 190 * @access public
191 *
196 * @param string the field name 192 * @param string the field name
193 *
197 * @return void 194 * @return void
198 */ 195 */
199 function error($field = '', $prefix = '', $suffix = '') 196 function error($field = '', $prefix = '', $suffix = '')
200 { 197 {
201 if ( ! isset($this->_field_data[$field]['error']) OR $this->_field_data[$field]['error'] == '') 198 if (!isset($this->_field_data[$field]['error']) OR $this->_field_data[$field]['error'] == '') {
202 {
203 return ''; 199 return '';
204 } 200 }
205 201
206 if ($prefix == '') 202 if ($prefix == '') {
207 {
208 $prefix = $this->_error_prefix; 203 $prefix = $this->_error_prefix;
209 } 204 }
210 205
211 if ($suffix == '') 206 if ($suffix == '') {
212 {
213 $suffix = $this->_error_suffix; 207 $suffix = $this->_error_suffix;
214 } 208 }
215 209
...@@ -224,34 +218,31 @@ class Validation { ...@@ -224,34 +218,31 @@ class Validation {
224 * Returns the error messages as a string, wrapped in the error delimiters 218 * Returns the error messages as a string, wrapped in the error delimiters
225 * 219 *
226 * @access public 220 * @access public
221 *
227 * @param string 222 * @param string
228 * @param string 223 * @param string
224 *
229 * @return str 225 * @return str
230 */ 226 */
231 function error_string($prefix = '', $suffix = '') 227 function error_string($prefix = '', $suffix = '')
232 { 228 {
233 // No errrors, validation passes! 229 // No errrors, validation passes!
234 if (count($this->_error_array) === 0) 230 if (count($this->_error_array) === 0) {
235 {
236 return ''; 231 return '';
237 } 232 }
238 233
239 if ($prefix == '') 234 if ($prefix == '') {
240 {
241 $prefix = $this->_error_prefix; 235 $prefix = $this->_error_prefix;
242 } 236 }
243 237
244 if ($suffix == '') 238 if ($suffix == '') {
245 {
246 $suffix = $this->_error_suffix; 239 $suffix = $this->_error_suffix;
247 } 240 }
248 241
249 // Generate the error string 242 // Generate the error string
250 $str = ''; 243 $str = '';
251 foreach ($this->_error_array as $val) 244 foreach ($this->_error_array as $val) {
252 { 245 if ($val != '') {
253 if ($val != '')
254 {
255 $str .= $prefix.$val.$suffix."\n"; 246 $str .= $prefix.$val.$suffix."\n";
256 } 247 }
257 } 248 }
...@@ -272,55 +263,43 @@ class Validation { ...@@ -272,55 +263,43 @@ class Validation {
272 function run($group = '') 263 function run($group = '')
273 { 264 {
274 // Do we even have any data to process? Mm? 265 // Do we even have any data to process? Mm?
275 if (count($_POST) == 0) 266 if (count($_POST) == 0) {
276 { 267 return false;
277 return FALSE;
278 } 268 }
279 269
280 // Does the _field_data array containing the validation rules exist? 270 // Does the _field_data array containing the validation rules exist?
281 // If not, we look to see if they were assigned via a config file 271 // If not, we look to see if they were assigned via a config file
282 if (count($this->_field_data) == 0) 272 if (count($this->_field_data) == 0) {
283 {
284 // No validation rules? We're done... 273 // No validation rules? We're done...
285 if (count($this->_config_rules) == 0) 274 if (count($this->_config_rules) == 0) {
286 { 275 return false;
287 return FALSE;
288 } 276 }
289 277
290 // Is there a validation rule for the particular URI being accessed? 278 // Is there a validation rule for the particular URI being accessed?
291 $uri = ($group == '') ? trim($this->CI->uri->ruri_string(), '/') : $group; 279 $uri = ($group == '') ? trim($this->CI->uri->ruri_string(), '/') : $group;
292 280
293 if ($uri != '' AND isset($this->_config_rules[$uri])) 281 if ($uri != '' AND isset($this->_config_rules[$uri])) {
294 {
295 $this->set_rules($this->_config_rules[$uri]); 282 $this->set_rules($this->_config_rules[$uri]);
296 } 283 } else {
297 else
298 {
299 $this->set_rules($this->_config_rules); 284 $this->set_rules($this->_config_rules);
300 } 285 }
301 286
302 // We're we able to set the rules correctly? 287 // We're we able to set the rules correctly?
303 if (count($this->_field_data) == 0) 288 if (count($this->_field_data) == 0) {
304 { 289 return false;
305 return FALSE;
306 } 290 }
307 } 291 }
308 292
309 // Cycle through the rules for each field, match the 293 // Cycle through the rules for each field, match the
310 // corresponding $_POST item and test for errors 294 // corresponding $_POST item and test for errors
311 foreach ($this->_field_data as $field => $row) 295 foreach ($this->_field_data as $field => $row) {
312 {
313 // Fetch the data from the corresponding $_POST array and cache it in the _field_data array. 296 // Fetch the data from the corresponding $_POST array and cache it in the _field_data array.
314 // Depending on whether the field name is an array or a string will determine where we get it from. 297 // Depending on whether the field name is an array or a string will determine where we get it from.
315 298
316 if ($row['is_array'] == TRUE) 299 if ($row['is_array'] == true) {
317 {
318 $this->_field_data[$field]['postdata'] = $this->_reduce_array($_POST, $row['keys']); 300 $this->_field_data[$field]['postdata'] = $this->_reduce_array($_POST, $row['keys']);
319 } 301 } else {
320 else 302 if (isset($_POST[$field]) AND $_POST[$field] != "") {
321 {
322 if (isset($_POST[$field]) AND $_POST[$field] != "")
323 {
324 $this->_field_data[$field]['postdata'] = $_POST[$field]; 303 $this->_field_data[$field]['postdata'] = $_POST[$field];
325 } 304 }
326 } 305 }
...@@ -331,22 +310,20 @@ class Validation { ...@@ -331,22 +310,20 @@ class Validation {
331 // Did we end up with any errors? 310 // Did we end up with any errors?
332 $total_errors = count($this->_error_array); 311 $total_errors = count($this->_error_array);
333 312
334 if ($total_errors > 0) 313 if ($total_errors > 0) {
335 { 314 $this->_safe_form_data = true;
336 $this->_safe_form_data = TRUE;
337 } 315 }
338 316
339 // Now we need to re-set the POST data with the new, processed data 317 // Now we need to re-set the POST data with the new, processed data
340 $this->_reset_post_array(); 318 $this->_reset_post_array();
341 319
342 // No errors, validation passes! 320 // No errors, validation passes!
343 if ($total_errors == 0) 321 if ($total_errors == 0) {
344 { 322 return true;
345 return TRUE;
346 } 323 }
347 324
348 // Validation fails 325 // Validation fails
349 return FALSE; 326 return false;
350 } 327 }
351 328
352 // -------------------------------------------------------------------- 329 // --------------------------------------------------------------------
...@@ -355,28 +332,23 @@ class Validation { ...@@ -355,28 +332,23 @@ class Validation {
355 * Traverse a multidimensional $_POST array index until the data is found 332 * Traverse a multidimensional $_POST array index until the data is found
356 * 333 *
357 * @access private 334 * @access private
335 *
358 * @param array 336 * @param array
359 * @param array 337 * @param array
360 * @param integer 338 * @param integer
339 *
361 * @return mixed 340 * @return mixed
362 */ 341 */
363 function _reduce_array($array, $keys, $i = 0) 342 function _reduce_array($array, $keys, $i = 0)
364 { 343 {
365 if (is_array($array)) 344 if (is_array($array)) {
366 { 345 if (isset($keys[$i])) {
367 if (isset($keys[$i])) 346 if (isset($array[$keys[$i]])) {
368 { 347 $array = $this->_reduce_array($array[$keys[$i]], $keys, ($i + 1));
369 if (isset($array[$keys[$i]])) 348 } else {
370 { 349 return null;
371 $array = $this->_reduce_array($array[$keys[$i]], $keys, ($i+1));
372 }
373 else
374 {
375 return NULL;
376 }
377 } 350 }
378 else 351 } else {
379 {
380 return $array; 352 return $array;
381 } 353 }
382 } 354 }
...@@ -394,47 +366,33 @@ class Validation { ...@@ -394,47 +366,33 @@ class Validation {
394 */ 366 */
395 function _reset_post_array() 367 function _reset_post_array()
396 { 368 {
397 foreach ($this->_field_data as $field => $row) 369 foreach ($this->_field_data as $field => $row) {
398 { 370 if (!is_null($row['postdata'])) {
399 if ( ! is_null($row['postdata'])) 371 if ($row['is_array'] == false) {
400 { 372 if (isset($_POST[$row['field']])) {
401 if ($row['is_array'] == FALSE)
402 {
403 if (isset($_POST[$row['field']]))
404 {
405 $_POST[$row['field']] = $this->prep_for_form($row['postdata']); 373 $_POST[$row['field']] = $this->prep_for_form($row['postdata']);
406 } 374 }
407 } 375 } else {
408 else
409 {
410 // start with a reference 376 // start with a reference
411 $post_ref =& $_POST; 377 $post_ref =& $_POST;
412 378
413 // before we assign values, make a reference to the right POST key 379 // before we assign values, make a reference to the right POST key
414 if (count($row['keys']) == 1) 380 if (count($row['keys']) == 1) {
415 {
416 $post_ref =& $post_ref[current($row['keys'])]; 381 $post_ref =& $post_ref[current($row['keys'])];
417 } 382 } else {
418 else 383 foreach ($row['keys'] as $val) {
419 {
420 foreach ($row['keys'] as $val)
421 {
422 $post_ref =& $post_ref[$val]; 384 $post_ref =& $post_ref[$val];
423 } 385 }
424 } 386 }
425 387
426 if (is_array($row['postdata'])) 388 if (is_array($row['postdata'])) {
427 { 389 $array = [];
428 $array = array(); 390 foreach ($row['postdata'] as $k => $v) {
429 foreach ($row['postdata'] as $k => $v)
430 {
431 $array[$k] = $this->prep_for_form($v); 391 $array[$k] = $this->prep_for_form($v);
432 } 392 }
433 393
434 $post_ref = $array; 394 $post_ref = $array;
435 } 395 } else {
436 else
437 {
438 $post_ref = $this->prep_for_form($row['postdata']); 396 $post_ref = $this->prep_for_form($row['postdata']);
439 } 397 }
440 } 398 }
...@@ -448,19 +406,19 @@ class Validation { ...@@ -448,19 +406,19 @@ class Validation {
448 * Executes the Validation routines 406 * Executes the Validation routines
449 * 407 *
450 * @access private 408 * @access private
409 *
451 * @param array 410 * @param array
452 * @param array 411 * @param array
453 * @param mixed 412 * @param mixed
454 * @param integer 413 * @param integer
414 *
455 * @return mixed 415 * @return mixed
456 */ 416 */
457 function _execute($row, $rules, $postdata = NULL, $cycles = 0) 417 function _execute($row, $rules, $postdata = null, $cycles = 0)
458 { 418 {
459 // If the $_POST data is an array we will run a recursive call 419 // If the $_POST data is an array we will run a recursive call
460 if (is_array($postdata)) 420 if (is_array($postdata)) {
461 { 421 foreach ($postdata as $key => $val) {
462 foreach ($postdata as $key => $val)
463 {
464 $this->_execute($row, $rules, $val, $cycles); 422 $this->_execute($row, $rules, $val, $cycles);
465 $cycles++; 423 $cycles++;
466 } 424 }
...@@ -471,17 +429,13 @@ class Validation { ...@@ -471,17 +429,13 @@ class Validation {
471 // -------------------------------------------------------------------- 429 // --------------------------------------------------------------------
472 430
473 // If the field is blank, but NOT required, no further tests are necessary 431 // If the field is blank, but NOT required, no further tests are necessary
474 $callback = FALSE; 432 $callback = false;
475 if ( ! in_array('required', $rules) AND is_null($postdata)) 433 if (!in_array('required', $rules) AND is_null($postdata)) {
476 {
477 // Before we bail out, does the rule contain a callback? 434 // Before we bail out, does the rule contain a callback?
478 if (preg_match("/(callback_\w+)/", implode(' ', $rules), $match)) 435 if (preg_match("/(callback_\w+)/", implode(' ', $rules), $match)) {
479 { 436 $callback = true;
480 $callback = TRUE; 437 $rules = (['1' => $match[1]]);
481 $rules = (array('1' => $match[1])); 438 } else {
482 }
483 else
484 {
485 return; 439 return;
486 } 440 }
487 } 441 }
...@@ -489,22 +443,16 @@ class Validation { ...@@ -489,22 +443,16 @@ class Validation {
489 // -------------------------------------------------------------------- 443 // --------------------------------------------------------------------
490 444
491 // Isset Test. Typically this rule will only apply to checkboxes. 445 // Isset Test. Typically this rule will only apply to checkboxes.
492 if (is_null($postdata) AND $callback == FALSE) 446 if (is_null($postdata) AND $callback == false) {
493 { 447 if (in_array('isset', $rules, true) OR in_array('required', $rules)) {
494 if (in_array('isset', $rules, TRUE) OR in_array('required', $rules))
495 {
496 // Set the message type 448 // Set the message type
497 $type = (in_array('required', $rules)) ? 'required' : 'isset'; 449 $type = (in_array('required', $rules)) ? 'required' : 'isset';
498 450
499 if ( ! isset($this->_error_messages[$type])) 451 if (!isset($this->_error_messages[$type])) {
500 { 452 if (false === ($line = $this->get_error_message($type))) {
501 if (FALSE === ($line = $this->get_error_message($type)))
502 {
503 $line = 'The field was not set'; 453 $line = 'The field was not set';
504 } 454 }
505 } 455 } else {
506 else
507 {
508 $line = $this->_error_messages[$type]; 456 $line = $this->_error_messages[$type];
509 } 457 }
510 458
...@@ -514,8 +462,7 @@ class Validation { ...@@ -514,8 +462,7 @@ class Validation {
514 // Save the error message 462 // Save the error message
515 $this->_field_data[$row['field']]['error'] = $message; 463 $this->_field_data[$row['field']]['error'] = $message;
516 464
517 if ( ! isset($this->_error_array[$row['field']])) 465 if (!isset($this->_error_array[$row['field']])) {
518 {
519 $this->_error_array[$row['field']] = $message; 466 $this->_error_array[$row['field']] = $message;
520 } 467 }
521 } 468 }
...@@ -526,53 +473,44 @@ class Validation { ...@@ -526,53 +473,44 @@ class Validation {
526 // -------------------------------------------------------------------- 473 // --------------------------------------------------------------------
527 474
528 // Cycle through each rule and run it 475 // Cycle through each rule and run it
529 foreach ($rules As $rule) 476 foreach ($rules As $rule) {
530 { 477 $_in_array = false;
531 $_in_array = FALSE;
532 478
533 // We set the $postdata variable with the current data in our master array so that 479 // We set the $postdata variable with the current data in our master array so that
534 // each cycle of the loop is dealing with the processed data from the last cycle 480 // each cycle of the loop is dealing with the processed data from the last cycle
535 if ($row['is_array'] == TRUE AND is_array($this->_field_data[$row['field']]['postdata'])) 481 if ($row['is_array'] == true AND is_array($this->_field_data[$row['field']]['postdata'])) {
536 {
537 // We shouldn't need this safety, but just in case there isn't an array index 482 // We shouldn't need this safety, but just in case there isn't an array index
538 // associated with this cycle we'll bail out 483 // associated with this cycle we'll bail out
539 if ( ! isset($this->_field_data[$row['field']]['postdata'][$cycles])) 484 if (!isset($this->_field_data[$row['field']]['postdata'][$cycles])) {
540 {
541 continue; 485 continue;
542 } 486 }
543 487
544 $postdata = $this->_field_data[$row['field']]['postdata'][$cycles]; 488 $postdata = $this->_field_data[$row['field']]['postdata'][$cycles];
545 $_in_array = TRUE; 489 $_in_array = true;
546 } 490 } else {
547 else
548 {
549 $postdata = $this->_field_data[$row['field']]['postdata']; 491 $postdata = $this->_field_data[$row['field']]['postdata'];
550 } 492 }
551 493
552 // -------------------------------------------------------------------- 494 // --------------------------------------------------------------------
553 495
554 // Is the rule a callback? 496 // Is the rule a callback?
555 $callback = FALSE; 497 $callback = false;
556 if (substr($rule, 0, 9) == 'callback_') 498 if (substr($rule, 0, 9) == 'callback_') {
557 {
558 $rule = substr($rule, 9); 499 $rule = substr($rule, 9);
559 $callback = TRUE; 500 $callback = true;
560 } 501 }
561 502
562 // Strip the parameter (if exists) from the rule 503 // Strip the parameter (if exists) from the rule
563 // Rules can contain a parameter: max_length[5] 504 // Rules can contain a parameter: max_length[5]
564 $param = FALSE; 505 $param = false;
565 if (preg_match("/(.*?)\[(.*?)\]/", $rule, $match)) 506 if (preg_match("/(.*?)\[(.*?)\]/", $rule, $match)) {
566 {
567 $rule = $match[1]; 507 $rule = $match[1];
568 $param = $match[2]; 508 $param = $match[2];
569 } 509 }
570 510
571 // Call the function that corresponds to the rule 511 // Call the function that corresponds to the rule
572 if ($callback === TRUE) 512 if ($callback === true) {
573 { 513 if (!method_exists($this->CI, $rule)) {
574 if ( ! method_exists($this->CI, $rule))
575 {
576 continue; 514 continue;
577 } 515 }
578 516
...@@ -580,37 +518,27 @@ class Validation { ...@@ -580,37 +518,27 @@ class Validation {
580 $result = $this->CI->$rule($postdata, $param); 518 $result = $this->CI->$rule($postdata, $param);
581 519
582 // Re-assign the result to the master data array 520 // Re-assign the result to the master data array
583 if ($_in_array == TRUE) 521 if ($_in_array == true) {
584 {
585 $this->_field_data[$row['field']]['postdata'][$cycles] = (is_bool($result)) ? $postdata : $result; 522 $this->_field_data[$row['field']]['postdata'][$cycles] = (is_bool($result)) ? $postdata : $result;
586 } 523 } else {
587 else
588 {
589 $this->_field_data[$row['field']]['postdata'] = (is_bool($result)) ? $postdata : $result; 524 $this->_field_data[$row['field']]['postdata'] = (is_bool($result)) ? $postdata : $result;
590 } 525 }
591 526
592 // If the field isn't required and we just processed a callback we'll move on... 527 // If the field isn't required and we just processed a callback we'll move on...
593 if ( ! in_array('required', $rules, TRUE) AND $result !== FALSE) 528 if (!in_array('required', $rules, true) AND $result !== false) {
594 {
595 continue; 529 continue;
596 } 530 }
597 } 531 } else {
598 else 532 if (!method_exists($this, $rule)) {
599 {
600 if ( ! method_exists($this, $rule))
601 {
602 // If our own wrapper function doesn't exist we see if a native PHP function does. 533 // If our own wrapper function doesn't exist we see if a native PHP function does.
603 // Users can use any native PHP function call that has one param. 534 // Users can use any native PHP function call that has one param.
604 if (function_exists($rule)) 535 if (function_exists($rule)) {
605 {
606 $result = $rule($postdata); 536 $result = $rule($postdata);
607 537
608 if ($_in_array == TRUE) 538 if ($_in_array == true) {
609 { 539 $this->_field_data[$row['field']]['postdata'][$cycles] = (is_bool($result)) ? $postdata
610 $this->_field_data[$row['field']]['postdata'][$cycles] = (is_bool($result)) ? $postdata : $result; 540 : $result;
611 } 541 } else {
612 else
613 {
614 $this->_field_data[$row['field']]['postdata'] = (is_bool($result)) ? $postdata : $result; 542 $this->_field_data[$row['field']]['postdata'] = (is_bool($result)) ? $postdata : $result;
615 } 543 }
616 } 544 }
...@@ -620,35 +548,26 @@ class Validation { ...@@ -620,35 +548,26 @@ class Validation {
620 548
621 $result = $this->$rule($postdata, $param); 549 $result = $this->$rule($postdata, $param);
622 550
623 if ($_in_array == TRUE) 551 if ($_in_array == true) {
624 {
625 $this->_field_data[$row['field']]['postdata'][$cycles] = (is_bool($result)) ? $postdata : $result; 552 $this->_field_data[$row['field']]['postdata'][$cycles] = (is_bool($result)) ? $postdata : $result;
626 } 553 } else {
627 else
628 {
629 $this->_field_data[$row['field']]['postdata'] = (is_bool($result)) ? $postdata : $result; 554 $this->_field_data[$row['field']]['postdata'] = (is_bool($result)) ? $postdata : $result;
630 } 555 }
631 } 556 }
632 557
633 // Did the rule test negatively? If so, grab the error. 558 // Did the rule test negatively? If so, grab the error.
634 if ($result === FALSE) 559 if ($result === false) {
635 { 560 if (!isset($this->_error_messages[$rule])) {
636 if ( ! isset($this->_error_messages[$rule])) 561 if (false === ($line = $this->get_error_message($rule))) {
637 {
638 if (FALSE === ($line = $this->get_error_message($rule)))
639 {
640 $line = 'Unable to access an error message corresponding to your field name.'; 562 $line = 'Unable to access an error message corresponding to your field name.';
641 } 563 }
642 } 564 } else {
643 else
644 {
645 $line = $this->_error_messages[$rule]; 565 $line = $this->_error_messages[$rule];
646 } 566 }
647 567
648 // Is the parameter we are inserting into the error message the name 568 // Is the parameter we are inserting into the error message the name
649 // of another field? If so we need to grab its "field label" 569 // of another field? If so we need to grab its "field label"
650 if (isset($this->_field_data[$param]) AND isset($this->_field_data[$param]['label'])) 570 if (isset($this->_field_data[$param]) AND isset($this->_field_data[$param]['label'])) {
651 {
652 $param = $this->_field_data[$param]['label']; 571 $param = $this->_field_data[$param]['label'];
653 } 572 }
654 573
...@@ -658,8 +577,7 @@ class Validation { ...@@ -658,8 +577,7 @@ class Validation {
658 // Save the error message 577 // Save the error message
659 $this->_field_data[$row['field']]['error'] = $message; 578 $this->_field_data[$row['field']]['error'] = $message;
660 579
661 if ( ! isset($this->_error_array[$row['field']])) 580 if (!isset($this->_error_array[$row['field']])) {
662 {
663 $this->_error_array[$row['field']] = $message; 581 $this->_error_array[$row['field']] = $message;
664 } 582 }
665 583
...@@ -671,7 +589,6 @@ class Validation { ...@@ -671,7 +589,6 @@ class Validation {
671 function form_error($field = '', $prefix = '', $suffix = '') 589 function form_error($field = '', $prefix = '', $suffix = '')
672 { 590 {
673 591
674
675 return $this->error($field, $prefix, $suffix); 592 return $this->error($field, $prefix, $suffix);
676 } 593 }
677 594
...@@ -686,21 +603,21 @@ class Validation { ...@@ -686,21 +603,21 @@ class Validation {
686 * Translate a field name 603 * Translate a field name
687 * 604 *
688 * @access private 605 * @access private
606 *
689 * @param string the field name 607 * @param string the field name
608 *
690 * @return string 609 * @return string
691 */ 610 */
692 function _translate_fieldname($fieldname) 611 function _translate_fieldname($fieldname)
693 { 612 {
694 // Do we need to translate the field name? 613 // Do we need to translate the field name?
695 // We look for the prefix lang: to determine this 614 // We look for the prefix lang: to determine this
696 if (substr($fieldname, 0, 5) == 'lang:') 615 if (substr($fieldname, 0, 5) == 'lang:') {
697 {
698 // Grab the variable 616 // Grab the variable
699 $line = substr($fieldname, 5); 617 $line = substr($fieldname, 5);
700 618
701 // Were we able to translate the field name? If not we use $line 619 // Were we able to translate the field name? If not we use $line
702 if (FALSE === ($fieldname = $this->get_error_message($line))) 620 if (false === ($fieldname = $this->get_error_message($line))) {
703 {
704 return $line; 621 return $line;
705 } 622 }
706 } 623 }
...@@ -717,14 +634,15 @@ class Validation { ...@@ -717,14 +634,15 @@ class Validation {
717 * with, or, if that value doesn't exist, with the default 634 * with, or, if that value doesn't exist, with the default
718 * 635 *
719 * @access public 636 * @access public
637 *
720 * @param string the field name 638 * @param string the field name
721 * @param string 639 * @param string
640 *
722 * @return mixed 641 * @return mixed
723 */ 642 */
724 function set_value($field = '', $default = '') 643 function set_value($field = '', $default = '')
725 { 644 {
726 if ( ! isset($this->_field_data[$field])) 645 if (!isset($this->_field_data[$field])) {
727 {
728 return $default; 646 return $default;
729 } 647 }
730 648
...@@ -740,34 +658,30 @@ class Validation { ...@@ -740,34 +658,30 @@ class Validation {
740 * selected in the event of an error 658 * selected in the event of an error
741 * 659 *
742 * @access public 660 * @access public
661 *
743 * @param string 662 * @param string
744 * @param string 663 * @param string
664 *
745 * @return string 665 * @return string
746 */ 666 */
747 function set_select($field = '', $value = '', $default = FALSE) 667 function set_select($field = '', $value = '', $default = false)
748 {
749 if ( ! isset($this->_field_data[$field]) OR ! isset($this->_field_data[$field]['postdata']))
750 {
751 if ($default === TRUE AND count($this->_field_data) === 0)
752 { 668 {
669 if (!isset($this->_field_data[$field]) OR !isset($this->_field_data[$field]['postdata'])) {
670 if ($default === true AND count($this->_field_data) === 0) {
753 return ' selected="selected"'; 671 return ' selected="selected"';
754 } 672 }
673
755 return ''; 674 return '';
756 } 675 }
757 676
758 $field = $this->_field_data[$field]['postdata']; 677 $field = $this->_field_data[$field]['postdata'];
759 678
760 if (is_array($field)) 679 if (is_array($field)) {
761 { 680 if (!in_array($value, $field)) {
762 if ( ! in_array($value, $field))
763 {
764 return ''; 681 return '';
765 } 682 }
766 } 683 } else {
767 else 684 if (($field == '' OR $value == '') OR ($field != $value)) {
768 {
769 if (($field == '' OR $value == '') OR ($field != $value))
770 {
771 return ''; 685 return '';
772 } 686 }
773 } 687 }
...@@ -784,34 +698,30 @@ class Validation { ...@@ -784,34 +698,30 @@ class Validation {
784 * selected in the event of an error 698 * selected in the event of an error
785 * 699 *
786 * @access public 700 * @access public
701 *
787 * @param string 702 * @param string
788 * @param string 703 * @param string
704 *
789 * @return string 705 * @return string
790 */ 706 */
791 function set_radio($field = '', $value = '', $default = FALSE) 707 function set_radio($field = '', $value = '', $default = false)
792 {
793 if ( ! isset($this->_field_data[$field]) OR ! isset($this->_field_data[$field]['postdata']))
794 {
795 if ($default === TRUE AND count($this->_field_data) === 0)
796 { 708 {
709 if (!isset($this->_field_data[$field]) OR !isset($this->_field_data[$field]['postdata'])) {
710 if ($default === true AND count($this->_field_data) === 0) {
797 return ' checked="checked"'; 711 return ' checked="checked"';
798 } 712 }
713
799 return ''; 714 return '';
800 } 715 }
801 716
802 $field = $this->_field_data[$field]['postdata']; 717 $field = $this->_field_data[$field]['postdata'];
803 718
804 if (is_array($field)) 719 if (is_array($field)) {
805 { 720 if (!in_array($value, $field)) {
806 if ( ! in_array($value, $field))
807 {
808 return ''; 721 return '';
809 } 722 }
810 } 723 } else {
811 else 724 if (($field == '' OR $value == '') OR ($field != $value)) {
812 {
813 if (($field == '' OR $value == '') OR ($field != $value))
814 {
815 return ''; 725 return '';
816 } 726 }
817 } 727 }
...@@ -828,34 +738,30 @@ class Validation { ...@@ -828,34 +738,30 @@ class Validation {
828 * selected in the event of an error 738 * selected in the event of an error
829 * 739 *
830 * @access public 740 * @access public
741 *
831 * @param string 742 * @param string
832 * @param string 743 * @param string
744 *
833 * @return string 745 * @return string
834 */ 746 */
835 function set_checkbox($field = '', $value = '', $default = FALSE) 747 function set_checkbox($field = '', $value = '', $default = false)
836 {
837 if ( ! isset($this->_field_data[$field]) OR ! isset($this->_field_data[$field]['postdata']))
838 {
839 if ($default === TRUE AND count($this->_field_data) === 0)
840 { 748 {
749 if (!isset($this->_field_data[$field]) OR !isset($this->_field_data[$field]['postdata'])) {
750 if ($default === true AND count($this->_field_data) === 0) {
841 return ' checked="checked"'; 751 return ' checked="checked"';
842 } 752 }
753
843 return ''; 754 return '';
844 } 755 }
845 756
846 $field = $this->_field_data[$field]['postdata']; 757 $field = $this->_field_data[$field]['postdata'];
847 758
848 if (is_array($field)) 759 if (is_array($field)) {
849 { 760 if (!in_array($value, $field)) {
850 if ( ! in_array($value, $field))
851 {
852 return ''; 761 return '';
853 } 762 }
854 } 763 } else {
855 else 764 if (($field == '' OR $value == '') OR ($field != $value)) {
856 {
857 if (($field == '' OR $value == '') OR ($field != $value))
858 {
859 return ''; 765 return '';
860 } 766 }
861 } 767 }
...@@ -869,18 +775,17 @@ class Validation { ...@@ -869,18 +775,17 @@ class Validation {
869 * Required 775 * Required
870 * 776 *
871 * @access public 777 * @access public
778 *
872 * @param string 779 * @param string
780 *
873 * @return bool 781 * @return bool
874 */ 782 */
875 function required($str) 783 function required($str)
876 { 784 {
877 if ( ! is_array($str)) 785 if (!is_array($str)) {
878 { 786 return (trim($str) == '') ? false : true;
879 return (trim($str) == '') ? FALSE : TRUE; 787 } else {
880 } 788 return (!empty($str));
881 else
882 {
883 return ( ! empty($str));
884 } 789 }
885 } 790 }
886 791
...@@ -890,20 +795,21 @@ class Validation { ...@@ -890,20 +795,21 @@ class Validation {
890 * Match one field to another 795 * Match one field to another
891 * 796 *
892 * @access public 797 * @access public
798 *
893 * @param string 799 * @param string
894 * @param field 800 * @param field
801 *
895 * @return bool 802 * @return bool
896 */ 803 */
897 function matches($str, $field) 804 function matches($str, $field)
898 { 805 {
899 if ( ! isset($_POST[$field])) 806 if (!isset($_POST[$field])) {
900 { 807 return false;
901 return FALSE;
902 } 808 }
903 809
904 $field = $_POST[$field]; 810 $field = $_POST[$field];
905 811
906 return ($str !== $field) ? FALSE : TRUE; 812 return ($str !== $field) ? false : true;
907 } 813 }
908 814
909 // -------------------------------------------------------------------- 815 // --------------------------------------------------------------------
...@@ -912,23 +818,23 @@ class Validation { ...@@ -912,23 +818,23 @@ class Validation {
912 * Minimum Length 818 * Minimum Length
913 * 819 *
914 * @access public 820 * @access public
821 *
915 * @param string 822 * @param string
916 * @param value 823 * @param value
824 *
917 * @return bool 825 * @return bool
918 */ 826 */
919 function min_length($str, $val) 827 function min_length($str, $val)
920 { 828 {
921 if (preg_match("/[^0-9]/", $val)) 829 if (preg_match("/[^0-9]/", $val)) {
922 { 830 return false;
923 return FALSE;
924 } 831 }
925 832
926 if (function_exists('mb_strlen')) 833 if (function_exists('mb_strlen')) {
927 { 834 return (mb_strlen($str) < $val) ? false : true;
928 return (mb_strlen($str) < $val) ? FALSE : TRUE;
929 } 835 }
930 836
931 return (strlen($str) < $val) ? FALSE : TRUE; 837 return (strlen($str) < $val) ? false : true;
932 } 838 }
933 839
934 // -------------------------------------------------------------------- 840 // --------------------------------------------------------------------
...@@ -937,23 +843,23 @@ class Validation { ...@@ -937,23 +843,23 @@ class Validation {
937 * Max Length 843 * Max Length
938 * 844 *
939 * @access public 845 * @access public
846 *
940 * @param string 847 * @param string
941 * @param value 848 * @param value
849 *
942 * @return bool 850 * @return bool
943 */ 851 */
944 function max_length($str, $val) 852 function max_length($str, $val)
945 { 853 {
946 if (preg_match("/[^0-9]/", $val)) 854 if (preg_match("/[^0-9]/", $val)) {
947 { 855 return false;
948 return FALSE;
949 } 856 }
950 857
951 if (function_exists('mb_strlen')) 858 if (function_exists('mb_strlen')) {
952 { 859 return (mb_strlen($str) > $val) ? false : true;
953 return (mb_strlen($str) > $val) ? FALSE : TRUE;
954 } 860 }
955 861
956 return (strlen($str) > $val) ? FALSE : TRUE; 862 return (strlen($str) > $val) ? false : true;
957 } 863 }
958 864
959 // -------------------------------------------------------------------- 865 // --------------------------------------------------------------------
...@@ -962,23 +868,23 @@ class Validation { ...@@ -962,23 +868,23 @@ class Validation {
962 * Exact Length 868 * Exact Length
963 * 869 *
964 * @access public 870 * @access public
871 *
965 * @param string 872 * @param string
966 * @param value 873 * @param value
874 *
967 * @return bool 875 * @return bool
968 */ 876 */
969 function exact_length($str, $val) 877 function exact_length($str, $val)
970 { 878 {
971 if (preg_match("/[^0-9]/", $val)) 879 if (preg_match("/[^0-9]/", $val)) {
972 { 880 return false;
973 return FALSE;
974 } 881 }
975 882
976 if (function_exists('mb_strlen')) 883 if (function_exists('mb_strlen')) {
977 { 884 return (mb_strlen($str) != $val) ? false : true;
978 return (mb_strlen($str) != $val) ? FALSE : TRUE;
979 } 885 }
980 886
981 return (strlen($str) != $val) ? FALSE : TRUE; 887 return (strlen($str) != $val) ? false : true;
982 } 888 }
983 889
984 // -------------------------------------------------------------------- 890 // --------------------------------------------------------------------
...@@ -987,12 +893,15 @@ class Validation { ...@@ -987,12 +893,15 @@ class Validation {
987 * Valid Email 893 * Valid Email
988 * 894 *
989 * @access public 895 * @access public
896 *
990 * @param string 897 * @param string
898 *
991 * @return bool 899 * @return bool
992 */ 900 */
993 function valid_email($str) 901 function valid_email($str)
994 { 902 {
995 return ( ! preg_match("/^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/ix", $str)) ? FALSE : TRUE; 903 return (!preg_match("/^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/ix", $str)) ? false
904 : true;
996 } 905 }
997 906
998 // -------------------------------------------------------------------- 907 // --------------------------------------------------------------------
...@@ -1001,25 +910,24 @@ class Validation { ...@@ -1001,25 +910,24 @@ class Validation {
1001 * Valid Emails 910 * Valid Emails
1002 * 911 *
1003 * @access public 912 * @access public
913 *
1004 * @param string 914 * @param string
915 *
1005 * @return bool 916 * @return bool
1006 */ 917 */
1007 function valid_emails($str) 918 function valid_emails($str)
1008 { 919 {
1009 if (strpos($str, ',') === FALSE) 920 if (strpos($str, ',') === false) {
1010 {
1011 return $this->valid_email(trim($str)); 921 return $this->valid_email(trim($str));
1012 } 922 }
1013 923
1014 foreach(explode(',', $str) as $email) 924 foreach (explode(',', $str) as $email) {
1015 { 925 if (trim($email) != '' && $this->valid_email(trim($email)) === false) {
1016 if (trim($email) != '' && $this->valid_email(trim($email)) === FALSE) 926 return false;
1017 {
1018 return FALSE;
1019 } 927 }
1020 } 928 }
1021 929
1022 return TRUE; 930 return true;
1023 } 931 }
1024 932
1025 // -------------------------------------------------------------------- 933 // --------------------------------------------------------------------
...@@ -1028,7 +936,9 @@ class Validation { ...@@ -1028,7 +936,9 @@ class Validation {
1028 * Validate IP Address 936 * Validate IP Address
1029 * 937 *
1030 * @access public 938 * @access public
939 *
1031 * @param string 940 * @param string
941 *
1032 * @return string 942 * @return string
1033 */ 943 */
1034 function valid_ip($ip) 944 function valid_ip($ip)
...@@ -1042,12 +952,14 @@ class Validation { ...@@ -1042,12 +952,14 @@ class Validation {
1042 * Alpha 952 * Alpha
1043 * 953 *
1044 * @access public 954 * @access public
955 *
1045 * @param string 956 * @param string
957 *
1046 * @return bool 958 * @return bool
1047 */ 959 */
1048 function alpha($str) 960 function alpha($str)
1049 { 961 {
1050 return ( ! preg_match("/^([a-z])+$/i", $str)) ? FALSE : TRUE; 962 return (!preg_match("/^([a-z])+$/i", $str)) ? false : true;
1051 } 963 }
1052 964
1053 // -------------------------------------------------------------------- 965 // --------------------------------------------------------------------
...@@ -1056,12 +968,14 @@ class Validation { ...@@ -1056,12 +968,14 @@ class Validation {
1056 * Alpha-numeric 968 * Alpha-numeric
1057 * 969 *
1058 * @access public 970 * @access public
971 *
1059 * @param string 972 * @param string
973 *
1060 * @return bool 974 * @return bool
1061 */ 975 */
1062 function alpha_numeric($str) 976 function alpha_numeric($str)
1063 { 977 {
1064 return ( ! preg_match("/^([a-z0-9])+$/i", $str)) ? FALSE : TRUE; 978 return (!preg_match("/^([a-z0-9])+$/i", $str)) ? false : true;
1065 } 979 }
1066 980
1067 // -------------------------------------------------------------------- 981 // --------------------------------------------------------------------
...@@ -1070,12 +984,14 @@ class Validation { ...@@ -1070,12 +984,14 @@ class Validation {
1070 * Alpha-numeric with underscores and dashes 984 * Alpha-numeric with underscores and dashes
1071 * 985 *
1072 * @access public 986 * @access public
987 *
1073 * @param string 988 * @param string
989 *
1074 * @return bool 990 * @return bool
1075 */ 991 */
1076 function alpha_dash($str) 992 function alpha_dash($str)
1077 { 993 {
1078 return ( ! preg_match("/^([-a-z0-9_-])+$/i", $str)) ? FALSE : TRUE; 994 return (!preg_match("/^([-a-z0-9_-])+$/i", $str)) ? false : true;
1079 } 995 }
1080 996
1081 // -------------------------------------------------------------------- 997 // --------------------------------------------------------------------
...@@ -1084,13 +1000,14 @@ class Validation { ...@@ -1084,13 +1000,14 @@ class Validation {
1084 * Numeric 1000 * Numeric
1085 * 1001 *
1086 * @access public 1002 * @access public
1003 *
1087 * @param string 1004 * @param string
1005 *
1088 * @return bool 1006 * @return bool
1089 */ 1007 */
1090 function numeric($str) 1008 function numeric($str)
1091 { 1009 {
1092 return (bool)preg_match( '/^[\-+]?[0-9]*\.?[0-9]+$/', $str); 1010 return (bool)preg_match('/^[\-+]?[0-9]*\.?[0-9]+$/', $str);
1093
1094 } 1011 }
1095 1012
1096 // -------------------------------------------------------------------- 1013 // --------------------------------------------------------------------
...@@ -1099,12 +1016,14 @@ class Validation { ...@@ -1099,12 +1016,14 @@ class Validation {
1099 * Is Numeric 1016 * Is Numeric
1100 * 1017 *
1101 * @access public 1018 * @access public
1019 *
1102 * @param string 1020 * @param string
1021 *
1103 * @return bool 1022 * @return bool
1104 */ 1023 */
1105 function is_numeric($str) 1024 function is_numeric($str)
1106 { 1025 {
1107 return ( ! is_numeric($str)) ? FALSE : TRUE; 1026 return (!is_numeric($str)) ? false : true;
1108 } 1027 }
1109 1028
1110 // -------------------------------------------------------------------- 1029 // --------------------------------------------------------------------
...@@ -1113,12 +1032,14 @@ class Validation { ...@@ -1113,12 +1032,14 @@ class Validation {
1113 * Integer 1032 * Integer
1114 * 1033 *
1115 * @access public 1034 * @access public
1035 *
1116 * @param string 1036 * @param string
1037 *
1117 * @return bool 1038 * @return bool
1118 */ 1039 */
1119 function integer($str) 1040 function integer($str)
1120 { 1041 {
1121 return (bool)preg_match( '/^[\-+]?[0-9]+$/', $str); 1042 return (bool)preg_match('/^[\-+]?[0-9]+$/', $str);
1122 } 1043 }
1123 1044
1124 // -------------------------------------------------------------------- 1045 // --------------------------------------------------------------------
...@@ -1127,12 +1048,14 @@ class Validation { ...@@ -1127,12 +1048,14 @@ class Validation {
1127 * Is a Natural number (0,1,2,3, etc.) 1048 * Is a Natural number (0,1,2,3, etc.)
1128 * 1049 *
1129 * @access public 1050 * @access public
1051 *
1130 * @param string 1052 * @param string
1053 *
1131 * @return bool 1054 * @return bool
1132 */ 1055 */
1133 function is_natural($str) 1056 function is_natural($str)
1134 { 1057 {
1135 return (bool)preg_match( '/^[0-9]+$/', $str); 1058 return (bool)preg_match('/^[0-9]+$/', $str);
1136 } 1059 }
1137 1060
1138 // -------------------------------------------------------------------- 1061 // --------------------------------------------------------------------
...@@ -1141,22 +1064,22 @@ class Validation { ...@@ -1141,22 +1064,22 @@ class Validation {
1141 * Is a Natural number, but not a zero (1,2,3, etc.) 1064 * Is a Natural number, but not a zero (1,2,3, etc.)
1142 * 1065 *
1143 * @access public 1066 * @access public
1067 *
1144 * @param string 1068 * @param string
1069 *
1145 * @return bool 1070 * @return bool
1146 */ 1071 */
1147 function is_natural_no_zero($str) 1072 function is_natural_no_zero($str)
1148 { 1073 {
1149 if ( ! preg_match( '/^[0-9]+$/', $str)) 1074 if (!preg_match('/^[0-9]+$/', $str)) {
1150 { 1075 return false;
1151 return FALSE;
1152 } 1076 }
1153 1077
1154 if ($str == 0) 1078 if ($str == 0) {
1155 { 1079 return false;
1156 return FALSE;
1157 } 1080 }
1158 1081
1159 return TRUE; 1082 return true;
1160 } 1083 }
1161 1084
1162 // -------------------------------------------------------------------- 1085 // --------------------------------------------------------------------
...@@ -1168,12 +1091,14 @@ class Validation { ...@@ -1168,12 +1091,14 @@ class Validation {
1168 * as defined by RFC 2045 http://www.faqs.org/rfcs/rfc2045 1091 * as defined by RFC 2045 http://www.faqs.org/rfcs/rfc2045
1169 * 1092 *
1170 * @access public 1093 * @access public
1094 *
1171 * @param string 1095 * @param string
1096 *
1172 * @return bool 1097 * @return bool
1173 */ 1098 */
1174 function valid_base64($str) 1099 function valid_base64($str)
1175 { 1100 {
1176 return (bool) ! preg_match('/[^a-zA-Z0-9\/\+=]/', $str); 1101 return (bool)!preg_match('/[^a-zA-Z0-9\/\+=]/', $str);
1177 } 1102 }
1178 1103
1179 // -------------------------------------------------------------------- 1104 // --------------------------------------------------------------------
...@@ -1185,27 +1110,26 @@ class Validation { ...@@ -1185,27 +1110,26 @@ class Validation {
1185 * Special characters are converted. 1110 * Special characters are converted.
1186 * 1111 *
1187 * @access public 1112 * @access public
1113 *
1188 * @param string 1114 * @param string
1115 *
1189 * @return string 1116 * @return string
1190 */ 1117 */
1191 function prep_for_form($data = '') 1118 function prep_for_form($data = '')
1192 { 1119 {
1193 if (is_array($data)) 1120 if (is_array($data)) {
1194 { 1121 foreach ($data as $key => $val) {
1195 foreach ($data as $key => $val)
1196 {
1197 $data[$key] = $this->prep_for_form($val); 1122 $data[$key] = $this->prep_for_form($val);
1198 } 1123 }
1199 1124
1200 return $data; 1125 return $data;
1201 } 1126 }
1202 1127
1203 if ($this->_safe_form_data == FALSE OR $data === '') 1128 if ($this->_safe_form_data == false OR $data === '') {
1204 {
1205 return $data; 1129 return $data;
1206 } 1130 }
1207 1131
1208 return str_replace(array("'", '"', '<', '>'), array("&#39;", "&quot;", '&lt;', '&gt;'), stripslashes($data)); 1132 return str_replace(["'", '"', '<', '>'], ["&#39;", "&quot;", '&lt;', '&gt;'], stripslashes($data));
1209 } 1133 }
1210 1134
1211 // -------------------------------------------------------------------- 1135 // --------------------------------------------------------------------
...@@ -1214,18 +1138,18 @@ class Validation { ...@@ -1214,18 +1138,18 @@ class Validation {
1214 * Prep URL 1138 * Prep URL
1215 * 1139 *
1216 * @access public 1140 * @access public
1141 *
1217 * @param string 1142 * @param string
1143 *
1218 * @return string 1144 * @return string
1219 */ 1145 */
1220 function prep_url($str = '') 1146 function prep_url($str = '')
1221 { 1147 {
1222 if ($str == 'http://' OR $str == '') 1148 if ($str == 'http://' OR $str == '') {
1223 {
1224 return ''; 1149 return '';
1225 } 1150 }
1226 1151
1227 if (substr($str, 0, 7) != 'http://' && substr($str, 0, 8) != 'https://') 1152 if (substr($str, 0, 7) != 'http://' && substr($str, 0, 8) != 'https://') {
1228 {
1229 $str = 'http://'.$str; 1153 $str = 'http://'.$str;
1230 } 1154 }
1231 1155
...@@ -1238,7 +1162,9 @@ class Validation { ...@@ -1238,7 +1162,9 @@ class Validation {
1238 * Strip Image Tags 1162 * Strip Image Tags
1239 * 1163 *
1240 * @access public 1164 * @access public
1165 *
1241 * @param string 1166 * @param string
1167 *
1242 * @return string 1168 * @return string
1243 */ 1169 */
1244 function strip_image_tags($str) 1170 function strip_image_tags($str)
...@@ -1252,7 +1178,9 @@ class Validation { ...@@ -1252,7 +1178,9 @@ class Validation {
1252 * XSS Clean 1178 * XSS Clean
1253 * 1179 *
1254 * @access public 1180 * @access public
1181 *
1255 * @param string 1182 * @param string
1183 *
1256 * @return string 1184 * @return string
1257 */ 1185 */
1258 function xss_clean($str) 1186 function xss_clean($str)
...@@ -1266,14 +1194,15 @@ class Validation { ...@@ -1266,14 +1194,15 @@ class Validation {
1266 * Convert PHP tags to entities 1194 * Convert PHP tags to entities
1267 * 1195 *
1268 * @access public 1196 * @access public
1197 *
1269 * @param string 1198 * @param string
1199 *
1270 * @return string 1200 * @return string
1271 */ 1201 */
1272 function encode_php_tags($str) 1202 function encode_php_tags($str)
1273 { 1203 {
1274 return str_replace(array('<?php', '<?PHP', '<?', '?>'), array('&lt;?php', '&lt;?PHP', '&lt;?', '?&gt;'), $str); 1204 return str_replace(['<?php', '<?PHP', '<?', '?>'], ['&lt;?php', '&lt;?PHP', '&lt;?', '?&gt;'], $str);
1275 } 1205 }
1276
1277 } 1206 }
1278 // END Form Validation Class 1207 // END Form Validation Class
1279 1208
......