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