@@ -12,97 +12,97 @@ |
||
12 | 12 | { |
13 | 13 | |
14 | 14 | |
15 | - protected $_validation_error_message = ''; |
|
16 | - |
|
17 | - |
|
18 | - |
|
19 | - /** |
|
20 | - * @param null $validation_error_message |
|
21 | - */ |
|
22 | - public function __construct($validation_error_message = null) |
|
23 | - { |
|
24 | - $this->_validation_error_message = $validation_error_message === null |
|
25 | - ? esc_html__('Input invalid', 'event_espresso') |
|
26 | - : $validation_error_message; |
|
27 | - parent::__construct(); |
|
28 | - } |
|
29 | - |
|
30 | - |
|
31 | - |
|
32 | - /** |
|
33 | - * Performs validation on the request data that corresponds to this field. |
|
34 | - * If validation fails, should throw an EE_Validation_Error. |
|
35 | - * Note: most validate() functions should allow $normalized_value to be empty, |
|
36 | - * as its the job of the EE_Required_Validation_Strategy to ensure that the field isn't empty. |
|
37 | - * |
|
38 | - * @param mixed $normalized_value ready for validation. May very well be NULL (which, unless |
|
39 | - * this validation strategy is the 'required' validation strategy, |
|
40 | - * most should be OK with a null, empty string, etc) |
|
41 | - */ |
|
42 | - public function validate($normalized_value) |
|
43 | - { |
|
44 | - // by default, the validation strategy does no validation. this should be implemented |
|
45 | - } |
|
46 | - |
|
47 | - |
|
48 | - |
|
49 | - /** |
|
50 | - * Gets the JS code for use in the jQuery validation js corresponding to this field when displaying. |
|
51 | - * For documentation, see http://jqueryvalidation.org/ |
|
52 | - * Eg to generate the following js for validation, <br><code> |
|
53 | - * $( "#myform" ).validate({ |
|
54 | - * rules: { |
|
55 | - * field_name: { |
|
56 | - * required: true, |
|
57 | - * minlength: 3, |
|
58 | - * equalTo: "#password" |
|
59 | - * } |
|
60 | - * } |
|
61 | - * }); |
|
62 | - * </code> |
|
63 | - * this function should return array('required'=>true,'minlength'=>3,'equalTo'=>'"#password"' ). |
|
64 | - * This is done so that if we are applying multiple sanitization strategies to a field, |
|
65 | - * we can easily combine them. |
|
66 | - * |
|
67 | - * @return array |
|
68 | - */ |
|
69 | - public function get_jquery_validation_rule_array() |
|
70 | - { |
|
71 | - return array(); |
|
72 | - } |
|
73 | - |
|
74 | - |
|
75 | - |
|
76 | - /** |
|
77 | - * Gets the i18n validation error message for when this validation strategy finds |
|
78 | - * the input is invalid. Used for both frontend and backend validation. |
|
79 | - * |
|
80 | - * @return string |
|
81 | - */ |
|
82 | - public function get_validation_error_message() |
|
83 | - { |
|
84 | - return $this->_validation_error_message; |
|
85 | - } |
|
86 | - |
|
87 | - |
|
88 | - |
|
89 | - /** |
|
90 | - * Adds js variables for localization to the $other_js_data. These should be put |
|
91 | - * in each form's "other_data" javascript object. |
|
92 | - * |
|
93 | - * @param array $other_js_data |
|
94 | - * @return array |
|
95 | - */ |
|
96 | - public function get_other_js_data($other_js_data = array()) |
|
97 | - { |
|
98 | - return $other_js_data; |
|
99 | - } |
|
100 | - |
|
101 | - /** |
|
102 | - * Opportunity for this display strategy to call wp_enqueue_script and wp_enqueue_style. |
|
103 | - * This should be called during wp_enqueue_scripts |
|
104 | - */ |
|
105 | - public function enqueue_js() |
|
106 | - { |
|
107 | - } |
|
15 | + protected $_validation_error_message = ''; |
|
16 | + |
|
17 | + |
|
18 | + |
|
19 | + /** |
|
20 | + * @param null $validation_error_message |
|
21 | + */ |
|
22 | + public function __construct($validation_error_message = null) |
|
23 | + { |
|
24 | + $this->_validation_error_message = $validation_error_message === null |
|
25 | + ? esc_html__('Input invalid', 'event_espresso') |
|
26 | + : $validation_error_message; |
|
27 | + parent::__construct(); |
|
28 | + } |
|
29 | + |
|
30 | + |
|
31 | + |
|
32 | + /** |
|
33 | + * Performs validation on the request data that corresponds to this field. |
|
34 | + * If validation fails, should throw an EE_Validation_Error. |
|
35 | + * Note: most validate() functions should allow $normalized_value to be empty, |
|
36 | + * as its the job of the EE_Required_Validation_Strategy to ensure that the field isn't empty. |
|
37 | + * |
|
38 | + * @param mixed $normalized_value ready for validation. May very well be NULL (which, unless |
|
39 | + * this validation strategy is the 'required' validation strategy, |
|
40 | + * most should be OK with a null, empty string, etc) |
|
41 | + */ |
|
42 | + public function validate($normalized_value) |
|
43 | + { |
|
44 | + // by default, the validation strategy does no validation. this should be implemented |
|
45 | + } |
|
46 | + |
|
47 | + |
|
48 | + |
|
49 | + /** |
|
50 | + * Gets the JS code for use in the jQuery validation js corresponding to this field when displaying. |
|
51 | + * For documentation, see http://jqueryvalidation.org/ |
|
52 | + * Eg to generate the following js for validation, <br><code> |
|
53 | + * $( "#myform" ).validate({ |
|
54 | + * rules: { |
|
55 | + * field_name: { |
|
56 | + * required: true, |
|
57 | + * minlength: 3, |
|
58 | + * equalTo: "#password" |
|
59 | + * } |
|
60 | + * } |
|
61 | + * }); |
|
62 | + * </code> |
|
63 | + * this function should return array('required'=>true,'minlength'=>3,'equalTo'=>'"#password"' ). |
|
64 | + * This is done so that if we are applying multiple sanitization strategies to a field, |
|
65 | + * we can easily combine them. |
|
66 | + * |
|
67 | + * @return array |
|
68 | + */ |
|
69 | + public function get_jquery_validation_rule_array() |
|
70 | + { |
|
71 | + return array(); |
|
72 | + } |
|
73 | + |
|
74 | + |
|
75 | + |
|
76 | + /** |
|
77 | + * Gets the i18n validation error message for when this validation strategy finds |
|
78 | + * the input is invalid. Used for both frontend and backend validation. |
|
79 | + * |
|
80 | + * @return string |
|
81 | + */ |
|
82 | + public function get_validation_error_message() |
|
83 | + { |
|
84 | + return $this->_validation_error_message; |
|
85 | + } |
|
86 | + |
|
87 | + |
|
88 | + |
|
89 | + /** |
|
90 | + * Adds js variables for localization to the $other_js_data. These should be put |
|
91 | + * in each form's "other_data" javascript object. |
|
92 | + * |
|
93 | + * @param array $other_js_data |
|
94 | + * @return array |
|
95 | + */ |
|
96 | + public function get_other_js_data($other_js_data = array()) |
|
97 | + { |
|
98 | + return $other_js_data; |
|
99 | + } |
|
100 | + |
|
101 | + /** |
|
102 | + * Opportunity for this display strategy to call wp_enqueue_script and wp_enqueue_style. |
|
103 | + * This should be called during wp_enqueue_scripts |
|
104 | + */ |
|
105 | + public function enqueue_js() |
|
106 | + { |
|
107 | + } |
|
108 | 108 | } |
@@ -16,77 +16,77 @@ |
||
16 | 16 | class EE_URL_Validation_Strategy extends EE_Validation_Strategy_Base |
17 | 17 | { |
18 | 18 | |
19 | - /** |
|
20 | - * @var @boolean whether we should check if the file exists or not |
|
21 | - */ |
|
22 | - protected $check_file_exists; |
|
19 | + /** |
|
20 | + * @var @boolean whether we should check if the file exists or not |
|
21 | + */ |
|
22 | + protected $check_file_exists; |
|
23 | 23 | |
24 | - /** |
|
25 | - * @var URLValidator |
|
26 | - */ |
|
27 | - protected $url_validator; |
|
24 | + /** |
|
25 | + * @var URLValidator |
|
26 | + */ |
|
27 | + protected $url_validator; |
|
28 | 28 | |
29 | - /** |
|
30 | - * @param null $validation_error_message |
|
31 | - * @param boolean $check_file_exists |
|
32 | - * @param URLValidator $url_validator |
|
33 | - * @throws InvalidArgumentException |
|
34 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
35 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
36 | - */ |
|
37 | - public function __construct( |
|
38 | - $validation_error_message = null, |
|
39 | - $check_file_exists = false, |
|
40 | - URLValidator $url_validator = null |
|
41 | - ) { |
|
42 | - if (! $url_validator instanceof URLValidator) { |
|
43 | - $url_validator = LoaderFactory::getLoader()->getShared('EventEspresso\core\services\validators\URLValidator'); |
|
44 | - } |
|
45 | - $this->url_validator = $url_validator; |
|
46 | - if (! $validation_error_message) { |
|
47 | - $validation_error_message = esc_html__("Please enter a valid URL. Eg https://eventespresso.com", "event_espresso"); |
|
48 | - } |
|
49 | - $this->check_file_exists = $check_file_exists; |
|
50 | - parent::__construct($validation_error_message); |
|
51 | - } |
|
29 | + /** |
|
30 | + * @param null $validation_error_message |
|
31 | + * @param boolean $check_file_exists |
|
32 | + * @param URLValidator $url_validator |
|
33 | + * @throws InvalidArgumentException |
|
34 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
35 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
36 | + */ |
|
37 | + public function __construct( |
|
38 | + $validation_error_message = null, |
|
39 | + $check_file_exists = false, |
|
40 | + URLValidator $url_validator = null |
|
41 | + ) { |
|
42 | + if (! $url_validator instanceof URLValidator) { |
|
43 | + $url_validator = LoaderFactory::getLoader()->getShared('EventEspresso\core\services\validators\URLValidator'); |
|
44 | + } |
|
45 | + $this->url_validator = $url_validator; |
|
46 | + if (! $validation_error_message) { |
|
47 | + $validation_error_message = esc_html__("Please enter a valid URL. Eg https://eventespresso.com", "event_espresso"); |
|
48 | + } |
|
49 | + $this->check_file_exists = $check_file_exists; |
|
50 | + parent::__construct($validation_error_message); |
|
51 | + } |
|
52 | 52 | |
53 | 53 | |
54 | 54 | |
55 | - /** |
|
56 | - * just checks the field isn't blank |
|
57 | - * |
|
58 | - * @param $normalized_value |
|
59 | - * @return bool |
|
60 | - * @throws \EE_Validation_Error |
|
61 | - */ |
|
62 | - public function validate($normalized_value) |
|
63 | - { |
|
64 | - if ($normalized_value) { |
|
65 | - if (! $this->url_validator->isValid($normalized_value)) { |
|
66 | - throw new EE_Validation_Error($this->get_validation_error_message(), 'invalid_url'); |
|
67 | - } elseif (apply_filters('FHEE__EE_URL_Validation_Strategy__validate__check_remote_file_exists', $this->check_file_exists, $this->_input)) { |
|
68 | - if ( |
|
69 | - ! EEH_URL::remote_file_exists( |
|
70 | - $normalized_value, |
|
71 | - array( |
|
72 | - 'sslverify' => false, |
|
73 | - 'limit_response_size' => 4095,// we don't really care for a full response, but we do want headers at least. Lets just ask for a one block |
|
74 | - ) |
|
75 | - ) |
|
76 | - ) { |
|
77 | - throw new EE_Validation_Error(sprintf(esc_html__("That URL seems to be broken. Please enter a valid URL", "event_espresso"))); |
|
78 | - } |
|
79 | - } |
|
80 | - } |
|
81 | - } |
|
55 | + /** |
|
56 | + * just checks the field isn't blank |
|
57 | + * |
|
58 | + * @param $normalized_value |
|
59 | + * @return bool |
|
60 | + * @throws \EE_Validation_Error |
|
61 | + */ |
|
62 | + public function validate($normalized_value) |
|
63 | + { |
|
64 | + if ($normalized_value) { |
|
65 | + if (! $this->url_validator->isValid($normalized_value)) { |
|
66 | + throw new EE_Validation_Error($this->get_validation_error_message(), 'invalid_url'); |
|
67 | + } elseif (apply_filters('FHEE__EE_URL_Validation_Strategy__validate__check_remote_file_exists', $this->check_file_exists, $this->_input)) { |
|
68 | + if ( |
|
69 | + ! EEH_URL::remote_file_exists( |
|
70 | + $normalized_value, |
|
71 | + array( |
|
72 | + 'sslverify' => false, |
|
73 | + 'limit_response_size' => 4095,// we don't really care for a full response, but we do want headers at least. Lets just ask for a one block |
|
74 | + ) |
|
75 | + ) |
|
76 | + ) { |
|
77 | + throw new EE_Validation_Error(sprintf(esc_html__("That URL seems to be broken. Please enter a valid URL", "event_espresso"))); |
|
78 | + } |
|
79 | + } |
|
80 | + } |
|
81 | + } |
|
82 | 82 | |
83 | 83 | |
84 | 84 | |
85 | - /** |
|
86 | - * @return array |
|
87 | - */ |
|
88 | - public function get_jquery_validation_rule_array() |
|
89 | - { |
|
90 | - return array( 'validUrl' => true, 'messages' => array( 'validUrl' => $this->get_validation_error_message() ) ); |
|
91 | - } |
|
85 | + /** |
|
86 | + * @return array |
|
87 | + */ |
|
88 | + public function get_jquery_validation_rule_array() |
|
89 | + { |
|
90 | + return array( 'validUrl' => true, 'messages' => array( 'validUrl' => $this->get_validation_error_message() ) ); |
|
91 | + } |
|
92 | 92 | } |
@@ -39,11 +39,11 @@ discard block |
||
39 | 39 | $check_file_exists = false, |
40 | 40 | URLValidator $url_validator = null |
41 | 41 | ) { |
42 | - if (! $url_validator instanceof URLValidator) { |
|
42 | + if ( ! $url_validator instanceof URLValidator) { |
|
43 | 43 | $url_validator = LoaderFactory::getLoader()->getShared('EventEspresso\core\services\validators\URLValidator'); |
44 | 44 | } |
45 | 45 | $this->url_validator = $url_validator; |
46 | - if (! $validation_error_message) { |
|
46 | + if ( ! $validation_error_message) { |
|
47 | 47 | $validation_error_message = esc_html__("Please enter a valid URL. Eg https://eventespresso.com", "event_espresso"); |
48 | 48 | } |
49 | 49 | $this->check_file_exists = $check_file_exists; |
@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | public function validate($normalized_value) |
63 | 63 | { |
64 | 64 | if ($normalized_value) { |
65 | - if (! $this->url_validator->isValid($normalized_value)) { |
|
65 | + if ( ! $this->url_validator->isValid($normalized_value)) { |
|
66 | 66 | throw new EE_Validation_Error($this->get_validation_error_message(), 'invalid_url'); |
67 | 67 | } elseif (apply_filters('FHEE__EE_URL_Validation_Strategy__validate__check_remote_file_exists', $this->check_file_exists, $this->_input)) { |
68 | 68 | if ( |
@@ -70,7 +70,7 @@ discard block |
||
70 | 70 | $normalized_value, |
71 | 71 | array( |
72 | 72 | 'sslverify' => false, |
73 | - 'limit_response_size' => 4095,// we don't really care for a full response, but we do want headers at least. Lets just ask for a one block |
|
73 | + 'limit_response_size' => 4095, // we don't really care for a full response, but we do want headers at least. Lets just ask for a one block |
|
74 | 74 | ) |
75 | 75 | ) |
76 | 76 | ) { |
@@ -87,6 +87,6 @@ discard block |
||
87 | 87 | */ |
88 | 88 | public function get_jquery_validation_rule_array() |
89 | 89 | { |
90 | - return array( 'validUrl' => true, 'messages' => array( 'validUrl' => $this->get_validation_error_message() ) ); |
|
90 | + return array('validUrl' => true, 'messages' => array('validUrl' => $this->get_validation_error_message())); |
|
91 | 91 | } |
92 | 92 | } |
@@ -10,41 +10,41 @@ |
||
10 | 10 | class EE_Int_Validation_Strategy extends EE_Validation_Strategy_Base |
11 | 11 | { |
12 | 12 | |
13 | - /** |
|
14 | - * @param null $validation_error_message |
|
15 | - */ |
|
16 | - public function __construct($validation_error_message = null) |
|
17 | - { |
|
18 | - if (! $validation_error_message) { |
|
19 | - $validation_error_message = esc_html__("Only digits are allowed.", "event_espresso"); |
|
20 | - } |
|
21 | - parent::__construct($validation_error_message); |
|
22 | - } |
|
23 | - |
|
24 | - |
|
25 | - |
|
26 | - /** |
|
27 | - * @param $normalized_value |
|
28 | - */ |
|
29 | - public function validate($normalized_value) |
|
30 | - { |
|
31 | - // this should have already been detected by the normalization strategy |
|
32 | - } |
|
33 | - |
|
34 | - |
|
35 | - |
|
36 | - /** |
|
37 | - * @return array |
|
38 | - */ |
|
39 | - public function get_jquery_validation_rule_array() |
|
40 | - { |
|
41 | - return array( |
|
42 | - 'number' => true, |
|
43 | - 'step' => 1, |
|
44 | - 'messages' => array( |
|
45 | - 'number' => $this->get_validation_error_message(), |
|
46 | - 'step' => $this->get_validation_error_message() |
|
47 | - ) |
|
48 | - ); |
|
49 | - } |
|
13 | + /** |
|
14 | + * @param null $validation_error_message |
|
15 | + */ |
|
16 | + public function __construct($validation_error_message = null) |
|
17 | + { |
|
18 | + if (! $validation_error_message) { |
|
19 | + $validation_error_message = esc_html__("Only digits are allowed.", "event_espresso"); |
|
20 | + } |
|
21 | + parent::__construct($validation_error_message); |
|
22 | + } |
|
23 | + |
|
24 | + |
|
25 | + |
|
26 | + /** |
|
27 | + * @param $normalized_value |
|
28 | + */ |
|
29 | + public function validate($normalized_value) |
|
30 | + { |
|
31 | + // this should have already been detected by the normalization strategy |
|
32 | + } |
|
33 | + |
|
34 | + |
|
35 | + |
|
36 | + /** |
|
37 | + * @return array |
|
38 | + */ |
|
39 | + public function get_jquery_validation_rule_array() |
|
40 | + { |
|
41 | + return array( |
|
42 | + 'number' => true, |
|
43 | + 'step' => 1, |
|
44 | + 'messages' => array( |
|
45 | + 'number' => $this->get_validation_error_message(), |
|
46 | + 'step' => $this->get_validation_error_message() |
|
47 | + ) |
|
48 | + ); |
|
49 | + } |
|
50 | 50 | } |
@@ -15,7 +15,7 @@ |
||
15 | 15 | */ |
16 | 16 | public function __construct($validation_error_message = null) |
17 | 17 | { |
18 | - if (! $validation_error_message) { |
|
18 | + if ( ! $validation_error_message) { |
|
19 | 19 | $validation_error_message = esc_html__("Only digits are allowed.", "event_espresso"); |
20 | 20 | } |
21 | 21 | parent::__construct($validation_error_message); |
@@ -14,62 +14,62 @@ |
||
14 | 14 | class EE_Full_HTML_Validation_Strategy extends EE_Validation_Strategy_Base |
15 | 15 | { |
16 | 16 | |
17 | - /** |
|
18 | - * @param null $validation_error_message |
|
19 | - */ |
|
20 | - public function __construct($validation_error_message = null) |
|
21 | - { |
|
22 | - if (! $validation_error_message) { |
|
23 | - $validation_error_message = sprintf( |
|
24 | - esc_html__('Only the following HTML tags are allowed:%1$s%2$s', "event_espresso"), |
|
25 | - '<br />', |
|
26 | - $this->get_list_of_allowed_tags() |
|
27 | - ); |
|
28 | - } |
|
29 | - parent::__construct($validation_error_message); |
|
30 | - } |
|
17 | + /** |
|
18 | + * @param null $validation_error_message |
|
19 | + */ |
|
20 | + public function __construct($validation_error_message = null) |
|
21 | + { |
|
22 | + if (! $validation_error_message) { |
|
23 | + $validation_error_message = sprintf( |
|
24 | + esc_html__('Only the following HTML tags are allowed:%1$s%2$s', "event_espresso"), |
|
25 | + '<br />', |
|
26 | + $this->get_list_of_allowed_tags() |
|
27 | + ); |
|
28 | + } |
|
29 | + parent::__construct($validation_error_message); |
|
30 | + } |
|
31 | 31 | |
32 | 32 | |
33 | - /** |
|
34 | - * get_list_of_allowed_tags |
|
35 | - * |
|
36 | - * generates and returns a string that lists the top-level HTML tags that are allowable for this input |
|
37 | - * |
|
38 | - * @return string |
|
39 | - */ |
|
40 | - public function get_list_of_allowed_tags() |
|
41 | - { |
|
42 | - $tags_we_allow = $this->getAllowedTags(); |
|
43 | - ksort($tags_we_allow); |
|
44 | - return implode(', ', array_keys($tags_we_allow)); |
|
45 | - } |
|
33 | + /** |
|
34 | + * get_list_of_allowed_tags |
|
35 | + * |
|
36 | + * generates and returns a string that lists the top-level HTML tags that are allowable for this input |
|
37 | + * |
|
38 | + * @return string |
|
39 | + */ |
|
40 | + public function get_list_of_allowed_tags() |
|
41 | + { |
|
42 | + $tags_we_allow = $this->getAllowedTags(); |
|
43 | + ksort($tags_we_allow); |
|
44 | + return implode(', ', array_keys($tags_we_allow)); |
|
45 | + } |
|
46 | 46 | |
47 | 47 | |
48 | - /** |
|
49 | - * Returns an array whose keys are allowed tags and values are an array of allowed attributes |
|
50 | - * |
|
51 | - * @return array |
|
52 | - */ |
|
53 | - protected function getAllowedTags() |
|
54 | - { |
|
55 | - global $allowedposttags; |
|
56 | - return array_merge_recursive( |
|
57 | - $allowedposttags, |
|
58 | - EEH_HTML::get_simple_tags() |
|
59 | - ); |
|
60 | - } |
|
48 | + /** |
|
49 | + * Returns an array whose keys are allowed tags and values are an array of allowed attributes |
|
50 | + * |
|
51 | + * @return array |
|
52 | + */ |
|
53 | + protected function getAllowedTags() |
|
54 | + { |
|
55 | + global $allowedposttags; |
|
56 | + return array_merge_recursive( |
|
57 | + $allowedposttags, |
|
58 | + EEH_HTML::get_simple_tags() |
|
59 | + ); |
|
60 | + } |
|
61 | 61 | |
62 | 62 | |
63 | - /** |
|
64 | - * @param $normalized_value |
|
65 | - * @throws \EE_Validation_Error |
|
66 | - */ |
|
67 | - public function validate($normalized_value) |
|
68 | - { |
|
69 | - parent::validate($normalized_value); |
|
70 | - $normalized_value_sans_tags = wp_kses("$normalized_value", $this->getAllowedTags()); |
|
71 | - if (strlen($normalized_value) > strlen($normalized_value_sans_tags)) { |
|
72 | - throw new EE_Validation_Error($this->get_validation_error_message(), 'complex_html_tags'); |
|
73 | - } |
|
74 | - } |
|
63 | + /** |
|
64 | + * @param $normalized_value |
|
65 | + * @throws \EE_Validation_Error |
|
66 | + */ |
|
67 | + public function validate($normalized_value) |
|
68 | + { |
|
69 | + parent::validate($normalized_value); |
|
70 | + $normalized_value_sans_tags = wp_kses("$normalized_value", $this->getAllowedTags()); |
|
71 | + if (strlen($normalized_value) > strlen($normalized_value_sans_tags)) { |
|
72 | + throw new EE_Validation_Error($this->get_validation_error_message(), 'complex_html_tags'); |
|
73 | + } |
|
74 | + } |
|
75 | 75 | } |
@@ -19,7 +19,7 @@ |
||
19 | 19 | */ |
20 | 20 | public function __construct($validation_error_message = null) |
21 | 21 | { |
22 | - if (! $validation_error_message) { |
|
22 | + if ( ! $validation_error_message) { |
|
23 | 23 | $validation_error_message = sprintf( |
24 | 24 | esc_html__('Only the following HTML tags are allowed:%1$s%2$s', "event_espresso"), |
25 | 25 | '<br />', |
@@ -14,19 +14,19 @@ |
||
14 | 14 | class EE_Credit_Card_Validation_Strategy extends EE_Text_Validation_Strategy |
15 | 15 | { |
16 | 16 | |
17 | - /** |
|
18 | - * @param null $validation_error_message |
|
19 | - */ |
|
20 | - public function __construct($validation_error_message = null) |
|
21 | - { |
|
22 | - if (! $validation_error_message) { |
|
23 | - $validation_error_message = esc_html__("Please enter a valid credit card number", "event_espresso"); |
|
24 | - } |
|
25 | - parent::__construct( |
|
26 | - $validation_error_message, |
|
27 | - // @codingStandardsIgnoreStart |
|
28 | - '~^(?:4[0-9]{12}(?:[0-9]{3})?|5[1-5][0-9]{14}|2[2-7][0-9]{14}|6011[0-9]{12}|3(?:0[0-5]|[68][0-9])[0-9]{11}|3[47][0-9]{13})$~' |
|
29 | - // @codingStandardsIgnoreEnd |
|
30 | - ); |
|
31 | - } |
|
17 | + /** |
|
18 | + * @param null $validation_error_message |
|
19 | + */ |
|
20 | + public function __construct($validation_error_message = null) |
|
21 | + { |
|
22 | + if (! $validation_error_message) { |
|
23 | + $validation_error_message = esc_html__("Please enter a valid credit card number", "event_espresso"); |
|
24 | + } |
|
25 | + parent::__construct( |
|
26 | + $validation_error_message, |
|
27 | + // @codingStandardsIgnoreStart |
|
28 | + '~^(?:4[0-9]{12}(?:[0-9]{3})?|5[1-5][0-9]{14}|2[2-7][0-9]{14}|6011[0-9]{12}|3(?:0[0-5]|[68][0-9])[0-9]{11}|3[47][0-9]{13})$~' |
|
29 | + // @codingStandardsIgnoreEnd |
|
30 | + ); |
|
31 | + } |
|
32 | 32 | } |
@@ -19,7 +19,7 @@ |
||
19 | 19 | */ |
20 | 20 | public function __construct($validation_error_message = null) |
21 | 21 | { |
22 | - if (! $validation_error_message) { |
|
22 | + if ( ! $validation_error_message) { |
|
23 | 23 | $validation_error_message = esc_html__("Please enter a valid credit card number", "event_espresso"); |
24 | 24 | } |
25 | 25 | parent::__construct( |
@@ -12,51 +12,51 @@ |
||
12 | 12 | class EE_Enum_Validation_Strategy extends EE_Validation_Strategy_Base |
13 | 13 | { |
14 | 14 | |
15 | - /** |
|
16 | - * Check that the value is in the allowed list |
|
17 | - * @param $normalized_value |
|
18 | - * @throws EE_Error |
|
19 | - * @throws EE_Validation_Error |
|
20 | - * @return boolean |
|
21 | - */ |
|
22 | - public function validate($normalized_value) |
|
23 | - { |
|
24 | - parent::validate($normalized_value); |
|
25 | - if (! $this->_input instanceof EE_Form_Input_With_Options_Base) { |
|
26 | - throw new EE_Error(sprintf(esc_html__("Cannot use Enum Validation Strategy with an input that doesn't have options", "event_espresso"))); |
|
27 | - } |
|
28 | - $enum_options = $this->_input->flat_options(); |
|
29 | - if ($normalized_value === true) { |
|
30 | - $normalized_value = 1; |
|
31 | - } elseif ($normalized_value === false) { |
|
32 | - $normalized_value = 0; |
|
33 | - } |
|
34 | - if ($normalized_value !== null && ! array_key_exists($normalized_value, $enum_options)) { |
|
35 | - throw new EE_Validation_Error( |
|
36 | - $this->get_validation_error_message(), |
|
37 | - 'invalid_enum_value' |
|
38 | - ); |
|
39 | - } else { |
|
40 | - return true; |
|
41 | - } |
|
42 | - } |
|
15 | + /** |
|
16 | + * Check that the value is in the allowed list |
|
17 | + * @param $normalized_value |
|
18 | + * @throws EE_Error |
|
19 | + * @throws EE_Validation_Error |
|
20 | + * @return boolean |
|
21 | + */ |
|
22 | + public function validate($normalized_value) |
|
23 | + { |
|
24 | + parent::validate($normalized_value); |
|
25 | + if (! $this->_input instanceof EE_Form_Input_With_Options_Base) { |
|
26 | + throw new EE_Error(sprintf(esc_html__("Cannot use Enum Validation Strategy with an input that doesn't have options", "event_espresso"))); |
|
27 | + } |
|
28 | + $enum_options = $this->_input->flat_options(); |
|
29 | + if ($normalized_value === true) { |
|
30 | + $normalized_value = 1; |
|
31 | + } elseif ($normalized_value === false) { |
|
32 | + $normalized_value = 0; |
|
33 | + } |
|
34 | + if ($normalized_value !== null && ! array_key_exists($normalized_value, $enum_options)) { |
|
35 | + throw new EE_Validation_Error( |
|
36 | + $this->get_validation_error_message(), |
|
37 | + 'invalid_enum_value' |
|
38 | + ); |
|
39 | + } else { |
|
40 | + return true; |
|
41 | + } |
|
42 | + } |
|
43 | 43 | |
44 | - /** |
|
45 | - * If we are using the default validation error message, make it dynamic based |
|
46 | - * on the allowed options. |
|
47 | - * @return string |
|
48 | - */ |
|
49 | - public function get_validation_error_message() |
|
50 | - { |
|
51 | - $parent_validation_error_message = parent::get_validation_error_message(); |
|
52 | - if (! $parent_validation_error_message) { |
|
53 | - $enum_options = $this->_input instanceof EE_Form_Input_With_Options_Base ? $this->_input->flat_options() : ''; |
|
54 | - return sprintf( |
|
55 | - esc_html__("This is not allowed option. Allowed options are %s.", "event_espresso"), |
|
56 | - implode(', ', $enum_options) |
|
57 | - ); |
|
58 | - } else { |
|
59 | - return $parent_validation_error_message; |
|
60 | - } |
|
61 | - } |
|
44 | + /** |
|
45 | + * If we are using the default validation error message, make it dynamic based |
|
46 | + * on the allowed options. |
|
47 | + * @return string |
|
48 | + */ |
|
49 | + public function get_validation_error_message() |
|
50 | + { |
|
51 | + $parent_validation_error_message = parent::get_validation_error_message(); |
|
52 | + if (! $parent_validation_error_message) { |
|
53 | + $enum_options = $this->_input instanceof EE_Form_Input_With_Options_Base ? $this->_input->flat_options() : ''; |
|
54 | + return sprintf( |
|
55 | + esc_html__("This is not allowed option. Allowed options are %s.", "event_espresso"), |
|
56 | + implode(', ', $enum_options) |
|
57 | + ); |
|
58 | + } else { |
|
59 | + return $parent_validation_error_message; |
|
60 | + } |
|
61 | + } |
|
62 | 62 | } |
@@ -22,7 +22,7 @@ discard block |
||
22 | 22 | public function validate($normalized_value) |
23 | 23 | { |
24 | 24 | parent::validate($normalized_value); |
25 | - if (! $this->_input instanceof EE_Form_Input_With_Options_Base) { |
|
25 | + if ( ! $this->_input instanceof EE_Form_Input_With_Options_Base) { |
|
26 | 26 | throw new EE_Error(sprintf(esc_html__("Cannot use Enum Validation Strategy with an input that doesn't have options", "event_espresso"))); |
27 | 27 | } |
28 | 28 | $enum_options = $this->_input->flat_options(); |
@@ -49,7 +49,7 @@ discard block |
||
49 | 49 | public function get_validation_error_message() |
50 | 50 | { |
51 | 51 | $parent_validation_error_message = parent::get_validation_error_message(); |
52 | - if (! $parent_validation_error_message) { |
|
52 | + if ( ! $parent_validation_error_message) { |
|
53 | 53 | $enum_options = $this->_input instanceof EE_Form_Input_With_Options_Base ? $this->_input->flat_options() : ''; |
54 | 54 | return sprintf( |
55 | 55 | esc_html__("This is not allowed option. Allowed options are %s.", "event_espresso"), |
@@ -14,54 +14,54 @@ |
||
14 | 14 | |
15 | 15 | |
16 | 16 | |
17 | - /** |
|
18 | - * @param string $validation_error_message |
|
19 | - */ |
|
20 | - public function __construct($validation_error_message = null) |
|
21 | - { |
|
22 | - if (! $validation_error_message) { |
|
23 | - $validation_error_message = esc_html__("This field is required.", "event_espresso"); |
|
24 | - } |
|
25 | - parent::__construct($validation_error_message); |
|
26 | - } |
|
17 | + /** |
|
18 | + * @param string $validation_error_message |
|
19 | + */ |
|
20 | + public function __construct($validation_error_message = null) |
|
21 | + { |
|
22 | + if (! $validation_error_message) { |
|
23 | + $validation_error_message = esc_html__("This field is required.", "event_espresso"); |
|
24 | + } |
|
25 | + parent::__construct($validation_error_message); |
|
26 | + } |
|
27 | 27 | |
28 | 28 | |
29 | 29 | |
30 | - /** |
|
31 | - * just checks the field isn't blank, provided the requirement conditions |
|
32 | - * indicate this input is still required |
|
33 | - * |
|
34 | - * @param $normalized_value |
|
35 | - * @return bool |
|
36 | - * @throws \EE_Error |
|
37 | - * @throws \EE_Validation_Error |
|
38 | - */ |
|
39 | - public function validate($normalized_value) |
|
40 | - { |
|
41 | - if ( |
|
42 | - $normalized_value === '' |
|
43 | - || $normalized_value === null |
|
44 | - || $normalized_value === array() |
|
45 | - ) { |
|
46 | - throw new EE_Validation_Error($this->get_validation_error_message(), 'required'); |
|
47 | - } else { |
|
48 | - return true; |
|
49 | - } |
|
50 | - } |
|
30 | + /** |
|
31 | + * just checks the field isn't blank, provided the requirement conditions |
|
32 | + * indicate this input is still required |
|
33 | + * |
|
34 | + * @param $normalized_value |
|
35 | + * @return bool |
|
36 | + * @throws \EE_Error |
|
37 | + * @throws \EE_Validation_Error |
|
38 | + */ |
|
39 | + public function validate($normalized_value) |
|
40 | + { |
|
41 | + if ( |
|
42 | + $normalized_value === '' |
|
43 | + || $normalized_value === null |
|
44 | + || $normalized_value === array() |
|
45 | + ) { |
|
46 | + throw new EE_Validation_Error($this->get_validation_error_message(), 'required'); |
|
47 | + } else { |
|
48 | + return true; |
|
49 | + } |
|
50 | + } |
|
51 | 51 | |
52 | 52 | |
53 | 53 | |
54 | - /** |
|
55 | - * @return array |
|
56 | - * @throws \EE_Error |
|
57 | - */ |
|
58 | - public function get_jquery_validation_rule_array() |
|
59 | - { |
|
60 | - return array( |
|
61 | - 'required' => true, |
|
62 | - 'messages' => array( |
|
63 | - 'required' => $this->get_validation_error_message() |
|
64 | - ) |
|
65 | - ); |
|
66 | - } |
|
54 | + /** |
|
55 | + * @return array |
|
56 | + * @throws \EE_Error |
|
57 | + */ |
|
58 | + public function get_jquery_validation_rule_array() |
|
59 | + { |
|
60 | + return array( |
|
61 | + 'required' => true, |
|
62 | + 'messages' => array( |
|
63 | + 'required' => $this->get_validation_error_message() |
|
64 | + ) |
|
65 | + ); |
|
66 | + } |
|
67 | 67 | } |
@@ -19,7 +19,7 @@ |
||
19 | 19 | */ |
20 | 20 | public function __construct($validation_error_message = null) |
21 | 21 | { |
22 | - if (! $validation_error_message) { |
|
22 | + if ( ! $validation_error_message) { |
|
23 | 23 | $validation_error_message = esc_html__("This field is required.", "event_espresso"); |
24 | 24 | } |
25 | 25 | parent::__construct($validation_error_message); |
@@ -14,86 +14,86 @@ |
||
14 | 14 | class EE_Model_Matching_Query_Validation_Strategy extends EE_Validation_Strategy_Base |
15 | 15 | { |
16 | 16 | |
17 | - /** |
|
18 | - * |
|
19 | - * @var EEM_Base |
|
20 | - */ |
|
21 | - protected $_model; |
|
22 | - protected $_query_params; |
|
23 | - protected $_input_field_name; |
|
17 | + /** |
|
18 | + * |
|
19 | + * @var EEM_Base |
|
20 | + */ |
|
21 | + protected $_model; |
|
22 | + protected $_query_params; |
|
23 | + protected $_input_field_name; |
|
24 | 24 | |
25 | 25 | |
26 | 26 | |
27 | - /** |
|
28 | - * @param string $validation_error_message |
|
29 | - * @param string $model_name name of an EEM_Base model |
|
30 | - * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
31 | - * @param string $input_field_name the input will be treated as this field's value |
|
32 | - * @throws \EE_Error |
|
33 | - */ |
|
34 | - public function __construct($validation_error_message = null, $model_name = '', $query_params = array(), $input_field_name = '') |
|
35 | - { |
|
36 | - if (! EE_Registry::instance()->is_model_name($model_name)) { |
|
37 | - throw new EE_Error(sprintf(esc_html__('You must provide a valid model object ', 'event_espresso'), $model_name)); |
|
38 | - } |
|
39 | - $this->_model = EE_Registry::instance()->load_model($model_name); |
|
40 | - $this->_query_params = $query_params; |
|
41 | - if (empty($input_field_name)) { |
|
42 | - $input_field_name = $this->_model->primary_key_name(); |
|
43 | - } |
|
44 | - $this->_input_field_name = $input_field_name; |
|
45 | - parent::__construct($validation_error_message); |
|
46 | - } |
|
27 | + /** |
|
28 | + * @param string $validation_error_message |
|
29 | + * @param string $model_name name of an EEM_Base model |
|
30 | + * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
31 | + * @param string $input_field_name the input will be treated as this field's value |
|
32 | + * @throws \EE_Error |
|
33 | + */ |
|
34 | + public function __construct($validation_error_message = null, $model_name = '', $query_params = array(), $input_field_name = '') |
|
35 | + { |
|
36 | + if (! EE_Registry::instance()->is_model_name($model_name)) { |
|
37 | + throw new EE_Error(sprintf(esc_html__('You must provide a valid model object ', 'event_espresso'), $model_name)); |
|
38 | + } |
|
39 | + $this->_model = EE_Registry::instance()->load_model($model_name); |
|
40 | + $this->_query_params = $query_params; |
|
41 | + if (empty($input_field_name)) { |
|
42 | + $input_field_name = $this->_model->primary_key_name(); |
|
43 | + } |
|
44 | + $this->_input_field_name = $input_field_name; |
|
45 | + parent::__construct($validation_error_message); |
|
46 | + } |
|
47 | 47 | |
48 | 48 | |
49 | 49 | |
50 | - /** |
|
51 | - * @param $normalized_value |
|
52 | - * @return bool|void |
|
53 | - * @throws \EE_Error |
|
54 | - * @throws \EE_Validation_Error |
|
55 | - */ |
|
56 | - public function validate($normalized_value) |
|
57 | - { |
|
58 | - if (empty($normalized_value)) { |
|
59 | - return true; |
|
60 | - } |
|
61 | - $combined_query_params = $this->get_query_params(); |
|
62 | - $combined_query_params[0][ $this->treat_input_as_field() ] = $normalized_value; |
|
63 | - if (! $this->get_model()->exists($combined_query_params)) { |
|
64 | - throw new EE_Validation_Error($this->get_validation_error_message(), 'no_matching_model_object'); |
|
65 | - } |
|
66 | - } |
|
50 | + /** |
|
51 | + * @param $normalized_value |
|
52 | + * @return bool|void |
|
53 | + * @throws \EE_Error |
|
54 | + * @throws \EE_Validation_Error |
|
55 | + */ |
|
56 | + public function validate($normalized_value) |
|
57 | + { |
|
58 | + if (empty($normalized_value)) { |
|
59 | + return true; |
|
60 | + } |
|
61 | + $combined_query_params = $this->get_query_params(); |
|
62 | + $combined_query_params[0][ $this->treat_input_as_field() ] = $normalized_value; |
|
63 | + if (! $this->get_model()->exists($combined_query_params)) { |
|
64 | + throw new EE_Validation_Error($this->get_validation_error_message(), 'no_matching_model_object'); |
|
65 | + } |
|
66 | + } |
|
67 | 67 | |
68 | - /** |
|
69 | - * Gets the model used for querying |
|
70 | - * @return EEM_Base |
|
71 | - */ |
|
72 | - public function get_model() |
|
73 | - { |
|
74 | - return $this->_model; |
|
75 | - } |
|
68 | + /** |
|
69 | + * Gets the model used for querying |
|
70 | + * @return EEM_Base |
|
71 | + */ |
|
72 | + public function get_model() |
|
73 | + { |
|
74 | + return $this->_model; |
|
75 | + } |
|
76 | 76 | |
77 | - /** |
|
78 | - * Returns query params used for model query |
|
79 | - * @return array |
|
80 | - */ |
|
81 | - public function get_query_params() |
|
82 | - { |
|
83 | - return (array) $this->_query_params; |
|
84 | - } |
|
77 | + /** |
|
78 | + * Returns query params used for model query |
|
79 | + * @return array |
|
80 | + */ |
|
81 | + public function get_query_params() |
|
82 | + { |
|
83 | + return (array) $this->_query_params; |
|
84 | + } |
|
85 | 85 | |
86 | - /** |
|
87 | - * Gets the name of the field that will be used for lookup. |
|
88 | - * eg it could be "EVT_name", meaning that if there is a model object in |
|
89 | - * the database that has that event name, and matching the other query parameters |
|
90 | - * on this strategy, the input will pass validation server-side |
|
91 | - * @return string |
|
92 | - */ |
|
93 | - public function treat_input_as_field() |
|
94 | - { |
|
95 | - return $this->_input_field_name; |
|
96 | - } |
|
86 | + /** |
|
87 | + * Gets the name of the field that will be used for lookup. |
|
88 | + * eg it could be "EVT_name", meaning that if there is a model object in |
|
89 | + * the database that has that event name, and matching the other query parameters |
|
90 | + * on this strategy, the input will pass validation server-side |
|
91 | + * @return string |
|
92 | + */ |
|
93 | + public function treat_input_as_field() |
|
94 | + { |
|
95 | + return $this->_input_field_name; |
|
96 | + } |
|
97 | 97 | } |
98 | 98 | |
99 | 99 | // End of file EE_FUll_HTML_Validation_Strategy.strategy.php |
@@ -33,7 +33,7 @@ discard block |
||
33 | 33 | */ |
34 | 34 | public function __construct($validation_error_message = null, $model_name = '', $query_params = array(), $input_field_name = '') |
35 | 35 | { |
36 | - if (! EE_Registry::instance()->is_model_name($model_name)) { |
|
36 | + if ( ! EE_Registry::instance()->is_model_name($model_name)) { |
|
37 | 37 | throw new EE_Error(sprintf(esc_html__('You must provide a valid model object ', 'event_espresso'), $model_name)); |
38 | 38 | } |
39 | 39 | $this->_model = EE_Registry::instance()->load_model($model_name); |
@@ -59,8 +59,8 @@ discard block |
||
59 | 59 | return true; |
60 | 60 | } |
61 | 61 | $combined_query_params = $this->get_query_params(); |
62 | - $combined_query_params[0][ $this->treat_input_as_field() ] = $normalized_value; |
|
63 | - if (! $this->get_model()->exists($combined_query_params)) { |
|
62 | + $combined_query_params[0][$this->treat_input_as_field()] = $normalized_value; |
|
63 | + if ( ! $this->get_model()->exists($combined_query_params)) { |
|
64 | 64 | throw new EE_Validation_Error($this->get_validation_error_message(), 'no_matching_model_object'); |
65 | 65 | } |
66 | 66 | } |
@@ -14,27 +14,27 @@ |
||
14 | 14 | class EE_Plaintext_Validation_Strategy extends EE_Validation_Strategy_Base |
15 | 15 | { |
16 | 16 | |
17 | - /** |
|
18 | - * @param null $validation_error_message |
|
19 | - */ |
|
20 | - public function __construct($validation_error_message = null) |
|
21 | - { |
|
22 | - if (! $validation_error_message) { |
|
23 | - $validation_error_message = esc_html__("HTML tags are not permitted in this field", "event_espresso"); |
|
24 | - } |
|
25 | - parent::__construct($validation_error_message); |
|
26 | - } |
|
17 | + /** |
|
18 | + * @param null $validation_error_message |
|
19 | + */ |
|
20 | + public function __construct($validation_error_message = null) |
|
21 | + { |
|
22 | + if (! $validation_error_message) { |
|
23 | + $validation_error_message = esc_html__("HTML tags are not permitted in this field", "event_espresso"); |
|
24 | + } |
|
25 | + parent::__construct($validation_error_message); |
|
26 | + } |
|
27 | 27 | |
28 | - /** |
|
29 | - * @param $normalized_value |
|
30 | - * @throws \EE_Validation_Error |
|
31 | - */ |
|
32 | - public function validate($normalized_value) |
|
33 | - { |
|
34 | - $no_tags = wp_strip_all_tags($normalized_value); |
|
35 | - if (strlen($no_tags) < strlen(trim($normalized_value))) { |
|
36 | - throw new EE_Validation_Error($this->get_validation_error_message(), 'no_html_tags'); |
|
37 | - } |
|
38 | - parent::validate($normalized_value); |
|
39 | - } |
|
28 | + /** |
|
29 | + * @param $normalized_value |
|
30 | + * @throws \EE_Validation_Error |
|
31 | + */ |
|
32 | + public function validate($normalized_value) |
|
33 | + { |
|
34 | + $no_tags = wp_strip_all_tags($normalized_value); |
|
35 | + if (strlen($no_tags) < strlen(trim($normalized_value))) { |
|
36 | + throw new EE_Validation_Error($this->get_validation_error_message(), 'no_html_tags'); |
|
37 | + } |
|
38 | + parent::validate($normalized_value); |
|
39 | + } |
|
40 | 40 | } |
@@ -19,7 +19,7 @@ |
||
19 | 19 | */ |
20 | 20 | public function __construct($validation_error_message = null) |
21 | 21 | { |
22 | - if (! $validation_error_message) { |
|
22 | + if ( ! $validation_error_message) { |
|
23 | 23 | $validation_error_message = esc_html__("HTML tags are not permitted in this field", "event_espresso"); |
24 | 24 | } |
25 | 25 | parent::__construct($validation_error_message); |