Completed
Branch FET-10416-autoload-b4-bootstra... (9a39f6)
by
unknown
119:38 queued 108:09
created
modules/ticket_selector/EED_Ticket_Selector.module.php 2 patches
Indentation   +266 added lines, -266 removed lines patch added patch discarded remove patch
@@ -22,15 +22,15 @@  discard block
 block discarded – undo
22 22
  */
23 23
 class EED_Ticket_Selector extends  EED_Module {
24 24
 
25
-    /**
26
-     * @var EventEspresso\modules\ticket_selector\DisplayTicketSelector $ticket_selector
27
-     */
28
-    private static $ticket_selector;
25
+	/**
26
+	 * @var EventEspresso\modules\ticket_selector\DisplayTicketSelector $ticket_selector
27
+	 */
28
+	private static $ticket_selector;
29 29
 
30
-    /**
31
-     * @var EventEspresso\modules\ticket_selector\TicketSelectorIframeEmbedButton $iframe_embed_button
32
-     */
33
-    private static $iframe_embed_button;
30
+	/**
31
+	 * @var EventEspresso\modules\ticket_selector\TicketSelectorIframeEmbedButton $iframe_embed_button
32
+	 */
33
+	private static $iframe_embed_button;
34 34
 
35 35
 
36 36
 
@@ -61,13 +61,13 @@  discard block
 block discarded – undo
61 61
 		// routing
62 62
 		EE_Config::register_route( 'iframe', 'EED_Ticket_Selector', 'ticket_selector_iframe', 'ticket_selector' );
63 63
 		EE_Config::register_route( 'process_ticket_selections', 'EED_Ticket_Selector', 'process_ticket_selections' );
64
-        EE_Config::register_route('cancel_ticket_selections', 'EED_Ticket_Selector', 'cancel_ticket_selections');
65
-        add_action( 'wp_loaded', array( 'EED_Ticket_Selector', 'set_definitions' ), 2 );
64
+		EE_Config::register_route('cancel_ticket_selections', 'EED_Ticket_Selector', 'cancel_ticket_selections');
65
+		add_action( 'wp_loaded', array( 'EED_Ticket_Selector', 'set_definitions' ), 2 );
66 66
 		add_action( 'AHEE_event_details_header_bottom', array( 'EED_Ticket_Selector', 'display_ticket_selector' ), 10, 1 );
67
-        add_action( 'wp_enqueue_scripts', array( 'EED_Ticket_Selector', 'translate_js_strings' ), 0 );
68
-        add_action( 'wp_enqueue_scripts', array( 'EED_Ticket_Selector', 'load_tckt_slctr_assets' ), 10 );
69
-        EED_Ticket_Selector::loadIframeAssets();
70
-    }
67
+		add_action( 'wp_enqueue_scripts', array( 'EED_Ticket_Selector', 'translate_js_strings' ), 0 );
68
+		add_action( 'wp_enqueue_scripts', array( 'EED_Ticket_Selector', 'load_tckt_slctr_assets' ), 10 );
69
+		EED_Ticket_Selector::loadIframeAssets();
70
+	}
71 71
 
72 72
 
73 73
 
@@ -86,16 +86,16 @@  discard block
 block discarded – undo
86 86
 			10
87 87
 		);
88 88
 
89
-        /**
90
-         * Make sure assets for the ticket selector are loaded on the espresso registrations route so  admin side
91
-         * registrations work.
92
-         */
89
+		/**
90
+		 * Make sure assets for the ticket selector are loaded on the espresso registrations route so  admin side
91
+		 * registrations work.
92
+		 */
93 93
 		add_action(
94
-		    'FHEE__EE_Admin_Page___load_page_dependencies__after_load__espresso_registrations__new_registration',
95
-            array('EED_Ticket_Selector', 'set_definitions'),
96
-            10
97
-        );
98
-    }
94
+			'FHEE__EE_Admin_Page___load_page_dependencies__after_load__espresso_registrations__new_registration',
95
+			array('EED_Ticket_Selector', 'set_definitions'),
96
+			10
97
+		);
98
+	}
99 99
 
100 100
 
101 101
 
@@ -106,34 +106,34 @@  discard block
 block discarded – undo
106 106
 	 *  @return 	void
107 107
 	 */
108 108
 	public static function set_definitions() {
109
-	    // don't do this twice
110
-	    if(defined('TICKET_SELECTOR_ASSETS_URL')) {
111
-	        return;
112
-        }
109
+		// don't do this twice
110
+		if(defined('TICKET_SELECTOR_ASSETS_URL')) {
111
+			return;
112
+		}
113 113
 		define( 'TICKET_SELECTOR_ASSETS_URL', plugin_dir_url( __FILE__ ) . 'assets' . DS );
114 114
 		define(
115
-		    'TICKET_SELECTOR_TEMPLATES_PATH',
116
-            str_replace( '\\', DS, plugin_dir_path( __FILE__ )) . 'templates' . DS
117
-        );
115
+			'TICKET_SELECTOR_TEMPLATES_PATH',
116
+			str_replace( '\\', DS, plugin_dir_path( __FILE__ )) . 'templates' . DS
117
+		);
118 118
 		//if config is not set, initialize
119 119
 		if ( ! EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector instanceof EE_Ticket_Selector_Config ) {
120
-            \EED_Ticket_Selector::instance()->set_config();
121
-            \EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector = \EED_Ticket_Selector::instance()->config();
120
+			\EED_Ticket_Selector::instance()->set_config();
121
+			\EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector = \EED_Ticket_Selector::instance()->config();
122 122
 		}
123 123
 	}
124 124
 
125 125
 
126 126
 
127 127
 	/**
128
-     * @return \EventEspresso\modules\ticket_selector\DisplayTicketSelector
129
-     */
130
-    public static function ticketSelector()
131
-    {
132
-        if ( ! EED_Ticket_Selector::$ticket_selector instanceof DisplayTicketSelector) {
133
-            EED_Ticket_Selector::$ticket_selector = new DisplayTicketSelector();
134
-        }
135
-        return EED_Ticket_Selector::$ticket_selector;
136
-    }
128
+	 * @return \EventEspresso\modules\ticket_selector\DisplayTicketSelector
129
+	 */
130
+	public static function ticketSelector()
131
+	{
132
+		if ( ! EED_Ticket_Selector::$ticket_selector instanceof DisplayTicketSelector) {
133
+			EED_Ticket_Selector::$ticket_selector = new DisplayTicketSelector();
134
+		}
135
+		return EED_Ticket_Selector::$ticket_selector;
136
+	}
137 137
 
138 138
 
139 139
 	/**
@@ -186,15 +186,15 @@  discard block
 block discarded – undo
186 186
 
187 187
 
188 188
 
189
-    /**
190
-     *    creates buttons for selecting number of attendees for an event
191
-     *
192
-     * @access    public
193
-     * @param    WP_Post|int $event
194
-     * @param    bool        $view_details
195
-     * @return    string
196
-     * @throws \EE_Error
197
-     */
189
+	/**
190
+	 *    creates buttons for selecting number of attendees for an event
191
+	 *
192
+	 * @access    public
193
+	 * @param    WP_Post|int $event
194
+	 * @param    bool        $view_details
195
+	 * @return    string
196
+	 * @throws \EE_Error
197
+	 */
198 198
 	public static function display_ticket_selector( $event = NULL, $view_details = FALSE ) {
199 199
 		return EED_Ticket_Selector::ticketSelector()->display( $event, $view_details );
200 200
 	}
@@ -215,244 +215,244 @@  discard block
 block discarded – undo
215 215
 
216 216
 
217 217
 
218
-    /**
219
-     * cancel_ticket_selections
220
-     *
221
-     * @access        public
222
-     * @return        string
223
-     */
224
-    public static function cancel_ticket_selections()
225
-    {
226
-        $form = new ProcessTicketSelector();
227
-        return $form->cancelTicketSelections();
228
-    }
218
+	/**
219
+	 * cancel_ticket_selections
220
+	 *
221
+	 * @access        public
222
+	 * @return        string
223
+	 */
224
+	public static function cancel_ticket_selections()
225
+	{
226
+		$form = new ProcessTicketSelector();
227
+		return $form->cancelTicketSelections();
228
+	}
229 229
 
230 230
 
231 231
 
232 232
 	/**
233
-	* @return void
234
-	*/
233
+	 * @return void
234
+	 */
235 235
 	public static function translate_js_strings() {
236
-        EE_Registry::$i18n_js_strings['please_select_date_filter_notice'] = esc_html__(
237
-            'please select a datetime', 'event_espresso'
238
-        );
239
-    }
236
+		EE_Registry::$i18n_js_strings['please_select_date_filter_notice'] = esc_html__(
237
+			'please select a datetime', 'event_espresso'
238
+		);
239
+	}
240 240
 
241 241
 
242 242
 
243 243
 	/**
244
-	* 	load js
245
-	*
246
-	* 	@access 		public
247
-	* 	@return 		void
248
-	*/
244
+	 * 	load js
245
+	 *
246
+	 * 	@access 		public
247
+	 * 	@return 		void
248
+	 */
249 249
 	public static function load_tckt_slctr_assets() {
250 250
 		if ( apply_filters( 'FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', FALSE ) ) {
251
-            // add some style
252
-            wp_register_style(
253
-                'ticket_selector',
254
-                TICKET_SELECTOR_ASSETS_URL . 'ticket_selector.css',
255
-                array(),
256
-                EVENT_ESPRESSO_VERSION
257
-            );
258
-            wp_enqueue_style('ticket_selector');
259
-            // make it dance
260
-            wp_register_script(
261
-                'ticket_selector',
262
-                TICKET_SELECTOR_ASSETS_URL . 'ticket_selector.js',
263
-                array('espresso_core'),
264
-                EVENT_ESPRESSO_VERSION,
265
-                TRUE
266
-            );
251
+			// add some style
252
+			wp_register_style(
253
+				'ticket_selector',
254
+				TICKET_SELECTOR_ASSETS_URL . 'ticket_selector.css',
255
+				array(),
256
+				EVENT_ESPRESSO_VERSION
257
+			);
258
+			wp_enqueue_style('ticket_selector');
259
+			// make it dance
260
+			wp_register_script(
261
+				'ticket_selector',
262
+				TICKET_SELECTOR_ASSETS_URL . 'ticket_selector.js',
263
+				array('espresso_core'),
264
+				EVENT_ESPRESSO_VERSION,
265
+				TRUE
266
+			);
267 267
 			wp_enqueue_script('ticket_selector');
268
-            require_once( EE_LIBRARIES.'form_sections/strategies/display/EE_Checkbox_Dropdown_Selector_Display_Strategy.strategy.php');
269
-            \EE_Checkbox_Dropdown_Selector_Display_Strategy::enqueue_styles_and_scripts();
270
-        }
268
+			require_once( EE_LIBRARIES.'form_sections/strategies/display/EE_Checkbox_Dropdown_Selector_Display_Strategy.strategy.php');
269
+			\EE_Checkbox_Dropdown_Selector_Display_Strategy::enqueue_styles_and_scripts();
270
+		}
271
+	}
272
+
273
+
274
+
275
+	/**
276
+	 * @return void
277
+	 */
278
+	public static function loadIframeAssets()
279
+	{
280
+		// for event lists
281
+		add_filter(
282
+			'FHEE__EventEspresso_modules_events_archive_EventsArchiveIframe__display__css',
283
+			array('EED_Ticket_Selector', 'iframeCss')
284
+		);
285
+		add_filter(
286
+			'FHEE__EventEspresso_modules_events_archive_EventsArchiveIframe__display__js',
287
+			array('EED_Ticket_Selector', 'iframeJs')
288
+		);
289
+		// for ticket selectors
290
+		add_filter(
291
+			'FHEE__EED_Ticket_Selector__ticket_selector_iframe__css',
292
+			array('EED_Ticket_Selector', 'iframeCss')
293
+		);
294
+		add_filter(
295
+			'FHEE__EED_Ticket_Selector__ticket_selector_iframe__js',
296
+			array('EED_Ticket_Selector', 'iframeJs')
297
+		);
298
+	}
299
+
300
+
301
+
302
+	/**
303
+	 * Informs the rest of the forms system what CSS and JS is needed to display the input
304
+	 *
305
+	 * @param array $iframe_css
306
+	 * @return array
307
+	 */
308
+	public static function iframeCss(array $iframe_css)
309
+	{
310
+		$iframe_css['ticket_selector'] = TICKET_SELECTOR_ASSETS_URL . 'ticket_selector.css';
311
+		return $iframe_css;
271 312
 	}
272 313
 
273 314
 
274 315
 
275
-    /**
276
-     * @return void
277
-     */
278
-    public static function loadIframeAssets()
279
-    {
280
-        // for event lists
281
-        add_filter(
282
-            'FHEE__EventEspresso_modules_events_archive_EventsArchiveIframe__display__css',
283
-            array('EED_Ticket_Selector', 'iframeCss')
284
-        );
285
-        add_filter(
286
-            'FHEE__EventEspresso_modules_events_archive_EventsArchiveIframe__display__js',
287
-            array('EED_Ticket_Selector', 'iframeJs')
288
-        );
289
-        // for ticket selectors
290
-        add_filter(
291
-            'FHEE__EED_Ticket_Selector__ticket_selector_iframe__css',
292
-            array('EED_Ticket_Selector', 'iframeCss')
293
-        );
294
-        add_filter(
295
-            'FHEE__EED_Ticket_Selector__ticket_selector_iframe__js',
296
-            array('EED_Ticket_Selector', 'iframeJs')
297
-        );
298
-    }
299
-
300
-
301
-
302
-    /**
303
-     * Informs the rest of the forms system what CSS and JS is needed to display the input
304
-     *
305
-     * @param array $iframe_css
306
-     * @return array
307
-     */
308
-    public static function iframeCss(array $iframe_css)
309
-    {
310
-        $iframe_css['ticket_selector'] = TICKET_SELECTOR_ASSETS_URL . 'ticket_selector.css';
311
-        return $iframe_css;
312
-    }
313
-
314
-
315
-
316
-    /**
317
-     * Informs the rest of the forms system what CSS and JS is needed to display the input
318
-     *
319
-     * @param array $iframe_js
320
-     * @return array
321
-     */
322
-    public static function iframeJs(array $iframe_js)
323
-    {
324
-        $iframe_js['ticket_selector'] = TICKET_SELECTOR_ASSETS_URL . 'ticket_selector.js';
325
-        return $iframe_js;
326
-    }
316
+	/**
317
+	 * Informs the rest of the forms system what CSS and JS is needed to display the input
318
+	 *
319
+	 * @param array $iframe_js
320
+	 * @return array
321
+	 */
322
+	public static function iframeJs(array $iframe_js)
323
+	{
324
+		$iframe_js['ticket_selector'] = TICKET_SELECTOR_ASSETS_URL . 'ticket_selector.js';
325
+		return $iframe_js;
326
+	}
327 327
 
328 328
 
329 329
 	/****************************** DEPRECATED ******************************/
330 330
 
331 331
 
332 332
 
333
-    /**
334
-     * @deprecated
335
-     * @return string
336
-     * @throws \EE_Error
337
-     */
338
-    public static function display_view_details_btn()
339
-    {
340
-        // todo add doing_it_wrong() notice during next major version
341
-        return EED_Ticket_Selector::ticketSelector()->displayViewDetailsButton();
342
-    }
343
-
344
-
345
-
346
-    /**
347
-     * @deprecated
348
-     * @return string
349
-     * @throws \EE_Error
350
-     */
351
-    public static function display_ticket_selector_submit()
352
-    {
353
-        // todo add doing_it_wrong() notice during next major version
354
-        return EED_Ticket_Selector::ticketSelector()->displaySubmitButton();
355
-    }
356
-
357
-
358
-
359
-    /**
360
-     * @deprecated
361
-     * @param string $permalink_string
362
-     * @param int    $id
363
-     * @param string $new_title
364
-     * @param string $new_slug
365
-     * @return string
366
-     */
367
-    public static function iframe_code_button($permalink_string, $id, $new_title = '', $new_slug = '')
368
-    {
369
-        // todo add doing_it_wrong() notice during next major version
370
-        if (
371
-        	\EE_Registry::instance()->REQ->get('page') === 'espresso_events'
372
-        	&& \EE_Registry::instance()->REQ->get('action') === 'edit'
373
-        ) {
374
-            $iframe_embed_button = \EED_Ticket_Selector::getIframeEmbedButton();
375
-            $iframe_embed_button->addEventEditorIframeEmbedButton();
376
-        }
377
-        return '';
378
-    }
379
-
380
-
381
-
382
-    /**
383
-     * @deprecated
384
-     * @param int    $ID
385
-     * @param string $external_url
386
-     * @return string
387
-     */
388
-    public static function ticket_selector_form_open($ID = 0, $external_url = '')
389
-    {
390
-        // todo add doing_it_wrong() notice during next major version
391
-        return EED_Ticket_Selector::ticketSelector()->formOpen($ID, $external_url);
392
-    }
393
-
394
-
395
-
396
-    /**
397
-     * @deprecated
398
-     * @return string
399
-     */
400
-    public static function ticket_selector_form_close()
401
-    {
402
-        // todo add doing_it_wrong() notice during next major version
403
-        return EED_Ticket_Selector::ticketSelector()->formClose();
404
-    }
405
-
406
-
407
-
408
-    /**
409
-     * @deprecated
410
-     * @return string
411
-     */
412
-    public static function no_tkt_slctr_end_dv()
413
-    {
414
-        // todo add doing_it_wrong() notice during next major version
415
-        return EED_Ticket_Selector::ticketSelector()->ticketSelectorEndDiv();
416
-    }
417
-
418
-
419
-
420
-    /**
421
-     * @deprecated 4.9.13
422
-     * @return string
423
-     */
424
-    public static function tkt_slctr_end_dv()
425
-    {
426
-        return EED_Ticket_Selector::ticketSelector()->clearTicketSelector();
427
-    }
428
-
429
-
430
-
431
-    /**
432
-     * @deprecated
433
-     * @return string
434
-     */
435
-    public static function clear_tkt_slctr()
436
-    {
437
-        return EED_Ticket_Selector::ticketSelector()->clearTicketSelector();
438
-    }
439
-
440
-
441
-
442
-    /**
443
-     * @deprecated
444
-     */
445
-    public static function load_tckt_slctr_assets_admin()
446
-    {
447
-        // todo add doing_it_wrong() notice during next major version
448
-	    if (
449
-		    \EE_Registry::instance()->REQ->get( 'page' ) === 'espresso_events'
450
-		    && \EE_Registry::instance()->REQ->get( 'action' ) === 'edit'
451
-	    ) {
452
-		    $iframe_embed_button = \EED_Ticket_Selector::getIframeEmbedButton();
453
-            $iframe_embed_button->embedButtonAssets();
454
-        }
455
-    }
333
+	/**
334
+	 * @deprecated
335
+	 * @return string
336
+	 * @throws \EE_Error
337
+	 */
338
+	public static function display_view_details_btn()
339
+	{
340
+		// todo add doing_it_wrong() notice during next major version
341
+		return EED_Ticket_Selector::ticketSelector()->displayViewDetailsButton();
342
+	}
343
+
344
+
345
+
346
+	/**
347
+	 * @deprecated
348
+	 * @return string
349
+	 * @throws \EE_Error
350
+	 */
351
+	public static function display_ticket_selector_submit()
352
+	{
353
+		// todo add doing_it_wrong() notice during next major version
354
+		return EED_Ticket_Selector::ticketSelector()->displaySubmitButton();
355
+	}
356
+
357
+
358
+
359
+	/**
360
+	 * @deprecated
361
+	 * @param string $permalink_string
362
+	 * @param int    $id
363
+	 * @param string $new_title
364
+	 * @param string $new_slug
365
+	 * @return string
366
+	 */
367
+	public static function iframe_code_button($permalink_string, $id, $new_title = '', $new_slug = '')
368
+	{
369
+		// todo add doing_it_wrong() notice during next major version
370
+		if (
371
+			\EE_Registry::instance()->REQ->get('page') === 'espresso_events'
372
+			&& \EE_Registry::instance()->REQ->get('action') === 'edit'
373
+		) {
374
+			$iframe_embed_button = \EED_Ticket_Selector::getIframeEmbedButton();
375
+			$iframe_embed_button->addEventEditorIframeEmbedButton();
376
+		}
377
+		return '';
378
+	}
379
+
380
+
381
+
382
+	/**
383
+	 * @deprecated
384
+	 * @param int    $ID
385
+	 * @param string $external_url
386
+	 * @return string
387
+	 */
388
+	public static function ticket_selector_form_open($ID = 0, $external_url = '')
389
+	{
390
+		// todo add doing_it_wrong() notice during next major version
391
+		return EED_Ticket_Selector::ticketSelector()->formOpen($ID, $external_url);
392
+	}
393
+
394
+
395
+
396
+	/**
397
+	 * @deprecated
398
+	 * @return string
399
+	 */
400
+	public static function ticket_selector_form_close()
401
+	{
402
+		// todo add doing_it_wrong() notice during next major version
403
+		return EED_Ticket_Selector::ticketSelector()->formClose();
404
+	}
405
+
406
+
407
+
408
+	/**
409
+	 * @deprecated
410
+	 * @return string
411
+	 */
412
+	public static function no_tkt_slctr_end_dv()
413
+	{
414
+		// todo add doing_it_wrong() notice during next major version
415
+		return EED_Ticket_Selector::ticketSelector()->ticketSelectorEndDiv();
416
+	}
417
+
418
+
419
+
420
+	/**
421
+	 * @deprecated 4.9.13
422
+	 * @return string
423
+	 */
424
+	public static function tkt_slctr_end_dv()
425
+	{
426
+		return EED_Ticket_Selector::ticketSelector()->clearTicketSelector();
427
+	}
428
+
429
+
430
+
431
+	/**
432
+	 * @deprecated
433
+	 * @return string
434
+	 */
435
+	public static function clear_tkt_slctr()
436
+	{
437
+		return EED_Ticket_Selector::ticketSelector()->clearTicketSelector();
438
+	}
439
+
440
+
441
+
442
+	/**
443
+	 * @deprecated
444
+	 */
445
+	public static function load_tckt_slctr_assets_admin()
446
+	{
447
+		// todo add doing_it_wrong() notice during next major version
448
+		if (
449
+			\EE_Registry::instance()->REQ->get( 'page' ) === 'espresso_events'
450
+			&& \EE_Registry::instance()->REQ->get( 'action' ) === 'edit'
451
+		) {
452
+			$iframe_embed_button = \EED_Ticket_Selector::getIframeEmbedButton();
453
+			$iframe_embed_button->embedButtonAssets();
454
+		}
455
+	}
456 456
 
457 457
 
458 458
 }
Please login to merge, or discard this patch.
Spacing   +30 added lines, -30 removed lines patch added patch discarded remove patch
@@ -3,8 +3,8 @@  discard block
 block discarded – undo
3 3
 use EventEspresso\modules\ticket_selector\TicketSelectorIframe;
4 4
 use EventEspresso\modules\ticket_selector\TicketSelectorIframeEmbedButton;
5 5
 
6
-if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) {
7
-	exit( 'No direct script access allowed' );
6
+if ( ! defined('EVENT_ESPRESSO_VERSION')) {
7
+	exit('No direct script access allowed');
8 8
 }
9 9
 
10 10
 
@@ -38,15 +38,15 @@  discard block
 block discarded – undo
38 38
 	 * @return EED_Ticket_Selector
39 39
 	 */
40 40
 	public static function instance() {
41
-		return parent::get_instance( __CLASS__ );
41
+		return parent::get_instance(__CLASS__);
42 42
 	}
43 43
 
44 44
 
45 45
 
46
-	protected function set_config(){
47
-		$this->set_config_section( 'template_settings' );
48
-		$this->set_config_class( 'EE_Ticket_Selector_Config' );
49
-		$this->set_config_name( 'EED_Ticket_Selector' );
46
+	protected function set_config() {
47
+		$this->set_config_section('template_settings');
48
+		$this->set_config_class('EE_Ticket_Selector_Config');
49
+		$this->set_config_name('EED_Ticket_Selector');
50 50
 	}
51 51
 
52 52
 
@@ -59,13 +59,13 @@  discard block
 block discarded – undo
59 59
 	 */
60 60
 	public static function set_hooks() {
61 61
 		// routing
62
-		EE_Config::register_route( 'iframe', 'EED_Ticket_Selector', 'ticket_selector_iframe', 'ticket_selector' );
63
-		EE_Config::register_route( 'process_ticket_selections', 'EED_Ticket_Selector', 'process_ticket_selections' );
62
+		EE_Config::register_route('iframe', 'EED_Ticket_Selector', 'ticket_selector_iframe', 'ticket_selector');
63
+		EE_Config::register_route('process_ticket_selections', 'EED_Ticket_Selector', 'process_ticket_selections');
64 64
         EE_Config::register_route('cancel_ticket_selections', 'EED_Ticket_Selector', 'cancel_ticket_selections');
65
-        add_action( 'wp_loaded', array( 'EED_Ticket_Selector', 'set_definitions' ), 2 );
66
-		add_action( 'AHEE_event_details_header_bottom', array( 'EED_Ticket_Selector', 'display_ticket_selector' ), 10, 1 );
67
-        add_action( 'wp_enqueue_scripts', array( 'EED_Ticket_Selector', 'translate_js_strings' ), 0 );
68
-        add_action( 'wp_enqueue_scripts', array( 'EED_Ticket_Selector', 'load_tckt_slctr_assets' ), 10 );
65
+        add_action('wp_loaded', array('EED_Ticket_Selector', 'set_definitions'), 2);
66
+		add_action('AHEE_event_details_header_bottom', array('EED_Ticket_Selector', 'display_ticket_selector'), 10, 1);
67
+        add_action('wp_enqueue_scripts', array('EED_Ticket_Selector', 'translate_js_strings'), 0);
68
+        add_action('wp_enqueue_scripts', array('EED_Ticket_Selector', 'load_tckt_slctr_assets'), 10);
69 69
         EED_Ticket_Selector::loadIframeAssets();
70 70
     }
71 71
 
@@ -82,7 +82,7 @@  discard block
 block discarded – undo
82 82
 		// to load assets for "espresso_events" page on the "edit" route (action)
83 83
 		add_action(
84 84
 			'FHEE__EE_Admin_Page___load_page_dependencies__after_load__espresso_events__edit',
85
-			array( 'EED_Ticket_Selector', 'ticket_selector_iframe_embed_button' ),
85
+			array('EED_Ticket_Selector', 'ticket_selector_iframe_embed_button'),
86 86
 			10
87 87
 		);
88 88
 
@@ -107,16 +107,16 @@  discard block
 block discarded – undo
107 107
 	 */
108 108
 	public static function set_definitions() {
109 109
 	    // don't do this twice
110
-	    if(defined('TICKET_SELECTOR_ASSETS_URL')) {
110
+	    if (defined('TICKET_SELECTOR_ASSETS_URL')) {
111 111
 	        return;
112 112
         }
113
-		define( 'TICKET_SELECTOR_ASSETS_URL', plugin_dir_url( __FILE__ ) . 'assets' . DS );
113
+		define('TICKET_SELECTOR_ASSETS_URL', plugin_dir_url(__FILE__).'assets'.DS);
114 114
 		define(
115 115
 		    'TICKET_SELECTOR_TEMPLATES_PATH',
116
-            str_replace( '\\', DS, plugin_dir_path( __FILE__ )) . 'templates' . DS
116
+            str_replace('\\', DS, plugin_dir_path(__FILE__)).'templates'.DS
117 117
         );
118 118
 		//if config is not set, initialize
119
-		if ( ! EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector instanceof EE_Ticket_Selector_Config ) {
119
+		if ( ! EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector instanceof EE_Ticket_Selector_Config) {
120 120
             \EED_Ticket_Selector::instance()->set_config();
121 121
             \EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector = \EED_Ticket_Selector::instance()->config();
122 122
 		}
@@ -143,7 +143,7 @@  discard block
 block discarded – undo
143 143
 	 * 	@param	WP $WP
144 144
 	 * 	@return void
145 145
 	 */
146
-	public function run( $WP ) {}
146
+	public function run($WP) {}
147 147
 
148 148
 
149 149
 
@@ -151,7 +151,7 @@  discard block
 block discarded – undo
151 151
 	 * @return \EventEspresso\modules\ticket_selector\TicketSelectorIframeEmbedButton
152 152
 	 */
153 153
 	public static function getIframeEmbedButton() {
154
-		if ( ! self::$iframe_embed_button instanceof TicketSelectorIframeEmbedButton ) {
154
+		if ( ! self::$iframe_embed_button instanceof TicketSelectorIframeEmbedButton) {
155 155
 			self::$iframe_embed_button = new TicketSelectorIframeEmbedButton();
156 156
 		}
157 157
 		return self::$iframe_embed_button;
@@ -195,8 +195,8 @@  discard block
 block discarded – undo
195 195
      * @return    string
196 196
      * @throws \EE_Error
197 197
      */
198
-	public static function display_ticket_selector( $event = NULL, $view_details = FALSE ) {
199
-		return EED_Ticket_Selector::ticketSelector()->display( $event, $view_details );
198
+	public static function display_ticket_selector($event = NULL, $view_details = FALSE) {
199
+		return EED_Ticket_Selector::ticketSelector()->display($event, $view_details);
200 200
 	}
201 201
 
202 202
 
@@ -247,11 +247,11 @@  discard block
 block discarded – undo
247 247
 	* 	@return 		void
248 248
 	*/
249 249
 	public static function load_tckt_slctr_assets() {
250
-		if ( apply_filters( 'FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', FALSE ) ) {
250
+		if (apply_filters('FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', FALSE)) {
251 251
             // add some style
252 252
             wp_register_style(
253 253
                 'ticket_selector',
254
-                TICKET_SELECTOR_ASSETS_URL . 'ticket_selector.css',
254
+                TICKET_SELECTOR_ASSETS_URL.'ticket_selector.css',
255 255
                 array(),
256 256
                 EVENT_ESPRESSO_VERSION
257 257
             );
@@ -259,13 +259,13 @@  discard block
 block discarded – undo
259 259
             // make it dance
260 260
             wp_register_script(
261 261
                 'ticket_selector',
262
-                TICKET_SELECTOR_ASSETS_URL . 'ticket_selector.js',
262
+                TICKET_SELECTOR_ASSETS_URL.'ticket_selector.js',
263 263
                 array('espresso_core'),
264 264
                 EVENT_ESPRESSO_VERSION,
265 265
                 TRUE
266 266
             );
267 267
 			wp_enqueue_script('ticket_selector');
268
-            require_once( EE_LIBRARIES.'form_sections/strategies/display/EE_Checkbox_Dropdown_Selector_Display_Strategy.strategy.php');
268
+            require_once(EE_LIBRARIES.'form_sections/strategies/display/EE_Checkbox_Dropdown_Selector_Display_Strategy.strategy.php');
269 269
             \EE_Checkbox_Dropdown_Selector_Display_Strategy::enqueue_styles_and_scripts();
270 270
         }
271 271
 	}
@@ -307,7 +307,7 @@  discard block
 block discarded – undo
307 307
      */
308 308
     public static function iframeCss(array $iframe_css)
309 309
     {
310
-        $iframe_css['ticket_selector'] = TICKET_SELECTOR_ASSETS_URL . 'ticket_selector.css';
310
+        $iframe_css['ticket_selector'] = TICKET_SELECTOR_ASSETS_URL.'ticket_selector.css';
311 311
         return $iframe_css;
312 312
     }
313 313
 
@@ -321,7 +321,7 @@  discard block
 block discarded – undo
321 321
      */
322 322
     public static function iframeJs(array $iframe_js)
323 323
     {
324
-        $iframe_js['ticket_selector'] = TICKET_SELECTOR_ASSETS_URL . 'ticket_selector.js';
324
+        $iframe_js['ticket_selector'] = TICKET_SELECTOR_ASSETS_URL.'ticket_selector.js';
325 325
         return $iframe_js;
326 326
     }
327 327
 
@@ -446,8 +446,8 @@  discard block
 block discarded – undo
446 446
     {
447 447
         // todo add doing_it_wrong() notice during next major version
448 448
 	    if (
449
-		    \EE_Registry::instance()->REQ->get( 'page' ) === 'espresso_events'
450
-		    && \EE_Registry::instance()->REQ->get( 'action' ) === 'edit'
449
+		    \EE_Registry::instance()->REQ->get('page') === 'espresso_events'
450
+		    && \EE_Registry::instance()->REQ->get('action') === 'edit'
451 451
 	    ) {
452 452
 		    $iframe_embed_button = \EED_Ticket_Selector::getIframeEmbedButton();
453 453
             $iframe_embed_button->embedButtonAssets();
Please login to merge, or discard this patch.
core/libraries/messages/messenger/EE_Email_messenger.class.php 2 patches
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -55,7 +55,7 @@  discard block
 block discarded – undo
55 55
             'This messenger delivers messages via email using the built-in <code>wp_mail</code> function included with WordPress',
56 56
             'event_espresso'
57 57
         );
58
-        $this->label               = array(
58
+        $this->label = array(
59 59
             'singular' => esc_html__('email', 'event_espresso'),
60 60
             'plural'   => esc_html__('emails', 'event_espresso'),
61 61
         );
@@ -419,7 +419,7 @@  discard block
 block discarded – undo
419 419
             $this->_body(),
420 420
             $this->_headers()
421 421
         );
422
-        if (! $success) {
422
+        if ( ! $success) {
423 423
             EE_Error::add_error(
424 424
                 sprintf(
425 425
                     esc_html__(
@@ -464,13 +464,13 @@  discard block
 block discarded – undo
464 464
         $from    = stripslashes_deep(html_entity_decode($this->_from, ENT_QUOTES, "UTF-8"));
465 465
         $headers = array(
466 466
             'MIME-Version: 1.0',
467
-            'From:' . $from,
468
-            'Reply-To:' . $from,
467
+            'From:'.$from,
468
+            'Reply-To:'.$from,
469 469
             'Content-Type:text/html; charset=utf-8',
470 470
         );
471 471
 
472
-        if (! empty($this->_cc)) {
473
-            $headers[] = 'cc: ' . $this->_cc;
472
+        if ( ! empty($this->_cc)) {
473
+            $headers[] = 'cc: '.$this->_cc;
474 474
         }
475 475
 
476 476
         //but wait!  Header's for the from is NOT reliable because some plugins don't respect From: as set in the
@@ -580,7 +580,7 @@  discard block
 block discarded – undo
580 580
                 )
581 581
             ),
582 582
         );
583
-        $body                 = $this->_get_main_template($preview);
583
+        $body = $this->_get_main_template($preview);
584 584
 
585 585
         /**
586 586
          * This filter allows one to bypass the CSSToInlineStyles tool and leave the body untouched.
@@ -590,10 +590,10 @@  discard block
 block discarded – undo
590 590
          */
591 591
         if (apply_filters('FHEE__EE_Email_messenger__apply_CSSInliner ', true, $preview)) {
592 592
             //require CssToInlineStyles library and its dependencies via composer autoloader
593
-            require_once EE_THIRD_PARTY . 'cssinliner/vendor/autoload.php';
593
+            require_once EE_THIRD_PARTY.'cssinliner/vendor/autoload.php';
594 594
 
595 595
             //now if this isn't a preview, let's setup the body so it has inline styles
596
-            if (! $preview || ($preview && defined('DOING_AJAX'))) {
596
+            if ( ! $preview || ($preview && defined('DOING_AJAX'))) {
597 597
                 $style = file_get_contents(
598 598
                     $this->get_variation(
599 599
                         $this->_tmp_pack,
Please login to merge, or discard this patch.
Indentation   +639 added lines, -639 removed lines patch added patch discarded remove patch
@@ -8,643 +8,643 @@
 block discarded – undo
8 8
 class EE_Email_messenger extends EE_messenger
9 9
 {
10 10
 
11
-    /**
12
-     * To field for email
13
-     * @var string
14
-     */
15
-    protected $_to = '';
16
-
17
-
18
-    /**
19
-     * CC field for email.
20
-     * @var string
21
-     */
22
-    protected $_cc = '';
23
-
24
-    /**
25
-     * From field for email
26
-     * @var string
27
-     */
28
-    protected $_from = '';
29
-
30
-
31
-    /**
32
-     * Subject field for email
33
-     * @var string
34
-     */
35
-    protected $_subject = '';
36
-
37
-
38
-    /**
39
-     * Content field for email
40
-     * @var string
41
-     */
42
-    protected $_content = '';
43
-
44
-
45
-    /**
46
-     * constructor
47
-     *
48
-     * @access public
49
-     */
50
-    public function __construct()
51
-    {
52
-        //set name and description properties
53
-        $this->name                = 'email';
54
-        $this->description         = esc_html__(
55
-            'This messenger delivers messages via email using the built-in <code>wp_mail</code> function included with WordPress',
56
-            'event_espresso'
57
-        );
58
-        $this->label               = array(
59
-            'singular' => esc_html__('email', 'event_espresso'),
60
-            'plural'   => esc_html__('emails', 'event_espresso'),
61
-        );
62
-        $this->activate_on_install = true;
63
-
64
-        //we're using defaults so let's call parent constructor that will take care of setting up all the other
65
-        // properties
66
-        parent::__construct();
67
-    }
68
-
69
-
70
-    /**
71
-     * see abstract declaration in parent class for details.
72
-     */
73
-    protected function _set_admin_pages()
74
-    {
75
-        $this->admin_registered_pages = array(
76
-            'events_edit' => true,
77
-        );
78
-    }
79
-
80
-
81
-    /**
82
-     * see abstract declaration in parent class for details
83
-     */
84
-    protected function _set_valid_shortcodes()
85
-    {
86
-        //remember by leaving the other fields not set, those fields will inherit the valid shortcodes from the
87
-        // message type.
88
-        $this->_valid_shortcodes = array(
89
-            'to'   => array('email', 'event_author', 'primary_registration_details', 'recipient_details'),
90
-            'cc' => array('email', 'event_author', 'primary_registration_details', 'recipient_details'),
91
-            'from' => array('email', 'event_author', 'primary_registration_details', 'recipient_details'),
92
-        );
93
-    }
94
-
95
-
96
-    /**
97
-     * see abstract declaration in parent class for details
98
-     *
99
-     * @access protected
100
-     * @return void
101
-     */
102
-    protected function _set_validator_config()
103
-    {
104
-        $valid_shortcodes = $this->get_valid_shortcodes();
105
-
106
-        $this->_validator_config = array(
107
-            'to'            => array(
108
-                'shortcodes' => $valid_shortcodes['to'],
109
-                'type'       => 'email',
110
-            ),
111
-            'cc' => array(
112
-                'shortcodes' => $valid_shortcodes['to'],
113
-                'type' => 'email',
114
-            ),
115
-            'from'          => array(
116
-                'shortcodes' => $valid_shortcodes['from'],
117
-                'type'       => 'email',
118
-            ),
119
-            'subject'       => array(
120
-                'shortcodes' => array(
121
-                    'organization',
122
-                    'primary_registration_details',
123
-                    'event_author',
124
-                    'primary_registration_details',
125
-                    'recipient_details',
126
-                ),
127
-            ),
128
-            'content'       => array(
129
-                'shortcodes' => array(
130
-                    'event_list',
131
-                    'attendee_list',
132
-                    'ticket_list',
133
-                    'organization',
134
-                    'primary_registration_details',
135
-                    'primary_registration_list',
136
-                    'event_author',
137
-                    'recipient_details',
138
-                    'recipient_list',
139
-                    'transaction',
140
-                    'messenger',
141
-                ),
142
-            ),
143
-            'attendee_list' => array(
144
-                'shortcodes' => array('attendee', 'event_list', 'ticket_list'),
145
-                'required'   => array('[ATTENDEE_LIST]'),
146
-            ),
147
-            'event_list'    => array(
148
-                'shortcodes' => array(
149
-                    'event',
150
-                    'attendee_list',
151
-                    'ticket_list',
152
-                    'venue',
153
-                    'datetime_list',
154
-                    'attendee',
155
-                    'primary_registration_details',
156
-                    'primary_registration_list',
157
-                    'event_author',
158
-                    'recipient_details',
159
-                    'recipient_list',
160
-                ),
161
-                'required'   => array('[EVENT_LIST]'),
162
-            ),
163
-            'ticket_list'   => array(
164
-                'shortcodes' => array(
165
-                    'event_list',
166
-                    'attendee_list',
167
-                    'ticket',
168
-                    'datetime_list',
169
-                    'primary_registration_details',
170
-                    'recipient_details',
171
-                ),
172
-                'required'   => array('[TICKET_LIST]'),
173
-            ),
174
-            'datetime_list' => array(
175
-                'shortcodes' => array('datetime'),
176
-                'required'   => array('[DATETIME_LIST]'),
177
-            ),
178
-        );
179
-    }
180
-
181
-
182
-    /**
183
-     * @see   parent EE_messenger class for docs
184
-     * @since 4.5.0
185
-     */
186
-    public function do_secondary_messenger_hooks($sending_messenger_name)
187
-    {
188
-        if ($sending_messenger_name = 'html') {
189
-            add_filter('FHEE__EE_Messages_Template_Pack__get_variation', array($this, 'add_email_css'), 10, 8);
190
-        }
191
-    }
192
-
193
-
194
-    public function add_email_css(
195
-        $variation_path,
196
-        $messenger,
197
-        $message_type,
198
-        $type,
199
-        $variation,
200
-        $file_extension,
201
-        $url,
202
-        EE_Messages_Template_Pack $template_pack
203
-    ) {
204
-        //prevent recursion on this callback.
205
-        remove_filter('FHEE__EE_Messages_Template_Pack__get_variation', array($this, 'add_email_css'), 10);
206
-        $variation = $this->get_variation($template_pack, $message_type, $url, 'main', $variation, false);
207
-
208
-        add_filter('FHEE__EE_Messages_Template_Pack__get_variation', array($this, 'add_email_css'), 10, 8);
209
-        return $variation;
210
-    }
211
-
212
-
213
-    /**
214
-     * See parent for details
215
-     *
216
-     * @access protected
217
-     * @return void
218
-     */
219
-    protected function _set_test_settings_fields()
220
-    {
221
-        $this->_test_settings_fields = array(
222
-            'to'      => array(
223
-                'input'      => 'text',
224
-                'label'      => esc_html__('Send a test email to', 'event_espresso'),
225
-                'type'       => 'email',
226
-                'required'   => true,
227
-                'validation' => true,
228
-                'css_class'  => 'large-text',
229
-                'format'     => '%s',
230
-                'default'    => get_bloginfo('admin_email'),
231
-            ),
232
-            'subject' => array(
233
-                'input'      => 'hidden',
234
-                'label'      => '',
235
-                'type'       => 'string',
236
-                'required'   => false,
237
-                'validation' => false,
238
-                'format'     => '%s',
239
-                'value'      => sprintf(__('Test email sent from %s', 'event_espresso'), get_bloginfo('name')),
240
-                'default'    => '',
241
-                'css_class'  => '',
242
-            ),
243
-        );
244
-    }
245
-
246
-
247
-    /**
248
-     * _set_template_fields
249
-     * This sets up the fields that a messenger requires for the message to go out.
250
-     *
251
-     * @access  protected
252
-     * @return void
253
-     */
254
-    protected function _set_template_fields()
255
-    {
256
-        // any extra template fields that are NOT used by the messenger but will get used by a messenger field for
257
-        // shortcode replacement get added to the 'extra' key in an associated array indexed by the messenger field
258
-        // they relate to.  This is important for the Messages_admin to know what fields to display to the user.
259
-        //  Also, notice that the "values" are equal to the field type that messages admin will use to know what
260
-        // kind of field to display. The values ALSO have one index labeled "shortcode".  the values in that array
261
-        // indicate which ACTUAL SHORTCODE (i.e. [SHORTCODE]) is required in order for this extra field to be
262
-        // displayed.  If the required shortcode isn't part of the shortcodes array then the field is not needed and
263
-        // will not be displayed/parsed.
264
-        $this->_template_fields = array(
265
-            'to'      => array(
266
-                'input'      => 'text',
267
-                'label'      => esc_html_x(
268
-                    'To',
269
-                    'Label for the "To" field for email addresses',
270
-                    'event_espresso'
271
-                ),
272
-                'type'       => 'string',
273
-                'required'   => true,
274
-                'validation' => true,
275
-                'css_class'  => 'large-text',
276
-                'format'     => '%s',
277
-            ),
278
-            'cc'      => array(
279
-                'input'      => 'text',
280
-                'label'      => esc_html_x(
281
-                    'CC',
282
-                    'Label for the "Carbon Copy" field used for additional email addresses',
283
-                    'event_espresso'
284
-                ),
285
-                'type'       => 'string',
286
-                'required'   => false,
287
-                'validation' => true,
288
-                'css_class'  => 'large-text',
289
-                'format'     => '%s',
290
-            ),
291
-            'from'    => array(
292
-                'input'      => 'text',
293
-                'label'      => esc_html_x(
294
-                    'From',
295
-                    'Label for the "From" field for email addresses.',
296
-                    'event_espresso'
297
-                ),
298
-                'type'       => 'string',
299
-                'required'   => true,
300
-                'validation' => true,
301
-                'css_class'  => 'large-text',
302
-                'format'     => '%s',
303
-            ),
304
-            'subject' => array(
305
-                'input'      => 'text',
306
-                'label'      => esc_html_x(
307
-                    'Subject',
308
-                    'Label for the "Subject" field (short description of contents) for emails.',
309
-                    'event_espresso'
310
-                ),
311
-                'type'       => 'string',
312
-                'required'   => true,
313
-                'validation' => true,
314
-                'css_class'  => 'large-text',
315
-                'format'     => '%s',
316
-            ),
317
-            'content' => '',
318
-            //left empty b/c it is in the "extra array" but messenger still needs needs to know this is a field.
319
-            'extra'   => array(
320
-                'content' => array(
321
-                    'main'          => array(
322
-                        'input'      => 'wp_editor',
323
-                        'label'      => esc_html__('Main Content', 'event_espresso'),
324
-                        'type'       => 'string',
325
-                        'required'   => true,
326
-                        'validation' => true,
327
-                        'format'     => '%s',
328
-                        'rows'       => '15',
329
-                    ),
330
-                    'event_list'    => array(
331
-                        'input'               => 'wp_editor',
332
-                        'label'               => '[EVENT_LIST]',
333
-                        'type'                => 'string',
334
-                        'required'            => true,
335
-                        'validation'          => true,
336
-                        'format'              => '%s',
337
-                        'rows'                => '15',
338
-                        'shortcodes_required' => array('[EVENT_LIST]'),
339
-                    ),
340
-                    'attendee_list' => array(
341
-                        'input'               => 'textarea',
342
-                        'label'               => '[ATTENDEE_LIST]',
343
-                        'type'                => 'string',
344
-                        'required'            => true,
345
-                        'validation'          => true,
346
-                        'format'              => '%s',
347
-                        'css_class'           => 'large-text',
348
-                        'rows'                => '5',
349
-                        'shortcodes_required' => array('[ATTENDEE_LIST]'),
350
-                    ),
351
-                    'ticket_list'   => array(
352
-                        'input'               => 'textarea',
353
-                        'label'               => '[TICKET_LIST]',
354
-                        'type'                => 'string',
355
-                        'required'            => true,
356
-                        'validation'          => true,
357
-                        'format'              => '%s',
358
-                        'css_class'           => 'large-text',
359
-                        'rows'                => '10',
360
-                        'shortcodes_required' => array('[TICKET_LIST]'),
361
-                    ),
362
-                    'datetime_list' => array(
363
-                        'input'               => 'textarea',
364
-                        'label'               => '[DATETIME_LIST]',
365
-                        'type'                => 'string',
366
-                        'required'            => true,
367
-                        'validation'          => true,
368
-                        'format'              => '%s',
369
-                        'css_class'           => 'large-text',
370
-                        'rows'                => '10',
371
-                        'shortcodes_required' => array('[DATETIME_LIST]'),
372
-                    ),
373
-                ),
374
-            ),
375
-        );
376
-    }
377
-
378
-
379
-    /**
380
-     * See definition of this class in parent
381
-     */
382
-    protected function _set_default_message_types()
383
-    {
384
-        $this->_default_message_types = array(
385
-            'payment',
386
-            'payment_refund',
387
-            'registration',
388
-            'not_approved_registration',
389
-            'pending_approval',
390
-        );
391
-    }
392
-
393
-
394
-    /**
395
-     * @see   definition of this class in parent
396
-     * @since 4.5.0
397
-     */
398
-    protected function _set_valid_message_types()
399
-    {
400
-        $this->_valid_message_types = array(
401
-            'payment',
402
-            'registration',
403
-            'not_approved_registration',
404
-            'declined_registration',
405
-            'cancelled_registration',
406
-            'pending_approval',
407
-            'registration_summary',
408
-            'payment_reminder',
409
-            'payment_declined',
410
-            'payment_refund',
411
-        );
412
-    }
413
-
414
-
415
-    /**
416
-     * setting up admin_settings_fields for messenger.
417
-     */
418
-    protected function _set_admin_settings_fields()
419
-    {
420
-    }
421
-
422
-    /**
423
-     * We just deliver the messages don't kill us!!
424
-     *
425
-     * @return bool|WP_Error true if message delivered, false if it didn't deliver OR bubble up any error object if
426
-     *              present.
427
-     * @throws EE_Error
428
-     * @throws \TijsVerkoyen\CssToInlineStyles\Exception
429
-     */
430
-    protected function _send_message()
431
-    {
432
-        $success = wp_mail(
433
-            html_entity_decode($this->_to, ENT_QUOTES, "UTF-8"),
434
-            stripslashes(html_entity_decode($this->_subject, ENT_QUOTES, "UTF-8")),
435
-            $this->_body(),
436
-            $this->_headers()
437
-        );
438
-        if (! $success) {
439
-            EE_Error::add_error(
440
-                sprintf(
441
-                    esc_html__(
442
-                        'The email did not send successfully.%3$sThe WordPress wp_mail function is used for sending mails but does not give any useful information when an email fails to send.%3$sIt is possible the "to" address (%1$s) or "from" address (%2$s) is invalid.%3$s',
443
-                        'event_espresso'
444
-                    ),
445
-                    $this->_to,
446
-                    $this->_from,
447
-                    '<br />'
448
-                ),
449
-                __FILE__,
450
-                __FUNCTION__,
451
-                __LINE__
452
-            );
453
-        }
454
-        return $success;
455
-    }
456
-
457
-
458
-    /**
459
-     * see parent for definition
460
-     *
461
-     * @return string html body of the message content and the related css.
462
-     * @throws EE_Error
463
-     * @throws \TijsVerkoyen\CssToInlineStyles\Exception
464
-     */
465
-    protected function _preview()
466
-    {
467
-        return $this->_body(true);
468
-    }
469
-
470
-
471
-    /**
472
-     * Setup headers for email
473
-     *
474
-     * @access protected
475
-     * @return string formatted header for email
476
-     */
477
-    protected function _headers()
478
-    {
479
-        $this->_ensure_has_from_email_address();
480
-        $from    = stripslashes_deep(html_entity_decode($this->_from, ENT_QUOTES, "UTF-8"));
481
-        $headers = array(
482
-            'MIME-Version: 1.0',
483
-            'From:' . $from,
484
-            'Reply-To:' . $from,
485
-            'Content-Type:text/html; charset=utf-8',
486
-        );
487
-
488
-        if (! empty($this->_cc)) {
489
-            $headers[] = 'cc: ' . $this->_cc;
490
-        }
491
-
492
-        //but wait!  Header's for the from is NOT reliable because some plugins don't respect From: as set in the
493
-        // header.
494
-        add_filter('wp_mail_from', array($this, 'set_from_address'), 100);
495
-        add_filter('wp_mail_from_name', array($this, 'set_from_name'), 100);
496
-        return apply_filters('FHEE__EE_Email_messenger___headers', $headers, $this->_incoming_message_type, $this);
497
-    }
498
-
499
-
500
-    /**
501
-     * This simply ensures that the from address is not empty.  If it is, then we use whatever is set as the site email
502
-     * address for the from address to avoid problems with sending emails.
503
-     */
504
-    protected function _ensure_has_from_email_address()
505
-    {
506
-        if (empty($this->_from)) {
507
-            $this->_from = get_bloginfo('admin_email');
508
-        }
509
-    }
510
-
511
-
512
-    /**
513
-     * This simply parses whatever is set as the $_from address and determines if it is in the format {name} <{email}>
514
-     * or just {email} and returns an array with the "from_name" and "from_email" as the values. Note from_name *MAY*
515
-     * be empty
516
-     *
517
-     * @since 4.3.1
518
-     * @return array
519
-     */
520
-    private function _parse_from()
521
-    {
522
-        if (strpos($this->_from, '<') !== false) {
523
-            $from_name = substr($this->_from, 0, strpos($this->_from, '<') - 1);
524
-            $from_name = str_replace('"', '', $from_name);
525
-            $from_name = trim($from_name);
526
-
527
-            $from_email = substr($this->_from, strpos($this->_from, '<') + 1);
528
-            $from_email = str_replace('>', '', $from_email);
529
-            $from_email = trim($from_email);
530
-        } elseif (trim($this->_from) !== '') {
531
-            $from_name  = '';
532
-            $from_email = trim($this->_from);
533
-        } else {
534
-            $from_name = $from_email = '';
535
-        }
536
-        return array($from_name, $from_email);
537
-    }
538
-
539
-
540
-    /**
541
-     * Callback for the wp_mail_from filter.
542
-     *
543
-     * @since 4.3.1
544
-     * @param string $from_email What the original from_email is.
545
-     * @return string
546
-     */
547
-    public function set_from_address($from_email)
548
-    {
549
-        $parsed_from = $this->_parse_from();
550
-        //includes fallback if the parsing failed.
551
-        $from_email = is_array($parsed_from) && ! empty($parsed_from[1])
552
-            ? $parsed_from[1]
553
-            : get_bloginfo('admin_email');
554
-        return $from_email;
555
-    }
556
-
557
-
558
-    /**
559
-     * Callback fro the wp_mail_from_name filter.
560
-     *
561
-     * @since 4.3.1
562
-     * @param string $from_name The original from_name.
563
-     * @return string
564
-     */
565
-    public function set_from_name($from_name)
566
-    {
567
-        $parsed_from = $this->_parse_from();
568
-        if (is_array($parsed_from) && ! empty($parsed_from[0])) {
569
-            $from_name = $parsed_from[0];
570
-        }
571
-
572
-        //if from name is "WordPress" let's sub in the site name instead (more friendly!)
573
-        $from_name = $from_name == 'WordPress' ? get_bloginfo() : $from_name;
574
-
575
-        return stripslashes_deep(html_entity_decode($from_name, ENT_QUOTES, "UTF-8"));
576
-    }
577
-
578
-
579
-    /**
580
-     * setup body for email
581
-     *
582
-     * @param bool $preview will determine whether this is preview template or not.
583
-     * @return string formatted body for email.
584
-     * @throws EE_Error
585
-     * @throws \TijsVerkoyen\CssToInlineStyles\Exception
586
-     */
587
-    protected function _body($preview = false)
588
-    {
589
-        //setup template args!
590
-        $this->_template_args = array(
591
-            'subject'   => $this->_subject,
592
-            'from'      => $this->_from,
593
-            'main_body' => wpautop(
594
-                stripslashes_deep(
595
-                    html_entity_decode($this->_content, ENT_QUOTES, "UTF-8")
596
-                )
597
-            ),
598
-        );
599
-        $body                 = $this->_get_main_template($preview);
600
-
601
-        /**
602
-         * This filter allows one to bypass the CSSToInlineStyles tool and leave the body untouched.
603
-         *
604
-         * @type    bool $preview Indicates whether a preview is being generated or not.
605
-         * @return  bool    true  indicates to use the inliner, false bypasses it.
606
-         */
607
-        if (apply_filters('FHEE__EE_Email_messenger__apply_CSSInliner ', true, $preview)) {
608
-            //require CssToInlineStyles library and its dependencies via composer autoloader
609
-            require_once EE_THIRD_PARTY . 'cssinliner/vendor/autoload.php';
610
-
611
-            //now if this isn't a preview, let's setup the body so it has inline styles
612
-            if (! $preview || ($preview && defined('DOING_AJAX'))) {
613
-                $style = file_get_contents(
614
-                    $this->get_variation(
615
-                        $this->_tmp_pack,
616
-                        $this->_incoming_message_type->name,
617
-                        false,
618
-                        'main',
619
-                        $this->_variation
620
-                    ),
621
-                    true
622
-                );
623
-                $CSS   = new TijsVerkoyen\CssToInlineStyles\CssToInlineStyles($body, $style);
624
-                //for some reason the library has a bracket and new line at the beginning.  This takes care of that.
625
-                $body  = ltrim($CSS->convert(true), ">\n");
626
-                //see https://events.codebasehq.com/projects/event-espresso/tickets/8609
627
-                $body  = ltrim($body, "<?");
628
-            }
629
-
630
-        }
631
-        return $body;
632
-    }
633
-
634
-
635
-    /**
636
-     * This just returns any existing test settings that might be saved in the database
637
-     *
638
-     * @access public
639
-     * @return array
640
-     */
641
-    public function get_existing_test_settings()
642
-    {
643
-        $settings = parent::get_existing_test_settings();
644
-        //override subject if present because we always want it to be fresh.
645
-        if (is_array($settings) && ! empty($settings['subject'])) {
646
-            $settings['subject'] = sprintf(__('Test email sent from %s', 'event_espresso'), get_bloginfo('name'));
647
-        }
648
-        return $settings;
649
-    }
11
+	/**
12
+	 * To field for email
13
+	 * @var string
14
+	 */
15
+	protected $_to = '';
16
+
17
+
18
+	/**
19
+	 * CC field for email.
20
+	 * @var string
21
+	 */
22
+	protected $_cc = '';
23
+
24
+	/**
25
+	 * From field for email
26
+	 * @var string
27
+	 */
28
+	protected $_from = '';
29
+
30
+
31
+	/**
32
+	 * Subject field for email
33
+	 * @var string
34
+	 */
35
+	protected $_subject = '';
36
+
37
+
38
+	/**
39
+	 * Content field for email
40
+	 * @var string
41
+	 */
42
+	protected $_content = '';
43
+
44
+
45
+	/**
46
+	 * constructor
47
+	 *
48
+	 * @access public
49
+	 */
50
+	public function __construct()
51
+	{
52
+		//set name and description properties
53
+		$this->name                = 'email';
54
+		$this->description         = esc_html__(
55
+			'This messenger delivers messages via email using the built-in <code>wp_mail</code> function included with WordPress',
56
+			'event_espresso'
57
+		);
58
+		$this->label               = array(
59
+			'singular' => esc_html__('email', 'event_espresso'),
60
+			'plural'   => esc_html__('emails', 'event_espresso'),
61
+		);
62
+		$this->activate_on_install = true;
63
+
64
+		//we're using defaults so let's call parent constructor that will take care of setting up all the other
65
+		// properties
66
+		parent::__construct();
67
+	}
68
+
69
+
70
+	/**
71
+	 * see abstract declaration in parent class for details.
72
+	 */
73
+	protected function _set_admin_pages()
74
+	{
75
+		$this->admin_registered_pages = array(
76
+			'events_edit' => true,
77
+		);
78
+	}
79
+
80
+
81
+	/**
82
+	 * see abstract declaration in parent class for details
83
+	 */
84
+	protected function _set_valid_shortcodes()
85
+	{
86
+		//remember by leaving the other fields not set, those fields will inherit the valid shortcodes from the
87
+		// message type.
88
+		$this->_valid_shortcodes = array(
89
+			'to'   => array('email', 'event_author', 'primary_registration_details', 'recipient_details'),
90
+			'cc' => array('email', 'event_author', 'primary_registration_details', 'recipient_details'),
91
+			'from' => array('email', 'event_author', 'primary_registration_details', 'recipient_details'),
92
+		);
93
+	}
94
+
95
+
96
+	/**
97
+	 * see abstract declaration in parent class for details
98
+	 *
99
+	 * @access protected
100
+	 * @return void
101
+	 */
102
+	protected function _set_validator_config()
103
+	{
104
+		$valid_shortcodes = $this->get_valid_shortcodes();
105
+
106
+		$this->_validator_config = array(
107
+			'to'            => array(
108
+				'shortcodes' => $valid_shortcodes['to'],
109
+				'type'       => 'email',
110
+			),
111
+			'cc' => array(
112
+				'shortcodes' => $valid_shortcodes['to'],
113
+				'type' => 'email',
114
+			),
115
+			'from'          => array(
116
+				'shortcodes' => $valid_shortcodes['from'],
117
+				'type'       => 'email',
118
+			),
119
+			'subject'       => array(
120
+				'shortcodes' => array(
121
+					'organization',
122
+					'primary_registration_details',
123
+					'event_author',
124
+					'primary_registration_details',
125
+					'recipient_details',
126
+				),
127
+			),
128
+			'content'       => array(
129
+				'shortcodes' => array(
130
+					'event_list',
131
+					'attendee_list',
132
+					'ticket_list',
133
+					'organization',
134
+					'primary_registration_details',
135
+					'primary_registration_list',
136
+					'event_author',
137
+					'recipient_details',
138
+					'recipient_list',
139
+					'transaction',
140
+					'messenger',
141
+				),
142
+			),
143
+			'attendee_list' => array(
144
+				'shortcodes' => array('attendee', 'event_list', 'ticket_list'),
145
+				'required'   => array('[ATTENDEE_LIST]'),
146
+			),
147
+			'event_list'    => array(
148
+				'shortcodes' => array(
149
+					'event',
150
+					'attendee_list',
151
+					'ticket_list',
152
+					'venue',
153
+					'datetime_list',
154
+					'attendee',
155
+					'primary_registration_details',
156
+					'primary_registration_list',
157
+					'event_author',
158
+					'recipient_details',
159
+					'recipient_list',
160
+				),
161
+				'required'   => array('[EVENT_LIST]'),
162
+			),
163
+			'ticket_list'   => array(
164
+				'shortcodes' => array(
165
+					'event_list',
166
+					'attendee_list',
167
+					'ticket',
168
+					'datetime_list',
169
+					'primary_registration_details',
170
+					'recipient_details',
171
+				),
172
+				'required'   => array('[TICKET_LIST]'),
173
+			),
174
+			'datetime_list' => array(
175
+				'shortcodes' => array('datetime'),
176
+				'required'   => array('[DATETIME_LIST]'),
177
+			),
178
+		);
179
+	}
180
+
181
+
182
+	/**
183
+	 * @see   parent EE_messenger class for docs
184
+	 * @since 4.5.0
185
+	 */
186
+	public function do_secondary_messenger_hooks($sending_messenger_name)
187
+	{
188
+		if ($sending_messenger_name = 'html') {
189
+			add_filter('FHEE__EE_Messages_Template_Pack__get_variation', array($this, 'add_email_css'), 10, 8);
190
+		}
191
+	}
192
+
193
+
194
+	public function add_email_css(
195
+		$variation_path,
196
+		$messenger,
197
+		$message_type,
198
+		$type,
199
+		$variation,
200
+		$file_extension,
201
+		$url,
202
+		EE_Messages_Template_Pack $template_pack
203
+	) {
204
+		//prevent recursion on this callback.
205
+		remove_filter('FHEE__EE_Messages_Template_Pack__get_variation', array($this, 'add_email_css'), 10);
206
+		$variation = $this->get_variation($template_pack, $message_type, $url, 'main', $variation, false);
207
+
208
+		add_filter('FHEE__EE_Messages_Template_Pack__get_variation', array($this, 'add_email_css'), 10, 8);
209
+		return $variation;
210
+	}
211
+
212
+
213
+	/**
214
+	 * See parent for details
215
+	 *
216
+	 * @access protected
217
+	 * @return void
218
+	 */
219
+	protected function _set_test_settings_fields()
220
+	{
221
+		$this->_test_settings_fields = array(
222
+			'to'      => array(
223
+				'input'      => 'text',
224
+				'label'      => esc_html__('Send a test email to', 'event_espresso'),
225
+				'type'       => 'email',
226
+				'required'   => true,
227
+				'validation' => true,
228
+				'css_class'  => 'large-text',
229
+				'format'     => '%s',
230
+				'default'    => get_bloginfo('admin_email'),
231
+			),
232
+			'subject' => array(
233
+				'input'      => 'hidden',
234
+				'label'      => '',
235
+				'type'       => 'string',
236
+				'required'   => false,
237
+				'validation' => false,
238
+				'format'     => '%s',
239
+				'value'      => sprintf(__('Test email sent from %s', 'event_espresso'), get_bloginfo('name')),
240
+				'default'    => '',
241
+				'css_class'  => '',
242
+			),
243
+		);
244
+	}
245
+
246
+
247
+	/**
248
+	 * _set_template_fields
249
+	 * This sets up the fields that a messenger requires for the message to go out.
250
+	 *
251
+	 * @access  protected
252
+	 * @return void
253
+	 */
254
+	protected function _set_template_fields()
255
+	{
256
+		// any extra template fields that are NOT used by the messenger but will get used by a messenger field for
257
+		// shortcode replacement get added to the 'extra' key in an associated array indexed by the messenger field
258
+		// they relate to.  This is important for the Messages_admin to know what fields to display to the user.
259
+		//  Also, notice that the "values" are equal to the field type that messages admin will use to know what
260
+		// kind of field to display. The values ALSO have one index labeled "shortcode".  the values in that array
261
+		// indicate which ACTUAL SHORTCODE (i.e. [SHORTCODE]) is required in order for this extra field to be
262
+		// displayed.  If the required shortcode isn't part of the shortcodes array then the field is not needed and
263
+		// will not be displayed/parsed.
264
+		$this->_template_fields = array(
265
+			'to'      => array(
266
+				'input'      => 'text',
267
+				'label'      => esc_html_x(
268
+					'To',
269
+					'Label for the "To" field for email addresses',
270
+					'event_espresso'
271
+				),
272
+				'type'       => 'string',
273
+				'required'   => true,
274
+				'validation' => true,
275
+				'css_class'  => 'large-text',
276
+				'format'     => '%s',
277
+			),
278
+			'cc'      => array(
279
+				'input'      => 'text',
280
+				'label'      => esc_html_x(
281
+					'CC',
282
+					'Label for the "Carbon Copy" field used for additional email addresses',
283
+					'event_espresso'
284
+				),
285
+				'type'       => 'string',
286
+				'required'   => false,
287
+				'validation' => true,
288
+				'css_class'  => 'large-text',
289
+				'format'     => '%s',
290
+			),
291
+			'from'    => array(
292
+				'input'      => 'text',
293
+				'label'      => esc_html_x(
294
+					'From',
295
+					'Label for the "From" field for email addresses.',
296
+					'event_espresso'
297
+				),
298
+				'type'       => 'string',
299
+				'required'   => true,
300
+				'validation' => true,
301
+				'css_class'  => 'large-text',
302
+				'format'     => '%s',
303
+			),
304
+			'subject' => array(
305
+				'input'      => 'text',
306
+				'label'      => esc_html_x(
307
+					'Subject',
308
+					'Label for the "Subject" field (short description of contents) for emails.',
309
+					'event_espresso'
310
+				),
311
+				'type'       => 'string',
312
+				'required'   => true,
313
+				'validation' => true,
314
+				'css_class'  => 'large-text',
315
+				'format'     => '%s',
316
+			),
317
+			'content' => '',
318
+			//left empty b/c it is in the "extra array" but messenger still needs needs to know this is a field.
319
+			'extra'   => array(
320
+				'content' => array(
321
+					'main'          => array(
322
+						'input'      => 'wp_editor',
323
+						'label'      => esc_html__('Main Content', 'event_espresso'),
324
+						'type'       => 'string',
325
+						'required'   => true,
326
+						'validation' => true,
327
+						'format'     => '%s',
328
+						'rows'       => '15',
329
+					),
330
+					'event_list'    => array(
331
+						'input'               => 'wp_editor',
332
+						'label'               => '[EVENT_LIST]',
333
+						'type'                => 'string',
334
+						'required'            => true,
335
+						'validation'          => true,
336
+						'format'              => '%s',
337
+						'rows'                => '15',
338
+						'shortcodes_required' => array('[EVENT_LIST]'),
339
+					),
340
+					'attendee_list' => array(
341
+						'input'               => 'textarea',
342
+						'label'               => '[ATTENDEE_LIST]',
343
+						'type'                => 'string',
344
+						'required'            => true,
345
+						'validation'          => true,
346
+						'format'              => '%s',
347
+						'css_class'           => 'large-text',
348
+						'rows'                => '5',
349
+						'shortcodes_required' => array('[ATTENDEE_LIST]'),
350
+					),
351
+					'ticket_list'   => array(
352
+						'input'               => 'textarea',
353
+						'label'               => '[TICKET_LIST]',
354
+						'type'                => 'string',
355
+						'required'            => true,
356
+						'validation'          => true,
357
+						'format'              => '%s',
358
+						'css_class'           => 'large-text',
359
+						'rows'                => '10',
360
+						'shortcodes_required' => array('[TICKET_LIST]'),
361
+					),
362
+					'datetime_list' => array(
363
+						'input'               => 'textarea',
364
+						'label'               => '[DATETIME_LIST]',
365
+						'type'                => 'string',
366
+						'required'            => true,
367
+						'validation'          => true,
368
+						'format'              => '%s',
369
+						'css_class'           => 'large-text',
370
+						'rows'                => '10',
371
+						'shortcodes_required' => array('[DATETIME_LIST]'),
372
+					),
373
+				),
374
+			),
375
+		);
376
+	}
377
+
378
+
379
+	/**
380
+	 * See definition of this class in parent
381
+	 */
382
+	protected function _set_default_message_types()
383
+	{
384
+		$this->_default_message_types = array(
385
+			'payment',
386
+			'payment_refund',
387
+			'registration',
388
+			'not_approved_registration',
389
+			'pending_approval',
390
+		);
391
+	}
392
+
393
+
394
+	/**
395
+	 * @see   definition of this class in parent
396
+	 * @since 4.5.0
397
+	 */
398
+	protected function _set_valid_message_types()
399
+	{
400
+		$this->_valid_message_types = array(
401
+			'payment',
402
+			'registration',
403
+			'not_approved_registration',
404
+			'declined_registration',
405
+			'cancelled_registration',
406
+			'pending_approval',
407
+			'registration_summary',
408
+			'payment_reminder',
409
+			'payment_declined',
410
+			'payment_refund',
411
+		);
412
+	}
413
+
414
+
415
+	/**
416
+	 * setting up admin_settings_fields for messenger.
417
+	 */
418
+	protected function _set_admin_settings_fields()
419
+	{
420
+	}
421
+
422
+	/**
423
+	 * We just deliver the messages don't kill us!!
424
+	 *
425
+	 * @return bool|WP_Error true if message delivered, false if it didn't deliver OR bubble up any error object if
426
+	 *              present.
427
+	 * @throws EE_Error
428
+	 * @throws \TijsVerkoyen\CssToInlineStyles\Exception
429
+	 */
430
+	protected function _send_message()
431
+	{
432
+		$success = wp_mail(
433
+			html_entity_decode($this->_to, ENT_QUOTES, "UTF-8"),
434
+			stripslashes(html_entity_decode($this->_subject, ENT_QUOTES, "UTF-8")),
435
+			$this->_body(),
436
+			$this->_headers()
437
+		);
438
+		if (! $success) {
439
+			EE_Error::add_error(
440
+				sprintf(
441
+					esc_html__(
442
+						'The email did not send successfully.%3$sThe WordPress wp_mail function is used for sending mails but does not give any useful information when an email fails to send.%3$sIt is possible the "to" address (%1$s) or "from" address (%2$s) is invalid.%3$s',
443
+						'event_espresso'
444
+					),
445
+					$this->_to,
446
+					$this->_from,
447
+					'<br />'
448
+				),
449
+				__FILE__,
450
+				__FUNCTION__,
451
+				__LINE__
452
+			);
453
+		}
454
+		return $success;
455
+	}
456
+
457
+
458
+	/**
459
+	 * see parent for definition
460
+	 *
461
+	 * @return string html body of the message content and the related css.
462
+	 * @throws EE_Error
463
+	 * @throws \TijsVerkoyen\CssToInlineStyles\Exception
464
+	 */
465
+	protected function _preview()
466
+	{
467
+		return $this->_body(true);
468
+	}
469
+
470
+
471
+	/**
472
+	 * Setup headers for email
473
+	 *
474
+	 * @access protected
475
+	 * @return string formatted header for email
476
+	 */
477
+	protected function _headers()
478
+	{
479
+		$this->_ensure_has_from_email_address();
480
+		$from    = stripslashes_deep(html_entity_decode($this->_from, ENT_QUOTES, "UTF-8"));
481
+		$headers = array(
482
+			'MIME-Version: 1.0',
483
+			'From:' . $from,
484
+			'Reply-To:' . $from,
485
+			'Content-Type:text/html; charset=utf-8',
486
+		);
487
+
488
+		if (! empty($this->_cc)) {
489
+			$headers[] = 'cc: ' . $this->_cc;
490
+		}
491
+
492
+		//but wait!  Header's for the from is NOT reliable because some plugins don't respect From: as set in the
493
+		// header.
494
+		add_filter('wp_mail_from', array($this, 'set_from_address'), 100);
495
+		add_filter('wp_mail_from_name', array($this, 'set_from_name'), 100);
496
+		return apply_filters('FHEE__EE_Email_messenger___headers', $headers, $this->_incoming_message_type, $this);
497
+	}
498
+
499
+
500
+	/**
501
+	 * This simply ensures that the from address is not empty.  If it is, then we use whatever is set as the site email
502
+	 * address for the from address to avoid problems with sending emails.
503
+	 */
504
+	protected function _ensure_has_from_email_address()
505
+	{
506
+		if (empty($this->_from)) {
507
+			$this->_from = get_bloginfo('admin_email');
508
+		}
509
+	}
510
+
511
+
512
+	/**
513
+	 * This simply parses whatever is set as the $_from address and determines if it is in the format {name} <{email}>
514
+	 * or just {email} and returns an array with the "from_name" and "from_email" as the values. Note from_name *MAY*
515
+	 * be empty
516
+	 *
517
+	 * @since 4.3.1
518
+	 * @return array
519
+	 */
520
+	private function _parse_from()
521
+	{
522
+		if (strpos($this->_from, '<') !== false) {
523
+			$from_name = substr($this->_from, 0, strpos($this->_from, '<') - 1);
524
+			$from_name = str_replace('"', '', $from_name);
525
+			$from_name = trim($from_name);
526
+
527
+			$from_email = substr($this->_from, strpos($this->_from, '<') + 1);
528
+			$from_email = str_replace('>', '', $from_email);
529
+			$from_email = trim($from_email);
530
+		} elseif (trim($this->_from) !== '') {
531
+			$from_name  = '';
532
+			$from_email = trim($this->_from);
533
+		} else {
534
+			$from_name = $from_email = '';
535
+		}
536
+		return array($from_name, $from_email);
537
+	}
538
+
539
+
540
+	/**
541
+	 * Callback for the wp_mail_from filter.
542
+	 *
543
+	 * @since 4.3.1
544
+	 * @param string $from_email What the original from_email is.
545
+	 * @return string
546
+	 */
547
+	public function set_from_address($from_email)
548
+	{
549
+		$parsed_from = $this->_parse_from();
550
+		//includes fallback if the parsing failed.
551
+		$from_email = is_array($parsed_from) && ! empty($parsed_from[1])
552
+			? $parsed_from[1]
553
+			: get_bloginfo('admin_email');
554
+		return $from_email;
555
+	}
556
+
557
+
558
+	/**
559
+	 * Callback fro the wp_mail_from_name filter.
560
+	 *
561
+	 * @since 4.3.1
562
+	 * @param string $from_name The original from_name.
563
+	 * @return string
564
+	 */
565
+	public function set_from_name($from_name)
566
+	{
567
+		$parsed_from = $this->_parse_from();
568
+		if (is_array($parsed_from) && ! empty($parsed_from[0])) {
569
+			$from_name = $parsed_from[0];
570
+		}
571
+
572
+		//if from name is "WordPress" let's sub in the site name instead (more friendly!)
573
+		$from_name = $from_name == 'WordPress' ? get_bloginfo() : $from_name;
574
+
575
+		return stripslashes_deep(html_entity_decode($from_name, ENT_QUOTES, "UTF-8"));
576
+	}
577
+
578
+
579
+	/**
580
+	 * setup body for email
581
+	 *
582
+	 * @param bool $preview will determine whether this is preview template or not.
583
+	 * @return string formatted body for email.
584
+	 * @throws EE_Error
585
+	 * @throws \TijsVerkoyen\CssToInlineStyles\Exception
586
+	 */
587
+	protected function _body($preview = false)
588
+	{
589
+		//setup template args!
590
+		$this->_template_args = array(
591
+			'subject'   => $this->_subject,
592
+			'from'      => $this->_from,
593
+			'main_body' => wpautop(
594
+				stripslashes_deep(
595
+					html_entity_decode($this->_content, ENT_QUOTES, "UTF-8")
596
+				)
597
+			),
598
+		);
599
+		$body                 = $this->_get_main_template($preview);
600
+
601
+		/**
602
+		 * This filter allows one to bypass the CSSToInlineStyles tool and leave the body untouched.
603
+		 *
604
+		 * @type    bool $preview Indicates whether a preview is being generated or not.
605
+		 * @return  bool    true  indicates to use the inliner, false bypasses it.
606
+		 */
607
+		if (apply_filters('FHEE__EE_Email_messenger__apply_CSSInliner ', true, $preview)) {
608
+			//require CssToInlineStyles library and its dependencies via composer autoloader
609
+			require_once EE_THIRD_PARTY . 'cssinliner/vendor/autoload.php';
610
+
611
+			//now if this isn't a preview, let's setup the body so it has inline styles
612
+			if (! $preview || ($preview && defined('DOING_AJAX'))) {
613
+				$style = file_get_contents(
614
+					$this->get_variation(
615
+						$this->_tmp_pack,
616
+						$this->_incoming_message_type->name,
617
+						false,
618
+						'main',
619
+						$this->_variation
620
+					),
621
+					true
622
+				);
623
+				$CSS   = new TijsVerkoyen\CssToInlineStyles\CssToInlineStyles($body, $style);
624
+				//for some reason the library has a bracket and new line at the beginning.  This takes care of that.
625
+				$body  = ltrim($CSS->convert(true), ">\n");
626
+				//see https://events.codebasehq.com/projects/event-espresso/tickets/8609
627
+				$body  = ltrim($body, "<?");
628
+			}
629
+
630
+		}
631
+		return $body;
632
+	}
633
+
634
+
635
+	/**
636
+	 * This just returns any existing test settings that might be saved in the database
637
+	 *
638
+	 * @access public
639
+	 * @return array
640
+	 */
641
+	public function get_existing_test_settings()
642
+	{
643
+		$settings = parent::get_existing_test_settings();
644
+		//override subject if present because we always want it to be fresh.
645
+		if (is_array($settings) && ! empty($settings['subject'])) {
646
+			$settings['subject'] = sprintf(__('Test email sent from %s', 'event_espresso'), get_bloginfo('name'));
647
+		}
648
+		return $settings;
649
+	}
650 650
 }
Please login to merge, or discard this patch.
modules/messages/EED_Messages.module.php 1 patch
Indentation   +1080 added lines, -1080 removed lines patch added patch discarded remove patch
@@ -13,1095 +13,1095 @@
 block discarded – undo
13 13
 class EED_Messages extends EED_Module
14 14
 {
15 15
 
16
-    /**
17
-     * This holds the EE_messages controller
18
-     *
19
-     * @deprecated 4.9.0
20
-     * @var EE_messages $_EEMSG
21
-     */
22
-    protected static $_EEMSG;
23
-
24
-    /**
25
-     * @type EE_Message_Resource_Manager $_message_resource_manager
26
-     */
27
-    protected static $_message_resource_manager;
28
-
29
-    /**
30
-     * This holds the EE_Messages_Processor business class.
31
-     *
32
-     * @type EE_Messages_Processor
33
-     */
34
-    protected static $_MSG_PROCESSOR;
35
-
36
-    /**
37
-     * holds all the paths for various messages components.
38
-     * Utilized by autoloader registry
39
-     *
40
-     * @var array
41
-     */
42
-    protected static $_MSG_PATHS;
43
-
44
-
45
-    /**
46
-     * This will hold an array of messages template packs that are registered in the messages system.
47
-     * Format is:
48
-     * array(
49
-     *    'template_pack_dbref' => EE_Messages_Template_Pack (instance)
50
-     * )
51
-     *
52
-     * @var EE_Messages_Template_Pack[]
53
-     */
54
-    protected static $_TMP_PACKS = array();
55
-
56
-
57
-    /**
58
-     * @return EED_Messages
59
-     */
60
-    public static function instance()
61
-    {
62
-        return parent::get_instance(__CLASS__);
63
-    }
64
-
65
-
66
-    /**
67
-     *  set_hooks - for hooking into EE Core, other modules, etc
68
-     *
69
-     * @since 4.5.0
70
-     * @return    void
71
-     */
72
-    public static function set_hooks()
73
-    {
74
-        //actions
75
-        add_action('AHEE__EE_Payment_Processor__update_txn_based_on_payment', array('EED_Messages', 'payment'), 10, 2);
76
-        add_action('AHEE__EE_Registration_Processor__trigger_registration_update_notifications',
77
-            array('EED_Messages', 'maybe_registration'), 10, 2);
78
-        //filters
79
-        add_filter('FHEE__EE_Registration__receipt_url__receipt_url',
80
-            array('EED_Messages', 'registration_message_trigger_url'), 10, 4);
81
-        add_filter('FHEE__EE_Registration__invoice_url__invoice_url',
82
-            array('EED_Messages', 'registration_message_trigger_url'), 10, 4);
83
-        //register routes
84
-        self::_register_routes();
85
-    }
86
-
87
-    /**
88
-     *    set_hooks_admin - for hooking into EE Admin Core, other modules, etc
89
-     *
90
-     * @access    public
91
-     * @return    void
92
-     */
93
-    public static function set_hooks_admin()
94
-    {
95
-        //actions
96
-        add_action('AHEE__EE_Payment_Processor__update_txn_based_on_payment', array('EED_Messages', 'payment'), 10, 2);
97
-        add_action('AHEE__Transactions_Admin_Page___send_payment_reminder__process_admin_payment_reminder',
98
-            array('EED_Messages', 'payment_reminder'), 10);
99
-        add_action('AHEE__EE_Registration_Processor__trigger_registration_update_notifications',
100
-            array('EED_Messages', 'maybe_registration'), 10, 3);
101
-        add_action('AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send__with_registrations',
102
-            array('EED_Messages', 'send_newsletter_message'), 10, 2);
103
-        add_action('AHEE__EES_Espresso_Cancelled__process_shortcode__transaction',
104
-            array('EED_Messages', 'cancelled_registration'), 10);
105
-        add_action('AHEE__EE_Admin_Page___process_admin_payment_notification',
106
-            array('EED_Messages', 'process_admin_payment'), 10, 1);
107
-        //filters
108
-        add_filter('FHEE__EE_Admin_Page___process_resend_registration__success',
109
-            array('EED_Messages', 'process_resend'), 10, 2);
110
-        add_filter('FHEE__EE_Registration__receipt_url__receipt_url',
111
-            array('EED_Messages', 'registration_message_trigger_url'), 10, 4);
112
-        add_filter('FHEE__EE_Registration__invoice_url__invoice_url',
113
-            array('EED_Messages', 'registration_message_trigger_url'), 10, 4);
114
-    }
115
-
116
-
117
-    /**
118
-     * All the message triggers done by route go in here.
119
-     *
120
-     * @since 4.5.0
121
-     * @return void
122
-     */
123
-    protected static function _register_routes()
124
-    {
125
-        EE_Config::register_route('msg_url_trigger', 'Messages', 'run');
126
-        EE_Config::register_route('msg_cron_trigger', 'Messages', 'execute_batch_request');
127
-        EE_Config::register_route('msg_browser_trigger', 'Messages', 'browser_trigger');
128
-        EE_Config::register_route('msg_browser_error_trigger', 'Messages', 'browser_error_trigger');
129
-        do_action('AHEE__EED_Messages___register_routes');
130
-    }
131
-
132
-
133
-    /**
134
-     * This is called when a browser display trigger is executed.
135
-     * The browser display trigger is typically used when a already generated message is displayed directly in the
136
-     * browser.
137
-     *
138
-     * @since 4.9.0
139
-     * @param WP $WP
140
-     */
141
-    public function browser_trigger($WP)
142
-    {
143
-        //ensure controller is loaded
144
-        self::_load_controller();
145
-        $token = EE_Registry::instance()->REQ->get('token');
146
-        try {
147
-            $mtg = new EE_Message_Generated_From_Token($token, 'html', self::$_message_resource_manager);
148
-            self::$_MSG_PROCESSOR->generate_and_send_now($mtg);
149
-        } catch (EE_Error $e) {
150
-            $error_msg = __('Please note that a system message failed to send due to a technical issue.',
151
-                'event_espresso');
152
-            // add specific message for developers if WP_DEBUG in on
153
-            $error_msg .= '||' . $e->getMessage();
154
-            EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__);
155
-        }
156
-    }
157
-
158
-
159
-    /**
160
-     * This is called when a browser error trigger is executed.
161
-     * When triggered this will grab the EE_Message matching the token in the request and use that to get the error
162
-     * message and display it.
163
-     *
164
-     * @since 4.9.0
165
-     * @param $WP
166
-     */
167
-    public function browser_error_trigger($WP)
168
-    {
169
-        $token = EE_Registry::instance()->REQ->get('token');
170
-        if ($token) {
171
-            $message = EEM_Message::instance()->get_one_by_token($token);
172
-            if ($message instanceof EE_Message) {
173
-                header('HTTP/1.1 200 OK');
174
-                $error_msg = nl2br($message->error_message());
175
-                ?>
16
+	/**
17
+	 * This holds the EE_messages controller
18
+	 *
19
+	 * @deprecated 4.9.0
20
+	 * @var EE_messages $_EEMSG
21
+	 */
22
+	protected static $_EEMSG;
23
+
24
+	/**
25
+	 * @type EE_Message_Resource_Manager $_message_resource_manager
26
+	 */
27
+	protected static $_message_resource_manager;
28
+
29
+	/**
30
+	 * This holds the EE_Messages_Processor business class.
31
+	 *
32
+	 * @type EE_Messages_Processor
33
+	 */
34
+	protected static $_MSG_PROCESSOR;
35
+
36
+	/**
37
+	 * holds all the paths for various messages components.
38
+	 * Utilized by autoloader registry
39
+	 *
40
+	 * @var array
41
+	 */
42
+	protected static $_MSG_PATHS;
43
+
44
+
45
+	/**
46
+	 * This will hold an array of messages template packs that are registered in the messages system.
47
+	 * Format is:
48
+	 * array(
49
+	 *    'template_pack_dbref' => EE_Messages_Template_Pack (instance)
50
+	 * )
51
+	 *
52
+	 * @var EE_Messages_Template_Pack[]
53
+	 */
54
+	protected static $_TMP_PACKS = array();
55
+
56
+
57
+	/**
58
+	 * @return EED_Messages
59
+	 */
60
+	public static function instance()
61
+	{
62
+		return parent::get_instance(__CLASS__);
63
+	}
64
+
65
+
66
+	/**
67
+	 *  set_hooks - for hooking into EE Core, other modules, etc
68
+	 *
69
+	 * @since 4.5.0
70
+	 * @return    void
71
+	 */
72
+	public static function set_hooks()
73
+	{
74
+		//actions
75
+		add_action('AHEE__EE_Payment_Processor__update_txn_based_on_payment', array('EED_Messages', 'payment'), 10, 2);
76
+		add_action('AHEE__EE_Registration_Processor__trigger_registration_update_notifications',
77
+			array('EED_Messages', 'maybe_registration'), 10, 2);
78
+		//filters
79
+		add_filter('FHEE__EE_Registration__receipt_url__receipt_url',
80
+			array('EED_Messages', 'registration_message_trigger_url'), 10, 4);
81
+		add_filter('FHEE__EE_Registration__invoice_url__invoice_url',
82
+			array('EED_Messages', 'registration_message_trigger_url'), 10, 4);
83
+		//register routes
84
+		self::_register_routes();
85
+	}
86
+
87
+	/**
88
+	 *    set_hooks_admin - for hooking into EE Admin Core, other modules, etc
89
+	 *
90
+	 * @access    public
91
+	 * @return    void
92
+	 */
93
+	public static function set_hooks_admin()
94
+	{
95
+		//actions
96
+		add_action('AHEE__EE_Payment_Processor__update_txn_based_on_payment', array('EED_Messages', 'payment'), 10, 2);
97
+		add_action('AHEE__Transactions_Admin_Page___send_payment_reminder__process_admin_payment_reminder',
98
+			array('EED_Messages', 'payment_reminder'), 10);
99
+		add_action('AHEE__EE_Registration_Processor__trigger_registration_update_notifications',
100
+			array('EED_Messages', 'maybe_registration'), 10, 3);
101
+		add_action('AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send__with_registrations',
102
+			array('EED_Messages', 'send_newsletter_message'), 10, 2);
103
+		add_action('AHEE__EES_Espresso_Cancelled__process_shortcode__transaction',
104
+			array('EED_Messages', 'cancelled_registration'), 10);
105
+		add_action('AHEE__EE_Admin_Page___process_admin_payment_notification',
106
+			array('EED_Messages', 'process_admin_payment'), 10, 1);
107
+		//filters
108
+		add_filter('FHEE__EE_Admin_Page___process_resend_registration__success',
109
+			array('EED_Messages', 'process_resend'), 10, 2);
110
+		add_filter('FHEE__EE_Registration__receipt_url__receipt_url',
111
+			array('EED_Messages', 'registration_message_trigger_url'), 10, 4);
112
+		add_filter('FHEE__EE_Registration__invoice_url__invoice_url',
113
+			array('EED_Messages', 'registration_message_trigger_url'), 10, 4);
114
+	}
115
+
116
+
117
+	/**
118
+	 * All the message triggers done by route go in here.
119
+	 *
120
+	 * @since 4.5.0
121
+	 * @return void
122
+	 */
123
+	protected static function _register_routes()
124
+	{
125
+		EE_Config::register_route('msg_url_trigger', 'Messages', 'run');
126
+		EE_Config::register_route('msg_cron_trigger', 'Messages', 'execute_batch_request');
127
+		EE_Config::register_route('msg_browser_trigger', 'Messages', 'browser_trigger');
128
+		EE_Config::register_route('msg_browser_error_trigger', 'Messages', 'browser_error_trigger');
129
+		do_action('AHEE__EED_Messages___register_routes');
130
+	}
131
+
132
+
133
+	/**
134
+	 * This is called when a browser display trigger is executed.
135
+	 * The browser display trigger is typically used when a already generated message is displayed directly in the
136
+	 * browser.
137
+	 *
138
+	 * @since 4.9.0
139
+	 * @param WP $WP
140
+	 */
141
+	public function browser_trigger($WP)
142
+	{
143
+		//ensure controller is loaded
144
+		self::_load_controller();
145
+		$token = EE_Registry::instance()->REQ->get('token');
146
+		try {
147
+			$mtg = new EE_Message_Generated_From_Token($token, 'html', self::$_message_resource_manager);
148
+			self::$_MSG_PROCESSOR->generate_and_send_now($mtg);
149
+		} catch (EE_Error $e) {
150
+			$error_msg = __('Please note that a system message failed to send due to a technical issue.',
151
+				'event_espresso');
152
+			// add specific message for developers if WP_DEBUG in on
153
+			$error_msg .= '||' . $e->getMessage();
154
+			EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__);
155
+		}
156
+	}
157
+
158
+
159
+	/**
160
+	 * This is called when a browser error trigger is executed.
161
+	 * When triggered this will grab the EE_Message matching the token in the request and use that to get the error
162
+	 * message and display it.
163
+	 *
164
+	 * @since 4.9.0
165
+	 * @param $WP
166
+	 */
167
+	public function browser_error_trigger($WP)
168
+	{
169
+		$token = EE_Registry::instance()->REQ->get('token');
170
+		if ($token) {
171
+			$message = EEM_Message::instance()->get_one_by_token($token);
172
+			if ($message instanceof EE_Message) {
173
+				header('HTTP/1.1 200 OK');
174
+				$error_msg = nl2br($message->error_message());
175
+				?>
176 176
                 <!DOCTYPE html>
177 177
                 <html>
178 178
                 <head></head>
179 179
                 <body>
180 180
                 <?php echo empty($error_msg)
181
-                    ? esc_html__('Unfortunately, we were unable to capture the error message for this message.',
182
-                        'event_espresso')
183
-                    : wp_kses(
184
-                        $error_msg,
185
-                        array(
186
-                            'a'      => array(
187
-                                'href'  => array(),
188
-                                'title' => array(),
189
-                            ),
190
-                            'span'   => array(),
191
-                            'div'    => array(),
192
-                            'p'      => array(),
193
-                            'strong' => array(),
194
-                            'em'     => array(),
195
-                            'br'     => array(),
196
-                        )
197
-                    ); ?>
181
+					? esc_html__('Unfortunately, we were unable to capture the error message for this message.',
182
+						'event_espresso')
183
+					: wp_kses(
184
+						$error_msg,
185
+						array(
186
+							'a'      => array(
187
+								'href'  => array(),
188
+								'title' => array(),
189
+							),
190
+							'span'   => array(),
191
+							'div'    => array(),
192
+							'p'      => array(),
193
+							'strong' => array(),
194
+							'em'     => array(),
195
+							'br'     => array(),
196
+						)
197
+					); ?>
198 198
                 </body>
199 199
                 </html>
200 200
                 <?php
201
-                exit;
202
-            }
203
-        }
204
-        return;
205
-    }
206
-
207
-
208
-    /**
209
-     *  This runs when the msg_url_trigger route has initiated.
210
-     *
211
-     * @since 4.5.0
212
-     * @param WP $WP
213
-     * @throws EE_Error
214
-     * @return    void
215
-     */
216
-    public function run($WP)
217
-    {
218
-        //ensure controller is loaded
219
-        self::_load_controller();
220
-        // attempt to process message
221
-        try {
222
-            /** @type EE_Message_To_Generate_From_Request $message_to_generate */
223
-            $message_to_generate = EE_Registry::instance()->load_lib('Message_To_Generate_From_Request');
224
-            self::$_MSG_PROCESSOR->generate_and_send_now($message_to_generate);
225
-        } catch (EE_Error $e) {
226
-            $error_msg = __('Please note that a system message failed to send due to a technical issue.',
227
-                'event_espresso');
228
-            // add specific message for developers if WP_DEBUG in on
229
-            $error_msg .= '||' . $e->getMessage();
230
-            EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__);
231
-        }
232
-    }
233
-
234
-
235
-    /**
236
-     * This is triggered by the 'msg_cron_trigger' route.
237
-     *
238
-     * @param WP $WP
239
-     */
240
-    public function execute_batch_request($WP)
241
-    {
242
-        $this->run_cron();
243
-        header('HTTP/1.1 200 OK');
244
-        exit();
245
-    }
246
-
247
-
248
-    /**
249
-     * This gets executed on wp_cron jobs or when a batch request is initiated on its own separate non regular wp
250
-     * request.
251
-     */
252
-    public function run_cron()
253
-    {
254
-        self::_load_controller();
255
-        //get required vars
256
-        $cron_type     = EE_Registry::instance()->REQ->get('type');
257
-        $transient_key = EE_Registry::instance()->REQ->get('key');
258
-
259
-        //now let's verify transient, if not valid exit immediately
260
-        if (! get_transient($transient_key)) {
261
-            /**
262
-             * trigger error so this gets in the error logs.  This is important because it happens on a non-user request.
263
-             */
264
-            trigger_error(esc_attr__('Invalid Request (Transient does not exist)', 'event_espresso'));
265
-        }
266
-
267
-        //if made it here, lets' delete the transient to keep the db clean
268
-        delete_transient($transient_key);
269
-
270
-        if (apply_filters('FHEE__EED_Messages__run_cron__use_wp_cron', true)) {
271
-
272
-            $method = 'batch_' . $cron_type . '_from_queue';
273
-            if (method_exists(self::$_MSG_PROCESSOR, $method)) {
274
-                self::$_MSG_PROCESSOR->$method();
275
-            } else {
276
-                //no matching task
277
-                /**
278
-                 * trigger error so this gets in the error logs.  This is important because it happens on a non user request.
279
-                 */
280
-                trigger_error(esc_attr(sprintf(__('There is no task corresponding to this route %s', 'event_espresso'),
281
-                    $cron_type)));
282
-            }
283
-        }
284
-
285
-        do_action('FHEE__EED_Messages__run_cron__end');
286
-    }
287
-
288
-
289
-    /**
290
-     * This is used to retrieve the template pack for the given name.
291
-     * Retrieved packs are cached on the static $_TMP_PACKS array.  If there is no class matching the given name then
292
-     * the default template pack is returned.
293
-     *
294
-     * @deprecated 4.9.0  @see EEH_MSG_Template::get_template_pack()
295
-     * @param string $template_pack_name This should correspond to the dbref of the template pack (which is also used
296
-     *                                   in generating the Pack class name).
297
-     * @return EE_Messages_Template_Pack
298
-     */
299
-    public static function get_template_pack($template_pack_name)
300
-    {
301
-        EE_Registry::instance()->load_helper('MSG_Template');
302
-        return EEH_MSG_Template::get_template_pack($template_pack_name);
303
-    }
304
-
305
-
306
-    /**
307
-     * Retrieves an array of all template packs.
308
-     * Array is in the format array( 'dbref' => EE_Messages_Template_Pack )
309
-     *
310
-     * @deprecated 4.9.0  @see EEH_MSG_Template_Pack::get_template_pack_collection
311
-     * @return EE_Messages_Template_Pack[]
312
-     */
313
-    public static function get_template_packs()
314
-    {
315
-        EE_Registry::instance()->load_helper('MSG_Template');
316
-
317
-        //for backward compat, let's make sure this returns in the same format as originally.
318
-        $template_pack_collection = EEH_MSG_Template::get_template_pack_collection();
319
-        $template_pack_collection->rewind();
320
-        $template_packs = array();
321
-        while ($template_pack_collection->valid()) {
322
-            $template_packs[$template_pack_collection->current()->dbref] = $template_pack_collection->current();
323
-            $template_pack_collection->next();
324
-        }
325
-        return $template_packs;
326
-    }
327
-
328
-
329
-    /**
330
-     * This simply makes sure the autoloaders are registered for the EE_messages system.
331
-     *
332
-     * @since 4.5.0
333
-     * @return void
334
-     */
335
-    public static function set_autoloaders()
336
-    {
337
-        if (empty(self::$_MSG_PATHS)) {
338
-            self::_set_messages_paths();
339
-            foreach (self::$_MSG_PATHS as $path) {
340
-                EEH_Autoloader::register_autoloaders_for_each_file_in_folder($path);
341
-            }
342
-            // add aliases
343
-            EEH_Autoloader::add_alias('EE_messages', 'EE_messages');
344
-            EEH_Autoloader::add_alias('EE_messenger', 'EE_messenger');
345
-        }
346
-    }
347
-
348
-
349
-    /**
350
-     * Take care of adding all the paths for the messages components to the $_MSG_PATHS property
351
-     * for use by the Messages Autoloaders
352
-     *
353
-     * @since 4.5.0
354
-     * @return void.
355
-     */
356
-    protected static function _set_messages_paths()
357
-    {
358
-        $dir_ref = array(
359
-            'messages/message_type',
360
-            'messages/messenger',
361
-            'messages/defaults',
362
-            'messages/defaults/email',
363
-            'messages/data_class',
364
-            'messages/validators',
365
-            'messages/validators/email',
366
-            'messages/validators/html',
367
-            'shortcodes',
368
-        );
369
-        $paths   = array();
370
-        foreach ($dir_ref as $index => $dir) {
371
-            $paths[$index] = EE_LIBRARIES . $dir;
372
-        }
373
-        self::$_MSG_PATHS = apply_filters('FHEE__EED_Messages___set_messages_paths___MSG_PATHS', $paths);
374
-    }
375
-
376
-
377
-    /**
378
-     * Takes care of loading dependencies
379
-     *
380
-     * @since 4.5.0
381
-     * @return void
382
-     */
383
-    protected static function _load_controller()
384
-    {
385
-        if (! self::$_MSG_PROCESSOR instanceof EE_Messages_Processor) {
386
-            EE_Registry::instance()->load_core('Request_Handler');
387
-            self::set_autoloaders();
388
-            self::$_EEMSG                    = EE_Registry::instance()->load_lib('messages');
389
-            self::$_MSG_PROCESSOR            = EE_Registry::instance()->load_lib('Messages_Processor');
390
-            self::$_message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
391
-        }
392
-    }
393
-
394
-
395
-    /**
396
-     * @param EE_Transaction $transaction
397
-     */
398
-    public static function payment_reminder(EE_Transaction $transaction)
399
-    {
400
-        self::_load_controller();
401
-        $data = array($transaction, null);
402
-        self::$_MSG_PROCESSOR->generate_for_all_active_messengers('payment_reminder', $data);
403
-    }
404
-
405
-
406
-    /**
407
-     * Any messages triggers for after successful gateway payments should go in here.
408
-     *
409
-     * @param  EE_Transaction object
410
-     * @param  EE_Payment     object
411
-     * @return void
412
-     */
413
-    public static function payment(EE_Transaction $transaction, EE_Payment $payment)
414
-    {
415
-        self::_load_controller();
416
-        $data = array($transaction, $payment);
417
-        EE_Registry::instance()->load_helper('MSG_Template');
418
-        $message_type = EEH_MSG_Template::convert_payment_status_to_message_type($payment->STS_ID());
419
-        //if payment amount is less than 0 then switch to payment_refund message type.
420
-        $message_type = $payment->amount() < 0 ? 'payment_refund' : $message_type;
421
-        self::$_MSG_PROCESSOR->generate_for_all_active_messengers($message_type, $data);
422
-    }
423
-
424
-
425
-    /**
426
-     * @param EE_Transaction $transaction
427
-     */
428
-    public static function cancelled_registration(EE_Transaction $transaction)
429
-    {
430
-        self::_load_controller();
431
-        $data = array($transaction, null);
432
-        self::$_MSG_PROCESSOR->generate_for_all_active_messengers('cancelled_registration', $data);
433
-    }
434
-
435
-
436
-    /**
437
-     * Trigger for Registration messages
438
-     * Note that what registration message type is sent depends on what the reg status is for the registrations on the
439
-     * incoming transaction.
440
-     *
441
-     * @param EE_Registration $registration
442
-     * @param array           $extra_details
443
-     * @return void
444
-     */
445
-    public static function maybe_registration(EE_Registration $registration, $extra_details = array())
446
-    {
447
-
448
-        if (! self::_verify_registration_notification_send($registration, $extra_details)) {
449
-            //no messages please
450
-            return;
451
-        }
452
-
453
-
454
-        //get all registrations so we make sure we send messages for the right status.
455
-        $all_registrations = $registration->transaction()->registrations();
456
-
457
-        //cached array of statuses so we only trigger messages once per status.
458
-        $statuses_sent = array();
459
-        self::_load_controller();
460
-        $mtgs = array();
461
-
462
-        //loop through registrations and trigger messages once per status.
463
-        foreach ($all_registrations as $reg) {
464
-
465
-            //already triggered?
466
-            if (in_array($reg->status_ID(), $statuses_sent)) {
467
-                continue;
468
-            }
469
-
470
-            $message_type    = EEH_MSG_Template::convert_reg_status_to_message_type($reg->status_ID());
471
-            $mtgs            = array_merge(
472
-                    $mtgs,
473
-                    self::$_MSG_PROCESSOR->setup_mtgs_for_all_active_messengers(
474
-                            $message_type,
475
-                            array($registration->transaction(), null, $reg->status_ID())
476
-                    )
477
-            );
478
-            $statuses_sent[] = $reg->status_ID();
479
-        }
480
-
481
-        if (count($statuses_sent) > 1) {
482
-            $mtgs = array_merge(
483
-                $mtgs,
484
-                self::$_MSG_PROCESSOR->setup_mtgs_for_all_active_messengers(
485
-                    'registration_summary',
486
-                    array($registration->transaction(), null)
487
-                )
488
-            );
489
-        }
490
-
491
-        //batch queue and initiate request
492
-        self::$_MSG_PROCESSOR->batch_queue_for_generation_and_persist($mtgs);
493
-        self::$_MSG_PROCESSOR->get_queue()->initiate_request_by_priority();
494
-    }
495
-
496
-
497
-    /**
498
-     * This is a helper method used to very whether a registration notification should be sent or
499
-     * not.  Prevents duplicate notifications going out for registration context notifications.
500
-     *
501
-     * @param EE_Registration $registration  [description]
502
-     * @param array           $extra_details [description]
503
-     * @return bool          true = send away, false = nope halt the presses.
504
-     */
505
-    protected static function _verify_registration_notification_send(
506
-        EE_Registration $registration,
507
-        $extra_details = array()
508
-    ) {
509
-        //self::log(
510
-        //	__CLASS__, __FUNCTION__, __LINE__,
511
-        //	$registration->transaction(),
512
-        //	array( '$extra_details' => $extra_details )
513
-        //);
514
-        // currently only using this to send messages for the primary registrant
515
-        if (! $registration->is_primary_registrant()) {
516
-            return false;
517
-        }
518
-        // first we check if we're in admin and not doing front ajax
519
-        if (is_admin() && ! EE_FRONT_AJAX) {
520
-            //make sure appropriate admin params are set for sending messages
521
-            if (empty($_REQUEST['txn_reg_status_change']['send_notifications']) || ! absint($_REQUEST['txn_reg_status_change']['send_notifications'])) {
522
-                //no messages sent please.
523
-                return false;
524
-            }
525
-        } else {
526
-            // frontend request (either regular or via AJAX)
527
-            // TXN is NOT finalized ?
528
-            if (! isset($extra_details['finalized']) || $extra_details['finalized'] === false) {
529
-                return false;
530
-            }
531
-            // return visit but nothing changed ???
532
-            if (
533
-                isset($extra_details['revisit'], $extra_details['status_updates']) &&
534
-                $extra_details['revisit'] && ! $extra_details['status_updates']
535
-            ) {
536
-                return false;
537
-            }
538
-            // NOT sending messages && reg status is something other than "Not-Approved"
539
-            if (
540
-                ! apply_filters('FHEE__EED_Messages___maybe_registration__deliver_notifications', false) &&
541
-                $registration->status_ID() !== EEM_Registration::status_id_not_approved
542
-            ) {
543
-                return false;
544
-            }
545
-        }
546
-        // release the kraken
547
-        return true;
548
-    }
549
-
550
-
551
-    /**
552
-     * Simply returns an array indexed by Registration Status ID and the related message_type name associated with that
553
-     * status id.
554
-     *
555
-     * @deprecated 4.9.0  Use EEH_MSG_Template::reg_status_to_message_type_array()
556
-     *                    or EEH_MSG_Template::convert_reg_status_to_message_type
557
-     * @param string $reg_status
558
-     * @return array
559
-     */
560
-    protected static function _get_reg_status_array($reg_status = '')
561
-    {
562
-        EE_Registry::instance()->load_helper('MSG_Template');
563
-        return EEH_MSG_Template::convert_reg_status_to_message_type($reg_status)
564
-            ? EEH_MSG_Template::convert_reg_status_to_message_type($reg_status)
565
-            : EEH_MSG_Template::reg_status_to_message_type_array();
566
-    }
567
-
568
-
569
-    /**
570
-     * Simply returns the payment message type for the given payment status.
571
-     *
572
-     * @deprecated 4.9.0 Use EEH_MSG_Template::payment_status_to_message_type_array
573
-     *                   or EEH_MSG_Template::convert_payment_status_to_message_type
574
-     * @param string $payment_status The payment status being matched.
575
-     * @return string|bool The payment message type slug matching the status or false if no match.
576
-     */
577
-    protected static function _get_payment_message_type($payment_status)
578
-    {
579
-        EE_Registry::instance()->load_helper('MSG_Template');
580
-        return EEH_MSG_Template::convert_payment_status_to_message_type($payment_status)
581
-            ? EEH_MSG_Template::convert_payment_status_to_message_type($payment_status)
582
-            : false;
583
-    }
584
-
585
-
586
-    /**
587
-     * Message triggers for a resending already sent message(s) (via EE_Message list table)
588
-     *
589
-     * @access public
590
-     * @param array $req_data This is the $_POST & $_GET data sent from EE_Admin Pages
591
-     * @return bool          success/fail
592
-     */
593
-    public static function process_resend($req_data)
594
-    {
595
-        self::_load_controller();
596
-
597
-        //if $msgID in this request then skip to the new resend_message
598
-        if (EE_Registry::instance()->REQ->get('MSG_ID')) {
599
-            return self::resend_message();
600
-        }
601
-
602
-        //make sure any incoming request data is set on the REQ so that it gets picked up later.
603
-        $req_data = (array)$req_data;
604
-        foreach ($req_data as $request_key => $request_value) {
605
-            EE_Registry::instance()->REQ->set($request_key, $request_value);
606
-        }
607
-
608
-        if (! $messages_to_send = self::$_MSG_PROCESSOR->setup_messages_to_generate_from_registration_ids_in_request()) {
609
-            return false;
610
-        }
611
-
612
-        try {
613
-            self::$_MSG_PROCESSOR->batch_queue_for_generation_and_persist($messages_to_send);
614
-            self::$_MSG_PROCESSOR->get_queue()->initiate_request_by_priority();
615
-        } catch (EE_Error $e) {
616
-            EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
617
-            return false;
618
-        }
619
-        EE_Error::add_success(
620
-            __('Messages have been successfully queued for generation and sending.', 'event_espresso')
621
-        );
622
-        return true; //everything got queued.
623
-    }
624
-
625
-
626
-    /**
627
-     * Message triggers for a resending already sent message(s) (via EE_Message list table)
628
-     *
629
-     * @return bool
630
-     */
631
-    public static function resend_message()
632
-    {
633
-        self::_load_controller();
634
-
635
-        $msgID = EE_Registry::instance()->REQ->get('MSG_ID');
636
-        if (! $msgID) {
637
-            EE_Error::add_error(__('Something went wrong because there is no "MSG_ID" value in the request',
638
-                'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
639
-            return false;
640
-        }
641
-
642
-        self::$_MSG_PROCESSOR->setup_messages_from_ids_and_send((array)$msgID);
643
-
644
-        //setup success message.
645
-        $count_ready_for_resend = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::status_resend);
646
-        EE_Error::add_success(sprintf(
647
-            _n(
648
-                'There was %d message queued for resending.',
649
-                'There were %d messages queued for resending.',
650
-                $count_ready_for_resend,
651
-                'event_espresso'
652
-            ),
653
-            $count_ready_for_resend
654
-        ));
655
-        return true;
656
-    }
657
-
658
-
659
-    /**
660
-     * Message triggers for manual payment applied by admin
661
-     *
662
-     * @param  EE_Payment $payment EE_payment object
663
-     * @return bool              success/fail
664
-     */
665
-    public static function process_admin_payment(EE_Payment $payment)
666
-    {
667
-        EE_Registry::instance()->load_helper('MSG_Template');
668
-        //we need to get the transaction object
669
-        $transaction = $payment->transaction();
670
-        if ($transaction instanceof EE_Transaction) {
671
-            $data         = array($transaction, $payment);
672
-            $message_type = EEH_MSG_Template::convert_payment_status_to_message_type($payment->STS_ID());
673
-
674
-            //if payment amount is less than 0 then switch to payment_refund message type.
675
-            $message_type = $payment->amount() < 0 ? 'payment_refund' : $message_type;
676
-
677
-            //if payment_refund is selected, but the status is NOT accepted.  Then change message type to false so NO message notification goes out.
678
-            $message_type = $message_type == 'payment_refund' && $payment->STS_ID() != EEM_Payment::status_id_approved ? false : $message_type;
679
-
680
-            self::_load_controller();
681
-
682
-            self::$_MSG_PROCESSOR->generate_for_all_active_messengers($message_type, $data);
683
-
684
-            //get count of queued for generation
685
-            $count_to_generate = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(array(
686
-                EEM_Message::status_incomplete,
687
-                EEM_Message::status_idle,
688
-            ));
689
-
690
-            if ($count_to_generate > 0 && self::$_MSG_PROCESSOR->get_queue()->get_message_repository()->count() !== 0) {
691
-                add_filter('FHEE__EE_Admin_Page___process_admin_payment_notification__success', '__return_true');
692
-                return true;
693
-            } else {
694
-                $count_failed = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::instance()->stati_indicating_failed_sending());
695
-                /**
696
-                 * Verify that there are actually errors.  If not then we return a success message because the queue might have been emptied due to successful
697
-                 * IMMEDIATE generation.
698
-                 */
699
-                if ($count_failed > 0) {
700
-                    EE_Error::add_error(sprintf(
701
-                        _n(
702
-                            'The payment notification generation failed.',
703
-                            '%d payment notifications failed being sent.',
704
-                            $count_failed,
705
-                            'event_espresso'
706
-                        ),
707
-                        $count_failed
708
-                    ), __FILE__, __FUNCTION__, __LINE__);
709
-
710
-                    return false;
711
-                } else {
712
-                    add_filter('FHEE__EE_Admin_Page___process_admin_payment_notification__success', '__return_true');
713
-                    return true;
714
-                }
715
-            }
716
-        } else {
717
-            EE_Error::add_error(
718
-                'Unable to generate the payment notification because the given value for the transaction is invalid.',
719
-                'event_espresso'
720
-            );
721
-            return false;
722
-        }
723
-    }
724
-
725
-
726
-    /**
727
-     * Callback for AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send_with_registrations trigger
728
-     *
729
-     * @since   4.3.0
730
-     * @param  EE_Registration[] $registrations an array of EE_Registration objects
731
-     * @param  int               $grp_id        a specific message template group id.
732
-     * @return void
733
-     */
734
-    public static function send_newsletter_message($registrations, $grp_id)
735
-    {
736
-        //make sure mtp is id and set it in the EE_Request Handler later messages setup.
737
-        EE_Registry::instance()->REQ->set('GRP_ID', (int)$grp_id);
738
-        self::_load_controller();
739
-        self::$_MSG_PROCESSOR->generate_for_all_active_messengers('newsletter', $registrations);
740
-    }
741
-
742
-
743
-    /**
744
-     * Callback for FHEE__EE_Registration__invoice_url__invoice_url or FHEE__EE_Registration__receipt_url__receipt_url
745
-     *
746
-     * @since   4.3.0
747
-     * @param    string          $registration_message_trigger_url
748
-     * @param    EE_Registration $registration
749
-     * @param string             $messenger
750
-     * @param string             $message_type
751
-     * @return    string
752
-     */
753
-    public static function registration_message_trigger_url(
754
-        $registration_message_trigger_url,
755
-        EE_Registration $registration,
756
-        $messenger = 'html',
757
-        $message_type = 'invoice'
758
-    ) {
759
-        // whitelist $messenger
760
-        switch ($messenger) {
761
-            case 'pdf' :
762
-                $sending_messenger    = 'pdf';
763
-                $generating_messenger = 'html';
764
-                break;
765
-            case 'html' :
766
-            default :
767
-                $sending_messenger    = 'html';
768
-                $generating_messenger = 'html';
769
-                break;
770
-        }
771
-        // whitelist $message_type
772
-        switch ($message_type) {
773
-            case 'receipt' :
774
-                $message_type = 'receipt';
775
-                break;
776
-            case 'invoice' :
777
-            default :
778
-                $message_type = 'invoice';
779
-                break;
780
-        }
781
-        // verify that both the messenger AND the message type are active
782
-        if (EEH_MSG_Template::is_messenger_active($sending_messenger) && EEH_MSG_Template::is_mt_active($message_type)) {
783
-            //need to get the correct message template group for this (i.e. is there a custom invoice for the event this registration is registered for?)
784
-            $template_query_params = array(
785
-                'MTP_is_active'    => true,
786
-                'MTP_messenger'    => $generating_messenger,
787
-                'MTP_message_type' => $message_type,
788
-                'Event.EVT_ID'     => $registration->event_ID(),
789
-            );
790
-            //get the message template group.
791
-            $msg_template_group = EEM_Message_Template_Group::instance()->get_one(array($template_query_params));
792
-            //if we don't have an EE_Message_Template_Group then return
793
-            if (! $msg_template_group instanceof EE_Message_Template_Group) {
794
-                // remove EVT_ID from query params so that global templates get picked up
795
-                unset($template_query_params['Event.EVT_ID']);
796
-                //get global template as the fallback
797
-                $msg_template_group = EEM_Message_Template_Group::instance()->get_one(array($template_query_params));
798
-            }
799
-            //if we don't have an EE_Message_Template_Group then return
800
-            if (! $msg_template_group instanceof EE_Message_Template_Group) {
801
-                return '';
802
-            }
803
-            // generate the URL
804
-            $registration_message_trigger_url = EEH_MSG_Template::generate_url_trigger(
805
-                $sending_messenger,
806
-                $generating_messenger,
807
-                'purchaser',
808
-                $message_type,
809
-                $registration,
810
-                $msg_template_group->ID(),
811
-                $registration->transaction_ID()
812
-            );
813
-
814
-        }
815
-        return $registration_message_trigger_url;
816
-    }
817
-
818
-
819
-    /**
820
-     * Use to generate and return a message preview!
821
-     *
822
-     * @param  string $type      This should correspond with a valid message type
823
-     * @param  string $context   This should correspond with a valid context for the message type
824
-     * @param  string $messenger This should correspond with a valid messenger.
825
-     * @param bool    $send      true we will do a test send using the messenger delivery, false we just do a regular
826
-     *                           preview
827
-     * @return bool|string The body of the message or if send is requested, sends.
828
-     * @throws EE_Error
829
-     */
830
-    public static function preview_message($type, $context, $messenger, $send = false)
831
-    {
832
-        self::_load_controller();
833
-        $mtg                     = new EE_Message_To_Generate(
834
-            $messenger,
835
-            $type,
836
-            array(),
837
-            $context,
838
-            true
839
-        );
840
-        $generated_preview_queue = self::$_MSG_PROCESSOR->generate_for_preview($mtg, $send);
841
-        if ($generated_preview_queue instanceof EE_Messages_Queue) {
842
-            $content = $generated_preview_queue->get_message_repository()->current()->content();
843
-            //if the current message was persisted to the db (which will happen with any extra fields on a message) then
844
-            //let's delete it because we don't need previews cluttering up the db.
845
-            if ($generated_preview_queue->get_message_repository()->current()->ID() > 0
846
-                && $generated_preview_queue->get_message_repository()->current()->STS_ID() !== EEM_Message::status_failed
847
-            ) {
848
-                $generated_preview_queue->get_message_repository()->delete();
849
-            }
850
-            return $content;
851
-        } else {
852
-            return $generated_preview_queue;
853
-        }
854
-    }
855
-
856
-
857
-    /**
858
-     * This is a method that allows for sending a message using a messenger matching the string given and the provided
859
-     * EE_Message_Queue object.  The EE_Message_Queue object is used to create a single aggregate EE_Message via the
860
-     * content found in the EE_Message objects in the queue.
861
-     *
862
-     * @since 4.9.0
863
-     * @param string            $messenger            a string matching a valid active messenger in the system
864
-     * @param string            $message_type         Although it seems contrary to the name of the method, a message
865
-     *                                                type name is still required to send along the message type to the
866
-     *                                                messenger because this is used for determining what specific
867
-     *                                                variations might be loaded for the generated message.
868
-     * @param EE_Messages_Queue $queue
869
-     * @param string            $custom_subject       Can be used to set what the custom subject string will be on the
870
-     *                                                aggregate EE_Message object.
871
-     * @return bool          success or fail.
872
-     */
873
-    public static function send_message_with_messenger_only(
874
-        $messenger,
875
-        $message_type,
876
-        EE_Messages_Queue $queue,
877
-        $custom_subject = ''
878
-    ) {
879
-        self::_load_controller();
880
-        /** @type EE_Message_To_Generate_From_Queue $message_to_generate */
881
-        $message_to_generate = EE_Registry::instance()->load_lib(
882
-            'Message_To_Generate_From_Queue',
883
-            array(
884
-                $messenger,
885
-                $message_type,
886
-                $queue,
887
-                $custom_subject,
888
-            )
889
-        );
890
-        return self::$_MSG_PROCESSOR->queue_for_sending($message_to_generate);
891
-    }
892
-
893
-
894
-    /**
895
-     * Generates Messages immediately for EE_Message IDs (but only for the correct status for generation)
896
-     *
897
-     * @since 4.9.0
898
-     * @param array $message_ids An array of message ids
899
-     * @return bool | EE_Messages_Queue     false if nothing was generated, EE_Messages_Queue containing generated
900
-     *              messages.
901
-     */
902
-    public static function generate_now($message_ids)
903
-    {
904
-        self::_load_controller();
905
-        $messages        = EEM_Message::instance()->get_all(
906
-            array(
907
-                0 => array(
908
-                    'MSG_ID' => array('IN', $message_ids),
909
-                    'STS_ID' => EEM_Message::status_incomplete,
910
-                ),
911
-            )
912
-        );
913
-        $generated_queue = false;
914
-        if ($messages) {
915
-            $generated_queue = self::$_MSG_PROCESSOR->batch_generate_from_queue($messages);
916
-        }
917
-
918
-        if (! $generated_queue instanceof EE_Messages_Queue) {
919
-            EE_Error::add_error(
920
-                __('The messages were not generated. This could mean there is already a batch being generated on a separate request, or because the selected messages are not ready for generation. Please wait a minute or two and try again.',
921
-                    'event_espresso'),
922
-                __FILE__, __FUNCTION__, __LINE__
923
-            );
924
-        }
925
-        return $generated_queue;
926
-    }
927
-
928
-
929
-    /**
930
-     * Sends messages immediately for the incoming message_ids that have the status of EEM_Message::status_resend or,
931
-     * EEM_Message::status_idle
932
-     *
933
-     * @since 4.9.0
934
-     * @param $message_ids
935
-     * @return bool | EE_Messages_Queue  false if no messages sent.
936
-     */
937
-    public static function send_now($message_ids)
938
-    {
939
-        self::_load_controller();
940
-        $messages   = EEM_Message::instance()->get_all(
941
-            array(
942
-                0 => array(
943
-                    'MSG_ID' => array('IN', $message_ids),
944
-                    'STS_ID' => array(
945
-                        'IN',
946
-                        array(EEM_Message::status_idle, EEM_Message::status_resend, EEM_Message::status_retry),
947
-                    ),
948
-                ),
949
-            )
950
-        );
951
-        $sent_queue = false;
952
-        if ($messages) {
953
-            $sent_queue = self::$_MSG_PROCESSOR->batch_send_from_queue($messages);
954
-        }
955
-
956
-        if (! $sent_queue instanceof EE_Messages_Queue) {
957
-            EE_Error::add_error(
958
-                __('The messages were not sent. This could mean there is already a batch being sent on a separate request, or because the selected messages are not sendable. Please wait a minute or two and try again.',
959
-                    'event_espresso'),
960
-                __FILE__, __FUNCTION__, __LINE__
961
-            );
962
-        } else {
963
-            //can count how many sent by using the messages in the queue
964
-            $sent_count = $sent_queue->count_STS_in_queue(EEM_Message::instance()->stati_indicating_sent());
965
-            if ($sent_count > 0) {
966
-                EE_Error::add_success(
967
-                    sprintf(
968
-                        _n(
969
-                            'There was %d message successfully sent.',
970
-                            'There were %d messages successfully sent.',
971
-                            $sent_count,
972
-                            'event_espresso'
973
-                        ),
974
-                        $sent_count
975
-                    )
976
-                );
977
-            } else {
978
-                EE_Error::overwrite_errors();
979
-                EE_Error::add_error(
980
-                    __('No message was sent because of problems with sending. Either all the messages you selected were not a sendable message, they were ALREADY sent on a different scheduled task, or there was an error.
201
+				exit;
202
+			}
203
+		}
204
+		return;
205
+	}
206
+
207
+
208
+	/**
209
+	 *  This runs when the msg_url_trigger route has initiated.
210
+	 *
211
+	 * @since 4.5.0
212
+	 * @param WP $WP
213
+	 * @throws EE_Error
214
+	 * @return    void
215
+	 */
216
+	public function run($WP)
217
+	{
218
+		//ensure controller is loaded
219
+		self::_load_controller();
220
+		// attempt to process message
221
+		try {
222
+			/** @type EE_Message_To_Generate_From_Request $message_to_generate */
223
+			$message_to_generate = EE_Registry::instance()->load_lib('Message_To_Generate_From_Request');
224
+			self::$_MSG_PROCESSOR->generate_and_send_now($message_to_generate);
225
+		} catch (EE_Error $e) {
226
+			$error_msg = __('Please note that a system message failed to send due to a technical issue.',
227
+				'event_espresso');
228
+			// add specific message for developers if WP_DEBUG in on
229
+			$error_msg .= '||' . $e->getMessage();
230
+			EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__);
231
+		}
232
+	}
233
+
234
+
235
+	/**
236
+	 * This is triggered by the 'msg_cron_trigger' route.
237
+	 *
238
+	 * @param WP $WP
239
+	 */
240
+	public function execute_batch_request($WP)
241
+	{
242
+		$this->run_cron();
243
+		header('HTTP/1.1 200 OK');
244
+		exit();
245
+	}
246
+
247
+
248
+	/**
249
+	 * This gets executed on wp_cron jobs or when a batch request is initiated on its own separate non regular wp
250
+	 * request.
251
+	 */
252
+	public function run_cron()
253
+	{
254
+		self::_load_controller();
255
+		//get required vars
256
+		$cron_type     = EE_Registry::instance()->REQ->get('type');
257
+		$transient_key = EE_Registry::instance()->REQ->get('key');
258
+
259
+		//now let's verify transient, if not valid exit immediately
260
+		if (! get_transient($transient_key)) {
261
+			/**
262
+			 * trigger error so this gets in the error logs.  This is important because it happens on a non-user request.
263
+			 */
264
+			trigger_error(esc_attr__('Invalid Request (Transient does not exist)', 'event_espresso'));
265
+		}
266
+
267
+		//if made it here, lets' delete the transient to keep the db clean
268
+		delete_transient($transient_key);
269
+
270
+		if (apply_filters('FHEE__EED_Messages__run_cron__use_wp_cron', true)) {
271
+
272
+			$method = 'batch_' . $cron_type . '_from_queue';
273
+			if (method_exists(self::$_MSG_PROCESSOR, $method)) {
274
+				self::$_MSG_PROCESSOR->$method();
275
+			} else {
276
+				//no matching task
277
+				/**
278
+				 * trigger error so this gets in the error logs.  This is important because it happens on a non user request.
279
+				 */
280
+				trigger_error(esc_attr(sprintf(__('There is no task corresponding to this route %s', 'event_espresso'),
281
+					$cron_type)));
282
+			}
283
+		}
284
+
285
+		do_action('FHEE__EED_Messages__run_cron__end');
286
+	}
287
+
288
+
289
+	/**
290
+	 * This is used to retrieve the template pack for the given name.
291
+	 * Retrieved packs are cached on the static $_TMP_PACKS array.  If there is no class matching the given name then
292
+	 * the default template pack is returned.
293
+	 *
294
+	 * @deprecated 4.9.0  @see EEH_MSG_Template::get_template_pack()
295
+	 * @param string $template_pack_name This should correspond to the dbref of the template pack (which is also used
296
+	 *                                   in generating the Pack class name).
297
+	 * @return EE_Messages_Template_Pack
298
+	 */
299
+	public static function get_template_pack($template_pack_name)
300
+	{
301
+		EE_Registry::instance()->load_helper('MSG_Template');
302
+		return EEH_MSG_Template::get_template_pack($template_pack_name);
303
+	}
304
+
305
+
306
+	/**
307
+	 * Retrieves an array of all template packs.
308
+	 * Array is in the format array( 'dbref' => EE_Messages_Template_Pack )
309
+	 *
310
+	 * @deprecated 4.9.0  @see EEH_MSG_Template_Pack::get_template_pack_collection
311
+	 * @return EE_Messages_Template_Pack[]
312
+	 */
313
+	public static function get_template_packs()
314
+	{
315
+		EE_Registry::instance()->load_helper('MSG_Template');
316
+
317
+		//for backward compat, let's make sure this returns in the same format as originally.
318
+		$template_pack_collection = EEH_MSG_Template::get_template_pack_collection();
319
+		$template_pack_collection->rewind();
320
+		$template_packs = array();
321
+		while ($template_pack_collection->valid()) {
322
+			$template_packs[$template_pack_collection->current()->dbref] = $template_pack_collection->current();
323
+			$template_pack_collection->next();
324
+		}
325
+		return $template_packs;
326
+	}
327
+
328
+
329
+	/**
330
+	 * This simply makes sure the autoloaders are registered for the EE_messages system.
331
+	 *
332
+	 * @since 4.5.0
333
+	 * @return void
334
+	 */
335
+	public static function set_autoloaders()
336
+	{
337
+		if (empty(self::$_MSG_PATHS)) {
338
+			self::_set_messages_paths();
339
+			foreach (self::$_MSG_PATHS as $path) {
340
+				EEH_Autoloader::register_autoloaders_for_each_file_in_folder($path);
341
+			}
342
+			// add aliases
343
+			EEH_Autoloader::add_alias('EE_messages', 'EE_messages');
344
+			EEH_Autoloader::add_alias('EE_messenger', 'EE_messenger');
345
+		}
346
+	}
347
+
348
+
349
+	/**
350
+	 * Take care of adding all the paths for the messages components to the $_MSG_PATHS property
351
+	 * for use by the Messages Autoloaders
352
+	 *
353
+	 * @since 4.5.0
354
+	 * @return void.
355
+	 */
356
+	protected static function _set_messages_paths()
357
+	{
358
+		$dir_ref = array(
359
+			'messages/message_type',
360
+			'messages/messenger',
361
+			'messages/defaults',
362
+			'messages/defaults/email',
363
+			'messages/data_class',
364
+			'messages/validators',
365
+			'messages/validators/email',
366
+			'messages/validators/html',
367
+			'shortcodes',
368
+		);
369
+		$paths   = array();
370
+		foreach ($dir_ref as $index => $dir) {
371
+			$paths[$index] = EE_LIBRARIES . $dir;
372
+		}
373
+		self::$_MSG_PATHS = apply_filters('FHEE__EED_Messages___set_messages_paths___MSG_PATHS', $paths);
374
+	}
375
+
376
+
377
+	/**
378
+	 * Takes care of loading dependencies
379
+	 *
380
+	 * @since 4.5.0
381
+	 * @return void
382
+	 */
383
+	protected static function _load_controller()
384
+	{
385
+		if (! self::$_MSG_PROCESSOR instanceof EE_Messages_Processor) {
386
+			EE_Registry::instance()->load_core('Request_Handler');
387
+			self::set_autoloaders();
388
+			self::$_EEMSG                    = EE_Registry::instance()->load_lib('messages');
389
+			self::$_MSG_PROCESSOR            = EE_Registry::instance()->load_lib('Messages_Processor');
390
+			self::$_message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
391
+		}
392
+	}
393
+
394
+
395
+	/**
396
+	 * @param EE_Transaction $transaction
397
+	 */
398
+	public static function payment_reminder(EE_Transaction $transaction)
399
+	{
400
+		self::_load_controller();
401
+		$data = array($transaction, null);
402
+		self::$_MSG_PROCESSOR->generate_for_all_active_messengers('payment_reminder', $data);
403
+	}
404
+
405
+
406
+	/**
407
+	 * Any messages triggers for after successful gateway payments should go in here.
408
+	 *
409
+	 * @param  EE_Transaction object
410
+	 * @param  EE_Payment     object
411
+	 * @return void
412
+	 */
413
+	public static function payment(EE_Transaction $transaction, EE_Payment $payment)
414
+	{
415
+		self::_load_controller();
416
+		$data = array($transaction, $payment);
417
+		EE_Registry::instance()->load_helper('MSG_Template');
418
+		$message_type = EEH_MSG_Template::convert_payment_status_to_message_type($payment->STS_ID());
419
+		//if payment amount is less than 0 then switch to payment_refund message type.
420
+		$message_type = $payment->amount() < 0 ? 'payment_refund' : $message_type;
421
+		self::$_MSG_PROCESSOR->generate_for_all_active_messengers($message_type, $data);
422
+	}
423
+
424
+
425
+	/**
426
+	 * @param EE_Transaction $transaction
427
+	 */
428
+	public static function cancelled_registration(EE_Transaction $transaction)
429
+	{
430
+		self::_load_controller();
431
+		$data = array($transaction, null);
432
+		self::$_MSG_PROCESSOR->generate_for_all_active_messengers('cancelled_registration', $data);
433
+	}
434
+
435
+
436
+	/**
437
+	 * Trigger for Registration messages
438
+	 * Note that what registration message type is sent depends on what the reg status is for the registrations on the
439
+	 * incoming transaction.
440
+	 *
441
+	 * @param EE_Registration $registration
442
+	 * @param array           $extra_details
443
+	 * @return void
444
+	 */
445
+	public static function maybe_registration(EE_Registration $registration, $extra_details = array())
446
+	{
447
+
448
+		if (! self::_verify_registration_notification_send($registration, $extra_details)) {
449
+			//no messages please
450
+			return;
451
+		}
452
+
453
+
454
+		//get all registrations so we make sure we send messages for the right status.
455
+		$all_registrations = $registration->transaction()->registrations();
456
+
457
+		//cached array of statuses so we only trigger messages once per status.
458
+		$statuses_sent = array();
459
+		self::_load_controller();
460
+		$mtgs = array();
461
+
462
+		//loop through registrations and trigger messages once per status.
463
+		foreach ($all_registrations as $reg) {
464
+
465
+			//already triggered?
466
+			if (in_array($reg->status_ID(), $statuses_sent)) {
467
+				continue;
468
+			}
469
+
470
+			$message_type    = EEH_MSG_Template::convert_reg_status_to_message_type($reg->status_ID());
471
+			$mtgs            = array_merge(
472
+					$mtgs,
473
+					self::$_MSG_PROCESSOR->setup_mtgs_for_all_active_messengers(
474
+							$message_type,
475
+							array($registration->transaction(), null, $reg->status_ID())
476
+					)
477
+			);
478
+			$statuses_sent[] = $reg->status_ID();
479
+		}
480
+
481
+		if (count($statuses_sent) > 1) {
482
+			$mtgs = array_merge(
483
+				$mtgs,
484
+				self::$_MSG_PROCESSOR->setup_mtgs_for_all_active_messengers(
485
+					'registration_summary',
486
+					array($registration->transaction(), null)
487
+				)
488
+			);
489
+		}
490
+
491
+		//batch queue and initiate request
492
+		self::$_MSG_PROCESSOR->batch_queue_for_generation_and_persist($mtgs);
493
+		self::$_MSG_PROCESSOR->get_queue()->initiate_request_by_priority();
494
+	}
495
+
496
+
497
+	/**
498
+	 * This is a helper method used to very whether a registration notification should be sent or
499
+	 * not.  Prevents duplicate notifications going out for registration context notifications.
500
+	 *
501
+	 * @param EE_Registration $registration  [description]
502
+	 * @param array           $extra_details [description]
503
+	 * @return bool          true = send away, false = nope halt the presses.
504
+	 */
505
+	protected static function _verify_registration_notification_send(
506
+		EE_Registration $registration,
507
+		$extra_details = array()
508
+	) {
509
+		//self::log(
510
+		//	__CLASS__, __FUNCTION__, __LINE__,
511
+		//	$registration->transaction(),
512
+		//	array( '$extra_details' => $extra_details )
513
+		//);
514
+		// currently only using this to send messages for the primary registrant
515
+		if (! $registration->is_primary_registrant()) {
516
+			return false;
517
+		}
518
+		// first we check if we're in admin and not doing front ajax
519
+		if (is_admin() && ! EE_FRONT_AJAX) {
520
+			//make sure appropriate admin params are set for sending messages
521
+			if (empty($_REQUEST['txn_reg_status_change']['send_notifications']) || ! absint($_REQUEST['txn_reg_status_change']['send_notifications'])) {
522
+				//no messages sent please.
523
+				return false;
524
+			}
525
+		} else {
526
+			// frontend request (either regular or via AJAX)
527
+			// TXN is NOT finalized ?
528
+			if (! isset($extra_details['finalized']) || $extra_details['finalized'] === false) {
529
+				return false;
530
+			}
531
+			// return visit but nothing changed ???
532
+			if (
533
+				isset($extra_details['revisit'], $extra_details['status_updates']) &&
534
+				$extra_details['revisit'] && ! $extra_details['status_updates']
535
+			) {
536
+				return false;
537
+			}
538
+			// NOT sending messages && reg status is something other than "Not-Approved"
539
+			if (
540
+				! apply_filters('FHEE__EED_Messages___maybe_registration__deliver_notifications', false) &&
541
+				$registration->status_ID() !== EEM_Registration::status_id_not_approved
542
+			) {
543
+				return false;
544
+			}
545
+		}
546
+		// release the kraken
547
+		return true;
548
+	}
549
+
550
+
551
+	/**
552
+	 * Simply returns an array indexed by Registration Status ID and the related message_type name associated with that
553
+	 * status id.
554
+	 *
555
+	 * @deprecated 4.9.0  Use EEH_MSG_Template::reg_status_to_message_type_array()
556
+	 *                    or EEH_MSG_Template::convert_reg_status_to_message_type
557
+	 * @param string $reg_status
558
+	 * @return array
559
+	 */
560
+	protected static function _get_reg_status_array($reg_status = '')
561
+	{
562
+		EE_Registry::instance()->load_helper('MSG_Template');
563
+		return EEH_MSG_Template::convert_reg_status_to_message_type($reg_status)
564
+			? EEH_MSG_Template::convert_reg_status_to_message_type($reg_status)
565
+			: EEH_MSG_Template::reg_status_to_message_type_array();
566
+	}
567
+
568
+
569
+	/**
570
+	 * Simply returns the payment message type for the given payment status.
571
+	 *
572
+	 * @deprecated 4.9.0 Use EEH_MSG_Template::payment_status_to_message_type_array
573
+	 *                   or EEH_MSG_Template::convert_payment_status_to_message_type
574
+	 * @param string $payment_status The payment status being matched.
575
+	 * @return string|bool The payment message type slug matching the status or false if no match.
576
+	 */
577
+	protected static function _get_payment_message_type($payment_status)
578
+	{
579
+		EE_Registry::instance()->load_helper('MSG_Template');
580
+		return EEH_MSG_Template::convert_payment_status_to_message_type($payment_status)
581
+			? EEH_MSG_Template::convert_payment_status_to_message_type($payment_status)
582
+			: false;
583
+	}
584
+
585
+
586
+	/**
587
+	 * Message triggers for a resending already sent message(s) (via EE_Message list table)
588
+	 *
589
+	 * @access public
590
+	 * @param array $req_data This is the $_POST & $_GET data sent from EE_Admin Pages
591
+	 * @return bool          success/fail
592
+	 */
593
+	public static function process_resend($req_data)
594
+	{
595
+		self::_load_controller();
596
+
597
+		//if $msgID in this request then skip to the new resend_message
598
+		if (EE_Registry::instance()->REQ->get('MSG_ID')) {
599
+			return self::resend_message();
600
+		}
601
+
602
+		//make sure any incoming request data is set on the REQ so that it gets picked up later.
603
+		$req_data = (array)$req_data;
604
+		foreach ($req_data as $request_key => $request_value) {
605
+			EE_Registry::instance()->REQ->set($request_key, $request_value);
606
+		}
607
+
608
+		if (! $messages_to_send = self::$_MSG_PROCESSOR->setup_messages_to_generate_from_registration_ids_in_request()) {
609
+			return false;
610
+		}
611
+
612
+		try {
613
+			self::$_MSG_PROCESSOR->batch_queue_for_generation_and_persist($messages_to_send);
614
+			self::$_MSG_PROCESSOR->get_queue()->initiate_request_by_priority();
615
+		} catch (EE_Error $e) {
616
+			EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
617
+			return false;
618
+		}
619
+		EE_Error::add_success(
620
+			__('Messages have been successfully queued for generation and sending.', 'event_espresso')
621
+		);
622
+		return true; //everything got queued.
623
+	}
624
+
625
+
626
+	/**
627
+	 * Message triggers for a resending already sent message(s) (via EE_Message list table)
628
+	 *
629
+	 * @return bool
630
+	 */
631
+	public static function resend_message()
632
+	{
633
+		self::_load_controller();
634
+
635
+		$msgID = EE_Registry::instance()->REQ->get('MSG_ID');
636
+		if (! $msgID) {
637
+			EE_Error::add_error(__('Something went wrong because there is no "MSG_ID" value in the request',
638
+				'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
639
+			return false;
640
+		}
641
+
642
+		self::$_MSG_PROCESSOR->setup_messages_from_ids_and_send((array)$msgID);
643
+
644
+		//setup success message.
645
+		$count_ready_for_resend = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::status_resend);
646
+		EE_Error::add_success(sprintf(
647
+			_n(
648
+				'There was %d message queued for resending.',
649
+				'There were %d messages queued for resending.',
650
+				$count_ready_for_resend,
651
+				'event_espresso'
652
+			),
653
+			$count_ready_for_resend
654
+		));
655
+		return true;
656
+	}
657
+
658
+
659
+	/**
660
+	 * Message triggers for manual payment applied by admin
661
+	 *
662
+	 * @param  EE_Payment $payment EE_payment object
663
+	 * @return bool              success/fail
664
+	 */
665
+	public static function process_admin_payment(EE_Payment $payment)
666
+	{
667
+		EE_Registry::instance()->load_helper('MSG_Template');
668
+		//we need to get the transaction object
669
+		$transaction = $payment->transaction();
670
+		if ($transaction instanceof EE_Transaction) {
671
+			$data         = array($transaction, $payment);
672
+			$message_type = EEH_MSG_Template::convert_payment_status_to_message_type($payment->STS_ID());
673
+
674
+			//if payment amount is less than 0 then switch to payment_refund message type.
675
+			$message_type = $payment->amount() < 0 ? 'payment_refund' : $message_type;
676
+
677
+			//if payment_refund is selected, but the status is NOT accepted.  Then change message type to false so NO message notification goes out.
678
+			$message_type = $message_type == 'payment_refund' && $payment->STS_ID() != EEM_Payment::status_id_approved ? false : $message_type;
679
+
680
+			self::_load_controller();
681
+
682
+			self::$_MSG_PROCESSOR->generate_for_all_active_messengers($message_type, $data);
683
+
684
+			//get count of queued for generation
685
+			$count_to_generate = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(array(
686
+				EEM_Message::status_incomplete,
687
+				EEM_Message::status_idle,
688
+			));
689
+
690
+			if ($count_to_generate > 0 && self::$_MSG_PROCESSOR->get_queue()->get_message_repository()->count() !== 0) {
691
+				add_filter('FHEE__EE_Admin_Page___process_admin_payment_notification__success', '__return_true');
692
+				return true;
693
+			} else {
694
+				$count_failed = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::instance()->stati_indicating_failed_sending());
695
+				/**
696
+				 * Verify that there are actually errors.  If not then we return a success message because the queue might have been emptied due to successful
697
+				 * IMMEDIATE generation.
698
+				 */
699
+				if ($count_failed > 0) {
700
+					EE_Error::add_error(sprintf(
701
+						_n(
702
+							'The payment notification generation failed.',
703
+							'%d payment notifications failed being sent.',
704
+							$count_failed,
705
+							'event_espresso'
706
+						),
707
+						$count_failed
708
+					), __FILE__, __FUNCTION__, __LINE__);
709
+
710
+					return false;
711
+				} else {
712
+					add_filter('FHEE__EE_Admin_Page___process_admin_payment_notification__success', '__return_true');
713
+					return true;
714
+				}
715
+			}
716
+		} else {
717
+			EE_Error::add_error(
718
+				'Unable to generate the payment notification because the given value for the transaction is invalid.',
719
+				'event_espresso'
720
+			);
721
+			return false;
722
+		}
723
+	}
724
+
725
+
726
+	/**
727
+	 * Callback for AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send_with_registrations trigger
728
+	 *
729
+	 * @since   4.3.0
730
+	 * @param  EE_Registration[] $registrations an array of EE_Registration objects
731
+	 * @param  int               $grp_id        a specific message template group id.
732
+	 * @return void
733
+	 */
734
+	public static function send_newsletter_message($registrations, $grp_id)
735
+	{
736
+		//make sure mtp is id and set it in the EE_Request Handler later messages setup.
737
+		EE_Registry::instance()->REQ->set('GRP_ID', (int)$grp_id);
738
+		self::_load_controller();
739
+		self::$_MSG_PROCESSOR->generate_for_all_active_messengers('newsletter', $registrations);
740
+	}
741
+
742
+
743
+	/**
744
+	 * Callback for FHEE__EE_Registration__invoice_url__invoice_url or FHEE__EE_Registration__receipt_url__receipt_url
745
+	 *
746
+	 * @since   4.3.0
747
+	 * @param    string          $registration_message_trigger_url
748
+	 * @param    EE_Registration $registration
749
+	 * @param string             $messenger
750
+	 * @param string             $message_type
751
+	 * @return    string
752
+	 */
753
+	public static function registration_message_trigger_url(
754
+		$registration_message_trigger_url,
755
+		EE_Registration $registration,
756
+		$messenger = 'html',
757
+		$message_type = 'invoice'
758
+	) {
759
+		// whitelist $messenger
760
+		switch ($messenger) {
761
+			case 'pdf' :
762
+				$sending_messenger    = 'pdf';
763
+				$generating_messenger = 'html';
764
+				break;
765
+			case 'html' :
766
+			default :
767
+				$sending_messenger    = 'html';
768
+				$generating_messenger = 'html';
769
+				break;
770
+		}
771
+		// whitelist $message_type
772
+		switch ($message_type) {
773
+			case 'receipt' :
774
+				$message_type = 'receipt';
775
+				break;
776
+			case 'invoice' :
777
+			default :
778
+				$message_type = 'invoice';
779
+				break;
780
+		}
781
+		// verify that both the messenger AND the message type are active
782
+		if (EEH_MSG_Template::is_messenger_active($sending_messenger) && EEH_MSG_Template::is_mt_active($message_type)) {
783
+			//need to get the correct message template group for this (i.e. is there a custom invoice for the event this registration is registered for?)
784
+			$template_query_params = array(
785
+				'MTP_is_active'    => true,
786
+				'MTP_messenger'    => $generating_messenger,
787
+				'MTP_message_type' => $message_type,
788
+				'Event.EVT_ID'     => $registration->event_ID(),
789
+			);
790
+			//get the message template group.
791
+			$msg_template_group = EEM_Message_Template_Group::instance()->get_one(array($template_query_params));
792
+			//if we don't have an EE_Message_Template_Group then return
793
+			if (! $msg_template_group instanceof EE_Message_Template_Group) {
794
+				// remove EVT_ID from query params so that global templates get picked up
795
+				unset($template_query_params['Event.EVT_ID']);
796
+				//get global template as the fallback
797
+				$msg_template_group = EEM_Message_Template_Group::instance()->get_one(array($template_query_params));
798
+			}
799
+			//if we don't have an EE_Message_Template_Group then return
800
+			if (! $msg_template_group instanceof EE_Message_Template_Group) {
801
+				return '';
802
+			}
803
+			// generate the URL
804
+			$registration_message_trigger_url = EEH_MSG_Template::generate_url_trigger(
805
+				$sending_messenger,
806
+				$generating_messenger,
807
+				'purchaser',
808
+				$message_type,
809
+				$registration,
810
+				$msg_template_group->ID(),
811
+				$registration->transaction_ID()
812
+			);
813
+
814
+		}
815
+		return $registration_message_trigger_url;
816
+	}
817
+
818
+
819
+	/**
820
+	 * Use to generate and return a message preview!
821
+	 *
822
+	 * @param  string $type      This should correspond with a valid message type
823
+	 * @param  string $context   This should correspond with a valid context for the message type
824
+	 * @param  string $messenger This should correspond with a valid messenger.
825
+	 * @param bool    $send      true we will do a test send using the messenger delivery, false we just do a regular
826
+	 *                           preview
827
+	 * @return bool|string The body of the message or if send is requested, sends.
828
+	 * @throws EE_Error
829
+	 */
830
+	public static function preview_message($type, $context, $messenger, $send = false)
831
+	{
832
+		self::_load_controller();
833
+		$mtg                     = new EE_Message_To_Generate(
834
+			$messenger,
835
+			$type,
836
+			array(),
837
+			$context,
838
+			true
839
+		);
840
+		$generated_preview_queue = self::$_MSG_PROCESSOR->generate_for_preview($mtg, $send);
841
+		if ($generated_preview_queue instanceof EE_Messages_Queue) {
842
+			$content = $generated_preview_queue->get_message_repository()->current()->content();
843
+			//if the current message was persisted to the db (which will happen with any extra fields on a message) then
844
+			//let's delete it because we don't need previews cluttering up the db.
845
+			if ($generated_preview_queue->get_message_repository()->current()->ID() > 0
846
+				&& $generated_preview_queue->get_message_repository()->current()->STS_ID() !== EEM_Message::status_failed
847
+			) {
848
+				$generated_preview_queue->get_message_repository()->delete();
849
+			}
850
+			return $content;
851
+		} else {
852
+			return $generated_preview_queue;
853
+		}
854
+	}
855
+
856
+
857
+	/**
858
+	 * This is a method that allows for sending a message using a messenger matching the string given and the provided
859
+	 * EE_Message_Queue object.  The EE_Message_Queue object is used to create a single aggregate EE_Message via the
860
+	 * content found in the EE_Message objects in the queue.
861
+	 *
862
+	 * @since 4.9.0
863
+	 * @param string            $messenger            a string matching a valid active messenger in the system
864
+	 * @param string            $message_type         Although it seems contrary to the name of the method, a message
865
+	 *                                                type name is still required to send along the message type to the
866
+	 *                                                messenger because this is used for determining what specific
867
+	 *                                                variations might be loaded for the generated message.
868
+	 * @param EE_Messages_Queue $queue
869
+	 * @param string            $custom_subject       Can be used to set what the custom subject string will be on the
870
+	 *                                                aggregate EE_Message object.
871
+	 * @return bool          success or fail.
872
+	 */
873
+	public static function send_message_with_messenger_only(
874
+		$messenger,
875
+		$message_type,
876
+		EE_Messages_Queue $queue,
877
+		$custom_subject = ''
878
+	) {
879
+		self::_load_controller();
880
+		/** @type EE_Message_To_Generate_From_Queue $message_to_generate */
881
+		$message_to_generate = EE_Registry::instance()->load_lib(
882
+			'Message_To_Generate_From_Queue',
883
+			array(
884
+				$messenger,
885
+				$message_type,
886
+				$queue,
887
+				$custom_subject,
888
+			)
889
+		);
890
+		return self::$_MSG_PROCESSOR->queue_for_sending($message_to_generate);
891
+	}
892
+
893
+
894
+	/**
895
+	 * Generates Messages immediately for EE_Message IDs (but only for the correct status for generation)
896
+	 *
897
+	 * @since 4.9.0
898
+	 * @param array $message_ids An array of message ids
899
+	 * @return bool | EE_Messages_Queue     false if nothing was generated, EE_Messages_Queue containing generated
900
+	 *              messages.
901
+	 */
902
+	public static function generate_now($message_ids)
903
+	{
904
+		self::_load_controller();
905
+		$messages        = EEM_Message::instance()->get_all(
906
+			array(
907
+				0 => array(
908
+					'MSG_ID' => array('IN', $message_ids),
909
+					'STS_ID' => EEM_Message::status_incomplete,
910
+				),
911
+			)
912
+		);
913
+		$generated_queue = false;
914
+		if ($messages) {
915
+			$generated_queue = self::$_MSG_PROCESSOR->batch_generate_from_queue($messages);
916
+		}
917
+
918
+		if (! $generated_queue instanceof EE_Messages_Queue) {
919
+			EE_Error::add_error(
920
+				__('The messages were not generated. This could mean there is already a batch being generated on a separate request, or because the selected messages are not ready for generation. Please wait a minute or two and try again.',
921
+					'event_espresso'),
922
+				__FILE__, __FUNCTION__, __LINE__
923
+			);
924
+		}
925
+		return $generated_queue;
926
+	}
927
+
928
+
929
+	/**
930
+	 * Sends messages immediately for the incoming message_ids that have the status of EEM_Message::status_resend or,
931
+	 * EEM_Message::status_idle
932
+	 *
933
+	 * @since 4.9.0
934
+	 * @param $message_ids
935
+	 * @return bool | EE_Messages_Queue  false if no messages sent.
936
+	 */
937
+	public static function send_now($message_ids)
938
+	{
939
+		self::_load_controller();
940
+		$messages   = EEM_Message::instance()->get_all(
941
+			array(
942
+				0 => array(
943
+					'MSG_ID' => array('IN', $message_ids),
944
+					'STS_ID' => array(
945
+						'IN',
946
+						array(EEM_Message::status_idle, EEM_Message::status_resend, EEM_Message::status_retry),
947
+					),
948
+				),
949
+			)
950
+		);
951
+		$sent_queue = false;
952
+		if ($messages) {
953
+			$sent_queue = self::$_MSG_PROCESSOR->batch_send_from_queue($messages);
954
+		}
955
+
956
+		if (! $sent_queue instanceof EE_Messages_Queue) {
957
+			EE_Error::add_error(
958
+				__('The messages were not sent. This could mean there is already a batch being sent on a separate request, or because the selected messages are not sendable. Please wait a minute or two and try again.',
959
+					'event_espresso'),
960
+				__FILE__, __FUNCTION__, __LINE__
961
+			);
962
+		} else {
963
+			//can count how many sent by using the messages in the queue
964
+			$sent_count = $sent_queue->count_STS_in_queue(EEM_Message::instance()->stati_indicating_sent());
965
+			if ($sent_count > 0) {
966
+				EE_Error::add_success(
967
+					sprintf(
968
+						_n(
969
+							'There was %d message successfully sent.',
970
+							'There were %d messages successfully sent.',
971
+							$sent_count,
972
+							'event_espresso'
973
+						),
974
+						$sent_count
975
+					)
976
+				);
977
+			} else {
978
+				EE_Error::overwrite_errors();
979
+				EE_Error::add_error(
980
+					__('No message was sent because of problems with sending. Either all the messages you selected were not a sendable message, they were ALREADY sent on a different scheduled task, or there was an error.
981 981
 					If there was an error, you can look at the messages in the message activity list table for any error messages.',
982
-                        'event_espresso'),
983
-                    __FILE__, __FUNCTION__, __LINE__
984
-                );
985
-            }
986
-        }
987
-        return $sent_queue;
988
-    }
989
-
990
-
991
-    /**
992
-     * This will queue the incoming message ids for resending.
993
-     * Note, only message_ids corresponding to messages with the status of EEM_Message::sent will be queued.
994
-     *
995
-     * @since 4.9.0
996
-     * @param array $message_ids An array of EE_Message IDs
997
-     * @return bool  true means messages were successfully queued for resending, false means none were queued for
998
-     *               resending.
999
-     */
1000
-    public static function queue_for_resending($message_ids)
1001
-    {
1002
-        self::_load_controller();
1003
-        self::$_MSG_PROCESSOR->setup_messages_from_ids_and_send($message_ids);
1004
-
1005
-        //get queue and count
1006
-        $queue_count = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::status_resend);
1007
-
1008
-        if (
1009
-            $queue_count > 0
1010
-        ) {
1011
-            EE_Error::add_success(
1012
-                sprintf(
1013
-                    _n(
1014
-                        '%d message successfully queued for resending.',
1015
-                        '%d messages successfully queued for resending.',
1016
-                        $queue_count,
1017
-                        'event_espresso'
1018
-                    ),
1019
-                    $queue_count
1020
-                )
1021
-            );
1022
-            /**
1023
-             * @see filter usage in EE_Messages_Queue::initiate_request_by_priority
1024
-             */
1025
-        } elseif (
1026
-            apply_filters('FHEE__EE_Messages_Processor__initiate_request_by_priority__do_immediate_processing', true)
1027
-            || EE_Registry::instance()->NET_CFG->core->do_messages_on_same_request
1028
-        ) {
1029
-            $queue_count = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::status_sent);
1030
-            if ($queue_count > 0) {
1031
-                EE_Error::add_success(
1032
-                    sprintf(
1033
-                        _n(
1034
-                            '%d message successfully sent.',
1035
-                            '%d messages successfully sent.',
1036
-                            $queue_count,
1037
-                            'event_espresso'
1038
-                        ),
1039
-                        $queue_count
1040
-                    )
1041
-                );
1042
-            } else {
1043
-                EE_Error::add_error(
1044
-                    __('No messages were queued for resending. This usually only happens when all the messages flagged for resending are not a status that can be resent.',
1045
-                        'event_espresso'),
1046
-                    __FILE__, __FUNCTION__, __LINE__
1047
-                );
1048
-            }
1049
-        } else {
1050
-            EE_Error::add_error(
1051
-                __('No messages were queued for resending. This usually only happens when all the messages flagged for resending are not a status that can be resent.',
1052
-                    'event_espresso'),
1053
-                __FILE__, __FUNCTION__, __LINE__
1054
-            );
1055
-        }
1056
-        return (bool)$queue_count;
1057
-    }
1058
-
1059
-
1060
-    /**
1061
-     * debug
1062
-     *
1063
-     * @param string          $class
1064
-     * @param string          $func
1065
-     * @param string          $line
1066
-     * @param \EE_Transaction $transaction
1067
-     * @param array           $info
1068
-     * @param bool            $display_request
1069
-     */
1070
-    protected static function log(
1071
-        $class = '',
1072
-        $func = '',
1073
-        $line = '',
1074
-        EE_Transaction $transaction,
1075
-        $info = array(),
1076
-        $display_request = false
1077
-    ) {
1078
-        if (WP_DEBUG && false) {
1079
-            if ($transaction instanceof EE_Transaction) {
1080
-                // don't serialize objects
1081
-                $info                  = EEH_Debug_Tools::strip_objects($info);
1082
-                $info['TXN_status']    = $transaction->status_ID();
1083
-                $info['TXN_reg_steps'] = $transaction->reg_steps();
1084
-                if ($transaction->ID()) {
1085
-                    $index = 'EE_Transaction: ' . $transaction->ID();
1086
-                    EEH_Debug_Tools::log($class, $func, $line, $info, $display_request, $index);
1087
-                }
1088
-            }
1089
-        }
1090
-
1091
-    }
1092
-
1093
-
1094
-    /**
1095
-     *  Resets all the static properties in this class when called.
1096
-     */
1097
-    public static function reset()
1098
-    {
1099
-        self::$_EEMSG                    = null;
1100
-        self::$_message_resource_manager = null;
1101
-        self::$_MSG_PROCESSOR            = null;
1102
-        self::$_MSG_PATHS                = null;
1103
-        self::$_TMP_PACKS                = array();
1104
-    }
982
+						'event_espresso'),
983
+					__FILE__, __FUNCTION__, __LINE__
984
+				);
985
+			}
986
+		}
987
+		return $sent_queue;
988
+	}
989
+
990
+
991
+	/**
992
+	 * This will queue the incoming message ids for resending.
993
+	 * Note, only message_ids corresponding to messages with the status of EEM_Message::sent will be queued.
994
+	 *
995
+	 * @since 4.9.0
996
+	 * @param array $message_ids An array of EE_Message IDs
997
+	 * @return bool  true means messages were successfully queued for resending, false means none were queued for
998
+	 *               resending.
999
+	 */
1000
+	public static function queue_for_resending($message_ids)
1001
+	{
1002
+		self::_load_controller();
1003
+		self::$_MSG_PROCESSOR->setup_messages_from_ids_and_send($message_ids);
1004
+
1005
+		//get queue and count
1006
+		$queue_count = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::status_resend);
1007
+
1008
+		if (
1009
+			$queue_count > 0
1010
+		) {
1011
+			EE_Error::add_success(
1012
+				sprintf(
1013
+					_n(
1014
+						'%d message successfully queued for resending.',
1015
+						'%d messages successfully queued for resending.',
1016
+						$queue_count,
1017
+						'event_espresso'
1018
+					),
1019
+					$queue_count
1020
+				)
1021
+			);
1022
+			/**
1023
+			 * @see filter usage in EE_Messages_Queue::initiate_request_by_priority
1024
+			 */
1025
+		} elseif (
1026
+			apply_filters('FHEE__EE_Messages_Processor__initiate_request_by_priority__do_immediate_processing', true)
1027
+			|| EE_Registry::instance()->NET_CFG->core->do_messages_on_same_request
1028
+		) {
1029
+			$queue_count = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::status_sent);
1030
+			if ($queue_count > 0) {
1031
+				EE_Error::add_success(
1032
+					sprintf(
1033
+						_n(
1034
+							'%d message successfully sent.',
1035
+							'%d messages successfully sent.',
1036
+							$queue_count,
1037
+							'event_espresso'
1038
+						),
1039
+						$queue_count
1040
+					)
1041
+				);
1042
+			} else {
1043
+				EE_Error::add_error(
1044
+					__('No messages were queued for resending. This usually only happens when all the messages flagged for resending are not a status that can be resent.',
1045
+						'event_espresso'),
1046
+					__FILE__, __FUNCTION__, __LINE__
1047
+				);
1048
+			}
1049
+		} else {
1050
+			EE_Error::add_error(
1051
+				__('No messages were queued for resending. This usually only happens when all the messages flagged for resending are not a status that can be resent.',
1052
+					'event_espresso'),
1053
+				__FILE__, __FUNCTION__, __LINE__
1054
+			);
1055
+		}
1056
+		return (bool)$queue_count;
1057
+	}
1058
+
1059
+
1060
+	/**
1061
+	 * debug
1062
+	 *
1063
+	 * @param string          $class
1064
+	 * @param string          $func
1065
+	 * @param string          $line
1066
+	 * @param \EE_Transaction $transaction
1067
+	 * @param array           $info
1068
+	 * @param bool            $display_request
1069
+	 */
1070
+	protected static function log(
1071
+		$class = '',
1072
+		$func = '',
1073
+		$line = '',
1074
+		EE_Transaction $transaction,
1075
+		$info = array(),
1076
+		$display_request = false
1077
+	) {
1078
+		if (WP_DEBUG && false) {
1079
+			if ($transaction instanceof EE_Transaction) {
1080
+				// don't serialize objects
1081
+				$info                  = EEH_Debug_Tools::strip_objects($info);
1082
+				$info['TXN_status']    = $transaction->status_ID();
1083
+				$info['TXN_reg_steps'] = $transaction->reg_steps();
1084
+				if ($transaction->ID()) {
1085
+					$index = 'EE_Transaction: ' . $transaction->ID();
1086
+					EEH_Debug_Tools::log($class, $func, $line, $info, $display_request, $index);
1087
+				}
1088
+			}
1089
+		}
1090
+
1091
+	}
1092
+
1093
+
1094
+	/**
1095
+	 *  Resets all the static properties in this class when called.
1096
+	 */
1097
+	public static function reset()
1098
+	{
1099
+		self::$_EEMSG                    = null;
1100
+		self::$_message_resource_manager = null;
1101
+		self::$_MSG_PROCESSOR            = null;
1102
+		self::$_MSG_PATHS                = null;
1103
+		self::$_TMP_PACKS                = array();
1104
+	}
1105 1105
 
1106 1106
 }
1107 1107
 // End of file EED_Messages.module.php
Please login to merge, or discard this patch.
core/libraries/messages/EE_Messages_Processor.lib.php 1 patch
Spacing   +108 added lines, -108 removed lines patch added patch discarded remove patch
@@ -35,7 +35,7 @@  discard block
 block discarded – undo
35 35
 	 *
36 36
 	 * @param EE_Message_Resource_Manager $message_resource_manager
37 37
 	 */
38
-	public function __construct( EE_Message_Resource_Manager $message_resource_manager ) {
38
+	public function __construct(EE_Message_Resource_Manager $message_resource_manager) {
39 39
 		$this->_message_resource_manager = $message_resource_manager;
40 40
 		$this->_init_queue_and_generator();
41 41
 	}
@@ -50,7 +50,7 @@  discard block
 block discarded – undo
50 50
 	 * - $_generator = holds the messages generator
51 51
 	 */
52 52
 	protected function _init_queue_and_generator() {
53
-		$this->_generator = EE_Registry::factory( 'EE_Messages_Generator' );
53
+		$this->_generator = EE_Registry::factory('EE_Messages_Generator');
54 54
 		$this->_queue = $this->_generator->generation_queue();
55 55
 	}
56 56
 
@@ -75,31 +75,31 @@  discard block
 block discarded – undo
75 75
 	 * @param EE_Messages_Queue $queue_to_process
76 76
 	 * @return bool  true for success false for error.
77 77
 	 */
78
-	public function process_immediately_from_queue( EE_Messages_Queue $queue_to_process ) {
78
+	public function process_immediately_from_queue(EE_Messages_Queue $queue_to_process) {
79 79
 		$success = false;
80 80
 		$messages_to_send = array();
81 81
 		$messages_to_generate = array();
82 82
 		//loop through and setup the various messages from the queue so we know what is being processed
83 83
 		$queue_to_process->get_message_repository()->rewind();
84
-		foreach ( $queue_to_process->get_message_repository() as $message ) {
85
-			if ( $message->STS_ID() === EEM_Message::status_incomplete ) {
84
+		foreach ($queue_to_process->get_message_repository() as $message) {
85
+			if ($message->STS_ID() === EEM_Message::status_incomplete) {
86 86
 				$messages_to_generate[] = $message;
87 87
 				continue;
88 88
 			}
89 89
 
90
-			if ( in_array( $message->STS_ID(), EEM_Message::instance()->stati_indicating_to_send() ) ) {
90
+			if (in_array($message->STS_ID(), EEM_Message::instance()->stati_indicating_to_send())) {
91 91
 				$messages_to_send[] = $message;
92 92
 				continue;
93 93
 			}
94 94
 		}
95 95
 
96 96
 		//do generation/sends
97
-		if ( $messages_to_generate ) {
98
-			$success = $this->batch_generate_from_queue( $messages_to_generate, true );
97
+		if ($messages_to_generate) {
98
+			$success = $this->batch_generate_from_queue($messages_to_generate, true);
99 99
 		}
100 100
 
101
-		if ( $messages_to_send ) {
102
-			$sent = $this->batch_send_from_queue( $messages_to_send, true );
101
+		if ($messages_to_send) {
102
+			$sent = $this->batch_send_from_queue($messages_to_send, true);
103 103
 			//if there was messages to generate and it failed, then we override any success value for the sending process
104 104
 			//otherwise we just use the return from batch send.  The intent is that there is a simple response for success/fail.
105 105
 			//Either everything was successful or we consider it a fail.  To be clear, this is a limitation of doing
@@ -119,13 +119,13 @@  discard block
 block discarded – undo
119 119
 	 * @return bool|EE_Messages_Queue return false if nothing generated.  This returns a new EE_Message_Queue with
120 120
 	 *                                   generated messages.
121 121
 	 */
122
-	public function batch_generate_from_queue( $messages = array(), $clear_queue = false ) {
123
-		if ( $this->_build_queue_for_generation( $messages, $clear_queue ) ) {
122
+	public function batch_generate_from_queue($messages = array(), $clear_queue = false) {
123
+		if ($this->_build_queue_for_generation($messages, $clear_queue)) {
124 124
 			$new_queue = $this->_generator->generate();
125
-			if ( $new_queue instanceof EE_Messages_Queue ) {
125
+			if ($new_queue instanceof EE_Messages_Queue) {
126 126
 				//unlock queue
127 127
 				$this->_queue->unlock_queue();
128
-				$new_queue->initiate_request_by_priority( 'send' );
128
+				$new_queue->initiate_request_by_priority('send');
129 129
 				return $new_queue;
130 130
 			}
131 131
 		}
@@ -146,24 +146,24 @@  discard block
 block discarded – undo
146 146
 	 *
147 147
 	 * @return bool true means queue prepped, false means there was a lock so no generation please.
148 148
 	 */
149
-	protected function _build_queue_for_generation( $messages = array(), $clear_queue = false ) {
149
+	protected function _build_queue_for_generation($messages = array(), $clear_queue = false) {
150 150
 
151
-		if ( $clear_queue ) {
151
+		if ($clear_queue) {
152 152
 			$this->_init_queue_and_generator();
153 153
 		}
154 154
 
155
-		if ( $messages ) {
155
+		if ($messages) {
156 156
 			//if generation is locked then get out now because that means processing is already happening.
157
-			if ( $this->_queue->is_locked() ) {
157
+			if ($this->_queue->is_locked()) {
158 158
 				return false;
159 159
 			}
160 160
 
161 161
 			$this->_queue->lock_queue();
162
-			$messages = is_array( $messages ) ? $messages : array( $messages );
163
-			foreach ( $messages as $message ) {
164
-				if ( $message instanceof EE_Message ) {
162
+			$messages = is_array($messages) ? $messages : array($messages);
163
+			foreach ($messages as $message) {
164
+				if ($message instanceof EE_Message) {
165 165
 					$data = $message->all_extra_meta_array();
166
-					$this->_queue->add( $message, $data );
166
+					$this->_queue->add($message, $data);
167 167
 				}
168 168
 			}
169 169
 			return true;
@@ -181,22 +181,22 @@  discard block
 block discarded – undo
181 181
 	 *
182 182
 	 * @return bool true means queue prepped, false means there was a lock so no queue prepped.
183 183
 	 */
184
-	protected function _build_queue_for_sending( $messages, $clear_queue = false ) {
184
+	protected function _build_queue_for_sending($messages, $clear_queue = false) {
185 185
 		//if sending is locked then get out now because that means processing is already happening.
186
-		if ( $this->_queue->is_locked( EE_Messages_Queue::action_sending ) ) {
186
+		if ($this->_queue->is_locked(EE_Messages_Queue::action_sending)) {
187 187
 			return false;
188 188
 		}
189 189
 
190
-		$this->_queue->lock_queue( EE_Messages_Queue::action_sending );
190
+		$this->_queue->lock_queue(EE_Messages_Queue::action_sending);
191 191
 
192
-		if ( $clear_queue ) {
192
+		if ($clear_queue) {
193 193
 			$this->_init_queue_and_generator();
194 194
 		}
195 195
 
196
-		$messages = is_array( $messages ) ? $messages : array( $messages );
196
+		$messages = is_array($messages) ? $messages : array($messages);
197 197
 
198
-		foreach ( $messages as $message ) {
199
-			$this->_queue->add( $message );
198
+		foreach ($messages as $message) {
199
+			$this->_queue->add($message);
200 200
 		}
201 201
 		return true;
202 202
 	}
@@ -212,11 +212,11 @@  discard block
 block discarded – undo
212 212
 	 *
213 213
 	 * @return EE_Messages_Queue
214 214
 	 */
215
-	public function batch_send_from_queue( $messages = array(), $clear_queue = false ) {
215
+	public function batch_send_from_queue($messages = array(), $clear_queue = false) {
216 216
 
217
-		if ( $messages && $this->_build_queue_for_sending( $messages, $clear_queue ) ) {
217
+		if ($messages && $this->_build_queue_for_sending($messages, $clear_queue)) {
218 218
 			$this->_queue->execute();
219
-			$this->_queue->unlock_queue( EE_Messages_Queue::action_sending );
219
+			$this->_queue->unlock_queue(EE_Messages_Queue::action_sending);
220 220
 		} else {
221 221
 			//get messages to send and execute.
222 222
 			$this->_queue->get_to_send_batch_and_send();
@@ -239,10 +239,10 @@  discard block
 block discarded – undo
239 239
 	 * @param EE_Message_To_Generate[] $messages_to_generate
240 240
 	 * @return EE_Messages_Queue
241 241
 	 */
242
-	public function generate_and_return(  $messages_to_generate ) {
242
+	public function generate_and_return($messages_to_generate) {
243 243
 		$this->_init_queue_and_generator();
244
-		$this->_queue_for_generation_loop( $messages_to_generate );
245
-		return $this->_generator->generate( false );
244
+		$this->_queue_for_generation_loop($messages_to_generate);
245
+		return $this->_generator->generate(false);
246 246
 	}
247 247
 
248 248
 
@@ -253,8 +253,8 @@  discard block
 block discarded – undo
253 253
 	 * @param  bool     $persist    Indicate whether to instruct the generator to persist the generated queue (true) or not (false).
254 254
 	 * @return EE_Messages_Queue
255 255
 	 */
256
-	public function generate_queue( $persist = true ) {
257
-		return $this->_generator->generate( $persist );
256
+	public function generate_queue($persist = true) {
257
+		return $this->_generator->generate($persist);
258 258
 	}
259 259
 
260 260
 
@@ -267,9 +267,9 @@  discard block
 block discarded – undo
267 267
 	 * @param bool                   $test_send             Whether this item is for a test send or not.
268 268
 	 * @return  EE_Messages_Queue
269 269
 	 */
270
-	public function queue_for_generation( EE_Message_To_Generate $message_to_generate, $test_send = false ) {
271
-		if ( $message_to_generate->valid() ) {
272
-			$this->_generator->create_and_add_message_to_queue( $message_to_generate, $test_send );
270
+	public function queue_for_generation(EE_Message_To_Generate $message_to_generate, $test_send = false) {
271
+		if ($message_to_generate->valid()) {
272
+			$this->_generator->create_and_add_message_to_queue($message_to_generate, $test_send);
273 273
 		}
274 274
 	}
275 275
 
@@ -285,9 +285,9 @@  discard block
 block discarded – undo
285 285
 	 *
286 286
 	 * @param EE_Message_To_Generate[] $messages_to_generate
287 287
 	 */
288
-	public function batch_queue_for_generation_and_persist( $messages_to_generate ) {
288
+	public function batch_queue_for_generation_and_persist($messages_to_generate) {
289 289
 		$this->_init_queue_and_generator();
290
-		$this->_queue_for_generation_loop( $messages_to_generate );
290
+		$this->_queue_for_generation_loop($messages_to_generate);
291 291
 		$this->_queue->save();
292 292
 	}
293 293
 
@@ -303,9 +303,9 @@  discard block
 block discarded – undo
303 303
 	 *
304 304
 	 * @param EE_Message_To_Generate[]  $messages_to_generate
305 305
 	 */
306
-	public function batch_queue_for_generation_no_persist( $messages_to_generate ) {
306
+	public function batch_queue_for_generation_no_persist($messages_to_generate) {
307 307
 		$this->_init_queue_and_generator();
308
-		$this->_queue_for_generation_loop( $messages_to_generate );
308
+		$this->_queue_for_generation_loop($messages_to_generate);
309 309
 	}
310 310
 
311 311
 
@@ -317,15 +317,15 @@  discard block
 block discarded – undo
317 317
 	 *
318 318
 	 * @param EE_Message_To_Generate[] $messages_to_generate
319 319
 	 */
320
-	protected function _queue_for_generation_loop( $messages_to_generate ) {
320
+	protected function _queue_for_generation_loop($messages_to_generate) {
321 321
 		//make sure is in an array.
322
-		if ( ! is_array( $messages_to_generate ) ) {
323
-			$messages_to_generate = array( $messages_to_generate );
322
+		if ( ! is_array($messages_to_generate)) {
323
+			$messages_to_generate = array($messages_to_generate);
324 324
 		}
325 325
 
326
-		foreach ( $messages_to_generate as $message_to_generate ) {
327
-			if ( $message_to_generate instanceof EE_Message_To_Generate && $message_to_generate->valid() ) {
328
-				$this->queue_for_generation( $message_to_generate );
326
+		foreach ($messages_to_generate as $message_to_generate) {
327
+			if ($message_to_generate instanceof EE_Message_To_Generate && $message_to_generate->valid()) {
328
+				$this->queue_for_generation($message_to_generate);
329 329
 			}
330 330
 		}
331 331
 	}
@@ -340,10 +340,10 @@  discard block
 block discarded – undo
340 340
 	 * @param  EE_Message_To_Generate[]
341 341
 	 * @return EE_Messages_Queue
342 342
 	 */
343
-	public function generate_and_queue_for_sending( $messages_to_generate ) {
343
+	public function generate_and_queue_for_sending($messages_to_generate) {
344 344
 		$this->_init_queue_and_generator();
345
-		$this->_queue_for_generation_loop( $messages_to_generate );
346
-		return $this->_generator->generate( true );
345
+		$this->_queue_for_generation_loop($messages_to_generate);
346
+		return $this->_generator->generate(true);
347 347
 	}
348 348
 
349 349
 
@@ -357,10 +357,10 @@  discard block
 block discarded – undo
357 357
 	 * @param   bool                   $test_send                Whether this is a test send or not.
358 358
 	 * @return  EE_Messages_Queue | bool   false if unable to generate otherwise the generated queue.
359 359
 	 */
360
-	public function generate_for_preview( EE_Message_To_Generate $message_to_generate, $test_send = false ) {
361
-		if ( ! $message_to_generate->valid() ) {
360
+	public function generate_for_preview(EE_Message_To_Generate $message_to_generate, $test_send = false) {
361
+		if ( ! $message_to_generate->valid()) {
362 362
 			EE_Error::add_error(
363
-				__( 'Unable to generate preview because of invalid data', 'event_espresso' ),
363
+				__('Unable to generate preview because of invalid data', 'event_espresso'),
364 364
 				__FILE__,
365 365
 				__FUNCTION__,
366 366
 				__LINE__
@@ -368,14 +368,14 @@  discard block
 block discarded – undo
368 368
 			return false;
369 369
 		}
370 370
 		//just make sure preview is set on the $message_to_generate (in case client forgot)
371
-		$message_to_generate->set_preview( true );
371
+		$message_to_generate->set_preview(true);
372 372
 		$this->_init_queue_and_generator();
373
-		$this->queue_for_generation( $message_to_generate, $test_send );
374
-		$generated_queue = $this->_generator->generate( false );
375
-		if ( $generated_queue->execute( false ) ) {
373
+		$this->queue_for_generation($message_to_generate, $test_send);
374
+		$generated_queue = $this->_generator->generate(false);
375
+		if ($generated_queue->execute(false)) {
376 376
 			//the first queue item should be the preview
377 377
 			$generated_queue->get_message_repository()->rewind();
378
-			if ( ! $generated_queue->get_message_repository()->valid() ) {
378
+			if ( ! $generated_queue->get_message_repository()->valid()) {
379 379
 				return $generated_queue;
380 380
 			}
381 381
 			return $generated_queue;
@@ -392,15 +392,15 @@  discard block
 block discarded – undo
392 392
 	 * @param EE_Message_To_Generate $message_to_generate
393 393
 	 * @return bool true or false for success.
394 394
 	 */
395
-	public function queue_for_sending( EE_Message_To_Generate $message_to_generate ) {
396
-		if ( ! $message_to_generate->valid() ) {
395
+	public function queue_for_sending(EE_Message_To_Generate $message_to_generate) {
396
+		if ( ! $message_to_generate->valid()) {
397 397
 			return false;
398 398
 		}
399 399
 		$this->_init_queue_and_generator();
400 400
 		$message = $message_to_generate->get_EE_Message();
401
-		$this->_queue->add( $message );
402
-		if ( $message->send_now() ) {
403
-			$this->_queue->execute( false );
401
+		$this->_queue->add($message);
402
+		if ($message->send_now()) {
403
+			$this->_queue->execute(false);
404 404
 		} else {
405 405
 			$this->_queue->save();
406 406
 		}
@@ -413,12 +413,12 @@  discard block
 block discarded – undo
413 413
 	 * @param EE_Message_To_Generate $message_to_generate
414 414
 	 * @return EE_Messages_Queue | null
415 415
 	 */
416
-	public function generate_and_send_now( EE_Message_To_Generate $message_to_generate ) {
417
-		if ( ! $message_to_generate->valid() ) {
416
+	public function generate_and_send_now(EE_Message_To_Generate $message_to_generate) {
417
+		if ( ! $message_to_generate->valid()) {
418 418
 			return null;
419 419
 		}
420 420
 		// is there supposed to be a sending messenger for this message?
421
-		if ( $message_to_generate instanceof EEI_Has_Sending_Messenger ) {
421
+		if ($message_to_generate instanceof EEI_Has_Sending_Messenger) {
422 422
 			// make sure it's valid, but if it's not,
423 423
 			// then set the value of $sending_messenger to an EE_Error object
424 424
 			// so that downstream code can easily see that things went wrong.
@@ -434,14 +434,14 @@  discard block
 block discarded – undo
434 434
 			$sending_messenger = null;
435 435
 		}
436 436
 
437
-		if ( $message_to_generate->get_EE_Message()->STS_ID() === EEM_Message::status_idle ) {
437
+		if ($message_to_generate->get_EE_Message()->STS_ID() === EEM_Message::status_idle) {
438 438
 			$this->_init_queue_and_generator();
439
-			$this->_queue->add( $message_to_generate->get_EE_Message() );
440
-			$this->_queue->execute( false, $sending_messenger );
439
+			$this->_queue->add($message_to_generate->get_EE_Message());
440
+			$this->_queue->execute(false, $sending_messenger);
441 441
 			return $this->_queue;
442
-		} elseif ( $message_to_generate->get_EE_Message()->STS_ID() === EEM_Message::status_incomplete ) {
443
-			$generated_queue = $this->generate_and_return( array( $message_to_generate ) );
444
-			$generated_queue->execute( false, $sending_messenger );
442
+		} elseif ($message_to_generate->get_EE_Message()->STS_ID() === EEM_Message::status_incomplete) {
443
+			$generated_queue = $this->generate_and_return(array($message_to_generate));
444
+			$generated_queue->execute(false, $sending_messenger);
445 445
 			return $generated_queue;
446 446
 		}
447 447
 		return null;
@@ -458,13 +458,13 @@  discard block
 block discarded – undo
458 458
 	 * @param mixed  $data   The data being used for generation.
459 459
 	 * @param bool   $persist   Whether to persist the queued messages to the db or not.
460 460
 	 */
461
-	public function generate_for_all_active_messengers( $message_type, $data, $persist = true ) {
462
-		$messages_to_generate = $this->setup_mtgs_for_all_active_messengers( $message_type, $data );
463
-		if ( $persist ) {
464
-			$this->batch_queue_for_generation_and_persist( $messages_to_generate );
461
+	public function generate_for_all_active_messengers($message_type, $data, $persist = true) {
462
+		$messages_to_generate = $this->setup_mtgs_for_all_active_messengers($message_type, $data);
463
+		if ($persist) {
464
+			$this->batch_queue_for_generation_and_persist($messages_to_generate);
465 465
 			$this->_queue->initiate_request_by_priority();
466 466
 		} else {
467
-			$this->batch_queue_for_generation_no_persist( $messages_to_generate );
467
+			$this->batch_queue_for_generation_no_persist($messages_to_generate);
468 468
 		}
469 469
 	}
470 470
 
@@ -479,11 +479,11 @@  discard block
 block discarded – undo
479 479
 	 *
480 480
 	 * @return EE_Message_To_Generate[]
481 481
 	 */
482
-	public function setup_mtgs_for_all_active_messengers( $message_type, $data ) {
482
+	public function setup_mtgs_for_all_active_messengers($message_type, $data) {
483 483
 		$messages_to_generate = array();
484
-		foreach ( $this->_message_resource_manager->active_messengers() as $messenger_slug => $messenger_object  ) {
485
-			$message_to_generate = new EE_Message_To_Generate( $messenger_slug, $message_type, $data );
486
-			if ( $message_to_generate->valid() ) {
484
+		foreach ($this->_message_resource_manager->active_messengers() as $messenger_slug => $messenger_object) {
485
+			$message_to_generate = new EE_Message_To_Generate($messenger_slug, $message_type, $data);
486
+			if ($message_to_generate->valid()) {
487 487
 				$messages_to_generate[] = $message_to_generate;
488 488
 			}
489 489
 		}
@@ -498,29 +498,29 @@  discard block
 block discarded – undo
498 498
 	 * and send.
499 499
 	 * @param array $message_ids
500 500
 	 */
501
-	public function setup_messages_from_ids_and_send( $message_ids ) {
501
+	public function setup_messages_from_ids_and_send($message_ids) {
502 502
 		$this->_init_queue_and_generator();
503
-		$messages = EEM_Message::instance()->get_all( array(
503
+		$messages = EEM_Message::instance()->get_all(array(
504 504
 			array(
505
-				'MSG_ID' => array( 'IN', $message_ids ),
505
+				'MSG_ID' => array('IN', $message_ids),
506 506
 				'STS_ID' => array(
507 507
 					'IN',
508 508
 					array_merge(
509 509
 						EEM_Message::instance()->stati_indicating_sent(),
510
-						array( EEM_Message::status_retry )
510
+						array(EEM_Message::status_retry)
511 511
 					),
512 512
 				),
513 513
 			),
514 514
 		));
515 515
 		//set the Messages to resend.
516
-		foreach ( $messages as $message ) {
517
-			if ( $message instanceof EE_Message ) {
518
-				$message->set_STS_ID( EEM_Message::status_resend );
519
-				$this->_queue->add( $message );
516
+		foreach ($messages as $message) {
517
+			if ($message instanceof EE_Message) {
518
+				$message->set_STS_ID(EEM_Message::status_resend);
519
+				$this->_queue->add($message);
520 520
 			}
521 521
 		}
522 522
 
523
-		$this->_queue->initiate_request_by_priority( 'send' );
523
+		$this->_queue->initiate_request_by_priority('send');
524 524
 	}
525 525
 
526 526
 
@@ -534,23 +534,23 @@  discard block
 block discarded – undo
534 534
 	 *
535 535
 	 * @return EE_Message_To_Generate[]
536 536
 	 */
537
-	public function setup_messages_to_generate_from_registration_ids_in_request( $registration_ids_key = '_REG_ID' ) {
538
-		EE_Registry::instance()->load_core( 'Request_Handler' );
539
-		EE_Registry::instance()->load_helper( 'MSG_Template' );
537
+	public function setup_messages_to_generate_from_registration_ids_in_request($registration_ids_key = '_REG_ID') {
538
+		EE_Registry::instance()->load_core('Request_Handler');
539
+		EE_Registry::instance()->load_helper('MSG_Template');
540 540
 		$regs_to_send = array();
541
-		$regIDs = EE_Registry::instance()->REQ->get( $registration_ids_key );
542
-		if ( empty( $regIDs ) ) {
543
-			EE_Error::add_error( __('Something went wrong because we\'re missing the registration ID', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__ );
541
+		$regIDs = EE_Registry::instance()->REQ->get($registration_ids_key);
542
+		if (empty($regIDs)) {
543
+			EE_Error::add_error(__('Something went wrong because we\'re missing the registration ID', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
544 544
 			return false;
545 545
 		}
546 546
 
547 547
 		//make sure is an array
548
-		$regIDs = is_array( $regIDs ) ? $regIDs : array( $regIDs );
548
+		$regIDs = is_array($regIDs) ? $regIDs : array($regIDs);
549 549
 
550
-		foreach( $regIDs as $regID ) {
551
-			$reg = EEM_Registration::instance()->get_one_by_ID( $regID );
552
-			if ( ! $reg instanceof EE_Registration ) {
553
-				EE_Error::add_error( sprintf( __('Unable to retrieve a registration object for the given reg id (%s)', 'event_espresso'), $regID ) );
550
+		foreach ($regIDs as $regID) {
551
+			$reg = EEM_Registration::instance()->get_one_by_ID($regID);
552
+			if ( ! $reg instanceof EE_Registration) {
553
+				EE_Error::add_error(sprintf(__('Unable to retrieve a registration object for the given reg id (%s)', 'event_espresso'), $regID));
554 554
 				return false;
555 555
 			}
556 556
 			$regs_to_send[$reg->transaction_ID()][$reg->status_ID()][] = $reg;
@@ -558,13 +558,13 @@  discard block
 block discarded – undo
558 558
 
559 559
 		$messages_to_generate = array();
560 560
 
561
-		foreach ( $regs_to_send as $status_group ) {
562
-			foreach ( $status_group as $status_id => $registrations ) {
561
+		foreach ($regs_to_send as $status_group) {
562
+			foreach ($status_group as $status_id => $registrations) {
563 563
 				$messages_to_generate = array_merge(
564 564
 					$messages_to_generate,
565 565
 					$this->setup_mtgs_for_all_active_messengers(
566
-						EEH_MSG_Template::convert_reg_status_to_message_type( $status_id ),
567
-						array( $registrations, $status_id )
566
+						EEH_MSG_Template::convert_reg_status_to_message_type($status_id),
567
+						array($registrations, $status_id)
568 568
 					)
569 569
 				);
570 570
 			}
Please login to merge, or discard this patch.
core/db_models/fields/EE_Post_Content_Field.php 2 patches
Indentation   +116 added lines, -116 removed lines patch added patch discarded remove patch
@@ -8,133 +8,133 @@
 block discarded – undo
8 8
 class EE_Post_Content_Field extends EE_Text_Field_Base
9 9
 {
10 10
 
11
-    /**
12
-     * @param string $table_column
13
-     * @param string $nicename
14
-     * @param bool   $nullable
15
-     * @param null   $default_value
16
-     */
17
-    public function __construct($table_column, $nicename, $nullable, $default_value = null)
18
-    {
19
-        parent::__construct($table_column, $nicename, $nullable, $default_value);
20
-        $this->setSchemaType('object');
21
-    }
11
+	/**
12
+	 * @param string $table_column
13
+	 * @param string $nicename
14
+	 * @param bool   $nullable
15
+	 * @param null   $default_value
16
+	 */
17
+	public function __construct($table_column, $nicename, $nullable, $default_value = null)
18
+	{
19
+		parent::__construct($table_column, $nicename, $nullable, $default_value);
20
+		$this->setSchemaType('object');
21
+	}
22 22
 
23 23
 
24
-    /**
25
-     * removes all tags which a WP Post wouldn't allow in its content normally
26
-     *
27
-     * @param string $value
28
-     * @return string
29
-     */
30
-    function prepare_for_set($value)
31
-    {
32
-        if (! current_user_can('unfiltered_html')) {
33
-            $value = wp_kses("$value", wp_kses_allowed_html('post'));
34
-        }
35
-        return parent::prepare_for_set($value);
36
-    }
24
+	/**
25
+	 * removes all tags which a WP Post wouldn't allow in its content normally
26
+	 *
27
+	 * @param string $value
28
+	 * @return string
29
+	 */
30
+	function prepare_for_set($value)
31
+	{
32
+		if (! current_user_can('unfiltered_html')) {
33
+			$value = wp_kses("$value", wp_kses_allowed_html('post'));
34
+		}
35
+		return parent::prepare_for_set($value);
36
+	}
37 37
 
38
-    function prepare_for_set_from_db($value_found_in_db_for_model_object)
39
-    {
40
-        return $value_found_in_db_for_model_object;
41
-    }
38
+	function prepare_for_set_from_db($value_found_in_db_for_model_object)
39
+	{
40
+		return $value_found_in_db_for_model_object;
41
+	}
42 42
 
43 43
 
44 44
 
45
-    /**
46
-     * Runs the content through `the_content`, or if prepares the content for placing in a form input
47
-     * @param string $value_on_field_to_be_outputted
48
-     * @param string   $schema possible values: 'form_input' or null (if null, will run through 'the_content')
49
-     * @return string
50
-     * @throws EE_Error when WP_DEBUG is on and recursive calling is detected
51
-     */
52
-    public function prepare_for_pretty_echoing($value_on_field_to_be_outputted, $schema = null)
53
-    {
54
-        switch($schema){
55
-            case 'form_input':
56
-                return parent::prepare_for_pretty_echoing($value_on_field_to_be_outputted, $schema);
57
-            case 'the_content':
45
+	/**
46
+	 * Runs the content through `the_content`, or if prepares the content for placing in a form input
47
+	 * @param string $value_on_field_to_be_outputted
48
+	 * @param string   $schema possible values: 'form_input' or null (if null, will run through 'the_content')
49
+	 * @return string
50
+	 * @throws EE_Error when WP_DEBUG is on and recursive calling is detected
51
+	 */
52
+	public function prepare_for_pretty_echoing($value_on_field_to_be_outputted, $schema = null)
53
+	{
54
+		switch($schema){
55
+			case 'form_input':
56
+				return parent::prepare_for_pretty_echoing($value_on_field_to_be_outputted, $schema);
57
+			case 'the_content':
58 58
 
59
-                if(doing_filter( 'the_content')){
60
-                    if( defined('WP_DEBUG') && WP_DEBUG){
61
-                        throw new EE_Error(
62
-                            sprintf(
63
-                                esc_html__('You have recursively called "%1$s" with %2$s set to %3$s which uses "%2$s" filter. You should use it with %2$s "%3$s" instead here.', 'event_espresso'),
64
-                                'EE_Post_Content_Field::prepare_for_pretty_echoing',
65
-                                '$schema',
66
-                                'the_content',
67
-                                'the_content_wp_core_only'
68
-                            )
69
-                        );
70
-                    } else {
71
-                        return $this->prepare_for_pretty_echoing($value_on_field_to_be_outputted, 'the_content_wp_core_only');
72
-                    }
73
-                }
74
-                return apply_filters(
75
-                    'the_content',
76
-                    parent::prepare_for_pretty_echoing(
77
-                        $value_on_field_to_be_outputted,
78
-                        $schema
79
-                    )
80
-                );
81
-            case 'the_content_wp_core_only':
82
-            default:
83
-                self::_setup_the_content_wp_core_only_filters();
84
-                $return_value = apply_filters(
85
-                    'the_content_wp_core_only',
86
-                    parent::prepare_for_pretty_echoing(
87
-                        $value_on_field_to_be_outputted,
88
-                        $schema
89
-                    )
90
-                );
91
-                //ya know what? adding these filters is super fast. Let's just
92
-                //avoid needing to maintain global state and set this up as-needed
93
-                remove_all_filters('the_content_wp_core_only');
94
-                do_action( 'AHEE__EE_Post_Content_Field__prepare_for_pretty_echoing__the_content_wp_core_only__done');
95
-                return $return_value;
96
-        }
97
-    }
59
+				if(doing_filter( 'the_content')){
60
+					if( defined('WP_DEBUG') && WP_DEBUG){
61
+						throw new EE_Error(
62
+							sprintf(
63
+								esc_html__('You have recursively called "%1$s" with %2$s set to %3$s which uses "%2$s" filter. You should use it with %2$s "%3$s" instead here.', 'event_espresso'),
64
+								'EE_Post_Content_Field::prepare_for_pretty_echoing',
65
+								'$schema',
66
+								'the_content',
67
+								'the_content_wp_core_only'
68
+							)
69
+						);
70
+					} else {
71
+						return $this->prepare_for_pretty_echoing($value_on_field_to_be_outputted, 'the_content_wp_core_only');
72
+					}
73
+				}
74
+				return apply_filters(
75
+					'the_content',
76
+					parent::prepare_for_pretty_echoing(
77
+						$value_on_field_to_be_outputted,
78
+						$schema
79
+					)
80
+				);
81
+			case 'the_content_wp_core_only':
82
+			default:
83
+				self::_setup_the_content_wp_core_only_filters();
84
+				$return_value = apply_filters(
85
+					'the_content_wp_core_only',
86
+					parent::prepare_for_pretty_echoing(
87
+						$value_on_field_to_be_outputted,
88
+						$schema
89
+					)
90
+				);
91
+				//ya know what? adding these filters is super fast. Let's just
92
+				//avoid needing to maintain global state and set this up as-needed
93
+				remove_all_filters('the_content_wp_core_only');
94
+				do_action( 'AHEE__EE_Post_Content_Field__prepare_for_pretty_echoing__the_content_wp_core_only__done');
95
+				return $return_value;
96
+		}
97
+	}
98 98
 
99 99
 
100 100
 
101
-    /**
102
-     * Verifies we've setup the standard WP core filters on  'the_content_wp_core_only' filter
103
-     */
104
-    protected static function _setup_the_content_wp_core_only_filters()
105
-    {
106
-        add_filter('the_content_wp_core_only', array( $GLOBALS['wp_embed'], 'run_shortcode'), 8);
107
-        add_filter('the_content_wp_core_only', array( $GLOBALS['wp_embed'], 'autoembed'), 8);
108
-        add_filter('the_content_wp_core_only', 'wptexturize', 10);
109
-        add_filter('the_content_wp_core_only', 'wpautop', 10);
110
-        add_filter('the_content_wp_core_only', 'shortcode_unautop', 10);
111
-        add_filter('the_content_wp_core_only', 'prepend_attachment', 10);
112
-        if(function_exists('wp_make_content_images_responsive')) {
113
-            add_filter('the_content_wp_core_only', 'wp_make_content_images_responsive', 10);
114
-        }
115
-        add_filter('the_content_wp_core_only', 'do_shortcode', 11);
116
-        add_filter('the_content_wp_core_only', 'convert_smilies', 20);
117
-    }
101
+	/**
102
+	 * Verifies we've setup the standard WP core filters on  'the_content_wp_core_only' filter
103
+	 */
104
+	protected static function _setup_the_content_wp_core_only_filters()
105
+	{
106
+		add_filter('the_content_wp_core_only', array( $GLOBALS['wp_embed'], 'run_shortcode'), 8);
107
+		add_filter('the_content_wp_core_only', array( $GLOBALS['wp_embed'], 'autoembed'), 8);
108
+		add_filter('the_content_wp_core_only', 'wptexturize', 10);
109
+		add_filter('the_content_wp_core_only', 'wpautop', 10);
110
+		add_filter('the_content_wp_core_only', 'shortcode_unautop', 10);
111
+		add_filter('the_content_wp_core_only', 'prepend_attachment', 10);
112
+		if(function_exists('wp_make_content_images_responsive')) {
113
+			add_filter('the_content_wp_core_only', 'wp_make_content_images_responsive', 10);
114
+		}
115
+		add_filter('the_content_wp_core_only', 'do_shortcode', 11);
116
+		add_filter('the_content_wp_core_only', 'convert_smilies', 20);
117
+	}
118 118
 
119 119
 
120 120
 
121
-    public function getSchemaProperties()
122
-    {
123
-        return array(
124
-            'raw' => array(
125
-                'description' =>  sprintf(
126
-                    __('%s - the content as it exists in the database.', 'event_espresso'),
127
-                    $this->get_nicename()
128
-                ),
129
-                'type' => 'string'
130
-            ),
131
-            'rendered' => array(
132
-                'description' =>  sprintf(
133
-                    __('%s - the content rendered for display.', 'event_espresso'),
134
-                    $this->get_nicename()
135
-                ),
136
-                'type' => 'string'
137
-            )
138
-        );
139
-    }
121
+	public function getSchemaProperties()
122
+	{
123
+		return array(
124
+			'raw' => array(
125
+				'description' =>  sprintf(
126
+					__('%s - the content as it exists in the database.', 'event_espresso'),
127
+					$this->get_nicename()
128
+				),
129
+				'type' => 'string'
130
+			),
131
+			'rendered' => array(
132
+				'description' =>  sprintf(
133
+					__('%s - the content rendered for display.', 'event_espresso'),
134
+					$this->get_nicename()
135
+				),
136
+				'type' => 'string'
137
+			)
138
+		);
139
+	}
140 140
 }
141 141
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -29,7 +29,7 @@  discard block
 block discarded – undo
29 29
      */
30 30
     function prepare_for_set($value)
31 31
     {
32
-        if (! current_user_can('unfiltered_html')) {
32
+        if ( ! current_user_can('unfiltered_html')) {
33 33
             $value = wp_kses("$value", wp_kses_allowed_html('post'));
34 34
         }
35 35
         return parent::prepare_for_set($value);
@@ -51,13 +51,13 @@  discard block
 block discarded – undo
51 51
      */
52 52
     public function prepare_for_pretty_echoing($value_on_field_to_be_outputted, $schema = null)
53 53
     {
54
-        switch($schema){
54
+        switch ($schema) {
55 55
             case 'form_input':
56 56
                 return parent::prepare_for_pretty_echoing($value_on_field_to_be_outputted, $schema);
57 57
             case 'the_content':
58 58
 
59
-                if(doing_filter( 'the_content')){
60
-                    if( defined('WP_DEBUG') && WP_DEBUG){
59
+                if (doing_filter('the_content')) {
60
+                    if (defined('WP_DEBUG') && WP_DEBUG) {
61 61
                         throw new EE_Error(
62 62
                             sprintf(
63 63
                                 esc_html__('You have recursively called "%1$s" with %2$s set to %3$s which uses "%2$s" filter. You should use it with %2$s "%3$s" instead here.', 'event_espresso'),
@@ -91,7 +91,7 @@  discard block
 block discarded – undo
91 91
                 //ya know what? adding these filters is super fast. Let's just
92 92
                 //avoid needing to maintain global state and set this up as-needed
93 93
                 remove_all_filters('the_content_wp_core_only');
94
-                do_action( 'AHEE__EE_Post_Content_Field__prepare_for_pretty_echoing__the_content_wp_core_only__done');
94
+                do_action('AHEE__EE_Post_Content_Field__prepare_for_pretty_echoing__the_content_wp_core_only__done');
95 95
                 return $return_value;
96 96
         }
97 97
     }
@@ -103,13 +103,13 @@  discard block
 block discarded – undo
103 103
      */
104 104
     protected static function _setup_the_content_wp_core_only_filters()
105 105
     {
106
-        add_filter('the_content_wp_core_only', array( $GLOBALS['wp_embed'], 'run_shortcode'), 8);
107
-        add_filter('the_content_wp_core_only', array( $GLOBALS['wp_embed'], 'autoembed'), 8);
106
+        add_filter('the_content_wp_core_only', array($GLOBALS['wp_embed'], 'run_shortcode'), 8);
107
+        add_filter('the_content_wp_core_only', array($GLOBALS['wp_embed'], 'autoembed'), 8);
108 108
         add_filter('the_content_wp_core_only', 'wptexturize', 10);
109 109
         add_filter('the_content_wp_core_only', 'wpautop', 10);
110 110
         add_filter('the_content_wp_core_only', 'shortcode_unautop', 10);
111 111
         add_filter('the_content_wp_core_only', 'prepend_attachment', 10);
112
-        if(function_exists('wp_make_content_images_responsive')) {
112
+        if (function_exists('wp_make_content_images_responsive')) {
113 113
             add_filter('the_content_wp_core_only', 'wp_make_content_images_responsive', 10);
114 114
         }
115 115
         add_filter('the_content_wp_core_only', 'do_shortcode', 11);
Please login to merge, or discard this patch.
core/db_classes/EE_CPT_Base.class.php 2 patches
Indentation   +82 added lines, -82 removed lines patch added patch discarded remove patch
@@ -36,9 +36,9 @@  discard block
 block discarded – undo
36 36
 	 */
37 37
 	protected $_feature_image = array();
38 38
 
39
-    /**
40
-     * @var WP_Post the WP_Post that corresponds with this CPT model object
41
-     */
39
+	/**
40
+	 * @var WP_Post the WP_Post that corresponds with this CPT model object
41
+	 */
42 42
 	protected $_wp_post;
43 43
 
44 44
 
@@ -46,75 +46,75 @@  discard block
 block discarded – undo
46 46
 
47 47
 
48 48
 
49
-    /**
50
-     * Returns the WP post associated with this CPT model object. If this CPT is saved, fetches it
51
-     * from the DB. Otherwise, create an unsaved WP_POst object. Caches the post internally.
52
-     * @return WP_Post
53
-     */
54
-    public function wp_post(){
55
-        global $wpdb;
56
-        if (! $this->_wp_post instanceof WP_Post) {
57
-            if ($this->ID()) {
58
-                $this->_wp_post = get_post($this->ID());
59
-            } else {
60
-                $simulated_db_result = new stdClass();
61
-                foreach($this->get_model()->field_settings(true) as $field_name => $field_obj){
62
-                    if ($this->get_model()->get_table_obj_by_alias($field_obj->get_table_alias())->get_table_name() === $wpdb->posts){
63
-                        $column = $field_obj->get_table_column();
64
-
65
-                        if($field_obj instanceof EE_Datetime_Field){
66
-                            $value_on_model_obj = $this->get_DateTime_object($field_name);
67
-                        } elseif( $field_obj->is_db_only_field()){
68
-                            $value_on_model_obj = $field_obj->get_default_value();
69
-                        } else {
70
-                            $value_on_model_obj = $this->get_raw($field_name);
71
-                        }
72
-                        $simulated_db_result->{$column} = $field_obj->prepare_for_use_in_db($value_on_model_obj);
73
-                    }
74
-                }
75
-                $this->_wp_post = new WP_Post($simulated_db_result);
76
-            }
77
-            //and let's make retrieving the EE CPT object easy too
78
-            $classname = get_class($this);
79
-            if (! isset($this->_wp_post->{$classname})) {
80
-                $this->_wp_post->{$classname} = $this;
81
-            }
82
-        }
83
-        return $this->_wp_post;
84
-    }
85
-
86
-    /**
87
-     * When fetching a new value for a post field that uses the global $post for rendering,
88
-     * set the global $post temporarily to be this model object; and afterwards restore it
89
-     * @param string $fieldname
90
-     * @param bool $pretty
91
-     * @param string $extra_cache_ref
92
-     * @return mixed
93
-     */
94
-    protected function _get_fresh_property($fieldname, $pretty = false, $extra_cache_ref = null)
95
-    {
96
-        global $post;
97
-
98
-        if ( $pretty
99
-            && (
100
-                ! (
101
-                       $post instanceof WP_Post
102
-                       && $post->ID
103
-                   )
104
-                || (int)$post->ID !== $this->ID()
105
-             )
106
-            && $this->get_model()->field_settings_for($fieldname) instanceof EE_Post_Content_Field ) {
107
-            $old_post = $post;
108
-            $post = $this->wp_post();
109
-            $return_value = parent::_get_fresh_property($fieldname, $pretty, $extra_cache_ref);
110
-            $post = $old_post;
111
-        } else {
112
-            $return_value = parent::_get_fresh_property($fieldname, $pretty, $extra_cache_ref);
113
-        }
114
-        return $return_value;
115
-    }
116
-
117
-    /**
49
+	/**
50
+	 * Returns the WP post associated with this CPT model object. If this CPT is saved, fetches it
51
+	 * from the DB. Otherwise, create an unsaved WP_POst object. Caches the post internally.
52
+	 * @return WP_Post
53
+	 */
54
+	public function wp_post(){
55
+		global $wpdb;
56
+		if (! $this->_wp_post instanceof WP_Post) {
57
+			if ($this->ID()) {
58
+				$this->_wp_post = get_post($this->ID());
59
+			} else {
60
+				$simulated_db_result = new stdClass();
61
+				foreach($this->get_model()->field_settings(true) as $field_name => $field_obj){
62
+					if ($this->get_model()->get_table_obj_by_alias($field_obj->get_table_alias())->get_table_name() === $wpdb->posts){
63
+						$column = $field_obj->get_table_column();
64
+
65
+						if($field_obj instanceof EE_Datetime_Field){
66
+							$value_on_model_obj = $this->get_DateTime_object($field_name);
67
+						} elseif( $field_obj->is_db_only_field()){
68
+							$value_on_model_obj = $field_obj->get_default_value();
69
+						} else {
70
+							$value_on_model_obj = $this->get_raw($field_name);
71
+						}
72
+						$simulated_db_result->{$column} = $field_obj->prepare_for_use_in_db($value_on_model_obj);
73
+					}
74
+				}
75
+				$this->_wp_post = new WP_Post($simulated_db_result);
76
+			}
77
+			//and let's make retrieving the EE CPT object easy too
78
+			$classname = get_class($this);
79
+			if (! isset($this->_wp_post->{$classname})) {
80
+				$this->_wp_post->{$classname} = $this;
81
+			}
82
+		}
83
+		return $this->_wp_post;
84
+	}
85
+
86
+	/**
87
+	 * When fetching a new value for a post field that uses the global $post for rendering,
88
+	 * set the global $post temporarily to be this model object; and afterwards restore it
89
+	 * @param string $fieldname
90
+	 * @param bool $pretty
91
+	 * @param string $extra_cache_ref
92
+	 * @return mixed
93
+	 */
94
+	protected function _get_fresh_property($fieldname, $pretty = false, $extra_cache_ref = null)
95
+	{
96
+		global $post;
97
+
98
+		if ( $pretty
99
+			&& (
100
+				! (
101
+					   $post instanceof WP_Post
102
+					   && $post->ID
103
+				   )
104
+				|| (int)$post->ID !== $this->ID()
105
+			 )
106
+			&& $this->get_model()->field_settings_for($fieldname) instanceof EE_Post_Content_Field ) {
107
+			$old_post = $post;
108
+			$post = $this->wp_post();
109
+			$return_value = parent::_get_fresh_property($fieldname, $pretty, $extra_cache_ref);
110
+			$post = $old_post;
111
+		} else {
112
+			$return_value = parent::_get_fresh_property($fieldname, $pretty, $extra_cache_ref);
113
+		}
114
+		return $return_value;
115
+	}
116
+
117
+	/**
118 118
 	 * Adds to the specified event category. If it category doesn't exist, creates it.
119 119
 	 * @param string $category_name
120 120
 	 * @param string $category_description    optional
@@ -399,14 +399,14 @@  discard block
 block discarded – undo
399 399
 
400 400
 
401 401
 
402
-    /**
403
-     * Don't serialize the WP Post. That's just duplicate data and we want to avoid recursion
404
-     * @return array
405
-     */
406
-    public function __sleep()
407
-    {
408
-        $properties_to_serialize = parent::__sleep();
409
-        $properties_to_serialize = array_diff( $properties_to_serialize, array('_wp_post'));
410
-        return $properties_to_serialize;
411
-    }
402
+	/**
403
+	 * Don't serialize the WP Post. That's just duplicate data and we want to avoid recursion
404
+	 * @return array
405
+	 */
406
+	public function __sleep()
407
+	{
408
+		$properties_to_serialize = parent::__sleep();
409
+		$properties_to_serialize = array_diff( $properties_to_serialize, array('_wp_post'));
410
+		return $properties_to_serialize;
411
+	}
412 412
 }
Please login to merge, or discard this patch.
Spacing   +67 added lines, -67 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1
-<?php if ( !defined( 'EVENT_ESPRESSO_VERSION' ) ) {
2
-	exit( 'No direct script access allowed' );
1
+<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) {
2
+	exit('No direct script access allowed');
3 3
 }
4 4
 /**
5 5
  * Event Espresso
@@ -51,20 +51,20 @@  discard block
 block discarded – undo
51 51
      * from the DB. Otherwise, create an unsaved WP_POst object. Caches the post internally.
52 52
      * @return WP_Post
53 53
      */
54
-    public function wp_post(){
54
+    public function wp_post() {
55 55
         global $wpdb;
56
-        if (! $this->_wp_post instanceof WP_Post) {
56
+        if ( ! $this->_wp_post instanceof WP_Post) {
57 57
             if ($this->ID()) {
58 58
                 $this->_wp_post = get_post($this->ID());
59 59
             } else {
60 60
                 $simulated_db_result = new stdClass();
61
-                foreach($this->get_model()->field_settings(true) as $field_name => $field_obj){
62
-                    if ($this->get_model()->get_table_obj_by_alias($field_obj->get_table_alias())->get_table_name() === $wpdb->posts){
61
+                foreach ($this->get_model()->field_settings(true) as $field_name => $field_obj) {
62
+                    if ($this->get_model()->get_table_obj_by_alias($field_obj->get_table_alias())->get_table_name() === $wpdb->posts) {
63 63
                         $column = $field_obj->get_table_column();
64 64
 
65
-                        if($field_obj instanceof EE_Datetime_Field){
65
+                        if ($field_obj instanceof EE_Datetime_Field) {
66 66
                             $value_on_model_obj = $this->get_DateTime_object($field_name);
67
-                        } elseif( $field_obj->is_db_only_field()){
67
+                        } elseif ($field_obj->is_db_only_field()) {
68 68
                             $value_on_model_obj = $field_obj->get_default_value();
69 69
                         } else {
70 70
                             $value_on_model_obj = $this->get_raw($field_name);
@@ -76,7 +76,7 @@  discard block
 block discarded – undo
76 76
             }
77 77
             //and let's make retrieving the EE CPT object easy too
78 78
             $classname = get_class($this);
79
-            if (! isset($this->_wp_post->{$classname})) {
79
+            if ( ! isset($this->_wp_post->{$classname})) {
80 80
                 $this->_wp_post->{$classname} = $this;
81 81
             }
82 82
         }
@@ -95,15 +95,15 @@  discard block
 block discarded – undo
95 95
     {
96 96
         global $post;
97 97
 
98
-        if ( $pretty
98
+        if ($pretty
99 99
             && (
100 100
                 ! (
101 101
                        $post instanceof WP_Post
102 102
                        && $post->ID
103 103
                    )
104
-                || (int)$post->ID !== $this->ID()
104
+                || (int) $post->ID !== $this->ID()
105 105
              )
106
-            && $this->get_model()->field_settings_for($fieldname) instanceof EE_Post_Content_Field ) {
106
+            && $this->get_model()->field_settings_for($fieldname) instanceof EE_Post_Content_Field) {
107 107
             $old_post = $post;
108 108
             $post = $this->wp_post();
109 109
             $return_value = parent::_get_fresh_property($fieldname, $pretty, $extra_cache_ref);
@@ -121,8 +121,8 @@  discard block
 block discarded – undo
121 121
 	 * @param int    $parent_term_taxonomy_id optional
122 122
 	 * @return EE_Term_Taxonomy
123 123
 	 */
124
-	function add_event_category( $category_name, $category_description = NULL, $parent_term_taxonomy_id = NULL ) {
125
-		return $this->get_model()->add_event_category( $this, $category_name, $category_description, $parent_term_taxonomy_id );
124
+	function add_event_category($category_name, $category_description = NULL, $parent_term_taxonomy_id = NULL) {
125
+		return $this->get_model()->add_event_category($this, $category_name, $category_description, $parent_term_taxonomy_id);
126 126
 	}
127 127
 
128 128
 
@@ -132,8 +132,8 @@  discard block
 block discarded – undo
132 132
 	 * @param string $category_name
133 133
 	 * @return bool
134 134
 	 */
135
-	function remove_event_category( $category_name ) {
136
-		return $this->get_model()->remove_event_category( $this, $category_name );
135
+	function remove_event_category($category_name) {
136
+		return $this->get_model()->remove_event_category($this, $category_name);
137 137
 	}
138 138
 
139 139
 
@@ -144,14 +144,14 @@  discard block
 block discarded – undo
144 144
 	 * @param EE_Term_Taxonomy $term_taxonomy
145 145
 	 * @return EE_Base_Class the relation was removed from
146 146
 	 */
147
-	function remove_relation_to_term_taxonomy( $term_taxonomy ) {
148
-		if ( !$term_taxonomy ) {
149
-			EE_Error::add_error( sprintf( __( "No Term_Taxonomy provided which to remove from model object of type %s and id %d", "event_espresso" ), get_class( $this ), $this->ID() ), __FILE__, __FUNCTION__, __LINE__ );
147
+	function remove_relation_to_term_taxonomy($term_taxonomy) {
148
+		if ( ! $term_taxonomy) {
149
+			EE_Error::add_error(sprintf(__("No Term_Taxonomy provided which to remove from model object of type %s and id %d", "event_espresso"), get_class($this), $this->ID()), __FILE__, __FUNCTION__, __LINE__);
150 150
 			return NULL;
151 151
 		}
152
-		$term_taxonomy->set_count( $term_taxonomy->count() - 1 );
152
+		$term_taxonomy->set_count($term_taxonomy->count() - 1);
153 153
 		$term_taxonomy->save();
154
-		return $this->_remove_relation_to( $term_taxonomy, 'Term_Taxonomy' );
154
+		return $this->_remove_relation_to($term_taxonomy, 'Term_Taxonomy');
155 155
 	}
156 156
 
157 157
 
@@ -175,7 +175,7 @@  discard block
 block discarded – undo
175 175
 	 * @return int
176 176
 	 */
177 177
 	public function parent() {
178
-		return $this->get( 'parent' );
178
+		return $this->get('parent');
179 179
 	}
180 180
 
181 181
 
@@ -185,7 +185,7 @@  discard block
 block discarded – undo
185 185
 	 * @return string
186 186
 	 */
187 187
 	public function status() {
188
-		return $this->get( 'status' );
188
+		return $this->get('status');
189 189
 	}
190 190
 
191 191
 
@@ -193,8 +193,8 @@  discard block
 block discarded – undo
193 193
 	/**
194 194
 	 * @param string $status
195 195
 	 */
196
-	public function set_status( $status ) {
197
-		$this->set( 'status', $status );
196
+	public function set_status($status) {
197
+		$this->set('status', $status);
198 198
 	}
199 199
 
200 200
 
@@ -208,12 +208,12 @@  discard block
 block discarded – undo
208 208
 	 * @param string|array $attr Optional. Query string or array of attributes.
209 209
 	 * @return string HTML image element
210 210
 	 */
211
-	protected function _get_feature_image( $size, $attr ) {
211
+	protected function _get_feature_image($size, $attr) {
212 212
 		//first let's see if we already have the _feature_image property set AND if it has a cached element on it FOR the given size
213
-		$attr_key = is_array( $attr ) ? implode( '_', $attr ) : $attr;
214
-		$cache_key = is_array( $size ) ? implode( '_', $size ) . $attr_key : $size . $attr_key;
215
-		$this->_feature_image[ $cache_key ] = isset( $this->_feature_image[ $cache_key ] ) ? $this->_feature_image[ $cache_key ] : $this->get_model()->get_feature_image( $this->ID(), $size, $attr );
216
-		return $this->_feature_image[ $cache_key ];
213
+		$attr_key = is_array($attr) ? implode('_', $attr) : $attr;
214
+		$cache_key = is_array($size) ? implode('_', $size).$attr_key : $size.$attr_key;
215
+		$this->_feature_image[$cache_key] = isset($this->_feature_image[$cache_key]) ? $this->_feature_image[$cache_key] : $this->get_model()->get_feature_image($this->ID(), $size, $attr);
216
+		return $this->_feature_image[$cache_key];
217 217
 	}
218 218
 
219 219
 
@@ -224,8 +224,8 @@  discard block
 block discarded – undo
224 224
 	 * @param string|array $attr
225 225
 	 * @return string of html
226 226
 	 */
227
-	public function feature_image( $size = 'thumbnail', $attr = '' ) {
228
-		return $this->_get_feature_image( $size, $attr );
227
+	public function feature_image($size = 'thumbnail', $attr = '') {
228
+		return $this->_get_feature_image($size, $attr);
229 229
 	}
230 230
 
231 231
 
@@ -235,9 +235,9 @@  discard block
 block discarded – undo
235 235
 	 * @param  string|array $size can either be a string: 'thumbnail', 'medium', 'large', 'full' OR 2-item array representing width and height in pixels eg. array(32,32).
236 236
 	 * @return string|boolean          the url of the image or false if not found
237 237
 	 */
238
-	public function feature_image_url( $size = 'thumbnail' ) {
239
-		$attachment = wp_get_attachment_image_src( get_post_thumbnail_id( $this->ID() ), $size );
240
-		return !empty( $attachment ) ? $attachment[ 0 ] : FALSE;
238
+	public function feature_image_url($size = 'thumbnail') {
239
+		$attachment = wp_get_attachment_image_src(get_post_thumbnail_id($this->ID()), $size);
240
+		return ! empty($attachment) ? $attachment[0] : FALSE;
241 241
 	}
242 242
 
243 243
 
@@ -259,36 +259,36 @@  discard block
 block discarded – undo
259 259
 	 *                                 This array is INDEXED by RELATED OBJ NAME (so it corresponds with the obj_names sent);
260 260
 	 * @return void
261 261
 	 */
262
-	public function restore_revision( $revision_id, $related_obj_names = array(), $where_query = array() ) {
262
+	public function restore_revision($revision_id, $related_obj_names = array(), $where_query = array()) {
263 263
 		//get revision object
264
-		$revision_obj = $this->get_model()->get_one_by_ID( $revision_id );
265
-		if ( $revision_obj instanceof EE_CPT_Base ) {
264
+		$revision_obj = $this->get_model()->get_one_by_ID($revision_id);
265
+		if ($revision_obj instanceof EE_CPT_Base) {
266 266
 			//no related_obj_name so we assume we're saving a revision on this object.
267
-			if ( empty( $related_obj_names ) ) {
267
+			if (empty($related_obj_names)) {
268 268
 				$fields = $this->get_model()->get_meta_table_fields();
269
-				foreach ( $fields as $field ) {
270
-					$this->set( $field, $revision_obj->get( $field ) );
269
+				foreach ($fields as $field) {
270
+					$this->set($field, $revision_obj->get($field));
271 271
 				}
272 272
 				$this->save();
273 273
 			}
274
-			$related_obj_names = (array)$related_obj_names;
275
-			foreach ( $related_obj_names as $related_name ) {
274
+			$related_obj_names = (array) $related_obj_names;
275
+			foreach ($related_obj_names as $related_name) {
276 276
 				//related_obj_name so we're saving a revision on an object related to this object
277 277
 				//do we have $where_query params for this related object?  If we do then we include that.
278
-				$cols_n_values = isset( $where_query[ $related_name ] ) ? $where_query[ $related_name ] : array();
279
-				$where_params = !empty( $cols_n_values ) ? array( $cols_n_values ) : array();
280
-				$related_objs = $this->get_many_related( $related_name, $where_params );
281
-				$revision_related_objs = $revision_obj->get_many_related( $related_name, $where_params );
278
+				$cols_n_values = isset($where_query[$related_name]) ? $where_query[$related_name] : array();
279
+				$where_params = ! empty($cols_n_values) ? array($cols_n_values) : array();
280
+				$related_objs = $this->get_many_related($related_name, $where_params);
281
+				$revision_related_objs = $revision_obj->get_many_related($related_name, $where_params);
282 282
 				//load helper
283 283
 				//remove related objs from this object that are not in revision
284 284
 				//array_diff *should* work cause I think objects are indexed by ID?
285
-				$related_to_remove = EEH_Array::object_array_diff( $related_objs, $revision_related_objs );
286
-				foreach ( $related_to_remove as $rr ) {
287
-					$this->_remove_relation_to( $rr, $related_name, $cols_n_values );
285
+				$related_to_remove = EEH_Array::object_array_diff($related_objs, $revision_related_objs);
286
+				foreach ($related_to_remove as $rr) {
287
+					$this->_remove_relation_to($rr, $related_name, $cols_n_values);
288 288
 				}
289 289
 				//add all related objs attached to revision to this object
290
-				foreach ( $revision_related_objs as $r_obj ) {
291
-					$this->_add_relation_to( $r_obj, $related_name, $cols_n_values );
290
+				foreach ($revision_related_objs as $r_obj) {
291
+					$this->_add_relation_to($r_obj, $related_name, $cols_n_values);
292 292
 				}
293 293
 			}
294 294
 		}
@@ -304,8 +304,8 @@  discard block
 block discarded – undo
304 304
 	 * <li>If $single is set to false, or left blank, the function returns an array containing all values of the specified key.</li>
305 305
 	 * <li>If $single is set to true, the function returns the first value of the specified key (not in an array</li></ul>
306 306
 	 */
307
-	public function get_post_meta( $meta_key = NULL, $single = FALSE ) {
308
-		return get_post_meta( $this->ID(), $meta_key, $single );
307
+	public function get_post_meta($meta_key = NULL, $single = FALSE) {
308
+		return get_post_meta($this->ID(), $meta_key, $single);
309 309
 	}
310 310
 
311 311
 
@@ -317,11 +317,11 @@  discard block
 block discarded – undo
317 317
 	 * @param mixed  $prev_value
318 318
 	 * @return mixed Returns meta_id if the meta doesn't exist, otherwise returns true on success and false on failure. NOTE: If the meta_value passed to this function is the same as the value that is already in the database, this function returns false.
319 319
 	 */
320
-	public function update_post_meta( $meta_key, $meta_value, $prev_value = NULL ) {
321
-		if ( ! $this->ID() ) {
320
+	public function update_post_meta($meta_key, $meta_value, $prev_value = NULL) {
321
+		if ( ! $this->ID()) {
322 322
 			$this->save();
323 323
 		}
324
-		return update_post_meta( $this->ID(), $meta_key, $meta_value, $prev_value );
324
+		return update_post_meta($this->ID(), $meta_key, $meta_value, $prev_value);
325 325
 	}
326 326
 
327 327
 
@@ -333,11 +333,11 @@  discard block
 block discarded – undo
333 333
 	 * @param bool  $unique . If postmeta for this $meta_key already exists, whether to add an additional item or not
334 334
 	 * @return boolean Boolean true, except if the $unique argument was set to true and a custom field with the given key already exists, in which case false is returned.
335 335
 	 */
336
-	public function add_post_meta( $meta_key, $meta_value, $unique = FALSE ) {
337
-		if ( $this->ID() ) {
336
+	public function add_post_meta($meta_key, $meta_value, $unique = FALSE) {
337
+		if ($this->ID()) {
338 338
 			$this->save();
339 339
 		}
340
-		return add_post_meta( $this->ID(), $meta_key, $meta_value, $unique );
340
+		return add_post_meta($this->ID(), $meta_key, $meta_value, $unique);
341 341
 	}
342 342
 
343 343
 
@@ -349,13 +349,13 @@  discard block
 block discarded – undo
349 349
 	 * @param mixed $meta_value
350 350
 	 * @return boolean False for failure. True for success.
351 351
 	 */
352
-	public function delete_post_meta( $meta_key, $meta_value = '' ) {
353
-		if ( ! $this->ID() ) {
352
+	public function delete_post_meta($meta_key, $meta_value = '') {
353
+		if ( ! $this->ID()) {
354 354
 			//there are obviously no postmetas for this if it's not saved
355 355
 			//so let's just report this as a success
356 356
 			return true;
357 357
 		}
358
-		return delete_post_meta( $this->ID(), $meta_key, $meta_value );
358
+		return delete_post_meta($this->ID(), $meta_key, $meta_value);
359 359
 	}
360 360
 
361 361
 
@@ -365,7 +365,7 @@  discard block
 block discarded – undo
365 365
 	 * @return string
366 366
 	 */
367 367
 	public function get_permalink() {
368
-		return get_permalink( $this->ID() );
368
+		return get_permalink($this->ID());
369 369
 	}
370 370
 
371 371
 
@@ -375,8 +375,8 @@  discard block
 block discarded – undo
375 375
 	 * @param array $query_params
376 376
 	 * @return EE_Term_Taxonomy
377 377
 	 */
378
-	public function term_taxonomies( $query_params = array() ) {
379
-		return $this->get_many_related( 'Term_Taxonomy', $query_params );
378
+	public function term_taxonomies($query_params = array()) {
379
+		return $this->get_many_related('Term_Taxonomy', $query_params);
380 380
 	}
381 381
 
382 382
 
@@ -406,7 +406,7 @@  discard block
 block discarded – undo
406 406
     public function __sleep()
407 407
     {
408 408
         $properties_to_serialize = parent::__sleep();
409
-        $properties_to_serialize = array_diff( $properties_to_serialize, array('_wp_post'));
409
+        $properties_to_serialize = array_diff($properties_to_serialize, array('_wp_post'));
410 410
         return $properties_to_serialize;
411 411
     }
412 412
 }
Please login to merge, or discard this patch.
core/services/shortcodes/EspressoShortcode.php 2 patches
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -84,7 +84,7 @@  discard block
 block discarded – undo
84 84
             }
85 85
         }
86 86
         return $this->shortcodeContent(
87
-            $this->sanitizeAttributes((array)$attributes)
87
+            $this->sanitizeAttributes((array) $attributes)
88 88
         );
89 89
     }
90 90
 
@@ -112,8 +112,8 @@  discard block
 block discarded – undo
112 112
             // serialized attributes
113 113
             wp_json_encode($attributes),
114 114
             // Closure for generating content if cache is expired
115
-            function () use ($shortcode, $attributes) {
116
-                if($shortcode->initialized() === false){
115
+            function() use ($shortcode, $attributes) {
116
+                if ($shortcode->initialized() === false) {
117 117
                     $shortcode->initializeShortcode();
118 118
                 }
119 119
                 return $shortcode->processShortcode($attributes);
@@ -247,7 +247,7 @@  discard block
 block discarded – undo
247 247
      * Returns whether or not this shortcode has been initialized
248 248
      * @return boolean
249 249
      */
250
-    public function initialized(){
250
+    public function initialized() {
251 251
         return $this->initialized;
252 252
     }
253 253
 
Please login to merge, or discard this patch.
Indentation   +224 added lines, -224 removed lines patch added patch discarded remove patch
@@ -23,230 +23,230 @@
 block discarded – undo
23 23
 abstract class EspressoShortcode implements ShortcodeInterface
24 24
 {
25 25
 
26
-    /**
27
-     * transient prefix
28
-     *
29
-     * @type string
30
-     */
31
-    const CACHE_TRANSIENT_PREFIX = 'ee_sc_';
32
-
33
-    /**
34
-     * @var PostRelatedCacheManager $cache_manager
35
-     */
36
-    private $cache_manager;
37
-
38
-    /**
39
-     * true if ShortcodeInterface::initializeShortcode() has been called
40
-     * if false, then that will get called before processing
41
-     *
42
-     * @var boolean $initialized
43
-     */
44
-    private $initialized = false;
45
-
46
-
47
-
48
-    /**
49
-     * EspressoShortcode constructor
50
-     *
51
-     * @param PostRelatedCacheManager $cache_manager
52
-     */
53
-    public function __construct(PostRelatedCacheManager $cache_manager)
54
-    {
55
-        $this->cache_manager = $cache_manager;
56
-    }
57
-
58
-
59
-
60
-    /**
61
-     * @return void
62
-     */
63
-    public function shortcodeHasBeenInitialized()
64
-    {
65
-        $this->initialized = true;
66
-    }
67
-
68
-
69
-
70
-    /**
71
-     * enqueues scripts then processes the shortcode
72
-     *
73
-     * @param array $attributes
74
-     * @return string
75
-     * @throws EE_Error
76
-     */
77
-    final public function processShortcodeCallback($attributes = array())
78
-    {
79
-        if ($this instanceof EnqueueAssetsInterface) {
80
-            if (is_admin()) {
81
-                $this->enqueueAdminScripts();
82
-            } else {
83
-                $this->enqueueScripts();
84
-            }
85
-        }
86
-        return $this->shortcodeContent(
87
-            $this->sanitizeAttributes((array)$attributes)
88
-        );
89
-    }
90
-
91
-
92
-
93
-    /**
94
-     * If shortcode caching is enabled for the shortcode,
95
-     * and cached results exist, then that will be returned
96
-     * else new content will be generated.
97
-     * If caching is enabled, then the new content will be cached for later.
98
-     *
99
-     * @param array $attributes
100
-     * @return mixed|string
101
-     * @throws EE_Error
102
-     */
103
-    private function shortcodeContent(array $attributes)
104
-    {
105
-        $shortcode = $this;
106
-        $post_ID = $this->currentPostID();
107
-        // something like "SC_EVENTS-123"
108
-        $cache_ID = $this->shortcodeCacheID($post_ID);
109
-        $this->cache_manager->clearPostRelatedCacheOnUpdate($post_ID, $cache_ID);
110
-        return $this->cache_manager->get(
111
-            $cache_ID,
112
-            // serialized attributes
113
-            wp_json_encode($attributes),
114
-            // Closure for generating content if cache is expired
115
-            function () use ($shortcode, $attributes) {
116
-                if($shortcode->initialized() === false){
117
-                    $shortcode->initializeShortcode();
118
-                }
119
-                return $shortcode->processShortcode($attributes);
120
-            },
121
-            // filterable cache expiration set by each shortcode
122
-            apply_filters(
123
-                'FHEE__EventEspresso_core_services_shortcodes_EspressoShortcode__shortcodeContent__cache_expiration',
124
-                $this->cacheExpiration(),
125
-                $this->getTag(),
126
-                $this
127
-            )
128
-        );
129
-    }
130
-
131
-
132
-
133
-    /**
134
-     * @return int
135
-     * @throws EE_Error
136
-     */
137
-    private function currentPostID()
138
-    {
139
-        // try to get EE_Event any way we can
140
-        $event = EEH_Event_View::get_event();
141
-        // then get some kind of ID
142
-        if ($event instanceof EE_Event) {
143
-            return $event->ID();
144
-        }
145
-        global $post;
146
-        if ($post instanceof WP_Post) {
147
-            return $post->ID;
148
-        }
149
-        return 0;
150
-    }
151
-
152
-
153
-
154
-    /**
155
-     * @param int $post_ID
156
-     * @return string
157
-     * @throws EE_Error
158
-     */
159
-    private function shortcodeCacheID($post_ID)
160
-    {
161
-        $tag = str_replace('ESPRESSO_', '', $this->getTag());
162
-        return "SC_{$tag}-{$post_ID}";
163
-    }
164
-
165
-
166
-
167
-    /**
168
-     * array for defining custom attribute sanitization callbacks,
169
-     * where keys match keys in your attributes array,
170
-     * and values represent the sanitization function you wish to be applied to that attribute.
171
-     * So for example, if you had an integer attribute named "event_id"
172
-     * that you wanted to be sanitized using absint(),
173
-     * then you would return the following:
174
-     *      array('event_id' => 'absint')
175
-     * Entering 'skip_sanitization' for the callback value
176
-     * means that no sanitization will be applied
177
-     * on the assumption that the attribute
178
-     * will be sanitized at some point... right?
179
-     * You wouldn't pass around unsanitized attributes would you?
180
-     * That would be very Tom Foolery of you!!!
181
-     *
182
-     * @return array
183
-     */
184
-    protected function customAttributeSanitizationMap()
185
-    {
186
-        return array();
187
-    }
188
-
189
-
190
-
191
-    /**
192
-     * Performs basic sanitization on shortcode attributes
193
-     * Since incoming attributes from the shortcode usage in the WP editor will all be strings,
194
-     * most attributes will by default be sanitized using the sanitize_text_field() function.
195
-     * This can be overridden using the customAttributeSanitizationMap() method (see above),
196
-     * all other attributes would be sanitized using the defaults in the switch statement below
197
-     *
198
-     * @param array $attributes
199
-     * @return array
200
-     */
201
-    private function sanitizeAttributes(array $attributes)
202
-    {
203
-        $custom_sanitization = $this->customAttributeSanitizationMap();
204
-        foreach ($attributes as $key => $value) {
205
-            // is a custom sanitization callback specified ?
206
-            if (isset($custom_sanitization[$key])) {
207
-                $callback = $custom_sanitization[$key];
208
-                if ($callback === 'skip_sanitization') {
209
-                    $attributes[$key] = $value;
210
-                    continue;
211
-                }
212
-                if (function_exists($callback)) {
213
-                    $attributes[$key] = $callback($value);
214
-                    continue;
215
-                }
216
-            }
217
-            switch (true) {
218
-                case $value === null :
219
-                case is_int($value) :
220
-                case is_float($value) :
221
-                    // typical booleans
222
-                case in_array($value, array(true, 'true', '1', 'on', 'yes', false, 'false', '0', 'off', 'no'), true) :
223
-                    $attributes[$key] = $value;
224
-                    break;
225
-                case is_string($value) :
226
-                    $attributes[$key] = sanitize_text_field($value);
227
-                    break;
228
-                case is_array($value) :
229
-                    $attributes[$key] = $this->sanitizeAttributes($value);
230
-                    break;
231
-                default :
232
-                    // only remaining data types are Object and Resource
233
-                    // which are not allowed as shortcode attributes
234
-                    $attributes[$key] = null;
235
-                    break;
236
-            }
237
-        }
238
-        return $attributes;
239
-    }
240
-
241
-
242
-
243
-    /**
244
-     * Returns whether or not this shortcode has been initialized
245
-     * @return boolean
246
-     */
247
-    public function initialized(){
248
-        return $this->initialized;
249
-    }
26
+	/**
27
+	 * transient prefix
28
+	 *
29
+	 * @type string
30
+	 */
31
+	const CACHE_TRANSIENT_PREFIX = 'ee_sc_';
32
+
33
+	/**
34
+	 * @var PostRelatedCacheManager $cache_manager
35
+	 */
36
+	private $cache_manager;
37
+
38
+	/**
39
+	 * true if ShortcodeInterface::initializeShortcode() has been called
40
+	 * if false, then that will get called before processing
41
+	 *
42
+	 * @var boolean $initialized
43
+	 */
44
+	private $initialized = false;
45
+
46
+
47
+
48
+	/**
49
+	 * EspressoShortcode constructor
50
+	 *
51
+	 * @param PostRelatedCacheManager $cache_manager
52
+	 */
53
+	public function __construct(PostRelatedCacheManager $cache_manager)
54
+	{
55
+		$this->cache_manager = $cache_manager;
56
+	}
57
+
58
+
59
+
60
+	/**
61
+	 * @return void
62
+	 */
63
+	public function shortcodeHasBeenInitialized()
64
+	{
65
+		$this->initialized = true;
66
+	}
67
+
68
+
69
+
70
+	/**
71
+	 * enqueues scripts then processes the shortcode
72
+	 *
73
+	 * @param array $attributes
74
+	 * @return string
75
+	 * @throws EE_Error
76
+	 */
77
+	final public function processShortcodeCallback($attributes = array())
78
+	{
79
+		if ($this instanceof EnqueueAssetsInterface) {
80
+			if (is_admin()) {
81
+				$this->enqueueAdminScripts();
82
+			} else {
83
+				$this->enqueueScripts();
84
+			}
85
+		}
86
+		return $this->shortcodeContent(
87
+			$this->sanitizeAttributes((array)$attributes)
88
+		);
89
+	}
90
+
91
+
92
+
93
+	/**
94
+	 * If shortcode caching is enabled for the shortcode,
95
+	 * and cached results exist, then that will be returned
96
+	 * else new content will be generated.
97
+	 * If caching is enabled, then the new content will be cached for later.
98
+	 *
99
+	 * @param array $attributes
100
+	 * @return mixed|string
101
+	 * @throws EE_Error
102
+	 */
103
+	private function shortcodeContent(array $attributes)
104
+	{
105
+		$shortcode = $this;
106
+		$post_ID = $this->currentPostID();
107
+		// something like "SC_EVENTS-123"
108
+		$cache_ID = $this->shortcodeCacheID($post_ID);
109
+		$this->cache_manager->clearPostRelatedCacheOnUpdate($post_ID, $cache_ID);
110
+		return $this->cache_manager->get(
111
+			$cache_ID,
112
+			// serialized attributes
113
+			wp_json_encode($attributes),
114
+			// Closure for generating content if cache is expired
115
+			function () use ($shortcode, $attributes) {
116
+				if($shortcode->initialized() === false){
117
+					$shortcode->initializeShortcode();
118
+				}
119
+				return $shortcode->processShortcode($attributes);
120
+			},
121
+			// filterable cache expiration set by each shortcode
122
+			apply_filters(
123
+				'FHEE__EventEspresso_core_services_shortcodes_EspressoShortcode__shortcodeContent__cache_expiration',
124
+				$this->cacheExpiration(),
125
+				$this->getTag(),
126
+				$this
127
+			)
128
+		);
129
+	}
130
+
131
+
132
+
133
+	/**
134
+	 * @return int
135
+	 * @throws EE_Error
136
+	 */
137
+	private function currentPostID()
138
+	{
139
+		// try to get EE_Event any way we can
140
+		$event = EEH_Event_View::get_event();
141
+		// then get some kind of ID
142
+		if ($event instanceof EE_Event) {
143
+			return $event->ID();
144
+		}
145
+		global $post;
146
+		if ($post instanceof WP_Post) {
147
+			return $post->ID;
148
+		}
149
+		return 0;
150
+	}
151
+
152
+
153
+
154
+	/**
155
+	 * @param int $post_ID
156
+	 * @return string
157
+	 * @throws EE_Error
158
+	 */
159
+	private function shortcodeCacheID($post_ID)
160
+	{
161
+		$tag = str_replace('ESPRESSO_', '', $this->getTag());
162
+		return "SC_{$tag}-{$post_ID}";
163
+	}
164
+
165
+
166
+
167
+	/**
168
+	 * array for defining custom attribute sanitization callbacks,
169
+	 * where keys match keys in your attributes array,
170
+	 * and values represent the sanitization function you wish to be applied to that attribute.
171
+	 * So for example, if you had an integer attribute named "event_id"
172
+	 * that you wanted to be sanitized using absint(),
173
+	 * then you would return the following:
174
+	 *      array('event_id' => 'absint')
175
+	 * Entering 'skip_sanitization' for the callback value
176
+	 * means that no sanitization will be applied
177
+	 * on the assumption that the attribute
178
+	 * will be sanitized at some point... right?
179
+	 * You wouldn't pass around unsanitized attributes would you?
180
+	 * That would be very Tom Foolery of you!!!
181
+	 *
182
+	 * @return array
183
+	 */
184
+	protected function customAttributeSanitizationMap()
185
+	{
186
+		return array();
187
+	}
188
+
189
+
190
+
191
+	/**
192
+	 * Performs basic sanitization on shortcode attributes
193
+	 * Since incoming attributes from the shortcode usage in the WP editor will all be strings,
194
+	 * most attributes will by default be sanitized using the sanitize_text_field() function.
195
+	 * This can be overridden using the customAttributeSanitizationMap() method (see above),
196
+	 * all other attributes would be sanitized using the defaults in the switch statement below
197
+	 *
198
+	 * @param array $attributes
199
+	 * @return array
200
+	 */
201
+	private function sanitizeAttributes(array $attributes)
202
+	{
203
+		$custom_sanitization = $this->customAttributeSanitizationMap();
204
+		foreach ($attributes as $key => $value) {
205
+			// is a custom sanitization callback specified ?
206
+			if (isset($custom_sanitization[$key])) {
207
+				$callback = $custom_sanitization[$key];
208
+				if ($callback === 'skip_sanitization') {
209
+					$attributes[$key] = $value;
210
+					continue;
211
+				}
212
+				if (function_exists($callback)) {
213
+					$attributes[$key] = $callback($value);
214
+					continue;
215
+				}
216
+			}
217
+			switch (true) {
218
+				case $value === null :
219
+				case is_int($value) :
220
+				case is_float($value) :
221
+					// typical booleans
222
+				case in_array($value, array(true, 'true', '1', 'on', 'yes', false, 'false', '0', 'off', 'no'), true) :
223
+					$attributes[$key] = $value;
224
+					break;
225
+				case is_string($value) :
226
+					$attributes[$key] = sanitize_text_field($value);
227
+					break;
228
+				case is_array($value) :
229
+					$attributes[$key] = $this->sanitizeAttributes($value);
230
+					break;
231
+				default :
232
+					// only remaining data types are Object and Resource
233
+					// which are not allowed as shortcode attributes
234
+					$attributes[$key] = null;
235
+					break;
236
+			}
237
+		}
238
+		return $attributes;
239
+	}
240
+
241
+
242
+
243
+	/**
244
+	 * Returns whether or not this shortcode has been initialized
245
+	 * @return boolean
246
+	 */
247
+	public function initialized(){
248
+		return $this->initialized;
249
+	}
250 250
 
251 251
 
252 252
 
Please login to merge, or discard this patch.
core/services/shortcodes/ShortcodeInterface.php 1 patch
Indentation   +46 added lines, -46 removed lines patch added patch discarded remove patch
@@ -8,52 +8,52 @@
 block discarded – undo
8 8
 interface ShortcodeInterface
9 9
 {
10 10
 
11
-    /**
12
-     * the actual shortcode tag that gets registered with WordPress
13
-     *
14
-     * @return string
15
-     */
16
-    public function getTag();
17
-
18
-    /**
19
-     * the length of time in seconds to cache the results of the processShortcode() method
20
-     * 0 means the processShortcode() results will NOT be cached at all
21
-     *
22
-     * @return int
23
-     */
24
-    public function cacheExpiration();
25
-
26
-    /**
27
-     * a place for adding any initialization code that needs to run prior to wp_header().
28
-     * this may be required for shortcodes that utilize a corresponding module,
29
-     * and need to enqueue assets for that module
30
-     *
31
-     * !!! IMPORTANT !!!
32
-     * After performing any logic within this method required for initialization
33
-     *         $this->shortcodeHasBeenInitialized();
34
-     * should be called to ensure that the shortcode is setup correctly.
35
-     *
36
-     * @return void
37
-     */
38
-    public function initializeShortcode();
39
-
40
-    /**
41
-     * callback that runs when the shortcode is encountered in post content.
42
-     * IMPORTANT !!!
43
-     * remember that shortcode content should be RETURNED and NOT echoed out
44
-     *
45
-     * @param array $attributes
46
-     * @return string
47
-     */
48
-    public function processShortcode($attributes = array());
49
-
50
-
51
-
52
-    /**
53
-     * Returns whether or not this shortcode class has already been initialized
54
-     * @return boolean
55
-     */
56
-    public function initialized();
11
+	/**
12
+	 * the actual shortcode tag that gets registered with WordPress
13
+	 *
14
+	 * @return string
15
+	 */
16
+	public function getTag();
17
+
18
+	/**
19
+	 * the length of time in seconds to cache the results of the processShortcode() method
20
+	 * 0 means the processShortcode() results will NOT be cached at all
21
+	 *
22
+	 * @return int
23
+	 */
24
+	public function cacheExpiration();
25
+
26
+	/**
27
+	 * a place for adding any initialization code that needs to run prior to wp_header().
28
+	 * this may be required for shortcodes that utilize a corresponding module,
29
+	 * and need to enqueue assets for that module
30
+	 *
31
+	 * !!! IMPORTANT !!!
32
+	 * After performing any logic within this method required for initialization
33
+	 *         $this->shortcodeHasBeenInitialized();
34
+	 * should be called to ensure that the shortcode is setup correctly.
35
+	 *
36
+	 * @return void
37
+	 */
38
+	public function initializeShortcode();
39
+
40
+	/**
41
+	 * callback that runs when the shortcode is encountered in post content.
42
+	 * IMPORTANT !!!
43
+	 * remember that shortcode content should be RETURNED and NOT echoed out
44
+	 *
45
+	 * @param array $attributes
46
+	 * @return string
47
+	 */
48
+	public function processShortcode($attributes = array());
49
+
50
+
51
+
52
+	/**
53
+	 * Returns whether or not this shortcode class has already been initialized
54
+	 * @return boolean
55
+	 */
56
+	public function initialized();
57 57
 
58 58
 }
59 59
 // End of file ShortcodeInterface.php
Please login to merge, or discard this patch.
core/db_models/fields/EE_Datetime_Field.php 1 patch
Indentation   +755 added lines, -755 removed lines patch added patch discarded remove patch
@@ -15,760 +15,760 @@
 block discarded – undo
15 15
 class EE_Datetime_Field extends EE_Model_Field_Base
16 16
 {
17 17
 
18
-    /**
19
-     * The pattern we're looking for is if only the characters 0-9 are found and there are only
20
-     * 10 or more numbers (because 9 numbers even with all 9's would be sometime in 2001 )
21
-     *
22
-     * @type string unix_timestamp_regex
23
-     */
24
-    const unix_timestamp_regex = '/[0-9]{10,}/';
25
-
26
-    /**
27
-     * @type string mysql_timestamp_format
28
-     */
29
-    const mysql_timestamp_format = 'Y-m-d H:i:s';
30
-
31
-    /**
32
-     * @type string mysql_date_format
33
-     */
34
-    const mysql_date_format = 'Y-m-d';
35
-
36
-    /**
37
-     * @type string mysql_time_format
38
-     */
39
-    const mysql_time_format = 'H:i:s';
40
-
41
-    /**
42
-     * Const for using in the default value. If the field's default is set to this,
43
-     * then we will return the time of calling `get_default_value()`, not
44
-     * just the current time at construction
45
-     */
46
-    const now = 'now';
47
-
48
-    /**
49
-     * The following properties hold the default formats for date and time.
50
-     * Defaults are set via the constructor and can be overridden on class instantiation.
51
-     * However they can also be overridden later by the set_format() method
52
-     * (and corresponding set_date_format, set_time_format methods);
53
-     */
54
-    /**
55
-     * @type string $_date_format
56
-     */
57
-    protected $_date_format = '';
58
-
59
-    /**
60
-     * @type string $_time_format
61
-     */
62
-    protected $_time_format = '';
63
-
64
-    /**
65
-     * @type string $_pretty_date_format
66
-     */
67
-    protected $_pretty_date_format = '';
68
-
69
-    /**
70
-     * @type string $_pretty_time_format
71
-     */
72
-    protected $_pretty_time_format = '';
73
-
74
-    /**
75
-     * @type DateTimeZone $_DateTimeZone
76
-     */
77
-    protected $_DateTimeZone;
78
-
79
-    /**
80
-     * @type DateTimeZone $_UTC_DateTimeZone
81
-     */
82
-    protected $_UTC_DateTimeZone;
83
-
84
-    /**
85
-     * @type DateTimeZone $_blog_DateTimeZone
86
-     */
87
-    protected $_blog_DateTimeZone;
88
-
89
-
90
-    /**
91
-     * This property holds how we want the output returned when getting a datetime string.  It is set for the
92
-     * set_date_time_output() method.  By default this is empty.  When empty, we are assuming that we want both date
93
-     * and time returned via getters.
94
-     *
95
-     * @var mixed (null|string)
96
-     */
97
-    protected $_date_time_output;
98
-
99
-
100
-    /**
101
-     * timezone string
102
-     * This gets set by the constructor and can be changed by the "set_timezone()" method so that we know what timezone
103
-     * incoming strings|timestamps are in.  This can also be used before a get to set what timezone you want strings
104
-     * coming out of the object to be in.  Default timezone is the current WP timezone option setting
105
-     *
106
-     * @var string
107
-     */
108
-    protected $_timezone_string;
109
-
110
-
111
-    /**
112
-     * This holds whatever UTC offset for the blog (we automatically convert timezone strings into their related
113
-     * offsets for comparison purposes).
114
-     *
115
-     * @var int
116
-     */
117
-    protected $_blog_offset;
118
-
119
-
120
-
121
-    /**
122
-     * @param string $table_column
123
-     * @param string $nice_name
124
-     * @param bool   $nullable
125
-     * @param string $default_value
126
-     * @param string $timezone_string
127
-     * @param string $date_format
128
-     * @param string $time_format
129
-     * @param string $pretty_date_format
130
-     * @param string $pretty_time_format
131
-     * @throws EE_Error
132
-     * @throws InvalidArgumentException
133
-     */
134
-    public function __construct(
135
-        $table_column,
136
-        $nice_name,
137
-        $nullable,
138
-        $default_value,
139
-        $timezone_string = '',
140
-        $date_format = '',
141
-        $time_format = '',
142
-        $pretty_date_format = '',
143
-        $pretty_time_format = ''
144
-    ) {
145
-
146
-        $this->_date_format        = ! empty($date_format) ? $date_format : get_option('date_format');
147
-        $this->_time_format        = ! empty($time_format) ? $time_format : get_option('time_format');
148
-        $this->_pretty_date_format = ! empty($pretty_date_format) ? $pretty_date_format : get_option('date_format');
149
-        $this->_pretty_time_format = ! empty($pretty_time_format) ? $pretty_time_format : get_option('time_format');
150
-
151
-        parent::__construct($table_column, $nice_name, $nullable, $default_value);
152
-        $this->set_timezone($timezone_string);
153
-        $this->setSchemaFormat('date-time');
154
-    }
155
-
156
-
157
-    /**
158
-     * @return DateTimeZone
159
-     * @throws \EE_Error
160
-     */
161
-    public function get_UTC_DateTimeZone()
162
-    {
163
-        return $this->_UTC_DateTimeZone instanceof DateTimeZone
164
-            ? $this->_UTC_DateTimeZone
165
-            : $this->_create_timezone_object_from_timezone_string('UTC');
166
-    }
167
-
168
-
169
-    /**
170
-     * @return DateTimeZone
171
-     * @throws \EE_Error
172
-     */
173
-    public function get_blog_DateTimeZone()
174
-    {
175
-        return $this->_blog_DateTimeZone instanceof DateTimeZone
176
-            ? $this->_blog_DateTimeZone
177
-            : $this->_create_timezone_object_from_timezone_string('');
178
-    }
179
-
180
-
181
-    /**
182
-     * this prepares any incoming date data and make sure its converted to a utc unix timestamp
183
-     *
184
-     * @param  string|int $value_inputted_for_field_on_model_object could be a string formatted date time or int unix
185
-     *                                                              timestamp
186
-     * @return DateTime
187
-     */
188
-    public function prepare_for_set($value_inputted_for_field_on_model_object)
189
-    {
190
-        return $this->_get_date_object($value_inputted_for_field_on_model_object);
191
-    }
192
-
193
-
194
-    /**
195
-     * This returns the format string to be used by getters depending on what the $_date_time_output property is set at.
196
-     * getters need to know whether we're just returning the date or the time or both.  By default we return both.
197
-     *
198
-     * @param bool $pretty If we're returning the pretty formats or standard format string.
199
-     * @return string    The final assembled format string.
200
-     */
201
-    protected function _get_date_time_output($pretty = false)
202
-    {
203
-
204
-        switch ($this->_date_time_output) {
205
-            case 'time' :
206
-                return $pretty ? $this->_pretty_time_format : $this->_time_format;
207
-                break;
208
-
209
-            case 'date' :
210
-                return $pretty ? $this->_pretty_date_format : $this->_date_format;
211
-                break;
212
-
213
-            default :
214
-                return $pretty
215
-                    ? $this->_pretty_date_format . ' ' . $this->_pretty_time_format
216
-                    : $this->_date_format . ' ' . $this->_time_format;
217
-        }
218
-    }
219
-
220
-
221
-    /**
222
-     * This just sets the $_date_time_output property so we can flag how date and times are formatted before being
223
-     * returned (using the format properties)
224
-     *
225
-     * @param string $what acceptable values are 'time' or 'date'.
226
-     *                     Any other value will be set but will always result
227
-     *                     in both 'date' and 'time' being returned.
228
-     * @return void
229
-     */
230
-    public function set_date_time_output($what = null)
231
-    {
232
-        $this->_date_time_output = $what;
233
-    }
234
-
235
-
236
-    /**
237
-     * See $_timezone property for description of what the timezone property is for.  This SETS the timezone internally
238
-     * for being able to reference what timezone we are running conversions on when converting TO the internal timezone
239
-     * (UTC Unix Timestamp) for the object OR when converting FROM the internal timezone (UTC Unix Timestamp).
240
-     * We also set some other properties in this method.
241
-     *
242
-     * @param string $timezone_string A valid timezone string as described by @link
243
-     *                                http://www.php.net/manual/en/timezones.php
244
-     * @return void
245
-     * @throws \EE_Error
246
-     */
247
-    public function set_timezone($timezone_string)
248
-    {
249
-        if (empty($timezone_string) && $this->_timezone_string !== null) {
250
-            // leave the timezone AS-IS if we already have one and
251
-            // the function arg didn't provide one
252
-            return;
253
-        }
254
-        $timezone_string        = EEH_DTT_Helper::get_valid_timezone_string($timezone_string);
255
-        $this->_timezone_string = ! empty($timezone_string) ? $timezone_string : 'UTC';
256
-        $this->_DateTimeZone    = $this->_create_timezone_object_from_timezone_string($this->_timezone_string);
257
-    }
258
-
259
-
260
-    /**
261
-     * _create_timezone_object_from_timezone_name
262
-     *
263
-     * @access protected
264
-     * @param string $timezone_string
265
-     * @return \DateTimeZone
266
-     * @throws \EE_Error
267
-     */
268
-    protected function _create_timezone_object_from_timezone_string($timezone_string = '')
269
-    {
270
-        return new DateTimeZone(EEH_DTT_Helper::get_valid_timezone_string($timezone_string));
271
-    }
272
-
273
-
274
-    /**
275
-     * This just returns whatever is set for the current timezone.
276
-     *
277
-     * @access public
278
-     * @return string timezone string
279
-     */
280
-    public function get_timezone()
281
-    {
282
-        return $this->_timezone_string;
283
-    }
284
-
285
-
286
-    /**
287
-     * set the $_date_format property
288
-     *
289
-     * @access public
290
-     * @param string $format a new date format (corresponding to formats accepted by PHP date() function)
291
-     * @param bool   $pretty Whether to set pretty format or not.
292
-     * @return void
293
-     */
294
-    public function set_date_format($format, $pretty = false)
295
-    {
296
-        if ($pretty) {
297
-            $this->_pretty_date_format = $format;
298
-        } else {
299
-            $this->_date_format = $format;
300
-        }
301
-    }
302
-
303
-
304
-    /**
305
-     * return the $_date_format property value.
306
-     *
307
-     * @param bool $pretty Whether to get pretty format or not.
308
-     * @return string
309
-     */
310
-    public function get_date_format($pretty = false)
311
-    {
312
-        return $pretty ? $this->_pretty_date_format : $this->_date_format;
313
-    }
314
-
315
-
316
-    /**
317
-     * set the $_time_format property
318
-     *
319
-     * @access public
320
-     * @param string $format a new time format (corresponding to formats accepted by PHP date() function)
321
-     * @param bool   $pretty Whether to set pretty format or not.
322
-     * @return void
323
-     */
324
-    public function set_time_format($format, $pretty = false)
325
-    {
326
-        if ($pretty) {
327
-            $this->_pretty_time_format = $format;
328
-        } else {
329
-            $this->_time_format = $format;
330
-        }
331
-    }
332
-
333
-
334
-    /**
335
-     * return the $_time_format property value.
336
-     *
337
-     * @param bool $pretty Whether to get pretty format or not.
338
-     * @return string
339
-     */
340
-    public function get_time_format($pretty = false)
341
-    {
342
-        return $pretty ? $this->_pretty_time_format : $this->_time_format;
343
-    }
344
-
345
-
346
-    /**
347
-     * set the $_pretty_date_format property
348
-     *
349
-     * @access public
350
-     * @param string $format a new pretty date format (corresponding to formats accepted by PHP date() function)
351
-     * @return void
352
-     */
353
-    public function set_pretty_date_format($format)
354
-    {
355
-        $this->_pretty_date_format = $format;
356
-    }
357
-
358
-
359
-    /**
360
-     * set the $_pretty_time_format property
361
-     *
362
-     * @access public
363
-     * @param string $format a new pretty time format (corresponding to formats accepted by PHP date() function)
364
-     * @return void
365
-     */
366
-    public function set_pretty_time_format($format)
367
-    {
368
-        $this->_pretty_time_format = $format;
369
-    }
370
-
371
-
372
-    /**
373
-     * Only sets the time portion of the datetime.
374
-     *
375
-     * @param string|DateTime $time_to_set_string like 8am OR a DateTime object.
376
-     * @param DateTime        $current            current DateTime object for the datetime field
377
-     * @return DateTime
378
-     */
379
-    public function prepare_for_set_with_new_time($time_to_set_string, DateTime $current)
380
-    {
381
-        // if $time_to_set_string is datetime object, then let's use it to set the parse array.
382
-        // Otherwise parse the string.
383
-        if ($time_to_set_string instanceof DateTime) {
384
-            $parsed = array(
385
-                'hour'   => $time_to_set_string->format('H'),
386
-                'minute' => $time_to_set_string->format('i'),
387
-                'second' => $time_to_set_string->format('s'),
388
-            );
389
-        } else {
390
-            //parse incoming string
391
-            $parsed = date_parse_from_format($this->_time_format, $time_to_set_string);
392
-        }
393
-
394
-        //make sure $current is in the correct timezone.
395
-        $current->setTimezone($this->_DateTimeZone);
396
-
397
-        return $current->setTime($parsed['hour'], $parsed['minute'], $parsed['second']);
398
-    }
399
-
400
-
401
-    /**
402
-     * Only sets the date portion of the datetime.
403
-     *
404
-     * @param string|DateTime $date_to_set_string like Friday, January 8th or a DateTime object.
405
-     * @param DateTime        $current            current DateTime object for the datetime field
406
-     * @return DateTime
407
-     */
408
-    public function prepare_for_set_with_new_date($date_to_set_string, DateTime $current)
409
-    {
410
-        // if $time_to_set_string is datetime object, then let's use it to set the parse array.
411
-        // Otherwise parse the string.
412
-        if ($date_to_set_string instanceof DateTime) {
413
-            $parsed = array(
414
-                'year'  => $date_to_set_string->format('Y'),
415
-                'month' => $date_to_set_string->format('m'),
416
-                'day'   => $date_to_set_string->format('d'),
417
-            );
418
-        } else {
419
-            //parse incoming string
420
-            $parsed = date_parse_from_format($this->_date_format, $date_to_set_string);
421
-        }
422
-
423
-        //make sure $current is in the correct timezone
424
-        $current->setTimezone($this->_DateTimeZone);
425
-
426
-        return $current->setDate($parsed['year'], $parsed['month'], $parsed['day']);
427
-    }
428
-
429
-
430
-    /**
431
-     * This prepares the EE_DateTime value to be saved to the db as mysql timestamp (UTC +0 timezone).  When the
432
-     * datetime gets to this stage it should ALREADY be in UTC time
433
-     *
434
-     * @param  DateTime $DateTime
435
-     * @return string formatted date time for given timezone
436
-     * @throws \EE_Error
437
-     */
438
-    public function prepare_for_get($DateTime)
439
-    {
440
-        return $this->_prepare_for_display($DateTime);
441
-    }
442
-
443
-
444
-    /**
445
-     * This differs from prepare_for_get in that it considers whether the internal $_timezone differs
446
-     * from the set wp timezone.  If so, then it returns the datetime string formatted via
447
-     * _pretty_date_format, and _pretty_time_format.  However, it also appends a timezone
448
-     * abbreviation to the date_string.
449
-     *
450
-     * @param mixed $DateTime
451
-     * @param null  $schema
452
-     * @return string
453
-     * @throws \EE_Error
454
-     */
455
-    public function prepare_for_pretty_echoing($DateTime, $schema = null)
456
-    {
457
-        return $this->_prepare_for_display($DateTime, $schema ? $schema : true);
458
-    }
459
-
460
-
461
-    /**
462
-     * This prepares the EE_DateTime value to be saved to the db as mysql timestamp (UTC +0
463
-     * timezone).
464
-     *
465
-     * @param DateTime    $DateTime
466
-     * @param bool|string $schema
467
-     * @return string
468
-     * @throws \EE_Error
469
-     */
470
-    protected function _prepare_for_display($DateTime, $schema = false)
471
-    {
472
-        if (! $DateTime instanceof DateTime) {
473
-            if ($this->_nullable) {
474
-                return '';
475
-            } else {
476
-                if (WP_DEBUG) {
477
-                    throw new EE_Error(
478
-                        sprintf(
479
-                            __(
480
-                                'EE_Datetime_Field::_prepare_for_display requires a DateTime class to be the value for the $DateTime argument because the %s field is not nullable.',
481
-                                'event_espresso'
482
-                            ),
483
-                            $this->_nicename
484
-                        )
485
-                    );
486
-                } else {
487
-                    $DateTime = new DbSafeDateTime(\EE_Datetime_Field::now);
488
-                    EE_Error::add_error(
489
-                        sprintf(
490
-                            __(
491
-                                'EE_Datetime_Field::_prepare_for_display requires a DateTime class to be the value for the $DateTime argument because the %s field is not nullable.  When WP_DEBUG is false, the value is set to "now" instead of throwing an exception.',
492
-                                'event_espresso'
493
-                            ),
494
-                            $this->_nicename
495
-                        )
496
-                    );
497
-                }
498
-            }
499
-        }
500
-        $format_string = $this->_get_date_time_output($schema);
501
-        //make sure datetime_value is in the correct timezone (in case that's been updated).
502
-        $DateTime->setTimezone($this->_DateTimeZone);
503
-        if ($schema) {
504
-            if ($this->_display_timezone()) {
505
-                //must be explicit because schema could equal true.
506
-                if ($schema === 'no_html') {
507
-                    $timezone_string = ' (' . $DateTime->format('T') . ')';
508
-                } else {
509
-                    $timezone_string = ' <span class="ee_dtt_timezone_string">(' . $DateTime->format('T') . ')</span>';
510
-                }
511
-            } else {
512
-                $timezone_string = '';
513
-            }
514
-
515
-            return $DateTime->format($format_string) . $timezone_string;
516
-        } else {
517
-            return $DateTime->format($format_string);
518
-        }
519
-    }
520
-
521
-
522
-    /**
523
-     * This prepares the EE_DateTime value to be saved to the db as mysql timestamp (UTC +0
524
-     * timezone).
525
-     *
526
-     * @param  mixed $datetime_value u
527
-     * @return string mysql timestamp in UTC
528
-     * @throws \EE_Error
529
-     */
530
-    public function prepare_for_use_in_db($datetime_value)
531
-    {
532
-        //we allow an empty value or DateTime object, but nothing else.
533
-        if (! empty($datetime_value) && ! $datetime_value instanceof DateTime) {
534
-            throw new EE_Error(
535
-            	sprintf(
536
-            	    __(
537
-            		    'The incoming value being prepared for setting in the database must either be empty or a php 
18
+	/**
19
+	 * The pattern we're looking for is if only the characters 0-9 are found and there are only
20
+	 * 10 or more numbers (because 9 numbers even with all 9's would be sometime in 2001 )
21
+	 *
22
+	 * @type string unix_timestamp_regex
23
+	 */
24
+	const unix_timestamp_regex = '/[0-9]{10,}/';
25
+
26
+	/**
27
+	 * @type string mysql_timestamp_format
28
+	 */
29
+	const mysql_timestamp_format = 'Y-m-d H:i:s';
30
+
31
+	/**
32
+	 * @type string mysql_date_format
33
+	 */
34
+	const mysql_date_format = 'Y-m-d';
35
+
36
+	/**
37
+	 * @type string mysql_time_format
38
+	 */
39
+	const mysql_time_format = 'H:i:s';
40
+
41
+	/**
42
+	 * Const for using in the default value. If the field's default is set to this,
43
+	 * then we will return the time of calling `get_default_value()`, not
44
+	 * just the current time at construction
45
+	 */
46
+	const now = 'now';
47
+
48
+	/**
49
+	 * The following properties hold the default formats for date and time.
50
+	 * Defaults are set via the constructor and can be overridden on class instantiation.
51
+	 * However they can also be overridden later by the set_format() method
52
+	 * (and corresponding set_date_format, set_time_format methods);
53
+	 */
54
+	/**
55
+	 * @type string $_date_format
56
+	 */
57
+	protected $_date_format = '';
58
+
59
+	/**
60
+	 * @type string $_time_format
61
+	 */
62
+	protected $_time_format = '';
63
+
64
+	/**
65
+	 * @type string $_pretty_date_format
66
+	 */
67
+	protected $_pretty_date_format = '';
68
+
69
+	/**
70
+	 * @type string $_pretty_time_format
71
+	 */
72
+	protected $_pretty_time_format = '';
73
+
74
+	/**
75
+	 * @type DateTimeZone $_DateTimeZone
76
+	 */
77
+	protected $_DateTimeZone;
78
+
79
+	/**
80
+	 * @type DateTimeZone $_UTC_DateTimeZone
81
+	 */
82
+	protected $_UTC_DateTimeZone;
83
+
84
+	/**
85
+	 * @type DateTimeZone $_blog_DateTimeZone
86
+	 */
87
+	protected $_blog_DateTimeZone;
88
+
89
+
90
+	/**
91
+	 * This property holds how we want the output returned when getting a datetime string.  It is set for the
92
+	 * set_date_time_output() method.  By default this is empty.  When empty, we are assuming that we want both date
93
+	 * and time returned via getters.
94
+	 *
95
+	 * @var mixed (null|string)
96
+	 */
97
+	protected $_date_time_output;
98
+
99
+
100
+	/**
101
+	 * timezone string
102
+	 * This gets set by the constructor and can be changed by the "set_timezone()" method so that we know what timezone
103
+	 * incoming strings|timestamps are in.  This can also be used before a get to set what timezone you want strings
104
+	 * coming out of the object to be in.  Default timezone is the current WP timezone option setting
105
+	 *
106
+	 * @var string
107
+	 */
108
+	protected $_timezone_string;
109
+
110
+
111
+	/**
112
+	 * This holds whatever UTC offset for the blog (we automatically convert timezone strings into their related
113
+	 * offsets for comparison purposes).
114
+	 *
115
+	 * @var int
116
+	 */
117
+	protected $_blog_offset;
118
+
119
+
120
+
121
+	/**
122
+	 * @param string $table_column
123
+	 * @param string $nice_name
124
+	 * @param bool   $nullable
125
+	 * @param string $default_value
126
+	 * @param string $timezone_string
127
+	 * @param string $date_format
128
+	 * @param string $time_format
129
+	 * @param string $pretty_date_format
130
+	 * @param string $pretty_time_format
131
+	 * @throws EE_Error
132
+	 * @throws InvalidArgumentException
133
+	 */
134
+	public function __construct(
135
+		$table_column,
136
+		$nice_name,
137
+		$nullable,
138
+		$default_value,
139
+		$timezone_string = '',
140
+		$date_format = '',
141
+		$time_format = '',
142
+		$pretty_date_format = '',
143
+		$pretty_time_format = ''
144
+	) {
145
+
146
+		$this->_date_format        = ! empty($date_format) ? $date_format : get_option('date_format');
147
+		$this->_time_format        = ! empty($time_format) ? $time_format : get_option('time_format');
148
+		$this->_pretty_date_format = ! empty($pretty_date_format) ? $pretty_date_format : get_option('date_format');
149
+		$this->_pretty_time_format = ! empty($pretty_time_format) ? $pretty_time_format : get_option('time_format');
150
+
151
+		parent::__construct($table_column, $nice_name, $nullable, $default_value);
152
+		$this->set_timezone($timezone_string);
153
+		$this->setSchemaFormat('date-time');
154
+	}
155
+
156
+
157
+	/**
158
+	 * @return DateTimeZone
159
+	 * @throws \EE_Error
160
+	 */
161
+	public function get_UTC_DateTimeZone()
162
+	{
163
+		return $this->_UTC_DateTimeZone instanceof DateTimeZone
164
+			? $this->_UTC_DateTimeZone
165
+			: $this->_create_timezone_object_from_timezone_string('UTC');
166
+	}
167
+
168
+
169
+	/**
170
+	 * @return DateTimeZone
171
+	 * @throws \EE_Error
172
+	 */
173
+	public function get_blog_DateTimeZone()
174
+	{
175
+		return $this->_blog_DateTimeZone instanceof DateTimeZone
176
+			? $this->_blog_DateTimeZone
177
+			: $this->_create_timezone_object_from_timezone_string('');
178
+	}
179
+
180
+
181
+	/**
182
+	 * this prepares any incoming date data and make sure its converted to a utc unix timestamp
183
+	 *
184
+	 * @param  string|int $value_inputted_for_field_on_model_object could be a string formatted date time or int unix
185
+	 *                                                              timestamp
186
+	 * @return DateTime
187
+	 */
188
+	public function prepare_for_set($value_inputted_for_field_on_model_object)
189
+	{
190
+		return $this->_get_date_object($value_inputted_for_field_on_model_object);
191
+	}
192
+
193
+
194
+	/**
195
+	 * This returns the format string to be used by getters depending on what the $_date_time_output property is set at.
196
+	 * getters need to know whether we're just returning the date or the time or both.  By default we return both.
197
+	 *
198
+	 * @param bool $pretty If we're returning the pretty formats or standard format string.
199
+	 * @return string    The final assembled format string.
200
+	 */
201
+	protected function _get_date_time_output($pretty = false)
202
+	{
203
+
204
+		switch ($this->_date_time_output) {
205
+			case 'time' :
206
+				return $pretty ? $this->_pretty_time_format : $this->_time_format;
207
+				break;
208
+
209
+			case 'date' :
210
+				return $pretty ? $this->_pretty_date_format : $this->_date_format;
211
+				break;
212
+
213
+			default :
214
+				return $pretty
215
+					? $this->_pretty_date_format . ' ' . $this->_pretty_time_format
216
+					: $this->_date_format . ' ' . $this->_time_format;
217
+		}
218
+	}
219
+
220
+
221
+	/**
222
+	 * This just sets the $_date_time_output property so we can flag how date and times are formatted before being
223
+	 * returned (using the format properties)
224
+	 *
225
+	 * @param string $what acceptable values are 'time' or 'date'.
226
+	 *                     Any other value will be set but will always result
227
+	 *                     in both 'date' and 'time' being returned.
228
+	 * @return void
229
+	 */
230
+	public function set_date_time_output($what = null)
231
+	{
232
+		$this->_date_time_output = $what;
233
+	}
234
+
235
+
236
+	/**
237
+	 * See $_timezone property for description of what the timezone property is for.  This SETS the timezone internally
238
+	 * for being able to reference what timezone we are running conversions on when converting TO the internal timezone
239
+	 * (UTC Unix Timestamp) for the object OR when converting FROM the internal timezone (UTC Unix Timestamp).
240
+	 * We also set some other properties in this method.
241
+	 *
242
+	 * @param string $timezone_string A valid timezone string as described by @link
243
+	 *                                http://www.php.net/manual/en/timezones.php
244
+	 * @return void
245
+	 * @throws \EE_Error
246
+	 */
247
+	public function set_timezone($timezone_string)
248
+	{
249
+		if (empty($timezone_string) && $this->_timezone_string !== null) {
250
+			// leave the timezone AS-IS if we already have one and
251
+			// the function arg didn't provide one
252
+			return;
253
+		}
254
+		$timezone_string        = EEH_DTT_Helper::get_valid_timezone_string($timezone_string);
255
+		$this->_timezone_string = ! empty($timezone_string) ? $timezone_string : 'UTC';
256
+		$this->_DateTimeZone    = $this->_create_timezone_object_from_timezone_string($this->_timezone_string);
257
+	}
258
+
259
+
260
+	/**
261
+	 * _create_timezone_object_from_timezone_name
262
+	 *
263
+	 * @access protected
264
+	 * @param string $timezone_string
265
+	 * @return \DateTimeZone
266
+	 * @throws \EE_Error
267
+	 */
268
+	protected function _create_timezone_object_from_timezone_string($timezone_string = '')
269
+	{
270
+		return new DateTimeZone(EEH_DTT_Helper::get_valid_timezone_string($timezone_string));
271
+	}
272
+
273
+
274
+	/**
275
+	 * This just returns whatever is set for the current timezone.
276
+	 *
277
+	 * @access public
278
+	 * @return string timezone string
279
+	 */
280
+	public function get_timezone()
281
+	{
282
+		return $this->_timezone_string;
283
+	}
284
+
285
+
286
+	/**
287
+	 * set the $_date_format property
288
+	 *
289
+	 * @access public
290
+	 * @param string $format a new date format (corresponding to formats accepted by PHP date() function)
291
+	 * @param bool   $pretty Whether to set pretty format or not.
292
+	 * @return void
293
+	 */
294
+	public function set_date_format($format, $pretty = false)
295
+	{
296
+		if ($pretty) {
297
+			$this->_pretty_date_format = $format;
298
+		} else {
299
+			$this->_date_format = $format;
300
+		}
301
+	}
302
+
303
+
304
+	/**
305
+	 * return the $_date_format property value.
306
+	 *
307
+	 * @param bool $pretty Whether to get pretty format or not.
308
+	 * @return string
309
+	 */
310
+	public function get_date_format($pretty = false)
311
+	{
312
+		return $pretty ? $this->_pretty_date_format : $this->_date_format;
313
+	}
314
+
315
+
316
+	/**
317
+	 * set the $_time_format property
318
+	 *
319
+	 * @access public
320
+	 * @param string $format a new time format (corresponding to formats accepted by PHP date() function)
321
+	 * @param bool   $pretty Whether to set pretty format or not.
322
+	 * @return void
323
+	 */
324
+	public function set_time_format($format, $pretty = false)
325
+	{
326
+		if ($pretty) {
327
+			$this->_pretty_time_format = $format;
328
+		} else {
329
+			$this->_time_format = $format;
330
+		}
331
+	}
332
+
333
+
334
+	/**
335
+	 * return the $_time_format property value.
336
+	 *
337
+	 * @param bool $pretty Whether to get pretty format or not.
338
+	 * @return string
339
+	 */
340
+	public function get_time_format($pretty = false)
341
+	{
342
+		return $pretty ? $this->_pretty_time_format : $this->_time_format;
343
+	}
344
+
345
+
346
+	/**
347
+	 * set the $_pretty_date_format property
348
+	 *
349
+	 * @access public
350
+	 * @param string $format a new pretty date format (corresponding to formats accepted by PHP date() function)
351
+	 * @return void
352
+	 */
353
+	public function set_pretty_date_format($format)
354
+	{
355
+		$this->_pretty_date_format = $format;
356
+	}
357
+
358
+
359
+	/**
360
+	 * set the $_pretty_time_format property
361
+	 *
362
+	 * @access public
363
+	 * @param string $format a new pretty time format (corresponding to formats accepted by PHP date() function)
364
+	 * @return void
365
+	 */
366
+	public function set_pretty_time_format($format)
367
+	{
368
+		$this->_pretty_time_format = $format;
369
+	}
370
+
371
+
372
+	/**
373
+	 * Only sets the time portion of the datetime.
374
+	 *
375
+	 * @param string|DateTime $time_to_set_string like 8am OR a DateTime object.
376
+	 * @param DateTime        $current            current DateTime object for the datetime field
377
+	 * @return DateTime
378
+	 */
379
+	public function prepare_for_set_with_new_time($time_to_set_string, DateTime $current)
380
+	{
381
+		// if $time_to_set_string is datetime object, then let's use it to set the parse array.
382
+		// Otherwise parse the string.
383
+		if ($time_to_set_string instanceof DateTime) {
384
+			$parsed = array(
385
+				'hour'   => $time_to_set_string->format('H'),
386
+				'minute' => $time_to_set_string->format('i'),
387
+				'second' => $time_to_set_string->format('s'),
388
+			);
389
+		} else {
390
+			//parse incoming string
391
+			$parsed = date_parse_from_format($this->_time_format, $time_to_set_string);
392
+		}
393
+
394
+		//make sure $current is in the correct timezone.
395
+		$current->setTimezone($this->_DateTimeZone);
396
+
397
+		return $current->setTime($parsed['hour'], $parsed['minute'], $parsed['second']);
398
+	}
399
+
400
+
401
+	/**
402
+	 * Only sets the date portion of the datetime.
403
+	 *
404
+	 * @param string|DateTime $date_to_set_string like Friday, January 8th or a DateTime object.
405
+	 * @param DateTime        $current            current DateTime object for the datetime field
406
+	 * @return DateTime
407
+	 */
408
+	public function prepare_for_set_with_new_date($date_to_set_string, DateTime $current)
409
+	{
410
+		// if $time_to_set_string is datetime object, then let's use it to set the parse array.
411
+		// Otherwise parse the string.
412
+		if ($date_to_set_string instanceof DateTime) {
413
+			$parsed = array(
414
+				'year'  => $date_to_set_string->format('Y'),
415
+				'month' => $date_to_set_string->format('m'),
416
+				'day'   => $date_to_set_string->format('d'),
417
+			);
418
+		} else {
419
+			//parse incoming string
420
+			$parsed = date_parse_from_format($this->_date_format, $date_to_set_string);
421
+		}
422
+
423
+		//make sure $current is in the correct timezone
424
+		$current->setTimezone($this->_DateTimeZone);
425
+
426
+		return $current->setDate($parsed['year'], $parsed['month'], $parsed['day']);
427
+	}
428
+
429
+
430
+	/**
431
+	 * This prepares the EE_DateTime value to be saved to the db as mysql timestamp (UTC +0 timezone).  When the
432
+	 * datetime gets to this stage it should ALREADY be in UTC time
433
+	 *
434
+	 * @param  DateTime $DateTime
435
+	 * @return string formatted date time for given timezone
436
+	 * @throws \EE_Error
437
+	 */
438
+	public function prepare_for_get($DateTime)
439
+	{
440
+		return $this->_prepare_for_display($DateTime);
441
+	}
442
+
443
+
444
+	/**
445
+	 * This differs from prepare_for_get in that it considers whether the internal $_timezone differs
446
+	 * from the set wp timezone.  If so, then it returns the datetime string formatted via
447
+	 * _pretty_date_format, and _pretty_time_format.  However, it also appends a timezone
448
+	 * abbreviation to the date_string.
449
+	 *
450
+	 * @param mixed $DateTime
451
+	 * @param null  $schema
452
+	 * @return string
453
+	 * @throws \EE_Error
454
+	 */
455
+	public function prepare_for_pretty_echoing($DateTime, $schema = null)
456
+	{
457
+		return $this->_prepare_for_display($DateTime, $schema ? $schema : true);
458
+	}
459
+
460
+
461
+	/**
462
+	 * This prepares the EE_DateTime value to be saved to the db as mysql timestamp (UTC +0
463
+	 * timezone).
464
+	 *
465
+	 * @param DateTime    $DateTime
466
+	 * @param bool|string $schema
467
+	 * @return string
468
+	 * @throws \EE_Error
469
+	 */
470
+	protected function _prepare_for_display($DateTime, $schema = false)
471
+	{
472
+		if (! $DateTime instanceof DateTime) {
473
+			if ($this->_nullable) {
474
+				return '';
475
+			} else {
476
+				if (WP_DEBUG) {
477
+					throw new EE_Error(
478
+						sprintf(
479
+							__(
480
+								'EE_Datetime_Field::_prepare_for_display requires a DateTime class to be the value for the $DateTime argument because the %s field is not nullable.',
481
+								'event_espresso'
482
+							),
483
+							$this->_nicename
484
+						)
485
+					);
486
+				} else {
487
+					$DateTime = new DbSafeDateTime(\EE_Datetime_Field::now);
488
+					EE_Error::add_error(
489
+						sprintf(
490
+							__(
491
+								'EE_Datetime_Field::_prepare_for_display requires a DateTime class to be the value for the $DateTime argument because the %s field is not nullable.  When WP_DEBUG is false, the value is set to "now" instead of throwing an exception.',
492
+								'event_espresso'
493
+							),
494
+							$this->_nicename
495
+						)
496
+					);
497
+				}
498
+			}
499
+		}
500
+		$format_string = $this->_get_date_time_output($schema);
501
+		//make sure datetime_value is in the correct timezone (in case that's been updated).
502
+		$DateTime->setTimezone($this->_DateTimeZone);
503
+		if ($schema) {
504
+			if ($this->_display_timezone()) {
505
+				//must be explicit because schema could equal true.
506
+				if ($schema === 'no_html') {
507
+					$timezone_string = ' (' . $DateTime->format('T') . ')';
508
+				} else {
509
+					$timezone_string = ' <span class="ee_dtt_timezone_string">(' . $DateTime->format('T') . ')</span>';
510
+				}
511
+			} else {
512
+				$timezone_string = '';
513
+			}
514
+
515
+			return $DateTime->format($format_string) . $timezone_string;
516
+		} else {
517
+			return $DateTime->format($format_string);
518
+		}
519
+	}
520
+
521
+
522
+	/**
523
+	 * This prepares the EE_DateTime value to be saved to the db as mysql timestamp (UTC +0
524
+	 * timezone).
525
+	 *
526
+	 * @param  mixed $datetime_value u
527
+	 * @return string mysql timestamp in UTC
528
+	 * @throws \EE_Error
529
+	 */
530
+	public function prepare_for_use_in_db($datetime_value)
531
+	{
532
+		//we allow an empty value or DateTime object, but nothing else.
533
+		if (! empty($datetime_value) && ! $datetime_value instanceof DateTime) {
534
+			throw new EE_Error(
535
+				sprintf(
536
+					__(
537
+						'The incoming value being prepared for setting in the database must either be empty or a php 
538 538
             		    DateTime object, instead of: %1$s %2$s',
539
-                        'event_espresso'
540
-	                ),
541
-                    '<br />',
542
-                    print_r($datetime_value, true)
543
-                )
544
-            );
545
-        }
546
-
547
-        if ($datetime_value instanceof DateTime) {
548
-            if ( ! $datetime_value instanceof DbSafeDateTime) {
549
-                $datetime_value = DbSafeDateTime::createFromDateTime($datetime_value);
550
-            }
551
-
552
-            return $datetime_value->setTimezone($this->get_UTC_DateTimeZone())->format(
553
-                EE_Datetime_Field::mysql_timestamp_format
554
-            );
555
-        }
556
-
557
-        // if $datetime_value is empty, and ! $this->_nullable, use current_time() but set the GMT flag to true
558
-        return ! $this->_nullable && empty($datetime_value) ? current_time('mysql', true) : null;
559
-    }
560
-
561
-
562
-    /**
563
-     * This prepares the datetime for internal usage as a PHP DateTime object OR null (if nullable is
564
-     * allowed)
565
-     *
566
-     * @param string $datetime_string mysql timestamp in UTC
567
-     * @return  mixed null | DateTime
568
-     * @throws \EE_Error
569
-     */
570
-    public function prepare_for_set_from_db($datetime_string)
571
-    {
572
-        //if $datetime_value is empty, and ! $this->_nullable, just use time()
573
-        if (empty($datetime_string) && $this->_nullable) {
574
-            return null;
575
-        }
576
-        // datetime strings from the db should ALWAYS be in UTC+0, so use UTC_DateTimeZone when creating
577
-        if (empty($datetime_string)) {
578
-            $DateTime = new DbSafeDateTime(\EE_Datetime_Field::now, $this->get_UTC_DateTimeZone());
579
-        } else {
580
-            $DateTime = DateTime::createFromFormat(
581
-                EE_Datetime_Field::mysql_timestamp_format,
582
-                $datetime_string,
583
-                $this->get_UTC_DateTimeZone()
584
-            );
585
-            if ($DateTime instanceof \DateTime) {
586
-                $DateTime = new DbSafeDateTime(
587
-                    $DateTime->format(\EE_Datetime_Field::mysql_timestamp_format),
588
-                    $this->get_UTC_DateTimeZone()
589
-                );
590
-            }
591
-        }
592
-
593
-        if (! $DateTime instanceof DbSafeDateTime) {
594
-            // if still no datetime object, then let's just use now
595
-            $DateTime = new DbSafeDateTime(\EE_Datetime_Field::now, $this->get_UTC_DateTimeZone());
596
-        }
597
-        // THEN apply the field's set DateTimeZone
598
-        $DateTime->setTimezone($this->_DateTimeZone);
599
-
600
-        return $DateTime;
601
-    }
602
-
603
-
604
-    /**
605
-     * All this method does is determine if we're going to display the timezone string or not on any output.
606
-     * To determine this we check if the set timezone offset is different than the blog's set timezone offset.
607
-     * If so, then true.
608
-     *
609
-     * @return bool true for yes false for no
610
-     * @throws \EE_Error
611
-     */
612
-    protected function _display_timezone()
613
-    {
614
-
615
-        // first let's do a comparison of timezone strings.
616
-        // If they match then we can get out without any further calculations
617
-        $blog_string = get_option('timezone_string');
618
-        if ($blog_string === $this->_timezone_string) {
619
-            return false;
620
-        }
621
-        // now we need to calc the offset for the timezone string so we can compare with the blog offset.
622
-        $this_offset = $this->get_timezone_offset($this->_DateTimeZone);
623
-        $blog_offset = $this->get_timezone_offset($this->get_blog_DateTimeZone());
624
-        // now compare
625
-        return $blog_offset !== $this_offset;
626
-    }
627
-
628
-
629
-    /**
630
-     * This method returns a php DateTime object for setting on the EE_Base_Class model.
631
-     * EE passes around DateTime objects because they are MUCH easier to manipulate and deal
632
-     * with.
633
-     *
634
-     * @param int|string|DateTime $date_string            This should be the incoming date string.  It's assumed to be
635
-     *                                                    in the format that is set on the date_field (or DateTime
636
-     *                                                    object)!
637
-     * @return DateTime
638
-     */
639
-    protected function _get_date_object($date_string)
640
-    {
641
-        //first if this is an empty date_string and nullable is allowed, just return null.
642
-        if ($this->_nullable && empty($date_string)) {
643
-            return null;
644
-        }
645
-
646
-        // if incoming date
647
-        if ($date_string instanceof DateTime) {
648
-            $date_string->setTimezone($this->_DateTimeZone);
649
-
650
-            return $date_string;
651
-        }
652
-        // if empty date_string and made it here.
653
-        // Return a datetime object for now in the given timezone.
654
-        if (empty($date_string)) {
655
-            return new DbSafeDateTime(\EE_Datetime_Field::now, $this->_DateTimeZone);
656
-        }
657
-        // if $date_string is matches something that looks like a Unix timestamp let's just use it.
658
-        if (preg_match(EE_Datetime_Field::unix_timestamp_regex, $date_string)) {
659
-            try {
660
-                // This is operating under the assumption that the incoming Unix timestamp
661
-                // is an ACTUAL Unix timestamp and not the calculated one output by current_time('timestamp');
662
-                $DateTime = new DbSafeDateTime(\EE_Datetime_Field::now, $this->_DateTimeZone);
663
-                $DateTime->setTimestamp($date_string);
664
-
665
-                return $DateTime;
666
-            } catch (Exception $e) {
667
-                // should be rare, but if things got fooled then let's just continue
668
-            }
669
-        }
670
-        //not a unix timestamp.  So we will use the set format on this object and set timezone to
671
-        //create the DateTime object.
672
-        $format = $this->_date_format . ' ' . $this->_time_format;
673
-        try {
674
-            $DateTime = DateTime::createFromFormat($format, $date_string, $this->_DateTimeZone);
675
-            if ($DateTime instanceof DateTime) {
676
-                $DateTime = new DbSafeDateTime(
677
-                    $DateTime->format(\EE_Datetime_Field::mysql_timestamp_format),
678
-                    $this->_DateTimeZone
679
-                );
680
-            }
681
-            if (! $DateTime instanceof DbSafeDateTime) {
682
-                throw new EE_Error(
683
-                    sprintf(
684
-                        __('"%1$s" does not represent a valid Date Time in the format "%2$s".', 'event_espresso'),
685
-                        $date_string,
686
-                        $format
687
-                    )
688
-                );
689
-            }
690
-        } catch (Exception $e) {
691
-            // if we made it here then likely then something went really wrong.
692
-            // Instead of throwing an exception, let's just return a DateTime object for now, in the set timezone.
693
-            $DateTime = new DbSafeDateTime(\EE_Datetime_Field::now, $this->_DateTimeZone);
694
-        }
695
-
696
-        return $DateTime;
697
-    }
698
-
699
-
700
-
701
-    /**
702
-     * get_timezone_transitions
703
-     *
704
-     * @param \DateTimeZone $DateTimeZone
705
-     * @param int           $time
706
-     * @param bool          $first_only
707
-     * @return mixed
708
-     */
709
-    public function get_timezone_transitions(DateTimeZone $DateTimeZone, $time = null, $first_only = true)
710
-    {
711
-        $time = is_int($time) || $time === null ? $time : strtotime($time);
712
-        $time = preg_match(EE_Datetime_Field::unix_timestamp_regex, $time) ? $time : time();
713
-        $transitions = $DateTimeZone->getTransitions($time);
714
-        return $first_only && ! isset($transitions['ts']) ? reset($transitions) : $transitions;
715
-    }
716
-
717
-
718
-
719
-    /**
720
-     * get_timezone_offset
721
-     *
722
-     * @param \DateTimeZone $DateTimeZone
723
-     * @param int           $time
724
-     * @return mixed
725
-     * @throws \DomainException
726
-     */
727
-    public function get_timezone_offset(DateTimeZone $DateTimeZone, $time = null)
728
-    {
729
-        $transitions = $this->get_timezone_transitions($DateTimeZone, $time);
730
-        if ( ! isset($transitions['offset'])) {
731
-            throw new DomainException();
732
-        }
733
-        return $transitions['offset'];
734
-    }
735
-
736
-
737
-    /**
738
-     * This will take an incoming timezone string and return the abbreviation for that timezone
739
-     *
740
-     * @param  string $timezone_string
741
-     * @return string           abbreviation
742
-     * @throws \EE_Error
743
-     */
744
-    public function get_timezone_abbrev($timezone_string)
745
-    {
746
-        $timezone_string = EEH_DTT_Helper::get_valid_timezone_string($timezone_string);
747
-        $dateTime        = new DateTime(\EE_Datetime_Field::now, new DateTimeZone($timezone_string));
748
-
749
-        return $dateTime->format('T');
750
-    }
751
-
752
-    /**
753
-     * Overrides the parent to allow for having a dynamic "now" value
754
-     *
755
-     * @return mixed
756
-     */
757
-    public function get_default_value()
758
-    {
759
-        if ($this->_default_value === EE_Datetime_Field::now) {
760
-            return time();
761
-        } else {
762
-            return parent::get_default_value();
763
-        }
764
-    }
765
-
766
-
767
-    public function getSchemaDescription()
768
-    {
769
-        return sprintf(
770
-            esc_html__('%s - the value for this field is in the timezone of the site.', 'event_espresso'),
771
-            $this->get_nicename()
772
-        );
773
-    }
539
+						'event_espresso'
540
+					),
541
+					'<br />',
542
+					print_r($datetime_value, true)
543
+				)
544
+			);
545
+		}
546
+
547
+		if ($datetime_value instanceof DateTime) {
548
+			if ( ! $datetime_value instanceof DbSafeDateTime) {
549
+				$datetime_value = DbSafeDateTime::createFromDateTime($datetime_value);
550
+			}
551
+
552
+			return $datetime_value->setTimezone($this->get_UTC_DateTimeZone())->format(
553
+				EE_Datetime_Field::mysql_timestamp_format
554
+			);
555
+		}
556
+
557
+		// if $datetime_value is empty, and ! $this->_nullable, use current_time() but set the GMT flag to true
558
+		return ! $this->_nullable && empty($datetime_value) ? current_time('mysql', true) : null;
559
+	}
560
+
561
+
562
+	/**
563
+	 * This prepares the datetime for internal usage as a PHP DateTime object OR null (if nullable is
564
+	 * allowed)
565
+	 *
566
+	 * @param string $datetime_string mysql timestamp in UTC
567
+	 * @return  mixed null | DateTime
568
+	 * @throws \EE_Error
569
+	 */
570
+	public function prepare_for_set_from_db($datetime_string)
571
+	{
572
+		//if $datetime_value is empty, and ! $this->_nullable, just use time()
573
+		if (empty($datetime_string) && $this->_nullable) {
574
+			return null;
575
+		}
576
+		// datetime strings from the db should ALWAYS be in UTC+0, so use UTC_DateTimeZone when creating
577
+		if (empty($datetime_string)) {
578
+			$DateTime = new DbSafeDateTime(\EE_Datetime_Field::now, $this->get_UTC_DateTimeZone());
579
+		} else {
580
+			$DateTime = DateTime::createFromFormat(
581
+				EE_Datetime_Field::mysql_timestamp_format,
582
+				$datetime_string,
583
+				$this->get_UTC_DateTimeZone()
584
+			);
585
+			if ($DateTime instanceof \DateTime) {
586
+				$DateTime = new DbSafeDateTime(
587
+					$DateTime->format(\EE_Datetime_Field::mysql_timestamp_format),
588
+					$this->get_UTC_DateTimeZone()
589
+				);
590
+			}
591
+		}
592
+
593
+		if (! $DateTime instanceof DbSafeDateTime) {
594
+			// if still no datetime object, then let's just use now
595
+			$DateTime = new DbSafeDateTime(\EE_Datetime_Field::now, $this->get_UTC_DateTimeZone());
596
+		}
597
+		// THEN apply the field's set DateTimeZone
598
+		$DateTime->setTimezone($this->_DateTimeZone);
599
+
600
+		return $DateTime;
601
+	}
602
+
603
+
604
+	/**
605
+	 * All this method does is determine if we're going to display the timezone string or not on any output.
606
+	 * To determine this we check if the set timezone offset is different than the blog's set timezone offset.
607
+	 * If so, then true.
608
+	 *
609
+	 * @return bool true for yes false for no
610
+	 * @throws \EE_Error
611
+	 */
612
+	protected function _display_timezone()
613
+	{
614
+
615
+		// first let's do a comparison of timezone strings.
616
+		// If they match then we can get out without any further calculations
617
+		$blog_string = get_option('timezone_string');
618
+		if ($blog_string === $this->_timezone_string) {
619
+			return false;
620
+		}
621
+		// now we need to calc the offset for the timezone string so we can compare with the blog offset.
622
+		$this_offset = $this->get_timezone_offset($this->_DateTimeZone);
623
+		$blog_offset = $this->get_timezone_offset($this->get_blog_DateTimeZone());
624
+		// now compare
625
+		return $blog_offset !== $this_offset;
626
+	}
627
+
628
+
629
+	/**
630
+	 * This method returns a php DateTime object for setting on the EE_Base_Class model.
631
+	 * EE passes around DateTime objects because they are MUCH easier to manipulate and deal
632
+	 * with.
633
+	 *
634
+	 * @param int|string|DateTime $date_string            This should be the incoming date string.  It's assumed to be
635
+	 *                                                    in the format that is set on the date_field (or DateTime
636
+	 *                                                    object)!
637
+	 * @return DateTime
638
+	 */
639
+	protected function _get_date_object($date_string)
640
+	{
641
+		//first if this is an empty date_string and nullable is allowed, just return null.
642
+		if ($this->_nullable && empty($date_string)) {
643
+			return null;
644
+		}
645
+
646
+		// if incoming date
647
+		if ($date_string instanceof DateTime) {
648
+			$date_string->setTimezone($this->_DateTimeZone);
649
+
650
+			return $date_string;
651
+		}
652
+		// if empty date_string and made it here.
653
+		// Return a datetime object for now in the given timezone.
654
+		if (empty($date_string)) {
655
+			return new DbSafeDateTime(\EE_Datetime_Field::now, $this->_DateTimeZone);
656
+		}
657
+		// if $date_string is matches something that looks like a Unix timestamp let's just use it.
658
+		if (preg_match(EE_Datetime_Field::unix_timestamp_regex, $date_string)) {
659
+			try {
660
+				// This is operating under the assumption that the incoming Unix timestamp
661
+				// is an ACTUAL Unix timestamp and not the calculated one output by current_time('timestamp');
662
+				$DateTime = new DbSafeDateTime(\EE_Datetime_Field::now, $this->_DateTimeZone);
663
+				$DateTime->setTimestamp($date_string);
664
+
665
+				return $DateTime;
666
+			} catch (Exception $e) {
667
+				// should be rare, but if things got fooled then let's just continue
668
+			}
669
+		}
670
+		//not a unix timestamp.  So we will use the set format on this object and set timezone to
671
+		//create the DateTime object.
672
+		$format = $this->_date_format . ' ' . $this->_time_format;
673
+		try {
674
+			$DateTime = DateTime::createFromFormat($format, $date_string, $this->_DateTimeZone);
675
+			if ($DateTime instanceof DateTime) {
676
+				$DateTime = new DbSafeDateTime(
677
+					$DateTime->format(\EE_Datetime_Field::mysql_timestamp_format),
678
+					$this->_DateTimeZone
679
+				);
680
+			}
681
+			if (! $DateTime instanceof DbSafeDateTime) {
682
+				throw new EE_Error(
683
+					sprintf(
684
+						__('"%1$s" does not represent a valid Date Time in the format "%2$s".', 'event_espresso'),
685
+						$date_string,
686
+						$format
687
+					)
688
+				);
689
+			}
690
+		} catch (Exception $e) {
691
+			// if we made it here then likely then something went really wrong.
692
+			// Instead of throwing an exception, let's just return a DateTime object for now, in the set timezone.
693
+			$DateTime = new DbSafeDateTime(\EE_Datetime_Field::now, $this->_DateTimeZone);
694
+		}
695
+
696
+		return $DateTime;
697
+	}
698
+
699
+
700
+
701
+	/**
702
+	 * get_timezone_transitions
703
+	 *
704
+	 * @param \DateTimeZone $DateTimeZone
705
+	 * @param int           $time
706
+	 * @param bool          $first_only
707
+	 * @return mixed
708
+	 */
709
+	public function get_timezone_transitions(DateTimeZone $DateTimeZone, $time = null, $first_only = true)
710
+	{
711
+		$time = is_int($time) || $time === null ? $time : strtotime($time);
712
+		$time = preg_match(EE_Datetime_Field::unix_timestamp_regex, $time) ? $time : time();
713
+		$transitions = $DateTimeZone->getTransitions($time);
714
+		return $first_only && ! isset($transitions['ts']) ? reset($transitions) : $transitions;
715
+	}
716
+
717
+
718
+
719
+	/**
720
+	 * get_timezone_offset
721
+	 *
722
+	 * @param \DateTimeZone $DateTimeZone
723
+	 * @param int           $time
724
+	 * @return mixed
725
+	 * @throws \DomainException
726
+	 */
727
+	public function get_timezone_offset(DateTimeZone $DateTimeZone, $time = null)
728
+	{
729
+		$transitions = $this->get_timezone_transitions($DateTimeZone, $time);
730
+		if ( ! isset($transitions['offset'])) {
731
+			throw new DomainException();
732
+		}
733
+		return $transitions['offset'];
734
+	}
735
+
736
+
737
+	/**
738
+	 * This will take an incoming timezone string and return the abbreviation for that timezone
739
+	 *
740
+	 * @param  string $timezone_string
741
+	 * @return string           abbreviation
742
+	 * @throws \EE_Error
743
+	 */
744
+	public function get_timezone_abbrev($timezone_string)
745
+	{
746
+		$timezone_string = EEH_DTT_Helper::get_valid_timezone_string($timezone_string);
747
+		$dateTime        = new DateTime(\EE_Datetime_Field::now, new DateTimeZone($timezone_string));
748
+
749
+		return $dateTime->format('T');
750
+	}
751
+
752
+	/**
753
+	 * Overrides the parent to allow for having a dynamic "now" value
754
+	 *
755
+	 * @return mixed
756
+	 */
757
+	public function get_default_value()
758
+	{
759
+		if ($this->_default_value === EE_Datetime_Field::now) {
760
+			return time();
761
+		} else {
762
+			return parent::get_default_value();
763
+		}
764
+	}
765
+
766
+
767
+	public function getSchemaDescription()
768
+	{
769
+		return sprintf(
770
+			esc_html__('%s - the value for this field is in the timezone of the site.', 'event_espresso'),
771
+			$this->get_nicename()
772
+		);
773
+	}
774 774
 }
Please login to merge, or discard this patch.