Completed
Branch BUG-10626-dst-unit-test (8c5dd4)
by
unknown
138:48 queued 126:51
created
core/EE_Cart.core.php 1 patch
Indentation   +413 added lines, -413 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php if ( ! defined('EVENT_ESPRESSO_VERSION')) {
2
-    exit('No direct script access allowed');
2
+	exit('No direct script access allowed');
3 3
 }
4 4
 do_action('AHEE_log', __FILE__, __FUNCTION__, '');
5 5
 
@@ -20,418 +20,418 @@  discard block
 block discarded – undo
20 20
 class EE_Cart
21 21
 {
22 22
 
23
-    /**
24
-     * instance of the EE_Cart object
25
-     *
26
-     * @access    private
27
-     * @var EE_Cart $_instance
28
-     */
29
-    private static $_instance;
30
-
31
-    /**
32
-     * instance of the EE_Session object
33
-     *
34
-     * @access    protected
35
-     * @var EE_Session $_session
36
-     */
37
-    protected $_session;
38
-
39
-    /**
40
-     * The total Line item which comprises all the children line-item subtotals,
41
-     * which in turn each have their line items.
42
-     * Typically, the line item structure will look like:
43
-     * grand total
44
-     * -tickets-sub-total
45
-     * --ticket1
46
-     * --ticket2
47
-     * --...
48
-     * -taxes-sub-total
49
-     * --tax1
50
-     * --tax2
51
-     *
52
-     * @var EE_Line_Item
53
-     */
54
-    private $_grand_total;
55
-
56
-
57
-
58
-    /**
59
-     * @singleton method used to instantiate class object
60
-     * @access    public
61
-     * @param EE_Line_Item $grand_total
62
-     * @param EE_Session   $session
63
-     * @return \EE_Cart
64
-     * @throws \EE_Error
65
-     */
66
-    public static function instance(EE_Line_Item $grand_total = null, EE_Session $session = null)
67
-    {
68
-        if ( ! empty($grand_total)) {
69
-            self::$_instance = new self($grand_total, $session);
70
-        }
71
-        // or maybe retrieve an existing one ?
72
-        if ( ! self::$_instance instanceof EE_Cart) {
73
-            // try getting the cart out of the session
74
-            $saved_cart = $session instanceof EE_Session ? $session->cart() : null;
75
-            self::$_instance = $saved_cart instanceof EE_Cart ? $saved_cart : new self($grand_total, $session);
76
-            unset($saved_cart);
77
-        }
78
-        // verify that cart is ok and grand total line item exists
79
-        if ( ! self::$_instance instanceof EE_Cart || ! self::$_instance->_grand_total instanceof EE_Line_Item) {
80
-            self::$_instance = new self($grand_total, $session);
81
-        }
82
-        self::$_instance->get_grand_total();
83
-        // once everything is all said and done, save the cart to the EE_Session
84
-        add_action('shutdown', array(self::$_instance, 'save_cart'), 90);
85
-        return self::$_instance;
86
-    }
87
-
88
-
89
-
90
-    /**
91
-     * private constructor to prevent direct creation
92
-     *
93
-     * @Constructor
94
-     * @access private
95
-     * @param EE_Line_Item $grand_total
96
-     * @param EE_Session   $session
97
-     */
98
-    private function __construct(EE_Line_Item $grand_total = null, EE_Session $session = null)
99
-    {
100
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
101
-        $this->set_session($session);
102
-        if ($grand_total instanceof EE_Line_Item) {
103
-            $this->set_grand_total_line_item($grand_total);
104
-        }
105
-    }
106
-
107
-
108
-
109
-    /**
110
-     * Resets the cart completely (whereas empty_cart
111
-     *
112
-     * @param EE_Line_Item $grand_total
113
-     * @param EE_Session   $session
114
-     * @return EE_Cart
115
-     * @throws \EE_Error
116
-     */
117
-    public static function reset(EE_Line_Item $grand_total = null, EE_Session $session = null)
118
-    {
119
-        remove_action('shutdown', array(self::$_instance, 'save_cart'), 90);
120
-        if ($session instanceof EE_Session) {
121
-            $session->reset_cart();
122
-        }
123
-        self::$_instance = null;
124
-        return self::instance($grand_total, $session);
125
-    }
126
-
127
-
128
-
129
-    /**
130
-     * @return \EE_Session
131
-     */
132
-    public function session()
133
-    {
134
-        if ( ! $this->_session instanceof EE_Session) {
135
-            $this->set_session();
136
-        }
137
-        return $this->_session;
138
-    }
139
-
140
-
141
-
142
-    /**
143
-     * @param EE_Session $session
144
-     */
145
-    public function set_session(EE_Session $session = null)
146
-    {
147
-        $this->_session = $session instanceof EE_Session ? $session : EE_Registry::instance()->load_core('Session');
148
-    }
149
-
150
-
151
-
152
-    /**
153
-     * Sets the cart to match the line item. Especially handy for loading an old cart where you
154
-     *  know the grand total line item on it
155
-     *
156
-     * @param EE_Line_Item $line_item
157
-     */
158
-    public function set_grand_total_line_item(EE_Line_Item $line_item)
159
-    {
160
-        $this->_grand_total = $line_item;
161
-    }
162
-
163
-
164
-
165
-    /**
166
-     * get_cart_from_reg_url_link
167
-     *
168
-     * @access public
169
-     * @param EE_Transaction $transaction
170
-     * @param EE_Session     $session
171
-     * @return \EE_Cart
172
-     * @throws \EE_Error
173
-     */
174
-    public static function get_cart_from_txn(EE_Transaction $transaction, EE_Session $session = null)
175
-    {
176
-        $grand_total = $transaction->total_line_item();
177
-        $grand_total->get_items();
178
-        $grand_total->tax_descendants();
179
-        return EE_Cart::instance($grand_total, $session);
180
-    }
181
-
182
-
183
-
184
-    /**
185
-     * Creates the total line item, and ensures it has its 'tickets' and 'taxes' sub-items
186
-     *
187
-     * @return EE_Line_Item
188
-     * @throws \EE_Error
189
-     */
190
-    private function _create_grand_total()
191
-    {
192
-        $this->_grand_total = EEH_Line_Item::create_total_line_item();
193
-        return $this->_grand_total;
194
-    }
195
-
196
-
197
-
198
-    /**
199
-     * Gets all the line items of object type Ticket
200
-     *
201
-     * @access public
202
-     * @return \EE_Line_Item[]
203
-     */
204
-    public function get_tickets()
205
-    {
206
-        if ($this->_grand_total === null ) {
207
-            return array();
208
-        }
209
-        return EEH_Line_Item::get_ticket_line_items($this->_grand_total);
210
-    }
211
-
212
-
213
-
214
-    /**
215
-     * returns the total quantity of tickets in the cart
216
-     *
217
-     * @access public
218
-     * @return int
219
-     * @throws \EE_Error
220
-     */
221
-    public function all_ticket_quantity_count()
222
-    {
223
-        $tickets = $this->get_tickets();
224
-        if (empty($tickets)) {
225
-            return 0;
226
-        }
227
-        $count = 0;
228
-        foreach ($tickets as $ticket) {
229
-            $count += $ticket->get('LIN_quantity');
230
-        }
231
-        return $count;
232
-    }
233
-
234
-
235
-
236
-    /**
237
-     * Gets all the tax line items
238
-     *
239
-     * @return \EE_Line_Item[]
240
-     * @throws \EE_Error
241
-     */
242
-    public function get_taxes()
243
-    {
244
-        return EEH_Line_Item::get_taxes_subtotal($this->_grand_total)->children();
245
-    }
246
-
247
-
248
-
249
-    /**
250
-     * Gets the total line item (which is a parent of all other line items) on this cart
251
-     *
252
-     * @return EE_Line_Item
253
-     * @throws \EE_Error
254
-     */
255
-    public function get_grand_total()
256
-    {
257
-        return $this->_grand_total instanceof EE_Line_Item ? $this->_grand_total : $this->_create_grand_total();
258
-    }
259
-
260
-
261
-
262
-    /**
263
-     * @process items for adding to cart
264
-     * @access  public
265
-     * @param EE_Ticket $ticket
266
-     * @param int       $qty
267
-     * @return TRUE on success, FALSE on fail
268
-     * @throws \EE_Error
269
-     */
270
-    public function add_ticket_to_cart(EE_Ticket $ticket, $qty = 1)
271
-    {
272
-        EEH_Line_Item::add_ticket_purchase($this->get_grand_total(), $ticket, $qty);
273
-        return $this->save_cart() ? true : false;
274
-    }
275
-
276
-
277
-
278
-    /**
279
-     * get_cart_total_before_tax
280
-     *
281
-     * @access public
282
-     * @return float
283
-     * @throws \EE_Error
284
-     */
285
-    public function get_cart_total_before_tax()
286
-    {
287
-        return $this->get_grand_total()->recalculate_pre_tax_total();
288
-    }
289
-
290
-
291
-
292
-    /**
293
-     * gets the total amount of tax paid for items in this cart
294
-     *
295
-     * @access public
296
-     * @return float
297
-     * @throws \EE_Error
298
-     */
299
-    public function get_applied_taxes()
300
-    {
301
-        return EEH_Line_Item::ensure_taxes_applied($this->_grand_total);
302
-    }
303
-
304
-
305
-
306
-    /**
307
-     * Gets the total amount to be paid for the items in the cart, including taxes and other modifiers
308
-     *
309
-     * @access public
310
-     * @return float
311
-     * @throws \EE_Error
312
-     */
313
-    public function get_cart_grand_total()
314
-    {
315
-        EEH_Line_Item::ensure_taxes_applied($this->_grand_total);
316
-        return $this->get_grand_total()->total();
317
-    }
318
-
319
-
320
-
321
-    /**
322
-     * Gets the total amount to be paid for the items in the cart, including taxes and other modifiers
323
-     *
324
-     * @access public
325
-     * @return float
326
-     * @throws \EE_Error
327
-     */
328
-    public function recalculate_all_cart_totals()
329
-    {
330
-        $pre_tax_total = $this->get_cart_total_before_tax();
331
-        $taxes_total = EEH_Line_Item::ensure_taxes_applied($this->_grand_total);
332
-        $this->_grand_total->set_total($pre_tax_total + $taxes_total);
333
-        $this->_grand_total->save_this_and_descendants_to_txn();
334
-        return $this->get_grand_total()->total();
335
-    }
336
-
337
-
338
-
339
-    /**
340
-     * deletes an item from the cart
341
-     *
342
-     * @access public
343
-     * @param array|bool|string $line_item_codes
344
-     * @return int on success, FALSE on fail
345
-     * @throws \EE_Error
346
-     */
347
-    public function delete_items($line_item_codes = false)
348
-    {
349
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
350
-        return EEH_Line_Item::delete_items($this->get_grand_total(), $line_item_codes);
351
-    }
352
-
353
-
354
-
355
-    /**
356
-     * @remove ALL items from cart and zero ALL totals
357
-     * @access public
358
-     * @return bool
359
-     * @throws \EE_Error
360
-     */
361
-    public function empty_cart()
362
-    {
363
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
364
-        $this->_grand_total = $this->_create_grand_total();
365
-        return $this->save_cart(true);
366
-    }
367
-
368
-
369
-
370
-    /**
371
-     * @remove ALL items from cart and delete total as well
372
-     * @access public
373
-     * @return bool
374
-     * @throws \EE_Error
375
-     */
376
-    public function delete_cart()
377
-    {
378
-        $deleted = EEH_Line_Item::delete_all_child_items($this->_grand_total);
379
-        if ($deleted) {
380
-            $deleted += $this->_grand_total->delete();
381
-            $this->_grand_total = null;
382
-        }
383
-        return $deleted;
384
-    }
385
-
386
-
387
-
388
-    /**
389
-     * @save   cart to session
390
-     * @access public
391
-     * @param bool $apply_taxes
392
-     * @return TRUE on success, FALSE on fail
393
-     * @throws \EE_Error
394
-     */
395
-    public function save_cart($apply_taxes = true)
396
-    {
397
-        if ($apply_taxes && $this->_grand_total instanceof EE_Line_Item) {
398
-            EEH_Line_Item::ensure_taxes_applied($this->_grand_total);
399
-            //make sure we don't cache the transaction because it can get stale
400
-            if ($this->_grand_total->get_one_from_cache('Transaction') instanceof EE_Transaction
401
-                && $this->_grand_total->get_one_from_cache('Transaction')->ID()
402
-            ) {
403
-                $this->_grand_total->clear_cache('Transaction', null, true);
404
-            }
405
-        }
406
-        if ($this->session() instanceof EE_Session) {
407
-            return $this->session()->set_cart($this);
408
-        } else {
409
-            return false;
410
-        }
411
-    }
412
-
413
-
414
-
415
-    public function __wakeup()
416
-    {
417
-        if ( ! $this->_grand_total instanceof EE_Line_Item && absint($this->_grand_total) !== 0) {
418
-            // $this->_grand_total is actually just an ID, so use it to get the object from the db
419
-            $this->_grand_total = EEM_Line_Item::instance()->get_one_by_ID($this->_grand_total);
420
-        }
421
-    }
422
-
423
-
424
-
425
-    /**
426
-     * @return array
427
-     */
428
-    public function __sleep()
429
-    {
430
-        if ($this->_grand_total instanceof EE_Line_Item && $this->_grand_total->ID()) {
431
-            $this->_grand_total = $this->_grand_total->ID();
432
-        }
433
-        return array('_grand_total');
434
-    }
23
+	/**
24
+	 * instance of the EE_Cart object
25
+	 *
26
+	 * @access    private
27
+	 * @var EE_Cart $_instance
28
+	 */
29
+	private static $_instance;
30
+
31
+	/**
32
+	 * instance of the EE_Session object
33
+	 *
34
+	 * @access    protected
35
+	 * @var EE_Session $_session
36
+	 */
37
+	protected $_session;
38
+
39
+	/**
40
+	 * The total Line item which comprises all the children line-item subtotals,
41
+	 * which in turn each have their line items.
42
+	 * Typically, the line item structure will look like:
43
+	 * grand total
44
+	 * -tickets-sub-total
45
+	 * --ticket1
46
+	 * --ticket2
47
+	 * --...
48
+	 * -taxes-sub-total
49
+	 * --tax1
50
+	 * --tax2
51
+	 *
52
+	 * @var EE_Line_Item
53
+	 */
54
+	private $_grand_total;
55
+
56
+
57
+
58
+	/**
59
+	 * @singleton method used to instantiate class object
60
+	 * @access    public
61
+	 * @param EE_Line_Item $grand_total
62
+	 * @param EE_Session   $session
63
+	 * @return \EE_Cart
64
+	 * @throws \EE_Error
65
+	 */
66
+	public static function instance(EE_Line_Item $grand_total = null, EE_Session $session = null)
67
+	{
68
+		if ( ! empty($grand_total)) {
69
+			self::$_instance = new self($grand_total, $session);
70
+		}
71
+		// or maybe retrieve an existing one ?
72
+		if ( ! self::$_instance instanceof EE_Cart) {
73
+			// try getting the cart out of the session
74
+			$saved_cart = $session instanceof EE_Session ? $session->cart() : null;
75
+			self::$_instance = $saved_cart instanceof EE_Cart ? $saved_cart : new self($grand_total, $session);
76
+			unset($saved_cart);
77
+		}
78
+		// verify that cart is ok and grand total line item exists
79
+		if ( ! self::$_instance instanceof EE_Cart || ! self::$_instance->_grand_total instanceof EE_Line_Item) {
80
+			self::$_instance = new self($grand_total, $session);
81
+		}
82
+		self::$_instance->get_grand_total();
83
+		// once everything is all said and done, save the cart to the EE_Session
84
+		add_action('shutdown', array(self::$_instance, 'save_cart'), 90);
85
+		return self::$_instance;
86
+	}
87
+
88
+
89
+
90
+	/**
91
+	 * private constructor to prevent direct creation
92
+	 *
93
+	 * @Constructor
94
+	 * @access private
95
+	 * @param EE_Line_Item $grand_total
96
+	 * @param EE_Session   $session
97
+	 */
98
+	private function __construct(EE_Line_Item $grand_total = null, EE_Session $session = null)
99
+	{
100
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
101
+		$this->set_session($session);
102
+		if ($grand_total instanceof EE_Line_Item) {
103
+			$this->set_grand_total_line_item($grand_total);
104
+		}
105
+	}
106
+
107
+
108
+
109
+	/**
110
+	 * Resets the cart completely (whereas empty_cart
111
+	 *
112
+	 * @param EE_Line_Item $grand_total
113
+	 * @param EE_Session   $session
114
+	 * @return EE_Cart
115
+	 * @throws \EE_Error
116
+	 */
117
+	public static function reset(EE_Line_Item $grand_total = null, EE_Session $session = null)
118
+	{
119
+		remove_action('shutdown', array(self::$_instance, 'save_cart'), 90);
120
+		if ($session instanceof EE_Session) {
121
+			$session->reset_cart();
122
+		}
123
+		self::$_instance = null;
124
+		return self::instance($grand_total, $session);
125
+	}
126
+
127
+
128
+
129
+	/**
130
+	 * @return \EE_Session
131
+	 */
132
+	public function session()
133
+	{
134
+		if ( ! $this->_session instanceof EE_Session) {
135
+			$this->set_session();
136
+		}
137
+		return $this->_session;
138
+	}
139
+
140
+
141
+
142
+	/**
143
+	 * @param EE_Session $session
144
+	 */
145
+	public function set_session(EE_Session $session = null)
146
+	{
147
+		$this->_session = $session instanceof EE_Session ? $session : EE_Registry::instance()->load_core('Session');
148
+	}
149
+
150
+
151
+
152
+	/**
153
+	 * Sets the cart to match the line item. Especially handy for loading an old cart where you
154
+	 *  know the grand total line item on it
155
+	 *
156
+	 * @param EE_Line_Item $line_item
157
+	 */
158
+	public function set_grand_total_line_item(EE_Line_Item $line_item)
159
+	{
160
+		$this->_grand_total = $line_item;
161
+	}
162
+
163
+
164
+
165
+	/**
166
+	 * get_cart_from_reg_url_link
167
+	 *
168
+	 * @access public
169
+	 * @param EE_Transaction $transaction
170
+	 * @param EE_Session     $session
171
+	 * @return \EE_Cart
172
+	 * @throws \EE_Error
173
+	 */
174
+	public static function get_cart_from_txn(EE_Transaction $transaction, EE_Session $session = null)
175
+	{
176
+		$grand_total = $transaction->total_line_item();
177
+		$grand_total->get_items();
178
+		$grand_total->tax_descendants();
179
+		return EE_Cart::instance($grand_total, $session);
180
+	}
181
+
182
+
183
+
184
+	/**
185
+	 * Creates the total line item, and ensures it has its 'tickets' and 'taxes' sub-items
186
+	 *
187
+	 * @return EE_Line_Item
188
+	 * @throws \EE_Error
189
+	 */
190
+	private function _create_grand_total()
191
+	{
192
+		$this->_grand_total = EEH_Line_Item::create_total_line_item();
193
+		return $this->_grand_total;
194
+	}
195
+
196
+
197
+
198
+	/**
199
+	 * Gets all the line items of object type Ticket
200
+	 *
201
+	 * @access public
202
+	 * @return \EE_Line_Item[]
203
+	 */
204
+	public function get_tickets()
205
+	{
206
+		if ($this->_grand_total === null ) {
207
+			return array();
208
+		}
209
+		return EEH_Line_Item::get_ticket_line_items($this->_grand_total);
210
+	}
211
+
212
+
213
+
214
+	/**
215
+	 * returns the total quantity of tickets in the cart
216
+	 *
217
+	 * @access public
218
+	 * @return int
219
+	 * @throws \EE_Error
220
+	 */
221
+	public function all_ticket_quantity_count()
222
+	{
223
+		$tickets = $this->get_tickets();
224
+		if (empty($tickets)) {
225
+			return 0;
226
+		}
227
+		$count = 0;
228
+		foreach ($tickets as $ticket) {
229
+			$count += $ticket->get('LIN_quantity');
230
+		}
231
+		return $count;
232
+	}
233
+
234
+
235
+
236
+	/**
237
+	 * Gets all the tax line items
238
+	 *
239
+	 * @return \EE_Line_Item[]
240
+	 * @throws \EE_Error
241
+	 */
242
+	public function get_taxes()
243
+	{
244
+		return EEH_Line_Item::get_taxes_subtotal($this->_grand_total)->children();
245
+	}
246
+
247
+
248
+
249
+	/**
250
+	 * Gets the total line item (which is a parent of all other line items) on this cart
251
+	 *
252
+	 * @return EE_Line_Item
253
+	 * @throws \EE_Error
254
+	 */
255
+	public function get_grand_total()
256
+	{
257
+		return $this->_grand_total instanceof EE_Line_Item ? $this->_grand_total : $this->_create_grand_total();
258
+	}
259
+
260
+
261
+
262
+	/**
263
+	 * @process items for adding to cart
264
+	 * @access  public
265
+	 * @param EE_Ticket $ticket
266
+	 * @param int       $qty
267
+	 * @return TRUE on success, FALSE on fail
268
+	 * @throws \EE_Error
269
+	 */
270
+	public function add_ticket_to_cart(EE_Ticket $ticket, $qty = 1)
271
+	{
272
+		EEH_Line_Item::add_ticket_purchase($this->get_grand_total(), $ticket, $qty);
273
+		return $this->save_cart() ? true : false;
274
+	}
275
+
276
+
277
+
278
+	/**
279
+	 * get_cart_total_before_tax
280
+	 *
281
+	 * @access public
282
+	 * @return float
283
+	 * @throws \EE_Error
284
+	 */
285
+	public function get_cart_total_before_tax()
286
+	{
287
+		return $this->get_grand_total()->recalculate_pre_tax_total();
288
+	}
289
+
290
+
291
+
292
+	/**
293
+	 * gets the total amount of tax paid for items in this cart
294
+	 *
295
+	 * @access public
296
+	 * @return float
297
+	 * @throws \EE_Error
298
+	 */
299
+	public function get_applied_taxes()
300
+	{
301
+		return EEH_Line_Item::ensure_taxes_applied($this->_grand_total);
302
+	}
303
+
304
+
305
+
306
+	/**
307
+	 * Gets the total amount to be paid for the items in the cart, including taxes and other modifiers
308
+	 *
309
+	 * @access public
310
+	 * @return float
311
+	 * @throws \EE_Error
312
+	 */
313
+	public function get_cart_grand_total()
314
+	{
315
+		EEH_Line_Item::ensure_taxes_applied($this->_grand_total);
316
+		return $this->get_grand_total()->total();
317
+	}
318
+
319
+
320
+
321
+	/**
322
+	 * Gets the total amount to be paid for the items in the cart, including taxes and other modifiers
323
+	 *
324
+	 * @access public
325
+	 * @return float
326
+	 * @throws \EE_Error
327
+	 */
328
+	public function recalculate_all_cart_totals()
329
+	{
330
+		$pre_tax_total = $this->get_cart_total_before_tax();
331
+		$taxes_total = EEH_Line_Item::ensure_taxes_applied($this->_grand_total);
332
+		$this->_grand_total->set_total($pre_tax_total + $taxes_total);
333
+		$this->_grand_total->save_this_and_descendants_to_txn();
334
+		return $this->get_grand_total()->total();
335
+	}
336
+
337
+
338
+
339
+	/**
340
+	 * deletes an item from the cart
341
+	 *
342
+	 * @access public
343
+	 * @param array|bool|string $line_item_codes
344
+	 * @return int on success, FALSE on fail
345
+	 * @throws \EE_Error
346
+	 */
347
+	public function delete_items($line_item_codes = false)
348
+	{
349
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
350
+		return EEH_Line_Item::delete_items($this->get_grand_total(), $line_item_codes);
351
+	}
352
+
353
+
354
+
355
+	/**
356
+	 * @remove ALL items from cart and zero ALL totals
357
+	 * @access public
358
+	 * @return bool
359
+	 * @throws \EE_Error
360
+	 */
361
+	public function empty_cart()
362
+	{
363
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
364
+		$this->_grand_total = $this->_create_grand_total();
365
+		return $this->save_cart(true);
366
+	}
367
+
368
+
369
+
370
+	/**
371
+	 * @remove ALL items from cart and delete total as well
372
+	 * @access public
373
+	 * @return bool
374
+	 * @throws \EE_Error
375
+	 */
376
+	public function delete_cart()
377
+	{
378
+		$deleted = EEH_Line_Item::delete_all_child_items($this->_grand_total);
379
+		if ($deleted) {
380
+			$deleted += $this->_grand_total->delete();
381
+			$this->_grand_total = null;
382
+		}
383
+		return $deleted;
384
+	}
385
+
386
+
387
+
388
+	/**
389
+	 * @save   cart to session
390
+	 * @access public
391
+	 * @param bool $apply_taxes
392
+	 * @return TRUE on success, FALSE on fail
393
+	 * @throws \EE_Error
394
+	 */
395
+	public function save_cart($apply_taxes = true)
396
+	{
397
+		if ($apply_taxes && $this->_grand_total instanceof EE_Line_Item) {
398
+			EEH_Line_Item::ensure_taxes_applied($this->_grand_total);
399
+			//make sure we don't cache the transaction because it can get stale
400
+			if ($this->_grand_total->get_one_from_cache('Transaction') instanceof EE_Transaction
401
+				&& $this->_grand_total->get_one_from_cache('Transaction')->ID()
402
+			) {
403
+				$this->_grand_total->clear_cache('Transaction', null, true);
404
+			}
405
+		}
406
+		if ($this->session() instanceof EE_Session) {
407
+			return $this->session()->set_cart($this);
408
+		} else {
409
+			return false;
410
+		}
411
+	}
412
+
413
+
414
+
415
+	public function __wakeup()
416
+	{
417
+		if ( ! $this->_grand_total instanceof EE_Line_Item && absint($this->_grand_total) !== 0) {
418
+			// $this->_grand_total is actually just an ID, so use it to get the object from the db
419
+			$this->_grand_total = EEM_Line_Item::instance()->get_one_by_ID($this->_grand_total);
420
+		}
421
+	}
422
+
423
+
424
+
425
+	/**
426
+	 * @return array
427
+	 */
428
+	public function __sleep()
429
+	{
430
+		if ($this->_grand_total instanceof EE_Line_Item && $this->_grand_total->ID()) {
431
+			$this->_grand_total = $this->_grand_total->ID();
432
+		}
433
+		return array('_grand_total');
434
+	}
435 435
 
436 436
 
437 437
 }
Please login to merge, or discard this patch.
core/helpers/EEH_File.helper.php 2 patches
Spacing   +176 added lines, -176 removed lines patch added patch discarded remove patch
@@ -12,8 +12,8 @@  discard block
 block discarded – undo
12 12
  * @ version		 	4.0
13 13
  *
14 14
  */
15
-require_once( EE_HELPERS . 'EEH_Base.helper.php' );
16
-require_once( EE_INTERFACES . 'EEI_Interfaces.php' );
15
+require_once(EE_HELPERS.'EEH_Base.helper.php');
16
+require_once(EE_INTERFACES.'EEI_Interfaces.php');
17 17
 /**
18 18
  *
19 19
  * Class EEH_File
@@ -52,30 +52,30 @@  discard block
 block discarded – undo
52 52
 	 * @throws EE_Error if filesystem credentials are required
53 53
 	 * @return WP_Filesystem_Base
54 54
 	 */
55
-	private static function _get_wp_filesystem( $filepath = null) {
56
-		if( apply_filters(
55
+	private static function _get_wp_filesystem($filepath = null) {
56
+		if (apply_filters(
57 57
 				'FHEE__EEH_File___get_wp_filesystem__allow_using_filesystem_direct',
58
-				$filepath && EEH_File::is_in_uploads_folder( $filepath ),
59
-				$filepath ) ) {
60
-			if( ! EEH_File::$_wp_filesystem_direct instanceof WP_Filesystem_Direct ) {
61
-				require_once(ABSPATH . 'wp-admin/includes/class-wp-filesystem-base.php');
58
+				$filepath && EEH_File::is_in_uploads_folder($filepath),
59
+				$filepath )) {
60
+			if ( ! EEH_File::$_wp_filesystem_direct instanceof WP_Filesystem_Direct) {
61
+				require_once(ABSPATH.'wp-admin/includes/class-wp-filesystem-base.php');
62 62
 				$method = 'direct';
63
-				$wp_filesystem_direct_file = apply_filters( 'filesystem_method_file', ABSPATH . 'wp-admin/includes/class-wp-filesystem-' . $method . '.php', $method );
63
+				$wp_filesystem_direct_file = apply_filters('filesystem_method_file', ABSPATH.'wp-admin/includes/class-wp-filesystem-'.$method.'.php', $method);
64 64
 				//check constants defined, just like in wp-admin/includes/file.php's WP_Filesystem()
65
-				if ( ! defined('FS_CHMOD_DIR') ) {
66
-					define('FS_CHMOD_DIR', ( fileperms( ABSPATH ) & 0777 | 0755 ) );
65
+				if ( ! defined('FS_CHMOD_DIR')) {
66
+					define('FS_CHMOD_DIR', (fileperms(ABSPATH) & 0777 | 0755));
67 67
 				}
68
-				if ( ! defined('FS_CHMOD_FILE') ) {
69
-					define('FS_CHMOD_FILE', ( fileperms( ABSPATH . 'index.php' ) & 0777 | 0644 ) );
68
+				if ( ! defined('FS_CHMOD_FILE')) {
69
+					define('FS_CHMOD_FILE', (fileperms(ABSPATH.'index.php') & 0777 | 0644));
70 70
 				}
71
-				require_once( $wp_filesystem_direct_file );
72
-				EEH_File::$_wp_filesystem_direct = new WP_Filesystem_Direct( array() );
71
+				require_once($wp_filesystem_direct_file);
72
+				EEH_File::$_wp_filesystem_direct = new WP_Filesystem_Direct(array());
73 73
 			}
74 74
 			return EEH_File::$_wp_filesystem_direct;
75 75
 		}
76 76
 		global $wp_filesystem;
77 77
 		// no filesystem setup ???
78
-		if ( ! $wp_filesystem instanceof WP_Filesystem_Base ) {
78
+		if ( ! $wp_filesystem instanceof WP_Filesystem_Base) {
79 79
 			// if some eager beaver's just trying to get in there too early...
80 80
 			// let them do it, because we are one of those eager beavers! :P
81 81
 			/**
@@ -88,34 +88,34 @@  discard block
 block discarded – undo
88 88
 			 * and there may be troubles if the WP files are owned by a different user
89 89
 			 * than the server user. But both of these issues should exist in 4.4 and earlier too
90 90
 			 */
91
-			if ( FALSE && ! did_action( 'wp_loaded' )) {
91
+			if (FALSE && ! did_action('wp_loaded')) {
92 92
 				$msg = __('An attempt to access and/or write to a file on the server could not be completed due to a lack of sufficient credentials.', 'event_espresso');
93
-				if ( WP_DEBUG ) {
94
-					$msg .= '<br />' .  __('The WP Filesystem can not be accessed until after the "wp_loaded" hook has run, so it\'s best not to attempt access until the "admin_init" hookpoint.', 'event_espresso');
93
+				if (WP_DEBUG) {
94
+					$msg .= '<br />'.__('The WP Filesystem can not be accessed until after the "wp_loaded" hook has run, so it\'s best not to attempt access until the "admin_init" hookpoint.', 'event_espresso');
95 95
 				}
96
-				throw new EE_Error( $msg );
96
+				throw new EE_Error($msg);
97 97
 			} else {
98 98
 				// should be loaded if we are past the wp_loaded hook...
99
-				if ( ! function_exists( 'WP_Filesystem' )) {
100
-					require_once( ABSPATH . 'wp-admin/includes/file.php' );
101
-					require_once( ABSPATH . 'wp-admin/includes/template.php' );
99
+				if ( ! function_exists('WP_Filesystem')) {
100
+					require_once(ABSPATH.'wp-admin/includes/file.php');
101
+					require_once(ABSPATH.'wp-admin/includes/template.php');
102 102
 				}
103 103
 				// turn on output buffering so that we can capture the credentials form
104 104
 				ob_start();
105
-				$credentials = request_filesystem_credentials( '' );
105
+				$credentials = request_filesystem_credentials('');
106 106
 				// store credentials form for the time being
107 107
 				EEH_File::$_credentials_form = ob_get_clean();
108 108
 				// basically check for direct or previously configured access
109
-				if ( ! WP_Filesystem( $credentials ) ) {
109
+				if ( ! WP_Filesystem($credentials)) {
110 110
 					// if credentials do NOT exist
111
-					if ( $credentials === FALSE ) {
112
-						add_action( 'admin_notices', array( 'EEH_File', 'display_request_filesystem_credentials_form' ), 999 );
113
-						throw new EE_Error( __('An attempt to access and/or write to a file on the server could not be completed due to a lack of sufficient credentials.', 'event_espresso'));
114
-					} elseif( is_wp_error( $wp_filesystem->errors ) && $wp_filesystem->errors->get_error_code() ) {
115
-						add_action( 'admin_notices', array( 'EEH_File', 'display_request_filesystem_credentials_form' ), 999 );
111
+					if ($credentials === FALSE) {
112
+						add_action('admin_notices', array('EEH_File', 'display_request_filesystem_credentials_form'), 999);
113
+						throw new EE_Error(__('An attempt to access and/or write to a file on the server could not be completed due to a lack of sufficient credentials.', 'event_espresso'));
114
+					} elseif (is_wp_error($wp_filesystem->errors) && $wp_filesystem->errors->get_error_code()) {
115
+						add_action('admin_notices', array('EEH_File', 'display_request_filesystem_credentials_form'), 999);
116 116
 						throw new EE_Error(
117 117
 								sprintf(
118
-										__( 'WP Filesystem Error: $1%s', 'event_espresso' ),
118
+										__('WP Filesystem Error: $1%s', 'event_espresso'),
119 119
 										$wp_filesystem->errors->get_error_message() ) );
120 120
 					}
121 121
 				}
@@ -128,8 +128,8 @@  discard block
 block discarded – undo
128 128
 	 * display_request_filesystem_credentials_form
129 129
 	 */
130 130
 	public static function display_request_filesystem_credentials_form() {
131
-		if ( ! empty( EEH_File::$_credentials_form )) {
132
-			echo '<div class="updated espresso-notices-attention"><p>' . EEH_File::$_credentials_form . '</p></div>';
131
+		if ( ! empty(EEH_File::$_credentials_form)) {
132
+			echo '<div class="updated espresso-notices-attention"><p>'.EEH_File::$_credentials_form.'</p></div>';
133 133
 		}
134 134
 	}
135 135
 
@@ -147,29 +147,29 @@  discard block
 block discarded – undo
147 147
 	 * @throws EE_Error if filesystem credentials are required
148 148
 	 * @return bool
149 149
 	 */
150
-	public static function verify_filepath_and_permissions( $full_file_path = '', $file_name = '', $file_ext = '', $type_of_file = '' ) {
150
+	public static function verify_filepath_and_permissions($full_file_path = '', $file_name = '', $file_ext = '', $type_of_file = '') {
151 151
 		// load WP_Filesystem and set file permissions
152
-		$wp_filesystem = EEH_File::_get_wp_filesystem( $full_file_path );
153
-		$full_file_path = EEH_File::standardise_directory_separators( $full_file_path );
154
-		if ( ! $wp_filesystem->is_readable( EEH_File::convert_local_filepath_to_remote_filepath( $full_file_path ) )) {
155
-			$file_name = ! empty( $type_of_file ) ? $file_name . ' ' . $type_of_file : $file_name;
156
-			$file_name .= ! empty( $file_ext ) ? ' file' : ' folder';
152
+		$wp_filesystem = EEH_File::_get_wp_filesystem($full_file_path);
153
+		$full_file_path = EEH_File::standardise_directory_separators($full_file_path);
154
+		if ( ! $wp_filesystem->is_readable(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path))) {
155
+			$file_name = ! empty($type_of_file) ? $file_name.' '.$type_of_file : $file_name;
156
+			$file_name .= ! empty($file_ext) ? ' file' : ' folder';
157 157
 			$msg = sprintf(
158
-				__( 'The requested %1$s could not be found or is not readable, possibly due to an incorrect filepath, or incorrect file permissions.%2$s', 'event_espresso' ),
158
+				__('The requested %1$s could not be found or is not readable, possibly due to an incorrect filepath, or incorrect file permissions.%2$s', 'event_espresso'),
159 159
 				$file_name,
160 160
 				'<br />'
161 161
 			);
162
-			if ( EEH_File::exists( $full_file_path )) {
163
-				$msg .= EEH_File::_permissions_error_for_unreadable_filepath( $full_file_path, $type_of_file );
162
+			if (EEH_File::exists($full_file_path)) {
163
+				$msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_file_path, $type_of_file);
164 164
 			} else {
165 165
 				// no file permissions means the file was not found
166 166
 				$msg .= sprintf(
167
-					__( 'Please ensure the following path is correct: "%s".', 'event_espresso' ),
167
+					__('Please ensure the following path is correct: "%s".', 'event_espresso'),
168 168
 					$full_file_path
169 169
 				);
170 170
 			}
171
-			if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
172
-				throw new EE_Error( $msg . '||' . $msg );
171
+			if (defined('WP_DEBUG') && WP_DEBUG) {
172
+				throw new EE_Error($msg.'||'.$msg);
173 173
 			}
174 174
 			return FALSE;
175 175
 		}
@@ -187,24 +187,24 @@  discard block
 block discarded – undo
187 187
 	 * @throws EE_Error if filesystem credentials are required
188 188
 	 * @return string
189 189
 	 */
190
-	private static function _permissions_error_for_unreadable_filepath( $full_file_path = '', $type_of_file = '' ){
190
+	private static function _permissions_error_for_unreadable_filepath($full_file_path = '', $type_of_file = '') {
191 191
 		// load WP_Filesystem and set file permissions
192
-		$wp_filesystem = EEH_File::_get_wp_filesystem( $full_file_path );
192
+		$wp_filesystem = EEH_File::_get_wp_filesystem($full_file_path);
193 193
 		// check file permissions
194
-		$perms = $wp_filesystem->getchmod( EEH_File::convert_local_filepath_to_remote_filepath( $full_file_path ) );
195
-		if ( $perms ) {
194
+		$perms = $wp_filesystem->getchmod(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path));
195
+		if ($perms) {
196 196
 			// file permissions exist, but way be set incorrectly
197
-			$type_of_file = ! empty( $type_of_file ) ? $type_of_file . ' ' : '';
198
-			$type_of_file .= ! empty( $type_of_file ) ? 'file' : 'folder';
197
+			$type_of_file = ! empty($type_of_file) ? $type_of_file.' ' : '';
198
+			$type_of_file .= ! empty($type_of_file) ? 'file' : 'folder';
199 199
 			return sprintf(
200
-				__( 'File permissions for the requested %1$s are currently set at "%2$s". The recommended permissions are 644 for files and 755 for folders.', 'event_espresso' ),
200
+				__('File permissions for the requested %1$s are currently set at "%2$s". The recommended permissions are 644 for files and 755 for folders.', 'event_espresso'),
201 201
 				$type_of_file,
202 202
 				$perms
203 203
 			);
204 204
 		} else {
205 205
 			// file exists but file permissions could not be read ?!?!
206 206
 			return sprintf(
207
-				__( 'Please ensure that the server and/or PHP configuration allows the current process to access the following file: "%s".', 'event_espresso' ),
207
+				__('Please ensure that the server and/or PHP configuration allows the current process to access the following file: "%s".', 'event_espresso'),
208 208
 				$full_file_path
209 209
 			);
210 210
 		}
@@ -222,35 +222,35 @@  discard block
 block discarded – undo
222 222
 	 * can't write to it
223 223
 	 * @return bool false if folder isn't writable; true if it exists and is writeable,
224 224
 	 */
225
-	public static function ensure_folder_exists_and_is_writable( $folder = '' ){
226
-		if ( empty( $folder )) {
225
+	public static function ensure_folder_exists_and_is_writable($folder = '') {
226
+		if (empty($folder)) {
227 227
 			return false;
228 228
 		}
229 229
 		// remove ending DS
230
-		$folder = EEH_File::standardise_directory_separators( rtrim( $folder, '/\\' ));
231
-		$parent_folder = EEH_File::get_parent_folder( $folder );
230
+		$folder = EEH_File::standardise_directory_separators(rtrim($folder, '/\\'));
231
+		$parent_folder = EEH_File::get_parent_folder($folder);
232 232
 		// add DS to folder
233
-		$folder = EEH_File::end_with_directory_separator( $folder );
234
-		$wp_filesystem = EEH_File::_get_wp_filesystem( $folder );
235
-		if ( ! $wp_filesystem->is_dir( EEH_File::convert_local_filepath_to_remote_filepath( $folder ) ) ) {
233
+		$folder = EEH_File::end_with_directory_separator($folder);
234
+		$wp_filesystem = EEH_File::_get_wp_filesystem($folder);
235
+		if ( ! $wp_filesystem->is_dir(EEH_File::convert_local_filepath_to_remote_filepath($folder))) {
236 236
 			//ok so it doesn't exist. Does its parent? Can we write to it?
237
-			if(	! EEH_File::ensure_folder_exists_and_is_writable( $parent_folder ) ) {
237
+			if ( ! EEH_File::ensure_folder_exists_and_is_writable($parent_folder)) {
238 238
 				return false;
239 239
 			}
240
-			if ( ! EEH_File::verify_is_writable( $parent_folder, 'folder' )) {
240
+			if ( ! EEH_File::verify_is_writable($parent_folder, 'folder')) {
241 241
 				return false;
242 242
 			} else {
243
-				if ( ! $wp_filesystem->mkdir( EEH_File::convert_local_filepath_to_remote_filepath(  $folder ) ) ) {
244
-					if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
245
-						$msg = sprintf( __( '"%s" could not be created.', 'event_espresso' ), $folder );
246
-						$msg .= EEH_File::_permissions_error_for_unreadable_filepath( $folder );
247
-						throw new EE_Error( $msg );
243
+				if ( ! $wp_filesystem->mkdir(EEH_File::convert_local_filepath_to_remote_filepath($folder))) {
244
+					if (defined('WP_DEBUG') && WP_DEBUG) {
245
+						$msg = sprintf(__('"%s" could not be created.', 'event_espresso'), $folder);
246
+						$msg .= EEH_File::_permissions_error_for_unreadable_filepath($folder);
247
+						throw new EE_Error($msg);
248 248
 					}
249 249
 					return false;
250 250
 				}
251
-				EEH_File::add_index_file( $folder );
251
+				EEH_File::add_index_file($folder);
252 252
 			}
253
-		} elseif ( ! EEH_File::verify_is_writable( $folder, 'folder' )) {
253
+		} elseif ( ! EEH_File::verify_is_writable($folder, 'folder')) {
254 254
 			return false;
255 255
 		}
256 256
 		return true;
@@ -265,15 +265,15 @@  discard block
 block discarded – undo
265 265
 	 * @throws EE_Error if filesystem credentials are required
266 266
 	 * @return bool
267 267
 	 */
268
-	public static function verify_is_writable( $full_path = '', $file_or_folder = 'folder' ){
268
+	public static function verify_is_writable($full_path = '', $file_or_folder = 'folder') {
269 269
 		// load WP_Filesystem and set file permissions
270
-		$wp_filesystem = EEH_File::_get_wp_filesystem( $full_path );
271
-		$full_path = EEH_File::standardise_directory_separators( $full_path );
272
-		if ( ! $wp_filesystem->is_writable( EEH_File::convert_local_filepath_to_remote_filepath( $full_path ) ) ) {
273
-			if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
274
-				$msg = sprintf( __( 'The "%1$s" %2$s is not writable.', 'event_espresso' ), $full_path, $file_or_folder );
275
-				$msg .= EEH_File::_permissions_error_for_unreadable_filepath( $full_path );
276
-				throw new EE_Error( $msg );
270
+		$wp_filesystem = EEH_File::_get_wp_filesystem($full_path);
271
+		$full_path = EEH_File::standardise_directory_separators($full_path);
272
+		if ( ! $wp_filesystem->is_writable(EEH_File::convert_local_filepath_to_remote_filepath($full_path))) {
273
+			if (defined('WP_DEBUG') && WP_DEBUG) {
274
+				$msg = sprintf(__('The "%1$s" %2$s is not writable.', 'event_espresso'), $full_path, $file_or_folder);
275
+				$msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_path);
276
+				throw new EE_Error($msg);
277 277
 			}
278 278
 			return FALSE;
279 279
 		}
@@ -290,25 +290,25 @@  discard block
 block discarded – undo
290 290
 	 * @throws EE_Error if filesystem credentials are required
291 291
 	 * @return bool
292 292
 	 */
293
-	public static function ensure_file_exists_and_is_writable( $full_file_path = '' ) {
293
+	public static function ensure_file_exists_and_is_writable($full_file_path = '') {
294 294
 		// load WP_Filesystem and set file permissions
295
-		$wp_filesystem = EEH_File::_get_wp_filesystem( $full_file_path );
296
-		$full_file_path = EEH_File::standardise_directory_separators( $full_file_path );
297
-		$parent_folder = EEH_File::get_parent_folder( $full_file_path );
298
-		if ( ! EEH_File::exists( $full_file_path )) {
299
-			if( ! EEH_File::ensure_folder_exists_and_is_writable( $parent_folder ) ) {
295
+		$wp_filesystem = EEH_File::_get_wp_filesystem($full_file_path);
296
+		$full_file_path = EEH_File::standardise_directory_separators($full_file_path);
297
+		$parent_folder = EEH_File::get_parent_folder($full_file_path);
298
+		if ( ! EEH_File::exists($full_file_path)) {
299
+			if ( ! EEH_File::ensure_folder_exists_and_is_writable($parent_folder)) {
300 300
 				return false;
301 301
 			}
302
-			if ( ! $wp_filesystem->touch( EEH_File::convert_local_filepath_to_remote_filepath( $full_file_path ) ) ) {
303
-				if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
304
-					$msg = sprintf( __( 'The "%s" file could not be created.', 'event_espresso' ), $full_file_path );
305
-					$msg .= EEH_File::_permissions_error_for_unreadable_filepath( $full_file_path );
306
-					throw new EE_Error( $msg );
302
+			if ( ! $wp_filesystem->touch(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path))) {
303
+				if (defined('WP_DEBUG') && WP_DEBUG) {
304
+					$msg = sprintf(__('The "%s" file could not be created.', 'event_espresso'), $full_file_path);
305
+					$msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_file_path);
306
+					throw new EE_Error($msg);
307 307
 				}
308 308
 				return false;
309 309
 			}
310 310
 		}
311
-		if ( ! EEH_File::verify_is_writable( $full_file_path, 'file' )) {
311
+		if ( ! EEH_File::verify_is_writable($full_file_path, 'file')) {
312 312
 			return false;
313 313
 		}
314 314
 		return true;
@@ -320,7 +320,7 @@  discard block
 block discarded – undo
320 320
 	 * @param string $file_or_folder_path
321 321
 	 * @return string parent folder, ENDING with a directory separator
322 322
 	 */
323
-	public static function get_parent_folder( $file_or_folder_path ) {
323
+	public static function get_parent_folder($file_or_folder_path) {
324 324
 		//find the last DS, ignoring a DS on the very end
325 325
 		//eg if given "/var/something/somewhere/", we want to get "somewhere"'s
326 326
 		//parent folder, "/var/something/"
@@ -342,12 +342,12 @@  discard block
 block discarded – undo
342 342
 	 * @throws EE_Error if filesystem credentials are required
343 343
 	 * @return string
344 344
 	 */
345
-	public static function get_file_contents( $full_file_path = '' ){
346
-		$full_file_path = EEH_File::standardise_directory_separators( $full_file_path );
347
-		if ( EEH_File::verify_filepath_and_permissions( $full_file_path, EEH_File::get_filename_from_filepath( $full_file_path ) , EEH_File::get_file_extension( $full_file_path ))) {
345
+	public static function get_file_contents($full_file_path = '') {
346
+		$full_file_path = EEH_File::standardise_directory_separators($full_file_path);
347
+		if (EEH_File::verify_filepath_and_permissions($full_file_path, EEH_File::get_filename_from_filepath($full_file_path), EEH_File::get_file_extension($full_file_path))) {
348 348
 			// load WP_Filesystem and set file permissions
349
-			$wp_filesystem = EEH_File::_get_wp_filesystem( $full_file_path );
350
-			return $wp_filesystem->get_contents(EEH_File::convert_local_filepath_to_remote_filepath( $full_file_path ) );
349
+			$wp_filesystem = EEH_File::_get_wp_filesystem($full_file_path);
350
+			return $wp_filesystem->get_contents(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path));
351 351
 		}
352 352
 		return '';
353 353
 	}
@@ -362,26 +362,26 @@  discard block
 block discarded – undo
362 362
 	 * @throws EE_Error if filesystem credentials are required
363 363
 	 * @return bool
364 364
 	 */
365
-	public static function write_to_file( $full_file_path = '', $file_contents = '', $file_type = '' ){
366
-		$full_file_path = EEH_File::standardise_directory_separators( $full_file_path );
367
-		$file_type = ! empty( $file_type ) ? rtrim( $file_type, ' ' ) . ' ' : '';
368
-		$folder = EEH_File::remove_filename_from_filepath( $full_file_path );
369
-		if ( ! EEH_File::verify_is_writable( $folder, 'folder' )) {
370
-			if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
371
-				$msg = sprintf( __( 'The %1$sfile located at "%2$s" is not writable.', 'event_espresso' ), $file_type, $full_file_path );
372
-				$msg .= EEH_File::_permissions_error_for_unreadable_filepath( $full_file_path );
373
-				throw new EE_Error( $msg );
365
+	public static function write_to_file($full_file_path = '', $file_contents = '', $file_type = '') {
366
+		$full_file_path = EEH_File::standardise_directory_separators($full_file_path);
367
+		$file_type = ! empty($file_type) ? rtrim($file_type, ' ').' ' : '';
368
+		$folder = EEH_File::remove_filename_from_filepath($full_file_path);
369
+		if ( ! EEH_File::verify_is_writable($folder, 'folder')) {
370
+			if (defined('WP_DEBUG') && WP_DEBUG) {
371
+				$msg = sprintf(__('The %1$sfile located at "%2$s" is not writable.', 'event_espresso'), $file_type, $full_file_path);
372
+				$msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_file_path);
373
+				throw new EE_Error($msg);
374 374
 			}
375 375
 			return FALSE;
376 376
 		}
377 377
 		// load WP_Filesystem and set file permissions
378
-		$wp_filesystem = EEH_File::_get_wp_filesystem( $full_file_path );
378
+		$wp_filesystem = EEH_File::_get_wp_filesystem($full_file_path);
379 379
 		// write the file
380
-		if ( ! $wp_filesystem->put_contents(EEH_File::convert_local_filepath_to_remote_filepath( $full_file_path ), $file_contents )) {
381
-			if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
382
-				$msg = sprintf( __( 'The %1$sfile located at "%2$s" could not be written to.', 'event_espresso' ), $file_type, $full_file_path );
383
-				$msg .= EEH_File::_permissions_error_for_unreadable_filepath( $full_file_path, 'f' );
384
-				throw new EE_Error( $msg );
380
+		if ( ! $wp_filesystem->put_contents(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path), $file_contents)) {
381
+			if (defined('WP_DEBUG') && WP_DEBUG) {
382
+				$msg = sprintf(__('The %1$sfile located at "%2$s" could not be written to.', 'event_espresso'), $file_type, $full_file_path);
383
+				$msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_file_path, 'f');
384
+				throw new EE_Error($msg);
385 385
 			}
386 386
 			return FALSE;
387 387
 		}
@@ -397,9 +397,9 @@  discard block
 block discarded – undo
397 397
 	 * @throws EE_Error if filesystem credentials are required
398 398
 	 * @return boolean
399 399
 	 */
400
-	public static function delete( $filepath, $recursive = false, $type = false ) {
400
+	public static function delete($filepath, $recursive = false, $type = false) {
401 401
 		$wp_filesystem = EEH_File::_get_wp_filesystem();
402
-		return $wp_filesystem->delete( $filepath, $recursive, $type ) ? TRUE : FALSE;
402
+		return $wp_filesystem->delete($filepath, $recursive, $type) ? TRUE : FALSE;
403 403
 	}
404 404
 
405 405
 
@@ -411,9 +411,9 @@  discard block
 block discarded – undo
411 411
 	 * @throws EE_Error if filesystem credentials are required
412 412
 	 * @return bool
413 413
 	 */
414
-	public static function exists( $full_file_path = '' ) {
415
-		$wp_filesystem = EEH_File::_get_wp_filesystem( $full_file_path );
416
-		return $wp_filesystem->exists( EEH_File::convert_local_filepath_to_remote_filepath( $full_file_path ) ) ? TRUE : FALSE;
414
+	public static function exists($full_file_path = '') {
415
+		$wp_filesystem = EEH_File::_get_wp_filesystem($full_file_path);
416
+		return $wp_filesystem->exists(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path)) ? TRUE : FALSE;
417 417
 	}
418 418
 
419 419
 
@@ -426,9 +426,9 @@  discard block
 block discarded – undo
426 426
 	 * @throws EE_Error if filesystem credentials are required
427 427
 	 * @return bool
428 428
 	 */
429
-	public static function is_readable( $full_file_path = '' ) {
430
-		$wp_filesystem = EEH_File::_get_wp_filesystem( $full_file_path );
431
-		if( $wp_filesystem->is_readable( EEH_File::convert_local_filepath_to_remote_filepath(  $full_file_path ) ) ) {
429
+	public static function is_readable($full_file_path = '') {
430
+		$wp_filesystem = EEH_File::_get_wp_filesystem($full_file_path);
431
+		if ($wp_filesystem->is_readable(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path))) {
432 432
 			return true;
433 433
 		} else {
434 434
 			return false;
@@ -444,8 +444,8 @@  discard block
 block discarded – undo
444 444
 	 * @param string $full_file_path
445 445
 	 * @return string
446 446
 	 */
447
-	public static function remove_filename_from_filepath( $full_file_path = '' ) {
448
-		return pathinfo( $full_file_path, PATHINFO_DIRNAME );
447
+	public static function remove_filename_from_filepath($full_file_path = '') {
448
+		return pathinfo($full_file_path, PATHINFO_DIRNAME);
449 449
 	}
450 450
 
451 451
 
@@ -455,8 +455,8 @@  discard block
 block discarded – undo
455 455
 	 * @param string $full_file_path
456 456
 	 * @return string
457 457
 	 */
458
-	public static function get_filename_from_filepath( $full_file_path = '' ) {
459
-		return pathinfo( $full_file_path, PATHINFO_BASENAME );
458
+	public static function get_filename_from_filepath($full_file_path = '') {
459
+		return pathinfo($full_file_path, PATHINFO_BASENAME);
460 460
 	}
461 461
 
462 462
 
@@ -466,8 +466,8 @@  discard block
 block discarded – undo
466 466
 	 * @param string $full_file_path
467 467
 	 * @return string
468 468
 	 */
469
-	public static function get_file_extension( $full_file_path = '' ) {
470
-		return pathinfo( $full_file_path, PATHINFO_EXTENSION );
469
+	public static function get_file_extension($full_file_path = '') {
470
+		return pathinfo($full_file_path, PATHINFO_EXTENSION);
471 471
 	}
472 472
 
473 473
 
@@ -478,10 +478,10 @@  discard block
 block discarded – undo
478 478
 	 * @throws EE_Error if filesystem credentials are required
479 479
 	 * @return bool
480 480
 	 */
481
-	public static function add_htaccess_deny_from_all( $folder = '' ) {
482
-		$folder = EEH_File::standardise_and_end_with_directory_separator( $folder );
483
-		if ( ! EEH_File::exists( $folder . '.htaccess' ) ) {
484
-			if ( ! EEH_File::write_to_file( $folder . '.htaccess', 'deny from all', '.htaccess' )) {
481
+	public static function add_htaccess_deny_from_all($folder = '') {
482
+		$folder = EEH_File::standardise_and_end_with_directory_separator($folder);
483
+		if ( ! EEH_File::exists($folder.'.htaccess')) {
484
+			if ( ! EEH_File::write_to_file($folder.'.htaccess', 'deny from all', '.htaccess')) {
485 485
 				return FALSE;
486 486
 			}
487 487
 		}
@@ -495,10 +495,10 @@  discard block
 block discarded – undo
495 495
 	 * @throws EE_Error if filesystem credentials are required
496 496
 	 * @return boolean
497 497
 	 */
498
-	public static function add_index_file( $folder ) {
499
-		$folder = EEH_File::standardise_and_end_with_directory_separator( $folder );
500
-		if ( ! EEH_File::exists( $folder . 'index.php' ) ) {
501
-			if ( ! EEH_File::write_to_file( $folder . 'index.php', 'You are not permitted to read from this folder', '.php' )) {
498
+	public static function add_index_file($folder) {
499
+		$folder = EEH_File::standardise_and_end_with_directory_separator($folder);
500
+		if ( ! EEH_File::exists($folder.'index.php')) {
501
+			if ( ! EEH_File::write_to_file($folder.'index.php', 'You are not permitted to read from this folder', '.php')) {
502 502
 				return false;
503 503
 			}
504 504
 		}
@@ -513,11 +513,11 @@  discard block
 block discarded – undo
513 513
 	 * @param string $file_path
514 514
 	 * @return string
515 515
 	 */
516
-	public static function get_classname_from_filepath_with_standard_filename( $file_path ){
516
+	public static function get_classname_from_filepath_with_standard_filename($file_path) {
517 517
 		//extract file from path
518
-		$filename = basename( $file_path );
518
+		$filename = basename($file_path);
519 519
 		//now remove the first period and everything after
520
-		$pos_of_first_period = strpos( $filename,'.' );
520
+		$pos_of_first_period = strpos($filename, '.');
521 521
 		return substr($filename, 0, $pos_of_first_period);
522 522
 	}
523 523
 
@@ -529,8 +529,8 @@  discard block
 block discarded – undo
529 529
 	 * @param string $file_path
530 530
 	 * @return string
531 531
 	 */
532
-	public static function standardise_directory_separators( $file_path ){
533
-		return str_replace( array( '\\', '/' ), DS, $file_path );
532
+	public static function standardise_directory_separators($file_path) {
533
+		return str_replace(array('\\', '/'), DS, $file_path);
534 534
 	}
535 535
 
536 536
 
@@ -541,8 +541,8 @@  discard block
 block discarded – undo
541 541
 	 * @param string $file_path
542 542
 	 * @return string
543 543
 	 */
544
-	public static function end_with_directory_separator( $file_path ){
545
-		return rtrim( $file_path, '/\\' ) . DS;
544
+	public static function end_with_directory_separator($file_path) {
545
+		return rtrim($file_path, '/\\').DS;
546 546
 	}
547 547
 
548 548
 
@@ -552,8 +552,8 @@  discard block
 block discarded – undo
552 552
 	 * @param $file_path
553 553
 	 * @return string
554 554
 	 */
555
-	public static function standardise_and_end_with_directory_separator( $file_path ){
556
-		return self::end_with_directory_separator( self::standardise_directory_separators( $file_path ));
555
+	public static function standardise_and_end_with_directory_separator($file_path) {
556
+		return self::end_with_directory_separator(self::standardise_directory_separators($file_path));
557 557
 	}
558 558
 
559 559
 
@@ -570,21 +570,21 @@  discard block
 block discarded – undo
570 570
 	 *		if $index_numerically == FALSE (Default) keys are what the class names SHOULD be;
571 571
 	 *		 and values are their filepaths
572 572
 	 */
573
-	public static function get_contents_of_folders( $folder_paths = array(), $index_numerically = FALSE ){
573
+	public static function get_contents_of_folders($folder_paths = array(), $index_numerically = FALSE) {
574 574
 		$class_to_folder_path = array();
575
-		foreach( $folder_paths as $folder_path ){
576
-			$folder_path = self::standardise_and_end_with_directory_separator( $folder_path );
575
+		foreach ($folder_paths as $folder_path) {
576
+			$folder_path = self::standardise_and_end_with_directory_separator($folder_path);
577 577
 			// load WP_Filesystem and set file permissions
578
-			$files_in_folder = glob( $folder_path . '*' );
578
+			$files_in_folder = glob($folder_path.'*');
579 579
 			$class_to_folder_path = array();
580
-			if ( $files_in_folder ) {
581
-				foreach( $files_in_folder as $file_path ){
580
+			if ($files_in_folder) {
581
+				foreach ($files_in_folder as $file_path) {
582 582
 					//only add files, not folders
583
-					if ( ! is_dir( $file_path )) {
584
-						if ( $index_numerically ) {
583
+					if ( ! is_dir($file_path)) {
584
+						if ($index_numerically) {
585 585
 							$class_to_folder_path[] = $file_path;
586 586
 						} else {
587
-							$classname = self::get_classname_from_filepath_with_standard_filename( $file_path );
587
+							$classname = self::get_classname_from_filepath_with_standard_filename($file_path);
588 588
 							$class_to_folder_path[$classname] = $file_path;
589 589
 						}
590 590
 					}
@@ -604,39 +604,39 @@  discard block
 block discarded – undo
604 604
 	 * @throws EE_Error if filesystem credentials are required
605 605
 	 * @return boolean success
606 606
 	 */
607
-	public static function copy( $source_file, $destination_file, $overwrite = FALSE ){
608
-		$full_source_path = EEH_File::standardise_directory_separators( $source_file );
609
-		if( ! EEH_File::exists( $full_source_path ) ){
610
-			if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
611
-				$msg = sprintf( __( 'The file located at "%2$s" is not readable or doesn\'t exist.', 'event_espresso' ), $full_source_path );
612
-				$msg .= EEH_File::_permissions_error_for_unreadable_filepath( $full_source_path );
613
-				throw new EE_Error( $msg );
607
+	public static function copy($source_file, $destination_file, $overwrite = FALSE) {
608
+		$full_source_path = EEH_File::standardise_directory_separators($source_file);
609
+		if ( ! EEH_File::exists($full_source_path)) {
610
+			if (defined('WP_DEBUG') && WP_DEBUG) {
611
+				$msg = sprintf(__('The file located at "%2$s" is not readable or doesn\'t exist.', 'event_espresso'), $full_source_path);
612
+				$msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_source_path);
613
+				throw new EE_Error($msg);
614 614
 			}
615 615
 			return FALSE;
616 616
 		}
617 617
 
618
-		$full_dest_path = EEH_File::standardise_directory_separators( $destination_file );
619
-		$folder = EEH_File::remove_filename_from_filepath( $full_dest_path );
620
-		if ( ! EEH_File::verify_is_writable( $folder, 'folder' )) {
621
-			if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
622
-				$msg = sprintf( __( 'The file located at "%2$s" is not writable.', 'event_espresso' ), $full_dest_path );
623
-				$msg .= EEH_File::_permissions_error_for_unreadable_filepath( $full_dest_path );
624
-				throw new EE_Error( $msg );
618
+		$full_dest_path = EEH_File::standardise_directory_separators($destination_file);
619
+		$folder = EEH_File::remove_filename_from_filepath($full_dest_path);
620
+		if ( ! EEH_File::verify_is_writable($folder, 'folder')) {
621
+			if (defined('WP_DEBUG') && WP_DEBUG) {
622
+				$msg = sprintf(__('The file located at "%2$s" is not writable.', 'event_espresso'), $full_dest_path);
623
+				$msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_dest_path);
624
+				throw new EE_Error($msg);
625 625
 			}
626 626
 			return FALSE;
627 627
 		}
628 628
 
629 629
 		// load WP_Filesystem and set file permissions
630
-		$wp_filesystem = EEH_File::_get_wp_filesystem( $destination_file );
630
+		$wp_filesystem = EEH_File::_get_wp_filesystem($destination_file);
631 631
 		// write the file
632 632
 		if ( ! $wp_filesystem->copy(
633
-						EEH_File::convert_local_filepath_to_remote_filepath( $full_source_path ),
634
-						EEH_File::convert_local_filepath_to_remote_filepath( $full_dest_path ),
633
+						EEH_File::convert_local_filepath_to_remote_filepath($full_source_path),
634
+						EEH_File::convert_local_filepath_to_remote_filepath($full_dest_path),
635 635
 						$overwrite )) {
636
-			if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
637
-				$msg = sprintf( __( 'Attempted writing to file %1$s, but could not, probably because of permissions issues', 'event_espresso' ), $full_source_path );
638
-				$msg .= EEH_File::_permissions_error_for_unreadable_filepath( $full_source_path, 'f' );
639
-				throw new EE_Error( $msg );
636
+			if (defined('WP_DEBUG') && WP_DEBUG) {
637
+				$msg = sprintf(__('Attempted writing to file %1$s, but could not, probably because of permissions issues', 'event_espresso'), $full_source_path);
638
+				$msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_source_path, 'f');
639
+				throw new EE_Error($msg);
640 640
 			}
641 641
 			return FALSE;
642 642
 		}
@@ -648,9 +648,9 @@  discard block
 block discarded – undo
648 648
 	 * @param string $filepath
649 649
 	 * @return boolean
650 650
 	 */
651
-	public static function is_in_uploads_folder( $filepath ) {
651
+	public static function is_in_uploads_folder($filepath) {
652 652
 		$uploads = wp_upload_dir();
653
-		return strpos( $filepath, $uploads[ 'basedir' ] ) === 0 ? true : false;
653
+		return strpos($filepath, $uploads['basedir']) === 0 ? true : false;
654 654
 	}
655 655
 
656 656
 	/**
@@ -665,9 +665,9 @@  discard block
 block discarded – undo
665 665
 	 * @return string the remote filepath (eg the filepath the filesystem method, eg
666 666
 	 * ftp or ssh, will use to access the folder
667 667
 	 */
668
-	public static function convert_local_filepath_to_remote_filepath( $local_filepath ) {
669
-		$wp_filesystem = EEH_File::_get_wp_filesystem( $local_filepath );
670
-		return str_replace( WP_CONTENT_DIR . DS, $wp_filesystem->wp_content_dir(), $local_filepath );
668
+	public static function convert_local_filepath_to_remote_filepath($local_filepath) {
669
+		$wp_filesystem = EEH_File::_get_wp_filesystem($local_filepath);
670
+		return str_replace(WP_CONTENT_DIR.DS, $wp_filesystem->wp_content_dir(), $local_filepath);
671 671
 	}
672 672
 }
673 673
 // End of file EEH_File.helper.php
Please login to merge, or discard this patch.
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,4 +1,6 @@
 block discarded – undo
1
-<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) exit('No direct script access allowed');
1
+<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) {
2
+	exit('No direct script access allowed');
3
+}
2 4
 /**
3 5
  * Event Espresso
4 6
  *
Please login to merge, or discard this patch.
core/EE_Payment_Processor.core.php 1 patch
Indentation   +734 added lines, -734 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php if ( ! defined('EVENT_ESPRESSO_VERSION')) {
2
-    exit('No direct script access allowed');
2
+	exit('No direct script access allowed');
3 3
 }
4 4
 EE_Registry::instance()->load_class('Processor_Base');
5 5
 
@@ -16,737 +16,737 @@  discard block
 block discarded – undo
16 16
 class EE_Payment_Processor extends EE_Processor_Base
17 17
 {
18 18
 
19
-    /**
20
-     * @var EE_Payment_Processor $_instance
21
-     * @access    private
22
-     */
23
-    private static $_instance;
24
-
25
-
26
-
27
-    /**
28
-     * @singleton method used to instantiate class object
29
-     * @access    public
30
-     * @return EE_Payment_Processor instance
31
-     */
32
-    public static function instance()
33
-    {
34
-        // check if class object is instantiated
35
-        if ( ! self::$_instance instanceof EE_Payment_Processor) {
36
-            self::$_instance = new self();
37
-        }
38
-        return self::$_instance;
39
-    }
40
-
41
-
42
-
43
-    /**
44
-     *private constructor to prevent direct creation
45
-     *
46
-     * @Constructor
47
-     * @access private
48
-     */
49
-    private function __construct()
50
-    {
51
-        do_action('AHEE__EE_Payment_Processor__construct');
52
-        add_action('http_api_curl', array($this, '_curl_requests_to_paypal_use_tls'), 10, 3);
53
-    }
54
-
55
-
56
-
57
-    /**
58
-     * Using the selected gateway, processes the payment for that transaction, and updates the transaction
59
-     * appropriately. Saves the payment that is generated
60
-     *
61
-     * @param EE_Payment_Method    $payment_method
62
-     * @param EE_Transaction       $transaction
63
-     * @param float                $amount       if only part of the transaction is to be paid for, how much.
64
-     *                                           Leave null if payment is for the full amount owing
65
-     * @param EE_Billing_Info_Form $billing_form (or probably null, if it's an offline or offsite payment method).
66
-     *                                           Receive_form_submission() should have
67
-     *                                           already been called on the billing form
68
-     *                                           (ie, its inputs should have their normalized values set).
69
-     * @param string               $return_url   string used mostly by offsite gateways to specify
70
-     *                                           where to go AFTER the offsite gateway
71
-     * @param string               $method       like 'CART', indicates who the client who called this was
72
-     * @param bool                 $by_admin     TRUE if payment is being attempted from the admin
73
-     * @param boolean              $update_txn   whether or not to call
74
-     *                                           EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment()
75
-     * @param string               $cancel_url   URL to return to if off-site payments are cancelled
76
-     * @return \EE_Payment
77
-     * @throws \EE_Error
78
-     */
79
-    public function process_payment(
80
-        EE_Payment_Method $payment_method,
81
-        EE_Transaction $transaction,
82
-        $amount = null,
83
-        $billing_form = null,
84
-        $return_url = null,
85
-        $method = 'CART',
86
-        $by_admin = false,
87
-        $update_txn = true,
88
-        $cancel_url = ''
89
-    ) {
90
-        if ((float)$amount < 0) {
91
-            throw new EE_Error(
92
-                sprintf(
93
-                    __(
94
-                        'Attempting to make a payment for a negative amount of %1$d for transaction %2$d. That should be a refund',
95
-                        'event_espresso'
96
-                    ),
97
-                    $amount,
98
-                    $transaction->ID()
99
-                )
100
-            );
101
-        }
102
-        // verify payment method
103
-        $payment_method = EEM_Payment_Method::instance()->ensure_is_obj($payment_method, true);
104
-        // verify transaction
105
-        EEM_Transaction::instance()->ensure_is_obj($transaction);
106
-        $transaction->set_payment_method_ID($payment_method->ID());
107
-        // verify payment method type
108
-        if ($payment_method->type_obj() instanceof EE_PMT_Base) {
109
-            $payment = $payment_method->type_obj()->process_payment(
110
-                $transaction,
111
-                min($amount, $transaction->remaining()),//make sure we don't overcharge
112
-                $billing_form,
113
-                $return_url,
114
-                add_query_arg(array('ee_cancel_payment' => true), $cancel_url),
115
-                $method,
116
-                $by_admin
117
-            );
118
-            // check if payment method uses an off-site gateway
119
-            if ($payment_method->type_obj()->payment_occurs() !== EE_PMT_Base::offsite) {
120
-                // don't process payments for off-site gateways yet because no payment has occurred yet
121
-                $this->update_txn_based_on_payment($transaction, $payment, $update_txn);
122
-            }
123
-            return $payment;
124
-        } else {
125
-            EE_Error::add_error(
126
-                sprintf(
127
-                    __('A valid payment method could not be determined due to a technical issue.%sPlease try again or contact %s for assistance.', 'event_espresso'),
128
-                    '<br/>',
129
-                    EE_Registry::instance()->CFG->organization->get_pretty('email')
130
-                ), __FILE__, __FUNCTION__, __LINE__
131
-            );
132
-            return null;
133
-        }
134
-    }
135
-
136
-
137
-
138
-    /**
139
-     * @param EE_Transaction|int $transaction
140
-     * @param EE_Payment_Method  $payment_method
141
-     * @throws EE_Error
142
-     * @return string
143
-     */
144
-    public function get_ipn_url_for_payment_method($transaction, $payment_method)
145
-    {
146
-        /** @type \EE_Transaction $transaction */
147
-        $transaction = EEM_Transaction::instance()->ensure_is_obj($transaction);
148
-        $primary_reg = $transaction->primary_registration();
149
-        if ( ! $primary_reg instanceof EE_Registration) {
150
-            throw new EE_Error(
151
-                sprintf(
152
-                    __(
153
-                        "Cannot get IPN URL for transaction with ID %d because it has no primary registration",
154
-                        "event_espresso"
155
-                    ),
156
-                    $transaction->ID()
157
-                )
158
-            );
159
-        }
160
-        $payment_method = EEM_Payment_Method::instance()->ensure_is_obj($payment_method, true);
161
-        $url = add_query_arg(
162
-            array(
163
-                'e_reg_url_link'    => $primary_reg->reg_url_link(),
164
-                'ee_payment_method' => $payment_method->slug(),
165
-            ),
166
-            EE_Registry::instance()->CFG->core->txn_page_url()
167
-        );
168
-        return $url;
169
-    }
170
-
171
-
172
-
173
-    /**
174
-     * Process the IPN. Firstly, we'll hope we put the standard args into the IPN URL so
175
-     * we can easily find what registration the IPN is for and what payment method.
176
-     * However, if not, we'll give all payment methods a chance to claim it and process it.
177
-     * If a payment is found for the IPN info, it is saved.
178
-     *
179
-     * @param array              $_req_data            eg $_REQUEST
180
-     * @param EE_Transaction|int $transaction          optional (or a transactions id)
181
-     * @param EE_Payment_Method  $payment_method       (or a slug or id of one)
182
-     * @param boolean            $update_txn           whether or not to call
183
-     *                                                 EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment()
184
-     * @param bool               $separate_IPN_request whether the IPN uses a separate request ( true like PayPal )
185
-     *                                                 or is processed manually ( false like Mijireh )
186
-     * @throws EE_Error
187
-     * @throws Exception
188
-     * @return EE_Payment
189
-     */
190
-    public function process_ipn(
191
-        $_req_data,
192
-        $transaction = null,
193
-        $payment_method = null,
194
-        $update_txn = true,
195
-        $separate_IPN_request = true
196
-    ) {
197
-        EE_Registry::instance()->load_model('Change_Log');
198
-        $_req_data = $this->_remove_unusable_characters_from_array((array)$_req_data);
199
-        EE_Processor_Base::set_IPN($separate_IPN_request);
200
-        $obj_for_log = null;
201
-        if ($transaction instanceof EE_Transaction) {
202
-            $obj_for_log = $transaction;
203
-            if ($payment_method instanceof EE_Payment_Method) {
204
-                $obj_for_log = EEM_Payment::instance()->get_one(
205
-                    array(
206
-                        array('TXN_ID' => $transaction->ID(), 'PMD_ID' => $payment_method->ID()),
207
-                        'order_by' => array('PAY_timestamp' => 'desc'),
208
-                    )
209
-                );
210
-            }
211
-        } else if ($payment_method instanceof EE_Payment) {
212
-            $obj_for_log = $payment_method;
213
-        }
214
-        $log = EEM_Change_Log::instance()->log(
215
-            EEM_Change_Log::type_gateway,
216
-            array('IPN data received' => $_req_data),
217
-            $obj_for_log
218
-        );
219
-        try {
220
-            /**
221
-             * @var EE_Payment $payment
222
-             */
223
-            $payment = null;
224
-            if ($transaction && $payment_method) {
225
-                /** @type EE_Transaction $transaction */
226
-                $transaction = EEM_Transaction::instance()->ensure_is_obj($transaction);
227
-                /** @type EE_Payment_Method $payment_method */
228
-                $payment_method = EEM_Payment_Method::instance()->ensure_is_obj($payment_method);
229
-                if ($payment_method->type_obj() instanceof EE_PMT_Base) {
230
-                    try {
231
-                        $payment = $payment_method->type_obj()->handle_ipn($_req_data, $transaction);
232
-                        $log->set_object($payment);
233
-                    } catch (EventEspresso\core\exceptions\IpnException $e) {
234
-                        EEM_Change_Log::instance()->log(
235
-                            EEM_Change_Log::type_gateway,
236
-                            array(
237
-                                'message'     => 'IPN Exception: ' . $e->getMessage(),
238
-                                'current_url' => EEH_URL::current_url(),
239
-                                'payment'     => $e->getPaymentProperties(),
240
-                                'IPN_data'    => $e->getIpnData(),
241
-                            ),
242
-                            $obj_for_log
243
-                        );
244
-                        return $e->getPayment();
245
-                    }
246
-                } else {
247
-                    // not a payment
248
-                    EE_Error::add_error(
249
-                        sprintf(
250
-                            __('A valid payment method could not be determined due to a technical issue.%sPlease refresh your browser and try again or contact %s for assistance.', 'event_espresso'),
251
-                            '<br/>',
252
-                            EE_Registry::instance()->CFG->organization->get_pretty('email')
253
-                        ),
254
-                        __FILE__, __FUNCTION__, __LINE__
255
-                    );
256
-                }
257
-            } else {
258
-                //that's actually pretty ok. The IPN just wasn't able
259
-                //to identify which transaction or payment method this was for
260
-                // give all active payment methods a chance to claim it
261
-                $active_payment_methods = EEM_Payment_Method::instance()->get_all_active();
262
-                foreach ($active_payment_methods as $active_payment_method) {
263
-                    try {
264
-                        $payment = $active_payment_method->type_obj()->handle_unclaimed_ipn($_req_data);
265
-                        $payment_method = $active_payment_method;
266
-                        EEM_Change_Log::instance()->log(
267
-                            EEM_Change_Log::type_gateway, array('IPN data' => $_req_data), $payment
268
-                        );
269
-                        break;
270
-                    } catch (EventEspresso\core\exceptions\IpnException $e) {
271
-                        EEM_Change_Log::instance()->log(
272
-                            EEM_Change_Log::type_gateway,
273
-                            array(
274
-                                'message'     => 'IPN Exception: ' . $e->getMessage(),
275
-                                'current_url' => EEH_URL::current_url(),
276
-                                'payment'     => $e->getPaymentProperties(),
277
-                                'IPN_data'    => $e->getIpnData(),
278
-                            ),
279
-                            $obj_for_log
280
-                        );
281
-                        return $e->getPayment();
282
-                    } catch (EE_Error $e) {
283
-                        //that's fine- it apparently couldn't handle the IPN
284
-                    }
285
-                }
286
-            }
287
-            // 			EEM_Payment_Log::instance()->log("got to 7",$transaction,$payment_method);
288
-            if ($payment instanceof EE_Payment) {
289
-                $payment->save();
290
-                //  update the TXN
291
-                $this->update_txn_based_on_payment($transaction, $payment, $update_txn, $separate_IPN_request);
292
-            } else {
293
-                //we couldn't find the payment for this IPN... let's try and log at least SOMETHING
294
-                if ($payment_method) {
295
-                    EEM_Change_Log::instance()->log(EEM_Change_Log::type_gateway, array('IPN data' => $_req_data), $payment_method);
296
-                } elseif ($transaction) {
297
-                    EEM_Change_Log::instance()->log(EEM_Change_Log::type_gateway, array('IPN data' => $_req_data), $transaction);
298
-                }
299
-            }
300
-            return $payment;
301
-        } catch (EE_Error $e) {
302
-            do_action(
303
-                'AHEE__log', __FILE__, __FUNCTION__, sprintf(
304
-                    __('Error occurred while receiving IPN. Transaction: %1$s, req data: %2$s. The error was "%3$s"', 'event_espresso'),
305
-                    print_r($transaction, true),
306
-                    print_r($_req_data, true),
307
-                    $e->getMessage()
308
-                )
309
-            );
310
-            throw $e;
311
-        }
312
-    }
313
-
314
-
315
-
316
-    /**
317
-     * Removes any non-printable illegal characters from the input,
318
-     * which might cause a raucous when trying to insert into the database
319
-     *
320
-     * @param  array $request_data
321
-     * @return array
322
-     */
323
-    protected function _remove_unusable_characters_from_array(array $request_data)
324
-    {
325
-        $return_data = array();
326
-        foreach ($request_data as $key => $value) {
327
-            $return_data[$this->_remove_unusable_characters($key)] = $this->_remove_unusable_characters($value);
328
-        }
329
-        return $return_data;
330
-    }
331
-
332
-
333
-
334
-    /**
335
-     * Removes any non-printable illegal characters from the input,
336
-     * which might cause a raucous when trying to insert into the database
337
-     *
338
-     * @param string $request_data
339
-     * @return string
340
-     */
341
-    protected function _remove_unusable_characters($request_data)
342
-    {
343
-        return preg_replace('/[^[:print:]]/', '', $request_data);
344
-    }
345
-
346
-
347
-
348
-    /**
349
-     * Should be called just before displaying the payment attempt results to the user,
350
-     * when the payment attempt has finished. Some payment methods may have special
351
-     * logic to perform here. For example, if process_payment() happens on a special request
352
-     * and then the user is redirected to a page that displays the payment's status, this
353
-     * should be called while loading the page that displays the payment's status. If the user is
354
-     * sent to an offsite payment provider, this should be called upon returning from that offsite payment
355
-     * provider.
356
-     *
357
-     * @param EE_Transaction|int $transaction
358
-     * @param bool               $update_txn whether or not to call
359
-     *                                       EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment()
360
-     * @throws \EE_Error
361
-     * @return EE_Payment
362
-     * @deprecated 4.6.24 method is no longer used. Instead it is up to client code, like SPCO,
363
-     *                                       to call handle_ipn() for offsite gateways that don't receive separate IPNs
364
-     */
365
-    public function finalize_payment_for($transaction, $update_txn = true)
366
-    {
367
-        /** @var $transaction EE_Transaction */
368
-        $transaction = EEM_Transaction::instance()->ensure_is_obj($transaction);
369
-        $last_payment_method = $transaction->payment_method();
370
-        if ($last_payment_method instanceof EE_Payment_Method) {
371
-            $payment = $last_payment_method->type_obj()->finalize_payment_for($transaction);
372
-            $this->update_txn_based_on_payment($transaction, $payment, $update_txn);
373
-            return $payment;
374
-        } else {
375
-            return null;
376
-        }
377
-    }
378
-
379
-
380
-
381
-    /**
382
-     * Processes a direct refund request, saves the payment, and updates the transaction appropriately.
383
-     *
384
-     * @param EE_Payment_Method $payment_method
385
-     * @param EE_Payment        $payment_to_refund
386
-     * @param array             $refund_info
387
-     * @return EE_Payment
388
-     * @throws \EE_Error
389
-     */
390
-    public function process_refund(
391
-        EE_Payment_Method $payment_method,
392
-        EE_Payment $payment_to_refund,
393
-        $refund_info = array()
394
-    ) {
395
-        if ($payment_method instanceof EE_Payment_Method && $payment_method->type_obj()->supports_sending_refunds()) {
396
-            $payment_method->type_obj()->process_refund($payment_to_refund, $refund_info);
397
-            $this->update_txn_based_on_payment($payment_to_refund->transaction(), $payment_to_refund);
398
-        }
399
-        return $payment_to_refund;
400
-    }
401
-
402
-
403
-
404
-    /**
405
-     * This should be called each time there may have been an update to a
406
-     * payment on a transaction (ie, we asked for a payment to process a
407
-     * payment for a transaction, or we told a payment method about an IPN, or
408
-     * we told a payment method to
409
-     * "finalize_payment_for" (a transaction), or we told a payment method to
410
-     * process a refund. This should handle firing the correct hooks to
411
-     * indicate
412
-     * what exactly happened and updating the transaction appropriately). This
413
-     * could be integrated directly into EE_Transaction upon save, but we want
414
-     * this logic to be separate from 'normal' plain-jane saving and updating
415
-     * of transactions and payments, and to be tied to payment processing.
416
-     * Note: this method DOES NOT save the payment passed into it. It is the responsibility
417
-     * of previous code to decide whether or not to save (because the payment passed into
418
-     * this method might be a temporary, never-to-be-saved payment from an offline gateway,
419
-     * in which case we only want that payment object for some temporary usage during this request,
420
-     * but we don't want it to be saved).
421
-     *
422
-     * @param EE_Transaction|int $transaction
423
-     * @param EE_Payment         $payment
424
-     * @param boolean            $update_txn
425
-     *                        whether or not to call
426
-     *                        EE_Transaction_Processor::
427
-     *                        update_transaction_and_registrations_after_checkout_or_payment()
428
-     *                        (you can save 1 DB query if you know you're going
429
-     *                        to save it later instead)
430
-     * @param bool               $IPN
431
-     *                        if processing IPNs or other similar payment
432
-     *                        related activities that occur in alternate
433
-     *                        requests than the main one that is processing the
434
-     *                        TXN, then set this to true to check whether the
435
-     *                        TXN is locked before updating
436
-     * @throws \EE_Error
437
-     */
438
-    public function update_txn_based_on_payment($transaction, $payment, $update_txn = true, $IPN = false)
439
-    {
440
-        $do_action = 'AHEE__EE_Payment_Processor__update_txn_based_on_payment__not_successful';
441
-        /** @type EE_Transaction $transaction */
442
-        $transaction = EEM_Transaction::instance()->ensure_is_obj($transaction);
443
-        // can we freely update the TXN at this moment?
444
-        if ($IPN && $transaction->is_locked()) {
445
-            // don't update the transaction at this exact moment
446
-            // because the TXN is active in another request
447
-            EE_Cron_Tasks::schedule_update_transaction_with_payment(
448
-                time(),
449
-                $transaction->ID(),
450
-                $payment->ID()
451
-            );
452
-        } else {
453
-            // verify payment and that it has been saved
454
-            if ($payment instanceof EE_Payment && $payment->ID()) {
455
-                if (
456
-                    $payment->payment_method() instanceof EE_Payment_Method
457
-                    && $payment->payment_method()->type_obj() instanceof EE_PMT_Base
458
-                ) {
459
-                    $payment->payment_method()->type_obj()->update_txn_based_on_payment($payment);
460
-                    // update TXN registrations with payment info
461
-                    $this->process_registration_payments($transaction, $payment);
462
-                }
463
-                $do_action = $payment->just_approved()
464
-                    ? 'AHEE__EE_Payment_Processor__update_txn_based_on_payment__successful'
465
-                    : $do_action;
466
-            } else {
467
-                // send out notifications
468
-                add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true');
469
-                $do_action = 'AHEE__EE_Payment_Processor__update_txn_based_on_payment__no_payment_made';
470
-            }
471
-            if ($payment instanceof EE_Payment && $payment->status() !== EEM_Payment::status_id_failed) {
472
-                /** @type EE_Transaction_Payments $transaction_payments */
473
-                $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments');
474
-                // set new value for total paid
475
-                $transaction_payments->calculate_total_payments_and_update_status($transaction);
476
-                // call EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment() ???
477
-                if ($update_txn) {
478
-                    $this->_post_payment_processing($transaction, $payment, $IPN);
479
-                }
480
-            }
481
-            // granular hook for others to use.
482
-            do_action($do_action, $transaction, $payment);
483
-            do_action('AHEE_log', __CLASS__, __FUNCTION__, $do_action, '$do_action');
484
-            //global hook for others to use.
485
-            do_action('AHEE__EE_Payment_Processor__update_txn_based_on_payment', $transaction, $payment);
486
-        }
487
-    }
488
-
489
-
490
-
491
-    /**
492
-     * update registrations REG_paid field after successful payment and link registrations with payment
493
-     *
494
-     * @param EE_Transaction    $transaction
495
-     * @param EE_Payment        $payment
496
-     * @param EE_Registration[] $registrations
497
-     * @throws \EE_Error
498
-     */
499
-    public function process_registration_payments(
500
-        EE_Transaction $transaction,
501
-        EE_Payment $payment,
502
-        $registrations = array()
503
-    ) {
504
-        // only process if payment was successful
505
-        if ($payment->status() !== EEM_Payment::status_id_approved) {
506
-            return;
507
-        }
508
-        //EEM_Registration::instance()->show_next_x_db_queries();
509
-        if (empty($registrations)) {
510
-            // find registrations with monies owing that can receive a payment
511
-            $registrations = $transaction->registrations(
512
-                array(
513
-                    array(
514
-                        // only these reg statuses can receive payments
515
-                        'STS_ID'           => array('IN', EEM_Registration::reg_statuses_that_allow_payment()),
516
-                        'REG_final_price'  => array('!=', 0),
517
-                        'REG_final_price*' => array('!=', 'REG_paid', true),
518
-                    ),
519
-                )
520
-            );
521
-        }
522
-        // still nothing ??!??
523
-        if (empty($registrations)) {
524
-            return;
525
-        }
526
-        // todo: break out the following logic into a separate strategy class
527
-        // todo: named something like "Sequential_Reg_Payment_Strategy"
528
-        // todo: which would apply payments using the capitalist "first come first paid" approach
529
-        // todo: then have another strategy class like "Distributed_Reg_Payment_Strategy"
530
-        // todo: which would be the socialist "everybody gets a piece of pie" approach,
531
-        // todo: which would be better for deposits, where you want a bit of the payment applied to each registration
532
-        $refund = $payment->is_a_refund();
533
-        // how much is available to apply to registrations?
534
-        $available_payment_amount = abs($payment->amount());
535
-        foreach ($registrations as $registration) {
536
-            if ($registration instanceof EE_Registration) {
537
-                // nothing left?
538
-                if ($available_payment_amount <= 0) {
539
-                    break;
540
-                }
541
-                if ($refund) {
542
-                    $available_payment_amount = $this->process_registration_refund($registration, $payment, $available_payment_amount);
543
-                } else {
544
-                    $available_payment_amount = $this->process_registration_payment($registration, $payment, $available_payment_amount);
545
-                }
546
-            }
547
-        }
548
-        if ($available_payment_amount > 0 && apply_filters('FHEE__EE_Payment_Processor__process_registration_payments__display_notifications', false)) {
549
-            EE_Error::add_attention(
550
-                sprintf(
551
-                    __('A remainder of %1$s exists after applying this payment to Registration(s) %2$s.%3$sPlease verify that the original payment amount of %4$s is correct. If so, you should edit this payment and select at least one additional registration in the "Registrations to Apply Payment to" section, so that the remainder of this payment can be applied to the additional registration(s).',
552
-                        'event_espresso'),
553
-                    EEH_Template::format_currency($available_payment_amount),
554
-                    implode(', ', array_keys($registrations)),
555
-                    '<br/>',
556
-                    EEH_Template::format_currency($payment->amount())
557
-                ),
558
-                __FILE__, __FUNCTION__, __LINE__
559
-            );
560
-        }
561
-    }
562
-
563
-
564
-
565
-    /**
566
-     * update registration REG_paid field after successful payment and link registration with payment
567
-     *
568
-     * @param EE_Registration $registration
569
-     * @param EE_Payment      $payment
570
-     * @param float           $available_payment_amount
571
-     * @return float
572
-     * @throws \EE_Error
573
-     */
574
-    public function process_registration_payment(
575
-        EE_Registration $registration,
576
-        EE_Payment $payment,
577
-        $available_payment_amount = 0.00
578
-    ) {
579
-        $owing = $registration->final_price() - $registration->paid();
580
-        if ($owing > 0) {
581
-            // don't allow payment amount to exceed the available payment amount, OR the amount owing
582
-            $payment_amount = min($available_payment_amount, $owing);
583
-            // update $available_payment_amount
584
-            $available_payment_amount -= $payment_amount;
585
-            //calculate and set new REG_paid
586
-            $registration->set_paid($registration->paid() + $payment_amount);
587
-            // now save it
588
-            $this->_apply_registration_payment($registration, $payment, $payment_amount);
589
-        }
590
-        return $available_payment_amount;
591
-    }
592
-
593
-
594
-
595
-    /**
596
-     * update registration REG_paid field after successful payment and link registration with payment
597
-     *
598
-     * @param EE_Registration $registration
599
-     * @param EE_Payment      $payment
600
-     * @param float           $payment_amount
601
-     * @return void
602
-     * @throws \EE_Error
603
-     */
604
-    protected function _apply_registration_payment(
605
-        EE_Registration $registration,
606
-        EE_Payment $payment,
607
-        $payment_amount = 0.00
608
-    ) {
609
-        // find any existing reg payment records for this registration and payment
610
-        $existing_reg_payment = EEM_Registration_Payment::instance()->get_one(
611
-            array(array('REG_ID' => $registration->ID(), 'PAY_ID' => $payment->ID()))
612
-        );
613
-        // if existing registration payment exists
614
-        if ($existing_reg_payment instanceof EE_Registration_Payment) {
615
-            // then update that record
616
-            $existing_reg_payment->set_amount($payment_amount);
617
-            $existing_reg_payment->save();
618
-        } else {
619
-            // or add new relation between registration and payment and set amount
620
-            $registration->_add_relation_to($payment, 'Payment', array('RPY_amount' => $payment_amount));
621
-            // make it stick
622
-            $registration->save();
623
-        }
624
-    }
625
-
626
-
627
-
628
-    /**
629
-     * update registration REG_paid field after refund and link registration with payment
630
-     *
631
-     * @param EE_Registration $registration
632
-     * @param EE_Payment      $payment
633
-     * @param float           $available_refund_amount - IMPORTANT !!! SEND AVAILABLE REFUND AMOUNT AS A POSITIVE NUMBER
634
-     * @return float
635
-     * @throws \EE_Error
636
-     */
637
-    public function process_registration_refund(
638
-        EE_Registration $registration,
639
-        EE_Payment $payment,
640
-        $available_refund_amount = 0.00
641
-    ) {
642
-        //EEH_Debug_Tools::printr( $payment->amount(), '$payment->amount()', __FILE__, __LINE__ );
643
-        if ($registration->paid() > 0) {
644
-            // ensure $available_refund_amount is NOT negative
645
-            $available_refund_amount = (float)abs($available_refund_amount);
646
-            // don't allow refund amount to exceed the available payment amount, OR the amount paid
647
-            $refund_amount = min($available_refund_amount, (float)$registration->paid());
648
-            // update $available_payment_amount
649
-            $available_refund_amount -= $refund_amount;
650
-            //calculate and set new REG_paid
651
-            $registration->set_paid($registration->paid() - $refund_amount);
652
-            // convert payment amount back to a negative value for storage in the db
653
-            $refund_amount = (float)abs($refund_amount) * -1;
654
-            // now save it
655
-            $this->_apply_registration_payment($registration, $payment, $refund_amount);
656
-        }
657
-        return $available_refund_amount;
658
-    }
659
-
660
-
661
-
662
-    /**
663
-     * Process payments and transaction after payment process completed.
664
-     * ultimately this will send the TXN and payment details off so that notifications can be sent out.
665
-     * if this request happens to be processing an IPN,
666
-     * then we will also set the Payment Options Reg Step to completed,
667
-     * and attempt to completely finalize the TXN if all of the other Reg Steps are completed as well.
668
-     *
669
-     * @param EE_Transaction $transaction
670
-     * @param EE_Payment     $payment
671
-     * @param bool           $IPN
672
-     * @throws \EE_Error
673
-     */
674
-    protected function _post_payment_processing(EE_Transaction $transaction, EE_Payment $payment, $IPN = false)
675
-    {
676
-        /** @type EE_Transaction_Processor $transaction_processor */
677
-        $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor');
678
-        // is the Payment Options Reg Step completed ?
679
-        $payment_options_step_completed = $transaction->reg_step_completed('payment_options');
680
-        // if the Payment Options Reg Step is completed...
681
-        $revisit = $payment_options_step_completed === true ? true : false;
682
-        // then this is kinda sorta a revisit with regards to payments at least
683
-        $transaction_processor->set_revisit($revisit);
684
-        // if this is an IPN, let's consider the Payment Options Reg Step completed if not already
685
-        if (
686
-            $IPN
687
-            && $payment_options_step_completed !== true
688
-            && ($payment->is_approved() || $payment->is_pending())
689
-        ) {
690
-            $payment_options_step_completed = $transaction->set_reg_step_completed(
691
-                'payment_options'
692
-            );
693
-        }
694
-        // maybe update status, but don't save transaction just yet
695
-        $transaction->update_status_based_on_total_paid(false);
696
-        // check if 'finalize_registration' step has been completed...
697
-        $finalized = $transaction->reg_step_completed('finalize_registration');
698
-        //  if this is an IPN and the final step has not been initiated
699
-        if ($IPN && $payment_options_step_completed && $finalized === false) {
700
-            // and if it hasn't already been set as being started...
701
-            $finalized = $transaction->set_reg_step_initiated('finalize_registration');
702
-        }
703
-        $transaction->save();
704
-        // because the above will return false if the final step was not fully completed, we need to check again...
705
-        if ($IPN && $finalized !== false) {
706
-            // and if we are all good to go, then send out notifications
707
-            add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true');
708
-            //ok, now process the transaction according to the payment
709
-            $transaction_processor->update_transaction_and_registrations_after_checkout_or_payment($transaction, $payment);
710
-        }
711
-        // DEBUG LOG
712
-        $payment_method = $payment->payment_method();
713
-        if ($payment_method instanceof EE_Payment_Method) {
714
-            $payment_method_type_obj = $payment_method->type_obj();
715
-            if ($payment_method_type_obj instanceof EE_PMT_Base) {
716
-                $gateway = $payment_method_type_obj->get_gateway();
717
-                if ($gateway instanceof EE_Gateway) {
718
-                    $gateway->log(
719
-                        array(
720
-                            'message'               => __('Post Payment Transaction Details', 'event_espresso'),
721
-                            'transaction'           => $transaction->model_field_array(),
722
-                            'finalized'             => $finalized,
723
-                            'IPN'                   => $IPN,
724
-                            'deliver_notifications' => has_filter(
725
-                                'FHEE__EED_Messages___maybe_registration__deliver_notifications'
726
-                            ),
727
-                        ),
728
-                        $payment
729
-                    );
730
-                }
731
-            }
732
-        }
733
-    }
734
-
735
-
736
-
737
-    /**
738
-     * Force posts to PayPal to use TLS v1.2. See:
739
-     * https://core.trac.wordpress.org/ticket/36320
740
-     * https://core.trac.wordpress.org/ticket/34924#comment:15
741
-     * https://www.paypal-knowledge.com/infocenter/index?page=content&widgetview=true&id=FAQ1914&viewlocale=en_US
742
-     * This will affect paypal standard, pro, express, and payflow.
743
-     */
744
-    public static function _curl_requests_to_paypal_use_tls($handle, $r, $url)
745
-    {
746
-        if (strstr($url, 'https://') && strstr($url, '.paypal.com')) {
747
-            //Use the value of the constant CURL_SSLVERSION_TLSv1 = 1
748
-            //instead of the constant because it might not be defined
749
-            curl_setopt($handle, CURLOPT_SSLVERSION, 1);
750
-        }
751
-    }
19
+	/**
20
+	 * @var EE_Payment_Processor $_instance
21
+	 * @access    private
22
+	 */
23
+	private static $_instance;
24
+
25
+
26
+
27
+	/**
28
+	 * @singleton method used to instantiate class object
29
+	 * @access    public
30
+	 * @return EE_Payment_Processor instance
31
+	 */
32
+	public static function instance()
33
+	{
34
+		// check if class object is instantiated
35
+		if ( ! self::$_instance instanceof EE_Payment_Processor) {
36
+			self::$_instance = new self();
37
+		}
38
+		return self::$_instance;
39
+	}
40
+
41
+
42
+
43
+	/**
44
+	 *private constructor to prevent direct creation
45
+	 *
46
+	 * @Constructor
47
+	 * @access private
48
+	 */
49
+	private function __construct()
50
+	{
51
+		do_action('AHEE__EE_Payment_Processor__construct');
52
+		add_action('http_api_curl', array($this, '_curl_requests_to_paypal_use_tls'), 10, 3);
53
+	}
54
+
55
+
56
+
57
+	/**
58
+	 * Using the selected gateway, processes the payment for that transaction, and updates the transaction
59
+	 * appropriately. Saves the payment that is generated
60
+	 *
61
+	 * @param EE_Payment_Method    $payment_method
62
+	 * @param EE_Transaction       $transaction
63
+	 * @param float                $amount       if only part of the transaction is to be paid for, how much.
64
+	 *                                           Leave null if payment is for the full amount owing
65
+	 * @param EE_Billing_Info_Form $billing_form (or probably null, if it's an offline or offsite payment method).
66
+	 *                                           Receive_form_submission() should have
67
+	 *                                           already been called on the billing form
68
+	 *                                           (ie, its inputs should have their normalized values set).
69
+	 * @param string               $return_url   string used mostly by offsite gateways to specify
70
+	 *                                           where to go AFTER the offsite gateway
71
+	 * @param string               $method       like 'CART', indicates who the client who called this was
72
+	 * @param bool                 $by_admin     TRUE if payment is being attempted from the admin
73
+	 * @param boolean              $update_txn   whether or not to call
74
+	 *                                           EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment()
75
+	 * @param string               $cancel_url   URL to return to if off-site payments are cancelled
76
+	 * @return \EE_Payment
77
+	 * @throws \EE_Error
78
+	 */
79
+	public function process_payment(
80
+		EE_Payment_Method $payment_method,
81
+		EE_Transaction $transaction,
82
+		$amount = null,
83
+		$billing_form = null,
84
+		$return_url = null,
85
+		$method = 'CART',
86
+		$by_admin = false,
87
+		$update_txn = true,
88
+		$cancel_url = ''
89
+	) {
90
+		if ((float)$amount < 0) {
91
+			throw new EE_Error(
92
+				sprintf(
93
+					__(
94
+						'Attempting to make a payment for a negative amount of %1$d for transaction %2$d. That should be a refund',
95
+						'event_espresso'
96
+					),
97
+					$amount,
98
+					$transaction->ID()
99
+				)
100
+			);
101
+		}
102
+		// verify payment method
103
+		$payment_method = EEM_Payment_Method::instance()->ensure_is_obj($payment_method, true);
104
+		// verify transaction
105
+		EEM_Transaction::instance()->ensure_is_obj($transaction);
106
+		$transaction->set_payment_method_ID($payment_method->ID());
107
+		// verify payment method type
108
+		if ($payment_method->type_obj() instanceof EE_PMT_Base) {
109
+			$payment = $payment_method->type_obj()->process_payment(
110
+				$transaction,
111
+				min($amount, $transaction->remaining()),//make sure we don't overcharge
112
+				$billing_form,
113
+				$return_url,
114
+				add_query_arg(array('ee_cancel_payment' => true), $cancel_url),
115
+				$method,
116
+				$by_admin
117
+			);
118
+			// check if payment method uses an off-site gateway
119
+			if ($payment_method->type_obj()->payment_occurs() !== EE_PMT_Base::offsite) {
120
+				// don't process payments for off-site gateways yet because no payment has occurred yet
121
+				$this->update_txn_based_on_payment($transaction, $payment, $update_txn);
122
+			}
123
+			return $payment;
124
+		} else {
125
+			EE_Error::add_error(
126
+				sprintf(
127
+					__('A valid payment method could not be determined due to a technical issue.%sPlease try again or contact %s for assistance.', 'event_espresso'),
128
+					'<br/>',
129
+					EE_Registry::instance()->CFG->organization->get_pretty('email')
130
+				), __FILE__, __FUNCTION__, __LINE__
131
+			);
132
+			return null;
133
+		}
134
+	}
135
+
136
+
137
+
138
+	/**
139
+	 * @param EE_Transaction|int $transaction
140
+	 * @param EE_Payment_Method  $payment_method
141
+	 * @throws EE_Error
142
+	 * @return string
143
+	 */
144
+	public function get_ipn_url_for_payment_method($transaction, $payment_method)
145
+	{
146
+		/** @type \EE_Transaction $transaction */
147
+		$transaction = EEM_Transaction::instance()->ensure_is_obj($transaction);
148
+		$primary_reg = $transaction->primary_registration();
149
+		if ( ! $primary_reg instanceof EE_Registration) {
150
+			throw new EE_Error(
151
+				sprintf(
152
+					__(
153
+						"Cannot get IPN URL for transaction with ID %d because it has no primary registration",
154
+						"event_espresso"
155
+					),
156
+					$transaction->ID()
157
+				)
158
+			);
159
+		}
160
+		$payment_method = EEM_Payment_Method::instance()->ensure_is_obj($payment_method, true);
161
+		$url = add_query_arg(
162
+			array(
163
+				'e_reg_url_link'    => $primary_reg->reg_url_link(),
164
+				'ee_payment_method' => $payment_method->slug(),
165
+			),
166
+			EE_Registry::instance()->CFG->core->txn_page_url()
167
+		);
168
+		return $url;
169
+	}
170
+
171
+
172
+
173
+	/**
174
+	 * Process the IPN. Firstly, we'll hope we put the standard args into the IPN URL so
175
+	 * we can easily find what registration the IPN is for and what payment method.
176
+	 * However, if not, we'll give all payment methods a chance to claim it and process it.
177
+	 * If a payment is found for the IPN info, it is saved.
178
+	 *
179
+	 * @param array              $_req_data            eg $_REQUEST
180
+	 * @param EE_Transaction|int $transaction          optional (or a transactions id)
181
+	 * @param EE_Payment_Method  $payment_method       (or a slug or id of one)
182
+	 * @param boolean            $update_txn           whether or not to call
183
+	 *                                                 EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment()
184
+	 * @param bool               $separate_IPN_request whether the IPN uses a separate request ( true like PayPal )
185
+	 *                                                 or is processed manually ( false like Mijireh )
186
+	 * @throws EE_Error
187
+	 * @throws Exception
188
+	 * @return EE_Payment
189
+	 */
190
+	public function process_ipn(
191
+		$_req_data,
192
+		$transaction = null,
193
+		$payment_method = null,
194
+		$update_txn = true,
195
+		$separate_IPN_request = true
196
+	) {
197
+		EE_Registry::instance()->load_model('Change_Log');
198
+		$_req_data = $this->_remove_unusable_characters_from_array((array)$_req_data);
199
+		EE_Processor_Base::set_IPN($separate_IPN_request);
200
+		$obj_for_log = null;
201
+		if ($transaction instanceof EE_Transaction) {
202
+			$obj_for_log = $transaction;
203
+			if ($payment_method instanceof EE_Payment_Method) {
204
+				$obj_for_log = EEM_Payment::instance()->get_one(
205
+					array(
206
+						array('TXN_ID' => $transaction->ID(), 'PMD_ID' => $payment_method->ID()),
207
+						'order_by' => array('PAY_timestamp' => 'desc'),
208
+					)
209
+				);
210
+			}
211
+		} else if ($payment_method instanceof EE_Payment) {
212
+			$obj_for_log = $payment_method;
213
+		}
214
+		$log = EEM_Change_Log::instance()->log(
215
+			EEM_Change_Log::type_gateway,
216
+			array('IPN data received' => $_req_data),
217
+			$obj_for_log
218
+		);
219
+		try {
220
+			/**
221
+			 * @var EE_Payment $payment
222
+			 */
223
+			$payment = null;
224
+			if ($transaction && $payment_method) {
225
+				/** @type EE_Transaction $transaction */
226
+				$transaction = EEM_Transaction::instance()->ensure_is_obj($transaction);
227
+				/** @type EE_Payment_Method $payment_method */
228
+				$payment_method = EEM_Payment_Method::instance()->ensure_is_obj($payment_method);
229
+				if ($payment_method->type_obj() instanceof EE_PMT_Base) {
230
+					try {
231
+						$payment = $payment_method->type_obj()->handle_ipn($_req_data, $transaction);
232
+						$log->set_object($payment);
233
+					} catch (EventEspresso\core\exceptions\IpnException $e) {
234
+						EEM_Change_Log::instance()->log(
235
+							EEM_Change_Log::type_gateway,
236
+							array(
237
+								'message'     => 'IPN Exception: ' . $e->getMessage(),
238
+								'current_url' => EEH_URL::current_url(),
239
+								'payment'     => $e->getPaymentProperties(),
240
+								'IPN_data'    => $e->getIpnData(),
241
+							),
242
+							$obj_for_log
243
+						);
244
+						return $e->getPayment();
245
+					}
246
+				} else {
247
+					// not a payment
248
+					EE_Error::add_error(
249
+						sprintf(
250
+							__('A valid payment method could not be determined due to a technical issue.%sPlease refresh your browser and try again or contact %s for assistance.', 'event_espresso'),
251
+							'<br/>',
252
+							EE_Registry::instance()->CFG->organization->get_pretty('email')
253
+						),
254
+						__FILE__, __FUNCTION__, __LINE__
255
+					);
256
+				}
257
+			} else {
258
+				//that's actually pretty ok. The IPN just wasn't able
259
+				//to identify which transaction or payment method this was for
260
+				// give all active payment methods a chance to claim it
261
+				$active_payment_methods = EEM_Payment_Method::instance()->get_all_active();
262
+				foreach ($active_payment_methods as $active_payment_method) {
263
+					try {
264
+						$payment = $active_payment_method->type_obj()->handle_unclaimed_ipn($_req_data);
265
+						$payment_method = $active_payment_method;
266
+						EEM_Change_Log::instance()->log(
267
+							EEM_Change_Log::type_gateway, array('IPN data' => $_req_data), $payment
268
+						);
269
+						break;
270
+					} catch (EventEspresso\core\exceptions\IpnException $e) {
271
+						EEM_Change_Log::instance()->log(
272
+							EEM_Change_Log::type_gateway,
273
+							array(
274
+								'message'     => 'IPN Exception: ' . $e->getMessage(),
275
+								'current_url' => EEH_URL::current_url(),
276
+								'payment'     => $e->getPaymentProperties(),
277
+								'IPN_data'    => $e->getIpnData(),
278
+							),
279
+							$obj_for_log
280
+						);
281
+						return $e->getPayment();
282
+					} catch (EE_Error $e) {
283
+						//that's fine- it apparently couldn't handle the IPN
284
+					}
285
+				}
286
+			}
287
+			// 			EEM_Payment_Log::instance()->log("got to 7",$transaction,$payment_method);
288
+			if ($payment instanceof EE_Payment) {
289
+				$payment->save();
290
+				//  update the TXN
291
+				$this->update_txn_based_on_payment($transaction, $payment, $update_txn, $separate_IPN_request);
292
+			} else {
293
+				//we couldn't find the payment for this IPN... let's try and log at least SOMETHING
294
+				if ($payment_method) {
295
+					EEM_Change_Log::instance()->log(EEM_Change_Log::type_gateway, array('IPN data' => $_req_data), $payment_method);
296
+				} elseif ($transaction) {
297
+					EEM_Change_Log::instance()->log(EEM_Change_Log::type_gateway, array('IPN data' => $_req_data), $transaction);
298
+				}
299
+			}
300
+			return $payment;
301
+		} catch (EE_Error $e) {
302
+			do_action(
303
+				'AHEE__log', __FILE__, __FUNCTION__, sprintf(
304
+					__('Error occurred while receiving IPN. Transaction: %1$s, req data: %2$s. The error was "%3$s"', 'event_espresso'),
305
+					print_r($transaction, true),
306
+					print_r($_req_data, true),
307
+					$e->getMessage()
308
+				)
309
+			);
310
+			throw $e;
311
+		}
312
+	}
313
+
314
+
315
+
316
+	/**
317
+	 * Removes any non-printable illegal characters from the input,
318
+	 * which might cause a raucous when trying to insert into the database
319
+	 *
320
+	 * @param  array $request_data
321
+	 * @return array
322
+	 */
323
+	protected function _remove_unusable_characters_from_array(array $request_data)
324
+	{
325
+		$return_data = array();
326
+		foreach ($request_data as $key => $value) {
327
+			$return_data[$this->_remove_unusable_characters($key)] = $this->_remove_unusable_characters($value);
328
+		}
329
+		return $return_data;
330
+	}
331
+
332
+
333
+
334
+	/**
335
+	 * Removes any non-printable illegal characters from the input,
336
+	 * which might cause a raucous when trying to insert into the database
337
+	 *
338
+	 * @param string $request_data
339
+	 * @return string
340
+	 */
341
+	protected function _remove_unusable_characters($request_data)
342
+	{
343
+		return preg_replace('/[^[:print:]]/', '', $request_data);
344
+	}
345
+
346
+
347
+
348
+	/**
349
+	 * Should be called just before displaying the payment attempt results to the user,
350
+	 * when the payment attempt has finished. Some payment methods may have special
351
+	 * logic to perform here. For example, if process_payment() happens on a special request
352
+	 * and then the user is redirected to a page that displays the payment's status, this
353
+	 * should be called while loading the page that displays the payment's status. If the user is
354
+	 * sent to an offsite payment provider, this should be called upon returning from that offsite payment
355
+	 * provider.
356
+	 *
357
+	 * @param EE_Transaction|int $transaction
358
+	 * @param bool               $update_txn whether or not to call
359
+	 *                                       EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment()
360
+	 * @throws \EE_Error
361
+	 * @return EE_Payment
362
+	 * @deprecated 4.6.24 method is no longer used. Instead it is up to client code, like SPCO,
363
+	 *                                       to call handle_ipn() for offsite gateways that don't receive separate IPNs
364
+	 */
365
+	public function finalize_payment_for($transaction, $update_txn = true)
366
+	{
367
+		/** @var $transaction EE_Transaction */
368
+		$transaction = EEM_Transaction::instance()->ensure_is_obj($transaction);
369
+		$last_payment_method = $transaction->payment_method();
370
+		if ($last_payment_method instanceof EE_Payment_Method) {
371
+			$payment = $last_payment_method->type_obj()->finalize_payment_for($transaction);
372
+			$this->update_txn_based_on_payment($transaction, $payment, $update_txn);
373
+			return $payment;
374
+		} else {
375
+			return null;
376
+		}
377
+	}
378
+
379
+
380
+
381
+	/**
382
+	 * Processes a direct refund request, saves the payment, and updates the transaction appropriately.
383
+	 *
384
+	 * @param EE_Payment_Method $payment_method
385
+	 * @param EE_Payment        $payment_to_refund
386
+	 * @param array             $refund_info
387
+	 * @return EE_Payment
388
+	 * @throws \EE_Error
389
+	 */
390
+	public function process_refund(
391
+		EE_Payment_Method $payment_method,
392
+		EE_Payment $payment_to_refund,
393
+		$refund_info = array()
394
+	) {
395
+		if ($payment_method instanceof EE_Payment_Method && $payment_method->type_obj()->supports_sending_refunds()) {
396
+			$payment_method->type_obj()->process_refund($payment_to_refund, $refund_info);
397
+			$this->update_txn_based_on_payment($payment_to_refund->transaction(), $payment_to_refund);
398
+		}
399
+		return $payment_to_refund;
400
+	}
401
+
402
+
403
+
404
+	/**
405
+	 * This should be called each time there may have been an update to a
406
+	 * payment on a transaction (ie, we asked for a payment to process a
407
+	 * payment for a transaction, or we told a payment method about an IPN, or
408
+	 * we told a payment method to
409
+	 * "finalize_payment_for" (a transaction), or we told a payment method to
410
+	 * process a refund. This should handle firing the correct hooks to
411
+	 * indicate
412
+	 * what exactly happened and updating the transaction appropriately). This
413
+	 * could be integrated directly into EE_Transaction upon save, but we want
414
+	 * this logic to be separate from 'normal' plain-jane saving and updating
415
+	 * of transactions and payments, and to be tied to payment processing.
416
+	 * Note: this method DOES NOT save the payment passed into it. It is the responsibility
417
+	 * of previous code to decide whether or not to save (because the payment passed into
418
+	 * this method might be a temporary, never-to-be-saved payment from an offline gateway,
419
+	 * in which case we only want that payment object for some temporary usage during this request,
420
+	 * but we don't want it to be saved).
421
+	 *
422
+	 * @param EE_Transaction|int $transaction
423
+	 * @param EE_Payment         $payment
424
+	 * @param boolean            $update_txn
425
+	 *                        whether or not to call
426
+	 *                        EE_Transaction_Processor::
427
+	 *                        update_transaction_and_registrations_after_checkout_or_payment()
428
+	 *                        (you can save 1 DB query if you know you're going
429
+	 *                        to save it later instead)
430
+	 * @param bool               $IPN
431
+	 *                        if processing IPNs or other similar payment
432
+	 *                        related activities that occur in alternate
433
+	 *                        requests than the main one that is processing the
434
+	 *                        TXN, then set this to true to check whether the
435
+	 *                        TXN is locked before updating
436
+	 * @throws \EE_Error
437
+	 */
438
+	public function update_txn_based_on_payment($transaction, $payment, $update_txn = true, $IPN = false)
439
+	{
440
+		$do_action = 'AHEE__EE_Payment_Processor__update_txn_based_on_payment__not_successful';
441
+		/** @type EE_Transaction $transaction */
442
+		$transaction = EEM_Transaction::instance()->ensure_is_obj($transaction);
443
+		// can we freely update the TXN at this moment?
444
+		if ($IPN && $transaction->is_locked()) {
445
+			// don't update the transaction at this exact moment
446
+			// because the TXN is active in another request
447
+			EE_Cron_Tasks::schedule_update_transaction_with_payment(
448
+				time(),
449
+				$transaction->ID(),
450
+				$payment->ID()
451
+			);
452
+		} else {
453
+			// verify payment and that it has been saved
454
+			if ($payment instanceof EE_Payment && $payment->ID()) {
455
+				if (
456
+					$payment->payment_method() instanceof EE_Payment_Method
457
+					&& $payment->payment_method()->type_obj() instanceof EE_PMT_Base
458
+				) {
459
+					$payment->payment_method()->type_obj()->update_txn_based_on_payment($payment);
460
+					// update TXN registrations with payment info
461
+					$this->process_registration_payments($transaction, $payment);
462
+				}
463
+				$do_action = $payment->just_approved()
464
+					? 'AHEE__EE_Payment_Processor__update_txn_based_on_payment__successful'
465
+					: $do_action;
466
+			} else {
467
+				// send out notifications
468
+				add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true');
469
+				$do_action = 'AHEE__EE_Payment_Processor__update_txn_based_on_payment__no_payment_made';
470
+			}
471
+			if ($payment instanceof EE_Payment && $payment->status() !== EEM_Payment::status_id_failed) {
472
+				/** @type EE_Transaction_Payments $transaction_payments */
473
+				$transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments');
474
+				// set new value for total paid
475
+				$transaction_payments->calculate_total_payments_and_update_status($transaction);
476
+				// call EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment() ???
477
+				if ($update_txn) {
478
+					$this->_post_payment_processing($transaction, $payment, $IPN);
479
+				}
480
+			}
481
+			// granular hook for others to use.
482
+			do_action($do_action, $transaction, $payment);
483
+			do_action('AHEE_log', __CLASS__, __FUNCTION__, $do_action, '$do_action');
484
+			//global hook for others to use.
485
+			do_action('AHEE__EE_Payment_Processor__update_txn_based_on_payment', $transaction, $payment);
486
+		}
487
+	}
488
+
489
+
490
+
491
+	/**
492
+	 * update registrations REG_paid field after successful payment and link registrations with payment
493
+	 *
494
+	 * @param EE_Transaction    $transaction
495
+	 * @param EE_Payment        $payment
496
+	 * @param EE_Registration[] $registrations
497
+	 * @throws \EE_Error
498
+	 */
499
+	public function process_registration_payments(
500
+		EE_Transaction $transaction,
501
+		EE_Payment $payment,
502
+		$registrations = array()
503
+	) {
504
+		// only process if payment was successful
505
+		if ($payment->status() !== EEM_Payment::status_id_approved) {
506
+			return;
507
+		}
508
+		//EEM_Registration::instance()->show_next_x_db_queries();
509
+		if (empty($registrations)) {
510
+			// find registrations with monies owing that can receive a payment
511
+			$registrations = $transaction->registrations(
512
+				array(
513
+					array(
514
+						// only these reg statuses can receive payments
515
+						'STS_ID'           => array('IN', EEM_Registration::reg_statuses_that_allow_payment()),
516
+						'REG_final_price'  => array('!=', 0),
517
+						'REG_final_price*' => array('!=', 'REG_paid', true),
518
+					),
519
+				)
520
+			);
521
+		}
522
+		// still nothing ??!??
523
+		if (empty($registrations)) {
524
+			return;
525
+		}
526
+		// todo: break out the following logic into a separate strategy class
527
+		// todo: named something like "Sequential_Reg_Payment_Strategy"
528
+		// todo: which would apply payments using the capitalist "first come first paid" approach
529
+		// todo: then have another strategy class like "Distributed_Reg_Payment_Strategy"
530
+		// todo: which would be the socialist "everybody gets a piece of pie" approach,
531
+		// todo: which would be better for deposits, where you want a bit of the payment applied to each registration
532
+		$refund = $payment->is_a_refund();
533
+		// how much is available to apply to registrations?
534
+		$available_payment_amount = abs($payment->amount());
535
+		foreach ($registrations as $registration) {
536
+			if ($registration instanceof EE_Registration) {
537
+				// nothing left?
538
+				if ($available_payment_amount <= 0) {
539
+					break;
540
+				}
541
+				if ($refund) {
542
+					$available_payment_amount = $this->process_registration_refund($registration, $payment, $available_payment_amount);
543
+				} else {
544
+					$available_payment_amount = $this->process_registration_payment($registration, $payment, $available_payment_amount);
545
+				}
546
+			}
547
+		}
548
+		if ($available_payment_amount > 0 && apply_filters('FHEE__EE_Payment_Processor__process_registration_payments__display_notifications', false)) {
549
+			EE_Error::add_attention(
550
+				sprintf(
551
+					__('A remainder of %1$s exists after applying this payment to Registration(s) %2$s.%3$sPlease verify that the original payment amount of %4$s is correct. If so, you should edit this payment and select at least one additional registration in the "Registrations to Apply Payment to" section, so that the remainder of this payment can be applied to the additional registration(s).',
552
+						'event_espresso'),
553
+					EEH_Template::format_currency($available_payment_amount),
554
+					implode(', ', array_keys($registrations)),
555
+					'<br/>',
556
+					EEH_Template::format_currency($payment->amount())
557
+				),
558
+				__FILE__, __FUNCTION__, __LINE__
559
+			);
560
+		}
561
+	}
562
+
563
+
564
+
565
+	/**
566
+	 * update registration REG_paid field after successful payment and link registration with payment
567
+	 *
568
+	 * @param EE_Registration $registration
569
+	 * @param EE_Payment      $payment
570
+	 * @param float           $available_payment_amount
571
+	 * @return float
572
+	 * @throws \EE_Error
573
+	 */
574
+	public function process_registration_payment(
575
+		EE_Registration $registration,
576
+		EE_Payment $payment,
577
+		$available_payment_amount = 0.00
578
+	) {
579
+		$owing = $registration->final_price() - $registration->paid();
580
+		if ($owing > 0) {
581
+			// don't allow payment amount to exceed the available payment amount, OR the amount owing
582
+			$payment_amount = min($available_payment_amount, $owing);
583
+			// update $available_payment_amount
584
+			$available_payment_amount -= $payment_amount;
585
+			//calculate and set new REG_paid
586
+			$registration->set_paid($registration->paid() + $payment_amount);
587
+			// now save it
588
+			$this->_apply_registration_payment($registration, $payment, $payment_amount);
589
+		}
590
+		return $available_payment_amount;
591
+	}
592
+
593
+
594
+
595
+	/**
596
+	 * update registration REG_paid field after successful payment and link registration with payment
597
+	 *
598
+	 * @param EE_Registration $registration
599
+	 * @param EE_Payment      $payment
600
+	 * @param float           $payment_amount
601
+	 * @return void
602
+	 * @throws \EE_Error
603
+	 */
604
+	protected function _apply_registration_payment(
605
+		EE_Registration $registration,
606
+		EE_Payment $payment,
607
+		$payment_amount = 0.00
608
+	) {
609
+		// find any existing reg payment records for this registration and payment
610
+		$existing_reg_payment = EEM_Registration_Payment::instance()->get_one(
611
+			array(array('REG_ID' => $registration->ID(), 'PAY_ID' => $payment->ID()))
612
+		);
613
+		// if existing registration payment exists
614
+		if ($existing_reg_payment instanceof EE_Registration_Payment) {
615
+			// then update that record
616
+			$existing_reg_payment->set_amount($payment_amount);
617
+			$existing_reg_payment->save();
618
+		} else {
619
+			// or add new relation between registration and payment and set amount
620
+			$registration->_add_relation_to($payment, 'Payment', array('RPY_amount' => $payment_amount));
621
+			// make it stick
622
+			$registration->save();
623
+		}
624
+	}
625
+
626
+
627
+
628
+	/**
629
+	 * update registration REG_paid field after refund and link registration with payment
630
+	 *
631
+	 * @param EE_Registration $registration
632
+	 * @param EE_Payment      $payment
633
+	 * @param float           $available_refund_amount - IMPORTANT !!! SEND AVAILABLE REFUND AMOUNT AS A POSITIVE NUMBER
634
+	 * @return float
635
+	 * @throws \EE_Error
636
+	 */
637
+	public function process_registration_refund(
638
+		EE_Registration $registration,
639
+		EE_Payment $payment,
640
+		$available_refund_amount = 0.00
641
+	) {
642
+		//EEH_Debug_Tools::printr( $payment->amount(), '$payment->amount()', __FILE__, __LINE__ );
643
+		if ($registration->paid() > 0) {
644
+			// ensure $available_refund_amount is NOT negative
645
+			$available_refund_amount = (float)abs($available_refund_amount);
646
+			// don't allow refund amount to exceed the available payment amount, OR the amount paid
647
+			$refund_amount = min($available_refund_amount, (float)$registration->paid());
648
+			// update $available_payment_amount
649
+			$available_refund_amount -= $refund_amount;
650
+			//calculate and set new REG_paid
651
+			$registration->set_paid($registration->paid() - $refund_amount);
652
+			// convert payment amount back to a negative value for storage in the db
653
+			$refund_amount = (float)abs($refund_amount) * -1;
654
+			// now save it
655
+			$this->_apply_registration_payment($registration, $payment, $refund_amount);
656
+		}
657
+		return $available_refund_amount;
658
+	}
659
+
660
+
661
+
662
+	/**
663
+	 * Process payments and transaction after payment process completed.
664
+	 * ultimately this will send the TXN and payment details off so that notifications can be sent out.
665
+	 * if this request happens to be processing an IPN,
666
+	 * then we will also set the Payment Options Reg Step to completed,
667
+	 * and attempt to completely finalize the TXN if all of the other Reg Steps are completed as well.
668
+	 *
669
+	 * @param EE_Transaction $transaction
670
+	 * @param EE_Payment     $payment
671
+	 * @param bool           $IPN
672
+	 * @throws \EE_Error
673
+	 */
674
+	protected function _post_payment_processing(EE_Transaction $transaction, EE_Payment $payment, $IPN = false)
675
+	{
676
+		/** @type EE_Transaction_Processor $transaction_processor */
677
+		$transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor');
678
+		// is the Payment Options Reg Step completed ?
679
+		$payment_options_step_completed = $transaction->reg_step_completed('payment_options');
680
+		// if the Payment Options Reg Step is completed...
681
+		$revisit = $payment_options_step_completed === true ? true : false;
682
+		// then this is kinda sorta a revisit with regards to payments at least
683
+		$transaction_processor->set_revisit($revisit);
684
+		// if this is an IPN, let's consider the Payment Options Reg Step completed if not already
685
+		if (
686
+			$IPN
687
+			&& $payment_options_step_completed !== true
688
+			&& ($payment->is_approved() || $payment->is_pending())
689
+		) {
690
+			$payment_options_step_completed = $transaction->set_reg_step_completed(
691
+				'payment_options'
692
+			);
693
+		}
694
+		// maybe update status, but don't save transaction just yet
695
+		$transaction->update_status_based_on_total_paid(false);
696
+		// check if 'finalize_registration' step has been completed...
697
+		$finalized = $transaction->reg_step_completed('finalize_registration');
698
+		//  if this is an IPN and the final step has not been initiated
699
+		if ($IPN && $payment_options_step_completed && $finalized === false) {
700
+			// and if it hasn't already been set as being started...
701
+			$finalized = $transaction->set_reg_step_initiated('finalize_registration');
702
+		}
703
+		$transaction->save();
704
+		// because the above will return false if the final step was not fully completed, we need to check again...
705
+		if ($IPN && $finalized !== false) {
706
+			// and if we are all good to go, then send out notifications
707
+			add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true');
708
+			//ok, now process the transaction according to the payment
709
+			$transaction_processor->update_transaction_and_registrations_after_checkout_or_payment($transaction, $payment);
710
+		}
711
+		// DEBUG LOG
712
+		$payment_method = $payment->payment_method();
713
+		if ($payment_method instanceof EE_Payment_Method) {
714
+			$payment_method_type_obj = $payment_method->type_obj();
715
+			if ($payment_method_type_obj instanceof EE_PMT_Base) {
716
+				$gateway = $payment_method_type_obj->get_gateway();
717
+				if ($gateway instanceof EE_Gateway) {
718
+					$gateway->log(
719
+						array(
720
+							'message'               => __('Post Payment Transaction Details', 'event_espresso'),
721
+							'transaction'           => $transaction->model_field_array(),
722
+							'finalized'             => $finalized,
723
+							'IPN'                   => $IPN,
724
+							'deliver_notifications' => has_filter(
725
+								'FHEE__EED_Messages___maybe_registration__deliver_notifications'
726
+							),
727
+						),
728
+						$payment
729
+					);
730
+				}
731
+			}
732
+		}
733
+	}
734
+
735
+
736
+
737
+	/**
738
+	 * Force posts to PayPal to use TLS v1.2. See:
739
+	 * https://core.trac.wordpress.org/ticket/36320
740
+	 * https://core.trac.wordpress.org/ticket/34924#comment:15
741
+	 * https://www.paypal-knowledge.com/infocenter/index?page=content&widgetview=true&id=FAQ1914&viewlocale=en_US
742
+	 * This will affect paypal standard, pro, express, and payflow.
743
+	 */
744
+	public static function _curl_requests_to_paypal_use_tls($handle, $r, $url)
745
+	{
746
+		if (strstr($url, 'https://') && strstr($url, '.paypal.com')) {
747
+			//Use the value of the constant CURL_SSLVERSION_TLSv1 = 1
748
+			//instead of the constant because it might not be defined
749
+			curl_setopt($handle, CURLOPT_SSLVERSION, 1);
750
+		}
751
+	}
752 752
 }
Please login to merge, or discard this patch.
core/libraries/payment_methods/EEI_Payment_Method_Interfaces.php 3 patches
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -5,7 +5,7 @@  discard block
 block discarded – undo
5 5
  *
6 6
  * allows gateways to be used by different systems other than Event Espresso
7 7
  */
8
-interface EEI_Payment extends EEI_Base{
8
+interface EEI_Payment extends EEI_Base {
9 9
 
10 10
 	/**
11 11
 	 * @return string indicating which the payment is approved, pending, cancelled or failed
@@ -153,7 +153,7 @@  discard block
 block discarded – undo
153 153
 /**
154 154
  * Interface EEI_Payment_Method
155 155
  */
156
-interface EEI_Payment_Method{
156
+interface EEI_Payment_Method {
157 157
 
158 158
 }
159 159
 
@@ -172,7 +172,7 @@  discard block
 block discarded – undo
172 172
 	 * @param string $model_name
173 173
 	 * @return EE_Log
174 174
 	 */
175
-	public function gateway_log($message,$id,$model_name);
175
+	public function gateway_log($message, $id, $model_name);
176 176
 }
177 177
 
178 178
 
Please login to merge, or discard this patch.
Doc Comments   +17 added lines, -2 removed lines patch added patch discarded remove patch
@@ -30,6 +30,7 @@  discard block
 block discarded – undo
30 30
 	/**
31 31
 	 *
32 32
 	 * @param string $status
33
+	 * @return void
33 34
 	 */
34 35
 	public function set_status($status);
35 36
 
@@ -37,6 +38,7 @@  discard block
 block discarded – undo
37 38
 	 * Sets the response from the gateway, which is displayable to the user.
38 39
 	 * Eg, 'payment was approved', 'payment failed because invalid date', etc.
39 40
 	 * @param string $response
41
+	 * @return void
40 42
 	 */
41 43
 	public function set_gateway_response($response);
42 44
 
@@ -44,6 +46,7 @@  discard block
 block discarded – undo
44 46
 	 * Sets the response details, usually the entire contents of an IPN request,
45 47
 	 * or data about the direct payment data sent
46 48
 	 * @param mixed $response_details
49
+	 * @return void
47 50
 	 */
48 51
 	public function set_details($response_details);
49 52
 
@@ -56,12 +59,14 @@  discard block
 block discarded – undo
56 59
 	/**
57 60
 	 * Sets the URl to redirect to, to process payment
58 61
 	 * @param string $url
62
+	 * @return void
59 63
 	 */
60 64
 	public function set_redirect_url($url);
61 65
 
62 66
 	/**
63 67
 	 * Sets the argument which should be passed to the redirect url (ie, usually POST variables)
64 68
 	 * @param array $args
69
+	 * @return void
65 70
 	 */
66 71
 	public function set_redirect_args($args);
67 72
 
@@ -80,25 +85,27 @@  discard block
 block discarded – undo
80 85
 	/**
81 86
 	 * Sets the amount for this payment
82 87
 	 * @param float $amount
88
+	 * @return void
83 89
 	 */
84 90
 	public function set_amount($amount);
85 91
 
86 92
 	/**
87 93
 	 * Sets the ID of the gateway transaction
88 94
 	 * @param string $txn_id
95
+	 * @return void
89 96
 	 */
90 97
 	public function set_txn_id_chq_nmbr($txn_id);
91 98
 
92 99
 	/**
93 100
 	 * Sets a string for some extra accounting info
94 101
 	 * @param string $extra_accounting_info
102
+	 * @return void
95 103
 	 */
96 104
 	public function set_extra_accntng($extra_accounting_info);
97 105
 
98 106
     /**
99 107
      * Gets the first event for this payment (it's possible that it could be for multiple)
100 108
      *
101
-     * @param EE_Payment $payment
102 109
      * @return EE_Event|null
103 110
      */
104 111
     public function get_first_event();
@@ -106,7 +113,6 @@  discard block
 block discarded – undo
106 113
     /**
107 114
      * Gets the name of the first event for which is being paid
108 115
      *
109
-     * @param EE_Payment $payment
110 116
      * @return string
111 117
      */
112 118
     public function get_first_event_name();
@@ -139,22 +145,27 @@  discard block
 block discarded – undo
139 145
 interface EEMI_Payment {
140 146
 	/**
141 147
 	 * returns a string for the approved status
148
+	 * @return string
142 149
 	 */
143 150
 	public function approved_status();
144 151
 	/**
145 152
 	 * returns a string for the pending status
153
+	 * @return string
146 154
 	 */
147 155
 	public function pending_status();
148 156
 	/**
149 157
 	 * returns a string for the cancelled status
158
+	 * @return string
150 159
 	 */
151 160
 	public function cancelled_status();
152 161
 	/**
153 162
 	 * returns a string for the failed status
163
+	 * @return string
154 164
 	 */
155 165
 	public function failed_status();
156 166
 	/**
157 167
 	 * returns a string for the declined status
168
+	 * @return string
158 169
 	 */
159 170
 	public function declined_status();
160 171
 
@@ -208,6 +219,10 @@  discard block
 block discarded – undo
208 219
  * Interface for an event being registered for
209 220
  */
210 221
 interface EEI_Event {
222
+
223
+	/**
224
+	 * @return boolean
225
+	 */
211 226
 	public function name();
212 227
 }
213 228
 
Please login to merge, or discard this patch.
Indentation   +28 added lines, -28 removed lines patch added patch discarded remove patch
@@ -95,34 +95,34 @@
 block discarded – undo
95 95
 	 */
96 96
 	public function set_extra_accntng($extra_accounting_info);
97 97
 
98
-    /**
99
-     * Gets the first event for this payment (it's possible that it could be for multiple)
100
-     *
101
-     * @param EE_Payment $payment
102
-     * @return EE_Event|null
103
-     */
104
-    public function get_first_event();
105
-
106
-    /**
107
-     * Gets the name of the first event for which is being paid
108
-     *
109
-     * @param EE_Payment $payment
110
-     * @return string
111
-     */
112
-    public function get_first_event_name();
113
-
114
-    /**
115
-     * Returns the payment's transaction's primary registration
116
-     *
117
-     * @return EE_Registration|null
118
-     */
119
-    public function get_primary_registration();
120
-
121
-    /**
122
-     * Gets the payment's transaction's primary registration's attendee, or null
123
-     * @return EE_Attendee|null
124
-     */
125
-    public function get_primary_attendee();
98
+	/**
99
+	 * Gets the first event for this payment (it's possible that it could be for multiple)
100
+	 *
101
+	 * @param EE_Payment $payment
102
+	 * @return EE_Event|null
103
+	 */
104
+	public function get_first_event();
105
+
106
+	/**
107
+	 * Gets the name of the first event for which is being paid
108
+	 *
109
+	 * @param EE_Payment $payment
110
+	 * @return string
111
+	 */
112
+	public function get_first_event_name();
113
+
114
+	/**
115
+	 * Returns the payment's transaction's primary registration
116
+	 *
117
+	 * @return EE_Registration|null
118
+	 */
119
+	public function get_primary_registration();
120
+
121
+	/**
122
+	 * Gets the payment's transaction's primary registration's attendee, or null
123
+	 * @return EE_Attendee|null
124
+	 */
125
+	public function get_primary_attendee();
126 126
 }
127 127
 
128 128
 
Please login to merge, or discard this patch.
core/EE_Error.core.php 1 patch
Spacing   +247 added lines, -247 removed lines patch added patch discarded remove patch
@@ -1,8 +1,8 @@  discard block
 block discarded – undo
1 1
 <?php if ( ! defined('EVENT_ESPRESSO_VERSION')) exit('No direct script access allowed');
2 2
 // if you're a dev and want to receive all errors via email add this to your wp-config.php: define( 'EE_ERROR_EMAILS', TRUE );
3
-if ( defined( 'WP_DEBUG' ) && WP_DEBUG === TRUE && defined( 'EE_ERROR_EMAILS' ) && EE_ERROR_EMAILS === TRUE ) {
4
-	set_error_handler( array( 'EE_Error', 'error_handler' ));
5
-	register_shutdown_function( array( 'EE_Error', 'fatal_error_handler' ));
3
+if (defined('WP_DEBUG') && WP_DEBUG === TRUE && defined('EE_ERROR_EMAILS') && EE_ERROR_EMAILS === TRUE) {
4
+	set_error_handler(array('EE_Error', 'error_handler'));
5
+	register_shutdown_function(array('EE_Error', 'fatal_error_handler'));
6 6
 }
7 7
 /**
8 8
  *
@@ -64,7 +64,7 @@  discard block
 block discarded – undo
64 64
 	* 	@access	private
65 65
     *	@var boolean
66 66
 	*/
67
-	private static $_espresso_notices = array( 'success' => FALSE, 'errors' => FALSE, 'attention' => FALSE );
67
+	private static $_espresso_notices = array('success' => FALSE, 'errors' => FALSE, 'attention' => FALSE);
68 68
 
69 69
 
70 70
 
@@ -75,11 +75,11 @@  discard block
 block discarded – undo
75 75
 	*	@access public
76 76
 	*	@echo string
77 77
 	*/
78
-	function __construct( $message, $code = 0, Exception $previous = NULL ) {
79
-		if ( version_compare( phpversion(), '5.3.0', '<' )) {
80
-			parent::__construct( $message, $code );
78
+	function __construct($message, $code = 0, Exception $previous = NULL) {
79
+		if (version_compare(phpversion(), '5.3.0', '<')) {
80
+			parent::__construct($message, $code);
81 81
 		} else {
82
-			parent::__construct( $message, $code, $previous );
82
+			parent::__construct($message, $code, $previous);
83 83
 		}
84 84
 	}
85 85
 
@@ -94,10 +94,10 @@  discard block
 block discarded – undo
94 94
 	 * @param $line
95 95
 	 * @return void
96 96
 	 */
97
-	public static function error_handler( $code, $message, $file, $line ) {
98
-		$type = EE_Error::error_type( $code );
97
+	public static function error_handler($code, $message, $file, $line) {
98
+		$type = EE_Error::error_type($code);
99 99
 		$site = site_url();
100
-		switch ( $site ) {
100
+		switch ($site) {
101 101
 			case 'http://ee4.eventespresso.com/' :
102 102
 			case 'http://ee4decaf.eventespresso.com/' :
103 103
 			case 'http://ee4hf.eventespresso.com/' :
@@ -110,16 +110,16 @@  discard block
 block discarded – undo
110 110
 				$to = '[email protected]';
111 111
 				break;
112 112
 			default :
113
-				$to = get_option( 'admin_email' );
113
+				$to = get_option('admin_email');
114 114
 		}
115
-		$subject = $type . ' ' . $message . ' in ' . EVENT_ESPRESSO_VERSION . ' on ' . site_url();
116
-		$msg = EE_Error::_format_error( $type, $message, $file, $line );
117
-		if ( function_exists( 'wp_mail' )) {
118
-			add_filter( 'wp_mail_content_type', array( 'EE_Error', 'set_content_type' ));
119
-			wp_mail( $to, $subject, $msg );
115
+		$subject = $type.' '.$message.' in '.EVENT_ESPRESSO_VERSION.' on '.site_url();
116
+		$msg = EE_Error::_format_error($type, $message, $file, $line);
117
+		if (function_exists('wp_mail')) {
118
+			add_filter('wp_mail_content_type', array('EE_Error', 'set_content_type'));
119
+			wp_mail($to, $subject, $msg);
120 120
 		}
121 121
 		echo '<div id="message" class="espresso-notices error"><p>';
122
-		echo $type . ': ' . $message . '<br />' . $file . ' line ' . $line;
122
+		echo $type.': '.$message.'<br />'.$file.' line '.$line;
123 123
 		echo '<br /></p></div>';
124 124
 	}
125 125
 
@@ -132,8 +132,8 @@  discard block
 block discarded – undo
132 132
 	 * @param $code
133 133
 	 * @return string
134 134
 	 */
135
-	public static function error_type( $code ) {
136
-		switch( $code ) {
135
+	public static function error_type($code) {
136
+		switch ($code) {
137 137
 			case E_ERROR: // 1 //
138 138
 			return 'E_ERROR';
139 139
 			case E_WARNING: // 2 //
@@ -179,8 +179,8 @@  discard block
 block discarded – undo
179 179
 	*/
180 180
 	public static function fatal_error_handler() {
181 181
 		$last_error = error_get_last();
182
-		if ( $last_error['type'] === E_ERROR ) {
183
-			EE_Error::error_handler( E_ERROR, $last_error['message'], $last_error['file'], $last_error['line'] );
182
+		if ($last_error['type'] === E_ERROR) {
183
+			EE_Error::error_handler(E_ERROR, $last_error['message'], $last_error['file'], $last_error['line']);
184 184
 		}
185 185
 	}
186 186
 
@@ -195,7 +195,7 @@  discard block
 block discarded – undo
195 195
 	 * @param $line
196 196
 	 * @return string
197 197
 	 */
198
-	private static function _format_error( $code, $message, $file, $line ) {
198
+	private static function _format_error($code, $message, $file, $line) {
199 199
 		$html  = "<table cellpadding='5'><thead bgcolor='#f8f8f8'><th>Item</th><th align='left'>Details</th></thead><tbody>";
200 200
 		$html .= "<tr valign='top'><td><b>Code</b></td><td>$code</td></tr>";
201 201
 		$html .= "<tr valign='top'><td><b>Error</b></td><td>$message</td></tr>";
@@ -213,7 +213,7 @@  discard block
 block discarded – undo
213 213
 	 * @param $content_type
214 214
 	 * @return string
215 215
 	 */
216
-	public static function set_content_type( $content_type ) {
216
+	public static function set_content_type($content_type) {
217 217
 		return 'text/html';
218 218
 	}
219 219
 
@@ -227,24 +227,24 @@  discard block
 block discarded – undo
227 227
 	*/
228 228
     public function get_error() {
229 229
 
230
-		if( apply_filters( 'FHEE__EE_Error__get_error__show_normal_exceptions', FALSE ) ){
230
+		if (apply_filters('FHEE__EE_Error__get_error__show_normal_exceptions', FALSE)) {
231 231
 			throw $this;
232 232
 		}
233 233
 		// get separate user and developer messages if they exist
234
-		$msg = explode( '||', $this->getMessage() );
234
+		$msg = explode('||', $this->getMessage());
235 235
 		$user_msg = $msg[0];
236
-		$dev_msg = isset( $msg[1] ) ? $msg[1] : $msg[0];
236
+		$dev_msg = isset($msg[1]) ? $msg[1] : $msg[0];
237 237
 		$msg = WP_DEBUG ? $dev_msg : $user_msg;
238 238
 
239 239
 		// add details to _all_exceptions array
240 240
 		$x_time = time();
241
-		self::$_all_exceptions[ $x_time ]['name'] 	= get_class( $this );
242
-		self::$_all_exceptions[ $x_time ]['file'] 		= $this->getFile();
243
-		self::$_all_exceptions[ $x_time ]['line'] 		= $this->getLine();
244
-		self::$_all_exceptions[ $x_time ]['msg'] 	= $msg;
245
-		self::$_all_exceptions[ $x_time ]['code'] 	= $this->getCode();
246
-		self::$_all_exceptions[ $x_time ]['trace'] 	= $this->getTrace();
247
-		self::$_all_exceptions[ $x_time ]['string'] 	= $this->getTraceAsString();
241
+		self::$_all_exceptions[$x_time]['name'] = get_class($this);
242
+		self::$_all_exceptions[$x_time]['file'] 		= $this->getFile();
243
+		self::$_all_exceptions[$x_time]['line'] 		= $this->getLine();
244
+		self::$_all_exceptions[$x_time]['msg'] = $msg;
245
+		self::$_all_exceptions[$x_time]['code'] = $this->getCode();
246
+		self::$_all_exceptions[$x_time]['trace'] 	= $this->getTrace();
247
+		self::$_all_exceptions[$x_time]['string'] = $this->getTraceAsString();
248 248
 		self::$_error_count++;
249 249
 
250 250
 		//add_action( 'shutdown', array( $this, 'display_errors' ));
@@ -262,14 +262,14 @@  discard block
 block discarded – undo
262 262
      * @param string $type_to_check
263 263
      * @return bool
264 264
      */
265
-    public static function has_error( $check_stored = false, $type_to_check = 'errors' ){
265
+    public static function has_error($check_stored = false, $type_to_check = 'errors') {
266 266
 	    $has_error = isset(self::$_espresso_notices[$type_to_check]) && ! empty(self::$_espresso_notices[$type_to_check])
267 267
             ? true
268 268
             : false;
269
-	    if ( $check_stored && ! $has_error ) {
270
-		    $notices = (array) get_option( 'ee_notices', array() );
271
-		    foreach ( $notices as $type => $notice ) {
272
-			    if ( $type === $type_to_check && $notice ) {
269
+	    if ($check_stored && ! $has_error) {
270
+		    $notices = (array) get_option('ee_notices', array());
271
+		    foreach ($notices as $type => $notice) {
272
+			    if ($type === $type_to_check && $notice) {
273 273
 				    return true;
274 274
 			    }
275 275
 		    }
@@ -284,7 +284,7 @@  discard block
 block discarded – undo
284 284
 	*	@access public
285 285
 	*	@echo string
286 286
 	*/
287
-    public function display_errors(){
287
+    public function display_errors() {
288 288
 
289 289
 		$trace_details = '';
290 290
 
@@ -345,18 +345,18 @@  discard block
 block discarded – undo
345 345
 </style>
346 346
 <div id="ee-error-message" class="error">';
347 347
 
348
-		if ( ! WP_DEBUG ) {
348
+		if ( ! WP_DEBUG) {
349 349
 			$output .= '
350 350
 	<p>';
351 351
 		}
352 352
 
353 353
 		// cycle thru errors
354
-		foreach ( self::$_all_exceptions as $time => $ex ) {
354
+		foreach (self::$_all_exceptions as $time => $ex) {
355 355
 
356 356
 			// process trace info
357
-			if ( empty( $ex['trace'] )) {
357
+			if (empty($ex['trace'])) {
358 358
 
359
-	            $trace_details .= __( 'Sorry, but no trace information was available for this exception.', 'event_espresso' );
359
+	            $trace_details .= __('Sorry, but no trace information was available for this exception.', 'event_espresso');
360 360
 
361 361
 			} else {
362 362
 
@@ -371,50 +371,50 @@  discard block
 block discarded – undo
371 371
 					<th scope="col" align="left">Method( arguments )</th>
372 372
 				</tr>';
373 373
 
374
-				$last_on_stack = count( $ex['trace'] ) - 1;
374
+				$last_on_stack = count($ex['trace']) - 1;
375 375
 				// reverse array so that stack is in proper chronological order
376
-				$sorted_trace = array_reverse( $ex['trace'] );
376
+				$sorted_trace = array_reverse($ex['trace']);
377 377
 
378
-				foreach ( $sorted_trace as $nmbr => $trace ) {
378
+				foreach ($sorted_trace as $nmbr => $trace) {
379 379
 
380
-					$file = isset( $trace['file'] ) ? $trace['file'] : '' ;
381
-					$class = isset( $trace['class'] ) ? $trace['class'] : '';
382
-					$type = isset( $trace['type'] ) ? $trace['type'] : '';
383
-					$function = isset( $trace['function'] ) ? $trace['function'] : '';
384
-					$args = isset( $trace['args'] ) ? $this->_convert_args_to_string( $trace['args'] ) : '';
385
-					$line = isset( $trace['line'] ) ? $trace['line'] : '';
380
+					$file = isset($trace['file']) ? $trace['file'] : '';
381
+					$class = isset($trace['class']) ? $trace['class'] : '';
382
+					$type = isset($trace['type']) ? $trace['type'] : '';
383
+					$function = isset($trace['function']) ? $trace['function'] : '';
384
+					$args = isset($trace['args']) ? $this->_convert_args_to_string($trace['args']) : '';
385
+					$line = isset($trace['line']) ? $trace['line'] : '';
386 386
 					$zebra = $nmbr % 2 ? ' odd' : '';
387 387
 
388
-					if ( empty( $file ) && ! empty( $class )) {
389
-						$a = new ReflectionClass( $class );
388
+					if (empty($file) && ! empty($class)) {
389
+						$a = new ReflectionClass($class);
390 390
 						$file = $a->getFileName();
391
-						if ( empty( $line ) && ! empty( $function )) {
392
-							$b = new ReflectionMethod( $class, $function );
391
+						if (empty($line) && ! empty($function)) {
392
+							$b = new ReflectionMethod($class, $function);
393 393
 							$line = $b->getStartLine();
394 394
 						}
395 395
 					}
396 396
 
397
-					if ( $nmbr == $last_on_stack ) {
397
+					if ($nmbr == $last_on_stack) {
398 398
 						$file = $ex['file'] != '' ? $ex['file'] : $file;
399 399
 						$line = $ex['line'] != '' ? $ex['line'] : $line;
400
-						$error_code = self::generate_error_code ( $file, $trace['function'], $line );
400
+						$error_code = self::generate_error_code($file, $trace['function'], $line);
401 401
 					}
402 402
 
403
-					$nmbr_dsply = ! empty( $nmbr ) ? $nmbr : '&nbsp;';
404
-					$line_dsply = ! empty( $line ) ? $line : '&nbsp;';
405
-					$file_dsply = ! empty( $file ) ? $file : '&nbsp;';
406
-					$class_dsply = ! empty( $class ) ? $class : '&nbsp;';
407
-					$type_dsply = ! empty( $type ) ? $type : '&nbsp;';
408
-					$function_dsply = ! empty( $function ) ? $function : '&nbsp;';
409
-					$args_dsply = ! empty( $args ) ? '( ' . $args . ' )' : '';
403
+					$nmbr_dsply = ! empty($nmbr) ? $nmbr : '&nbsp;';
404
+					$line_dsply = ! empty($line) ? $line : '&nbsp;';
405
+					$file_dsply = ! empty($file) ? $file : '&nbsp;';
406
+					$class_dsply = ! empty($class) ? $class : '&nbsp;';
407
+					$type_dsply = ! empty($type) ? $type : '&nbsp;';
408
+					$function_dsply = ! empty($function) ? $function : '&nbsp;';
409
+					$args_dsply = ! empty($args) ? '( '.$args.' )' : '';
410 410
 
411 411
 		              $trace_details .= '
412 412
 					<tr>
413
-						<td align="right" class="' . $zebra . '">' . $nmbr_dsply . '</td>
414
-						<td align="right" class="' . $zebra . '">' . $line_dsply . '</td>
415
-						<td align="left" class="' . $zebra . '">' . $file_dsply . '</td>
416
-						<td align="left" class="' . $zebra . '">' . $class_dsply . '</td>
417
-						<td align="left" class="' . $zebra . '">' . $type_dsply . $function_dsply . $args_dsply . '</td>
413
+						<td align="right" class="' . $zebra.'">'.$nmbr_dsply.'</td>
414
+						<td align="right" class="' . $zebra.'">'.$line_dsply.'</td>
415
+						<td align="left" class="' . $zebra.'">'.$file_dsply.'</td>
416
+						<td align="left" class="' . $zebra.'">'.$class_dsply.'</td>
417
+						<td align="left" class="' . $zebra.'">'.$type_dsply.$function_dsply.$args_dsply.'</td>
418 418
 					</tr>';
419 419
 
420 420
 
@@ -429,9 +429,9 @@  discard block
 block discarded – undo
429 429
 			$ex['code'] = $ex['code'] ? $ex['code'] : $error_code;
430 430
 
431 431
 			// add generic non-identifying messages for non-privileged uesrs
432
-			if ( ! WP_DEBUG ) {
432
+			if ( ! WP_DEBUG) {
433 433
 
434
-				$output .= '<span class="ee-error-user-msg-spn">' . trim( $ex['msg'] )  . '</span> &nbsp; <sup>' . $ex['code'] . '</sup><br />';
434
+				$output .= '<span class="ee-error-user-msg-spn">'.trim($ex['msg']).'</span> &nbsp; <sup>'.$ex['code'].'</sup><br />';
435 435
 
436 436
 			} else {
437 437
 
@@ -439,24 +439,24 @@  discard block
 block discarded – undo
439 439
 				$output .= '
440 440
 		<div class="ee-error-dev-msg-dv">
441 441
 			<p class="ee-error-dev-msg-pg">
442
-				<strong class="ee-error-dev-msg-str">An ' . $ex['name'] . ' exception was thrown!</strong>  &nbsp; <span>code: ' . $ex['code'] . '</span><br />
443
-				<span class="big-text">"' . trim( $ex['msg'] ) . '"</span><br/>
444
-				<a id="display-ee-error-trace-' . self::$_error_count . $time . '" class="display-ee-error-trace-lnk small-text" rel="ee-error-trace-' . self::$_error_count . $time . '">
445
-					' . __( 'click to view backtrace and class/method details', 'event_espresso' ) . '
442
+				<strong class="ee-error-dev-msg-str">An ' . $ex['name'].' exception was thrown!</strong>  &nbsp; <span>code: '.$ex['code'].'</span><br />
443
+				<span class="big-text">"' . trim($ex['msg']).'"</span><br/>
444
+				<a id="display-ee-error-trace-' . self::$_error_count.$time.'" class="display-ee-error-trace-lnk small-text" rel="ee-error-trace-'.self::$_error_count.$time.'">
445
+					' . __('click to view backtrace and class/method details', 'event_espresso').'
446 446
 				</a><br />
447 447
 				<span class="small-text lt-grey-text">'.$ex['file'].' &nbsp; ( line no: '.$ex['line'].' )</span>
448 448
 			</p>
449
-			<div id="ee-error-trace-' . self::$_error_count . $time . '-dv" class="ee-error-trace-dv" style="display: none;">
449
+			<div id="ee-error-trace-' . self::$_error_count.$time.'-dv" class="ee-error-trace-dv" style="display: none;">
450 450
 				' . $trace_details;
451 451
 
452
-				if ( ! empty( $class )) {
452
+				if ( ! empty($class)) {
453 453
 					$output .= '
454 454
 				<div style="padding:3px; margin:0 0 1em; border:1px solid #666; background:#fff; border-radius:3px;">
455 455
 					<div style="padding:1em 2em; border:1px solid #666; background:#f9f9f9;">
456 456
 						<h3>Class Details</h3>';
457
-						$a = new ReflectionClass( $class );
457
+						$a = new ReflectionClass($class);
458 458
 						$output .= '
459
-						<pre>' . $a . '</pre>
459
+						<pre>' . $a.'</pre>
460 460
 					</div>
461 461
 				</div>';
462 462
 				}
@@ -468,14 +468,14 @@  discard block
 block discarded – undo
468 468
 
469 469
 			}
470 470
 
471
-			$this->write_to_error_log( $time, $ex );
471
+			$this->write_to_error_log($time, $ex);
472 472
 
473 473
 		}
474 474
 
475 475
 		// remove last linebreak
476
-		$output = substr( $output, 0, ( count( $output ) - 7 ));
476
+		$output = substr($output, 0, (count($output) - 7));
477 477
 
478
-		if ( ! WP_DEBUG ) {
478
+		if ( ! WP_DEBUG) {
479 479
 			$output .= '
480 480
 	</p>';
481 481
 		}
@@ -483,10 +483,10 @@  discard block
 block discarded – undo
483 483
 		$output .= '
484 484
 </div>';
485 485
 
486
-		$output .= self::_print_scripts( TRUE );
486
+		$output .= self::_print_scripts(TRUE);
487 487
 
488
-		if ( defined( 'DOING_AJAX' )) {
489
-			echo wp_json_encode( array( 'error' => $output ));
488
+		if (defined('DOING_AJAX')) {
489
+			echo wp_json_encode(array('error' => $output));
490 490
 			exit();
491 491
 		}
492 492
 
@@ -506,29 +506,29 @@  discard block
 block discarded – undo
506 506
 	*	@ param array $arguments
507 507
 	*	@ return string
508 508
 	*/
509
-	private function _convert_args_to_string ( $arguments = array(), $array = FALSE ) {
509
+	private function _convert_args_to_string($arguments = array(), $array = FALSE) {
510 510
 
511 511
 		$arg_string = '';
512
-		if ( ! empty( $arguments )) {
512
+		if ( ! empty($arguments)) {
513 513
 
514 514
 			$args = array();
515 515
 
516
-			foreach ( $arguments as $arg ) {
516
+			foreach ($arguments as $arg) {
517 517
 
518
-				if ( ! empty( $arg )) {
518
+				if ( ! empty($arg)) {
519 519
 
520
-					if ( is_string( $arg )) {
521
-						$args[] = " '" . $arg . "'";
522
-					} elseif ( is_array( $arg )) {
523
-						$args[] = 'ARRAY(' . $this->_convert_args_to_string( $arg, TRUE );
524
-					} elseif ( is_null( $arg )) {
520
+					if (is_string($arg)) {
521
+						$args[] = " '".$arg."'";
522
+					} elseif (is_array($arg)) {
523
+						$args[] = 'ARRAY('.$this->_convert_args_to_string($arg, TRUE);
524
+					} elseif (is_null($arg)) {
525 525
 						$args[] = ' NULL';
526
-					} elseif ( is_bool( $arg )) {
527
-						$args[] = ( $arg ) ? ' TRUE' : ' FALSE';
528
-					} elseif ( is_object( $arg )) {
529
-						$args[] = ' OBJECT ' . get_class( $arg );
530
-					} elseif ( is_resource( $arg )) {
531
-						$args[] = get_resource_type( $arg );
526
+					} elseif (is_bool($arg)) {
527
+						$args[] = ($arg) ? ' TRUE' : ' FALSE';
528
+					} elseif (is_object($arg)) {
529
+						$args[] = ' OBJECT '.get_class($arg);
530
+					} elseif (is_resource($arg)) {
531
+						$args[] = get_resource_type($arg);
532 532
 					} else {
533 533
 						$args[] = $arg;
534 534
 					}
@@ -536,9 +536,9 @@  discard block
 block discarded – undo
536 536
 				}
537 537
 
538 538
 			}
539
-			$arg_string = implode( ', ', $args );
539
+			$arg_string = implode(', ', $args);
540 540
 		}
541
-		if ( $array ) {
541
+		if ($array) {
542 542
 			$arg_string .= ' )';
543 543
 		}
544 544
 		return $arg_string;
@@ -558,8 +558,8 @@  discard block
 block discarded – undo
558 558
 	* 	@param		string		$line	the line number where the error occurred - just use __LINE__
559 559
 	* 	@return 		void
560 560
 	*/
561
-	public static function add_error( $msg = NULL, $file = NULL, $func = NULL, $line = NULL ) {
562
-		self::_add_notice ( 'errors', $msg, $file, $func, $line );
561
+	public static function add_error($msg = NULL, $file = NULL, $func = NULL, $line = NULL) {
562
+		self::_add_notice('errors', $msg, $file, $func, $line);
563 563
 		self::$_error_count++;
564 564
 	}
565 565
 
@@ -572,11 +572,11 @@  discard block
 block discarded – undo
572 572
 	 * @param string $line
573 573
 	 * @throws EE_Error
574 574
 	 */
575
-	public static function throw_exception_if_debugging( $msg = null, $file = null, $func = null, $line = null ) {
576
-		if( WP_DEBUG ) {
577
-			throw new EE_Error( $msg );
578
-		} else  {
579
-			EE_Error::add_error( $msg, $file, $func, $line );
575
+	public static function throw_exception_if_debugging($msg = null, $file = null, $func = null, $line = null) {
576
+		if (WP_DEBUG) {
577
+			throw new EE_Error($msg);
578
+		} else {
579
+			EE_Error::add_error($msg, $file, $func, $line);
580 580
 		}
581 581
 	}
582 582
 
@@ -594,8 +594,8 @@  discard block
 block discarded – undo
594 594
 	* 	@param		string		$line	the line number where the error occurred - just use __LINE__
595 595
 	* 	@return 		void
596 596
 	*/
597
-	public static function add_success( $msg = NULL, $file = NULL, $func = NULL, $line = NULL ) {
598
-		self::_add_notice ( 'success', $msg, $file, $func, $line );
597
+	public static function add_success($msg = NULL, $file = NULL, $func = NULL, $line = NULL) {
598
+		self::_add_notice('success', $msg, $file, $func, $line);
599 599
 	}
600 600
 
601 601
 
@@ -612,8 +612,8 @@  discard block
 block discarded – undo
612 612
 	* 	@param		string		$line	the line number where the error occurred - just use __LINE__
613 613
 	* 	@return 		void
614 614
 	*/
615
-	public static function add_attention( $msg = NULL, $file = NULL, $func = NULL, $line = NULL ) {
616
-		self::_add_notice ( 'attention', $msg, $file, $func, $line );
615
+	public static function add_attention($msg = NULL, $file = NULL, $func = NULL, $line = NULL) {
616
+		self::_add_notice('attention', $msg, $file, $func, $line);
617 617
 	}
618 618
 
619 619
 
@@ -631,12 +631,12 @@  discard block
 block discarded – undo
631 631
 	* 	@param		string		$line	the line number where the error occurred - just use __LINE__
632 632
 	* 	@return 		void
633 633
 	*/
634
-	private static function _add_notice( $type = 'success', $msg = NULL, $file = NULL, $func = NULL, $line = NULL ) {
635
-		if ( empty( $msg )) {
634
+	private static function _add_notice($type = 'success', $msg = NULL, $file = NULL, $func = NULL, $line = NULL) {
635
+		if (empty($msg)) {
636 636
 			EE_Error::doing_it_wrong(
637
-				'EE_Error::add_' . $type . '()',
637
+				'EE_Error::add_'.$type.'()',
638 638
 				sprintf(
639
-					__( 'Notifications are not much use without a message! Please add a message to the EE_Error::add_%s() call made in %s on line %d', 'event_espresso' ),
639
+					__('Notifications are not much use without a message! Please add a message to the EE_Error::add_%s() call made in %s on line %d', 'event_espresso'),
640 640
 					$type,
641 641
 					$file,
642 642
 					$line
@@ -644,17 +644,17 @@  discard block
 block discarded – undo
644 644
 				EVENT_ESPRESSO_VERSION
645 645
 			);
646 646
 		}
647
-		if ( $type == 'errors' && ( empty( $file ) || empty( $func ) || empty( $line ))) {
647
+		if ($type == 'errors' && (empty($file) || empty($func) || empty($line))) {
648 648
 			EE_Error::doing_it_wrong(
649 649
 				'EE_Error::add_error()',
650
-				__('You need to provide the file name, function name, and line number that the error occurred on in order to better assist with debugging.', 'event_espresso' ),
650
+				__('You need to provide the file name, function name, and line number that the error occurred on in order to better assist with debugging.', 'event_espresso'),
651 651
 				EVENT_ESPRESSO_VERSION
652 652
 			);
653 653
 		}
654 654
 		// get separate user and developer messages if they exist
655
-		$msg = explode( '||', $msg );
655
+		$msg = explode('||', $msg);
656 656
 		$user_msg = $msg[0];
657
-		$dev_msg = isset( $msg[1] ) ? $msg[1] : $msg[0];
657
+		$dev_msg = isset($msg[1]) ? $msg[1] : $msg[0];
658 658
 		/**
659 659
 		 * Do an action so other code can be triggered when a notice is created
660 660
 		 * @param string $type can be 'errors', 'attention', or 'success'
@@ -664,22 +664,22 @@  discard block
 block discarded – undo
664 664
 		 * @param string $func function where error was generated
665 665
 		 * @param string $line line where error was generated
666 666
 		 */
667
-		do_action( 'AHEE__EE_Error___add_notice', $type, $user_msg, $dev_msg, $file, $func, $line );
667
+		do_action('AHEE__EE_Error___add_notice', $type, $user_msg, $dev_msg, $file, $func, $line);
668 668
 		$msg = WP_DEBUG ? $dev_msg : $user_msg;
669 669
 		// add notice if message exists
670
-		if ( ! empty( $msg )) {
670
+		if ( ! empty($msg)) {
671 671
 			// get error code
672
-			$notice_code = EE_Error::generate_error_code( $file, $func, $line );
673
-			if ( WP_DEBUG && $type == 'errors' ) {
674
-				$msg .= '<br/><span class="tiny-text">' . $notice_code . '</span>';
672
+			$notice_code = EE_Error::generate_error_code($file, $func, $line);
673
+			if (WP_DEBUG && $type == 'errors') {
674
+				$msg .= '<br/><span class="tiny-text">'.$notice_code.'</span>';
675 675
 			}
676 676
 			// add notice. Index by code if it's not blank
677
-			if( $notice_code ) {
678
-				self::$_espresso_notices[ $type ][ $notice_code ] = $msg;
677
+			if ($notice_code) {
678
+				self::$_espresso_notices[$type][$notice_code] = $msg;
679 679
 			} else {
680
-				self::$_espresso_notices[ $type ][] = $msg;
680
+				self::$_espresso_notices[$type][] = $msg;
681 681
 			}
682
-			add_action( 'wp_footer', array( 'EE_Error', 'enqueue_error_scripts' ), 1 );
682
+			add_action('wp_footer', array('EE_Error', 'enqueue_error_scripts'), 1);
683 683
 		}
684 684
 
685 685
 	}
@@ -733,7 +733,7 @@  discard block
 block discarded – undo
733 733
 	*	@access private
734 734
 	*	@return void
735 735
 	*/
736
-	public static function reset_notices(){
736
+	public static function reset_notices() {
737 737
     	self::$_espresso_notices['success'] = FALSE;
738 738
     	self::$_espresso_notices['attention'] = FALSE;
739 739
     	self::$_espresso_notices['errors'] = FALSE;
@@ -746,14 +746,14 @@  discard block
 block discarded – undo
746 746
 	*	@access public
747 747
 	*	@return int
748 748
 	*/
749
-    public static function has_notices(){
749
+    public static function has_notices() {
750 750
 		$has_notices = 0;
751 751
 		// check for success messages
752
-		$has_notices = self::$_espresso_notices['success'] && ! empty(  self::$_espresso_notices['success'] ) ? 3 : $has_notices;
752
+		$has_notices = self::$_espresso_notices['success'] && ! empty(self::$_espresso_notices['success']) ? 3 : $has_notices;
753 753
 		// check for attention messages
754
-		$has_notices = self::$_espresso_notices['attention'] && ! empty(  self::$_espresso_notices['attention'] ) ? 2 : $has_notices;
754
+		$has_notices = self::$_espresso_notices['attention'] && ! empty(self::$_espresso_notices['attention']) ? 2 : $has_notices;
755 755
 		// check for error messages
756
-		$has_notices = self::$_espresso_notices['errors'] && ! empty(  self::$_espresso_notices['errors'] ) ? 1 : $has_notices;
756
+		$has_notices = self::$_espresso_notices['errors'] && ! empty(self::$_espresso_notices['errors']) ? 1 : $has_notices;
757 757
 		return $has_notices;
758 758
 	}
759 759
 
@@ -768,9 +768,9 @@  discard block
 block discarded – undo
768 768
 	 */
769 769
 	public static function get_vanilla_notices() {
770 770
 		return array(
771
-			'success' => isset( self::$_espresso_notices['success'] ) ? self::$_espresso_notices['success'] : array(),
772
-			'attention' => isset( self::$_espresso_notices['attention'] )  ? self::$_espresso_notices['attention'] : array(),
773
-			'errors' => isset( self::$_espresso_notices['errors'] ) ? self::$_espresso_notices['errors'] : array(),
771
+			'success' => isset(self::$_espresso_notices['success']) ? self::$_espresso_notices['success'] : array(),
772
+			'attention' => isset(self::$_espresso_notices['attention']) ? self::$_espresso_notices['attention'] : array(),
773
+			'errors' => isset(self::$_espresso_notices['errors']) ? self::$_espresso_notices['errors'] : array(),
774 774
 		);
775 775
 	}
776 776
 
@@ -786,8 +786,8 @@  discard block
 block discarded – undo
786 786
 	* 	@param		boolean		$remove_empty		whether or not to unset empty messages
787 787
 	* 	@return 		array
788 788
 	*/
789
-	public static function get_notices( $format_output = TRUE, $save_to_transient = FALSE, $remove_empty = TRUE ) {
790
-		do_action( 'AHEE_log', __FILE__, __FUNCTION__, '' );
789
+	public static function get_notices($format_output = TRUE, $save_to_transient = FALSE, $remove_empty = TRUE) {
790
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
791 791
 
792 792
 		$success_messages = '';
793 793
 		$attention_messages = '';
@@ -797,44 +797,44 @@  discard block
 block discarded – undo
797 797
 		// EEH_Debug_Tools::printr( self::$_espresso_notices, 'espresso_notices  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' );
798 798
 
799 799
 		// either save notices to the db
800
-		if ( $save_to_transient ) {
801
-			update_option( 'ee_notices', self::$_espresso_notices );
800
+		if ($save_to_transient) {
801
+			update_option('ee_notices', self::$_espresso_notices);
802 802
 			return;
803 803
 		}
804 804
 		// grab any notices that have been previously saved
805
-		if ( $notices = get_option( 'ee_notices', FALSE )) {
806
-			foreach ( $notices as $type => $notice ) {
807
-				if ( is_array( $notice ) && ! empty( $notice )) {
805
+		if ($notices = get_option('ee_notices', FALSE)) {
806
+			foreach ($notices as $type => $notice) {
807
+				if (is_array($notice) && ! empty($notice)) {
808 808
 					// make sure that existing notice type is an array
809
-					self::$_espresso_notices[ $type ] =  is_array( self::$_espresso_notices[ $type ] ) && ! empty( self::$_espresso_notices[ $type ] ) ? self::$_espresso_notices[ $type ] : array();
809
+					self::$_espresso_notices[$type] = is_array(self::$_espresso_notices[$type]) && ! empty(self::$_espresso_notices[$type]) ? self::$_espresso_notices[$type] : array();
810 810
 					// merge stored notices with any newly created ones
811
-					self::$_espresso_notices[ $type ] = array_merge( self::$_espresso_notices[ $type ], $notice );
811
+					self::$_espresso_notices[$type] = array_merge(self::$_espresso_notices[$type], $notice);
812 812
 					$print_scripts = TRUE;
813 813
 				}
814 814
 			}
815 815
 			// now clear any stored notices
816
-			update_option( 'ee_notices', FALSE );
816
+			update_option('ee_notices', FALSE);
817 817
 		}
818 818
 
819 819
 		// check for success messages
820
-		if ( self::$_espresso_notices['success'] && ! empty(  self::$_espresso_notices['success'] )) {
820
+		if (self::$_espresso_notices['success'] && ! empty(self::$_espresso_notices['success'])) {
821 821
 			// combine messages
822
-			$success_messages .= implode( self::$_espresso_notices['success'], '<br />' );
822
+			$success_messages .= implode(self::$_espresso_notices['success'], '<br />');
823 823
 			$print_scripts = TRUE;
824 824
 		}
825 825
 
826 826
 		// check for attention messages
827
-		if ( self::$_espresso_notices['attention'] && ! empty(  self::$_espresso_notices['attention'] ) ) {
827
+		if (self::$_espresso_notices['attention'] && ! empty(self::$_espresso_notices['attention'])) {
828 828
 			// combine messages
829
-			$attention_messages .= implode( self::$_espresso_notices['attention'], '<br />' );
829
+			$attention_messages .= implode(self::$_espresso_notices['attention'], '<br />');
830 830
 			$print_scripts = TRUE;
831 831
 		}
832 832
 
833 833
 		// check for error messages
834
-		if ( self::$_espresso_notices['errors'] && ! empty(  self::$_espresso_notices['errors'] ) ) {
835
-			$error_messages .= count( self::$_espresso_notices['errors'] ) > 1 ? __( 'The following errors have occurred:<br />', 'event_espresso' ) : __( 'An error has occurred:<br />', 'event_espresso' );
834
+		if (self::$_espresso_notices['errors'] && ! empty(self::$_espresso_notices['errors'])) {
835
+			$error_messages .= count(self::$_espresso_notices['errors']) > 1 ? __('The following errors have occurred:<br />', 'event_espresso') : __('An error has occurred:<br />', 'event_espresso');
836 836
 			// combine messages
837
-			$error_messages .= implode( self::$_espresso_notices['errors'], '<br />' );
837
+			$error_messages .= implode(self::$_espresso_notices['errors'], '<br />');
838 838
 			$print_scripts = TRUE;
839 839
 		}
840 840
 
@@ -848,21 +848,21 @@  discard block
 block discarded – undo
848 848
 				$css_id = is_admin() ? 'message' : 'espresso-notices-success';
849 849
 				$css_class = is_admin() ? 'updated fade' : 'success fade-away';
850 850
 				//showMessage( $success_messages );
851
-				$notices .= '<div id="' . $css_id . '" class="espresso-notices ' . $css_class . '" style="display:none;"><p>' . $success_messages . '</p>' . $close . '</div>';
851
+				$notices .= '<div id="'.$css_id.'" class="espresso-notices '.$css_class.'" style="display:none;"><p>'.$success_messages.'</p>'.$close.'</div>';
852 852
 			}
853 853
 
854 854
 			if ($attention_messages !== '') {
855 855
 				$css_id = is_admin() ? 'message' : 'espresso-notices-attention';
856 856
 				$css_class = is_admin() ? 'updated ee-notices-attention' : 'attention fade-away';
857 857
 				//showMessage( $error_messages, TRUE );
858
-				$notices .= '<div id="' . $css_id . '" class="espresso-notices ' . $css_class . '" style="display:none;"><p>' . $attention_messages . '</p>' . $close . '</div>';
858
+				$notices .= '<div id="'.$css_id.'" class="espresso-notices '.$css_class.'" style="display:none;"><p>'.$attention_messages.'</p>'.$close.'</div>';
859 859
 			}
860 860
 
861 861
 			if ($error_messages !== '') {
862 862
 				$css_id = is_admin() ? 'message' : 'espresso-notices-error';
863 863
 				$css_class = is_admin() ? 'error' : 'error fade-away';
864 864
 				//showMessage( $error_messages, TRUE );
865
-				$notices .= '<div id="' . $css_id . '" class="espresso-notices ' . $css_class . '" style="display:none;"><p>' . $error_messages . '</p>' . $close . '</div>';
865
+				$notices .= '<div id="'.$css_id.'" class="espresso-notices '.$css_class.'" style="display:none;"><p>'.$error_messages.'</p>'.$close.'</div>';
866 866
 			}
867 867
 
868 868
 			$notices .= '</div>';
@@ -875,7 +875,7 @@  discard block
 block discarded – undo
875 875
 					'errors' => $error_messages
876 876
 			);
877 877
 
878
-			if ( $remove_empty ) {
878
+			if ($remove_empty) {
879 879
 				// remove empty notices
880 880
 				foreach ($notices as $type => $notice) {
881 881
 					if (empty($notice)) {
@@ -885,7 +885,7 @@  discard block
 block discarded – undo
885 885
 			}
886 886
 		}
887 887
 
888
-		if ( $print_scripts ) {
888
+		if ($print_scripts) {
889 889
 			self::_print_scripts();
890 890
 		}
891 891
 
@@ -905,17 +905,17 @@  discard block
 block discarded – undo
905 905
 	* 	@param bool $force_update allows one to enforce the reappearance of a persistent message.
906 906
 	* 	@return 		void
907 907
 	*/
908
-	public static function add_persistent_admin_notice( $pan_name = '', $pan_message, $force_update = FALSE ) {
909
-		if ( ! empty( $pan_name ) && ! empty( $pan_message )) {
910
-			$persistent_admin_notices = get_option( 'ee_pers_admin_notices', array() );
908
+	public static function add_persistent_admin_notice($pan_name = '', $pan_message, $force_update = FALSE) {
909
+		if ( ! empty($pan_name) && ! empty($pan_message)) {
910
+			$persistent_admin_notices = get_option('ee_pers_admin_notices', array());
911 911
 			//maybe initialize persistent_admin_notices
912
-			if ( empty( $persistent_admin_notices )) {
913
-				add_option( 'ee_pers_admin_notices', array(), '', 'no' );
912
+			if (empty($persistent_admin_notices)) {
913
+				add_option('ee_pers_admin_notices', array(), '', 'no');
914 914
 			}
915
-			$pan_name = sanitize_key( $pan_name );
916
-			if ( ! array_key_exists( $pan_name, $persistent_admin_notices ) || $force_update ) {
917
-				$persistent_admin_notices[ $pan_name ] = $pan_message;
918
-				update_option( 'ee_pers_admin_notices', $persistent_admin_notices );
915
+			$pan_name = sanitize_key($pan_name);
916
+			if ( ! array_key_exists($pan_name, $persistent_admin_notices) || $force_update) {
917
+				$persistent_admin_notices[$pan_name] = $pan_message;
918
+				update_option('ee_pers_admin_notices', $persistent_admin_notices);
919 919
 			}
920 920
 		}
921 921
 	}
@@ -931,34 +931,34 @@  discard block
 block discarded – undo
931 931
 	 * @param bool          $return_immediately
932 932
 	 * @return        void
933 933
 	 */
934
-	public static function dismiss_persistent_admin_notice( $pan_name = '', $purge = FALSE, $return_immediately = FALSE ) {
935
-		$pan_name = EE_Registry::instance()->REQ->is_set( 'ee_nag_notice' ) ? EE_Registry::instance()->REQ->get( 'ee_nag_notice' ) : $pan_name;
936
-		if ( ! empty( $pan_name )) {
937
-			$persistent_admin_notices = get_option( 'ee_pers_admin_notices', array() );
934
+	public static function dismiss_persistent_admin_notice($pan_name = '', $purge = FALSE, $return_immediately = FALSE) {
935
+		$pan_name = EE_Registry::instance()->REQ->is_set('ee_nag_notice') ? EE_Registry::instance()->REQ->get('ee_nag_notice') : $pan_name;
936
+		if ( ! empty($pan_name)) {
937
+			$persistent_admin_notices = get_option('ee_pers_admin_notices', array());
938 938
 			// check if notice we wish to dismiss is actually in the $persistent_admin_notices array
939
-			if ( is_array( $persistent_admin_notices ) && isset( $persistent_admin_notices[ $pan_name ] )) {
939
+			if (is_array($persistent_admin_notices) && isset($persistent_admin_notices[$pan_name])) {
940 940
 				// completely delete nag notice, or just NULL message so that it can NOT be added again ?
941
-				if ( $purge ) {
942
-					unset( $persistent_admin_notices[ $pan_name ] );
941
+				if ($purge) {
942
+					unset($persistent_admin_notices[$pan_name]);
943 943
 				} else {
944
-					$persistent_admin_notices[ $pan_name ] = NULL;
944
+					$persistent_admin_notices[$pan_name] = NULL;
945 945
 				}
946
-				if ( update_option( 'ee_pers_admin_notices', $persistent_admin_notices ) === FALSE ) {
947
-					EE_Error::add_error( sprintf( __( 'The persistent admin notice for "%s" could not be deleted.', 'event_espresso' ), $pan_name ), __FILE__, __FUNCTION__, __LINE__ );
946
+				if (update_option('ee_pers_admin_notices', $persistent_admin_notices) === FALSE) {
947
+					EE_Error::add_error(sprintf(__('The persistent admin notice for "%s" could not be deleted.', 'event_espresso'), $pan_name), __FILE__, __FUNCTION__, __LINE__);
948 948
 				}
949 949
 			}
950 950
 		}
951
-		if ( $return_immediately ) {
951
+		if ($return_immediately) {
952 952
 			return;
953
-		} else if ( EE_Registry::instance()->REQ->ajax ) {
953
+		} else if (EE_Registry::instance()->REQ->ajax) {
954 954
 			// grab any notices and concatenate into string
955
-			echo wp_json_encode( array( 'errors' => implode( '<br />', EE_Error::get_notices( FALSE ))));
955
+			echo wp_json_encode(array('errors' => implode('<br />', EE_Error::get_notices(FALSE))));
956 956
 			exit();
957 957
 		} else {
958 958
 			// save errors to a transient to be displayed on next request (after redirect)
959
-			EE_Error::get_notices( FALSE, TRUE );
960
-			$return_url = EE_Registry::instance()->REQ->is_set( 'return_url' ) ? EE_Registry::instance()->REQ->get( 'return_url' ) : '';
961
-			wp_safe_redirect( urldecode( $return_url ));
959
+			EE_Error::get_notices(FALSE, TRUE);
960
+			$return_url = EE_Registry::instance()->REQ->is_set('return_url') ? EE_Registry::instance()->REQ->get('return_url') : '';
961
+			wp_safe_redirect(urldecode($return_url));
962 962
 		}
963 963
 	}
964 964
 
@@ -973,20 +973,20 @@  discard block
 block discarded – undo
973 973
 	 * @param  string $return_url  URL to go back to after nag notice is dismissed
974 974
 	 * @return string
975 975
 	 */
976
-	public static function display_persistent_admin_notices( $pan_name = '', $pan_message = '', $return_url = '' ) {
977
-		if ( ! empty( $pan_name ) && ! empty( $pan_message )) {
976
+	public static function display_persistent_admin_notices($pan_name = '', $pan_message = '', $return_url = '') {
977
+		if ( ! empty($pan_name) && ! empty($pan_message)) {
978 978
 			$args = array(
979 979
 				'nag_notice' => $pan_name,
980
-				'return_url' => urlencode( $return_url ),
980
+				'return_url' => urlencode($return_url),
981 981
 				'ajax_url' => WP_AJAX_URL,
982
-				'unknown_error' => __( 'An unknown error has occurred on the server while attempting to dismiss this notice.', 'event_espresso' )
982
+				'unknown_error' => __('An unknown error has occurred on the server while attempting to dismiss this notice.', 'event_espresso')
983 983
 			);
984
-			wp_localize_script( 'espresso_core', 'ee_dismiss', $args );
984
+			wp_localize_script('espresso_core', 'ee_dismiss', $args);
985 985
 			return '
986
-			<div id="' . $pan_name . '" class="espresso-notices updated ee-nag-notice clearfix" style="border-left: 4px solid #fcb93c;">
987
-				<p>' . $pan_message . '</p>
988
-				<a class="dismiss-ee-nag-notice hide-if-no-js" style="float: right; cursor: pointer; text-decoration:none;" rel="' . $pan_name . '">
989
-					<span class="dashicons dashicons-dismiss" style="position:relative; top:-1px; margin-right:.25em;"></span>'.__( 'Dismiss', 'event_espresso' ) .'
986
+			<div id="' . $pan_name.'" class="espresso-notices updated ee-nag-notice clearfix" style="border-left: 4px solid #fcb93c;">
987
+				<p>' . $pan_message.'</p>
988
+				<a class="dismiss-ee-nag-notice hide-if-no-js" style="float: right; cursor: pointer; text-decoration:none;" rel="' . $pan_name.'">
989
+					<span class="dashicons dashicons-dismiss" style="position:relative; top:-1px; margin-right:.25em;"></span>'.__('Dismiss', 'event_espresso').'
990 990
 				</a>
991 991
 				<div style="clear:both;"></div>
992 992
 			</div>';
@@ -1003,24 +1003,24 @@  discard block
 block discarded – undo
1003 1003
 	 * @param string $return_url
1004 1004
 	 * @return    array
1005 1005
 	 */
1006
-	public static function get_persistent_admin_notices( $return_url = '' ) {
1006
+	public static function get_persistent_admin_notices($return_url = '') {
1007 1007
 		$notices = '';
1008 1008
 		// check for persistent admin notices
1009 1009
 		//filter the list though so plugins can notify the admin in a different way if they want
1010 1010
 		$persistent_admin_notices = apply_filters(
1011 1011
 			'FHEE__EE_Error__get_persistent_admin_notices',
1012
-			get_option( 'ee_pers_admin_notices', FALSE ),
1012
+			get_option('ee_pers_admin_notices', FALSE),
1013 1013
 			'ee_pers_admin_notices',
1014 1014
 			$return_url
1015 1015
 		);
1016
-		if ( $persistent_admin_notices ) {
1016
+		if ($persistent_admin_notices) {
1017 1017
 			// load scripts
1018
-			wp_register_script( 'espresso_core', EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js', array('jquery'), EVENT_ESPRESSO_VERSION, TRUE );
1019
-			wp_register_script( 'ee_error_js', EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js', array('espresso_core'), EVENT_ESPRESSO_VERSION, TRUE );
1020
-			wp_enqueue_script( 'ee_error_js' );
1018
+			wp_register_script('espresso_core', EE_GLOBAL_ASSETS_URL.'scripts/espresso_core.js', array('jquery'), EVENT_ESPRESSO_VERSION, TRUE);
1019
+			wp_register_script('ee_error_js', EE_GLOBAL_ASSETS_URL.'scripts/EE_Error.js', array('espresso_core'), EVENT_ESPRESSO_VERSION, TRUE);
1020
+			wp_enqueue_script('ee_error_js');
1021 1021
 			// and display notices
1022
-			foreach( $persistent_admin_notices as $pan_name => $pan_message ) {
1023
-				$notices .= self::display_persistent_admin_notices( $pan_name, $pan_message, $return_url );
1022
+			foreach ($persistent_admin_notices as $pan_name => $pan_message) {
1023
+				$notices .= self::display_persistent_admin_notices($pan_name, $pan_message, $return_url);
1024 1024
 			}
1025 1025
 		}
1026 1026
 		return $notices;
@@ -1035,26 +1035,26 @@  discard block
 block discarded – undo
1035 1035
 	 * @param 	bool $force_print
1036 1036
 	 * @return 	void
1037 1037
 	 */
1038
-	private static function _print_scripts( $force_print = FALSE ) {
1039
-		if (( did_action( 'admin_enqueue_scripts' ) || did_action( 'wp_enqueue_scripts' )) && ! $force_print ) {
1040
-			if ( wp_script_is( 'ee_error_js', 'enqueued' )) {
1038
+	private static function _print_scripts($force_print = FALSE) {
1039
+		if ((did_action('admin_enqueue_scripts') || did_action('wp_enqueue_scripts')) && ! $force_print) {
1040
+			if (wp_script_is('ee_error_js', 'enqueued')) {
1041 1041
 				return;
1042
-			} else if ( wp_script_is( 'ee_error_js', 'registered' )) {
1043
-				add_filter( 'FHEE_load_css', '__return_true' );
1044
-				add_filter( 'FHEE_load_js', '__return_true' );
1045
-				wp_enqueue_script( 'ee_error_js' );
1046
-				wp_localize_script( 'ee_error_js','ee_settings', array( 'wp_debug'=>WP_DEBUG ));
1042
+			} else if (wp_script_is('ee_error_js', 'registered')) {
1043
+				add_filter('FHEE_load_css', '__return_true');
1044
+				add_filter('FHEE_load_js', '__return_true');
1045
+				wp_enqueue_script('ee_error_js');
1046
+				wp_localize_script('ee_error_js', 'ee_settings', array('wp_debug'=>WP_DEBUG));
1047 1047
 			}
1048 1048
 		} else {
1049 1049
 			return '
1050 1050
 <script>
1051 1051
 /* <![CDATA[ */
1052
-var ee_settings = {"wp_debug":"' . WP_DEBUG . '"};
1052
+var ee_settings = {"wp_debug":"' . WP_DEBUG.'"};
1053 1053
 /* ]]> */
1054 1054
 </script>
1055
-<script src="' . includes_url() . 'js/jquery/jquery.js" type="text/javascript"></script>
1056
-<script src="' . EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js' . '?ver=' . espresso_version() . '" type="text/javascript"></script>
1057
-<script src="' . EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js' . '?ver=' . espresso_version() . '" type="text/javascript"></script>
1055
+<script src="' . includes_url().'js/jquery/jquery.js" type="text/javascript"></script>
1056
+<script src="' . EE_GLOBAL_ASSETS_URL.'scripts/espresso_core.js'.'?ver='.espresso_version().'" type="text/javascript"></script>
1057
+<script src="' . EE_GLOBAL_ASSETS_URL.'scripts/EE_Error.js'.'?ver='.espresso_version().'" type="text/javascript"></script>
1058 1058
 ';
1059 1059
 
1060 1060
 		}
@@ -1088,11 +1088,11 @@  discard block
 block discarded – undo
1088 1088
 	*	@param string $line
1089 1089
 	*	@return string
1090 1090
 	*/
1091
-	public static function generate_error_code ( $file = '', $func = '', $line = '' ) {
1092
-		$file = explode( '.', basename( $file ));
1093
-		$error_code = ! empty( $file[0] ) ? $file[0] : '';
1094
-		$error_code .= ! empty( $func ) ? ' - ' . $func : '';
1095
-		$error_code .= ! empty( $line ) ? ' - ' . $line : '';
1091
+	public static function generate_error_code($file = '', $func = '', $line = '') {
1092
+		$file = explode('.', basename($file));
1093
+		$error_code = ! empty($file[0]) ? $file[0] : '';
1094
+		$error_code .= ! empty($func) ? ' - '.$func : '';
1095
+		$error_code .= ! empty($line) ? ' - '.$line : '';
1096 1096
 		return $error_code;
1097 1097
 	}
1098 1098
 
@@ -1108,36 +1108,36 @@  discard block
 block discarded – undo
1108 1108
 	*	@ param object $ex
1109 1109
 	*	@ return void
1110 1110
 	*/
1111
-	public function write_to_error_log ( $time = FALSE, $ex = FALSE, $clear = FALSE ) {
1111
+	public function write_to_error_log($time = FALSE, $ex = FALSE, $clear = FALSE) {
1112 1112
 
1113
-		if ( ! $ex ) {
1113
+		if ( ! $ex) {
1114 1114
 			return;
1115 1115
 		}
1116 1116
 
1117
-		if ( ! $time ) {
1117
+		if ( ! $time) {
1118 1118
 			$time = time();
1119 1119
 		}
1120 1120
 
1121
-		$exception_log = '----------------------------------------------------------------------------------------' . PHP_EOL;
1122
-		$exception_log .= '[' . date( 'Y-m-d H:i:s', $time ) . ']  Exception Details' . PHP_EOL;
1123
-		$exception_log .= 'Message: ' . $ex['msg'] . PHP_EOL;
1124
-		$exception_log .= 'Code: '. $ex['code'] . PHP_EOL;
1125
-		$exception_log .= 'File: '. $ex['file'] . PHP_EOL;
1126
-		$exception_log .= 'Line No: ' . $ex['line'] . PHP_EOL;
1127
-		$exception_log .= 'Stack trace: ' . PHP_EOL;
1128
-		$exception_log .= $ex['string'] . PHP_EOL;
1129
-		$exception_log .= '----------------------------------------------------------------------------------------' . PHP_EOL;
1121
+		$exception_log = '----------------------------------------------------------------------------------------'.PHP_EOL;
1122
+		$exception_log .= '['.date('Y-m-d H:i:s', $time).']  Exception Details'.PHP_EOL;
1123
+		$exception_log .= 'Message: '.$ex['msg'].PHP_EOL;
1124
+		$exception_log .= 'Code: '.$ex['code'].PHP_EOL;
1125
+		$exception_log .= 'File: '.$ex['file'].PHP_EOL;
1126
+		$exception_log .= 'Line No: '.$ex['line'].PHP_EOL;
1127
+		$exception_log .= 'Stack trace: '.PHP_EOL;
1128
+		$exception_log .= $ex['string'].PHP_EOL;
1129
+		$exception_log .= '----------------------------------------------------------------------------------------'.PHP_EOL;
1130 1130
 
1131 1131
 		try {
1132
-			EEH_File::ensure_file_exists_and_is_writable( EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . self::$_exception_log_file );
1133
-			EEH_File::add_htaccess_deny_from_all( EVENT_ESPRESSO_UPLOAD_DIR . 'logs' );
1134
-			if ( ! $clear ) {
1132
+			EEH_File::ensure_file_exists_and_is_writable(EVENT_ESPRESSO_UPLOAD_DIR.'logs'.DS.self::$_exception_log_file);
1133
+			EEH_File::add_htaccess_deny_from_all(EVENT_ESPRESSO_UPLOAD_DIR.'logs');
1134
+			if ( ! $clear) {
1135 1135
 				//get existing log file and append new log info
1136
-				$exception_log = EEH_File::get_file_contents( EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . self::$_exception_log_file ) . $exception_log;
1136
+				$exception_log = EEH_File::get_file_contents(EVENT_ESPRESSO_UPLOAD_DIR.'logs'.DS.self::$_exception_log_file).$exception_log;
1137 1137
 			}
1138
-			EEH_File::write_to_file( EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . self::$_exception_log_file, $exception_log );
1139
-		} catch( EE_Error $e ){
1140
-			EE_Error::add_error( sprintf( __(  'Event Espresso error logging could not be setup because: %s', 'event_espresso' ), $e->getMessage() ));
1138
+			EEH_File::write_to_file(EVENT_ESPRESSO_UPLOAD_DIR.'logs'.DS.self::$_exception_log_file, $exception_log);
1139
+		} catch (EE_Error $e) {
1140
+			EE_Error::add_error(sprintf(__('Event Espresso error logging could not be setup because: %s', 'event_espresso'), $e->getMessage()));
1141 1141
 			return;
1142 1142
 		}
1143 1143
 
@@ -1173,8 +1173,8 @@  discard block
 block discarded – undo
1173 1173
 		$applies_when = '',
1174 1174
 		$error_type = null
1175 1175
 	) {
1176
-		if ( defined('WP_DEBUG') && WP_DEBUG ) {
1177
-			EEH_Debug_Tools::instance()->doing_it_wrong( $function, $message, $version, $applies_when, $error_type );
1176
+		if (defined('WP_DEBUG') && WP_DEBUG) {
1177
+			EEH_Debug_Tools::instance()->doing_it_wrong($function, $message, $version, $applies_when, $error_type);
1178 1178
 		}
1179 1179
 	}
1180 1180
 
@@ -1208,13 +1208,13 @@  discard block
 block discarded – undo
1208 1208
  */
1209 1209
 function espresso_error_enqueue_scripts() {
1210 1210
 	// js for error handling
1211
-	wp_register_script( 'espresso_core', EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js', array('jquery'), EVENT_ESPRESSO_VERSION, FALSE );
1212
-	wp_register_script( 'ee_error_js', EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js', array('espresso_core'), EVENT_ESPRESSO_VERSION, FALSE );
1211
+	wp_register_script('espresso_core', EE_GLOBAL_ASSETS_URL.'scripts/espresso_core.js', array('jquery'), EVENT_ESPRESSO_VERSION, FALSE);
1212
+	wp_register_script('ee_error_js', EE_GLOBAL_ASSETS_URL.'scripts/EE_Error.js', array('espresso_core'), EVENT_ESPRESSO_VERSION, FALSE);
1213 1213
 }
1214
-if ( is_admin() ) {
1215
-	add_action( 'admin_enqueue_scripts', 'espresso_error_enqueue_scripts', 2 );
1214
+if (is_admin()) {
1215
+	add_action('admin_enqueue_scripts', 'espresso_error_enqueue_scripts', 2);
1216 1216
 } else {
1217
-	add_action( 'wp_enqueue_scripts', 'espresso_error_enqueue_scripts', 2 );
1217
+	add_action('wp_enqueue_scripts', 'espresso_error_enqueue_scripts', 2);
1218 1218
 }
1219 1219
 
1220 1220
 
Please login to merge, or discard this patch.
core/EE_Psr4AutoloaderInit.core.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -24,15 +24,15 @@
 block discarded – undo
24 24
 	 */
25 25
 	public function __construct() {
26 26
 		static $initialized = false;
27
-		if ( ! $initialized ) {
27
+		if ( ! $initialized) {
28 28
 			// instantiate PSR4 autoloader
29
-			espresso_load_required( 'Psr4Autoloader', EE_CORE . 'Psr4Autoloader.php' );
29
+			espresso_load_required('Psr4Autoloader', EE_CORE.'Psr4Autoloader.php');
30 30
 			EE_Psr4AutoloaderInit::$psr4_loader = new \EventEspresso\core\Psr4Autoloader();
31 31
 			// register the autoloader
32 32
 			EE_Psr4AutoloaderInit::$psr4_loader->register();
33 33
 			// register the base directories for the namespace prefix
34
-			EE_Psr4AutoloaderInit::$psr4_loader->addNamespace( 'EventEspresso', EE_PLUGIN_DIR_PATH );
35
-			EE_Psr4AutoloaderInit::$psr4_loader->addNamespace( 'EventEspressoBatchRequest', EE_LIBRARIES . 'batch' );
34
+			EE_Psr4AutoloaderInit::$psr4_loader->addNamespace('EventEspresso', EE_PLUGIN_DIR_PATH);
35
+			EE_Psr4AutoloaderInit::$psr4_loader->addNamespace('EventEspressoBatchRequest', EE_LIBRARIES.'batch');
36 36
 			$initialized = true;
37 37
 		}
38 38
 	}
Please login to merge, or discard this patch.
espresso.php 2 patches
Spacing   +48 added lines, -48 removed lines patch added patch discarded remove patch
@@ -129,54 +129,54 @@  discard block
 block discarded – undo
129 129
         define('EE_PLUGIN_DIR_PATH', plugin_dir_path(EVENT_ESPRESSO_MAIN_FILE));
130 130
         define('EE_PLUGIN_DIR_URL', plugin_dir_url(EVENT_ESPRESSO_MAIN_FILE));
131 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);
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 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);
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 153
         // gateways
154
-        define('EE_GATEWAYS', EE_MODULES . 'gateways' . DS);
155
-        define('EE_GATEWAYS_URL', EE_PLUGIN_DIR_URL . 'modules' . DS . 'gateways' . DS);
154
+        define('EE_GATEWAYS', EE_MODULES.'gateways'.DS);
155
+        define('EE_GATEWAYS_URL', EE_PLUGIN_DIR_URL.'modules'.DS.'gateways'.DS);
156 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/');
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 163
         // define upload paths
164 164
         $uploads = wp_upload_dir();
165 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);
166
+        define('EVENT_ESPRESSO_UPLOAD_DIR', $uploads['basedir'].DS.'espresso'.DS);
167
+        define('EVENT_ESPRESSO_UPLOAD_URL', $uploads['baseurl'].DS.'espresso'.DS);
168 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);
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 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);
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 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);
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 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);
178
+        if (file_exists(EVENT_ESPRESSO_UPLOAD_DIR.'fonts'.DS)) {
179
+            define('DOMPDF_FONT_DIR', EVENT_ESPRESSO_UPLOAD_DIR.'fonts'.DS);
180 180
         }
181 181
         //ajax constants
182 182
         define(
@@ -191,7 +191,7 @@  discard block
 block discarded – undo
191 191
         //you're better to use this than its straight value (currently -1) in case you ever
192 192
         //want to change its default value! or find when -1 means infinity
193 193
         define('EE_INF_IN_DB', -1);
194
-        define('EE_INF', INF > (float)PHP_INT_MAX ? INF : PHP_INT_MAX);
194
+        define('EE_INF', INF > (float) PHP_INT_MAX ? INF : PHP_INT_MAX);
195 195
         define('EE_DEBUG', false);
196 196
         // for older WP versions
197 197
         if ( ! defined('MONTH_IN_SECONDS')) {
@@ -214,13 +214,13 @@  discard block
 block discarded – undo
214 214
         function espresso_load_error_handling()
215 215
         {
216 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');
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 219
                 EEH_Debug_Tools::instance();
220 220
             }
221 221
             // load error handling
222
-            if (is_readable(EE_CORE . 'EE_Error.core.php')) {
223
-                require_once(EE_CORE . 'EE_Error.core.php');
222
+            if (is_readable(EE_CORE.'EE_Error.core.php')) {
223
+                require_once(EE_CORE.'EE_Error.core.php');
224 224
             } else {
225 225
                 wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso'));
226 226
             }
@@ -244,7 +244,7 @@  discard block
 block discarded – undo
244 244
             if (is_readable($full_path_to_file)) {
245 245
                 require_once($full_path_to_file);
246 246
             } else {
247
-                throw new EE_Error (
247
+                throw new EE_Error(
248 248
                         sprintf(
249 249
                                 esc_html__(
250 250
                                         'The %s class file could not be located or is not readable due to file permissions.',
@@ -256,9 +256,9 @@  discard block
 block discarded – undo
256 256
             }
257 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');
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 262
         new EE_Bootstrap();
263 263
     }
264 264
 }
@@ -274,7 +274,7 @@  discard block
 block discarded – undo
274 274
     function espresso_deactivate_plugin($plugin_basename = '')
275 275
     {
276 276
         if ( ! function_exists('deactivate_plugins')) {
277
-            require_once(ABSPATH . 'wp-admin/includes/plugin.php');
277
+            require_once(ABSPATH.'wp-admin/includes/plugin.php');
278 278
         }
279 279
         unset($_GET['activate'], $_REQUEST['activate']);
280 280
         deactivate_plugins($plugin_basename);
Please login to merge, or discard this 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.37.rc.002');
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.37.rc.002');
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.
core/interfaces/EEI_Interfaces.php 3 patches
Doc Comments   +113 added lines, -5 removed lines patch added patch discarded remove patch
@@ -60,7 +60,7 @@  discard block
 block discarded – undo
60 60
 	 * You can specify $default is case you haven't found the extra meta
61 61
 	 * @param string $meta_key
62 62
 	 * @param boolean $single
63
-	 * @param mixed $default if we don't find anything, what should we return?
63
+	 * @param boolean $default if we don't find anything, what should we return?
64 64
 	 * @return mixed single value if $single; array if ! $single
65 65
 	 */
66 66
 	public function get_extra_meta($meta_key,$single = FALSE,$default = NULL);
@@ -72,9 +72,7 @@  discard block
 block discarded – undo
72 72
      * The $extra_cache_ref will be passed to the model field's prepare_for_pretty_echoing, so consult the field's class
73 73
      * to see what options are available.
74 74
      * @param string $field_name
75
-     * @param string $format This allows the user to specify an extra cache ref for the given property
76
-     *                                (in cases where the same property may be used for different outputs
77
-     *                                - i.e. datetime, money etc.)
75
+     * @param string|null $extra_cache_ref
78 76
      * @return mixed
79 77
      * @throws \EE_Error
80 78
      */
@@ -120,6 +118,7 @@  discard block
 block discarded – undo
120 118
 	 *
121 119
 	 * @param EE_Request $request
122 120
 	 * @param EE_Response $response
121
+	 * @return void
123 122
 	 */
124 123
 	public function handle_response( EE_Request $request, EE_Response $response );
125 124
 }
@@ -203,26 +202,78 @@  discard block
 block discarded – undo
203 202
  * Interface EEI_Attendee
204 203
  */
205 204
 interface EEI_Attendee {
205
+
206
+	/**
207
+	 * @return string
208
+	 */
206 209
 	public function fname();
210
+
211
+	/**
212
+	 * @return string
213
+	 */
207 214
 	public function lname();
215
+
216
+    /**
217
+     * @return string
218
+     */
208 219
     public function full_name();
220
+
221
+	/**
222
+	 * @return string
223
+	 */
209 224
 	public function email();
225
+
226
+	/**
227
+	 * @return string
228
+	 */
210 229
 	public function phone();
230
+
231
+	/**
232
+	 * @return string
233
+	 */
211 234
 	public function address();
235
+
236
+	/**
237
+	 * @return string
238
+	 */
212 239
 	public function address2();
240
+
241
+	/**
242
+	 * @return string
243
+	 */
213 244
 	public function city();
245
+
246
+	/**
247
+	 * @return string
248
+	 */
214 249
 	public function state_ID();
250
+
251
+	/**
252
+	 * @return string
253
+	 */
215 254
 	public function state_name();
216 255
 	/**
217 256
 	 * @return EE_State
218 257
 	 */
219 258
 	public function state_obj();
259
+
260
+	/**
261
+	 * @return string
262
+	 */
220 263
 	public function country_ID();
264
+
265
+	/**
266
+	 * @return string
267
+	 */
221 268
 	public function country_name();
222 269
 	/**
223 270
 	 * @return EE_Country
224 271
 	 */
225 272
 	public function country_obj();
273
+
274
+	/**
275
+	 * @return string
276
+	 */
226 277
 	public function zip();
227 278
 }
228 279
 
@@ -234,9 +285,25 @@  discard block
 block discarded – undo
234 285
  * Interface EEI_Contact
235 286
  */
236 287
 interface EEI_Contact {
288
+
289
+	/**
290
+	 * @return string
291
+	 */
237 292
 	public function fname();
293
+
294
+	/**
295
+	 * @return string
296
+	 */
238 297
 	public function lname();
298
+
299
+	/**
300
+	 * @return string
301
+	 */
239 302
 	public function email();
303
+
304
+	/**
305
+	 * @return string
306
+	 */
240 307
 	public function phone();
241 308
 }
242 309
 
@@ -263,24 +330,64 @@  discard block
 block discarded – undo
263 330
  * Interface EEI_Address
264 331
  */
265 332
 interface EEI_Address {
333
+
334
+	/**
335
+	 * @return string
336
+	 */
266 337
 	public function address();
338
+
339
+	/**
340
+	 * @return string
341
+	 */
267 342
 	public function address2();
343
+
344
+	/**
345
+	 * @return string
346
+	 */
268 347
 	public function city();
269 348
 	/**
270 349
 	 * @return EE_State
271 350
 	 */
272 351
 	public function state_obj();
273 352
 	public function state_ID();
353
+
354
+	/**
355
+	 * @return string
356
+	 */
274 357
 	public function state_name();
358
+
359
+	/**
360
+	 * @return string
361
+	 */
275 362
 	public function state_abbrev();
363
+
364
+	/**
365
+	 * @return string
366
+	 */
276 367
 	public function state();
277 368
 	/**
278 369
 	 * @return EE_Country
279 370
 	 */
280 371
 	public function country_obj();
372
+
373
+	/**
374
+	 * @return string
375
+	 */
281 376
 	public function country_ID();
377
+
378
+	/**
379
+	 * @return string
380
+	 */
282 381
 	public function country_name();
382
+
383
+	/**
384
+	 * @return string
385
+	 */
283 386
 	public function country();
387
+
388
+	/**
389
+	 * @return string
390
+	 */
284 391
 	public function zip();
285 392
 }
286 393
 
@@ -301,6 +408,7 @@  discard block
 block discarded – undo
301 408
 	 * @param string $zip
302 409
 	 * @param string $country
303 410
 	 * @param string $CNT_ISO
411
+	 * @return string|null
304 412
 	 */
305 413
 	public function format( $address, $address2, $city, $state, $zip, $country, $CNT_ISO );
306 414
 }
@@ -413,7 +521,7 @@  discard block
 block discarded – undo
413 521
 	/**
414 522
 	 * @param EE_Line_Item $line_item
415 523
 	 * @param array $options
416
-	 * @return mixed
524
+	 * @return string
417 525
 	 */
418 526
 	public function display_line_item( EE_Line_Item $line_item, $options = array() );
419 527
 
Please login to merge, or discard this patch.
Spacing   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -5,7 +5,7 @@  discard block
 block discarded – undo
5 5
 /**
6 6
  * Interface EEI_Base
7 7
  */
8
-interface EEI_Base{
8
+interface EEI_Base {
9 9
 	/**
10 10
 	 * gets the unique ID of the model object. If it hasn't been saved yet
11 11
 	 * to the database, this should be 0 or NULL
@@ -32,7 +32,7 @@  discard block
 block discarded – undo
32 32
 	 * @return int records updated (or BOOLEAN if we actually ended up inserting the extra meta row)
33 33
 	 * NOTE: if the values haven't changed, returns 0
34 34
 	 */
35
-	public function update_extra_meta($meta_key,$meta_value,$previous_value = NULL);
35
+	public function update_extra_meta($meta_key, $meta_value, $previous_value = NULL);
36 36
 
37 37
 	/**
38 38
 	 * Adds a new extra meta record. If $unique is set to TRUE, we'll first double-check
@@ -43,7 +43,7 @@  discard block
 block discarded – undo
43 43
 	 * @param boolean $unique
44 44
 	 * @return boolean
45 45
 	 */
46
-	public function add_extra_meta($meta_key,$meta_value,$unique = false);
46
+	public function add_extra_meta($meta_key, $meta_value, $unique = false);
47 47
 
48 48
 	/**
49 49
 	 * Deletes all the extra meta rows for this record as specified by key. If $meta_value
@@ -52,7 +52,7 @@  discard block
 block discarded – undo
52 52
 	 * @param string $meta_value
53 53
 	 * @return int number of extra meta rows deleted
54 54
 	 */
55
-	public function delete_extra_meta($meta_key,$meta_value = NULL);
55
+	public function delete_extra_meta($meta_key, $meta_value = NULL);
56 56
 
57 57
 	/**
58 58
 	 * Gets the extra meta with the given meta key. If you specify "single" we just return 1, otherwise
@@ -63,7 +63,7 @@  discard block
 block discarded – undo
63 63
 	 * @param mixed $default if we don't find anything, what should we return?
64 64
 	 * @return mixed single value if $single; array if ! $single
65 65
 	 */
66
-	public function get_extra_meta($meta_key,$single = FALSE,$default = NULL);
66
+	public function get_extra_meta($meta_key, $single = FALSE, $default = NULL);
67 67
 
68 68
 
69 69
 
@@ -105,7 +105,7 @@  discard block
 block discarded – undo
105 105
 	 * @param 	EE_Response $response
106 106
 	 * @return 	EE_Response
107 107
 	 */
108
-	public function handle_request( EE_Request $request, EE_Response $response );
108
+	public function handle_request(EE_Request $request, EE_Response $response);
109 109
 }
110 110
 
111 111
 
@@ -121,7 +121,7 @@  discard block
 block discarded – undo
121 121
 	 * @param EE_Request $request
122 122
 	 * @param EE_Response $response
123 123
 	 */
124
-	public function handle_response( EE_Request $request, EE_Response $response );
124
+	public function handle_response(EE_Request $request, EE_Response $response);
125 125
 }
126 126
 
127 127
 
@@ -302,7 +302,7 @@  discard block
 block discarded – undo
302 302
 	 * @param string $country
303 303
 	 * @param string $CNT_ISO
304 304
 	 */
305
-	public function format( $address, $address2, $city, $state, $zip, $country, $CNT_ISO );
305
+	public function format($address, $address2, $city, $state, $zip, $country, $CNT_ISO);
306 306
 }
307 307
 
308 308
 
@@ -312,13 +312,13 @@  discard block
 block discarded – undo
312 312
 /**
313 313
  * Interface EEHI_Line_Item
314 314
  */
315
-interface EEHI_Line_Item{
315
+interface EEHI_Line_Item {
316 316
 	/**
317 317
 	 * Adds an item to the purchase in the right spot
318 318
 	 * @param EE_Line_Item $total_line_item
319 319
 	 * @param EE_Line_Item $line_item
320 320
 	 */
321
-	public function add_item( EE_Line_Item $total_line_item, EE_Line_Item $line_item );
321
+	public function add_item(EE_Line_Item $total_line_item, EE_Line_Item $line_item);
322 322
 	/**
323 323
 	 * Overwrites the previous tax by clearing out the old taxes, and creates a new
324 324
 	 * tax and updates the total line item accordingly
@@ -332,7 +332,7 @@  discard block
 block discarded – undo
332 332
          *  set the taxes to match $amount
333 333
 	 * @return EE_Line_Item the new tax created
334 334
 	 */
335
-	public function set_total_tax_to( EE_Line_Item $total_line_item, $amount, $name  = NULL, $description = NULL, $code = NULL, $add_to_existing_line_item = false );
335
+	public function set_total_tax_to(EE_Line_Item $total_line_item, $amount, $name = NULL, $description = NULL, $code = NULL, $add_to_existing_line_item = false);
336 336
 
337 337
          /**
338 338
          * Makes all the line items which are children of $line_item taxable (or not).
@@ -342,7 +342,7 @@  discard block
 block discarded – undo
342 342
          * @param string $code_substring_for_whitelist if this string is part of the line item's code
343 343
          *  it will be whitelisted (ie, except from becoming taxable)
344 344
          */
345
-        public static function set_line_items_taxable( EE_Line_Item $line_item, $taxable = true, $code_substring_for_whitelist = null );
345
+        public static function set_line_items_taxable(EE_Line_Item $line_item, $taxable = true, $code_substring_for_whitelist = null);
346 346
 
347 347
 	/**
348 348
 	 * Adds a simple item ( unrelated to any other model object) to the total line item,
@@ -356,21 +356,21 @@  discard block
 block discarded – undo
356 356
 	 * @param boolean $code if set to a value, ensures there is only one line item with that code
357 357
 	 * @return boolean success
358 358
 	 */
359
-	public function add_unrelated_item( EE_Line_Item $total_line_item, $name, $unit_price, $description = '', $quantity = 1, $taxable = FALSE, $code = null );
359
+	public function add_unrelated_item(EE_Line_Item $total_line_item, $name, $unit_price, $description = '', $quantity = 1, $taxable = FALSE, $code = null);
360 360
 
361 361
 	/**
362 362
 	 * Gets the line item for the taxes subtotal
363 363
 	 * @param EE_Line_Item $total_line_item of type EEM_Line_Item::type_total
364 364
 	 * @return \EE_Line_Item
365 365
 	 */
366
-	public static function get_taxes_subtotal( EE_Line_Item $total_line_item );
366
+	public static function get_taxes_subtotal(EE_Line_Item $total_line_item);
367 367
 }
368 368
 
369 369
 
370 370
 /**
371 371
  * Money-related helper
372 372
  */
373
-interface EEHI_Money{
373
+interface EEHI_Money {
374 374
 		/**
375 375
 	 * For comparing floats. Default operator is '=', but see the $operator below for all options.
376 376
 	 * This should be used to compare floats instead of normal '==' because floats
@@ -381,13 +381,13 @@  discard block
 block discarded – undo
381 381
 	 * @param string $operator  The operator. Valid options are =, <=, <, >=, >, <>, eq, lt, lte, gt, gte, ne
382 382
 	 * @return boolean whether the equation is true or false
383 383
 	 */
384
-	public function compare_floats( $float1, $float2, $operator='=' );
384
+	public function compare_floats($float1, $float2, $operator = '=');
385 385
 }
386 386
 
387 387
 /**
388 388
  * Interface EEHI_Template
389 389
  */
390
-interface EEHI_Template{
390
+interface EEHI_Template {
391 391
 
392 392
 	/**
393 393
 	 * EEH_Template::format_currency
@@ -400,7 +400,7 @@  discard block
 block discarded – undo
400 400
 	 * @param string   $cur_code_span_class
401 401
 	 * @return string the html output for the formatted money value
402 402
 	 */
403
-	public static function format_currency( $amount = NULL, $return_raw = FALSE, $display_code = TRUE, $CNT_ISO = '', $cur_code_span_class = 'currency-code' );
403
+	public static function format_currency($amount = NULL, $return_raw = FALSE, $display_code = TRUE, $CNT_ISO = '', $cur_code_span_class = 'currency-code');
404 404
 }
405 405
 
406 406
 
@@ -415,7 +415,7 @@  discard block
 block discarded – undo
415 415
 	 * @param array $options
416 416
 	 * @return mixed
417 417
 	 */
418
-	public function display_line_item( EE_Line_Item $line_item, $options = array() );
418
+	public function display_line_item(EE_Line_Item $line_item, $options = array());
419 419
 
420 420
 }
421 421
 
@@ -432,7 +432,7 @@  discard block
 block discarded – undo
432 432
 	 * @throws EE_Error
433 433
 	 * @return bool
434 434
 	 */
435
-	public static function ensure_file_exists_and_is_writable( $full_file_path = '' );
435
+	public static function ensure_file_exists_and_is_writable($full_file_path = '');
436 436
 
437 437
 	/**
438 438
 	 * ensure_folder_exists_and_is_writable
@@ -441,7 +441,7 @@  discard block
 block discarded – undo
441 441
 	 * @throws EE_Error
442 442
 	 * @return bool
443 443
 	 */
444
-	public static function ensure_folder_exists_and_is_writable( $folder = '' );
444
+	public static function ensure_folder_exists_and_is_writable($folder = '');
445 445
 }
446 446
 
447 447
 // End of file EEI_Interfaces.php
Please login to merge, or discard this patch.
Indentation   +40 added lines, -40 removed lines patch added patch discarded remove patch
@@ -67,18 +67,18 @@  discard block
 block discarded – undo
67 67
 
68 68
 
69 69
 
70
-    /**
71
-     * Gets a pretty view of the field's value. $extra_cache_ref can specify different formats for this.
72
-     * The $extra_cache_ref will be passed to the model field's prepare_for_pretty_echoing, so consult the field's class
73
-     * to see what options are available.
74
-     * @param string $field_name
75
-     * @param string $format This allows the user to specify an extra cache ref for the given property
76
-     *                                (in cases where the same property may be used for different outputs
77
-     *                                - i.e. datetime, money etc.)
78
-     * @return mixed
79
-     * @throws \EE_Error
80
-     */
81
-    public function get_pretty($field_name, $extra_cache_ref);
70
+	/**
71
+	 * Gets a pretty view of the field's value. $extra_cache_ref can specify different formats for this.
72
+	 * The $extra_cache_ref will be passed to the model field's prepare_for_pretty_echoing, so consult the field's class
73
+	 * to see what options are available.
74
+	 * @param string $field_name
75
+	 * @param string $format This allows the user to specify an extra cache ref for the given property
76
+	 *                                (in cases where the same property may be used for different outputs
77
+	 *                                - i.e. datetime, money etc.)
78
+	 * @return mixed
79
+	 * @throws \EE_Error
80
+	 */
81
+	public function get_pretty($field_name, $extra_cache_ref);
82 82
 }
83 83
 
84 84
 
@@ -168,11 +168,11 @@  discard block
 block discarded – undo
168 168
 
169 169
 
170 170
 
171
-    /**
172
-     * Retrieves all the pending payments on this transaction
173
-     * @return EEI_Payment[]
174
-     */
175
-    public function pending_payments();
171
+	/**
172
+	 * Retrieves all the pending payments on this transaction
173
+	 * @return EEI_Payment[]
174
+	 */
175
+	public function pending_payments();
176 176
 }
177 177
 
178 178
 
@@ -213,7 +213,7 @@  discard block
 block discarded – undo
213 213
 interface EEI_Attendee {
214 214
 	public function fname();
215 215
 	public function lname();
216
-    public function full_name();
216
+	public function full_name();
217 217
 	public function email();
218 218
 	public function phone();
219 219
 	public function address();
@@ -334,23 +334,23 @@  discard block
 block discarded – undo
334 334
 	 * @param float $amount
335 335
 	 * @param string $name
336 336
 	 * @param string $description
337
-         * @param string $code
338
-         * @param boolean $add_to_existing_line_item if true and a duplicate line item with
339
-         *  the same code is found, $amount will be added onto it; otherwise will simply
340
-         *  set the taxes to match $amount
337
+	 * @param string $code
338
+	 * @param boolean $add_to_existing_line_item if true and a duplicate line item with
339
+	 *  the same code is found, $amount will be added onto it; otherwise will simply
340
+	 *  set the taxes to match $amount
341 341
 	 * @return EE_Line_Item the new tax created
342 342
 	 */
343 343
 	public function set_total_tax_to( EE_Line_Item $total_line_item, $amount, $name  = NULL, $description = NULL, $code = NULL, $add_to_existing_line_item = false );
344 344
 
345
-         /**
346
-         * Makes all the line items which are children of $line_item taxable (or not).
347
-         * Does NOT save the line items
348
-         * @param EE_Line_Item $line_item
349
-         * @param boolean $taxable
350
-         * @param string $code_substring_for_whitelist if this string is part of the line item's code
351
-         *  it will be whitelisted (ie, except from becoming taxable)
352
-         */
353
-        public static function set_line_items_taxable( EE_Line_Item $line_item, $taxable = true, $code_substring_for_whitelist = null );
345
+		 /**
346
+		  * Makes all the line items which are children of $line_item taxable (or not).
347
+		  * Does NOT save the line items
348
+		  * @param EE_Line_Item $line_item
349
+		  * @param boolean $taxable
350
+		  * @param string $code_substring_for_whitelist if this string is part of the line item's code
351
+		  *  it will be whitelisted (ie, except from becoming taxable)
352
+		  */
353
+		public static function set_line_items_taxable( EE_Line_Item $line_item, $taxable = true, $code_substring_for_whitelist = null );
354 354
 
355 355
 	/**
356 356
 	 * Adds a simple item ( unrelated to any other model object) to the total line item,
@@ -380,15 +380,15 @@  discard block
 block discarded – undo
380 380
  */
381 381
 interface EEHI_Money{
382 382
 		/**
383
-	 * For comparing floats. Default operator is '=', but see the $operator below for all options.
384
-	 * This should be used to compare floats instead of normal '==' because floats
385
-	 * are inherently imprecise, and so you can sometimes have two floats that appear to be identical
386
-	 * but actually differ by 0.00000001.
387
-	 * @param float $float1
388
-	 * @param float $float2
389
-	 * @param string $operator  The operator. Valid options are =, <=, <, >=, >, <>, eq, lt, lte, gt, gte, ne
390
-	 * @return boolean whether the equation is true or false
391
-	 */
383
+		 * For comparing floats. Default operator is '=', but see the $operator below for all options.
384
+		 * This should be used to compare floats instead of normal '==' because floats
385
+		 * are inherently imprecise, and so you can sometimes have two floats that appear to be identical
386
+		 * but actually differ by 0.00000001.
387
+		 * @param float $float1
388
+		 * @param float $float2
389
+		 * @param string $operator  The operator. Valid options are =, <=, <, >=, >, <>, eq, lt, lte, gt, gte, ne
390
+		 * @return boolean whether the equation is true or false
391
+		 */
392 392
 	public function compare_floats( $float1, $float2, $operator='=' );
393 393
 }
394 394
 
Please login to merge, or discard this patch.
core/libraries/payment_methods/EE_Gateway.lib.php 1 patch
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -369,7 +369,7 @@  discard block
 block discarded – undo
369 369
 	/**
370 370
 	 * Gets the first event for this payment (it's possible that it could be for multiple)
371 371
 	 * @param EEI_Payment $payment
372
-	 * @return EEI_Event|null
372
+	 * @return EE_Event|null
373 373
      * @deprecated since 4.9.31 instead use EEI_Payment::get_first_event()
374 374
 	 */
375 375
 	protected function _get_first_event_for_payment( EEI_Payment $payment ) {
@@ -430,7 +430,7 @@  discard block
 block discarded – undo
430 430
 	 * Gets the order description that should generlly be sent to gateways
431 431
      * @deprecated since 4.9.31 instead use $this->_get_gateway_formatter()->formatOrderDescription($payment)
432 432
 	 * @param EEI_Payment $payment
433
-	 * @return type
433
+	 * @return string
434 434
 	 */
435 435
 	protected function _format_order_description( EEI_Payment $payment ) {
436 436
 		return $this->_get_gateway_formatter()->formatOrderDescription($payment);
Please login to merge, or discard this patch.