@@ -16,304 +16,304 @@ |
||
| 16 | 16 | class EED_Bot_Trap extends EED_Module |
| 17 | 17 | { |
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * @return EED_Bot_Trap|EED_Module |
|
| 21 | - */ |
|
| 22 | - public static function instance() |
|
| 23 | - { |
|
| 24 | - return parent::get_instance(__CLASS__); |
|
| 25 | - } |
|
| 19 | + /** |
|
| 20 | + * @return EED_Bot_Trap|EED_Module |
|
| 21 | + */ |
|
| 22 | + public static function instance() |
|
| 23 | + { |
|
| 24 | + return parent::get_instance(__CLASS__); |
|
| 25 | + } |
|
| 26 | 26 | |
| 27 | 27 | |
| 28 | - /** |
|
| 29 | - * set_hooks - for hooking into EE Core, other modules, etc |
|
| 30 | - * |
|
| 31 | - * @return void |
|
| 32 | - */ |
|
| 33 | - public static function set_hooks() |
|
| 34 | - { |
|
| 35 | - if (apply_filters('FHEE__EED_Bot_Trap__set_hooks__use_bot_trap', true) && |
|
| 36 | - EE_Registry::instance()->CFG->registration->use_bot_trap |
|
| 37 | - ) { |
|
| 38 | - EED_Bot_Trap::set_trap(); |
|
| 39 | - // redirect bots to bogus success page |
|
| 40 | - EE_Config::register_route( |
|
| 41 | - 'ticket_selection_received', |
|
| 42 | - 'EED_Bot_Trap', |
|
| 43 | - 'display_bot_trap_success' |
|
| 44 | - ); |
|
| 45 | - } |
|
| 46 | - } |
|
| 28 | + /** |
|
| 29 | + * set_hooks - for hooking into EE Core, other modules, etc |
|
| 30 | + * |
|
| 31 | + * @return void |
|
| 32 | + */ |
|
| 33 | + public static function set_hooks() |
|
| 34 | + { |
|
| 35 | + if (apply_filters('FHEE__EED_Bot_Trap__set_hooks__use_bot_trap', true) && |
|
| 36 | + EE_Registry::instance()->CFG->registration->use_bot_trap |
|
| 37 | + ) { |
|
| 38 | + EED_Bot_Trap::set_trap(); |
|
| 39 | + // redirect bots to bogus success page |
|
| 40 | + EE_Config::register_route( |
|
| 41 | + 'ticket_selection_received', |
|
| 42 | + 'EED_Bot_Trap', |
|
| 43 | + 'display_bot_trap_success' |
|
| 44 | + ); |
|
| 45 | + } |
|
| 46 | + } |
|
| 47 | 47 | |
| 48 | 48 | |
| 49 | - /** |
|
| 50 | - * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
| 51 | - * |
|
| 52 | - * @return void |
|
| 53 | - */ |
|
| 54 | - public static function set_trap() |
|
| 55 | - { |
|
| 56 | - define('EE_BOT_TRAP_BASE_URL', plugin_dir_url(__FILE__) . '/'); |
|
| 57 | - add_action( |
|
| 58 | - 'AHEE__ticket_selector_chart__template__after_ticket_selector', |
|
| 59 | - array('EED_Bot_Trap', 'generate_bot_trap'), |
|
| 60 | - 10, |
|
| 61 | - 2 |
|
| 62 | - ); |
|
| 63 | - add_action( |
|
| 64 | - 'EED_Ticket_Selector__process_ticket_selections__before', |
|
| 65 | - array('EED_Bot_Trap', 'process_bot_trap'), |
|
| 66 | - 1, |
|
| 67 | - 2 |
|
| 68 | - ); |
|
| 69 | - } |
|
| 49 | + /** |
|
| 50 | + * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
| 51 | + * |
|
| 52 | + * @return void |
|
| 53 | + */ |
|
| 54 | + public static function set_trap() |
|
| 55 | + { |
|
| 56 | + define('EE_BOT_TRAP_BASE_URL', plugin_dir_url(__FILE__) . '/'); |
|
| 57 | + add_action( |
|
| 58 | + 'AHEE__ticket_selector_chart__template__after_ticket_selector', |
|
| 59 | + array('EED_Bot_Trap', 'generate_bot_trap'), |
|
| 60 | + 10, |
|
| 61 | + 2 |
|
| 62 | + ); |
|
| 63 | + add_action( |
|
| 64 | + 'EED_Ticket_Selector__process_ticket_selections__before', |
|
| 65 | + array('EED_Bot_Trap', 'process_bot_trap'), |
|
| 66 | + 1, |
|
| 67 | + 2 |
|
| 68 | + ); |
|
| 69 | + } |
|
| 70 | 70 | |
| 71 | 71 | |
| 72 | - /** |
|
| 73 | - * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
| 74 | - * |
|
| 75 | - * @return void |
|
| 76 | - */ |
|
| 77 | - public static function set_hooks_admin() |
|
| 78 | - { |
|
| 79 | - if (defined('DOING_AJAX') |
|
| 80 | - && DOING_AJAX |
|
| 81 | - && apply_filters('FHEE__EED_Bot_Trap__set_hooks__use_bot_trap', true) |
|
| 82 | - && EE_Registry::instance()->CFG->registration->use_bot_trap |
|
| 83 | - ) { |
|
| 84 | - EED_Bot_Trap::set_trap(); |
|
| 85 | - } |
|
| 86 | - add_action( |
|
| 87 | - 'AHEE__Extend_Registration_Form_Admin_Page___reg_form_settings_template', |
|
| 88 | - array('EED_Bot_Trap', 'bot_trap_settings_form'), |
|
| 89 | - 5 |
|
| 90 | - ); |
|
| 91 | - add_filter( |
|
| 92 | - 'FHEE__Extend_Registration_Form_Admin_Page___update_reg_form_settings__CFG_registration', |
|
| 93 | - array('EED_Bot_Trap', 'update_bot_trap_settings_form'), |
|
| 94 | - 10, |
|
| 95 | - 1 |
|
| 96 | - ); |
|
| 97 | - } |
|
| 72 | + /** |
|
| 73 | + * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
| 74 | + * |
|
| 75 | + * @return void |
|
| 76 | + */ |
|
| 77 | + public static function set_hooks_admin() |
|
| 78 | + { |
|
| 79 | + if (defined('DOING_AJAX') |
|
| 80 | + && DOING_AJAX |
|
| 81 | + && apply_filters('FHEE__EED_Bot_Trap__set_hooks__use_bot_trap', true) |
|
| 82 | + && EE_Registry::instance()->CFG->registration->use_bot_trap |
|
| 83 | + ) { |
|
| 84 | + EED_Bot_Trap::set_trap(); |
|
| 85 | + } |
|
| 86 | + add_action( |
|
| 87 | + 'AHEE__Extend_Registration_Form_Admin_Page___reg_form_settings_template', |
|
| 88 | + array('EED_Bot_Trap', 'bot_trap_settings_form'), |
|
| 89 | + 5 |
|
| 90 | + ); |
|
| 91 | + add_filter( |
|
| 92 | + 'FHEE__Extend_Registration_Form_Admin_Page___update_reg_form_settings__CFG_registration', |
|
| 93 | + array('EED_Bot_Trap', 'update_bot_trap_settings_form'), |
|
| 94 | + 10, |
|
| 95 | + 1 |
|
| 96 | + ); |
|
| 97 | + } |
|
| 98 | 98 | |
| 99 | 99 | |
| 100 | - /** |
|
| 101 | - * run - initial module setup |
|
| 102 | - * |
|
| 103 | - * @param WP $WP |
|
| 104 | - * @return void |
|
| 105 | - */ |
|
| 106 | - public function run($WP) |
|
| 107 | - { |
|
| 108 | - } |
|
| 100 | + /** |
|
| 101 | + * run - initial module setup |
|
| 102 | + * |
|
| 103 | + * @param WP $WP |
|
| 104 | + * @return void |
|
| 105 | + */ |
|
| 106 | + public function run($WP) |
|
| 107 | + { |
|
| 108 | + } |
|
| 109 | 109 | |
| 110 | 110 | |
| 111 | - /** |
|
| 112 | - * generate_bot_trap |
|
| 113 | - * |
|
| 114 | - * @return void |
|
| 115 | - * @throws RuntimeException |
|
| 116 | - */ |
|
| 117 | - public static function generate_bot_trap() |
|
| 118 | - { |
|
| 119 | - $do_not_enter = esc_html__('please do not enter anything in this input', 'event_espresso'); |
|
| 120 | - $time = microtime(true); |
|
| 121 | - $html = '<div class="tkt-slctr-request-processor-dv" style="float:left; margin:0 0 0 -999em; height: 0;">'; |
|
| 122 | - $html .= '<label for="tkt-slctr-request-processor-email-' . $time . '">' . $do_not_enter . '</label>'; |
|
| 123 | - $html .= '<input type="email" id="tkt-slctr-request-processor-email-'; |
|
| 124 | - $html .= $time . '" name="tkt-slctr-request-processor-email" value=""/>'; |
|
| 125 | - $html .= '</div><!-- .tkt-slctr-request-processor-dv -->'; |
|
| 126 | - echo $html; |
|
| 127 | - } |
|
| 111 | + /** |
|
| 112 | + * generate_bot_trap |
|
| 113 | + * |
|
| 114 | + * @return void |
|
| 115 | + * @throws RuntimeException |
|
| 116 | + */ |
|
| 117 | + public static function generate_bot_trap() |
|
| 118 | + { |
|
| 119 | + $do_not_enter = esc_html__('please do not enter anything in this input', 'event_espresso'); |
|
| 120 | + $time = microtime(true); |
|
| 121 | + $html = '<div class="tkt-slctr-request-processor-dv" style="float:left; margin:0 0 0 -999em; height: 0;">'; |
|
| 122 | + $html .= '<label for="tkt-slctr-request-processor-email-' . $time . '">' . $do_not_enter . '</label>'; |
|
| 123 | + $html .= '<input type="email" id="tkt-slctr-request-processor-email-'; |
|
| 124 | + $html .= $time . '" name="tkt-slctr-request-processor-email" value=""/>'; |
|
| 125 | + $html .= '</div><!-- .tkt-slctr-request-processor-dv -->'; |
|
| 126 | + echo $html; |
|
| 127 | + } |
|
| 128 | 128 | |
| 129 | 129 | |
| 130 | - /** |
|
| 131 | - * process_bot_trap |
|
| 132 | - * |
|
| 133 | - * @param array|string $triggered_trap_callback Callback that will be executed for handling the |
|
| 134 | - * response if the bot trap is triggered. |
|
| 135 | - * It should receive one argument: a boolean indicating |
|
| 136 | - * whether the trap was triggered by suspicious timing or not. |
|
| 137 | - * @throws RuntimeException |
|
| 138 | - */ |
|
| 139 | - public static function process_bot_trap($triggered_trap_callback = array()) |
|
| 140 | - { |
|
| 141 | - // what's your email address Mr. Bot ? |
|
| 142 | - $empty_trap = isset($_REQUEST['tkt-slctr-request-processor-email']) |
|
| 143 | - && $_REQUEST['tkt-slctr-request-processor-email'] === ''; |
|
| 144 | - // are we human ? |
|
| 145 | - if ($empty_trap) { |
|
| 146 | - do_action('AHEE__EED_Bot_Trap__process_bot_trap__trap_not_triggered'); |
|
| 147 | - return; |
|
| 148 | - } |
|
| 149 | - // check the given callback is valid first before executing |
|
| 150 | - if (! is_callable($triggered_trap_callback)) { |
|
| 151 | - // invalid callback so lets just sub in our default. |
|
| 152 | - $triggered_trap_callback = array('EED_Bot_Trap', 'triggered_trap_response'); |
|
| 153 | - } |
|
| 154 | - call_user_func($triggered_trap_callback); |
|
| 155 | - } |
|
| 130 | + /** |
|
| 131 | + * process_bot_trap |
|
| 132 | + * |
|
| 133 | + * @param array|string $triggered_trap_callback Callback that will be executed for handling the |
|
| 134 | + * response if the bot trap is triggered. |
|
| 135 | + * It should receive one argument: a boolean indicating |
|
| 136 | + * whether the trap was triggered by suspicious timing or not. |
|
| 137 | + * @throws RuntimeException |
|
| 138 | + */ |
|
| 139 | + public static function process_bot_trap($triggered_trap_callback = array()) |
|
| 140 | + { |
|
| 141 | + // what's your email address Mr. Bot ? |
|
| 142 | + $empty_trap = isset($_REQUEST['tkt-slctr-request-processor-email']) |
|
| 143 | + && $_REQUEST['tkt-slctr-request-processor-email'] === ''; |
|
| 144 | + // are we human ? |
|
| 145 | + if ($empty_trap) { |
|
| 146 | + do_action('AHEE__EED_Bot_Trap__process_bot_trap__trap_not_triggered'); |
|
| 147 | + return; |
|
| 148 | + } |
|
| 149 | + // check the given callback is valid first before executing |
|
| 150 | + if (! is_callable($triggered_trap_callback)) { |
|
| 151 | + // invalid callback so lets just sub in our default. |
|
| 152 | + $triggered_trap_callback = array('EED_Bot_Trap', 'triggered_trap_response'); |
|
| 153 | + } |
|
| 154 | + call_user_func($triggered_trap_callback); |
|
| 155 | + } |
|
| 156 | 156 | |
| 157 | 157 | |
| 158 | - /** |
|
| 159 | - * This is the default callback executed by EED_Bot_Trap::process_bot_trap that handles the response. |
|
| 160 | - * |
|
| 161 | - * @throws InvalidArgumentException |
|
| 162 | - * @throws InvalidDataTypeException |
|
| 163 | - * @throws InvalidInterfaceException |
|
| 164 | - */ |
|
| 165 | - public static function triggered_trap_response() |
|
| 166 | - { |
|
| 167 | - // UH OH... |
|
| 168 | - $redirect_url = apply_filters( |
|
| 169 | - 'FHEE__EED_Bot_Trap__process_bot_trap__redirect_url', |
|
| 170 | - add_query_arg( |
|
| 171 | - array('ee' => 'ticket_selection_received'), |
|
| 172 | - EE_Registry::instance()->CFG->core->reg_page_url() |
|
| 173 | - ) |
|
| 174 | - ); |
|
| 175 | - // if AJAX, return the redirect URL |
|
| 176 | - if (defined('DOING_AJAX') && DOING_AJAX) { |
|
| 177 | - echo wp_json_encode( |
|
| 178 | - array_merge( |
|
| 179 | - EE_Error::get_notices(false), |
|
| 180 | - array( |
|
| 181 | - 'redirect_url' => $redirect_url, |
|
| 182 | - ) |
|
| 183 | - ) |
|
| 184 | - ); |
|
| 185 | - exit(); |
|
| 186 | - } |
|
| 187 | - wp_safe_redirect($redirect_url); |
|
| 188 | - exit(); |
|
| 189 | - } |
|
| 158 | + /** |
|
| 159 | + * This is the default callback executed by EED_Bot_Trap::process_bot_trap that handles the response. |
|
| 160 | + * |
|
| 161 | + * @throws InvalidArgumentException |
|
| 162 | + * @throws InvalidDataTypeException |
|
| 163 | + * @throws InvalidInterfaceException |
|
| 164 | + */ |
|
| 165 | + public static function triggered_trap_response() |
|
| 166 | + { |
|
| 167 | + // UH OH... |
|
| 168 | + $redirect_url = apply_filters( |
|
| 169 | + 'FHEE__EED_Bot_Trap__process_bot_trap__redirect_url', |
|
| 170 | + add_query_arg( |
|
| 171 | + array('ee' => 'ticket_selection_received'), |
|
| 172 | + EE_Registry::instance()->CFG->core->reg_page_url() |
|
| 173 | + ) |
|
| 174 | + ); |
|
| 175 | + // if AJAX, return the redirect URL |
|
| 176 | + if (defined('DOING_AJAX') && DOING_AJAX) { |
|
| 177 | + echo wp_json_encode( |
|
| 178 | + array_merge( |
|
| 179 | + EE_Error::get_notices(false), |
|
| 180 | + array( |
|
| 181 | + 'redirect_url' => $redirect_url, |
|
| 182 | + ) |
|
| 183 | + ) |
|
| 184 | + ); |
|
| 185 | + exit(); |
|
| 186 | + } |
|
| 187 | + wp_safe_redirect($redirect_url); |
|
| 188 | + exit(); |
|
| 189 | + } |
|
| 190 | 190 | |
| 191 | 191 | |
| 192 | - /** |
|
| 193 | - * display_bot_trap_success |
|
| 194 | - * shows a "success" screen to bots so that they (ie: the ppl managing them) |
|
| 195 | - * think the form was submitted successfully |
|
| 196 | - * |
|
| 197 | - * @return void |
|
| 198 | - */ |
|
| 199 | - public static function display_bot_trap_success() |
|
| 200 | - { |
|
| 201 | - add_filter('FHEE__EED_Single_Page_Checkout__run', '__return_false'); |
|
| 202 | - $bot_notice = esc_html__( |
|
| 203 | - 'Thank you so much. Your ticket selections have been received for consideration.', |
|
| 204 | - 'event_espresso' |
|
| 205 | - ); |
|
| 206 | - $bot_notice = isset($_REQUEST['ee-notice']) && $_REQUEST['ee-notice'] !== '' |
|
| 207 | - ? sanitize_text_field(stripslashes($_REQUEST['ee-notice'])) |
|
| 208 | - : $bot_notice; |
|
| 209 | - EE_Registry::instance()->REQ->add_output(EEH_HTML::div($bot_notice, '', 'ee-attention')); |
|
| 210 | - } |
|
| 192 | + /** |
|
| 193 | + * display_bot_trap_success |
|
| 194 | + * shows a "success" screen to bots so that they (ie: the ppl managing them) |
|
| 195 | + * think the form was submitted successfully |
|
| 196 | + * |
|
| 197 | + * @return void |
|
| 198 | + */ |
|
| 199 | + public static function display_bot_trap_success() |
|
| 200 | + { |
|
| 201 | + add_filter('FHEE__EED_Single_Page_Checkout__run', '__return_false'); |
|
| 202 | + $bot_notice = esc_html__( |
|
| 203 | + 'Thank you so much. Your ticket selections have been received for consideration.', |
|
| 204 | + 'event_espresso' |
|
| 205 | + ); |
|
| 206 | + $bot_notice = isset($_REQUEST['ee-notice']) && $_REQUEST['ee-notice'] !== '' |
|
| 207 | + ? sanitize_text_field(stripslashes($_REQUEST['ee-notice'])) |
|
| 208 | + : $bot_notice; |
|
| 209 | + EE_Registry::instance()->REQ->add_output(EEH_HTML::div($bot_notice, '', 'ee-attention')); |
|
| 210 | + } |
|
| 211 | 211 | |
| 212 | 212 | |
| 213 | 213 | |
| 214 | - /*********************************** ADMIN **********************************/ |
|
| 214 | + /*********************************** ADMIN **********************************/ |
|
| 215 | 215 | |
| 216 | 216 | |
| 217 | - /** |
|
| 218 | - * bot_trap_settings_form |
|
| 219 | - * |
|
| 220 | - * @return void |
|
| 221 | - * @throws EE_Error |
|
| 222 | - * @throws InvalidArgumentException |
|
| 223 | - * @throws InvalidDataTypeException |
|
| 224 | - * @throws InvalidInterfaceException |
|
| 225 | - */ |
|
| 226 | - public static function bot_trap_settings_form() |
|
| 227 | - { |
|
| 228 | - EED_Bot_Trap::_bot_trap_settings_form()->enqueue_js(); |
|
| 229 | - echo EED_Bot_Trap::_bot_trap_settings_form()->get_html(); |
|
| 230 | - } |
|
| 217 | + /** |
|
| 218 | + * bot_trap_settings_form |
|
| 219 | + * |
|
| 220 | + * @return void |
|
| 221 | + * @throws EE_Error |
|
| 222 | + * @throws InvalidArgumentException |
|
| 223 | + * @throws InvalidDataTypeException |
|
| 224 | + * @throws InvalidInterfaceException |
|
| 225 | + */ |
|
| 226 | + public static function bot_trap_settings_form() |
|
| 227 | + { |
|
| 228 | + EED_Bot_Trap::_bot_trap_settings_form()->enqueue_js(); |
|
| 229 | + echo EED_Bot_Trap::_bot_trap_settings_form()->get_html(); |
|
| 230 | + } |
|
| 231 | 231 | |
| 232 | 232 | |
| 233 | - /** |
|
| 234 | - * _bot_trap_settings_form |
|
| 235 | - * |
|
| 236 | - * @return EE_Form_Section_Proper |
|
| 237 | - * @throws EE_Error |
|
| 238 | - */ |
|
| 239 | - protected static function _bot_trap_settings_form() |
|
| 240 | - { |
|
| 241 | - return new EE_Form_Section_Proper( |
|
| 242 | - array( |
|
| 243 | - 'name' => 'bot_trap_settings', |
|
| 244 | - 'html_id' => 'bot_trap_settings', |
|
| 245 | - 'layout_strategy' => new EE_Admin_Two_Column_Layout(), |
|
| 246 | - 'subsections' => array( |
|
| 247 | - 'bot_trap_hdr' => new EE_Form_Section_HTML( |
|
| 248 | - EEH_HTML::h2(esc_html__('Bot Trap Settings', 'event_espresso')) |
|
| 249 | - ), |
|
| 250 | - 'use_bot_trap' => new EE_Yes_No_Input( |
|
| 251 | - array( |
|
| 252 | - 'html_label_text' => esc_html__('Enable Bot Trap', 'event_espresso'), |
|
| 253 | - 'html_help_text' => esc_html__( |
|
| 254 | - 'The Event Espresso Bot Trap will insert a fake input into your Ticket Selector forms that is hidden from regular site visitors, but visible to spam bots. Because the input asks for an email address, it is irresistible to spam bots who will of course enter text into it. Since regular site visitors can not see this input, any value detected during form submission means a bot has been detected, which will then be blocked from submitting the form.', |
|
| 255 | - 'event_espresso' |
|
| 256 | - ), |
|
| 257 | - 'default' => EE_Registry::instance()->CFG->registration->use_bot_trap !== null |
|
| 258 | - ? EE_Registry::instance()->CFG->registration->use_bot_trap |
|
| 259 | - : true, |
|
| 260 | - 'required' => false, |
|
| 261 | - ) |
|
| 262 | - ), |
|
| 263 | - ), |
|
| 264 | - ) |
|
| 265 | - ); |
|
| 266 | - } |
|
| 233 | + /** |
|
| 234 | + * _bot_trap_settings_form |
|
| 235 | + * |
|
| 236 | + * @return EE_Form_Section_Proper |
|
| 237 | + * @throws EE_Error |
|
| 238 | + */ |
|
| 239 | + protected static function _bot_trap_settings_form() |
|
| 240 | + { |
|
| 241 | + return new EE_Form_Section_Proper( |
|
| 242 | + array( |
|
| 243 | + 'name' => 'bot_trap_settings', |
|
| 244 | + 'html_id' => 'bot_trap_settings', |
|
| 245 | + 'layout_strategy' => new EE_Admin_Two_Column_Layout(), |
|
| 246 | + 'subsections' => array( |
|
| 247 | + 'bot_trap_hdr' => new EE_Form_Section_HTML( |
|
| 248 | + EEH_HTML::h2(esc_html__('Bot Trap Settings', 'event_espresso')) |
|
| 249 | + ), |
|
| 250 | + 'use_bot_trap' => new EE_Yes_No_Input( |
|
| 251 | + array( |
|
| 252 | + 'html_label_text' => esc_html__('Enable Bot Trap', 'event_espresso'), |
|
| 253 | + 'html_help_text' => esc_html__( |
|
| 254 | + 'The Event Espresso Bot Trap will insert a fake input into your Ticket Selector forms that is hidden from regular site visitors, but visible to spam bots. Because the input asks for an email address, it is irresistible to spam bots who will of course enter text into it. Since regular site visitors can not see this input, any value detected during form submission means a bot has been detected, which will then be blocked from submitting the form.', |
|
| 255 | + 'event_espresso' |
|
| 256 | + ), |
|
| 257 | + 'default' => EE_Registry::instance()->CFG->registration->use_bot_trap !== null |
|
| 258 | + ? EE_Registry::instance()->CFG->registration->use_bot_trap |
|
| 259 | + : true, |
|
| 260 | + 'required' => false, |
|
| 261 | + ) |
|
| 262 | + ), |
|
| 263 | + ), |
|
| 264 | + ) |
|
| 265 | + ); |
|
| 266 | + } |
|
| 267 | 267 | |
| 268 | 268 | |
| 269 | - /** |
|
| 270 | - * update_bot_trap_settings_form |
|
| 271 | - * |
|
| 272 | - * @param EE_Registration_Config $EE_Registration_Config |
|
| 273 | - * @return EE_Registration_Config |
|
| 274 | - * @throws EE_Error |
|
| 275 | - * @throws InvalidArgumentException |
|
| 276 | - * @throws ReflectionException |
|
| 277 | - * @throws InvalidDataTypeException |
|
| 278 | - * @throws InvalidInterfaceException |
|
| 279 | - */ |
|
| 280 | - public static function update_bot_trap_settings_form(EE_Registration_Config $EE_Registration_Config) |
|
| 281 | - { |
|
| 282 | - try { |
|
| 283 | - $bot_trap_settings_form = EED_Bot_Trap::_bot_trap_settings_form(); |
|
| 284 | - // if not displaying a form, then check for form submission |
|
| 285 | - if ($bot_trap_settings_form->was_submitted()) { |
|
| 286 | - // capture form data |
|
| 287 | - $bot_trap_settings_form->receive_form_submission(); |
|
| 288 | - // validate form data |
|
| 289 | - if ($bot_trap_settings_form->is_valid()) { |
|
| 290 | - // grab validated data from form |
|
| 291 | - $valid_data = $bot_trap_settings_form->valid_data(); |
|
| 292 | - if (isset($valid_data['use_bot_trap'])) { |
|
| 293 | - $EE_Registration_Config->use_bot_trap = $valid_data['use_bot_trap']; |
|
| 294 | - } else { |
|
| 295 | - EE_Error::add_error( |
|
| 296 | - esc_html__( |
|
| 297 | - 'Invalid or missing Bot Trap settings. Please refresh the form and try again.', |
|
| 298 | - 'event_espresso' |
|
| 299 | - ), |
|
| 300 | - __FILE__, |
|
| 301 | - __FUNCTION__, |
|
| 302 | - __LINE__ |
|
| 303 | - ); |
|
| 304 | - } |
|
| 305 | - } elseif ($bot_trap_settings_form->submission_error_message() !== '') { |
|
| 306 | - EE_Error::add_error( |
|
| 307 | - $bot_trap_settings_form->submission_error_message(), |
|
| 308 | - __FILE__, |
|
| 309 | - __FUNCTION__, |
|
| 310 | - __LINE__ |
|
| 311 | - ); |
|
| 312 | - } |
|
| 313 | - } |
|
| 314 | - } catch (EE_Error $e) { |
|
| 315 | - $e->get_error(); |
|
| 316 | - } |
|
| 317 | - return $EE_Registration_Config; |
|
| 318 | - } |
|
| 269 | + /** |
|
| 270 | + * update_bot_trap_settings_form |
|
| 271 | + * |
|
| 272 | + * @param EE_Registration_Config $EE_Registration_Config |
|
| 273 | + * @return EE_Registration_Config |
|
| 274 | + * @throws EE_Error |
|
| 275 | + * @throws InvalidArgumentException |
|
| 276 | + * @throws ReflectionException |
|
| 277 | + * @throws InvalidDataTypeException |
|
| 278 | + * @throws InvalidInterfaceException |
|
| 279 | + */ |
|
| 280 | + public static function update_bot_trap_settings_form(EE_Registration_Config $EE_Registration_Config) |
|
| 281 | + { |
|
| 282 | + try { |
|
| 283 | + $bot_trap_settings_form = EED_Bot_Trap::_bot_trap_settings_form(); |
|
| 284 | + // if not displaying a form, then check for form submission |
|
| 285 | + if ($bot_trap_settings_form->was_submitted()) { |
|
| 286 | + // capture form data |
|
| 287 | + $bot_trap_settings_form->receive_form_submission(); |
|
| 288 | + // validate form data |
|
| 289 | + if ($bot_trap_settings_form->is_valid()) { |
|
| 290 | + // grab validated data from form |
|
| 291 | + $valid_data = $bot_trap_settings_form->valid_data(); |
|
| 292 | + if (isset($valid_data['use_bot_trap'])) { |
|
| 293 | + $EE_Registration_Config->use_bot_trap = $valid_data['use_bot_trap']; |
|
| 294 | + } else { |
|
| 295 | + EE_Error::add_error( |
|
| 296 | + esc_html__( |
|
| 297 | + 'Invalid or missing Bot Trap settings. Please refresh the form and try again.', |
|
| 298 | + 'event_espresso' |
|
| 299 | + ), |
|
| 300 | + __FILE__, |
|
| 301 | + __FUNCTION__, |
|
| 302 | + __LINE__ |
|
| 303 | + ); |
|
| 304 | + } |
|
| 305 | + } elseif ($bot_trap_settings_form->submission_error_message() !== '') { |
|
| 306 | + EE_Error::add_error( |
|
| 307 | + $bot_trap_settings_form->submission_error_message(), |
|
| 308 | + __FILE__, |
|
| 309 | + __FUNCTION__, |
|
| 310 | + __LINE__ |
|
| 311 | + ); |
|
| 312 | + } |
|
| 313 | + } |
|
| 314 | + } catch (EE_Error $e) { |
|
| 315 | + $e->get_error(); |
|
| 316 | + } |
|
| 317 | + return $EE_Registration_Config; |
|
| 318 | + } |
|
| 319 | 319 | } |
@@ -53,7 +53,7 @@ discard block |
||
| 53 | 53 | */ |
| 54 | 54 | public static function set_trap() |
| 55 | 55 | { |
| 56 | - define('EE_BOT_TRAP_BASE_URL', plugin_dir_url(__FILE__) . '/'); |
|
| 56 | + define('EE_BOT_TRAP_BASE_URL', plugin_dir_url(__FILE__).'/'); |
|
| 57 | 57 | add_action( |
| 58 | 58 | 'AHEE__ticket_selector_chart__template__after_ticket_selector', |
| 59 | 59 | array('EED_Bot_Trap', 'generate_bot_trap'), |
@@ -119,9 +119,9 @@ discard block |
||
| 119 | 119 | $do_not_enter = esc_html__('please do not enter anything in this input', 'event_espresso'); |
| 120 | 120 | $time = microtime(true); |
| 121 | 121 | $html = '<div class="tkt-slctr-request-processor-dv" style="float:left; margin:0 0 0 -999em; height: 0;">'; |
| 122 | - $html .= '<label for="tkt-slctr-request-processor-email-' . $time . '">' . $do_not_enter . '</label>'; |
|
| 122 | + $html .= '<label for="tkt-slctr-request-processor-email-'.$time.'">'.$do_not_enter.'</label>'; |
|
| 123 | 123 | $html .= '<input type="email" id="tkt-slctr-request-processor-email-'; |
| 124 | - $html .= $time . '" name="tkt-slctr-request-processor-email" value=""/>'; |
|
| 124 | + $html .= $time.'" name="tkt-slctr-request-processor-email" value=""/>'; |
|
| 125 | 125 | $html .= '</div><!-- .tkt-slctr-request-processor-dv -->'; |
| 126 | 126 | echo $html; |
| 127 | 127 | } |
@@ -147,7 +147,7 @@ discard block |
||
| 147 | 147 | return; |
| 148 | 148 | } |
| 149 | 149 | // check the given callback is valid first before executing |
| 150 | - if (! is_callable($triggered_trap_callback)) { |
|
| 150 | + if ( ! is_callable($triggered_trap_callback)) { |
|
| 151 | 151 | // invalid callback so lets just sub in our default. |
| 152 | 152 | $triggered_trap_callback = array('EED_Bot_Trap', 'triggered_trap_response'); |
| 153 | 153 | } |
@@ -16,1094 +16,1094 @@ discard block |
||
| 16 | 16 | class EED_Events_Archive extends EED_Module |
| 17 | 17 | { |
| 18 | 18 | |
| 19 | - const EVENT_DETAILS_PRIORITY = 100; |
|
| 20 | - |
|
| 21 | - const EVENT_DATETIMES_PRIORITY = 110; |
|
| 22 | - |
|
| 23 | - const EVENT_TICKETS_PRIORITY = 120; |
|
| 24 | - |
|
| 25 | - const EVENT_VENUES_PRIORITY = 130; |
|
| 26 | - |
|
| 27 | - |
|
| 28 | - public static $espresso_event_list_ID = 0; |
|
| 29 | - |
|
| 30 | - public static $espresso_grid_event_lists = array(); |
|
| 31 | - |
|
| 32 | - /** |
|
| 33 | - * @type bool $using_get_the_excerpt |
|
| 34 | - */ |
|
| 35 | - protected static $using_get_the_excerpt = false; |
|
| 36 | - |
|
| 37 | - /** |
|
| 38 | - * Used to flag when the event list is being called from an external iframe. |
|
| 39 | - * |
|
| 40 | - * @var bool $iframe |
|
| 41 | - */ |
|
| 42 | - protected static $iframe = false; |
|
| 43 | - |
|
| 44 | - /** |
|
| 45 | - * @var \EventEspresso\core\libraries\iframe_display\EventListIframeEmbedButton $_iframe_embed_button |
|
| 46 | - */ |
|
| 47 | - private static $_iframe_embed_button; |
|
| 48 | - |
|
| 49 | - /** |
|
| 50 | - * @type EE_Template_Part_Manager $template_parts |
|
| 51 | - */ |
|
| 52 | - protected $template_parts; |
|
| 53 | - |
|
| 54 | - |
|
| 55 | - /** |
|
| 56 | - * @return EED_Events_Archive |
|
| 57 | - */ |
|
| 58 | - public static function instance() |
|
| 59 | - { |
|
| 60 | - return parent::get_instance(__CLASS__); |
|
| 61 | - } |
|
| 62 | - |
|
| 63 | - |
|
| 64 | - /** |
|
| 65 | - * set_hooks - for hooking into EE Core, other modules, etc |
|
| 66 | - * |
|
| 67 | - * @return void |
|
| 68 | - * @throws InvalidArgumentException |
|
| 69 | - * @throws InvalidDataTypeException |
|
| 70 | - * @throws InvalidInterfaceException |
|
| 71 | - */ |
|
| 72 | - public static function set_hooks() |
|
| 73 | - { |
|
| 74 | - /** @var EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions $custom_post_type_definitions */ |
|
| 75 | - $custom_post_type_definitions = LoaderFactory::getLoader()->getShared( |
|
| 76 | - 'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' |
|
| 77 | - ); |
|
| 78 | - $custom_post_types = $custom_post_type_definitions->getDefinitions(); |
|
| 79 | - EE_Config::register_route( |
|
| 80 | - $custom_post_types['espresso_events']['plural_slug'], |
|
| 81 | - 'Events_Archive', |
|
| 82 | - 'run' |
|
| 83 | - ); |
|
| 84 | - EE_Config::register_route( |
|
| 85 | - 'event_list', |
|
| 86 | - 'Events_Archive', |
|
| 87 | - 'event_list' |
|
| 88 | - ); |
|
| 89 | - EE_Config::register_route( |
|
| 90 | - 'iframe', |
|
| 91 | - 'Events_Archive', |
|
| 92 | - 'event_list_iframe', |
|
| 93 | - 'event_list' |
|
| 94 | - ); |
|
| 95 | - add_action('wp_loaded', array('EED_Events_Archive', 'set_definitions'), 2); |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - |
|
| 99 | - /** |
|
| 100 | - * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
| 101 | - * |
|
| 102 | - * @access public |
|
| 103 | - * @return void |
|
| 104 | - */ |
|
| 105 | - public static function set_hooks_admin() |
|
| 106 | - { |
|
| 107 | - add_action('wp_loaded', array('EED_Events_Archive', 'set_definitions'), 2); |
|
| 108 | - // hook into the end of the \EE_Admin_Page::_load_page_dependencies() |
|
| 109 | - // to load assets for "espresso_events" page on the "default" route (action) |
|
| 110 | - add_action( |
|
| 111 | - 'FHEE__EE_Admin_Page___load_page_dependencies__after_load__espresso_events__default', |
|
| 112 | - array('EED_Events_Archive', 'event_list_iframe_embed_button'), |
|
| 113 | - 10 |
|
| 114 | - ); |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - |
|
| 118 | - /** |
|
| 119 | - * set_definitions |
|
| 120 | - * |
|
| 121 | - * @access public |
|
| 122 | - * @return void |
|
| 123 | - */ |
|
| 124 | - public static function set_definitions() |
|
| 125 | - { |
|
| 126 | - define('EVENTS_ARCHIVE_ASSETS_URL', plugin_dir_url(__FILE__) . 'assets/'); |
|
| 127 | - define('EVENTS_ARCHIVE_TEMPLATES_PATH', str_replace('\\', '/', plugin_dir_path(__FILE__)) . 'templates/'); |
|
| 128 | - } |
|
| 129 | - |
|
| 130 | - |
|
| 131 | - /** |
|
| 132 | - * set up EE_Events_Archive_Config |
|
| 133 | - */ |
|
| 134 | - protected function set_config() |
|
| 135 | - { |
|
| 136 | - $this->set_config_section('template_settings'); |
|
| 137 | - $this->set_config_class('EE_Events_Archive_Config'); |
|
| 138 | - $this->set_config_name('EED_Events_Archive'); |
|
| 139 | - } |
|
| 140 | - |
|
| 141 | - |
|
| 142 | - /** |
|
| 143 | - * @return EventListIframeEmbedButton |
|
| 144 | - */ |
|
| 145 | - public static function get_iframe_embed_button() |
|
| 146 | - { |
|
| 147 | - if (! self::$_iframe_embed_button instanceof EventListIframeEmbedButton) { |
|
| 148 | - self::$_iframe_embed_button = new EventListIframeEmbedButton(); |
|
| 149 | - } |
|
| 150 | - return self::$_iframe_embed_button; |
|
| 151 | - } |
|
| 152 | - |
|
| 153 | - |
|
| 154 | - /** |
|
| 155 | - * event_list_iframe_embed_button |
|
| 156 | - * |
|
| 157 | - * @return void |
|
| 158 | - * @throws \EE_Error |
|
| 159 | - */ |
|
| 160 | - public static function event_list_iframe_embed_button() |
|
| 161 | - { |
|
| 162 | - $iframe_embed_button = \EED_Events_Archive::get_iframe_embed_button(); |
|
| 163 | - $iframe_embed_button->addEmbedButton(); |
|
| 164 | - } |
|
| 165 | - |
|
| 166 | - |
|
| 167 | - /** |
|
| 168 | - * initialize_template_parts |
|
| 169 | - * |
|
| 170 | - * @access public |
|
| 171 | - * @param \EE_Events_Archive_Config $config |
|
| 172 | - * @return \EE_Template_Part_Manager |
|
| 173 | - */ |
|
| 174 | - public function initialize_template_parts(EE_Events_Archive_Config $config = null) |
|
| 175 | - { |
|
| 176 | - $config = $config instanceof EE_Events_Archive_Config ? $config : $this->config(); |
|
| 177 | - EEH_Autoloader::instance()->register_template_part_autoloaders(); |
|
| 178 | - $template_parts = new EE_Template_Part_Manager(); |
|
| 179 | - $template_parts->add_template_part( |
|
| 180 | - 'tickets', |
|
| 181 | - __('Ticket Selector', 'event_espresso'), |
|
| 182 | - 'content-espresso_events-tickets.php', |
|
| 183 | - $config->display_order_tickets |
|
| 184 | - ); |
|
| 185 | - $template_parts->add_template_part( |
|
| 186 | - 'datetimes', |
|
| 187 | - __('Dates and Times', 'event_espresso'), |
|
| 188 | - 'content-espresso_events-datetimes.php', |
|
| 189 | - $config->display_order_datetimes |
|
| 190 | - ); |
|
| 191 | - $template_parts->add_template_part( |
|
| 192 | - 'event', |
|
| 193 | - __('Event Description', 'event_espresso'), |
|
| 194 | - 'content-espresso_events-details.php', |
|
| 195 | - $config->display_order_event |
|
| 196 | - ); |
|
| 197 | - $template_parts->add_template_part( |
|
| 198 | - 'venue', |
|
| 199 | - __('Venue Information', 'event_espresso'), |
|
| 200 | - 'content-espresso_events-venues.php', |
|
| 201 | - $config->display_order_venue |
|
| 202 | - ); |
|
| 203 | - do_action('AHEE__EED_Event_Archive__initialize_template_parts', $template_parts); |
|
| 204 | - return $template_parts; |
|
| 205 | - } |
|
| 206 | - |
|
| 207 | - |
|
| 208 | - /** |
|
| 209 | - * run - initial module setup - this gets called by the EE_Front_Controller if the module route is found in the |
|
| 210 | - * incoming request |
|
| 211 | - * |
|
| 212 | - * @access public |
|
| 213 | - * @param WP $WP |
|
| 214 | - * @return void |
|
| 215 | - */ |
|
| 216 | - public function run($WP) |
|
| 217 | - { |
|
| 218 | - do_action('AHEE__EED_Events_Archive__before_run'); |
|
| 219 | - // ensure valid EE_Events_Archive_Config() object exists |
|
| 220 | - $this->set_config(); |
|
| 221 | - /** @type EE_Events_Archive_Config $config */ |
|
| 222 | - $config = $this->config(); |
|
| 223 | - // load other required components |
|
| 224 | - $this->load_event_list_assets(); |
|
| 225 | - // filter the WP posts_join, posts_where, and posts_orderby SQL clauses |
|
| 226 | - // add query filters |
|
| 227 | - EEH_Event_Query::add_query_filters(); |
|
| 228 | - // set params that will get used by the filters |
|
| 229 | - EEH_Event_Query::set_query_params( |
|
| 230 | - '', // month |
|
| 231 | - '', // category |
|
| 232 | - $config->display_expired_events, // show_expired |
|
| 233 | - 'start_date', // orderby |
|
| 234 | - 'ASC' // sort |
|
| 235 | - ); |
|
| 236 | - // check what template is loaded |
|
| 237 | - add_filter('template_include', array($this, 'template_include'), 999, 1); |
|
| 238 | - } |
|
| 239 | - |
|
| 240 | - |
|
| 241 | - /** |
|
| 242 | - * most likely called by the ESPRESSO_EVENTS shortcode which uses this module to do some of it's lifting |
|
| 243 | - * |
|
| 244 | - * @return void |
|
| 245 | - */ |
|
| 246 | - public function event_list() |
|
| 247 | - { |
|
| 248 | - // ensure valid EE_Events_Archive_Config() object exists |
|
| 249 | - $this->set_config(); |
|
| 250 | - // load other required components |
|
| 251 | - $this->load_event_list_assets(); |
|
| 252 | - } |
|
| 253 | - |
|
| 254 | - |
|
| 255 | - /** |
|
| 256 | - * @access public |
|
| 257 | - * @return void |
|
| 258 | - * @throws \EE_Error |
|
| 259 | - * @throws \DomainException |
|
| 260 | - */ |
|
| 261 | - public function event_list_iframe() |
|
| 262 | - { |
|
| 263 | - \EED_Events_Archive::$iframe = true; |
|
| 264 | - $event_list_iframe = new EventsArchiveIframe($this); |
|
| 265 | - $event_list_iframe->display(); |
|
| 266 | - } |
|
| 267 | - |
|
| 268 | - |
|
| 269 | - /** |
|
| 270 | - * @access public |
|
| 271 | - * @return string |
|
| 272 | - */ |
|
| 273 | - public static function is_iframe() |
|
| 274 | - { |
|
| 275 | - return \EED_Events_Archive::$iframe; |
|
| 276 | - } |
|
| 277 | - |
|
| 278 | - |
|
| 279 | - /** |
|
| 280 | - * @access public |
|
| 281 | - * @return string |
|
| 282 | - */ |
|
| 283 | - public static function link_target() |
|
| 284 | - { |
|
| 285 | - return \EED_Events_Archive::$iframe ? ' target="_blank"' : ''; |
|
| 286 | - } |
|
| 287 | - |
|
| 288 | - |
|
| 289 | - /** |
|
| 290 | - * template_include |
|
| 291 | - * |
|
| 292 | - * @access public |
|
| 293 | - * @param string $template |
|
| 294 | - * @return string |
|
| 295 | - */ |
|
| 296 | - public function template_include($template = '') |
|
| 297 | - { |
|
| 298 | - // don't add content filter for dedicated EE child themes or private posts |
|
| 299 | - if (! EEH_Template::is_espresso_theme()) { |
|
| 300 | - /** @type EE_Events_Archive_Config $config */ |
|
| 301 | - $config = $this->config(); |
|
| 302 | - // add status banner ? |
|
| 303 | - if ($config->display_status_banner) { |
|
| 304 | - add_filter('the_title', array('EED_Events_Archive', 'the_title'), 100, 2); |
|
| 305 | - } |
|
| 306 | - // if NOT a custom template |
|
| 307 | - if (apply_filters('FHEE__EED_Event_Archive__template_include__allow_custom_selected_template', false) |
|
| 308 | - || EE_Registry::instance() |
|
| 309 | - ->load_core('Front_Controller') |
|
| 310 | - ->get_selected_template() !== 'archive-espresso_events.php' |
|
| 311 | - ) { |
|
| 312 | - // don't display entry meta because the existing theme will take care of that |
|
| 313 | - add_filter('FHEE__EED_Events_Archive__template_include__events_list_active', '__return_true'); |
|
| 314 | - // load functions.php file for the theme (loaded by WP if using child theme) |
|
| 315 | - EEH_Template::load_espresso_theme_functions(); |
|
| 316 | - // because we don't know if the theme is using the_excerpt() |
|
| 317 | - add_filter( |
|
| 318 | - 'the_excerpt', |
|
| 319 | - array('EED_Events_Archive', 'event_details'), |
|
| 320 | - EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
| 321 | - ); |
|
| 322 | - // or the_content |
|
| 323 | - add_filter( |
|
| 324 | - 'the_content', |
|
| 325 | - array('EED_Events_Archive', 'event_details'), |
|
| 326 | - EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
| 327 | - ); |
|
| 328 | - // and just in case they are running get_the_excerpt() which DESTROYS things |
|
| 329 | - add_filter('get_the_excerpt', array('EED_Events_Archive', 'get_the_excerpt'), 1, 1); |
|
| 330 | - // don't display entry meta because the existing theme will take care of that |
|
| 331 | - add_filter('FHEE__content_espresso_events_details_template__display_entry_meta', '__return_false'); |
|
| 332 | - } |
|
| 333 | - } |
|
| 334 | - return $template; |
|
| 335 | - } |
|
| 336 | - |
|
| 337 | - |
|
| 338 | - /** |
|
| 339 | - * get_the_excerpt - kinda hacky, but if a theme is using get_the_excerpt(), then we need to remove our filters |
|
| 340 | - * on the_content() |
|
| 341 | - * |
|
| 342 | - * @access public |
|
| 343 | - * @param string $excerpt |
|
| 344 | - * @return string |
|
| 345 | - */ |
|
| 346 | - public static function get_the_excerpt($excerpt = '') |
|
| 347 | - { |
|
| 348 | - if (post_password_required()) { |
|
| 349 | - return $excerpt; |
|
| 350 | - } |
|
| 351 | - if (apply_filters('FHEE__EED_Events_Archive__get_the_excerpt__theme_uses_get_the_excerpt', false)) { |
|
| 352 | - remove_filter( |
|
| 353 | - 'the_excerpt', |
|
| 354 | - array('EED_Events_Archive', 'event_details'), |
|
| 355 | - EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
| 356 | - ); |
|
| 357 | - remove_filter( |
|
| 358 | - 'the_content', |
|
| 359 | - array('EED_Events_Archive', 'event_details'), |
|
| 360 | - EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
| 361 | - ); |
|
| 362 | - $excerpt = EED_Events_Archive::event_details($excerpt); |
|
| 363 | - } else { |
|
| 364 | - EED_Events_Archive::$using_get_the_excerpt = true; |
|
| 365 | - add_filter('wp_trim_excerpt', array('EED_Events_Archive', 'end_get_the_excerpt'), 999, 1); |
|
| 366 | - } |
|
| 367 | - return $excerpt; |
|
| 368 | - } |
|
| 369 | - |
|
| 370 | - |
|
| 371 | - /** |
|
| 372 | - * end_get_the_excerpt |
|
| 373 | - * |
|
| 374 | - * @access public |
|
| 375 | - * @param string $text |
|
| 376 | - * @return string |
|
| 377 | - */ |
|
| 378 | - public static function end_get_the_excerpt($text = '') |
|
| 379 | - { |
|
| 380 | - EED_Events_Archive::$using_get_the_excerpt = false; |
|
| 381 | - return $text; |
|
| 382 | - } |
|
| 383 | - |
|
| 384 | - |
|
| 385 | - /** |
|
| 386 | - * the_title |
|
| 387 | - * |
|
| 388 | - * @access public |
|
| 389 | - * @param string $title |
|
| 390 | - * @param string $id |
|
| 391 | - * @return string |
|
| 392 | - */ |
|
| 393 | - public static function the_title($title = '', $id = '') |
|
| 394 | - { |
|
| 395 | - global $post; |
|
| 396 | - if ($post instanceof WP_Post) { |
|
| 397 | - return in_the_loop() && $post->ID == $id ? espresso_event_status_banner($post->ID) . $title : $title; |
|
| 398 | - } |
|
| 399 | - return $title; |
|
| 400 | - } |
|
| 401 | - |
|
| 402 | - |
|
| 403 | - /** |
|
| 404 | - * event_details |
|
| 405 | - * |
|
| 406 | - * @access public |
|
| 407 | - * @param string $content |
|
| 408 | - * @return string |
|
| 409 | - */ |
|
| 410 | - public static function event_details($content) |
|
| 411 | - { |
|
| 412 | - global $post; |
|
| 413 | - static $current_post_ID = 0; |
|
| 414 | - if ($current_post_ID !== $post->ID |
|
| 415 | - && $post->post_type === 'espresso_events' |
|
| 416 | - && ! EED_Events_Archive::$using_get_the_excerpt |
|
| 417 | - && ! post_password_required() |
|
| 418 | - && ( |
|
| 419 | - apply_filters('FHEE__EES_Espresso_Events__process_shortcode__true', false) |
|
| 420 | - || ! apply_filters('FHEE__content_espresso_events__template_loaded', false) |
|
| 421 | - ) |
|
| 422 | - ) { |
|
| 423 | - // Set current post ID to prevent showing content twice, but only if headers have definitely been sent. |
|
| 424 | - // Reason being is that some plugins, like Yoast, need to run through a copy of the loop early |
|
| 425 | - // BEFORE headers are sent in order to examine the post content and generate content for the HTML header. |
|
| 426 | - // We want to allow those plugins to still do their thing and have access to our content, but depending on |
|
| 427 | - // how your event content is being displayed (shortcode, CPT route, etc), this filter can get applied twice, |
|
| 428 | - // so the following allows this filter to be applied multiple times, but only once for real |
|
| 429 | - $current_post_ID = did_action('loop_start') ? $post->ID : 0; |
|
| 430 | - if (EE_Registry::instance()->CFG->template_settings->EED_Events_Archive->use_sortable_display_order) { |
|
| 431 | - $content = \EED_Events_Archive::use_sortable_display_order(); |
|
| 432 | - } else { |
|
| 433 | - $content = \EED_Events_Archive::use_filterable_display_order(); |
|
| 434 | - } |
|
| 435 | - } |
|
| 436 | - return $content; |
|
| 437 | - } |
|
| 438 | - |
|
| 439 | - |
|
| 440 | - /** |
|
| 441 | - * use_sortable_display_order |
|
| 442 | - * |
|
| 443 | - * @access protected |
|
| 444 | - * @return string |
|
| 445 | - */ |
|
| 446 | - protected static function use_sortable_display_order() |
|
| 447 | - { |
|
| 448 | - // no further password checks required atm |
|
| 449 | - add_filter('FHEE__EED_Events_Archive__event_details__no_post_password_required', '__return_true'); |
|
| 450 | - // we need to first remove this callback from being applied to the_content() or the_excerpt() |
|
| 451 | - // (otherwise it will recurse and blow up the interweb) |
|
| 452 | - remove_filter( |
|
| 453 | - 'the_excerpt', |
|
| 454 | - array('EED_Events_Archive', 'event_details'), |
|
| 455 | - EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
| 456 | - ); |
|
| 457 | - remove_filter( |
|
| 458 | - 'the_content', |
|
| 459 | - array('EED_Events_Archive', 'event_details'), |
|
| 460 | - EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
| 461 | - ); |
|
| 462 | - remove_filter('get_the_excerpt', array('EED_Events_Archive', 'get_the_excerpt'), 1); |
|
| 463 | - // now add additional content depending on whether event is using the_excerpt() or the_content() |
|
| 464 | - EED_Events_Archive::instance()->template_parts = EED_Events_Archive::instance()->initialize_template_parts(); |
|
| 465 | - $content = EEH_Template::locate_template('content-espresso_events-details.php'); |
|
| 466 | - $content = EED_Events_Archive::instance()->template_parts->apply_template_part_filters($content); |
|
| 467 | - // re-add our main filters (or else the next event won't have them) |
|
| 468 | - add_filter( |
|
| 469 | - 'the_excerpt', |
|
| 470 | - array('EED_Events_Archive', 'event_details'), |
|
| 471 | - EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
| 472 | - ); |
|
| 473 | - add_filter( |
|
| 474 | - 'the_content', |
|
| 475 | - array('EED_Events_Archive', 'event_details'), |
|
| 476 | - EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
| 477 | - ); |
|
| 478 | - add_filter('get_the_excerpt', array('EED_Events_Archive', 'get_the_excerpt'), 1, 1); |
|
| 479 | - remove_filter( |
|
| 480 | - 'FHEE__EED_Events_Archive__event_details__no_post_password_required', |
|
| 481 | - '__return_true' |
|
| 482 | - ); |
|
| 483 | - return $content; |
|
| 484 | - } |
|
| 485 | - |
|
| 486 | - |
|
| 487 | - /** |
|
| 488 | - * use_filterable_display_order |
|
| 489 | - * |
|
| 490 | - * @access protected |
|
| 491 | - * @return string |
|
| 492 | - */ |
|
| 493 | - protected static function use_filterable_display_order() |
|
| 494 | - { |
|
| 495 | - // we need to first remove this callback from being applied to the_content() |
|
| 496 | - // (otherwise it will recurse and blow up the interweb) |
|
| 497 | - remove_filter( |
|
| 498 | - 'the_excerpt', |
|
| 499 | - array('EED_Events_Archive', 'event_details'), |
|
| 500 | - EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
| 501 | - ); |
|
| 502 | - remove_filter( |
|
| 503 | - 'the_content', |
|
| 504 | - array('EED_Events_Archive', 'event_details'), |
|
| 505 | - EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
| 506 | - ); |
|
| 507 | - remove_filter('get_the_excerpt', array('EED_Events_Archive', 'get_the_excerpt'), 1); |
|
| 508 | - // now add additional content depending on whether event is using the_excerpt() or the_content() |
|
| 509 | - EED_Events_Archive::_add_additional_excerpt_filters(); |
|
| 510 | - EED_Events_Archive::_add_additional_content_filters(); |
|
| 511 | - do_action('AHEE__EED_Events_Archive__use_filterable_display_order__after_add_filters'); |
|
| 512 | - // now load our template |
|
| 513 | - $content = EEH_Template::locate_template('content-espresso_events-details.php'); |
|
| 514 | - // re-add our main filters (or else the next event won't have them) |
|
| 515 | - add_filter( |
|
| 516 | - 'the_excerpt', |
|
| 517 | - array('EED_Events_Archive', 'event_details'), |
|
| 518 | - EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
| 519 | - ); |
|
| 520 | - add_filter( |
|
| 521 | - 'the_content', |
|
| 522 | - array('EED_Events_Archive', 'event_details'), |
|
| 523 | - EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
| 524 | - ); |
|
| 525 | - add_filter('get_the_excerpt', array('EED_Events_Archive', 'get_the_excerpt'), 1, 1); |
|
| 526 | - // but remove the other filters so that they don't get applied to the next post |
|
| 527 | - EED_Events_Archive::_remove_additional_events_archive_filters(); |
|
| 528 | - do_action('AHEE__EED_Events_Archive__use_filterable_display_order__after_remove_filters'); |
|
| 529 | - // we're not returning the $content directly because the template we are loading uses the_content (or the_excerpt) |
|
| 530 | - // return ! empty( $template ) ? $template : $content; |
|
| 531 | - return $content; |
|
| 532 | - } |
|
| 533 | - |
|
| 534 | - |
|
| 535 | - /** |
|
| 536 | - * event_datetimes - adds datetimes ABOVE content |
|
| 537 | - * |
|
| 538 | - * @access public |
|
| 539 | - * @param string $content |
|
| 540 | - * @return string |
|
| 541 | - */ |
|
| 542 | - public static function event_datetimes($content) |
|
| 543 | - { |
|
| 544 | - if (post_password_required()) { |
|
| 545 | - return $content; |
|
| 546 | - } |
|
| 547 | - return EEH_Template::locate_template('content-espresso_events-datetimes.php') . $content; |
|
| 548 | - } |
|
| 549 | - |
|
| 550 | - |
|
| 551 | - /** |
|
| 552 | - * event_tickets - adds tickets ABOVE content (which includes datetimes) |
|
| 553 | - * |
|
| 554 | - * @access public |
|
| 555 | - * @param string $content |
|
| 556 | - * @return string |
|
| 557 | - */ |
|
| 558 | - public static function event_tickets($content) |
|
| 559 | - { |
|
| 560 | - if (post_password_required()) { |
|
| 561 | - return $content; |
|
| 562 | - } |
|
| 563 | - return EEH_Template::locate_template('content-espresso_events-tickets.php') . $content; |
|
| 564 | - } |
|
| 565 | - |
|
| 566 | - |
|
| 567 | - /** |
|
| 568 | - * event_venues - adds venues BELOW content |
|
| 569 | - * |
|
| 570 | - * @access public |
|
| 571 | - * @param string $content |
|
| 572 | - * @return string |
|
| 573 | - */ |
|
| 574 | - public static function event_venue($content) |
|
| 575 | - { |
|
| 576 | - return EED_Events_Archive::event_venues($content); |
|
| 577 | - } |
|
| 578 | - |
|
| 579 | - |
|
| 580 | - /** |
|
| 581 | - * event_venues - adds venues BELOW content |
|
| 582 | - * |
|
| 583 | - * @access public |
|
| 584 | - * @param string $content |
|
| 585 | - * @return string |
|
| 586 | - */ |
|
| 587 | - public static function event_venues($content) |
|
| 588 | - { |
|
| 589 | - if (post_password_required()) { |
|
| 590 | - return $content; |
|
| 591 | - } |
|
| 592 | - return $content . EEH_Template::locate_template('content-espresso_events-venues.php'); |
|
| 593 | - } |
|
| 594 | - |
|
| 595 | - |
|
| 596 | - /** |
|
| 597 | - * _add_additional_content_filters |
|
| 598 | - * |
|
| 599 | - * @access private |
|
| 600 | - * @return void |
|
| 601 | - */ |
|
| 602 | - private static function _add_additional_excerpt_filters() |
|
| 603 | - { |
|
| 604 | - add_filter( |
|
| 605 | - 'the_excerpt', |
|
| 606 | - array('EED_Events_Archive', 'event_datetimes'), |
|
| 607 | - EED_Events_Archive::EVENT_DATETIMES_PRIORITY |
|
| 608 | - ); |
|
| 609 | - add_filter( |
|
| 610 | - 'the_excerpt', |
|
| 611 | - array('EED_Events_Archive', 'event_tickets'), |
|
| 612 | - EED_Events_Archive::EVENT_TICKETS_PRIORITY |
|
| 613 | - ); |
|
| 614 | - add_filter( |
|
| 615 | - 'the_excerpt', |
|
| 616 | - array('EED_Events_Archive', 'event_venues'), |
|
| 617 | - EED_Events_Archive::EVENT_VENUES_PRIORITY |
|
| 618 | - ); |
|
| 619 | - } |
|
| 620 | - |
|
| 621 | - |
|
| 622 | - /** |
|
| 623 | - * _add_additional_content_filters |
|
| 624 | - * |
|
| 625 | - * @access private |
|
| 626 | - * @return void |
|
| 627 | - */ |
|
| 628 | - private static function _add_additional_content_filters() |
|
| 629 | - { |
|
| 630 | - add_filter( |
|
| 631 | - 'the_content', |
|
| 632 | - array('EED_Events_Archive', 'event_datetimes'), |
|
| 633 | - EED_Events_Archive::EVENT_DATETIMES_PRIORITY |
|
| 634 | - ); |
|
| 635 | - add_filter( |
|
| 636 | - 'the_content', |
|
| 637 | - array('EED_Events_Archive', 'event_tickets'), |
|
| 638 | - EED_Events_Archive::EVENT_TICKETS_PRIORITY |
|
| 639 | - ); |
|
| 640 | - add_filter( |
|
| 641 | - 'the_content', |
|
| 642 | - array('EED_Events_Archive', 'event_venues'), |
|
| 643 | - EED_Events_Archive::EVENT_VENUES_PRIORITY |
|
| 644 | - ); |
|
| 645 | - } |
|
| 646 | - |
|
| 647 | - |
|
| 648 | - /** |
|
| 649 | - * _remove_additional_events_archive_filters |
|
| 650 | - * |
|
| 651 | - * @access private |
|
| 652 | - * @return void |
|
| 653 | - */ |
|
| 654 | - private static function _remove_additional_events_archive_filters() |
|
| 655 | - { |
|
| 656 | - remove_filter( |
|
| 657 | - 'the_excerpt', |
|
| 658 | - array('EED_Events_Archive', 'event_datetimes'), |
|
| 659 | - EED_Events_Archive::EVENT_DATETIMES_PRIORITY |
|
| 660 | - ); |
|
| 661 | - remove_filter( |
|
| 662 | - 'the_excerpt', |
|
| 663 | - array('EED_Events_Archive', 'event_tickets'), |
|
| 664 | - EED_Events_Archive::EVENT_TICKETS_PRIORITY |
|
| 665 | - ); |
|
| 666 | - remove_filter( |
|
| 667 | - 'the_excerpt', |
|
| 668 | - array('EED_Events_Archive', 'event_venues'), |
|
| 669 | - EED_Events_Archive::EVENT_VENUES_PRIORITY |
|
| 670 | - ); |
|
| 671 | - remove_filter( |
|
| 672 | - 'the_content', |
|
| 673 | - array('EED_Events_Archive', 'event_datetimes'), |
|
| 674 | - EED_Events_Archive::EVENT_DATETIMES_PRIORITY |
|
| 675 | - ); |
|
| 676 | - remove_filter( |
|
| 677 | - 'the_content', |
|
| 678 | - array('EED_Events_Archive', 'event_tickets'), |
|
| 679 | - EED_Events_Archive::EVENT_TICKETS_PRIORITY |
|
| 680 | - ); |
|
| 681 | - remove_filter( |
|
| 682 | - 'the_content', |
|
| 683 | - array('EED_Events_Archive', 'event_venues'), |
|
| 684 | - EED_Events_Archive::EVENT_VENUES_PRIORITY |
|
| 685 | - ); |
|
| 686 | - } |
|
| 687 | - |
|
| 688 | - |
|
| 689 | - /** |
|
| 690 | - * remove_all_events_archive_filters |
|
| 691 | - * |
|
| 692 | - * @access public |
|
| 693 | - * @return void |
|
| 694 | - */ |
|
| 695 | - public static function remove_all_events_archive_filters() |
|
| 696 | - { |
|
| 697 | - // remove_filter( 'get_the_excerpt', array( 'EED_Events_Archive', 'get_the_excerpt' ), 1 ); |
|
| 698 | - remove_filter('the_title', array('EED_Events_Archive', 'the_title'), 1); |
|
| 699 | - remove_filter( |
|
| 700 | - 'the_excerpt', |
|
| 701 | - array('EED_Events_Archive', 'event_details'), |
|
| 702 | - EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
| 703 | - ); |
|
| 704 | - remove_filter( |
|
| 705 | - 'the_excerpt', |
|
| 706 | - array('EED_Events_Archive', 'event_datetimes'), |
|
| 707 | - EED_Events_Archive::EVENT_DATETIMES_PRIORITY |
|
| 708 | - ); |
|
| 709 | - remove_filter( |
|
| 710 | - 'the_excerpt', |
|
| 711 | - array('EED_Events_Archive', 'event_tickets'), |
|
| 712 | - EED_Events_Archive::EVENT_TICKETS_PRIORITY |
|
| 713 | - ); |
|
| 714 | - remove_filter( |
|
| 715 | - 'the_excerpt', |
|
| 716 | - array('EED_Events_Archive', 'event_venues'), |
|
| 717 | - EED_Events_Archive::EVENT_VENUES_PRIORITY |
|
| 718 | - ); |
|
| 719 | - remove_filter( |
|
| 720 | - 'the_content', |
|
| 721 | - array('EED_Events_Archive', 'event_details'), |
|
| 722 | - EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
| 723 | - ); |
|
| 724 | - remove_filter( |
|
| 725 | - 'the_content', |
|
| 726 | - array('EED_Events_Archive', 'event_datetimes'), |
|
| 727 | - EED_Events_Archive::EVENT_DATETIMES_PRIORITY |
|
| 728 | - ); |
|
| 729 | - remove_filter( |
|
| 730 | - 'the_content', |
|
| 731 | - array('EED_Events_Archive', 'event_tickets'), |
|
| 732 | - EED_Events_Archive::EVENT_TICKETS_PRIORITY |
|
| 733 | - ); |
|
| 734 | - remove_filter( |
|
| 735 | - 'the_content', |
|
| 736 | - array('EED_Events_Archive', 'event_venues'), |
|
| 737 | - EED_Events_Archive::EVENT_VENUES_PRIORITY |
|
| 738 | - ); |
|
| 739 | - // don't display entry meta because the existing theme will take care of that |
|
| 740 | - remove_filter( |
|
| 741 | - 'FHEE__content_espresso_events_details_template__display_entry_meta', |
|
| 742 | - '__return_false' |
|
| 743 | - ); |
|
| 744 | - } |
|
| 745 | - |
|
| 746 | - |
|
| 747 | - /** |
|
| 748 | - * load_event_list_assets |
|
| 749 | - * |
|
| 750 | - * @access public |
|
| 751 | - * @return void |
|
| 752 | - */ |
|
| 753 | - public function load_event_list_assets() |
|
| 754 | - { |
|
| 755 | - do_action('AHEE__EED_Events_Archive__before_load_assets'); |
|
| 756 | - add_filter('FHEE_load_EE_Session', '__return_true'); |
|
| 757 | - add_filter('FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', '__return_true'); |
|
| 758 | - add_action('wp_enqueue_scripts', array($this, 'wp_enqueue_scripts'), 10); |
|
| 759 | - if (EE_Registry::instance()->CFG->map_settings->use_google_maps) { |
|
| 760 | - add_action('wp_enqueue_scripts', array('EEH_Maps', 'espresso_google_map_js'), 11); |
|
| 761 | - } |
|
| 762 | - } |
|
| 763 | - |
|
| 764 | - |
|
| 765 | - /** |
|
| 766 | - * wp_enqueue_scripts |
|
| 767 | - * |
|
| 768 | - * @access public |
|
| 769 | - * @return void |
|
| 770 | - */ |
|
| 771 | - public function wp_enqueue_scripts() |
|
| 772 | - { |
|
| 773 | - // get some style |
|
| 774 | - if (apply_filters('FHEE_enable_default_espresso_css', false)) { |
|
| 775 | - // first check uploads folder |
|
| 776 | - if (EEH_File::is_readable(get_stylesheet_directory() . $this->theme . '/style.css')) { |
|
| 777 | - wp_register_style( |
|
| 778 | - $this->theme, |
|
| 779 | - get_stylesheet_directory_uri() . $this->theme . '/style.css', |
|
| 780 | - array('dashicons', 'espresso_default') |
|
| 781 | - ); |
|
| 782 | - } else { |
|
| 783 | - } |
|
| 784 | - wp_enqueue_style($this->theme); |
|
| 785 | - } |
|
| 786 | - } |
|
| 787 | - |
|
| 788 | - |
|
| 789 | - /** |
|
| 790 | - * template_settings_form |
|
| 791 | - * |
|
| 792 | - * @access public |
|
| 793 | - * @static |
|
| 794 | - * @return string |
|
| 795 | - */ |
|
| 796 | - public static function template_settings_form() |
|
| 797 | - { |
|
| 798 | - $template_settings = EE_Registry::instance()->CFG->template_settings; |
|
| 799 | - $template_settings->EED_Events_Archive = isset($template_settings->EED_Events_Archive) |
|
| 800 | - ? $template_settings->EED_Events_Archive : new EE_Events_Archive_Config(); |
|
| 801 | - $template_settings->EED_Events_Archive = apply_filters( |
|
| 802 | - 'FHEE__EED_Events_Archive__template_settings_form__event_list_config', |
|
| 803 | - $template_settings->EED_Events_Archive |
|
| 804 | - ); |
|
| 805 | - $events_archive_settings = array( |
|
| 806 | - 'display_status_banner' => 0, |
|
| 807 | - 'display_description' => 1, |
|
| 808 | - 'display_ticket_selector' => 0, |
|
| 809 | - 'display_datetimes' => 1, |
|
| 810 | - 'display_venue' => 0, |
|
| 811 | - 'display_expired_events' => 0, |
|
| 812 | - ); |
|
| 813 | - $events_archive_settings = array_merge( |
|
| 814 | - $events_archive_settings, |
|
| 815 | - (array) $template_settings->EED_Events_Archive |
|
| 816 | - ); |
|
| 817 | - EEH_Template::display_template( |
|
| 818 | - EVENTS_ARCHIVE_TEMPLATES_PATH . 'admin-event-list-settings.template.php', |
|
| 819 | - $events_archive_settings |
|
| 820 | - ); |
|
| 821 | - } |
|
| 822 | - |
|
| 823 | - |
|
| 824 | - /** |
|
| 825 | - * update_template_settings |
|
| 826 | - * |
|
| 827 | - * @access public |
|
| 828 | - * @param EE_Template_Config $CFG |
|
| 829 | - * @param EE_Request_Handler $REQ |
|
| 830 | - * @return EE_Template_Config |
|
| 831 | - */ |
|
| 832 | - public static function update_template_settings($CFG, $REQ) |
|
| 833 | - { |
|
| 834 | - $CFG->EED_Events_Archive = new EE_Events_Archive_Config(); |
|
| 835 | - // unless we are resetting the config... |
|
| 836 | - if (! isset($REQ['EED_Events_Archive_reset_event_list_settings']) |
|
| 837 | - || absint($REQ['EED_Events_Archive_reset_event_list_settings']) !== 1 |
|
| 838 | - ) { |
|
| 839 | - $CFG->EED_Events_Archive->display_status_banner = isset($REQ['EED_Events_Archive_display_status_banner']) |
|
| 840 | - ? absint($REQ['EED_Events_Archive_display_status_banner']) : 0; |
|
| 841 | - $CFG->EED_Events_Archive->display_description = isset($REQ['EED_Events_Archive_display_description']) |
|
| 842 | - ? absint($REQ['EED_Events_Archive_display_description']) : 1; |
|
| 843 | - $CFG->EED_Events_Archive->display_ticket_selector = isset($REQ['EED_Events_Archive_display_ticket_selector']) |
|
| 844 | - ? absint($REQ['EED_Events_Archive_display_ticket_selector']) : 0; |
|
| 845 | - $CFG->EED_Events_Archive->display_datetimes = isset($REQ['EED_Events_Archive_display_datetimes']) ? absint( |
|
| 846 | - $REQ['EED_Events_Archive_display_datetimes'] |
|
| 847 | - ) : 1; |
|
| 848 | - $CFG->EED_Events_Archive->display_venue = isset($REQ['EED_Events_Archive_display_venue']) ? absint( |
|
| 849 | - $REQ['EED_Events_Archive_display_venue'] |
|
| 850 | - ) : 0; |
|
| 851 | - $CFG->EED_Events_Archive->display_expired_events = isset($REQ['EED_Events_Archive_display_expired_events']) |
|
| 852 | - ? absint($REQ['EED_Events_Archive_display_expired_events']) : 0; |
|
| 853 | - } |
|
| 854 | - return $CFG; |
|
| 855 | - } |
|
| 856 | - |
|
| 857 | - |
|
| 858 | - /** |
|
| 859 | - * event_list_css |
|
| 860 | - * |
|
| 861 | - * @access public |
|
| 862 | - * @param string $extra_class |
|
| 863 | - * @return string |
|
| 864 | - */ |
|
| 865 | - public static function event_list_css($extra_class = '') |
|
| 866 | - { |
|
| 867 | - $event_list_css = ! empty($extra_class) ? array($extra_class) : array(); |
|
| 868 | - $event_list_css[] = 'espresso-event-list-event'; |
|
| 869 | - return implode(' ', $event_list_css); |
|
| 870 | - } |
|
| 871 | - |
|
| 872 | - |
|
| 873 | - /** |
|
| 874 | - * event_categories |
|
| 875 | - * |
|
| 876 | - * @access public |
|
| 877 | - * @return array |
|
| 878 | - */ |
|
| 879 | - public static function event_categories() |
|
| 880 | - { |
|
| 881 | - return EE_Registry::instance()->load_model('Term')->get_all_ee_categories(); |
|
| 882 | - } |
|
| 883 | - |
|
| 884 | - |
|
| 885 | - /** |
|
| 886 | - * display_description |
|
| 887 | - * |
|
| 888 | - * @access public |
|
| 889 | - * @param $value |
|
| 890 | - * @return bool |
|
| 891 | - */ |
|
| 892 | - public static function display_description($value) |
|
| 893 | - { |
|
| 894 | - $config = EE_Registry::instance()->CFG->template_settings->EED_Events_Archive; |
|
| 895 | - $display_description = isset($config->display_description) ? $config->display_description : 1; |
|
| 896 | - return $display_description === $value ? true : false; |
|
| 897 | - } |
|
| 898 | - |
|
| 899 | - |
|
| 900 | - /** |
|
| 901 | - * display_ticket_selector |
|
| 902 | - * |
|
| 903 | - * @access public |
|
| 904 | - * @return bool |
|
| 905 | - */ |
|
| 906 | - public static function display_ticket_selector() |
|
| 907 | - { |
|
| 908 | - $config = EE_Registry::instance()->CFG->template_settings->EED_Events_Archive; |
|
| 909 | - return isset($config->display_ticket_selector) && $config->display_ticket_selector ? true : false; |
|
| 910 | - } |
|
| 911 | - |
|
| 912 | - |
|
| 913 | - /** |
|
| 914 | - * display_venue |
|
| 915 | - * |
|
| 916 | - * @access public |
|
| 917 | - * @return bool |
|
| 918 | - */ |
|
| 919 | - public static function display_venue() |
|
| 920 | - { |
|
| 921 | - $config = EE_Registry::instance()->CFG->template_settings->EED_Events_Archive; |
|
| 922 | - return isset($config->display_venue) && $config->display_venue && EEH_Venue_View::venue_name() ? true : false; |
|
| 923 | - } |
|
| 924 | - |
|
| 925 | - |
|
| 926 | - /** |
|
| 927 | - * display_datetimes |
|
| 928 | - * |
|
| 929 | - * @access public |
|
| 930 | - * @return bool |
|
| 931 | - */ |
|
| 932 | - public static function display_datetimes() |
|
| 933 | - { |
|
| 934 | - $config = EE_Registry::instance()->CFG->template_settings->EED_Events_Archive; |
|
| 935 | - return isset($config->display_datetimes) && $config->display_datetimes ? true : false; |
|
| 936 | - } |
|
| 937 | - |
|
| 938 | - |
|
| 939 | - /** |
|
| 940 | - * event_list_title |
|
| 941 | - * |
|
| 942 | - * @access public |
|
| 943 | - * @return string |
|
| 944 | - */ |
|
| 945 | - public static function event_list_title() |
|
| 946 | - { |
|
| 947 | - return apply_filters( |
|
| 948 | - 'FHEE__archive_espresso_events_template__upcoming_events_h1', |
|
| 949 | - __('Upcoming Events', 'event_espresso') |
|
| 950 | - ); |
|
| 951 | - } |
|
| 952 | - |
|
| 953 | - |
|
| 954 | - // GRAVEYARD |
|
| 955 | - |
|
| 956 | - |
|
| 957 | - /** |
|
| 958 | - * @since 4.4.0 |
|
| 959 | - */ |
|
| 960 | - public static function _doing_it_wrong_notice($function = '') |
|
| 961 | - { |
|
| 962 | - EE_Error::doing_it_wrong( |
|
| 963 | - __FUNCTION__, |
|
| 964 | - sprintf( |
|
| 965 | - __( |
|
| 966 | - 'EED_Events_Archive::%1$s was moved to EEH_Event_Query::%1$s:%2$sPlease update your existing code because the method it calls will be removed in version %3$s', |
|
| 967 | - 'event_espresso' |
|
| 968 | - ), |
|
| 969 | - $function, |
|
| 970 | - '<br />', |
|
| 971 | - '4.6.0' |
|
| 972 | - ), |
|
| 973 | - '4.4.0' |
|
| 974 | - ); |
|
| 975 | - } |
|
| 976 | - |
|
| 977 | - |
|
| 978 | - /** |
|
| 979 | - * @deprecated |
|
| 980 | - * @since 4.4.0 |
|
| 981 | - */ |
|
| 982 | - public function get_post_data() |
|
| 983 | - { |
|
| 984 | - EEH_Event_Query::set_query_params(); |
|
| 985 | - } |
|
| 986 | - |
|
| 987 | - |
|
| 988 | - /** |
|
| 989 | - * @deprecated |
|
| 990 | - * @since 4.4.0 |
|
| 991 | - */ |
|
| 992 | - public function posts_fields($SQL, WP_Query $wp_query) |
|
| 993 | - { |
|
| 994 | - EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__); |
|
| 995 | - return EEH_Event_Query::posts_fields($SQL, $wp_query); |
|
| 996 | - } |
|
| 997 | - |
|
| 998 | - |
|
| 999 | - /** |
|
| 1000 | - * @deprecated |
|
| 1001 | - * @since 4.4.0 |
|
| 1002 | - */ |
|
| 1003 | - public static function posts_fields_sql_for_orderby($orderby_params = array()) |
|
| 1004 | - { |
|
| 1005 | - EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__); |
|
| 1006 | - return EEH_Event_Query::posts_fields_sql_for_orderby($orderby_params); |
|
| 1007 | - } |
|
| 1008 | - |
|
| 1009 | - |
|
| 1010 | - /** |
|
| 1011 | - * @deprecated |
|
| 1012 | - * @since 4.4.0 |
|
| 1013 | - */ |
|
| 1014 | - public function posts_join($SQL, WP_Query $wp_query) |
|
| 1015 | - { |
|
| 1016 | - EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__); |
|
| 1017 | - return EEH_Event_Query::posts_join($SQL, $wp_query); |
|
| 1018 | - } |
|
| 1019 | - |
|
| 1020 | - |
|
| 1021 | - /** |
|
| 1022 | - * @deprecated |
|
| 1023 | - * @since 4.4.0 |
|
| 1024 | - */ |
|
| 1025 | - public static function posts_join_sql_for_terms($join_terms = null) |
|
| 1026 | - { |
|
| 1027 | - EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__); |
|
| 1028 | - return EEH_Event_Query::posts_join_sql_for_terms($join_terms); |
|
| 1029 | - } |
|
| 1030 | - |
|
| 1031 | - |
|
| 1032 | - /** |
|
| 1033 | - * @deprecated |
|
| 1034 | - * @since 4.4.0 |
|
| 1035 | - */ |
|
| 1036 | - public static function posts_join_for_orderby($orderby_params = array()) |
|
| 1037 | - { |
|
| 1038 | - EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__); |
|
| 1039 | - return EEH_Event_Query::posts_join_for_orderby($orderby_params); |
|
| 1040 | - } |
|
| 1041 | - |
|
| 1042 | - |
|
| 1043 | - /** |
|
| 1044 | - * @deprecated |
|
| 1045 | - * @since 4.4.0 |
|
| 1046 | - */ |
|
| 1047 | - public function posts_where($SQL, WP_Query $wp_query) |
|
| 1048 | - { |
|
| 1049 | - EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__); |
|
| 1050 | - return EEH_Event_Query::posts_where($SQL, $wp_query); |
|
| 1051 | - } |
|
| 1052 | - |
|
| 1053 | - |
|
| 1054 | - /** |
|
| 1055 | - * @deprecated |
|
| 1056 | - * @since 4.4.0 |
|
| 1057 | - */ |
|
| 1058 | - public static function posts_where_sql_for_show_expired($show_expired = false) |
|
| 1059 | - { |
|
| 1060 | - EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__); |
|
| 1061 | - return EEH_Event_Query::posts_where_sql_for_show_expired($show_expired); |
|
| 1062 | - } |
|
| 1063 | - |
|
| 1064 | - |
|
| 1065 | - /** |
|
| 1066 | - * @deprecated |
|
| 1067 | - * @since 4.4.0 |
|
| 1068 | - */ |
|
| 1069 | - public static function posts_where_sql_for_event_category_slug($event_category_slug = null) |
|
| 1070 | - { |
|
| 1071 | - EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__); |
|
| 1072 | - return EEH_Event_Query::posts_where_sql_for_event_category_slug($event_category_slug); |
|
| 1073 | - } |
|
| 1074 | - |
|
| 1075 | - |
|
| 1076 | - /** |
|
| 1077 | - * @deprecated |
|
| 1078 | - * @since 4.4.0 |
|
| 1079 | - */ |
|
| 1080 | - public static function posts_where_sql_for_event_list_month($month = null) |
|
| 1081 | - { |
|
| 1082 | - EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__); |
|
| 1083 | - return EEH_Event_Query::posts_where_sql_for_event_list_month($month); |
|
| 1084 | - } |
|
| 1085 | - |
|
| 1086 | - |
|
| 1087 | - /** |
|
| 1088 | - * @deprecated |
|
| 1089 | - * @since 4.4.0 |
|
| 1090 | - */ |
|
| 1091 | - public function posts_orderby($SQL, WP_Query $wp_query) |
|
| 1092 | - { |
|
| 1093 | - EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__); |
|
| 1094 | - return EEH_Event_Query::posts_orderby($SQL, $wp_query); |
|
| 1095 | - } |
|
| 1096 | - |
|
| 1097 | - |
|
| 1098 | - /** |
|
| 1099 | - * @deprecated |
|
| 1100 | - * @since 4.4.0 |
|
| 1101 | - */ |
|
| 1102 | - public static function posts_orderby_sql($orderby_params = array(), $sort = 'ASC') |
|
| 1103 | - { |
|
| 1104 | - EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__); |
|
| 1105 | - return EEH_Event_Query::posts_orderby_sql($orderby_params, $sort); |
|
| 1106 | - } |
|
| 19 | + const EVENT_DETAILS_PRIORITY = 100; |
|
| 20 | + |
|
| 21 | + const EVENT_DATETIMES_PRIORITY = 110; |
|
| 22 | + |
|
| 23 | + const EVENT_TICKETS_PRIORITY = 120; |
|
| 24 | + |
|
| 25 | + const EVENT_VENUES_PRIORITY = 130; |
|
| 26 | + |
|
| 27 | + |
|
| 28 | + public static $espresso_event_list_ID = 0; |
|
| 29 | + |
|
| 30 | + public static $espresso_grid_event_lists = array(); |
|
| 31 | + |
|
| 32 | + /** |
|
| 33 | + * @type bool $using_get_the_excerpt |
|
| 34 | + */ |
|
| 35 | + protected static $using_get_the_excerpt = false; |
|
| 36 | + |
|
| 37 | + /** |
|
| 38 | + * Used to flag when the event list is being called from an external iframe. |
|
| 39 | + * |
|
| 40 | + * @var bool $iframe |
|
| 41 | + */ |
|
| 42 | + protected static $iframe = false; |
|
| 43 | + |
|
| 44 | + /** |
|
| 45 | + * @var \EventEspresso\core\libraries\iframe_display\EventListIframeEmbedButton $_iframe_embed_button |
|
| 46 | + */ |
|
| 47 | + private static $_iframe_embed_button; |
|
| 48 | + |
|
| 49 | + /** |
|
| 50 | + * @type EE_Template_Part_Manager $template_parts |
|
| 51 | + */ |
|
| 52 | + protected $template_parts; |
|
| 53 | + |
|
| 54 | + |
|
| 55 | + /** |
|
| 56 | + * @return EED_Events_Archive |
|
| 57 | + */ |
|
| 58 | + public static function instance() |
|
| 59 | + { |
|
| 60 | + return parent::get_instance(__CLASS__); |
|
| 61 | + } |
|
| 62 | + |
|
| 63 | + |
|
| 64 | + /** |
|
| 65 | + * set_hooks - for hooking into EE Core, other modules, etc |
|
| 66 | + * |
|
| 67 | + * @return void |
|
| 68 | + * @throws InvalidArgumentException |
|
| 69 | + * @throws InvalidDataTypeException |
|
| 70 | + * @throws InvalidInterfaceException |
|
| 71 | + */ |
|
| 72 | + public static function set_hooks() |
|
| 73 | + { |
|
| 74 | + /** @var EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions $custom_post_type_definitions */ |
|
| 75 | + $custom_post_type_definitions = LoaderFactory::getLoader()->getShared( |
|
| 76 | + 'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' |
|
| 77 | + ); |
|
| 78 | + $custom_post_types = $custom_post_type_definitions->getDefinitions(); |
|
| 79 | + EE_Config::register_route( |
|
| 80 | + $custom_post_types['espresso_events']['plural_slug'], |
|
| 81 | + 'Events_Archive', |
|
| 82 | + 'run' |
|
| 83 | + ); |
|
| 84 | + EE_Config::register_route( |
|
| 85 | + 'event_list', |
|
| 86 | + 'Events_Archive', |
|
| 87 | + 'event_list' |
|
| 88 | + ); |
|
| 89 | + EE_Config::register_route( |
|
| 90 | + 'iframe', |
|
| 91 | + 'Events_Archive', |
|
| 92 | + 'event_list_iframe', |
|
| 93 | + 'event_list' |
|
| 94 | + ); |
|
| 95 | + add_action('wp_loaded', array('EED_Events_Archive', 'set_definitions'), 2); |
|
| 96 | + } |
|
| 97 | + |
|
| 98 | + |
|
| 99 | + /** |
|
| 100 | + * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
| 101 | + * |
|
| 102 | + * @access public |
|
| 103 | + * @return void |
|
| 104 | + */ |
|
| 105 | + public static function set_hooks_admin() |
|
| 106 | + { |
|
| 107 | + add_action('wp_loaded', array('EED_Events_Archive', 'set_definitions'), 2); |
|
| 108 | + // hook into the end of the \EE_Admin_Page::_load_page_dependencies() |
|
| 109 | + // to load assets for "espresso_events" page on the "default" route (action) |
|
| 110 | + add_action( |
|
| 111 | + 'FHEE__EE_Admin_Page___load_page_dependencies__after_load__espresso_events__default', |
|
| 112 | + array('EED_Events_Archive', 'event_list_iframe_embed_button'), |
|
| 113 | + 10 |
|
| 114 | + ); |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + |
|
| 118 | + /** |
|
| 119 | + * set_definitions |
|
| 120 | + * |
|
| 121 | + * @access public |
|
| 122 | + * @return void |
|
| 123 | + */ |
|
| 124 | + public static function set_definitions() |
|
| 125 | + { |
|
| 126 | + define('EVENTS_ARCHIVE_ASSETS_URL', plugin_dir_url(__FILE__) . 'assets/'); |
|
| 127 | + define('EVENTS_ARCHIVE_TEMPLATES_PATH', str_replace('\\', '/', plugin_dir_path(__FILE__)) . 'templates/'); |
|
| 128 | + } |
|
| 129 | + |
|
| 130 | + |
|
| 131 | + /** |
|
| 132 | + * set up EE_Events_Archive_Config |
|
| 133 | + */ |
|
| 134 | + protected function set_config() |
|
| 135 | + { |
|
| 136 | + $this->set_config_section('template_settings'); |
|
| 137 | + $this->set_config_class('EE_Events_Archive_Config'); |
|
| 138 | + $this->set_config_name('EED_Events_Archive'); |
|
| 139 | + } |
|
| 140 | + |
|
| 141 | + |
|
| 142 | + /** |
|
| 143 | + * @return EventListIframeEmbedButton |
|
| 144 | + */ |
|
| 145 | + public static function get_iframe_embed_button() |
|
| 146 | + { |
|
| 147 | + if (! self::$_iframe_embed_button instanceof EventListIframeEmbedButton) { |
|
| 148 | + self::$_iframe_embed_button = new EventListIframeEmbedButton(); |
|
| 149 | + } |
|
| 150 | + return self::$_iframe_embed_button; |
|
| 151 | + } |
|
| 152 | + |
|
| 153 | + |
|
| 154 | + /** |
|
| 155 | + * event_list_iframe_embed_button |
|
| 156 | + * |
|
| 157 | + * @return void |
|
| 158 | + * @throws \EE_Error |
|
| 159 | + */ |
|
| 160 | + public static function event_list_iframe_embed_button() |
|
| 161 | + { |
|
| 162 | + $iframe_embed_button = \EED_Events_Archive::get_iframe_embed_button(); |
|
| 163 | + $iframe_embed_button->addEmbedButton(); |
|
| 164 | + } |
|
| 165 | + |
|
| 166 | + |
|
| 167 | + /** |
|
| 168 | + * initialize_template_parts |
|
| 169 | + * |
|
| 170 | + * @access public |
|
| 171 | + * @param \EE_Events_Archive_Config $config |
|
| 172 | + * @return \EE_Template_Part_Manager |
|
| 173 | + */ |
|
| 174 | + public function initialize_template_parts(EE_Events_Archive_Config $config = null) |
|
| 175 | + { |
|
| 176 | + $config = $config instanceof EE_Events_Archive_Config ? $config : $this->config(); |
|
| 177 | + EEH_Autoloader::instance()->register_template_part_autoloaders(); |
|
| 178 | + $template_parts = new EE_Template_Part_Manager(); |
|
| 179 | + $template_parts->add_template_part( |
|
| 180 | + 'tickets', |
|
| 181 | + __('Ticket Selector', 'event_espresso'), |
|
| 182 | + 'content-espresso_events-tickets.php', |
|
| 183 | + $config->display_order_tickets |
|
| 184 | + ); |
|
| 185 | + $template_parts->add_template_part( |
|
| 186 | + 'datetimes', |
|
| 187 | + __('Dates and Times', 'event_espresso'), |
|
| 188 | + 'content-espresso_events-datetimes.php', |
|
| 189 | + $config->display_order_datetimes |
|
| 190 | + ); |
|
| 191 | + $template_parts->add_template_part( |
|
| 192 | + 'event', |
|
| 193 | + __('Event Description', 'event_espresso'), |
|
| 194 | + 'content-espresso_events-details.php', |
|
| 195 | + $config->display_order_event |
|
| 196 | + ); |
|
| 197 | + $template_parts->add_template_part( |
|
| 198 | + 'venue', |
|
| 199 | + __('Venue Information', 'event_espresso'), |
|
| 200 | + 'content-espresso_events-venues.php', |
|
| 201 | + $config->display_order_venue |
|
| 202 | + ); |
|
| 203 | + do_action('AHEE__EED_Event_Archive__initialize_template_parts', $template_parts); |
|
| 204 | + return $template_parts; |
|
| 205 | + } |
|
| 206 | + |
|
| 207 | + |
|
| 208 | + /** |
|
| 209 | + * run - initial module setup - this gets called by the EE_Front_Controller if the module route is found in the |
|
| 210 | + * incoming request |
|
| 211 | + * |
|
| 212 | + * @access public |
|
| 213 | + * @param WP $WP |
|
| 214 | + * @return void |
|
| 215 | + */ |
|
| 216 | + public function run($WP) |
|
| 217 | + { |
|
| 218 | + do_action('AHEE__EED_Events_Archive__before_run'); |
|
| 219 | + // ensure valid EE_Events_Archive_Config() object exists |
|
| 220 | + $this->set_config(); |
|
| 221 | + /** @type EE_Events_Archive_Config $config */ |
|
| 222 | + $config = $this->config(); |
|
| 223 | + // load other required components |
|
| 224 | + $this->load_event_list_assets(); |
|
| 225 | + // filter the WP posts_join, posts_where, and posts_orderby SQL clauses |
|
| 226 | + // add query filters |
|
| 227 | + EEH_Event_Query::add_query_filters(); |
|
| 228 | + // set params that will get used by the filters |
|
| 229 | + EEH_Event_Query::set_query_params( |
|
| 230 | + '', // month |
|
| 231 | + '', // category |
|
| 232 | + $config->display_expired_events, // show_expired |
|
| 233 | + 'start_date', // orderby |
|
| 234 | + 'ASC' // sort |
|
| 235 | + ); |
|
| 236 | + // check what template is loaded |
|
| 237 | + add_filter('template_include', array($this, 'template_include'), 999, 1); |
|
| 238 | + } |
|
| 239 | + |
|
| 240 | + |
|
| 241 | + /** |
|
| 242 | + * most likely called by the ESPRESSO_EVENTS shortcode which uses this module to do some of it's lifting |
|
| 243 | + * |
|
| 244 | + * @return void |
|
| 245 | + */ |
|
| 246 | + public function event_list() |
|
| 247 | + { |
|
| 248 | + // ensure valid EE_Events_Archive_Config() object exists |
|
| 249 | + $this->set_config(); |
|
| 250 | + // load other required components |
|
| 251 | + $this->load_event_list_assets(); |
|
| 252 | + } |
|
| 253 | + |
|
| 254 | + |
|
| 255 | + /** |
|
| 256 | + * @access public |
|
| 257 | + * @return void |
|
| 258 | + * @throws \EE_Error |
|
| 259 | + * @throws \DomainException |
|
| 260 | + */ |
|
| 261 | + public function event_list_iframe() |
|
| 262 | + { |
|
| 263 | + \EED_Events_Archive::$iframe = true; |
|
| 264 | + $event_list_iframe = new EventsArchiveIframe($this); |
|
| 265 | + $event_list_iframe->display(); |
|
| 266 | + } |
|
| 267 | + |
|
| 268 | + |
|
| 269 | + /** |
|
| 270 | + * @access public |
|
| 271 | + * @return string |
|
| 272 | + */ |
|
| 273 | + public static function is_iframe() |
|
| 274 | + { |
|
| 275 | + return \EED_Events_Archive::$iframe; |
|
| 276 | + } |
|
| 277 | + |
|
| 278 | + |
|
| 279 | + /** |
|
| 280 | + * @access public |
|
| 281 | + * @return string |
|
| 282 | + */ |
|
| 283 | + public static function link_target() |
|
| 284 | + { |
|
| 285 | + return \EED_Events_Archive::$iframe ? ' target="_blank"' : ''; |
|
| 286 | + } |
|
| 287 | + |
|
| 288 | + |
|
| 289 | + /** |
|
| 290 | + * template_include |
|
| 291 | + * |
|
| 292 | + * @access public |
|
| 293 | + * @param string $template |
|
| 294 | + * @return string |
|
| 295 | + */ |
|
| 296 | + public function template_include($template = '') |
|
| 297 | + { |
|
| 298 | + // don't add content filter for dedicated EE child themes or private posts |
|
| 299 | + if (! EEH_Template::is_espresso_theme()) { |
|
| 300 | + /** @type EE_Events_Archive_Config $config */ |
|
| 301 | + $config = $this->config(); |
|
| 302 | + // add status banner ? |
|
| 303 | + if ($config->display_status_banner) { |
|
| 304 | + add_filter('the_title', array('EED_Events_Archive', 'the_title'), 100, 2); |
|
| 305 | + } |
|
| 306 | + // if NOT a custom template |
|
| 307 | + if (apply_filters('FHEE__EED_Event_Archive__template_include__allow_custom_selected_template', false) |
|
| 308 | + || EE_Registry::instance() |
|
| 309 | + ->load_core('Front_Controller') |
|
| 310 | + ->get_selected_template() !== 'archive-espresso_events.php' |
|
| 311 | + ) { |
|
| 312 | + // don't display entry meta because the existing theme will take care of that |
|
| 313 | + add_filter('FHEE__EED_Events_Archive__template_include__events_list_active', '__return_true'); |
|
| 314 | + // load functions.php file for the theme (loaded by WP if using child theme) |
|
| 315 | + EEH_Template::load_espresso_theme_functions(); |
|
| 316 | + // because we don't know if the theme is using the_excerpt() |
|
| 317 | + add_filter( |
|
| 318 | + 'the_excerpt', |
|
| 319 | + array('EED_Events_Archive', 'event_details'), |
|
| 320 | + EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
| 321 | + ); |
|
| 322 | + // or the_content |
|
| 323 | + add_filter( |
|
| 324 | + 'the_content', |
|
| 325 | + array('EED_Events_Archive', 'event_details'), |
|
| 326 | + EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
| 327 | + ); |
|
| 328 | + // and just in case they are running get_the_excerpt() which DESTROYS things |
|
| 329 | + add_filter('get_the_excerpt', array('EED_Events_Archive', 'get_the_excerpt'), 1, 1); |
|
| 330 | + // don't display entry meta because the existing theme will take care of that |
|
| 331 | + add_filter('FHEE__content_espresso_events_details_template__display_entry_meta', '__return_false'); |
|
| 332 | + } |
|
| 333 | + } |
|
| 334 | + return $template; |
|
| 335 | + } |
|
| 336 | + |
|
| 337 | + |
|
| 338 | + /** |
|
| 339 | + * get_the_excerpt - kinda hacky, but if a theme is using get_the_excerpt(), then we need to remove our filters |
|
| 340 | + * on the_content() |
|
| 341 | + * |
|
| 342 | + * @access public |
|
| 343 | + * @param string $excerpt |
|
| 344 | + * @return string |
|
| 345 | + */ |
|
| 346 | + public static function get_the_excerpt($excerpt = '') |
|
| 347 | + { |
|
| 348 | + if (post_password_required()) { |
|
| 349 | + return $excerpt; |
|
| 350 | + } |
|
| 351 | + if (apply_filters('FHEE__EED_Events_Archive__get_the_excerpt__theme_uses_get_the_excerpt', false)) { |
|
| 352 | + remove_filter( |
|
| 353 | + 'the_excerpt', |
|
| 354 | + array('EED_Events_Archive', 'event_details'), |
|
| 355 | + EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
| 356 | + ); |
|
| 357 | + remove_filter( |
|
| 358 | + 'the_content', |
|
| 359 | + array('EED_Events_Archive', 'event_details'), |
|
| 360 | + EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
| 361 | + ); |
|
| 362 | + $excerpt = EED_Events_Archive::event_details($excerpt); |
|
| 363 | + } else { |
|
| 364 | + EED_Events_Archive::$using_get_the_excerpt = true; |
|
| 365 | + add_filter('wp_trim_excerpt', array('EED_Events_Archive', 'end_get_the_excerpt'), 999, 1); |
|
| 366 | + } |
|
| 367 | + return $excerpt; |
|
| 368 | + } |
|
| 369 | + |
|
| 370 | + |
|
| 371 | + /** |
|
| 372 | + * end_get_the_excerpt |
|
| 373 | + * |
|
| 374 | + * @access public |
|
| 375 | + * @param string $text |
|
| 376 | + * @return string |
|
| 377 | + */ |
|
| 378 | + public static function end_get_the_excerpt($text = '') |
|
| 379 | + { |
|
| 380 | + EED_Events_Archive::$using_get_the_excerpt = false; |
|
| 381 | + return $text; |
|
| 382 | + } |
|
| 383 | + |
|
| 384 | + |
|
| 385 | + /** |
|
| 386 | + * the_title |
|
| 387 | + * |
|
| 388 | + * @access public |
|
| 389 | + * @param string $title |
|
| 390 | + * @param string $id |
|
| 391 | + * @return string |
|
| 392 | + */ |
|
| 393 | + public static function the_title($title = '', $id = '') |
|
| 394 | + { |
|
| 395 | + global $post; |
|
| 396 | + if ($post instanceof WP_Post) { |
|
| 397 | + return in_the_loop() && $post->ID == $id ? espresso_event_status_banner($post->ID) . $title : $title; |
|
| 398 | + } |
|
| 399 | + return $title; |
|
| 400 | + } |
|
| 401 | + |
|
| 402 | + |
|
| 403 | + /** |
|
| 404 | + * event_details |
|
| 405 | + * |
|
| 406 | + * @access public |
|
| 407 | + * @param string $content |
|
| 408 | + * @return string |
|
| 409 | + */ |
|
| 410 | + public static function event_details($content) |
|
| 411 | + { |
|
| 412 | + global $post; |
|
| 413 | + static $current_post_ID = 0; |
|
| 414 | + if ($current_post_ID !== $post->ID |
|
| 415 | + && $post->post_type === 'espresso_events' |
|
| 416 | + && ! EED_Events_Archive::$using_get_the_excerpt |
|
| 417 | + && ! post_password_required() |
|
| 418 | + && ( |
|
| 419 | + apply_filters('FHEE__EES_Espresso_Events__process_shortcode__true', false) |
|
| 420 | + || ! apply_filters('FHEE__content_espresso_events__template_loaded', false) |
|
| 421 | + ) |
|
| 422 | + ) { |
|
| 423 | + // Set current post ID to prevent showing content twice, but only if headers have definitely been sent. |
|
| 424 | + // Reason being is that some plugins, like Yoast, need to run through a copy of the loop early |
|
| 425 | + // BEFORE headers are sent in order to examine the post content and generate content for the HTML header. |
|
| 426 | + // We want to allow those plugins to still do their thing and have access to our content, but depending on |
|
| 427 | + // how your event content is being displayed (shortcode, CPT route, etc), this filter can get applied twice, |
|
| 428 | + // so the following allows this filter to be applied multiple times, but only once for real |
|
| 429 | + $current_post_ID = did_action('loop_start') ? $post->ID : 0; |
|
| 430 | + if (EE_Registry::instance()->CFG->template_settings->EED_Events_Archive->use_sortable_display_order) { |
|
| 431 | + $content = \EED_Events_Archive::use_sortable_display_order(); |
|
| 432 | + } else { |
|
| 433 | + $content = \EED_Events_Archive::use_filterable_display_order(); |
|
| 434 | + } |
|
| 435 | + } |
|
| 436 | + return $content; |
|
| 437 | + } |
|
| 438 | + |
|
| 439 | + |
|
| 440 | + /** |
|
| 441 | + * use_sortable_display_order |
|
| 442 | + * |
|
| 443 | + * @access protected |
|
| 444 | + * @return string |
|
| 445 | + */ |
|
| 446 | + protected static function use_sortable_display_order() |
|
| 447 | + { |
|
| 448 | + // no further password checks required atm |
|
| 449 | + add_filter('FHEE__EED_Events_Archive__event_details__no_post_password_required', '__return_true'); |
|
| 450 | + // we need to first remove this callback from being applied to the_content() or the_excerpt() |
|
| 451 | + // (otherwise it will recurse and blow up the interweb) |
|
| 452 | + remove_filter( |
|
| 453 | + 'the_excerpt', |
|
| 454 | + array('EED_Events_Archive', 'event_details'), |
|
| 455 | + EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
| 456 | + ); |
|
| 457 | + remove_filter( |
|
| 458 | + 'the_content', |
|
| 459 | + array('EED_Events_Archive', 'event_details'), |
|
| 460 | + EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
| 461 | + ); |
|
| 462 | + remove_filter('get_the_excerpt', array('EED_Events_Archive', 'get_the_excerpt'), 1); |
|
| 463 | + // now add additional content depending on whether event is using the_excerpt() or the_content() |
|
| 464 | + EED_Events_Archive::instance()->template_parts = EED_Events_Archive::instance()->initialize_template_parts(); |
|
| 465 | + $content = EEH_Template::locate_template('content-espresso_events-details.php'); |
|
| 466 | + $content = EED_Events_Archive::instance()->template_parts->apply_template_part_filters($content); |
|
| 467 | + // re-add our main filters (or else the next event won't have them) |
|
| 468 | + add_filter( |
|
| 469 | + 'the_excerpt', |
|
| 470 | + array('EED_Events_Archive', 'event_details'), |
|
| 471 | + EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
| 472 | + ); |
|
| 473 | + add_filter( |
|
| 474 | + 'the_content', |
|
| 475 | + array('EED_Events_Archive', 'event_details'), |
|
| 476 | + EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
| 477 | + ); |
|
| 478 | + add_filter('get_the_excerpt', array('EED_Events_Archive', 'get_the_excerpt'), 1, 1); |
|
| 479 | + remove_filter( |
|
| 480 | + 'FHEE__EED_Events_Archive__event_details__no_post_password_required', |
|
| 481 | + '__return_true' |
|
| 482 | + ); |
|
| 483 | + return $content; |
|
| 484 | + } |
|
| 485 | + |
|
| 486 | + |
|
| 487 | + /** |
|
| 488 | + * use_filterable_display_order |
|
| 489 | + * |
|
| 490 | + * @access protected |
|
| 491 | + * @return string |
|
| 492 | + */ |
|
| 493 | + protected static function use_filterable_display_order() |
|
| 494 | + { |
|
| 495 | + // we need to first remove this callback from being applied to the_content() |
|
| 496 | + // (otherwise it will recurse and blow up the interweb) |
|
| 497 | + remove_filter( |
|
| 498 | + 'the_excerpt', |
|
| 499 | + array('EED_Events_Archive', 'event_details'), |
|
| 500 | + EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
| 501 | + ); |
|
| 502 | + remove_filter( |
|
| 503 | + 'the_content', |
|
| 504 | + array('EED_Events_Archive', 'event_details'), |
|
| 505 | + EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
| 506 | + ); |
|
| 507 | + remove_filter('get_the_excerpt', array('EED_Events_Archive', 'get_the_excerpt'), 1); |
|
| 508 | + // now add additional content depending on whether event is using the_excerpt() or the_content() |
|
| 509 | + EED_Events_Archive::_add_additional_excerpt_filters(); |
|
| 510 | + EED_Events_Archive::_add_additional_content_filters(); |
|
| 511 | + do_action('AHEE__EED_Events_Archive__use_filterable_display_order__after_add_filters'); |
|
| 512 | + // now load our template |
|
| 513 | + $content = EEH_Template::locate_template('content-espresso_events-details.php'); |
|
| 514 | + // re-add our main filters (or else the next event won't have them) |
|
| 515 | + add_filter( |
|
| 516 | + 'the_excerpt', |
|
| 517 | + array('EED_Events_Archive', 'event_details'), |
|
| 518 | + EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
| 519 | + ); |
|
| 520 | + add_filter( |
|
| 521 | + 'the_content', |
|
| 522 | + array('EED_Events_Archive', 'event_details'), |
|
| 523 | + EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
| 524 | + ); |
|
| 525 | + add_filter('get_the_excerpt', array('EED_Events_Archive', 'get_the_excerpt'), 1, 1); |
|
| 526 | + // but remove the other filters so that they don't get applied to the next post |
|
| 527 | + EED_Events_Archive::_remove_additional_events_archive_filters(); |
|
| 528 | + do_action('AHEE__EED_Events_Archive__use_filterable_display_order__after_remove_filters'); |
|
| 529 | + // we're not returning the $content directly because the template we are loading uses the_content (or the_excerpt) |
|
| 530 | + // return ! empty( $template ) ? $template : $content; |
|
| 531 | + return $content; |
|
| 532 | + } |
|
| 533 | + |
|
| 534 | + |
|
| 535 | + /** |
|
| 536 | + * event_datetimes - adds datetimes ABOVE content |
|
| 537 | + * |
|
| 538 | + * @access public |
|
| 539 | + * @param string $content |
|
| 540 | + * @return string |
|
| 541 | + */ |
|
| 542 | + public static function event_datetimes($content) |
|
| 543 | + { |
|
| 544 | + if (post_password_required()) { |
|
| 545 | + return $content; |
|
| 546 | + } |
|
| 547 | + return EEH_Template::locate_template('content-espresso_events-datetimes.php') . $content; |
|
| 548 | + } |
|
| 549 | + |
|
| 550 | + |
|
| 551 | + /** |
|
| 552 | + * event_tickets - adds tickets ABOVE content (which includes datetimes) |
|
| 553 | + * |
|
| 554 | + * @access public |
|
| 555 | + * @param string $content |
|
| 556 | + * @return string |
|
| 557 | + */ |
|
| 558 | + public static function event_tickets($content) |
|
| 559 | + { |
|
| 560 | + if (post_password_required()) { |
|
| 561 | + return $content; |
|
| 562 | + } |
|
| 563 | + return EEH_Template::locate_template('content-espresso_events-tickets.php') . $content; |
|
| 564 | + } |
|
| 565 | + |
|
| 566 | + |
|
| 567 | + /** |
|
| 568 | + * event_venues - adds venues BELOW content |
|
| 569 | + * |
|
| 570 | + * @access public |
|
| 571 | + * @param string $content |
|
| 572 | + * @return string |
|
| 573 | + */ |
|
| 574 | + public static function event_venue($content) |
|
| 575 | + { |
|
| 576 | + return EED_Events_Archive::event_venues($content); |
|
| 577 | + } |
|
| 578 | + |
|
| 579 | + |
|
| 580 | + /** |
|
| 581 | + * event_venues - adds venues BELOW content |
|
| 582 | + * |
|
| 583 | + * @access public |
|
| 584 | + * @param string $content |
|
| 585 | + * @return string |
|
| 586 | + */ |
|
| 587 | + public static function event_venues($content) |
|
| 588 | + { |
|
| 589 | + if (post_password_required()) { |
|
| 590 | + return $content; |
|
| 591 | + } |
|
| 592 | + return $content . EEH_Template::locate_template('content-espresso_events-venues.php'); |
|
| 593 | + } |
|
| 594 | + |
|
| 595 | + |
|
| 596 | + /** |
|
| 597 | + * _add_additional_content_filters |
|
| 598 | + * |
|
| 599 | + * @access private |
|
| 600 | + * @return void |
|
| 601 | + */ |
|
| 602 | + private static function _add_additional_excerpt_filters() |
|
| 603 | + { |
|
| 604 | + add_filter( |
|
| 605 | + 'the_excerpt', |
|
| 606 | + array('EED_Events_Archive', 'event_datetimes'), |
|
| 607 | + EED_Events_Archive::EVENT_DATETIMES_PRIORITY |
|
| 608 | + ); |
|
| 609 | + add_filter( |
|
| 610 | + 'the_excerpt', |
|
| 611 | + array('EED_Events_Archive', 'event_tickets'), |
|
| 612 | + EED_Events_Archive::EVENT_TICKETS_PRIORITY |
|
| 613 | + ); |
|
| 614 | + add_filter( |
|
| 615 | + 'the_excerpt', |
|
| 616 | + array('EED_Events_Archive', 'event_venues'), |
|
| 617 | + EED_Events_Archive::EVENT_VENUES_PRIORITY |
|
| 618 | + ); |
|
| 619 | + } |
|
| 620 | + |
|
| 621 | + |
|
| 622 | + /** |
|
| 623 | + * _add_additional_content_filters |
|
| 624 | + * |
|
| 625 | + * @access private |
|
| 626 | + * @return void |
|
| 627 | + */ |
|
| 628 | + private static function _add_additional_content_filters() |
|
| 629 | + { |
|
| 630 | + add_filter( |
|
| 631 | + 'the_content', |
|
| 632 | + array('EED_Events_Archive', 'event_datetimes'), |
|
| 633 | + EED_Events_Archive::EVENT_DATETIMES_PRIORITY |
|
| 634 | + ); |
|
| 635 | + add_filter( |
|
| 636 | + 'the_content', |
|
| 637 | + array('EED_Events_Archive', 'event_tickets'), |
|
| 638 | + EED_Events_Archive::EVENT_TICKETS_PRIORITY |
|
| 639 | + ); |
|
| 640 | + add_filter( |
|
| 641 | + 'the_content', |
|
| 642 | + array('EED_Events_Archive', 'event_venues'), |
|
| 643 | + EED_Events_Archive::EVENT_VENUES_PRIORITY |
|
| 644 | + ); |
|
| 645 | + } |
|
| 646 | + |
|
| 647 | + |
|
| 648 | + /** |
|
| 649 | + * _remove_additional_events_archive_filters |
|
| 650 | + * |
|
| 651 | + * @access private |
|
| 652 | + * @return void |
|
| 653 | + */ |
|
| 654 | + private static function _remove_additional_events_archive_filters() |
|
| 655 | + { |
|
| 656 | + remove_filter( |
|
| 657 | + 'the_excerpt', |
|
| 658 | + array('EED_Events_Archive', 'event_datetimes'), |
|
| 659 | + EED_Events_Archive::EVENT_DATETIMES_PRIORITY |
|
| 660 | + ); |
|
| 661 | + remove_filter( |
|
| 662 | + 'the_excerpt', |
|
| 663 | + array('EED_Events_Archive', 'event_tickets'), |
|
| 664 | + EED_Events_Archive::EVENT_TICKETS_PRIORITY |
|
| 665 | + ); |
|
| 666 | + remove_filter( |
|
| 667 | + 'the_excerpt', |
|
| 668 | + array('EED_Events_Archive', 'event_venues'), |
|
| 669 | + EED_Events_Archive::EVENT_VENUES_PRIORITY |
|
| 670 | + ); |
|
| 671 | + remove_filter( |
|
| 672 | + 'the_content', |
|
| 673 | + array('EED_Events_Archive', 'event_datetimes'), |
|
| 674 | + EED_Events_Archive::EVENT_DATETIMES_PRIORITY |
|
| 675 | + ); |
|
| 676 | + remove_filter( |
|
| 677 | + 'the_content', |
|
| 678 | + array('EED_Events_Archive', 'event_tickets'), |
|
| 679 | + EED_Events_Archive::EVENT_TICKETS_PRIORITY |
|
| 680 | + ); |
|
| 681 | + remove_filter( |
|
| 682 | + 'the_content', |
|
| 683 | + array('EED_Events_Archive', 'event_venues'), |
|
| 684 | + EED_Events_Archive::EVENT_VENUES_PRIORITY |
|
| 685 | + ); |
|
| 686 | + } |
|
| 687 | + |
|
| 688 | + |
|
| 689 | + /** |
|
| 690 | + * remove_all_events_archive_filters |
|
| 691 | + * |
|
| 692 | + * @access public |
|
| 693 | + * @return void |
|
| 694 | + */ |
|
| 695 | + public static function remove_all_events_archive_filters() |
|
| 696 | + { |
|
| 697 | + // remove_filter( 'get_the_excerpt', array( 'EED_Events_Archive', 'get_the_excerpt' ), 1 ); |
|
| 698 | + remove_filter('the_title', array('EED_Events_Archive', 'the_title'), 1); |
|
| 699 | + remove_filter( |
|
| 700 | + 'the_excerpt', |
|
| 701 | + array('EED_Events_Archive', 'event_details'), |
|
| 702 | + EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
| 703 | + ); |
|
| 704 | + remove_filter( |
|
| 705 | + 'the_excerpt', |
|
| 706 | + array('EED_Events_Archive', 'event_datetimes'), |
|
| 707 | + EED_Events_Archive::EVENT_DATETIMES_PRIORITY |
|
| 708 | + ); |
|
| 709 | + remove_filter( |
|
| 710 | + 'the_excerpt', |
|
| 711 | + array('EED_Events_Archive', 'event_tickets'), |
|
| 712 | + EED_Events_Archive::EVENT_TICKETS_PRIORITY |
|
| 713 | + ); |
|
| 714 | + remove_filter( |
|
| 715 | + 'the_excerpt', |
|
| 716 | + array('EED_Events_Archive', 'event_venues'), |
|
| 717 | + EED_Events_Archive::EVENT_VENUES_PRIORITY |
|
| 718 | + ); |
|
| 719 | + remove_filter( |
|
| 720 | + 'the_content', |
|
| 721 | + array('EED_Events_Archive', 'event_details'), |
|
| 722 | + EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
| 723 | + ); |
|
| 724 | + remove_filter( |
|
| 725 | + 'the_content', |
|
| 726 | + array('EED_Events_Archive', 'event_datetimes'), |
|
| 727 | + EED_Events_Archive::EVENT_DATETIMES_PRIORITY |
|
| 728 | + ); |
|
| 729 | + remove_filter( |
|
| 730 | + 'the_content', |
|
| 731 | + array('EED_Events_Archive', 'event_tickets'), |
|
| 732 | + EED_Events_Archive::EVENT_TICKETS_PRIORITY |
|
| 733 | + ); |
|
| 734 | + remove_filter( |
|
| 735 | + 'the_content', |
|
| 736 | + array('EED_Events_Archive', 'event_venues'), |
|
| 737 | + EED_Events_Archive::EVENT_VENUES_PRIORITY |
|
| 738 | + ); |
|
| 739 | + // don't display entry meta because the existing theme will take care of that |
|
| 740 | + remove_filter( |
|
| 741 | + 'FHEE__content_espresso_events_details_template__display_entry_meta', |
|
| 742 | + '__return_false' |
|
| 743 | + ); |
|
| 744 | + } |
|
| 745 | + |
|
| 746 | + |
|
| 747 | + /** |
|
| 748 | + * load_event_list_assets |
|
| 749 | + * |
|
| 750 | + * @access public |
|
| 751 | + * @return void |
|
| 752 | + */ |
|
| 753 | + public function load_event_list_assets() |
|
| 754 | + { |
|
| 755 | + do_action('AHEE__EED_Events_Archive__before_load_assets'); |
|
| 756 | + add_filter('FHEE_load_EE_Session', '__return_true'); |
|
| 757 | + add_filter('FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', '__return_true'); |
|
| 758 | + add_action('wp_enqueue_scripts', array($this, 'wp_enqueue_scripts'), 10); |
|
| 759 | + if (EE_Registry::instance()->CFG->map_settings->use_google_maps) { |
|
| 760 | + add_action('wp_enqueue_scripts', array('EEH_Maps', 'espresso_google_map_js'), 11); |
|
| 761 | + } |
|
| 762 | + } |
|
| 763 | + |
|
| 764 | + |
|
| 765 | + /** |
|
| 766 | + * wp_enqueue_scripts |
|
| 767 | + * |
|
| 768 | + * @access public |
|
| 769 | + * @return void |
|
| 770 | + */ |
|
| 771 | + public function wp_enqueue_scripts() |
|
| 772 | + { |
|
| 773 | + // get some style |
|
| 774 | + if (apply_filters('FHEE_enable_default_espresso_css', false)) { |
|
| 775 | + // first check uploads folder |
|
| 776 | + if (EEH_File::is_readable(get_stylesheet_directory() . $this->theme . '/style.css')) { |
|
| 777 | + wp_register_style( |
|
| 778 | + $this->theme, |
|
| 779 | + get_stylesheet_directory_uri() . $this->theme . '/style.css', |
|
| 780 | + array('dashicons', 'espresso_default') |
|
| 781 | + ); |
|
| 782 | + } else { |
|
| 783 | + } |
|
| 784 | + wp_enqueue_style($this->theme); |
|
| 785 | + } |
|
| 786 | + } |
|
| 787 | + |
|
| 788 | + |
|
| 789 | + /** |
|
| 790 | + * template_settings_form |
|
| 791 | + * |
|
| 792 | + * @access public |
|
| 793 | + * @static |
|
| 794 | + * @return string |
|
| 795 | + */ |
|
| 796 | + public static function template_settings_form() |
|
| 797 | + { |
|
| 798 | + $template_settings = EE_Registry::instance()->CFG->template_settings; |
|
| 799 | + $template_settings->EED_Events_Archive = isset($template_settings->EED_Events_Archive) |
|
| 800 | + ? $template_settings->EED_Events_Archive : new EE_Events_Archive_Config(); |
|
| 801 | + $template_settings->EED_Events_Archive = apply_filters( |
|
| 802 | + 'FHEE__EED_Events_Archive__template_settings_form__event_list_config', |
|
| 803 | + $template_settings->EED_Events_Archive |
|
| 804 | + ); |
|
| 805 | + $events_archive_settings = array( |
|
| 806 | + 'display_status_banner' => 0, |
|
| 807 | + 'display_description' => 1, |
|
| 808 | + 'display_ticket_selector' => 0, |
|
| 809 | + 'display_datetimes' => 1, |
|
| 810 | + 'display_venue' => 0, |
|
| 811 | + 'display_expired_events' => 0, |
|
| 812 | + ); |
|
| 813 | + $events_archive_settings = array_merge( |
|
| 814 | + $events_archive_settings, |
|
| 815 | + (array) $template_settings->EED_Events_Archive |
|
| 816 | + ); |
|
| 817 | + EEH_Template::display_template( |
|
| 818 | + EVENTS_ARCHIVE_TEMPLATES_PATH . 'admin-event-list-settings.template.php', |
|
| 819 | + $events_archive_settings |
|
| 820 | + ); |
|
| 821 | + } |
|
| 822 | + |
|
| 823 | + |
|
| 824 | + /** |
|
| 825 | + * update_template_settings |
|
| 826 | + * |
|
| 827 | + * @access public |
|
| 828 | + * @param EE_Template_Config $CFG |
|
| 829 | + * @param EE_Request_Handler $REQ |
|
| 830 | + * @return EE_Template_Config |
|
| 831 | + */ |
|
| 832 | + public static function update_template_settings($CFG, $REQ) |
|
| 833 | + { |
|
| 834 | + $CFG->EED_Events_Archive = new EE_Events_Archive_Config(); |
|
| 835 | + // unless we are resetting the config... |
|
| 836 | + if (! isset($REQ['EED_Events_Archive_reset_event_list_settings']) |
|
| 837 | + || absint($REQ['EED_Events_Archive_reset_event_list_settings']) !== 1 |
|
| 838 | + ) { |
|
| 839 | + $CFG->EED_Events_Archive->display_status_banner = isset($REQ['EED_Events_Archive_display_status_banner']) |
|
| 840 | + ? absint($REQ['EED_Events_Archive_display_status_banner']) : 0; |
|
| 841 | + $CFG->EED_Events_Archive->display_description = isset($REQ['EED_Events_Archive_display_description']) |
|
| 842 | + ? absint($REQ['EED_Events_Archive_display_description']) : 1; |
|
| 843 | + $CFG->EED_Events_Archive->display_ticket_selector = isset($REQ['EED_Events_Archive_display_ticket_selector']) |
|
| 844 | + ? absint($REQ['EED_Events_Archive_display_ticket_selector']) : 0; |
|
| 845 | + $CFG->EED_Events_Archive->display_datetimes = isset($REQ['EED_Events_Archive_display_datetimes']) ? absint( |
|
| 846 | + $REQ['EED_Events_Archive_display_datetimes'] |
|
| 847 | + ) : 1; |
|
| 848 | + $CFG->EED_Events_Archive->display_venue = isset($REQ['EED_Events_Archive_display_venue']) ? absint( |
|
| 849 | + $REQ['EED_Events_Archive_display_venue'] |
|
| 850 | + ) : 0; |
|
| 851 | + $CFG->EED_Events_Archive->display_expired_events = isset($REQ['EED_Events_Archive_display_expired_events']) |
|
| 852 | + ? absint($REQ['EED_Events_Archive_display_expired_events']) : 0; |
|
| 853 | + } |
|
| 854 | + return $CFG; |
|
| 855 | + } |
|
| 856 | + |
|
| 857 | + |
|
| 858 | + /** |
|
| 859 | + * event_list_css |
|
| 860 | + * |
|
| 861 | + * @access public |
|
| 862 | + * @param string $extra_class |
|
| 863 | + * @return string |
|
| 864 | + */ |
|
| 865 | + public static function event_list_css($extra_class = '') |
|
| 866 | + { |
|
| 867 | + $event_list_css = ! empty($extra_class) ? array($extra_class) : array(); |
|
| 868 | + $event_list_css[] = 'espresso-event-list-event'; |
|
| 869 | + return implode(' ', $event_list_css); |
|
| 870 | + } |
|
| 871 | + |
|
| 872 | + |
|
| 873 | + /** |
|
| 874 | + * event_categories |
|
| 875 | + * |
|
| 876 | + * @access public |
|
| 877 | + * @return array |
|
| 878 | + */ |
|
| 879 | + public static function event_categories() |
|
| 880 | + { |
|
| 881 | + return EE_Registry::instance()->load_model('Term')->get_all_ee_categories(); |
|
| 882 | + } |
|
| 883 | + |
|
| 884 | + |
|
| 885 | + /** |
|
| 886 | + * display_description |
|
| 887 | + * |
|
| 888 | + * @access public |
|
| 889 | + * @param $value |
|
| 890 | + * @return bool |
|
| 891 | + */ |
|
| 892 | + public static function display_description($value) |
|
| 893 | + { |
|
| 894 | + $config = EE_Registry::instance()->CFG->template_settings->EED_Events_Archive; |
|
| 895 | + $display_description = isset($config->display_description) ? $config->display_description : 1; |
|
| 896 | + return $display_description === $value ? true : false; |
|
| 897 | + } |
|
| 898 | + |
|
| 899 | + |
|
| 900 | + /** |
|
| 901 | + * display_ticket_selector |
|
| 902 | + * |
|
| 903 | + * @access public |
|
| 904 | + * @return bool |
|
| 905 | + */ |
|
| 906 | + public static function display_ticket_selector() |
|
| 907 | + { |
|
| 908 | + $config = EE_Registry::instance()->CFG->template_settings->EED_Events_Archive; |
|
| 909 | + return isset($config->display_ticket_selector) && $config->display_ticket_selector ? true : false; |
|
| 910 | + } |
|
| 911 | + |
|
| 912 | + |
|
| 913 | + /** |
|
| 914 | + * display_venue |
|
| 915 | + * |
|
| 916 | + * @access public |
|
| 917 | + * @return bool |
|
| 918 | + */ |
|
| 919 | + public static function display_venue() |
|
| 920 | + { |
|
| 921 | + $config = EE_Registry::instance()->CFG->template_settings->EED_Events_Archive; |
|
| 922 | + return isset($config->display_venue) && $config->display_venue && EEH_Venue_View::venue_name() ? true : false; |
|
| 923 | + } |
|
| 924 | + |
|
| 925 | + |
|
| 926 | + /** |
|
| 927 | + * display_datetimes |
|
| 928 | + * |
|
| 929 | + * @access public |
|
| 930 | + * @return bool |
|
| 931 | + */ |
|
| 932 | + public static function display_datetimes() |
|
| 933 | + { |
|
| 934 | + $config = EE_Registry::instance()->CFG->template_settings->EED_Events_Archive; |
|
| 935 | + return isset($config->display_datetimes) && $config->display_datetimes ? true : false; |
|
| 936 | + } |
|
| 937 | + |
|
| 938 | + |
|
| 939 | + /** |
|
| 940 | + * event_list_title |
|
| 941 | + * |
|
| 942 | + * @access public |
|
| 943 | + * @return string |
|
| 944 | + */ |
|
| 945 | + public static function event_list_title() |
|
| 946 | + { |
|
| 947 | + return apply_filters( |
|
| 948 | + 'FHEE__archive_espresso_events_template__upcoming_events_h1', |
|
| 949 | + __('Upcoming Events', 'event_espresso') |
|
| 950 | + ); |
|
| 951 | + } |
|
| 952 | + |
|
| 953 | + |
|
| 954 | + // GRAVEYARD |
|
| 955 | + |
|
| 956 | + |
|
| 957 | + /** |
|
| 958 | + * @since 4.4.0 |
|
| 959 | + */ |
|
| 960 | + public static function _doing_it_wrong_notice($function = '') |
|
| 961 | + { |
|
| 962 | + EE_Error::doing_it_wrong( |
|
| 963 | + __FUNCTION__, |
|
| 964 | + sprintf( |
|
| 965 | + __( |
|
| 966 | + 'EED_Events_Archive::%1$s was moved to EEH_Event_Query::%1$s:%2$sPlease update your existing code because the method it calls will be removed in version %3$s', |
|
| 967 | + 'event_espresso' |
|
| 968 | + ), |
|
| 969 | + $function, |
|
| 970 | + '<br />', |
|
| 971 | + '4.6.0' |
|
| 972 | + ), |
|
| 973 | + '4.4.0' |
|
| 974 | + ); |
|
| 975 | + } |
|
| 976 | + |
|
| 977 | + |
|
| 978 | + /** |
|
| 979 | + * @deprecated |
|
| 980 | + * @since 4.4.0 |
|
| 981 | + */ |
|
| 982 | + public function get_post_data() |
|
| 983 | + { |
|
| 984 | + EEH_Event_Query::set_query_params(); |
|
| 985 | + } |
|
| 986 | + |
|
| 987 | + |
|
| 988 | + /** |
|
| 989 | + * @deprecated |
|
| 990 | + * @since 4.4.0 |
|
| 991 | + */ |
|
| 992 | + public function posts_fields($SQL, WP_Query $wp_query) |
|
| 993 | + { |
|
| 994 | + EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__); |
|
| 995 | + return EEH_Event_Query::posts_fields($SQL, $wp_query); |
|
| 996 | + } |
|
| 997 | + |
|
| 998 | + |
|
| 999 | + /** |
|
| 1000 | + * @deprecated |
|
| 1001 | + * @since 4.4.0 |
|
| 1002 | + */ |
|
| 1003 | + public static function posts_fields_sql_for_orderby($orderby_params = array()) |
|
| 1004 | + { |
|
| 1005 | + EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__); |
|
| 1006 | + return EEH_Event_Query::posts_fields_sql_for_orderby($orderby_params); |
|
| 1007 | + } |
|
| 1008 | + |
|
| 1009 | + |
|
| 1010 | + /** |
|
| 1011 | + * @deprecated |
|
| 1012 | + * @since 4.4.0 |
|
| 1013 | + */ |
|
| 1014 | + public function posts_join($SQL, WP_Query $wp_query) |
|
| 1015 | + { |
|
| 1016 | + EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__); |
|
| 1017 | + return EEH_Event_Query::posts_join($SQL, $wp_query); |
|
| 1018 | + } |
|
| 1019 | + |
|
| 1020 | + |
|
| 1021 | + /** |
|
| 1022 | + * @deprecated |
|
| 1023 | + * @since 4.4.0 |
|
| 1024 | + */ |
|
| 1025 | + public static function posts_join_sql_for_terms($join_terms = null) |
|
| 1026 | + { |
|
| 1027 | + EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__); |
|
| 1028 | + return EEH_Event_Query::posts_join_sql_for_terms($join_terms); |
|
| 1029 | + } |
|
| 1030 | + |
|
| 1031 | + |
|
| 1032 | + /** |
|
| 1033 | + * @deprecated |
|
| 1034 | + * @since 4.4.0 |
|
| 1035 | + */ |
|
| 1036 | + public static function posts_join_for_orderby($orderby_params = array()) |
|
| 1037 | + { |
|
| 1038 | + EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__); |
|
| 1039 | + return EEH_Event_Query::posts_join_for_orderby($orderby_params); |
|
| 1040 | + } |
|
| 1041 | + |
|
| 1042 | + |
|
| 1043 | + /** |
|
| 1044 | + * @deprecated |
|
| 1045 | + * @since 4.4.0 |
|
| 1046 | + */ |
|
| 1047 | + public function posts_where($SQL, WP_Query $wp_query) |
|
| 1048 | + { |
|
| 1049 | + EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__); |
|
| 1050 | + return EEH_Event_Query::posts_where($SQL, $wp_query); |
|
| 1051 | + } |
|
| 1052 | + |
|
| 1053 | + |
|
| 1054 | + /** |
|
| 1055 | + * @deprecated |
|
| 1056 | + * @since 4.4.0 |
|
| 1057 | + */ |
|
| 1058 | + public static function posts_where_sql_for_show_expired($show_expired = false) |
|
| 1059 | + { |
|
| 1060 | + EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__); |
|
| 1061 | + return EEH_Event_Query::posts_where_sql_for_show_expired($show_expired); |
|
| 1062 | + } |
|
| 1063 | + |
|
| 1064 | + |
|
| 1065 | + /** |
|
| 1066 | + * @deprecated |
|
| 1067 | + * @since 4.4.0 |
|
| 1068 | + */ |
|
| 1069 | + public static function posts_where_sql_for_event_category_slug($event_category_slug = null) |
|
| 1070 | + { |
|
| 1071 | + EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__); |
|
| 1072 | + return EEH_Event_Query::posts_where_sql_for_event_category_slug($event_category_slug); |
|
| 1073 | + } |
|
| 1074 | + |
|
| 1075 | + |
|
| 1076 | + /** |
|
| 1077 | + * @deprecated |
|
| 1078 | + * @since 4.4.0 |
|
| 1079 | + */ |
|
| 1080 | + public static function posts_where_sql_for_event_list_month($month = null) |
|
| 1081 | + { |
|
| 1082 | + EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__); |
|
| 1083 | + return EEH_Event_Query::posts_where_sql_for_event_list_month($month); |
|
| 1084 | + } |
|
| 1085 | + |
|
| 1086 | + |
|
| 1087 | + /** |
|
| 1088 | + * @deprecated |
|
| 1089 | + * @since 4.4.0 |
|
| 1090 | + */ |
|
| 1091 | + public function posts_orderby($SQL, WP_Query $wp_query) |
|
| 1092 | + { |
|
| 1093 | + EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__); |
|
| 1094 | + return EEH_Event_Query::posts_orderby($SQL, $wp_query); |
|
| 1095 | + } |
|
| 1096 | + |
|
| 1097 | + |
|
| 1098 | + /** |
|
| 1099 | + * @deprecated |
|
| 1100 | + * @since 4.4.0 |
|
| 1101 | + */ |
|
| 1102 | + public static function posts_orderby_sql($orderby_params = array(), $sort = 'ASC') |
|
| 1103 | + { |
|
| 1104 | + EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__); |
|
| 1105 | + return EEH_Event_Query::posts_orderby_sql($orderby_params, $sort); |
|
| 1106 | + } |
|
| 1107 | 1107 | } |
| 1108 | 1108 | |
| 1109 | 1109 | |
@@ -1112,9 +1112,9 @@ discard block |
||
| 1112 | 1112 | */ |
| 1113 | 1113 | function espresso_get_event_list_ID() |
| 1114 | 1114 | { |
| 1115 | - EED_Events_Archive::$espresso_event_list_ID++; |
|
| 1116 | - EED_Events_Archive::$espresso_grid_event_lists[] = EED_Events_Archive::$espresso_event_list_ID; |
|
| 1117 | - return EED_Events_Archive::$espresso_event_list_ID; |
|
| 1115 | + EED_Events_Archive::$espresso_event_list_ID++; |
|
| 1116 | + EED_Events_Archive::$espresso_grid_event_lists[] = EED_Events_Archive::$espresso_event_list_ID; |
|
| 1117 | + return EED_Events_Archive::$espresso_event_list_ID; |
|
| 1118 | 1118 | } |
| 1119 | 1119 | |
| 1120 | 1120 | /** |
@@ -1122,7 +1122,7 @@ discard block |
||
| 1122 | 1122 | */ |
| 1123 | 1123 | function espresso_event_list_title() |
| 1124 | 1124 | { |
| 1125 | - return EED_Events_Archive::event_list_title(); |
|
| 1125 | + return EED_Events_Archive::event_list_title(); |
|
| 1126 | 1126 | } |
| 1127 | 1127 | |
| 1128 | 1128 | /** |
@@ -1131,7 +1131,7 @@ discard block |
||
| 1131 | 1131 | */ |
| 1132 | 1132 | function espresso_event_list_css($extra_class = '') |
| 1133 | 1133 | { |
| 1134 | - return EED_Events_Archive::event_list_css($extra_class); |
|
| 1134 | + return EED_Events_Archive::event_list_css($extra_class); |
|
| 1135 | 1135 | } |
| 1136 | 1136 | |
| 1137 | 1137 | /** |
@@ -1139,7 +1139,7 @@ discard block |
||
| 1139 | 1139 | */ |
| 1140 | 1140 | function espresso_get_event_categories() |
| 1141 | 1141 | { |
| 1142 | - return EED_Events_Archive::event_categories(); |
|
| 1142 | + return EED_Events_Archive::event_categories(); |
|
| 1143 | 1143 | } |
| 1144 | 1144 | |
| 1145 | 1145 | /** |
@@ -1147,7 +1147,7 @@ discard block |
||
| 1147 | 1147 | */ |
| 1148 | 1148 | function espresso_display_full_description_in_event_list() |
| 1149 | 1149 | { |
| 1150 | - return EED_Events_Archive::display_description(2); |
|
| 1150 | + return EED_Events_Archive::display_description(2); |
|
| 1151 | 1151 | } |
| 1152 | 1152 | |
| 1153 | 1153 | /** |
@@ -1155,7 +1155,7 @@ discard block |
||
| 1155 | 1155 | */ |
| 1156 | 1156 | function espresso_display_excerpt_in_event_list() |
| 1157 | 1157 | { |
| 1158 | - return EED_Events_Archive::display_description(1); |
|
| 1158 | + return EED_Events_Archive::display_description(1); |
|
| 1159 | 1159 | } |
| 1160 | 1160 | |
| 1161 | 1161 | /** |
@@ -1163,7 +1163,7 @@ discard block |
||
| 1163 | 1163 | */ |
| 1164 | 1164 | function espresso_display_ticket_selector_in_event_list() |
| 1165 | 1165 | { |
| 1166 | - return EED_Events_Archive::display_ticket_selector(); |
|
| 1166 | + return EED_Events_Archive::display_ticket_selector(); |
|
| 1167 | 1167 | } |
| 1168 | 1168 | |
| 1169 | 1169 | /** |
@@ -1171,7 +1171,7 @@ discard block |
||
| 1171 | 1171 | */ |
| 1172 | 1172 | function espresso_display_venue_in_event_list() |
| 1173 | 1173 | { |
| 1174 | - return EED_Events_Archive::display_venue(); |
|
| 1174 | + return EED_Events_Archive::display_venue(); |
|
| 1175 | 1175 | } |
| 1176 | 1176 | |
| 1177 | 1177 | /** |
@@ -1179,5 +1179,5 @@ discard block |
||
| 1179 | 1179 | */ |
| 1180 | 1180 | function espresso_display_datetimes_in_event_list() |
| 1181 | 1181 | { |
| 1182 | - return EED_Events_Archive::display_datetimes(); |
|
| 1182 | + return EED_Events_Archive::display_datetimes(); |
|
| 1183 | 1183 | } |
@@ -123,8 +123,8 @@ discard block |
||
| 123 | 123 | */ |
| 124 | 124 | public static function set_definitions() |
| 125 | 125 | { |
| 126 | - define('EVENTS_ARCHIVE_ASSETS_URL', plugin_dir_url(__FILE__) . 'assets/'); |
|
| 127 | - define('EVENTS_ARCHIVE_TEMPLATES_PATH', str_replace('\\', '/', plugin_dir_path(__FILE__)) . 'templates/'); |
|
| 126 | + define('EVENTS_ARCHIVE_ASSETS_URL', plugin_dir_url(__FILE__).'assets/'); |
|
| 127 | + define('EVENTS_ARCHIVE_TEMPLATES_PATH', str_replace('\\', '/', plugin_dir_path(__FILE__)).'templates/'); |
|
| 128 | 128 | } |
| 129 | 129 | |
| 130 | 130 | |
@@ -144,7 +144,7 @@ discard block |
||
| 144 | 144 | */ |
| 145 | 145 | public static function get_iframe_embed_button() |
| 146 | 146 | { |
| 147 | - if (! self::$_iframe_embed_button instanceof EventListIframeEmbedButton) { |
|
| 147 | + if ( ! self::$_iframe_embed_button instanceof EventListIframeEmbedButton) { |
|
| 148 | 148 | self::$_iframe_embed_button = new EventListIframeEmbedButton(); |
| 149 | 149 | } |
| 150 | 150 | return self::$_iframe_embed_button; |
@@ -227,10 +227,10 @@ discard block |
||
| 227 | 227 | EEH_Event_Query::add_query_filters(); |
| 228 | 228 | // set params that will get used by the filters |
| 229 | 229 | EEH_Event_Query::set_query_params( |
| 230 | - '', // month |
|
| 231 | - '', // category |
|
| 232 | - $config->display_expired_events, // show_expired |
|
| 233 | - 'start_date', // orderby |
|
| 230 | + '', // month |
|
| 231 | + '', // category |
|
| 232 | + $config->display_expired_events, // show_expired |
|
| 233 | + 'start_date', // orderby |
|
| 234 | 234 | 'ASC' // sort |
| 235 | 235 | ); |
| 236 | 236 | // check what template is loaded |
@@ -296,7 +296,7 @@ discard block |
||
| 296 | 296 | public function template_include($template = '') |
| 297 | 297 | { |
| 298 | 298 | // don't add content filter for dedicated EE child themes or private posts |
| 299 | - if (! EEH_Template::is_espresso_theme()) { |
|
| 299 | + if ( ! EEH_Template::is_espresso_theme()) { |
|
| 300 | 300 | /** @type EE_Events_Archive_Config $config */ |
| 301 | 301 | $config = $this->config(); |
| 302 | 302 | // add status banner ? |
@@ -394,7 +394,7 @@ discard block |
||
| 394 | 394 | { |
| 395 | 395 | global $post; |
| 396 | 396 | if ($post instanceof WP_Post) { |
| 397 | - return in_the_loop() && $post->ID == $id ? espresso_event_status_banner($post->ID) . $title : $title; |
|
| 397 | + return in_the_loop() && $post->ID == $id ? espresso_event_status_banner($post->ID).$title : $title; |
|
| 398 | 398 | } |
| 399 | 399 | return $title; |
| 400 | 400 | } |
@@ -544,7 +544,7 @@ discard block |
||
| 544 | 544 | if (post_password_required()) { |
| 545 | 545 | return $content; |
| 546 | 546 | } |
| 547 | - return EEH_Template::locate_template('content-espresso_events-datetimes.php') . $content; |
|
| 547 | + return EEH_Template::locate_template('content-espresso_events-datetimes.php').$content; |
|
| 548 | 548 | } |
| 549 | 549 | |
| 550 | 550 | |
@@ -560,7 +560,7 @@ discard block |
||
| 560 | 560 | if (post_password_required()) { |
| 561 | 561 | return $content; |
| 562 | 562 | } |
| 563 | - return EEH_Template::locate_template('content-espresso_events-tickets.php') . $content; |
|
| 563 | + return EEH_Template::locate_template('content-espresso_events-tickets.php').$content; |
|
| 564 | 564 | } |
| 565 | 565 | |
| 566 | 566 | |
@@ -589,7 +589,7 @@ discard block |
||
| 589 | 589 | if (post_password_required()) { |
| 590 | 590 | return $content; |
| 591 | 591 | } |
| 592 | - return $content . EEH_Template::locate_template('content-espresso_events-venues.php'); |
|
| 592 | + return $content.EEH_Template::locate_template('content-espresso_events-venues.php'); |
|
| 593 | 593 | } |
| 594 | 594 | |
| 595 | 595 | |
@@ -773,10 +773,10 @@ discard block |
||
| 773 | 773 | // get some style |
| 774 | 774 | if (apply_filters('FHEE_enable_default_espresso_css', false)) { |
| 775 | 775 | // first check uploads folder |
| 776 | - if (EEH_File::is_readable(get_stylesheet_directory() . $this->theme . '/style.css')) { |
|
| 776 | + if (EEH_File::is_readable(get_stylesheet_directory().$this->theme.'/style.css')) { |
|
| 777 | 777 | wp_register_style( |
| 778 | 778 | $this->theme, |
| 779 | - get_stylesheet_directory_uri() . $this->theme . '/style.css', |
|
| 779 | + get_stylesheet_directory_uri().$this->theme.'/style.css', |
|
| 780 | 780 | array('dashicons', 'espresso_default') |
| 781 | 781 | ); |
| 782 | 782 | } else { |
@@ -815,7 +815,7 @@ discard block |
||
| 815 | 815 | (array) $template_settings->EED_Events_Archive |
| 816 | 816 | ); |
| 817 | 817 | EEH_Template::display_template( |
| 818 | - EVENTS_ARCHIVE_TEMPLATES_PATH . 'admin-event-list-settings.template.php', |
|
| 818 | + EVENTS_ARCHIVE_TEMPLATES_PATH.'admin-event-list-settings.template.php', |
|
| 819 | 819 | $events_archive_settings |
| 820 | 820 | ); |
| 821 | 821 | } |
@@ -833,7 +833,7 @@ discard block |
||
| 833 | 833 | { |
| 834 | 834 | $CFG->EED_Events_Archive = new EE_Events_Archive_Config(); |
| 835 | 835 | // unless we are resetting the config... |
| 836 | - if (! isset($REQ['EED_Events_Archive_reset_event_list_settings']) |
|
| 836 | + if ( ! isset($REQ['EED_Events_Archive_reset_event_list_settings']) |
|
| 837 | 837 | || absint($REQ['EED_Events_Archive_reset_event_list_settings']) !== 1 |
| 838 | 838 | ) { |
| 839 | 839 | $CFG->EED_Events_Archive->display_status_banner = isset($REQ['EED_Events_Archive_display_status_banner']) |
@@ -15,1800 +15,1800 @@ |
||
| 15 | 15 | class EED_Single_Page_Checkout extends EED_Module |
| 16 | 16 | { |
| 17 | 17 | |
| 18 | - /** |
|
| 19 | - * $_initialized - has the SPCO controller already been initialized ? |
|
| 20 | - * |
|
| 21 | - * @access private |
|
| 22 | - * @var bool $_initialized |
|
| 23 | - */ |
|
| 24 | - private static $_initialized = false; |
|
| 25 | - |
|
| 26 | - |
|
| 27 | - /** |
|
| 28 | - * $_checkout_verified - is the EE_Checkout verified as correct for this request ? |
|
| 29 | - * |
|
| 30 | - * @access private |
|
| 31 | - * @var bool $_valid_checkout |
|
| 32 | - */ |
|
| 33 | - private static $_checkout_verified = true; |
|
| 34 | - |
|
| 35 | - /** |
|
| 36 | - * $_reg_steps_array - holds initial array of reg steps |
|
| 37 | - * |
|
| 38 | - * @access private |
|
| 39 | - * @var array $_reg_steps_array |
|
| 40 | - */ |
|
| 41 | - private static $_reg_steps_array = array(); |
|
| 42 | - |
|
| 43 | - /** |
|
| 44 | - * $checkout - EE_Checkout object for handling the properties of the current checkout process |
|
| 45 | - * |
|
| 46 | - * @access public |
|
| 47 | - * @var EE_Checkout $checkout |
|
| 48 | - */ |
|
| 49 | - public $checkout; |
|
| 50 | - |
|
| 51 | - |
|
| 52 | - /** |
|
| 53 | - * @return EED_Module|EED_Single_Page_Checkout |
|
| 54 | - */ |
|
| 55 | - public static function instance() |
|
| 56 | - { |
|
| 57 | - add_filter('EED_Single_Page_Checkout__SPCO_active', '__return_true'); |
|
| 58 | - return parent::get_instance(__CLASS__); |
|
| 59 | - } |
|
| 60 | - |
|
| 61 | - |
|
| 62 | - /** |
|
| 63 | - * @return EE_CART |
|
| 64 | - */ |
|
| 65 | - public function cart() |
|
| 66 | - { |
|
| 67 | - return $this->checkout->cart; |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - |
|
| 71 | - /** |
|
| 72 | - * @return EE_Transaction |
|
| 73 | - */ |
|
| 74 | - public function transaction() |
|
| 75 | - { |
|
| 76 | - return $this->checkout->transaction; |
|
| 77 | - } |
|
| 78 | - |
|
| 79 | - |
|
| 80 | - /** |
|
| 81 | - * set_hooks - for hooking into EE Core, other modules, etc |
|
| 82 | - * |
|
| 83 | - * @access public |
|
| 84 | - * @return void |
|
| 85 | - * @throws EE_Error |
|
| 86 | - */ |
|
| 87 | - public static function set_hooks() |
|
| 88 | - { |
|
| 89 | - EED_Single_Page_Checkout::set_definitions(); |
|
| 90 | - } |
|
| 91 | - |
|
| 92 | - |
|
| 93 | - /** |
|
| 94 | - * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
| 95 | - * |
|
| 96 | - * @access public |
|
| 97 | - * @return void |
|
| 98 | - * @throws EE_Error |
|
| 99 | - */ |
|
| 100 | - public static function set_hooks_admin() |
|
| 101 | - { |
|
| 102 | - EED_Single_Page_Checkout::set_definitions(); |
|
| 103 | - if (! (defined('DOING_AJAX') && DOING_AJAX)) { |
|
| 104 | - return; |
|
| 105 | - } |
|
| 106 | - // going to start an output buffer in case anything gets accidentally output |
|
| 107 | - // that might disrupt our JSON response |
|
| 108 | - ob_start(); |
|
| 109 | - EED_Single_Page_Checkout::load_request_handler(); |
|
| 110 | - EED_Single_Page_Checkout::load_reg_steps(); |
|
| 111 | - // set ajax hooks |
|
| 112 | - add_action('wp_ajax_process_reg_step', array('EED_Single_Page_Checkout', 'process_reg_step')); |
|
| 113 | - add_action('wp_ajax_nopriv_process_reg_step', array('EED_Single_Page_Checkout', 'process_reg_step')); |
|
| 114 | - add_action('wp_ajax_display_spco_reg_step', array('EED_Single_Page_Checkout', 'display_reg_step')); |
|
| 115 | - add_action('wp_ajax_nopriv_display_spco_reg_step', array('EED_Single_Page_Checkout', 'display_reg_step')); |
|
| 116 | - add_action('wp_ajax_update_reg_step', array('EED_Single_Page_Checkout', 'update_reg_step')); |
|
| 117 | - add_action('wp_ajax_nopriv_update_reg_step', array('EED_Single_Page_Checkout', 'update_reg_step')); |
|
| 118 | - } |
|
| 119 | - |
|
| 120 | - |
|
| 121 | - /** |
|
| 122 | - * process ajax request |
|
| 123 | - * |
|
| 124 | - * @param string $ajax_action |
|
| 125 | - * @throws EE_Error |
|
| 126 | - */ |
|
| 127 | - public static function process_ajax_request($ajax_action) |
|
| 128 | - { |
|
| 129 | - EE_Registry::instance()->REQ->set('action', $ajax_action); |
|
| 130 | - EED_Single_Page_Checkout::instance()->_initialize(); |
|
| 131 | - } |
|
| 132 | - |
|
| 133 | - |
|
| 134 | - /** |
|
| 135 | - * ajax display registration step |
|
| 136 | - * |
|
| 137 | - * @throws EE_Error |
|
| 138 | - */ |
|
| 139 | - public static function display_reg_step() |
|
| 140 | - { |
|
| 141 | - EED_Single_Page_Checkout::process_ajax_request('display_spco_reg_step'); |
|
| 142 | - } |
|
| 143 | - |
|
| 144 | - |
|
| 145 | - /** |
|
| 146 | - * ajax process registration step |
|
| 147 | - * |
|
| 148 | - * @throws EE_Error |
|
| 149 | - */ |
|
| 150 | - public static function process_reg_step() |
|
| 151 | - { |
|
| 152 | - EED_Single_Page_Checkout::process_ajax_request('process_reg_step'); |
|
| 153 | - } |
|
| 154 | - |
|
| 155 | - |
|
| 156 | - /** |
|
| 157 | - * ajax process registration step |
|
| 158 | - * |
|
| 159 | - * @throws EE_Error |
|
| 160 | - */ |
|
| 161 | - public static function update_reg_step() |
|
| 162 | - { |
|
| 163 | - EED_Single_Page_Checkout::process_ajax_request('update_reg_step'); |
|
| 164 | - } |
|
| 165 | - |
|
| 166 | - |
|
| 167 | - /** |
|
| 168 | - * update_checkout |
|
| 169 | - * |
|
| 170 | - * @access public |
|
| 171 | - * @return void |
|
| 172 | - * @throws EE_Error |
|
| 173 | - */ |
|
| 174 | - public static function update_checkout() |
|
| 175 | - { |
|
| 176 | - EED_Single_Page_Checkout::process_ajax_request('update_checkout'); |
|
| 177 | - } |
|
| 178 | - |
|
| 179 | - |
|
| 180 | - /** |
|
| 181 | - * load_request_handler |
|
| 182 | - * |
|
| 183 | - * @access public |
|
| 184 | - * @return void |
|
| 185 | - */ |
|
| 186 | - public static function load_request_handler() |
|
| 187 | - { |
|
| 188 | - // load core Request_Handler class |
|
| 189 | - if (EE_Registry::instance()->REQ !== null) { |
|
| 190 | - EE_Registry::instance()->load_core('Request_Handler'); |
|
| 191 | - } |
|
| 192 | - } |
|
| 193 | - |
|
| 194 | - |
|
| 195 | - /** |
|
| 196 | - * set_definitions |
|
| 197 | - * |
|
| 198 | - * @access public |
|
| 199 | - * @return void |
|
| 200 | - * @throws EE_Error |
|
| 201 | - */ |
|
| 202 | - public static function set_definitions() |
|
| 203 | - { |
|
| 204 | - if (defined('SPCO_BASE_PATH')) { |
|
| 205 | - return; |
|
| 206 | - } |
|
| 207 | - define( |
|
| 208 | - 'SPCO_BASE_PATH', |
|
| 209 | - rtrim(str_replace(array('\\', '/'), '/', plugin_dir_path(__FILE__)), '/') . '/' |
|
| 210 | - ); |
|
| 211 | - define('SPCO_CSS_URL', plugin_dir_url(__FILE__) . 'css/'); |
|
| 212 | - define('SPCO_IMG_URL', plugin_dir_url(__FILE__) . 'img/'); |
|
| 213 | - define('SPCO_JS_URL', plugin_dir_url(__FILE__) . 'js/'); |
|
| 214 | - define('SPCO_INC_PATH', SPCO_BASE_PATH . 'inc/'); |
|
| 215 | - define('SPCO_REG_STEPS_PATH', SPCO_BASE_PATH . 'reg_steps/'); |
|
| 216 | - define('SPCO_TEMPLATES_PATH', SPCO_BASE_PATH . 'templates/'); |
|
| 217 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(SPCO_BASE_PATH, true); |
|
| 218 | - EE_Registry::$i18n_js_strings['registration_expiration_notice'] = EED_Single_Page_Checkout::getRegistrationExpirationNotice( |
|
| 219 | - ); |
|
| 220 | - } |
|
| 221 | - |
|
| 222 | - |
|
| 223 | - /** |
|
| 224 | - * load_reg_steps |
|
| 225 | - * loads and instantiates each reg step based on the EE_Registry::instance()->CFG->registration->reg_steps array |
|
| 226 | - * |
|
| 227 | - * @access private |
|
| 228 | - * @throws EE_Error |
|
| 229 | - */ |
|
| 230 | - public static function load_reg_steps() |
|
| 231 | - { |
|
| 232 | - static $reg_steps_loaded = false; |
|
| 233 | - if ($reg_steps_loaded) { |
|
| 234 | - return; |
|
| 235 | - } |
|
| 236 | - // filter list of reg_steps |
|
| 237 | - $reg_steps_to_load = (array) apply_filters( |
|
| 238 | - 'AHEE__SPCO__load_reg_steps__reg_steps_to_load', |
|
| 239 | - EED_Single_Page_Checkout::get_reg_steps() |
|
| 240 | - ); |
|
| 241 | - // sort by key (order) |
|
| 242 | - ksort($reg_steps_to_load); |
|
| 243 | - // loop through folders |
|
| 244 | - foreach ($reg_steps_to_load as $order => $reg_step) { |
|
| 245 | - // we need a |
|
| 246 | - if (isset($reg_step['file_path'], $reg_step['class_name'], $reg_step['slug'])) { |
|
| 247 | - // copy over to the reg_steps_array |
|
| 248 | - EED_Single_Page_Checkout::$_reg_steps_array[ $order ] = $reg_step; |
|
| 249 | - // register custom key route for each reg step |
|
| 250 | - // ie: step=>"slug" - this is the entire reason we load the reg steps array now |
|
| 251 | - EE_Config::register_route( |
|
| 252 | - $reg_step['slug'], |
|
| 253 | - 'EED_Single_Page_Checkout', |
|
| 254 | - 'run', |
|
| 255 | - 'step' |
|
| 256 | - ); |
|
| 257 | - // add AJAX or other hooks |
|
| 258 | - if (isset($reg_step['has_hooks']) && $reg_step['has_hooks']) { |
|
| 259 | - // setup autoloaders if necessary |
|
| 260 | - if (! class_exists($reg_step['class_name'])) { |
|
| 261 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder( |
|
| 262 | - $reg_step['file_path'], |
|
| 263 | - true |
|
| 264 | - ); |
|
| 265 | - } |
|
| 266 | - if (is_callable($reg_step['class_name'], 'set_hooks')) { |
|
| 267 | - call_user_func(array($reg_step['class_name'], 'set_hooks')); |
|
| 268 | - } |
|
| 269 | - } |
|
| 270 | - } |
|
| 271 | - } |
|
| 272 | - $reg_steps_loaded = true; |
|
| 273 | - } |
|
| 274 | - |
|
| 275 | - |
|
| 276 | - /** |
|
| 277 | - * get_reg_steps |
|
| 278 | - * |
|
| 279 | - * @access public |
|
| 280 | - * @return array |
|
| 281 | - */ |
|
| 282 | - public static function get_reg_steps() |
|
| 283 | - { |
|
| 284 | - $reg_steps = EE_Registry::instance()->CFG->registration->reg_steps; |
|
| 285 | - if (empty($reg_steps)) { |
|
| 286 | - $reg_steps = array( |
|
| 287 | - 10 => array( |
|
| 288 | - 'file_path' => SPCO_REG_STEPS_PATH . 'attendee_information', |
|
| 289 | - 'class_name' => 'EE_SPCO_Reg_Step_Attendee_Information', |
|
| 290 | - 'slug' => 'attendee_information', |
|
| 291 | - 'has_hooks' => false, |
|
| 292 | - ), |
|
| 293 | - 30 => array( |
|
| 294 | - 'file_path' => SPCO_REG_STEPS_PATH . 'payment_options', |
|
| 295 | - 'class_name' => 'EE_SPCO_Reg_Step_Payment_Options', |
|
| 296 | - 'slug' => 'payment_options', |
|
| 297 | - 'has_hooks' => true, |
|
| 298 | - ), |
|
| 299 | - 999 => array( |
|
| 300 | - 'file_path' => SPCO_REG_STEPS_PATH . 'finalize_registration', |
|
| 301 | - 'class_name' => 'EE_SPCO_Reg_Step_Finalize_Registration', |
|
| 302 | - 'slug' => 'finalize_registration', |
|
| 303 | - 'has_hooks' => false, |
|
| 304 | - ), |
|
| 305 | - ); |
|
| 306 | - } |
|
| 307 | - return $reg_steps; |
|
| 308 | - } |
|
| 309 | - |
|
| 310 | - |
|
| 311 | - /** |
|
| 312 | - * registration_checkout_for_admin |
|
| 313 | - * |
|
| 314 | - * @access public |
|
| 315 | - * @return string |
|
| 316 | - * @throws EE_Error |
|
| 317 | - */ |
|
| 318 | - public static function registration_checkout_for_admin() |
|
| 319 | - { |
|
| 320 | - EED_Single_Page_Checkout::load_request_handler(); |
|
| 321 | - EE_Registry::instance()->REQ->set('step', 'attendee_information'); |
|
| 322 | - EE_Registry::instance()->REQ->set('action', 'display_spco_reg_step'); |
|
| 323 | - EE_Registry::instance()->REQ->set('process_form_submission', false); |
|
| 324 | - EED_Single_Page_Checkout::instance()->_initialize(); |
|
| 325 | - EED_Single_Page_Checkout::instance()->_display_spco_reg_form(); |
|
| 326 | - return EE_Registry::instance()->REQ->get_output(); |
|
| 327 | - } |
|
| 328 | - |
|
| 329 | - |
|
| 330 | - /** |
|
| 331 | - * process_registration_from_admin |
|
| 332 | - * |
|
| 333 | - * @access public |
|
| 334 | - * @return \EE_Transaction |
|
| 335 | - * @throws EE_Error |
|
| 336 | - */ |
|
| 337 | - public static function process_registration_from_admin() |
|
| 338 | - { |
|
| 339 | - EED_Single_Page_Checkout::load_request_handler(); |
|
| 340 | - EE_Registry::instance()->REQ->set('step', 'attendee_information'); |
|
| 341 | - EE_Registry::instance()->REQ->set('action', 'process_reg_step'); |
|
| 342 | - EE_Registry::instance()->REQ->set('process_form_submission', true); |
|
| 343 | - EED_Single_Page_Checkout::instance()->_initialize(); |
|
| 344 | - if (EED_Single_Page_Checkout::instance()->checkout->current_step->completed()) { |
|
| 345 | - $final_reg_step = end(EED_Single_Page_Checkout::instance()->checkout->reg_steps); |
|
| 346 | - if ($final_reg_step instanceof EE_SPCO_Reg_Step_Finalize_Registration) { |
|
| 347 | - EED_Single_Page_Checkout::instance()->checkout->set_reg_step_initiated($final_reg_step); |
|
| 348 | - if ($final_reg_step->process_reg_step()) { |
|
| 349 | - $final_reg_step->set_completed(); |
|
| 350 | - EED_Single_Page_Checkout::instance()->checkout->update_txn_reg_steps_array(); |
|
| 351 | - return EED_Single_Page_Checkout::instance()->checkout->transaction; |
|
| 352 | - } |
|
| 353 | - } |
|
| 354 | - } |
|
| 355 | - return null; |
|
| 356 | - } |
|
| 357 | - |
|
| 358 | - |
|
| 359 | - /** |
|
| 360 | - * run |
|
| 361 | - * |
|
| 362 | - * @access public |
|
| 363 | - * @param WP_Query $WP_Query |
|
| 364 | - * @return void |
|
| 365 | - * @throws EE_Error |
|
| 366 | - */ |
|
| 367 | - public function run($WP_Query) |
|
| 368 | - { |
|
| 369 | - if ($WP_Query instanceof WP_Query |
|
| 370 | - && $WP_Query->is_main_query() |
|
| 371 | - && apply_filters('FHEE__EED_Single_Page_Checkout__run', true) |
|
| 372 | - && $this->_is_reg_checkout() |
|
| 373 | - ) { |
|
| 374 | - $this->_initialize(); |
|
| 375 | - } |
|
| 376 | - } |
|
| 377 | - |
|
| 378 | - |
|
| 379 | - /** |
|
| 380 | - * determines whether current url matches reg page url |
|
| 381 | - * |
|
| 382 | - * @return bool |
|
| 383 | - */ |
|
| 384 | - protected function _is_reg_checkout() |
|
| 385 | - { |
|
| 386 | - // get current permalink for reg page without any extra query args |
|
| 387 | - $reg_page_url = \get_permalink(EE_Config::instance()->core->reg_page_id); |
|
| 388 | - // get request URI for current request, but without the scheme or host |
|
| 389 | - $current_request_uri = \EEH_URL::filter_input_server_url('REQUEST_URI'); |
|
| 390 | - $current_request_uri = html_entity_decode($current_request_uri); |
|
| 391 | - // get array of query args from the current request URI |
|
| 392 | - $query_args = \EEH_URL::get_query_string($current_request_uri); |
|
| 393 | - // grab page id if it is set |
|
| 394 | - $page_id = isset($query_args['page_id']) ? absint($query_args['page_id']) : 0; |
|
| 395 | - // and remove the page id from the query args (we will re-add it later) |
|
| 396 | - unset($query_args['page_id']); |
|
| 397 | - // now strip all query args from current request URI |
|
| 398 | - $current_request_uri = remove_query_arg(array_keys($query_args), $current_request_uri); |
|
| 399 | - // and re-add the page id if it was set |
|
| 400 | - if ($page_id) { |
|
| 401 | - $current_request_uri = add_query_arg('page_id', $page_id, $current_request_uri); |
|
| 402 | - } |
|
| 403 | - // remove slashes and ? |
|
| 404 | - $current_request_uri = trim($current_request_uri, '?/'); |
|
| 405 | - // is current request URI part of the known full reg page URL ? |
|
| 406 | - return ! empty($current_request_uri) && strpos($reg_page_url, $current_request_uri) !== false; |
|
| 407 | - } |
|
| 408 | - |
|
| 409 | - |
|
| 410 | - /** |
|
| 411 | - * @param WP_Query $wp_query |
|
| 412 | - * @return void |
|
| 413 | - * @throws EE_Error |
|
| 414 | - */ |
|
| 415 | - public static function init($wp_query) |
|
| 416 | - { |
|
| 417 | - EED_Single_Page_Checkout::instance()->run($wp_query); |
|
| 418 | - } |
|
| 419 | - |
|
| 420 | - |
|
| 421 | - /** |
|
| 422 | - * _initialize - initial module setup |
|
| 423 | - * |
|
| 424 | - * @access private |
|
| 425 | - * @throws EE_Error |
|
| 426 | - * @return void |
|
| 427 | - */ |
|
| 428 | - private function _initialize() |
|
| 429 | - { |
|
| 430 | - // ensure SPCO doesn't run twice |
|
| 431 | - if (EED_Single_Page_Checkout::$_initialized) { |
|
| 432 | - return; |
|
| 433 | - } |
|
| 434 | - try { |
|
| 435 | - EED_Single_Page_Checkout::load_reg_steps(); |
|
| 436 | - $this->_verify_session(); |
|
| 437 | - // setup the EE_Checkout object |
|
| 438 | - $this->checkout = $this->_initialize_checkout(); |
|
| 439 | - // filter checkout |
|
| 440 | - $this->checkout = apply_filters('FHEE__EED_Single_Page_Checkout___initialize__checkout', $this->checkout); |
|
| 441 | - // get the $_GET |
|
| 442 | - $this->_get_request_vars(); |
|
| 443 | - if ($this->_block_bots()) { |
|
| 444 | - return; |
|
| 445 | - } |
|
| 446 | - // filter continue_reg |
|
| 447 | - $this->checkout->continue_reg = apply_filters( |
|
| 448 | - 'FHEE__EED_Single_Page_Checkout__init___continue_reg', |
|
| 449 | - true, |
|
| 450 | - $this->checkout |
|
| 451 | - ); |
|
| 452 | - // load the reg steps array |
|
| 453 | - if (! $this->_load_and_instantiate_reg_steps()) { |
|
| 454 | - EED_Single_Page_Checkout::$_initialized = true; |
|
| 455 | - return; |
|
| 456 | - } |
|
| 457 | - // set the current step |
|
| 458 | - $this->checkout->set_current_step($this->checkout->step); |
|
| 459 | - // and the next step |
|
| 460 | - $this->checkout->set_next_step(); |
|
| 461 | - // verify that everything has been setup correctly |
|
| 462 | - if (! ($this->_verify_transaction_and_get_registrations() && $this->_final_verifications())) { |
|
| 463 | - EED_Single_Page_Checkout::$_initialized = true; |
|
| 464 | - return; |
|
| 465 | - } |
|
| 466 | - // lock the transaction |
|
| 467 | - $this->checkout->transaction->lock(); |
|
| 468 | - // make sure all of our cached objects are added to their respective model entity mappers |
|
| 469 | - $this->checkout->refresh_all_entities(); |
|
| 470 | - // set amount owing |
|
| 471 | - $this->checkout->amount_owing = $this->checkout->transaction->remaining(); |
|
| 472 | - // initialize each reg step, which gives them the chance to potentially alter the process |
|
| 473 | - $this->_initialize_reg_steps(); |
|
| 474 | - // DEBUG LOG |
|
| 475 | - // $this->checkout->log( __CLASS__, __FUNCTION__, __LINE__ ); |
|
| 476 | - // get reg form |
|
| 477 | - if (! $this->_check_form_submission()) { |
|
| 478 | - EED_Single_Page_Checkout::$_initialized = true; |
|
| 479 | - return; |
|
| 480 | - } |
|
| 481 | - // checkout the action!!! |
|
| 482 | - $this->_process_form_action(); |
|
| 483 | - // add some style and make it dance |
|
| 484 | - $this->add_styles_and_scripts(); |
|
| 485 | - // kk... SPCO has successfully run |
|
| 486 | - EED_Single_Page_Checkout::$_initialized = true; |
|
| 487 | - // set no cache headers and constants |
|
| 488 | - EE_System::do_not_cache(); |
|
| 489 | - // add anchor |
|
| 490 | - add_action('loop_start', array($this, 'set_checkout_anchor'), 1); |
|
| 491 | - // remove transaction lock |
|
| 492 | - add_action('shutdown', array($this, 'unlock_transaction'), 1); |
|
| 493 | - } catch (Exception $e) { |
|
| 494 | - EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
| 495 | - } |
|
| 496 | - } |
|
| 497 | - |
|
| 498 | - |
|
| 499 | - /** |
|
| 500 | - * _verify_session |
|
| 501 | - * checks that the session is valid and not expired |
|
| 502 | - * |
|
| 503 | - * @access private |
|
| 504 | - * @throws EE_Error |
|
| 505 | - */ |
|
| 506 | - private function _verify_session() |
|
| 507 | - { |
|
| 508 | - if (! EE_Registry::instance()->SSN instanceof EE_Session) { |
|
| 509 | - throw new EE_Error(esc_html__('The EE_Session class could not be loaded.', 'event_espresso')); |
|
| 510 | - } |
|
| 511 | - $clear_session_requested = filter_var( |
|
| 512 | - EE_Registry::instance()->REQ->get('clear_session', false), |
|
| 513 | - FILTER_VALIDATE_BOOLEAN |
|
| 514 | - ); |
|
| 515 | - // is session still valid ? |
|
| 516 | - if ($clear_session_requested |
|
| 517 | - || (EE_Registry::instance()->SSN->expired() |
|
| 518 | - && EE_Registry::instance()->REQ->get('e_reg_url_link', '') === '' |
|
| 519 | - ) |
|
| 520 | - ) { |
|
| 521 | - $this->checkout = new EE_Checkout(); |
|
| 522 | - EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__); |
|
| 523 | - // EE_Registry::instance()->SSN->reset_cart(); |
|
| 524 | - // EE_Registry::instance()->SSN->reset_checkout(); |
|
| 525 | - // EE_Registry::instance()->SSN->reset_transaction(); |
|
| 526 | - if (! $clear_session_requested) { |
|
| 527 | - EE_Error::add_attention( |
|
| 528 | - EE_Registry::$i18n_js_strings['registration_expiration_notice'], |
|
| 529 | - __FILE__, |
|
| 530 | - __FUNCTION__, |
|
| 531 | - __LINE__ |
|
| 532 | - ); |
|
| 533 | - } |
|
| 534 | - // EE_Registry::instance()->SSN->reset_expired(); |
|
| 535 | - } |
|
| 536 | - } |
|
| 537 | - |
|
| 538 | - |
|
| 539 | - /** |
|
| 540 | - * _initialize_checkout |
|
| 541 | - * loads and instantiates EE_Checkout |
|
| 542 | - * |
|
| 543 | - * @access private |
|
| 544 | - * @throws EE_Error |
|
| 545 | - * @return EE_Checkout |
|
| 546 | - */ |
|
| 547 | - private function _initialize_checkout() |
|
| 548 | - { |
|
| 549 | - // look in session for existing checkout |
|
| 550 | - /** @type EE_Checkout $checkout */ |
|
| 551 | - $checkout = EE_Registry::instance()->SSN->checkout(); |
|
| 552 | - // verify |
|
| 553 | - if (! $checkout instanceof EE_Checkout) { |
|
| 554 | - // instantiate EE_Checkout object for handling the properties of the current checkout process |
|
| 555 | - $checkout = EE_Registry::instance()->load_file( |
|
| 556 | - SPCO_INC_PATH, |
|
| 557 | - 'EE_Checkout', |
|
| 558 | - 'class', |
|
| 559 | - array(), |
|
| 560 | - false |
|
| 561 | - ); |
|
| 562 | - } else { |
|
| 563 | - if ($checkout->current_step->is_final_step() && $checkout->exit_spco() === true) { |
|
| 564 | - $this->unlock_transaction(); |
|
| 565 | - wp_safe_redirect($checkout->redirect_url); |
|
| 566 | - exit(); |
|
| 567 | - } |
|
| 568 | - } |
|
| 569 | - $checkout = apply_filters('FHEE__EED_Single_Page_Checkout___initialize_checkout__checkout', $checkout); |
|
| 570 | - // verify again |
|
| 571 | - if (! $checkout instanceof EE_Checkout) { |
|
| 572 | - throw new EE_Error(esc_html__('The EE_Checkout class could not be loaded.', 'event_espresso')); |
|
| 573 | - } |
|
| 574 | - // reset anything that needs a clean slate for each request |
|
| 575 | - $checkout->reset_for_current_request(); |
|
| 576 | - return $checkout; |
|
| 577 | - } |
|
| 578 | - |
|
| 579 | - |
|
| 580 | - /** |
|
| 581 | - * _get_request_vars |
|
| 582 | - * |
|
| 583 | - * @access private |
|
| 584 | - * @return void |
|
| 585 | - * @throws EE_Error |
|
| 586 | - */ |
|
| 587 | - private function _get_request_vars() |
|
| 588 | - { |
|
| 589 | - // load classes |
|
| 590 | - EED_Single_Page_Checkout::load_request_handler(); |
|
| 591 | - // make sure this request is marked as belonging to EE |
|
| 592 | - EE_Registry::instance()->REQ->set_espresso_page(true); |
|
| 593 | - // which step is being requested ? |
|
| 594 | - $this->checkout->step = EE_Registry::instance()->REQ->get('step', $this->_get_first_step()); |
|
| 595 | - // which step is being edited ? |
|
| 596 | - $this->checkout->edit_step = EE_Registry::instance()->REQ->get('edit_step', ''); |
|
| 597 | - // and what we're doing on the current step |
|
| 598 | - $this->checkout->action = EE_Registry::instance()->REQ->get('action', 'display_spco_reg_step'); |
|
| 599 | - // timestamp |
|
| 600 | - $this->checkout->uts = EE_Registry::instance()->REQ->get('uts', 0); |
|
| 601 | - // returning to edit ? |
|
| 602 | - $this->checkout->reg_url_link = EE_Registry::instance()->REQ->get('e_reg_url_link', ''); |
|
| 603 | - // add reg url link to registration query params |
|
| 604 | - if ($this->checkout->reg_url_link && strpos($this->checkout->reg_url_link, '1-') !== 0) { |
|
| 605 | - $this->checkout->reg_cache_where_params[0]['REG_url_link'] = $this->checkout->reg_url_link; |
|
| 606 | - } |
|
| 607 | - // or some other kind of revisit ? |
|
| 608 | - $this->checkout->revisit = filter_var( |
|
| 609 | - EE_Registry::instance()->REQ->get('revisit', false), |
|
| 610 | - FILTER_VALIDATE_BOOLEAN |
|
| 611 | - ); |
|
| 612 | - // and whether or not to generate a reg form for this request |
|
| 613 | - $this->checkout->generate_reg_form = filter_var( |
|
| 614 | - EE_Registry::instance()->REQ->get('generate_reg_form', true), |
|
| 615 | - FILTER_VALIDATE_BOOLEAN |
|
| 616 | - ); |
|
| 617 | - // and whether or not to process a reg form submission for this request |
|
| 618 | - $this->checkout->process_form_submission = filter_var( |
|
| 619 | - EE_Registry::instance()->REQ->get( |
|
| 620 | - 'process_form_submission', |
|
| 621 | - $this->checkout->action === 'process_reg_step' |
|
| 622 | - ), |
|
| 623 | - FILTER_VALIDATE_BOOLEAN |
|
| 624 | - ); |
|
| 625 | - $this->checkout->process_form_submission = filter_var( |
|
| 626 | - $this->checkout->action !== 'display_spco_reg_step' |
|
| 627 | - ? $this->checkout->process_form_submission |
|
| 628 | - : false, |
|
| 629 | - FILTER_VALIDATE_BOOLEAN |
|
| 630 | - ); |
|
| 631 | - // $this->_display_request_vars(); |
|
| 632 | - } |
|
| 633 | - |
|
| 634 | - |
|
| 635 | - /** |
|
| 636 | - * _display_request_vars |
|
| 637 | - * |
|
| 638 | - * @access protected |
|
| 639 | - * @return void |
|
| 640 | - */ |
|
| 641 | - protected function _display_request_vars() |
|
| 642 | - { |
|
| 643 | - if (! WP_DEBUG) { |
|
| 644 | - return; |
|
| 645 | - } |
|
| 646 | - EEH_Debug_Tools::printr($_REQUEST, '$_REQUEST', __FILE__, __LINE__); |
|
| 647 | - EEH_Debug_Tools::printr($this->checkout->step, '$this->checkout->step', __FILE__, __LINE__); |
|
| 648 | - EEH_Debug_Tools::printr($this->checkout->edit_step, '$this->checkout->edit_step', __FILE__, __LINE__); |
|
| 649 | - EEH_Debug_Tools::printr($this->checkout->action, '$this->checkout->action', __FILE__, __LINE__); |
|
| 650 | - EEH_Debug_Tools::printr($this->checkout->reg_url_link, '$this->checkout->reg_url_link', __FILE__, __LINE__); |
|
| 651 | - EEH_Debug_Tools::printr($this->checkout->revisit, '$this->checkout->revisit', __FILE__, __LINE__); |
|
| 652 | - EEH_Debug_Tools::printr( |
|
| 653 | - $this->checkout->generate_reg_form, |
|
| 654 | - '$this->checkout->generate_reg_form', |
|
| 655 | - __FILE__, |
|
| 656 | - __LINE__ |
|
| 657 | - ); |
|
| 658 | - EEH_Debug_Tools::printr( |
|
| 659 | - $this->checkout->process_form_submission, |
|
| 660 | - '$this->checkout->process_form_submission', |
|
| 661 | - __FILE__, |
|
| 662 | - __LINE__ |
|
| 663 | - ); |
|
| 664 | - } |
|
| 665 | - |
|
| 666 | - |
|
| 667 | - /** |
|
| 668 | - * _block_bots |
|
| 669 | - * checks that the incoming request has either of the following set: |
|
| 670 | - * a uts (unix timestamp) which indicates that the request was redirected from the Ticket Selector |
|
| 671 | - * a REG URL Link, which indicates that the request is a return visit to SPCO for a valid TXN |
|
| 672 | - * so if you're not coming from the Ticket Selector nor returning for a valid IP... |
|
| 673 | - * then where you coming from man? |
|
| 674 | - * |
|
| 675 | - * @return boolean |
|
| 676 | - */ |
|
| 677 | - private function _block_bots() |
|
| 678 | - { |
|
| 679 | - $invalid_checkout_access = EED_Invalid_Checkout_Access::getInvalidCheckoutAccess(); |
|
| 680 | - if ($invalid_checkout_access->checkoutAccessIsInvalid($this->checkout)) { |
|
| 681 | - return true; |
|
| 682 | - } |
|
| 683 | - return false; |
|
| 684 | - } |
|
| 685 | - |
|
| 686 | - |
|
| 687 | - /** |
|
| 688 | - * _get_first_step |
|
| 689 | - * gets slug for first step in $_reg_steps_array |
|
| 690 | - * |
|
| 691 | - * @access private |
|
| 692 | - * @throws EE_Error |
|
| 693 | - * @return string |
|
| 694 | - */ |
|
| 695 | - private function _get_first_step() |
|
| 696 | - { |
|
| 697 | - $first_step = reset(EED_Single_Page_Checkout::$_reg_steps_array); |
|
| 698 | - return isset($first_step['slug']) ? $first_step['slug'] : 'attendee_information'; |
|
| 699 | - } |
|
| 700 | - |
|
| 701 | - |
|
| 702 | - /** |
|
| 703 | - * instantiates each reg step based on the loaded reg_steps array |
|
| 704 | - * |
|
| 705 | - * @return bool |
|
| 706 | - * @throws EE_Error |
|
| 707 | - * @throws InvalidArgumentException |
|
| 708 | - * @throws InvalidDataTypeException |
|
| 709 | - * @throws InvalidInterfaceException |
|
| 710 | - */ |
|
| 711 | - private function _load_and_instantiate_reg_steps() |
|
| 712 | - { |
|
| 713 | - do_action('AHEE__Single_Page_Checkout___load_and_instantiate_reg_steps__start', $this->checkout); |
|
| 714 | - // have reg_steps already been instantiated ? |
|
| 715 | - if (empty($this->checkout->reg_steps) |
|
| 716 | - || apply_filters('FHEE__Single_Page_Checkout__load_reg_steps__reload_reg_steps', false, $this->checkout) |
|
| 717 | - ) { |
|
| 718 | - // if not, then loop through raw reg steps array |
|
| 719 | - foreach (EED_Single_Page_Checkout::$_reg_steps_array as $order => $reg_step) { |
|
| 720 | - if (! $this->_load_and_instantiate_reg_step($reg_step, $order)) { |
|
| 721 | - return false; |
|
| 722 | - } |
|
| 723 | - } |
|
| 724 | - if (isset($this->checkout->reg_steps['registration_confirmation'])) { |
|
| 725 | - // skip the registration_confirmation page ? |
|
| 726 | - if (EE_Registry::instance()->CFG->registration->skip_reg_confirmation) { |
|
| 727 | - // just remove it from the reg steps array |
|
| 728 | - $this->checkout->remove_reg_step('registration_confirmation', false); |
|
| 729 | - } elseif (EE_Registry::instance()->CFG->registration->reg_confirmation_last |
|
| 730 | - ) { |
|
| 731 | - // set the order to something big like 100 |
|
| 732 | - $this->checkout->set_reg_step_order('registration_confirmation', 100); |
|
| 733 | - } |
|
| 734 | - } |
|
| 735 | - // filter the array for good luck |
|
| 736 | - $this->checkout->reg_steps = apply_filters( |
|
| 737 | - 'FHEE__Single_Page_Checkout__load_reg_steps__reg_steps', |
|
| 738 | - $this->checkout->reg_steps |
|
| 739 | - ); |
|
| 740 | - // finally re-sort based on the reg step class order properties |
|
| 741 | - $this->checkout->sort_reg_steps(); |
|
| 742 | - } else { |
|
| 743 | - foreach ($this->checkout->reg_steps as $reg_step) { |
|
| 744 | - // set all current step stati to FALSE |
|
| 745 | - $reg_step->set_is_current_step(false); |
|
| 746 | - } |
|
| 747 | - } |
|
| 748 | - if (empty($this->checkout->reg_steps)) { |
|
| 749 | - EE_Error::add_error( |
|
| 750 | - esc_html__('No Reg Steps were loaded..', 'event_espresso'), |
|
| 751 | - __FILE__, |
|
| 752 | - __FUNCTION__, |
|
| 753 | - __LINE__ |
|
| 754 | - ); |
|
| 755 | - return false; |
|
| 756 | - } |
|
| 757 | - // make reg step details available to JS |
|
| 758 | - $this->checkout->set_reg_step_JSON_info(); |
|
| 759 | - return true; |
|
| 760 | - } |
|
| 761 | - |
|
| 762 | - |
|
| 763 | - /** |
|
| 764 | - * _load_and_instantiate_reg_step |
|
| 765 | - * |
|
| 766 | - * @access private |
|
| 767 | - * @param array $reg_step |
|
| 768 | - * @param int $order |
|
| 769 | - * @return bool |
|
| 770 | - */ |
|
| 771 | - private function _load_and_instantiate_reg_step($reg_step = array(), $order = 0) |
|
| 772 | - { |
|
| 773 | - // we need a file_path, class_name, and slug to add a reg step |
|
| 774 | - if (isset($reg_step['file_path'], $reg_step['class_name'], $reg_step['slug'])) { |
|
| 775 | - // if editing a specific step, but this is NOT that step... (and it's not the 'finalize_registration' step) |
|
| 776 | - if ($this->checkout->reg_url_link |
|
| 777 | - && $this->checkout->step !== $reg_step['slug'] |
|
| 778 | - && $reg_step['slug'] !== 'finalize_registration' |
|
| 779 | - // normally at this point we would NOT load the reg step, but this filter can change that |
|
| 780 | - && apply_filters( |
|
| 781 | - 'FHEE__Single_Page_Checkout___load_and_instantiate_reg_step__bypass_reg_step', |
|
| 782 | - true, |
|
| 783 | - $reg_step, |
|
| 784 | - $this->checkout |
|
| 785 | - ) |
|
| 786 | - ) { |
|
| 787 | - return true; |
|
| 788 | - } |
|
| 789 | - // instantiate step class using file path and class name |
|
| 790 | - $reg_step_obj = EE_Registry::instance()->load_file( |
|
| 791 | - $reg_step['file_path'], |
|
| 792 | - $reg_step['class_name'], |
|
| 793 | - 'class', |
|
| 794 | - $this->checkout, |
|
| 795 | - false |
|
| 796 | - ); |
|
| 797 | - // did we gets the goods ? |
|
| 798 | - if ($reg_step_obj instanceof EE_SPCO_Reg_Step) { |
|
| 799 | - // set reg step order based on config |
|
| 800 | - $reg_step_obj->set_order($order); |
|
| 801 | - // add instantiated reg step object to the master reg steps array |
|
| 802 | - $this->checkout->add_reg_step($reg_step_obj); |
|
| 803 | - } else { |
|
| 804 | - EE_Error::add_error( |
|
| 805 | - esc_html__('The current step could not be set.', 'event_espresso'), |
|
| 806 | - __FILE__, |
|
| 807 | - __FUNCTION__, |
|
| 808 | - __LINE__ |
|
| 809 | - ); |
|
| 810 | - return false; |
|
| 811 | - } |
|
| 812 | - } else { |
|
| 813 | - if (WP_DEBUG) { |
|
| 814 | - EE_Error::add_error( |
|
| 815 | - sprintf( |
|
| 816 | - esc_html__( |
|
| 817 | - 'A registration step could not be loaded. One or more of the following data points is invalid:%4$s%5$sFile Path: %1$s%6$s%5$sClass Name: %2$s%6$s%5$sSlug: %3$s%6$s%7$s', |
|
| 818 | - 'event_espresso' |
|
| 819 | - ), |
|
| 820 | - isset($reg_step['file_path']) ? $reg_step['file_path'] : '', |
|
| 821 | - isset($reg_step['class_name']) ? $reg_step['class_name'] : '', |
|
| 822 | - isset($reg_step['slug']) ? $reg_step['slug'] : '', |
|
| 823 | - '<ul>', |
|
| 824 | - '<li>', |
|
| 825 | - '</li>', |
|
| 826 | - '</ul>' |
|
| 827 | - ), |
|
| 828 | - __FILE__, |
|
| 829 | - __FUNCTION__, |
|
| 830 | - __LINE__ |
|
| 831 | - ); |
|
| 832 | - } |
|
| 833 | - return false; |
|
| 834 | - } |
|
| 835 | - return true; |
|
| 836 | - } |
|
| 837 | - |
|
| 838 | - |
|
| 839 | - /** |
|
| 840 | - * _verify_transaction_and_get_registrations |
|
| 841 | - * |
|
| 842 | - * @access private |
|
| 843 | - * @return bool |
|
| 844 | - * @throws InvalidDataTypeException |
|
| 845 | - * @throws InvalidEntityException |
|
| 846 | - * @throws EE_Error |
|
| 847 | - */ |
|
| 848 | - private function _verify_transaction_and_get_registrations() |
|
| 849 | - { |
|
| 850 | - // was there already a valid transaction in the checkout from the session ? |
|
| 851 | - if (! $this->checkout->transaction instanceof EE_Transaction) { |
|
| 852 | - // get transaction from db or session |
|
| 853 | - $this->checkout->transaction = $this->checkout->reg_url_link && ! is_admin() |
|
| 854 | - ? $this->_get_transaction_and_cart_for_previous_visit() |
|
| 855 | - : $this->_get_cart_for_current_session_and_setup_new_transaction(); |
|
| 856 | - if (! $this->checkout->transaction instanceof EE_Transaction) { |
|
| 857 | - EE_Error::add_error( |
|
| 858 | - esc_html__( |
|
| 859 | - 'Your Registration and Transaction information could not be retrieved from the db.', |
|
| 860 | - 'event_espresso' |
|
| 861 | - ), |
|
| 862 | - __FILE__, |
|
| 863 | - __FUNCTION__, |
|
| 864 | - __LINE__ |
|
| 865 | - ); |
|
| 866 | - $this->checkout->transaction = EE_Transaction::new_instance(); |
|
| 867 | - // add some style and make it dance |
|
| 868 | - $this->add_styles_and_scripts(); |
|
| 869 | - EED_Single_Page_Checkout::$_initialized = true; |
|
| 870 | - return false; |
|
| 871 | - } |
|
| 872 | - // and the registrations for the transaction |
|
| 873 | - $this->_get_registrations($this->checkout->transaction); |
|
| 874 | - } |
|
| 875 | - return true; |
|
| 876 | - } |
|
| 877 | - |
|
| 878 | - |
|
| 879 | - /** |
|
| 880 | - * _get_transaction_and_cart_for_previous_visit |
|
| 881 | - * |
|
| 882 | - * @access private |
|
| 883 | - * @return mixed EE_Transaction|NULL |
|
| 884 | - */ |
|
| 885 | - private function _get_transaction_and_cart_for_previous_visit() |
|
| 886 | - { |
|
| 887 | - /** @var $TXN_model EEM_Transaction */ |
|
| 888 | - $TXN_model = EE_Registry::instance()->load_model('Transaction'); |
|
| 889 | - // because the reg_url_link is present in the request, |
|
| 890 | - // this is a return visit to SPCO, so we'll get the transaction data from the db |
|
| 891 | - $transaction = $TXN_model->get_transaction_from_reg_url_link($this->checkout->reg_url_link); |
|
| 892 | - // verify transaction |
|
| 893 | - if ($transaction instanceof EE_Transaction) { |
|
| 894 | - // and get the cart that was used for that transaction |
|
| 895 | - $this->checkout->cart = $this->_get_cart_for_transaction($transaction); |
|
| 896 | - return $transaction; |
|
| 897 | - } |
|
| 898 | - EE_Error::add_error( |
|
| 899 | - esc_html__('Your Registration and Transaction information could not be retrieved from the db.', 'event_espresso'), |
|
| 900 | - __FILE__, |
|
| 901 | - __FUNCTION__, |
|
| 902 | - __LINE__ |
|
| 903 | - ); |
|
| 904 | - return null; |
|
| 905 | - } |
|
| 906 | - |
|
| 907 | - |
|
| 908 | - /** |
|
| 909 | - * _get_cart_for_transaction |
|
| 910 | - * |
|
| 911 | - * @access private |
|
| 912 | - * @param EE_Transaction $transaction |
|
| 913 | - * @return EE_Cart |
|
| 914 | - */ |
|
| 915 | - private function _get_cart_for_transaction($transaction) |
|
| 916 | - { |
|
| 917 | - return $this->checkout->get_cart_for_transaction($transaction); |
|
| 918 | - } |
|
| 919 | - |
|
| 920 | - |
|
| 921 | - /** |
|
| 922 | - * get_cart_for_transaction |
|
| 923 | - * |
|
| 924 | - * @access public |
|
| 925 | - * @param EE_Transaction $transaction |
|
| 926 | - * @return EE_Cart |
|
| 927 | - */ |
|
| 928 | - public function get_cart_for_transaction(EE_Transaction $transaction) |
|
| 929 | - { |
|
| 930 | - return $this->checkout->get_cart_for_transaction($transaction); |
|
| 931 | - } |
|
| 932 | - |
|
| 933 | - |
|
| 934 | - /** |
|
| 935 | - * _get_transaction_and_cart_for_current_session |
|
| 936 | - * generates a new EE_Transaction object and adds it to the $_transaction property. |
|
| 937 | - * |
|
| 938 | - * @access private |
|
| 939 | - * @return EE_Transaction |
|
| 940 | - * @throws EE_Error |
|
| 941 | - */ |
|
| 942 | - private function _get_cart_for_current_session_and_setup_new_transaction() |
|
| 943 | - { |
|
| 944 | - // if there's no transaction, then this is the FIRST visit to SPCO |
|
| 945 | - // so load up the cart ( passing nothing for the TXN because it doesn't exist yet ) |
|
| 946 | - $this->checkout->cart = $this->_get_cart_for_transaction(null); |
|
| 947 | - // and then create a new transaction |
|
| 948 | - $transaction = $this->_initialize_transaction(); |
|
| 949 | - // verify transaction |
|
| 950 | - if ($transaction instanceof EE_Transaction) { |
|
| 951 | - // save it so that we have an ID for other objects to use |
|
| 952 | - $transaction->save(); |
|
| 953 | - // and save TXN data to the cart |
|
| 954 | - $this->checkout->cart->get_grand_total()->save_this_and_descendants_to_txn($transaction->ID()); |
|
| 955 | - } else { |
|
| 956 | - EE_Error::add_error( |
|
| 957 | - esc_html__('A Valid Transaction could not be initialized.', 'event_espresso'), |
|
| 958 | - __FILE__, |
|
| 959 | - __FUNCTION__, |
|
| 960 | - __LINE__ |
|
| 961 | - ); |
|
| 962 | - } |
|
| 963 | - return $transaction; |
|
| 964 | - } |
|
| 965 | - |
|
| 966 | - |
|
| 967 | - /** |
|
| 968 | - * generates a new EE_Transaction object and adds it to the $_transaction property. |
|
| 969 | - * |
|
| 970 | - * @access private |
|
| 971 | - * @return mixed EE_Transaction|NULL |
|
| 972 | - */ |
|
| 973 | - private function _initialize_transaction() |
|
| 974 | - { |
|
| 975 | - try { |
|
| 976 | - // ensure cart totals have been calculated |
|
| 977 | - $this->checkout->cart->get_grand_total()->recalculate_total_including_taxes(); |
|
| 978 | - // grab the cart grand total |
|
| 979 | - $cart_total = $this->checkout->cart->get_cart_grand_total(); |
|
| 980 | - // create new TXN |
|
| 981 | - $transaction = EE_Transaction::new_instance( |
|
| 982 | - array( |
|
| 983 | - 'TXN_reg_steps' => $this->checkout->initialize_txn_reg_steps_array(), |
|
| 984 | - 'TXN_total' => $cart_total > 0 ? $cart_total : 0, |
|
| 985 | - 'TXN_paid' => 0, |
|
| 986 | - 'STS_ID' => EEM_Transaction::failed_status_code, |
|
| 987 | - ) |
|
| 988 | - ); |
|
| 989 | - // save it so that we have an ID for other objects to use |
|
| 990 | - $transaction->save(); |
|
| 991 | - // set cron job for following up on TXNs after their session has expired |
|
| 992 | - EE_Cron_Tasks::schedule_expired_transaction_check( |
|
| 993 | - EE_Registry::instance()->SSN->expiration() + 1, |
|
| 994 | - $transaction->ID() |
|
| 995 | - ); |
|
| 996 | - return $transaction; |
|
| 997 | - } catch (Exception $e) { |
|
| 998 | - EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
| 999 | - } |
|
| 1000 | - return null; |
|
| 1001 | - } |
|
| 1002 | - |
|
| 1003 | - |
|
| 1004 | - /** |
|
| 1005 | - * _get_registrations |
|
| 1006 | - * |
|
| 1007 | - * @access private |
|
| 1008 | - * @param EE_Transaction $transaction |
|
| 1009 | - * @return void |
|
| 1010 | - * @throws InvalidDataTypeException |
|
| 1011 | - * @throws InvalidEntityException |
|
| 1012 | - * @throws EE_Error |
|
| 1013 | - */ |
|
| 1014 | - private function _get_registrations(EE_Transaction $transaction) |
|
| 1015 | - { |
|
| 1016 | - // first step: grab the registrants { : o |
|
| 1017 | - $registrations = $transaction->registrations($this->checkout->reg_cache_where_params, false); |
|
| 1018 | - $this->checkout->total_ticket_count = count($registrations); |
|
| 1019 | - // verify registrations have been set |
|
| 1020 | - if (empty($registrations)) { |
|
| 1021 | - // if no cached registrations, then check the db |
|
| 1022 | - $registrations = $transaction->registrations($this->checkout->reg_cache_where_params, false); |
|
| 1023 | - // still nothing ? well as long as this isn't a revisit |
|
| 1024 | - if (empty($registrations) && ! $this->checkout->revisit) { |
|
| 1025 | - // generate new registrations from scratch |
|
| 1026 | - $registrations = $this->_initialize_registrations($transaction); |
|
| 1027 | - } |
|
| 1028 | - } |
|
| 1029 | - // sort by their original registration order |
|
| 1030 | - usort($registrations, array('EED_Single_Page_Checkout', 'sort_registrations_by_REG_count')); |
|
| 1031 | - // then loop thru the array |
|
| 1032 | - foreach ($registrations as $registration) { |
|
| 1033 | - // verify each registration |
|
| 1034 | - if ($registration instanceof EE_Registration) { |
|
| 1035 | - // we display all attendee info for the primary registrant |
|
| 1036 | - if ($this->checkout->reg_url_link === $registration->reg_url_link() |
|
| 1037 | - && $registration->is_primary_registrant() |
|
| 1038 | - ) { |
|
| 1039 | - $this->checkout->primary_revisit = true; |
|
| 1040 | - break; |
|
| 1041 | - } |
|
| 1042 | - if ($this->checkout->revisit && $this->checkout->reg_url_link !== $registration->reg_url_link()) { |
|
| 1043 | - // but hide info if it doesn't belong to you |
|
| 1044 | - $transaction->clear_cache('Registration', $registration->ID()); |
|
| 1045 | - $this->checkout->total_ticket_count--; |
|
| 1046 | - } |
|
| 1047 | - $this->checkout->set_reg_status_updated($registration->ID(), false); |
|
| 1048 | - } |
|
| 1049 | - } |
|
| 1050 | - } |
|
| 1051 | - |
|
| 1052 | - |
|
| 1053 | - /** |
|
| 1054 | - * adds related EE_Registration objects for each ticket in the cart to the current EE_Transaction object |
|
| 1055 | - * |
|
| 1056 | - * @access private |
|
| 1057 | - * @param EE_Transaction $transaction |
|
| 1058 | - * @return array |
|
| 1059 | - * @throws InvalidDataTypeException |
|
| 1060 | - * @throws InvalidEntityException |
|
| 1061 | - * @throws EE_Error |
|
| 1062 | - */ |
|
| 1063 | - private function _initialize_registrations(EE_Transaction $transaction) |
|
| 1064 | - { |
|
| 1065 | - $att_nmbr = 0; |
|
| 1066 | - $registrations = array(); |
|
| 1067 | - if ($transaction instanceof EE_Transaction) { |
|
| 1068 | - /** @type EE_Registration_Processor $registration_processor */ |
|
| 1069 | - $registration_processor = EE_Registry::instance()->load_class('Registration_Processor'); |
|
| 1070 | - $this->checkout->total_ticket_count = $this->checkout->cart->all_ticket_quantity_count(); |
|
| 1071 | - // now let's add the cart items to the $transaction |
|
| 1072 | - foreach ($this->checkout->cart->get_tickets() as $line_item) { |
|
| 1073 | - // do the following for each ticket of this type they selected |
|
| 1074 | - for ($x = 1; $x <= $line_item->quantity(); $x++) { |
|
| 1075 | - $att_nmbr++; |
|
| 1076 | - /** @var EventEspresso\core\services\commands\registration\CreateRegistrationCommand $CreateRegistrationCommand */ |
|
| 1077 | - $CreateRegistrationCommand = EE_Registry::instance()->create( |
|
| 1078 | - 'EventEspresso\core\services\commands\registration\CreateRegistrationCommand', |
|
| 1079 | - array( |
|
| 1080 | - $transaction, |
|
| 1081 | - $line_item, |
|
| 1082 | - $att_nmbr, |
|
| 1083 | - $this->checkout->total_ticket_count, |
|
| 1084 | - ) |
|
| 1085 | - ); |
|
| 1086 | - // override capabilities for frontend registrations |
|
| 1087 | - if (! is_admin()) { |
|
| 1088 | - $CreateRegistrationCommand->setCapCheck( |
|
| 1089 | - new PublicCapabilities('', 'create_new_registration') |
|
| 1090 | - ); |
|
| 1091 | - } |
|
| 1092 | - $registration = EE_Registry::instance()->BUS->execute($CreateRegistrationCommand); |
|
| 1093 | - if (! $registration instanceof EE_Registration) { |
|
| 1094 | - throw new InvalidEntityException($registration, 'EE_Registration'); |
|
| 1095 | - } |
|
| 1096 | - $registrations[ $registration->ID() ] = $registration; |
|
| 1097 | - } |
|
| 1098 | - } |
|
| 1099 | - $registration_processor->fix_reg_final_price_rounding_issue($transaction); |
|
| 1100 | - } |
|
| 1101 | - return $registrations; |
|
| 1102 | - } |
|
| 1103 | - |
|
| 1104 | - |
|
| 1105 | - /** |
|
| 1106 | - * sorts registrations by REG_count |
|
| 1107 | - * |
|
| 1108 | - * @access public |
|
| 1109 | - * @param EE_Registration $reg_A |
|
| 1110 | - * @param EE_Registration $reg_B |
|
| 1111 | - * @return int |
|
| 1112 | - */ |
|
| 1113 | - public static function sort_registrations_by_REG_count(EE_Registration $reg_A, EE_Registration $reg_B) |
|
| 1114 | - { |
|
| 1115 | - // this shouldn't ever happen within the same TXN, but oh well |
|
| 1116 | - if ($reg_A->count() === $reg_B->count()) { |
|
| 1117 | - return 0; |
|
| 1118 | - } |
|
| 1119 | - return ($reg_A->count() > $reg_B->count()) ? 1 : -1; |
|
| 1120 | - } |
|
| 1121 | - |
|
| 1122 | - |
|
| 1123 | - /** |
|
| 1124 | - * _final_verifications |
|
| 1125 | - * just makes sure that everything is set up correctly before proceeding |
|
| 1126 | - * |
|
| 1127 | - * @access private |
|
| 1128 | - * @return bool |
|
| 1129 | - * @throws EE_Error |
|
| 1130 | - */ |
|
| 1131 | - private function _final_verifications() |
|
| 1132 | - { |
|
| 1133 | - // filter checkout |
|
| 1134 | - $this->checkout = apply_filters( |
|
| 1135 | - 'FHEE__EED_Single_Page_Checkout___final_verifications__checkout', |
|
| 1136 | - $this->checkout |
|
| 1137 | - ); |
|
| 1138 | - // verify that current step is still set correctly |
|
| 1139 | - if (! $this->checkout->current_step instanceof EE_SPCO_Reg_Step) { |
|
| 1140 | - EE_Error::add_error( |
|
| 1141 | - esc_html__( |
|
| 1142 | - 'We\'re sorry but the registration process can not proceed because one or more registration steps were not setup correctly. Please refresh the page and try again or contact support.', |
|
| 1143 | - 'event_espresso' |
|
| 1144 | - ), |
|
| 1145 | - __FILE__, |
|
| 1146 | - __FUNCTION__, |
|
| 1147 | - __LINE__ |
|
| 1148 | - ); |
|
| 1149 | - return false; |
|
| 1150 | - } |
|
| 1151 | - // if returning to SPCO, then verify that primary registrant is set |
|
| 1152 | - if (! empty($this->checkout->reg_url_link)) { |
|
| 1153 | - $valid_registrant = $this->checkout->transaction->primary_registration(); |
|
| 1154 | - if (! $valid_registrant instanceof EE_Registration) { |
|
| 1155 | - EE_Error::add_error( |
|
| 1156 | - esc_html__( |
|
| 1157 | - 'We\'re sorry but there appears to be an error with the "reg_url_link" or the primary registrant for this transaction. Please refresh the page and try again or contact support.', |
|
| 1158 | - 'event_espresso' |
|
| 1159 | - ), |
|
| 1160 | - __FILE__, |
|
| 1161 | - __FUNCTION__, |
|
| 1162 | - __LINE__ |
|
| 1163 | - ); |
|
| 1164 | - return false; |
|
| 1165 | - } |
|
| 1166 | - $valid_registrant = null; |
|
| 1167 | - foreach ($this->checkout->transaction->registrations($this->checkout->reg_cache_where_params) as $registration) { |
|
| 1168 | - if ($registration instanceof EE_Registration |
|
| 1169 | - && $registration->reg_url_link() === $this->checkout->reg_url_link |
|
| 1170 | - ) { |
|
| 1171 | - $valid_registrant = $registration; |
|
| 1172 | - } |
|
| 1173 | - } |
|
| 1174 | - if (! $valid_registrant instanceof EE_Registration) { |
|
| 1175 | - // hmmm... maybe we have the wrong session because the user is opening multiple tabs ? |
|
| 1176 | - if (EED_Single_Page_Checkout::$_checkout_verified) { |
|
| 1177 | - // clear the session, mark the checkout as unverified, and try again |
|
| 1178 | - EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__); |
|
| 1179 | - EED_Single_Page_Checkout::$_initialized = false; |
|
| 1180 | - EED_Single_Page_Checkout::$_checkout_verified = false; |
|
| 1181 | - $this->_initialize(); |
|
| 1182 | - EE_Error::reset_notices(); |
|
| 1183 | - return false; |
|
| 1184 | - } |
|
| 1185 | - EE_Error::add_error( |
|
| 1186 | - esc_html__( |
|
| 1187 | - 'We\'re sorry but there appears to be an error with the "reg_url_link" or the transaction itself. Please refresh the page and try again or contact support.', |
|
| 1188 | - 'event_espresso' |
|
| 1189 | - ), |
|
| 1190 | - __FILE__, |
|
| 1191 | - __FUNCTION__, |
|
| 1192 | - __LINE__ |
|
| 1193 | - ); |
|
| 1194 | - return false; |
|
| 1195 | - } |
|
| 1196 | - } |
|
| 1197 | - // now that things have been kinda sufficiently verified, |
|
| 1198 | - // let's add the checkout to the session so that it's available to other systems |
|
| 1199 | - EE_Registry::instance()->SSN->set_checkout($this->checkout); |
|
| 1200 | - return true; |
|
| 1201 | - } |
|
| 1202 | - |
|
| 1203 | - |
|
| 1204 | - /** |
|
| 1205 | - * _initialize_reg_steps |
|
| 1206 | - * first makes sure that EE_Transaction_Processor::set_reg_step_initiated() is called as required |
|
| 1207 | - * then loops thru all of the active reg steps and calls the initialize_reg_step() method |
|
| 1208 | - * |
|
| 1209 | - * @access private |
|
| 1210 | - * @param bool $reinitializing |
|
| 1211 | - * @throws EE_Error |
|
| 1212 | - */ |
|
| 1213 | - private function _initialize_reg_steps($reinitializing = false) |
|
| 1214 | - { |
|
| 1215 | - $this->checkout->set_reg_step_initiated($this->checkout->current_step); |
|
| 1216 | - // loop thru all steps to call their individual "initialize" methods and set i18n strings for JS |
|
| 1217 | - foreach ($this->checkout->reg_steps as $reg_step) { |
|
| 1218 | - if (! $reg_step->initialize_reg_step()) { |
|
| 1219 | - // if not initialized then maybe this step is being removed... |
|
| 1220 | - if (! $reinitializing && $reg_step->is_current_step()) { |
|
| 1221 | - // if it was the current step, then we need to start over here |
|
| 1222 | - $this->_initialize_reg_steps(true); |
|
| 1223 | - return; |
|
| 1224 | - } |
|
| 1225 | - continue; |
|
| 1226 | - } |
|
| 1227 | - // add css and JS for current step |
|
| 1228 | - $reg_step->enqueue_styles_and_scripts(); |
|
| 1229 | - // i18n |
|
| 1230 | - $reg_step->translate_js_strings(); |
|
| 1231 | - if ($reg_step->is_current_step()) { |
|
| 1232 | - // the text that appears on the reg step form submit button |
|
| 1233 | - $reg_step->set_submit_button_text(); |
|
| 1234 | - } |
|
| 1235 | - } |
|
| 1236 | - // dynamically creates hook point like: AHEE__Single_Page_Checkout___initialize_reg_step__attendee_information |
|
| 1237 | - do_action( |
|
| 1238 | - "AHEE__Single_Page_Checkout___initialize_reg_step__{$this->checkout->current_step->slug()}", |
|
| 1239 | - $this->checkout->current_step |
|
| 1240 | - ); |
|
| 1241 | - } |
|
| 1242 | - |
|
| 1243 | - |
|
| 1244 | - /** |
|
| 1245 | - * _check_form_submission |
|
| 1246 | - * |
|
| 1247 | - * @access private |
|
| 1248 | - * @return boolean |
|
| 1249 | - */ |
|
| 1250 | - private function _check_form_submission() |
|
| 1251 | - { |
|
| 1252 | - // does this request require the reg form to be generated ? |
|
| 1253 | - if ($this->checkout->generate_reg_form) { |
|
| 1254 | - // ever heard that song by Blue Rodeo ? |
|
| 1255 | - try { |
|
| 1256 | - $this->checkout->current_step->reg_form = $this->checkout->current_step->generate_reg_form(); |
|
| 1257 | - // if not displaying a form, then check for form submission |
|
| 1258 | - if ($this->checkout->process_form_submission |
|
| 1259 | - && $this->checkout->current_step->reg_form->was_submitted() |
|
| 1260 | - ) { |
|
| 1261 | - // clear out any old data in case this step is being run again |
|
| 1262 | - $this->checkout->current_step->set_valid_data(array()); |
|
| 1263 | - // capture submitted form data |
|
| 1264 | - $this->checkout->current_step->reg_form->receive_form_submission( |
|
| 1265 | - apply_filters( |
|
| 1266 | - 'FHEE__Single_Page_Checkout___check_form_submission__request_params', |
|
| 1267 | - EE_Registry::instance()->REQ->params(), |
|
| 1268 | - $this->checkout |
|
| 1269 | - ) |
|
| 1270 | - ); |
|
| 1271 | - // validate submitted form data |
|
| 1272 | - if (! $this->checkout->continue_reg || ! $this->checkout->current_step->reg_form->is_valid()) { |
|
| 1273 | - // thou shall not pass !!! |
|
| 1274 | - $this->checkout->continue_reg = false; |
|
| 1275 | - // any form validation errors? |
|
| 1276 | - if ($this->checkout->current_step->reg_form->submission_error_message() !== '') { |
|
| 1277 | - EE_Error::add_error( |
|
| 1278 | - $this->checkout->current_step->reg_form->submission_error_message(), |
|
| 1279 | - __FILE__, |
|
| 1280 | - __FUNCTION__, |
|
| 1281 | - __LINE__ |
|
| 1282 | - ); |
|
| 1283 | - } |
|
| 1284 | - // well not really... what will happen is |
|
| 1285 | - // we'll just get redirected back to redo the current step |
|
| 1286 | - $this->go_to_next_step(); |
|
| 1287 | - return false; |
|
| 1288 | - } |
|
| 1289 | - } |
|
| 1290 | - } catch (EE_Error $e) { |
|
| 1291 | - $e->get_error(); |
|
| 1292 | - } |
|
| 1293 | - } |
|
| 1294 | - return true; |
|
| 1295 | - } |
|
| 1296 | - |
|
| 1297 | - |
|
| 1298 | - /** |
|
| 1299 | - * _process_action |
|
| 1300 | - * |
|
| 1301 | - * @access private |
|
| 1302 | - * @return void |
|
| 1303 | - * @throws EE_Error |
|
| 1304 | - */ |
|
| 1305 | - private function _process_form_action() |
|
| 1306 | - { |
|
| 1307 | - // what cha wanna do? |
|
| 1308 | - switch ($this->checkout->action) { |
|
| 1309 | - // AJAX next step reg form |
|
| 1310 | - case 'display_spco_reg_step': |
|
| 1311 | - $this->checkout->redirect = false; |
|
| 1312 | - if (EE_Registry::instance()->REQ->ajax) { |
|
| 1313 | - $this->checkout->json_response->set_reg_step_html( |
|
| 1314 | - $this->checkout->current_step->display_reg_form() |
|
| 1315 | - ); |
|
| 1316 | - } |
|
| 1317 | - break; |
|
| 1318 | - default: |
|
| 1319 | - // meh... do one of those other steps first |
|
| 1320 | - if (! empty($this->checkout->action) |
|
| 1321 | - && is_callable(array($this->checkout->current_step, $this->checkout->action)) |
|
| 1322 | - ) { |
|
| 1323 | - // dynamically creates hook point like: |
|
| 1324 | - // AHEE__Single_Page_Checkout__before_attendee_information__process_reg_step |
|
| 1325 | - do_action( |
|
| 1326 | - "AHEE__Single_Page_Checkout__before_{$this->checkout->current_step->slug()}__{$this->checkout->action}", |
|
| 1327 | - $this->checkout->current_step |
|
| 1328 | - ); |
|
| 1329 | - // call action on current step |
|
| 1330 | - if (call_user_func(array($this->checkout->current_step, $this->checkout->action))) { |
|
| 1331 | - // good registrant, you get to proceed |
|
| 1332 | - if ($this->checkout->current_step->success_message() !== '' |
|
| 1333 | - && apply_filters( |
|
| 1334 | - 'FHEE__Single_Page_Checkout___process_form_action__display_success', |
|
| 1335 | - false |
|
| 1336 | - ) |
|
| 1337 | - ) { |
|
| 1338 | - EE_Error::add_success( |
|
| 1339 | - $this->checkout->current_step->success_message() |
|
| 1340 | - . '<br />' . $this->checkout->next_step->_instructions() |
|
| 1341 | - ); |
|
| 1342 | - } |
|
| 1343 | - // pack it up, pack it in... |
|
| 1344 | - $this->_setup_redirect(); |
|
| 1345 | - } |
|
| 1346 | - // dynamically creates hook point like: |
|
| 1347 | - // AHEE__Single_Page_Checkout__after_payment_options__process_reg_step |
|
| 1348 | - do_action( |
|
| 1349 | - "AHEE__Single_Page_Checkout__after_{$this->checkout->current_step->slug()}__{$this->checkout->action}", |
|
| 1350 | - $this->checkout->current_step |
|
| 1351 | - ); |
|
| 1352 | - } else { |
|
| 1353 | - EE_Error::add_error( |
|
| 1354 | - sprintf( |
|
| 1355 | - esc_html__( |
|
| 1356 | - 'The requested form action "%s" does not exist for the current "%s" registration step.', |
|
| 1357 | - 'event_espresso' |
|
| 1358 | - ), |
|
| 1359 | - $this->checkout->action, |
|
| 1360 | - $this->checkout->current_step->name() |
|
| 1361 | - ), |
|
| 1362 | - __FILE__, |
|
| 1363 | - __FUNCTION__, |
|
| 1364 | - __LINE__ |
|
| 1365 | - ); |
|
| 1366 | - } |
|
| 1367 | - // end default |
|
| 1368 | - } |
|
| 1369 | - // store our progress so far |
|
| 1370 | - $this->checkout->stash_transaction_and_checkout(); |
|
| 1371 | - // advance to the next step! If you pass GO, collect $200 |
|
| 1372 | - $this->go_to_next_step(); |
|
| 1373 | - } |
|
| 1374 | - |
|
| 1375 | - |
|
| 1376 | - /** |
|
| 1377 | - * add_styles_and_scripts |
|
| 1378 | - * |
|
| 1379 | - * @access public |
|
| 1380 | - * @return void |
|
| 1381 | - */ |
|
| 1382 | - public function add_styles_and_scripts() |
|
| 1383 | - { |
|
| 1384 | - // i18n |
|
| 1385 | - $this->translate_js_strings(); |
|
| 1386 | - if ($this->checkout->admin_request) { |
|
| 1387 | - add_action('admin_enqueue_scripts', array($this, 'enqueue_styles_and_scripts'), 10); |
|
| 1388 | - } else { |
|
| 1389 | - add_action('wp_enqueue_scripts', array($this, 'enqueue_styles_and_scripts'), 10); |
|
| 1390 | - } |
|
| 1391 | - } |
|
| 1392 | - |
|
| 1393 | - |
|
| 1394 | - /** |
|
| 1395 | - * translate_js_strings |
|
| 1396 | - * |
|
| 1397 | - * @access public |
|
| 1398 | - * @return void |
|
| 1399 | - */ |
|
| 1400 | - public function translate_js_strings() |
|
| 1401 | - { |
|
| 1402 | - EE_Registry::$i18n_js_strings['revisit'] = $this->checkout->revisit; |
|
| 1403 | - EE_Registry::$i18n_js_strings['e_reg_url_link'] = $this->checkout->reg_url_link; |
|
| 1404 | - EE_Registry::$i18n_js_strings['server_error'] = esc_html__( |
|
| 1405 | - 'An unknown error occurred on the server while attempting to process your request. Please refresh the page and try again or contact support.', |
|
| 1406 | - 'event_espresso' |
|
| 1407 | - ); |
|
| 1408 | - EE_Registry::$i18n_js_strings['invalid_json_response'] = esc_html__( |
|
| 1409 | - 'An invalid response was returned from the server while attempting to process your request. Please refresh the page and try again or contact support.', |
|
| 1410 | - 'event_espresso' |
|
| 1411 | - ); |
|
| 1412 | - EE_Registry::$i18n_js_strings['validation_error'] = esc_html__( |
|
| 1413 | - 'There appears to be a problem with the form validation configuration! Please check the admin settings or contact support.', |
|
| 1414 | - 'event_espresso' |
|
| 1415 | - ); |
|
| 1416 | - EE_Registry::$i18n_js_strings['invalid_payment_method'] = esc_html__( |
|
| 1417 | - 'There appears to be a problem with the payment method configuration! Please refresh the page and try again or contact support.', |
|
| 1418 | - 'event_espresso' |
|
| 1419 | - ); |
|
| 1420 | - EE_Registry::$i18n_js_strings['reg_step_error'] = esc_html__( |
|
| 1421 | - 'This registration step could not be completed. Please refresh the page and try again.', |
|
| 1422 | - 'event_espresso' |
|
| 1423 | - ); |
|
| 1424 | - EE_Registry::$i18n_js_strings['invalid_coupon'] = esc_html__( |
|
| 1425 | - 'We\'re sorry but that coupon code does not appear to be valid. If this is incorrect, please contact the site administrator.', |
|
| 1426 | - 'event_espresso' |
|
| 1427 | - ); |
|
| 1428 | - EE_Registry::$i18n_js_strings['process_registration'] = sprintf( |
|
| 1429 | - esc_html__( |
|
| 1430 | - 'Please wait while we process your registration.%sDo not refresh the page or navigate away while this is happening.%sThank you for your patience.', |
|
| 1431 | - 'event_espresso' |
|
| 1432 | - ), |
|
| 1433 | - '<br/>', |
|
| 1434 | - '<br/>' |
|
| 1435 | - ); |
|
| 1436 | - EE_Registry::$i18n_js_strings['language'] = get_bloginfo('language'); |
|
| 1437 | - EE_Registry::$i18n_js_strings['EESID'] = EE_Registry::instance()->SSN->id(); |
|
| 1438 | - EE_Registry::$i18n_js_strings['currency'] = EE_Registry::instance()->CFG->currency; |
|
| 1439 | - EE_Registry::$i18n_js_strings['datepicker_yearRange'] = '-150:+20'; |
|
| 1440 | - EE_Registry::$i18n_js_strings['timer_years'] = esc_html__('years', 'event_espresso'); |
|
| 1441 | - EE_Registry::$i18n_js_strings['timer_months'] = esc_html__('months', 'event_espresso'); |
|
| 1442 | - EE_Registry::$i18n_js_strings['timer_weeks'] = esc_html__('weeks', 'event_espresso'); |
|
| 1443 | - EE_Registry::$i18n_js_strings['timer_days'] = esc_html__('days', 'event_espresso'); |
|
| 1444 | - EE_Registry::$i18n_js_strings['timer_hours'] = esc_html__('hours', 'event_espresso'); |
|
| 1445 | - EE_Registry::$i18n_js_strings['timer_minutes'] = esc_html__('minutes', 'event_espresso'); |
|
| 1446 | - EE_Registry::$i18n_js_strings['timer_seconds'] = esc_html__('seconds', 'event_espresso'); |
|
| 1447 | - EE_Registry::$i18n_js_strings['timer_year'] = esc_html__('year', 'event_espresso'); |
|
| 1448 | - EE_Registry::$i18n_js_strings['timer_month'] = esc_html__('month', 'event_espresso'); |
|
| 1449 | - EE_Registry::$i18n_js_strings['timer_week'] = esc_html__('week', 'event_espresso'); |
|
| 1450 | - EE_Registry::$i18n_js_strings['timer_day'] = esc_html__('day', 'event_espresso'); |
|
| 1451 | - EE_Registry::$i18n_js_strings['timer_hour'] = esc_html__('hour', 'event_espresso'); |
|
| 1452 | - EE_Registry::$i18n_js_strings['timer_minute'] = esc_html__('minute', 'event_espresso'); |
|
| 1453 | - EE_Registry::$i18n_js_strings['timer_second'] = esc_html__('second', 'event_espresso'); |
|
| 1454 | - EE_Registry::$i18n_js_strings['registration_expiration_notice'] = EED_Single_Page_Checkout::getRegistrationExpirationNotice( |
|
| 1455 | - ); |
|
| 1456 | - EE_Registry::$i18n_js_strings['ajax_submit'] = apply_filters( |
|
| 1457 | - 'FHEE__Single_Page_Checkout__translate_js_strings__ajax_submit', |
|
| 1458 | - true |
|
| 1459 | - ); |
|
| 1460 | - EE_Registry::$i18n_js_strings['session_extension'] = absint( |
|
| 1461 | - apply_filters('FHEE__EE_Session__extend_expiration__seconds_added', 10 * MINUTE_IN_SECONDS) |
|
| 1462 | - ); |
|
| 1463 | - EE_Registry::$i18n_js_strings['session_expiration'] = gmdate( |
|
| 1464 | - 'M d, Y H:i:s', |
|
| 1465 | - EE_Registry::instance()->SSN->expiration() + (get_option('gmt_offset') * HOUR_IN_SECONDS) |
|
| 1466 | - ); |
|
| 1467 | - } |
|
| 1468 | - |
|
| 1469 | - |
|
| 1470 | - /** |
|
| 1471 | - * enqueue_styles_and_scripts |
|
| 1472 | - * |
|
| 1473 | - * @access public |
|
| 1474 | - * @return void |
|
| 1475 | - * @throws EE_Error |
|
| 1476 | - */ |
|
| 1477 | - public function enqueue_styles_and_scripts() |
|
| 1478 | - { |
|
| 1479 | - // load css |
|
| 1480 | - wp_register_style( |
|
| 1481 | - 'single_page_checkout', |
|
| 1482 | - SPCO_CSS_URL . 'single_page_checkout.css', |
|
| 1483 | - array('espresso_default'), |
|
| 1484 | - EVENT_ESPRESSO_VERSION |
|
| 1485 | - ); |
|
| 1486 | - wp_enqueue_style('single_page_checkout'); |
|
| 1487 | - // load JS |
|
| 1488 | - wp_register_script( |
|
| 1489 | - 'jquery_plugin', |
|
| 1490 | - EE_THIRD_PARTY_URL . 'jquery .plugin.min.js', |
|
| 1491 | - array('jquery'), |
|
| 1492 | - '1.0.1', |
|
| 1493 | - true |
|
| 1494 | - ); |
|
| 1495 | - wp_register_script( |
|
| 1496 | - 'jquery_countdown', |
|
| 1497 | - EE_THIRD_PARTY_URL . 'jquery .countdown.min.js', |
|
| 1498 | - array('jquery_plugin'), |
|
| 1499 | - '2.1.0', |
|
| 1500 | - true |
|
| 1501 | - ); |
|
| 1502 | - wp_register_script( |
|
| 1503 | - 'single_page_checkout', |
|
| 1504 | - SPCO_JS_URL . 'single_page_checkout.js', |
|
| 1505 | - array('espresso_core', 'underscore', 'ee_form_section_validation'), |
|
| 1506 | - EVENT_ESPRESSO_VERSION, |
|
| 1507 | - true |
|
| 1508 | - ); |
|
| 1509 | - if ($this->checkout->registration_form instanceof EE_Form_Section_Proper) { |
|
| 1510 | - $this->checkout->registration_form->enqueue_js(); |
|
| 1511 | - } |
|
| 1512 | - if ($this->checkout->current_step->reg_form instanceof EE_Form_Section_Proper) { |
|
| 1513 | - $this->checkout->current_step->reg_form->enqueue_js(); |
|
| 1514 | - } |
|
| 1515 | - wp_enqueue_script('single_page_checkout'); |
|
| 1516 | - if (apply_filters('FHEE__registration_page_wrapper_template__display_time_limit', false)) { |
|
| 1517 | - wp_enqueue_script('jquery_countdown'); |
|
| 1518 | - } |
|
| 1519 | - /** |
|
| 1520 | - * global action hook for enqueueing styles and scripts with |
|
| 1521 | - * spco calls. |
|
| 1522 | - */ |
|
| 1523 | - do_action('AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts', $this); |
|
| 1524 | - /** |
|
| 1525 | - * dynamic action hook for enqueueing styles and scripts with spco calls. |
|
| 1526 | - * The hook will end up being something like: |
|
| 1527 | - * AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__attendee_information |
|
| 1528 | - */ |
|
| 1529 | - do_action( |
|
| 1530 | - 'AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__' . $this->checkout->current_step->slug(), |
|
| 1531 | - $this |
|
| 1532 | - ); |
|
| 1533 | - } |
|
| 1534 | - |
|
| 1535 | - |
|
| 1536 | - /** |
|
| 1537 | - * display the Registration Single Page Checkout Form |
|
| 1538 | - * |
|
| 1539 | - * @access private |
|
| 1540 | - * @return void |
|
| 1541 | - * @throws EE_Error |
|
| 1542 | - */ |
|
| 1543 | - private function _display_spco_reg_form() |
|
| 1544 | - { |
|
| 1545 | - // if registering via the admin, just display the reg form for the current step |
|
| 1546 | - if ($this->checkout->admin_request) { |
|
| 1547 | - EE_Registry::instance()->REQ->add_output($this->checkout->current_step->display_reg_form()); |
|
| 1548 | - } else { |
|
| 1549 | - // add powered by EE msg |
|
| 1550 | - add_action('AHEE__SPCO__reg_form_footer', array('EED_Single_Page_Checkout', 'display_registration_footer')); |
|
| 1551 | - $empty_cart = count($this->checkout->transaction |
|
| 1552 | - ->registrations($this->checkout->reg_cache_where_params)) < 1; |
|
| 1553 | - EE_Registry::$i18n_js_strings['empty_cart'] = $empty_cart; |
|
| 1554 | - $cookies_not_set_msg = ''; |
|
| 1555 | - if ($empty_cart) { |
|
| 1556 | - $cookies_not_set_msg = apply_filters( |
|
| 1557 | - 'FHEE__Single_Page_Checkout__display_spco_reg_form__cookies_not_set_msg', |
|
| 1558 | - sprintf( |
|
| 1559 | - esc_html__( |
|
| 1560 | - '%1$s%3$sIt appears your browser is not currently set to accept Cookies%4$s%5$sIn order to register for events, you need to enable cookies.%7$sIf you require assistance, then click the following link to learn how to %8$senable cookies%9$s%6$s%2$s', |
|
| 1561 | - 'event_espresso' |
|
| 1562 | - ), |
|
| 1563 | - '<div class="ee-attention hidden" id="ee-cookies-not-set-msg">', |
|
| 1564 | - '</div>', |
|
| 1565 | - '<h6 class="important-notice">', |
|
| 1566 | - '</h6>', |
|
| 1567 | - '<p>', |
|
| 1568 | - '</p>', |
|
| 1569 | - '<br />', |
|
| 1570 | - '<a href="http://www.whatarecookies.com/enable.asp" target="_blank" rel="noopener noreferrer">', |
|
| 1571 | - '</a>' |
|
| 1572 | - ) |
|
| 1573 | - ); |
|
| 1574 | - } |
|
| 1575 | - $this->checkout->registration_form = new EE_Form_Section_Proper( |
|
| 1576 | - array( |
|
| 1577 | - 'name' => 'single-page-checkout', |
|
| 1578 | - 'html_id' => 'ee-single-page-checkout-dv', |
|
| 1579 | - 'layout_strategy' => |
|
| 1580 | - new EE_Template_Layout( |
|
| 1581 | - array( |
|
| 1582 | - 'layout_template_file' => SPCO_TEMPLATES_PATH . 'registration_page_wrapper.template.php', |
|
| 1583 | - 'template_args' => array( |
|
| 1584 | - 'empty_cart' => $empty_cart, |
|
| 1585 | - 'revisit' => $this->checkout->revisit, |
|
| 1586 | - 'reg_steps' => $this->checkout->reg_steps, |
|
| 1587 | - 'next_step' => $this->checkout->next_step instanceof EE_SPCO_Reg_Step |
|
| 1588 | - ? $this->checkout->next_step->slug() |
|
| 1589 | - : '', |
|
| 1590 | - 'empty_msg' => apply_filters( |
|
| 1591 | - 'FHEE__Single_Page_Checkout__display_spco_reg_form__empty_msg', |
|
| 1592 | - sprintf( |
|
| 1593 | - esc_html__( |
|
| 1594 | - 'You need to %1$sReturn to Events list%2$sselect at least one event%3$s before you can proceed with the registration process.', |
|
| 1595 | - 'event_espresso' |
|
| 1596 | - ), |
|
| 1597 | - '<a href="' |
|
| 1598 | - . get_post_type_archive_link('espresso_events') |
|
| 1599 | - . '" title="', |
|
| 1600 | - '">', |
|
| 1601 | - '</a>' |
|
| 1602 | - ) |
|
| 1603 | - ), |
|
| 1604 | - 'cookies_not_set_msg' => $cookies_not_set_msg, |
|
| 1605 | - 'registration_time_limit' => $this->checkout->get_registration_time_limit(), |
|
| 1606 | - 'session_expiration' => gmdate( |
|
| 1607 | - 'M d, Y H:i:s', |
|
| 1608 | - EE_Registry::instance()->SSN->expiration() |
|
| 1609 | - + (get_option('gmt_offset') * HOUR_IN_SECONDS) |
|
| 1610 | - ), |
|
| 1611 | - ), |
|
| 1612 | - ) |
|
| 1613 | - ), |
|
| 1614 | - ) |
|
| 1615 | - ); |
|
| 1616 | - // load template and add to output sent that gets filtered into the_content() |
|
| 1617 | - EE_Registry::instance()->REQ->add_output($this->checkout->registration_form->get_html()); |
|
| 1618 | - } |
|
| 1619 | - } |
|
| 1620 | - |
|
| 1621 | - |
|
| 1622 | - /** |
|
| 1623 | - * add_extra_finalize_registration_inputs |
|
| 1624 | - * |
|
| 1625 | - * @access public |
|
| 1626 | - * @param $next_step |
|
| 1627 | - * @internal param string $label |
|
| 1628 | - * @return void |
|
| 1629 | - */ |
|
| 1630 | - public function add_extra_finalize_registration_inputs($next_step) |
|
| 1631 | - { |
|
| 1632 | - if ($next_step === 'finalize_registration') { |
|
| 1633 | - echo '<div id="spco-extra-finalize_registration-inputs-dv"></div>'; |
|
| 1634 | - } |
|
| 1635 | - } |
|
| 1636 | - |
|
| 1637 | - |
|
| 1638 | - /** |
|
| 1639 | - * display_registration_footer |
|
| 1640 | - * |
|
| 1641 | - * @access public |
|
| 1642 | - * @return string |
|
| 1643 | - */ |
|
| 1644 | - public static function display_registration_footer() |
|
| 1645 | - { |
|
| 1646 | - if (apply_filters( |
|
| 1647 | - 'FHEE__EE_Front__Controller__show_reg_footer', |
|
| 1648 | - EE_Registry::instance()->CFG->admin->show_reg_footer |
|
| 1649 | - )) { |
|
| 1650 | - add_filter( |
|
| 1651 | - 'FHEE__EEH_Template__powered_by_event_espresso__url', |
|
| 1652 | - function ($url) { |
|
| 1653 | - return apply_filters('FHEE__EE_Front_Controller__registration_footer__url', $url); |
|
| 1654 | - } |
|
| 1655 | - ); |
|
| 1656 | - echo apply_filters( |
|
| 1657 | - 'FHEE__EE_Front_Controller__display_registration_footer', |
|
| 1658 | - \EEH_Template::powered_by_event_espresso( |
|
| 1659 | - '', |
|
| 1660 | - 'espresso-registration-footer-dv', |
|
| 1661 | - array('utm_content' => 'registration_checkout') |
|
| 1662 | - ) |
|
| 1663 | - ); |
|
| 1664 | - } |
|
| 1665 | - return ''; |
|
| 1666 | - } |
|
| 1667 | - |
|
| 1668 | - |
|
| 1669 | - /** |
|
| 1670 | - * unlock_transaction |
|
| 1671 | - * |
|
| 1672 | - * @access public |
|
| 1673 | - * @return void |
|
| 1674 | - * @throws EE_Error |
|
| 1675 | - */ |
|
| 1676 | - public function unlock_transaction() |
|
| 1677 | - { |
|
| 1678 | - if ($this->checkout->transaction instanceof EE_Transaction) { |
|
| 1679 | - $this->checkout->transaction->unlock(); |
|
| 1680 | - } |
|
| 1681 | - } |
|
| 1682 | - |
|
| 1683 | - |
|
| 1684 | - /** |
|
| 1685 | - * _setup_redirect |
|
| 1686 | - * |
|
| 1687 | - * @access private |
|
| 1688 | - * @return void |
|
| 1689 | - */ |
|
| 1690 | - private function _setup_redirect() |
|
| 1691 | - { |
|
| 1692 | - if ($this->checkout->continue_reg && $this->checkout->next_step instanceof EE_SPCO_Reg_Step) { |
|
| 1693 | - $this->checkout->redirect = true; |
|
| 1694 | - if (empty($this->checkout->redirect_url)) { |
|
| 1695 | - $this->checkout->redirect_url = $this->checkout->next_step->reg_step_url(); |
|
| 1696 | - } |
|
| 1697 | - $this->checkout->redirect_url = apply_filters( |
|
| 1698 | - 'FHEE__EED_Single_Page_Checkout___setup_redirect__checkout_redirect_url', |
|
| 1699 | - $this->checkout->redirect_url, |
|
| 1700 | - $this->checkout |
|
| 1701 | - ); |
|
| 1702 | - } |
|
| 1703 | - } |
|
| 1704 | - |
|
| 1705 | - |
|
| 1706 | - /** |
|
| 1707 | - * handle ajax message responses and redirects |
|
| 1708 | - * |
|
| 1709 | - * @access public |
|
| 1710 | - * @return void |
|
| 1711 | - * @throws EE_Error |
|
| 1712 | - */ |
|
| 1713 | - public function go_to_next_step() |
|
| 1714 | - { |
|
| 1715 | - if (EE_Registry::instance()->REQ->ajax) { |
|
| 1716 | - // capture contents of output buffer we started earlier in the request, and insert into JSON response |
|
| 1717 | - $this->checkout->json_response->set_unexpected_errors(ob_get_clean()); |
|
| 1718 | - } |
|
| 1719 | - $this->unlock_transaction(); |
|
| 1720 | - // just return for these conditions |
|
| 1721 | - if ($this->checkout->admin_request |
|
| 1722 | - || $this->checkout->action === 'redirect_form' |
|
| 1723 | - || $this->checkout->action === 'update_checkout' |
|
| 1724 | - ) { |
|
| 1725 | - return; |
|
| 1726 | - } |
|
| 1727 | - // AJAX response |
|
| 1728 | - $this->_handle_json_response(); |
|
| 1729 | - // redirect to next step or the Thank You page |
|
| 1730 | - $this->_handle_html_redirects(); |
|
| 1731 | - // hmmm... must be something wrong, so let's just display the form again ! |
|
| 1732 | - $this->_display_spco_reg_form(); |
|
| 1733 | - } |
|
| 1734 | - |
|
| 1735 | - |
|
| 1736 | - /** |
|
| 1737 | - * _handle_json_response |
|
| 1738 | - * |
|
| 1739 | - * @access protected |
|
| 1740 | - * @return void |
|
| 1741 | - */ |
|
| 1742 | - protected function _handle_json_response() |
|
| 1743 | - { |
|
| 1744 | - // if this is an ajax request |
|
| 1745 | - if (EE_Registry::instance()->REQ->ajax) { |
|
| 1746 | - $this->checkout->json_response->set_registration_time_limit( |
|
| 1747 | - $this->checkout->get_registration_time_limit() |
|
| 1748 | - ); |
|
| 1749 | - $this->checkout->json_response->set_payment_amount($this->checkout->amount_owing); |
|
| 1750 | - // just send the ajax ( |
|
| 1751 | - $json_response = apply_filters( |
|
| 1752 | - 'FHEE__EE_Single_Page_Checkout__JSON_response', |
|
| 1753 | - $this->checkout->json_response |
|
| 1754 | - ); |
|
| 1755 | - echo $json_response; |
|
| 1756 | - exit(); |
|
| 1757 | - } |
|
| 1758 | - } |
|
| 1759 | - |
|
| 1760 | - |
|
| 1761 | - /** |
|
| 1762 | - * _handle_redirects |
|
| 1763 | - * |
|
| 1764 | - * @access protected |
|
| 1765 | - * @return void |
|
| 1766 | - */ |
|
| 1767 | - protected function _handle_html_redirects() |
|
| 1768 | - { |
|
| 1769 | - // going somewhere ? |
|
| 1770 | - if ($this->checkout->redirect && ! empty($this->checkout->redirect_url)) { |
|
| 1771 | - // store notices in a transient |
|
| 1772 | - EE_Error::get_notices(false, true, true); |
|
| 1773 | - wp_safe_redirect($this->checkout->redirect_url); |
|
| 1774 | - exit(); |
|
| 1775 | - } |
|
| 1776 | - } |
|
| 1777 | - |
|
| 1778 | - |
|
| 1779 | - /** |
|
| 1780 | - * set_checkout_anchor |
|
| 1781 | - * |
|
| 1782 | - * @access public |
|
| 1783 | - * @return void |
|
| 1784 | - */ |
|
| 1785 | - public function set_checkout_anchor() |
|
| 1786 | - { |
|
| 1787 | - echo '<a id="checkout" style="float: left; margin-left: -999em;"></a>'; |
|
| 1788 | - } |
|
| 1789 | - |
|
| 1790 | - /** |
|
| 1791 | - * getRegistrationExpirationNotice |
|
| 1792 | - * |
|
| 1793 | - * @since 4.9.59.p |
|
| 1794 | - * @access public |
|
| 1795 | - * @return string |
|
| 1796 | - */ |
|
| 1797 | - public static function getRegistrationExpirationNotice() |
|
| 1798 | - { |
|
| 1799 | - return sprintf( |
|
| 1800 | - esc_html__( |
|
| 1801 | - '%1$sWe\'re sorry, but your registration time has expired.%2$s%3$s%4$sIf you still wish to complete your registration, please return to the %5$sEvent List%6$sEvent List%7$s and reselect your tickets if available. Please accept our apologies for any inconvenience this may have caused.%8$s', |
|
| 1802 | - 'event_espresso' |
|
| 1803 | - ), |
|
| 1804 | - '<h4 class="important-notice">', |
|
| 1805 | - '</h4>', |
|
| 1806 | - '<br />', |
|
| 1807 | - '<p>', |
|
| 1808 | - '<a href="' . get_post_type_archive_link('espresso_events') . '" title="', |
|
| 1809 | - '">', |
|
| 1810 | - '</a>', |
|
| 1811 | - '</p>' |
|
| 1812 | - ); |
|
| 1813 | - } |
|
| 18 | + /** |
|
| 19 | + * $_initialized - has the SPCO controller already been initialized ? |
|
| 20 | + * |
|
| 21 | + * @access private |
|
| 22 | + * @var bool $_initialized |
|
| 23 | + */ |
|
| 24 | + private static $_initialized = false; |
|
| 25 | + |
|
| 26 | + |
|
| 27 | + /** |
|
| 28 | + * $_checkout_verified - is the EE_Checkout verified as correct for this request ? |
|
| 29 | + * |
|
| 30 | + * @access private |
|
| 31 | + * @var bool $_valid_checkout |
|
| 32 | + */ |
|
| 33 | + private static $_checkout_verified = true; |
|
| 34 | + |
|
| 35 | + /** |
|
| 36 | + * $_reg_steps_array - holds initial array of reg steps |
|
| 37 | + * |
|
| 38 | + * @access private |
|
| 39 | + * @var array $_reg_steps_array |
|
| 40 | + */ |
|
| 41 | + private static $_reg_steps_array = array(); |
|
| 42 | + |
|
| 43 | + /** |
|
| 44 | + * $checkout - EE_Checkout object for handling the properties of the current checkout process |
|
| 45 | + * |
|
| 46 | + * @access public |
|
| 47 | + * @var EE_Checkout $checkout |
|
| 48 | + */ |
|
| 49 | + public $checkout; |
|
| 50 | + |
|
| 51 | + |
|
| 52 | + /** |
|
| 53 | + * @return EED_Module|EED_Single_Page_Checkout |
|
| 54 | + */ |
|
| 55 | + public static function instance() |
|
| 56 | + { |
|
| 57 | + add_filter('EED_Single_Page_Checkout__SPCO_active', '__return_true'); |
|
| 58 | + return parent::get_instance(__CLASS__); |
|
| 59 | + } |
|
| 60 | + |
|
| 61 | + |
|
| 62 | + /** |
|
| 63 | + * @return EE_CART |
|
| 64 | + */ |
|
| 65 | + public function cart() |
|
| 66 | + { |
|
| 67 | + return $this->checkout->cart; |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + |
|
| 71 | + /** |
|
| 72 | + * @return EE_Transaction |
|
| 73 | + */ |
|
| 74 | + public function transaction() |
|
| 75 | + { |
|
| 76 | + return $this->checkout->transaction; |
|
| 77 | + } |
|
| 78 | + |
|
| 79 | + |
|
| 80 | + /** |
|
| 81 | + * set_hooks - for hooking into EE Core, other modules, etc |
|
| 82 | + * |
|
| 83 | + * @access public |
|
| 84 | + * @return void |
|
| 85 | + * @throws EE_Error |
|
| 86 | + */ |
|
| 87 | + public static function set_hooks() |
|
| 88 | + { |
|
| 89 | + EED_Single_Page_Checkout::set_definitions(); |
|
| 90 | + } |
|
| 91 | + |
|
| 92 | + |
|
| 93 | + /** |
|
| 94 | + * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
| 95 | + * |
|
| 96 | + * @access public |
|
| 97 | + * @return void |
|
| 98 | + * @throws EE_Error |
|
| 99 | + */ |
|
| 100 | + public static function set_hooks_admin() |
|
| 101 | + { |
|
| 102 | + EED_Single_Page_Checkout::set_definitions(); |
|
| 103 | + if (! (defined('DOING_AJAX') && DOING_AJAX)) { |
|
| 104 | + return; |
|
| 105 | + } |
|
| 106 | + // going to start an output buffer in case anything gets accidentally output |
|
| 107 | + // that might disrupt our JSON response |
|
| 108 | + ob_start(); |
|
| 109 | + EED_Single_Page_Checkout::load_request_handler(); |
|
| 110 | + EED_Single_Page_Checkout::load_reg_steps(); |
|
| 111 | + // set ajax hooks |
|
| 112 | + add_action('wp_ajax_process_reg_step', array('EED_Single_Page_Checkout', 'process_reg_step')); |
|
| 113 | + add_action('wp_ajax_nopriv_process_reg_step', array('EED_Single_Page_Checkout', 'process_reg_step')); |
|
| 114 | + add_action('wp_ajax_display_spco_reg_step', array('EED_Single_Page_Checkout', 'display_reg_step')); |
|
| 115 | + add_action('wp_ajax_nopriv_display_spco_reg_step', array('EED_Single_Page_Checkout', 'display_reg_step')); |
|
| 116 | + add_action('wp_ajax_update_reg_step', array('EED_Single_Page_Checkout', 'update_reg_step')); |
|
| 117 | + add_action('wp_ajax_nopriv_update_reg_step', array('EED_Single_Page_Checkout', 'update_reg_step')); |
|
| 118 | + } |
|
| 119 | + |
|
| 120 | + |
|
| 121 | + /** |
|
| 122 | + * process ajax request |
|
| 123 | + * |
|
| 124 | + * @param string $ajax_action |
|
| 125 | + * @throws EE_Error |
|
| 126 | + */ |
|
| 127 | + public static function process_ajax_request($ajax_action) |
|
| 128 | + { |
|
| 129 | + EE_Registry::instance()->REQ->set('action', $ajax_action); |
|
| 130 | + EED_Single_Page_Checkout::instance()->_initialize(); |
|
| 131 | + } |
|
| 132 | + |
|
| 133 | + |
|
| 134 | + /** |
|
| 135 | + * ajax display registration step |
|
| 136 | + * |
|
| 137 | + * @throws EE_Error |
|
| 138 | + */ |
|
| 139 | + public static function display_reg_step() |
|
| 140 | + { |
|
| 141 | + EED_Single_Page_Checkout::process_ajax_request('display_spco_reg_step'); |
|
| 142 | + } |
|
| 143 | + |
|
| 144 | + |
|
| 145 | + /** |
|
| 146 | + * ajax process registration step |
|
| 147 | + * |
|
| 148 | + * @throws EE_Error |
|
| 149 | + */ |
|
| 150 | + public static function process_reg_step() |
|
| 151 | + { |
|
| 152 | + EED_Single_Page_Checkout::process_ajax_request('process_reg_step'); |
|
| 153 | + } |
|
| 154 | + |
|
| 155 | + |
|
| 156 | + /** |
|
| 157 | + * ajax process registration step |
|
| 158 | + * |
|
| 159 | + * @throws EE_Error |
|
| 160 | + */ |
|
| 161 | + public static function update_reg_step() |
|
| 162 | + { |
|
| 163 | + EED_Single_Page_Checkout::process_ajax_request('update_reg_step'); |
|
| 164 | + } |
|
| 165 | + |
|
| 166 | + |
|
| 167 | + /** |
|
| 168 | + * update_checkout |
|
| 169 | + * |
|
| 170 | + * @access public |
|
| 171 | + * @return void |
|
| 172 | + * @throws EE_Error |
|
| 173 | + */ |
|
| 174 | + public static function update_checkout() |
|
| 175 | + { |
|
| 176 | + EED_Single_Page_Checkout::process_ajax_request('update_checkout'); |
|
| 177 | + } |
|
| 178 | + |
|
| 179 | + |
|
| 180 | + /** |
|
| 181 | + * load_request_handler |
|
| 182 | + * |
|
| 183 | + * @access public |
|
| 184 | + * @return void |
|
| 185 | + */ |
|
| 186 | + public static function load_request_handler() |
|
| 187 | + { |
|
| 188 | + // load core Request_Handler class |
|
| 189 | + if (EE_Registry::instance()->REQ !== null) { |
|
| 190 | + EE_Registry::instance()->load_core('Request_Handler'); |
|
| 191 | + } |
|
| 192 | + } |
|
| 193 | + |
|
| 194 | + |
|
| 195 | + /** |
|
| 196 | + * set_definitions |
|
| 197 | + * |
|
| 198 | + * @access public |
|
| 199 | + * @return void |
|
| 200 | + * @throws EE_Error |
|
| 201 | + */ |
|
| 202 | + public static function set_definitions() |
|
| 203 | + { |
|
| 204 | + if (defined('SPCO_BASE_PATH')) { |
|
| 205 | + return; |
|
| 206 | + } |
|
| 207 | + define( |
|
| 208 | + 'SPCO_BASE_PATH', |
|
| 209 | + rtrim(str_replace(array('\\', '/'), '/', plugin_dir_path(__FILE__)), '/') . '/' |
|
| 210 | + ); |
|
| 211 | + define('SPCO_CSS_URL', plugin_dir_url(__FILE__) . 'css/'); |
|
| 212 | + define('SPCO_IMG_URL', plugin_dir_url(__FILE__) . 'img/'); |
|
| 213 | + define('SPCO_JS_URL', plugin_dir_url(__FILE__) . 'js/'); |
|
| 214 | + define('SPCO_INC_PATH', SPCO_BASE_PATH . 'inc/'); |
|
| 215 | + define('SPCO_REG_STEPS_PATH', SPCO_BASE_PATH . 'reg_steps/'); |
|
| 216 | + define('SPCO_TEMPLATES_PATH', SPCO_BASE_PATH . 'templates/'); |
|
| 217 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(SPCO_BASE_PATH, true); |
|
| 218 | + EE_Registry::$i18n_js_strings['registration_expiration_notice'] = EED_Single_Page_Checkout::getRegistrationExpirationNotice( |
|
| 219 | + ); |
|
| 220 | + } |
|
| 221 | + |
|
| 222 | + |
|
| 223 | + /** |
|
| 224 | + * load_reg_steps |
|
| 225 | + * loads and instantiates each reg step based on the EE_Registry::instance()->CFG->registration->reg_steps array |
|
| 226 | + * |
|
| 227 | + * @access private |
|
| 228 | + * @throws EE_Error |
|
| 229 | + */ |
|
| 230 | + public static function load_reg_steps() |
|
| 231 | + { |
|
| 232 | + static $reg_steps_loaded = false; |
|
| 233 | + if ($reg_steps_loaded) { |
|
| 234 | + return; |
|
| 235 | + } |
|
| 236 | + // filter list of reg_steps |
|
| 237 | + $reg_steps_to_load = (array) apply_filters( |
|
| 238 | + 'AHEE__SPCO__load_reg_steps__reg_steps_to_load', |
|
| 239 | + EED_Single_Page_Checkout::get_reg_steps() |
|
| 240 | + ); |
|
| 241 | + // sort by key (order) |
|
| 242 | + ksort($reg_steps_to_load); |
|
| 243 | + // loop through folders |
|
| 244 | + foreach ($reg_steps_to_load as $order => $reg_step) { |
|
| 245 | + // we need a |
|
| 246 | + if (isset($reg_step['file_path'], $reg_step['class_name'], $reg_step['slug'])) { |
|
| 247 | + // copy over to the reg_steps_array |
|
| 248 | + EED_Single_Page_Checkout::$_reg_steps_array[ $order ] = $reg_step; |
|
| 249 | + // register custom key route for each reg step |
|
| 250 | + // ie: step=>"slug" - this is the entire reason we load the reg steps array now |
|
| 251 | + EE_Config::register_route( |
|
| 252 | + $reg_step['slug'], |
|
| 253 | + 'EED_Single_Page_Checkout', |
|
| 254 | + 'run', |
|
| 255 | + 'step' |
|
| 256 | + ); |
|
| 257 | + // add AJAX or other hooks |
|
| 258 | + if (isset($reg_step['has_hooks']) && $reg_step['has_hooks']) { |
|
| 259 | + // setup autoloaders if necessary |
|
| 260 | + if (! class_exists($reg_step['class_name'])) { |
|
| 261 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder( |
|
| 262 | + $reg_step['file_path'], |
|
| 263 | + true |
|
| 264 | + ); |
|
| 265 | + } |
|
| 266 | + if (is_callable($reg_step['class_name'], 'set_hooks')) { |
|
| 267 | + call_user_func(array($reg_step['class_name'], 'set_hooks')); |
|
| 268 | + } |
|
| 269 | + } |
|
| 270 | + } |
|
| 271 | + } |
|
| 272 | + $reg_steps_loaded = true; |
|
| 273 | + } |
|
| 274 | + |
|
| 275 | + |
|
| 276 | + /** |
|
| 277 | + * get_reg_steps |
|
| 278 | + * |
|
| 279 | + * @access public |
|
| 280 | + * @return array |
|
| 281 | + */ |
|
| 282 | + public static function get_reg_steps() |
|
| 283 | + { |
|
| 284 | + $reg_steps = EE_Registry::instance()->CFG->registration->reg_steps; |
|
| 285 | + if (empty($reg_steps)) { |
|
| 286 | + $reg_steps = array( |
|
| 287 | + 10 => array( |
|
| 288 | + 'file_path' => SPCO_REG_STEPS_PATH . 'attendee_information', |
|
| 289 | + 'class_name' => 'EE_SPCO_Reg_Step_Attendee_Information', |
|
| 290 | + 'slug' => 'attendee_information', |
|
| 291 | + 'has_hooks' => false, |
|
| 292 | + ), |
|
| 293 | + 30 => array( |
|
| 294 | + 'file_path' => SPCO_REG_STEPS_PATH . 'payment_options', |
|
| 295 | + 'class_name' => 'EE_SPCO_Reg_Step_Payment_Options', |
|
| 296 | + 'slug' => 'payment_options', |
|
| 297 | + 'has_hooks' => true, |
|
| 298 | + ), |
|
| 299 | + 999 => array( |
|
| 300 | + 'file_path' => SPCO_REG_STEPS_PATH . 'finalize_registration', |
|
| 301 | + 'class_name' => 'EE_SPCO_Reg_Step_Finalize_Registration', |
|
| 302 | + 'slug' => 'finalize_registration', |
|
| 303 | + 'has_hooks' => false, |
|
| 304 | + ), |
|
| 305 | + ); |
|
| 306 | + } |
|
| 307 | + return $reg_steps; |
|
| 308 | + } |
|
| 309 | + |
|
| 310 | + |
|
| 311 | + /** |
|
| 312 | + * registration_checkout_for_admin |
|
| 313 | + * |
|
| 314 | + * @access public |
|
| 315 | + * @return string |
|
| 316 | + * @throws EE_Error |
|
| 317 | + */ |
|
| 318 | + public static function registration_checkout_for_admin() |
|
| 319 | + { |
|
| 320 | + EED_Single_Page_Checkout::load_request_handler(); |
|
| 321 | + EE_Registry::instance()->REQ->set('step', 'attendee_information'); |
|
| 322 | + EE_Registry::instance()->REQ->set('action', 'display_spco_reg_step'); |
|
| 323 | + EE_Registry::instance()->REQ->set('process_form_submission', false); |
|
| 324 | + EED_Single_Page_Checkout::instance()->_initialize(); |
|
| 325 | + EED_Single_Page_Checkout::instance()->_display_spco_reg_form(); |
|
| 326 | + return EE_Registry::instance()->REQ->get_output(); |
|
| 327 | + } |
|
| 328 | + |
|
| 329 | + |
|
| 330 | + /** |
|
| 331 | + * process_registration_from_admin |
|
| 332 | + * |
|
| 333 | + * @access public |
|
| 334 | + * @return \EE_Transaction |
|
| 335 | + * @throws EE_Error |
|
| 336 | + */ |
|
| 337 | + public static function process_registration_from_admin() |
|
| 338 | + { |
|
| 339 | + EED_Single_Page_Checkout::load_request_handler(); |
|
| 340 | + EE_Registry::instance()->REQ->set('step', 'attendee_information'); |
|
| 341 | + EE_Registry::instance()->REQ->set('action', 'process_reg_step'); |
|
| 342 | + EE_Registry::instance()->REQ->set('process_form_submission', true); |
|
| 343 | + EED_Single_Page_Checkout::instance()->_initialize(); |
|
| 344 | + if (EED_Single_Page_Checkout::instance()->checkout->current_step->completed()) { |
|
| 345 | + $final_reg_step = end(EED_Single_Page_Checkout::instance()->checkout->reg_steps); |
|
| 346 | + if ($final_reg_step instanceof EE_SPCO_Reg_Step_Finalize_Registration) { |
|
| 347 | + EED_Single_Page_Checkout::instance()->checkout->set_reg_step_initiated($final_reg_step); |
|
| 348 | + if ($final_reg_step->process_reg_step()) { |
|
| 349 | + $final_reg_step->set_completed(); |
|
| 350 | + EED_Single_Page_Checkout::instance()->checkout->update_txn_reg_steps_array(); |
|
| 351 | + return EED_Single_Page_Checkout::instance()->checkout->transaction; |
|
| 352 | + } |
|
| 353 | + } |
|
| 354 | + } |
|
| 355 | + return null; |
|
| 356 | + } |
|
| 357 | + |
|
| 358 | + |
|
| 359 | + /** |
|
| 360 | + * run |
|
| 361 | + * |
|
| 362 | + * @access public |
|
| 363 | + * @param WP_Query $WP_Query |
|
| 364 | + * @return void |
|
| 365 | + * @throws EE_Error |
|
| 366 | + */ |
|
| 367 | + public function run($WP_Query) |
|
| 368 | + { |
|
| 369 | + if ($WP_Query instanceof WP_Query |
|
| 370 | + && $WP_Query->is_main_query() |
|
| 371 | + && apply_filters('FHEE__EED_Single_Page_Checkout__run', true) |
|
| 372 | + && $this->_is_reg_checkout() |
|
| 373 | + ) { |
|
| 374 | + $this->_initialize(); |
|
| 375 | + } |
|
| 376 | + } |
|
| 377 | + |
|
| 378 | + |
|
| 379 | + /** |
|
| 380 | + * determines whether current url matches reg page url |
|
| 381 | + * |
|
| 382 | + * @return bool |
|
| 383 | + */ |
|
| 384 | + protected function _is_reg_checkout() |
|
| 385 | + { |
|
| 386 | + // get current permalink for reg page without any extra query args |
|
| 387 | + $reg_page_url = \get_permalink(EE_Config::instance()->core->reg_page_id); |
|
| 388 | + // get request URI for current request, but without the scheme or host |
|
| 389 | + $current_request_uri = \EEH_URL::filter_input_server_url('REQUEST_URI'); |
|
| 390 | + $current_request_uri = html_entity_decode($current_request_uri); |
|
| 391 | + // get array of query args from the current request URI |
|
| 392 | + $query_args = \EEH_URL::get_query_string($current_request_uri); |
|
| 393 | + // grab page id if it is set |
|
| 394 | + $page_id = isset($query_args['page_id']) ? absint($query_args['page_id']) : 0; |
|
| 395 | + // and remove the page id from the query args (we will re-add it later) |
|
| 396 | + unset($query_args['page_id']); |
|
| 397 | + // now strip all query args from current request URI |
|
| 398 | + $current_request_uri = remove_query_arg(array_keys($query_args), $current_request_uri); |
|
| 399 | + // and re-add the page id if it was set |
|
| 400 | + if ($page_id) { |
|
| 401 | + $current_request_uri = add_query_arg('page_id', $page_id, $current_request_uri); |
|
| 402 | + } |
|
| 403 | + // remove slashes and ? |
|
| 404 | + $current_request_uri = trim($current_request_uri, '?/'); |
|
| 405 | + // is current request URI part of the known full reg page URL ? |
|
| 406 | + return ! empty($current_request_uri) && strpos($reg_page_url, $current_request_uri) !== false; |
|
| 407 | + } |
|
| 408 | + |
|
| 409 | + |
|
| 410 | + /** |
|
| 411 | + * @param WP_Query $wp_query |
|
| 412 | + * @return void |
|
| 413 | + * @throws EE_Error |
|
| 414 | + */ |
|
| 415 | + public static function init($wp_query) |
|
| 416 | + { |
|
| 417 | + EED_Single_Page_Checkout::instance()->run($wp_query); |
|
| 418 | + } |
|
| 419 | + |
|
| 420 | + |
|
| 421 | + /** |
|
| 422 | + * _initialize - initial module setup |
|
| 423 | + * |
|
| 424 | + * @access private |
|
| 425 | + * @throws EE_Error |
|
| 426 | + * @return void |
|
| 427 | + */ |
|
| 428 | + private function _initialize() |
|
| 429 | + { |
|
| 430 | + // ensure SPCO doesn't run twice |
|
| 431 | + if (EED_Single_Page_Checkout::$_initialized) { |
|
| 432 | + return; |
|
| 433 | + } |
|
| 434 | + try { |
|
| 435 | + EED_Single_Page_Checkout::load_reg_steps(); |
|
| 436 | + $this->_verify_session(); |
|
| 437 | + // setup the EE_Checkout object |
|
| 438 | + $this->checkout = $this->_initialize_checkout(); |
|
| 439 | + // filter checkout |
|
| 440 | + $this->checkout = apply_filters('FHEE__EED_Single_Page_Checkout___initialize__checkout', $this->checkout); |
|
| 441 | + // get the $_GET |
|
| 442 | + $this->_get_request_vars(); |
|
| 443 | + if ($this->_block_bots()) { |
|
| 444 | + return; |
|
| 445 | + } |
|
| 446 | + // filter continue_reg |
|
| 447 | + $this->checkout->continue_reg = apply_filters( |
|
| 448 | + 'FHEE__EED_Single_Page_Checkout__init___continue_reg', |
|
| 449 | + true, |
|
| 450 | + $this->checkout |
|
| 451 | + ); |
|
| 452 | + // load the reg steps array |
|
| 453 | + if (! $this->_load_and_instantiate_reg_steps()) { |
|
| 454 | + EED_Single_Page_Checkout::$_initialized = true; |
|
| 455 | + return; |
|
| 456 | + } |
|
| 457 | + // set the current step |
|
| 458 | + $this->checkout->set_current_step($this->checkout->step); |
|
| 459 | + // and the next step |
|
| 460 | + $this->checkout->set_next_step(); |
|
| 461 | + // verify that everything has been setup correctly |
|
| 462 | + if (! ($this->_verify_transaction_and_get_registrations() && $this->_final_verifications())) { |
|
| 463 | + EED_Single_Page_Checkout::$_initialized = true; |
|
| 464 | + return; |
|
| 465 | + } |
|
| 466 | + // lock the transaction |
|
| 467 | + $this->checkout->transaction->lock(); |
|
| 468 | + // make sure all of our cached objects are added to their respective model entity mappers |
|
| 469 | + $this->checkout->refresh_all_entities(); |
|
| 470 | + // set amount owing |
|
| 471 | + $this->checkout->amount_owing = $this->checkout->transaction->remaining(); |
|
| 472 | + // initialize each reg step, which gives them the chance to potentially alter the process |
|
| 473 | + $this->_initialize_reg_steps(); |
|
| 474 | + // DEBUG LOG |
|
| 475 | + // $this->checkout->log( __CLASS__, __FUNCTION__, __LINE__ ); |
|
| 476 | + // get reg form |
|
| 477 | + if (! $this->_check_form_submission()) { |
|
| 478 | + EED_Single_Page_Checkout::$_initialized = true; |
|
| 479 | + return; |
|
| 480 | + } |
|
| 481 | + // checkout the action!!! |
|
| 482 | + $this->_process_form_action(); |
|
| 483 | + // add some style and make it dance |
|
| 484 | + $this->add_styles_and_scripts(); |
|
| 485 | + // kk... SPCO has successfully run |
|
| 486 | + EED_Single_Page_Checkout::$_initialized = true; |
|
| 487 | + // set no cache headers and constants |
|
| 488 | + EE_System::do_not_cache(); |
|
| 489 | + // add anchor |
|
| 490 | + add_action('loop_start', array($this, 'set_checkout_anchor'), 1); |
|
| 491 | + // remove transaction lock |
|
| 492 | + add_action('shutdown', array($this, 'unlock_transaction'), 1); |
|
| 493 | + } catch (Exception $e) { |
|
| 494 | + EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
| 495 | + } |
|
| 496 | + } |
|
| 497 | + |
|
| 498 | + |
|
| 499 | + /** |
|
| 500 | + * _verify_session |
|
| 501 | + * checks that the session is valid and not expired |
|
| 502 | + * |
|
| 503 | + * @access private |
|
| 504 | + * @throws EE_Error |
|
| 505 | + */ |
|
| 506 | + private function _verify_session() |
|
| 507 | + { |
|
| 508 | + if (! EE_Registry::instance()->SSN instanceof EE_Session) { |
|
| 509 | + throw new EE_Error(esc_html__('The EE_Session class could not be loaded.', 'event_espresso')); |
|
| 510 | + } |
|
| 511 | + $clear_session_requested = filter_var( |
|
| 512 | + EE_Registry::instance()->REQ->get('clear_session', false), |
|
| 513 | + FILTER_VALIDATE_BOOLEAN |
|
| 514 | + ); |
|
| 515 | + // is session still valid ? |
|
| 516 | + if ($clear_session_requested |
|
| 517 | + || (EE_Registry::instance()->SSN->expired() |
|
| 518 | + && EE_Registry::instance()->REQ->get('e_reg_url_link', '') === '' |
|
| 519 | + ) |
|
| 520 | + ) { |
|
| 521 | + $this->checkout = new EE_Checkout(); |
|
| 522 | + EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__); |
|
| 523 | + // EE_Registry::instance()->SSN->reset_cart(); |
|
| 524 | + // EE_Registry::instance()->SSN->reset_checkout(); |
|
| 525 | + // EE_Registry::instance()->SSN->reset_transaction(); |
|
| 526 | + if (! $clear_session_requested) { |
|
| 527 | + EE_Error::add_attention( |
|
| 528 | + EE_Registry::$i18n_js_strings['registration_expiration_notice'], |
|
| 529 | + __FILE__, |
|
| 530 | + __FUNCTION__, |
|
| 531 | + __LINE__ |
|
| 532 | + ); |
|
| 533 | + } |
|
| 534 | + // EE_Registry::instance()->SSN->reset_expired(); |
|
| 535 | + } |
|
| 536 | + } |
|
| 537 | + |
|
| 538 | + |
|
| 539 | + /** |
|
| 540 | + * _initialize_checkout |
|
| 541 | + * loads and instantiates EE_Checkout |
|
| 542 | + * |
|
| 543 | + * @access private |
|
| 544 | + * @throws EE_Error |
|
| 545 | + * @return EE_Checkout |
|
| 546 | + */ |
|
| 547 | + private function _initialize_checkout() |
|
| 548 | + { |
|
| 549 | + // look in session for existing checkout |
|
| 550 | + /** @type EE_Checkout $checkout */ |
|
| 551 | + $checkout = EE_Registry::instance()->SSN->checkout(); |
|
| 552 | + // verify |
|
| 553 | + if (! $checkout instanceof EE_Checkout) { |
|
| 554 | + // instantiate EE_Checkout object for handling the properties of the current checkout process |
|
| 555 | + $checkout = EE_Registry::instance()->load_file( |
|
| 556 | + SPCO_INC_PATH, |
|
| 557 | + 'EE_Checkout', |
|
| 558 | + 'class', |
|
| 559 | + array(), |
|
| 560 | + false |
|
| 561 | + ); |
|
| 562 | + } else { |
|
| 563 | + if ($checkout->current_step->is_final_step() && $checkout->exit_spco() === true) { |
|
| 564 | + $this->unlock_transaction(); |
|
| 565 | + wp_safe_redirect($checkout->redirect_url); |
|
| 566 | + exit(); |
|
| 567 | + } |
|
| 568 | + } |
|
| 569 | + $checkout = apply_filters('FHEE__EED_Single_Page_Checkout___initialize_checkout__checkout', $checkout); |
|
| 570 | + // verify again |
|
| 571 | + if (! $checkout instanceof EE_Checkout) { |
|
| 572 | + throw new EE_Error(esc_html__('The EE_Checkout class could not be loaded.', 'event_espresso')); |
|
| 573 | + } |
|
| 574 | + // reset anything that needs a clean slate for each request |
|
| 575 | + $checkout->reset_for_current_request(); |
|
| 576 | + return $checkout; |
|
| 577 | + } |
|
| 578 | + |
|
| 579 | + |
|
| 580 | + /** |
|
| 581 | + * _get_request_vars |
|
| 582 | + * |
|
| 583 | + * @access private |
|
| 584 | + * @return void |
|
| 585 | + * @throws EE_Error |
|
| 586 | + */ |
|
| 587 | + private function _get_request_vars() |
|
| 588 | + { |
|
| 589 | + // load classes |
|
| 590 | + EED_Single_Page_Checkout::load_request_handler(); |
|
| 591 | + // make sure this request is marked as belonging to EE |
|
| 592 | + EE_Registry::instance()->REQ->set_espresso_page(true); |
|
| 593 | + // which step is being requested ? |
|
| 594 | + $this->checkout->step = EE_Registry::instance()->REQ->get('step', $this->_get_first_step()); |
|
| 595 | + // which step is being edited ? |
|
| 596 | + $this->checkout->edit_step = EE_Registry::instance()->REQ->get('edit_step', ''); |
|
| 597 | + // and what we're doing on the current step |
|
| 598 | + $this->checkout->action = EE_Registry::instance()->REQ->get('action', 'display_spco_reg_step'); |
|
| 599 | + // timestamp |
|
| 600 | + $this->checkout->uts = EE_Registry::instance()->REQ->get('uts', 0); |
|
| 601 | + // returning to edit ? |
|
| 602 | + $this->checkout->reg_url_link = EE_Registry::instance()->REQ->get('e_reg_url_link', ''); |
|
| 603 | + // add reg url link to registration query params |
|
| 604 | + if ($this->checkout->reg_url_link && strpos($this->checkout->reg_url_link, '1-') !== 0) { |
|
| 605 | + $this->checkout->reg_cache_where_params[0]['REG_url_link'] = $this->checkout->reg_url_link; |
|
| 606 | + } |
|
| 607 | + // or some other kind of revisit ? |
|
| 608 | + $this->checkout->revisit = filter_var( |
|
| 609 | + EE_Registry::instance()->REQ->get('revisit', false), |
|
| 610 | + FILTER_VALIDATE_BOOLEAN |
|
| 611 | + ); |
|
| 612 | + // and whether or not to generate a reg form for this request |
|
| 613 | + $this->checkout->generate_reg_form = filter_var( |
|
| 614 | + EE_Registry::instance()->REQ->get('generate_reg_form', true), |
|
| 615 | + FILTER_VALIDATE_BOOLEAN |
|
| 616 | + ); |
|
| 617 | + // and whether or not to process a reg form submission for this request |
|
| 618 | + $this->checkout->process_form_submission = filter_var( |
|
| 619 | + EE_Registry::instance()->REQ->get( |
|
| 620 | + 'process_form_submission', |
|
| 621 | + $this->checkout->action === 'process_reg_step' |
|
| 622 | + ), |
|
| 623 | + FILTER_VALIDATE_BOOLEAN |
|
| 624 | + ); |
|
| 625 | + $this->checkout->process_form_submission = filter_var( |
|
| 626 | + $this->checkout->action !== 'display_spco_reg_step' |
|
| 627 | + ? $this->checkout->process_form_submission |
|
| 628 | + : false, |
|
| 629 | + FILTER_VALIDATE_BOOLEAN |
|
| 630 | + ); |
|
| 631 | + // $this->_display_request_vars(); |
|
| 632 | + } |
|
| 633 | + |
|
| 634 | + |
|
| 635 | + /** |
|
| 636 | + * _display_request_vars |
|
| 637 | + * |
|
| 638 | + * @access protected |
|
| 639 | + * @return void |
|
| 640 | + */ |
|
| 641 | + protected function _display_request_vars() |
|
| 642 | + { |
|
| 643 | + if (! WP_DEBUG) { |
|
| 644 | + return; |
|
| 645 | + } |
|
| 646 | + EEH_Debug_Tools::printr($_REQUEST, '$_REQUEST', __FILE__, __LINE__); |
|
| 647 | + EEH_Debug_Tools::printr($this->checkout->step, '$this->checkout->step', __FILE__, __LINE__); |
|
| 648 | + EEH_Debug_Tools::printr($this->checkout->edit_step, '$this->checkout->edit_step', __FILE__, __LINE__); |
|
| 649 | + EEH_Debug_Tools::printr($this->checkout->action, '$this->checkout->action', __FILE__, __LINE__); |
|
| 650 | + EEH_Debug_Tools::printr($this->checkout->reg_url_link, '$this->checkout->reg_url_link', __FILE__, __LINE__); |
|
| 651 | + EEH_Debug_Tools::printr($this->checkout->revisit, '$this->checkout->revisit', __FILE__, __LINE__); |
|
| 652 | + EEH_Debug_Tools::printr( |
|
| 653 | + $this->checkout->generate_reg_form, |
|
| 654 | + '$this->checkout->generate_reg_form', |
|
| 655 | + __FILE__, |
|
| 656 | + __LINE__ |
|
| 657 | + ); |
|
| 658 | + EEH_Debug_Tools::printr( |
|
| 659 | + $this->checkout->process_form_submission, |
|
| 660 | + '$this->checkout->process_form_submission', |
|
| 661 | + __FILE__, |
|
| 662 | + __LINE__ |
|
| 663 | + ); |
|
| 664 | + } |
|
| 665 | + |
|
| 666 | + |
|
| 667 | + /** |
|
| 668 | + * _block_bots |
|
| 669 | + * checks that the incoming request has either of the following set: |
|
| 670 | + * a uts (unix timestamp) which indicates that the request was redirected from the Ticket Selector |
|
| 671 | + * a REG URL Link, which indicates that the request is a return visit to SPCO for a valid TXN |
|
| 672 | + * so if you're not coming from the Ticket Selector nor returning for a valid IP... |
|
| 673 | + * then where you coming from man? |
|
| 674 | + * |
|
| 675 | + * @return boolean |
|
| 676 | + */ |
|
| 677 | + private function _block_bots() |
|
| 678 | + { |
|
| 679 | + $invalid_checkout_access = EED_Invalid_Checkout_Access::getInvalidCheckoutAccess(); |
|
| 680 | + if ($invalid_checkout_access->checkoutAccessIsInvalid($this->checkout)) { |
|
| 681 | + return true; |
|
| 682 | + } |
|
| 683 | + return false; |
|
| 684 | + } |
|
| 685 | + |
|
| 686 | + |
|
| 687 | + /** |
|
| 688 | + * _get_first_step |
|
| 689 | + * gets slug for first step in $_reg_steps_array |
|
| 690 | + * |
|
| 691 | + * @access private |
|
| 692 | + * @throws EE_Error |
|
| 693 | + * @return string |
|
| 694 | + */ |
|
| 695 | + private function _get_first_step() |
|
| 696 | + { |
|
| 697 | + $first_step = reset(EED_Single_Page_Checkout::$_reg_steps_array); |
|
| 698 | + return isset($first_step['slug']) ? $first_step['slug'] : 'attendee_information'; |
|
| 699 | + } |
|
| 700 | + |
|
| 701 | + |
|
| 702 | + /** |
|
| 703 | + * instantiates each reg step based on the loaded reg_steps array |
|
| 704 | + * |
|
| 705 | + * @return bool |
|
| 706 | + * @throws EE_Error |
|
| 707 | + * @throws InvalidArgumentException |
|
| 708 | + * @throws InvalidDataTypeException |
|
| 709 | + * @throws InvalidInterfaceException |
|
| 710 | + */ |
|
| 711 | + private function _load_and_instantiate_reg_steps() |
|
| 712 | + { |
|
| 713 | + do_action('AHEE__Single_Page_Checkout___load_and_instantiate_reg_steps__start', $this->checkout); |
|
| 714 | + // have reg_steps already been instantiated ? |
|
| 715 | + if (empty($this->checkout->reg_steps) |
|
| 716 | + || apply_filters('FHEE__Single_Page_Checkout__load_reg_steps__reload_reg_steps', false, $this->checkout) |
|
| 717 | + ) { |
|
| 718 | + // if not, then loop through raw reg steps array |
|
| 719 | + foreach (EED_Single_Page_Checkout::$_reg_steps_array as $order => $reg_step) { |
|
| 720 | + if (! $this->_load_and_instantiate_reg_step($reg_step, $order)) { |
|
| 721 | + return false; |
|
| 722 | + } |
|
| 723 | + } |
|
| 724 | + if (isset($this->checkout->reg_steps['registration_confirmation'])) { |
|
| 725 | + // skip the registration_confirmation page ? |
|
| 726 | + if (EE_Registry::instance()->CFG->registration->skip_reg_confirmation) { |
|
| 727 | + // just remove it from the reg steps array |
|
| 728 | + $this->checkout->remove_reg_step('registration_confirmation', false); |
|
| 729 | + } elseif (EE_Registry::instance()->CFG->registration->reg_confirmation_last |
|
| 730 | + ) { |
|
| 731 | + // set the order to something big like 100 |
|
| 732 | + $this->checkout->set_reg_step_order('registration_confirmation', 100); |
|
| 733 | + } |
|
| 734 | + } |
|
| 735 | + // filter the array for good luck |
|
| 736 | + $this->checkout->reg_steps = apply_filters( |
|
| 737 | + 'FHEE__Single_Page_Checkout__load_reg_steps__reg_steps', |
|
| 738 | + $this->checkout->reg_steps |
|
| 739 | + ); |
|
| 740 | + // finally re-sort based on the reg step class order properties |
|
| 741 | + $this->checkout->sort_reg_steps(); |
|
| 742 | + } else { |
|
| 743 | + foreach ($this->checkout->reg_steps as $reg_step) { |
|
| 744 | + // set all current step stati to FALSE |
|
| 745 | + $reg_step->set_is_current_step(false); |
|
| 746 | + } |
|
| 747 | + } |
|
| 748 | + if (empty($this->checkout->reg_steps)) { |
|
| 749 | + EE_Error::add_error( |
|
| 750 | + esc_html__('No Reg Steps were loaded..', 'event_espresso'), |
|
| 751 | + __FILE__, |
|
| 752 | + __FUNCTION__, |
|
| 753 | + __LINE__ |
|
| 754 | + ); |
|
| 755 | + return false; |
|
| 756 | + } |
|
| 757 | + // make reg step details available to JS |
|
| 758 | + $this->checkout->set_reg_step_JSON_info(); |
|
| 759 | + return true; |
|
| 760 | + } |
|
| 761 | + |
|
| 762 | + |
|
| 763 | + /** |
|
| 764 | + * _load_and_instantiate_reg_step |
|
| 765 | + * |
|
| 766 | + * @access private |
|
| 767 | + * @param array $reg_step |
|
| 768 | + * @param int $order |
|
| 769 | + * @return bool |
|
| 770 | + */ |
|
| 771 | + private function _load_and_instantiate_reg_step($reg_step = array(), $order = 0) |
|
| 772 | + { |
|
| 773 | + // we need a file_path, class_name, and slug to add a reg step |
|
| 774 | + if (isset($reg_step['file_path'], $reg_step['class_name'], $reg_step['slug'])) { |
|
| 775 | + // if editing a specific step, but this is NOT that step... (and it's not the 'finalize_registration' step) |
|
| 776 | + if ($this->checkout->reg_url_link |
|
| 777 | + && $this->checkout->step !== $reg_step['slug'] |
|
| 778 | + && $reg_step['slug'] !== 'finalize_registration' |
|
| 779 | + // normally at this point we would NOT load the reg step, but this filter can change that |
|
| 780 | + && apply_filters( |
|
| 781 | + 'FHEE__Single_Page_Checkout___load_and_instantiate_reg_step__bypass_reg_step', |
|
| 782 | + true, |
|
| 783 | + $reg_step, |
|
| 784 | + $this->checkout |
|
| 785 | + ) |
|
| 786 | + ) { |
|
| 787 | + return true; |
|
| 788 | + } |
|
| 789 | + // instantiate step class using file path and class name |
|
| 790 | + $reg_step_obj = EE_Registry::instance()->load_file( |
|
| 791 | + $reg_step['file_path'], |
|
| 792 | + $reg_step['class_name'], |
|
| 793 | + 'class', |
|
| 794 | + $this->checkout, |
|
| 795 | + false |
|
| 796 | + ); |
|
| 797 | + // did we gets the goods ? |
|
| 798 | + if ($reg_step_obj instanceof EE_SPCO_Reg_Step) { |
|
| 799 | + // set reg step order based on config |
|
| 800 | + $reg_step_obj->set_order($order); |
|
| 801 | + // add instantiated reg step object to the master reg steps array |
|
| 802 | + $this->checkout->add_reg_step($reg_step_obj); |
|
| 803 | + } else { |
|
| 804 | + EE_Error::add_error( |
|
| 805 | + esc_html__('The current step could not be set.', 'event_espresso'), |
|
| 806 | + __FILE__, |
|
| 807 | + __FUNCTION__, |
|
| 808 | + __LINE__ |
|
| 809 | + ); |
|
| 810 | + return false; |
|
| 811 | + } |
|
| 812 | + } else { |
|
| 813 | + if (WP_DEBUG) { |
|
| 814 | + EE_Error::add_error( |
|
| 815 | + sprintf( |
|
| 816 | + esc_html__( |
|
| 817 | + 'A registration step could not be loaded. One or more of the following data points is invalid:%4$s%5$sFile Path: %1$s%6$s%5$sClass Name: %2$s%6$s%5$sSlug: %3$s%6$s%7$s', |
|
| 818 | + 'event_espresso' |
|
| 819 | + ), |
|
| 820 | + isset($reg_step['file_path']) ? $reg_step['file_path'] : '', |
|
| 821 | + isset($reg_step['class_name']) ? $reg_step['class_name'] : '', |
|
| 822 | + isset($reg_step['slug']) ? $reg_step['slug'] : '', |
|
| 823 | + '<ul>', |
|
| 824 | + '<li>', |
|
| 825 | + '</li>', |
|
| 826 | + '</ul>' |
|
| 827 | + ), |
|
| 828 | + __FILE__, |
|
| 829 | + __FUNCTION__, |
|
| 830 | + __LINE__ |
|
| 831 | + ); |
|
| 832 | + } |
|
| 833 | + return false; |
|
| 834 | + } |
|
| 835 | + return true; |
|
| 836 | + } |
|
| 837 | + |
|
| 838 | + |
|
| 839 | + /** |
|
| 840 | + * _verify_transaction_and_get_registrations |
|
| 841 | + * |
|
| 842 | + * @access private |
|
| 843 | + * @return bool |
|
| 844 | + * @throws InvalidDataTypeException |
|
| 845 | + * @throws InvalidEntityException |
|
| 846 | + * @throws EE_Error |
|
| 847 | + */ |
|
| 848 | + private function _verify_transaction_and_get_registrations() |
|
| 849 | + { |
|
| 850 | + // was there already a valid transaction in the checkout from the session ? |
|
| 851 | + if (! $this->checkout->transaction instanceof EE_Transaction) { |
|
| 852 | + // get transaction from db or session |
|
| 853 | + $this->checkout->transaction = $this->checkout->reg_url_link && ! is_admin() |
|
| 854 | + ? $this->_get_transaction_and_cart_for_previous_visit() |
|
| 855 | + : $this->_get_cart_for_current_session_and_setup_new_transaction(); |
|
| 856 | + if (! $this->checkout->transaction instanceof EE_Transaction) { |
|
| 857 | + EE_Error::add_error( |
|
| 858 | + esc_html__( |
|
| 859 | + 'Your Registration and Transaction information could not be retrieved from the db.', |
|
| 860 | + 'event_espresso' |
|
| 861 | + ), |
|
| 862 | + __FILE__, |
|
| 863 | + __FUNCTION__, |
|
| 864 | + __LINE__ |
|
| 865 | + ); |
|
| 866 | + $this->checkout->transaction = EE_Transaction::new_instance(); |
|
| 867 | + // add some style and make it dance |
|
| 868 | + $this->add_styles_and_scripts(); |
|
| 869 | + EED_Single_Page_Checkout::$_initialized = true; |
|
| 870 | + return false; |
|
| 871 | + } |
|
| 872 | + // and the registrations for the transaction |
|
| 873 | + $this->_get_registrations($this->checkout->transaction); |
|
| 874 | + } |
|
| 875 | + return true; |
|
| 876 | + } |
|
| 877 | + |
|
| 878 | + |
|
| 879 | + /** |
|
| 880 | + * _get_transaction_and_cart_for_previous_visit |
|
| 881 | + * |
|
| 882 | + * @access private |
|
| 883 | + * @return mixed EE_Transaction|NULL |
|
| 884 | + */ |
|
| 885 | + private function _get_transaction_and_cart_for_previous_visit() |
|
| 886 | + { |
|
| 887 | + /** @var $TXN_model EEM_Transaction */ |
|
| 888 | + $TXN_model = EE_Registry::instance()->load_model('Transaction'); |
|
| 889 | + // because the reg_url_link is present in the request, |
|
| 890 | + // this is a return visit to SPCO, so we'll get the transaction data from the db |
|
| 891 | + $transaction = $TXN_model->get_transaction_from_reg_url_link($this->checkout->reg_url_link); |
|
| 892 | + // verify transaction |
|
| 893 | + if ($transaction instanceof EE_Transaction) { |
|
| 894 | + // and get the cart that was used for that transaction |
|
| 895 | + $this->checkout->cart = $this->_get_cart_for_transaction($transaction); |
|
| 896 | + return $transaction; |
|
| 897 | + } |
|
| 898 | + EE_Error::add_error( |
|
| 899 | + esc_html__('Your Registration and Transaction information could not be retrieved from the db.', 'event_espresso'), |
|
| 900 | + __FILE__, |
|
| 901 | + __FUNCTION__, |
|
| 902 | + __LINE__ |
|
| 903 | + ); |
|
| 904 | + return null; |
|
| 905 | + } |
|
| 906 | + |
|
| 907 | + |
|
| 908 | + /** |
|
| 909 | + * _get_cart_for_transaction |
|
| 910 | + * |
|
| 911 | + * @access private |
|
| 912 | + * @param EE_Transaction $transaction |
|
| 913 | + * @return EE_Cart |
|
| 914 | + */ |
|
| 915 | + private function _get_cart_for_transaction($transaction) |
|
| 916 | + { |
|
| 917 | + return $this->checkout->get_cart_for_transaction($transaction); |
|
| 918 | + } |
|
| 919 | + |
|
| 920 | + |
|
| 921 | + /** |
|
| 922 | + * get_cart_for_transaction |
|
| 923 | + * |
|
| 924 | + * @access public |
|
| 925 | + * @param EE_Transaction $transaction |
|
| 926 | + * @return EE_Cart |
|
| 927 | + */ |
|
| 928 | + public function get_cart_for_transaction(EE_Transaction $transaction) |
|
| 929 | + { |
|
| 930 | + return $this->checkout->get_cart_for_transaction($transaction); |
|
| 931 | + } |
|
| 932 | + |
|
| 933 | + |
|
| 934 | + /** |
|
| 935 | + * _get_transaction_and_cart_for_current_session |
|
| 936 | + * generates a new EE_Transaction object and adds it to the $_transaction property. |
|
| 937 | + * |
|
| 938 | + * @access private |
|
| 939 | + * @return EE_Transaction |
|
| 940 | + * @throws EE_Error |
|
| 941 | + */ |
|
| 942 | + private function _get_cart_for_current_session_and_setup_new_transaction() |
|
| 943 | + { |
|
| 944 | + // if there's no transaction, then this is the FIRST visit to SPCO |
|
| 945 | + // so load up the cart ( passing nothing for the TXN because it doesn't exist yet ) |
|
| 946 | + $this->checkout->cart = $this->_get_cart_for_transaction(null); |
|
| 947 | + // and then create a new transaction |
|
| 948 | + $transaction = $this->_initialize_transaction(); |
|
| 949 | + // verify transaction |
|
| 950 | + if ($transaction instanceof EE_Transaction) { |
|
| 951 | + // save it so that we have an ID for other objects to use |
|
| 952 | + $transaction->save(); |
|
| 953 | + // and save TXN data to the cart |
|
| 954 | + $this->checkout->cart->get_grand_total()->save_this_and_descendants_to_txn($transaction->ID()); |
|
| 955 | + } else { |
|
| 956 | + EE_Error::add_error( |
|
| 957 | + esc_html__('A Valid Transaction could not be initialized.', 'event_espresso'), |
|
| 958 | + __FILE__, |
|
| 959 | + __FUNCTION__, |
|
| 960 | + __LINE__ |
|
| 961 | + ); |
|
| 962 | + } |
|
| 963 | + return $transaction; |
|
| 964 | + } |
|
| 965 | + |
|
| 966 | + |
|
| 967 | + /** |
|
| 968 | + * generates a new EE_Transaction object and adds it to the $_transaction property. |
|
| 969 | + * |
|
| 970 | + * @access private |
|
| 971 | + * @return mixed EE_Transaction|NULL |
|
| 972 | + */ |
|
| 973 | + private function _initialize_transaction() |
|
| 974 | + { |
|
| 975 | + try { |
|
| 976 | + // ensure cart totals have been calculated |
|
| 977 | + $this->checkout->cart->get_grand_total()->recalculate_total_including_taxes(); |
|
| 978 | + // grab the cart grand total |
|
| 979 | + $cart_total = $this->checkout->cart->get_cart_grand_total(); |
|
| 980 | + // create new TXN |
|
| 981 | + $transaction = EE_Transaction::new_instance( |
|
| 982 | + array( |
|
| 983 | + 'TXN_reg_steps' => $this->checkout->initialize_txn_reg_steps_array(), |
|
| 984 | + 'TXN_total' => $cart_total > 0 ? $cart_total : 0, |
|
| 985 | + 'TXN_paid' => 0, |
|
| 986 | + 'STS_ID' => EEM_Transaction::failed_status_code, |
|
| 987 | + ) |
|
| 988 | + ); |
|
| 989 | + // save it so that we have an ID for other objects to use |
|
| 990 | + $transaction->save(); |
|
| 991 | + // set cron job for following up on TXNs after their session has expired |
|
| 992 | + EE_Cron_Tasks::schedule_expired_transaction_check( |
|
| 993 | + EE_Registry::instance()->SSN->expiration() + 1, |
|
| 994 | + $transaction->ID() |
|
| 995 | + ); |
|
| 996 | + return $transaction; |
|
| 997 | + } catch (Exception $e) { |
|
| 998 | + EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
| 999 | + } |
|
| 1000 | + return null; |
|
| 1001 | + } |
|
| 1002 | + |
|
| 1003 | + |
|
| 1004 | + /** |
|
| 1005 | + * _get_registrations |
|
| 1006 | + * |
|
| 1007 | + * @access private |
|
| 1008 | + * @param EE_Transaction $transaction |
|
| 1009 | + * @return void |
|
| 1010 | + * @throws InvalidDataTypeException |
|
| 1011 | + * @throws InvalidEntityException |
|
| 1012 | + * @throws EE_Error |
|
| 1013 | + */ |
|
| 1014 | + private function _get_registrations(EE_Transaction $transaction) |
|
| 1015 | + { |
|
| 1016 | + // first step: grab the registrants { : o |
|
| 1017 | + $registrations = $transaction->registrations($this->checkout->reg_cache_where_params, false); |
|
| 1018 | + $this->checkout->total_ticket_count = count($registrations); |
|
| 1019 | + // verify registrations have been set |
|
| 1020 | + if (empty($registrations)) { |
|
| 1021 | + // if no cached registrations, then check the db |
|
| 1022 | + $registrations = $transaction->registrations($this->checkout->reg_cache_where_params, false); |
|
| 1023 | + // still nothing ? well as long as this isn't a revisit |
|
| 1024 | + if (empty($registrations) && ! $this->checkout->revisit) { |
|
| 1025 | + // generate new registrations from scratch |
|
| 1026 | + $registrations = $this->_initialize_registrations($transaction); |
|
| 1027 | + } |
|
| 1028 | + } |
|
| 1029 | + // sort by their original registration order |
|
| 1030 | + usort($registrations, array('EED_Single_Page_Checkout', 'sort_registrations_by_REG_count')); |
|
| 1031 | + // then loop thru the array |
|
| 1032 | + foreach ($registrations as $registration) { |
|
| 1033 | + // verify each registration |
|
| 1034 | + if ($registration instanceof EE_Registration) { |
|
| 1035 | + // we display all attendee info for the primary registrant |
|
| 1036 | + if ($this->checkout->reg_url_link === $registration->reg_url_link() |
|
| 1037 | + && $registration->is_primary_registrant() |
|
| 1038 | + ) { |
|
| 1039 | + $this->checkout->primary_revisit = true; |
|
| 1040 | + break; |
|
| 1041 | + } |
|
| 1042 | + if ($this->checkout->revisit && $this->checkout->reg_url_link !== $registration->reg_url_link()) { |
|
| 1043 | + // but hide info if it doesn't belong to you |
|
| 1044 | + $transaction->clear_cache('Registration', $registration->ID()); |
|
| 1045 | + $this->checkout->total_ticket_count--; |
|
| 1046 | + } |
|
| 1047 | + $this->checkout->set_reg_status_updated($registration->ID(), false); |
|
| 1048 | + } |
|
| 1049 | + } |
|
| 1050 | + } |
|
| 1051 | + |
|
| 1052 | + |
|
| 1053 | + /** |
|
| 1054 | + * adds related EE_Registration objects for each ticket in the cart to the current EE_Transaction object |
|
| 1055 | + * |
|
| 1056 | + * @access private |
|
| 1057 | + * @param EE_Transaction $transaction |
|
| 1058 | + * @return array |
|
| 1059 | + * @throws InvalidDataTypeException |
|
| 1060 | + * @throws InvalidEntityException |
|
| 1061 | + * @throws EE_Error |
|
| 1062 | + */ |
|
| 1063 | + private function _initialize_registrations(EE_Transaction $transaction) |
|
| 1064 | + { |
|
| 1065 | + $att_nmbr = 0; |
|
| 1066 | + $registrations = array(); |
|
| 1067 | + if ($transaction instanceof EE_Transaction) { |
|
| 1068 | + /** @type EE_Registration_Processor $registration_processor */ |
|
| 1069 | + $registration_processor = EE_Registry::instance()->load_class('Registration_Processor'); |
|
| 1070 | + $this->checkout->total_ticket_count = $this->checkout->cart->all_ticket_quantity_count(); |
|
| 1071 | + // now let's add the cart items to the $transaction |
|
| 1072 | + foreach ($this->checkout->cart->get_tickets() as $line_item) { |
|
| 1073 | + // do the following for each ticket of this type they selected |
|
| 1074 | + for ($x = 1; $x <= $line_item->quantity(); $x++) { |
|
| 1075 | + $att_nmbr++; |
|
| 1076 | + /** @var EventEspresso\core\services\commands\registration\CreateRegistrationCommand $CreateRegistrationCommand */ |
|
| 1077 | + $CreateRegistrationCommand = EE_Registry::instance()->create( |
|
| 1078 | + 'EventEspresso\core\services\commands\registration\CreateRegistrationCommand', |
|
| 1079 | + array( |
|
| 1080 | + $transaction, |
|
| 1081 | + $line_item, |
|
| 1082 | + $att_nmbr, |
|
| 1083 | + $this->checkout->total_ticket_count, |
|
| 1084 | + ) |
|
| 1085 | + ); |
|
| 1086 | + // override capabilities for frontend registrations |
|
| 1087 | + if (! is_admin()) { |
|
| 1088 | + $CreateRegistrationCommand->setCapCheck( |
|
| 1089 | + new PublicCapabilities('', 'create_new_registration') |
|
| 1090 | + ); |
|
| 1091 | + } |
|
| 1092 | + $registration = EE_Registry::instance()->BUS->execute($CreateRegistrationCommand); |
|
| 1093 | + if (! $registration instanceof EE_Registration) { |
|
| 1094 | + throw new InvalidEntityException($registration, 'EE_Registration'); |
|
| 1095 | + } |
|
| 1096 | + $registrations[ $registration->ID() ] = $registration; |
|
| 1097 | + } |
|
| 1098 | + } |
|
| 1099 | + $registration_processor->fix_reg_final_price_rounding_issue($transaction); |
|
| 1100 | + } |
|
| 1101 | + return $registrations; |
|
| 1102 | + } |
|
| 1103 | + |
|
| 1104 | + |
|
| 1105 | + /** |
|
| 1106 | + * sorts registrations by REG_count |
|
| 1107 | + * |
|
| 1108 | + * @access public |
|
| 1109 | + * @param EE_Registration $reg_A |
|
| 1110 | + * @param EE_Registration $reg_B |
|
| 1111 | + * @return int |
|
| 1112 | + */ |
|
| 1113 | + public static function sort_registrations_by_REG_count(EE_Registration $reg_A, EE_Registration $reg_B) |
|
| 1114 | + { |
|
| 1115 | + // this shouldn't ever happen within the same TXN, but oh well |
|
| 1116 | + if ($reg_A->count() === $reg_B->count()) { |
|
| 1117 | + return 0; |
|
| 1118 | + } |
|
| 1119 | + return ($reg_A->count() > $reg_B->count()) ? 1 : -1; |
|
| 1120 | + } |
|
| 1121 | + |
|
| 1122 | + |
|
| 1123 | + /** |
|
| 1124 | + * _final_verifications |
|
| 1125 | + * just makes sure that everything is set up correctly before proceeding |
|
| 1126 | + * |
|
| 1127 | + * @access private |
|
| 1128 | + * @return bool |
|
| 1129 | + * @throws EE_Error |
|
| 1130 | + */ |
|
| 1131 | + private function _final_verifications() |
|
| 1132 | + { |
|
| 1133 | + // filter checkout |
|
| 1134 | + $this->checkout = apply_filters( |
|
| 1135 | + 'FHEE__EED_Single_Page_Checkout___final_verifications__checkout', |
|
| 1136 | + $this->checkout |
|
| 1137 | + ); |
|
| 1138 | + // verify that current step is still set correctly |
|
| 1139 | + if (! $this->checkout->current_step instanceof EE_SPCO_Reg_Step) { |
|
| 1140 | + EE_Error::add_error( |
|
| 1141 | + esc_html__( |
|
| 1142 | + 'We\'re sorry but the registration process can not proceed because one or more registration steps were not setup correctly. Please refresh the page and try again or contact support.', |
|
| 1143 | + 'event_espresso' |
|
| 1144 | + ), |
|
| 1145 | + __FILE__, |
|
| 1146 | + __FUNCTION__, |
|
| 1147 | + __LINE__ |
|
| 1148 | + ); |
|
| 1149 | + return false; |
|
| 1150 | + } |
|
| 1151 | + // if returning to SPCO, then verify that primary registrant is set |
|
| 1152 | + if (! empty($this->checkout->reg_url_link)) { |
|
| 1153 | + $valid_registrant = $this->checkout->transaction->primary_registration(); |
|
| 1154 | + if (! $valid_registrant instanceof EE_Registration) { |
|
| 1155 | + EE_Error::add_error( |
|
| 1156 | + esc_html__( |
|
| 1157 | + 'We\'re sorry but there appears to be an error with the "reg_url_link" or the primary registrant for this transaction. Please refresh the page and try again or contact support.', |
|
| 1158 | + 'event_espresso' |
|
| 1159 | + ), |
|
| 1160 | + __FILE__, |
|
| 1161 | + __FUNCTION__, |
|
| 1162 | + __LINE__ |
|
| 1163 | + ); |
|
| 1164 | + return false; |
|
| 1165 | + } |
|
| 1166 | + $valid_registrant = null; |
|
| 1167 | + foreach ($this->checkout->transaction->registrations($this->checkout->reg_cache_where_params) as $registration) { |
|
| 1168 | + if ($registration instanceof EE_Registration |
|
| 1169 | + && $registration->reg_url_link() === $this->checkout->reg_url_link |
|
| 1170 | + ) { |
|
| 1171 | + $valid_registrant = $registration; |
|
| 1172 | + } |
|
| 1173 | + } |
|
| 1174 | + if (! $valid_registrant instanceof EE_Registration) { |
|
| 1175 | + // hmmm... maybe we have the wrong session because the user is opening multiple tabs ? |
|
| 1176 | + if (EED_Single_Page_Checkout::$_checkout_verified) { |
|
| 1177 | + // clear the session, mark the checkout as unverified, and try again |
|
| 1178 | + EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__); |
|
| 1179 | + EED_Single_Page_Checkout::$_initialized = false; |
|
| 1180 | + EED_Single_Page_Checkout::$_checkout_verified = false; |
|
| 1181 | + $this->_initialize(); |
|
| 1182 | + EE_Error::reset_notices(); |
|
| 1183 | + return false; |
|
| 1184 | + } |
|
| 1185 | + EE_Error::add_error( |
|
| 1186 | + esc_html__( |
|
| 1187 | + 'We\'re sorry but there appears to be an error with the "reg_url_link" or the transaction itself. Please refresh the page and try again or contact support.', |
|
| 1188 | + 'event_espresso' |
|
| 1189 | + ), |
|
| 1190 | + __FILE__, |
|
| 1191 | + __FUNCTION__, |
|
| 1192 | + __LINE__ |
|
| 1193 | + ); |
|
| 1194 | + return false; |
|
| 1195 | + } |
|
| 1196 | + } |
|
| 1197 | + // now that things have been kinda sufficiently verified, |
|
| 1198 | + // let's add the checkout to the session so that it's available to other systems |
|
| 1199 | + EE_Registry::instance()->SSN->set_checkout($this->checkout); |
|
| 1200 | + return true; |
|
| 1201 | + } |
|
| 1202 | + |
|
| 1203 | + |
|
| 1204 | + /** |
|
| 1205 | + * _initialize_reg_steps |
|
| 1206 | + * first makes sure that EE_Transaction_Processor::set_reg_step_initiated() is called as required |
|
| 1207 | + * then loops thru all of the active reg steps and calls the initialize_reg_step() method |
|
| 1208 | + * |
|
| 1209 | + * @access private |
|
| 1210 | + * @param bool $reinitializing |
|
| 1211 | + * @throws EE_Error |
|
| 1212 | + */ |
|
| 1213 | + private function _initialize_reg_steps($reinitializing = false) |
|
| 1214 | + { |
|
| 1215 | + $this->checkout->set_reg_step_initiated($this->checkout->current_step); |
|
| 1216 | + // loop thru all steps to call their individual "initialize" methods and set i18n strings for JS |
|
| 1217 | + foreach ($this->checkout->reg_steps as $reg_step) { |
|
| 1218 | + if (! $reg_step->initialize_reg_step()) { |
|
| 1219 | + // if not initialized then maybe this step is being removed... |
|
| 1220 | + if (! $reinitializing && $reg_step->is_current_step()) { |
|
| 1221 | + // if it was the current step, then we need to start over here |
|
| 1222 | + $this->_initialize_reg_steps(true); |
|
| 1223 | + return; |
|
| 1224 | + } |
|
| 1225 | + continue; |
|
| 1226 | + } |
|
| 1227 | + // add css and JS for current step |
|
| 1228 | + $reg_step->enqueue_styles_and_scripts(); |
|
| 1229 | + // i18n |
|
| 1230 | + $reg_step->translate_js_strings(); |
|
| 1231 | + if ($reg_step->is_current_step()) { |
|
| 1232 | + // the text that appears on the reg step form submit button |
|
| 1233 | + $reg_step->set_submit_button_text(); |
|
| 1234 | + } |
|
| 1235 | + } |
|
| 1236 | + // dynamically creates hook point like: AHEE__Single_Page_Checkout___initialize_reg_step__attendee_information |
|
| 1237 | + do_action( |
|
| 1238 | + "AHEE__Single_Page_Checkout___initialize_reg_step__{$this->checkout->current_step->slug()}", |
|
| 1239 | + $this->checkout->current_step |
|
| 1240 | + ); |
|
| 1241 | + } |
|
| 1242 | + |
|
| 1243 | + |
|
| 1244 | + /** |
|
| 1245 | + * _check_form_submission |
|
| 1246 | + * |
|
| 1247 | + * @access private |
|
| 1248 | + * @return boolean |
|
| 1249 | + */ |
|
| 1250 | + private function _check_form_submission() |
|
| 1251 | + { |
|
| 1252 | + // does this request require the reg form to be generated ? |
|
| 1253 | + if ($this->checkout->generate_reg_form) { |
|
| 1254 | + // ever heard that song by Blue Rodeo ? |
|
| 1255 | + try { |
|
| 1256 | + $this->checkout->current_step->reg_form = $this->checkout->current_step->generate_reg_form(); |
|
| 1257 | + // if not displaying a form, then check for form submission |
|
| 1258 | + if ($this->checkout->process_form_submission |
|
| 1259 | + && $this->checkout->current_step->reg_form->was_submitted() |
|
| 1260 | + ) { |
|
| 1261 | + // clear out any old data in case this step is being run again |
|
| 1262 | + $this->checkout->current_step->set_valid_data(array()); |
|
| 1263 | + // capture submitted form data |
|
| 1264 | + $this->checkout->current_step->reg_form->receive_form_submission( |
|
| 1265 | + apply_filters( |
|
| 1266 | + 'FHEE__Single_Page_Checkout___check_form_submission__request_params', |
|
| 1267 | + EE_Registry::instance()->REQ->params(), |
|
| 1268 | + $this->checkout |
|
| 1269 | + ) |
|
| 1270 | + ); |
|
| 1271 | + // validate submitted form data |
|
| 1272 | + if (! $this->checkout->continue_reg || ! $this->checkout->current_step->reg_form->is_valid()) { |
|
| 1273 | + // thou shall not pass !!! |
|
| 1274 | + $this->checkout->continue_reg = false; |
|
| 1275 | + // any form validation errors? |
|
| 1276 | + if ($this->checkout->current_step->reg_form->submission_error_message() !== '') { |
|
| 1277 | + EE_Error::add_error( |
|
| 1278 | + $this->checkout->current_step->reg_form->submission_error_message(), |
|
| 1279 | + __FILE__, |
|
| 1280 | + __FUNCTION__, |
|
| 1281 | + __LINE__ |
|
| 1282 | + ); |
|
| 1283 | + } |
|
| 1284 | + // well not really... what will happen is |
|
| 1285 | + // we'll just get redirected back to redo the current step |
|
| 1286 | + $this->go_to_next_step(); |
|
| 1287 | + return false; |
|
| 1288 | + } |
|
| 1289 | + } |
|
| 1290 | + } catch (EE_Error $e) { |
|
| 1291 | + $e->get_error(); |
|
| 1292 | + } |
|
| 1293 | + } |
|
| 1294 | + return true; |
|
| 1295 | + } |
|
| 1296 | + |
|
| 1297 | + |
|
| 1298 | + /** |
|
| 1299 | + * _process_action |
|
| 1300 | + * |
|
| 1301 | + * @access private |
|
| 1302 | + * @return void |
|
| 1303 | + * @throws EE_Error |
|
| 1304 | + */ |
|
| 1305 | + private function _process_form_action() |
|
| 1306 | + { |
|
| 1307 | + // what cha wanna do? |
|
| 1308 | + switch ($this->checkout->action) { |
|
| 1309 | + // AJAX next step reg form |
|
| 1310 | + case 'display_spco_reg_step': |
|
| 1311 | + $this->checkout->redirect = false; |
|
| 1312 | + if (EE_Registry::instance()->REQ->ajax) { |
|
| 1313 | + $this->checkout->json_response->set_reg_step_html( |
|
| 1314 | + $this->checkout->current_step->display_reg_form() |
|
| 1315 | + ); |
|
| 1316 | + } |
|
| 1317 | + break; |
|
| 1318 | + default: |
|
| 1319 | + // meh... do one of those other steps first |
|
| 1320 | + if (! empty($this->checkout->action) |
|
| 1321 | + && is_callable(array($this->checkout->current_step, $this->checkout->action)) |
|
| 1322 | + ) { |
|
| 1323 | + // dynamically creates hook point like: |
|
| 1324 | + // AHEE__Single_Page_Checkout__before_attendee_information__process_reg_step |
|
| 1325 | + do_action( |
|
| 1326 | + "AHEE__Single_Page_Checkout__before_{$this->checkout->current_step->slug()}__{$this->checkout->action}", |
|
| 1327 | + $this->checkout->current_step |
|
| 1328 | + ); |
|
| 1329 | + // call action on current step |
|
| 1330 | + if (call_user_func(array($this->checkout->current_step, $this->checkout->action))) { |
|
| 1331 | + // good registrant, you get to proceed |
|
| 1332 | + if ($this->checkout->current_step->success_message() !== '' |
|
| 1333 | + && apply_filters( |
|
| 1334 | + 'FHEE__Single_Page_Checkout___process_form_action__display_success', |
|
| 1335 | + false |
|
| 1336 | + ) |
|
| 1337 | + ) { |
|
| 1338 | + EE_Error::add_success( |
|
| 1339 | + $this->checkout->current_step->success_message() |
|
| 1340 | + . '<br />' . $this->checkout->next_step->_instructions() |
|
| 1341 | + ); |
|
| 1342 | + } |
|
| 1343 | + // pack it up, pack it in... |
|
| 1344 | + $this->_setup_redirect(); |
|
| 1345 | + } |
|
| 1346 | + // dynamically creates hook point like: |
|
| 1347 | + // AHEE__Single_Page_Checkout__after_payment_options__process_reg_step |
|
| 1348 | + do_action( |
|
| 1349 | + "AHEE__Single_Page_Checkout__after_{$this->checkout->current_step->slug()}__{$this->checkout->action}", |
|
| 1350 | + $this->checkout->current_step |
|
| 1351 | + ); |
|
| 1352 | + } else { |
|
| 1353 | + EE_Error::add_error( |
|
| 1354 | + sprintf( |
|
| 1355 | + esc_html__( |
|
| 1356 | + 'The requested form action "%s" does not exist for the current "%s" registration step.', |
|
| 1357 | + 'event_espresso' |
|
| 1358 | + ), |
|
| 1359 | + $this->checkout->action, |
|
| 1360 | + $this->checkout->current_step->name() |
|
| 1361 | + ), |
|
| 1362 | + __FILE__, |
|
| 1363 | + __FUNCTION__, |
|
| 1364 | + __LINE__ |
|
| 1365 | + ); |
|
| 1366 | + } |
|
| 1367 | + // end default |
|
| 1368 | + } |
|
| 1369 | + // store our progress so far |
|
| 1370 | + $this->checkout->stash_transaction_and_checkout(); |
|
| 1371 | + // advance to the next step! If you pass GO, collect $200 |
|
| 1372 | + $this->go_to_next_step(); |
|
| 1373 | + } |
|
| 1374 | + |
|
| 1375 | + |
|
| 1376 | + /** |
|
| 1377 | + * add_styles_and_scripts |
|
| 1378 | + * |
|
| 1379 | + * @access public |
|
| 1380 | + * @return void |
|
| 1381 | + */ |
|
| 1382 | + public function add_styles_and_scripts() |
|
| 1383 | + { |
|
| 1384 | + // i18n |
|
| 1385 | + $this->translate_js_strings(); |
|
| 1386 | + if ($this->checkout->admin_request) { |
|
| 1387 | + add_action('admin_enqueue_scripts', array($this, 'enqueue_styles_and_scripts'), 10); |
|
| 1388 | + } else { |
|
| 1389 | + add_action('wp_enqueue_scripts', array($this, 'enqueue_styles_and_scripts'), 10); |
|
| 1390 | + } |
|
| 1391 | + } |
|
| 1392 | + |
|
| 1393 | + |
|
| 1394 | + /** |
|
| 1395 | + * translate_js_strings |
|
| 1396 | + * |
|
| 1397 | + * @access public |
|
| 1398 | + * @return void |
|
| 1399 | + */ |
|
| 1400 | + public function translate_js_strings() |
|
| 1401 | + { |
|
| 1402 | + EE_Registry::$i18n_js_strings['revisit'] = $this->checkout->revisit; |
|
| 1403 | + EE_Registry::$i18n_js_strings['e_reg_url_link'] = $this->checkout->reg_url_link; |
|
| 1404 | + EE_Registry::$i18n_js_strings['server_error'] = esc_html__( |
|
| 1405 | + 'An unknown error occurred on the server while attempting to process your request. Please refresh the page and try again or contact support.', |
|
| 1406 | + 'event_espresso' |
|
| 1407 | + ); |
|
| 1408 | + EE_Registry::$i18n_js_strings['invalid_json_response'] = esc_html__( |
|
| 1409 | + 'An invalid response was returned from the server while attempting to process your request. Please refresh the page and try again or contact support.', |
|
| 1410 | + 'event_espresso' |
|
| 1411 | + ); |
|
| 1412 | + EE_Registry::$i18n_js_strings['validation_error'] = esc_html__( |
|
| 1413 | + 'There appears to be a problem with the form validation configuration! Please check the admin settings or contact support.', |
|
| 1414 | + 'event_espresso' |
|
| 1415 | + ); |
|
| 1416 | + EE_Registry::$i18n_js_strings['invalid_payment_method'] = esc_html__( |
|
| 1417 | + 'There appears to be a problem with the payment method configuration! Please refresh the page and try again or contact support.', |
|
| 1418 | + 'event_espresso' |
|
| 1419 | + ); |
|
| 1420 | + EE_Registry::$i18n_js_strings['reg_step_error'] = esc_html__( |
|
| 1421 | + 'This registration step could not be completed. Please refresh the page and try again.', |
|
| 1422 | + 'event_espresso' |
|
| 1423 | + ); |
|
| 1424 | + EE_Registry::$i18n_js_strings['invalid_coupon'] = esc_html__( |
|
| 1425 | + 'We\'re sorry but that coupon code does not appear to be valid. If this is incorrect, please contact the site administrator.', |
|
| 1426 | + 'event_espresso' |
|
| 1427 | + ); |
|
| 1428 | + EE_Registry::$i18n_js_strings['process_registration'] = sprintf( |
|
| 1429 | + esc_html__( |
|
| 1430 | + 'Please wait while we process your registration.%sDo not refresh the page or navigate away while this is happening.%sThank you for your patience.', |
|
| 1431 | + 'event_espresso' |
|
| 1432 | + ), |
|
| 1433 | + '<br/>', |
|
| 1434 | + '<br/>' |
|
| 1435 | + ); |
|
| 1436 | + EE_Registry::$i18n_js_strings['language'] = get_bloginfo('language'); |
|
| 1437 | + EE_Registry::$i18n_js_strings['EESID'] = EE_Registry::instance()->SSN->id(); |
|
| 1438 | + EE_Registry::$i18n_js_strings['currency'] = EE_Registry::instance()->CFG->currency; |
|
| 1439 | + EE_Registry::$i18n_js_strings['datepicker_yearRange'] = '-150:+20'; |
|
| 1440 | + EE_Registry::$i18n_js_strings['timer_years'] = esc_html__('years', 'event_espresso'); |
|
| 1441 | + EE_Registry::$i18n_js_strings['timer_months'] = esc_html__('months', 'event_espresso'); |
|
| 1442 | + EE_Registry::$i18n_js_strings['timer_weeks'] = esc_html__('weeks', 'event_espresso'); |
|
| 1443 | + EE_Registry::$i18n_js_strings['timer_days'] = esc_html__('days', 'event_espresso'); |
|
| 1444 | + EE_Registry::$i18n_js_strings['timer_hours'] = esc_html__('hours', 'event_espresso'); |
|
| 1445 | + EE_Registry::$i18n_js_strings['timer_minutes'] = esc_html__('minutes', 'event_espresso'); |
|
| 1446 | + EE_Registry::$i18n_js_strings['timer_seconds'] = esc_html__('seconds', 'event_espresso'); |
|
| 1447 | + EE_Registry::$i18n_js_strings['timer_year'] = esc_html__('year', 'event_espresso'); |
|
| 1448 | + EE_Registry::$i18n_js_strings['timer_month'] = esc_html__('month', 'event_espresso'); |
|
| 1449 | + EE_Registry::$i18n_js_strings['timer_week'] = esc_html__('week', 'event_espresso'); |
|
| 1450 | + EE_Registry::$i18n_js_strings['timer_day'] = esc_html__('day', 'event_espresso'); |
|
| 1451 | + EE_Registry::$i18n_js_strings['timer_hour'] = esc_html__('hour', 'event_espresso'); |
|
| 1452 | + EE_Registry::$i18n_js_strings['timer_minute'] = esc_html__('minute', 'event_espresso'); |
|
| 1453 | + EE_Registry::$i18n_js_strings['timer_second'] = esc_html__('second', 'event_espresso'); |
|
| 1454 | + EE_Registry::$i18n_js_strings['registration_expiration_notice'] = EED_Single_Page_Checkout::getRegistrationExpirationNotice( |
|
| 1455 | + ); |
|
| 1456 | + EE_Registry::$i18n_js_strings['ajax_submit'] = apply_filters( |
|
| 1457 | + 'FHEE__Single_Page_Checkout__translate_js_strings__ajax_submit', |
|
| 1458 | + true |
|
| 1459 | + ); |
|
| 1460 | + EE_Registry::$i18n_js_strings['session_extension'] = absint( |
|
| 1461 | + apply_filters('FHEE__EE_Session__extend_expiration__seconds_added', 10 * MINUTE_IN_SECONDS) |
|
| 1462 | + ); |
|
| 1463 | + EE_Registry::$i18n_js_strings['session_expiration'] = gmdate( |
|
| 1464 | + 'M d, Y H:i:s', |
|
| 1465 | + EE_Registry::instance()->SSN->expiration() + (get_option('gmt_offset') * HOUR_IN_SECONDS) |
|
| 1466 | + ); |
|
| 1467 | + } |
|
| 1468 | + |
|
| 1469 | + |
|
| 1470 | + /** |
|
| 1471 | + * enqueue_styles_and_scripts |
|
| 1472 | + * |
|
| 1473 | + * @access public |
|
| 1474 | + * @return void |
|
| 1475 | + * @throws EE_Error |
|
| 1476 | + */ |
|
| 1477 | + public function enqueue_styles_and_scripts() |
|
| 1478 | + { |
|
| 1479 | + // load css |
|
| 1480 | + wp_register_style( |
|
| 1481 | + 'single_page_checkout', |
|
| 1482 | + SPCO_CSS_URL . 'single_page_checkout.css', |
|
| 1483 | + array('espresso_default'), |
|
| 1484 | + EVENT_ESPRESSO_VERSION |
|
| 1485 | + ); |
|
| 1486 | + wp_enqueue_style('single_page_checkout'); |
|
| 1487 | + // load JS |
|
| 1488 | + wp_register_script( |
|
| 1489 | + 'jquery_plugin', |
|
| 1490 | + EE_THIRD_PARTY_URL . 'jquery .plugin.min.js', |
|
| 1491 | + array('jquery'), |
|
| 1492 | + '1.0.1', |
|
| 1493 | + true |
|
| 1494 | + ); |
|
| 1495 | + wp_register_script( |
|
| 1496 | + 'jquery_countdown', |
|
| 1497 | + EE_THIRD_PARTY_URL . 'jquery .countdown.min.js', |
|
| 1498 | + array('jquery_plugin'), |
|
| 1499 | + '2.1.0', |
|
| 1500 | + true |
|
| 1501 | + ); |
|
| 1502 | + wp_register_script( |
|
| 1503 | + 'single_page_checkout', |
|
| 1504 | + SPCO_JS_URL . 'single_page_checkout.js', |
|
| 1505 | + array('espresso_core', 'underscore', 'ee_form_section_validation'), |
|
| 1506 | + EVENT_ESPRESSO_VERSION, |
|
| 1507 | + true |
|
| 1508 | + ); |
|
| 1509 | + if ($this->checkout->registration_form instanceof EE_Form_Section_Proper) { |
|
| 1510 | + $this->checkout->registration_form->enqueue_js(); |
|
| 1511 | + } |
|
| 1512 | + if ($this->checkout->current_step->reg_form instanceof EE_Form_Section_Proper) { |
|
| 1513 | + $this->checkout->current_step->reg_form->enqueue_js(); |
|
| 1514 | + } |
|
| 1515 | + wp_enqueue_script('single_page_checkout'); |
|
| 1516 | + if (apply_filters('FHEE__registration_page_wrapper_template__display_time_limit', false)) { |
|
| 1517 | + wp_enqueue_script('jquery_countdown'); |
|
| 1518 | + } |
|
| 1519 | + /** |
|
| 1520 | + * global action hook for enqueueing styles and scripts with |
|
| 1521 | + * spco calls. |
|
| 1522 | + */ |
|
| 1523 | + do_action('AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts', $this); |
|
| 1524 | + /** |
|
| 1525 | + * dynamic action hook for enqueueing styles and scripts with spco calls. |
|
| 1526 | + * The hook will end up being something like: |
|
| 1527 | + * AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__attendee_information |
|
| 1528 | + */ |
|
| 1529 | + do_action( |
|
| 1530 | + 'AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__' . $this->checkout->current_step->slug(), |
|
| 1531 | + $this |
|
| 1532 | + ); |
|
| 1533 | + } |
|
| 1534 | + |
|
| 1535 | + |
|
| 1536 | + /** |
|
| 1537 | + * display the Registration Single Page Checkout Form |
|
| 1538 | + * |
|
| 1539 | + * @access private |
|
| 1540 | + * @return void |
|
| 1541 | + * @throws EE_Error |
|
| 1542 | + */ |
|
| 1543 | + private function _display_spco_reg_form() |
|
| 1544 | + { |
|
| 1545 | + // if registering via the admin, just display the reg form for the current step |
|
| 1546 | + if ($this->checkout->admin_request) { |
|
| 1547 | + EE_Registry::instance()->REQ->add_output($this->checkout->current_step->display_reg_form()); |
|
| 1548 | + } else { |
|
| 1549 | + // add powered by EE msg |
|
| 1550 | + add_action('AHEE__SPCO__reg_form_footer', array('EED_Single_Page_Checkout', 'display_registration_footer')); |
|
| 1551 | + $empty_cart = count($this->checkout->transaction |
|
| 1552 | + ->registrations($this->checkout->reg_cache_where_params)) < 1; |
|
| 1553 | + EE_Registry::$i18n_js_strings['empty_cart'] = $empty_cart; |
|
| 1554 | + $cookies_not_set_msg = ''; |
|
| 1555 | + if ($empty_cart) { |
|
| 1556 | + $cookies_not_set_msg = apply_filters( |
|
| 1557 | + 'FHEE__Single_Page_Checkout__display_spco_reg_form__cookies_not_set_msg', |
|
| 1558 | + sprintf( |
|
| 1559 | + esc_html__( |
|
| 1560 | + '%1$s%3$sIt appears your browser is not currently set to accept Cookies%4$s%5$sIn order to register for events, you need to enable cookies.%7$sIf you require assistance, then click the following link to learn how to %8$senable cookies%9$s%6$s%2$s', |
|
| 1561 | + 'event_espresso' |
|
| 1562 | + ), |
|
| 1563 | + '<div class="ee-attention hidden" id="ee-cookies-not-set-msg">', |
|
| 1564 | + '</div>', |
|
| 1565 | + '<h6 class="important-notice">', |
|
| 1566 | + '</h6>', |
|
| 1567 | + '<p>', |
|
| 1568 | + '</p>', |
|
| 1569 | + '<br />', |
|
| 1570 | + '<a href="http://www.whatarecookies.com/enable.asp" target="_blank" rel="noopener noreferrer">', |
|
| 1571 | + '</a>' |
|
| 1572 | + ) |
|
| 1573 | + ); |
|
| 1574 | + } |
|
| 1575 | + $this->checkout->registration_form = new EE_Form_Section_Proper( |
|
| 1576 | + array( |
|
| 1577 | + 'name' => 'single-page-checkout', |
|
| 1578 | + 'html_id' => 'ee-single-page-checkout-dv', |
|
| 1579 | + 'layout_strategy' => |
|
| 1580 | + new EE_Template_Layout( |
|
| 1581 | + array( |
|
| 1582 | + 'layout_template_file' => SPCO_TEMPLATES_PATH . 'registration_page_wrapper.template.php', |
|
| 1583 | + 'template_args' => array( |
|
| 1584 | + 'empty_cart' => $empty_cart, |
|
| 1585 | + 'revisit' => $this->checkout->revisit, |
|
| 1586 | + 'reg_steps' => $this->checkout->reg_steps, |
|
| 1587 | + 'next_step' => $this->checkout->next_step instanceof EE_SPCO_Reg_Step |
|
| 1588 | + ? $this->checkout->next_step->slug() |
|
| 1589 | + : '', |
|
| 1590 | + 'empty_msg' => apply_filters( |
|
| 1591 | + 'FHEE__Single_Page_Checkout__display_spco_reg_form__empty_msg', |
|
| 1592 | + sprintf( |
|
| 1593 | + esc_html__( |
|
| 1594 | + 'You need to %1$sReturn to Events list%2$sselect at least one event%3$s before you can proceed with the registration process.', |
|
| 1595 | + 'event_espresso' |
|
| 1596 | + ), |
|
| 1597 | + '<a href="' |
|
| 1598 | + . get_post_type_archive_link('espresso_events') |
|
| 1599 | + . '" title="', |
|
| 1600 | + '">', |
|
| 1601 | + '</a>' |
|
| 1602 | + ) |
|
| 1603 | + ), |
|
| 1604 | + 'cookies_not_set_msg' => $cookies_not_set_msg, |
|
| 1605 | + 'registration_time_limit' => $this->checkout->get_registration_time_limit(), |
|
| 1606 | + 'session_expiration' => gmdate( |
|
| 1607 | + 'M d, Y H:i:s', |
|
| 1608 | + EE_Registry::instance()->SSN->expiration() |
|
| 1609 | + + (get_option('gmt_offset') * HOUR_IN_SECONDS) |
|
| 1610 | + ), |
|
| 1611 | + ), |
|
| 1612 | + ) |
|
| 1613 | + ), |
|
| 1614 | + ) |
|
| 1615 | + ); |
|
| 1616 | + // load template and add to output sent that gets filtered into the_content() |
|
| 1617 | + EE_Registry::instance()->REQ->add_output($this->checkout->registration_form->get_html()); |
|
| 1618 | + } |
|
| 1619 | + } |
|
| 1620 | + |
|
| 1621 | + |
|
| 1622 | + /** |
|
| 1623 | + * add_extra_finalize_registration_inputs |
|
| 1624 | + * |
|
| 1625 | + * @access public |
|
| 1626 | + * @param $next_step |
|
| 1627 | + * @internal param string $label |
|
| 1628 | + * @return void |
|
| 1629 | + */ |
|
| 1630 | + public function add_extra_finalize_registration_inputs($next_step) |
|
| 1631 | + { |
|
| 1632 | + if ($next_step === 'finalize_registration') { |
|
| 1633 | + echo '<div id="spco-extra-finalize_registration-inputs-dv"></div>'; |
|
| 1634 | + } |
|
| 1635 | + } |
|
| 1636 | + |
|
| 1637 | + |
|
| 1638 | + /** |
|
| 1639 | + * display_registration_footer |
|
| 1640 | + * |
|
| 1641 | + * @access public |
|
| 1642 | + * @return string |
|
| 1643 | + */ |
|
| 1644 | + public static function display_registration_footer() |
|
| 1645 | + { |
|
| 1646 | + if (apply_filters( |
|
| 1647 | + 'FHEE__EE_Front__Controller__show_reg_footer', |
|
| 1648 | + EE_Registry::instance()->CFG->admin->show_reg_footer |
|
| 1649 | + )) { |
|
| 1650 | + add_filter( |
|
| 1651 | + 'FHEE__EEH_Template__powered_by_event_espresso__url', |
|
| 1652 | + function ($url) { |
|
| 1653 | + return apply_filters('FHEE__EE_Front_Controller__registration_footer__url', $url); |
|
| 1654 | + } |
|
| 1655 | + ); |
|
| 1656 | + echo apply_filters( |
|
| 1657 | + 'FHEE__EE_Front_Controller__display_registration_footer', |
|
| 1658 | + \EEH_Template::powered_by_event_espresso( |
|
| 1659 | + '', |
|
| 1660 | + 'espresso-registration-footer-dv', |
|
| 1661 | + array('utm_content' => 'registration_checkout') |
|
| 1662 | + ) |
|
| 1663 | + ); |
|
| 1664 | + } |
|
| 1665 | + return ''; |
|
| 1666 | + } |
|
| 1667 | + |
|
| 1668 | + |
|
| 1669 | + /** |
|
| 1670 | + * unlock_transaction |
|
| 1671 | + * |
|
| 1672 | + * @access public |
|
| 1673 | + * @return void |
|
| 1674 | + * @throws EE_Error |
|
| 1675 | + */ |
|
| 1676 | + public function unlock_transaction() |
|
| 1677 | + { |
|
| 1678 | + if ($this->checkout->transaction instanceof EE_Transaction) { |
|
| 1679 | + $this->checkout->transaction->unlock(); |
|
| 1680 | + } |
|
| 1681 | + } |
|
| 1682 | + |
|
| 1683 | + |
|
| 1684 | + /** |
|
| 1685 | + * _setup_redirect |
|
| 1686 | + * |
|
| 1687 | + * @access private |
|
| 1688 | + * @return void |
|
| 1689 | + */ |
|
| 1690 | + private function _setup_redirect() |
|
| 1691 | + { |
|
| 1692 | + if ($this->checkout->continue_reg && $this->checkout->next_step instanceof EE_SPCO_Reg_Step) { |
|
| 1693 | + $this->checkout->redirect = true; |
|
| 1694 | + if (empty($this->checkout->redirect_url)) { |
|
| 1695 | + $this->checkout->redirect_url = $this->checkout->next_step->reg_step_url(); |
|
| 1696 | + } |
|
| 1697 | + $this->checkout->redirect_url = apply_filters( |
|
| 1698 | + 'FHEE__EED_Single_Page_Checkout___setup_redirect__checkout_redirect_url', |
|
| 1699 | + $this->checkout->redirect_url, |
|
| 1700 | + $this->checkout |
|
| 1701 | + ); |
|
| 1702 | + } |
|
| 1703 | + } |
|
| 1704 | + |
|
| 1705 | + |
|
| 1706 | + /** |
|
| 1707 | + * handle ajax message responses and redirects |
|
| 1708 | + * |
|
| 1709 | + * @access public |
|
| 1710 | + * @return void |
|
| 1711 | + * @throws EE_Error |
|
| 1712 | + */ |
|
| 1713 | + public function go_to_next_step() |
|
| 1714 | + { |
|
| 1715 | + if (EE_Registry::instance()->REQ->ajax) { |
|
| 1716 | + // capture contents of output buffer we started earlier in the request, and insert into JSON response |
|
| 1717 | + $this->checkout->json_response->set_unexpected_errors(ob_get_clean()); |
|
| 1718 | + } |
|
| 1719 | + $this->unlock_transaction(); |
|
| 1720 | + // just return for these conditions |
|
| 1721 | + if ($this->checkout->admin_request |
|
| 1722 | + || $this->checkout->action === 'redirect_form' |
|
| 1723 | + || $this->checkout->action === 'update_checkout' |
|
| 1724 | + ) { |
|
| 1725 | + return; |
|
| 1726 | + } |
|
| 1727 | + // AJAX response |
|
| 1728 | + $this->_handle_json_response(); |
|
| 1729 | + // redirect to next step or the Thank You page |
|
| 1730 | + $this->_handle_html_redirects(); |
|
| 1731 | + // hmmm... must be something wrong, so let's just display the form again ! |
|
| 1732 | + $this->_display_spco_reg_form(); |
|
| 1733 | + } |
|
| 1734 | + |
|
| 1735 | + |
|
| 1736 | + /** |
|
| 1737 | + * _handle_json_response |
|
| 1738 | + * |
|
| 1739 | + * @access protected |
|
| 1740 | + * @return void |
|
| 1741 | + */ |
|
| 1742 | + protected function _handle_json_response() |
|
| 1743 | + { |
|
| 1744 | + // if this is an ajax request |
|
| 1745 | + if (EE_Registry::instance()->REQ->ajax) { |
|
| 1746 | + $this->checkout->json_response->set_registration_time_limit( |
|
| 1747 | + $this->checkout->get_registration_time_limit() |
|
| 1748 | + ); |
|
| 1749 | + $this->checkout->json_response->set_payment_amount($this->checkout->amount_owing); |
|
| 1750 | + // just send the ajax ( |
|
| 1751 | + $json_response = apply_filters( |
|
| 1752 | + 'FHEE__EE_Single_Page_Checkout__JSON_response', |
|
| 1753 | + $this->checkout->json_response |
|
| 1754 | + ); |
|
| 1755 | + echo $json_response; |
|
| 1756 | + exit(); |
|
| 1757 | + } |
|
| 1758 | + } |
|
| 1759 | + |
|
| 1760 | + |
|
| 1761 | + /** |
|
| 1762 | + * _handle_redirects |
|
| 1763 | + * |
|
| 1764 | + * @access protected |
|
| 1765 | + * @return void |
|
| 1766 | + */ |
|
| 1767 | + protected function _handle_html_redirects() |
|
| 1768 | + { |
|
| 1769 | + // going somewhere ? |
|
| 1770 | + if ($this->checkout->redirect && ! empty($this->checkout->redirect_url)) { |
|
| 1771 | + // store notices in a transient |
|
| 1772 | + EE_Error::get_notices(false, true, true); |
|
| 1773 | + wp_safe_redirect($this->checkout->redirect_url); |
|
| 1774 | + exit(); |
|
| 1775 | + } |
|
| 1776 | + } |
|
| 1777 | + |
|
| 1778 | + |
|
| 1779 | + /** |
|
| 1780 | + * set_checkout_anchor |
|
| 1781 | + * |
|
| 1782 | + * @access public |
|
| 1783 | + * @return void |
|
| 1784 | + */ |
|
| 1785 | + public function set_checkout_anchor() |
|
| 1786 | + { |
|
| 1787 | + echo '<a id="checkout" style="float: left; margin-left: -999em;"></a>'; |
|
| 1788 | + } |
|
| 1789 | + |
|
| 1790 | + /** |
|
| 1791 | + * getRegistrationExpirationNotice |
|
| 1792 | + * |
|
| 1793 | + * @since 4.9.59.p |
|
| 1794 | + * @access public |
|
| 1795 | + * @return string |
|
| 1796 | + */ |
|
| 1797 | + public static function getRegistrationExpirationNotice() |
|
| 1798 | + { |
|
| 1799 | + return sprintf( |
|
| 1800 | + esc_html__( |
|
| 1801 | + '%1$sWe\'re sorry, but your registration time has expired.%2$s%3$s%4$sIf you still wish to complete your registration, please return to the %5$sEvent List%6$sEvent List%7$s and reselect your tickets if available. Please accept our apologies for any inconvenience this may have caused.%8$s', |
|
| 1802 | + 'event_espresso' |
|
| 1803 | + ), |
|
| 1804 | + '<h4 class="important-notice">', |
|
| 1805 | + '</h4>', |
|
| 1806 | + '<br />', |
|
| 1807 | + '<p>', |
|
| 1808 | + '<a href="' . get_post_type_archive_link('espresso_events') . '" title="', |
|
| 1809 | + '">', |
|
| 1810 | + '</a>', |
|
| 1811 | + '</p>' |
|
| 1812 | + ); |
|
| 1813 | + } |
|
| 1814 | 1814 | } |
@@ -100,7 +100,7 @@ discard block |
||
| 100 | 100 | public static function set_hooks_admin() |
| 101 | 101 | { |
| 102 | 102 | EED_Single_Page_Checkout::set_definitions(); |
| 103 | - if (! (defined('DOING_AJAX') && DOING_AJAX)) { |
|
| 103 | + if ( ! (defined('DOING_AJAX') && DOING_AJAX)) { |
|
| 104 | 104 | return; |
| 105 | 105 | } |
| 106 | 106 | // going to start an output buffer in case anything gets accidentally output |
@@ -206,14 +206,14 @@ discard block |
||
| 206 | 206 | } |
| 207 | 207 | define( |
| 208 | 208 | 'SPCO_BASE_PATH', |
| 209 | - rtrim(str_replace(array('\\', '/'), '/', plugin_dir_path(__FILE__)), '/') . '/' |
|
| 209 | + rtrim(str_replace(array('\\', '/'), '/', plugin_dir_path(__FILE__)), '/').'/' |
|
| 210 | 210 | ); |
| 211 | - define('SPCO_CSS_URL', plugin_dir_url(__FILE__) . 'css/'); |
|
| 212 | - define('SPCO_IMG_URL', plugin_dir_url(__FILE__) . 'img/'); |
|
| 213 | - define('SPCO_JS_URL', plugin_dir_url(__FILE__) . 'js/'); |
|
| 214 | - define('SPCO_INC_PATH', SPCO_BASE_PATH . 'inc/'); |
|
| 215 | - define('SPCO_REG_STEPS_PATH', SPCO_BASE_PATH . 'reg_steps/'); |
|
| 216 | - define('SPCO_TEMPLATES_PATH', SPCO_BASE_PATH . 'templates/'); |
|
| 211 | + define('SPCO_CSS_URL', plugin_dir_url(__FILE__).'css/'); |
|
| 212 | + define('SPCO_IMG_URL', plugin_dir_url(__FILE__).'img/'); |
|
| 213 | + define('SPCO_JS_URL', plugin_dir_url(__FILE__).'js/'); |
|
| 214 | + define('SPCO_INC_PATH', SPCO_BASE_PATH.'inc/'); |
|
| 215 | + define('SPCO_REG_STEPS_PATH', SPCO_BASE_PATH.'reg_steps/'); |
|
| 216 | + define('SPCO_TEMPLATES_PATH', SPCO_BASE_PATH.'templates/'); |
|
| 217 | 217 | EEH_Autoloader::register_autoloaders_for_each_file_in_folder(SPCO_BASE_PATH, true); |
| 218 | 218 | EE_Registry::$i18n_js_strings['registration_expiration_notice'] = EED_Single_Page_Checkout::getRegistrationExpirationNotice( |
| 219 | 219 | ); |
@@ -245,7 +245,7 @@ discard block |
||
| 245 | 245 | // we need a |
| 246 | 246 | if (isset($reg_step['file_path'], $reg_step['class_name'], $reg_step['slug'])) { |
| 247 | 247 | // copy over to the reg_steps_array |
| 248 | - EED_Single_Page_Checkout::$_reg_steps_array[ $order ] = $reg_step; |
|
| 248 | + EED_Single_Page_Checkout::$_reg_steps_array[$order] = $reg_step; |
|
| 249 | 249 | // register custom key route for each reg step |
| 250 | 250 | // ie: step=>"slug" - this is the entire reason we load the reg steps array now |
| 251 | 251 | EE_Config::register_route( |
@@ -257,7 +257,7 @@ discard block |
||
| 257 | 257 | // add AJAX or other hooks |
| 258 | 258 | if (isset($reg_step['has_hooks']) && $reg_step['has_hooks']) { |
| 259 | 259 | // setup autoloaders if necessary |
| 260 | - if (! class_exists($reg_step['class_name'])) { |
|
| 260 | + if ( ! class_exists($reg_step['class_name'])) { |
|
| 261 | 261 | EEH_Autoloader::register_autoloaders_for_each_file_in_folder( |
| 262 | 262 | $reg_step['file_path'], |
| 263 | 263 | true |
@@ -285,19 +285,19 @@ discard block |
||
| 285 | 285 | if (empty($reg_steps)) { |
| 286 | 286 | $reg_steps = array( |
| 287 | 287 | 10 => array( |
| 288 | - 'file_path' => SPCO_REG_STEPS_PATH . 'attendee_information', |
|
| 288 | + 'file_path' => SPCO_REG_STEPS_PATH.'attendee_information', |
|
| 289 | 289 | 'class_name' => 'EE_SPCO_Reg_Step_Attendee_Information', |
| 290 | 290 | 'slug' => 'attendee_information', |
| 291 | 291 | 'has_hooks' => false, |
| 292 | 292 | ), |
| 293 | 293 | 30 => array( |
| 294 | - 'file_path' => SPCO_REG_STEPS_PATH . 'payment_options', |
|
| 294 | + 'file_path' => SPCO_REG_STEPS_PATH.'payment_options', |
|
| 295 | 295 | 'class_name' => 'EE_SPCO_Reg_Step_Payment_Options', |
| 296 | 296 | 'slug' => 'payment_options', |
| 297 | 297 | 'has_hooks' => true, |
| 298 | 298 | ), |
| 299 | 299 | 999 => array( |
| 300 | - 'file_path' => SPCO_REG_STEPS_PATH . 'finalize_registration', |
|
| 300 | + 'file_path' => SPCO_REG_STEPS_PATH.'finalize_registration', |
|
| 301 | 301 | 'class_name' => 'EE_SPCO_Reg_Step_Finalize_Registration', |
| 302 | 302 | 'slug' => 'finalize_registration', |
| 303 | 303 | 'has_hooks' => false, |
@@ -450,7 +450,7 @@ discard block |
||
| 450 | 450 | $this->checkout |
| 451 | 451 | ); |
| 452 | 452 | // load the reg steps array |
| 453 | - if (! $this->_load_and_instantiate_reg_steps()) { |
|
| 453 | + if ( ! $this->_load_and_instantiate_reg_steps()) { |
|
| 454 | 454 | EED_Single_Page_Checkout::$_initialized = true; |
| 455 | 455 | return; |
| 456 | 456 | } |
@@ -459,7 +459,7 @@ discard block |
||
| 459 | 459 | // and the next step |
| 460 | 460 | $this->checkout->set_next_step(); |
| 461 | 461 | // verify that everything has been setup correctly |
| 462 | - if (! ($this->_verify_transaction_and_get_registrations() && $this->_final_verifications())) { |
|
| 462 | + if ( ! ($this->_verify_transaction_and_get_registrations() && $this->_final_verifications())) { |
|
| 463 | 463 | EED_Single_Page_Checkout::$_initialized = true; |
| 464 | 464 | return; |
| 465 | 465 | } |
@@ -474,7 +474,7 @@ discard block |
||
| 474 | 474 | // DEBUG LOG |
| 475 | 475 | // $this->checkout->log( __CLASS__, __FUNCTION__, __LINE__ ); |
| 476 | 476 | // get reg form |
| 477 | - if (! $this->_check_form_submission()) { |
|
| 477 | + if ( ! $this->_check_form_submission()) { |
|
| 478 | 478 | EED_Single_Page_Checkout::$_initialized = true; |
| 479 | 479 | return; |
| 480 | 480 | } |
@@ -505,7 +505,7 @@ discard block |
||
| 505 | 505 | */ |
| 506 | 506 | private function _verify_session() |
| 507 | 507 | { |
| 508 | - if (! EE_Registry::instance()->SSN instanceof EE_Session) { |
|
| 508 | + if ( ! EE_Registry::instance()->SSN instanceof EE_Session) { |
|
| 509 | 509 | throw new EE_Error(esc_html__('The EE_Session class could not be loaded.', 'event_espresso')); |
| 510 | 510 | } |
| 511 | 511 | $clear_session_requested = filter_var( |
@@ -523,7 +523,7 @@ discard block |
||
| 523 | 523 | // EE_Registry::instance()->SSN->reset_cart(); |
| 524 | 524 | // EE_Registry::instance()->SSN->reset_checkout(); |
| 525 | 525 | // EE_Registry::instance()->SSN->reset_transaction(); |
| 526 | - if (! $clear_session_requested) { |
|
| 526 | + if ( ! $clear_session_requested) { |
|
| 527 | 527 | EE_Error::add_attention( |
| 528 | 528 | EE_Registry::$i18n_js_strings['registration_expiration_notice'], |
| 529 | 529 | __FILE__, |
@@ -550,7 +550,7 @@ discard block |
||
| 550 | 550 | /** @type EE_Checkout $checkout */ |
| 551 | 551 | $checkout = EE_Registry::instance()->SSN->checkout(); |
| 552 | 552 | // verify |
| 553 | - if (! $checkout instanceof EE_Checkout) { |
|
| 553 | + if ( ! $checkout instanceof EE_Checkout) { |
|
| 554 | 554 | // instantiate EE_Checkout object for handling the properties of the current checkout process |
| 555 | 555 | $checkout = EE_Registry::instance()->load_file( |
| 556 | 556 | SPCO_INC_PATH, |
@@ -568,7 +568,7 @@ discard block |
||
| 568 | 568 | } |
| 569 | 569 | $checkout = apply_filters('FHEE__EED_Single_Page_Checkout___initialize_checkout__checkout', $checkout); |
| 570 | 570 | // verify again |
| 571 | - if (! $checkout instanceof EE_Checkout) { |
|
| 571 | + if ( ! $checkout instanceof EE_Checkout) { |
|
| 572 | 572 | throw new EE_Error(esc_html__('The EE_Checkout class could not be loaded.', 'event_espresso')); |
| 573 | 573 | } |
| 574 | 574 | // reset anything that needs a clean slate for each request |
@@ -640,7 +640,7 @@ discard block |
||
| 640 | 640 | */ |
| 641 | 641 | protected function _display_request_vars() |
| 642 | 642 | { |
| 643 | - if (! WP_DEBUG) { |
|
| 643 | + if ( ! WP_DEBUG) { |
|
| 644 | 644 | return; |
| 645 | 645 | } |
| 646 | 646 | EEH_Debug_Tools::printr($_REQUEST, '$_REQUEST', __FILE__, __LINE__); |
@@ -717,7 +717,7 @@ discard block |
||
| 717 | 717 | ) { |
| 718 | 718 | // if not, then loop through raw reg steps array |
| 719 | 719 | foreach (EED_Single_Page_Checkout::$_reg_steps_array as $order => $reg_step) { |
| 720 | - if (! $this->_load_and_instantiate_reg_step($reg_step, $order)) { |
|
| 720 | + if ( ! $this->_load_and_instantiate_reg_step($reg_step, $order)) { |
|
| 721 | 721 | return false; |
| 722 | 722 | } |
| 723 | 723 | } |
@@ -848,12 +848,12 @@ discard block |
||
| 848 | 848 | private function _verify_transaction_and_get_registrations() |
| 849 | 849 | { |
| 850 | 850 | // was there already a valid transaction in the checkout from the session ? |
| 851 | - if (! $this->checkout->transaction instanceof EE_Transaction) { |
|
| 851 | + if ( ! $this->checkout->transaction instanceof EE_Transaction) { |
|
| 852 | 852 | // get transaction from db or session |
| 853 | 853 | $this->checkout->transaction = $this->checkout->reg_url_link && ! is_admin() |
| 854 | 854 | ? $this->_get_transaction_and_cart_for_previous_visit() |
| 855 | 855 | : $this->_get_cart_for_current_session_and_setup_new_transaction(); |
| 856 | - if (! $this->checkout->transaction instanceof EE_Transaction) { |
|
| 856 | + if ( ! $this->checkout->transaction instanceof EE_Transaction) { |
|
| 857 | 857 | EE_Error::add_error( |
| 858 | 858 | esc_html__( |
| 859 | 859 | 'Your Registration and Transaction information could not be retrieved from the db.', |
@@ -1084,16 +1084,16 @@ discard block |
||
| 1084 | 1084 | ) |
| 1085 | 1085 | ); |
| 1086 | 1086 | // override capabilities for frontend registrations |
| 1087 | - if (! is_admin()) { |
|
| 1087 | + if ( ! is_admin()) { |
|
| 1088 | 1088 | $CreateRegistrationCommand->setCapCheck( |
| 1089 | 1089 | new PublicCapabilities('', 'create_new_registration') |
| 1090 | 1090 | ); |
| 1091 | 1091 | } |
| 1092 | 1092 | $registration = EE_Registry::instance()->BUS->execute($CreateRegistrationCommand); |
| 1093 | - if (! $registration instanceof EE_Registration) { |
|
| 1093 | + if ( ! $registration instanceof EE_Registration) { |
|
| 1094 | 1094 | throw new InvalidEntityException($registration, 'EE_Registration'); |
| 1095 | 1095 | } |
| 1096 | - $registrations[ $registration->ID() ] = $registration; |
|
| 1096 | + $registrations[$registration->ID()] = $registration; |
|
| 1097 | 1097 | } |
| 1098 | 1098 | } |
| 1099 | 1099 | $registration_processor->fix_reg_final_price_rounding_issue($transaction); |
@@ -1136,7 +1136,7 @@ discard block |
||
| 1136 | 1136 | $this->checkout |
| 1137 | 1137 | ); |
| 1138 | 1138 | // verify that current step is still set correctly |
| 1139 | - if (! $this->checkout->current_step instanceof EE_SPCO_Reg_Step) { |
|
| 1139 | + if ( ! $this->checkout->current_step instanceof EE_SPCO_Reg_Step) { |
|
| 1140 | 1140 | EE_Error::add_error( |
| 1141 | 1141 | esc_html__( |
| 1142 | 1142 | 'We\'re sorry but the registration process can not proceed because one or more registration steps were not setup correctly. Please refresh the page and try again or contact support.', |
@@ -1149,9 +1149,9 @@ discard block |
||
| 1149 | 1149 | return false; |
| 1150 | 1150 | } |
| 1151 | 1151 | // if returning to SPCO, then verify that primary registrant is set |
| 1152 | - if (! empty($this->checkout->reg_url_link)) { |
|
| 1152 | + if ( ! empty($this->checkout->reg_url_link)) { |
|
| 1153 | 1153 | $valid_registrant = $this->checkout->transaction->primary_registration(); |
| 1154 | - if (! $valid_registrant instanceof EE_Registration) { |
|
| 1154 | + if ( ! $valid_registrant instanceof EE_Registration) { |
|
| 1155 | 1155 | EE_Error::add_error( |
| 1156 | 1156 | esc_html__( |
| 1157 | 1157 | 'We\'re sorry but there appears to be an error with the "reg_url_link" or the primary registrant for this transaction. Please refresh the page and try again or contact support.', |
@@ -1171,7 +1171,7 @@ discard block |
||
| 1171 | 1171 | $valid_registrant = $registration; |
| 1172 | 1172 | } |
| 1173 | 1173 | } |
| 1174 | - if (! $valid_registrant instanceof EE_Registration) { |
|
| 1174 | + if ( ! $valid_registrant instanceof EE_Registration) { |
|
| 1175 | 1175 | // hmmm... maybe we have the wrong session because the user is opening multiple tabs ? |
| 1176 | 1176 | if (EED_Single_Page_Checkout::$_checkout_verified) { |
| 1177 | 1177 | // clear the session, mark the checkout as unverified, and try again |
@@ -1215,9 +1215,9 @@ discard block |
||
| 1215 | 1215 | $this->checkout->set_reg_step_initiated($this->checkout->current_step); |
| 1216 | 1216 | // loop thru all steps to call their individual "initialize" methods and set i18n strings for JS |
| 1217 | 1217 | foreach ($this->checkout->reg_steps as $reg_step) { |
| 1218 | - if (! $reg_step->initialize_reg_step()) { |
|
| 1218 | + if ( ! $reg_step->initialize_reg_step()) { |
|
| 1219 | 1219 | // if not initialized then maybe this step is being removed... |
| 1220 | - if (! $reinitializing && $reg_step->is_current_step()) { |
|
| 1220 | + if ( ! $reinitializing && $reg_step->is_current_step()) { |
|
| 1221 | 1221 | // if it was the current step, then we need to start over here |
| 1222 | 1222 | $this->_initialize_reg_steps(true); |
| 1223 | 1223 | return; |
@@ -1269,7 +1269,7 @@ discard block |
||
| 1269 | 1269 | ) |
| 1270 | 1270 | ); |
| 1271 | 1271 | // validate submitted form data |
| 1272 | - if (! $this->checkout->continue_reg || ! $this->checkout->current_step->reg_form->is_valid()) { |
|
| 1272 | + if ( ! $this->checkout->continue_reg || ! $this->checkout->current_step->reg_form->is_valid()) { |
|
| 1273 | 1273 | // thou shall not pass !!! |
| 1274 | 1274 | $this->checkout->continue_reg = false; |
| 1275 | 1275 | // any form validation errors? |
@@ -1317,7 +1317,7 @@ discard block |
||
| 1317 | 1317 | break; |
| 1318 | 1318 | default: |
| 1319 | 1319 | // meh... do one of those other steps first |
| 1320 | - if (! empty($this->checkout->action) |
|
| 1320 | + if ( ! empty($this->checkout->action) |
|
| 1321 | 1321 | && is_callable(array($this->checkout->current_step, $this->checkout->action)) |
| 1322 | 1322 | ) { |
| 1323 | 1323 | // dynamically creates hook point like: |
@@ -1337,7 +1337,7 @@ discard block |
||
| 1337 | 1337 | ) { |
| 1338 | 1338 | EE_Error::add_success( |
| 1339 | 1339 | $this->checkout->current_step->success_message() |
| 1340 | - . '<br />' . $this->checkout->next_step->_instructions() |
|
| 1340 | + . '<br />'.$this->checkout->next_step->_instructions() |
|
| 1341 | 1341 | ); |
| 1342 | 1342 | } |
| 1343 | 1343 | // pack it up, pack it in... |
@@ -1479,7 +1479,7 @@ discard block |
||
| 1479 | 1479 | // load css |
| 1480 | 1480 | wp_register_style( |
| 1481 | 1481 | 'single_page_checkout', |
| 1482 | - SPCO_CSS_URL . 'single_page_checkout.css', |
|
| 1482 | + SPCO_CSS_URL.'single_page_checkout.css', |
|
| 1483 | 1483 | array('espresso_default'), |
| 1484 | 1484 | EVENT_ESPRESSO_VERSION |
| 1485 | 1485 | ); |
@@ -1487,21 +1487,21 @@ discard block |
||
| 1487 | 1487 | // load JS |
| 1488 | 1488 | wp_register_script( |
| 1489 | 1489 | 'jquery_plugin', |
| 1490 | - EE_THIRD_PARTY_URL . 'jquery .plugin.min.js', |
|
| 1490 | + EE_THIRD_PARTY_URL.'jquery .plugin.min.js', |
|
| 1491 | 1491 | array('jquery'), |
| 1492 | 1492 | '1.0.1', |
| 1493 | 1493 | true |
| 1494 | 1494 | ); |
| 1495 | 1495 | wp_register_script( |
| 1496 | 1496 | 'jquery_countdown', |
| 1497 | - EE_THIRD_PARTY_URL . 'jquery .countdown.min.js', |
|
| 1497 | + EE_THIRD_PARTY_URL.'jquery .countdown.min.js', |
|
| 1498 | 1498 | array('jquery_plugin'), |
| 1499 | 1499 | '2.1.0', |
| 1500 | 1500 | true |
| 1501 | 1501 | ); |
| 1502 | 1502 | wp_register_script( |
| 1503 | 1503 | 'single_page_checkout', |
| 1504 | - SPCO_JS_URL . 'single_page_checkout.js', |
|
| 1504 | + SPCO_JS_URL.'single_page_checkout.js', |
|
| 1505 | 1505 | array('espresso_core', 'underscore', 'ee_form_section_validation'), |
| 1506 | 1506 | EVENT_ESPRESSO_VERSION, |
| 1507 | 1507 | true |
@@ -1527,7 +1527,7 @@ discard block |
||
| 1527 | 1527 | * AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__attendee_information |
| 1528 | 1528 | */ |
| 1529 | 1529 | do_action( |
| 1530 | - 'AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__' . $this->checkout->current_step->slug(), |
|
| 1530 | + 'AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__'.$this->checkout->current_step->slug(), |
|
| 1531 | 1531 | $this |
| 1532 | 1532 | ); |
| 1533 | 1533 | } |
@@ -1579,7 +1579,7 @@ discard block |
||
| 1579 | 1579 | 'layout_strategy' => |
| 1580 | 1580 | new EE_Template_Layout( |
| 1581 | 1581 | array( |
| 1582 | - 'layout_template_file' => SPCO_TEMPLATES_PATH . 'registration_page_wrapper.template.php', |
|
| 1582 | + 'layout_template_file' => SPCO_TEMPLATES_PATH.'registration_page_wrapper.template.php', |
|
| 1583 | 1583 | 'template_args' => array( |
| 1584 | 1584 | 'empty_cart' => $empty_cart, |
| 1585 | 1585 | 'revisit' => $this->checkout->revisit, |
@@ -1649,7 +1649,7 @@ discard block |
||
| 1649 | 1649 | )) { |
| 1650 | 1650 | add_filter( |
| 1651 | 1651 | 'FHEE__EEH_Template__powered_by_event_espresso__url', |
| 1652 | - function ($url) { |
|
| 1652 | + function($url) { |
|
| 1653 | 1653 | return apply_filters('FHEE__EE_Front_Controller__registration_footer__url', $url); |
| 1654 | 1654 | } |
| 1655 | 1655 | ); |
@@ -1805,7 +1805,7 @@ discard block |
||
| 1805 | 1805 | '</h4>', |
| 1806 | 1806 | '<br />', |
| 1807 | 1807 | '<p>', |
| 1808 | - '<a href="' . get_post_type_archive_link('espresso_events') . '" title="', |
|
| 1808 | + '<a href="'.get_post_type_archive_link('espresso_events').'" title="', |
|
| 1809 | 1809 | '">', |
| 1810 | 1810 | '</a>', |
| 1811 | 1811 | '</p>' |
@@ -18,1428 +18,1428 @@ |
||
| 18 | 18 | class EE_SPCO_Reg_Step_Attendee_Information extends EE_SPCO_Reg_Step |
| 19 | 19 | { |
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * @type bool $_print_copy_info |
|
| 23 | - */ |
|
| 24 | - private $_print_copy_info = false; |
|
| 25 | - |
|
| 26 | - /** |
|
| 27 | - * @type array $_attendee_data |
|
| 28 | - */ |
|
| 29 | - private $_attendee_data = array(); |
|
| 30 | - |
|
| 31 | - /** |
|
| 32 | - * @type array $_required_questions |
|
| 33 | - */ |
|
| 34 | - private $_required_questions = array(); |
|
| 35 | - |
|
| 36 | - /** |
|
| 37 | - * @type array $_registration_answers |
|
| 38 | - */ |
|
| 39 | - private $_registration_answers = array(); |
|
| 40 | - |
|
| 41 | - |
|
| 42 | - /** |
|
| 43 | - * class constructor |
|
| 44 | - * |
|
| 45 | - * @access public |
|
| 46 | - * @param EE_Checkout $checkout |
|
| 47 | - */ |
|
| 48 | - public function __construct(EE_Checkout $checkout) |
|
| 49 | - { |
|
| 50 | - $this->_slug = 'attendee_information'; |
|
| 51 | - $this->_name = esc_html__('Attendee Information', 'event_espresso'); |
|
| 52 | - $this->_template = SPCO_REG_STEPS_PATH . $this->_slug . '/attendee_info_main.template.php'; |
|
| 53 | - $this->checkout = $checkout; |
|
| 54 | - $this->_reset_success_message(); |
|
| 55 | - $this->set_instructions( |
|
| 56 | - esc_html__('Please answer the following registration questions before proceeding.', 'event_espresso') |
|
| 57 | - ); |
|
| 58 | - } |
|
| 59 | - |
|
| 60 | - |
|
| 61 | - public function translate_js_strings() |
|
| 62 | - { |
|
| 63 | - EE_Registry::$i18n_js_strings['required_field'] = esc_html__( |
|
| 64 | - ' is a required question.', |
|
| 65 | - 'event_espresso' |
|
| 66 | - ); |
|
| 67 | - EE_Registry::$i18n_js_strings['required_multi_field'] = esc_html__( |
|
| 68 | - ' is a required question. Please enter a value for at least one of the options.', |
|
| 69 | - 'event_espresso' |
|
| 70 | - ); |
|
| 71 | - EE_Registry::$i18n_js_strings['answer_required_questions'] = esc_html__( |
|
| 72 | - 'Please answer all required questions correctly before proceeding.', |
|
| 73 | - 'event_espresso' |
|
| 74 | - ); |
|
| 75 | - EE_Registry::$i18n_js_strings['attendee_info_copied'] = sprintf( |
|
| 76 | - esc_html_x( |
|
| 77 | - 'The attendee information was successfully copied.%sPlease ensure the rest of the registration form is completed before proceeding.', |
|
| 78 | - 'The attendee information was successfully copied.(line break)Please ensure the rest of the registration form is completed before proceeding.', |
|
| 79 | - 'event_espresso' |
|
| 80 | - ), |
|
| 81 | - '<br/>' |
|
| 82 | - ); |
|
| 83 | - EE_Registry::$i18n_js_strings['attendee_info_copy_error'] = esc_html__( |
|
| 84 | - 'An unknown error occurred on the server while attempting to copy the attendee information. Please refresh the page and try again.', |
|
| 85 | - 'event_espresso' |
|
| 86 | - ); |
|
| 87 | - EE_Registry::$i18n_js_strings['enter_valid_email'] = esc_html__( |
|
| 88 | - 'You must enter a valid email address.', |
|
| 89 | - 'event_espresso' |
|
| 90 | - ); |
|
| 91 | - EE_Registry::$i18n_js_strings['valid_email_and_questions'] = esc_html__( |
|
| 92 | - 'You must enter a valid email address and answer all other required questions before you can proceed.', |
|
| 93 | - 'event_espresso' |
|
| 94 | - ); |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - |
|
| 98 | - public function enqueue_styles_and_scripts() |
|
| 99 | - { |
|
| 100 | - } |
|
| 101 | - |
|
| 102 | - |
|
| 103 | - /** |
|
| 104 | - * @return boolean |
|
| 105 | - */ |
|
| 106 | - public function initialize_reg_step() |
|
| 107 | - { |
|
| 108 | - return true; |
|
| 109 | - } |
|
| 110 | - |
|
| 111 | - |
|
| 112 | - /** |
|
| 113 | - * @return EE_Form_Section_Proper |
|
| 114 | - * @throws DomainException |
|
| 115 | - * @throws EE_Error |
|
| 116 | - * @throws InvalidArgumentException |
|
| 117 | - * @throws ReflectionException |
|
| 118 | - * @throws EntityNotFoundException |
|
| 119 | - * @throws InvalidDataTypeException |
|
| 120 | - * @throws InvalidInterfaceException |
|
| 121 | - */ |
|
| 122 | - public function generate_reg_form() |
|
| 123 | - { |
|
| 124 | - $this->_print_copy_info = false; |
|
| 125 | - $primary_registrant = null; |
|
| 126 | - // autoload Line_Item_Display classes |
|
| 127 | - EEH_Autoloader::register_line_item_display_autoloaders(); |
|
| 128 | - $Line_Item_Display = new EE_Line_Item_Display(); |
|
| 129 | - // calculate taxes |
|
| 130 | - $Line_Item_Display->display_line_item( |
|
| 131 | - $this->checkout->cart->get_grand_total(), |
|
| 132 | - array('set_tax_rate' => true) |
|
| 133 | - ); |
|
| 134 | - /** @var $subsections EE_Form_Section_Proper[] */ |
|
| 135 | - $extra_inputs_section = $this->reg_step_hidden_inputs(); |
|
| 136 | - $subsections = array( |
|
| 137 | - 'default_hidden_inputs' => $extra_inputs_section, |
|
| 138 | - ); |
|
| 139 | - |
|
| 140 | - /** |
|
| 141 | - * @var $reg_config EE_Registration_Config |
|
| 142 | - */ |
|
| 143 | - $reg_config = LoaderFactory::getLoader()->getShared('EE_Registration_Config'); |
|
| 144 | - // if this isn't a revisit, and they have the privacy consent box enalbed, add it |
|
| 145 | - if (! $this->checkout->revisit && $reg_config->isConsentCheckboxEnabled()) { |
|
| 146 | - $extra_inputs_section->add_subsections( |
|
| 147 | - array( |
|
| 148 | - 'consent_box' => new EE_Form_Section_Proper( |
|
| 149 | - array( |
|
| 150 | - 'layout_strategy' => |
|
| 151 | - new EE_Template_Layout( |
|
| 152 | - array( |
|
| 153 | - 'input_template_file' => SPCO_REG_STEPS_PATH . $this->_slug . '/privacy_consent.template.php', |
|
| 154 | - ) |
|
| 155 | - ), |
|
| 156 | - 'subsections' => array( |
|
| 157 | - 'consent' => new EE_Checkbox_Multi_Input( |
|
| 158 | - array( |
|
| 159 | - 'consent' => $reg_config->getConsentCheckboxLabelText(), |
|
| 160 | - ), |
|
| 161 | - array( |
|
| 162 | - 'required' => true, |
|
| 163 | - 'required_validation_error_message' => esc_html__( |
|
| 164 | - 'You must consent to these terms in order to register.', |
|
| 165 | - 'event_espresso' |
|
| 166 | - ), |
|
| 167 | - 'html_label_text' => '', |
|
| 168 | - ) |
|
| 169 | - ), |
|
| 170 | - ), |
|
| 171 | - ) |
|
| 172 | - ), |
|
| 173 | - ), |
|
| 174 | - null, |
|
| 175 | - false |
|
| 176 | - ); |
|
| 177 | - } |
|
| 178 | - $template_args = array( |
|
| 179 | - 'revisit' => $this->checkout->revisit, |
|
| 180 | - 'registrations' => array(), |
|
| 181 | - 'ticket_count' => array(), |
|
| 182 | - ); |
|
| 183 | - // grab the saved registrations from the transaction |
|
| 184 | - $registrations = $this->checkout->transaction->registrations($this->checkout->reg_cache_where_params); |
|
| 185 | - if ($registrations) { |
|
| 186 | - foreach ($registrations as $registration) { |
|
| 187 | - // can this registration be processed during this visit ? |
|
| 188 | - if ($registration instanceof EE_Registration |
|
| 189 | - && $this->checkout->visit_allows_processing_of_this_registration($registration) |
|
| 190 | - ) { |
|
| 191 | - $subsections[ $registration->reg_url_link() ] = $this->_registrations_reg_form($registration); |
|
| 192 | - if (! $this->checkout->admin_request) { |
|
| 193 | - $template_args['registrations'][ $registration->reg_url_link() ] = $registration; |
|
| 194 | - $template_args['ticket_count'][ $registration->ticket()->ID() ] = isset( |
|
| 195 | - $template_args['ticket_count'][ $registration->ticket()->ID() ] |
|
| 196 | - ) |
|
| 197 | - ? $template_args['ticket_count'][ $registration->ticket()->ID() ] + 1 |
|
| 198 | - : 1; |
|
| 199 | - $ticket_line_item = EEH_Line_Item::get_line_items_by_object_type_and_IDs( |
|
| 200 | - $this->checkout->cart->get_grand_total(), |
|
| 201 | - 'Ticket', |
|
| 202 | - array($registration->ticket()->ID()) |
|
| 203 | - ); |
|
| 204 | - $ticket_line_item = is_array($ticket_line_item) |
|
| 205 | - ? reset($ticket_line_item) |
|
| 206 | - : $ticket_line_item; |
|
| 207 | - $template_args['ticket_line_item'][ $registration->ticket()->ID() ] = |
|
| 208 | - $Line_Item_Display->display_line_item($ticket_line_item); |
|
| 209 | - } |
|
| 210 | - if ($registration->is_primary_registrant()) { |
|
| 211 | - $primary_registrant = $registration->reg_url_link(); |
|
| 212 | - } |
|
| 213 | - } |
|
| 214 | - } |
|
| 215 | - // print_copy_info ? |
|
| 216 | - if ($primary_registrant && ! $this->checkout->admin_request && count($registrations) > 1) { |
|
| 217 | - // TODO: add admin option for toggling copy attendee info, |
|
| 218 | - // then use that value to change $this->_print_copy_info |
|
| 219 | - $copy_options['spco_copy_attendee_chk'] = $this->_print_copy_info |
|
| 220 | - ? $this->_copy_attendee_info_form() |
|
| 221 | - : $this->_auto_copy_attendee_info(); |
|
| 222 | - // generate hidden input |
|
| 223 | - if (isset($subsections[ $primary_registrant ]) |
|
| 224 | - && $subsections[ $primary_registrant ] instanceof EE_Form_Section_Proper |
|
| 225 | - ) { |
|
| 226 | - $subsections[ $primary_registrant ]->add_subsections( |
|
| 227 | - $copy_options, |
|
| 228 | - 'primary_registrant', |
|
| 229 | - false |
|
| 230 | - ); |
|
| 231 | - } |
|
| 232 | - } |
|
| 233 | - } |
|
| 234 | - return new EE_Form_Section_Proper( |
|
| 235 | - array( |
|
| 236 | - 'name' => $this->reg_form_name(), |
|
| 237 | - 'html_id' => $this->reg_form_name(), |
|
| 238 | - 'subsections' => $subsections, |
|
| 239 | - 'layout_strategy' => $this->checkout->admin_request |
|
| 240 | - ? |
|
| 241 | - new EE_Div_Per_Section_Layout() |
|
| 242 | - : |
|
| 243 | - new EE_Template_Layout( |
|
| 244 | - array( |
|
| 245 | - 'layout_template_file' => $this->_template, // layout_template |
|
| 246 | - 'template_args' => $template_args, |
|
| 247 | - ) |
|
| 248 | - ), |
|
| 249 | - ) |
|
| 250 | - ); |
|
| 251 | - } |
|
| 252 | - |
|
| 253 | - |
|
| 254 | - /** |
|
| 255 | - * @param EE_Registration $registration |
|
| 256 | - * @return EE_Form_Section_Base |
|
| 257 | - * @throws EE_Error |
|
| 258 | - * @throws InvalidArgumentException |
|
| 259 | - * @throws EntityNotFoundException |
|
| 260 | - * @throws InvalidDataTypeException |
|
| 261 | - * @throws InvalidInterfaceException |
|
| 262 | - * @throws ReflectionException |
|
| 263 | - */ |
|
| 264 | - private function _registrations_reg_form(EE_Registration $registration) |
|
| 265 | - { |
|
| 266 | - static $attendee_nmbr = 1; |
|
| 267 | - $form_args = array(); |
|
| 268 | - // verify that registration has valid event |
|
| 269 | - if ($registration->event() instanceof EE_Event) { |
|
| 270 | - $field_name = 'Event_Question_Group.' |
|
| 271 | - . EEM_Event_Question_Group::instance()->fieldNameForContext( |
|
| 272 | - $registration->is_primary_registrant() |
|
| 273 | - ); |
|
| 274 | - $question_groups = $registration->event()->question_groups( |
|
| 275 | - apply_filters( |
|
| 276 | - // @codingStandardsIgnoreStart |
|
| 277 | - 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___registrations_reg_form__question_groups_query_parameters', |
|
| 278 | - // @codingStandardsIgnoreEnd |
|
| 279 | - [ |
|
| 280 | - [ |
|
| 281 | - 'Event.EVT_ID' => $registration->event()->ID(), |
|
| 282 | - $field_name => true, |
|
| 283 | - ], |
|
| 284 | - 'order_by' => ['QSG_order' => 'ASC'], |
|
| 285 | - ], |
|
| 286 | - $registration, |
|
| 287 | - $this |
|
| 288 | - ) |
|
| 289 | - ); |
|
| 290 | - if ($question_groups) { |
|
| 291 | - // array of params to pass to parent constructor |
|
| 292 | - $form_args = array( |
|
| 293 | - 'html_id' => 'ee-registration-' . $registration->reg_url_link(), |
|
| 294 | - 'html_class' => 'ee-reg-form-attendee-dv', |
|
| 295 | - 'html_style' => $this->checkout->admin_request |
|
| 296 | - ? 'padding:0em 2em 1em; margin:3em 0 0; border:1px solid #ddd;' |
|
| 297 | - : '', |
|
| 298 | - 'subsections' => array(), |
|
| 299 | - 'layout_strategy' => new EE_Fieldset_Section_Layout( |
|
| 300 | - array( |
|
| 301 | - 'legend_class' => 'spco-attendee-lgnd smaller-text lt-grey-text', |
|
| 302 | - 'legend_text' => sprintf( |
|
| 303 | - esc_html_x( |
|
| 304 | - 'Attendee %d', |
|
| 305 | - 'Attendee 123', |
|
| 306 | - 'event_espresso' |
|
| 307 | - ), |
|
| 308 | - $attendee_nmbr |
|
| 309 | - ), |
|
| 310 | - ) |
|
| 311 | - ), |
|
| 312 | - ); |
|
| 313 | - foreach ($question_groups as $question_group) { |
|
| 314 | - if ($question_group instanceof EE_Question_Group) { |
|
| 315 | - $form_args['subsections'][ $question_group->identifier() ] = $this->_question_group_reg_form( |
|
| 316 | - $registration, |
|
| 317 | - $question_group |
|
| 318 | - ); |
|
| 319 | - } |
|
| 320 | - } |
|
| 321 | - // add hidden input |
|
| 322 | - $form_args['subsections']['additional_attendee_reg_info'] = $this->_additional_attendee_reg_info_input( |
|
| 323 | - $registration |
|
| 324 | - ); |
|
| 325 | - // if we have question groups for additional attendees, then display the copy options |
|
| 326 | - $this->_print_copy_info = $attendee_nmbr > 1 ? true : $this->_print_copy_info; |
|
| 327 | - if ($registration->is_primary_registrant()) { |
|
| 328 | - // generate hidden input |
|
| 329 | - $form_args['subsections']['primary_registrant'] = $this->_additional_primary_registrant_inputs( |
|
| 330 | - $registration |
|
| 331 | - ); |
|
| 332 | - } |
|
| 333 | - } |
|
| 334 | - } |
|
| 335 | - $attendee_nmbr++; |
|
| 336 | - return ! empty($form_args) |
|
| 337 | - ? new EE_Form_Section_Proper($form_args) |
|
| 338 | - : new EE_Form_Section_HTML(); |
|
| 339 | - } |
|
| 340 | - |
|
| 341 | - |
|
| 342 | - /** |
|
| 343 | - * @param EE_Registration $registration |
|
| 344 | - * @param bool $additional_attendee_reg_info |
|
| 345 | - * @return EE_Form_Input_Base |
|
| 346 | - * @throws EE_Error |
|
| 347 | - */ |
|
| 348 | - private function _additional_attendee_reg_info_input( |
|
| 349 | - EE_Registration $registration, |
|
| 350 | - $additional_attendee_reg_info = true |
|
| 351 | - ) { |
|
| 352 | - // generate hidden input |
|
| 353 | - return new EE_Hidden_Input( |
|
| 354 | - array( |
|
| 355 | - 'html_id' => 'additional-attendee-reg-info-' . $registration->reg_url_link(), |
|
| 356 | - 'default' => $additional_attendee_reg_info, |
|
| 357 | - ) |
|
| 358 | - ); |
|
| 359 | - } |
|
| 360 | - |
|
| 361 | - |
|
| 362 | - /** |
|
| 363 | - * @param EE_Registration $registration |
|
| 364 | - * @param EE_Question_Group $question_group |
|
| 365 | - * @return EE_Form_Section_Proper |
|
| 366 | - * @throws EE_Error |
|
| 367 | - * @throws InvalidArgumentException |
|
| 368 | - * @throws InvalidDataTypeException |
|
| 369 | - * @throws InvalidInterfaceException |
|
| 370 | - * @throws ReflectionException |
|
| 371 | - */ |
|
| 372 | - private function _question_group_reg_form(EE_Registration $registration, EE_Question_Group $question_group) |
|
| 373 | - { |
|
| 374 | - // array of params to pass to parent constructor |
|
| 375 | - $form_args = array( |
|
| 376 | - 'html_id' => 'ee-reg-form-qstn-grp-' . $question_group->identifier() . '-' . $registration->ID(), |
|
| 377 | - 'html_class' => $this->checkout->admin_request |
|
| 378 | - ? 'form-table ee-reg-form-qstn-grp-dv' |
|
| 379 | - : 'ee-reg-form-qstn-grp-dv', |
|
| 380 | - 'html_label_id' => 'ee-reg-form-qstn-grp-' . $question_group->identifier() . '-' |
|
| 381 | - . $registration->ID() . '-lbl', |
|
| 382 | - 'subsections' => array( |
|
| 383 | - 'reg_form_qstn_grp_hdr' => $this->_question_group_header($question_group), |
|
| 384 | - ), |
|
| 385 | - 'layout_strategy' => $this->checkout->admin_request |
|
| 386 | - ? new EE_Admin_Two_Column_Layout() |
|
| 387 | - : new EE_Div_Per_Section_Layout(), |
|
| 388 | - ); |
|
| 389 | - // where params |
|
| 390 | - $query_params = array('QST_deleted' => 0); |
|
| 391 | - // don't load admin only questions on the frontend |
|
| 392 | - if (! $this->checkout->admin_request) { |
|
| 393 | - $query_params['QST_admin_only'] = array('!=', true); |
|
| 394 | - } |
|
| 395 | - $questions = $question_group->get_many_related( |
|
| 396 | - 'Question', |
|
| 397 | - apply_filters( |
|
| 398 | - 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___question_group_reg_form__related_questions_query_params', |
|
| 399 | - array( |
|
| 400 | - $query_params, |
|
| 401 | - 'order_by' => array( |
|
| 402 | - 'Question_Group_Question.QGQ_order' => 'ASC', |
|
| 403 | - ), |
|
| 404 | - ), |
|
| 405 | - $question_group, |
|
| 406 | - $registration, |
|
| 407 | - $this |
|
| 408 | - ) |
|
| 409 | - ); |
|
| 410 | - // filter for additional content before questions |
|
| 411 | - $form_args['subsections']['reg_form_questions_before'] = new EE_Form_Section_HTML( |
|
| 412 | - apply_filters( |
|
| 413 | - 'FHEE__EEH_Form_Fields__generate_question_groups_html__before_question_group_questions', |
|
| 414 | - '', |
|
| 415 | - $registration, |
|
| 416 | - $question_group, |
|
| 417 | - $this |
|
| 418 | - ) |
|
| 419 | - ); |
|
| 420 | - // loop thru questions |
|
| 421 | - foreach ($questions as $question) { |
|
| 422 | - if ($question instanceof EE_Question) { |
|
| 423 | - $identifier = $question->is_system_question() |
|
| 424 | - ? $question->system_ID() |
|
| 425 | - : $question->ID(); |
|
| 426 | - $form_args['subsections'][ $identifier ] = $this->reg_form_question($registration, $question); |
|
| 427 | - } |
|
| 428 | - } |
|
| 429 | - $form_args['subsections'] = apply_filters( |
|
| 430 | - 'FHEE__EE_SPCO_Reg_Step_Attendee_Information__question_group_reg_form__subsections_array', |
|
| 431 | - $form_args['subsections'], |
|
| 432 | - $registration, |
|
| 433 | - $question_group, |
|
| 434 | - $this |
|
| 435 | - ); |
|
| 436 | - // filter for additional content after questions |
|
| 437 | - $form_args['subsections']['reg_form_questions_after'] = new EE_Form_Section_HTML( |
|
| 438 | - apply_filters( |
|
| 439 | - 'FHEE__EEH_Form_Fields__generate_question_groups_html__after_question_group_questions', |
|
| 440 | - '', |
|
| 441 | - $registration, |
|
| 442 | - $question_group, |
|
| 443 | - $this |
|
| 444 | - ) |
|
| 445 | - ); |
|
| 446 | - // d($form_args); |
|
| 447 | - $question_group_reg_form = new EE_Form_Section_Proper($form_args); |
|
| 448 | - return apply_filters( |
|
| 449 | - 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___question_group_reg_form__question_group_reg_form', |
|
| 450 | - $question_group_reg_form, |
|
| 451 | - $registration, |
|
| 452 | - $question_group, |
|
| 453 | - $this |
|
| 454 | - ); |
|
| 455 | - } |
|
| 456 | - |
|
| 457 | - |
|
| 458 | - /** |
|
| 459 | - * @param EE_Question_Group $question_group |
|
| 460 | - * @return EE_Form_Section_HTML |
|
| 461 | - */ |
|
| 462 | - private function _question_group_header(EE_Question_Group $question_group) |
|
| 463 | - { |
|
| 464 | - $html = ''; |
|
| 465 | - // group_name |
|
| 466 | - if ($question_group->show_group_name() && $question_group->name() !== '') { |
|
| 467 | - if ($this->checkout->admin_request) { |
|
| 468 | - $html .= EEH_HTML::br(); |
|
| 469 | - $html .= EEH_HTML::h3( |
|
| 470 | - $question_group->name(), |
|
| 471 | - '', |
|
| 472 | - 'ee-reg-form-qstn-grp-title title', |
|
| 473 | - 'font-size: 1.3em; padding-left:0;' |
|
| 474 | - ); |
|
| 475 | - } else { |
|
| 476 | - $html .= EEH_HTML::h4( |
|
| 477 | - $question_group->name(), |
|
| 478 | - '', |
|
| 479 | - 'ee-reg-form-qstn-grp-title section-title' |
|
| 480 | - ); |
|
| 481 | - } |
|
| 482 | - } |
|
| 483 | - // group_desc |
|
| 484 | - if ($question_group->show_group_desc() && $question_group->desc() !== '') { |
|
| 485 | - $html .= EEH_HTML::p( |
|
| 486 | - $question_group->desc(), |
|
| 487 | - '', |
|
| 488 | - $this->checkout->admin_request |
|
| 489 | - ? 'ee-reg-form-qstn-grp-desc-pg' |
|
| 490 | - : 'ee-reg-form-qstn-grp-desc-pg small-text lt-grey-text' |
|
| 491 | - ); |
|
| 492 | - } |
|
| 493 | - return new EE_Form_Section_HTML($html); |
|
| 494 | - } |
|
| 495 | - |
|
| 496 | - |
|
| 497 | - /** |
|
| 498 | - * @return EE_Form_Section_Proper |
|
| 499 | - * @throws EE_Error |
|
| 500 | - * @throws InvalidArgumentException |
|
| 501 | - * @throws ReflectionException |
|
| 502 | - * @throws InvalidDataTypeException |
|
| 503 | - * @throws InvalidInterfaceException |
|
| 504 | - */ |
|
| 505 | - private function _copy_attendee_info_form() |
|
| 506 | - { |
|
| 507 | - // array of params to pass to parent constructor |
|
| 508 | - return new EE_Form_Section_Proper( |
|
| 509 | - array( |
|
| 510 | - 'subsections' => $this->_copy_attendee_info_inputs(), |
|
| 511 | - 'layout_strategy' => new EE_Template_Layout( |
|
| 512 | - array( |
|
| 513 | - 'layout_template_file' => SPCO_REG_STEPS_PATH |
|
| 514 | - . $this->_slug |
|
| 515 | - . '/copy_attendee_info.template.php', |
|
| 516 | - 'begin_template_file' => null, |
|
| 517 | - 'input_template_file' => null, |
|
| 518 | - 'subsection_template_file' => null, |
|
| 519 | - 'end_template_file' => null, |
|
| 520 | - ) |
|
| 521 | - ), |
|
| 522 | - ) |
|
| 523 | - ); |
|
| 524 | - } |
|
| 525 | - |
|
| 526 | - |
|
| 527 | - /** |
|
| 528 | - * @return EE_Form_Section_HTML |
|
| 529 | - * @throws DomainException |
|
| 530 | - * @throws InvalidArgumentException |
|
| 531 | - * @throws InvalidDataTypeException |
|
| 532 | - * @throws InvalidInterfaceException |
|
| 533 | - */ |
|
| 534 | - private function _auto_copy_attendee_info() |
|
| 535 | - { |
|
| 536 | - return new EE_Form_Section_HTML( |
|
| 537 | - EEH_Template::locate_template( |
|
| 538 | - SPCO_REG_STEPS_PATH . $this->_slug . '/_auto_copy_attendee_info.template.php', |
|
| 539 | - apply_filters( |
|
| 540 | - 'FHEE__EE_SPCO_Reg_Step_Attendee_Information__auto_copy_attendee_info__template_args', |
|
| 541 | - array() |
|
| 542 | - ), |
|
| 543 | - true, |
|
| 544 | - true |
|
| 545 | - ) |
|
| 546 | - ); |
|
| 547 | - } |
|
| 548 | - |
|
| 549 | - |
|
| 550 | - /** |
|
| 551 | - * @return array |
|
| 552 | - * @throws EE_Error |
|
| 553 | - * @throws InvalidArgumentException |
|
| 554 | - * @throws ReflectionException |
|
| 555 | - * @throws InvalidDataTypeException |
|
| 556 | - * @throws InvalidInterfaceException |
|
| 557 | - */ |
|
| 558 | - private function _copy_attendee_info_inputs() |
|
| 559 | - { |
|
| 560 | - $copy_attendee_info_inputs = array(); |
|
| 561 | - $prev_ticket = null; |
|
| 562 | - // grab the saved registrations from the transaction |
|
| 563 | - $registrations = $this->checkout->transaction->registrations($this->checkout->reg_cache_where_params); |
|
| 564 | - foreach ($registrations as $registration) { |
|
| 565 | - // for all attendees other than the primary attendee |
|
| 566 | - if ($registration instanceof EE_Registration && ! $registration->is_primary_registrant()) { |
|
| 567 | - // if this is a new ticket OR if this is the very first additional attendee after the primary attendee |
|
| 568 | - if ($registration->ticket()->ID() !== $prev_ticket) { |
|
| 569 | - $item_name = $registration->ticket()->name(); |
|
| 570 | - $item_name .= $registration->ticket()->description() !== '' |
|
| 571 | - ? ' - ' . $registration->ticket()->description() |
|
| 572 | - : ''; |
|
| 573 | - $copy_attendee_info_inputs[ 'spco_copy_attendee_chk[ticket-' . $registration->ticket()->ID( |
|
| 574 | - ) . ']' ] = |
|
| 575 | - new EE_Form_Section_HTML( |
|
| 576 | - '<h6 class="spco-copy-attendee-event-hdr">' . $item_name . '</h6>' |
|
| 577 | - ); |
|
| 578 | - $prev_ticket = $registration->ticket()->ID(); |
|
| 579 | - } |
|
| 580 | - |
|
| 581 | - $copy_attendee_info_inputs[ 'spco_copy_attendee_chk[' . $registration->ID() . ']' ] = |
|
| 582 | - new EE_Checkbox_Multi_Input( |
|
| 583 | - array( |
|
| 584 | - $registration->ID() => sprintf( |
|
| 585 | - esc_html_x('Attendee #%s', 'Attendee #123', 'event_espresso'), |
|
| 586 | - $registration->count() |
|
| 587 | - ), |
|
| 588 | - ), |
|
| 589 | - array( |
|
| 590 | - 'html_id' => 'spco-copy-attendee-chk-' . $registration->reg_url_link(), |
|
| 591 | - 'html_class' => 'spco-copy-attendee-chk ee-do-not-validate', |
|
| 592 | - 'display_html_label_text' => false, |
|
| 593 | - ) |
|
| 594 | - ); |
|
| 595 | - } |
|
| 596 | - } |
|
| 597 | - return $copy_attendee_info_inputs; |
|
| 598 | - } |
|
| 599 | - |
|
| 600 | - |
|
| 601 | - /** |
|
| 602 | - * @param EE_Registration $registration |
|
| 603 | - * @return EE_Form_Input_Base |
|
| 604 | - * @throws EE_Error |
|
| 605 | - */ |
|
| 606 | - private function _additional_primary_registrant_inputs(EE_Registration $registration) |
|
| 607 | - { |
|
| 608 | - // generate hidden input |
|
| 609 | - return new EE_Hidden_Input( |
|
| 610 | - array( |
|
| 611 | - 'html_id' => 'primary_registrant', |
|
| 612 | - 'default' => $registration->reg_url_link(), |
|
| 613 | - ) |
|
| 614 | - ); |
|
| 615 | - } |
|
| 616 | - |
|
| 617 | - |
|
| 618 | - /** |
|
| 619 | - * @param EE_Registration $registration |
|
| 620 | - * @param EE_Question $question |
|
| 621 | - * @return EE_Form_Input_Base |
|
| 622 | - * @throws EE_Error |
|
| 623 | - * @throws InvalidArgumentException |
|
| 624 | - * @throws InvalidDataTypeException |
|
| 625 | - * @throws InvalidInterfaceException |
|
| 626 | - * @throws ReflectionException |
|
| 627 | - */ |
|
| 628 | - public function reg_form_question(EE_Registration $registration, EE_Question $question) |
|
| 629 | - { |
|
| 630 | - |
|
| 631 | - // if this question was for an attendee detail, then check for that answer |
|
| 632 | - $answer_value = EEM_Answer::instance()->get_attendee_property_answer_value( |
|
| 633 | - $registration, |
|
| 634 | - $question->system_ID() |
|
| 635 | - ); |
|
| 636 | - $answer = $answer_value === null |
|
| 637 | - ? EEM_Answer::instance()->get_one( |
|
| 638 | - array(array('QST_ID' => $question->ID(), 'REG_ID' => $registration->ID())) |
|
| 639 | - ) |
|
| 640 | - : null; |
|
| 641 | - // if NOT returning to edit an existing registration |
|
| 642 | - // OR if this question is for an attendee property |
|
| 643 | - // OR we still don't have an EE_Answer object |
|
| 644 | - if ($answer_value || ! $answer instanceof EE_Answer || ! $registration->reg_url_link()) { |
|
| 645 | - // create an EE_Answer object for storing everything in |
|
| 646 | - $answer = EE_Answer::new_instance( |
|
| 647 | - array( |
|
| 648 | - 'QST_ID' => $question->ID(), |
|
| 649 | - 'REG_ID' => $registration->ID(), |
|
| 650 | - ) |
|
| 651 | - ); |
|
| 652 | - } |
|
| 653 | - // verify instance |
|
| 654 | - if ($answer instanceof EE_Answer) { |
|
| 655 | - if (! empty($answer_value)) { |
|
| 656 | - $answer->set('ANS_value', $answer_value); |
|
| 657 | - } |
|
| 658 | - $answer->cache('Question', $question); |
|
| 659 | - // remember system ID had a bug where sometimes it could be null |
|
| 660 | - $answer_cache_id = $question->is_system_question() |
|
| 661 | - ? $question->system_ID() . '-' . $registration->reg_url_link() |
|
| 662 | - : $question->ID() . '-' . $registration->reg_url_link(); |
|
| 663 | - $registration->cache('Answer', $answer, $answer_cache_id); |
|
| 664 | - } |
|
| 665 | - return $this->_generate_question_input($registration, $question, $answer); |
|
| 666 | - } |
|
| 667 | - |
|
| 668 | - |
|
| 669 | - /** |
|
| 670 | - * @param EE_Registration $registration |
|
| 671 | - * @param EE_Question $question |
|
| 672 | - * @param $answer |
|
| 673 | - * @return EE_Form_Input_Base |
|
| 674 | - * @throws EE_Error |
|
| 675 | - * @throws InvalidArgumentException |
|
| 676 | - * @throws ReflectionException |
|
| 677 | - * @throws InvalidDataTypeException |
|
| 678 | - * @throws InvalidInterfaceException |
|
| 679 | - */ |
|
| 680 | - private function _generate_question_input(EE_Registration $registration, EE_Question $question, $answer) |
|
| 681 | - { |
|
| 682 | - $identifier = $question->is_system_question() |
|
| 683 | - ? $question->system_ID() |
|
| 684 | - : $question->ID(); |
|
| 685 | - $this->_required_questions[ $identifier ] = $question->required() ? true : false; |
|
| 686 | - add_filter( |
|
| 687 | - 'FHEE__EE_Question__generate_form_input__country_options', |
|
| 688 | - array($this, 'use_cached_countries_for_form_input'), |
|
| 689 | - 10, |
|
| 690 | - 4 |
|
| 691 | - ); |
|
| 692 | - add_filter( |
|
| 693 | - 'FHEE__EE_Question__generate_form_input__state_options', |
|
| 694 | - array($this, 'use_cached_states_for_form_input'), |
|
| 695 | - 10, |
|
| 696 | - 4 |
|
| 697 | - ); |
|
| 698 | - $input_constructor_args = array( |
|
| 699 | - 'html_name' => 'ee_reg_qstn[' . $registration->ID() . '][' . $identifier . ']', |
|
| 700 | - 'html_id' => 'ee_reg_qstn-' . $registration->ID() . '-' . $identifier, |
|
| 701 | - 'html_class' => 'ee-reg-qstn ee-reg-qstn-' . $identifier, |
|
| 702 | - 'html_label_id' => 'ee_reg_qstn-' . $registration->ID() . '-' . $identifier, |
|
| 703 | - 'html_label_class' => 'ee-reg-qstn', |
|
| 704 | - ); |
|
| 705 | - $input_constructor_args['html_label_id'] .= '-lbl'; |
|
| 706 | - if ($answer instanceof EE_Answer && $answer->ID()) { |
|
| 707 | - $input_constructor_args['html_name'] .= '[' . $answer->ID() . ']'; |
|
| 708 | - $input_constructor_args['html_id'] .= '-' . $answer->ID(); |
|
| 709 | - $input_constructor_args['html_label_id'] .= '-' . $answer->ID(); |
|
| 710 | - } |
|
| 711 | - $form_input = $question->generate_form_input( |
|
| 712 | - $registration, |
|
| 713 | - $answer, |
|
| 714 | - $input_constructor_args |
|
| 715 | - ); |
|
| 716 | - remove_filter( |
|
| 717 | - 'FHEE__EE_Question__generate_form_input__country_options', |
|
| 718 | - array($this, 'use_cached_countries_for_form_input') |
|
| 719 | - ); |
|
| 720 | - remove_filter( |
|
| 721 | - 'FHEE__EE_Question__generate_form_input__state_options', |
|
| 722 | - array($this, 'use_cached_states_for_form_input') |
|
| 723 | - ); |
|
| 724 | - return $form_input; |
|
| 725 | - } |
|
| 726 | - |
|
| 727 | - |
|
| 728 | - /** |
|
| 729 | - * Gets the list of countries for the form input |
|
| 730 | - * |
|
| 731 | - * @param array|null $countries_list |
|
| 732 | - * @param EE_Question $question |
|
| 733 | - * @param EE_Registration $registration |
|
| 734 | - * @param EE_Answer $answer |
|
| 735 | - * @return array 2d keys are country IDs, values are their names |
|
| 736 | - * @throws EE_Error |
|
| 737 | - * @throws InvalidArgumentException |
|
| 738 | - * @throws InvalidDataTypeException |
|
| 739 | - * @throws InvalidInterfaceException |
|
| 740 | - * @throws ReflectionException |
|
| 741 | - */ |
|
| 742 | - public function use_cached_countries_for_form_input( |
|
| 743 | - $countries_list, |
|
| 744 | - EE_Question $question = null, |
|
| 745 | - EE_Registration $registration = null, |
|
| 746 | - EE_Answer $answer = null |
|
| 747 | - ) { |
|
| 748 | - $country_options = array('' => ''); |
|
| 749 | - // get possibly cached list of countries |
|
| 750 | - $countries = $this->checkout->action === 'process_reg_step' |
|
| 751 | - ? EEM_Country::instance()->get_all_countries() |
|
| 752 | - : EEM_Country::instance()->get_all_active_countries(); |
|
| 753 | - if (! empty($countries)) { |
|
| 754 | - foreach ($countries as $country) { |
|
| 755 | - if ($country instanceof EE_Country) { |
|
| 756 | - $country_options[ $country->ID() ] = $country->name(); |
|
| 757 | - } |
|
| 758 | - } |
|
| 759 | - } |
|
| 760 | - if ($question instanceof EE_Question && $registration instanceof EE_Registration) { |
|
| 761 | - $answer = EEM_Answer::instance()->get_one( |
|
| 762 | - array(array('QST_ID' => $question->ID(), 'REG_ID' => $registration->ID())) |
|
| 763 | - ); |
|
| 764 | - } else { |
|
| 765 | - $answer = EE_Answer::new_instance(); |
|
| 766 | - } |
|
| 767 | - $country_options = apply_filters( |
|
| 768 | - 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__country_options', |
|
| 769 | - $country_options, |
|
| 770 | - $this, |
|
| 771 | - $registration, |
|
| 772 | - $question, |
|
| 773 | - $answer |
|
| 774 | - ); |
|
| 775 | - return $country_options; |
|
| 776 | - } |
|
| 777 | - |
|
| 778 | - |
|
| 779 | - /** |
|
| 780 | - * Gets the list of states for the form input |
|
| 781 | - * |
|
| 782 | - * @param array|null $states_list |
|
| 783 | - * @param EE_Question $question |
|
| 784 | - * @param EE_Registration $registration |
|
| 785 | - * @param EE_Answer $answer |
|
| 786 | - * @return array 2d keys are state IDs, values are their names |
|
| 787 | - * @throws EE_Error |
|
| 788 | - * @throws InvalidArgumentException |
|
| 789 | - * @throws InvalidDataTypeException |
|
| 790 | - * @throws InvalidInterfaceException |
|
| 791 | - * @throws ReflectionException |
|
| 792 | - */ |
|
| 793 | - public function use_cached_states_for_form_input( |
|
| 794 | - $states_list, |
|
| 795 | - EE_Question $question = null, |
|
| 796 | - EE_Registration $registration = null, |
|
| 797 | - EE_Answer $answer = null |
|
| 798 | - ) { |
|
| 799 | - $state_options = array('' => array('' => '')); |
|
| 800 | - $states = $this->checkout->action === 'process_reg_step' |
|
| 801 | - ? EEM_State::instance()->get_all_states() |
|
| 802 | - : EEM_State::instance()->get_all_active_states(); |
|
| 803 | - if (! empty($states)) { |
|
| 804 | - foreach ($states as $state) { |
|
| 805 | - if ($state instanceof EE_State) { |
|
| 806 | - $state_options[ $state->country()->name() ][ $state->ID() ] = $state->name(); |
|
| 807 | - } |
|
| 808 | - } |
|
| 809 | - } |
|
| 810 | - $state_options = apply_filters( |
|
| 811 | - 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__state_options', |
|
| 812 | - $state_options, |
|
| 813 | - $this, |
|
| 814 | - $registration, |
|
| 815 | - $question, |
|
| 816 | - $answer |
|
| 817 | - ); |
|
| 818 | - return $state_options; |
|
| 819 | - } |
|
| 820 | - |
|
| 821 | - |
|
| 822 | - /********************************************************************************************************/ |
|
| 823 | - /**************************************** PROCESS REG STEP ****************************************/ |
|
| 824 | - /********************************************************************************************************/ |
|
| 825 | - |
|
| 826 | - |
|
| 827 | - /** |
|
| 828 | - * @return bool |
|
| 829 | - * @throws EE_Error |
|
| 830 | - * @throws InvalidArgumentException |
|
| 831 | - * @throws ReflectionException |
|
| 832 | - * @throws RuntimeException |
|
| 833 | - * @throws InvalidDataTypeException |
|
| 834 | - * @throws InvalidInterfaceException |
|
| 835 | - */ |
|
| 836 | - public function process_reg_step() |
|
| 837 | - { |
|
| 838 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 839 | - // grab validated data from form |
|
| 840 | - $valid_data = $this->checkout->current_step->valid_data(); |
|
| 841 | - // EEH_Debug_Tools::printr( $_REQUEST, '$_REQUEST', __FILE__, __LINE__ ); |
|
| 842 | - // EEH_Debug_Tools::printr( $valid_data, '$valid_data', __FILE__, __LINE__ ); |
|
| 843 | - // if we don't have any $valid_data then something went TERRIBLY WRONG !!! |
|
| 844 | - if (empty($valid_data)) { |
|
| 845 | - EE_Error::add_error( |
|
| 846 | - esc_html__('No valid question responses were received.', 'event_espresso'), |
|
| 847 | - __FILE__, |
|
| 848 | - __FUNCTION__, |
|
| 849 | - __LINE__ |
|
| 850 | - ); |
|
| 851 | - return false; |
|
| 852 | - } |
|
| 853 | - if (! $this->checkout->transaction instanceof EE_Transaction || ! $this->checkout->continue_reg) { |
|
| 854 | - EE_Error::add_error( |
|
| 855 | - esc_html__( |
|
| 856 | - 'A valid transaction could not be initiated for processing your registrations.', |
|
| 857 | - 'event_espresso' |
|
| 858 | - ), |
|
| 859 | - __FILE__, |
|
| 860 | - __FUNCTION__, |
|
| 861 | - __LINE__ |
|
| 862 | - ); |
|
| 863 | - return false; |
|
| 864 | - } |
|
| 865 | - // get cached registrations |
|
| 866 | - $registrations = $this->checkout->transaction->registrations($this->checkout->reg_cache_where_params); |
|
| 867 | - // verify we got the goods |
|
| 868 | - if (empty($registrations)) { |
|
| 869 | - // combine the old translated string with a new one, in order to not break translations |
|
| 870 | - $error_message = esc_html__( |
|
| 871 | - 'Your form data could not be applied to any valid registrations.', |
|
| 872 | - 'event_espresso' |
|
| 873 | - ) |
|
| 874 | - . sprintf( |
|
| 875 | - esc_html_x( |
|
| 876 | - '%3$sThis can sometimes happen if too much time has been taken to complete the registration process.%3$sPlease return to the %1$sEvent List%2$s and reselect your tickets. If the problem continues, please contact the site administrator.', |
|
| 877 | - '(line break)This can sometimes happen if too much time has been taken to complete the registration process.(line break)Please return to the (link)Event List(end link) and reselect your tickets. If the problem continues, please contact the site administrator.', |
|
| 878 | - 'event_espresso' |
|
| 879 | - ), |
|
| 880 | - '<a href="' . get_post_type_archive_link('espresso_events') . '" >', |
|
| 881 | - '</a>', |
|
| 882 | - '<br />' |
|
| 883 | - ); |
|
| 884 | - EE_Error::add_error( |
|
| 885 | - $error_message, |
|
| 886 | - __FILE__, |
|
| 887 | - __FUNCTION__, |
|
| 888 | - __LINE__ |
|
| 889 | - ); |
|
| 890 | - return false; |
|
| 891 | - } |
|
| 892 | - // extract attendee info from form data and save to model objects |
|
| 893 | - $registrations_processed = $this->_process_registrations($registrations, $valid_data); |
|
| 894 | - // if first pass thru SPCO, |
|
| 895 | - // then let's check processed registrations against the total number of tickets in the cart |
|
| 896 | - if ($registrations_processed === false) { |
|
| 897 | - // but return immediately if the previous step exited early due to errors |
|
| 898 | - return false; |
|
| 899 | - } |
|
| 900 | - if (! $this->checkout->revisit && $registrations_processed !== $this->checkout->total_ticket_count) { |
|
| 901 | - // generate a correctly translated string for all possible singular/plural combinations |
|
| 902 | - if ($this->checkout->total_ticket_count === 1 && $registrations_processed !== 1) { |
|
| 903 | - $error_msg = sprintf( |
|
| 904 | - esc_html_x( |
|
| 905 | - 'There was %1$d ticket in the Event Queue, but %2$ds registrations were processed', |
|
| 906 | - 'There was 1 ticket in the Event Queue, but 2 registrations were processed', |
|
| 907 | - 'event_espresso' |
|
| 908 | - ), |
|
| 909 | - $this->checkout->total_ticket_count, |
|
| 910 | - $registrations_processed |
|
| 911 | - ); |
|
| 912 | - } elseif ($this->checkout->total_ticket_count !== 1 && $registrations_processed === 1) { |
|
| 913 | - $error_msg = sprintf( |
|
| 914 | - esc_html_x( |
|
| 915 | - 'There was a total of %1$d tickets in the Event Queue, but only %2$ds registration was processed', |
|
| 916 | - 'There was a total of 2 tickets in the Event Queue, but only 1 registration was processed', |
|
| 917 | - 'event_espresso' |
|
| 918 | - ), |
|
| 919 | - $this->checkout->total_ticket_count, |
|
| 920 | - $registrations_processed |
|
| 921 | - ); |
|
| 922 | - } else { |
|
| 923 | - $error_msg = sprintf( |
|
| 924 | - esc_html__( |
|
| 925 | - 'There was a total of 2 tickets in the Event Queue, but 2 registrations were processed', |
|
| 926 | - 'event_espresso' |
|
| 927 | - ), |
|
| 928 | - $this->checkout->total_ticket_count, |
|
| 929 | - $registrations_processed |
|
| 930 | - ); |
|
| 931 | - } |
|
| 932 | - EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 933 | - return false; |
|
| 934 | - } |
|
| 935 | - // mark this reg step as completed |
|
| 936 | - $this->set_completed(); |
|
| 937 | - $this->_set_success_message( |
|
| 938 | - esc_html__('The Attendee Information Step has been successfully completed.', 'event_espresso') |
|
| 939 | - ); |
|
| 940 | - // do action in case a plugin wants to do something with the data submitted in step 1. |
|
| 941 | - // passes EE_Single_Page_Checkout, and it's posted data |
|
| 942 | - do_action('AHEE__EE_Single_Page_Checkout__process_attendee_information__end', $this, $valid_data); |
|
| 943 | - return true; |
|
| 944 | - } |
|
| 945 | - |
|
| 946 | - |
|
| 947 | - /** |
|
| 948 | - * _process_registrations |
|
| 949 | - * |
|
| 950 | - * @param EE_Registration[] $registrations |
|
| 951 | - * @param array[][] $valid_data |
|
| 952 | - * @return bool|int |
|
| 953 | - * @throws EntityNotFoundException |
|
| 954 | - * @throws EE_Error |
|
| 955 | - * @throws InvalidArgumentException |
|
| 956 | - * @throws ReflectionException |
|
| 957 | - * @throws RuntimeException |
|
| 958 | - * @throws InvalidDataTypeException |
|
| 959 | - * @throws InvalidInterfaceException |
|
| 960 | - */ |
|
| 961 | - private function _process_registrations($registrations = array(), $valid_data = array()) |
|
| 962 | - { |
|
| 963 | - // load resources and set some defaults |
|
| 964 | - EE_Registry::instance()->load_model('Attendee'); |
|
| 965 | - // holder for primary registrant attendee object |
|
| 966 | - $this->checkout->primary_attendee_obj = null; |
|
| 967 | - // array for tracking reg form data for the primary registrant |
|
| 968 | - $primary_registrant = array( |
|
| 969 | - 'line_item_id' => null, |
|
| 970 | - ); |
|
| 971 | - $copy_primary = false; |
|
| 972 | - // reg form sections that do not contain inputs |
|
| 973 | - $non_input_form_sections = array( |
|
| 974 | - 'primary_registrant', |
|
| 975 | - 'additional_attendee_reg_info', |
|
| 976 | - 'spco_copy_attendee_chk', |
|
| 977 | - ); |
|
| 978 | - // attendee counter |
|
| 979 | - $att_nmbr = 0; |
|
| 980 | - // grab the saved registrations from the transaction |
|
| 981 | - foreach ($registrations as $registration) { |
|
| 982 | - // verify EE_Registration object |
|
| 983 | - if (! $registration instanceof EE_Registration) { |
|
| 984 | - EE_Error::add_error( |
|
| 985 | - esc_html__( |
|
| 986 | - 'An invalid Registration object was discovered when attempting to process your registration information.', |
|
| 987 | - 'event_espresso' |
|
| 988 | - ), |
|
| 989 | - __FILE__, |
|
| 990 | - __FUNCTION__, |
|
| 991 | - __LINE__ |
|
| 992 | - ); |
|
| 993 | - return false; |
|
| 994 | - } |
|
| 995 | - /** @var string $reg_url_link */ |
|
| 996 | - $reg_url_link = $registration->reg_url_link(); |
|
| 997 | - // reg_url_link exists ? |
|
| 998 | - if (! empty($reg_url_link)) { |
|
| 999 | - // should this registration be processed during this visit ? |
|
| 1000 | - if ($this->checkout->visit_allows_processing_of_this_registration($registration)) { |
|
| 1001 | - // if NOT revisiting, then let's save the registration now, |
|
| 1002 | - // so that we have a REG_ID to use when generating other objects |
|
| 1003 | - if (! $this->checkout->revisit) { |
|
| 1004 | - $registration->save(); |
|
| 1005 | - } |
|
| 1006 | - /** |
|
| 1007 | - * This allows plugins to trigger a fail on processing of a |
|
| 1008 | - * registration for any conditions they may have for it to pass. |
|
| 1009 | - * |
|
| 1010 | - * @var bool if true is returned by the plugin then the |
|
| 1011 | - * registration processing is halted. |
|
| 1012 | - */ |
|
| 1013 | - if (apply_filters( |
|
| 1014 | - 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___process_registrations__pre_registration_process', |
|
| 1015 | - false, |
|
| 1016 | - $att_nmbr, |
|
| 1017 | - $registration, |
|
| 1018 | - $registrations, |
|
| 1019 | - $valid_data, |
|
| 1020 | - $this |
|
| 1021 | - )) { |
|
| 1022 | - return false; |
|
| 1023 | - } |
|
| 1024 | - |
|
| 1025 | - // Houston, we have a registration! |
|
| 1026 | - $att_nmbr++; |
|
| 1027 | - $this->_attendee_data[ $reg_url_link ] = array(); |
|
| 1028 | - // grab any existing related answer objects |
|
| 1029 | - $this->_registration_answers = $registration->answers(); |
|
| 1030 | - // unset( $valid_data[ $reg_url_link ]['additional_attendee_reg_info'] ); |
|
| 1031 | - if (isset($valid_data[ $reg_url_link ])) { |
|
| 1032 | - // do we need to copy basic info from primary attendee ? |
|
| 1033 | - $copy_primary = isset($valid_data[ $reg_url_link ]['additional_attendee_reg_info']) |
|
| 1034 | - && absint($valid_data[ $reg_url_link ]['additional_attendee_reg_info']) === 0; |
|
| 1035 | - // filter form input data for this registration |
|
| 1036 | - $valid_data[ $reg_url_link ] = (array) apply_filters( |
|
| 1037 | - 'FHEE__EE_Single_Page_Checkout__process_attendee_information__valid_data_line_item', |
|
| 1038 | - $valid_data[ $reg_url_link ] |
|
| 1039 | - ); |
|
| 1040 | - if (isset($valid_data['primary_attendee'])) { |
|
| 1041 | - $primary_registrant['line_item_id'] = ! empty($valid_data['primary_attendee']) |
|
| 1042 | - ? $valid_data['primary_attendee'] |
|
| 1043 | - : false; |
|
| 1044 | - unset($valid_data['primary_attendee']); |
|
| 1045 | - } |
|
| 1046 | - // now loop through our array of valid post data && process attendee reg forms |
|
| 1047 | - foreach ($valid_data[ $reg_url_link ] as $form_section => $form_inputs) { |
|
| 1048 | - if (! in_array($form_section, $non_input_form_sections, true)) { |
|
| 1049 | - foreach ($form_inputs as $form_input => $input_value) { |
|
| 1050 | - // \EEH_Debug_Tools::printr( $input_value, $form_input, __FILE__, __LINE__ ); |
|
| 1051 | - // check for critical inputs |
|
| 1052 | - if (! $this->_verify_critical_attendee_details_are_set_and_validate_email( |
|
| 1053 | - $form_input, |
|
| 1054 | - $input_value |
|
| 1055 | - ) |
|
| 1056 | - ) { |
|
| 1057 | - return false; |
|
| 1058 | - } |
|
| 1059 | - // store a bit of data about the primary attendee |
|
| 1060 | - if ($att_nmbr === 1 |
|
| 1061 | - && ! empty($input_value) |
|
| 1062 | - && $reg_url_link === $primary_registrant['line_item_id'] |
|
| 1063 | - ) { |
|
| 1064 | - $primary_registrant[ $form_input ] = $input_value; |
|
| 1065 | - } elseif ($copy_primary |
|
| 1066 | - && $input_value === null |
|
| 1067 | - && isset($primary_registrant[ $form_input ]) |
|
| 1068 | - ) { |
|
| 1069 | - $input_value = $primary_registrant[ $form_input ]; |
|
| 1070 | - } |
|
| 1071 | - // now attempt to save the input data |
|
| 1072 | - if (! $this->_save_registration_form_input( |
|
| 1073 | - $registration, |
|
| 1074 | - $form_input, |
|
| 1075 | - $input_value |
|
| 1076 | - ) |
|
| 1077 | - ) { |
|
| 1078 | - EE_Error::add_error( |
|
| 1079 | - sprintf( |
|
| 1080 | - esc_html_x( |
|
| 1081 | - 'Unable to save registration form data for the form input: "%1$s" with the submitted value: "%2$s"', |
|
| 1082 | - 'Unable to save registration form data for the form input: "form input name" with the submitted value: "form input value"', |
|
| 1083 | - 'event_espresso' |
|
| 1084 | - ), |
|
| 1085 | - $form_input, |
|
| 1086 | - $input_value |
|
| 1087 | - ), |
|
| 1088 | - __FILE__, |
|
| 1089 | - __FUNCTION__, |
|
| 1090 | - __LINE__ |
|
| 1091 | - ); |
|
| 1092 | - return false; |
|
| 1093 | - } |
|
| 1094 | - } |
|
| 1095 | - } |
|
| 1096 | - } // end of foreach ( $valid_data[ $reg_url_link ] as $form_section => $form_inputs ) |
|
| 1097 | - } |
|
| 1098 | - // EEH_Debug_Tools::printr( $this->_attendee_data, '$this->_attendee_data', __FILE__, __LINE__ ); |
|
| 1099 | - // this registration does not require additional attendee information ? |
|
| 1100 | - if ($copy_primary |
|
| 1101 | - && $att_nmbr > 1 |
|
| 1102 | - && $this->checkout->primary_attendee_obj instanceof EE_Attendee |
|
| 1103 | - ) { |
|
| 1104 | - // just copy the primary registrant |
|
| 1105 | - $attendee = $this->checkout->primary_attendee_obj; |
|
| 1106 | - } else { |
|
| 1107 | - // ensure critical details are set for additional attendees |
|
| 1108 | - $this->_attendee_data[ $reg_url_link ] = $att_nmbr > 1 |
|
| 1109 | - ? $this->_copy_critical_attendee_details_from_primary_registrant( |
|
| 1110 | - $this->_attendee_data[ $reg_url_link ] |
|
| 1111 | - ) |
|
| 1112 | - : $this->_attendee_data[ $reg_url_link ]; |
|
| 1113 | - // execute create attendee command (which may return an existing attendee) |
|
| 1114 | - $attendee = EE_Registry::instance()->BUS->execute( |
|
| 1115 | - new CreateAttendeeCommand( |
|
| 1116 | - $this->_attendee_data[ $reg_url_link ], |
|
| 1117 | - $registration |
|
| 1118 | - ) |
|
| 1119 | - ); |
|
| 1120 | - // who's #1 ? |
|
| 1121 | - if ($att_nmbr === 1) { |
|
| 1122 | - $this->checkout->primary_attendee_obj = $attendee; |
|
| 1123 | - } |
|
| 1124 | - } |
|
| 1125 | - // EEH_Debug_Tools::printr( $attendee, '$attendee', __FILE__, __LINE__ ); |
|
| 1126 | - // add relation to registration, set attendee ID, and cache attendee |
|
| 1127 | - $this->_associate_attendee_with_registration($registration, $attendee); |
|
| 1128 | - // \EEH_Debug_Tools::printr( $registration, '$registration', __FILE__, __LINE__ ); |
|
| 1129 | - if (! $registration->attendee() instanceof EE_Attendee) { |
|
| 1130 | - EE_Error::add_error( |
|
| 1131 | - sprintf( |
|
| 1132 | - esc_html_x( |
|
| 1133 | - 'Registration %s has an invalid or missing Attendee object.', |
|
| 1134 | - 'Registration 123-456-789 has an invalid or missing Attendee object.', |
|
| 1135 | - 'event_espresso' |
|
| 1136 | - ), |
|
| 1137 | - $reg_url_link |
|
| 1138 | - ), |
|
| 1139 | - __FILE__, |
|
| 1140 | - __FUNCTION__, |
|
| 1141 | - __LINE__ |
|
| 1142 | - ); |
|
| 1143 | - return false; |
|
| 1144 | - } |
|
| 1145 | - /** @type EE_Registration_Processor $registration_processor */ |
|
| 1146 | - $registration_processor = EE_Registry::instance()->load_class('Registration_Processor'); |
|
| 1147 | - // at this point, we should have enough details about the registrant to consider the registration |
|
| 1148 | - // NOT incomplete |
|
| 1149 | - $registration_processor->toggle_incomplete_registration_status_to_default( |
|
| 1150 | - $registration, |
|
| 1151 | - false, |
|
| 1152 | - new Context( |
|
| 1153 | - 'spco_reg_step_attendee_information_process_registrations', |
|
| 1154 | - esc_html__( |
|
| 1155 | - 'Finished populating registration with details from the registration form after submitting the Attendee Information Reg Step.', |
|
| 1156 | - 'event_espresso' |
|
| 1157 | - ) |
|
| 1158 | - ) |
|
| 1159 | - ); |
|
| 1160 | - // we can also consider the TXN to not have been failed, so temporarily upgrade it's status to |
|
| 1161 | - // abandoned |
|
| 1162 | - $this->checkout->transaction->toggle_failed_transaction_status(); |
|
| 1163 | - // if we've gotten this far, then let's save what we have |
|
| 1164 | - $registration->save(); |
|
| 1165 | - // add relation between TXN and registration |
|
| 1166 | - $this->_associate_registration_with_transaction($registration); |
|
| 1167 | - } |
|
| 1168 | - } else { |
|
| 1169 | - EE_Error::add_error( |
|
| 1170 | - esc_html__( |
|
| 1171 | - 'An invalid or missing line item ID was encountered while attempting to process the registration form.', |
|
| 1172 | - 'event_espresso' |
|
| 1173 | - ), |
|
| 1174 | - __FILE__, |
|
| 1175 | - __FUNCTION__, |
|
| 1176 | - __LINE__ |
|
| 1177 | - ); |
|
| 1178 | - // remove malformed data |
|
| 1179 | - unset($valid_data[ $reg_url_link ]); |
|
| 1180 | - return false; |
|
| 1181 | - } |
|
| 1182 | - } // end of foreach ( $this->checkout->transaction->registrations() as $registration ) |
|
| 1183 | - return $att_nmbr; |
|
| 1184 | - } |
|
| 1185 | - |
|
| 1186 | - |
|
| 1187 | - /** |
|
| 1188 | - * _save_registration_form_input |
|
| 1189 | - * |
|
| 1190 | - * @param EE_Registration $registration |
|
| 1191 | - * @param string $form_input |
|
| 1192 | - * @param string $input_value |
|
| 1193 | - * @return bool |
|
| 1194 | - * @throws EE_Error |
|
| 1195 | - * @throws InvalidArgumentException |
|
| 1196 | - * @throws InvalidDataTypeException |
|
| 1197 | - * @throws InvalidInterfaceException |
|
| 1198 | - * @throws ReflectionException |
|
| 1199 | - */ |
|
| 1200 | - private function _save_registration_form_input( |
|
| 1201 | - EE_Registration $registration, |
|
| 1202 | - $form_input = '', |
|
| 1203 | - $input_value = '' |
|
| 1204 | - ) { |
|
| 1205 | - // \EEH_Debug_Tools::printr( __FUNCTION__, __CLASS__, __FILE__, __LINE__, 2 ); |
|
| 1206 | - // \EEH_Debug_Tools::printr( $form_input, '$form_input', __FILE__, __LINE__ ); |
|
| 1207 | - // \EEH_Debug_Tools::printr( $input_value, '$input_value', __FILE__, __LINE__ ); |
|
| 1208 | - // allow for plugins to hook in and do their own processing of the form input. |
|
| 1209 | - // For plugins to bypass normal processing here, they just need to return a boolean value. |
|
| 1210 | - if (apply_filters( |
|
| 1211 | - 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___save_registration_form_input', |
|
| 1212 | - false, |
|
| 1213 | - $registration, |
|
| 1214 | - $form_input, |
|
| 1215 | - $input_value, |
|
| 1216 | - $this |
|
| 1217 | - )) { |
|
| 1218 | - return true; |
|
| 1219 | - } |
|
| 1220 | - /* |
|
| 21 | + /** |
|
| 22 | + * @type bool $_print_copy_info |
|
| 23 | + */ |
|
| 24 | + private $_print_copy_info = false; |
|
| 25 | + |
|
| 26 | + /** |
|
| 27 | + * @type array $_attendee_data |
|
| 28 | + */ |
|
| 29 | + private $_attendee_data = array(); |
|
| 30 | + |
|
| 31 | + /** |
|
| 32 | + * @type array $_required_questions |
|
| 33 | + */ |
|
| 34 | + private $_required_questions = array(); |
|
| 35 | + |
|
| 36 | + /** |
|
| 37 | + * @type array $_registration_answers |
|
| 38 | + */ |
|
| 39 | + private $_registration_answers = array(); |
|
| 40 | + |
|
| 41 | + |
|
| 42 | + /** |
|
| 43 | + * class constructor |
|
| 44 | + * |
|
| 45 | + * @access public |
|
| 46 | + * @param EE_Checkout $checkout |
|
| 47 | + */ |
|
| 48 | + public function __construct(EE_Checkout $checkout) |
|
| 49 | + { |
|
| 50 | + $this->_slug = 'attendee_information'; |
|
| 51 | + $this->_name = esc_html__('Attendee Information', 'event_espresso'); |
|
| 52 | + $this->_template = SPCO_REG_STEPS_PATH . $this->_slug . '/attendee_info_main.template.php'; |
|
| 53 | + $this->checkout = $checkout; |
|
| 54 | + $this->_reset_success_message(); |
|
| 55 | + $this->set_instructions( |
|
| 56 | + esc_html__('Please answer the following registration questions before proceeding.', 'event_espresso') |
|
| 57 | + ); |
|
| 58 | + } |
|
| 59 | + |
|
| 60 | + |
|
| 61 | + public function translate_js_strings() |
|
| 62 | + { |
|
| 63 | + EE_Registry::$i18n_js_strings['required_field'] = esc_html__( |
|
| 64 | + ' is a required question.', |
|
| 65 | + 'event_espresso' |
|
| 66 | + ); |
|
| 67 | + EE_Registry::$i18n_js_strings['required_multi_field'] = esc_html__( |
|
| 68 | + ' is a required question. Please enter a value for at least one of the options.', |
|
| 69 | + 'event_espresso' |
|
| 70 | + ); |
|
| 71 | + EE_Registry::$i18n_js_strings['answer_required_questions'] = esc_html__( |
|
| 72 | + 'Please answer all required questions correctly before proceeding.', |
|
| 73 | + 'event_espresso' |
|
| 74 | + ); |
|
| 75 | + EE_Registry::$i18n_js_strings['attendee_info_copied'] = sprintf( |
|
| 76 | + esc_html_x( |
|
| 77 | + 'The attendee information was successfully copied.%sPlease ensure the rest of the registration form is completed before proceeding.', |
|
| 78 | + 'The attendee information was successfully copied.(line break)Please ensure the rest of the registration form is completed before proceeding.', |
|
| 79 | + 'event_espresso' |
|
| 80 | + ), |
|
| 81 | + '<br/>' |
|
| 82 | + ); |
|
| 83 | + EE_Registry::$i18n_js_strings['attendee_info_copy_error'] = esc_html__( |
|
| 84 | + 'An unknown error occurred on the server while attempting to copy the attendee information. Please refresh the page and try again.', |
|
| 85 | + 'event_espresso' |
|
| 86 | + ); |
|
| 87 | + EE_Registry::$i18n_js_strings['enter_valid_email'] = esc_html__( |
|
| 88 | + 'You must enter a valid email address.', |
|
| 89 | + 'event_espresso' |
|
| 90 | + ); |
|
| 91 | + EE_Registry::$i18n_js_strings['valid_email_and_questions'] = esc_html__( |
|
| 92 | + 'You must enter a valid email address and answer all other required questions before you can proceed.', |
|
| 93 | + 'event_espresso' |
|
| 94 | + ); |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + |
|
| 98 | + public function enqueue_styles_and_scripts() |
|
| 99 | + { |
|
| 100 | + } |
|
| 101 | + |
|
| 102 | + |
|
| 103 | + /** |
|
| 104 | + * @return boolean |
|
| 105 | + */ |
|
| 106 | + public function initialize_reg_step() |
|
| 107 | + { |
|
| 108 | + return true; |
|
| 109 | + } |
|
| 110 | + |
|
| 111 | + |
|
| 112 | + /** |
|
| 113 | + * @return EE_Form_Section_Proper |
|
| 114 | + * @throws DomainException |
|
| 115 | + * @throws EE_Error |
|
| 116 | + * @throws InvalidArgumentException |
|
| 117 | + * @throws ReflectionException |
|
| 118 | + * @throws EntityNotFoundException |
|
| 119 | + * @throws InvalidDataTypeException |
|
| 120 | + * @throws InvalidInterfaceException |
|
| 121 | + */ |
|
| 122 | + public function generate_reg_form() |
|
| 123 | + { |
|
| 124 | + $this->_print_copy_info = false; |
|
| 125 | + $primary_registrant = null; |
|
| 126 | + // autoload Line_Item_Display classes |
|
| 127 | + EEH_Autoloader::register_line_item_display_autoloaders(); |
|
| 128 | + $Line_Item_Display = new EE_Line_Item_Display(); |
|
| 129 | + // calculate taxes |
|
| 130 | + $Line_Item_Display->display_line_item( |
|
| 131 | + $this->checkout->cart->get_grand_total(), |
|
| 132 | + array('set_tax_rate' => true) |
|
| 133 | + ); |
|
| 134 | + /** @var $subsections EE_Form_Section_Proper[] */ |
|
| 135 | + $extra_inputs_section = $this->reg_step_hidden_inputs(); |
|
| 136 | + $subsections = array( |
|
| 137 | + 'default_hidden_inputs' => $extra_inputs_section, |
|
| 138 | + ); |
|
| 139 | + |
|
| 140 | + /** |
|
| 141 | + * @var $reg_config EE_Registration_Config |
|
| 142 | + */ |
|
| 143 | + $reg_config = LoaderFactory::getLoader()->getShared('EE_Registration_Config'); |
|
| 144 | + // if this isn't a revisit, and they have the privacy consent box enalbed, add it |
|
| 145 | + if (! $this->checkout->revisit && $reg_config->isConsentCheckboxEnabled()) { |
|
| 146 | + $extra_inputs_section->add_subsections( |
|
| 147 | + array( |
|
| 148 | + 'consent_box' => new EE_Form_Section_Proper( |
|
| 149 | + array( |
|
| 150 | + 'layout_strategy' => |
|
| 151 | + new EE_Template_Layout( |
|
| 152 | + array( |
|
| 153 | + 'input_template_file' => SPCO_REG_STEPS_PATH . $this->_slug . '/privacy_consent.template.php', |
|
| 154 | + ) |
|
| 155 | + ), |
|
| 156 | + 'subsections' => array( |
|
| 157 | + 'consent' => new EE_Checkbox_Multi_Input( |
|
| 158 | + array( |
|
| 159 | + 'consent' => $reg_config->getConsentCheckboxLabelText(), |
|
| 160 | + ), |
|
| 161 | + array( |
|
| 162 | + 'required' => true, |
|
| 163 | + 'required_validation_error_message' => esc_html__( |
|
| 164 | + 'You must consent to these terms in order to register.', |
|
| 165 | + 'event_espresso' |
|
| 166 | + ), |
|
| 167 | + 'html_label_text' => '', |
|
| 168 | + ) |
|
| 169 | + ), |
|
| 170 | + ), |
|
| 171 | + ) |
|
| 172 | + ), |
|
| 173 | + ), |
|
| 174 | + null, |
|
| 175 | + false |
|
| 176 | + ); |
|
| 177 | + } |
|
| 178 | + $template_args = array( |
|
| 179 | + 'revisit' => $this->checkout->revisit, |
|
| 180 | + 'registrations' => array(), |
|
| 181 | + 'ticket_count' => array(), |
|
| 182 | + ); |
|
| 183 | + // grab the saved registrations from the transaction |
|
| 184 | + $registrations = $this->checkout->transaction->registrations($this->checkout->reg_cache_where_params); |
|
| 185 | + if ($registrations) { |
|
| 186 | + foreach ($registrations as $registration) { |
|
| 187 | + // can this registration be processed during this visit ? |
|
| 188 | + if ($registration instanceof EE_Registration |
|
| 189 | + && $this->checkout->visit_allows_processing_of_this_registration($registration) |
|
| 190 | + ) { |
|
| 191 | + $subsections[ $registration->reg_url_link() ] = $this->_registrations_reg_form($registration); |
|
| 192 | + if (! $this->checkout->admin_request) { |
|
| 193 | + $template_args['registrations'][ $registration->reg_url_link() ] = $registration; |
|
| 194 | + $template_args['ticket_count'][ $registration->ticket()->ID() ] = isset( |
|
| 195 | + $template_args['ticket_count'][ $registration->ticket()->ID() ] |
|
| 196 | + ) |
|
| 197 | + ? $template_args['ticket_count'][ $registration->ticket()->ID() ] + 1 |
|
| 198 | + : 1; |
|
| 199 | + $ticket_line_item = EEH_Line_Item::get_line_items_by_object_type_and_IDs( |
|
| 200 | + $this->checkout->cart->get_grand_total(), |
|
| 201 | + 'Ticket', |
|
| 202 | + array($registration->ticket()->ID()) |
|
| 203 | + ); |
|
| 204 | + $ticket_line_item = is_array($ticket_line_item) |
|
| 205 | + ? reset($ticket_line_item) |
|
| 206 | + : $ticket_line_item; |
|
| 207 | + $template_args['ticket_line_item'][ $registration->ticket()->ID() ] = |
|
| 208 | + $Line_Item_Display->display_line_item($ticket_line_item); |
|
| 209 | + } |
|
| 210 | + if ($registration->is_primary_registrant()) { |
|
| 211 | + $primary_registrant = $registration->reg_url_link(); |
|
| 212 | + } |
|
| 213 | + } |
|
| 214 | + } |
|
| 215 | + // print_copy_info ? |
|
| 216 | + if ($primary_registrant && ! $this->checkout->admin_request && count($registrations) > 1) { |
|
| 217 | + // TODO: add admin option for toggling copy attendee info, |
|
| 218 | + // then use that value to change $this->_print_copy_info |
|
| 219 | + $copy_options['spco_copy_attendee_chk'] = $this->_print_copy_info |
|
| 220 | + ? $this->_copy_attendee_info_form() |
|
| 221 | + : $this->_auto_copy_attendee_info(); |
|
| 222 | + // generate hidden input |
|
| 223 | + if (isset($subsections[ $primary_registrant ]) |
|
| 224 | + && $subsections[ $primary_registrant ] instanceof EE_Form_Section_Proper |
|
| 225 | + ) { |
|
| 226 | + $subsections[ $primary_registrant ]->add_subsections( |
|
| 227 | + $copy_options, |
|
| 228 | + 'primary_registrant', |
|
| 229 | + false |
|
| 230 | + ); |
|
| 231 | + } |
|
| 232 | + } |
|
| 233 | + } |
|
| 234 | + return new EE_Form_Section_Proper( |
|
| 235 | + array( |
|
| 236 | + 'name' => $this->reg_form_name(), |
|
| 237 | + 'html_id' => $this->reg_form_name(), |
|
| 238 | + 'subsections' => $subsections, |
|
| 239 | + 'layout_strategy' => $this->checkout->admin_request |
|
| 240 | + ? |
|
| 241 | + new EE_Div_Per_Section_Layout() |
|
| 242 | + : |
|
| 243 | + new EE_Template_Layout( |
|
| 244 | + array( |
|
| 245 | + 'layout_template_file' => $this->_template, // layout_template |
|
| 246 | + 'template_args' => $template_args, |
|
| 247 | + ) |
|
| 248 | + ), |
|
| 249 | + ) |
|
| 250 | + ); |
|
| 251 | + } |
|
| 252 | + |
|
| 253 | + |
|
| 254 | + /** |
|
| 255 | + * @param EE_Registration $registration |
|
| 256 | + * @return EE_Form_Section_Base |
|
| 257 | + * @throws EE_Error |
|
| 258 | + * @throws InvalidArgumentException |
|
| 259 | + * @throws EntityNotFoundException |
|
| 260 | + * @throws InvalidDataTypeException |
|
| 261 | + * @throws InvalidInterfaceException |
|
| 262 | + * @throws ReflectionException |
|
| 263 | + */ |
|
| 264 | + private function _registrations_reg_form(EE_Registration $registration) |
|
| 265 | + { |
|
| 266 | + static $attendee_nmbr = 1; |
|
| 267 | + $form_args = array(); |
|
| 268 | + // verify that registration has valid event |
|
| 269 | + if ($registration->event() instanceof EE_Event) { |
|
| 270 | + $field_name = 'Event_Question_Group.' |
|
| 271 | + . EEM_Event_Question_Group::instance()->fieldNameForContext( |
|
| 272 | + $registration->is_primary_registrant() |
|
| 273 | + ); |
|
| 274 | + $question_groups = $registration->event()->question_groups( |
|
| 275 | + apply_filters( |
|
| 276 | + // @codingStandardsIgnoreStart |
|
| 277 | + 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___registrations_reg_form__question_groups_query_parameters', |
|
| 278 | + // @codingStandardsIgnoreEnd |
|
| 279 | + [ |
|
| 280 | + [ |
|
| 281 | + 'Event.EVT_ID' => $registration->event()->ID(), |
|
| 282 | + $field_name => true, |
|
| 283 | + ], |
|
| 284 | + 'order_by' => ['QSG_order' => 'ASC'], |
|
| 285 | + ], |
|
| 286 | + $registration, |
|
| 287 | + $this |
|
| 288 | + ) |
|
| 289 | + ); |
|
| 290 | + if ($question_groups) { |
|
| 291 | + // array of params to pass to parent constructor |
|
| 292 | + $form_args = array( |
|
| 293 | + 'html_id' => 'ee-registration-' . $registration->reg_url_link(), |
|
| 294 | + 'html_class' => 'ee-reg-form-attendee-dv', |
|
| 295 | + 'html_style' => $this->checkout->admin_request |
|
| 296 | + ? 'padding:0em 2em 1em; margin:3em 0 0; border:1px solid #ddd;' |
|
| 297 | + : '', |
|
| 298 | + 'subsections' => array(), |
|
| 299 | + 'layout_strategy' => new EE_Fieldset_Section_Layout( |
|
| 300 | + array( |
|
| 301 | + 'legend_class' => 'spco-attendee-lgnd smaller-text lt-grey-text', |
|
| 302 | + 'legend_text' => sprintf( |
|
| 303 | + esc_html_x( |
|
| 304 | + 'Attendee %d', |
|
| 305 | + 'Attendee 123', |
|
| 306 | + 'event_espresso' |
|
| 307 | + ), |
|
| 308 | + $attendee_nmbr |
|
| 309 | + ), |
|
| 310 | + ) |
|
| 311 | + ), |
|
| 312 | + ); |
|
| 313 | + foreach ($question_groups as $question_group) { |
|
| 314 | + if ($question_group instanceof EE_Question_Group) { |
|
| 315 | + $form_args['subsections'][ $question_group->identifier() ] = $this->_question_group_reg_form( |
|
| 316 | + $registration, |
|
| 317 | + $question_group |
|
| 318 | + ); |
|
| 319 | + } |
|
| 320 | + } |
|
| 321 | + // add hidden input |
|
| 322 | + $form_args['subsections']['additional_attendee_reg_info'] = $this->_additional_attendee_reg_info_input( |
|
| 323 | + $registration |
|
| 324 | + ); |
|
| 325 | + // if we have question groups for additional attendees, then display the copy options |
|
| 326 | + $this->_print_copy_info = $attendee_nmbr > 1 ? true : $this->_print_copy_info; |
|
| 327 | + if ($registration->is_primary_registrant()) { |
|
| 328 | + // generate hidden input |
|
| 329 | + $form_args['subsections']['primary_registrant'] = $this->_additional_primary_registrant_inputs( |
|
| 330 | + $registration |
|
| 331 | + ); |
|
| 332 | + } |
|
| 333 | + } |
|
| 334 | + } |
|
| 335 | + $attendee_nmbr++; |
|
| 336 | + return ! empty($form_args) |
|
| 337 | + ? new EE_Form_Section_Proper($form_args) |
|
| 338 | + : new EE_Form_Section_HTML(); |
|
| 339 | + } |
|
| 340 | + |
|
| 341 | + |
|
| 342 | + /** |
|
| 343 | + * @param EE_Registration $registration |
|
| 344 | + * @param bool $additional_attendee_reg_info |
|
| 345 | + * @return EE_Form_Input_Base |
|
| 346 | + * @throws EE_Error |
|
| 347 | + */ |
|
| 348 | + private function _additional_attendee_reg_info_input( |
|
| 349 | + EE_Registration $registration, |
|
| 350 | + $additional_attendee_reg_info = true |
|
| 351 | + ) { |
|
| 352 | + // generate hidden input |
|
| 353 | + return new EE_Hidden_Input( |
|
| 354 | + array( |
|
| 355 | + 'html_id' => 'additional-attendee-reg-info-' . $registration->reg_url_link(), |
|
| 356 | + 'default' => $additional_attendee_reg_info, |
|
| 357 | + ) |
|
| 358 | + ); |
|
| 359 | + } |
|
| 360 | + |
|
| 361 | + |
|
| 362 | + /** |
|
| 363 | + * @param EE_Registration $registration |
|
| 364 | + * @param EE_Question_Group $question_group |
|
| 365 | + * @return EE_Form_Section_Proper |
|
| 366 | + * @throws EE_Error |
|
| 367 | + * @throws InvalidArgumentException |
|
| 368 | + * @throws InvalidDataTypeException |
|
| 369 | + * @throws InvalidInterfaceException |
|
| 370 | + * @throws ReflectionException |
|
| 371 | + */ |
|
| 372 | + private function _question_group_reg_form(EE_Registration $registration, EE_Question_Group $question_group) |
|
| 373 | + { |
|
| 374 | + // array of params to pass to parent constructor |
|
| 375 | + $form_args = array( |
|
| 376 | + 'html_id' => 'ee-reg-form-qstn-grp-' . $question_group->identifier() . '-' . $registration->ID(), |
|
| 377 | + 'html_class' => $this->checkout->admin_request |
|
| 378 | + ? 'form-table ee-reg-form-qstn-grp-dv' |
|
| 379 | + : 'ee-reg-form-qstn-grp-dv', |
|
| 380 | + 'html_label_id' => 'ee-reg-form-qstn-grp-' . $question_group->identifier() . '-' |
|
| 381 | + . $registration->ID() . '-lbl', |
|
| 382 | + 'subsections' => array( |
|
| 383 | + 'reg_form_qstn_grp_hdr' => $this->_question_group_header($question_group), |
|
| 384 | + ), |
|
| 385 | + 'layout_strategy' => $this->checkout->admin_request |
|
| 386 | + ? new EE_Admin_Two_Column_Layout() |
|
| 387 | + : new EE_Div_Per_Section_Layout(), |
|
| 388 | + ); |
|
| 389 | + // where params |
|
| 390 | + $query_params = array('QST_deleted' => 0); |
|
| 391 | + // don't load admin only questions on the frontend |
|
| 392 | + if (! $this->checkout->admin_request) { |
|
| 393 | + $query_params['QST_admin_only'] = array('!=', true); |
|
| 394 | + } |
|
| 395 | + $questions = $question_group->get_many_related( |
|
| 396 | + 'Question', |
|
| 397 | + apply_filters( |
|
| 398 | + 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___question_group_reg_form__related_questions_query_params', |
|
| 399 | + array( |
|
| 400 | + $query_params, |
|
| 401 | + 'order_by' => array( |
|
| 402 | + 'Question_Group_Question.QGQ_order' => 'ASC', |
|
| 403 | + ), |
|
| 404 | + ), |
|
| 405 | + $question_group, |
|
| 406 | + $registration, |
|
| 407 | + $this |
|
| 408 | + ) |
|
| 409 | + ); |
|
| 410 | + // filter for additional content before questions |
|
| 411 | + $form_args['subsections']['reg_form_questions_before'] = new EE_Form_Section_HTML( |
|
| 412 | + apply_filters( |
|
| 413 | + 'FHEE__EEH_Form_Fields__generate_question_groups_html__before_question_group_questions', |
|
| 414 | + '', |
|
| 415 | + $registration, |
|
| 416 | + $question_group, |
|
| 417 | + $this |
|
| 418 | + ) |
|
| 419 | + ); |
|
| 420 | + // loop thru questions |
|
| 421 | + foreach ($questions as $question) { |
|
| 422 | + if ($question instanceof EE_Question) { |
|
| 423 | + $identifier = $question->is_system_question() |
|
| 424 | + ? $question->system_ID() |
|
| 425 | + : $question->ID(); |
|
| 426 | + $form_args['subsections'][ $identifier ] = $this->reg_form_question($registration, $question); |
|
| 427 | + } |
|
| 428 | + } |
|
| 429 | + $form_args['subsections'] = apply_filters( |
|
| 430 | + 'FHEE__EE_SPCO_Reg_Step_Attendee_Information__question_group_reg_form__subsections_array', |
|
| 431 | + $form_args['subsections'], |
|
| 432 | + $registration, |
|
| 433 | + $question_group, |
|
| 434 | + $this |
|
| 435 | + ); |
|
| 436 | + // filter for additional content after questions |
|
| 437 | + $form_args['subsections']['reg_form_questions_after'] = new EE_Form_Section_HTML( |
|
| 438 | + apply_filters( |
|
| 439 | + 'FHEE__EEH_Form_Fields__generate_question_groups_html__after_question_group_questions', |
|
| 440 | + '', |
|
| 441 | + $registration, |
|
| 442 | + $question_group, |
|
| 443 | + $this |
|
| 444 | + ) |
|
| 445 | + ); |
|
| 446 | + // d($form_args); |
|
| 447 | + $question_group_reg_form = new EE_Form_Section_Proper($form_args); |
|
| 448 | + return apply_filters( |
|
| 449 | + 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___question_group_reg_form__question_group_reg_form', |
|
| 450 | + $question_group_reg_form, |
|
| 451 | + $registration, |
|
| 452 | + $question_group, |
|
| 453 | + $this |
|
| 454 | + ); |
|
| 455 | + } |
|
| 456 | + |
|
| 457 | + |
|
| 458 | + /** |
|
| 459 | + * @param EE_Question_Group $question_group |
|
| 460 | + * @return EE_Form_Section_HTML |
|
| 461 | + */ |
|
| 462 | + private function _question_group_header(EE_Question_Group $question_group) |
|
| 463 | + { |
|
| 464 | + $html = ''; |
|
| 465 | + // group_name |
|
| 466 | + if ($question_group->show_group_name() && $question_group->name() !== '') { |
|
| 467 | + if ($this->checkout->admin_request) { |
|
| 468 | + $html .= EEH_HTML::br(); |
|
| 469 | + $html .= EEH_HTML::h3( |
|
| 470 | + $question_group->name(), |
|
| 471 | + '', |
|
| 472 | + 'ee-reg-form-qstn-grp-title title', |
|
| 473 | + 'font-size: 1.3em; padding-left:0;' |
|
| 474 | + ); |
|
| 475 | + } else { |
|
| 476 | + $html .= EEH_HTML::h4( |
|
| 477 | + $question_group->name(), |
|
| 478 | + '', |
|
| 479 | + 'ee-reg-form-qstn-grp-title section-title' |
|
| 480 | + ); |
|
| 481 | + } |
|
| 482 | + } |
|
| 483 | + // group_desc |
|
| 484 | + if ($question_group->show_group_desc() && $question_group->desc() !== '') { |
|
| 485 | + $html .= EEH_HTML::p( |
|
| 486 | + $question_group->desc(), |
|
| 487 | + '', |
|
| 488 | + $this->checkout->admin_request |
|
| 489 | + ? 'ee-reg-form-qstn-grp-desc-pg' |
|
| 490 | + : 'ee-reg-form-qstn-grp-desc-pg small-text lt-grey-text' |
|
| 491 | + ); |
|
| 492 | + } |
|
| 493 | + return new EE_Form_Section_HTML($html); |
|
| 494 | + } |
|
| 495 | + |
|
| 496 | + |
|
| 497 | + /** |
|
| 498 | + * @return EE_Form_Section_Proper |
|
| 499 | + * @throws EE_Error |
|
| 500 | + * @throws InvalidArgumentException |
|
| 501 | + * @throws ReflectionException |
|
| 502 | + * @throws InvalidDataTypeException |
|
| 503 | + * @throws InvalidInterfaceException |
|
| 504 | + */ |
|
| 505 | + private function _copy_attendee_info_form() |
|
| 506 | + { |
|
| 507 | + // array of params to pass to parent constructor |
|
| 508 | + return new EE_Form_Section_Proper( |
|
| 509 | + array( |
|
| 510 | + 'subsections' => $this->_copy_attendee_info_inputs(), |
|
| 511 | + 'layout_strategy' => new EE_Template_Layout( |
|
| 512 | + array( |
|
| 513 | + 'layout_template_file' => SPCO_REG_STEPS_PATH |
|
| 514 | + . $this->_slug |
|
| 515 | + . '/copy_attendee_info.template.php', |
|
| 516 | + 'begin_template_file' => null, |
|
| 517 | + 'input_template_file' => null, |
|
| 518 | + 'subsection_template_file' => null, |
|
| 519 | + 'end_template_file' => null, |
|
| 520 | + ) |
|
| 521 | + ), |
|
| 522 | + ) |
|
| 523 | + ); |
|
| 524 | + } |
|
| 525 | + |
|
| 526 | + |
|
| 527 | + /** |
|
| 528 | + * @return EE_Form_Section_HTML |
|
| 529 | + * @throws DomainException |
|
| 530 | + * @throws InvalidArgumentException |
|
| 531 | + * @throws InvalidDataTypeException |
|
| 532 | + * @throws InvalidInterfaceException |
|
| 533 | + */ |
|
| 534 | + private function _auto_copy_attendee_info() |
|
| 535 | + { |
|
| 536 | + return new EE_Form_Section_HTML( |
|
| 537 | + EEH_Template::locate_template( |
|
| 538 | + SPCO_REG_STEPS_PATH . $this->_slug . '/_auto_copy_attendee_info.template.php', |
|
| 539 | + apply_filters( |
|
| 540 | + 'FHEE__EE_SPCO_Reg_Step_Attendee_Information__auto_copy_attendee_info__template_args', |
|
| 541 | + array() |
|
| 542 | + ), |
|
| 543 | + true, |
|
| 544 | + true |
|
| 545 | + ) |
|
| 546 | + ); |
|
| 547 | + } |
|
| 548 | + |
|
| 549 | + |
|
| 550 | + /** |
|
| 551 | + * @return array |
|
| 552 | + * @throws EE_Error |
|
| 553 | + * @throws InvalidArgumentException |
|
| 554 | + * @throws ReflectionException |
|
| 555 | + * @throws InvalidDataTypeException |
|
| 556 | + * @throws InvalidInterfaceException |
|
| 557 | + */ |
|
| 558 | + private function _copy_attendee_info_inputs() |
|
| 559 | + { |
|
| 560 | + $copy_attendee_info_inputs = array(); |
|
| 561 | + $prev_ticket = null; |
|
| 562 | + // grab the saved registrations from the transaction |
|
| 563 | + $registrations = $this->checkout->transaction->registrations($this->checkout->reg_cache_where_params); |
|
| 564 | + foreach ($registrations as $registration) { |
|
| 565 | + // for all attendees other than the primary attendee |
|
| 566 | + if ($registration instanceof EE_Registration && ! $registration->is_primary_registrant()) { |
|
| 567 | + // if this is a new ticket OR if this is the very first additional attendee after the primary attendee |
|
| 568 | + if ($registration->ticket()->ID() !== $prev_ticket) { |
|
| 569 | + $item_name = $registration->ticket()->name(); |
|
| 570 | + $item_name .= $registration->ticket()->description() !== '' |
|
| 571 | + ? ' - ' . $registration->ticket()->description() |
|
| 572 | + : ''; |
|
| 573 | + $copy_attendee_info_inputs[ 'spco_copy_attendee_chk[ticket-' . $registration->ticket()->ID( |
|
| 574 | + ) . ']' ] = |
|
| 575 | + new EE_Form_Section_HTML( |
|
| 576 | + '<h6 class="spco-copy-attendee-event-hdr">' . $item_name . '</h6>' |
|
| 577 | + ); |
|
| 578 | + $prev_ticket = $registration->ticket()->ID(); |
|
| 579 | + } |
|
| 580 | + |
|
| 581 | + $copy_attendee_info_inputs[ 'spco_copy_attendee_chk[' . $registration->ID() . ']' ] = |
|
| 582 | + new EE_Checkbox_Multi_Input( |
|
| 583 | + array( |
|
| 584 | + $registration->ID() => sprintf( |
|
| 585 | + esc_html_x('Attendee #%s', 'Attendee #123', 'event_espresso'), |
|
| 586 | + $registration->count() |
|
| 587 | + ), |
|
| 588 | + ), |
|
| 589 | + array( |
|
| 590 | + 'html_id' => 'spco-copy-attendee-chk-' . $registration->reg_url_link(), |
|
| 591 | + 'html_class' => 'spco-copy-attendee-chk ee-do-not-validate', |
|
| 592 | + 'display_html_label_text' => false, |
|
| 593 | + ) |
|
| 594 | + ); |
|
| 595 | + } |
|
| 596 | + } |
|
| 597 | + return $copy_attendee_info_inputs; |
|
| 598 | + } |
|
| 599 | + |
|
| 600 | + |
|
| 601 | + /** |
|
| 602 | + * @param EE_Registration $registration |
|
| 603 | + * @return EE_Form_Input_Base |
|
| 604 | + * @throws EE_Error |
|
| 605 | + */ |
|
| 606 | + private function _additional_primary_registrant_inputs(EE_Registration $registration) |
|
| 607 | + { |
|
| 608 | + // generate hidden input |
|
| 609 | + return new EE_Hidden_Input( |
|
| 610 | + array( |
|
| 611 | + 'html_id' => 'primary_registrant', |
|
| 612 | + 'default' => $registration->reg_url_link(), |
|
| 613 | + ) |
|
| 614 | + ); |
|
| 615 | + } |
|
| 616 | + |
|
| 617 | + |
|
| 618 | + /** |
|
| 619 | + * @param EE_Registration $registration |
|
| 620 | + * @param EE_Question $question |
|
| 621 | + * @return EE_Form_Input_Base |
|
| 622 | + * @throws EE_Error |
|
| 623 | + * @throws InvalidArgumentException |
|
| 624 | + * @throws InvalidDataTypeException |
|
| 625 | + * @throws InvalidInterfaceException |
|
| 626 | + * @throws ReflectionException |
|
| 627 | + */ |
|
| 628 | + public function reg_form_question(EE_Registration $registration, EE_Question $question) |
|
| 629 | + { |
|
| 630 | + |
|
| 631 | + // if this question was for an attendee detail, then check for that answer |
|
| 632 | + $answer_value = EEM_Answer::instance()->get_attendee_property_answer_value( |
|
| 633 | + $registration, |
|
| 634 | + $question->system_ID() |
|
| 635 | + ); |
|
| 636 | + $answer = $answer_value === null |
|
| 637 | + ? EEM_Answer::instance()->get_one( |
|
| 638 | + array(array('QST_ID' => $question->ID(), 'REG_ID' => $registration->ID())) |
|
| 639 | + ) |
|
| 640 | + : null; |
|
| 641 | + // if NOT returning to edit an existing registration |
|
| 642 | + // OR if this question is for an attendee property |
|
| 643 | + // OR we still don't have an EE_Answer object |
|
| 644 | + if ($answer_value || ! $answer instanceof EE_Answer || ! $registration->reg_url_link()) { |
|
| 645 | + // create an EE_Answer object for storing everything in |
|
| 646 | + $answer = EE_Answer::new_instance( |
|
| 647 | + array( |
|
| 648 | + 'QST_ID' => $question->ID(), |
|
| 649 | + 'REG_ID' => $registration->ID(), |
|
| 650 | + ) |
|
| 651 | + ); |
|
| 652 | + } |
|
| 653 | + // verify instance |
|
| 654 | + if ($answer instanceof EE_Answer) { |
|
| 655 | + if (! empty($answer_value)) { |
|
| 656 | + $answer->set('ANS_value', $answer_value); |
|
| 657 | + } |
|
| 658 | + $answer->cache('Question', $question); |
|
| 659 | + // remember system ID had a bug where sometimes it could be null |
|
| 660 | + $answer_cache_id = $question->is_system_question() |
|
| 661 | + ? $question->system_ID() . '-' . $registration->reg_url_link() |
|
| 662 | + : $question->ID() . '-' . $registration->reg_url_link(); |
|
| 663 | + $registration->cache('Answer', $answer, $answer_cache_id); |
|
| 664 | + } |
|
| 665 | + return $this->_generate_question_input($registration, $question, $answer); |
|
| 666 | + } |
|
| 667 | + |
|
| 668 | + |
|
| 669 | + /** |
|
| 670 | + * @param EE_Registration $registration |
|
| 671 | + * @param EE_Question $question |
|
| 672 | + * @param $answer |
|
| 673 | + * @return EE_Form_Input_Base |
|
| 674 | + * @throws EE_Error |
|
| 675 | + * @throws InvalidArgumentException |
|
| 676 | + * @throws ReflectionException |
|
| 677 | + * @throws InvalidDataTypeException |
|
| 678 | + * @throws InvalidInterfaceException |
|
| 679 | + */ |
|
| 680 | + private function _generate_question_input(EE_Registration $registration, EE_Question $question, $answer) |
|
| 681 | + { |
|
| 682 | + $identifier = $question->is_system_question() |
|
| 683 | + ? $question->system_ID() |
|
| 684 | + : $question->ID(); |
|
| 685 | + $this->_required_questions[ $identifier ] = $question->required() ? true : false; |
|
| 686 | + add_filter( |
|
| 687 | + 'FHEE__EE_Question__generate_form_input__country_options', |
|
| 688 | + array($this, 'use_cached_countries_for_form_input'), |
|
| 689 | + 10, |
|
| 690 | + 4 |
|
| 691 | + ); |
|
| 692 | + add_filter( |
|
| 693 | + 'FHEE__EE_Question__generate_form_input__state_options', |
|
| 694 | + array($this, 'use_cached_states_for_form_input'), |
|
| 695 | + 10, |
|
| 696 | + 4 |
|
| 697 | + ); |
|
| 698 | + $input_constructor_args = array( |
|
| 699 | + 'html_name' => 'ee_reg_qstn[' . $registration->ID() . '][' . $identifier . ']', |
|
| 700 | + 'html_id' => 'ee_reg_qstn-' . $registration->ID() . '-' . $identifier, |
|
| 701 | + 'html_class' => 'ee-reg-qstn ee-reg-qstn-' . $identifier, |
|
| 702 | + 'html_label_id' => 'ee_reg_qstn-' . $registration->ID() . '-' . $identifier, |
|
| 703 | + 'html_label_class' => 'ee-reg-qstn', |
|
| 704 | + ); |
|
| 705 | + $input_constructor_args['html_label_id'] .= '-lbl'; |
|
| 706 | + if ($answer instanceof EE_Answer && $answer->ID()) { |
|
| 707 | + $input_constructor_args['html_name'] .= '[' . $answer->ID() . ']'; |
|
| 708 | + $input_constructor_args['html_id'] .= '-' . $answer->ID(); |
|
| 709 | + $input_constructor_args['html_label_id'] .= '-' . $answer->ID(); |
|
| 710 | + } |
|
| 711 | + $form_input = $question->generate_form_input( |
|
| 712 | + $registration, |
|
| 713 | + $answer, |
|
| 714 | + $input_constructor_args |
|
| 715 | + ); |
|
| 716 | + remove_filter( |
|
| 717 | + 'FHEE__EE_Question__generate_form_input__country_options', |
|
| 718 | + array($this, 'use_cached_countries_for_form_input') |
|
| 719 | + ); |
|
| 720 | + remove_filter( |
|
| 721 | + 'FHEE__EE_Question__generate_form_input__state_options', |
|
| 722 | + array($this, 'use_cached_states_for_form_input') |
|
| 723 | + ); |
|
| 724 | + return $form_input; |
|
| 725 | + } |
|
| 726 | + |
|
| 727 | + |
|
| 728 | + /** |
|
| 729 | + * Gets the list of countries for the form input |
|
| 730 | + * |
|
| 731 | + * @param array|null $countries_list |
|
| 732 | + * @param EE_Question $question |
|
| 733 | + * @param EE_Registration $registration |
|
| 734 | + * @param EE_Answer $answer |
|
| 735 | + * @return array 2d keys are country IDs, values are their names |
|
| 736 | + * @throws EE_Error |
|
| 737 | + * @throws InvalidArgumentException |
|
| 738 | + * @throws InvalidDataTypeException |
|
| 739 | + * @throws InvalidInterfaceException |
|
| 740 | + * @throws ReflectionException |
|
| 741 | + */ |
|
| 742 | + public function use_cached_countries_for_form_input( |
|
| 743 | + $countries_list, |
|
| 744 | + EE_Question $question = null, |
|
| 745 | + EE_Registration $registration = null, |
|
| 746 | + EE_Answer $answer = null |
|
| 747 | + ) { |
|
| 748 | + $country_options = array('' => ''); |
|
| 749 | + // get possibly cached list of countries |
|
| 750 | + $countries = $this->checkout->action === 'process_reg_step' |
|
| 751 | + ? EEM_Country::instance()->get_all_countries() |
|
| 752 | + : EEM_Country::instance()->get_all_active_countries(); |
|
| 753 | + if (! empty($countries)) { |
|
| 754 | + foreach ($countries as $country) { |
|
| 755 | + if ($country instanceof EE_Country) { |
|
| 756 | + $country_options[ $country->ID() ] = $country->name(); |
|
| 757 | + } |
|
| 758 | + } |
|
| 759 | + } |
|
| 760 | + if ($question instanceof EE_Question && $registration instanceof EE_Registration) { |
|
| 761 | + $answer = EEM_Answer::instance()->get_one( |
|
| 762 | + array(array('QST_ID' => $question->ID(), 'REG_ID' => $registration->ID())) |
|
| 763 | + ); |
|
| 764 | + } else { |
|
| 765 | + $answer = EE_Answer::new_instance(); |
|
| 766 | + } |
|
| 767 | + $country_options = apply_filters( |
|
| 768 | + 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__country_options', |
|
| 769 | + $country_options, |
|
| 770 | + $this, |
|
| 771 | + $registration, |
|
| 772 | + $question, |
|
| 773 | + $answer |
|
| 774 | + ); |
|
| 775 | + return $country_options; |
|
| 776 | + } |
|
| 777 | + |
|
| 778 | + |
|
| 779 | + /** |
|
| 780 | + * Gets the list of states for the form input |
|
| 781 | + * |
|
| 782 | + * @param array|null $states_list |
|
| 783 | + * @param EE_Question $question |
|
| 784 | + * @param EE_Registration $registration |
|
| 785 | + * @param EE_Answer $answer |
|
| 786 | + * @return array 2d keys are state IDs, values are their names |
|
| 787 | + * @throws EE_Error |
|
| 788 | + * @throws InvalidArgumentException |
|
| 789 | + * @throws InvalidDataTypeException |
|
| 790 | + * @throws InvalidInterfaceException |
|
| 791 | + * @throws ReflectionException |
|
| 792 | + */ |
|
| 793 | + public function use_cached_states_for_form_input( |
|
| 794 | + $states_list, |
|
| 795 | + EE_Question $question = null, |
|
| 796 | + EE_Registration $registration = null, |
|
| 797 | + EE_Answer $answer = null |
|
| 798 | + ) { |
|
| 799 | + $state_options = array('' => array('' => '')); |
|
| 800 | + $states = $this->checkout->action === 'process_reg_step' |
|
| 801 | + ? EEM_State::instance()->get_all_states() |
|
| 802 | + : EEM_State::instance()->get_all_active_states(); |
|
| 803 | + if (! empty($states)) { |
|
| 804 | + foreach ($states as $state) { |
|
| 805 | + if ($state instanceof EE_State) { |
|
| 806 | + $state_options[ $state->country()->name() ][ $state->ID() ] = $state->name(); |
|
| 807 | + } |
|
| 808 | + } |
|
| 809 | + } |
|
| 810 | + $state_options = apply_filters( |
|
| 811 | + 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__state_options', |
|
| 812 | + $state_options, |
|
| 813 | + $this, |
|
| 814 | + $registration, |
|
| 815 | + $question, |
|
| 816 | + $answer |
|
| 817 | + ); |
|
| 818 | + return $state_options; |
|
| 819 | + } |
|
| 820 | + |
|
| 821 | + |
|
| 822 | + /********************************************************************************************************/ |
|
| 823 | + /**************************************** PROCESS REG STEP ****************************************/ |
|
| 824 | + /********************************************************************************************************/ |
|
| 825 | + |
|
| 826 | + |
|
| 827 | + /** |
|
| 828 | + * @return bool |
|
| 829 | + * @throws EE_Error |
|
| 830 | + * @throws InvalidArgumentException |
|
| 831 | + * @throws ReflectionException |
|
| 832 | + * @throws RuntimeException |
|
| 833 | + * @throws InvalidDataTypeException |
|
| 834 | + * @throws InvalidInterfaceException |
|
| 835 | + */ |
|
| 836 | + public function process_reg_step() |
|
| 837 | + { |
|
| 838 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 839 | + // grab validated data from form |
|
| 840 | + $valid_data = $this->checkout->current_step->valid_data(); |
|
| 841 | + // EEH_Debug_Tools::printr( $_REQUEST, '$_REQUEST', __FILE__, __LINE__ ); |
|
| 842 | + // EEH_Debug_Tools::printr( $valid_data, '$valid_data', __FILE__, __LINE__ ); |
|
| 843 | + // if we don't have any $valid_data then something went TERRIBLY WRONG !!! |
|
| 844 | + if (empty($valid_data)) { |
|
| 845 | + EE_Error::add_error( |
|
| 846 | + esc_html__('No valid question responses were received.', 'event_espresso'), |
|
| 847 | + __FILE__, |
|
| 848 | + __FUNCTION__, |
|
| 849 | + __LINE__ |
|
| 850 | + ); |
|
| 851 | + return false; |
|
| 852 | + } |
|
| 853 | + if (! $this->checkout->transaction instanceof EE_Transaction || ! $this->checkout->continue_reg) { |
|
| 854 | + EE_Error::add_error( |
|
| 855 | + esc_html__( |
|
| 856 | + 'A valid transaction could not be initiated for processing your registrations.', |
|
| 857 | + 'event_espresso' |
|
| 858 | + ), |
|
| 859 | + __FILE__, |
|
| 860 | + __FUNCTION__, |
|
| 861 | + __LINE__ |
|
| 862 | + ); |
|
| 863 | + return false; |
|
| 864 | + } |
|
| 865 | + // get cached registrations |
|
| 866 | + $registrations = $this->checkout->transaction->registrations($this->checkout->reg_cache_where_params); |
|
| 867 | + // verify we got the goods |
|
| 868 | + if (empty($registrations)) { |
|
| 869 | + // combine the old translated string with a new one, in order to not break translations |
|
| 870 | + $error_message = esc_html__( |
|
| 871 | + 'Your form data could not be applied to any valid registrations.', |
|
| 872 | + 'event_espresso' |
|
| 873 | + ) |
|
| 874 | + . sprintf( |
|
| 875 | + esc_html_x( |
|
| 876 | + '%3$sThis can sometimes happen if too much time has been taken to complete the registration process.%3$sPlease return to the %1$sEvent List%2$s and reselect your tickets. If the problem continues, please contact the site administrator.', |
|
| 877 | + '(line break)This can sometimes happen if too much time has been taken to complete the registration process.(line break)Please return to the (link)Event List(end link) and reselect your tickets. If the problem continues, please contact the site administrator.', |
|
| 878 | + 'event_espresso' |
|
| 879 | + ), |
|
| 880 | + '<a href="' . get_post_type_archive_link('espresso_events') . '" >', |
|
| 881 | + '</a>', |
|
| 882 | + '<br />' |
|
| 883 | + ); |
|
| 884 | + EE_Error::add_error( |
|
| 885 | + $error_message, |
|
| 886 | + __FILE__, |
|
| 887 | + __FUNCTION__, |
|
| 888 | + __LINE__ |
|
| 889 | + ); |
|
| 890 | + return false; |
|
| 891 | + } |
|
| 892 | + // extract attendee info from form data and save to model objects |
|
| 893 | + $registrations_processed = $this->_process_registrations($registrations, $valid_data); |
|
| 894 | + // if first pass thru SPCO, |
|
| 895 | + // then let's check processed registrations against the total number of tickets in the cart |
|
| 896 | + if ($registrations_processed === false) { |
|
| 897 | + // but return immediately if the previous step exited early due to errors |
|
| 898 | + return false; |
|
| 899 | + } |
|
| 900 | + if (! $this->checkout->revisit && $registrations_processed !== $this->checkout->total_ticket_count) { |
|
| 901 | + // generate a correctly translated string for all possible singular/plural combinations |
|
| 902 | + if ($this->checkout->total_ticket_count === 1 && $registrations_processed !== 1) { |
|
| 903 | + $error_msg = sprintf( |
|
| 904 | + esc_html_x( |
|
| 905 | + 'There was %1$d ticket in the Event Queue, but %2$ds registrations were processed', |
|
| 906 | + 'There was 1 ticket in the Event Queue, but 2 registrations were processed', |
|
| 907 | + 'event_espresso' |
|
| 908 | + ), |
|
| 909 | + $this->checkout->total_ticket_count, |
|
| 910 | + $registrations_processed |
|
| 911 | + ); |
|
| 912 | + } elseif ($this->checkout->total_ticket_count !== 1 && $registrations_processed === 1) { |
|
| 913 | + $error_msg = sprintf( |
|
| 914 | + esc_html_x( |
|
| 915 | + 'There was a total of %1$d tickets in the Event Queue, but only %2$ds registration was processed', |
|
| 916 | + 'There was a total of 2 tickets in the Event Queue, but only 1 registration was processed', |
|
| 917 | + 'event_espresso' |
|
| 918 | + ), |
|
| 919 | + $this->checkout->total_ticket_count, |
|
| 920 | + $registrations_processed |
|
| 921 | + ); |
|
| 922 | + } else { |
|
| 923 | + $error_msg = sprintf( |
|
| 924 | + esc_html__( |
|
| 925 | + 'There was a total of 2 tickets in the Event Queue, but 2 registrations were processed', |
|
| 926 | + 'event_espresso' |
|
| 927 | + ), |
|
| 928 | + $this->checkout->total_ticket_count, |
|
| 929 | + $registrations_processed |
|
| 930 | + ); |
|
| 931 | + } |
|
| 932 | + EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 933 | + return false; |
|
| 934 | + } |
|
| 935 | + // mark this reg step as completed |
|
| 936 | + $this->set_completed(); |
|
| 937 | + $this->_set_success_message( |
|
| 938 | + esc_html__('The Attendee Information Step has been successfully completed.', 'event_espresso') |
|
| 939 | + ); |
|
| 940 | + // do action in case a plugin wants to do something with the data submitted in step 1. |
|
| 941 | + // passes EE_Single_Page_Checkout, and it's posted data |
|
| 942 | + do_action('AHEE__EE_Single_Page_Checkout__process_attendee_information__end', $this, $valid_data); |
|
| 943 | + return true; |
|
| 944 | + } |
|
| 945 | + |
|
| 946 | + |
|
| 947 | + /** |
|
| 948 | + * _process_registrations |
|
| 949 | + * |
|
| 950 | + * @param EE_Registration[] $registrations |
|
| 951 | + * @param array[][] $valid_data |
|
| 952 | + * @return bool|int |
|
| 953 | + * @throws EntityNotFoundException |
|
| 954 | + * @throws EE_Error |
|
| 955 | + * @throws InvalidArgumentException |
|
| 956 | + * @throws ReflectionException |
|
| 957 | + * @throws RuntimeException |
|
| 958 | + * @throws InvalidDataTypeException |
|
| 959 | + * @throws InvalidInterfaceException |
|
| 960 | + */ |
|
| 961 | + private function _process_registrations($registrations = array(), $valid_data = array()) |
|
| 962 | + { |
|
| 963 | + // load resources and set some defaults |
|
| 964 | + EE_Registry::instance()->load_model('Attendee'); |
|
| 965 | + // holder for primary registrant attendee object |
|
| 966 | + $this->checkout->primary_attendee_obj = null; |
|
| 967 | + // array for tracking reg form data for the primary registrant |
|
| 968 | + $primary_registrant = array( |
|
| 969 | + 'line_item_id' => null, |
|
| 970 | + ); |
|
| 971 | + $copy_primary = false; |
|
| 972 | + // reg form sections that do not contain inputs |
|
| 973 | + $non_input_form_sections = array( |
|
| 974 | + 'primary_registrant', |
|
| 975 | + 'additional_attendee_reg_info', |
|
| 976 | + 'spco_copy_attendee_chk', |
|
| 977 | + ); |
|
| 978 | + // attendee counter |
|
| 979 | + $att_nmbr = 0; |
|
| 980 | + // grab the saved registrations from the transaction |
|
| 981 | + foreach ($registrations as $registration) { |
|
| 982 | + // verify EE_Registration object |
|
| 983 | + if (! $registration instanceof EE_Registration) { |
|
| 984 | + EE_Error::add_error( |
|
| 985 | + esc_html__( |
|
| 986 | + 'An invalid Registration object was discovered when attempting to process your registration information.', |
|
| 987 | + 'event_espresso' |
|
| 988 | + ), |
|
| 989 | + __FILE__, |
|
| 990 | + __FUNCTION__, |
|
| 991 | + __LINE__ |
|
| 992 | + ); |
|
| 993 | + return false; |
|
| 994 | + } |
|
| 995 | + /** @var string $reg_url_link */ |
|
| 996 | + $reg_url_link = $registration->reg_url_link(); |
|
| 997 | + // reg_url_link exists ? |
|
| 998 | + if (! empty($reg_url_link)) { |
|
| 999 | + // should this registration be processed during this visit ? |
|
| 1000 | + if ($this->checkout->visit_allows_processing_of_this_registration($registration)) { |
|
| 1001 | + // if NOT revisiting, then let's save the registration now, |
|
| 1002 | + // so that we have a REG_ID to use when generating other objects |
|
| 1003 | + if (! $this->checkout->revisit) { |
|
| 1004 | + $registration->save(); |
|
| 1005 | + } |
|
| 1006 | + /** |
|
| 1007 | + * This allows plugins to trigger a fail on processing of a |
|
| 1008 | + * registration for any conditions they may have for it to pass. |
|
| 1009 | + * |
|
| 1010 | + * @var bool if true is returned by the plugin then the |
|
| 1011 | + * registration processing is halted. |
|
| 1012 | + */ |
|
| 1013 | + if (apply_filters( |
|
| 1014 | + 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___process_registrations__pre_registration_process', |
|
| 1015 | + false, |
|
| 1016 | + $att_nmbr, |
|
| 1017 | + $registration, |
|
| 1018 | + $registrations, |
|
| 1019 | + $valid_data, |
|
| 1020 | + $this |
|
| 1021 | + )) { |
|
| 1022 | + return false; |
|
| 1023 | + } |
|
| 1024 | + |
|
| 1025 | + // Houston, we have a registration! |
|
| 1026 | + $att_nmbr++; |
|
| 1027 | + $this->_attendee_data[ $reg_url_link ] = array(); |
|
| 1028 | + // grab any existing related answer objects |
|
| 1029 | + $this->_registration_answers = $registration->answers(); |
|
| 1030 | + // unset( $valid_data[ $reg_url_link ]['additional_attendee_reg_info'] ); |
|
| 1031 | + if (isset($valid_data[ $reg_url_link ])) { |
|
| 1032 | + // do we need to copy basic info from primary attendee ? |
|
| 1033 | + $copy_primary = isset($valid_data[ $reg_url_link ]['additional_attendee_reg_info']) |
|
| 1034 | + && absint($valid_data[ $reg_url_link ]['additional_attendee_reg_info']) === 0; |
|
| 1035 | + // filter form input data for this registration |
|
| 1036 | + $valid_data[ $reg_url_link ] = (array) apply_filters( |
|
| 1037 | + 'FHEE__EE_Single_Page_Checkout__process_attendee_information__valid_data_line_item', |
|
| 1038 | + $valid_data[ $reg_url_link ] |
|
| 1039 | + ); |
|
| 1040 | + if (isset($valid_data['primary_attendee'])) { |
|
| 1041 | + $primary_registrant['line_item_id'] = ! empty($valid_data['primary_attendee']) |
|
| 1042 | + ? $valid_data['primary_attendee'] |
|
| 1043 | + : false; |
|
| 1044 | + unset($valid_data['primary_attendee']); |
|
| 1045 | + } |
|
| 1046 | + // now loop through our array of valid post data && process attendee reg forms |
|
| 1047 | + foreach ($valid_data[ $reg_url_link ] as $form_section => $form_inputs) { |
|
| 1048 | + if (! in_array($form_section, $non_input_form_sections, true)) { |
|
| 1049 | + foreach ($form_inputs as $form_input => $input_value) { |
|
| 1050 | + // \EEH_Debug_Tools::printr( $input_value, $form_input, __FILE__, __LINE__ ); |
|
| 1051 | + // check for critical inputs |
|
| 1052 | + if (! $this->_verify_critical_attendee_details_are_set_and_validate_email( |
|
| 1053 | + $form_input, |
|
| 1054 | + $input_value |
|
| 1055 | + ) |
|
| 1056 | + ) { |
|
| 1057 | + return false; |
|
| 1058 | + } |
|
| 1059 | + // store a bit of data about the primary attendee |
|
| 1060 | + if ($att_nmbr === 1 |
|
| 1061 | + && ! empty($input_value) |
|
| 1062 | + && $reg_url_link === $primary_registrant['line_item_id'] |
|
| 1063 | + ) { |
|
| 1064 | + $primary_registrant[ $form_input ] = $input_value; |
|
| 1065 | + } elseif ($copy_primary |
|
| 1066 | + && $input_value === null |
|
| 1067 | + && isset($primary_registrant[ $form_input ]) |
|
| 1068 | + ) { |
|
| 1069 | + $input_value = $primary_registrant[ $form_input ]; |
|
| 1070 | + } |
|
| 1071 | + // now attempt to save the input data |
|
| 1072 | + if (! $this->_save_registration_form_input( |
|
| 1073 | + $registration, |
|
| 1074 | + $form_input, |
|
| 1075 | + $input_value |
|
| 1076 | + ) |
|
| 1077 | + ) { |
|
| 1078 | + EE_Error::add_error( |
|
| 1079 | + sprintf( |
|
| 1080 | + esc_html_x( |
|
| 1081 | + 'Unable to save registration form data for the form input: "%1$s" with the submitted value: "%2$s"', |
|
| 1082 | + 'Unable to save registration form data for the form input: "form input name" with the submitted value: "form input value"', |
|
| 1083 | + 'event_espresso' |
|
| 1084 | + ), |
|
| 1085 | + $form_input, |
|
| 1086 | + $input_value |
|
| 1087 | + ), |
|
| 1088 | + __FILE__, |
|
| 1089 | + __FUNCTION__, |
|
| 1090 | + __LINE__ |
|
| 1091 | + ); |
|
| 1092 | + return false; |
|
| 1093 | + } |
|
| 1094 | + } |
|
| 1095 | + } |
|
| 1096 | + } // end of foreach ( $valid_data[ $reg_url_link ] as $form_section => $form_inputs ) |
|
| 1097 | + } |
|
| 1098 | + // EEH_Debug_Tools::printr( $this->_attendee_data, '$this->_attendee_data', __FILE__, __LINE__ ); |
|
| 1099 | + // this registration does not require additional attendee information ? |
|
| 1100 | + if ($copy_primary |
|
| 1101 | + && $att_nmbr > 1 |
|
| 1102 | + && $this->checkout->primary_attendee_obj instanceof EE_Attendee |
|
| 1103 | + ) { |
|
| 1104 | + // just copy the primary registrant |
|
| 1105 | + $attendee = $this->checkout->primary_attendee_obj; |
|
| 1106 | + } else { |
|
| 1107 | + // ensure critical details are set for additional attendees |
|
| 1108 | + $this->_attendee_data[ $reg_url_link ] = $att_nmbr > 1 |
|
| 1109 | + ? $this->_copy_critical_attendee_details_from_primary_registrant( |
|
| 1110 | + $this->_attendee_data[ $reg_url_link ] |
|
| 1111 | + ) |
|
| 1112 | + : $this->_attendee_data[ $reg_url_link ]; |
|
| 1113 | + // execute create attendee command (which may return an existing attendee) |
|
| 1114 | + $attendee = EE_Registry::instance()->BUS->execute( |
|
| 1115 | + new CreateAttendeeCommand( |
|
| 1116 | + $this->_attendee_data[ $reg_url_link ], |
|
| 1117 | + $registration |
|
| 1118 | + ) |
|
| 1119 | + ); |
|
| 1120 | + // who's #1 ? |
|
| 1121 | + if ($att_nmbr === 1) { |
|
| 1122 | + $this->checkout->primary_attendee_obj = $attendee; |
|
| 1123 | + } |
|
| 1124 | + } |
|
| 1125 | + // EEH_Debug_Tools::printr( $attendee, '$attendee', __FILE__, __LINE__ ); |
|
| 1126 | + // add relation to registration, set attendee ID, and cache attendee |
|
| 1127 | + $this->_associate_attendee_with_registration($registration, $attendee); |
|
| 1128 | + // \EEH_Debug_Tools::printr( $registration, '$registration', __FILE__, __LINE__ ); |
|
| 1129 | + if (! $registration->attendee() instanceof EE_Attendee) { |
|
| 1130 | + EE_Error::add_error( |
|
| 1131 | + sprintf( |
|
| 1132 | + esc_html_x( |
|
| 1133 | + 'Registration %s has an invalid or missing Attendee object.', |
|
| 1134 | + 'Registration 123-456-789 has an invalid or missing Attendee object.', |
|
| 1135 | + 'event_espresso' |
|
| 1136 | + ), |
|
| 1137 | + $reg_url_link |
|
| 1138 | + ), |
|
| 1139 | + __FILE__, |
|
| 1140 | + __FUNCTION__, |
|
| 1141 | + __LINE__ |
|
| 1142 | + ); |
|
| 1143 | + return false; |
|
| 1144 | + } |
|
| 1145 | + /** @type EE_Registration_Processor $registration_processor */ |
|
| 1146 | + $registration_processor = EE_Registry::instance()->load_class('Registration_Processor'); |
|
| 1147 | + // at this point, we should have enough details about the registrant to consider the registration |
|
| 1148 | + // NOT incomplete |
|
| 1149 | + $registration_processor->toggle_incomplete_registration_status_to_default( |
|
| 1150 | + $registration, |
|
| 1151 | + false, |
|
| 1152 | + new Context( |
|
| 1153 | + 'spco_reg_step_attendee_information_process_registrations', |
|
| 1154 | + esc_html__( |
|
| 1155 | + 'Finished populating registration with details from the registration form after submitting the Attendee Information Reg Step.', |
|
| 1156 | + 'event_espresso' |
|
| 1157 | + ) |
|
| 1158 | + ) |
|
| 1159 | + ); |
|
| 1160 | + // we can also consider the TXN to not have been failed, so temporarily upgrade it's status to |
|
| 1161 | + // abandoned |
|
| 1162 | + $this->checkout->transaction->toggle_failed_transaction_status(); |
|
| 1163 | + // if we've gotten this far, then let's save what we have |
|
| 1164 | + $registration->save(); |
|
| 1165 | + // add relation between TXN and registration |
|
| 1166 | + $this->_associate_registration_with_transaction($registration); |
|
| 1167 | + } |
|
| 1168 | + } else { |
|
| 1169 | + EE_Error::add_error( |
|
| 1170 | + esc_html__( |
|
| 1171 | + 'An invalid or missing line item ID was encountered while attempting to process the registration form.', |
|
| 1172 | + 'event_espresso' |
|
| 1173 | + ), |
|
| 1174 | + __FILE__, |
|
| 1175 | + __FUNCTION__, |
|
| 1176 | + __LINE__ |
|
| 1177 | + ); |
|
| 1178 | + // remove malformed data |
|
| 1179 | + unset($valid_data[ $reg_url_link ]); |
|
| 1180 | + return false; |
|
| 1181 | + } |
|
| 1182 | + } // end of foreach ( $this->checkout->transaction->registrations() as $registration ) |
|
| 1183 | + return $att_nmbr; |
|
| 1184 | + } |
|
| 1185 | + |
|
| 1186 | + |
|
| 1187 | + /** |
|
| 1188 | + * _save_registration_form_input |
|
| 1189 | + * |
|
| 1190 | + * @param EE_Registration $registration |
|
| 1191 | + * @param string $form_input |
|
| 1192 | + * @param string $input_value |
|
| 1193 | + * @return bool |
|
| 1194 | + * @throws EE_Error |
|
| 1195 | + * @throws InvalidArgumentException |
|
| 1196 | + * @throws InvalidDataTypeException |
|
| 1197 | + * @throws InvalidInterfaceException |
|
| 1198 | + * @throws ReflectionException |
|
| 1199 | + */ |
|
| 1200 | + private function _save_registration_form_input( |
|
| 1201 | + EE_Registration $registration, |
|
| 1202 | + $form_input = '', |
|
| 1203 | + $input_value = '' |
|
| 1204 | + ) { |
|
| 1205 | + // \EEH_Debug_Tools::printr( __FUNCTION__, __CLASS__, __FILE__, __LINE__, 2 ); |
|
| 1206 | + // \EEH_Debug_Tools::printr( $form_input, '$form_input', __FILE__, __LINE__ ); |
|
| 1207 | + // \EEH_Debug_Tools::printr( $input_value, '$input_value', __FILE__, __LINE__ ); |
|
| 1208 | + // allow for plugins to hook in and do their own processing of the form input. |
|
| 1209 | + // For plugins to bypass normal processing here, they just need to return a boolean value. |
|
| 1210 | + if (apply_filters( |
|
| 1211 | + 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___save_registration_form_input', |
|
| 1212 | + false, |
|
| 1213 | + $registration, |
|
| 1214 | + $form_input, |
|
| 1215 | + $input_value, |
|
| 1216 | + $this |
|
| 1217 | + )) { |
|
| 1218 | + return true; |
|
| 1219 | + } |
|
| 1220 | + /* |
|
| 1221 | 1221 | * $answer_cache_id is the key used to find the EE_Answer we want |
| 1222 | 1222 | * @see https://events.codebasehq.com/projects/event-espresso/tickets/10477 |
| 1223 | 1223 | */ |
| 1224 | - $answer_cache_id = $this->checkout->reg_url_link |
|
| 1225 | - ? $form_input . '-' . $registration->reg_url_link() |
|
| 1226 | - : $form_input; |
|
| 1227 | - $answer_is_obj = isset($this->_registration_answers[ $answer_cache_id ]) |
|
| 1228 | - && $this->_registration_answers[ $answer_cache_id ] instanceof EE_Answer; |
|
| 1229 | - // rename form_inputs if they are EE_Attendee properties |
|
| 1230 | - switch ((string) $form_input) { |
|
| 1231 | - case 'state': |
|
| 1232 | - case 'STA_ID': |
|
| 1233 | - $attendee_property = true; |
|
| 1234 | - $form_input = 'STA_ID'; |
|
| 1235 | - break; |
|
| 1236 | - |
|
| 1237 | - case 'country': |
|
| 1238 | - case 'CNT_ISO': |
|
| 1239 | - $attendee_property = true; |
|
| 1240 | - $form_input = 'CNT_ISO'; |
|
| 1241 | - break; |
|
| 1242 | - |
|
| 1243 | - default: |
|
| 1244 | - $ATT_input = 'ATT_' . $form_input; |
|
| 1245 | - // EEH_Debug_Tools::printr( $ATT_input, '$ATT_input', __FILE__, __LINE__ ); |
|
| 1246 | - $attendee_property = EEM_Attendee::instance()->has_field($ATT_input) ? true : false; |
|
| 1247 | - $form_input = $attendee_property ? 'ATT_' . $form_input : $form_input; |
|
| 1248 | - } |
|
| 1249 | - // EEH_Debug_Tools::printr( $answer_cache_id, '$answer_cache_id', __FILE__, __LINE__ ); |
|
| 1250 | - // EEH_Debug_Tools::printr( $attendee_property, '$attendee_property', __FILE__, __LINE__ ); |
|
| 1251 | - // EEH_Debug_Tools::printr( $answer_is_obj, '$answer_is_obj', __FILE__, __LINE__ ); |
|
| 1252 | - // if this form input has a corresponding attendee property |
|
| 1253 | - if ($attendee_property) { |
|
| 1254 | - $this->_attendee_data[ $registration->reg_url_link() ][ $form_input ] = $input_value; |
|
| 1255 | - if ($answer_is_obj) { |
|
| 1256 | - // and delete the corresponding answer since we won't be storing this data in that object |
|
| 1257 | - $registration->_remove_relation_to($this->_registration_answers[ $answer_cache_id ], 'Answer'); |
|
| 1258 | - $this->_registration_answers[ $answer_cache_id ]->delete_permanently(); |
|
| 1259 | - } |
|
| 1260 | - return true; |
|
| 1261 | - } |
|
| 1262 | - if ($answer_is_obj) { |
|
| 1263 | - // save this data to the answer object |
|
| 1264 | - $this->_registration_answers[ $answer_cache_id ]->set_value($input_value); |
|
| 1265 | - $result = $this->_registration_answers[ $answer_cache_id ]->save(); |
|
| 1266 | - return $result !== false; |
|
| 1267 | - } |
|
| 1268 | - foreach ($this->_registration_answers as $answer) { |
|
| 1269 | - if ($answer instanceof EE_Answer && $answer->question_ID() === $answer_cache_id) { |
|
| 1270 | - $answer->set_value($input_value); |
|
| 1271 | - $result = $answer->save(); |
|
| 1272 | - return $result !== false; |
|
| 1273 | - } |
|
| 1274 | - } |
|
| 1275 | - return false; |
|
| 1276 | - } |
|
| 1277 | - |
|
| 1278 | - |
|
| 1279 | - /** |
|
| 1280 | - * _verify_critical_attendee_details_are_set |
|
| 1281 | - * |
|
| 1282 | - * @param string $form_input |
|
| 1283 | - * @param string $input_value |
|
| 1284 | - * @return boolean |
|
| 1285 | - */ |
|
| 1286 | - private function _verify_critical_attendee_details_are_set_and_validate_email( |
|
| 1287 | - $form_input = '', |
|
| 1288 | - $input_value = '' |
|
| 1289 | - ) { |
|
| 1290 | - if (empty($input_value)) { |
|
| 1291 | - // if the form input isn't marked as being required, then just return |
|
| 1292 | - if (! isset($this->_required_questions[ $form_input ]) || ! $this->_required_questions[ $form_input ]) { |
|
| 1293 | - return true; |
|
| 1294 | - } |
|
| 1295 | - switch ($form_input) { |
|
| 1296 | - case 'fname': |
|
| 1297 | - EE_Error::add_error( |
|
| 1298 | - esc_html__('First Name is a required value.', 'event_espresso'), |
|
| 1299 | - __FILE__, |
|
| 1300 | - __FUNCTION__, |
|
| 1301 | - __LINE__ |
|
| 1302 | - ); |
|
| 1303 | - return false; |
|
| 1304 | - break; |
|
| 1305 | - case 'lname': |
|
| 1306 | - EE_Error::add_error( |
|
| 1307 | - esc_html__('Last Name is a required value.', 'event_espresso'), |
|
| 1308 | - __FILE__, |
|
| 1309 | - __FUNCTION__, |
|
| 1310 | - __LINE__ |
|
| 1311 | - ); |
|
| 1312 | - return false; |
|
| 1313 | - break; |
|
| 1314 | - case 'email': |
|
| 1315 | - EE_Error::add_error( |
|
| 1316 | - esc_html__('Please enter a valid email address.', 'event_espresso'), |
|
| 1317 | - __FILE__, |
|
| 1318 | - __FUNCTION__, |
|
| 1319 | - __LINE__ |
|
| 1320 | - ); |
|
| 1321 | - return false; |
|
| 1322 | - break; |
|
| 1323 | - } |
|
| 1324 | - } |
|
| 1325 | - return true; |
|
| 1326 | - } |
|
| 1327 | - |
|
| 1328 | - |
|
| 1329 | - /** |
|
| 1330 | - * _associate_attendee_with_registration |
|
| 1331 | - * |
|
| 1332 | - * @param EE_Registration $registration |
|
| 1333 | - * @param EE_Attendee $attendee |
|
| 1334 | - * @return void |
|
| 1335 | - * @throws EE_Error |
|
| 1336 | - * @throws InvalidArgumentException |
|
| 1337 | - * @throws ReflectionException |
|
| 1338 | - * @throws RuntimeException |
|
| 1339 | - * @throws InvalidDataTypeException |
|
| 1340 | - * @throws InvalidInterfaceException |
|
| 1341 | - */ |
|
| 1342 | - private function _associate_attendee_with_registration(EE_Registration $registration, EE_Attendee $attendee) |
|
| 1343 | - { |
|
| 1344 | - // add relation to attendee |
|
| 1345 | - $registration->_add_relation_to($attendee, 'Attendee'); |
|
| 1346 | - $registration->set_attendee_id($attendee->ID()); |
|
| 1347 | - $registration->update_cache_after_object_save('Attendee', $attendee); |
|
| 1348 | - } |
|
| 1349 | - |
|
| 1350 | - |
|
| 1351 | - /** |
|
| 1352 | - * _associate_registration_with_transaction |
|
| 1353 | - * |
|
| 1354 | - * @param EE_Registration $registration |
|
| 1355 | - * @return void |
|
| 1356 | - * @throws EE_Error |
|
| 1357 | - * @throws InvalidArgumentException |
|
| 1358 | - * @throws ReflectionException |
|
| 1359 | - * @throws InvalidDataTypeException |
|
| 1360 | - * @throws InvalidInterfaceException |
|
| 1361 | - */ |
|
| 1362 | - private function _associate_registration_with_transaction(EE_Registration $registration) |
|
| 1363 | - { |
|
| 1364 | - // add relation to registration |
|
| 1365 | - $this->checkout->transaction->_add_relation_to($registration, 'Registration'); |
|
| 1366 | - $this->checkout->transaction->update_cache_after_object_save('Registration', $registration); |
|
| 1367 | - } |
|
| 1368 | - |
|
| 1369 | - |
|
| 1370 | - /** |
|
| 1371 | - * _copy_critical_attendee_details_from_primary_registrant |
|
| 1372 | - * ensures that all attendees at least have data for first name, last name, and email address |
|
| 1373 | - * |
|
| 1374 | - * @param array $attendee_data |
|
| 1375 | - * @return array |
|
| 1376 | - * @throws EE_Error |
|
| 1377 | - * @throws InvalidArgumentException |
|
| 1378 | - * @throws ReflectionException |
|
| 1379 | - * @throws InvalidDataTypeException |
|
| 1380 | - * @throws InvalidInterfaceException |
|
| 1381 | - */ |
|
| 1382 | - private function _copy_critical_attendee_details_from_primary_registrant($attendee_data = array()) |
|
| 1383 | - { |
|
| 1384 | - // bare minimum critical details include first name, last name, email address |
|
| 1385 | - $critical_attendee_details = array('ATT_fname', 'ATT_lname', 'ATT_email'); |
|
| 1386 | - // add address info to critical details? |
|
| 1387 | - if (apply_filters( |
|
| 1388 | - 'FHEE__EE_SPCO_Reg_Step_Attendee_Information__merge_address_details_with_critical_attendee_details', |
|
| 1389 | - false |
|
| 1390 | - )) { |
|
| 1391 | - $address_details = array( |
|
| 1392 | - 'ATT_address', |
|
| 1393 | - 'ATT_address2', |
|
| 1394 | - 'ATT_city', |
|
| 1395 | - 'STA_ID', |
|
| 1396 | - 'CNT_ISO', |
|
| 1397 | - 'ATT_zip', |
|
| 1398 | - 'ATT_phone', |
|
| 1399 | - ); |
|
| 1400 | - $critical_attendee_details = array_merge($critical_attendee_details, $address_details); |
|
| 1401 | - } |
|
| 1402 | - foreach ($critical_attendee_details as $critical_attendee_detail) { |
|
| 1403 | - if (! isset($attendee_data[ $critical_attendee_detail ]) |
|
| 1404 | - || empty($attendee_data[ $critical_attendee_detail ]) |
|
| 1405 | - ) { |
|
| 1406 | - $attendee_data[ $critical_attendee_detail ] = $this->checkout->primary_attendee_obj->get( |
|
| 1407 | - $critical_attendee_detail |
|
| 1408 | - ); |
|
| 1409 | - } |
|
| 1410 | - } |
|
| 1411 | - return $attendee_data; |
|
| 1412 | - } |
|
| 1413 | - |
|
| 1414 | - |
|
| 1415 | - /** |
|
| 1416 | - * update_reg_step |
|
| 1417 | - * this is the final step after a user revisits the site to edit their attendee information |
|
| 1418 | - * this gets called AFTER the process_reg_step() method above |
|
| 1419 | - * |
|
| 1420 | - * @return bool |
|
| 1421 | - * @throws EE_Error |
|
| 1422 | - * @throws InvalidArgumentException |
|
| 1423 | - * @throws ReflectionException |
|
| 1424 | - * @throws RuntimeException |
|
| 1425 | - * @throws InvalidDataTypeException |
|
| 1426 | - * @throws InvalidInterfaceException |
|
| 1427 | - */ |
|
| 1428 | - public function update_reg_step() |
|
| 1429 | - { |
|
| 1430 | - // save everything |
|
| 1431 | - if ($this->process_reg_step()) { |
|
| 1432 | - $this->checkout->redirect = true; |
|
| 1433 | - $this->checkout->redirect_url = add_query_arg( |
|
| 1434 | - array( |
|
| 1435 | - 'e_reg_url_link' => $this->checkout->reg_url_link, |
|
| 1436 | - 'revisit' => true, |
|
| 1437 | - ), |
|
| 1438 | - $this->checkout->thank_you_page_url |
|
| 1439 | - ); |
|
| 1440 | - $this->checkout->json_response->set_redirect_url($this->checkout->redirect_url); |
|
| 1441 | - return true; |
|
| 1442 | - } |
|
| 1443 | - return false; |
|
| 1444 | - } |
|
| 1224 | + $answer_cache_id = $this->checkout->reg_url_link |
|
| 1225 | + ? $form_input . '-' . $registration->reg_url_link() |
|
| 1226 | + : $form_input; |
|
| 1227 | + $answer_is_obj = isset($this->_registration_answers[ $answer_cache_id ]) |
|
| 1228 | + && $this->_registration_answers[ $answer_cache_id ] instanceof EE_Answer; |
|
| 1229 | + // rename form_inputs if they are EE_Attendee properties |
|
| 1230 | + switch ((string) $form_input) { |
|
| 1231 | + case 'state': |
|
| 1232 | + case 'STA_ID': |
|
| 1233 | + $attendee_property = true; |
|
| 1234 | + $form_input = 'STA_ID'; |
|
| 1235 | + break; |
|
| 1236 | + |
|
| 1237 | + case 'country': |
|
| 1238 | + case 'CNT_ISO': |
|
| 1239 | + $attendee_property = true; |
|
| 1240 | + $form_input = 'CNT_ISO'; |
|
| 1241 | + break; |
|
| 1242 | + |
|
| 1243 | + default: |
|
| 1244 | + $ATT_input = 'ATT_' . $form_input; |
|
| 1245 | + // EEH_Debug_Tools::printr( $ATT_input, '$ATT_input', __FILE__, __LINE__ ); |
|
| 1246 | + $attendee_property = EEM_Attendee::instance()->has_field($ATT_input) ? true : false; |
|
| 1247 | + $form_input = $attendee_property ? 'ATT_' . $form_input : $form_input; |
|
| 1248 | + } |
|
| 1249 | + // EEH_Debug_Tools::printr( $answer_cache_id, '$answer_cache_id', __FILE__, __LINE__ ); |
|
| 1250 | + // EEH_Debug_Tools::printr( $attendee_property, '$attendee_property', __FILE__, __LINE__ ); |
|
| 1251 | + // EEH_Debug_Tools::printr( $answer_is_obj, '$answer_is_obj', __FILE__, __LINE__ ); |
|
| 1252 | + // if this form input has a corresponding attendee property |
|
| 1253 | + if ($attendee_property) { |
|
| 1254 | + $this->_attendee_data[ $registration->reg_url_link() ][ $form_input ] = $input_value; |
|
| 1255 | + if ($answer_is_obj) { |
|
| 1256 | + // and delete the corresponding answer since we won't be storing this data in that object |
|
| 1257 | + $registration->_remove_relation_to($this->_registration_answers[ $answer_cache_id ], 'Answer'); |
|
| 1258 | + $this->_registration_answers[ $answer_cache_id ]->delete_permanently(); |
|
| 1259 | + } |
|
| 1260 | + return true; |
|
| 1261 | + } |
|
| 1262 | + if ($answer_is_obj) { |
|
| 1263 | + // save this data to the answer object |
|
| 1264 | + $this->_registration_answers[ $answer_cache_id ]->set_value($input_value); |
|
| 1265 | + $result = $this->_registration_answers[ $answer_cache_id ]->save(); |
|
| 1266 | + return $result !== false; |
|
| 1267 | + } |
|
| 1268 | + foreach ($this->_registration_answers as $answer) { |
|
| 1269 | + if ($answer instanceof EE_Answer && $answer->question_ID() === $answer_cache_id) { |
|
| 1270 | + $answer->set_value($input_value); |
|
| 1271 | + $result = $answer->save(); |
|
| 1272 | + return $result !== false; |
|
| 1273 | + } |
|
| 1274 | + } |
|
| 1275 | + return false; |
|
| 1276 | + } |
|
| 1277 | + |
|
| 1278 | + |
|
| 1279 | + /** |
|
| 1280 | + * _verify_critical_attendee_details_are_set |
|
| 1281 | + * |
|
| 1282 | + * @param string $form_input |
|
| 1283 | + * @param string $input_value |
|
| 1284 | + * @return boolean |
|
| 1285 | + */ |
|
| 1286 | + private function _verify_critical_attendee_details_are_set_and_validate_email( |
|
| 1287 | + $form_input = '', |
|
| 1288 | + $input_value = '' |
|
| 1289 | + ) { |
|
| 1290 | + if (empty($input_value)) { |
|
| 1291 | + // if the form input isn't marked as being required, then just return |
|
| 1292 | + if (! isset($this->_required_questions[ $form_input ]) || ! $this->_required_questions[ $form_input ]) { |
|
| 1293 | + return true; |
|
| 1294 | + } |
|
| 1295 | + switch ($form_input) { |
|
| 1296 | + case 'fname': |
|
| 1297 | + EE_Error::add_error( |
|
| 1298 | + esc_html__('First Name is a required value.', 'event_espresso'), |
|
| 1299 | + __FILE__, |
|
| 1300 | + __FUNCTION__, |
|
| 1301 | + __LINE__ |
|
| 1302 | + ); |
|
| 1303 | + return false; |
|
| 1304 | + break; |
|
| 1305 | + case 'lname': |
|
| 1306 | + EE_Error::add_error( |
|
| 1307 | + esc_html__('Last Name is a required value.', 'event_espresso'), |
|
| 1308 | + __FILE__, |
|
| 1309 | + __FUNCTION__, |
|
| 1310 | + __LINE__ |
|
| 1311 | + ); |
|
| 1312 | + return false; |
|
| 1313 | + break; |
|
| 1314 | + case 'email': |
|
| 1315 | + EE_Error::add_error( |
|
| 1316 | + esc_html__('Please enter a valid email address.', 'event_espresso'), |
|
| 1317 | + __FILE__, |
|
| 1318 | + __FUNCTION__, |
|
| 1319 | + __LINE__ |
|
| 1320 | + ); |
|
| 1321 | + return false; |
|
| 1322 | + break; |
|
| 1323 | + } |
|
| 1324 | + } |
|
| 1325 | + return true; |
|
| 1326 | + } |
|
| 1327 | + |
|
| 1328 | + |
|
| 1329 | + /** |
|
| 1330 | + * _associate_attendee_with_registration |
|
| 1331 | + * |
|
| 1332 | + * @param EE_Registration $registration |
|
| 1333 | + * @param EE_Attendee $attendee |
|
| 1334 | + * @return void |
|
| 1335 | + * @throws EE_Error |
|
| 1336 | + * @throws InvalidArgumentException |
|
| 1337 | + * @throws ReflectionException |
|
| 1338 | + * @throws RuntimeException |
|
| 1339 | + * @throws InvalidDataTypeException |
|
| 1340 | + * @throws InvalidInterfaceException |
|
| 1341 | + */ |
|
| 1342 | + private function _associate_attendee_with_registration(EE_Registration $registration, EE_Attendee $attendee) |
|
| 1343 | + { |
|
| 1344 | + // add relation to attendee |
|
| 1345 | + $registration->_add_relation_to($attendee, 'Attendee'); |
|
| 1346 | + $registration->set_attendee_id($attendee->ID()); |
|
| 1347 | + $registration->update_cache_after_object_save('Attendee', $attendee); |
|
| 1348 | + } |
|
| 1349 | + |
|
| 1350 | + |
|
| 1351 | + /** |
|
| 1352 | + * _associate_registration_with_transaction |
|
| 1353 | + * |
|
| 1354 | + * @param EE_Registration $registration |
|
| 1355 | + * @return void |
|
| 1356 | + * @throws EE_Error |
|
| 1357 | + * @throws InvalidArgumentException |
|
| 1358 | + * @throws ReflectionException |
|
| 1359 | + * @throws InvalidDataTypeException |
|
| 1360 | + * @throws InvalidInterfaceException |
|
| 1361 | + */ |
|
| 1362 | + private function _associate_registration_with_transaction(EE_Registration $registration) |
|
| 1363 | + { |
|
| 1364 | + // add relation to registration |
|
| 1365 | + $this->checkout->transaction->_add_relation_to($registration, 'Registration'); |
|
| 1366 | + $this->checkout->transaction->update_cache_after_object_save('Registration', $registration); |
|
| 1367 | + } |
|
| 1368 | + |
|
| 1369 | + |
|
| 1370 | + /** |
|
| 1371 | + * _copy_critical_attendee_details_from_primary_registrant |
|
| 1372 | + * ensures that all attendees at least have data for first name, last name, and email address |
|
| 1373 | + * |
|
| 1374 | + * @param array $attendee_data |
|
| 1375 | + * @return array |
|
| 1376 | + * @throws EE_Error |
|
| 1377 | + * @throws InvalidArgumentException |
|
| 1378 | + * @throws ReflectionException |
|
| 1379 | + * @throws InvalidDataTypeException |
|
| 1380 | + * @throws InvalidInterfaceException |
|
| 1381 | + */ |
|
| 1382 | + private function _copy_critical_attendee_details_from_primary_registrant($attendee_data = array()) |
|
| 1383 | + { |
|
| 1384 | + // bare minimum critical details include first name, last name, email address |
|
| 1385 | + $critical_attendee_details = array('ATT_fname', 'ATT_lname', 'ATT_email'); |
|
| 1386 | + // add address info to critical details? |
|
| 1387 | + if (apply_filters( |
|
| 1388 | + 'FHEE__EE_SPCO_Reg_Step_Attendee_Information__merge_address_details_with_critical_attendee_details', |
|
| 1389 | + false |
|
| 1390 | + )) { |
|
| 1391 | + $address_details = array( |
|
| 1392 | + 'ATT_address', |
|
| 1393 | + 'ATT_address2', |
|
| 1394 | + 'ATT_city', |
|
| 1395 | + 'STA_ID', |
|
| 1396 | + 'CNT_ISO', |
|
| 1397 | + 'ATT_zip', |
|
| 1398 | + 'ATT_phone', |
|
| 1399 | + ); |
|
| 1400 | + $critical_attendee_details = array_merge($critical_attendee_details, $address_details); |
|
| 1401 | + } |
|
| 1402 | + foreach ($critical_attendee_details as $critical_attendee_detail) { |
|
| 1403 | + if (! isset($attendee_data[ $critical_attendee_detail ]) |
|
| 1404 | + || empty($attendee_data[ $critical_attendee_detail ]) |
|
| 1405 | + ) { |
|
| 1406 | + $attendee_data[ $critical_attendee_detail ] = $this->checkout->primary_attendee_obj->get( |
|
| 1407 | + $critical_attendee_detail |
|
| 1408 | + ); |
|
| 1409 | + } |
|
| 1410 | + } |
|
| 1411 | + return $attendee_data; |
|
| 1412 | + } |
|
| 1413 | + |
|
| 1414 | + |
|
| 1415 | + /** |
|
| 1416 | + * update_reg_step |
|
| 1417 | + * this is the final step after a user revisits the site to edit their attendee information |
|
| 1418 | + * this gets called AFTER the process_reg_step() method above |
|
| 1419 | + * |
|
| 1420 | + * @return bool |
|
| 1421 | + * @throws EE_Error |
|
| 1422 | + * @throws InvalidArgumentException |
|
| 1423 | + * @throws ReflectionException |
|
| 1424 | + * @throws RuntimeException |
|
| 1425 | + * @throws InvalidDataTypeException |
|
| 1426 | + * @throws InvalidInterfaceException |
|
| 1427 | + */ |
|
| 1428 | + public function update_reg_step() |
|
| 1429 | + { |
|
| 1430 | + // save everything |
|
| 1431 | + if ($this->process_reg_step()) { |
|
| 1432 | + $this->checkout->redirect = true; |
|
| 1433 | + $this->checkout->redirect_url = add_query_arg( |
|
| 1434 | + array( |
|
| 1435 | + 'e_reg_url_link' => $this->checkout->reg_url_link, |
|
| 1436 | + 'revisit' => true, |
|
| 1437 | + ), |
|
| 1438 | + $this->checkout->thank_you_page_url |
|
| 1439 | + ); |
|
| 1440 | + $this->checkout->json_response->set_redirect_url($this->checkout->redirect_url); |
|
| 1441 | + return true; |
|
| 1442 | + } |
|
| 1443 | + return false; |
|
| 1444 | + } |
|
| 1445 | 1445 | } |
@@ -49,7 +49,7 @@ discard block |
||
| 49 | 49 | { |
| 50 | 50 | $this->_slug = 'attendee_information'; |
| 51 | 51 | $this->_name = esc_html__('Attendee Information', 'event_espresso'); |
| 52 | - $this->_template = SPCO_REG_STEPS_PATH . $this->_slug . '/attendee_info_main.template.php'; |
|
| 52 | + $this->_template = SPCO_REG_STEPS_PATH.$this->_slug.'/attendee_info_main.template.php'; |
|
| 53 | 53 | $this->checkout = $checkout; |
| 54 | 54 | $this->_reset_success_message(); |
| 55 | 55 | $this->set_instructions( |
@@ -142,7 +142,7 @@ discard block |
||
| 142 | 142 | */ |
| 143 | 143 | $reg_config = LoaderFactory::getLoader()->getShared('EE_Registration_Config'); |
| 144 | 144 | // if this isn't a revisit, and they have the privacy consent box enalbed, add it |
| 145 | - if (! $this->checkout->revisit && $reg_config->isConsentCheckboxEnabled()) { |
|
| 145 | + if ( ! $this->checkout->revisit && $reg_config->isConsentCheckboxEnabled()) { |
|
| 146 | 146 | $extra_inputs_section->add_subsections( |
| 147 | 147 | array( |
| 148 | 148 | 'consent_box' => new EE_Form_Section_Proper( |
@@ -150,7 +150,7 @@ discard block |
||
| 150 | 150 | 'layout_strategy' => |
| 151 | 151 | new EE_Template_Layout( |
| 152 | 152 | array( |
| 153 | - 'input_template_file' => SPCO_REG_STEPS_PATH . $this->_slug . '/privacy_consent.template.php', |
|
| 153 | + 'input_template_file' => SPCO_REG_STEPS_PATH.$this->_slug.'/privacy_consent.template.php', |
|
| 154 | 154 | ) |
| 155 | 155 | ), |
| 156 | 156 | 'subsections' => array( |
@@ -188,13 +188,13 @@ discard block |
||
| 188 | 188 | if ($registration instanceof EE_Registration |
| 189 | 189 | && $this->checkout->visit_allows_processing_of_this_registration($registration) |
| 190 | 190 | ) { |
| 191 | - $subsections[ $registration->reg_url_link() ] = $this->_registrations_reg_form($registration); |
|
| 192 | - if (! $this->checkout->admin_request) { |
|
| 193 | - $template_args['registrations'][ $registration->reg_url_link() ] = $registration; |
|
| 194 | - $template_args['ticket_count'][ $registration->ticket()->ID() ] = isset( |
|
| 195 | - $template_args['ticket_count'][ $registration->ticket()->ID() ] |
|
| 191 | + $subsections[$registration->reg_url_link()] = $this->_registrations_reg_form($registration); |
|
| 192 | + if ( ! $this->checkout->admin_request) { |
|
| 193 | + $template_args['registrations'][$registration->reg_url_link()] = $registration; |
|
| 194 | + $template_args['ticket_count'][$registration->ticket()->ID()] = isset( |
|
| 195 | + $template_args['ticket_count'][$registration->ticket()->ID()] |
|
| 196 | 196 | ) |
| 197 | - ? $template_args['ticket_count'][ $registration->ticket()->ID() ] + 1 |
|
| 197 | + ? $template_args['ticket_count'][$registration->ticket()->ID()] + 1 |
|
| 198 | 198 | : 1; |
| 199 | 199 | $ticket_line_item = EEH_Line_Item::get_line_items_by_object_type_and_IDs( |
| 200 | 200 | $this->checkout->cart->get_grand_total(), |
@@ -204,7 +204,7 @@ discard block |
||
| 204 | 204 | $ticket_line_item = is_array($ticket_line_item) |
| 205 | 205 | ? reset($ticket_line_item) |
| 206 | 206 | : $ticket_line_item; |
| 207 | - $template_args['ticket_line_item'][ $registration->ticket()->ID() ] = |
|
| 207 | + $template_args['ticket_line_item'][$registration->ticket()->ID()] = |
|
| 208 | 208 | $Line_Item_Display->display_line_item($ticket_line_item); |
| 209 | 209 | } |
| 210 | 210 | if ($registration->is_primary_registrant()) { |
@@ -220,10 +220,10 @@ discard block |
||
| 220 | 220 | ? $this->_copy_attendee_info_form() |
| 221 | 221 | : $this->_auto_copy_attendee_info(); |
| 222 | 222 | // generate hidden input |
| 223 | - if (isset($subsections[ $primary_registrant ]) |
|
| 224 | - && $subsections[ $primary_registrant ] instanceof EE_Form_Section_Proper |
|
| 223 | + if (isset($subsections[$primary_registrant]) |
|
| 224 | + && $subsections[$primary_registrant] instanceof EE_Form_Section_Proper |
|
| 225 | 225 | ) { |
| 226 | - $subsections[ $primary_registrant ]->add_subsections( |
|
| 226 | + $subsections[$primary_registrant]->add_subsections( |
|
| 227 | 227 | $copy_options, |
| 228 | 228 | 'primary_registrant', |
| 229 | 229 | false |
@@ -290,7 +290,7 @@ discard block |
||
| 290 | 290 | if ($question_groups) { |
| 291 | 291 | // array of params to pass to parent constructor |
| 292 | 292 | $form_args = array( |
| 293 | - 'html_id' => 'ee-registration-' . $registration->reg_url_link(), |
|
| 293 | + 'html_id' => 'ee-registration-'.$registration->reg_url_link(), |
|
| 294 | 294 | 'html_class' => 'ee-reg-form-attendee-dv', |
| 295 | 295 | 'html_style' => $this->checkout->admin_request |
| 296 | 296 | ? 'padding:0em 2em 1em; margin:3em 0 0; border:1px solid #ddd;' |
@@ -312,7 +312,7 @@ discard block |
||
| 312 | 312 | ); |
| 313 | 313 | foreach ($question_groups as $question_group) { |
| 314 | 314 | if ($question_group instanceof EE_Question_Group) { |
| 315 | - $form_args['subsections'][ $question_group->identifier() ] = $this->_question_group_reg_form( |
|
| 315 | + $form_args['subsections'][$question_group->identifier()] = $this->_question_group_reg_form( |
|
| 316 | 316 | $registration, |
| 317 | 317 | $question_group |
| 318 | 318 | ); |
@@ -352,7 +352,7 @@ discard block |
||
| 352 | 352 | // generate hidden input |
| 353 | 353 | return new EE_Hidden_Input( |
| 354 | 354 | array( |
| 355 | - 'html_id' => 'additional-attendee-reg-info-' . $registration->reg_url_link(), |
|
| 355 | + 'html_id' => 'additional-attendee-reg-info-'.$registration->reg_url_link(), |
|
| 356 | 356 | 'default' => $additional_attendee_reg_info, |
| 357 | 357 | ) |
| 358 | 358 | ); |
@@ -373,12 +373,12 @@ discard block |
||
| 373 | 373 | { |
| 374 | 374 | // array of params to pass to parent constructor |
| 375 | 375 | $form_args = array( |
| 376 | - 'html_id' => 'ee-reg-form-qstn-grp-' . $question_group->identifier() . '-' . $registration->ID(), |
|
| 376 | + 'html_id' => 'ee-reg-form-qstn-grp-'.$question_group->identifier().'-'.$registration->ID(), |
|
| 377 | 377 | 'html_class' => $this->checkout->admin_request |
| 378 | 378 | ? 'form-table ee-reg-form-qstn-grp-dv' |
| 379 | 379 | : 'ee-reg-form-qstn-grp-dv', |
| 380 | - 'html_label_id' => 'ee-reg-form-qstn-grp-' . $question_group->identifier() . '-' |
|
| 381 | - . $registration->ID() . '-lbl', |
|
| 380 | + 'html_label_id' => 'ee-reg-form-qstn-grp-'.$question_group->identifier().'-' |
|
| 381 | + . $registration->ID().'-lbl', |
|
| 382 | 382 | 'subsections' => array( |
| 383 | 383 | 'reg_form_qstn_grp_hdr' => $this->_question_group_header($question_group), |
| 384 | 384 | ), |
@@ -389,7 +389,7 @@ discard block |
||
| 389 | 389 | // where params |
| 390 | 390 | $query_params = array('QST_deleted' => 0); |
| 391 | 391 | // don't load admin only questions on the frontend |
| 392 | - if (! $this->checkout->admin_request) { |
|
| 392 | + if ( ! $this->checkout->admin_request) { |
|
| 393 | 393 | $query_params['QST_admin_only'] = array('!=', true); |
| 394 | 394 | } |
| 395 | 395 | $questions = $question_group->get_many_related( |
@@ -423,7 +423,7 @@ discard block |
||
| 423 | 423 | $identifier = $question->is_system_question() |
| 424 | 424 | ? $question->system_ID() |
| 425 | 425 | : $question->ID(); |
| 426 | - $form_args['subsections'][ $identifier ] = $this->reg_form_question($registration, $question); |
|
| 426 | + $form_args['subsections'][$identifier] = $this->reg_form_question($registration, $question); |
|
| 427 | 427 | } |
| 428 | 428 | } |
| 429 | 429 | $form_args['subsections'] = apply_filters( |
@@ -535,7 +535,7 @@ discard block |
||
| 535 | 535 | { |
| 536 | 536 | return new EE_Form_Section_HTML( |
| 537 | 537 | EEH_Template::locate_template( |
| 538 | - SPCO_REG_STEPS_PATH . $this->_slug . '/_auto_copy_attendee_info.template.php', |
|
| 538 | + SPCO_REG_STEPS_PATH.$this->_slug.'/_auto_copy_attendee_info.template.php', |
|
| 539 | 539 | apply_filters( |
| 540 | 540 | 'FHEE__EE_SPCO_Reg_Step_Attendee_Information__auto_copy_attendee_info__template_args', |
| 541 | 541 | array() |
@@ -568,17 +568,17 @@ discard block |
||
| 568 | 568 | if ($registration->ticket()->ID() !== $prev_ticket) { |
| 569 | 569 | $item_name = $registration->ticket()->name(); |
| 570 | 570 | $item_name .= $registration->ticket()->description() !== '' |
| 571 | - ? ' - ' . $registration->ticket()->description() |
|
| 571 | + ? ' - '.$registration->ticket()->description() |
|
| 572 | 572 | : ''; |
| 573 | - $copy_attendee_info_inputs[ 'spco_copy_attendee_chk[ticket-' . $registration->ticket()->ID( |
|
| 574 | - ) . ']' ] = |
|
| 573 | + $copy_attendee_info_inputs['spco_copy_attendee_chk[ticket-'.$registration->ticket()->ID( |
|
| 574 | + ).']'] = |
|
| 575 | 575 | new EE_Form_Section_HTML( |
| 576 | - '<h6 class="spco-copy-attendee-event-hdr">' . $item_name . '</h6>' |
|
| 576 | + '<h6 class="spco-copy-attendee-event-hdr">'.$item_name.'</h6>' |
|
| 577 | 577 | ); |
| 578 | 578 | $prev_ticket = $registration->ticket()->ID(); |
| 579 | 579 | } |
| 580 | 580 | |
| 581 | - $copy_attendee_info_inputs[ 'spco_copy_attendee_chk[' . $registration->ID() . ']' ] = |
|
| 581 | + $copy_attendee_info_inputs['spco_copy_attendee_chk['.$registration->ID().']'] = |
|
| 582 | 582 | new EE_Checkbox_Multi_Input( |
| 583 | 583 | array( |
| 584 | 584 | $registration->ID() => sprintf( |
@@ -587,7 +587,7 @@ discard block |
||
| 587 | 587 | ), |
| 588 | 588 | ), |
| 589 | 589 | array( |
| 590 | - 'html_id' => 'spco-copy-attendee-chk-' . $registration->reg_url_link(), |
|
| 590 | + 'html_id' => 'spco-copy-attendee-chk-'.$registration->reg_url_link(), |
|
| 591 | 591 | 'html_class' => 'spco-copy-attendee-chk ee-do-not-validate', |
| 592 | 592 | 'display_html_label_text' => false, |
| 593 | 593 | ) |
@@ -652,14 +652,14 @@ discard block |
||
| 652 | 652 | } |
| 653 | 653 | // verify instance |
| 654 | 654 | if ($answer instanceof EE_Answer) { |
| 655 | - if (! empty($answer_value)) { |
|
| 655 | + if ( ! empty($answer_value)) { |
|
| 656 | 656 | $answer->set('ANS_value', $answer_value); |
| 657 | 657 | } |
| 658 | 658 | $answer->cache('Question', $question); |
| 659 | 659 | // remember system ID had a bug where sometimes it could be null |
| 660 | 660 | $answer_cache_id = $question->is_system_question() |
| 661 | - ? $question->system_ID() . '-' . $registration->reg_url_link() |
|
| 662 | - : $question->ID() . '-' . $registration->reg_url_link(); |
|
| 661 | + ? $question->system_ID().'-'.$registration->reg_url_link() |
|
| 662 | + : $question->ID().'-'.$registration->reg_url_link(); |
|
| 663 | 663 | $registration->cache('Answer', $answer, $answer_cache_id); |
| 664 | 664 | } |
| 665 | 665 | return $this->_generate_question_input($registration, $question, $answer); |
@@ -682,7 +682,7 @@ discard block |
||
| 682 | 682 | $identifier = $question->is_system_question() |
| 683 | 683 | ? $question->system_ID() |
| 684 | 684 | : $question->ID(); |
| 685 | - $this->_required_questions[ $identifier ] = $question->required() ? true : false; |
|
| 685 | + $this->_required_questions[$identifier] = $question->required() ? true : false; |
|
| 686 | 686 | add_filter( |
| 687 | 687 | 'FHEE__EE_Question__generate_form_input__country_options', |
| 688 | 688 | array($this, 'use_cached_countries_for_form_input'), |
@@ -696,17 +696,17 @@ discard block |
||
| 696 | 696 | 4 |
| 697 | 697 | ); |
| 698 | 698 | $input_constructor_args = array( |
| 699 | - 'html_name' => 'ee_reg_qstn[' . $registration->ID() . '][' . $identifier . ']', |
|
| 700 | - 'html_id' => 'ee_reg_qstn-' . $registration->ID() . '-' . $identifier, |
|
| 701 | - 'html_class' => 'ee-reg-qstn ee-reg-qstn-' . $identifier, |
|
| 702 | - 'html_label_id' => 'ee_reg_qstn-' . $registration->ID() . '-' . $identifier, |
|
| 699 | + 'html_name' => 'ee_reg_qstn['.$registration->ID().']['.$identifier.']', |
|
| 700 | + 'html_id' => 'ee_reg_qstn-'.$registration->ID().'-'.$identifier, |
|
| 701 | + 'html_class' => 'ee-reg-qstn ee-reg-qstn-'.$identifier, |
|
| 702 | + 'html_label_id' => 'ee_reg_qstn-'.$registration->ID().'-'.$identifier, |
|
| 703 | 703 | 'html_label_class' => 'ee-reg-qstn', |
| 704 | 704 | ); |
| 705 | 705 | $input_constructor_args['html_label_id'] .= '-lbl'; |
| 706 | 706 | if ($answer instanceof EE_Answer && $answer->ID()) { |
| 707 | - $input_constructor_args['html_name'] .= '[' . $answer->ID() . ']'; |
|
| 708 | - $input_constructor_args['html_id'] .= '-' . $answer->ID(); |
|
| 709 | - $input_constructor_args['html_label_id'] .= '-' . $answer->ID(); |
|
| 707 | + $input_constructor_args['html_name'] .= '['.$answer->ID().']'; |
|
| 708 | + $input_constructor_args['html_id'] .= '-'.$answer->ID(); |
|
| 709 | + $input_constructor_args['html_label_id'] .= '-'.$answer->ID(); |
|
| 710 | 710 | } |
| 711 | 711 | $form_input = $question->generate_form_input( |
| 712 | 712 | $registration, |
@@ -750,10 +750,10 @@ discard block |
||
| 750 | 750 | $countries = $this->checkout->action === 'process_reg_step' |
| 751 | 751 | ? EEM_Country::instance()->get_all_countries() |
| 752 | 752 | : EEM_Country::instance()->get_all_active_countries(); |
| 753 | - if (! empty($countries)) { |
|
| 753 | + if ( ! empty($countries)) { |
|
| 754 | 754 | foreach ($countries as $country) { |
| 755 | 755 | if ($country instanceof EE_Country) { |
| 756 | - $country_options[ $country->ID() ] = $country->name(); |
|
| 756 | + $country_options[$country->ID()] = $country->name(); |
|
| 757 | 757 | } |
| 758 | 758 | } |
| 759 | 759 | } |
@@ -800,10 +800,10 @@ discard block |
||
| 800 | 800 | $states = $this->checkout->action === 'process_reg_step' |
| 801 | 801 | ? EEM_State::instance()->get_all_states() |
| 802 | 802 | : EEM_State::instance()->get_all_active_states(); |
| 803 | - if (! empty($states)) { |
|
| 803 | + if ( ! empty($states)) { |
|
| 804 | 804 | foreach ($states as $state) { |
| 805 | 805 | if ($state instanceof EE_State) { |
| 806 | - $state_options[ $state->country()->name() ][ $state->ID() ] = $state->name(); |
|
| 806 | + $state_options[$state->country()->name()][$state->ID()] = $state->name(); |
|
| 807 | 807 | } |
| 808 | 808 | } |
| 809 | 809 | } |
@@ -850,7 +850,7 @@ discard block |
||
| 850 | 850 | ); |
| 851 | 851 | return false; |
| 852 | 852 | } |
| 853 | - if (! $this->checkout->transaction instanceof EE_Transaction || ! $this->checkout->continue_reg) { |
|
| 853 | + if ( ! $this->checkout->transaction instanceof EE_Transaction || ! $this->checkout->continue_reg) { |
|
| 854 | 854 | EE_Error::add_error( |
| 855 | 855 | esc_html__( |
| 856 | 856 | 'A valid transaction could not be initiated for processing your registrations.', |
@@ -877,7 +877,7 @@ discard block |
||
| 877 | 877 | '(line break)This can sometimes happen if too much time has been taken to complete the registration process.(line break)Please return to the (link)Event List(end link) and reselect your tickets. If the problem continues, please contact the site administrator.', |
| 878 | 878 | 'event_espresso' |
| 879 | 879 | ), |
| 880 | - '<a href="' . get_post_type_archive_link('espresso_events') . '" >', |
|
| 880 | + '<a href="'.get_post_type_archive_link('espresso_events').'" >', |
|
| 881 | 881 | '</a>', |
| 882 | 882 | '<br />' |
| 883 | 883 | ); |
@@ -897,7 +897,7 @@ discard block |
||
| 897 | 897 | // but return immediately if the previous step exited early due to errors |
| 898 | 898 | return false; |
| 899 | 899 | } |
| 900 | - if (! $this->checkout->revisit && $registrations_processed !== $this->checkout->total_ticket_count) { |
|
| 900 | + if ( ! $this->checkout->revisit && $registrations_processed !== $this->checkout->total_ticket_count) { |
|
| 901 | 901 | // generate a correctly translated string for all possible singular/plural combinations |
| 902 | 902 | if ($this->checkout->total_ticket_count === 1 && $registrations_processed !== 1) { |
| 903 | 903 | $error_msg = sprintf( |
@@ -980,7 +980,7 @@ discard block |
||
| 980 | 980 | // grab the saved registrations from the transaction |
| 981 | 981 | foreach ($registrations as $registration) { |
| 982 | 982 | // verify EE_Registration object |
| 983 | - if (! $registration instanceof EE_Registration) { |
|
| 983 | + if ( ! $registration instanceof EE_Registration) { |
|
| 984 | 984 | EE_Error::add_error( |
| 985 | 985 | esc_html__( |
| 986 | 986 | 'An invalid Registration object was discovered when attempting to process your registration information.', |
@@ -995,12 +995,12 @@ discard block |
||
| 995 | 995 | /** @var string $reg_url_link */ |
| 996 | 996 | $reg_url_link = $registration->reg_url_link(); |
| 997 | 997 | // reg_url_link exists ? |
| 998 | - if (! empty($reg_url_link)) { |
|
| 998 | + if ( ! empty($reg_url_link)) { |
|
| 999 | 999 | // should this registration be processed during this visit ? |
| 1000 | 1000 | if ($this->checkout->visit_allows_processing_of_this_registration($registration)) { |
| 1001 | 1001 | // if NOT revisiting, then let's save the registration now, |
| 1002 | 1002 | // so that we have a REG_ID to use when generating other objects |
| 1003 | - if (! $this->checkout->revisit) { |
|
| 1003 | + if ( ! $this->checkout->revisit) { |
|
| 1004 | 1004 | $registration->save(); |
| 1005 | 1005 | } |
| 1006 | 1006 | /** |
@@ -1024,18 +1024,18 @@ discard block |
||
| 1024 | 1024 | |
| 1025 | 1025 | // Houston, we have a registration! |
| 1026 | 1026 | $att_nmbr++; |
| 1027 | - $this->_attendee_data[ $reg_url_link ] = array(); |
|
| 1027 | + $this->_attendee_data[$reg_url_link] = array(); |
|
| 1028 | 1028 | // grab any existing related answer objects |
| 1029 | 1029 | $this->_registration_answers = $registration->answers(); |
| 1030 | 1030 | // unset( $valid_data[ $reg_url_link ]['additional_attendee_reg_info'] ); |
| 1031 | - if (isset($valid_data[ $reg_url_link ])) { |
|
| 1031 | + if (isset($valid_data[$reg_url_link])) { |
|
| 1032 | 1032 | // do we need to copy basic info from primary attendee ? |
| 1033 | - $copy_primary = isset($valid_data[ $reg_url_link ]['additional_attendee_reg_info']) |
|
| 1034 | - && absint($valid_data[ $reg_url_link ]['additional_attendee_reg_info']) === 0; |
|
| 1033 | + $copy_primary = isset($valid_data[$reg_url_link]['additional_attendee_reg_info']) |
|
| 1034 | + && absint($valid_data[$reg_url_link]['additional_attendee_reg_info']) === 0; |
|
| 1035 | 1035 | // filter form input data for this registration |
| 1036 | - $valid_data[ $reg_url_link ] = (array) apply_filters( |
|
| 1036 | + $valid_data[$reg_url_link] = (array) apply_filters( |
|
| 1037 | 1037 | 'FHEE__EE_Single_Page_Checkout__process_attendee_information__valid_data_line_item', |
| 1038 | - $valid_data[ $reg_url_link ] |
|
| 1038 | + $valid_data[$reg_url_link] |
|
| 1039 | 1039 | ); |
| 1040 | 1040 | if (isset($valid_data['primary_attendee'])) { |
| 1041 | 1041 | $primary_registrant['line_item_id'] = ! empty($valid_data['primary_attendee']) |
@@ -1044,12 +1044,12 @@ discard block |
||
| 1044 | 1044 | unset($valid_data['primary_attendee']); |
| 1045 | 1045 | } |
| 1046 | 1046 | // now loop through our array of valid post data && process attendee reg forms |
| 1047 | - foreach ($valid_data[ $reg_url_link ] as $form_section => $form_inputs) { |
|
| 1048 | - if (! in_array($form_section, $non_input_form_sections, true)) { |
|
| 1047 | + foreach ($valid_data[$reg_url_link] as $form_section => $form_inputs) { |
|
| 1048 | + if ( ! in_array($form_section, $non_input_form_sections, true)) { |
|
| 1049 | 1049 | foreach ($form_inputs as $form_input => $input_value) { |
| 1050 | 1050 | // \EEH_Debug_Tools::printr( $input_value, $form_input, __FILE__, __LINE__ ); |
| 1051 | 1051 | // check for critical inputs |
| 1052 | - if (! $this->_verify_critical_attendee_details_are_set_and_validate_email( |
|
| 1052 | + if ( ! $this->_verify_critical_attendee_details_are_set_and_validate_email( |
|
| 1053 | 1053 | $form_input, |
| 1054 | 1054 | $input_value |
| 1055 | 1055 | ) |
@@ -1061,15 +1061,15 @@ discard block |
||
| 1061 | 1061 | && ! empty($input_value) |
| 1062 | 1062 | && $reg_url_link === $primary_registrant['line_item_id'] |
| 1063 | 1063 | ) { |
| 1064 | - $primary_registrant[ $form_input ] = $input_value; |
|
| 1064 | + $primary_registrant[$form_input] = $input_value; |
|
| 1065 | 1065 | } elseif ($copy_primary |
| 1066 | 1066 | && $input_value === null |
| 1067 | - && isset($primary_registrant[ $form_input ]) |
|
| 1067 | + && isset($primary_registrant[$form_input]) |
|
| 1068 | 1068 | ) { |
| 1069 | - $input_value = $primary_registrant[ $form_input ]; |
|
| 1069 | + $input_value = $primary_registrant[$form_input]; |
|
| 1070 | 1070 | } |
| 1071 | 1071 | // now attempt to save the input data |
| 1072 | - if (! $this->_save_registration_form_input( |
|
| 1072 | + if ( ! $this->_save_registration_form_input( |
|
| 1073 | 1073 | $registration, |
| 1074 | 1074 | $form_input, |
| 1075 | 1075 | $input_value |
@@ -1105,15 +1105,15 @@ discard block |
||
| 1105 | 1105 | $attendee = $this->checkout->primary_attendee_obj; |
| 1106 | 1106 | } else { |
| 1107 | 1107 | // ensure critical details are set for additional attendees |
| 1108 | - $this->_attendee_data[ $reg_url_link ] = $att_nmbr > 1 |
|
| 1108 | + $this->_attendee_data[$reg_url_link] = $att_nmbr > 1 |
|
| 1109 | 1109 | ? $this->_copy_critical_attendee_details_from_primary_registrant( |
| 1110 | - $this->_attendee_data[ $reg_url_link ] |
|
| 1110 | + $this->_attendee_data[$reg_url_link] |
|
| 1111 | 1111 | ) |
| 1112 | - : $this->_attendee_data[ $reg_url_link ]; |
|
| 1112 | + : $this->_attendee_data[$reg_url_link]; |
|
| 1113 | 1113 | // execute create attendee command (which may return an existing attendee) |
| 1114 | 1114 | $attendee = EE_Registry::instance()->BUS->execute( |
| 1115 | 1115 | new CreateAttendeeCommand( |
| 1116 | - $this->_attendee_data[ $reg_url_link ], |
|
| 1116 | + $this->_attendee_data[$reg_url_link], |
|
| 1117 | 1117 | $registration |
| 1118 | 1118 | ) |
| 1119 | 1119 | ); |
@@ -1126,7 +1126,7 @@ discard block |
||
| 1126 | 1126 | // add relation to registration, set attendee ID, and cache attendee |
| 1127 | 1127 | $this->_associate_attendee_with_registration($registration, $attendee); |
| 1128 | 1128 | // \EEH_Debug_Tools::printr( $registration, '$registration', __FILE__, __LINE__ ); |
| 1129 | - if (! $registration->attendee() instanceof EE_Attendee) { |
|
| 1129 | + if ( ! $registration->attendee() instanceof EE_Attendee) { |
|
| 1130 | 1130 | EE_Error::add_error( |
| 1131 | 1131 | sprintf( |
| 1132 | 1132 | esc_html_x( |
@@ -1176,7 +1176,7 @@ discard block |
||
| 1176 | 1176 | __LINE__ |
| 1177 | 1177 | ); |
| 1178 | 1178 | // remove malformed data |
| 1179 | - unset($valid_data[ $reg_url_link ]); |
|
| 1179 | + unset($valid_data[$reg_url_link]); |
|
| 1180 | 1180 | return false; |
| 1181 | 1181 | } |
| 1182 | 1182 | } // end of foreach ( $this->checkout->transaction->registrations() as $registration ) |
@@ -1222,10 +1222,10 @@ discard block |
||
| 1222 | 1222 | * @see https://events.codebasehq.com/projects/event-espresso/tickets/10477 |
| 1223 | 1223 | */ |
| 1224 | 1224 | $answer_cache_id = $this->checkout->reg_url_link |
| 1225 | - ? $form_input . '-' . $registration->reg_url_link() |
|
| 1225 | + ? $form_input.'-'.$registration->reg_url_link() |
|
| 1226 | 1226 | : $form_input; |
| 1227 | - $answer_is_obj = isset($this->_registration_answers[ $answer_cache_id ]) |
|
| 1228 | - && $this->_registration_answers[ $answer_cache_id ] instanceof EE_Answer; |
|
| 1227 | + $answer_is_obj = isset($this->_registration_answers[$answer_cache_id]) |
|
| 1228 | + && $this->_registration_answers[$answer_cache_id] instanceof EE_Answer; |
|
| 1229 | 1229 | // rename form_inputs if they are EE_Attendee properties |
| 1230 | 1230 | switch ((string) $form_input) { |
| 1231 | 1231 | case 'state': |
@@ -1241,28 +1241,28 @@ discard block |
||
| 1241 | 1241 | break; |
| 1242 | 1242 | |
| 1243 | 1243 | default: |
| 1244 | - $ATT_input = 'ATT_' . $form_input; |
|
| 1244 | + $ATT_input = 'ATT_'.$form_input; |
|
| 1245 | 1245 | // EEH_Debug_Tools::printr( $ATT_input, '$ATT_input', __FILE__, __LINE__ ); |
| 1246 | 1246 | $attendee_property = EEM_Attendee::instance()->has_field($ATT_input) ? true : false; |
| 1247 | - $form_input = $attendee_property ? 'ATT_' . $form_input : $form_input; |
|
| 1247 | + $form_input = $attendee_property ? 'ATT_'.$form_input : $form_input; |
|
| 1248 | 1248 | } |
| 1249 | 1249 | // EEH_Debug_Tools::printr( $answer_cache_id, '$answer_cache_id', __FILE__, __LINE__ ); |
| 1250 | 1250 | // EEH_Debug_Tools::printr( $attendee_property, '$attendee_property', __FILE__, __LINE__ ); |
| 1251 | 1251 | // EEH_Debug_Tools::printr( $answer_is_obj, '$answer_is_obj', __FILE__, __LINE__ ); |
| 1252 | 1252 | // if this form input has a corresponding attendee property |
| 1253 | 1253 | if ($attendee_property) { |
| 1254 | - $this->_attendee_data[ $registration->reg_url_link() ][ $form_input ] = $input_value; |
|
| 1254 | + $this->_attendee_data[$registration->reg_url_link()][$form_input] = $input_value; |
|
| 1255 | 1255 | if ($answer_is_obj) { |
| 1256 | 1256 | // and delete the corresponding answer since we won't be storing this data in that object |
| 1257 | - $registration->_remove_relation_to($this->_registration_answers[ $answer_cache_id ], 'Answer'); |
|
| 1258 | - $this->_registration_answers[ $answer_cache_id ]->delete_permanently(); |
|
| 1257 | + $registration->_remove_relation_to($this->_registration_answers[$answer_cache_id], 'Answer'); |
|
| 1258 | + $this->_registration_answers[$answer_cache_id]->delete_permanently(); |
|
| 1259 | 1259 | } |
| 1260 | 1260 | return true; |
| 1261 | 1261 | } |
| 1262 | 1262 | if ($answer_is_obj) { |
| 1263 | 1263 | // save this data to the answer object |
| 1264 | - $this->_registration_answers[ $answer_cache_id ]->set_value($input_value); |
|
| 1265 | - $result = $this->_registration_answers[ $answer_cache_id ]->save(); |
|
| 1264 | + $this->_registration_answers[$answer_cache_id]->set_value($input_value); |
|
| 1265 | + $result = $this->_registration_answers[$answer_cache_id]->save(); |
|
| 1266 | 1266 | return $result !== false; |
| 1267 | 1267 | } |
| 1268 | 1268 | foreach ($this->_registration_answers as $answer) { |
@@ -1289,7 +1289,7 @@ discard block |
||
| 1289 | 1289 | ) { |
| 1290 | 1290 | if (empty($input_value)) { |
| 1291 | 1291 | // if the form input isn't marked as being required, then just return |
| 1292 | - if (! isset($this->_required_questions[ $form_input ]) || ! $this->_required_questions[ $form_input ]) { |
|
| 1292 | + if ( ! isset($this->_required_questions[$form_input]) || ! $this->_required_questions[$form_input]) { |
|
| 1293 | 1293 | return true; |
| 1294 | 1294 | } |
| 1295 | 1295 | switch ($form_input) { |
@@ -1400,10 +1400,10 @@ discard block |
||
| 1400 | 1400 | $critical_attendee_details = array_merge($critical_attendee_details, $address_details); |
| 1401 | 1401 | } |
| 1402 | 1402 | foreach ($critical_attendee_details as $critical_attendee_detail) { |
| 1403 | - if (! isset($attendee_data[ $critical_attendee_detail ]) |
|
| 1404 | - || empty($attendee_data[ $critical_attendee_detail ]) |
|
| 1403 | + if ( ! isset($attendee_data[$critical_attendee_detail]) |
|
| 1404 | + || empty($attendee_data[$critical_attendee_detail]) |
|
| 1405 | 1405 | ) { |
| 1406 | - $attendee_data[ $critical_attendee_detail ] = $this->checkout->primary_attendee_obj->get( |
|
| 1406 | + $attendee_data[$critical_attendee_detail] = $this->checkout->primary_attendee_obj->get( |
|
| 1407 | 1407 | $critical_attendee_detail |
| 1408 | 1408 | ); |
| 1409 | 1409 | } |
@@ -12,2889 +12,2889 @@ |
||
| 12 | 12 | class EE_SPCO_Reg_Step_Payment_Options extends EE_SPCO_Reg_Step |
| 13 | 13 | { |
| 14 | 14 | |
| 15 | - /** |
|
| 16 | - * @access protected |
|
| 17 | - * @var EE_Line_Item_Display $Line_Item_Display |
|
| 18 | - */ |
|
| 19 | - protected $line_item_display; |
|
| 20 | - |
|
| 21 | - /** |
|
| 22 | - * @access protected |
|
| 23 | - * @var boolean $handle_IPN_in_this_request |
|
| 24 | - */ |
|
| 25 | - protected $handle_IPN_in_this_request = false; |
|
| 26 | - |
|
| 27 | - |
|
| 28 | - /** |
|
| 29 | - * set_hooks - for hooking into EE Core, other modules, etc |
|
| 30 | - * |
|
| 31 | - * @access public |
|
| 32 | - * @return void |
|
| 33 | - */ |
|
| 34 | - public static function set_hooks() |
|
| 35 | - { |
|
| 36 | - add_filter( |
|
| 37 | - 'FHEE__SPCO__EE_Line_Item_Filter_Collection', |
|
| 38 | - array('EE_SPCO_Reg_Step_Payment_Options', 'add_spco_line_item_filters') |
|
| 39 | - ); |
|
| 40 | - add_action( |
|
| 41 | - 'wp_ajax_switch_spco_billing_form', |
|
| 42 | - array('EE_SPCO_Reg_Step_Payment_Options', 'switch_spco_billing_form') |
|
| 43 | - ); |
|
| 44 | - add_action( |
|
| 45 | - 'wp_ajax_nopriv_switch_spco_billing_form', |
|
| 46 | - array('EE_SPCO_Reg_Step_Payment_Options', 'switch_spco_billing_form') |
|
| 47 | - ); |
|
| 48 | - add_action('wp_ajax_save_payer_details', array('EE_SPCO_Reg_Step_Payment_Options', 'save_payer_details')); |
|
| 49 | - add_action( |
|
| 50 | - 'wp_ajax_nopriv_save_payer_details', |
|
| 51 | - array('EE_SPCO_Reg_Step_Payment_Options', 'save_payer_details') |
|
| 52 | - ); |
|
| 53 | - add_action( |
|
| 54 | - 'wp_ajax_get_transaction_details_for_gateways', |
|
| 55 | - array('EE_SPCO_Reg_Step_Payment_Options', 'get_transaction_details') |
|
| 56 | - ); |
|
| 57 | - add_action( |
|
| 58 | - 'wp_ajax_nopriv_get_transaction_details_for_gateways', |
|
| 59 | - array('EE_SPCO_Reg_Step_Payment_Options', 'get_transaction_details') |
|
| 60 | - ); |
|
| 61 | - add_filter( |
|
| 62 | - 'FHEE__EED_Recaptcha___bypass_recaptcha__bypass_request_params_array', |
|
| 63 | - array('EE_SPCO_Reg_Step_Payment_Options', 'bypass_recaptcha_for_load_payment_method'), |
|
| 64 | - 10, |
|
| 65 | - 1 |
|
| 66 | - ); |
|
| 67 | - } |
|
| 68 | - |
|
| 69 | - |
|
| 70 | - /** |
|
| 71 | - * ajax switch_spco_billing_form |
|
| 72 | - * |
|
| 73 | - * @throws \EE_Error |
|
| 74 | - */ |
|
| 75 | - public static function switch_spco_billing_form() |
|
| 76 | - { |
|
| 77 | - EED_Single_Page_Checkout::process_ajax_request('switch_payment_method'); |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - |
|
| 81 | - /** |
|
| 82 | - * ajax save_payer_details |
|
| 83 | - * |
|
| 84 | - * @throws \EE_Error |
|
| 85 | - */ |
|
| 86 | - public static function save_payer_details() |
|
| 87 | - { |
|
| 88 | - EED_Single_Page_Checkout::process_ajax_request('save_payer_details_via_ajax'); |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - |
|
| 92 | - /** |
|
| 93 | - * ajax get_transaction_details |
|
| 94 | - * |
|
| 95 | - * @throws \EE_Error |
|
| 96 | - */ |
|
| 97 | - public static function get_transaction_details() |
|
| 98 | - { |
|
| 99 | - EED_Single_Page_Checkout::process_ajax_request('get_transaction_details_for_gateways'); |
|
| 100 | - } |
|
| 101 | - |
|
| 102 | - |
|
| 103 | - /** |
|
| 104 | - * bypass_recaptcha_for_load_payment_method |
|
| 105 | - * |
|
| 106 | - * @access public |
|
| 107 | - * @return array |
|
| 108 | - * @throws InvalidArgumentException |
|
| 109 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 110 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 111 | - */ |
|
| 112 | - public static function bypass_recaptcha_for_load_payment_method() |
|
| 113 | - { |
|
| 114 | - return array( |
|
| 115 | - 'EESID' => EE_Registry::instance()->SSN->id(), |
|
| 116 | - 'step' => 'payment_options', |
|
| 117 | - 'action' => 'spco_billing_form', |
|
| 118 | - ); |
|
| 119 | - } |
|
| 120 | - |
|
| 121 | - |
|
| 122 | - /** |
|
| 123 | - * class constructor |
|
| 124 | - * |
|
| 125 | - * @access public |
|
| 126 | - * @param EE_Checkout $checkout |
|
| 127 | - */ |
|
| 128 | - public function __construct(EE_Checkout $checkout) |
|
| 129 | - { |
|
| 130 | - $this->_slug = 'payment_options'; |
|
| 131 | - $this->_name = esc_html__('Payment Options', 'event_espresso'); |
|
| 132 | - $this->_template = SPCO_REG_STEPS_PATH . $this->_slug . '/payment_options_main.template.php'; |
|
| 133 | - $this->checkout = $checkout; |
|
| 134 | - $this->_reset_success_message(); |
|
| 135 | - $this->set_instructions( |
|
| 136 | - esc_html__( |
|
| 137 | - 'Please select a method of payment and provide any necessary billing information before proceeding.', |
|
| 138 | - 'event_espresso' |
|
| 139 | - ) |
|
| 140 | - ); |
|
| 141 | - } |
|
| 142 | - |
|
| 143 | - |
|
| 144 | - /** |
|
| 145 | - * @return null |
|
| 146 | - */ |
|
| 147 | - public function line_item_display() |
|
| 148 | - { |
|
| 149 | - return $this->line_item_display; |
|
| 150 | - } |
|
| 151 | - |
|
| 152 | - |
|
| 153 | - /** |
|
| 154 | - * @param null $line_item_display |
|
| 155 | - */ |
|
| 156 | - public function set_line_item_display($line_item_display) |
|
| 157 | - { |
|
| 158 | - $this->line_item_display = $line_item_display; |
|
| 159 | - } |
|
| 160 | - |
|
| 161 | - |
|
| 162 | - /** |
|
| 163 | - * @return boolean |
|
| 164 | - */ |
|
| 165 | - public function handle_IPN_in_this_request() |
|
| 166 | - { |
|
| 167 | - return $this->handle_IPN_in_this_request; |
|
| 168 | - } |
|
| 169 | - |
|
| 170 | - |
|
| 171 | - /** |
|
| 172 | - * @param boolean $handle_IPN_in_this_request |
|
| 173 | - */ |
|
| 174 | - public function set_handle_IPN_in_this_request($handle_IPN_in_this_request) |
|
| 175 | - { |
|
| 176 | - $this->handle_IPN_in_this_request = filter_var($handle_IPN_in_this_request, FILTER_VALIDATE_BOOLEAN); |
|
| 177 | - } |
|
| 178 | - |
|
| 179 | - |
|
| 180 | - /** |
|
| 181 | - * translate_js_strings |
|
| 182 | - * |
|
| 183 | - * @return void |
|
| 184 | - */ |
|
| 185 | - public function translate_js_strings() |
|
| 186 | - { |
|
| 187 | - EE_Registry::$i18n_js_strings['no_payment_method'] = esc_html__( |
|
| 188 | - 'Please select a method of payment in order to continue.', |
|
| 189 | - 'event_espresso' |
|
| 190 | - ); |
|
| 191 | - EE_Registry::$i18n_js_strings['invalid_payment_method'] = esc_html__( |
|
| 192 | - 'A valid method of payment could not be determined. Please refresh the page and try again.', |
|
| 193 | - 'event_espresso' |
|
| 194 | - ); |
|
| 195 | - EE_Registry::$i18n_js_strings['forwarding_to_offsite'] = esc_html__( |
|
| 196 | - 'Forwarding to Secure Payment Provider.', |
|
| 197 | - 'event_espresso' |
|
| 198 | - ); |
|
| 199 | - } |
|
| 200 | - |
|
| 201 | - |
|
| 202 | - /** |
|
| 203 | - * enqueue_styles_and_scripts |
|
| 204 | - * |
|
| 205 | - * @return void |
|
| 206 | - * @throws EE_Error |
|
| 207 | - * @throws InvalidArgumentException |
|
| 208 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 209 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 210 | - */ |
|
| 211 | - public function enqueue_styles_and_scripts() |
|
| 212 | - { |
|
| 213 | - $transaction = $this->checkout->transaction; |
|
| 214 | - // if the transaction isn't set or nothing is owed on it, don't enqueue any JS |
|
| 215 | - if (! $transaction instanceof EE_Transaction || EEH_Money::compare_floats($transaction->remaining(), 0)) { |
|
| 216 | - return; |
|
| 217 | - } |
|
| 218 | - foreach (EEM_Payment_Method::instance()->get_all_for_transaction( |
|
| 219 | - $transaction, |
|
| 220 | - EEM_Payment_Method::scope_cart |
|
| 221 | - ) as $payment_method) { |
|
| 222 | - $type_obj = $payment_method->type_obj(); |
|
| 223 | - if ($type_obj instanceof EE_PMT_Base) { |
|
| 224 | - $billing_form = $type_obj->generate_new_billing_form($transaction); |
|
| 225 | - if ($billing_form instanceof EE_Form_Section_Proper) { |
|
| 226 | - $billing_form->enqueue_js(); |
|
| 227 | - } |
|
| 228 | - } |
|
| 229 | - } |
|
| 230 | - } |
|
| 231 | - |
|
| 232 | - |
|
| 233 | - /** |
|
| 234 | - * initialize_reg_step |
|
| 235 | - * |
|
| 236 | - * @return bool |
|
| 237 | - * @throws EE_Error |
|
| 238 | - * @throws InvalidArgumentException |
|
| 239 | - * @throws ReflectionException |
|
| 240 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 241 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 242 | - */ |
|
| 243 | - public function initialize_reg_step() |
|
| 244 | - { |
|
| 245 | - // TODO: if /when we implement donations, then this will need overriding |
|
| 246 | - if (// don't need payment options for: |
|
| 247 | - // registrations made via the admin |
|
| 248 | - // completed transactions |
|
| 249 | - // overpaid transactions |
|
| 250 | - // $ 0.00 transactions(no payment required) |
|
| 251 | - ! $this->checkout->payment_required() |
|
| 252 | - // but do NOT remove if current action being called belongs to this reg step |
|
| 253 | - && ! is_callable(array($this, $this->checkout->action)) |
|
| 254 | - && ! $this->completed() |
|
| 255 | - ) { |
|
| 256 | - // and if so, then we no longer need the Payment Options step |
|
| 257 | - if ($this->is_current_step()) { |
|
| 258 | - $this->checkout->generate_reg_form = false; |
|
| 259 | - } |
|
| 260 | - $this->checkout->remove_reg_step($this->_slug); |
|
| 261 | - // DEBUG LOG |
|
| 262 | - // $this->checkout->log( __CLASS__, __FUNCTION__, __LINE__ ); |
|
| 263 | - return false; |
|
| 264 | - } |
|
| 265 | - // load EEM_Payment_Method |
|
| 266 | - EE_Registry::instance()->load_model('Payment_Method'); |
|
| 267 | - // get all active payment methods |
|
| 268 | - $this->checkout->available_payment_methods = EEM_Payment_Method::instance()->get_all_for_transaction( |
|
| 269 | - $this->checkout->transaction, |
|
| 270 | - EEM_Payment_Method::scope_cart |
|
| 271 | - ); |
|
| 272 | - return true; |
|
| 273 | - } |
|
| 274 | - |
|
| 275 | - |
|
| 276 | - /** |
|
| 277 | - * @return EE_Form_Section_Proper |
|
| 278 | - * @throws EE_Error |
|
| 279 | - * @throws InvalidArgumentException |
|
| 280 | - * @throws ReflectionException |
|
| 281 | - * @throws \EventEspresso\core\exceptions\EntityNotFoundException |
|
| 282 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 283 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 284 | - * @throws \EventEspresso\core\exceptions\InvalidStatusException |
|
| 285 | - */ |
|
| 286 | - public function generate_reg_form() |
|
| 287 | - { |
|
| 288 | - // reset in case someone changes their mind |
|
| 289 | - $this->_reset_selected_method_of_payment(); |
|
| 290 | - // set some defaults |
|
| 291 | - $this->checkout->selected_method_of_payment = 'payments_closed'; |
|
| 292 | - $registrations_requiring_payment = array(); |
|
| 293 | - $registrations_for_free_events = array(); |
|
| 294 | - $registrations_requiring_pre_approval = array(); |
|
| 295 | - $sold_out_events = array(); |
|
| 296 | - $insufficient_spaces_available = array(); |
|
| 297 | - $no_payment_required = true; |
|
| 298 | - // loop thru registrations to gather info |
|
| 299 | - $registrations = $this->checkout->transaction->registrations($this->checkout->reg_cache_where_params); |
|
| 300 | - $ejected_registrations = EE_SPCO_Reg_Step_Payment_Options::find_registrations_that_lost_their_space( |
|
| 301 | - $registrations, |
|
| 302 | - $this->checkout->revisit |
|
| 303 | - ); |
|
| 304 | - foreach ($registrations as $REG_ID => $registration) { |
|
| 305 | - /** @var $registration EE_Registration */ |
|
| 306 | - // has this registration lost it's space ? |
|
| 307 | - if (isset($ejected_registrations[ $REG_ID ])) { |
|
| 308 | - if ($registration->event()->is_sold_out() || $registration->event()->is_sold_out(true)) { |
|
| 309 | - $sold_out_events[ $registration->event()->ID() ] = $registration->event(); |
|
| 310 | - } else { |
|
| 311 | - $insufficient_spaces_available[ $registration->event()->ID() ] = $registration->event(); |
|
| 312 | - } |
|
| 313 | - continue; |
|
| 314 | - } |
|
| 315 | - // event requires admin approval |
|
| 316 | - if ($registration->status_ID() === EEM_Registration::status_id_not_approved) { |
|
| 317 | - // add event to list of events with pre-approval reg status |
|
| 318 | - $registrations_requiring_pre_approval[ $REG_ID ] = $registration; |
|
| 319 | - do_action( |
|
| 320 | - 'AHEE__EE_SPCO_Reg_Step_Payment_Options__generate_reg_form__event_requires_pre_approval', |
|
| 321 | - $registration->event(), |
|
| 322 | - $this |
|
| 323 | - ); |
|
| 324 | - continue; |
|
| 325 | - } |
|
| 326 | - if ($this->checkout->revisit |
|
| 327 | - && $registration->status_ID() !== EEM_Registration::status_id_approved |
|
| 328 | - && ( |
|
| 329 | - $registration->event()->is_sold_out() |
|
| 330 | - || $registration->event()->is_sold_out(true) |
|
| 331 | - ) |
|
| 332 | - ) { |
|
| 333 | - // add event to list of events that are sold out |
|
| 334 | - $sold_out_events[ $registration->event()->ID() ] = $registration->event(); |
|
| 335 | - do_action( |
|
| 336 | - 'AHEE__EE_SPCO_Reg_Step_Payment_Options__generate_reg_form__sold_out_event', |
|
| 337 | - $registration->event(), |
|
| 338 | - $this |
|
| 339 | - ); |
|
| 340 | - continue; |
|
| 341 | - } |
|
| 342 | - // are they allowed to pay now and is there monies owing? |
|
| 343 | - if ($registration->owes_monies_and_can_pay()) { |
|
| 344 | - $registrations_requiring_payment[ $REG_ID ] = $registration; |
|
| 345 | - do_action( |
|
| 346 | - 'AHEE__EE_SPCO_Reg_Step_Payment_Options__generate_reg_form__event_requires_payment', |
|
| 347 | - $registration->event(), |
|
| 348 | - $this |
|
| 349 | - ); |
|
| 350 | - } elseif (! $this->checkout->revisit |
|
| 351 | - && $registration->status_ID() !== EEM_Registration::status_id_not_approved |
|
| 352 | - && $registration->ticket()->is_free() |
|
| 353 | - ) { |
|
| 354 | - $registrations_for_free_events[ $registration->ticket()->ID() ] = $registration; |
|
| 355 | - } |
|
| 356 | - } |
|
| 357 | - $subsections = array(); |
|
| 358 | - // now decide which template to load |
|
| 359 | - if (! empty($sold_out_events)) { |
|
| 360 | - $subsections['sold_out_events'] = $this->_sold_out_events($sold_out_events); |
|
| 361 | - } |
|
| 362 | - if (! empty($insufficient_spaces_available)) { |
|
| 363 | - $subsections['insufficient_space'] = $this->_insufficient_spaces_available( |
|
| 364 | - $insufficient_spaces_available |
|
| 365 | - ); |
|
| 366 | - } |
|
| 367 | - if (! empty($registrations_requiring_pre_approval)) { |
|
| 368 | - $subsections['registrations_requiring_pre_approval'] = $this->_registrations_requiring_pre_approval( |
|
| 369 | - $registrations_requiring_pre_approval |
|
| 370 | - ); |
|
| 371 | - } |
|
| 372 | - if (! empty($registrations_for_free_events)) { |
|
| 373 | - $subsections['no_payment_required'] = $this->_no_payment_required($registrations_for_free_events); |
|
| 374 | - } |
|
| 375 | - if (! empty($registrations_requiring_payment)) { |
|
| 376 | - if ($this->checkout->amount_owing > 0) { |
|
| 377 | - // autoload Line_Item_Display classes |
|
| 378 | - EEH_Autoloader::register_line_item_filter_autoloaders(); |
|
| 379 | - $line_item_filter_processor = new EE_Line_Item_Filter_Processor( |
|
| 380 | - apply_filters( |
|
| 381 | - 'FHEE__SPCO__EE_Line_Item_Filter_Collection', |
|
| 382 | - new EE_Line_Item_Filter_Collection() |
|
| 383 | - ), |
|
| 384 | - $this->checkout->cart->get_grand_total() |
|
| 385 | - ); |
|
| 386 | - /** @var EE_Line_Item $filtered_line_item_tree */ |
|
| 387 | - $filtered_line_item_tree = $line_item_filter_processor->process(); |
|
| 388 | - EEH_Autoloader::register_line_item_display_autoloaders(); |
|
| 389 | - $this->set_line_item_display(new EE_Line_Item_Display('spco')); |
|
| 390 | - $subsections['payment_options'] = $this->_display_payment_options( |
|
| 391 | - $this->line_item_display->display_line_item( |
|
| 392 | - $filtered_line_item_tree, |
|
| 393 | - array('registrations' => $registrations) |
|
| 394 | - ) |
|
| 395 | - ); |
|
| 396 | - $this->checkout->amount_owing = $filtered_line_item_tree->total(); |
|
| 397 | - $this->_apply_registration_payments_to_amount_owing($registrations); |
|
| 398 | - } |
|
| 399 | - $no_payment_required = false; |
|
| 400 | - } else { |
|
| 401 | - $this->_hide_reg_step_submit_button_if_revisit(); |
|
| 402 | - } |
|
| 403 | - $this->_save_selected_method_of_payment(); |
|
| 404 | - |
|
| 405 | - $subsections['default_hidden_inputs'] = $this->reg_step_hidden_inputs(); |
|
| 406 | - $subsections['extra_hidden_inputs'] = $this->_extra_hidden_inputs($no_payment_required); |
|
| 407 | - |
|
| 408 | - return new EE_Form_Section_Proper( |
|
| 409 | - array( |
|
| 410 | - 'name' => $this->reg_form_name(), |
|
| 411 | - 'html_id' => $this->reg_form_name(), |
|
| 412 | - 'subsections' => $subsections, |
|
| 413 | - 'layout_strategy' => new EE_No_Layout(), |
|
| 414 | - ) |
|
| 415 | - ); |
|
| 416 | - } |
|
| 417 | - |
|
| 418 | - |
|
| 419 | - /** |
|
| 420 | - * add line item filters required for this reg step |
|
| 421 | - * these filters are applied via this line in EE_SPCO_Reg_Step_Payment_Options::set_hooks(): |
|
| 422 | - * add_filter( 'FHEE__SPCO__EE_Line_Item_Filter_Collection', array( 'EE_SPCO_Reg_Step_Payment_Options', |
|
| 423 | - * 'add_spco_line_item_filters' ) ); so any code that wants to use the same set of filters during the |
|
| 424 | - * payment options reg step, can apply these filters via the following: apply_filters( |
|
| 425 | - * 'FHEE__SPCO__EE_Line_Item_Filter_Collection', new EE_Line_Item_Filter_Collection() ) or to an existing |
|
| 426 | - * filter collection by passing that instead of instantiating a new collection |
|
| 427 | - * |
|
| 428 | - * @param \EE_Line_Item_Filter_Collection $line_item_filter_collection |
|
| 429 | - * @return EE_Line_Item_Filter_Collection |
|
| 430 | - * @throws EE_Error |
|
| 431 | - * @throws InvalidArgumentException |
|
| 432 | - * @throws ReflectionException |
|
| 433 | - * @throws \EventEspresso\core\exceptions\EntityNotFoundException |
|
| 434 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 435 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 436 | - * @throws \EventEspresso\core\exceptions\InvalidStatusException |
|
| 437 | - */ |
|
| 438 | - public static function add_spco_line_item_filters(EE_Line_Item_Filter_Collection $line_item_filter_collection) |
|
| 439 | - { |
|
| 440 | - if (! EE_Registry::instance()->SSN instanceof EE_Session) { |
|
| 441 | - return $line_item_filter_collection; |
|
| 442 | - } |
|
| 443 | - if (! EE_Registry::instance()->SSN->checkout() instanceof EE_Checkout) { |
|
| 444 | - return $line_item_filter_collection; |
|
| 445 | - } |
|
| 446 | - if (! EE_Registry::instance()->SSN->checkout()->transaction instanceof EE_Transaction) { |
|
| 447 | - return $line_item_filter_collection; |
|
| 448 | - } |
|
| 449 | - $line_item_filter_collection->add( |
|
| 450 | - new EE_Billable_Line_Item_Filter( |
|
| 451 | - EE_SPCO_Reg_Step_Payment_Options::remove_ejected_registrations( |
|
| 452 | - EE_Registry::instance()->SSN->checkout()->transaction->registrations( |
|
| 453 | - EE_Registry::instance()->SSN->checkout()->reg_cache_where_params |
|
| 454 | - ) |
|
| 455 | - ) |
|
| 456 | - ) |
|
| 457 | - ); |
|
| 458 | - $line_item_filter_collection->add(new EE_Non_Zero_Line_Item_Filter()); |
|
| 459 | - return $line_item_filter_collection; |
|
| 460 | - } |
|
| 461 | - |
|
| 462 | - |
|
| 463 | - /** |
|
| 464 | - * remove_ejected_registrations |
|
| 465 | - * if a registrant has lost their potential space at an event due to lack of payment, |
|
| 466 | - * then this method removes them from the list of registrations being paid for during this request |
|
| 467 | - * |
|
| 468 | - * @param \EE_Registration[] $registrations |
|
| 469 | - * @return EE_Registration[] |
|
| 470 | - * @throws EE_Error |
|
| 471 | - * @throws InvalidArgumentException |
|
| 472 | - * @throws ReflectionException |
|
| 473 | - * @throws \EventEspresso\core\exceptions\EntityNotFoundException |
|
| 474 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 475 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 476 | - * @throws \EventEspresso\core\exceptions\InvalidStatusException |
|
| 477 | - */ |
|
| 478 | - public static function remove_ejected_registrations(array $registrations) |
|
| 479 | - { |
|
| 480 | - $ejected_registrations = EE_SPCO_Reg_Step_Payment_Options::find_registrations_that_lost_their_space( |
|
| 481 | - $registrations, |
|
| 482 | - EE_Registry::instance()->SSN->checkout()->revisit |
|
| 483 | - ); |
|
| 484 | - foreach ($registrations as $REG_ID => $registration) { |
|
| 485 | - // has this registration lost it's space ? |
|
| 486 | - if (isset($ejected_registrations[ $REG_ID ])) { |
|
| 487 | - unset($registrations[ $REG_ID ]); |
|
| 488 | - continue; |
|
| 489 | - } |
|
| 490 | - } |
|
| 491 | - return $registrations; |
|
| 492 | - } |
|
| 493 | - |
|
| 494 | - |
|
| 495 | - /** |
|
| 496 | - * find_registrations_that_lost_their_space |
|
| 497 | - * If a registrant chooses an offline payment method like Invoice, |
|
| 498 | - * then no space is reserved for them at the event until they fully pay fo that site |
|
| 499 | - * (unless the event's default reg status is set to APPROVED) |
|
| 500 | - * if a registrant then later returns to pay, but the number of spaces available has been reduced due to sales, |
|
| 501 | - * then this method will determine which registrations have lost the ability to complete the reg process. |
|
| 502 | - * |
|
| 503 | - * @param \EE_Registration[] $registrations |
|
| 504 | - * @param bool $revisit |
|
| 505 | - * @return array |
|
| 506 | - * @throws EE_Error |
|
| 507 | - * @throws InvalidArgumentException |
|
| 508 | - * @throws ReflectionException |
|
| 509 | - * @throws \EventEspresso\core\exceptions\EntityNotFoundException |
|
| 510 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 511 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 512 | - * @throws \EventEspresso\core\exceptions\InvalidStatusException |
|
| 513 | - */ |
|
| 514 | - public static function find_registrations_that_lost_their_space(array $registrations, $revisit = false) |
|
| 515 | - { |
|
| 516 | - // registrations per event |
|
| 517 | - $event_reg_count = array(); |
|
| 518 | - // spaces left per event |
|
| 519 | - $event_spaces_remaining = array(); |
|
| 520 | - // tickets left sorted by ID |
|
| 521 | - $tickets_remaining = array(); |
|
| 522 | - // registrations that have lost their space |
|
| 523 | - $ejected_registrations = array(); |
|
| 524 | - foreach ($registrations as $REG_ID => $registration) { |
|
| 525 | - if ($registration->status_ID() === EEM_Registration::status_id_approved |
|
| 526 | - || apply_filters( |
|
| 527 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options__find_registrations_that_lost_their_space__allow_reg_payment', |
|
| 528 | - false, |
|
| 529 | - $registration, |
|
| 530 | - $revisit |
|
| 531 | - ) |
|
| 532 | - ) { |
|
| 533 | - continue; |
|
| 534 | - } |
|
| 535 | - $EVT_ID = $registration->event_ID(); |
|
| 536 | - $ticket = $registration->ticket(); |
|
| 537 | - if (! isset($tickets_remaining[ $ticket->ID() ])) { |
|
| 538 | - $tickets_remaining[ $ticket->ID() ] = $ticket->remaining(); |
|
| 539 | - } |
|
| 540 | - if ($tickets_remaining[ $ticket->ID() ] > 0) { |
|
| 541 | - if (! isset($event_reg_count[ $EVT_ID ])) { |
|
| 542 | - $event_reg_count[ $EVT_ID ] = 0; |
|
| 543 | - } |
|
| 544 | - $event_reg_count[ $EVT_ID ]++; |
|
| 545 | - if (! isset($event_spaces_remaining[ $EVT_ID ])) { |
|
| 546 | - $event_spaces_remaining[ $EVT_ID ] = $registration->event()->spaces_remaining_for_sale(); |
|
| 547 | - } |
|
| 548 | - } |
|
| 549 | - if ($revisit |
|
| 550 | - && ($tickets_remaining[ $ticket->ID() ] === 0 |
|
| 551 | - || $event_reg_count[ $EVT_ID ] > $event_spaces_remaining[ $EVT_ID ] |
|
| 552 | - ) |
|
| 553 | - ) { |
|
| 554 | - $ejected_registrations[ $REG_ID ] = $registration->event(); |
|
| 555 | - if ($registration->status_ID() !== EEM_Registration::status_id_wait_list) { |
|
| 556 | - /** @type EE_Registration_Processor $registration_processor */ |
|
| 557 | - $registration_processor = EE_Registry::instance()->load_class('Registration_Processor'); |
|
| 558 | - // at this point, we should have enough details about the registrant to consider the registration |
|
| 559 | - // NOT incomplete |
|
| 560 | - $registration_processor->manually_update_registration_status( |
|
| 561 | - $registration, |
|
| 562 | - EEM_Registration::status_id_wait_list |
|
| 563 | - ); |
|
| 564 | - } |
|
| 565 | - } |
|
| 566 | - } |
|
| 567 | - return $ejected_registrations; |
|
| 568 | - } |
|
| 569 | - |
|
| 570 | - |
|
| 571 | - /** |
|
| 572 | - * _hide_reg_step_submit_button |
|
| 573 | - * removes the html for the reg step submit button |
|
| 574 | - * by replacing it with an empty string via filter callback |
|
| 575 | - * |
|
| 576 | - * @return void |
|
| 577 | - */ |
|
| 578 | - protected function _adjust_registration_status_if_event_old_sold() |
|
| 579 | - { |
|
| 580 | - } |
|
| 581 | - |
|
| 582 | - |
|
| 583 | - /** |
|
| 584 | - * _hide_reg_step_submit_button |
|
| 585 | - * removes the html for the reg step submit button |
|
| 586 | - * by replacing it with an empty string via filter callback |
|
| 587 | - * |
|
| 588 | - * @return void |
|
| 589 | - */ |
|
| 590 | - protected function _hide_reg_step_submit_button_if_revisit() |
|
| 591 | - { |
|
| 592 | - if ($this->checkout->revisit) { |
|
| 593 | - add_filter('FHEE__EE_SPCO_Reg_Step__reg_step_submit_button__sbmt_btn_html', '__return_empty_string'); |
|
| 594 | - } |
|
| 595 | - } |
|
| 596 | - |
|
| 597 | - |
|
| 598 | - /** |
|
| 599 | - * sold_out_events |
|
| 600 | - * displays notices regarding events that have sold out since hte registrant first signed up |
|
| 601 | - * |
|
| 602 | - * @param \EE_Event[] $sold_out_events_array |
|
| 603 | - * @return \EE_Form_Section_Proper |
|
| 604 | - * @throws \EE_Error |
|
| 605 | - */ |
|
| 606 | - private function _sold_out_events($sold_out_events_array = array()) |
|
| 607 | - { |
|
| 608 | - // set some defaults |
|
| 609 | - $this->checkout->selected_method_of_payment = 'events_sold_out'; |
|
| 610 | - $sold_out_events = ''; |
|
| 611 | - foreach ($sold_out_events_array as $sold_out_event) { |
|
| 612 | - $sold_out_events .= EEH_HTML::li( |
|
| 613 | - EEH_HTML::span( |
|
| 614 | - ' ' . $sold_out_event->name(), |
|
| 615 | - '', |
|
| 616 | - 'dashicons dashicons-marker ee-icon-size-16 pink-text' |
|
| 617 | - ) |
|
| 618 | - ); |
|
| 619 | - } |
|
| 620 | - return new EE_Form_Section_Proper( |
|
| 621 | - array( |
|
| 622 | - 'layout_strategy' => new EE_Template_Layout( |
|
| 623 | - array( |
|
| 624 | - 'layout_template_file' => SPCO_REG_STEPS_PATH |
|
| 625 | - . $this->_slug |
|
| 626 | - . '/sold_out_events.template.php', |
|
| 627 | - 'template_args' => apply_filters( |
|
| 628 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options___sold_out_events__template_args', |
|
| 629 | - array( |
|
| 630 | - 'sold_out_events' => $sold_out_events, |
|
| 631 | - 'sold_out_events_msg' => apply_filters( |
|
| 632 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options___sold_out_events__sold_out_events_msg', |
|
| 633 | - sprintf( |
|
| 634 | - esc_html__( |
|
| 635 | - 'It appears that the event you were about to make a payment for has sold out since you first registered. If you have already made a partial payment towards this event, please contact the event administrator for a refund.%3$s%3$s%1$sPlease note that availability can change at any time due to cancellations, so please check back again later if registration for this event(s) is important to you.%2$s', |
|
| 636 | - 'event_espresso' |
|
| 637 | - ), |
|
| 638 | - '<strong>', |
|
| 639 | - '</strong>', |
|
| 640 | - '<br />' |
|
| 641 | - ) |
|
| 642 | - ), |
|
| 643 | - ) |
|
| 644 | - ), |
|
| 645 | - ) |
|
| 646 | - ), |
|
| 647 | - ) |
|
| 648 | - ); |
|
| 649 | - } |
|
| 650 | - |
|
| 651 | - |
|
| 652 | - /** |
|
| 653 | - * _insufficient_spaces_available |
|
| 654 | - * displays notices regarding events that do not have enough remaining spaces |
|
| 655 | - * to satisfy the current number of registrations looking to pay |
|
| 656 | - * |
|
| 657 | - * @param \EE_Event[] $insufficient_spaces_events_array |
|
| 658 | - * @return \EE_Form_Section_Proper |
|
| 659 | - * @throws \EE_Error |
|
| 660 | - */ |
|
| 661 | - private function _insufficient_spaces_available($insufficient_spaces_events_array = array()) |
|
| 662 | - { |
|
| 663 | - // set some defaults |
|
| 664 | - $this->checkout->selected_method_of_payment = 'invoice'; |
|
| 665 | - $insufficient_space_events = ''; |
|
| 666 | - foreach ($insufficient_spaces_events_array as $event) { |
|
| 667 | - if ($event instanceof EE_Event) { |
|
| 668 | - $insufficient_space_events .= EEH_HTML::li( |
|
| 669 | - EEH_HTML::span(' ' . $event->name(), '', 'dashicons dashicons-marker ee-icon-size-16 pink-text') |
|
| 670 | - ); |
|
| 671 | - } |
|
| 672 | - } |
|
| 673 | - return new EE_Form_Section_Proper( |
|
| 674 | - array( |
|
| 675 | - 'subsections' => array( |
|
| 676 | - 'default_hidden_inputs' => $this->reg_step_hidden_inputs(), |
|
| 677 | - 'extra_hidden_inputs' => $this->_extra_hidden_inputs(), |
|
| 678 | - ), |
|
| 679 | - 'layout_strategy' => new EE_Template_Layout( |
|
| 680 | - array( |
|
| 681 | - 'layout_template_file' => SPCO_REG_STEPS_PATH |
|
| 682 | - . $this->_slug |
|
| 683 | - . '/sold_out_events.template.php', |
|
| 684 | - 'template_args' => apply_filters( |
|
| 685 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options___insufficient_spaces_available__template_args', |
|
| 686 | - array( |
|
| 687 | - 'sold_out_events' => $insufficient_space_events, |
|
| 688 | - 'sold_out_events_msg' => apply_filters( |
|
| 689 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options___insufficient_spaces_available__insufficient_space_msg', |
|
| 690 | - esc_html__( |
|
| 691 | - 'It appears that the event you were about to make a payment for has sold additional tickets since you first registered, and there are no longer enough spaces left to accommodate your selections. You may continue to pay and secure the available space(s) remaining, or simply cancel if you no longer wish to purchase. If you have already made a partial payment towards this event, please contact the event administrator for a refund.', |
|
| 692 | - 'event_espresso' |
|
| 693 | - ) |
|
| 694 | - ), |
|
| 695 | - ) |
|
| 696 | - ), |
|
| 697 | - ) |
|
| 698 | - ), |
|
| 699 | - ) |
|
| 700 | - ); |
|
| 701 | - } |
|
| 702 | - |
|
| 703 | - |
|
| 704 | - /** |
|
| 705 | - * registrations_requiring_pre_approval |
|
| 706 | - * |
|
| 707 | - * @param array $registrations_requiring_pre_approval |
|
| 708 | - * @return EE_Form_Section_Proper |
|
| 709 | - * @throws EE_Error |
|
| 710 | - * @throws \EventEspresso\core\exceptions\EntityNotFoundException |
|
| 711 | - */ |
|
| 712 | - private function _registrations_requiring_pre_approval($registrations_requiring_pre_approval = array()) |
|
| 713 | - { |
|
| 714 | - $events_requiring_pre_approval = array(); |
|
| 715 | - foreach ($registrations_requiring_pre_approval as $registration) { |
|
| 716 | - if ($registration instanceof EE_Registration && $registration->event() instanceof EE_Event) { |
|
| 717 | - $events_requiring_pre_approval[ $registration->event()->ID() ] = EEH_HTML::li( |
|
| 718 | - EEH_HTML::span( |
|
| 719 | - '', |
|
| 720 | - '', |
|
| 721 | - 'dashicons dashicons-marker ee-icon-size-16 orange-text' |
|
| 722 | - ) |
|
| 723 | - . EEH_HTML::span($registration->event()->name(), '', 'orange-text') |
|
| 724 | - ); |
|
| 725 | - } |
|
| 726 | - } |
|
| 727 | - return new EE_Form_Section_Proper( |
|
| 728 | - array( |
|
| 729 | - 'layout_strategy' => new EE_Template_Layout( |
|
| 730 | - array( |
|
| 731 | - 'layout_template_file' => SPCO_REG_STEPS_PATH |
|
| 732 | - . $this->_slug |
|
| 733 | - . '/events_requiring_pre_approval.template.php', // layout_template |
|
| 734 | - 'template_args' => apply_filters( |
|
| 735 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options___sold_out_events__template_args', |
|
| 736 | - array( |
|
| 737 | - 'events_requiring_pre_approval' => implode('', $events_requiring_pre_approval), |
|
| 738 | - 'events_requiring_pre_approval_msg' => apply_filters( |
|
| 739 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options___events_requiring_pre_approval__events_requiring_pre_approval_msg', |
|
| 740 | - esc_html__( |
|
| 741 | - 'The following events do not require payment at this time and will not be billed during this transaction. Billing will only occur after the attendee has been approved by the event organizer. You will be notified when your registration has been processed. If this is a free event, then no billing will occur.', |
|
| 742 | - 'event_espresso' |
|
| 743 | - ) |
|
| 744 | - ), |
|
| 745 | - ) |
|
| 746 | - ), |
|
| 747 | - ) |
|
| 748 | - ), |
|
| 749 | - ) |
|
| 750 | - ); |
|
| 751 | - } |
|
| 752 | - |
|
| 753 | - |
|
| 754 | - /** |
|
| 755 | - * _no_payment_required |
|
| 756 | - * |
|
| 757 | - * @param \EE_Event[] $registrations_for_free_events |
|
| 758 | - * @return \EE_Form_Section_Proper |
|
| 759 | - * @throws \EE_Error |
|
| 760 | - */ |
|
| 761 | - private function _no_payment_required($registrations_for_free_events = array()) |
|
| 762 | - { |
|
| 763 | - // set some defaults |
|
| 764 | - $this->checkout->selected_method_of_payment = 'no_payment_required'; |
|
| 765 | - // generate no_payment_required form |
|
| 766 | - return new EE_Form_Section_Proper( |
|
| 767 | - array( |
|
| 768 | - 'layout_strategy' => new EE_Template_Layout( |
|
| 769 | - array( |
|
| 770 | - 'layout_template_file' => SPCO_REG_STEPS_PATH |
|
| 771 | - . $this->_slug |
|
| 772 | - . '/no_payment_required.template.php', // layout_template |
|
| 773 | - 'template_args' => apply_filters( |
|
| 774 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options___no_payment_required__template_args', |
|
| 775 | - array( |
|
| 776 | - 'revisit' => $this->checkout->revisit, |
|
| 777 | - 'registrations' => array(), |
|
| 778 | - 'ticket_count' => array(), |
|
| 779 | - 'registrations_for_free_events' => $registrations_for_free_events, |
|
| 780 | - 'no_payment_required_msg' => EEH_HTML::p( |
|
| 781 | - esc_html__('This is a free event, so no billing will occur.', 'event_espresso') |
|
| 782 | - ), |
|
| 783 | - ) |
|
| 784 | - ), |
|
| 785 | - ) |
|
| 786 | - ), |
|
| 787 | - ) |
|
| 788 | - ); |
|
| 789 | - } |
|
| 790 | - |
|
| 791 | - |
|
| 792 | - /** |
|
| 793 | - * _display_payment_options |
|
| 794 | - * |
|
| 795 | - * @param string $transaction_details |
|
| 796 | - * @return EE_Form_Section_Proper |
|
| 797 | - * @throws EE_Error |
|
| 798 | - * @throws InvalidArgumentException |
|
| 799 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 800 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 801 | - */ |
|
| 802 | - private function _display_payment_options($transaction_details = '') |
|
| 803 | - { |
|
| 804 | - // has method_of_payment been set by no-js user? |
|
| 805 | - $this->checkout->selected_method_of_payment = $this->_get_selected_method_of_payment(); |
|
| 806 | - // build payment options form |
|
| 807 | - return apply_filters( |
|
| 808 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options___display_payment_options__payment_options_form', |
|
| 809 | - new EE_Form_Section_Proper( |
|
| 810 | - array( |
|
| 811 | - 'subsections' => array( |
|
| 812 | - 'before_payment_options' => apply_filters( |
|
| 813 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options___display_payment_options__before_payment_options', |
|
| 814 | - new EE_Form_Section_Proper( |
|
| 815 | - array('layout_strategy' => new EE_Div_Per_Section_Layout()) |
|
| 816 | - ) |
|
| 817 | - ), |
|
| 818 | - 'payment_options' => $this->_setup_payment_options(), |
|
| 819 | - 'after_payment_options' => apply_filters( |
|
| 820 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options___display_payment_options__after_payment_options', |
|
| 821 | - new EE_Form_Section_Proper( |
|
| 822 | - array('layout_strategy' => new EE_Div_Per_Section_Layout()) |
|
| 823 | - ) |
|
| 824 | - ), |
|
| 825 | - ), |
|
| 826 | - 'layout_strategy' => new EE_Template_Layout( |
|
| 827 | - array( |
|
| 828 | - 'layout_template_file' => $this->_template, |
|
| 829 | - 'template_args' => apply_filters( |
|
| 830 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options___display_payment_options__template_args', |
|
| 831 | - array( |
|
| 832 | - 'reg_count' => $this->line_item_display->total_items(), |
|
| 833 | - 'transaction_details' => $transaction_details, |
|
| 834 | - 'available_payment_methods' => array(), |
|
| 835 | - ) |
|
| 836 | - ), |
|
| 837 | - ) |
|
| 838 | - ), |
|
| 839 | - ) |
|
| 840 | - ) |
|
| 841 | - ); |
|
| 842 | - } |
|
| 843 | - |
|
| 844 | - |
|
| 845 | - /** |
|
| 846 | - * _extra_hidden_inputs |
|
| 847 | - * |
|
| 848 | - * @param bool $no_payment_required |
|
| 849 | - * @return \EE_Form_Section_Proper |
|
| 850 | - * @throws \EE_Error |
|
| 851 | - */ |
|
| 852 | - private function _extra_hidden_inputs($no_payment_required = true) |
|
| 853 | - { |
|
| 854 | - return new EE_Form_Section_Proper( |
|
| 855 | - array( |
|
| 856 | - 'html_id' => 'ee-' . $this->slug() . '-extra-hidden-inputs', |
|
| 857 | - 'layout_strategy' => new EE_Div_Per_Section_Layout(), |
|
| 858 | - 'subsections' => array( |
|
| 859 | - 'spco_no_payment_required' => new EE_Hidden_Input( |
|
| 860 | - array( |
|
| 861 | - 'normalization_strategy' => new EE_Boolean_Normalization(), |
|
| 862 | - 'html_name' => 'spco_no_payment_required', |
|
| 863 | - 'html_id' => 'spco-no-payment-required-payment_options', |
|
| 864 | - 'default' => $no_payment_required, |
|
| 865 | - ) |
|
| 866 | - ), |
|
| 867 | - 'spco_transaction_id' => new EE_Fixed_Hidden_Input( |
|
| 868 | - array( |
|
| 869 | - 'normalization_strategy' => new EE_Int_Normalization(), |
|
| 870 | - 'html_name' => 'spco_transaction_id', |
|
| 871 | - 'html_id' => 'spco-transaction-id', |
|
| 872 | - 'default' => $this->checkout->transaction->ID(), |
|
| 873 | - ) |
|
| 874 | - ), |
|
| 875 | - ), |
|
| 876 | - ) |
|
| 877 | - ); |
|
| 878 | - } |
|
| 879 | - |
|
| 880 | - |
|
| 881 | - /** |
|
| 882 | - * _apply_registration_payments_to_amount_owing |
|
| 883 | - * |
|
| 884 | - * @access protected |
|
| 885 | - * @param array $registrations |
|
| 886 | - * @throws EE_Error |
|
| 887 | - */ |
|
| 888 | - protected function _apply_registration_payments_to_amount_owing(array $registrations) |
|
| 889 | - { |
|
| 890 | - $payments = array(); |
|
| 891 | - foreach ($registrations as $registration) { |
|
| 892 | - if ($registration instanceof EE_Registration && $registration->owes_monies_and_can_pay()) { |
|
| 893 | - $payments += $registration->registration_payments(); |
|
| 894 | - } |
|
| 895 | - } |
|
| 896 | - if (! empty($payments)) { |
|
| 897 | - foreach ($payments as $payment) { |
|
| 898 | - if ($payment instanceof EE_Registration_Payment) { |
|
| 899 | - $this->checkout->amount_owing -= $payment->amount(); |
|
| 900 | - } |
|
| 901 | - } |
|
| 902 | - } |
|
| 903 | - } |
|
| 904 | - |
|
| 905 | - |
|
| 906 | - /** |
|
| 907 | - * _reset_selected_method_of_payment |
|
| 908 | - * |
|
| 909 | - * @access private |
|
| 910 | - * @param bool $force_reset |
|
| 911 | - * @return void |
|
| 912 | - * @throws InvalidArgumentException |
|
| 913 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 914 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 915 | - */ |
|
| 916 | - private function _reset_selected_method_of_payment($force_reset = false) |
|
| 917 | - { |
|
| 918 | - $reset_payment_method = $force_reset |
|
| 919 | - ? true |
|
| 920 | - : sanitize_text_field(EE_Registry::instance()->REQ->get('reset_payment_method', false)); |
|
| 921 | - if ($reset_payment_method) { |
|
| 922 | - $this->checkout->selected_method_of_payment = null; |
|
| 923 | - $this->checkout->payment_method = null; |
|
| 924 | - $this->checkout->billing_form = null; |
|
| 925 | - $this->_save_selected_method_of_payment(); |
|
| 926 | - } |
|
| 927 | - } |
|
| 928 | - |
|
| 929 | - |
|
| 930 | - /** |
|
| 931 | - * _save_selected_method_of_payment |
|
| 932 | - * stores the selected_method_of_payment in the session |
|
| 933 | - * so that it's available for all subsequent requests including AJAX |
|
| 934 | - * |
|
| 935 | - * @access private |
|
| 936 | - * @param string $selected_method_of_payment |
|
| 937 | - * @return void |
|
| 938 | - * @throws InvalidArgumentException |
|
| 939 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 940 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 941 | - */ |
|
| 942 | - private function _save_selected_method_of_payment($selected_method_of_payment = '') |
|
| 943 | - { |
|
| 944 | - $selected_method_of_payment = ! empty($selected_method_of_payment) |
|
| 945 | - ? $selected_method_of_payment |
|
| 946 | - : $this->checkout->selected_method_of_payment; |
|
| 947 | - EE_Registry::instance()->SSN->set_session_data( |
|
| 948 | - array('selected_method_of_payment' => $selected_method_of_payment) |
|
| 949 | - ); |
|
| 950 | - } |
|
| 951 | - |
|
| 952 | - |
|
| 953 | - /** |
|
| 954 | - * _setup_payment_options |
|
| 955 | - * |
|
| 956 | - * @return EE_Form_Section_Proper |
|
| 957 | - * @throws EE_Error |
|
| 958 | - * @throws InvalidArgumentException |
|
| 959 | - * @throws ReflectionException |
|
| 960 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 961 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 962 | - */ |
|
| 963 | - public function _setup_payment_options() |
|
| 964 | - { |
|
| 965 | - // load payment method classes |
|
| 966 | - $this->checkout->available_payment_methods = $this->_get_available_payment_methods(); |
|
| 967 | - if (empty($this->checkout->available_payment_methods)) { |
|
| 968 | - EE_Error::add_error( |
|
| 969 | - apply_filters( |
|
| 970 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options___setup_payment_options__error_message_no_payment_methods', |
|
| 971 | - sprintf( |
|
| 972 | - esc_html__( |
|
| 973 | - 'Sorry, you cannot complete your purchase because a payment method is not active.%1$s Please contact %2$s for assistance and provide a description of the problem.', |
|
| 974 | - 'event_espresso' |
|
| 975 | - ), |
|
| 976 | - '<br>', |
|
| 977 | - EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
| 978 | - ) |
|
| 979 | - ), |
|
| 980 | - __FILE__, |
|
| 981 | - __FUNCTION__, |
|
| 982 | - __LINE__ |
|
| 983 | - ); |
|
| 984 | - } |
|
| 985 | - // switch up header depending on number of available payment methods |
|
| 986 | - $payment_method_header = count($this->checkout->available_payment_methods) > 1 |
|
| 987 | - ? apply_filters( |
|
| 988 | - 'FHEE__registration_page_payment_options__method_of_payment_hdr', |
|
| 989 | - esc_html__('Please Select Your Method of Payment', 'event_espresso') |
|
| 990 | - ) |
|
| 991 | - : apply_filters( |
|
| 992 | - 'FHEE__registration_page_payment_options__method_of_payment_hdr', |
|
| 993 | - esc_html__('Method of Payment', 'event_espresso') |
|
| 994 | - ); |
|
| 995 | - $available_payment_methods = array( |
|
| 996 | - // display the "Payment Method" header |
|
| 997 | - 'payment_method_header' => new EE_Form_Section_HTML( |
|
| 998 | - apply_filters( |
|
| 999 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options___setup_payment_options__payment_method_header', |
|
| 1000 | - EEH_HTML::h4($payment_method_header, 'method-of-payment-hdr'), |
|
| 1001 | - $payment_method_header |
|
| 1002 | - ) |
|
| 1003 | - ), |
|
| 1004 | - ); |
|
| 1005 | - // the list of actual payment methods ( invoice, paypal, etc ) in a ( slug => HTML ) format |
|
| 1006 | - $available_payment_method_options = array(); |
|
| 1007 | - $default_payment_method_option = array(); |
|
| 1008 | - // additional instructions to be displayed and hidden below payment methods (adding a clearing div to start) |
|
| 1009 | - $payment_methods_billing_info = array( |
|
| 1010 | - new EE_Form_Section_HTML( |
|
| 1011 | - EEH_HTML::div('<br />', '', '', 'clear:both;') |
|
| 1012 | - ), |
|
| 1013 | - ); |
|
| 1014 | - // loop through payment methods |
|
| 1015 | - foreach ($this->checkout->available_payment_methods as $payment_method) { |
|
| 1016 | - if ($payment_method instanceof EE_Payment_Method) { |
|
| 1017 | - $payment_method_button = EEH_HTML::img( |
|
| 1018 | - $payment_method->button_url(), |
|
| 1019 | - $payment_method->name(), |
|
| 1020 | - 'spco-payment-method-' . $payment_method->slug() . '-btn-img', |
|
| 1021 | - 'spco-payment-method-btn-img' |
|
| 1022 | - ); |
|
| 1023 | - // check if any payment methods are set as default |
|
| 1024 | - // if payment method is already selected OR nothing is selected and this payment method should be |
|
| 1025 | - // open_by_default |
|
| 1026 | - if (($this->checkout->selected_method_of_payment === $payment_method->slug()) |
|
| 1027 | - || (! $this->checkout->selected_method_of_payment && $payment_method->open_by_default()) |
|
| 1028 | - ) { |
|
| 1029 | - $this->checkout->selected_method_of_payment = $payment_method->slug(); |
|
| 1030 | - $this->_save_selected_method_of_payment(); |
|
| 1031 | - $default_payment_method_option[ $payment_method->slug() ] = $payment_method_button; |
|
| 1032 | - } else { |
|
| 1033 | - $available_payment_method_options[ $payment_method->slug() ] = $payment_method_button; |
|
| 1034 | - } |
|
| 1035 | - $payment_methods_billing_info[ $payment_method->slug( |
|
| 1036 | - ) . '-info' ] = $this->_payment_method_billing_info( |
|
| 1037 | - $payment_method |
|
| 1038 | - ); |
|
| 1039 | - } |
|
| 1040 | - } |
|
| 1041 | - // prepend available_payment_method_options with default_payment_method_option so that it appears first in list |
|
| 1042 | - // of PMs |
|
| 1043 | - $available_payment_method_options = $default_payment_method_option + $available_payment_method_options; |
|
| 1044 | - // now generate the actual form inputs |
|
| 1045 | - $available_payment_methods['available_payment_methods'] = $this->_available_payment_method_inputs( |
|
| 1046 | - $available_payment_method_options |
|
| 1047 | - ); |
|
| 1048 | - $available_payment_methods += $payment_methods_billing_info; |
|
| 1049 | - // build the available payment methods form |
|
| 1050 | - return new EE_Form_Section_Proper( |
|
| 1051 | - array( |
|
| 1052 | - 'html_id' => 'spco-available-methods-of-payment-dv', |
|
| 1053 | - 'subsections' => $available_payment_methods, |
|
| 1054 | - 'layout_strategy' => new EE_Div_Per_Section_Layout(), |
|
| 1055 | - ) |
|
| 1056 | - ); |
|
| 1057 | - } |
|
| 1058 | - |
|
| 1059 | - |
|
| 1060 | - /** |
|
| 1061 | - * _get_available_payment_methods |
|
| 1062 | - * |
|
| 1063 | - * @return EE_Payment_Method[] |
|
| 1064 | - * @throws EE_Error |
|
| 1065 | - * @throws InvalidArgumentException |
|
| 1066 | - * @throws ReflectionException |
|
| 1067 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 1068 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 1069 | - */ |
|
| 1070 | - protected function _get_available_payment_methods() |
|
| 1071 | - { |
|
| 1072 | - if (! empty($this->checkout->available_payment_methods)) { |
|
| 1073 | - return $this->checkout->available_payment_methods; |
|
| 1074 | - } |
|
| 1075 | - $available_payment_methods = array(); |
|
| 1076 | - // load EEM_Payment_Method |
|
| 1077 | - EE_Registry::instance()->load_model('Payment_Method'); |
|
| 1078 | - /** @type EEM_Payment_Method $EEM_Payment_Method */ |
|
| 1079 | - $EEM_Payment_Method = EE_Registry::instance()->LIB->EEM_Payment_Method; |
|
| 1080 | - // get all active payment methods |
|
| 1081 | - $payment_methods = $EEM_Payment_Method->get_all_for_transaction( |
|
| 1082 | - $this->checkout->transaction, |
|
| 1083 | - EEM_Payment_Method::scope_cart |
|
| 1084 | - ); |
|
| 1085 | - foreach ($payment_methods as $payment_method) { |
|
| 1086 | - if ($payment_method instanceof EE_Payment_Method) { |
|
| 1087 | - $available_payment_methods[ $payment_method->slug() ] = $payment_method; |
|
| 1088 | - } |
|
| 1089 | - } |
|
| 1090 | - return $available_payment_methods; |
|
| 1091 | - } |
|
| 1092 | - |
|
| 1093 | - |
|
| 1094 | - /** |
|
| 1095 | - * _available_payment_method_inputs |
|
| 1096 | - * |
|
| 1097 | - * @access private |
|
| 1098 | - * @param array $available_payment_method_options |
|
| 1099 | - * @return \EE_Form_Section_Proper |
|
| 1100 | - */ |
|
| 1101 | - private function _available_payment_method_inputs($available_payment_method_options = array()) |
|
| 1102 | - { |
|
| 1103 | - // generate inputs |
|
| 1104 | - return new EE_Form_Section_Proper( |
|
| 1105 | - array( |
|
| 1106 | - 'html_id' => 'ee-available-payment-method-inputs', |
|
| 1107 | - 'layout_strategy' => new EE_Div_Per_Section_Layout(), |
|
| 1108 | - 'subsections' => array( |
|
| 1109 | - '' => new EE_Radio_Button_Input( |
|
| 1110 | - $available_payment_method_options, |
|
| 1111 | - array( |
|
| 1112 | - 'html_name' => 'selected_method_of_payment', |
|
| 1113 | - 'html_class' => 'spco-payment-method', |
|
| 1114 | - 'default' => $this->checkout->selected_method_of_payment, |
|
| 1115 | - 'label_size' => 11, |
|
| 1116 | - 'enforce_label_size' => true, |
|
| 1117 | - ) |
|
| 1118 | - ), |
|
| 1119 | - ), |
|
| 1120 | - ) |
|
| 1121 | - ); |
|
| 1122 | - } |
|
| 1123 | - |
|
| 1124 | - |
|
| 1125 | - /** |
|
| 1126 | - * _payment_method_billing_info |
|
| 1127 | - * |
|
| 1128 | - * @access private |
|
| 1129 | - * @param EE_Payment_Method $payment_method |
|
| 1130 | - * @return EE_Form_Section_Proper |
|
| 1131 | - * @throws EE_Error |
|
| 1132 | - * @throws InvalidArgumentException |
|
| 1133 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 1134 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 1135 | - */ |
|
| 1136 | - private function _payment_method_billing_info(EE_Payment_Method $payment_method) |
|
| 1137 | - { |
|
| 1138 | - $currently_selected = $this->checkout->selected_method_of_payment === $payment_method->slug() |
|
| 1139 | - ? true |
|
| 1140 | - : false; |
|
| 1141 | - // generate the billing form for payment method |
|
| 1142 | - $billing_form = $currently_selected |
|
| 1143 | - ? $this->_get_billing_form_for_payment_method($payment_method) |
|
| 1144 | - : new EE_Form_Section_HTML(); |
|
| 1145 | - $this->checkout->billing_form = $currently_selected |
|
| 1146 | - ? $billing_form |
|
| 1147 | - : $this->checkout->billing_form; |
|
| 1148 | - // it's all in the details |
|
| 1149 | - $info_html = EEH_HTML::h3( |
|
| 1150 | - esc_html__('Important information regarding your payment', 'event_espresso'), |
|
| 1151 | - '', |
|
| 1152 | - 'spco-payment-method-hdr' |
|
| 1153 | - ); |
|
| 1154 | - // add some info regarding the step, either from what's saved in the admin, |
|
| 1155 | - // or a default string depending on whether the PM has a billing form or not |
|
| 1156 | - if ($payment_method->description()) { |
|
| 1157 | - $payment_method_info = $payment_method->description(); |
|
| 1158 | - } elseif ($billing_form instanceof EE_Billing_Info_Form) { |
|
| 1159 | - $payment_method_info = sprintf( |
|
| 1160 | - esc_html__( |
|
| 1161 | - 'Please provide the following billing information, then click the "%1$s" button below in order to proceed.', |
|
| 1162 | - 'event_espresso' |
|
| 1163 | - ), |
|
| 1164 | - $this->submit_button_text() |
|
| 1165 | - ); |
|
| 1166 | - } else { |
|
| 1167 | - $payment_method_info = sprintf( |
|
| 1168 | - esc_html__('Please click the "%1$s" button below in order to proceed.', 'event_espresso'), |
|
| 1169 | - $this->submit_button_text() |
|
| 1170 | - ); |
|
| 1171 | - } |
|
| 1172 | - $info_html .= EEH_HTML::div( |
|
| 1173 | - apply_filters( |
|
| 1174 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options___payment_method_billing_info__payment_method_info', |
|
| 1175 | - $payment_method_info |
|
| 1176 | - ), |
|
| 1177 | - '', |
|
| 1178 | - 'spco-payment-method-desc ee-attention' |
|
| 1179 | - ); |
|
| 1180 | - return new EE_Form_Section_Proper( |
|
| 1181 | - array( |
|
| 1182 | - 'html_id' => 'spco-payment-method-info-' . $payment_method->slug(), |
|
| 1183 | - 'html_class' => 'spco-payment-method-info-dv', |
|
| 1184 | - // only display the selected or default PM |
|
| 1185 | - 'html_style' => $currently_selected ? '' : 'display:none;', |
|
| 1186 | - 'layout_strategy' => new EE_Div_Per_Section_Layout(), |
|
| 1187 | - 'subsections' => array( |
|
| 1188 | - 'info' => new EE_Form_Section_HTML($info_html), |
|
| 1189 | - 'billing_form' => $currently_selected ? $billing_form : new EE_Form_Section_HTML(), |
|
| 1190 | - ), |
|
| 1191 | - ) |
|
| 1192 | - ); |
|
| 1193 | - } |
|
| 1194 | - |
|
| 1195 | - |
|
| 1196 | - /** |
|
| 1197 | - * get_billing_form_html_for_payment_method |
|
| 1198 | - * |
|
| 1199 | - * @access public |
|
| 1200 | - * @return string |
|
| 1201 | - * @throws EE_Error |
|
| 1202 | - * @throws InvalidArgumentException |
|
| 1203 | - * @throws ReflectionException |
|
| 1204 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 1205 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 1206 | - */ |
|
| 1207 | - public function get_billing_form_html_for_payment_method() |
|
| 1208 | - { |
|
| 1209 | - // how have they chosen to pay? |
|
| 1210 | - $this->checkout->selected_method_of_payment = $this->_get_selected_method_of_payment(true); |
|
| 1211 | - $this->checkout->payment_method = $this->_get_payment_method_for_selected_method_of_payment(); |
|
| 1212 | - if (! $this->checkout->payment_method instanceof EE_Payment_Method) { |
|
| 1213 | - return false; |
|
| 1214 | - } |
|
| 1215 | - if (apply_filters( |
|
| 1216 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options__registration_checkout__selected_payment_method__display_success', |
|
| 1217 | - false |
|
| 1218 | - )) { |
|
| 1219 | - EE_Error::add_success( |
|
| 1220 | - apply_filters( |
|
| 1221 | - 'FHEE__Single_Page_Checkout__registration_checkout__selected_payment_method', |
|
| 1222 | - sprintf( |
|
| 1223 | - esc_html__( |
|
| 1224 | - 'You have selected "%s" as your method of payment. Please note the important payment information below.', |
|
| 1225 | - 'event_espresso' |
|
| 1226 | - ), |
|
| 1227 | - $this->checkout->payment_method->name() |
|
| 1228 | - ) |
|
| 1229 | - ) |
|
| 1230 | - ); |
|
| 1231 | - } |
|
| 1232 | - // now generate billing form for selected method of payment |
|
| 1233 | - $payment_method_billing_form = $this->_get_billing_form_for_payment_method($this->checkout->payment_method); |
|
| 1234 | - // fill form with attendee info if applicable |
|
| 1235 | - if ($payment_method_billing_form instanceof EE_Billing_Attendee_Info_Form |
|
| 1236 | - && $this->checkout->transaction_has_primary_registrant() |
|
| 1237 | - ) { |
|
| 1238 | - $payment_method_billing_form->populate_from_attendee( |
|
| 1239 | - $this->checkout->transaction->primary_registration()->attendee() |
|
| 1240 | - ); |
|
| 1241 | - } |
|
| 1242 | - // and debug content |
|
| 1243 | - if ($payment_method_billing_form instanceof EE_Billing_Info_Form |
|
| 1244 | - && $this->checkout->payment_method->type_obj() instanceof EE_PMT_Base |
|
| 1245 | - ) { |
|
| 1246 | - $payment_method_billing_form = |
|
| 1247 | - $this->checkout->payment_method->type_obj()->apply_billing_form_debug_settings( |
|
| 1248 | - $payment_method_billing_form |
|
| 1249 | - ); |
|
| 1250 | - } |
|
| 1251 | - $billing_info = $payment_method_billing_form instanceof EE_Form_Section_Proper |
|
| 1252 | - ? $payment_method_billing_form->get_html() |
|
| 1253 | - : ''; |
|
| 1254 | - $this->checkout->json_response->set_return_data(array('payment_method_info' => $billing_info)); |
|
| 1255 | - // localize validation rules for main form |
|
| 1256 | - $this->checkout->current_step->reg_form->localize_validation_rules(); |
|
| 1257 | - $this->checkout->json_response->add_validation_rules(EE_Form_Section_Proper::js_localization()); |
|
| 1258 | - return true; |
|
| 1259 | - } |
|
| 1260 | - |
|
| 1261 | - |
|
| 1262 | - /** |
|
| 1263 | - * _get_billing_form_for_payment_method |
|
| 1264 | - * |
|
| 1265 | - * @access private |
|
| 1266 | - * @param EE_Payment_Method $payment_method |
|
| 1267 | - * @return EE_Billing_Info_Form|EE_Form_Section_HTML |
|
| 1268 | - * @throws EE_Error |
|
| 1269 | - * @throws InvalidArgumentException |
|
| 1270 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 1271 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 1272 | - */ |
|
| 1273 | - private function _get_billing_form_for_payment_method(EE_Payment_Method $payment_method) |
|
| 1274 | - { |
|
| 1275 | - $billing_form = $payment_method->type_obj()->billing_form( |
|
| 1276 | - $this->checkout->transaction, |
|
| 1277 | - array('amount_owing' => $this->checkout->amount_owing) |
|
| 1278 | - ); |
|
| 1279 | - if ($billing_form instanceof EE_Billing_Info_Form) { |
|
| 1280 | - if (apply_filters( |
|
| 1281 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options__registration_checkout__selected_payment_method__display_success', |
|
| 1282 | - false |
|
| 1283 | - ) |
|
| 1284 | - && EE_Registry::instance()->REQ->is_set('payment_method') |
|
| 1285 | - ) { |
|
| 1286 | - EE_Error::add_success( |
|
| 1287 | - apply_filters( |
|
| 1288 | - 'FHEE__Single_Page_Checkout__registration_checkout__selected_payment_method', |
|
| 1289 | - sprintf( |
|
| 1290 | - esc_html__( |
|
| 1291 | - 'You have selected "%s" as your method of payment. Please note the important payment information below.', |
|
| 1292 | - 'event_espresso' |
|
| 1293 | - ), |
|
| 1294 | - $payment_method->name() |
|
| 1295 | - ) |
|
| 1296 | - ) |
|
| 1297 | - ); |
|
| 1298 | - } |
|
| 1299 | - return apply_filters( |
|
| 1300 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options___get_billing_form_for_payment_method__billing_form', |
|
| 1301 | - $billing_form, |
|
| 1302 | - $payment_method |
|
| 1303 | - ); |
|
| 1304 | - } |
|
| 1305 | - // no actual billing form, so return empty HTML form section |
|
| 1306 | - return new EE_Form_Section_HTML(); |
|
| 1307 | - } |
|
| 1308 | - |
|
| 1309 | - |
|
| 1310 | - /** |
|
| 1311 | - * _get_selected_method_of_payment |
|
| 1312 | - * |
|
| 1313 | - * @access private |
|
| 1314 | - * @param boolean $required whether to throw an error if the "selected_method_of_payment" |
|
| 1315 | - * is not found in the incoming request |
|
| 1316 | - * @param string $request_param |
|
| 1317 | - * @return NULL|string |
|
| 1318 | - * @throws EE_Error |
|
| 1319 | - * @throws InvalidArgumentException |
|
| 1320 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 1321 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 1322 | - */ |
|
| 1323 | - private function _get_selected_method_of_payment( |
|
| 1324 | - $required = false, |
|
| 1325 | - $request_param = 'selected_method_of_payment' |
|
| 1326 | - ) { |
|
| 1327 | - // is selected_method_of_payment set in the request ? |
|
| 1328 | - $selected_method_of_payment = EE_Registry::instance()->REQ->get($request_param, false); |
|
| 1329 | - if ($selected_method_of_payment) { |
|
| 1330 | - // sanitize it |
|
| 1331 | - $selected_method_of_payment = is_array($selected_method_of_payment) |
|
| 1332 | - ? array_shift($selected_method_of_payment) |
|
| 1333 | - : $selected_method_of_payment; |
|
| 1334 | - $selected_method_of_payment = sanitize_text_field($selected_method_of_payment); |
|
| 1335 | - // store it in the session so that it's available for all subsequent requests including AJAX |
|
| 1336 | - $this->_save_selected_method_of_payment($selected_method_of_payment); |
|
| 1337 | - } else { |
|
| 1338 | - // or is is set in the session ? |
|
| 1339 | - $selected_method_of_payment = EE_Registry::instance()->SSN->get_session_data( |
|
| 1340 | - 'selected_method_of_payment' |
|
| 1341 | - ); |
|
| 1342 | - } |
|
| 1343 | - // do ya really really gotta have it? |
|
| 1344 | - if (empty($selected_method_of_payment) && $required) { |
|
| 1345 | - EE_Error::add_error( |
|
| 1346 | - sprintf( |
|
| 1347 | - esc_html__( |
|
| 1348 | - 'The selected method of payment could not be determined.%sPlease ensure that you have selected one before proceeding.%sIf you continue to experience difficulties, then refresh your browser and try again, or contact %s for assistance.', |
|
| 1349 | - 'event_espresso' |
|
| 1350 | - ), |
|
| 1351 | - '<br/>', |
|
| 1352 | - '<br/>', |
|
| 1353 | - EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
| 1354 | - ), |
|
| 1355 | - __FILE__, |
|
| 1356 | - __FUNCTION__, |
|
| 1357 | - __LINE__ |
|
| 1358 | - ); |
|
| 1359 | - return null; |
|
| 1360 | - } |
|
| 1361 | - return $selected_method_of_payment; |
|
| 1362 | - } |
|
| 1363 | - |
|
| 1364 | - |
|
| 1365 | - |
|
| 1366 | - |
|
| 1367 | - |
|
| 1368 | - |
|
| 1369 | - /********************************************************************************************************/ |
|
| 1370 | - /*********************************** SWITCH PAYMENT METHOD ************************************/ |
|
| 1371 | - /********************************************************************************************************/ |
|
| 1372 | - /** |
|
| 1373 | - * switch_payment_method |
|
| 1374 | - * |
|
| 1375 | - * @access public |
|
| 1376 | - * @return string |
|
| 1377 | - * @throws EE_Error |
|
| 1378 | - * @throws InvalidArgumentException |
|
| 1379 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 1380 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 1381 | - */ |
|
| 1382 | - public function switch_payment_method() |
|
| 1383 | - { |
|
| 1384 | - if (! $this->_verify_payment_method_is_set()) { |
|
| 1385 | - return false; |
|
| 1386 | - } |
|
| 1387 | - if (apply_filters( |
|
| 1388 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options__registration_checkout__selected_payment_method__display_success', |
|
| 1389 | - false |
|
| 1390 | - )) { |
|
| 1391 | - EE_Error::add_success( |
|
| 1392 | - apply_filters( |
|
| 1393 | - 'FHEE__Single_Page_Checkout__registration_checkout__selected_payment_method', |
|
| 1394 | - sprintf( |
|
| 1395 | - esc_html__( |
|
| 1396 | - 'You have selected "%s" as your method of payment. Please note the important payment information below.', |
|
| 1397 | - 'event_espresso' |
|
| 1398 | - ), |
|
| 1399 | - $this->checkout->payment_method->name() |
|
| 1400 | - ) |
|
| 1401 | - ) |
|
| 1402 | - ); |
|
| 1403 | - } |
|
| 1404 | - // generate billing form for selected method of payment if it hasn't been done already |
|
| 1405 | - if ($this->checkout->payment_method->type_obj()->has_billing_form()) { |
|
| 1406 | - $this->checkout->billing_form = $this->_get_billing_form_for_payment_method( |
|
| 1407 | - $this->checkout->payment_method |
|
| 1408 | - ); |
|
| 1409 | - } |
|
| 1410 | - // fill form with attendee info if applicable |
|
| 1411 | - if (apply_filters( |
|
| 1412 | - 'FHEE__populate_billing_form_fields_from_attendee', |
|
| 1413 | - ( |
|
| 1414 | - $this->checkout->billing_form instanceof EE_Billing_Attendee_Info_Form |
|
| 1415 | - && $this->checkout->transaction_has_primary_registrant() |
|
| 1416 | - ), |
|
| 1417 | - $this->checkout->billing_form, |
|
| 1418 | - $this->checkout->transaction |
|
| 1419 | - ) |
|
| 1420 | - ) { |
|
| 1421 | - $this->checkout->billing_form->populate_from_attendee( |
|
| 1422 | - $this->checkout->transaction->primary_registration()->attendee() |
|
| 1423 | - ); |
|
| 1424 | - } |
|
| 1425 | - // and debug content |
|
| 1426 | - if ($this->checkout->billing_form instanceof EE_Billing_Info_Form |
|
| 1427 | - && $this->checkout->payment_method->type_obj() instanceof EE_PMT_Base |
|
| 1428 | - ) { |
|
| 1429 | - $this->checkout->billing_form = |
|
| 1430 | - $this->checkout->payment_method->type_obj()->apply_billing_form_debug_settings( |
|
| 1431 | - $this->checkout->billing_form |
|
| 1432 | - ); |
|
| 1433 | - } |
|
| 1434 | - // get html and validation rules for form |
|
| 1435 | - if ($this->checkout->billing_form instanceof EE_Form_Section_Proper) { |
|
| 1436 | - $this->checkout->json_response->set_return_data( |
|
| 1437 | - array('payment_method_info' => $this->checkout->billing_form->get_html()) |
|
| 1438 | - ); |
|
| 1439 | - // localize validation rules for main form |
|
| 1440 | - $this->checkout->billing_form->localize_validation_rules(true); |
|
| 1441 | - $this->checkout->json_response->add_validation_rules(EE_Form_Section_Proper::js_localization()); |
|
| 1442 | - } else { |
|
| 1443 | - $this->checkout->json_response->set_return_data(array('payment_method_info' => '')); |
|
| 1444 | - } |
|
| 1445 | - // prevents advancement to next step |
|
| 1446 | - $this->checkout->continue_reg = false; |
|
| 1447 | - return true; |
|
| 1448 | - } |
|
| 1449 | - |
|
| 1450 | - |
|
| 1451 | - /** |
|
| 1452 | - * _verify_payment_method_is_set |
|
| 1453 | - * |
|
| 1454 | - * @return bool |
|
| 1455 | - * @throws EE_Error |
|
| 1456 | - * @throws InvalidArgumentException |
|
| 1457 | - * @throws ReflectionException |
|
| 1458 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 1459 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 1460 | - */ |
|
| 1461 | - protected function _verify_payment_method_is_set() |
|
| 1462 | - { |
|
| 1463 | - // generate billing form for selected method of payment if it hasn't been done already |
|
| 1464 | - if (empty($this->checkout->selected_method_of_payment)) { |
|
| 1465 | - // how have they chosen to pay? |
|
| 1466 | - $this->checkout->selected_method_of_payment = $this->_get_selected_method_of_payment(true); |
|
| 1467 | - } else { |
|
| 1468 | - // choose your own adventure based on method_of_payment |
|
| 1469 | - switch ($this->checkout->selected_method_of_payment) { |
|
| 1470 | - case 'events_sold_out': |
|
| 1471 | - EE_Error::add_attention( |
|
| 1472 | - apply_filters( |
|
| 1473 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options___verify_payment_method_is_set__sold_out_events_msg', |
|
| 1474 | - esc_html__( |
|
| 1475 | - 'It appears that the event you were about to make a payment for has sold out since this form first loaded. Please contact the event administrator if you believe this is an error.', |
|
| 1476 | - 'event_espresso' |
|
| 1477 | - ) |
|
| 1478 | - ), |
|
| 1479 | - __FILE__, |
|
| 1480 | - __FUNCTION__, |
|
| 1481 | - __LINE__ |
|
| 1482 | - ); |
|
| 1483 | - return false; |
|
| 1484 | - break; |
|
| 1485 | - case 'payments_closed': |
|
| 1486 | - EE_Error::add_attention( |
|
| 1487 | - apply_filters( |
|
| 1488 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options___verify_payment_method_is_set__payments_closed_msg', |
|
| 1489 | - esc_html__( |
|
| 1490 | - 'It appears that the event you were about to make a payment for is not accepting payments at this time. Please contact the event administrator if you believe this is an error.', |
|
| 1491 | - 'event_espresso' |
|
| 1492 | - ) |
|
| 1493 | - ), |
|
| 1494 | - __FILE__, |
|
| 1495 | - __FUNCTION__, |
|
| 1496 | - __LINE__ |
|
| 1497 | - ); |
|
| 1498 | - return false; |
|
| 1499 | - break; |
|
| 1500 | - case 'no_payment_required': |
|
| 1501 | - EE_Error::add_attention( |
|
| 1502 | - apply_filters( |
|
| 1503 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options___verify_payment_method_is_set__no_payment_required_msg', |
|
| 1504 | - esc_html__( |
|
| 1505 | - 'It appears that the event you were about to make a payment for does not require payment. Please contact the event administrator if you believe this is an error.', |
|
| 1506 | - 'event_espresso' |
|
| 1507 | - ) |
|
| 1508 | - ), |
|
| 1509 | - __FILE__, |
|
| 1510 | - __FUNCTION__, |
|
| 1511 | - __LINE__ |
|
| 1512 | - ); |
|
| 1513 | - return false; |
|
| 1514 | - break; |
|
| 1515 | - default: |
|
| 1516 | - } |
|
| 1517 | - } |
|
| 1518 | - // verify payment method |
|
| 1519 | - if (! $this->checkout->payment_method instanceof EE_Payment_Method) { |
|
| 1520 | - // get payment method for selected method of payment |
|
| 1521 | - $this->checkout->payment_method = $this->_get_payment_method_for_selected_method_of_payment(); |
|
| 1522 | - } |
|
| 1523 | - return $this->checkout->payment_method instanceof EE_Payment_Method ? true : false; |
|
| 1524 | - } |
|
| 1525 | - |
|
| 1526 | - |
|
| 1527 | - |
|
| 1528 | - /********************************************************************************************************/ |
|
| 1529 | - /*************************************** SAVE PAYER DETAILS ****************************************/ |
|
| 1530 | - /********************************************************************************************************/ |
|
| 1531 | - /** |
|
| 1532 | - * save_payer_details_via_ajax |
|
| 1533 | - * |
|
| 1534 | - * @return void |
|
| 1535 | - * @throws EE_Error |
|
| 1536 | - * @throws InvalidArgumentException |
|
| 1537 | - * @throws ReflectionException |
|
| 1538 | - * @throws RuntimeException |
|
| 1539 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 1540 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 1541 | - */ |
|
| 1542 | - public function save_payer_details_via_ajax() |
|
| 1543 | - { |
|
| 1544 | - if (! $this->_verify_payment_method_is_set()) { |
|
| 1545 | - return; |
|
| 1546 | - } |
|
| 1547 | - // generate billing form for selected method of payment if it hasn't been done already |
|
| 1548 | - if ($this->checkout->payment_method->type_obj()->has_billing_form()) { |
|
| 1549 | - $this->checkout->billing_form = $this->_get_billing_form_for_payment_method( |
|
| 1550 | - $this->checkout->payment_method |
|
| 1551 | - ); |
|
| 1552 | - } |
|
| 1553 | - // generate primary attendee from payer info if applicable |
|
| 1554 | - if (! $this->checkout->transaction_has_primary_registrant()) { |
|
| 1555 | - $attendee = $this->_create_attendee_from_request_data(); |
|
| 1556 | - if ($attendee instanceof EE_Attendee) { |
|
| 1557 | - foreach ($this->checkout->transaction->registrations() as $registration) { |
|
| 1558 | - if ($registration->is_primary_registrant()) { |
|
| 1559 | - $this->checkout->primary_attendee_obj = $attendee; |
|
| 1560 | - $registration->_add_relation_to($attendee, 'Attendee'); |
|
| 1561 | - $registration->set_attendee_id($attendee->ID()); |
|
| 1562 | - $registration->update_cache_after_object_save('Attendee', $attendee); |
|
| 1563 | - } |
|
| 1564 | - } |
|
| 1565 | - } |
|
| 1566 | - } |
|
| 1567 | - } |
|
| 1568 | - |
|
| 1569 | - |
|
| 1570 | - /** |
|
| 1571 | - * create_attendee_from_request_data |
|
| 1572 | - * uses info from alternate GET or POST data (such as AJAX) to create a new attendee |
|
| 1573 | - * |
|
| 1574 | - * @return EE_Attendee |
|
| 1575 | - * @throws EE_Error |
|
| 1576 | - * @throws InvalidArgumentException |
|
| 1577 | - * @throws ReflectionException |
|
| 1578 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 1579 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 1580 | - */ |
|
| 1581 | - protected function _create_attendee_from_request_data() |
|
| 1582 | - { |
|
| 1583 | - // get State ID |
|
| 1584 | - $STA_ID = ! empty($_REQUEST['state']) ? sanitize_text_field($_REQUEST['state']) : ''; |
|
| 1585 | - if (! empty($STA_ID)) { |
|
| 1586 | - // can we get state object from name ? |
|
| 1587 | - EE_Registry::instance()->load_model('State'); |
|
| 1588 | - $state = EEM_State::instance()->get_col(array(array('STA_name' => $STA_ID), 'limit' => 1), 'STA_ID'); |
|
| 1589 | - $STA_ID = is_array($state) && ! empty($state) ? reset($state) : $STA_ID; |
|
| 1590 | - } |
|
| 1591 | - // get Country ISO |
|
| 1592 | - $CNT_ISO = ! empty($_REQUEST['country']) ? sanitize_text_field($_REQUEST['country']) : ''; |
|
| 1593 | - if (! empty($CNT_ISO)) { |
|
| 1594 | - // can we get country object from name ? |
|
| 1595 | - EE_Registry::instance()->load_model('Country'); |
|
| 1596 | - $country = EEM_Country::instance()->get_col( |
|
| 1597 | - array(array('CNT_name' => $CNT_ISO), 'limit' => 1), |
|
| 1598 | - 'CNT_ISO' |
|
| 1599 | - ); |
|
| 1600 | - $CNT_ISO = is_array($country) && ! empty($country) ? reset($country) : $CNT_ISO; |
|
| 1601 | - } |
|
| 1602 | - // grab attendee data |
|
| 1603 | - $attendee_data = array( |
|
| 1604 | - 'ATT_fname' => ! empty($_REQUEST['first_name']) ? sanitize_text_field($_REQUEST['first_name']) : '', |
|
| 1605 | - 'ATT_lname' => ! empty($_REQUEST['last_name']) ? sanitize_text_field($_REQUEST['last_name']) : '', |
|
| 1606 | - 'ATT_email' => ! empty($_REQUEST['email']) ? sanitize_email($_REQUEST['email']) : '', |
|
| 1607 | - 'ATT_address' => ! empty($_REQUEST['address']) ? sanitize_text_field($_REQUEST['address']) : '', |
|
| 1608 | - 'ATT_address2' => ! empty($_REQUEST['address2']) ? sanitize_text_field($_REQUEST['address2']) : '', |
|
| 1609 | - 'ATT_city' => ! empty($_REQUEST['city']) ? sanitize_text_field($_REQUEST['city']) : '', |
|
| 1610 | - 'STA_ID' => $STA_ID, |
|
| 1611 | - 'CNT_ISO' => $CNT_ISO, |
|
| 1612 | - 'ATT_zip' => ! empty($_REQUEST['zip']) ? sanitize_text_field($_REQUEST['zip']) : '', |
|
| 1613 | - 'ATT_phone' => ! empty($_REQUEST['phone']) ? sanitize_text_field($_REQUEST['phone']) : '', |
|
| 1614 | - ); |
|
| 1615 | - // validate the email address since it is the most important piece of info |
|
| 1616 | - if (empty($attendee_data['ATT_email']) || $attendee_data['ATT_email'] !== $_REQUEST['email']) { |
|
| 1617 | - EE_Error::add_error( |
|
| 1618 | - esc_html__('An invalid email address was submitted.', 'event_espresso'), |
|
| 1619 | - __FILE__, |
|
| 1620 | - __FUNCTION__, |
|
| 1621 | - __LINE__ |
|
| 1622 | - ); |
|
| 1623 | - } |
|
| 1624 | - // does this attendee already exist in the db ? we're searching using a combination of first name, last name, |
|
| 1625 | - // AND email address |
|
| 1626 | - if (! empty($attendee_data['ATT_fname']) |
|
| 1627 | - && ! empty($attendee_data['ATT_lname']) |
|
| 1628 | - && ! empty($attendee_data['ATT_email']) |
|
| 1629 | - ) { |
|
| 1630 | - $existing_attendee = EE_Registry::instance()->LIB->EEM_Attendee->find_existing_attendee( |
|
| 1631 | - array( |
|
| 1632 | - 'ATT_fname' => $attendee_data['ATT_fname'], |
|
| 1633 | - 'ATT_lname' => $attendee_data['ATT_lname'], |
|
| 1634 | - 'ATT_email' => $attendee_data['ATT_email'], |
|
| 1635 | - ) |
|
| 1636 | - ); |
|
| 1637 | - if ($existing_attendee instanceof EE_Attendee) { |
|
| 1638 | - return $existing_attendee; |
|
| 1639 | - } |
|
| 1640 | - } |
|
| 1641 | - // no existing attendee? kk let's create a new one |
|
| 1642 | - // kinda lame, but we need a first and last name to create an attendee, so use the email address if those |
|
| 1643 | - // don't exist |
|
| 1644 | - $attendee_data['ATT_fname'] = ! empty($attendee_data['ATT_fname']) |
|
| 1645 | - ? $attendee_data['ATT_fname'] |
|
| 1646 | - : $attendee_data['ATT_email']; |
|
| 1647 | - $attendee_data['ATT_lname'] = ! empty($attendee_data['ATT_lname']) |
|
| 1648 | - ? $attendee_data['ATT_lname'] |
|
| 1649 | - : $attendee_data['ATT_email']; |
|
| 1650 | - return EE_Attendee::new_instance($attendee_data); |
|
| 1651 | - } |
|
| 1652 | - |
|
| 1653 | - |
|
| 1654 | - |
|
| 1655 | - /********************************************************************************************************/ |
|
| 1656 | - /**************************************** PROCESS REG STEP *****************************************/ |
|
| 1657 | - /********************************************************************************************************/ |
|
| 1658 | - /** |
|
| 1659 | - * process_reg_step |
|
| 1660 | - * |
|
| 1661 | - * @return bool |
|
| 1662 | - * @throws EE_Error |
|
| 1663 | - * @throws InvalidArgumentException |
|
| 1664 | - * @throws ReflectionException |
|
| 1665 | - * @throws \EventEspresso\core\exceptions\EntityNotFoundException |
|
| 1666 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 1667 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 1668 | - * @throws \EventEspresso\core\exceptions\InvalidStatusException |
|
| 1669 | - */ |
|
| 1670 | - public function process_reg_step() |
|
| 1671 | - { |
|
| 1672 | - // how have they chosen to pay? |
|
| 1673 | - $this->checkout->selected_method_of_payment = $this->checkout->transaction->is_free() |
|
| 1674 | - ? 'no_payment_required' |
|
| 1675 | - : $this->_get_selected_method_of_payment(true); |
|
| 1676 | - // choose your own adventure based on method_of_payment |
|
| 1677 | - switch ($this->checkout->selected_method_of_payment) { |
|
| 1678 | - case 'events_sold_out': |
|
| 1679 | - $this->checkout->redirect = true; |
|
| 1680 | - $this->checkout->redirect_url = $this->checkout->cancel_page_url; |
|
| 1681 | - $this->checkout->json_response->set_redirect_url($this->checkout->redirect_url); |
|
| 1682 | - // mark this reg step as completed |
|
| 1683 | - $this->set_completed(); |
|
| 1684 | - return false; |
|
| 1685 | - break; |
|
| 1686 | - |
|
| 1687 | - case 'payments_closed': |
|
| 1688 | - if (apply_filters( |
|
| 1689 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options__process_reg_step__payments_closed__display_success', |
|
| 1690 | - false |
|
| 1691 | - )) { |
|
| 1692 | - EE_Error::add_success( |
|
| 1693 | - esc_html__('no payment required at this time.', 'event_espresso'), |
|
| 1694 | - __FILE__, |
|
| 1695 | - __FUNCTION__, |
|
| 1696 | - __LINE__ |
|
| 1697 | - ); |
|
| 1698 | - } |
|
| 1699 | - // mark this reg step as completed |
|
| 1700 | - $this->set_completed(); |
|
| 1701 | - return true; |
|
| 1702 | - break; |
|
| 1703 | - |
|
| 1704 | - case 'no_payment_required': |
|
| 1705 | - if (apply_filters( |
|
| 1706 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options__process_reg_step__no_payment_required__display_success', |
|
| 1707 | - false |
|
| 1708 | - )) { |
|
| 1709 | - EE_Error::add_success( |
|
| 1710 | - esc_html__('no payment required.', 'event_espresso'), |
|
| 1711 | - __FILE__, |
|
| 1712 | - __FUNCTION__, |
|
| 1713 | - __LINE__ |
|
| 1714 | - ); |
|
| 1715 | - } |
|
| 1716 | - // mark this reg step as completed |
|
| 1717 | - $this->set_completed(); |
|
| 1718 | - return true; |
|
| 1719 | - break; |
|
| 1720 | - |
|
| 1721 | - default: |
|
| 1722 | - $registrations = EE_Registry::instance()->SSN->checkout()->transaction->registrations( |
|
| 1723 | - EE_Registry::instance()->SSN->checkout()->reg_cache_where_params |
|
| 1724 | - ); |
|
| 1725 | - $ejected_registrations = EE_SPCO_Reg_Step_Payment_Options::find_registrations_that_lost_their_space( |
|
| 1726 | - $registrations, |
|
| 1727 | - EE_Registry::instance()->SSN->checkout()->revisit |
|
| 1728 | - ); |
|
| 1729 | - // calculate difference between the two arrays |
|
| 1730 | - $registrations = array_diff($registrations, $ejected_registrations); |
|
| 1731 | - if (empty($registrations)) { |
|
| 1732 | - $this->_redirect_because_event_sold_out(); |
|
| 1733 | - return false; |
|
| 1734 | - } |
|
| 1735 | - $payment_successful = $this->_process_payment(); |
|
| 1736 | - if ($payment_successful) { |
|
| 1737 | - $this->checkout->continue_reg = true; |
|
| 1738 | - $this->_maybe_set_completed($this->checkout->payment_method); |
|
| 1739 | - } else { |
|
| 1740 | - $this->checkout->continue_reg = false; |
|
| 1741 | - } |
|
| 1742 | - return $payment_successful; |
|
| 1743 | - } |
|
| 1744 | - } |
|
| 1745 | - |
|
| 1746 | - |
|
| 1747 | - /** |
|
| 1748 | - * _redirect_because_event_sold_out |
|
| 1749 | - * |
|
| 1750 | - * @access protected |
|
| 1751 | - * @return void |
|
| 1752 | - */ |
|
| 1753 | - protected function _redirect_because_event_sold_out() |
|
| 1754 | - { |
|
| 1755 | - $this->checkout->continue_reg = false; |
|
| 1756 | - // set redirect URL |
|
| 1757 | - $this->checkout->redirect_url = add_query_arg( |
|
| 1758 | - array('e_reg_url_link' => $this->checkout->reg_url_link), |
|
| 1759 | - $this->checkout->current_step->reg_step_url() |
|
| 1760 | - ); |
|
| 1761 | - $this->checkout->json_response->set_redirect_url($this->checkout->redirect_url); |
|
| 1762 | - } |
|
| 1763 | - |
|
| 1764 | - |
|
| 1765 | - /** |
|
| 1766 | - * _maybe_set_completed |
|
| 1767 | - * |
|
| 1768 | - * @access protected |
|
| 1769 | - * @param \EE_Payment_Method $payment_method |
|
| 1770 | - * @return void |
|
| 1771 | - * @throws \EE_Error |
|
| 1772 | - */ |
|
| 1773 | - protected function _maybe_set_completed(EE_Payment_Method $payment_method) |
|
| 1774 | - { |
|
| 1775 | - switch ($payment_method->type_obj()->payment_occurs()) { |
|
| 1776 | - case EE_PMT_Base::offsite: |
|
| 1777 | - break; |
|
| 1778 | - case EE_PMT_Base::onsite: |
|
| 1779 | - case EE_PMT_Base::offline: |
|
| 1780 | - // mark this reg step as completed |
|
| 1781 | - $this->set_completed(); |
|
| 1782 | - break; |
|
| 1783 | - } |
|
| 1784 | - } |
|
| 1785 | - |
|
| 1786 | - |
|
| 1787 | - /** |
|
| 1788 | - * update_reg_step |
|
| 1789 | - * this is the final step after a user revisits the site to retry a payment |
|
| 1790 | - * |
|
| 1791 | - * @return bool |
|
| 1792 | - * @throws EE_Error |
|
| 1793 | - * @throws InvalidArgumentException |
|
| 1794 | - * @throws ReflectionException |
|
| 1795 | - * @throws \EventEspresso\core\exceptions\EntityNotFoundException |
|
| 1796 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 1797 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 1798 | - * @throws \EventEspresso\core\exceptions\InvalidStatusException |
|
| 1799 | - */ |
|
| 1800 | - public function update_reg_step() |
|
| 1801 | - { |
|
| 1802 | - $success = true; |
|
| 1803 | - // if payment required |
|
| 1804 | - if ($this->checkout->transaction->total() > 0) { |
|
| 1805 | - do_action( |
|
| 1806 | - 'AHEE__EE_Single_Page_Checkout__process_finalize_registration__before_gateway', |
|
| 1807 | - $this->checkout->transaction |
|
| 1808 | - ); |
|
| 1809 | - // attempt payment via payment method |
|
| 1810 | - $success = $this->process_reg_step(); |
|
| 1811 | - } |
|
| 1812 | - if ($success && ! $this->checkout->redirect) { |
|
| 1813 | - $this->checkout->cart->get_grand_total()->save_this_and_descendants_to_txn( |
|
| 1814 | - $this->checkout->transaction->ID() |
|
| 1815 | - ); |
|
| 1816 | - // set return URL |
|
| 1817 | - $this->checkout->redirect_url = add_query_arg( |
|
| 1818 | - array('e_reg_url_link' => $this->checkout->reg_url_link), |
|
| 1819 | - $this->checkout->thank_you_page_url |
|
| 1820 | - ); |
|
| 1821 | - } |
|
| 1822 | - return $success; |
|
| 1823 | - } |
|
| 1824 | - |
|
| 1825 | - |
|
| 1826 | - /** |
|
| 1827 | - * _process_payment |
|
| 1828 | - * |
|
| 1829 | - * @access private |
|
| 1830 | - * @return bool |
|
| 1831 | - * @throws EE_Error |
|
| 1832 | - * @throws InvalidArgumentException |
|
| 1833 | - * @throws ReflectionException |
|
| 1834 | - * @throws RuntimeException |
|
| 1835 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 1836 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 1837 | - */ |
|
| 1838 | - private function _process_payment() |
|
| 1839 | - { |
|
| 1840 | - // basically confirm that the event hasn't sold out since they hit the page |
|
| 1841 | - if (! $this->_last_second_ticket_verifications()) { |
|
| 1842 | - return false; |
|
| 1843 | - } |
|
| 1844 | - // ya gotta make a choice man |
|
| 1845 | - if (empty($this->checkout->selected_method_of_payment)) { |
|
| 1846 | - $this->checkout->json_response->set_plz_select_method_of_payment( |
|
| 1847 | - esc_html__('Please select a method of payment before proceeding.', 'event_espresso') |
|
| 1848 | - ); |
|
| 1849 | - return false; |
|
| 1850 | - } |
|
| 1851 | - // get EE_Payment_Method object |
|
| 1852 | - if (! $this->checkout->payment_method = $this->_get_payment_method_for_selected_method_of_payment()) { |
|
| 1853 | - return false; |
|
| 1854 | - } |
|
| 1855 | - // setup billing form |
|
| 1856 | - if ($this->checkout->payment_method->is_on_site()) { |
|
| 1857 | - $this->checkout->billing_form = $this->_get_billing_form_for_payment_method( |
|
| 1858 | - $this->checkout->payment_method |
|
| 1859 | - ); |
|
| 1860 | - // bad billing form ? |
|
| 1861 | - if (! $this->_billing_form_is_valid()) { |
|
| 1862 | - return false; |
|
| 1863 | - } |
|
| 1864 | - } |
|
| 1865 | - // ensure primary registrant has been fully processed |
|
| 1866 | - if (! $this->_setup_primary_registrant_prior_to_payment()) { |
|
| 1867 | - return false; |
|
| 1868 | - } |
|
| 1869 | - // if session is close to expiring (under 10 minutes by default) |
|
| 1870 | - if ((time() - EE_Registry::instance()->SSN->expiration()) < EE_Registry::instance()->SSN->extension()) { |
|
| 1871 | - // add some time to session expiration so that payment can be completed |
|
| 1872 | - EE_Registry::instance()->SSN->extend_expiration(); |
|
| 1873 | - } |
|
| 1874 | - /** @type EE_Transaction_Processor $transaction_processor */ |
|
| 1875 | - // $transaction_processor = EE_Registry::instance()->load_class( 'Transaction_Processor' ); |
|
| 1876 | - // in case a registrant leaves to an Off-Site Gateway and never returns, we want to approve any registrations |
|
| 1877 | - // for events with a default reg status of Approved |
|
| 1878 | - // $transaction_processor->toggle_registration_statuses_for_default_approved_events( |
|
| 1879 | - // $this->checkout->transaction, $this->checkout->reg_cache_where_params |
|
| 1880 | - // ); |
|
| 1881 | - // attempt payment |
|
| 1882 | - $payment = $this->_attempt_payment($this->checkout->payment_method); |
|
| 1883 | - // process results |
|
| 1884 | - $payment = $this->_validate_payment($payment); |
|
| 1885 | - $payment = $this->_post_payment_processing($payment); |
|
| 1886 | - // verify payment |
|
| 1887 | - if ($payment instanceof EE_Payment) { |
|
| 1888 | - // store that for later |
|
| 1889 | - $this->checkout->payment = $payment; |
|
| 1890 | - // we can also consider the TXN to not have been failed, so temporarily upgrade it's status to abandoned |
|
| 1891 | - $this->checkout->transaction->toggle_failed_transaction_status(); |
|
| 1892 | - $payment_status = $payment->status(); |
|
| 1893 | - if ($payment_status === EEM_Payment::status_id_approved |
|
| 1894 | - || $payment_status === EEM_Payment::status_id_pending |
|
| 1895 | - ) { |
|
| 1896 | - return true; |
|
| 1897 | - } else { |
|
| 1898 | - return false; |
|
| 1899 | - } |
|
| 1900 | - } elseif ($payment === true) { |
|
| 1901 | - // please note that offline payment methods will NOT make a payment, |
|
| 1902 | - // but instead just mark themselves as the PMD_ID on the transaction, and return true |
|
| 1903 | - $this->checkout->payment = $payment; |
|
| 1904 | - return true; |
|
| 1905 | - } |
|
| 1906 | - // where's my money? |
|
| 1907 | - return false; |
|
| 1908 | - } |
|
| 1909 | - |
|
| 1910 | - |
|
| 1911 | - /** |
|
| 1912 | - * _last_second_ticket_verifications |
|
| 1913 | - * |
|
| 1914 | - * @access public |
|
| 1915 | - * @return bool |
|
| 1916 | - * @throws EE_Error |
|
| 1917 | - */ |
|
| 1918 | - protected function _last_second_ticket_verifications() |
|
| 1919 | - { |
|
| 1920 | - // don't bother re-validating if not a return visit |
|
| 1921 | - if (! $this->checkout->revisit) { |
|
| 1922 | - return true; |
|
| 1923 | - } |
|
| 1924 | - $registrations = $this->checkout->transaction->registrations(); |
|
| 1925 | - if (empty($registrations)) { |
|
| 1926 | - return false; |
|
| 1927 | - } |
|
| 1928 | - foreach ($registrations as $registration) { |
|
| 1929 | - if ($registration instanceof EE_Registration && ! $registration->is_approved()) { |
|
| 1930 | - $event = $registration->event_obj(); |
|
| 1931 | - if ($event instanceof EE_Event && $event->is_sold_out(true)) { |
|
| 1932 | - EE_Error::add_error( |
|
| 1933 | - apply_filters( |
|
| 1934 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options___last_second_ticket_verifications__sold_out_events_msg', |
|
| 1935 | - sprintf( |
|
| 1936 | - esc_html__( |
|
| 1937 | - 'It appears that the %1$s event that you were about to make a payment for has sold out since you first registered and/or arrived at this page. Please refresh the page and try again. If you have already made a partial payment towards this event, please contact the event administrator for a refund.', |
|
| 1938 | - 'event_espresso' |
|
| 1939 | - ), |
|
| 1940 | - $event->name() |
|
| 1941 | - ) |
|
| 1942 | - ), |
|
| 1943 | - __FILE__, |
|
| 1944 | - __FUNCTION__, |
|
| 1945 | - __LINE__ |
|
| 1946 | - ); |
|
| 1947 | - return false; |
|
| 1948 | - } |
|
| 1949 | - } |
|
| 1950 | - } |
|
| 1951 | - return true; |
|
| 1952 | - } |
|
| 1953 | - |
|
| 1954 | - |
|
| 1955 | - /** |
|
| 1956 | - * redirect_form |
|
| 1957 | - * |
|
| 1958 | - * @access public |
|
| 1959 | - * @return bool |
|
| 1960 | - * @throws EE_Error |
|
| 1961 | - * @throws InvalidArgumentException |
|
| 1962 | - * @throws ReflectionException |
|
| 1963 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 1964 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 1965 | - */ |
|
| 1966 | - public function redirect_form() |
|
| 1967 | - { |
|
| 1968 | - $payment_method_billing_info = $this->_payment_method_billing_info( |
|
| 1969 | - $this->_get_payment_method_for_selected_method_of_payment() |
|
| 1970 | - ); |
|
| 1971 | - $html = $payment_method_billing_info->get_html(); |
|
| 1972 | - $html .= $this->checkout->redirect_form; |
|
| 1973 | - EE_Registry::instance()->REQ->add_output($html); |
|
| 1974 | - return true; |
|
| 1975 | - } |
|
| 1976 | - |
|
| 1977 | - |
|
| 1978 | - /** |
|
| 1979 | - * _billing_form_is_valid |
|
| 1980 | - * |
|
| 1981 | - * @access private |
|
| 1982 | - * @return bool |
|
| 1983 | - * @throws \EE_Error |
|
| 1984 | - */ |
|
| 1985 | - private function _billing_form_is_valid() |
|
| 1986 | - { |
|
| 1987 | - if (! $this->checkout->payment_method->type_obj()->has_billing_form()) { |
|
| 1988 | - return true; |
|
| 1989 | - } |
|
| 1990 | - if ($this->checkout->billing_form instanceof EE_Billing_Info_Form) { |
|
| 1991 | - if ($this->checkout->billing_form->was_submitted()) { |
|
| 1992 | - $this->checkout->billing_form->receive_form_submission(); |
|
| 1993 | - if ($this->checkout->billing_form->is_valid()) { |
|
| 1994 | - return true; |
|
| 1995 | - } |
|
| 1996 | - $validation_errors = $this->checkout->billing_form->get_validation_errors_accumulated(); |
|
| 1997 | - $error_strings = array(); |
|
| 1998 | - foreach ($validation_errors as $validation_error) { |
|
| 1999 | - if ($validation_error instanceof EE_Validation_Error) { |
|
| 2000 | - $form_section = $validation_error->get_form_section(); |
|
| 2001 | - if ($form_section instanceof EE_Form_Input_Base) { |
|
| 2002 | - $label = $form_section->html_label_text(); |
|
| 2003 | - } elseif ($form_section instanceof EE_Form_Section_Base) { |
|
| 2004 | - $label = $form_section->name(); |
|
| 2005 | - } else { |
|
| 2006 | - $label = esc_html__('Validation Error', 'event_espresso'); |
|
| 2007 | - } |
|
| 2008 | - $error_strings[] = sprintf('%1$s: %2$s', $label, $validation_error->getMessage()); |
|
| 2009 | - } |
|
| 2010 | - } |
|
| 2011 | - EE_Error::add_error( |
|
| 2012 | - sprintf( |
|
| 2013 | - esc_html__( |
|
| 2014 | - 'One or more billing form inputs are invalid and require correction before proceeding. %1$s %2$s', |
|
| 2015 | - 'event_espresso' |
|
| 2016 | - ), |
|
| 2017 | - '<br/>', |
|
| 2018 | - implode('<br/>', $error_strings) |
|
| 2019 | - ), |
|
| 2020 | - __FILE__, |
|
| 2021 | - __FUNCTION__, |
|
| 2022 | - __LINE__ |
|
| 2023 | - ); |
|
| 2024 | - } else { |
|
| 2025 | - EE_Error::add_error( |
|
| 2026 | - esc_html__( |
|
| 2027 | - 'The billing form was not submitted or something prevented it\'s submission.', |
|
| 2028 | - 'event_espresso' |
|
| 2029 | - ), |
|
| 2030 | - __FILE__, |
|
| 2031 | - __FUNCTION__, |
|
| 2032 | - __LINE__ |
|
| 2033 | - ); |
|
| 2034 | - } |
|
| 2035 | - } else { |
|
| 2036 | - EE_Error::add_error( |
|
| 2037 | - esc_html__( |
|
| 2038 | - 'The submitted billing form is invalid possibly due to a technical reason.', |
|
| 2039 | - 'event_espresso' |
|
| 2040 | - ), |
|
| 2041 | - __FILE__, |
|
| 2042 | - __FUNCTION__, |
|
| 2043 | - __LINE__ |
|
| 2044 | - ); |
|
| 2045 | - } |
|
| 2046 | - return false; |
|
| 2047 | - } |
|
| 2048 | - |
|
| 2049 | - |
|
| 2050 | - /** |
|
| 2051 | - * _setup_primary_registrant_prior_to_payment |
|
| 2052 | - * ensures that the primary registrant has a valid attendee object created with the critical details populated |
|
| 2053 | - * (first & last name & email) and that both the transaction object and primary registration object have been saved |
|
| 2054 | - * plz note that any other registrations will NOT be saved at this point (because they may not have any details |
|
| 2055 | - * yet) |
|
| 2056 | - * |
|
| 2057 | - * @access private |
|
| 2058 | - * @return bool |
|
| 2059 | - * @throws EE_Error |
|
| 2060 | - * @throws InvalidArgumentException |
|
| 2061 | - * @throws ReflectionException |
|
| 2062 | - * @throws RuntimeException |
|
| 2063 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 2064 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 2065 | - */ |
|
| 2066 | - private function _setup_primary_registrant_prior_to_payment() |
|
| 2067 | - { |
|
| 2068 | - // check if transaction has a primary registrant and that it has a related Attendee object |
|
| 2069 | - // if not, then we need to at least gather some primary registrant data before attempting payment |
|
| 2070 | - if ($this->checkout->billing_form instanceof EE_Billing_Attendee_Info_Form |
|
| 2071 | - && ! $this->checkout->transaction_has_primary_registrant() |
|
| 2072 | - && ! $this->_capture_primary_registration_data_from_billing_form() |
|
| 2073 | - ) { |
|
| 2074 | - return false; |
|
| 2075 | - } |
|
| 2076 | - // because saving an object clears it's cache, we need to do the chevy shuffle |
|
| 2077 | - // grab the primary_registration object |
|
| 2078 | - $primary_registration = $this->checkout->transaction->primary_registration(); |
|
| 2079 | - // at this point we'll consider a TXN to not have been failed |
|
| 2080 | - $this->checkout->transaction->toggle_failed_transaction_status(); |
|
| 2081 | - // save the TXN ( which clears cached copy of primary_registration) |
|
| 2082 | - $this->checkout->transaction->save(); |
|
| 2083 | - // grab TXN ID and save it to the primary_registration |
|
| 2084 | - $primary_registration->set_transaction_id($this->checkout->transaction->ID()); |
|
| 2085 | - // save what we have so far |
|
| 2086 | - $primary_registration->save(); |
|
| 2087 | - return true; |
|
| 2088 | - } |
|
| 2089 | - |
|
| 2090 | - |
|
| 2091 | - /** |
|
| 2092 | - * _capture_primary_registration_data_from_billing_form |
|
| 2093 | - * |
|
| 2094 | - * @access private |
|
| 2095 | - * @return bool |
|
| 2096 | - * @throws EE_Error |
|
| 2097 | - * @throws InvalidArgumentException |
|
| 2098 | - * @throws ReflectionException |
|
| 2099 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 2100 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 2101 | - */ |
|
| 2102 | - private function _capture_primary_registration_data_from_billing_form() |
|
| 2103 | - { |
|
| 2104 | - // convert billing form data into an attendee |
|
| 2105 | - $this->checkout->primary_attendee_obj = $this->checkout->billing_form->create_attendee_from_billing_form_data(); |
|
| 2106 | - if (! $this->checkout->primary_attendee_obj instanceof EE_Attendee) { |
|
| 2107 | - EE_Error::add_error( |
|
| 2108 | - sprintf( |
|
| 2109 | - esc_html__( |
|
| 2110 | - 'The billing form details could not be used for attendee details due to a technical issue.%sPlease try again or contact %s for assistance.', |
|
| 2111 | - 'event_espresso' |
|
| 2112 | - ), |
|
| 2113 | - '<br/>', |
|
| 2114 | - EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
| 2115 | - ), |
|
| 2116 | - __FILE__, |
|
| 2117 | - __FUNCTION__, |
|
| 2118 | - __LINE__ |
|
| 2119 | - ); |
|
| 2120 | - return false; |
|
| 2121 | - } |
|
| 2122 | - $primary_registration = $this->checkout->transaction->primary_registration(); |
|
| 2123 | - if (! $primary_registration instanceof EE_Registration) { |
|
| 2124 | - EE_Error::add_error( |
|
| 2125 | - sprintf( |
|
| 2126 | - esc_html__( |
|
| 2127 | - 'The primary registrant for this transaction could not be determined due to a technical issue.%sPlease try again or contact %s for assistance.', |
|
| 2128 | - 'event_espresso' |
|
| 2129 | - ), |
|
| 2130 | - '<br/>', |
|
| 2131 | - EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
| 2132 | - ), |
|
| 2133 | - __FILE__, |
|
| 2134 | - __FUNCTION__, |
|
| 2135 | - __LINE__ |
|
| 2136 | - ); |
|
| 2137 | - return false; |
|
| 2138 | - } |
|
| 2139 | - if (! $primary_registration->_add_relation_to($this->checkout->primary_attendee_obj, 'Attendee') |
|
| 2140 | - instanceof |
|
| 2141 | - EE_Attendee |
|
| 2142 | - ) { |
|
| 2143 | - EE_Error::add_error( |
|
| 2144 | - sprintf( |
|
| 2145 | - esc_html__( |
|
| 2146 | - 'The primary registrant could not be associated with this transaction due to a technical issue.%sPlease try again or contact %s for assistance.', |
|
| 2147 | - 'event_espresso' |
|
| 2148 | - ), |
|
| 2149 | - '<br/>', |
|
| 2150 | - EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
| 2151 | - ), |
|
| 2152 | - __FILE__, |
|
| 2153 | - __FUNCTION__, |
|
| 2154 | - __LINE__ |
|
| 2155 | - ); |
|
| 2156 | - return false; |
|
| 2157 | - } |
|
| 2158 | - /** @type EE_Registration_Processor $registration_processor */ |
|
| 2159 | - $registration_processor = EE_Registry::instance()->load_class('Registration_Processor'); |
|
| 2160 | - // at this point, we should have enough details about the registrant to consider the registration NOT incomplete |
|
| 2161 | - $registration_processor->toggle_incomplete_registration_status_to_default($primary_registration); |
|
| 2162 | - return true; |
|
| 2163 | - } |
|
| 2164 | - |
|
| 2165 | - |
|
| 2166 | - /** |
|
| 2167 | - * _get_payment_method_for_selected_method_of_payment |
|
| 2168 | - * retrieves a valid payment method |
|
| 2169 | - * |
|
| 2170 | - * @access public |
|
| 2171 | - * @return EE_Payment_Method |
|
| 2172 | - * @throws EE_Error |
|
| 2173 | - * @throws InvalidArgumentException |
|
| 2174 | - * @throws ReflectionException |
|
| 2175 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 2176 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 2177 | - */ |
|
| 2178 | - private function _get_payment_method_for_selected_method_of_payment() |
|
| 2179 | - { |
|
| 2180 | - if ($this->checkout->selected_method_of_payment === 'events_sold_out') { |
|
| 2181 | - $this->_redirect_because_event_sold_out(); |
|
| 2182 | - return null; |
|
| 2183 | - } |
|
| 2184 | - // get EE_Payment_Method object |
|
| 2185 | - if (isset($this->checkout->available_payment_methods[ $this->checkout->selected_method_of_payment ])) { |
|
| 2186 | - $payment_method = $this->checkout->available_payment_methods[ $this->checkout->selected_method_of_payment ]; |
|
| 2187 | - } else { |
|
| 2188 | - // load EEM_Payment_Method |
|
| 2189 | - EE_Registry::instance()->load_model('Payment_Method'); |
|
| 2190 | - /** @type EEM_Payment_Method $EEM_Payment_Method */ |
|
| 2191 | - $EEM_Payment_Method = EE_Registry::instance()->LIB->EEM_Payment_Method; |
|
| 2192 | - $payment_method = $EEM_Payment_Method->get_one_by_slug($this->checkout->selected_method_of_payment); |
|
| 2193 | - } |
|
| 2194 | - // verify $payment_method |
|
| 2195 | - if (! $payment_method instanceof EE_Payment_Method) { |
|
| 2196 | - // not a payment |
|
| 2197 | - EE_Error::add_error( |
|
| 2198 | - sprintf( |
|
| 2199 | - esc_html__( |
|
| 2200 | - 'The selected method of payment could not be determined due to a technical issue.%sPlease try again or contact %s for assistance.', |
|
| 2201 | - 'event_espresso' |
|
| 2202 | - ), |
|
| 2203 | - '<br/>', |
|
| 2204 | - EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
| 2205 | - ), |
|
| 2206 | - __FILE__, |
|
| 2207 | - __FUNCTION__, |
|
| 2208 | - __LINE__ |
|
| 2209 | - ); |
|
| 2210 | - return null; |
|
| 2211 | - } |
|
| 2212 | - // and verify it has a valid Payment_Method Type object |
|
| 2213 | - if (! $payment_method->type_obj() instanceof EE_PMT_Base) { |
|
| 2214 | - // not a payment |
|
| 2215 | - EE_Error::add_error( |
|
| 2216 | - sprintf( |
|
| 2217 | - esc_html__( |
|
| 2218 | - 'A valid payment method could not be determined due to a technical issue.%sPlease try again or contact %s for assistance.', |
|
| 2219 | - 'event_espresso' |
|
| 2220 | - ), |
|
| 2221 | - '<br/>', |
|
| 2222 | - EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
| 2223 | - ), |
|
| 2224 | - __FILE__, |
|
| 2225 | - __FUNCTION__, |
|
| 2226 | - __LINE__ |
|
| 2227 | - ); |
|
| 2228 | - return null; |
|
| 2229 | - } |
|
| 2230 | - return $payment_method; |
|
| 2231 | - } |
|
| 2232 | - |
|
| 2233 | - |
|
| 2234 | - /** |
|
| 2235 | - * _attempt_payment |
|
| 2236 | - * |
|
| 2237 | - * @access private |
|
| 2238 | - * @type EE_Payment_Method $payment_method |
|
| 2239 | - * @return mixed EE_Payment | boolean |
|
| 2240 | - * @throws EE_Error |
|
| 2241 | - * @throws InvalidArgumentException |
|
| 2242 | - * @throws ReflectionException |
|
| 2243 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 2244 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 2245 | - */ |
|
| 2246 | - private function _attempt_payment(EE_Payment_Method $payment_method) |
|
| 2247 | - { |
|
| 2248 | - $payment = null; |
|
| 2249 | - $this->checkout->transaction->save(); |
|
| 2250 | - $payment_processor = EE_Registry::instance()->load_core('Payment_Processor'); |
|
| 2251 | - if (! $payment_processor instanceof EE_Payment_Processor) { |
|
| 2252 | - return false; |
|
| 2253 | - } |
|
| 2254 | - try { |
|
| 2255 | - $payment_processor->set_revisit($this->checkout->revisit); |
|
| 2256 | - // generate payment object |
|
| 2257 | - $payment = $payment_processor->process_payment( |
|
| 2258 | - $payment_method, |
|
| 2259 | - $this->checkout->transaction, |
|
| 2260 | - $this->checkout->amount_owing, |
|
| 2261 | - $this->checkout->billing_form, |
|
| 2262 | - $this->_get_return_url($payment_method), |
|
| 2263 | - 'CART', |
|
| 2264 | - $this->checkout->admin_request, |
|
| 2265 | - true, |
|
| 2266 | - $this->reg_step_url() |
|
| 2267 | - ); |
|
| 2268 | - } catch (Exception $e) { |
|
| 2269 | - $this->_handle_payment_processor_exception($e); |
|
| 2270 | - } |
|
| 2271 | - return $payment; |
|
| 2272 | - } |
|
| 2273 | - |
|
| 2274 | - |
|
| 2275 | - /** |
|
| 2276 | - * _handle_payment_processor_exception |
|
| 2277 | - * |
|
| 2278 | - * @access protected |
|
| 2279 | - * @param \Exception $e |
|
| 2280 | - * @return void |
|
| 2281 | - * @throws EE_Error |
|
| 2282 | - * @throws InvalidArgumentException |
|
| 2283 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 2284 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 2285 | - */ |
|
| 2286 | - protected function _handle_payment_processor_exception(Exception $e) |
|
| 2287 | - { |
|
| 2288 | - EE_Error::add_error( |
|
| 2289 | - sprintf( |
|
| 2290 | - esc_html__( |
|
| 2291 | - 'The payment could not br processed due to a technical issue.%1$sPlease try again or contact %2$s for assistance.||The following Exception was thrown in %4$s on line %5$s:%1$s%3$s', |
|
| 2292 | - 'event_espresso' |
|
| 2293 | - ), |
|
| 2294 | - '<br/>', |
|
| 2295 | - EE_Registry::instance()->CFG->organization->get_pretty('email'), |
|
| 2296 | - $e->getMessage(), |
|
| 2297 | - $e->getFile(), |
|
| 2298 | - $e->getLine() |
|
| 2299 | - ), |
|
| 2300 | - __FILE__, |
|
| 2301 | - __FUNCTION__, |
|
| 2302 | - __LINE__ |
|
| 2303 | - ); |
|
| 2304 | - } |
|
| 2305 | - |
|
| 2306 | - |
|
| 2307 | - /** |
|
| 2308 | - * _get_return_url |
|
| 2309 | - * |
|
| 2310 | - * @access protected |
|
| 2311 | - * @param \EE_Payment_Method $payment_method |
|
| 2312 | - * @return string |
|
| 2313 | - * @throws \EE_Error |
|
| 2314 | - */ |
|
| 2315 | - protected function _get_return_url(EE_Payment_Method $payment_method) |
|
| 2316 | - { |
|
| 2317 | - $return_url = ''; |
|
| 2318 | - switch ($payment_method->type_obj()->payment_occurs()) { |
|
| 2319 | - case EE_PMT_Base::offsite: |
|
| 2320 | - $return_url = add_query_arg( |
|
| 2321 | - array( |
|
| 2322 | - 'action' => 'process_gateway_response', |
|
| 2323 | - 'selected_method_of_payment' => $this->checkout->selected_method_of_payment, |
|
| 2324 | - 'spco_txn' => $this->checkout->transaction->ID(), |
|
| 2325 | - ), |
|
| 2326 | - $this->reg_step_url() |
|
| 2327 | - ); |
|
| 2328 | - break; |
|
| 2329 | - case EE_PMT_Base::onsite: |
|
| 2330 | - case EE_PMT_Base::offline: |
|
| 2331 | - $return_url = $this->checkout->next_step->reg_step_url(); |
|
| 2332 | - break; |
|
| 2333 | - } |
|
| 2334 | - return $return_url; |
|
| 2335 | - } |
|
| 2336 | - |
|
| 2337 | - |
|
| 2338 | - /** |
|
| 2339 | - * _validate_payment |
|
| 2340 | - * |
|
| 2341 | - * @access private |
|
| 2342 | - * @param EE_Payment $payment |
|
| 2343 | - * @return EE_Payment|FALSE |
|
| 2344 | - * @throws EE_Error |
|
| 2345 | - * @throws InvalidArgumentException |
|
| 2346 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 2347 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 2348 | - */ |
|
| 2349 | - private function _validate_payment($payment = null) |
|
| 2350 | - { |
|
| 2351 | - if ($this->checkout->payment_method->is_off_line()) { |
|
| 2352 | - return true; |
|
| 2353 | - } |
|
| 2354 | - // verify payment object |
|
| 2355 | - if (! $payment instanceof EE_Payment) { |
|
| 2356 | - // not a payment |
|
| 2357 | - EE_Error::add_error( |
|
| 2358 | - sprintf( |
|
| 2359 | - esc_html__( |
|
| 2360 | - 'A valid payment was not generated due to a technical issue.%1$sPlease try again or contact %2$s for assistance.', |
|
| 2361 | - 'event_espresso' |
|
| 2362 | - ), |
|
| 2363 | - '<br/>', |
|
| 2364 | - EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
| 2365 | - ), |
|
| 2366 | - __FILE__, |
|
| 2367 | - __FUNCTION__, |
|
| 2368 | - __LINE__ |
|
| 2369 | - ); |
|
| 2370 | - return false; |
|
| 2371 | - } |
|
| 2372 | - return $payment; |
|
| 2373 | - } |
|
| 2374 | - |
|
| 2375 | - |
|
| 2376 | - /** |
|
| 2377 | - * _post_payment_processing |
|
| 2378 | - * |
|
| 2379 | - * @access private |
|
| 2380 | - * @param EE_Payment|bool $payment |
|
| 2381 | - * @return bool |
|
| 2382 | - * @throws EE_Error |
|
| 2383 | - * @throws InvalidArgumentException |
|
| 2384 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 2385 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 2386 | - */ |
|
| 2387 | - private function _post_payment_processing($payment = null) |
|
| 2388 | - { |
|
| 2389 | - // Off-Line payment? |
|
| 2390 | - if ($payment === true) { |
|
| 2391 | - // $this->_setup_redirect_for_next_step(); |
|
| 2392 | - return true; |
|
| 2393 | - // On-Site payment? |
|
| 2394 | - } elseif ($this->checkout->payment_method->is_on_site()) { |
|
| 2395 | - if (! $this->_process_payment_status($payment, EE_PMT_Base::onsite)) { |
|
| 2396 | - // $this->_setup_redirect_for_next_step(); |
|
| 2397 | - $this->checkout->continue_reg = false; |
|
| 2398 | - } |
|
| 2399 | - // Off-Site payment? |
|
| 2400 | - } elseif ($this->checkout->payment_method->is_off_site()) { |
|
| 2401 | - // if a payment object was made and it specifies a redirect url, then we'll setup that redirect info |
|
| 2402 | - if ($payment instanceof EE_Payment && $payment->redirect_url()) { |
|
| 2403 | - do_action('AHEE_log', __CLASS__, __FUNCTION__, $payment->redirect_url(), '$payment->redirect_url()'); |
|
| 2404 | - $this->checkout->redirect = true; |
|
| 2405 | - $this->checkout->redirect_form = $payment->redirect_form(); |
|
| 2406 | - $this->checkout->redirect_url = $this->reg_step_url('redirect_form'); |
|
| 2407 | - // set JSON response |
|
| 2408 | - $this->checkout->json_response->set_redirect_form($this->checkout->redirect_form); |
|
| 2409 | - // and lastly, let's bump the payment status to pending |
|
| 2410 | - $payment->set_status(EEM_Payment::status_id_pending); |
|
| 2411 | - $payment->save(); |
|
| 2412 | - } else { |
|
| 2413 | - // not a payment |
|
| 2414 | - $this->checkout->continue_reg = false; |
|
| 2415 | - EE_Error::add_error( |
|
| 2416 | - sprintf( |
|
| 2417 | - esc_html__( |
|
| 2418 | - 'It appears the Off Site Payment Method was not configured properly.%sPlease try again or contact %s for assistance.', |
|
| 2419 | - 'event_espresso' |
|
| 2420 | - ), |
|
| 2421 | - '<br/>', |
|
| 2422 | - EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
| 2423 | - ), |
|
| 2424 | - __FILE__, |
|
| 2425 | - __FUNCTION__, |
|
| 2426 | - __LINE__ |
|
| 2427 | - ); |
|
| 2428 | - } |
|
| 2429 | - } else { |
|
| 2430 | - // ummm ya... not Off-Line, not On-Site, not off-Site ???? |
|
| 2431 | - $this->checkout->continue_reg = false; |
|
| 2432 | - return false; |
|
| 2433 | - } |
|
| 2434 | - return $payment; |
|
| 2435 | - } |
|
| 2436 | - |
|
| 2437 | - |
|
| 2438 | - /** |
|
| 2439 | - * _process_payment_status |
|
| 2440 | - * |
|
| 2441 | - * @access private |
|
| 2442 | - * @type EE_Payment $payment |
|
| 2443 | - * @param string $payment_occurs |
|
| 2444 | - * @return bool |
|
| 2445 | - * @throws EE_Error |
|
| 2446 | - * @throws InvalidArgumentException |
|
| 2447 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 2448 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 2449 | - */ |
|
| 2450 | - private function _process_payment_status($payment, $payment_occurs = EE_PMT_Base::offline) |
|
| 2451 | - { |
|
| 2452 | - // off-line payment? carry on |
|
| 2453 | - if ($payment_occurs === EE_PMT_Base::offline) { |
|
| 2454 | - return true; |
|
| 2455 | - } |
|
| 2456 | - // verify payment validity |
|
| 2457 | - if ($payment instanceof EE_Payment) { |
|
| 2458 | - do_action('AHEE_log', __CLASS__, __FUNCTION__, $payment->status(), '$payment->status()'); |
|
| 2459 | - $msg = $payment->gateway_response(); |
|
| 2460 | - // check results |
|
| 2461 | - switch ($payment->status()) { |
|
| 2462 | - // good payment |
|
| 2463 | - case EEM_Payment::status_id_approved: |
|
| 2464 | - EE_Error::add_success( |
|
| 2465 | - esc_html__('Your payment was processed successfully.', 'event_espresso'), |
|
| 2466 | - __FILE__, |
|
| 2467 | - __FUNCTION__, |
|
| 2468 | - __LINE__ |
|
| 2469 | - ); |
|
| 2470 | - return true; |
|
| 2471 | - break; |
|
| 2472 | - // slow payment |
|
| 2473 | - case EEM_Payment::status_id_pending: |
|
| 2474 | - if (empty($msg)) { |
|
| 2475 | - $msg = esc_html__( |
|
| 2476 | - 'Your payment appears to have been processed successfully, but the Instant Payment Notification has not yet been received. It should arrive shortly.', |
|
| 2477 | - 'event_espresso' |
|
| 2478 | - ); |
|
| 2479 | - } |
|
| 2480 | - EE_Error::add_success($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2481 | - return true; |
|
| 2482 | - break; |
|
| 2483 | - // don't wanna payment |
|
| 2484 | - case EEM_Payment::status_id_cancelled: |
|
| 2485 | - if (empty($msg)) { |
|
| 2486 | - $msg = _n( |
|
| 2487 | - 'Payment cancelled. Please try again.', |
|
| 2488 | - 'Payment cancelled. Please try again or select another method of payment.', |
|
| 2489 | - count($this->checkout->available_payment_methods), |
|
| 2490 | - 'event_espresso' |
|
| 2491 | - ); |
|
| 2492 | - } |
|
| 2493 | - EE_Error::add_attention($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2494 | - return false; |
|
| 2495 | - break; |
|
| 2496 | - // not enough payment |
|
| 2497 | - case EEM_Payment::status_id_declined: |
|
| 2498 | - if (empty($msg)) { |
|
| 2499 | - $msg = _n( |
|
| 2500 | - 'We\'re sorry but your payment was declined. Please try again.', |
|
| 2501 | - 'We\'re sorry but your payment was declined. Please try again or select another method of payment.', |
|
| 2502 | - count($this->checkout->available_payment_methods), |
|
| 2503 | - 'event_espresso' |
|
| 2504 | - ); |
|
| 2505 | - } |
|
| 2506 | - EE_Error::add_attention($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2507 | - return false; |
|
| 2508 | - break; |
|
| 2509 | - // bad payment |
|
| 2510 | - case EEM_Payment::status_id_failed: |
|
| 2511 | - if (! empty($msg)) { |
|
| 2512 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2513 | - return false; |
|
| 2514 | - } |
|
| 2515 | - // default to error below |
|
| 2516 | - break; |
|
| 2517 | - } |
|
| 2518 | - } |
|
| 2519 | - // off-site payment gateway responses are too unreliable, so let's just assume that |
|
| 2520 | - // the payment processing is just running slower than the registrant's request |
|
| 2521 | - if ($payment_occurs === EE_PMT_Base::offsite) { |
|
| 2522 | - return true; |
|
| 2523 | - } |
|
| 2524 | - EE_Error::add_error( |
|
| 2525 | - sprintf( |
|
| 2526 | - esc_html__( |
|
| 2527 | - 'Your payment could not be processed successfully due to a technical issue.%sPlease try again or contact %s for assistance.', |
|
| 2528 | - 'event_espresso' |
|
| 2529 | - ), |
|
| 2530 | - '<br/>', |
|
| 2531 | - EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
| 2532 | - ), |
|
| 2533 | - __FILE__, |
|
| 2534 | - __FUNCTION__, |
|
| 2535 | - __LINE__ |
|
| 2536 | - ); |
|
| 2537 | - return false; |
|
| 2538 | - } |
|
| 2539 | - |
|
| 2540 | - |
|
| 2541 | - |
|
| 2542 | - |
|
| 2543 | - |
|
| 2544 | - |
|
| 2545 | - /********************************************************************************************************/ |
|
| 2546 | - /********************************** PROCESS GATEWAY RESPONSE **********************************/ |
|
| 2547 | - /********************************************************************************************************/ |
|
| 2548 | - /** |
|
| 2549 | - * process_gateway_response |
|
| 2550 | - * this is the return point for Off-Site Payment Methods |
|
| 2551 | - * It will attempt to "handle the IPN" if it appears that this has not already occurred, |
|
| 2552 | - * otherwise, it will load up the last payment made for the TXN. |
|
| 2553 | - * If the payment retrieved looks good, it will then either: |
|
| 2554 | - * complete the current step and allow advancement to the next reg step |
|
| 2555 | - * or present the payment options again |
|
| 2556 | - * |
|
| 2557 | - * @access private |
|
| 2558 | - * @return EE_Payment|FALSE |
|
| 2559 | - * @throws EE_Error |
|
| 2560 | - * @throws InvalidArgumentException |
|
| 2561 | - * @throws ReflectionException |
|
| 2562 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 2563 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 2564 | - * @throws \EventEspresso\core\exceptions\InvalidSessionDataException |
|
| 2565 | - */ |
|
| 2566 | - public function process_gateway_response() |
|
| 2567 | - { |
|
| 2568 | - $payment = null; |
|
| 2569 | - // how have they chosen to pay? |
|
| 2570 | - $this->checkout->selected_method_of_payment = $this->_get_selected_method_of_payment(true); |
|
| 2571 | - // get EE_Payment_Method object |
|
| 2572 | - if (! $this->checkout->payment_method = $this->_get_payment_method_for_selected_method_of_payment()) { |
|
| 2573 | - $this->checkout->continue_reg = false; |
|
| 2574 | - return false; |
|
| 2575 | - } |
|
| 2576 | - if (! $this->checkout->payment_method->is_off_site()) { |
|
| 2577 | - return false; |
|
| 2578 | - } |
|
| 2579 | - $this->_validate_offsite_return(); |
|
| 2580 | - // DEBUG LOG |
|
| 2581 | - // $this->checkout->log( |
|
| 2582 | - // __CLASS__, |
|
| 2583 | - // __FUNCTION__, |
|
| 2584 | - // __LINE__, |
|
| 2585 | - // array( |
|
| 2586 | - // 'selected_method_of_payment' => $this->checkout->selected_method_of_payment, |
|
| 2587 | - // 'payment_method' => $this->checkout->payment_method, |
|
| 2588 | - // ), |
|
| 2589 | - // true |
|
| 2590 | - // ); |
|
| 2591 | - // verify TXN |
|
| 2592 | - if ($this->checkout->transaction instanceof EE_Transaction) { |
|
| 2593 | - $gateway = $this->checkout->payment_method->type_obj()->get_gateway(); |
|
| 2594 | - if (! $gateway instanceof EE_Offsite_Gateway) { |
|
| 2595 | - $this->checkout->continue_reg = false; |
|
| 2596 | - return false; |
|
| 2597 | - } |
|
| 2598 | - $payment = $this->_process_off_site_payment($gateway); |
|
| 2599 | - $payment = $this->_process_cancelled_payments($payment); |
|
| 2600 | - $payment = $this->_validate_payment($payment); |
|
| 2601 | - // if payment was not declined by the payment gateway or cancelled by the registrant |
|
| 2602 | - if ($this->_process_payment_status($payment, EE_PMT_Base::offsite)) { |
|
| 2603 | - // $this->_setup_redirect_for_next_step(); |
|
| 2604 | - // store that for later |
|
| 2605 | - $this->checkout->payment = $payment; |
|
| 2606 | - // mark this reg step as completed, as long as gateway doesn't use a separate IPN request, |
|
| 2607 | - // because we will complete this step during the IPN processing then |
|
| 2608 | - if ($gateway instanceof EE_Offsite_Gateway && ! $this->handle_IPN_in_this_request()) { |
|
| 2609 | - $this->set_completed(); |
|
| 2610 | - } |
|
| 2611 | - return true; |
|
| 2612 | - } |
|
| 2613 | - } |
|
| 2614 | - // DEBUG LOG |
|
| 2615 | - // $this->checkout->log( |
|
| 2616 | - // __CLASS__, |
|
| 2617 | - // __FUNCTION__, |
|
| 2618 | - // __LINE__, |
|
| 2619 | - // array('payment' => $payment) |
|
| 2620 | - // ); |
|
| 2621 | - $this->checkout->continue_reg = false; |
|
| 2622 | - return false; |
|
| 2623 | - } |
|
| 2624 | - |
|
| 2625 | - |
|
| 2626 | - /** |
|
| 2627 | - * _validate_return |
|
| 2628 | - * |
|
| 2629 | - * @access private |
|
| 2630 | - * @return void |
|
| 2631 | - * @throws EE_Error |
|
| 2632 | - * @throws InvalidArgumentException |
|
| 2633 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 2634 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 2635 | - * @throws \EventEspresso\core\exceptions\InvalidSessionDataException |
|
| 2636 | - */ |
|
| 2637 | - private function _validate_offsite_return() |
|
| 2638 | - { |
|
| 2639 | - $TXN_ID = (int) EE_Registry::instance()->REQ->get('spco_txn', 0); |
|
| 2640 | - if ($TXN_ID !== $this->checkout->transaction->ID()) { |
|
| 2641 | - // Houston... we might have a problem |
|
| 2642 | - $invalid_TXN = false; |
|
| 2643 | - // first gather some info |
|
| 2644 | - $valid_TXN = EEM_Transaction::instance()->get_one_by_ID($TXN_ID); |
|
| 2645 | - $primary_registrant = $valid_TXN instanceof EE_Transaction |
|
| 2646 | - ? $valid_TXN->primary_registration() |
|
| 2647 | - : null; |
|
| 2648 | - // let's start by retrieving the cart for this TXN |
|
| 2649 | - $cart = $this->checkout->get_cart_for_transaction($this->checkout->transaction); |
|
| 2650 | - if ($cart instanceof EE_Cart) { |
|
| 2651 | - // verify that the current cart has tickets |
|
| 2652 | - $tickets = $cart->get_tickets(); |
|
| 2653 | - if (empty($tickets)) { |
|
| 2654 | - $invalid_TXN = true; |
|
| 2655 | - } |
|
| 2656 | - } else { |
|
| 2657 | - $invalid_TXN = true; |
|
| 2658 | - } |
|
| 2659 | - $valid_TXN_SID = $primary_registrant instanceof EE_Registration |
|
| 2660 | - ? $primary_registrant->session_ID() |
|
| 2661 | - : null; |
|
| 2662 | - // validate current Session ID and compare against valid TXN session ID |
|
| 2663 | - if ($invalid_TXN // if this is already true, then skip other checks |
|
| 2664 | - || EE_Session::instance()->id() === null |
|
| 2665 | - || ( |
|
| 2666 | - // WARNING !!! |
|
| 2667 | - // this could be PayPal sending back duplicate requests (ya they do that) |
|
| 2668 | - // or it **could** mean someone is simply registering AGAIN after having just done so |
|
| 2669 | - // so now we need to determine if this current TXN looks valid or not |
|
| 2670 | - // and whether this reg step has even been started ? |
|
| 2671 | - EE_Session::instance()->id() === $valid_TXN_SID |
|
| 2672 | - // really? you're half way through this reg step, but you never started it ? |
|
| 2673 | - && $this->checkout->transaction->reg_step_completed($this->slug()) === false |
|
| 2674 | - ) |
|
| 2675 | - ) { |
|
| 2676 | - $invalid_TXN = true; |
|
| 2677 | - } |
|
| 2678 | - if ($invalid_TXN) { |
|
| 2679 | - // is the valid TXN completed ? |
|
| 2680 | - if ($valid_TXN instanceof EE_Transaction) { |
|
| 2681 | - // has this step even been started ? |
|
| 2682 | - $reg_step_completed = $valid_TXN->reg_step_completed($this->slug()); |
|
| 2683 | - if ($reg_step_completed !== false && $reg_step_completed !== true) { |
|
| 2684 | - // so it **looks** like this is a double request from PayPal |
|
| 2685 | - // so let's try to pick up where we left off |
|
| 2686 | - $this->checkout->transaction = $valid_TXN; |
|
| 2687 | - $this->checkout->refresh_all_entities(true); |
|
| 2688 | - return; |
|
| 2689 | - } |
|
| 2690 | - } |
|
| 2691 | - // you appear to be lost? |
|
| 2692 | - $this->_redirect_wayward_request($primary_registrant); |
|
| 2693 | - } |
|
| 2694 | - } |
|
| 2695 | - } |
|
| 2696 | - |
|
| 2697 | - |
|
| 2698 | - /** |
|
| 2699 | - * _redirect_wayward_request |
|
| 2700 | - * |
|
| 2701 | - * @access private |
|
| 2702 | - * @param \EE_Registration|null $primary_registrant |
|
| 2703 | - * @return bool |
|
| 2704 | - * @throws EE_Error |
|
| 2705 | - * @throws InvalidArgumentException |
|
| 2706 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 2707 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 2708 | - */ |
|
| 2709 | - private function _redirect_wayward_request(EE_Registration $primary_registrant) |
|
| 2710 | - { |
|
| 2711 | - if (! $primary_registrant instanceof EE_Registration) { |
|
| 2712 | - // try redirecting based on the current TXN |
|
| 2713 | - $primary_registrant = $this->checkout->transaction instanceof EE_Transaction |
|
| 2714 | - ? $this->checkout->transaction->primary_registration() |
|
| 2715 | - : null; |
|
| 2716 | - } |
|
| 2717 | - if (! $primary_registrant instanceof EE_Registration) { |
|
| 2718 | - EE_Error::add_error( |
|
| 2719 | - sprintf( |
|
| 2720 | - esc_html__( |
|
| 2721 | - 'Invalid information was received from the Off-Site Payment Processor and your Transaction details could not be retrieved from the database.%1$sPlease try again or contact %2$s for assistance.', |
|
| 2722 | - 'event_espresso' |
|
| 2723 | - ), |
|
| 2724 | - '<br/>', |
|
| 2725 | - EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
| 2726 | - ), |
|
| 2727 | - __FILE__, |
|
| 2728 | - __FUNCTION__, |
|
| 2729 | - __LINE__ |
|
| 2730 | - ); |
|
| 2731 | - return false; |
|
| 2732 | - } |
|
| 2733 | - // make sure transaction is not locked |
|
| 2734 | - $this->checkout->transaction->unlock(); |
|
| 2735 | - wp_safe_redirect( |
|
| 2736 | - add_query_arg( |
|
| 2737 | - array( |
|
| 2738 | - 'e_reg_url_link' => $primary_registrant->reg_url_link(), |
|
| 2739 | - ), |
|
| 2740 | - $this->checkout->thank_you_page_url |
|
| 2741 | - ) |
|
| 2742 | - ); |
|
| 2743 | - exit(); |
|
| 2744 | - } |
|
| 2745 | - |
|
| 2746 | - |
|
| 2747 | - /** |
|
| 2748 | - * _process_off_site_payment |
|
| 2749 | - * |
|
| 2750 | - * @access private |
|
| 2751 | - * @param \EE_Offsite_Gateway $gateway |
|
| 2752 | - * @return EE_Payment |
|
| 2753 | - * @throws EE_Error |
|
| 2754 | - * @throws InvalidArgumentException |
|
| 2755 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 2756 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 2757 | - */ |
|
| 2758 | - private function _process_off_site_payment(EE_Offsite_Gateway $gateway) |
|
| 2759 | - { |
|
| 2760 | - try { |
|
| 2761 | - $request_data = \EE_Registry::instance()->REQ->params(); |
|
| 2762 | - // if gateway uses_separate_IPN_request, then we don't have to process the IPN manually |
|
| 2763 | - $this->set_handle_IPN_in_this_request( |
|
| 2764 | - $gateway->handle_IPN_in_this_request($request_data, false) |
|
| 2765 | - ); |
|
| 2766 | - if ($this->handle_IPN_in_this_request()) { |
|
| 2767 | - // get payment details and process results |
|
| 2768 | - /** @type EE_Payment_Processor $payment_processor */ |
|
| 2769 | - $payment_processor = EE_Registry::instance()->load_core('Payment_Processor'); |
|
| 2770 | - $payment = $payment_processor->process_ipn( |
|
| 2771 | - $request_data, |
|
| 2772 | - $this->checkout->transaction, |
|
| 2773 | - $this->checkout->payment_method, |
|
| 2774 | - true, |
|
| 2775 | - false |
|
| 2776 | - ); |
|
| 2777 | - // $payment_source = 'process_ipn'; |
|
| 2778 | - } else { |
|
| 2779 | - $payment = $this->checkout->transaction->last_payment(); |
|
| 2780 | - // $payment_source = 'last_payment'; |
|
| 2781 | - } |
|
| 2782 | - } catch (Exception $e) { |
|
| 2783 | - // let's just eat the exception and try to move on using any previously set payment info |
|
| 2784 | - $payment = $this->checkout->transaction->last_payment(); |
|
| 2785 | - // $payment_source = 'last_payment after Exception'; |
|
| 2786 | - // but if we STILL don't have a payment object |
|
| 2787 | - if (! $payment instanceof EE_Payment) { |
|
| 2788 | - // then we'll object ! ( not object like a thing... but object like what a lawyer says ! ) |
|
| 2789 | - $this->_handle_payment_processor_exception($e); |
|
| 2790 | - } |
|
| 2791 | - } |
|
| 2792 | - // DEBUG LOG |
|
| 2793 | - // $this->checkout->log( |
|
| 2794 | - // __CLASS__, |
|
| 2795 | - // __FUNCTION__, |
|
| 2796 | - // __LINE__, |
|
| 2797 | - // array( |
|
| 2798 | - // 'process_ipn_payment' => $payment, |
|
| 2799 | - // 'payment_source' => $payment_source, |
|
| 2800 | - // ) |
|
| 2801 | - // ); |
|
| 2802 | - return $payment; |
|
| 2803 | - } |
|
| 2804 | - |
|
| 2805 | - |
|
| 2806 | - /** |
|
| 2807 | - * _process_cancelled_payments |
|
| 2808 | - * just makes sure that the payment status gets updated correctly |
|
| 2809 | - * so tha tan error isn't generated during payment validation |
|
| 2810 | - * |
|
| 2811 | - * @access private |
|
| 2812 | - * @param EE_Payment $payment |
|
| 2813 | - * @return EE_Payment | FALSE |
|
| 2814 | - * @throws \EE_Error |
|
| 2815 | - */ |
|
| 2816 | - private function _process_cancelled_payments($payment = null) |
|
| 2817 | - { |
|
| 2818 | - if ($payment instanceof EE_Payment |
|
| 2819 | - && isset($_REQUEST['ee_cancel_payment']) |
|
| 2820 | - && $payment->status() === EEM_Payment::status_id_failed |
|
| 2821 | - ) { |
|
| 2822 | - $payment->set_status(EEM_Payment::status_id_cancelled); |
|
| 2823 | - } |
|
| 2824 | - return $payment; |
|
| 2825 | - } |
|
| 2826 | - |
|
| 2827 | - |
|
| 2828 | - /** |
|
| 2829 | - * get_transaction_details_for_gateways |
|
| 2830 | - * |
|
| 2831 | - * @access public |
|
| 2832 | - * @return int |
|
| 2833 | - * @throws EE_Error |
|
| 2834 | - * @throws InvalidArgumentException |
|
| 2835 | - * @throws ReflectionException |
|
| 2836 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 2837 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 2838 | - */ |
|
| 2839 | - public function get_transaction_details_for_gateways() |
|
| 2840 | - { |
|
| 2841 | - $txn_details = array(); |
|
| 2842 | - // ya gotta make a choice man |
|
| 2843 | - if (empty($this->checkout->selected_method_of_payment)) { |
|
| 2844 | - $txn_details = array( |
|
| 2845 | - 'error' => esc_html__('Please select a method of payment before proceeding.', 'event_espresso'), |
|
| 2846 | - ); |
|
| 2847 | - } |
|
| 2848 | - // get EE_Payment_Method object |
|
| 2849 | - if (empty($txn_details) |
|
| 2850 | - && |
|
| 2851 | - ! $this->checkout->payment_method = $this->_get_payment_method_for_selected_method_of_payment() |
|
| 2852 | - ) { |
|
| 2853 | - $txn_details = array( |
|
| 2854 | - 'selected_method_of_payment' => $this->checkout->selected_method_of_payment, |
|
| 2855 | - 'error' => esc_html__( |
|
| 2856 | - 'A valid Payment Method could not be determined.', |
|
| 2857 | - 'event_espresso' |
|
| 2858 | - ), |
|
| 2859 | - ); |
|
| 2860 | - } |
|
| 2861 | - if (empty($txn_details) && $this->checkout->transaction instanceof EE_Transaction) { |
|
| 2862 | - $return_url = $this->_get_return_url($this->checkout->payment_method); |
|
| 2863 | - $txn_details = array( |
|
| 2864 | - 'TXN_ID' => $this->checkout->transaction->ID(), |
|
| 2865 | - 'TXN_timestamp' => $this->checkout->transaction->datetime(), |
|
| 2866 | - 'TXN_total' => $this->checkout->transaction->total(), |
|
| 2867 | - 'TXN_paid' => $this->checkout->transaction->paid(), |
|
| 2868 | - 'TXN_reg_steps' => $this->checkout->transaction->reg_steps(), |
|
| 2869 | - 'STS_ID' => $this->checkout->transaction->status_ID(), |
|
| 2870 | - 'PMD_ID' => $this->checkout->transaction->payment_method_ID(), |
|
| 2871 | - 'payment_amount' => $this->checkout->amount_owing, |
|
| 2872 | - 'return_url' => $return_url, |
|
| 2873 | - 'cancel_url' => add_query_arg(array('ee_cancel_payment' => true), $return_url), |
|
| 2874 | - 'notify_url' => EE_Config::instance()->core->txn_page_url( |
|
| 2875 | - array( |
|
| 2876 | - 'e_reg_url_link' => $this->checkout->transaction->primary_registration()->reg_url_link(), |
|
| 2877 | - 'ee_payment_method' => $this->checkout->payment_method->slug(), |
|
| 2878 | - ) |
|
| 2879 | - ), |
|
| 2880 | - ); |
|
| 2881 | - } |
|
| 2882 | - echo wp_json_encode($txn_details); |
|
| 2883 | - exit(); |
|
| 2884 | - } |
|
| 2885 | - |
|
| 2886 | - |
|
| 2887 | - /** |
|
| 2888 | - * __sleep |
|
| 2889 | - * to conserve db space, let's remove the reg_form and the EE_Checkout object from EE_SPCO_Reg_Step objects upon |
|
| 2890 | - * serialization EE_Checkout will handle the reimplementation of itself upon waking, but we won't bother with the |
|
| 2891 | - * reg form, because if needed, it will be regenerated anyways |
|
| 2892 | - * |
|
| 2893 | - * @return array |
|
| 2894 | - */ |
|
| 2895 | - public function __sleep() |
|
| 2896 | - { |
|
| 2897 | - // remove the reg form and the checkout |
|
| 2898 | - return array_diff(array_keys(get_object_vars($this)), array('reg_form', 'checkout', 'line_item_display')); |
|
| 2899 | - } |
|
| 15 | + /** |
|
| 16 | + * @access protected |
|
| 17 | + * @var EE_Line_Item_Display $Line_Item_Display |
|
| 18 | + */ |
|
| 19 | + protected $line_item_display; |
|
| 20 | + |
|
| 21 | + /** |
|
| 22 | + * @access protected |
|
| 23 | + * @var boolean $handle_IPN_in_this_request |
|
| 24 | + */ |
|
| 25 | + protected $handle_IPN_in_this_request = false; |
|
| 26 | + |
|
| 27 | + |
|
| 28 | + /** |
|
| 29 | + * set_hooks - for hooking into EE Core, other modules, etc |
|
| 30 | + * |
|
| 31 | + * @access public |
|
| 32 | + * @return void |
|
| 33 | + */ |
|
| 34 | + public static function set_hooks() |
|
| 35 | + { |
|
| 36 | + add_filter( |
|
| 37 | + 'FHEE__SPCO__EE_Line_Item_Filter_Collection', |
|
| 38 | + array('EE_SPCO_Reg_Step_Payment_Options', 'add_spco_line_item_filters') |
|
| 39 | + ); |
|
| 40 | + add_action( |
|
| 41 | + 'wp_ajax_switch_spco_billing_form', |
|
| 42 | + array('EE_SPCO_Reg_Step_Payment_Options', 'switch_spco_billing_form') |
|
| 43 | + ); |
|
| 44 | + add_action( |
|
| 45 | + 'wp_ajax_nopriv_switch_spco_billing_form', |
|
| 46 | + array('EE_SPCO_Reg_Step_Payment_Options', 'switch_spco_billing_form') |
|
| 47 | + ); |
|
| 48 | + add_action('wp_ajax_save_payer_details', array('EE_SPCO_Reg_Step_Payment_Options', 'save_payer_details')); |
|
| 49 | + add_action( |
|
| 50 | + 'wp_ajax_nopriv_save_payer_details', |
|
| 51 | + array('EE_SPCO_Reg_Step_Payment_Options', 'save_payer_details') |
|
| 52 | + ); |
|
| 53 | + add_action( |
|
| 54 | + 'wp_ajax_get_transaction_details_for_gateways', |
|
| 55 | + array('EE_SPCO_Reg_Step_Payment_Options', 'get_transaction_details') |
|
| 56 | + ); |
|
| 57 | + add_action( |
|
| 58 | + 'wp_ajax_nopriv_get_transaction_details_for_gateways', |
|
| 59 | + array('EE_SPCO_Reg_Step_Payment_Options', 'get_transaction_details') |
|
| 60 | + ); |
|
| 61 | + add_filter( |
|
| 62 | + 'FHEE__EED_Recaptcha___bypass_recaptcha__bypass_request_params_array', |
|
| 63 | + array('EE_SPCO_Reg_Step_Payment_Options', 'bypass_recaptcha_for_load_payment_method'), |
|
| 64 | + 10, |
|
| 65 | + 1 |
|
| 66 | + ); |
|
| 67 | + } |
|
| 68 | + |
|
| 69 | + |
|
| 70 | + /** |
|
| 71 | + * ajax switch_spco_billing_form |
|
| 72 | + * |
|
| 73 | + * @throws \EE_Error |
|
| 74 | + */ |
|
| 75 | + public static function switch_spco_billing_form() |
|
| 76 | + { |
|
| 77 | + EED_Single_Page_Checkout::process_ajax_request('switch_payment_method'); |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + |
|
| 81 | + /** |
|
| 82 | + * ajax save_payer_details |
|
| 83 | + * |
|
| 84 | + * @throws \EE_Error |
|
| 85 | + */ |
|
| 86 | + public static function save_payer_details() |
|
| 87 | + { |
|
| 88 | + EED_Single_Page_Checkout::process_ajax_request('save_payer_details_via_ajax'); |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + |
|
| 92 | + /** |
|
| 93 | + * ajax get_transaction_details |
|
| 94 | + * |
|
| 95 | + * @throws \EE_Error |
|
| 96 | + */ |
|
| 97 | + public static function get_transaction_details() |
|
| 98 | + { |
|
| 99 | + EED_Single_Page_Checkout::process_ajax_request('get_transaction_details_for_gateways'); |
|
| 100 | + } |
|
| 101 | + |
|
| 102 | + |
|
| 103 | + /** |
|
| 104 | + * bypass_recaptcha_for_load_payment_method |
|
| 105 | + * |
|
| 106 | + * @access public |
|
| 107 | + * @return array |
|
| 108 | + * @throws InvalidArgumentException |
|
| 109 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 110 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 111 | + */ |
|
| 112 | + public static function bypass_recaptcha_for_load_payment_method() |
|
| 113 | + { |
|
| 114 | + return array( |
|
| 115 | + 'EESID' => EE_Registry::instance()->SSN->id(), |
|
| 116 | + 'step' => 'payment_options', |
|
| 117 | + 'action' => 'spco_billing_form', |
|
| 118 | + ); |
|
| 119 | + } |
|
| 120 | + |
|
| 121 | + |
|
| 122 | + /** |
|
| 123 | + * class constructor |
|
| 124 | + * |
|
| 125 | + * @access public |
|
| 126 | + * @param EE_Checkout $checkout |
|
| 127 | + */ |
|
| 128 | + public function __construct(EE_Checkout $checkout) |
|
| 129 | + { |
|
| 130 | + $this->_slug = 'payment_options'; |
|
| 131 | + $this->_name = esc_html__('Payment Options', 'event_espresso'); |
|
| 132 | + $this->_template = SPCO_REG_STEPS_PATH . $this->_slug . '/payment_options_main.template.php'; |
|
| 133 | + $this->checkout = $checkout; |
|
| 134 | + $this->_reset_success_message(); |
|
| 135 | + $this->set_instructions( |
|
| 136 | + esc_html__( |
|
| 137 | + 'Please select a method of payment and provide any necessary billing information before proceeding.', |
|
| 138 | + 'event_espresso' |
|
| 139 | + ) |
|
| 140 | + ); |
|
| 141 | + } |
|
| 142 | + |
|
| 143 | + |
|
| 144 | + /** |
|
| 145 | + * @return null |
|
| 146 | + */ |
|
| 147 | + public function line_item_display() |
|
| 148 | + { |
|
| 149 | + return $this->line_item_display; |
|
| 150 | + } |
|
| 151 | + |
|
| 152 | + |
|
| 153 | + /** |
|
| 154 | + * @param null $line_item_display |
|
| 155 | + */ |
|
| 156 | + public function set_line_item_display($line_item_display) |
|
| 157 | + { |
|
| 158 | + $this->line_item_display = $line_item_display; |
|
| 159 | + } |
|
| 160 | + |
|
| 161 | + |
|
| 162 | + /** |
|
| 163 | + * @return boolean |
|
| 164 | + */ |
|
| 165 | + public function handle_IPN_in_this_request() |
|
| 166 | + { |
|
| 167 | + return $this->handle_IPN_in_this_request; |
|
| 168 | + } |
|
| 169 | + |
|
| 170 | + |
|
| 171 | + /** |
|
| 172 | + * @param boolean $handle_IPN_in_this_request |
|
| 173 | + */ |
|
| 174 | + public function set_handle_IPN_in_this_request($handle_IPN_in_this_request) |
|
| 175 | + { |
|
| 176 | + $this->handle_IPN_in_this_request = filter_var($handle_IPN_in_this_request, FILTER_VALIDATE_BOOLEAN); |
|
| 177 | + } |
|
| 178 | + |
|
| 179 | + |
|
| 180 | + /** |
|
| 181 | + * translate_js_strings |
|
| 182 | + * |
|
| 183 | + * @return void |
|
| 184 | + */ |
|
| 185 | + public function translate_js_strings() |
|
| 186 | + { |
|
| 187 | + EE_Registry::$i18n_js_strings['no_payment_method'] = esc_html__( |
|
| 188 | + 'Please select a method of payment in order to continue.', |
|
| 189 | + 'event_espresso' |
|
| 190 | + ); |
|
| 191 | + EE_Registry::$i18n_js_strings['invalid_payment_method'] = esc_html__( |
|
| 192 | + 'A valid method of payment could not be determined. Please refresh the page and try again.', |
|
| 193 | + 'event_espresso' |
|
| 194 | + ); |
|
| 195 | + EE_Registry::$i18n_js_strings['forwarding_to_offsite'] = esc_html__( |
|
| 196 | + 'Forwarding to Secure Payment Provider.', |
|
| 197 | + 'event_espresso' |
|
| 198 | + ); |
|
| 199 | + } |
|
| 200 | + |
|
| 201 | + |
|
| 202 | + /** |
|
| 203 | + * enqueue_styles_and_scripts |
|
| 204 | + * |
|
| 205 | + * @return void |
|
| 206 | + * @throws EE_Error |
|
| 207 | + * @throws InvalidArgumentException |
|
| 208 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 209 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 210 | + */ |
|
| 211 | + public function enqueue_styles_and_scripts() |
|
| 212 | + { |
|
| 213 | + $transaction = $this->checkout->transaction; |
|
| 214 | + // if the transaction isn't set or nothing is owed on it, don't enqueue any JS |
|
| 215 | + if (! $transaction instanceof EE_Transaction || EEH_Money::compare_floats($transaction->remaining(), 0)) { |
|
| 216 | + return; |
|
| 217 | + } |
|
| 218 | + foreach (EEM_Payment_Method::instance()->get_all_for_transaction( |
|
| 219 | + $transaction, |
|
| 220 | + EEM_Payment_Method::scope_cart |
|
| 221 | + ) as $payment_method) { |
|
| 222 | + $type_obj = $payment_method->type_obj(); |
|
| 223 | + if ($type_obj instanceof EE_PMT_Base) { |
|
| 224 | + $billing_form = $type_obj->generate_new_billing_form($transaction); |
|
| 225 | + if ($billing_form instanceof EE_Form_Section_Proper) { |
|
| 226 | + $billing_form->enqueue_js(); |
|
| 227 | + } |
|
| 228 | + } |
|
| 229 | + } |
|
| 230 | + } |
|
| 231 | + |
|
| 232 | + |
|
| 233 | + /** |
|
| 234 | + * initialize_reg_step |
|
| 235 | + * |
|
| 236 | + * @return bool |
|
| 237 | + * @throws EE_Error |
|
| 238 | + * @throws InvalidArgumentException |
|
| 239 | + * @throws ReflectionException |
|
| 240 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 241 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 242 | + */ |
|
| 243 | + public function initialize_reg_step() |
|
| 244 | + { |
|
| 245 | + // TODO: if /when we implement donations, then this will need overriding |
|
| 246 | + if (// don't need payment options for: |
|
| 247 | + // registrations made via the admin |
|
| 248 | + // completed transactions |
|
| 249 | + // overpaid transactions |
|
| 250 | + // $ 0.00 transactions(no payment required) |
|
| 251 | + ! $this->checkout->payment_required() |
|
| 252 | + // but do NOT remove if current action being called belongs to this reg step |
|
| 253 | + && ! is_callable(array($this, $this->checkout->action)) |
|
| 254 | + && ! $this->completed() |
|
| 255 | + ) { |
|
| 256 | + // and if so, then we no longer need the Payment Options step |
|
| 257 | + if ($this->is_current_step()) { |
|
| 258 | + $this->checkout->generate_reg_form = false; |
|
| 259 | + } |
|
| 260 | + $this->checkout->remove_reg_step($this->_slug); |
|
| 261 | + // DEBUG LOG |
|
| 262 | + // $this->checkout->log( __CLASS__, __FUNCTION__, __LINE__ ); |
|
| 263 | + return false; |
|
| 264 | + } |
|
| 265 | + // load EEM_Payment_Method |
|
| 266 | + EE_Registry::instance()->load_model('Payment_Method'); |
|
| 267 | + // get all active payment methods |
|
| 268 | + $this->checkout->available_payment_methods = EEM_Payment_Method::instance()->get_all_for_transaction( |
|
| 269 | + $this->checkout->transaction, |
|
| 270 | + EEM_Payment_Method::scope_cart |
|
| 271 | + ); |
|
| 272 | + return true; |
|
| 273 | + } |
|
| 274 | + |
|
| 275 | + |
|
| 276 | + /** |
|
| 277 | + * @return EE_Form_Section_Proper |
|
| 278 | + * @throws EE_Error |
|
| 279 | + * @throws InvalidArgumentException |
|
| 280 | + * @throws ReflectionException |
|
| 281 | + * @throws \EventEspresso\core\exceptions\EntityNotFoundException |
|
| 282 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 283 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 284 | + * @throws \EventEspresso\core\exceptions\InvalidStatusException |
|
| 285 | + */ |
|
| 286 | + public function generate_reg_form() |
|
| 287 | + { |
|
| 288 | + // reset in case someone changes their mind |
|
| 289 | + $this->_reset_selected_method_of_payment(); |
|
| 290 | + // set some defaults |
|
| 291 | + $this->checkout->selected_method_of_payment = 'payments_closed'; |
|
| 292 | + $registrations_requiring_payment = array(); |
|
| 293 | + $registrations_for_free_events = array(); |
|
| 294 | + $registrations_requiring_pre_approval = array(); |
|
| 295 | + $sold_out_events = array(); |
|
| 296 | + $insufficient_spaces_available = array(); |
|
| 297 | + $no_payment_required = true; |
|
| 298 | + // loop thru registrations to gather info |
|
| 299 | + $registrations = $this->checkout->transaction->registrations($this->checkout->reg_cache_where_params); |
|
| 300 | + $ejected_registrations = EE_SPCO_Reg_Step_Payment_Options::find_registrations_that_lost_their_space( |
|
| 301 | + $registrations, |
|
| 302 | + $this->checkout->revisit |
|
| 303 | + ); |
|
| 304 | + foreach ($registrations as $REG_ID => $registration) { |
|
| 305 | + /** @var $registration EE_Registration */ |
|
| 306 | + // has this registration lost it's space ? |
|
| 307 | + if (isset($ejected_registrations[ $REG_ID ])) { |
|
| 308 | + if ($registration->event()->is_sold_out() || $registration->event()->is_sold_out(true)) { |
|
| 309 | + $sold_out_events[ $registration->event()->ID() ] = $registration->event(); |
|
| 310 | + } else { |
|
| 311 | + $insufficient_spaces_available[ $registration->event()->ID() ] = $registration->event(); |
|
| 312 | + } |
|
| 313 | + continue; |
|
| 314 | + } |
|
| 315 | + // event requires admin approval |
|
| 316 | + if ($registration->status_ID() === EEM_Registration::status_id_not_approved) { |
|
| 317 | + // add event to list of events with pre-approval reg status |
|
| 318 | + $registrations_requiring_pre_approval[ $REG_ID ] = $registration; |
|
| 319 | + do_action( |
|
| 320 | + 'AHEE__EE_SPCO_Reg_Step_Payment_Options__generate_reg_form__event_requires_pre_approval', |
|
| 321 | + $registration->event(), |
|
| 322 | + $this |
|
| 323 | + ); |
|
| 324 | + continue; |
|
| 325 | + } |
|
| 326 | + if ($this->checkout->revisit |
|
| 327 | + && $registration->status_ID() !== EEM_Registration::status_id_approved |
|
| 328 | + && ( |
|
| 329 | + $registration->event()->is_sold_out() |
|
| 330 | + || $registration->event()->is_sold_out(true) |
|
| 331 | + ) |
|
| 332 | + ) { |
|
| 333 | + // add event to list of events that are sold out |
|
| 334 | + $sold_out_events[ $registration->event()->ID() ] = $registration->event(); |
|
| 335 | + do_action( |
|
| 336 | + 'AHEE__EE_SPCO_Reg_Step_Payment_Options__generate_reg_form__sold_out_event', |
|
| 337 | + $registration->event(), |
|
| 338 | + $this |
|
| 339 | + ); |
|
| 340 | + continue; |
|
| 341 | + } |
|
| 342 | + // are they allowed to pay now and is there monies owing? |
|
| 343 | + if ($registration->owes_monies_and_can_pay()) { |
|
| 344 | + $registrations_requiring_payment[ $REG_ID ] = $registration; |
|
| 345 | + do_action( |
|
| 346 | + 'AHEE__EE_SPCO_Reg_Step_Payment_Options__generate_reg_form__event_requires_payment', |
|
| 347 | + $registration->event(), |
|
| 348 | + $this |
|
| 349 | + ); |
|
| 350 | + } elseif (! $this->checkout->revisit |
|
| 351 | + && $registration->status_ID() !== EEM_Registration::status_id_not_approved |
|
| 352 | + && $registration->ticket()->is_free() |
|
| 353 | + ) { |
|
| 354 | + $registrations_for_free_events[ $registration->ticket()->ID() ] = $registration; |
|
| 355 | + } |
|
| 356 | + } |
|
| 357 | + $subsections = array(); |
|
| 358 | + // now decide which template to load |
|
| 359 | + if (! empty($sold_out_events)) { |
|
| 360 | + $subsections['sold_out_events'] = $this->_sold_out_events($sold_out_events); |
|
| 361 | + } |
|
| 362 | + if (! empty($insufficient_spaces_available)) { |
|
| 363 | + $subsections['insufficient_space'] = $this->_insufficient_spaces_available( |
|
| 364 | + $insufficient_spaces_available |
|
| 365 | + ); |
|
| 366 | + } |
|
| 367 | + if (! empty($registrations_requiring_pre_approval)) { |
|
| 368 | + $subsections['registrations_requiring_pre_approval'] = $this->_registrations_requiring_pre_approval( |
|
| 369 | + $registrations_requiring_pre_approval |
|
| 370 | + ); |
|
| 371 | + } |
|
| 372 | + if (! empty($registrations_for_free_events)) { |
|
| 373 | + $subsections['no_payment_required'] = $this->_no_payment_required($registrations_for_free_events); |
|
| 374 | + } |
|
| 375 | + if (! empty($registrations_requiring_payment)) { |
|
| 376 | + if ($this->checkout->amount_owing > 0) { |
|
| 377 | + // autoload Line_Item_Display classes |
|
| 378 | + EEH_Autoloader::register_line_item_filter_autoloaders(); |
|
| 379 | + $line_item_filter_processor = new EE_Line_Item_Filter_Processor( |
|
| 380 | + apply_filters( |
|
| 381 | + 'FHEE__SPCO__EE_Line_Item_Filter_Collection', |
|
| 382 | + new EE_Line_Item_Filter_Collection() |
|
| 383 | + ), |
|
| 384 | + $this->checkout->cart->get_grand_total() |
|
| 385 | + ); |
|
| 386 | + /** @var EE_Line_Item $filtered_line_item_tree */ |
|
| 387 | + $filtered_line_item_tree = $line_item_filter_processor->process(); |
|
| 388 | + EEH_Autoloader::register_line_item_display_autoloaders(); |
|
| 389 | + $this->set_line_item_display(new EE_Line_Item_Display('spco')); |
|
| 390 | + $subsections['payment_options'] = $this->_display_payment_options( |
|
| 391 | + $this->line_item_display->display_line_item( |
|
| 392 | + $filtered_line_item_tree, |
|
| 393 | + array('registrations' => $registrations) |
|
| 394 | + ) |
|
| 395 | + ); |
|
| 396 | + $this->checkout->amount_owing = $filtered_line_item_tree->total(); |
|
| 397 | + $this->_apply_registration_payments_to_amount_owing($registrations); |
|
| 398 | + } |
|
| 399 | + $no_payment_required = false; |
|
| 400 | + } else { |
|
| 401 | + $this->_hide_reg_step_submit_button_if_revisit(); |
|
| 402 | + } |
|
| 403 | + $this->_save_selected_method_of_payment(); |
|
| 404 | + |
|
| 405 | + $subsections['default_hidden_inputs'] = $this->reg_step_hidden_inputs(); |
|
| 406 | + $subsections['extra_hidden_inputs'] = $this->_extra_hidden_inputs($no_payment_required); |
|
| 407 | + |
|
| 408 | + return new EE_Form_Section_Proper( |
|
| 409 | + array( |
|
| 410 | + 'name' => $this->reg_form_name(), |
|
| 411 | + 'html_id' => $this->reg_form_name(), |
|
| 412 | + 'subsections' => $subsections, |
|
| 413 | + 'layout_strategy' => new EE_No_Layout(), |
|
| 414 | + ) |
|
| 415 | + ); |
|
| 416 | + } |
|
| 417 | + |
|
| 418 | + |
|
| 419 | + /** |
|
| 420 | + * add line item filters required for this reg step |
|
| 421 | + * these filters are applied via this line in EE_SPCO_Reg_Step_Payment_Options::set_hooks(): |
|
| 422 | + * add_filter( 'FHEE__SPCO__EE_Line_Item_Filter_Collection', array( 'EE_SPCO_Reg_Step_Payment_Options', |
|
| 423 | + * 'add_spco_line_item_filters' ) ); so any code that wants to use the same set of filters during the |
|
| 424 | + * payment options reg step, can apply these filters via the following: apply_filters( |
|
| 425 | + * 'FHEE__SPCO__EE_Line_Item_Filter_Collection', new EE_Line_Item_Filter_Collection() ) or to an existing |
|
| 426 | + * filter collection by passing that instead of instantiating a new collection |
|
| 427 | + * |
|
| 428 | + * @param \EE_Line_Item_Filter_Collection $line_item_filter_collection |
|
| 429 | + * @return EE_Line_Item_Filter_Collection |
|
| 430 | + * @throws EE_Error |
|
| 431 | + * @throws InvalidArgumentException |
|
| 432 | + * @throws ReflectionException |
|
| 433 | + * @throws \EventEspresso\core\exceptions\EntityNotFoundException |
|
| 434 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 435 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 436 | + * @throws \EventEspresso\core\exceptions\InvalidStatusException |
|
| 437 | + */ |
|
| 438 | + public static function add_spco_line_item_filters(EE_Line_Item_Filter_Collection $line_item_filter_collection) |
|
| 439 | + { |
|
| 440 | + if (! EE_Registry::instance()->SSN instanceof EE_Session) { |
|
| 441 | + return $line_item_filter_collection; |
|
| 442 | + } |
|
| 443 | + if (! EE_Registry::instance()->SSN->checkout() instanceof EE_Checkout) { |
|
| 444 | + return $line_item_filter_collection; |
|
| 445 | + } |
|
| 446 | + if (! EE_Registry::instance()->SSN->checkout()->transaction instanceof EE_Transaction) { |
|
| 447 | + return $line_item_filter_collection; |
|
| 448 | + } |
|
| 449 | + $line_item_filter_collection->add( |
|
| 450 | + new EE_Billable_Line_Item_Filter( |
|
| 451 | + EE_SPCO_Reg_Step_Payment_Options::remove_ejected_registrations( |
|
| 452 | + EE_Registry::instance()->SSN->checkout()->transaction->registrations( |
|
| 453 | + EE_Registry::instance()->SSN->checkout()->reg_cache_where_params |
|
| 454 | + ) |
|
| 455 | + ) |
|
| 456 | + ) |
|
| 457 | + ); |
|
| 458 | + $line_item_filter_collection->add(new EE_Non_Zero_Line_Item_Filter()); |
|
| 459 | + return $line_item_filter_collection; |
|
| 460 | + } |
|
| 461 | + |
|
| 462 | + |
|
| 463 | + /** |
|
| 464 | + * remove_ejected_registrations |
|
| 465 | + * if a registrant has lost their potential space at an event due to lack of payment, |
|
| 466 | + * then this method removes them from the list of registrations being paid for during this request |
|
| 467 | + * |
|
| 468 | + * @param \EE_Registration[] $registrations |
|
| 469 | + * @return EE_Registration[] |
|
| 470 | + * @throws EE_Error |
|
| 471 | + * @throws InvalidArgumentException |
|
| 472 | + * @throws ReflectionException |
|
| 473 | + * @throws \EventEspresso\core\exceptions\EntityNotFoundException |
|
| 474 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 475 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 476 | + * @throws \EventEspresso\core\exceptions\InvalidStatusException |
|
| 477 | + */ |
|
| 478 | + public static function remove_ejected_registrations(array $registrations) |
|
| 479 | + { |
|
| 480 | + $ejected_registrations = EE_SPCO_Reg_Step_Payment_Options::find_registrations_that_lost_their_space( |
|
| 481 | + $registrations, |
|
| 482 | + EE_Registry::instance()->SSN->checkout()->revisit |
|
| 483 | + ); |
|
| 484 | + foreach ($registrations as $REG_ID => $registration) { |
|
| 485 | + // has this registration lost it's space ? |
|
| 486 | + if (isset($ejected_registrations[ $REG_ID ])) { |
|
| 487 | + unset($registrations[ $REG_ID ]); |
|
| 488 | + continue; |
|
| 489 | + } |
|
| 490 | + } |
|
| 491 | + return $registrations; |
|
| 492 | + } |
|
| 493 | + |
|
| 494 | + |
|
| 495 | + /** |
|
| 496 | + * find_registrations_that_lost_their_space |
|
| 497 | + * If a registrant chooses an offline payment method like Invoice, |
|
| 498 | + * then no space is reserved for them at the event until they fully pay fo that site |
|
| 499 | + * (unless the event's default reg status is set to APPROVED) |
|
| 500 | + * if a registrant then later returns to pay, but the number of spaces available has been reduced due to sales, |
|
| 501 | + * then this method will determine which registrations have lost the ability to complete the reg process. |
|
| 502 | + * |
|
| 503 | + * @param \EE_Registration[] $registrations |
|
| 504 | + * @param bool $revisit |
|
| 505 | + * @return array |
|
| 506 | + * @throws EE_Error |
|
| 507 | + * @throws InvalidArgumentException |
|
| 508 | + * @throws ReflectionException |
|
| 509 | + * @throws \EventEspresso\core\exceptions\EntityNotFoundException |
|
| 510 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 511 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 512 | + * @throws \EventEspresso\core\exceptions\InvalidStatusException |
|
| 513 | + */ |
|
| 514 | + public static function find_registrations_that_lost_their_space(array $registrations, $revisit = false) |
|
| 515 | + { |
|
| 516 | + // registrations per event |
|
| 517 | + $event_reg_count = array(); |
|
| 518 | + // spaces left per event |
|
| 519 | + $event_spaces_remaining = array(); |
|
| 520 | + // tickets left sorted by ID |
|
| 521 | + $tickets_remaining = array(); |
|
| 522 | + // registrations that have lost their space |
|
| 523 | + $ejected_registrations = array(); |
|
| 524 | + foreach ($registrations as $REG_ID => $registration) { |
|
| 525 | + if ($registration->status_ID() === EEM_Registration::status_id_approved |
|
| 526 | + || apply_filters( |
|
| 527 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options__find_registrations_that_lost_their_space__allow_reg_payment', |
|
| 528 | + false, |
|
| 529 | + $registration, |
|
| 530 | + $revisit |
|
| 531 | + ) |
|
| 532 | + ) { |
|
| 533 | + continue; |
|
| 534 | + } |
|
| 535 | + $EVT_ID = $registration->event_ID(); |
|
| 536 | + $ticket = $registration->ticket(); |
|
| 537 | + if (! isset($tickets_remaining[ $ticket->ID() ])) { |
|
| 538 | + $tickets_remaining[ $ticket->ID() ] = $ticket->remaining(); |
|
| 539 | + } |
|
| 540 | + if ($tickets_remaining[ $ticket->ID() ] > 0) { |
|
| 541 | + if (! isset($event_reg_count[ $EVT_ID ])) { |
|
| 542 | + $event_reg_count[ $EVT_ID ] = 0; |
|
| 543 | + } |
|
| 544 | + $event_reg_count[ $EVT_ID ]++; |
|
| 545 | + if (! isset($event_spaces_remaining[ $EVT_ID ])) { |
|
| 546 | + $event_spaces_remaining[ $EVT_ID ] = $registration->event()->spaces_remaining_for_sale(); |
|
| 547 | + } |
|
| 548 | + } |
|
| 549 | + if ($revisit |
|
| 550 | + && ($tickets_remaining[ $ticket->ID() ] === 0 |
|
| 551 | + || $event_reg_count[ $EVT_ID ] > $event_spaces_remaining[ $EVT_ID ] |
|
| 552 | + ) |
|
| 553 | + ) { |
|
| 554 | + $ejected_registrations[ $REG_ID ] = $registration->event(); |
|
| 555 | + if ($registration->status_ID() !== EEM_Registration::status_id_wait_list) { |
|
| 556 | + /** @type EE_Registration_Processor $registration_processor */ |
|
| 557 | + $registration_processor = EE_Registry::instance()->load_class('Registration_Processor'); |
|
| 558 | + // at this point, we should have enough details about the registrant to consider the registration |
|
| 559 | + // NOT incomplete |
|
| 560 | + $registration_processor->manually_update_registration_status( |
|
| 561 | + $registration, |
|
| 562 | + EEM_Registration::status_id_wait_list |
|
| 563 | + ); |
|
| 564 | + } |
|
| 565 | + } |
|
| 566 | + } |
|
| 567 | + return $ejected_registrations; |
|
| 568 | + } |
|
| 569 | + |
|
| 570 | + |
|
| 571 | + /** |
|
| 572 | + * _hide_reg_step_submit_button |
|
| 573 | + * removes the html for the reg step submit button |
|
| 574 | + * by replacing it with an empty string via filter callback |
|
| 575 | + * |
|
| 576 | + * @return void |
|
| 577 | + */ |
|
| 578 | + protected function _adjust_registration_status_if_event_old_sold() |
|
| 579 | + { |
|
| 580 | + } |
|
| 581 | + |
|
| 582 | + |
|
| 583 | + /** |
|
| 584 | + * _hide_reg_step_submit_button |
|
| 585 | + * removes the html for the reg step submit button |
|
| 586 | + * by replacing it with an empty string via filter callback |
|
| 587 | + * |
|
| 588 | + * @return void |
|
| 589 | + */ |
|
| 590 | + protected function _hide_reg_step_submit_button_if_revisit() |
|
| 591 | + { |
|
| 592 | + if ($this->checkout->revisit) { |
|
| 593 | + add_filter('FHEE__EE_SPCO_Reg_Step__reg_step_submit_button__sbmt_btn_html', '__return_empty_string'); |
|
| 594 | + } |
|
| 595 | + } |
|
| 596 | + |
|
| 597 | + |
|
| 598 | + /** |
|
| 599 | + * sold_out_events |
|
| 600 | + * displays notices regarding events that have sold out since hte registrant first signed up |
|
| 601 | + * |
|
| 602 | + * @param \EE_Event[] $sold_out_events_array |
|
| 603 | + * @return \EE_Form_Section_Proper |
|
| 604 | + * @throws \EE_Error |
|
| 605 | + */ |
|
| 606 | + private function _sold_out_events($sold_out_events_array = array()) |
|
| 607 | + { |
|
| 608 | + // set some defaults |
|
| 609 | + $this->checkout->selected_method_of_payment = 'events_sold_out'; |
|
| 610 | + $sold_out_events = ''; |
|
| 611 | + foreach ($sold_out_events_array as $sold_out_event) { |
|
| 612 | + $sold_out_events .= EEH_HTML::li( |
|
| 613 | + EEH_HTML::span( |
|
| 614 | + ' ' . $sold_out_event->name(), |
|
| 615 | + '', |
|
| 616 | + 'dashicons dashicons-marker ee-icon-size-16 pink-text' |
|
| 617 | + ) |
|
| 618 | + ); |
|
| 619 | + } |
|
| 620 | + return new EE_Form_Section_Proper( |
|
| 621 | + array( |
|
| 622 | + 'layout_strategy' => new EE_Template_Layout( |
|
| 623 | + array( |
|
| 624 | + 'layout_template_file' => SPCO_REG_STEPS_PATH |
|
| 625 | + . $this->_slug |
|
| 626 | + . '/sold_out_events.template.php', |
|
| 627 | + 'template_args' => apply_filters( |
|
| 628 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options___sold_out_events__template_args', |
|
| 629 | + array( |
|
| 630 | + 'sold_out_events' => $sold_out_events, |
|
| 631 | + 'sold_out_events_msg' => apply_filters( |
|
| 632 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options___sold_out_events__sold_out_events_msg', |
|
| 633 | + sprintf( |
|
| 634 | + esc_html__( |
|
| 635 | + 'It appears that the event you were about to make a payment for has sold out since you first registered. If you have already made a partial payment towards this event, please contact the event administrator for a refund.%3$s%3$s%1$sPlease note that availability can change at any time due to cancellations, so please check back again later if registration for this event(s) is important to you.%2$s', |
|
| 636 | + 'event_espresso' |
|
| 637 | + ), |
|
| 638 | + '<strong>', |
|
| 639 | + '</strong>', |
|
| 640 | + '<br />' |
|
| 641 | + ) |
|
| 642 | + ), |
|
| 643 | + ) |
|
| 644 | + ), |
|
| 645 | + ) |
|
| 646 | + ), |
|
| 647 | + ) |
|
| 648 | + ); |
|
| 649 | + } |
|
| 650 | + |
|
| 651 | + |
|
| 652 | + /** |
|
| 653 | + * _insufficient_spaces_available |
|
| 654 | + * displays notices regarding events that do not have enough remaining spaces |
|
| 655 | + * to satisfy the current number of registrations looking to pay |
|
| 656 | + * |
|
| 657 | + * @param \EE_Event[] $insufficient_spaces_events_array |
|
| 658 | + * @return \EE_Form_Section_Proper |
|
| 659 | + * @throws \EE_Error |
|
| 660 | + */ |
|
| 661 | + private function _insufficient_spaces_available($insufficient_spaces_events_array = array()) |
|
| 662 | + { |
|
| 663 | + // set some defaults |
|
| 664 | + $this->checkout->selected_method_of_payment = 'invoice'; |
|
| 665 | + $insufficient_space_events = ''; |
|
| 666 | + foreach ($insufficient_spaces_events_array as $event) { |
|
| 667 | + if ($event instanceof EE_Event) { |
|
| 668 | + $insufficient_space_events .= EEH_HTML::li( |
|
| 669 | + EEH_HTML::span(' ' . $event->name(), '', 'dashicons dashicons-marker ee-icon-size-16 pink-text') |
|
| 670 | + ); |
|
| 671 | + } |
|
| 672 | + } |
|
| 673 | + return new EE_Form_Section_Proper( |
|
| 674 | + array( |
|
| 675 | + 'subsections' => array( |
|
| 676 | + 'default_hidden_inputs' => $this->reg_step_hidden_inputs(), |
|
| 677 | + 'extra_hidden_inputs' => $this->_extra_hidden_inputs(), |
|
| 678 | + ), |
|
| 679 | + 'layout_strategy' => new EE_Template_Layout( |
|
| 680 | + array( |
|
| 681 | + 'layout_template_file' => SPCO_REG_STEPS_PATH |
|
| 682 | + . $this->_slug |
|
| 683 | + . '/sold_out_events.template.php', |
|
| 684 | + 'template_args' => apply_filters( |
|
| 685 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options___insufficient_spaces_available__template_args', |
|
| 686 | + array( |
|
| 687 | + 'sold_out_events' => $insufficient_space_events, |
|
| 688 | + 'sold_out_events_msg' => apply_filters( |
|
| 689 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options___insufficient_spaces_available__insufficient_space_msg', |
|
| 690 | + esc_html__( |
|
| 691 | + 'It appears that the event you were about to make a payment for has sold additional tickets since you first registered, and there are no longer enough spaces left to accommodate your selections. You may continue to pay and secure the available space(s) remaining, or simply cancel if you no longer wish to purchase. If you have already made a partial payment towards this event, please contact the event administrator for a refund.', |
|
| 692 | + 'event_espresso' |
|
| 693 | + ) |
|
| 694 | + ), |
|
| 695 | + ) |
|
| 696 | + ), |
|
| 697 | + ) |
|
| 698 | + ), |
|
| 699 | + ) |
|
| 700 | + ); |
|
| 701 | + } |
|
| 702 | + |
|
| 703 | + |
|
| 704 | + /** |
|
| 705 | + * registrations_requiring_pre_approval |
|
| 706 | + * |
|
| 707 | + * @param array $registrations_requiring_pre_approval |
|
| 708 | + * @return EE_Form_Section_Proper |
|
| 709 | + * @throws EE_Error |
|
| 710 | + * @throws \EventEspresso\core\exceptions\EntityNotFoundException |
|
| 711 | + */ |
|
| 712 | + private function _registrations_requiring_pre_approval($registrations_requiring_pre_approval = array()) |
|
| 713 | + { |
|
| 714 | + $events_requiring_pre_approval = array(); |
|
| 715 | + foreach ($registrations_requiring_pre_approval as $registration) { |
|
| 716 | + if ($registration instanceof EE_Registration && $registration->event() instanceof EE_Event) { |
|
| 717 | + $events_requiring_pre_approval[ $registration->event()->ID() ] = EEH_HTML::li( |
|
| 718 | + EEH_HTML::span( |
|
| 719 | + '', |
|
| 720 | + '', |
|
| 721 | + 'dashicons dashicons-marker ee-icon-size-16 orange-text' |
|
| 722 | + ) |
|
| 723 | + . EEH_HTML::span($registration->event()->name(), '', 'orange-text') |
|
| 724 | + ); |
|
| 725 | + } |
|
| 726 | + } |
|
| 727 | + return new EE_Form_Section_Proper( |
|
| 728 | + array( |
|
| 729 | + 'layout_strategy' => new EE_Template_Layout( |
|
| 730 | + array( |
|
| 731 | + 'layout_template_file' => SPCO_REG_STEPS_PATH |
|
| 732 | + . $this->_slug |
|
| 733 | + . '/events_requiring_pre_approval.template.php', // layout_template |
|
| 734 | + 'template_args' => apply_filters( |
|
| 735 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options___sold_out_events__template_args', |
|
| 736 | + array( |
|
| 737 | + 'events_requiring_pre_approval' => implode('', $events_requiring_pre_approval), |
|
| 738 | + 'events_requiring_pre_approval_msg' => apply_filters( |
|
| 739 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options___events_requiring_pre_approval__events_requiring_pre_approval_msg', |
|
| 740 | + esc_html__( |
|
| 741 | + 'The following events do not require payment at this time and will not be billed during this transaction. Billing will only occur after the attendee has been approved by the event organizer. You will be notified when your registration has been processed. If this is a free event, then no billing will occur.', |
|
| 742 | + 'event_espresso' |
|
| 743 | + ) |
|
| 744 | + ), |
|
| 745 | + ) |
|
| 746 | + ), |
|
| 747 | + ) |
|
| 748 | + ), |
|
| 749 | + ) |
|
| 750 | + ); |
|
| 751 | + } |
|
| 752 | + |
|
| 753 | + |
|
| 754 | + /** |
|
| 755 | + * _no_payment_required |
|
| 756 | + * |
|
| 757 | + * @param \EE_Event[] $registrations_for_free_events |
|
| 758 | + * @return \EE_Form_Section_Proper |
|
| 759 | + * @throws \EE_Error |
|
| 760 | + */ |
|
| 761 | + private function _no_payment_required($registrations_for_free_events = array()) |
|
| 762 | + { |
|
| 763 | + // set some defaults |
|
| 764 | + $this->checkout->selected_method_of_payment = 'no_payment_required'; |
|
| 765 | + // generate no_payment_required form |
|
| 766 | + return new EE_Form_Section_Proper( |
|
| 767 | + array( |
|
| 768 | + 'layout_strategy' => new EE_Template_Layout( |
|
| 769 | + array( |
|
| 770 | + 'layout_template_file' => SPCO_REG_STEPS_PATH |
|
| 771 | + . $this->_slug |
|
| 772 | + . '/no_payment_required.template.php', // layout_template |
|
| 773 | + 'template_args' => apply_filters( |
|
| 774 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options___no_payment_required__template_args', |
|
| 775 | + array( |
|
| 776 | + 'revisit' => $this->checkout->revisit, |
|
| 777 | + 'registrations' => array(), |
|
| 778 | + 'ticket_count' => array(), |
|
| 779 | + 'registrations_for_free_events' => $registrations_for_free_events, |
|
| 780 | + 'no_payment_required_msg' => EEH_HTML::p( |
|
| 781 | + esc_html__('This is a free event, so no billing will occur.', 'event_espresso') |
|
| 782 | + ), |
|
| 783 | + ) |
|
| 784 | + ), |
|
| 785 | + ) |
|
| 786 | + ), |
|
| 787 | + ) |
|
| 788 | + ); |
|
| 789 | + } |
|
| 790 | + |
|
| 791 | + |
|
| 792 | + /** |
|
| 793 | + * _display_payment_options |
|
| 794 | + * |
|
| 795 | + * @param string $transaction_details |
|
| 796 | + * @return EE_Form_Section_Proper |
|
| 797 | + * @throws EE_Error |
|
| 798 | + * @throws InvalidArgumentException |
|
| 799 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 800 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 801 | + */ |
|
| 802 | + private function _display_payment_options($transaction_details = '') |
|
| 803 | + { |
|
| 804 | + // has method_of_payment been set by no-js user? |
|
| 805 | + $this->checkout->selected_method_of_payment = $this->_get_selected_method_of_payment(); |
|
| 806 | + // build payment options form |
|
| 807 | + return apply_filters( |
|
| 808 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options___display_payment_options__payment_options_form', |
|
| 809 | + new EE_Form_Section_Proper( |
|
| 810 | + array( |
|
| 811 | + 'subsections' => array( |
|
| 812 | + 'before_payment_options' => apply_filters( |
|
| 813 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options___display_payment_options__before_payment_options', |
|
| 814 | + new EE_Form_Section_Proper( |
|
| 815 | + array('layout_strategy' => new EE_Div_Per_Section_Layout()) |
|
| 816 | + ) |
|
| 817 | + ), |
|
| 818 | + 'payment_options' => $this->_setup_payment_options(), |
|
| 819 | + 'after_payment_options' => apply_filters( |
|
| 820 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options___display_payment_options__after_payment_options', |
|
| 821 | + new EE_Form_Section_Proper( |
|
| 822 | + array('layout_strategy' => new EE_Div_Per_Section_Layout()) |
|
| 823 | + ) |
|
| 824 | + ), |
|
| 825 | + ), |
|
| 826 | + 'layout_strategy' => new EE_Template_Layout( |
|
| 827 | + array( |
|
| 828 | + 'layout_template_file' => $this->_template, |
|
| 829 | + 'template_args' => apply_filters( |
|
| 830 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options___display_payment_options__template_args', |
|
| 831 | + array( |
|
| 832 | + 'reg_count' => $this->line_item_display->total_items(), |
|
| 833 | + 'transaction_details' => $transaction_details, |
|
| 834 | + 'available_payment_methods' => array(), |
|
| 835 | + ) |
|
| 836 | + ), |
|
| 837 | + ) |
|
| 838 | + ), |
|
| 839 | + ) |
|
| 840 | + ) |
|
| 841 | + ); |
|
| 842 | + } |
|
| 843 | + |
|
| 844 | + |
|
| 845 | + /** |
|
| 846 | + * _extra_hidden_inputs |
|
| 847 | + * |
|
| 848 | + * @param bool $no_payment_required |
|
| 849 | + * @return \EE_Form_Section_Proper |
|
| 850 | + * @throws \EE_Error |
|
| 851 | + */ |
|
| 852 | + private function _extra_hidden_inputs($no_payment_required = true) |
|
| 853 | + { |
|
| 854 | + return new EE_Form_Section_Proper( |
|
| 855 | + array( |
|
| 856 | + 'html_id' => 'ee-' . $this->slug() . '-extra-hidden-inputs', |
|
| 857 | + 'layout_strategy' => new EE_Div_Per_Section_Layout(), |
|
| 858 | + 'subsections' => array( |
|
| 859 | + 'spco_no_payment_required' => new EE_Hidden_Input( |
|
| 860 | + array( |
|
| 861 | + 'normalization_strategy' => new EE_Boolean_Normalization(), |
|
| 862 | + 'html_name' => 'spco_no_payment_required', |
|
| 863 | + 'html_id' => 'spco-no-payment-required-payment_options', |
|
| 864 | + 'default' => $no_payment_required, |
|
| 865 | + ) |
|
| 866 | + ), |
|
| 867 | + 'spco_transaction_id' => new EE_Fixed_Hidden_Input( |
|
| 868 | + array( |
|
| 869 | + 'normalization_strategy' => new EE_Int_Normalization(), |
|
| 870 | + 'html_name' => 'spco_transaction_id', |
|
| 871 | + 'html_id' => 'spco-transaction-id', |
|
| 872 | + 'default' => $this->checkout->transaction->ID(), |
|
| 873 | + ) |
|
| 874 | + ), |
|
| 875 | + ), |
|
| 876 | + ) |
|
| 877 | + ); |
|
| 878 | + } |
|
| 879 | + |
|
| 880 | + |
|
| 881 | + /** |
|
| 882 | + * _apply_registration_payments_to_amount_owing |
|
| 883 | + * |
|
| 884 | + * @access protected |
|
| 885 | + * @param array $registrations |
|
| 886 | + * @throws EE_Error |
|
| 887 | + */ |
|
| 888 | + protected function _apply_registration_payments_to_amount_owing(array $registrations) |
|
| 889 | + { |
|
| 890 | + $payments = array(); |
|
| 891 | + foreach ($registrations as $registration) { |
|
| 892 | + if ($registration instanceof EE_Registration && $registration->owes_monies_and_can_pay()) { |
|
| 893 | + $payments += $registration->registration_payments(); |
|
| 894 | + } |
|
| 895 | + } |
|
| 896 | + if (! empty($payments)) { |
|
| 897 | + foreach ($payments as $payment) { |
|
| 898 | + if ($payment instanceof EE_Registration_Payment) { |
|
| 899 | + $this->checkout->amount_owing -= $payment->amount(); |
|
| 900 | + } |
|
| 901 | + } |
|
| 902 | + } |
|
| 903 | + } |
|
| 904 | + |
|
| 905 | + |
|
| 906 | + /** |
|
| 907 | + * _reset_selected_method_of_payment |
|
| 908 | + * |
|
| 909 | + * @access private |
|
| 910 | + * @param bool $force_reset |
|
| 911 | + * @return void |
|
| 912 | + * @throws InvalidArgumentException |
|
| 913 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 914 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 915 | + */ |
|
| 916 | + private function _reset_selected_method_of_payment($force_reset = false) |
|
| 917 | + { |
|
| 918 | + $reset_payment_method = $force_reset |
|
| 919 | + ? true |
|
| 920 | + : sanitize_text_field(EE_Registry::instance()->REQ->get('reset_payment_method', false)); |
|
| 921 | + if ($reset_payment_method) { |
|
| 922 | + $this->checkout->selected_method_of_payment = null; |
|
| 923 | + $this->checkout->payment_method = null; |
|
| 924 | + $this->checkout->billing_form = null; |
|
| 925 | + $this->_save_selected_method_of_payment(); |
|
| 926 | + } |
|
| 927 | + } |
|
| 928 | + |
|
| 929 | + |
|
| 930 | + /** |
|
| 931 | + * _save_selected_method_of_payment |
|
| 932 | + * stores the selected_method_of_payment in the session |
|
| 933 | + * so that it's available for all subsequent requests including AJAX |
|
| 934 | + * |
|
| 935 | + * @access private |
|
| 936 | + * @param string $selected_method_of_payment |
|
| 937 | + * @return void |
|
| 938 | + * @throws InvalidArgumentException |
|
| 939 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 940 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 941 | + */ |
|
| 942 | + private function _save_selected_method_of_payment($selected_method_of_payment = '') |
|
| 943 | + { |
|
| 944 | + $selected_method_of_payment = ! empty($selected_method_of_payment) |
|
| 945 | + ? $selected_method_of_payment |
|
| 946 | + : $this->checkout->selected_method_of_payment; |
|
| 947 | + EE_Registry::instance()->SSN->set_session_data( |
|
| 948 | + array('selected_method_of_payment' => $selected_method_of_payment) |
|
| 949 | + ); |
|
| 950 | + } |
|
| 951 | + |
|
| 952 | + |
|
| 953 | + /** |
|
| 954 | + * _setup_payment_options |
|
| 955 | + * |
|
| 956 | + * @return EE_Form_Section_Proper |
|
| 957 | + * @throws EE_Error |
|
| 958 | + * @throws InvalidArgumentException |
|
| 959 | + * @throws ReflectionException |
|
| 960 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 961 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 962 | + */ |
|
| 963 | + public function _setup_payment_options() |
|
| 964 | + { |
|
| 965 | + // load payment method classes |
|
| 966 | + $this->checkout->available_payment_methods = $this->_get_available_payment_methods(); |
|
| 967 | + if (empty($this->checkout->available_payment_methods)) { |
|
| 968 | + EE_Error::add_error( |
|
| 969 | + apply_filters( |
|
| 970 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options___setup_payment_options__error_message_no_payment_methods', |
|
| 971 | + sprintf( |
|
| 972 | + esc_html__( |
|
| 973 | + 'Sorry, you cannot complete your purchase because a payment method is not active.%1$s Please contact %2$s for assistance and provide a description of the problem.', |
|
| 974 | + 'event_espresso' |
|
| 975 | + ), |
|
| 976 | + '<br>', |
|
| 977 | + EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
| 978 | + ) |
|
| 979 | + ), |
|
| 980 | + __FILE__, |
|
| 981 | + __FUNCTION__, |
|
| 982 | + __LINE__ |
|
| 983 | + ); |
|
| 984 | + } |
|
| 985 | + // switch up header depending on number of available payment methods |
|
| 986 | + $payment_method_header = count($this->checkout->available_payment_methods) > 1 |
|
| 987 | + ? apply_filters( |
|
| 988 | + 'FHEE__registration_page_payment_options__method_of_payment_hdr', |
|
| 989 | + esc_html__('Please Select Your Method of Payment', 'event_espresso') |
|
| 990 | + ) |
|
| 991 | + : apply_filters( |
|
| 992 | + 'FHEE__registration_page_payment_options__method_of_payment_hdr', |
|
| 993 | + esc_html__('Method of Payment', 'event_espresso') |
|
| 994 | + ); |
|
| 995 | + $available_payment_methods = array( |
|
| 996 | + // display the "Payment Method" header |
|
| 997 | + 'payment_method_header' => new EE_Form_Section_HTML( |
|
| 998 | + apply_filters( |
|
| 999 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options___setup_payment_options__payment_method_header', |
|
| 1000 | + EEH_HTML::h4($payment_method_header, 'method-of-payment-hdr'), |
|
| 1001 | + $payment_method_header |
|
| 1002 | + ) |
|
| 1003 | + ), |
|
| 1004 | + ); |
|
| 1005 | + // the list of actual payment methods ( invoice, paypal, etc ) in a ( slug => HTML ) format |
|
| 1006 | + $available_payment_method_options = array(); |
|
| 1007 | + $default_payment_method_option = array(); |
|
| 1008 | + // additional instructions to be displayed and hidden below payment methods (adding a clearing div to start) |
|
| 1009 | + $payment_methods_billing_info = array( |
|
| 1010 | + new EE_Form_Section_HTML( |
|
| 1011 | + EEH_HTML::div('<br />', '', '', 'clear:both;') |
|
| 1012 | + ), |
|
| 1013 | + ); |
|
| 1014 | + // loop through payment methods |
|
| 1015 | + foreach ($this->checkout->available_payment_methods as $payment_method) { |
|
| 1016 | + if ($payment_method instanceof EE_Payment_Method) { |
|
| 1017 | + $payment_method_button = EEH_HTML::img( |
|
| 1018 | + $payment_method->button_url(), |
|
| 1019 | + $payment_method->name(), |
|
| 1020 | + 'spco-payment-method-' . $payment_method->slug() . '-btn-img', |
|
| 1021 | + 'spco-payment-method-btn-img' |
|
| 1022 | + ); |
|
| 1023 | + // check if any payment methods are set as default |
|
| 1024 | + // if payment method is already selected OR nothing is selected and this payment method should be |
|
| 1025 | + // open_by_default |
|
| 1026 | + if (($this->checkout->selected_method_of_payment === $payment_method->slug()) |
|
| 1027 | + || (! $this->checkout->selected_method_of_payment && $payment_method->open_by_default()) |
|
| 1028 | + ) { |
|
| 1029 | + $this->checkout->selected_method_of_payment = $payment_method->slug(); |
|
| 1030 | + $this->_save_selected_method_of_payment(); |
|
| 1031 | + $default_payment_method_option[ $payment_method->slug() ] = $payment_method_button; |
|
| 1032 | + } else { |
|
| 1033 | + $available_payment_method_options[ $payment_method->slug() ] = $payment_method_button; |
|
| 1034 | + } |
|
| 1035 | + $payment_methods_billing_info[ $payment_method->slug( |
|
| 1036 | + ) . '-info' ] = $this->_payment_method_billing_info( |
|
| 1037 | + $payment_method |
|
| 1038 | + ); |
|
| 1039 | + } |
|
| 1040 | + } |
|
| 1041 | + // prepend available_payment_method_options with default_payment_method_option so that it appears first in list |
|
| 1042 | + // of PMs |
|
| 1043 | + $available_payment_method_options = $default_payment_method_option + $available_payment_method_options; |
|
| 1044 | + // now generate the actual form inputs |
|
| 1045 | + $available_payment_methods['available_payment_methods'] = $this->_available_payment_method_inputs( |
|
| 1046 | + $available_payment_method_options |
|
| 1047 | + ); |
|
| 1048 | + $available_payment_methods += $payment_methods_billing_info; |
|
| 1049 | + // build the available payment methods form |
|
| 1050 | + return new EE_Form_Section_Proper( |
|
| 1051 | + array( |
|
| 1052 | + 'html_id' => 'spco-available-methods-of-payment-dv', |
|
| 1053 | + 'subsections' => $available_payment_methods, |
|
| 1054 | + 'layout_strategy' => new EE_Div_Per_Section_Layout(), |
|
| 1055 | + ) |
|
| 1056 | + ); |
|
| 1057 | + } |
|
| 1058 | + |
|
| 1059 | + |
|
| 1060 | + /** |
|
| 1061 | + * _get_available_payment_methods |
|
| 1062 | + * |
|
| 1063 | + * @return EE_Payment_Method[] |
|
| 1064 | + * @throws EE_Error |
|
| 1065 | + * @throws InvalidArgumentException |
|
| 1066 | + * @throws ReflectionException |
|
| 1067 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 1068 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 1069 | + */ |
|
| 1070 | + protected function _get_available_payment_methods() |
|
| 1071 | + { |
|
| 1072 | + if (! empty($this->checkout->available_payment_methods)) { |
|
| 1073 | + return $this->checkout->available_payment_methods; |
|
| 1074 | + } |
|
| 1075 | + $available_payment_methods = array(); |
|
| 1076 | + // load EEM_Payment_Method |
|
| 1077 | + EE_Registry::instance()->load_model('Payment_Method'); |
|
| 1078 | + /** @type EEM_Payment_Method $EEM_Payment_Method */ |
|
| 1079 | + $EEM_Payment_Method = EE_Registry::instance()->LIB->EEM_Payment_Method; |
|
| 1080 | + // get all active payment methods |
|
| 1081 | + $payment_methods = $EEM_Payment_Method->get_all_for_transaction( |
|
| 1082 | + $this->checkout->transaction, |
|
| 1083 | + EEM_Payment_Method::scope_cart |
|
| 1084 | + ); |
|
| 1085 | + foreach ($payment_methods as $payment_method) { |
|
| 1086 | + if ($payment_method instanceof EE_Payment_Method) { |
|
| 1087 | + $available_payment_methods[ $payment_method->slug() ] = $payment_method; |
|
| 1088 | + } |
|
| 1089 | + } |
|
| 1090 | + return $available_payment_methods; |
|
| 1091 | + } |
|
| 1092 | + |
|
| 1093 | + |
|
| 1094 | + /** |
|
| 1095 | + * _available_payment_method_inputs |
|
| 1096 | + * |
|
| 1097 | + * @access private |
|
| 1098 | + * @param array $available_payment_method_options |
|
| 1099 | + * @return \EE_Form_Section_Proper |
|
| 1100 | + */ |
|
| 1101 | + private function _available_payment_method_inputs($available_payment_method_options = array()) |
|
| 1102 | + { |
|
| 1103 | + // generate inputs |
|
| 1104 | + return new EE_Form_Section_Proper( |
|
| 1105 | + array( |
|
| 1106 | + 'html_id' => 'ee-available-payment-method-inputs', |
|
| 1107 | + 'layout_strategy' => new EE_Div_Per_Section_Layout(), |
|
| 1108 | + 'subsections' => array( |
|
| 1109 | + '' => new EE_Radio_Button_Input( |
|
| 1110 | + $available_payment_method_options, |
|
| 1111 | + array( |
|
| 1112 | + 'html_name' => 'selected_method_of_payment', |
|
| 1113 | + 'html_class' => 'spco-payment-method', |
|
| 1114 | + 'default' => $this->checkout->selected_method_of_payment, |
|
| 1115 | + 'label_size' => 11, |
|
| 1116 | + 'enforce_label_size' => true, |
|
| 1117 | + ) |
|
| 1118 | + ), |
|
| 1119 | + ), |
|
| 1120 | + ) |
|
| 1121 | + ); |
|
| 1122 | + } |
|
| 1123 | + |
|
| 1124 | + |
|
| 1125 | + /** |
|
| 1126 | + * _payment_method_billing_info |
|
| 1127 | + * |
|
| 1128 | + * @access private |
|
| 1129 | + * @param EE_Payment_Method $payment_method |
|
| 1130 | + * @return EE_Form_Section_Proper |
|
| 1131 | + * @throws EE_Error |
|
| 1132 | + * @throws InvalidArgumentException |
|
| 1133 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 1134 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 1135 | + */ |
|
| 1136 | + private function _payment_method_billing_info(EE_Payment_Method $payment_method) |
|
| 1137 | + { |
|
| 1138 | + $currently_selected = $this->checkout->selected_method_of_payment === $payment_method->slug() |
|
| 1139 | + ? true |
|
| 1140 | + : false; |
|
| 1141 | + // generate the billing form for payment method |
|
| 1142 | + $billing_form = $currently_selected |
|
| 1143 | + ? $this->_get_billing_form_for_payment_method($payment_method) |
|
| 1144 | + : new EE_Form_Section_HTML(); |
|
| 1145 | + $this->checkout->billing_form = $currently_selected |
|
| 1146 | + ? $billing_form |
|
| 1147 | + : $this->checkout->billing_form; |
|
| 1148 | + // it's all in the details |
|
| 1149 | + $info_html = EEH_HTML::h3( |
|
| 1150 | + esc_html__('Important information regarding your payment', 'event_espresso'), |
|
| 1151 | + '', |
|
| 1152 | + 'spco-payment-method-hdr' |
|
| 1153 | + ); |
|
| 1154 | + // add some info regarding the step, either from what's saved in the admin, |
|
| 1155 | + // or a default string depending on whether the PM has a billing form or not |
|
| 1156 | + if ($payment_method->description()) { |
|
| 1157 | + $payment_method_info = $payment_method->description(); |
|
| 1158 | + } elseif ($billing_form instanceof EE_Billing_Info_Form) { |
|
| 1159 | + $payment_method_info = sprintf( |
|
| 1160 | + esc_html__( |
|
| 1161 | + 'Please provide the following billing information, then click the "%1$s" button below in order to proceed.', |
|
| 1162 | + 'event_espresso' |
|
| 1163 | + ), |
|
| 1164 | + $this->submit_button_text() |
|
| 1165 | + ); |
|
| 1166 | + } else { |
|
| 1167 | + $payment_method_info = sprintf( |
|
| 1168 | + esc_html__('Please click the "%1$s" button below in order to proceed.', 'event_espresso'), |
|
| 1169 | + $this->submit_button_text() |
|
| 1170 | + ); |
|
| 1171 | + } |
|
| 1172 | + $info_html .= EEH_HTML::div( |
|
| 1173 | + apply_filters( |
|
| 1174 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options___payment_method_billing_info__payment_method_info', |
|
| 1175 | + $payment_method_info |
|
| 1176 | + ), |
|
| 1177 | + '', |
|
| 1178 | + 'spco-payment-method-desc ee-attention' |
|
| 1179 | + ); |
|
| 1180 | + return new EE_Form_Section_Proper( |
|
| 1181 | + array( |
|
| 1182 | + 'html_id' => 'spco-payment-method-info-' . $payment_method->slug(), |
|
| 1183 | + 'html_class' => 'spco-payment-method-info-dv', |
|
| 1184 | + // only display the selected or default PM |
|
| 1185 | + 'html_style' => $currently_selected ? '' : 'display:none;', |
|
| 1186 | + 'layout_strategy' => new EE_Div_Per_Section_Layout(), |
|
| 1187 | + 'subsections' => array( |
|
| 1188 | + 'info' => new EE_Form_Section_HTML($info_html), |
|
| 1189 | + 'billing_form' => $currently_selected ? $billing_form : new EE_Form_Section_HTML(), |
|
| 1190 | + ), |
|
| 1191 | + ) |
|
| 1192 | + ); |
|
| 1193 | + } |
|
| 1194 | + |
|
| 1195 | + |
|
| 1196 | + /** |
|
| 1197 | + * get_billing_form_html_for_payment_method |
|
| 1198 | + * |
|
| 1199 | + * @access public |
|
| 1200 | + * @return string |
|
| 1201 | + * @throws EE_Error |
|
| 1202 | + * @throws InvalidArgumentException |
|
| 1203 | + * @throws ReflectionException |
|
| 1204 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 1205 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 1206 | + */ |
|
| 1207 | + public function get_billing_form_html_for_payment_method() |
|
| 1208 | + { |
|
| 1209 | + // how have they chosen to pay? |
|
| 1210 | + $this->checkout->selected_method_of_payment = $this->_get_selected_method_of_payment(true); |
|
| 1211 | + $this->checkout->payment_method = $this->_get_payment_method_for_selected_method_of_payment(); |
|
| 1212 | + if (! $this->checkout->payment_method instanceof EE_Payment_Method) { |
|
| 1213 | + return false; |
|
| 1214 | + } |
|
| 1215 | + if (apply_filters( |
|
| 1216 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options__registration_checkout__selected_payment_method__display_success', |
|
| 1217 | + false |
|
| 1218 | + )) { |
|
| 1219 | + EE_Error::add_success( |
|
| 1220 | + apply_filters( |
|
| 1221 | + 'FHEE__Single_Page_Checkout__registration_checkout__selected_payment_method', |
|
| 1222 | + sprintf( |
|
| 1223 | + esc_html__( |
|
| 1224 | + 'You have selected "%s" as your method of payment. Please note the important payment information below.', |
|
| 1225 | + 'event_espresso' |
|
| 1226 | + ), |
|
| 1227 | + $this->checkout->payment_method->name() |
|
| 1228 | + ) |
|
| 1229 | + ) |
|
| 1230 | + ); |
|
| 1231 | + } |
|
| 1232 | + // now generate billing form for selected method of payment |
|
| 1233 | + $payment_method_billing_form = $this->_get_billing_form_for_payment_method($this->checkout->payment_method); |
|
| 1234 | + // fill form with attendee info if applicable |
|
| 1235 | + if ($payment_method_billing_form instanceof EE_Billing_Attendee_Info_Form |
|
| 1236 | + && $this->checkout->transaction_has_primary_registrant() |
|
| 1237 | + ) { |
|
| 1238 | + $payment_method_billing_form->populate_from_attendee( |
|
| 1239 | + $this->checkout->transaction->primary_registration()->attendee() |
|
| 1240 | + ); |
|
| 1241 | + } |
|
| 1242 | + // and debug content |
|
| 1243 | + if ($payment_method_billing_form instanceof EE_Billing_Info_Form |
|
| 1244 | + && $this->checkout->payment_method->type_obj() instanceof EE_PMT_Base |
|
| 1245 | + ) { |
|
| 1246 | + $payment_method_billing_form = |
|
| 1247 | + $this->checkout->payment_method->type_obj()->apply_billing_form_debug_settings( |
|
| 1248 | + $payment_method_billing_form |
|
| 1249 | + ); |
|
| 1250 | + } |
|
| 1251 | + $billing_info = $payment_method_billing_form instanceof EE_Form_Section_Proper |
|
| 1252 | + ? $payment_method_billing_form->get_html() |
|
| 1253 | + : ''; |
|
| 1254 | + $this->checkout->json_response->set_return_data(array('payment_method_info' => $billing_info)); |
|
| 1255 | + // localize validation rules for main form |
|
| 1256 | + $this->checkout->current_step->reg_form->localize_validation_rules(); |
|
| 1257 | + $this->checkout->json_response->add_validation_rules(EE_Form_Section_Proper::js_localization()); |
|
| 1258 | + return true; |
|
| 1259 | + } |
|
| 1260 | + |
|
| 1261 | + |
|
| 1262 | + /** |
|
| 1263 | + * _get_billing_form_for_payment_method |
|
| 1264 | + * |
|
| 1265 | + * @access private |
|
| 1266 | + * @param EE_Payment_Method $payment_method |
|
| 1267 | + * @return EE_Billing_Info_Form|EE_Form_Section_HTML |
|
| 1268 | + * @throws EE_Error |
|
| 1269 | + * @throws InvalidArgumentException |
|
| 1270 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 1271 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 1272 | + */ |
|
| 1273 | + private function _get_billing_form_for_payment_method(EE_Payment_Method $payment_method) |
|
| 1274 | + { |
|
| 1275 | + $billing_form = $payment_method->type_obj()->billing_form( |
|
| 1276 | + $this->checkout->transaction, |
|
| 1277 | + array('amount_owing' => $this->checkout->amount_owing) |
|
| 1278 | + ); |
|
| 1279 | + if ($billing_form instanceof EE_Billing_Info_Form) { |
|
| 1280 | + if (apply_filters( |
|
| 1281 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options__registration_checkout__selected_payment_method__display_success', |
|
| 1282 | + false |
|
| 1283 | + ) |
|
| 1284 | + && EE_Registry::instance()->REQ->is_set('payment_method') |
|
| 1285 | + ) { |
|
| 1286 | + EE_Error::add_success( |
|
| 1287 | + apply_filters( |
|
| 1288 | + 'FHEE__Single_Page_Checkout__registration_checkout__selected_payment_method', |
|
| 1289 | + sprintf( |
|
| 1290 | + esc_html__( |
|
| 1291 | + 'You have selected "%s" as your method of payment. Please note the important payment information below.', |
|
| 1292 | + 'event_espresso' |
|
| 1293 | + ), |
|
| 1294 | + $payment_method->name() |
|
| 1295 | + ) |
|
| 1296 | + ) |
|
| 1297 | + ); |
|
| 1298 | + } |
|
| 1299 | + return apply_filters( |
|
| 1300 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options___get_billing_form_for_payment_method__billing_form', |
|
| 1301 | + $billing_form, |
|
| 1302 | + $payment_method |
|
| 1303 | + ); |
|
| 1304 | + } |
|
| 1305 | + // no actual billing form, so return empty HTML form section |
|
| 1306 | + return new EE_Form_Section_HTML(); |
|
| 1307 | + } |
|
| 1308 | + |
|
| 1309 | + |
|
| 1310 | + /** |
|
| 1311 | + * _get_selected_method_of_payment |
|
| 1312 | + * |
|
| 1313 | + * @access private |
|
| 1314 | + * @param boolean $required whether to throw an error if the "selected_method_of_payment" |
|
| 1315 | + * is not found in the incoming request |
|
| 1316 | + * @param string $request_param |
|
| 1317 | + * @return NULL|string |
|
| 1318 | + * @throws EE_Error |
|
| 1319 | + * @throws InvalidArgumentException |
|
| 1320 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 1321 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 1322 | + */ |
|
| 1323 | + private function _get_selected_method_of_payment( |
|
| 1324 | + $required = false, |
|
| 1325 | + $request_param = 'selected_method_of_payment' |
|
| 1326 | + ) { |
|
| 1327 | + // is selected_method_of_payment set in the request ? |
|
| 1328 | + $selected_method_of_payment = EE_Registry::instance()->REQ->get($request_param, false); |
|
| 1329 | + if ($selected_method_of_payment) { |
|
| 1330 | + // sanitize it |
|
| 1331 | + $selected_method_of_payment = is_array($selected_method_of_payment) |
|
| 1332 | + ? array_shift($selected_method_of_payment) |
|
| 1333 | + : $selected_method_of_payment; |
|
| 1334 | + $selected_method_of_payment = sanitize_text_field($selected_method_of_payment); |
|
| 1335 | + // store it in the session so that it's available for all subsequent requests including AJAX |
|
| 1336 | + $this->_save_selected_method_of_payment($selected_method_of_payment); |
|
| 1337 | + } else { |
|
| 1338 | + // or is is set in the session ? |
|
| 1339 | + $selected_method_of_payment = EE_Registry::instance()->SSN->get_session_data( |
|
| 1340 | + 'selected_method_of_payment' |
|
| 1341 | + ); |
|
| 1342 | + } |
|
| 1343 | + // do ya really really gotta have it? |
|
| 1344 | + if (empty($selected_method_of_payment) && $required) { |
|
| 1345 | + EE_Error::add_error( |
|
| 1346 | + sprintf( |
|
| 1347 | + esc_html__( |
|
| 1348 | + 'The selected method of payment could not be determined.%sPlease ensure that you have selected one before proceeding.%sIf you continue to experience difficulties, then refresh your browser and try again, or contact %s for assistance.', |
|
| 1349 | + 'event_espresso' |
|
| 1350 | + ), |
|
| 1351 | + '<br/>', |
|
| 1352 | + '<br/>', |
|
| 1353 | + EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
| 1354 | + ), |
|
| 1355 | + __FILE__, |
|
| 1356 | + __FUNCTION__, |
|
| 1357 | + __LINE__ |
|
| 1358 | + ); |
|
| 1359 | + return null; |
|
| 1360 | + } |
|
| 1361 | + return $selected_method_of_payment; |
|
| 1362 | + } |
|
| 1363 | + |
|
| 1364 | + |
|
| 1365 | + |
|
| 1366 | + |
|
| 1367 | + |
|
| 1368 | + |
|
| 1369 | + /********************************************************************************************************/ |
|
| 1370 | + /*********************************** SWITCH PAYMENT METHOD ************************************/ |
|
| 1371 | + /********************************************************************************************************/ |
|
| 1372 | + /** |
|
| 1373 | + * switch_payment_method |
|
| 1374 | + * |
|
| 1375 | + * @access public |
|
| 1376 | + * @return string |
|
| 1377 | + * @throws EE_Error |
|
| 1378 | + * @throws InvalidArgumentException |
|
| 1379 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 1380 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 1381 | + */ |
|
| 1382 | + public function switch_payment_method() |
|
| 1383 | + { |
|
| 1384 | + if (! $this->_verify_payment_method_is_set()) { |
|
| 1385 | + return false; |
|
| 1386 | + } |
|
| 1387 | + if (apply_filters( |
|
| 1388 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options__registration_checkout__selected_payment_method__display_success', |
|
| 1389 | + false |
|
| 1390 | + )) { |
|
| 1391 | + EE_Error::add_success( |
|
| 1392 | + apply_filters( |
|
| 1393 | + 'FHEE__Single_Page_Checkout__registration_checkout__selected_payment_method', |
|
| 1394 | + sprintf( |
|
| 1395 | + esc_html__( |
|
| 1396 | + 'You have selected "%s" as your method of payment. Please note the important payment information below.', |
|
| 1397 | + 'event_espresso' |
|
| 1398 | + ), |
|
| 1399 | + $this->checkout->payment_method->name() |
|
| 1400 | + ) |
|
| 1401 | + ) |
|
| 1402 | + ); |
|
| 1403 | + } |
|
| 1404 | + // generate billing form for selected method of payment if it hasn't been done already |
|
| 1405 | + if ($this->checkout->payment_method->type_obj()->has_billing_form()) { |
|
| 1406 | + $this->checkout->billing_form = $this->_get_billing_form_for_payment_method( |
|
| 1407 | + $this->checkout->payment_method |
|
| 1408 | + ); |
|
| 1409 | + } |
|
| 1410 | + // fill form with attendee info if applicable |
|
| 1411 | + if (apply_filters( |
|
| 1412 | + 'FHEE__populate_billing_form_fields_from_attendee', |
|
| 1413 | + ( |
|
| 1414 | + $this->checkout->billing_form instanceof EE_Billing_Attendee_Info_Form |
|
| 1415 | + && $this->checkout->transaction_has_primary_registrant() |
|
| 1416 | + ), |
|
| 1417 | + $this->checkout->billing_form, |
|
| 1418 | + $this->checkout->transaction |
|
| 1419 | + ) |
|
| 1420 | + ) { |
|
| 1421 | + $this->checkout->billing_form->populate_from_attendee( |
|
| 1422 | + $this->checkout->transaction->primary_registration()->attendee() |
|
| 1423 | + ); |
|
| 1424 | + } |
|
| 1425 | + // and debug content |
|
| 1426 | + if ($this->checkout->billing_form instanceof EE_Billing_Info_Form |
|
| 1427 | + && $this->checkout->payment_method->type_obj() instanceof EE_PMT_Base |
|
| 1428 | + ) { |
|
| 1429 | + $this->checkout->billing_form = |
|
| 1430 | + $this->checkout->payment_method->type_obj()->apply_billing_form_debug_settings( |
|
| 1431 | + $this->checkout->billing_form |
|
| 1432 | + ); |
|
| 1433 | + } |
|
| 1434 | + // get html and validation rules for form |
|
| 1435 | + if ($this->checkout->billing_form instanceof EE_Form_Section_Proper) { |
|
| 1436 | + $this->checkout->json_response->set_return_data( |
|
| 1437 | + array('payment_method_info' => $this->checkout->billing_form->get_html()) |
|
| 1438 | + ); |
|
| 1439 | + // localize validation rules for main form |
|
| 1440 | + $this->checkout->billing_form->localize_validation_rules(true); |
|
| 1441 | + $this->checkout->json_response->add_validation_rules(EE_Form_Section_Proper::js_localization()); |
|
| 1442 | + } else { |
|
| 1443 | + $this->checkout->json_response->set_return_data(array('payment_method_info' => '')); |
|
| 1444 | + } |
|
| 1445 | + // prevents advancement to next step |
|
| 1446 | + $this->checkout->continue_reg = false; |
|
| 1447 | + return true; |
|
| 1448 | + } |
|
| 1449 | + |
|
| 1450 | + |
|
| 1451 | + /** |
|
| 1452 | + * _verify_payment_method_is_set |
|
| 1453 | + * |
|
| 1454 | + * @return bool |
|
| 1455 | + * @throws EE_Error |
|
| 1456 | + * @throws InvalidArgumentException |
|
| 1457 | + * @throws ReflectionException |
|
| 1458 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 1459 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 1460 | + */ |
|
| 1461 | + protected function _verify_payment_method_is_set() |
|
| 1462 | + { |
|
| 1463 | + // generate billing form for selected method of payment if it hasn't been done already |
|
| 1464 | + if (empty($this->checkout->selected_method_of_payment)) { |
|
| 1465 | + // how have they chosen to pay? |
|
| 1466 | + $this->checkout->selected_method_of_payment = $this->_get_selected_method_of_payment(true); |
|
| 1467 | + } else { |
|
| 1468 | + // choose your own adventure based on method_of_payment |
|
| 1469 | + switch ($this->checkout->selected_method_of_payment) { |
|
| 1470 | + case 'events_sold_out': |
|
| 1471 | + EE_Error::add_attention( |
|
| 1472 | + apply_filters( |
|
| 1473 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options___verify_payment_method_is_set__sold_out_events_msg', |
|
| 1474 | + esc_html__( |
|
| 1475 | + 'It appears that the event you were about to make a payment for has sold out since this form first loaded. Please contact the event administrator if you believe this is an error.', |
|
| 1476 | + 'event_espresso' |
|
| 1477 | + ) |
|
| 1478 | + ), |
|
| 1479 | + __FILE__, |
|
| 1480 | + __FUNCTION__, |
|
| 1481 | + __LINE__ |
|
| 1482 | + ); |
|
| 1483 | + return false; |
|
| 1484 | + break; |
|
| 1485 | + case 'payments_closed': |
|
| 1486 | + EE_Error::add_attention( |
|
| 1487 | + apply_filters( |
|
| 1488 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options___verify_payment_method_is_set__payments_closed_msg', |
|
| 1489 | + esc_html__( |
|
| 1490 | + 'It appears that the event you were about to make a payment for is not accepting payments at this time. Please contact the event administrator if you believe this is an error.', |
|
| 1491 | + 'event_espresso' |
|
| 1492 | + ) |
|
| 1493 | + ), |
|
| 1494 | + __FILE__, |
|
| 1495 | + __FUNCTION__, |
|
| 1496 | + __LINE__ |
|
| 1497 | + ); |
|
| 1498 | + return false; |
|
| 1499 | + break; |
|
| 1500 | + case 'no_payment_required': |
|
| 1501 | + EE_Error::add_attention( |
|
| 1502 | + apply_filters( |
|
| 1503 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options___verify_payment_method_is_set__no_payment_required_msg', |
|
| 1504 | + esc_html__( |
|
| 1505 | + 'It appears that the event you were about to make a payment for does not require payment. Please contact the event administrator if you believe this is an error.', |
|
| 1506 | + 'event_espresso' |
|
| 1507 | + ) |
|
| 1508 | + ), |
|
| 1509 | + __FILE__, |
|
| 1510 | + __FUNCTION__, |
|
| 1511 | + __LINE__ |
|
| 1512 | + ); |
|
| 1513 | + return false; |
|
| 1514 | + break; |
|
| 1515 | + default: |
|
| 1516 | + } |
|
| 1517 | + } |
|
| 1518 | + // verify payment method |
|
| 1519 | + if (! $this->checkout->payment_method instanceof EE_Payment_Method) { |
|
| 1520 | + // get payment method for selected method of payment |
|
| 1521 | + $this->checkout->payment_method = $this->_get_payment_method_for_selected_method_of_payment(); |
|
| 1522 | + } |
|
| 1523 | + return $this->checkout->payment_method instanceof EE_Payment_Method ? true : false; |
|
| 1524 | + } |
|
| 1525 | + |
|
| 1526 | + |
|
| 1527 | + |
|
| 1528 | + /********************************************************************************************************/ |
|
| 1529 | + /*************************************** SAVE PAYER DETAILS ****************************************/ |
|
| 1530 | + /********************************************************************************************************/ |
|
| 1531 | + /** |
|
| 1532 | + * save_payer_details_via_ajax |
|
| 1533 | + * |
|
| 1534 | + * @return void |
|
| 1535 | + * @throws EE_Error |
|
| 1536 | + * @throws InvalidArgumentException |
|
| 1537 | + * @throws ReflectionException |
|
| 1538 | + * @throws RuntimeException |
|
| 1539 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 1540 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 1541 | + */ |
|
| 1542 | + public function save_payer_details_via_ajax() |
|
| 1543 | + { |
|
| 1544 | + if (! $this->_verify_payment_method_is_set()) { |
|
| 1545 | + return; |
|
| 1546 | + } |
|
| 1547 | + // generate billing form for selected method of payment if it hasn't been done already |
|
| 1548 | + if ($this->checkout->payment_method->type_obj()->has_billing_form()) { |
|
| 1549 | + $this->checkout->billing_form = $this->_get_billing_form_for_payment_method( |
|
| 1550 | + $this->checkout->payment_method |
|
| 1551 | + ); |
|
| 1552 | + } |
|
| 1553 | + // generate primary attendee from payer info if applicable |
|
| 1554 | + if (! $this->checkout->transaction_has_primary_registrant()) { |
|
| 1555 | + $attendee = $this->_create_attendee_from_request_data(); |
|
| 1556 | + if ($attendee instanceof EE_Attendee) { |
|
| 1557 | + foreach ($this->checkout->transaction->registrations() as $registration) { |
|
| 1558 | + if ($registration->is_primary_registrant()) { |
|
| 1559 | + $this->checkout->primary_attendee_obj = $attendee; |
|
| 1560 | + $registration->_add_relation_to($attendee, 'Attendee'); |
|
| 1561 | + $registration->set_attendee_id($attendee->ID()); |
|
| 1562 | + $registration->update_cache_after_object_save('Attendee', $attendee); |
|
| 1563 | + } |
|
| 1564 | + } |
|
| 1565 | + } |
|
| 1566 | + } |
|
| 1567 | + } |
|
| 1568 | + |
|
| 1569 | + |
|
| 1570 | + /** |
|
| 1571 | + * create_attendee_from_request_data |
|
| 1572 | + * uses info from alternate GET or POST data (such as AJAX) to create a new attendee |
|
| 1573 | + * |
|
| 1574 | + * @return EE_Attendee |
|
| 1575 | + * @throws EE_Error |
|
| 1576 | + * @throws InvalidArgumentException |
|
| 1577 | + * @throws ReflectionException |
|
| 1578 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 1579 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 1580 | + */ |
|
| 1581 | + protected function _create_attendee_from_request_data() |
|
| 1582 | + { |
|
| 1583 | + // get State ID |
|
| 1584 | + $STA_ID = ! empty($_REQUEST['state']) ? sanitize_text_field($_REQUEST['state']) : ''; |
|
| 1585 | + if (! empty($STA_ID)) { |
|
| 1586 | + // can we get state object from name ? |
|
| 1587 | + EE_Registry::instance()->load_model('State'); |
|
| 1588 | + $state = EEM_State::instance()->get_col(array(array('STA_name' => $STA_ID), 'limit' => 1), 'STA_ID'); |
|
| 1589 | + $STA_ID = is_array($state) && ! empty($state) ? reset($state) : $STA_ID; |
|
| 1590 | + } |
|
| 1591 | + // get Country ISO |
|
| 1592 | + $CNT_ISO = ! empty($_REQUEST['country']) ? sanitize_text_field($_REQUEST['country']) : ''; |
|
| 1593 | + if (! empty($CNT_ISO)) { |
|
| 1594 | + // can we get country object from name ? |
|
| 1595 | + EE_Registry::instance()->load_model('Country'); |
|
| 1596 | + $country = EEM_Country::instance()->get_col( |
|
| 1597 | + array(array('CNT_name' => $CNT_ISO), 'limit' => 1), |
|
| 1598 | + 'CNT_ISO' |
|
| 1599 | + ); |
|
| 1600 | + $CNT_ISO = is_array($country) && ! empty($country) ? reset($country) : $CNT_ISO; |
|
| 1601 | + } |
|
| 1602 | + // grab attendee data |
|
| 1603 | + $attendee_data = array( |
|
| 1604 | + 'ATT_fname' => ! empty($_REQUEST['first_name']) ? sanitize_text_field($_REQUEST['first_name']) : '', |
|
| 1605 | + 'ATT_lname' => ! empty($_REQUEST['last_name']) ? sanitize_text_field($_REQUEST['last_name']) : '', |
|
| 1606 | + 'ATT_email' => ! empty($_REQUEST['email']) ? sanitize_email($_REQUEST['email']) : '', |
|
| 1607 | + 'ATT_address' => ! empty($_REQUEST['address']) ? sanitize_text_field($_REQUEST['address']) : '', |
|
| 1608 | + 'ATT_address2' => ! empty($_REQUEST['address2']) ? sanitize_text_field($_REQUEST['address2']) : '', |
|
| 1609 | + 'ATT_city' => ! empty($_REQUEST['city']) ? sanitize_text_field($_REQUEST['city']) : '', |
|
| 1610 | + 'STA_ID' => $STA_ID, |
|
| 1611 | + 'CNT_ISO' => $CNT_ISO, |
|
| 1612 | + 'ATT_zip' => ! empty($_REQUEST['zip']) ? sanitize_text_field($_REQUEST['zip']) : '', |
|
| 1613 | + 'ATT_phone' => ! empty($_REQUEST['phone']) ? sanitize_text_field($_REQUEST['phone']) : '', |
|
| 1614 | + ); |
|
| 1615 | + // validate the email address since it is the most important piece of info |
|
| 1616 | + if (empty($attendee_data['ATT_email']) || $attendee_data['ATT_email'] !== $_REQUEST['email']) { |
|
| 1617 | + EE_Error::add_error( |
|
| 1618 | + esc_html__('An invalid email address was submitted.', 'event_espresso'), |
|
| 1619 | + __FILE__, |
|
| 1620 | + __FUNCTION__, |
|
| 1621 | + __LINE__ |
|
| 1622 | + ); |
|
| 1623 | + } |
|
| 1624 | + // does this attendee already exist in the db ? we're searching using a combination of first name, last name, |
|
| 1625 | + // AND email address |
|
| 1626 | + if (! empty($attendee_data['ATT_fname']) |
|
| 1627 | + && ! empty($attendee_data['ATT_lname']) |
|
| 1628 | + && ! empty($attendee_data['ATT_email']) |
|
| 1629 | + ) { |
|
| 1630 | + $existing_attendee = EE_Registry::instance()->LIB->EEM_Attendee->find_existing_attendee( |
|
| 1631 | + array( |
|
| 1632 | + 'ATT_fname' => $attendee_data['ATT_fname'], |
|
| 1633 | + 'ATT_lname' => $attendee_data['ATT_lname'], |
|
| 1634 | + 'ATT_email' => $attendee_data['ATT_email'], |
|
| 1635 | + ) |
|
| 1636 | + ); |
|
| 1637 | + if ($existing_attendee instanceof EE_Attendee) { |
|
| 1638 | + return $existing_attendee; |
|
| 1639 | + } |
|
| 1640 | + } |
|
| 1641 | + // no existing attendee? kk let's create a new one |
|
| 1642 | + // kinda lame, but we need a first and last name to create an attendee, so use the email address if those |
|
| 1643 | + // don't exist |
|
| 1644 | + $attendee_data['ATT_fname'] = ! empty($attendee_data['ATT_fname']) |
|
| 1645 | + ? $attendee_data['ATT_fname'] |
|
| 1646 | + : $attendee_data['ATT_email']; |
|
| 1647 | + $attendee_data['ATT_lname'] = ! empty($attendee_data['ATT_lname']) |
|
| 1648 | + ? $attendee_data['ATT_lname'] |
|
| 1649 | + : $attendee_data['ATT_email']; |
|
| 1650 | + return EE_Attendee::new_instance($attendee_data); |
|
| 1651 | + } |
|
| 1652 | + |
|
| 1653 | + |
|
| 1654 | + |
|
| 1655 | + /********************************************************************************************************/ |
|
| 1656 | + /**************************************** PROCESS REG STEP *****************************************/ |
|
| 1657 | + /********************************************************************************************************/ |
|
| 1658 | + /** |
|
| 1659 | + * process_reg_step |
|
| 1660 | + * |
|
| 1661 | + * @return bool |
|
| 1662 | + * @throws EE_Error |
|
| 1663 | + * @throws InvalidArgumentException |
|
| 1664 | + * @throws ReflectionException |
|
| 1665 | + * @throws \EventEspresso\core\exceptions\EntityNotFoundException |
|
| 1666 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 1667 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 1668 | + * @throws \EventEspresso\core\exceptions\InvalidStatusException |
|
| 1669 | + */ |
|
| 1670 | + public function process_reg_step() |
|
| 1671 | + { |
|
| 1672 | + // how have they chosen to pay? |
|
| 1673 | + $this->checkout->selected_method_of_payment = $this->checkout->transaction->is_free() |
|
| 1674 | + ? 'no_payment_required' |
|
| 1675 | + : $this->_get_selected_method_of_payment(true); |
|
| 1676 | + // choose your own adventure based on method_of_payment |
|
| 1677 | + switch ($this->checkout->selected_method_of_payment) { |
|
| 1678 | + case 'events_sold_out': |
|
| 1679 | + $this->checkout->redirect = true; |
|
| 1680 | + $this->checkout->redirect_url = $this->checkout->cancel_page_url; |
|
| 1681 | + $this->checkout->json_response->set_redirect_url($this->checkout->redirect_url); |
|
| 1682 | + // mark this reg step as completed |
|
| 1683 | + $this->set_completed(); |
|
| 1684 | + return false; |
|
| 1685 | + break; |
|
| 1686 | + |
|
| 1687 | + case 'payments_closed': |
|
| 1688 | + if (apply_filters( |
|
| 1689 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options__process_reg_step__payments_closed__display_success', |
|
| 1690 | + false |
|
| 1691 | + )) { |
|
| 1692 | + EE_Error::add_success( |
|
| 1693 | + esc_html__('no payment required at this time.', 'event_espresso'), |
|
| 1694 | + __FILE__, |
|
| 1695 | + __FUNCTION__, |
|
| 1696 | + __LINE__ |
|
| 1697 | + ); |
|
| 1698 | + } |
|
| 1699 | + // mark this reg step as completed |
|
| 1700 | + $this->set_completed(); |
|
| 1701 | + return true; |
|
| 1702 | + break; |
|
| 1703 | + |
|
| 1704 | + case 'no_payment_required': |
|
| 1705 | + if (apply_filters( |
|
| 1706 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options__process_reg_step__no_payment_required__display_success', |
|
| 1707 | + false |
|
| 1708 | + )) { |
|
| 1709 | + EE_Error::add_success( |
|
| 1710 | + esc_html__('no payment required.', 'event_espresso'), |
|
| 1711 | + __FILE__, |
|
| 1712 | + __FUNCTION__, |
|
| 1713 | + __LINE__ |
|
| 1714 | + ); |
|
| 1715 | + } |
|
| 1716 | + // mark this reg step as completed |
|
| 1717 | + $this->set_completed(); |
|
| 1718 | + return true; |
|
| 1719 | + break; |
|
| 1720 | + |
|
| 1721 | + default: |
|
| 1722 | + $registrations = EE_Registry::instance()->SSN->checkout()->transaction->registrations( |
|
| 1723 | + EE_Registry::instance()->SSN->checkout()->reg_cache_where_params |
|
| 1724 | + ); |
|
| 1725 | + $ejected_registrations = EE_SPCO_Reg_Step_Payment_Options::find_registrations_that_lost_their_space( |
|
| 1726 | + $registrations, |
|
| 1727 | + EE_Registry::instance()->SSN->checkout()->revisit |
|
| 1728 | + ); |
|
| 1729 | + // calculate difference between the two arrays |
|
| 1730 | + $registrations = array_diff($registrations, $ejected_registrations); |
|
| 1731 | + if (empty($registrations)) { |
|
| 1732 | + $this->_redirect_because_event_sold_out(); |
|
| 1733 | + return false; |
|
| 1734 | + } |
|
| 1735 | + $payment_successful = $this->_process_payment(); |
|
| 1736 | + if ($payment_successful) { |
|
| 1737 | + $this->checkout->continue_reg = true; |
|
| 1738 | + $this->_maybe_set_completed($this->checkout->payment_method); |
|
| 1739 | + } else { |
|
| 1740 | + $this->checkout->continue_reg = false; |
|
| 1741 | + } |
|
| 1742 | + return $payment_successful; |
|
| 1743 | + } |
|
| 1744 | + } |
|
| 1745 | + |
|
| 1746 | + |
|
| 1747 | + /** |
|
| 1748 | + * _redirect_because_event_sold_out |
|
| 1749 | + * |
|
| 1750 | + * @access protected |
|
| 1751 | + * @return void |
|
| 1752 | + */ |
|
| 1753 | + protected function _redirect_because_event_sold_out() |
|
| 1754 | + { |
|
| 1755 | + $this->checkout->continue_reg = false; |
|
| 1756 | + // set redirect URL |
|
| 1757 | + $this->checkout->redirect_url = add_query_arg( |
|
| 1758 | + array('e_reg_url_link' => $this->checkout->reg_url_link), |
|
| 1759 | + $this->checkout->current_step->reg_step_url() |
|
| 1760 | + ); |
|
| 1761 | + $this->checkout->json_response->set_redirect_url($this->checkout->redirect_url); |
|
| 1762 | + } |
|
| 1763 | + |
|
| 1764 | + |
|
| 1765 | + /** |
|
| 1766 | + * _maybe_set_completed |
|
| 1767 | + * |
|
| 1768 | + * @access protected |
|
| 1769 | + * @param \EE_Payment_Method $payment_method |
|
| 1770 | + * @return void |
|
| 1771 | + * @throws \EE_Error |
|
| 1772 | + */ |
|
| 1773 | + protected function _maybe_set_completed(EE_Payment_Method $payment_method) |
|
| 1774 | + { |
|
| 1775 | + switch ($payment_method->type_obj()->payment_occurs()) { |
|
| 1776 | + case EE_PMT_Base::offsite: |
|
| 1777 | + break; |
|
| 1778 | + case EE_PMT_Base::onsite: |
|
| 1779 | + case EE_PMT_Base::offline: |
|
| 1780 | + // mark this reg step as completed |
|
| 1781 | + $this->set_completed(); |
|
| 1782 | + break; |
|
| 1783 | + } |
|
| 1784 | + } |
|
| 1785 | + |
|
| 1786 | + |
|
| 1787 | + /** |
|
| 1788 | + * update_reg_step |
|
| 1789 | + * this is the final step after a user revisits the site to retry a payment |
|
| 1790 | + * |
|
| 1791 | + * @return bool |
|
| 1792 | + * @throws EE_Error |
|
| 1793 | + * @throws InvalidArgumentException |
|
| 1794 | + * @throws ReflectionException |
|
| 1795 | + * @throws \EventEspresso\core\exceptions\EntityNotFoundException |
|
| 1796 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 1797 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 1798 | + * @throws \EventEspresso\core\exceptions\InvalidStatusException |
|
| 1799 | + */ |
|
| 1800 | + public function update_reg_step() |
|
| 1801 | + { |
|
| 1802 | + $success = true; |
|
| 1803 | + // if payment required |
|
| 1804 | + if ($this->checkout->transaction->total() > 0) { |
|
| 1805 | + do_action( |
|
| 1806 | + 'AHEE__EE_Single_Page_Checkout__process_finalize_registration__before_gateway', |
|
| 1807 | + $this->checkout->transaction |
|
| 1808 | + ); |
|
| 1809 | + // attempt payment via payment method |
|
| 1810 | + $success = $this->process_reg_step(); |
|
| 1811 | + } |
|
| 1812 | + if ($success && ! $this->checkout->redirect) { |
|
| 1813 | + $this->checkout->cart->get_grand_total()->save_this_and_descendants_to_txn( |
|
| 1814 | + $this->checkout->transaction->ID() |
|
| 1815 | + ); |
|
| 1816 | + // set return URL |
|
| 1817 | + $this->checkout->redirect_url = add_query_arg( |
|
| 1818 | + array('e_reg_url_link' => $this->checkout->reg_url_link), |
|
| 1819 | + $this->checkout->thank_you_page_url |
|
| 1820 | + ); |
|
| 1821 | + } |
|
| 1822 | + return $success; |
|
| 1823 | + } |
|
| 1824 | + |
|
| 1825 | + |
|
| 1826 | + /** |
|
| 1827 | + * _process_payment |
|
| 1828 | + * |
|
| 1829 | + * @access private |
|
| 1830 | + * @return bool |
|
| 1831 | + * @throws EE_Error |
|
| 1832 | + * @throws InvalidArgumentException |
|
| 1833 | + * @throws ReflectionException |
|
| 1834 | + * @throws RuntimeException |
|
| 1835 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 1836 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 1837 | + */ |
|
| 1838 | + private function _process_payment() |
|
| 1839 | + { |
|
| 1840 | + // basically confirm that the event hasn't sold out since they hit the page |
|
| 1841 | + if (! $this->_last_second_ticket_verifications()) { |
|
| 1842 | + return false; |
|
| 1843 | + } |
|
| 1844 | + // ya gotta make a choice man |
|
| 1845 | + if (empty($this->checkout->selected_method_of_payment)) { |
|
| 1846 | + $this->checkout->json_response->set_plz_select_method_of_payment( |
|
| 1847 | + esc_html__('Please select a method of payment before proceeding.', 'event_espresso') |
|
| 1848 | + ); |
|
| 1849 | + return false; |
|
| 1850 | + } |
|
| 1851 | + // get EE_Payment_Method object |
|
| 1852 | + if (! $this->checkout->payment_method = $this->_get_payment_method_for_selected_method_of_payment()) { |
|
| 1853 | + return false; |
|
| 1854 | + } |
|
| 1855 | + // setup billing form |
|
| 1856 | + if ($this->checkout->payment_method->is_on_site()) { |
|
| 1857 | + $this->checkout->billing_form = $this->_get_billing_form_for_payment_method( |
|
| 1858 | + $this->checkout->payment_method |
|
| 1859 | + ); |
|
| 1860 | + // bad billing form ? |
|
| 1861 | + if (! $this->_billing_form_is_valid()) { |
|
| 1862 | + return false; |
|
| 1863 | + } |
|
| 1864 | + } |
|
| 1865 | + // ensure primary registrant has been fully processed |
|
| 1866 | + if (! $this->_setup_primary_registrant_prior_to_payment()) { |
|
| 1867 | + return false; |
|
| 1868 | + } |
|
| 1869 | + // if session is close to expiring (under 10 minutes by default) |
|
| 1870 | + if ((time() - EE_Registry::instance()->SSN->expiration()) < EE_Registry::instance()->SSN->extension()) { |
|
| 1871 | + // add some time to session expiration so that payment can be completed |
|
| 1872 | + EE_Registry::instance()->SSN->extend_expiration(); |
|
| 1873 | + } |
|
| 1874 | + /** @type EE_Transaction_Processor $transaction_processor */ |
|
| 1875 | + // $transaction_processor = EE_Registry::instance()->load_class( 'Transaction_Processor' ); |
|
| 1876 | + // in case a registrant leaves to an Off-Site Gateway and never returns, we want to approve any registrations |
|
| 1877 | + // for events with a default reg status of Approved |
|
| 1878 | + // $transaction_processor->toggle_registration_statuses_for_default_approved_events( |
|
| 1879 | + // $this->checkout->transaction, $this->checkout->reg_cache_where_params |
|
| 1880 | + // ); |
|
| 1881 | + // attempt payment |
|
| 1882 | + $payment = $this->_attempt_payment($this->checkout->payment_method); |
|
| 1883 | + // process results |
|
| 1884 | + $payment = $this->_validate_payment($payment); |
|
| 1885 | + $payment = $this->_post_payment_processing($payment); |
|
| 1886 | + // verify payment |
|
| 1887 | + if ($payment instanceof EE_Payment) { |
|
| 1888 | + // store that for later |
|
| 1889 | + $this->checkout->payment = $payment; |
|
| 1890 | + // we can also consider the TXN to not have been failed, so temporarily upgrade it's status to abandoned |
|
| 1891 | + $this->checkout->transaction->toggle_failed_transaction_status(); |
|
| 1892 | + $payment_status = $payment->status(); |
|
| 1893 | + if ($payment_status === EEM_Payment::status_id_approved |
|
| 1894 | + || $payment_status === EEM_Payment::status_id_pending |
|
| 1895 | + ) { |
|
| 1896 | + return true; |
|
| 1897 | + } else { |
|
| 1898 | + return false; |
|
| 1899 | + } |
|
| 1900 | + } elseif ($payment === true) { |
|
| 1901 | + // please note that offline payment methods will NOT make a payment, |
|
| 1902 | + // but instead just mark themselves as the PMD_ID on the transaction, and return true |
|
| 1903 | + $this->checkout->payment = $payment; |
|
| 1904 | + return true; |
|
| 1905 | + } |
|
| 1906 | + // where's my money? |
|
| 1907 | + return false; |
|
| 1908 | + } |
|
| 1909 | + |
|
| 1910 | + |
|
| 1911 | + /** |
|
| 1912 | + * _last_second_ticket_verifications |
|
| 1913 | + * |
|
| 1914 | + * @access public |
|
| 1915 | + * @return bool |
|
| 1916 | + * @throws EE_Error |
|
| 1917 | + */ |
|
| 1918 | + protected function _last_second_ticket_verifications() |
|
| 1919 | + { |
|
| 1920 | + // don't bother re-validating if not a return visit |
|
| 1921 | + if (! $this->checkout->revisit) { |
|
| 1922 | + return true; |
|
| 1923 | + } |
|
| 1924 | + $registrations = $this->checkout->transaction->registrations(); |
|
| 1925 | + if (empty($registrations)) { |
|
| 1926 | + return false; |
|
| 1927 | + } |
|
| 1928 | + foreach ($registrations as $registration) { |
|
| 1929 | + if ($registration instanceof EE_Registration && ! $registration->is_approved()) { |
|
| 1930 | + $event = $registration->event_obj(); |
|
| 1931 | + if ($event instanceof EE_Event && $event->is_sold_out(true)) { |
|
| 1932 | + EE_Error::add_error( |
|
| 1933 | + apply_filters( |
|
| 1934 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options___last_second_ticket_verifications__sold_out_events_msg', |
|
| 1935 | + sprintf( |
|
| 1936 | + esc_html__( |
|
| 1937 | + 'It appears that the %1$s event that you were about to make a payment for has sold out since you first registered and/or arrived at this page. Please refresh the page and try again. If you have already made a partial payment towards this event, please contact the event administrator for a refund.', |
|
| 1938 | + 'event_espresso' |
|
| 1939 | + ), |
|
| 1940 | + $event->name() |
|
| 1941 | + ) |
|
| 1942 | + ), |
|
| 1943 | + __FILE__, |
|
| 1944 | + __FUNCTION__, |
|
| 1945 | + __LINE__ |
|
| 1946 | + ); |
|
| 1947 | + return false; |
|
| 1948 | + } |
|
| 1949 | + } |
|
| 1950 | + } |
|
| 1951 | + return true; |
|
| 1952 | + } |
|
| 1953 | + |
|
| 1954 | + |
|
| 1955 | + /** |
|
| 1956 | + * redirect_form |
|
| 1957 | + * |
|
| 1958 | + * @access public |
|
| 1959 | + * @return bool |
|
| 1960 | + * @throws EE_Error |
|
| 1961 | + * @throws InvalidArgumentException |
|
| 1962 | + * @throws ReflectionException |
|
| 1963 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 1964 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 1965 | + */ |
|
| 1966 | + public function redirect_form() |
|
| 1967 | + { |
|
| 1968 | + $payment_method_billing_info = $this->_payment_method_billing_info( |
|
| 1969 | + $this->_get_payment_method_for_selected_method_of_payment() |
|
| 1970 | + ); |
|
| 1971 | + $html = $payment_method_billing_info->get_html(); |
|
| 1972 | + $html .= $this->checkout->redirect_form; |
|
| 1973 | + EE_Registry::instance()->REQ->add_output($html); |
|
| 1974 | + return true; |
|
| 1975 | + } |
|
| 1976 | + |
|
| 1977 | + |
|
| 1978 | + /** |
|
| 1979 | + * _billing_form_is_valid |
|
| 1980 | + * |
|
| 1981 | + * @access private |
|
| 1982 | + * @return bool |
|
| 1983 | + * @throws \EE_Error |
|
| 1984 | + */ |
|
| 1985 | + private function _billing_form_is_valid() |
|
| 1986 | + { |
|
| 1987 | + if (! $this->checkout->payment_method->type_obj()->has_billing_form()) { |
|
| 1988 | + return true; |
|
| 1989 | + } |
|
| 1990 | + if ($this->checkout->billing_form instanceof EE_Billing_Info_Form) { |
|
| 1991 | + if ($this->checkout->billing_form->was_submitted()) { |
|
| 1992 | + $this->checkout->billing_form->receive_form_submission(); |
|
| 1993 | + if ($this->checkout->billing_form->is_valid()) { |
|
| 1994 | + return true; |
|
| 1995 | + } |
|
| 1996 | + $validation_errors = $this->checkout->billing_form->get_validation_errors_accumulated(); |
|
| 1997 | + $error_strings = array(); |
|
| 1998 | + foreach ($validation_errors as $validation_error) { |
|
| 1999 | + if ($validation_error instanceof EE_Validation_Error) { |
|
| 2000 | + $form_section = $validation_error->get_form_section(); |
|
| 2001 | + if ($form_section instanceof EE_Form_Input_Base) { |
|
| 2002 | + $label = $form_section->html_label_text(); |
|
| 2003 | + } elseif ($form_section instanceof EE_Form_Section_Base) { |
|
| 2004 | + $label = $form_section->name(); |
|
| 2005 | + } else { |
|
| 2006 | + $label = esc_html__('Validation Error', 'event_espresso'); |
|
| 2007 | + } |
|
| 2008 | + $error_strings[] = sprintf('%1$s: %2$s', $label, $validation_error->getMessage()); |
|
| 2009 | + } |
|
| 2010 | + } |
|
| 2011 | + EE_Error::add_error( |
|
| 2012 | + sprintf( |
|
| 2013 | + esc_html__( |
|
| 2014 | + 'One or more billing form inputs are invalid and require correction before proceeding. %1$s %2$s', |
|
| 2015 | + 'event_espresso' |
|
| 2016 | + ), |
|
| 2017 | + '<br/>', |
|
| 2018 | + implode('<br/>', $error_strings) |
|
| 2019 | + ), |
|
| 2020 | + __FILE__, |
|
| 2021 | + __FUNCTION__, |
|
| 2022 | + __LINE__ |
|
| 2023 | + ); |
|
| 2024 | + } else { |
|
| 2025 | + EE_Error::add_error( |
|
| 2026 | + esc_html__( |
|
| 2027 | + 'The billing form was not submitted or something prevented it\'s submission.', |
|
| 2028 | + 'event_espresso' |
|
| 2029 | + ), |
|
| 2030 | + __FILE__, |
|
| 2031 | + __FUNCTION__, |
|
| 2032 | + __LINE__ |
|
| 2033 | + ); |
|
| 2034 | + } |
|
| 2035 | + } else { |
|
| 2036 | + EE_Error::add_error( |
|
| 2037 | + esc_html__( |
|
| 2038 | + 'The submitted billing form is invalid possibly due to a technical reason.', |
|
| 2039 | + 'event_espresso' |
|
| 2040 | + ), |
|
| 2041 | + __FILE__, |
|
| 2042 | + __FUNCTION__, |
|
| 2043 | + __LINE__ |
|
| 2044 | + ); |
|
| 2045 | + } |
|
| 2046 | + return false; |
|
| 2047 | + } |
|
| 2048 | + |
|
| 2049 | + |
|
| 2050 | + /** |
|
| 2051 | + * _setup_primary_registrant_prior_to_payment |
|
| 2052 | + * ensures that the primary registrant has a valid attendee object created with the critical details populated |
|
| 2053 | + * (first & last name & email) and that both the transaction object and primary registration object have been saved |
|
| 2054 | + * plz note that any other registrations will NOT be saved at this point (because they may not have any details |
|
| 2055 | + * yet) |
|
| 2056 | + * |
|
| 2057 | + * @access private |
|
| 2058 | + * @return bool |
|
| 2059 | + * @throws EE_Error |
|
| 2060 | + * @throws InvalidArgumentException |
|
| 2061 | + * @throws ReflectionException |
|
| 2062 | + * @throws RuntimeException |
|
| 2063 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 2064 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 2065 | + */ |
|
| 2066 | + private function _setup_primary_registrant_prior_to_payment() |
|
| 2067 | + { |
|
| 2068 | + // check if transaction has a primary registrant and that it has a related Attendee object |
|
| 2069 | + // if not, then we need to at least gather some primary registrant data before attempting payment |
|
| 2070 | + if ($this->checkout->billing_form instanceof EE_Billing_Attendee_Info_Form |
|
| 2071 | + && ! $this->checkout->transaction_has_primary_registrant() |
|
| 2072 | + && ! $this->_capture_primary_registration_data_from_billing_form() |
|
| 2073 | + ) { |
|
| 2074 | + return false; |
|
| 2075 | + } |
|
| 2076 | + // because saving an object clears it's cache, we need to do the chevy shuffle |
|
| 2077 | + // grab the primary_registration object |
|
| 2078 | + $primary_registration = $this->checkout->transaction->primary_registration(); |
|
| 2079 | + // at this point we'll consider a TXN to not have been failed |
|
| 2080 | + $this->checkout->transaction->toggle_failed_transaction_status(); |
|
| 2081 | + // save the TXN ( which clears cached copy of primary_registration) |
|
| 2082 | + $this->checkout->transaction->save(); |
|
| 2083 | + // grab TXN ID and save it to the primary_registration |
|
| 2084 | + $primary_registration->set_transaction_id($this->checkout->transaction->ID()); |
|
| 2085 | + // save what we have so far |
|
| 2086 | + $primary_registration->save(); |
|
| 2087 | + return true; |
|
| 2088 | + } |
|
| 2089 | + |
|
| 2090 | + |
|
| 2091 | + /** |
|
| 2092 | + * _capture_primary_registration_data_from_billing_form |
|
| 2093 | + * |
|
| 2094 | + * @access private |
|
| 2095 | + * @return bool |
|
| 2096 | + * @throws EE_Error |
|
| 2097 | + * @throws InvalidArgumentException |
|
| 2098 | + * @throws ReflectionException |
|
| 2099 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 2100 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 2101 | + */ |
|
| 2102 | + private function _capture_primary_registration_data_from_billing_form() |
|
| 2103 | + { |
|
| 2104 | + // convert billing form data into an attendee |
|
| 2105 | + $this->checkout->primary_attendee_obj = $this->checkout->billing_form->create_attendee_from_billing_form_data(); |
|
| 2106 | + if (! $this->checkout->primary_attendee_obj instanceof EE_Attendee) { |
|
| 2107 | + EE_Error::add_error( |
|
| 2108 | + sprintf( |
|
| 2109 | + esc_html__( |
|
| 2110 | + 'The billing form details could not be used for attendee details due to a technical issue.%sPlease try again or contact %s for assistance.', |
|
| 2111 | + 'event_espresso' |
|
| 2112 | + ), |
|
| 2113 | + '<br/>', |
|
| 2114 | + EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
| 2115 | + ), |
|
| 2116 | + __FILE__, |
|
| 2117 | + __FUNCTION__, |
|
| 2118 | + __LINE__ |
|
| 2119 | + ); |
|
| 2120 | + return false; |
|
| 2121 | + } |
|
| 2122 | + $primary_registration = $this->checkout->transaction->primary_registration(); |
|
| 2123 | + if (! $primary_registration instanceof EE_Registration) { |
|
| 2124 | + EE_Error::add_error( |
|
| 2125 | + sprintf( |
|
| 2126 | + esc_html__( |
|
| 2127 | + 'The primary registrant for this transaction could not be determined due to a technical issue.%sPlease try again or contact %s for assistance.', |
|
| 2128 | + 'event_espresso' |
|
| 2129 | + ), |
|
| 2130 | + '<br/>', |
|
| 2131 | + EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
| 2132 | + ), |
|
| 2133 | + __FILE__, |
|
| 2134 | + __FUNCTION__, |
|
| 2135 | + __LINE__ |
|
| 2136 | + ); |
|
| 2137 | + return false; |
|
| 2138 | + } |
|
| 2139 | + if (! $primary_registration->_add_relation_to($this->checkout->primary_attendee_obj, 'Attendee') |
|
| 2140 | + instanceof |
|
| 2141 | + EE_Attendee |
|
| 2142 | + ) { |
|
| 2143 | + EE_Error::add_error( |
|
| 2144 | + sprintf( |
|
| 2145 | + esc_html__( |
|
| 2146 | + 'The primary registrant could not be associated with this transaction due to a technical issue.%sPlease try again or contact %s for assistance.', |
|
| 2147 | + 'event_espresso' |
|
| 2148 | + ), |
|
| 2149 | + '<br/>', |
|
| 2150 | + EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
| 2151 | + ), |
|
| 2152 | + __FILE__, |
|
| 2153 | + __FUNCTION__, |
|
| 2154 | + __LINE__ |
|
| 2155 | + ); |
|
| 2156 | + return false; |
|
| 2157 | + } |
|
| 2158 | + /** @type EE_Registration_Processor $registration_processor */ |
|
| 2159 | + $registration_processor = EE_Registry::instance()->load_class('Registration_Processor'); |
|
| 2160 | + // at this point, we should have enough details about the registrant to consider the registration NOT incomplete |
|
| 2161 | + $registration_processor->toggle_incomplete_registration_status_to_default($primary_registration); |
|
| 2162 | + return true; |
|
| 2163 | + } |
|
| 2164 | + |
|
| 2165 | + |
|
| 2166 | + /** |
|
| 2167 | + * _get_payment_method_for_selected_method_of_payment |
|
| 2168 | + * retrieves a valid payment method |
|
| 2169 | + * |
|
| 2170 | + * @access public |
|
| 2171 | + * @return EE_Payment_Method |
|
| 2172 | + * @throws EE_Error |
|
| 2173 | + * @throws InvalidArgumentException |
|
| 2174 | + * @throws ReflectionException |
|
| 2175 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 2176 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 2177 | + */ |
|
| 2178 | + private function _get_payment_method_for_selected_method_of_payment() |
|
| 2179 | + { |
|
| 2180 | + if ($this->checkout->selected_method_of_payment === 'events_sold_out') { |
|
| 2181 | + $this->_redirect_because_event_sold_out(); |
|
| 2182 | + return null; |
|
| 2183 | + } |
|
| 2184 | + // get EE_Payment_Method object |
|
| 2185 | + if (isset($this->checkout->available_payment_methods[ $this->checkout->selected_method_of_payment ])) { |
|
| 2186 | + $payment_method = $this->checkout->available_payment_methods[ $this->checkout->selected_method_of_payment ]; |
|
| 2187 | + } else { |
|
| 2188 | + // load EEM_Payment_Method |
|
| 2189 | + EE_Registry::instance()->load_model('Payment_Method'); |
|
| 2190 | + /** @type EEM_Payment_Method $EEM_Payment_Method */ |
|
| 2191 | + $EEM_Payment_Method = EE_Registry::instance()->LIB->EEM_Payment_Method; |
|
| 2192 | + $payment_method = $EEM_Payment_Method->get_one_by_slug($this->checkout->selected_method_of_payment); |
|
| 2193 | + } |
|
| 2194 | + // verify $payment_method |
|
| 2195 | + if (! $payment_method instanceof EE_Payment_Method) { |
|
| 2196 | + // not a payment |
|
| 2197 | + EE_Error::add_error( |
|
| 2198 | + sprintf( |
|
| 2199 | + esc_html__( |
|
| 2200 | + 'The selected method of payment could not be determined due to a technical issue.%sPlease try again or contact %s for assistance.', |
|
| 2201 | + 'event_espresso' |
|
| 2202 | + ), |
|
| 2203 | + '<br/>', |
|
| 2204 | + EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
| 2205 | + ), |
|
| 2206 | + __FILE__, |
|
| 2207 | + __FUNCTION__, |
|
| 2208 | + __LINE__ |
|
| 2209 | + ); |
|
| 2210 | + return null; |
|
| 2211 | + } |
|
| 2212 | + // and verify it has a valid Payment_Method Type object |
|
| 2213 | + if (! $payment_method->type_obj() instanceof EE_PMT_Base) { |
|
| 2214 | + // not a payment |
|
| 2215 | + EE_Error::add_error( |
|
| 2216 | + sprintf( |
|
| 2217 | + esc_html__( |
|
| 2218 | + 'A valid payment method could not be determined due to a technical issue.%sPlease try again or contact %s for assistance.', |
|
| 2219 | + 'event_espresso' |
|
| 2220 | + ), |
|
| 2221 | + '<br/>', |
|
| 2222 | + EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
| 2223 | + ), |
|
| 2224 | + __FILE__, |
|
| 2225 | + __FUNCTION__, |
|
| 2226 | + __LINE__ |
|
| 2227 | + ); |
|
| 2228 | + return null; |
|
| 2229 | + } |
|
| 2230 | + return $payment_method; |
|
| 2231 | + } |
|
| 2232 | + |
|
| 2233 | + |
|
| 2234 | + /** |
|
| 2235 | + * _attempt_payment |
|
| 2236 | + * |
|
| 2237 | + * @access private |
|
| 2238 | + * @type EE_Payment_Method $payment_method |
|
| 2239 | + * @return mixed EE_Payment | boolean |
|
| 2240 | + * @throws EE_Error |
|
| 2241 | + * @throws InvalidArgumentException |
|
| 2242 | + * @throws ReflectionException |
|
| 2243 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 2244 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 2245 | + */ |
|
| 2246 | + private function _attempt_payment(EE_Payment_Method $payment_method) |
|
| 2247 | + { |
|
| 2248 | + $payment = null; |
|
| 2249 | + $this->checkout->transaction->save(); |
|
| 2250 | + $payment_processor = EE_Registry::instance()->load_core('Payment_Processor'); |
|
| 2251 | + if (! $payment_processor instanceof EE_Payment_Processor) { |
|
| 2252 | + return false; |
|
| 2253 | + } |
|
| 2254 | + try { |
|
| 2255 | + $payment_processor->set_revisit($this->checkout->revisit); |
|
| 2256 | + // generate payment object |
|
| 2257 | + $payment = $payment_processor->process_payment( |
|
| 2258 | + $payment_method, |
|
| 2259 | + $this->checkout->transaction, |
|
| 2260 | + $this->checkout->amount_owing, |
|
| 2261 | + $this->checkout->billing_form, |
|
| 2262 | + $this->_get_return_url($payment_method), |
|
| 2263 | + 'CART', |
|
| 2264 | + $this->checkout->admin_request, |
|
| 2265 | + true, |
|
| 2266 | + $this->reg_step_url() |
|
| 2267 | + ); |
|
| 2268 | + } catch (Exception $e) { |
|
| 2269 | + $this->_handle_payment_processor_exception($e); |
|
| 2270 | + } |
|
| 2271 | + return $payment; |
|
| 2272 | + } |
|
| 2273 | + |
|
| 2274 | + |
|
| 2275 | + /** |
|
| 2276 | + * _handle_payment_processor_exception |
|
| 2277 | + * |
|
| 2278 | + * @access protected |
|
| 2279 | + * @param \Exception $e |
|
| 2280 | + * @return void |
|
| 2281 | + * @throws EE_Error |
|
| 2282 | + * @throws InvalidArgumentException |
|
| 2283 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 2284 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 2285 | + */ |
|
| 2286 | + protected function _handle_payment_processor_exception(Exception $e) |
|
| 2287 | + { |
|
| 2288 | + EE_Error::add_error( |
|
| 2289 | + sprintf( |
|
| 2290 | + esc_html__( |
|
| 2291 | + 'The payment could not br processed due to a technical issue.%1$sPlease try again or contact %2$s for assistance.||The following Exception was thrown in %4$s on line %5$s:%1$s%3$s', |
|
| 2292 | + 'event_espresso' |
|
| 2293 | + ), |
|
| 2294 | + '<br/>', |
|
| 2295 | + EE_Registry::instance()->CFG->organization->get_pretty('email'), |
|
| 2296 | + $e->getMessage(), |
|
| 2297 | + $e->getFile(), |
|
| 2298 | + $e->getLine() |
|
| 2299 | + ), |
|
| 2300 | + __FILE__, |
|
| 2301 | + __FUNCTION__, |
|
| 2302 | + __LINE__ |
|
| 2303 | + ); |
|
| 2304 | + } |
|
| 2305 | + |
|
| 2306 | + |
|
| 2307 | + /** |
|
| 2308 | + * _get_return_url |
|
| 2309 | + * |
|
| 2310 | + * @access protected |
|
| 2311 | + * @param \EE_Payment_Method $payment_method |
|
| 2312 | + * @return string |
|
| 2313 | + * @throws \EE_Error |
|
| 2314 | + */ |
|
| 2315 | + protected function _get_return_url(EE_Payment_Method $payment_method) |
|
| 2316 | + { |
|
| 2317 | + $return_url = ''; |
|
| 2318 | + switch ($payment_method->type_obj()->payment_occurs()) { |
|
| 2319 | + case EE_PMT_Base::offsite: |
|
| 2320 | + $return_url = add_query_arg( |
|
| 2321 | + array( |
|
| 2322 | + 'action' => 'process_gateway_response', |
|
| 2323 | + 'selected_method_of_payment' => $this->checkout->selected_method_of_payment, |
|
| 2324 | + 'spco_txn' => $this->checkout->transaction->ID(), |
|
| 2325 | + ), |
|
| 2326 | + $this->reg_step_url() |
|
| 2327 | + ); |
|
| 2328 | + break; |
|
| 2329 | + case EE_PMT_Base::onsite: |
|
| 2330 | + case EE_PMT_Base::offline: |
|
| 2331 | + $return_url = $this->checkout->next_step->reg_step_url(); |
|
| 2332 | + break; |
|
| 2333 | + } |
|
| 2334 | + return $return_url; |
|
| 2335 | + } |
|
| 2336 | + |
|
| 2337 | + |
|
| 2338 | + /** |
|
| 2339 | + * _validate_payment |
|
| 2340 | + * |
|
| 2341 | + * @access private |
|
| 2342 | + * @param EE_Payment $payment |
|
| 2343 | + * @return EE_Payment|FALSE |
|
| 2344 | + * @throws EE_Error |
|
| 2345 | + * @throws InvalidArgumentException |
|
| 2346 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 2347 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 2348 | + */ |
|
| 2349 | + private function _validate_payment($payment = null) |
|
| 2350 | + { |
|
| 2351 | + if ($this->checkout->payment_method->is_off_line()) { |
|
| 2352 | + return true; |
|
| 2353 | + } |
|
| 2354 | + // verify payment object |
|
| 2355 | + if (! $payment instanceof EE_Payment) { |
|
| 2356 | + // not a payment |
|
| 2357 | + EE_Error::add_error( |
|
| 2358 | + sprintf( |
|
| 2359 | + esc_html__( |
|
| 2360 | + 'A valid payment was not generated due to a technical issue.%1$sPlease try again or contact %2$s for assistance.', |
|
| 2361 | + 'event_espresso' |
|
| 2362 | + ), |
|
| 2363 | + '<br/>', |
|
| 2364 | + EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
| 2365 | + ), |
|
| 2366 | + __FILE__, |
|
| 2367 | + __FUNCTION__, |
|
| 2368 | + __LINE__ |
|
| 2369 | + ); |
|
| 2370 | + return false; |
|
| 2371 | + } |
|
| 2372 | + return $payment; |
|
| 2373 | + } |
|
| 2374 | + |
|
| 2375 | + |
|
| 2376 | + /** |
|
| 2377 | + * _post_payment_processing |
|
| 2378 | + * |
|
| 2379 | + * @access private |
|
| 2380 | + * @param EE_Payment|bool $payment |
|
| 2381 | + * @return bool |
|
| 2382 | + * @throws EE_Error |
|
| 2383 | + * @throws InvalidArgumentException |
|
| 2384 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 2385 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 2386 | + */ |
|
| 2387 | + private function _post_payment_processing($payment = null) |
|
| 2388 | + { |
|
| 2389 | + // Off-Line payment? |
|
| 2390 | + if ($payment === true) { |
|
| 2391 | + // $this->_setup_redirect_for_next_step(); |
|
| 2392 | + return true; |
|
| 2393 | + // On-Site payment? |
|
| 2394 | + } elseif ($this->checkout->payment_method->is_on_site()) { |
|
| 2395 | + if (! $this->_process_payment_status($payment, EE_PMT_Base::onsite)) { |
|
| 2396 | + // $this->_setup_redirect_for_next_step(); |
|
| 2397 | + $this->checkout->continue_reg = false; |
|
| 2398 | + } |
|
| 2399 | + // Off-Site payment? |
|
| 2400 | + } elseif ($this->checkout->payment_method->is_off_site()) { |
|
| 2401 | + // if a payment object was made and it specifies a redirect url, then we'll setup that redirect info |
|
| 2402 | + if ($payment instanceof EE_Payment && $payment->redirect_url()) { |
|
| 2403 | + do_action('AHEE_log', __CLASS__, __FUNCTION__, $payment->redirect_url(), '$payment->redirect_url()'); |
|
| 2404 | + $this->checkout->redirect = true; |
|
| 2405 | + $this->checkout->redirect_form = $payment->redirect_form(); |
|
| 2406 | + $this->checkout->redirect_url = $this->reg_step_url('redirect_form'); |
|
| 2407 | + // set JSON response |
|
| 2408 | + $this->checkout->json_response->set_redirect_form($this->checkout->redirect_form); |
|
| 2409 | + // and lastly, let's bump the payment status to pending |
|
| 2410 | + $payment->set_status(EEM_Payment::status_id_pending); |
|
| 2411 | + $payment->save(); |
|
| 2412 | + } else { |
|
| 2413 | + // not a payment |
|
| 2414 | + $this->checkout->continue_reg = false; |
|
| 2415 | + EE_Error::add_error( |
|
| 2416 | + sprintf( |
|
| 2417 | + esc_html__( |
|
| 2418 | + 'It appears the Off Site Payment Method was not configured properly.%sPlease try again or contact %s for assistance.', |
|
| 2419 | + 'event_espresso' |
|
| 2420 | + ), |
|
| 2421 | + '<br/>', |
|
| 2422 | + EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
| 2423 | + ), |
|
| 2424 | + __FILE__, |
|
| 2425 | + __FUNCTION__, |
|
| 2426 | + __LINE__ |
|
| 2427 | + ); |
|
| 2428 | + } |
|
| 2429 | + } else { |
|
| 2430 | + // ummm ya... not Off-Line, not On-Site, not off-Site ???? |
|
| 2431 | + $this->checkout->continue_reg = false; |
|
| 2432 | + return false; |
|
| 2433 | + } |
|
| 2434 | + return $payment; |
|
| 2435 | + } |
|
| 2436 | + |
|
| 2437 | + |
|
| 2438 | + /** |
|
| 2439 | + * _process_payment_status |
|
| 2440 | + * |
|
| 2441 | + * @access private |
|
| 2442 | + * @type EE_Payment $payment |
|
| 2443 | + * @param string $payment_occurs |
|
| 2444 | + * @return bool |
|
| 2445 | + * @throws EE_Error |
|
| 2446 | + * @throws InvalidArgumentException |
|
| 2447 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 2448 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 2449 | + */ |
|
| 2450 | + private function _process_payment_status($payment, $payment_occurs = EE_PMT_Base::offline) |
|
| 2451 | + { |
|
| 2452 | + // off-line payment? carry on |
|
| 2453 | + if ($payment_occurs === EE_PMT_Base::offline) { |
|
| 2454 | + return true; |
|
| 2455 | + } |
|
| 2456 | + // verify payment validity |
|
| 2457 | + if ($payment instanceof EE_Payment) { |
|
| 2458 | + do_action('AHEE_log', __CLASS__, __FUNCTION__, $payment->status(), '$payment->status()'); |
|
| 2459 | + $msg = $payment->gateway_response(); |
|
| 2460 | + // check results |
|
| 2461 | + switch ($payment->status()) { |
|
| 2462 | + // good payment |
|
| 2463 | + case EEM_Payment::status_id_approved: |
|
| 2464 | + EE_Error::add_success( |
|
| 2465 | + esc_html__('Your payment was processed successfully.', 'event_espresso'), |
|
| 2466 | + __FILE__, |
|
| 2467 | + __FUNCTION__, |
|
| 2468 | + __LINE__ |
|
| 2469 | + ); |
|
| 2470 | + return true; |
|
| 2471 | + break; |
|
| 2472 | + // slow payment |
|
| 2473 | + case EEM_Payment::status_id_pending: |
|
| 2474 | + if (empty($msg)) { |
|
| 2475 | + $msg = esc_html__( |
|
| 2476 | + 'Your payment appears to have been processed successfully, but the Instant Payment Notification has not yet been received. It should arrive shortly.', |
|
| 2477 | + 'event_espresso' |
|
| 2478 | + ); |
|
| 2479 | + } |
|
| 2480 | + EE_Error::add_success($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2481 | + return true; |
|
| 2482 | + break; |
|
| 2483 | + // don't wanna payment |
|
| 2484 | + case EEM_Payment::status_id_cancelled: |
|
| 2485 | + if (empty($msg)) { |
|
| 2486 | + $msg = _n( |
|
| 2487 | + 'Payment cancelled. Please try again.', |
|
| 2488 | + 'Payment cancelled. Please try again or select another method of payment.', |
|
| 2489 | + count($this->checkout->available_payment_methods), |
|
| 2490 | + 'event_espresso' |
|
| 2491 | + ); |
|
| 2492 | + } |
|
| 2493 | + EE_Error::add_attention($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2494 | + return false; |
|
| 2495 | + break; |
|
| 2496 | + // not enough payment |
|
| 2497 | + case EEM_Payment::status_id_declined: |
|
| 2498 | + if (empty($msg)) { |
|
| 2499 | + $msg = _n( |
|
| 2500 | + 'We\'re sorry but your payment was declined. Please try again.', |
|
| 2501 | + 'We\'re sorry but your payment was declined. Please try again or select another method of payment.', |
|
| 2502 | + count($this->checkout->available_payment_methods), |
|
| 2503 | + 'event_espresso' |
|
| 2504 | + ); |
|
| 2505 | + } |
|
| 2506 | + EE_Error::add_attention($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2507 | + return false; |
|
| 2508 | + break; |
|
| 2509 | + // bad payment |
|
| 2510 | + case EEM_Payment::status_id_failed: |
|
| 2511 | + if (! empty($msg)) { |
|
| 2512 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2513 | + return false; |
|
| 2514 | + } |
|
| 2515 | + // default to error below |
|
| 2516 | + break; |
|
| 2517 | + } |
|
| 2518 | + } |
|
| 2519 | + // off-site payment gateway responses are too unreliable, so let's just assume that |
|
| 2520 | + // the payment processing is just running slower than the registrant's request |
|
| 2521 | + if ($payment_occurs === EE_PMT_Base::offsite) { |
|
| 2522 | + return true; |
|
| 2523 | + } |
|
| 2524 | + EE_Error::add_error( |
|
| 2525 | + sprintf( |
|
| 2526 | + esc_html__( |
|
| 2527 | + 'Your payment could not be processed successfully due to a technical issue.%sPlease try again or contact %s for assistance.', |
|
| 2528 | + 'event_espresso' |
|
| 2529 | + ), |
|
| 2530 | + '<br/>', |
|
| 2531 | + EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
| 2532 | + ), |
|
| 2533 | + __FILE__, |
|
| 2534 | + __FUNCTION__, |
|
| 2535 | + __LINE__ |
|
| 2536 | + ); |
|
| 2537 | + return false; |
|
| 2538 | + } |
|
| 2539 | + |
|
| 2540 | + |
|
| 2541 | + |
|
| 2542 | + |
|
| 2543 | + |
|
| 2544 | + |
|
| 2545 | + /********************************************************************************************************/ |
|
| 2546 | + /********************************** PROCESS GATEWAY RESPONSE **********************************/ |
|
| 2547 | + /********************************************************************************************************/ |
|
| 2548 | + /** |
|
| 2549 | + * process_gateway_response |
|
| 2550 | + * this is the return point for Off-Site Payment Methods |
|
| 2551 | + * It will attempt to "handle the IPN" if it appears that this has not already occurred, |
|
| 2552 | + * otherwise, it will load up the last payment made for the TXN. |
|
| 2553 | + * If the payment retrieved looks good, it will then either: |
|
| 2554 | + * complete the current step and allow advancement to the next reg step |
|
| 2555 | + * or present the payment options again |
|
| 2556 | + * |
|
| 2557 | + * @access private |
|
| 2558 | + * @return EE_Payment|FALSE |
|
| 2559 | + * @throws EE_Error |
|
| 2560 | + * @throws InvalidArgumentException |
|
| 2561 | + * @throws ReflectionException |
|
| 2562 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 2563 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 2564 | + * @throws \EventEspresso\core\exceptions\InvalidSessionDataException |
|
| 2565 | + */ |
|
| 2566 | + public function process_gateway_response() |
|
| 2567 | + { |
|
| 2568 | + $payment = null; |
|
| 2569 | + // how have they chosen to pay? |
|
| 2570 | + $this->checkout->selected_method_of_payment = $this->_get_selected_method_of_payment(true); |
|
| 2571 | + // get EE_Payment_Method object |
|
| 2572 | + if (! $this->checkout->payment_method = $this->_get_payment_method_for_selected_method_of_payment()) { |
|
| 2573 | + $this->checkout->continue_reg = false; |
|
| 2574 | + return false; |
|
| 2575 | + } |
|
| 2576 | + if (! $this->checkout->payment_method->is_off_site()) { |
|
| 2577 | + return false; |
|
| 2578 | + } |
|
| 2579 | + $this->_validate_offsite_return(); |
|
| 2580 | + // DEBUG LOG |
|
| 2581 | + // $this->checkout->log( |
|
| 2582 | + // __CLASS__, |
|
| 2583 | + // __FUNCTION__, |
|
| 2584 | + // __LINE__, |
|
| 2585 | + // array( |
|
| 2586 | + // 'selected_method_of_payment' => $this->checkout->selected_method_of_payment, |
|
| 2587 | + // 'payment_method' => $this->checkout->payment_method, |
|
| 2588 | + // ), |
|
| 2589 | + // true |
|
| 2590 | + // ); |
|
| 2591 | + // verify TXN |
|
| 2592 | + if ($this->checkout->transaction instanceof EE_Transaction) { |
|
| 2593 | + $gateway = $this->checkout->payment_method->type_obj()->get_gateway(); |
|
| 2594 | + if (! $gateway instanceof EE_Offsite_Gateway) { |
|
| 2595 | + $this->checkout->continue_reg = false; |
|
| 2596 | + return false; |
|
| 2597 | + } |
|
| 2598 | + $payment = $this->_process_off_site_payment($gateway); |
|
| 2599 | + $payment = $this->_process_cancelled_payments($payment); |
|
| 2600 | + $payment = $this->_validate_payment($payment); |
|
| 2601 | + // if payment was not declined by the payment gateway or cancelled by the registrant |
|
| 2602 | + if ($this->_process_payment_status($payment, EE_PMT_Base::offsite)) { |
|
| 2603 | + // $this->_setup_redirect_for_next_step(); |
|
| 2604 | + // store that for later |
|
| 2605 | + $this->checkout->payment = $payment; |
|
| 2606 | + // mark this reg step as completed, as long as gateway doesn't use a separate IPN request, |
|
| 2607 | + // because we will complete this step during the IPN processing then |
|
| 2608 | + if ($gateway instanceof EE_Offsite_Gateway && ! $this->handle_IPN_in_this_request()) { |
|
| 2609 | + $this->set_completed(); |
|
| 2610 | + } |
|
| 2611 | + return true; |
|
| 2612 | + } |
|
| 2613 | + } |
|
| 2614 | + // DEBUG LOG |
|
| 2615 | + // $this->checkout->log( |
|
| 2616 | + // __CLASS__, |
|
| 2617 | + // __FUNCTION__, |
|
| 2618 | + // __LINE__, |
|
| 2619 | + // array('payment' => $payment) |
|
| 2620 | + // ); |
|
| 2621 | + $this->checkout->continue_reg = false; |
|
| 2622 | + return false; |
|
| 2623 | + } |
|
| 2624 | + |
|
| 2625 | + |
|
| 2626 | + /** |
|
| 2627 | + * _validate_return |
|
| 2628 | + * |
|
| 2629 | + * @access private |
|
| 2630 | + * @return void |
|
| 2631 | + * @throws EE_Error |
|
| 2632 | + * @throws InvalidArgumentException |
|
| 2633 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 2634 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 2635 | + * @throws \EventEspresso\core\exceptions\InvalidSessionDataException |
|
| 2636 | + */ |
|
| 2637 | + private function _validate_offsite_return() |
|
| 2638 | + { |
|
| 2639 | + $TXN_ID = (int) EE_Registry::instance()->REQ->get('spco_txn', 0); |
|
| 2640 | + if ($TXN_ID !== $this->checkout->transaction->ID()) { |
|
| 2641 | + // Houston... we might have a problem |
|
| 2642 | + $invalid_TXN = false; |
|
| 2643 | + // first gather some info |
|
| 2644 | + $valid_TXN = EEM_Transaction::instance()->get_one_by_ID($TXN_ID); |
|
| 2645 | + $primary_registrant = $valid_TXN instanceof EE_Transaction |
|
| 2646 | + ? $valid_TXN->primary_registration() |
|
| 2647 | + : null; |
|
| 2648 | + // let's start by retrieving the cart for this TXN |
|
| 2649 | + $cart = $this->checkout->get_cart_for_transaction($this->checkout->transaction); |
|
| 2650 | + if ($cart instanceof EE_Cart) { |
|
| 2651 | + // verify that the current cart has tickets |
|
| 2652 | + $tickets = $cart->get_tickets(); |
|
| 2653 | + if (empty($tickets)) { |
|
| 2654 | + $invalid_TXN = true; |
|
| 2655 | + } |
|
| 2656 | + } else { |
|
| 2657 | + $invalid_TXN = true; |
|
| 2658 | + } |
|
| 2659 | + $valid_TXN_SID = $primary_registrant instanceof EE_Registration |
|
| 2660 | + ? $primary_registrant->session_ID() |
|
| 2661 | + : null; |
|
| 2662 | + // validate current Session ID and compare against valid TXN session ID |
|
| 2663 | + if ($invalid_TXN // if this is already true, then skip other checks |
|
| 2664 | + || EE_Session::instance()->id() === null |
|
| 2665 | + || ( |
|
| 2666 | + // WARNING !!! |
|
| 2667 | + // this could be PayPal sending back duplicate requests (ya they do that) |
|
| 2668 | + // or it **could** mean someone is simply registering AGAIN after having just done so |
|
| 2669 | + // so now we need to determine if this current TXN looks valid or not |
|
| 2670 | + // and whether this reg step has even been started ? |
|
| 2671 | + EE_Session::instance()->id() === $valid_TXN_SID |
|
| 2672 | + // really? you're half way through this reg step, but you never started it ? |
|
| 2673 | + && $this->checkout->transaction->reg_step_completed($this->slug()) === false |
|
| 2674 | + ) |
|
| 2675 | + ) { |
|
| 2676 | + $invalid_TXN = true; |
|
| 2677 | + } |
|
| 2678 | + if ($invalid_TXN) { |
|
| 2679 | + // is the valid TXN completed ? |
|
| 2680 | + if ($valid_TXN instanceof EE_Transaction) { |
|
| 2681 | + // has this step even been started ? |
|
| 2682 | + $reg_step_completed = $valid_TXN->reg_step_completed($this->slug()); |
|
| 2683 | + if ($reg_step_completed !== false && $reg_step_completed !== true) { |
|
| 2684 | + // so it **looks** like this is a double request from PayPal |
|
| 2685 | + // so let's try to pick up where we left off |
|
| 2686 | + $this->checkout->transaction = $valid_TXN; |
|
| 2687 | + $this->checkout->refresh_all_entities(true); |
|
| 2688 | + return; |
|
| 2689 | + } |
|
| 2690 | + } |
|
| 2691 | + // you appear to be lost? |
|
| 2692 | + $this->_redirect_wayward_request($primary_registrant); |
|
| 2693 | + } |
|
| 2694 | + } |
|
| 2695 | + } |
|
| 2696 | + |
|
| 2697 | + |
|
| 2698 | + /** |
|
| 2699 | + * _redirect_wayward_request |
|
| 2700 | + * |
|
| 2701 | + * @access private |
|
| 2702 | + * @param \EE_Registration|null $primary_registrant |
|
| 2703 | + * @return bool |
|
| 2704 | + * @throws EE_Error |
|
| 2705 | + * @throws InvalidArgumentException |
|
| 2706 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 2707 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 2708 | + */ |
|
| 2709 | + private function _redirect_wayward_request(EE_Registration $primary_registrant) |
|
| 2710 | + { |
|
| 2711 | + if (! $primary_registrant instanceof EE_Registration) { |
|
| 2712 | + // try redirecting based on the current TXN |
|
| 2713 | + $primary_registrant = $this->checkout->transaction instanceof EE_Transaction |
|
| 2714 | + ? $this->checkout->transaction->primary_registration() |
|
| 2715 | + : null; |
|
| 2716 | + } |
|
| 2717 | + if (! $primary_registrant instanceof EE_Registration) { |
|
| 2718 | + EE_Error::add_error( |
|
| 2719 | + sprintf( |
|
| 2720 | + esc_html__( |
|
| 2721 | + 'Invalid information was received from the Off-Site Payment Processor and your Transaction details could not be retrieved from the database.%1$sPlease try again or contact %2$s for assistance.', |
|
| 2722 | + 'event_espresso' |
|
| 2723 | + ), |
|
| 2724 | + '<br/>', |
|
| 2725 | + EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
| 2726 | + ), |
|
| 2727 | + __FILE__, |
|
| 2728 | + __FUNCTION__, |
|
| 2729 | + __LINE__ |
|
| 2730 | + ); |
|
| 2731 | + return false; |
|
| 2732 | + } |
|
| 2733 | + // make sure transaction is not locked |
|
| 2734 | + $this->checkout->transaction->unlock(); |
|
| 2735 | + wp_safe_redirect( |
|
| 2736 | + add_query_arg( |
|
| 2737 | + array( |
|
| 2738 | + 'e_reg_url_link' => $primary_registrant->reg_url_link(), |
|
| 2739 | + ), |
|
| 2740 | + $this->checkout->thank_you_page_url |
|
| 2741 | + ) |
|
| 2742 | + ); |
|
| 2743 | + exit(); |
|
| 2744 | + } |
|
| 2745 | + |
|
| 2746 | + |
|
| 2747 | + /** |
|
| 2748 | + * _process_off_site_payment |
|
| 2749 | + * |
|
| 2750 | + * @access private |
|
| 2751 | + * @param \EE_Offsite_Gateway $gateway |
|
| 2752 | + * @return EE_Payment |
|
| 2753 | + * @throws EE_Error |
|
| 2754 | + * @throws InvalidArgumentException |
|
| 2755 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 2756 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 2757 | + */ |
|
| 2758 | + private function _process_off_site_payment(EE_Offsite_Gateway $gateway) |
|
| 2759 | + { |
|
| 2760 | + try { |
|
| 2761 | + $request_data = \EE_Registry::instance()->REQ->params(); |
|
| 2762 | + // if gateway uses_separate_IPN_request, then we don't have to process the IPN manually |
|
| 2763 | + $this->set_handle_IPN_in_this_request( |
|
| 2764 | + $gateway->handle_IPN_in_this_request($request_data, false) |
|
| 2765 | + ); |
|
| 2766 | + if ($this->handle_IPN_in_this_request()) { |
|
| 2767 | + // get payment details and process results |
|
| 2768 | + /** @type EE_Payment_Processor $payment_processor */ |
|
| 2769 | + $payment_processor = EE_Registry::instance()->load_core('Payment_Processor'); |
|
| 2770 | + $payment = $payment_processor->process_ipn( |
|
| 2771 | + $request_data, |
|
| 2772 | + $this->checkout->transaction, |
|
| 2773 | + $this->checkout->payment_method, |
|
| 2774 | + true, |
|
| 2775 | + false |
|
| 2776 | + ); |
|
| 2777 | + // $payment_source = 'process_ipn'; |
|
| 2778 | + } else { |
|
| 2779 | + $payment = $this->checkout->transaction->last_payment(); |
|
| 2780 | + // $payment_source = 'last_payment'; |
|
| 2781 | + } |
|
| 2782 | + } catch (Exception $e) { |
|
| 2783 | + // let's just eat the exception and try to move on using any previously set payment info |
|
| 2784 | + $payment = $this->checkout->transaction->last_payment(); |
|
| 2785 | + // $payment_source = 'last_payment after Exception'; |
|
| 2786 | + // but if we STILL don't have a payment object |
|
| 2787 | + if (! $payment instanceof EE_Payment) { |
|
| 2788 | + // then we'll object ! ( not object like a thing... but object like what a lawyer says ! ) |
|
| 2789 | + $this->_handle_payment_processor_exception($e); |
|
| 2790 | + } |
|
| 2791 | + } |
|
| 2792 | + // DEBUG LOG |
|
| 2793 | + // $this->checkout->log( |
|
| 2794 | + // __CLASS__, |
|
| 2795 | + // __FUNCTION__, |
|
| 2796 | + // __LINE__, |
|
| 2797 | + // array( |
|
| 2798 | + // 'process_ipn_payment' => $payment, |
|
| 2799 | + // 'payment_source' => $payment_source, |
|
| 2800 | + // ) |
|
| 2801 | + // ); |
|
| 2802 | + return $payment; |
|
| 2803 | + } |
|
| 2804 | + |
|
| 2805 | + |
|
| 2806 | + /** |
|
| 2807 | + * _process_cancelled_payments |
|
| 2808 | + * just makes sure that the payment status gets updated correctly |
|
| 2809 | + * so tha tan error isn't generated during payment validation |
|
| 2810 | + * |
|
| 2811 | + * @access private |
|
| 2812 | + * @param EE_Payment $payment |
|
| 2813 | + * @return EE_Payment | FALSE |
|
| 2814 | + * @throws \EE_Error |
|
| 2815 | + */ |
|
| 2816 | + private function _process_cancelled_payments($payment = null) |
|
| 2817 | + { |
|
| 2818 | + if ($payment instanceof EE_Payment |
|
| 2819 | + && isset($_REQUEST['ee_cancel_payment']) |
|
| 2820 | + && $payment->status() === EEM_Payment::status_id_failed |
|
| 2821 | + ) { |
|
| 2822 | + $payment->set_status(EEM_Payment::status_id_cancelled); |
|
| 2823 | + } |
|
| 2824 | + return $payment; |
|
| 2825 | + } |
|
| 2826 | + |
|
| 2827 | + |
|
| 2828 | + /** |
|
| 2829 | + * get_transaction_details_for_gateways |
|
| 2830 | + * |
|
| 2831 | + * @access public |
|
| 2832 | + * @return int |
|
| 2833 | + * @throws EE_Error |
|
| 2834 | + * @throws InvalidArgumentException |
|
| 2835 | + * @throws ReflectionException |
|
| 2836 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 2837 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 2838 | + */ |
|
| 2839 | + public function get_transaction_details_for_gateways() |
|
| 2840 | + { |
|
| 2841 | + $txn_details = array(); |
|
| 2842 | + // ya gotta make a choice man |
|
| 2843 | + if (empty($this->checkout->selected_method_of_payment)) { |
|
| 2844 | + $txn_details = array( |
|
| 2845 | + 'error' => esc_html__('Please select a method of payment before proceeding.', 'event_espresso'), |
|
| 2846 | + ); |
|
| 2847 | + } |
|
| 2848 | + // get EE_Payment_Method object |
|
| 2849 | + if (empty($txn_details) |
|
| 2850 | + && |
|
| 2851 | + ! $this->checkout->payment_method = $this->_get_payment_method_for_selected_method_of_payment() |
|
| 2852 | + ) { |
|
| 2853 | + $txn_details = array( |
|
| 2854 | + 'selected_method_of_payment' => $this->checkout->selected_method_of_payment, |
|
| 2855 | + 'error' => esc_html__( |
|
| 2856 | + 'A valid Payment Method could not be determined.', |
|
| 2857 | + 'event_espresso' |
|
| 2858 | + ), |
|
| 2859 | + ); |
|
| 2860 | + } |
|
| 2861 | + if (empty($txn_details) && $this->checkout->transaction instanceof EE_Transaction) { |
|
| 2862 | + $return_url = $this->_get_return_url($this->checkout->payment_method); |
|
| 2863 | + $txn_details = array( |
|
| 2864 | + 'TXN_ID' => $this->checkout->transaction->ID(), |
|
| 2865 | + 'TXN_timestamp' => $this->checkout->transaction->datetime(), |
|
| 2866 | + 'TXN_total' => $this->checkout->transaction->total(), |
|
| 2867 | + 'TXN_paid' => $this->checkout->transaction->paid(), |
|
| 2868 | + 'TXN_reg_steps' => $this->checkout->transaction->reg_steps(), |
|
| 2869 | + 'STS_ID' => $this->checkout->transaction->status_ID(), |
|
| 2870 | + 'PMD_ID' => $this->checkout->transaction->payment_method_ID(), |
|
| 2871 | + 'payment_amount' => $this->checkout->amount_owing, |
|
| 2872 | + 'return_url' => $return_url, |
|
| 2873 | + 'cancel_url' => add_query_arg(array('ee_cancel_payment' => true), $return_url), |
|
| 2874 | + 'notify_url' => EE_Config::instance()->core->txn_page_url( |
|
| 2875 | + array( |
|
| 2876 | + 'e_reg_url_link' => $this->checkout->transaction->primary_registration()->reg_url_link(), |
|
| 2877 | + 'ee_payment_method' => $this->checkout->payment_method->slug(), |
|
| 2878 | + ) |
|
| 2879 | + ), |
|
| 2880 | + ); |
|
| 2881 | + } |
|
| 2882 | + echo wp_json_encode($txn_details); |
|
| 2883 | + exit(); |
|
| 2884 | + } |
|
| 2885 | + |
|
| 2886 | + |
|
| 2887 | + /** |
|
| 2888 | + * __sleep |
|
| 2889 | + * to conserve db space, let's remove the reg_form and the EE_Checkout object from EE_SPCO_Reg_Step objects upon |
|
| 2890 | + * serialization EE_Checkout will handle the reimplementation of itself upon waking, but we won't bother with the |
|
| 2891 | + * reg form, because if needed, it will be regenerated anyways |
|
| 2892 | + * |
|
| 2893 | + * @return array |
|
| 2894 | + */ |
|
| 2895 | + public function __sleep() |
|
| 2896 | + { |
|
| 2897 | + // remove the reg form and the checkout |
|
| 2898 | + return array_diff(array_keys(get_object_vars($this)), array('reg_form', 'checkout', 'line_item_display')); |
|
| 2899 | + } |
|
| 2900 | 2900 | } |
@@ -129,7 +129,7 @@ discard block |
||
| 129 | 129 | { |
| 130 | 130 | $this->_slug = 'payment_options'; |
| 131 | 131 | $this->_name = esc_html__('Payment Options', 'event_espresso'); |
| 132 | - $this->_template = SPCO_REG_STEPS_PATH . $this->_slug . '/payment_options_main.template.php'; |
|
| 132 | + $this->_template = SPCO_REG_STEPS_PATH.$this->_slug.'/payment_options_main.template.php'; |
|
| 133 | 133 | $this->checkout = $checkout; |
| 134 | 134 | $this->_reset_success_message(); |
| 135 | 135 | $this->set_instructions( |
@@ -212,7 +212,7 @@ discard block |
||
| 212 | 212 | { |
| 213 | 213 | $transaction = $this->checkout->transaction; |
| 214 | 214 | // if the transaction isn't set or nothing is owed on it, don't enqueue any JS |
| 215 | - if (! $transaction instanceof EE_Transaction || EEH_Money::compare_floats($transaction->remaining(), 0)) { |
|
| 215 | + if ( ! $transaction instanceof EE_Transaction || EEH_Money::compare_floats($transaction->remaining(), 0)) { |
|
| 216 | 216 | return; |
| 217 | 217 | } |
| 218 | 218 | foreach (EEM_Payment_Method::instance()->get_all_for_transaction( |
@@ -304,18 +304,18 @@ discard block |
||
| 304 | 304 | foreach ($registrations as $REG_ID => $registration) { |
| 305 | 305 | /** @var $registration EE_Registration */ |
| 306 | 306 | // has this registration lost it's space ? |
| 307 | - if (isset($ejected_registrations[ $REG_ID ])) { |
|
| 307 | + if (isset($ejected_registrations[$REG_ID])) { |
|
| 308 | 308 | if ($registration->event()->is_sold_out() || $registration->event()->is_sold_out(true)) { |
| 309 | - $sold_out_events[ $registration->event()->ID() ] = $registration->event(); |
|
| 309 | + $sold_out_events[$registration->event()->ID()] = $registration->event(); |
|
| 310 | 310 | } else { |
| 311 | - $insufficient_spaces_available[ $registration->event()->ID() ] = $registration->event(); |
|
| 311 | + $insufficient_spaces_available[$registration->event()->ID()] = $registration->event(); |
|
| 312 | 312 | } |
| 313 | 313 | continue; |
| 314 | 314 | } |
| 315 | 315 | // event requires admin approval |
| 316 | 316 | if ($registration->status_ID() === EEM_Registration::status_id_not_approved) { |
| 317 | 317 | // add event to list of events with pre-approval reg status |
| 318 | - $registrations_requiring_pre_approval[ $REG_ID ] = $registration; |
|
| 318 | + $registrations_requiring_pre_approval[$REG_ID] = $registration; |
|
| 319 | 319 | do_action( |
| 320 | 320 | 'AHEE__EE_SPCO_Reg_Step_Payment_Options__generate_reg_form__event_requires_pre_approval', |
| 321 | 321 | $registration->event(), |
@@ -331,7 +331,7 @@ discard block |
||
| 331 | 331 | ) |
| 332 | 332 | ) { |
| 333 | 333 | // add event to list of events that are sold out |
| 334 | - $sold_out_events[ $registration->event()->ID() ] = $registration->event(); |
|
| 334 | + $sold_out_events[$registration->event()->ID()] = $registration->event(); |
|
| 335 | 335 | do_action( |
| 336 | 336 | 'AHEE__EE_SPCO_Reg_Step_Payment_Options__generate_reg_form__sold_out_event', |
| 337 | 337 | $registration->event(), |
@@ -341,38 +341,38 @@ discard block |
||
| 341 | 341 | } |
| 342 | 342 | // are they allowed to pay now and is there monies owing? |
| 343 | 343 | if ($registration->owes_monies_and_can_pay()) { |
| 344 | - $registrations_requiring_payment[ $REG_ID ] = $registration; |
|
| 344 | + $registrations_requiring_payment[$REG_ID] = $registration; |
|
| 345 | 345 | do_action( |
| 346 | 346 | 'AHEE__EE_SPCO_Reg_Step_Payment_Options__generate_reg_form__event_requires_payment', |
| 347 | 347 | $registration->event(), |
| 348 | 348 | $this |
| 349 | 349 | ); |
| 350 | - } elseif (! $this->checkout->revisit |
|
| 350 | + } elseif ( ! $this->checkout->revisit |
|
| 351 | 351 | && $registration->status_ID() !== EEM_Registration::status_id_not_approved |
| 352 | 352 | && $registration->ticket()->is_free() |
| 353 | 353 | ) { |
| 354 | - $registrations_for_free_events[ $registration->ticket()->ID() ] = $registration; |
|
| 354 | + $registrations_for_free_events[$registration->ticket()->ID()] = $registration; |
|
| 355 | 355 | } |
| 356 | 356 | } |
| 357 | 357 | $subsections = array(); |
| 358 | 358 | // now decide which template to load |
| 359 | - if (! empty($sold_out_events)) { |
|
| 359 | + if ( ! empty($sold_out_events)) { |
|
| 360 | 360 | $subsections['sold_out_events'] = $this->_sold_out_events($sold_out_events); |
| 361 | 361 | } |
| 362 | - if (! empty($insufficient_spaces_available)) { |
|
| 362 | + if ( ! empty($insufficient_spaces_available)) { |
|
| 363 | 363 | $subsections['insufficient_space'] = $this->_insufficient_spaces_available( |
| 364 | 364 | $insufficient_spaces_available |
| 365 | 365 | ); |
| 366 | 366 | } |
| 367 | - if (! empty($registrations_requiring_pre_approval)) { |
|
| 367 | + if ( ! empty($registrations_requiring_pre_approval)) { |
|
| 368 | 368 | $subsections['registrations_requiring_pre_approval'] = $this->_registrations_requiring_pre_approval( |
| 369 | 369 | $registrations_requiring_pre_approval |
| 370 | 370 | ); |
| 371 | 371 | } |
| 372 | - if (! empty($registrations_for_free_events)) { |
|
| 372 | + if ( ! empty($registrations_for_free_events)) { |
|
| 373 | 373 | $subsections['no_payment_required'] = $this->_no_payment_required($registrations_for_free_events); |
| 374 | 374 | } |
| 375 | - if (! empty($registrations_requiring_payment)) { |
|
| 375 | + if ( ! empty($registrations_requiring_payment)) { |
|
| 376 | 376 | if ($this->checkout->amount_owing > 0) { |
| 377 | 377 | // autoload Line_Item_Display classes |
| 378 | 378 | EEH_Autoloader::register_line_item_filter_autoloaders(); |
@@ -437,13 +437,13 @@ discard block |
||
| 437 | 437 | */ |
| 438 | 438 | public static function add_spco_line_item_filters(EE_Line_Item_Filter_Collection $line_item_filter_collection) |
| 439 | 439 | { |
| 440 | - if (! EE_Registry::instance()->SSN instanceof EE_Session) { |
|
| 440 | + if ( ! EE_Registry::instance()->SSN instanceof EE_Session) { |
|
| 441 | 441 | return $line_item_filter_collection; |
| 442 | 442 | } |
| 443 | - if (! EE_Registry::instance()->SSN->checkout() instanceof EE_Checkout) { |
|
| 443 | + if ( ! EE_Registry::instance()->SSN->checkout() instanceof EE_Checkout) { |
|
| 444 | 444 | return $line_item_filter_collection; |
| 445 | 445 | } |
| 446 | - if (! EE_Registry::instance()->SSN->checkout()->transaction instanceof EE_Transaction) { |
|
| 446 | + if ( ! EE_Registry::instance()->SSN->checkout()->transaction instanceof EE_Transaction) { |
|
| 447 | 447 | return $line_item_filter_collection; |
| 448 | 448 | } |
| 449 | 449 | $line_item_filter_collection->add( |
@@ -483,8 +483,8 @@ discard block |
||
| 483 | 483 | ); |
| 484 | 484 | foreach ($registrations as $REG_ID => $registration) { |
| 485 | 485 | // has this registration lost it's space ? |
| 486 | - if (isset($ejected_registrations[ $REG_ID ])) { |
|
| 487 | - unset($registrations[ $REG_ID ]); |
|
| 486 | + if (isset($ejected_registrations[$REG_ID])) { |
|
| 487 | + unset($registrations[$REG_ID]); |
|
| 488 | 488 | continue; |
| 489 | 489 | } |
| 490 | 490 | } |
@@ -534,24 +534,24 @@ discard block |
||
| 534 | 534 | } |
| 535 | 535 | $EVT_ID = $registration->event_ID(); |
| 536 | 536 | $ticket = $registration->ticket(); |
| 537 | - if (! isset($tickets_remaining[ $ticket->ID() ])) { |
|
| 538 | - $tickets_remaining[ $ticket->ID() ] = $ticket->remaining(); |
|
| 537 | + if ( ! isset($tickets_remaining[$ticket->ID()])) { |
|
| 538 | + $tickets_remaining[$ticket->ID()] = $ticket->remaining(); |
|
| 539 | 539 | } |
| 540 | - if ($tickets_remaining[ $ticket->ID() ] > 0) { |
|
| 541 | - if (! isset($event_reg_count[ $EVT_ID ])) { |
|
| 542 | - $event_reg_count[ $EVT_ID ] = 0; |
|
| 540 | + if ($tickets_remaining[$ticket->ID()] > 0) { |
|
| 541 | + if ( ! isset($event_reg_count[$EVT_ID])) { |
|
| 542 | + $event_reg_count[$EVT_ID] = 0; |
|
| 543 | 543 | } |
| 544 | - $event_reg_count[ $EVT_ID ]++; |
|
| 545 | - if (! isset($event_spaces_remaining[ $EVT_ID ])) { |
|
| 546 | - $event_spaces_remaining[ $EVT_ID ] = $registration->event()->spaces_remaining_for_sale(); |
|
| 544 | + $event_reg_count[$EVT_ID]++; |
|
| 545 | + if ( ! isset($event_spaces_remaining[$EVT_ID])) { |
|
| 546 | + $event_spaces_remaining[$EVT_ID] = $registration->event()->spaces_remaining_for_sale(); |
|
| 547 | 547 | } |
| 548 | 548 | } |
| 549 | 549 | if ($revisit |
| 550 | - && ($tickets_remaining[ $ticket->ID() ] === 0 |
|
| 551 | - || $event_reg_count[ $EVT_ID ] > $event_spaces_remaining[ $EVT_ID ] |
|
| 550 | + && ($tickets_remaining[$ticket->ID()] === 0 |
|
| 551 | + || $event_reg_count[$EVT_ID] > $event_spaces_remaining[$EVT_ID] |
|
| 552 | 552 | ) |
| 553 | 553 | ) { |
| 554 | - $ejected_registrations[ $REG_ID ] = $registration->event(); |
|
| 554 | + $ejected_registrations[$REG_ID] = $registration->event(); |
|
| 555 | 555 | if ($registration->status_ID() !== EEM_Registration::status_id_wait_list) { |
| 556 | 556 | /** @type EE_Registration_Processor $registration_processor */ |
| 557 | 557 | $registration_processor = EE_Registry::instance()->load_class('Registration_Processor'); |
@@ -611,7 +611,7 @@ discard block |
||
| 611 | 611 | foreach ($sold_out_events_array as $sold_out_event) { |
| 612 | 612 | $sold_out_events .= EEH_HTML::li( |
| 613 | 613 | EEH_HTML::span( |
| 614 | - ' ' . $sold_out_event->name(), |
|
| 614 | + ' '.$sold_out_event->name(), |
|
| 615 | 615 | '', |
| 616 | 616 | 'dashicons dashicons-marker ee-icon-size-16 pink-text' |
| 617 | 617 | ) |
@@ -666,7 +666,7 @@ discard block |
||
| 666 | 666 | foreach ($insufficient_spaces_events_array as $event) { |
| 667 | 667 | if ($event instanceof EE_Event) { |
| 668 | 668 | $insufficient_space_events .= EEH_HTML::li( |
| 669 | - EEH_HTML::span(' ' . $event->name(), '', 'dashicons dashicons-marker ee-icon-size-16 pink-text') |
|
| 669 | + EEH_HTML::span(' '.$event->name(), '', 'dashicons dashicons-marker ee-icon-size-16 pink-text') |
|
| 670 | 670 | ); |
| 671 | 671 | } |
| 672 | 672 | } |
@@ -714,7 +714,7 @@ discard block |
||
| 714 | 714 | $events_requiring_pre_approval = array(); |
| 715 | 715 | foreach ($registrations_requiring_pre_approval as $registration) { |
| 716 | 716 | if ($registration instanceof EE_Registration && $registration->event() instanceof EE_Event) { |
| 717 | - $events_requiring_pre_approval[ $registration->event()->ID() ] = EEH_HTML::li( |
|
| 717 | + $events_requiring_pre_approval[$registration->event()->ID()] = EEH_HTML::li( |
|
| 718 | 718 | EEH_HTML::span( |
| 719 | 719 | '', |
| 720 | 720 | '', |
@@ -853,7 +853,7 @@ discard block |
||
| 853 | 853 | { |
| 854 | 854 | return new EE_Form_Section_Proper( |
| 855 | 855 | array( |
| 856 | - 'html_id' => 'ee-' . $this->slug() . '-extra-hidden-inputs', |
|
| 856 | + 'html_id' => 'ee-'.$this->slug().'-extra-hidden-inputs', |
|
| 857 | 857 | 'layout_strategy' => new EE_Div_Per_Section_Layout(), |
| 858 | 858 | 'subsections' => array( |
| 859 | 859 | 'spco_no_payment_required' => new EE_Hidden_Input( |
@@ -893,7 +893,7 @@ discard block |
||
| 893 | 893 | $payments += $registration->registration_payments(); |
| 894 | 894 | } |
| 895 | 895 | } |
| 896 | - if (! empty($payments)) { |
|
| 896 | + if ( ! empty($payments)) { |
|
| 897 | 897 | foreach ($payments as $payment) { |
| 898 | 898 | if ($payment instanceof EE_Registration_Payment) { |
| 899 | 899 | $this->checkout->amount_owing -= $payment->amount(); |
@@ -1017,23 +1017,23 @@ discard block |
||
| 1017 | 1017 | $payment_method_button = EEH_HTML::img( |
| 1018 | 1018 | $payment_method->button_url(), |
| 1019 | 1019 | $payment_method->name(), |
| 1020 | - 'spco-payment-method-' . $payment_method->slug() . '-btn-img', |
|
| 1020 | + 'spco-payment-method-'.$payment_method->slug().'-btn-img', |
|
| 1021 | 1021 | 'spco-payment-method-btn-img' |
| 1022 | 1022 | ); |
| 1023 | 1023 | // check if any payment methods are set as default |
| 1024 | 1024 | // if payment method is already selected OR nothing is selected and this payment method should be |
| 1025 | 1025 | // open_by_default |
| 1026 | 1026 | if (($this->checkout->selected_method_of_payment === $payment_method->slug()) |
| 1027 | - || (! $this->checkout->selected_method_of_payment && $payment_method->open_by_default()) |
|
| 1027 | + || ( ! $this->checkout->selected_method_of_payment && $payment_method->open_by_default()) |
|
| 1028 | 1028 | ) { |
| 1029 | 1029 | $this->checkout->selected_method_of_payment = $payment_method->slug(); |
| 1030 | 1030 | $this->_save_selected_method_of_payment(); |
| 1031 | - $default_payment_method_option[ $payment_method->slug() ] = $payment_method_button; |
|
| 1031 | + $default_payment_method_option[$payment_method->slug()] = $payment_method_button; |
|
| 1032 | 1032 | } else { |
| 1033 | - $available_payment_method_options[ $payment_method->slug() ] = $payment_method_button; |
|
| 1033 | + $available_payment_method_options[$payment_method->slug()] = $payment_method_button; |
|
| 1034 | 1034 | } |
| 1035 | - $payment_methods_billing_info[ $payment_method->slug( |
|
| 1036 | - ) . '-info' ] = $this->_payment_method_billing_info( |
|
| 1035 | + $payment_methods_billing_info[$payment_method->slug( |
|
| 1036 | + ).'-info'] = $this->_payment_method_billing_info( |
|
| 1037 | 1037 | $payment_method |
| 1038 | 1038 | ); |
| 1039 | 1039 | } |
@@ -1069,7 +1069,7 @@ discard block |
||
| 1069 | 1069 | */ |
| 1070 | 1070 | protected function _get_available_payment_methods() |
| 1071 | 1071 | { |
| 1072 | - if (! empty($this->checkout->available_payment_methods)) { |
|
| 1072 | + if ( ! empty($this->checkout->available_payment_methods)) { |
|
| 1073 | 1073 | return $this->checkout->available_payment_methods; |
| 1074 | 1074 | } |
| 1075 | 1075 | $available_payment_methods = array(); |
@@ -1084,7 +1084,7 @@ discard block |
||
| 1084 | 1084 | ); |
| 1085 | 1085 | foreach ($payment_methods as $payment_method) { |
| 1086 | 1086 | if ($payment_method instanceof EE_Payment_Method) { |
| 1087 | - $available_payment_methods[ $payment_method->slug() ] = $payment_method; |
|
| 1087 | + $available_payment_methods[$payment_method->slug()] = $payment_method; |
|
| 1088 | 1088 | } |
| 1089 | 1089 | } |
| 1090 | 1090 | return $available_payment_methods; |
@@ -1179,7 +1179,7 @@ discard block |
||
| 1179 | 1179 | ); |
| 1180 | 1180 | return new EE_Form_Section_Proper( |
| 1181 | 1181 | array( |
| 1182 | - 'html_id' => 'spco-payment-method-info-' . $payment_method->slug(), |
|
| 1182 | + 'html_id' => 'spco-payment-method-info-'.$payment_method->slug(), |
|
| 1183 | 1183 | 'html_class' => 'spco-payment-method-info-dv', |
| 1184 | 1184 | // only display the selected or default PM |
| 1185 | 1185 | 'html_style' => $currently_selected ? '' : 'display:none;', |
@@ -1209,7 +1209,7 @@ discard block |
||
| 1209 | 1209 | // how have they chosen to pay? |
| 1210 | 1210 | $this->checkout->selected_method_of_payment = $this->_get_selected_method_of_payment(true); |
| 1211 | 1211 | $this->checkout->payment_method = $this->_get_payment_method_for_selected_method_of_payment(); |
| 1212 | - if (! $this->checkout->payment_method instanceof EE_Payment_Method) { |
|
| 1212 | + if ( ! $this->checkout->payment_method instanceof EE_Payment_Method) { |
|
| 1213 | 1213 | return false; |
| 1214 | 1214 | } |
| 1215 | 1215 | if (apply_filters( |
@@ -1381,7 +1381,7 @@ discard block |
||
| 1381 | 1381 | */ |
| 1382 | 1382 | public function switch_payment_method() |
| 1383 | 1383 | { |
| 1384 | - if (! $this->_verify_payment_method_is_set()) { |
|
| 1384 | + if ( ! $this->_verify_payment_method_is_set()) { |
|
| 1385 | 1385 | return false; |
| 1386 | 1386 | } |
| 1387 | 1387 | if (apply_filters( |
@@ -1516,7 +1516,7 @@ discard block |
||
| 1516 | 1516 | } |
| 1517 | 1517 | } |
| 1518 | 1518 | // verify payment method |
| 1519 | - if (! $this->checkout->payment_method instanceof EE_Payment_Method) { |
|
| 1519 | + if ( ! $this->checkout->payment_method instanceof EE_Payment_Method) { |
|
| 1520 | 1520 | // get payment method for selected method of payment |
| 1521 | 1521 | $this->checkout->payment_method = $this->_get_payment_method_for_selected_method_of_payment(); |
| 1522 | 1522 | } |
@@ -1541,7 +1541,7 @@ discard block |
||
| 1541 | 1541 | */ |
| 1542 | 1542 | public function save_payer_details_via_ajax() |
| 1543 | 1543 | { |
| 1544 | - if (! $this->_verify_payment_method_is_set()) { |
|
| 1544 | + if ( ! $this->_verify_payment_method_is_set()) { |
|
| 1545 | 1545 | return; |
| 1546 | 1546 | } |
| 1547 | 1547 | // generate billing form for selected method of payment if it hasn't been done already |
@@ -1551,7 +1551,7 @@ discard block |
||
| 1551 | 1551 | ); |
| 1552 | 1552 | } |
| 1553 | 1553 | // generate primary attendee from payer info if applicable |
| 1554 | - if (! $this->checkout->transaction_has_primary_registrant()) { |
|
| 1554 | + if ( ! $this->checkout->transaction_has_primary_registrant()) { |
|
| 1555 | 1555 | $attendee = $this->_create_attendee_from_request_data(); |
| 1556 | 1556 | if ($attendee instanceof EE_Attendee) { |
| 1557 | 1557 | foreach ($this->checkout->transaction->registrations() as $registration) { |
@@ -1582,7 +1582,7 @@ discard block |
||
| 1582 | 1582 | { |
| 1583 | 1583 | // get State ID |
| 1584 | 1584 | $STA_ID = ! empty($_REQUEST['state']) ? sanitize_text_field($_REQUEST['state']) : ''; |
| 1585 | - if (! empty($STA_ID)) { |
|
| 1585 | + if ( ! empty($STA_ID)) { |
|
| 1586 | 1586 | // can we get state object from name ? |
| 1587 | 1587 | EE_Registry::instance()->load_model('State'); |
| 1588 | 1588 | $state = EEM_State::instance()->get_col(array(array('STA_name' => $STA_ID), 'limit' => 1), 'STA_ID'); |
@@ -1590,7 +1590,7 @@ discard block |
||
| 1590 | 1590 | } |
| 1591 | 1591 | // get Country ISO |
| 1592 | 1592 | $CNT_ISO = ! empty($_REQUEST['country']) ? sanitize_text_field($_REQUEST['country']) : ''; |
| 1593 | - if (! empty($CNT_ISO)) { |
|
| 1593 | + if ( ! empty($CNT_ISO)) { |
|
| 1594 | 1594 | // can we get country object from name ? |
| 1595 | 1595 | EE_Registry::instance()->load_model('Country'); |
| 1596 | 1596 | $country = EEM_Country::instance()->get_col( |
@@ -1623,7 +1623,7 @@ discard block |
||
| 1623 | 1623 | } |
| 1624 | 1624 | // does this attendee already exist in the db ? we're searching using a combination of first name, last name, |
| 1625 | 1625 | // AND email address |
| 1626 | - if (! empty($attendee_data['ATT_fname']) |
|
| 1626 | + if ( ! empty($attendee_data['ATT_fname']) |
|
| 1627 | 1627 | && ! empty($attendee_data['ATT_lname']) |
| 1628 | 1628 | && ! empty($attendee_data['ATT_email']) |
| 1629 | 1629 | ) { |
@@ -1838,7 +1838,7 @@ discard block |
||
| 1838 | 1838 | private function _process_payment() |
| 1839 | 1839 | { |
| 1840 | 1840 | // basically confirm that the event hasn't sold out since they hit the page |
| 1841 | - if (! $this->_last_second_ticket_verifications()) { |
|
| 1841 | + if ( ! $this->_last_second_ticket_verifications()) { |
|
| 1842 | 1842 | return false; |
| 1843 | 1843 | } |
| 1844 | 1844 | // ya gotta make a choice man |
@@ -1849,7 +1849,7 @@ discard block |
||
| 1849 | 1849 | return false; |
| 1850 | 1850 | } |
| 1851 | 1851 | // get EE_Payment_Method object |
| 1852 | - if (! $this->checkout->payment_method = $this->_get_payment_method_for_selected_method_of_payment()) { |
|
| 1852 | + if ( ! $this->checkout->payment_method = $this->_get_payment_method_for_selected_method_of_payment()) { |
|
| 1853 | 1853 | return false; |
| 1854 | 1854 | } |
| 1855 | 1855 | // setup billing form |
@@ -1858,12 +1858,12 @@ discard block |
||
| 1858 | 1858 | $this->checkout->payment_method |
| 1859 | 1859 | ); |
| 1860 | 1860 | // bad billing form ? |
| 1861 | - if (! $this->_billing_form_is_valid()) { |
|
| 1861 | + if ( ! $this->_billing_form_is_valid()) { |
|
| 1862 | 1862 | return false; |
| 1863 | 1863 | } |
| 1864 | 1864 | } |
| 1865 | 1865 | // ensure primary registrant has been fully processed |
| 1866 | - if (! $this->_setup_primary_registrant_prior_to_payment()) { |
|
| 1866 | + if ( ! $this->_setup_primary_registrant_prior_to_payment()) { |
|
| 1867 | 1867 | return false; |
| 1868 | 1868 | } |
| 1869 | 1869 | // if session is close to expiring (under 10 minutes by default) |
@@ -1918,7 +1918,7 @@ discard block |
||
| 1918 | 1918 | protected function _last_second_ticket_verifications() |
| 1919 | 1919 | { |
| 1920 | 1920 | // don't bother re-validating if not a return visit |
| 1921 | - if (! $this->checkout->revisit) { |
|
| 1921 | + if ( ! $this->checkout->revisit) { |
|
| 1922 | 1922 | return true; |
| 1923 | 1923 | } |
| 1924 | 1924 | $registrations = $this->checkout->transaction->registrations(); |
@@ -1984,7 +1984,7 @@ discard block |
||
| 1984 | 1984 | */ |
| 1985 | 1985 | private function _billing_form_is_valid() |
| 1986 | 1986 | { |
| 1987 | - if (! $this->checkout->payment_method->type_obj()->has_billing_form()) { |
|
| 1987 | + if ( ! $this->checkout->payment_method->type_obj()->has_billing_form()) { |
|
| 1988 | 1988 | return true; |
| 1989 | 1989 | } |
| 1990 | 1990 | if ($this->checkout->billing_form instanceof EE_Billing_Info_Form) { |
@@ -2103,7 +2103,7 @@ discard block |
||
| 2103 | 2103 | { |
| 2104 | 2104 | // convert billing form data into an attendee |
| 2105 | 2105 | $this->checkout->primary_attendee_obj = $this->checkout->billing_form->create_attendee_from_billing_form_data(); |
| 2106 | - if (! $this->checkout->primary_attendee_obj instanceof EE_Attendee) { |
|
| 2106 | + if ( ! $this->checkout->primary_attendee_obj instanceof EE_Attendee) { |
|
| 2107 | 2107 | EE_Error::add_error( |
| 2108 | 2108 | sprintf( |
| 2109 | 2109 | esc_html__( |
@@ -2120,7 +2120,7 @@ discard block |
||
| 2120 | 2120 | return false; |
| 2121 | 2121 | } |
| 2122 | 2122 | $primary_registration = $this->checkout->transaction->primary_registration(); |
| 2123 | - if (! $primary_registration instanceof EE_Registration) { |
|
| 2123 | + if ( ! $primary_registration instanceof EE_Registration) { |
|
| 2124 | 2124 | EE_Error::add_error( |
| 2125 | 2125 | sprintf( |
| 2126 | 2126 | esc_html__( |
@@ -2136,7 +2136,7 @@ discard block |
||
| 2136 | 2136 | ); |
| 2137 | 2137 | return false; |
| 2138 | 2138 | } |
| 2139 | - if (! $primary_registration->_add_relation_to($this->checkout->primary_attendee_obj, 'Attendee') |
|
| 2139 | + if ( ! $primary_registration->_add_relation_to($this->checkout->primary_attendee_obj, 'Attendee') |
|
| 2140 | 2140 | instanceof |
| 2141 | 2141 | EE_Attendee |
| 2142 | 2142 | ) { |
@@ -2182,8 +2182,8 @@ discard block |
||
| 2182 | 2182 | return null; |
| 2183 | 2183 | } |
| 2184 | 2184 | // get EE_Payment_Method object |
| 2185 | - if (isset($this->checkout->available_payment_methods[ $this->checkout->selected_method_of_payment ])) { |
|
| 2186 | - $payment_method = $this->checkout->available_payment_methods[ $this->checkout->selected_method_of_payment ]; |
|
| 2185 | + if (isset($this->checkout->available_payment_methods[$this->checkout->selected_method_of_payment])) { |
|
| 2186 | + $payment_method = $this->checkout->available_payment_methods[$this->checkout->selected_method_of_payment]; |
|
| 2187 | 2187 | } else { |
| 2188 | 2188 | // load EEM_Payment_Method |
| 2189 | 2189 | EE_Registry::instance()->load_model('Payment_Method'); |
@@ -2192,7 +2192,7 @@ discard block |
||
| 2192 | 2192 | $payment_method = $EEM_Payment_Method->get_one_by_slug($this->checkout->selected_method_of_payment); |
| 2193 | 2193 | } |
| 2194 | 2194 | // verify $payment_method |
| 2195 | - if (! $payment_method instanceof EE_Payment_Method) { |
|
| 2195 | + if ( ! $payment_method instanceof EE_Payment_Method) { |
|
| 2196 | 2196 | // not a payment |
| 2197 | 2197 | EE_Error::add_error( |
| 2198 | 2198 | sprintf( |
@@ -2210,7 +2210,7 @@ discard block |
||
| 2210 | 2210 | return null; |
| 2211 | 2211 | } |
| 2212 | 2212 | // and verify it has a valid Payment_Method Type object |
| 2213 | - if (! $payment_method->type_obj() instanceof EE_PMT_Base) { |
|
| 2213 | + if ( ! $payment_method->type_obj() instanceof EE_PMT_Base) { |
|
| 2214 | 2214 | // not a payment |
| 2215 | 2215 | EE_Error::add_error( |
| 2216 | 2216 | sprintf( |
@@ -2248,7 +2248,7 @@ discard block |
||
| 2248 | 2248 | $payment = null; |
| 2249 | 2249 | $this->checkout->transaction->save(); |
| 2250 | 2250 | $payment_processor = EE_Registry::instance()->load_core('Payment_Processor'); |
| 2251 | - if (! $payment_processor instanceof EE_Payment_Processor) { |
|
| 2251 | + if ( ! $payment_processor instanceof EE_Payment_Processor) { |
|
| 2252 | 2252 | return false; |
| 2253 | 2253 | } |
| 2254 | 2254 | try { |
@@ -2352,7 +2352,7 @@ discard block |
||
| 2352 | 2352 | return true; |
| 2353 | 2353 | } |
| 2354 | 2354 | // verify payment object |
| 2355 | - if (! $payment instanceof EE_Payment) { |
|
| 2355 | + if ( ! $payment instanceof EE_Payment) { |
|
| 2356 | 2356 | // not a payment |
| 2357 | 2357 | EE_Error::add_error( |
| 2358 | 2358 | sprintf( |
@@ -2392,7 +2392,7 @@ discard block |
||
| 2392 | 2392 | return true; |
| 2393 | 2393 | // On-Site payment? |
| 2394 | 2394 | } elseif ($this->checkout->payment_method->is_on_site()) { |
| 2395 | - if (! $this->_process_payment_status($payment, EE_PMT_Base::onsite)) { |
|
| 2395 | + if ( ! $this->_process_payment_status($payment, EE_PMT_Base::onsite)) { |
|
| 2396 | 2396 | // $this->_setup_redirect_for_next_step(); |
| 2397 | 2397 | $this->checkout->continue_reg = false; |
| 2398 | 2398 | } |
@@ -2508,7 +2508,7 @@ discard block |
||
| 2508 | 2508 | break; |
| 2509 | 2509 | // bad payment |
| 2510 | 2510 | case EEM_Payment::status_id_failed: |
| 2511 | - if (! empty($msg)) { |
|
| 2511 | + if ( ! empty($msg)) { |
|
| 2512 | 2512 | EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
| 2513 | 2513 | return false; |
| 2514 | 2514 | } |
@@ -2569,11 +2569,11 @@ discard block |
||
| 2569 | 2569 | // how have they chosen to pay? |
| 2570 | 2570 | $this->checkout->selected_method_of_payment = $this->_get_selected_method_of_payment(true); |
| 2571 | 2571 | // get EE_Payment_Method object |
| 2572 | - if (! $this->checkout->payment_method = $this->_get_payment_method_for_selected_method_of_payment()) { |
|
| 2572 | + if ( ! $this->checkout->payment_method = $this->_get_payment_method_for_selected_method_of_payment()) { |
|
| 2573 | 2573 | $this->checkout->continue_reg = false; |
| 2574 | 2574 | return false; |
| 2575 | 2575 | } |
| 2576 | - if (! $this->checkout->payment_method->is_off_site()) { |
|
| 2576 | + if ( ! $this->checkout->payment_method->is_off_site()) { |
|
| 2577 | 2577 | return false; |
| 2578 | 2578 | } |
| 2579 | 2579 | $this->_validate_offsite_return(); |
@@ -2591,7 +2591,7 @@ discard block |
||
| 2591 | 2591 | // verify TXN |
| 2592 | 2592 | if ($this->checkout->transaction instanceof EE_Transaction) { |
| 2593 | 2593 | $gateway = $this->checkout->payment_method->type_obj()->get_gateway(); |
| 2594 | - if (! $gateway instanceof EE_Offsite_Gateway) { |
|
| 2594 | + if ( ! $gateway instanceof EE_Offsite_Gateway) { |
|
| 2595 | 2595 | $this->checkout->continue_reg = false; |
| 2596 | 2596 | return false; |
| 2597 | 2597 | } |
@@ -2708,13 +2708,13 @@ discard block |
||
| 2708 | 2708 | */ |
| 2709 | 2709 | private function _redirect_wayward_request(EE_Registration $primary_registrant) |
| 2710 | 2710 | { |
| 2711 | - if (! $primary_registrant instanceof EE_Registration) { |
|
| 2711 | + if ( ! $primary_registrant instanceof EE_Registration) { |
|
| 2712 | 2712 | // try redirecting based on the current TXN |
| 2713 | 2713 | $primary_registrant = $this->checkout->transaction instanceof EE_Transaction |
| 2714 | 2714 | ? $this->checkout->transaction->primary_registration() |
| 2715 | 2715 | : null; |
| 2716 | 2716 | } |
| 2717 | - if (! $primary_registrant instanceof EE_Registration) { |
|
| 2717 | + if ( ! $primary_registrant instanceof EE_Registration) { |
|
| 2718 | 2718 | EE_Error::add_error( |
| 2719 | 2719 | sprintf( |
| 2720 | 2720 | esc_html__( |
@@ -2784,7 +2784,7 @@ discard block |
||
| 2784 | 2784 | $payment = $this->checkout->transaction->last_payment(); |
| 2785 | 2785 | // $payment_source = 'last_payment after Exception'; |
| 2786 | 2786 | // but if we STILL don't have a payment object |
| 2787 | - if (! $payment instanceof EE_Payment) { |
|
| 2787 | + if ( ! $payment instanceof EE_Payment) { |
|
| 2788 | 2788 | // then we'll object ! ( not object like a thing... but object like what a lawyer says ! ) |
| 2789 | 2789 | $this->_handle_payment_processor_exception($e); |
| 2790 | 2790 | } |
@@ -14,472 +14,472 @@ discard block |
||
| 14 | 14 | class EED_Event_Single extends EED_Module |
| 15 | 15 | { |
| 16 | 16 | |
| 17 | - const EVENT_DETAILS_PRIORITY = 100; |
|
| 18 | - const EVENT_DATETIMES_PRIORITY = 110; |
|
| 19 | - const EVENT_TICKETS_PRIORITY = 120; |
|
| 20 | - const EVENT_VENUES_PRIORITY = 130; |
|
| 21 | - |
|
| 22 | - /** |
|
| 23 | - * @type bool $using_get_the_excerpt |
|
| 24 | - */ |
|
| 25 | - protected static $using_get_the_excerpt = false; |
|
| 26 | - |
|
| 27 | - |
|
| 28 | - /** |
|
| 29 | - * @type EE_Template_Part_Manager $template_parts |
|
| 30 | - */ |
|
| 31 | - protected $template_parts; |
|
| 32 | - |
|
| 33 | - |
|
| 34 | - /** |
|
| 35 | - * @return EED_Module|EED_Event_Single |
|
| 36 | - */ |
|
| 37 | - public static function instance() |
|
| 38 | - { |
|
| 39 | - return parent::get_instance(__CLASS__); |
|
| 40 | - } |
|
| 41 | - |
|
| 42 | - |
|
| 43 | - /** |
|
| 44 | - * set_hooks - for hooking into EE Core, other modules, etc |
|
| 45 | - * |
|
| 46 | - * @return void |
|
| 47 | - * @throws InvalidArgumentException |
|
| 48 | - * @throws InvalidDataTypeException |
|
| 49 | - * @throws InvalidInterfaceException |
|
| 50 | - */ |
|
| 51 | - public static function set_hooks() |
|
| 52 | - { |
|
| 53 | - add_filter('FHEE_run_EE_wp', '__return_true'); |
|
| 54 | - add_action('wp_loaded', array('EED_Event_Single', 'set_definitions'), 2); |
|
| 55 | - /** @var EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions $custom_post_type_definitions */ |
|
| 56 | - $custom_post_type_definitions = LoaderFactory::getLoader()->getShared( |
|
| 57 | - 'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' |
|
| 58 | - ); |
|
| 59 | - $custom_post_types = $custom_post_type_definitions->getDefinitions(); |
|
| 60 | - EE_Config::register_route( |
|
| 61 | - $custom_post_types['espresso_events']['singular_slug'], |
|
| 62 | - 'Event_Single', |
|
| 63 | - 'run' |
|
| 64 | - ); |
|
| 65 | - } |
|
| 66 | - |
|
| 67 | - /** |
|
| 68 | - * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
| 69 | - * |
|
| 70 | - * @return void |
|
| 71 | - */ |
|
| 72 | - public static function set_hooks_admin() |
|
| 73 | - { |
|
| 74 | - add_action('wp_loaded', array('EED_Event_Single', 'set_definitions'), 2); |
|
| 75 | - } |
|
| 76 | - |
|
| 77 | - |
|
| 78 | - /** |
|
| 79 | - * set_definitions |
|
| 80 | - * |
|
| 81 | - * @static |
|
| 82 | - * @return void |
|
| 83 | - */ |
|
| 84 | - public static function set_definitions() |
|
| 85 | - { |
|
| 86 | - define('EVENT_SINGLE_ASSETS_URL', plugin_dir_url(__FILE__) . 'assets/'); |
|
| 87 | - define('EVENT_SINGLE_TEMPLATES_PATH', plugin_dir_path(__FILE__) . 'templates/'); |
|
| 88 | - } |
|
| 89 | - |
|
| 90 | - |
|
| 91 | - /** |
|
| 92 | - * set_config |
|
| 93 | - * |
|
| 94 | - * @void |
|
| 95 | - */ |
|
| 96 | - protected function set_config() |
|
| 97 | - { |
|
| 98 | - $this->set_config_section('template_settings'); |
|
| 99 | - $this->set_config_class('EE_Event_Single_Config'); |
|
| 100 | - $this->set_config_name('EED_Event_Single'); |
|
| 101 | - } |
|
| 102 | - |
|
| 103 | - |
|
| 104 | - /** |
|
| 105 | - * initialize_template_parts |
|
| 106 | - * |
|
| 107 | - * @param EE_Config_Base|EE_Event_Single_Config $config |
|
| 108 | - * @return EE_Template_Part_Manager |
|
| 109 | - */ |
|
| 110 | - public function initialize_template_parts(EE_Event_Single_Config $config = null) |
|
| 111 | - { |
|
| 112 | - /** @type EE_Event_Single_Config $config */ |
|
| 113 | - $config = $config instanceof EE_Event_Single_Config ? $config : $this->config(); |
|
| 114 | - EEH_Autoloader::instance()->register_template_part_autoloaders(); |
|
| 115 | - $template_parts = new EE_Template_Part_Manager(); |
|
| 116 | - $template_parts->add_template_part( |
|
| 117 | - 'tickets', |
|
| 118 | - __('Ticket Selector', 'event_espresso'), |
|
| 119 | - 'content-espresso_events-tickets.php', |
|
| 120 | - $config->display_order_tickets |
|
| 121 | - ); |
|
| 122 | - $template_parts->add_template_part( |
|
| 123 | - 'datetimes', |
|
| 124 | - __('Dates and Times', 'event_espresso'), |
|
| 125 | - 'content-espresso_events-datetimes.php', |
|
| 126 | - $config->display_order_datetimes |
|
| 127 | - ); |
|
| 128 | - $template_parts->add_template_part( |
|
| 129 | - 'event', |
|
| 130 | - __('Event Description', 'event_espresso'), |
|
| 131 | - 'content-espresso_events-details.php', |
|
| 132 | - $config->display_order_event |
|
| 133 | - ); |
|
| 134 | - $template_parts->add_template_part( |
|
| 135 | - 'venue', |
|
| 136 | - __('Venue Information', 'event_espresso'), |
|
| 137 | - 'content-espresso_events-venues.php', |
|
| 138 | - $config->display_order_venue |
|
| 139 | - ); |
|
| 140 | - do_action('AHEE__EED_Event_Single__initialize_template_parts', $template_parts); |
|
| 141 | - return $template_parts; |
|
| 142 | - } |
|
| 143 | - |
|
| 144 | - |
|
| 145 | - /** |
|
| 146 | - * run - initial module setup |
|
| 147 | - * |
|
| 148 | - * @param WP $WP |
|
| 149 | - * @return void |
|
| 150 | - */ |
|
| 151 | - public function run($WP) |
|
| 152 | - { |
|
| 153 | - // ensure valid EE_Events_Single_Config() object exists |
|
| 154 | - $this->set_config(); |
|
| 155 | - // check what template is loaded |
|
| 156 | - add_filter('template_include', array($this, 'template_include'), 999, 1); |
|
| 157 | - add_filter('FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', '__return_true'); |
|
| 158 | - // load css |
|
| 159 | - add_action('wp_enqueue_scripts', array($this, 'wp_enqueue_scripts'), 10); |
|
| 160 | - } |
|
| 161 | - |
|
| 162 | - |
|
| 163 | - /** |
|
| 164 | - * template_include |
|
| 165 | - * |
|
| 166 | - * @param string $template |
|
| 167 | - * @return string |
|
| 168 | - */ |
|
| 169 | - public function template_include($template) |
|
| 170 | - { |
|
| 171 | - global $post; |
|
| 172 | - /** @type EE_Event_Single_Config $config */ |
|
| 173 | - $config = $this->config(); |
|
| 174 | - if ($config->display_status_banner_single) { |
|
| 175 | - add_filter('the_title', array('EED_Event_Single', 'the_title'), 100, 2); |
|
| 176 | - } |
|
| 177 | - // not a custom template? |
|
| 178 | - if (! post_password_required($post) |
|
| 179 | - && ( |
|
| 180 | - apply_filters('FHEE__EED_Event_Single__template_include__allow_custom_selected_template', false) |
|
| 181 | - || EE_Registry::instance() |
|
| 182 | - ->load_core('Front_Controller') |
|
| 183 | - ->get_selected_template() !== 'single-espresso_events.php' |
|
| 184 | - ) |
|
| 185 | - |
|
| 186 | - ) { |
|
| 187 | - EEH_Template::load_espresso_theme_functions(); |
|
| 188 | - // then add extra event data via hooks |
|
| 189 | - add_action('loop_start', array('EED_Event_Single', 'loop_start')); |
|
| 190 | - add_filter('get_the_excerpt', array('EED_Event_Single', 'get_the_excerpt'), 1, 1); |
|
| 191 | - add_filter( |
|
| 192 | - 'the_content', |
|
| 193 | - array('EED_Event_Single', 'event_details'), |
|
| 194 | - EED_Event_Single::EVENT_DETAILS_PRIORITY |
|
| 195 | - ); |
|
| 196 | - add_action('loop_end', array('EED_Event_Single', 'loop_end')); |
|
| 197 | - // don't display entry meta because the existing theme will take car of that |
|
| 198 | - add_filter('FHEE__content_espresso_events_details_template__display_entry_meta', '__return_false'); |
|
| 199 | - } |
|
| 200 | - return $template; |
|
| 201 | - } |
|
| 202 | - |
|
| 203 | - |
|
| 204 | - /** |
|
| 205 | - * loop_start |
|
| 206 | - * |
|
| 207 | - * @param array $wp_query_array an array containing the WP_Query object |
|
| 208 | - * @return void |
|
| 209 | - */ |
|
| 210 | - public static function loop_start($wp_query_array) |
|
| 211 | - { |
|
| 212 | - global $post; |
|
| 213 | - do_action('AHEE_event_details_before_post', $post, $wp_query_array); |
|
| 214 | - } |
|
| 215 | - |
|
| 216 | - |
|
| 217 | - /** |
|
| 218 | - * the_title |
|
| 219 | - * |
|
| 220 | - * @param string $title |
|
| 221 | - * @param int $id |
|
| 222 | - * @return string |
|
| 223 | - */ |
|
| 224 | - public static function the_title($title = '', $id = 0) |
|
| 225 | - { |
|
| 226 | - global $post; |
|
| 227 | - return in_the_loop() && $post->ID === (int) $id |
|
| 228 | - ? espresso_event_status_banner($post->ID) . $title |
|
| 229 | - : $title; |
|
| 230 | - } |
|
| 231 | - |
|
| 232 | - |
|
| 233 | - /** |
|
| 234 | - * get_the_excerpt |
|
| 235 | - * kinda hacky, but if a theme is using get_the_excerpt(), |
|
| 236 | - * then we need to remove our filters on the_content() |
|
| 237 | - * |
|
| 238 | - * @param string $excerpt |
|
| 239 | - * @return string |
|
| 240 | - */ |
|
| 241 | - public static function get_the_excerpt($excerpt = '') |
|
| 242 | - { |
|
| 243 | - EED_Event_Single::$using_get_the_excerpt = true; |
|
| 244 | - add_filter('wp_trim_excerpt', array('EED_Event_Single', 'end_get_the_excerpt'), 999, 1); |
|
| 245 | - return $excerpt; |
|
| 246 | - } |
|
| 247 | - |
|
| 248 | - |
|
| 249 | - /** |
|
| 250 | - * end_get_the_excerpt |
|
| 251 | - * |
|
| 252 | - * @param string $text |
|
| 253 | - * @return string |
|
| 254 | - */ |
|
| 255 | - public static function end_get_the_excerpt($text = '') |
|
| 256 | - { |
|
| 257 | - EED_Event_Single::$using_get_the_excerpt = false; |
|
| 258 | - return $text; |
|
| 259 | - } |
|
| 260 | - |
|
| 261 | - |
|
| 262 | - /** |
|
| 263 | - * event_details |
|
| 264 | - * |
|
| 265 | - * @param string $content |
|
| 266 | - * @return string |
|
| 267 | - */ |
|
| 268 | - public static function event_details($content) |
|
| 269 | - { |
|
| 270 | - global $post; |
|
| 271 | - static $current_post_ID = 0; |
|
| 272 | - if ($current_post_ID !== $post->ID |
|
| 273 | - && $post->post_type === 'espresso_events' |
|
| 274 | - && ! EED_Event_Single::$using_get_the_excerpt |
|
| 275 | - && ! post_password_required() |
|
| 276 | - ) { |
|
| 277 | - // Set current post ID to prevent showing content twice, but only if headers have definitely been sent. |
|
| 278 | - // Reason being is that some plugins, like Yoast, need to run through a copy of the loop early |
|
| 279 | - // BEFORE headers are sent in order to examine the post content and generate content for the HTML header. |
|
| 280 | - // We want to allow those plugins to still do their thing and have access to our content, but depending on |
|
| 281 | - // how your event content is being displayed (shortcode, CPT route, etc), this filter can get applied twice, |
|
| 282 | - // so the following allows this filter to be applied multiple times, but only once for real |
|
| 283 | - $current_post_ID = did_action('loop_start') ? $post->ID : 0; |
|
| 284 | - if (EE_Registry::instance()->CFG->template_settings->EED_Event_Single->use_sortable_display_order) { |
|
| 285 | - // we need to first remove this callback from being applied to the_content() |
|
| 286 | - // (otherwise it will recurse and blow up the interweb) |
|
| 287 | - remove_filter( |
|
| 288 | - 'the_content', |
|
| 289 | - array('EED_Event_Single', 'event_details'), |
|
| 290 | - EED_Event_Single::EVENT_DETAILS_PRIORITY |
|
| 291 | - ); |
|
| 292 | - EED_Event_Single::instance()->template_parts = EED_Event_Single::instance()->initialize_template_parts( |
|
| 293 | - ); |
|
| 294 | - $content = EEH_Template::locate_template('content-espresso_events-details.php'); |
|
| 295 | - $content = EED_Event_Single::instance()->template_parts->apply_template_part_filters($content); |
|
| 296 | - add_filter( |
|
| 297 | - 'the_content', |
|
| 298 | - array('EED_Event_Single', 'event_details'), |
|
| 299 | - EED_Event_Single::EVENT_DETAILS_PRIORITY |
|
| 300 | - ); |
|
| 301 | - } else { |
|
| 302 | - $content = EED_Event_Single::use_filterable_display_order(); |
|
| 303 | - } |
|
| 304 | - } |
|
| 305 | - return $content; |
|
| 306 | - } |
|
| 307 | - |
|
| 308 | - |
|
| 309 | - /** |
|
| 310 | - * use_filterable_display_order |
|
| 311 | - * |
|
| 312 | - * @return string |
|
| 313 | - */ |
|
| 314 | - protected static function use_filterable_display_order() |
|
| 315 | - { |
|
| 316 | - // since the 'content-espresso_events-details.php' template might be used directly from within a theme, |
|
| 317 | - // it uses the_content() for displaying the $post->post_content |
|
| 318 | - // so in order to load a template that uses the_content() |
|
| 319 | - // from within a callback being used to filter the_content(), |
|
| 320 | - // we need to first remove this callback from being applied to the_content() |
|
| 321 | - // (otherwise it will recurse and blow up the interweb) |
|
| 322 | - remove_filter( |
|
| 323 | - 'the_content', |
|
| 324 | - array('EED_Event_Single', 'event_details'), |
|
| 325 | - EED_Event_Single::EVENT_DETAILS_PRIORITY |
|
| 326 | - ); |
|
| 327 | - // now add additional content |
|
| 328 | - add_filter( |
|
| 329 | - 'the_content', |
|
| 330 | - array('EED_Event_Single', 'event_datetimes'), |
|
| 331 | - EED_Event_Single::EVENT_DATETIMES_PRIORITY, |
|
| 332 | - 1 |
|
| 333 | - ); |
|
| 334 | - add_filter( |
|
| 335 | - 'the_content', |
|
| 336 | - array('EED_Event_Single', 'event_tickets'), |
|
| 337 | - EED_Event_Single::EVENT_TICKETS_PRIORITY, |
|
| 338 | - 1 |
|
| 339 | - ); |
|
| 340 | - add_filter( |
|
| 341 | - 'the_content', |
|
| 342 | - array('EED_Event_Single', 'event_venues'), |
|
| 343 | - EED_Event_Single::EVENT_VENUES_PRIORITY, |
|
| 344 | - 1 |
|
| 345 | - ); |
|
| 346 | - do_action('AHEE__EED_Event_Single__use_filterable_display_order__after_add_filters'); |
|
| 347 | - // now load our template |
|
| 348 | - $content = EEH_Template::locate_template('content-espresso_events-details.php'); |
|
| 349 | - // now add our filter back in, plus some others |
|
| 350 | - add_filter( |
|
| 351 | - 'the_content', |
|
| 352 | - array('EED_Event_Single', 'event_details'), |
|
| 353 | - EED_Event_Single::EVENT_DETAILS_PRIORITY |
|
| 354 | - ); |
|
| 355 | - remove_filter( |
|
| 356 | - 'the_content', |
|
| 357 | - array('EED_Event_Single', 'event_datetimes'), |
|
| 358 | - EED_Event_Single::EVENT_DATETIMES_PRIORITY |
|
| 359 | - ); |
|
| 360 | - remove_filter( |
|
| 361 | - 'the_content', |
|
| 362 | - array('EED_Event_Single', 'event_tickets'), |
|
| 363 | - EED_Event_Single::EVENT_TICKETS_PRIORITY |
|
| 364 | - ); |
|
| 365 | - remove_filter( |
|
| 366 | - 'the_content', |
|
| 367 | - array('EED_Event_Single', 'event_venues'), |
|
| 368 | - EED_Event_Single::EVENT_VENUES_PRIORITY |
|
| 369 | - ); |
|
| 370 | - do_action('AHEE__EED_Event_Single__use_filterable_display_order__after_remove_filters'); |
|
| 371 | - // we're not returning the $content directly because the template we are loading uses the_content (or the_excerpt) |
|
| 372 | - return $content; |
|
| 373 | - } |
|
| 374 | - |
|
| 375 | - |
|
| 376 | - /** |
|
| 377 | - * event_datetimes - adds datetimes ABOVE content |
|
| 378 | - * |
|
| 379 | - * @param string $content |
|
| 380 | - * @return string |
|
| 381 | - */ |
|
| 382 | - public static function event_datetimes($content) |
|
| 383 | - { |
|
| 384 | - return EEH_Template::locate_template('content-espresso_events-datetimes.php') . $content; |
|
| 385 | - } |
|
| 386 | - |
|
| 387 | - |
|
| 388 | - /** |
|
| 389 | - * event_tickets - adds tickets ABOVE content (which includes datetimes) |
|
| 390 | - * |
|
| 391 | - * @param string $content |
|
| 392 | - * @return string |
|
| 393 | - */ |
|
| 394 | - public static function event_tickets($content) |
|
| 395 | - { |
|
| 396 | - return EEH_Template::locate_template('content-espresso_events-tickets.php') . $content; |
|
| 397 | - } |
|
| 398 | - |
|
| 399 | - |
|
| 400 | - /** |
|
| 401 | - * event_venues |
|
| 402 | - * |
|
| 403 | - * @param string $content |
|
| 404 | - * @return string |
|
| 405 | - */ |
|
| 406 | - public static function event_venue($content) |
|
| 407 | - { |
|
| 408 | - return EED_Event_Single::event_venues($content); |
|
| 409 | - } |
|
| 410 | - |
|
| 411 | - |
|
| 412 | - /** |
|
| 413 | - * event_venues - adds venues BELOW content |
|
| 414 | - * |
|
| 415 | - * @param string $content |
|
| 416 | - * @return string |
|
| 417 | - */ |
|
| 418 | - public static function event_venues($content) |
|
| 419 | - { |
|
| 420 | - return $content . EEH_Template::locate_template('content-espresso_events-venues.php'); |
|
| 421 | - } |
|
| 422 | - |
|
| 423 | - |
|
| 424 | - /** |
|
| 425 | - * loop_end |
|
| 426 | - * |
|
| 427 | - * @param array $wp_query_array an array containing the WP_Query object |
|
| 428 | - * @return void |
|
| 429 | - */ |
|
| 430 | - public static function loop_end($wp_query_array) |
|
| 431 | - { |
|
| 432 | - global $post; |
|
| 433 | - do_action('AHEE_event_details_after_post', $post, $wp_query_array); |
|
| 434 | - } |
|
| 435 | - |
|
| 436 | - |
|
| 437 | - /** |
|
| 438 | - * wp_enqueue_scripts |
|
| 439 | - * |
|
| 440 | - * @return void |
|
| 441 | - */ |
|
| 442 | - public function wp_enqueue_scripts() |
|
| 443 | - { |
|
| 444 | - // get some style |
|
| 445 | - if (apply_filters('FHEE_enable_default_espresso_css', true) |
|
| 446 | - && apply_filters('FHEE__EED_Event_Single__wp_enqueue_scripts__enable_css', true) |
|
| 447 | - ) { |
|
| 448 | - // first check uploads folder |
|
| 449 | - if (is_readable(get_stylesheet_directory() . $this->theme . '/style.css')) { |
|
| 450 | - wp_register_style( |
|
| 451 | - $this->theme, |
|
| 452 | - get_stylesheet_directory_uri() . $this->theme . '/style.css', |
|
| 453 | - array('dashicons', 'espresso_default') |
|
| 454 | - ); |
|
| 455 | - } else { |
|
| 456 | - wp_register_style( |
|
| 457 | - $this->theme, |
|
| 458 | - EE_TEMPLATES_URL . $this->theme . '/style.css', |
|
| 459 | - array('dashicons', 'espresso_default') |
|
| 460 | - ); |
|
| 461 | - } |
|
| 462 | - wp_enqueue_script($this->theme); |
|
| 463 | - if (EE_Registry::instance()->CFG->map_settings->use_google_maps) { |
|
| 464 | - add_action('wp_enqueue_scripts', array('EEH_Maps', 'espresso_google_map_js'), 11); |
|
| 465 | - } |
|
| 466 | - } |
|
| 467 | - } |
|
| 468 | - |
|
| 469 | - |
|
| 470 | - /** |
|
| 471 | - * display_venue |
|
| 472 | - * |
|
| 473 | - * @return bool |
|
| 474 | - */ |
|
| 475 | - public static function display_venue() |
|
| 476 | - { |
|
| 477 | - /** @type EE_Event_Single_Config $config */ |
|
| 478 | - $config = EED_Event_Single::instance()->config(); |
|
| 479 | - $display_venue = $config->display_venue === null ? true : $config->display_venue; |
|
| 480 | - $venue_name = EEH_Venue_View::venue_name(); |
|
| 481 | - return $display_venue && ! empty($venue_name); |
|
| 482 | - } |
|
| 17 | + const EVENT_DETAILS_PRIORITY = 100; |
|
| 18 | + const EVENT_DATETIMES_PRIORITY = 110; |
|
| 19 | + const EVENT_TICKETS_PRIORITY = 120; |
|
| 20 | + const EVENT_VENUES_PRIORITY = 130; |
|
| 21 | + |
|
| 22 | + /** |
|
| 23 | + * @type bool $using_get_the_excerpt |
|
| 24 | + */ |
|
| 25 | + protected static $using_get_the_excerpt = false; |
|
| 26 | + |
|
| 27 | + |
|
| 28 | + /** |
|
| 29 | + * @type EE_Template_Part_Manager $template_parts |
|
| 30 | + */ |
|
| 31 | + protected $template_parts; |
|
| 32 | + |
|
| 33 | + |
|
| 34 | + /** |
|
| 35 | + * @return EED_Module|EED_Event_Single |
|
| 36 | + */ |
|
| 37 | + public static function instance() |
|
| 38 | + { |
|
| 39 | + return parent::get_instance(__CLASS__); |
|
| 40 | + } |
|
| 41 | + |
|
| 42 | + |
|
| 43 | + /** |
|
| 44 | + * set_hooks - for hooking into EE Core, other modules, etc |
|
| 45 | + * |
|
| 46 | + * @return void |
|
| 47 | + * @throws InvalidArgumentException |
|
| 48 | + * @throws InvalidDataTypeException |
|
| 49 | + * @throws InvalidInterfaceException |
|
| 50 | + */ |
|
| 51 | + public static function set_hooks() |
|
| 52 | + { |
|
| 53 | + add_filter('FHEE_run_EE_wp', '__return_true'); |
|
| 54 | + add_action('wp_loaded', array('EED_Event_Single', 'set_definitions'), 2); |
|
| 55 | + /** @var EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions $custom_post_type_definitions */ |
|
| 56 | + $custom_post_type_definitions = LoaderFactory::getLoader()->getShared( |
|
| 57 | + 'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' |
|
| 58 | + ); |
|
| 59 | + $custom_post_types = $custom_post_type_definitions->getDefinitions(); |
|
| 60 | + EE_Config::register_route( |
|
| 61 | + $custom_post_types['espresso_events']['singular_slug'], |
|
| 62 | + 'Event_Single', |
|
| 63 | + 'run' |
|
| 64 | + ); |
|
| 65 | + } |
|
| 66 | + |
|
| 67 | + /** |
|
| 68 | + * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
| 69 | + * |
|
| 70 | + * @return void |
|
| 71 | + */ |
|
| 72 | + public static function set_hooks_admin() |
|
| 73 | + { |
|
| 74 | + add_action('wp_loaded', array('EED_Event_Single', 'set_definitions'), 2); |
|
| 75 | + } |
|
| 76 | + |
|
| 77 | + |
|
| 78 | + /** |
|
| 79 | + * set_definitions |
|
| 80 | + * |
|
| 81 | + * @static |
|
| 82 | + * @return void |
|
| 83 | + */ |
|
| 84 | + public static function set_definitions() |
|
| 85 | + { |
|
| 86 | + define('EVENT_SINGLE_ASSETS_URL', plugin_dir_url(__FILE__) . 'assets/'); |
|
| 87 | + define('EVENT_SINGLE_TEMPLATES_PATH', plugin_dir_path(__FILE__) . 'templates/'); |
|
| 88 | + } |
|
| 89 | + |
|
| 90 | + |
|
| 91 | + /** |
|
| 92 | + * set_config |
|
| 93 | + * |
|
| 94 | + * @void |
|
| 95 | + */ |
|
| 96 | + protected function set_config() |
|
| 97 | + { |
|
| 98 | + $this->set_config_section('template_settings'); |
|
| 99 | + $this->set_config_class('EE_Event_Single_Config'); |
|
| 100 | + $this->set_config_name('EED_Event_Single'); |
|
| 101 | + } |
|
| 102 | + |
|
| 103 | + |
|
| 104 | + /** |
|
| 105 | + * initialize_template_parts |
|
| 106 | + * |
|
| 107 | + * @param EE_Config_Base|EE_Event_Single_Config $config |
|
| 108 | + * @return EE_Template_Part_Manager |
|
| 109 | + */ |
|
| 110 | + public function initialize_template_parts(EE_Event_Single_Config $config = null) |
|
| 111 | + { |
|
| 112 | + /** @type EE_Event_Single_Config $config */ |
|
| 113 | + $config = $config instanceof EE_Event_Single_Config ? $config : $this->config(); |
|
| 114 | + EEH_Autoloader::instance()->register_template_part_autoloaders(); |
|
| 115 | + $template_parts = new EE_Template_Part_Manager(); |
|
| 116 | + $template_parts->add_template_part( |
|
| 117 | + 'tickets', |
|
| 118 | + __('Ticket Selector', 'event_espresso'), |
|
| 119 | + 'content-espresso_events-tickets.php', |
|
| 120 | + $config->display_order_tickets |
|
| 121 | + ); |
|
| 122 | + $template_parts->add_template_part( |
|
| 123 | + 'datetimes', |
|
| 124 | + __('Dates and Times', 'event_espresso'), |
|
| 125 | + 'content-espresso_events-datetimes.php', |
|
| 126 | + $config->display_order_datetimes |
|
| 127 | + ); |
|
| 128 | + $template_parts->add_template_part( |
|
| 129 | + 'event', |
|
| 130 | + __('Event Description', 'event_espresso'), |
|
| 131 | + 'content-espresso_events-details.php', |
|
| 132 | + $config->display_order_event |
|
| 133 | + ); |
|
| 134 | + $template_parts->add_template_part( |
|
| 135 | + 'venue', |
|
| 136 | + __('Venue Information', 'event_espresso'), |
|
| 137 | + 'content-espresso_events-venues.php', |
|
| 138 | + $config->display_order_venue |
|
| 139 | + ); |
|
| 140 | + do_action('AHEE__EED_Event_Single__initialize_template_parts', $template_parts); |
|
| 141 | + return $template_parts; |
|
| 142 | + } |
|
| 143 | + |
|
| 144 | + |
|
| 145 | + /** |
|
| 146 | + * run - initial module setup |
|
| 147 | + * |
|
| 148 | + * @param WP $WP |
|
| 149 | + * @return void |
|
| 150 | + */ |
|
| 151 | + public function run($WP) |
|
| 152 | + { |
|
| 153 | + // ensure valid EE_Events_Single_Config() object exists |
|
| 154 | + $this->set_config(); |
|
| 155 | + // check what template is loaded |
|
| 156 | + add_filter('template_include', array($this, 'template_include'), 999, 1); |
|
| 157 | + add_filter('FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', '__return_true'); |
|
| 158 | + // load css |
|
| 159 | + add_action('wp_enqueue_scripts', array($this, 'wp_enqueue_scripts'), 10); |
|
| 160 | + } |
|
| 161 | + |
|
| 162 | + |
|
| 163 | + /** |
|
| 164 | + * template_include |
|
| 165 | + * |
|
| 166 | + * @param string $template |
|
| 167 | + * @return string |
|
| 168 | + */ |
|
| 169 | + public function template_include($template) |
|
| 170 | + { |
|
| 171 | + global $post; |
|
| 172 | + /** @type EE_Event_Single_Config $config */ |
|
| 173 | + $config = $this->config(); |
|
| 174 | + if ($config->display_status_banner_single) { |
|
| 175 | + add_filter('the_title', array('EED_Event_Single', 'the_title'), 100, 2); |
|
| 176 | + } |
|
| 177 | + // not a custom template? |
|
| 178 | + if (! post_password_required($post) |
|
| 179 | + && ( |
|
| 180 | + apply_filters('FHEE__EED_Event_Single__template_include__allow_custom_selected_template', false) |
|
| 181 | + || EE_Registry::instance() |
|
| 182 | + ->load_core('Front_Controller') |
|
| 183 | + ->get_selected_template() !== 'single-espresso_events.php' |
|
| 184 | + ) |
|
| 185 | + |
|
| 186 | + ) { |
|
| 187 | + EEH_Template::load_espresso_theme_functions(); |
|
| 188 | + // then add extra event data via hooks |
|
| 189 | + add_action('loop_start', array('EED_Event_Single', 'loop_start')); |
|
| 190 | + add_filter('get_the_excerpt', array('EED_Event_Single', 'get_the_excerpt'), 1, 1); |
|
| 191 | + add_filter( |
|
| 192 | + 'the_content', |
|
| 193 | + array('EED_Event_Single', 'event_details'), |
|
| 194 | + EED_Event_Single::EVENT_DETAILS_PRIORITY |
|
| 195 | + ); |
|
| 196 | + add_action('loop_end', array('EED_Event_Single', 'loop_end')); |
|
| 197 | + // don't display entry meta because the existing theme will take car of that |
|
| 198 | + add_filter('FHEE__content_espresso_events_details_template__display_entry_meta', '__return_false'); |
|
| 199 | + } |
|
| 200 | + return $template; |
|
| 201 | + } |
|
| 202 | + |
|
| 203 | + |
|
| 204 | + /** |
|
| 205 | + * loop_start |
|
| 206 | + * |
|
| 207 | + * @param array $wp_query_array an array containing the WP_Query object |
|
| 208 | + * @return void |
|
| 209 | + */ |
|
| 210 | + public static function loop_start($wp_query_array) |
|
| 211 | + { |
|
| 212 | + global $post; |
|
| 213 | + do_action('AHEE_event_details_before_post', $post, $wp_query_array); |
|
| 214 | + } |
|
| 215 | + |
|
| 216 | + |
|
| 217 | + /** |
|
| 218 | + * the_title |
|
| 219 | + * |
|
| 220 | + * @param string $title |
|
| 221 | + * @param int $id |
|
| 222 | + * @return string |
|
| 223 | + */ |
|
| 224 | + public static function the_title($title = '', $id = 0) |
|
| 225 | + { |
|
| 226 | + global $post; |
|
| 227 | + return in_the_loop() && $post->ID === (int) $id |
|
| 228 | + ? espresso_event_status_banner($post->ID) . $title |
|
| 229 | + : $title; |
|
| 230 | + } |
|
| 231 | + |
|
| 232 | + |
|
| 233 | + /** |
|
| 234 | + * get_the_excerpt |
|
| 235 | + * kinda hacky, but if a theme is using get_the_excerpt(), |
|
| 236 | + * then we need to remove our filters on the_content() |
|
| 237 | + * |
|
| 238 | + * @param string $excerpt |
|
| 239 | + * @return string |
|
| 240 | + */ |
|
| 241 | + public static function get_the_excerpt($excerpt = '') |
|
| 242 | + { |
|
| 243 | + EED_Event_Single::$using_get_the_excerpt = true; |
|
| 244 | + add_filter('wp_trim_excerpt', array('EED_Event_Single', 'end_get_the_excerpt'), 999, 1); |
|
| 245 | + return $excerpt; |
|
| 246 | + } |
|
| 247 | + |
|
| 248 | + |
|
| 249 | + /** |
|
| 250 | + * end_get_the_excerpt |
|
| 251 | + * |
|
| 252 | + * @param string $text |
|
| 253 | + * @return string |
|
| 254 | + */ |
|
| 255 | + public static function end_get_the_excerpt($text = '') |
|
| 256 | + { |
|
| 257 | + EED_Event_Single::$using_get_the_excerpt = false; |
|
| 258 | + return $text; |
|
| 259 | + } |
|
| 260 | + |
|
| 261 | + |
|
| 262 | + /** |
|
| 263 | + * event_details |
|
| 264 | + * |
|
| 265 | + * @param string $content |
|
| 266 | + * @return string |
|
| 267 | + */ |
|
| 268 | + public static function event_details($content) |
|
| 269 | + { |
|
| 270 | + global $post; |
|
| 271 | + static $current_post_ID = 0; |
|
| 272 | + if ($current_post_ID !== $post->ID |
|
| 273 | + && $post->post_type === 'espresso_events' |
|
| 274 | + && ! EED_Event_Single::$using_get_the_excerpt |
|
| 275 | + && ! post_password_required() |
|
| 276 | + ) { |
|
| 277 | + // Set current post ID to prevent showing content twice, but only if headers have definitely been sent. |
|
| 278 | + // Reason being is that some plugins, like Yoast, need to run through a copy of the loop early |
|
| 279 | + // BEFORE headers are sent in order to examine the post content and generate content for the HTML header. |
|
| 280 | + // We want to allow those plugins to still do their thing and have access to our content, but depending on |
|
| 281 | + // how your event content is being displayed (shortcode, CPT route, etc), this filter can get applied twice, |
|
| 282 | + // so the following allows this filter to be applied multiple times, but only once for real |
|
| 283 | + $current_post_ID = did_action('loop_start') ? $post->ID : 0; |
|
| 284 | + if (EE_Registry::instance()->CFG->template_settings->EED_Event_Single->use_sortable_display_order) { |
|
| 285 | + // we need to first remove this callback from being applied to the_content() |
|
| 286 | + // (otherwise it will recurse and blow up the interweb) |
|
| 287 | + remove_filter( |
|
| 288 | + 'the_content', |
|
| 289 | + array('EED_Event_Single', 'event_details'), |
|
| 290 | + EED_Event_Single::EVENT_DETAILS_PRIORITY |
|
| 291 | + ); |
|
| 292 | + EED_Event_Single::instance()->template_parts = EED_Event_Single::instance()->initialize_template_parts( |
|
| 293 | + ); |
|
| 294 | + $content = EEH_Template::locate_template('content-espresso_events-details.php'); |
|
| 295 | + $content = EED_Event_Single::instance()->template_parts->apply_template_part_filters($content); |
|
| 296 | + add_filter( |
|
| 297 | + 'the_content', |
|
| 298 | + array('EED_Event_Single', 'event_details'), |
|
| 299 | + EED_Event_Single::EVENT_DETAILS_PRIORITY |
|
| 300 | + ); |
|
| 301 | + } else { |
|
| 302 | + $content = EED_Event_Single::use_filterable_display_order(); |
|
| 303 | + } |
|
| 304 | + } |
|
| 305 | + return $content; |
|
| 306 | + } |
|
| 307 | + |
|
| 308 | + |
|
| 309 | + /** |
|
| 310 | + * use_filterable_display_order |
|
| 311 | + * |
|
| 312 | + * @return string |
|
| 313 | + */ |
|
| 314 | + protected static function use_filterable_display_order() |
|
| 315 | + { |
|
| 316 | + // since the 'content-espresso_events-details.php' template might be used directly from within a theme, |
|
| 317 | + // it uses the_content() for displaying the $post->post_content |
|
| 318 | + // so in order to load a template that uses the_content() |
|
| 319 | + // from within a callback being used to filter the_content(), |
|
| 320 | + // we need to first remove this callback from being applied to the_content() |
|
| 321 | + // (otherwise it will recurse and blow up the interweb) |
|
| 322 | + remove_filter( |
|
| 323 | + 'the_content', |
|
| 324 | + array('EED_Event_Single', 'event_details'), |
|
| 325 | + EED_Event_Single::EVENT_DETAILS_PRIORITY |
|
| 326 | + ); |
|
| 327 | + // now add additional content |
|
| 328 | + add_filter( |
|
| 329 | + 'the_content', |
|
| 330 | + array('EED_Event_Single', 'event_datetimes'), |
|
| 331 | + EED_Event_Single::EVENT_DATETIMES_PRIORITY, |
|
| 332 | + 1 |
|
| 333 | + ); |
|
| 334 | + add_filter( |
|
| 335 | + 'the_content', |
|
| 336 | + array('EED_Event_Single', 'event_tickets'), |
|
| 337 | + EED_Event_Single::EVENT_TICKETS_PRIORITY, |
|
| 338 | + 1 |
|
| 339 | + ); |
|
| 340 | + add_filter( |
|
| 341 | + 'the_content', |
|
| 342 | + array('EED_Event_Single', 'event_venues'), |
|
| 343 | + EED_Event_Single::EVENT_VENUES_PRIORITY, |
|
| 344 | + 1 |
|
| 345 | + ); |
|
| 346 | + do_action('AHEE__EED_Event_Single__use_filterable_display_order__after_add_filters'); |
|
| 347 | + // now load our template |
|
| 348 | + $content = EEH_Template::locate_template('content-espresso_events-details.php'); |
|
| 349 | + // now add our filter back in, plus some others |
|
| 350 | + add_filter( |
|
| 351 | + 'the_content', |
|
| 352 | + array('EED_Event_Single', 'event_details'), |
|
| 353 | + EED_Event_Single::EVENT_DETAILS_PRIORITY |
|
| 354 | + ); |
|
| 355 | + remove_filter( |
|
| 356 | + 'the_content', |
|
| 357 | + array('EED_Event_Single', 'event_datetimes'), |
|
| 358 | + EED_Event_Single::EVENT_DATETIMES_PRIORITY |
|
| 359 | + ); |
|
| 360 | + remove_filter( |
|
| 361 | + 'the_content', |
|
| 362 | + array('EED_Event_Single', 'event_tickets'), |
|
| 363 | + EED_Event_Single::EVENT_TICKETS_PRIORITY |
|
| 364 | + ); |
|
| 365 | + remove_filter( |
|
| 366 | + 'the_content', |
|
| 367 | + array('EED_Event_Single', 'event_venues'), |
|
| 368 | + EED_Event_Single::EVENT_VENUES_PRIORITY |
|
| 369 | + ); |
|
| 370 | + do_action('AHEE__EED_Event_Single__use_filterable_display_order__after_remove_filters'); |
|
| 371 | + // we're not returning the $content directly because the template we are loading uses the_content (or the_excerpt) |
|
| 372 | + return $content; |
|
| 373 | + } |
|
| 374 | + |
|
| 375 | + |
|
| 376 | + /** |
|
| 377 | + * event_datetimes - adds datetimes ABOVE content |
|
| 378 | + * |
|
| 379 | + * @param string $content |
|
| 380 | + * @return string |
|
| 381 | + */ |
|
| 382 | + public static function event_datetimes($content) |
|
| 383 | + { |
|
| 384 | + return EEH_Template::locate_template('content-espresso_events-datetimes.php') . $content; |
|
| 385 | + } |
|
| 386 | + |
|
| 387 | + |
|
| 388 | + /** |
|
| 389 | + * event_tickets - adds tickets ABOVE content (which includes datetimes) |
|
| 390 | + * |
|
| 391 | + * @param string $content |
|
| 392 | + * @return string |
|
| 393 | + */ |
|
| 394 | + public static function event_tickets($content) |
|
| 395 | + { |
|
| 396 | + return EEH_Template::locate_template('content-espresso_events-tickets.php') . $content; |
|
| 397 | + } |
|
| 398 | + |
|
| 399 | + |
|
| 400 | + /** |
|
| 401 | + * event_venues |
|
| 402 | + * |
|
| 403 | + * @param string $content |
|
| 404 | + * @return string |
|
| 405 | + */ |
|
| 406 | + public static function event_venue($content) |
|
| 407 | + { |
|
| 408 | + return EED_Event_Single::event_venues($content); |
|
| 409 | + } |
|
| 410 | + |
|
| 411 | + |
|
| 412 | + /** |
|
| 413 | + * event_venues - adds venues BELOW content |
|
| 414 | + * |
|
| 415 | + * @param string $content |
|
| 416 | + * @return string |
|
| 417 | + */ |
|
| 418 | + public static function event_venues($content) |
|
| 419 | + { |
|
| 420 | + return $content . EEH_Template::locate_template('content-espresso_events-venues.php'); |
|
| 421 | + } |
|
| 422 | + |
|
| 423 | + |
|
| 424 | + /** |
|
| 425 | + * loop_end |
|
| 426 | + * |
|
| 427 | + * @param array $wp_query_array an array containing the WP_Query object |
|
| 428 | + * @return void |
|
| 429 | + */ |
|
| 430 | + public static function loop_end($wp_query_array) |
|
| 431 | + { |
|
| 432 | + global $post; |
|
| 433 | + do_action('AHEE_event_details_after_post', $post, $wp_query_array); |
|
| 434 | + } |
|
| 435 | + |
|
| 436 | + |
|
| 437 | + /** |
|
| 438 | + * wp_enqueue_scripts |
|
| 439 | + * |
|
| 440 | + * @return void |
|
| 441 | + */ |
|
| 442 | + public function wp_enqueue_scripts() |
|
| 443 | + { |
|
| 444 | + // get some style |
|
| 445 | + if (apply_filters('FHEE_enable_default_espresso_css', true) |
|
| 446 | + && apply_filters('FHEE__EED_Event_Single__wp_enqueue_scripts__enable_css', true) |
|
| 447 | + ) { |
|
| 448 | + // first check uploads folder |
|
| 449 | + if (is_readable(get_stylesheet_directory() . $this->theme . '/style.css')) { |
|
| 450 | + wp_register_style( |
|
| 451 | + $this->theme, |
|
| 452 | + get_stylesheet_directory_uri() . $this->theme . '/style.css', |
|
| 453 | + array('dashicons', 'espresso_default') |
|
| 454 | + ); |
|
| 455 | + } else { |
|
| 456 | + wp_register_style( |
|
| 457 | + $this->theme, |
|
| 458 | + EE_TEMPLATES_URL . $this->theme . '/style.css', |
|
| 459 | + array('dashicons', 'espresso_default') |
|
| 460 | + ); |
|
| 461 | + } |
|
| 462 | + wp_enqueue_script($this->theme); |
|
| 463 | + if (EE_Registry::instance()->CFG->map_settings->use_google_maps) { |
|
| 464 | + add_action('wp_enqueue_scripts', array('EEH_Maps', 'espresso_google_map_js'), 11); |
|
| 465 | + } |
|
| 466 | + } |
|
| 467 | + } |
|
| 468 | + |
|
| 469 | + |
|
| 470 | + /** |
|
| 471 | + * display_venue |
|
| 472 | + * |
|
| 473 | + * @return bool |
|
| 474 | + */ |
|
| 475 | + public static function display_venue() |
|
| 476 | + { |
|
| 477 | + /** @type EE_Event_Single_Config $config */ |
|
| 478 | + $config = EED_Event_Single::instance()->config(); |
|
| 479 | + $display_venue = $config->display_venue === null ? true : $config->display_venue; |
|
| 480 | + $venue_name = EEH_Venue_View::venue_name(); |
|
| 481 | + return $display_venue && ! empty($venue_name); |
|
| 482 | + } |
|
| 483 | 483 | } |
| 484 | 484 | |
| 485 | 485 | |
@@ -491,5 +491,5 @@ discard block |
||
| 491 | 491 | */ |
| 492 | 492 | function espresso_display_venue_in_event_details() |
| 493 | 493 | { |
| 494 | - return EED_Event_Single::display_venue(); |
|
| 494 | + return EED_Event_Single::display_venue(); |
|
| 495 | 495 | } |
@@ -83,8 +83,8 @@ discard block |
||
| 83 | 83 | */ |
| 84 | 84 | public static function set_definitions() |
| 85 | 85 | { |
| 86 | - define('EVENT_SINGLE_ASSETS_URL', plugin_dir_url(__FILE__) . 'assets/'); |
|
| 87 | - define('EVENT_SINGLE_TEMPLATES_PATH', plugin_dir_path(__FILE__) . 'templates/'); |
|
| 86 | + define('EVENT_SINGLE_ASSETS_URL', plugin_dir_url(__FILE__).'assets/'); |
|
| 87 | + define('EVENT_SINGLE_TEMPLATES_PATH', plugin_dir_path(__FILE__).'templates/'); |
|
| 88 | 88 | } |
| 89 | 89 | |
| 90 | 90 | |
@@ -175,7 +175,7 @@ discard block |
||
| 175 | 175 | add_filter('the_title', array('EED_Event_Single', 'the_title'), 100, 2); |
| 176 | 176 | } |
| 177 | 177 | // not a custom template? |
| 178 | - if (! post_password_required($post) |
|
| 178 | + if ( ! post_password_required($post) |
|
| 179 | 179 | && ( |
| 180 | 180 | apply_filters('FHEE__EED_Event_Single__template_include__allow_custom_selected_template', false) |
| 181 | 181 | || EE_Registry::instance() |
@@ -225,7 +225,7 @@ discard block |
||
| 225 | 225 | { |
| 226 | 226 | global $post; |
| 227 | 227 | return in_the_loop() && $post->ID === (int) $id |
| 228 | - ? espresso_event_status_banner($post->ID) . $title |
|
| 228 | + ? espresso_event_status_banner($post->ID).$title |
|
| 229 | 229 | : $title; |
| 230 | 230 | } |
| 231 | 231 | |
@@ -381,7 +381,7 @@ discard block |
||
| 381 | 381 | */ |
| 382 | 382 | public static function event_datetimes($content) |
| 383 | 383 | { |
| 384 | - return EEH_Template::locate_template('content-espresso_events-datetimes.php') . $content; |
|
| 384 | + return EEH_Template::locate_template('content-espresso_events-datetimes.php').$content; |
|
| 385 | 385 | } |
| 386 | 386 | |
| 387 | 387 | |
@@ -393,7 +393,7 @@ discard block |
||
| 393 | 393 | */ |
| 394 | 394 | public static function event_tickets($content) |
| 395 | 395 | { |
| 396 | - return EEH_Template::locate_template('content-espresso_events-tickets.php') . $content; |
|
| 396 | + return EEH_Template::locate_template('content-espresso_events-tickets.php').$content; |
|
| 397 | 397 | } |
| 398 | 398 | |
| 399 | 399 | |
@@ -417,7 +417,7 @@ discard block |
||
| 417 | 417 | */ |
| 418 | 418 | public static function event_venues($content) |
| 419 | 419 | { |
| 420 | - return $content . EEH_Template::locate_template('content-espresso_events-venues.php'); |
|
| 420 | + return $content.EEH_Template::locate_template('content-espresso_events-venues.php'); |
|
| 421 | 421 | } |
| 422 | 422 | |
| 423 | 423 | |
@@ -446,16 +446,16 @@ discard block |
||
| 446 | 446 | && apply_filters('FHEE__EED_Event_Single__wp_enqueue_scripts__enable_css', true) |
| 447 | 447 | ) { |
| 448 | 448 | // first check uploads folder |
| 449 | - if (is_readable(get_stylesheet_directory() . $this->theme . '/style.css')) { |
|
| 449 | + if (is_readable(get_stylesheet_directory().$this->theme.'/style.css')) { |
|
| 450 | 450 | wp_register_style( |
| 451 | 451 | $this->theme, |
| 452 | - get_stylesheet_directory_uri() . $this->theme . '/style.css', |
|
| 452 | + get_stylesheet_directory_uri().$this->theme.'/style.css', |
|
| 453 | 453 | array('dashicons', 'espresso_default') |
| 454 | 454 | ); |
| 455 | 455 | } else { |
| 456 | 456 | wp_register_style( |
| 457 | 457 | $this->theme, |
| 458 | - EE_TEMPLATES_URL . $this->theme . '/style.css', |
|
| 458 | + EE_TEMPLATES_URL.$this->theme.'/style.css', |
|
| 459 | 459 | array('dashicons', 'espresso_default') |
| 460 | 460 | ); |
| 461 | 461 | } |
@@ -29,358 +29,358 @@ |
||
| 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 | - __('File Generation complete. Downloading, and %1$sredirecting%2$s...', 'event_espresso'), |
|
| 192 | - '<a href="' . $_REQUEST['return_url'] . '">', |
|
| 193 | - '</a>' |
|
| 194 | - ), |
|
| 195 | - 'return_url' => $_REQUEST['return_url'], |
|
| 196 | - ) |
|
| 197 | - ); |
|
| 198 | - } |
|
| 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 | + __('File Generation complete. Downloading, and %1$sredirecting%2$s...', 'event_espresso'), |
|
| 192 | + '<a href="' . $_REQUEST['return_url'] . '">', |
|
| 193 | + '</a>' |
|
| 194 | + ), |
|
| 195 | + 'return_url' => $_REQUEST['return_url'], |
|
| 196 | + ) |
|
| 197 | + ); |
|
| 198 | + } |
|
| 199 | 199 | |
| 200 | - /** |
|
| 201 | - * Enqueues scripts and styles common to any batch job, and creates |
|
| 202 | - * a job from the request data, and stores the response in the |
|
| 203 | - * $this->_job_step_response property |
|
| 204 | - * |
|
| 205 | - * @return \EventEspressoBatchRequest\Helpers\JobStepResponse |
|
| 206 | - */ |
|
| 207 | - protected function _enqueue_batch_job_scripts_and_styles_and_start_job() |
|
| 208 | - { |
|
| 209 | - // just copy the bits of EE admin's eei18n that we need in the JS |
|
| 210 | - EE_Registry::$i18n_js_strings['batchJobError'] = esc_html__( |
|
| 211 | - 'An error occurred and the job has been stopped. Please refresh the page to try again.', |
|
| 212 | - 'event_espresso' |
|
| 213 | - ); |
|
| 214 | - wp_register_script( |
|
| 215 | - 'progress_bar', |
|
| 216 | - EE_PLUGIN_DIR_URL . 'core/libraries/batch/Assets/progress_bar.js', |
|
| 217 | - array('jquery'), |
|
| 218 | - EVENT_ESPRESSO_VERSION, |
|
| 219 | - true |
|
| 220 | - ); |
|
| 221 | - wp_enqueue_style( |
|
| 222 | - 'progress_bar', |
|
| 223 | - EE_PLUGIN_DIR_URL . 'core/libraries/batch/Assets/progress_bar.css', |
|
| 224 | - array(), |
|
| 225 | - EVENT_ESPRESSO_VERSION |
|
| 226 | - ); |
|
| 227 | - wp_enqueue_script( |
|
| 228 | - 'batch_runner', |
|
| 229 | - EE_PLUGIN_DIR_URL . 'core/libraries/batch/Assets/batch_runner.js', |
|
| 230 | - array('progress_bar', CoreAssetManager::JS_HANDLE_CORE), |
|
| 231 | - EVENT_ESPRESSO_VERSION, |
|
| 232 | - true |
|
| 233 | - ); |
|
| 234 | - $job_handler_classname = stripslashes($_GET['job_handler']); |
|
| 235 | - $request_data = array_diff_key( |
|
| 236 | - $_REQUEST, |
|
| 237 | - array_flip(array('action', 'page', 'ee', 'batch')) |
|
| 238 | - ); |
|
| 239 | - $batch_runner = $this->getLoader()->getShared('EventEspressoBatchRequest\BatchRequestProcessor'); |
|
| 240 | - // eg 'EventEspressoBatchRequest\JobHandlers\RegistrationsReport' |
|
| 241 | - $job_response = $batch_runner->create_job($job_handler_classname, $request_data); |
|
| 242 | - // remember the response for later. We need it to display the page body |
|
| 243 | - $this->_job_step_response = $job_response; |
|
| 244 | - return $job_response; |
|
| 245 | - } |
|
| 200 | + /** |
|
| 201 | + * Enqueues scripts and styles common to any batch job, and creates |
|
| 202 | + * a job from the request data, and stores the response in the |
|
| 203 | + * $this->_job_step_response property |
|
| 204 | + * |
|
| 205 | + * @return \EventEspressoBatchRequest\Helpers\JobStepResponse |
|
| 206 | + */ |
|
| 207 | + protected function _enqueue_batch_job_scripts_and_styles_and_start_job() |
|
| 208 | + { |
|
| 209 | + // just copy the bits of EE admin's eei18n that we need in the JS |
|
| 210 | + EE_Registry::$i18n_js_strings['batchJobError'] = esc_html__( |
|
| 211 | + 'An error occurred and the job has been stopped. Please refresh the page to try again.', |
|
| 212 | + 'event_espresso' |
|
| 213 | + ); |
|
| 214 | + wp_register_script( |
|
| 215 | + 'progress_bar', |
|
| 216 | + EE_PLUGIN_DIR_URL . 'core/libraries/batch/Assets/progress_bar.js', |
|
| 217 | + array('jquery'), |
|
| 218 | + EVENT_ESPRESSO_VERSION, |
|
| 219 | + true |
|
| 220 | + ); |
|
| 221 | + wp_enqueue_style( |
|
| 222 | + 'progress_bar', |
|
| 223 | + EE_PLUGIN_DIR_URL . 'core/libraries/batch/Assets/progress_bar.css', |
|
| 224 | + array(), |
|
| 225 | + EVENT_ESPRESSO_VERSION |
|
| 226 | + ); |
|
| 227 | + wp_enqueue_script( |
|
| 228 | + 'batch_runner', |
|
| 229 | + EE_PLUGIN_DIR_URL . 'core/libraries/batch/Assets/batch_runner.js', |
|
| 230 | + array('progress_bar', CoreAssetManager::JS_HANDLE_CORE), |
|
| 231 | + EVENT_ESPRESSO_VERSION, |
|
| 232 | + true |
|
| 233 | + ); |
|
| 234 | + $job_handler_classname = stripslashes($_GET['job_handler']); |
|
| 235 | + $request_data = array_diff_key( |
|
| 236 | + $_REQUEST, |
|
| 237 | + array_flip(array('action', 'page', 'ee', 'batch')) |
|
| 238 | + ); |
|
| 239 | + $batch_runner = $this->getLoader()->getShared('EventEspressoBatchRequest\BatchRequestProcessor'); |
|
| 240 | + // eg 'EventEspressoBatchRequest\JobHandlers\RegistrationsReport' |
|
| 241 | + $job_response = $batch_runner->create_job($job_handler_classname, $request_data); |
|
| 242 | + // remember the response for later. We need it to display the page body |
|
| 243 | + $this->_job_step_response = $job_response; |
|
| 244 | + return $job_response; |
|
| 245 | + } |
|
| 246 | 246 | |
| 247 | - /** |
|
| 248 | - * If we are doing a frontend batch job, this makes it so WP shows our template's HTML |
|
| 249 | - * |
|
| 250 | - * @param string $template |
|
| 251 | - * @return string |
|
| 252 | - */ |
|
| 253 | - public function override_template($template) |
|
| 254 | - { |
|
| 255 | - if (isset($_REQUEST['espresso_batch']) && isset($_REQUEST['batch'])) { |
|
| 256 | - return EE_MODULES . 'batch/templates/batch_frontend_wrapper.template.html'; |
|
| 257 | - } |
|
| 258 | - return $template; |
|
| 259 | - } |
|
| 247 | + /** |
|
| 248 | + * If we are doing a frontend batch job, this makes it so WP shows our template's HTML |
|
| 249 | + * |
|
| 250 | + * @param string $template |
|
| 251 | + * @return string |
|
| 252 | + */ |
|
| 253 | + public function override_template($template) |
|
| 254 | + { |
|
| 255 | + if (isset($_REQUEST['espresso_batch']) && isset($_REQUEST['batch'])) { |
|
| 256 | + return EE_MODULES . 'batch/templates/batch_frontend_wrapper.template.html'; |
|
| 257 | + } |
|
| 258 | + return $template; |
|
| 259 | + } |
|
| 260 | 260 | |
| 261 | - /** |
|
| 262 | - * Adds an admin page which doesn't appear in the admin menu |
|
| 263 | - */ |
|
| 264 | - public function register_admin_pages() |
|
| 265 | - { |
|
| 266 | - add_submenu_page( |
|
| 267 | - '', // parent slug. we don't want this to actually appear in the menu |
|
| 268 | - __('Batch Job', 'event_espresso'), // page title |
|
| 269 | - 'n/a', // menu title |
|
| 270 | - 'read', // we want this page to actually be accessible to anyone, |
|
| 271 | - 'espresso_batch', // menu slug |
|
| 272 | - array(self::instance(), 'show_admin_page') |
|
| 273 | - ); |
|
| 274 | - } |
|
| 261 | + /** |
|
| 262 | + * Adds an admin page which doesn't appear in the admin menu |
|
| 263 | + */ |
|
| 264 | + public function register_admin_pages() |
|
| 265 | + { |
|
| 266 | + add_submenu_page( |
|
| 267 | + '', // parent slug. we don't want this to actually appear in the menu |
|
| 268 | + __('Batch Job', 'event_espresso'), // page title |
|
| 269 | + 'n/a', // menu title |
|
| 270 | + 'read', // we want this page to actually be accessible to anyone, |
|
| 271 | + 'espresso_batch', // menu slug |
|
| 272 | + array(self::instance(), 'show_admin_page') |
|
| 273 | + ); |
|
| 274 | + } |
|
| 275 | 275 | |
| 276 | - /** |
|
| 277 | - * Renders the admin page, after most of the work was already done during enqueuing scripts |
|
| 278 | - * of creating the job and localizing some data |
|
| 279 | - */ |
|
| 280 | - public function show_admin_page() |
|
| 281 | - { |
|
| 282 | - echo EEH_Template::locate_template( |
|
| 283 | - EE_MODULES . 'batch/templates/batch_wrapper.template.html', |
|
| 284 | - array('batch_request_type' => $this->batch_request_type()) |
|
| 285 | - ); |
|
| 286 | - } |
|
| 276 | + /** |
|
| 277 | + * Renders the admin page, after most of the work was already done during enqueuing scripts |
|
| 278 | + * of creating the job and localizing some data |
|
| 279 | + */ |
|
| 280 | + public function show_admin_page() |
|
| 281 | + { |
|
| 282 | + echo EEH_Template::locate_template( |
|
| 283 | + EE_MODULES . 'batch/templates/batch_wrapper.template.html', |
|
| 284 | + array('batch_request_type' => $this->batch_request_type()) |
|
| 285 | + ); |
|
| 286 | + } |
|
| 287 | 287 | |
| 288 | - /** |
|
| 289 | - * Receives ajax calls for continuing a job |
|
| 290 | - */ |
|
| 291 | - public function batch_continue() |
|
| 292 | - { |
|
| 293 | - $job_id = sanitize_text_field($_REQUEST['job_id']); |
|
| 294 | - $batch_runner = $this->getLoader()->getShared('EventEspressoBatchRequest\BatchRequestProcessor'); |
|
| 295 | - $response_obj = $batch_runner->continue_job($job_id); |
|
| 296 | - $this->_return_json($response_obj->to_array()); |
|
| 297 | - } |
|
| 288 | + /** |
|
| 289 | + * Receives ajax calls for continuing a job |
|
| 290 | + */ |
|
| 291 | + public function batch_continue() |
|
| 292 | + { |
|
| 293 | + $job_id = sanitize_text_field($_REQUEST['job_id']); |
|
| 294 | + $batch_runner = $this->getLoader()->getShared('EventEspressoBatchRequest\BatchRequestProcessor'); |
|
| 295 | + $response_obj = $batch_runner->continue_job($job_id); |
|
| 296 | + $this->_return_json($response_obj->to_array()); |
|
| 297 | + } |
|
| 298 | 298 | |
| 299 | - /** |
|
| 300 | - * Receives the ajax call to cleanup a job |
|
| 301 | - * |
|
| 302 | - * @return type |
|
| 303 | - */ |
|
| 304 | - public function batch_cleanup() |
|
| 305 | - { |
|
| 306 | - $job_id = sanitize_text_field($_REQUEST['job_id']); |
|
| 307 | - $batch_runner = $this->getLoader()->getShared('EventEspressoBatchRequest\BatchRequestProcessor'); |
|
| 308 | - $response_obj = $batch_runner->cleanup_job($job_id); |
|
| 309 | - $this->_return_json($response_obj->to_array()); |
|
| 310 | - } |
|
| 299 | + /** |
|
| 300 | + * Receives the ajax call to cleanup a job |
|
| 301 | + * |
|
| 302 | + * @return type |
|
| 303 | + */ |
|
| 304 | + public function batch_cleanup() |
|
| 305 | + { |
|
| 306 | + $job_id = sanitize_text_field($_REQUEST['job_id']); |
|
| 307 | + $batch_runner = $this->getLoader()->getShared('EventEspressoBatchRequest\BatchRequestProcessor'); |
|
| 308 | + $response_obj = $batch_runner->cleanup_job($job_id); |
|
| 309 | + $this->_return_json($response_obj->to_array()); |
|
| 310 | + } |
|
| 311 | 311 | |
| 312 | 312 | |
| 313 | - /** |
|
| 314 | - * Returns a json response |
|
| 315 | - * |
|
| 316 | - * @param array $data The data we want to send echo via in the JSON response's "data" element |
|
| 317 | - * |
|
| 318 | - * The returned json object is created from an array in the following format: |
|
| 319 | - * array( |
|
| 320 | - * 'notices' => '', // - contains any EE_Error formatted notices |
|
| 321 | - * 'data' => array() //this can be any key/value pairs that a method returns for later json parsing by the js. |
|
| 322 | - * We're also going to include the template args with every package (so js can pick out any specific template |
|
| 323 | - * args that might be included in here) |
|
| 324 | - * 'isEEajax' => true,//indicates this is a response from EE |
|
| 325 | - * ) |
|
| 326 | - */ |
|
| 327 | - protected function _return_json($data) |
|
| 328 | - { |
|
| 329 | - $json = array( |
|
| 330 | - 'notices' => EE_Error::get_notices(), |
|
| 331 | - 'data' => $data, |
|
| 332 | - 'isEEajax' => true |
|
| 333 | - // special flag so any ajax.Success methods in js can identify this return package as a EEajax package. |
|
| 334 | - ); |
|
| 313 | + /** |
|
| 314 | + * Returns a json response |
|
| 315 | + * |
|
| 316 | + * @param array $data The data we want to send echo via in the JSON response's "data" element |
|
| 317 | + * |
|
| 318 | + * The returned json object is created from an array in the following format: |
|
| 319 | + * array( |
|
| 320 | + * 'notices' => '', // - contains any EE_Error formatted notices |
|
| 321 | + * 'data' => array() //this can be any key/value pairs that a method returns for later json parsing by the js. |
|
| 322 | + * We're also going to include the template args with every package (so js can pick out any specific template |
|
| 323 | + * args that might be included in here) |
|
| 324 | + * 'isEEajax' => true,//indicates this is a response from EE |
|
| 325 | + * ) |
|
| 326 | + */ |
|
| 327 | + protected function _return_json($data) |
|
| 328 | + { |
|
| 329 | + $json = array( |
|
| 330 | + 'notices' => EE_Error::get_notices(), |
|
| 331 | + 'data' => $data, |
|
| 332 | + 'isEEajax' => true |
|
| 333 | + // special flag so any ajax.Success methods in js can identify this return package as a EEajax package. |
|
| 334 | + ); |
|
| 335 | 335 | |
| 336 | 336 | |
| 337 | - // make sure there are no php errors or headers_sent. Then we can set correct json header. |
|
| 338 | - if (null === error_get_last() || ! headers_sent()) { |
|
| 339 | - header('Content-Type: application/json; charset=UTF-8'); |
|
| 340 | - } |
|
| 341 | - echo wp_json_encode($json); |
|
| 342 | - exit(); |
|
| 343 | - } |
|
| 337 | + // make sure there are no php errors or headers_sent. Then we can set correct json header. |
|
| 338 | + if (null === error_get_last() || ! headers_sent()) { |
|
| 339 | + header('Content-Type: application/json; charset=UTF-8'); |
|
| 340 | + } |
|
| 341 | + echo wp_json_encode($json); |
|
| 342 | + exit(); |
|
| 343 | + } |
|
| 344 | 344 | |
| 345 | - /** |
|
| 346 | - * Gets the job step response which was done during the enqueuing of scripts |
|
| 347 | - * |
|
| 348 | - * @return \EventEspressoBatchRequest\Helpers\JobStepResponse |
|
| 349 | - */ |
|
| 350 | - public function job_step_response() |
|
| 351 | - { |
|
| 352 | - return $this->_job_step_response; |
|
| 353 | - } |
|
| 345 | + /** |
|
| 346 | + * Gets the job step response which was done during the enqueuing of scripts |
|
| 347 | + * |
|
| 348 | + * @return \EventEspressoBatchRequest\Helpers\JobStepResponse |
|
| 349 | + */ |
|
| 350 | + public function job_step_response() |
|
| 351 | + { |
|
| 352 | + return $this->_job_step_response; |
|
| 353 | + } |
|
| 354 | 354 | |
| 355 | - /** |
|
| 356 | - * Gets the batch request type indicated in the $_REQUEST |
|
| 357 | - * |
|
| 358 | - * @return string: EED_Batch::batch_job, EED_Batch::batch_file_job, EED_Batch::batch_not_job |
|
| 359 | - */ |
|
| 360 | - public function batch_request_type() |
|
| 361 | - { |
|
| 362 | - if ($this->_batch_request_type === null) { |
|
| 363 | - if (isset($_GET['batch'])) { |
|
| 364 | - if ($_GET['batch'] == self::batch_job) { |
|
| 365 | - $this->_batch_request_type = self::batch_job; |
|
| 366 | - } elseif ($_GET['batch'] == self::batch_file_job) { |
|
| 367 | - $this->_batch_request_type = self::batch_file_job; |
|
| 368 | - } |
|
| 369 | - } |
|
| 370 | - // if we didn't find that it was a batch request, indicate it wasn't |
|
| 371 | - if ($this->_batch_request_type === null) { |
|
| 372 | - $this->_batch_request_type = self::batch_not_job; |
|
| 373 | - } |
|
| 374 | - } |
|
| 375 | - return $this->_batch_request_type; |
|
| 376 | - } |
|
| 355 | + /** |
|
| 356 | + * Gets the batch request type indicated in the $_REQUEST |
|
| 357 | + * |
|
| 358 | + * @return string: EED_Batch::batch_job, EED_Batch::batch_file_job, EED_Batch::batch_not_job |
|
| 359 | + */ |
|
| 360 | + public function batch_request_type() |
|
| 361 | + { |
|
| 362 | + if ($this->_batch_request_type === null) { |
|
| 363 | + if (isset($_GET['batch'])) { |
|
| 364 | + if ($_GET['batch'] == self::batch_job) { |
|
| 365 | + $this->_batch_request_type = self::batch_job; |
|
| 366 | + } elseif ($_GET['batch'] == self::batch_file_job) { |
|
| 367 | + $this->_batch_request_type = self::batch_file_job; |
|
| 368 | + } |
|
| 369 | + } |
|
| 370 | + // if we didn't find that it was a batch request, indicate it wasn't |
|
| 371 | + if ($this->_batch_request_type === null) { |
|
| 372 | + $this->_batch_request_type = self::batch_not_job; |
|
| 373 | + } |
|
| 374 | + } |
|
| 375 | + return $this->_batch_request_type; |
|
| 376 | + } |
|
| 377 | 377 | |
| 378 | - /** |
|
| 379 | - * Unnecessary |
|
| 380 | - * |
|
| 381 | - * @param type $WP |
|
| 382 | - */ |
|
| 383 | - public function run($WP) |
|
| 384 | - { |
|
| 385 | - } |
|
| 378 | + /** |
|
| 379 | + * Unnecessary |
|
| 380 | + * |
|
| 381 | + * @param type $WP |
|
| 382 | + */ |
|
| 383 | + public function run($WP) |
|
| 384 | + { |
|
| 385 | + } |
|
| 386 | 386 | } |
@@ -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 |
@@ -189,7 +189,7 @@ discard block |
||
| 189 | 189 | array( |
| 190 | 190 | 'download_and_redirecting' => sprintf( |
| 191 | 191 | __('File Generation complete. Downloading, and %1$sredirecting%2$s...', 'event_espresso'), |
| 192 | - '<a href="' . $_REQUEST['return_url'] . '">', |
|
| 192 | + '<a href="'.$_REQUEST['return_url'].'">', |
|
| 193 | 193 | '</a>' |
| 194 | 194 | ), |
| 195 | 195 | 'return_url' => $_REQUEST['return_url'], |
@@ -207,26 +207,26 @@ discard block |
||
| 207 | 207 | protected function _enqueue_batch_job_scripts_and_styles_and_start_job() |
| 208 | 208 | { |
| 209 | 209 | // just copy the bits of EE admin's eei18n that we need in the JS |
| 210 | - EE_Registry::$i18n_js_strings['batchJobError'] = esc_html__( |
|
| 210 | + EE_Registry::$i18n_js_strings['batchJobError'] = esc_html__( |
|
| 211 | 211 | 'An error occurred and the job has been stopped. Please refresh the page to try again.', |
| 212 | 212 | 'event_espresso' |
| 213 | 213 | ); |
| 214 | 214 | wp_register_script( |
| 215 | 215 | 'progress_bar', |
| 216 | - EE_PLUGIN_DIR_URL . 'core/libraries/batch/Assets/progress_bar.js', |
|
| 216 | + EE_PLUGIN_DIR_URL.'core/libraries/batch/Assets/progress_bar.js', |
|
| 217 | 217 | array('jquery'), |
| 218 | 218 | EVENT_ESPRESSO_VERSION, |
| 219 | 219 | true |
| 220 | 220 | ); |
| 221 | 221 | wp_enqueue_style( |
| 222 | 222 | 'progress_bar', |
| 223 | - EE_PLUGIN_DIR_URL . 'core/libraries/batch/Assets/progress_bar.css', |
|
| 223 | + EE_PLUGIN_DIR_URL.'core/libraries/batch/Assets/progress_bar.css', |
|
| 224 | 224 | array(), |
| 225 | 225 | EVENT_ESPRESSO_VERSION |
| 226 | 226 | ); |
| 227 | 227 | wp_enqueue_script( |
| 228 | 228 | 'batch_runner', |
| 229 | - EE_PLUGIN_DIR_URL . 'core/libraries/batch/Assets/batch_runner.js', |
|
| 229 | + EE_PLUGIN_DIR_URL.'core/libraries/batch/Assets/batch_runner.js', |
|
| 230 | 230 | array('progress_bar', CoreAssetManager::JS_HANDLE_CORE), |
| 231 | 231 | EVENT_ESPRESSO_VERSION, |
| 232 | 232 | true |
@@ -253,7 +253,7 @@ discard block |
||
| 253 | 253 | public function override_template($template) |
| 254 | 254 | { |
| 255 | 255 | if (isset($_REQUEST['espresso_batch']) && isset($_REQUEST['batch'])) { |
| 256 | - return EE_MODULES . 'batch/templates/batch_frontend_wrapper.template.html'; |
|
| 256 | + return EE_MODULES.'batch/templates/batch_frontend_wrapper.template.html'; |
|
| 257 | 257 | } |
| 258 | 258 | return $template; |
| 259 | 259 | } |
@@ -280,7 +280,7 @@ discard block |
||
| 280 | 280 | public function show_admin_page() |
| 281 | 281 | { |
| 282 | 282 | echo EEH_Template::locate_template( |
| 283 | - EE_MODULES . 'batch/templates/batch_wrapper.template.html', |
|
| 283 | + EE_MODULES.'batch/templates/batch_wrapper.template.html', |
|
| 284 | 284 | array('batch_request_type' => $this->batch_request_type()) |
| 285 | 285 | ); |
| 286 | 286 | } |
@@ -12,217 +12,217 @@ |
||
| 12 | 12 | { |
| 13 | 13 | |
| 14 | 14 | |
| 15 | - /** |
|
| 16 | - * @return EED_Feeds |
|
| 17 | - */ |
|
| 18 | - public static function instance() |
|
| 19 | - { |
|
| 20 | - return parent::get_instance(__CLASS__); |
|
| 21 | - } |
|
| 22 | - |
|
| 23 | - |
|
| 24 | - /** |
|
| 25 | - * set_hooks - for hooking into EE Core, other modules, etc |
|
| 26 | - * |
|
| 27 | - * @access public |
|
| 28 | - * @return void |
|
| 29 | - */ |
|
| 30 | - public static function set_hooks() |
|
| 31 | - { |
|
| 32 | - add_action('parse_request', array('EED_Feeds', 'parse_request'), 10); |
|
| 33 | - add_filter('default_feed', array('EED_Feeds', 'default_feed'), 10, 1); |
|
| 34 | - add_filter('comment_feed_join', array('EED_Feeds', 'comment_feed_join'), 10, 2); |
|
| 35 | - add_filter('comment_feed_where', array('EED_Feeds', 'comment_feed_where'), 10, 2); |
|
| 36 | - } |
|
| 37 | - |
|
| 38 | - /** |
|
| 39 | - * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
| 40 | - * |
|
| 41 | - * @access public |
|
| 42 | - * @return void |
|
| 43 | - */ |
|
| 44 | - public static function set_hooks_admin() |
|
| 45 | - { |
|
| 46 | - } |
|
| 47 | - |
|
| 48 | - |
|
| 49 | - /** |
|
| 50 | - * run - initial module setup |
|
| 51 | - * |
|
| 52 | - * @access public |
|
| 53 | - * @return void |
|
| 54 | - */ |
|
| 55 | - public function run($WP) |
|
| 56 | - { |
|
| 57 | - } |
|
| 58 | - |
|
| 59 | - |
|
| 60 | - /** |
|
| 61 | - * default_feed |
|
| 62 | - * |
|
| 63 | - * @access public |
|
| 64 | - * @param type rss2, atom, rss, rdf, rssjs |
|
| 65 | - * @return string |
|
| 66 | - */ |
|
| 67 | - public static function default_feed($type = 'rss2') |
|
| 68 | - { |
|
| 69 | - // rss2, atom, rss, rdf, rssjs |
|
| 70 | - $type = 'rss2'; |
|
| 71 | - return $type; |
|
| 72 | - } |
|
| 73 | - |
|
| 74 | - |
|
| 75 | - /** |
|
| 76 | - * parse_request |
|
| 77 | - * |
|
| 78 | - * @access public |
|
| 79 | - * @return void |
|
| 80 | - */ |
|
| 81 | - public static function parse_request() |
|
| 82 | - { |
|
| 83 | - if (EE_Registry::instance()->REQ->is_set('post_type')) { |
|
| 84 | - // define path to templates |
|
| 85 | - define('RSS_FEEDS_TEMPLATES_PATH', str_replace('\\', '/', plugin_dir_path(__FILE__)) . 'templates/'); |
|
| 86 | - // what kinda post_type are we dealing with ? |
|
| 87 | - switch (EE_Registry::instance()->REQ->get('post_type')) { |
|
| 88 | - case 'espresso_events': |
|
| 89 | - // for rss2, atom, rss, rdf |
|
| 90 | - add_filter('the_excerpt_rss', array('EED_Feeds', 'the_event_feed'), 10, 1); |
|
| 91 | - add_filter('the_content_feed', array('EED_Feeds', 'the_event_feed'), 10, 1); |
|
| 92 | - // for json ( also uses the above filter ) |
|
| 93 | - add_filter('rssjs_feed_item', array('EED_Feeds', 'the_event_rssjs_feed'), 10, 1); |
|
| 94 | - break; |
|
| 95 | - case 'espresso_venues': |
|
| 96 | - // for rss2, atom, rss, rdf |
|
| 97 | - add_filter('the_excerpt_rss', array('EED_Feeds', 'the_venue_feed'), 10, 1); |
|
| 98 | - add_filter('the_content_feed', array('EED_Feeds', 'the_venue_feed'), 10, 1); |
|
| 99 | - // for json ( also uses the above filter ) |
|
| 100 | - add_filter('rssjs_feed_item', array('EED_Feeds', 'the_venue_rssjs_feed'), 10, 1); |
|
| 101 | - break; |
|
| 102 | - } |
|
| 103 | - } |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - |
|
| 107 | - /** |
|
| 108 | - * comment_feed_join - EVEN THOUGH... our espresso_attendees custom post type is set to NOT PUBLIC |
|
| 109 | - * WordPress thought it would be a good idea to display the comments for them in the RSS feeds... we think NOT |
|
| 110 | - * so this little snippet of SQL taps into the comment feed query and removes comments for the |
|
| 111 | - * espresso_attendees post_type |
|
| 112 | - * |
|
| 113 | - * @access public |
|
| 114 | - * @param string $SQL the JOIN clause for the comment feed query |
|
| 115 | - * @return void |
|
| 116 | - */ |
|
| 117 | - public static function comment_feed_join($SQL) |
|
| 118 | - { |
|
| 119 | - global $wpdb; |
|
| 120 | - // check for wp_posts table in JOIN clause |
|
| 121 | - if (strpos($SQL, $wpdb->posts) !== false) { |
|
| 122 | - add_filter('EED_Feeds__comment_feed_where__espresso_attendees', '__return_true'); |
|
| 123 | - } |
|
| 124 | - return $SQL; |
|
| 125 | - } |
|
| 126 | - |
|
| 127 | - |
|
| 128 | - /** |
|
| 129 | - * comment_feed_where - EVEN THOUGH... our espresso_attendees custom post type is set to NOT PUBLIC |
|
| 130 | - * WordPress thought it would be a good idea to display the comments for them in the RSS feeds... we think NOT |
|
| 131 | - * so this little snippet of SQL taps into the comment feed query and removes comments for the |
|
| 132 | - * espresso_attendees post_type |
|
| 133 | - * |
|
| 134 | - * @access public |
|
| 135 | - * @param string $SQL the WHERE clause for the comment feed query |
|
| 136 | - * @return void |
|
| 137 | - */ |
|
| 138 | - public static function comment_feed_where($SQL) |
|
| 139 | - { |
|
| 140 | - global $wp_query, $wpdb; |
|
| 141 | - if ($wp_query->is_comment_feed && apply_filters('EED_Feeds__comment_feed_where__espresso_attendees', false)) { |
|
| 142 | - $SQL .= " AND $wpdb->posts.post_type != 'espresso_attendees'"; |
|
| 143 | - } |
|
| 144 | - return $SQL; |
|
| 145 | - } |
|
| 146 | - |
|
| 147 | - |
|
| 148 | - /** |
|
| 149 | - * the_event_feed |
|
| 150 | - * |
|
| 151 | - * @access public |
|
| 152 | - * @param string $content |
|
| 153 | - * @return void |
|
| 154 | - */ |
|
| 155 | - public static function the_event_feed($content) |
|
| 156 | - { |
|
| 157 | - if (is_feed() && is_readable(RSS_FEEDS_TEMPLATES_PATH . 'espresso_events_feed.template.php')) { |
|
| 158 | - global $post; |
|
| 159 | - $template_args = array( |
|
| 160 | - 'EVT_ID' => $post->ID, |
|
| 161 | - 'event_description' => get_option('rss_use_excerpt') ? $post->post_excerpt : $post->post_content, |
|
| 162 | - ); |
|
| 163 | - $content = EEH_Template::display_template( |
|
| 164 | - RSS_FEEDS_TEMPLATES_PATH . 'espresso_events_feed.template.php', |
|
| 165 | - $template_args, |
|
| 166 | - true |
|
| 167 | - ); |
|
| 168 | - } |
|
| 169 | - return $content; |
|
| 170 | - } |
|
| 171 | - |
|
| 172 | - |
|
| 173 | - /** |
|
| 174 | - * the_event_rssjs_feed |
|
| 175 | - * |
|
| 176 | - * @access public |
|
| 177 | - * @param object $item |
|
| 178 | - * @return void |
|
| 179 | - */ |
|
| 180 | - public static function the_event_rssjs_feed($item) |
|
| 181 | - { |
|
| 182 | - if (is_feed() && isset($item->description)) { |
|
| 183 | - $item->description = EED_Feeds::the_event_feed($item->description); |
|
| 184 | - } |
|
| 185 | - return $item; |
|
| 186 | - } |
|
| 187 | - |
|
| 188 | - |
|
| 189 | - /** |
|
| 190 | - * the_venue_feed |
|
| 191 | - * |
|
| 192 | - * @access public |
|
| 193 | - * @param string $content |
|
| 194 | - * @return void |
|
| 195 | - */ |
|
| 196 | - public static function the_venue_feed($content) |
|
| 197 | - { |
|
| 198 | - if (is_feed() && is_readable(RSS_FEEDS_TEMPLATES_PATH . 'espresso_venues_feed.template.php')) { |
|
| 199 | - global $post; |
|
| 200 | - $template_args = array( |
|
| 201 | - 'VNU_ID' => $post->ID, |
|
| 202 | - 'venue_description' => get_option('rss_use_excerpt') ? $post->post_excerpt : $post->post_content, |
|
| 203 | - ); |
|
| 204 | - $content = EEH_Template::display_template( |
|
| 205 | - RSS_FEEDS_TEMPLATES_PATH . 'espresso_venues_feed.template.php', |
|
| 206 | - $template_args, |
|
| 207 | - true |
|
| 208 | - ); |
|
| 209 | - } |
|
| 210 | - return $content; |
|
| 211 | - } |
|
| 212 | - |
|
| 213 | - |
|
| 214 | - /** |
|
| 215 | - * the_venue_rssjs_feed |
|
| 216 | - * |
|
| 217 | - * @access public |
|
| 218 | - * @param object $item |
|
| 219 | - * @return void |
|
| 220 | - */ |
|
| 221 | - public static function the_venue_rssjs_feed($item) |
|
| 222 | - { |
|
| 223 | - if (is_feed() && isset($item->description)) { |
|
| 224 | - $item->description = EED_Feeds::the_venue_feed($item->description); |
|
| 225 | - } |
|
| 226 | - return $item; |
|
| 227 | - } |
|
| 15 | + /** |
|
| 16 | + * @return EED_Feeds |
|
| 17 | + */ |
|
| 18 | + public static function instance() |
|
| 19 | + { |
|
| 20 | + return parent::get_instance(__CLASS__); |
|
| 21 | + } |
|
| 22 | + |
|
| 23 | + |
|
| 24 | + /** |
|
| 25 | + * set_hooks - for hooking into EE Core, other modules, etc |
|
| 26 | + * |
|
| 27 | + * @access public |
|
| 28 | + * @return void |
|
| 29 | + */ |
|
| 30 | + public static function set_hooks() |
|
| 31 | + { |
|
| 32 | + add_action('parse_request', array('EED_Feeds', 'parse_request'), 10); |
|
| 33 | + add_filter('default_feed', array('EED_Feeds', 'default_feed'), 10, 1); |
|
| 34 | + add_filter('comment_feed_join', array('EED_Feeds', 'comment_feed_join'), 10, 2); |
|
| 35 | + add_filter('comment_feed_where', array('EED_Feeds', 'comment_feed_where'), 10, 2); |
|
| 36 | + } |
|
| 37 | + |
|
| 38 | + /** |
|
| 39 | + * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
| 40 | + * |
|
| 41 | + * @access public |
|
| 42 | + * @return void |
|
| 43 | + */ |
|
| 44 | + public static function set_hooks_admin() |
|
| 45 | + { |
|
| 46 | + } |
|
| 47 | + |
|
| 48 | + |
|
| 49 | + /** |
|
| 50 | + * run - initial module setup |
|
| 51 | + * |
|
| 52 | + * @access public |
|
| 53 | + * @return void |
|
| 54 | + */ |
|
| 55 | + public function run($WP) |
|
| 56 | + { |
|
| 57 | + } |
|
| 58 | + |
|
| 59 | + |
|
| 60 | + /** |
|
| 61 | + * default_feed |
|
| 62 | + * |
|
| 63 | + * @access public |
|
| 64 | + * @param type rss2, atom, rss, rdf, rssjs |
|
| 65 | + * @return string |
|
| 66 | + */ |
|
| 67 | + public static function default_feed($type = 'rss2') |
|
| 68 | + { |
|
| 69 | + // rss2, atom, rss, rdf, rssjs |
|
| 70 | + $type = 'rss2'; |
|
| 71 | + return $type; |
|
| 72 | + } |
|
| 73 | + |
|
| 74 | + |
|
| 75 | + /** |
|
| 76 | + * parse_request |
|
| 77 | + * |
|
| 78 | + * @access public |
|
| 79 | + * @return void |
|
| 80 | + */ |
|
| 81 | + public static function parse_request() |
|
| 82 | + { |
|
| 83 | + if (EE_Registry::instance()->REQ->is_set('post_type')) { |
|
| 84 | + // define path to templates |
|
| 85 | + define('RSS_FEEDS_TEMPLATES_PATH', str_replace('\\', '/', plugin_dir_path(__FILE__)) . 'templates/'); |
|
| 86 | + // what kinda post_type are we dealing with ? |
|
| 87 | + switch (EE_Registry::instance()->REQ->get('post_type')) { |
|
| 88 | + case 'espresso_events': |
|
| 89 | + // for rss2, atom, rss, rdf |
|
| 90 | + add_filter('the_excerpt_rss', array('EED_Feeds', 'the_event_feed'), 10, 1); |
|
| 91 | + add_filter('the_content_feed', array('EED_Feeds', 'the_event_feed'), 10, 1); |
|
| 92 | + // for json ( also uses the above filter ) |
|
| 93 | + add_filter('rssjs_feed_item', array('EED_Feeds', 'the_event_rssjs_feed'), 10, 1); |
|
| 94 | + break; |
|
| 95 | + case 'espresso_venues': |
|
| 96 | + // for rss2, atom, rss, rdf |
|
| 97 | + add_filter('the_excerpt_rss', array('EED_Feeds', 'the_venue_feed'), 10, 1); |
|
| 98 | + add_filter('the_content_feed', array('EED_Feeds', 'the_venue_feed'), 10, 1); |
|
| 99 | + // for json ( also uses the above filter ) |
|
| 100 | + add_filter('rssjs_feed_item', array('EED_Feeds', 'the_venue_rssjs_feed'), 10, 1); |
|
| 101 | + break; |
|
| 102 | + } |
|
| 103 | + } |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + |
|
| 107 | + /** |
|
| 108 | + * comment_feed_join - EVEN THOUGH... our espresso_attendees custom post type is set to NOT PUBLIC |
|
| 109 | + * WordPress thought it would be a good idea to display the comments for them in the RSS feeds... we think NOT |
|
| 110 | + * so this little snippet of SQL taps into the comment feed query and removes comments for the |
|
| 111 | + * espresso_attendees post_type |
|
| 112 | + * |
|
| 113 | + * @access public |
|
| 114 | + * @param string $SQL the JOIN clause for the comment feed query |
|
| 115 | + * @return void |
|
| 116 | + */ |
|
| 117 | + public static function comment_feed_join($SQL) |
|
| 118 | + { |
|
| 119 | + global $wpdb; |
|
| 120 | + // check for wp_posts table in JOIN clause |
|
| 121 | + if (strpos($SQL, $wpdb->posts) !== false) { |
|
| 122 | + add_filter('EED_Feeds__comment_feed_where__espresso_attendees', '__return_true'); |
|
| 123 | + } |
|
| 124 | + return $SQL; |
|
| 125 | + } |
|
| 126 | + |
|
| 127 | + |
|
| 128 | + /** |
|
| 129 | + * comment_feed_where - EVEN THOUGH... our espresso_attendees custom post type is set to NOT PUBLIC |
|
| 130 | + * WordPress thought it would be a good idea to display the comments for them in the RSS feeds... we think NOT |
|
| 131 | + * so this little snippet of SQL taps into the comment feed query and removes comments for the |
|
| 132 | + * espresso_attendees post_type |
|
| 133 | + * |
|
| 134 | + * @access public |
|
| 135 | + * @param string $SQL the WHERE clause for the comment feed query |
|
| 136 | + * @return void |
|
| 137 | + */ |
|
| 138 | + public static function comment_feed_where($SQL) |
|
| 139 | + { |
|
| 140 | + global $wp_query, $wpdb; |
|
| 141 | + if ($wp_query->is_comment_feed && apply_filters('EED_Feeds__comment_feed_where__espresso_attendees', false)) { |
|
| 142 | + $SQL .= " AND $wpdb->posts.post_type != 'espresso_attendees'"; |
|
| 143 | + } |
|
| 144 | + return $SQL; |
|
| 145 | + } |
|
| 146 | + |
|
| 147 | + |
|
| 148 | + /** |
|
| 149 | + * the_event_feed |
|
| 150 | + * |
|
| 151 | + * @access public |
|
| 152 | + * @param string $content |
|
| 153 | + * @return void |
|
| 154 | + */ |
|
| 155 | + public static function the_event_feed($content) |
|
| 156 | + { |
|
| 157 | + if (is_feed() && is_readable(RSS_FEEDS_TEMPLATES_PATH . 'espresso_events_feed.template.php')) { |
|
| 158 | + global $post; |
|
| 159 | + $template_args = array( |
|
| 160 | + 'EVT_ID' => $post->ID, |
|
| 161 | + 'event_description' => get_option('rss_use_excerpt') ? $post->post_excerpt : $post->post_content, |
|
| 162 | + ); |
|
| 163 | + $content = EEH_Template::display_template( |
|
| 164 | + RSS_FEEDS_TEMPLATES_PATH . 'espresso_events_feed.template.php', |
|
| 165 | + $template_args, |
|
| 166 | + true |
|
| 167 | + ); |
|
| 168 | + } |
|
| 169 | + return $content; |
|
| 170 | + } |
|
| 171 | + |
|
| 172 | + |
|
| 173 | + /** |
|
| 174 | + * the_event_rssjs_feed |
|
| 175 | + * |
|
| 176 | + * @access public |
|
| 177 | + * @param object $item |
|
| 178 | + * @return void |
|
| 179 | + */ |
|
| 180 | + public static function the_event_rssjs_feed($item) |
|
| 181 | + { |
|
| 182 | + if (is_feed() && isset($item->description)) { |
|
| 183 | + $item->description = EED_Feeds::the_event_feed($item->description); |
|
| 184 | + } |
|
| 185 | + return $item; |
|
| 186 | + } |
|
| 187 | + |
|
| 188 | + |
|
| 189 | + /** |
|
| 190 | + * the_venue_feed |
|
| 191 | + * |
|
| 192 | + * @access public |
|
| 193 | + * @param string $content |
|
| 194 | + * @return void |
|
| 195 | + */ |
|
| 196 | + public static function the_venue_feed($content) |
|
| 197 | + { |
|
| 198 | + if (is_feed() && is_readable(RSS_FEEDS_TEMPLATES_PATH . 'espresso_venues_feed.template.php')) { |
|
| 199 | + global $post; |
|
| 200 | + $template_args = array( |
|
| 201 | + 'VNU_ID' => $post->ID, |
|
| 202 | + 'venue_description' => get_option('rss_use_excerpt') ? $post->post_excerpt : $post->post_content, |
|
| 203 | + ); |
|
| 204 | + $content = EEH_Template::display_template( |
|
| 205 | + RSS_FEEDS_TEMPLATES_PATH . 'espresso_venues_feed.template.php', |
|
| 206 | + $template_args, |
|
| 207 | + true |
|
| 208 | + ); |
|
| 209 | + } |
|
| 210 | + return $content; |
|
| 211 | + } |
|
| 212 | + |
|
| 213 | + |
|
| 214 | + /** |
|
| 215 | + * the_venue_rssjs_feed |
|
| 216 | + * |
|
| 217 | + * @access public |
|
| 218 | + * @param object $item |
|
| 219 | + * @return void |
|
| 220 | + */ |
|
| 221 | + public static function the_venue_rssjs_feed($item) |
|
| 222 | + { |
|
| 223 | + if (is_feed() && isset($item->description)) { |
|
| 224 | + $item->description = EED_Feeds::the_venue_feed($item->description); |
|
| 225 | + } |
|
| 226 | + return $item; |
|
| 227 | + } |
|
| 228 | 228 | } |
@@ -82,7 +82,7 @@ discard block |
||
| 82 | 82 | { |
| 83 | 83 | if (EE_Registry::instance()->REQ->is_set('post_type')) { |
| 84 | 84 | // define path to templates |
| 85 | - define('RSS_FEEDS_TEMPLATES_PATH', str_replace('\\', '/', plugin_dir_path(__FILE__)) . 'templates/'); |
|
| 85 | + define('RSS_FEEDS_TEMPLATES_PATH', str_replace('\\', '/', plugin_dir_path(__FILE__)).'templates/'); |
|
| 86 | 86 | // what kinda post_type are we dealing with ? |
| 87 | 87 | switch (EE_Registry::instance()->REQ->get('post_type')) { |
| 88 | 88 | case 'espresso_events': |
@@ -154,14 +154,14 @@ discard block |
||
| 154 | 154 | */ |
| 155 | 155 | public static function the_event_feed($content) |
| 156 | 156 | { |
| 157 | - if (is_feed() && is_readable(RSS_FEEDS_TEMPLATES_PATH . 'espresso_events_feed.template.php')) { |
|
| 157 | + if (is_feed() && is_readable(RSS_FEEDS_TEMPLATES_PATH.'espresso_events_feed.template.php')) { |
|
| 158 | 158 | global $post; |
| 159 | 159 | $template_args = array( |
| 160 | 160 | 'EVT_ID' => $post->ID, |
| 161 | 161 | 'event_description' => get_option('rss_use_excerpt') ? $post->post_excerpt : $post->post_content, |
| 162 | 162 | ); |
| 163 | 163 | $content = EEH_Template::display_template( |
| 164 | - RSS_FEEDS_TEMPLATES_PATH . 'espresso_events_feed.template.php', |
|
| 164 | + RSS_FEEDS_TEMPLATES_PATH.'espresso_events_feed.template.php', |
|
| 165 | 165 | $template_args, |
| 166 | 166 | true |
| 167 | 167 | ); |
@@ -195,14 +195,14 @@ discard block |
||
| 195 | 195 | */ |
| 196 | 196 | public static function the_venue_feed($content) |
| 197 | 197 | { |
| 198 | - if (is_feed() && is_readable(RSS_FEEDS_TEMPLATES_PATH . 'espresso_venues_feed.template.php')) { |
|
| 198 | + if (is_feed() && is_readable(RSS_FEEDS_TEMPLATES_PATH.'espresso_venues_feed.template.php')) { |
|
| 199 | 199 | global $post; |
| 200 | 200 | $template_args = array( |
| 201 | 201 | 'VNU_ID' => $post->ID, |
| 202 | 202 | 'venue_description' => get_option('rss_use_excerpt') ? $post->post_excerpt : $post->post_content, |
| 203 | 203 | ); |
| 204 | 204 | $content = EEH_Template::display_template( |
| 205 | - RSS_FEEDS_TEMPLATES_PATH . 'espresso_venues_feed.template.php', |
|
| 205 | + RSS_FEEDS_TEMPLATES_PATH.'espresso_venues_feed.template.php', |
|
| 206 | 206 | $template_args, |
| 207 | 207 | true |
| 208 | 208 | ); |
@@ -29,176 +29,176 @@ |
||
| 29 | 29 | class EED_Venues_Archive extends EED_Module |
| 30 | 30 | { |
| 31 | 31 | |
| 32 | - /** |
|
| 33 | - * @return EED_Venues_Archive |
|
| 34 | - */ |
|
| 35 | - public static function instance() |
|
| 36 | - { |
|
| 37 | - return parent::get_instance(__CLASS__); |
|
| 38 | - } |
|
| 39 | - |
|
| 40 | - |
|
| 41 | - /** |
|
| 42 | - * set_hooks - for hooking into EE Core, other modules, etc |
|
| 43 | - * |
|
| 44 | - * @return void |
|
| 45 | - * @throws InvalidArgumentException |
|
| 46 | - * @throws InvalidDataTypeException |
|
| 47 | - * @throws InvalidInterfaceException |
|
| 48 | - */ |
|
| 49 | - public static function set_hooks() |
|
| 50 | - { |
|
| 51 | - /** @var EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions $custom_post_type_definitions */ |
|
| 52 | - $custom_post_type_definitions = LoaderFactory::getLoader()->getShared( |
|
| 53 | - 'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' |
|
| 54 | - ); |
|
| 55 | - $custom_post_types = $custom_post_type_definitions->getDefinitions(); |
|
| 56 | - EE_Config::register_route( |
|
| 57 | - $custom_post_types['espresso_venues']['plural_slug'], |
|
| 58 | - 'Venues_Archive', |
|
| 59 | - 'run' |
|
| 60 | - ); |
|
| 61 | - } |
|
| 62 | - |
|
| 63 | - /** |
|
| 64 | - * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
| 65 | - * |
|
| 66 | - * @access public |
|
| 67 | - * @return void |
|
| 68 | - */ |
|
| 69 | - public static function set_hooks_admin() |
|
| 70 | - { |
|
| 71 | - } |
|
| 72 | - |
|
| 73 | - |
|
| 74 | - /** |
|
| 75 | - * run - initial module setup |
|
| 76 | - * |
|
| 77 | - * @access public |
|
| 78 | - * @param \WP $WP |
|
| 79 | - */ |
|
| 80 | - public function run($WP) |
|
| 81 | - { |
|
| 82 | - // check what template is loaded |
|
| 83 | - add_filter('template_include', array($this, 'template_include'), 999, 1); |
|
| 84 | - add_action('wp_enqueue_scripts', array($this, 'wp_enqueue_scripts'), 10); |
|
| 85 | - } |
|
| 86 | - |
|
| 87 | - |
|
| 88 | - /** |
|
| 89 | - * template_include |
|
| 90 | - * |
|
| 91 | - * @access public |
|
| 92 | - * @param string $template |
|
| 93 | - * @return string |
|
| 94 | - */ |
|
| 95 | - public function template_include($template) |
|
| 96 | - { |
|
| 97 | - // not a custom template? |
|
| 98 | - if (EE_Registry::instance()->load_core('Front_Controller', array(), false, true) |
|
| 99 | - ->get_selected_template() != 'archive-espresso_venues.php' |
|
| 100 | - ) { |
|
| 101 | - EEH_Template::load_espresso_theme_functions(); |
|
| 102 | - // then add extra event data via hooks |
|
| 103 | - add_filter('the_title', array($this, 'the_title'), 100, 1); |
|
| 104 | - // don't know if theme uses the_excerpt |
|
| 105 | - add_filter('the_excerpt', array($this, 'venue_details'), 100); |
|
| 106 | - // or the_content |
|
| 107 | - add_filter('the_content', array($this, 'venue_details'), 100); |
|
| 108 | - // don't display entry meta because the existing theme will take care of that |
|
| 109 | - add_filter('FHEE__content_espresso_venues_details_template__display_entry_meta', '__return_false'); |
|
| 110 | - } |
|
| 111 | - return $template; |
|
| 112 | - } |
|
| 113 | - |
|
| 114 | - |
|
| 115 | - /** |
|
| 116 | - * the_title |
|
| 117 | - * |
|
| 118 | - * @access public |
|
| 119 | - * @param string $title |
|
| 120 | - * @return string |
|
| 121 | - */ |
|
| 122 | - public function the_title($title = '') |
|
| 123 | - { |
|
| 124 | - return $title; |
|
| 125 | - } |
|
| 126 | - |
|
| 127 | - |
|
| 128 | - /** |
|
| 129 | - * venue_details |
|
| 130 | - * |
|
| 131 | - * @access public |
|
| 132 | - * @param string $content |
|
| 133 | - * @return string |
|
| 134 | - */ |
|
| 135 | - public function venue_details($content) |
|
| 136 | - { |
|
| 137 | - global $post; |
|
| 138 | - if ($post->post_type == 'espresso_venues' |
|
| 139 | - && ! post_password_required() |
|
| 140 | - ) { |
|
| 141 | - // since the 'content-espresso_venues-details.php' template might be used directly from within a theme, |
|
| 142 | - // it uses the_content() for displaying the $post->post_content |
|
| 143 | - // so in order to load a template that uses the_content() from within a callback being used to filter the_content(), |
|
| 144 | - // we need to first remove this callback from being applied to the_content() (otherwise it will recurse and blow up the interweb) |
|
| 145 | - remove_filter('the_excerpt', array($this, 'venue_details'), 100); |
|
| 146 | - remove_filter('the_content', array($this, 'venue_details'), 100); |
|
| 147 | - // add filters we want |
|
| 148 | - add_filter('the_content', array($this, 'venue_location'), 110); |
|
| 149 | - add_filter('the_excerpt', array($this, 'venue_location'), 110); |
|
| 150 | - // now load our template |
|
| 151 | - $template = EEH_Template::locate_template('content-espresso_venues-details.php'); |
|
| 152 | - // now add our filter back in, plus some others |
|
| 153 | - add_filter('the_excerpt', array($this, 'venue_details'), 100); |
|
| 154 | - add_filter('the_content', array($this, 'venue_details'), 100); |
|
| 155 | - // remove other filters we added so they won't get applied to the next post |
|
| 156 | - remove_filter('the_content', array($this, 'venue_location'), 110); |
|
| 157 | - remove_filter('the_excerpt', array($this, 'venue_location'), 110); |
|
| 158 | - // we're not returning the $content directly because the template we are loading uses the_content (or the_excerpt) |
|
| 159 | - } |
|
| 160 | - return ! empty($template) ? $template : $content; |
|
| 161 | - } |
|
| 162 | - |
|
| 163 | - |
|
| 164 | - /** |
|
| 165 | - * venue_location |
|
| 166 | - * |
|
| 167 | - * @access public |
|
| 168 | - * @param string $content |
|
| 169 | - * @return string |
|
| 170 | - */ |
|
| 171 | - public function venue_location($content) |
|
| 172 | - { |
|
| 173 | - return $content . EEH_Template::locate_template('content-espresso_venues-location.php'); |
|
| 174 | - } |
|
| 175 | - |
|
| 176 | - |
|
| 177 | - /** |
|
| 178 | - * wp_enqueue_scripts |
|
| 179 | - * |
|
| 180 | - * @access public |
|
| 181 | - * @return void |
|
| 182 | - */ |
|
| 183 | - public function wp_enqueue_scripts() |
|
| 184 | - { |
|
| 185 | - // get some style |
|
| 186 | - if (apply_filters('FHEE_enable_default_espresso_css', true) && is_archive()) { |
|
| 187 | - // first check theme folder |
|
| 188 | - if (is_readable(get_stylesheet_directory() . $this->theme . '/style.css')) { |
|
| 189 | - wp_register_style( |
|
| 190 | - $this->theme, |
|
| 191 | - get_stylesheet_directory_uri() . $this->theme . '/style.css', |
|
| 192 | - array('dashicons', 'espresso_default') |
|
| 193 | - ); |
|
| 194 | - } elseif (is_readable(EE_TEMPLATES . $this->theme . '/style.css')) { |
|
| 195 | - wp_register_style( |
|
| 196 | - $this->theme, |
|
| 197 | - EE_TEMPLATES_URL . $this->theme . '/style.css', |
|
| 198 | - array('dashicons', 'espresso_default') |
|
| 199 | - ); |
|
| 200 | - } |
|
| 201 | - wp_enqueue_style($this->theme); |
|
| 202 | - } |
|
| 203 | - } |
|
| 32 | + /** |
|
| 33 | + * @return EED_Venues_Archive |
|
| 34 | + */ |
|
| 35 | + public static function instance() |
|
| 36 | + { |
|
| 37 | + return parent::get_instance(__CLASS__); |
|
| 38 | + } |
|
| 39 | + |
|
| 40 | + |
|
| 41 | + /** |
|
| 42 | + * set_hooks - for hooking into EE Core, other modules, etc |
|
| 43 | + * |
|
| 44 | + * @return void |
|
| 45 | + * @throws InvalidArgumentException |
|
| 46 | + * @throws InvalidDataTypeException |
|
| 47 | + * @throws InvalidInterfaceException |
|
| 48 | + */ |
|
| 49 | + public static function set_hooks() |
|
| 50 | + { |
|
| 51 | + /** @var EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions $custom_post_type_definitions */ |
|
| 52 | + $custom_post_type_definitions = LoaderFactory::getLoader()->getShared( |
|
| 53 | + 'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' |
|
| 54 | + ); |
|
| 55 | + $custom_post_types = $custom_post_type_definitions->getDefinitions(); |
|
| 56 | + EE_Config::register_route( |
|
| 57 | + $custom_post_types['espresso_venues']['plural_slug'], |
|
| 58 | + 'Venues_Archive', |
|
| 59 | + 'run' |
|
| 60 | + ); |
|
| 61 | + } |
|
| 62 | + |
|
| 63 | + /** |
|
| 64 | + * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
| 65 | + * |
|
| 66 | + * @access public |
|
| 67 | + * @return void |
|
| 68 | + */ |
|
| 69 | + public static function set_hooks_admin() |
|
| 70 | + { |
|
| 71 | + } |
|
| 72 | + |
|
| 73 | + |
|
| 74 | + /** |
|
| 75 | + * run - initial module setup |
|
| 76 | + * |
|
| 77 | + * @access public |
|
| 78 | + * @param \WP $WP |
|
| 79 | + */ |
|
| 80 | + public function run($WP) |
|
| 81 | + { |
|
| 82 | + // check what template is loaded |
|
| 83 | + add_filter('template_include', array($this, 'template_include'), 999, 1); |
|
| 84 | + add_action('wp_enqueue_scripts', array($this, 'wp_enqueue_scripts'), 10); |
|
| 85 | + } |
|
| 86 | + |
|
| 87 | + |
|
| 88 | + /** |
|
| 89 | + * template_include |
|
| 90 | + * |
|
| 91 | + * @access public |
|
| 92 | + * @param string $template |
|
| 93 | + * @return string |
|
| 94 | + */ |
|
| 95 | + public function template_include($template) |
|
| 96 | + { |
|
| 97 | + // not a custom template? |
|
| 98 | + if (EE_Registry::instance()->load_core('Front_Controller', array(), false, true) |
|
| 99 | + ->get_selected_template() != 'archive-espresso_venues.php' |
|
| 100 | + ) { |
|
| 101 | + EEH_Template::load_espresso_theme_functions(); |
|
| 102 | + // then add extra event data via hooks |
|
| 103 | + add_filter('the_title', array($this, 'the_title'), 100, 1); |
|
| 104 | + // don't know if theme uses the_excerpt |
|
| 105 | + add_filter('the_excerpt', array($this, 'venue_details'), 100); |
|
| 106 | + // or the_content |
|
| 107 | + add_filter('the_content', array($this, 'venue_details'), 100); |
|
| 108 | + // don't display entry meta because the existing theme will take care of that |
|
| 109 | + add_filter('FHEE__content_espresso_venues_details_template__display_entry_meta', '__return_false'); |
|
| 110 | + } |
|
| 111 | + return $template; |
|
| 112 | + } |
|
| 113 | + |
|
| 114 | + |
|
| 115 | + /** |
|
| 116 | + * the_title |
|
| 117 | + * |
|
| 118 | + * @access public |
|
| 119 | + * @param string $title |
|
| 120 | + * @return string |
|
| 121 | + */ |
|
| 122 | + public function the_title($title = '') |
|
| 123 | + { |
|
| 124 | + return $title; |
|
| 125 | + } |
|
| 126 | + |
|
| 127 | + |
|
| 128 | + /** |
|
| 129 | + * venue_details |
|
| 130 | + * |
|
| 131 | + * @access public |
|
| 132 | + * @param string $content |
|
| 133 | + * @return string |
|
| 134 | + */ |
|
| 135 | + public function venue_details($content) |
|
| 136 | + { |
|
| 137 | + global $post; |
|
| 138 | + if ($post->post_type == 'espresso_venues' |
|
| 139 | + && ! post_password_required() |
|
| 140 | + ) { |
|
| 141 | + // since the 'content-espresso_venues-details.php' template might be used directly from within a theme, |
|
| 142 | + // it uses the_content() for displaying the $post->post_content |
|
| 143 | + // so in order to load a template that uses the_content() from within a callback being used to filter the_content(), |
|
| 144 | + // we need to first remove this callback from being applied to the_content() (otherwise it will recurse and blow up the interweb) |
|
| 145 | + remove_filter('the_excerpt', array($this, 'venue_details'), 100); |
|
| 146 | + remove_filter('the_content', array($this, 'venue_details'), 100); |
|
| 147 | + // add filters we want |
|
| 148 | + add_filter('the_content', array($this, 'venue_location'), 110); |
|
| 149 | + add_filter('the_excerpt', array($this, 'venue_location'), 110); |
|
| 150 | + // now load our template |
|
| 151 | + $template = EEH_Template::locate_template('content-espresso_venues-details.php'); |
|
| 152 | + // now add our filter back in, plus some others |
|
| 153 | + add_filter('the_excerpt', array($this, 'venue_details'), 100); |
|
| 154 | + add_filter('the_content', array($this, 'venue_details'), 100); |
|
| 155 | + // remove other filters we added so they won't get applied to the next post |
|
| 156 | + remove_filter('the_content', array($this, 'venue_location'), 110); |
|
| 157 | + remove_filter('the_excerpt', array($this, 'venue_location'), 110); |
|
| 158 | + // we're not returning the $content directly because the template we are loading uses the_content (or the_excerpt) |
|
| 159 | + } |
|
| 160 | + return ! empty($template) ? $template : $content; |
|
| 161 | + } |
|
| 162 | + |
|
| 163 | + |
|
| 164 | + /** |
|
| 165 | + * venue_location |
|
| 166 | + * |
|
| 167 | + * @access public |
|
| 168 | + * @param string $content |
|
| 169 | + * @return string |
|
| 170 | + */ |
|
| 171 | + public function venue_location($content) |
|
| 172 | + { |
|
| 173 | + return $content . EEH_Template::locate_template('content-espresso_venues-location.php'); |
|
| 174 | + } |
|
| 175 | + |
|
| 176 | + |
|
| 177 | + /** |
|
| 178 | + * wp_enqueue_scripts |
|
| 179 | + * |
|
| 180 | + * @access public |
|
| 181 | + * @return void |
|
| 182 | + */ |
|
| 183 | + public function wp_enqueue_scripts() |
|
| 184 | + { |
|
| 185 | + // get some style |
|
| 186 | + if (apply_filters('FHEE_enable_default_espresso_css', true) && is_archive()) { |
|
| 187 | + // first check theme folder |
|
| 188 | + if (is_readable(get_stylesheet_directory() . $this->theme . '/style.css')) { |
|
| 189 | + wp_register_style( |
|
| 190 | + $this->theme, |
|
| 191 | + get_stylesheet_directory_uri() . $this->theme . '/style.css', |
|
| 192 | + array('dashicons', 'espresso_default') |
|
| 193 | + ); |
|
| 194 | + } elseif (is_readable(EE_TEMPLATES . $this->theme . '/style.css')) { |
|
| 195 | + wp_register_style( |
|
| 196 | + $this->theme, |
|
| 197 | + EE_TEMPLATES_URL . $this->theme . '/style.css', |
|
| 198 | + array('dashicons', 'espresso_default') |
|
| 199 | + ); |
|
| 200 | + } |
|
| 201 | + wp_enqueue_style($this->theme); |
|
| 202 | + } |
|
| 203 | + } |
|
| 204 | 204 | } |
@@ -170,7 +170,7 @@ discard block |
||
| 170 | 170 | */ |
| 171 | 171 | public function venue_location($content) |
| 172 | 172 | { |
| 173 | - return $content . EEH_Template::locate_template('content-espresso_venues-location.php'); |
|
| 173 | + return $content.EEH_Template::locate_template('content-espresso_venues-location.php'); |
|
| 174 | 174 | } |
| 175 | 175 | |
| 176 | 176 | |
@@ -185,16 +185,16 @@ discard block |
||
| 185 | 185 | // get some style |
| 186 | 186 | if (apply_filters('FHEE_enable_default_espresso_css', true) && is_archive()) { |
| 187 | 187 | // first check theme folder |
| 188 | - if (is_readable(get_stylesheet_directory() . $this->theme . '/style.css')) { |
|
| 188 | + if (is_readable(get_stylesheet_directory().$this->theme.'/style.css')) { |
|
| 189 | 189 | wp_register_style( |
| 190 | 190 | $this->theme, |
| 191 | - get_stylesheet_directory_uri() . $this->theme . '/style.css', |
|
| 191 | + get_stylesheet_directory_uri().$this->theme.'/style.css', |
|
| 192 | 192 | array('dashicons', 'espresso_default') |
| 193 | 193 | ); |
| 194 | - } elseif (is_readable(EE_TEMPLATES . $this->theme . '/style.css')) { |
|
| 194 | + } elseif (is_readable(EE_TEMPLATES.$this->theme.'/style.css')) { |
|
| 195 | 195 | wp_register_style( |
| 196 | 196 | $this->theme, |
| 197 | - EE_TEMPLATES_URL . $this->theme . '/style.css', |
|
| 197 | + EE_TEMPLATES_URL.$this->theme.'/style.css', |
|
| 198 | 198 | array('dashicons', 'espresso_default') |
| 199 | 199 | ); |
| 200 | 200 | } |