@@ -163,7 +163,7 @@ |
||
163 | 163 | private function _get_events_from_registration(EE_Registration $registration) |
164 | 164 | { |
165 | 165 | return isset($this->_extra_data['data']->registrations) |
166 | - ? [$this->_extra_data['data']->registrations[ $registration->ID() ]['evt_obj']] |
|
166 | + ? [$this->_extra_data['data']->registrations[$registration->ID()]['evt_obj']] |
|
167 | 167 | : []; |
168 | 168 | } |
169 | 169 | } |
@@ -18,156 +18,156 @@ |
||
18 | 18 | */ |
19 | 19 | class EE_Event_List_Shortcodes extends EE_Shortcodes |
20 | 20 | { |
21 | - public function __construct() |
|
22 | - { |
|
23 | - parent::__construct(); |
|
24 | - } |
|
25 | - |
|
26 | - |
|
27 | - protected function _init_props() |
|
28 | - { |
|
29 | - $this->label = esc_html__('Event List Shortcodes', 'event_espresso'); |
|
30 | - $this->description = esc_html__('All shortcodes specific to event lists', 'event_espresso'); |
|
31 | - $this->_shortcodes = [ |
|
32 | - '[EVENT_LIST]' => esc_html__('Will output a list of events', 'event_espresso'), |
|
33 | - ]; |
|
34 | - } |
|
35 | - |
|
36 | - |
|
37 | - /** |
|
38 | - * @param string $shortcode |
|
39 | - * @return string |
|
40 | - * @throws EE_Error |
|
41 | - * @throws ReflectionException |
|
42 | - */ |
|
43 | - protected function _parser($shortcode) |
|
44 | - { |
|
45 | - switch ($shortcode) { |
|
46 | - case '[EVENT_LIST]': |
|
47 | - return $this->_get_event_list(); |
|
48 | - } |
|
49 | - return ''; |
|
50 | - } |
|
51 | - |
|
52 | - |
|
53 | - /** |
|
54 | - * figure out what the incoming data is and then return the appropriate parsed value. |
|
55 | - * |
|
56 | - * @return string |
|
57 | - * @throws EE_Error |
|
58 | - * @throws ReflectionException |
|
59 | - */ |
|
60 | - private function _get_event_list() |
|
61 | - { |
|
62 | - $this->_validate_list_requirements(); |
|
63 | - |
|
64 | - if ($this->_data['data'] instanceof EE_Messages_Addressee) { |
|
65 | - return $this->_get_event_list_for_main(); |
|
66 | - } |
|
67 | - if ($this->_data['data'] instanceof EE_Registration) { |
|
68 | - return $this->_get_event_list_for_registration(); |
|
69 | - } |
|
70 | - // prevent recursive loop |
|
71 | - return ''; |
|
72 | - } |
|
73 | - |
|
74 | - |
|
75 | - /** |
|
76 | - * This returns the parsed event list for main template |
|
77 | - * |
|
78 | - * @return string |
|
79 | - */ |
|
80 | - private function _get_event_list_for_main() |
|
81 | - { |
|
82 | - |
|
83 | - $valid_shortcodes = [ |
|
84 | - 'event', |
|
85 | - 'attendee_list', |
|
86 | - 'ticket_list', |
|
87 | - 'datetime_list', |
|
88 | - 'venue', |
|
89 | - 'attendee', |
|
90 | - 'recipient_list', |
|
91 | - 'recipient_details', |
|
92 | - 'primary_registration_list', |
|
93 | - 'primary_registration_details', |
|
94 | - 'event_author', |
|
95 | - 'organization', |
|
96 | - ]; |
|
97 | - $template = $this->_data['template']; |
|
98 | - $data = $this->_data['data']; |
|
99 | - $events = ''; |
|
100 | - |
|
101 | - // now we need to loop through the events array in EE_Messages_Addressee and send data to the EE_Parser helper. |
|
102 | - foreach ($data->events as $event) { |
|
103 | - $events .= $this->_shortcode_helper->parse_event_list_template( |
|
104 | - $template, |
|
105 | - $event['event'], |
|
106 | - $valid_shortcodes, |
|
107 | - $this->_extra_data |
|
108 | - ); |
|
109 | - } |
|
110 | - return $events; |
|
111 | - } |
|
112 | - |
|
113 | - |
|
114 | - /** |
|
115 | - * This returns the parsed event list for an attendee |
|
116 | - * |
|
117 | - * @return string |
|
118 | - * @throws EE_Error |
|
119 | - * @throws ReflectionException |
|
120 | - */ |
|
121 | - private function _get_event_list_for_registration() |
|
122 | - { |
|
123 | - $valid_shortcodes = [ |
|
124 | - 'event', |
|
125 | - 'ticket_list', |
|
126 | - 'datetime_list', |
|
127 | - 'attendee', |
|
128 | - 'event_author', |
|
129 | - 'recipient_details', |
|
130 | - 'recipient_list', |
|
131 | - 'venue', |
|
132 | - 'organization', |
|
133 | - ]; |
|
134 | - $template = is_array($this->_data['template']) && isset($this->_data['template']['event_list']) |
|
135 | - ? $this->_data['template']['event_list'] |
|
136 | - : $this->_extra_data['template']['event_list']; |
|
137 | - $registration = $this->_data['data']; |
|
138 | - |
|
139 | - // let's remove any existing [ATTENDEE_LIST] shortcode from the event list template so that we don't get recursion. |
|
140 | - $template = str_replace('[ATTENDEE_LIST]', '', $template); |
|
141 | - |
|
142 | - // here we're setting up the events for the event_list template for THIS registration. |
|
143 | - $all_events = $this->_get_events_from_registration($registration); |
|
144 | - |
|
145 | - // we're NOT going to prepare a list of attendees this time around |
|
146 | - $events = ''; |
|
147 | - |
|
148 | - foreach ($all_events as $event) { |
|
149 | - $events .= $this->_shortcode_helper->parse_event_list_template( |
|
150 | - $template, |
|
151 | - $event, |
|
152 | - $valid_shortcodes, |
|
153 | - $this->_extra_data |
|
154 | - ); |
|
155 | - } |
|
156 | - |
|
157 | - return $events; |
|
158 | - } |
|
159 | - |
|
160 | - |
|
161 | - /** |
|
162 | - * @param EE_Registration $registration |
|
163 | - * @return array |
|
164 | - * @throws EE_Error |
|
165 | - * @throws ReflectionException |
|
166 | - */ |
|
167 | - private function _get_events_from_registration(EE_Registration $registration) |
|
168 | - { |
|
169 | - return isset($this->_extra_data['data']->registrations) |
|
170 | - ? [$this->_extra_data['data']->registrations[ $registration->ID() ]['evt_obj']] |
|
171 | - : []; |
|
172 | - } |
|
21 | + public function __construct() |
|
22 | + { |
|
23 | + parent::__construct(); |
|
24 | + } |
|
25 | + |
|
26 | + |
|
27 | + protected function _init_props() |
|
28 | + { |
|
29 | + $this->label = esc_html__('Event List Shortcodes', 'event_espresso'); |
|
30 | + $this->description = esc_html__('All shortcodes specific to event lists', 'event_espresso'); |
|
31 | + $this->_shortcodes = [ |
|
32 | + '[EVENT_LIST]' => esc_html__('Will output a list of events', 'event_espresso'), |
|
33 | + ]; |
|
34 | + } |
|
35 | + |
|
36 | + |
|
37 | + /** |
|
38 | + * @param string $shortcode |
|
39 | + * @return string |
|
40 | + * @throws EE_Error |
|
41 | + * @throws ReflectionException |
|
42 | + */ |
|
43 | + protected function _parser($shortcode) |
|
44 | + { |
|
45 | + switch ($shortcode) { |
|
46 | + case '[EVENT_LIST]': |
|
47 | + return $this->_get_event_list(); |
|
48 | + } |
|
49 | + return ''; |
|
50 | + } |
|
51 | + |
|
52 | + |
|
53 | + /** |
|
54 | + * figure out what the incoming data is and then return the appropriate parsed value. |
|
55 | + * |
|
56 | + * @return string |
|
57 | + * @throws EE_Error |
|
58 | + * @throws ReflectionException |
|
59 | + */ |
|
60 | + private function _get_event_list() |
|
61 | + { |
|
62 | + $this->_validate_list_requirements(); |
|
63 | + |
|
64 | + if ($this->_data['data'] instanceof EE_Messages_Addressee) { |
|
65 | + return $this->_get_event_list_for_main(); |
|
66 | + } |
|
67 | + if ($this->_data['data'] instanceof EE_Registration) { |
|
68 | + return $this->_get_event_list_for_registration(); |
|
69 | + } |
|
70 | + // prevent recursive loop |
|
71 | + return ''; |
|
72 | + } |
|
73 | + |
|
74 | + |
|
75 | + /** |
|
76 | + * This returns the parsed event list for main template |
|
77 | + * |
|
78 | + * @return string |
|
79 | + */ |
|
80 | + private function _get_event_list_for_main() |
|
81 | + { |
|
82 | + |
|
83 | + $valid_shortcodes = [ |
|
84 | + 'event', |
|
85 | + 'attendee_list', |
|
86 | + 'ticket_list', |
|
87 | + 'datetime_list', |
|
88 | + 'venue', |
|
89 | + 'attendee', |
|
90 | + 'recipient_list', |
|
91 | + 'recipient_details', |
|
92 | + 'primary_registration_list', |
|
93 | + 'primary_registration_details', |
|
94 | + 'event_author', |
|
95 | + 'organization', |
|
96 | + ]; |
|
97 | + $template = $this->_data['template']; |
|
98 | + $data = $this->_data['data']; |
|
99 | + $events = ''; |
|
100 | + |
|
101 | + // now we need to loop through the events array in EE_Messages_Addressee and send data to the EE_Parser helper. |
|
102 | + foreach ($data->events as $event) { |
|
103 | + $events .= $this->_shortcode_helper->parse_event_list_template( |
|
104 | + $template, |
|
105 | + $event['event'], |
|
106 | + $valid_shortcodes, |
|
107 | + $this->_extra_data |
|
108 | + ); |
|
109 | + } |
|
110 | + return $events; |
|
111 | + } |
|
112 | + |
|
113 | + |
|
114 | + /** |
|
115 | + * This returns the parsed event list for an attendee |
|
116 | + * |
|
117 | + * @return string |
|
118 | + * @throws EE_Error |
|
119 | + * @throws ReflectionException |
|
120 | + */ |
|
121 | + private function _get_event_list_for_registration() |
|
122 | + { |
|
123 | + $valid_shortcodes = [ |
|
124 | + 'event', |
|
125 | + 'ticket_list', |
|
126 | + 'datetime_list', |
|
127 | + 'attendee', |
|
128 | + 'event_author', |
|
129 | + 'recipient_details', |
|
130 | + 'recipient_list', |
|
131 | + 'venue', |
|
132 | + 'organization', |
|
133 | + ]; |
|
134 | + $template = is_array($this->_data['template']) && isset($this->_data['template']['event_list']) |
|
135 | + ? $this->_data['template']['event_list'] |
|
136 | + : $this->_extra_data['template']['event_list']; |
|
137 | + $registration = $this->_data['data']; |
|
138 | + |
|
139 | + // let's remove any existing [ATTENDEE_LIST] shortcode from the event list template so that we don't get recursion. |
|
140 | + $template = str_replace('[ATTENDEE_LIST]', '', $template); |
|
141 | + |
|
142 | + // here we're setting up the events for the event_list template for THIS registration. |
|
143 | + $all_events = $this->_get_events_from_registration($registration); |
|
144 | + |
|
145 | + // we're NOT going to prepare a list of attendees this time around |
|
146 | + $events = ''; |
|
147 | + |
|
148 | + foreach ($all_events as $event) { |
|
149 | + $events .= $this->_shortcode_helper->parse_event_list_template( |
|
150 | + $template, |
|
151 | + $event, |
|
152 | + $valid_shortcodes, |
|
153 | + $this->_extra_data |
|
154 | + ); |
|
155 | + } |
|
156 | + |
|
157 | + return $events; |
|
158 | + } |
|
159 | + |
|
160 | + |
|
161 | + /** |
|
162 | + * @param EE_Registration $registration |
|
163 | + * @return array |
|
164 | + * @throws EE_Error |
|
165 | + * @throws ReflectionException |
|
166 | + */ |
|
167 | + private function _get_events_from_registration(EE_Registration $registration) |
|
168 | + { |
|
169 | + return isset($this->_extra_data['data']->registrations) |
|
170 | + ? [$this->_extra_data['data']->registrations[ $registration->ID() ]['evt_obj']] |
|
171 | + : []; |
|
172 | + } |
|
173 | 173 | } |
@@ -1,6 +1,6 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | 3 | esc_html_e( |
4 | - 'Bank is an offline payment method for accepting payments. Payments are processed manually by providing your registrants/attendees with information on how to pay with a bank transfer.', |
|
5 | - 'event_espresso' |
|
4 | + 'Bank is an offline payment method for accepting payments. Payments are processed manually by providing your registrants/attendees with information on how to pay with a bank transfer.', |
|
5 | + 'event_espresso' |
|
6 | 6 | ); |
@@ -1,6 +1,6 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | 3 | esc_html_e( |
4 | - 'Check is an offline payment method for accepting payments. Payments are processed manually by providing your registrants/attendees with information on how to pay with a check.', |
|
5 | - 'event_espresso' |
|
4 | + 'Check is an offline payment method for accepting payments. Payments are processed manually by providing your registrants/attendees with information on how to pay with a check.', |
|
5 | + 'event_espresso' |
|
6 | 6 | ); |
@@ -40,7 +40,7 @@ discard block |
||
40 | 40 | '<br />' |
41 | 41 | ); |
42 | 42 | parent::__construct($pm_instance); |
43 | - $this->_default_button_url = $this->file_url() . 'lib/invoice-logo.png'; |
|
43 | + $this->_default_button_url = $this->file_url().'lib/invoice-logo.png'; |
|
44 | 44 | } |
45 | 45 | |
46 | 46 | |
@@ -65,7 +65,7 @@ discard block |
||
65 | 65 | { |
66 | 66 | $pdf_payee_input_name = 'pdf_payee_name'; |
67 | 67 | $confirmation_text_input_name = 'page_confirmation_text'; |
68 | - $form = new EE_Payment_Method_Form(array( |
|
68 | + $form = new EE_Payment_Method_Form(array( |
|
69 | 69 | // 'payment_method_type' => $this, |
70 | 70 | 'extra_meta_inputs' => array( |
71 | 71 | $pdf_payee_input_name => new EE_Text_Input(array( |
@@ -79,12 +79,12 @@ discard block |
||
79 | 79 | )), |
80 | 80 | 'pdf_payee_address' => new EE_Text_Area_Input(array( |
81 | 81 | 'html_label_text' => sprintf(esc_html__('Payee Address %s', 'event_espresso'), $this->get_help_tab_link()), |
82 | - 'validation_strategies' => array( new EE_Full_HTML_Validation_Strategy() ), |
|
82 | + 'validation_strategies' => array(new EE_Full_HTML_Validation_Strategy()), |
|
83 | 83 | )), |
84 | 84 | 'pdf_instructions' => new EE_Text_Area_Input(array( |
85 | 85 | 'html_label_text' => sprintf(esc_html__("Instructions %s", "event_espresso"), $this->get_help_tab_link()), |
86 | 86 | 'default' => esc_html__("Please send this invoice with payment attached to the address above, or use the payment link below. Payment must be received within 48 hours of event date.", 'event_espresso'), |
87 | - 'validation_strategies' => array( new EE_Full_HTML_Validation_Strategy() ), |
|
87 | + 'validation_strategies' => array(new EE_Full_HTML_Validation_Strategy()), |
|
88 | 88 | )), |
89 | 89 | 'pdf_logo_image' => new EE_Admin_File_Uploader_Input(array( |
90 | 90 | 'html_label_text' => sprintf(esc_html__("Logo Image %s", "event_espresso"), $this->get_help_tab_link()), |
@@ -94,24 +94,24 @@ discard block |
||
94 | 94 | $confirmation_text_input_name => new EE_Text_Area_Input(array( |
95 | 95 | 'html_label_text' => sprintf(esc_html__("Confirmation Text %s", "event_espresso"), $this->get_help_tab_link()), |
96 | 96 | 'default' => esc_html__("Payment must be received within 48 hours of event date. Details about where to send the payment are included on the invoice.", 'event_espresso'), |
97 | - 'validation_strategies' => array( new EE_Full_HTML_Validation_Strategy() ), |
|
97 | + 'validation_strategies' => array(new EE_Full_HTML_Validation_Strategy()), |
|
98 | 98 | )), |
99 | 99 | 'page_extra_info' => new EE_Text_Area_Input(array( |
100 | 100 | 'html_label_text' => sprintf(esc_html__("Extra Info %s", "event_espresso"), $this->get_help_tab_link()), |
101 | - 'validation_strategies' => array( new EE_Full_HTML_Validation_Strategy() ), |
|
101 | + 'validation_strategies' => array(new EE_Full_HTML_Validation_Strategy()), |
|
102 | 102 | )), |
103 | 103 | ), |
104 | 104 | 'include' => array( |
105 | - 'PMD_ID', 'PMD_name','PMD_desc','PMD_admin_name','PMD_admin_desc', 'PMD_type','PMD_slug', 'PMD_open_by_default','PMD_button_url','PMD_scope','Currency','PMD_order', |
|
106 | - $pdf_payee_input_name, 'pdf_payee_email', 'pdf_payee_tax_number', 'pdf_payee_address', 'pdf_instructions','pdf_logo_image', |
|
105 | + 'PMD_ID', 'PMD_name', 'PMD_desc', 'PMD_admin_name', 'PMD_admin_desc', 'PMD_type', 'PMD_slug', 'PMD_open_by_default', 'PMD_button_url', 'PMD_scope', 'Currency', 'PMD_order', |
|
106 | + $pdf_payee_input_name, 'pdf_payee_email', 'pdf_payee_tax_number', 'pdf_payee_address', 'pdf_instructions', 'pdf_logo_image', |
|
107 | 107 | $confirmation_text_input_name, 'page_extra_info'), |
108 | 108 | )); |
109 | 109 | $form->add_subsections( |
110 | - array( 'header1' => new EE_Form_Section_HTML_From_Template('payment_methods/Invoice/templates/invoice_settings_header_display.template.php')), |
|
110 | + array('header1' => new EE_Form_Section_HTML_From_Template('payment_methods/Invoice/templates/invoice_settings_header_display.template.php')), |
|
111 | 111 | $pdf_payee_input_name |
112 | 112 | ); |
113 | 113 | $form->add_subsections( |
114 | - array( 'header2' => new EE_Form_Section_HTML_From_Template('payment_methods/Invoice/templates/invoice_settings_header_gateway.template.php')), |
|
114 | + array('header2' => new EE_Form_Section_HTML_From_Template('payment_methods/Invoice/templates/invoice_settings_header_gateway.template.php')), |
|
115 | 115 | $confirmation_text_input_name |
116 | 116 | ); |
117 | 117 | return $form; |
@@ -24,136 +24,136 @@ |
||
24 | 24 | */ |
25 | 25 | class EE_PMT_Invoice extends EE_PMT_Base |
26 | 26 | { |
27 | - /** |
|
28 | - * |
|
29 | - * @param EE_Payment_Method $pm_instance |
|
30 | - * @return EE_PMT_Invoice |
|
31 | - */ |
|
32 | - public function __construct($pm_instance = null) |
|
33 | - { |
|
34 | - $this->_pretty_name = esc_html__("Invoice", 'event_espresso'); |
|
35 | - $this->_default_description = sprintf( |
|
36 | - esc_html__('After clicking "Finalize Registration", you will be given instructions on how to access your invoice and complete your payment.%sPlease note that event spaces will not be reserved until payment is received in full, and any remaining tickets could be sold to others in the meantime.', 'event_espresso'), |
|
37 | - '<br />' |
|
38 | - ); |
|
39 | - parent::__construct($pm_instance); |
|
40 | - $this->_default_button_url = $this->file_url() . 'lib/invoice-logo.png'; |
|
41 | - } |
|
27 | + /** |
|
28 | + * |
|
29 | + * @param EE_Payment_Method $pm_instance |
|
30 | + * @return EE_PMT_Invoice |
|
31 | + */ |
|
32 | + public function __construct($pm_instance = null) |
|
33 | + { |
|
34 | + $this->_pretty_name = esc_html__("Invoice", 'event_espresso'); |
|
35 | + $this->_default_description = sprintf( |
|
36 | + esc_html__('After clicking "Finalize Registration", you will be given instructions on how to access your invoice and complete your payment.%sPlease note that event spaces will not be reserved until payment is received in full, and any remaining tickets could be sold to others in the meantime.', 'event_espresso'), |
|
37 | + '<br />' |
|
38 | + ); |
|
39 | + parent::__construct($pm_instance); |
|
40 | + $this->_default_button_url = $this->file_url() . 'lib/invoice-logo.png'; |
|
41 | + } |
|
42 | 42 | |
43 | 43 | |
44 | 44 | |
45 | - /** |
|
46 | - * Creates the billing form for this payment method type |
|
47 | - * @param \EE_Transaction $transaction |
|
48 | - * @return NULL |
|
49 | - */ |
|
50 | - public function generate_new_billing_form(EE_Transaction $transaction = null) |
|
51 | - { |
|
52 | - return null; |
|
53 | - } |
|
45 | + /** |
|
46 | + * Creates the billing form for this payment method type |
|
47 | + * @param \EE_Transaction $transaction |
|
48 | + * @return NULL |
|
49 | + */ |
|
50 | + public function generate_new_billing_form(EE_Transaction $transaction = null) |
|
51 | + { |
|
52 | + return null; |
|
53 | + } |
|
54 | 54 | |
55 | 55 | |
56 | 56 | |
57 | - /** |
|
58 | - * Gets the form for all the settings related to this payment method type |
|
59 | - * @return EE_Payment_Method_Form |
|
60 | - */ |
|
61 | - public function generate_new_settings_form() |
|
62 | - { |
|
63 | - $pdf_payee_input_name = 'pdf_payee_name'; |
|
64 | - $confirmation_text_input_name = 'page_confirmation_text'; |
|
65 | - $form = new EE_Payment_Method_Form(array( |
|
57 | + /** |
|
58 | + * Gets the form for all the settings related to this payment method type |
|
59 | + * @return EE_Payment_Method_Form |
|
60 | + */ |
|
61 | + public function generate_new_settings_form() |
|
62 | + { |
|
63 | + $pdf_payee_input_name = 'pdf_payee_name'; |
|
64 | + $confirmation_text_input_name = 'page_confirmation_text'; |
|
65 | + $form = new EE_Payment_Method_Form(array( |
|
66 | 66 | // 'payment_method_type' => $this, |
67 | - 'extra_meta_inputs' => array( |
|
68 | - $pdf_payee_input_name => new EE_Text_Input(array( |
|
69 | - 'html_label_text' => sprintf(esc_html__('Payee Name %s', 'event_espresso'), $this->get_help_tab_link()) |
|
70 | - )), |
|
71 | - 'pdf_payee_email' => new EE_Email_Input(array( |
|
72 | - 'html_label_text' => sprintf(esc_html__('Payee Email %s', 'event_espresso'), $this->get_help_tab_link()), |
|
73 | - )), |
|
74 | - 'pdf_payee_tax_number' => new EE_Text_Input(array( |
|
75 | - 'html_label_text' => sprintf(esc_html__('Payee Tax Number %s', 'event_espresso'), $this->get_help_tab_link()), |
|
76 | - )), |
|
77 | - 'pdf_payee_address' => new EE_Text_Area_Input(array( |
|
78 | - 'html_label_text' => sprintf(esc_html__('Payee Address %s', 'event_espresso'), $this->get_help_tab_link()), |
|
79 | - 'validation_strategies' => array( new EE_Full_HTML_Validation_Strategy() ), |
|
80 | - )), |
|
81 | - 'pdf_instructions' => new EE_Text_Area_Input(array( |
|
82 | - 'html_label_text' => sprintf(esc_html__("Instructions %s", "event_espresso"), $this->get_help_tab_link()), |
|
83 | - 'default' => esc_html__("Please send this invoice with payment attached to the address above, or use the payment link below. Payment must be received within 48 hours of event date.", 'event_espresso'), |
|
84 | - 'validation_strategies' => array( new EE_Full_HTML_Validation_Strategy() ), |
|
85 | - )), |
|
86 | - 'pdf_logo_image' => new EE_Admin_File_Uploader_Input(array( |
|
87 | - 'html_label_text' => sprintf(esc_html__("Logo Image %s", "event_espresso"), $this->get_help_tab_link()), |
|
88 | - 'default' => EE_Config::instance()->organization->logo_url, |
|
89 | - 'html_help_text' => esc_html__("(Logo for the top left of the invoice)", 'event_espresso'), |
|
90 | - )), |
|
91 | - $confirmation_text_input_name => new EE_Text_Area_Input(array( |
|
92 | - 'html_label_text' => sprintf(esc_html__("Confirmation Text %s", "event_espresso"), $this->get_help_tab_link()), |
|
93 | - 'default' => esc_html__("Payment must be received within 48 hours of event date. Details about where to send the payment are included on the invoice.", 'event_espresso'), |
|
94 | - 'validation_strategies' => array( new EE_Full_HTML_Validation_Strategy() ), |
|
95 | - )), |
|
96 | - 'page_extra_info' => new EE_Text_Area_Input(array( |
|
97 | - 'html_label_text' => sprintf(esc_html__("Extra Info %s", "event_espresso"), $this->get_help_tab_link()), |
|
98 | - 'validation_strategies' => array( new EE_Full_HTML_Validation_Strategy() ), |
|
99 | - )), |
|
100 | - ), |
|
101 | - 'include' => array( |
|
102 | - 'PMD_ID', 'PMD_name','PMD_desc','PMD_admin_name','PMD_admin_desc', 'PMD_type','PMD_slug', 'PMD_open_by_default','PMD_button_url','PMD_scope','Currency','PMD_order', |
|
103 | - $pdf_payee_input_name, 'pdf_payee_email', 'pdf_payee_tax_number', 'pdf_payee_address', 'pdf_instructions','pdf_logo_image', |
|
104 | - $confirmation_text_input_name, 'page_extra_info'), |
|
105 | - )); |
|
106 | - $form->add_subsections( |
|
107 | - array( 'header1' => new EE_Form_Section_HTML_From_Template('payment_methods/Invoice/templates/invoice_settings_header_display.template.php')), |
|
108 | - $pdf_payee_input_name |
|
109 | - ); |
|
110 | - $form->add_subsections( |
|
111 | - array( 'header2' => new EE_Form_Section_HTML_From_Template('payment_methods/Invoice/templates/invoice_settings_header_gateway.template.php')), |
|
112 | - $confirmation_text_input_name |
|
113 | - ); |
|
114 | - return $form; |
|
115 | - } |
|
67 | + 'extra_meta_inputs' => array( |
|
68 | + $pdf_payee_input_name => new EE_Text_Input(array( |
|
69 | + 'html_label_text' => sprintf(esc_html__('Payee Name %s', 'event_espresso'), $this->get_help_tab_link()) |
|
70 | + )), |
|
71 | + 'pdf_payee_email' => new EE_Email_Input(array( |
|
72 | + 'html_label_text' => sprintf(esc_html__('Payee Email %s', 'event_espresso'), $this->get_help_tab_link()), |
|
73 | + )), |
|
74 | + 'pdf_payee_tax_number' => new EE_Text_Input(array( |
|
75 | + 'html_label_text' => sprintf(esc_html__('Payee Tax Number %s', 'event_espresso'), $this->get_help_tab_link()), |
|
76 | + )), |
|
77 | + 'pdf_payee_address' => new EE_Text_Area_Input(array( |
|
78 | + 'html_label_text' => sprintf(esc_html__('Payee Address %s', 'event_espresso'), $this->get_help_tab_link()), |
|
79 | + 'validation_strategies' => array( new EE_Full_HTML_Validation_Strategy() ), |
|
80 | + )), |
|
81 | + 'pdf_instructions' => new EE_Text_Area_Input(array( |
|
82 | + 'html_label_text' => sprintf(esc_html__("Instructions %s", "event_espresso"), $this->get_help_tab_link()), |
|
83 | + 'default' => esc_html__("Please send this invoice with payment attached to the address above, or use the payment link below. Payment must be received within 48 hours of event date.", 'event_espresso'), |
|
84 | + 'validation_strategies' => array( new EE_Full_HTML_Validation_Strategy() ), |
|
85 | + )), |
|
86 | + 'pdf_logo_image' => new EE_Admin_File_Uploader_Input(array( |
|
87 | + 'html_label_text' => sprintf(esc_html__("Logo Image %s", "event_espresso"), $this->get_help_tab_link()), |
|
88 | + 'default' => EE_Config::instance()->organization->logo_url, |
|
89 | + 'html_help_text' => esc_html__("(Logo for the top left of the invoice)", 'event_espresso'), |
|
90 | + )), |
|
91 | + $confirmation_text_input_name => new EE_Text_Area_Input(array( |
|
92 | + 'html_label_text' => sprintf(esc_html__("Confirmation Text %s", "event_espresso"), $this->get_help_tab_link()), |
|
93 | + 'default' => esc_html__("Payment must be received within 48 hours of event date. Details about where to send the payment are included on the invoice.", 'event_espresso'), |
|
94 | + 'validation_strategies' => array( new EE_Full_HTML_Validation_Strategy() ), |
|
95 | + )), |
|
96 | + 'page_extra_info' => new EE_Text_Area_Input(array( |
|
97 | + 'html_label_text' => sprintf(esc_html__("Extra Info %s", "event_espresso"), $this->get_help_tab_link()), |
|
98 | + 'validation_strategies' => array( new EE_Full_HTML_Validation_Strategy() ), |
|
99 | + )), |
|
100 | + ), |
|
101 | + 'include' => array( |
|
102 | + 'PMD_ID', 'PMD_name','PMD_desc','PMD_admin_name','PMD_admin_desc', 'PMD_type','PMD_slug', 'PMD_open_by_default','PMD_button_url','PMD_scope','Currency','PMD_order', |
|
103 | + $pdf_payee_input_name, 'pdf_payee_email', 'pdf_payee_tax_number', 'pdf_payee_address', 'pdf_instructions','pdf_logo_image', |
|
104 | + $confirmation_text_input_name, 'page_extra_info'), |
|
105 | + )); |
|
106 | + $form->add_subsections( |
|
107 | + array( 'header1' => new EE_Form_Section_HTML_From_Template('payment_methods/Invoice/templates/invoice_settings_header_display.template.php')), |
|
108 | + $pdf_payee_input_name |
|
109 | + ); |
|
110 | + $form->add_subsections( |
|
111 | + array( 'header2' => new EE_Form_Section_HTML_From_Template('payment_methods/Invoice/templates/invoice_settings_header_gateway.template.php')), |
|
112 | + $confirmation_text_input_name |
|
113 | + ); |
|
114 | + return $form; |
|
115 | + } |
|
116 | 116 | |
117 | 117 | |
118 | 118 | |
119 | - /** |
|
120 | - * Adds the help tab |
|
121 | - * @see EE_PMT_Base::help_tabs_config() |
|
122 | - * @return array |
|
123 | - */ |
|
124 | - public function help_tabs_config() |
|
125 | - { |
|
126 | - return array( |
|
127 | - $this->get_help_tab_name() => array( |
|
128 | - 'title' => esc_html__('Invoice Settings', 'event_espresso'), |
|
129 | - 'filename' => 'payment_methods_overview_invoice' |
|
130 | - ), |
|
131 | - ); |
|
132 | - } |
|
119 | + /** |
|
120 | + * Adds the help tab |
|
121 | + * @see EE_PMT_Base::help_tabs_config() |
|
122 | + * @return array |
|
123 | + */ |
|
124 | + public function help_tabs_config() |
|
125 | + { |
|
126 | + return array( |
|
127 | + $this->get_help_tab_name() => array( |
|
128 | + 'title' => esc_html__('Invoice Settings', 'event_espresso'), |
|
129 | + 'filename' => 'payment_methods_overview_invoice' |
|
130 | + ), |
|
131 | + ); |
|
132 | + } |
|
133 | 133 | |
134 | 134 | |
135 | - /** |
|
136 | - * For adding any html output above the payment overview. |
|
137 | - * Many gateways won't want ot display anything, so this function just returns an empty string. |
|
138 | - * Other gateways may want to override this, such as offline gateways. |
|
139 | - * |
|
140 | - * @param \EE_Payment $payment |
|
141 | - * @return string |
|
142 | - */ |
|
143 | - public function payment_overview_content(EE_Payment $payment) |
|
144 | - { |
|
145 | - return EEH_Template::locate_template( |
|
146 | - 'payment_methods/Invoice/templates/invoice_payment_details_content.template.php', |
|
147 | - array_merge( |
|
148 | - array( |
|
149 | - 'payment_method' => $this->_pm_instance, |
|
150 | - 'payment' => $payment, |
|
151 | - 'page_confirmation_text' => '', |
|
152 | - 'page_extra_info' => '', |
|
153 | - 'invoice_url' => $payment->transaction()->primary_registration()->invoice_url('html') |
|
154 | - ), |
|
155 | - $this->_pm_instance->all_extra_meta_array() |
|
156 | - ) |
|
157 | - ); |
|
158 | - } |
|
135 | + /** |
|
136 | + * For adding any html output above the payment overview. |
|
137 | + * Many gateways won't want ot display anything, so this function just returns an empty string. |
|
138 | + * Other gateways may want to override this, such as offline gateways. |
|
139 | + * |
|
140 | + * @param \EE_Payment $payment |
|
141 | + * @return string |
|
142 | + */ |
|
143 | + public function payment_overview_content(EE_Payment $payment) |
|
144 | + { |
|
145 | + return EEH_Template::locate_template( |
|
146 | + 'payment_methods/Invoice/templates/invoice_payment_details_content.template.php', |
|
147 | + array_merge( |
|
148 | + array( |
|
149 | + 'payment_method' => $this->_pm_instance, |
|
150 | + 'payment' => $payment, |
|
151 | + 'page_confirmation_text' => '', |
|
152 | + 'page_extra_info' => '', |
|
153 | + 'invoice_url' => $payment->transaction()->primary_registration()->invoice_url('html') |
|
154 | + ), |
|
155 | + $this->_pm_instance->all_extra_meta_array() |
|
156 | + ) |
|
157 | + ); |
|
158 | + } |
|
159 | 159 | } |
@@ -1,6 +1,6 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | 3 | esc_html_e( |
4 | - 'Invoice is an offline payment method for accepting payments. Payments are processed manually by providing your registrants/attendees with information on how to pay their invoice.', |
|
5 | - 'event_espresso' |
|
4 | + 'Invoice is an offline payment method for accepting payments. Payments are processed manually by providing your registrants/attendees with information on how to pay their invoice.', |
|
5 | + 'event_espresso' |
|
6 | 6 | ); |
@@ -13,677 +13,677 @@ |
||
13 | 13 | |
14 | 14 | // Quickfix to address https://events.codebasehq.com/projects/event-espresso/tickets/11089 ASAP |
15 | 15 | if (! function_exists('mb_strcut')) { |
16 | - /** |
|
17 | - * Very simple mimic of mb_substr (which WP ensures exists in wp-includes/compat.php). Still has all the problems of mb_substr |
|
18 | - * (namely, that we might send too many characters to PayPal; however in this case they just issue a warning but nothing breaks) |
|
19 | - * @param $string |
|
20 | - * @param $start |
|
21 | - * @param $length |
|
22 | - * @return bool|string |
|
23 | - */ |
|
24 | - function mb_strcut($string, $start, $length = null) |
|
25 | - { |
|
26 | - return mb_substr($string, $start, $length); |
|
27 | - } |
|
16 | + /** |
|
17 | + * Very simple mimic of mb_substr (which WP ensures exists in wp-includes/compat.php). Still has all the problems of mb_substr |
|
18 | + * (namely, that we might send too many characters to PayPal; however in this case they just issue a warning but nothing breaks) |
|
19 | + * @param $string |
|
20 | + * @param $start |
|
21 | + * @param $length |
|
22 | + * @return bool|string |
|
23 | + */ |
|
24 | + function mb_strcut($string, $start, $length = null) |
|
25 | + { |
|
26 | + return mb_substr($string, $start, $length); |
|
27 | + } |
|
28 | 28 | } |
29 | 29 | class EEG_Paypal_Express extends EE_Offsite_Gateway |
30 | 30 | { |
31 | 31 | |
32 | - /** |
|
33 | - * Merchant API Username. |
|
34 | - * |
|
35 | - * @var string |
|
36 | - */ |
|
37 | - protected $_api_username; |
|
38 | - |
|
39 | - /** |
|
40 | - * Merchant API Password. |
|
41 | - * |
|
42 | - * @var string |
|
43 | - */ |
|
44 | - protected $_api_password; |
|
45 | - |
|
46 | - /** |
|
47 | - * API Signature. |
|
48 | - * |
|
49 | - * @var string |
|
50 | - */ |
|
51 | - protected $_api_signature; |
|
52 | - |
|
53 | - /** |
|
54 | - * Request Shipping address on PP checkout page. |
|
55 | - * |
|
56 | - * @var string |
|
57 | - */ |
|
58 | - protected $_request_shipping_addr; |
|
59 | - |
|
60 | - /** |
|
61 | - * Business/personal logo. |
|
62 | - * |
|
63 | - * @var string |
|
64 | - */ |
|
65 | - protected $_image_url; |
|
66 | - |
|
67 | - /** |
|
68 | - * gateway URL variable |
|
69 | - * |
|
70 | - * @var string |
|
71 | - */ |
|
72 | - protected $_base_gateway_url = ''; |
|
73 | - |
|
74 | - |
|
75 | - |
|
76 | - /** |
|
77 | - * EEG_Paypal_Express constructor. |
|
78 | - */ |
|
79 | - public function __construct() |
|
80 | - { |
|
81 | - $this->_currencies_supported = array( |
|
82 | - 'USD', |
|
83 | - 'AUD', |
|
84 | - 'BRL', |
|
85 | - 'CAD', |
|
86 | - 'CZK', |
|
87 | - 'DKK', |
|
88 | - 'EUR', |
|
89 | - 'HKD', |
|
90 | - 'HUF', |
|
91 | - 'ILS', |
|
92 | - 'JPY', |
|
93 | - 'MYR', |
|
94 | - 'MXN', |
|
95 | - 'NOK', |
|
96 | - 'NZD', |
|
97 | - 'PHP', |
|
98 | - 'PLN', |
|
99 | - 'GBP', |
|
100 | - 'RUB', |
|
101 | - 'SGD', |
|
102 | - 'SEK', |
|
103 | - 'CHF', |
|
104 | - 'TWD', |
|
105 | - 'THB', |
|
106 | - 'TRY', |
|
107 | - 'INR', |
|
108 | - ); |
|
109 | - parent::__construct(); |
|
110 | - } |
|
111 | - |
|
112 | - |
|
113 | - |
|
114 | - /** |
|
115 | - * Sets the gateway URL variable based on whether debug mode is enabled or not. |
|
116 | - * |
|
117 | - * @param array $settings_array |
|
118 | - */ |
|
119 | - public function set_settings($settings_array) |
|
120 | - { |
|
121 | - parent::set_settings($settings_array); |
|
122 | - // Redirect URL. |
|
123 | - $this->_base_gateway_url = $this->_debug_mode |
|
124 | - ? 'https://api-3t.sandbox.paypal.com/nvp' |
|
125 | - : 'https://api-3t.paypal.com/nvp'; |
|
126 | - } |
|
127 | - |
|
128 | - |
|
129 | - |
|
130 | - /** |
|
131 | - * @param EEI_Payment $payment |
|
132 | - * @param array $billing_info |
|
133 | - * @param string $return_url |
|
134 | - * @param string $notify_url |
|
135 | - * @param string $cancel_url |
|
136 | - * @return \EE_Payment|\EEI_Payment |
|
137 | - * @throws \EE_Error |
|
138 | - */ |
|
139 | - public function set_redirection_info( |
|
140 | - $payment, |
|
141 | - $billing_info = array(), |
|
142 | - $return_url = null, |
|
143 | - $notify_url = null, |
|
144 | - $cancel_url = null |
|
145 | - ) { |
|
146 | - if (! $payment instanceof EEI_Payment) { |
|
147 | - $payment->set_gateway_response( |
|
148 | - esc_html__( |
|
149 | - 'Error. No associated payment was found.', |
|
150 | - 'event_espresso' |
|
151 | - ) |
|
152 | - ); |
|
153 | - $payment->set_status($this->_pay_model->failed_status()); |
|
154 | - return $payment; |
|
155 | - } |
|
156 | - $transaction = $payment->transaction(); |
|
157 | - if (! $transaction instanceof EEI_Transaction) { |
|
158 | - $payment->set_gateway_response( |
|
159 | - esc_html__( |
|
160 | - 'Could not process this payment because it has no associated transaction.', |
|
161 | - 'event_espresso' |
|
162 | - ) |
|
163 | - ); |
|
164 | - $payment->set_status($this->_pay_model->failed_status()); |
|
165 | - return $payment; |
|
166 | - } |
|
167 | - $gateway_formatter = $this->_get_gateway_formatter(); |
|
168 | - $order_description = mb_strcut($gateway_formatter->formatOrderDescription($payment), 0, 127); |
|
169 | - $primary_registration = $transaction->primary_registration(); |
|
170 | - $primary_attendee = $primary_registration instanceof EE_Registration |
|
171 | - ? $primary_registration->attendee() |
|
172 | - : false; |
|
173 | - $locale = explode('-', get_bloginfo('language')); |
|
174 | - // Gather request parameters. |
|
175 | - $token_request_dtls = array( |
|
176 | - 'METHOD' => 'SetExpressCheckout', |
|
177 | - 'PAYMENTREQUEST_0_AMT' => $payment->amount(), |
|
178 | - 'PAYMENTREQUEST_0_CURRENCYCODE' => $payment->currency_code(), |
|
179 | - 'PAYMENTREQUEST_0_DESC' => $order_description, |
|
180 | - 'RETURNURL' => $return_url, |
|
181 | - 'CANCELURL' => $cancel_url, |
|
182 | - 'PAYMENTREQUEST_0_PAYMENTACTION' => 'Sale', |
|
183 | - // Buyer does not need to create a PayPal account to check out. |
|
184 | - // This is referred to as PayPal Account Optional. |
|
185 | - 'SOLUTIONTYPE' => 'Sole', |
|
186 | - // Locale of the pages displayed by PayPal during Express Checkout. |
|
187 | - 'LOCALECODE' => $locale[1] |
|
188 | - ); |
|
189 | - // Show itemized list. |
|
190 | - $itemized_list = $this->itemize_list($payment, $transaction); |
|
191 | - $token_request_dtls = array_merge($token_request_dtls, $itemized_list); |
|
192 | - // Automatically filling out shipping and contact information. |
|
193 | - if ($this->_request_shipping_addr && $primary_attendee instanceof EEI_Attendee) { |
|
194 | - // If you do not pass the shipping address, PayPal obtains it from the buyer's account profile. |
|
195 | - $token_request_dtls['NOSHIPPING'] = '2'; |
|
196 | - $token_request_dtls['PAYMENTREQUEST_0_SHIPTOSTREET'] = $primary_attendee->address(); |
|
197 | - $token_request_dtls['PAYMENTREQUEST_0_SHIPTOSTREET2'] = $primary_attendee->address2(); |
|
198 | - $token_request_dtls['PAYMENTREQUEST_0_SHIPTOCITY'] = $primary_attendee->city(); |
|
199 | - $token_request_dtls['PAYMENTREQUEST_0_SHIPTOSTATE'] = $primary_attendee->state_abbrev(); |
|
200 | - $token_request_dtls['PAYMENTREQUEST_0_SHIPTOCOUNTRYCODE'] = $primary_attendee->country_ID(); |
|
201 | - $token_request_dtls['PAYMENTREQUEST_0_SHIPTOZIP'] = $primary_attendee->zip(); |
|
202 | - $token_request_dtls['PAYMENTREQUEST_0_EMAIL'] = $primary_attendee->email(); |
|
203 | - $token_request_dtls['PAYMENTREQUEST_0_SHIPTOPHONENUM'] = $primary_attendee->phone(); |
|
204 | - } elseif (! $this->_request_shipping_addr) { |
|
205 | - // Do not request shipping details on the PP Checkout page. |
|
206 | - $token_request_dtls['NOSHIPPING'] = '1'; |
|
207 | - $token_request_dtls['REQCONFIRMSHIPPING'] = '0'; |
|
208 | - } |
|
209 | - // Used a business/personal logo on the PayPal page. |
|
210 | - if (! empty($this->_image_url)) { |
|
211 | - $token_request_dtls['LOGOIMG'] = $this->_image_url; |
|
212 | - } |
|
213 | - $token_request_dtls = apply_filters( |
|
214 | - 'FHEE__EEG_Paypal_Express__set_redirection_info__arguments', |
|
215 | - $token_request_dtls, |
|
216 | - $this |
|
217 | - ); |
|
218 | - // Request PayPal token. |
|
219 | - $token_request_response = $this->_ppExpress_request($token_request_dtls, 'Payment Token', $payment); |
|
220 | - $token_rstatus = $this->_ppExpress_check_response($token_request_response); |
|
221 | - $response_args = (isset($token_rstatus['args']) && is_array($token_rstatus['args'])) |
|
222 | - ? $token_rstatus['args'] |
|
223 | - : array(); |
|
224 | - if ($token_rstatus['status']) { |
|
225 | - // We got the Token so we may continue with the payment and redirect the client. |
|
226 | - $payment->set_details($response_args); |
|
227 | - $gateway_url = $this->_debug_mode ? 'https://www.sandbox.paypal.com' : 'https://www.paypal.com'; |
|
228 | - $payment->set_redirect_url( |
|
229 | - $gateway_url |
|
230 | - . '/checkoutnow?useraction=commit&cmd=_express-checkout&token=' |
|
231 | - . $response_args['TOKEN'] |
|
232 | - ); |
|
233 | - } else { |
|
234 | - if (isset($response_args['L_ERRORCODE'])) { |
|
235 | - $payment->set_gateway_response($response_args['L_ERRORCODE'] . '; ' . $response_args['L_SHORTMESSAGE']); |
|
236 | - } else { |
|
237 | - $payment->set_gateway_response( |
|
238 | - esc_html__( |
|
239 | - 'Error occurred while trying to setup the Express Checkout.', |
|
240 | - 'event_espresso' |
|
241 | - ) |
|
242 | - ); |
|
243 | - } |
|
244 | - $payment->set_details($response_args); |
|
245 | - $payment->set_status($this->_pay_model->failed_status()); |
|
246 | - } |
|
247 | - return $payment; |
|
248 | - } |
|
249 | - |
|
250 | - |
|
251 | - |
|
252 | - /** |
|
253 | - * @param array $update_info { |
|
254 | - * @type string $gateway_txn_id |
|
255 | - * @type string status an EEMI_Payment status |
|
256 | - * } |
|
257 | - * @param EEI_Transaction $transaction |
|
258 | - * @return EEI_Payment |
|
259 | - */ |
|
260 | - public function handle_payment_update($update_info, $transaction) |
|
261 | - { |
|
262 | - $payment = $transaction instanceof EEI_Transaction ? $transaction->last_payment() : null; |
|
263 | - if ($payment instanceof EEI_Payment) { |
|
264 | - $this->log(array('Return from Authorization' => $update_info), $payment); |
|
265 | - $transaction = $payment->transaction(); |
|
266 | - if (! $transaction instanceof EEI_Transaction) { |
|
267 | - $payment->set_gateway_response( |
|
268 | - esc_html__( |
|
269 | - 'Could not process this payment because it has no associated transaction.', |
|
270 | - 'event_espresso' |
|
271 | - ) |
|
272 | - ); |
|
273 | - $payment->set_status($this->_pay_model->failed_status()); |
|
274 | - return $payment; |
|
275 | - } |
|
276 | - $primary_registrant = $transaction->primary_registration(); |
|
277 | - $payment_details = $payment->details(); |
|
278 | - // Check if we still have the token. |
|
279 | - if (! isset($payment_details['TOKEN']) || empty($payment_details['TOKEN'])) { |
|
280 | - $payment->set_status($this->_pay_model->failed_status()); |
|
281 | - return $payment; |
|
282 | - } |
|
283 | - $cdetails_request_dtls = array( |
|
284 | - 'METHOD' => 'GetExpressCheckoutDetails', |
|
285 | - 'TOKEN' => $payment_details['TOKEN'], |
|
286 | - ); |
|
287 | - // Request Customer Details. |
|
288 | - $cdetails_request_response = $this->_ppExpress_request( |
|
289 | - $cdetails_request_dtls, |
|
290 | - 'Customer Details', |
|
291 | - $payment |
|
292 | - ); |
|
293 | - $cdetails_rstatus = $this->_ppExpress_check_response($cdetails_request_response); |
|
294 | - $cdata_response_args = (isset($cdetails_rstatus['args']) && is_array($cdetails_rstatus['args'])) |
|
295 | - ? $cdetails_rstatus['args'] |
|
296 | - : array(); |
|
297 | - if ($cdetails_rstatus['status']) { |
|
298 | - // We got the PayerID so now we can Complete the transaction. |
|
299 | - $docheckout_request_dtls = array( |
|
300 | - 'METHOD' => 'DoExpressCheckoutPayment', |
|
301 | - 'PAYERID' => $cdata_response_args['PAYERID'], |
|
302 | - 'TOKEN' => $payment_details['TOKEN'], |
|
303 | - 'PAYMENTREQUEST_0_PAYMENTACTION' => 'Sale', |
|
304 | - 'PAYMENTREQUEST_0_AMT' => $payment->amount(), |
|
305 | - 'PAYMENTREQUEST_0_CURRENCYCODE' => $payment->currency_code(), |
|
306 | - ); |
|
307 | - // Include itemized list. |
|
308 | - $itemized_list = $this->itemize_list( |
|
309 | - $payment, |
|
310 | - $transaction, |
|
311 | - $cdata_response_args |
|
312 | - ); |
|
313 | - $docheckout_request_dtls = array_merge($docheckout_request_dtls, $itemized_list); |
|
314 | - // Payment Checkout/Capture. |
|
315 | - $docheckout_request_response = $this->_ppExpress_request( |
|
316 | - $docheckout_request_dtls, |
|
317 | - 'Do Payment', |
|
318 | - $payment |
|
319 | - ); |
|
320 | - $docheckout_rstatus = $this->_ppExpress_check_response($docheckout_request_response); |
|
321 | - $docheckout_response_args = (isset($docheckout_rstatus['args']) && is_array($docheckout_rstatus['args'])) |
|
322 | - ? $docheckout_rstatus['args'] |
|
323 | - : array(); |
|
324 | - if ($docheckout_rstatus['status']) { |
|
325 | - // All is well, payment approved. |
|
326 | - $primary_registration_code = $primary_registrant instanceof EE_Registration ? |
|
327 | - $primary_registrant->reg_code() |
|
328 | - : ''; |
|
329 | - $payment->set_extra_accntng($primary_registration_code); |
|
330 | - $payment->set_amount(isset($docheckout_response_args['PAYMENTINFO_0_AMT']) |
|
331 | - ? (float) $docheckout_response_args['PAYMENTINFO_0_AMT'] |
|
332 | - : 0); |
|
333 | - $payment->set_txn_id_chq_nmbr(isset($docheckout_response_args['PAYMENTINFO_0_TRANSACTIONID']) |
|
334 | - ? $docheckout_response_args['PAYMENTINFO_0_TRANSACTIONID'] |
|
335 | - : null); |
|
336 | - $payment->set_details($cdata_response_args); |
|
337 | - $payment->set_gateway_response(isset($docheckout_response_args['PAYMENTINFO_0_ACK']) |
|
338 | - ? $docheckout_response_args['PAYMENTINFO_0_ACK'] |
|
339 | - : ''); |
|
340 | - $payment->set_status($this->_pay_model->approved_status()); |
|
341 | - } else { |
|
342 | - if (isset($docheckout_response_args['L_ERRORCODE'])) { |
|
343 | - $payment->set_gateway_response( |
|
344 | - $docheckout_response_args['L_ERRORCODE'] |
|
345 | - . '; ' |
|
346 | - . $docheckout_response_args['L_SHORTMESSAGE'] |
|
347 | - ); |
|
348 | - } else { |
|
349 | - $payment->set_gateway_response( |
|
350 | - esc_html__( |
|
351 | - 'Error occurred while trying to Capture the funds.', |
|
352 | - 'event_espresso' |
|
353 | - ) |
|
354 | - ); |
|
355 | - } |
|
356 | - $payment->set_details($docheckout_response_args); |
|
357 | - $payment->set_status($this->_pay_model->declined_status()); |
|
358 | - } |
|
359 | - } else { |
|
360 | - if (isset($cdata_response_args['L_ERRORCODE'])) { |
|
361 | - $payment->set_gateway_response( |
|
362 | - $cdata_response_args['L_ERRORCODE'] |
|
363 | - . '; ' |
|
364 | - . $cdata_response_args['L_SHORTMESSAGE'] |
|
365 | - ); |
|
366 | - } else { |
|
367 | - $payment->set_gateway_response( |
|
368 | - esc_html__( |
|
369 | - 'Error occurred while trying to get payment Details from PayPal.', |
|
370 | - 'event_espresso' |
|
371 | - ) |
|
372 | - ); |
|
373 | - } |
|
374 | - $payment->set_details($cdata_response_args); |
|
375 | - $payment->set_status($this->_pay_model->failed_status()); |
|
376 | - } |
|
377 | - } else { |
|
378 | - $payment->set_gateway_response( |
|
379 | - esc_html__( |
|
380 | - 'Error occurred while trying to process the payment.', |
|
381 | - 'event_espresso' |
|
382 | - ) |
|
383 | - ); |
|
384 | - $payment->set_status($this->_pay_model->failed_status()); |
|
385 | - } |
|
386 | - return $payment; |
|
387 | - } |
|
388 | - |
|
389 | - |
|
390 | - |
|
391 | - /** |
|
392 | - * Make a list of items that are in the giver transaction. |
|
393 | - * |
|
394 | - * @param EEI_Payment $payment |
|
395 | - * @param EEI_Transaction $transaction |
|
396 | - * @param array $request_response_args Data from a previous communication with PP. |
|
397 | - * @return array |
|
398 | - */ |
|
399 | - public function itemize_list(EEI_Payment $payment, EEI_Transaction $transaction, $request_response_args = array()) |
|
400 | - { |
|
401 | - $itemized_list = array(); |
|
402 | - $gateway_formatter = $this->_get_gateway_formatter(); |
|
403 | - // If we have data from a previous communication with PP (on this transaction) we may use that for our list... |
|
404 | - if ( |
|
405 | - ! empty($request_response_args) |
|
406 | - && array_key_exists('L_PAYMENTREQUEST_0_AMT0', $request_response_args) |
|
407 | - && array_key_exists('PAYMENTREQUEST_0_ITEMAMT', $request_response_args) |
|
408 | - ) { |
|
409 | - foreach ($request_response_args as $arg_key => $arg_val) { |
|
410 | - if ( |
|
411 | - strpos($arg_key, 'PAYMENTREQUEST_') !== false |
|
412 | - && strpos($arg_key, 'NOTIFYURL') === false |
|
413 | - ) { |
|
414 | - $itemized_list[ $arg_key ] = $arg_val; |
|
415 | - } |
|
416 | - } |
|
417 | - // If we got only a few Items then something is not right. |
|
418 | - if (count($itemized_list) > 2) { |
|
419 | - return $itemized_list; |
|
420 | - } else { |
|
421 | - if (WP_DEBUG) { |
|
422 | - throw new EE_Error( |
|
423 | - sprintf( |
|
424 | - esc_html__( |
|
425 | - // @codingStandardsIgnoreStart |
|
426 | - 'Unable to continue with the checkout because a proper purchase list could not be generated. The purchased list we could have sent was %1$s', |
|
427 | - // @codingStandardsIgnoreEnd |
|
428 | - 'event_espresso' |
|
429 | - ), |
|
430 | - wp_json_encode($itemized_list) |
|
431 | - ) |
|
432 | - ); |
|
433 | - } |
|
434 | - // Reset the list and log an error, maybe allow to try and generate a new list (below). |
|
435 | - $itemized_list = array(); |
|
436 | - $this->log( |
|
437 | - array( |
|
438 | - (string) esc_html__( |
|
439 | - 'Could not generate a proper item list with:', |
|
440 | - 'event_espresso' |
|
441 | - ) => $request_response_args |
|
442 | - ), |
|
443 | - $payment |
|
444 | - ); |
|
445 | - } |
|
446 | - } |
|
447 | - // ...otherwise we generate a new list for this transaction. |
|
448 | - if ($this->_money->compare_floats($payment->amount(), $transaction->total(), '==')) { |
|
449 | - $item_num = 0; |
|
450 | - $itemized_sum = 0; |
|
451 | - $total_line_items = $transaction->total_line_item(); |
|
452 | - // Go through each item in the list. |
|
453 | - foreach ($total_line_items->get_items() as $line_item) { |
|
454 | - if ($line_item instanceof EE_Line_Item) { |
|
455 | - // PayPal doesn't like line items with 0.00 amount, so we may skip those. |
|
456 | - if (EEH_Money::compare_floats($line_item->total(), '0.00', '==')) { |
|
457 | - continue; |
|
458 | - } |
|
459 | - $unit_price = $line_item->unit_price(); |
|
460 | - $line_item_quantity = $line_item->quantity(); |
|
461 | - // This is a discount. |
|
462 | - if ($line_item->is_percent()) { |
|
463 | - $unit_price = $line_item->total(); |
|
464 | - $line_item_quantity = 1; |
|
465 | - } |
|
466 | - // Item Name. |
|
467 | - $itemized_list[ 'L_PAYMENTREQUEST_0_NAME' . $item_num ] = mb_strcut( |
|
468 | - $gateway_formatter->formatLineItemName($line_item, $payment), |
|
469 | - 0, |
|
470 | - 127 |
|
471 | - ); |
|
472 | - // Item description. |
|
473 | - $itemized_list[ 'L_PAYMENTREQUEST_0_DESC' . $item_num ] = mb_strcut( |
|
474 | - $gateway_formatter->formatLineItemDesc($line_item, $payment), |
|
475 | - 0, |
|
476 | - 127 |
|
477 | - ); |
|
478 | - // Cost of individual item. |
|
479 | - $itemized_list[ 'L_PAYMENTREQUEST_0_AMT' . $item_num ] = $gateway_formatter->formatCurrency($unit_price); |
|
480 | - // Item Number. |
|
481 | - $itemized_list[ 'L_PAYMENTREQUEST_0_NUMBER' . $item_num ] = $item_num + 1; |
|
482 | - // Item quantity. |
|
483 | - $itemized_list[ 'L_PAYMENTREQUEST_0_QTY' . $item_num ] = $line_item_quantity; |
|
484 | - // Digital item is sold. |
|
485 | - $itemized_list[ 'L_PAYMENTREQUEST_0_ITEMCATEGORY' . $item_num ] = 'Physical'; |
|
486 | - $itemized_sum += $line_item->total(); |
|
487 | - ++$item_num; |
|
488 | - } |
|
489 | - } |
|
490 | - // Item's sales S/H and tax amount. |
|
491 | - $itemized_list['PAYMENTREQUEST_0_ITEMAMT'] = $total_line_items->get_items_total(); |
|
492 | - $itemized_list['PAYMENTREQUEST_0_TAXAMT'] = $total_line_items->get_total_tax(); |
|
493 | - $itemized_list['PAYMENTREQUEST_0_SHIPPINGAMT'] = '0'; |
|
494 | - $itemized_list['PAYMENTREQUEST_0_HANDLINGAMT'] = '0'; |
|
495 | - $itemized_sum_diff_from_txn_total = round( |
|
496 | - $transaction->total() - $itemized_sum - $total_line_items->get_total_tax(), |
|
497 | - 2 |
|
498 | - ); |
|
499 | - // If we were not able to recognize some item like promotion, surcharge or cancellation, |
|
500 | - // add the difference as an extra line item. |
|
501 | - if ($this->_money->compare_floats($itemized_sum_diff_from_txn_total, 0, '!=')) { |
|
502 | - // Item Name. |
|
503 | - $itemized_list[ 'L_PAYMENTREQUEST_0_NAME' . $item_num ] = mb_strcut( |
|
504 | - esc_html__( |
|
505 | - 'Other (promotion/surcharge/cancellation)', |
|
506 | - 'event_espresso' |
|
507 | - ), |
|
508 | - 0, |
|
509 | - 127 |
|
510 | - ); |
|
511 | - // Item description. |
|
512 | - $itemized_list[ 'L_PAYMENTREQUEST_0_DESC' . $item_num ] = ''; |
|
513 | - // Cost of individual item. |
|
514 | - $itemized_list[ 'L_PAYMENTREQUEST_0_AMT' . $item_num ] = $gateway_formatter->formatCurrency( |
|
515 | - $itemized_sum_diff_from_txn_total |
|
516 | - ); |
|
517 | - // Item Number. |
|
518 | - $itemized_list[ 'L_PAYMENTREQUEST_0_NUMBER' . $item_num ] = $item_num + 1; |
|
519 | - // Item quantity. |
|
520 | - $itemized_list[ 'L_PAYMENTREQUEST_0_QTY' . $item_num ] = 1; |
|
521 | - // Digital item is sold. |
|
522 | - $itemized_list[ 'L_PAYMENTREQUEST_0_ITEMCATEGORY' . $item_num ] = 'Physical'; |
|
523 | - $item_num++; |
|
524 | - } |
|
525 | - } else { |
|
526 | - // Just one Item. |
|
527 | - // Item Name. |
|
528 | - $itemized_list['L_PAYMENTREQUEST_0_NAME0'] = mb_strcut( |
|
529 | - $gateway_formatter->formatPartialPaymentLineItemName($payment), |
|
530 | - 0, |
|
531 | - 127 |
|
532 | - ); |
|
533 | - // Item description. |
|
534 | - $itemized_list['L_PAYMENTREQUEST_0_DESC0'] = mb_strcut( |
|
535 | - $gateway_formatter->formatPartialPaymentLineItemDesc($payment), |
|
536 | - 0, |
|
537 | - 127 |
|
538 | - ); |
|
539 | - // Cost of individual item. |
|
540 | - $itemized_list['L_PAYMENTREQUEST_0_AMT0'] = $gateway_formatter->formatCurrency($payment->amount()); |
|
541 | - // Item Number. |
|
542 | - $itemized_list['L_PAYMENTREQUEST_0_NUMBER0'] = 1; |
|
543 | - // Item quantity. |
|
544 | - $itemized_list['L_PAYMENTREQUEST_0_QTY0'] = 1; |
|
545 | - // Digital item is sold. |
|
546 | - $itemized_list['L_PAYMENTREQUEST_0_ITEMCATEGORY0'] = 'Physical'; |
|
547 | - // Item's sales S/H and tax amount. |
|
548 | - $itemized_list['PAYMENTREQUEST_0_ITEMAMT'] = $gateway_formatter->formatCurrency($payment->amount()); |
|
549 | - $itemized_list['PAYMENTREQUEST_0_TAXAMT'] = '0'; |
|
550 | - $itemized_list['PAYMENTREQUEST_0_SHIPPINGAMT'] = '0'; |
|
551 | - $itemized_list['PAYMENTREQUEST_0_HANDLINGAMT'] = '0'; |
|
552 | - } |
|
553 | - return $itemized_list; |
|
554 | - } |
|
555 | - |
|
556 | - |
|
557 | - |
|
558 | - /** |
|
559 | - * Make the Express checkout request. |
|
560 | - * |
|
561 | - * @param array $request_params |
|
562 | - * @param string $request_text |
|
563 | - * @param EEI_Payment $payment |
|
564 | - * @return mixed |
|
565 | - */ |
|
566 | - public function _ppExpress_request($request_params, $request_text, $payment) |
|
567 | - { |
|
568 | - $request_dtls = array( |
|
569 | - 'VERSION' => '204.0', |
|
570 | - 'USER' => $this->_api_username, |
|
571 | - 'PWD' => $this->_api_password, |
|
572 | - 'SIGNATURE' => $this->_api_signature, |
|
573 | - // EE will blow up if you change this |
|
574 | - 'BUTTONSOURCE' => 'EventEspresso_SP', |
|
575 | - ); |
|
576 | - $dtls = array_merge($request_dtls, $request_params); |
|
577 | - $this->_log_clean_request($dtls, $payment, $request_text . ' Request'); |
|
578 | - // Request Customer Details. |
|
579 | - $request_response = wp_remote_post( |
|
580 | - $this->_base_gateway_url, |
|
581 | - array( |
|
582 | - 'method' => 'POST', |
|
583 | - 'timeout' => 45, |
|
584 | - 'httpversion' => '1.1', |
|
585 | - 'cookies' => array(), |
|
586 | - 'headers' => array(), |
|
587 | - 'body' => http_build_query($dtls, '', '&'), |
|
588 | - ) |
|
589 | - ); |
|
590 | - // Log the response. |
|
591 | - $this->log(array($request_text . ' Response' => $request_response), $payment); |
|
592 | - return $request_response; |
|
593 | - } |
|
594 | - |
|
595 | - |
|
596 | - |
|
597 | - /** |
|
598 | - * Check the response status. |
|
599 | - * |
|
600 | - * @param mixed $request_response |
|
601 | - * @return array |
|
602 | - */ |
|
603 | - public function _ppExpress_check_response($request_response) |
|
604 | - { |
|
605 | - if (is_wp_error($request_response) || empty($request_response['body'])) { |
|
606 | - // If we got here then there was an error in this request. |
|
607 | - return array('status' => false, 'args' => $request_response); |
|
608 | - } |
|
609 | - $response_args = array(); |
|
610 | - parse_str(urldecode($request_response['body']), $response_args); |
|
611 | - if (! isset($response_args['ACK'])) { |
|
612 | - return array('status' => false, 'args' => $request_response); |
|
613 | - } |
|
614 | - if ( |
|
615 | - ( |
|
616 | - isset($response_args['PAYERID']) |
|
617 | - || isset($response_args['TOKEN']) |
|
618 | - || isset($response_args['PAYMENTINFO_0_TRANSACTIONID']) |
|
619 | - || (isset($response_args['PAYMENTSTATUS']) && $response_args['PAYMENTSTATUS'] === 'Completed') |
|
620 | - ) |
|
621 | - && in_array($response_args['ACK'], array('Success', 'SuccessWithWarning'), true) |
|
622 | - ) { |
|
623 | - // Response status OK, return response parameters for further processing. |
|
624 | - return array('status' => true, 'args' => $response_args); |
|
625 | - } |
|
626 | - $errors = $this->_get_errors($response_args); |
|
627 | - return array('status' => false, 'args' => $errors); |
|
628 | - } |
|
629 | - |
|
630 | - |
|
631 | - |
|
632 | - /** |
|
633 | - * Log a "Cleared" request. |
|
634 | - * |
|
635 | - * @param array $request |
|
636 | - * @param EEI_Payment $payment |
|
637 | - * @param string $info |
|
638 | - * @return void |
|
639 | - */ |
|
640 | - private function _log_clean_request($request, $payment, $info) |
|
641 | - { |
|
642 | - $cleaned_request_data = $request; |
|
643 | - unset($cleaned_request_data['PWD'], $cleaned_request_data['USER'], $cleaned_request_data['SIGNATURE']); |
|
644 | - $this->log(array($info => $cleaned_request_data), $payment); |
|
645 | - } |
|
646 | - |
|
647 | - |
|
648 | - |
|
649 | - /** |
|
650 | - * Get error from the response data. |
|
651 | - * |
|
652 | - * @param array $data_array |
|
653 | - * @return array |
|
654 | - */ |
|
655 | - private function _get_errors($data_array) |
|
656 | - { |
|
657 | - $errors = array(); |
|
658 | - $n = 0; |
|
659 | - while (isset($data_array[ "L_ERRORCODE{$n}" ])) { |
|
660 | - $l_error_code = isset($data_array[ "L_ERRORCODE{$n}" ]) |
|
661 | - ? $data_array[ "L_ERRORCODE{$n}" ] |
|
662 | - : ''; |
|
663 | - $l_severity_code = isset($data_array[ "L_SEVERITYCODE{$n}" ]) |
|
664 | - ? $data_array[ "L_SEVERITYCODE{$n}" ] |
|
665 | - : ''; |
|
666 | - $l_short_message = isset($data_array[ "L_SHORTMESSAGE{$n}" ]) |
|
667 | - ? $data_array[ "L_SHORTMESSAGE{$n}" ] |
|
668 | - : ''; |
|
669 | - $l_long_message = isset($data_array[ "L_LONGMESSAGE{$n}" ]) |
|
670 | - ? $data_array[ "L_LONGMESSAGE{$n}" ] |
|
671 | - : ''; |
|
672 | - if ($n === 0) { |
|
673 | - $errors = array( |
|
674 | - 'L_ERRORCODE' => $l_error_code, |
|
675 | - 'L_SHORTMESSAGE' => $l_short_message, |
|
676 | - 'L_LONGMESSAGE' => $l_long_message, |
|
677 | - 'L_SEVERITYCODE' => $l_severity_code, |
|
678 | - ); |
|
679 | - } else { |
|
680 | - $errors['L_ERRORCODE'] .= ', ' . $l_error_code; |
|
681 | - $errors['L_SHORTMESSAGE'] .= ', ' . $l_short_message; |
|
682 | - $errors['L_LONGMESSAGE'] .= ', ' . $l_long_message; |
|
683 | - $errors['L_SEVERITYCODE'] .= ', ' . $l_severity_code; |
|
684 | - } |
|
685 | - $n++; |
|
686 | - } |
|
687 | - return $errors; |
|
688 | - } |
|
32 | + /** |
|
33 | + * Merchant API Username. |
|
34 | + * |
|
35 | + * @var string |
|
36 | + */ |
|
37 | + protected $_api_username; |
|
38 | + |
|
39 | + /** |
|
40 | + * Merchant API Password. |
|
41 | + * |
|
42 | + * @var string |
|
43 | + */ |
|
44 | + protected $_api_password; |
|
45 | + |
|
46 | + /** |
|
47 | + * API Signature. |
|
48 | + * |
|
49 | + * @var string |
|
50 | + */ |
|
51 | + protected $_api_signature; |
|
52 | + |
|
53 | + /** |
|
54 | + * Request Shipping address on PP checkout page. |
|
55 | + * |
|
56 | + * @var string |
|
57 | + */ |
|
58 | + protected $_request_shipping_addr; |
|
59 | + |
|
60 | + /** |
|
61 | + * Business/personal logo. |
|
62 | + * |
|
63 | + * @var string |
|
64 | + */ |
|
65 | + protected $_image_url; |
|
66 | + |
|
67 | + /** |
|
68 | + * gateway URL variable |
|
69 | + * |
|
70 | + * @var string |
|
71 | + */ |
|
72 | + protected $_base_gateway_url = ''; |
|
73 | + |
|
74 | + |
|
75 | + |
|
76 | + /** |
|
77 | + * EEG_Paypal_Express constructor. |
|
78 | + */ |
|
79 | + public function __construct() |
|
80 | + { |
|
81 | + $this->_currencies_supported = array( |
|
82 | + 'USD', |
|
83 | + 'AUD', |
|
84 | + 'BRL', |
|
85 | + 'CAD', |
|
86 | + 'CZK', |
|
87 | + 'DKK', |
|
88 | + 'EUR', |
|
89 | + 'HKD', |
|
90 | + 'HUF', |
|
91 | + 'ILS', |
|
92 | + 'JPY', |
|
93 | + 'MYR', |
|
94 | + 'MXN', |
|
95 | + 'NOK', |
|
96 | + 'NZD', |
|
97 | + 'PHP', |
|
98 | + 'PLN', |
|
99 | + 'GBP', |
|
100 | + 'RUB', |
|
101 | + 'SGD', |
|
102 | + 'SEK', |
|
103 | + 'CHF', |
|
104 | + 'TWD', |
|
105 | + 'THB', |
|
106 | + 'TRY', |
|
107 | + 'INR', |
|
108 | + ); |
|
109 | + parent::__construct(); |
|
110 | + } |
|
111 | + |
|
112 | + |
|
113 | + |
|
114 | + /** |
|
115 | + * Sets the gateway URL variable based on whether debug mode is enabled or not. |
|
116 | + * |
|
117 | + * @param array $settings_array |
|
118 | + */ |
|
119 | + public function set_settings($settings_array) |
|
120 | + { |
|
121 | + parent::set_settings($settings_array); |
|
122 | + // Redirect URL. |
|
123 | + $this->_base_gateway_url = $this->_debug_mode |
|
124 | + ? 'https://api-3t.sandbox.paypal.com/nvp' |
|
125 | + : 'https://api-3t.paypal.com/nvp'; |
|
126 | + } |
|
127 | + |
|
128 | + |
|
129 | + |
|
130 | + /** |
|
131 | + * @param EEI_Payment $payment |
|
132 | + * @param array $billing_info |
|
133 | + * @param string $return_url |
|
134 | + * @param string $notify_url |
|
135 | + * @param string $cancel_url |
|
136 | + * @return \EE_Payment|\EEI_Payment |
|
137 | + * @throws \EE_Error |
|
138 | + */ |
|
139 | + public function set_redirection_info( |
|
140 | + $payment, |
|
141 | + $billing_info = array(), |
|
142 | + $return_url = null, |
|
143 | + $notify_url = null, |
|
144 | + $cancel_url = null |
|
145 | + ) { |
|
146 | + if (! $payment instanceof EEI_Payment) { |
|
147 | + $payment->set_gateway_response( |
|
148 | + esc_html__( |
|
149 | + 'Error. No associated payment was found.', |
|
150 | + 'event_espresso' |
|
151 | + ) |
|
152 | + ); |
|
153 | + $payment->set_status($this->_pay_model->failed_status()); |
|
154 | + return $payment; |
|
155 | + } |
|
156 | + $transaction = $payment->transaction(); |
|
157 | + if (! $transaction instanceof EEI_Transaction) { |
|
158 | + $payment->set_gateway_response( |
|
159 | + esc_html__( |
|
160 | + 'Could not process this payment because it has no associated transaction.', |
|
161 | + 'event_espresso' |
|
162 | + ) |
|
163 | + ); |
|
164 | + $payment->set_status($this->_pay_model->failed_status()); |
|
165 | + return $payment; |
|
166 | + } |
|
167 | + $gateway_formatter = $this->_get_gateway_formatter(); |
|
168 | + $order_description = mb_strcut($gateway_formatter->formatOrderDescription($payment), 0, 127); |
|
169 | + $primary_registration = $transaction->primary_registration(); |
|
170 | + $primary_attendee = $primary_registration instanceof EE_Registration |
|
171 | + ? $primary_registration->attendee() |
|
172 | + : false; |
|
173 | + $locale = explode('-', get_bloginfo('language')); |
|
174 | + // Gather request parameters. |
|
175 | + $token_request_dtls = array( |
|
176 | + 'METHOD' => 'SetExpressCheckout', |
|
177 | + 'PAYMENTREQUEST_0_AMT' => $payment->amount(), |
|
178 | + 'PAYMENTREQUEST_0_CURRENCYCODE' => $payment->currency_code(), |
|
179 | + 'PAYMENTREQUEST_0_DESC' => $order_description, |
|
180 | + 'RETURNURL' => $return_url, |
|
181 | + 'CANCELURL' => $cancel_url, |
|
182 | + 'PAYMENTREQUEST_0_PAYMENTACTION' => 'Sale', |
|
183 | + // Buyer does not need to create a PayPal account to check out. |
|
184 | + // This is referred to as PayPal Account Optional. |
|
185 | + 'SOLUTIONTYPE' => 'Sole', |
|
186 | + // Locale of the pages displayed by PayPal during Express Checkout. |
|
187 | + 'LOCALECODE' => $locale[1] |
|
188 | + ); |
|
189 | + // Show itemized list. |
|
190 | + $itemized_list = $this->itemize_list($payment, $transaction); |
|
191 | + $token_request_dtls = array_merge($token_request_dtls, $itemized_list); |
|
192 | + // Automatically filling out shipping and contact information. |
|
193 | + if ($this->_request_shipping_addr && $primary_attendee instanceof EEI_Attendee) { |
|
194 | + // If you do not pass the shipping address, PayPal obtains it from the buyer's account profile. |
|
195 | + $token_request_dtls['NOSHIPPING'] = '2'; |
|
196 | + $token_request_dtls['PAYMENTREQUEST_0_SHIPTOSTREET'] = $primary_attendee->address(); |
|
197 | + $token_request_dtls['PAYMENTREQUEST_0_SHIPTOSTREET2'] = $primary_attendee->address2(); |
|
198 | + $token_request_dtls['PAYMENTREQUEST_0_SHIPTOCITY'] = $primary_attendee->city(); |
|
199 | + $token_request_dtls['PAYMENTREQUEST_0_SHIPTOSTATE'] = $primary_attendee->state_abbrev(); |
|
200 | + $token_request_dtls['PAYMENTREQUEST_0_SHIPTOCOUNTRYCODE'] = $primary_attendee->country_ID(); |
|
201 | + $token_request_dtls['PAYMENTREQUEST_0_SHIPTOZIP'] = $primary_attendee->zip(); |
|
202 | + $token_request_dtls['PAYMENTREQUEST_0_EMAIL'] = $primary_attendee->email(); |
|
203 | + $token_request_dtls['PAYMENTREQUEST_0_SHIPTOPHONENUM'] = $primary_attendee->phone(); |
|
204 | + } elseif (! $this->_request_shipping_addr) { |
|
205 | + // Do not request shipping details on the PP Checkout page. |
|
206 | + $token_request_dtls['NOSHIPPING'] = '1'; |
|
207 | + $token_request_dtls['REQCONFIRMSHIPPING'] = '0'; |
|
208 | + } |
|
209 | + // Used a business/personal logo on the PayPal page. |
|
210 | + if (! empty($this->_image_url)) { |
|
211 | + $token_request_dtls['LOGOIMG'] = $this->_image_url; |
|
212 | + } |
|
213 | + $token_request_dtls = apply_filters( |
|
214 | + 'FHEE__EEG_Paypal_Express__set_redirection_info__arguments', |
|
215 | + $token_request_dtls, |
|
216 | + $this |
|
217 | + ); |
|
218 | + // Request PayPal token. |
|
219 | + $token_request_response = $this->_ppExpress_request($token_request_dtls, 'Payment Token', $payment); |
|
220 | + $token_rstatus = $this->_ppExpress_check_response($token_request_response); |
|
221 | + $response_args = (isset($token_rstatus['args']) && is_array($token_rstatus['args'])) |
|
222 | + ? $token_rstatus['args'] |
|
223 | + : array(); |
|
224 | + if ($token_rstatus['status']) { |
|
225 | + // We got the Token so we may continue with the payment and redirect the client. |
|
226 | + $payment->set_details($response_args); |
|
227 | + $gateway_url = $this->_debug_mode ? 'https://www.sandbox.paypal.com' : 'https://www.paypal.com'; |
|
228 | + $payment->set_redirect_url( |
|
229 | + $gateway_url |
|
230 | + . '/checkoutnow?useraction=commit&cmd=_express-checkout&token=' |
|
231 | + . $response_args['TOKEN'] |
|
232 | + ); |
|
233 | + } else { |
|
234 | + if (isset($response_args['L_ERRORCODE'])) { |
|
235 | + $payment->set_gateway_response($response_args['L_ERRORCODE'] . '; ' . $response_args['L_SHORTMESSAGE']); |
|
236 | + } else { |
|
237 | + $payment->set_gateway_response( |
|
238 | + esc_html__( |
|
239 | + 'Error occurred while trying to setup the Express Checkout.', |
|
240 | + 'event_espresso' |
|
241 | + ) |
|
242 | + ); |
|
243 | + } |
|
244 | + $payment->set_details($response_args); |
|
245 | + $payment->set_status($this->_pay_model->failed_status()); |
|
246 | + } |
|
247 | + return $payment; |
|
248 | + } |
|
249 | + |
|
250 | + |
|
251 | + |
|
252 | + /** |
|
253 | + * @param array $update_info { |
|
254 | + * @type string $gateway_txn_id |
|
255 | + * @type string status an EEMI_Payment status |
|
256 | + * } |
|
257 | + * @param EEI_Transaction $transaction |
|
258 | + * @return EEI_Payment |
|
259 | + */ |
|
260 | + public function handle_payment_update($update_info, $transaction) |
|
261 | + { |
|
262 | + $payment = $transaction instanceof EEI_Transaction ? $transaction->last_payment() : null; |
|
263 | + if ($payment instanceof EEI_Payment) { |
|
264 | + $this->log(array('Return from Authorization' => $update_info), $payment); |
|
265 | + $transaction = $payment->transaction(); |
|
266 | + if (! $transaction instanceof EEI_Transaction) { |
|
267 | + $payment->set_gateway_response( |
|
268 | + esc_html__( |
|
269 | + 'Could not process this payment because it has no associated transaction.', |
|
270 | + 'event_espresso' |
|
271 | + ) |
|
272 | + ); |
|
273 | + $payment->set_status($this->_pay_model->failed_status()); |
|
274 | + return $payment; |
|
275 | + } |
|
276 | + $primary_registrant = $transaction->primary_registration(); |
|
277 | + $payment_details = $payment->details(); |
|
278 | + // Check if we still have the token. |
|
279 | + if (! isset($payment_details['TOKEN']) || empty($payment_details['TOKEN'])) { |
|
280 | + $payment->set_status($this->_pay_model->failed_status()); |
|
281 | + return $payment; |
|
282 | + } |
|
283 | + $cdetails_request_dtls = array( |
|
284 | + 'METHOD' => 'GetExpressCheckoutDetails', |
|
285 | + 'TOKEN' => $payment_details['TOKEN'], |
|
286 | + ); |
|
287 | + // Request Customer Details. |
|
288 | + $cdetails_request_response = $this->_ppExpress_request( |
|
289 | + $cdetails_request_dtls, |
|
290 | + 'Customer Details', |
|
291 | + $payment |
|
292 | + ); |
|
293 | + $cdetails_rstatus = $this->_ppExpress_check_response($cdetails_request_response); |
|
294 | + $cdata_response_args = (isset($cdetails_rstatus['args']) && is_array($cdetails_rstatus['args'])) |
|
295 | + ? $cdetails_rstatus['args'] |
|
296 | + : array(); |
|
297 | + if ($cdetails_rstatus['status']) { |
|
298 | + // We got the PayerID so now we can Complete the transaction. |
|
299 | + $docheckout_request_dtls = array( |
|
300 | + 'METHOD' => 'DoExpressCheckoutPayment', |
|
301 | + 'PAYERID' => $cdata_response_args['PAYERID'], |
|
302 | + 'TOKEN' => $payment_details['TOKEN'], |
|
303 | + 'PAYMENTREQUEST_0_PAYMENTACTION' => 'Sale', |
|
304 | + 'PAYMENTREQUEST_0_AMT' => $payment->amount(), |
|
305 | + 'PAYMENTREQUEST_0_CURRENCYCODE' => $payment->currency_code(), |
|
306 | + ); |
|
307 | + // Include itemized list. |
|
308 | + $itemized_list = $this->itemize_list( |
|
309 | + $payment, |
|
310 | + $transaction, |
|
311 | + $cdata_response_args |
|
312 | + ); |
|
313 | + $docheckout_request_dtls = array_merge($docheckout_request_dtls, $itemized_list); |
|
314 | + // Payment Checkout/Capture. |
|
315 | + $docheckout_request_response = $this->_ppExpress_request( |
|
316 | + $docheckout_request_dtls, |
|
317 | + 'Do Payment', |
|
318 | + $payment |
|
319 | + ); |
|
320 | + $docheckout_rstatus = $this->_ppExpress_check_response($docheckout_request_response); |
|
321 | + $docheckout_response_args = (isset($docheckout_rstatus['args']) && is_array($docheckout_rstatus['args'])) |
|
322 | + ? $docheckout_rstatus['args'] |
|
323 | + : array(); |
|
324 | + if ($docheckout_rstatus['status']) { |
|
325 | + // All is well, payment approved. |
|
326 | + $primary_registration_code = $primary_registrant instanceof EE_Registration ? |
|
327 | + $primary_registrant->reg_code() |
|
328 | + : ''; |
|
329 | + $payment->set_extra_accntng($primary_registration_code); |
|
330 | + $payment->set_amount(isset($docheckout_response_args['PAYMENTINFO_0_AMT']) |
|
331 | + ? (float) $docheckout_response_args['PAYMENTINFO_0_AMT'] |
|
332 | + : 0); |
|
333 | + $payment->set_txn_id_chq_nmbr(isset($docheckout_response_args['PAYMENTINFO_0_TRANSACTIONID']) |
|
334 | + ? $docheckout_response_args['PAYMENTINFO_0_TRANSACTIONID'] |
|
335 | + : null); |
|
336 | + $payment->set_details($cdata_response_args); |
|
337 | + $payment->set_gateway_response(isset($docheckout_response_args['PAYMENTINFO_0_ACK']) |
|
338 | + ? $docheckout_response_args['PAYMENTINFO_0_ACK'] |
|
339 | + : ''); |
|
340 | + $payment->set_status($this->_pay_model->approved_status()); |
|
341 | + } else { |
|
342 | + if (isset($docheckout_response_args['L_ERRORCODE'])) { |
|
343 | + $payment->set_gateway_response( |
|
344 | + $docheckout_response_args['L_ERRORCODE'] |
|
345 | + . '; ' |
|
346 | + . $docheckout_response_args['L_SHORTMESSAGE'] |
|
347 | + ); |
|
348 | + } else { |
|
349 | + $payment->set_gateway_response( |
|
350 | + esc_html__( |
|
351 | + 'Error occurred while trying to Capture the funds.', |
|
352 | + 'event_espresso' |
|
353 | + ) |
|
354 | + ); |
|
355 | + } |
|
356 | + $payment->set_details($docheckout_response_args); |
|
357 | + $payment->set_status($this->_pay_model->declined_status()); |
|
358 | + } |
|
359 | + } else { |
|
360 | + if (isset($cdata_response_args['L_ERRORCODE'])) { |
|
361 | + $payment->set_gateway_response( |
|
362 | + $cdata_response_args['L_ERRORCODE'] |
|
363 | + . '; ' |
|
364 | + . $cdata_response_args['L_SHORTMESSAGE'] |
|
365 | + ); |
|
366 | + } else { |
|
367 | + $payment->set_gateway_response( |
|
368 | + esc_html__( |
|
369 | + 'Error occurred while trying to get payment Details from PayPal.', |
|
370 | + 'event_espresso' |
|
371 | + ) |
|
372 | + ); |
|
373 | + } |
|
374 | + $payment->set_details($cdata_response_args); |
|
375 | + $payment->set_status($this->_pay_model->failed_status()); |
|
376 | + } |
|
377 | + } else { |
|
378 | + $payment->set_gateway_response( |
|
379 | + esc_html__( |
|
380 | + 'Error occurred while trying to process the payment.', |
|
381 | + 'event_espresso' |
|
382 | + ) |
|
383 | + ); |
|
384 | + $payment->set_status($this->_pay_model->failed_status()); |
|
385 | + } |
|
386 | + return $payment; |
|
387 | + } |
|
388 | + |
|
389 | + |
|
390 | + |
|
391 | + /** |
|
392 | + * Make a list of items that are in the giver transaction. |
|
393 | + * |
|
394 | + * @param EEI_Payment $payment |
|
395 | + * @param EEI_Transaction $transaction |
|
396 | + * @param array $request_response_args Data from a previous communication with PP. |
|
397 | + * @return array |
|
398 | + */ |
|
399 | + public function itemize_list(EEI_Payment $payment, EEI_Transaction $transaction, $request_response_args = array()) |
|
400 | + { |
|
401 | + $itemized_list = array(); |
|
402 | + $gateway_formatter = $this->_get_gateway_formatter(); |
|
403 | + // If we have data from a previous communication with PP (on this transaction) we may use that for our list... |
|
404 | + if ( |
|
405 | + ! empty($request_response_args) |
|
406 | + && array_key_exists('L_PAYMENTREQUEST_0_AMT0', $request_response_args) |
|
407 | + && array_key_exists('PAYMENTREQUEST_0_ITEMAMT', $request_response_args) |
|
408 | + ) { |
|
409 | + foreach ($request_response_args as $arg_key => $arg_val) { |
|
410 | + if ( |
|
411 | + strpos($arg_key, 'PAYMENTREQUEST_') !== false |
|
412 | + && strpos($arg_key, 'NOTIFYURL') === false |
|
413 | + ) { |
|
414 | + $itemized_list[ $arg_key ] = $arg_val; |
|
415 | + } |
|
416 | + } |
|
417 | + // If we got only a few Items then something is not right. |
|
418 | + if (count($itemized_list) > 2) { |
|
419 | + return $itemized_list; |
|
420 | + } else { |
|
421 | + if (WP_DEBUG) { |
|
422 | + throw new EE_Error( |
|
423 | + sprintf( |
|
424 | + esc_html__( |
|
425 | + // @codingStandardsIgnoreStart |
|
426 | + 'Unable to continue with the checkout because a proper purchase list could not be generated. The purchased list we could have sent was %1$s', |
|
427 | + // @codingStandardsIgnoreEnd |
|
428 | + 'event_espresso' |
|
429 | + ), |
|
430 | + wp_json_encode($itemized_list) |
|
431 | + ) |
|
432 | + ); |
|
433 | + } |
|
434 | + // Reset the list and log an error, maybe allow to try and generate a new list (below). |
|
435 | + $itemized_list = array(); |
|
436 | + $this->log( |
|
437 | + array( |
|
438 | + (string) esc_html__( |
|
439 | + 'Could not generate a proper item list with:', |
|
440 | + 'event_espresso' |
|
441 | + ) => $request_response_args |
|
442 | + ), |
|
443 | + $payment |
|
444 | + ); |
|
445 | + } |
|
446 | + } |
|
447 | + // ...otherwise we generate a new list for this transaction. |
|
448 | + if ($this->_money->compare_floats($payment->amount(), $transaction->total(), '==')) { |
|
449 | + $item_num = 0; |
|
450 | + $itemized_sum = 0; |
|
451 | + $total_line_items = $transaction->total_line_item(); |
|
452 | + // Go through each item in the list. |
|
453 | + foreach ($total_line_items->get_items() as $line_item) { |
|
454 | + if ($line_item instanceof EE_Line_Item) { |
|
455 | + // PayPal doesn't like line items with 0.00 amount, so we may skip those. |
|
456 | + if (EEH_Money::compare_floats($line_item->total(), '0.00', '==')) { |
|
457 | + continue; |
|
458 | + } |
|
459 | + $unit_price = $line_item->unit_price(); |
|
460 | + $line_item_quantity = $line_item->quantity(); |
|
461 | + // This is a discount. |
|
462 | + if ($line_item->is_percent()) { |
|
463 | + $unit_price = $line_item->total(); |
|
464 | + $line_item_quantity = 1; |
|
465 | + } |
|
466 | + // Item Name. |
|
467 | + $itemized_list[ 'L_PAYMENTREQUEST_0_NAME' . $item_num ] = mb_strcut( |
|
468 | + $gateway_formatter->formatLineItemName($line_item, $payment), |
|
469 | + 0, |
|
470 | + 127 |
|
471 | + ); |
|
472 | + // Item description. |
|
473 | + $itemized_list[ 'L_PAYMENTREQUEST_0_DESC' . $item_num ] = mb_strcut( |
|
474 | + $gateway_formatter->formatLineItemDesc($line_item, $payment), |
|
475 | + 0, |
|
476 | + 127 |
|
477 | + ); |
|
478 | + // Cost of individual item. |
|
479 | + $itemized_list[ 'L_PAYMENTREQUEST_0_AMT' . $item_num ] = $gateway_formatter->formatCurrency($unit_price); |
|
480 | + // Item Number. |
|
481 | + $itemized_list[ 'L_PAYMENTREQUEST_0_NUMBER' . $item_num ] = $item_num + 1; |
|
482 | + // Item quantity. |
|
483 | + $itemized_list[ 'L_PAYMENTREQUEST_0_QTY' . $item_num ] = $line_item_quantity; |
|
484 | + // Digital item is sold. |
|
485 | + $itemized_list[ 'L_PAYMENTREQUEST_0_ITEMCATEGORY' . $item_num ] = 'Physical'; |
|
486 | + $itemized_sum += $line_item->total(); |
|
487 | + ++$item_num; |
|
488 | + } |
|
489 | + } |
|
490 | + // Item's sales S/H and tax amount. |
|
491 | + $itemized_list['PAYMENTREQUEST_0_ITEMAMT'] = $total_line_items->get_items_total(); |
|
492 | + $itemized_list['PAYMENTREQUEST_0_TAXAMT'] = $total_line_items->get_total_tax(); |
|
493 | + $itemized_list['PAYMENTREQUEST_0_SHIPPINGAMT'] = '0'; |
|
494 | + $itemized_list['PAYMENTREQUEST_0_HANDLINGAMT'] = '0'; |
|
495 | + $itemized_sum_diff_from_txn_total = round( |
|
496 | + $transaction->total() - $itemized_sum - $total_line_items->get_total_tax(), |
|
497 | + 2 |
|
498 | + ); |
|
499 | + // If we were not able to recognize some item like promotion, surcharge or cancellation, |
|
500 | + // add the difference as an extra line item. |
|
501 | + if ($this->_money->compare_floats($itemized_sum_diff_from_txn_total, 0, '!=')) { |
|
502 | + // Item Name. |
|
503 | + $itemized_list[ 'L_PAYMENTREQUEST_0_NAME' . $item_num ] = mb_strcut( |
|
504 | + esc_html__( |
|
505 | + 'Other (promotion/surcharge/cancellation)', |
|
506 | + 'event_espresso' |
|
507 | + ), |
|
508 | + 0, |
|
509 | + 127 |
|
510 | + ); |
|
511 | + // Item description. |
|
512 | + $itemized_list[ 'L_PAYMENTREQUEST_0_DESC' . $item_num ] = ''; |
|
513 | + // Cost of individual item. |
|
514 | + $itemized_list[ 'L_PAYMENTREQUEST_0_AMT' . $item_num ] = $gateway_formatter->formatCurrency( |
|
515 | + $itemized_sum_diff_from_txn_total |
|
516 | + ); |
|
517 | + // Item Number. |
|
518 | + $itemized_list[ 'L_PAYMENTREQUEST_0_NUMBER' . $item_num ] = $item_num + 1; |
|
519 | + // Item quantity. |
|
520 | + $itemized_list[ 'L_PAYMENTREQUEST_0_QTY' . $item_num ] = 1; |
|
521 | + // Digital item is sold. |
|
522 | + $itemized_list[ 'L_PAYMENTREQUEST_0_ITEMCATEGORY' . $item_num ] = 'Physical'; |
|
523 | + $item_num++; |
|
524 | + } |
|
525 | + } else { |
|
526 | + // Just one Item. |
|
527 | + // Item Name. |
|
528 | + $itemized_list['L_PAYMENTREQUEST_0_NAME0'] = mb_strcut( |
|
529 | + $gateway_formatter->formatPartialPaymentLineItemName($payment), |
|
530 | + 0, |
|
531 | + 127 |
|
532 | + ); |
|
533 | + // Item description. |
|
534 | + $itemized_list['L_PAYMENTREQUEST_0_DESC0'] = mb_strcut( |
|
535 | + $gateway_formatter->formatPartialPaymentLineItemDesc($payment), |
|
536 | + 0, |
|
537 | + 127 |
|
538 | + ); |
|
539 | + // Cost of individual item. |
|
540 | + $itemized_list['L_PAYMENTREQUEST_0_AMT0'] = $gateway_formatter->formatCurrency($payment->amount()); |
|
541 | + // Item Number. |
|
542 | + $itemized_list['L_PAYMENTREQUEST_0_NUMBER0'] = 1; |
|
543 | + // Item quantity. |
|
544 | + $itemized_list['L_PAYMENTREQUEST_0_QTY0'] = 1; |
|
545 | + // Digital item is sold. |
|
546 | + $itemized_list['L_PAYMENTREQUEST_0_ITEMCATEGORY0'] = 'Physical'; |
|
547 | + // Item's sales S/H and tax amount. |
|
548 | + $itemized_list['PAYMENTREQUEST_0_ITEMAMT'] = $gateway_formatter->formatCurrency($payment->amount()); |
|
549 | + $itemized_list['PAYMENTREQUEST_0_TAXAMT'] = '0'; |
|
550 | + $itemized_list['PAYMENTREQUEST_0_SHIPPINGAMT'] = '0'; |
|
551 | + $itemized_list['PAYMENTREQUEST_0_HANDLINGAMT'] = '0'; |
|
552 | + } |
|
553 | + return $itemized_list; |
|
554 | + } |
|
555 | + |
|
556 | + |
|
557 | + |
|
558 | + /** |
|
559 | + * Make the Express checkout request. |
|
560 | + * |
|
561 | + * @param array $request_params |
|
562 | + * @param string $request_text |
|
563 | + * @param EEI_Payment $payment |
|
564 | + * @return mixed |
|
565 | + */ |
|
566 | + public function _ppExpress_request($request_params, $request_text, $payment) |
|
567 | + { |
|
568 | + $request_dtls = array( |
|
569 | + 'VERSION' => '204.0', |
|
570 | + 'USER' => $this->_api_username, |
|
571 | + 'PWD' => $this->_api_password, |
|
572 | + 'SIGNATURE' => $this->_api_signature, |
|
573 | + // EE will blow up if you change this |
|
574 | + 'BUTTONSOURCE' => 'EventEspresso_SP', |
|
575 | + ); |
|
576 | + $dtls = array_merge($request_dtls, $request_params); |
|
577 | + $this->_log_clean_request($dtls, $payment, $request_text . ' Request'); |
|
578 | + // Request Customer Details. |
|
579 | + $request_response = wp_remote_post( |
|
580 | + $this->_base_gateway_url, |
|
581 | + array( |
|
582 | + 'method' => 'POST', |
|
583 | + 'timeout' => 45, |
|
584 | + 'httpversion' => '1.1', |
|
585 | + 'cookies' => array(), |
|
586 | + 'headers' => array(), |
|
587 | + 'body' => http_build_query($dtls, '', '&'), |
|
588 | + ) |
|
589 | + ); |
|
590 | + // Log the response. |
|
591 | + $this->log(array($request_text . ' Response' => $request_response), $payment); |
|
592 | + return $request_response; |
|
593 | + } |
|
594 | + |
|
595 | + |
|
596 | + |
|
597 | + /** |
|
598 | + * Check the response status. |
|
599 | + * |
|
600 | + * @param mixed $request_response |
|
601 | + * @return array |
|
602 | + */ |
|
603 | + public function _ppExpress_check_response($request_response) |
|
604 | + { |
|
605 | + if (is_wp_error($request_response) || empty($request_response['body'])) { |
|
606 | + // If we got here then there was an error in this request. |
|
607 | + return array('status' => false, 'args' => $request_response); |
|
608 | + } |
|
609 | + $response_args = array(); |
|
610 | + parse_str(urldecode($request_response['body']), $response_args); |
|
611 | + if (! isset($response_args['ACK'])) { |
|
612 | + return array('status' => false, 'args' => $request_response); |
|
613 | + } |
|
614 | + if ( |
|
615 | + ( |
|
616 | + isset($response_args['PAYERID']) |
|
617 | + || isset($response_args['TOKEN']) |
|
618 | + || isset($response_args['PAYMENTINFO_0_TRANSACTIONID']) |
|
619 | + || (isset($response_args['PAYMENTSTATUS']) && $response_args['PAYMENTSTATUS'] === 'Completed') |
|
620 | + ) |
|
621 | + && in_array($response_args['ACK'], array('Success', 'SuccessWithWarning'), true) |
|
622 | + ) { |
|
623 | + // Response status OK, return response parameters for further processing. |
|
624 | + return array('status' => true, 'args' => $response_args); |
|
625 | + } |
|
626 | + $errors = $this->_get_errors($response_args); |
|
627 | + return array('status' => false, 'args' => $errors); |
|
628 | + } |
|
629 | + |
|
630 | + |
|
631 | + |
|
632 | + /** |
|
633 | + * Log a "Cleared" request. |
|
634 | + * |
|
635 | + * @param array $request |
|
636 | + * @param EEI_Payment $payment |
|
637 | + * @param string $info |
|
638 | + * @return void |
|
639 | + */ |
|
640 | + private function _log_clean_request($request, $payment, $info) |
|
641 | + { |
|
642 | + $cleaned_request_data = $request; |
|
643 | + unset($cleaned_request_data['PWD'], $cleaned_request_data['USER'], $cleaned_request_data['SIGNATURE']); |
|
644 | + $this->log(array($info => $cleaned_request_data), $payment); |
|
645 | + } |
|
646 | + |
|
647 | + |
|
648 | + |
|
649 | + /** |
|
650 | + * Get error from the response data. |
|
651 | + * |
|
652 | + * @param array $data_array |
|
653 | + * @return array |
|
654 | + */ |
|
655 | + private function _get_errors($data_array) |
|
656 | + { |
|
657 | + $errors = array(); |
|
658 | + $n = 0; |
|
659 | + while (isset($data_array[ "L_ERRORCODE{$n}" ])) { |
|
660 | + $l_error_code = isset($data_array[ "L_ERRORCODE{$n}" ]) |
|
661 | + ? $data_array[ "L_ERRORCODE{$n}" ] |
|
662 | + : ''; |
|
663 | + $l_severity_code = isset($data_array[ "L_SEVERITYCODE{$n}" ]) |
|
664 | + ? $data_array[ "L_SEVERITYCODE{$n}" ] |
|
665 | + : ''; |
|
666 | + $l_short_message = isset($data_array[ "L_SHORTMESSAGE{$n}" ]) |
|
667 | + ? $data_array[ "L_SHORTMESSAGE{$n}" ] |
|
668 | + : ''; |
|
669 | + $l_long_message = isset($data_array[ "L_LONGMESSAGE{$n}" ]) |
|
670 | + ? $data_array[ "L_LONGMESSAGE{$n}" ] |
|
671 | + : ''; |
|
672 | + if ($n === 0) { |
|
673 | + $errors = array( |
|
674 | + 'L_ERRORCODE' => $l_error_code, |
|
675 | + 'L_SHORTMESSAGE' => $l_short_message, |
|
676 | + 'L_LONGMESSAGE' => $l_long_message, |
|
677 | + 'L_SEVERITYCODE' => $l_severity_code, |
|
678 | + ); |
|
679 | + } else { |
|
680 | + $errors['L_ERRORCODE'] .= ', ' . $l_error_code; |
|
681 | + $errors['L_SHORTMESSAGE'] .= ', ' . $l_short_message; |
|
682 | + $errors['L_LONGMESSAGE'] .= ', ' . $l_long_message; |
|
683 | + $errors['L_SEVERITYCODE'] .= ', ' . $l_severity_code; |
|
684 | + } |
|
685 | + $n++; |
|
686 | + } |
|
687 | + return $errors; |
|
688 | + } |
|
689 | 689 | } |
@@ -12,7 +12,7 @@ discard block |
||
12 | 12 | */ |
13 | 13 | |
14 | 14 | // Quickfix to address https://events.codebasehq.com/projects/event-espresso/tickets/11089 ASAP |
15 | -if (! function_exists('mb_strcut')) { |
|
15 | +if ( ! function_exists('mb_strcut')) { |
|
16 | 16 | /** |
17 | 17 | * Very simple mimic of mb_substr (which WP ensures exists in wp-includes/compat.php). Still has all the problems of mb_substr |
18 | 18 | * (namely, that we might send too many characters to PayPal; however in this case they just issue a warning but nothing breaks) |
@@ -143,7 +143,7 @@ discard block |
||
143 | 143 | $notify_url = null, |
144 | 144 | $cancel_url = null |
145 | 145 | ) { |
146 | - if (! $payment instanceof EEI_Payment) { |
|
146 | + if ( ! $payment instanceof EEI_Payment) { |
|
147 | 147 | $payment->set_gateway_response( |
148 | 148 | esc_html__( |
149 | 149 | 'Error. No associated payment was found.', |
@@ -154,7 +154,7 @@ discard block |
||
154 | 154 | return $payment; |
155 | 155 | } |
156 | 156 | $transaction = $payment->transaction(); |
157 | - if (! $transaction instanceof EEI_Transaction) { |
|
157 | + if ( ! $transaction instanceof EEI_Transaction) { |
|
158 | 158 | $payment->set_gateway_response( |
159 | 159 | esc_html__( |
160 | 160 | 'Could not process this payment because it has no associated transaction.', |
@@ -201,13 +201,13 @@ discard block |
||
201 | 201 | $token_request_dtls['PAYMENTREQUEST_0_SHIPTOZIP'] = $primary_attendee->zip(); |
202 | 202 | $token_request_dtls['PAYMENTREQUEST_0_EMAIL'] = $primary_attendee->email(); |
203 | 203 | $token_request_dtls['PAYMENTREQUEST_0_SHIPTOPHONENUM'] = $primary_attendee->phone(); |
204 | - } elseif (! $this->_request_shipping_addr) { |
|
204 | + } elseif ( ! $this->_request_shipping_addr) { |
|
205 | 205 | // Do not request shipping details on the PP Checkout page. |
206 | 206 | $token_request_dtls['NOSHIPPING'] = '1'; |
207 | 207 | $token_request_dtls['REQCONFIRMSHIPPING'] = '0'; |
208 | 208 | } |
209 | 209 | // Used a business/personal logo on the PayPal page. |
210 | - if (! empty($this->_image_url)) { |
|
210 | + if ( ! empty($this->_image_url)) { |
|
211 | 211 | $token_request_dtls['LOGOIMG'] = $this->_image_url; |
212 | 212 | } |
213 | 213 | $token_request_dtls = apply_filters( |
@@ -232,7 +232,7 @@ discard block |
||
232 | 232 | ); |
233 | 233 | } else { |
234 | 234 | if (isset($response_args['L_ERRORCODE'])) { |
235 | - $payment->set_gateway_response($response_args['L_ERRORCODE'] . '; ' . $response_args['L_SHORTMESSAGE']); |
|
235 | + $payment->set_gateway_response($response_args['L_ERRORCODE'].'; '.$response_args['L_SHORTMESSAGE']); |
|
236 | 236 | } else { |
237 | 237 | $payment->set_gateway_response( |
238 | 238 | esc_html__( |
@@ -263,7 +263,7 @@ discard block |
||
263 | 263 | if ($payment instanceof EEI_Payment) { |
264 | 264 | $this->log(array('Return from Authorization' => $update_info), $payment); |
265 | 265 | $transaction = $payment->transaction(); |
266 | - if (! $transaction instanceof EEI_Transaction) { |
|
266 | + if ( ! $transaction instanceof EEI_Transaction) { |
|
267 | 267 | $payment->set_gateway_response( |
268 | 268 | esc_html__( |
269 | 269 | 'Could not process this payment because it has no associated transaction.', |
@@ -276,7 +276,7 @@ discard block |
||
276 | 276 | $primary_registrant = $transaction->primary_registration(); |
277 | 277 | $payment_details = $payment->details(); |
278 | 278 | // Check if we still have the token. |
279 | - if (! isset($payment_details['TOKEN']) || empty($payment_details['TOKEN'])) { |
|
279 | + if ( ! isset($payment_details['TOKEN']) || empty($payment_details['TOKEN'])) { |
|
280 | 280 | $payment->set_status($this->_pay_model->failed_status()); |
281 | 281 | return $payment; |
282 | 282 | } |
@@ -411,7 +411,7 @@ discard block |
||
411 | 411 | strpos($arg_key, 'PAYMENTREQUEST_') !== false |
412 | 412 | && strpos($arg_key, 'NOTIFYURL') === false |
413 | 413 | ) { |
414 | - $itemized_list[ $arg_key ] = $arg_val; |
|
414 | + $itemized_list[$arg_key] = $arg_val; |
|
415 | 415 | } |
416 | 416 | } |
417 | 417 | // If we got only a few Items then something is not right. |
@@ -464,25 +464,25 @@ discard block |
||
464 | 464 | $line_item_quantity = 1; |
465 | 465 | } |
466 | 466 | // Item Name. |
467 | - $itemized_list[ 'L_PAYMENTREQUEST_0_NAME' . $item_num ] = mb_strcut( |
|
467 | + $itemized_list['L_PAYMENTREQUEST_0_NAME'.$item_num] = mb_strcut( |
|
468 | 468 | $gateway_formatter->formatLineItemName($line_item, $payment), |
469 | 469 | 0, |
470 | 470 | 127 |
471 | 471 | ); |
472 | 472 | // Item description. |
473 | - $itemized_list[ 'L_PAYMENTREQUEST_0_DESC' . $item_num ] = mb_strcut( |
|
473 | + $itemized_list['L_PAYMENTREQUEST_0_DESC'.$item_num] = mb_strcut( |
|
474 | 474 | $gateway_formatter->formatLineItemDesc($line_item, $payment), |
475 | 475 | 0, |
476 | 476 | 127 |
477 | 477 | ); |
478 | 478 | // Cost of individual item. |
479 | - $itemized_list[ 'L_PAYMENTREQUEST_0_AMT' . $item_num ] = $gateway_formatter->formatCurrency($unit_price); |
|
479 | + $itemized_list['L_PAYMENTREQUEST_0_AMT'.$item_num] = $gateway_formatter->formatCurrency($unit_price); |
|
480 | 480 | // Item Number. |
481 | - $itemized_list[ 'L_PAYMENTREQUEST_0_NUMBER' . $item_num ] = $item_num + 1; |
|
481 | + $itemized_list['L_PAYMENTREQUEST_0_NUMBER'.$item_num] = $item_num + 1; |
|
482 | 482 | // Item quantity. |
483 | - $itemized_list[ 'L_PAYMENTREQUEST_0_QTY' . $item_num ] = $line_item_quantity; |
|
483 | + $itemized_list['L_PAYMENTREQUEST_0_QTY'.$item_num] = $line_item_quantity; |
|
484 | 484 | // Digital item is sold. |
485 | - $itemized_list[ 'L_PAYMENTREQUEST_0_ITEMCATEGORY' . $item_num ] = 'Physical'; |
|
485 | + $itemized_list['L_PAYMENTREQUEST_0_ITEMCATEGORY'.$item_num] = 'Physical'; |
|
486 | 486 | $itemized_sum += $line_item->total(); |
487 | 487 | ++$item_num; |
488 | 488 | } |
@@ -500,7 +500,7 @@ discard block |
||
500 | 500 | // add the difference as an extra line item. |
501 | 501 | if ($this->_money->compare_floats($itemized_sum_diff_from_txn_total, 0, '!=')) { |
502 | 502 | // Item Name. |
503 | - $itemized_list[ 'L_PAYMENTREQUEST_0_NAME' . $item_num ] = mb_strcut( |
|
503 | + $itemized_list['L_PAYMENTREQUEST_0_NAME'.$item_num] = mb_strcut( |
|
504 | 504 | esc_html__( |
505 | 505 | 'Other (promotion/surcharge/cancellation)', |
506 | 506 | 'event_espresso' |
@@ -509,17 +509,17 @@ discard block |
||
509 | 509 | 127 |
510 | 510 | ); |
511 | 511 | // Item description. |
512 | - $itemized_list[ 'L_PAYMENTREQUEST_0_DESC' . $item_num ] = ''; |
|
512 | + $itemized_list['L_PAYMENTREQUEST_0_DESC'.$item_num] = ''; |
|
513 | 513 | // Cost of individual item. |
514 | - $itemized_list[ 'L_PAYMENTREQUEST_0_AMT' . $item_num ] = $gateway_formatter->formatCurrency( |
|
514 | + $itemized_list['L_PAYMENTREQUEST_0_AMT'.$item_num] = $gateway_formatter->formatCurrency( |
|
515 | 515 | $itemized_sum_diff_from_txn_total |
516 | 516 | ); |
517 | 517 | // Item Number. |
518 | - $itemized_list[ 'L_PAYMENTREQUEST_0_NUMBER' . $item_num ] = $item_num + 1; |
|
518 | + $itemized_list['L_PAYMENTREQUEST_0_NUMBER'.$item_num] = $item_num + 1; |
|
519 | 519 | // Item quantity. |
520 | - $itemized_list[ 'L_PAYMENTREQUEST_0_QTY' . $item_num ] = 1; |
|
520 | + $itemized_list['L_PAYMENTREQUEST_0_QTY'.$item_num] = 1; |
|
521 | 521 | // Digital item is sold. |
522 | - $itemized_list[ 'L_PAYMENTREQUEST_0_ITEMCATEGORY' . $item_num ] = 'Physical'; |
|
522 | + $itemized_list['L_PAYMENTREQUEST_0_ITEMCATEGORY'.$item_num] = 'Physical'; |
|
523 | 523 | $item_num++; |
524 | 524 | } |
525 | 525 | } else { |
@@ -574,7 +574,7 @@ discard block |
||
574 | 574 | 'BUTTONSOURCE' => 'EventEspresso_SP', |
575 | 575 | ); |
576 | 576 | $dtls = array_merge($request_dtls, $request_params); |
577 | - $this->_log_clean_request($dtls, $payment, $request_text . ' Request'); |
|
577 | + $this->_log_clean_request($dtls, $payment, $request_text.' Request'); |
|
578 | 578 | // Request Customer Details. |
579 | 579 | $request_response = wp_remote_post( |
580 | 580 | $this->_base_gateway_url, |
@@ -588,7 +588,7 @@ discard block |
||
588 | 588 | ) |
589 | 589 | ); |
590 | 590 | // Log the response. |
591 | - $this->log(array($request_text . ' Response' => $request_response), $payment); |
|
591 | + $this->log(array($request_text.' Response' => $request_response), $payment); |
|
592 | 592 | return $request_response; |
593 | 593 | } |
594 | 594 | |
@@ -608,7 +608,7 @@ discard block |
||
608 | 608 | } |
609 | 609 | $response_args = array(); |
610 | 610 | parse_str(urldecode($request_response['body']), $response_args); |
611 | - if (! isset($response_args['ACK'])) { |
|
611 | + if ( ! isset($response_args['ACK'])) { |
|
612 | 612 | return array('status' => false, 'args' => $request_response); |
613 | 613 | } |
614 | 614 | if ( |
@@ -656,18 +656,18 @@ discard block |
||
656 | 656 | { |
657 | 657 | $errors = array(); |
658 | 658 | $n = 0; |
659 | - while (isset($data_array[ "L_ERRORCODE{$n}" ])) { |
|
660 | - $l_error_code = isset($data_array[ "L_ERRORCODE{$n}" ]) |
|
661 | - ? $data_array[ "L_ERRORCODE{$n}" ] |
|
659 | + while (isset($data_array["L_ERRORCODE{$n}"])) { |
|
660 | + $l_error_code = isset($data_array["L_ERRORCODE{$n}"]) |
|
661 | + ? $data_array["L_ERRORCODE{$n}"] |
|
662 | 662 | : ''; |
663 | - $l_severity_code = isset($data_array[ "L_SEVERITYCODE{$n}" ]) |
|
664 | - ? $data_array[ "L_SEVERITYCODE{$n}" ] |
|
663 | + $l_severity_code = isset($data_array["L_SEVERITYCODE{$n}"]) |
|
664 | + ? $data_array["L_SEVERITYCODE{$n}"] |
|
665 | 665 | : ''; |
666 | - $l_short_message = isset($data_array[ "L_SHORTMESSAGE{$n}" ]) |
|
667 | - ? $data_array[ "L_SHORTMESSAGE{$n}" ] |
|
666 | + $l_short_message = isset($data_array["L_SHORTMESSAGE{$n}"]) |
|
667 | + ? $data_array["L_SHORTMESSAGE{$n}"] |
|
668 | 668 | : ''; |
669 | - $l_long_message = isset($data_array[ "L_LONGMESSAGE{$n}" ]) |
|
670 | - ? $data_array[ "L_LONGMESSAGE{$n}" ] |
|
669 | + $l_long_message = isset($data_array["L_LONGMESSAGE{$n}"]) |
|
670 | + ? $data_array["L_LONGMESSAGE{$n}"] |
|
671 | 671 | : ''; |
672 | 672 | if ($n === 0) { |
673 | 673 | $errors = array( |
@@ -677,10 +677,10 @@ discard block |
||
677 | 677 | 'L_SEVERITYCODE' => $l_severity_code, |
678 | 678 | ); |
679 | 679 | } else { |
680 | - $errors['L_ERRORCODE'] .= ', ' . $l_error_code; |
|
681 | - $errors['L_SHORTMESSAGE'] .= ', ' . $l_short_message; |
|
682 | - $errors['L_LONGMESSAGE'] .= ', ' . $l_long_message; |
|
683 | - $errors['L_SEVERITYCODE'] .= ', ' . $l_severity_code; |
|
680 | + $errors['L_ERRORCODE'] .= ', '.$l_error_code; |
|
681 | + $errors['L_SHORTMESSAGE'] .= ', '.$l_short_message; |
|
682 | + $errors['L_LONGMESSAGE'] .= ', '.$l_long_message; |
|
683 | + $errors['L_SEVERITYCODE'] .= ', '.$l_severity_code; |
|
684 | 684 | } |
685 | 685 | $n++; |
686 | 686 | } |
@@ -19,7 +19,7 @@ discard block |
||
19 | 19 | public function __construct($admin_page) |
20 | 20 | { |
21 | 21 | parent::__construct($admin_page); |
22 | - require_once(EE_MODELS . 'EEM_Price_Type.model.php'); |
|
22 | + require_once(EE_MODELS.'EEM_Price_Type.model.php'); |
|
23 | 23 | $this->_PRT = EEM_Price_Type::instance(); |
24 | 24 | } |
25 | 25 | |
@@ -45,7 +45,7 @@ discard block |
||
45 | 45 | $this->_columns = array( |
46 | 46 | 'cb' => '<input type="checkbox" />', // Render a checkbox instead of text |
47 | 47 | 'name' => esc_html__('Name', 'event_espresso'), |
48 | - 'base_type' => '<div class="jst-cntr">' . esc_html__('Base Type', 'event_espresso') . '</div>', |
|
48 | + 'base_type' => '<div class="jst-cntr">'.esc_html__('Base Type', 'event_espresso').'</div>', |
|
49 | 49 | 'percent' => '<div class="jst-cntr">' |
50 | 50 | . sprintf( |
51 | 51 | /* translators: 1: HTML new line, 2: open span tag, 3: close span tag */ |
@@ -121,14 +121,14 @@ discard block |
||
121 | 121 | 'action' => 'edit_price_type', |
122 | 122 | 'id' => $item->ID(), |
123 | 123 | ), PRICING_ADMIN_URL); |
124 | - $actions['edit'] = '<a href="' . $edit_lnk_url . '" aria-label="' |
|
124 | + $actions['edit'] = '<a href="'.$edit_lnk_url.'" aria-label="' |
|
125 | 125 | . sprintf( |
126 | 126 | /* translators: The name of the price type */ |
127 | 127 | esc_attr__('Edit Price Type (%s)', 'event_espresso'), |
128 | 128 | $item->name() |
129 | 129 | ) |
130 | 130 | . '">' |
131 | - . esc_html__('Edit', 'event_espresso') . '</a>'; |
|
131 | + . esc_html__('Edit', 'event_espresso').'</a>'; |
|
132 | 132 | } |
133 | 133 | |
134 | 134 | $name_link = EE_Registry::instance()->CAP->current_user_can( |
@@ -136,14 +136,14 @@ discard block |
||
136 | 136 | 'pricing_edit_price_type', |
137 | 137 | $item->ID() |
138 | 138 | ) |
139 | - ? '<a href="' . $edit_lnk_url . '" aria-label="' |
|
139 | + ? '<a href="'.$edit_lnk_url.'" aria-label="' |
|
140 | 140 | . sprintf( |
141 | 141 | /* translators: The name of the price type */ |
142 | 142 | esc_attr__('Edit Price Type (%s)', 'event_espresso'), |
143 | 143 | $item->name() |
144 | 144 | ) |
145 | 145 | . '">' |
146 | - . stripslashes($item->name()) . '</a>' |
|
146 | + . stripslashes($item->name()).'</a>' |
|
147 | 147 | : $item->name(); |
148 | 148 | |
149 | 149 | if ($item->base_type() !== 1) { |
@@ -161,14 +161,14 @@ discard block |
||
161 | 161 | 'id' => $item->ID(), |
162 | 162 | 'noheader' => true, |
163 | 163 | ), PRICING_ADMIN_URL); |
164 | - $actions['trash'] = '<a href="' . $trash_lnk_url . '" aria-label="' |
|
164 | + $actions['trash'] = '<a href="'.$trash_lnk_url.'" aria-label="' |
|
165 | 165 | . sprintf( |
166 | 166 | /* translators: The name of the price type */ |
167 | 167 | esc_attr__('Move Price Type %s to Trash', 'event_espresso'), |
168 | 168 | $item->name() |
169 | 169 | ) |
170 | 170 | . '">' |
171 | - . esc_html__('Move to Trash', 'event_espresso') . '</a>'; |
|
171 | + . esc_html__('Move to Trash', 'event_espresso').'</a>'; |
|
172 | 172 | } |
173 | 173 | } else { |
174 | 174 | // restore price link |
@@ -184,14 +184,14 @@ discard block |
||
184 | 184 | 'id' => $item->ID(), |
185 | 185 | 'noheader' => true, |
186 | 186 | ), PRICING_ADMIN_URL); |
187 | - $actions['restore'] = '<a href="' . $restore_lnk_url . '" aria-label="' |
|
187 | + $actions['restore'] = '<a href="'.$restore_lnk_url.'" aria-label="' |
|
188 | 188 | . sprintf( |
189 | 189 | /* translators: The name of the price type */ |
190 | 190 | esc_attr__('Restore Price Type (%s)', 'event_espresso'), |
191 | 191 | $item->name() |
192 | 192 | ) |
193 | 193 | . '">' |
194 | - . esc_html__('Restore', 'event_espresso') . '</a>'; |
|
194 | + . esc_html__('Restore', 'event_espresso').'</a>'; |
|
195 | 195 | } |
196 | 196 | // delete price link |
197 | 197 | if ( |
@@ -206,14 +206,14 @@ discard block |
||
206 | 206 | 'id' => $item->ID(), |
207 | 207 | 'noheader' => true, |
208 | 208 | ), PRICING_ADMIN_URL); |
209 | - $actions['delete'] = '<a href="' . $delete_lnk_url . '" aria-label="' |
|
209 | + $actions['delete'] = '<a href="'.$delete_lnk_url.'" aria-label="' |
|
210 | 210 | . sprintf( |
211 | 211 | /* translators: The name of the price type */ |
212 | 212 | esc_attr__('Delete Price Type %s Permanently', 'event_espresso'), |
213 | 213 | $item->name() |
214 | 214 | ) |
215 | 215 | . '">' |
216 | - . esc_html__('Delete Permanently', 'event_espresso') . '</a>'; |
|
216 | + . esc_html__('Delete Permanently', 'event_espresso').'</a>'; |
|
217 | 217 | } |
218 | 218 | } |
219 | 219 | } |
@@ -230,18 +230,18 @@ discard block |
||
230 | 230 | |
231 | 231 | public function column_base_type($item) |
232 | 232 | { |
233 | - return '<div class="jst-cntr">' . $item->base_type_name() . '</div>'; |
|
233 | + return '<div class="jst-cntr">'.$item->base_type_name().'</div>'; |
|
234 | 234 | } |
235 | 235 | |
236 | 236 | |
237 | 237 | public function column_percent($item) |
238 | 238 | { |
239 | - return '<div class="jst-cntr">' . ($item->is_percent() ? '%' : EE_Registry::instance()->CFG->currency->sign) . '</div>'; |
|
239 | + return '<div class="jst-cntr">'.($item->is_percent() ? '%' : EE_Registry::instance()->CFG->currency->sign).'</div>'; |
|
240 | 240 | } |
241 | 241 | |
242 | 242 | |
243 | 243 | public function column_order($item) |
244 | 244 | { |
245 | - return '<div class="jst-cntr">' . $item->order() . '</div>'; |
|
245 | + return '<div class="jst-cntr">'.$item->order().'</div>'; |
|
246 | 246 | } |
247 | 247 | } |
@@ -15,232 +15,232 @@ |
||
15 | 15 | */ |
16 | 16 | class Price_Types_List_Table extends EE_Admin_List_Table |
17 | 17 | { |
18 | - public function __construct($admin_page) |
|
19 | - { |
|
20 | - parent::__construct($admin_page); |
|
21 | - require_once(EE_MODELS . 'EEM_Price_Type.model.php'); |
|
22 | - $this->_PRT = EEM_Price_Type::instance(); |
|
23 | - } |
|
24 | - |
|
25 | - |
|
26 | - protected function _setup_data() |
|
27 | - { |
|
28 | - $trashed = $this->_admin_page->get_view() == 'trashed' ? true : false; |
|
29 | - $this->_data = $this->_admin_page->get_price_types_overview_data($this->_per_page, false, $trashed); |
|
30 | - $this->_all_data_count = $this->_admin_page->get_price_types_overview_data($this->_per_page, true, false); |
|
31 | - $this->_trashed_count = $this->_admin_page->get_price_types_overview_data($this->_per_page, true, true); |
|
32 | - } |
|
33 | - |
|
34 | - |
|
35 | - protected function _set_properties() |
|
36 | - { |
|
37 | - $this->_wp_list_args = array( |
|
38 | - 'singular' => esc_html__('price type', 'event_espresso'), |
|
39 | - 'plural' => esc_html__('price types', 'event_espresso'), |
|
40 | - 'ajax' => true, |
|
41 | - 'screen' => $this->_admin_page->get_current_screen()->id, |
|
42 | - ); |
|
43 | - |
|
44 | - $this->_columns = array( |
|
45 | - 'cb' => '<input type="checkbox" />', // Render a checkbox instead of text |
|
46 | - 'name' => esc_html__('Name', 'event_espresso'), |
|
47 | - 'base_type' => '<div class="jst-cntr">' . esc_html__('Base Type', 'event_espresso') . '</div>', |
|
48 | - 'percent' => '<div class="jst-cntr">' |
|
49 | - . sprintf( |
|
50 | - /* translators: 1: HTML new line, 2: open span tag, 3: close span tag */ |
|
51 | - esc_html__('Applied %1$s as %2$s%%%3$s or %2$s$%3$s', 'event_espresso'), |
|
52 | - '<br/>', |
|
53 | - '<span class="big-text">', |
|
54 | - '</span>' |
|
55 | - ) |
|
56 | - . '</div>', |
|
57 | - 'order' => '<div class="jst-cntr">' |
|
58 | - . sprintf( |
|
59 | - /* translators: HTML new line */ |
|
60 | - esc_html__('Order of %s Application', 'event_espresso'), |
|
61 | - '<br/>' |
|
62 | - ) |
|
63 | - . '</div>', |
|
64 | - ); |
|
65 | - |
|
66 | - $this->_sortable_columns = array( |
|
67 | - // TRUE means its already sorted |
|
68 | - 'name' => array('name' => false), |
|
69 | - ); |
|
70 | - |
|
71 | - $this->_hidden_columns = array(); |
|
72 | - } |
|
73 | - |
|
74 | - |
|
75 | - protected function _get_table_filters() |
|
76 | - { |
|
77 | - } |
|
78 | - |
|
79 | - |
|
80 | - protected function _add_view_counts() |
|
81 | - { |
|
82 | - $this->_views['all']['count'] = $this->_all_data_count; |
|
83 | - if ( |
|
84 | - EE_Registry::instance()->CAP->current_user_can( |
|
85 | - 'ee_delete_default_price_types', |
|
86 | - 'pricing_trash_price_type' |
|
87 | - ) |
|
88 | - ) { |
|
89 | - $this->_views['trashed']['count'] = $this->_trashed_count; |
|
90 | - } |
|
91 | - } |
|
92 | - |
|
93 | - |
|
94 | - public function column_cb($item) |
|
95 | - { |
|
96 | - if ($item->base_type() !== 1) { |
|
97 | - return sprintf( |
|
98 | - '<input type="checkbox" name="checkbox[%1$s]" />', |
|
99 | - $item->ID() |
|
100 | - ); |
|
101 | - } |
|
102 | - return ''; |
|
103 | - } |
|
104 | - |
|
105 | - |
|
106 | - public function column_name($item) |
|
107 | - { |
|
108 | - |
|
109 | - // Build row actions |
|
110 | - $actions = array(); |
|
111 | - // edit price link |
|
112 | - if ( |
|
113 | - EE_Registry::instance()->CAP->current_user_can( |
|
114 | - 'ee_edit_default_price_type', |
|
115 | - 'pricing_edit_price_type', |
|
116 | - $item->ID() |
|
117 | - ) |
|
118 | - ) { |
|
119 | - $edit_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
120 | - 'action' => 'edit_price_type', |
|
121 | - 'id' => $item->ID(), |
|
122 | - ), PRICING_ADMIN_URL); |
|
123 | - $actions['edit'] = '<a href="' . $edit_lnk_url . '" aria-label="' |
|
124 | - . sprintf( |
|
125 | - /* translators: The name of the price type */ |
|
126 | - esc_attr__('Edit Price Type (%s)', 'event_espresso'), |
|
127 | - $item->name() |
|
128 | - ) |
|
129 | - . '">' |
|
130 | - . esc_html__('Edit', 'event_espresso') . '</a>'; |
|
131 | - } |
|
132 | - |
|
133 | - $name_link = EE_Registry::instance()->CAP->current_user_can( |
|
134 | - 'ee_edit_default_price_type', |
|
135 | - 'pricing_edit_price_type', |
|
136 | - $item->ID() |
|
137 | - ) |
|
138 | - ? '<a href="' . $edit_lnk_url . '" aria-label="' |
|
139 | - . sprintf( |
|
140 | - /* translators: The name of the price type */ |
|
141 | - esc_attr__('Edit Price Type (%s)', 'event_espresso'), |
|
142 | - $item->name() |
|
143 | - ) |
|
144 | - . '">' |
|
145 | - . stripslashes($item->name()) . '</a>' |
|
146 | - : $item->name(); |
|
147 | - |
|
148 | - if ($item->base_type() !== 1) { |
|
149 | - if ($this->_view == 'all') { |
|
150 | - // trash price link |
|
151 | - if ( |
|
152 | - EE_Registry::instance()->CAP->current_user_can( |
|
153 | - 'ee_delete_default_price_type', |
|
154 | - 'pricing_trash_price_type', |
|
155 | - $item->ID() |
|
156 | - ) |
|
157 | - ) { |
|
158 | - $trash_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
159 | - 'action' => 'trash_price_type', |
|
160 | - 'id' => $item->ID(), |
|
161 | - 'noheader' => true, |
|
162 | - ), PRICING_ADMIN_URL); |
|
163 | - $actions['trash'] = '<a href="' . $trash_lnk_url . '" aria-label="' |
|
164 | - . sprintf( |
|
165 | - /* translators: The name of the price type */ |
|
166 | - esc_attr__('Move Price Type %s to Trash', 'event_espresso'), |
|
167 | - $item->name() |
|
168 | - ) |
|
169 | - . '">' |
|
170 | - . esc_html__('Move to Trash', 'event_espresso') . '</a>'; |
|
171 | - } |
|
172 | - } else { |
|
173 | - // restore price link |
|
174 | - if ( |
|
175 | - EE_Registry::instance()->CAP->current_user_can( |
|
176 | - 'ee_delete_default_price_type', |
|
177 | - 'pricing_restore_price_type', |
|
178 | - $item->ID() |
|
179 | - ) |
|
180 | - ) { |
|
181 | - $restore_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
182 | - 'action' => 'restore_price_type', |
|
183 | - 'id' => $item->ID(), |
|
184 | - 'noheader' => true, |
|
185 | - ), PRICING_ADMIN_URL); |
|
186 | - $actions['restore'] = '<a href="' . $restore_lnk_url . '" aria-label="' |
|
187 | - . sprintf( |
|
188 | - /* translators: The name of the price type */ |
|
189 | - esc_attr__('Restore Price Type (%s)', 'event_espresso'), |
|
190 | - $item->name() |
|
191 | - ) |
|
192 | - . '">' |
|
193 | - . esc_html__('Restore', 'event_espresso') . '</a>'; |
|
194 | - } |
|
195 | - // delete price link |
|
196 | - if ( |
|
197 | - EE_Registry::instance()->CAP->current_user_can( |
|
198 | - 'ee_delete_default_price_type', |
|
199 | - 'pricing_delete_price_type', |
|
200 | - $item->ID() |
|
201 | - ) |
|
202 | - ) { |
|
203 | - $delete_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
204 | - 'action' => 'delete_price_type', |
|
205 | - 'id' => $item->ID(), |
|
206 | - 'noheader' => true, |
|
207 | - ), PRICING_ADMIN_URL); |
|
208 | - $actions['delete'] = '<a href="' . $delete_lnk_url . '" aria-label="' |
|
209 | - . sprintf( |
|
210 | - /* translators: The name of the price type */ |
|
211 | - esc_attr__('Delete Price Type %s Permanently', 'event_espresso'), |
|
212 | - $item->name() |
|
213 | - ) |
|
214 | - . '">' |
|
215 | - . esc_html__('Delete Permanently', 'event_espresso') . '</a>'; |
|
216 | - } |
|
217 | - } |
|
218 | - } |
|
219 | - |
|
220 | - // Return the name contents |
|
221 | - return sprintf( |
|
222 | - '%1$s <span style="color:silver">(id:%2$s)</span>%3$s', |
|
223 | - $name_link, |
|
224 | - $item->ID(), |
|
225 | - $this->row_actions($actions) |
|
226 | - ); |
|
227 | - } |
|
228 | - |
|
229 | - |
|
230 | - public function column_base_type($item) |
|
231 | - { |
|
232 | - return '<div class="jst-cntr">' . $item->base_type_name() . '</div>'; |
|
233 | - } |
|
234 | - |
|
235 | - |
|
236 | - public function column_percent($item) |
|
237 | - { |
|
238 | - return '<div class="jst-cntr">' . ($item->is_percent() ? '%' : EE_Registry::instance()->CFG->currency->sign) . '</div>'; |
|
239 | - } |
|
240 | - |
|
241 | - |
|
242 | - public function column_order($item) |
|
243 | - { |
|
244 | - return '<div class="jst-cntr">' . $item->order() . '</div>'; |
|
245 | - } |
|
18 | + public function __construct($admin_page) |
|
19 | + { |
|
20 | + parent::__construct($admin_page); |
|
21 | + require_once(EE_MODELS . 'EEM_Price_Type.model.php'); |
|
22 | + $this->_PRT = EEM_Price_Type::instance(); |
|
23 | + } |
|
24 | + |
|
25 | + |
|
26 | + protected function _setup_data() |
|
27 | + { |
|
28 | + $trashed = $this->_admin_page->get_view() == 'trashed' ? true : false; |
|
29 | + $this->_data = $this->_admin_page->get_price_types_overview_data($this->_per_page, false, $trashed); |
|
30 | + $this->_all_data_count = $this->_admin_page->get_price_types_overview_data($this->_per_page, true, false); |
|
31 | + $this->_trashed_count = $this->_admin_page->get_price_types_overview_data($this->_per_page, true, true); |
|
32 | + } |
|
33 | + |
|
34 | + |
|
35 | + protected function _set_properties() |
|
36 | + { |
|
37 | + $this->_wp_list_args = array( |
|
38 | + 'singular' => esc_html__('price type', 'event_espresso'), |
|
39 | + 'plural' => esc_html__('price types', 'event_espresso'), |
|
40 | + 'ajax' => true, |
|
41 | + 'screen' => $this->_admin_page->get_current_screen()->id, |
|
42 | + ); |
|
43 | + |
|
44 | + $this->_columns = array( |
|
45 | + 'cb' => '<input type="checkbox" />', // Render a checkbox instead of text |
|
46 | + 'name' => esc_html__('Name', 'event_espresso'), |
|
47 | + 'base_type' => '<div class="jst-cntr">' . esc_html__('Base Type', 'event_espresso') . '</div>', |
|
48 | + 'percent' => '<div class="jst-cntr">' |
|
49 | + . sprintf( |
|
50 | + /* translators: 1: HTML new line, 2: open span tag, 3: close span tag */ |
|
51 | + esc_html__('Applied %1$s as %2$s%%%3$s or %2$s$%3$s', 'event_espresso'), |
|
52 | + '<br/>', |
|
53 | + '<span class="big-text">', |
|
54 | + '</span>' |
|
55 | + ) |
|
56 | + . '</div>', |
|
57 | + 'order' => '<div class="jst-cntr">' |
|
58 | + . sprintf( |
|
59 | + /* translators: HTML new line */ |
|
60 | + esc_html__('Order of %s Application', 'event_espresso'), |
|
61 | + '<br/>' |
|
62 | + ) |
|
63 | + . '</div>', |
|
64 | + ); |
|
65 | + |
|
66 | + $this->_sortable_columns = array( |
|
67 | + // TRUE means its already sorted |
|
68 | + 'name' => array('name' => false), |
|
69 | + ); |
|
70 | + |
|
71 | + $this->_hidden_columns = array(); |
|
72 | + } |
|
73 | + |
|
74 | + |
|
75 | + protected function _get_table_filters() |
|
76 | + { |
|
77 | + } |
|
78 | + |
|
79 | + |
|
80 | + protected function _add_view_counts() |
|
81 | + { |
|
82 | + $this->_views['all']['count'] = $this->_all_data_count; |
|
83 | + if ( |
|
84 | + EE_Registry::instance()->CAP->current_user_can( |
|
85 | + 'ee_delete_default_price_types', |
|
86 | + 'pricing_trash_price_type' |
|
87 | + ) |
|
88 | + ) { |
|
89 | + $this->_views['trashed']['count'] = $this->_trashed_count; |
|
90 | + } |
|
91 | + } |
|
92 | + |
|
93 | + |
|
94 | + public function column_cb($item) |
|
95 | + { |
|
96 | + if ($item->base_type() !== 1) { |
|
97 | + return sprintf( |
|
98 | + '<input type="checkbox" name="checkbox[%1$s]" />', |
|
99 | + $item->ID() |
|
100 | + ); |
|
101 | + } |
|
102 | + return ''; |
|
103 | + } |
|
104 | + |
|
105 | + |
|
106 | + public function column_name($item) |
|
107 | + { |
|
108 | + |
|
109 | + // Build row actions |
|
110 | + $actions = array(); |
|
111 | + // edit price link |
|
112 | + if ( |
|
113 | + EE_Registry::instance()->CAP->current_user_can( |
|
114 | + 'ee_edit_default_price_type', |
|
115 | + 'pricing_edit_price_type', |
|
116 | + $item->ID() |
|
117 | + ) |
|
118 | + ) { |
|
119 | + $edit_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
120 | + 'action' => 'edit_price_type', |
|
121 | + 'id' => $item->ID(), |
|
122 | + ), PRICING_ADMIN_URL); |
|
123 | + $actions['edit'] = '<a href="' . $edit_lnk_url . '" aria-label="' |
|
124 | + . sprintf( |
|
125 | + /* translators: The name of the price type */ |
|
126 | + esc_attr__('Edit Price Type (%s)', 'event_espresso'), |
|
127 | + $item->name() |
|
128 | + ) |
|
129 | + . '">' |
|
130 | + . esc_html__('Edit', 'event_espresso') . '</a>'; |
|
131 | + } |
|
132 | + |
|
133 | + $name_link = EE_Registry::instance()->CAP->current_user_can( |
|
134 | + 'ee_edit_default_price_type', |
|
135 | + 'pricing_edit_price_type', |
|
136 | + $item->ID() |
|
137 | + ) |
|
138 | + ? '<a href="' . $edit_lnk_url . '" aria-label="' |
|
139 | + . sprintf( |
|
140 | + /* translators: The name of the price type */ |
|
141 | + esc_attr__('Edit Price Type (%s)', 'event_espresso'), |
|
142 | + $item->name() |
|
143 | + ) |
|
144 | + . '">' |
|
145 | + . stripslashes($item->name()) . '</a>' |
|
146 | + : $item->name(); |
|
147 | + |
|
148 | + if ($item->base_type() !== 1) { |
|
149 | + if ($this->_view == 'all') { |
|
150 | + // trash price link |
|
151 | + if ( |
|
152 | + EE_Registry::instance()->CAP->current_user_can( |
|
153 | + 'ee_delete_default_price_type', |
|
154 | + 'pricing_trash_price_type', |
|
155 | + $item->ID() |
|
156 | + ) |
|
157 | + ) { |
|
158 | + $trash_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
159 | + 'action' => 'trash_price_type', |
|
160 | + 'id' => $item->ID(), |
|
161 | + 'noheader' => true, |
|
162 | + ), PRICING_ADMIN_URL); |
|
163 | + $actions['trash'] = '<a href="' . $trash_lnk_url . '" aria-label="' |
|
164 | + . sprintf( |
|
165 | + /* translators: The name of the price type */ |
|
166 | + esc_attr__('Move Price Type %s to Trash', 'event_espresso'), |
|
167 | + $item->name() |
|
168 | + ) |
|
169 | + . '">' |
|
170 | + . esc_html__('Move to Trash', 'event_espresso') . '</a>'; |
|
171 | + } |
|
172 | + } else { |
|
173 | + // restore price link |
|
174 | + if ( |
|
175 | + EE_Registry::instance()->CAP->current_user_can( |
|
176 | + 'ee_delete_default_price_type', |
|
177 | + 'pricing_restore_price_type', |
|
178 | + $item->ID() |
|
179 | + ) |
|
180 | + ) { |
|
181 | + $restore_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
182 | + 'action' => 'restore_price_type', |
|
183 | + 'id' => $item->ID(), |
|
184 | + 'noheader' => true, |
|
185 | + ), PRICING_ADMIN_URL); |
|
186 | + $actions['restore'] = '<a href="' . $restore_lnk_url . '" aria-label="' |
|
187 | + . sprintf( |
|
188 | + /* translators: The name of the price type */ |
|
189 | + esc_attr__('Restore Price Type (%s)', 'event_espresso'), |
|
190 | + $item->name() |
|
191 | + ) |
|
192 | + . '">' |
|
193 | + . esc_html__('Restore', 'event_espresso') . '</a>'; |
|
194 | + } |
|
195 | + // delete price link |
|
196 | + if ( |
|
197 | + EE_Registry::instance()->CAP->current_user_can( |
|
198 | + 'ee_delete_default_price_type', |
|
199 | + 'pricing_delete_price_type', |
|
200 | + $item->ID() |
|
201 | + ) |
|
202 | + ) { |
|
203 | + $delete_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
204 | + 'action' => 'delete_price_type', |
|
205 | + 'id' => $item->ID(), |
|
206 | + 'noheader' => true, |
|
207 | + ), PRICING_ADMIN_URL); |
|
208 | + $actions['delete'] = '<a href="' . $delete_lnk_url . '" aria-label="' |
|
209 | + . sprintf( |
|
210 | + /* translators: The name of the price type */ |
|
211 | + esc_attr__('Delete Price Type %s Permanently', 'event_espresso'), |
|
212 | + $item->name() |
|
213 | + ) |
|
214 | + . '">' |
|
215 | + . esc_html__('Delete Permanently', 'event_espresso') . '</a>'; |
|
216 | + } |
|
217 | + } |
|
218 | + } |
|
219 | + |
|
220 | + // Return the name contents |
|
221 | + return sprintf( |
|
222 | + '%1$s <span style="color:silver">(id:%2$s)</span>%3$s', |
|
223 | + $name_link, |
|
224 | + $item->ID(), |
|
225 | + $this->row_actions($actions) |
|
226 | + ); |
|
227 | + } |
|
228 | + |
|
229 | + |
|
230 | + public function column_base_type($item) |
|
231 | + { |
|
232 | + return '<div class="jst-cntr">' . $item->base_type_name() . '</div>'; |
|
233 | + } |
|
234 | + |
|
235 | + |
|
236 | + public function column_percent($item) |
|
237 | + { |
|
238 | + return '<div class="jst-cntr">' . ($item->is_percent() ? '%' : EE_Registry::instance()->CFG->currency->sign) . '</div>'; |
|
239 | + } |
|
240 | + |
|
241 | + |
|
242 | + public function column_order($item) |
|
243 | + { |
|
244 | + return '<div class="jst-cntr">' . $item->order() . '</div>'; |
|
245 | + } |
|
246 | 246 | } |
@@ -99,7 +99,7 @@ discard block |
||
99 | 99 | */ |
100 | 100 | public function column_name($item) |
101 | 101 | { |
102 | - return '<p>' . $item->name() . '</p>'; |
|
102 | + return '<p>'.$item->name().'</p>'; |
|
103 | 103 | } |
104 | 104 | |
105 | 105 | |
@@ -137,7 +137,7 @@ discard block |
||
137 | 137 | protected function _add_view_counts() |
138 | 138 | { |
139 | 139 | foreach ($this->_views as $view => $args) { |
140 | - $this->_views[ $view ]['count'] = $this->get_admin_page()->get_message_templates( |
|
140 | + $this->_views[$view]['count'] = $this->get_admin_page()->get_message_templates( |
|
141 | 141 | $this->_per_page, |
142 | 142 | $view, |
143 | 143 | true, |
@@ -219,7 +219,7 @@ discard block |
||
219 | 219 | . '" title="' |
220 | 220 | . esc_attr__('Restore Message Template', 'event_espresso') |
221 | 221 | . '">' |
222 | - . esc_html__('Restore', 'event_espresso') . '</a>'; |
|
222 | + . esc_html__('Restore', 'event_espresso').'</a>'; |
|
223 | 223 | } |
224 | 224 | |
225 | 225 | if ( |
@@ -11,259 +11,259 @@ |
||
11 | 11 | */ |
12 | 12 | class Custom_Messages_Template_List_Table extends Messages_Template_List_Table |
13 | 13 | { |
14 | - /** |
|
15 | - * Setup initial data. |
|
16 | - */ |
|
17 | - protected function _setup_data() |
|
18 | - { |
|
19 | - $this->_data = $this->get_admin_page()->get_message_templates( |
|
20 | - $this->_per_page, |
|
21 | - $this->_view, |
|
22 | - false, |
|
23 | - false, |
|
24 | - false |
|
25 | - ); |
|
26 | - $this->_all_data_count = $this->get_admin_page()->get_message_templates( |
|
27 | - $this->_per_page, |
|
28 | - $this->_view, |
|
29 | - true, |
|
30 | - true, |
|
31 | - false |
|
32 | - ); |
|
33 | - } |
|
14 | + /** |
|
15 | + * Setup initial data. |
|
16 | + */ |
|
17 | + protected function _setup_data() |
|
18 | + { |
|
19 | + $this->_data = $this->get_admin_page()->get_message_templates( |
|
20 | + $this->_per_page, |
|
21 | + $this->_view, |
|
22 | + false, |
|
23 | + false, |
|
24 | + false |
|
25 | + ); |
|
26 | + $this->_all_data_count = $this->get_admin_page()->get_message_templates( |
|
27 | + $this->_per_page, |
|
28 | + $this->_view, |
|
29 | + true, |
|
30 | + true, |
|
31 | + false |
|
32 | + ); |
|
33 | + } |
|
34 | 34 | |
35 | 35 | |
36 | - /** |
|
37 | - * Set initial properties |
|
38 | - */ |
|
39 | - protected function _set_properties() |
|
40 | - { |
|
41 | - parent::_set_properties(); |
|
42 | - $this->_wp_list_args = array( |
|
43 | - 'singular' => esc_html__('Message Template Group', 'event_espresso'), |
|
44 | - 'plural' => esc_html__('Message Template', 'event_espresso'), |
|
45 | - 'ajax' => true, // for now, |
|
46 | - 'screen' => $this->get_admin_page()->get_current_screen()->id, |
|
47 | - ); |
|
36 | + /** |
|
37 | + * Set initial properties |
|
38 | + */ |
|
39 | + protected function _set_properties() |
|
40 | + { |
|
41 | + parent::_set_properties(); |
|
42 | + $this->_wp_list_args = array( |
|
43 | + 'singular' => esc_html__('Message Template Group', 'event_espresso'), |
|
44 | + 'plural' => esc_html__('Message Template', 'event_espresso'), |
|
45 | + 'ajax' => true, // for now, |
|
46 | + 'screen' => $this->get_admin_page()->get_current_screen()->id, |
|
47 | + ); |
|
48 | 48 | |
49 | - $this->_columns = array_merge( |
|
50 | - array( |
|
51 | - 'cb' => '<input type="checkbox" />', |
|
52 | - 'name' => esc_html__('Template Name', 'event_espresso'), |
|
53 | - ), |
|
54 | - $this->_columns, |
|
55 | - array( |
|
56 | - 'events' => esc_html__('Events', 'event_espresso'), |
|
57 | - 'actions' => '', |
|
58 | - ) |
|
59 | - ); |
|
60 | - } |
|
49 | + $this->_columns = array_merge( |
|
50 | + array( |
|
51 | + 'cb' => '<input type="checkbox" />', |
|
52 | + 'name' => esc_html__('Template Name', 'event_espresso'), |
|
53 | + ), |
|
54 | + $this->_columns, |
|
55 | + array( |
|
56 | + 'events' => esc_html__('Events', 'event_espresso'), |
|
57 | + 'actions' => '', |
|
58 | + ) |
|
59 | + ); |
|
60 | + } |
|
61 | 61 | |
62 | 62 | |
63 | - /** |
|
64 | - * Custom message for when there are no items found. |
|
65 | - * |
|
66 | - * @since 4.3.0 |
|
67 | - */ |
|
68 | - public function no_items() |
|
69 | - { |
|
70 | - if ($this->_view !== 'trashed') { |
|
71 | - printf( |
|
72 | - esc_html__( |
|
73 | - '%sNo Custom Templates found.%s To create your first custom message template, go to the "Default Message Templates" tab and click the "Create Custom" button next to the template you want to use as a base for the new one.', |
|
74 | - 'event_espresso' |
|
75 | - ), |
|
76 | - '<strong>', |
|
77 | - '</strong>' |
|
78 | - ); |
|
79 | - } else { |
|
80 | - parent::no_items(); |
|
81 | - } |
|
82 | - } |
|
63 | + /** |
|
64 | + * Custom message for when there are no items found. |
|
65 | + * |
|
66 | + * @since 4.3.0 |
|
67 | + */ |
|
68 | + public function no_items() |
|
69 | + { |
|
70 | + if ($this->_view !== 'trashed') { |
|
71 | + printf( |
|
72 | + esc_html__( |
|
73 | + '%sNo Custom Templates found.%s To create your first custom message template, go to the "Default Message Templates" tab and click the "Create Custom" button next to the template you want to use as a base for the new one.', |
|
74 | + 'event_espresso' |
|
75 | + ), |
|
76 | + '<strong>', |
|
77 | + '</strong>' |
|
78 | + ); |
|
79 | + } else { |
|
80 | + parent::no_items(); |
|
81 | + } |
|
82 | + } |
|
83 | 83 | |
84 | 84 | |
85 | - /** |
|
86 | - * @param EE_Message_Template_Group $item |
|
87 | - * @return string |
|
88 | - */ |
|
89 | - public function column_cb($item) |
|
90 | - { |
|
91 | - return sprintf('<input type="checkbox" name="checkbox[%s]" value="1" />', $item->GRP_ID()); |
|
92 | - } |
|
85 | + /** |
|
86 | + * @param EE_Message_Template_Group $item |
|
87 | + * @return string |
|
88 | + */ |
|
89 | + public function column_cb($item) |
|
90 | + { |
|
91 | + return sprintf('<input type="checkbox" name="checkbox[%s]" value="1" />', $item->GRP_ID()); |
|
92 | + } |
|
93 | 93 | |
94 | 94 | |
95 | - /** |
|
96 | - * @param EE_Message_Template_Group $item |
|
97 | - * @return string |
|
98 | - */ |
|
99 | - public function column_name($item) |
|
100 | - { |
|
101 | - return '<p>' . $item->name() . '</p>'; |
|
102 | - } |
|
95 | + /** |
|
96 | + * @param EE_Message_Template_Group $item |
|
97 | + * @return string |
|
98 | + */ |
|
99 | + public function column_name($item) |
|
100 | + { |
|
101 | + return '<p>' . $item->name() . '</p>'; |
|
102 | + } |
|
103 | 103 | |
104 | 104 | |
105 | - /** |
|
106 | - * @param EE_Message_Template_Group $item |
|
107 | - * @return string |
|
108 | - */ |
|
109 | - public function column_actions($item) |
|
110 | - { |
|
111 | - if ( |
|
112 | - EE_Registry::instance()->CAP->current_user_can( |
|
113 | - 'ee_edit_messages', |
|
114 | - 'espresso_messages_add_new_message_template' |
|
115 | - ) |
|
116 | - ) { |
|
117 | - $create_args = array( |
|
118 | - 'GRP_ID' => $item->ID(), |
|
119 | - 'messenger' => $item->messenger(), |
|
120 | - 'message_type' => $item->message_type(), |
|
121 | - 'action' => 'add_new_message_template', |
|
122 | - ); |
|
123 | - $create_link = EE_Admin_Page::add_query_args_and_nonce($create_args, EE_MSG_ADMIN_URL); |
|
124 | - return sprintf( |
|
125 | - '<p><a href="%s" class="button button-small">%s</a></p>', |
|
126 | - $create_link, |
|
127 | - esc_html__('Create Custom', 'event_espresso') |
|
128 | - ); |
|
129 | - } |
|
130 | - return ''; |
|
131 | - } |
|
105 | + /** |
|
106 | + * @param EE_Message_Template_Group $item |
|
107 | + * @return string |
|
108 | + */ |
|
109 | + public function column_actions($item) |
|
110 | + { |
|
111 | + if ( |
|
112 | + EE_Registry::instance()->CAP->current_user_can( |
|
113 | + 'ee_edit_messages', |
|
114 | + 'espresso_messages_add_new_message_template' |
|
115 | + ) |
|
116 | + ) { |
|
117 | + $create_args = array( |
|
118 | + 'GRP_ID' => $item->ID(), |
|
119 | + 'messenger' => $item->messenger(), |
|
120 | + 'message_type' => $item->message_type(), |
|
121 | + 'action' => 'add_new_message_template', |
|
122 | + ); |
|
123 | + $create_link = EE_Admin_Page::add_query_args_and_nonce($create_args, EE_MSG_ADMIN_URL); |
|
124 | + return sprintf( |
|
125 | + '<p><a href="%s" class="button button-small">%s</a></p>', |
|
126 | + $create_link, |
|
127 | + esc_html__('Create Custom', 'event_espresso') |
|
128 | + ); |
|
129 | + } |
|
130 | + return ''; |
|
131 | + } |
|
132 | 132 | |
133 | - /** |
|
134 | - * Set the view counts on the _views property |
|
135 | - */ |
|
136 | - protected function _add_view_counts() |
|
137 | - { |
|
138 | - foreach ($this->_views as $view => $args) { |
|
139 | - $this->_views[ $view ]['count'] = $this->get_admin_page()->get_message_templates( |
|
140 | - $this->_per_page, |
|
141 | - $view, |
|
142 | - true, |
|
143 | - true, |
|
144 | - false |
|
145 | - ); |
|
146 | - } |
|
147 | - } |
|
133 | + /** |
|
134 | + * Set the view counts on the _views property |
|
135 | + */ |
|
136 | + protected function _add_view_counts() |
|
137 | + { |
|
138 | + foreach ($this->_views as $view => $args) { |
|
139 | + $this->_views[ $view ]['count'] = $this->get_admin_page()->get_message_templates( |
|
140 | + $this->_per_page, |
|
141 | + $view, |
|
142 | + true, |
|
143 | + true, |
|
144 | + false |
|
145 | + ); |
|
146 | + } |
|
147 | + } |
|
148 | 148 | |
149 | 149 | |
150 | - /** |
|
151 | - * column_events |
|
152 | - * This provides a count of events using this custom template |
|
153 | - * |
|
154 | - * @param EE_Message_Template_Group $item message_template group data |
|
155 | - * @return string column output |
|
156 | - */ |
|
157 | - public function column_events($item) |
|
158 | - { |
|
159 | - return $item->count_events(); |
|
160 | - } |
|
150 | + /** |
|
151 | + * column_events |
|
152 | + * This provides a count of events using this custom template |
|
153 | + * |
|
154 | + * @param EE_Message_Template_Group $item message_template group data |
|
155 | + * @return string column output |
|
156 | + */ |
|
157 | + public function column_events($item) |
|
158 | + { |
|
159 | + return $item->count_events(); |
|
160 | + } |
|
161 | 161 | |
162 | 162 | |
163 | - /** |
|
164 | - * Add additional actions for custom message template list view. |
|
165 | - * |
|
166 | - * @param EE_Message_Template_Group $item |
|
167 | - * @return array |
|
168 | - * @throws EE_Error |
|
169 | - */ |
|
170 | - protected function _get_actions_for_messenger_column(EE_Message_Template_Group $item) |
|
171 | - { |
|
172 | - $actions = parent::_get_actions_for_messenger_column($item); |
|
163 | + /** |
|
164 | + * Add additional actions for custom message template list view. |
|
165 | + * |
|
166 | + * @param EE_Message_Template_Group $item |
|
167 | + * @return array |
|
168 | + * @throws EE_Error |
|
169 | + */ |
|
170 | + protected function _get_actions_for_messenger_column(EE_Message_Template_Group $item) |
|
171 | + { |
|
172 | + $actions = parent::_get_actions_for_messenger_column($item); |
|
173 | 173 | |
174 | - // add additional actions for trash/restore etc. |
|
175 | - $trash_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
176 | - 'action' => 'trash_message_template', |
|
177 | - 'id' => $item->GRP_ID(), |
|
178 | - 'noheader' => true, |
|
179 | - ), EE_MSG_ADMIN_URL); |
|
180 | - // restore link |
|
181 | - $restore_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
182 | - 'action' => 'restore_message_template', |
|
183 | - 'id' => $item->GRP_ID(), |
|
184 | - 'noheader' => true, |
|
185 | - ), EE_MSG_ADMIN_URL); |
|
186 | - // delete price link |
|
187 | - $delete_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
188 | - 'action' => 'delete_message_template', |
|
189 | - 'id' => $item->GRP_ID(), |
|
190 | - 'noheader' => true, |
|
191 | - ), EE_MSG_ADMIN_URL); |
|
174 | + // add additional actions for trash/restore etc. |
|
175 | + $trash_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
176 | + 'action' => 'trash_message_template', |
|
177 | + 'id' => $item->GRP_ID(), |
|
178 | + 'noheader' => true, |
|
179 | + ), EE_MSG_ADMIN_URL); |
|
180 | + // restore link |
|
181 | + $restore_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
182 | + 'action' => 'restore_message_template', |
|
183 | + 'id' => $item->GRP_ID(), |
|
184 | + 'noheader' => true, |
|
185 | + ), EE_MSG_ADMIN_URL); |
|
186 | + // delete price link |
|
187 | + $delete_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
188 | + 'action' => 'delete_message_template', |
|
189 | + 'id' => $item->GRP_ID(), |
|
190 | + 'noheader' => true, |
|
191 | + ), EE_MSG_ADMIN_URL); |
|
192 | 192 | |
193 | - if ( |
|
194 | - ! $item->get('MTP_deleted') |
|
195 | - && EE_Registry::instance()->CAP->current_user_can( |
|
196 | - 'ee_delete_message', |
|
197 | - 'espresso_messages_trash_message_template', |
|
198 | - $item->ID() |
|
199 | - ) |
|
200 | - ) { |
|
201 | - $actions['trash'] = '<a href="' |
|
202 | - . $trash_lnk_url |
|
203 | - . '" title="' |
|
204 | - . esc_attr__('Move Template Group to Trash', 'event_espresso') |
|
205 | - . '">' |
|
206 | - . esc_html__('Move to Trash', 'event_espresso') |
|
207 | - . '</a>'; |
|
208 | - } else { |
|
209 | - if ( |
|
210 | - EE_Registry::instance()->CAP->current_user_can( |
|
211 | - 'ee_delete_message', |
|
212 | - 'espresso_messages_restore_message_template', |
|
213 | - $item->ID() |
|
214 | - ) |
|
215 | - ) { |
|
216 | - $actions['restore'] = '<a href="' |
|
217 | - . $restore_lnk_url |
|
218 | - . '" title="' |
|
219 | - . esc_attr__('Restore Message Template', 'event_espresso') |
|
220 | - . '">' |
|
221 | - . esc_html__('Restore', 'event_espresso') . '</a>'; |
|
222 | - } |
|
193 | + if ( |
|
194 | + ! $item->get('MTP_deleted') |
|
195 | + && EE_Registry::instance()->CAP->current_user_can( |
|
196 | + 'ee_delete_message', |
|
197 | + 'espresso_messages_trash_message_template', |
|
198 | + $item->ID() |
|
199 | + ) |
|
200 | + ) { |
|
201 | + $actions['trash'] = '<a href="' |
|
202 | + . $trash_lnk_url |
|
203 | + . '" title="' |
|
204 | + . esc_attr__('Move Template Group to Trash', 'event_espresso') |
|
205 | + . '">' |
|
206 | + . esc_html__('Move to Trash', 'event_espresso') |
|
207 | + . '</a>'; |
|
208 | + } else { |
|
209 | + if ( |
|
210 | + EE_Registry::instance()->CAP->current_user_can( |
|
211 | + 'ee_delete_message', |
|
212 | + 'espresso_messages_restore_message_template', |
|
213 | + $item->ID() |
|
214 | + ) |
|
215 | + ) { |
|
216 | + $actions['restore'] = '<a href="' |
|
217 | + . $restore_lnk_url |
|
218 | + . '" title="' |
|
219 | + . esc_attr__('Restore Message Template', 'event_espresso') |
|
220 | + . '">' |
|
221 | + . esc_html__('Restore', 'event_espresso') . '</a>'; |
|
222 | + } |
|
223 | 223 | |
224 | - if ( |
|
225 | - $this->_view === 'trashed' |
|
226 | - && EE_Registry::instance()->CAP->current_user_can( |
|
227 | - 'ee_delete_message', |
|
228 | - 'espresso_messages_delete_message_template', |
|
229 | - $item->ID() |
|
230 | - ) |
|
231 | - ) { |
|
232 | - $actions['delete'] = '<a href="' |
|
233 | - . $delete_lnk_url |
|
234 | - . '" title="' |
|
235 | - . esc_attr__('Delete Template Group Permanently', 'event_espresso') |
|
236 | - . '">' |
|
237 | - . esc_html__('Delete Permanently', 'event_espresso') |
|
238 | - . '</a>'; |
|
239 | - } |
|
240 | - } |
|
241 | - return $actions; |
|
242 | - } |
|
224 | + if ( |
|
225 | + $this->_view === 'trashed' |
|
226 | + && EE_Registry::instance()->CAP->current_user_can( |
|
227 | + 'ee_delete_message', |
|
228 | + 'espresso_messages_delete_message_template', |
|
229 | + $item->ID() |
|
230 | + ) |
|
231 | + ) { |
|
232 | + $actions['delete'] = '<a href="' |
|
233 | + . $delete_lnk_url |
|
234 | + . '" title="' |
|
235 | + . esc_attr__('Delete Template Group Permanently', 'event_espresso') |
|
236 | + . '">' |
|
237 | + . esc_html__('Delete Permanently', 'event_espresso') |
|
238 | + . '</a>'; |
|
239 | + } |
|
240 | + } |
|
241 | + return $actions; |
|
242 | + } |
|
243 | 243 | |
244 | 244 | |
245 | - /** |
|
246 | - * Generate dropdown filter select input for messengers |
|
247 | - * |
|
248 | - * @param bool $global |
|
249 | - * @return string |
|
250 | - * @throws EE_Error |
|
251 | - */ |
|
252 | - protected function _get_messengers_dropdown_filter($global = true) |
|
253 | - { |
|
254 | - return parent::_get_messengers_dropdown_filter(false); |
|
255 | - } |
|
245 | + /** |
|
246 | + * Generate dropdown filter select input for messengers |
|
247 | + * |
|
248 | + * @param bool $global |
|
249 | + * @return string |
|
250 | + * @throws EE_Error |
|
251 | + */ |
|
252 | + protected function _get_messengers_dropdown_filter($global = true) |
|
253 | + { |
|
254 | + return parent::_get_messengers_dropdown_filter(false); |
|
255 | + } |
|
256 | 256 | |
257 | 257 | |
258 | - /** |
|
259 | - * Generate dropdown filter select input for message types |
|
260 | - * |
|
261 | - * @param bool $global |
|
262 | - * @return string |
|
263 | - * @throws EE_Error |
|
264 | - */ |
|
265 | - protected function _get_message_types_dropdown_filter($global = true) |
|
266 | - { |
|
267 | - return parent::_get_message_types_dropdown_filter(false); |
|
268 | - } |
|
258 | + /** |
|
259 | + * Generate dropdown filter select input for message types |
|
260 | + * |
|
261 | + * @param bool $global |
|
262 | + * @return string |
|
263 | + * @throws EE_Error |
|
264 | + */ |
|
265 | + protected function _get_message_types_dropdown_filter($global = true) |
|
266 | + { |
|
267 | + return parent::_get_message_types_dropdown_filter(false); |
|
268 | + } |
|
269 | 269 | } |
@@ -129,7 +129,7 @@ discard block |
||
129 | 129 | */ |
130 | 130 | public function messages_autoload_paths($dir_ref) |
131 | 131 | { |
132 | - $dir_ref[] = EE_CAF_LIBRARIES . 'shortcodes/'; |
|
132 | + $dir_ref[] = EE_CAF_LIBRARIES.'shortcodes/'; |
|
133 | 133 | |
134 | 134 | return $dir_ref; |
135 | 135 | } |
@@ -245,32 +245,32 @@ discard block |
||
245 | 245 | ) { |
246 | 246 | |
247 | 247 | // we're only modifying templates for the default template pack |
248 | - if (! $template_pack instanceof EE_Messages_Template_Pack_Default) { |
|
248 | + if ( ! $template_pack instanceof EE_Messages_Template_Pack_Default) { |
|
249 | 249 | return $contents; |
250 | 250 | } |
251 | 251 | |
252 | 252 | // the template file name we're replacing contents for. |
253 | - $template_file_prefix = $field . '_' . $context; |
|
254 | - $msg_prefix = $messenger->name . '_' . $message_type->name . '_'; |
|
253 | + $template_file_prefix = $field.'_'.$context; |
|
254 | + $msg_prefix = $messenger->name.'_'.$message_type->name.'_'; |
|
255 | 255 | |
256 | - $base_path = EE_CAF_LIBRARIES . 'messages/defaults/default/'; |
|
256 | + $base_path = EE_CAF_LIBRARIES.'messages/defaults/default/'; |
|
257 | 257 | |
258 | 258 | if ($messenger->name == 'email' && $message_type->name == 'registration') { |
259 | 259 | switch ($template_file_prefix) { |
260 | 260 | case 'question_list_admin': |
261 | 261 | case 'question_list_attendee': |
262 | 262 | case 'question_list_primary_attendee': |
263 | - $path = $base_path . $msg_prefix . 'question_list.template.php'; |
|
263 | + $path = $base_path.$msg_prefix.'question_list.template.php'; |
|
264 | 264 | $contents = EEH_Template::display_template($path, array(), true); |
265 | 265 | break; |
266 | 266 | |
267 | 267 | case 'attendee_list_primary_attendee': |
268 | - $path = $base_path . $msg_prefix . 'attendee_list.template.php'; |
|
268 | + $path = $base_path.$msg_prefix.'attendee_list.template.php'; |
|
269 | 269 | $contents = EEH_Template::display_template($path, array(), true); |
270 | 270 | break; |
271 | 271 | |
272 | 272 | case 'attendee_list_admin': |
273 | - $path = $base_path . $msg_prefix . 'attendee_list_admin.template.php'; |
|
273 | + $path = $base_path.$msg_prefix.'attendee_list_admin.template.php'; |
|
274 | 274 | $contents = EEH_Template::display_template( |
275 | 275 | $path, |
276 | 276 | array(), |
@@ -283,31 +283,31 @@ discard block |
||
283 | 283 | break; |
284 | 284 | |
285 | 285 | case 'event_list_attendee': |
286 | - $path = $base_path . $msg_prefix . 'event_list_attendee.template.php'; |
|
286 | + $path = $base_path.$msg_prefix.'event_list_attendee.template.php'; |
|
287 | 287 | $contents = EEH_Template::display_template($path, array(), true); |
288 | 288 | break; |
289 | 289 | } |
290 | 290 | } elseif ($messenger->name == 'email' && $message_type->name == 'newsletter') { |
291 | 291 | switch ($template_file_prefix) { |
292 | 292 | case 'content_attendee': |
293 | - $path = $base_path . $msg_prefix . 'content.template.php'; |
|
293 | + $path = $base_path.$msg_prefix.'content.template.php'; |
|
294 | 294 | $contents = EEH_Template::display_template($path, array(), true); |
295 | 295 | break; |
296 | 296 | |
297 | 297 | case 'newsletter_content_attendee': |
298 | - $path = $base_path . $msg_prefix . 'newsletter_content.template.php'; |
|
298 | + $path = $base_path.$msg_prefix.'newsletter_content.template.php'; |
|
299 | 299 | $contents = EEH_Template::display_template($path, array(), true); |
300 | 300 | break; |
301 | 301 | |
302 | 302 | case 'newsletter_subject_attendee': |
303 | - $path = $base_path . $msg_prefix . 'subject.template.php'; |
|
303 | + $path = $base_path.$msg_prefix.'subject.template.php'; |
|
304 | 304 | $contents = EEH_Template::display_template($path, array(), true); |
305 | 305 | break; |
306 | 306 | } |
307 | 307 | } elseif ($messenger->name == 'html' && $message_type->name == 'receipt') { |
308 | 308 | switch ($template_file_prefix) { |
309 | 309 | case 'attendee_list_purchaser': |
310 | - $path = $base_path . $msg_prefix . 'attendee_list.template.php'; |
|
310 | + $path = $base_path.$msg_prefix.'attendee_list.template.php'; |
|
311 | 311 | $contents = EEH_Template::display_template($path, array(), true); |
312 | 312 | break; |
313 | 313 | } |
@@ -338,8 +338,8 @@ discard block |
||
338 | 338 | if ($msg instanceof EE_message_type && in_array($msg->name, $include_with)) { |
339 | 339 | $contexts = array_keys($msg->get_contexts()); |
340 | 340 | foreach ($contexts as $context) { |
341 | - $valid_shortcodes[ $context ][] = 'question_list'; |
|
342 | - $valid_shortcodes[ $context ][] = 'question'; |
|
341 | + $valid_shortcodes[$context][] = 'question_list'; |
|
342 | + $valid_shortcodes[$context][] = 'question'; |
|
343 | 343 | } |
344 | 344 | } |
345 | 345 | |
@@ -383,7 +383,7 @@ discard block |
||
383 | 383 | $extra_data |
384 | 384 | ) && isset($extra_data['data']) ? $extra_data['data'] : $aee; |
385 | 385 | |
386 | - if (! $registration instanceof EE_Registration || ! $aee instanceof EE_Messages_Addressee) { |
|
386 | + if ( ! $registration instanceof EE_Registration || ! $aee instanceof EE_Messages_Addressee) { |
|
387 | 387 | return $parsed; |
388 | 388 | } |
389 | 389 | |
@@ -392,9 +392,9 @@ discard block |
||
392 | 392 | if ( |
393 | 393 | $question instanceof EE_Question |
394 | 394 | && trim($question->display_text()) == trim($shortcode) |
395 | - && isset($aee->registrations[ $registration->ID() ]['ans_objs'][ $ansid ]) |
|
395 | + && isset($aee->registrations[$registration->ID()]['ans_objs'][$ansid]) |
|
396 | 396 | ) { |
397 | - return $aee->registrations[ $registration->ID() ]['ans_objs'][ $ansid ]->get_pretty( |
|
397 | + return $aee->registrations[$registration->ID()]['ans_objs'][$ansid]->get_pretty( |
|
398 | 398 | 'ANS_value', |
399 | 399 | 'no_wpautop' |
400 | 400 | ); |
@@ -455,7 +455,7 @@ discard block |
||
455 | 455 | public function additional_datetime_parser($parsed, $shortcode, $data, $extra_data, $shortcode_parser) |
456 | 456 | { |
457 | 457 | |
458 | - if (! $data instanceof EE_Datetime) { |
|
458 | + if ( ! $data instanceof EE_Datetime) { |
|
459 | 459 | return ''; // get out because we can only parse with the datetime object. |
460 | 460 | } |
461 | 461 | |
@@ -508,7 +508,7 @@ discard block |
||
508 | 508 | $recipient = $data['data'] instanceof EE_Messages_Addressee ? $data['data'] : null; |
509 | 509 | $recipient = ! $recipient instanceof EE_Messages_Addressee && array($extra_data) && isset($extra_data['data']) && $extra_data['data'] instanceof EE_Messages_Addressee ? $extra_data['data'] : $recipient; |
510 | 510 | |
511 | - if (! $recipient instanceof EE_Messages_Addressee) { |
|
511 | + if ( ! $recipient instanceof EE_Messages_Addressee) { |
|
512 | 512 | return $parsed; |
513 | 513 | } |
514 | 514 | |
@@ -516,7 +516,7 @@ discard block |
||
516 | 516 | case '[RECIPIENT_QUESTION_LIST]': |
517 | 517 | $att = $recipient->att_obj; |
518 | 518 | $registrations_on_attendee = $att instanceof EE_Attendee |
519 | - ? $recipient->attendees[ $att->ID() ]['reg_objs'] |
|
519 | + ? $recipient->attendees[$att->ID()]['reg_objs'] |
|
520 | 520 | : array(); |
521 | 521 | $registrations_on_attendee = empty($registrations_on_attendee) && $recipient->reg_obj instanceof EE_Registration ? array($recipient->reg_obj) : $registrations_on_attendee; |
522 | 522 | $answers = array(); |
@@ -530,12 +530,12 @@ discard block |
||
530 | 530 | if ($data['data'] instanceof EE_Messages_Addressee) { |
531 | 531 | foreach ($registrations_on_attendee as $reg) { |
532 | 532 | if ($reg instanceof EE_Registration) { |
533 | - $anss = ! empty($recipient->registrations[ $reg->ID() ]['ans_objs']) |
|
534 | - ? $recipient->registrations[ $reg->ID() ]['ans_objs'] |
|
533 | + $anss = ! empty($recipient->registrations[$reg->ID()]['ans_objs']) |
|
534 | + ? $recipient->registrations[$reg->ID()]['ans_objs'] |
|
535 | 535 | : array(); |
536 | 536 | foreach ($anss as $ans) { |
537 | 537 | if ($ans instanceof EE_Answer) { |
538 | - $answers[ $ans->ID() ] = $ans; |
|
538 | + $answers[$ans->ID()] = $ans; |
|
539 | 539 | } |
540 | 540 | } |
541 | 541 | } |
@@ -547,12 +547,12 @@ discard block |
||
547 | 547 | $event = $data['data']; |
548 | 548 | foreach ($registrations_on_attendee as $reg) { |
549 | 549 | if ($reg instanceof EE_Registration && $reg->event_ID() == $event->ID()) { |
550 | - $anss = ! empty($recipient->registrations[ $reg->ID() ]['ans_objs']) |
|
551 | - ? $recipient->registrations[ $reg->ID() ]['ans_objs'] |
|
550 | + $anss = ! empty($recipient->registrations[$reg->ID()]['ans_objs']) |
|
551 | + ? $recipient->registrations[$reg->ID()]['ans_objs'] |
|
552 | 552 | : array(); |
553 | 553 | foreach ($anss as $ans) { |
554 | 554 | if ($ans instanceof EE_Answer) { |
555 | - $answers[ $ans->ID() ] = $ans; |
|
555 | + $answers[$ans->ID()] = $ans; |
|
556 | 556 | } |
557 | 557 | } |
558 | 558 | } |
@@ -563,7 +563,7 @@ discard block |
||
563 | 563 | |
564 | 564 | // if $extra_data does not have a 'data' key then let's make sure we add it and set the EE_Messages_Addressee |
565 | 565 | // object on it. |
566 | - if (! isset($extra_data['data'])) { |
|
566 | + if ( ! isset($extra_data['data'])) { |
|
567 | 567 | $extra_data['data'] = $recipient; |
568 | 568 | } |
569 | 569 | |
@@ -620,18 +620,18 @@ discard block |
||
620 | 620 | $recipient = $data['data'] instanceof EE_Messages_Addressee ? $data['data'] : null; |
621 | 621 | $recipient = ! $recipient instanceof EE_Messages_Addressee && array($extra_data) && isset($extra_data['data']) && $extra_data['data'] instanceof EE_Messages_Addressee ? $extra_data['data'] : $recipient; |
622 | 622 | |
623 | - if (! $recipient instanceof EE_Messages_Addressee) { |
|
623 | + if ( ! $recipient instanceof EE_Messages_Addressee) { |
|
624 | 624 | return $parsed; |
625 | 625 | } |
626 | 626 | |
627 | 627 | switch ($shortcode) { |
628 | 628 | case '[PRIMARY_REGISTRANT_QUESTION_LIST]': |
629 | - if (! $recipient->primary_att_obj instanceof EE_Attendee || ! $recipient->primary_reg_obj instanceof EE_Registration) { |
|
629 | + if ( ! $recipient->primary_att_obj instanceof EE_Attendee || ! $recipient->primary_reg_obj instanceof EE_Registration) { |
|
630 | 630 | return ''; |
631 | 631 | } |
632 | 632 | $registration = $recipient->primary_reg_obj; |
633 | - $answers = isset($recipient->registrations[ $registration->ID() ]['ans_objs']) |
|
634 | - ? $recipient->registrations[ $registration->ID() ]['ans_objs'] |
|
633 | + $answers = isset($recipient->registrations[$registration->ID()]['ans_objs']) |
|
634 | + ? $recipient->registrations[$registration->ID()]['ans_objs'] |
|
635 | 635 | : array(); |
636 | 636 | if (empty($answers)) { |
637 | 637 | return ''; |
@@ -640,11 +640,11 @@ discard block |
||
640 | 640 | ? $data['template']['question_list'] |
641 | 641 | : $extra_data['template']['question_list']; |
642 | 642 | $valid_shortcodes = array('question'); |
643 | - $answers = $recipient->registrations[ $registration->ID() ]['ans_objs']; |
|
643 | + $answers = $recipient->registrations[$registration->ID()]['ans_objs']; |
|
644 | 644 | $questions = isset($recipient->questions) ? $recipient->questions : array(); |
645 | 645 | // if $extra_data does not have a 'data' key then let's make sure we add it and set the EE_Messages_Addressee |
646 | 646 | // object on it. |
647 | - if (! isset($extra_data['data'])) { |
|
647 | + if ( ! isset($extra_data['data'])) { |
|
648 | 648 | $extra_data['data'] = $recipient; |
649 | 649 | } |
650 | 650 | return $this->_parse_question_list_for_primary_or_recipient_registration( |
@@ -677,7 +677,7 @@ discard block |
||
677 | 677 | $setup_args = array( |
678 | 678 | 'mtfilename' => 'EE_Newsletter_message_type.class.php', |
679 | 679 | 'autoloadpaths' => array( |
680 | - EE_CAF_LIBRARIES . 'messages/message_type/newsletter/', |
|
680 | + EE_CAF_LIBRARIES.'messages/message_type/newsletter/', |
|
681 | 681 | ), |
682 | 682 | 'messengers_to_activate_with' => array('email'), |
683 | 683 | 'messengers_to_validate_with' => array('email'), |
@@ -688,7 +688,7 @@ discard block |
||
688 | 688 | // register payment reminder message type |
689 | 689 | $setup_args = array( |
690 | 690 | 'mtfilename' => 'EE_Payment_Reminder_message_type.class.php', |
691 | - 'autoloadpaths' => array(EE_CAF_LIBRARIES . 'messages/message_type/payment_reminder/'), |
|
691 | + 'autoloadpaths' => array(EE_CAF_LIBRARIES.'messages/message_type/payment_reminder/'), |
|
692 | 692 | 'messengers_to_activate_with' => array('email'), |
693 | 693 | 'messengers_to_validate_with' => array('email'), |
694 | 694 | 'messengers_supporting_default_template_pack_with' => array('email'), |
@@ -698,7 +698,7 @@ discard block |
||
698 | 698 | // register payment declined message type |
699 | 699 | $setup_args = array( |
700 | 700 | 'mtfilename' => 'EE_Payment_Declined_message_type.class.php', |
701 | - 'autoloadpaths' => array(EE_CAF_LIBRARIES . 'messages/message_type/payment_declined/'), |
|
701 | + 'autoloadpaths' => array(EE_CAF_LIBRARIES.'messages/message_type/payment_declined/'), |
|
702 | 702 | 'messengers_to_activate_with' => array('email'), |
703 | 703 | 'messengers_to_validate_with' => array('email'), |
704 | 704 | 'messengers_supporting_default_template_pack_with' => array('email'), |
@@ -708,7 +708,7 @@ discard block |
||
708 | 708 | // register registration declined message type |
709 | 709 | $setup_args = array( |
710 | 710 | 'mtfilename' => 'EE_Declined_Registration_message_type.class.php', |
711 | - 'autoloadpaths' => array(EE_CAF_LIBRARIES . 'messages/message_type/declined_registration/'), |
|
711 | + 'autoloadpaths' => array(EE_CAF_LIBRARIES.'messages/message_type/declined_registration/'), |
|
712 | 712 | 'messengers_to_activate_with' => array('email'), |
713 | 713 | 'messengers_to_validate_with' => array('email'), |
714 | 714 | 'messengers_supporting_default_template_pack_with' => array('email'), |
@@ -718,7 +718,7 @@ discard block |
||
718 | 718 | // register registration cancelled message type |
719 | 719 | $setup_args = array( |
720 | 720 | 'mtfilename' => 'EE_Cancelled_Registration_message_type.class.php', |
721 | - 'autoloadpaths' => array(EE_CAF_LIBRARIES . 'messages/message_type/cancelled_registration/'), |
|
721 | + 'autoloadpaths' => array(EE_CAF_LIBRARIES.'messages/message_type/cancelled_registration/'), |
|
722 | 722 | 'messengers_to_activate_with' => array('email'), |
723 | 723 | 'messengers_to_validate_with' => array('email'), |
724 | 724 | 'messengers_supporting_default_template_pack_with' => array('email'), |
@@ -729,7 +729,7 @@ discard block |
||
729 | 729 | // register payment failed message type |
730 | 730 | $setup_args = array( |
731 | 731 | 'mtfilename' => 'EE_Payment_Failed_message_type.class.php', |
732 | - 'autoloadpaths' => array(EE_CAF_LIBRARIES . 'messages/message_type/payment_failed/'), |
|
732 | + 'autoloadpaths' => array(EE_CAF_LIBRARIES.'messages/message_type/payment_failed/'), |
|
733 | 733 | 'messengers_to_activate_with' => array('email'), |
734 | 734 | 'messengers_to_validate_with' => array('email'), |
735 | 735 | 'messengers_supporting_default_template_pack_with' => array('email'), |
@@ -739,7 +739,7 @@ discard block |
||
739 | 739 | // register payment declined message type |
740 | 740 | $setup_args = array( |
741 | 741 | 'mtfilename' => 'EE_Payment_Cancelled_message_type.class.php', |
742 | - 'autoloadpaths' => array(EE_CAF_LIBRARIES . 'messages/message_type/payment_cancelled/'), |
|
742 | + 'autoloadpaths' => array(EE_CAF_LIBRARIES.'messages/message_type/payment_cancelled/'), |
|
743 | 743 | 'messengers_to_activate_with' => array('email'), |
744 | 744 | 'messengers_to_validate_with' => array('email'), |
745 | 745 | 'messengers_supporting_default_template_pack_with' => array('email'), |
@@ -759,7 +759,7 @@ discard block |
||
759 | 759 | { |
760 | 760 | $setup_args = array( |
761 | 761 | 'autoloadpaths' => array( |
762 | - EE_CAF_LIBRARIES . 'shortcodes/', |
|
762 | + EE_CAF_LIBRARIES.'shortcodes/', |
|
763 | 763 | ), |
764 | 764 | 'msgr_validator_callback' => array('EE_Newsletter_Shortcodes', 'messenger_validator_config'), |
765 | 765 | 'msgr_template_fields_callback' => array('EE_Newsletter_Shortcodes', 'messenger_template_fields'), |
@@ -793,7 +793,7 @@ discard block |
||
793 | 793 | foreach ($answers as $answer) { |
794 | 794 | if ($answer instanceof EE_Answer) { |
795 | 795 | // first see if the question is in our $questions array. If not then try to get from answer object. |
796 | - $question = isset($questions[ $answer->ID() ]) ? $questions[ $answer->ID() ] : null; |
|
796 | + $question = isset($questions[$answer->ID()]) ? $questions[$answer->ID()] : null; |
|
797 | 797 | $question = ! $question instanceof EE_Question ? $answer->question() : $question; |
798 | 798 | if ( |
799 | 799 | ! $question instanceof EE_Question |
@@ -10,806 +10,806 @@ |
||
10 | 10 | */ |
11 | 11 | class EE_Caf_Messages |
12 | 12 | { |
13 | - /** |
|
14 | - * constructor. |
|
15 | - */ |
|
16 | - public function __construct() |
|
17 | - { |
|
18 | - $this->_caf_hooks(); |
|
19 | - } |
|
20 | - |
|
21 | - |
|
22 | - /** |
|
23 | - * Contains all the hooks filters for setting up caffeinated messages functionality. |
|
24 | - * |
|
25 | - * @since 4.3.2 |
|
26 | - * |
|
27 | - * @return void |
|
28 | - */ |
|
29 | - private function _caf_hooks() |
|
30 | - { |
|
31 | - add_filter('FHEE__EED_Messages___set_messages_paths___MSG_PATHS', array($this, 'messages_autoload_paths'), 5); |
|
32 | - add_filter( |
|
33 | - 'FHEE__EE_Email_messenger__get_validator_config', |
|
34 | - array($this, 'email_messenger_validator_config'), |
|
35 | - 5, |
|
36 | - 2 |
|
37 | - ); |
|
38 | - add_filter( |
|
39 | - 'FHEE__EE_Email_messenger__get_template_fields', |
|
40 | - array($this, 'email_messenger_template_fields'), |
|
41 | - 5, |
|
42 | - 2 |
|
43 | - ); |
|
44 | - add_filter( |
|
45 | - 'FHEE__EE_Html_messenger__get_template_fields', |
|
46 | - array($this, 'html_messenger_template_fields'), |
|
47 | - 5, |
|
48 | - 2 |
|
49 | - ); |
|
50 | - add_filter( |
|
51 | - 'FHEE__EE_Html_messenger__get_validator_config', |
|
52 | - array($this, 'html_messenger_validator_config'), |
|
53 | - 5, |
|
54 | - 2 |
|
55 | - ); |
|
56 | - add_filter('FHEE__EE_Pdf_messenger__get_template_fields', array($this, 'pdf_messenger_template_fields'), 5, 2); |
|
57 | - add_filter( |
|
58 | - 'FHEE__EE_Pdf_messenger__get_validator_config', |
|
59 | - array($this, 'pdf_messenger_validator_config'), |
|
60 | - 5, |
|
61 | - 2 |
|
62 | - ); |
|
63 | - add_filter( |
|
64 | - 'FHEE__EE_Messages_Template_Pack__get_specific_template__contents', |
|
65 | - array($this, 'new_default_templates'), |
|
66 | - 5, |
|
67 | - 7 |
|
68 | - ); |
|
69 | - add_filter( |
|
70 | - 'FHEE__EE_Messages_Base__get_valid_shortcodes', |
|
71 | - array($this, 'message_types_valid_shortcodes'), |
|
72 | - 5, |
|
73 | - 2 |
|
74 | - ); |
|
75 | - |
|
76 | - // shortcode parsers |
|
77 | - add_filter('FHEE__EE_Attendee_Shortcodes__shortcodes', array($this, 'additional_attendee_shortcodes'), 5, 2); |
|
78 | - add_filter('FHEE__EE_Attendee_Shortcodes__parser_after', array($this, 'additional_attendee_parser'), 5, 5); |
|
79 | - add_filter( |
|
80 | - 'FHEE__EE_Recipient_List_Shortcodes__shortcodes', |
|
81 | - array($this, 'additional_recipient_details_shortcodes'), |
|
82 | - 5, |
|
83 | - 2 |
|
84 | - ); |
|
85 | - add_filter( |
|
86 | - 'FHEE__EE_Recipient_List_Shortcodes__parser_after', |
|
87 | - array($this, 'additional_recipient_details_parser'), |
|
88 | - 5, |
|
89 | - 5 |
|
90 | - ); |
|
91 | - add_filter( |
|
92 | - 'FHEE__EE_Primary_Registration_List_Shortcodes__shortcodes', |
|
93 | - array($this, 'additional_primary_registration_details_shortcodes'), |
|
94 | - 5, |
|
95 | - 2 |
|
96 | - ); |
|
97 | - add_filter( |
|
98 | - 'FHEE__EE_Primary_Registration_List_Shortcodes__parser_after', |
|
99 | - array($this, 'additional_primary_registration_details_parser'), |
|
100 | - 5, |
|
101 | - 5 |
|
102 | - ); |
|
103 | - |
|
104 | - /** |
|
105 | - * @since 4.2.0 |
|
106 | - */ |
|
107 | - add_filter('FHEE__EE_Datetime_Shortcodes__shortcodes', array($this, 'additional_datetime_shortcodes'), 10, 2); |
|
108 | - add_filter('FHEE__EE_Datetime_Shortcodes__parser_after', array($this, 'additional_datetime_parser'), 10, 5); |
|
109 | - |
|
110 | - /** |
|
111 | - * @since 4.3.0 |
|
112 | - */ |
|
113 | - // eat our own dog food! |
|
114 | - add_action('EE_Brewing_Regular___messages_caf', array($this, 'register_caf_message_types')); |
|
115 | - add_action('EE_Brewing_Regular___messages_caf', array($this, 'register_caf_shortcodes')); |
|
116 | - do_action('EE_Brewing_Regular___messages_caf'); |
|
117 | - } |
|
118 | - |
|
119 | - |
|
120 | - /** |
|
121 | - * This just allows us to add additional paths to the autoloader (EED_Messages::autoload_messages()) for the |
|
122 | - * messages system. |
|
123 | - * |
|
124 | - * @param array $dir_ref original array of paths |
|
125 | - * |
|
126 | - * @return array appended paths |
|
127 | - */ |
|
128 | - public function messages_autoload_paths($dir_ref) |
|
129 | - { |
|
130 | - $dir_ref[] = EE_CAF_LIBRARIES . 'shortcodes/'; |
|
131 | - |
|
132 | - return $dir_ref; |
|
133 | - } |
|
134 | - |
|
135 | - |
|
136 | - public function email_messenger_validator_config($validator_config, EE_Email_messenger $messenger) |
|
137 | - { |
|
138 | - $validator_config['attendee_list'] = array( |
|
139 | - 'shortcodes' => array('attendee', 'event_list', 'ticket_list', 'question_list'), |
|
140 | - 'required' => array('[ATTENDEE_LIST]'), |
|
141 | - ); |
|
142 | - $validator_config['question_list'] = array( |
|
143 | - 'shortcodes' => array('question'), |
|
144 | - 'required' => array('[QUESTION_LIST]'), |
|
145 | - ); |
|
146 | - |
|
147 | - return $validator_config; |
|
148 | - } |
|
149 | - |
|
150 | - |
|
151 | - public function html_messenger_validator_config($validator_config, EE_Html_messenger $messenger) |
|
152 | - { |
|
153 | - $validator_config['attendee_list'] = array( |
|
154 | - 'shortcodes' => array('attendee', 'question_list'), |
|
155 | - 'required' => array('[ATTENDEE_LIST]'), |
|
156 | - ); |
|
157 | - $validator_config['question_list'] = array( |
|
158 | - 'shortcodes' => array('question'), |
|
159 | - 'required' => array('[QUESTION_LIST]'), |
|
160 | - ); |
|
161 | - |
|
162 | - return $validator_config; |
|
163 | - } |
|
164 | - |
|
165 | - |
|
166 | - public function pdf_messenger_validator_config($validator_config, EE_Pdf_messenger $messenger) |
|
167 | - { |
|
168 | - $validator_config['attendee_list'] = array( |
|
169 | - 'shortcodes' => array('attendee', 'event_list', 'ticket_list', 'question_list'), |
|
170 | - 'required' => array('[ATTENDEE_LIST]'), |
|
171 | - ); |
|
172 | - $validator_config['question_list'] = array( |
|
173 | - 'shortcodes' => array('question'), |
|
174 | - 'required' => array('[QUESTION_LIST]'), |
|
175 | - ); |
|
176 | - |
|
177 | - return $validator_config; |
|
178 | - } |
|
179 | - |
|
180 | - |
|
181 | - public function email_messenger_template_fields($template_fields, EE_Email_messenger $messenger) |
|
182 | - { |
|
183 | - $template_fields['extra']['content']['question_list'] = array( |
|
184 | - 'input' => 'textarea', |
|
185 | - 'label' => '[QUESTION_LIST]', |
|
186 | - 'type' => 'string', |
|
187 | - 'required' => true, |
|
188 | - 'validation' => true, |
|
189 | - 'format' => '%s', |
|
190 | - 'css_class' => 'large-text', |
|
191 | - 'rows' => '5', |
|
192 | - 'shortcodes_required' => array('[QUESTION_LIST]'), |
|
193 | - ); |
|
194 | - |
|
195 | - return $template_fields; |
|
196 | - } |
|
197 | - |
|
198 | - |
|
199 | - public function html_messenger_template_fields($template_fields, EE_Html_messenger $messenger) |
|
200 | - { |
|
201 | - $template_fields['extra']['content']['question_list'] = array( |
|
202 | - 'input' => 'textarea', |
|
203 | - 'label' => '[QUESTION_LIST]', |
|
204 | - 'type' => 'string', |
|
205 | - 'required' => true, |
|
206 | - 'validation' => true, |
|
207 | - 'format' => '%s', |
|
208 | - 'css_class' => 'large-text', |
|
209 | - 'rows' => '5', |
|
210 | - 'shortcodes_required' => array('[QUESTION_LIST]'), |
|
211 | - ); |
|
212 | - |
|
213 | - return $template_fields; |
|
214 | - } |
|
215 | - |
|
216 | - |
|
217 | - public function pdf_messenger_template_fields($template_fields, EE_Pdf_messenger $messenger) |
|
218 | - { |
|
219 | - $template_fields['extra']['content']['question_list'] = array( |
|
220 | - 'input' => 'textarea', |
|
221 | - 'label' => '[QUESTION_LIST]', |
|
222 | - 'type' => 'string', |
|
223 | - 'required' => true, |
|
224 | - 'validation' => true, |
|
225 | - 'format' => '%s', |
|
226 | - 'css_class' => 'large-text', |
|
227 | - 'rows' => '5', |
|
228 | - 'shortcodes_required' => array('[QUESTION_LIST]'), |
|
229 | - ); |
|
230 | - |
|
231 | - return $template_fields; |
|
232 | - } |
|
233 | - |
|
234 | - |
|
235 | - public function new_default_templates( |
|
236 | - $contents, |
|
237 | - $actual_path, |
|
238 | - EE_messenger $messenger, |
|
239 | - EE_message_type $message_type, |
|
240 | - $field, |
|
241 | - $context, |
|
242 | - EE_Messages_Template_Pack $template_pack |
|
243 | - ) { |
|
244 | - |
|
245 | - // we're only modifying templates for the default template pack |
|
246 | - if (! $template_pack instanceof EE_Messages_Template_Pack_Default) { |
|
247 | - return $contents; |
|
248 | - } |
|
249 | - |
|
250 | - // the template file name we're replacing contents for. |
|
251 | - $template_file_prefix = $field . '_' . $context; |
|
252 | - $msg_prefix = $messenger->name . '_' . $message_type->name . '_'; |
|
253 | - |
|
254 | - $base_path = EE_CAF_LIBRARIES . 'messages/defaults/default/'; |
|
255 | - |
|
256 | - if ($messenger->name == 'email' && $message_type->name == 'registration') { |
|
257 | - switch ($template_file_prefix) { |
|
258 | - case 'question_list_admin': |
|
259 | - case 'question_list_attendee': |
|
260 | - case 'question_list_primary_attendee': |
|
261 | - $path = $base_path . $msg_prefix . 'question_list.template.php'; |
|
262 | - $contents = EEH_Template::display_template($path, array(), true); |
|
263 | - break; |
|
264 | - |
|
265 | - case 'attendee_list_primary_attendee': |
|
266 | - $path = $base_path . $msg_prefix . 'attendee_list.template.php'; |
|
267 | - $contents = EEH_Template::display_template($path, array(), true); |
|
268 | - break; |
|
269 | - |
|
270 | - case 'attendee_list_admin': |
|
271 | - $path = $base_path . $msg_prefix . 'attendee_list_admin.template.php'; |
|
272 | - $contents = EEH_Template::display_template( |
|
273 | - $path, |
|
274 | - array(), |
|
275 | - true |
|
276 | - ); |
|
277 | - break; |
|
278 | - |
|
279 | - case 'attendee_list_attendee': |
|
280 | - $contents = ''; |
|
281 | - break; |
|
282 | - |
|
283 | - case 'event_list_attendee': |
|
284 | - $path = $base_path . $msg_prefix . 'event_list_attendee.template.php'; |
|
285 | - $contents = EEH_Template::display_template($path, array(), true); |
|
286 | - break; |
|
287 | - } |
|
288 | - } elseif ($messenger->name == 'email' && $message_type->name == 'newsletter') { |
|
289 | - switch ($template_file_prefix) { |
|
290 | - case 'content_attendee': |
|
291 | - $path = $base_path . $msg_prefix . 'content.template.php'; |
|
292 | - $contents = EEH_Template::display_template($path, array(), true); |
|
293 | - break; |
|
294 | - |
|
295 | - case 'newsletter_content_attendee': |
|
296 | - $path = $base_path . $msg_prefix . 'newsletter_content.template.php'; |
|
297 | - $contents = EEH_Template::display_template($path, array(), true); |
|
298 | - break; |
|
299 | - |
|
300 | - case 'newsletter_subject_attendee': |
|
301 | - $path = $base_path . $msg_prefix . 'subject.template.php'; |
|
302 | - $contents = EEH_Template::display_template($path, array(), true); |
|
303 | - break; |
|
304 | - } |
|
305 | - } elseif ($messenger->name == 'html' && $message_type->name == 'receipt') { |
|
306 | - switch ($template_file_prefix) { |
|
307 | - case 'attendee_list_purchaser': |
|
308 | - $path = $base_path . $msg_prefix . 'attendee_list.template.php'; |
|
309 | - $contents = EEH_Template::display_template($path, array(), true); |
|
310 | - break; |
|
311 | - } |
|
312 | - } |
|
313 | - |
|
314 | - return $contents; |
|
315 | - } |
|
316 | - |
|
317 | - |
|
318 | - public function message_types_valid_shortcodes($valid_shortcodes, EE_Messages_Base $msg) |
|
319 | - { |
|
320 | - // make sure question_list and question are ONLY added for the core message types. Any other message types will have to explicitly set question_list as a valid shortcode. |
|
321 | - $include_with = array( |
|
322 | - 'registration', |
|
323 | - 'cancelled_registration', |
|
324 | - 'declined_registration', |
|
325 | - 'not_approved_registration', |
|
326 | - 'payment_declined', |
|
327 | - 'payment_failed', |
|
328 | - 'payment_cancelled', |
|
329 | - 'payment', |
|
330 | - 'payment_reminder', |
|
331 | - 'pending_approval', |
|
332 | - 'registration_summary', |
|
333 | - 'invoice', |
|
334 | - 'receipt', |
|
335 | - ); |
|
336 | - if ($msg instanceof EE_message_type && in_array($msg->name, $include_with)) { |
|
337 | - $contexts = array_keys($msg->get_contexts()); |
|
338 | - foreach ($contexts as $context) { |
|
339 | - $valid_shortcodes[ $context ][] = 'question_list'; |
|
340 | - $valid_shortcodes[ $context ][] = 'question'; |
|
341 | - } |
|
342 | - } |
|
343 | - |
|
344 | - return $valid_shortcodes; |
|
345 | - } |
|
346 | - |
|
347 | - |
|
348 | - public function additional_attendee_shortcodes($shortcodes, $shortcode_parser) |
|
349 | - { |
|
350 | - $shortcodes['[ANSWER_*]'] = esc_html__( |
|
351 | - 'This is a special dynamic shortcode. Right after the "*", add the exact text of a existing question, and if there is an answer for that question for this registrant, that will take the place of this shortcode.', |
|
352 | - 'event_espresso' |
|
353 | - ); |
|
354 | - |
|
355 | - return $shortcodes; |
|
356 | - } |
|
357 | - |
|
358 | - |
|
359 | - public function additional_attendee_parser($parsed, $shortcode, $data, $extra_data, $shortcode_parser) |
|
360 | - { |
|
361 | - |
|
362 | - if ( |
|
363 | - strpos($shortcode, '[ANSWER_*') === false |
|
364 | - || ! isset($extra_data['data']->questions) |
|
365 | - || ! isset($extra_data['data']->registrations) |
|
366 | - ) { |
|
367 | - return $parsed; |
|
368 | - } |
|
369 | - |
|
370 | - // let's get the question from the code. |
|
371 | - $shortcode = str_replace('[ANSWER_*', '', $shortcode); |
|
372 | - $shortcode = trim(str_replace(']', '', $shortcode)); |
|
373 | - |
|
374 | - $registration = $data instanceof EE_Registration ? $data : null; |
|
375 | - $registration = ! $registration instanceof EE_Registration && is_array( |
|
376 | - $extra_data |
|
377 | - ) && isset($extra_data['data']) && $extra_data['data'] instanceof EE_Registration ? $extra_data['data'] : $registration; |
|
378 | - |
|
379 | - $aee = $data instanceof EE_Messages_Addressee ? $data : null; |
|
380 | - $aee = ! $aee instanceof EE_Messages_Addressee && is_array( |
|
381 | - $extra_data |
|
382 | - ) && isset($extra_data['data']) ? $extra_data['data'] : $aee; |
|
383 | - |
|
384 | - if (! $registration instanceof EE_Registration || ! $aee instanceof EE_Messages_Addressee) { |
|
385 | - return $parsed; |
|
386 | - } |
|
387 | - |
|
388 | - // now let's figure out which question has this text. |
|
389 | - foreach ($aee->questions as $ansid => $question) { |
|
390 | - if ( |
|
391 | - $question instanceof EE_Question |
|
392 | - && trim($question->display_text()) == trim($shortcode) |
|
393 | - && isset($aee->registrations[ $registration->ID() ]['ans_objs'][ $ansid ]) |
|
394 | - ) { |
|
395 | - return $aee->registrations[ $registration->ID() ]['ans_objs'][ $ansid ]->get_pretty( |
|
396 | - 'ANS_value', |
|
397 | - 'no_wpautop' |
|
398 | - ); |
|
399 | - } |
|
400 | - } |
|
401 | - |
|
402 | - // nothing! |
|
403 | - return $parsed; |
|
404 | - } |
|
405 | - |
|
406 | - |
|
407 | - /** |
|
408 | - * Callback for additional shortcodes filter for adding additional datetime shortcodes. |
|
409 | - * |
|
410 | - * @since 4.2 |
|
411 | - * |
|
412 | - * @param array $shortcodes array of shortcodes and |
|
413 | - * descriptions |
|
414 | - * @param EE_Datetime_Shortcodes $shortcode_parser EE_Shortcodes object |
|
415 | - * |
|
416 | - * @return array array of shortcodes and |
|
417 | - * descriptions |
|
418 | - */ |
|
419 | - public function additional_datetime_shortcodes($shortcodes, $shortcode_parser) |
|
420 | - { |
|
421 | - $shortcodes['[DTT_NAME]'] = esc_html__( |
|
422 | - 'This will be parsed to the Title given for a Datetime', |
|
423 | - 'event_espresso' |
|
424 | - ); |
|
425 | - $shortcodes['[DTT_DESCRIPTION]'] = esc_html__( |
|
426 | - 'This will be parsed to the description for a Datetime', |
|
427 | - 'event_espresso' |
|
428 | - ); |
|
429 | - $shortcodes['[DTT_NAME_OR_DATES]'] = esc_html__( |
|
430 | - 'When parsed, if the Datetime has a name, it is used, otherwise a formatted string including the start date and end date will be used.', |
|
431 | - 'event_espresso' |
|
432 | - ); |
|
433 | - |
|
434 | - return $shortcodes; |
|
435 | - } |
|
436 | - |
|
437 | - |
|
438 | - /** |
|
439 | - * Callback for additional shortcodes parser filter used for adding parser for new |
|
440 | - * Datetime shortcodes |
|
441 | - * |
|
442 | - * @since 4.2 |
|
443 | - * |
|
444 | - * @param string $parsed The finished parsed string for the given shortcode. |
|
445 | - * @param string $shortcode The shortcode being parsed. |
|
446 | - * @param object $data The incoming data object for the Shortcode Parser. |
|
447 | - * @param object $extra_data The incoming extra date object for the Shortcode |
|
448 | - * Parser. |
|
449 | - * @param EE_Datetime_Shortcodes $shortcode_parser |
|
450 | - * |
|
451 | - * @return string The new parsed string. |
|
452 | - */ |
|
453 | - public function additional_datetime_parser($parsed, $shortcode, $data, $extra_data, $shortcode_parser) |
|
454 | - { |
|
455 | - |
|
456 | - if (! $data instanceof EE_Datetime) { |
|
457 | - return ''; // get out because we can only parse with the datetime object. |
|
458 | - } |
|
459 | - |
|
460 | - switch ($shortcode) { |
|
461 | - case '[DTT_NAME]': |
|
462 | - return $data->name(); |
|
463 | - break; |
|
464 | - case '[DTT_DESCRIPTION]': |
|
465 | - return $data->description(); |
|
466 | - break; |
|
467 | - case '[DTT_NAME_OR_DATES]': |
|
468 | - return $data->get_dtt_display_name(true); |
|
469 | - break; |
|
470 | - default: |
|
471 | - return $parsed; |
|
472 | - break; |
|
473 | - } |
|
474 | - } |
|
475 | - |
|
476 | - |
|
477 | - public function additional_recipient_details_shortcodes($shortcodes, $shortcode_parser) |
|
478 | - { |
|
479 | - $shortcodes['[RECIPIENT_QUESTION_LIST]'] = esc_html__( |
|
480 | - 'This is used to indicate where you want the list of questions and answers to show for the person receiving the message.', |
|
481 | - 'event_espresso' |
|
482 | - ); |
|
483 | - |
|
484 | - return $shortcodes; |
|
485 | - } |
|
486 | - |
|
487 | - |
|
488 | - /** |
|
489 | - * Callback for FHEE__EE_Recipient_List_Shortcodes__parser_after filter (dynamic filter). |
|
490 | - * |
|
491 | - * @param string $parsed The original parsed content for the shortcode |
|
492 | - * @param string $shortcode The shortcode being parsed |
|
493 | - * @param array $data The shortcode parser data array |
|
494 | - * @param array $extra_data The shortcode parser extra data array |
|
495 | - * @param \EE_Shortcodes $shortcode_parser Shortcode parser. |
|
496 | - * |
|
497 | - * @return string |
|
498 | - */ |
|
499 | - public function additional_recipient_details_parser($parsed, $shortcode, $data, $extra_data, $shortcode_parser) |
|
500 | - { |
|
501 | - |
|
502 | - if (array($data) && ! isset($data['data'])) { |
|
503 | - return $parsed; |
|
504 | - } |
|
505 | - |
|
506 | - $recipient = $data['data'] instanceof EE_Messages_Addressee ? $data['data'] : null; |
|
507 | - $recipient = ! $recipient instanceof EE_Messages_Addressee && array($extra_data) && isset($extra_data['data']) && $extra_data['data'] instanceof EE_Messages_Addressee ? $extra_data['data'] : $recipient; |
|
508 | - |
|
509 | - if (! $recipient instanceof EE_Messages_Addressee) { |
|
510 | - return $parsed; |
|
511 | - } |
|
512 | - |
|
513 | - switch ($shortcode) { |
|
514 | - case '[RECIPIENT_QUESTION_LIST]': |
|
515 | - $att = $recipient->att_obj; |
|
516 | - $registrations_on_attendee = $att instanceof EE_Attendee |
|
517 | - ? $recipient->attendees[ $att->ID() ]['reg_objs'] |
|
518 | - : array(); |
|
519 | - $registrations_on_attendee = empty($registrations_on_attendee) && $recipient->reg_obj instanceof EE_Registration ? array($recipient->reg_obj) : $registrations_on_attendee; |
|
520 | - $answers = array(); |
|
521 | - |
|
522 | - $template = is_array($data['template']) && isset($data['template']['question_list']) |
|
523 | - ? $data['template']['question_list'] |
|
524 | - : $extra_data['template']['question_list']; |
|
525 | - $valid_shortcodes = array('question'); |
|
526 | - |
|
527 | - // if the context is main_content then get all answers for all registrations on this attendee |
|
528 | - if ($data['data'] instanceof EE_Messages_Addressee) { |
|
529 | - foreach ($registrations_on_attendee as $reg) { |
|
530 | - if ($reg instanceof EE_Registration) { |
|
531 | - $anss = ! empty($recipient->registrations[ $reg->ID() ]['ans_objs']) |
|
532 | - ? $recipient->registrations[ $reg->ID() ]['ans_objs'] |
|
533 | - : array(); |
|
534 | - foreach ($anss as $ans) { |
|
535 | - if ($ans instanceof EE_Answer) { |
|
536 | - $answers[ $ans->ID() ] = $ans; |
|
537 | - } |
|
538 | - } |
|
539 | - } |
|
540 | - } |
|
541 | - } |
|
542 | - |
|
543 | - // if the context is the event list parser, then let's return just the answers for all registrations attached to the recipient for that event. |
|
544 | - if ($data['data'] instanceof EE_Event) { |
|
545 | - $event = $data['data']; |
|
546 | - foreach ($registrations_on_attendee as $reg) { |
|
547 | - if ($reg instanceof EE_Registration && $reg->event_ID() == $event->ID()) { |
|
548 | - $anss = ! empty($recipient->registrations[ $reg->ID() ]['ans_objs']) |
|
549 | - ? $recipient->registrations[ $reg->ID() ]['ans_objs'] |
|
550 | - : array(); |
|
551 | - foreach ($anss as $ans) { |
|
552 | - if ($ans instanceof EE_Answer) { |
|
553 | - $answers[ $ans->ID() ] = $ans; |
|
554 | - } |
|
555 | - } |
|
556 | - } |
|
557 | - } |
|
558 | - } |
|
559 | - |
|
560 | - $questions = $questions = isset($recipient->questions) ? $recipient->questions : array(); |
|
561 | - |
|
562 | - // if $extra_data does not have a 'data' key then let's make sure we add it and set the EE_Messages_Addressee |
|
563 | - // object on it. |
|
564 | - if (! isset($extra_data['data'])) { |
|
565 | - $extra_data['data'] = $recipient; |
|
566 | - } |
|
567 | - |
|
568 | - return $this->_parse_question_list_for_primary_or_recipient_registration( |
|
569 | - $shortcode_parser, |
|
570 | - $questions, |
|
571 | - $answers, |
|
572 | - $template, |
|
573 | - $valid_shortcodes, |
|
574 | - $extra_data |
|
575 | - ); |
|
576 | - break; |
|
577 | - |
|
578 | - default: |
|
579 | - return $parsed; |
|
580 | - break; |
|
581 | - } |
|
582 | - } |
|
583 | - |
|
584 | - |
|
585 | - public function additional_primary_registration_details_shortcodes($shortcodes, $shortcode_parser) |
|
586 | - { |
|
587 | - $shortcodes['[PRIMARY_REGISTRANT_QUESTION_LIST]'] = esc_html__( |
|
588 | - 'This is used to indicate the questions and answers for the primary_registrant. It should be placed in the "[attendee_list]" field', |
|
589 | - 'event_espresso' |
|
590 | - ); |
|
591 | - |
|
592 | - return $shortcodes; |
|
593 | - } |
|
594 | - |
|
595 | - |
|
596 | - /** |
|
597 | - * Callback for FHEE__EE_Primary_Registration_List_Shortcodes__parser_after filter (dynamic filter). |
|
598 | - * |
|
599 | - * @param string $parsed The original parsed content for the shortcode |
|
600 | - * @param string $shortcode The shortcode being parsed |
|
601 | - * @param array $data The shortcode parser data array |
|
602 | - * @param array $extra_data The shortcode parser extra data array |
|
603 | - * @param \EE_Shortcodes $shortcode_parser Shortcode parser. |
|
604 | - * |
|
605 | - * @return string |
|
606 | - */ |
|
607 | - public function additional_primary_registration_details_parser( |
|
608 | - $parsed, |
|
609 | - $shortcode, |
|
610 | - $data, |
|
611 | - $extra_data, |
|
612 | - $shortcode_parser |
|
613 | - ) { |
|
614 | - if (array($data) && ! isset($data['data'])) { |
|
615 | - return $parsed; |
|
616 | - } |
|
617 | - |
|
618 | - $recipient = $data['data'] instanceof EE_Messages_Addressee ? $data['data'] : null; |
|
619 | - $recipient = ! $recipient instanceof EE_Messages_Addressee && array($extra_data) && isset($extra_data['data']) && $extra_data['data'] instanceof EE_Messages_Addressee ? $extra_data['data'] : $recipient; |
|
620 | - |
|
621 | - if (! $recipient instanceof EE_Messages_Addressee) { |
|
622 | - return $parsed; |
|
623 | - } |
|
624 | - |
|
625 | - switch ($shortcode) { |
|
626 | - case '[PRIMARY_REGISTRANT_QUESTION_LIST]': |
|
627 | - if (! $recipient->primary_att_obj instanceof EE_Attendee || ! $recipient->primary_reg_obj instanceof EE_Registration) { |
|
628 | - return ''; |
|
629 | - } |
|
630 | - $registration = $recipient->primary_reg_obj; |
|
631 | - $answers = isset($recipient->registrations[ $registration->ID() ]['ans_objs']) |
|
632 | - ? $recipient->registrations[ $registration->ID() ]['ans_objs'] |
|
633 | - : array(); |
|
634 | - if (empty($answers)) { |
|
635 | - return ''; |
|
636 | - } |
|
637 | - $template = is_array($data['template']) && isset($data['template']['question_list']) |
|
638 | - ? $data['template']['question_list'] |
|
639 | - : $extra_data['template']['question_list']; |
|
640 | - $valid_shortcodes = array('question'); |
|
641 | - $answers = $recipient->registrations[ $registration->ID() ]['ans_objs']; |
|
642 | - $questions = isset($recipient->questions) ? $recipient->questions : array(); |
|
643 | - // if $extra_data does not have a 'data' key then let's make sure we add it and set the EE_Messages_Addressee |
|
644 | - // object on it. |
|
645 | - if (! isset($extra_data['data'])) { |
|
646 | - $extra_data['data'] = $recipient; |
|
647 | - } |
|
648 | - return $this->_parse_question_list_for_primary_or_recipient_registration( |
|
649 | - $shortcode_parser, |
|
650 | - $questions, |
|
651 | - $answers, |
|
652 | - $template, |
|
653 | - $valid_shortcodes, |
|
654 | - $extra_data |
|
655 | - ); |
|
656 | - break; |
|
657 | - |
|
658 | - default: |
|
659 | - return $parsed; |
|
660 | - break; |
|
661 | - } |
|
662 | - } |
|
663 | - |
|
664 | - |
|
665 | - /** |
|
666 | - * Takes care of registering the message types that are only available in caffeinated EE. |
|
667 | - * |
|
668 | - * @since 4.3.2 |
|
669 | - * |
|
670 | - * @return void |
|
671 | - */ |
|
672 | - public function register_caf_message_types() |
|
673 | - { |
|
674 | - // register newsletter message type |
|
675 | - $setup_args = array( |
|
676 | - 'mtfilename' => 'EE_Newsletter_message_type.class.php', |
|
677 | - 'autoloadpaths' => array( |
|
678 | - EE_CAF_LIBRARIES . 'messages/message_type/newsletter/', |
|
679 | - ), |
|
680 | - 'messengers_to_activate_with' => array('email'), |
|
681 | - 'messengers_to_validate_with' => array('email'), |
|
682 | - 'messengers_supporting_default_template_pack_with' => array('email'), |
|
683 | - ); |
|
684 | - EE_Register_Message_Type::register('newsletter', $setup_args); |
|
685 | - |
|
686 | - // register payment reminder message type |
|
687 | - $setup_args = array( |
|
688 | - 'mtfilename' => 'EE_Payment_Reminder_message_type.class.php', |
|
689 | - 'autoloadpaths' => array(EE_CAF_LIBRARIES . 'messages/message_type/payment_reminder/'), |
|
690 | - 'messengers_to_activate_with' => array('email'), |
|
691 | - 'messengers_to_validate_with' => array('email'), |
|
692 | - 'messengers_supporting_default_template_pack_with' => array('email'), |
|
693 | - ); |
|
694 | - EE_Register_Message_Type::register('payment_reminder', $setup_args); |
|
695 | - |
|
696 | - // register payment declined message type |
|
697 | - $setup_args = array( |
|
698 | - 'mtfilename' => 'EE_Payment_Declined_message_type.class.php', |
|
699 | - 'autoloadpaths' => array(EE_CAF_LIBRARIES . 'messages/message_type/payment_declined/'), |
|
700 | - 'messengers_to_activate_with' => array('email'), |
|
701 | - 'messengers_to_validate_with' => array('email'), |
|
702 | - 'messengers_supporting_default_template_pack_with' => array('email'), |
|
703 | - ); |
|
704 | - EE_Register_Message_Type::register('payment_declined', $setup_args); |
|
705 | - |
|
706 | - // register registration declined message type |
|
707 | - $setup_args = array( |
|
708 | - 'mtfilename' => 'EE_Declined_Registration_message_type.class.php', |
|
709 | - 'autoloadpaths' => array(EE_CAF_LIBRARIES . 'messages/message_type/declined_registration/'), |
|
710 | - 'messengers_to_activate_with' => array('email'), |
|
711 | - 'messengers_to_validate_with' => array('email'), |
|
712 | - 'messengers_supporting_default_template_pack_with' => array('email'), |
|
713 | - ); |
|
714 | - EE_Register_Message_Type::register('declined_registration', $setup_args); |
|
715 | - |
|
716 | - // register registration cancelled message type |
|
717 | - $setup_args = array( |
|
718 | - 'mtfilename' => 'EE_Cancelled_Registration_message_type.class.php', |
|
719 | - 'autoloadpaths' => array(EE_CAF_LIBRARIES . 'messages/message_type/cancelled_registration/'), |
|
720 | - 'messengers_to_activate_with' => array('email'), |
|
721 | - 'messengers_to_validate_with' => array('email'), |
|
722 | - 'messengers_supporting_default_template_pack_with' => array('email'), |
|
723 | - ); |
|
724 | - EE_Register_Message_Type::register('cancelled_registration', $setup_args); |
|
725 | - |
|
726 | - |
|
727 | - // register payment failed message type |
|
728 | - $setup_args = array( |
|
729 | - 'mtfilename' => 'EE_Payment_Failed_message_type.class.php', |
|
730 | - 'autoloadpaths' => array(EE_CAF_LIBRARIES . 'messages/message_type/payment_failed/'), |
|
731 | - 'messengers_to_activate_with' => array('email'), |
|
732 | - 'messengers_to_validate_with' => array('email'), |
|
733 | - 'messengers_supporting_default_template_pack_with' => array('email'), |
|
734 | - ); |
|
735 | - EE_Register_Message_Type::register('payment_failed', $setup_args); |
|
736 | - |
|
737 | - // register payment declined message type |
|
738 | - $setup_args = array( |
|
739 | - 'mtfilename' => 'EE_Payment_Cancelled_message_type.class.php', |
|
740 | - 'autoloadpaths' => array(EE_CAF_LIBRARIES . 'messages/message_type/payment_cancelled/'), |
|
741 | - 'messengers_to_activate_with' => array('email'), |
|
742 | - 'messengers_to_validate_with' => array('email'), |
|
743 | - 'messengers_supporting_default_template_pack_with' => array('email'), |
|
744 | - ); |
|
745 | - EE_Register_Message_Type::register('payment_cancelled', $setup_args); |
|
746 | - } |
|
747 | - |
|
748 | - |
|
749 | - /** |
|
750 | - * Takes care of registering the shortcode libraries implemented with caffeinated EE and set up related items. |
|
751 | - * |
|
752 | - * @since 4.3.2 |
|
753 | - * |
|
754 | - * @return void |
|
755 | - */ |
|
756 | - public function register_caf_shortcodes() |
|
757 | - { |
|
758 | - $setup_args = array( |
|
759 | - 'autoloadpaths' => array( |
|
760 | - EE_CAF_LIBRARIES . 'shortcodes/', |
|
761 | - ), |
|
762 | - 'msgr_validator_callback' => array('EE_Newsletter_Shortcodes', 'messenger_validator_config'), |
|
763 | - 'msgr_template_fields_callback' => array('EE_Newsletter_Shortcodes', 'messenger_template_fields'), |
|
764 | - 'list_type_shortcodes' => array('[NEWSLETTER_CONTENT]'), |
|
765 | - ); |
|
766 | - EE_Register_Messages_Shortcode_Library::register('newsletter', $setup_args); |
|
767 | - } |
|
768 | - |
|
769 | - |
|
770 | - /** |
|
771 | - * Parses a question list shortcode using given data and template |
|
772 | - * |
|
773 | - * @param \EE_Shortcodes $shortcode_parser |
|
774 | - * @param EE_Question[] $questions An array of questions indexed by answer id. |
|
775 | - * @param EE_Answer[] $answers An array of answer objects |
|
776 | - * @param string $template Template content to be parsed. |
|
777 | - * @param array $valid_shortcodes Valid shortcodes for the template being parsed. |
|
778 | - * @param array $extra_data Extra data that might be used when parsing the template. |
|
779 | - */ |
|
780 | - protected function _parse_question_list_for_primary_or_recipient_registration( |
|
781 | - $shortcode_parser, |
|
782 | - $questions, |
|
783 | - $answers, |
|
784 | - $template, |
|
785 | - $valid_shortcodes, |
|
786 | - $extra_data |
|
787 | - ) { |
|
788 | - $question_list = ''; |
|
789 | - /** @var EEH_Parse_Shortcodes $shortcode_helper */ |
|
790 | - $shortcode_helper = $shortcode_parser->get_shortcode_helper(); |
|
791 | - foreach ($answers as $answer) { |
|
792 | - if ($answer instanceof EE_Answer) { |
|
793 | - // first see if the question is in our $questions array. If not then try to get from answer object. |
|
794 | - $question = isset($questions[ $answer->ID() ]) ? $questions[ $answer->ID() ] : null; |
|
795 | - $question = ! $question instanceof EE_Question ? $answer->question() : $question; |
|
796 | - if ( |
|
797 | - ! $question instanceof EE_Question |
|
798 | - || ( |
|
799 | - $question instanceof EE_Question |
|
800 | - && $question->admin_only() |
|
801 | - ) |
|
802 | - ) { |
|
803 | - continue; |
|
804 | - } |
|
805 | - $question_list .= $shortcode_helper->parse_question_list_template( |
|
806 | - $template, |
|
807 | - $answer, |
|
808 | - $valid_shortcodes, |
|
809 | - $extra_data |
|
810 | - ); |
|
811 | - } |
|
812 | - } |
|
813 | - return $question_list; |
|
814 | - } |
|
13 | + /** |
|
14 | + * constructor. |
|
15 | + */ |
|
16 | + public function __construct() |
|
17 | + { |
|
18 | + $this->_caf_hooks(); |
|
19 | + } |
|
20 | + |
|
21 | + |
|
22 | + /** |
|
23 | + * Contains all the hooks filters for setting up caffeinated messages functionality. |
|
24 | + * |
|
25 | + * @since 4.3.2 |
|
26 | + * |
|
27 | + * @return void |
|
28 | + */ |
|
29 | + private function _caf_hooks() |
|
30 | + { |
|
31 | + add_filter('FHEE__EED_Messages___set_messages_paths___MSG_PATHS', array($this, 'messages_autoload_paths'), 5); |
|
32 | + add_filter( |
|
33 | + 'FHEE__EE_Email_messenger__get_validator_config', |
|
34 | + array($this, 'email_messenger_validator_config'), |
|
35 | + 5, |
|
36 | + 2 |
|
37 | + ); |
|
38 | + add_filter( |
|
39 | + 'FHEE__EE_Email_messenger__get_template_fields', |
|
40 | + array($this, 'email_messenger_template_fields'), |
|
41 | + 5, |
|
42 | + 2 |
|
43 | + ); |
|
44 | + add_filter( |
|
45 | + 'FHEE__EE_Html_messenger__get_template_fields', |
|
46 | + array($this, 'html_messenger_template_fields'), |
|
47 | + 5, |
|
48 | + 2 |
|
49 | + ); |
|
50 | + add_filter( |
|
51 | + 'FHEE__EE_Html_messenger__get_validator_config', |
|
52 | + array($this, 'html_messenger_validator_config'), |
|
53 | + 5, |
|
54 | + 2 |
|
55 | + ); |
|
56 | + add_filter('FHEE__EE_Pdf_messenger__get_template_fields', array($this, 'pdf_messenger_template_fields'), 5, 2); |
|
57 | + add_filter( |
|
58 | + 'FHEE__EE_Pdf_messenger__get_validator_config', |
|
59 | + array($this, 'pdf_messenger_validator_config'), |
|
60 | + 5, |
|
61 | + 2 |
|
62 | + ); |
|
63 | + add_filter( |
|
64 | + 'FHEE__EE_Messages_Template_Pack__get_specific_template__contents', |
|
65 | + array($this, 'new_default_templates'), |
|
66 | + 5, |
|
67 | + 7 |
|
68 | + ); |
|
69 | + add_filter( |
|
70 | + 'FHEE__EE_Messages_Base__get_valid_shortcodes', |
|
71 | + array($this, 'message_types_valid_shortcodes'), |
|
72 | + 5, |
|
73 | + 2 |
|
74 | + ); |
|
75 | + |
|
76 | + // shortcode parsers |
|
77 | + add_filter('FHEE__EE_Attendee_Shortcodes__shortcodes', array($this, 'additional_attendee_shortcodes'), 5, 2); |
|
78 | + add_filter('FHEE__EE_Attendee_Shortcodes__parser_after', array($this, 'additional_attendee_parser'), 5, 5); |
|
79 | + add_filter( |
|
80 | + 'FHEE__EE_Recipient_List_Shortcodes__shortcodes', |
|
81 | + array($this, 'additional_recipient_details_shortcodes'), |
|
82 | + 5, |
|
83 | + 2 |
|
84 | + ); |
|
85 | + add_filter( |
|
86 | + 'FHEE__EE_Recipient_List_Shortcodes__parser_after', |
|
87 | + array($this, 'additional_recipient_details_parser'), |
|
88 | + 5, |
|
89 | + 5 |
|
90 | + ); |
|
91 | + add_filter( |
|
92 | + 'FHEE__EE_Primary_Registration_List_Shortcodes__shortcodes', |
|
93 | + array($this, 'additional_primary_registration_details_shortcodes'), |
|
94 | + 5, |
|
95 | + 2 |
|
96 | + ); |
|
97 | + add_filter( |
|
98 | + 'FHEE__EE_Primary_Registration_List_Shortcodes__parser_after', |
|
99 | + array($this, 'additional_primary_registration_details_parser'), |
|
100 | + 5, |
|
101 | + 5 |
|
102 | + ); |
|
103 | + |
|
104 | + /** |
|
105 | + * @since 4.2.0 |
|
106 | + */ |
|
107 | + add_filter('FHEE__EE_Datetime_Shortcodes__shortcodes', array($this, 'additional_datetime_shortcodes'), 10, 2); |
|
108 | + add_filter('FHEE__EE_Datetime_Shortcodes__parser_after', array($this, 'additional_datetime_parser'), 10, 5); |
|
109 | + |
|
110 | + /** |
|
111 | + * @since 4.3.0 |
|
112 | + */ |
|
113 | + // eat our own dog food! |
|
114 | + add_action('EE_Brewing_Regular___messages_caf', array($this, 'register_caf_message_types')); |
|
115 | + add_action('EE_Brewing_Regular___messages_caf', array($this, 'register_caf_shortcodes')); |
|
116 | + do_action('EE_Brewing_Regular___messages_caf'); |
|
117 | + } |
|
118 | + |
|
119 | + |
|
120 | + /** |
|
121 | + * This just allows us to add additional paths to the autoloader (EED_Messages::autoload_messages()) for the |
|
122 | + * messages system. |
|
123 | + * |
|
124 | + * @param array $dir_ref original array of paths |
|
125 | + * |
|
126 | + * @return array appended paths |
|
127 | + */ |
|
128 | + public function messages_autoload_paths($dir_ref) |
|
129 | + { |
|
130 | + $dir_ref[] = EE_CAF_LIBRARIES . 'shortcodes/'; |
|
131 | + |
|
132 | + return $dir_ref; |
|
133 | + } |
|
134 | + |
|
135 | + |
|
136 | + public function email_messenger_validator_config($validator_config, EE_Email_messenger $messenger) |
|
137 | + { |
|
138 | + $validator_config['attendee_list'] = array( |
|
139 | + 'shortcodes' => array('attendee', 'event_list', 'ticket_list', 'question_list'), |
|
140 | + 'required' => array('[ATTENDEE_LIST]'), |
|
141 | + ); |
|
142 | + $validator_config['question_list'] = array( |
|
143 | + 'shortcodes' => array('question'), |
|
144 | + 'required' => array('[QUESTION_LIST]'), |
|
145 | + ); |
|
146 | + |
|
147 | + return $validator_config; |
|
148 | + } |
|
149 | + |
|
150 | + |
|
151 | + public function html_messenger_validator_config($validator_config, EE_Html_messenger $messenger) |
|
152 | + { |
|
153 | + $validator_config['attendee_list'] = array( |
|
154 | + 'shortcodes' => array('attendee', 'question_list'), |
|
155 | + 'required' => array('[ATTENDEE_LIST]'), |
|
156 | + ); |
|
157 | + $validator_config['question_list'] = array( |
|
158 | + 'shortcodes' => array('question'), |
|
159 | + 'required' => array('[QUESTION_LIST]'), |
|
160 | + ); |
|
161 | + |
|
162 | + return $validator_config; |
|
163 | + } |
|
164 | + |
|
165 | + |
|
166 | + public function pdf_messenger_validator_config($validator_config, EE_Pdf_messenger $messenger) |
|
167 | + { |
|
168 | + $validator_config['attendee_list'] = array( |
|
169 | + 'shortcodes' => array('attendee', 'event_list', 'ticket_list', 'question_list'), |
|
170 | + 'required' => array('[ATTENDEE_LIST]'), |
|
171 | + ); |
|
172 | + $validator_config['question_list'] = array( |
|
173 | + 'shortcodes' => array('question'), |
|
174 | + 'required' => array('[QUESTION_LIST]'), |
|
175 | + ); |
|
176 | + |
|
177 | + return $validator_config; |
|
178 | + } |
|
179 | + |
|
180 | + |
|
181 | + public function email_messenger_template_fields($template_fields, EE_Email_messenger $messenger) |
|
182 | + { |
|
183 | + $template_fields['extra']['content']['question_list'] = array( |
|
184 | + 'input' => 'textarea', |
|
185 | + 'label' => '[QUESTION_LIST]', |
|
186 | + 'type' => 'string', |
|
187 | + 'required' => true, |
|
188 | + 'validation' => true, |
|
189 | + 'format' => '%s', |
|
190 | + 'css_class' => 'large-text', |
|
191 | + 'rows' => '5', |
|
192 | + 'shortcodes_required' => array('[QUESTION_LIST]'), |
|
193 | + ); |
|
194 | + |
|
195 | + return $template_fields; |
|
196 | + } |
|
197 | + |
|
198 | + |
|
199 | + public function html_messenger_template_fields($template_fields, EE_Html_messenger $messenger) |
|
200 | + { |
|
201 | + $template_fields['extra']['content']['question_list'] = array( |
|
202 | + 'input' => 'textarea', |
|
203 | + 'label' => '[QUESTION_LIST]', |
|
204 | + 'type' => 'string', |
|
205 | + 'required' => true, |
|
206 | + 'validation' => true, |
|
207 | + 'format' => '%s', |
|
208 | + 'css_class' => 'large-text', |
|
209 | + 'rows' => '5', |
|
210 | + 'shortcodes_required' => array('[QUESTION_LIST]'), |
|
211 | + ); |
|
212 | + |
|
213 | + return $template_fields; |
|
214 | + } |
|
215 | + |
|
216 | + |
|
217 | + public function pdf_messenger_template_fields($template_fields, EE_Pdf_messenger $messenger) |
|
218 | + { |
|
219 | + $template_fields['extra']['content']['question_list'] = array( |
|
220 | + 'input' => 'textarea', |
|
221 | + 'label' => '[QUESTION_LIST]', |
|
222 | + 'type' => 'string', |
|
223 | + 'required' => true, |
|
224 | + 'validation' => true, |
|
225 | + 'format' => '%s', |
|
226 | + 'css_class' => 'large-text', |
|
227 | + 'rows' => '5', |
|
228 | + 'shortcodes_required' => array('[QUESTION_LIST]'), |
|
229 | + ); |
|
230 | + |
|
231 | + return $template_fields; |
|
232 | + } |
|
233 | + |
|
234 | + |
|
235 | + public function new_default_templates( |
|
236 | + $contents, |
|
237 | + $actual_path, |
|
238 | + EE_messenger $messenger, |
|
239 | + EE_message_type $message_type, |
|
240 | + $field, |
|
241 | + $context, |
|
242 | + EE_Messages_Template_Pack $template_pack |
|
243 | + ) { |
|
244 | + |
|
245 | + // we're only modifying templates for the default template pack |
|
246 | + if (! $template_pack instanceof EE_Messages_Template_Pack_Default) { |
|
247 | + return $contents; |
|
248 | + } |
|
249 | + |
|
250 | + // the template file name we're replacing contents for. |
|
251 | + $template_file_prefix = $field . '_' . $context; |
|
252 | + $msg_prefix = $messenger->name . '_' . $message_type->name . '_'; |
|
253 | + |
|
254 | + $base_path = EE_CAF_LIBRARIES . 'messages/defaults/default/'; |
|
255 | + |
|
256 | + if ($messenger->name == 'email' && $message_type->name == 'registration') { |
|
257 | + switch ($template_file_prefix) { |
|
258 | + case 'question_list_admin': |
|
259 | + case 'question_list_attendee': |
|
260 | + case 'question_list_primary_attendee': |
|
261 | + $path = $base_path . $msg_prefix . 'question_list.template.php'; |
|
262 | + $contents = EEH_Template::display_template($path, array(), true); |
|
263 | + break; |
|
264 | + |
|
265 | + case 'attendee_list_primary_attendee': |
|
266 | + $path = $base_path . $msg_prefix . 'attendee_list.template.php'; |
|
267 | + $contents = EEH_Template::display_template($path, array(), true); |
|
268 | + break; |
|
269 | + |
|
270 | + case 'attendee_list_admin': |
|
271 | + $path = $base_path . $msg_prefix . 'attendee_list_admin.template.php'; |
|
272 | + $contents = EEH_Template::display_template( |
|
273 | + $path, |
|
274 | + array(), |
|
275 | + true |
|
276 | + ); |
|
277 | + break; |
|
278 | + |
|
279 | + case 'attendee_list_attendee': |
|
280 | + $contents = ''; |
|
281 | + break; |
|
282 | + |
|
283 | + case 'event_list_attendee': |
|
284 | + $path = $base_path . $msg_prefix . 'event_list_attendee.template.php'; |
|
285 | + $contents = EEH_Template::display_template($path, array(), true); |
|
286 | + break; |
|
287 | + } |
|
288 | + } elseif ($messenger->name == 'email' && $message_type->name == 'newsletter') { |
|
289 | + switch ($template_file_prefix) { |
|
290 | + case 'content_attendee': |
|
291 | + $path = $base_path . $msg_prefix . 'content.template.php'; |
|
292 | + $contents = EEH_Template::display_template($path, array(), true); |
|
293 | + break; |
|
294 | + |
|
295 | + case 'newsletter_content_attendee': |
|
296 | + $path = $base_path . $msg_prefix . 'newsletter_content.template.php'; |
|
297 | + $contents = EEH_Template::display_template($path, array(), true); |
|
298 | + break; |
|
299 | + |
|
300 | + case 'newsletter_subject_attendee': |
|
301 | + $path = $base_path . $msg_prefix . 'subject.template.php'; |
|
302 | + $contents = EEH_Template::display_template($path, array(), true); |
|
303 | + break; |
|
304 | + } |
|
305 | + } elseif ($messenger->name == 'html' && $message_type->name == 'receipt') { |
|
306 | + switch ($template_file_prefix) { |
|
307 | + case 'attendee_list_purchaser': |
|
308 | + $path = $base_path . $msg_prefix . 'attendee_list.template.php'; |
|
309 | + $contents = EEH_Template::display_template($path, array(), true); |
|
310 | + break; |
|
311 | + } |
|
312 | + } |
|
313 | + |
|
314 | + return $contents; |
|
315 | + } |
|
316 | + |
|
317 | + |
|
318 | + public function message_types_valid_shortcodes($valid_shortcodes, EE_Messages_Base $msg) |
|
319 | + { |
|
320 | + // make sure question_list and question are ONLY added for the core message types. Any other message types will have to explicitly set question_list as a valid shortcode. |
|
321 | + $include_with = array( |
|
322 | + 'registration', |
|
323 | + 'cancelled_registration', |
|
324 | + 'declined_registration', |
|
325 | + 'not_approved_registration', |
|
326 | + 'payment_declined', |
|
327 | + 'payment_failed', |
|
328 | + 'payment_cancelled', |
|
329 | + 'payment', |
|
330 | + 'payment_reminder', |
|
331 | + 'pending_approval', |
|
332 | + 'registration_summary', |
|
333 | + 'invoice', |
|
334 | + 'receipt', |
|
335 | + ); |
|
336 | + if ($msg instanceof EE_message_type && in_array($msg->name, $include_with)) { |
|
337 | + $contexts = array_keys($msg->get_contexts()); |
|
338 | + foreach ($contexts as $context) { |
|
339 | + $valid_shortcodes[ $context ][] = 'question_list'; |
|
340 | + $valid_shortcodes[ $context ][] = 'question'; |
|
341 | + } |
|
342 | + } |
|
343 | + |
|
344 | + return $valid_shortcodes; |
|
345 | + } |
|
346 | + |
|
347 | + |
|
348 | + public function additional_attendee_shortcodes($shortcodes, $shortcode_parser) |
|
349 | + { |
|
350 | + $shortcodes['[ANSWER_*]'] = esc_html__( |
|
351 | + 'This is a special dynamic shortcode. Right after the "*", add the exact text of a existing question, and if there is an answer for that question for this registrant, that will take the place of this shortcode.', |
|
352 | + 'event_espresso' |
|
353 | + ); |
|
354 | + |
|
355 | + return $shortcodes; |
|
356 | + } |
|
357 | + |
|
358 | + |
|
359 | + public function additional_attendee_parser($parsed, $shortcode, $data, $extra_data, $shortcode_parser) |
|
360 | + { |
|
361 | + |
|
362 | + if ( |
|
363 | + strpos($shortcode, '[ANSWER_*') === false |
|
364 | + || ! isset($extra_data['data']->questions) |
|
365 | + || ! isset($extra_data['data']->registrations) |
|
366 | + ) { |
|
367 | + return $parsed; |
|
368 | + } |
|
369 | + |
|
370 | + // let's get the question from the code. |
|
371 | + $shortcode = str_replace('[ANSWER_*', '', $shortcode); |
|
372 | + $shortcode = trim(str_replace(']', '', $shortcode)); |
|
373 | + |
|
374 | + $registration = $data instanceof EE_Registration ? $data : null; |
|
375 | + $registration = ! $registration instanceof EE_Registration && is_array( |
|
376 | + $extra_data |
|
377 | + ) && isset($extra_data['data']) && $extra_data['data'] instanceof EE_Registration ? $extra_data['data'] : $registration; |
|
378 | + |
|
379 | + $aee = $data instanceof EE_Messages_Addressee ? $data : null; |
|
380 | + $aee = ! $aee instanceof EE_Messages_Addressee && is_array( |
|
381 | + $extra_data |
|
382 | + ) && isset($extra_data['data']) ? $extra_data['data'] : $aee; |
|
383 | + |
|
384 | + if (! $registration instanceof EE_Registration || ! $aee instanceof EE_Messages_Addressee) { |
|
385 | + return $parsed; |
|
386 | + } |
|
387 | + |
|
388 | + // now let's figure out which question has this text. |
|
389 | + foreach ($aee->questions as $ansid => $question) { |
|
390 | + if ( |
|
391 | + $question instanceof EE_Question |
|
392 | + && trim($question->display_text()) == trim($shortcode) |
|
393 | + && isset($aee->registrations[ $registration->ID() ]['ans_objs'][ $ansid ]) |
|
394 | + ) { |
|
395 | + return $aee->registrations[ $registration->ID() ]['ans_objs'][ $ansid ]->get_pretty( |
|
396 | + 'ANS_value', |
|
397 | + 'no_wpautop' |
|
398 | + ); |
|
399 | + } |
|
400 | + } |
|
401 | + |
|
402 | + // nothing! |
|
403 | + return $parsed; |
|
404 | + } |
|
405 | + |
|
406 | + |
|
407 | + /** |
|
408 | + * Callback for additional shortcodes filter for adding additional datetime shortcodes. |
|
409 | + * |
|
410 | + * @since 4.2 |
|
411 | + * |
|
412 | + * @param array $shortcodes array of shortcodes and |
|
413 | + * descriptions |
|
414 | + * @param EE_Datetime_Shortcodes $shortcode_parser EE_Shortcodes object |
|
415 | + * |
|
416 | + * @return array array of shortcodes and |
|
417 | + * descriptions |
|
418 | + */ |
|
419 | + public function additional_datetime_shortcodes($shortcodes, $shortcode_parser) |
|
420 | + { |
|
421 | + $shortcodes['[DTT_NAME]'] = esc_html__( |
|
422 | + 'This will be parsed to the Title given for a Datetime', |
|
423 | + 'event_espresso' |
|
424 | + ); |
|
425 | + $shortcodes['[DTT_DESCRIPTION]'] = esc_html__( |
|
426 | + 'This will be parsed to the description for a Datetime', |
|
427 | + 'event_espresso' |
|
428 | + ); |
|
429 | + $shortcodes['[DTT_NAME_OR_DATES]'] = esc_html__( |
|
430 | + 'When parsed, if the Datetime has a name, it is used, otherwise a formatted string including the start date and end date will be used.', |
|
431 | + 'event_espresso' |
|
432 | + ); |
|
433 | + |
|
434 | + return $shortcodes; |
|
435 | + } |
|
436 | + |
|
437 | + |
|
438 | + /** |
|
439 | + * Callback for additional shortcodes parser filter used for adding parser for new |
|
440 | + * Datetime shortcodes |
|
441 | + * |
|
442 | + * @since 4.2 |
|
443 | + * |
|
444 | + * @param string $parsed The finished parsed string for the given shortcode. |
|
445 | + * @param string $shortcode The shortcode being parsed. |
|
446 | + * @param object $data The incoming data object for the Shortcode Parser. |
|
447 | + * @param object $extra_data The incoming extra date object for the Shortcode |
|
448 | + * Parser. |
|
449 | + * @param EE_Datetime_Shortcodes $shortcode_parser |
|
450 | + * |
|
451 | + * @return string The new parsed string. |
|
452 | + */ |
|
453 | + public function additional_datetime_parser($parsed, $shortcode, $data, $extra_data, $shortcode_parser) |
|
454 | + { |
|
455 | + |
|
456 | + if (! $data instanceof EE_Datetime) { |
|
457 | + return ''; // get out because we can only parse with the datetime object. |
|
458 | + } |
|
459 | + |
|
460 | + switch ($shortcode) { |
|
461 | + case '[DTT_NAME]': |
|
462 | + return $data->name(); |
|
463 | + break; |
|
464 | + case '[DTT_DESCRIPTION]': |
|
465 | + return $data->description(); |
|
466 | + break; |
|
467 | + case '[DTT_NAME_OR_DATES]': |
|
468 | + return $data->get_dtt_display_name(true); |
|
469 | + break; |
|
470 | + default: |
|
471 | + return $parsed; |
|
472 | + break; |
|
473 | + } |
|
474 | + } |
|
475 | + |
|
476 | + |
|
477 | + public function additional_recipient_details_shortcodes($shortcodes, $shortcode_parser) |
|
478 | + { |
|
479 | + $shortcodes['[RECIPIENT_QUESTION_LIST]'] = esc_html__( |
|
480 | + 'This is used to indicate where you want the list of questions and answers to show for the person receiving the message.', |
|
481 | + 'event_espresso' |
|
482 | + ); |
|
483 | + |
|
484 | + return $shortcodes; |
|
485 | + } |
|
486 | + |
|
487 | + |
|
488 | + /** |
|
489 | + * Callback for FHEE__EE_Recipient_List_Shortcodes__parser_after filter (dynamic filter). |
|
490 | + * |
|
491 | + * @param string $parsed The original parsed content for the shortcode |
|
492 | + * @param string $shortcode The shortcode being parsed |
|
493 | + * @param array $data The shortcode parser data array |
|
494 | + * @param array $extra_data The shortcode parser extra data array |
|
495 | + * @param \EE_Shortcodes $shortcode_parser Shortcode parser. |
|
496 | + * |
|
497 | + * @return string |
|
498 | + */ |
|
499 | + public function additional_recipient_details_parser($parsed, $shortcode, $data, $extra_data, $shortcode_parser) |
|
500 | + { |
|
501 | + |
|
502 | + if (array($data) && ! isset($data['data'])) { |
|
503 | + return $parsed; |
|
504 | + } |
|
505 | + |
|
506 | + $recipient = $data['data'] instanceof EE_Messages_Addressee ? $data['data'] : null; |
|
507 | + $recipient = ! $recipient instanceof EE_Messages_Addressee && array($extra_data) && isset($extra_data['data']) && $extra_data['data'] instanceof EE_Messages_Addressee ? $extra_data['data'] : $recipient; |
|
508 | + |
|
509 | + if (! $recipient instanceof EE_Messages_Addressee) { |
|
510 | + return $parsed; |
|
511 | + } |
|
512 | + |
|
513 | + switch ($shortcode) { |
|
514 | + case '[RECIPIENT_QUESTION_LIST]': |
|
515 | + $att = $recipient->att_obj; |
|
516 | + $registrations_on_attendee = $att instanceof EE_Attendee |
|
517 | + ? $recipient->attendees[ $att->ID() ]['reg_objs'] |
|
518 | + : array(); |
|
519 | + $registrations_on_attendee = empty($registrations_on_attendee) && $recipient->reg_obj instanceof EE_Registration ? array($recipient->reg_obj) : $registrations_on_attendee; |
|
520 | + $answers = array(); |
|
521 | + |
|
522 | + $template = is_array($data['template']) && isset($data['template']['question_list']) |
|
523 | + ? $data['template']['question_list'] |
|
524 | + : $extra_data['template']['question_list']; |
|
525 | + $valid_shortcodes = array('question'); |
|
526 | + |
|
527 | + // if the context is main_content then get all answers for all registrations on this attendee |
|
528 | + if ($data['data'] instanceof EE_Messages_Addressee) { |
|
529 | + foreach ($registrations_on_attendee as $reg) { |
|
530 | + if ($reg instanceof EE_Registration) { |
|
531 | + $anss = ! empty($recipient->registrations[ $reg->ID() ]['ans_objs']) |
|
532 | + ? $recipient->registrations[ $reg->ID() ]['ans_objs'] |
|
533 | + : array(); |
|
534 | + foreach ($anss as $ans) { |
|
535 | + if ($ans instanceof EE_Answer) { |
|
536 | + $answers[ $ans->ID() ] = $ans; |
|
537 | + } |
|
538 | + } |
|
539 | + } |
|
540 | + } |
|
541 | + } |
|
542 | + |
|
543 | + // if the context is the event list parser, then let's return just the answers for all registrations attached to the recipient for that event. |
|
544 | + if ($data['data'] instanceof EE_Event) { |
|
545 | + $event = $data['data']; |
|
546 | + foreach ($registrations_on_attendee as $reg) { |
|
547 | + if ($reg instanceof EE_Registration && $reg->event_ID() == $event->ID()) { |
|
548 | + $anss = ! empty($recipient->registrations[ $reg->ID() ]['ans_objs']) |
|
549 | + ? $recipient->registrations[ $reg->ID() ]['ans_objs'] |
|
550 | + : array(); |
|
551 | + foreach ($anss as $ans) { |
|
552 | + if ($ans instanceof EE_Answer) { |
|
553 | + $answers[ $ans->ID() ] = $ans; |
|
554 | + } |
|
555 | + } |
|
556 | + } |
|
557 | + } |
|
558 | + } |
|
559 | + |
|
560 | + $questions = $questions = isset($recipient->questions) ? $recipient->questions : array(); |
|
561 | + |
|
562 | + // if $extra_data does not have a 'data' key then let's make sure we add it and set the EE_Messages_Addressee |
|
563 | + // object on it. |
|
564 | + if (! isset($extra_data['data'])) { |
|
565 | + $extra_data['data'] = $recipient; |
|
566 | + } |
|
567 | + |
|
568 | + return $this->_parse_question_list_for_primary_or_recipient_registration( |
|
569 | + $shortcode_parser, |
|
570 | + $questions, |
|
571 | + $answers, |
|
572 | + $template, |
|
573 | + $valid_shortcodes, |
|
574 | + $extra_data |
|
575 | + ); |
|
576 | + break; |
|
577 | + |
|
578 | + default: |
|
579 | + return $parsed; |
|
580 | + break; |
|
581 | + } |
|
582 | + } |
|
583 | + |
|
584 | + |
|
585 | + public function additional_primary_registration_details_shortcodes($shortcodes, $shortcode_parser) |
|
586 | + { |
|
587 | + $shortcodes['[PRIMARY_REGISTRANT_QUESTION_LIST]'] = esc_html__( |
|
588 | + 'This is used to indicate the questions and answers for the primary_registrant. It should be placed in the "[attendee_list]" field', |
|
589 | + 'event_espresso' |
|
590 | + ); |
|
591 | + |
|
592 | + return $shortcodes; |
|
593 | + } |
|
594 | + |
|
595 | + |
|
596 | + /** |
|
597 | + * Callback for FHEE__EE_Primary_Registration_List_Shortcodes__parser_after filter (dynamic filter). |
|
598 | + * |
|
599 | + * @param string $parsed The original parsed content for the shortcode |
|
600 | + * @param string $shortcode The shortcode being parsed |
|
601 | + * @param array $data The shortcode parser data array |
|
602 | + * @param array $extra_data The shortcode parser extra data array |
|
603 | + * @param \EE_Shortcodes $shortcode_parser Shortcode parser. |
|
604 | + * |
|
605 | + * @return string |
|
606 | + */ |
|
607 | + public function additional_primary_registration_details_parser( |
|
608 | + $parsed, |
|
609 | + $shortcode, |
|
610 | + $data, |
|
611 | + $extra_data, |
|
612 | + $shortcode_parser |
|
613 | + ) { |
|
614 | + if (array($data) && ! isset($data['data'])) { |
|
615 | + return $parsed; |
|
616 | + } |
|
617 | + |
|
618 | + $recipient = $data['data'] instanceof EE_Messages_Addressee ? $data['data'] : null; |
|
619 | + $recipient = ! $recipient instanceof EE_Messages_Addressee && array($extra_data) && isset($extra_data['data']) && $extra_data['data'] instanceof EE_Messages_Addressee ? $extra_data['data'] : $recipient; |
|
620 | + |
|
621 | + if (! $recipient instanceof EE_Messages_Addressee) { |
|
622 | + return $parsed; |
|
623 | + } |
|
624 | + |
|
625 | + switch ($shortcode) { |
|
626 | + case '[PRIMARY_REGISTRANT_QUESTION_LIST]': |
|
627 | + if (! $recipient->primary_att_obj instanceof EE_Attendee || ! $recipient->primary_reg_obj instanceof EE_Registration) { |
|
628 | + return ''; |
|
629 | + } |
|
630 | + $registration = $recipient->primary_reg_obj; |
|
631 | + $answers = isset($recipient->registrations[ $registration->ID() ]['ans_objs']) |
|
632 | + ? $recipient->registrations[ $registration->ID() ]['ans_objs'] |
|
633 | + : array(); |
|
634 | + if (empty($answers)) { |
|
635 | + return ''; |
|
636 | + } |
|
637 | + $template = is_array($data['template']) && isset($data['template']['question_list']) |
|
638 | + ? $data['template']['question_list'] |
|
639 | + : $extra_data['template']['question_list']; |
|
640 | + $valid_shortcodes = array('question'); |
|
641 | + $answers = $recipient->registrations[ $registration->ID() ]['ans_objs']; |
|
642 | + $questions = isset($recipient->questions) ? $recipient->questions : array(); |
|
643 | + // if $extra_data does not have a 'data' key then let's make sure we add it and set the EE_Messages_Addressee |
|
644 | + // object on it. |
|
645 | + if (! isset($extra_data['data'])) { |
|
646 | + $extra_data['data'] = $recipient; |
|
647 | + } |
|
648 | + return $this->_parse_question_list_for_primary_or_recipient_registration( |
|
649 | + $shortcode_parser, |
|
650 | + $questions, |
|
651 | + $answers, |
|
652 | + $template, |
|
653 | + $valid_shortcodes, |
|
654 | + $extra_data |
|
655 | + ); |
|
656 | + break; |
|
657 | + |
|
658 | + default: |
|
659 | + return $parsed; |
|
660 | + break; |
|
661 | + } |
|
662 | + } |
|
663 | + |
|
664 | + |
|
665 | + /** |
|
666 | + * Takes care of registering the message types that are only available in caffeinated EE. |
|
667 | + * |
|
668 | + * @since 4.3.2 |
|
669 | + * |
|
670 | + * @return void |
|
671 | + */ |
|
672 | + public function register_caf_message_types() |
|
673 | + { |
|
674 | + // register newsletter message type |
|
675 | + $setup_args = array( |
|
676 | + 'mtfilename' => 'EE_Newsletter_message_type.class.php', |
|
677 | + 'autoloadpaths' => array( |
|
678 | + EE_CAF_LIBRARIES . 'messages/message_type/newsletter/', |
|
679 | + ), |
|
680 | + 'messengers_to_activate_with' => array('email'), |
|
681 | + 'messengers_to_validate_with' => array('email'), |
|
682 | + 'messengers_supporting_default_template_pack_with' => array('email'), |
|
683 | + ); |
|
684 | + EE_Register_Message_Type::register('newsletter', $setup_args); |
|
685 | + |
|
686 | + // register payment reminder message type |
|
687 | + $setup_args = array( |
|
688 | + 'mtfilename' => 'EE_Payment_Reminder_message_type.class.php', |
|
689 | + 'autoloadpaths' => array(EE_CAF_LIBRARIES . 'messages/message_type/payment_reminder/'), |
|
690 | + 'messengers_to_activate_with' => array('email'), |
|
691 | + 'messengers_to_validate_with' => array('email'), |
|
692 | + 'messengers_supporting_default_template_pack_with' => array('email'), |
|
693 | + ); |
|
694 | + EE_Register_Message_Type::register('payment_reminder', $setup_args); |
|
695 | + |
|
696 | + // register payment declined message type |
|
697 | + $setup_args = array( |
|
698 | + 'mtfilename' => 'EE_Payment_Declined_message_type.class.php', |
|
699 | + 'autoloadpaths' => array(EE_CAF_LIBRARIES . 'messages/message_type/payment_declined/'), |
|
700 | + 'messengers_to_activate_with' => array('email'), |
|
701 | + 'messengers_to_validate_with' => array('email'), |
|
702 | + 'messengers_supporting_default_template_pack_with' => array('email'), |
|
703 | + ); |
|
704 | + EE_Register_Message_Type::register('payment_declined', $setup_args); |
|
705 | + |
|
706 | + // register registration declined message type |
|
707 | + $setup_args = array( |
|
708 | + 'mtfilename' => 'EE_Declined_Registration_message_type.class.php', |
|
709 | + 'autoloadpaths' => array(EE_CAF_LIBRARIES . 'messages/message_type/declined_registration/'), |
|
710 | + 'messengers_to_activate_with' => array('email'), |
|
711 | + 'messengers_to_validate_with' => array('email'), |
|
712 | + 'messengers_supporting_default_template_pack_with' => array('email'), |
|
713 | + ); |
|
714 | + EE_Register_Message_Type::register('declined_registration', $setup_args); |
|
715 | + |
|
716 | + // register registration cancelled message type |
|
717 | + $setup_args = array( |
|
718 | + 'mtfilename' => 'EE_Cancelled_Registration_message_type.class.php', |
|
719 | + 'autoloadpaths' => array(EE_CAF_LIBRARIES . 'messages/message_type/cancelled_registration/'), |
|
720 | + 'messengers_to_activate_with' => array('email'), |
|
721 | + 'messengers_to_validate_with' => array('email'), |
|
722 | + 'messengers_supporting_default_template_pack_with' => array('email'), |
|
723 | + ); |
|
724 | + EE_Register_Message_Type::register('cancelled_registration', $setup_args); |
|
725 | + |
|
726 | + |
|
727 | + // register payment failed message type |
|
728 | + $setup_args = array( |
|
729 | + 'mtfilename' => 'EE_Payment_Failed_message_type.class.php', |
|
730 | + 'autoloadpaths' => array(EE_CAF_LIBRARIES . 'messages/message_type/payment_failed/'), |
|
731 | + 'messengers_to_activate_with' => array('email'), |
|
732 | + 'messengers_to_validate_with' => array('email'), |
|
733 | + 'messengers_supporting_default_template_pack_with' => array('email'), |
|
734 | + ); |
|
735 | + EE_Register_Message_Type::register('payment_failed', $setup_args); |
|
736 | + |
|
737 | + // register payment declined message type |
|
738 | + $setup_args = array( |
|
739 | + 'mtfilename' => 'EE_Payment_Cancelled_message_type.class.php', |
|
740 | + 'autoloadpaths' => array(EE_CAF_LIBRARIES . 'messages/message_type/payment_cancelled/'), |
|
741 | + 'messengers_to_activate_with' => array('email'), |
|
742 | + 'messengers_to_validate_with' => array('email'), |
|
743 | + 'messengers_supporting_default_template_pack_with' => array('email'), |
|
744 | + ); |
|
745 | + EE_Register_Message_Type::register('payment_cancelled', $setup_args); |
|
746 | + } |
|
747 | + |
|
748 | + |
|
749 | + /** |
|
750 | + * Takes care of registering the shortcode libraries implemented with caffeinated EE and set up related items. |
|
751 | + * |
|
752 | + * @since 4.3.2 |
|
753 | + * |
|
754 | + * @return void |
|
755 | + */ |
|
756 | + public function register_caf_shortcodes() |
|
757 | + { |
|
758 | + $setup_args = array( |
|
759 | + 'autoloadpaths' => array( |
|
760 | + EE_CAF_LIBRARIES . 'shortcodes/', |
|
761 | + ), |
|
762 | + 'msgr_validator_callback' => array('EE_Newsletter_Shortcodes', 'messenger_validator_config'), |
|
763 | + 'msgr_template_fields_callback' => array('EE_Newsletter_Shortcodes', 'messenger_template_fields'), |
|
764 | + 'list_type_shortcodes' => array('[NEWSLETTER_CONTENT]'), |
|
765 | + ); |
|
766 | + EE_Register_Messages_Shortcode_Library::register('newsletter', $setup_args); |
|
767 | + } |
|
768 | + |
|
769 | + |
|
770 | + /** |
|
771 | + * Parses a question list shortcode using given data and template |
|
772 | + * |
|
773 | + * @param \EE_Shortcodes $shortcode_parser |
|
774 | + * @param EE_Question[] $questions An array of questions indexed by answer id. |
|
775 | + * @param EE_Answer[] $answers An array of answer objects |
|
776 | + * @param string $template Template content to be parsed. |
|
777 | + * @param array $valid_shortcodes Valid shortcodes for the template being parsed. |
|
778 | + * @param array $extra_data Extra data that might be used when parsing the template. |
|
779 | + */ |
|
780 | + protected function _parse_question_list_for_primary_or_recipient_registration( |
|
781 | + $shortcode_parser, |
|
782 | + $questions, |
|
783 | + $answers, |
|
784 | + $template, |
|
785 | + $valid_shortcodes, |
|
786 | + $extra_data |
|
787 | + ) { |
|
788 | + $question_list = ''; |
|
789 | + /** @var EEH_Parse_Shortcodes $shortcode_helper */ |
|
790 | + $shortcode_helper = $shortcode_parser->get_shortcode_helper(); |
|
791 | + foreach ($answers as $answer) { |
|
792 | + if ($answer instanceof EE_Answer) { |
|
793 | + // first see if the question is in our $questions array. If not then try to get from answer object. |
|
794 | + $question = isset($questions[ $answer->ID() ]) ? $questions[ $answer->ID() ] : null; |
|
795 | + $question = ! $question instanceof EE_Question ? $answer->question() : $question; |
|
796 | + if ( |
|
797 | + ! $question instanceof EE_Question |
|
798 | + || ( |
|
799 | + $question instanceof EE_Question |
|
800 | + && $question->admin_only() |
|
801 | + ) |
|
802 | + ) { |
|
803 | + continue; |
|
804 | + } |
|
805 | + $question_list .= $shortcode_helper->parse_question_list_template( |
|
806 | + $template, |
|
807 | + $answer, |
|
808 | + $valid_shortcodes, |
|
809 | + $extra_data |
|
810 | + ); |
|
811 | + } |
|
812 | + } |
|
813 | + return $question_list; |
|
814 | + } |
|
815 | 815 | } |