@@ -27,270 +27,270 @@ |
||
| 27 | 27 | class InvisibleRecaptcha |
| 28 | 28 | { |
| 29 | 29 | |
| 30 | - const URL_GOOGLE_RECAPTCHA_API = 'https://www.google.com/recaptcha/api/siteverify'; |
|
| 30 | + const URL_GOOGLE_RECAPTCHA_API = 'https://www.google.com/recaptcha/api/siteverify'; |
|
| 31 | 31 | |
| 32 | - const SESSION_DATA_KEY_RECAPTCHA_PASSED = 'recaptcha_passed'; |
|
| 32 | + const SESSION_DATA_KEY_RECAPTCHA_PASSED = 'recaptcha_passed'; |
|
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * @var EE_Registration_Config $config |
|
| 36 | - */ |
|
| 37 | - private $config; |
|
| 34 | + /** |
|
| 35 | + * @var EE_Registration_Config $config |
|
| 36 | + */ |
|
| 37 | + private $config; |
|
| 38 | 38 | |
| 39 | - /** |
|
| 40 | - * @var EE_Session $session |
|
| 41 | - */ |
|
| 42 | - private $session; |
|
| 39 | + /** |
|
| 40 | + * @var EE_Session $session |
|
| 41 | + */ |
|
| 42 | + private $session; |
|
| 43 | 43 | |
| 44 | - /** |
|
| 45 | - * @var boolean $recaptcha_passed |
|
| 46 | - */ |
|
| 47 | - private $recaptcha_passed; |
|
| 44 | + /** |
|
| 45 | + * @var boolean $recaptcha_passed |
|
| 46 | + */ |
|
| 47 | + private $recaptcha_passed; |
|
| 48 | 48 | |
| 49 | 49 | |
| 50 | - /** |
|
| 51 | - * InvisibleRecaptcha constructor. |
|
| 52 | - * |
|
| 53 | - * @param EE_Registration_Config $registration_config |
|
| 54 | - * @param EE_Session $session |
|
| 55 | - */ |
|
| 56 | - public function __construct(EE_Registration_Config $registration_config, EE_Session $session) |
|
| 57 | - { |
|
| 58 | - $this->config = $registration_config; |
|
| 59 | - $this->session = $session; |
|
| 60 | - } |
|
| 50 | + /** |
|
| 51 | + * InvisibleRecaptcha constructor. |
|
| 52 | + * |
|
| 53 | + * @param EE_Registration_Config $registration_config |
|
| 54 | + * @param EE_Session $session |
|
| 55 | + */ |
|
| 56 | + public function __construct(EE_Registration_Config $registration_config, EE_Session $session) |
|
| 57 | + { |
|
| 58 | + $this->config = $registration_config; |
|
| 59 | + $this->session = $session; |
|
| 60 | + } |
|
| 61 | 61 | |
| 62 | 62 | |
| 63 | - /** |
|
| 64 | - * @return boolean |
|
| 65 | - */ |
|
| 66 | - public function useInvisibleRecaptcha() |
|
| 67 | - { |
|
| 68 | - return $this->config->use_captcha && $this->config->recaptcha_theme === 'invisible'; |
|
| 69 | - } |
|
| 63 | + /** |
|
| 64 | + * @return boolean |
|
| 65 | + */ |
|
| 66 | + public function useInvisibleRecaptcha() |
|
| 67 | + { |
|
| 68 | + return $this->config->use_captcha && $this->config->recaptcha_theme === 'invisible'; |
|
| 69 | + } |
|
| 70 | 70 | |
| 71 | 71 | |
| 72 | - /** |
|
| 73 | - * @param array $input_settings |
|
| 74 | - * @return EE_Invisible_Recaptcha_Input |
|
| 75 | - * @throws InvalidDataTypeException |
|
| 76 | - * @throws InvalidInterfaceException |
|
| 77 | - * @throws InvalidArgumentException |
|
| 78 | - * @throws DomainException |
|
| 79 | - */ |
|
| 80 | - public function getInput(array $input_settings = array()) |
|
| 81 | - { |
|
| 82 | - return new EE_Invisible_Recaptcha_Input( |
|
| 83 | - $input_settings, |
|
| 84 | - $this->config |
|
| 85 | - ); |
|
| 86 | - } |
|
| 72 | + /** |
|
| 73 | + * @param array $input_settings |
|
| 74 | + * @return EE_Invisible_Recaptcha_Input |
|
| 75 | + * @throws InvalidDataTypeException |
|
| 76 | + * @throws InvalidInterfaceException |
|
| 77 | + * @throws InvalidArgumentException |
|
| 78 | + * @throws DomainException |
|
| 79 | + */ |
|
| 80 | + public function getInput(array $input_settings = array()) |
|
| 81 | + { |
|
| 82 | + return new EE_Invisible_Recaptcha_Input( |
|
| 83 | + $input_settings, |
|
| 84 | + $this->config |
|
| 85 | + ); |
|
| 86 | + } |
|
| 87 | 87 | |
| 88 | 88 | |
| 89 | - /** |
|
| 90 | - * @param array $input_settings |
|
| 91 | - * @return string |
|
| 92 | - * @throws EE_Error |
|
| 93 | - * @throws InvalidDataTypeException |
|
| 94 | - * @throws InvalidInterfaceException |
|
| 95 | - * @throws InvalidArgumentException |
|
| 96 | - * @throws DomainException |
|
| 97 | - */ |
|
| 98 | - public function getInputHtml(array $input_settings = array()) |
|
| 99 | - { |
|
| 100 | - return $this->getInput($input_settings)->get_html_for_input(); |
|
| 101 | - } |
|
| 89 | + /** |
|
| 90 | + * @param array $input_settings |
|
| 91 | + * @return string |
|
| 92 | + * @throws EE_Error |
|
| 93 | + * @throws InvalidDataTypeException |
|
| 94 | + * @throws InvalidInterfaceException |
|
| 95 | + * @throws InvalidArgumentException |
|
| 96 | + * @throws DomainException |
|
| 97 | + */ |
|
| 98 | + public function getInputHtml(array $input_settings = array()) |
|
| 99 | + { |
|
| 100 | + return $this->getInput($input_settings)->get_html_for_input(); |
|
| 101 | + } |
|
| 102 | 102 | |
| 103 | 103 | |
| 104 | - /** |
|
| 105 | - * @param EE_Form_Section_Proper $form |
|
| 106 | - * @param array $input_settings |
|
| 107 | - * @throws EE_Error |
|
| 108 | - * @throws InvalidArgumentException |
|
| 109 | - * @throws InvalidDataTypeException |
|
| 110 | - * @throws InvalidInterfaceException |
|
| 111 | - * @throws DomainException |
|
| 112 | - */ |
|
| 113 | - public function addToFormSection(EE_Form_Section_Proper $form, array $input_settings = array()) |
|
| 114 | - { |
|
| 115 | - $form->add_subsections( |
|
| 116 | - array( |
|
| 117 | - 'espresso_recaptcha' => $this->getInput($input_settings), |
|
| 118 | - ), |
|
| 119 | - null, |
|
| 120 | - false |
|
| 121 | - ); |
|
| 122 | - } |
|
| 104 | + /** |
|
| 105 | + * @param EE_Form_Section_Proper $form |
|
| 106 | + * @param array $input_settings |
|
| 107 | + * @throws EE_Error |
|
| 108 | + * @throws InvalidArgumentException |
|
| 109 | + * @throws InvalidDataTypeException |
|
| 110 | + * @throws InvalidInterfaceException |
|
| 111 | + * @throws DomainException |
|
| 112 | + */ |
|
| 113 | + public function addToFormSection(EE_Form_Section_Proper $form, array $input_settings = array()) |
|
| 114 | + { |
|
| 115 | + $form->add_subsections( |
|
| 116 | + array( |
|
| 117 | + 'espresso_recaptcha' => $this->getInput($input_settings), |
|
| 118 | + ), |
|
| 119 | + null, |
|
| 120 | + false |
|
| 121 | + ); |
|
| 122 | + } |
|
| 123 | 123 | |
| 124 | 124 | |
| 125 | - /** |
|
| 126 | - * @param RequestInterface $request |
|
| 127 | - * @return boolean |
|
| 128 | - * @throws InvalidArgumentException |
|
| 129 | - * @throws InvalidDataTypeException |
|
| 130 | - * @throws InvalidInterfaceException |
|
| 131 | - * @throws RuntimeException |
|
| 132 | - */ |
|
| 133 | - public function verifyToken(RequestInterface $request) |
|
| 134 | - { |
|
| 135 | - static $previous_recaptcha_response = array(); |
|
| 136 | - $grecaptcha_response = $request->getRequestParam('g-recaptcha-response'); |
|
| 137 | - // if this token has already been verified, then return previous response |
|
| 138 | - if (isset($previous_recaptcha_response[ $grecaptcha_response ])) { |
|
| 139 | - return $previous_recaptcha_response[ $grecaptcha_response ]; |
|
| 140 | - } |
|
| 141 | - // still here but no g-recaptcha-response ? - verification failed |
|
| 142 | - if (! $grecaptcha_response) { |
|
| 143 | - EE_Error::add_error( |
|
| 144 | - sprintf( |
|
| 145 | - /* translators: 1: missing parameter */ |
|
| 146 | - esc_html__( |
|
| 147 | - // @codingStandardsIgnoreStart |
|
| 148 | - 'We\'re sorry but an attempt to verify the form\'s reCAPTCHA has failed. Missing "%1$s". Please try again.', |
|
| 149 | - // @codingStandardsIgnoreEnd |
|
| 150 | - 'event_espresso' |
|
| 151 | - ), |
|
| 152 | - 'g-recaptcha-response' |
|
| 153 | - ), |
|
| 154 | - __FILE__, |
|
| 155 | - __FUNCTION__, |
|
| 156 | - __LINE__ |
|
| 157 | - ); |
|
| 158 | - return false; |
|
| 159 | - } |
|
| 160 | - // will update to true if everything passes |
|
| 161 | - $previous_recaptcha_response[ $grecaptcha_response ] = false; |
|
| 162 | - $response = wp_safe_remote_post( |
|
| 163 | - InvisibleRecaptcha::URL_GOOGLE_RECAPTCHA_API, |
|
| 164 | - array( |
|
| 165 | - 'body' => array( |
|
| 166 | - 'secret' => $this->config->recaptcha_privatekey, |
|
| 167 | - 'response' => $grecaptcha_response, |
|
| 168 | - 'remoteip' => $request->ipAddress(), |
|
| 169 | - ), |
|
| 170 | - ) |
|
| 171 | - ); |
|
| 172 | - if ($response instanceof WP_Error) { |
|
| 173 | - $this->generateError($response->get_error_messages()); |
|
| 174 | - return false; |
|
| 175 | - } |
|
| 176 | - $results = json_decode(wp_remote_retrieve_body($response), true); |
|
| 177 | - if (filter_var($results['success'], FILTER_VALIDATE_BOOLEAN) !== true) { |
|
| 178 | - $errors = array_map( |
|
| 179 | - array($this, 'getErrorCode'), |
|
| 180 | - $results['error-codes'] |
|
| 181 | - ); |
|
| 182 | - if (isset($results['challenge_ts'])) { |
|
| 183 | - $errors[] = 'challenge timestamp: ' . $results['challenge_ts'] . '.'; |
|
| 184 | - } |
|
| 185 | - $this->generateError(implode(' ', $errors), true); |
|
| 186 | - } |
|
| 187 | - $previous_recaptcha_response[ $grecaptcha_response ] = true; |
|
| 188 | - add_action('shutdown', array($this, 'setSessionData')); |
|
| 189 | - return true; |
|
| 190 | - } |
|
| 125 | + /** |
|
| 126 | + * @param RequestInterface $request |
|
| 127 | + * @return boolean |
|
| 128 | + * @throws InvalidArgumentException |
|
| 129 | + * @throws InvalidDataTypeException |
|
| 130 | + * @throws InvalidInterfaceException |
|
| 131 | + * @throws RuntimeException |
|
| 132 | + */ |
|
| 133 | + public function verifyToken(RequestInterface $request) |
|
| 134 | + { |
|
| 135 | + static $previous_recaptcha_response = array(); |
|
| 136 | + $grecaptcha_response = $request->getRequestParam('g-recaptcha-response'); |
|
| 137 | + // if this token has already been verified, then return previous response |
|
| 138 | + if (isset($previous_recaptcha_response[ $grecaptcha_response ])) { |
|
| 139 | + return $previous_recaptcha_response[ $grecaptcha_response ]; |
|
| 140 | + } |
|
| 141 | + // still here but no g-recaptcha-response ? - verification failed |
|
| 142 | + if (! $grecaptcha_response) { |
|
| 143 | + EE_Error::add_error( |
|
| 144 | + sprintf( |
|
| 145 | + /* translators: 1: missing parameter */ |
|
| 146 | + esc_html__( |
|
| 147 | + // @codingStandardsIgnoreStart |
|
| 148 | + 'We\'re sorry but an attempt to verify the form\'s reCAPTCHA has failed. Missing "%1$s". Please try again.', |
|
| 149 | + // @codingStandardsIgnoreEnd |
|
| 150 | + 'event_espresso' |
|
| 151 | + ), |
|
| 152 | + 'g-recaptcha-response' |
|
| 153 | + ), |
|
| 154 | + __FILE__, |
|
| 155 | + __FUNCTION__, |
|
| 156 | + __LINE__ |
|
| 157 | + ); |
|
| 158 | + return false; |
|
| 159 | + } |
|
| 160 | + // will update to true if everything passes |
|
| 161 | + $previous_recaptcha_response[ $grecaptcha_response ] = false; |
|
| 162 | + $response = wp_safe_remote_post( |
|
| 163 | + InvisibleRecaptcha::URL_GOOGLE_RECAPTCHA_API, |
|
| 164 | + array( |
|
| 165 | + 'body' => array( |
|
| 166 | + 'secret' => $this->config->recaptcha_privatekey, |
|
| 167 | + 'response' => $grecaptcha_response, |
|
| 168 | + 'remoteip' => $request->ipAddress(), |
|
| 169 | + ), |
|
| 170 | + ) |
|
| 171 | + ); |
|
| 172 | + if ($response instanceof WP_Error) { |
|
| 173 | + $this->generateError($response->get_error_messages()); |
|
| 174 | + return false; |
|
| 175 | + } |
|
| 176 | + $results = json_decode(wp_remote_retrieve_body($response), true); |
|
| 177 | + if (filter_var($results['success'], FILTER_VALIDATE_BOOLEAN) !== true) { |
|
| 178 | + $errors = array_map( |
|
| 179 | + array($this, 'getErrorCode'), |
|
| 180 | + $results['error-codes'] |
|
| 181 | + ); |
|
| 182 | + if (isset($results['challenge_ts'])) { |
|
| 183 | + $errors[] = 'challenge timestamp: ' . $results['challenge_ts'] . '.'; |
|
| 184 | + } |
|
| 185 | + $this->generateError(implode(' ', $errors), true); |
|
| 186 | + } |
|
| 187 | + $previous_recaptcha_response[ $grecaptcha_response ] = true; |
|
| 188 | + add_action('shutdown', array($this, 'setSessionData')); |
|
| 189 | + return true; |
|
| 190 | + } |
|
| 191 | 191 | |
| 192 | 192 | |
| 193 | - /** |
|
| 194 | - * @param string $error_response |
|
| 195 | - * @param bool $show_errors |
|
| 196 | - * @return void |
|
| 197 | - * @throws RuntimeException |
|
| 198 | - */ |
|
| 199 | - public function generateError($error_response = '', $show_errors = false) |
|
| 200 | - { |
|
| 201 | - throw new RuntimeException( |
|
| 202 | - sprintf( |
|
| 203 | - esc_html__( |
|
| 204 | - 'We\'re sorry but an attempt to verify the form\'s reCAPTCHA has failed. %1$s %2$s Please try again.', |
|
| 205 | - 'event_espresso' |
|
| 206 | - ), |
|
| 207 | - '<br />', |
|
| 208 | - $show_errors || current_user_can('manage_options') ? $error_response : '' |
|
| 209 | - ) |
|
| 210 | - ); |
|
| 211 | - } |
|
| 193 | + /** |
|
| 194 | + * @param string $error_response |
|
| 195 | + * @param bool $show_errors |
|
| 196 | + * @return void |
|
| 197 | + * @throws RuntimeException |
|
| 198 | + */ |
|
| 199 | + public function generateError($error_response = '', $show_errors = false) |
|
| 200 | + { |
|
| 201 | + throw new RuntimeException( |
|
| 202 | + sprintf( |
|
| 203 | + esc_html__( |
|
| 204 | + 'We\'re sorry but an attempt to verify the form\'s reCAPTCHA has failed. %1$s %2$s Please try again.', |
|
| 205 | + 'event_espresso' |
|
| 206 | + ), |
|
| 207 | + '<br />', |
|
| 208 | + $show_errors || current_user_can('manage_options') ? $error_response : '' |
|
| 209 | + ) |
|
| 210 | + ); |
|
| 211 | + } |
|
| 212 | 212 | |
| 213 | 213 | |
| 214 | - /** |
|
| 215 | - * @param string $error_code |
|
| 216 | - * @return string |
|
| 217 | - */ |
|
| 218 | - public function getErrorCode(&$error_code) |
|
| 219 | - { |
|
| 220 | - $error_codes = array( |
|
| 221 | - 'missing-input-secret' => 'The secret parameter is missing.', |
|
| 222 | - 'invalid-input-secret' => 'The secret parameter is invalid or malformed.', |
|
| 223 | - 'missing-input-response' => 'The response parameter is missing.', |
|
| 224 | - 'invalid-input-response' => 'The response parameter is invalid or malformed.', |
|
| 225 | - 'bad-request' => 'The request is invalid or malformed.', |
|
| 226 | - 'timeout-or-duplicate' => 'The request took too long to be sent or was a duplicate of a previous request.', |
|
| 227 | - ); |
|
| 228 | - return isset($error_codes[ $error_code ]) ? $error_codes[ $error_code ] : ''; |
|
| 229 | - } |
|
| 214 | + /** |
|
| 215 | + * @param string $error_code |
|
| 216 | + * @return string |
|
| 217 | + */ |
|
| 218 | + public function getErrorCode(&$error_code) |
|
| 219 | + { |
|
| 220 | + $error_codes = array( |
|
| 221 | + 'missing-input-secret' => 'The secret parameter is missing.', |
|
| 222 | + 'invalid-input-secret' => 'The secret parameter is invalid or malformed.', |
|
| 223 | + 'missing-input-response' => 'The response parameter is missing.', |
|
| 224 | + 'invalid-input-response' => 'The response parameter is invalid or malformed.', |
|
| 225 | + 'bad-request' => 'The request is invalid or malformed.', |
|
| 226 | + 'timeout-or-duplicate' => 'The request took too long to be sent or was a duplicate of a previous request.', |
|
| 227 | + ); |
|
| 228 | + return isset($error_codes[ $error_code ]) ? $error_codes[ $error_code ] : ''; |
|
| 229 | + } |
|
| 230 | 230 | |
| 231 | 231 | |
| 232 | - /** |
|
| 233 | - * @return array |
|
| 234 | - * @throws InvalidInterfaceException |
|
| 235 | - * @throws InvalidDataTypeException |
|
| 236 | - * @throws InvalidArgumentException |
|
| 237 | - */ |
|
| 238 | - public function getLocalizedVars() |
|
| 239 | - { |
|
| 240 | - return (array) apply_filters( |
|
| 241 | - 'FHEE__EventEspresso_caffeinated_modules_recaptcha_invisible_InvisibleRecaptcha__getLocalizedVars__localized_vars', |
|
| 242 | - array( |
|
| 243 | - 'siteKey' => $this->config->recaptcha_publickey, |
|
| 244 | - 'recaptcha_passed' => $this->recaptchaPassed(), |
|
| 245 | - 'wp_debug' => WP_DEBUG, |
|
| 246 | - 'disable_submit' => defined('EE_EVENT_QUEUE_BASE_URL'), |
|
| 247 | - 'failed_message' => wp_strip_all_tags( |
|
| 248 | - __( |
|
| 249 | - 'We\'re sorry but an attempt to verify the form\'s reCAPTCHA has failed. Please try again.', |
|
| 250 | - 'event_espresso' |
|
| 251 | - ) |
|
| 252 | - ) |
|
| 253 | - ) |
|
| 254 | - ); |
|
| 255 | - } |
|
| 232 | + /** |
|
| 233 | + * @return array |
|
| 234 | + * @throws InvalidInterfaceException |
|
| 235 | + * @throws InvalidDataTypeException |
|
| 236 | + * @throws InvalidArgumentException |
|
| 237 | + */ |
|
| 238 | + public function getLocalizedVars() |
|
| 239 | + { |
|
| 240 | + return (array) apply_filters( |
|
| 241 | + 'FHEE__EventEspresso_caffeinated_modules_recaptcha_invisible_InvisibleRecaptcha__getLocalizedVars__localized_vars', |
|
| 242 | + array( |
|
| 243 | + 'siteKey' => $this->config->recaptcha_publickey, |
|
| 244 | + 'recaptcha_passed' => $this->recaptchaPassed(), |
|
| 245 | + 'wp_debug' => WP_DEBUG, |
|
| 246 | + 'disable_submit' => defined('EE_EVENT_QUEUE_BASE_URL'), |
|
| 247 | + 'failed_message' => wp_strip_all_tags( |
|
| 248 | + __( |
|
| 249 | + 'We\'re sorry but an attempt to verify the form\'s reCAPTCHA has failed. Please try again.', |
|
| 250 | + 'event_espresso' |
|
| 251 | + ) |
|
| 252 | + ) |
|
| 253 | + ) |
|
| 254 | + ); |
|
| 255 | + } |
|
| 256 | 256 | |
| 257 | 257 | |
| 258 | - /** |
|
| 259 | - * @return boolean |
|
| 260 | - * @throws InvalidInterfaceException |
|
| 261 | - * @throws InvalidDataTypeException |
|
| 262 | - * @throws InvalidArgumentException |
|
| 263 | - */ |
|
| 264 | - public function recaptchaPassed() |
|
| 265 | - { |
|
| 266 | - if ($this->recaptcha_passed !== null) { |
|
| 267 | - return $this->recaptcha_passed; |
|
| 268 | - } |
|
| 269 | - // logged in means you have already passed a turing test of sorts |
|
| 270 | - if ($this->useInvisibleRecaptcha() === false || is_user_logged_in()) { |
|
| 271 | - $this->recaptcha_passed = true; |
|
| 272 | - return $this->recaptcha_passed; |
|
| 273 | - } |
|
| 274 | - // was test already passed? |
|
| 275 | - $this->recaptcha_passed = filter_var( |
|
| 276 | - $this->session->get_session_data( |
|
| 277 | - InvisibleRecaptcha::SESSION_DATA_KEY_RECAPTCHA_PASSED |
|
| 278 | - ), |
|
| 279 | - FILTER_VALIDATE_BOOLEAN |
|
| 280 | - ); |
|
| 281 | - return $this->recaptcha_passed; |
|
| 282 | - } |
|
| 258 | + /** |
|
| 259 | + * @return boolean |
|
| 260 | + * @throws InvalidInterfaceException |
|
| 261 | + * @throws InvalidDataTypeException |
|
| 262 | + * @throws InvalidArgumentException |
|
| 263 | + */ |
|
| 264 | + public function recaptchaPassed() |
|
| 265 | + { |
|
| 266 | + if ($this->recaptcha_passed !== null) { |
|
| 267 | + return $this->recaptcha_passed; |
|
| 268 | + } |
|
| 269 | + // logged in means you have already passed a turing test of sorts |
|
| 270 | + if ($this->useInvisibleRecaptcha() === false || is_user_logged_in()) { |
|
| 271 | + $this->recaptcha_passed = true; |
|
| 272 | + return $this->recaptcha_passed; |
|
| 273 | + } |
|
| 274 | + // was test already passed? |
|
| 275 | + $this->recaptcha_passed = filter_var( |
|
| 276 | + $this->session->get_session_data( |
|
| 277 | + InvisibleRecaptcha::SESSION_DATA_KEY_RECAPTCHA_PASSED |
|
| 278 | + ), |
|
| 279 | + FILTER_VALIDATE_BOOLEAN |
|
| 280 | + ); |
|
| 281 | + return $this->recaptcha_passed; |
|
| 282 | + } |
|
| 283 | 283 | |
| 284 | 284 | |
| 285 | - /** |
|
| 286 | - * @throws InvalidArgumentException |
|
| 287 | - * @throws InvalidDataTypeException |
|
| 288 | - * @throws InvalidInterfaceException |
|
| 289 | - */ |
|
| 290 | - public function setSessionData() |
|
| 291 | - { |
|
| 292 | - $this->session->set_session_data( |
|
| 293 | - array(InvisibleRecaptcha::SESSION_DATA_KEY_RECAPTCHA_PASSED => true) |
|
| 294 | - ); |
|
| 295 | - } |
|
| 285 | + /** |
|
| 286 | + * @throws InvalidArgumentException |
|
| 287 | + * @throws InvalidDataTypeException |
|
| 288 | + * @throws InvalidInterfaceException |
|
| 289 | + */ |
|
| 290 | + public function setSessionData() |
|
| 291 | + { |
|
| 292 | + $this->session->set_session_data( |
|
| 293 | + array(InvisibleRecaptcha::SESSION_DATA_KEY_RECAPTCHA_PASSED => true) |
|
| 294 | + ); |
|
| 295 | + } |
|
| 296 | 296 | } |
@@ -29,360 +29,360 @@ |
||
| 29 | 29 | class EED_Batch extends EED_Module |
| 30 | 30 | { |
| 31 | 31 | |
| 32 | - /** |
|
| 33 | - * Possibly value for $_REQUEST[ 'batch' ]. Indicates to run a job that |
|
| 34 | - * processes data only |
|
| 35 | - */ |
|
| 36 | - const batch_job = 'job'; |
|
| 37 | - /** |
|
| 38 | - * Possibly value for $_REQUEST[ 'batch' ]. Indicates to run a job that |
|
| 39 | - * produces a file for download |
|
| 40 | - */ |
|
| 41 | - const batch_file_job = 'file'; |
|
| 42 | - /** |
|
| 43 | - * Possibly value for $_REQUEST[ 'batch' ]. Indicates this request is NOT |
|
| 44 | - * for a batch job. It's the same as not providing the $_REQUEST[ 'batch' ] |
|
| 45 | - * at all |
|
| 46 | - */ |
|
| 47 | - const batch_not_job = 'none'; |
|
| 32 | + /** |
|
| 33 | + * Possibly value for $_REQUEST[ 'batch' ]. Indicates to run a job that |
|
| 34 | + * processes data only |
|
| 35 | + */ |
|
| 36 | + const batch_job = 'job'; |
|
| 37 | + /** |
|
| 38 | + * Possibly value for $_REQUEST[ 'batch' ]. Indicates to run a job that |
|
| 39 | + * produces a file for download |
|
| 40 | + */ |
|
| 41 | + const batch_file_job = 'file'; |
|
| 42 | + /** |
|
| 43 | + * Possibly value for $_REQUEST[ 'batch' ]. Indicates this request is NOT |
|
| 44 | + * for a batch job. It's the same as not providing the $_REQUEST[ 'batch' ] |
|
| 45 | + * at all |
|
| 46 | + */ |
|
| 47 | + const batch_not_job = 'none'; |
|
| 48 | 48 | |
| 49 | - /** |
|
| 50 | - * |
|
| 51 | - * @var string 'file', or 'job', or false to indicate its not a batch request at all |
|
| 52 | - */ |
|
| 53 | - protected $_batch_request_type = null; |
|
| 49 | + /** |
|
| 50 | + * |
|
| 51 | + * @var string 'file', or 'job', or false to indicate its not a batch request at all |
|
| 52 | + */ |
|
| 53 | + protected $_batch_request_type = null; |
|
| 54 | 54 | |
| 55 | - /** |
|
| 56 | - * Because we want to use the response in both the localized JS and in the body |
|
| 57 | - * we need to make this response available between method calls |
|
| 58 | - * |
|
| 59 | - * @var \EventEspressoBatchRequest\Helpers\JobStepResponse |
|
| 60 | - */ |
|
| 61 | - protected $_job_step_response = null; |
|
| 55 | + /** |
|
| 56 | + * Because we want to use the response in both the localized JS and in the body |
|
| 57 | + * we need to make this response available between method calls |
|
| 58 | + * |
|
| 59 | + * @var \EventEspressoBatchRequest\Helpers\JobStepResponse |
|
| 60 | + */ |
|
| 61 | + protected $_job_step_response = null; |
|
| 62 | 62 | |
| 63 | - /** |
|
| 64 | - * @var LoaderInterface |
|
| 65 | - */ |
|
| 66 | - protected $loader; |
|
| 63 | + /** |
|
| 64 | + * @var LoaderInterface |
|
| 65 | + */ |
|
| 66 | + protected $loader; |
|
| 67 | 67 | |
| 68 | - /** |
|
| 69 | - * Gets the batch instance |
|
| 70 | - * |
|
| 71 | - * @return EED_Batch |
|
| 72 | - */ |
|
| 73 | - public static function instance() |
|
| 74 | - { |
|
| 75 | - return self::get_instance(); |
|
| 76 | - } |
|
| 68 | + /** |
|
| 69 | + * Gets the batch instance |
|
| 70 | + * |
|
| 71 | + * @return EED_Batch |
|
| 72 | + */ |
|
| 73 | + public static function instance() |
|
| 74 | + { |
|
| 75 | + return self::get_instance(); |
|
| 76 | + } |
|
| 77 | 77 | |
| 78 | - /** |
|
| 79 | - * Sets hooks to enable batch jobs on the frontend. Disabled by default |
|
| 80 | - * because it's an attack vector and there are currently no implementations |
|
| 81 | - */ |
|
| 82 | - public static function set_hooks() |
|
| 83 | - { |
|
| 84 | - // because this is a possibel attack vector, let's have this disabled until |
|
| 85 | - // we at least have a real use for it on the frontend |
|
| 86 | - if (apply_filters('FHEE__EED_Batch__set_hooks__enable_frontend_batch', false)) { |
|
| 87 | - add_action('wp_enqueue_scripts', array(self::instance(), 'enqueue_scripts')); |
|
| 88 | - add_filter('template_include', array(self::instance(), 'override_template'), 99); |
|
| 89 | - } |
|
| 90 | - } |
|
| 78 | + /** |
|
| 79 | + * Sets hooks to enable batch jobs on the frontend. Disabled by default |
|
| 80 | + * because it's an attack vector and there are currently no implementations |
|
| 81 | + */ |
|
| 82 | + public static function set_hooks() |
|
| 83 | + { |
|
| 84 | + // because this is a possibel attack vector, let's have this disabled until |
|
| 85 | + // we at least have a real use for it on the frontend |
|
| 86 | + if (apply_filters('FHEE__EED_Batch__set_hooks__enable_frontend_batch', false)) { |
|
| 87 | + add_action('wp_enqueue_scripts', array(self::instance(), 'enqueue_scripts')); |
|
| 88 | + add_filter('template_include', array(self::instance(), 'override_template'), 99); |
|
| 89 | + } |
|
| 90 | + } |
|
| 91 | 91 | |
| 92 | - /** |
|
| 93 | - * Initializes some hooks for the admin in order to run batch jobs |
|
| 94 | - */ |
|
| 95 | - public static function set_hooks_admin() |
|
| 96 | - { |
|
| 97 | - add_action('admin_menu', array(self::instance(), 'register_admin_pages')); |
|
| 98 | - add_action('admin_enqueue_scripts', array(self::instance(), 'enqueue_scripts')); |
|
| 92 | + /** |
|
| 93 | + * Initializes some hooks for the admin in order to run batch jobs |
|
| 94 | + */ |
|
| 95 | + public static function set_hooks_admin() |
|
| 96 | + { |
|
| 97 | + add_action('admin_menu', array(self::instance(), 'register_admin_pages')); |
|
| 98 | + add_action('admin_enqueue_scripts', array(self::instance(), 'enqueue_scripts')); |
|
| 99 | 99 | |
| 100 | - // ajax |
|
| 101 | - add_action('wp_ajax_espresso_batch_continue', array(self::instance(), 'batch_continue')); |
|
| 102 | - add_action('wp_ajax_espresso_batch_cleanup', array(self::instance(), 'batch_cleanup')); |
|
| 103 | - add_action('wp_ajax_nopriv_espresso_batch_continue', array(self::instance(), 'batch_continue')); |
|
| 104 | - add_action('wp_ajax_nopriv_espresso_batch_cleanup', array(self::instance(), 'batch_cleanup')); |
|
| 105 | - } |
|
| 100 | + // ajax |
|
| 101 | + add_action('wp_ajax_espresso_batch_continue', array(self::instance(), 'batch_continue')); |
|
| 102 | + add_action('wp_ajax_espresso_batch_cleanup', array(self::instance(), 'batch_cleanup')); |
|
| 103 | + add_action('wp_ajax_nopriv_espresso_batch_continue', array(self::instance(), 'batch_continue')); |
|
| 104 | + add_action('wp_ajax_nopriv_espresso_batch_cleanup', array(self::instance(), 'batch_cleanup')); |
|
| 105 | + } |
|
| 106 | 106 | |
| 107 | - /** |
|
| 108 | - * @since 4.9.80.p |
|
| 109 | - * @return LoaderInterface |
|
| 110 | - * @throws InvalidArgumentException |
|
| 111 | - * @throws InvalidDataTypeException |
|
| 112 | - * @throws InvalidInterfaceException |
|
| 113 | - */ |
|
| 114 | - protected function getLoader() |
|
| 115 | - { |
|
| 116 | - if (!$this->loader instanceof LoaderInterface) { |
|
| 117 | - $this->loader = LoaderFactory::getLoader(); |
|
| 118 | - } |
|
| 119 | - return $this->loader; |
|
| 120 | - } |
|
| 107 | + /** |
|
| 108 | + * @since 4.9.80.p |
|
| 109 | + * @return LoaderInterface |
|
| 110 | + * @throws InvalidArgumentException |
|
| 111 | + * @throws InvalidDataTypeException |
|
| 112 | + * @throws InvalidInterfaceException |
|
| 113 | + */ |
|
| 114 | + protected function getLoader() |
|
| 115 | + { |
|
| 116 | + if (!$this->loader instanceof LoaderInterface) { |
|
| 117 | + $this->loader = LoaderFactory::getLoader(); |
|
| 118 | + } |
|
| 119 | + return $this->loader; |
|
| 120 | + } |
|
| 121 | 121 | |
| 122 | - /** |
|
| 123 | - * Enqueues batch scripts on the frontend or admin, and creates a job |
|
| 124 | - */ |
|
| 125 | - public function enqueue_scripts() |
|
| 126 | - { |
|
| 127 | - if (isset($_REQUEST['espresso_batch']) |
|
| 128 | - || |
|
| 129 | - ( |
|
| 130 | - isset($_REQUEST['page']) |
|
| 131 | - && $_REQUEST['page'] == 'espresso_batch' |
|
| 132 | - ) |
|
| 133 | - ) { |
|
| 134 | - if (! isset($_REQUEST['default_nonce']) || ! wp_verify_nonce($_REQUEST['default_nonce'], 'default_nonce')) { |
|
| 135 | - wp_die(esc_html__('The link you clicked to start the batch job has expired. Please go back and refresh the previous page.', 'event_espresso')); |
|
| 136 | - } |
|
| 137 | - switch ($this->batch_request_type()) { |
|
| 138 | - case self::batch_job: |
|
| 139 | - $this->enqueue_scripts_styles_batch_create(); |
|
| 140 | - break; |
|
| 141 | - case self::batch_file_job: |
|
| 142 | - $this->enqueue_scripts_styles_batch_file_create(); |
|
| 143 | - break; |
|
| 144 | - } |
|
| 145 | - } |
|
| 146 | - } |
|
| 122 | + /** |
|
| 123 | + * Enqueues batch scripts on the frontend or admin, and creates a job |
|
| 124 | + */ |
|
| 125 | + public function enqueue_scripts() |
|
| 126 | + { |
|
| 127 | + if (isset($_REQUEST['espresso_batch']) |
|
| 128 | + || |
|
| 129 | + ( |
|
| 130 | + isset($_REQUEST['page']) |
|
| 131 | + && $_REQUEST['page'] == 'espresso_batch' |
|
| 132 | + ) |
|
| 133 | + ) { |
|
| 134 | + if (! isset($_REQUEST['default_nonce']) || ! wp_verify_nonce($_REQUEST['default_nonce'], 'default_nonce')) { |
|
| 135 | + wp_die(esc_html__('The link you clicked to start the batch job has expired. Please go back and refresh the previous page.', 'event_espresso')); |
|
| 136 | + } |
|
| 137 | + switch ($this->batch_request_type()) { |
|
| 138 | + case self::batch_job: |
|
| 139 | + $this->enqueue_scripts_styles_batch_create(); |
|
| 140 | + break; |
|
| 141 | + case self::batch_file_job: |
|
| 142 | + $this->enqueue_scripts_styles_batch_file_create(); |
|
| 143 | + break; |
|
| 144 | + } |
|
| 145 | + } |
|
| 146 | + } |
|
| 147 | 147 | |
| 148 | - /** |
|
| 149 | - * Create a batch job, enqueues a script to run it, and localizes some data for it |
|
| 150 | - */ |
|
| 151 | - public function enqueue_scripts_styles_batch_create() |
|
| 152 | - { |
|
| 153 | - $job_response = $this->_enqueue_batch_job_scripts_and_styles_and_start_job(); |
|
| 154 | - wp_enqueue_script( |
|
| 155 | - 'batch_runner_init', |
|
| 156 | - BATCH_URL . 'assets/batch_runner_init.js', |
|
| 157 | - array('batch_runner'), |
|
| 158 | - EVENT_ESPRESSO_VERSION, |
|
| 159 | - true |
|
| 160 | - ); |
|
| 161 | - wp_localize_script('batch_runner_init', 'ee_job_response', $job_response->to_array()); |
|
| 162 | - wp_localize_script( |
|
| 163 | - 'batch_runner_init', |
|
| 164 | - 'ee_job_i18n', |
|
| 165 | - array( |
|
| 166 | - 'return_url' => $_REQUEST['return_url'], |
|
| 167 | - ) |
|
| 168 | - ); |
|
| 169 | - } |
|
| 148 | + /** |
|
| 149 | + * Create a batch job, enqueues a script to run it, and localizes some data for it |
|
| 150 | + */ |
|
| 151 | + public function enqueue_scripts_styles_batch_create() |
|
| 152 | + { |
|
| 153 | + $job_response = $this->_enqueue_batch_job_scripts_and_styles_and_start_job(); |
|
| 154 | + wp_enqueue_script( |
|
| 155 | + 'batch_runner_init', |
|
| 156 | + BATCH_URL . 'assets/batch_runner_init.js', |
|
| 157 | + array('batch_runner'), |
|
| 158 | + EVENT_ESPRESSO_VERSION, |
|
| 159 | + true |
|
| 160 | + ); |
|
| 161 | + wp_localize_script('batch_runner_init', 'ee_job_response', $job_response->to_array()); |
|
| 162 | + wp_localize_script( |
|
| 163 | + 'batch_runner_init', |
|
| 164 | + 'ee_job_i18n', |
|
| 165 | + array( |
|
| 166 | + 'return_url' => $_REQUEST['return_url'], |
|
| 167 | + ) |
|
| 168 | + ); |
|
| 169 | + } |
|
| 170 | 170 | |
| 171 | - /** |
|
| 172 | - * Creates a batch job which will download a file, enqueues a script to run the job, and localizes some data for it |
|
| 173 | - */ |
|
| 174 | - public function enqueue_scripts_styles_batch_file_create() |
|
| 175 | - { |
|
| 176 | - // creates a job based on the request variable |
|
| 177 | - $job_response = $this->_enqueue_batch_job_scripts_and_styles_and_start_job(); |
|
| 178 | - wp_enqueue_script( |
|
| 179 | - 'batch_file_runner_init', |
|
| 180 | - BATCH_URL . 'assets/batch_file_runner_init.js', |
|
| 181 | - array('batch_runner'), |
|
| 182 | - EVENT_ESPRESSO_VERSION, |
|
| 183 | - true |
|
| 184 | - ); |
|
| 185 | - wp_localize_script('batch_file_runner_init', 'ee_job_response', $job_response->to_array()); |
|
| 186 | - wp_localize_script( |
|
| 187 | - 'batch_file_runner_init', |
|
| 188 | - 'ee_job_i18n', |
|
| 189 | - array( |
|
| 190 | - 'download_and_redirecting' => sprintf( |
|
| 191 | - wp_strip_all_tags( |
|
| 192 | - __('File Generation complete. Downloading, and %1$sredirecting%2$s...', 'event_espresso') |
|
| 193 | - ), |
|
| 194 | - '<a href="' . $_REQUEST['return_url'] . '">', |
|
| 195 | - '</a>' |
|
| 196 | - ), |
|
| 197 | - 'return_url' => $_REQUEST['return_url'], |
|
| 198 | - ) |
|
| 199 | - ); |
|
| 200 | - } |
|
| 171 | + /** |
|
| 172 | + * Creates a batch job which will download a file, enqueues a script to run the job, and localizes some data for it |
|
| 173 | + */ |
|
| 174 | + public function enqueue_scripts_styles_batch_file_create() |
|
| 175 | + { |
|
| 176 | + // creates a job based on the request variable |
|
| 177 | + $job_response = $this->_enqueue_batch_job_scripts_and_styles_and_start_job(); |
|
| 178 | + wp_enqueue_script( |
|
| 179 | + 'batch_file_runner_init', |
|
| 180 | + BATCH_URL . 'assets/batch_file_runner_init.js', |
|
| 181 | + array('batch_runner'), |
|
| 182 | + EVENT_ESPRESSO_VERSION, |
|
| 183 | + true |
|
| 184 | + ); |
|
| 185 | + wp_localize_script('batch_file_runner_init', 'ee_job_response', $job_response->to_array()); |
|
| 186 | + wp_localize_script( |
|
| 187 | + 'batch_file_runner_init', |
|
| 188 | + 'ee_job_i18n', |
|
| 189 | + array( |
|
| 190 | + 'download_and_redirecting' => sprintf( |
|
| 191 | + wp_strip_all_tags( |
|
| 192 | + __('File Generation complete. Downloading, and %1$sredirecting%2$s...', 'event_espresso') |
|
| 193 | + ), |
|
| 194 | + '<a href="' . $_REQUEST['return_url'] . '">', |
|
| 195 | + '</a>' |
|
| 196 | + ), |
|
| 197 | + 'return_url' => $_REQUEST['return_url'], |
|
| 198 | + ) |
|
| 199 | + ); |
|
| 200 | + } |
|
| 201 | 201 | |
| 202 | - /** |
|
| 203 | - * Enqueues scripts and styles common to any batch job, and creates |
|
| 204 | - * a job from the request data, and stores the response in the |
|
| 205 | - * $this->_job_step_response property |
|
| 206 | - * |
|
| 207 | - * @return \EventEspressoBatchRequest\Helpers\JobStepResponse |
|
| 208 | - */ |
|
| 209 | - protected function _enqueue_batch_job_scripts_and_styles_and_start_job() |
|
| 210 | - { |
|
| 211 | - // just copy the bits of EE admin's eei18n that we need in the JS |
|
| 212 | - EE_Registry::$i18n_js_strings['batchJobError'] = esc_html__( |
|
| 213 | - 'An error occurred and the job has been stopped. Please refresh the page to try again.', |
|
| 214 | - 'event_espresso' |
|
| 215 | - ); |
|
| 216 | - wp_register_script( |
|
| 217 | - 'progress_bar', |
|
| 218 | - EE_PLUGIN_DIR_URL . 'core/libraries/batch/Assets/progress_bar.js', |
|
| 219 | - array('jquery'), |
|
| 220 | - EVENT_ESPRESSO_VERSION, |
|
| 221 | - true |
|
| 222 | - ); |
|
| 223 | - wp_enqueue_style( |
|
| 224 | - 'progress_bar', |
|
| 225 | - EE_PLUGIN_DIR_URL . 'core/libraries/batch/Assets/progress_bar.css', |
|
| 226 | - array(), |
|
| 227 | - EVENT_ESPRESSO_VERSION |
|
| 228 | - ); |
|
| 229 | - wp_enqueue_script( |
|
| 230 | - 'batch_runner', |
|
| 231 | - EE_PLUGIN_DIR_URL . 'core/libraries/batch/Assets/batch_runner.js', |
|
| 232 | - array('progress_bar', CoreAssetManager::JS_HANDLE_CORE), |
|
| 233 | - EVENT_ESPRESSO_VERSION, |
|
| 234 | - true |
|
| 235 | - ); |
|
| 236 | - $job_handler_classname = stripslashes($_GET['job_handler']); |
|
| 237 | - $request_data = array_diff_key( |
|
| 238 | - $_REQUEST, |
|
| 239 | - array_flip(array('action', 'page', 'ee', 'batch')) |
|
| 240 | - ); |
|
| 241 | - $batch_runner = $this->getLoader()->getShared('EventEspressoBatchRequest\BatchRequestProcessor'); |
|
| 242 | - // eg 'EventEspressoBatchRequest\JobHandlers\RegistrationsReport' |
|
| 243 | - $job_response = $batch_runner->create_job($job_handler_classname, $request_data); |
|
| 244 | - // remember the response for later. We need it to display the page body |
|
| 245 | - $this->_job_step_response = $job_response; |
|
| 246 | - return $job_response; |
|
| 247 | - } |
|
| 202 | + /** |
|
| 203 | + * Enqueues scripts and styles common to any batch job, and creates |
|
| 204 | + * a job from the request data, and stores the response in the |
|
| 205 | + * $this->_job_step_response property |
|
| 206 | + * |
|
| 207 | + * @return \EventEspressoBatchRequest\Helpers\JobStepResponse |
|
| 208 | + */ |
|
| 209 | + protected function _enqueue_batch_job_scripts_and_styles_and_start_job() |
|
| 210 | + { |
|
| 211 | + // just copy the bits of EE admin's eei18n that we need in the JS |
|
| 212 | + EE_Registry::$i18n_js_strings['batchJobError'] = esc_html__( |
|
| 213 | + 'An error occurred and the job has been stopped. Please refresh the page to try again.', |
|
| 214 | + 'event_espresso' |
|
| 215 | + ); |
|
| 216 | + wp_register_script( |
|
| 217 | + 'progress_bar', |
|
| 218 | + EE_PLUGIN_DIR_URL . 'core/libraries/batch/Assets/progress_bar.js', |
|
| 219 | + array('jquery'), |
|
| 220 | + EVENT_ESPRESSO_VERSION, |
|
| 221 | + true |
|
| 222 | + ); |
|
| 223 | + wp_enqueue_style( |
|
| 224 | + 'progress_bar', |
|
| 225 | + EE_PLUGIN_DIR_URL . 'core/libraries/batch/Assets/progress_bar.css', |
|
| 226 | + array(), |
|
| 227 | + EVENT_ESPRESSO_VERSION |
|
| 228 | + ); |
|
| 229 | + wp_enqueue_script( |
|
| 230 | + 'batch_runner', |
|
| 231 | + EE_PLUGIN_DIR_URL . 'core/libraries/batch/Assets/batch_runner.js', |
|
| 232 | + array('progress_bar', CoreAssetManager::JS_HANDLE_CORE), |
|
| 233 | + EVENT_ESPRESSO_VERSION, |
|
| 234 | + true |
|
| 235 | + ); |
|
| 236 | + $job_handler_classname = stripslashes($_GET['job_handler']); |
|
| 237 | + $request_data = array_diff_key( |
|
| 238 | + $_REQUEST, |
|
| 239 | + array_flip(array('action', 'page', 'ee', 'batch')) |
|
| 240 | + ); |
|
| 241 | + $batch_runner = $this->getLoader()->getShared('EventEspressoBatchRequest\BatchRequestProcessor'); |
|
| 242 | + // eg 'EventEspressoBatchRequest\JobHandlers\RegistrationsReport' |
|
| 243 | + $job_response = $batch_runner->create_job($job_handler_classname, $request_data); |
|
| 244 | + // remember the response for later. We need it to display the page body |
|
| 245 | + $this->_job_step_response = $job_response; |
|
| 246 | + return $job_response; |
|
| 247 | + } |
|
| 248 | 248 | |
| 249 | - /** |
|
| 250 | - * If we are doing a frontend batch job, this makes it so WP shows our template's HTML |
|
| 251 | - * |
|
| 252 | - * @param string $template |
|
| 253 | - * @return string |
|
| 254 | - */ |
|
| 255 | - public function override_template($template) |
|
| 256 | - { |
|
| 257 | - if (isset($_REQUEST['espresso_batch']) && isset($_REQUEST['batch'])) { |
|
| 258 | - return EE_MODULES . 'batch' . DS . 'templates' . DS . 'batch_frontend_wrapper.template.html'; |
|
| 259 | - } |
|
| 260 | - return $template; |
|
| 261 | - } |
|
| 249 | + /** |
|
| 250 | + * If we are doing a frontend batch job, this makes it so WP shows our template's HTML |
|
| 251 | + * |
|
| 252 | + * @param string $template |
|
| 253 | + * @return string |
|
| 254 | + */ |
|
| 255 | + public function override_template($template) |
|
| 256 | + { |
|
| 257 | + if (isset($_REQUEST['espresso_batch']) && isset($_REQUEST['batch'])) { |
|
| 258 | + return EE_MODULES . 'batch' . DS . 'templates' . DS . 'batch_frontend_wrapper.template.html'; |
|
| 259 | + } |
|
| 260 | + return $template; |
|
| 261 | + } |
|
| 262 | 262 | |
| 263 | - /** |
|
| 264 | - * Adds an admin page which doesn't appear in the admin menu |
|
| 265 | - */ |
|
| 266 | - public function register_admin_pages() |
|
| 267 | - { |
|
| 268 | - add_submenu_page( |
|
| 269 | - '', // parent slug. we don't want this to actually appear in the menu |
|
| 270 | - __('Batch Job', 'event_espresso'), // page title |
|
| 271 | - 'n/a', // menu title |
|
| 272 | - 'read', // we want this page to actually be accessible to anyone, |
|
| 273 | - 'espresso_batch', // menu slug |
|
| 274 | - array(self::instance(), 'show_admin_page') |
|
| 275 | - ); |
|
| 276 | - } |
|
| 263 | + /** |
|
| 264 | + * Adds an admin page which doesn't appear in the admin menu |
|
| 265 | + */ |
|
| 266 | + public function register_admin_pages() |
|
| 267 | + { |
|
| 268 | + add_submenu_page( |
|
| 269 | + '', // parent slug. we don't want this to actually appear in the menu |
|
| 270 | + __('Batch Job', 'event_espresso'), // page title |
|
| 271 | + 'n/a', // menu title |
|
| 272 | + 'read', // we want this page to actually be accessible to anyone, |
|
| 273 | + 'espresso_batch', // menu slug |
|
| 274 | + array(self::instance(), 'show_admin_page') |
|
| 275 | + ); |
|
| 276 | + } |
|
| 277 | 277 | |
| 278 | - /** |
|
| 279 | - * Renders the admin page, after most of the work was already done during enqueuing scripts |
|
| 280 | - * of creating the job and localizing some data |
|
| 281 | - */ |
|
| 282 | - public function show_admin_page() |
|
| 283 | - { |
|
| 284 | - echo EEH_Template::locate_template( |
|
| 285 | - EE_MODULES . 'batch' . DS . 'templates' . DS . 'batch_wrapper.template.html', |
|
| 286 | - array('batch_request_type' => $this->batch_request_type()) |
|
| 287 | - ); |
|
| 288 | - } |
|
| 278 | + /** |
|
| 279 | + * Renders the admin page, after most of the work was already done during enqueuing scripts |
|
| 280 | + * of creating the job and localizing some data |
|
| 281 | + */ |
|
| 282 | + public function show_admin_page() |
|
| 283 | + { |
|
| 284 | + echo EEH_Template::locate_template( |
|
| 285 | + EE_MODULES . 'batch' . DS . 'templates' . DS . 'batch_wrapper.template.html', |
|
| 286 | + array('batch_request_type' => $this->batch_request_type()) |
|
| 287 | + ); |
|
| 288 | + } |
|
| 289 | 289 | |
| 290 | - /** |
|
| 291 | - * Receives ajax calls for continuing a job |
|
| 292 | - */ |
|
| 293 | - public function batch_continue() |
|
| 294 | - { |
|
| 295 | - $job_id = sanitize_text_field($_REQUEST['job_id']); |
|
| 296 | - $batch_runner = $this->getLoader()->getShared('EventEspressoBatchRequest\BatchRequestProcessor'); |
|
| 297 | - $response_obj = $batch_runner->continue_job($job_id); |
|
| 298 | - $this->_return_json($response_obj->to_array()); |
|
| 299 | - } |
|
| 290 | + /** |
|
| 291 | + * Receives ajax calls for continuing a job |
|
| 292 | + */ |
|
| 293 | + public function batch_continue() |
|
| 294 | + { |
|
| 295 | + $job_id = sanitize_text_field($_REQUEST['job_id']); |
|
| 296 | + $batch_runner = $this->getLoader()->getShared('EventEspressoBatchRequest\BatchRequestProcessor'); |
|
| 297 | + $response_obj = $batch_runner->continue_job($job_id); |
|
| 298 | + $this->_return_json($response_obj->to_array()); |
|
| 299 | + } |
|
| 300 | 300 | |
| 301 | - /** |
|
| 302 | - * Receives the ajax call to cleanup a job |
|
| 303 | - * |
|
| 304 | - * @return type |
|
| 305 | - */ |
|
| 306 | - public function batch_cleanup() |
|
| 307 | - { |
|
| 308 | - $job_id = sanitize_text_field($_REQUEST['job_id']); |
|
| 309 | - $batch_runner = $this->getLoader()->getShared('EventEspressoBatchRequest\BatchRequestProcessor'); |
|
| 310 | - $response_obj = $batch_runner->cleanup_job($job_id); |
|
| 311 | - $this->_return_json($response_obj->to_array()); |
|
| 312 | - } |
|
| 301 | + /** |
|
| 302 | + * Receives the ajax call to cleanup a job |
|
| 303 | + * |
|
| 304 | + * @return type |
|
| 305 | + */ |
|
| 306 | + public function batch_cleanup() |
|
| 307 | + { |
|
| 308 | + $job_id = sanitize_text_field($_REQUEST['job_id']); |
|
| 309 | + $batch_runner = $this->getLoader()->getShared('EventEspressoBatchRequest\BatchRequestProcessor'); |
|
| 310 | + $response_obj = $batch_runner->cleanup_job($job_id); |
|
| 311 | + $this->_return_json($response_obj->to_array()); |
|
| 312 | + } |
|
| 313 | 313 | |
| 314 | 314 | |
| 315 | - /** |
|
| 316 | - * Returns a json response |
|
| 317 | - * |
|
| 318 | - * @param array $data The data we want to send echo via in the JSON response's "data" element |
|
| 319 | - * |
|
| 320 | - * The returned json object is created from an array in the following format: |
|
| 321 | - * array( |
|
| 322 | - * 'notices' => '', // - contains any EE_Error formatted notices |
|
| 323 | - * 'data' => array() //this can be any key/value pairs that a method returns for later json parsing by the js. |
|
| 324 | - * We're also going to include the template args with every package (so js can pick out any specific template |
|
| 325 | - * args that might be included in here) |
|
| 326 | - * 'isEEajax' => true,//indicates this is a response from EE |
|
| 327 | - * ) |
|
| 328 | - */ |
|
| 329 | - protected function _return_json($data) |
|
| 330 | - { |
|
| 331 | - $json = array( |
|
| 332 | - 'notices' => EE_Error::get_notices(), |
|
| 333 | - 'data' => $data, |
|
| 334 | - 'isEEajax' => true |
|
| 335 | - // special flag so any ajax.Success methods in js can identify this return package as a EEajax package. |
|
| 336 | - ); |
|
| 315 | + /** |
|
| 316 | + * Returns a json response |
|
| 317 | + * |
|
| 318 | + * @param array $data The data we want to send echo via in the JSON response's "data" element |
|
| 319 | + * |
|
| 320 | + * The returned json object is created from an array in the following format: |
|
| 321 | + * array( |
|
| 322 | + * 'notices' => '', // - contains any EE_Error formatted notices |
|
| 323 | + * 'data' => array() //this can be any key/value pairs that a method returns for later json parsing by the js. |
|
| 324 | + * We're also going to include the template args with every package (so js can pick out any specific template |
|
| 325 | + * args that might be included in here) |
|
| 326 | + * 'isEEajax' => true,//indicates this is a response from EE |
|
| 327 | + * ) |
|
| 328 | + */ |
|
| 329 | + protected function _return_json($data) |
|
| 330 | + { |
|
| 331 | + $json = array( |
|
| 332 | + 'notices' => EE_Error::get_notices(), |
|
| 333 | + 'data' => $data, |
|
| 334 | + 'isEEajax' => true |
|
| 335 | + // special flag so any ajax.Success methods in js can identify this return package as a EEajax package. |
|
| 336 | + ); |
|
| 337 | 337 | |
| 338 | 338 | |
| 339 | - // make sure there are no php errors or headers_sent. Then we can set correct json header. |
|
| 340 | - if (null === error_get_last() || ! headers_sent()) { |
|
| 341 | - header('Content-Type: application/json; charset=UTF-8'); |
|
| 342 | - } |
|
| 343 | - echo wp_json_encode($json); |
|
| 344 | - exit(); |
|
| 345 | - } |
|
| 339 | + // make sure there are no php errors or headers_sent. Then we can set correct json header. |
|
| 340 | + if (null === error_get_last() || ! headers_sent()) { |
|
| 341 | + header('Content-Type: application/json; charset=UTF-8'); |
|
| 342 | + } |
|
| 343 | + echo wp_json_encode($json); |
|
| 344 | + exit(); |
|
| 345 | + } |
|
| 346 | 346 | |
| 347 | - /** |
|
| 348 | - * Gets the job step response which was done during the enqueuing of scripts |
|
| 349 | - * |
|
| 350 | - * @return \EventEspressoBatchRequest\Helpers\JobStepResponse |
|
| 351 | - */ |
|
| 352 | - public function job_step_response() |
|
| 353 | - { |
|
| 354 | - return $this->_job_step_response; |
|
| 355 | - } |
|
| 347 | + /** |
|
| 348 | + * Gets the job step response which was done during the enqueuing of scripts |
|
| 349 | + * |
|
| 350 | + * @return \EventEspressoBatchRequest\Helpers\JobStepResponse |
|
| 351 | + */ |
|
| 352 | + public function job_step_response() |
|
| 353 | + { |
|
| 354 | + return $this->_job_step_response; |
|
| 355 | + } |
|
| 356 | 356 | |
| 357 | - /** |
|
| 358 | - * Gets the batch request type indicated in the $_REQUEST |
|
| 359 | - * |
|
| 360 | - * @return string: EED_Batch::batch_job, EED_Batch::batch_file_job, EED_Batch::batch_not_job |
|
| 361 | - */ |
|
| 362 | - public function batch_request_type() |
|
| 363 | - { |
|
| 364 | - if ($this->_batch_request_type === null) { |
|
| 365 | - if (isset($_GET['batch'])) { |
|
| 366 | - if ($_GET['batch'] == self::batch_job) { |
|
| 367 | - $this->_batch_request_type = self::batch_job; |
|
| 368 | - } elseif ($_GET['batch'] == self::batch_file_job) { |
|
| 369 | - $this->_batch_request_type = self::batch_file_job; |
|
| 370 | - } |
|
| 371 | - } |
|
| 372 | - // if we didn't find that it was a batch request, indicate it wasn't |
|
| 373 | - if ($this->_batch_request_type === null) { |
|
| 374 | - $this->_batch_request_type = self::batch_not_job; |
|
| 375 | - } |
|
| 376 | - } |
|
| 377 | - return $this->_batch_request_type; |
|
| 378 | - } |
|
| 357 | + /** |
|
| 358 | + * Gets the batch request type indicated in the $_REQUEST |
|
| 359 | + * |
|
| 360 | + * @return string: EED_Batch::batch_job, EED_Batch::batch_file_job, EED_Batch::batch_not_job |
|
| 361 | + */ |
|
| 362 | + public function batch_request_type() |
|
| 363 | + { |
|
| 364 | + if ($this->_batch_request_type === null) { |
|
| 365 | + if (isset($_GET['batch'])) { |
|
| 366 | + if ($_GET['batch'] == self::batch_job) { |
|
| 367 | + $this->_batch_request_type = self::batch_job; |
|
| 368 | + } elseif ($_GET['batch'] == self::batch_file_job) { |
|
| 369 | + $this->_batch_request_type = self::batch_file_job; |
|
| 370 | + } |
|
| 371 | + } |
|
| 372 | + // if we didn't find that it was a batch request, indicate it wasn't |
|
| 373 | + if ($this->_batch_request_type === null) { |
|
| 374 | + $this->_batch_request_type = self::batch_not_job; |
|
| 375 | + } |
|
| 376 | + } |
|
| 377 | + return $this->_batch_request_type; |
|
| 378 | + } |
|
| 379 | 379 | |
| 380 | - /** |
|
| 381 | - * Unnecessary |
|
| 382 | - * |
|
| 383 | - * @param type $WP |
|
| 384 | - */ |
|
| 385 | - public function run($WP) |
|
| 386 | - { |
|
| 387 | - } |
|
| 380 | + /** |
|
| 381 | + * Unnecessary |
|
| 382 | + * |
|
| 383 | + * @param type $WP |
|
| 384 | + */ |
|
| 385 | + public function run($WP) |
|
| 386 | + { |
|
| 387 | + } |
|
| 388 | 388 | } |
@@ -113,7 +113,7 @@ discard block |
||
| 113 | 113 | */ |
| 114 | 114 | protected function getLoader() |
| 115 | 115 | { |
| 116 | - if (!$this->loader instanceof LoaderInterface) { |
|
| 116 | + if ( ! $this->loader instanceof LoaderInterface) { |
|
| 117 | 117 | $this->loader = LoaderFactory::getLoader(); |
| 118 | 118 | } |
| 119 | 119 | return $this->loader; |
@@ -131,7 +131,7 @@ discard block |
||
| 131 | 131 | && $_REQUEST['page'] == 'espresso_batch' |
| 132 | 132 | ) |
| 133 | 133 | ) { |
| 134 | - if (! isset($_REQUEST['default_nonce']) || ! wp_verify_nonce($_REQUEST['default_nonce'], 'default_nonce')) { |
|
| 134 | + if ( ! isset($_REQUEST['default_nonce']) || ! wp_verify_nonce($_REQUEST['default_nonce'], 'default_nonce')) { |
|
| 135 | 135 | wp_die(esc_html__('The link you clicked to start the batch job has expired. Please go back and refresh the previous page.', 'event_espresso')); |
| 136 | 136 | } |
| 137 | 137 | switch ($this->batch_request_type()) { |
@@ -153,7 +153,7 @@ discard block |
||
| 153 | 153 | $job_response = $this->_enqueue_batch_job_scripts_and_styles_and_start_job(); |
| 154 | 154 | wp_enqueue_script( |
| 155 | 155 | 'batch_runner_init', |
| 156 | - BATCH_URL . 'assets/batch_runner_init.js', |
|
| 156 | + BATCH_URL.'assets/batch_runner_init.js', |
|
| 157 | 157 | array('batch_runner'), |
| 158 | 158 | EVENT_ESPRESSO_VERSION, |
| 159 | 159 | true |
@@ -177,7 +177,7 @@ discard block |
||
| 177 | 177 | $job_response = $this->_enqueue_batch_job_scripts_and_styles_and_start_job(); |
| 178 | 178 | wp_enqueue_script( |
| 179 | 179 | 'batch_file_runner_init', |
| 180 | - BATCH_URL . 'assets/batch_file_runner_init.js', |
|
| 180 | + BATCH_URL.'assets/batch_file_runner_init.js', |
|
| 181 | 181 | array('batch_runner'), |
| 182 | 182 | EVENT_ESPRESSO_VERSION, |
| 183 | 183 | true |
@@ -191,7 +191,7 @@ discard block |
||
| 191 | 191 | wp_strip_all_tags( |
| 192 | 192 | __('File Generation complete. Downloading, and %1$sredirecting%2$s...', 'event_espresso') |
| 193 | 193 | ), |
| 194 | - '<a href="' . $_REQUEST['return_url'] . '">', |
|
| 194 | + '<a href="'.$_REQUEST['return_url'].'">', |
|
| 195 | 195 | '</a>' |
| 196 | 196 | ), |
| 197 | 197 | 'return_url' => $_REQUEST['return_url'], |
@@ -209,26 +209,26 @@ discard block |
||
| 209 | 209 | protected function _enqueue_batch_job_scripts_and_styles_and_start_job() |
| 210 | 210 | { |
| 211 | 211 | // just copy the bits of EE admin's eei18n that we need in the JS |
| 212 | - EE_Registry::$i18n_js_strings['batchJobError'] = esc_html__( |
|
| 212 | + EE_Registry::$i18n_js_strings['batchJobError'] = esc_html__( |
|
| 213 | 213 | 'An error occurred and the job has been stopped. Please refresh the page to try again.', |
| 214 | 214 | 'event_espresso' |
| 215 | 215 | ); |
| 216 | 216 | wp_register_script( |
| 217 | 217 | 'progress_bar', |
| 218 | - EE_PLUGIN_DIR_URL . 'core/libraries/batch/Assets/progress_bar.js', |
|
| 218 | + EE_PLUGIN_DIR_URL.'core/libraries/batch/Assets/progress_bar.js', |
|
| 219 | 219 | array('jquery'), |
| 220 | 220 | EVENT_ESPRESSO_VERSION, |
| 221 | 221 | true |
| 222 | 222 | ); |
| 223 | 223 | wp_enqueue_style( |
| 224 | 224 | 'progress_bar', |
| 225 | - EE_PLUGIN_DIR_URL . 'core/libraries/batch/Assets/progress_bar.css', |
|
| 225 | + EE_PLUGIN_DIR_URL.'core/libraries/batch/Assets/progress_bar.css', |
|
| 226 | 226 | array(), |
| 227 | 227 | EVENT_ESPRESSO_VERSION |
| 228 | 228 | ); |
| 229 | 229 | wp_enqueue_script( |
| 230 | 230 | 'batch_runner', |
| 231 | - EE_PLUGIN_DIR_URL . 'core/libraries/batch/Assets/batch_runner.js', |
|
| 231 | + EE_PLUGIN_DIR_URL.'core/libraries/batch/Assets/batch_runner.js', |
|
| 232 | 232 | array('progress_bar', CoreAssetManager::JS_HANDLE_CORE), |
| 233 | 233 | EVENT_ESPRESSO_VERSION, |
| 234 | 234 | true |
@@ -255,7 +255,7 @@ discard block |
||
| 255 | 255 | public function override_template($template) |
| 256 | 256 | { |
| 257 | 257 | if (isset($_REQUEST['espresso_batch']) && isset($_REQUEST['batch'])) { |
| 258 | - return EE_MODULES . 'batch' . DS . 'templates' . DS . 'batch_frontend_wrapper.template.html'; |
|
| 258 | + return EE_MODULES.'batch'.DS.'templates'.DS.'batch_frontend_wrapper.template.html'; |
|
| 259 | 259 | } |
| 260 | 260 | return $template; |
| 261 | 261 | } |
@@ -282,7 +282,7 @@ discard block |
||
| 282 | 282 | public function show_admin_page() |
| 283 | 283 | { |
| 284 | 284 | echo EEH_Template::locate_template( |
| 285 | - EE_MODULES . 'batch' . DS . 'templates' . DS . 'batch_wrapper.template.html', |
|
| 285 | + EE_MODULES.'batch'.DS.'templates'.DS.'batch_wrapper.template.html', |
|
| 286 | 286 | array('batch_request_type' => $this->batch_request_type()) |
| 287 | 287 | ); |
| 288 | 288 | } |