@@ -157,9 +157,9 @@ |
||
157 | 157 | $aee = array_merge( $this->_default_addressee_data, $aee ); |
158 | 158 | |
159 | 159 | //make sure txn is set |
160 | - if (empty($aee['txn']) && $aee['reg_obj'] instanceof EE_Registration) { |
|
161 | - $aee['txn'] = $aee['reg_obj']->transaction(); |
|
162 | - } |
|
160 | + if (empty($aee['txn']) && $aee['reg_obj'] instanceof EE_Registration) { |
|
161 | + $aee['txn'] = $aee['reg_obj']->transaction(); |
|
162 | + } |
|
163 | 163 | |
164 | 164 | $addressee[] = new EE_Messages_Addressee( $aee ); |
165 | 165 | } |
@@ -22,10 +22,10 @@ discard block |
||
22 | 22 | |
23 | 23 | public function __construct() { |
24 | 24 | $this->name = 'newsletter'; |
25 | - $this->description = __( 'Batch message type messages are triggered manually by the admin for sending notifications to a selected group of recipients. This should only be used for more general notification type messages that contain information specific for the recipients. For "newsletter" type messages we recommend using an email list service like MailChimp, because sending non-related mail-outs to contacts increases the risk of your site domain getting added to spam lists, which will prevent messages getting to users.', 'event_espresso' ); |
|
25 | + $this->description = __('Batch message type messages are triggered manually by the admin for sending notifications to a selected group of recipients. This should only be used for more general notification type messages that contain information specific for the recipients. For "newsletter" type messages we recommend using an email list service like MailChimp, because sending non-related mail-outs to contacts increases the risk of your site domain getting added to spam lists, which will prevent messages getting to users.', 'event_espresso'); |
|
26 | 26 | $this->label = array( |
27 | - 'singular' => __( 'batch', 'event_espresso' ), |
|
28 | - 'plural' => __( 'batches', 'event_espresso' ) |
|
27 | + 'singular' => __('batch', 'event_espresso'), |
|
28 | + 'plural' => __('batches', 'event_espresso') |
|
29 | 29 | ); |
30 | 30 | $this->_master_templates = array( |
31 | 31 | 'email' => 'registration', |
@@ -49,9 +49,9 @@ discard block |
||
49 | 49 | |
50 | 50 | |
51 | 51 | |
52 | - protected function _get_data_for_context( $context, EE_Registration $registration, $id ) { |
|
52 | + protected function _get_data_for_context($context, EE_Registration $registration, $id) { |
|
53 | 53 | //newsletter message type data handler is 'Registrations' and it expects an array of EE_Registration objects. |
54 | - return array( $registration ); |
|
54 | + return array($registration); |
|
55 | 55 | } |
56 | 56 | |
57 | 57 | |
@@ -64,15 +64,15 @@ discard block |
||
64 | 64 | |
65 | 65 | protected function _set_contexts() { |
66 | 66 | $this->_context_label = array( |
67 | - 'label' => __( 'recipient', 'event_espresso' ), |
|
68 | - 'plural' => __( 'recipients', 'event_espresso' ), |
|
69 | - 'description' => __( 'Recipient\'s are who will receive the message.', 'event_espresso' ) |
|
67 | + 'label' => __('recipient', 'event_espresso'), |
|
68 | + 'plural' => __('recipients', 'event_espresso'), |
|
69 | + 'description' => __('Recipient\'s are who will receive the message.', 'event_espresso') |
|
70 | 70 | ); |
71 | 71 | |
72 | 72 | $this->_contexts = array( |
73 | 73 | 'attendee' => array( |
74 | - 'label' => __( 'Registrant', 'event_espresso' ), |
|
75 | - 'description' => __( 'This template goes to selected registrants.', 'event_espresso' ) |
|
74 | + 'label' => __('Registrant', 'event_espresso'), |
|
75 | + 'description' => __('This template goes to selected registrants.', 'event_espresso') |
|
76 | 76 | ) |
77 | 77 | ); |
78 | 78 | } |
@@ -98,13 +98,13 @@ discard block |
||
98 | 98 | 'newsletter', |
99 | 99 | ); |
100 | 100 | |
101 | - foreach ( $this->_valid_shortcodes as $context => $shortcodes ) { |
|
102 | - foreach ( $shortcodes as $key => $shortcode ) { |
|
103 | - if ( ! in_array( $shortcode, $included_shortcodes ) ) { |
|
104 | - unset( $this->_valid_shortcodes[ $context ][ $key ] ); |
|
101 | + foreach ($this->_valid_shortcodes as $context => $shortcodes) { |
|
102 | + foreach ($shortcodes as $key => $shortcode) { |
|
103 | + if ( ! in_array($shortcode, $included_shortcodes)) { |
|
104 | + unset($this->_valid_shortcodes[$context][$key]); |
|
105 | 105 | } |
106 | 106 | } |
107 | - $this->_valid_shortcodes[ $context ][] = 'newsletter'; |
|
107 | + $this->_valid_shortcodes[$context][] = 'newsletter'; |
|
108 | 108 | } |
109 | 109 | |
110 | 110 | } |
@@ -118,50 +118,50 @@ discard block |
||
118 | 118 | $addressee = array(); |
119 | 119 | |
120 | 120 | //looping through registrations |
121 | - foreach ( $this->_data->registrations as $reg_id => $details ) { |
|
121 | + foreach ($this->_data->registrations as $reg_id => $details) { |
|
122 | 122 | //set $attendee array to blank on each loop |
123 | 123 | $aee = array(); |
124 | 124 | |
125 | 125 | //need to get the attendee from this registration. |
126 | - $attendee = isset( $details['att_obj'] ) && $details['att_obj'] instanceof EE_Attendee |
|
126 | + $attendee = isset($details['att_obj']) && $details['att_obj'] instanceof EE_Attendee |
|
127 | 127 | ? $details['att_obj'] |
128 | 128 | : null; |
129 | 129 | |
130 | - if ( ! $attendee instanceof EE_Attendee ) { |
|
130 | + if ( ! $attendee instanceof EE_Attendee) { |
|
131 | 131 | continue; |
132 | 132 | } |
133 | 133 | |
134 | 134 | //set $aee from attendee object |
135 | 135 | $aee['att_obj'] = $attendee; |
136 | - $aee['reg_objs'] = isset( $this->_data->attendees[ $attendee->ID() ]['reg_objs'] ) |
|
137 | - ? $this->_data->attendees[ $attendee->ID() ]['reg_objs'] |
|
136 | + $aee['reg_objs'] = isset($this->_data->attendees[$attendee->ID()]['reg_objs']) |
|
137 | + ? $this->_data->attendees[$attendee->ID()]['reg_objs'] |
|
138 | 138 | : array(); |
139 | 139 | $aee['attendee_email'] = $attendee->email(); |
140 | - $aee['tkt_objs'] = isset( $this->_data->attendees[ $attendee->ID() ]['tkt_objs'] ) |
|
141 | - ? $this->_data->attendees[ $attendee->ID() ]['tkt_objs'] |
|
140 | + $aee['tkt_objs'] = isset($this->_data->attendees[$attendee->ID()]['tkt_objs']) |
|
141 | + ? $this->_data->attendees[$attendee->ID()]['tkt_objs'] |
|
142 | 142 | : array(); |
143 | 143 | |
144 | - if ( isset( $this->_data->attendees[ $attendee->ID() ]['evt_objs'] ) ) { |
|
145 | - $aee['evt_objs'] = $this->_data->attendees[ $attendee->ID() ]['evt_objs']; |
|
146 | - $aee['events'] = $this->_data->attendees[ $attendee->ID() ]['evt_objs']; |
|
144 | + if (isset($this->_data->attendees[$attendee->ID()]['evt_objs'])) { |
|
145 | + $aee['evt_objs'] = $this->_data->attendees[$attendee->ID()]['evt_objs']; |
|
146 | + $aee['events'] = $this->_data->attendees[$attendee->ID()]['evt_objs']; |
|
147 | 147 | } else { |
148 | 148 | $aee['evt_objs'] = $aee['events'] = array(); |
149 | 149 | } |
150 | 150 | |
151 | - $aee['reg_obj'] = isset( $details['reg_obj'] ) |
|
151 | + $aee['reg_obj'] = isset($details['reg_obj']) |
|
152 | 152 | ? $details['reg_obj'] |
153 | 153 | : null; |
154 | 154 | $aee['attendees'] = $this->_data->attendees; |
155 | 155 | |
156 | 156 | //merge in the primary attendee data |
157 | - $aee = array_merge( $this->_default_addressee_data, $aee ); |
|
157 | + $aee = array_merge($this->_default_addressee_data, $aee); |
|
158 | 158 | |
159 | 159 | //make sure txn is set |
160 | 160 | if (empty($aee['txn']) && $aee['reg_obj'] instanceof EE_Registration) { |
161 | 161 | $aee['txn'] = $aee['reg_obj']->transaction(); |
162 | 162 | } |
163 | 163 | |
164 | - $addressee[] = new EE_Messages_Addressee( $aee ); |
|
164 | + $addressee[] = new EE_Messages_Addressee($aee); |
|
165 | 165 | } |
166 | 166 | return $addressee; |
167 | 167 | } |
@@ -16,1105 +16,1105 @@ |
||
16 | 16 | class EED_Messages extends EED_Module |
17 | 17 | { |
18 | 18 | |
19 | - /** |
|
20 | - * This holds the EE_messages controller |
|
21 | - * |
|
22 | - * @deprecated 4.9.0 |
|
23 | - * @var EE_messages $_EEMSG |
|
24 | - */ |
|
25 | - protected static $_EEMSG; |
|
26 | - |
|
27 | - /** |
|
28 | - * @type EE_Message_Resource_Manager $_message_resource_manager |
|
29 | - */ |
|
30 | - protected static $_message_resource_manager; |
|
31 | - |
|
32 | - /** |
|
33 | - * This holds the EE_Messages_Processor business class. |
|
34 | - * |
|
35 | - * @type EE_Messages_Processor |
|
36 | - */ |
|
37 | - protected static $_MSG_PROCESSOR; |
|
38 | - |
|
39 | - /** |
|
40 | - * holds all the paths for various messages components. |
|
41 | - * Utilized by autoloader registry |
|
42 | - * |
|
43 | - * @var array |
|
44 | - */ |
|
45 | - protected static $_MSG_PATHS; |
|
46 | - |
|
47 | - |
|
48 | - /** |
|
49 | - * This will hold an array of messages template packs that are registered in the messages system. |
|
50 | - * Format is: |
|
51 | - * array( |
|
52 | - * 'template_pack_dbref' => EE_Messages_Template_Pack (instance) |
|
53 | - * ) |
|
54 | - * |
|
55 | - * @var EE_Messages_Template_Pack[] |
|
56 | - */ |
|
57 | - protected static $_TMP_PACKS = array(); |
|
58 | - |
|
59 | - |
|
60 | - /** |
|
61 | - * @return EED_Messages |
|
62 | - */ |
|
63 | - public static function instance() |
|
64 | - { |
|
65 | - return parent::get_instance(__CLASS__); |
|
66 | - } |
|
67 | - |
|
68 | - |
|
69 | - /** |
|
70 | - * set_hooks - for hooking into EE Core, other modules, etc |
|
71 | - * |
|
72 | - * @since 4.5.0 |
|
73 | - * @return void |
|
74 | - */ |
|
75 | - public static function set_hooks() |
|
76 | - { |
|
77 | - //actions |
|
78 | - add_action('AHEE__EE_Payment_Processor__update_txn_based_on_payment', array('EED_Messages', 'payment'), 10, 2); |
|
79 | - add_action('AHEE__EE_Registration_Processor__trigger_registration_update_notifications', |
|
80 | - array('EED_Messages', 'maybe_registration'), 10, 2); |
|
81 | - //filters |
|
82 | - add_filter('FHEE__EE_Registration__receipt_url__receipt_url', |
|
83 | - array('EED_Messages', 'registration_message_trigger_url'), 10, 4); |
|
84 | - add_filter('FHEE__EE_Registration__invoice_url__invoice_url', |
|
85 | - array('EED_Messages', 'registration_message_trigger_url'), 10, 4); |
|
86 | - //register routes |
|
87 | - self::_register_routes(); |
|
88 | - } |
|
89 | - |
|
90 | - /** |
|
91 | - * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
92 | - * |
|
93 | - * @access public |
|
94 | - * @return void |
|
95 | - */ |
|
96 | - public static function set_hooks_admin() |
|
97 | - { |
|
98 | - //actions |
|
99 | - add_action('AHEE__EE_Payment_Processor__update_txn_based_on_payment', array('EED_Messages', 'payment'), 10, 2); |
|
100 | - add_action('AHEE__Transactions_Admin_Page___send_payment_reminder__process_admin_payment_reminder', |
|
101 | - array('EED_Messages', 'payment_reminder'), 10); |
|
102 | - add_action('AHEE__EE_Registration_Processor__trigger_registration_update_notifications', |
|
103 | - array('EED_Messages', 'maybe_registration'), 10, 3); |
|
104 | - add_action('AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send__with_registrations', |
|
105 | - array('EED_Messages', 'send_newsletter_message'), 10, 2); |
|
106 | - add_action('AHEE__EES_Espresso_Cancelled__process_shortcode__transaction', |
|
107 | - array('EED_Messages', 'cancelled_registration'), 10); |
|
108 | - add_action('AHEE__EE_Admin_Page___process_admin_payment_notification', |
|
109 | - array('EED_Messages', 'process_admin_payment'), 10, 1); |
|
110 | - //filters |
|
111 | - add_filter('FHEE__EE_Admin_Page___process_resend_registration__success', |
|
112 | - array('EED_Messages', 'process_resend'), 10, 2); |
|
113 | - add_filter('FHEE__EE_Registration__receipt_url__receipt_url', |
|
114 | - array('EED_Messages', 'registration_message_trigger_url'), 10, 4); |
|
115 | - add_filter('FHEE__EE_Registration__invoice_url__invoice_url', |
|
116 | - array('EED_Messages', 'registration_message_trigger_url'), 10, 4); |
|
117 | - } |
|
118 | - |
|
119 | - |
|
120 | - /** |
|
121 | - * All the message triggers done by route go in here. |
|
122 | - * |
|
123 | - * @since 4.5.0 |
|
124 | - * @return void |
|
125 | - */ |
|
126 | - protected static function _register_routes() |
|
127 | - { |
|
128 | - EE_Config::register_route('msg_url_trigger', 'Messages', 'run'); |
|
129 | - EE_Config::register_route('msg_cron_trigger', 'Messages', 'execute_batch_request'); |
|
130 | - EE_Config::register_route('msg_browser_trigger', 'Messages', 'browser_trigger'); |
|
131 | - EE_Config::register_route('msg_browser_error_trigger', 'Messages', 'browser_error_trigger'); |
|
132 | - do_action('AHEE__EED_Messages___register_routes'); |
|
133 | - } |
|
134 | - |
|
135 | - |
|
136 | - /** |
|
137 | - * This is called when a browser display trigger is executed. |
|
138 | - * The browser display trigger is typically used when a already generated message is displayed directly in the |
|
139 | - * browser. |
|
140 | - * |
|
141 | - * @since 4.9.0 |
|
142 | - * @param WP $WP |
|
143 | - */ |
|
144 | - public function browser_trigger($WP) |
|
145 | - { |
|
146 | - //ensure controller is loaded |
|
147 | - self::_load_controller(); |
|
148 | - $token = EE_Registry::instance()->REQ->get('token'); |
|
149 | - try { |
|
150 | - $mtg = new EE_Message_Generated_From_Token($token, 'html', self::$_message_resource_manager); |
|
151 | - self::$_MSG_PROCESSOR->generate_and_send_now($mtg); |
|
152 | - } catch (EE_Error $e) { |
|
153 | - $error_msg = __('Please note that a system message failed to send due to a technical issue.', |
|
154 | - 'event_espresso'); |
|
155 | - // add specific message for developers if WP_DEBUG in on |
|
156 | - $error_msg .= '||' . $e->getMessage(); |
|
157 | - EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__); |
|
158 | - } |
|
159 | - } |
|
160 | - |
|
161 | - |
|
162 | - /** |
|
163 | - * This is called when a browser error trigger is executed. |
|
164 | - * When triggered this will grab the EE_Message matching the token in the request and use that to get the error |
|
165 | - * message and display it. |
|
166 | - * |
|
167 | - * @since 4.9.0 |
|
168 | - * @param $WP |
|
169 | - */ |
|
170 | - public function browser_error_trigger($WP) |
|
171 | - { |
|
172 | - $token = EE_Registry::instance()->REQ->get('token'); |
|
173 | - if ($token) { |
|
174 | - $message = EEM_Message::instance()->get_one_by_token($token); |
|
175 | - if ($message instanceof EE_Message) { |
|
176 | - header('HTTP/1.1 200 OK'); |
|
177 | - $error_msg = nl2br($message->error_message()); |
|
178 | - ?> |
|
19 | + /** |
|
20 | + * This holds the EE_messages controller |
|
21 | + * |
|
22 | + * @deprecated 4.9.0 |
|
23 | + * @var EE_messages $_EEMSG |
|
24 | + */ |
|
25 | + protected static $_EEMSG; |
|
26 | + |
|
27 | + /** |
|
28 | + * @type EE_Message_Resource_Manager $_message_resource_manager |
|
29 | + */ |
|
30 | + protected static $_message_resource_manager; |
|
31 | + |
|
32 | + /** |
|
33 | + * This holds the EE_Messages_Processor business class. |
|
34 | + * |
|
35 | + * @type EE_Messages_Processor |
|
36 | + */ |
|
37 | + protected static $_MSG_PROCESSOR; |
|
38 | + |
|
39 | + /** |
|
40 | + * holds all the paths for various messages components. |
|
41 | + * Utilized by autoloader registry |
|
42 | + * |
|
43 | + * @var array |
|
44 | + */ |
|
45 | + protected static $_MSG_PATHS; |
|
46 | + |
|
47 | + |
|
48 | + /** |
|
49 | + * This will hold an array of messages template packs that are registered in the messages system. |
|
50 | + * Format is: |
|
51 | + * array( |
|
52 | + * 'template_pack_dbref' => EE_Messages_Template_Pack (instance) |
|
53 | + * ) |
|
54 | + * |
|
55 | + * @var EE_Messages_Template_Pack[] |
|
56 | + */ |
|
57 | + protected static $_TMP_PACKS = array(); |
|
58 | + |
|
59 | + |
|
60 | + /** |
|
61 | + * @return EED_Messages |
|
62 | + */ |
|
63 | + public static function instance() |
|
64 | + { |
|
65 | + return parent::get_instance(__CLASS__); |
|
66 | + } |
|
67 | + |
|
68 | + |
|
69 | + /** |
|
70 | + * set_hooks - for hooking into EE Core, other modules, etc |
|
71 | + * |
|
72 | + * @since 4.5.0 |
|
73 | + * @return void |
|
74 | + */ |
|
75 | + public static function set_hooks() |
|
76 | + { |
|
77 | + //actions |
|
78 | + add_action('AHEE__EE_Payment_Processor__update_txn_based_on_payment', array('EED_Messages', 'payment'), 10, 2); |
|
79 | + add_action('AHEE__EE_Registration_Processor__trigger_registration_update_notifications', |
|
80 | + array('EED_Messages', 'maybe_registration'), 10, 2); |
|
81 | + //filters |
|
82 | + add_filter('FHEE__EE_Registration__receipt_url__receipt_url', |
|
83 | + array('EED_Messages', 'registration_message_trigger_url'), 10, 4); |
|
84 | + add_filter('FHEE__EE_Registration__invoice_url__invoice_url', |
|
85 | + array('EED_Messages', 'registration_message_trigger_url'), 10, 4); |
|
86 | + //register routes |
|
87 | + self::_register_routes(); |
|
88 | + } |
|
89 | + |
|
90 | + /** |
|
91 | + * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
92 | + * |
|
93 | + * @access public |
|
94 | + * @return void |
|
95 | + */ |
|
96 | + public static function set_hooks_admin() |
|
97 | + { |
|
98 | + //actions |
|
99 | + add_action('AHEE__EE_Payment_Processor__update_txn_based_on_payment', array('EED_Messages', 'payment'), 10, 2); |
|
100 | + add_action('AHEE__Transactions_Admin_Page___send_payment_reminder__process_admin_payment_reminder', |
|
101 | + array('EED_Messages', 'payment_reminder'), 10); |
|
102 | + add_action('AHEE__EE_Registration_Processor__trigger_registration_update_notifications', |
|
103 | + array('EED_Messages', 'maybe_registration'), 10, 3); |
|
104 | + add_action('AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send__with_registrations', |
|
105 | + array('EED_Messages', 'send_newsletter_message'), 10, 2); |
|
106 | + add_action('AHEE__EES_Espresso_Cancelled__process_shortcode__transaction', |
|
107 | + array('EED_Messages', 'cancelled_registration'), 10); |
|
108 | + add_action('AHEE__EE_Admin_Page___process_admin_payment_notification', |
|
109 | + array('EED_Messages', 'process_admin_payment'), 10, 1); |
|
110 | + //filters |
|
111 | + add_filter('FHEE__EE_Admin_Page___process_resend_registration__success', |
|
112 | + array('EED_Messages', 'process_resend'), 10, 2); |
|
113 | + add_filter('FHEE__EE_Registration__receipt_url__receipt_url', |
|
114 | + array('EED_Messages', 'registration_message_trigger_url'), 10, 4); |
|
115 | + add_filter('FHEE__EE_Registration__invoice_url__invoice_url', |
|
116 | + array('EED_Messages', 'registration_message_trigger_url'), 10, 4); |
|
117 | + } |
|
118 | + |
|
119 | + |
|
120 | + /** |
|
121 | + * All the message triggers done by route go in here. |
|
122 | + * |
|
123 | + * @since 4.5.0 |
|
124 | + * @return void |
|
125 | + */ |
|
126 | + protected static function _register_routes() |
|
127 | + { |
|
128 | + EE_Config::register_route('msg_url_trigger', 'Messages', 'run'); |
|
129 | + EE_Config::register_route('msg_cron_trigger', 'Messages', 'execute_batch_request'); |
|
130 | + EE_Config::register_route('msg_browser_trigger', 'Messages', 'browser_trigger'); |
|
131 | + EE_Config::register_route('msg_browser_error_trigger', 'Messages', 'browser_error_trigger'); |
|
132 | + do_action('AHEE__EED_Messages___register_routes'); |
|
133 | + } |
|
134 | + |
|
135 | + |
|
136 | + /** |
|
137 | + * This is called when a browser display trigger is executed. |
|
138 | + * The browser display trigger is typically used when a already generated message is displayed directly in the |
|
139 | + * browser. |
|
140 | + * |
|
141 | + * @since 4.9.0 |
|
142 | + * @param WP $WP |
|
143 | + */ |
|
144 | + public function browser_trigger($WP) |
|
145 | + { |
|
146 | + //ensure controller is loaded |
|
147 | + self::_load_controller(); |
|
148 | + $token = EE_Registry::instance()->REQ->get('token'); |
|
149 | + try { |
|
150 | + $mtg = new EE_Message_Generated_From_Token($token, 'html', self::$_message_resource_manager); |
|
151 | + self::$_MSG_PROCESSOR->generate_and_send_now($mtg); |
|
152 | + } catch (EE_Error $e) { |
|
153 | + $error_msg = __('Please note that a system message failed to send due to a technical issue.', |
|
154 | + 'event_espresso'); |
|
155 | + // add specific message for developers if WP_DEBUG in on |
|
156 | + $error_msg .= '||' . $e->getMessage(); |
|
157 | + EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__); |
|
158 | + } |
|
159 | + } |
|
160 | + |
|
161 | + |
|
162 | + /** |
|
163 | + * This is called when a browser error trigger is executed. |
|
164 | + * When triggered this will grab the EE_Message matching the token in the request and use that to get the error |
|
165 | + * message and display it. |
|
166 | + * |
|
167 | + * @since 4.9.0 |
|
168 | + * @param $WP |
|
169 | + */ |
|
170 | + public function browser_error_trigger($WP) |
|
171 | + { |
|
172 | + $token = EE_Registry::instance()->REQ->get('token'); |
|
173 | + if ($token) { |
|
174 | + $message = EEM_Message::instance()->get_one_by_token($token); |
|
175 | + if ($message instanceof EE_Message) { |
|
176 | + header('HTTP/1.1 200 OK'); |
|
177 | + $error_msg = nl2br($message->error_message()); |
|
178 | + ?> |
|
179 | 179 | <!DOCTYPE html> |
180 | 180 | <html> |
181 | 181 | <head></head> |
182 | 182 | <body> |
183 | 183 | <?php echo empty($error_msg) |
184 | - ? esc_html__('Unfortunately, we were unable to capture the error message for this message.', |
|
185 | - 'event_espresso') |
|
186 | - : wp_kses( |
|
187 | - $error_msg, |
|
188 | - array( |
|
189 | - 'a' => array( |
|
190 | - 'href' => array(), |
|
191 | - 'title' => array(), |
|
192 | - ), |
|
193 | - 'span' => array(), |
|
194 | - 'div' => array(), |
|
195 | - 'p' => array(), |
|
196 | - 'strong' => array(), |
|
197 | - 'em' => array(), |
|
198 | - 'br' => array(), |
|
199 | - ) |
|
200 | - ); ?> |
|
184 | + ? esc_html__('Unfortunately, we were unable to capture the error message for this message.', |
|
185 | + 'event_espresso') |
|
186 | + : wp_kses( |
|
187 | + $error_msg, |
|
188 | + array( |
|
189 | + 'a' => array( |
|
190 | + 'href' => array(), |
|
191 | + 'title' => array(), |
|
192 | + ), |
|
193 | + 'span' => array(), |
|
194 | + 'div' => array(), |
|
195 | + 'p' => array(), |
|
196 | + 'strong' => array(), |
|
197 | + 'em' => array(), |
|
198 | + 'br' => array(), |
|
199 | + ) |
|
200 | + ); ?> |
|
201 | 201 | </body> |
202 | 202 | </html> |
203 | 203 | <?php |
204 | - exit; |
|
205 | - } |
|
206 | - } |
|
207 | - return; |
|
208 | - } |
|
209 | - |
|
210 | - |
|
211 | - /** |
|
212 | - * This runs when the msg_url_trigger route has initiated. |
|
213 | - * |
|
214 | - * @since 4.5.0 |
|
215 | - * @param WP $WP |
|
216 | - * @throws EE_Error |
|
217 | - * @return void |
|
218 | - */ |
|
219 | - public function run($WP) |
|
220 | - { |
|
221 | - //ensure controller is loaded |
|
222 | - self::_load_controller(); |
|
223 | - // attempt to process message |
|
224 | - try { |
|
225 | - /** @type EE_Message_To_Generate_From_Request $message_to_generate */ |
|
226 | - $message_to_generate = EE_Registry::instance()->load_lib('Message_To_Generate_From_Request'); |
|
227 | - self::$_MSG_PROCESSOR->generate_and_send_now($message_to_generate); |
|
228 | - } catch (EE_Error $e) { |
|
229 | - $error_msg = __('Please note that a system message failed to send due to a technical issue.', |
|
230 | - 'event_espresso'); |
|
231 | - // add specific message for developers if WP_DEBUG in on |
|
232 | - $error_msg .= '||' . $e->getMessage(); |
|
233 | - EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__); |
|
234 | - } |
|
235 | - } |
|
236 | - |
|
237 | - |
|
238 | - /** |
|
239 | - * This is triggered by the 'msg_cron_trigger' route. |
|
240 | - * |
|
241 | - * @param WP $WP |
|
242 | - */ |
|
243 | - public function execute_batch_request($WP) |
|
244 | - { |
|
245 | - $this->run_cron(); |
|
246 | - header('HTTP/1.1 200 OK'); |
|
247 | - exit(); |
|
248 | - } |
|
249 | - |
|
250 | - |
|
251 | - /** |
|
252 | - * This gets executed on wp_cron jobs or when a batch request is initiated on its own separate non regular wp |
|
253 | - * request. |
|
254 | - */ |
|
255 | - public function run_cron() |
|
256 | - { |
|
257 | - self::_load_controller(); |
|
258 | - //get required vars |
|
259 | - $cron_type = EE_Registry::instance()->REQ->get('type'); |
|
260 | - $transient_key = EE_Registry::instance()->REQ->get('key'); |
|
261 | - |
|
262 | - //now let's verify transient, if not valid exit immediately |
|
263 | - if (! get_transient($transient_key)) { |
|
264 | - /** |
|
265 | - * trigger error so this gets in the error logs. This is important because it happens on a non-user request. |
|
266 | - */ |
|
267 | - trigger_error(esc_attr__('Invalid Request (Transient does not exist)', 'event_espresso')); |
|
268 | - } |
|
269 | - |
|
270 | - //if made it here, lets' delete the transient to keep the db clean |
|
271 | - delete_transient($transient_key); |
|
272 | - |
|
273 | - if (apply_filters('FHEE__EED_Messages__run_cron__use_wp_cron', true)) { |
|
274 | - |
|
275 | - $method = 'batch_' . $cron_type . '_from_queue'; |
|
276 | - if (method_exists(self::$_MSG_PROCESSOR, $method)) { |
|
277 | - self::$_MSG_PROCESSOR->$method(); |
|
278 | - } else { |
|
279 | - //no matching task |
|
280 | - /** |
|
281 | - * trigger error so this gets in the error logs. This is important because it happens on a non user request. |
|
282 | - */ |
|
283 | - trigger_error(esc_attr(sprintf(__('There is no task corresponding to this route %s', 'event_espresso'), |
|
284 | - $cron_type))); |
|
285 | - } |
|
286 | - } |
|
287 | - |
|
288 | - do_action('FHEE__EED_Messages__run_cron__end'); |
|
289 | - } |
|
290 | - |
|
291 | - |
|
292 | - /** |
|
293 | - * This is used to retrieve the template pack for the given name. |
|
294 | - * Retrieved packs are cached on the static $_TMP_PACKS array. If there is no class matching the given name then |
|
295 | - * the default template pack is returned. |
|
296 | - * |
|
297 | - * @deprecated 4.9.0 @see EEH_MSG_Template::get_template_pack() |
|
298 | - * @param string $template_pack_name This should correspond to the dbref of the template pack (which is also used |
|
299 | - * in generating the Pack class name). |
|
300 | - * @return EE_Messages_Template_Pack |
|
301 | - */ |
|
302 | - public static function get_template_pack($template_pack_name) |
|
303 | - { |
|
304 | - EE_Registry::instance()->load_helper('MSG_Template'); |
|
305 | - return EEH_MSG_Template::get_template_pack($template_pack_name); |
|
306 | - } |
|
307 | - |
|
308 | - |
|
309 | - /** |
|
310 | - * Retrieves an array of all template packs. |
|
311 | - * Array is in the format array( 'dbref' => EE_Messages_Template_Pack ) |
|
312 | - * |
|
313 | - * @deprecated 4.9.0 @see EEH_MSG_Template_Pack::get_template_pack_collection |
|
314 | - * @return EE_Messages_Template_Pack[] |
|
315 | - */ |
|
316 | - public static function get_template_packs() |
|
317 | - { |
|
318 | - EE_Registry::instance()->load_helper('MSG_Template'); |
|
319 | - |
|
320 | - //for backward compat, let's make sure this returns in the same format as originally. |
|
321 | - $template_pack_collection = EEH_MSG_Template::get_template_pack_collection(); |
|
322 | - $template_pack_collection->rewind(); |
|
323 | - $template_packs = array(); |
|
324 | - while ($template_pack_collection->valid()) { |
|
325 | - $template_packs[$template_pack_collection->current()->dbref] = $template_pack_collection->current(); |
|
326 | - $template_pack_collection->next(); |
|
327 | - } |
|
328 | - return $template_packs; |
|
329 | - } |
|
330 | - |
|
331 | - |
|
332 | - /** |
|
333 | - * This simply makes sure the autoloaders are registered for the EE_messages system. |
|
334 | - * |
|
335 | - * @since 4.5.0 |
|
336 | - * @return void |
|
337 | - */ |
|
338 | - public static function set_autoloaders() |
|
339 | - { |
|
340 | - if (empty(self::$_MSG_PATHS)) { |
|
341 | - self::_set_messages_paths(); |
|
342 | - foreach (self::$_MSG_PATHS as $path) { |
|
343 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder($path); |
|
344 | - } |
|
345 | - // add aliases |
|
346 | - EEH_Autoloader::add_alias('EE_messages', 'EE_messages'); |
|
347 | - EEH_Autoloader::add_alias('EE_messenger', 'EE_messenger'); |
|
348 | - } |
|
349 | - } |
|
350 | - |
|
351 | - |
|
352 | - /** |
|
353 | - * Take care of adding all the paths for the messages components to the $_MSG_PATHS property |
|
354 | - * for use by the Messages Autoloaders |
|
355 | - * |
|
356 | - * @since 4.5.0 |
|
357 | - * @return void. |
|
358 | - */ |
|
359 | - protected static function _set_messages_paths() |
|
360 | - { |
|
361 | - $dir_ref = array( |
|
362 | - 'messages/message_type', |
|
363 | - 'messages/messenger', |
|
364 | - 'messages/defaults', |
|
365 | - 'messages/defaults/email', |
|
366 | - 'messages/data_class', |
|
367 | - 'messages/validators', |
|
368 | - 'messages/validators/email', |
|
369 | - 'messages/validators/html', |
|
370 | - 'shortcodes', |
|
371 | - ); |
|
372 | - $paths = array(); |
|
373 | - foreach ($dir_ref as $index => $dir) { |
|
374 | - $paths[$index] = EE_LIBRARIES . $dir; |
|
375 | - } |
|
376 | - self::$_MSG_PATHS = apply_filters('FHEE__EED_Messages___set_messages_paths___MSG_PATHS', $paths); |
|
377 | - } |
|
378 | - |
|
379 | - |
|
380 | - /** |
|
381 | - * Takes care of loading dependencies |
|
382 | - * |
|
383 | - * @since 4.5.0 |
|
384 | - * @return void |
|
385 | - */ |
|
386 | - protected static function _load_controller() |
|
387 | - { |
|
388 | - if (! self::$_MSG_PROCESSOR instanceof EE_Messages_Processor) { |
|
389 | - EE_Registry::instance()->load_core('Request_Handler'); |
|
390 | - self::set_autoloaders(); |
|
391 | - self::$_EEMSG = EE_Registry::instance()->load_lib('messages'); |
|
392 | - self::$_MSG_PROCESSOR = EE_Registry::instance()->load_lib('Messages_Processor'); |
|
393 | - self::$_message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
394 | - } |
|
395 | - } |
|
396 | - |
|
397 | - |
|
398 | - /** |
|
399 | - * @param EE_Transaction $transaction |
|
400 | - */ |
|
401 | - public static function payment_reminder(EE_Transaction $transaction) |
|
402 | - { |
|
403 | - self::_load_controller(); |
|
404 | - $data = array($transaction, null); |
|
405 | - self::$_MSG_PROCESSOR->generate_for_all_active_messengers('payment_reminder', $data); |
|
406 | - } |
|
407 | - |
|
408 | - |
|
409 | - /** |
|
410 | - * Any messages triggers for after successful gateway payments should go in here. |
|
411 | - * |
|
412 | - * @param EE_Transaction object |
|
413 | - * @param EE_Payment object |
|
414 | - * @return void |
|
415 | - */ |
|
416 | - public static function payment(EE_Transaction $transaction, EE_Payment $payment) |
|
417 | - { |
|
418 | - self::_load_controller(); |
|
419 | - $data = array($transaction, $payment); |
|
420 | - EE_Registry::instance()->load_helper('MSG_Template'); |
|
421 | - $message_type = EEH_MSG_Template::convert_payment_status_to_message_type($payment->STS_ID()); |
|
422 | - //if payment amount is less than 0 then switch to payment_refund message type. |
|
423 | - $message_type = $payment->amount() < 0 ? 'payment_refund' : $message_type; |
|
424 | - self::$_MSG_PROCESSOR->generate_for_all_active_messengers($message_type, $data); |
|
425 | - } |
|
426 | - |
|
427 | - |
|
428 | - /** |
|
429 | - * @param EE_Transaction $transaction |
|
430 | - */ |
|
431 | - public static function cancelled_registration(EE_Transaction $transaction) |
|
432 | - { |
|
433 | - self::_load_controller(); |
|
434 | - $data = array($transaction, null); |
|
435 | - self::$_MSG_PROCESSOR->generate_for_all_active_messengers('cancelled_registration', $data); |
|
436 | - } |
|
437 | - |
|
438 | - |
|
439 | - |
|
440 | - /** |
|
441 | - * Trigger for Registration messages |
|
442 | - * Note that what registration message type is sent depends on what the reg status is for the registrations on the |
|
443 | - * incoming transaction. |
|
444 | - * |
|
445 | - * @param EE_Registration $registration |
|
446 | - * @param array $extra_details |
|
447 | - * @return void |
|
448 | - * @throws EE_Error |
|
449 | - * @throws EntityNotFoundException |
|
450 | - */ |
|
451 | - public static function maybe_registration(EE_Registration $registration, $extra_details = array()) |
|
452 | - { |
|
453 | - |
|
454 | - if (! self::_verify_registration_notification_send($registration, $extra_details)) { |
|
455 | - //no messages please |
|
456 | - return; |
|
457 | - } |
|
458 | - |
|
459 | - // get all non-trashed registrations so we make sure we send messages for the right status. |
|
460 | - $all_registrations = $registration->transaction()->registrations( |
|
461 | - array( |
|
462 | - array('REG_deleted' => false), |
|
463 | - 'order_by' => array( |
|
464 | - 'Event.EVT_name' => 'ASC', |
|
465 | - 'Attendee.ATT_lname' => 'ASC', |
|
466 | - 'Attendee.ATT_fname' => 'ASC' |
|
467 | - ) |
|
468 | - ) |
|
469 | - ); |
|
470 | - //cached array of statuses so we only trigger messages once per status. |
|
471 | - $statuses_sent = array(); |
|
472 | - self::_load_controller(); |
|
473 | - $mtgs = array(); |
|
474 | - |
|
475 | - //loop through registrations and trigger messages once per status. |
|
476 | - foreach ($all_registrations as $reg) { |
|
477 | - |
|
478 | - //already triggered? |
|
479 | - if (in_array($reg->status_ID(), $statuses_sent)) { |
|
480 | - continue; |
|
481 | - } |
|
482 | - |
|
483 | - $message_type = EEH_MSG_Template::convert_reg_status_to_message_type($reg->status_ID()); |
|
484 | - $mtgs = array_merge( |
|
485 | - $mtgs, |
|
486 | - self::$_MSG_PROCESSOR->setup_mtgs_for_all_active_messengers( |
|
487 | - $message_type, |
|
488 | - array($registration->transaction(), null, $reg->status_ID()) |
|
489 | - ) |
|
490 | - ); |
|
491 | - $statuses_sent[] = $reg->status_ID(); |
|
492 | - } |
|
493 | - |
|
494 | - if (count($statuses_sent) > 1) { |
|
495 | - $mtgs = array_merge( |
|
496 | - $mtgs, |
|
497 | - self::$_MSG_PROCESSOR->setup_mtgs_for_all_active_messengers( |
|
498 | - 'registration_summary', |
|
499 | - array($registration->transaction(), null) |
|
500 | - ) |
|
501 | - ); |
|
502 | - } |
|
503 | - |
|
504 | - //batch queue and initiate request |
|
505 | - self::$_MSG_PROCESSOR->batch_queue_for_generation_and_persist($mtgs); |
|
506 | - self::$_MSG_PROCESSOR->get_queue()->initiate_request_by_priority(); |
|
507 | - } |
|
508 | - |
|
509 | - |
|
510 | - /** |
|
511 | - * This is a helper method used to very whether a registration notification should be sent or |
|
512 | - * not. Prevents duplicate notifications going out for registration context notifications. |
|
513 | - * |
|
514 | - * @param EE_Registration $registration [description] |
|
515 | - * @param array $extra_details [description] |
|
516 | - * @return bool true = send away, false = nope halt the presses. |
|
517 | - */ |
|
518 | - protected static function _verify_registration_notification_send( |
|
519 | - EE_Registration $registration, |
|
520 | - $extra_details = array() |
|
521 | - ) { |
|
522 | - //self::log( |
|
523 | - // __CLASS__, __FUNCTION__, __LINE__, |
|
524 | - // $registration->transaction(), |
|
525 | - // array( '$extra_details' => $extra_details ) |
|
526 | - //); |
|
527 | - // currently only using this to send messages for the primary registrant |
|
528 | - if (! $registration->is_primary_registrant()) { |
|
529 | - return false; |
|
530 | - } |
|
531 | - // first we check if we're in admin and not doing front ajax |
|
532 | - if (is_admin() && ! EE_FRONT_AJAX) { |
|
533 | - //make sure appropriate admin params are set for sending messages |
|
534 | - if (empty($_REQUEST['txn_reg_status_change']['send_notifications']) || ! absint($_REQUEST['txn_reg_status_change']['send_notifications'])) { |
|
535 | - //no messages sent please. |
|
536 | - return false; |
|
537 | - } |
|
538 | - } else { |
|
539 | - // frontend request (either regular or via AJAX) |
|
540 | - // TXN is NOT finalized ? |
|
541 | - if (! isset($extra_details['finalized']) || $extra_details['finalized'] === false) { |
|
542 | - return false; |
|
543 | - } |
|
544 | - // return visit but nothing changed ??? |
|
545 | - if ( |
|
546 | - isset($extra_details['revisit'], $extra_details['status_updates']) && |
|
547 | - $extra_details['revisit'] && ! $extra_details['status_updates'] |
|
548 | - ) { |
|
549 | - return false; |
|
550 | - } |
|
551 | - // NOT sending messages && reg status is something other than "Not-Approved" |
|
552 | - if ( |
|
553 | - ! apply_filters('FHEE__EED_Messages___maybe_registration__deliver_notifications', false) && |
|
554 | - $registration->status_ID() !== EEM_Registration::status_id_not_approved |
|
555 | - ) { |
|
556 | - return false; |
|
557 | - } |
|
558 | - } |
|
559 | - // release the kraken |
|
560 | - return true; |
|
561 | - } |
|
562 | - |
|
563 | - |
|
564 | - /** |
|
565 | - * Simply returns an array indexed by Registration Status ID and the related message_type name associated with that |
|
566 | - * status id. |
|
567 | - * |
|
568 | - * @deprecated 4.9.0 Use EEH_MSG_Template::reg_status_to_message_type_array() |
|
569 | - * or EEH_MSG_Template::convert_reg_status_to_message_type |
|
570 | - * @param string $reg_status |
|
571 | - * @return array |
|
572 | - */ |
|
573 | - protected static function _get_reg_status_array($reg_status = '') |
|
574 | - { |
|
575 | - EE_Registry::instance()->load_helper('MSG_Template'); |
|
576 | - return EEH_MSG_Template::convert_reg_status_to_message_type($reg_status) |
|
577 | - ? EEH_MSG_Template::convert_reg_status_to_message_type($reg_status) |
|
578 | - : EEH_MSG_Template::reg_status_to_message_type_array(); |
|
579 | - } |
|
580 | - |
|
581 | - |
|
582 | - /** |
|
583 | - * Simply returns the payment message type for the given payment status. |
|
584 | - * |
|
585 | - * @deprecated 4.9.0 Use EEH_MSG_Template::payment_status_to_message_type_array |
|
586 | - * or EEH_MSG_Template::convert_payment_status_to_message_type |
|
587 | - * @param string $payment_status The payment status being matched. |
|
588 | - * @return string|bool The payment message type slug matching the status or false if no match. |
|
589 | - */ |
|
590 | - protected static function _get_payment_message_type($payment_status) |
|
591 | - { |
|
592 | - EE_Registry::instance()->load_helper('MSG_Template'); |
|
593 | - return EEH_MSG_Template::convert_payment_status_to_message_type($payment_status) |
|
594 | - ? EEH_MSG_Template::convert_payment_status_to_message_type($payment_status) |
|
595 | - : false; |
|
596 | - } |
|
597 | - |
|
598 | - |
|
599 | - /** |
|
600 | - * Message triggers for a resending already sent message(s) (via EE_Message list table) |
|
601 | - * |
|
602 | - * @access public |
|
603 | - * @param array $req_data This is the $_POST & $_GET data sent from EE_Admin Pages |
|
604 | - * @return bool success/fail |
|
605 | - */ |
|
606 | - public static function process_resend($req_data) |
|
607 | - { |
|
608 | - self::_load_controller(); |
|
609 | - |
|
610 | - //if $msgID in this request then skip to the new resend_message |
|
611 | - if (EE_Registry::instance()->REQ->get('MSG_ID')) { |
|
612 | - return self::resend_message(); |
|
613 | - } |
|
614 | - |
|
615 | - //make sure any incoming request data is set on the REQ so that it gets picked up later. |
|
616 | - $req_data = (array)$req_data; |
|
617 | - foreach ($req_data as $request_key => $request_value) { |
|
618 | - EE_Registry::instance()->REQ->set($request_key, $request_value); |
|
619 | - } |
|
620 | - |
|
621 | - if (! $messages_to_send = self::$_MSG_PROCESSOR->setup_messages_to_generate_from_registration_ids_in_request()) { |
|
622 | - return false; |
|
623 | - } |
|
624 | - |
|
625 | - try { |
|
626 | - self::$_MSG_PROCESSOR->batch_queue_for_generation_and_persist($messages_to_send); |
|
627 | - self::$_MSG_PROCESSOR->get_queue()->initiate_request_by_priority(); |
|
628 | - } catch (EE_Error $e) { |
|
629 | - EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
630 | - return false; |
|
631 | - } |
|
632 | - EE_Error::add_success( |
|
633 | - __('Messages have been successfully queued for generation and sending.', 'event_espresso') |
|
634 | - ); |
|
635 | - return true; //everything got queued. |
|
636 | - } |
|
637 | - |
|
638 | - |
|
639 | - /** |
|
640 | - * Message triggers for a resending already sent message(s) (via EE_Message list table) |
|
641 | - * |
|
642 | - * @return bool |
|
643 | - */ |
|
644 | - public static function resend_message() |
|
645 | - { |
|
646 | - self::_load_controller(); |
|
647 | - |
|
648 | - $msgID = EE_Registry::instance()->REQ->get('MSG_ID'); |
|
649 | - if (! $msgID) { |
|
650 | - EE_Error::add_error(__('Something went wrong because there is no "MSG_ID" value in the request', |
|
651 | - 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
652 | - return false; |
|
653 | - } |
|
654 | - |
|
655 | - self::$_MSG_PROCESSOR->setup_messages_from_ids_and_send((array)$msgID); |
|
656 | - |
|
657 | - //setup success message. |
|
658 | - $count_ready_for_resend = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::status_resend); |
|
659 | - EE_Error::add_success(sprintf( |
|
660 | - _n( |
|
661 | - 'There was %d message queued for resending.', |
|
662 | - 'There were %d messages queued for resending.', |
|
663 | - $count_ready_for_resend, |
|
664 | - 'event_espresso' |
|
665 | - ), |
|
666 | - $count_ready_for_resend |
|
667 | - )); |
|
668 | - return true; |
|
669 | - } |
|
670 | - |
|
671 | - |
|
672 | - /** |
|
673 | - * Message triggers for manual payment applied by admin |
|
674 | - * |
|
675 | - * @param EE_Payment $payment EE_payment object |
|
676 | - * @return bool success/fail |
|
677 | - */ |
|
678 | - public static function process_admin_payment(EE_Payment $payment) |
|
679 | - { |
|
680 | - EE_Registry::instance()->load_helper('MSG_Template'); |
|
681 | - //we need to get the transaction object |
|
682 | - $transaction = $payment->transaction(); |
|
683 | - if ($transaction instanceof EE_Transaction) { |
|
684 | - $data = array($transaction, $payment); |
|
685 | - $message_type = EEH_MSG_Template::convert_payment_status_to_message_type($payment->STS_ID()); |
|
686 | - |
|
687 | - //if payment amount is less than 0 then switch to payment_refund message type. |
|
688 | - $message_type = $payment->amount() < 0 ? 'payment_refund' : $message_type; |
|
689 | - |
|
690 | - //if payment_refund is selected, but the status is NOT accepted. Then change message type to false so NO message notification goes out. |
|
691 | - $message_type = $message_type == 'payment_refund' && $payment->STS_ID() != EEM_Payment::status_id_approved ? false : $message_type; |
|
692 | - |
|
693 | - self::_load_controller(); |
|
694 | - |
|
695 | - self::$_MSG_PROCESSOR->generate_for_all_active_messengers($message_type, $data); |
|
696 | - |
|
697 | - //get count of queued for generation |
|
698 | - $count_to_generate = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(array( |
|
699 | - EEM_Message::status_incomplete, |
|
700 | - EEM_Message::status_idle, |
|
701 | - )); |
|
702 | - |
|
703 | - if ($count_to_generate > 0 && self::$_MSG_PROCESSOR->get_queue()->get_message_repository()->count() !== 0) { |
|
704 | - add_filter('FHEE__EE_Admin_Page___process_admin_payment_notification__success', '__return_true'); |
|
705 | - return true; |
|
706 | - } else { |
|
707 | - $count_failed = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::instance()->stati_indicating_failed_sending()); |
|
708 | - /** |
|
709 | - * Verify that there are actually errors. If not then we return a success message because the queue might have been emptied due to successful |
|
710 | - * IMMEDIATE generation. |
|
711 | - */ |
|
712 | - if ($count_failed > 0) { |
|
713 | - EE_Error::add_error(sprintf( |
|
714 | - _n( |
|
715 | - 'The payment notification generation failed.', |
|
716 | - '%d payment notifications failed being sent.', |
|
717 | - $count_failed, |
|
718 | - 'event_espresso' |
|
719 | - ), |
|
720 | - $count_failed |
|
721 | - ), __FILE__, __FUNCTION__, __LINE__); |
|
722 | - |
|
723 | - return false; |
|
724 | - } else { |
|
725 | - add_filter('FHEE__EE_Admin_Page___process_admin_payment_notification__success', '__return_true'); |
|
726 | - return true; |
|
727 | - } |
|
728 | - } |
|
729 | - } else { |
|
730 | - EE_Error::add_error( |
|
731 | - 'Unable to generate the payment notification because the given value for the transaction is invalid.', |
|
732 | - 'event_espresso' |
|
733 | - ); |
|
734 | - return false; |
|
735 | - } |
|
736 | - } |
|
737 | - |
|
738 | - |
|
739 | - /** |
|
740 | - * Callback for AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send_with_registrations trigger |
|
741 | - * |
|
742 | - * @since 4.3.0 |
|
743 | - * @param EE_Registration[] $registrations an array of EE_Registration objects |
|
744 | - * @param int $grp_id a specific message template group id. |
|
745 | - * @return void |
|
746 | - */ |
|
747 | - public static function send_newsletter_message($registrations, $grp_id) |
|
748 | - { |
|
749 | - //make sure mtp is id and set it in the EE_Request Handler later messages setup. |
|
750 | - EE_Registry::instance()->REQ->set('GRP_ID', (int)$grp_id); |
|
751 | - self::_load_controller(); |
|
752 | - self::$_MSG_PROCESSOR->generate_for_all_active_messengers('newsletter', $registrations); |
|
753 | - } |
|
754 | - |
|
755 | - |
|
756 | - /** |
|
757 | - * Callback for FHEE__EE_Registration__invoice_url__invoice_url or FHEE__EE_Registration__receipt_url__receipt_url |
|
758 | - * |
|
759 | - * @since 4.3.0 |
|
760 | - * @param string $registration_message_trigger_url |
|
761 | - * @param EE_Registration $registration |
|
762 | - * @param string $messenger |
|
763 | - * @param string $message_type |
|
764 | - * @return string |
|
765 | - */ |
|
766 | - public static function registration_message_trigger_url( |
|
767 | - $registration_message_trigger_url, |
|
768 | - EE_Registration $registration, |
|
769 | - $messenger = 'html', |
|
770 | - $message_type = 'invoice' |
|
771 | - ) { |
|
772 | - // whitelist $messenger |
|
773 | - switch ($messenger) { |
|
774 | - case 'pdf' : |
|
775 | - $sending_messenger = 'pdf'; |
|
776 | - $generating_messenger = 'html'; |
|
777 | - break; |
|
778 | - case 'html' : |
|
779 | - default : |
|
780 | - $sending_messenger = 'html'; |
|
781 | - $generating_messenger = 'html'; |
|
782 | - break; |
|
783 | - } |
|
784 | - // whitelist $message_type |
|
785 | - switch ($message_type) { |
|
786 | - case 'receipt' : |
|
787 | - $message_type = 'receipt'; |
|
788 | - break; |
|
789 | - case 'invoice' : |
|
790 | - default : |
|
791 | - $message_type = 'invoice'; |
|
792 | - break; |
|
793 | - } |
|
794 | - // verify that both the messenger AND the message type are active |
|
795 | - if (EEH_MSG_Template::is_messenger_active($sending_messenger) && EEH_MSG_Template::is_mt_active($message_type)) { |
|
796 | - //need to get the correct message template group for this (i.e. is there a custom invoice for the event this registration is registered for?) |
|
797 | - $template_query_params = array( |
|
798 | - 'MTP_is_active' => true, |
|
799 | - 'MTP_messenger' => $generating_messenger, |
|
800 | - 'MTP_message_type' => $message_type, |
|
801 | - 'Event.EVT_ID' => $registration->event_ID(), |
|
802 | - ); |
|
803 | - //get the message template group. |
|
804 | - $msg_template_group = EEM_Message_Template_Group::instance()->get_one(array($template_query_params)); |
|
805 | - //if we don't have an EE_Message_Template_Group then return |
|
806 | - if (! $msg_template_group instanceof EE_Message_Template_Group) { |
|
807 | - // remove EVT_ID from query params so that global templates get picked up |
|
808 | - unset($template_query_params['Event.EVT_ID']); |
|
809 | - //get global template as the fallback |
|
810 | - $msg_template_group = EEM_Message_Template_Group::instance()->get_one(array($template_query_params)); |
|
811 | - } |
|
812 | - //if we don't have an EE_Message_Template_Group then return |
|
813 | - if (! $msg_template_group instanceof EE_Message_Template_Group) { |
|
814 | - return ''; |
|
815 | - } |
|
816 | - // generate the URL |
|
817 | - $registration_message_trigger_url = EEH_MSG_Template::generate_url_trigger( |
|
818 | - $sending_messenger, |
|
819 | - $generating_messenger, |
|
820 | - 'purchaser', |
|
821 | - $message_type, |
|
822 | - $registration, |
|
823 | - $msg_template_group->ID(), |
|
824 | - $registration->transaction_ID() |
|
825 | - ); |
|
826 | - |
|
827 | - } |
|
828 | - return $registration_message_trigger_url; |
|
829 | - } |
|
830 | - |
|
831 | - |
|
832 | - /** |
|
833 | - * Use to generate and return a message preview! |
|
834 | - * |
|
835 | - * @param string $type This should correspond with a valid message type |
|
836 | - * @param string $context This should correspond with a valid context for the message type |
|
837 | - * @param string $messenger This should correspond with a valid messenger. |
|
838 | - * @param bool $send true we will do a test send using the messenger delivery, false we just do a regular |
|
839 | - * preview |
|
840 | - * @return bool|string The body of the message or if send is requested, sends. |
|
841 | - * @throws EE_Error |
|
842 | - */ |
|
843 | - public static function preview_message($type, $context, $messenger, $send = false) |
|
844 | - { |
|
845 | - self::_load_controller(); |
|
846 | - $mtg = new EE_Message_To_Generate( |
|
847 | - $messenger, |
|
848 | - $type, |
|
849 | - array(), |
|
850 | - $context, |
|
851 | - true |
|
852 | - ); |
|
853 | - $generated_preview_queue = self::$_MSG_PROCESSOR->generate_for_preview($mtg, $send); |
|
854 | - if ($generated_preview_queue instanceof EE_Messages_Queue) { |
|
855 | - //loop through all content for the preview and remove any persisted records. |
|
856 | - $content = ''; |
|
857 | - foreach ($generated_preview_queue->get_message_repository() as $message) { |
|
858 | - $content = $message->content(); |
|
859 | - if ($message->ID() > 0 && $message->STS_ID() !== EEM_Message::status_failed) { |
|
860 | - $message->delete(); |
|
861 | - } |
|
862 | - } |
|
863 | - return $content; |
|
864 | - } else { |
|
865 | - return $generated_preview_queue; |
|
866 | - } |
|
867 | - } |
|
868 | - |
|
869 | - |
|
870 | - /** |
|
871 | - * This is a method that allows for sending a message using a messenger matching the string given and the provided |
|
872 | - * EE_Message_Queue object. The EE_Message_Queue object is used to create a single aggregate EE_Message via the |
|
873 | - * content found in the EE_Message objects in the queue. |
|
874 | - * |
|
875 | - * @since 4.9.0 |
|
876 | - * @param string $messenger a string matching a valid active messenger in the system |
|
877 | - * @param string $message_type Although it seems contrary to the name of the method, a message |
|
878 | - * type name is still required to send along the message type to the |
|
879 | - * messenger because this is used for determining what specific |
|
880 | - * variations might be loaded for the generated message. |
|
881 | - * @param EE_Messages_Queue $queue |
|
882 | - * @param string $custom_subject Can be used to set what the custom subject string will be on the |
|
883 | - * aggregate EE_Message object. |
|
884 | - * @return bool success or fail. |
|
885 | - */ |
|
886 | - public static function send_message_with_messenger_only( |
|
887 | - $messenger, |
|
888 | - $message_type, |
|
889 | - EE_Messages_Queue $queue, |
|
890 | - $custom_subject = '' |
|
891 | - ) { |
|
892 | - self::_load_controller(); |
|
893 | - /** @type EE_Message_To_Generate_From_Queue $message_to_generate */ |
|
894 | - $message_to_generate = EE_Registry::instance()->load_lib( |
|
895 | - 'Message_To_Generate_From_Queue', |
|
896 | - array( |
|
897 | - $messenger, |
|
898 | - $message_type, |
|
899 | - $queue, |
|
900 | - $custom_subject, |
|
901 | - ) |
|
902 | - ); |
|
903 | - return self::$_MSG_PROCESSOR->queue_for_sending($message_to_generate); |
|
904 | - } |
|
905 | - |
|
906 | - |
|
907 | - /** |
|
908 | - * Generates Messages immediately for EE_Message IDs (but only for the correct status for generation) |
|
909 | - * |
|
910 | - * @since 4.9.0 |
|
911 | - * @param array $message_ids An array of message ids |
|
912 | - * @return bool | EE_Messages_Queue false if nothing was generated, EE_Messages_Queue containing generated |
|
913 | - * messages. |
|
914 | - */ |
|
915 | - public static function generate_now($message_ids) |
|
916 | - { |
|
917 | - self::_load_controller(); |
|
918 | - $messages = EEM_Message::instance()->get_all( |
|
919 | - array( |
|
920 | - 0 => array( |
|
921 | - 'MSG_ID' => array('IN', $message_ids), |
|
922 | - 'STS_ID' => EEM_Message::status_incomplete, |
|
923 | - ), |
|
924 | - ) |
|
925 | - ); |
|
926 | - $generated_queue = false; |
|
927 | - if ($messages) { |
|
928 | - $generated_queue = self::$_MSG_PROCESSOR->batch_generate_from_queue($messages); |
|
929 | - } |
|
930 | - |
|
931 | - if (! $generated_queue instanceof EE_Messages_Queue) { |
|
932 | - EE_Error::add_error( |
|
933 | - __('The messages were not generated. This could mean there is already a batch being generated on a separate request, or because the selected messages are not ready for generation. Please wait a minute or two and try again.', |
|
934 | - 'event_espresso'), |
|
935 | - __FILE__, __FUNCTION__, __LINE__ |
|
936 | - ); |
|
937 | - } |
|
938 | - return $generated_queue; |
|
939 | - } |
|
940 | - |
|
941 | - |
|
942 | - /** |
|
943 | - * Sends messages immediately for the incoming message_ids that have the status of EEM_Message::status_resend or, |
|
944 | - * EEM_Message::status_idle |
|
945 | - * |
|
946 | - * @since 4.9.0 |
|
947 | - * @param $message_ids |
|
948 | - * @return bool | EE_Messages_Queue false if no messages sent. |
|
949 | - */ |
|
950 | - public static function send_now($message_ids) |
|
951 | - { |
|
952 | - self::_load_controller(); |
|
953 | - $messages = EEM_Message::instance()->get_all( |
|
954 | - array( |
|
955 | - 0 => array( |
|
956 | - 'MSG_ID' => array('IN', $message_ids), |
|
957 | - 'STS_ID' => array( |
|
958 | - 'IN', |
|
959 | - array(EEM_Message::status_idle, EEM_Message::status_resend, EEM_Message::status_retry), |
|
960 | - ), |
|
961 | - ), |
|
962 | - ) |
|
963 | - ); |
|
964 | - $sent_queue = false; |
|
965 | - if ($messages) { |
|
966 | - $sent_queue = self::$_MSG_PROCESSOR->batch_send_from_queue($messages); |
|
967 | - } |
|
968 | - |
|
969 | - if (! $sent_queue instanceof EE_Messages_Queue) { |
|
970 | - EE_Error::add_error( |
|
971 | - __('The messages were not sent. This could mean there is already a batch being sent on a separate request, or because the selected messages are not sendable. Please wait a minute or two and try again.', |
|
972 | - 'event_espresso'), |
|
973 | - __FILE__, __FUNCTION__, __LINE__ |
|
974 | - ); |
|
975 | - } else { |
|
976 | - //can count how many sent by using the messages in the queue |
|
977 | - $sent_count = $sent_queue->count_STS_in_queue(EEM_Message::instance()->stati_indicating_sent()); |
|
978 | - if ($sent_count > 0) { |
|
979 | - EE_Error::add_success( |
|
980 | - sprintf( |
|
981 | - _n( |
|
982 | - 'There was %d message successfully sent.', |
|
983 | - 'There were %d messages successfully sent.', |
|
984 | - $sent_count, |
|
985 | - 'event_espresso' |
|
986 | - ), |
|
987 | - $sent_count |
|
988 | - ) |
|
989 | - ); |
|
990 | - } else { |
|
991 | - EE_Error::overwrite_errors(); |
|
992 | - EE_Error::add_error( |
|
993 | - __('No message was sent because of problems with sending. Either all the messages you selected were not a sendable message, they were ALREADY sent on a different scheduled task, or there was an error. |
|
204 | + exit; |
|
205 | + } |
|
206 | + } |
|
207 | + return; |
|
208 | + } |
|
209 | + |
|
210 | + |
|
211 | + /** |
|
212 | + * This runs when the msg_url_trigger route has initiated. |
|
213 | + * |
|
214 | + * @since 4.5.0 |
|
215 | + * @param WP $WP |
|
216 | + * @throws EE_Error |
|
217 | + * @return void |
|
218 | + */ |
|
219 | + public function run($WP) |
|
220 | + { |
|
221 | + //ensure controller is loaded |
|
222 | + self::_load_controller(); |
|
223 | + // attempt to process message |
|
224 | + try { |
|
225 | + /** @type EE_Message_To_Generate_From_Request $message_to_generate */ |
|
226 | + $message_to_generate = EE_Registry::instance()->load_lib('Message_To_Generate_From_Request'); |
|
227 | + self::$_MSG_PROCESSOR->generate_and_send_now($message_to_generate); |
|
228 | + } catch (EE_Error $e) { |
|
229 | + $error_msg = __('Please note that a system message failed to send due to a technical issue.', |
|
230 | + 'event_espresso'); |
|
231 | + // add specific message for developers if WP_DEBUG in on |
|
232 | + $error_msg .= '||' . $e->getMessage(); |
|
233 | + EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__); |
|
234 | + } |
|
235 | + } |
|
236 | + |
|
237 | + |
|
238 | + /** |
|
239 | + * This is triggered by the 'msg_cron_trigger' route. |
|
240 | + * |
|
241 | + * @param WP $WP |
|
242 | + */ |
|
243 | + public function execute_batch_request($WP) |
|
244 | + { |
|
245 | + $this->run_cron(); |
|
246 | + header('HTTP/1.1 200 OK'); |
|
247 | + exit(); |
|
248 | + } |
|
249 | + |
|
250 | + |
|
251 | + /** |
|
252 | + * This gets executed on wp_cron jobs or when a batch request is initiated on its own separate non regular wp |
|
253 | + * request. |
|
254 | + */ |
|
255 | + public function run_cron() |
|
256 | + { |
|
257 | + self::_load_controller(); |
|
258 | + //get required vars |
|
259 | + $cron_type = EE_Registry::instance()->REQ->get('type'); |
|
260 | + $transient_key = EE_Registry::instance()->REQ->get('key'); |
|
261 | + |
|
262 | + //now let's verify transient, if not valid exit immediately |
|
263 | + if (! get_transient($transient_key)) { |
|
264 | + /** |
|
265 | + * trigger error so this gets in the error logs. This is important because it happens on a non-user request. |
|
266 | + */ |
|
267 | + trigger_error(esc_attr__('Invalid Request (Transient does not exist)', 'event_espresso')); |
|
268 | + } |
|
269 | + |
|
270 | + //if made it here, lets' delete the transient to keep the db clean |
|
271 | + delete_transient($transient_key); |
|
272 | + |
|
273 | + if (apply_filters('FHEE__EED_Messages__run_cron__use_wp_cron', true)) { |
|
274 | + |
|
275 | + $method = 'batch_' . $cron_type . '_from_queue'; |
|
276 | + if (method_exists(self::$_MSG_PROCESSOR, $method)) { |
|
277 | + self::$_MSG_PROCESSOR->$method(); |
|
278 | + } else { |
|
279 | + //no matching task |
|
280 | + /** |
|
281 | + * trigger error so this gets in the error logs. This is important because it happens on a non user request. |
|
282 | + */ |
|
283 | + trigger_error(esc_attr(sprintf(__('There is no task corresponding to this route %s', 'event_espresso'), |
|
284 | + $cron_type))); |
|
285 | + } |
|
286 | + } |
|
287 | + |
|
288 | + do_action('FHEE__EED_Messages__run_cron__end'); |
|
289 | + } |
|
290 | + |
|
291 | + |
|
292 | + /** |
|
293 | + * This is used to retrieve the template pack for the given name. |
|
294 | + * Retrieved packs are cached on the static $_TMP_PACKS array. If there is no class matching the given name then |
|
295 | + * the default template pack is returned. |
|
296 | + * |
|
297 | + * @deprecated 4.9.0 @see EEH_MSG_Template::get_template_pack() |
|
298 | + * @param string $template_pack_name This should correspond to the dbref of the template pack (which is also used |
|
299 | + * in generating the Pack class name). |
|
300 | + * @return EE_Messages_Template_Pack |
|
301 | + */ |
|
302 | + public static function get_template_pack($template_pack_name) |
|
303 | + { |
|
304 | + EE_Registry::instance()->load_helper('MSG_Template'); |
|
305 | + return EEH_MSG_Template::get_template_pack($template_pack_name); |
|
306 | + } |
|
307 | + |
|
308 | + |
|
309 | + /** |
|
310 | + * Retrieves an array of all template packs. |
|
311 | + * Array is in the format array( 'dbref' => EE_Messages_Template_Pack ) |
|
312 | + * |
|
313 | + * @deprecated 4.9.0 @see EEH_MSG_Template_Pack::get_template_pack_collection |
|
314 | + * @return EE_Messages_Template_Pack[] |
|
315 | + */ |
|
316 | + public static function get_template_packs() |
|
317 | + { |
|
318 | + EE_Registry::instance()->load_helper('MSG_Template'); |
|
319 | + |
|
320 | + //for backward compat, let's make sure this returns in the same format as originally. |
|
321 | + $template_pack_collection = EEH_MSG_Template::get_template_pack_collection(); |
|
322 | + $template_pack_collection->rewind(); |
|
323 | + $template_packs = array(); |
|
324 | + while ($template_pack_collection->valid()) { |
|
325 | + $template_packs[$template_pack_collection->current()->dbref] = $template_pack_collection->current(); |
|
326 | + $template_pack_collection->next(); |
|
327 | + } |
|
328 | + return $template_packs; |
|
329 | + } |
|
330 | + |
|
331 | + |
|
332 | + /** |
|
333 | + * This simply makes sure the autoloaders are registered for the EE_messages system. |
|
334 | + * |
|
335 | + * @since 4.5.0 |
|
336 | + * @return void |
|
337 | + */ |
|
338 | + public static function set_autoloaders() |
|
339 | + { |
|
340 | + if (empty(self::$_MSG_PATHS)) { |
|
341 | + self::_set_messages_paths(); |
|
342 | + foreach (self::$_MSG_PATHS as $path) { |
|
343 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder($path); |
|
344 | + } |
|
345 | + // add aliases |
|
346 | + EEH_Autoloader::add_alias('EE_messages', 'EE_messages'); |
|
347 | + EEH_Autoloader::add_alias('EE_messenger', 'EE_messenger'); |
|
348 | + } |
|
349 | + } |
|
350 | + |
|
351 | + |
|
352 | + /** |
|
353 | + * Take care of adding all the paths for the messages components to the $_MSG_PATHS property |
|
354 | + * for use by the Messages Autoloaders |
|
355 | + * |
|
356 | + * @since 4.5.0 |
|
357 | + * @return void. |
|
358 | + */ |
|
359 | + protected static function _set_messages_paths() |
|
360 | + { |
|
361 | + $dir_ref = array( |
|
362 | + 'messages/message_type', |
|
363 | + 'messages/messenger', |
|
364 | + 'messages/defaults', |
|
365 | + 'messages/defaults/email', |
|
366 | + 'messages/data_class', |
|
367 | + 'messages/validators', |
|
368 | + 'messages/validators/email', |
|
369 | + 'messages/validators/html', |
|
370 | + 'shortcodes', |
|
371 | + ); |
|
372 | + $paths = array(); |
|
373 | + foreach ($dir_ref as $index => $dir) { |
|
374 | + $paths[$index] = EE_LIBRARIES . $dir; |
|
375 | + } |
|
376 | + self::$_MSG_PATHS = apply_filters('FHEE__EED_Messages___set_messages_paths___MSG_PATHS', $paths); |
|
377 | + } |
|
378 | + |
|
379 | + |
|
380 | + /** |
|
381 | + * Takes care of loading dependencies |
|
382 | + * |
|
383 | + * @since 4.5.0 |
|
384 | + * @return void |
|
385 | + */ |
|
386 | + protected static function _load_controller() |
|
387 | + { |
|
388 | + if (! self::$_MSG_PROCESSOR instanceof EE_Messages_Processor) { |
|
389 | + EE_Registry::instance()->load_core('Request_Handler'); |
|
390 | + self::set_autoloaders(); |
|
391 | + self::$_EEMSG = EE_Registry::instance()->load_lib('messages'); |
|
392 | + self::$_MSG_PROCESSOR = EE_Registry::instance()->load_lib('Messages_Processor'); |
|
393 | + self::$_message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
394 | + } |
|
395 | + } |
|
396 | + |
|
397 | + |
|
398 | + /** |
|
399 | + * @param EE_Transaction $transaction |
|
400 | + */ |
|
401 | + public static function payment_reminder(EE_Transaction $transaction) |
|
402 | + { |
|
403 | + self::_load_controller(); |
|
404 | + $data = array($transaction, null); |
|
405 | + self::$_MSG_PROCESSOR->generate_for_all_active_messengers('payment_reminder', $data); |
|
406 | + } |
|
407 | + |
|
408 | + |
|
409 | + /** |
|
410 | + * Any messages triggers for after successful gateway payments should go in here. |
|
411 | + * |
|
412 | + * @param EE_Transaction object |
|
413 | + * @param EE_Payment object |
|
414 | + * @return void |
|
415 | + */ |
|
416 | + public static function payment(EE_Transaction $transaction, EE_Payment $payment) |
|
417 | + { |
|
418 | + self::_load_controller(); |
|
419 | + $data = array($transaction, $payment); |
|
420 | + EE_Registry::instance()->load_helper('MSG_Template'); |
|
421 | + $message_type = EEH_MSG_Template::convert_payment_status_to_message_type($payment->STS_ID()); |
|
422 | + //if payment amount is less than 0 then switch to payment_refund message type. |
|
423 | + $message_type = $payment->amount() < 0 ? 'payment_refund' : $message_type; |
|
424 | + self::$_MSG_PROCESSOR->generate_for_all_active_messengers($message_type, $data); |
|
425 | + } |
|
426 | + |
|
427 | + |
|
428 | + /** |
|
429 | + * @param EE_Transaction $transaction |
|
430 | + */ |
|
431 | + public static function cancelled_registration(EE_Transaction $transaction) |
|
432 | + { |
|
433 | + self::_load_controller(); |
|
434 | + $data = array($transaction, null); |
|
435 | + self::$_MSG_PROCESSOR->generate_for_all_active_messengers('cancelled_registration', $data); |
|
436 | + } |
|
437 | + |
|
438 | + |
|
439 | + |
|
440 | + /** |
|
441 | + * Trigger for Registration messages |
|
442 | + * Note that what registration message type is sent depends on what the reg status is for the registrations on the |
|
443 | + * incoming transaction. |
|
444 | + * |
|
445 | + * @param EE_Registration $registration |
|
446 | + * @param array $extra_details |
|
447 | + * @return void |
|
448 | + * @throws EE_Error |
|
449 | + * @throws EntityNotFoundException |
|
450 | + */ |
|
451 | + public static function maybe_registration(EE_Registration $registration, $extra_details = array()) |
|
452 | + { |
|
453 | + |
|
454 | + if (! self::_verify_registration_notification_send($registration, $extra_details)) { |
|
455 | + //no messages please |
|
456 | + return; |
|
457 | + } |
|
458 | + |
|
459 | + // get all non-trashed registrations so we make sure we send messages for the right status. |
|
460 | + $all_registrations = $registration->transaction()->registrations( |
|
461 | + array( |
|
462 | + array('REG_deleted' => false), |
|
463 | + 'order_by' => array( |
|
464 | + 'Event.EVT_name' => 'ASC', |
|
465 | + 'Attendee.ATT_lname' => 'ASC', |
|
466 | + 'Attendee.ATT_fname' => 'ASC' |
|
467 | + ) |
|
468 | + ) |
|
469 | + ); |
|
470 | + //cached array of statuses so we only trigger messages once per status. |
|
471 | + $statuses_sent = array(); |
|
472 | + self::_load_controller(); |
|
473 | + $mtgs = array(); |
|
474 | + |
|
475 | + //loop through registrations and trigger messages once per status. |
|
476 | + foreach ($all_registrations as $reg) { |
|
477 | + |
|
478 | + //already triggered? |
|
479 | + if (in_array($reg->status_ID(), $statuses_sent)) { |
|
480 | + continue; |
|
481 | + } |
|
482 | + |
|
483 | + $message_type = EEH_MSG_Template::convert_reg_status_to_message_type($reg->status_ID()); |
|
484 | + $mtgs = array_merge( |
|
485 | + $mtgs, |
|
486 | + self::$_MSG_PROCESSOR->setup_mtgs_for_all_active_messengers( |
|
487 | + $message_type, |
|
488 | + array($registration->transaction(), null, $reg->status_ID()) |
|
489 | + ) |
|
490 | + ); |
|
491 | + $statuses_sent[] = $reg->status_ID(); |
|
492 | + } |
|
493 | + |
|
494 | + if (count($statuses_sent) > 1) { |
|
495 | + $mtgs = array_merge( |
|
496 | + $mtgs, |
|
497 | + self::$_MSG_PROCESSOR->setup_mtgs_for_all_active_messengers( |
|
498 | + 'registration_summary', |
|
499 | + array($registration->transaction(), null) |
|
500 | + ) |
|
501 | + ); |
|
502 | + } |
|
503 | + |
|
504 | + //batch queue and initiate request |
|
505 | + self::$_MSG_PROCESSOR->batch_queue_for_generation_and_persist($mtgs); |
|
506 | + self::$_MSG_PROCESSOR->get_queue()->initiate_request_by_priority(); |
|
507 | + } |
|
508 | + |
|
509 | + |
|
510 | + /** |
|
511 | + * This is a helper method used to very whether a registration notification should be sent or |
|
512 | + * not. Prevents duplicate notifications going out for registration context notifications. |
|
513 | + * |
|
514 | + * @param EE_Registration $registration [description] |
|
515 | + * @param array $extra_details [description] |
|
516 | + * @return bool true = send away, false = nope halt the presses. |
|
517 | + */ |
|
518 | + protected static function _verify_registration_notification_send( |
|
519 | + EE_Registration $registration, |
|
520 | + $extra_details = array() |
|
521 | + ) { |
|
522 | + //self::log( |
|
523 | + // __CLASS__, __FUNCTION__, __LINE__, |
|
524 | + // $registration->transaction(), |
|
525 | + // array( '$extra_details' => $extra_details ) |
|
526 | + //); |
|
527 | + // currently only using this to send messages for the primary registrant |
|
528 | + if (! $registration->is_primary_registrant()) { |
|
529 | + return false; |
|
530 | + } |
|
531 | + // first we check if we're in admin and not doing front ajax |
|
532 | + if (is_admin() && ! EE_FRONT_AJAX) { |
|
533 | + //make sure appropriate admin params are set for sending messages |
|
534 | + if (empty($_REQUEST['txn_reg_status_change']['send_notifications']) || ! absint($_REQUEST['txn_reg_status_change']['send_notifications'])) { |
|
535 | + //no messages sent please. |
|
536 | + return false; |
|
537 | + } |
|
538 | + } else { |
|
539 | + // frontend request (either regular or via AJAX) |
|
540 | + // TXN is NOT finalized ? |
|
541 | + if (! isset($extra_details['finalized']) || $extra_details['finalized'] === false) { |
|
542 | + return false; |
|
543 | + } |
|
544 | + // return visit but nothing changed ??? |
|
545 | + if ( |
|
546 | + isset($extra_details['revisit'], $extra_details['status_updates']) && |
|
547 | + $extra_details['revisit'] && ! $extra_details['status_updates'] |
|
548 | + ) { |
|
549 | + return false; |
|
550 | + } |
|
551 | + // NOT sending messages && reg status is something other than "Not-Approved" |
|
552 | + if ( |
|
553 | + ! apply_filters('FHEE__EED_Messages___maybe_registration__deliver_notifications', false) && |
|
554 | + $registration->status_ID() !== EEM_Registration::status_id_not_approved |
|
555 | + ) { |
|
556 | + return false; |
|
557 | + } |
|
558 | + } |
|
559 | + // release the kraken |
|
560 | + return true; |
|
561 | + } |
|
562 | + |
|
563 | + |
|
564 | + /** |
|
565 | + * Simply returns an array indexed by Registration Status ID and the related message_type name associated with that |
|
566 | + * status id. |
|
567 | + * |
|
568 | + * @deprecated 4.9.0 Use EEH_MSG_Template::reg_status_to_message_type_array() |
|
569 | + * or EEH_MSG_Template::convert_reg_status_to_message_type |
|
570 | + * @param string $reg_status |
|
571 | + * @return array |
|
572 | + */ |
|
573 | + protected static function _get_reg_status_array($reg_status = '') |
|
574 | + { |
|
575 | + EE_Registry::instance()->load_helper('MSG_Template'); |
|
576 | + return EEH_MSG_Template::convert_reg_status_to_message_type($reg_status) |
|
577 | + ? EEH_MSG_Template::convert_reg_status_to_message_type($reg_status) |
|
578 | + : EEH_MSG_Template::reg_status_to_message_type_array(); |
|
579 | + } |
|
580 | + |
|
581 | + |
|
582 | + /** |
|
583 | + * Simply returns the payment message type for the given payment status. |
|
584 | + * |
|
585 | + * @deprecated 4.9.0 Use EEH_MSG_Template::payment_status_to_message_type_array |
|
586 | + * or EEH_MSG_Template::convert_payment_status_to_message_type |
|
587 | + * @param string $payment_status The payment status being matched. |
|
588 | + * @return string|bool The payment message type slug matching the status or false if no match. |
|
589 | + */ |
|
590 | + protected static function _get_payment_message_type($payment_status) |
|
591 | + { |
|
592 | + EE_Registry::instance()->load_helper('MSG_Template'); |
|
593 | + return EEH_MSG_Template::convert_payment_status_to_message_type($payment_status) |
|
594 | + ? EEH_MSG_Template::convert_payment_status_to_message_type($payment_status) |
|
595 | + : false; |
|
596 | + } |
|
597 | + |
|
598 | + |
|
599 | + /** |
|
600 | + * Message triggers for a resending already sent message(s) (via EE_Message list table) |
|
601 | + * |
|
602 | + * @access public |
|
603 | + * @param array $req_data This is the $_POST & $_GET data sent from EE_Admin Pages |
|
604 | + * @return bool success/fail |
|
605 | + */ |
|
606 | + public static function process_resend($req_data) |
|
607 | + { |
|
608 | + self::_load_controller(); |
|
609 | + |
|
610 | + //if $msgID in this request then skip to the new resend_message |
|
611 | + if (EE_Registry::instance()->REQ->get('MSG_ID')) { |
|
612 | + return self::resend_message(); |
|
613 | + } |
|
614 | + |
|
615 | + //make sure any incoming request data is set on the REQ so that it gets picked up later. |
|
616 | + $req_data = (array)$req_data; |
|
617 | + foreach ($req_data as $request_key => $request_value) { |
|
618 | + EE_Registry::instance()->REQ->set($request_key, $request_value); |
|
619 | + } |
|
620 | + |
|
621 | + if (! $messages_to_send = self::$_MSG_PROCESSOR->setup_messages_to_generate_from_registration_ids_in_request()) { |
|
622 | + return false; |
|
623 | + } |
|
624 | + |
|
625 | + try { |
|
626 | + self::$_MSG_PROCESSOR->batch_queue_for_generation_and_persist($messages_to_send); |
|
627 | + self::$_MSG_PROCESSOR->get_queue()->initiate_request_by_priority(); |
|
628 | + } catch (EE_Error $e) { |
|
629 | + EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
630 | + return false; |
|
631 | + } |
|
632 | + EE_Error::add_success( |
|
633 | + __('Messages have been successfully queued for generation and sending.', 'event_espresso') |
|
634 | + ); |
|
635 | + return true; //everything got queued. |
|
636 | + } |
|
637 | + |
|
638 | + |
|
639 | + /** |
|
640 | + * Message triggers for a resending already sent message(s) (via EE_Message list table) |
|
641 | + * |
|
642 | + * @return bool |
|
643 | + */ |
|
644 | + public static function resend_message() |
|
645 | + { |
|
646 | + self::_load_controller(); |
|
647 | + |
|
648 | + $msgID = EE_Registry::instance()->REQ->get('MSG_ID'); |
|
649 | + if (! $msgID) { |
|
650 | + EE_Error::add_error(__('Something went wrong because there is no "MSG_ID" value in the request', |
|
651 | + 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
652 | + return false; |
|
653 | + } |
|
654 | + |
|
655 | + self::$_MSG_PROCESSOR->setup_messages_from_ids_and_send((array)$msgID); |
|
656 | + |
|
657 | + //setup success message. |
|
658 | + $count_ready_for_resend = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::status_resend); |
|
659 | + EE_Error::add_success(sprintf( |
|
660 | + _n( |
|
661 | + 'There was %d message queued for resending.', |
|
662 | + 'There were %d messages queued for resending.', |
|
663 | + $count_ready_for_resend, |
|
664 | + 'event_espresso' |
|
665 | + ), |
|
666 | + $count_ready_for_resend |
|
667 | + )); |
|
668 | + return true; |
|
669 | + } |
|
670 | + |
|
671 | + |
|
672 | + /** |
|
673 | + * Message triggers for manual payment applied by admin |
|
674 | + * |
|
675 | + * @param EE_Payment $payment EE_payment object |
|
676 | + * @return bool success/fail |
|
677 | + */ |
|
678 | + public static function process_admin_payment(EE_Payment $payment) |
|
679 | + { |
|
680 | + EE_Registry::instance()->load_helper('MSG_Template'); |
|
681 | + //we need to get the transaction object |
|
682 | + $transaction = $payment->transaction(); |
|
683 | + if ($transaction instanceof EE_Transaction) { |
|
684 | + $data = array($transaction, $payment); |
|
685 | + $message_type = EEH_MSG_Template::convert_payment_status_to_message_type($payment->STS_ID()); |
|
686 | + |
|
687 | + //if payment amount is less than 0 then switch to payment_refund message type. |
|
688 | + $message_type = $payment->amount() < 0 ? 'payment_refund' : $message_type; |
|
689 | + |
|
690 | + //if payment_refund is selected, but the status is NOT accepted. Then change message type to false so NO message notification goes out. |
|
691 | + $message_type = $message_type == 'payment_refund' && $payment->STS_ID() != EEM_Payment::status_id_approved ? false : $message_type; |
|
692 | + |
|
693 | + self::_load_controller(); |
|
694 | + |
|
695 | + self::$_MSG_PROCESSOR->generate_for_all_active_messengers($message_type, $data); |
|
696 | + |
|
697 | + //get count of queued for generation |
|
698 | + $count_to_generate = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(array( |
|
699 | + EEM_Message::status_incomplete, |
|
700 | + EEM_Message::status_idle, |
|
701 | + )); |
|
702 | + |
|
703 | + if ($count_to_generate > 0 && self::$_MSG_PROCESSOR->get_queue()->get_message_repository()->count() !== 0) { |
|
704 | + add_filter('FHEE__EE_Admin_Page___process_admin_payment_notification__success', '__return_true'); |
|
705 | + return true; |
|
706 | + } else { |
|
707 | + $count_failed = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::instance()->stati_indicating_failed_sending()); |
|
708 | + /** |
|
709 | + * Verify that there are actually errors. If not then we return a success message because the queue might have been emptied due to successful |
|
710 | + * IMMEDIATE generation. |
|
711 | + */ |
|
712 | + if ($count_failed > 0) { |
|
713 | + EE_Error::add_error(sprintf( |
|
714 | + _n( |
|
715 | + 'The payment notification generation failed.', |
|
716 | + '%d payment notifications failed being sent.', |
|
717 | + $count_failed, |
|
718 | + 'event_espresso' |
|
719 | + ), |
|
720 | + $count_failed |
|
721 | + ), __FILE__, __FUNCTION__, __LINE__); |
|
722 | + |
|
723 | + return false; |
|
724 | + } else { |
|
725 | + add_filter('FHEE__EE_Admin_Page___process_admin_payment_notification__success', '__return_true'); |
|
726 | + return true; |
|
727 | + } |
|
728 | + } |
|
729 | + } else { |
|
730 | + EE_Error::add_error( |
|
731 | + 'Unable to generate the payment notification because the given value for the transaction is invalid.', |
|
732 | + 'event_espresso' |
|
733 | + ); |
|
734 | + return false; |
|
735 | + } |
|
736 | + } |
|
737 | + |
|
738 | + |
|
739 | + /** |
|
740 | + * Callback for AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send_with_registrations trigger |
|
741 | + * |
|
742 | + * @since 4.3.0 |
|
743 | + * @param EE_Registration[] $registrations an array of EE_Registration objects |
|
744 | + * @param int $grp_id a specific message template group id. |
|
745 | + * @return void |
|
746 | + */ |
|
747 | + public static function send_newsletter_message($registrations, $grp_id) |
|
748 | + { |
|
749 | + //make sure mtp is id and set it in the EE_Request Handler later messages setup. |
|
750 | + EE_Registry::instance()->REQ->set('GRP_ID', (int)$grp_id); |
|
751 | + self::_load_controller(); |
|
752 | + self::$_MSG_PROCESSOR->generate_for_all_active_messengers('newsletter', $registrations); |
|
753 | + } |
|
754 | + |
|
755 | + |
|
756 | + /** |
|
757 | + * Callback for FHEE__EE_Registration__invoice_url__invoice_url or FHEE__EE_Registration__receipt_url__receipt_url |
|
758 | + * |
|
759 | + * @since 4.3.0 |
|
760 | + * @param string $registration_message_trigger_url |
|
761 | + * @param EE_Registration $registration |
|
762 | + * @param string $messenger |
|
763 | + * @param string $message_type |
|
764 | + * @return string |
|
765 | + */ |
|
766 | + public static function registration_message_trigger_url( |
|
767 | + $registration_message_trigger_url, |
|
768 | + EE_Registration $registration, |
|
769 | + $messenger = 'html', |
|
770 | + $message_type = 'invoice' |
|
771 | + ) { |
|
772 | + // whitelist $messenger |
|
773 | + switch ($messenger) { |
|
774 | + case 'pdf' : |
|
775 | + $sending_messenger = 'pdf'; |
|
776 | + $generating_messenger = 'html'; |
|
777 | + break; |
|
778 | + case 'html' : |
|
779 | + default : |
|
780 | + $sending_messenger = 'html'; |
|
781 | + $generating_messenger = 'html'; |
|
782 | + break; |
|
783 | + } |
|
784 | + // whitelist $message_type |
|
785 | + switch ($message_type) { |
|
786 | + case 'receipt' : |
|
787 | + $message_type = 'receipt'; |
|
788 | + break; |
|
789 | + case 'invoice' : |
|
790 | + default : |
|
791 | + $message_type = 'invoice'; |
|
792 | + break; |
|
793 | + } |
|
794 | + // verify that both the messenger AND the message type are active |
|
795 | + if (EEH_MSG_Template::is_messenger_active($sending_messenger) && EEH_MSG_Template::is_mt_active($message_type)) { |
|
796 | + //need to get the correct message template group for this (i.e. is there a custom invoice for the event this registration is registered for?) |
|
797 | + $template_query_params = array( |
|
798 | + 'MTP_is_active' => true, |
|
799 | + 'MTP_messenger' => $generating_messenger, |
|
800 | + 'MTP_message_type' => $message_type, |
|
801 | + 'Event.EVT_ID' => $registration->event_ID(), |
|
802 | + ); |
|
803 | + //get the message template group. |
|
804 | + $msg_template_group = EEM_Message_Template_Group::instance()->get_one(array($template_query_params)); |
|
805 | + //if we don't have an EE_Message_Template_Group then return |
|
806 | + if (! $msg_template_group instanceof EE_Message_Template_Group) { |
|
807 | + // remove EVT_ID from query params so that global templates get picked up |
|
808 | + unset($template_query_params['Event.EVT_ID']); |
|
809 | + //get global template as the fallback |
|
810 | + $msg_template_group = EEM_Message_Template_Group::instance()->get_one(array($template_query_params)); |
|
811 | + } |
|
812 | + //if we don't have an EE_Message_Template_Group then return |
|
813 | + if (! $msg_template_group instanceof EE_Message_Template_Group) { |
|
814 | + return ''; |
|
815 | + } |
|
816 | + // generate the URL |
|
817 | + $registration_message_trigger_url = EEH_MSG_Template::generate_url_trigger( |
|
818 | + $sending_messenger, |
|
819 | + $generating_messenger, |
|
820 | + 'purchaser', |
|
821 | + $message_type, |
|
822 | + $registration, |
|
823 | + $msg_template_group->ID(), |
|
824 | + $registration->transaction_ID() |
|
825 | + ); |
|
826 | + |
|
827 | + } |
|
828 | + return $registration_message_trigger_url; |
|
829 | + } |
|
830 | + |
|
831 | + |
|
832 | + /** |
|
833 | + * Use to generate and return a message preview! |
|
834 | + * |
|
835 | + * @param string $type This should correspond with a valid message type |
|
836 | + * @param string $context This should correspond with a valid context for the message type |
|
837 | + * @param string $messenger This should correspond with a valid messenger. |
|
838 | + * @param bool $send true we will do a test send using the messenger delivery, false we just do a regular |
|
839 | + * preview |
|
840 | + * @return bool|string The body of the message or if send is requested, sends. |
|
841 | + * @throws EE_Error |
|
842 | + */ |
|
843 | + public static function preview_message($type, $context, $messenger, $send = false) |
|
844 | + { |
|
845 | + self::_load_controller(); |
|
846 | + $mtg = new EE_Message_To_Generate( |
|
847 | + $messenger, |
|
848 | + $type, |
|
849 | + array(), |
|
850 | + $context, |
|
851 | + true |
|
852 | + ); |
|
853 | + $generated_preview_queue = self::$_MSG_PROCESSOR->generate_for_preview($mtg, $send); |
|
854 | + if ($generated_preview_queue instanceof EE_Messages_Queue) { |
|
855 | + //loop through all content for the preview and remove any persisted records. |
|
856 | + $content = ''; |
|
857 | + foreach ($generated_preview_queue->get_message_repository() as $message) { |
|
858 | + $content = $message->content(); |
|
859 | + if ($message->ID() > 0 && $message->STS_ID() !== EEM_Message::status_failed) { |
|
860 | + $message->delete(); |
|
861 | + } |
|
862 | + } |
|
863 | + return $content; |
|
864 | + } else { |
|
865 | + return $generated_preview_queue; |
|
866 | + } |
|
867 | + } |
|
868 | + |
|
869 | + |
|
870 | + /** |
|
871 | + * This is a method that allows for sending a message using a messenger matching the string given and the provided |
|
872 | + * EE_Message_Queue object. The EE_Message_Queue object is used to create a single aggregate EE_Message via the |
|
873 | + * content found in the EE_Message objects in the queue. |
|
874 | + * |
|
875 | + * @since 4.9.0 |
|
876 | + * @param string $messenger a string matching a valid active messenger in the system |
|
877 | + * @param string $message_type Although it seems contrary to the name of the method, a message |
|
878 | + * type name is still required to send along the message type to the |
|
879 | + * messenger because this is used for determining what specific |
|
880 | + * variations might be loaded for the generated message. |
|
881 | + * @param EE_Messages_Queue $queue |
|
882 | + * @param string $custom_subject Can be used to set what the custom subject string will be on the |
|
883 | + * aggregate EE_Message object. |
|
884 | + * @return bool success or fail. |
|
885 | + */ |
|
886 | + public static function send_message_with_messenger_only( |
|
887 | + $messenger, |
|
888 | + $message_type, |
|
889 | + EE_Messages_Queue $queue, |
|
890 | + $custom_subject = '' |
|
891 | + ) { |
|
892 | + self::_load_controller(); |
|
893 | + /** @type EE_Message_To_Generate_From_Queue $message_to_generate */ |
|
894 | + $message_to_generate = EE_Registry::instance()->load_lib( |
|
895 | + 'Message_To_Generate_From_Queue', |
|
896 | + array( |
|
897 | + $messenger, |
|
898 | + $message_type, |
|
899 | + $queue, |
|
900 | + $custom_subject, |
|
901 | + ) |
|
902 | + ); |
|
903 | + return self::$_MSG_PROCESSOR->queue_for_sending($message_to_generate); |
|
904 | + } |
|
905 | + |
|
906 | + |
|
907 | + /** |
|
908 | + * Generates Messages immediately for EE_Message IDs (but only for the correct status for generation) |
|
909 | + * |
|
910 | + * @since 4.9.0 |
|
911 | + * @param array $message_ids An array of message ids |
|
912 | + * @return bool | EE_Messages_Queue false if nothing was generated, EE_Messages_Queue containing generated |
|
913 | + * messages. |
|
914 | + */ |
|
915 | + public static function generate_now($message_ids) |
|
916 | + { |
|
917 | + self::_load_controller(); |
|
918 | + $messages = EEM_Message::instance()->get_all( |
|
919 | + array( |
|
920 | + 0 => array( |
|
921 | + 'MSG_ID' => array('IN', $message_ids), |
|
922 | + 'STS_ID' => EEM_Message::status_incomplete, |
|
923 | + ), |
|
924 | + ) |
|
925 | + ); |
|
926 | + $generated_queue = false; |
|
927 | + if ($messages) { |
|
928 | + $generated_queue = self::$_MSG_PROCESSOR->batch_generate_from_queue($messages); |
|
929 | + } |
|
930 | + |
|
931 | + if (! $generated_queue instanceof EE_Messages_Queue) { |
|
932 | + EE_Error::add_error( |
|
933 | + __('The messages were not generated. This could mean there is already a batch being generated on a separate request, or because the selected messages are not ready for generation. Please wait a minute or two and try again.', |
|
934 | + 'event_espresso'), |
|
935 | + __FILE__, __FUNCTION__, __LINE__ |
|
936 | + ); |
|
937 | + } |
|
938 | + return $generated_queue; |
|
939 | + } |
|
940 | + |
|
941 | + |
|
942 | + /** |
|
943 | + * Sends messages immediately for the incoming message_ids that have the status of EEM_Message::status_resend or, |
|
944 | + * EEM_Message::status_idle |
|
945 | + * |
|
946 | + * @since 4.9.0 |
|
947 | + * @param $message_ids |
|
948 | + * @return bool | EE_Messages_Queue false if no messages sent. |
|
949 | + */ |
|
950 | + public static function send_now($message_ids) |
|
951 | + { |
|
952 | + self::_load_controller(); |
|
953 | + $messages = EEM_Message::instance()->get_all( |
|
954 | + array( |
|
955 | + 0 => array( |
|
956 | + 'MSG_ID' => array('IN', $message_ids), |
|
957 | + 'STS_ID' => array( |
|
958 | + 'IN', |
|
959 | + array(EEM_Message::status_idle, EEM_Message::status_resend, EEM_Message::status_retry), |
|
960 | + ), |
|
961 | + ), |
|
962 | + ) |
|
963 | + ); |
|
964 | + $sent_queue = false; |
|
965 | + if ($messages) { |
|
966 | + $sent_queue = self::$_MSG_PROCESSOR->batch_send_from_queue($messages); |
|
967 | + } |
|
968 | + |
|
969 | + if (! $sent_queue instanceof EE_Messages_Queue) { |
|
970 | + EE_Error::add_error( |
|
971 | + __('The messages were not sent. This could mean there is already a batch being sent on a separate request, or because the selected messages are not sendable. Please wait a minute or two and try again.', |
|
972 | + 'event_espresso'), |
|
973 | + __FILE__, __FUNCTION__, __LINE__ |
|
974 | + ); |
|
975 | + } else { |
|
976 | + //can count how many sent by using the messages in the queue |
|
977 | + $sent_count = $sent_queue->count_STS_in_queue(EEM_Message::instance()->stati_indicating_sent()); |
|
978 | + if ($sent_count > 0) { |
|
979 | + EE_Error::add_success( |
|
980 | + sprintf( |
|
981 | + _n( |
|
982 | + 'There was %d message successfully sent.', |
|
983 | + 'There were %d messages successfully sent.', |
|
984 | + $sent_count, |
|
985 | + 'event_espresso' |
|
986 | + ), |
|
987 | + $sent_count |
|
988 | + ) |
|
989 | + ); |
|
990 | + } else { |
|
991 | + EE_Error::overwrite_errors(); |
|
992 | + EE_Error::add_error( |
|
993 | + __('No message was sent because of problems with sending. Either all the messages you selected were not a sendable message, they were ALREADY sent on a different scheduled task, or there was an error. |
|
994 | 994 | If there was an error, you can look at the messages in the message activity list table for any error messages.', |
995 | - 'event_espresso'), |
|
996 | - __FILE__, __FUNCTION__, __LINE__ |
|
997 | - ); |
|
998 | - } |
|
999 | - } |
|
1000 | - return $sent_queue; |
|
1001 | - } |
|
1002 | - |
|
1003 | - |
|
1004 | - /** |
|
1005 | - * This will queue the incoming message ids for resending. |
|
1006 | - * Note, only message_ids corresponding to messages with the status of EEM_Message::sent will be queued. |
|
1007 | - * |
|
1008 | - * @since 4.9.0 |
|
1009 | - * @param array $message_ids An array of EE_Message IDs |
|
1010 | - * @return bool true means messages were successfully queued for resending, false means none were queued for |
|
1011 | - * resending. |
|
1012 | - */ |
|
1013 | - public static function queue_for_resending($message_ids) |
|
1014 | - { |
|
1015 | - self::_load_controller(); |
|
1016 | - self::$_MSG_PROCESSOR->setup_messages_from_ids_and_send($message_ids); |
|
1017 | - |
|
1018 | - //get queue and count |
|
1019 | - $queue_count = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::status_resend); |
|
1020 | - |
|
1021 | - if ( |
|
1022 | - $queue_count > 0 |
|
1023 | - ) { |
|
1024 | - EE_Error::add_success( |
|
1025 | - sprintf( |
|
1026 | - _n( |
|
1027 | - '%d message successfully queued for resending.', |
|
1028 | - '%d messages successfully queued for resending.', |
|
1029 | - $queue_count, |
|
1030 | - 'event_espresso' |
|
1031 | - ), |
|
1032 | - $queue_count |
|
1033 | - ) |
|
1034 | - ); |
|
1035 | - /** |
|
1036 | - * @see filter usage in EE_Messages_Queue::initiate_request_by_priority |
|
1037 | - */ |
|
1038 | - } elseif ( |
|
1039 | - apply_filters('FHEE__EE_Messages_Processor__initiate_request_by_priority__do_immediate_processing', true) |
|
1040 | - || EE_Registry::instance()->NET_CFG->core->do_messages_on_same_request |
|
1041 | - ) { |
|
1042 | - $queue_count = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::status_sent); |
|
1043 | - if ($queue_count > 0) { |
|
1044 | - EE_Error::add_success( |
|
1045 | - sprintf( |
|
1046 | - _n( |
|
1047 | - '%d message successfully sent.', |
|
1048 | - '%d messages successfully sent.', |
|
1049 | - $queue_count, |
|
1050 | - 'event_espresso' |
|
1051 | - ), |
|
1052 | - $queue_count |
|
1053 | - ) |
|
1054 | - ); |
|
1055 | - } else { |
|
1056 | - EE_Error::add_error( |
|
1057 | - __('No messages were queued for resending. This usually only happens when all the messages flagged for resending are not a status that can be resent.', |
|
1058 | - 'event_espresso'), |
|
1059 | - __FILE__, __FUNCTION__, __LINE__ |
|
1060 | - ); |
|
1061 | - } |
|
1062 | - } else { |
|
1063 | - EE_Error::add_error( |
|
1064 | - __('No messages were queued for resending. This usually only happens when all the messages flagged for resending are not a status that can be resent.', |
|
1065 | - 'event_espresso'), |
|
1066 | - __FILE__, __FUNCTION__, __LINE__ |
|
1067 | - ); |
|
1068 | - } |
|
1069 | - return (bool)$queue_count; |
|
1070 | - } |
|
1071 | - |
|
1072 | - |
|
1073 | - /** |
|
1074 | - * debug |
|
1075 | - * |
|
1076 | - * @param string $class |
|
1077 | - * @param string $func |
|
1078 | - * @param string $line |
|
1079 | - * @param \EE_Transaction $transaction |
|
1080 | - * @param array $info |
|
1081 | - * @param bool $display_request |
|
1082 | - */ |
|
1083 | - protected static function log( |
|
1084 | - $class = '', |
|
1085 | - $func = '', |
|
1086 | - $line = '', |
|
1087 | - EE_Transaction $transaction, |
|
1088 | - $info = array(), |
|
1089 | - $display_request = false |
|
1090 | - ) { |
|
1091 | - if (WP_DEBUG && false) { |
|
1092 | - if ($transaction instanceof EE_Transaction) { |
|
1093 | - // don't serialize objects |
|
1094 | - $info = EEH_Debug_Tools::strip_objects($info); |
|
1095 | - $info['TXN_status'] = $transaction->status_ID(); |
|
1096 | - $info['TXN_reg_steps'] = $transaction->reg_steps(); |
|
1097 | - if ($transaction->ID()) { |
|
1098 | - $index = 'EE_Transaction: ' . $transaction->ID(); |
|
1099 | - EEH_Debug_Tools::log($class, $func, $line, $info, $display_request, $index); |
|
1100 | - } |
|
1101 | - } |
|
1102 | - } |
|
1103 | - |
|
1104 | - } |
|
1105 | - |
|
1106 | - |
|
1107 | - /** |
|
1108 | - * Resets all the static properties in this class when called. |
|
1109 | - */ |
|
1110 | - public static function reset() |
|
1111 | - { |
|
1112 | - self::$_EEMSG = null; |
|
1113 | - self::$_message_resource_manager = null; |
|
1114 | - self::$_MSG_PROCESSOR = null; |
|
1115 | - self::$_MSG_PATHS = null; |
|
1116 | - self::$_TMP_PACKS = array(); |
|
1117 | - } |
|
995 | + 'event_espresso'), |
|
996 | + __FILE__, __FUNCTION__, __LINE__ |
|
997 | + ); |
|
998 | + } |
|
999 | + } |
|
1000 | + return $sent_queue; |
|
1001 | + } |
|
1002 | + |
|
1003 | + |
|
1004 | + /** |
|
1005 | + * This will queue the incoming message ids for resending. |
|
1006 | + * Note, only message_ids corresponding to messages with the status of EEM_Message::sent will be queued. |
|
1007 | + * |
|
1008 | + * @since 4.9.0 |
|
1009 | + * @param array $message_ids An array of EE_Message IDs |
|
1010 | + * @return bool true means messages were successfully queued for resending, false means none were queued for |
|
1011 | + * resending. |
|
1012 | + */ |
|
1013 | + public static function queue_for_resending($message_ids) |
|
1014 | + { |
|
1015 | + self::_load_controller(); |
|
1016 | + self::$_MSG_PROCESSOR->setup_messages_from_ids_and_send($message_ids); |
|
1017 | + |
|
1018 | + //get queue and count |
|
1019 | + $queue_count = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::status_resend); |
|
1020 | + |
|
1021 | + if ( |
|
1022 | + $queue_count > 0 |
|
1023 | + ) { |
|
1024 | + EE_Error::add_success( |
|
1025 | + sprintf( |
|
1026 | + _n( |
|
1027 | + '%d message successfully queued for resending.', |
|
1028 | + '%d messages successfully queued for resending.', |
|
1029 | + $queue_count, |
|
1030 | + 'event_espresso' |
|
1031 | + ), |
|
1032 | + $queue_count |
|
1033 | + ) |
|
1034 | + ); |
|
1035 | + /** |
|
1036 | + * @see filter usage in EE_Messages_Queue::initiate_request_by_priority |
|
1037 | + */ |
|
1038 | + } elseif ( |
|
1039 | + apply_filters('FHEE__EE_Messages_Processor__initiate_request_by_priority__do_immediate_processing', true) |
|
1040 | + || EE_Registry::instance()->NET_CFG->core->do_messages_on_same_request |
|
1041 | + ) { |
|
1042 | + $queue_count = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::status_sent); |
|
1043 | + if ($queue_count > 0) { |
|
1044 | + EE_Error::add_success( |
|
1045 | + sprintf( |
|
1046 | + _n( |
|
1047 | + '%d message successfully sent.', |
|
1048 | + '%d messages successfully sent.', |
|
1049 | + $queue_count, |
|
1050 | + 'event_espresso' |
|
1051 | + ), |
|
1052 | + $queue_count |
|
1053 | + ) |
|
1054 | + ); |
|
1055 | + } else { |
|
1056 | + EE_Error::add_error( |
|
1057 | + __('No messages were queued for resending. This usually only happens when all the messages flagged for resending are not a status that can be resent.', |
|
1058 | + 'event_espresso'), |
|
1059 | + __FILE__, __FUNCTION__, __LINE__ |
|
1060 | + ); |
|
1061 | + } |
|
1062 | + } else { |
|
1063 | + EE_Error::add_error( |
|
1064 | + __('No messages were queued for resending. This usually only happens when all the messages flagged for resending are not a status that can be resent.', |
|
1065 | + 'event_espresso'), |
|
1066 | + __FILE__, __FUNCTION__, __LINE__ |
|
1067 | + ); |
|
1068 | + } |
|
1069 | + return (bool)$queue_count; |
|
1070 | + } |
|
1071 | + |
|
1072 | + |
|
1073 | + /** |
|
1074 | + * debug |
|
1075 | + * |
|
1076 | + * @param string $class |
|
1077 | + * @param string $func |
|
1078 | + * @param string $line |
|
1079 | + * @param \EE_Transaction $transaction |
|
1080 | + * @param array $info |
|
1081 | + * @param bool $display_request |
|
1082 | + */ |
|
1083 | + protected static function log( |
|
1084 | + $class = '', |
|
1085 | + $func = '', |
|
1086 | + $line = '', |
|
1087 | + EE_Transaction $transaction, |
|
1088 | + $info = array(), |
|
1089 | + $display_request = false |
|
1090 | + ) { |
|
1091 | + if (WP_DEBUG && false) { |
|
1092 | + if ($transaction instanceof EE_Transaction) { |
|
1093 | + // don't serialize objects |
|
1094 | + $info = EEH_Debug_Tools::strip_objects($info); |
|
1095 | + $info['TXN_status'] = $transaction->status_ID(); |
|
1096 | + $info['TXN_reg_steps'] = $transaction->reg_steps(); |
|
1097 | + if ($transaction->ID()) { |
|
1098 | + $index = 'EE_Transaction: ' . $transaction->ID(); |
|
1099 | + EEH_Debug_Tools::log($class, $func, $line, $info, $display_request, $index); |
|
1100 | + } |
|
1101 | + } |
|
1102 | + } |
|
1103 | + |
|
1104 | + } |
|
1105 | + |
|
1106 | + |
|
1107 | + /** |
|
1108 | + * Resets all the static properties in this class when called. |
|
1109 | + */ |
|
1110 | + public static function reset() |
|
1111 | + { |
|
1112 | + self::$_EEMSG = null; |
|
1113 | + self::$_message_resource_manager = null; |
|
1114 | + self::$_MSG_PROCESSOR = null; |
|
1115 | + self::$_MSG_PATHS = null; |
|
1116 | + self::$_TMP_PACKS = array(); |
|
1117 | + } |
|
1118 | 1118 | |
1119 | 1119 | } |
1120 | 1120 | // End of file EED_Messages.module.php |
@@ -5,7 +5,7 @@ discard block |
||
5 | 5 | use EventEspresso\core\exceptions\InvalidEntityException; |
6 | 6 | |
7 | 7 | if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
8 | - exit('No direct script access allowed'); |
|
8 | + exit('No direct script access allowed'); |
|
9 | 9 | } |
10 | 10 | |
11 | 11 | |
@@ -20,1865 +20,1865 @@ discard block |
||
20 | 20 | class EED_Single_Page_Checkout extends EED_Module |
21 | 21 | { |
22 | 22 | |
23 | - /** |
|
24 | - * $_initialized - has the SPCO controller already been initialized ? |
|
25 | - * |
|
26 | - * @access private |
|
27 | - * @var bool $_initialized |
|
28 | - */ |
|
29 | - private static $_initialized = false; |
|
30 | - |
|
31 | - |
|
32 | - /** |
|
33 | - * $_checkout_verified - is the EE_Checkout verified as correct for this request ? |
|
34 | - * |
|
35 | - * @access private |
|
36 | - * @var bool $_valid_checkout |
|
37 | - */ |
|
38 | - private static $_checkout_verified = true; |
|
39 | - |
|
40 | - /** |
|
41 | - * $_reg_steps_array - holds initial array of reg steps |
|
42 | - * |
|
43 | - * @access private |
|
44 | - * @var array $_reg_steps_array |
|
45 | - */ |
|
46 | - private static $_reg_steps_array = array(); |
|
47 | - |
|
48 | - /** |
|
49 | - * $checkout - EE_Checkout object for handling the properties of the current checkout process |
|
50 | - * |
|
51 | - * @access public |
|
52 | - * @var EE_Checkout $checkout |
|
53 | - */ |
|
54 | - public $checkout; |
|
55 | - |
|
56 | - |
|
57 | - |
|
58 | - /** |
|
59 | - * @return EED_Module|EED_Single_Page_Checkout |
|
60 | - */ |
|
61 | - public static function instance() |
|
62 | - { |
|
63 | - add_filter('EED_Single_Page_Checkout__SPCO_active', '__return_true'); |
|
64 | - return parent::get_instance(__CLASS__); |
|
65 | - } |
|
66 | - |
|
67 | - |
|
68 | - |
|
69 | - /** |
|
70 | - * @return EE_CART |
|
71 | - */ |
|
72 | - public function cart() |
|
73 | - { |
|
74 | - return $this->checkout->cart; |
|
75 | - } |
|
76 | - |
|
77 | - |
|
78 | - |
|
79 | - /** |
|
80 | - * @return EE_Transaction |
|
81 | - */ |
|
82 | - public function transaction() |
|
83 | - { |
|
84 | - return $this->checkout->transaction; |
|
85 | - } |
|
86 | - |
|
87 | - |
|
88 | - |
|
89 | - /** |
|
90 | - * set_hooks - for hooking into EE Core, other modules, etc |
|
91 | - * |
|
92 | - * @access public |
|
93 | - * @return void |
|
94 | - * @throws EE_Error |
|
95 | - */ |
|
96 | - public static function set_hooks() |
|
97 | - { |
|
98 | - EED_Single_Page_Checkout::set_definitions(); |
|
99 | - } |
|
100 | - |
|
101 | - |
|
102 | - |
|
103 | - /** |
|
104 | - * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
105 | - * |
|
106 | - * @access public |
|
107 | - * @return void |
|
108 | - * @throws EE_Error |
|
109 | - */ |
|
110 | - public static function set_hooks_admin() |
|
111 | - { |
|
112 | - EED_Single_Page_Checkout::set_definitions(); |
|
113 | - if ( ! (defined('DOING_AJAX') && DOING_AJAX)) { |
|
114 | - return; |
|
115 | - } |
|
116 | - // going to start an output buffer in case anything gets accidentally output |
|
117 | - // that might disrupt our JSON response |
|
118 | - ob_start(); |
|
119 | - EED_Single_Page_Checkout::load_request_handler(); |
|
120 | - EED_Single_Page_Checkout::load_reg_steps(); |
|
121 | - // set ajax hooks |
|
122 | - add_action('wp_ajax_process_reg_step', array('EED_Single_Page_Checkout', 'process_reg_step')); |
|
123 | - add_action('wp_ajax_nopriv_process_reg_step', array('EED_Single_Page_Checkout', 'process_reg_step')); |
|
124 | - add_action('wp_ajax_display_spco_reg_step', array('EED_Single_Page_Checkout', 'display_reg_step')); |
|
125 | - add_action('wp_ajax_nopriv_display_spco_reg_step', array('EED_Single_Page_Checkout', 'display_reg_step')); |
|
126 | - add_action('wp_ajax_update_reg_step', array('EED_Single_Page_Checkout', 'update_reg_step')); |
|
127 | - add_action('wp_ajax_nopriv_update_reg_step', array('EED_Single_Page_Checkout', 'update_reg_step')); |
|
128 | - } |
|
129 | - |
|
130 | - |
|
131 | - |
|
132 | - /** |
|
133 | - * process ajax request |
|
134 | - * |
|
135 | - * @param string $ajax_action |
|
136 | - * @throws EE_Error |
|
137 | - */ |
|
138 | - public static function process_ajax_request($ajax_action) |
|
139 | - { |
|
140 | - EE_Registry::instance()->REQ->set('action', $ajax_action); |
|
141 | - EED_Single_Page_Checkout::instance()->_initialize(); |
|
142 | - } |
|
143 | - |
|
144 | - |
|
145 | - |
|
146 | - /** |
|
147 | - * ajax display registration step |
|
148 | - * |
|
149 | - * @throws EE_Error |
|
150 | - */ |
|
151 | - public static function display_reg_step() |
|
152 | - { |
|
153 | - EED_Single_Page_Checkout::process_ajax_request('display_spco_reg_step'); |
|
154 | - } |
|
155 | - |
|
156 | - |
|
157 | - |
|
158 | - /** |
|
159 | - * ajax process registration step |
|
160 | - * |
|
161 | - * @throws EE_Error |
|
162 | - */ |
|
163 | - public static function process_reg_step() |
|
164 | - { |
|
165 | - EED_Single_Page_Checkout::process_ajax_request('process_reg_step'); |
|
166 | - } |
|
167 | - |
|
168 | - |
|
169 | - |
|
170 | - /** |
|
171 | - * ajax process registration step |
|
172 | - * |
|
173 | - * @throws EE_Error |
|
174 | - */ |
|
175 | - public static function update_reg_step() |
|
176 | - { |
|
177 | - EED_Single_Page_Checkout::process_ajax_request('update_reg_step'); |
|
178 | - } |
|
179 | - |
|
180 | - |
|
181 | - |
|
182 | - /** |
|
183 | - * update_checkout |
|
184 | - * |
|
185 | - * @access public |
|
186 | - * @return void |
|
187 | - * @throws EE_Error |
|
188 | - */ |
|
189 | - public static function update_checkout() |
|
190 | - { |
|
191 | - EED_Single_Page_Checkout::process_ajax_request('update_checkout'); |
|
192 | - } |
|
193 | - |
|
194 | - |
|
195 | - |
|
196 | - /** |
|
197 | - * load_request_handler |
|
198 | - * |
|
199 | - * @access public |
|
200 | - * @return void |
|
201 | - */ |
|
202 | - public static function load_request_handler() |
|
203 | - { |
|
204 | - // load core Request_Handler class |
|
205 | - if (EE_Registry::instance()->REQ !== null) { |
|
206 | - EE_Registry::instance()->load_core('Request_Handler'); |
|
207 | - } |
|
208 | - } |
|
209 | - |
|
210 | - |
|
211 | - |
|
212 | - /** |
|
213 | - * set_definitions |
|
214 | - * |
|
215 | - * @access public |
|
216 | - * @return void |
|
217 | - * @throws EE_Error |
|
218 | - */ |
|
219 | - public static function set_definitions() |
|
220 | - { |
|
221 | - if(defined('SPCO_BASE_PATH')) { |
|
222 | - return; |
|
223 | - } |
|
224 | - define( |
|
225 | - 'SPCO_BASE_PATH', |
|
226 | - rtrim(str_replace(array('\\', '/'), DS, plugin_dir_path(__FILE__)), DS) . DS |
|
227 | - ); |
|
228 | - define('SPCO_CSS_URL', plugin_dir_url(__FILE__) . 'css' . DS); |
|
229 | - define('SPCO_IMG_URL', plugin_dir_url(__FILE__) . 'img' . DS); |
|
230 | - define('SPCO_JS_URL', plugin_dir_url(__FILE__) . 'js' . DS); |
|
231 | - define('SPCO_INC_PATH', SPCO_BASE_PATH . 'inc' . DS); |
|
232 | - define('SPCO_REG_STEPS_PATH', SPCO_BASE_PATH . 'reg_steps' . DS); |
|
233 | - define('SPCO_TEMPLATES_PATH', SPCO_BASE_PATH . 'templates' . DS); |
|
234 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(SPCO_BASE_PATH, true); |
|
235 | - EE_Registry::$i18n_js_strings['registration_expiration_notice'] = sprintf( |
|
236 | - __('%1$sWe\'re sorry, but you\'re registration time has expired.%2$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 except our apologies for any inconvenience this may have caused.%8$s', |
|
237 | - 'event_espresso'), |
|
238 | - '<h4 class="important-notice">', |
|
239 | - '</h4>', |
|
240 | - '<br />', |
|
241 | - '<p>', |
|
242 | - '<a href="' . get_post_type_archive_link('espresso_events') . '" title="', |
|
243 | - '">', |
|
244 | - '</a>', |
|
245 | - '</p>' |
|
246 | - ); |
|
247 | - } |
|
248 | - |
|
249 | - |
|
250 | - |
|
251 | - /** |
|
252 | - * load_reg_steps |
|
253 | - * loads and instantiates each reg step based on the EE_Registry::instance()->CFG->registration->reg_steps array |
|
254 | - * |
|
255 | - * @access private |
|
256 | - * @throws EE_Error |
|
257 | - */ |
|
258 | - public static function load_reg_steps() |
|
259 | - { |
|
260 | - static $reg_steps_loaded = false; |
|
261 | - if ($reg_steps_loaded) { |
|
262 | - return; |
|
263 | - } |
|
264 | - // filter list of reg_steps |
|
265 | - $reg_steps_to_load = (array)apply_filters( |
|
266 | - 'AHEE__SPCO__load_reg_steps__reg_steps_to_load', |
|
267 | - EED_Single_Page_Checkout::get_reg_steps() |
|
268 | - ); |
|
269 | - // sort by key (order) |
|
270 | - ksort($reg_steps_to_load); |
|
271 | - // loop through folders |
|
272 | - foreach ($reg_steps_to_load as $order => $reg_step) { |
|
273 | - // we need a |
|
274 | - if (isset($reg_step['file_path'], $reg_step['class_name'], $reg_step['slug'])) { |
|
275 | - // copy over to the reg_steps_array |
|
276 | - EED_Single_Page_Checkout::$_reg_steps_array[$order] = $reg_step; |
|
277 | - // register custom key route for each reg step |
|
278 | - // ie: step=>"slug" - this is the entire reason we load the reg steps array now |
|
279 | - EE_Config::register_route( |
|
280 | - $reg_step['slug'], |
|
281 | - 'EED_Single_Page_Checkout', |
|
282 | - 'run', |
|
283 | - 'step' |
|
284 | - ); |
|
285 | - // add AJAX or other hooks |
|
286 | - if (isset($reg_step['has_hooks']) && $reg_step['has_hooks']) { |
|
287 | - // setup autoloaders if necessary |
|
288 | - if ( ! class_exists($reg_step['class_name'])) { |
|
289 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder( |
|
290 | - $reg_step['file_path'], |
|
291 | - true |
|
292 | - ); |
|
293 | - } |
|
294 | - if (is_callable($reg_step['class_name'], 'set_hooks')) { |
|
295 | - call_user_func(array($reg_step['class_name'], 'set_hooks')); |
|
296 | - } |
|
297 | - } |
|
298 | - } |
|
299 | - } |
|
300 | - $reg_steps_loaded = true; |
|
301 | - } |
|
302 | - |
|
303 | - |
|
304 | - |
|
305 | - /** |
|
306 | - * get_reg_steps |
|
307 | - * |
|
308 | - * @access public |
|
309 | - * @return array |
|
310 | - */ |
|
311 | - public static function get_reg_steps() |
|
312 | - { |
|
313 | - $reg_steps = EE_Registry::instance()->CFG->registration->reg_steps; |
|
314 | - if (empty($reg_steps)) { |
|
315 | - $reg_steps = array( |
|
316 | - 10 => array( |
|
317 | - 'file_path' => SPCO_REG_STEPS_PATH . 'attendee_information', |
|
318 | - 'class_name' => 'EE_SPCO_Reg_Step_Attendee_Information', |
|
319 | - 'slug' => 'attendee_information', |
|
320 | - 'has_hooks' => false, |
|
321 | - ), |
|
322 | - 20 => array( |
|
323 | - 'file_path' => SPCO_REG_STEPS_PATH . 'registration_confirmation', |
|
324 | - 'class_name' => 'EE_SPCO_Reg_Step_Registration_Confirmation', |
|
325 | - 'slug' => 'registration_confirmation', |
|
326 | - 'has_hooks' => false, |
|
327 | - ), |
|
328 | - 30 => array( |
|
329 | - 'file_path' => SPCO_REG_STEPS_PATH . 'payment_options', |
|
330 | - 'class_name' => 'EE_SPCO_Reg_Step_Payment_Options', |
|
331 | - 'slug' => 'payment_options', |
|
332 | - 'has_hooks' => true, |
|
333 | - ), |
|
334 | - 999 => array( |
|
335 | - 'file_path' => SPCO_REG_STEPS_PATH . 'finalize_registration', |
|
336 | - 'class_name' => 'EE_SPCO_Reg_Step_Finalize_Registration', |
|
337 | - 'slug' => 'finalize_registration', |
|
338 | - 'has_hooks' => false, |
|
339 | - ), |
|
340 | - ); |
|
341 | - } |
|
342 | - return $reg_steps; |
|
343 | - } |
|
344 | - |
|
345 | - |
|
346 | - |
|
347 | - /** |
|
348 | - * registration_checkout_for_admin |
|
349 | - * |
|
350 | - * @access public |
|
351 | - * @return string |
|
352 | - * @throws EE_Error |
|
353 | - */ |
|
354 | - public static function registration_checkout_for_admin() |
|
355 | - { |
|
356 | - EED_Single_Page_Checkout::load_request_handler(); |
|
357 | - EE_Registry::instance()->REQ->set('step', 'attendee_information'); |
|
358 | - EE_Registry::instance()->REQ->set('action', 'display_spco_reg_step'); |
|
359 | - EE_Registry::instance()->REQ->set('process_form_submission', false); |
|
360 | - EED_Single_Page_Checkout::instance()->_initialize(); |
|
361 | - EED_Single_Page_Checkout::instance()->_display_spco_reg_form(); |
|
362 | - return EE_Registry::instance()->REQ->get_output(); |
|
363 | - } |
|
364 | - |
|
365 | - |
|
366 | - |
|
367 | - /** |
|
368 | - * process_registration_from_admin |
|
369 | - * |
|
370 | - * @access public |
|
371 | - * @return \EE_Transaction |
|
372 | - * @throws EE_Error |
|
373 | - */ |
|
374 | - public static function process_registration_from_admin() |
|
375 | - { |
|
376 | - EED_Single_Page_Checkout::load_request_handler(); |
|
377 | - EE_Registry::instance()->REQ->set('step', 'attendee_information'); |
|
378 | - EE_Registry::instance()->REQ->set('action', 'process_reg_step'); |
|
379 | - EE_Registry::instance()->REQ->set('process_form_submission', true); |
|
380 | - EED_Single_Page_Checkout::instance()->_initialize(); |
|
381 | - if (EED_Single_Page_Checkout::instance()->checkout->current_step->completed()) { |
|
382 | - $final_reg_step = end(EED_Single_Page_Checkout::instance()->checkout->reg_steps); |
|
383 | - if ($final_reg_step instanceof EE_SPCO_Reg_Step_Finalize_Registration) { |
|
384 | - EED_Single_Page_Checkout::instance()->checkout->set_reg_step_initiated($final_reg_step); |
|
385 | - if ($final_reg_step->process_reg_step()) { |
|
386 | - $final_reg_step->set_completed(); |
|
387 | - EED_Single_Page_Checkout::instance()->checkout->update_txn_reg_steps_array(); |
|
388 | - return EED_Single_Page_Checkout::instance()->checkout->transaction; |
|
389 | - } |
|
390 | - } |
|
391 | - } |
|
392 | - return null; |
|
393 | - } |
|
394 | - |
|
395 | - |
|
396 | - |
|
397 | - /** |
|
398 | - * run |
|
399 | - * |
|
400 | - * @access public |
|
401 | - * @param WP_Query $WP_Query |
|
402 | - * @return void |
|
403 | - * @throws EE_Error |
|
404 | - */ |
|
405 | - public function run($WP_Query) |
|
406 | - { |
|
407 | - if ( |
|
408 | - $WP_Query instanceof WP_Query |
|
409 | - && $WP_Query->is_main_query() |
|
410 | - && apply_filters('FHEE__EED_Single_Page_Checkout__run', true) |
|
411 | - && $this->_is_reg_checkout() |
|
412 | - ) { |
|
413 | - $this->_initialize(); |
|
414 | - } |
|
415 | - } |
|
416 | - |
|
417 | - |
|
418 | - |
|
419 | - /** |
|
420 | - * determines whether current url matches reg page url |
|
421 | - * |
|
422 | - * @return bool |
|
423 | - */ |
|
424 | - protected function _is_reg_checkout() |
|
425 | - { |
|
426 | - // get current permalink for reg page without any extra query args |
|
427 | - $reg_page_url = \get_permalink(EE_Config::instance()->core->reg_page_id); |
|
428 | - // get request URI for current request, but without the scheme or host |
|
429 | - $current_request_uri = \EEH_URL::filter_input_server_url('REQUEST_URI'); |
|
430 | - $current_request_uri = html_entity_decode($current_request_uri); |
|
431 | - // get array of query args from the current request URI |
|
432 | - $query_args = \EEH_URL::get_query_string($current_request_uri); |
|
433 | - // grab page id if it is set |
|
434 | - $page_id = isset($query_args['page_id']) ? absint($query_args['page_id']) : 0; |
|
435 | - // and remove the page id from the query args (we will re-add it later) |
|
436 | - unset($query_args['page_id']); |
|
437 | - // now strip all query args from current request URI |
|
438 | - $current_request_uri = remove_query_arg(array_keys($query_args), $current_request_uri); |
|
439 | - // and re-add the page id if it was set |
|
440 | - if ($page_id) { |
|
441 | - $current_request_uri = add_query_arg('page_id', $page_id, $current_request_uri); |
|
442 | - } |
|
443 | - // remove slashes and ? |
|
444 | - $current_request_uri = trim($current_request_uri, '?/'); |
|
445 | - // is current request URI part of the known full reg page URL ? |
|
446 | - return ! empty($current_request_uri) && strpos($reg_page_url, $current_request_uri) !== false; |
|
447 | - } |
|
448 | - |
|
449 | - |
|
450 | - |
|
451 | - /** |
|
452 | - * @param WP_Query $wp_query |
|
453 | - * @return void |
|
454 | - * @throws EE_Error |
|
455 | - */ |
|
456 | - public static function init($wp_query) |
|
457 | - { |
|
458 | - EED_Single_Page_Checkout::instance()->run($wp_query); |
|
459 | - } |
|
460 | - |
|
461 | - |
|
462 | - |
|
463 | - /** |
|
464 | - * _initialize - initial module setup |
|
465 | - * |
|
466 | - * @access private |
|
467 | - * @throws EE_Error |
|
468 | - * @return void |
|
469 | - */ |
|
470 | - private function _initialize() |
|
471 | - { |
|
472 | - // ensure SPCO doesn't run twice |
|
473 | - if (EED_Single_Page_Checkout::$_initialized) { |
|
474 | - return; |
|
475 | - } |
|
476 | - try { |
|
477 | - EED_Single_Page_Checkout::load_reg_steps(); |
|
478 | - $this->_verify_session(); |
|
479 | - // setup the EE_Checkout object |
|
480 | - $this->checkout = $this->_initialize_checkout(); |
|
481 | - // filter checkout |
|
482 | - $this->checkout = apply_filters('FHEE__EED_Single_Page_Checkout___initialize__checkout', $this->checkout); |
|
483 | - // get the $_GET |
|
484 | - $this->_get_request_vars(); |
|
485 | - if ($this->_block_bots()) { |
|
486 | - return; |
|
487 | - } |
|
488 | - // filter continue_reg |
|
489 | - $this->checkout->continue_reg = apply_filters( |
|
490 | - 'FHEE__EED_Single_Page_Checkout__init___continue_reg', |
|
491 | - true, |
|
492 | - $this->checkout |
|
493 | - ); |
|
494 | - // load the reg steps array |
|
495 | - if ( ! $this->_load_and_instantiate_reg_steps()) { |
|
496 | - EED_Single_Page_Checkout::$_initialized = true; |
|
497 | - return; |
|
498 | - } |
|
499 | - // set the current step |
|
500 | - $this->checkout->set_current_step($this->checkout->step); |
|
501 | - // and the next step |
|
502 | - $this->checkout->set_next_step(); |
|
503 | - // verify that everything has been setup correctly |
|
504 | - if ( ! ($this->_verify_transaction_and_get_registrations() && $this->_final_verifications())) { |
|
505 | - EED_Single_Page_Checkout::$_initialized = true; |
|
506 | - return; |
|
507 | - } |
|
508 | - // lock the transaction |
|
509 | - $this->checkout->transaction->lock(); |
|
510 | - // make sure all of our cached objects are added to their respective model entity mappers |
|
511 | - $this->checkout->refresh_all_entities(); |
|
512 | - // set amount owing |
|
513 | - $this->checkout->amount_owing = $this->checkout->transaction->remaining(); |
|
514 | - // initialize each reg step, which gives them the chance to potentially alter the process |
|
515 | - $this->_initialize_reg_steps(); |
|
516 | - // DEBUG LOG |
|
517 | - //$this->checkout->log( __CLASS__, __FUNCTION__, __LINE__ ); |
|
518 | - // get reg form |
|
519 | - if( ! $this->_check_form_submission()) { |
|
520 | - EED_Single_Page_Checkout::$_initialized = true; |
|
521 | - return; |
|
522 | - } |
|
523 | - // checkout the action!!! |
|
524 | - $this->_process_form_action(); |
|
525 | - // add some style and make it dance |
|
526 | - $this->add_styles_and_scripts(); |
|
527 | - // kk... SPCO has successfully run |
|
528 | - EED_Single_Page_Checkout::$_initialized = true; |
|
529 | - // set no cache headers and constants |
|
530 | - EE_System::do_not_cache(); |
|
531 | - // add anchor |
|
532 | - add_action('loop_start', array($this, 'set_checkout_anchor'), 1); |
|
533 | - // remove transaction lock |
|
534 | - add_action('shutdown', array($this, 'unlock_transaction'), 1); |
|
535 | - } catch (Exception $e) { |
|
536 | - EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
537 | - } |
|
538 | - } |
|
539 | - |
|
540 | - |
|
541 | - |
|
542 | - /** |
|
543 | - * _verify_session |
|
544 | - * checks that the session is valid and not expired |
|
545 | - * |
|
546 | - * @access private |
|
547 | - * @throws EE_Error |
|
548 | - */ |
|
549 | - private function _verify_session() |
|
550 | - { |
|
551 | - if ( ! EE_Registry::instance()->SSN instanceof EE_Session) { |
|
552 | - throw new EE_Error(__('The EE_Session class could not be loaded.', 'event_espresso')); |
|
553 | - } |
|
554 | - $clear_session_requested = filter_var( |
|
555 | - EE_Registry::instance()->REQ->get('clear_session', false), |
|
556 | - FILTER_VALIDATE_BOOLEAN |
|
557 | - ); |
|
558 | - // is session still valid ? |
|
559 | - if ($clear_session_requested |
|
560 | - || ( EE_Registry::instance()->SSN->expired() |
|
561 | - && EE_Registry::instance()->REQ->get('e_reg_url_link', '') === '' |
|
562 | - ) |
|
563 | - ) { |
|
564 | - $this->checkout = new EE_Checkout(); |
|
565 | - EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__); |
|
566 | - // EE_Registry::instance()->SSN->reset_cart(); |
|
567 | - // EE_Registry::instance()->SSN->reset_checkout(); |
|
568 | - // EE_Registry::instance()->SSN->reset_transaction(); |
|
569 | - if (! $clear_session_requested) { |
|
570 | - EE_Error::add_attention( |
|
571 | - EE_Registry::$i18n_js_strings['registration_expiration_notice'], |
|
572 | - __FILE__, __FUNCTION__, __LINE__ |
|
573 | - ); |
|
574 | - } |
|
575 | - // EE_Registry::instance()->SSN->reset_expired(); |
|
576 | - } |
|
577 | - } |
|
578 | - |
|
579 | - |
|
580 | - |
|
581 | - /** |
|
582 | - * _initialize_checkout |
|
583 | - * loads and instantiates EE_Checkout |
|
584 | - * |
|
585 | - * @access private |
|
586 | - * @throws EE_Error |
|
587 | - * @return EE_Checkout |
|
588 | - */ |
|
589 | - private function _initialize_checkout() |
|
590 | - { |
|
591 | - // look in session for existing checkout |
|
592 | - /** @type EE_Checkout $checkout */ |
|
593 | - $checkout = EE_Registry::instance()->SSN->checkout(); |
|
594 | - // verify |
|
595 | - if ( ! $checkout instanceof EE_Checkout) { |
|
596 | - // instantiate EE_Checkout object for handling the properties of the current checkout process |
|
597 | - $checkout = EE_Registry::instance()->load_file( |
|
598 | - SPCO_INC_PATH, |
|
599 | - 'EE_Checkout', |
|
600 | - 'class', array(), |
|
601 | - false |
|
602 | - ); |
|
603 | - } else { |
|
604 | - if ($checkout->current_step->is_final_step() && $checkout->exit_spco() === true) { |
|
605 | - $this->unlock_transaction(); |
|
606 | - wp_safe_redirect($checkout->redirect_url); |
|
607 | - exit(); |
|
608 | - } |
|
609 | - } |
|
610 | - $checkout = apply_filters('FHEE__EED_Single_Page_Checkout___initialize_checkout__checkout', $checkout); |
|
611 | - // verify again |
|
612 | - if ( ! $checkout instanceof EE_Checkout) { |
|
613 | - throw new EE_Error(__('The EE_Checkout class could not be loaded.', 'event_espresso')); |
|
614 | - } |
|
615 | - // reset anything that needs a clean slate for each request |
|
616 | - $checkout->reset_for_current_request(); |
|
617 | - return $checkout; |
|
618 | - } |
|
619 | - |
|
620 | - |
|
621 | - |
|
622 | - /** |
|
623 | - * _get_request_vars |
|
624 | - * |
|
625 | - * @access private |
|
626 | - * @return void |
|
627 | - * @throws EE_Error |
|
628 | - */ |
|
629 | - private function _get_request_vars() |
|
630 | - { |
|
631 | - // load classes |
|
632 | - EED_Single_Page_Checkout::load_request_handler(); |
|
633 | - //make sure this request is marked as belonging to EE |
|
634 | - EE_Registry::instance()->REQ->set_espresso_page(true); |
|
635 | - // which step is being requested ? |
|
636 | - $this->checkout->step = EE_Registry::instance()->REQ->get('step', $this->_get_first_step()); |
|
637 | - // which step is being edited ? |
|
638 | - $this->checkout->edit_step = EE_Registry::instance()->REQ->get('edit_step', ''); |
|
639 | - // and what we're doing on the current step |
|
640 | - $this->checkout->action = EE_Registry::instance()->REQ->get('action', 'display_spco_reg_step'); |
|
641 | - // timestamp |
|
642 | - $this->checkout->uts = EE_Registry::instance()->REQ->get('uts', 0); |
|
643 | - // returning to edit ? |
|
644 | - $this->checkout->reg_url_link = EE_Registry::instance()->REQ->get('e_reg_url_link', ''); |
|
645 | - // add reg url link to registration query params |
|
646 | - if ($this->checkout->reg_url_link && strpos($this->checkout->reg_url_link, '1-') !== 0) { |
|
647 | - $this->checkout->reg_cache_where_params[0]['REG_url_link'] = $this->checkout->reg_url_link; |
|
648 | - } |
|
649 | - // or some other kind of revisit ? |
|
650 | - $this->checkout->revisit = filter_var( |
|
651 | - EE_Registry::instance()->REQ->get('revisit', false), |
|
652 | - FILTER_VALIDATE_BOOLEAN |
|
653 | - ); |
|
654 | - // and whether or not to generate a reg form for this request |
|
655 | - $this->checkout->generate_reg_form = filter_var( |
|
656 | - EE_Registry::instance()->REQ->get('generate_reg_form', true), |
|
657 | - FILTER_VALIDATE_BOOLEAN |
|
658 | - ); |
|
659 | - // and whether or not to process a reg form submission for this request |
|
660 | - $this->checkout->process_form_submission = filter_var( |
|
661 | - EE_Registry::instance()->REQ->get( |
|
662 | - 'process_form_submission', |
|
663 | - $this->checkout->action === 'process_reg_step' |
|
664 | - ), |
|
665 | - FILTER_VALIDATE_BOOLEAN |
|
666 | - ); |
|
667 | - $this->checkout->process_form_submission = filter_var( |
|
668 | - $this->checkout->action !== 'display_spco_reg_step' |
|
669 | - ? $this->checkout->process_form_submission |
|
670 | - : false, |
|
671 | - FILTER_VALIDATE_BOOLEAN |
|
672 | - ); |
|
673 | - // $this->_display_request_vars(); |
|
674 | - } |
|
675 | - |
|
676 | - |
|
677 | - |
|
678 | - /** |
|
679 | - * _display_request_vars |
|
680 | - * |
|
681 | - * @access protected |
|
682 | - * @return void |
|
683 | - */ |
|
684 | - protected function _display_request_vars() |
|
685 | - { |
|
686 | - if ( ! WP_DEBUG) { |
|
687 | - return; |
|
688 | - } |
|
689 | - EEH_Debug_Tools::printr($_REQUEST, '$_REQUEST', __FILE__, __LINE__); |
|
690 | - EEH_Debug_Tools::printr($this->checkout->step, '$this->checkout->step', __FILE__, __LINE__); |
|
691 | - EEH_Debug_Tools::printr($this->checkout->edit_step, '$this->checkout->edit_step', __FILE__, __LINE__); |
|
692 | - EEH_Debug_Tools::printr($this->checkout->action, '$this->checkout->action', __FILE__, __LINE__); |
|
693 | - EEH_Debug_Tools::printr($this->checkout->reg_url_link, '$this->checkout->reg_url_link', __FILE__, __LINE__); |
|
694 | - EEH_Debug_Tools::printr($this->checkout->revisit, '$this->checkout->revisit', __FILE__, __LINE__); |
|
695 | - EEH_Debug_Tools::printr($this->checkout->generate_reg_form, '$this->checkout->generate_reg_form', __FILE__, __LINE__); |
|
696 | - EEH_Debug_Tools::printr($this->checkout->process_form_submission, '$this->checkout->process_form_submission', __FILE__, __LINE__); |
|
697 | - } |
|
698 | - |
|
699 | - |
|
700 | - |
|
701 | - /** |
|
702 | - * _block_bots |
|
703 | - * checks that the incoming request has either of the following set: |
|
704 | - * a uts (unix timestamp) which indicates that the request was redirected from the Ticket Selector |
|
705 | - * a REG URL Link, which indicates that the request is a return visit to SPCO for a valid TXN |
|
706 | - * so if you're not coming from the Ticket Selector nor returning for a valid IP... |
|
707 | - * then where you coming from man? |
|
708 | - * |
|
709 | - * @return boolean |
|
710 | - */ |
|
711 | - private function _block_bots() |
|
712 | - { |
|
713 | - $invalid_checkout_access = EED_Invalid_Checkout_Access::getInvalidCheckoutAccess(); |
|
714 | - if ($invalid_checkout_access->checkoutAccessIsInvalid($this->checkout)) { |
|
715 | - return true; |
|
716 | - } |
|
717 | - return false; |
|
718 | - } |
|
719 | - |
|
720 | - |
|
721 | - |
|
722 | - /** |
|
723 | - * _get_first_step |
|
724 | - * gets slug for first step in $_reg_steps_array |
|
725 | - * |
|
726 | - * @access private |
|
727 | - * @throws EE_Error |
|
728 | - * @return string |
|
729 | - */ |
|
730 | - private function _get_first_step() |
|
731 | - { |
|
732 | - $first_step = reset(EED_Single_Page_Checkout::$_reg_steps_array); |
|
733 | - return isset($first_step['slug']) ? $first_step['slug'] : 'attendee_information'; |
|
734 | - } |
|
735 | - |
|
736 | - |
|
737 | - |
|
738 | - /** |
|
739 | - * _load_and_instantiate_reg_steps |
|
740 | - * instantiates each reg step based on the loaded reg_steps array |
|
741 | - * |
|
742 | - * @access private |
|
743 | - * @throws EE_Error |
|
744 | - * @return bool |
|
745 | - */ |
|
746 | - private function _load_and_instantiate_reg_steps() |
|
747 | - { |
|
748 | - do_action('AHEE__Single_Page_Checkout___load_and_instantiate_reg_steps__start', $this->checkout); |
|
749 | - // have reg_steps already been instantiated ? |
|
750 | - if ( |
|
751 | - empty($this->checkout->reg_steps) |
|
752 | - || apply_filters('FHEE__Single_Page_Checkout__load_reg_steps__reload_reg_steps', false, $this->checkout) |
|
753 | - ) { |
|
754 | - // if not, then loop through raw reg steps array |
|
755 | - foreach (EED_Single_Page_Checkout::$_reg_steps_array as $order => $reg_step) { |
|
756 | - if ( ! $this->_load_and_instantiate_reg_step($reg_step, $order)) { |
|
757 | - return false; |
|
758 | - } |
|
759 | - } |
|
760 | - EE_Registry::instance()->CFG->registration->skip_reg_confirmation = true; |
|
761 | - EE_Registry::instance()->CFG->registration->reg_confirmation_last = true; |
|
762 | - // skip the registration_confirmation page ? |
|
763 | - if (EE_Registry::instance()->CFG->registration->skip_reg_confirmation) { |
|
764 | - // just remove it from the reg steps array |
|
765 | - $this->checkout->remove_reg_step('registration_confirmation', false); |
|
766 | - } else if ( |
|
767 | - isset($this->checkout->reg_steps['registration_confirmation']) |
|
768 | - && EE_Registry::instance()->CFG->registration->reg_confirmation_last |
|
769 | - ) { |
|
770 | - // set the order to something big like 100 |
|
771 | - $this->checkout->set_reg_step_order('registration_confirmation', 100); |
|
772 | - } |
|
773 | - // filter the array for good luck |
|
774 | - $this->checkout->reg_steps = apply_filters( |
|
775 | - 'FHEE__Single_Page_Checkout__load_reg_steps__reg_steps', |
|
776 | - $this->checkout->reg_steps |
|
777 | - ); |
|
778 | - // finally re-sort based on the reg step class order properties |
|
779 | - $this->checkout->sort_reg_steps(); |
|
780 | - } else { |
|
781 | - foreach ($this->checkout->reg_steps as $reg_step) { |
|
782 | - // set all current step stati to FALSE |
|
783 | - $reg_step->set_is_current_step(false); |
|
784 | - } |
|
785 | - } |
|
786 | - if (empty($this->checkout->reg_steps)) { |
|
787 | - EE_Error::add_error( |
|
788 | - __('No Reg Steps were loaded..', 'event_espresso'), |
|
789 | - __FILE__, __FUNCTION__, __LINE__ |
|
790 | - ); |
|
791 | - return false; |
|
792 | - } |
|
793 | - // make reg step details available to JS |
|
794 | - $this->checkout->set_reg_step_JSON_info(); |
|
795 | - return true; |
|
796 | - } |
|
797 | - |
|
798 | - |
|
799 | - |
|
800 | - /** |
|
801 | - * _load_and_instantiate_reg_step |
|
802 | - * |
|
803 | - * @access private |
|
804 | - * @param array $reg_step |
|
805 | - * @param int $order |
|
806 | - * @return bool |
|
807 | - */ |
|
808 | - private function _load_and_instantiate_reg_step($reg_step = array(), $order = 0) |
|
809 | - { |
|
810 | - // we need a file_path, class_name, and slug to add a reg step |
|
811 | - if (isset($reg_step['file_path'], $reg_step['class_name'], $reg_step['slug'])) { |
|
812 | - // if editing a specific step, but this is NOT that step... (and it's not the 'finalize_registration' step) |
|
813 | - if ( |
|
814 | - $this->checkout->reg_url_link |
|
815 | - && $this->checkout->step !== $reg_step['slug'] |
|
816 | - && $reg_step['slug'] !== 'finalize_registration' |
|
817 | - // normally at this point we would NOT load the reg step, but this filter can change that |
|
818 | - && apply_filters( |
|
819 | - 'FHEE__Single_Page_Checkout___load_and_instantiate_reg_step__bypass_reg_step', |
|
820 | - true, |
|
821 | - $reg_step, |
|
822 | - $this->checkout |
|
823 | - ) |
|
824 | - ) { |
|
825 | - return true; |
|
826 | - } |
|
827 | - // instantiate step class using file path and class name |
|
828 | - $reg_step_obj = EE_Registry::instance()->load_file( |
|
829 | - $reg_step['file_path'], |
|
830 | - $reg_step['class_name'], |
|
831 | - 'class', |
|
832 | - $this->checkout, |
|
833 | - false |
|
834 | - ); |
|
835 | - // did we gets the goods ? |
|
836 | - if ($reg_step_obj instanceof EE_SPCO_Reg_Step) { |
|
837 | - // set reg step order based on config |
|
838 | - $reg_step_obj->set_order($order); |
|
839 | - // add instantiated reg step object to the master reg steps array |
|
840 | - $this->checkout->add_reg_step($reg_step_obj); |
|
841 | - } else { |
|
842 | - EE_Error::add_error( |
|
843 | - __('The current step could not be set.', 'event_espresso'), |
|
844 | - __FILE__, __FUNCTION__, __LINE__ |
|
845 | - ); |
|
846 | - return false; |
|
847 | - } |
|
848 | - } else { |
|
849 | - if (WP_DEBUG) { |
|
850 | - EE_Error::add_error( |
|
851 | - sprintf( |
|
852 | - __( |
|
853 | - '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', |
|
854 | - 'event_espresso' |
|
855 | - ), |
|
856 | - isset($reg_step['file_path']) ? $reg_step['file_path'] : '', |
|
857 | - isset($reg_step['class_name']) ? $reg_step['class_name'] : '', |
|
858 | - isset($reg_step['slug']) ? $reg_step['slug'] : '', |
|
859 | - '<ul>', |
|
860 | - '<li>', |
|
861 | - '</li>', |
|
862 | - '</ul>' |
|
863 | - ), |
|
864 | - __FILE__, __FUNCTION__, __LINE__ |
|
865 | - ); |
|
866 | - } |
|
867 | - return false; |
|
868 | - } |
|
869 | - return true; |
|
870 | - } |
|
871 | - |
|
872 | - |
|
873 | - /** |
|
874 | - * _verify_transaction_and_get_registrations |
|
875 | - * |
|
876 | - * @access private |
|
877 | - * @return bool |
|
878 | - * @throws InvalidDataTypeException |
|
879 | - * @throws InvalidEntityException |
|
880 | - * @throws EE_Error |
|
881 | - */ |
|
882 | - private function _verify_transaction_and_get_registrations() |
|
883 | - { |
|
884 | - // was there already a valid transaction in the checkout from the session ? |
|
885 | - if ( ! $this->checkout->transaction instanceof EE_Transaction) { |
|
886 | - // get transaction from db or session |
|
887 | - $this->checkout->transaction = $this->checkout->reg_url_link && ! is_admin() |
|
888 | - ? $this->_get_transaction_and_cart_for_previous_visit() |
|
889 | - : $this->_get_cart_for_current_session_and_setup_new_transaction(); |
|
890 | - if ( ! $this->checkout->transaction instanceof EE_Transaction) { |
|
891 | - EE_Error::add_error( |
|
892 | - __('Your Registration and Transaction information could not be retrieved from the db.', |
|
893 | - 'event_espresso'), |
|
894 | - __FILE__, __FUNCTION__, __LINE__ |
|
895 | - ); |
|
896 | - $this->checkout->transaction = EE_Transaction::new_instance(); |
|
897 | - // add some style and make it dance |
|
898 | - $this->add_styles_and_scripts(); |
|
899 | - EED_Single_Page_Checkout::$_initialized = true; |
|
900 | - return false; |
|
901 | - } |
|
902 | - // and the registrations for the transaction |
|
903 | - $this->_get_registrations($this->checkout->transaction); |
|
904 | - } |
|
905 | - return true; |
|
906 | - } |
|
907 | - |
|
908 | - |
|
909 | - |
|
910 | - /** |
|
911 | - * _get_transaction_and_cart_for_previous_visit |
|
912 | - * |
|
913 | - * @access private |
|
914 | - * @return mixed EE_Transaction|NULL |
|
915 | - */ |
|
916 | - private function _get_transaction_and_cart_for_previous_visit() |
|
917 | - { |
|
918 | - /** @var $TXN_model EEM_Transaction */ |
|
919 | - $TXN_model = EE_Registry::instance()->load_model('Transaction'); |
|
920 | - // because the reg_url_link is present in the request, |
|
921 | - // this is a return visit to SPCO, so we'll get the transaction data from the db |
|
922 | - $transaction = $TXN_model->get_transaction_from_reg_url_link($this->checkout->reg_url_link); |
|
923 | - // verify transaction |
|
924 | - if ($transaction instanceof EE_Transaction) { |
|
925 | - // and get the cart that was used for that transaction |
|
926 | - $this->checkout->cart = $this->_get_cart_for_transaction($transaction); |
|
927 | - return $transaction; |
|
928 | - } |
|
929 | - EE_Error::add_error( |
|
930 | - __('Your Registration and Transaction information could not be retrieved from the db.', 'event_espresso'), |
|
931 | - __FILE__, __FUNCTION__, __LINE__ |
|
932 | - ); |
|
933 | - return null; |
|
934 | - |
|
935 | - } |
|
936 | - |
|
937 | - |
|
938 | - |
|
939 | - /** |
|
940 | - * _get_cart_for_transaction |
|
941 | - * |
|
942 | - * @access private |
|
943 | - * @param EE_Transaction $transaction |
|
944 | - * @return EE_Cart |
|
945 | - */ |
|
946 | - private function _get_cart_for_transaction($transaction) |
|
947 | - { |
|
948 | - return $this->checkout->get_cart_for_transaction($transaction); |
|
949 | - } |
|
950 | - |
|
951 | - |
|
952 | - |
|
953 | - /** |
|
954 | - * get_cart_for_transaction |
|
955 | - * |
|
956 | - * @access public |
|
957 | - * @param EE_Transaction $transaction |
|
958 | - * @return EE_Cart |
|
959 | - */ |
|
960 | - public function get_cart_for_transaction(EE_Transaction $transaction) |
|
961 | - { |
|
962 | - return $this->checkout->get_cart_for_transaction($transaction); |
|
963 | - } |
|
964 | - |
|
965 | - |
|
966 | - |
|
967 | - /** |
|
968 | - * _get_transaction_and_cart_for_current_session |
|
969 | - * generates a new EE_Transaction object and adds it to the $_transaction property. |
|
970 | - * |
|
971 | - * @access private |
|
972 | - * @return EE_Transaction |
|
973 | - * @throws EE_Error |
|
974 | - */ |
|
975 | - private function _get_cart_for_current_session_and_setup_new_transaction() |
|
976 | - { |
|
977 | - // if there's no transaction, then this is the FIRST visit to SPCO |
|
978 | - // so load up the cart ( passing nothing for the TXN because it doesn't exist yet ) |
|
979 | - $this->checkout->cart = $this->_get_cart_for_transaction(null); |
|
980 | - // and then create a new transaction |
|
981 | - $transaction = $this->_initialize_transaction(); |
|
982 | - // verify transaction |
|
983 | - if ($transaction instanceof EE_Transaction) { |
|
984 | - // save it so that we have an ID for other objects to use |
|
985 | - $transaction->save(); |
|
986 | - // and save TXN data to the cart |
|
987 | - $this->checkout->cart->get_grand_total()->save_this_and_descendants_to_txn($transaction->ID()); |
|
988 | - } else { |
|
989 | - EE_Error::add_error( |
|
990 | - __('A Valid Transaction could not be initialized.', 'event_espresso'), |
|
991 | - __FILE__, __FUNCTION__, __LINE__ |
|
992 | - ); |
|
993 | - } |
|
994 | - return $transaction; |
|
995 | - } |
|
996 | - |
|
997 | - |
|
998 | - |
|
999 | - /** |
|
1000 | - * generates a new EE_Transaction object and adds it to the $_transaction property. |
|
1001 | - * |
|
1002 | - * @access private |
|
1003 | - * @return mixed EE_Transaction|NULL |
|
1004 | - */ |
|
1005 | - private function _initialize_transaction() |
|
1006 | - { |
|
1007 | - try { |
|
1008 | - // ensure cart totals have been calculated |
|
1009 | - $this->checkout->cart->get_grand_total()->recalculate_total_including_taxes(); |
|
1010 | - // grab the cart grand total |
|
1011 | - $cart_total = $this->checkout->cart->get_cart_grand_total(); |
|
1012 | - // create new TXN |
|
1013 | - $transaction = EE_Transaction::new_instance( |
|
1014 | - array( |
|
1015 | - 'TXN_reg_steps' => $this->checkout->initialize_txn_reg_steps_array(), |
|
1016 | - 'TXN_total' => $cart_total > 0 ? $cart_total : 0, |
|
1017 | - 'TXN_paid' => 0, |
|
1018 | - 'STS_ID' => EEM_Transaction::failed_status_code, |
|
1019 | - ) |
|
1020 | - ); |
|
1021 | - // save it so that we have an ID for other objects to use |
|
1022 | - $transaction->save(); |
|
1023 | - // set cron job for following up on TXNs after their session has expired |
|
1024 | - EE_Cron_Tasks::schedule_expired_transaction_check( |
|
1025 | - EE_Registry::instance()->SSN->expiration() + 1, |
|
1026 | - $transaction->ID() |
|
1027 | - ); |
|
1028 | - return $transaction; |
|
1029 | - } catch (Exception $e) { |
|
1030 | - EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
1031 | - } |
|
1032 | - return null; |
|
1033 | - } |
|
1034 | - |
|
1035 | - |
|
1036 | - /** |
|
1037 | - * _get_registrations |
|
1038 | - * |
|
1039 | - * @access private |
|
1040 | - * @param EE_Transaction $transaction |
|
1041 | - * @return void |
|
1042 | - * @throws InvalidDataTypeException |
|
1043 | - * @throws InvalidEntityException |
|
1044 | - * @throws EE_Error |
|
1045 | - */ |
|
1046 | - private function _get_registrations(EE_Transaction $transaction) |
|
1047 | - { |
|
1048 | - // first step: grab the registrants { : o |
|
1049 | - $registrations = $transaction->registrations($this->checkout->reg_cache_where_params, false); |
|
1050 | - $this->checkout->total_ticket_count = count($registrations); |
|
1051 | - // verify registrations have been set |
|
1052 | - if (empty($registrations)) { |
|
1053 | - // if no cached registrations, then check the db |
|
1054 | - $registrations = $transaction->registrations($this->checkout->reg_cache_where_params, false); |
|
1055 | - // still nothing ? well as long as this isn't a revisit |
|
1056 | - if (empty($registrations) && ! $this->checkout->revisit) { |
|
1057 | - // generate new registrations from scratch |
|
1058 | - $registrations = $this->_initialize_registrations($transaction); |
|
1059 | - } |
|
1060 | - } |
|
1061 | - // sort by their original registration order |
|
1062 | - usort($registrations, array('EED_Single_Page_Checkout', 'sort_registrations_by_REG_count')); |
|
1063 | - // then loop thru the array |
|
1064 | - foreach ($registrations as $registration) { |
|
1065 | - // verify each registration |
|
1066 | - if ($registration instanceof EE_Registration) { |
|
1067 | - // we display all attendee info for the primary registrant |
|
1068 | - if ($this->checkout->reg_url_link === $registration->reg_url_link() |
|
1069 | - && $registration->is_primary_registrant() |
|
1070 | - ) { |
|
1071 | - $this->checkout->primary_revisit = true; |
|
1072 | - break; |
|
1073 | - } |
|
1074 | - if ($this->checkout->revisit && $this->checkout->reg_url_link !== $registration->reg_url_link()) { |
|
1075 | - // but hide info if it doesn't belong to you |
|
1076 | - $transaction->clear_cache('Registration', $registration->ID()); |
|
1077 | - $this->checkout->total_ticket_count--; |
|
1078 | - } |
|
1079 | - $this->checkout->set_reg_status_updated($registration->ID(), false); |
|
1080 | - } |
|
1081 | - } |
|
1082 | - } |
|
1083 | - |
|
1084 | - |
|
1085 | - /** |
|
1086 | - * adds related EE_Registration objects for each ticket in the cart to the current EE_Transaction object |
|
1087 | - * |
|
1088 | - * @access private |
|
1089 | - * @param EE_Transaction $transaction |
|
1090 | - * @return array |
|
1091 | - * @throws InvalidDataTypeException |
|
1092 | - * @throws InvalidEntityException |
|
1093 | - * @throws EE_Error |
|
1094 | - */ |
|
1095 | - private function _initialize_registrations(EE_Transaction $transaction) |
|
1096 | - { |
|
1097 | - $att_nmbr = 0; |
|
1098 | - $registrations = array(); |
|
1099 | - if ($transaction instanceof EE_Transaction) { |
|
1100 | - /** @type EE_Registration_Processor $registration_processor */ |
|
1101 | - $registration_processor = EE_Registry::instance()->load_class('Registration_Processor'); |
|
1102 | - $this->checkout->total_ticket_count = $this->checkout->cart->all_ticket_quantity_count(); |
|
1103 | - // now let's add the cart items to the $transaction |
|
1104 | - foreach ($this->checkout->cart->get_tickets() as $line_item) { |
|
1105 | - //do the following for each ticket of this type they selected |
|
1106 | - for ($x = 1; $x <= $line_item->quantity(); $x++) { |
|
1107 | - $att_nmbr++; |
|
1108 | - /** @var EventEspresso\core\services\commands\registration\CreateRegistrationCommand $CreateRegistrationCommand */ |
|
1109 | - $CreateRegistrationCommand = EE_Registry::instance()->create( |
|
1110 | - 'EventEspresso\core\services\commands\registration\CreateRegistrationCommand', |
|
1111 | - array( |
|
1112 | - $transaction, |
|
1113 | - $line_item, |
|
1114 | - $att_nmbr, |
|
1115 | - $this->checkout->total_ticket_count, |
|
1116 | - ) |
|
1117 | - ); |
|
1118 | - // override capabilities for frontend registrations |
|
1119 | - if ( ! is_admin()) { |
|
1120 | - $CreateRegistrationCommand->setCapCheck( |
|
1121 | - new PublicCapabilities('', 'create_new_registration') |
|
1122 | - ); |
|
1123 | - } |
|
1124 | - $registration = EE_Registry::instance()->BUS->execute($CreateRegistrationCommand); |
|
1125 | - if ( ! $registration instanceof EE_Registration) { |
|
1126 | - throw new InvalidEntityException($registration, 'EE_Registration'); |
|
1127 | - } |
|
1128 | - $registrations[ $registration->ID() ] = $registration; |
|
1129 | - } |
|
1130 | - } |
|
1131 | - $registration_processor->fix_reg_final_price_rounding_issue($transaction); |
|
1132 | - } |
|
1133 | - return $registrations; |
|
1134 | - } |
|
1135 | - |
|
1136 | - |
|
1137 | - |
|
1138 | - /** |
|
1139 | - * sorts registrations by REG_count |
|
1140 | - * |
|
1141 | - * @access public |
|
1142 | - * @param EE_Registration $reg_A |
|
1143 | - * @param EE_Registration $reg_B |
|
1144 | - * @return int |
|
1145 | - */ |
|
1146 | - public static function sort_registrations_by_REG_count(EE_Registration $reg_A, EE_Registration $reg_B) |
|
1147 | - { |
|
1148 | - // this shouldn't ever happen within the same TXN, but oh well |
|
1149 | - if ($reg_A->count() === $reg_B->count()) { |
|
1150 | - return 0; |
|
1151 | - } |
|
1152 | - return ($reg_A->count() > $reg_B->count()) ? 1 : -1; |
|
1153 | - } |
|
1154 | - |
|
1155 | - |
|
1156 | - |
|
1157 | - /** |
|
1158 | - * _final_verifications |
|
1159 | - * just makes sure that everything is set up correctly before proceeding |
|
1160 | - * |
|
1161 | - * @access private |
|
1162 | - * @return bool |
|
1163 | - * @throws EE_Error |
|
1164 | - */ |
|
1165 | - private function _final_verifications() |
|
1166 | - { |
|
1167 | - // filter checkout |
|
1168 | - $this->checkout = apply_filters( |
|
1169 | - 'FHEE__EED_Single_Page_Checkout___final_verifications__checkout', |
|
1170 | - $this->checkout |
|
1171 | - ); |
|
1172 | - //verify that current step is still set correctly |
|
1173 | - if ( ! $this->checkout->current_step instanceof EE_SPCO_Reg_Step) { |
|
1174 | - EE_Error::add_error( |
|
1175 | - __('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.', 'event_espresso'), |
|
1176 | - __FILE__, |
|
1177 | - __FUNCTION__, |
|
1178 | - __LINE__ |
|
1179 | - ); |
|
1180 | - return false; |
|
1181 | - } |
|
1182 | - // if returning to SPCO, then verify that primary registrant is set |
|
1183 | - if ( ! empty($this->checkout->reg_url_link)) { |
|
1184 | - $valid_registrant = $this->checkout->transaction->primary_registration(); |
|
1185 | - if ( ! $valid_registrant instanceof EE_Registration) { |
|
1186 | - EE_Error::add_error( |
|
1187 | - __('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.', 'event_espresso'), |
|
1188 | - __FILE__, |
|
1189 | - __FUNCTION__, |
|
1190 | - __LINE__ |
|
1191 | - ); |
|
1192 | - return false; |
|
1193 | - } |
|
1194 | - $valid_registrant = null; |
|
1195 | - foreach ( |
|
1196 | - $this->checkout->transaction->registrations($this->checkout->reg_cache_where_params) as $registration |
|
1197 | - ) { |
|
1198 | - if ( |
|
1199 | - $registration instanceof EE_Registration |
|
1200 | - && $registration->reg_url_link() === $this->checkout->reg_url_link |
|
1201 | - ) { |
|
1202 | - $valid_registrant = $registration; |
|
1203 | - } |
|
1204 | - } |
|
1205 | - if ( ! $valid_registrant instanceof EE_Registration) { |
|
1206 | - // hmmm... maybe we have the wrong session because the user is opening multiple tabs ? |
|
1207 | - if (EED_Single_Page_Checkout::$_checkout_verified) { |
|
1208 | - // clear the session, mark the checkout as unverified, and try again |
|
1209 | - EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__); |
|
1210 | - EED_Single_Page_Checkout::$_initialized = false; |
|
1211 | - EED_Single_Page_Checkout::$_checkout_verified = false; |
|
1212 | - $this->_initialize(); |
|
1213 | - EE_Error::reset_notices(); |
|
1214 | - return false; |
|
1215 | - } |
|
1216 | - EE_Error::add_error( |
|
1217 | - __( |
|
1218 | - '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.', |
|
1219 | - 'event_espresso' |
|
1220 | - ), |
|
1221 | - __FILE__, |
|
1222 | - __FUNCTION__, |
|
1223 | - __LINE__ |
|
1224 | - ); |
|
1225 | - return false; |
|
1226 | - } |
|
1227 | - } |
|
1228 | - // now that things have been kinda sufficiently verified, |
|
1229 | - // let's add the checkout to the session so that it's available to other systems |
|
1230 | - EE_Registry::instance()->SSN->set_checkout($this->checkout); |
|
1231 | - return true; |
|
1232 | - } |
|
1233 | - |
|
1234 | - |
|
1235 | - |
|
1236 | - /** |
|
1237 | - * _initialize_reg_steps |
|
1238 | - * first makes sure that EE_Transaction_Processor::set_reg_step_initiated() is called as required |
|
1239 | - * then loops thru all of the active reg steps and calls the initialize_reg_step() method |
|
1240 | - * |
|
1241 | - * @access private |
|
1242 | - * @param bool $reinitializing |
|
1243 | - * @throws EE_Error |
|
1244 | - */ |
|
1245 | - private function _initialize_reg_steps($reinitializing = false) |
|
1246 | - { |
|
1247 | - $this->checkout->set_reg_step_initiated($this->checkout->current_step); |
|
1248 | - // loop thru all steps to call their individual "initialize" methods and set i18n strings for JS |
|
1249 | - foreach ($this->checkout->reg_steps as $reg_step) { |
|
1250 | - if ( ! $reg_step->initialize_reg_step()) { |
|
1251 | - // if not initialized then maybe this step is being removed... |
|
1252 | - if ( ! $reinitializing && $reg_step->is_current_step()) { |
|
1253 | - // if it was the current step, then we need to start over here |
|
1254 | - $this->_initialize_reg_steps(true); |
|
1255 | - return; |
|
1256 | - } |
|
1257 | - continue; |
|
1258 | - } |
|
1259 | - // add css and JS for current step |
|
1260 | - $reg_step->enqueue_styles_and_scripts(); |
|
1261 | - // i18n |
|
1262 | - $reg_step->translate_js_strings(); |
|
1263 | - if ($reg_step->is_current_step()) { |
|
1264 | - // the text that appears on the reg step form submit button |
|
1265 | - $reg_step->set_submit_button_text(); |
|
1266 | - } |
|
1267 | - } |
|
1268 | - // dynamically creates hook point like: AHEE__Single_Page_Checkout___initialize_reg_step__attendee_information |
|
1269 | - do_action( |
|
1270 | - "AHEE__Single_Page_Checkout___initialize_reg_step__{$this->checkout->current_step->slug()}", |
|
1271 | - $this->checkout->current_step |
|
1272 | - ); |
|
1273 | - } |
|
1274 | - |
|
1275 | - |
|
1276 | - |
|
1277 | - /** |
|
1278 | - * _check_form_submission |
|
1279 | - * |
|
1280 | - * @access private |
|
1281 | - * @return boolean |
|
1282 | - */ |
|
1283 | - private function _check_form_submission() |
|
1284 | - { |
|
1285 | - //does this request require the reg form to be generated ? |
|
1286 | - if ($this->checkout->generate_reg_form) { |
|
1287 | - // ever heard that song by Blue Rodeo ? |
|
1288 | - try { |
|
1289 | - $this->checkout->current_step->reg_form = $this->checkout->current_step->generate_reg_form(); |
|
1290 | - // if not displaying a form, then check for form submission |
|
1291 | - if ( |
|
1292 | - $this->checkout->process_form_submission |
|
1293 | - && $this->checkout->current_step->reg_form->was_submitted() |
|
1294 | - ) { |
|
1295 | - // clear out any old data in case this step is being run again |
|
1296 | - $this->checkout->current_step->set_valid_data(array()); |
|
1297 | - // capture submitted form data |
|
1298 | - $this->checkout->current_step->reg_form->receive_form_submission( |
|
1299 | - apply_filters( |
|
1300 | - 'FHEE__Single_Page_Checkout___check_form_submission__request_params', |
|
1301 | - EE_Registry::instance()->REQ->params(), |
|
1302 | - $this->checkout |
|
1303 | - ) |
|
1304 | - ); |
|
1305 | - // validate submitted form data |
|
1306 | - if ( ! $this->checkout->continue_reg || ! $this->checkout->current_step->reg_form->is_valid()) { |
|
1307 | - // thou shall not pass !!! |
|
1308 | - $this->checkout->continue_reg = false; |
|
1309 | - // any form validation errors? |
|
1310 | - if ($this->checkout->current_step->reg_form->submission_error_message() !== '') { |
|
1311 | - $submission_error_messages = array(); |
|
1312 | - // bad, bad, bad registrant |
|
1313 | - foreach ( |
|
1314 | - $this->checkout->current_step->reg_form->get_validation_errors_accumulated() |
|
1315 | - as $validation_error |
|
1316 | - ) { |
|
1317 | - if ($validation_error instanceof EE_Validation_Error) { |
|
1318 | - $submission_error_messages[] = sprintf( |
|
1319 | - __('%s : %s', 'event_espresso'), |
|
1320 | - $validation_error->get_form_section()->html_label_text(), |
|
1321 | - $validation_error->getMessage() |
|
1322 | - ); |
|
1323 | - } |
|
1324 | - } |
|
1325 | - EE_Error::add_error( |
|
1326 | - implode('<br />', $submission_error_messages), |
|
1327 | - __FILE__, __FUNCTION__, __LINE__ |
|
1328 | - ); |
|
1329 | - } |
|
1330 | - // well not really... what will happen is |
|
1331 | - // we'll just get redirected back to redo the current step |
|
1332 | - $this->go_to_next_step(); |
|
1333 | - return false; |
|
1334 | - } |
|
1335 | - } |
|
1336 | - } catch (EE_Error $e) { |
|
1337 | - $e->get_error(); |
|
1338 | - } |
|
1339 | - } |
|
1340 | - return true; |
|
1341 | - } |
|
1342 | - |
|
1343 | - |
|
1344 | - |
|
1345 | - /** |
|
1346 | - * _process_action |
|
1347 | - * |
|
1348 | - * @access private |
|
1349 | - * @return void |
|
1350 | - * @throws EE_Error |
|
1351 | - */ |
|
1352 | - private function _process_form_action() |
|
1353 | - { |
|
1354 | - // what cha wanna do? |
|
1355 | - switch ($this->checkout->action) { |
|
1356 | - // AJAX next step reg form |
|
1357 | - case 'display_spco_reg_step' : |
|
1358 | - $this->checkout->redirect = false; |
|
1359 | - if (EE_Registry::instance()->REQ->ajax) { |
|
1360 | - $this->checkout->json_response->set_reg_step_html( |
|
1361 | - $this->checkout->current_step->display_reg_form() |
|
1362 | - ); |
|
1363 | - } |
|
1364 | - break; |
|
1365 | - default : |
|
1366 | - // meh... do one of those other steps first |
|
1367 | - if ( |
|
1368 | - ! empty($this->checkout->action) |
|
1369 | - && is_callable(array($this->checkout->current_step, $this->checkout->action)) |
|
1370 | - ) { |
|
1371 | - // dynamically creates hook point like: |
|
1372 | - // AHEE__Single_Page_Checkout__before_attendee_information__process_reg_step |
|
1373 | - do_action( |
|
1374 | - "AHEE__Single_Page_Checkout__before_{$this->checkout->current_step->slug()}__{$this->checkout->action}", |
|
1375 | - $this->checkout->current_step |
|
1376 | - ); |
|
1377 | - // call action on current step |
|
1378 | - if (call_user_func(array($this->checkout->current_step, $this->checkout->action))) { |
|
1379 | - // good registrant, you get to proceed |
|
1380 | - if ( |
|
1381 | - $this->checkout->current_step->success_message() !== '' |
|
1382 | - && apply_filters( |
|
1383 | - 'FHEE__Single_Page_Checkout___process_form_action__display_success', |
|
1384 | - false |
|
1385 | - ) |
|
1386 | - ) { |
|
1387 | - EE_Error::add_success( |
|
1388 | - $this->checkout->current_step->success_message() |
|
1389 | - . '<br />' . $this->checkout->next_step->_instructions() |
|
1390 | - ); |
|
1391 | - } |
|
1392 | - // pack it up, pack it in... |
|
1393 | - $this->_setup_redirect(); |
|
1394 | - } |
|
1395 | - // dynamically creates hook point like: |
|
1396 | - // AHEE__Single_Page_Checkout__after_payment_options__process_reg_step |
|
1397 | - do_action( |
|
1398 | - "AHEE__Single_Page_Checkout__after_{$this->checkout->current_step->slug()}__{$this->checkout->action}", |
|
1399 | - $this->checkout->current_step |
|
1400 | - ); |
|
1401 | - } else { |
|
1402 | - EE_Error::add_error( |
|
1403 | - sprintf( |
|
1404 | - __( |
|
1405 | - 'The requested form action "%s" does not exist for the current "%s" registration step.', |
|
1406 | - 'event_espresso' |
|
1407 | - ), |
|
1408 | - $this->checkout->action, |
|
1409 | - $this->checkout->current_step->name() |
|
1410 | - ), |
|
1411 | - __FILE__, |
|
1412 | - __FUNCTION__, |
|
1413 | - __LINE__ |
|
1414 | - ); |
|
1415 | - } |
|
1416 | - // end default |
|
1417 | - } |
|
1418 | - // store our progress so far |
|
1419 | - $this->checkout->stash_transaction_and_checkout(); |
|
1420 | - // advance to the next step! If you pass GO, collect $200 |
|
1421 | - $this->go_to_next_step(); |
|
1422 | - } |
|
1423 | - |
|
1424 | - |
|
1425 | - |
|
1426 | - /** |
|
1427 | - * add_styles_and_scripts |
|
1428 | - * |
|
1429 | - * @access public |
|
1430 | - * @return void |
|
1431 | - */ |
|
1432 | - public function add_styles_and_scripts() |
|
1433 | - { |
|
1434 | - // i18n |
|
1435 | - $this->translate_js_strings(); |
|
1436 | - if ($this->checkout->admin_request) { |
|
1437 | - add_action('admin_enqueue_scripts', array($this, 'enqueue_styles_and_scripts'), 10); |
|
1438 | - } else { |
|
1439 | - add_action('wp_enqueue_scripts', array($this, 'enqueue_styles_and_scripts'), 10); |
|
1440 | - } |
|
1441 | - } |
|
1442 | - |
|
1443 | - |
|
1444 | - |
|
1445 | - /** |
|
1446 | - * translate_js_strings |
|
1447 | - * |
|
1448 | - * @access public |
|
1449 | - * @return void |
|
1450 | - */ |
|
1451 | - public function translate_js_strings() |
|
1452 | - { |
|
1453 | - EE_Registry::$i18n_js_strings['revisit'] = $this->checkout->revisit; |
|
1454 | - EE_Registry::$i18n_js_strings['e_reg_url_link'] = $this->checkout->reg_url_link; |
|
1455 | - EE_Registry::$i18n_js_strings['server_error'] = __( |
|
1456 | - 'An unknown error occurred on the server while attempting to process your request. Please refresh the page and try again or contact support.', |
|
1457 | - 'event_espresso' |
|
1458 | - ); |
|
1459 | - EE_Registry::$i18n_js_strings['invalid_json_response'] = __( |
|
1460 | - 'An invalid response was returned from the server while attempting to process your request. Please refresh the page and try again or contact support.', |
|
1461 | - 'event_espresso' |
|
1462 | - ); |
|
1463 | - EE_Registry::$i18n_js_strings['validation_error'] = __( |
|
1464 | - 'There appears to be a problem with the form validation configuration! Please check the admin settings or contact support.', |
|
1465 | - 'event_espresso' |
|
1466 | - ); |
|
1467 | - EE_Registry::$i18n_js_strings['invalid_payment_method'] = __( |
|
1468 | - 'There appears to be a problem with the payment method configuration! Please refresh the page and try again or contact support.', |
|
1469 | - 'event_espresso' |
|
1470 | - ); |
|
1471 | - EE_Registry::$i18n_js_strings['reg_step_error'] = __( |
|
1472 | - 'This registration step could not be completed. Please refresh the page and try again.', |
|
1473 | - 'event_espresso' |
|
1474 | - ); |
|
1475 | - EE_Registry::$i18n_js_strings['invalid_coupon'] = __( |
|
1476 | - 'We\'re sorry but that coupon code does not appear to be valid. If this is incorrect, please contact the site administrator.', |
|
1477 | - 'event_espresso' |
|
1478 | - ); |
|
1479 | - EE_Registry::$i18n_js_strings['process_registration'] = sprintf( |
|
1480 | - __( |
|
1481 | - 'Please wait while we process your registration.%sDo not refresh the page or navigate away while this is happening.%sThank you for your patience.', |
|
1482 | - 'event_espresso' |
|
1483 | - ), |
|
1484 | - '<br/>', |
|
1485 | - '<br/>' |
|
1486 | - ); |
|
1487 | - EE_Registry::$i18n_js_strings['language'] = get_bloginfo('language'); |
|
1488 | - EE_Registry::$i18n_js_strings['EESID'] = EE_Registry::instance()->SSN->id(); |
|
1489 | - EE_Registry::$i18n_js_strings['currency'] = EE_Registry::instance()->CFG->currency; |
|
1490 | - EE_Registry::$i18n_js_strings['datepicker_yearRange'] = '-150:+20'; |
|
1491 | - EE_Registry::$i18n_js_strings['timer_years'] = __('years', 'event_espresso'); |
|
1492 | - EE_Registry::$i18n_js_strings['timer_months'] = __('months', 'event_espresso'); |
|
1493 | - EE_Registry::$i18n_js_strings['timer_weeks'] = __('weeks', 'event_espresso'); |
|
1494 | - EE_Registry::$i18n_js_strings['timer_days'] = __('days', 'event_espresso'); |
|
1495 | - EE_Registry::$i18n_js_strings['timer_hours'] = __('hours', 'event_espresso'); |
|
1496 | - EE_Registry::$i18n_js_strings['timer_minutes'] = __('minutes', 'event_espresso'); |
|
1497 | - EE_Registry::$i18n_js_strings['timer_seconds'] = __('seconds', 'event_espresso'); |
|
1498 | - EE_Registry::$i18n_js_strings['timer_year'] = __('year', 'event_espresso'); |
|
1499 | - EE_Registry::$i18n_js_strings['timer_month'] = __('month', 'event_espresso'); |
|
1500 | - EE_Registry::$i18n_js_strings['timer_week'] = __('week', 'event_espresso'); |
|
1501 | - EE_Registry::$i18n_js_strings['timer_day'] = __('day', 'event_espresso'); |
|
1502 | - EE_Registry::$i18n_js_strings['timer_hour'] = __('hour', 'event_espresso'); |
|
1503 | - EE_Registry::$i18n_js_strings['timer_minute'] = __('minute', 'event_espresso'); |
|
1504 | - EE_Registry::$i18n_js_strings['timer_second'] = __('second', 'event_espresso'); |
|
1505 | - EE_Registry::$i18n_js_strings['registration_expiration_notice'] = sprintf( |
|
1506 | - __( |
|
1507 | - '%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 except our apologies for any inconvenience this may have caused.%8$s', |
|
1508 | - 'event_espresso' |
|
1509 | - ), |
|
1510 | - '<h4 class="important-notice">', |
|
1511 | - '</h4>', |
|
1512 | - '<br />', |
|
1513 | - '<p>', |
|
1514 | - '<a href="' . get_post_type_archive_link('espresso_events') . '" title="', |
|
1515 | - '">', |
|
1516 | - '</a>', |
|
1517 | - '</p>' |
|
1518 | - ); |
|
1519 | - EE_Registry::$i18n_js_strings['ajax_submit'] = apply_filters( |
|
1520 | - 'FHEE__Single_Page_Checkout__translate_js_strings__ajax_submit', |
|
1521 | - true |
|
1522 | - ); |
|
1523 | - EE_Registry::$i18n_js_strings['session_extension'] = absint( |
|
1524 | - apply_filters('FHEE__EE_Session__extend_expiration__seconds_added', 10 * MINUTE_IN_SECONDS) |
|
1525 | - ); |
|
1526 | - EE_Registry::$i18n_js_strings['session_expiration'] = gmdate( |
|
1527 | - 'M d, Y H:i:s', |
|
1528 | - EE_Registry::instance()->SSN->expiration() + (get_option('gmt_offset') * HOUR_IN_SECONDS) |
|
1529 | - ); |
|
1530 | - } |
|
1531 | - |
|
1532 | - |
|
1533 | - |
|
1534 | - /** |
|
1535 | - * enqueue_styles_and_scripts |
|
1536 | - * |
|
1537 | - * @access public |
|
1538 | - * @return void |
|
1539 | - * @throws EE_Error |
|
1540 | - */ |
|
1541 | - public function enqueue_styles_and_scripts() |
|
1542 | - { |
|
1543 | - // load css |
|
1544 | - wp_register_style( |
|
1545 | - 'single_page_checkout', |
|
1546 | - SPCO_CSS_URL . 'single_page_checkout.css', |
|
1547 | - array('espresso_default'), |
|
1548 | - EVENT_ESPRESSO_VERSION |
|
1549 | - ); |
|
1550 | - wp_enqueue_style('single_page_checkout'); |
|
1551 | - // load JS |
|
1552 | - wp_register_script( |
|
1553 | - 'jquery_plugin', |
|
1554 | - EE_THIRD_PARTY_URL . 'jquery .plugin.min.js', |
|
1555 | - array('jquery'), |
|
1556 | - '1.0.1', |
|
1557 | - true |
|
1558 | - ); |
|
1559 | - wp_register_script( |
|
1560 | - 'jquery_countdown', |
|
1561 | - EE_THIRD_PARTY_URL . 'jquery .countdown.min.js', |
|
1562 | - array('jquery_plugin'), |
|
1563 | - '2.0.2', |
|
1564 | - true |
|
1565 | - ); |
|
1566 | - wp_register_script( |
|
1567 | - 'single_page_checkout', |
|
1568 | - SPCO_JS_URL . 'single_page_checkout.js', |
|
1569 | - array('espresso_core', 'underscore', 'ee_form_section_validation', 'jquery_countdown'), |
|
1570 | - EVENT_ESPRESSO_VERSION, |
|
1571 | - true |
|
1572 | - ); |
|
1573 | - if ($this->checkout->registration_form instanceof EE_Form_Section_Proper) { |
|
1574 | - $this->checkout->registration_form->enqueue_js(); |
|
1575 | - } |
|
1576 | - if ($this->checkout->current_step->reg_form instanceof EE_Form_Section_Proper) { |
|
1577 | - $this->checkout->current_step->reg_form->enqueue_js(); |
|
1578 | - } |
|
1579 | - wp_enqueue_script('single_page_checkout'); |
|
1580 | - /** |
|
1581 | - * global action hook for enqueueing styles and scripts with |
|
1582 | - * spco calls. |
|
1583 | - */ |
|
1584 | - do_action('AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts', $this); |
|
1585 | - /** |
|
1586 | - * dynamic action hook for enqueueing styles and scripts with spco calls. |
|
1587 | - * The hook will end up being something like: |
|
1588 | - * AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__attendee_information |
|
1589 | - */ |
|
1590 | - do_action( |
|
1591 | - 'AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__' . $this->checkout->current_step->slug(), |
|
1592 | - $this |
|
1593 | - ); |
|
1594 | - } |
|
1595 | - |
|
1596 | - |
|
1597 | - |
|
1598 | - /** |
|
1599 | - * display the Registration Single Page Checkout Form |
|
1600 | - * |
|
1601 | - * @access private |
|
1602 | - * @return void |
|
1603 | - * @throws EE_Error |
|
1604 | - */ |
|
1605 | - private function _display_spco_reg_form() |
|
1606 | - { |
|
1607 | - // if registering via the admin, just display the reg form for the current step |
|
1608 | - if ($this->checkout->admin_request) { |
|
1609 | - EE_Registry::instance()->REQ->add_output($this->checkout->current_step->display_reg_form()); |
|
1610 | - } else { |
|
1611 | - // add powered by EE msg |
|
1612 | - add_action('AHEE__SPCO__reg_form_footer', array('EED_Single_Page_Checkout', 'display_registration_footer')); |
|
1613 | - $empty_cart = count( |
|
1614 | - $this->checkout->transaction->registrations($this->checkout->reg_cache_where_params) |
|
1615 | - ) < 1; |
|
1616 | - EE_Registry::$i18n_js_strings['empty_cart'] = $empty_cart; |
|
1617 | - $cookies_not_set_msg = ''; |
|
1618 | - if ($empty_cart && ! isset($_COOKIE['ee_cookie_test'])) { |
|
1619 | - $cookies_not_set_msg = apply_filters( |
|
1620 | - 'FHEE__Single_Page_Checkout__display_spco_reg_form__cookies_not_set_msg', |
|
1621 | - sprintf( |
|
1622 | - __( |
|
1623 | - '%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', |
|
1624 | - 'event_espresso' |
|
1625 | - ), |
|
1626 | - '<div class="ee-attention">', |
|
1627 | - '</div>', |
|
1628 | - '<h6 class="important-notice">', |
|
1629 | - '</h6>', |
|
1630 | - '<p>', |
|
1631 | - '</p>', |
|
1632 | - '<br />', |
|
1633 | - '<a href="http://www.whatarecookies.com/enable.asp" target="_blank">', |
|
1634 | - '</a>' |
|
1635 | - ) |
|
1636 | - ); |
|
1637 | - } |
|
1638 | - $this->checkout->registration_form = new EE_Form_Section_Proper( |
|
1639 | - array( |
|
1640 | - 'name' => 'single-page-checkout', |
|
1641 | - 'html_id' => 'ee-single-page-checkout-dv', |
|
1642 | - 'layout_strategy' => |
|
1643 | - new EE_Template_Layout( |
|
1644 | - array( |
|
1645 | - 'layout_template_file' => SPCO_TEMPLATES_PATH . 'registration_page_wrapper.template.php', |
|
1646 | - 'template_args' => array( |
|
1647 | - 'empty_cart' => $empty_cart, |
|
1648 | - 'revisit' => $this->checkout->revisit, |
|
1649 | - 'reg_steps' => $this->checkout->reg_steps, |
|
1650 | - 'next_step' => $this->checkout->next_step instanceof EE_SPCO_Reg_Step |
|
1651 | - ? $this->checkout->next_step->slug() |
|
1652 | - : '', |
|
1653 | - 'cancel_page_url' => $this->checkout->cancel_page_url, |
|
1654 | - 'empty_msg' => apply_filters( |
|
1655 | - 'FHEE__Single_Page_Checkout__display_spco_reg_form__empty_msg', |
|
1656 | - sprintf( |
|
1657 | - __( |
|
1658 | - 'You need to %1$sReturn to Events list%2$sselect at least one event%3$s before you can proceed with the registration process.', |
|
1659 | - 'event_espresso' |
|
1660 | - ), |
|
1661 | - '<a href="' |
|
1662 | - . get_post_type_archive_link('espresso_events') |
|
1663 | - . '" title="', |
|
1664 | - '">', |
|
1665 | - '</a>' |
|
1666 | - ) |
|
1667 | - ), |
|
1668 | - 'cookies_not_set_msg' => $cookies_not_set_msg, |
|
1669 | - 'registration_time_limit' => $this->checkout->get_registration_time_limit(), |
|
1670 | - 'session_expiration' => gmdate( |
|
1671 | - 'M d, Y H:i:s', |
|
1672 | - EE_Registry::instance()->SSN->expiration() |
|
1673 | - + (get_option('gmt_offset') * HOUR_IN_SECONDS) |
|
1674 | - ), |
|
1675 | - ), |
|
1676 | - ) |
|
1677 | - ), |
|
1678 | - ) |
|
1679 | - ); |
|
1680 | - // load template and add to output sent that gets filtered into the_content() |
|
1681 | - EE_Registry::instance()->REQ->add_output($this->checkout->registration_form->get_html()); |
|
1682 | - } |
|
1683 | - } |
|
1684 | - |
|
1685 | - |
|
1686 | - |
|
1687 | - /** |
|
1688 | - * add_extra_finalize_registration_inputs |
|
1689 | - * |
|
1690 | - * @access public |
|
1691 | - * @param $next_step |
|
1692 | - * @internal param string $label |
|
1693 | - * @return void |
|
1694 | - */ |
|
1695 | - public function add_extra_finalize_registration_inputs($next_step) |
|
1696 | - { |
|
1697 | - if ($next_step === 'finalize_registration') { |
|
1698 | - echo '<div id="spco-extra-finalize_registration-inputs-dv"></div>'; |
|
1699 | - } |
|
1700 | - } |
|
1701 | - |
|
1702 | - |
|
1703 | - |
|
1704 | - /** |
|
1705 | - * display_registration_footer |
|
1706 | - * |
|
1707 | - * @access public |
|
1708 | - * @return string |
|
1709 | - */ |
|
1710 | - public static function display_registration_footer() |
|
1711 | - { |
|
1712 | - if ( |
|
1713 | - apply_filters( |
|
1714 | - 'FHEE__EE_Front__Controller__show_reg_footer', |
|
1715 | - EE_Registry::instance()->CFG->admin->show_reg_footer |
|
1716 | - ) |
|
1717 | - ) { |
|
1718 | - add_filter( |
|
1719 | - 'FHEE__EEH_Template__powered_by_event_espresso__url', |
|
1720 | - function ($url) { |
|
1721 | - return apply_filters('FHEE__EE_Front_Controller__registration_footer__url', $url); |
|
1722 | - } |
|
1723 | - ); |
|
1724 | - echo apply_filters( |
|
1725 | - 'FHEE__EE_Front_Controller__display_registration_footer', |
|
1726 | - \EEH_Template::powered_by_event_espresso( |
|
1727 | - '', |
|
1728 | - 'espresso-registration-footer-dv', |
|
1729 | - array('utm_content' => 'registration_checkout') |
|
1730 | - ) |
|
1731 | - ); |
|
1732 | - } |
|
1733 | - return ''; |
|
1734 | - } |
|
1735 | - |
|
1736 | - |
|
1737 | - |
|
1738 | - /** |
|
1739 | - * unlock_transaction |
|
1740 | - * |
|
1741 | - * @access public |
|
1742 | - * @return void |
|
1743 | - * @throws EE_Error |
|
1744 | - */ |
|
1745 | - public function unlock_transaction() |
|
1746 | - { |
|
1747 | - if ($this->checkout->transaction instanceof EE_Transaction) { |
|
1748 | - $this->checkout->transaction->unlock(); |
|
1749 | - } |
|
1750 | - } |
|
1751 | - |
|
1752 | - |
|
1753 | - |
|
1754 | - /** |
|
1755 | - * _setup_redirect |
|
1756 | - * |
|
1757 | - * @access private |
|
1758 | - * @return void |
|
1759 | - */ |
|
1760 | - private function _setup_redirect() |
|
1761 | - { |
|
1762 | - if ($this->checkout->continue_reg && $this->checkout->next_step instanceof EE_SPCO_Reg_Step) { |
|
1763 | - $this->checkout->redirect = true; |
|
1764 | - if (empty($this->checkout->redirect_url)) { |
|
1765 | - $this->checkout->redirect_url = $this->checkout->next_step->reg_step_url(); |
|
1766 | - } |
|
1767 | - $this->checkout->redirect_url = apply_filters( |
|
1768 | - 'FHEE__EED_Single_Page_Checkout___setup_redirect__checkout_redirect_url', |
|
1769 | - $this->checkout->redirect_url, |
|
1770 | - $this->checkout |
|
1771 | - ); |
|
1772 | - } |
|
1773 | - } |
|
1774 | - |
|
1775 | - |
|
1776 | - |
|
1777 | - /** |
|
1778 | - * handle ajax message responses and redirects |
|
1779 | - * |
|
1780 | - * @access public |
|
1781 | - * @return void |
|
1782 | - * @throws EE_Error |
|
1783 | - */ |
|
1784 | - public function go_to_next_step() |
|
1785 | - { |
|
1786 | - if (EE_Registry::instance()->REQ->ajax) { |
|
1787 | - // capture contents of output buffer we started earlier in the request, and insert into JSON response |
|
1788 | - $this->checkout->json_response->set_unexpected_errors(ob_get_clean()); |
|
1789 | - } |
|
1790 | - $this->unlock_transaction(); |
|
1791 | - // just return for these conditions |
|
1792 | - if ( |
|
1793 | - $this->checkout->admin_request |
|
1794 | - || $this->checkout->action === 'redirect_form' |
|
1795 | - || $this->checkout->action === 'update_checkout' |
|
1796 | - ) { |
|
1797 | - return; |
|
1798 | - } |
|
1799 | - // AJAX response |
|
1800 | - $this->_handle_json_response(); |
|
1801 | - // redirect to next step or the Thank You page |
|
1802 | - $this->_handle_html_redirects(); |
|
1803 | - // hmmm... must be something wrong, so let's just display the form again ! |
|
1804 | - $this->_display_spco_reg_form(); |
|
1805 | - } |
|
1806 | - |
|
1807 | - |
|
1808 | - |
|
1809 | - /** |
|
1810 | - * _handle_json_response |
|
1811 | - * |
|
1812 | - * @access protected |
|
1813 | - * @return void |
|
1814 | - */ |
|
1815 | - protected function _handle_json_response() |
|
1816 | - { |
|
1817 | - // if this is an ajax request |
|
1818 | - if (EE_Registry::instance()->REQ->ajax) { |
|
1819 | - // DEBUG LOG |
|
1820 | - //$this->checkout->log( |
|
1821 | - // __CLASS__, __FUNCTION__, __LINE__, |
|
1822 | - // array( |
|
1823 | - // 'json_response_redirect_url' => $this->checkout->json_response->redirect_url(), |
|
1824 | - // 'redirect' => $this->checkout->redirect, |
|
1825 | - // 'continue_reg' => $this->checkout->continue_reg, |
|
1826 | - // ) |
|
1827 | - //); |
|
1828 | - $this->checkout->json_response->set_registration_time_limit( |
|
1829 | - $this->checkout->get_registration_time_limit() |
|
1830 | - ); |
|
1831 | - $this->checkout->json_response->set_payment_amount($this->checkout->amount_owing); |
|
1832 | - // just send the ajax ( |
|
1833 | - $json_response = apply_filters( |
|
1834 | - 'FHEE__EE_Single_Page_Checkout__JSON_response', |
|
1835 | - $this->checkout->json_response |
|
1836 | - ); |
|
1837 | - echo $json_response; |
|
1838 | - exit(); |
|
1839 | - } |
|
1840 | - } |
|
1841 | - |
|
1842 | - |
|
1843 | - |
|
1844 | - /** |
|
1845 | - * _handle_redirects |
|
1846 | - * |
|
1847 | - * @access protected |
|
1848 | - * @return void |
|
1849 | - */ |
|
1850 | - protected function _handle_html_redirects() |
|
1851 | - { |
|
1852 | - // going somewhere ? |
|
1853 | - if ($this->checkout->redirect && ! empty($this->checkout->redirect_url)) { |
|
1854 | - // store notices in a transient |
|
1855 | - EE_Error::get_notices(false, true, true); |
|
1856 | - // DEBUG LOG |
|
1857 | - //$this->checkout->log( |
|
1858 | - // __CLASS__, __FUNCTION__, __LINE__, |
|
1859 | - // array( |
|
1860 | - // 'headers_sent' => headers_sent(), |
|
1861 | - // 'redirect_url' => $this->checkout->redirect_url, |
|
1862 | - // 'headers_list' => headers_list(), |
|
1863 | - // ) |
|
1864 | - //); |
|
1865 | - wp_safe_redirect($this->checkout->redirect_url); |
|
1866 | - exit(); |
|
1867 | - } |
|
1868 | - } |
|
1869 | - |
|
1870 | - |
|
1871 | - |
|
1872 | - /** |
|
1873 | - * set_checkout_anchor |
|
1874 | - * |
|
1875 | - * @access public |
|
1876 | - * @return void |
|
1877 | - */ |
|
1878 | - public function set_checkout_anchor() |
|
1879 | - { |
|
1880 | - echo '<a id="checkout" style="float: left; margin-left: -999em;"></a>'; |
|
1881 | - } |
|
23 | + /** |
|
24 | + * $_initialized - has the SPCO controller already been initialized ? |
|
25 | + * |
|
26 | + * @access private |
|
27 | + * @var bool $_initialized |
|
28 | + */ |
|
29 | + private static $_initialized = false; |
|
30 | + |
|
31 | + |
|
32 | + /** |
|
33 | + * $_checkout_verified - is the EE_Checkout verified as correct for this request ? |
|
34 | + * |
|
35 | + * @access private |
|
36 | + * @var bool $_valid_checkout |
|
37 | + */ |
|
38 | + private static $_checkout_verified = true; |
|
39 | + |
|
40 | + /** |
|
41 | + * $_reg_steps_array - holds initial array of reg steps |
|
42 | + * |
|
43 | + * @access private |
|
44 | + * @var array $_reg_steps_array |
|
45 | + */ |
|
46 | + private static $_reg_steps_array = array(); |
|
47 | + |
|
48 | + /** |
|
49 | + * $checkout - EE_Checkout object for handling the properties of the current checkout process |
|
50 | + * |
|
51 | + * @access public |
|
52 | + * @var EE_Checkout $checkout |
|
53 | + */ |
|
54 | + public $checkout; |
|
55 | + |
|
56 | + |
|
57 | + |
|
58 | + /** |
|
59 | + * @return EED_Module|EED_Single_Page_Checkout |
|
60 | + */ |
|
61 | + public static function instance() |
|
62 | + { |
|
63 | + add_filter('EED_Single_Page_Checkout__SPCO_active', '__return_true'); |
|
64 | + return parent::get_instance(__CLASS__); |
|
65 | + } |
|
66 | + |
|
67 | + |
|
68 | + |
|
69 | + /** |
|
70 | + * @return EE_CART |
|
71 | + */ |
|
72 | + public function cart() |
|
73 | + { |
|
74 | + return $this->checkout->cart; |
|
75 | + } |
|
76 | + |
|
77 | + |
|
78 | + |
|
79 | + /** |
|
80 | + * @return EE_Transaction |
|
81 | + */ |
|
82 | + public function transaction() |
|
83 | + { |
|
84 | + return $this->checkout->transaction; |
|
85 | + } |
|
86 | + |
|
87 | + |
|
88 | + |
|
89 | + /** |
|
90 | + * set_hooks - for hooking into EE Core, other modules, etc |
|
91 | + * |
|
92 | + * @access public |
|
93 | + * @return void |
|
94 | + * @throws EE_Error |
|
95 | + */ |
|
96 | + public static function set_hooks() |
|
97 | + { |
|
98 | + EED_Single_Page_Checkout::set_definitions(); |
|
99 | + } |
|
100 | + |
|
101 | + |
|
102 | + |
|
103 | + /** |
|
104 | + * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
105 | + * |
|
106 | + * @access public |
|
107 | + * @return void |
|
108 | + * @throws EE_Error |
|
109 | + */ |
|
110 | + public static function set_hooks_admin() |
|
111 | + { |
|
112 | + EED_Single_Page_Checkout::set_definitions(); |
|
113 | + if ( ! (defined('DOING_AJAX') && DOING_AJAX)) { |
|
114 | + return; |
|
115 | + } |
|
116 | + // going to start an output buffer in case anything gets accidentally output |
|
117 | + // that might disrupt our JSON response |
|
118 | + ob_start(); |
|
119 | + EED_Single_Page_Checkout::load_request_handler(); |
|
120 | + EED_Single_Page_Checkout::load_reg_steps(); |
|
121 | + // set ajax hooks |
|
122 | + add_action('wp_ajax_process_reg_step', array('EED_Single_Page_Checkout', 'process_reg_step')); |
|
123 | + add_action('wp_ajax_nopriv_process_reg_step', array('EED_Single_Page_Checkout', 'process_reg_step')); |
|
124 | + add_action('wp_ajax_display_spco_reg_step', array('EED_Single_Page_Checkout', 'display_reg_step')); |
|
125 | + add_action('wp_ajax_nopriv_display_spco_reg_step', array('EED_Single_Page_Checkout', 'display_reg_step')); |
|
126 | + add_action('wp_ajax_update_reg_step', array('EED_Single_Page_Checkout', 'update_reg_step')); |
|
127 | + add_action('wp_ajax_nopriv_update_reg_step', array('EED_Single_Page_Checkout', 'update_reg_step')); |
|
128 | + } |
|
129 | + |
|
130 | + |
|
131 | + |
|
132 | + /** |
|
133 | + * process ajax request |
|
134 | + * |
|
135 | + * @param string $ajax_action |
|
136 | + * @throws EE_Error |
|
137 | + */ |
|
138 | + public static function process_ajax_request($ajax_action) |
|
139 | + { |
|
140 | + EE_Registry::instance()->REQ->set('action', $ajax_action); |
|
141 | + EED_Single_Page_Checkout::instance()->_initialize(); |
|
142 | + } |
|
143 | + |
|
144 | + |
|
145 | + |
|
146 | + /** |
|
147 | + * ajax display registration step |
|
148 | + * |
|
149 | + * @throws EE_Error |
|
150 | + */ |
|
151 | + public static function display_reg_step() |
|
152 | + { |
|
153 | + EED_Single_Page_Checkout::process_ajax_request('display_spco_reg_step'); |
|
154 | + } |
|
155 | + |
|
156 | + |
|
157 | + |
|
158 | + /** |
|
159 | + * ajax process registration step |
|
160 | + * |
|
161 | + * @throws EE_Error |
|
162 | + */ |
|
163 | + public static function process_reg_step() |
|
164 | + { |
|
165 | + EED_Single_Page_Checkout::process_ajax_request('process_reg_step'); |
|
166 | + } |
|
167 | + |
|
168 | + |
|
169 | + |
|
170 | + /** |
|
171 | + * ajax process registration step |
|
172 | + * |
|
173 | + * @throws EE_Error |
|
174 | + */ |
|
175 | + public static function update_reg_step() |
|
176 | + { |
|
177 | + EED_Single_Page_Checkout::process_ajax_request('update_reg_step'); |
|
178 | + } |
|
179 | + |
|
180 | + |
|
181 | + |
|
182 | + /** |
|
183 | + * update_checkout |
|
184 | + * |
|
185 | + * @access public |
|
186 | + * @return void |
|
187 | + * @throws EE_Error |
|
188 | + */ |
|
189 | + public static function update_checkout() |
|
190 | + { |
|
191 | + EED_Single_Page_Checkout::process_ajax_request('update_checkout'); |
|
192 | + } |
|
193 | + |
|
194 | + |
|
195 | + |
|
196 | + /** |
|
197 | + * load_request_handler |
|
198 | + * |
|
199 | + * @access public |
|
200 | + * @return void |
|
201 | + */ |
|
202 | + public static function load_request_handler() |
|
203 | + { |
|
204 | + // load core Request_Handler class |
|
205 | + if (EE_Registry::instance()->REQ !== null) { |
|
206 | + EE_Registry::instance()->load_core('Request_Handler'); |
|
207 | + } |
|
208 | + } |
|
209 | + |
|
210 | + |
|
211 | + |
|
212 | + /** |
|
213 | + * set_definitions |
|
214 | + * |
|
215 | + * @access public |
|
216 | + * @return void |
|
217 | + * @throws EE_Error |
|
218 | + */ |
|
219 | + public static function set_definitions() |
|
220 | + { |
|
221 | + if(defined('SPCO_BASE_PATH')) { |
|
222 | + return; |
|
223 | + } |
|
224 | + define( |
|
225 | + 'SPCO_BASE_PATH', |
|
226 | + rtrim(str_replace(array('\\', '/'), DS, plugin_dir_path(__FILE__)), DS) . DS |
|
227 | + ); |
|
228 | + define('SPCO_CSS_URL', plugin_dir_url(__FILE__) . 'css' . DS); |
|
229 | + define('SPCO_IMG_URL', plugin_dir_url(__FILE__) . 'img' . DS); |
|
230 | + define('SPCO_JS_URL', plugin_dir_url(__FILE__) . 'js' . DS); |
|
231 | + define('SPCO_INC_PATH', SPCO_BASE_PATH . 'inc' . DS); |
|
232 | + define('SPCO_REG_STEPS_PATH', SPCO_BASE_PATH . 'reg_steps' . DS); |
|
233 | + define('SPCO_TEMPLATES_PATH', SPCO_BASE_PATH . 'templates' . DS); |
|
234 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(SPCO_BASE_PATH, true); |
|
235 | + EE_Registry::$i18n_js_strings['registration_expiration_notice'] = sprintf( |
|
236 | + __('%1$sWe\'re sorry, but you\'re registration time has expired.%2$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 except our apologies for any inconvenience this may have caused.%8$s', |
|
237 | + 'event_espresso'), |
|
238 | + '<h4 class="important-notice">', |
|
239 | + '</h4>', |
|
240 | + '<br />', |
|
241 | + '<p>', |
|
242 | + '<a href="' . get_post_type_archive_link('espresso_events') . '" title="', |
|
243 | + '">', |
|
244 | + '</a>', |
|
245 | + '</p>' |
|
246 | + ); |
|
247 | + } |
|
248 | + |
|
249 | + |
|
250 | + |
|
251 | + /** |
|
252 | + * load_reg_steps |
|
253 | + * loads and instantiates each reg step based on the EE_Registry::instance()->CFG->registration->reg_steps array |
|
254 | + * |
|
255 | + * @access private |
|
256 | + * @throws EE_Error |
|
257 | + */ |
|
258 | + public static function load_reg_steps() |
|
259 | + { |
|
260 | + static $reg_steps_loaded = false; |
|
261 | + if ($reg_steps_loaded) { |
|
262 | + return; |
|
263 | + } |
|
264 | + // filter list of reg_steps |
|
265 | + $reg_steps_to_load = (array)apply_filters( |
|
266 | + 'AHEE__SPCO__load_reg_steps__reg_steps_to_load', |
|
267 | + EED_Single_Page_Checkout::get_reg_steps() |
|
268 | + ); |
|
269 | + // sort by key (order) |
|
270 | + ksort($reg_steps_to_load); |
|
271 | + // loop through folders |
|
272 | + foreach ($reg_steps_to_load as $order => $reg_step) { |
|
273 | + // we need a |
|
274 | + if (isset($reg_step['file_path'], $reg_step['class_name'], $reg_step['slug'])) { |
|
275 | + // copy over to the reg_steps_array |
|
276 | + EED_Single_Page_Checkout::$_reg_steps_array[$order] = $reg_step; |
|
277 | + // register custom key route for each reg step |
|
278 | + // ie: step=>"slug" - this is the entire reason we load the reg steps array now |
|
279 | + EE_Config::register_route( |
|
280 | + $reg_step['slug'], |
|
281 | + 'EED_Single_Page_Checkout', |
|
282 | + 'run', |
|
283 | + 'step' |
|
284 | + ); |
|
285 | + // add AJAX or other hooks |
|
286 | + if (isset($reg_step['has_hooks']) && $reg_step['has_hooks']) { |
|
287 | + // setup autoloaders if necessary |
|
288 | + if ( ! class_exists($reg_step['class_name'])) { |
|
289 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder( |
|
290 | + $reg_step['file_path'], |
|
291 | + true |
|
292 | + ); |
|
293 | + } |
|
294 | + if (is_callable($reg_step['class_name'], 'set_hooks')) { |
|
295 | + call_user_func(array($reg_step['class_name'], 'set_hooks')); |
|
296 | + } |
|
297 | + } |
|
298 | + } |
|
299 | + } |
|
300 | + $reg_steps_loaded = true; |
|
301 | + } |
|
302 | + |
|
303 | + |
|
304 | + |
|
305 | + /** |
|
306 | + * get_reg_steps |
|
307 | + * |
|
308 | + * @access public |
|
309 | + * @return array |
|
310 | + */ |
|
311 | + public static function get_reg_steps() |
|
312 | + { |
|
313 | + $reg_steps = EE_Registry::instance()->CFG->registration->reg_steps; |
|
314 | + if (empty($reg_steps)) { |
|
315 | + $reg_steps = array( |
|
316 | + 10 => array( |
|
317 | + 'file_path' => SPCO_REG_STEPS_PATH . 'attendee_information', |
|
318 | + 'class_name' => 'EE_SPCO_Reg_Step_Attendee_Information', |
|
319 | + 'slug' => 'attendee_information', |
|
320 | + 'has_hooks' => false, |
|
321 | + ), |
|
322 | + 20 => array( |
|
323 | + 'file_path' => SPCO_REG_STEPS_PATH . 'registration_confirmation', |
|
324 | + 'class_name' => 'EE_SPCO_Reg_Step_Registration_Confirmation', |
|
325 | + 'slug' => 'registration_confirmation', |
|
326 | + 'has_hooks' => false, |
|
327 | + ), |
|
328 | + 30 => array( |
|
329 | + 'file_path' => SPCO_REG_STEPS_PATH . 'payment_options', |
|
330 | + 'class_name' => 'EE_SPCO_Reg_Step_Payment_Options', |
|
331 | + 'slug' => 'payment_options', |
|
332 | + 'has_hooks' => true, |
|
333 | + ), |
|
334 | + 999 => array( |
|
335 | + 'file_path' => SPCO_REG_STEPS_PATH . 'finalize_registration', |
|
336 | + 'class_name' => 'EE_SPCO_Reg_Step_Finalize_Registration', |
|
337 | + 'slug' => 'finalize_registration', |
|
338 | + 'has_hooks' => false, |
|
339 | + ), |
|
340 | + ); |
|
341 | + } |
|
342 | + return $reg_steps; |
|
343 | + } |
|
344 | + |
|
345 | + |
|
346 | + |
|
347 | + /** |
|
348 | + * registration_checkout_for_admin |
|
349 | + * |
|
350 | + * @access public |
|
351 | + * @return string |
|
352 | + * @throws EE_Error |
|
353 | + */ |
|
354 | + public static function registration_checkout_for_admin() |
|
355 | + { |
|
356 | + EED_Single_Page_Checkout::load_request_handler(); |
|
357 | + EE_Registry::instance()->REQ->set('step', 'attendee_information'); |
|
358 | + EE_Registry::instance()->REQ->set('action', 'display_spco_reg_step'); |
|
359 | + EE_Registry::instance()->REQ->set('process_form_submission', false); |
|
360 | + EED_Single_Page_Checkout::instance()->_initialize(); |
|
361 | + EED_Single_Page_Checkout::instance()->_display_spco_reg_form(); |
|
362 | + return EE_Registry::instance()->REQ->get_output(); |
|
363 | + } |
|
364 | + |
|
365 | + |
|
366 | + |
|
367 | + /** |
|
368 | + * process_registration_from_admin |
|
369 | + * |
|
370 | + * @access public |
|
371 | + * @return \EE_Transaction |
|
372 | + * @throws EE_Error |
|
373 | + */ |
|
374 | + public static function process_registration_from_admin() |
|
375 | + { |
|
376 | + EED_Single_Page_Checkout::load_request_handler(); |
|
377 | + EE_Registry::instance()->REQ->set('step', 'attendee_information'); |
|
378 | + EE_Registry::instance()->REQ->set('action', 'process_reg_step'); |
|
379 | + EE_Registry::instance()->REQ->set('process_form_submission', true); |
|
380 | + EED_Single_Page_Checkout::instance()->_initialize(); |
|
381 | + if (EED_Single_Page_Checkout::instance()->checkout->current_step->completed()) { |
|
382 | + $final_reg_step = end(EED_Single_Page_Checkout::instance()->checkout->reg_steps); |
|
383 | + if ($final_reg_step instanceof EE_SPCO_Reg_Step_Finalize_Registration) { |
|
384 | + EED_Single_Page_Checkout::instance()->checkout->set_reg_step_initiated($final_reg_step); |
|
385 | + if ($final_reg_step->process_reg_step()) { |
|
386 | + $final_reg_step->set_completed(); |
|
387 | + EED_Single_Page_Checkout::instance()->checkout->update_txn_reg_steps_array(); |
|
388 | + return EED_Single_Page_Checkout::instance()->checkout->transaction; |
|
389 | + } |
|
390 | + } |
|
391 | + } |
|
392 | + return null; |
|
393 | + } |
|
394 | + |
|
395 | + |
|
396 | + |
|
397 | + /** |
|
398 | + * run |
|
399 | + * |
|
400 | + * @access public |
|
401 | + * @param WP_Query $WP_Query |
|
402 | + * @return void |
|
403 | + * @throws EE_Error |
|
404 | + */ |
|
405 | + public function run($WP_Query) |
|
406 | + { |
|
407 | + if ( |
|
408 | + $WP_Query instanceof WP_Query |
|
409 | + && $WP_Query->is_main_query() |
|
410 | + && apply_filters('FHEE__EED_Single_Page_Checkout__run', true) |
|
411 | + && $this->_is_reg_checkout() |
|
412 | + ) { |
|
413 | + $this->_initialize(); |
|
414 | + } |
|
415 | + } |
|
416 | + |
|
417 | + |
|
418 | + |
|
419 | + /** |
|
420 | + * determines whether current url matches reg page url |
|
421 | + * |
|
422 | + * @return bool |
|
423 | + */ |
|
424 | + protected function _is_reg_checkout() |
|
425 | + { |
|
426 | + // get current permalink for reg page without any extra query args |
|
427 | + $reg_page_url = \get_permalink(EE_Config::instance()->core->reg_page_id); |
|
428 | + // get request URI for current request, but without the scheme or host |
|
429 | + $current_request_uri = \EEH_URL::filter_input_server_url('REQUEST_URI'); |
|
430 | + $current_request_uri = html_entity_decode($current_request_uri); |
|
431 | + // get array of query args from the current request URI |
|
432 | + $query_args = \EEH_URL::get_query_string($current_request_uri); |
|
433 | + // grab page id if it is set |
|
434 | + $page_id = isset($query_args['page_id']) ? absint($query_args['page_id']) : 0; |
|
435 | + // and remove the page id from the query args (we will re-add it later) |
|
436 | + unset($query_args['page_id']); |
|
437 | + // now strip all query args from current request URI |
|
438 | + $current_request_uri = remove_query_arg(array_keys($query_args), $current_request_uri); |
|
439 | + // and re-add the page id if it was set |
|
440 | + if ($page_id) { |
|
441 | + $current_request_uri = add_query_arg('page_id', $page_id, $current_request_uri); |
|
442 | + } |
|
443 | + // remove slashes and ? |
|
444 | + $current_request_uri = trim($current_request_uri, '?/'); |
|
445 | + // is current request URI part of the known full reg page URL ? |
|
446 | + return ! empty($current_request_uri) && strpos($reg_page_url, $current_request_uri) !== false; |
|
447 | + } |
|
448 | + |
|
449 | + |
|
450 | + |
|
451 | + /** |
|
452 | + * @param WP_Query $wp_query |
|
453 | + * @return void |
|
454 | + * @throws EE_Error |
|
455 | + */ |
|
456 | + public static function init($wp_query) |
|
457 | + { |
|
458 | + EED_Single_Page_Checkout::instance()->run($wp_query); |
|
459 | + } |
|
460 | + |
|
461 | + |
|
462 | + |
|
463 | + /** |
|
464 | + * _initialize - initial module setup |
|
465 | + * |
|
466 | + * @access private |
|
467 | + * @throws EE_Error |
|
468 | + * @return void |
|
469 | + */ |
|
470 | + private function _initialize() |
|
471 | + { |
|
472 | + // ensure SPCO doesn't run twice |
|
473 | + if (EED_Single_Page_Checkout::$_initialized) { |
|
474 | + return; |
|
475 | + } |
|
476 | + try { |
|
477 | + EED_Single_Page_Checkout::load_reg_steps(); |
|
478 | + $this->_verify_session(); |
|
479 | + // setup the EE_Checkout object |
|
480 | + $this->checkout = $this->_initialize_checkout(); |
|
481 | + // filter checkout |
|
482 | + $this->checkout = apply_filters('FHEE__EED_Single_Page_Checkout___initialize__checkout', $this->checkout); |
|
483 | + // get the $_GET |
|
484 | + $this->_get_request_vars(); |
|
485 | + if ($this->_block_bots()) { |
|
486 | + return; |
|
487 | + } |
|
488 | + // filter continue_reg |
|
489 | + $this->checkout->continue_reg = apply_filters( |
|
490 | + 'FHEE__EED_Single_Page_Checkout__init___continue_reg', |
|
491 | + true, |
|
492 | + $this->checkout |
|
493 | + ); |
|
494 | + // load the reg steps array |
|
495 | + if ( ! $this->_load_and_instantiate_reg_steps()) { |
|
496 | + EED_Single_Page_Checkout::$_initialized = true; |
|
497 | + return; |
|
498 | + } |
|
499 | + // set the current step |
|
500 | + $this->checkout->set_current_step($this->checkout->step); |
|
501 | + // and the next step |
|
502 | + $this->checkout->set_next_step(); |
|
503 | + // verify that everything has been setup correctly |
|
504 | + if ( ! ($this->_verify_transaction_and_get_registrations() && $this->_final_verifications())) { |
|
505 | + EED_Single_Page_Checkout::$_initialized = true; |
|
506 | + return; |
|
507 | + } |
|
508 | + // lock the transaction |
|
509 | + $this->checkout->transaction->lock(); |
|
510 | + // make sure all of our cached objects are added to their respective model entity mappers |
|
511 | + $this->checkout->refresh_all_entities(); |
|
512 | + // set amount owing |
|
513 | + $this->checkout->amount_owing = $this->checkout->transaction->remaining(); |
|
514 | + // initialize each reg step, which gives them the chance to potentially alter the process |
|
515 | + $this->_initialize_reg_steps(); |
|
516 | + // DEBUG LOG |
|
517 | + //$this->checkout->log( __CLASS__, __FUNCTION__, __LINE__ ); |
|
518 | + // get reg form |
|
519 | + if( ! $this->_check_form_submission()) { |
|
520 | + EED_Single_Page_Checkout::$_initialized = true; |
|
521 | + return; |
|
522 | + } |
|
523 | + // checkout the action!!! |
|
524 | + $this->_process_form_action(); |
|
525 | + // add some style and make it dance |
|
526 | + $this->add_styles_and_scripts(); |
|
527 | + // kk... SPCO has successfully run |
|
528 | + EED_Single_Page_Checkout::$_initialized = true; |
|
529 | + // set no cache headers and constants |
|
530 | + EE_System::do_not_cache(); |
|
531 | + // add anchor |
|
532 | + add_action('loop_start', array($this, 'set_checkout_anchor'), 1); |
|
533 | + // remove transaction lock |
|
534 | + add_action('shutdown', array($this, 'unlock_transaction'), 1); |
|
535 | + } catch (Exception $e) { |
|
536 | + EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
537 | + } |
|
538 | + } |
|
539 | + |
|
540 | + |
|
541 | + |
|
542 | + /** |
|
543 | + * _verify_session |
|
544 | + * checks that the session is valid and not expired |
|
545 | + * |
|
546 | + * @access private |
|
547 | + * @throws EE_Error |
|
548 | + */ |
|
549 | + private function _verify_session() |
|
550 | + { |
|
551 | + if ( ! EE_Registry::instance()->SSN instanceof EE_Session) { |
|
552 | + throw new EE_Error(__('The EE_Session class could not be loaded.', 'event_espresso')); |
|
553 | + } |
|
554 | + $clear_session_requested = filter_var( |
|
555 | + EE_Registry::instance()->REQ->get('clear_session', false), |
|
556 | + FILTER_VALIDATE_BOOLEAN |
|
557 | + ); |
|
558 | + // is session still valid ? |
|
559 | + if ($clear_session_requested |
|
560 | + || ( EE_Registry::instance()->SSN->expired() |
|
561 | + && EE_Registry::instance()->REQ->get('e_reg_url_link', '') === '' |
|
562 | + ) |
|
563 | + ) { |
|
564 | + $this->checkout = new EE_Checkout(); |
|
565 | + EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__); |
|
566 | + // EE_Registry::instance()->SSN->reset_cart(); |
|
567 | + // EE_Registry::instance()->SSN->reset_checkout(); |
|
568 | + // EE_Registry::instance()->SSN->reset_transaction(); |
|
569 | + if (! $clear_session_requested) { |
|
570 | + EE_Error::add_attention( |
|
571 | + EE_Registry::$i18n_js_strings['registration_expiration_notice'], |
|
572 | + __FILE__, __FUNCTION__, __LINE__ |
|
573 | + ); |
|
574 | + } |
|
575 | + // EE_Registry::instance()->SSN->reset_expired(); |
|
576 | + } |
|
577 | + } |
|
578 | + |
|
579 | + |
|
580 | + |
|
581 | + /** |
|
582 | + * _initialize_checkout |
|
583 | + * loads and instantiates EE_Checkout |
|
584 | + * |
|
585 | + * @access private |
|
586 | + * @throws EE_Error |
|
587 | + * @return EE_Checkout |
|
588 | + */ |
|
589 | + private function _initialize_checkout() |
|
590 | + { |
|
591 | + // look in session for existing checkout |
|
592 | + /** @type EE_Checkout $checkout */ |
|
593 | + $checkout = EE_Registry::instance()->SSN->checkout(); |
|
594 | + // verify |
|
595 | + if ( ! $checkout instanceof EE_Checkout) { |
|
596 | + // instantiate EE_Checkout object for handling the properties of the current checkout process |
|
597 | + $checkout = EE_Registry::instance()->load_file( |
|
598 | + SPCO_INC_PATH, |
|
599 | + 'EE_Checkout', |
|
600 | + 'class', array(), |
|
601 | + false |
|
602 | + ); |
|
603 | + } else { |
|
604 | + if ($checkout->current_step->is_final_step() && $checkout->exit_spco() === true) { |
|
605 | + $this->unlock_transaction(); |
|
606 | + wp_safe_redirect($checkout->redirect_url); |
|
607 | + exit(); |
|
608 | + } |
|
609 | + } |
|
610 | + $checkout = apply_filters('FHEE__EED_Single_Page_Checkout___initialize_checkout__checkout', $checkout); |
|
611 | + // verify again |
|
612 | + if ( ! $checkout instanceof EE_Checkout) { |
|
613 | + throw new EE_Error(__('The EE_Checkout class could not be loaded.', 'event_espresso')); |
|
614 | + } |
|
615 | + // reset anything that needs a clean slate for each request |
|
616 | + $checkout->reset_for_current_request(); |
|
617 | + return $checkout; |
|
618 | + } |
|
619 | + |
|
620 | + |
|
621 | + |
|
622 | + /** |
|
623 | + * _get_request_vars |
|
624 | + * |
|
625 | + * @access private |
|
626 | + * @return void |
|
627 | + * @throws EE_Error |
|
628 | + */ |
|
629 | + private function _get_request_vars() |
|
630 | + { |
|
631 | + // load classes |
|
632 | + EED_Single_Page_Checkout::load_request_handler(); |
|
633 | + //make sure this request is marked as belonging to EE |
|
634 | + EE_Registry::instance()->REQ->set_espresso_page(true); |
|
635 | + // which step is being requested ? |
|
636 | + $this->checkout->step = EE_Registry::instance()->REQ->get('step', $this->_get_first_step()); |
|
637 | + // which step is being edited ? |
|
638 | + $this->checkout->edit_step = EE_Registry::instance()->REQ->get('edit_step', ''); |
|
639 | + // and what we're doing on the current step |
|
640 | + $this->checkout->action = EE_Registry::instance()->REQ->get('action', 'display_spco_reg_step'); |
|
641 | + // timestamp |
|
642 | + $this->checkout->uts = EE_Registry::instance()->REQ->get('uts', 0); |
|
643 | + // returning to edit ? |
|
644 | + $this->checkout->reg_url_link = EE_Registry::instance()->REQ->get('e_reg_url_link', ''); |
|
645 | + // add reg url link to registration query params |
|
646 | + if ($this->checkout->reg_url_link && strpos($this->checkout->reg_url_link, '1-') !== 0) { |
|
647 | + $this->checkout->reg_cache_where_params[0]['REG_url_link'] = $this->checkout->reg_url_link; |
|
648 | + } |
|
649 | + // or some other kind of revisit ? |
|
650 | + $this->checkout->revisit = filter_var( |
|
651 | + EE_Registry::instance()->REQ->get('revisit', false), |
|
652 | + FILTER_VALIDATE_BOOLEAN |
|
653 | + ); |
|
654 | + // and whether or not to generate a reg form for this request |
|
655 | + $this->checkout->generate_reg_form = filter_var( |
|
656 | + EE_Registry::instance()->REQ->get('generate_reg_form', true), |
|
657 | + FILTER_VALIDATE_BOOLEAN |
|
658 | + ); |
|
659 | + // and whether or not to process a reg form submission for this request |
|
660 | + $this->checkout->process_form_submission = filter_var( |
|
661 | + EE_Registry::instance()->REQ->get( |
|
662 | + 'process_form_submission', |
|
663 | + $this->checkout->action === 'process_reg_step' |
|
664 | + ), |
|
665 | + FILTER_VALIDATE_BOOLEAN |
|
666 | + ); |
|
667 | + $this->checkout->process_form_submission = filter_var( |
|
668 | + $this->checkout->action !== 'display_spco_reg_step' |
|
669 | + ? $this->checkout->process_form_submission |
|
670 | + : false, |
|
671 | + FILTER_VALIDATE_BOOLEAN |
|
672 | + ); |
|
673 | + // $this->_display_request_vars(); |
|
674 | + } |
|
675 | + |
|
676 | + |
|
677 | + |
|
678 | + /** |
|
679 | + * _display_request_vars |
|
680 | + * |
|
681 | + * @access protected |
|
682 | + * @return void |
|
683 | + */ |
|
684 | + protected function _display_request_vars() |
|
685 | + { |
|
686 | + if ( ! WP_DEBUG) { |
|
687 | + return; |
|
688 | + } |
|
689 | + EEH_Debug_Tools::printr($_REQUEST, '$_REQUEST', __FILE__, __LINE__); |
|
690 | + EEH_Debug_Tools::printr($this->checkout->step, '$this->checkout->step', __FILE__, __LINE__); |
|
691 | + EEH_Debug_Tools::printr($this->checkout->edit_step, '$this->checkout->edit_step', __FILE__, __LINE__); |
|
692 | + EEH_Debug_Tools::printr($this->checkout->action, '$this->checkout->action', __FILE__, __LINE__); |
|
693 | + EEH_Debug_Tools::printr($this->checkout->reg_url_link, '$this->checkout->reg_url_link', __FILE__, __LINE__); |
|
694 | + EEH_Debug_Tools::printr($this->checkout->revisit, '$this->checkout->revisit', __FILE__, __LINE__); |
|
695 | + EEH_Debug_Tools::printr($this->checkout->generate_reg_form, '$this->checkout->generate_reg_form', __FILE__, __LINE__); |
|
696 | + EEH_Debug_Tools::printr($this->checkout->process_form_submission, '$this->checkout->process_form_submission', __FILE__, __LINE__); |
|
697 | + } |
|
698 | + |
|
699 | + |
|
700 | + |
|
701 | + /** |
|
702 | + * _block_bots |
|
703 | + * checks that the incoming request has either of the following set: |
|
704 | + * a uts (unix timestamp) which indicates that the request was redirected from the Ticket Selector |
|
705 | + * a REG URL Link, which indicates that the request is a return visit to SPCO for a valid TXN |
|
706 | + * so if you're not coming from the Ticket Selector nor returning for a valid IP... |
|
707 | + * then where you coming from man? |
|
708 | + * |
|
709 | + * @return boolean |
|
710 | + */ |
|
711 | + private function _block_bots() |
|
712 | + { |
|
713 | + $invalid_checkout_access = EED_Invalid_Checkout_Access::getInvalidCheckoutAccess(); |
|
714 | + if ($invalid_checkout_access->checkoutAccessIsInvalid($this->checkout)) { |
|
715 | + return true; |
|
716 | + } |
|
717 | + return false; |
|
718 | + } |
|
719 | + |
|
720 | + |
|
721 | + |
|
722 | + /** |
|
723 | + * _get_first_step |
|
724 | + * gets slug for first step in $_reg_steps_array |
|
725 | + * |
|
726 | + * @access private |
|
727 | + * @throws EE_Error |
|
728 | + * @return string |
|
729 | + */ |
|
730 | + private function _get_first_step() |
|
731 | + { |
|
732 | + $first_step = reset(EED_Single_Page_Checkout::$_reg_steps_array); |
|
733 | + return isset($first_step['slug']) ? $first_step['slug'] : 'attendee_information'; |
|
734 | + } |
|
735 | + |
|
736 | + |
|
737 | + |
|
738 | + /** |
|
739 | + * _load_and_instantiate_reg_steps |
|
740 | + * instantiates each reg step based on the loaded reg_steps array |
|
741 | + * |
|
742 | + * @access private |
|
743 | + * @throws EE_Error |
|
744 | + * @return bool |
|
745 | + */ |
|
746 | + private function _load_and_instantiate_reg_steps() |
|
747 | + { |
|
748 | + do_action('AHEE__Single_Page_Checkout___load_and_instantiate_reg_steps__start', $this->checkout); |
|
749 | + // have reg_steps already been instantiated ? |
|
750 | + if ( |
|
751 | + empty($this->checkout->reg_steps) |
|
752 | + || apply_filters('FHEE__Single_Page_Checkout__load_reg_steps__reload_reg_steps', false, $this->checkout) |
|
753 | + ) { |
|
754 | + // if not, then loop through raw reg steps array |
|
755 | + foreach (EED_Single_Page_Checkout::$_reg_steps_array as $order => $reg_step) { |
|
756 | + if ( ! $this->_load_and_instantiate_reg_step($reg_step, $order)) { |
|
757 | + return false; |
|
758 | + } |
|
759 | + } |
|
760 | + EE_Registry::instance()->CFG->registration->skip_reg_confirmation = true; |
|
761 | + EE_Registry::instance()->CFG->registration->reg_confirmation_last = true; |
|
762 | + // skip the registration_confirmation page ? |
|
763 | + if (EE_Registry::instance()->CFG->registration->skip_reg_confirmation) { |
|
764 | + // just remove it from the reg steps array |
|
765 | + $this->checkout->remove_reg_step('registration_confirmation', false); |
|
766 | + } else if ( |
|
767 | + isset($this->checkout->reg_steps['registration_confirmation']) |
|
768 | + && EE_Registry::instance()->CFG->registration->reg_confirmation_last |
|
769 | + ) { |
|
770 | + // set the order to something big like 100 |
|
771 | + $this->checkout->set_reg_step_order('registration_confirmation', 100); |
|
772 | + } |
|
773 | + // filter the array for good luck |
|
774 | + $this->checkout->reg_steps = apply_filters( |
|
775 | + 'FHEE__Single_Page_Checkout__load_reg_steps__reg_steps', |
|
776 | + $this->checkout->reg_steps |
|
777 | + ); |
|
778 | + // finally re-sort based on the reg step class order properties |
|
779 | + $this->checkout->sort_reg_steps(); |
|
780 | + } else { |
|
781 | + foreach ($this->checkout->reg_steps as $reg_step) { |
|
782 | + // set all current step stati to FALSE |
|
783 | + $reg_step->set_is_current_step(false); |
|
784 | + } |
|
785 | + } |
|
786 | + if (empty($this->checkout->reg_steps)) { |
|
787 | + EE_Error::add_error( |
|
788 | + __('No Reg Steps were loaded..', 'event_espresso'), |
|
789 | + __FILE__, __FUNCTION__, __LINE__ |
|
790 | + ); |
|
791 | + return false; |
|
792 | + } |
|
793 | + // make reg step details available to JS |
|
794 | + $this->checkout->set_reg_step_JSON_info(); |
|
795 | + return true; |
|
796 | + } |
|
797 | + |
|
798 | + |
|
799 | + |
|
800 | + /** |
|
801 | + * _load_and_instantiate_reg_step |
|
802 | + * |
|
803 | + * @access private |
|
804 | + * @param array $reg_step |
|
805 | + * @param int $order |
|
806 | + * @return bool |
|
807 | + */ |
|
808 | + private function _load_and_instantiate_reg_step($reg_step = array(), $order = 0) |
|
809 | + { |
|
810 | + // we need a file_path, class_name, and slug to add a reg step |
|
811 | + if (isset($reg_step['file_path'], $reg_step['class_name'], $reg_step['slug'])) { |
|
812 | + // if editing a specific step, but this is NOT that step... (and it's not the 'finalize_registration' step) |
|
813 | + if ( |
|
814 | + $this->checkout->reg_url_link |
|
815 | + && $this->checkout->step !== $reg_step['slug'] |
|
816 | + && $reg_step['slug'] !== 'finalize_registration' |
|
817 | + // normally at this point we would NOT load the reg step, but this filter can change that |
|
818 | + && apply_filters( |
|
819 | + 'FHEE__Single_Page_Checkout___load_and_instantiate_reg_step__bypass_reg_step', |
|
820 | + true, |
|
821 | + $reg_step, |
|
822 | + $this->checkout |
|
823 | + ) |
|
824 | + ) { |
|
825 | + return true; |
|
826 | + } |
|
827 | + // instantiate step class using file path and class name |
|
828 | + $reg_step_obj = EE_Registry::instance()->load_file( |
|
829 | + $reg_step['file_path'], |
|
830 | + $reg_step['class_name'], |
|
831 | + 'class', |
|
832 | + $this->checkout, |
|
833 | + false |
|
834 | + ); |
|
835 | + // did we gets the goods ? |
|
836 | + if ($reg_step_obj instanceof EE_SPCO_Reg_Step) { |
|
837 | + // set reg step order based on config |
|
838 | + $reg_step_obj->set_order($order); |
|
839 | + // add instantiated reg step object to the master reg steps array |
|
840 | + $this->checkout->add_reg_step($reg_step_obj); |
|
841 | + } else { |
|
842 | + EE_Error::add_error( |
|
843 | + __('The current step could not be set.', 'event_espresso'), |
|
844 | + __FILE__, __FUNCTION__, __LINE__ |
|
845 | + ); |
|
846 | + return false; |
|
847 | + } |
|
848 | + } else { |
|
849 | + if (WP_DEBUG) { |
|
850 | + EE_Error::add_error( |
|
851 | + sprintf( |
|
852 | + __( |
|
853 | + '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', |
|
854 | + 'event_espresso' |
|
855 | + ), |
|
856 | + isset($reg_step['file_path']) ? $reg_step['file_path'] : '', |
|
857 | + isset($reg_step['class_name']) ? $reg_step['class_name'] : '', |
|
858 | + isset($reg_step['slug']) ? $reg_step['slug'] : '', |
|
859 | + '<ul>', |
|
860 | + '<li>', |
|
861 | + '</li>', |
|
862 | + '</ul>' |
|
863 | + ), |
|
864 | + __FILE__, __FUNCTION__, __LINE__ |
|
865 | + ); |
|
866 | + } |
|
867 | + return false; |
|
868 | + } |
|
869 | + return true; |
|
870 | + } |
|
871 | + |
|
872 | + |
|
873 | + /** |
|
874 | + * _verify_transaction_and_get_registrations |
|
875 | + * |
|
876 | + * @access private |
|
877 | + * @return bool |
|
878 | + * @throws InvalidDataTypeException |
|
879 | + * @throws InvalidEntityException |
|
880 | + * @throws EE_Error |
|
881 | + */ |
|
882 | + private function _verify_transaction_and_get_registrations() |
|
883 | + { |
|
884 | + // was there already a valid transaction in the checkout from the session ? |
|
885 | + if ( ! $this->checkout->transaction instanceof EE_Transaction) { |
|
886 | + // get transaction from db or session |
|
887 | + $this->checkout->transaction = $this->checkout->reg_url_link && ! is_admin() |
|
888 | + ? $this->_get_transaction_and_cart_for_previous_visit() |
|
889 | + : $this->_get_cart_for_current_session_and_setup_new_transaction(); |
|
890 | + if ( ! $this->checkout->transaction instanceof EE_Transaction) { |
|
891 | + EE_Error::add_error( |
|
892 | + __('Your Registration and Transaction information could not be retrieved from the db.', |
|
893 | + 'event_espresso'), |
|
894 | + __FILE__, __FUNCTION__, __LINE__ |
|
895 | + ); |
|
896 | + $this->checkout->transaction = EE_Transaction::new_instance(); |
|
897 | + // add some style and make it dance |
|
898 | + $this->add_styles_and_scripts(); |
|
899 | + EED_Single_Page_Checkout::$_initialized = true; |
|
900 | + return false; |
|
901 | + } |
|
902 | + // and the registrations for the transaction |
|
903 | + $this->_get_registrations($this->checkout->transaction); |
|
904 | + } |
|
905 | + return true; |
|
906 | + } |
|
907 | + |
|
908 | + |
|
909 | + |
|
910 | + /** |
|
911 | + * _get_transaction_and_cart_for_previous_visit |
|
912 | + * |
|
913 | + * @access private |
|
914 | + * @return mixed EE_Transaction|NULL |
|
915 | + */ |
|
916 | + private function _get_transaction_and_cart_for_previous_visit() |
|
917 | + { |
|
918 | + /** @var $TXN_model EEM_Transaction */ |
|
919 | + $TXN_model = EE_Registry::instance()->load_model('Transaction'); |
|
920 | + // because the reg_url_link is present in the request, |
|
921 | + // this is a return visit to SPCO, so we'll get the transaction data from the db |
|
922 | + $transaction = $TXN_model->get_transaction_from_reg_url_link($this->checkout->reg_url_link); |
|
923 | + // verify transaction |
|
924 | + if ($transaction instanceof EE_Transaction) { |
|
925 | + // and get the cart that was used for that transaction |
|
926 | + $this->checkout->cart = $this->_get_cart_for_transaction($transaction); |
|
927 | + return $transaction; |
|
928 | + } |
|
929 | + EE_Error::add_error( |
|
930 | + __('Your Registration and Transaction information could not be retrieved from the db.', 'event_espresso'), |
|
931 | + __FILE__, __FUNCTION__, __LINE__ |
|
932 | + ); |
|
933 | + return null; |
|
934 | + |
|
935 | + } |
|
936 | + |
|
937 | + |
|
938 | + |
|
939 | + /** |
|
940 | + * _get_cart_for_transaction |
|
941 | + * |
|
942 | + * @access private |
|
943 | + * @param EE_Transaction $transaction |
|
944 | + * @return EE_Cart |
|
945 | + */ |
|
946 | + private function _get_cart_for_transaction($transaction) |
|
947 | + { |
|
948 | + return $this->checkout->get_cart_for_transaction($transaction); |
|
949 | + } |
|
950 | + |
|
951 | + |
|
952 | + |
|
953 | + /** |
|
954 | + * get_cart_for_transaction |
|
955 | + * |
|
956 | + * @access public |
|
957 | + * @param EE_Transaction $transaction |
|
958 | + * @return EE_Cart |
|
959 | + */ |
|
960 | + public function get_cart_for_transaction(EE_Transaction $transaction) |
|
961 | + { |
|
962 | + return $this->checkout->get_cart_for_transaction($transaction); |
|
963 | + } |
|
964 | + |
|
965 | + |
|
966 | + |
|
967 | + /** |
|
968 | + * _get_transaction_and_cart_for_current_session |
|
969 | + * generates a new EE_Transaction object and adds it to the $_transaction property. |
|
970 | + * |
|
971 | + * @access private |
|
972 | + * @return EE_Transaction |
|
973 | + * @throws EE_Error |
|
974 | + */ |
|
975 | + private function _get_cart_for_current_session_and_setup_new_transaction() |
|
976 | + { |
|
977 | + // if there's no transaction, then this is the FIRST visit to SPCO |
|
978 | + // so load up the cart ( passing nothing for the TXN because it doesn't exist yet ) |
|
979 | + $this->checkout->cart = $this->_get_cart_for_transaction(null); |
|
980 | + // and then create a new transaction |
|
981 | + $transaction = $this->_initialize_transaction(); |
|
982 | + // verify transaction |
|
983 | + if ($transaction instanceof EE_Transaction) { |
|
984 | + // save it so that we have an ID for other objects to use |
|
985 | + $transaction->save(); |
|
986 | + // and save TXN data to the cart |
|
987 | + $this->checkout->cart->get_grand_total()->save_this_and_descendants_to_txn($transaction->ID()); |
|
988 | + } else { |
|
989 | + EE_Error::add_error( |
|
990 | + __('A Valid Transaction could not be initialized.', 'event_espresso'), |
|
991 | + __FILE__, __FUNCTION__, __LINE__ |
|
992 | + ); |
|
993 | + } |
|
994 | + return $transaction; |
|
995 | + } |
|
996 | + |
|
997 | + |
|
998 | + |
|
999 | + /** |
|
1000 | + * generates a new EE_Transaction object and adds it to the $_transaction property. |
|
1001 | + * |
|
1002 | + * @access private |
|
1003 | + * @return mixed EE_Transaction|NULL |
|
1004 | + */ |
|
1005 | + private function _initialize_transaction() |
|
1006 | + { |
|
1007 | + try { |
|
1008 | + // ensure cart totals have been calculated |
|
1009 | + $this->checkout->cart->get_grand_total()->recalculate_total_including_taxes(); |
|
1010 | + // grab the cart grand total |
|
1011 | + $cart_total = $this->checkout->cart->get_cart_grand_total(); |
|
1012 | + // create new TXN |
|
1013 | + $transaction = EE_Transaction::new_instance( |
|
1014 | + array( |
|
1015 | + 'TXN_reg_steps' => $this->checkout->initialize_txn_reg_steps_array(), |
|
1016 | + 'TXN_total' => $cart_total > 0 ? $cart_total : 0, |
|
1017 | + 'TXN_paid' => 0, |
|
1018 | + 'STS_ID' => EEM_Transaction::failed_status_code, |
|
1019 | + ) |
|
1020 | + ); |
|
1021 | + // save it so that we have an ID for other objects to use |
|
1022 | + $transaction->save(); |
|
1023 | + // set cron job for following up on TXNs after their session has expired |
|
1024 | + EE_Cron_Tasks::schedule_expired_transaction_check( |
|
1025 | + EE_Registry::instance()->SSN->expiration() + 1, |
|
1026 | + $transaction->ID() |
|
1027 | + ); |
|
1028 | + return $transaction; |
|
1029 | + } catch (Exception $e) { |
|
1030 | + EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
1031 | + } |
|
1032 | + return null; |
|
1033 | + } |
|
1034 | + |
|
1035 | + |
|
1036 | + /** |
|
1037 | + * _get_registrations |
|
1038 | + * |
|
1039 | + * @access private |
|
1040 | + * @param EE_Transaction $transaction |
|
1041 | + * @return void |
|
1042 | + * @throws InvalidDataTypeException |
|
1043 | + * @throws InvalidEntityException |
|
1044 | + * @throws EE_Error |
|
1045 | + */ |
|
1046 | + private function _get_registrations(EE_Transaction $transaction) |
|
1047 | + { |
|
1048 | + // first step: grab the registrants { : o |
|
1049 | + $registrations = $transaction->registrations($this->checkout->reg_cache_where_params, false); |
|
1050 | + $this->checkout->total_ticket_count = count($registrations); |
|
1051 | + // verify registrations have been set |
|
1052 | + if (empty($registrations)) { |
|
1053 | + // if no cached registrations, then check the db |
|
1054 | + $registrations = $transaction->registrations($this->checkout->reg_cache_where_params, false); |
|
1055 | + // still nothing ? well as long as this isn't a revisit |
|
1056 | + if (empty($registrations) && ! $this->checkout->revisit) { |
|
1057 | + // generate new registrations from scratch |
|
1058 | + $registrations = $this->_initialize_registrations($transaction); |
|
1059 | + } |
|
1060 | + } |
|
1061 | + // sort by their original registration order |
|
1062 | + usort($registrations, array('EED_Single_Page_Checkout', 'sort_registrations_by_REG_count')); |
|
1063 | + // then loop thru the array |
|
1064 | + foreach ($registrations as $registration) { |
|
1065 | + // verify each registration |
|
1066 | + if ($registration instanceof EE_Registration) { |
|
1067 | + // we display all attendee info for the primary registrant |
|
1068 | + if ($this->checkout->reg_url_link === $registration->reg_url_link() |
|
1069 | + && $registration->is_primary_registrant() |
|
1070 | + ) { |
|
1071 | + $this->checkout->primary_revisit = true; |
|
1072 | + break; |
|
1073 | + } |
|
1074 | + if ($this->checkout->revisit && $this->checkout->reg_url_link !== $registration->reg_url_link()) { |
|
1075 | + // but hide info if it doesn't belong to you |
|
1076 | + $transaction->clear_cache('Registration', $registration->ID()); |
|
1077 | + $this->checkout->total_ticket_count--; |
|
1078 | + } |
|
1079 | + $this->checkout->set_reg_status_updated($registration->ID(), false); |
|
1080 | + } |
|
1081 | + } |
|
1082 | + } |
|
1083 | + |
|
1084 | + |
|
1085 | + /** |
|
1086 | + * adds related EE_Registration objects for each ticket in the cart to the current EE_Transaction object |
|
1087 | + * |
|
1088 | + * @access private |
|
1089 | + * @param EE_Transaction $transaction |
|
1090 | + * @return array |
|
1091 | + * @throws InvalidDataTypeException |
|
1092 | + * @throws InvalidEntityException |
|
1093 | + * @throws EE_Error |
|
1094 | + */ |
|
1095 | + private function _initialize_registrations(EE_Transaction $transaction) |
|
1096 | + { |
|
1097 | + $att_nmbr = 0; |
|
1098 | + $registrations = array(); |
|
1099 | + if ($transaction instanceof EE_Transaction) { |
|
1100 | + /** @type EE_Registration_Processor $registration_processor */ |
|
1101 | + $registration_processor = EE_Registry::instance()->load_class('Registration_Processor'); |
|
1102 | + $this->checkout->total_ticket_count = $this->checkout->cart->all_ticket_quantity_count(); |
|
1103 | + // now let's add the cart items to the $transaction |
|
1104 | + foreach ($this->checkout->cart->get_tickets() as $line_item) { |
|
1105 | + //do the following for each ticket of this type they selected |
|
1106 | + for ($x = 1; $x <= $line_item->quantity(); $x++) { |
|
1107 | + $att_nmbr++; |
|
1108 | + /** @var EventEspresso\core\services\commands\registration\CreateRegistrationCommand $CreateRegistrationCommand */ |
|
1109 | + $CreateRegistrationCommand = EE_Registry::instance()->create( |
|
1110 | + 'EventEspresso\core\services\commands\registration\CreateRegistrationCommand', |
|
1111 | + array( |
|
1112 | + $transaction, |
|
1113 | + $line_item, |
|
1114 | + $att_nmbr, |
|
1115 | + $this->checkout->total_ticket_count, |
|
1116 | + ) |
|
1117 | + ); |
|
1118 | + // override capabilities for frontend registrations |
|
1119 | + if ( ! is_admin()) { |
|
1120 | + $CreateRegistrationCommand->setCapCheck( |
|
1121 | + new PublicCapabilities('', 'create_new_registration') |
|
1122 | + ); |
|
1123 | + } |
|
1124 | + $registration = EE_Registry::instance()->BUS->execute($CreateRegistrationCommand); |
|
1125 | + if ( ! $registration instanceof EE_Registration) { |
|
1126 | + throw new InvalidEntityException($registration, 'EE_Registration'); |
|
1127 | + } |
|
1128 | + $registrations[ $registration->ID() ] = $registration; |
|
1129 | + } |
|
1130 | + } |
|
1131 | + $registration_processor->fix_reg_final_price_rounding_issue($transaction); |
|
1132 | + } |
|
1133 | + return $registrations; |
|
1134 | + } |
|
1135 | + |
|
1136 | + |
|
1137 | + |
|
1138 | + /** |
|
1139 | + * sorts registrations by REG_count |
|
1140 | + * |
|
1141 | + * @access public |
|
1142 | + * @param EE_Registration $reg_A |
|
1143 | + * @param EE_Registration $reg_B |
|
1144 | + * @return int |
|
1145 | + */ |
|
1146 | + public static function sort_registrations_by_REG_count(EE_Registration $reg_A, EE_Registration $reg_B) |
|
1147 | + { |
|
1148 | + // this shouldn't ever happen within the same TXN, but oh well |
|
1149 | + if ($reg_A->count() === $reg_B->count()) { |
|
1150 | + return 0; |
|
1151 | + } |
|
1152 | + return ($reg_A->count() > $reg_B->count()) ? 1 : -1; |
|
1153 | + } |
|
1154 | + |
|
1155 | + |
|
1156 | + |
|
1157 | + /** |
|
1158 | + * _final_verifications |
|
1159 | + * just makes sure that everything is set up correctly before proceeding |
|
1160 | + * |
|
1161 | + * @access private |
|
1162 | + * @return bool |
|
1163 | + * @throws EE_Error |
|
1164 | + */ |
|
1165 | + private function _final_verifications() |
|
1166 | + { |
|
1167 | + // filter checkout |
|
1168 | + $this->checkout = apply_filters( |
|
1169 | + 'FHEE__EED_Single_Page_Checkout___final_verifications__checkout', |
|
1170 | + $this->checkout |
|
1171 | + ); |
|
1172 | + //verify that current step is still set correctly |
|
1173 | + if ( ! $this->checkout->current_step instanceof EE_SPCO_Reg_Step) { |
|
1174 | + EE_Error::add_error( |
|
1175 | + __('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.', 'event_espresso'), |
|
1176 | + __FILE__, |
|
1177 | + __FUNCTION__, |
|
1178 | + __LINE__ |
|
1179 | + ); |
|
1180 | + return false; |
|
1181 | + } |
|
1182 | + // if returning to SPCO, then verify that primary registrant is set |
|
1183 | + if ( ! empty($this->checkout->reg_url_link)) { |
|
1184 | + $valid_registrant = $this->checkout->transaction->primary_registration(); |
|
1185 | + if ( ! $valid_registrant instanceof EE_Registration) { |
|
1186 | + EE_Error::add_error( |
|
1187 | + __('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.', 'event_espresso'), |
|
1188 | + __FILE__, |
|
1189 | + __FUNCTION__, |
|
1190 | + __LINE__ |
|
1191 | + ); |
|
1192 | + return false; |
|
1193 | + } |
|
1194 | + $valid_registrant = null; |
|
1195 | + foreach ( |
|
1196 | + $this->checkout->transaction->registrations($this->checkout->reg_cache_where_params) as $registration |
|
1197 | + ) { |
|
1198 | + if ( |
|
1199 | + $registration instanceof EE_Registration |
|
1200 | + && $registration->reg_url_link() === $this->checkout->reg_url_link |
|
1201 | + ) { |
|
1202 | + $valid_registrant = $registration; |
|
1203 | + } |
|
1204 | + } |
|
1205 | + if ( ! $valid_registrant instanceof EE_Registration) { |
|
1206 | + // hmmm... maybe we have the wrong session because the user is opening multiple tabs ? |
|
1207 | + if (EED_Single_Page_Checkout::$_checkout_verified) { |
|
1208 | + // clear the session, mark the checkout as unverified, and try again |
|
1209 | + EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__); |
|
1210 | + EED_Single_Page_Checkout::$_initialized = false; |
|
1211 | + EED_Single_Page_Checkout::$_checkout_verified = false; |
|
1212 | + $this->_initialize(); |
|
1213 | + EE_Error::reset_notices(); |
|
1214 | + return false; |
|
1215 | + } |
|
1216 | + EE_Error::add_error( |
|
1217 | + __( |
|
1218 | + '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.', |
|
1219 | + 'event_espresso' |
|
1220 | + ), |
|
1221 | + __FILE__, |
|
1222 | + __FUNCTION__, |
|
1223 | + __LINE__ |
|
1224 | + ); |
|
1225 | + return false; |
|
1226 | + } |
|
1227 | + } |
|
1228 | + // now that things have been kinda sufficiently verified, |
|
1229 | + // let's add the checkout to the session so that it's available to other systems |
|
1230 | + EE_Registry::instance()->SSN->set_checkout($this->checkout); |
|
1231 | + return true; |
|
1232 | + } |
|
1233 | + |
|
1234 | + |
|
1235 | + |
|
1236 | + /** |
|
1237 | + * _initialize_reg_steps |
|
1238 | + * first makes sure that EE_Transaction_Processor::set_reg_step_initiated() is called as required |
|
1239 | + * then loops thru all of the active reg steps and calls the initialize_reg_step() method |
|
1240 | + * |
|
1241 | + * @access private |
|
1242 | + * @param bool $reinitializing |
|
1243 | + * @throws EE_Error |
|
1244 | + */ |
|
1245 | + private function _initialize_reg_steps($reinitializing = false) |
|
1246 | + { |
|
1247 | + $this->checkout->set_reg_step_initiated($this->checkout->current_step); |
|
1248 | + // loop thru all steps to call their individual "initialize" methods and set i18n strings for JS |
|
1249 | + foreach ($this->checkout->reg_steps as $reg_step) { |
|
1250 | + if ( ! $reg_step->initialize_reg_step()) { |
|
1251 | + // if not initialized then maybe this step is being removed... |
|
1252 | + if ( ! $reinitializing && $reg_step->is_current_step()) { |
|
1253 | + // if it was the current step, then we need to start over here |
|
1254 | + $this->_initialize_reg_steps(true); |
|
1255 | + return; |
|
1256 | + } |
|
1257 | + continue; |
|
1258 | + } |
|
1259 | + // add css and JS for current step |
|
1260 | + $reg_step->enqueue_styles_and_scripts(); |
|
1261 | + // i18n |
|
1262 | + $reg_step->translate_js_strings(); |
|
1263 | + if ($reg_step->is_current_step()) { |
|
1264 | + // the text that appears on the reg step form submit button |
|
1265 | + $reg_step->set_submit_button_text(); |
|
1266 | + } |
|
1267 | + } |
|
1268 | + // dynamically creates hook point like: AHEE__Single_Page_Checkout___initialize_reg_step__attendee_information |
|
1269 | + do_action( |
|
1270 | + "AHEE__Single_Page_Checkout___initialize_reg_step__{$this->checkout->current_step->slug()}", |
|
1271 | + $this->checkout->current_step |
|
1272 | + ); |
|
1273 | + } |
|
1274 | + |
|
1275 | + |
|
1276 | + |
|
1277 | + /** |
|
1278 | + * _check_form_submission |
|
1279 | + * |
|
1280 | + * @access private |
|
1281 | + * @return boolean |
|
1282 | + */ |
|
1283 | + private function _check_form_submission() |
|
1284 | + { |
|
1285 | + //does this request require the reg form to be generated ? |
|
1286 | + if ($this->checkout->generate_reg_form) { |
|
1287 | + // ever heard that song by Blue Rodeo ? |
|
1288 | + try { |
|
1289 | + $this->checkout->current_step->reg_form = $this->checkout->current_step->generate_reg_form(); |
|
1290 | + // if not displaying a form, then check for form submission |
|
1291 | + if ( |
|
1292 | + $this->checkout->process_form_submission |
|
1293 | + && $this->checkout->current_step->reg_form->was_submitted() |
|
1294 | + ) { |
|
1295 | + // clear out any old data in case this step is being run again |
|
1296 | + $this->checkout->current_step->set_valid_data(array()); |
|
1297 | + // capture submitted form data |
|
1298 | + $this->checkout->current_step->reg_form->receive_form_submission( |
|
1299 | + apply_filters( |
|
1300 | + 'FHEE__Single_Page_Checkout___check_form_submission__request_params', |
|
1301 | + EE_Registry::instance()->REQ->params(), |
|
1302 | + $this->checkout |
|
1303 | + ) |
|
1304 | + ); |
|
1305 | + // validate submitted form data |
|
1306 | + if ( ! $this->checkout->continue_reg || ! $this->checkout->current_step->reg_form->is_valid()) { |
|
1307 | + // thou shall not pass !!! |
|
1308 | + $this->checkout->continue_reg = false; |
|
1309 | + // any form validation errors? |
|
1310 | + if ($this->checkout->current_step->reg_form->submission_error_message() !== '') { |
|
1311 | + $submission_error_messages = array(); |
|
1312 | + // bad, bad, bad registrant |
|
1313 | + foreach ( |
|
1314 | + $this->checkout->current_step->reg_form->get_validation_errors_accumulated() |
|
1315 | + as $validation_error |
|
1316 | + ) { |
|
1317 | + if ($validation_error instanceof EE_Validation_Error) { |
|
1318 | + $submission_error_messages[] = sprintf( |
|
1319 | + __('%s : %s', 'event_espresso'), |
|
1320 | + $validation_error->get_form_section()->html_label_text(), |
|
1321 | + $validation_error->getMessage() |
|
1322 | + ); |
|
1323 | + } |
|
1324 | + } |
|
1325 | + EE_Error::add_error( |
|
1326 | + implode('<br />', $submission_error_messages), |
|
1327 | + __FILE__, __FUNCTION__, __LINE__ |
|
1328 | + ); |
|
1329 | + } |
|
1330 | + // well not really... what will happen is |
|
1331 | + // we'll just get redirected back to redo the current step |
|
1332 | + $this->go_to_next_step(); |
|
1333 | + return false; |
|
1334 | + } |
|
1335 | + } |
|
1336 | + } catch (EE_Error $e) { |
|
1337 | + $e->get_error(); |
|
1338 | + } |
|
1339 | + } |
|
1340 | + return true; |
|
1341 | + } |
|
1342 | + |
|
1343 | + |
|
1344 | + |
|
1345 | + /** |
|
1346 | + * _process_action |
|
1347 | + * |
|
1348 | + * @access private |
|
1349 | + * @return void |
|
1350 | + * @throws EE_Error |
|
1351 | + */ |
|
1352 | + private function _process_form_action() |
|
1353 | + { |
|
1354 | + // what cha wanna do? |
|
1355 | + switch ($this->checkout->action) { |
|
1356 | + // AJAX next step reg form |
|
1357 | + case 'display_spco_reg_step' : |
|
1358 | + $this->checkout->redirect = false; |
|
1359 | + if (EE_Registry::instance()->REQ->ajax) { |
|
1360 | + $this->checkout->json_response->set_reg_step_html( |
|
1361 | + $this->checkout->current_step->display_reg_form() |
|
1362 | + ); |
|
1363 | + } |
|
1364 | + break; |
|
1365 | + default : |
|
1366 | + // meh... do one of those other steps first |
|
1367 | + if ( |
|
1368 | + ! empty($this->checkout->action) |
|
1369 | + && is_callable(array($this->checkout->current_step, $this->checkout->action)) |
|
1370 | + ) { |
|
1371 | + // dynamically creates hook point like: |
|
1372 | + // AHEE__Single_Page_Checkout__before_attendee_information__process_reg_step |
|
1373 | + do_action( |
|
1374 | + "AHEE__Single_Page_Checkout__before_{$this->checkout->current_step->slug()}__{$this->checkout->action}", |
|
1375 | + $this->checkout->current_step |
|
1376 | + ); |
|
1377 | + // call action on current step |
|
1378 | + if (call_user_func(array($this->checkout->current_step, $this->checkout->action))) { |
|
1379 | + // good registrant, you get to proceed |
|
1380 | + if ( |
|
1381 | + $this->checkout->current_step->success_message() !== '' |
|
1382 | + && apply_filters( |
|
1383 | + 'FHEE__Single_Page_Checkout___process_form_action__display_success', |
|
1384 | + false |
|
1385 | + ) |
|
1386 | + ) { |
|
1387 | + EE_Error::add_success( |
|
1388 | + $this->checkout->current_step->success_message() |
|
1389 | + . '<br />' . $this->checkout->next_step->_instructions() |
|
1390 | + ); |
|
1391 | + } |
|
1392 | + // pack it up, pack it in... |
|
1393 | + $this->_setup_redirect(); |
|
1394 | + } |
|
1395 | + // dynamically creates hook point like: |
|
1396 | + // AHEE__Single_Page_Checkout__after_payment_options__process_reg_step |
|
1397 | + do_action( |
|
1398 | + "AHEE__Single_Page_Checkout__after_{$this->checkout->current_step->slug()}__{$this->checkout->action}", |
|
1399 | + $this->checkout->current_step |
|
1400 | + ); |
|
1401 | + } else { |
|
1402 | + EE_Error::add_error( |
|
1403 | + sprintf( |
|
1404 | + __( |
|
1405 | + 'The requested form action "%s" does not exist for the current "%s" registration step.', |
|
1406 | + 'event_espresso' |
|
1407 | + ), |
|
1408 | + $this->checkout->action, |
|
1409 | + $this->checkout->current_step->name() |
|
1410 | + ), |
|
1411 | + __FILE__, |
|
1412 | + __FUNCTION__, |
|
1413 | + __LINE__ |
|
1414 | + ); |
|
1415 | + } |
|
1416 | + // end default |
|
1417 | + } |
|
1418 | + // store our progress so far |
|
1419 | + $this->checkout->stash_transaction_and_checkout(); |
|
1420 | + // advance to the next step! If you pass GO, collect $200 |
|
1421 | + $this->go_to_next_step(); |
|
1422 | + } |
|
1423 | + |
|
1424 | + |
|
1425 | + |
|
1426 | + /** |
|
1427 | + * add_styles_and_scripts |
|
1428 | + * |
|
1429 | + * @access public |
|
1430 | + * @return void |
|
1431 | + */ |
|
1432 | + public function add_styles_and_scripts() |
|
1433 | + { |
|
1434 | + // i18n |
|
1435 | + $this->translate_js_strings(); |
|
1436 | + if ($this->checkout->admin_request) { |
|
1437 | + add_action('admin_enqueue_scripts', array($this, 'enqueue_styles_and_scripts'), 10); |
|
1438 | + } else { |
|
1439 | + add_action('wp_enqueue_scripts', array($this, 'enqueue_styles_and_scripts'), 10); |
|
1440 | + } |
|
1441 | + } |
|
1442 | + |
|
1443 | + |
|
1444 | + |
|
1445 | + /** |
|
1446 | + * translate_js_strings |
|
1447 | + * |
|
1448 | + * @access public |
|
1449 | + * @return void |
|
1450 | + */ |
|
1451 | + public function translate_js_strings() |
|
1452 | + { |
|
1453 | + EE_Registry::$i18n_js_strings['revisit'] = $this->checkout->revisit; |
|
1454 | + EE_Registry::$i18n_js_strings['e_reg_url_link'] = $this->checkout->reg_url_link; |
|
1455 | + EE_Registry::$i18n_js_strings['server_error'] = __( |
|
1456 | + 'An unknown error occurred on the server while attempting to process your request. Please refresh the page and try again or contact support.', |
|
1457 | + 'event_espresso' |
|
1458 | + ); |
|
1459 | + EE_Registry::$i18n_js_strings['invalid_json_response'] = __( |
|
1460 | + 'An invalid response was returned from the server while attempting to process your request. Please refresh the page and try again or contact support.', |
|
1461 | + 'event_espresso' |
|
1462 | + ); |
|
1463 | + EE_Registry::$i18n_js_strings['validation_error'] = __( |
|
1464 | + 'There appears to be a problem with the form validation configuration! Please check the admin settings or contact support.', |
|
1465 | + 'event_espresso' |
|
1466 | + ); |
|
1467 | + EE_Registry::$i18n_js_strings['invalid_payment_method'] = __( |
|
1468 | + 'There appears to be a problem with the payment method configuration! Please refresh the page and try again or contact support.', |
|
1469 | + 'event_espresso' |
|
1470 | + ); |
|
1471 | + EE_Registry::$i18n_js_strings['reg_step_error'] = __( |
|
1472 | + 'This registration step could not be completed. Please refresh the page and try again.', |
|
1473 | + 'event_espresso' |
|
1474 | + ); |
|
1475 | + EE_Registry::$i18n_js_strings['invalid_coupon'] = __( |
|
1476 | + 'We\'re sorry but that coupon code does not appear to be valid. If this is incorrect, please contact the site administrator.', |
|
1477 | + 'event_espresso' |
|
1478 | + ); |
|
1479 | + EE_Registry::$i18n_js_strings['process_registration'] = sprintf( |
|
1480 | + __( |
|
1481 | + 'Please wait while we process your registration.%sDo not refresh the page or navigate away while this is happening.%sThank you for your patience.', |
|
1482 | + 'event_espresso' |
|
1483 | + ), |
|
1484 | + '<br/>', |
|
1485 | + '<br/>' |
|
1486 | + ); |
|
1487 | + EE_Registry::$i18n_js_strings['language'] = get_bloginfo('language'); |
|
1488 | + EE_Registry::$i18n_js_strings['EESID'] = EE_Registry::instance()->SSN->id(); |
|
1489 | + EE_Registry::$i18n_js_strings['currency'] = EE_Registry::instance()->CFG->currency; |
|
1490 | + EE_Registry::$i18n_js_strings['datepicker_yearRange'] = '-150:+20'; |
|
1491 | + EE_Registry::$i18n_js_strings['timer_years'] = __('years', 'event_espresso'); |
|
1492 | + EE_Registry::$i18n_js_strings['timer_months'] = __('months', 'event_espresso'); |
|
1493 | + EE_Registry::$i18n_js_strings['timer_weeks'] = __('weeks', 'event_espresso'); |
|
1494 | + EE_Registry::$i18n_js_strings['timer_days'] = __('days', 'event_espresso'); |
|
1495 | + EE_Registry::$i18n_js_strings['timer_hours'] = __('hours', 'event_espresso'); |
|
1496 | + EE_Registry::$i18n_js_strings['timer_minutes'] = __('minutes', 'event_espresso'); |
|
1497 | + EE_Registry::$i18n_js_strings['timer_seconds'] = __('seconds', 'event_espresso'); |
|
1498 | + EE_Registry::$i18n_js_strings['timer_year'] = __('year', 'event_espresso'); |
|
1499 | + EE_Registry::$i18n_js_strings['timer_month'] = __('month', 'event_espresso'); |
|
1500 | + EE_Registry::$i18n_js_strings['timer_week'] = __('week', 'event_espresso'); |
|
1501 | + EE_Registry::$i18n_js_strings['timer_day'] = __('day', 'event_espresso'); |
|
1502 | + EE_Registry::$i18n_js_strings['timer_hour'] = __('hour', 'event_espresso'); |
|
1503 | + EE_Registry::$i18n_js_strings['timer_minute'] = __('minute', 'event_espresso'); |
|
1504 | + EE_Registry::$i18n_js_strings['timer_second'] = __('second', 'event_espresso'); |
|
1505 | + EE_Registry::$i18n_js_strings['registration_expiration_notice'] = sprintf( |
|
1506 | + __( |
|
1507 | + '%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 except our apologies for any inconvenience this may have caused.%8$s', |
|
1508 | + 'event_espresso' |
|
1509 | + ), |
|
1510 | + '<h4 class="important-notice">', |
|
1511 | + '</h4>', |
|
1512 | + '<br />', |
|
1513 | + '<p>', |
|
1514 | + '<a href="' . get_post_type_archive_link('espresso_events') . '" title="', |
|
1515 | + '">', |
|
1516 | + '</a>', |
|
1517 | + '</p>' |
|
1518 | + ); |
|
1519 | + EE_Registry::$i18n_js_strings['ajax_submit'] = apply_filters( |
|
1520 | + 'FHEE__Single_Page_Checkout__translate_js_strings__ajax_submit', |
|
1521 | + true |
|
1522 | + ); |
|
1523 | + EE_Registry::$i18n_js_strings['session_extension'] = absint( |
|
1524 | + apply_filters('FHEE__EE_Session__extend_expiration__seconds_added', 10 * MINUTE_IN_SECONDS) |
|
1525 | + ); |
|
1526 | + EE_Registry::$i18n_js_strings['session_expiration'] = gmdate( |
|
1527 | + 'M d, Y H:i:s', |
|
1528 | + EE_Registry::instance()->SSN->expiration() + (get_option('gmt_offset') * HOUR_IN_SECONDS) |
|
1529 | + ); |
|
1530 | + } |
|
1531 | + |
|
1532 | + |
|
1533 | + |
|
1534 | + /** |
|
1535 | + * enqueue_styles_and_scripts |
|
1536 | + * |
|
1537 | + * @access public |
|
1538 | + * @return void |
|
1539 | + * @throws EE_Error |
|
1540 | + */ |
|
1541 | + public function enqueue_styles_and_scripts() |
|
1542 | + { |
|
1543 | + // load css |
|
1544 | + wp_register_style( |
|
1545 | + 'single_page_checkout', |
|
1546 | + SPCO_CSS_URL . 'single_page_checkout.css', |
|
1547 | + array('espresso_default'), |
|
1548 | + EVENT_ESPRESSO_VERSION |
|
1549 | + ); |
|
1550 | + wp_enqueue_style('single_page_checkout'); |
|
1551 | + // load JS |
|
1552 | + wp_register_script( |
|
1553 | + 'jquery_plugin', |
|
1554 | + EE_THIRD_PARTY_URL . 'jquery .plugin.min.js', |
|
1555 | + array('jquery'), |
|
1556 | + '1.0.1', |
|
1557 | + true |
|
1558 | + ); |
|
1559 | + wp_register_script( |
|
1560 | + 'jquery_countdown', |
|
1561 | + EE_THIRD_PARTY_URL . 'jquery .countdown.min.js', |
|
1562 | + array('jquery_plugin'), |
|
1563 | + '2.0.2', |
|
1564 | + true |
|
1565 | + ); |
|
1566 | + wp_register_script( |
|
1567 | + 'single_page_checkout', |
|
1568 | + SPCO_JS_URL . 'single_page_checkout.js', |
|
1569 | + array('espresso_core', 'underscore', 'ee_form_section_validation', 'jquery_countdown'), |
|
1570 | + EVENT_ESPRESSO_VERSION, |
|
1571 | + true |
|
1572 | + ); |
|
1573 | + if ($this->checkout->registration_form instanceof EE_Form_Section_Proper) { |
|
1574 | + $this->checkout->registration_form->enqueue_js(); |
|
1575 | + } |
|
1576 | + if ($this->checkout->current_step->reg_form instanceof EE_Form_Section_Proper) { |
|
1577 | + $this->checkout->current_step->reg_form->enqueue_js(); |
|
1578 | + } |
|
1579 | + wp_enqueue_script('single_page_checkout'); |
|
1580 | + /** |
|
1581 | + * global action hook for enqueueing styles and scripts with |
|
1582 | + * spco calls. |
|
1583 | + */ |
|
1584 | + do_action('AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts', $this); |
|
1585 | + /** |
|
1586 | + * dynamic action hook for enqueueing styles and scripts with spco calls. |
|
1587 | + * The hook will end up being something like: |
|
1588 | + * AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__attendee_information |
|
1589 | + */ |
|
1590 | + do_action( |
|
1591 | + 'AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__' . $this->checkout->current_step->slug(), |
|
1592 | + $this |
|
1593 | + ); |
|
1594 | + } |
|
1595 | + |
|
1596 | + |
|
1597 | + |
|
1598 | + /** |
|
1599 | + * display the Registration Single Page Checkout Form |
|
1600 | + * |
|
1601 | + * @access private |
|
1602 | + * @return void |
|
1603 | + * @throws EE_Error |
|
1604 | + */ |
|
1605 | + private function _display_spco_reg_form() |
|
1606 | + { |
|
1607 | + // if registering via the admin, just display the reg form for the current step |
|
1608 | + if ($this->checkout->admin_request) { |
|
1609 | + EE_Registry::instance()->REQ->add_output($this->checkout->current_step->display_reg_form()); |
|
1610 | + } else { |
|
1611 | + // add powered by EE msg |
|
1612 | + add_action('AHEE__SPCO__reg_form_footer', array('EED_Single_Page_Checkout', 'display_registration_footer')); |
|
1613 | + $empty_cart = count( |
|
1614 | + $this->checkout->transaction->registrations($this->checkout->reg_cache_where_params) |
|
1615 | + ) < 1; |
|
1616 | + EE_Registry::$i18n_js_strings['empty_cart'] = $empty_cart; |
|
1617 | + $cookies_not_set_msg = ''; |
|
1618 | + if ($empty_cart && ! isset($_COOKIE['ee_cookie_test'])) { |
|
1619 | + $cookies_not_set_msg = apply_filters( |
|
1620 | + 'FHEE__Single_Page_Checkout__display_spco_reg_form__cookies_not_set_msg', |
|
1621 | + sprintf( |
|
1622 | + __( |
|
1623 | + '%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', |
|
1624 | + 'event_espresso' |
|
1625 | + ), |
|
1626 | + '<div class="ee-attention">', |
|
1627 | + '</div>', |
|
1628 | + '<h6 class="important-notice">', |
|
1629 | + '</h6>', |
|
1630 | + '<p>', |
|
1631 | + '</p>', |
|
1632 | + '<br />', |
|
1633 | + '<a href="http://www.whatarecookies.com/enable.asp" target="_blank">', |
|
1634 | + '</a>' |
|
1635 | + ) |
|
1636 | + ); |
|
1637 | + } |
|
1638 | + $this->checkout->registration_form = new EE_Form_Section_Proper( |
|
1639 | + array( |
|
1640 | + 'name' => 'single-page-checkout', |
|
1641 | + 'html_id' => 'ee-single-page-checkout-dv', |
|
1642 | + 'layout_strategy' => |
|
1643 | + new EE_Template_Layout( |
|
1644 | + array( |
|
1645 | + 'layout_template_file' => SPCO_TEMPLATES_PATH . 'registration_page_wrapper.template.php', |
|
1646 | + 'template_args' => array( |
|
1647 | + 'empty_cart' => $empty_cart, |
|
1648 | + 'revisit' => $this->checkout->revisit, |
|
1649 | + 'reg_steps' => $this->checkout->reg_steps, |
|
1650 | + 'next_step' => $this->checkout->next_step instanceof EE_SPCO_Reg_Step |
|
1651 | + ? $this->checkout->next_step->slug() |
|
1652 | + : '', |
|
1653 | + 'cancel_page_url' => $this->checkout->cancel_page_url, |
|
1654 | + 'empty_msg' => apply_filters( |
|
1655 | + 'FHEE__Single_Page_Checkout__display_spco_reg_form__empty_msg', |
|
1656 | + sprintf( |
|
1657 | + __( |
|
1658 | + 'You need to %1$sReturn to Events list%2$sselect at least one event%3$s before you can proceed with the registration process.', |
|
1659 | + 'event_espresso' |
|
1660 | + ), |
|
1661 | + '<a href="' |
|
1662 | + . get_post_type_archive_link('espresso_events') |
|
1663 | + . '" title="', |
|
1664 | + '">', |
|
1665 | + '</a>' |
|
1666 | + ) |
|
1667 | + ), |
|
1668 | + 'cookies_not_set_msg' => $cookies_not_set_msg, |
|
1669 | + 'registration_time_limit' => $this->checkout->get_registration_time_limit(), |
|
1670 | + 'session_expiration' => gmdate( |
|
1671 | + 'M d, Y H:i:s', |
|
1672 | + EE_Registry::instance()->SSN->expiration() |
|
1673 | + + (get_option('gmt_offset') * HOUR_IN_SECONDS) |
|
1674 | + ), |
|
1675 | + ), |
|
1676 | + ) |
|
1677 | + ), |
|
1678 | + ) |
|
1679 | + ); |
|
1680 | + // load template and add to output sent that gets filtered into the_content() |
|
1681 | + EE_Registry::instance()->REQ->add_output($this->checkout->registration_form->get_html()); |
|
1682 | + } |
|
1683 | + } |
|
1684 | + |
|
1685 | + |
|
1686 | + |
|
1687 | + /** |
|
1688 | + * add_extra_finalize_registration_inputs |
|
1689 | + * |
|
1690 | + * @access public |
|
1691 | + * @param $next_step |
|
1692 | + * @internal param string $label |
|
1693 | + * @return void |
|
1694 | + */ |
|
1695 | + public function add_extra_finalize_registration_inputs($next_step) |
|
1696 | + { |
|
1697 | + if ($next_step === 'finalize_registration') { |
|
1698 | + echo '<div id="spco-extra-finalize_registration-inputs-dv"></div>'; |
|
1699 | + } |
|
1700 | + } |
|
1701 | + |
|
1702 | + |
|
1703 | + |
|
1704 | + /** |
|
1705 | + * display_registration_footer |
|
1706 | + * |
|
1707 | + * @access public |
|
1708 | + * @return string |
|
1709 | + */ |
|
1710 | + public static function display_registration_footer() |
|
1711 | + { |
|
1712 | + if ( |
|
1713 | + apply_filters( |
|
1714 | + 'FHEE__EE_Front__Controller__show_reg_footer', |
|
1715 | + EE_Registry::instance()->CFG->admin->show_reg_footer |
|
1716 | + ) |
|
1717 | + ) { |
|
1718 | + add_filter( |
|
1719 | + 'FHEE__EEH_Template__powered_by_event_espresso__url', |
|
1720 | + function ($url) { |
|
1721 | + return apply_filters('FHEE__EE_Front_Controller__registration_footer__url', $url); |
|
1722 | + } |
|
1723 | + ); |
|
1724 | + echo apply_filters( |
|
1725 | + 'FHEE__EE_Front_Controller__display_registration_footer', |
|
1726 | + \EEH_Template::powered_by_event_espresso( |
|
1727 | + '', |
|
1728 | + 'espresso-registration-footer-dv', |
|
1729 | + array('utm_content' => 'registration_checkout') |
|
1730 | + ) |
|
1731 | + ); |
|
1732 | + } |
|
1733 | + return ''; |
|
1734 | + } |
|
1735 | + |
|
1736 | + |
|
1737 | + |
|
1738 | + /** |
|
1739 | + * unlock_transaction |
|
1740 | + * |
|
1741 | + * @access public |
|
1742 | + * @return void |
|
1743 | + * @throws EE_Error |
|
1744 | + */ |
|
1745 | + public function unlock_transaction() |
|
1746 | + { |
|
1747 | + if ($this->checkout->transaction instanceof EE_Transaction) { |
|
1748 | + $this->checkout->transaction->unlock(); |
|
1749 | + } |
|
1750 | + } |
|
1751 | + |
|
1752 | + |
|
1753 | + |
|
1754 | + /** |
|
1755 | + * _setup_redirect |
|
1756 | + * |
|
1757 | + * @access private |
|
1758 | + * @return void |
|
1759 | + */ |
|
1760 | + private function _setup_redirect() |
|
1761 | + { |
|
1762 | + if ($this->checkout->continue_reg && $this->checkout->next_step instanceof EE_SPCO_Reg_Step) { |
|
1763 | + $this->checkout->redirect = true; |
|
1764 | + if (empty($this->checkout->redirect_url)) { |
|
1765 | + $this->checkout->redirect_url = $this->checkout->next_step->reg_step_url(); |
|
1766 | + } |
|
1767 | + $this->checkout->redirect_url = apply_filters( |
|
1768 | + 'FHEE__EED_Single_Page_Checkout___setup_redirect__checkout_redirect_url', |
|
1769 | + $this->checkout->redirect_url, |
|
1770 | + $this->checkout |
|
1771 | + ); |
|
1772 | + } |
|
1773 | + } |
|
1774 | + |
|
1775 | + |
|
1776 | + |
|
1777 | + /** |
|
1778 | + * handle ajax message responses and redirects |
|
1779 | + * |
|
1780 | + * @access public |
|
1781 | + * @return void |
|
1782 | + * @throws EE_Error |
|
1783 | + */ |
|
1784 | + public function go_to_next_step() |
|
1785 | + { |
|
1786 | + if (EE_Registry::instance()->REQ->ajax) { |
|
1787 | + // capture contents of output buffer we started earlier in the request, and insert into JSON response |
|
1788 | + $this->checkout->json_response->set_unexpected_errors(ob_get_clean()); |
|
1789 | + } |
|
1790 | + $this->unlock_transaction(); |
|
1791 | + // just return for these conditions |
|
1792 | + if ( |
|
1793 | + $this->checkout->admin_request |
|
1794 | + || $this->checkout->action === 'redirect_form' |
|
1795 | + || $this->checkout->action === 'update_checkout' |
|
1796 | + ) { |
|
1797 | + return; |
|
1798 | + } |
|
1799 | + // AJAX response |
|
1800 | + $this->_handle_json_response(); |
|
1801 | + // redirect to next step or the Thank You page |
|
1802 | + $this->_handle_html_redirects(); |
|
1803 | + // hmmm... must be something wrong, so let's just display the form again ! |
|
1804 | + $this->_display_spco_reg_form(); |
|
1805 | + } |
|
1806 | + |
|
1807 | + |
|
1808 | + |
|
1809 | + /** |
|
1810 | + * _handle_json_response |
|
1811 | + * |
|
1812 | + * @access protected |
|
1813 | + * @return void |
|
1814 | + */ |
|
1815 | + protected function _handle_json_response() |
|
1816 | + { |
|
1817 | + // if this is an ajax request |
|
1818 | + if (EE_Registry::instance()->REQ->ajax) { |
|
1819 | + // DEBUG LOG |
|
1820 | + //$this->checkout->log( |
|
1821 | + // __CLASS__, __FUNCTION__, __LINE__, |
|
1822 | + // array( |
|
1823 | + // 'json_response_redirect_url' => $this->checkout->json_response->redirect_url(), |
|
1824 | + // 'redirect' => $this->checkout->redirect, |
|
1825 | + // 'continue_reg' => $this->checkout->continue_reg, |
|
1826 | + // ) |
|
1827 | + //); |
|
1828 | + $this->checkout->json_response->set_registration_time_limit( |
|
1829 | + $this->checkout->get_registration_time_limit() |
|
1830 | + ); |
|
1831 | + $this->checkout->json_response->set_payment_amount($this->checkout->amount_owing); |
|
1832 | + // just send the ajax ( |
|
1833 | + $json_response = apply_filters( |
|
1834 | + 'FHEE__EE_Single_Page_Checkout__JSON_response', |
|
1835 | + $this->checkout->json_response |
|
1836 | + ); |
|
1837 | + echo $json_response; |
|
1838 | + exit(); |
|
1839 | + } |
|
1840 | + } |
|
1841 | + |
|
1842 | + |
|
1843 | + |
|
1844 | + /** |
|
1845 | + * _handle_redirects |
|
1846 | + * |
|
1847 | + * @access protected |
|
1848 | + * @return void |
|
1849 | + */ |
|
1850 | + protected function _handle_html_redirects() |
|
1851 | + { |
|
1852 | + // going somewhere ? |
|
1853 | + if ($this->checkout->redirect && ! empty($this->checkout->redirect_url)) { |
|
1854 | + // store notices in a transient |
|
1855 | + EE_Error::get_notices(false, true, true); |
|
1856 | + // DEBUG LOG |
|
1857 | + //$this->checkout->log( |
|
1858 | + // __CLASS__, __FUNCTION__, __LINE__, |
|
1859 | + // array( |
|
1860 | + // 'headers_sent' => headers_sent(), |
|
1861 | + // 'redirect_url' => $this->checkout->redirect_url, |
|
1862 | + // 'headers_list' => headers_list(), |
|
1863 | + // ) |
|
1864 | + //); |
|
1865 | + wp_safe_redirect($this->checkout->redirect_url); |
|
1866 | + exit(); |
|
1867 | + } |
|
1868 | + } |
|
1869 | + |
|
1870 | + |
|
1871 | + |
|
1872 | + /** |
|
1873 | + * set_checkout_anchor |
|
1874 | + * |
|
1875 | + * @access public |
|
1876 | + * @return void |
|
1877 | + */ |
|
1878 | + public function set_checkout_anchor() |
|
1879 | + { |
|
1880 | + echo '<a id="checkout" style="float: left; margin-left: -999em;"></a>'; |
|
1881 | + } |
|
1882 | 1882 | |
1883 | 1883 | |
1884 | 1884 |
@@ -53,7 +53,7 @@ |
||
53 | 53 | |
54 | 54 | /** |
55 | 55 | * Callback for FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks hook |
56 | - * @param $callbacks |
|
56 | + * @param callable[] $callbacks |
|
57 | 57 | * @return array |
58 | 58 | */ |
59 | 59 | public function modify_callbacks($callbacks) |
@@ -18,207 +18,207 @@ |
||
18 | 18 | { |
19 | 19 | |
20 | 20 | |
21 | - /** |
|
22 | - * @var EE_Event|null |
|
23 | - */ |
|
24 | - protected $_event; |
|
25 | - |
|
26 | - |
|
27 | - protected function _set_hooks_properties() |
|
28 | - { |
|
29 | - |
|
30 | - $this->_name = 'registration_form'; |
|
31 | - $this->_metaboxes = array( |
|
32 | - 0 => array( |
|
33 | - 'page_route' => array('edit', 'create_new'), |
|
34 | - 'func' => 'primary_questions', |
|
35 | - 'label' => esc_html__('Questions for Primary Registrant', 'event_espresso'), |
|
36 | - 'priority' => 'default', |
|
37 | - 'context' => 'side', |
|
38 | - ), |
|
39 | - ); |
|
40 | - |
|
41 | - //hook into the handler for saving question groups |
|
42 | - add_filter( |
|
43 | - 'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks', |
|
44 | - array($this, 'modify_callbacks'), |
|
45 | - 10 |
|
46 | - ); |
|
47 | - |
|
48 | - //hook into revision restores (we're hooking into the global action because EE_Admin_Hooks classes are already |
|
49 | - //restricted by page) |
|
50 | - add_action('AHEE_EE_Admin_Page_CPT__restore_revision', array($this, 'restore_revision'), 10, 2); |
|
51 | - } |
|
52 | - |
|
53 | - |
|
54 | - /** |
|
55 | - * Callback for FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks hook |
|
56 | - * @param $callbacks |
|
57 | - * @return array |
|
58 | - */ |
|
59 | - public function modify_callbacks($callbacks) |
|
60 | - { |
|
61 | - //now let's add the question group callback |
|
62 | - $callbacks[] = array($this, 'primary_question_group_update'); |
|
63 | - return $callbacks; |
|
64 | - } |
|
65 | - |
|
66 | - |
|
67 | - /** |
|
68 | - * Hooked into revision restores. |
|
69 | - * @param $post_id |
|
70 | - * @param $revision_id |
|
71 | - * @return EE_Base_Class |
|
72 | - * @throws EE_Error |
|
73 | - * @throws InvalidArgumentException |
|
74 | - * @throws ReflectionException |
|
75 | - * @throws InvalidDataTypeException |
|
76 | - * @throws InvalidInterfaceException |
|
77 | - */ |
|
78 | - public function restore_revision($post_id, $revision_id) |
|
79 | - { |
|
80 | - $EVT_MDL = EE_Registry::instance()->load_model('Event'); |
|
81 | - $post_evt = $EVT_MDL->get_one_by_ID($post_id); |
|
82 | - //restore revision for primary questions |
|
83 | - $post_evt->restore_revision( |
|
84 | - $revision_id, |
|
85 | - array('Question_Group'), |
|
86 | - array('Question_Group' => array('Event_Question_Group.EQG_primary' => 1)) |
|
87 | - ); |
|
88 | - return $post_evt; |
|
89 | - } |
|
90 | - |
|
91 | - |
|
92 | - /** |
|
93 | - * Content of metabox. |
|
94 | - * @param $post_id |
|
95 | - * @param $post |
|
96 | - * @throws EE_Error |
|
97 | - * @throws InvalidArgumentException |
|
98 | - * @throws InvalidDataTypeException |
|
99 | - * @throws InvalidInterfaceException |
|
100 | - */ |
|
101 | - public function primary_questions($post_id, $post) |
|
102 | - { |
|
103 | - $this->_event = $this->_adminpage_obj->get_event_object(); |
|
104 | - $event_id = $this->_event->ID(); |
|
105 | - ?> |
|
21 | + /** |
|
22 | + * @var EE_Event|null |
|
23 | + */ |
|
24 | + protected $_event; |
|
25 | + |
|
26 | + |
|
27 | + protected function _set_hooks_properties() |
|
28 | + { |
|
29 | + |
|
30 | + $this->_name = 'registration_form'; |
|
31 | + $this->_metaboxes = array( |
|
32 | + 0 => array( |
|
33 | + 'page_route' => array('edit', 'create_new'), |
|
34 | + 'func' => 'primary_questions', |
|
35 | + 'label' => esc_html__('Questions for Primary Registrant', 'event_espresso'), |
|
36 | + 'priority' => 'default', |
|
37 | + 'context' => 'side', |
|
38 | + ), |
|
39 | + ); |
|
40 | + |
|
41 | + //hook into the handler for saving question groups |
|
42 | + add_filter( |
|
43 | + 'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks', |
|
44 | + array($this, 'modify_callbacks'), |
|
45 | + 10 |
|
46 | + ); |
|
47 | + |
|
48 | + //hook into revision restores (we're hooking into the global action because EE_Admin_Hooks classes are already |
|
49 | + //restricted by page) |
|
50 | + add_action('AHEE_EE_Admin_Page_CPT__restore_revision', array($this, 'restore_revision'), 10, 2); |
|
51 | + } |
|
52 | + |
|
53 | + |
|
54 | + /** |
|
55 | + * Callback for FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks hook |
|
56 | + * @param $callbacks |
|
57 | + * @return array |
|
58 | + */ |
|
59 | + public function modify_callbacks($callbacks) |
|
60 | + { |
|
61 | + //now let's add the question group callback |
|
62 | + $callbacks[] = array($this, 'primary_question_group_update'); |
|
63 | + return $callbacks; |
|
64 | + } |
|
65 | + |
|
66 | + |
|
67 | + /** |
|
68 | + * Hooked into revision restores. |
|
69 | + * @param $post_id |
|
70 | + * @param $revision_id |
|
71 | + * @return EE_Base_Class |
|
72 | + * @throws EE_Error |
|
73 | + * @throws InvalidArgumentException |
|
74 | + * @throws ReflectionException |
|
75 | + * @throws InvalidDataTypeException |
|
76 | + * @throws InvalidInterfaceException |
|
77 | + */ |
|
78 | + public function restore_revision($post_id, $revision_id) |
|
79 | + { |
|
80 | + $EVT_MDL = EE_Registry::instance()->load_model('Event'); |
|
81 | + $post_evt = $EVT_MDL->get_one_by_ID($post_id); |
|
82 | + //restore revision for primary questions |
|
83 | + $post_evt->restore_revision( |
|
84 | + $revision_id, |
|
85 | + array('Question_Group'), |
|
86 | + array('Question_Group' => array('Event_Question_Group.EQG_primary' => 1)) |
|
87 | + ); |
|
88 | + return $post_evt; |
|
89 | + } |
|
90 | + |
|
91 | + |
|
92 | + /** |
|
93 | + * Content of metabox. |
|
94 | + * @param $post_id |
|
95 | + * @param $post |
|
96 | + * @throws EE_Error |
|
97 | + * @throws InvalidArgumentException |
|
98 | + * @throws InvalidDataTypeException |
|
99 | + * @throws InvalidInterfaceException |
|
100 | + */ |
|
101 | + public function primary_questions($post_id, $post) |
|
102 | + { |
|
103 | + $this->_event = $this->_adminpage_obj->get_event_object(); |
|
104 | + $event_id = $this->_event->ID(); |
|
105 | + ?> |
|
106 | 106 | <div class="inside"> |
107 | 107 | <p><strong> |
108 | 108 | <?php _e('Question Groups', 'event_espresso'); ?> |
109 | 109 | </strong><br/> |
110 | 110 | <?php |
111 | - printf( |
|
112 | - esc_html__( |
|
113 | - 'Add a pre-populated %1$sgroup of questions%2$s to your event. The personal information group is required for all events', |
|
114 | - 'event_espresso' |
|
115 | - ), |
|
116 | - '<a href="admin.php?page=espresso_registration_form" target="_blank">', |
|
117 | - '</a>' |
|
118 | - ) |
|
119 | - ?> |
|
111 | + printf( |
|
112 | + esc_html__( |
|
113 | + 'Add a pre-populated %1$sgroup of questions%2$s to your event. The personal information group is required for all events', |
|
114 | + 'event_espresso' |
|
115 | + ), |
|
116 | + '<a href="admin.php?page=espresso_registration_form" target="_blank">', |
|
117 | + '</a>' |
|
118 | + ) |
|
119 | + ?> |
|
120 | 120 | </p> |
121 | 121 | <?php |
122 | 122 | |
123 | - $qsg_where['QSG_deleted'] = false; |
|
124 | - $query_params = apply_filters( |
|
125 | - 'FHEE__espresso_events_Registration_Form_Hooks__primary_questions__question_group_query_parameters', |
|
126 | - array($qsg_where, 'order_by' => array('QSG_order' => 'ASC')) |
|
127 | - ); |
|
128 | - $QSGs = EEM_Question_Group::instance()->get_all($query_params); |
|
129 | - $EQGs = ! empty($event_id) |
|
130 | - ? $this->_event->get_many_related( |
|
131 | - 'Question_Group', |
|
132 | - array(array('Event_Question_Group.EQG_primary' => 1)) |
|
133 | - ) |
|
134 | - : array(); |
|
135 | - $EQGids = array_keys($EQGs); |
|
136 | - |
|
137 | - if (! empty($QSGs)) { |
|
138 | - $html = count($QSGs) > 10 ? '<div style="height:250px;overflow:auto;">' : ''; |
|
139 | - foreach ($QSGs as $QSG) { |
|
140 | - $checked = in_array($QSG->ID(), $EQGids, true) |
|
141 | - || $QSG->get('QSG_system') === 1 |
|
142 | - ? ' checked="checked"' |
|
143 | - : ''; |
|
144 | - $visibility = $QSG->get('QSG_system') === 1 |
|
145 | - ? ' style="visibility:hidden"' |
|
146 | - : ''; |
|
147 | - $edit_query_args = $this->_adminpage_obj->is_caf() ? array( |
|
148 | - 'action' => 'edit_question_group', |
|
149 | - 'QSG_ID' => $QSG->ID(), |
|
150 | - ) : array('action' => 'question_groups'); |
|
151 | - $edit_link = EE_Admin_Page::add_query_args_and_nonce( |
|
152 | - $edit_query_args, |
|
153 | - EE_FORMS_ADMIN_URL |
|
154 | - ); |
|
155 | - |
|
156 | - $html .= ' |
|
123 | + $qsg_where['QSG_deleted'] = false; |
|
124 | + $query_params = apply_filters( |
|
125 | + 'FHEE__espresso_events_Registration_Form_Hooks__primary_questions__question_group_query_parameters', |
|
126 | + array($qsg_where, 'order_by' => array('QSG_order' => 'ASC')) |
|
127 | + ); |
|
128 | + $QSGs = EEM_Question_Group::instance()->get_all($query_params); |
|
129 | + $EQGs = ! empty($event_id) |
|
130 | + ? $this->_event->get_many_related( |
|
131 | + 'Question_Group', |
|
132 | + array(array('Event_Question_Group.EQG_primary' => 1)) |
|
133 | + ) |
|
134 | + : array(); |
|
135 | + $EQGids = array_keys($EQGs); |
|
136 | + |
|
137 | + if (! empty($QSGs)) { |
|
138 | + $html = count($QSGs) > 10 ? '<div style="height:250px;overflow:auto;">' : ''; |
|
139 | + foreach ($QSGs as $QSG) { |
|
140 | + $checked = in_array($QSG->ID(), $EQGids, true) |
|
141 | + || $QSG->get('QSG_system') === 1 |
|
142 | + ? ' checked="checked"' |
|
143 | + : ''; |
|
144 | + $visibility = $QSG->get('QSG_system') === 1 |
|
145 | + ? ' style="visibility:hidden"' |
|
146 | + : ''; |
|
147 | + $edit_query_args = $this->_adminpage_obj->is_caf() ? array( |
|
148 | + 'action' => 'edit_question_group', |
|
149 | + 'QSG_ID' => $QSG->ID(), |
|
150 | + ) : array('action' => 'question_groups'); |
|
151 | + $edit_link = EE_Admin_Page::add_query_args_and_nonce( |
|
152 | + $edit_query_args, |
|
153 | + EE_FORMS_ADMIN_URL |
|
154 | + ); |
|
155 | + |
|
156 | + $html .= ' |
|
157 | 157 | <p id="event-question-group-' . $QSG->ID() . '"> |
158 | 158 | <input value="' . $QSG->ID() . '" type="checkbox"' |
159 | - . $visibility |
|
160 | - . ' name="question_groups[' . $QSG->ID() . ']"' . $checked . ' /> |
|
159 | + . $visibility |
|
160 | + . ' name="question_groups[' . $QSG->ID() . ']"' . $checked . ' /> |
|
161 | 161 | <a href="' . $edit_link . '" title="' |
162 | - . sprintf( |
|
163 | - esc_attr__('Edit %s Group', 'event_espresso'), |
|
164 | - $QSG->get('QSG_name') |
|
165 | - ) |
|
166 | - . '" target="_blank">' . $QSG->get('QSG_name') . '</a> |
|
162 | + . sprintf( |
|
163 | + esc_attr__('Edit %s Group', 'event_espresso'), |
|
164 | + $QSG->get('QSG_name') |
|
165 | + ) |
|
166 | + . '" target="_blank">' . $QSG->get('QSG_name') . '</a> |
|
167 | 167 | </p>'; |
168 | - } |
|
169 | - $html .= count($QSGs) > 10 ? '</div>' : ''; |
|
170 | - |
|
171 | - echo $html; |
|
172 | - } else { |
|
173 | - esc_html_e( |
|
174 | - 'There seems to be a problem with your questions. Please contact [email protected]', |
|
175 | - 'event_espresso' |
|
176 | - ); |
|
177 | - } |
|
178 | - do_action('AHEE_event_editor_questions_notice'); |
|
179 | - ?> |
|
168 | + } |
|
169 | + $html .= count($QSGs) > 10 ? '</div>' : ''; |
|
170 | + |
|
171 | + echo $html; |
|
172 | + } else { |
|
173 | + esc_html_e( |
|
174 | + 'There seems to be a problem with your questions. Please contact [email protected]', |
|
175 | + 'event_espresso' |
|
176 | + ); |
|
177 | + } |
|
178 | + do_action('AHEE_event_editor_questions_notice'); |
|
179 | + ?> |
|
180 | 180 | </div> |
181 | 181 | <?php |
182 | - } |
|
183 | - |
|
184 | - |
|
185 | - /** |
|
186 | - * @param EE_Event $evtobj |
|
187 | - * @param array $data |
|
188 | - * @return bool |
|
189 | - * @throws EE_Error |
|
190 | - */ |
|
191 | - public function primary_question_group_update($evtobj, $data) |
|
192 | - { |
|
193 | - $question_groups = ! empty($data['question_groups']) ? (array)$data['question_groups'] : array(); |
|
194 | - $added_qgs = array_keys($question_groups); |
|
195 | - $success = array(); |
|
196 | - |
|
197 | - //let's get all current question groups associated with this event. |
|
198 | - $current_qgs = $evtobj->get_many_related( |
|
199 | - 'Question_Group', |
|
200 | - array(array('Event_Question_Group.EQG_primary' => 1)) |
|
201 | - ); |
|
202 | - $current_qgs = array_keys($current_qgs); //we just want the ids |
|
203 | - |
|
204 | - //now let's get the groups selected in the editor and update (IF we have data) |
|
205 | - if (! empty($question_groups)) { |
|
206 | - foreach ($question_groups as $id => $val) { |
|
207 | - //add to event |
|
208 | - if ($val) { |
|
209 | - $qg = $evtobj->_add_relation_to($id, 'Question_Group', array('EQG_primary' => 1)); |
|
210 | - } |
|
211 | - $success[] = ! empty($qg) ? 1 : 0; |
|
212 | - } |
|
213 | - } |
|
214 | - |
|
215 | - //wait a minute... are there question groups missing in the saved groups that ARE with the current event? |
|
216 | - $removed_qgs = array_diff($current_qgs, $added_qgs); |
|
217 | - |
|
218 | - foreach ($removed_qgs as $qgid) { |
|
219 | - $qg = $evtobj->_remove_relation_to($qgid, 'Question_Group', array('EQG_primary' => 1)); |
|
220 | - $success[] = ! empty($qg) ? 1 : 0; |
|
221 | - } |
|
222 | - return in_array(0, $success, true) ? false : true; |
|
223 | - } |
|
182 | + } |
|
183 | + |
|
184 | + |
|
185 | + /** |
|
186 | + * @param EE_Event $evtobj |
|
187 | + * @param array $data |
|
188 | + * @return bool |
|
189 | + * @throws EE_Error |
|
190 | + */ |
|
191 | + public function primary_question_group_update($evtobj, $data) |
|
192 | + { |
|
193 | + $question_groups = ! empty($data['question_groups']) ? (array)$data['question_groups'] : array(); |
|
194 | + $added_qgs = array_keys($question_groups); |
|
195 | + $success = array(); |
|
196 | + |
|
197 | + //let's get all current question groups associated with this event. |
|
198 | + $current_qgs = $evtobj->get_many_related( |
|
199 | + 'Question_Group', |
|
200 | + array(array('Event_Question_Group.EQG_primary' => 1)) |
|
201 | + ); |
|
202 | + $current_qgs = array_keys($current_qgs); //we just want the ids |
|
203 | + |
|
204 | + //now let's get the groups selected in the editor and update (IF we have data) |
|
205 | + if (! empty($question_groups)) { |
|
206 | + foreach ($question_groups as $id => $val) { |
|
207 | + //add to event |
|
208 | + if ($val) { |
|
209 | + $qg = $evtobj->_add_relation_to($id, 'Question_Group', array('EQG_primary' => 1)); |
|
210 | + } |
|
211 | + $success[] = ! empty($qg) ? 1 : 0; |
|
212 | + } |
|
213 | + } |
|
214 | + |
|
215 | + //wait a minute... are there question groups missing in the saved groups that ARE with the current event? |
|
216 | + $removed_qgs = array_diff($current_qgs, $added_qgs); |
|
217 | + |
|
218 | + foreach ($removed_qgs as $qgid) { |
|
219 | + $qg = $evtobj->_remove_relation_to($qgid, 'Question_Group', array('EQG_primary' => 1)); |
|
220 | + $success[] = ! empty($qg) ? 1 : 0; |
|
221 | + } |
|
222 | + return in_array(0, $success, true) ? false : true; |
|
223 | + } |
|
224 | 224 | } |
@@ -132,12 +132,12 @@ discard block |
||
132 | 132 | array(array('Event_Question_Group.EQG_primary' => 1)) |
133 | 133 | ) |
134 | 134 | : array(); |
135 | - $EQGids = array_keys($EQGs); |
|
135 | + $EQGids = array_keys($EQGs); |
|
136 | 136 | |
137 | - if (! empty($QSGs)) { |
|
137 | + if ( ! empty($QSGs)) { |
|
138 | 138 | $html = count($QSGs) > 10 ? '<div style="height:250px;overflow:auto;">' : ''; |
139 | 139 | foreach ($QSGs as $QSG) { |
140 | - $checked = in_array($QSG->ID(), $EQGids, true) |
|
140 | + $checked = in_array($QSG->ID(), $EQGids, true) |
|
141 | 141 | || $QSG->get('QSG_system') === 1 |
142 | 142 | ? ' checked="checked"' |
143 | 143 | : ''; |
@@ -148,22 +148,22 @@ discard block |
||
148 | 148 | 'action' => 'edit_question_group', |
149 | 149 | 'QSG_ID' => $QSG->ID(), |
150 | 150 | ) : array('action' => 'question_groups'); |
151 | - $edit_link = EE_Admin_Page::add_query_args_and_nonce( |
|
151 | + $edit_link = EE_Admin_Page::add_query_args_and_nonce( |
|
152 | 152 | $edit_query_args, |
153 | 153 | EE_FORMS_ADMIN_URL |
154 | 154 | ); |
155 | 155 | |
156 | 156 | $html .= ' |
157 | - <p id="event-question-group-' . $QSG->ID() . '"> |
|
158 | - <input value="' . $QSG->ID() . '" type="checkbox"' |
|
157 | + <p id="event-question-group-' . $QSG->ID().'"> |
|
158 | + <input value="' . $QSG->ID().'" type="checkbox"' |
|
159 | 159 | . $visibility |
160 | - . ' name="question_groups[' . $QSG->ID() . ']"' . $checked . ' /> |
|
161 | - <a href="' . $edit_link . '" title="' |
|
160 | + . ' name="question_groups['.$QSG->ID().']"'.$checked.' /> |
|
161 | + <a href="' . $edit_link.'" title="' |
|
162 | 162 | . sprintf( |
163 | 163 | esc_attr__('Edit %s Group', 'event_espresso'), |
164 | 164 | $QSG->get('QSG_name') |
165 | 165 | ) |
166 | - . '" target="_blank">' . $QSG->get('QSG_name') . '</a> |
|
166 | + . '" target="_blank">'.$QSG->get('QSG_name').'</a> |
|
167 | 167 | </p>'; |
168 | 168 | } |
169 | 169 | $html .= count($QSGs) > 10 ? '</div>' : ''; |
@@ -190,7 +190,7 @@ discard block |
||
190 | 190 | */ |
191 | 191 | public function primary_question_group_update($evtobj, $data) |
192 | 192 | { |
193 | - $question_groups = ! empty($data['question_groups']) ? (array)$data['question_groups'] : array(); |
|
193 | + $question_groups = ! empty($data['question_groups']) ? (array) $data['question_groups'] : array(); |
|
194 | 194 | $added_qgs = array_keys($question_groups); |
195 | 195 | $success = array(); |
196 | 196 | |
@@ -202,7 +202,7 @@ discard block |
||
202 | 202 | $current_qgs = array_keys($current_qgs); //we just want the ids |
203 | 203 | |
204 | 204 | //now let's get the groups selected in the editor and update (IF we have data) |
205 | - if (! empty($question_groups)) { |
|
205 | + if ( ! empty($question_groups)) { |
|
206 | 206 | foreach ($question_groups as $id => $val) { |
207 | 207 | //add to event |
208 | 208 | if ($val) { |
@@ -17,208 +17,208 @@ |
||
17 | 17 | class espresso_events_Registration_Form_Hooks_Extend extends espresso_events_Registration_Form_Hooks |
18 | 18 | { |
19 | 19 | |
20 | - /** |
|
21 | - * extending the properties set in espresso_events_Registration_From_Hooks |
|
22 | - * |
|
23 | - * @access protected |
|
24 | - * @return void |
|
25 | - */ |
|
26 | - protected function _extend_properties() |
|
27 | - { |
|
28 | - $this->_metaboxes = array_merge( |
|
29 | - $this->_metaboxes, |
|
30 | - array( |
|
31 | - 1 => array( |
|
32 | - 'page_route' => array('create_new', 'edit'), |
|
33 | - 'func' => 'additional_questions', |
|
34 | - 'label' => esc_html__('Questions for Additional Registrants', 'event_espresso'), |
|
35 | - 'priority' => 'default', |
|
36 | - 'context' => 'side', |
|
37 | - ), |
|
38 | - ) |
|
39 | - ); |
|
40 | - $this->_scripts_styles = array( |
|
41 | - 'registers' => array( |
|
42 | - 'extended-event-editor' => array( |
|
43 | - 'url' => EE_CORE_CAF_ADMIN_EXTEND_URL |
|
44 | - . 'registration_form/assets/event-editor-question-groups.js', |
|
45 | - 'depends' => array('jquery'), |
|
46 | - ), |
|
47 | - ), |
|
48 | - 'enqueues' => array( |
|
49 | - 'extended-event-editor' => array('edit', 'create_new'), |
|
50 | - ), |
|
51 | - ); |
|
52 | - } |
|
53 | - |
|
54 | - |
|
55 | - /** |
|
56 | - * @param Callable[] $callbacks |
|
57 | - * @return array |
|
58 | - */ |
|
59 | - public function modify_callbacks($callbacks) |
|
60 | - { |
|
61 | - $callbacks = parent::modify_callbacks($callbacks); |
|
62 | - $callbacks[] = array($this, 'additional_question_group_update'); |
|
63 | - return $callbacks; |
|
64 | - } |
|
65 | - |
|
66 | - |
|
67 | - /** |
|
68 | - * Call back hooked into revision restores. |
|
69 | - * |
|
70 | - * @param $post_id |
|
71 | - * @param $revision_id |
|
72 | - * @return EE_Base_Class|void |
|
73 | - * @throws EE_Error |
|
74 | - * @throws InvalidArgumentException |
|
75 | - * @throws InvalidDataTypeException |
|
76 | - * @throws InvalidInterfaceException |
|
77 | - * @throws ReflectionException |
|
78 | - */ |
|
79 | - public function restore_revision($post_id, $revision_id) |
|
80 | - { |
|
81 | - $post_evt = parent::restore_revision($post_id, $revision_id); |
|
82 | - |
|
83 | - //restore revision for additional questions |
|
84 | - $post_evt->restore_revision( |
|
85 | - $revision_id, |
|
86 | - array('Question_Group'), |
|
87 | - array('Question_Group' => array('Event_Question_Group.EQG_primary' => 0) |
|
88 | - ) |
|
89 | - ); |
|
90 | - } |
|
91 | - |
|
92 | - |
|
93 | - /** |
|
94 | - * @param $post_id |
|
95 | - * @param $post |
|
96 | - * @throws EE_Error |
|
97 | - * @throws InvalidArgumentException |
|
98 | - * @throws InvalidDataTypeException |
|
99 | - * @throws InvalidInterfaceException |
|
100 | - */ |
|
101 | - public function additional_questions($post_id, $post) |
|
102 | - { |
|
103 | - $this->_event = $this->_adminpage_obj->get_event_object(); |
|
104 | - $event_id = $this->_event->ID(); |
|
105 | - ?> |
|
20 | + /** |
|
21 | + * extending the properties set in espresso_events_Registration_From_Hooks |
|
22 | + * |
|
23 | + * @access protected |
|
24 | + * @return void |
|
25 | + */ |
|
26 | + protected function _extend_properties() |
|
27 | + { |
|
28 | + $this->_metaboxes = array_merge( |
|
29 | + $this->_metaboxes, |
|
30 | + array( |
|
31 | + 1 => array( |
|
32 | + 'page_route' => array('create_new', 'edit'), |
|
33 | + 'func' => 'additional_questions', |
|
34 | + 'label' => esc_html__('Questions for Additional Registrants', 'event_espresso'), |
|
35 | + 'priority' => 'default', |
|
36 | + 'context' => 'side', |
|
37 | + ), |
|
38 | + ) |
|
39 | + ); |
|
40 | + $this->_scripts_styles = array( |
|
41 | + 'registers' => array( |
|
42 | + 'extended-event-editor' => array( |
|
43 | + 'url' => EE_CORE_CAF_ADMIN_EXTEND_URL |
|
44 | + . 'registration_form/assets/event-editor-question-groups.js', |
|
45 | + 'depends' => array('jquery'), |
|
46 | + ), |
|
47 | + ), |
|
48 | + 'enqueues' => array( |
|
49 | + 'extended-event-editor' => array('edit', 'create_new'), |
|
50 | + ), |
|
51 | + ); |
|
52 | + } |
|
53 | + |
|
54 | + |
|
55 | + /** |
|
56 | + * @param Callable[] $callbacks |
|
57 | + * @return array |
|
58 | + */ |
|
59 | + public function modify_callbacks($callbacks) |
|
60 | + { |
|
61 | + $callbacks = parent::modify_callbacks($callbacks); |
|
62 | + $callbacks[] = array($this, 'additional_question_group_update'); |
|
63 | + return $callbacks; |
|
64 | + } |
|
65 | + |
|
66 | + |
|
67 | + /** |
|
68 | + * Call back hooked into revision restores. |
|
69 | + * |
|
70 | + * @param $post_id |
|
71 | + * @param $revision_id |
|
72 | + * @return EE_Base_Class|void |
|
73 | + * @throws EE_Error |
|
74 | + * @throws InvalidArgumentException |
|
75 | + * @throws InvalidDataTypeException |
|
76 | + * @throws InvalidInterfaceException |
|
77 | + * @throws ReflectionException |
|
78 | + */ |
|
79 | + public function restore_revision($post_id, $revision_id) |
|
80 | + { |
|
81 | + $post_evt = parent::restore_revision($post_id, $revision_id); |
|
82 | + |
|
83 | + //restore revision for additional questions |
|
84 | + $post_evt->restore_revision( |
|
85 | + $revision_id, |
|
86 | + array('Question_Group'), |
|
87 | + array('Question_Group' => array('Event_Question_Group.EQG_primary' => 0) |
|
88 | + ) |
|
89 | + ); |
|
90 | + } |
|
91 | + |
|
92 | + |
|
93 | + /** |
|
94 | + * @param $post_id |
|
95 | + * @param $post |
|
96 | + * @throws EE_Error |
|
97 | + * @throws InvalidArgumentException |
|
98 | + * @throws InvalidDataTypeException |
|
99 | + * @throws InvalidInterfaceException |
|
100 | + */ |
|
101 | + public function additional_questions($post_id, $post) |
|
102 | + { |
|
103 | + $this->_event = $this->_adminpage_obj->get_event_object(); |
|
104 | + $event_id = $this->_event->ID(); |
|
105 | + ?> |
|
106 | 106 | <div class="inside"> |
107 | 107 | <p><strong> |
108 | 108 | <?php _e('Question Groups', 'event_espresso'); ?> |
109 | 109 | </strong><br/> |
110 | 110 | <?php |
111 | - printf( |
|
112 | - esc_html__( |
|
113 | - 'Add a pre-populated %1$sgroup of questions%2$s to your event.', |
|
114 | - 'event_espresso' |
|
115 | - ), |
|
116 | - '<a href="admin.php?page=espresso_registration_form" target="_blank">', |
|
117 | - '</a>' |
|
118 | - ); |
|
119 | - ?> |
|
111 | + printf( |
|
112 | + esc_html__( |
|
113 | + 'Add a pre-populated %1$sgroup of questions%2$s to your event.', |
|
114 | + 'event_espresso' |
|
115 | + ), |
|
116 | + '<a href="admin.php?page=espresso_registration_form" target="_blank">', |
|
117 | + '</a>' |
|
118 | + ); |
|
119 | + ?> |
|
120 | 120 | </p> |
121 | 121 | <?php |
122 | 122 | |
123 | - $qsg_where['QSG_deleted'] = false; |
|
124 | - $query_params = apply_filters( |
|
125 | - 'FHEE__espresso_events_Registration_Form_Hooks_Extend__additional_questions__question_group_query_parameters', |
|
126 | - array($qsg_where, 'order_by' => array('QSG_order' => 'ASC')) |
|
127 | - ); |
|
128 | - $QSGs = EEM_Question_Group::instance()->get_all($query_params); |
|
129 | - $EQGs = ! empty($event_id) |
|
130 | - ? $this->_event->get_many_related( |
|
131 | - 'Question_Group', |
|
132 | - array(array('Event_Question_Group.EQG_primary' => 0)) |
|
133 | - ) |
|
134 | - : array(); |
|
135 | - $EQGids = array_keys($EQGs); |
|
136 | - |
|
137 | - if (! empty($QSGs)) { |
|
138 | - $html = count($QSGs) > 10 ? '<div style="height:250px;overflow:auto;">' : ''; |
|
139 | - foreach ($QSGs as $QSG) { |
|
140 | - $checked = in_array($QSG->ID(), $EQGids, true) ? ' checked="checked" ' : ''; |
|
141 | - $edit_link = EE_Admin_Page::add_query_args_and_nonce( |
|
142 | - array( |
|
143 | - 'action' => 'edit_question_group', |
|
144 | - 'QSG_ID' => $QSG->ID(), |
|
145 | - ), |
|
146 | - EE_FORMS_ADMIN_URL |
|
147 | - ); |
|
148 | - |
|
149 | - $html .= ' |
|
123 | + $qsg_where['QSG_deleted'] = false; |
|
124 | + $query_params = apply_filters( |
|
125 | + 'FHEE__espresso_events_Registration_Form_Hooks_Extend__additional_questions__question_group_query_parameters', |
|
126 | + array($qsg_where, 'order_by' => array('QSG_order' => 'ASC')) |
|
127 | + ); |
|
128 | + $QSGs = EEM_Question_Group::instance()->get_all($query_params); |
|
129 | + $EQGs = ! empty($event_id) |
|
130 | + ? $this->_event->get_many_related( |
|
131 | + 'Question_Group', |
|
132 | + array(array('Event_Question_Group.EQG_primary' => 0)) |
|
133 | + ) |
|
134 | + : array(); |
|
135 | + $EQGids = array_keys($EQGs); |
|
136 | + |
|
137 | + if (! empty($QSGs)) { |
|
138 | + $html = count($QSGs) > 10 ? '<div style="height:250px;overflow:auto;">' : ''; |
|
139 | + foreach ($QSGs as $QSG) { |
|
140 | + $checked = in_array($QSG->ID(), $EQGids, true) ? ' checked="checked" ' : ''; |
|
141 | + $edit_link = EE_Admin_Page::add_query_args_and_nonce( |
|
142 | + array( |
|
143 | + 'action' => 'edit_question_group', |
|
144 | + 'QSG_ID' => $QSG->ID(), |
|
145 | + ), |
|
146 | + EE_FORMS_ADMIN_URL |
|
147 | + ); |
|
148 | + |
|
149 | + $html .= ' |
|
150 | 150 | <p id="event-question-group-' . $QSG->ID() . '"> |
151 | 151 | <input value="' . $QSG->ID() . '"' |
152 | - . ' type="checkbox" name="add_attendee_question_groups[' . $QSG->ID() . ']"' . $checked . ' /> |
|
152 | + . ' type="checkbox" name="add_attendee_question_groups[' . $QSG->ID() . ']"' . $checked . ' /> |
|
153 | 153 | <a href="' . $edit_link . '" title="' |
154 | - . sprintf( |
|
155 | - esc_attr__('Edit %s Group', 'event_espresso'), |
|
156 | - $QSG->get('QSG_name') |
|
157 | - ) |
|
158 | - . '" target="_blank">' . $QSG->get('QSG_name') . '</a> |
|
154 | + . sprintf( |
|
155 | + esc_attr__('Edit %s Group', 'event_espresso'), |
|
156 | + $QSG->get('QSG_name') |
|
157 | + ) |
|
158 | + . '" target="_blank">' . $QSG->get('QSG_name') . '</a> |
|
159 | 159 | </p>'; |
160 | - if ($QSG->ID() === 2) { |
|
161 | - $html .= ' |
|
160 | + if ($QSG->ID() === 2) { |
|
161 | + $html .= ' |
|
162 | 162 | <p id="question-group-requirements-notice-pg" class="important-notice small-text" style="display: none;">' |
163 | - . esc_html__( |
|
164 | - 'The Personal Information question group is required whenever the Address Information question group is activated.', |
|
165 | - 'event_espresso' |
|
166 | - ) |
|
167 | - . '</p>'; |
|
168 | - } |
|
169 | - } |
|
170 | - $html .= count($QSGs) > 10 ? '</div>' : ''; |
|
171 | - |
|
172 | - echo $html; |
|
173 | - |
|
174 | - } else { |
|
175 | - esc_html_e( |
|
176 | - 'There seems to be a problem with your questions. Please contact [email protected]', |
|
177 | - 'event_espresso' |
|
178 | - ); |
|
179 | - } |
|
180 | - do_action('AHEE__espresso_events_Registration_Form_Hooks__additional_questions__after_content'); |
|
181 | - ?> |
|
163 | + . esc_html__( |
|
164 | + 'The Personal Information question group is required whenever the Address Information question group is activated.', |
|
165 | + 'event_espresso' |
|
166 | + ) |
|
167 | + . '</p>'; |
|
168 | + } |
|
169 | + } |
|
170 | + $html .= count($QSGs) > 10 ? '</div>' : ''; |
|
171 | + |
|
172 | + echo $html; |
|
173 | + |
|
174 | + } else { |
|
175 | + esc_html_e( |
|
176 | + 'There seems to be a problem with your questions. Please contact [email protected]', |
|
177 | + 'event_espresso' |
|
178 | + ); |
|
179 | + } |
|
180 | + do_action('AHEE__espresso_events_Registration_Form_Hooks__additional_questions__after_content'); |
|
181 | + ?> |
|
182 | 182 | </div> |
183 | 183 | <?php |
184 | - } |
|
185 | - |
|
186 | - |
|
187 | - public function additional_question_group_update($evtobj, $data) |
|
188 | - { |
|
189 | - $question_groups = ! empty($data['add_attendee_question_groups']) |
|
190 | - ? (array) $data['add_attendee_question_groups'] |
|
191 | - : array(); |
|
192 | - $added_qgs = array_keys($question_groups); |
|
193 | - $success = array(); |
|
194 | - |
|
195 | - //let's get all current question groups associated with this event. |
|
196 | - $current_qgs = $evtobj->get_many_related( |
|
197 | - 'Question_Group', |
|
198 | - array(array('Event_Question_Group.EQG_primary' => 0)) |
|
199 | - ); |
|
200 | - $current_qgs = array_keys($current_qgs); //we just want the ids |
|
201 | - |
|
202 | - //now let's get the groups selected in the editor and update (IF we have data) |
|
203 | - if (! empty($question_groups)) { |
|
204 | - foreach ($question_groups as $id => $val) { |
|
205 | - //add to event |
|
206 | - if ($val) { |
|
207 | - $qg = $evtobj->_add_relation_to($id, 'Question_Group', array('EQG_primary' => 0)); |
|
208 | - } |
|
209 | - $success[] = ! empty($qg) ? 1 : 0; |
|
210 | - } |
|
211 | - } |
|
212 | - |
|
213 | - //wait a minute... are there question groups missing in the saved groups that ARE with the current event? |
|
214 | - $removed_qgs = array_diff($current_qgs, $added_qgs); |
|
215 | - |
|
216 | - foreach ($removed_qgs as $qgid) { |
|
217 | - $qg = $evtobj->_remove_relation_to($qgid, 'Question_Group', array('EQG_primary' => 0)); |
|
218 | - $success[] = ! empty($qg) ? 1 : 0; |
|
219 | - } |
|
220 | - |
|
221 | - |
|
222 | - return in_array(0, $success, true) ? false : true; |
|
223 | - } |
|
184 | + } |
|
185 | + |
|
186 | + |
|
187 | + public function additional_question_group_update($evtobj, $data) |
|
188 | + { |
|
189 | + $question_groups = ! empty($data['add_attendee_question_groups']) |
|
190 | + ? (array) $data['add_attendee_question_groups'] |
|
191 | + : array(); |
|
192 | + $added_qgs = array_keys($question_groups); |
|
193 | + $success = array(); |
|
194 | + |
|
195 | + //let's get all current question groups associated with this event. |
|
196 | + $current_qgs = $evtobj->get_many_related( |
|
197 | + 'Question_Group', |
|
198 | + array(array('Event_Question_Group.EQG_primary' => 0)) |
|
199 | + ); |
|
200 | + $current_qgs = array_keys($current_qgs); //we just want the ids |
|
201 | + |
|
202 | + //now let's get the groups selected in the editor and update (IF we have data) |
|
203 | + if (! empty($question_groups)) { |
|
204 | + foreach ($question_groups as $id => $val) { |
|
205 | + //add to event |
|
206 | + if ($val) { |
|
207 | + $qg = $evtobj->_add_relation_to($id, 'Question_Group', array('EQG_primary' => 0)); |
|
208 | + } |
|
209 | + $success[] = ! empty($qg) ? 1 : 0; |
|
210 | + } |
|
211 | + } |
|
212 | + |
|
213 | + //wait a minute... are there question groups missing in the saved groups that ARE with the current event? |
|
214 | + $removed_qgs = array_diff($current_qgs, $added_qgs); |
|
215 | + |
|
216 | + foreach ($removed_qgs as $qgid) { |
|
217 | + $qg = $evtobj->_remove_relation_to($qgid, 'Question_Group', array('EQG_primary' => 0)); |
|
218 | + $success[] = ! empty($qg) ? 1 : 0; |
|
219 | + } |
|
220 | + |
|
221 | + |
|
222 | + return in_array(0, $success, true) ? false : true; |
|
223 | + } |
|
224 | 224 | } |
@@ -25,7 +25,7 @@ discard block |
||
25 | 25 | */ |
26 | 26 | protected function _extend_properties() |
27 | 27 | { |
28 | - $this->_metaboxes = array_merge( |
|
28 | + $this->_metaboxes = array_merge( |
|
29 | 29 | $this->_metaboxes, |
30 | 30 | array( |
31 | 31 | 1 => array( |
@@ -132,9 +132,9 @@ discard block |
||
132 | 132 | array(array('Event_Question_Group.EQG_primary' => 0)) |
133 | 133 | ) |
134 | 134 | : array(); |
135 | - $EQGids = array_keys($EQGs); |
|
135 | + $EQGids = array_keys($EQGs); |
|
136 | 136 | |
137 | - if (! empty($QSGs)) { |
|
137 | + if ( ! empty($QSGs)) { |
|
138 | 138 | $html = count($QSGs) > 10 ? '<div style="height:250px;overflow:auto;">' : ''; |
139 | 139 | foreach ($QSGs as $QSG) { |
140 | 140 | $checked = in_array($QSG->ID(), $EQGids, true) ? ' checked="checked" ' : ''; |
@@ -147,15 +147,15 @@ discard block |
||
147 | 147 | ); |
148 | 148 | |
149 | 149 | $html .= ' |
150 | - <p id="event-question-group-' . $QSG->ID() . '"> |
|
151 | - <input value="' . $QSG->ID() . '"' |
|
152 | - . ' type="checkbox" name="add_attendee_question_groups[' . $QSG->ID() . ']"' . $checked . ' /> |
|
153 | - <a href="' . $edit_link . '" title="' |
|
150 | + <p id="event-question-group-' . $QSG->ID().'"> |
|
151 | + <input value="' . $QSG->ID().'"' |
|
152 | + . ' type="checkbox" name="add_attendee_question_groups['.$QSG->ID().']"'.$checked.' /> |
|
153 | + <a href="' . $edit_link.'" title="' |
|
154 | 154 | . sprintf( |
155 | 155 | esc_attr__('Edit %s Group', 'event_espresso'), |
156 | 156 | $QSG->get('QSG_name') |
157 | 157 | ) |
158 | - . '" target="_blank">' . $QSG->get('QSG_name') . '</a> |
|
158 | + . '" target="_blank">'.$QSG->get('QSG_name').'</a> |
|
159 | 159 | </p>'; |
160 | 160 | if ($QSG->ID() === 2) { |
161 | 161 | $html .= ' |
@@ -200,7 +200,7 @@ discard block |
||
200 | 200 | $current_qgs = array_keys($current_qgs); //we just want the ids |
201 | 201 | |
202 | 202 | //now let's get the groups selected in the editor and update (IF we have data) |
203 | - if (! empty($question_groups)) { |
|
203 | + if ( ! empty($question_groups)) { |
|
204 | 204 | foreach ($question_groups as $id => $val) { |
205 | 205 | //add to event |
206 | 206 | if ($val) { |
@@ -1,7 +1,7 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | 3 | if (! defined('EVENT_ESPRESSO_VERSION')) { |
4 | - exit('NO direct script access allowed'); |
|
4 | + exit('NO direct script access allowed'); |
|
5 | 5 | } |
6 | 6 | |
7 | 7 | /** |
@@ -27,511 +27,511 @@ discard block |
||
27 | 27 | { |
28 | 28 | |
29 | 29 | |
30 | - /** |
|
31 | - * user id for logged in user when data collected |
|
32 | - * |
|
33 | - * @var string $user_id |
|
34 | - */ |
|
35 | - public $user_id; |
|
36 | - |
|
37 | - /** |
|
38 | - * IP Address of browser used |
|
39 | - * |
|
40 | - * @var string $ip_address |
|
41 | - */ |
|
42 | - public $ip_address; |
|
43 | - |
|
44 | - /** |
|
45 | - * browser |
|
46 | - * |
|
47 | - * @var string $user_agent |
|
48 | - */ |
|
49 | - public $user_agent; |
|
50 | - |
|
51 | - /** |
|
52 | - * Unix timestamp |
|
53 | - * |
|
54 | - * @var string $init_access |
|
55 | - */ |
|
56 | - public $init_access; |
|
57 | - |
|
58 | - /** |
|
59 | - * Unix timestamp |
|
60 | - * |
|
61 | - * @var string $last_access |
|
62 | - */ |
|
63 | - public $last_access; |
|
64 | - |
|
65 | - /** |
|
66 | - * The registrations details from the cart |
|
67 | - * |
|
68 | - * @var array $reg_info |
|
69 | - */ |
|
70 | - public $reg_info; |
|
71 | - |
|
72 | - /** |
|
73 | - * Some data handlers can set what reg status all the registrations are filtered by. |
|
74 | - * The status should match a EEM_Registration status constant. |
|
75 | - * |
|
76 | - * @var string $filtered_reg_status |
|
77 | - */ |
|
78 | - public $filtered_reg_status; |
|
79 | - |
|
80 | - /** |
|
81 | - * will hold an array of events assembled from $reg_info |
|
82 | - * |
|
83 | - * @var EE_Event[] $events |
|
84 | - */ |
|
85 | - public $events; |
|
86 | - |
|
87 | - /** |
|
88 | - * holds an array of datetimes assembled from the incoming data. |
|
89 | - * |
|
90 | - * @var EE_Datetime[] $datetimes |
|
91 | - */ |
|
92 | - public $datetimes; |
|
93 | - |
|
94 | - /** |
|
95 | - * holds an array of tickets assembled from the incoming data. |
|
96 | - * |
|
97 | - * @var EE_Ticket[] $tickets |
|
98 | - */ |
|
99 | - public $tickets; |
|
100 | - |
|
101 | - /** |
|
102 | - * holds an array with a key of parent line item and values are an array of children of that line item. |
|
103 | - * |
|
104 | - * @since 4.5.0 |
|
105 | - * @var EE_Line_Item[] $line_items_with_children |
|
106 | - */ |
|
107 | - public $line_items_with_children; |
|
108 | - |
|
109 | - /** |
|
110 | - * will hold an array of attendees assembled from the $reg_info |
|
111 | - * |
|
112 | - * @var EE_Attendee[] $attendees |
|
113 | - */ |
|
114 | - public $attendees; |
|
115 | - |
|
116 | - /** |
|
117 | - * will hold an array of cached registration objects and info assembled from reg_info |
|
118 | - * |
|
119 | - * @var array $registrations |
|
120 | - */ |
|
121 | - public $registrations; |
|
122 | - |
|
123 | - /** |
|
124 | - * will hold an array of answers assembled from the $reg_info |
|
125 | - * |
|
126 | - * @var EE_Answer[] $answers |
|
127 | - */ |
|
128 | - public $answers; |
|
129 | - |
|
130 | - /** |
|
131 | - * will hold an array of questions assembled from the $reg_info (indexed by Answer ID); |
|
132 | - * |
|
133 | - * @var EE_Question[] $questions |
|
134 | - */ |
|
135 | - public $questions; |
|
136 | - |
|
137 | - /** |
|
138 | - * Will hold billing data assembled from $billing_info (if present) |
|
139 | - * |
|
140 | - * @var mixed (array|null) $billing |
|
141 | - */ |
|
142 | - public $billing; |
|
143 | - |
|
144 | - /** |
|
145 | - * The total amount of tax for the transaction |
|
146 | - * |
|
147 | - * @var float $taxes |
|
148 | - */ |
|
149 | - public $taxes; |
|
150 | - |
|
151 | - /** |
|
152 | - * Holds the line items related to taxes |
|
153 | - * |
|
154 | - * @since 4.5.0 |
|
155 | - * @var EE_Line_Item[] $tax_line_items |
|
156 | - */ |
|
157 | - public $tax_line_items; |
|
158 | - |
|
159 | - /** |
|
160 | - * Hold the line items which aren't taxes and don't relate |
|
161 | - * to tickets. So: promotions and miscellaneous charges |
|
162 | - * |
|
163 | - * @since 4.5 |
|
164 | - * @var EE_Line_Item[] $additional_line_items |
|
165 | - */ |
|
166 | - public $additional_line_items; |
|
167 | - |
|
168 | - /** |
|
169 | - * Holds the grand total EE_Line_Item |
|
170 | - * |
|
171 | - * @var EE_Line_Item $grand_total_line_item |
|
172 | - */ |
|
173 | - public $grand_total_line_item; |
|
174 | - |
|
175 | - /** |
|
176 | - * holds the grand total price object |
|
177 | - * |
|
178 | - * @var object $grand_total_price_object |
|
179 | - */ |
|
180 | - public $grand_total_price_object; |
|
181 | - |
|
182 | - /** |
|
183 | - * total number of tickets |
|
184 | - * |
|
185 | - * @var int $total_ticket_count |
|
186 | - */ |
|
187 | - public $total_ticket_count; |
|
188 | - |
|
189 | - /** |
|
190 | - * Will hold the final transaction object (EE_Transaction) |
|
191 | - * |
|
192 | - * @var EE_Transaction $txn |
|
193 | - */ |
|
194 | - public $txn; |
|
195 | - |
|
196 | - /** |
|
197 | - * Holds the payments related to a transaction |
|
198 | - * |
|
199 | - * @since 4.5.0 |
|
200 | - * @var EE_Payment[] $payments |
|
201 | - */ |
|
202 | - public $payments; |
|
203 | - |
|
204 | - /** |
|
205 | - * Holds the first related payment related for a transaction |
|
206 | - * |
|
207 | - * @since 4.5.0 |
|
208 | - * @var EE_Payment $payment |
|
209 | - */ |
|
210 | - public $payment; |
|
211 | - |
|
212 | - /** |
|
213 | - * Will hold the label for the txn status |
|
214 | - * |
|
215 | - * @var string $txn_status |
|
216 | - */ |
|
217 | - public $txn_status; |
|
218 | - |
|
219 | - /** |
|
220 | - * Will hold the final registration object (EE_Registration) |
|
221 | - * |
|
222 | - * @var EE_Registration[] $reg_objs |
|
223 | - */ |
|
224 | - public $reg_objs; |
|
225 | - |
|
226 | - /** |
|
227 | - * Will hold an array of primary attendee data (if present) |
|
228 | - * |
|
229 | - * @var array $primary_attendee_data |
|
230 | - */ |
|
231 | - public $primary_attendee_data; |
|
232 | - |
|
233 | - /** |
|
234 | - * This is just an internal object used for passing around the incoming data. |
|
235 | - * |
|
236 | - * @var object $_data |
|
237 | - */ |
|
238 | - protected $_data; |
|
239 | - |
|
240 | - /** |
|
241 | - * This is just an internal object used for passing around the incoming data. |
|
242 | - * |
|
243 | - * @var object $incoming_data |
|
244 | - */ |
|
245 | - public $incoming_data; |
|
246 | - |
|
247 | - /** |
|
248 | - * hold objects that might be created |
|
249 | - * |
|
250 | - * @type EE_Registration $reg_obj |
|
251 | - */ |
|
252 | - public $reg_obj; |
|
253 | - |
|
254 | - |
|
255 | - /** |
|
256 | - * constructor |
|
257 | - * |
|
258 | - * @param mixed $data incoming data object|array. Suggested that child classes use type hinting for expected |
|
259 | - * data object. But here parent will be generic because we don't know what's coming in. |
|
260 | - */ |
|
261 | - public function __construct($data) |
|
262 | - { |
|
263 | - $this->_data = $data; |
|
264 | - $this->_setup_data(); |
|
265 | - } |
|
266 | - |
|
267 | - |
|
268 | - /** |
|
269 | - * Every child class has to setup the data object ! |
|
270 | - * |
|
271 | - * @return void |
|
272 | - */ |
|
273 | - abstract protected function _setup_data(); |
|
274 | - |
|
275 | - |
|
276 | - /** |
|
277 | - * Returns database safe representation of the data later used to when instantiating this object. |
|
278 | - * |
|
279 | - * @param mixed $data The incoming data to be prepped. |
|
280 | - * @return mixed The prepped data for db |
|
281 | - */ |
|
282 | - static public function convert_data_for_persistent_storage($data) |
|
283 | - { |
|
284 | - return $data; |
|
285 | - } |
|
286 | - |
|
287 | - |
|
288 | - /** |
|
289 | - * Data that has been stored in persistent storage that was prepped by _convert_data_for_persistent_storage |
|
290 | - * can be sent into this method and converted back into the format used for instantiating with this data handler. |
|
291 | - * |
|
292 | - * @param $data |
|
293 | - * @return mixed |
|
294 | - */ |
|
295 | - static public function convert_data_from_persistent_storage($data) |
|
296 | - { |
|
297 | - return $data; |
|
298 | - } |
|
299 | - |
|
300 | - |
|
301 | - /** |
|
302 | - * only purpose is to return the data |
|
303 | - * |
|
304 | - * @access public |
|
305 | - * @return object the formatted data object! |
|
306 | - */ |
|
307 | - public function data() |
|
308 | - { |
|
309 | - return $this->_data; |
|
310 | - } |
|
311 | - |
|
312 | - |
|
313 | - /** |
|
314 | - * This helper method can be used by any incoming data handlers to setup the data correctly. All that is required |
|
315 | - * is that $this->reg_objs be set. |
|
316 | - * |
|
317 | - * @throws \EE_Error |
|
318 | - */ |
|
319 | - protected function _assemble_data() |
|
320 | - { |
|
321 | - //verify that reg_objs is set |
|
322 | - if ( |
|
323 | - ! is_array($this->reg_objs) |
|
324 | - && ! reset($this->reg_objs) instanceof EE_Registration |
|
325 | - ) { |
|
326 | - throw new EE_Error( |
|
327 | - __( |
|
328 | - 'In order to assemble the data correctly, the "reg_objs" property must be an array of EE_Registration objects', |
|
329 | - 'event_espresso' |
|
330 | - ) |
|
331 | - ); |
|
332 | - } |
|
333 | - |
|
334 | - //get all attendee and events associated with the registrations in this transaction |
|
335 | - $events = $event_setup = $evtcache = $tickets = $datetimes = array(); |
|
336 | - $answers = $questions = $attendees = $line_items = $registrations = array(); |
|
337 | - $total_ticket_count = 0; |
|
338 | - |
|
339 | - if (! empty($this->reg_objs)) { |
|
340 | - $event_attendee_count = array(); |
|
341 | - foreach ($this->reg_objs as $reg) { |
|
342 | - |
|
343 | - if ( |
|
344 | - $this->_skip_registration_for_processing($reg) |
|
345 | - ) { |
|
346 | - continue; |
|
347 | - } |
|
348 | - |
|
349 | - $evt_id = $reg->event_ID(); |
|
350 | - /** @type EE_Ticket $ticket */ |
|
351 | - $ticket = $reg->get_first_related('Ticket'); |
|
352 | - $relateddatetime = $ticket->datetimes(); |
|
353 | - $total_ticket_count++; |
|
354 | - $tickets[$ticket->ID()]['ticket'] = $ticket; |
|
355 | - $tickets[$ticket->ID()]['count'] = is_array($tickets[$ticket->ID()]) |
|
356 | - && isset($tickets[$ticket->ID()]['count']) |
|
357 | - ? $tickets[$ticket->ID()]['count'] + 1 |
|
358 | - : 1; |
|
359 | - $tickets[$ticket->ID()]['att_objs'][$reg->attendee_ID()] = $reg->attendee(); |
|
360 | - $tickets[$ticket->ID()]['dtt_objs'] = $relateddatetime; |
|
361 | - $tickets[$ticket->ID()]['reg_objs'][$reg->ID()] = $reg; |
|
362 | - $event = $reg->event(); |
|
363 | - $tickets[$ticket->ID()]['EE_Event'] = $event; |
|
364 | - $evtcache[$evt_id] = $event; |
|
365 | - $eventsetup[$evt_id]['reg_objs'][$reg->ID()] = $reg; |
|
366 | - $eventsetup[$evt_id]['tkt_objs'][$ticket->ID()] = $ticket; |
|
367 | - $eventsetup[$evt_id]['att_objs'][$reg->attendee_ID()] = $reg->attendee(); |
|
368 | - $event_attendee_count[$evt_id] = isset($event_attendee_count[$evt_id]) |
|
369 | - ? $event_attendee_count[$evt_id] + 1 |
|
370 | - : 0; |
|
371 | - $attendees[$reg->attendee_ID()]['line_ref'][] = $evt_id; |
|
372 | - $attendees[$reg->attendee_ID()]['att_obj'] = $reg->attendee(); |
|
373 | - $attendees[$reg->attendee_ID()]['reg_objs'][$reg->ID()] = $reg; |
|
374 | - //$attendees[ $reg->attendee_ID() ]['registration_id'] = $reg->ID(); |
|
375 | - $attendees[$reg->attendee_ID()]['attendee_email'] = $reg->attendee() instanceof EE_Attendee |
|
376 | - ? $reg->attendee()->email() |
|
377 | - : ''; |
|
378 | - $attendees[$reg->attendee_ID()]['tkt_objs'][$ticket->ID()] = $ticket; |
|
379 | - $attendees[$reg->attendee_ID()]['evt_objs'][$evt_id] = $event; |
|
380 | - |
|
381 | - //registrations |
|
382 | - $registrations[$reg->ID()]['tkt_obj'] = $ticket; |
|
383 | - $registrations[$reg->ID()]['evt_obj'] = $event; |
|
384 | - $registrations[$reg->ID()]['reg_obj'] = $reg; |
|
385 | - $registrations[$reg->ID()]['att_obj'] = $reg->attendee(); |
|
386 | - |
|
387 | - //set up answer objects |
|
388 | - $rel_ans = $reg->get_many_related('Answer'); |
|
389 | - foreach ($rel_ans as $ansid => $answer) { |
|
390 | - if (! isset($questions[$ansid])) { |
|
391 | - $questions[$ansid] = $answer->get_first_related('Question'); |
|
392 | - } |
|
393 | - $answers[$ansid] = $answer; |
|
394 | - $registrations[$reg->ID()]['ans_objs'][$ansid] = $answer; |
|
395 | - } |
|
396 | - |
|
397 | - foreach ($relateddatetime as $dtt_id => $datetime) { |
|
398 | - $eventsetup[$evt_id]['dtt_objs'][$dtt_id] = $datetime; |
|
399 | - $registrations[$reg->ID()]['dtt_objs'][$dtt_id] = $datetime; |
|
400 | - |
|
401 | - if (isset($datetimes[$dtt_id])) { |
|
402 | - continue; //already have this info in the datetimes array. |
|
403 | - } |
|
404 | - |
|
405 | - $datetimes[$dtt_id]['tkt_objs'][] = $ticket; |
|
406 | - $datetimes[$dtt_id]['datetime'] = $datetime; |
|
407 | - $datetimes[$dtt_id]['evt_objs'][$evt_id] = $event; |
|
408 | - $datetimes[$dtt_id]['reg_objs'][$reg->ID()] = $reg; |
|
409 | - } |
|
410 | - } |
|
411 | - |
|
412 | - //let's loop through the unique event=>reg items and setup data on them |
|
413 | - |
|
414 | - if (! empty($eventsetup)) { |
|
415 | - foreach ($eventsetup as $evt_id => $items) { |
|
416 | - if ($this->txn instanceof EE_Transaction) { |
|
417 | - $ticket_line_items_for_event = EEM_Line_Item::instance()->get_all( |
|
418 | - array( |
|
419 | - array( |
|
420 | - 'Ticket.Datetime.EVT_ID' => $evt_id, |
|
421 | - 'TXN_ID' => $this->txn->ID(), |
|
422 | - ), |
|
423 | - 'default_where_conditions' => 'none', |
|
424 | - ) |
|
425 | - ); |
|
426 | - } else { |
|
427 | - $ticket_line_items_for_event = array(); |
|
428 | - } |
|
429 | - $events[$evt_id] = array( |
|
430 | - 'ID' => $evt_id, |
|
431 | - 'event' => $evtcache[$evt_id], |
|
432 | - 'name' => $evtcache[$evt_id] instanceof EE_Event ? $evtcache[$evt_id]->name() : '', |
|
433 | - 'total_attendees' => $event_attendee_count[$evt_id], |
|
434 | - 'reg_objs' => $items['reg_objs'], |
|
435 | - 'tkt_objs' => $items['tkt_objs'], |
|
436 | - 'att_objs' => $items['att_objs'], |
|
437 | - 'dtt_objs' => isset($items['dtt_objs']) ? $items['dtt_objs'] : array(), |
|
438 | - 'line_items' => $ticket_line_items_for_event, |
|
439 | - ); |
|
440 | - |
|
441 | - //make sure the tickets have the line items setup for them. |
|
442 | - foreach ($ticket_line_items_for_event as $line_id => $line_item) { |
|
443 | - if ($line_item instanceof EE_Line_Item) { |
|
444 | - $tickets[$line_item->ticket()->ID()]['line_item'] = $line_item; |
|
445 | - $tickets[$line_item->ticket()->ID()]['sub_line_items'] = $line_item->children(); |
|
446 | - $line_items[$line_item->ID()]['children'] = $line_item->children(); |
|
447 | - $line_items[$line_item->ID()]['EE_Ticket'] = $line_item->ticket(); |
|
448 | - } |
|
449 | - } |
|
450 | - } |
|
451 | - } |
|
452 | - |
|
453 | - $this->grand_total_line_item = $this->txn instanceof EE_Transaction |
|
454 | - ? $this->txn->total_line_item() |
|
455 | - : null; |
|
456 | - } |
|
457 | - |
|
458 | - //lets set the attendees and events properties |
|
459 | - $this->attendees = $attendees; |
|
460 | - $this->events = $events; |
|
461 | - $this->tickets = $tickets; |
|
462 | - $this->line_items_with_children = $line_items; |
|
463 | - $this->datetimes = $datetimes; |
|
464 | - $this->questions = $questions; |
|
465 | - $this->answers = $answers; |
|
466 | - $this->total_ticket_count = $total_ticket_count; |
|
467 | - $this->registrations = $registrations; |
|
468 | - |
|
469 | - if ($this->txn instanceof EE_Transaction) { |
|
470 | - $this->tax_line_items = $this->txn->tax_items(); |
|
471 | - $this->additional_line_items = $this->txn->non_ticket_line_items(); |
|
472 | - $this->payments = $this->txn->payments(); |
|
473 | - |
|
474 | - //setup primary registration if we have a single transaction object to work with |
|
475 | - |
|
476 | - //let's get just the primary_attendee_data! First we get the primary registration object. |
|
477 | - $primary_reg = $this->txn->primary_registration(); |
|
478 | - // verify |
|
479 | - if ($primary_reg instanceof EE_Registration) { |
|
480 | - |
|
481 | - // get attendee object |
|
482 | - if ($primary_reg->attendee() instanceof EE_Attendee) { |
|
483 | - |
|
484 | - //now we can setup the primary_attendee_data array |
|
485 | - $this->primary_attendee_data = array( |
|
486 | - 'registration_id' => $primary_reg->ID(), |
|
487 | - 'att_obj' => $primary_reg->attendee(), |
|
488 | - 'reg_obj' => $primary_reg, |
|
489 | - 'primary_att_obj' => $primary_reg->attendee(), |
|
490 | - 'primary_reg_obj' => $primary_reg, |
|
491 | - ); |
|
492 | - |
|
493 | - } else { |
|
494 | - EE_Error::add_error( |
|
495 | - __( |
|
496 | - 'Incoming data does not have a valid Attendee object for the primary registrant.', |
|
497 | - 'event_espresso' |
|
498 | - ), |
|
499 | - __FILE__, |
|
500 | - __FUNCTION__, |
|
501 | - __LINE__ |
|
502 | - ); |
|
503 | - } |
|
504 | - } else { |
|
505 | - EE_Error::add_error( |
|
506 | - __( |
|
507 | - 'Incoming data does not have a valid Registration object for the primary registrant.', |
|
508 | - 'event_espresso' |
|
509 | - ), |
|
510 | - __FILE__, |
|
511 | - __FUNCTION__, |
|
512 | - __LINE__ |
|
513 | - ); |
|
514 | - } |
|
515 | - } |
|
516 | - } |
|
517 | - |
|
518 | - /** |
|
519 | - * This simply considers whether the given registration should be processed or not based on comparison with the |
|
520 | - * filtered_reg_status property. |
|
521 | - * |
|
522 | - * @param EE_Registration $registration |
|
523 | - * @return bool returning true means we DO want to skip processing. returning false means we DON'T want to skip |
|
524 | - * processing |
|
525 | - */ |
|
526 | - protected function _skip_registration_for_processing(EE_Registration $registration) |
|
527 | - { |
|
528 | - if (empty($this->filtered_reg_status)) { |
|
529 | - return false; |
|
530 | - } |
|
531 | - |
|
532 | - //if we made it here then we just compare the filtered_reg_status with the registration status and return that |
|
533 | - return $this->filtered_reg_status !== $registration->status_ID(); |
|
534 | - } |
|
30 | + /** |
|
31 | + * user id for logged in user when data collected |
|
32 | + * |
|
33 | + * @var string $user_id |
|
34 | + */ |
|
35 | + public $user_id; |
|
36 | + |
|
37 | + /** |
|
38 | + * IP Address of browser used |
|
39 | + * |
|
40 | + * @var string $ip_address |
|
41 | + */ |
|
42 | + public $ip_address; |
|
43 | + |
|
44 | + /** |
|
45 | + * browser |
|
46 | + * |
|
47 | + * @var string $user_agent |
|
48 | + */ |
|
49 | + public $user_agent; |
|
50 | + |
|
51 | + /** |
|
52 | + * Unix timestamp |
|
53 | + * |
|
54 | + * @var string $init_access |
|
55 | + */ |
|
56 | + public $init_access; |
|
57 | + |
|
58 | + /** |
|
59 | + * Unix timestamp |
|
60 | + * |
|
61 | + * @var string $last_access |
|
62 | + */ |
|
63 | + public $last_access; |
|
64 | + |
|
65 | + /** |
|
66 | + * The registrations details from the cart |
|
67 | + * |
|
68 | + * @var array $reg_info |
|
69 | + */ |
|
70 | + public $reg_info; |
|
71 | + |
|
72 | + /** |
|
73 | + * Some data handlers can set what reg status all the registrations are filtered by. |
|
74 | + * The status should match a EEM_Registration status constant. |
|
75 | + * |
|
76 | + * @var string $filtered_reg_status |
|
77 | + */ |
|
78 | + public $filtered_reg_status; |
|
79 | + |
|
80 | + /** |
|
81 | + * will hold an array of events assembled from $reg_info |
|
82 | + * |
|
83 | + * @var EE_Event[] $events |
|
84 | + */ |
|
85 | + public $events; |
|
86 | + |
|
87 | + /** |
|
88 | + * holds an array of datetimes assembled from the incoming data. |
|
89 | + * |
|
90 | + * @var EE_Datetime[] $datetimes |
|
91 | + */ |
|
92 | + public $datetimes; |
|
93 | + |
|
94 | + /** |
|
95 | + * holds an array of tickets assembled from the incoming data. |
|
96 | + * |
|
97 | + * @var EE_Ticket[] $tickets |
|
98 | + */ |
|
99 | + public $tickets; |
|
100 | + |
|
101 | + /** |
|
102 | + * holds an array with a key of parent line item and values are an array of children of that line item. |
|
103 | + * |
|
104 | + * @since 4.5.0 |
|
105 | + * @var EE_Line_Item[] $line_items_with_children |
|
106 | + */ |
|
107 | + public $line_items_with_children; |
|
108 | + |
|
109 | + /** |
|
110 | + * will hold an array of attendees assembled from the $reg_info |
|
111 | + * |
|
112 | + * @var EE_Attendee[] $attendees |
|
113 | + */ |
|
114 | + public $attendees; |
|
115 | + |
|
116 | + /** |
|
117 | + * will hold an array of cached registration objects and info assembled from reg_info |
|
118 | + * |
|
119 | + * @var array $registrations |
|
120 | + */ |
|
121 | + public $registrations; |
|
122 | + |
|
123 | + /** |
|
124 | + * will hold an array of answers assembled from the $reg_info |
|
125 | + * |
|
126 | + * @var EE_Answer[] $answers |
|
127 | + */ |
|
128 | + public $answers; |
|
129 | + |
|
130 | + /** |
|
131 | + * will hold an array of questions assembled from the $reg_info (indexed by Answer ID); |
|
132 | + * |
|
133 | + * @var EE_Question[] $questions |
|
134 | + */ |
|
135 | + public $questions; |
|
136 | + |
|
137 | + /** |
|
138 | + * Will hold billing data assembled from $billing_info (if present) |
|
139 | + * |
|
140 | + * @var mixed (array|null) $billing |
|
141 | + */ |
|
142 | + public $billing; |
|
143 | + |
|
144 | + /** |
|
145 | + * The total amount of tax for the transaction |
|
146 | + * |
|
147 | + * @var float $taxes |
|
148 | + */ |
|
149 | + public $taxes; |
|
150 | + |
|
151 | + /** |
|
152 | + * Holds the line items related to taxes |
|
153 | + * |
|
154 | + * @since 4.5.0 |
|
155 | + * @var EE_Line_Item[] $tax_line_items |
|
156 | + */ |
|
157 | + public $tax_line_items; |
|
158 | + |
|
159 | + /** |
|
160 | + * Hold the line items which aren't taxes and don't relate |
|
161 | + * to tickets. So: promotions and miscellaneous charges |
|
162 | + * |
|
163 | + * @since 4.5 |
|
164 | + * @var EE_Line_Item[] $additional_line_items |
|
165 | + */ |
|
166 | + public $additional_line_items; |
|
167 | + |
|
168 | + /** |
|
169 | + * Holds the grand total EE_Line_Item |
|
170 | + * |
|
171 | + * @var EE_Line_Item $grand_total_line_item |
|
172 | + */ |
|
173 | + public $grand_total_line_item; |
|
174 | + |
|
175 | + /** |
|
176 | + * holds the grand total price object |
|
177 | + * |
|
178 | + * @var object $grand_total_price_object |
|
179 | + */ |
|
180 | + public $grand_total_price_object; |
|
181 | + |
|
182 | + /** |
|
183 | + * total number of tickets |
|
184 | + * |
|
185 | + * @var int $total_ticket_count |
|
186 | + */ |
|
187 | + public $total_ticket_count; |
|
188 | + |
|
189 | + /** |
|
190 | + * Will hold the final transaction object (EE_Transaction) |
|
191 | + * |
|
192 | + * @var EE_Transaction $txn |
|
193 | + */ |
|
194 | + public $txn; |
|
195 | + |
|
196 | + /** |
|
197 | + * Holds the payments related to a transaction |
|
198 | + * |
|
199 | + * @since 4.5.0 |
|
200 | + * @var EE_Payment[] $payments |
|
201 | + */ |
|
202 | + public $payments; |
|
203 | + |
|
204 | + /** |
|
205 | + * Holds the first related payment related for a transaction |
|
206 | + * |
|
207 | + * @since 4.5.0 |
|
208 | + * @var EE_Payment $payment |
|
209 | + */ |
|
210 | + public $payment; |
|
211 | + |
|
212 | + /** |
|
213 | + * Will hold the label for the txn status |
|
214 | + * |
|
215 | + * @var string $txn_status |
|
216 | + */ |
|
217 | + public $txn_status; |
|
218 | + |
|
219 | + /** |
|
220 | + * Will hold the final registration object (EE_Registration) |
|
221 | + * |
|
222 | + * @var EE_Registration[] $reg_objs |
|
223 | + */ |
|
224 | + public $reg_objs; |
|
225 | + |
|
226 | + /** |
|
227 | + * Will hold an array of primary attendee data (if present) |
|
228 | + * |
|
229 | + * @var array $primary_attendee_data |
|
230 | + */ |
|
231 | + public $primary_attendee_data; |
|
232 | + |
|
233 | + /** |
|
234 | + * This is just an internal object used for passing around the incoming data. |
|
235 | + * |
|
236 | + * @var object $_data |
|
237 | + */ |
|
238 | + protected $_data; |
|
239 | + |
|
240 | + /** |
|
241 | + * This is just an internal object used for passing around the incoming data. |
|
242 | + * |
|
243 | + * @var object $incoming_data |
|
244 | + */ |
|
245 | + public $incoming_data; |
|
246 | + |
|
247 | + /** |
|
248 | + * hold objects that might be created |
|
249 | + * |
|
250 | + * @type EE_Registration $reg_obj |
|
251 | + */ |
|
252 | + public $reg_obj; |
|
253 | + |
|
254 | + |
|
255 | + /** |
|
256 | + * constructor |
|
257 | + * |
|
258 | + * @param mixed $data incoming data object|array. Suggested that child classes use type hinting for expected |
|
259 | + * data object. But here parent will be generic because we don't know what's coming in. |
|
260 | + */ |
|
261 | + public function __construct($data) |
|
262 | + { |
|
263 | + $this->_data = $data; |
|
264 | + $this->_setup_data(); |
|
265 | + } |
|
266 | + |
|
267 | + |
|
268 | + /** |
|
269 | + * Every child class has to setup the data object ! |
|
270 | + * |
|
271 | + * @return void |
|
272 | + */ |
|
273 | + abstract protected function _setup_data(); |
|
274 | + |
|
275 | + |
|
276 | + /** |
|
277 | + * Returns database safe representation of the data later used to when instantiating this object. |
|
278 | + * |
|
279 | + * @param mixed $data The incoming data to be prepped. |
|
280 | + * @return mixed The prepped data for db |
|
281 | + */ |
|
282 | + static public function convert_data_for_persistent_storage($data) |
|
283 | + { |
|
284 | + return $data; |
|
285 | + } |
|
286 | + |
|
287 | + |
|
288 | + /** |
|
289 | + * Data that has been stored in persistent storage that was prepped by _convert_data_for_persistent_storage |
|
290 | + * can be sent into this method and converted back into the format used for instantiating with this data handler. |
|
291 | + * |
|
292 | + * @param $data |
|
293 | + * @return mixed |
|
294 | + */ |
|
295 | + static public function convert_data_from_persistent_storage($data) |
|
296 | + { |
|
297 | + return $data; |
|
298 | + } |
|
299 | + |
|
300 | + |
|
301 | + /** |
|
302 | + * only purpose is to return the data |
|
303 | + * |
|
304 | + * @access public |
|
305 | + * @return object the formatted data object! |
|
306 | + */ |
|
307 | + public function data() |
|
308 | + { |
|
309 | + return $this->_data; |
|
310 | + } |
|
311 | + |
|
312 | + |
|
313 | + /** |
|
314 | + * This helper method can be used by any incoming data handlers to setup the data correctly. All that is required |
|
315 | + * is that $this->reg_objs be set. |
|
316 | + * |
|
317 | + * @throws \EE_Error |
|
318 | + */ |
|
319 | + protected function _assemble_data() |
|
320 | + { |
|
321 | + //verify that reg_objs is set |
|
322 | + if ( |
|
323 | + ! is_array($this->reg_objs) |
|
324 | + && ! reset($this->reg_objs) instanceof EE_Registration |
|
325 | + ) { |
|
326 | + throw new EE_Error( |
|
327 | + __( |
|
328 | + 'In order to assemble the data correctly, the "reg_objs" property must be an array of EE_Registration objects', |
|
329 | + 'event_espresso' |
|
330 | + ) |
|
331 | + ); |
|
332 | + } |
|
333 | + |
|
334 | + //get all attendee and events associated with the registrations in this transaction |
|
335 | + $events = $event_setup = $evtcache = $tickets = $datetimes = array(); |
|
336 | + $answers = $questions = $attendees = $line_items = $registrations = array(); |
|
337 | + $total_ticket_count = 0; |
|
338 | + |
|
339 | + if (! empty($this->reg_objs)) { |
|
340 | + $event_attendee_count = array(); |
|
341 | + foreach ($this->reg_objs as $reg) { |
|
342 | + |
|
343 | + if ( |
|
344 | + $this->_skip_registration_for_processing($reg) |
|
345 | + ) { |
|
346 | + continue; |
|
347 | + } |
|
348 | + |
|
349 | + $evt_id = $reg->event_ID(); |
|
350 | + /** @type EE_Ticket $ticket */ |
|
351 | + $ticket = $reg->get_first_related('Ticket'); |
|
352 | + $relateddatetime = $ticket->datetimes(); |
|
353 | + $total_ticket_count++; |
|
354 | + $tickets[$ticket->ID()]['ticket'] = $ticket; |
|
355 | + $tickets[$ticket->ID()]['count'] = is_array($tickets[$ticket->ID()]) |
|
356 | + && isset($tickets[$ticket->ID()]['count']) |
|
357 | + ? $tickets[$ticket->ID()]['count'] + 1 |
|
358 | + : 1; |
|
359 | + $tickets[$ticket->ID()]['att_objs'][$reg->attendee_ID()] = $reg->attendee(); |
|
360 | + $tickets[$ticket->ID()]['dtt_objs'] = $relateddatetime; |
|
361 | + $tickets[$ticket->ID()]['reg_objs'][$reg->ID()] = $reg; |
|
362 | + $event = $reg->event(); |
|
363 | + $tickets[$ticket->ID()]['EE_Event'] = $event; |
|
364 | + $evtcache[$evt_id] = $event; |
|
365 | + $eventsetup[$evt_id]['reg_objs'][$reg->ID()] = $reg; |
|
366 | + $eventsetup[$evt_id]['tkt_objs'][$ticket->ID()] = $ticket; |
|
367 | + $eventsetup[$evt_id]['att_objs'][$reg->attendee_ID()] = $reg->attendee(); |
|
368 | + $event_attendee_count[$evt_id] = isset($event_attendee_count[$evt_id]) |
|
369 | + ? $event_attendee_count[$evt_id] + 1 |
|
370 | + : 0; |
|
371 | + $attendees[$reg->attendee_ID()]['line_ref'][] = $evt_id; |
|
372 | + $attendees[$reg->attendee_ID()]['att_obj'] = $reg->attendee(); |
|
373 | + $attendees[$reg->attendee_ID()]['reg_objs'][$reg->ID()] = $reg; |
|
374 | + //$attendees[ $reg->attendee_ID() ]['registration_id'] = $reg->ID(); |
|
375 | + $attendees[$reg->attendee_ID()]['attendee_email'] = $reg->attendee() instanceof EE_Attendee |
|
376 | + ? $reg->attendee()->email() |
|
377 | + : ''; |
|
378 | + $attendees[$reg->attendee_ID()]['tkt_objs'][$ticket->ID()] = $ticket; |
|
379 | + $attendees[$reg->attendee_ID()]['evt_objs'][$evt_id] = $event; |
|
380 | + |
|
381 | + //registrations |
|
382 | + $registrations[$reg->ID()]['tkt_obj'] = $ticket; |
|
383 | + $registrations[$reg->ID()]['evt_obj'] = $event; |
|
384 | + $registrations[$reg->ID()]['reg_obj'] = $reg; |
|
385 | + $registrations[$reg->ID()]['att_obj'] = $reg->attendee(); |
|
386 | + |
|
387 | + //set up answer objects |
|
388 | + $rel_ans = $reg->get_many_related('Answer'); |
|
389 | + foreach ($rel_ans as $ansid => $answer) { |
|
390 | + if (! isset($questions[$ansid])) { |
|
391 | + $questions[$ansid] = $answer->get_first_related('Question'); |
|
392 | + } |
|
393 | + $answers[$ansid] = $answer; |
|
394 | + $registrations[$reg->ID()]['ans_objs'][$ansid] = $answer; |
|
395 | + } |
|
396 | + |
|
397 | + foreach ($relateddatetime as $dtt_id => $datetime) { |
|
398 | + $eventsetup[$evt_id]['dtt_objs'][$dtt_id] = $datetime; |
|
399 | + $registrations[$reg->ID()]['dtt_objs'][$dtt_id] = $datetime; |
|
400 | + |
|
401 | + if (isset($datetimes[$dtt_id])) { |
|
402 | + continue; //already have this info in the datetimes array. |
|
403 | + } |
|
404 | + |
|
405 | + $datetimes[$dtt_id]['tkt_objs'][] = $ticket; |
|
406 | + $datetimes[$dtt_id]['datetime'] = $datetime; |
|
407 | + $datetimes[$dtt_id]['evt_objs'][$evt_id] = $event; |
|
408 | + $datetimes[$dtt_id]['reg_objs'][$reg->ID()] = $reg; |
|
409 | + } |
|
410 | + } |
|
411 | + |
|
412 | + //let's loop through the unique event=>reg items and setup data on them |
|
413 | + |
|
414 | + if (! empty($eventsetup)) { |
|
415 | + foreach ($eventsetup as $evt_id => $items) { |
|
416 | + if ($this->txn instanceof EE_Transaction) { |
|
417 | + $ticket_line_items_for_event = EEM_Line_Item::instance()->get_all( |
|
418 | + array( |
|
419 | + array( |
|
420 | + 'Ticket.Datetime.EVT_ID' => $evt_id, |
|
421 | + 'TXN_ID' => $this->txn->ID(), |
|
422 | + ), |
|
423 | + 'default_where_conditions' => 'none', |
|
424 | + ) |
|
425 | + ); |
|
426 | + } else { |
|
427 | + $ticket_line_items_for_event = array(); |
|
428 | + } |
|
429 | + $events[$evt_id] = array( |
|
430 | + 'ID' => $evt_id, |
|
431 | + 'event' => $evtcache[$evt_id], |
|
432 | + 'name' => $evtcache[$evt_id] instanceof EE_Event ? $evtcache[$evt_id]->name() : '', |
|
433 | + 'total_attendees' => $event_attendee_count[$evt_id], |
|
434 | + 'reg_objs' => $items['reg_objs'], |
|
435 | + 'tkt_objs' => $items['tkt_objs'], |
|
436 | + 'att_objs' => $items['att_objs'], |
|
437 | + 'dtt_objs' => isset($items['dtt_objs']) ? $items['dtt_objs'] : array(), |
|
438 | + 'line_items' => $ticket_line_items_for_event, |
|
439 | + ); |
|
440 | + |
|
441 | + //make sure the tickets have the line items setup for them. |
|
442 | + foreach ($ticket_line_items_for_event as $line_id => $line_item) { |
|
443 | + if ($line_item instanceof EE_Line_Item) { |
|
444 | + $tickets[$line_item->ticket()->ID()]['line_item'] = $line_item; |
|
445 | + $tickets[$line_item->ticket()->ID()]['sub_line_items'] = $line_item->children(); |
|
446 | + $line_items[$line_item->ID()]['children'] = $line_item->children(); |
|
447 | + $line_items[$line_item->ID()]['EE_Ticket'] = $line_item->ticket(); |
|
448 | + } |
|
449 | + } |
|
450 | + } |
|
451 | + } |
|
452 | + |
|
453 | + $this->grand_total_line_item = $this->txn instanceof EE_Transaction |
|
454 | + ? $this->txn->total_line_item() |
|
455 | + : null; |
|
456 | + } |
|
457 | + |
|
458 | + //lets set the attendees and events properties |
|
459 | + $this->attendees = $attendees; |
|
460 | + $this->events = $events; |
|
461 | + $this->tickets = $tickets; |
|
462 | + $this->line_items_with_children = $line_items; |
|
463 | + $this->datetimes = $datetimes; |
|
464 | + $this->questions = $questions; |
|
465 | + $this->answers = $answers; |
|
466 | + $this->total_ticket_count = $total_ticket_count; |
|
467 | + $this->registrations = $registrations; |
|
468 | + |
|
469 | + if ($this->txn instanceof EE_Transaction) { |
|
470 | + $this->tax_line_items = $this->txn->tax_items(); |
|
471 | + $this->additional_line_items = $this->txn->non_ticket_line_items(); |
|
472 | + $this->payments = $this->txn->payments(); |
|
473 | + |
|
474 | + //setup primary registration if we have a single transaction object to work with |
|
475 | + |
|
476 | + //let's get just the primary_attendee_data! First we get the primary registration object. |
|
477 | + $primary_reg = $this->txn->primary_registration(); |
|
478 | + // verify |
|
479 | + if ($primary_reg instanceof EE_Registration) { |
|
480 | + |
|
481 | + // get attendee object |
|
482 | + if ($primary_reg->attendee() instanceof EE_Attendee) { |
|
483 | + |
|
484 | + //now we can setup the primary_attendee_data array |
|
485 | + $this->primary_attendee_data = array( |
|
486 | + 'registration_id' => $primary_reg->ID(), |
|
487 | + 'att_obj' => $primary_reg->attendee(), |
|
488 | + 'reg_obj' => $primary_reg, |
|
489 | + 'primary_att_obj' => $primary_reg->attendee(), |
|
490 | + 'primary_reg_obj' => $primary_reg, |
|
491 | + ); |
|
492 | + |
|
493 | + } else { |
|
494 | + EE_Error::add_error( |
|
495 | + __( |
|
496 | + 'Incoming data does not have a valid Attendee object for the primary registrant.', |
|
497 | + 'event_espresso' |
|
498 | + ), |
|
499 | + __FILE__, |
|
500 | + __FUNCTION__, |
|
501 | + __LINE__ |
|
502 | + ); |
|
503 | + } |
|
504 | + } else { |
|
505 | + EE_Error::add_error( |
|
506 | + __( |
|
507 | + 'Incoming data does not have a valid Registration object for the primary registrant.', |
|
508 | + 'event_espresso' |
|
509 | + ), |
|
510 | + __FILE__, |
|
511 | + __FUNCTION__, |
|
512 | + __LINE__ |
|
513 | + ); |
|
514 | + } |
|
515 | + } |
|
516 | + } |
|
517 | + |
|
518 | + /** |
|
519 | + * This simply considers whether the given registration should be processed or not based on comparison with the |
|
520 | + * filtered_reg_status property. |
|
521 | + * |
|
522 | + * @param EE_Registration $registration |
|
523 | + * @return bool returning true means we DO want to skip processing. returning false means we DON'T want to skip |
|
524 | + * processing |
|
525 | + */ |
|
526 | + protected function _skip_registration_for_processing(EE_Registration $registration) |
|
527 | + { |
|
528 | + if (empty($this->filtered_reg_status)) { |
|
529 | + return false; |
|
530 | + } |
|
531 | + |
|
532 | + //if we made it here then we just compare the filtered_reg_status with the registration status and return that |
|
533 | + return $this->filtered_reg_status !== $registration->status_ID(); |
|
534 | + } |
|
535 | 535 | |
536 | 536 | |
537 | 537 | } //end EE_Messages_incoming_data class |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
3 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
4 | 4 | exit('NO direct script access allowed'); |
5 | 5 | } |
6 | 6 | |
@@ -336,7 +336,7 @@ discard block |
||
336 | 336 | $answers = $questions = $attendees = $line_items = $registrations = array(); |
337 | 337 | $total_ticket_count = 0; |
338 | 338 | |
339 | - if (! empty($this->reg_objs)) { |
|
339 | + if ( ! empty($this->reg_objs)) { |
|
340 | 340 | $event_attendee_count = array(); |
341 | 341 | foreach ($this->reg_objs as $reg) { |
342 | 342 | |
@@ -387,7 +387,7 @@ discard block |
||
387 | 387 | //set up answer objects |
388 | 388 | $rel_ans = $reg->get_many_related('Answer'); |
389 | 389 | foreach ($rel_ans as $ansid => $answer) { |
390 | - if (! isset($questions[$ansid])) { |
|
390 | + if ( ! isset($questions[$ansid])) { |
|
391 | 391 | $questions[$ansid] = $answer->get_first_related('Question'); |
392 | 392 | } |
393 | 393 | $answers[$ansid] = $answer; |
@@ -411,7 +411,7 @@ discard block |
||
411 | 411 | |
412 | 412 | //let's loop through the unique event=>reg items and setup data on them |
413 | 413 | |
414 | - if (! empty($eventsetup)) { |
|
414 | + if ( ! empty($eventsetup)) { |
|
415 | 415 | foreach ($eventsetup as $evt_id => $items) { |
416 | 416 | if ($this->txn instanceof EE_Transaction) { |
417 | 417 | $ticket_line_items_for_event = EEM_Line_Item::instance()->get_all( |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php if (! defined('EVENT_ESPRESSO_VERSION')) { |
2 | - exit('NO direct script access allowed'); |
|
2 | + exit('NO direct script access allowed'); |
|
3 | 3 | } |
4 | 4 | |
5 | 5 | |
@@ -17,592 +17,592 @@ discard block |
||
17 | 17 | class EEG_Paypal_Express extends EE_Offsite_Gateway |
18 | 18 | { |
19 | 19 | |
20 | - /** |
|
21 | - * Merchant API Username. |
|
22 | - * |
|
23 | - * @var string |
|
24 | - */ |
|
25 | - protected $_api_username; |
|
26 | - |
|
27 | - /** |
|
28 | - * Merchant API Password. |
|
29 | - * |
|
30 | - * @var string |
|
31 | - */ |
|
32 | - protected $_api_password; |
|
33 | - |
|
34 | - /** |
|
35 | - * API Signature. |
|
36 | - * |
|
37 | - * @var string |
|
38 | - */ |
|
39 | - protected $_api_signature; |
|
40 | - |
|
41 | - /** |
|
42 | - * Request Shipping address on PP checkout page. |
|
43 | - * |
|
44 | - * @var string |
|
45 | - */ |
|
46 | - protected $_request_shipping_addr; |
|
47 | - |
|
48 | - /** |
|
49 | - * Business/personal logo. |
|
50 | - * |
|
51 | - * @var string |
|
52 | - */ |
|
53 | - protected $_image_url; |
|
54 | - |
|
55 | - /** |
|
56 | - * gateway URL variable |
|
57 | - * |
|
58 | - * @var string |
|
59 | - */ |
|
60 | - protected $_base_gateway_url = ''; |
|
61 | - |
|
62 | - |
|
63 | - |
|
64 | - /** |
|
65 | - * EEG_Paypal_Express constructor. |
|
66 | - */ |
|
67 | - public function __construct() |
|
68 | - { |
|
69 | - $this->_currencies_supported = array( |
|
70 | - 'USD', |
|
71 | - 'AUD', |
|
72 | - 'BRL', |
|
73 | - 'CAD', |
|
74 | - 'CZK', |
|
75 | - 'DKK', |
|
76 | - 'EUR', |
|
77 | - 'HKD', |
|
78 | - 'HUF', |
|
79 | - 'ILS', |
|
80 | - 'JPY', |
|
81 | - 'MYR', |
|
82 | - 'MXN', |
|
83 | - 'NOK', |
|
84 | - 'NZD', |
|
85 | - 'PHP', |
|
86 | - 'PLN', |
|
87 | - 'GBP', |
|
88 | - 'RUB', |
|
89 | - 'SGD', |
|
90 | - 'SEK', |
|
91 | - 'CHF', |
|
92 | - 'TWD', |
|
93 | - 'THB', |
|
94 | - 'TRY', |
|
95 | - ); |
|
96 | - parent::__construct(); |
|
97 | - } |
|
98 | - |
|
99 | - |
|
100 | - |
|
101 | - /** |
|
102 | - * Sets the gateway URL variable based on whether debug mode is enabled or not. |
|
103 | - * |
|
104 | - * @param array $settings_array |
|
105 | - */ |
|
106 | - public function set_settings($settings_array) |
|
107 | - { |
|
108 | - parent::set_settings($settings_array); |
|
109 | - // Redirect URL. |
|
110 | - $this->_base_gateway_url = $this->_debug_mode |
|
111 | - ? 'https://api-3t.sandbox.paypal.com/nvp' |
|
112 | - : 'https://api-3t.paypal.com/nvp'; |
|
113 | - } |
|
114 | - |
|
115 | - |
|
116 | - |
|
117 | - /** |
|
118 | - * @param EEI_Payment $payment |
|
119 | - * @param array $billing_info |
|
120 | - * @param string $return_url |
|
121 | - * @param string $notify_url |
|
122 | - * @param string $cancel_url |
|
123 | - * @return \EE_Payment|\EEI_Payment |
|
124 | - * @throws \EE_Error |
|
125 | - */ |
|
126 | - public function set_redirection_info( |
|
127 | - $payment, |
|
128 | - $billing_info = array(), |
|
129 | - $return_url = null, |
|
130 | - $notify_url = null, |
|
131 | - $cancel_url = null |
|
132 | - ) { |
|
133 | - if (! $payment instanceof EEI_Payment) { |
|
134 | - $payment->set_gateway_response( |
|
135 | - esc_html__( |
|
136 | - 'Error. No associated payment was found.', |
|
137 | - 'event_espresso' |
|
138 | - ) |
|
139 | - ); |
|
140 | - $payment->set_status($this->_pay_model->failed_status()); |
|
141 | - return $payment; |
|
142 | - } |
|
143 | - $transaction = $payment->transaction(); |
|
144 | - if (! $transaction instanceof EEI_Transaction) { |
|
145 | - $payment->set_gateway_response( |
|
146 | - esc_html__( |
|
147 | - 'Could not process this payment because it has no associated transaction.', |
|
148 | - 'event_espresso' |
|
149 | - ) |
|
150 | - ); |
|
151 | - $payment->set_status($this->_pay_model->failed_status()); |
|
152 | - return $payment; |
|
153 | - } |
|
154 | - $order_description = substr($this->_format_order_description($payment), 0, 127); |
|
155 | - $primary_registration = $transaction->primary_registration(); |
|
156 | - $primary_attendee = $primary_registration instanceof EE_Registration |
|
157 | - ? $primary_registration->attendee() |
|
158 | - : false; |
|
159 | - $locale = explode('-', get_bloginfo('language')); |
|
160 | - // Gather request parameters. |
|
161 | - $token_request_dtls = array( |
|
162 | - 'METHOD' => 'SetExpressCheckout', |
|
163 | - 'PAYMENTREQUEST_0_AMT' => $payment->amount(), |
|
164 | - 'PAYMENTREQUEST_0_CURRENCYCODE' => $payment->currency_code(), |
|
165 | - 'PAYMENTREQUEST_0_DESC' => $order_description, |
|
166 | - 'RETURNURL' => $return_url, |
|
167 | - 'CANCELURL' => $cancel_url, |
|
168 | - 'PAYMENTREQUEST_0_PAYMENTACTION' => 'Sale', |
|
169 | - // Buyer does not need to create a PayPal account to check out. |
|
170 | - // This is referred to as PayPal Account Optional. |
|
171 | - 'SOLUTIONTYPE' => 'Sole', |
|
172 | - //EE will blow up if you change this |
|
173 | - 'BUTTONSOURCE' => 'EventEspresso_SP', |
|
174 | - // Locale of the pages displayed by PayPal during Express Checkout. |
|
175 | - 'LOCALECODE' => $locale[1] |
|
176 | - ); |
|
177 | - // Show itemized list. |
|
178 | - if ($this->_money->compare_floats($payment->amount(), $transaction->total(), '==')) { |
|
179 | - $item_num = 0; |
|
180 | - $itemized_sum = 0; |
|
181 | - $total_line_items = $transaction->total_line_item(); |
|
182 | - // Go through each item in the list. |
|
183 | - foreach ($total_line_items->get_items() as $line_item) { |
|
184 | - if ($line_item instanceof EE_Line_Item) { |
|
185 | - // PayPal doesn't like line items with 0.00 amount, so we may skip those. |
|
186 | - if (EEH_Money::compare_floats($line_item->total(), '0.00', '==')) { |
|
187 | - continue; |
|
188 | - } |
|
189 | - $unit_price = $line_item->unit_price(); |
|
190 | - $line_item_quantity = $line_item->quantity(); |
|
191 | - // This is a discount. |
|
192 | - if ($line_item->is_percent()) { |
|
193 | - $unit_price = $line_item->total(); |
|
194 | - $line_item_quantity = 1; |
|
195 | - } |
|
196 | - // Item Name. |
|
197 | - $token_request_dtls['L_PAYMENTREQUEST_0_NAME' . $item_num] = substr( |
|
198 | - $this->_format_line_item_name($line_item, $payment), |
|
199 | - 0, |
|
200 | - 127 |
|
201 | - ); |
|
202 | - // Item description. |
|
203 | - $token_request_dtls['L_PAYMENTREQUEST_0_DESC' . $item_num] = substr( |
|
204 | - $this->_format_line_item_desc($line_item, $payment), |
|
205 | - 0, |
|
206 | - 127 |
|
207 | - ); |
|
208 | - // Cost of individual item. |
|
209 | - $token_request_dtls['L_PAYMENTREQUEST_0_AMT' . $item_num] = $this->format_currency($unit_price); |
|
210 | - // Item Number. |
|
211 | - $token_request_dtls['L_PAYMENTREQUEST_0_NUMBER' . $item_num] = $item_num + 1; |
|
212 | - // Item quantity. |
|
213 | - $token_request_dtls['L_PAYMENTREQUEST_0_QTY' . $item_num] = $line_item_quantity; |
|
214 | - // Digital item is sold. |
|
215 | - $token_request_dtls['L_PAYMENTREQUEST_0_ITEMCATEGORY' . $item_num] = 'Physical'; |
|
216 | - $itemized_sum += $line_item->total(); |
|
217 | - ++$item_num; |
|
218 | - } |
|
219 | - } |
|
220 | - // Item's sales S/H and tax amount. |
|
221 | - $token_request_dtls['PAYMENTREQUEST_0_ITEMAMT'] = $total_line_items->get_items_total(); |
|
222 | - $token_request_dtls['PAYMENTREQUEST_0_TAXAMT'] = $total_line_items->get_total_tax(); |
|
223 | - $token_request_dtls['PAYMENTREQUEST_0_SHIPPINGAMT'] = '0'; |
|
224 | - $token_request_dtls['PAYMENTREQUEST_0_HANDLINGAMT'] = '0'; |
|
225 | - $itemized_sum_diff_from_txn_total = round( |
|
226 | - $transaction->total() - $itemized_sum - $total_line_items->get_total_tax(), |
|
227 | - 2 |
|
228 | - ); |
|
229 | - // If we were not able to recognize some item like promotion, surcharge or cancellation, |
|
230 | - // add the difference as an extra line item. |
|
231 | - if ($this->_money->compare_floats($itemized_sum_diff_from_txn_total, 0, '!=')) { |
|
232 | - // Item Name. |
|
233 | - $token_request_dtls['L_PAYMENTREQUEST_0_NAME' . $item_num] = substr( |
|
234 | - esc_html__( |
|
235 | - 'Other (promotion/surcharge/cancellation)', |
|
236 | - 'event_espresso' |
|
237 | - ), |
|
238 | - 0, |
|
239 | - 127 |
|
240 | - ); |
|
241 | - // Item description. |
|
242 | - $token_request_dtls['L_PAYMENTREQUEST_0_DESC' . $item_num] = ''; |
|
243 | - // Cost of individual item. |
|
244 | - $token_request_dtls['L_PAYMENTREQUEST_0_AMT' . $item_num] = $this->format_currency( |
|
245 | - $itemized_sum_diff_from_txn_total |
|
246 | - ); |
|
247 | - // Item Number. |
|
248 | - $token_request_dtls['L_PAYMENTREQUEST_0_NUMBER' . $item_num] = $item_num + 1; |
|
249 | - // Item quantity. |
|
250 | - $token_request_dtls['L_PAYMENTREQUEST_0_QTY' . $item_num] = 1; |
|
251 | - // Digital item is sold. |
|
252 | - $token_request_dtls['L_PAYMENTREQUEST_0_ITEMCATEGORY' . $item_num] = 'Physical'; |
|
253 | - $item_num++; |
|
254 | - } |
|
255 | - } else { |
|
256 | - // Just one Item. |
|
257 | - // Item Name. |
|
258 | - $token_request_dtls['L_PAYMENTREQUEST_0_NAME0'] = substr( |
|
259 | - $this->_format_partial_payment_line_item_name($payment), |
|
260 | - 0, |
|
261 | - 127 |
|
262 | - ); |
|
263 | - // Item description. |
|
264 | - $token_request_dtls['L_PAYMENTREQUEST_0_DESC0'] = substr( |
|
265 | - $this->_format_partial_payment_line_item_desc($payment), |
|
266 | - 0, |
|
267 | - 127 |
|
268 | - ); |
|
269 | - // Cost of individual item. |
|
270 | - $token_request_dtls['L_PAYMENTREQUEST_0_AMT0'] = $this->format_currency($payment->amount()); |
|
271 | - // Item Number. |
|
272 | - $token_request_dtls['L_PAYMENTREQUEST_0_NUMBER0'] = 1; |
|
273 | - // Item quantity. |
|
274 | - $token_request_dtls['L_PAYMENTREQUEST_0_QTY0'] = 1; |
|
275 | - // Digital item is sold. |
|
276 | - $token_request_dtls['L_PAYMENTREQUEST_0_ITEMCATEGORY0'] = 'Physical'; |
|
277 | - // Item's sales S/H and tax amount. |
|
278 | - $token_request_dtls['PAYMENTREQUEST_0_ITEMAMT'] = $this->format_currency($payment->amount()); |
|
279 | - $token_request_dtls['PAYMENTREQUEST_0_TAXAMT'] = '0'; |
|
280 | - $token_request_dtls['PAYMENTREQUEST_0_SHIPPINGAMT'] = '0'; |
|
281 | - $token_request_dtls['PAYMENTREQUEST_0_HANDLINGAMT'] = '0'; |
|
282 | - } |
|
283 | - // Automatically filling out shipping and contact information. |
|
284 | - if ($this->_request_shipping_addr && $primary_attendee instanceof EEI_Attendee) { |
|
285 | - // If you do not pass the shipping address, PayPal obtains it from the buyer's account profile. |
|
286 | - $token_request_dtls['NOSHIPPING'] = '2'; |
|
287 | - $token_request_dtls['PAYMENTREQUEST_0_SHIPTOSTREET'] = $primary_attendee->address(); |
|
288 | - $token_request_dtls['PAYMENTREQUEST_0_SHIPTOSTREET2'] = $primary_attendee->address2(); |
|
289 | - $token_request_dtls['PAYMENTREQUEST_0_SHIPTOCITY'] = $primary_attendee->city(); |
|
290 | - $token_request_dtls['PAYMENTREQUEST_0_SHIPTOSTATE'] = $primary_attendee->state_abbrev(); |
|
291 | - $token_request_dtls['PAYMENTREQUEST_0_SHIPTOCOUNTRYCODE'] = $primary_attendee->country_ID(); |
|
292 | - $token_request_dtls['PAYMENTREQUEST_0_SHIPTOZIP'] = $primary_attendee->zip(); |
|
293 | - $token_request_dtls['PAYMENTREQUEST_0_EMAIL'] = $primary_attendee->email(); |
|
294 | - $token_request_dtls['PAYMENTREQUEST_0_SHIPTOPHONENUM'] = $primary_attendee->phone(); |
|
295 | - } elseif (! $this->_request_shipping_addr) { |
|
296 | - // Do not request shipping details on the PP Checkout page. |
|
297 | - $token_request_dtls['NOSHIPPING'] = '1'; |
|
298 | - $token_request_dtls['REQCONFIRMSHIPPING'] = '0'; |
|
299 | - } |
|
300 | - // Used a business/personal logo on the PayPal page. |
|
301 | - if (! empty($this->_image_url)) { |
|
302 | - $token_request_dtls['LOGOIMG'] = $this->_image_url; |
|
303 | - } |
|
304 | - $token_request_dtls = apply_filters( |
|
305 | - 'FHEE__EEG_Paypal_Express__set_redirection_info__arguments', |
|
306 | - $token_request_dtls, |
|
307 | - $this |
|
308 | - ); |
|
309 | - // Request PayPal token. |
|
310 | - $token_request_response = $this->_ppExpress_request($token_request_dtls, 'Payment Token', $payment); |
|
311 | - $token_rstatus = $this->_ppExpress_check_response($token_request_response); |
|
312 | - $response_args = (isset($token_rstatus['args']) && is_array($token_rstatus['args'])) |
|
313 | - ? $token_rstatus['args'] |
|
314 | - : array(); |
|
315 | - if ($token_rstatus['status']) { |
|
316 | - // We got the Token so we may continue with the payment and redirect the client. |
|
317 | - $payment->set_details($response_args); |
|
318 | - $gateway_url = $this->_debug_mode ? 'https://www.sandbox.paypal.com' : 'https://www.paypal.com'; |
|
319 | - $payment->set_redirect_url( |
|
320 | - $gateway_url |
|
321 | - . '/checkoutnow?useraction=commit&cmd=_express-checkout&token=' |
|
322 | - . $response_args['TOKEN'] |
|
323 | - ); |
|
324 | - } else { |
|
325 | - if (isset($response_args['L_ERRORCODE'])) { |
|
326 | - $payment->set_gateway_response($response_args['L_ERRORCODE'] . '; ' . $response_args['L_SHORTMESSAGE']); |
|
327 | - } else { |
|
328 | - $payment->set_gateway_response( |
|
329 | - esc_html__( |
|
330 | - 'Error occurred while trying to setup the Express Checkout.', |
|
331 | - 'event_espresso' |
|
332 | - ) |
|
333 | - ); |
|
334 | - } |
|
335 | - $payment->set_details($response_args); |
|
336 | - $payment->set_status($this->_pay_model->failed_status()); |
|
337 | - } |
|
338 | - return $payment; |
|
339 | - } |
|
340 | - |
|
341 | - |
|
342 | - |
|
343 | - /** |
|
344 | - * @param array $update_info { |
|
345 | - * @type string $gateway_txn_id |
|
346 | - * @type string status an EEMI_Payment status |
|
347 | - * } |
|
348 | - * @param EEI_Transaction $transaction |
|
349 | - * @return EEI_Payment |
|
350 | - */ |
|
351 | - public function handle_payment_update($update_info, $transaction) |
|
352 | - { |
|
353 | - $payment = $transaction instanceof EEI_Transaction ? $transaction->last_payment() : null; |
|
354 | - if ($payment instanceof EEI_Payment) { |
|
355 | - $this->log(array('Return from Authorization' => $update_info), $payment); |
|
356 | - $transaction = $payment->transaction(); |
|
357 | - if (! $transaction instanceof EEI_Transaction) { |
|
358 | - $payment->set_gateway_response( |
|
359 | - esc_html__( |
|
360 | - 'Could not process this payment because it has no associated transaction.', |
|
361 | - 'event_espresso' |
|
362 | - ) |
|
363 | - ); |
|
364 | - $payment->set_status($this->_pay_model->failed_status()); |
|
365 | - return $payment; |
|
366 | - } |
|
367 | - $primary_registrant = $transaction->primary_registration(); |
|
368 | - $payment_details = $payment->details(); |
|
369 | - // Check if we still have the token. |
|
370 | - if (! isset($payment_details['TOKEN']) || empty($payment_details['TOKEN'])) { |
|
371 | - $payment->set_status($this->_pay_model->failed_status()); |
|
372 | - return $payment; |
|
373 | - } |
|
374 | - $cdetails_request_dtls = array( |
|
375 | - 'METHOD' => 'GetExpressCheckoutDetails', |
|
376 | - 'TOKEN' => $payment_details['TOKEN'], |
|
377 | - ); |
|
378 | - // Request Customer Details. |
|
379 | - $cdetails_request_response = $this->_ppExpress_request( |
|
380 | - $cdetails_request_dtls, |
|
381 | - 'Customer Details', |
|
382 | - $payment |
|
383 | - ); |
|
384 | - $cdetails_rstatus = $this->_ppExpress_check_response($cdetails_request_response); |
|
385 | - $cdata_response_args = (isset($cdetails_rstatus['args']) && is_array($cdetails_rstatus['args'])) |
|
386 | - ? $cdetails_rstatus['args'] |
|
387 | - : array(); |
|
388 | - if ($cdetails_rstatus['status']) { |
|
389 | - // We got the PayerID so now we can Complete the transaction. |
|
390 | - $docheckout_request_dtls = array( |
|
391 | - 'METHOD' => 'DoExpressCheckoutPayment', |
|
392 | - 'PAYERID' => $cdata_response_args['PAYERID'], |
|
393 | - 'TOKEN' => $payment_details['TOKEN'], |
|
394 | - 'PAYMENTREQUEST_0_PAYMENTACTION' => 'Sale', |
|
395 | - 'PAYMENTREQUEST_0_AMT' => $payment->amount(), |
|
396 | - 'PAYMENTREQUEST_0_CURRENCYCODE' => $payment->currency_code(), |
|
397 | - //EE will blow up if you change this |
|
398 | - 'BUTTONSOURCE' => 'EventEspresso_SP', |
|
399 | - ); |
|
400 | - // Payment Checkout/Capture. |
|
401 | - $docheckout_request_response = $this->_ppExpress_request( |
|
402 | - $docheckout_request_dtls, |
|
403 | - 'Do Payment', |
|
404 | - $payment |
|
405 | - ); |
|
406 | - $docheckout_rstatus = $this->_ppExpress_check_response($docheckout_request_response); |
|
407 | - $docheckout_response_args = (isset($docheckout_rstatus['args']) && is_array($docheckout_rstatus['args'])) |
|
408 | - ? $docheckout_rstatus['args'] |
|
409 | - : array(); |
|
410 | - if ($docheckout_rstatus['status']) { |
|
411 | - // All is well, payment approved. |
|
412 | - $primary_registration_code = $primary_registrant instanceof EE_Registration ? |
|
413 | - $primary_registrant->reg_code() |
|
414 | - : ''; |
|
415 | - $payment->set_extra_accntng($primary_registration_code); |
|
416 | - $payment->set_amount(isset($docheckout_response_args['PAYMENTINFO_0_AMT']) |
|
417 | - ? (float)$docheckout_response_args['PAYMENTINFO_0_AMT'] |
|
418 | - : 0); |
|
419 | - $payment->set_txn_id_chq_nmbr(isset($docheckout_response_args['PAYMENTINFO_0_TRANSACTIONID']) |
|
420 | - ? $docheckout_response_args['PAYMENTINFO_0_TRANSACTIONID'] |
|
421 | - : null); |
|
422 | - $payment->set_details($cdata_response_args); |
|
423 | - $payment->set_gateway_response(isset($docheckout_response_args['PAYMENTINFO_0_ACK']) |
|
424 | - ? $docheckout_response_args['PAYMENTINFO_0_ACK'] |
|
425 | - : ''); |
|
426 | - $payment->set_status($this->_pay_model->approved_status()); |
|
427 | - } else { |
|
428 | - if (isset($docheckout_response_args['L_ERRORCODE'])) { |
|
429 | - $payment->set_gateway_response( |
|
430 | - $docheckout_response_args['L_ERRORCODE'] |
|
431 | - . '; ' |
|
432 | - . $docheckout_response_args['L_SHORTMESSAGE'] |
|
433 | - ); |
|
434 | - } else { |
|
435 | - $payment->set_gateway_response( |
|
436 | - esc_html__( |
|
437 | - 'Error occurred while trying to Capture the funds.', |
|
438 | - 'event_espresso' |
|
439 | - ) |
|
440 | - ); |
|
441 | - } |
|
442 | - $payment->set_details($docheckout_response_args); |
|
443 | - $payment->set_status($this->_pay_model->declined_status()); |
|
444 | - } |
|
445 | - } else { |
|
446 | - if (isset($cdata_response_args['L_ERRORCODE'])) { |
|
447 | - $payment->set_gateway_response( |
|
448 | - $cdata_response_args['L_ERRORCODE'] |
|
449 | - . '; ' |
|
450 | - . $cdata_response_args['L_SHORTMESSAGE'] |
|
451 | - ); |
|
452 | - } else { |
|
453 | - $payment->set_gateway_response( |
|
454 | - esc_html__( |
|
455 | - 'Error occurred while trying to get payment Details from PayPal.', |
|
456 | - 'event_espresso' |
|
457 | - ) |
|
458 | - ); |
|
459 | - } |
|
460 | - $payment->set_details($cdata_response_args); |
|
461 | - $payment->set_status($this->_pay_model->failed_status()); |
|
462 | - } |
|
463 | - } else { |
|
464 | - $payment->set_gateway_response( |
|
465 | - esc_html__( |
|
466 | - 'Error occurred while trying to process the payment.', |
|
467 | - 'event_espresso' |
|
468 | - ) |
|
469 | - ); |
|
470 | - $payment->set_status($this->_pay_model->failed_status()); |
|
471 | - } |
|
472 | - return $payment; |
|
473 | - } |
|
474 | - |
|
475 | - |
|
476 | - |
|
477 | - /** |
|
478 | - * Make the Express checkout request. |
|
479 | - * |
|
480 | - * @param array $request_params |
|
481 | - * @param string $request_text |
|
482 | - * @param EEI_Payment $payment |
|
483 | - * @return mixed |
|
484 | - */ |
|
485 | - public function _ppExpress_request($request_params, $request_text, $payment) |
|
486 | - { |
|
487 | - $request_dtls = array( |
|
488 | - 'VERSION' => '204.0', |
|
489 | - 'USER' => urlencode($this->_api_username), |
|
490 | - 'PWD' => urlencode($this->_api_password), |
|
491 | - 'SIGNATURE' => urlencode($this->_api_signature), |
|
492 | - ); |
|
493 | - $dtls = array_merge($request_dtls, $request_params); |
|
494 | - $this->_log_clean_request($dtls, $payment, $request_text . ' Request'); |
|
495 | - // Request Customer Details. |
|
496 | - $request_response = wp_remote_post( |
|
497 | - $this->_base_gateway_url, |
|
498 | - array( |
|
499 | - 'method' => 'POST', |
|
500 | - 'timeout' => 45, |
|
501 | - 'httpversion' => '1.1', |
|
502 | - 'cookies' => array(), |
|
503 | - 'headers' => array(), |
|
504 | - 'body' => http_build_query($dtls), |
|
505 | - ) |
|
506 | - ); |
|
507 | - // Log the response. |
|
508 | - $this->log(array($request_text . ' Response' => $request_response), $payment); |
|
509 | - return $request_response; |
|
510 | - } |
|
511 | - |
|
512 | - |
|
513 | - |
|
514 | - /** |
|
515 | - * Check the response status. |
|
516 | - * |
|
517 | - * @param mixed $request_response |
|
518 | - * @return array |
|
519 | - */ |
|
520 | - public function _ppExpress_check_response($request_response) |
|
521 | - { |
|
522 | - if (is_wp_error($request_response) || empty($request_response['body'])) { |
|
523 | - // If we got here then there was an error in this request. |
|
524 | - return array('status' => false, 'args' => $request_response); |
|
525 | - } |
|
526 | - $response_args = array(); |
|
527 | - parse_str(urldecode($request_response['body']), $response_args); |
|
528 | - if (! isset($response_args['ACK'])) { |
|
529 | - return array('status' => false, 'args' => $request_response); |
|
530 | - } |
|
531 | - if ( |
|
532 | - ( |
|
533 | - isset($response_args['PAYERID']) |
|
534 | - || isset($response_args['TOKEN']) |
|
535 | - || isset($response_args['PAYMENTINFO_0_TRANSACTIONID']) |
|
536 | - || (isset($response_args['PAYMENTSTATUS']) && $response_args['PAYMENTSTATUS'] === 'Completed') |
|
537 | - ) |
|
538 | - && in_array($response_args['ACK'], array('Success', 'SuccessWithWarning'), true) |
|
539 | - ) { |
|
540 | - // Response status OK, return response parameters for further processing. |
|
541 | - return array('status' => true, 'args' => $response_args); |
|
542 | - } |
|
543 | - $errors = $this->_get_errors($response_args); |
|
544 | - return array('status' => false, 'args' => $errors); |
|
545 | - } |
|
546 | - |
|
547 | - |
|
548 | - |
|
549 | - /** |
|
550 | - * Log a "Cleared" request. |
|
551 | - * |
|
552 | - * @param array $request |
|
553 | - * @param EEI_Payment $payment |
|
554 | - * @param string $info |
|
555 | - * @return void |
|
556 | - */ |
|
557 | - private function _log_clean_request($request, $payment, $info) |
|
558 | - { |
|
559 | - $cleaned_request_data = $request; |
|
560 | - unset($cleaned_request_data['PWD'], $cleaned_request_data['USER'], $cleaned_request_data['SIGNATURE']); |
|
561 | - $this->log(array($info => $cleaned_request_data), $payment); |
|
562 | - } |
|
563 | - |
|
564 | - |
|
565 | - |
|
566 | - /** |
|
567 | - * Get error from the response data. |
|
568 | - * |
|
569 | - * @param array $data_array |
|
570 | - * @return array |
|
571 | - */ |
|
572 | - private function _get_errors($data_array) |
|
573 | - { |
|
574 | - $errors = array(); |
|
575 | - $n = 0; |
|
576 | - while (isset($data_array["L_ERRORCODE{$n}"])) { |
|
577 | - $l_error_code = isset($data_array["L_ERRORCODE{$n}"]) |
|
578 | - ? $data_array["L_ERRORCODE{$n}"] |
|
579 | - : ''; |
|
580 | - $l_severity_code = isset($data_array["L_SEVERITYCODE{$n}"]) |
|
581 | - ? $data_array["L_SEVERITYCODE{$n}"] |
|
582 | - : ''; |
|
583 | - $l_short_message = isset($data_array["L_SHORTMESSAGE{$n}"]) |
|
584 | - ? $data_array["L_SHORTMESSAGE{$n}"] |
|
585 | - : ''; |
|
586 | - $l_long_message = isset($data_array["L_LONGMESSAGE{$n}"]) |
|
587 | - ? $data_array["L_LONGMESSAGE{$n}"] |
|
588 | - : ''; |
|
589 | - if ($n === 0) { |
|
590 | - $errors = array( |
|
591 | - 'L_ERRORCODE' => $l_error_code, |
|
592 | - 'L_SHORTMESSAGE' => $l_short_message, |
|
593 | - 'L_LONGMESSAGE' => $l_long_message, |
|
594 | - 'L_SEVERITYCODE' => $l_severity_code, |
|
595 | - ); |
|
596 | - } else { |
|
597 | - $errors['L_ERRORCODE'] .= ', ' . $l_error_code; |
|
598 | - $errors['L_SHORTMESSAGE'] .= ', ' . $l_short_message; |
|
599 | - $errors['L_LONGMESSAGE'] .= ', ' . $l_long_message; |
|
600 | - $errors['L_SEVERITYCODE'] .= ', ' . $l_severity_code; |
|
601 | - } |
|
602 | - $n++; |
|
603 | - } |
|
604 | - return $errors; |
|
605 | - } |
|
20 | + /** |
|
21 | + * Merchant API Username. |
|
22 | + * |
|
23 | + * @var string |
|
24 | + */ |
|
25 | + protected $_api_username; |
|
26 | + |
|
27 | + /** |
|
28 | + * Merchant API Password. |
|
29 | + * |
|
30 | + * @var string |
|
31 | + */ |
|
32 | + protected $_api_password; |
|
33 | + |
|
34 | + /** |
|
35 | + * API Signature. |
|
36 | + * |
|
37 | + * @var string |
|
38 | + */ |
|
39 | + protected $_api_signature; |
|
40 | + |
|
41 | + /** |
|
42 | + * Request Shipping address on PP checkout page. |
|
43 | + * |
|
44 | + * @var string |
|
45 | + */ |
|
46 | + protected $_request_shipping_addr; |
|
47 | + |
|
48 | + /** |
|
49 | + * Business/personal logo. |
|
50 | + * |
|
51 | + * @var string |
|
52 | + */ |
|
53 | + protected $_image_url; |
|
54 | + |
|
55 | + /** |
|
56 | + * gateway URL variable |
|
57 | + * |
|
58 | + * @var string |
|
59 | + */ |
|
60 | + protected $_base_gateway_url = ''; |
|
61 | + |
|
62 | + |
|
63 | + |
|
64 | + /** |
|
65 | + * EEG_Paypal_Express constructor. |
|
66 | + */ |
|
67 | + public function __construct() |
|
68 | + { |
|
69 | + $this->_currencies_supported = array( |
|
70 | + 'USD', |
|
71 | + 'AUD', |
|
72 | + 'BRL', |
|
73 | + 'CAD', |
|
74 | + 'CZK', |
|
75 | + 'DKK', |
|
76 | + 'EUR', |
|
77 | + 'HKD', |
|
78 | + 'HUF', |
|
79 | + 'ILS', |
|
80 | + 'JPY', |
|
81 | + 'MYR', |
|
82 | + 'MXN', |
|
83 | + 'NOK', |
|
84 | + 'NZD', |
|
85 | + 'PHP', |
|
86 | + 'PLN', |
|
87 | + 'GBP', |
|
88 | + 'RUB', |
|
89 | + 'SGD', |
|
90 | + 'SEK', |
|
91 | + 'CHF', |
|
92 | + 'TWD', |
|
93 | + 'THB', |
|
94 | + 'TRY', |
|
95 | + ); |
|
96 | + parent::__construct(); |
|
97 | + } |
|
98 | + |
|
99 | + |
|
100 | + |
|
101 | + /** |
|
102 | + * Sets the gateway URL variable based on whether debug mode is enabled or not. |
|
103 | + * |
|
104 | + * @param array $settings_array |
|
105 | + */ |
|
106 | + public function set_settings($settings_array) |
|
107 | + { |
|
108 | + parent::set_settings($settings_array); |
|
109 | + // Redirect URL. |
|
110 | + $this->_base_gateway_url = $this->_debug_mode |
|
111 | + ? 'https://api-3t.sandbox.paypal.com/nvp' |
|
112 | + : 'https://api-3t.paypal.com/nvp'; |
|
113 | + } |
|
114 | + |
|
115 | + |
|
116 | + |
|
117 | + /** |
|
118 | + * @param EEI_Payment $payment |
|
119 | + * @param array $billing_info |
|
120 | + * @param string $return_url |
|
121 | + * @param string $notify_url |
|
122 | + * @param string $cancel_url |
|
123 | + * @return \EE_Payment|\EEI_Payment |
|
124 | + * @throws \EE_Error |
|
125 | + */ |
|
126 | + public function set_redirection_info( |
|
127 | + $payment, |
|
128 | + $billing_info = array(), |
|
129 | + $return_url = null, |
|
130 | + $notify_url = null, |
|
131 | + $cancel_url = null |
|
132 | + ) { |
|
133 | + if (! $payment instanceof EEI_Payment) { |
|
134 | + $payment->set_gateway_response( |
|
135 | + esc_html__( |
|
136 | + 'Error. No associated payment was found.', |
|
137 | + 'event_espresso' |
|
138 | + ) |
|
139 | + ); |
|
140 | + $payment->set_status($this->_pay_model->failed_status()); |
|
141 | + return $payment; |
|
142 | + } |
|
143 | + $transaction = $payment->transaction(); |
|
144 | + if (! $transaction instanceof EEI_Transaction) { |
|
145 | + $payment->set_gateway_response( |
|
146 | + esc_html__( |
|
147 | + 'Could not process this payment because it has no associated transaction.', |
|
148 | + 'event_espresso' |
|
149 | + ) |
|
150 | + ); |
|
151 | + $payment->set_status($this->_pay_model->failed_status()); |
|
152 | + return $payment; |
|
153 | + } |
|
154 | + $order_description = substr($this->_format_order_description($payment), 0, 127); |
|
155 | + $primary_registration = $transaction->primary_registration(); |
|
156 | + $primary_attendee = $primary_registration instanceof EE_Registration |
|
157 | + ? $primary_registration->attendee() |
|
158 | + : false; |
|
159 | + $locale = explode('-', get_bloginfo('language')); |
|
160 | + // Gather request parameters. |
|
161 | + $token_request_dtls = array( |
|
162 | + 'METHOD' => 'SetExpressCheckout', |
|
163 | + 'PAYMENTREQUEST_0_AMT' => $payment->amount(), |
|
164 | + 'PAYMENTREQUEST_0_CURRENCYCODE' => $payment->currency_code(), |
|
165 | + 'PAYMENTREQUEST_0_DESC' => $order_description, |
|
166 | + 'RETURNURL' => $return_url, |
|
167 | + 'CANCELURL' => $cancel_url, |
|
168 | + 'PAYMENTREQUEST_0_PAYMENTACTION' => 'Sale', |
|
169 | + // Buyer does not need to create a PayPal account to check out. |
|
170 | + // This is referred to as PayPal Account Optional. |
|
171 | + 'SOLUTIONTYPE' => 'Sole', |
|
172 | + //EE will blow up if you change this |
|
173 | + 'BUTTONSOURCE' => 'EventEspresso_SP', |
|
174 | + // Locale of the pages displayed by PayPal during Express Checkout. |
|
175 | + 'LOCALECODE' => $locale[1] |
|
176 | + ); |
|
177 | + // Show itemized list. |
|
178 | + if ($this->_money->compare_floats($payment->amount(), $transaction->total(), '==')) { |
|
179 | + $item_num = 0; |
|
180 | + $itemized_sum = 0; |
|
181 | + $total_line_items = $transaction->total_line_item(); |
|
182 | + // Go through each item in the list. |
|
183 | + foreach ($total_line_items->get_items() as $line_item) { |
|
184 | + if ($line_item instanceof EE_Line_Item) { |
|
185 | + // PayPal doesn't like line items with 0.00 amount, so we may skip those. |
|
186 | + if (EEH_Money::compare_floats($line_item->total(), '0.00', '==')) { |
|
187 | + continue; |
|
188 | + } |
|
189 | + $unit_price = $line_item->unit_price(); |
|
190 | + $line_item_quantity = $line_item->quantity(); |
|
191 | + // This is a discount. |
|
192 | + if ($line_item->is_percent()) { |
|
193 | + $unit_price = $line_item->total(); |
|
194 | + $line_item_quantity = 1; |
|
195 | + } |
|
196 | + // Item Name. |
|
197 | + $token_request_dtls['L_PAYMENTREQUEST_0_NAME' . $item_num] = substr( |
|
198 | + $this->_format_line_item_name($line_item, $payment), |
|
199 | + 0, |
|
200 | + 127 |
|
201 | + ); |
|
202 | + // Item description. |
|
203 | + $token_request_dtls['L_PAYMENTREQUEST_0_DESC' . $item_num] = substr( |
|
204 | + $this->_format_line_item_desc($line_item, $payment), |
|
205 | + 0, |
|
206 | + 127 |
|
207 | + ); |
|
208 | + // Cost of individual item. |
|
209 | + $token_request_dtls['L_PAYMENTREQUEST_0_AMT' . $item_num] = $this->format_currency($unit_price); |
|
210 | + // Item Number. |
|
211 | + $token_request_dtls['L_PAYMENTREQUEST_0_NUMBER' . $item_num] = $item_num + 1; |
|
212 | + // Item quantity. |
|
213 | + $token_request_dtls['L_PAYMENTREQUEST_0_QTY' . $item_num] = $line_item_quantity; |
|
214 | + // Digital item is sold. |
|
215 | + $token_request_dtls['L_PAYMENTREQUEST_0_ITEMCATEGORY' . $item_num] = 'Physical'; |
|
216 | + $itemized_sum += $line_item->total(); |
|
217 | + ++$item_num; |
|
218 | + } |
|
219 | + } |
|
220 | + // Item's sales S/H and tax amount. |
|
221 | + $token_request_dtls['PAYMENTREQUEST_0_ITEMAMT'] = $total_line_items->get_items_total(); |
|
222 | + $token_request_dtls['PAYMENTREQUEST_0_TAXAMT'] = $total_line_items->get_total_tax(); |
|
223 | + $token_request_dtls['PAYMENTREQUEST_0_SHIPPINGAMT'] = '0'; |
|
224 | + $token_request_dtls['PAYMENTREQUEST_0_HANDLINGAMT'] = '0'; |
|
225 | + $itemized_sum_diff_from_txn_total = round( |
|
226 | + $transaction->total() - $itemized_sum - $total_line_items->get_total_tax(), |
|
227 | + 2 |
|
228 | + ); |
|
229 | + // If we were not able to recognize some item like promotion, surcharge or cancellation, |
|
230 | + // add the difference as an extra line item. |
|
231 | + if ($this->_money->compare_floats($itemized_sum_diff_from_txn_total, 0, '!=')) { |
|
232 | + // Item Name. |
|
233 | + $token_request_dtls['L_PAYMENTREQUEST_0_NAME' . $item_num] = substr( |
|
234 | + esc_html__( |
|
235 | + 'Other (promotion/surcharge/cancellation)', |
|
236 | + 'event_espresso' |
|
237 | + ), |
|
238 | + 0, |
|
239 | + 127 |
|
240 | + ); |
|
241 | + // Item description. |
|
242 | + $token_request_dtls['L_PAYMENTREQUEST_0_DESC' . $item_num] = ''; |
|
243 | + // Cost of individual item. |
|
244 | + $token_request_dtls['L_PAYMENTREQUEST_0_AMT' . $item_num] = $this->format_currency( |
|
245 | + $itemized_sum_diff_from_txn_total |
|
246 | + ); |
|
247 | + // Item Number. |
|
248 | + $token_request_dtls['L_PAYMENTREQUEST_0_NUMBER' . $item_num] = $item_num + 1; |
|
249 | + // Item quantity. |
|
250 | + $token_request_dtls['L_PAYMENTREQUEST_0_QTY' . $item_num] = 1; |
|
251 | + // Digital item is sold. |
|
252 | + $token_request_dtls['L_PAYMENTREQUEST_0_ITEMCATEGORY' . $item_num] = 'Physical'; |
|
253 | + $item_num++; |
|
254 | + } |
|
255 | + } else { |
|
256 | + // Just one Item. |
|
257 | + // Item Name. |
|
258 | + $token_request_dtls['L_PAYMENTREQUEST_0_NAME0'] = substr( |
|
259 | + $this->_format_partial_payment_line_item_name($payment), |
|
260 | + 0, |
|
261 | + 127 |
|
262 | + ); |
|
263 | + // Item description. |
|
264 | + $token_request_dtls['L_PAYMENTREQUEST_0_DESC0'] = substr( |
|
265 | + $this->_format_partial_payment_line_item_desc($payment), |
|
266 | + 0, |
|
267 | + 127 |
|
268 | + ); |
|
269 | + // Cost of individual item. |
|
270 | + $token_request_dtls['L_PAYMENTREQUEST_0_AMT0'] = $this->format_currency($payment->amount()); |
|
271 | + // Item Number. |
|
272 | + $token_request_dtls['L_PAYMENTREQUEST_0_NUMBER0'] = 1; |
|
273 | + // Item quantity. |
|
274 | + $token_request_dtls['L_PAYMENTREQUEST_0_QTY0'] = 1; |
|
275 | + // Digital item is sold. |
|
276 | + $token_request_dtls['L_PAYMENTREQUEST_0_ITEMCATEGORY0'] = 'Physical'; |
|
277 | + // Item's sales S/H and tax amount. |
|
278 | + $token_request_dtls['PAYMENTREQUEST_0_ITEMAMT'] = $this->format_currency($payment->amount()); |
|
279 | + $token_request_dtls['PAYMENTREQUEST_0_TAXAMT'] = '0'; |
|
280 | + $token_request_dtls['PAYMENTREQUEST_0_SHIPPINGAMT'] = '0'; |
|
281 | + $token_request_dtls['PAYMENTREQUEST_0_HANDLINGAMT'] = '0'; |
|
282 | + } |
|
283 | + // Automatically filling out shipping and contact information. |
|
284 | + if ($this->_request_shipping_addr && $primary_attendee instanceof EEI_Attendee) { |
|
285 | + // If you do not pass the shipping address, PayPal obtains it from the buyer's account profile. |
|
286 | + $token_request_dtls['NOSHIPPING'] = '2'; |
|
287 | + $token_request_dtls['PAYMENTREQUEST_0_SHIPTOSTREET'] = $primary_attendee->address(); |
|
288 | + $token_request_dtls['PAYMENTREQUEST_0_SHIPTOSTREET2'] = $primary_attendee->address2(); |
|
289 | + $token_request_dtls['PAYMENTREQUEST_0_SHIPTOCITY'] = $primary_attendee->city(); |
|
290 | + $token_request_dtls['PAYMENTREQUEST_0_SHIPTOSTATE'] = $primary_attendee->state_abbrev(); |
|
291 | + $token_request_dtls['PAYMENTREQUEST_0_SHIPTOCOUNTRYCODE'] = $primary_attendee->country_ID(); |
|
292 | + $token_request_dtls['PAYMENTREQUEST_0_SHIPTOZIP'] = $primary_attendee->zip(); |
|
293 | + $token_request_dtls['PAYMENTREQUEST_0_EMAIL'] = $primary_attendee->email(); |
|
294 | + $token_request_dtls['PAYMENTREQUEST_0_SHIPTOPHONENUM'] = $primary_attendee->phone(); |
|
295 | + } elseif (! $this->_request_shipping_addr) { |
|
296 | + // Do not request shipping details on the PP Checkout page. |
|
297 | + $token_request_dtls['NOSHIPPING'] = '1'; |
|
298 | + $token_request_dtls['REQCONFIRMSHIPPING'] = '0'; |
|
299 | + } |
|
300 | + // Used a business/personal logo on the PayPal page. |
|
301 | + if (! empty($this->_image_url)) { |
|
302 | + $token_request_dtls['LOGOIMG'] = $this->_image_url; |
|
303 | + } |
|
304 | + $token_request_dtls = apply_filters( |
|
305 | + 'FHEE__EEG_Paypal_Express__set_redirection_info__arguments', |
|
306 | + $token_request_dtls, |
|
307 | + $this |
|
308 | + ); |
|
309 | + // Request PayPal token. |
|
310 | + $token_request_response = $this->_ppExpress_request($token_request_dtls, 'Payment Token', $payment); |
|
311 | + $token_rstatus = $this->_ppExpress_check_response($token_request_response); |
|
312 | + $response_args = (isset($token_rstatus['args']) && is_array($token_rstatus['args'])) |
|
313 | + ? $token_rstatus['args'] |
|
314 | + : array(); |
|
315 | + if ($token_rstatus['status']) { |
|
316 | + // We got the Token so we may continue with the payment and redirect the client. |
|
317 | + $payment->set_details($response_args); |
|
318 | + $gateway_url = $this->_debug_mode ? 'https://www.sandbox.paypal.com' : 'https://www.paypal.com'; |
|
319 | + $payment->set_redirect_url( |
|
320 | + $gateway_url |
|
321 | + . '/checkoutnow?useraction=commit&cmd=_express-checkout&token=' |
|
322 | + . $response_args['TOKEN'] |
|
323 | + ); |
|
324 | + } else { |
|
325 | + if (isset($response_args['L_ERRORCODE'])) { |
|
326 | + $payment->set_gateway_response($response_args['L_ERRORCODE'] . '; ' . $response_args['L_SHORTMESSAGE']); |
|
327 | + } else { |
|
328 | + $payment->set_gateway_response( |
|
329 | + esc_html__( |
|
330 | + 'Error occurred while trying to setup the Express Checkout.', |
|
331 | + 'event_espresso' |
|
332 | + ) |
|
333 | + ); |
|
334 | + } |
|
335 | + $payment->set_details($response_args); |
|
336 | + $payment->set_status($this->_pay_model->failed_status()); |
|
337 | + } |
|
338 | + return $payment; |
|
339 | + } |
|
340 | + |
|
341 | + |
|
342 | + |
|
343 | + /** |
|
344 | + * @param array $update_info { |
|
345 | + * @type string $gateway_txn_id |
|
346 | + * @type string status an EEMI_Payment status |
|
347 | + * } |
|
348 | + * @param EEI_Transaction $transaction |
|
349 | + * @return EEI_Payment |
|
350 | + */ |
|
351 | + public function handle_payment_update($update_info, $transaction) |
|
352 | + { |
|
353 | + $payment = $transaction instanceof EEI_Transaction ? $transaction->last_payment() : null; |
|
354 | + if ($payment instanceof EEI_Payment) { |
|
355 | + $this->log(array('Return from Authorization' => $update_info), $payment); |
|
356 | + $transaction = $payment->transaction(); |
|
357 | + if (! $transaction instanceof EEI_Transaction) { |
|
358 | + $payment->set_gateway_response( |
|
359 | + esc_html__( |
|
360 | + 'Could not process this payment because it has no associated transaction.', |
|
361 | + 'event_espresso' |
|
362 | + ) |
|
363 | + ); |
|
364 | + $payment->set_status($this->_pay_model->failed_status()); |
|
365 | + return $payment; |
|
366 | + } |
|
367 | + $primary_registrant = $transaction->primary_registration(); |
|
368 | + $payment_details = $payment->details(); |
|
369 | + // Check if we still have the token. |
|
370 | + if (! isset($payment_details['TOKEN']) || empty($payment_details['TOKEN'])) { |
|
371 | + $payment->set_status($this->_pay_model->failed_status()); |
|
372 | + return $payment; |
|
373 | + } |
|
374 | + $cdetails_request_dtls = array( |
|
375 | + 'METHOD' => 'GetExpressCheckoutDetails', |
|
376 | + 'TOKEN' => $payment_details['TOKEN'], |
|
377 | + ); |
|
378 | + // Request Customer Details. |
|
379 | + $cdetails_request_response = $this->_ppExpress_request( |
|
380 | + $cdetails_request_dtls, |
|
381 | + 'Customer Details', |
|
382 | + $payment |
|
383 | + ); |
|
384 | + $cdetails_rstatus = $this->_ppExpress_check_response($cdetails_request_response); |
|
385 | + $cdata_response_args = (isset($cdetails_rstatus['args']) && is_array($cdetails_rstatus['args'])) |
|
386 | + ? $cdetails_rstatus['args'] |
|
387 | + : array(); |
|
388 | + if ($cdetails_rstatus['status']) { |
|
389 | + // We got the PayerID so now we can Complete the transaction. |
|
390 | + $docheckout_request_dtls = array( |
|
391 | + 'METHOD' => 'DoExpressCheckoutPayment', |
|
392 | + 'PAYERID' => $cdata_response_args['PAYERID'], |
|
393 | + 'TOKEN' => $payment_details['TOKEN'], |
|
394 | + 'PAYMENTREQUEST_0_PAYMENTACTION' => 'Sale', |
|
395 | + 'PAYMENTREQUEST_0_AMT' => $payment->amount(), |
|
396 | + 'PAYMENTREQUEST_0_CURRENCYCODE' => $payment->currency_code(), |
|
397 | + //EE will blow up if you change this |
|
398 | + 'BUTTONSOURCE' => 'EventEspresso_SP', |
|
399 | + ); |
|
400 | + // Payment Checkout/Capture. |
|
401 | + $docheckout_request_response = $this->_ppExpress_request( |
|
402 | + $docheckout_request_dtls, |
|
403 | + 'Do Payment', |
|
404 | + $payment |
|
405 | + ); |
|
406 | + $docheckout_rstatus = $this->_ppExpress_check_response($docheckout_request_response); |
|
407 | + $docheckout_response_args = (isset($docheckout_rstatus['args']) && is_array($docheckout_rstatus['args'])) |
|
408 | + ? $docheckout_rstatus['args'] |
|
409 | + : array(); |
|
410 | + if ($docheckout_rstatus['status']) { |
|
411 | + // All is well, payment approved. |
|
412 | + $primary_registration_code = $primary_registrant instanceof EE_Registration ? |
|
413 | + $primary_registrant->reg_code() |
|
414 | + : ''; |
|
415 | + $payment->set_extra_accntng($primary_registration_code); |
|
416 | + $payment->set_amount(isset($docheckout_response_args['PAYMENTINFO_0_AMT']) |
|
417 | + ? (float)$docheckout_response_args['PAYMENTINFO_0_AMT'] |
|
418 | + : 0); |
|
419 | + $payment->set_txn_id_chq_nmbr(isset($docheckout_response_args['PAYMENTINFO_0_TRANSACTIONID']) |
|
420 | + ? $docheckout_response_args['PAYMENTINFO_0_TRANSACTIONID'] |
|
421 | + : null); |
|
422 | + $payment->set_details($cdata_response_args); |
|
423 | + $payment->set_gateway_response(isset($docheckout_response_args['PAYMENTINFO_0_ACK']) |
|
424 | + ? $docheckout_response_args['PAYMENTINFO_0_ACK'] |
|
425 | + : ''); |
|
426 | + $payment->set_status($this->_pay_model->approved_status()); |
|
427 | + } else { |
|
428 | + if (isset($docheckout_response_args['L_ERRORCODE'])) { |
|
429 | + $payment->set_gateway_response( |
|
430 | + $docheckout_response_args['L_ERRORCODE'] |
|
431 | + . '; ' |
|
432 | + . $docheckout_response_args['L_SHORTMESSAGE'] |
|
433 | + ); |
|
434 | + } else { |
|
435 | + $payment->set_gateway_response( |
|
436 | + esc_html__( |
|
437 | + 'Error occurred while trying to Capture the funds.', |
|
438 | + 'event_espresso' |
|
439 | + ) |
|
440 | + ); |
|
441 | + } |
|
442 | + $payment->set_details($docheckout_response_args); |
|
443 | + $payment->set_status($this->_pay_model->declined_status()); |
|
444 | + } |
|
445 | + } else { |
|
446 | + if (isset($cdata_response_args['L_ERRORCODE'])) { |
|
447 | + $payment->set_gateway_response( |
|
448 | + $cdata_response_args['L_ERRORCODE'] |
|
449 | + . '; ' |
|
450 | + . $cdata_response_args['L_SHORTMESSAGE'] |
|
451 | + ); |
|
452 | + } else { |
|
453 | + $payment->set_gateway_response( |
|
454 | + esc_html__( |
|
455 | + 'Error occurred while trying to get payment Details from PayPal.', |
|
456 | + 'event_espresso' |
|
457 | + ) |
|
458 | + ); |
|
459 | + } |
|
460 | + $payment->set_details($cdata_response_args); |
|
461 | + $payment->set_status($this->_pay_model->failed_status()); |
|
462 | + } |
|
463 | + } else { |
|
464 | + $payment->set_gateway_response( |
|
465 | + esc_html__( |
|
466 | + 'Error occurred while trying to process the payment.', |
|
467 | + 'event_espresso' |
|
468 | + ) |
|
469 | + ); |
|
470 | + $payment->set_status($this->_pay_model->failed_status()); |
|
471 | + } |
|
472 | + return $payment; |
|
473 | + } |
|
474 | + |
|
475 | + |
|
476 | + |
|
477 | + /** |
|
478 | + * Make the Express checkout request. |
|
479 | + * |
|
480 | + * @param array $request_params |
|
481 | + * @param string $request_text |
|
482 | + * @param EEI_Payment $payment |
|
483 | + * @return mixed |
|
484 | + */ |
|
485 | + public function _ppExpress_request($request_params, $request_text, $payment) |
|
486 | + { |
|
487 | + $request_dtls = array( |
|
488 | + 'VERSION' => '204.0', |
|
489 | + 'USER' => urlencode($this->_api_username), |
|
490 | + 'PWD' => urlencode($this->_api_password), |
|
491 | + 'SIGNATURE' => urlencode($this->_api_signature), |
|
492 | + ); |
|
493 | + $dtls = array_merge($request_dtls, $request_params); |
|
494 | + $this->_log_clean_request($dtls, $payment, $request_text . ' Request'); |
|
495 | + // Request Customer Details. |
|
496 | + $request_response = wp_remote_post( |
|
497 | + $this->_base_gateway_url, |
|
498 | + array( |
|
499 | + 'method' => 'POST', |
|
500 | + 'timeout' => 45, |
|
501 | + 'httpversion' => '1.1', |
|
502 | + 'cookies' => array(), |
|
503 | + 'headers' => array(), |
|
504 | + 'body' => http_build_query($dtls), |
|
505 | + ) |
|
506 | + ); |
|
507 | + // Log the response. |
|
508 | + $this->log(array($request_text . ' Response' => $request_response), $payment); |
|
509 | + return $request_response; |
|
510 | + } |
|
511 | + |
|
512 | + |
|
513 | + |
|
514 | + /** |
|
515 | + * Check the response status. |
|
516 | + * |
|
517 | + * @param mixed $request_response |
|
518 | + * @return array |
|
519 | + */ |
|
520 | + public function _ppExpress_check_response($request_response) |
|
521 | + { |
|
522 | + if (is_wp_error($request_response) || empty($request_response['body'])) { |
|
523 | + // If we got here then there was an error in this request. |
|
524 | + return array('status' => false, 'args' => $request_response); |
|
525 | + } |
|
526 | + $response_args = array(); |
|
527 | + parse_str(urldecode($request_response['body']), $response_args); |
|
528 | + if (! isset($response_args['ACK'])) { |
|
529 | + return array('status' => false, 'args' => $request_response); |
|
530 | + } |
|
531 | + if ( |
|
532 | + ( |
|
533 | + isset($response_args['PAYERID']) |
|
534 | + || isset($response_args['TOKEN']) |
|
535 | + || isset($response_args['PAYMENTINFO_0_TRANSACTIONID']) |
|
536 | + || (isset($response_args['PAYMENTSTATUS']) && $response_args['PAYMENTSTATUS'] === 'Completed') |
|
537 | + ) |
|
538 | + && in_array($response_args['ACK'], array('Success', 'SuccessWithWarning'), true) |
|
539 | + ) { |
|
540 | + // Response status OK, return response parameters for further processing. |
|
541 | + return array('status' => true, 'args' => $response_args); |
|
542 | + } |
|
543 | + $errors = $this->_get_errors($response_args); |
|
544 | + return array('status' => false, 'args' => $errors); |
|
545 | + } |
|
546 | + |
|
547 | + |
|
548 | + |
|
549 | + /** |
|
550 | + * Log a "Cleared" request. |
|
551 | + * |
|
552 | + * @param array $request |
|
553 | + * @param EEI_Payment $payment |
|
554 | + * @param string $info |
|
555 | + * @return void |
|
556 | + */ |
|
557 | + private function _log_clean_request($request, $payment, $info) |
|
558 | + { |
|
559 | + $cleaned_request_data = $request; |
|
560 | + unset($cleaned_request_data['PWD'], $cleaned_request_data['USER'], $cleaned_request_data['SIGNATURE']); |
|
561 | + $this->log(array($info => $cleaned_request_data), $payment); |
|
562 | + } |
|
563 | + |
|
564 | + |
|
565 | + |
|
566 | + /** |
|
567 | + * Get error from the response data. |
|
568 | + * |
|
569 | + * @param array $data_array |
|
570 | + * @return array |
|
571 | + */ |
|
572 | + private function _get_errors($data_array) |
|
573 | + { |
|
574 | + $errors = array(); |
|
575 | + $n = 0; |
|
576 | + while (isset($data_array["L_ERRORCODE{$n}"])) { |
|
577 | + $l_error_code = isset($data_array["L_ERRORCODE{$n}"]) |
|
578 | + ? $data_array["L_ERRORCODE{$n}"] |
|
579 | + : ''; |
|
580 | + $l_severity_code = isset($data_array["L_SEVERITYCODE{$n}"]) |
|
581 | + ? $data_array["L_SEVERITYCODE{$n}"] |
|
582 | + : ''; |
|
583 | + $l_short_message = isset($data_array["L_SHORTMESSAGE{$n}"]) |
|
584 | + ? $data_array["L_SHORTMESSAGE{$n}"] |
|
585 | + : ''; |
|
586 | + $l_long_message = isset($data_array["L_LONGMESSAGE{$n}"]) |
|
587 | + ? $data_array["L_LONGMESSAGE{$n}"] |
|
588 | + : ''; |
|
589 | + if ($n === 0) { |
|
590 | + $errors = array( |
|
591 | + 'L_ERRORCODE' => $l_error_code, |
|
592 | + 'L_SHORTMESSAGE' => $l_short_message, |
|
593 | + 'L_LONGMESSAGE' => $l_long_message, |
|
594 | + 'L_SEVERITYCODE' => $l_severity_code, |
|
595 | + ); |
|
596 | + } else { |
|
597 | + $errors['L_ERRORCODE'] .= ', ' . $l_error_code; |
|
598 | + $errors['L_SHORTMESSAGE'] .= ', ' . $l_short_message; |
|
599 | + $errors['L_LONGMESSAGE'] .= ', ' . $l_long_message; |
|
600 | + $errors['L_SEVERITYCODE'] .= ', ' . $l_severity_code; |
|
601 | + } |
|
602 | + $n++; |
|
603 | + } |
|
604 | + return $errors; |
|
605 | + } |
|
606 | 606 | |
607 | 607 | } |
608 | 608 | // End of file EEG_Paypal_Express.gateway.php |
@@ -1,4 +1,4 @@ discard block |
||
1 | -<?php if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
1 | +<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
2 | 2 | exit('NO direct script access allowed'); |
3 | 3 | } |
4 | 4 | |
@@ -130,7 +130,7 @@ discard block |
||
130 | 130 | $notify_url = null, |
131 | 131 | $cancel_url = null |
132 | 132 | ) { |
133 | - if (! $payment instanceof EEI_Payment) { |
|
133 | + if ( ! $payment instanceof EEI_Payment) { |
|
134 | 134 | $payment->set_gateway_response( |
135 | 135 | esc_html__( |
136 | 136 | 'Error. No associated payment was found.', |
@@ -141,7 +141,7 @@ discard block |
||
141 | 141 | return $payment; |
142 | 142 | } |
143 | 143 | $transaction = $payment->transaction(); |
144 | - if (! $transaction instanceof EEI_Transaction) { |
|
144 | + if ( ! $transaction instanceof EEI_Transaction) { |
|
145 | 145 | $payment->set_gateway_response( |
146 | 146 | esc_html__( |
147 | 147 | 'Could not process this payment because it has no associated transaction.', |
@@ -194,25 +194,25 @@ discard block |
||
194 | 194 | $line_item_quantity = 1; |
195 | 195 | } |
196 | 196 | // Item Name. |
197 | - $token_request_dtls['L_PAYMENTREQUEST_0_NAME' . $item_num] = substr( |
|
197 | + $token_request_dtls['L_PAYMENTREQUEST_0_NAME'.$item_num] = substr( |
|
198 | 198 | $this->_format_line_item_name($line_item, $payment), |
199 | 199 | 0, |
200 | 200 | 127 |
201 | 201 | ); |
202 | 202 | // Item description. |
203 | - $token_request_dtls['L_PAYMENTREQUEST_0_DESC' . $item_num] = substr( |
|
203 | + $token_request_dtls['L_PAYMENTREQUEST_0_DESC'.$item_num] = substr( |
|
204 | 204 | $this->_format_line_item_desc($line_item, $payment), |
205 | 205 | 0, |
206 | 206 | 127 |
207 | 207 | ); |
208 | 208 | // Cost of individual item. |
209 | - $token_request_dtls['L_PAYMENTREQUEST_0_AMT' . $item_num] = $this->format_currency($unit_price); |
|
209 | + $token_request_dtls['L_PAYMENTREQUEST_0_AMT'.$item_num] = $this->format_currency($unit_price); |
|
210 | 210 | // Item Number. |
211 | - $token_request_dtls['L_PAYMENTREQUEST_0_NUMBER' . $item_num] = $item_num + 1; |
|
211 | + $token_request_dtls['L_PAYMENTREQUEST_0_NUMBER'.$item_num] = $item_num + 1; |
|
212 | 212 | // Item quantity. |
213 | - $token_request_dtls['L_PAYMENTREQUEST_0_QTY' . $item_num] = $line_item_quantity; |
|
213 | + $token_request_dtls['L_PAYMENTREQUEST_0_QTY'.$item_num] = $line_item_quantity; |
|
214 | 214 | // Digital item is sold. |
215 | - $token_request_dtls['L_PAYMENTREQUEST_0_ITEMCATEGORY' . $item_num] = 'Physical'; |
|
215 | + $token_request_dtls['L_PAYMENTREQUEST_0_ITEMCATEGORY'.$item_num] = 'Physical'; |
|
216 | 216 | $itemized_sum += $line_item->total(); |
217 | 217 | ++$item_num; |
218 | 218 | } |
@@ -230,7 +230,7 @@ discard block |
||
230 | 230 | // add the difference as an extra line item. |
231 | 231 | if ($this->_money->compare_floats($itemized_sum_diff_from_txn_total, 0, '!=')) { |
232 | 232 | // Item Name. |
233 | - $token_request_dtls['L_PAYMENTREQUEST_0_NAME' . $item_num] = substr( |
|
233 | + $token_request_dtls['L_PAYMENTREQUEST_0_NAME'.$item_num] = substr( |
|
234 | 234 | esc_html__( |
235 | 235 | 'Other (promotion/surcharge/cancellation)', |
236 | 236 | 'event_espresso' |
@@ -239,17 +239,17 @@ discard block |
||
239 | 239 | 127 |
240 | 240 | ); |
241 | 241 | // Item description. |
242 | - $token_request_dtls['L_PAYMENTREQUEST_0_DESC' . $item_num] = ''; |
|
242 | + $token_request_dtls['L_PAYMENTREQUEST_0_DESC'.$item_num] = ''; |
|
243 | 243 | // Cost of individual item. |
244 | - $token_request_dtls['L_PAYMENTREQUEST_0_AMT' . $item_num] = $this->format_currency( |
|
244 | + $token_request_dtls['L_PAYMENTREQUEST_0_AMT'.$item_num] = $this->format_currency( |
|
245 | 245 | $itemized_sum_diff_from_txn_total |
246 | 246 | ); |
247 | 247 | // Item Number. |
248 | - $token_request_dtls['L_PAYMENTREQUEST_0_NUMBER' . $item_num] = $item_num + 1; |
|
248 | + $token_request_dtls['L_PAYMENTREQUEST_0_NUMBER'.$item_num] = $item_num + 1; |
|
249 | 249 | // Item quantity. |
250 | - $token_request_dtls['L_PAYMENTREQUEST_0_QTY' . $item_num] = 1; |
|
250 | + $token_request_dtls['L_PAYMENTREQUEST_0_QTY'.$item_num] = 1; |
|
251 | 251 | // Digital item is sold. |
252 | - $token_request_dtls['L_PAYMENTREQUEST_0_ITEMCATEGORY' . $item_num] = 'Physical'; |
|
252 | + $token_request_dtls['L_PAYMENTREQUEST_0_ITEMCATEGORY'.$item_num] = 'Physical'; |
|
253 | 253 | $item_num++; |
254 | 254 | } |
255 | 255 | } else { |
@@ -292,13 +292,13 @@ discard block |
||
292 | 292 | $token_request_dtls['PAYMENTREQUEST_0_SHIPTOZIP'] = $primary_attendee->zip(); |
293 | 293 | $token_request_dtls['PAYMENTREQUEST_0_EMAIL'] = $primary_attendee->email(); |
294 | 294 | $token_request_dtls['PAYMENTREQUEST_0_SHIPTOPHONENUM'] = $primary_attendee->phone(); |
295 | - } elseif (! $this->_request_shipping_addr) { |
|
295 | + } elseif ( ! $this->_request_shipping_addr) { |
|
296 | 296 | // Do not request shipping details on the PP Checkout page. |
297 | 297 | $token_request_dtls['NOSHIPPING'] = '1'; |
298 | 298 | $token_request_dtls['REQCONFIRMSHIPPING'] = '0'; |
299 | 299 | } |
300 | 300 | // Used a business/personal logo on the PayPal page. |
301 | - if (! empty($this->_image_url)) { |
|
301 | + if ( ! empty($this->_image_url)) { |
|
302 | 302 | $token_request_dtls['LOGOIMG'] = $this->_image_url; |
303 | 303 | } |
304 | 304 | $token_request_dtls = apply_filters( |
@@ -323,7 +323,7 @@ discard block |
||
323 | 323 | ); |
324 | 324 | } else { |
325 | 325 | if (isset($response_args['L_ERRORCODE'])) { |
326 | - $payment->set_gateway_response($response_args['L_ERRORCODE'] . '; ' . $response_args['L_SHORTMESSAGE']); |
|
326 | + $payment->set_gateway_response($response_args['L_ERRORCODE'].'; '.$response_args['L_SHORTMESSAGE']); |
|
327 | 327 | } else { |
328 | 328 | $payment->set_gateway_response( |
329 | 329 | esc_html__( |
@@ -354,7 +354,7 @@ discard block |
||
354 | 354 | if ($payment instanceof EEI_Payment) { |
355 | 355 | $this->log(array('Return from Authorization' => $update_info), $payment); |
356 | 356 | $transaction = $payment->transaction(); |
357 | - if (! $transaction instanceof EEI_Transaction) { |
|
357 | + if ( ! $transaction instanceof EEI_Transaction) { |
|
358 | 358 | $payment->set_gateway_response( |
359 | 359 | esc_html__( |
360 | 360 | 'Could not process this payment because it has no associated transaction.', |
@@ -367,7 +367,7 @@ discard block |
||
367 | 367 | $primary_registrant = $transaction->primary_registration(); |
368 | 368 | $payment_details = $payment->details(); |
369 | 369 | // Check if we still have the token. |
370 | - if (! isset($payment_details['TOKEN']) || empty($payment_details['TOKEN'])) { |
|
370 | + if ( ! isset($payment_details['TOKEN']) || empty($payment_details['TOKEN'])) { |
|
371 | 371 | $payment->set_status($this->_pay_model->failed_status()); |
372 | 372 | return $payment; |
373 | 373 | } |
@@ -414,7 +414,7 @@ discard block |
||
414 | 414 | : ''; |
415 | 415 | $payment->set_extra_accntng($primary_registration_code); |
416 | 416 | $payment->set_amount(isset($docheckout_response_args['PAYMENTINFO_0_AMT']) |
417 | - ? (float)$docheckout_response_args['PAYMENTINFO_0_AMT'] |
|
417 | + ? (float) $docheckout_response_args['PAYMENTINFO_0_AMT'] |
|
418 | 418 | : 0); |
419 | 419 | $payment->set_txn_id_chq_nmbr(isset($docheckout_response_args['PAYMENTINFO_0_TRANSACTIONID']) |
420 | 420 | ? $docheckout_response_args['PAYMENTINFO_0_TRANSACTIONID'] |
@@ -491,7 +491,7 @@ discard block |
||
491 | 491 | 'SIGNATURE' => urlencode($this->_api_signature), |
492 | 492 | ); |
493 | 493 | $dtls = array_merge($request_dtls, $request_params); |
494 | - $this->_log_clean_request($dtls, $payment, $request_text . ' Request'); |
|
494 | + $this->_log_clean_request($dtls, $payment, $request_text.' Request'); |
|
495 | 495 | // Request Customer Details. |
496 | 496 | $request_response = wp_remote_post( |
497 | 497 | $this->_base_gateway_url, |
@@ -505,7 +505,7 @@ discard block |
||
505 | 505 | ) |
506 | 506 | ); |
507 | 507 | // Log the response. |
508 | - $this->log(array($request_text . ' Response' => $request_response), $payment); |
|
508 | + $this->log(array($request_text.' Response' => $request_response), $payment); |
|
509 | 509 | return $request_response; |
510 | 510 | } |
511 | 511 | |
@@ -525,7 +525,7 @@ discard block |
||
525 | 525 | } |
526 | 526 | $response_args = array(); |
527 | 527 | parse_str(urldecode($request_response['body']), $response_args); |
528 | - if (! isset($response_args['ACK'])) { |
|
528 | + if ( ! isset($response_args['ACK'])) { |
|
529 | 529 | return array('status' => false, 'args' => $request_response); |
530 | 530 | } |
531 | 531 | if ( |
@@ -594,10 +594,10 @@ discard block |
||
594 | 594 | 'L_SEVERITYCODE' => $l_severity_code, |
595 | 595 | ); |
596 | 596 | } else { |
597 | - $errors['L_ERRORCODE'] .= ', ' . $l_error_code; |
|
598 | - $errors['L_SHORTMESSAGE'] .= ', ' . $l_short_message; |
|
599 | - $errors['L_LONGMESSAGE'] .= ', ' . $l_long_message; |
|
600 | - $errors['L_SEVERITYCODE'] .= ', ' . $l_severity_code; |
|
597 | + $errors['L_ERRORCODE'] .= ', '.$l_error_code; |
|
598 | + $errors['L_SHORTMESSAGE'] .= ', '.$l_short_message; |
|
599 | + $errors['L_LONGMESSAGE'] .= ', '.$l_long_message; |
|
600 | + $errors['L_SEVERITYCODE'] .= ', '.$l_severity_code; |
|
601 | 601 | } |
602 | 602 | $n++; |
603 | 603 | } |
@@ -226,7 +226,7 @@ discard block |
||
226 | 226 | |
227 | 227 | |
228 | 228 | /** |
229 | - * @return array or FALSE |
|
229 | + * @return boolean|null or FALSE |
|
230 | 230 | * @throws EE_Error |
231 | 231 | */ |
232 | 232 | public function process_ticket_selections() |
@@ -238,7 +238,7 @@ discard block |
||
238 | 238 | |
239 | 239 | |
240 | 240 | /** |
241 | - * @return string |
|
241 | + * @return false|null |
|
242 | 242 | */ |
243 | 243 | public static function cancel_ticket_selections() |
244 | 244 | { |
@@ -20,462 +20,462 @@ |
||
20 | 20 | class EED_Ticket_Selector extends EED_Module |
21 | 21 | { |
22 | 22 | |
23 | - /** |
|
24 | - * @var DisplayTicketSelector $ticket_selector |
|
25 | - */ |
|
26 | - private static $ticket_selector; |
|
27 | - |
|
28 | - /** |
|
29 | - * @var TicketSelectorIframeEmbedButton $iframe_embed_button |
|
30 | - */ |
|
31 | - private static $iframe_embed_button; |
|
32 | - |
|
33 | - |
|
34 | - |
|
35 | - /** |
|
36 | - * @return EED_Module|EED_Ticket_Selector |
|
37 | - */ |
|
38 | - public static function instance() |
|
39 | - { |
|
40 | - return parent::get_instance(__CLASS__); |
|
41 | - } |
|
42 | - |
|
43 | - |
|
44 | - |
|
45 | - /** |
|
46 | - * @return void |
|
47 | - */ |
|
48 | - protected function set_config() |
|
49 | - { |
|
50 | - $this->set_config_section('template_settings'); |
|
51 | - $this->set_config_class('EE_Ticket_Selector_Config'); |
|
52 | - $this->set_config_name('EED_Ticket_Selector'); |
|
53 | - } |
|
54 | - |
|
55 | - |
|
56 | - |
|
57 | - /** |
|
58 | - * set_hooks - for hooking into EE Core, other modules, etc |
|
59 | - * |
|
60 | - * @return void |
|
61 | - */ |
|
62 | - public static function set_hooks() |
|
63 | - { |
|
64 | - // routing |
|
65 | - EE_Config::register_route( |
|
66 | - 'iframe', |
|
67 | - 'EED_Ticket_Selector', |
|
68 | - 'ticket_selector_iframe', |
|
69 | - 'ticket_selector' |
|
70 | - ); |
|
71 | - EE_Config::register_route( |
|
72 | - 'process_ticket_selections', |
|
73 | - 'EED_Ticket_Selector', |
|
74 | - 'process_ticket_selections' |
|
75 | - ); |
|
76 | - EE_Config::register_route( |
|
77 | - 'cancel_ticket_selections', |
|
78 | - 'EED_Ticket_Selector', |
|
79 | - 'cancel_ticket_selections' |
|
80 | - ); |
|
81 | - add_action('wp_loaded', array('EED_Ticket_Selector', 'set_definitions'), 2); |
|
82 | - add_action('AHEE_event_details_header_bottom', array('EED_Ticket_Selector', 'display_ticket_selector'), 10, 1); |
|
83 | - add_action('wp_enqueue_scripts', array('EED_Ticket_Selector', 'translate_js_strings'), 0); |
|
84 | - add_action('wp_enqueue_scripts', array('EED_Ticket_Selector', 'load_tckt_slctr_assets'), 10); |
|
85 | - EED_Ticket_Selector::loadIframeAssets(); |
|
86 | - } |
|
87 | - |
|
88 | - |
|
89 | - |
|
90 | - /** |
|
91 | - * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
92 | - * |
|
93 | - * @return void |
|
94 | - */ |
|
95 | - public static function set_hooks_admin() |
|
96 | - { |
|
97 | - // hook into the end of the \EE_Admin_Page::_load_page_dependencies() |
|
98 | - // to load assets for "espresso_events" page on the "edit" route (action) |
|
99 | - add_action( |
|
100 | - 'FHEE__EE_Admin_Page___load_page_dependencies__after_load__espresso_events__edit', |
|
101 | - array('EED_Ticket_Selector', 'ticket_selector_iframe_embed_button'), |
|
102 | - 10 |
|
103 | - ); |
|
104 | - /** |
|
105 | - * Make sure assets for the ticket selector are loaded on the espresso registrations route so admin side |
|
106 | - * registrations work. |
|
107 | - */ |
|
108 | - add_action( |
|
109 | - 'FHEE__EE_Admin_Page___load_page_dependencies__after_load__espresso_registrations__new_registration', |
|
110 | - array('EED_Ticket_Selector', 'set_definitions'), |
|
111 | - 10 |
|
112 | - ); |
|
113 | - } |
|
114 | - |
|
115 | - |
|
116 | - |
|
117 | - /** |
|
118 | - * set_definitions |
|
119 | - * |
|
120 | - * @return void |
|
121 | - * @throws InvalidArgumentException |
|
122 | - * @throws InvalidDataTypeException |
|
123 | - * @throws InvalidInterfaceException |
|
124 | - */ |
|
125 | - public static function set_definitions() |
|
126 | - { |
|
127 | - // don't do this twice |
|
128 | - if (defined('TICKET_SELECTOR_ASSETS_URL')) { |
|
129 | - return; |
|
130 | - } |
|
131 | - define('TICKET_SELECTOR_ASSETS_URL', plugin_dir_url(__FILE__) . 'assets' . DS); |
|
132 | - define( |
|
133 | - 'TICKET_SELECTOR_TEMPLATES_PATH', |
|
134 | - str_replace('\\', DS, plugin_dir_path(__FILE__)) . 'templates' . DS |
|
135 | - ); |
|
136 | - //if config is not set, initialize |
|
137 | - if ( |
|
138 | - ! EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector instanceof EE_Ticket_Selector_Config |
|
139 | - ) { |
|
140 | - EED_Ticket_Selector::instance()->set_config(); |
|
141 | - EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector = EED_Ticket_Selector::instance()->config(); |
|
142 | - } |
|
143 | - } |
|
144 | - |
|
145 | - |
|
146 | - |
|
147 | - /** |
|
148 | - * @return DisplayTicketSelector |
|
149 | - */ |
|
150 | - public static function ticketSelector() |
|
151 | - { |
|
152 | - if (! EED_Ticket_Selector::$ticket_selector instanceof DisplayTicketSelector) { |
|
153 | - EED_Ticket_Selector::$ticket_selector = new DisplayTicketSelector(EED_Events_Archive::is_iframe()); |
|
154 | - } |
|
155 | - return EED_Ticket_Selector::$ticket_selector; |
|
156 | - } |
|
157 | - |
|
158 | - |
|
159 | - /** |
|
160 | - * gets the ball rolling |
|
161 | - * |
|
162 | - * @param WP $WP |
|
163 | - * @return void |
|
164 | - */ |
|
165 | - public function run($WP) |
|
166 | - { |
|
167 | - } |
|
168 | - |
|
169 | - |
|
170 | - |
|
171 | - /** |
|
172 | - * @return TicketSelectorIframeEmbedButton |
|
173 | - */ |
|
174 | - public static function getIframeEmbedButton() |
|
175 | - { |
|
176 | - if (! self::$iframe_embed_button instanceof TicketSelectorIframeEmbedButton) { |
|
177 | - self::$iframe_embed_button = new TicketSelectorIframeEmbedButton(); |
|
178 | - } |
|
179 | - return self::$iframe_embed_button; |
|
180 | - } |
|
181 | - |
|
182 | - |
|
183 | - |
|
184 | - /** |
|
185 | - * ticket_selector_iframe_embed_button |
|
186 | - * |
|
187 | - * @return void |
|
188 | - * @throws EE_Error |
|
189 | - */ |
|
190 | - public static function ticket_selector_iframe_embed_button() |
|
191 | - { |
|
192 | - $iframe_embed_button = EED_Ticket_Selector::getIframeEmbedButton(); |
|
193 | - $iframe_embed_button->addEventEditorIframeEmbedButton(); |
|
194 | - } |
|
195 | - |
|
196 | - |
|
197 | - |
|
198 | - /** |
|
199 | - * ticket_selector_iframe |
|
200 | - * |
|
201 | - * @return void |
|
202 | - * @throws DomainException |
|
203 | - * @throws EE_Error |
|
204 | - */ |
|
205 | - public function ticket_selector_iframe() |
|
206 | - { |
|
207 | - $ticket_selector_iframe = new TicketSelectorIframe(); |
|
208 | - $ticket_selector_iframe->display(); |
|
209 | - } |
|
210 | - |
|
211 | - |
|
212 | - |
|
213 | - /** |
|
214 | - * creates buttons for selecting number of attendees for an event |
|
215 | - * |
|
216 | - * @param WP_Post|int $event |
|
217 | - * @param bool $view_details |
|
218 | - * @return string |
|
219 | - * @throws EE_Error |
|
220 | - */ |
|
221 | - public static function display_ticket_selector($event = null, $view_details = false) |
|
222 | - { |
|
223 | - return EED_Ticket_Selector::ticketSelector()->display($event, $view_details); |
|
224 | - } |
|
225 | - |
|
226 | - |
|
227 | - |
|
228 | - /** |
|
229 | - * @return array or FALSE |
|
230 | - * @throws EE_Error |
|
231 | - */ |
|
232 | - public function process_ticket_selections() |
|
233 | - { |
|
234 | - $form = new ProcessTicketSelector(); |
|
235 | - return $form->processTicketSelections(); |
|
236 | - } |
|
237 | - |
|
238 | - |
|
239 | - |
|
240 | - /** |
|
241 | - * @return string |
|
242 | - */ |
|
243 | - public static function cancel_ticket_selections() |
|
244 | - { |
|
245 | - $form = new ProcessTicketSelector(); |
|
246 | - return $form->cancelTicketSelections(); |
|
247 | - } |
|
248 | - |
|
249 | - |
|
250 | - |
|
251 | - /** |
|
252 | - * @return void |
|
253 | - */ |
|
254 | - public static function translate_js_strings() |
|
255 | - { |
|
256 | - EE_Registry::$i18n_js_strings['please_select_date_filter_notice'] = esc_html__( |
|
257 | - 'please select a datetime', |
|
258 | - 'event_espresso' |
|
259 | - ); |
|
260 | - } |
|
261 | - |
|
262 | - |
|
263 | - |
|
264 | - /** |
|
265 | - * @return void |
|
266 | - */ |
|
267 | - public static function load_tckt_slctr_assets() |
|
268 | - { |
|
269 | - if (apply_filters('FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', false)) { |
|
270 | - // add some style |
|
271 | - wp_register_style( |
|
272 | - 'ticket_selector', |
|
273 | - TICKET_SELECTOR_ASSETS_URL . 'ticket_selector.css', |
|
274 | - array(), |
|
275 | - EVENT_ESPRESSO_VERSION |
|
276 | - ); |
|
277 | - wp_enqueue_style('ticket_selector'); |
|
278 | - // make it dance |
|
279 | - wp_register_script( |
|
280 | - 'ticket_selector', |
|
281 | - TICKET_SELECTOR_ASSETS_URL . 'ticket_selector.js', |
|
282 | - array('espresso_core'), |
|
283 | - EVENT_ESPRESSO_VERSION, |
|
284 | - true |
|
285 | - ); |
|
286 | - wp_enqueue_script('ticket_selector'); |
|
287 | - require_once EE_LIBRARIES |
|
288 | - . 'form_sections/strategies/display/EE_Checkbox_Dropdown_Selector_Display_Strategy.strategy.php'; |
|
289 | - \EE_Checkbox_Dropdown_Selector_Display_Strategy::enqueue_styles_and_scripts(); |
|
290 | - } |
|
291 | - } |
|
292 | - |
|
293 | - |
|
294 | - |
|
295 | - /** |
|
296 | - * @return void |
|
297 | - */ |
|
298 | - public static function loadIframeAssets() |
|
299 | - { |
|
300 | - // for event lists |
|
301 | - add_filter( |
|
302 | - 'FHEE__EventEspresso_modules_events_archive_EventsArchiveIframe__display__css', |
|
303 | - array('EED_Ticket_Selector', 'iframeCss') |
|
304 | - ); |
|
305 | - add_filter( |
|
306 | - 'FHEE__EventEspresso_modules_events_archive_EventsArchiveIframe__display__js', |
|
307 | - array('EED_Ticket_Selector', 'iframeJs') |
|
308 | - ); |
|
309 | - // for ticket selectors |
|
310 | - add_filter( |
|
311 | - 'FHEE__EED_Ticket_Selector__ticket_selector_iframe__css', |
|
312 | - array('EED_Ticket_Selector', 'iframeCss') |
|
313 | - ); |
|
314 | - add_filter( |
|
315 | - 'FHEE__EED_Ticket_Selector__ticket_selector_iframe__js', |
|
316 | - array('EED_Ticket_Selector', 'iframeJs') |
|
317 | - ); |
|
318 | - } |
|
319 | - |
|
320 | - |
|
321 | - |
|
322 | - /** |
|
323 | - * Informs the rest of the forms system what CSS and JS is needed to display the input |
|
324 | - * |
|
325 | - * @param array $iframe_css |
|
326 | - * @return array |
|
327 | - */ |
|
328 | - public static function iframeCss(array $iframe_css) |
|
329 | - { |
|
330 | - $iframe_css['ticket_selector'] = TICKET_SELECTOR_ASSETS_URL . 'ticket_selector.css'; |
|
331 | - return $iframe_css; |
|
332 | - } |
|
333 | - |
|
334 | - |
|
335 | - |
|
336 | - /** |
|
337 | - * Informs the rest of the forms system what CSS and JS is needed to display the input |
|
338 | - * |
|
339 | - * @param array $iframe_js |
|
340 | - * @return array |
|
341 | - */ |
|
342 | - public static function iframeJs(array $iframe_js) |
|
343 | - { |
|
344 | - $iframe_js['ticket_selector'] = TICKET_SELECTOR_ASSETS_URL . 'ticket_selector.js'; |
|
345 | - return $iframe_js; |
|
346 | - } |
|
347 | - |
|
348 | - |
|
349 | - /****************************** DEPRECATED ******************************/ |
|
350 | - |
|
351 | - |
|
352 | - |
|
353 | - /** |
|
354 | - * @deprecated |
|
355 | - * @return string |
|
356 | - * @throws EE_Error |
|
357 | - */ |
|
358 | - public static function display_view_details_btn() |
|
359 | - { |
|
360 | - // todo add doing_it_wrong() notice during next major version |
|
361 | - return EED_Ticket_Selector::ticketSelector()->displayViewDetailsButton(); |
|
362 | - } |
|
363 | - |
|
364 | - |
|
365 | - |
|
366 | - /** |
|
367 | - * @deprecated |
|
368 | - * @return string |
|
369 | - * @throws EE_Error |
|
370 | - */ |
|
371 | - public static function display_ticket_selector_submit() |
|
372 | - { |
|
373 | - // todo add doing_it_wrong() notice during next major version |
|
374 | - return EED_Ticket_Selector::ticketSelector()->displaySubmitButton(); |
|
375 | - } |
|
376 | - |
|
377 | - |
|
378 | - |
|
379 | - /** |
|
380 | - * @deprecated |
|
381 | - * @param string $permalink_string |
|
382 | - * @param int $id |
|
383 | - * @param string $new_title |
|
384 | - * @param string $new_slug |
|
385 | - * @return string |
|
386 | - * @throws InvalidArgumentException |
|
387 | - * @throws InvalidDataTypeException |
|
388 | - * @throws InvalidInterfaceException |
|
389 | - */ |
|
390 | - public static function iframe_code_button($permalink_string, $id, $new_title = '', $new_slug = '') |
|
391 | - { |
|
392 | - // todo add doing_it_wrong() notice during next major version |
|
393 | - if ( |
|
394 | - EE_Registry::instance()->REQ->get('page') === 'espresso_events' |
|
395 | - && EE_Registry::instance()->REQ->get('action') === 'edit' |
|
396 | - ) { |
|
397 | - $iframe_embed_button = EED_Ticket_Selector::getIframeEmbedButton(); |
|
398 | - $iframe_embed_button->addEventEditorIframeEmbedButton(); |
|
399 | - } |
|
400 | - return ''; |
|
401 | - } |
|
402 | - |
|
403 | - |
|
404 | - |
|
405 | - /** |
|
406 | - * @deprecated |
|
407 | - * @param int $ID |
|
408 | - * @param string $external_url |
|
409 | - * @return string |
|
410 | - */ |
|
411 | - public static function ticket_selector_form_open($ID = 0, $external_url = '') |
|
412 | - { |
|
413 | - // todo add doing_it_wrong() notice during next major version |
|
414 | - return EED_Ticket_Selector::ticketSelector()->formOpen($ID, $external_url); |
|
415 | - } |
|
416 | - |
|
417 | - |
|
418 | - |
|
419 | - /** |
|
420 | - * @deprecated |
|
421 | - * @return string |
|
422 | - */ |
|
423 | - public static function ticket_selector_form_close() |
|
424 | - { |
|
425 | - // todo add doing_it_wrong() notice during next major version |
|
426 | - return EED_Ticket_Selector::ticketSelector()->formClose(); |
|
427 | - } |
|
428 | - |
|
429 | - |
|
430 | - |
|
431 | - /** |
|
432 | - * @deprecated |
|
433 | - * @return string |
|
434 | - */ |
|
435 | - public static function no_tkt_slctr_end_dv() |
|
436 | - { |
|
437 | - // todo add doing_it_wrong() notice during next major version |
|
438 | - return EED_Ticket_Selector::ticketSelector()->ticketSelectorEndDiv(); |
|
439 | - } |
|
440 | - |
|
441 | - |
|
442 | - |
|
443 | - /** |
|
444 | - * @deprecated 4.9.13 |
|
445 | - * @return string |
|
446 | - */ |
|
447 | - public static function tkt_slctr_end_dv() |
|
448 | - { |
|
449 | - return EED_Ticket_Selector::ticketSelector()->clearTicketSelector(); |
|
450 | - } |
|
451 | - |
|
452 | - |
|
453 | - |
|
454 | - /** |
|
455 | - * @deprecated |
|
456 | - * @return string |
|
457 | - */ |
|
458 | - public static function clear_tkt_slctr() |
|
459 | - { |
|
460 | - return EED_Ticket_Selector::ticketSelector()->clearTicketSelector(); |
|
461 | - } |
|
462 | - |
|
463 | - |
|
464 | - |
|
465 | - /** |
|
466 | - * @deprecated |
|
467 | - */ |
|
468 | - public static function load_tckt_slctr_assets_admin() |
|
469 | - { |
|
470 | - // todo add doing_it_wrong() notice during next major version |
|
471 | - if ( |
|
472 | - EE_Registry::instance()->REQ->get('page') === 'espresso_events' |
|
473 | - && EE_Registry::instance()->REQ->get('action') === 'edit' |
|
474 | - ) { |
|
475 | - $iframe_embed_button = EED_Ticket_Selector::getIframeEmbedButton(); |
|
476 | - $iframe_embed_button->embedButtonAssets(); |
|
477 | - } |
|
478 | - } |
|
23 | + /** |
|
24 | + * @var DisplayTicketSelector $ticket_selector |
|
25 | + */ |
|
26 | + private static $ticket_selector; |
|
27 | + |
|
28 | + /** |
|
29 | + * @var TicketSelectorIframeEmbedButton $iframe_embed_button |
|
30 | + */ |
|
31 | + private static $iframe_embed_button; |
|
32 | + |
|
33 | + |
|
34 | + |
|
35 | + /** |
|
36 | + * @return EED_Module|EED_Ticket_Selector |
|
37 | + */ |
|
38 | + public static function instance() |
|
39 | + { |
|
40 | + return parent::get_instance(__CLASS__); |
|
41 | + } |
|
42 | + |
|
43 | + |
|
44 | + |
|
45 | + /** |
|
46 | + * @return void |
|
47 | + */ |
|
48 | + protected function set_config() |
|
49 | + { |
|
50 | + $this->set_config_section('template_settings'); |
|
51 | + $this->set_config_class('EE_Ticket_Selector_Config'); |
|
52 | + $this->set_config_name('EED_Ticket_Selector'); |
|
53 | + } |
|
54 | + |
|
55 | + |
|
56 | + |
|
57 | + /** |
|
58 | + * set_hooks - for hooking into EE Core, other modules, etc |
|
59 | + * |
|
60 | + * @return void |
|
61 | + */ |
|
62 | + public static function set_hooks() |
|
63 | + { |
|
64 | + // routing |
|
65 | + EE_Config::register_route( |
|
66 | + 'iframe', |
|
67 | + 'EED_Ticket_Selector', |
|
68 | + 'ticket_selector_iframe', |
|
69 | + 'ticket_selector' |
|
70 | + ); |
|
71 | + EE_Config::register_route( |
|
72 | + 'process_ticket_selections', |
|
73 | + 'EED_Ticket_Selector', |
|
74 | + 'process_ticket_selections' |
|
75 | + ); |
|
76 | + EE_Config::register_route( |
|
77 | + 'cancel_ticket_selections', |
|
78 | + 'EED_Ticket_Selector', |
|
79 | + 'cancel_ticket_selections' |
|
80 | + ); |
|
81 | + add_action('wp_loaded', array('EED_Ticket_Selector', 'set_definitions'), 2); |
|
82 | + add_action('AHEE_event_details_header_bottom', array('EED_Ticket_Selector', 'display_ticket_selector'), 10, 1); |
|
83 | + add_action('wp_enqueue_scripts', array('EED_Ticket_Selector', 'translate_js_strings'), 0); |
|
84 | + add_action('wp_enqueue_scripts', array('EED_Ticket_Selector', 'load_tckt_slctr_assets'), 10); |
|
85 | + EED_Ticket_Selector::loadIframeAssets(); |
|
86 | + } |
|
87 | + |
|
88 | + |
|
89 | + |
|
90 | + /** |
|
91 | + * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
92 | + * |
|
93 | + * @return void |
|
94 | + */ |
|
95 | + public static function set_hooks_admin() |
|
96 | + { |
|
97 | + // hook into the end of the \EE_Admin_Page::_load_page_dependencies() |
|
98 | + // to load assets for "espresso_events" page on the "edit" route (action) |
|
99 | + add_action( |
|
100 | + 'FHEE__EE_Admin_Page___load_page_dependencies__after_load__espresso_events__edit', |
|
101 | + array('EED_Ticket_Selector', 'ticket_selector_iframe_embed_button'), |
|
102 | + 10 |
|
103 | + ); |
|
104 | + /** |
|
105 | + * Make sure assets for the ticket selector are loaded on the espresso registrations route so admin side |
|
106 | + * registrations work. |
|
107 | + */ |
|
108 | + add_action( |
|
109 | + 'FHEE__EE_Admin_Page___load_page_dependencies__after_load__espresso_registrations__new_registration', |
|
110 | + array('EED_Ticket_Selector', 'set_definitions'), |
|
111 | + 10 |
|
112 | + ); |
|
113 | + } |
|
114 | + |
|
115 | + |
|
116 | + |
|
117 | + /** |
|
118 | + * set_definitions |
|
119 | + * |
|
120 | + * @return void |
|
121 | + * @throws InvalidArgumentException |
|
122 | + * @throws InvalidDataTypeException |
|
123 | + * @throws InvalidInterfaceException |
|
124 | + */ |
|
125 | + public static function set_definitions() |
|
126 | + { |
|
127 | + // don't do this twice |
|
128 | + if (defined('TICKET_SELECTOR_ASSETS_URL')) { |
|
129 | + return; |
|
130 | + } |
|
131 | + define('TICKET_SELECTOR_ASSETS_URL', plugin_dir_url(__FILE__) . 'assets' . DS); |
|
132 | + define( |
|
133 | + 'TICKET_SELECTOR_TEMPLATES_PATH', |
|
134 | + str_replace('\\', DS, plugin_dir_path(__FILE__)) . 'templates' . DS |
|
135 | + ); |
|
136 | + //if config is not set, initialize |
|
137 | + if ( |
|
138 | + ! EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector instanceof EE_Ticket_Selector_Config |
|
139 | + ) { |
|
140 | + EED_Ticket_Selector::instance()->set_config(); |
|
141 | + EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector = EED_Ticket_Selector::instance()->config(); |
|
142 | + } |
|
143 | + } |
|
144 | + |
|
145 | + |
|
146 | + |
|
147 | + /** |
|
148 | + * @return DisplayTicketSelector |
|
149 | + */ |
|
150 | + public static function ticketSelector() |
|
151 | + { |
|
152 | + if (! EED_Ticket_Selector::$ticket_selector instanceof DisplayTicketSelector) { |
|
153 | + EED_Ticket_Selector::$ticket_selector = new DisplayTicketSelector(EED_Events_Archive::is_iframe()); |
|
154 | + } |
|
155 | + return EED_Ticket_Selector::$ticket_selector; |
|
156 | + } |
|
157 | + |
|
158 | + |
|
159 | + /** |
|
160 | + * gets the ball rolling |
|
161 | + * |
|
162 | + * @param WP $WP |
|
163 | + * @return void |
|
164 | + */ |
|
165 | + public function run($WP) |
|
166 | + { |
|
167 | + } |
|
168 | + |
|
169 | + |
|
170 | + |
|
171 | + /** |
|
172 | + * @return TicketSelectorIframeEmbedButton |
|
173 | + */ |
|
174 | + public static function getIframeEmbedButton() |
|
175 | + { |
|
176 | + if (! self::$iframe_embed_button instanceof TicketSelectorIframeEmbedButton) { |
|
177 | + self::$iframe_embed_button = new TicketSelectorIframeEmbedButton(); |
|
178 | + } |
|
179 | + return self::$iframe_embed_button; |
|
180 | + } |
|
181 | + |
|
182 | + |
|
183 | + |
|
184 | + /** |
|
185 | + * ticket_selector_iframe_embed_button |
|
186 | + * |
|
187 | + * @return void |
|
188 | + * @throws EE_Error |
|
189 | + */ |
|
190 | + public static function ticket_selector_iframe_embed_button() |
|
191 | + { |
|
192 | + $iframe_embed_button = EED_Ticket_Selector::getIframeEmbedButton(); |
|
193 | + $iframe_embed_button->addEventEditorIframeEmbedButton(); |
|
194 | + } |
|
195 | + |
|
196 | + |
|
197 | + |
|
198 | + /** |
|
199 | + * ticket_selector_iframe |
|
200 | + * |
|
201 | + * @return void |
|
202 | + * @throws DomainException |
|
203 | + * @throws EE_Error |
|
204 | + */ |
|
205 | + public function ticket_selector_iframe() |
|
206 | + { |
|
207 | + $ticket_selector_iframe = new TicketSelectorIframe(); |
|
208 | + $ticket_selector_iframe->display(); |
|
209 | + } |
|
210 | + |
|
211 | + |
|
212 | + |
|
213 | + /** |
|
214 | + * creates buttons for selecting number of attendees for an event |
|
215 | + * |
|
216 | + * @param WP_Post|int $event |
|
217 | + * @param bool $view_details |
|
218 | + * @return string |
|
219 | + * @throws EE_Error |
|
220 | + */ |
|
221 | + public static function display_ticket_selector($event = null, $view_details = false) |
|
222 | + { |
|
223 | + return EED_Ticket_Selector::ticketSelector()->display($event, $view_details); |
|
224 | + } |
|
225 | + |
|
226 | + |
|
227 | + |
|
228 | + /** |
|
229 | + * @return array or FALSE |
|
230 | + * @throws EE_Error |
|
231 | + */ |
|
232 | + public function process_ticket_selections() |
|
233 | + { |
|
234 | + $form = new ProcessTicketSelector(); |
|
235 | + return $form->processTicketSelections(); |
|
236 | + } |
|
237 | + |
|
238 | + |
|
239 | + |
|
240 | + /** |
|
241 | + * @return string |
|
242 | + */ |
|
243 | + public static function cancel_ticket_selections() |
|
244 | + { |
|
245 | + $form = new ProcessTicketSelector(); |
|
246 | + return $form->cancelTicketSelections(); |
|
247 | + } |
|
248 | + |
|
249 | + |
|
250 | + |
|
251 | + /** |
|
252 | + * @return void |
|
253 | + */ |
|
254 | + public static function translate_js_strings() |
|
255 | + { |
|
256 | + EE_Registry::$i18n_js_strings['please_select_date_filter_notice'] = esc_html__( |
|
257 | + 'please select a datetime', |
|
258 | + 'event_espresso' |
|
259 | + ); |
|
260 | + } |
|
261 | + |
|
262 | + |
|
263 | + |
|
264 | + /** |
|
265 | + * @return void |
|
266 | + */ |
|
267 | + public static function load_tckt_slctr_assets() |
|
268 | + { |
|
269 | + if (apply_filters('FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', false)) { |
|
270 | + // add some style |
|
271 | + wp_register_style( |
|
272 | + 'ticket_selector', |
|
273 | + TICKET_SELECTOR_ASSETS_URL . 'ticket_selector.css', |
|
274 | + array(), |
|
275 | + EVENT_ESPRESSO_VERSION |
|
276 | + ); |
|
277 | + wp_enqueue_style('ticket_selector'); |
|
278 | + // make it dance |
|
279 | + wp_register_script( |
|
280 | + 'ticket_selector', |
|
281 | + TICKET_SELECTOR_ASSETS_URL . 'ticket_selector.js', |
|
282 | + array('espresso_core'), |
|
283 | + EVENT_ESPRESSO_VERSION, |
|
284 | + true |
|
285 | + ); |
|
286 | + wp_enqueue_script('ticket_selector'); |
|
287 | + require_once EE_LIBRARIES |
|
288 | + . 'form_sections/strategies/display/EE_Checkbox_Dropdown_Selector_Display_Strategy.strategy.php'; |
|
289 | + \EE_Checkbox_Dropdown_Selector_Display_Strategy::enqueue_styles_and_scripts(); |
|
290 | + } |
|
291 | + } |
|
292 | + |
|
293 | + |
|
294 | + |
|
295 | + /** |
|
296 | + * @return void |
|
297 | + */ |
|
298 | + public static function loadIframeAssets() |
|
299 | + { |
|
300 | + // for event lists |
|
301 | + add_filter( |
|
302 | + 'FHEE__EventEspresso_modules_events_archive_EventsArchiveIframe__display__css', |
|
303 | + array('EED_Ticket_Selector', 'iframeCss') |
|
304 | + ); |
|
305 | + add_filter( |
|
306 | + 'FHEE__EventEspresso_modules_events_archive_EventsArchiveIframe__display__js', |
|
307 | + array('EED_Ticket_Selector', 'iframeJs') |
|
308 | + ); |
|
309 | + // for ticket selectors |
|
310 | + add_filter( |
|
311 | + 'FHEE__EED_Ticket_Selector__ticket_selector_iframe__css', |
|
312 | + array('EED_Ticket_Selector', 'iframeCss') |
|
313 | + ); |
|
314 | + add_filter( |
|
315 | + 'FHEE__EED_Ticket_Selector__ticket_selector_iframe__js', |
|
316 | + array('EED_Ticket_Selector', 'iframeJs') |
|
317 | + ); |
|
318 | + } |
|
319 | + |
|
320 | + |
|
321 | + |
|
322 | + /** |
|
323 | + * Informs the rest of the forms system what CSS and JS is needed to display the input |
|
324 | + * |
|
325 | + * @param array $iframe_css |
|
326 | + * @return array |
|
327 | + */ |
|
328 | + public static function iframeCss(array $iframe_css) |
|
329 | + { |
|
330 | + $iframe_css['ticket_selector'] = TICKET_SELECTOR_ASSETS_URL . 'ticket_selector.css'; |
|
331 | + return $iframe_css; |
|
332 | + } |
|
333 | + |
|
334 | + |
|
335 | + |
|
336 | + /** |
|
337 | + * Informs the rest of the forms system what CSS and JS is needed to display the input |
|
338 | + * |
|
339 | + * @param array $iframe_js |
|
340 | + * @return array |
|
341 | + */ |
|
342 | + public static function iframeJs(array $iframe_js) |
|
343 | + { |
|
344 | + $iframe_js['ticket_selector'] = TICKET_SELECTOR_ASSETS_URL . 'ticket_selector.js'; |
|
345 | + return $iframe_js; |
|
346 | + } |
|
347 | + |
|
348 | + |
|
349 | + /****************************** DEPRECATED ******************************/ |
|
350 | + |
|
351 | + |
|
352 | + |
|
353 | + /** |
|
354 | + * @deprecated |
|
355 | + * @return string |
|
356 | + * @throws EE_Error |
|
357 | + */ |
|
358 | + public static function display_view_details_btn() |
|
359 | + { |
|
360 | + // todo add doing_it_wrong() notice during next major version |
|
361 | + return EED_Ticket_Selector::ticketSelector()->displayViewDetailsButton(); |
|
362 | + } |
|
363 | + |
|
364 | + |
|
365 | + |
|
366 | + /** |
|
367 | + * @deprecated |
|
368 | + * @return string |
|
369 | + * @throws EE_Error |
|
370 | + */ |
|
371 | + public static function display_ticket_selector_submit() |
|
372 | + { |
|
373 | + // todo add doing_it_wrong() notice during next major version |
|
374 | + return EED_Ticket_Selector::ticketSelector()->displaySubmitButton(); |
|
375 | + } |
|
376 | + |
|
377 | + |
|
378 | + |
|
379 | + /** |
|
380 | + * @deprecated |
|
381 | + * @param string $permalink_string |
|
382 | + * @param int $id |
|
383 | + * @param string $new_title |
|
384 | + * @param string $new_slug |
|
385 | + * @return string |
|
386 | + * @throws InvalidArgumentException |
|
387 | + * @throws InvalidDataTypeException |
|
388 | + * @throws InvalidInterfaceException |
|
389 | + */ |
|
390 | + public static function iframe_code_button($permalink_string, $id, $new_title = '', $new_slug = '') |
|
391 | + { |
|
392 | + // todo add doing_it_wrong() notice during next major version |
|
393 | + if ( |
|
394 | + EE_Registry::instance()->REQ->get('page') === 'espresso_events' |
|
395 | + && EE_Registry::instance()->REQ->get('action') === 'edit' |
|
396 | + ) { |
|
397 | + $iframe_embed_button = EED_Ticket_Selector::getIframeEmbedButton(); |
|
398 | + $iframe_embed_button->addEventEditorIframeEmbedButton(); |
|
399 | + } |
|
400 | + return ''; |
|
401 | + } |
|
402 | + |
|
403 | + |
|
404 | + |
|
405 | + /** |
|
406 | + * @deprecated |
|
407 | + * @param int $ID |
|
408 | + * @param string $external_url |
|
409 | + * @return string |
|
410 | + */ |
|
411 | + public static function ticket_selector_form_open($ID = 0, $external_url = '') |
|
412 | + { |
|
413 | + // todo add doing_it_wrong() notice during next major version |
|
414 | + return EED_Ticket_Selector::ticketSelector()->formOpen($ID, $external_url); |
|
415 | + } |
|
416 | + |
|
417 | + |
|
418 | + |
|
419 | + /** |
|
420 | + * @deprecated |
|
421 | + * @return string |
|
422 | + */ |
|
423 | + public static function ticket_selector_form_close() |
|
424 | + { |
|
425 | + // todo add doing_it_wrong() notice during next major version |
|
426 | + return EED_Ticket_Selector::ticketSelector()->formClose(); |
|
427 | + } |
|
428 | + |
|
429 | + |
|
430 | + |
|
431 | + /** |
|
432 | + * @deprecated |
|
433 | + * @return string |
|
434 | + */ |
|
435 | + public static function no_tkt_slctr_end_dv() |
|
436 | + { |
|
437 | + // todo add doing_it_wrong() notice during next major version |
|
438 | + return EED_Ticket_Selector::ticketSelector()->ticketSelectorEndDiv(); |
|
439 | + } |
|
440 | + |
|
441 | + |
|
442 | + |
|
443 | + /** |
|
444 | + * @deprecated 4.9.13 |
|
445 | + * @return string |
|
446 | + */ |
|
447 | + public static function tkt_slctr_end_dv() |
|
448 | + { |
|
449 | + return EED_Ticket_Selector::ticketSelector()->clearTicketSelector(); |
|
450 | + } |
|
451 | + |
|
452 | + |
|
453 | + |
|
454 | + /** |
|
455 | + * @deprecated |
|
456 | + * @return string |
|
457 | + */ |
|
458 | + public static function clear_tkt_slctr() |
|
459 | + { |
|
460 | + return EED_Ticket_Selector::ticketSelector()->clearTicketSelector(); |
|
461 | + } |
|
462 | + |
|
463 | + |
|
464 | + |
|
465 | + /** |
|
466 | + * @deprecated |
|
467 | + */ |
|
468 | + public static function load_tckt_slctr_assets_admin() |
|
469 | + { |
|
470 | + // todo add doing_it_wrong() notice during next major version |
|
471 | + if ( |
|
472 | + EE_Registry::instance()->REQ->get('page') === 'espresso_events' |
|
473 | + && EE_Registry::instance()->REQ->get('action') === 'edit' |
|
474 | + ) { |
|
475 | + $iframe_embed_button = EED_Ticket_Selector::getIframeEmbedButton(); |
|
476 | + $iframe_embed_button->embedButtonAssets(); |
|
477 | + } |
|
478 | + } |
|
479 | 479 | |
480 | 480 | |
481 | 481 | } |
@@ -128,10 +128,10 @@ discard block |
||
128 | 128 | if (defined('TICKET_SELECTOR_ASSETS_URL')) { |
129 | 129 | return; |
130 | 130 | } |
131 | - define('TICKET_SELECTOR_ASSETS_URL', plugin_dir_url(__FILE__) . 'assets' . DS); |
|
131 | + define('TICKET_SELECTOR_ASSETS_URL', plugin_dir_url(__FILE__).'assets'.DS); |
|
132 | 132 | define( |
133 | 133 | 'TICKET_SELECTOR_TEMPLATES_PATH', |
134 | - str_replace('\\', DS, plugin_dir_path(__FILE__)) . 'templates' . DS |
|
134 | + str_replace('\\', DS, plugin_dir_path(__FILE__)).'templates'.DS |
|
135 | 135 | ); |
136 | 136 | //if config is not set, initialize |
137 | 137 | if ( |
@@ -149,7 +149,7 @@ discard block |
||
149 | 149 | */ |
150 | 150 | public static function ticketSelector() |
151 | 151 | { |
152 | - if (! EED_Ticket_Selector::$ticket_selector instanceof DisplayTicketSelector) { |
|
152 | + if ( ! EED_Ticket_Selector::$ticket_selector instanceof DisplayTicketSelector) { |
|
153 | 153 | EED_Ticket_Selector::$ticket_selector = new DisplayTicketSelector(EED_Events_Archive::is_iframe()); |
154 | 154 | } |
155 | 155 | return EED_Ticket_Selector::$ticket_selector; |
@@ -173,7 +173,7 @@ discard block |
||
173 | 173 | */ |
174 | 174 | public static function getIframeEmbedButton() |
175 | 175 | { |
176 | - if (! self::$iframe_embed_button instanceof TicketSelectorIframeEmbedButton) { |
|
176 | + if ( ! self::$iframe_embed_button instanceof TicketSelectorIframeEmbedButton) { |
|
177 | 177 | self::$iframe_embed_button = new TicketSelectorIframeEmbedButton(); |
178 | 178 | } |
179 | 179 | return self::$iframe_embed_button; |
@@ -270,7 +270,7 @@ discard block |
||
270 | 270 | // add some style |
271 | 271 | wp_register_style( |
272 | 272 | 'ticket_selector', |
273 | - TICKET_SELECTOR_ASSETS_URL . 'ticket_selector.css', |
|
273 | + TICKET_SELECTOR_ASSETS_URL.'ticket_selector.css', |
|
274 | 274 | array(), |
275 | 275 | EVENT_ESPRESSO_VERSION |
276 | 276 | ); |
@@ -278,7 +278,7 @@ discard block |
||
278 | 278 | // make it dance |
279 | 279 | wp_register_script( |
280 | 280 | 'ticket_selector', |
281 | - TICKET_SELECTOR_ASSETS_URL . 'ticket_selector.js', |
|
281 | + TICKET_SELECTOR_ASSETS_URL.'ticket_selector.js', |
|
282 | 282 | array('espresso_core'), |
283 | 283 | EVENT_ESPRESSO_VERSION, |
284 | 284 | true |
@@ -327,7 +327,7 @@ discard block |
||
327 | 327 | */ |
328 | 328 | public static function iframeCss(array $iframe_css) |
329 | 329 | { |
330 | - $iframe_css['ticket_selector'] = TICKET_SELECTOR_ASSETS_URL . 'ticket_selector.css'; |
|
330 | + $iframe_css['ticket_selector'] = TICKET_SELECTOR_ASSETS_URL.'ticket_selector.css'; |
|
331 | 331 | return $iframe_css; |
332 | 332 | } |
333 | 333 | |
@@ -341,7 +341,7 @@ discard block |
||
341 | 341 | */ |
342 | 342 | public static function iframeJs(array $iframe_js) |
343 | 343 | { |
344 | - $iframe_js['ticket_selector'] = TICKET_SELECTOR_ASSETS_URL . 'ticket_selector.js'; |
|
344 | + $iframe_js['ticket_selector'] = TICKET_SELECTOR_ASSETS_URL.'ticket_selector.js'; |
|
345 | 345 | return $iframe_js; |
346 | 346 | } |
347 | 347 |
@@ -36,743 +36,743 @@ |
||
36 | 36 | class DisplayTicketSelector |
37 | 37 | { |
38 | 38 | |
39 | - /** |
|
40 | - * event that ticket selector is being generated for |
|
41 | - * |
|
42 | - * @access protected |
|
43 | - * @var EE_Event $event |
|
44 | - */ |
|
45 | - protected $event; |
|
46 | - |
|
47 | - /** |
|
48 | - * Used to flag when the ticket selector is being called from an external iframe. |
|
49 | - * |
|
50 | - * @var bool $iframe |
|
51 | - */ |
|
52 | - protected $iframe = false; |
|
53 | - |
|
54 | - /** |
|
55 | - * max attendees that can register for event at one time |
|
56 | - * |
|
57 | - * @var int $max_attendees |
|
58 | - */ |
|
59 | - private $max_attendees = EE_INF; |
|
60 | - |
|
61 | - /** |
|
62 | - * @var string $date_format |
|
63 | - */ |
|
64 | - private $date_format; |
|
65 | - |
|
66 | - /** |
|
67 | - * @var string $time_format |
|
68 | - */ |
|
69 | - private $time_format; |
|
70 | - |
|
71 | - /** |
|
72 | - * @var boolean $display_full_ui |
|
73 | - */ |
|
74 | - private $display_full_ui; |
|
75 | - |
|
76 | - |
|
77 | - |
|
78 | - /** |
|
79 | - * DisplayTicketSelector constructor. |
|
80 | - * |
|
81 | - * @param bool $iframe |
|
82 | - */ |
|
83 | - public function __construct($iframe = false) |
|
84 | - { |
|
85 | - $this->iframe = $iframe; |
|
86 | - $this->date_format = apply_filters( |
|
87 | - 'FHEE__EED_Ticket_Selector__display_ticket_selector__date_format', |
|
88 | - get_option('date_format') |
|
89 | - ); |
|
90 | - $this->time_format = apply_filters( |
|
91 | - 'FHEE__EED_Ticket_Selector__display_ticket_selector__time_format', |
|
92 | - get_option('time_format') |
|
93 | - ); |
|
94 | - } |
|
95 | - |
|
96 | - |
|
97 | - /** |
|
98 | - * @return bool |
|
99 | - */ |
|
100 | - public function isIframe() |
|
101 | - { |
|
102 | - return $this->iframe; |
|
103 | - } |
|
104 | - |
|
105 | - |
|
106 | - |
|
107 | - /** |
|
108 | - * @param boolean $iframe |
|
109 | - */ |
|
110 | - public function setIframe($iframe = true) |
|
111 | - { |
|
112 | - $this->iframe = filter_var($iframe, FILTER_VALIDATE_BOOLEAN); |
|
113 | - } |
|
114 | - |
|
115 | - |
|
116 | - /** |
|
117 | - * finds and sets the \EE_Event object for use throughout class |
|
118 | - * |
|
119 | - * @param mixed $event |
|
120 | - * @return bool |
|
121 | - * @throws EE_Error |
|
122 | - * @throws InvalidDataTypeException |
|
123 | - * @throws InvalidInterfaceException |
|
124 | - * @throws InvalidArgumentException |
|
125 | - */ |
|
126 | - protected function setEvent($event = null) |
|
127 | - { |
|
128 | - if ($event === null) { |
|
129 | - global $post; |
|
130 | - $event = $post; |
|
131 | - } |
|
132 | - if ($event instanceof EE_Event) { |
|
133 | - $this->event = $event; |
|
134 | - } elseif ($event instanceof WP_Post) { |
|
135 | - if (isset($event->EE_Event) && $event->EE_Event instanceof EE_Event) { |
|
136 | - $this->event = $event->EE_Event; |
|
137 | - } elseif ($event->post_type === 'espresso_events') { |
|
138 | - $event->EE_Event = EEM_Event::instance()->instantiate_class_from_post_object($event); |
|
139 | - $this->event = $event->EE_Event; |
|
140 | - } |
|
141 | - } else { |
|
142 | - $user_msg = __('No Event object or an invalid Event object was supplied.', 'event_espresso'); |
|
143 | - $dev_msg = $user_msg . __( |
|
144 | - 'In order to generate a ticket selector, please ensure you are passing either an EE_Event object or a WP_Post object of the post type "espresso_event" to the EE_Ticket_Selector class constructor.', |
|
145 | - 'event_espresso' |
|
146 | - ); |
|
147 | - EE_Error::add_error($user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__); |
|
148 | - return false; |
|
149 | - } |
|
150 | - return true; |
|
151 | - } |
|
152 | - |
|
153 | - |
|
154 | - |
|
155 | - /** |
|
156 | - * @return int |
|
157 | - */ |
|
158 | - public function getMaxAttendees() |
|
159 | - { |
|
160 | - return $this->max_attendees; |
|
161 | - } |
|
162 | - |
|
163 | - |
|
164 | - |
|
165 | - /** |
|
166 | - * @param int $max_attendees |
|
167 | - */ |
|
168 | - public function setMaxAttendees($max_attendees) |
|
169 | - { |
|
170 | - $this->max_attendees = absint( |
|
171 | - apply_filters( |
|
172 | - 'FHEE__EE_Ticket_Selector__display_ticket_selector__max_tickets', |
|
173 | - $max_attendees |
|
174 | - ) |
|
175 | - ); |
|
176 | - } |
|
177 | - |
|
178 | - |
|
179 | - |
|
180 | - /** |
|
181 | - * Returns whether or not the full ticket selector should be shown or not. |
|
182 | - * Currently, it displays on the frontend (including ajax requests) but not the backend |
|
183 | - * |
|
184 | - * @return bool |
|
185 | - */ |
|
186 | - private function display_full_ui() |
|
187 | - { |
|
188 | - if ($this->display_full_ui === null) { |
|
189 | - $this->display_full_ui = ! is_admin() || (defined('DOING_AJAX') && DOING_AJAX); |
|
190 | - } |
|
191 | - return $this->display_full_ui; |
|
192 | - } |
|
193 | - |
|
194 | - |
|
195 | - /** |
|
196 | - * creates buttons for selecting number of attendees for an event |
|
197 | - * |
|
198 | - * @param WP_Post|int $event |
|
199 | - * @param bool $view_details |
|
200 | - * @return string |
|
201 | - * @throws EE_Error |
|
202 | - * @throws InvalidArgumentException |
|
203 | - * @throws InvalidDataTypeException |
|
204 | - * @throws InvalidInterfaceException |
|
205 | - */ |
|
206 | - public function display($event = null, $view_details = false) |
|
207 | - { |
|
208 | - // reset filter for displaying submit button |
|
209 | - remove_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true'); |
|
210 | - // poke and prod incoming event till it tells us what it is |
|
211 | - if (! $this->setEvent($event)) { |
|
212 | - return false; |
|
213 | - } |
|
214 | - // begin gathering template arguments by getting event status |
|
215 | - $template_args = array('event_status' => $this->event->get_active_status()); |
|
216 | - if ( |
|
217 | - $this->activeEventAndShowTicketSelector( |
|
218 | - $event, |
|
219 | - $template_args['event_status'], |
|
220 | - $view_details |
|
221 | - ) |
|
222 | - ) { |
|
223 | - return ! is_single() ? $this->displayViewDetailsButton() : ''; |
|
224 | - } |
|
225 | - // filter the maximum qty that can appear in the Ticket Selector qty dropdowns |
|
226 | - $this->setMaxAttendees($this->event->additional_limit()); |
|
227 | - if ($this->getMaxAttendees() < 1) { |
|
228 | - return $this->ticketSalesClosedMessage(); |
|
229 | - } |
|
230 | - // is the event expired ? |
|
231 | - $template_args['event_is_expired'] = $this->event->is_expired(); |
|
232 | - if ($template_args['event_is_expired']) { |
|
233 | - return $this->expiredEventMessage(); |
|
234 | - } |
|
235 | - // get all tickets for this event ordered by the datetime |
|
236 | - $tickets = $this->getTickets(); |
|
237 | - if (count($tickets) < 1) { |
|
238 | - return $this->noTicketAvailableMessage(); |
|
239 | - } |
|
240 | - // redirecting to another site for registration ?? |
|
241 | - $external_url = (string)$this->event->external_url(); |
|
242 | - // if redirecting to another site for registration, then we don't load the TS |
|
243 | - $ticket_selector = $external_url |
|
244 | - ? $this->externalEventRegistration() |
|
245 | - : $this->loadTicketSelector($tickets, $template_args); |
|
246 | - // now set up the form (but not for the admin) |
|
247 | - $ticket_selector = $this->display_full_ui() |
|
248 | - ? $this->formOpen($this->event->ID(), $external_url) . $ticket_selector |
|
249 | - : $ticket_selector; |
|
250 | - // submit button and form close tag |
|
251 | - $ticket_selector .= $this->display_full_ui() ? $this->displaySubmitButton($external_url) : ''; |
|
252 | - return $ticket_selector; |
|
253 | - } |
|
254 | - |
|
255 | - |
|
256 | - |
|
257 | - /** |
|
258 | - * displayTicketSelector |
|
259 | - * examines the event properties and determines whether a Ticket Selector should be displayed |
|
260 | - * |
|
261 | - * @param WP_Post|int $event |
|
262 | - * @param string $_event_active_status |
|
263 | - * @param bool $view_details |
|
264 | - * @return bool |
|
265 | - * @throws EE_Error |
|
266 | - */ |
|
267 | - protected function activeEventAndShowTicketSelector($event, $_event_active_status, $view_details) |
|
268 | - { |
|
269 | - $event_post = $this->event instanceof EE_Event ? $this->event->ID() : $event; |
|
270 | - return $this->display_full_ui() |
|
271 | - && ( |
|
272 | - ! $this->event->display_ticket_selector() |
|
273 | - || $view_details |
|
274 | - || post_password_required($event_post) |
|
275 | - || ( |
|
276 | - $_event_active_status !== EE_Datetime::active |
|
277 | - && $_event_active_status !== EE_Datetime::upcoming |
|
278 | - && $_event_active_status !== EE_Datetime::sold_out |
|
279 | - && ! ( |
|
280 | - $_event_active_status === EE_Datetime::inactive |
|
281 | - && is_user_logged_in() |
|
282 | - ) |
|
283 | - ) |
|
284 | - ); |
|
285 | - } |
|
286 | - |
|
287 | - |
|
288 | - |
|
289 | - /** |
|
290 | - * noTicketAvailableMessage |
|
291 | - * notice displayed if event is expired |
|
292 | - * |
|
293 | - * @return string |
|
294 | - * @throws EE_Error |
|
295 | - */ |
|
296 | - protected function expiredEventMessage() |
|
297 | - { |
|
298 | - return '<div class="ee-event-expired-notice"><span class="important-notice">' . esc_html__( |
|
299 | - 'We\'re sorry, but all tickets sales have ended because the event is expired.', |
|
300 | - 'event_espresso' |
|
301 | - ) . '</span></div><!-- .ee-event-expired-notice -->'; |
|
302 | - } |
|
303 | - |
|
304 | - |
|
305 | - |
|
306 | - /** |
|
307 | - * noTicketAvailableMessage |
|
308 | - * notice displayed if event has no more tickets available |
|
309 | - * |
|
310 | - * @return string |
|
311 | - * @throws EE_Error |
|
312 | - */ |
|
313 | - protected function noTicketAvailableMessage() |
|
314 | - { |
|
315 | - $no_ticket_available_msg = esc_html__('We\'re sorry, but all ticket sales have ended.', 'event_espresso'); |
|
316 | - if (current_user_can('edit_post', $this->event->ID())) { |
|
317 | - $no_ticket_available_msg .= sprintf( |
|
318 | - esc_html__( |
|
319 | - '%1$sNote to Event Admin:%2$sNo tickets were found for this event. This effectively turns off ticket sales. Please ensure that at least one ticket is available for if you want people to be able to register.%3$s(click to edit this event)%4$s', |
|
320 | - 'event_espresso' |
|
321 | - ), |
|
322 | - '<div class="ee-attention" style="text-align: left;"><b>', |
|
323 | - '</b><br />', |
|
324 | - '<span class="edit-link"><a class="post-edit-link" href="' |
|
325 | - . get_edit_post_link($this->event->ID()) |
|
326 | - . '">', |
|
327 | - '</a></span></div><!-- .ee-attention noTicketAvailableMessage -->' |
|
328 | - ); |
|
329 | - } |
|
330 | - return ' |
|
39 | + /** |
|
40 | + * event that ticket selector is being generated for |
|
41 | + * |
|
42 | + * @access protected |
|
43 | + * @var EE_Event $event |
|
44 | + */ |
|
45 | + protected $event; |
|
46 | + |
|
47 | + /** |
|
48 | + * Used to flag when the ticket selector is being called from an external iframe. |
|
49 | + * |
|
50 | + * @var bool $iframe |
|
51 | + */ |
|
52 | + protected $iframe = false; |
|
53 | + |
|
54 | + /** |
|
55 | + * max attendees that can register for event at one time |
|
56 | + * |
|
57 | + * @var int $max_attendees |
|
58 | + */ |
|
59 | + private $max_attendees = EE_INF; |
|
60 | + |
|
61 | + /** |
|
62 | + * @var string $date_format |
|
63 | + */ |
|
64 | + private $date_format; |
|
65 | + |
|
66 | + /** |
|
67 | + * @var string $time_format |
|
68 | + */ |
|
69 | + private $time_format; |
|
70 | + |
|
71 | + /** |
|
72 | + * @var boolean $display_full_ui |
|
73 | + */ |
|
74 | + private $display_full_ui; |
|
75 | + |
|
76 | + |
|
77 | + |
|
78 | + /** |
|
79 | + * DisplayTicketSelector constructor. |
|
80 | + * |
|
81 | + * @param bool $iframe |
|
82 | + */ |
|
83 | + public function __construct($iframe = false) |
|
84 | + { |
|
85 | + $this->iframe = $iframe; |
|
86 | + $this->date_format = apply_filters( |
|
87 | + 'FHEE__EED_Ticket_Selector__display_ticket_selector__date_format', |
|
88 | + get_option('date_format') |
|
89 | + ); |
|
90 | + $this->time_format = apply_filters( |
|
91 | + 'FHEE__EED_Ticket_Selector__display_ticket_selector__time_format', |
|
92 | + get_option('time_format') |
|
93 | + ); |
|
94 | + } |
|
95 | + |
|
96 | + |
|
97 | + /** |
|
98 | + * @return bool |
|
99 | + */ |
|
100 | + public function isIframe() |
|
101 | + { |
|
102 | + return $this->iframe; |
|
103 | + } |
|
104 | + |
|
105 | + |
|
106 | + |
|
107 | + /** |
|
108 | + * @param boolean $iframe |
|
109 | + */ |
|
110 | + public function setIframe($iframe = true) |
|
111 | + { |
|
112 | + $this->iframe = filter_var($iframe, FILTER_VALIDATE_BOOLEAN); |
|
113 | + } |
|
114 | + |
|
115 | + |
|
116 | + /** |
|
117 | + * finds and sets the \EE_Event object for use throughout class |
|
118 | + * |
|
119 | + * @param mixed $event |
|
120 | + * @return bool |
|
121 | + * @throws EE_Error |
|
122 | + * @throws InvalidDataTypeException |
|
123 | + * @throws InvalidInterfaceException |
|
124 | + * @throws InvalidArgumentException |
|
125 | + */ |
|
126 | + protected function setEvent($event = null) |
|
127 | + { |
|
128 | + if ($event === null) { |
|
129 | + global $post; |
|
130 | + $event = $post; |
|
131 | + } |
|
132 | + if ($event instanceof EE_Event) { |
|
133 | + $this->event = $event; |
|
134 | + } elseif ($event instanceof WP_Post) { |
|
135 | + if (isset($event->EE_Event) && $event->EE_Event instanceof EE_Event) { |
|
136 | + $this->event = $event->EE_Event; |
|
137 | + } elseif ($event->post_type === 'espresso_events') { |
|
138 | + $event->EE_Event = EEM_Event::instance()->instantiate_class_from_post_object($event); |
|
139 | + $this->event = $event->EE_Event; |
|
140 | + } |
|
141 | + } else { |
|
142 | + $user_msg = __('No Event object or an invalid Event object was supplied.', 'event_espresso'); |
|
143 | + $dev_msg = $user_msg . __( |
|
144 | + 'In order to generate a ticket selector, please ensure you are passing either an EE_Event object or a WP_Post object of the post type "espresso_event" to the EE_Ticket_Selector class constructor.', |
|
145 | + 'event_espresso' |
|
146 | + ); |
|
147 | + EE_Error::add_error($user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__); |
|
148 | + return false; |
|
149 | + } |
|
150 | + return true; |
|
151 | + } |
|
152 | + |
|
153 | + |
|
154 | + |
|
155 | + /** |
|
156 | + * @return int |
|
157 | + */ |
|
158 | + public function getMaxAttendees() |
|
159 | + { |
|
160 | + return $this->max_attendees; |
|
161 | + } |
|
162 | + |
|
163 | + |
|
164 | + |
|
165 | + /** |
|
166 | + * @param int $max_attendees |
|
167 | + */ |
|
168 | + public function setMaxAttendees($max_attendees) |
|
169 | + { |
|
170 | + $this->max_attendees = absint( |
|
171 | + apply_filters( |
|
172 | + 'FHEE__EE_Ticket_Selector__display_ticket_selector__max_tickets', |
|
173 | + $max_attendees |
|
174 | + ) |
|
175 | + ); |
|
176 | + } |
|
177 | + |
|
178 | + |
|
179 | + |
|
180 | + /** |
|
181 | + * Returns whether or not the full ticket selector should be shown or not. |
|
182 | + * Currently, it displays on the frontend (including ajax requests) but not the backend |
|
183 | + * |
|
184 | + * @return bool |
|
185 | + */ |
|
186 | + private function display_full_ui() |
|
187 | + { |
|
188 | + if ($this->display_full_ui === null) { |
|
189 | + $this->display_full_ui = ! is_admin() || (defined('DOING_AJAX') && DOING_AJAX); |
|
190 | + } |
|
191 | + return $this->display_full_ui; |
|
192 | + } |
|
193 | + |
|
194 | + |
|
195 | + /** |
|
196 | + * creates buttons for selecting number of attendees for an event |
|
197 | + * |
|
198 | + * @param WP_Post|int $event |
|
199 | + * @param bool $view_details |
|
200 | + * @return string |
|
201 | + * @throws EE_Error |
|
202 | + * @throws InvalidArgumentException |
|
203 | + * @throws InvalidDataTypeException |
|
204 | + * @throws InvalidInterfaceException |
|
205 | + */ |
|
206 | + public function display($event = null, $view_details = false) |
|
207 | + { |
|
208 | + // reset filter for displaying submit button |
|
209 | + remove_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true'); |
|
210 | + // poke and prod incoming event till it tells us what it is |
|
211 | + if (! $this->setEvent($event)) { |
|
212 | + return false; |
|
213 | + } |
|
214 | + // begin gathering template arguments by getting event status |
|
215 | + $template_args = array('event_status' => $this->event->get_active_status()); |
|
216 | + if ( |
|
217 | + $this->activeEventAndShowTicketSelector( |
|
218 | + $event, |
|
219 | + $template_args['event_status'], |
|
220 | + $view_details |
|
221 | + ) |
|
222 | + ) { |
|
223 | + return ! is_single() ? $this->displayViewDetailsButton() : ''; |
|
224 | + } |
|
225 | + // filter the maximum qty that can appear in the Ticket Selector qty dropdowns |
|
226 | + $this->setMaxAttendees($this->event->additional_limit()); |
|
227 | + if ($this->getMaxAttendees() < 1) { |
|
228 | + return $this->ticketSalesClosedMessage(); |
|
229 | + } |
|
230 | + // is the event expired ? |
|
231 | + $template_args['event_is_expired'] = $this->event->is_expired(); |
|
232 | + if ($template_args['event_is_expired']) { |
|
233 | + return $this->expiredEventMessage(); |
|
234 | + } |
|
235 | + // get all tickets for this event ordered by the datetime |
|
236 | + $tickets = $this->getTickets(); |
|
237 | + if (count($tickets) < 1) { |
|
238 | + return $this->noTicketAvailableMessage(); |
|
239 | + } |
|
240 | + // redirecting to another site for registration ?? |
|
241 | + $external_url = (string)$this->event->external_url(); |
|
242 | + // if redirecting to another site for registration, then we don't load the TS |
|
243 | + $ticket_selector = $external_url |
|
244 | + ? $this->externalEventRegistration() |
|
245 | + : $this->loadTicketSelector($tickets, $template_args); |
|
246 | + // now set up the form (but not for the admin) |
|
247 | + $ticket_selector = $this->display_full_ui() |
|
248 | + ? $this->formOpen($this->event->ID(), $external_url) . $ticket_selector |
|
249 | + : $ticket_selector; |
|
250 | + // submit button and form close tag |
|
251 | + $ticket_selector .= $this->display_full_ui() ? $this->displaySubmitButton($external_url) : ''; |
|
252 | + return $ticket_selector; |
|
253 | + } |
|
254 | + |
|
255 | + |
|
256 | + |
|
257 | + /** |
|
258 | + * displayTicketSelector |
|
259 | + * examines the event properties and determines whether a Ticket Selector should be displayed |
|
260 | + * |
|
261 | + * @param WP_Post|int $event |
|
262 | + * @param string $_event_active_status |
|
263 | + * @param bool $view_details |
|
264 | + * @return bool |
|
265 | + * @throws EE_Error |
|
266 | + */ |
|
267 | + protected function activeEventAndShowTicketSelector($event, $_event_active_status, $view_details) |
|
268 | + { |
|
269 | + $event_post = $this->event instanceof EE_Event ? $this->event->ID() : $event; |
|
270 | + return $this->display_full_ui() |
|
271 | + && ( |
|
272 | + ! $this->event->display_ticket_selector() |
|
273 | + || $view_details |
|
274 | + || post_password_required($event_post) |
|
275 | + || ( |
|
276 | + $_event_active_status !== EE_Datetime::active |
|
277 | + && $_event_active_status !== EE_Datetime::upcoming |
|
278 | + && $_event_active_status !== EE_Datetime::sold_out |
|
279 | + && ! ( |
|
280 | + $_event_active_status === EE_Datetime::inactive |
|
281 | + && is_user_logged_in() |
|
282 | + ) |
|
283 | + ) |
|
284 | + ); |
|
285 | + } |
|
286 | + |
|
287 | + |
|
288 | + |
|
289 | + /** |
|
290 | + * noTicketAvailableMessage |
|
291 | + * notice displayed if event is expired |
|
292 | + * |
|
293 | + * @return string |
|
294 | + * @throws EE_Error |
|
295 | + */ |
|
296 | + protected function expiredEventMessage() |
|
297 | + { |
|
298 | + return '<div class="ee-event-expired-notice"><span class="important-notice">' . esc_html__( |
|
299 | + 'We\'re sorry, but all tickets sales have ended because the event is expired.', |
|
300 | + 'event_espresso' |
|
301 | + ) . '</span></div><!-- .ee-event-expired-notice -->'; |
|
302 | + } |
|
303 | + |
|
304 | + |
|
305 | + |
|
306 | + /** |
|
307 | + * noTicketAvailableMessage |
|
308 | + * notice displayed if event has no more tickets available |
|
309 | + * |
|
310 | + * @return string |
|
311 | + * @throws EE_Error |
|
312 | + */ |
|
313 | + protected function noTicketAvailableMessage() |
|
314 | + { |
|
315 | + $no_ticket_available_msg = esc_html__('We\'re sorry, but all ticket sales have ended.', 'event_espresso'); |
|
316 | + if (current_user_can('edit_post', $this->event->ID())) { |
|
317 | + $no_ticket_available_msg .= sprintf( |
|
318 | + esc_html__( |
|
319 | + '%1$sNote to Event Admin:%2$sNo tickets were found for this event. This effectively turns off ticket sales. Please ensure that at least one ticket is available for if you want people to be able to register.%3$s(click to edit this event)%4$s', |
|
320 | + 'event_espresso' |
|
321 | + ), |
|
322 | + '<div class="ee-attention" style="text-align: left;"><b>', |
|
323 | + '</b><br />', |
|
324 | + '<span class="edit-link"><a class="post-edit-link" href="' |
|
325 | + . get_edit_post_link($this->event->ID()) |
|
326 | + . '">', |
|
327 | + '</a></span></div><!-- .ee-attention noTicketAvailableMessage -->' |
|
328 | + ); |
|
329 | + } |
|
330 | + return ' |
|
331 | 331 | <div class="ee-event-expired-notice"> |
332 | 332 | <span class="important-notice">' . $no_ticket_available_msg . '</span> |
333 | 333 | </div><!-- .ee-event-expired-notice -->'; |
334 | - } |
|
335 | - |
|
336 | - |
|
337 | - |
|
338 | - /** |
|
339 | - * ticketSalesClosed |
|
340 | - * notice displayed if event ticket sales are turned off |
|
341 | - * |
|
342 | - * @return string |
|
343 | - * @throws EE_Error |
|
344 | - */ |
|
345 | - protected function ticketSalesClosedMessage() |
|
346 | - { |
|
347 | - $sales_closed_msg = esc_html__( |
|
348 | - 'We\'re sorry, but ticket sales have been closed at this time. Please check back again later.', |
|
349 | - 'event_espresso' |
|
350 | - ); |
|
351 | - if (current_user_can('edit_post', $this->event->ID())) { |
|
352 | - $sales_closed_msg .= sprintf( |
|
353 | - esc_html__( |
|
354 | - '%sNote to Event Admin:%sThe "Maximum number of tickets allowed per order for this event" in the Event Registration Options has been set to "0". This effectively turns off ticket sales. %s(click to edit this event)%s', |
|
355 | - 'event_espresso' |
|
356 | - ), |
|
357 | - '<div class="ee-attention" style="text-align: left;"><b>', |
|
358 | - '</b><br />', |
|
359 | - '<span class="edit-link"><a class="post-edit-link" href="' |
|
360 | - . get_edit_post_link($this->event->ID()) |
|
361 | - . '">', |
|
362 | - '</a></span></div><!-- .ee-attention ticketSalesClosedMessage -->' |
|
363 | - ); |
|
364 | - } |
|
365 | - return '<p><span class="important-notice">' . $sales_closed_msg . '</span></p>'; |
|
366 | - } |
|
367 | - |
|
368 | - |
|
369 | - |
|
370 | - /** |
|
371 | - * getTickets |
|
372 | - * |
|
373 | - * @return \EE_Base_Class[]|\EE_Ticket[] |
|
374 | - * @throws EE_Error |
|
375 | - * @throws InvalidDataTypeException |
|
376 | - * @throws InvalidInterfaceException |
|
377 | - * @throws InvalidArgumentException |
|
378 | - */ |
|
379 | - protected function getTickets() |
|
380 | - { |
|
381 | - $ticket_query_args = array( |
|
382 | - array('Datetime.EVT_ID' => $this->event->ID()), |
|
383 | - 'order_by' => array( |
|
384 | - 'TKT_order' => 'ASC', |
|
385 | - 'TKT_required' => 'DESC', |
|
386 | - 'TKT_start_date' => 'ASC', |
|
387 | - 'TKT_end_date' => 'ASC', |
|
388 | - 'Datetime.DTT_EVT_start' => 'DESC', |
|
389 | - ), |
|
390 | - ); |
|
391 | - if ( |
|
392 | - ! ( |
|
393 | - EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector instanceof EE_Ticket_Selector_Config |
|
394 | - && EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector->show_expired_tickets |
|
395 | - ) |
|
396 | - ) { |
|
397 | - //use the correct applicable time query depending on what version of core is being run. |
|
398 | - $current_time = method_exists('EEM_Datetime', 'current_time_for_query') |
|
399 | - ? time() |
|
400 | - : current_time('timestamp'); |
|
401 | - $ticket_query_args[0]['TKT_end_date'] = array('>', $current_time); |
|
402 | - } |
|
403 | - return EEM_Ticket::instance()->get_all($ticket_query_args); |
|
404 | - } |
|
405 | - |
|
406 | - |
|
407 | - |
|
408 | - /** |
|
409 | - * loadTicketSelector |
|
410 | - * begins to assemble template arguments |
|
411 | - * and decides whether to load a "simple" ticket selector, or the standard |
|
412 | - * |
|
413 | - * @param \EE_Ticket[] $tickets |
|
414 | - * @param array $template_args |
|
415 | - * @return string |
|
416 | - * @throws EE_Error |
|
417 | - */ |
|
418 | - protected function loadTicketSelector(array $tickets, array $template_args) |
|
419 | - { |
|
420 | - $template_args['event'] = $this->event; |
|
421 | - $template_args['EVT_ID'] = $this->event->ID(); |
|
422 | - $template_args['event_is_expired'] = $this->event->is_expired(); |
|
423 | - $template_args['max_atndz'] = $this->getMaxAttendees(); |
|
424 | - $template_args['date_format'] = $this->date_format; |
|
425 | - $template_args['time_format'] = $this->time_format; |
|
426 | - /** |
|
427 | - * Filters the anchor ID used when redirecting to the Ticket Selector if no quantity selected |
|
428 | - * |
|
429 | - * @since 4.9.13 |
|
430 | - * @param string '#tkt-slctr-tbl-' . $EVT_ID The html ID to anchor to |
|
431 | - * @param int $EVT_ID The Event ID |
|
432 | - */ |
|
433 | - $template_args['anchor_id'] = apply_filters( |
|
434 | - 'FHEE__EE_Ticket_Selector__redirect_anchor_id', |
|
435 | - '#tkt-slctr-tbl-' . $this->event->ID(), |
|
436 | - $this->event->ID() |
|
437 | - ); |
|
438 | - $template_args['tickets'] = $tickets; |
|
439 | - $template_args['ticket_count'] = count($tickets); |
|
440 | - $ticket_selector = $this->simpleTicketSelector($tickets, $template_args); |
|
441 | - return $ticket_selector instanceof TicketSelectorSimple |
|
442 | - ? $ticket_selector |
|
443 | - : new TicketSelectorStandard( |
|
444 | - $this->event, |
|
445 | - $tickets, |
|
446 | - $this->getMaxAttendees(), |
|
447 | - $template_args, |
|
448 | - $this->date_format, |
|
449 | - $this->time_format |
|
450 | - ); |
|
451 | - } |
|
452 | - |
|
453 | - |
|
454 | - |
|
455 | - /** |
|
456 | - * simpleTicketSelector |
|
457 | - * there's one ticket, and max attendees is set to one, |
|
458 | - * so if the event is free, then this is a "simple" ticket selector |
|
459 | - * a.k.a. "Dude Where's my Ticket Selector?" |
|
460 | - * |
|
461 | - * @param \EE_Ticket[] $tickets |
|
462 | - * @param array $template_args |
|
463 | - * @return string |
|
464 | - * @throws EE_Error |
|
465 | - */ |
|
466 | - protected function simpleTicketSelector($tickets, array $template_args) |
|
467 | - { |
|
468 | - // if there is only ONE ticket with a max qty of ONE |
|
469 | - if (count($tickets) > 1 || $this->getMaxAttendees() !== 1) { |
|
470 | - return ''; |
|
471 | - } |
|
472 | - /** @var \EE_Ticket $ticket */ |
|
473 | - $ticket = reset($tickets); |
|
474 | - // if the ticket is free... then not much need for the ticket selector |
|
475 | - if ( |
|
476 | - apply_filters( |
|
477 | - 'FHEE__ticket_selector_chart_template__hide_ticket_selector', |
|
478 | - $ticket->is_free(), |
|
479 | - $this->event->ID() |
|
480 | - ) |
|
481 | - ) { |
|
482 | - return new TicketSelectorSimple( |
|
483 | - $this->event, |
|
484 | - $ticket, |
|
485 | - $this->getMaxAttendees(), |
|
486 | - $template_args |
|
487 | - ); |
|
488 | - } |
|
489 | - return ''; |
|
490 | - } |
|
491 | - |
|
492 | - |
|
493 | - |
|
494 | - /** |
|
495 | - * externalEventRegistration |
|
496 | - * |
|
497 | - * @return string |
|
498 | - */ |
|
499 | - public function externalEventRegistration() |
|
500 | - { |
|
501 | - // if not we still need to trigger the display of the submit button |
|
502 | - add_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true'); |
|
503 | - //display notice to admin that registration is external |
|
504 | - return $this->display_full_ui() |
|
505 | - ? esc_html__( |
|
506 | - 'Registration is at an external URL for this event.', |
|
507 | - 'event_espresso' |
|
508 | - ) |
|
509 | - : ''; |
|
510 | - } |
|
511 | - |
|
512 | - |
|
513 | - |
|
514 | - /** |
|
515 | - * formOpen |
|
516 | - * |
|
517 | - * @param int $ID |
|
518 | - * @param string $external_url |
|
519 | - * @return string |
|
520 | - */ |
|
521 | - public function formOpen($ID = 0, $external_url = '') |
|
522 | - { |
|
523 | - // if redirecting, we don't need any anything else |
|
524 | - if ($external_url) { |
|
525 | - $html = '<form method="GET" action="' . EEH_URL::refactor_url($external_url) . '"'; |
|
526 | - // open link in new window ? |
|
527 | - $html .= apply_filters( |
|
528 | - 'FHEE__EventEspresso_modules_ticket_selector_DisplayTicketSelector__formOpen__external_url_target_blank', |
|
529 | - $this->isIframe(), |
|
530 | - $this |
|
531 | - ) |
|
532 | - ? ' target="_blank"' |
|
533 | - : ''; |
|
534 | - $html .= '>'; |
|
535 | - $query_args = EEH_URL::get_query_string($external_url); |
|
536 | - foreach ((array)$query_args as $query_arg => $value) { |
|
537 | - $html .= '<input type="hidden" name="' . $query_arg . '" value="' . $value . '">'; |
|
538 | - } |
|
539 | - return $html; |
|
540 | - } |
|
541 | - // if there is no submit button, then don't start building a form |
|
542 | - // because the "View Details" button will build its own form |
|
543 | - if (! apply_filters('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', false)) { |
|
544 | - return ''; |
|
545 | - } |
|
546 | - $checkout_url = EEH_Event_View::event_link_url($ID); |
|
547 | - if (! $checkout_url) { |
|
548 | - EE_Error::add_error( |
|
549 | - esc_html__('The URL for the Event Details page could not be retrieved.', 'event_espresso'), |
|
550 | - __FILE__, |
|
551 | - __FUNCTION__, |
|
552 | - __LINE__ |
|
553 | - ); |
|
554 | - } |
|
555 | - // set no cache headers and constants |
|
556 | - EE_System::do_not_cache(); |
|
557 | - $extra_params = $this->iframe ? ' target="_blank"' : ''; |
|
558 | - $html = '<form method="POST" action="' . $checkout_url . '"' . $extra_params . '>'; |
|
559 | - $html .= '<input type="hidden" name="ee" value="process_ticket_selections">'; |
|
560 | - $html = apply_filters('FHEE__EE_Ticket_Selector__ticket_selector_form_open__html', $html, $this->event); |
|
561 | - return $html; |
|
562 | - } |
|
563 | - |
|
564 | - |
|
565 | - |
|
566 | - /** |
|
567 | - * displaySubmitButton |
|
568 | - * |
|
569 | - * @param string $external_url |
|
570 | - * @return string |
|
571 | - * @throws EE_Error |
|
572 | - */ |
|
573 | - public function displaySubmitButton($external_url = '') |
|
574 | - { |
|
575 | - $html = ''; |
|
576 | - if ($this->display_full_ui()) { |
|
577 | - // standard TS displayed with submit button, ie: "Register Now" |
|
578 | - if (apply_filters('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', false)) { |
|
579 | - $html .= $this->displayRegisterNowButton(); |
|
580 | - $html .= empty($external_url) |
|
581 | - ? $this->ticketSelectorEndDiv() |
|
582 | - : $this->clearTicketSelector(); |
|
583 | - $html .= '<br/>' . $this->formClose(); |
|
584 | - } elseif ($this->getMaxAttendees() === 1) { |
|
585 | - // its a "Dude Where's my Ticket Selector?" (DWMTS) type event (ie: $_max_atndz === 1) |
|
586 | - if ($this->event->is_sold_out()) { |
|
587 | - // then instead of a View Details or Submit button, just display a "Sold Out" message |
|
588 | - $html .= apply_filters( |
|
589 | - 'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__sold_out_msg', |
|
590 | - sprintf( |
|
591 | - __( |
|
592 | - '%1$s"%2$s" is currently sold out.%4$sPlease check back again later, as spots may become available.%3$s', |
|
593 | - 'event_espresso' |
|
594 | - ), |
|
595 | - '<p class="no-ticket-selector-msg clear-float">', |
|
596 | - $this->event->name(), |
|
597 | - '</p>', |
|
598 | - '<br />' |
|
599 | - ), |
|
600 | - $this->event |
|
601 | - ); |
|
602 | - if ( |
|
603 | - apply_filters( |
|
604 | - 'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__no_tickets_but_display_register_now_button', |
|
605 | - false, |
|
606 | - $this->event |
|
607 | - ) |
|
608 | - ) { |
|
609 | - $html .= $this->displayRegisterNowButton(); |
|
610 | - } |
|
611 | - // sold out DWMTS event, no TS, no submit or view details button, but has additional content |
|
612 | - $html .= $this->ticketSelectorEndDiv(); |
|
613 | - } elseif ( |
|
614 | - apply_filters('FHEE__EE_Ticket_Selector__hide_ticket_selector', false) |
|
615 | - && ! is_single() |
|
616 | - ) { |
|
617 | - // this is a "Dude Where's my Ticket Selector?" (DWMTS) type event, |
|
618 | - // but no tickets are available, so display event's "View Details" button. |
|
619 | - // it is being viewed via somewhere other than a single post |
|
620 | - $html .= $this->displayViewDetailsButton(true); |
|
621 | - } else { |
|
622 | - $html .= $this->ticketSelectorEndDiv(); |
|
623 | - } |
|
624 | - } elseif (is_archive()) { |
|
625 | - // event list, no tickets available so display event's "View Details" button |
|
626 | - $html .= $this->ticketSelectorEndDiv(); |
|
627 | - $html .= $this->displayViewDetailsButton(); |
|
628 | - } else { |
|
629 | - if ( |
|
630 | - apply_filters( |
|
631 | - 'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__no_tickets_but_display_register_now_button', |
|
632 | - false, |
|
633 | - $this->event |
|
634 | - ) |
|
635 | - ) { |
|
636 | - $html .= $this->displayRegisterNowButton(); |
|
637 | - } |
|
638 | - // no submit or view details button, and no additional content |
|
639 | - $html .= $this->ticketSelectorEndDiv(); |
|
640 | - } |
|
641 | - if (! $this->iframe && ! is_archive()) { |
|
642 | - $html .= EEH_Template::powered_by_event_espresso('', '', array('utm_content' => 'ticket_selector')); |
|
643 | - } |
|
644 | - } |
|
645 | - return apply_filters( |
|
646 | - 'FHEE__EventEspresso_modules_ticket_selector_DisplayTicketSelector__displaySubmitButton__html', |
|
647 | - $html, |
|
648 | - $this->event, |
|
649 | - $this |
|
650 | - ); |
|
651 | - } |
|
652 | - |
|
653 | - |
|
654 | - |
|
655 | - /** |
|
656 | - * @return string |
|
657 | - * @throws EE_Error |
|
658 | - */ |
|
659 | - public function displayRegisterNowButton() |
|
660 | - { |
|
661 | - $btn_text = apply_filters( |
|
662 | - 'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__btn_text', |
|
663 | - __('Register Now', 'event_espresso'), |
|
664 | - $this->event |
|
665 | - ); |
|
666 | - $external_url = $this->event->external_url(); |
|
667 | - $html = EEH_HTML::div( |
|
668 | - '', |
|
669 | - 'ticket-selector-submit-' . $this->event->ID() . '-btn-wrap', |
|
670 | - 'ticket-selector-submit-btn-wrap' |
|
671 | - ); |
|
672 | - $html .= '<input id="ticket-selector-submit-' . $this->event->ID() . '-btn"'; |
|
673 | - $html .= ' class="ticket-selector-submit-btn '; |
|
674 | - $html .= empty($external_url) ? 'ticket-selector-submit-ajax"' : '"'; |
|
675 | - $html .= ' type="submit" value="' . $btn_text . '" />'; |
|
676 | - $html .= EEH_HTML::divx() . '<!-- .ticket-selector-submit-btn-wrap -->'; |
|
677 | - $html .= apply_filters( |
|
678 | - 'FHEE__EE_Ticket_Selector__after_ticket_selector_submit', |
|
679 | - '', |
|
680 | - $this->event |
|
681 | - ); |
|
682 | - return $html; |
|
683 | - } |
|
684 | - |
|
685 | - |
|
686 | - /** |
|
687 | - * displayViewDetailsButton |
|
688 | - * |
|
689 | - * @param bool $DWMTS indicates a "Dude Where's my Ticket Selector?" (DWMTS) type event |
|
690 | - * (ie: $_max_atndz === 1) where there are no available tickets, |
|
691 | - * either because they are sold out, expired, or not yet on sale. |
|
692 | - * In this case, we need to close the form BEFORE adding any closing divs |
|
693 | - * @return string |
|
694 | - * @throws EE_Error |
|
695 | - */ |
|
696 | - public function displayViewDetailsButton($DWMTS = false) |
|
697 | - { |
|
698 | - if (! $this->event->get_permalink()) { |
|
699 | - EE_Error::add_error( |
|
700 | - esc_html__('The URL for the Event Details page could not be retrieved.', 'event_espresso'), |
|
701 | - __FILE__, |
|
702 | - __FUNCTION__, |
|
703 | - __LINE__ |
|
704 | - ); |
|
705 | - } |
|
706 | - $view_details_btn = '<form method="POST" action="'; |
|
707 | - $view_details_btn .= apply_filters( |
|
708 | - 'FHEE__EE_Ticket_Selector__display_view_details_btn__btn_url', |
|
709 | - $this->event->get_permalink(), |
|
710 | - $this->event |
|
711 | - ); |
|
712 | - $view_details_btn .= '"'; |
|
713 | - // open link in new window ? |
|
714 | - $view_details_btn .= apply_filters( |
|
715 | - 'FHEE__EventEspresso_modules_ticket_selector_DisplayTicketSelector__displayViewDetailsButton__url_target_blank', |
|
716 | - $this->isIframe(), |
|
717 | - $this |
|
718 | - ) |
|
719 | - ? ' target="_blank"' |
|
720 | - : ''; |
|
721 | - $view_details_btn .= '>'; |
|
722 | - $btn_text = apply_filters( |
|
723 | - 'FHEE__EE_Ticket_Selector__display_view_details_btn__btn_text', |
|
724 | - esc_html__('View Details', 'event_espresso'), |
|
725 | - $this->event |
|
726 | - ); |
|
727 | - $view_details_btn .= '<input id="ticket-selector-submit-' |
|
728 | - . $this->event->ID() |
|
729 | - . '-btn" class="ticket-selector-submit-btn view-details-btn" type="submit" value="' |
|
730 | - . $btn_text |
|
731 | - . '" />'; |
|
732 | - $view_details_btn .= apply_filters('FHEE__EE_Ticket_Selector__after_view_details_btn', '', $this->event); |
|
733 | - if ($DWMTS) { |
|
734 | - $view_details_btn .= $this->formClose(); |
|
735 | - $view_details_btn .= $this->ticketSelectorEndDiv(); |
|
736 | - $view_details_btn .= '<br/>'; |
|
737 | - } else { |
|
738 | - $view_details_btn .= $this->clearTicketSelector(); |
|
739 | - $view_details_btn .= '<br/>'; |
|
740 | - $view_details_btn .= $this->formClose(); |
|
741 | - } |
|
742 | - return $view_details_btn; |
|
743 | - } |
|
744 | - |
|
745 | - |
|
746 | - |
|
747 | - /** |
|
748 | - * @return string |
|
749 | - */ |
|
750 | - public function ticketSelectorEndDiv() |
|
751 | - { |
|
752 | - return $this->clearTicketSelector() . '</div><!-- ticketSelectorEndDiv -->'; |
|
753 | - } |
|
754 | - |
|
755 | - |
|
756 | - |
|
757 | - /** |
|
758 | - * @return string |
|
759 | - */ |
|
760 | - public function clearTicketSelector() |
|
761 | - { |
|
762 | - // standard TS displayed, appears after a "Register Now" or "view Details" button |
|
763 | - return '<div class="clear"></div><!-- clearTicketSelector -->'; |
|
764 | - } |
|
765 | - |
|
766 | - |
|
767 | - |
|
768 | - /** |
|
769 | - * @access public |
|
770 | - * @return string |
|
771 | - */ |
|
772 | - public function formClose() |
|
773 | - { |
|
774 | - return '</form>'; |
|
775 | - } |
|
334 | + } |
|
335 | + |
|
336 | + |
|
337 | + |
|
338 | + /** |
|
339 | + * ticketSalesClosed |
|
340 | + * notice displayed if event ticket sales are turned off |
|
341 | + * |
|
342 | + * @return string |
|
343 | + * @throws EE_Error |
|
344 | + */ |
|
345 | + protected function ticketSalesClosedMessage() |
|
346 | + { |
|
347 | + $sales_closed_msg = esc_html__( |
|
348 | + 'We\'re sorry, but ticket sales have been closed at this time. Please check back again later.', |
|
349 | + 'event_espresso' |
|
350 | + ); |
|
351 | + if (current_user_can('edit_post', $this->event->ID())) { |
|
352 | + $sales_closed_msg .= sprintf( |
|
353 | + esc_html__( |
|
354 | + '%sNote to Event Admin:%sThe "Maximum number of tickets allowed per order for this event" in the Event Registration Options has been set to "0". This effectively turns off ticket sales. %s(click to edit this event)%s', |
|
355 | + 'event_espresso' |
|
356 | + ), |
|
357 | + '<div class="ee-attention" style="text-align: left;"><b>', |
|
358 | + '</b><br />', |
|
359 | + '<span class="edit-link"><a class="post-edit-link" href="' |
|
360 | + . get_edit_post_link($this->event->ID()) |
|
361 | + . '">', |
|
362 | + '</a></span></div><!-- .ee-attention ticketSalesClosedMessage -->' |
|
363 | + ); |
|
364 | + } |
|
365 | + return '<p><span class="important-notice">' . $sales_closed_msg . '</span></p>'; |
|
366 | + } |
|
367 | + |
|
368 | + |
|
369 | + |
|
370 | + /** |
|
371 | + * getTickets |
|
372 | + * |
|
373 | + * @return \EE_Base_Class[]|\EE_Ticket[] |
|
374 | + * @throws EE_Error |
|
375 | + * @throws InvalidDataTypeException |
|
376 | + * @throws InvalidInterfaceException |
|
377 | + * @throws InvalidArgumentException |
|
378 | + */ |
|
379 | + protected function getTickets() |
|
380 | + { |
|
381 | + $ticket_query_args = array( |
|
382 | + array('Datetime.EVT_ID' => $this->event->ID()), |
|
383 | + 'order_by' => array( |
|
384 | + 'TKT_order' => 'ASC', |
|
385 | + 'TKT_required' => 'DESC', |
|
386 | + 'TKT_start_date' => 'ASC', |
|
387 | + 'TKT_end_date' => 'ASC', |
|
388 | + 'Datetime.DTT_EVT_start' => 'DESC', |
|
389 | + ), |
|
390 | + ); |
|
391 | + if ( |
|
392 | + ! ( |
|
393 | + EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector instanceof EE_Ticket_Selector_Config |
|
394 | + && EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector->show_expired_tickets |
|
395 | + ) |
|
396 | + ) { |
|
397 | + //use the correct applicable time query depending on what version of core is being run. |
|
398 | + $current_time = method_exists('EEM_Datetime', 'current_time_for_query') |
|
399 | + ? time() |
|
400 | + : current_time('timestamp'); |
|
401 | + $ticket_query_args[0]['TKT_end_date'] = array('>', $current_time); |
|
402 | + } |
|
403 | + return EEM_Ticket::instance()->get_all($ticket_query_args); |
|
404 | + } |
|
405 | + |
|
406 | + |
|
407 | + |
|
408 | + /** |
|
409 | + * loadTicketSelector |
|
410 | + * begins to assemble template arguments |
|
411 | + * and decides whether to load a "simple" ticket selector, or the standard |
|
412 | + * |
|
413 | + * @param \EE_Ticket[] $tickets |
|
414 | + * @param array $template_args |
|
415 | + * @return string |
|
416 | + * @throws EE_Error |
|
417 | + */ |
|
418 | + protected function loadTicketSelector(array $tickets, array $template_args) |
|
419 | + { |
|
420 | + $template_args['event'] = $this->event; |
|
421 | + $template_args['EVT_ID'] = $this->event->ID(); |
|
422 | + $template_args['event_is_expired'] = $this->event->is_expired(); |
|
423 | + $template_args['max_atndz'] = $this->getMaxAttendees(); |
|
424 | + $template_args['date_format'] = $this->date_format; |
|
425 | + $template_args['time_format'] = $this->time_format; |
|
426 | + /** |
|
427 | + * Filters the anchor ID used when redirecting to the Ticket Selector if no quantity selected |
|
428 | + * |
|
429 | + * @since 4.9.13 |
|
430 | + * @param string '#tkt-slctr-tbl-' . $EVT_ID The html ID to anchor to |
|
431 | + * @param int $EVT_ID The Event ID |
|
432 | + */ |
|
433 | + $template_args['anchor_id'] = apply_filters( |
|
434 | + 'FHEE__EE_Ticket_Selector__redirect_anchor_id', |
|
435 | + '#tkt-slctr-tbl-' . $this->event->ID(), |
|
436 | + $this->event->ID() |
|
437 | + ); |
|
438 | + $template_args['tickets'] = $tickets; |
|
439 | + $template_args['ticket_count'] = count($tickets); |
|
440 | + $ticket_selector = $this->simpleTicketSelector($tickets, $template_args); |
|
441 | + return $ticket_selector instanceof TicketSelectorSimple |
|
442 | + ? $ticket_selector |
|
443 | + : new TicketSelectorStandard( |
|
444 | + $this->event, |
|
445 | + $tickets, |
|
446 | + $this->getMaxAttendees(), |
|
447 | + $template_args, |
|
448 | + $this->date_format, |
|
449 | + $this->time_format |
|
450 | + ); |
|
451 | + } |
|
452 | + |
|
453 | + |
|
454 | + |
|
455 | + /** |
|
456 | + * simpleTicketSelector |
|
457 | + * there's one ticket, and max attendees is set to one, |
|
458 | + * so if the event is free, then this is a "simple" ticket selector |
|
459 | + * a.k.a. "Dude Where's my Ticket Selector?" |
|
460 | + * |
|
461 | + * @param \EE_Ticket[] $tickets |
|
462 | + * @param array $template_args |
|
463 | + * @return string |
|
464 | + * @throws EE_Error |
|
465 | + */ |
|
466 | + protected function simpleTicketSelector($tickets, array $template_args) |
|
467 | + { |
|
468 | + // if there is only ONE ticket with a max qty of ONE |
|
469 | + if (count($tickets) > 1 || $this->getMaxAttendees() !== 1) { |
|
470 | + return ''; |
|
471 | + } |
|
472 | + /** @var \EE_Ticket $ticket */ |
|
473 | + $ticket = reset($tickets); |
|
474 | + // if the ticket is free... then not much need for the ticket selector |
|
475 | + if ( |
|
476 | + apply_filters( |
|
477 | + 'FHEE__ticket_selector_chart_template__hide_ticket_selector', |
|
478 | + $ticket->is_free(), |
|
479 | + $this->event->ID() |
|
480 | + ) |
|
481 | + ) { |
|
482 | + return new TicketSelectorSimple( |
|
483 | + $this->event, |
|
484 | + $ticket, |
|
485 | + $this->getMaxAttendees(), |
|
486 | + $template_args |
|
487 | + ); |
|
488 | + } |
|
489 | + return ''; |
|
490 | + } |
|
491 | + |
|
492 | + |
|
493 | + |
|
494 | + /** |
|
495 | + * externalEventRegistration |
|
496 | + * |
|
497 | + * @return string |
|
498 | + */ |
|
499 | + public function externalEventRegistration() |
|
500 | + { |
|
501 | + // if not we still need to trigger the display of the submit button |
|
502 | + add_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true'); |
|
503 | + //display notice to admin that registration is external |
|
504 | + return $this->display_full_ui() |
|
505 | + ? esc_html__( |
|
506 | + 'Registration is at an external URL for this event.', |
|
507 | + 'event_espresso' |
|
508 | + ) |
|
509 | + : ''; |
|
510 | + } |
|
511 | + |
|
512 | + |
|
513 | + |
|
514 | + /** |
|
515 | + * formOpen |
|
516 | + * |
|
517 | + * @param int $ID |
|
518 | + * @param string $external_url |
|
519 | + * @return string |
|
520 | + */ |
|
521 | + public function formOpen($ID = 0, $external_url = '') |
|
522 | + { |
|
523 | + // if redirecting, we don't need any anything else |
|
524 | + if ($external_url) { |
|
525 | + $html = '<form method="GET" action="' . EEH_URL::refactor_url($external_url) . '"'; |
|
526 | + // open link in new window ? |
|
527 | + $html .= apply_filters( |
|
528 | + 'FHEE__EventEspresso_modules_ticket_selector_DisplayTicketSelector__formOpen__external_url_target_blank', |
|
529 | + $this->isIframe(), |
|
530 | + $this |
|
531 | + ) |
|
532 | + ? ' target="_blank"' |
|
533 | + : ''; |
|
534 | + $html .= '>'; |
|
535 | + $query_args = EEH_URL::get_query_string($external_url); |
|
536 | + foreach ((array)$query_args as $query_arg => $value) { |
|
537 | + $html .= '<input type="hidden" name="' . $query_arg . '" value="' . $value . '">'; |
|
538 | + } |
|
539 | + return $html; |
|
540 | + } |
|
541 | + // if there is no submit button, then don't start building a form |
|
542 | + // because the "View Details" button will build its own form |
|
543 | + if (! apply_filters('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', false)) { |
|
544 | + return ''; |
|
545 | + } |
|
546 | + $checkout_url = EEH_Event_View::event_link_url($ID); |
|
547 | + if (! $checkout_url) { |
|
548 | + EE_Error::add_error( |
|
549 | + esc_html__('The URL for the Event Details page could not be retrieved.', 'event_espresso'), |
|
550 | + __FILE__, |
|
551 | + __FUNCTION__, |
|
552 | + __LINE__ |
|
553 | + ); |
|
554 | + } |
|
555 | + // set no cache headers and constants |
|
556 | + EE_System::do_not_cache(); |
|
557 | + $extra_params = $this->iframe ? ' target="_blank"' : ''; |
|
558 | + $html = '<form method="POST" action="' . $checkout_url . '"' . $extra_params . '>'; |
|
559 | + $html .= '<input type="hidden" name="ee" value="process_ticket_selections">'; |
|
560 | + $html = apply_filters('FHEE__EE_Ticket_Selector__ticket_selector_form_open__html', $html, $this->event); |
|
561 | + return $html; |
|
562 | + } |
|
563 | + |
|
564 | + |
|
565 | + |
|
566 | + /** |
|
567 | + * displaySubmitButton |
|
568 | + * |
|
569 | + * @param string $external_url |
|
570 | + * @return string |
|
571 | + * @throws EE_Error |
|
572 | + */ |
|
573 | + public function displaySubmitButton($external_url = '') |
|
574 | + { |
|
575 | + $html = ''; |
|
576 | + if ($this->display_full_ui()) { |
|
577 | + // standard TS displayed with submit button, ie: "Register Now" |
|
578 | + if (apply_filters('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', false)) { |
|
579 | + $html .= $this->displayRegisterNowButton(); |
|
580 | + $html .= empty($external_url) |
|
581 | + ? $this->ticketSelectorEndDiv() |
|
582 | + : $this->clearTicketSelector(); |
|
583 | + $html .= '<br/>' . $this->formClose(); |
|
584 | + } elseif ($this->getMaxAttendees() === 1) { |
|
585 | + // its a "Dude Where's my Ticket Selector?" (DWMTS) type event (ie: $_max_atndz === 1) |
|
586 | + if ($this->event->is_sold_out()) { |
|
587 | + // then instead of a View Details or Submit button, just display a "Sold Out" message |
|
588 | + $html .= apply_filters( |
|
589 | + 'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__sold_out_msg', |
|
590 | + sprintf( |
|
591 | + __( |
|
592 | + '%1$s"%2$s" is currently sold out.%4$sPlease check back again later, as spots may become available.%3$s', |
|
593 | + 'event_espresso' |
|
594 | + ), |
|
595 | + '<p class="no-ticket-selector-msg clear-float">', |
|
596 | + $this->event->name(), |
|
597 | + '</p>', |
|
598 | + '<br />' |
|
599 | + ), |
|
600 | + $this->event |
|
601 | + ); |
|
602 | + if ( |
|
603 | + apply_filters( |
|
604 | + 'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__no_tickets_but_display_register_now_button', |
|
605 | + false, |
|
606 | + $this->event |
|
607 | + ) |
|
608 | + ) { |
|
609 | + $html .= $this->displayRegisterNowButton(); |
|
610 | + } |
|
611 | + // sold out DWMTS event, no TS, no submit or view details button, but has additional content |
|
612 | + $html .= $this->ticketSelectorEndDiv(); |
|
613 | + } elseif ( |
|
614 | + apply_filters('FHEE__EE_Ticket_Selector__hide_ticket_selector', false) |
|
615 | + && ! is_single() |
|
616 | + ) { |
|
617 | + // this is a "Dude Where's my Ticket Selector?" (DWMTS) type event, |
|
618 | + // but no tickets are available, so display event's "View Details" button. |
|
619 | + // it is being viewed via somewhere other than a single post |
|
620 | + $html .= $this->displayViewDetailsButton(true); |
|
621 | + } else { |
|
622 | + $html .= $this->ticketSelectorEndDiv(); |
|
623 | + } |
|
624 | + } elseif (is_archive()) { |
|
625 | + // event list, no tickets available so display event's "View Details" button |
|
626 | + $html .= $this->ticketSelectorEndDiv(); |
|
627 | + $html .= $this->displayViewDetailsButton(); |
|
628 | + } else { |
|
629 | + if ( |
|
630 | + apply_filters( |
|
631 | + 'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__no_tickets_but_display_register_now_button', |
|
632 | + false, |
|
633 | + $this->event |
|
634 | + ) |
|
635 | + ) { |
|
636 | + $html .= $this->displayRegisterNowButton(); |
|
637 | + } |
|
638 | + // no submit or view details button, and no additional content |
|
639 | + $html .= $this->ticketSelectorEndDiv(); |
|
640 | + } |
|
641 | + if (! $this->iframe && ! is_archive()) { |
|
642 | + $html .= EEH_Template::powered_by_event_espresso('', '', array('utm_content' => 'ticket_selector')); |
|
643 | + } |
|
644 | + } |
|
645 | + return apply_filters( |
|
646 | + 'FHEE__EventEspresso_modules_ticket_selector_DisplayTicketSelector__displaySubmitButton__html', |
|
647 | + $html, |
|
648 | + $this->event, |
|
649 | + $this |
|
650 | + ); |
|
651 | + } |
|
652 | + |
|
653 | + |
|
654 | + |
|
655 | + /** |
|
656 | + * @return string |
|
657 | + * @throws EE_Error |
|
658 | + */ |
|
659 | + public function displayRegisterNowButton() |
|
660 | + { |
|
661 | + $btn_text = apply_filters( |
|
662 | + 'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__btn_text', |
|
663 | + __('Register Now', 'event_espresso'), |
|
664 | + $this->event |
|
665 | + ); |
|
666 | + $external_url = $this->event->external_url(); |
|
667 | + $html = EEH_HTML::div( |
|
668 | + '', |
|
669 | + 'ticket-selector-submit-' . $this->event->ID() . '-btn-wrap', |
|
670 | + 'ticket-selector-submit-btn-wrap' |
|
671 | + ); |
|
672 | + $html .= '<input id="ticket-selector-submit-' . $this->event->ID() . '-btn"'; |
|
673 | + $html .= ' class="ticket-selector-submit-btn '; |
|
674 | + $html .= empty($external_url) ? 'ticket-selector-submit-ajax"' : '"'; |
|
675 | + $html .= ' type="submit" value="' . $btn_text . '" />'; |
|
676 | + $html .= EEH_HTML::divx() . '<!-- .ticket-selector-submit-btn-wrap -->'; |
|
677 | + $html .= apply_filters( |
|
678 | + 'FHEE__EE_Ticket_Selector__after_ticket_selector_submit', |
|
679 | + '', |
|
680 | + $this->event |
|
681 | + ); |
|
682 | + return $html; |
|
683 | + } |
|
684 | + |
|
685 | + |
|
686 | + /** |
|
687 | + * displayViewDetailsButton |
|
688 | + * |
|
689 | + * @param bool $DWMTS indicates a "Dude Where's my Ticket Selector?" (DWMTS) type event |
|
690 | + * (ie: $_max_atndz === 1) where there are no available tickets, |
|
691 | + * either because they are sold out, expired, or not yet on sale. |
|
692 | + * In this case, we need to close the form BEFORE adding any closing divs |
|
693 | + * @return string |
|
694 | + * @throws EE_Error |
|
695 | + */ |
|
696 | + public function displayViewDetailsButton($DWMTS = false) |
|
697 | + { |
|
698 | + if (! $this->event->get_permalink()) { |
|
699 | + EE_Error::add_error( |
|
700 | + esc_html__('The URL for the Event Details page could not be retrieved.', 'event_espresso'), |
|
701 | + __FILE__, |
|
702 | + __FUNCTION__, |
|
703 | + __LINE__ |
|
704 | + ); |
|
705 | + } |
|
706 | + $view_details_btn = '<form method="POST" action="'; |
|
707 | + $view_details_btn .= apply_filters( |
|
708 | + 'FHEE__EE_Ticket_Selector__display_view_details_btn__btn_url', |
|
709 | + $this->event->get_permalink(), |
|
710 | + $this->event |
|
711 | + ); |
|
712 | + $view_details_btn .= '"'; |
|
713 | + // open link in new window ? |
|
714 | + $view_details_btn .= apply_filters( |
|
715 | + 'FHEE__EventEspresso_modules_ticket_selector_DisplayTicketSelector__displayViewDetailsButton__url_target_blank', |
|
716 | + $this->isIframe(), |
|
717 | + $this |
|
718 | + ) |
|
719 | + ? ' target="_blank"' |
|
720 | + : ''; |
|
721 | + $view_details_btn .= '>'; |
|
722 | + $btn_text = apply_filters( |
|
723 | + 'FHEE__EE_Ticket_Selector__display_view_details_btn__btn_text', |
|
724 | + esc_html__('View Details', 'event_espresso'), |
|
725 | + $this->event |
|
726 | + ); |
|
727 | + $view_details_btn .= '<input id="ticket-selector-submit-' |
|
728 | + . $this->event->ID() |
|
729 | + . '-btn" class="ticket-selector-submit-btn view-details-btn" type="submit" value="' |
|
730 | + . $btn_text |
|
731 | + . '" />'; |
|
732 | + $view_details_btn .= apply_filters('FHEE__EE_Ticket_Selector__after_view_details_btn', '', $this->event); |
|
733 | + if ($DWMTS) { |
|
734 | + $view_details_btn .= $this->formClose(); |
|
735 | + $view_details_btn .= $this->ticketSelectorEndDiv(); |
|
736 | + $view_details_btn .= '<br/>'; |
|
737 | + } else { |
|
738 | + $view_details_btn .= $this->clearTicketSelector(); |
|
739 | + $view_details_btn .= '<br/>'; |
|
740 | + $view_details_btn .= $this->formClose(); |
|
741 | + } |
|
742 | + return $view_details_btn; |
|
743 | + } |
|
744 | + |
|
745 | + |
|
746 | + |
|
747 | + /** |
|
748 | + * @return string |
|
749 | + */ |
|
750 | + public function ticketSelectorEndDiv() |
|
751 | + { |
|
752 | + return $this->clearTicketSelector() . '</div><!-- ticketSelectorEndDiv -->'; |
|
753 | + } |
|
754 | + |
|
755 | + |
|
756 | + |
|
757 | + /** |
|
758 | + * @return string |
|
759 | + */ |
|
760 | + public function clearTicketSelector() |
|
761 | + { |
|
762 | + // standard TS displayed, appears after a "Register Now" or "view Details" button |
|
763 | + return '<div class="clear"></div><!-- clearTicketSelector -->'; |
|
764 | + } |
|
765 | + |
|
766 | + |
|
767 | + |
|
768 | + /** |
|
769 | + * @access public |
|
770 | + * @return string |
|
771 | + */ |
|
772 | + public function formClose() |
|
773 | + { |
|
774 | + return '</form>'; |
|
775 | + } |
|
776 | 776 | |
777 | 777 | |
778 | 778 |
@@ -19,7 +19,7 @@ discard block |
||
19 | 19 | use InvalidArgumentException; |
20 | 20 | use WP_Post; |
21 | 21 | |
22 | -defined('EVENT_ESPRESSO_VERSION')|| exit('No direct script access allowed'); |
|
22 | +defined('EVENT_ESPRESSO_VERSION') || exit('No direct script access allowed'); |
|
23 | 23 | |
24 | 24 | |
25 | 25 | |
@@ -140,11 +140,11 @@ discard block |
||
140 | 140 | } |
141 | 141 | } else { |
142 | 142 | $user_msg = __('No Event object or an invalid Event object was supplied.', 'event_espresso'); |
143 | - $dev_msg = $user_msg . __( |
|
143 | + $dev_msg = $user_msg.__( |
|
144 | 144 | 'In order to generate a ticket selector, please ensure you are passing either an EE_Event object or a WP_Post object of the post type "espresso_event" to the EE_Ticket_Selector class constructor.', |
145 | 145 | 'event_espresso' |
146 | 146 | ); |
147 | - EE_Error::add_error($user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__); |
|
147 | + EE_Error::add_error($user_msg.'||'.$dev_msg, __FILE__, __FUNCTION__, __LINE__); |
|
148 | 148 | return false; |
149 | 149 | } |
150 | 150 | return true; |
@@ -208,7 +208,7 @@ discard block |
||
208 | 208 | // reset filter for displaying submit button |
209 | 209 | remove_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true'); |
210 | 210 | // poke and prod incoming event till it tells us what it is |
211 | - if (! $this->setEvent($event)) { |
|
211 | + if ( ! $this->setEvent($event)) { |
|
212 | 212 | return false; |
213 | 213 | } |
214 | 214 | // begin gathering template arguments by getting event status |
@@ -238,14 +238,14 @@ discard block |
||
238 | 238 | return $this->noTicketAvailableMessage(); |
239 | 239 | } |
240 | 240 | // redirecting to another site for registration ?? |
241 | - $external_url = (string)$this->event->external_url(); |
|
241 | + $external_url = (string) $this->event->external_url(); |
|
242 | 242 | // if redirecting to another site for registration, then we don't load the TS |
243 | 243 | $ticket_selector = $external_url |
244 | 244 | ? $this->externalEventRegistration() |
245 | 245 | : $this->loadTicketSelector($tickets, $template_args); |
246 | 246 | // now set up the form (but not for the admin) |
247 | 247 | $ticket_selector = $this->display_full_ui() |
248 | - ? $this->formOpen($this->event->ID(), $external_url) . $ticket_selector |
|
248 | + ? $this->formOpen($this->event->ID(), $external_url).$ticket_selector |
|
249 | 249 | : $ticket_selector; |
250 | 250 | // submit button and form close tag |
251 | 251 | $ticket_selector .= $this->display_full_ui() ? $this->displaySubmitButton($external_url) : ''; |
@@ -295,10 +295,10 @@ discard block |
||
295 | 295 | */ |
296 | 296 | protected function expiredEventMessage() |
297 | 297 | { |
298 | - return '<div class="ee-event-expired-notice"><span class="important-notice">' . esc_html__( |
|
298 | + return '<div class="ee-event-expired-notice"><span class="important-notice">'.esc_html__( |
|
299 | 299 | 'We\'re sorry, but all tickets sales have ended because the event is expired.', |
300 | 300 | 'event_espresso' |
301 | - ) . '</span></div><!-- .ee-event-expired-notice -->'; |
|
301 | + ).'</span></div><!-- .ee-event-expired-notice -->'; |
|
302 | 302 | } |
303 | 303 | |
304 | 304 | |
@@ -329,7 +329,7 @@ discard block |
||
329 | 329 | } |
330 | 330 | return ' |
331 | 331 | <div class="ee-event-expired-notice"> |
332 | - <span class="important-notice">' . $no_ticket_available_msg . '</span> |
|
332 | + <span class="important-notice">' . $no_ticket_available_msg.'</span> |
|
333 | 333 | </div><!-- .ee-event-expired-notice -->'; |
334 | 334 | } |
335 | 335 | |
@@ -362,7 +362,7 @@ discard block |
||
362 | 362 | '</a></span></div><!-- .ee-attention ticketSalesClosedMessage -->' |
363 | 363 | ); |
364 | 364 | } |
365 | - return '<p><span class="important-notice">' . $sales_closed_msg . '</span></p>'; |
|
365 | + return '<p><span class="important-notice">'.$sales_closed_msg.'</span></p>'; |
|
366 | 366 | } |
367 | 367 | |
368 | 368 | |
@@ -430,9 +430,9 @@ discard block |
||
430 | 430 | * @param string '#tkt-slctr-tbl-' . $EVT_ID The html ID to anchor to |
431 | 431 | * @param int $EVT_ID The Event ID |
432 | 432 | */ |
433 | - $template_args['anchor_id'] = apply_filters( |
|
433 | + $template_args['anchor_id'] = apply_filters( |
|
434 | 434 | 'FHEE__EE_Ticket_Selector__redirect_anchor_id', |
435 | - '#tkt-slctr-tbl-' . $this->event->ID(), |
|
435 | + '#tkt-slctr-tbl-'.$this->event->ID(), |
|
436 | 436 | $this->event->ID() |
437 | 437 | ); |
438 | 438 | $template_args['tickets'] = $tickets; |
@@ -522,29 +522,29 @@ discard block |
||
522 | 522 | { |
523 | 523 | // if redirecting, we don't need any anything else |
524 | 524 | if ($external_url) { |
525 | - $html = '<form method="GET" action="' . EEH_URL::refactor_url($external_url) . '"'; |
|
525 | + $html = '<form method="GET" action="'.EEH_URL::refactor_url($external_url).'"'; |
|
526 | 526 | // open link in new window ? |
527 | - $html .= apply_filters( |
|
527 | + $html .= apply_filters( |
|
528 | 528 | 'FHEE__EventEspresso_modules_ticket_selector_DisplayTicketSelector__formOpen__external_url_target_blank', |
529 | 529 | $this->isIframe(), |
530 | 530 | $this |
531 | 531 | ) |
532 | 532 | ? ' target="_blank"' |
533 | 533 | : ''; |
534 | - $html .= '>'; |
|
534 | + $html .= '>'; |
|
535 | 535 | $query_args = EEH_URL::get_query_string($external_url); |
536 | - foreach ((array)$query_args as $query_arg => $value) { |
|
537 | - $html .= '<input type="hidden" name="' . $query_arg . '" value="' . $value . '">'; |
|
536 | + foreach ((array) $query_args as $query_arg => $value) { |
|
537 | + $html .= '<input type="hidden" name="'.$query_arg.'" value="'.$value.'">'; |
|
538 | 538 | } |
539 | 539 | return $html; |
540 | 540 | } |
541 | 541 | // if there is no submit button, then don't start building a form |
542 | 542 | // because the "View Details" button will build its own form |
543 | - if (! apply_filters('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', false)) { |
|
543 | + if ( ! apply_filters('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', false)) { |
|
544 | 544 | return ''; |
545 | 545 | } |
546 | 546 | $checkout_url = EEH_Event_View::event_link_url($ID); |
547 | - if (! $checkout_url) { |
|
547 | + if ( ! $checkout_url) { |
|
548 | 548 | EE_Error::add_error( |
549 | 549 | esc_html__('The URL for the Event Details page could not be retrieved.', 'event_espresso'), |
550 | 550 | __FILE__, |
@@ -555,8 +555,8 @@ discard block |
||
555 | 555 | // set no cache headers and constants |
556 | 556 | EE_System::do_not_cache(); |
557 | 557 | $extra_params = $this->iframe ? ' target="_blank"' : ''; |
558 | - $html = '<form method="POST" action="' . $checkout_url . '"' . $extra_params . '>'; |
|
559 | - $html .= '<input type="hidden" name="ee" value="process_ticket_selections">'; |
|
558 | + $html = '<form method="POST" action="'.$checkout_url.'"'.$extra_params.'>'; |
|
559 | + $html .= '<input type="hidden" name="ee" value="process_ticket_selections">'; |
|
560 | 560 | $html = apply_filters('FHEE__EE_Ticket_Selector__ticket_selector_form_open__html', $html, $this->event); |
561 | 561 | return $html; |
562 | 562 | } |
@@ -580,7 +580,7 @@ discard block |
||
580 | 580 | $html .= empty($external_url) |
581 | 581 | ? $this->ticketSelectorEndDiv() |
582 | 582 | : $this->clearTicketSelector(); |
583 | - $html .= '<br/>' . $this->formClose(); |
|
583 | + $html .= '<br/>'.$this->formClose(); |
|
584 | 584 | } elseif ($this->getMaxAttendees() === 1) { |
585 | 585 | // its a "Dude Where's my Ticket Selector?" (DWMTS) type event (ie: $_max_atndz === 1) |
586 | 586 | if ($this->event->is_sold_out()) { |
@@ -638,7 +638,7 @@ discard block |
||
638 | 638 | // no submit or view details button, and no additional content |
639 | 639 | $html .= $this->ticketSelectorEndDiv(); |
640 | 640 | } |
641 | - if (! $this->iframe && ! is_archive()) { |
|
641 | + if ( ! $this->iframe && ! is_archive()) { |
|
642 | 642 | $html .= EEH_Template::powered_by_event_espresso('', '', array('utm_content' => 'ticket_selector')); |
643 | 643 | } |
644 | 644 | } |
@@ -658,7 +658,7 @@ discard block |
||
658 | 658 | */ |
659 | 659 | public function displayRegisterNowButton() |
660 | 660 | { |
661 | - $btn_text = apply_filters( |
|
661 | + $btn_text = apply_filters( |
|
662 | 662 | 'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__btn_text', |
663 | 663 | __('Register Now', 'event_espresso'), |
664 | 664 | $this->event |
@@ -666,14 +666,14 @@ discard block |
||
666 | 666 | $external_url = $this->event->external_url(); |
667 | 667 | $html = EEH_HTML::div( |
668 | 668 | '', |
669 | - 'ticket-selector-submit-' . $this->event->ID() . '-btn-wrap', |
|
669 | + 'ticket-selector-submit-'.$this->event->ID().'-btn-wrap', |
|
670 | 670 | 'ticket-selector-submit-btn-wrap' |
671 | 671 | ); |
672 | - $html .= '<input id="ticket-selector-submit-' . $this->event->ID() . '-btn"'; |
|
672 | + $html .= '<input id="ticket-selector-submit-'.$this->event->ID().'-btn"'; |
|
673 | 673 | $html .= ' class="ticket-selector-submit-btn '; |
674 | 674 | $html .= empty($external_url) ? 'ticket-selector-submit-ajax"' : '"'; |
675 | - $html .= ' type="submit" value="' . $btn_text . '" />'; |
|
676 | - $html .= EEH_HTML::divx() . '<!-- .ticket-selector-submit-btn-wrap -->'; |
|
675 | + $html .= ' type="submit" value="'.$btn_text.'" />'; |
|
676 | + $html .= EEH_HTML::divx().'<!-- .ticket-selector-submit-btn-wrap -->'; |
|
677 | 677 | $html .= apply_filters( |
678 | 678 | 'FHEE__EE_Ticket_Selector__after_ticket_selector_submit', |
679 | 679 | '', |
@@ -695,7 +695,7 @@ discard block |
||
695 | 695 | */ |
696 | 696 | public function displayViewDetailsButton($DWMTS = false) |
697 | 697 | { |
698 | - if (! $this->event->get_permalink()) { |
|
698 | + if ( ! $this->event->get_permalink()) { |
|
699 | 699 | EE_Error::add_error( |
700 | 700 | esc_html__('The URL for the Event Details page could not be retrieved.', 'event_espresso'), |
701 | 701 | __FILE__, |
@@ -719,7 +719,7 @@ discard block |
||
719 | 719 | ? ' target="_blank"' |
720 | 720 | : ''; |
721 | 721 | $view_details_btn .= '>'; |
722 | - $btn_text = apply_filters( |
|
722 | + $btn_text = apply_filters( |
|
723 | 723 | 'FHEE__EE_Ticket_Selector__display_view_details_btn__btn_text', |
724 | 724 | esc_html__('View Details', 'event_espresso'), |
725 | 725 | $this->event |
@@ -749,7 +749,7 @@ discard block |
||
749 | 749 | */ |
750 | 750 | public function ticketSelectorEndDiv() |
751 | 751 | { |
752 | - return $this->clearTicketSelector() . '</div><!-- ticketSelectorEndDiv -->'; |
|
752 | + return $this->clearTicketSelector().'</div><!-- ticketSelectorEndDiv -->'; |
|
753 | 753 | } |
754 | 754 | |
755 | 755 |