@@ -13,431 +13,431 @@ |
||
13 | 13 | */ |
14 | 14 | class Invoice |
15 | 15 | { |
16 | - /** |
|
17 | - * |
|
18 | - * @var EE_Registration |
|
19 | - */ |
|
20 | - private $registration; |
|
21 | - |
|
22 | - /** |
|
23 | - * |
|
24 | - * @var EE_Transaction |
|
25 | - */ |
|
26 | - private $transaction; |
|
27 | - |
|
28 | - /** |
|
29 | - * |
|
30 | - * @var EE_Payment_Method |
|
31 | - */ |
|
32 | - private $invoice_payment_method; |
|
33 | - |
|
34 | - |
|
35 | - /** |
|
36 | - * Invoice constructor. |
|
37 | - * |
|
38 | - * @param int $url_link |
|
39 | - * @throws EE_Error |
|
40 | - * @throws ReflectionException |
|
41 | - * @deprecated 4.9.13 |
|
42 | - */ |
|
43 | - public function __construct($url_link = 0) |
|
44 | - { |
|
45 | - EE_Error::doing_it_wrong( |
|
46 | - __CLASS__, |
|
47 | - esc_html__( |
|
48 | - 'This class has been deprecated and replaced by the new Messages library.', |
|
49 | - 'event_espresso' |
|
50 | - ), |
|
51 | - '4.9.12', |
|
52 | - '5.0.0' |
|
53 | - ); |
|
54 | - /** @var EEM_Registration $reg_model */ |
|
55 | - $reg_model = EE_Registry::instance()->load_model('Registration'); |
|
56 | - if ($this->registration = $reg_model->get_registration_for_reg_url_link($url_link)) { |
|
57 | - $this->transaction = $this->registration->transaction(); |
|
58 | - EE_Config::instance()->gateway->payment_settings; |
|
59 | - $this->invoice_payment_method = EEM_Payment_Method::instance()->get_one_of_type('Invoice'); |
|
60 | - } else { |
|
61 | - EE_Error::add_error( |
|
62 | - esc_html__( |
|
63 | - 'Your request appears to be missing some required data, and no information for your transaction could be retrieved.', |
|
64 | - 'event_espresso' |
|
65 | - ), |
|
66 | - __FILE__, |
|
67 | - __FUNCTION__, |
|
68 | - __LINE__ |
|
69 | - ); |
|
70 | - } |
|
71 | - } |
|
72 | - |
|
73 | - |
|
74 | - /** |
|
75 | - * @param false $download |
|
76 | - * @throws EE_Error |
|
77 | - * @throws ReflectionException |
|
78 | - */ |
|
79 | - public function send_invoice($download = false) |
|
80 | - { |
|
81 | - $template_args = []; |
|
82 | - $EE = EE_Registry::instance(); |
|
83 | - /** @var RequestInterface $request */ |
|
84 | - $request = LoaderFactory::getLoader()->getShared(RequestInterface::class); |
|
85 | - $theme = $request->getRequestParam('theme', 0, 'int'); |
|
86 | - // allow the request to override the default theme defined in the invoice settings |
|
87 | - $theme_requested = $theme > 0 && $theme < 8 |
|
88 | - ? $theme |
|
89 | - : null; |
|
90 | - $themes = [ |
|
91 | - 1 => "simple.css", |
|
92 | - 2 => "bauhaus.css", |
|
93 | - 3 => "ejs.css", |
|
94 | - 4 => "horizon.css", |
|
95 | - 5 => "lola.css", |
|
96 | - 6 => "tranquility.css", |
|
97 | - 7 => "union.css", |
|
98 | - ]; |
|
99 | - // Get the CSS file |
|
100 | - if (isset($themes[ $theme_requested ])) { |
|
101 | - $template_args['invoice_css'] = $themes[ $theme_requested ]; |
|
102 | - } else { |
|
103 | - $template_args['invoice_css'] = $this->invoice_payment_method->get_extra_meta( |
|
104 | - 'legacy_invoice_css', |
|
105 | - true, |
|
106 | - 'simple.css' |
|
107 | - ); |
|
108 | - } |
|
109 | - |
|
110 | - if (is_dir(EVENT_ESPRESSO_GATEWAY_DIR . '/invoice')) { |
|
111 | - $template_args['base_url'] = EVENT_ESPRESSO_GATEWAY_URL . 'Invoice/lib/templates/'; |
|
112 | - } else { |
|
113 | - $template_args['base_url'] = EE_GATEWAYS . '/Invoice/lib/templates/'; |
|
114 | - } |
|
115 | - $primary_attendee = $this->transaction->primary_registration()->attendee(); |
|
116 | - |
|
117 | - $template_args['organization'] = $EE->CFG->organization->get_pretty('name'); |
|
118 | - $template_args['street'] = empty($EE->CFG->organization->address_2) |
|
119 | - ? $EE->CFG->organization->get_pretty('address_1') |
|
120 | - : $EE->CFG->organization->get_pretty('address_1') |
|
121 | - . '<br>' |
|
122 | - . $EE->CFG->organization->get_pretty('address_2'); |
|
123 | - $template_args['city'] = $EE->CFG->organization->get_pretty('city'); |
|
124 | - $template_args['state'] = EE_Registry::instance()->load_model('State')->get_one_by_ID( |
|
125 | - $EE->CFG->organization->STA_ID |
|
126 | - ); |
|
127 | - $template_args['country'] = EE_Registry::instance()->load_model('Country')->get_one_by_ID( |
|
128 | - $EE->CFG->organization->CNT_ISO |
|
129 | - ); |
|
130 | - $template_args['zip'] = $EE->CFG->organization->get_pretty('zip'); |
|
131 | - $template_args['email'] = $EE->CFG->organization->get_pretty('email'); |
|
132 | - |
|
133 | - $template_args['registration_code'] = $this->registration->reg_code(); |
|
134 | - $template_args['registration_date'] = $this->registration->date(); |
|
135 | - $template_args['name'] = $primary_attendee->full_name(); |
|
136 | - $template_args['attendee_address'] = $primary_attendee->address(); |
|
137 | - $template_args['attendee_address2'] = $primary_attendee->address2(); |
|
138 | - $template_args['attendee_city'] = $primary_attendee->city(); |
|
139 | - $attendee_state = $primary_attendee->state_obj(); |
|
140 | - if ($attendee_state) { |
|
141 | - $attendee_state_name = $attendee_state->name(); |
|
142 | - } else { |
|
143 | - $attendee_state_name = ''; |
|
144 | - } |
|
145 | - $template_args['attendee_state'] = $attendee_state_name; |
|
146 | - $template_args['attendee_zip'] = $primary_attendee->zip(); |
|
147 | - |
|
148 | - $template_args['ship_name'] = $template_args['name']; |
|
149 | - $template_args['ship_address'] = $template_args['attendee_address']; |
|
150 | - $template_args['ship_city'] = $template_args['attendee_city']; |
|
151 | - $template_args['ship_state'] = $template_args['attendee_state']; |
|
152 | - $template_args['ship_zip'] = $template_args['attendee_zip']; |
|
153 | - |
|
154 | - $template_args['total_cost'] = number_format($this->transaction->total(), 2, '.', ''); |
|
155 | - $template_args['transaction'] = $this->transaction; |
|
156 | - $template_args['amount_pd'] = $this->transaction->paid(); |
|
157 | - $template_args['amount_owed'] = $this->transaction->total() - $this->transaction->paid(); |
|
158 | - $template_args['payments'] = $this->transaction->approved_payments(); |
|
159 | - $template_args['net_total'] = ''; |
|
160 | - $template_args['edit_reg_info_url'] = $this->registration->edit_attendee_information_url(); |
|
161 | - $template_args['retry_payment_url'] = $this->registration->payment_overview_url(); |
|
162 | - $template_args['show_line_item_description'] = $this->check_if_any_line_items_have_a_description( |
|
163 | - $this->transaction->total_line_item() |
|
164 | - ); |
|
165 | - if ($template_args['amount_pd'] != $template_args['total_cost']) { |
|
166 | - // $template_args['net_total'] = $this->espressoInvoiceTotals( |
|
167 | - // esc_html__('SubTotal', 'event_espresso'), |
|
168 | - // $this->transaction->total()); |
|
169 | - // $this->session_data['cart']['REG']['sub_total'] |
|
170 | - // ); |
|
171 | - $tax_items = $this->transaction->tax_items(); |
|
172 | - if (! empty($tax_items)) { |
|
173 | - foreach ($tax_items as $tax) { |
|
174 | - $template_args['net_total'] .= $this->espressoInvoiceTotals($tax->name(), $tax->total()); |
|
175 | - } |
|
176 | - } |
|
177 | - |
|
178 | - $difference = $template_args['amount_pd'] - $template_args['total_cost']; |
|
179 | - if ($difference < 0) { |
|
180 | - $text = esc_html__('Discount', 'event_espresso'); |
|
181 | - } else { |
|
182 | - $text = esc_html__('Extra', 'event_espresso'); |
|
183 | - } |
|
184 | - $template_args['discount'] = $this->espressoInvoiceTotals($text, $difference); |
|
185 | - } |
|
186 | - |
|
187 | - $template_args['currency_symbol'] = $EE->CFG->currency->sign; |
|
188 | - $template_args['template_payment_instructions'] = wpautop( |
|
189 | - stripslashes_deep( |
|
190 | - html_entity_decode($this->invoice_payment_method->get_extra_meta('pdf_instructions', true), ENT_QUOTES) |
|
191 | - ) |
|
192 | - ); |
|
193 | - $template_args['shameless_plug'] = apply_filters( |
|
194 | - 'FHEE_Invoice__send_invoice__shameless_plug', |
|
195 | - true |
|
196 | - ); |
|
197 | - $receipt = $request->getRequestParam('receipt'); |
|
198 | - if ($receipt) { |
|
199 | - // receipt-specific stuff |
|
200 | - $events_for_txn = EEM_Event::instance()->get_all( |
|
201 | - [['Registration.TXN_ID' => $this->transaction->ID()]] |
|
202 | - ); |
|
203 | - $ticket_line_items_per_event = []; |
|
204 | - $registrations_per_line_item = []; |
|
205 | - $venues_for_events = []; |
|
206 | - foreach ($events_for_txn as $event_id => $event) { |
|
207 | - $line_items_for_this_event = EEM_Line_Item::instance()->get_all( |
|
208 | - [['Ticket.Datetime.EVT_ID' => $event_id, 'TXN_ID' => $this->transaction->ID()]] |
|
209 | - ); |
|
210 | - $ticket_line_items_per_event[ $event_id ] = $line_items_for_this_event; |
|
211 | - foreach ($line_items_for_this_event as $line_item_id => $line_item) { |
|
212 | - if (! $line_item instanceof EE_Line_Item) { |
|
213 | - continue; |
|
214 | - } |
|
215 | - $ticket = $line_item->ticket(); |
|
216 | - $registrations_for_this_ticket = EEM_Registration::instance()->get_all( |
|
217 | - [['TKT_ID' => $ticket->ID(), 'TXN_ID' => $this->transaction->ID()]] |
|
218 | - ); |
|
219 | - $registrations_per_line_item[ $line_item_id ] = $registrations_for_this_ticket; |
|
220 | - } |
|
221 | - if ($event instanceof EE_Event) { |
|
222 | - $venues_for_events += $event->venues(); |
|
223 | - } |
|
224 | - } |
|
225 | - $tax_total_line_item = EEM_Line_Item::instance()->get_one( |
|
226 | - [['TXN_ID' => $this->transaction->ID(), 'LIN_type' => EEM_Line_Item::type_tax_sub_total]] |
|
227 | - ); |
|
228 | - $questions_to_skip = [ |
|
229 | - EEM_Attendee::system_question_fname, |
|
230 | - EEM_Attendee::system_question_lname, |
|
231 | - EEM_Attendee::system_question_email, |
|
232 | - ]; |
|
233 | - |
|
234 | - |
|
235 | - $template_args['events_for_txn'] = $events_for_txn; |
|
236 | - $template_args['ticket_line_items_per_event'] = $ticket_line_items_per_event; |
|
237 | - $template_args['registrations_per_line_item'] = $registrations_per_line_item; |
|
238 | - $template_args['venues_for_events'] = $venues_for_events; |
|
239 | - $template_args['tax_total_line_item'] = $tax_total_line_item; |
|
240 | - $template_args['questions_to_skip'] = $questions_to_skip; |
|
241 | - // d($template_args); |
|
242 | - $template_args['download_link'] = $this->registration->receipt_url('download'); |
|
243 | - } else { |
|
244 | - // it's just an invoice we're accessing |
|
245 | - $template_args['download_link'] = $this->registration->invoice_url('download'); |
|
246 | - } |
|
247 | - |
|
248 | - // Get the HTML as an object |
|
249 | - $templates_relative_path = 'modules/gateways/Invoice/lib/templates/'; |
|
250 | - $template_header = EEH_Template::locate_template( |
|
251 | - $templates_relative_path . 'invoice_header.template.php', |
|
252 | - $template_args |
|
253 | - ); |
|
254 | - if ($receipt) { |
|
255 | - $template_body = EEH_Template::locate_template( |
|
256 | - $templates_relative_path . 'receipt_body.template.php', |
|
257 | - $template_args |
|
258 | - ); |
|
259 | - } else { |
|
260 | - $template_body = EEH_Template::locate_template( |
|
261 | - $templates_relative_path . 'invoice_body.template.php', |
|
262 | - $template_args |
|
263 | - ); |
|
264 | - } |
|
265 | - |
|
266 | - |
|
267 | - $template_footer = EEH_Template::locate_template( |
|
268 | - $templates_relative_path . 'invoice_footer.template.php', |
|
269 | - $template_args |
|
270 | - ); |
|
271 | - |
|
272 | - $copies = $request->getRequestParam('copies', 1, 'int'); |
|
273 | - |
|
274 | - $content = $this->espresso_replace_invoice_shortcodes($template_header); |
|
275 | - for ($x = 1; $x <= $copies; $x++) { |
|
276 | - $content .= $this->espresso_replace_invoice_shortcodes($template_body); |
|
277 | - } |
|
278 | - $content .= $this->espresso_replace_invoice_shortcodes($template_footer); |
|
279 | - |
|
280 | - // Check if debugging or mobile is set |
|
281 | - if ($request->getRequestParam('html')) { |
|
282 | - echo wp_kses($content, AllowedTags::getWithFormTags()); |
|
283 | - exit(0); |
|
284 | - } |
|
285 | - $invoice_name = $template_args['organization'] . ' '; |
|
286 | - $invoice_name .= esc_html__('Invoice #', 'event_espresso'); |
|
287 | - $invoice_name .= $template_args['registration_code']; |
|
288 | - $invoice_name .= esc_html__(' for ', 'event_espresso') . $template_args['name']; |
|
289 | - $invoice_name = str_replace(' ', '_', $invoice_name); |
|
290 | - // Create the PDF |
|
291 | - if ($request->requestParamIsSet('html')) { |
|
292 | - echo wp_kses($content, AllowedTags::getWithFormTags()); |
|
293 | - exit(0); |
|
294 | - } |
|
295 | - $pdf_adapter = new PdfAdapter(); |
|
296 | - // dompdf options |
|
297 | - $options = $pdf_adapter->getOptions(); |
|
298 | - if ($options instanceof Dompdf\Options) { |
|
299 | - $pdf_adapter |
|
300 | - ->setOptions($options) |
|
301 | - ->setContent($content) |
|
302 | - ->generate($invoice_name . ".pdf", (bool) $download); |
|
303 | - exit(0); |
|
304 | - } |
|
305 | - wp_die(esc_html__( |
|
306 | - 'DomPDF package appears to be missing, so cannot generate the PDF file.', |
|
307 | - 'event_espresso' |
|
308 | - )); |
|
309 | - exit(0); |
|
310 | - } |
|
311 | - |
|
312 | - |
|
313 | - /** |
|
314 | - * Checks if this line item, or any of its children, actually has a description. |
|
315 | - * If none do, then the template can decide to not show any description column |
|
316 | - * |
|
317 | - * @param EE_Line_Item $line_item |
|
318 | - * @return boolean |
|
319 | - * @throws EE_Error |
|
320 | - * @throws ReflectionException |
|
321 | - */ |
|
322 | - public function check_if_any_line_items_have_a_description(EE_Line_Item $line_item) |
|
323 | - { |
|
324 | - if ($line_item->desc()) { |
|
325 | - return true; |
|
326 | - } else { |
|
327 | - foreach ($line_item->children() as $child_line_item) { |
|
328 | - if ($this->check_if_any_line_items_have_a_description($child_line_item)) { |
|
329 | - return true; |
|
330 | - } |
|
331 | - } |
|
332 | - // well, if I and my children don't have descriptions, I guess not |
|
333 | - return false; |
|
334 | - } |
|
335 | - } |
|
336 | - |
|
337 | - |
|
338 | - /** |
|
339 | - * Perform the shortcode replacement |
|
340 | - * |
|
341 | - * @param $content |
|
342 | - * @return array|string|string[] |
|
343 | - * @throws EE_Error |
|
344 | - * @throws ReflectionException |
|
345 | - */ |
|
346 | - public function espresso_replace_invoice_shortcodes($content) |
|
347 | - { |
|
348 | - |
|
349 | - $EE = EE_Registry::instance(); |
|
350 | - // Create the logo |
|
351 | - $invoice_logo_url = $this->invoice_payment_method->get_extra_meta( |
|
352 | - 'pdf_logo_image', |
|
353 | - true, |
|
354 | - $EE->CFG->organization->logo_url |
|
355 | - ); |
|
356 | - if (! empty($invoice_logo_url)) { |
|
357 | - $image_size = getimagesize($invoice_logo_url); |
|
358 | - $invoice_logo_image = |
|
359 | - '<img class="logo screen" src="' . $invoice_logo_url . '" ' . $image_size[3] . ' alt="logo" /> '; |
|
360 | - } else { |
|
361 | - $invoice_logo_image = ''; |
|
362 | - } |
|
363 | - $SearchValues = [ |
|
364 | - "[organization]", |
|
365 | - "[registration_code]", |
|
366 | - "[transaction_id]", |
|
367 | - "[name]", |
|
368 | - "[base_url]", |
|
369 | - "[download_link]", |
|
370 | - "[invoice_logo_image]", |
|
371 | - "[street]", |
|
372 | - "[city]", |
|
373 | - "[state]", |
|
374 | - "[zip]", |
|
375 | - "[email]", |
|
376 | - "[vat]", |
|
377 | - "[registration_date]", |
|
378 | - "[instructions]", |
|
379 | - ]; |
|
380 | - $primary_attendee = $this->transaction->primary_registration()->attendee(); |
|
381 | - $org_state = EE_Registry::instance()->load_model('State')->get_one_by_ID($EE->CFG->organization->STA_ID); |
|
382 | - if ($org_state) { |
|
383 | - $org_state_name = $org_state->name(); |
|
384 | - } else { |
|
385 | - $org_state_name = ''; |
|
386 | - } |
|
387 | - $ReplaceValues = [ |
|
388 | - $EE->CFG->organization->get_pretty('name'), |
|
389 | - $this->registration->reg_code(), |
|
390 | - $this->transaction->ID(), |
|
391 | - $primary_attendee->full_name(), |
|
392 | - (is_dir(EVENT_ESPRESSO_GATEWAY_DIR . '/invoice')) |
|
393 | - ? EVENT_ESPRESSO_GATEWAY_URL . 'Invoice/lib/templates/' |
|
394 | - : EE_GATEWAYS_URL . 'Invoice/lib/templates/', |
|
395 | - $this->registration->invoice_url(), |
|
396 | - // home_url() . '/?download_invoice=true&id=' . $this->registration->reg_url_link(), |
|
397 | - $invoice_logo_image, |
|
398 | - empty($EE->CFG->organization->address_2) |
|
399 | - ? $EE->CFG->organization->get_pretty('address_1') |
|
400 | - : $EE->CFG->organization->get_pretty('address_1') . '<br>' . $EE->CFG->organization->get_pretty( |
|
401 | - 'address_2' |
|
402 | - ), |
|
403 | - $EE->CFG->organization->get_pretty('city'), |
|
404 | - $org_state_name, |
|
405 | - $EE->CFG->organization->get_pretty('zip'), |
|
406 | - $EE->CFG->organization->get_pretty('email'), |
|
407 | - $EE->CFG->organization->vat, |
|
408 | - $this->registration->get_i18n_datetime('REG_date', get_option('date_format')), |
|
409 | - $this->invoice_payment_method->get_extra_meta('pdf_instructions', true), |
|
410 | - ]; |
|
411 | - |
|
412 | - return str_replace($SearchValues, $ReplaceValues, $content); |
|
413 | - } |
|
414 | - |
|
415 | - |
|
416 | - public function espressoLoadData($items) |
|
417 | - { |
|
418 | - $lines = $items; |
|
419 | - $data = []; |
|
420 | - foreach ($lines as $line) { |
|
421 | - $data[] = explode(';', chop($line)); |
|
422 | - } |
|
423 | - |
|
424 | - return $data; |
|
425 | - } |
|
426 | - |
|
427 | - |
|
428 | - public function espressoInvoiceTotals($text, $total_cost) |
|
429 | - { |
|
430 | - $html = ''; |
|
431 | - if ($total_cost < 0) { |
|
432 | - $total_cost = (-1) * $total_cost; |
|
433 | - } |
|
434 | - $find = [' ']; |
|
435 | - $replace = ['-']; |
|
436 | - $row_id = strtolower(str_replace($find, $replace, $text)); |
|
437 | - $html .= '<tr id="' . $row_id . '-tr"><td colspan="4"> </td>'; |
|
438 | - $html .= '<td class="item_r">' . $text . '</td>'; |
|
439 | - $html .= '<td class="item_r">' . $total_cost . '</td>'; |
|
440 | - $html .= '</tr>'; |
|
441 | - return $html; |
|
442 | - } |
|
16 | + /** |
|
17 | + * |
|
18 | + * @var EE_Registration |
|
19 | + */ |
|
20 | + private $registration; |
|
21 | + |
|
22 | + /** |
|
23 | + * |
|
24 | + * @var EE_Transaction |
|
25 | + */ |
|
26 | + private $transaction; |
|
27 | + |
|
28 | + /** |
|
29 | + * |
|
30 | + * @var EE_Payment_Method |
|
31 | + */ |
|
32 | + private $invoice_payment_method; |
|
33 | + |
|
34 | + |
|
35 | + /** |
|
36 | + * Invoice constructor. |
|
37 | + * |
|
38 | + * @param int $url_link |
|
39 | + * @throws EE_Error |
|
40 | + * @throws ReflectionException |
|
41 | + * @deprecated 4.9.13 |
|
42 | + */ |
|
43 | + public function __construct($url_link = 0) |
|
44 | + { |
|
45 | + EE_Error::doing_it_wrong( |
|
46 | + __CLASS__, |
|
47 | + esc_html__( |
|
48 | + 'This class has been deprecated and replaced by the new Messages library.', |
|
49 | + 'event_espresso' |
|
50 | + ), |
|
51 | + '4.9.12', |
|
52 | + '5.0.0' |
|
53 | + ); |
|
54 | + /** @var EEM_Registration $reg_model */ |
|
55 | + $reg_model = EE_Registry::instance()->load_model('Registration'); |
|
56 | + if ($this->registration = $reg_model->get_registration_for_reg_url_link($url_link)) { |
|
57 | + $this->transaction = $this->registration->transaction(); |
|
58 | + EE_Config::instance()->gateway->payment_settings; |
|
59 | + $this->invoice_payment_method = EEM_Payment_Method::instance()->get_one_of_type('Invoice'); |
|
60 | + } else { |
|
61 | + EE_Error::add_error( |
|
62 | + esc_html__( |
|
63 | + 'Your request appears to be missing some required data, and no information for your transaction could be retrieved.', |
|
64 | + 'event_espresso' |
|
65 | + ), |
|
66 | + __FILE__, |
|
67 | + __FUNCTION__, |
|
68 | + __LINE__ |
|
69 | + ); |
|
70 | + } |
|
71 | + } |
|
72 | + |
|
73 | + |
|
74 | + /** |
|
75 | + * @param false $download |
|
76 | + * @throws EE_Error |
|
77 | + * @throws ReflectionException |
|
78 | + */ |
|
79 | + public function send_invoice($download = false) |
|
80 | + { |
|
81 | + $template_args = []; |
|
82 | + $EE = EE_Registry::instance(); |
|
83 | + /** @var RequestInterface $request */ |
|
84 | + $request = LoaderFactory::getLoader()->getShared(RequestInterface::class); |
|
85 | + $theme = $request->getRequestParam('theme', 0, 'int'); |
|
86 | + // allow the request to override the default theme defined in the invoice settings |
|
87 | + $theme_requested = $theme > 0 && $theme < 8 |
|
88 | + ? $theme |
|
89 | + : null; |
|
90 | + $themes = [ |
|
91 | + 1 => "simple.css", |
|
92 | + 2 => "bauhaus.css", |
|
93 | + 3 => "ejs.css", |
|
94 | + 4 => "horizon.css", |
|
95 | + 5 => "lola.css", |
|
96 | + 6 => "tranquility.css", |
|
97 | + 7 => "union.css", |
|
98 | + ]; |
|
99 | + // Get the CSS file |
|
100 | + if (isset($themes[ $theme_requested ])) { |
|
101 | + $template_args['invoice_css'] = $themes[ $theme_requested ]; |
|
102 | + } else { |
|
103 | + $template_args['invoice_css'] = $this->invoice_payment_method->get_extra_meta( |
|
104 | + 'legacy_invoice_css', |
|
105 | + true, |
|
106 | + 'simple.css' |
|
107 | + ); |
|
108 | + } |
|
109 | + |
|
110 | + if (is_dir(EVENT_ESPRESSO_GATEWAY_DIR . '/invoice')) { |
|
111 | + $template_args['base_url'] = EVENT_ESPRESSO_GATEWAY_URL . 'Invoice/lib/templates/'; |
|
112 | + } else { |
|
113 | + $template_args['base_url'] = EE_GATEWAYS . '/Invoice/lib/templates/'; |
|
114 | + } |
|
115 | + $primary_attendee = $this->transaction->primary_registration()->attendee(); |
|
116 | + |
|
117 | + $template_args['organization'] = $EE->CFG->organization->get_pretty('name'); |
|
118 | + $template_args['street'] = empty($EE->CFG->organization->address_2) |
|
119 | + ? $EE->CFG->organization->get_pretty('address_1') |
|
120 | + : $EE->CFG->organization->get_pretty('address_1') |
|
121 | + . '<br>' |
|
122 | + . $EE->CFG->organization->get_pretty('address_2'); |
|
123 | + $template_args['city'] = $EE->CFG->organization->get_pretty('city'); |
|
124 | + $template_args['state'] = EE_Registry::instance()->load_model('State')->get_one_by_ID( |
|
125 | + $EE->CFG->organization->STA_ID |
|
126 | + ); |
|
127 | + $template_args['country'] = EE_Registry::instance()->load_model('Country')->get_one_by_ID( |
|
128 | + $EE->CFG->organization->CNT_ISO |
|
129 | + ); |
|
130 | + $template_args['zip'] = $EE->CFG->organization->get_pretty('zip'); |
|
131 | + $template_args['email'] = $EE->CFG->organization->get_pretty('email'); |
|
132 | + |
|
133 | + $template_args['registration_code'] = $this->registration->reg_code(); |
|
134 | + $template_args['registration_date'] = $this->registration->date(); |
|
135 | + $template_args['name'] = $primary_attendee->full_name(); |
|
136 | + $template_args['attendee_address'] = $primary_attendee->address(); |
|
137 | + $template_args['attendee_address2'] = $primary_attendee->address2(); |
|
138 | + $template_args['attendee_city'] = $primary_attendee->city(); |
|
139 | + $attendee_state = $primary_attendee->state_obj(); |
|
140 | + if ($attendee_state) { |
|
141 | + $attendee_state_name = $attendee_state->name(); |
|
142 | + } else { |
|
143 | + $attendee_state_name = ''; |
|
144 | + } |
|
145 | + $template_args['attendee_state'] = $attendee_state_name; |
|
146 | + $template_args['attendee_zip'] = $primary_attendee->zip(); |
|
147 | + |
|
148 | + $template_args['ship_name'] = $template_args['name']; |
|
149 | + $template_args['ship_address'] = $template_args['attendee_address']; |
|
150 | + $template_args['ship_city'] = $template_args['attendee_city']; |
|
151 | + $template_args['ship_state'] = $template_args['attendee_state']; |
|
152 | + $template_args['ship_zip'] = $template_args['attendee_zip']; |
|
153 | + |
|
154 | + $template_args['total_cost'] = number_format($this->transaction->total(), 2, '.', ''); |
|
155 | + $template_args['transaction'] = $this->transaction; |
|
156 | + $template_args['amount_pd'] = $this->transaction->paid(); |
|
157 | + $template_args['amount_owed'] = $this->transaction->total() - $this->transaction->paid(); |
|
158 | + $template_args['payments'] = $this->transaction->approved_payments(); |
|
159 | + $template_args['net_total'] = ''; |
|
160 | + $template_args['edit_reg_info_url'] = $this->registration->edit_attendee_information_url(); |
|
161 | + $template_args['retry_payment_url'] = $this->registration->payment_overview_url(); |
|
162 | + $template_args['show_line_item_description'] = $this->check_if_any_line_items_have_a_description( |
|
163 | + $this->transaction->total_line_item() |
|
164 | + ); |
|
165 | + if ($template_args['amount_pd'] != $template_args['total_cost']) { |
|
166 | + // $template_args['net_total'] = $this->espressoInvoiceTotals( |
|
167 | + // esc_html__('SubTotal', 'event_espresso'), |
|
168 | + // $this->transaction->total()); |
|
169 | + // $this->session_data['cart']['REG']['sub_total'] |
|
170 | + // ); |
|
171 | + $tax_items = $this->transaction->tax_items(); |
|
172 | + if (! empty($tax_items)) { |
|
173 | + foreach ($tax_items as $tax) { |
|
174 | + $template_args['net_total'] .= $this->espressoInvoiceTotals($tax->name(), $tax->total()); |
|
175 | + } |
|
176 | + } |
|
177 | + |
|
178 | + $difference = $template_args['amount_pd'] - $template_args['total_cost']; |
|
179 | + if ($difference < 0) { |
|
180 | + $text = esc_html__('Discount', 'event_espresso'); |
|
181 | + } else { |
|
182 | + $text = esc_html__('Extra', 'event_espresso'); |
|
183 | + } |
|
184 | + $template_args['discount'] = $this->espressoInvoiceTotals($text, $difference); |
|
185 | + } |
|
186 | + |
|
187 | + $template_args['currency_symbol'] = $EE->CFG->currency->sign; |
|
188 | + $template_args['template_payment_instructions'] = wpautop( |
|
189 | + stripslashes_deep( |
|
190 | + html_entity_decode($this->invoice_payment_method->get_extra_meta('pdf_instructions', true), ENT_QUOTES) |
|
191 | + ) |
|
192 | + ); |
|
193 | + $template_args['shameless_plug'] = apply_filters( |
|
194 | + 'FHEE_Invoice__send_invoice__shameless_plug', |
|
195 | + true |
|
196 | + ); |
|
197 | + $receipt = $request->getRequestParam('receipt'); |
|
198 | + if ($receipt) { |
|
199 | + // receipt-specific stuff |
|
200 | + $events_for_txn = EEM_Event::instance()->get_all( |
|
201 | + [['Registration.TXN_ID' => $this->transaction->ID()]] |
|
202 | + ); |
|
203 | + $ticket_line_items_per_event = []; |
|
204 | + $registrations_per_line_item = []; |
|
205 | + $venues_for_events = []; |
|
206 | + foreach ($events_for_txn as $event_id => $event) { |
|
207 | + $line_items_for_this_event = EEM_Line_Item::instance()->get_all( |
|
208 | + [['Ticket.Datetime.EVT_ID' => $event_id, 'TXN_ID' => $this->transaction->ID()]] |
|
209 | + ); |
|
210 | + $ticket_line_items_per_event[ $event_id ] = $line_items_for_this_event; |
|
211 | + foreach ($line_items_for_this_event as $line_item_id => $line_item) { |
|
212 | + if (! $line_item instanceof EE_Line_Item) { |
|
213 | + continue; |
|
214 | + } |
|
215 | + $ticket = $line_item->ticket(); |
|
216 | + $registrations_for_this_ticket = EEM_Registration::instance()->get_all( |
|
217 | + [['TKT_ID' => $ticket->ID(), 'TXN_ID' => $this->transaction->ID()]] |
|
218 | + ); |
|
219 | + $registrations_per_line_item[ $line_item_id ] = $registrations_for_this_ticket; |
|
220 | + } |
|
221 | + if ($event instanceof EE_Event) { |
|
222 | + $venues_for_events += $event->venues(); |
|
223 | + } |
|
224 | + } |
|
225 | + $tax_total_line_item = EEM_Line_Item::instance()->get_one( |
|
226 | + [['TXN_ID' => $this->transaction->ID(), 'LIN_type' => EEM_Line_Item::type_tax_sub_total]] |
|
227 | + ); |
|
228 | + $questions_to_skip = [ |
|
229 | + EEM_Attendee::system_question_fname, |
|
230 | + EEM_Attendee::system_question_lname, |
|
231 | + EEM_Attendee::system_question_email, |
|
232 | + ]; |
|
233 | + |
|
234 | + |
|
235 | + $template_args['events_for_txn'] = $events_for_txn; |
|
236 | + $template_args['ticket_line_items_per_event'] = $ticket_line_items_per_event; |
|
237 | + $template_args['registrations_per_line_item'] = $registrations_per_line_item; |
|
238 | + $template_args['venues_for_events'] = $venues_for_events; |
|
239 | + $template_args['tax_total_line_item'] = $tax_total_line_item; |
|
240 | + $template_args['questions_to_skip'] = $questions_to_skip; |
|
241 | + // d($template_args); |
|
242 | + $template_args['download_link'] = $this->registration->receipt_url('download'); |
|
243 | + } else { |
|
244 | + // it's just an invoice we're accessing |
|
245 | + $template_args['download_link'] = $this->registration->invoice_url('download'); |
|
246 | + } |
|
247 | + |
|
248 | + // Get the HTML as an object |
|
249 | + $templates_relative_path = 'modules/gateways/Invoice/lib/templates/'; |
|
250 | + $template_header = EEH_Template::locate_template( |
|
251 | + $templates_relative_path . 'invoice_header.template.php', |
|
252 | + $template_args |
|
253 | + ); |
|
254 | + if ($receipt) { |
|
255 | + $template_body = EEH_Template::locate_template( |
|
256 | + $templates_relative_path . 'receipt_body.template.php', |
|
257 | + $template_args |
|
258 | + ); |
|
259 | + } else { |
|
260 | + $template_body = EEH_Template::locate_template( |
|
261 | + $templates_relative_path . 'invoice_body.template.php', |
|
262 | + $template_args |
|
263 | + ); |
|
264 | + } |
|
265 | + |
|
266 | + |
|
267 | + $template_footer = EEH_Template::locate_template( |
|
268 | + $templates_relative_path . 'invoice_footer.template.php', |
|
269 | + $template_args |
|
270 | + ); |
|
271 | + |
|
272 | + $copies = $request->getRequestParam('copies', 1, 'int'); |
|
273 | + |
|
274 | + $content = $this->espresso_replace_invoice_shortcodes($template_header); |
|
275 | + for ($x = 1; $x <= $copies; $x++) { |
|
276 | + $content .= $this->espresso_replace_invoice_shortcodes($template_body); |
|
277 | + } |
|
278 | + $content .= $this->espresso_replace_invoice_shortcodes($template_footer); |
|
279 | + |
|
280 | + // Check if debugging or mobile is set |
|
281 | + if ($request->getRequestParam('html')) { |
|
282 | + echo wp_kses($content, AllowedTags::getWithFormTags()); |
|
283 | + exit(0); |
|
284 | + } |
|
285 | + $invoice_name = $template_args['organization'] . ' '; |
|
286 | + $invoice_name .= esc_html__('Invoice #', 'event_espresso'); |
|
287 | + $invoice_name .= $template_args['registration_code']; |
|
288 | + $invoice_name .= esc_html__(' for ', 'event_espresso') . $template_args['name']; |
|
289 | + $invoice_name = str_replace(' ', '_', $invoice_name); |
|
290 | + // Create the PDF |
|
291 | + if ($request->requestParamIsSet('html')) { |
|
292 | + echo wp_kses($content, AllowedTags::getWithFormTags()); |
|
293 | + exit(0); |
|
294 | + } |
|
295 | + $pdf_adapter = new PdfAdapter(); |
|
296 | + // dompdf options |
|
297 | + $options = $pdf_adapter->getOptions(); |
|
298 | + if ($options instanceof Dompdf\Options) { |
|
299 | + $pdf_adapter |
|
300 | + ->setOptions($options) |
|
301 | + ->setContent($content) |
|
302 | + ->generate($invoice_name . ".pdf", (bool) $download); |
|
303 | + exit(0); |
|
304 | + } |
|
305 | + wp_die(esc_html__( |
|
306 | + 'DomPDF package appears to be missing, so cannot generate the PDF file.', |
|
307 | + 'event_espresso' |
|
308 | + )); |
|
309 | + exit(0); |
|
310 | + } |
|
311 | + |
|
312 | + |
|
313 | + /** |
|
314 | + * Checks if this line item, or any of its children, actually has a description. |
|
315 | + * If none do, then the template can decide to not show any description column |
|
316 | + * |
|
317 | + * @param EE_Line_Item $line_item |
|
318 | + * @return boolean |
|
319 | + * @throws EE_Error |
|
320 | + * @throws ReflectionException |
|
321 | + */ |
|
322 | + public function check_if_any_line_items_have_a_description(EE_Line_Item $line_item) |
|
323 | + { |
|
324 | + if ($line_item->desc()) { |
|
325 | + return true; |
|
326 | + } else { |
|
327 | + foreach ($line_item->children() as $child_line_item) { |
|
328 | + if ($this->check_if_any_line_items_have_a_description($child_line_item)) { |
|
329 | + return true; |
|
330 | + } |
|
331 | + } |
|
332 | + // well, if I and my children don't have descriptions, I guess not |
|
333 | + return false; |
|
334 | + } |
|
335 | + } |
|
336 | + |
|
337 | + |
|
338 | + /** |
|
339 | + * Perform the shortcode replacement |
|
340 | + * |
|
341 | + * @param $content |
|
342 | + * @return array|string|string[] |
|
343 | + * @throws EE_Error |
|
344 | + * @throws ReflectionException |
|
345 | + */ |
|
346 | + public function espresso_replace_invoice_shortcodes($content) |
|
347 | + { |
|
348 | + |
|
349 | + $EE = EE_Registry::instance(); |
|
350 | + // Create the logo |
|
351 | + $invoice_logo_url = $this->invoice_payment_method->get_extra_meta( |
|
352 | + 'pdf_logo_image', |
|
353 | + true, |
|
354 | + $EE->CFG->organization->logo_url |
|
355 | + ); |
|
356 | + if (! empty($invoice_logo_url)) { |
|
357 | + $image_size = getimagesize($invoice_logo_url); |
|
358 | + $invoice_logo_image = |
|
359 | + '<img class="logo screen" src="' . $invoice_logo_url . '" ' . $image_size[3] . ' alt="logo" /> '; |
|
360 | + } else { |
|
361 | + $invoice_logo_image = ''; |
|
362 | + } |
|
363 | + $SearchValues = [ |
|
364 | + "[organization]", |
|
365 | + "[registration_code]", |
|
366 | + "[transaction_id]", |
|
367 | + "[name]", |
|
368 | + "[base_url]", |
|
369 | + "[download_link]", |
|
370 | + "[invoice_logo_image]", |
|
371 | + "[street]", |
|
372 | + "[city]", |
|
373 | + "[state]", |
|
374 | + "[zip]", |
|
375 | + "[email]", |
|
376 | + "[vat]", |
|
377 | + "[registration_date]", |
|
378 | + "[instructions]", |
|
379 | + ]; |
|
380 | + $primary_attendee = $this->transaction->primary_registration()->attendee(); |
|
381 | + $org_state = EE_Registry::instance()->load_model('State')->get_one_by_ID($EE->CFG->organization->STA_ID); |
|
382 | + if ($org_state) { |
|
383 | + $org_state_name = $org_state->name(); |
|
384 | + } else { |
|
385 | + $org_state_name = ''; |
|
386 | + } |
|
387 | + $ReplaceValues = [ |
|
388 | + $EE->CFG->organization->get_pretty('name'), |
|
389 | + $this->registration->reg_code(), |
|
390 | + $this->transaction->ID(), |
|
391 | + $primary_attendee->full_name(), |
|
392 | + (is_dir(EVENT_ESPRESSO_GATEWAY_DIR . '/invoice')) |
|
393 | + ? EVENT_ESPRESSO_GATEWAY_URL . 'Invoice/lib/templates/' |
|
394 | + : EE_GATEWAYS_URL . 'Invoice/lib/templates/', |
|
395 | + $this->registration->invoice_url(), |
|
396 | + // home_url() . '/?download_invoice=true&id=' . $this->registration->reg_url_link(), |
|
397 | + $invoice_logo_image, |
|
398 | + empty($EE->CFG->organization->address_2) |
|
399 | + ? $EE->CFG->organization->get_pretty('address_1') |
|
400 | + : $EE->CFG->organization->get_pretty('address_1') . '<br>' . $EE->CFG->organization->get_pretty( |
|
401 | + 'address_2' |
|
402 | + ), |
|
403 | + $EE->CFG->organization->get_pretty('city'), |
|
404 | + $org_state_name, |
|
405 | + $EE->CFG->organization->get_pretty('zip'), |
|
406 | + $EE->CFG->organization->get_pretty('email'), |
|
407 | + $EE->CFG->organization->vat, |
|
408 | + $this->registration->get_i18n_datetime('REG_date', get_option('date_format')), |
|
409 | + $this->invoice_payment_method->get_extra_meta('pdf_instructions', true), |
|
410 | + ]; |
|
411 | + |
|
412 | + return str_replace($SearchValues, $ReplaceValues, $content); |
|
413 | + } |
|
414 | + |
|
415 | + |
|
416 | + public function espressoLoadData($items) |
|
417 | + { |
|
418 | + $lines = $items; |
|
419 | + $data = []; |
|
420 | + foreach ($lines as $line) { |
|
421 | + $data[] = explode(';', chop($line)); |
|
422 | + } |
|
423 | + |
|
424 | + return $data; |
|
425 | + } |
|
426 | + |
|
427 | + |
|
428 | + public function espressoInvoiceTotals($text, $total_cost) |
|
429 | + { |
|
430 | + $html = ''; |
|
431 | + if ($total_cost < 0) { |
|
432 | + $total_cost = (-1) * $total_cost; |
|
433 | + } |
|
434 | + $find = [' ']; |
|
435 | + $replace = ['-']; |
|
436 | + $row_id = strtolower(str_replace($find, $replace, $text)); |
|
437 | + $html .= '<tr id="' . $row_id . '-tr"><td colspan="4"> </td>'; |
|
438 | + $html .= '<td class="item_r">' . $text . '</td>'; |
|
439 | + $html .= '<td class="item_r">' . $total_cost . '</td>'; |
|
440 | + $html .= '</tr>'; |
|
441 | + return $html; |
|
442 | + } |
|
443 | 443 | } |
@@ -97,8 +97,8 @@ discard block |
||
97 | 97 | 7 => "union.css", |
98 | 98 | ]; |
99 | 99 | // Get the CSS file |
100 | - if (isset($themes[ $theme_requested ])) { |
|
101 | - $template_args['invoice_css'] = $themes[ $theme_requested ]; |
|
100 | + if (isset($themes[$theme_requested])) { |
|
101 | + $template_args['invoice_css'] = $themes[$theme_requested]; |
|
102 | 102 | } else { |
103 | 103 | $template_args['invoice_css'] = $this->invoice_payment_method->get_extra_meta( |
104 | 104 | 'legacy_invoice_css', |
@@ -107,10 +107,10 @@ discard block |
||
107 | 107 | ); |
108 | 108 | } |
109 | 109 | |
110 | - if (is_dir(EVENT_ESPRESSO_GATEWAY_DIR . '/invoice')) { |
|
111 | - $template_args['base_url'] = EVENT_ESPRESSO_GATEWAY_URL . 'Invoice/lib/templates/'; |
|
110 | + if (is_dir(EVENT_ESPRESSO_GATEWAY_DIR.'/invoice')) { |
|
111 | + $template_args['base_url'] = EVENT_ESPRESSO_GATEWAY_URL.'Invoice/lib/templates/'; |
|
112 | 112 | } else { |
113 | - $template_args['base_url'] = EE_GATEWAYS . '/Invoice/lib/templates/'; |
|
113 | + $template_args['base_url'] = EE_GATEWAYS.'/Invoice/lib/templates/'; |
|
114 | 114 | } |
115 | 115 | $primary_attendee = $this->transaction->primary_registration()->attendee(); |
116 | 116 | |
@@ -169,7 +169,7 @@ discard block |
||
169 | 169 | // $this->session_data['cart']['REG']['sub_total'] |
170 | 170 | // ); |
171 | 171 | $tax_items = $this->transaction->tax_items(); |
172 | - if (! empty($tax_items)) { |
|
172 | + if ( ! empty($tax_items)) { |
|
173 | 173 | foreach ($tax_items as $tax) { |
174 | 174 | $template_args['net_total'] .= $this->espressoInvoiceTotals($tax->name(), $tax->total()); |
175 | 175 | } |
@@ -190,7 +190,7 @@ discard block |
||
190 | 190 | html_entity_decode($this->invoice_payment_method->get_extra_meta('pdf_instructions', true), ENT_QUOTES) |
191 | 191 | ) |
192 | 192 | ); |
193 | - $template_args['shameless_plug'] = apply_filters( |
|
193 | + $template_args['shameless_plug'] = apply_filters( |
|
194 | 194 | 'FHEE_Invoice__send_invoice__shameless_plug', |
195 | 195 | true |
196 | 196 | ); |
@@ -207,16 +207,16 @@ discard block |
||
207 | 207 | $line_items_for_this_event = EEM_Line_Item::instance()->get_all( |
208 | 208 | [['Ticket.Datetime.EVT_ID' => $event_id, 'TXN_ID' => $this->transaction->ID()]] |
209 | 209 | ); |
210 | - $ticket_line_items_per_event[ $event_id ] = $line_items_for_this_event; |
|
210 | + $ticket_line_items_per_event[$event_id] = $line_items_for_this_event; |
|
211 | 211 | foreach ($line_items_for_this_event as $line_item_id => $line_item) { |
212 | - if (! $line_item instanceof EE_Line_Item) { |
|
212 | + if ( ! $line_item instanceof EE_Line_Item) { |
|
213 | 213 | continue; |
214 | 214 | } |
215 | 215 | $ticket = $line_item->ticket(); |
216 | 216 | $registrations_for_this_ticket = EEM_Registration::instance()->get_all( |
217 | 217 | [['TKT_ID' => $ticket->ID(), 'TXN_ID' => $this->transaction->ID()]] |
218 | 218 | ); |
219 | - $registrations_per_line_item[ $line_item_id ] = $registrations_for_this_ticket; |
|
219 | + $registrations_per_line_item[$line_item_id] = $registrations_for_this_ticket; |
|
220 | 220 | } |
221 | 221 | if ($event instanceof EE_Event) { |
222 | 222 | $venues_for_events += $event->venues(); |
@@ -248,24 +248,24 @@ discard block |
||
248 | 248 | // Get the HTML as an object |
249 | 249 | $templates_relative_path = 'modules/gateways/Invoice/lib/templates/'; |
250 | 250 | $template_header = EEH_Template::locate_template( |
251 | - $templates_relative_path . 'invoice_header.template.php', |
|
251 | + $templates_relative_path.'invoice_header.template.php', |
|
252 | 252 | $template_args |
253 | 253 | ); |
254 | 254 | if ($receipt) { |
255 | 255 | $template_body = EEH_Template::locate_template( |
256 | - $templates_relative_path . 'receipt_body.template.php', |
|
256 | + $templates_relative_path.'receipt_body.template.php', |
|
257 | 257 | $template_args |
258 | 258 | ); |
259 | 259 | } else { |
260 | 260 | $template_body = EEH_Template::locate_template( |
261 | - $templates_relative_path . 'invoice_body.template.php', |
|
261 | + $templates_relative_path.'invoice_body.template.php', |
|
262 | 262 | $template_args |
263 | 263 | ); |
264 | 264 | } |
265 | 265 | |
266 | 266 | |
267 | 267 | $template_footer = EEH_Template::locate_template( |
268 | - $templates_relative_path . 'invoice_footer.template.php', |
|
268 | + $templates_relative_path.'invoice_footer.template.php', |
|
269 | 269 | $template_args |
270 | 270 | ); |
271 | 271 | |
@@ -282,10 +282,10 @@ discard block |
||
282 | 282 | echo wp_kses($content, AllowedTags::getWithFormTags()); |
283 | 283 | exit(0); |
284 | 284 | } |
285 | - $invoice_name = $template_args['organization'] . ' '; |
|
285 | + $invoice_name = $template_args['organization'].' '; |
|
286 | 286 | $invoice_name .= esc_html__('Invoice #', 'event_espresso'); |
287 | 287 | $invoice_name .= $template_args['registration_code']; |
288 | - $invoice_name .= esc_html__(' for ', 'event_espresso') . $template_args['name']; |
|
288 | + $invoice_name .= esc_html__(' for ', 'event_espresso').$template_args['name']; |
|
289 | 289 | $invoice_name = str_replace(' ', '_', $invoice_name); |
290 | 290 | // Create the PDF |
291 | 291 | if ($request->requestParamIsSet('html')) { |
@@ -299,7 +299,7 @@ discard block |
||
299 | 299 | $pdf_adapter |
300 | 300 | ->setOptions($options) |
301 | 301 | ->setContent($content) |
302 | - ->generate($invoice_name . ".pdf", (bool) $download); |
|
302 | + ->generate($invoice_name.".pdf", (bool) $download); |
|
303 | 303 | exit(0); |
304 | 304 | } |
305 | 305 | wp_die(esc_html__( |
@@ -353,14 +353,14 @@ discard block |
||
353 | 353 | true, |
354 | 354 | $EE->CFG->organization->logo_url |
355 | 355 | ); |
356 | - if (! empty($invoice_logo_url)) { |
|
356 | + if ( ! empty($invoice_logo_url)) { |
|
357 | 357 | $image_size = getimagesize($invoice_logo_url); |
358 | 358 | $invoice_logo_image = |
359 | - '<img class="logo screen" src="' . $invoice_logo_url . '" ' . $image_size[3] . ' alt="logo" /> '; |
|
359 | + '<img class="logo screen" src="'.$invoice_logo_url.'" '.$image_size[3].' alt="logo" /> '; |
|
360 | 360 | } else { |
361 | 361 | $invoice_logo_image = ''; |
362 | 362 | } |
363 | - $SearchValues = [ |
|
363 | + $SearchValues = [ |
|
364 | 364 | "[organization]", |
365 | 365 | "[registration_code]", |
366 | 366 | "[transaction_id]", |
@@ -389,15 +389,15 @@ discard block |
||
389 | 389 | $this->registration->reg_code(), |
390 | 390 | $this->transaction->ID(), |
391 | 391 | $primary_attendee->full_name(), |
392 | - (is_dir(EVENT_ESPRESSO_GATEWAY_DIR . '/invoice')) |
|
392 | + (is_dir(EVENT_ESPRESSO_GATEWAY_DIR.'/invoice')) |
|
393 | 393 | ? EVENT_ESPRESSO_GATEWAY_URL . 'Invoice/lib/templates/' |
394 | - : EE_GATEWAYS_URL . 'Invoice/lib/templates/', |
|
394 | + : EE_GATEWAYS_URL.'Invoice/lib/templates/', |
|
395 | 395 | $this->registration->invoice_url(), |
396 | 396 | // home_url() . '/?download_invoice=true&id=' . $this->registration->reg_url_link(), |
397 | 397 | $invoice_logo_image, |
398 | 398 | empty($EE->CFG->organization->address_2) |
399 | 399 | ? $EE->CFG->organization->get_pretty('address_1') |
400 | - : $EE->CFG->organization->get_pretty('address_1') . '<br>' . $EE->CFG->organization->get_pretty( |
|
400 | + : $EE->CFG->organization->get_pretty('address_1').'<br>'.$EE->CFG->organization->get_pretty( |
|
401 | 401 | 'address_2' |
402 | 402 | ), |
403 | 403 | $EE->CFG->organization->get_pretty('city'), |
@@ -434,9 +434,9 @@ discard block |
||
434 | 434 | $find = [' ']; |
435 | 435 | $replace = ['-']; |
436 | 436 | $row_id = strtolower(str_replace($find, $replace, $text)); |
437 | - $html .= '<tr id="' . $row_id . '-tr"><td colspan="4"> </td>'; |
|
438 | - $html .= '<td class="item_r">' . $text . '</td>'; |
|
439 | - $html .= '<td class="item_r">' . $total_cost . '</td>'; |
|
437 | + $html .= '<tr id="'.$row_id.'-tr"><td colspan="4"> </td>'; |
|
438 | + $html .= '<td class="item_r">'.$text.'</td>'; |
|
439 | + $html .= '<td class="item_r">'.$total_cost.'</td>'; |
|
440 | 440 | $html .= '</tr>'; |
441 | 441 | return $html; |
442 | 442 | } |
@@ -13,89 +13,89 @@ |
||
13 | 13 | */ |
14 | 14 | class PdfAdapter |
15 | 15 | { |
16 | - /** |
|
17 | - * @var Options|null |
|
18 | - */ |
|
19 | - private $options; |
|
16 | + /** |
|
17 | + * @var Options|null |
|
18 | + */ |
|
19 | + private $options; |
|
20 | 20 | |
21 | - /** |
|
22 | - * @var string |
|
23 | - */ |
|
24 | - private $content; |
|
21 | + /** |
|
22 | + * @var string |
|
23 | + */ |
|
24 | + private $content; |
|
25 | 25 | |
26 | 26 | |
27 | - /** |
|
28 | - * PdfAdapter constructor. |
|
29 | - */ |
|
30 | - public function __construct() |
|
31 | - { |
|
32 | - $this->options = null; |
|
33 | - $this->content = ''; |
|
34 | - } |
|
27 | + /** |
|
28 | + * PdfAdapter constructor. |
|
29 | + */ |
|
30 | + public function __construct() |
|
31 | + { |
|
32 | + $this->options = null; |
|
33 | + $this->content = ''; |
|
34 | + } |
|
35 | 35 | |
36 | 36 | |
37 | - /** |
|
38 | - * @return Options|null |
|
39 | - */ |
|
40 | - public function getOptions() |
|
41 | - { |
|
42 | - // only load dompdf if nobody else has yet... |
|
43 | - if (! class_exists('Dompdf\Autoloader') and is_readable(EE_THIRD_PARTY . 'dompdf/src/Autoloader.php')) { |
|
44 | - require_once(EE_THIRD_PARTY . 'dompdf/src/Autoloader.php'); |
|
45 | - Autoloader::register(); |
|
46 | - } |
|
47 | - if (! class_exists('Dompdf\Options')) { |
|
48 | - return null; |
|
49 | - } |
|
50 | - $options = new Options(); |
|
51 | - $options->set('isRemoteEnabled', true); |
|
52 | - $options->set('isJavascriptEnabled', false); |
|
53 | - if (defined('DOMPDF_FONT_DIR')) { |
|
54 | - $options->setFontDir(DOMPDF_FONT_DIR); |
|
55 | - $options->setFontCache(DOMPDF_FONT_DIR); |
|
56 | - } |
|
57 | - // Allow changing the paper size. |
|
58 | - if (defined('DOMPDF_DEFAULT_PAPER_SIZE')) { |
|
59 | - $options->set('defaultPaperSize', DOMPDF_DEFAULT_PAPER_SIZE); |
|
60 | - } |
|
61 | - return $options; |
|
62 | - } |
|
37 | + /** |
|
38 | + * @return Options|null |
|
39 | + */ |
|
40 | + public function getOptions() |
|
41 | + { |
|
42 | + // only load dompdf if nobody else has yet... |
|
43 | + if (! class_exists('Dompdf\Autoloader') and is_readable(EE_THIRD_PARTY . 'dompdf/src/Autoloader.php')) { |
|
44 | + require_once(EE_THIRD_PARTY . 'dompdf/src/Autoloader.php'); |
|
45 | + Autoloader::register(); |
|
46 | + } |
|
47 | + if (! class_exists('Dompdf\Options')) { |
|
48 | + return null; |
|
49 | + } |
|
50 | + $options = new Options(); |
|
51 | + $options->set('isRemoteEnabled', true); |
|
52 | + $options->set('isJavascriptEnabled', false); |
|
53 | + if (defined('DOMPDF_FONT_DIR')) { |
|
54 | + $options->setFontDir(DOMPDF_FONT_DIR); |
|
55 | + $options->setFontCache(DOMPDF_FONT_DIR); |
|
56 | + } |
|
57 | + // Allow changing the paper size. |
|
58 | + if (defined('DOMPDF_DEFAULT_PAPER_SIZE')) { |
|
59 | + $options->set('defaultPaperSize', DOMPDF_DEFAULT_PAPER_SIZE); |
|
60 | + } |
|
61 | + return $options; |
|
62 | + } |
|
63 | 63 | |
64 | 64 | |
65 | - /** |
|
66 | - * @param Options $options |
|
67 | - * @return $this |
|
68 | - */ |
|
69 | - public function setOptions(Options $options): self |
|
70 | - { |
|
71 | - $this->options = $options; |
|
72 | - return $this; |
|
73 | - } |
|
65 | + /** |
|
66 | + * @param Options $options |
|
67 | + * @return $this |
|
68 | + */ |
|
69 | + public function setOptions(Options $options): self |
|
70 | + { |
|
71 | + $this->options = $options; |
|
72 | + return $this; |
|
73 | + } |
|
74 | 74 | |
75 | 75 | |
76 | - /** |
|
77 | - * @param string $content |
|
78 | - * @return $this |
|
79 | - */ |
|
80 | - public function setContent(string $content): self |
|
81 | - { |
|
82 | - $this->content = $content; |
|
83 | - return $this; |
|
84 | - } |
|
76 | + /** |
|
77 | + * @param string $content |
|
78 | + * @return $this |
|
79 | + */ |
|
80 | + public function setContent(string $content): self |
|
81 | + { |
|
82 | + $this->content = $content; |
|
83 | + return $this; |
|
84 | + } |
|
85 | 85 | |
86 | 86 | |
87 | - /** |
|
88 | - * @param string $filename |
|
89 | - * @param bool $download |
|
90 | - * @return void |
|
91 | - */ |
|
92 | - public function generate(string $filename, bool $download): void |
|
93 | - { |
|
94 | - if ($this->options instanceof Options && ! empty($this->content)) { |
|
95 | - $dompdf = new Dompdf($this->options); |
|
96 | - $dompdf->loadHtml($this->content); |
|
97 | - $dompdf->render(); |
|
98 | - $dompdf->stream($filename, ['Attachment' => $download]); |
|
99 | - } |
|
100 | - } |
|
87 | + /** |
|
88 | + * @param string $filename |
|
89 | + * @param bool $download |
|
90 | + * @return void |
|
91 | + */ |
|
92 | + public function generate(string $filename, bool $download): void |
|
93 | + { |
|
94 | + if ($this->options instanceof Options && ! empty($this->content)) { |
|
95 | + $dompdf = new Dompdf($this->options); |
|
96 | + $dompdf->loadHtml($this->content); |
|
97 | + $dompdf->render(); |
|
98 | + $dompdf->stream($filename, ['Attachment' => $download]); |
|
99 | + } |
|
100 | + } |
|
101 | 101 | } |
@@ -40,11 +40,11 @@ |
||
40 | 40 | public function getOptions() |
41 | 41 | { |
42 | 42 | // only load dompdf if nobody else has yet... |
43 | - if (! class_exists('Dompdf\Autoloader') and is_readable(EE_THIRD_PARTY . 'dompdf/src/Autoloader.php')) { |
|
44 | - require_once(EE_THIRD_PARTY . 'dompdf/src/Autoloader.php'); |
|
43 | + if ( ! class_exists('Dompdf\Autoloader') and is_readable(EE_THIRD_PARTY.'dompdf/src/Autoloader.php')) { |
|
44 | + require_once(EE_THIRD_PARTY.'dompdf/src/Autoloader.php'); |
|
45 | 45 | Autoloader::register(); |
46 | 46 | } |
47 | - if (! class_exists('Dompdf\Options')) { |
|
47 | + if ( ! class_exists('Dompdf\Options')) { |
|
48 | 48 | return null; |
49 | 49 | } |
50 | 50 | $options = new Options(); |
@@ -16,350 +16,350 @@ |
||
16 | 16 | */ |
17 | 17 | class EE_Pdf_messenger extends EE_messenger |
18 | 18 | { |
19 | - /** |
|
20 | - * The following are the properties that this messenger requires for generating pdf |
|
21 | - */ |
|
22 | - |
|
23 | - /** |
|
24 | - * This is the pdf body generated by the template via the message type. |
|
25 | - * |
|
26 | - * @var string |
|
27 | - */ |
|
28 | - protected $_content; |
|
29 | - |
|
30 | - |
|
31 | - /** |
|
32 | - * This is for the page title that gets displayed. This will end up being the filename for the generated pdf. |
|
33 | - * |
|
34 | - * @var string |
|
35 | - */ |
|
36 | - protected $_subject; |
|
37 | - |
|
38 | - /** |
|
39 | - * @var PdfAdapter |
|
40 | - */ |
|
41 | - protected $pdf_adapter; |
|
42 | - |
|
43 | - |
|
44 | - /** |
|
45 | - * EE_Pdf_messenger constructor. |
|
46 | - */ |
|
47 | - public function __construct() |
|
48 | - { |
|
49 | - // set properties |
|
50 | - $this->name = 'pdf'; |
|
51 | - $this->description = esc_html__('This messenger is used for generating a pdf version of the message.', 'event_espresso'); |
|
52 | - $this->label = array( |
|
53 | - 'singular' => esc_html__('PDF', 'event_espresso'), |
|
54 | - 'plural' => esc_html__('PDFs', 'event_espresso') |
|
55 | - ); |
|
56 | - $this->activate_on_install = true; |
|
57 | - $this->pdf_adapter = new PdfAdapter(); |
|
58 | - |
|
59 | - parent::__construct(); |
|
60 | - } |
|
61 | - |
|
62 | - |
|
63 | - /** |
|
64 | - * PDF Messenger desires execution immediately. |
|
65 | - * @see parent::send_now() for documentation. |
|
66 | - * @since 4.9.0 |
|
67 | - * @return bool |
|
68 | - */ |
|
69 | - public function send_now() |
|
70 | - { |
|
71 | - return true; |
|
72 | - } |
|
73 | - |
|
74 | - |
|
75 | - /** |
|
76 | - * HTML Messenger allows an empty to field. |
|
77 | - * @see parent::allow_empty_to_field() for documentation |
|
78 | - * @since 4.9.0 |
|
79 | - * @return bool |
|
80 | - */ |
|
81 | - public function allow_empty_to_field() |
|
82 | - { |
|
83 | - return true; |
|
84 | - } |
|
85 | - |
|
86 | - |
|
87 | - /** |
|
88 | - * @see abstract declaration in EE_messenger for details. |
|
89 | - */ |
|
90 | - protected function _set_admin_pages() |
|
91 | - { |
|
92 | - $this->admin_registered_pages = array('events_edit' => false); |
|
93 | - } |
|
94 | - |
|
95 | - |
|
96 | - /** |
|
97 | - * @see abstract declaration in EE_messenger for details. |
|
98 | - */ |
|
99 | - protected function _set_valid_shortcodes() |
|
100 | - { |
|
101 | - $this->_valid_shortcodes = array(); |
|
102 | - } |
|
103 | - |
|
104 | - |
|
105 | - /** |
|
106 | - * @see abstract declaration in EE_messenger for details. |
|
107 | - */ |
|
108 | - protected function _set_validator_config() |
|
109 | - { |
|
110 | - $this->_validator_config = array( |
|
111 | - 'subject' => array( |
|
112 | - 'shortcodes' => array('recipient_details', 'organization', 'event', 'ticket', 'venue', 'primary_registration_details', 'event_author', 'email', 'event_meta', 'recipient_list', 'transaction', 'datetime_list', 'datetime') |
|
113 | - ), |
|
114 | - 'content' => array( |
|
115 | - 'shortcodes' => array('recipient_details', 'organization', 'event', 'ticket', 'venue', 'primary_registration_details', 'event_author', 'email', 'event_meta', 'recipient_list', 'transaction', 'datetime_list', 'datetime') |
|
116 | - ), |
|
117 | - 'attendee_list' => array( |
|
118 | - 'shortcodes' => array('attendee', 'event_list', 'ticket_list'), |
|
119 | - 'required' => array('[ATTENDEE_LIST]') |
|
120 | - ), |
|
121 | - 'event_list' => array( |
|
122 | - 'shortcodes' => array('event', 'attendee_list', 'ticket_list', 'venue', 'datetime_list', 'attendee', 'primary_registration_details', 'primary_registration_list', 'event_author', 'recipient_details', 'recipient_list'), |
|
123 | - 'required' => array('[EVENT_LIST]') |
|
124 | - ), |
|
125 | - 'ticket_list' => array( |
|
126 | - 'shortcodes' => array('event_list', 'attendee_list', 'ticket', 'datetime_list', 'primary_registration_details', 'recipient_details'), |
|
127 | - 'required' => array('[TICKET_LIST]') |
|
128 | - ), |
|
129 | - 'datetime_list' => array( |
|
130 | - 'shortcodes' => array('datetime'), |
|
131 | - 'required' => array('[DATETIME_LIST]') |
|
132 | - ), |
|
133 | - ); |
|
134 | - } |
|
135 | - |
|
136 | - |
|
137 | - /** |
|
138 | - * Takes care of enqueuing any necessary scripts or styles for the page. A do_action() so message types using this messenger can add their own js. |
|
139 | - * |
|
140 | - * @return void. |
|
141 | - */ |
|
142 | - public function enqueue_scripts_styles() |
|
143 | - { |
|
144 | - parent::enqueue_scripts_styles(); |
|
145 | - do_action('AHEE__EE_Pdf_messenger__enqueue_scripts_styles'); |
|
146 | - } |
|
147 | - |
|
148 | - |
|
149 | - /** |
|
150 | - * _set_template_fields |
|
151 | - * This sets up the fields that a messenger requires for the message to go out. |
|
152 | - * |
|
153 | - * @access protected |
|
154 | - * @return void |
|
155 | - */ |
|
156 | - protected function _set_template_fields() |
|
157 | - { |
|
158 | - // any extra template fields that are NOT used by the messenger but will get used by a messenger field for shortcode replacement get added to the 'extra' key in an associated array indexed by the messenger field they relate to. This is important for the Messages_admin to know what fields to display to the user. Also, notice that the "values" are equal to the field type that messages admin will use to know what kind of field to display. The values ALSO have one index labeled "shortcode". the values in that array indicate which ACTUAL SHORTCODE (i.e. [SHORTCODE]) is required in order for this extra field to be displayed. If the required shortcode isn't part of the shortcodes array then the field is not needed and will not be displayed/parsed. |
|
159 | - $this->_template_fields = array( |
|
160 | - 'subject' => array( |
|
161 | - 'input' => 'text', |
|
162 | - 'label' => esc_html__('Page Title', 'event_espresso'), |
|
163 | - 'type' => 'string', |
|
164 | - 'required' => true, |
|
165 | - 'validation' => true, |
|
166 | - 'css_class' => 'large-text', |
|
167 | - 'format' => '%s' |
|
168 | - ), |
|
169 | - 'content' => '', // left empty b/c it is in the "extra array" but messenger still needs needs to know this is a field. |
|
170 | - 'extra' => array( |
|
171 | - 'content' => array( |
|
172 | - 'main' => array( |
|
173 | - 'input' => 'wp_editor', |
|
174 | - 'label' => esc_html__('Main Content', 'event_espresso'), |
|
175 | - 'type' => 'string', |
|
176 | - 'required' => true, |
|
177 | - 'validation' => true, |
|
178 | - 'format' => '%s', |
|
179 | - 'rows' => '15' |
|
180 | - ), |
|
181 | - 'event_list' => array( |
|
182 | - 'input' => 'wp_editor', |
|
183 | - 'label' => '[EVENT_LIST]', |
|
184 | - 'type' => 'string', |
|
185 | - 'required' => true, |
|
186 | - 'validation' => true, |
|
187 | - 'format' => '%s', |
|
188 | - 'rows' => '15', |
|
189 | - 'shortcodes_required' => array('[EVENT_LIST]') |
|
190 | - ), |
|
191 | - 'attendee_list' => array( |
|
192 | - 'input' => 'textarea', |
|
193 | - 'label' => '[ATTENDEE_LIST]', |
|
194 | - 'type' => 'string', |
|
195 | - 'required' => true, |
|
196 | - 'validation' => true, |
|
197 | - 'format' => '%s', |
|
198 | - 'css_class' => 'large-text', |
|
199 | - 'rows' => '5', |
|
200 | - 'shortcodes_required' => array('[ATTENDEE_LIST]') |
|
201 | - ), |
|
202 | - 'ticket_list' => array( |
|
203 | - 'input' => 'textarea', |
|
204 | - 'label' => '[TICKET_LIST]', |
|
205 | - 'type' => 'string', |
|
206 | - 'required' => true, |
|
207 | - 'validation' => true, |
|
208 | - 'format' => '%s', |
|
209 | - 'css_class' => 'large-text', |
|
210 | - 'rows' => '10', |
|
211 | - 'shortcodes_required' => array('[TICKET_LIST]') |
|
212 | - ), |
|
213 | - 'datetime_list' => array( |
|
214 | - 'input' => 'textarea', |
|
215 | - 'label' => '[DATETIME_LIST]', |
|
216 | - 'type' => 'string', |
|
217 | - 'required' => true, |
|
218 | - 'validation' => true, |
|
219 | - 'format' => '%s', |
|
220 | - 'css_class' => 'large-text', |
|
221 | - 'rows' => '10', |
|
222 | - 'shortcodes_required' => array('[DATETIME_LIST]') |
|
223 | - ) |
|
224 | - ) |
|
225 | - ) |
|
226 | - ); |
|
227 | - } |
|
228 | - |
|
229 | - |
|
230 | - /** |
|
231 | - * @see definition of this method in parent |
|
232 | - * |
|
233 | - * @since 4.5.0 |
|
234 | - * |
|
235 | - */ |
|
236 | - protected function _set_default_message_types() |
|
237 | - { |
|
238 | - // note currently PDF is only a secondary messenger so it never has any associated message types. |
|
239 | - $this->_default_message_types = array(); |
|
240 | - } |
|
241 | - |
|
242 | - |
|
243 | - /** |
|
244 | - * @see definition of this method in parent |
|
245 | - * |
|
246 | - * @since 4.5.0 |
|
247 | - */ |
|
248 | - protected function _set_valid_message_types() |
|
249 | - { |
|
250 | - $this->_valid_message_types = array(); |
|
251 | - } |
|
252 | - |
|
253 | - |
|
254 | - /** |
|
255 | - * Generates html version of the message content and then sends it to the pdf generator. |
|
256 | - * |
|
257 | - * |
|
258 | - * @since 4.5.0 |
|
259 | - * |
|
260 | - * @return string. |
|
261 | - */ |
|
262 | - protected function _send_message() |
|
263 | - { |
|
264 | - $this->_template_args = array( |
|
265 | - 'page_title' => $this->_subject, |
|
266 | - 'base_css' => $this->get_variation($this->_tmp_pack, $this->_incoming_message_type->name, true, 'base', $this->_variation), |
|
267 | - 'print_css' => $this->get_variation($this->_tmp_pack, $this->_incoming_message_type->name, true, 'print', $this->_variation), |
|
268 | - 'main_css' => $this->get_variation($this->_tmp_pack, $this->_incoming_message_type->name, true, 'main', $this->_variation), |
|
269 | - 'extra_css' => EE_LIBRARIES_URL . 'messages/defaults/default/variations/pdf_base_default.css', |
|
270 | - 'main_body' => apply_filters('FHEE__EE_Pdf_messenger___send_message__main_body', wpautop($this->_content), $this->_content) |
|
271 | - ); |
|
272 | - $this->_deregister_wp_hooks(); |
|
273 | - add_action('wp_enqueue_scripts', array($this, 'enqueue_scripts_styles')); |
|
274 | - $content = $this->_get_main_template(); |
|
19 | + /** |
|
20 | + * The following are the properties that this messenger requires for generating pdf |
|
21 | + */ |
|
22 | + |
|
23 | + /** |
|
24 | + * This is the pdf body generated by the template via the message type. |
|
25 | + * |
|
26 | + * @var string |
|
27 | + */ |
|
28 | + protected $_content; |
|
29 | + |
|
30 | + |
|
31 | + /** |
|
32 | + * This is for the page title that gets displayed. This will end up being the filename for the generated pdf. |
|
33 | + * |
|
34 | + * @var string |
|
35 | + */ |
|
36 | + protected $_subject; |
|
37 | + |
|
38 | + /** |
|
39 | + * @var PdfAdapter |
|
40 | + */ |
|
41 | + protected $pdf_adapter; |
|
42 | + |
|
43 | + |
|
44 | + /** |
|
45 | + * EE_Pdf_messenger constructor. |
|
46 | + */ |
|
47 | + public function __construct() |
|
48 | + { |
|
49 | + // set properties |
|
50 | + $this->name = 'pdf'; |
|
51 | + $this->description = esc_html__('This messenger is used for generating a pdf version of the message.', 'event_espresso'); |
|
52 | + $this->label = array( |
|
53 | + 'singular' => esc_html__('PDF', 'event_espresso'), |
|
54 | + 'plural' => esc_html__('PDFs', 'event_espresso') |
|
55 | + ); |
|
56 | + $this->activate_on_install = true; |
|
57 | + $this->pdf_adapter = new PdfAdapter(); |
|
58 | + |
|
59 | + parent::__construct(); |
|
60 | + } |
|
61 | + |
|
62 | + |
|
63 | + /** |
|
64 | + * PDF Messenger desires execution immediately. |
|
65 | + * @see parent::send_now() for documentation. |
|
66 | + * @since 4.9.0 |
|
67 | + * @return bool |
|
68 | + */ |
|
69 | + public function send_now() |
|
70 | + { |
|
71 | + return true; |
|
72 | + } |
|
73 | + |
|
74 | + |
|
75 | + /** |
|
76 | + * HTML Messenger allows an empty to field. |
|
77 | + * @see parent::allow_empty_to_field() for documentation |
|
78 | + * @since 4.9.0 |
|
79 | + * @return bool |
|
80 | + */ |
|
81 | + public function allow_empty_to_field() |
|
82 | + { |
|
83 | + return true; |
|
84 | + } |
|
85 | + |
|
86 | + |
|
87 | + /** |
|
88 | + * @see abstract declaration in EE_messenger for details. |
|
89 | + */ |
|
90 | + protected function _set_admin_pages() |
|
91 | + { |
|
92 | + $this->admin_registered_pages = array('events_edit' => false); |
|
93 | + } |
|
94 | + |
|
95 | + |
|
96 | + /** |
|
97 | + * @see abstract declaration in EE_messenger for details. |
|
98 | + */ |
|
99 | + protected function _set_valid_shortcodes() |
|
100 | + { |
|
101 | + $this->_valid_shortcodes = array(); |
|
102 | + } |
|
103 | + |
|
104 | + |
|
105 | + /** |
|
106 | + * @see abstract declaration in EE_messenger for details. |
|
107 | + */ |
|
108 | + protected function _set_validator_config() |
|
109 | + { |
|
110 | + $this->_validator_config = array( |
|
111 | + 'subject' => array( |
|
112 | + 'shortcodes' => array('recipient_details', 'organization', 'event', 'ticket', 'venue', 'primary_registration_details', 'event_author', 'email', 'event_meta', 'recipient_list', 'transaction', 'datetime_list', 'datetime') |
|
113 | + ), |
|
114 | + 'content' => array( |
|
115 | + 'shortcodes' => array('recipient_details', 'organization', 'event', 'ticket', 'venue', 'primary_registration_details', 'event_author', 'email', 'event_meta', 'recipient_list', 'transaction', 'datetime_list', 'datetime') |
|
116 | + ), |
|
117 | + 'attendee_list' => array( |
|
118 | + 'shortcodes' => array('attendee', 'event_list', 'ticket_list'), |
|
119 | + 'required' => array('[ATTENDEE_LIST]') |
|
120 | + ), |
|
121 | + 'event_list' => array( |
|
122 | + 'shortcodes' => array('event', 'attendee_list', 'ticket_list', 'venue', 'datetime_list', 'attendee', 'primary_registration_details', 'primary_registration_list', 'event_author', 'recipient_details', 'recipient_list'), |
|
123 | + 'required' => array('[EVENT_LIST]') |
|
124 | + ), |
|
125 | + 'ticket_list' => array( |
|
126 | + 'shortcodes' => array('event_list', 'attendee_list', 'ticket', 'datetime_list', 'primary_registration_details', 'recipient_details'), |
|
127 | + 'required' => array('[TICKET_LIST]') |
|
128 | + ), |
|
129 | + 'datetime_list' => array( |
|
130 | + 'shortcodes' => array('datetime'), |
|
131 | + 'required' => array('[DATETIME_LIST]') |
|
132 | + ), |
|
133 | + ); |
|
134 | + } |
|
135 | + |
|
136 | + |
|
137 | + /** |
|
138 | + * Takes care of enqueuing any necessary scripts or styles for the page. A do_action() so message types using this messenger can add their own js. |
|
139 | + * |
|
140 | + * @return void. |
|
141 | + */ |
|
142 | + public function enqueue_scripts_styles() |
|
143 | + { |
|
144 | + parent::enqueue_scripts_styles(); |
|
145 | + do_action('AHEE__EE_Pdf_messenger__enqueue_scripts_styles'); |
|
146 | + } |
|
147 | + |
|
148 | + |
|
149 | + /** |
|
150 | + * _set_template_fields |
|
151 | + * This sets up the fields that a messenger requires for the message to go out. |
|
152 | + * |
|
153 | + * @access protected |
|
154 | + * @return void |
|
155 | + */ |
|
156 | + protected function _set_template_fields() |
|
157 | + { |
|
158 | + // any extra template fields that are NOT used by the messenger but will get used by a messenger field for shortcode replacement get added to the 'extra' key in an associated array indexed by the messenger field they relate to. This is important for the Messages_admin to know what fields to display to the user. Also, notice that the "values" are equal to the field type that messages admin will use to know what kind of field to display. The values ALSO have one index labeled "shortcode". the values in that array indicate which ACTUAL SHORTCODE (i.e. [SHORTCODE]) is required in order for this extra field to be displayed. If the required shortcode isn't part of the shortcodes array then the field is not needed and will not be displayed/parsed. |
|
159 | + $this->_template_fields = array( |
|
160 | + 'subject' => array( |
|
161 | + 'input' => 'text', |
|
162 | + 'label' => esc_html__('Page Title', 'event_espresso'), |
|
163 | + 'type' => 'string', |
|
164 | + 'required' => true, |
|
165 | + 'validation' => true, |
|
166 | + 'css_class' => 'large-text', |
|
167 | + 'format' => '%s' |
|
168 | + ), |
|
169 | + 'content' => '', // left empty b/c it is in the "extra array" but messenger still needs needs to know this is a field. |
|
170 | + 'extra' => array( |
|
171 | + 'content' => array( |
|
172 | + 'main' => array( |
|
173 | + 'input' => 'wp_editor', |
|
174 | + 'label' => esc_html__('Main Content', 'event_espresso'), |
|
175 | + 'type' => 'string', |
|
176 | + 'required' => true, |
|
177 | + 'validation' => true, |
|
178 | + 'format' => '%s', |
|
179 | + 'rows' => '15' |
|
180 | + ), |
|
181 | + 'event_list' => array( |
|
182 | + 'input' => 'wp_editor', |
|
183 | + 'label' => '[EVENT_LIST]', |
|
184 | + 'type' => 'string', |
|
185 | + 'required' => true, |
|
186 | + 'validation' => true, |
|
187 | + 'format' => '%s', |
|
188 | + 'rows' => '15', |
|
189 | + 'shortcodes_required' => array('[EVENT_LIST]') |
|
190 | + ), |
|
191 | + 'attendee_list' => array( |
|
192 | + 'input' => 'textarea', |
|
193 | + 'label' => '[ATTENDEE_LIST]', |
|
194 | + 'type' => 'string', |
|
195 | + 'required' => true, |
|
196 | + 'validation' => true, |
|
197 | + 'format' => '%s', |
|
198 | + 'css_class' => 'large-text', |
|
199 | + 'rows' => '5', |
|
200 | + 'shortcodes_required' => array('[ATTENDEE_LIST]') |
|
201 | + ), |
|
202 | + 'ticket_list' => array( |
|
203 | + 'input' => 'textarea', |
|
204 | + 'label' => '[TICKET_LIST]', |
|
205 | + 'type' => 'string', |
|
206 | + 'required' => true, |
|
207 | + 'validation' => true, |
|
208 | + 'format' => '%s', |
|
209 | + 'css_class' => 'large-text', |
|
210 | + 'rows' => '10', |
|
211 | + 'shortcodes_required' => array('[TICKET_LIST]') |
|
212 | + ), |
|
213 | + 'datetime_list' => array( |
|
214 | + 'input' => 'textarea', |
|
215 | + 'label' => '[DATETIME_LIST]', |
|
216 | + 'type' => 'string', |
|
217 | + 'required' => true, |
|
218 | + 'validation' => true, |
|
219 | + 'format' => '%s', |
|
220 | + 'css_class' => 'large-text', |
|
221 | + 'rows' => '10', |
|
222 | + 'shortcodes_required' => array('[DATETIME_LIST]') |
|
223 | + ) |
|
224 | + ) |
|
225 | + ) |
|
226 | + ); |
|
227 | + } |
|
228 | + |
|
229 | + |
|
230 | + /** |
|
231 | + * @see definition of this method in parent |
|
232 | + * |
|
233 | + * @since 4.5.0 |
|
234 | + * |
|
235 | + */ |
|
236 | + protected function _set_default_message_types() |
|
237 | + { |
|
238 | + // note currently PDF is only a secondary messenger so it never has any associated message types. |
|
239 | + $this->_default_message_types = array(); |
|
240 | + } |
|
241 | + |
|
242 | + |
|
243 | + /** |
|
244 | + * @see definition of this method in parent |
|
245 | + * |
|
246 | + * @since 4.5.0 |
|
247 | + */ |
|
248 | + protected function _set_valid_message_types() |
|
249 | + { |
|
250 | + $this->_valid_message_types = array(); |
|
251 | + } |
|
252 | + |
|
253 | + |
|
254 | + /** |
|
255 | + * Generates html version of the message content and then sends it to the pdf generator. |
|
256 | + * |
|
257 | + * |
|
258 | + * @since 4.5.0 |
|
259 | + * |
|
260 | + * @return string. |
|
261 | + */ |
|
262 | + protected function _send_message() |
|
263 | + { |
|
264 | + $this->_template_args = array( |
|
265 | + 'page_title' => $this->_subject, |
|
266 | + 'base_css' => $this->get_variation($this->_tmp_pack, $this->_incoming_message_type->name, true, 'base', $this->_variation), |
|
267 | + 'print_css' => $this->get_variation($this->_tmp_pack, $this->_incoming_message_type->name, true, 'print', $this->_variation), |
|
268 | + 'main_css' => $this->get_variation($this->_tmp_pack, $this->_incoming_message_type->name, true, 'main', $this->_variation), |
|
269 | + 'extra_css' => EE_LIBRARIES_URL . 'messages/defaults/default/variations/pdf_base_default.css', |
|
270 | + 'main_body' => apply_filters('FHEE__EE_Pdf_messenger___send_message__main_body', wpautop($this->_content), $this->_content) |
|
271 | + ); |
|
272 | + $this->_deregister_wp_hooks(); |
|
273 | + add_action('wp_enqueue_scripts', array($this, 'enqueue_scripts_styles')); |
|
274 | + $content = $this->_get_main_template(); |
|
275 | 275 | // die( $content ); |
276 | - $this->_do_pdf($content); |
|
277 | - exit(0); |
|
278 | - } |
|
279 | - |
|
280 | - |
|
281 | - /** |
|
282 | - * The purpose of this function is to de register all actions hooked into wp_head and wp_footer so that it doesn't interfere with our templates. If users want to add any custom styles or scripts they must use the AHEE__EE_Pdf_messenger__enqueue_scripts_styles hook. |
|
283 | - * |
|
284 | - * @since 4.5.0 |
|
285 | - * |
|
286 | - * @return void |
|
287 | - */ |
|
288 | - protected function _deregister_wp_hooks() |
|
289 | - { |
|
290 | - remove_all_actions('wp_head'); |
|
291 | - remove_all_actions('wp_footer'); |
|
292 | - remove_all_actions('wp_print_footer_scripts'); |
|
293 | - remove_all_actions('wp_enqueue_scripts'); |
|
294 | - global $wp_scripts, $wp_styles; |
|
295 | - $wp_scripts = $wp_styles = array(); |
|
296 | - |
|
297 | - // just add back in wp_enqueue_scripts and wp_print_footer_scripts cause that's all we want to load. |
|
298 | - add_action('wp_head', 'wp_enqueue_scripts'); |
|
299 | - add_action('wp_footer', 'wp_print_footer_scripts'); |
|
300 | - add_action('wp_print_footer_scripts', '_wp_footer_scripts'); |
|
301 | - } |
|
302 | - |
|
303 | - |
|
304 | - /** |
|
305 | - * Overwrite parent _get_main_template for pdf purposes. |
|
306 | - * |
|
307 | - * @since 4.5.0 |
|
308 | - * |
|
309 | - * @param bool $preview |
|
310 | - * @return string |
|
311 | - */ |
|
312 | - protected function _get_main_template($preview = false) |
|
313 | - { |
|
314 | - $wrapper_template = $this->_tmp_pack->get_wrapper('html', 'main'); |
|
315 | - // add message type to template_args |
|
316 | - $this->_template_args['message_type'] = $this->_incoming_message_type; |
|
317 | - return EEH_Template::display_template($wrapper_template, $this->_template_args, true); |
|
318 | - } |
|
319 | - |
|
320 | - |
|
321 | - /** |
|
322 | - * This takes care of loading the dompdf library and generating the actual pdf |
|
323 | - * |
|
324 | - * @param string $content This is the generated html content being converted into a pdf. |
|
325 | - * |
|
326 | - * @return void |
|
327 | - */ |
|
328 | - protected function _do_pdf($content = '') |
|
329 | - { |
|
330 | - // dompdf options |
|
331 | - $options = $this->pdf_adapter->getOptions(); |
|
332 | - if ($options instanceof Options) { |
|
333 | - // Remove all spaces between HTML tags |
|
334 | - $content = preg_replace('/>\s+</', '><', $content); |
|
335 | - if ($content) { |
|
336 | - $this->pdf_adapter |
|
337 | - ->setOptions($options) |
|
338 | - ->setContent($content) |
|
339 | - // forcing the browser to open a download dialog. |
|
340 | - ->generate($this->_subject . ".pdf", true); |
|
341 | - exit; |
|
342 | - } |
|
343 | - } |
|
344 | - // display error if dompdf is not available |
|
345 | - wp_die(esc_html__( |
|
346 | - 'DomPDF package appears to be missing, so cannot generate the PDF file.', |
|
347 | - 'event_espresso' |
|
348 | - )); |
|
349 | - exit; |
|
350 | - } |
|
351 | - |
|
352 | - |
|
353 | - /** |
|
354 | - * @return string |
|
355 | - */ |
|
356 | - protected function _preview() |
|
357 | - { |
|
358 | - return $this->_send_message(); |
|
359 | - } |
|
360 | - |
|
361 | - |
|
362 | - protected function _set_admin_settings_fields() |
|
363 | - { |
|
364 | - } |
|
276 | + $this->_do_pdf($content); |
|
277 | + exit(0); |
|
278 | + } |
|
279 | + |
|
280 | + |
|
281 | + /** |
|
282 | + * The purpose of this function is to de register all actions hooked into wp_head and wp_footer so that it doesn't interfere with our templates. If users want to add any custom styles or scripts they must use the AHEE__EE_Pdf_messenger__enqueue_scripts_styles hook. |
|
283 | + * |
|
284 | + * @since 4.5.0 |
|
285 | + * |
|
286 | + * @return void |
|
287 | + */ |
|
288 | + protected function _deregister_wp_hooks() |
|
289 | + { |
|
290 | + remove_all_actions('wp_head'); |
|
291 | + remove_all_actions('wp_footer'); |
|
292 | + remove_all_actions('wp_print_footer_scripts'); |
|
293 | + remove_all_actions('wp_enqueue_scripts'); |
|
294 | + global $wp_scripts, $wp_styles; |
|
295 | + $wp_scripts = $wp_styles = array(); |
|
296 | + |
|
297 | + // just add back in wp_enqueue_scripts and wp_print_footer_scripts cause that's all we want to load. |
|
298 | + add_action('wp_head', 'wp_enqueue_scripts'); |
|
299 | + add_action('wp_footer', 'wp_print_footer_scripts'); |
|
300 | + add_action('wp_print_footer_scripts', '_wp_footer_scripts'); |
|
301 | + } |
|
302 | + |
|
303 | + |
|
304 | + /** |
|
305 | + * Overwrite parent _get_main_template for pdf purposes. |
|
306 | + * |
|
307 | + * @since 4.5.0 |
|
308 | + * |
|
309 | + * @param bool $preview |
|
310 | + * @return string |
|
311 | + */ |
|
312 | + protected function _get_main_template($preview = false) |
|
313 | + { |
|
314 | + $wrapper_template = $this->_tmp_pack->get_wrapper('html', 'main'); |
|
315 | + // add message type to template_args |
|
316 | + $this->_template_args['message_type'] = $this->_incoming_message_type; |
|
317 | + return EEH_Template::display_template($wrapper_template, $this->_template_args, true); |
|
318 | + } |
|
319 | + |
|
320 | + |
|
321 | + /** |
|
322 | + * This takes care of loading the dompdf library and generating the actual pdf |
|
323 | + * |
|
324 | + * @param string $content This is the generated html content being converted into a pdf. |
|
325 | + * |
|
326 | + * @return void |
|
327 | + */ |
|
328 | + protected function _do_pdf($content = '') |
|
329 | + { |
|
330 | + // dompdf options |
|
331 | + $options = $this->pdf_adapter->getOptions(); |
|
332 | + if ($options instanceof Options) { |
|
333 | + // Remove all spaces between HTML tags |
|
334 | + $content = preg_replace('/>\s+</', '><', $content); |
|
335 | + if ($content) { |
|
336 | + $this->pdf_adapter |
|
337 | + ->setOptions($options) |
|
338 | + ->setContent($content) |
|
339 | + // forcing the browser to open a download dialog. |
|
340 | + ->generate($this->_subject . ".pdf", true); |
|
341 | + exit; |
|
342 | + } |
|
343 | + } |
|
344 | + // display error if dompdf is not available |
|
345 | + wp_die(esc_html__( |
|
346 | + 'DomPDF package appears to be missing, so cannot generate the PDF file.', |
|
347 | + 'event_espresso' |
|
348 | + )); |
|
349 | + exit; |
|
350 | + } |
|
351 | + |
|
352 | + |
|
353 | + /** |
|
354 | + * @return string |
|
355 | + */ |
|
356 | + protected function _preview() |
|
357 | + { |
|
358 | + return $this->_send_message(); |
|
359 | + } |
|
360 | + |
|
361 | + |
|
362 | + protected function _set_admin_settings_fields() |
|
363 | + { |
|
364 | + } |
|
365 | 365 | } |
@@ -266,7 +266,7 @@ discard block |
||
266 | 266 | 'base_css' => $this->get_variation($this->_tmp_pack, $this->_incoming_message_type->name, true, 'base', $this->_variation), |
267 | 267 | 'print_css' => $this->get_variation($this->_tmp_pack, $this->_incoming_message_type->name, true, 'print', $this->_variation), |
268 | 268 | 'main_css' => $this->get_variation($this->_tmp_pack, $this->_incoming_message_type->name, true, 'main', $this->_variation), |
269 | - 'extra_css' => EE_LIBRARIES_URL . 'messages/defaults/default/variations/pdf_base_default.css', |
|
269 | + 'extra_css' => EE_LIBRARIES_URL.'messages/defaults/default/variations/pdf_base_default.css', |
|
270 | 270 | 'main_body' => apply_filters('FHEE__EE_Pdf_messenger___send_message__main_body', wpautop($this->_content), $this->_content) |
271 | 271 | ); |
272 | 272 | $this->_deregister_wp_hooks(); |
@@ -337,7 +337,7 @@ discard block |
||
337 | 337 | ->setOptions($options) |
338 | 338 | ->setContent($content) |
339 | 339 | // forcing the browser to open a download dialog. |
340 | - ->generate($this->_subject . ".pdf", true); |
|
340 | + ->generate($this->_subject.".pdf", true); |
|
341 | 341 | exit; |
342 | 342 | } |
343 | 343 | } |