Completed
Branch BUG-10412-mcrypt-deprecated (81a654)
by
unknown
49:46 queued 37:21
created
libraries/line_item_display/EE_SPCO_Line_Item_Display_Strategy.strategy.php 3 patches
Doc Comments   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -77,7 +77,7 @@  discard block
 block discarded – undo
77 77
      * @param EE_Line_Item $line_item
78 78
      * @param array        $options
79 79
      * @param EE_Line_Item $parent_line_item
80
-     * @return mixed
80
+     * @return string
81 81
      * @throws EE_Error
82 82
      */
83 83
     public function display_line_item(
@@ -223,7 +223,7 @@  discard block
 block discarded – undo
223 223
      * _event_row - basically a Heading row displayed once above each event's ticket rows
224 224
      *
225 225
      * @param EE_Line_Item $line_item
226
-     * @return mixed
226
+     * @return string
227 227
      */
228 228
     private function _event_row(EE_Line_Item $line_item)
229 229
     {
@@ -249,7 +249,7 @@  discard block
 block discarded – undo
249 249
      *
250 250
      * @param EE_Line_Item $line_item
251 251
      * @param array        $options
252
-     * @return mixed
252
+     * @return string
253 253
      * @throws EE_Error
254 254
      */
255 255
     private function _ticket_row(EE_Line_Item $line_item, $options = array())
@@ -303,7 +303,7 @@  discard block
 block discarded – undo
303 303
      *
304 304
      * @param EE_Line_Item $line_item
305 305
      * @param array        $options
306
-     * @return mixed
306
+     * @return string
307 307
      * @throws EE_Error
308 308
      */
309 309
     private function _item_row(EE_Line_Item $line_item, $options = array())
@@ -363,7 +363,7 @@  discard block
 block discarded – undo
363 363
      * @param EE_Line_Item $line_item
364 364
      * @param array        $options
365 365
      * @param EE_Line_Item $parent_line_item
366
-     * @return mixed
366
+     * @return string
367 367
      * @throws EE_Error
368 368
      */
369 369
     private function _sub_item_row(EE_Line_Item $line_item, $options = array(), EE_Line_Item $parent_line_item = null)
@@ -407,7 +407,7 @@  discard block
 block discarded – undo
407 407
      *
408 408
      * @param EE_Line_Item $line_item
409 409
      * @param array        $options
410
-     * @return mixed
410
+     * @return string
411 411
      * @throws EE_Error
412 412
      */
413 413
     private function _tax_row(EE_Line_Item $line_item, $options = array())
@@ -444,7 +444,7 @@  discard block
 block discarded – undo
444 444
      *
445 445
      * @param EE_Line_Item $line_item
446 446
      * @param string       $text
447
-     * @return mixed
447
+     * @return string
448 448
      * @throws EE_Error
449 449
      */
450 450
     private function _total_tax_row(EE_Line_Item $line_item, $text = '')
@@ -483,7 +483,7 @@  discard block
 block discarded – undo
483 483
      * @param EE_Line_Item $line_item
484 484
      * @param string       $text
485 485
      * @param array        $options
486
-     * @return mixed
486
+     * @return string
487 487
      * @throws EE_Error
488 488
      */
489 489
     private function _sub_total_row(EE_Line_Item $line_item, $text = '', $options = array())
@@ -519,7 +519,7 @@  discard block
 block discarded – undo
519 519
      *
520 520
      * @param EE_Line_Item $line_item
521 521
      * @param string       $text
522
-     * @return mixed
522
+     * @return string
523 523
      * @throws EE_Error
524 524
      */
525 525
     private function _total_row(EE_Line_Item $line_item, $text = '')
@@ -546,7 +546,7 @@  discard block
 block discarded – undo
546 546
      *
547 547
      * @param EE_Line_Item $line_item
548 548
      * @param array        $options
549
-     * @return mixed
549
+     * @return string
550 550
      * @throws EE_Error
551 551
      */
552 552
     private function _payments_and_amount_owing_rows(EE_Line_Item $line_item, $options = array())
Please login to merge, or discard this patch.
Indentation   +603 added lines, -603 removed lines patch added patch discarded remove patch
@@ -16,609 +16,609 @@
 block discarded – undo
16 16
 class EE_SPCO_Line_Item_Display_Strategy implements EEI_Line_Item_Display
17 17
 {
18 18
 
19
-    /**
20
-     * array of events
21
-     *
22
-     * @type EE_Line_Item[] $_events
23
-     */
24
-    private $_events = array();
25
-
26
-    /**
27
-     * whether to display the taxes row or not
28
-     *
29
-     * @type bool $_show_taxes
30
-     */
31
-    private $_show_taxes = false;
32
-
33
-    /**
34
-     * html for any tax rows
35
-     *
36
-     * @type string $_show_taxes
37
-     */
38
-    private $_taxes_html = '';
39
-
40
-    /**
41
-     * total amount including tax we can bill for at this time
42
-     *
43
-     * @type float $_grand_total
44
-     */
45
-    private $_grand_total = 0.00;
46
-
47
-    /**
48
-     * total number of items being billed for
49
-     *
50
-     * @type int $_total_items
51
-     */
52
-    private $_total_items = 0;
53
-
54
-
55
-
56
-    /**
57
-     * @return float
58
-     */
59
-    public function grand_total()
60
-    {
61
-        return $this->_grand_total;
62
-    }
63
-
64
-
65
-
66
-    /**
67
-     * @return int
68
-     */
69
-    public function total_items()
70
-    {
71
-        return $this->_total_items;
72
-    }
73
-
74
-
75
-
76
-    /**
77
-     * @param EE_Line_Item $line_item
78
-     * @param array        $options
79
-     * @param EE_Line_Item $parent_line_item
80
-     * @return mixed
81
-     * @throws EE_Error
82
-     */
83
-    public function display_line_item(
84
-        EE_Line_Item $line_item,
85
-        $options = array(),
86
-        EE_Line_Item $parent_line_item = null
87
-    ) {
88
-        $html = '';
89
-        // set some default options and merge with incoming
90
-        $default_options = array(
91
-            'show_desc' => true,  // 	true 		false
92
-            'odd'       => false,
93
-        );
94
-        $options = array_merge($default_options, (array)$options);
95
-        switch ($line_item->type()) {
96
-            case EEM_Line_Item::type_line_item:
97
-                $this->_show_taxes = $line_item->is_taxable() ? true : $this->_show_taxes;
98
-                if ($line_item->OBJ_type() === 'Ticket') {
99
-                    // item row
100
-                    $html .= $this->_ticket_row($line_item, $options);
101
-                } else {
102
-                    // item row
103
-                    $html .= $this->_item_row($line_item, $options);
104
-                }
105
-                if (
106
-                apply_filters(
107
-                    'FHEE__EE_SPCO_Line_Item_Display_Strategy__display_line_item__display_sub_line_items',
108
-                    true
109
-                )
110
-                ) {
111
-                    // got any kids?
112
-                    foreach ($line_item->children() as $child_line_item) {
113
-                        $html .= $this->display_line_item($child_line_item, $options, $line_item);
114
-                    }
115
-                }
116
-                break;
117
-            case EEM_Line_Item::type_sub_line_item:
118
-                $html .= $this->_sub_item_row($line_item, $options, $parent_line_item);
119
-                break;
120
-            case EEM_Line_Item::type_sub_total:
121
-                static $sub_total = 0;
122
-                $event_sub_total = 0;
123
-                $text = esc_html__('Sub-Total', 'event_espresso');
124
-                if ($line_item->OBJ_type() === 'Event') {
125
-                    $options['event_id'] = $event_id = $line_item->OBJ_ID();
126
-                    if (! isset($this->_events[$options['event_id']])) {
127
-                        $event = EEM_Event::instance()->get_one_by_ID($options['event_id']);
128
-                        // if event has default reg status of Not Approved, then don't display info on it
129
-                        if (
130
-                            $event instanceof EE_Event
131
-                            && $event->default_registration_status() === EEM_Registration::status_id_not_approved
132
-                        ) {
133
-                            $display_event = false;
134
-                            // unless there are registrations for it that are returning to pay
135
-                            if (isset($options['registrations']) && is_array($options['registrations'])) {
136
-                                foreach ($options['registrations'] as $registration) {
137
-                                    if (! $registration instanceof EE_Registration) {
138
-                                        continue;
139
-                                    }
140
-                                    $display_event = $registration->event_ID() === $options['event_id']
141
-                                                     && $registration->status_ID() !== EEM_Registration::status_id_not_approved
142
-                                        ? true
143
-                                        : $display_event;
144
-                                }
145
-                            }
146
-                            if (! $display_event) {
147
-                                return '';
148
-                            }
149
-                        }
150
-                        $this->_events[$options['event_id']] = 0;
151
-                        $html .= $this->_event_row($line_item);
152
-                        $text = esc_html__('Event Sub-Total', 'event_espresso');
153
-                    }
154
-                }
155
-                $child_line_items = $line_item->children();
156
-                // loop thru children
157
-                foreach ($child_line_items as $child_line_item) {
158
-                    // recursively feed children back into this method
159
-                    $html .= $this->display_line_item($child_line_item, $options, $line_item);
160
-                }
161
-                $event_sub_total += isset($options['event_id']) ? $this->_events[$options['event_id']] : 0;
162
-                $sub_total += $event_sub_total;
163
-                if (
164
-                    (
165
-                        // event subtotals
166
-                        $line_item->code() !== 'pre-tax-subtotal' && count($child_line_items) > 1
167
-                    )
168
-                    || (
169
-                        // pre-tax subtotals
170
-                        $line_item->code() === 'pre-tax-subtotal' && count($this->_events) > 1
171
-                    )
172
-                ) {
173
-                    $options['sub_total'] = $line_item->OBJ_type() === 'Event' ? $event_sub_total : $sub_total;
174
-                    $html .= $this->_sub_total_row($line_item, $text, $options);
175
-                }
176
-                break;
177
-            case EEM_Line_Item::type_tax:
178
-                if ($this->_show_taxes) {
179
-                    $this->_taxes_html .= $this->_tax_row($line_item, $options);
180
-                }
181
-                break;
182
-            case EEM_Line_Item::type_tax_sub_total:
183
-                if ($this->_show_taxes) {
184
-                    $child_line_items = $line_item->children();
185
-                    // loop thru children
186
-                    foreach ($child_line_items as $child_line_item) {
187
-                        // recursively feed children back into this method
188
-                        $html .= $this->display_line_item($child_line_item, $options, $line_item);
189
-                    }
190
-                    if (count($child_line_items) > 1) {
191
-                        $this->_taxes_html .= $this->_total_tax_row($line_item, esc_html__('Tax Total', 'event_espresso'));
192
-                    }
193
-                }
194
-                break;
195
-            case EEM_Line_Item::type_total:
196
-                // get all child line items
197
-                $children = $line_item->children();
198
-                // loop thru all non-tax child line items
199
-                foreach ($children as $child_line_item) {
200
-                    if ($child_line_item->type() !== EEM_Line_Item::type_tax_sub_total) {
201
-                        // recursively feed children back into this method
202
-                        $html .= $this->display_line_item($child_line_item, $options, $line_item);
203
-                    }
204
-                }
205
-                // now loop thru  tax child line items
206
-                foreach ($children as $child_line_item) {
207
-                    if ($child_line_item->type() === EEM_Line_Item::type_tax_sub_total) {
208
-                        // recursively feed children back into this method
209
-                        $html .= $this->display_line_item($child_line_item, $options, $line_item);
210
-                    }
211
-                }
212
-                $html .= $this->_taxes_html;
213
-                $html .= $this->_total_row($line_item, esc_html__('Total', 'event_espresso'));
214
-                $html .= $this->_payments_and_amount_owing_rows($line_item, $options);
215
-                break;
216
-        }
217
-        return $html;
218
-    }
219
-
220
-
221
-
222
-    /**
223
-     * _event_row - basically a Heading row displayed once above each event's ticket rows
224
-     *
225
-     * @param EE_Line_Item $line_item
226
-     * @return mixed
227
-     */
228
-    private function _event_row(EE_Line_Item $line_item)
229
-    {
230
-        // start of row
231
-        $html = EEH_HTML::tr('', 'event-cart-total-row', 'total_tr odd');
232
-        // event name td
233
-        $html .= EEH_HTML::td(
234
-            EEH_HTML::strong($line_item->name()),
235
-            '',
236
-            'event-header',
237
-            '',
238
-            ' colspan="4"'
239
-        );
240
-        // end of row
241
-        $html .= EEH_HTML::trx();
242
-        return $html;
243
-    }
244
-
245
-
246
-
247
-    /**
248
-     * _ticket_row
249
-     *
250
-     * @param EE_Line_Item $line_item
251
-     * @param array        $options
252
-     * @return mixed
253
-     * @throws EE_Error
254
-     */
255
-    private function _ticket_row(EE_Line_Item $line_item, $options = array())
256
-    {
257
-        // start of row
258
-        $row_class = $options['odd'] ? 'item odd' : 'item';
259
-        $html = EEH_HTML::tr('', '', $row_class);
260
-        // name && desc
261
-        $name_and_desc = apply_filters(
262
-            'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__name',
263
-            $line_item->name(),
264
-            $line_item
265
-        );
266
-        $name_and_desc .= apply_filters(
267
-            'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__desc',
268
-            (
269
-                $options['show_desc']
270
-                    ? '<span class="line-item-desc-spn smaller-text">: ' . $line_item->desc() . '</span>'
271
-                    : ''
272
-            ),
273
-            $line_item,
274
-            $options
275
-        );
276
-        $name_and_desc .= $line_item->is_taxable() ? ' * ' : '';
277
-        // name td
278
-        $html .= EEH_HTML::td( /*__FUNCTION__ .*/
279
-            $name_and_desc, '', 'item_l');
280
-        // price td
281
-        $html .= EEH_HTML::td($line_item->unit_price_no_code(), '', 'item_c jst-rght');
282
-        // quantity td
283
-        $html .= EEH_HTML::td($line_item->quantity(), '', 'item_l jst-rght');
284
-        $this->_total_items += $line_item->quantity();
285
-        // determine total for line item
286
-        $total = $line_item->total();
287
-        $this->_events[$options['event_id']] += $total;
288
-        // total td
289
-        $html .= EEH_HTML::td(
290
-            EEH_Template::format_currency($total, false, false),
291
-            '',
292
-            'item_r jst-rght'
293
-        );
294
-        // end of row
295
-        $html .= EEH_HTML::trx();
296
-        return $html;
297
-    }
298
-
299
-
300
-
301
-    /**
302
-     * _item_row
303
-     *
304
-     * @param EE_Line_Item $line_item
305
-     * @param array        $options
306
-     * @return mixed
307
-     * @throws EE_Error
308
-     */
309
-    private function _item_row(EE_Line_Item $line_item, $options = array())
310
-    {
311
-        // start of row
312
-        $row_class = $options['odd'] ? 'item odd' : 'item';
313
-        $html = EEH_HTML::tr('', '', $row_class);
314
-        $obj_name = $line_item->OBJ_type() ? $line_item->OBJ_type_i18n() . ': ' : '';
315
-        // name && desc
316
-        $name_and_desc = apply_filters(
317
-            'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__name',
318
-            $obj_name . $line_item->name(),
319
-            $line_item
320
-        );
321
-        $name_and_desc .= apply_filters(
322
-            'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__desc',
323
-            (
324
-                $options['show_desc']
325
-                ? '<span class="line-item-desc-spn smaller-text">: ' . $line_item->desc() . '</span>'
326
-                : ''
327
-            ),
328
-            $line_item,
329
-            $options
330
-        );
331
-        $name_and_desc .= $line_item->is_taxable() ? ' * ' : '';
332
-        // name td
333
-        $html .= EEH_HTML::td($name_and_desc, '', 'item_l');
334
-        // price td
335
-        if ($line_item->is_percent()) {
336
-            $html .= EEH_HTML::td($line_item->percent() . '%', '', 'item_c jst-rght');
337
-        } else {
338
-            $html .= EEH_HTML::td($line_item->unit_price_no_code(), '', 'item_c jst-rght');
339
-        }
340
-        // quantity td
341
-        $html .= EEH_HTML::td($line_item->quantity(), '', 'item_l jst-rght');
342
-        //$total = $line_item->total() * $line_item->quantity();
343
-        $total = $line_item->total();
344
-        if (isset($options['event_id'], $this->_events[$options['event_id']])) {
345
-            $this->_events[$options['event_id']] += $total;
346
-        }
347
-        // total td
348
-        $html .= EEH_HTML::td(
349
-            EEH_Template::format_currency($total, false, false),
350
-            '',
351
-            'item_r jst-rght'
352
-        );
353
-        // end of row
354
-        $html .= EEH_HTML::trx();
355
-        return $html;
356
-    }
357
-
358
-
359
-
360
-    /**
361
-     * _sub_item_row
362
-     *
363
-     * @param EE_Line_Item $line_item
364
-     * @param array        $options
365
-     * @param EE_Line_Item $parent_line_item
366
-     * @return mixed
367
-     * @throws EE_Error
368
-     */
369
-    private function _sub_item_row(EE_Line_Item $line_item, $options = array(), EE_Line_Item $parent_line_item = null)
370
-    {
371
-        // start of row
372
-        $html = EEH_HTML::tr('', '', 'item sub-item-row');
373
-        // name && desc
374
-        $name_and_desc = EEH_HTML::span('', '', 'sub-item-row-bullet dashicons dashicons-arrow-right')
375
-                         . $line_item->name();
376
-        $name_and_desc .= $options['show_desc'] ? '<span class="line-sub-item-desc-spn smaller-text">: '
377
-                                                  . $line_item->desc()
378
-                                                  . '</span>' : '';
379
-        // name td
380
-        $html .= EEH_HTML::td( $name_and_desc, '', 'item_l sub-item');
381
-        $qty = $parent_line_item instanceof EE_Line_Item ? $parent_line_item->quantity() : 1;
382
-        // discount/surcharge td
383
-        if ($line_item->is_percent()) {
384
-            $html .= EEH_HTML::td(
385
-                EEH_Template::format_currency(
386
-                    $line_item->total() / $qty,
387
-                    false, false
388
-                ),
389
-                '', 'item_c jst-rght'
390
-            );
391
-        } else {
392
-            $html .= EEH_HTML::td($line_item->unit_price_no_code(), '', 'item_c jst-rght');
393
-        }
394
-        // no quantity td
395
-        $html .= EEH_HTML::td();
396
-        // no total td
397
-        $html .= EEH_HTML::td();
398
-        // end of row
399
-        $html .= EEH_HTML::trx();
400
-        return $html;
401
-    }
402
-
403
-
404
-
405
-    /**
406
-     * _tax_row
407
-     *
408
-     * @param EE_Line_Item $line_item
409
-     * @param array        $options
410
-     * @return mixed
411
-     * @throws EE_Error
412
-     */
413
-    private function _tax_row(EE_Line_Item $line_item, $options = array())
414
-    {
415
-        // start of row
416
-        $html = EEH_HTML::tr('', 'item sub-item tax-total');
417
-        // name && desc
418
-        $name_and_desc = $line_item->name();
419
-        $name_and_desc .= '<span class="smaller-text lt-grey-text" style="margin:0 0 0 2em;">'
420
-                          . esc_html__(' * taxable items', 'event_espresso') . '</span>';
421
-        $name_and_desc .= $options['show_desc'] ? '<br/>' . $line_item->desc() : '';
422
-        // name td
423
-        $html .= EEH_HTML::td( /*__FUNCTION__ .*/
424
-            $name_and_desc, '', 'item_l sub-item');
425
-        // percent td
426
-        $html .= EEH_HTML::td($line_item->percent() . '%', '', ' jst-rght', '');
427
-        // empty td (price)
428
-        $html .= EEH_HTML::td(EEH_HTML::nbsp());
429
-        // total td
430
-        $html .= EEH_HTML::td(EEH_Template::format_currency(
431
-            $line_item->total(), false, false),
432
-            '',
433
-            'item_r jst-rght'
434
-        );
435
-        // end of row
436
-        $html .= EEH_HTML::trx();
437
-        return $html;
438
-    }
439
-
440
-
441
-
442
-    /**
443
-     * _total_row
444
-     *
445
-     * @param EE_Line_Item $line_item
446
-     * @param string       $text
447
-     * @return mixed
448
-     * @throws EE_Error
449
-     */
450
-    private function _total_tax_row(EE_Line_Item $line_item, $text = '')
451
-    {
452
-        $html = '';
453
-        if ($line_item->total()) {
454
-            // start of row
455
-            $html = EEH_HTML::tr('', '', 'total_tr odd');
456
-            // total td
457
-            $html .= EEH_HTML::td(
458
-                $text,
459
-                '',
460
-                'total_currency total jst-rght',
461
-                '',
462
-                ' colspan="2"'
463
-            );
464
-            // empty td (price)
465
-            $html .= EEH_HTML::td(EEH_HTML::nbsp());
466
-            // total td
467
-            $html .= EEH_HTML::td(
468
-                EEH_Template::format_currency($line_item->total(), false, false),
469
-                '',
470
-                'total jst-rght'
471
-            );
472
-            // end of row
473
-            $html .= EEH_HTML::trx();
474
-        }
475
-        return $html;
476
-    }
477
-
478
-
479
-
480
-    /**
481
-     * _total_row
482
-     *
483
-     * @param EE_Line_Item $line_item
484
-     * @param string       $text
485
-     * @param array        $options
486
-     * @return mixed
487
-     * @throws EE_Error
488
-     */
489
-    private function _sub_total_row(EE_Line_Item $line_item, $text = '', $options = array())
490
-    {
491
-        $html = '';
492
-        if ($line_item->total()) {
493
-            // start of row
494
-            $html = EEH_HTML::tr('', '', 'total_tr odd');
495
-            // total td
496
-            $html .= EEH_HTML::td(
497
-                $text,
498
-                '',
499
-                'total_currency total jst-rght',
500
-                '',
501
-                ' colspan="3"'
502
-            );
503
-            // total td
504
-            $html .= EEH_HTML::td(
505
-                EEH_Template::format_currency($options['sub_total'], false, false),
506
-                '',
507
-                'total jst-rght'
508
-            );
509
-            // end of row
510
-            $html .= EEH_HTML::trx();
511
-        }
512
-        return $html;
513
-    }
514
-
515
-
516
-
517
-    /**
518
-     * _total_row
519
-     *
520
-     * @param EE_Line_Item $line_item
521
-     * @param string       $text
522
-     * @return mixed
523
-     * @throws EE_Error
524
-     */
525
-    private function _total_row(EE_Line_Item $line_item, $text = '')
526
-    {
527
-        // start of row
528
-        $html = EEH_HTML::tr('', '', 'spco-grand-total total_tr odd');
529
-        // total td
530
-        $html .= EEH_HTML::td($text, '', 'total_currency total jst-rght', '', ' colspan="3"');
531
-        // total td
532
-        $html .= EEH_HTML::td(
533
-            EEH_Template::format_currency($line_item->total(), false, false),
534
-            '',
535
-            'total jst-rght'
536
-        );
537
-        // end of row
538
-        $html .= EEH_HTML::trx();
539
-        return $html;
540
-    }
541
-
542
-
543
-
544
-    /**
545
-     * _payments_and_amount_owing_rows
546
-     *
547
-     * @param EE_Line_Item $line_item
548
-     * @param array        $options
549
-     * @return mixed
550
-     * @throws EE_Error
551
-     */
552
-    private function _payments_and_amount_owing_rows(EE_Line_Item $line_item, $options = array())
553
-    {
554
-        $html = '';
555
-        $owing = $line_item->total();
556
-        $transaction = EEM_Transaction::instance()->get_one_by_ID($line_item->TXN_ID());
557
-        if ($transaction instanceof EE_Transaction) {
558
-            $registration_payments = array();
559
-            $registrations = ! empty($options['registrations'])
560
-                ? $options['registrations']
561
-                : $transaction->registrations();
562
-            foreach ($registrations as $registration) {
563
-                if ($registration instanceof EE_Registration && $registration->owes_monies_and_can_pay()) {
564
-                    $registration_payments += $registration->registration_payments();
565
-                }
566
-            }
567
-            if (! empty($registration_payments)) {
568
-                foreach ($registration_payments as $registration_payment) {
569
-                    if ($registration_payment instanceof EE_Registration_Payment) {
570
-                        $owing -= $registration_payment->amount();
571
-                        $payment = $registration_payment->payment();
572
-                        $payment_desc = '';
573
-                        if ($payment instanceof EE_Payment) {
574
-                            $payment_desc = sprintf(
575
-                                esc_html__('Payment%1$s Received: %2$s', 'event_espresso'),
576
-                                $payment->txn_id_chq_nmbr() !== ''
577
-                                    ? ' <span class="small-text">(#' . $payment->txn_id_chq_nmbr() . ')</span> '
578
-                                    : '',
579
-                                $payment->timestamp()
580
-                            );
581
-                        }
582
-                        // start of row
583
-                        $html .= EEH_HTML::tr('', '', 'total_tr odd');
584
-                        // payment desc
585
-                        $html .= EEH_HTML::td($payment_desc, '', '', '', ' colspan="3"');
586
-                        // total td
587
-                        $html .= EEH_HTML::td(
588
-                            EEH_Template::format_currency(
589
-                                $registration_payment->amount(),
590
-                                false,
591
-                                false
592
-                            ),
593
-                            '',
594
-                            'total jst-rght'
595
-                        );
596
-                        // end of row
597
-                        $html .= EEH_HTML::trx();
598
-                    }
599
-                }
600
-                if ($line_item->total()) {
601
-                    // start of row
602
-                    $html .= EEH_HTML::tr('', '', 'total_tr odd');
603
-                    // total td
604
-                    $html .= EEH_HTML::td(
605
-                        esc_html__('Amount Owing', 'event_espresso'),
606
-                        '', 'total_currency total jst-rght', '', ' colspan="3"'
607
-                    );
608
-                    // total td
609
-                    $html .= EEH_HTML::td(
610
-                        EEH_Template::format_currency($owing, false, false),
611
-                        '',
612
-                        'total jst-rght'
613
-                    );
614
-                    // end of row
615
-                    $html .= EEH_HTML::trx();
616
-                }
617
-            }
618
-        }
619
-        $this->_grand_total = $owing;
620
-        return $html;
621
-    }
19
+	/**
20
+	 * array of events
21
+	 *
22
+	 * @type EE_Line_Item[] $_events
23
+	 */
24
+	private $_events = array();
25
+
26
+	/**
27
+	 * whether to display the taxes row or not
28
+	 *
29
+	 * @type bool $_show_taxes
30
+	 */
31
+	private $_show_taxes = false;
32
+
33
+	/**
34
+	 * html for any tax rows
35
+	 *
36
+	 * @type string $_show_taxes
37
+	 */
38
+	private $_taxes_html = '';
39
+
40
+	/**
41
+	 * total amount including tax we can bill for at this time
42
+	 *
43
+	 * @type float $_grand_total
44
+	 */
45
+	private $_grand_total = 0.00;
46
+
47
+	/**
48
+	 * total number of items being billed for
49
+	 *
50
+	 * @type int $_total_items
51
+	 */
52
+	private $_total_items = 0;
53
+
54
+
55
+
56
+	/**
57
+	 * @return float
58
+	 */
59
+	public function grand_total()
60
+	{
61
+		return $this->_grand_total;
62
+	}
63
+
64
+
65
+
66
+	/**
67
+	 * @return int
68
+	 */
69
+	public function total_items()
70
+	{
71
+		return $this->_total_items;
72
+	}
73
+
74
+
75
+
76
+	/**
77
+	 * @param EE_Line_Item $line_item
78
+	 * @param array        $options
79
+	 * @param EE_Line_Item $parent_line_item
80
+	 * @return mixed
81
+	 * @throws EE_Error
82
+	 */
83
+	public function display_line_item(
84
+		EE_Line_Item $line_item,
85
+		$options = array(),
86
+		EE_Line_Item $parent_line_item = null
87
+	) {
88
+		$html = '';
89
+		// set some default options and merge with incoming
90
+		$default_options = array(
91
+			'show_desc' => true,  // 	true 		false
92
+			'odd'       => false,
93
+		);
94
+		$options = array_merge($default_options, (array)$options);
95
+		switch ($line_item->type()) {
96
+			case EEM_Line_Item::type_line_item:
97
+				$this->_show_taxes = $line_item->is_taxable() ? true : $this->_show_taxes;
98
+				if ($line_item->OBJ_type() === 'Ticket') {
99
+					// item row
100
+					$html .= $this->_ticket_row($line_item, $options);
101
+				} else {
102
+					// item row
103
+					$html .= $this->_item_row($line_item, $options);
104
+				}
105
+				if (
106
+				apply_filters(
107
+					'FHEE__EE_SPCO_Line_Item_Display_Strategy__display_line_item__display_sub_line_items',
108
+					true
109
+				)
110
+				) {
111
+					// got any kids?
112
+					foreach ($line_item->children() as $child_line_item) {
113
+						$html .= $this->display_line_item($child_line_item, $options, $line_item);
114
+					}
115
+				}
116
+				break;
117
+			case EEM_Line_Item::type_sub_line_item:
118
+				$html .= $this->_sub_item_row($line_item, $options, $parent_line_item);
119
+				break;
120
+			case EEM_Line_Item::type_sub_total:
121
+				static $sub_total = 0;
122
+				$event_sub_total = 0;
123
+				$text = esc_html__('Sub-Total', 'event_espresso');
124
+				if ($line_item->OBJ_type() === 'Event') {
125
+					$options['event_id'] = $event_id = $line_item->OBJ_ID();
126
+					if (! isset($this->_events[$options['event_id']])) {
127
+						$event = EEM_Event::instance()->get_one_by_ID($options['event_id']);
128
+						// if event has default reg status of Not Approved, then don't display info on it
129
+						if (
130
+							$event instanceof EE_Event
131
+							&& $event->default_registration_status() === EEM_Registration::status_id_not_approved
132
+						) {
133
+							$display_event = false;
134
+							// unless there are registrations for it that are returning to pay
135
+							if (isset($options['registrations']) && is_array($options['registrations'])) {
136
+								foreach ($options['registrations'] as $registration) {
137
+									if (! $registration instanceof EE_Registration) {
138
+										continue;
139
+									}
140
+									$display_event = $registration->event_ID() === $options['event_id']
141
+													 && $registration->status_ID() !== EEM_Registration::status_id_not_approved
142
+										? true
143
+										: $display_event;
144
+								}
145
+							}
146
+							if (! $display_event) {
147
+								return '';
148
+							}
149
+						}
150
+						$this->_events[$options['event_id']] = 0;
151
+						$html .= $this->_event_row($line_item);
152
+						$text = esc_html__('Event Sub-Total', 'event_espresso');
153
+					}
154
+				}
155
+				$child_line_items = $line_item->children();
156
+				// loop thru children
157
+				foreach ($child_line_items as $child_line_item) {
158
+					// recursively feed children back into this method
159
+					$html .= $this->display_line_item($child_line_item, $options, $line_item);
160
+				}
161
+				$event_sub_total += isset($options['event_id']) ? $this->_events[$options['event_id']] : 0;
162
+				$sub_total += $event_sub_total;
163
+				if (
164
+					(
165
+						// event subtotals
166
+						$line_item->code() !== 'pre-tax-subtotal' && count($child_line_items) > 1
167
+					)
168
+					|| (
169
+						// pre-tax subtotals
170
+						$line_item->code() === 'pre-tax-subtotal' && count($this->_events) > 1
171
+					)
172
+				) {
173
+					$options['sub_total'] = $line_item->OBJ_type() === 'Event' ? $event_sub_total : $sub_total;
174
+					$html .= $this->_sub_total_row($line_item, $text, $options);
175
+				}
176
+				break;
177
+			case EEM_Line_Item::type_tax:
178
+				if ($this->_show_taxes) {
179
+					$this->_taxes_html .= $this->_tax_row($line_item, $options);
180
+				}
181
+				break;
182
+			case EEM_Line_Item::type_tax_sub_total:
183
+				if ($this->_show_taxes) {
184
+					$child_line_items = $line_item->children();
185
+					// loop thru children
186
+					foreach ($child_line_items as $child_line_item) {
187
+						// recursively feed children back into this method
188
+						$html .= $this->display_line_item($child_line_item, $options, $line_item);
189
+					}
190
+					if (count($child_line_items) > 1) {
191
+						$this->_taxes_html .= $this->_total_tax_row($line_item, esc_html__('Tax Total', 'event_espresso'));
192
+					}
193
+				}
194
+				break;
195
+			case EEM_Line_Item::type_total:
196
+				// get all child line items
197
+				$children = $line_item->children();
198
+				// loop thru all non-tax child line items
199
+				foreach ($children as $child_line_item) {
200
+					if ($child_line_item->type() !== EEM_Line_Item::type_tax_sub_total) {
201
+						// recursively feed children back into this method
202
+						$html .= $this->display_line_item($child_line_item, $options, $line_item);
203
+					}
204
+				}
205
+				// now loop thru  tax child line items
206
+				foreach ($children as $child_line_item) {
207
+					if ($child_line_item->type() === EEM_Line_Item::type_tax_sub_total) {
208
+						// recursively feed children back into this method
209
+						$html .= $this->display_line_item($child_line_item, $options, $line_item);
210
+					}
211
+				}
212
+				$html .= $this->_taxes_html;
213
+				$html .= $this->_total_row($line_item, esc_html__('Total', 'event_espresso'));
214
+				$html .= $this->_payments_and_amount_owing_rows($line_item, $options);
215
+				break;
216
+		}
217
+		return $html;
218
+	}
219
+
220
+
221
+
222
+	/**
223
+	 * _event_row - basically a Heading row displayed once above each event's ticket rows
224
+	 *
225
+	 * @param EE_Line_Item $line_item
226
+	 * @return mixed
227
+	 */
228
+	private function _event_row(EE_Line_Item $line_item)
229
+	{
230
+		// start of row
231
+		$html = EEH_HTML::tr('', 'event-cart-total-row', 'total_tr odd');
232
+		// event name td
233
+		$html .= EEH_HTML::td(
234
+			EEH_HTML::strong($line_item->name()),
235
+			'',
236
+			'event-header',
237
+			'',
238
+			' colspan="4"'
239
+		);
240
+		// end of row
241
+		$html .= EEH_HTML::trx();
242
+		return $html;
243
+	}
244
+
245
+
246
+
247
+	/**
248
+	 * _ticket_row
249
+	 *
250
+	 * @param EE_Line_Item $line_item
251
+	 * @param array        $options
252
+	 * @return mixed
253
+	 * @throws EE_Error
254
+	 */
255
+	private function _ticket_row(EE_Line_Item $line_item, $options = array())
256
+	{
257
+		// start of row
258
+		$row_class = $options['odd'] ? 'item odd' : 'item';
259
+		$html = EEH_HTML::tr('', '', $row_class);
260
+		// name && desc
261
+		$name_and_desc = apply_filters(
262
+			'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__name',
263
+			$line_item->name(),
264
+			$line_item
265
+		);
266
+		$name_and_desc .= apply_filters(
267
+			'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__desc',
268
+			(
269
+				$options['show_desc']
270
+					? '<span class="line-item-desc-spn smaller-text">: ' . $line_item->desc() . '</span>'
271
+					: ''
272
+			),
273
+			$line_item,
274
+			$options
275
+		);
276
+		$name_and_desc .= $line_item->is_taxable() ? ' * ' : '';
277
+		// name td
278
+		$html .= EEH_HTML::td( /*__FUNCTION__ .*/
279
+			$name_and_desc, '', 'item_l');
280
+		// price td
281
+		$html .= EEH_HTML::td($line_item->unit_price_no_code(), '', 'item_c jst-rght');
282
+		// quantity td
283
+		$html .= EEH_HTML::td($line_item->quantity(), '', 'item_l jst-rght');
284
+		$this->_total_items += $line_item->quantity();
285
+		// determine total for line item
286
+		$total = $line_item->total();
287
+		$this->_events[$options['event_id']] += $total;
288
+		// total td
289
+		$html .= EEH_HTML::td(
290
+			EEH_Template::format_currency($total, false, false),
291
+			'',
292
+			'item_r jst-rght'
293
+		);
294
+		// end of row
295
+		$html .= EEH_HTML::trx();
296
+		return $html;
297
+	}
298
+
299
+
300
+
301
+	/**
302
+	 * _item_row
303
+	 *
304
+	 * @param EE_Line_Item $line_item
305
+	 * @param array        $options
306
+	 * @return mixed
307
+	 * @throws EE_Error
308
+	 */
309
+	private function _item_row(EE_Line_Item $line_item, $options = array())
310
+	{
311
+		// start of row
312
+		$row_class = $options['odd'] ? 'item odd' : 'item';
313
+		$html = EEH_HTML::tr('', '', $row_class);
314
+		$obj_name = $line_item->OBJ_type() ? $line_item->OBJ_type_i18n() . ': ' : '';
315
+		// name && desc
316
+		$name_and_desc = apply_filters(
317
+			'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__name',
318
+			$obj_name . $line_item->name(),
319
+			$line_item
320
+		);
321
+		$name_and_desc .= apply_filters(
322
+			'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__desc',
323
+			(
324
+				$options['show_desc']
325
+				? '<span class="line-item-desc-spn smaller-text">: ' . $line_item->desc() . '</span>'
326
+				: ''
327
+			),
328
+			$line_item,
329
+			$options
330
+		);
331
+		$name_and_desc .= $line_item->is_taxable() ? ' * ' : '';
332
+		// name td
333
+		$html .= EEH_HTML::td($name_and_desc, '', 'item_l');
334
+		// price td
335
+		if ($line_item->is_percent()) {
336
+			$html .= EEH_HTML::td($line_item->percent() . '%', '', 'item_c jst-rght');
337
+		} else {
338
+			$html .= EEH_HTML::td($line_item->unit_price_no_code(), '', 'item_c jst-rght');
339
+		}
340
+		// quantity td
341
+		$html .= EEH_HTML::td($line_item->quantity(), '', 'item_l jst-rght');
342
+		//$total = $line_item->total() * $line_item->quantity();
343
+		$total = $line_item->total();
344
+		if (isset($options['event_id'], $this->_events[$options['event_id']])) {
345
+			$this->_events[$options['event_id']] += $total;
346
+		}
347
+		// total td
348
+		$html .= EEH_HTML::td(
349
+			EEH_Template::format_currency($total, false, false),
350
+			'',
351
+			'item_r jst-rght'
352
+		);
353
+		// end of row
354
+		$html .= EEH_HTML::trx();
355
+		return $html;
356
+	}
357
+
358
+
359
+
360
+	/**
361
+	 * _sub_item_row
362
+	 *
363
+	 * @param EE_Line_Item $line_item
364
+	 * @param array        $options
365
+	 * @param EE_Line_Item $parent_line_item
366
+	 * @return mixed
367
+	 * @throws EE_Error
368
+	 */
369
+	private function _sub_item_row(EE_Line_Item $line_item, $options = array(), EE_Line_Item $parent_line_item = null)
370
+	{
371
+		// start of row
372
+		$html = EEH_HTML::tr('', '', 'item sub-item-row');
373
+		// name && desc
374
+		$name_and_desc = EEH_HTML::span('', '', 'sub-item-row-bullet dashicons dashicons-arrow-right')
375
+						 . $line_item->name();
376
+		$name_and_desc .= $options['show_desc'] ? '<span class="line-sub-item-desc-spn smaller-text">: '
377
+												  . $line_item->desc()
378
+												  . '</span>' : '';
379
+		// name td
380
+		$html .= EEH_HTML::td( $name_and_desc, '', 'item_l sub-item');
381
+		$qty = $parent_line_item instanceof EE_Line_Item ? $parent_line_item->quantity() : 1;
382
+		// discount/surcharge td
383
+		if ($line_item->is_percent()) {
384
+			$html .= EEH_HTML::td(
385
+				EEH_Template::format_currency(
386
+					$line_item->total() / $qty,
387
+					false, false
388
+				),
389
+				'', 'item_c jst-rght'
390
+			);
391
+		} else {
392
+			$html .= EEH_HTML::td($line_item->unit_price_no_code(), '', 'item_c jst-rght');
393
+		}
394
+		// no quantity td
395
+		$html .= EEH_HTML::td();
396
+		// no total td
397
+		$html .= EEH_HTML::td();
398
+		// end of row
399
+		$html .= EEH_HTML::trx();
400
+		return $html;
401
+	}
402
+
403
+
404
+
405
+	/**
406
+	 * _tax_row
407
+	 *
408
+	 * @param EE_Line_Item $line_item
409
+	 * @param array        $options
410
+	 * @return mixed
411
+	 * @throws EE_Error
412
+	 */
413
+	private function _tax_row(EE_Line_Item $line_item, $options = array())
414
+	{
415
+		// start of row
416
+		$html = EEH_HTML::tr('', 'item sub-item tax-total');
417
+		// name && desc
418
+		$name_and_desc = $line_item->name();
419
+		$name_and_desc .= '<span class="smaller-text lt-grey-text" style="margin:0 0 0 2em;">'
420
+						  . esc_html__(' * taxable items', 'event_espresso') . '</span>';
421
+		$name_and_desc .= $options['show_desc'] ? '<br/>' . $line_item->desc() : '';
422
+		// name td
423
+		$html .= EEH_HTML::td( /*__FUNCTION__ .*/
424
+			$name_and_desc, '', 'item_l sub-item');
425
+		// percent td
426
+		$html .= EEH_HTML::td($line_item->percent() . '%', '', ' jst-rght', '');
427
+		// empty td (price)
428
+		$html .= EEH_HTML::td(EEH_HTML::nbsp());
429
+		// total td
430
+		$html .= EEH_HTML::td(EEH_Template::format_currency(
431
+			$line_item->total(), false, false),
432
+			'',
433
+			'item_r jst-rght'
434
+		);
435
+		// end of row
436
+		$html .= EEH_HTML::trx();
437
+		return $html;
438
+	}
439
+
440
+
441
+
442
+	/**
443
+	 * _total_row
444
+	 *
445
+	 * @param EE_Line_Item $line_item
446
+	 * @param string       $text
447
+	 * @return mixed
448
+	 * @throws EE_Error
449
+	 */
450
+	private function _total_tax_row(EE_Line_Item $line_item, $text = '')
451
+	{
452
+		$html = '';
453
+		if ($line_item->total()) {
454
+			// start of row
455
+			$html = EEH_HTML::tr('', '', 'total_tr odd');
456
+			// total td
457
+			$html .= EEH_HTML::td(
458
+				$text,
459
+				'',
460
+				'total_currency total jst-rght',
461
+				'',
462
+				' colspan="2"'
463
+			);
464
+			// empty td (price)
465
+			$html .= EEH_HTML::td(EEH_HTML::nbsp());
466
+			// total td
467
+			$html .= EEH_HTML::td(
468
+				EEH_Template::format_currency($line_item->total(), false, false),
469
+				'',
470
+				'total jst-rght'
471
+			);
472
+			// end of row
473
+			$html .= EEH_HTML::trx();
474
+		}
475
+		return $html;
476
+	}
477
+
478
+
479
+
480
+	/**
481
+	 * _total_row
482
+	 *
483
+	 * @param EE_Line_Item $line_item
484
+	 * @param string       $text
485
+	 * @param array        $options
486
+	 * @return mixed
487
+	 * @throws EE_Error
488
+	 */
489
+	private function _sub_total_row(EE_Line_Item $line_item, $text = '', $options = array())
490
+	{
491
+		$html = '';
492
+		if ($line_item->total()) {
493
+			// start of row
494
+			$html = EEH_HTML::tr('', '', 'total_tr odd');
495
+			// total td
496
+			$html .= EEH_HTML::td(
497
+				$text,
498
+				'',
499
+				'total_currency total jst-rght',
500
+				'',
501
+				' colspan="3"'
502
+			);
503
+			// total td
504
+			$html .= EEH_HTML::td(
505
+				EEH_Template::format_currency($options['sub_total'], false, false),
506
+				'',
507
+				'total jst-rght'
508
+			);
509
+			// end of row
510
+			$html .= EEH_HTML::trx();
511
+		}
512
+		return $html;
513
+	}
514
+
515
+
516
+
517
+	/**
518
+	 * _total_row
519
+	 *
520
+	 * @param EE_Line_Item $line_item
521
+	 * @param string       $text
522
+	 * @return mixed
523
+	 * @throws EE_Error
524
+	 */
525
+	private function _total_row(EE_Line_Item $line_item, $text = '')
526
+	{
527
+		// start of row
528
+		$html = EEH_HTML::tr('', '', 'spco-grand-total total_tr odd');
529
+		// total td
530
+		$html .= EEH_HTML::td($text, '', 'total_currency total jst-rght', '', ' colspan="3"');
531
+		// total td
532
+		$html .= EEH_HTML::td(
533
+			EEH_Template::format_currency($line_item->total(), false, false),
534
+			'',
535
+			'total jst-rght'
536
+		);
537
+		// end of row
538
+		$html .= EEH_HTML::trx();
539
+		return $html;
540
+	}
541
+
542
+
543
+
544
+	/**
545
+	 * _payments_and_amount_owing_rows
546
+	 *
547
+	 * @param EE_Line_Item $line_item
548
+	 * @param array        $options
549
+	 * @return mixed
550
+	 * @throws EE_Error
551
+	 */
552
+	private function _payments_and_amount_owing_rows(EE_Line_Item $line_item, $options = array())
553
+	{
554
+		$html = '';
555
+		$owing = $line_item->total();
556
+		$transaction = EEM_Transaction::instance()->get_one_by_ID($line_item->TXN_ID());
557
+		if ($transaction instanceof EE_Transaction) {
558
+			$registration_payments = array();
559
+			$registrations = ! empty($options['registrations'])
560
+				? $options['registrations']
561
+				: $transaction->registrations();
562
+			foreach ($registrations as $registration) {
563
+				if ($registration instanceof EE_Registration && $registration->owes_monies_and_can_pay()) {
564
+					$registration_payments += $registration->registration_payments();
565
+				}
566
+			}
567
+			if (! empty($registration_payments)) {
568
+				foreach ($registration_payments as $registration_payment) {
569
+					if ($registration_payment instanceof EE_Registration_Payment) {
570
+						$owing -= $registration_payment->amount();
571
+						$payment = $registration_payment->payment();
572
+						$payment_desc = '';
573
+						if ($payment instanceof EE_Payment) {
574
+							$payment_desc = sprintf(
575
+								esc_html__('Payment%1$s Received: %2$s', 'event_espresso'),
576
+								$payment->txn_id_chq_nmbr() !== ''
577
+									? ' <span class="small-text">(#' . $payment->txn_id_chq_nmbr() . ')</span> '
578
+									: '',
579
+								$payment->timestamp()
580
+							);
581
+						}
582
+						// start of row
583
+						$html .= EEH_HTML::tr('', '', 'total_tr odd');
584
+						// payment desc
585
+						$html .= EEH_HTML::td($payment_desc, '', '', '', ' colspan="3"');
586
+						// total td
587
+						$html .= EEH_HTML::td(
588
+							EEH_Template::format_currency(
589
+								$registration_payment->amount(),
590
+								false,
591
+								false
592
+							),
593
+							'',
594
+							'total jst-rght'
595
+						);
596
+						// end of row
597
+						$html .= EEH_HTML::trx();
598
+					}
599
+				}
600
+				if ($line_item->total()) {
601
+					// start of row
602
+					$html .= EEH_HTML::tr('', '', 'total_tr odd');
603
+					// total td
604
+					$html .= EEH_HTML::td(
605
+						esc_html__('Amount Owing', 'event_espresso'),
606
+						'', 'total_currency total jst-rght', '', ' colspan="3"'
607
+					);
608
+					// total td
609
+					$html .= EEH_HTML::td(
610
+						EEH_Template::format_currency($owing, false, false),
611
+						'',
612
+						'total jst-rght'
613
+					);
614
+					// end of row
615
+					$html .= EEH_HTML::trx();
616
+				}
617
+			}
618
+		}
619
+		$this->_grand_total = $owing;
620
+		return $html;
621
+	}
622 622
 
623 623
 
624 624
 }
Please login to merge, or discard this patch.
Spacing   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -88,10 +88,10 @@  discard block
 block discarded – undo
88 88
         $html = '';
89 89
         // set some default options and merge with incoming
90 90
         $default_options = array(
91
-            'show_desc' => true,  // 	true 		false
91
+            'show_desc' => true, // 	true 		false
92 92
             'odd'       => false,
93 93
         );
94
-        $options = array_merge($default_options, (array)$options);
94
+        $options = array_merge($default_options, (array) $options);
95 95
         switch ($line_item->type()) {
96 96
             case EEM_Line_Item::type_line_item:
97 97
                 $this->_show_taxes = $line_item->is_taxable() ? true : $this->_show_taxes;
@@ -123,7 +123,7 @@  discard block
 block discarded – undo
123 123
                 $text = esc_html__('Sub-Total', 'event_espresso');
124 124
                 if ($line_item->OBJ_type() === 'Event') {
125 125
                     $options['event_id'] = $event_id = $line_item->OBJ_ID();
126
-                    if (! isset($this->_events[$options['event_id']])) {
126
+                    if ( ! isset($this->_events[$options['event_id']])) {
127 127
                         $event = EEM_Event::instance()->get_one_by_ID($options['event_id']);
128 128
                         // if event has default reg status of Not Approved, then don't display info on it
129 129
                         if (
@@ -134,7 +134,7 @@  discard block
 block discarded – undo
134 134
                             // unless there are registrations for it that are returning to pay
135 135
                             if (isset($options['registrations']) && is_array($options['registrations'])) {
136 136
                                 foreach ($options['registrations'] as $registration) {
137
-                                    if (! $registration instanceof EE_Registration) {
137
+                                    if ( ! $registration instanceof EE_Registration) {
138 138
                                         continue;
139 139
                                     }
140 140
                                     $display_event = $registration->event_ID() === $options['event_id']
@@ -143,7 +143,7 @@  discard block
 block discarded – undo
143 143
                                         : $display_event;
144 144
                                 }
145 145
                             }
146
-                            if (! $display_event) {
146
+                            if ( ! $display_event) {
147 147
                                 return '';
148 148
                             }
149 149
                         }
@@ -267,7 +267,7 @@  discard block
 block discarded – undo
267 267
             'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__desc',
268 268
             (
269 269
                 $options['show_desc']
270
-                    ? '<span class="line-item-desc-spn smaller-text">: ' . $line_item->desc() . '</span>'
270
+                    ? '<span class="line-item-desc-spn smaller-text">: '.$line_item->desc().'</span>'
271 271
                     : ''
272 272
             ),
273 273
             $line_item,
@@ -311,18 +311,18 @@  discard block
 block discarded – undo
311 311
         // start of row
312 312
         $row_class = $options['odd'] ? 'item odd' : 'item';
313 313
         $html = EEH_HTML::tr('', '', $row_class);
314
-        $obj_name = $line_item->OBJ_type() ? $line_item->OBJ_type_i18n() . ': ' : '';
314
+        $obj_name = $line_item->OBJ_type() ? $line_item->OBJ_type_i18n().': ' : '';
315 315
         // name && desc
316 316
         $name_and_desc = apply_filters(
317 317
             'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__name',
318
-            $obj_name . $line_item->name(),
318
+            $obj_name.$line_item->name(),
319 319
             $line_item
320 320
         );
321 321
         $name_and_desc .= apply_filters(
322 322
             'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__desc',
323 323
             (
324 324
                 $options['show_desc']
325
-                ? '<span class="line-item-desc-spn smaller-text">: ' . $line_item->desc() . '</span>'
325
+                ? '<span class="line-item-desc-spn smaller-text">: '.$line_item->desc().'</span>'
326 326
                 : ''
327 327
             ),
328 328
             $line_item,
@@ -333,7 +333,7 @@  discard block
 block discarded – undo
333 333
         $html .= EEH_HTML::td($name_and_desc, '', 'item_l');
334 334
         // price td
335 335
         if ($line_item->is_percent()) {
336
-            $html .= EEH_HTML::td($line_item->percent() . '%', '', 'item_c jst-rght');
336
+            $html .= EEH_HTML::td($line_item->percent().'%', '', 'item_c jst-rght');
337 337
         } else {
338 338
             $html .= EEH_HTML::td($line_item->unit_price_no_code(), '', 'item_c jst-rght');
339 339
         }
@@ -377,7 +377,7 @@  discard block
 block discarded – undo
377 377
                                                   . $line_item->desc()
378 378
                                                   . '</span>' : '';
379 379
         // name td
380
-        $html .= EEH_HTML::td( $name_and_desc, '', 'item_l sub-item');
380
+        $html .= EEH_HTML::td($name_and_desc, '', 'item_l sub-item');
381 381
         $qty = $parent_line_item instanceof EE_Line_Item ? $parent_line_item->quantity() : 1;
382 382
         // discount/surcharge td
383 383
         if ($line_item->is_percent()) {
@@ -417,13 +417,13 @@  discard block
 block discarded – undo
417 417
         // name && desc
418 418
         $name_and_desc = $line_item->name();
419 419
         $name_and_desc .= '<span class="smaller-text lt-grey-text" style="margin:0 0 0 2em;">'
420
-                          . esc_html__(' * taxable items', 'event_espresso') . '</span>';
421
-        $name_and_desc .= $options['show_desc'] ? '<br/>' . $line_item->desc() : '';
420
+                          . esc_html__(' * taxable items', 'event_espresso').'</span>';
421
+        $name_and_desc .= $options['show_desc'] ? '<br/>'.$line_item->desc() : '';
422 422
         // name td
423 423
         $html .= EEH_HTML::td( /*__FUNCTION__ .*/
424 424
             $name_and_desc, '', 'item_l sub-item');
425 425
         // percent td
426
-        $html .= EEH_HTML::td($line_item->percent() . '%', '', ' jst-rght', '');
426
+        $html .= EEH_HTML::td($line_item->percent().'%', '', ' jst-rght', '');
427 427
         // empty td (price)
428 428
         $html .= EEH_HTML::td(EEH_HTML::nbsp());
429 429
         // total td
@@ -564,7 +564,7 @@  discard block
 block discarded – undo
564 564
                     $registration_payments += $registration->registration_payments();
565 565
                 }
566 566
             }
567
-            if (! empty($registration_payments)) {
567
+            if ( ! empty($registration_payments)) {
568 568
                 foreach ($registration_payments as $registration_payment) {
569 569
                     if ($registration_payment instanceof EE_Registration_Payment) {
570 570
                         $owing -= $registration_payment->amount();
@@ -574,7 +574,7 @@  discard block
 block discarded – undo
574 574
                             $payment_desc = sprintf(
575 575
                                 esc_html__('Payment%1$s Received: %2$s', 'event_espresso'),
576 576
                                 $payment->txn_id_chq_nmbr() !== ''
577
-                                    ? ' <span class="small-text">(#' . $payment->txn_id_chq_nmbr() . ')</span> '
577
+                                    ? ' <span class="small-text">(#'.$payment->txn_id_chq_nmbr().')</span> '
578 578
                                     : '',
579 579
                                 $payment->timestamp()
580 580
                             );
Please login to merge, or discard this patch.
core/libraries/line_item_filters/EE_Non_Zero_Line_Item_Filter.class.php 2 patches
Indentation   +97 added lines, -97 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 if (! defined('EVENT_ESPRESSO_VERSION')) {
3
-    exit('No direct script access allowed');
3
+	exit('No direct script access allowed');
4 4
 }
5 5
 
6 6
 
@@ -19,102 +19,102 @@  discard block
 block discarded – undo
19 19
 class EE_Non_Zero_Line_Item_Filter extends EE_Line_Item_Filter_Base
20 20
 {
21 21
 
22
-    /**
23
-     * EE_Non_Zero_Line_Item_Filter constructor.
24
-     */
25
-    public function __construct()
26
-    {
27
-    }
28
-
29
-
30
-
31
-    /**
32
-     * Creates a duplicate of the line item tree, except only includes billable items
33
-     * and the portion of line items attributed to billable things
34
-     *
35
-     * @param EEI_Line_Item $line_item
36
-     * @return EEI_Line_Item
37
-     */
38
-    public function process(EEI_Line_Item $line_item)
39
-    {
40
-        $non_zero_line_item = $this->_filter_zero_line_item($line_item);
41
-        if (! $non_zero_line_item instanceof EEI_Line_Item) {
42
-            return null;
43
-        }
44
-        //if this is an event subtotal, we want to only include it if it
45
-        //has a non-zero total and at least one ticket line item child
46
-        if ($line_item->children()) {
47
-            $ticket_or_subtotals_with_tkt_children_count = 0;
48
-            foreach ($line_item->children() as $child_line_item) {
49
-                $code = $child_line_item->code();
50
-                $child_line_item = $this->process($child_line_item);
51
-                if (! $child_line_item instanceof EEI_Line_Item) {
52
-                    $line_item->delete_child_line_item($code);
53
-                    continue;
54
-                }
55
-                if (
56
-                    (
57
-                        $child_line_item instanceof EEI_Line_Item
58
-                        && $child_line_item->type() === EEM_Line_Item::type_sub_total
59
-                    )
60
-                    || (
61
-                        $child_line_item instanceof EEI_Line_Item
62
-                        && $child_line_item->type() === EEM_Line_Item::type_line_item
63
-                        && $child_line_item->OBJ_type() === 'Ticket'
64
-                    )
65
-                ) {
66
-                    $ticket_or_subtotals_with_tkt_children_count++;
67
-                }
68
-            }
69
-            // if this is an event subtotal with NO ticket children
70
-            // we basically want to ignore it
71
-            return $this->_filter_zero_subtotal_line_item($non_zero_line_item,
72
-                $ticket_or_subtotals_with_tkt_children_count);
73
-        }
74
-        return $non_zero_line_item;
75
-    }
76
-
77
-
78
-
79
-    /**
80
-     * Creates a new, unsaved line item, but if it's a ticket line item
81
-     * with a total of 0, or a subtotal of 0, returns null instead
82
-     *
83
-     * @param EEI_Line_Item $line_item
84
-     * @return EEI_Line_Item
85
-     */
86
-    protected function _filter_zero_line_item(EEI_Line_Item $line_item)
87
-    {
88
-        if (
89
-            $line_item->type() === EEM_Line_Item::type_line_item
90
-            && $line_item->OBJ_type() === 'Ticket'
91
-            && (int)$line_item->quantity() === 0
92
-        ) {
93
-            return null;
94
-        }
95
-        return $line_item;
96
-    }
97
-
98
-
99
-
100
-    /**
101
-     * Creates a new, unsaved line item, but if it's a ticket line item
102
-     * with a total of 0, or a subtotal of 0, returns null instead
103
-     *
104
-     * @param EEI_Line_Item $line_item
105
-     * @param int           $ticket_children
106
-     * @return EEI_Line_Item
107
-     */
108
-    protected function _filter_zero_subtotal_line_item(EEI_Line_Item $line_item, $ticket_children = 0)
109
-    {
110
-        if (
111
-            (int)$ticket_children === 0
112
-            && $line_item->type() === EEM_Line_Item::type_sub_total
113
-        ) {
114
-            return null;
115
-        }
116
-        return $line_item;
117
-    }
22
+	/**
23
+	 * EE_Non_Zero_Line_Item_Filter constructor.
24
+	 */
25
+	public function __construct()
26
+	{
27
+	}
28
+
29
+
30
+
31
+	/**
32
+	 * Creates a duplicate of the line item tree, except only includes billable items
33
+	 * and the portion of line items attributed to billable things
34
+	 *
35
+	 * @param EEI_Line_Item $line_item
36
+	 * @return EEI_Line_Item
37
+	 */
38
+	public function process(EEI_Line_Item $line_item)
39
+	{
40
+		$non_zero_line_item = $this->_filter_zero_line_item($line_item);
41
+		if (! $non_zero_line_item instanceof EEI_Line_Item) {
42
+			return null;
43
+		}
44
+		//if this is an event subtotal, we want to only include it if it
45
+		//has a non-zero total and at least one ticket line item child
46
+		if ($line_item->children()) {
47
+			$ticket_or_subtotals_with_tkt_children_count = 0;
48
+			foreach ($line_item->children() as $child_line_item) {
49
+				$code = $child_line_item->code();
50
+				$child_line_item = $this->process($child_line_item);
51
+				if (! $child_line_item instanceof EEI_Line_Item) {
52
+					$line_item->delete_child_line_item($code);
53
+					continue;
54
+				}
55
+				if (
56
+					(
57
+						$child_line_item instanceof EEI_Line_Item
58
+						&& $child_line_item->type() === EEM_Line_Item::type_sub_total
59
+					)
60
+					|| (
61
+						$child_line_item instanceof EEI_Line_Item
62
+						&& $child_line_item->type() === EEM_Line_Item::type_line_item
63
+						&& $child_line_item->OBJ_type() === 'Ticket'
64
+					)
65
+				) {
66
+					$ticket_or_subtotals_with_tkt_children_count++;
67
+				}
68
+			}
69
+			// if this is an event subtotal with NO ticket children
70
+			// we basically want to ignore it
71
+			return $this->_filter_zero_subtotal_line_item($non_zero_line_item,
72
+				$ticket_or_subtotals_with_tkt_children_count);
73
+		}
74
+		return $non_zero_line_item;
75
+	}
76
+
77
+
78
+
79
+	/**
80
+	 * Creates a new, unsaved line item, but if it's a ticket line item
81
+	 * with a total of 0, or a subtotal of 0, returns null instead
82
+	 *
83
+	 * @param EEI_Line_Item $line_item
84
+	 * @return EEI_Line_Item
85
+	 */
86
+	protected function _filter_zero_line_item(EEI_Line_Item $line_item)
87
+	{
88
+		if (
89
+			$line_item->type() === EEM_Line_Item::type_line_item
90
+			&& $line_item->OBJ_type() === 'Ticket'
91
+			&& (int)$line_item->quantity() === 0
92
+		) {
93
+			return null;
94
+		}
95
+		return $line_item;
96
+	}
97
+
98
+
99
+
100
+	/**
101
+	 * Creates a new, unsaved line item, but if it's a ticket line item
102
+	 * with a total of 0, or a subtotal of 0, returns null instead
103
+	 *
104
+	 * @param EEI_Line_Item $line_item
105
+	 * @param int           $ticket_children
106
+	 * @return EEI_Line_Item
107
+	 */
108
+	protected function _filter_zero_subtotal_line_item(EEI_Line_Item $line_item, $ticket_children = 0)
109
+	{
110
+		if (
111
+			(int)$ticket_children === 0
112
+			&& $line_item->type() === EEM_Line_Item::type_sub_total
113
+		) {
114
+			return null;
115
+		}
116
+		return $line_item;
117
+	}
118 118
 
119 119
 
120 120
 
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if (! defined('EVENT_ESPRESSO_VERSION')) {
2
+if ( ! defined('EVENT_ESPRESSO_VERSION')) {
3 3
     exit('No direct script access allowed');
4 4
 }
5 5
 
@@ -38,7 +38,7 @@  discard block
 block discarded – undo
38 38
     public function process(EEI_Line_Item $line_item)
39 39
     {
40 40
         $non_zero_line_item = $this->_filter_zero_line_item($line_item);
41
-        if (! $non_zero_line_item instanceof EEI_Line_Item) {
41
+        if ( ! $non_zero_line_item instanceof EEI_Line_Item) {
42 42
             return null;
43 43
         }
44 44
         //if this is an event subtotal, we want to only include it if it
@@ -48,7 +48,7 @@  discard block
 block discarded – undo
48 48
             foreach ($line_item->children() as $child_line_item) {
49 49
                 $code = $child_line_item->code();
50 50
                 $child_line_item = $this->process($child_line_item);
51
-                if (! $child_line_item instanceof EEI_Line_Item) {
51
+                if ( ! $child_line_item instanceof EEI_Line_Item) {
52 52
                     $line_item->delete_child_line_item($code);
53 53
                     continue;
54 54
                 }
@@ -88,7 +88,7 @@  discard block
 block discarded – undo
88 88
         if (
89 89
             $line_item->type() === EEM_Line_Item::type_line_item
90 90
             && $line_item->OBJ_type() === 'Ticket'
91
-            && (int)$line_item->quantity() === 0
91
+            && (int) $line_item->quantity() === 0
92 92
         ) {
93 93
             return null;
94 94
         }
@@ -108,7 +108,7 @@  discard block
 block discarded – undo
108 108
     protected function _filter_zero_subtotal_line_item(EEI_Line_Item $line_item, $ticket_children = 0)
109 109
     {
110 110
         if (
111
-            (int)$ticket_children === 0
111
+            (int) $ticket_children === 0
112 112
             && $line_item->type() === EEM_Line_Item::type_sub_total
113 113
         ) {
114 114
             return null;
Please login to merge, or discard this patch.
line_item_filters/EE_Specific_Registrations_Line_Item_Filter.class.php 2 patches
Indentation   +187 added lines, -187 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 if (! defined('EVENT_ESPRESSO_VERSION')) {
3
-    exit('No direct script access allowed');
3
+	exit('No direct script access allowed');
4 4
 }
5 5
 
6 6
 
@@ -18,192 +18,192 @@  discard block
 block discarded – undo
18 18
 class EE_Specific_Registrations_Line_Item_Filter extends EE_Line_Item_Filter_Base
19 19
 {
20 20
 
21
-    /**
22
-     * array of line item codes and their corresponding quantities for registrations
23
-     *
24
-     * @type array $_line_item_registrations
25
-     */
26
-    protected $_line_item_registrations = array();
27
-
28
-    /**
29
-     * Just kept in case we want it someday. Currently unused
30
-     *
31
-     * @var EE_Registration[]
32
-     */
33
-    protected $_registrations = array();
34
-
35
-    /**
36
-     * @var EE_Registration
37
-     */
38
-    protected $_current_registration;
39
-
40
-    /**
41
-     * these reg statuses should NOT increment the line item quantity
42
-     *
43
-     * @var array
44
-     */
45
-    protected $_closed_reg_statuses = array();
46
-
47
-
48
-
49
-    /**
50
-     * EE_Billable_Line_Item_Filter constructor.
51
-     *
52
-     * @param EE_Registration[] $registrations
53
-     * @throws EE_Error
54
-     */
55
-    public function __construct($registrations)
56
-    {
57
-        $this->_registrations = $registrations;
58
-        $this->_calculate_registrations_per_line_item_code($registrations);
59
-        // these reg statuses should NOT increment the line item quantity
60
-        $this->_closed_reg_statuses = EEM_Registration::closed_reg_statuses();
61
-    }
62
-
63
-
64
-
65
-    /**
66
-     * sets the _line_item_registrations from the provided registrations
67
-     *
68
-     * @param EE_Registration[] $registrations
69
-     * @return void
70
-     * @throws EE_Error
71
-     */
72
-    protected function _calculate_registrations_per_line_item_code($registrations)
73
-    {
74
-        foreach ($registrations as $registration) {
75
-            $line_item_code = EEM_Line_Item::instance()->get_var(
76
-                EEM_Line_Item::instance()->line_item_for_registration_query_params(
77
-                    $registration,
78
-                    array('limit' => 1)
79
-                ),
80
-                'LIN_code'
81
-            );
82
-            if ($line_item_code) {
83
-                if (! isset($this->_line_item_registrations[$line_item_code])) {
84
-                    $this->_line_item_registrations[$line_item_code] = array();
85
-                }
86
-                $this->_line_item_registrations[$line_item_code][$registration->ID()] = $registration;
87
-            }
88
-        }
89
-    }
90
-
91
-
92
-
93
-    /**
94
-     * Creates a duplicate of the line item tree, except only includes billable items
95
-     * and the portion of line items attributed to billable things
96
-     *
97
-     * @param EEI_Line_Item $line_item
98
-     * @return EEI_Line_Item
99
-     * @throws EE_Error
100
-     */
101
-    public function process(EEI_Line_Item $line_item)
102
-    {
103
-        $this->_adjust_line_item_quantity($line_item);
104
-        if (! $line_item->children()) {
105
-            return $line_item;
106
-        }
107
-        //the original running total (taking ALL tickets into account)
108
-        $running_total_of_children = 0;
109
-        //the new running total (only taking the specified ticket quantities into account)
110
-        $running_total_of_children_under_consideration = 0;
111
-        // let's also track the quantity of tickets that pertain to the registrations
112
-        $total_child_ticket_quantity = 0;
113
-        foreach ($line_item->children() as $child_line_item) {
114
-            $original_li_total = $child_line_item->is_percent()
115
-                ? $running_total_of_children * $child_line_item->percent() / 100
116
-                : $child_line_item->unit_price() * $child_line_item->quantity();
117
-            $this->process($child_line_item);
118
-            // If this line item is a normal line item that isn't for a ticket,
119
-            // we want to modify its total (and unit price if not a percentage line item)
120
-            // so it reflects only that portion of the surcharge/discount shared by these registrations
121
-            if (
122
-                $child_line_item->type() === EEM_Line_Item::type_line_item
123
-                && $child_line_item->OBJ_type() !== 'Ticket'
124
-            ) {
125
-                $percent_of_running_total = $running_total_of_children
126
-                    ? $original_li_total / $running_total_of_children
127
-                    : 0;
128
-                $child_line_item->set_total(
129
-                    $running_total_of_children_under_consideration * $percent_of_running_total
130
-                );
131
-                if (! $child_line_item->is_percent()) {
132
-                    $child_line_item->set_unit_price($child_line_item->total() / $child_line_item->quantity());
133
-                }
134
-            } else if (
135
-                //make sure this item's quantity and total matches its parent
136
-                $line_item->type() === EEM_Line_Item::type_line_item
137
-                && $line_item->OBJ_type() === 'Ticket'
138
-                // but not if it's a percentage modifier
139
-                && ! $child_line_item->is_percent()
140
-                && ! (
141
-                    // or a cancellation
142
-                    $child_line_item->is_cancelled()
143
-                    && ! (
144
-                        // unless it IS a cancellation and the current registration is cancelled
145
-                        $child_line_item->is_cancelled()
146
-                        && $this->_current_registration instanceof EE_Registration
147
-                        && in_array($this->_current_registration->status_ID(), $this->_closed_reg_statuses, true)
148
-                    )
149
-                )
150
-            ) {
151
-                $child_line_item->set_quantity($line_item->quantity());
152
-                $child_line_item->set_total($child_line_item->unit_price() * $child_line_item->quantity());
153
-            }
154
-            $running_total_of_children += $original_li_total;
155
-            $running_total_of_children_under_consideration += $child_line_item->total();
156
-            if ($child_line_item->OBJ_type() === 'Ticket') {
157
-                $total_child_ticket_quantity += $child_line_item->quantity();
158
-            }
159
-        }
160
-        $line_item->set_total($running_total_of_children_under_consideration);
161
-        if ($line_item->quantity()) {
162
-            $line_item->set_unit_price($running_total_of_children_under_consideration / $line_item->quantity());
163
-        } else {
164
-            $line_item->set_unit_price(0);
165
-        }
166
-        if ($line_item->OBJ_type() === 'Event') {
167
-            $line_item->set_quantity($total_child_ticket_quantity);
168
-        }
169
-        return $line_item;
170
-    }
171
-
172
-
173
-
174
-    /**
175
-     * Adjusts quantities for line items for tickets according to the registrations provided
176
-     * in the constructor
177
-     *
178
-     * @param EEI_Line_Item $line_item
179
-     * @return EEI_Line_Item
180
-     */
181
-    protected function _adjust_line_item_quantity(EEI_Line_Item $line_item)
182
-    {
183
-        // is this a ticket ?
184
-        if ($line_item->type() === EEM_Line_Item::type_line_item && $line_item->OBJ_type() === 'Ticket') {
185
-            $this->_current_registration = null;
186
-            $quantity = 0;
187
-            // if this ticket is billable at this moment, then we should have a positive quantity
188
-            if (
189
-                isset($this->_line_item_registrations[$line_item->code()])
190
-                && is_array($this->_line_item_registrations[$line_item->code()])
191
-            ) {
192
-                // set quantity based on number of open registrations for this ticket
193
-                foreach ($this->_line_item_registrations[$line_item->code()] as $registration) {
194
-                    if (
195
-                        $registration instanceof EE_Registration
196
-                    ) {
197
-                        $quantity++;
198
-                        $this->_current_registration = $registration;
199
-                    }
200
-                }
201
-            }
202
-            $line_item->set_quantity($quantity);
203
-            $line_item->set_total($line_item->unit_price() * $line_item->quantity());
204
-        }
205
-        return $line_item;
206
-    }
21
+	/**
22
+	 * array of line item codes and their corresponding quantities for registrations
23
+	 *
24
+	 * @type array $_line_item_registrations
25
+	 */
26
+	protected $_line_item_registrations = array();
27
+
28
+	/**
29
+	 * Just kept in case we want it someday. Currently unused
30
+	 *
31
+	 * @var EE_Registration[]
32
+	 */
33
+	protected $_registrations = array();
34
+
35
+	/**
36
+	 * @var EE_Registration
37
+	 */
38
+	protected $_current_registration;
39
+
40
+	/**
41
+	 * these reg statuses should NOT increment the line item quantity
42
+	 *
43
+	 * @var array
44
+	 */
45
+	protected $_closed_reg_statuses = array();
46
+
47
+
48
+
49
+	/**
50
+	 * EE_Billable_Line_Item_Filter constructor.
51
+	 *
52
+	 * @param EE_Registration[] $registrations
53
+	 * @throws EE_Error
54
+	 */
55
+	public function __construct($registrations)
56
+	{
57
+		$this->_registrations = $registrations;
58
+		$this->_calculate_registrations_per_line_item_code($registrations);
59
+		// these reg statuses should NOT increment the line item quantity
60
+		$this->_closed_reg_statuses = EEM_Registration::closed_reg_statuses();
61
+	}
62
+
63
+
64
+
65
+	/**
66
+	 * sets the _line_item_registrations from the provided registrations
67
+	 *
68
+	 * @param EE_Registration[] $registrations
69
+	 * @return void
70
+	 * @throws EE_Error
71
+	 */
72
+	protected function _calculate_registrations_per_line_item_code($registrations)
73
+	{
74
+		foreach ($registrations as $registration) {
75
+			$line_item_code = EEM_Line_Item::instance()->get_var(
76
+				EEM_Line_Item::instance()->line_item_for_registration_query_params(
77
+					$registration,
78
+					array('limit' => 1)
79
+				),
80
+				'LIN_code'
81
+			);
82
+			if ($line_item_code) {
83
+				if (! isset($this->_line_item_registrations[$line_item_code])) {
84
+					$this->_line_item_registrations[$line_item_code] = array();
85
+				}
86
+				$this->_line_item_registrations[$line_item_code][$registration->ID()] = $registration;
87
+			}
88
+		}
89
+	}
90
+
91
+
92
+
93
+	/**
94
+	 * Creates a duplicate of the line item tree, except only includes billable items
95
+	 * and the portion of line items attributed to billable things
96
+	 *
97
+	 * @param EEI_Line_Item $line_item
98
+	 * @return EEI_Line_Item
99
+	 * @throws EE_Error
100
+	 */
101
+	public function process(EEI_Line_Item $line_item)
102
+	{
103
+		$this->_adjust_line_item_quantity($line_item);
104
+		if (! $line_item->children()) {
105
+			return $line_item;
106
+		}
107
+		//the original running total (taking ALL tickets into account)
108
+		$running_total_of_children = 0;
109
+		//the new running total (only taking the specified ticket quantities into account)
110
+		$running_total_of_children_under_consideration = 0;
111
+		// let's also track the quantity of tickets that pertain to the registrations
112
+		$total_child_ticket_quantity = 0;
113
+		foreach ($line_item->children() as $child_line_item) {
114
+			$original_li_total = $child_line_item->is_percent()
115
+				? $running_total_of_children * $child_line_item->percent() / 100
116
+				: $child_line_item->unit_price() * $child_line_item->quantity();
117
+			$this->process($child_line_item);
118
+			// If this line item is a normal line item that isn't for a ticket,
119
+			// we want to modify its total (and unit price if not a percentage line item)
120
+			// so it reflects only that portion of the surcharge/discount shared by these registrations
121
+			if (
122
+				$child_line_item->type() === EEM_Line_Item::type_line_item
123
+				&& $child_line_item->OBJ_type() !== 'Ticket'
124
+			) {
125
+				$percent_of_running_total = $running_total_of_children
126
+					? $original_li_total / $running_total_of_children
127
+					: 0;
128
+				$child_line_item->set_total(
129
+					$running_total_of_children_under_consideration * $percent_of_running_total
130
+				);
131
+				if (! $child_line_item->is_percent()) {
132
+					$child_line_item->set_unit_price($child_line_item->total() / $child_line_item->quantity());
133
+				}
134
+			} else if (
135
+				//make sure this item's quantity and total matches its parent
136
+				$line_item->type() === EEM_Line_Item::type_line_item
137
+				&& $line_item->OBJ_type() === 'Ticket'
138
+				// but not if it's a percentage modifier
139
+				&& ! $child_line_item->is_percent()
140
+				&& ! (
141
+					// or a cancellation
142
+					$child_line_item->is_cancelled()
143
+					&& ! (
144
+						// unless it IS a cancellation and the current registration is cancelled
145
+						$child_line_item->is_cancelled()
146
+						&& $this->_current_registration instanceof EE_Registration
147
+						&& in_array($this->_current_registration->status_ID(), $this->_closed_reg_statuses, true)
148
+					)
149
+				)
150
+			) {
151
+				$child_line_item->set_quantity($line_item->quantity());
152
+				$child_line_item->set_total($child_line_item->unit_price() * $child_line_item->quantity());
153
+			}
154
+			$running_total_of_children += $original_li_total;
155
+			$running_total_of_children_under_consideration += $child_line_item->total();
156
+			if ($child_line_item->OBJ_type() === 'Ticket') {
157
+				$total_child_ticket_quantity += $child_line_item->quantity();
158
+			}
159
+		}
160
+		$line_item->set_total($running_total_of_children_under_consideration);
161
+		if ($line_item->quantity()) {
162
+			$line_item->set_unit_price($running_total_of_children_under_consideration / $line_item->quantity());
163
+		} else {
164
+			$line_item->set_unit_price(0);
165
+		}
166
+		if ($line_item->OBJ_type() === 'Event') {
167
+			$line_item->set_quantity($total_child_ticket_quantity);
168
+		}
169
+		return $line_item;
170
+	}
171
+
172
+
173
+
174
+	/**
175
+	 * Adjusts quantities for line items for tickets according to the registrations provided
176
+	 * in the constructor
177
+	 *
178
+	 * @param EEI_Line_Item $line_item
179
+	 * @return EEI_Line_Item
180
+	 */
181
+	protected function _adjust_line_item_quantity(EEI_Line_Item $line_item)
182
+	{
183
+		// is this a ticket ?
184
+		if ($line_item->type() === EEM_Line_Item::type_line_item && $line_item->OBJ_type() === 'Ticket') {
185
+			$this->_current_registration = null;
186
+			$quantity = 0;
187
+			// if this ticket is billable at this moment, then we should have a positive quantity
188
+			if (
189
+				isset($this->_line_item_registrations[$line_item->code()])
190
+				&& is_array($this->_line_item_registrations[$line_item->code()])
191
+			) {
192
+				// set quantity based on number of open registrations for this ticket
193
+				foreach ($this->_line_item_registrations[$line_item->code()] as $registration) {
194
+					if (
195
+						$registration instanceof EE_Registration
196
+					) {
197
+						$quantity++;
198
+						$this->_current_registration = $registration;
199
+					}
200
+				}
201
+			}
202
+			$line_item->set_quantity($quantity);
203
+			$line_item->set_total($line_item->unit_price() * $line_item->quantity());
204
+		}
205
+		return $line_item;
206
+	}
207 207
 
208 208
 
209 209
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if (! defined('EVENT_ESPRESSO_VERSION')) {
2
+if ( ! defined('EVENT_ESPRESSO_VERSION')) {
3 3
     exit('No direct script access allowed');
4 4
 }
5 5
 
@@ -80,7 +80,7 @@  discard block
 block discarded – undo
80 80
                 'LIN_code'
81 81
             );
82 82
             if ($line_item_code) {
83
-                if (! isset($this->_line_item_registrations[$line_item_code])) {
83
+                if ( ! isset($this->_line_item_registrations[$line_item_code])) {
84 84
                     $this->_line_item_registrations[$line_item_code] = array();
85 85
                 }
86 86
                 $this->_line_item_registrations[$line_item_code][$registration->ID()] = $registration;
@@ -101,7 +101,7 @@  discard block
 block discarded – undo
101 101
     public function process(EEI_Line_Item $line_item)
102 102
     {
103 103
         $this->_adjust_line_item_quantity($line_item);
104
-        if (! $line_item->children()) {
104
+        if ( ! $line_item->children()) {
105 105
             return $line_item;
106 106
         }
107 107
         //the original running total (taking ALL tickets into account)
@@ -128,7 +128,7 @@  discard block
 block discarded – undo
128 128
                 $child_line_item->set_total(
129 129
                     $running_total_of_children_under_consideration * $percent_of_running_total
130 130
                 );
131
-                if (! $child_line_item->is_percent()) {
131
+                if ( ! $child_line_item->is_percent()) {
132 132
                     $child_line_item->set_unit_price($child_line_item->total() / $child_line_item->quantity());
133 133
                 }
134 134
             } else if (
Please login to merge, or discard this patch.
core/EE_Encryption.core.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -396,7 +396,7 @@
 block discarded – undo
396 396
 
397 397
     /**
398 398
      * @see http://stackoverflow.com/questions/2556345/detect-base64-encoding-in-php#30231906
399
-     * @param $string
399
+     * @param string $string
400 400
      * @return bool
401 401
      */
402 402
     protected function valid_base_64($string)
Please login to merge, or discard this patch.
Indentation   +501 added lines, -501 removed lines patch added patch discarded remove patch
@@ -16,507 +16,507 @@
 block discarded – undo
16 16
 class EE_Encryption
17 17
 {
18 18
 
19
-    /**
20
-     * key used for saving the encryption key to the wp_options table
21
-     */
22
-    const ENCRYPTION_OPTION_KEY = 'ee_encryption_key';
23
-
24
-    /**
25
-     * the OPENSSL cipher method used
26
-     */
27
-    const OPENSSL_CIPHER_METHOD = 'aes-256-ctr';
28
-
29
-    /**
30
-     * the OPENSSL digest method used
31
-     */
32
-    const OPENSSL_DIGEST_METHOD = 'sha512';
33
-
34
-    /**
35
-     * separates the encrypted text from the initialization vector
36
-     */
37
-    const OPENSSL_IV_DELIMITER = ':iv:';
38
-
39
-
40
-
41
-    /**
42
-     * instance of the EE_Encryption object
43
-     */
44
-    protected static $_instance;
45
-
46
-    /**
47
-     * @var string $_encryption_key
48
-     */
49
-    protected $_encryption_key;
50
-
51
-    /**
52
-     * @var boolean $_use_openssl_encrypt
53
-     */
54
-    protected $_use_openssl_encrypt = false;
55
-
56
-    /**
57
-     * @var boolean $_use_mcrypt
58
-     */
59
-    protected $_use_mcrypt = false;
60
-
61
-    /**
62
-     * @var boolean $_use_base64_encode
63
-     */
64
-    protected $_use_base64_encode = false;
65
-
66
-
67
-
68
-    /**
69
-     * protected constructor to prevent direct creation
70
-     */
71
-    protected function __construct()
72
-    {
73
-        if (! defined('ESPRESSO_ENCRYPT')) {
74
-            define('ESPRESSO_ENCRYPT', true);
75
-        }
76
-        if (function_exists('openssl_encrypt')) {
77
-            $this->_use_openssl_encrypt = true;
78
-        } else if (function_exists('mcrypt_encrypt')) {
79
-            $this->_use_mcrypt = true;
80
-        }
81
-        if (function_exists('base64_encode')) {
82
-            $this->_use_base64_encode = true;
83
-        }
84
-    }
85
-
86
-
87
-
88
-    /**
89
-     * singleton method used to instantiate class object
90
-     *
91
-     * @return EE_Encryption
92
-     */
93
-    public static function instance()
94
-    {
95
-        // check if class object is instantiated
96
-        if (! self::$_instance instanceof EE_Encryption) {
97
-            self::$_instance = new self();
98
-        }
99
-        return self::$_instance;
100
-    }
101
-
102
-
103
-
104
-    /**
105
-     * get encryption key
106
-     *
107
-     * @return string
108
-     */
109
-    public function get_encryption_key()
110
-    {
111
-        // if encryption key has not been set
112
-        if (empty($this->_encryption_key)) {
113
-            // retrieve encryption_key from db
114
-            $this->_encryption_key = get_option(EE_Encryption::ENCRYPTION_OPTION_KEY, '');
115
-            // WHAT?? No encryption_key in the db ??
116
-            if ($this->_encryption_key === '') {
117
-                // let's make one. And md5 it to make it just the right size for a key
118
-                $new_key = md5($this->generate_random_string());
119
-                // now save it to the db for later
120
-                add_option(EE_Encryption::ENCRYPTION_OPTION_KEY, $new_key);
121
-                // here's the key - FINALLY !
122
-                $this->_encryption_key = $new_key;
123
-            }
124
-        }
125
-        return $this->_encryption_key;
126
-    }
127
-
128
-
129
-
130
-    /**
131
-     * encrypts data
132
-     *
133
-     * @param string $text_string - the text to be encrypted
134
-     * @return string
135
-     * @throws RuntimeException
136
-     */
137
-    public function encrypt($text_string = '')
138
-    {
139
-        // you give me nothing??? GET OUT !
140
-        if (empty($text_string)) {
141
-            return $text_string;
142
-        }
143
-        if ($this->_use_openssl_encrypt) {
144
-            $encrypted_text = $this->openssl_encrypt($text_string);
145
-        } else {
146
-            $encrypted_text = $this->acme_encrypt($text_string);
147
-        }
148
-        return $encrypted_text;
149
-    }
150
-
151
-
152
-
153
-    /**
154
-     * decrypts data
155
-     *
156
-     * @param string $encrypted_text - the text to be decrypted
157
-     * @return string
158
-     * @throws RuntimeException
159
-     */
160
-    public function decrypt($encrypted_text = '')
161
-    {
162
-        // you give me nothing??? GET OUT !
163
-        if (empty($encrypted_text)) {
164
-            return $encrypted_text;
165
-        }
166
-        // if PHP's mcrypt functions are installed then we'll use them
167
-        if ($this->_use_openssl_encrypt) {
168
-            $decrypted_text = $this->openssl_decrypt($encrypted_text);
169
-        } else if ($this->_use_mcrypt) {
170
-            $decrypted_text = $this->m_decrypt($encrypted_text);
171
-        } else {
172
-            $decrypted_text = $this->acme_decrypt($encrypted_text);
173
-        }
174
-        return $decrypted_text;
175
-    }
176
-
177
-
178
-
179
-    /**
180
-     * encodes string with PHP's base64 encoding
181
-     *
182
-     * @see http://php.net/manual/en/function.base64-encode.php
183
-     * @param string $text_string the text to be encoded
184
-     * @return string
185
-     */
186
-    public function base64_string_encode($text_string = '')
187
-    {
188
-        // you give me nothing??? GET OUT !
189
-        if (empty($text_string) || ! $this->_use_base64_encode) {
190
-            return $text_string;
191
-        }
192
-        // encode
193
-        return base64_encode($text_string);
194
-    }
195
-
196
-
197
-
198
-    /**
199
-     * decodes string that has been encoded with PHP's base64 encoding
200
-     *
201
-     * @see http://php.net/manual/en/function.base64-encode.php
202
-     * @param string $encoded_string the text to be decoded
203
-     * @return string
204
-     */
205
-    public function base64_string_decode($encoded_string = '')
206
-    {
207
-        // you give me nothing??? GET OUT !
208
-        if (empty($encoded_string) || ! $this->valid_base_64($encoded_string)) {
209
-            return $encoded_string;
210
-        }
211
-        // decode
212
-        return base64_decode($encoded_string);
213
-    }
214
-
215
-
216
-
217
-    /**
218
-     * encodes  url string with PHP's base64 encoding
219
-     *
220
-     * @see http://php.net/manual/en/function.base64-encode.php
221
-     * @param string $text_string the text to be encoded
222
-     * @return string
223
-     */
224
-    public function base64_url_encode($text_string = '')
225
-    {
226
-        // you give me nothing??? GET OUT !
227
-        if (empty($text_string) || ! $this->_use_base64_encode) {
228
-            return $text_string;
229
-        }
230
-        // encode
231
-        $encoded_string = base64_encode($text_string);
232
-        // remove chars to make encoding more URL friendly
233
-        return strtr($encoded_string, '+/=', '-_,');
234
-    }
235
-
236
-
237
-
238
-    /**
239
-     * decodes  url string that has been encoded with PHP's base64 encoding
240
-     *
241
-     * @see http://php.net/manual/en/function.base64-encode.php
242
-     * @param string $encoded_string the text to be decoded
243
-     * @return string
244
-     */
245
-    public function base64_url_decode($encoded_string = '')
246
-    {
247
-        // you give me nothing??? GET OUT !
248
-        if (empty($encoded_string) || ! $this->valid_base_64($encoded_string)) {
249
-            return $encoded_string;
250
-        }
251
-        // replace previously removed characters
252
-        $encoded_string = strtr($encoded_string, '-_,', '+/=');
253
-        // decode
254
-        return base64_decode($encoded_string);
255
-    }
256
-
257
-
258
-
259
-    /**
260
-     * encrypts data using PHP's openssl functions
261
-     *
262
-     * @param string $text_string the text to be encrypted
263
-     * @return string
264
-     * @throws RuntimeException
265
-     */
266
-    protected function openssl_encrypt($text_string = '')
267
-    {
268
-        // you give me nothing??? GET OUT !
269
-        if (empty($text_string)) {
270
-            return $text_string;
271
-        }
272
-        // get initialization vector size
273
-        $iv_size = openssl_cipher_iv_length(EE_Encryption::OPENSSL_CIPHER_METHOD);
274
-        // generate initialization vector
275
-        $iv = openssl_random_pseudo_bytes($iv_size, $is_strong);
276
-        if ($iv === false || $is_strong === false) {
277
-            throw new RuntimeException(
278
-                esc_html__('Failed to generate OpenSSL initialization vector.', 'event_espresso')
279
-            );
280
-        }
281
-        // encrypt it
282
-        $encrypted_text = openssl_encrypt(
283
-            $text_string,
284
-            EE_Encryption::OPENSSL_CIPHER_METHOD,
285
-            openssl_digest($this->get_encryption_key(), EE_Encryption::OPENSSL_DIGEST_METHOD),
286
-            0,
287
-            $iv
288
-        );
289
-        // append the initialization vector
290
-        $encrypted_text .= EE_Encryption::OPENSSL_IV_DELIMITER . $iv;
291
-        // trim and maybe encode
292
-        return $this->_use_base64_encode
293
-            ? trim(base64_encode($encrypted_text))
294
-            : trim($encrypted_text);
295
-    }
296
-
297
-
298
-
299
-    /**
300
-     * decrypts data that has been encrypted with PHP's openssl functions
301
-     *
302
-     * @param string $encrypted_text the text to be decrypted
303
-     * @return string
304
-     * @throws RuntimeException
305
-     */
306
-    protected function openssl_decrypt($encrypted_text = '')
307
-    {
308
-        // you give me nothing??? GET OUT !
309
-        if (empty($encrypted_text)) {
310
-            return $encrypted_text;
311
-        }
312
-        // decode
313
-        $encrypted_text = $this->valid_base_64($encrypted_text)
314
-            ? base64_decode($encrypted_text)
315
-            : $encrypted_text;
316
-        $encrypted_components = explode(
317
-            EE_Encryption::OPENSSL_IV_DELIMITER,
318
-            $encrypted_text,
319
-            2
320
-        );
321
-        // check that iv exists, and if not, maybe text was encoded using mcrypt?
322
-        if (! isset($encrypted_components[1]) && $this->_use_mcrypt) {
323
-            return $this->m_decrypt($encrypted_text);
324
-        }
325
-        // decrypt it
326
-        $decrypted_text = openssl_decrypt(
327
-            $encrypted_components[0],
328
-            EE_Encryption::OPENSSL_CIPHER_METHOD,
329
-            openssl_digest($this->get_encryption_key(), EE_Encryption::OPENSSL_DIGEST_METHOD),
330
-            0,
331
-            $encrypted_components[1]
332
-        );
333
-        $decrypted_text = trim($decrypted_text);
334
-        return $decrypted_text;
335
-    }
336
-
337
-
338
-
339
-    /**
340
-     * encrypts data for acme servers that didn't bother to install PHP mcrypt
341
-     *
342
-     * @see http://stackoverflow.com/questions/800922/how-to-encrypt-string-without-mcrypt-library-in-php
343
-     * @param string $text_string the text to be decrypted
344
-     * @return string
345
-     */
346
-    protected function acme_encrypt($text_string = '')
347
-    {
348
-        // you give me nothing??? GET OUT !
349
-        if (empty($text_string)) {
350
-            return $text_string;
351
-        }
352
-        $key_bits = str_split(
353
-            str_pad('', strlen($text_string), $this->get_encryption_key(), STR_PAD_RIGHT)
354
-        );
355
-        $string_bits = str_split($text_string);
356
-        foreach ($string_bits as $k => $v) {
357
-            $temp = ord($v) + ord($key_bits[$k]);
358
-            $string_bits[$k] = chr($temp > 255 ? ($temp - 256) : $temp);
359
-        }
360
-        return $this->_use_base64_encode
361
-            ? base64_encode(implode('', $string_bits))
362
-            : implode('', $string_bits);
363
-    }
364
-
365
-
366
-
367
-    /**
368
-     * decrypts data for acme servers that didn't bother to install PHP mcrypt
369
-     *
370
-     * @see http://stackoverflow.com/questions/800922/how-to-encrypt-string-without-mcrypt-library-in-php
371
-     * @param string $encrypted_text the text to be decrypted
372
-     * @return string
373
-     */
374
-    protected function acme_decrypt($encrypted_text = '')
375
-    {
376
-        // you give me nothing??? GET OUT !
377
-        if (empty($encrypted_text)) {
378
-            return $encrypted_text;
379
-        }
380
-        // decode the data ?
381
-        $encrypted_text = $this->valid_base_64($encrypted_text)
382
-            ? base64_decode($encrypted_text)
383
-            : $encrypted_text;
384
-        $key_bits = str_split(
385
-            str_pad('', strlen($encrypted_text), $this->get_encryption_key(), STR_PAD_RIGHT)
386
-        );
387
-        $string_bits = str_split($encrypted_text);
388
-        foreach ($string_bits as $k => $v) {
389
-            $temp = ord($v) - ord($key_bits[$k]);
390
-            $string_bits[$k] = chr($temp < 0 ? ($temp + 256) : $temp);
391
-        }
392
-        return implode('', $string_bits);
393
-    }
394
-
395
-
396
-
397
-    /**
398
-     * @see http://stackoverflow.com/questions/2556345/detect-base64-encoding-in-php#30231906
399
-     * @param $string
400
-     * @return bool
401
-     */
402
-    protected function valid_base_64($string)
403
-    {
404
-        // ensure data is a string
405
-        if (! is_string($string) || ! $this->_use_base64_encode) {
406
-            return false;
407
-        }
408
-        $decoded = base64_decode($string, true);
409
-        // Check if there is no invalid character in string
410
-        if (! preg_match('/^[a-zA-Z0-9\/\r\n+]*={0,2}$/', $string)) {
411
-            return false;
412
-        }
413
-        // Decode the string in strict mode and send the response
414
-        if (! base64_decode($string, true)) {
415
-            return false;
416
-        }
417
-        // Encode and compare it to original one
418
-        return base64_encode($decoded) === $string;
419
-    }
420
-
421
-
422
-
423
-    /**
424
-     * generate random string
425
-     *
426
-     * @see http://stackoverflow.com/questions/637278/what-is-the-best-way-to-generate-a-random-key-within-php
427
-     * @param int $length number of characters for random string
428
-     * @return string
429
-     */
430
-    public function generate_random_string($length = 40)
431
-    {
432
-        $iterations = ceil($length / 40);
433
-        $random_string = '';
434
-        for ($i = 0; $i < $iterations; $i++) {
435
-            $random_string .= sha1(microtime(true) . mt_rand(10000, 90000));
436
-        }
437
-        $random_string = substr($random_string, 0, $length);
438
-        return $random_string;
439
-    }
440
-
441
-
442
-
443
-    /**
444
-     * encrypts data using PHP's mcrypt functions
445
-     *
446
-     * @deprecated 4.9.39
447
-     * @param string $text_string
448
-     * @internal   param $string - the text to be encrypted
449
-     * @return string
450
-     * @throws RuntimeException
451
-     */
452
-    protected function m_encrypt($text_string = '')
453
-    {
454
-        // you give me nothing??? GET OUT !
455
-        if (empty($text_string)) {
456
-            return $text_string;
457
-        }
458
-        // get the initialization vector size
459
-        $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB);
460
-        // initialization vector
461
-        $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
462
-        if ($iv === false) {
463
-            throw new RuntimeException(
464
-                esc_html__('Failed to generate mcrypt initialization vector.', 'event_espresso')
465
-            );
466
-        }
467
-        // encrypt it
468
-        $encrypted_text = mcrypt_encrypt(
469
-            MCRYPT_RIJNDAEL_256,
470
-            $this->get_encryption_key(),
471
-            $text_string,
472
-            MCRYPT_MODE_ECB,
473
-            $iv
474
-        );
475
-        // trim and maybe encode
476
-        return $this->_use_base64_encode
477
-            ? trim(base64_encode($encrypted_text))
478
-            : trim($encrypted_text);
479
-    }
480
-
481
-
482
-
483
-    /**
484
-     * decrypts data that has been encrypted with PHP's mcrypt functions
485
-     *
486
-     * @deprecated 4.9.39
487
-     * @param string $encrypted_text the text to be decrypted
488
-     * @return string
489
-     * @throws RuntimeException
490
-     */
491
-    protected function m_decrypt($encrypted_text = '')
492
-    {
493
-        // you give me nothing??? GET OUT !
494
-        if (empty($encrypted_text)) {
495
-            return $encrypted_text;
496
-        }
497
-        // decode
498
-        $encrypted_text = $this->valid_base_64($encrypted_text)
499
-            ? base64_decode($encrypted_text)
500
-            : $encrypted_text;
501
-        // get the initialization vector size
502
-        $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB);
503
-        $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
504
-        if ($iv === false) {
505
-            throw new RuntimeException(
506
-                esc_html__('Failed to generate mcrypt initialization vector.', 'event_espresso')
507
-            );
508
-        }
509
-        // decrypt it
510
-        $decrypted_text = mcrypt_decrypt(
511
-            MCRYPT_RIJNDAEL_256,
512
-            $this->get_encryption_key(),
513
-            $encrypted_text,
514
-            MCRYPT_MODE_ECB,
515
-            $iv
516
-        );
517
-        $decrypted_text = trim($decrypted_text);
518
-        return $decrypted_text;
519
-    }
19
+	/**
20
+	 * key used for saving the encryption key to the wp_options table
21
+	 */
22
+	const ENCRYPTION_OPTION_KEY = 'ee_encryption_key';
23
+
24
+	/**
25
+	 * the OPENSSL cipher method used
26
+	 */
27
+	const OPENSSL_CIPHER_METHOD = 'aes-256-ctr';
28
+
29
+	/**
30
+	 * the OPENSSL digest method used
31
+	 */
32
+	const OPENSSL_DIGEST_METHOD = 'sha512';
33
+
34
+	/**
35
+	 * separates the encrypted text from the initialization vector
36
+	 */
37
+	const OPENSSL_IV_DELIMITER = ':iv:';
38
+
39
+
40
+
41
+	/**
42
+	 * instance of the EE_Encryption object
43
+	 */
44
+	protected static $_instance;
45
+
46
+	/**
47
+	 * @var string $_encryption_key
48
+	 */
49
+	protected $_encryption_key;
50
+
51
+	/**
52
+	 * @var boolean $_use_openssl_encrypt
53
+	 */
54
+	protected $_use_openssl_encrypt = false;
55
+
56
+	/**
57
+	 * @var boolean $_use_mcrypt
58
+	 */
59
+	protected $_use_mcrypt = false;
60
+
61
+	/**
62
+	 * @var boolean $_use_base64_encode
63
+	 */
64
+	protected $_use_base64_encode = false;
65
+
66
+
67
+
68
+	/**
69
+	 * protected constructor to prevent direct creation
70
+	 */
71
+	protected function __construct()
72
+	{
73
+		if (! defined('ESPRESSO_ENCRYPT')) {
74
+			define('ESPRESSO_ENCRYPT', true);
75
+		}
76
+		if (function_exists('openssl_encrypt')) {
77
+			$this->_use_openssl_encrypt = true;
78
+		} else if (function_exists('mcrypt_encrypt')) {
79
+			$this->_use_mcrypt = true;
80
+		}
81
+		if (function_exists('base64_encode')) {
82
+			$this->_use_base64_encode = true;
83
+		}
84
+	}
85
+
86
+
87
+
88
+	/**
89
+	 * singleton method used to instantiate class object
90
+	 *
91
+	 * @return EE_Encryption
92
+	 */
93
+	public static function instance()
94
+	{
95
+		// check if class object is instantiated
96
+		if (! self::$_instance instanceof EE_Encryption) {
97
+			self::$_instance = new self();
98
+		}
99
+		return self::$_instance;
100
+	}
101
+
102
+
103
+
104
+	/**
105
+	 * get encryption key
106
+	 *
107
+	 * @return string
108
+	 */
109
+	public function get_encryption_key()
110
+	{
111
+		// if encryption key has not been set
112
+		if (empty($this->_encryption_key)) {
113
+			// retrieve encryption_key from db
114
+			$this->_encryption_key = get_option(EE_Encryption::ENCRYPTION_OPTION_KEY, '');
115
+			// WHAT?? No encryption_key in the db ??
116
+			if ($this->_encryption_key === '') {
117
+				// let's make one. And md5 it to make it just the right size for a key
118
+				$new_key = md5($this->generate_random_string());
119
+				// now save it to the db for later
120
+				add_option(EE_Encryption::ENCRYPTION_OPTION_KEY, $new_key);
121
+				// here's the key - FINALLY !
122
+				$this->_encryption_key = $new_key;
123
+			}
124
+		}
125
+		return $this->_encryption_key;
126
+	}
127
+
128
+
129
+
130
+	/**
131
+	 * encrypts data
132
+	 *
133
+	 * @param string $text_string - the text to be encrypted
134
+	 * @return string
135
+	 * @throws RuntimeException
136
+	 */
137
+	public function encrypt($text_string = '')
138
+	{
139
+		// you give me nothing??? GET OUT !
140
+		if (empty($text_string)) {
141
+			return $text_string;
142
+		}
143
+		if ($this->_use_openssl_encrypt) {
144
+			$encrypted_text = $this->openssl_encrypt($text_string);
145
+		} else {
146
+			$encrypted_text = $this->acme_encrypt($text_string);
147
+		}
148
+		return $encrypted_text;
149
+	}
150
+
151
+
152
+
153
+	/**
154
+	 * decrypts data
155
+	 *
156
+	 * @param string $encrypted_text - the text to be decrypted
157
+	 * @return string
158
+	 * @throws RuntimeException
159
+	 */
160
+	public function decrypt($encrypted_text = '')
161
+	{
162
+		// you give me nothing??? GET OUT !
163
+		if (empty($encrypted_text)) {
164
+			return $encrypted_text;
165
+		}
166
+		// if PHP's mcrypt functions are installed then we'll use them
167
+		if ($this->_use_openssl_encrypt) {
168
+			$decrypted_text = $this->openssl_decrypt($encrypted_text);
169
+		} else if ($this->_use_mcrypt) {
170
+			$decrypted_text = $this->m_decrypt($encrypted_text);
171
+		} else {
172
+			$decrypted_text = $this->acme_decrypt($encrypted_text);
173
+		}
174
+		return $decrypted_text;
175
+	}
176
+
177
+
178
+
179
+	/**
180
+	 * encodes string with PHP's base64 encoding
181
+	 *
182
+	 * @see http://php.net/manual/en/function.base64-encode.php
183
+	 * @param string $text_string the text to be encoded
184
+	 * @return string
185
+	 */
186
+	public function base64_string_encode($text_string = '')
187
+	{
188
+		// you give me nothing??? GET OUT !
189
+		if (empty($text_string) || ! $this->_use_base64_encode) {
190
+			return $text_string;
191
+		}
192
+		// encode
193
+		return base64_encode($text_string);
194
+	}
195
+
196
+
197
+
198
+	/**
199
+	 * decodes string that has been encoded with PHP's base64 encoding
200
+	 *
201
+	 * @see http://php.net/manual/en/function.base64-encode.php
202
+	 * @param string $encoded_string the text to be decoded
203
+	 * @return string
204
+	 */
205
+	public function base64_string_decode($encoded_string = '')
206
+	{
207
+		// you give me nothing??? GET OUT !
208
+		if (empty($encoded_string) || ! $this->valid_base_64($encoded_string)) {
209
+			return $encoded_string;
210
+		}
211
+		// decode
212
+		return base64_decode($encoded_string);
213
+	}
214
+
215
+
216
+
217
+	/**
218
+	 * encodes  url string with PHP's base64 encoding
219
+	 *
220
+	 * @see http://php.net/manual/en/function.base64-encode.php
221
+	 * @param string $text_string the text to be encoded
222
+	 * @return string
223
+	 */
224
+	public function base64_url_encode($text_string = '')
225
+	{
226
+		// you give me nothing??? GET OUT !
227
+		if (empty($text_string) || ! $this->_use_base64_encode) {
228
+			return $text_string;
229
+		}
230
+		// encode
231
+		$encoded_string = base64_encode($text_string);
232
+		// remove chars to make encoding more URL friendly
233
+		return strtr($encoded_string, '+/=', '-_,');
234
+	}
235
+
236
+
237
+
238
+	/**
239
+	 * decodes  url string that has been encoded with PHP's base64 encoding
240
+	 *
241
+	 * @see http://php.net/manual/en/function.base64-encode.php
242
+	 * @param string $encoded_string the text to be decoded
243
+	 * @return string
244
+	 */
245
+	public function base64_url_decode($encoded_string = '')
246
+	{
247
+		// you give me nothing??? GET OUT !
248
+		if (empty($encoded_string) || ! $this->valid_base_64($encoded_string)) {
249
+			return $encoded_string;
250
+		}
251
+		// replace previously removed characters
252
+		$encoded_string = strtr($encoded_string, '-_,', '+/=');
253
+		// decode
254
+		return base64_decode($encoded_string);
255
+	}
256
+
257
+
258
+
259
+	/**
260
+	 * encrypts data using PHP's openssl functions
261
+	 *
262
+	 * @param string $text_string the text to be encrypted
263
+	 * @return string
264
+	 * @throws RuntimeException
265
+	 */
266
+	protected function openssl_encrypt($text_string = '')
267
+	{
268
+		// you give me nothing??? GET OUT !
269
+		if (empty($text_string)) {
270
+			return $text_string;
271
+		}
272
+		// get initialization vector size
273
+		$iv_size = openssl_cipher_iv_length(EE_Encryption::OPENSSL_CIPHER_METHOD);
274
+		// generate initialization vector
275
+		$iv = openssl_random_pseudo_bytes($iv_size, $is_strong);
276
+		if ($iv === false || $is_strong === false) {
277
+			throw new RuntimeException(
278
+				esc_html__('Failed to generate OpenSSL initialization vector.', 'event_espresso')
279
+			);
280
+		}
281
+		// encrypt it
282
+		$encrypted_text = openssl_encrypt(
283
+			$text_string,
284
+			EE_Encryption::OPENSSL_CIPHER_METHOD,
285
+			openssl_digest($this->get_encryption_key(), EE_Encryption::OPENSSL_DIGEST_METHOD),
286
+			0,
287
+			$iv
288
+		);
289
+		// append the initialization vector
290
+		$encrypted_text .= EE_Encryption::OPENSSL_IV_DELIMITER . $iv;
291
+		// trim and maybe encode
292
+		return $this->_use_base64_encode
293
+			? trim(base64_encode($encrypted_text))
294
+			: trim($encrypted_text);
295
+	}
296
+
297
+
298
+
299
+	/**
300
+	 * decrypts data that has been encrypted with PHP's openssl functions
301
+	 *
302
+	 * @param string $encrypted_text the text to be decrypted
303
+	 * @return string
304
+	 * @throws RuntimeException
305
+	 */
306
+	protected function openssl_decrypt($encrypted_text = '')
307
+	{
308
+		// you give me nothing??? GET OUT !
309
+		if (empty($encrypted_text)) {
310
+			return $encrypted_text;
311
+		}
312
+		// decode
313
+		$encrypted_text = $this->valid_base_64($encrypted_text)
314
+			? base64_decode($encrypted_text)
315
+			: $encrypted_text;
316
+		$encrypted_components = explode(
317
+			EE_Encryption::OPENSSL_IV_DELIMITER,
318
+			$encrypted_text,
319
+			2
320
+		);
321
+		// check that iv exists, and if not, maybe text was encoded using mcrypt?
322
+		if (! isset($encrypted_components[1]) && $this->_use_mcrypt) {
323
+			return $this->m_decrypt($encrypted_text);
324
+		}
325
+		// decrypt it
326
+		$decrypted_text = openssl_decrypt(
327
+			$encrypted_components[0],
328
+			EE_Encryption::OPENSSL_CIPHER_METHOD,
329
+			openssl_digest($this->get_encryption_key(), EE_Encryption::OPENSSL_DIGEST_METHOD),
330
+			0,
331
+			$encrypted_components[1]
332
+		);
333
+		$decrypted_text = trim($decrypted_text);
334
+		return $decrypted_text;
335
+	}
336
+
337
+
338
+
339
+	/**
340
+	 * encrypts data for acme servers that didn't bother to install PHP mcrypt
341
+	 *
342
+	 * @see http://stackoverflow.com/questions/800922/how-to-encrypt-string-without-mcrypt-library-in-php
343
+	 * @param string $text_string the text to be decrypted
344
+	 * @return string
345
+	 */
346
+	protected function acme_encrypt($text_string = '')
347
+	{
348
+		// you give me nothing??? GET OUT !
349
+		if (empty($text_string)) {
350
+			return $text_string;
351
+		}
352
+		$key_bits = str_split(
353
+			str_pad('', strlen($text_string), $this->get_encryption_key(), STR_PAD_RIGHT)
354
+		);
355
+		$string_bits = str_split($text_string);
356
+		foreach ($string_bits as $k => $v) {
357
+			$temp = ord($v) + ord($key_bits[$k]);
358
+			$string_bits[$k] = chr($temp > 255 ? ($temp - 256) : $temp);
359
+		}
360
+		return $this->_use_base64_encode
361
+			? base64_encode(implode('', $string_bits))
362
+			: implode('', $string_bits);
363
+	}
364
+
365
+
366
+
367
+	/**
368
+	 * decrypts data for acme servers that didn't bother to install PHP mcrypt
369
+	 *
370
+	 * @see http://stackoverflow.com/questions/800922/how-to-encrypt-string-without-mcrypt-library-in-php
371
+	 * @param string $encrypted_text the text to be decrypted
372
+	 * @return string
373
+	 */
374
+	protected function acme_decrypt($encrypted_text = '')
375
+	{
376
+		// you give me nothing??? GET OUT !
377
+		if (empty($encrypted_text)) {
378
+			return $encrypted_text;
379
+		}
380
+		// decode the data ?
381
+		$encrypted_text = $this->valid_base_64($encrypted_text)
382
+			? base64_decode($encrypted_text)
383
+			: $encrypted_text;
384
+		$key_bits = str_split(
385
+			str_pad('', strlen($encrypted_text), $this->get_encryption_key(), STR_PAD_RIGHT)
386
+		);
387
+		$string_bits = str_split($encrypted_text);
388
+		foreach ($string_bits as $k => $v) {
389
+			$temp = ord($v) - ord($key_bits[$k]);
390
+			$string_bits[$k] = chr($temp < 0 ? ($temp + 256) : $temp);
391
+		}
392
+		return implode('', $string_bits);
393
+	}
394
+
395
+
396
+
397
+	/**
398
+	 * @see http://stackoverflow.com/questions/2556345/detect-base64-encoding-in-php#30231906
399
+	 * @param $string
400
+	 * @return bool
401
+	 */
402
+	protected function valid_base_64($string)
403
+	{
404
+		// ensure data is a string
405
+		if (! is_string($string) || ! $this->_use_base64_encode) {
406
+			return false;
407
+		}
408
+		$decoded = base64_decode($string, true);
409
+		// Check if there is no invalid character in string
410
+		if (! preg_match('/^[a-zA-Z0-9\/\r\n+]*={0,2}$/', $string)) {
411
+			return false;
412
+		}
413
+		// Decode the string in strict mode and send the response
414
+		if (! base64_decode($string, true)) {
415
+			return false;
416
+		}
417
+		// Encode and compare it to original one
418
+		return base64_encode($decoded) === $string;
419
+	}
420
+
421
+
422
+
423
+	/**
424
+	 * generate random string
425
+	 *
426
+	 * @see http://stackoverflow.com/questions/637278/what-is-the-best-way-to-generate-a-random-key-within-php
427
+	 * @param int $length number of characters for random string
428
+	 * @return string
429
+	 */
430
+	public function generate_random_string($length = 40)
431
+	{
432
+		$iterations = ceil($length / 40);
433
+		$random_string = '';
434
+		for ($i = 0; $i < $iterations; $i++) {
435
+			$random_string .= sha1(microtime(true) . mt_rand(10000, 90000));
436
+		}
437
+		$random_string = substr($random_string, 0, $length);
438
+		return $random_string;
439
+	}
440
+
441
+
442
+
443
+	/**
444
+	 * encrypts data using PHP's mcrypt functions
445
+	 *
446
+	 * @deprecated 4.9.39
447
+	 * @param string $text_string
448
+	 * @internal   param $string - the text to be encrypted
449
+	 * @return string
450
+	 * @throws RuntimeException
451
+	 */
452
+	protected function m_encrypt($text_string = '')
453
+	{
454
+		// you give me nothing??? GET OUT !
455
+		if (empty($text_string)) {
456
+			return $text_string;
457
+		}
458
+		// get the initialization vector size
459
+		$iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB);
460
+		// initialization vector
461
+		$iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
462
+		if ($iv === false) {
463
+			throw new RuntimeException(
464
+				esc_html__('Failed to generate mcrypt initialization vector.', 'event_espresso')
465
+			);
466
+		}
467
+		// encrypt it
468
+		$encrypted_text = mcrypt_encrypt(
469
+			MCRYPT_RIJNDAEL_256,
470
+			$this->get_encryption_key(),
471
+			$text_string,
472
+			MCRYPT_MODE_ECB,
473
+			$iv
474
+		);
475
+		// trim and maybe encode
476
+		return $this->_use_base64_encode
477
+			? trim(base64_encode($encrypted_text))
478
+			: trim($encrypted_text);
479
+	}
480
+
481
+
482
+
483
+	/**
484
+	 * decrypts data that has been encrypted with PHP's mcrypt functions
485
+	 *
486
+	 * @deprecated 4.9.39
487
+	 * @param string $encrypted_text the text to be decrypted
488
+	 * @return string
489
+	 * @throws RuntimeException
490
+	 */
491
+	protected function m_decrypt($encrypted_text = '')
492
+	{
493
+		// you give me nothing??? GET OUT !
494
+		if (empty($encrypted_text)) {
495
+			return $encrypted_text;
496
+		}
497
+		// decode
498
+		$encrypted_text = $this->valid_base_64($encrypted_text)
499
+			? base64_decode($encrypted_text)
500
+			: $encrypted_text;
501
+		// get the initialization vector size
502
+		$iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB);
503
+		$iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
504
+		if ($iv === false) {
505
+			throw new RuntimeException(
506
+				esc_html__('Failed to generate mcrypt initialization vector.', 'event_espresso')
507
+			);
508
+		}
509
+		// decrypt it
510
+		$decrypted_text = mcrypt_decrypt(
511
+			MCRYPT_RIJNDAEL_256,
512
+			$this->get_encryption_key(),
513
+			$encrypted_text,
514
+			MCRYPT_MODE_ECB,
515
+			$iv
516
+		);
517
+		$decrypted_text = trim($decrypted_text);
518
+		return $decrypted_text;
519
+	}
520 520
 
521 521
 }
522 522
 /* End of file EE_Encryption.class.php */
Please login to merge, or discard this patch.
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -70,7 +70,7 @@  discard block
 block discarded – undo
70 70
      */
71 71
     protected function __construct()
72 72
     {
73
-        if (! defined('ESPRESSO_ENCRYPT')) {
73
+        if ( ! defined('ESPRESSO_ENCRYPT')) {
74 74
             define('ESPRESSO_ENCRYPT', true);
75 75
         }
76 76
         if (function_exists('openssl_encrypt')) {
@@ -93,7 +93,7 @@  discard block
 block discarded – undo
93 93
     public static function instance()
94 94
     {
95 95
         // check if class object is instantiated
96
-        if (! self::$_instance instanceof EE_Encryption) {
96
+        if ( ! self::$_instance instanceof EE_Encryption) {
97 97
             self::$_instance = new self();
98 98
         }
99 99
         return self::$_instance;
@@ -287,7 +287,7 @@  discard block
 block discarded – undo
287 287
             $iv
288 288
         );
289 289
         // append the initialization vector
290
-        $encrypted_text .= EE_Encryption::OPENSSL_IV_DELIMITER . $iv;
290
+        $encrypted_text .= EE_Encryption::OPENSSL_IV_DELIMITER.$iv;
291 291
         // trim and maybe encode
292 292
         return $this->_use_base64_encode
293 293
             ? trim(base64_encode($encrypted_text))
@@ -319,7 +319,7 @@  discard block
 block discarded – undo
319 319
             2
320 320
         );
321 321
         // check that iv exists, and if not, maybe text was encoded using mcrypt?
322
-        if (! isset($encrypted_components[1]) && $this->_use_mcrypt) {
322
+        if ( ! isset($encrypted_components[1]) && $this->_use_mcrypt) {
323 323
             return $this->m_decrypt($encrypted_text);
324 324
         }
325 325
         // decrypt it
@@ -402,16 +402,16 @@  discard block
 block discarded – undo
402 402
     protected function valid_base_64($string)
403 403
     {
404 404
         // ensure data is a string
405
-        if (! is_string($string) || ! $this->_use_base64_encode) {
405
+        if ( ! is_string($string) || ! $this->_use_base64_encode) {
406 406
             return false;
407 407
         }
408 408
         $decoded = base64_decode($string, true);
409 409
         // Check if there is no invalid character in string
410
-        if (! preg_match('/^[a-zA-Z0-9\/\r\n+]*={0,2}$/', $string)) {
410
+        if ( ! preg_match('/^[a-zA-Z0-9\/\r\n+]*={0,2}$/', $string)) {
411 411
             return false;
412 412
         }
413 413
         // Decode the string in strict mode and send the response
414
-        if (! base64_decode($string, true)) {
414
+        if ( ! base64_decode($string, true)) {
415 415
             return false;
416 416
         }
417 417
         // Encode and compare it to original one
@@ -432,7 +432,7 @@  discard block
 block discarded – undo
432 432
         $iterations = ceil($length / 40);
433 433
         $random_string = '';
434 434
         for ($i = 0; $i < $iterations; $i++) {
435
-            $random_string .= sha1(microtime(true) . mt_rand(10000, 90000));
435
+            $random_string .= sha1(microtime(true).mt_rand(10000, 90000));
436 436
         }
437 437
         $random_string = substr($random_string, 0, $length);
438 438
         return $random_string;
Please login to merge, or discard this patch.
espresso.php 1 patch
Indentation   +219 added lines, -219 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php if ( ! defined('ABSPATH')) {
2
-    exit('No direct script access allowed');
2
+	exit('No direct script access allowed');
3 3
 }
4 4
 /*
5 5
   Plugin Name:		Event Espresso
@@ -40,243 +40,243 @@  discard block
 block discarded – undo
40 40
  * @since            4.0
41 41
  */
42 42
 if (function_exists('espresso_version')) {
43
-    /**
44
-     *    espresso_duplicate_plugin_error
45
-     *    displays if more than one version of EE is activated at the same time
46
-     */
47
-    function espresso_duplicate_plugin_error()
48
-    {
49
-        ?>
43
+	/**
44
+	 *    espresso_duplicate_plugin_error
45
+	 *    displays if more than one version of EE is activated at the same time
46
+	 */
47
+	function espresso_duplicate_plugin_error()
48
+	{
49
+		?>
50 50
         <div class="error">
51 51
             <p>
52 52
                 <?php echo esc_html__(
53
-                        'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.',
54
-                        'event_espresso'
55
-                ); ?>
53
+						'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.',
54
+						'event_espresso'
55
+				); ?>
56 56
             </p>
57 57
         </div>
58 58
         <?php
59
-        espresso_deactivate_plugin(plugin_basename(__FILE__));
60
-    }
59
+		espresso_deactivate_plugin(plugin_basename(__FILE__));
60
+	}
61 61
 
62
-    add_action('admin_notices', 'espresso_duplicate_plugin_error', 1);
62
+	add_action('admin_notices', 'espresso_duplicate_plugin_error', 1);
63 63
 } else {
64
-    define('EE_MIN_PHP_VER_REQUIRED', '5.3.9');
65
-    if ( ! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) {
66
-        /**
67
-         * espresso_minimum_php_version_error
68
-         *
69
-         * @return void
70
-         */
71
-        function espresso_minimum_php_version_error()
72
-        {
73
-            ?>
64
+	define('EE_MIN_PHP_VER_REQUIRED', '5.3.9');
65
+	if ( ! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) {
66
+		/**
67
+		 * espresso_minimum_php_version_error
68
+		 *
69
+		 * @return void
70
+		 */
71
+		function espresso_minimum_php_version_error()
72
+		{
73
+			?>
74 74
             <div class="error">
75 75
                 <p>
76 76
                     <?php
77
-                    printf(
78
-                            esc_html__(
79
-                                    'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.',
80
-                                    'event_espresso'
81
-                            ),
82
-                            EE_MIN_PHP_VER_REQUIRED,
83
-                            PHP_VERSION,
84
-                            '<br/>',
85
-                            '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>'
86
-                    );
87
-                    ?>
77
+					printf(
78
+							esc_html__(
79
+									'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.',
80
+									'event_espresso'
81
+							),
82
+							EE_MIN_PHP_VER_REQUIRED,
83
+							PHP_VERSION,
84
+							'<br/>',
85
+							'<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>'
86
+					);
87
+					?>
88 88
                 </p>
89 89
             </div>
90 90
             <?php
91
-            espresso_deactivate_plugin(plugin_basename(__FILE__));
92
-        }
91
+			espresso_deactivate_plugin(plugin_basename(__FILE__));
92
+		}
93 93
 
94
-        add_action('admin_notices', 'espresso_minimum_php_version_error', 1);
95
-    } else {
96
-        /**
97
-         * espresso_version
98
-         * Returns the plugin version
99
-         *
100
-         * @return string
101
-         */
102
-        function espresso_version()
103
-        {
104
-            return apply_filters('FHEE__espresso__espresso_version', '4.9.39.rc.019');
105
-        }
94
+		add_action('admin_notices', 'espresso_minimum_php_version_error', 1);
95
+	} else {
96
+		/**
97
+		 * espresso_version
98
+		 * Returns the plugin version
99
+		 *
100
+		 * @return string
101
+		 */
102
+		function espresso_version()
103
+		{
104
+			return apply_filters('FHEE__espresso__espresso_version', '4.9.39.rc.019');
105
+		}
106 106
 
107
-        // define versions
108
-        define('EVENT_ESPRESSO_VERSION', espresso_version());
109
-        define('EE_MIN_WP_VER_REQUIRED', '4.1');
110
-        define('EE_MIN_WP_VER_RECOMMENDED', '4.4.2');
111
-        define('EE_MIN_PHP_VER_RECOMMENDED', '5.4.44');
112
-        define('EVENT_ESPRESSO_MAIN_FILE', __FILE__);
113
-        //used to be DIRECTORY_SEPARATOR, but that caused issues on windows
114
-        if ( ! defined('DS')) {
115
-            define('DS', '/');
116
-        }
117
-        if ( ! defined('PS')) {
118
-            define('PS', PATH_SEPARATOR);
119
-        }
120
-        if ( ! defined('SP')) {
121
-            define('SP', ' ');
122
-        }
123
-        if ( ! defined('EENL')) {
124
-            define('EENL', "\n");
125
-        }
126
-        define('EE_SUPPORT_EMAIL', '[email protected]');
127
-        // define the plugin directory and URL
128
-        define('EE_PLUGIN_BASENAME', plugin_basename(EVENT_ESPRESSO_MAIN_FILE));
129
-        define('EE_PLUGIN_DIR_PATH', plugin_dir_path(EVENT_ESPRESSO_MAIN_FILE));
130
-        define('EE_PLUGIN_DIR_URL', plugin_dir_url(EVENT_ESPRESSO_MAIN_FILE));
131
-        // main root folder paths
132
-        define('EE_ADMIN_PAGES', EE_PLUGIN_DIR_PATH . 'admin_pages' . DS);
133
-        define('EE_CORE', EE_PLUGIN_DIR_PATH . 'core' . DS);
134
-        define('EE_MODULES', EE_PLUGIN_DIR_PATH . 'modules' . DS);
135
-        define('EE_PUBLIC', EE_PLUGIN_DIR_PATH . 'public' . DS);
136
-        define('EE_SHORTCODES', EE_PLUGIN_DIR_PATH . 'shortcodes' . DS);
137
-        define('EE_WIDGETS', EE_PLUGIN_DIR_PATH . 'widgets' . DS);
138
-        define('EE_PAYMENT_METHODS', EE_PLUGIN_DIR_PATH . 'payment_methods' . DS);
139
-        define('EE_CAFF_PATH', EE_PLUGIN_DIR_PATH . 'caffeinated' . DS);
140
-        // core system paths
141
-        define('EE_ADMIN', EE_CORE . 'admin' . DS);
142
-        define('EE_CPTS', EE_CORE . 'CPTs' . DS);
143
-        define('EE_CLASSES', EE_CORE . 'db_classes' . DS);
144
-        define('EE_INTERFACES', EE_CORE . 'interfaces' . DS);
145
-        define('EE_BUSINESS', EE_CORE . 'business' . DS);
146
-        define('EE_MODELS', EE_CORE . 'db_models' . DS);
147
-        define('EE_HELPERS', EE_CORE . 'helpers' . DS);
148
-        define('EE_LIBRARIES', EE_CORE . 'libraries' . DS);
149
-        define('EE_TEMPLATES', EE_CORE . 'templates' . DS);
150
-        define('EE_THIRD_PARTY', EE_CORE . 'third_party_libs' . DS);
151
-        define('EE_GLOBAL_ASSETS', EE_TEMPLATES . 'global_assets' . DS);
152
-        define('EE_FORM_SECTIONS', EE_LIBRARIES . 'form_sections' . DS);
153
-        // gateways
154
-        define('EE_GATEWAYS', EE_MODULES . 'gateways' . DS);
155
-        define('EE_GATEWAYS_URL', EE_PLUGIN_DIR_URL . 'modules' . DS . 'gateways' . DS);
156
-        // asset URL paths
157
-        define('EE_TEMPLATES_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'templates' . DS);
158
-        define('EE_GLOBAL_ASSETS_URL', EE_TEMPLATES_URL . 'global_assets' . DS);
159
-        define('EE_IMAGES_URL', EE_GLOBAL_ASSETS_URL . 'images' . DS);
160
-        define('EE_THIRD_PARTY_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'third_party_libs' . DS);
161
-        define('EE_HELPERS_ASSETS', EE_PLUGIN_DIR_URL . 'core/helpers/assets/');
162
-        define('EE_LIBRARIES_URL', EE_PLUGIN_DIR_URL . 'core/libraries/');
163
-        // define upload paths
164
-        $uploads = wp_upload_dir();
165
-        // define the uploads directory and URL
166
-        define('EVENT_ESPRESSO_UPLOAD_DIR', $uploads['basedir'] . DS . 'espresso' . DS);
167
-        define('EVENT_ESPRESSO_UPLOAD_URL', $uploads['baseurl'] . DS . 'espresso' . DS);
168
-        // define the templates directory and URL
169
-        define('EVENT_ESPRESSO_TEMPLATE_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'templates' . DS);
170
-        define('EVENT_ESPRESSO_TEMPLATE_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'templates' . DS);
171
-        // define the gateway directory and URL
172
-        define('EVENT_ESPRESSO_GATEWAY_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'gateways' . DS);
173
-        define('EVENT_ESPRESSO_GATEWAY_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'gateways' . DS);
174
-        // languages folder/path
175
-        define('EE_LANGUAGES_SAFE_LOC', '..' . DS . 'uploads' . DS . 'espresso' . DS . 'languages' . DS);
176
-        define('EE_LANGUAGES_SAFE_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'languages' . DS);
177
-        //check for dompdf fonts in uploads
178
-        if (file_exists(EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS)) {
179
-            define('DOMPDF_FONT_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS);
180
-        }
181
-        //ajax constants
182
-        define(
183
-                'EE_FRONT_AJAX',
184
-                isset($_REQUEST['ee_front_ajax']) || isset($_REQUEST['data']['ee_front_ajax']) ? true : false
185
-        );
186
-        define(
187
-                'EE_ADMIN_AJAX',
188
-                isset($_REQUEST['ee_admin_ajax']) || isset($_REQUEST['data']['ee_admin_ajax']) ? true : false
189
-        );
190
-        //just a handy constant occasionally needed for finding values representing infinity in the DB
191
-        //you're better to use this than its straight value (currently -1) in case you ever
192
-        //want to change its default value! or find when -1 means infinity
193
-        define('EE_INF_IN_DB', -1);
194
-        define('EE_INF', INF > (float)PHP_INT_MAX ? INF : PHP_INT_MAX);
195
-        define('EE_DEBUG', false);
196
-        // for older WP versions
197
-        if ( ! defined('MONTH_IN_SECONDS')) {
198
-            define('MONTH_IN_SECONDS', DAY_IN_SECONDS * 30);
199
-        }
200
-        /**
201
-         *    espresso_plugin_activation
202
-         *    adds a wp-option to indicate that EE has been activated via the WP admin plugins page
203
-         */
204
-        function espresso_plugin_activation()
205
-        {
206
-            update_option('ee_espresso_activation', true);
207
-        }
107
+		// define versions
108
+		define('EVENT_ESPRESSO_VERSION', espresso_version());
109
+		define('EE_MIN_WP_VER_REQUIRED', '4.1');
110
+		define('EE_MIN_WP_VER_RECOMMENDED', '4.4.2');
111
+		define('EE_MIN_PHP_VER_RECOMMENDED', '5.4.44');
112
+		define('EVENT_ESPRESSO_MAIN_FILE', __FILE__);
113
+		//used to be DIRECTORY_SEPARATOR, but that caused issues on windows
114
+		if ( ! defined('DS')) {
115
+			define('DS', '/');
116
+		}
117
+		if ( ! defined('PS')) {
118
+			define('PS', PATH_SEPARATOR);
119
+		}
120
+		if ( ! defined('SP')) {
121
+			define('SP', ' ');
122
+		}
123
+		if ( ! defined('EENL')) {
124
+			define('EENL', "\n");
125
+		}
126
+		define('EE_SUPPORT_EMAIL', '[email protected]');
127
+		// define the plugin directory and URL
128
+		define('EE_PLUGIN_BASENAME', plugin_basename(EVENT_ESPRESSO_MAIN_FILE));
129
+		define('EE_PLUGIN_DIR_PATH', plugin_dir_path(EVENT_ESPRESSO_MAIN_FILE));
130
+		define('EE_PLUGIN_DIR_URL', plugin_dir_url(EVENT_ESPRESSO_MAIN_FILE));
131
+		// main root folder paths
132
+		define('EE_ADMIN_PAGES', EE_PLUGIN_DIR_PATH . 'admin_pages' . DS);
133
+		define('EE_CORE', EE_PLUGIN_DIR_PATH . 'core' . DS);
134
+		define('EE_MODULES', EE_PLUGIN_DIR_PATH . 'modules' . DS);
135
+		define('EE_PUBLIC', EE_PLUGIN_DIR_PATH . 'public' . DS);
136
+		define('EE_SHORTCODES', EE_PLUGIN_DIR_PATH . 'shortcodes' . DS);
137
+		define('EE_WIDGETS', EE_PLUGIN_DIR_PATH . 'widgets' . DS);
138
+		define('EE_PAYMENT_METHODS', EE_PLUGIN_DIR_PATH . 'payment_methods' . DS);
139
+		define('EE_CAFF_PATH', EE_PLUGIN_DIR_PATH . 'caffeinated' . DS);
140
+		// core system paths
141
+		define('EE_ADMIN', EE_CORE . 'admin' . DS);
142
+		define('EE_CPTS', EE_CORE . 'CPTs' . DS);
143
+		define('EE_CLASSES', EE_CORE . 'db_classes' . DS);
144
+		define('EE_INTERFACES', EE_CORE . 'interfaces' . DS);
145
+		define('EE_BUSINESS', EE_CORE . 'business' . DS);
146
+		define('EE_MODELS', EE_CORE . 'db_models' . DS);
147
+		define('EE_HELPERS', EE_CORE . 'helpers' . DS);
148
+		define('EE_LIBRARIES', EE_CORE . 'libraries' . DS);
149
+		define('EE_TEMPLATES', EE_CORE . 'templates' . DS);
150
+		define('EE_THIRD_PARTY', EE_CORE . 'third_party_libs' . DS);
151
+		define('EE_GLOBAL_ASSETS', EE_TEMPLATES . 'global_assets' . DS);
152
+		define('EE_FORM_SECTIONS', EE_LIBRARIES . 'form_sections' . DS);
153
+		// gateways
154
+		define('EE_GATEWAYS', EE_MODULES . 'gateways' . DS);
155
+		define('EE_GATEWAYS_URL', EE_PLUGIN_DIR_URL . 'modules' . DS . 'gateways' . DS);
156
+		// asset URL paths
157
+		define('EE_TEMPLATES_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'templates' . DS);
158
+		define('EE_GLOBAL_ASSETS_URL', EE_TEMPLATES_URL . 'global_assets' . DS);
159
+		define('EE_IMAGES_URL', EE_GLOBAL_ASSETS_URL . 'images' . DS);
160
+		define('EE_THIRD_PARTY_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'third_party_libs' . DS);
161
+		define('EE_HELPERS_ASSETS', EE_PLUGIN_DIR_URL . 'core/helpers/assets/');
162
+		define('EE_LIBRARIES_URL', EE_PLUGIN_DIR_URL . 'core/libraries/');
163
+		// define upload paths
164
+		$uploads = wp_upload_dir();
165
+		// define the uploads directory and URL
166
+		define('EVENT_ESPRESSO_UPLOAD_DIR', $uploads['basedir'] . DS . 'espresso' . DS);
167
+		define('EVENT_ESPRESSO_UPLOAD_URL', $uploads['baseurl'] . DS . 'espresso' . DS);
168
+		// define the templates directory and URL
169
+		define('EVENT_ESPRESSO_TEMPLATE_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'templates' . DS);
170
+		define('EVENT_ESPRESSO_TEMPLATE_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'templates' . DS);
171
+		// define the gateway directory and URL
172
+		define('EVENT_ESPRESSO_GATEWAY_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'gateways' . DS);
173
+		define('EVENT_ESPRESSO_GATEWAY_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'gateways' . DS);
174
+		// languages folder/path
175
+		define('EE_LANGUAGES_SAFE_LOC', '..' . DS . 'uploads' . DS . 'espresso' . DS . 'languages' . DS);
176
+		define('EE_LANGUAGES_SAFE_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'languages' . DS);
177
+		//check for dompdf fonts in uploads
178
+		if (file_exists(EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS)) {
179
+			define('DOMPDF_FONT_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS);
180
+		}
181
+		//ajax constants
182
+		define(
183
+				'EE_FRONT_AJAX',
184
+				isset($_REQUEST['ee_front_ajax']) || isset($_REQUEST['data']['ee_front_ajax']) ? true : false
185
+		);
186
+		define(
187
+				'EE_ADMIN_AJAX',
188
+				isset($_REQUEST['ee_admin_ajax']) || isset($_REQUEST['data']['ee_admin_ajax']) ? true : false
189
+		);
190
+		//just a handy constant occasionally needed for finding values representing infinity in the DB
191
+		//you're better to use this than its straight value (currently -1) in case you ever
192
+		//want to change its default value! or find when -1 means infinity
193
+		define('EE_INF_IN_DB', -1);
194
+		define('EE_INF', INF > (float)PHP_INT_MAX ? INF : PHP_INT_MAX);
195
+		define('EE_DEBUG', false);
196
+		// for older WP versions
197
+		if ( ! defined('MONTH_IN_SECONDS')) {
198
+			define('MONTH_IN_SECONDS', DAY_IN_SECONDS * 30);
199
+		}
200
+		/**
201
+		 *    espresso_plugin_activation
202
+		 *    adds a wp-option to indicate that EE has been activated via the WP admin plugins page
203
+		 */
204
+		function espresso_plugin_activation()
205
+		{
206
+			update_option('ee_espresso_activation', true);
207
+		}
208 208
 
209
-        register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation');
210
-        /**
211
-         *    espresso_load_error_handling
212
-         *    this function loads EE's class for handling exceptions and errors
213
-         */
214
-        function espresso_load_error_handling()
215
-        {
216
-            // load debugging tools
217
-            if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) {
218
-                require_once(EE_HELPERS . 'EEH_Debug_Tools.helper.php');
219
-                EEH_Debug_Tools::instance();
220
-            }
221
-            // load error handling
222
-            if (is_readable(EE_CORE . 'EE_Error.core.php')) {
223
-                require_once(EE_CORE . 'EE_Error.core.php');
224
-            } else {
225
-                wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso'));
226
-            }
227
-        }
209
+		register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation');
210
+		/**
211
+		 *    espresso_load_error_handling
212
+		 *    this function loads EE's class for handling exceptions and errors
213
+		 */
214
+		function espresso_load_error_handling()
215
+		{
216
+			// load debugging tools
217
+			if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) {
218
+				require_once(EE_HELPERS . 'EEH_Debug_Tools.helper.php');
219
+				EEH_Debug_Tools::instance();
220
+			}
221
+			// load error handling
222
+			if (is_readable(EE_CORE . 'EE_Error.core.php')) {
223
+				require_once(EE_CORE . 'EE_Error.core.php');
224
+			} else {
225
+				wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso'));
226
+			}
227
+		}
228 228
 
229
-        /**
230
-         *    espresso_load_required
231
-         *    given a class name and path, this function will load that file or throw an exception
232
-         *
233
-         * @param    string $classname
234
-         * @param    string $full_path_to_file
235
-         * @throws    EE_Error
236
-         */
237
-        function espresso_load_required($classname, $full_path_to_file)
238
-        {
239
-            static $error_handling_loaded = false;
240
-            if ( ! $error_handling_loaded) {
241
-                espresso_load_error_handling();
242
-                $error_handling_loaded = true;
243
-            }
244
-            if (is_readable($full_path_to_file)) {
245
-                require_once($full_path_to_file);
246
-            } else {
247
-                throw new EE_Error (
248
-                        sprintf(
249
-                                esc_html__(
250
-                                        'The %s class file could not be located or is not readable due to file permissions.',
251
-                                        'event_espresso'
252
-                                ),
253
-                                $classname
254
-                        )
255
-                );
256
-            }
257
-        }
229
+		/**
230
+		 *    espresso_load_required
231
+		 *    given a class name and path, this function will load that file or throw an exception
232
+		 *
233
+		 * @param    string $classname
234
+		 * @param    string $full_path_to_file
235
+		 * @throws    EE_Error
236
+		 */
237
+		function espresso_load_required($classname, $full_path_to_file)
238
+		{
239
+			static $error_handling_loaded = false;
240
+			if ( ! $error_handling_loaded) {
241
+				espresso_load_error_handling();
242
+				$error_handling_loaded = true;
243
+			}
244
+			if (is_readable($full_path_to_file)) {
245
+				require_once($full_path_to_file);
246
+			} else {
247
+				throw new EE_Error (
248
+						sprintf(
249
+								esc_html__(
250
+										'The %s class file could not be located or is not readable due to file permissions.',
251
+										'event_espresso'
252
+								),
253
+								$classname
254
+						)
255
+				);
256
+			}
257
+		}
258 258
 
259
-        espresso_load_required('EEH_Base', EE_CORE . 'helpers' . DS . 'EEH_Base.helper.php');
260
-        espresso_load_required('EEH_File', EE_CORE . 'helpers' . DS . 'EEH_File.helper.php');
261
-        espresso_load_required('EE_Bootstrap', EE_CORE . 'EE_Bootstrap.core.php');
262
-        new EE_Bootstrap();
263
-    }
259
+		espresso_load_required('EEH_Base', EE_CORE . 'helpers' . DS . 'EEH_Base.helper.php');
260
+		espresso_load_required('EEH_File', EE_CORE . 'helpers' . DS . 'EEH_File.helper.php');
261
+		espresso_load_required('EE_Bootstrap', EE_CORE . 'EE_Bootstrap.core.php');
262
+		new EE_Bootstrap();
263
+	}
264 264
 }
265 265
 if ( ! function_exists('espresso_deactivate_plugin')) {
266
-    /**
267
-     *    deactivate_plugin
268
-     * usage:  espresso_deactivate_plugin( plugin_basename( __FILE__ ));
269
-     *
270
-     * @access public
271
-     * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file
272
-     * @return    void
273
-     */
274
-    function espresso_deactivate_plugin($plugin_basename = '')
275
-    {
276
-        if ( ! function_exists('deactivate_plugins')) {
277
-            require_once(ABSPATH . 'wp-admin/includes/plugin.php');
278
-        }
279
-        unset($_GET['activate'], $_REQUEST['activate']);
280
-        deactivate_plugins($plugin_basename);
281
-    }
266
+	/**
267
+	 *    deactivate_plugin
268
+	 * usage:  espresso_deactivate_plugin( plugin_basename( __FILE__ ));
269
+	 *
270
+	 * @access public
271
+	 * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file
272
+	 * @return    void
273
+	 */
274
+	function espresso_deactivate_plugin($plugin_basename = '')
275
+	{
276
+		if ( ! function_exists('deactivate_plugins')) {
277
+			require_once(ABSPATH . 'wp-admin/includes/plugin.php');
278
+		}
279
+		unset($_GET['activate'], $_REQUEST['activate']);
280
+		deactivate_plugins($plugin_basename);
281
+	}
282 282
 }
283 283
\ No newline at end of file
Please login to merge, or discard this patch.