@@ -136,17 +136,17 @@ discard block |
||
| 136 | 136 | */ |
| 137 | 137 | private function addIframeAssets(array $localized_vars) |
| 138 | 138 | { |
| 139 | - if (! $this->useCaptcha()) { |
|
| 139 | + if ( ! $this->useCaptcha()) { |
|
| 140 | 140 | return; |
| 141 | 141 | } |
| 142 | 142 | add_filter( |
| 143 | 143 | 'FHEE__EED_Ticket_Selector__ticket_selector_iframe__js', |
| 144 | - function (array $iframe_assets) { |
|
| 145 | - $iframe_assets[ EE_Invisible_Recaptcha_Input::SCRIPT_HANDLE_ESPRESSO_INVISIBLE_RECAPTCHA ] = |
|
| 144 | + function(array $iframe_assets) { |
|
| 145 | + $iframe_assets[EE_Invisible_Recaptcha_Input::SCRIPT_HANDLE_ESPRESSO_INVISIBLE_RECAPTCHA] = |
|
| 146 | 146 | EED_Recaptcha_Invisible::assetsUrl() |
| 147 | 147 | . 'espresso_invisible_recaptcha.js?ver=' |
| 148 | 148 | . EVENT_ESPRESSO_VERSION; |
| 149 | - $iframe_assets[ EE_Invisible_Recaptcha_Input::SCRIPT_HANDLE_GOOGLE_INVISIBLE_RECAPTCHA ] = |
|
| 149 | + $iframe_assets[EE_Invisible_Recaptcha_Input::SCRIPT_HANDLE_GOOGLE_INVISIBLE_RECAPTCHA] = |
|
| 150 | 150 | add_query_arg( |
| 151 | 151 | array( |
| 152 | 152 | 'onload' => 'espressoLoadRecaptcha', |
@@ -160,15 +160,15 @@ discard block |
||
| 160 | 160 | ); |
| 161 | 161 | add_filter( |
| 162 | 162 | 'FHEE__EventEspresso_modules_ticket_selector_TicketSelectorIframe__construct__js_attributes', |
| 163 | - function (array $iframe_asset_attributes) { |
|
| 164 | - $iframe_asset_attributes[ EE_Invisible_Recaptcha_Input::SCRIPT_HANDLE_GOOGLE_INVISIBLE_RECAPTCHA ] |
|
| 163 | + function(array $iframe_asset_attributes) { |
|
| 164 | + $iframe_asset_attributes[EE_Invisible_Recaptcha_Input::SCRIPT_HANDLE_GOOGLE_INVISIBLE_RECAPTCHA] |
|
| 165 | 165 | = ' async="async" defer="defer"'; |
| 166 | 166 | return $iframe_asset_attributes; |
| 167 | 167 | } |
| 168 | 168 | ); |
| 169 | 169 | add_action( |
| 170 | 170 | 'AHEE__EventEspresso_modules_ticket_selector_TicketSelectorIframe__construct__complete', |
| 171 | - function (EventEspresso\modules\ticket_selector\TicketSelectorIframe $ticket_selector_iframe) use ($localized_vars) { |
|
| 171 | + function(EventEspresso\modules\ticket_selector\TicketSelectorIframe $ticket_selector_iframe) use ($localized_vars) { |
|
| 172 | 172 | $ticket_selector_iframe->addLocalizedVars($localized_vars, 'eeRecaptcha'); |
| 173 | 173 | } |
| 174 | 174 | ); |
@@ -180,13 +180,13 @@ discard block |
||
| 180 | 180 | */ |
| 181 | 181 | private function registerScripts() |
| 182 | 182 | { |
| 183 | - if (! $this->useCaptcha()) { |
|
| 183 | + if ( ! $this->useCaptcha()) { |
|
| 184 | 184 | return; |
| 185 | 185 | } |
| 186 | 186 | add_filter('script_loader_tag', array($this, 'addScriptAttributes'), 10, 2); |
| 187 | 187 | wp_register_script( |
| 188 | 188 | EE_Invisible_Recaptcha_Input::SCRIPT_HANDLE_ESPRESSO_INVISIBLE_RECAPTCHA, |
| 189 | - EED_Recaptcha_Invisible::assetsUrl() . 'espresso_invisible_recaptcha.js', |
|
| 189 | + EED_Recaptcha_Invisible::assetsUrl().'espresso_invisible_recaptcha.js', |
|
| 190 | 190 | array('espresso_core'), |
| 191 | 191 | EVENT_ESPRESSO_VERSION, |
| 192 | 192 | true |
@@ -14,222 +14,222 @@ |
||
| 14 | 14 | */ |
| 15 | 15 | class EE_Invisible_Recaptcha_Input extends EE_Form_Input_Base |
| 16 | 16 | { |
| 17 | - const SCRIPT_HANDLE_GOOGLE_INVISIBLE_RECAPTCHA = 'google_invisible_recaptcha'; |
|
| 18 | - |
|
| 19 | - const SCRIPT_HANDLE_ESPRESSO_INVISIBLE_RECAPTCHA = 'espresso_invisible_recaptcha'; |
|
| 20 | - |
|
| 21 | - /** |
|
| 22 | - * @var EE_Registration_Config $config |
|
| 23 | - */ |
|
| 24 | - private $config; |
|
| 25 | - |
|
| 26 | - /** |
|
| 27 | - * @var string $recaptcha_id |
|
| 28 | - */ |
|
| 29 | - private $recaptcha_id; |
|
| 30 | - |
|
| 31 | - /** |
|
| 32 | - * @var string $submit_button_id |
|
| 33 | - */ |
|
| 34 | - private $submit_button_id; |
|
| 35 | - |
|
| 36 | - |
|
| 37 | - /** |
|
| 38 | - * @param array $input_settings |
|
| 39 | - * @param EE_Registration_Config $registration_config |
|
| 40 | - * @throws InvalidArgumentException |
|
| 41 | - * @throws InvalidDataTypeException |
|
| 42 | - * @throws InvalidInterfaceException |
|
| 43 | - * @throws DomainException |
|
| 44 | - */ |
|
| 45 | - public function __construct(array $input_settings = array(), EE_Registration_Config $registration_config = null) |
|
| 46 | - { |
|
| 47 | - $this->_set_display_strategy(new EE_Invisible_Recaptcha_Display_Strategy()); |
|
| 48 | - parent::__construct($input_settings); |
|
| 49 | - $registration_config = $registration_config instanceof EE_Registration_Config |
|
| 50 | - ? $registration_config |
|
| 51 | - : EE_Registry::instance()->CFG->registration; |
|
| 52 | - $this->config = $registration_config; |
|
| 53 | - $this->recaptcha_id = isset($input_settings['recaptcha_id']) |
|
| 54 | - ? $input_settings['recaptcha_id'] |
|
| 55 | - : substr(spl_object_hash($this), 8, 8); |
|
| 56 | - $this->submit_button_id = isset($input_settings['submit_button_id']) |
|
| 57 | - ? $input_settings['submit_button_id'] |
|
| 58 | - : ''; |
|
| 59 | - if ( |
|
| 60 | - isset($input_settings['localized_vars']) |
|
| 61 | - && filter_var($input_settings['iframe'], FILTER_VALIDATE_BOOLEAN) |
|
| 62 | - ) { |
|
| 63 | - $this->addIframeAssets($input_settings['localized_vars']); |
|
| 64 | - } else { |
|
| 65 | - $this->registerScripts(); |
|
| 66 | - } |
|
| 67 | - } |
|
| 68 | - |
|
| 69 | - |
|
| 70 | - /** |
|
| 71 | - * @return bool |
|
| 72 | - */ |
|
| 73 | - public function useCaptcha() |
|
| 74 | - { |
|
| 75 | - return $this->config->use_captcha && $this->config->recaptcha_theme === 'invisible'; |
|
| 76 | - } |
|
| 77 | - |
|
| 78 | - |
|
| 79 | - /** |
|
| 80 | - * @return string |
|
| 81 | - */ |
|
| 82 | - public function badge() |
|
| 83 | - { |
|
| 84 | - return $this->config->recaptcha_badge; |
|
| 85 | - } |
|
| 86 | - |
|
| 87 | - |
|
| 88 | - /** |
|
| 89 | - * @return string |
|
| 90 | - */ |
|
| 91 | - public function language() |
|
| 92 | - { |
|
| 93 | - return $this->config->recaptcha_language; |
|
| 94 | - } |
|
| 95 | - |
|
| 96 | - |
|
| 97 | - /** |
|
| 98 | - * @return string |
|
| 99 | - */ |
|
| 100 | - public function siteKey() |
|
| 101 | - { |
|
| 102 | - return $this->config->recaptcha_publickey; |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - |
|
| 106 | - /** |
|
| 107 | - * @return string |
|
| 108 | - */ |
|
| 109 | - public function secretKey() |
|
| 110 | - { |
|
| 111 | - return $this->config->recaptcha_privatekey; |
|
| 112 | - } |
|
| 113 | - |
|
| 114 | - |
|
| 115 | - /** |
|
| 116 | - * @return string |
|
| 117 | - */ |
|
| 118 | - public function recaptchaId() |
|
| 119 | - { |
|
| 120 | - return $this->recaptcha_id; |
|
| 121 | - } |
|
| 122 | - |
|
| 123 | - |
|
| 124 | - /** |
|
| 125 | - * @return string |
|
| 126 | - */ |
|
| 127 | - public function submitButtonId() |
|
| 128 | - { |
|
| 129 | - return $this->submit_button_id; |
|
| 130 | - } |
|
| 131 | - |
|
| 132 | - |
|
| 133 | - /** |
|
| 134 | - * @param array $localized_vars |
|
| 135 | - * @throws DomainException |
|
| 136 | - */ |
|
| 137 | - private function addIframeAssets(array $localized_vars) |
|
| 138 | - { |
|
| 139 | - if (! $this->useCaptcha()) { |
|
| 140 | - return; |
|
| 141 | - } |
|
| 142 | - add_filter( |
|
| 143 | - 'FHEE__EED_Ticket_Selector__ticket_selector_iframe__js', |
|
| 144 | - function (array $iframe_assets) { |
|
| 145 | - $iframe_assets[ EE_Invisible_Recaptcha_Input::SCRIPT_HANDLE_ESPRESSO_INVISIBLE_RECAPTCHA ] = |
|
| 146 | - EED_Recaptcha_Invisible::assetsUrl() |
|
| 147 | - . 'espresso_invisible_recaptcha.js?ver=' |
|
| 148 | - . EVENT_ESPRESSO_VERSION; |
|
| 149 | - $iframe_assets[ EE_Invisible_Recaptcha_Input::SCRIPT_HANDLE_GOOGLE_INVISIBLE_RECAPTCHA ] = |
|
| 150 | - add_query_arg( |
|
| 151 | - array( |
|
| 152 | - 'onload' => 'espressoLoadRecaptcha', |
|
| 153 | - 'render' => 'explicit', |
|
| 154 | - 'hl' => $this->language(), |
|
| 155 | - ), |
|
| 156 | - 'https://www.google.com/recaptcha/api.js?' |
|
| 157 | - ); |
|
| 158 | - return $iframe_assets; |
|
| 159 | - } |
|
| 160 | - ); |
|
| 161 | - add_filter( |
|
| 162 | - 'FHEE__EventEspresso_modules_ticket_selector_TicketSelectorIframe__construct__js_attributes', |
|
| 163 | - function (array $iframe_asset_attributes) { |
|
| 164 | - $iframe_asset_attributes[ EE_Invisible_Recaptcha_Input::SCRIPT_HANDLE_GOOGLE_INVISIBLE_RECAPTCHA ] |
|
| 165 | - = ' async="async" defer="defer"'; |
|
| 166 | - return $iframe_asset_attributes; |
|
| 167 | - } |
|
| 168 | - ); |
|
| 169 | - add_action( |
|
| 170 | - 'AHEE__EventEspresso_modules_ticket_selector_TicketSelectorIframe__construct__complete', |
|
| 171 | - function (EventEspresso\modules\ticket_selector\TicketSelectorIframe $ticket_selector_iframe) use ($localized_vars) { |
|
| 172 | - $ticket_selector_iframe->addLocalizedVars($localized_vars, 'eeRecaptcha'); |
|
| 173 | - } |
|
| 174 | - ); |
|
| 175 | - } |
|
| 176 | - |
|
| 177 | - |
|
| 178 | - /** |
|
| 179 | - * @return void |
|
| 180 | - */ |
|
| 181 | - private function registerScripts() |
|
| 182 | - { |
|
| 183 | - if (! $this->useCaptcha()) { |
|
| 184 | - return; |
|
| 185 | - } |
|
| 186 | - add_filter('script_loader_tag', array($this, 'addScriptAttributes'), 10, 2); |
|
| 187 | - wp_register_script( |
|
| 188 | - EE_Invisible_Recaptcha_Input::SCRIPT_HANDLE_ESPRESSO_INVISIBLE_RECAPTCHA, |
|
| 189 | - EED_Recaptcha_Invisible::assetsUrl() . 'espresso_invisible_recaptcha.js', |
|
| 190 | - array('espresso_core'), |
|
| 191 | - EVENT_ESPRESSO_VERSION, |
|
| 192 | - true |
|
| 193 | - ); |
|
| 194 | - wp_register_script( |
|
| 195 | - EE_Invisible_Recaptcha_Input::SCRIPT_HANDLE_GOOGLE_INVISIBLE_RECAPTCHA, |
|
| 196 | - add_query_arg( |
|
| 197 | - array( |
|
| 198 | - 'onload' => 'espressoLoadRecaptcha', |
|
| 199 | - 'render' => 'explicit', |
|
| 200 | - 'hl' => $this->language(), |
|
| 201 | - ), |
|
| 202 | - 'https://www.google.com/recaptcha/api.js?' |
|
| 203 | - ), |
|
| 204 | - array(EE_Invisible_Recaptcha_Input::SCRIPT_HANDLE_ESPRESSO_INVISIBLE_RECAPTCHA), |
|
| 205 | - false, |
|
| 206 | - true |
|
| 207 | - ); |
|
| 208 | - } |
|
| 209 | - |
|
| 210 | - |
|
| 211 | - /** |
|
| 212 | - * @param string $tag |
|
| 213 | - * @param string $handle |
|
| 214 | - * @return string |
|
| 215 | - */ |
|
| 216 | - public function addScriptAttributes($tag, $handle) |
|
| 217 | - { |
|
| 218 | - if ($handle === EE_Invisible_Recaptcha_Input::SCRIPT_HANDLE_GOOGLE_INVISIBLE_RECAPTCHA) { |
|
| 219 | - $tag = str_replace('></script>', ' async="async" defer="defer"></script>', $tag); |
|
| 220 | - } |
|
| 221 | - return $tag; |
|
| 222 | - } |
|
| 223 | - |
|
| 224 | - |
|
| 225 | - /** |
|
| 226 | - * Gets the HTML for displaying the label for this form input |
|
| 227 | - * according to the form section's layout strategy |
|
| 228 | - * |
|
| 229 | - * @return string |
|
| 230 | - */ |
|
| 231 | - public function get_html_for_label() |
|
| 232 | - { |
|
| 233 | - return ''; |
|
| 234 | - } |
|
| 17 | + const SCRIPT_HANDLE_GOOGLE_INVISIBLE_RECAPTCHA = 'google_invisible_recaptcha'; |
|
| 18 | + |
|
| 19 | + const SCRIPT_HANDLE_ESPRESSO_INVISIBLE_RECAPTCHA = 'espresso_invisible_recaptcha'; |
|
| 20 | + |
|
| 21 | + /** |
|
| 22 | + * @var EE_Registration_Config $config |
|
| 23 | + */ |
|
| 24 | + private $config; |
|
| 25 | + |
|
| 26 | + /** |
|
| 27 | + * @var string $recaptcha_id |
|
| 28 | + */ |
|
| 29 | + private $recaptcha_id; |
|
| 30 | + |
|
| 31 | + /** |
|
| 32 | + * @var string $submit_button_id |
|
| 33 | + */ |
|
| 34 | + private $submit_button_id; |
|
| 35 | + |
|
| 36 | + |
|
| 37 | + /** |
|
| 38 | + * @param array $input_settings |
|
| 39 | + * @param EE_Registration_Config $registration_config |
|
| 40 | + * @throws InvalidArgumentException |
|
| 41 | + * @throws InvalidDataTypeException |
|
| 42 | + * @throws InvalidInterfaceException |
|
| 43 | + * @throws DomainException |
|
| 44 | + */ |
|
| 45 | + public function __construct(array $input_settings = array(), EE_Registration_Config $registration_config = null) |
|
| 46 | + { |
|
| 47 | + $this->_set_display_strategy(new EE_Invisible_Recaptcha_Display_Strategy()); |
|
| 48 | + parent::__construct($input_settings); |
|
| 49 | + $registration_config = $registration_config instanceof EE_Registration_Config |
|
| 50 | + ? $registration_config |
|
| 51 | + : EE_Registry::instance()->CFG->registration; |
|
| 52 | + $this->config = $registration_config; |
|
| 53 | + $this->recaptcha_id = isset($input_settings['recaptcha_id']) |
|
| 54 | + ? $input_settings['recaptcha_id'] |
|
| 55 | + : substr(spl_object_hash($this), 8, 8); |
|
| 56 | + $this->submit_button_id = isset($input_settings['submit_button_id']) |
|
| 57 | + ? $input_settings['submit_button_id'] |
|
| 58 | + : ''; |
|
| 59 | + if ( |
|
| 60 | + isset($input_settings['localized_vars']) |
|
| 61 | + && filter_var($input_settings['iframe'], FILTER_VALIDATE_BOOLEAN) |
|
| 62 | + ) { |
|
| 63 | + $this->addIframeAssets($input_settings['localized_vars']); |
|
| 64 | + } else { |
|
| 65 | + $this->registerScripts(); |
|
| 66 | + } |
|
| 67 | + } |
|
| 68 | + |
|
| 69 | + |
|
| 70 | + /** |
|
| 71 | + * @return bool |
|
| 72 | + */ |
|
| 73 | + public function useCaptcha() |
|
| 74 | + { |
|
| 75 | + return $this->config->use_captcha && $this->config->recaptcha_theme === 'invisible'; |
|
| 76 | + } |
|
| 77 | + |
|
| 78 | + |
|
| 79 | + /** |
|
| 80 | + * @return string |
|
| 81 | + */ |
|
| 82 | + public function badge() |
|
| 83 | + { |
|
| 84 | + return $this->config->recaptcha_badge; |
|
| 85 | + } |
|
| 86 | + |
|
| 87 | + |
|
| 88 | + /** |
|
| 89 | + * @return string |
|
| 90 | + */ |
|
| 91 | + public function language() |
|
| 92 | + { |
|
| 93 | + return $this->config->recaptcha_language; |
|
| 94 | + } |
|
| 95 | + |
|
| 96 | + |
|
| 97 | + /** |
|
| 98 | + * @return string |
|
| 99 | + */ |
|
| 100 | + public function siteKey() |
|
| 101 | + { |
|
| 102 | + return $this->config->recaptcha_publickey; |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + |
|
| 106 | + /** |
|
| 107 | + * @return string |
|
| 108 | + */ |
|
| 109 | + public function secretKey() |
|
| 110 | + { |
|
| 111 | + return $this->config->recaptcha_privatekey; |
|
| 112 | + } |
|
| 113 | + |
|
| 114 | + |
|
| 115 | + /** |
|
| 116 | + * @return string |
|
| 117 | + */ |
|
| 118 | + public function recaptchaId() |
|
| 119 | + { |
|
| 120 | + return $this->recaptcha_id; |
|
| 121 | + } |
|
| 122 | + |
|
| 123 | + |
|
| 124 | + /** |
|
| 125 | + * @return string |
|
| 126 | + */ |
|
| 127 | + public function submitButtonId() |
|
| 128 | + { |
|
| 129 | + return $this->submit_button_id; |
|
| 130 | + } |
|
| 131 | + |
|
| 132 | + |
|
| 133 | + /** |
|
| 134 | + * @param array $localized_vars |
|
| 135 | + * @throws DomainException |
|
| 136 | + */ |
|
| 137 | + private function addIframeAssets(array $localized_vars) |
|
| 138 | + { |
|
| 139 | + if (! $this->useCaptcha()) { |
|
| 140 | + return; |
|
| 141 | + } |
|
| 142 | + add_filter( |
|
| 143 | + 'FHEE__EED_Ticket_Selector__ticket_selector_iframe__js', |
|
| 144 | + function (array $iframe_assets) { |
|
| 145 | + $iframe_assets[ EE_Invisible_Recaptcha_Input::SCRIPT_HANDLE_ESPRESSO_INVISIBLE_RECAPTCHA ] = |
|
| 146 | + EED_Recaptcha_Invisible::assetsUrl() |
|
| 147 | + . 'espresso_invisible_recaptcha.js?ver=' |
|
| 148 | + . EVENT_ESPRESSO_VERSION; |
|
| 149 | + $iframe_assets[ EE_Invisible_Recaptcha_Input::SCRIPT_HANDLE_GOOGLE_INVISIBLE_RECAPTCHA ] = |
|
| 150 | + add_query_arg( |
|
| 151 | + array( |
|
| 152 | + 'onload' => 'espressoLoadRecaptcha', |
|
| 153 | + 'render' => 'explicit', |
|
| 154 | + 'hl' => $this->language(), |
|
| 155 | + ), |
|
| 156 | + 'https://www.google.com/recaptcha/api.js?' |
|
| 157 | + ); |
|
| 158 | + return $iframe_assets; |
|
| 159 | + } |
|
| 160 | + ); |
|
| 161 | + add_filter( |
|
| 162 | + 'FHEE__EventEspresso_modules_ticket_selector_TicketSelectorIframe__construct__js_attributes', |
|
| 163 | + function (array $iframe_asset_attributes) { |
|
| 164 | + $iframe_asset_attributes[ EE_Invisible_Recaptcha_Input::SCRIPT_HANDLE_GOOGLE_INVISIBLE_RECAPTCHA ] |
|
| 165 | + = ' async="async" defer="defer"'; |
|
| 166 | + return $iframe_asset_attributes; |
|
| 167 | + } |
|
| 168 | + ); |
|
| 169 | + add_action( |
|
| 170 | + 'AHEE__EventEspresso_modules_ticket_selector_TicketSelectorIframe__construct__complete', |
|
| 171 | + function (EventEspresso\modules\ticket_selector\TicketSelectorIframe $ticket_selector_iframe) use ($localized_vars) { |
|
| 172 | + $ticket_selector_iframe->addLocalizedVars($localized_vars, 'eeRecaptcha'); |
|
| 173 | + } |
|
| 174 | + ); |
|
| 175 | + } |
|
| 176 | + |
|
| 177 | + |
|
| 178 | + /** |
|
| 179 | + * @return void |
|
| 180 | + */ |
|
| 181 | + private function registerScripts() |
|
| 182 | + { |
|
| 183 | + if (! $this->useCaptcha()) { |
|
| 184 | + return; |
|
| 185 | + } |
|
| 186 | + add_filter('script_loader_tag', array($this, 'addScriptAttributes'), 10, 2); |
|
| 187 | + wp_register_script( |
|
| 188 | + EE_Invisible_Recaptcha_Input::SCRIPT_HANDLE_ESPRESSO_INVISIBLE_RECAPTCHA, |
|
| 189 | + EED_Recaptcha_Invisible::assetsUrl() . 'espresso_invisible_recaptcha.js', |
|
| 190 | + array('espresso_core'), |
|
| 191 | + EVENT_ESPRESSO_VERSION, |
|
| 192 | + true |
|
| 193 | + ); |
|
| 194 | + wp_register_script( |
|
| 195 | + EE_Invisible_Recaptcha_Input::SCRIPT_HANDLE_GOOGLE_INVISIBLE_RECAPTCHA, |
|
| 196 | + add_query_arg( |
|
| 197 | + array( |
|
| 198 | + 'onload' => 'espressoLoadRecaptcha', |
|
| 199 | + 'render' => 'explicit', |
|
| 200 | + 'hl' => $this->language(), |
|
| 201 | + ), |
|
| 202 | + 'https://www.google.com/recaptcha/api.js?' |
|
| 203 | + ), |
|
| 204 | + array(EE_Invisible_Recaptcha_Input::SCRIPT_HANDLE_ESPRESSO_INVISIBLE_RECAPTCHA), |
|
| 205 | + false, |
|
| 206 | + true |
|
| 207 | + ); |
|
| 208 | + } |
|
| 209 | + |
|
| 210 | + |
|
| 211 | + /** |
|
| 212 | + * @param string $tag |
|
| 213 | + * @param string $handle |
|
| 214 | + * @return string |
|
| 215 | + */ |
|
| 216 | + public function addScriptAttributes($tag, $handle) |
|
| 217 | + { |
|
| 218 | + if ($handle === EE_Invisible_Recaptcha_Input::SCRIPT_HANDLE_GOOGLE_INVISIBLE_RECAPTCHA) { |
|
| 219 | + $tag = str_replace('></script>', ' async="async" defer="defer"></script>', $tag); |
|
| 220 | + } |
|
| 221 | + return $tag; |
|
| 222 | + } |
|
| 223 | + |
|
| 224 | + |
|
| 225 | + /** |
|
| 226 | + * Gets the HTML for displaying the label for this form input |
|
| 227 | + * according to the form section's layout strategy |
|
| 228 | + * |
|
| 229 | + * @return string |
|
| 230 | + */ |
|
| 231 | + public function get_html_for_label() |
|
| 232 | + { |
|
| 233 | + return ''; |
|
| 234 | + } |
|
| 235 | 235 | } |
@@ -16,7 +16,7 @@ |
||
| 16 | 16 | public function __construct($answer_options, $input_settings = array()) |
| 17 | 17 | { |
| 18 | 18 | $this->_set_display_strategy(new EE_Select_Multiple_Display_Strategy()); |
| 19 | - $this->_add_validation_strategy(new EE_Many_Valued_Validation_Strategy(array( new EE_Enum_Validation_Strategy(isset($input_settings['validation_error_message']) ? $input_settings['validation_error_message'] : null) ))); |
|
| 19 | + $this->_add_validation_strategy(new EE_Many_Valued_Validation_Strategy(array(new EE_Enum_Validation_Strategy(isset($input_settings['validation_error_message']) ? $input_settings['validation_error_message'] : null)))); |
|
| 20 | 20 | $this->_multiple_selections = true; |
| 21 | 21 | parent::__construct($answer_options, $input_settings); |
| 22 | 22 | } |
@@ -9,15 +9,15 @@ |
||
| 9 | 9 | */ |
| 10 | 10 | class EE_Select_Multiple_Input extends EE_Form_Input_With_Options_Base |
| 11 | 11 | { |
| 12 | - /** |
|
| 13 | - * @param array | EE_Question_Option[] $answer_options |
|
| 14 | - * @param array $input_settings |
|
| 15 | - */ |
|
| 16 | - public function __construct($answer_options, $input_settings = array()) |
|
| 17 | - { |
|
| 18 | - $this->_set_display_strategy(new EE_Select_Multiple_Display_Strategy()); |
|
| 19 | - $this->_add_validation_strategy(new EE_Many_Valued_Validation_Strategy(array( new EE_Enum_Validation_Strategy(isset($input_settings['validation_error_message']) ? $input_settings['validation_error_message'] : null) ))); |
|
| 20 | - $this->_multiple_selections = true; |
|
| 21 | - parent::__construct($answer_options, $input_settings); |
|
| 22 | - } |
|
| 12 | + /** |
|
| 13 | + * @param array | EE_Question_Option[] $answer_options |
|
| 14 | + * @param array $input_settings |
|
| 15 | + */ |
|
| 16 | + public function __construct($answer_options, $input_settings = array()) |
|
| 17 | + { |
|
| 18 | + $this->_set_display_strategy(new EE_Select_Multiple_Display_Strategy()); |
|
| 19 | + $this->_add_validation_strategy(new EE_Many_Valued_Validation_Strategy(array( new EE_Enum_Validation_Strategy(isset($input_settings['validation_error_message']) ? $input_settings['validation_error_message'] : null) ))); |
|
| 20 | + $this->_multiple_selections = true; |
|
| 21 | + parent::__construct($answer_options, $input_settings); |
|
| 22 | + } |
|
| 23 | 23 | } |
@@ -21,7 +21,7 @@ |
||
| 21 | 21 | } |
| 22 | 22 | $answer_options = array(); |
| 23 | 23 | for ($start = $current_year_int - $years_behind; $start <= ($current_year_int + $years_ahead); $start++) { |
| 24 | - $answer_options[ $start ] = $start; |
|
| 24 | + $answer_options[$start] = $start; |
|
| 25 | 25 | } |
| 26 | 26 | parent::__construct($answer_options, $input_settings); |
| 27 | 27 | } |
@@ -11,17 +11,17 @@ |
||
| 11 | 11 | */ |
| 12 | 12 | class EE_Year_Input extends EE_Select_Input |
| 13 | 13 | { |
| 14 | - public function __construct($input_settings = array(), $four_digit_year = true, $years_behind = 100, $years_ahead = 0) |
|
| 15 | - { |
|
| 16 | - if ($four_digit_year) { |
|
| 17 | - $current_year_int = intval(date('Y')); |
|
| 18 | - } else { |
|
| 19 | - $current_year_int = intval(date('y')); |
|
| 20 | - } |
|
| 21 | - $answer_options = array(); |
|
| 22 | - for ($start = $current_year_int - $years_behind; $start <= ($current_year_int + $years_ahead); $start++) { |
|
| 23 | - $answer_options[ $start ] = $start; |
|
| 24 | - } |
|
| 25 | - parent::__construct($answer_options, $input_settings); |
|
| 26 | - } |
|
| 14 | + public function __construct($input_settings = array(), $four_digit_year = true, $years_behind = 100, $years_ahead = 0) |
|
| 15 | + { |
|
| 16 | + if ($four_digit_year) { |
|
| 17 | + $current_year_int = intval(date('Y')); |
|
| 18 | + } else { |
|
| 19 | + $current_year_int = intval(date('y')); |
|
| 20 | + } |
|
| 21 | + $answer_options = array(); |
|
| 22 | + for ($start = $current_year_int - $years_behind; $start <= ($current_year_int + $years_ahead); $start++) { |
|
| 23 | + $answer_options[ $start ] = $start; |
|
| 24 | + } |
|
| 25 | + parent::__construct($answer_options, $input_settings); |
|
| 26 | + } |
|
| 27 | 27 | } |
@@ -18,6 +18,6 @@ |
||
| 18 | 18 | $this->_set_display_strategy(new EE_Text_Input_Display_Strategy('password')); |
| 19 | 19 | $this->_set_normalization_strategy(new EE_Text_Normalization()); |
| 20 | 20 | parent::__construct($input_settings); |
| 21 | - $this->set_html_class($this->html_class() . 'password'); |
|
| 21 | + $this->set_html_class($this->html_class().'password'); |
|
| 22 | 22 | } |
| 23 | 23 | } |
@@ -9,14 +9,14 @@ |
||
| 9 | 9 | */ |
| 10 | 10 | class EE_Password_Input extends EE_Form_Input_Base |
| 11 | 11 | { |
| 12 | - /** |
|
| 13 | - * @param array $input_settings |
|
| 14 | - */ |
|
| 15 | - public function __construct($input_settings = array()) |
|
| 16 | - { |
|
| 17 | - $this->_set_display_strategy(new EE_Text_Input_Display_Strategy('password')); |
|
| 18 | - $this->_set_normalization_strategy(new EE_Text_Normalization()); |
|
| 19 | - parent::__construct($input_settings); |
|
| 20 | - $this->set_html_class($this->html_class() . 'password'); |
|
| 21 | - } |
|
| 12 | + /** |
|
| 13 | + * @param array $input_settings |
|
| 14 | + */ |
|
| 15 | + public function __construct($input_settings = array()) |
|
| 16 | + { |
|
| 17 | + $this->_set_display_strategy(new EE_Text_Input_Display_Strategy('password')); |
|
| 18 | + $this->_set_normalization_strategy(new EE_Text_Normalization()); |
|
| 19 | + parent::__construct($input_settings); |
|
| 20 | + $this->set_html_class($this->html_class() . 'password'); |
|
| 21 | + } |
|
| 22 | 22 | } |
@@ -24,6 +24,6 @@ |
||
| 24 | 24 | ) |
| 25 | 25 | ); |
| 26 | 26 | parent::__construct($input_settings); |
| 27 | - $this->set_html_class($this->html_class() . ' email'); |
|
| 27 | + $this->set_html_class($this->html_class().' email'); |
|
| 28 | 28 | } |
| 29 | 29 | } |
@@ -9,21 +9,21 @@ |
||
| 9 | 9 | */ |
| 10 | 10 | class EE_Email_Input extends EE_Form_Input_Base |
| 11 | 11 | { |
| 12 | - /** |
|
| 13 | - * @param array $input_settings |
|
| 14 | - */ |
|
| 15 | - public function __construct($input_settings = array()) |
|
| 16 | - { |
|
| 17 | - $this->_set_display_strategy(new EE_Text_Input_Display_Strategy('email')); |
|
| 18 | - $this->_set_normalization_strategy(new EE_Text_Normalization()); |
|
| 19 | - $this->_add_validation_strategy( |
|
| 20 | - new EE_Email_Validation_Strategy( |
|
| 21 | - isset($input_settings['validation_error_message']) |
|
| 22 | - ? $input_settings['validation_error_message'] |
|
| 23 | - : null |
|
| 24 | - ) |
|
| 25 | - ); |
|
| 26 | - parent::__construct($input_settings); |
|
| 27 | - $this->set_html_class($this->html_class() . ' email'); |
|
| 28 | - } |
|
| 12 | + /** |
|
| 13 | + * @param array $input_settings |
|
| 14 | + */ |
|
| 15 | + public function __construct($input_settings = array()) |
|
| 16 | + { |
|
| 17 | + $this->_set_display_strategy(new EE_Text_Input_Display_Strategy('email')); |
|
| 18 | + $this->_set_normalization_strategy(new EE_Text_Normalization()); |
|
| 19 | + $this->_add_validation_strategy( |
|
| 20 | + new EE_Email_Validation_Strategy( |
|
| 21 | + isset($input_settings['validation_error_message']) |
|
| 22 | + ? $input_settings['validation_error_message'] |
|
| 23 | + : null |
|
| 24 | + ) |
|
| 25 | + ); |
|
| 26 | + parent::__construct($input_settings); |
|
| 27 | + $this->set_html_class($this->html_class() . ' email'); |
|
| 28 | + } |
|
| 29 | 29 | } |
@@ -29,8 +29,8 @@ |
||
| 29 | 29 | 'type' => 'submit', |
| 30 | 30 | 'value' => $default_value, |
| 31 | 31 | // overwrite the standard id with the backwards compatible one |
| 32 | - 'id' => $this->_input->html_id() . '-submit', |
|
| 33 | - 'class' => $this->_input->html_class() . ' ' . $this->_input->button_css_attributes() |
|
| 32 | + 'id' => $this->_input->html_id().'-submit', |
|
| 33 | + 'class' => $this->_input->html_class().' '.$this->_input->button_css_attributes() |
|
| 34 | 34 | ) |
| 35 | 35 | ) |
| 36 | 36 | ); |
@@ -9,29 +9,29 @@ |
||
| 9 | 9 | */ |
| 10 | 10 | class EE_Submit_Input_Display_Strategy extends EE_Display_Strategy_Base |
| 11 | 11 | { |
| 12 | - /** |
|
| 13 | - * @return string of html to display the input |
|
| 14 | - */ |
|
| 15 | - public function display() |
|
| 16 | - { |
|
| 17 | - $default_value = $this->_input->get_default(); |
|
| 18 | - if ($this->_input->get_normalization_strategy() instanceof EE_Normalization_Strategy_Base) { |
|
| 19 | - $default_value = $this->_input->get_normalization_strategy()->unnormalize($default_value); |
|
| 20 | - } |
|
| 21 | - $html = $this->_opening_tag('input'); |
|
| 22 | - $html .= $this->_attributes_string( |
|
| 23 | - array_merge( |
|
| 24 | - $this->_standard_attributes_array(), |
|
| 25 | - array( |
|
| 26 | - 'type' => 'submit', |
|
| 27 | - 'value' => $default_value, |
|
| 28 | - // overwrite the standard id with the backwards compatible one |
|
| 29 | - 'id' => $this->_input->html_id() . '-submit', |
|
| 30 | - 'class' => $this->_input->html_class() . ' ' . $this->_input->button_css_attributes() |
|
| 31 | - ) |
|
| 32 | - ) |
|
| 33 | - ); |
|
| 34 | - $html .= $this->_close_tag(); |
|
| 35 | - return $html; |
|
| 36 | - } |
|
| 12 | + /** |
|
| 13 | + * @return string of html to display the input |
|
| 14 | + */ |
|
| 15 | + public function display() |
|
| 16 | + { |
|
| 17 | + $default_value = $this->_input->get_default(); |
|
| 18 | + if ($this->_input->get_normalization_strategy() instanceof EE_Normalization_Strategy_Base) { |
|
| 19 | + $default_value = $this->_input->get_normalization_strategy()->unnormalize($default_value); |
|
| 20 | + } |
|
| 21 | + $html = $this->_opening_tag('input'); |
|
| 22 | + $html .= $this->_attributes_string( |
|
| 23 | + array_merge( |
|
| 24 | + $this->_standard_attributes_array(), |
|
| 25 | + array( |
|
| 26 | + 'type' => 'submit', |
|
| 27 | + 'value' => $default_value, |
|
| 28 | + // overwrite the standard id with the backwards compatible one |
|
| 29 | + 'id' => $this->_input->html_id() . '-submit', |
|
| 30 | + 'class' => $this->_input->html_class() . ' ' . $this->_input->button_css_attributes() |
|
| 31 | + ) |
|
| 32 | + ) |
|
| 33 | + ); |
|
| 34 | + $html .= $this->_close_tag(); |
|
| 35 | + return $html; |
|
| 36 | + } |
|
| 37 | 37 | } |
@@ -11,13 +11,13 @@ |
||
| 11 | 11 | */ |
| 12 | 12 | class EE_Hidden_Display_Strategy extends EE_Display_Strategy_Base |
| 13 | 13 | { |
| 14 | - /** |
|
| 15 | - * |
|
| 16 | - * @return string of html to display the HIDDEN field |
|
| 17 | - */ |
|
| 18 | - public function display() |
|
| 19 | - { |
|
| 20 | - $input = $this->_input; |
|
| 21 | - return "<input type='hidden' id='{$input->html_id()}' name='{$input->html_name()}' class='{$input->html_class()}' style='{$input->html_style()}' value='{$input->raw_value_in_form()}' {$input->other_html_attributes()}/>"; |
|
| 22 | - } |
|
| 14 | + /** |
|
| 15 | + * |
|
| 16 | + * @return string of html to display the HIDDEN field |
|
| 17 | + */ |
|
| 18 | + public function display() |
|
| 19 | + { |
|
| 20 | + $input = $this->_input; |
|
| 21 | + return "<input type='hidden' id='{$input->html_id()}' name='{$input->html_name()}' class='{$input->html_class()}' style='{$input->html_style()}' value='{$input->raw_value_in_form()}' {$input->other_html_attributes()}/>"; |
|
| 22 | + } |
|
| 23 | 23 | } |
@@ -20,12 +20,12 @@ |
||
| 20 | 20 | $cols = 20; |
| 21 | 21 | } |
| 22 | 22 | $html = '<textarea'; |
| 23 | - $html .= ' id="' . $input->html_id() . '"'; |
|
| 24 | - $html .= ' name="' . $input->html_name() . '"'; |
|
| 25 | - $html .= ' class="' . $input->html_class() . '"' ; |
|
| 26 | - $html .= ' style="' . $input->html_style() . '"'; |
|
| 23 | + $html .= ' id="'.$input->html_id().'"'; |
|
| 24 | + $html .= ' name="'.$input->html_name().'"'; |
|
| 25 | + $html .= ' class="'.$input->html_class().'"'; |
|
| 26 | + $html .= ' style="'.$input->html_style().'"'; |
|
| 27 | 27 | $html .= $input->other_html_attributes(); |
| 28 | - $html .= ' rows= "' . $rows . '" cols="' . $cols . '">'; |
|
| 28 | + $html .= ' rows= "'.$rows.'" cols="'.$cols.'">'; |
|
| 29 | 29 | $html .= esc_textarea($raw_value); |
| 30 | 30 | $html .= '</textarea>'; |
| 31 | 31 | foreach ($this->_input->get_validation_strategies() as $validation_strategy) { |
@@ -2,43 +2,43 @@ |
||
| 2 | 2 | |
| 3 | 3 | class EE_Text_Area_Display_Strategy extends EE_Display_Strategy_Base |
| 4 | 4 | { |
| 5 | - /** |
|
| 6 | - * |
|
| 7 | - * @return string of html to display the field |
|
| 8 | - */ |
|
| 9 | - public function display() |
|
| 10 | - { |
|
| 11 | - $input = $this->_input; |
|
| 12 | - $raw_value = maybe_serialize($input->raw_value()); |
|
| 13 | - if ($input instanceof EE_Text_Area_Input) { |
|
| 14 | - $rows = $input->get_rows(); |
|
| 15 | - $cols = $input->get_cols(); |
|
| 16 | - } else { |
|
| 17 | - $rows = 4; |
|
| 18 | - $cols = 20; |
|
| 19 | - } |
|
| 20 | - $html = '<textarea'; |
|
| 21 | - $html .= ' id="' . $input->html_id() . '"'; |
|
| 22 | - $html .= ' name="' . $input->html_name() . '"'; |
|
| 23 | - $html .= ' class="' . $input->html_class() . '"' ; |
|
| 24 | - $html .= ' style="' . $input->html_style() . '"'; |
|
| 25 | - $html .= $input->other_html_attributes(); |
|
| 26 | - $html .= ' rows= "' . $rows . '" cols="' . $cols . '">'; |
|
| 27 | - $html .= esc_textarea($raw_value); |
|
| 28 | - $html .= '</textarea>'; |
|
| 29 | - foreach ($this->_input->get_validation_strategies() as $validation_strategy) { |
|
| 30 | - if ( |
|
| 31 | - $validation_strategy instanceof EE_Simple_HTML_Validation_Strategy |
|
| 32 | - || $validation_strategy instanceof EE_Full_HTML_Validation_Strategy |
|
| 33 | - ) { |
|
| 34 | - $html .= sprintf( |
|
| 35 | - esc_html__('%1$s(allowed tags: %2$s)%3$s', 'event_espresso'), |
|
| 36 | - '<p class="ee-question-desc">', |
|
| 37 | - $validation_strategy->get_list_of_allowed_tags(), |
|
| 38 | - '</p>' |
|
| 39 | - ); |
|
| 40 | - } |
|
| 41 | - } |
|
| 42 | - return $html; |
|
| 43 | - } |
|
| 5 | + /** |
|
| 6 | + * |
|
| 7 | + * @return string of html to display the field |
|
| 8 | + */ |
|
| 9 | + public function display() |
|
| 10 | + { |
|
| 11 | + $input = $this->_input; |
|
| 12 | + $raw_value = maybe_serialize($input->raw_value()); |
|
| 13 | + if ($input instanceof EE_Text_Area_Input) { |
|
| 14 | + $rows = $input->get_rows(); |
|
| 15 | + $cols = $input->get_cols(); |
|
| 16 | + } else { |
|
| 17 | + $rows = 4; |
|
| 18 | + $cols = 20; |
|
| 19 | + } |
|
| 20 | + $html = '<textarea'; |
|
| 21 | + $html .= ' id="' . $input->html_id() . '"'; |
|
| 22 | + $html .= ' name="' . $input->html_name() . '"'; |
|
| 23 | + $html .= ' class="' . $input->html_class() . '"' ; |
|
| 24 | + $html .= ' style="' . $input->html_style() . '"'; |
|
| 25 | + $html .= $input->other_html_attributes(); |
|
| 26 | + $html .= ' rows= "' . $rows . '" cols="' . $cols . '">'; |
|
| 27 | + $html .= esc_textarea($raw_value); |
|
| 28 | + $html .= '</textarea>'; |
|
| 29 | + foreach ($this->_input->get_validation_strategies() as $validation_strategy) { |
|
| 30 | + if ( |
|
| 31 | + $validation_strategy instanceof EE_Simple_HTML_Validation_Strategy |
|
| 32 | + || $validation_strategy instanceof EE_Full_HTML_Validation_Strategy |
|
| 33 | + ) { |
|
| 34 | + $html .= sprintf( |
|
| 35 | + esc_html__('%1$s(allowed tags: %2$s)%3$s', 'event_espresso'), |
|
| 36 | + '<p class="ee-question-desc">', |
|
| 37 | + $validation_strategy->get_list_of_allowed_tags(), |
|
| 38 | + '</p>' |
|
| 39 | + ); |
|
| 40 | + } |
|
| 41 | + } |
|
| 42 | + return $html; |
|
| 43 | + } |
|
| 44 | 44 | } |
@@ -43,7 +43,7 @@ discard block |
||
| 43 | 43 | } |
| 44 | 44 | $normalized_array_value = array(); |
| 45 | 45 | foreach ($items_to_normalize as $key => $individual_item) { |
| 46 | - $normalized_array_value[ $key ] = $this->normalize_one($individual_item); |
|
| 46 | + $normalized_array_value[$key] = $this->normalize_one($individual_item); |
|
| 47 | 47 | } |
| 48 | 48 | return $normalized_array_value; |
| 49 | 49 | } |
@@ -74,12 +74,12 @@ discard block |
||
| 74 | 74 | if ($normalized_values === null) { |
| 75 | 75 | $normalized_values = array(); |
| 76 | 76 | } |
| 77 | - if (! is_array($normalized_values)) { |
|
| 77 | + if ( ! is_array($normalized_values)) { |
|
| 78 | 78 | $normalized_values = array($normalized_values); |
| 79 | 79 | } |
| 80 | 80 | $non_normal_values = array(); |
| 81 | 81 | foreach ($normalized_values as $key => $value) { |
| 82 | - $non_normal_values[ $key ] = $this->unnormalize_one($value); |
|
| 82 | + $non_normal_values[$key] = $this->unnormalize_one($value); |
|
| 83 | 83 | } |
| 84 | 84 | return $non_normal_values; |
| 85 | 85 | } |
@@ -9,90 +9,90 @@ |
||
| 9 | 9 | */ |
| 10 | 10 | class EE_Many_Valued_Normalization extends EE_Normalization_Strategy_Base |
| 11 | 11 | { |
| 12 | - protected $_individual_item_normalization_strategy = array(); |
|
| 13 | - |
|
| 14 | - |
|
| 15 | - |
|
| 16 | - /** |
|
| 17 | - * @param EE_Normalization_Strategy_Base $individual_item_normalization_strategy |
|
| 18 | - */ |
|
| 19 | - public function __construct($individual_item_normalization_strategy) |
|
| 20 | - { |
|
| 21 | - $this->_individual_item_normalization_strategy = $individual_item_normalization_strategy; |
|
| 22 | - parent::__construct(); |
|
| 23 | - } |
|
| 24 | - |
|
| 25 | - |
|
| 26 | - |
|
| 27 | - /** |
|
| 28 | - * Normalizes the input into an array, and normalizes each item according to its |
|
| 29 | - * individual item normalization strategy |
|
| 30 | - * |
|
| 31 | - * @param array | string $value_to_normalize |
|
| 32 | - * @return array |
|
| 33 | - */ |
|
| 34 | - public function normalize($value_to_normalize) |
|
| 35 | - { |
|
| 36 | - if (is_array($value_to_normalize)) { |
|
| 37 | - $items_to_normalize = $value_to_normalize; |
|
| 38 | - } elseif ($value_to_normalize !== null) { |
|
| 39 | - $items_to_normalize = array($value_to_normalize); |
|
| 40 | - } else { |
|
| 41 | - $items_to_normalize = array(); |
|
| 42 | - } |
|
| 43 | - $normalized_array_value = array(); |
|
| 44 | - foreach ($items_to_normalize as $key => $individual_item) { |
|
| 45 | - $normalized_array_value[ $key ] = $this->normalize_one($individual_item); |
|
| 46 | - } |
|
| 47 | - return $normalized_array_value; |
|
| 48 | - } |
|
| 49 | - |
|
| 50 | - |
|
| 51 | - |
|
| 52 | - /** |
|
| 53 | - * Normalized the one item (called for each array item in EE_Many_values_Normalization::normalize()) |
|
| 54 | - * |
|
| 55 | - * @param string $individual_value_to_normalize but definitely NOT an array |
|
| 56 | - * @return mixed |
|
| 57 | - */ |
|
| 58 | - public function normalize_one($individual_value_to_normalize) |
|
| 59 | - { |
|
| 60 | - return $this->_individual_item_normalization_strategy->normalize($individual_value_to_normalize); |
|
| 61 | - } |
|
| 62 | - |
|
| 63 | - |
|
| 64 | - |
|
| 65 | - /** |
|
| 66 | - * Converts the array of normalized things to an array of raw html values. |
|
| 67 | - * |
|
| 68 | - * @param array $normalized_values |
|
| 69 | - * @return string[] |
|
| 70 | - */ |
|
| 71 | - public function unnormalize($normalized_values) |
|
| 72 | - { |
|
| 73 | - if ($normalized_values === null) { |
|
| 74 | - $normalized_values = array(); |
|
| 75 | - } |
|
| 76 | - if (! is_array($normalized_values)) { |
|
| 77 | - $normalized_values = array($normalized_values); |
|
| 78 | - } |
|
| 79 | - $non_normal_values = array(); |
|
| 80 | - foreach ($normalized_values as $key => $value) { |
|
| 81 | - $non_normal_values[ $key ] = $this->unnormalize_one($value); |
|
| 82 | - } |
|
| 83 | - return $non_normal_values; |
|
| 84 | - } |
|
| 85 | - |
|
| 86 | - |
|
| 87 | - |
|
| 88 | - /** |
|
| 89 | - * Unnormalizes an individual item in the array of values |
|
| 90 | - * |
|
| 91 | - * @param mixed $individual_value_to_unnormalize but certainly NOT an array |
|
| 92 | - * @return string |
|
| 93 | - */ |
|
| 94 | - public function unnormalize_one($individual_value_to_unnormalize) |
|
| 95 | - { |
|
| 96 | - return $this->_individual_item_normalization_strategy->unnormalize($individual_value_to_unnormalize); |
|
| 97 | - } |
|
| 12 | + protected $_individual_item_normalization_strategy = array(); |
|
| 13 | + |
|
| 14 | + |
|
| 15 | + |
|
| 16 | + /** |
|
| 17 | + * @param EE_Normalization_Strategy_Base $individual_item_normalization_strategy |
|
| 18 | + */ |
|
| 19 | + public function __construct($individual_item_normalization_strategy) |
|
| 20 | + { |
|
| 21 | + $this->_individual_item_normalization_strategy = $individual_item_normalization_strategy; |
|
| 22 | + parent::__construct(); |
|
| 23 | + } |
|
| 24 | + |
|
| 25 | + |
|
| 26 | + |
|
| 27 | + /** |
|
| 28 | + * Normalizes the input into an array, and normalizes each item according to its |
|
| 29 | + * individual item normalization strategy |
|
| 30 | + * |
|
| 31 | + * @param array | string $value_to_normalize |
|
| 32 | + * @return array |
|
| 33 | + */ |
|
| 34 | + public function normalize($value_to_normalize) |
|
| 35 | + { |
|
| 36 | + if (is_array($value_to_normalize)) { |
|
| 37 | + $items_to_normalize = $value_to_normalize; |
|
| 38 | + } elseif ($value_to_normalize !== null) { |
|
| 39 | + $items_to_normalize = array($value_to_normalize); |
|
| 40 | + } else { |
|
| 41 | + $items_to_normalize = array(); |
|
| 42 | + } |
|
| 43 | + $normalized_array_value = array(); |
|
| 44 | + foreach ($items_to_normalize as $key => $individual_item) { |
|
| 45 | + $normalized_array_value[ $key ] = $this->normalize_one($individual_item); |
|
| 46 | + } |
|
| 47 | + return $normalized_array_value; |
|
| 48 | + } |
|
| 49 | + |
|
| 50 | + |
|
| 51 | + |
|
| 52 | + /** |
|
| 53 | + * Normalized the one item (called for each array item in EE_Many_values_Normalization::normalize()) |
|
| 54 | + * |
|
| 55 | + * @param string $individual_value_to_normalize but definitely NOT an array |
|
| 56 | + * @return mixed |
|
| 57 | + */ |
|
| 58 | + public function normalize_one($individual_value_to_normalize) |
|
| 59 | + { |
|
| 60 | + return $this->_individual_item_normalization_strategy->normalize($individual_value_to_normalize); |
|
| 61 | + } |
|
| 62 | + |
|
| 63 | + |
|
| 64 | + |
|
| 65 | + /** |
|
| 66 | + * Converts the array of normalized things to an array of raw html values. |
|
| 67 | + * |
|
| 68 | + * @param array $normalized_values |
|
| 69 | + * @return string[] |
|
| 70 | + */ |
|
| 71 | + public function unnormalize($normalized_values) |
|
| 72 | + { |
|
| 73 | + if ($normalized_values === null) { |
|
| 74 | + $normalized_values = array(); |
|
| 75 | + } |
|
| 76 | + if (! is_array($normalized_values)) { |
|
| 77 | + $normalized_values = array($normalized_values); |
|
| 78 | + } |
|
| 79 | + $non_normal_values = array(); |
|
| 80 | + foreach ($normalized_values as $key => $value) { |
|
| 81 | + $non_normal_values[ $key ] = $this->unnormalize_one($value); |
|
| 82 | + } |
|
| 83 | + return $non_normal_values; |
|
| 84 | + } |
|
| 85 | + |
|
| 86 | + |
|
| 87 | + |
|
| 88 | + /** |
|
| 89 | + * Unnormalizes an individual item in the array of values |
|
| 90 | + * |
|
| 91 | + * @param mixed $individual_value_to_unnormalize but certainly NOT an array |
|
| 92 | + * @return string |
|
| 93 | + */ |
|
| 94 | + public function unnormalize_one($individual_value_to_unnormalize) |
|
| 95 | + { |
|
| 96 | + return $this->_individual_item_normalization_strategy->unnormalize($individual_value_to_unnormalize); |
|
| 97 | + } |
|
| 98 | 98 | } |