Completed
Branch FET-9046-messages-queue (fc38ba)
by
unknown
475:27 queued 459:28
created

EE_Messages::activate_messenger()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 63
Code Lines 2

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 63
rs 9.4347
cc 1
eloc 2
nc 1
nop 2

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
if (!defined('EVENT_ESPRESSO_VERSION') )
4
	exit('NO direct script access allowed');
5
6
/**
7
 * EE_Messages class
8
 *
9
 * This class is the main controller class for EE_Messages, it delegates messages to the messengers and contains other methods for obtaining various details about the active messengers and message types.
10
 *
11
 * @package		Event Espresso
12
 * @subpackage	includes/core/messages
13
 * @author		Darren Ethier, Brent Christensen
14
 *
15
 * ------------------------------------------------------------------------
16
 */
17
class EE_Messages {
18
19
20
	/**
21
	 * Array of active messengers.
22
	 * Format is this:
23
	 * array(
24
	 *      'messenger_name' => EE_messenger
25
	 * )
26
	 *
27
	 * @type EE_Messenger[]
28
	 */
29
	protected $_active_messengers = array();
30
31
32
33
34
	/**
35
	 * Formatted array of active message types grouped per messenger.
36
	 * Format is this:
37
	 * array(
38
	 *      'messenger_name' => array(
39
	 *          'settings' => array(
40
	 *              '{messenger_name}-message_types' => array(
41
	 *                  'message_type_name' => array() //variable array of settings corresponding to message type.
42
	 *              )
43
	 *          )
44
	 *      )
45
	 * )
46
	 * @type array
47
	 */
48
	protected $_active_message_types = array();
49
50
51
52
53
54
	/**
55
	 * @type EE_message_type[]
56
	 */
57
	protected $_installed_message_types = array();
58
59
60
61
62
63
	/**
64
	 * When setting up values this is a temporary holder of the current EE_messenger object.
65
	 *
66
*@type EE_Messenger
67
	 */
68
	protected $_messenger;
69
70
71
72
73
74
	/**
75
	 * When setting up values this is a temporary holder of the current EE_message_type object.
76
	 * @type EE_message_type
77
	 */
78
	protected $_message_type;
79
80
81
82
83
84
	/**
85
	 * An array of unique message type contexts across all active message types.
86
	 *
87
	 * The array will be indexed by either 'slugs' or 'all'.
88
	 * The slugs index contains an array indexed by unique context slugs with the latest label representation for that slug.
89
	 * array(
90
	 *      'context_slug' => 'localized label for context obtained from latest message type in the loop'.
91
	 * );
92
	 *
93
	 * The all index returns an array in this format:
94
	 * array(
95
	 *      'message_type_name' => array(
96
	 *          'context_slug' => array(
97
	 *              'label' => 'localized label for context',
98
	 *              'description' => 'localized description for context'
99
	 *          )
100
	 *      )
101
	 * );
102
	 * @type array
103
	 */
104
	protected $_contexts = array();
105
106
107
	/**
108
	 * @type EE_Message_Resource_Manager $_message_resource_manager
109
	 */
110
	protected $_message_resource_manager;
111
112
113
114
	/**
115
	 * EE_Messages constructor.
116
	 *
117
	 * @deprecated 4.9.0
118
	 */
119
	function __construct() {
120
		// not yet
121
		//EE_Error::doing_it_wrong(
122
		//	'construct',
123
		//	__( 'EE_messages has been deprecated.  Please use EE_Message_Resource_Manager instead.' ),
124
		//	'4.9.0'
125
		//);
126
		$this->_message_resource_manager = EE_Registry::instance()->load_lib( 'Message_Resource_Manager' );
127
		// get list of active messengers and active message types
128
		//$this->_set_active_messengers_and_message_types();
129
	}
130
131
132
133
	/**
134
	 * get active messengers from db and instantiate them.
135
	 */
136
	//private function _set_active_messengers_and_message_types() {
137
		//$this->_active_messengers = $this->_message_resource_manager->active_messengers();
138
		//$this->_active_message_types = $this->_message_resource_manager->active_message_types();
139
		//// todo: right now this just gets active global messengers: at some point we'll have to get what the active messengers are for the event.
140
		//$_actives = EEH_MSG_Template::get_active_messengers_in_db();
141
		//$actives = is_array( $_actives ) ? array_keys( $_actives ) : $_actives;
142
		//$active_names = $this->_load_files( 'messenger', $actives );
143
		//if ( is_array( $active_names ) ) {
144
		//	foreach ( $active_names as $name => $class ) {
145
		//		$active = new $class();
146
		//		if ( ! $active instanceof EE_Messenger ) {
147
		//			//we've got an error so let's bubble up the error_object to be caught by caller.
148
		//			//todo: would be better to just catch the errors and then return any aggregated errors later.
149
		//			EE_Error::add_error(
150
		//				sprintf(
151
		//					__( 'The "%1$s" messenger is not installed or is invalid', 'event_espresso' ),
152
		//					$class
153
		//				),
154
		//				__FILE__,
155
		//				__FUNCTION__,
156
		//				__LINE__
157
		//			);
158
		//		}
159
		//		$this->_active_messengers[ $name ] = $active;
160
		//		$this->_active_message_types[ $name ] = ! empty( $_actives[ $name ][ 'settings' ][ $name
161
		//																						   . '-message_types' ] )
162
		//			? $_actives[ $name ][ 'settings' ][ $name . '-message_types' ]
163
		//			: array();
164
		//	}
165
		//}
166
	//}
167
168
169
170
	/**
171
	 * Ensures that the specified messenger is currently active.
172
	 * If not, activates it and its default message types.
173
	 *
174
	 * >>>>>>>>>>>> 1 usage in \EE_Payment_Method_Manager::activate_a_payment_method_of_type()
175
	 * >>>>>>>>>>>> 2 usages in \EE_messages_Test::test_ensure_messenger_is_active()
176
	 *
177
	 * @deprecated 4.9.0
178
	 * @param string $messenger_name
179
	 * @return boolean TRUE if it was PREVIOUSLY active, and FALSE if it was previously inactive
180
	 */
181
	public function ensure_messenger_is_active( $messenger_name ){
182
		return $this->_message_resource_manager->ensure_messenger_is_active( $messenger_name );
183
		//note: active messengers indexed by their names
184
		//$active_messengers = EEH_MSG_Template::get_active_messengers_in_db();
185
		//if( ! isset( $active_messengers[ $messenger_name ] ) ) {
186
		//	$this->activate_messenger( $messenger_name );
187
		//	return FALSE;
188
		//}else{
189
		//	return TRUE;
190
		//}
191
	}
192
193
194
195
	/**
196
	 * Ensures that the specified message type for the given messenger is currently active, if not activates it.
197
	 * This ALSO ensures that the given messenger is active as well!.
198
	 *
199
	 * >>>>>>>>>>>> 1 usage in \EE_Payment_Method_Manager::activate_a_payment_method_of_type()
200
	 * >>>>>>>>>>>> 1 usage in \EE_Register_Message_Type::set_defaults()
201
	 *
202
	 * @deprecated 4.9.0
203
	 * @param string $message_type message type name
204
	 * @param        $messenger
205
	 * @return bool true if it got activated (or was active) and false if not.
206
	 * @throws \EE_Error
207
	 */
208
	public function ensure_message_type_is_active( $message_type, $messenger ) {
209
		return $this->_message_resource_manager->ensure_message_type_is_active( $message_type, $messenger );
210
		//first validate that the incoming messenger allows this message type to be activated.
211
		//$messengers = $this->get_installed_messengers();
212
		//if ( ! isset( $messengers[$messenger] ) ) {
213
		//	throw new EE_Error( sprintf( __('The messenger sent to %s is not installed', 'event_espresso'), __METHOD__ ) );
214
		//}
215
		//
216
		//$msgr = $messengers[$messenger];
217
		//$valid_message_types = $msgr instanceof EE_Messenger ? $msgr->get_valid_message_types() : array();
218
		//if ( ! in_array( $message_type, $valid_message_types ) ) {
219
		//	throw new EE_Error(
220
		//		sprintf(
221
		//			__('The message type (%1$s) sent to %2$s is not valid for the %3$s messenger.  Double-check the spelling and verify that message type has been registered as a valid type with the messenger.', 'event_espresso' ),
222
		//			$message_type,
223
		//			__METHOD__,
224
		//			$messenger
225
		//		)
226
		//	);
227
		//}
228
		//
229
		////all is good so let's just get it active
230
		//return $this->activate_messenger( $messenger, array( $message_type ) );
231
	}
232
233
	/**
234
	 * Activates the specified messenger
235
	 *
236
	 * >>>>>>>>>>>> 2 usages found in this file: ensure_message_type_is_active() and ensure_messenger_is_active()
237
	 *
238
	 * @deprecated 4.9.0
239
	 * @param string $messenger_name
240
	 * @param array $mts_to_activate (optional) An array of message types to activate with this messenger.  If
241
	 *                             				included we do NOT setup the default message types (assuming
242
	 *                             				they are already setup.)
243
	 * @return boolean an array of generated templates or false if nothing generated/activated.
244
	 */
245
	public function activate_messenger( $messenger_name, $mts_to_activate = array() ){
246
		return $this->_message_resource_manager->activate_messenger( $messenger_name, $mts_to_activate );
247
		//$active_messengers = EEH_MSG_Template::get_active_messengers_in_db();
248
		//$message_types = $this->get_installed_message_types();
249
		//$installed_messengers = $this->get_installed_messengers();
250
		//$templates = false;
251
		//$settings = array();
252
		////get has_active so we can be sure its kept up to date.
253
		//$has_activated = get_option( 'ee_has_activated_messenger' );
254
		//
255
		////grab the messenger to work with.
256
		//$messenger = isset( $installed_messengers[$messenger_name] ) ? $installed_messengers[$messenger_name] : null;
257
		//
258
		////it's inactive. Activate it.
259
		//
260
		//if( $messenger instanceof EE_Messenger ) {
261
		//	$active_messengers[ $messenger->name ][ 'obj' ] = $messenger;
262
		//
263
		//	/** @var EE_Messenger[] $installed_messengers  */
264
		//	$mts_to_activate = ! empty( $mts_to_activate ) ? $mts_to_activate :  $messenger->get_default_message_types();
265
		//	foreach ( $mts_to_activate as $message_type ) {
266
		//		//we need to setup any initial settings for message types
267
		//		/** @var EE_message_type[] $installed_mts */
268
		//		$settings_fields = isset( $message_types[$message_type] ) ? $message_types[ $message_type ]->get_admin_settings_fields() : array();
269
		//		if ( !empty( $settings_fields ) ) {
270
		//			foreach ( $settings_fields as $field => $values ) {
271
		//				$settings[$field] = $values[ 'default' ];
272
		//			}
273
		//		} else {
274
		//			$settings = array();
275
		//		}
276
		//
277
		//		$active_messengers[ $messenger->name ][ 'settings' ][ $messenger->name . '-message_types' ][ $message_type ][ 'settings' ] = $settings;
278
		//
279
		//		if (  ! empty( $has_activated[$messenger->name] ) && ! in_array( $message_type, $has_activated[$messenger->name] ) ) {
280
		//			$has_activated[$messenger->name][] = $message_type;
281
		//		}
282
		//	}
283
		//
284
		//	//setup any initial settings for the messenger
285
		//	$msgr_settings = $messenger->get_admin_settings_fields();
286
		//
287
		//	if ( !empty( $msgr_settings ) ) {
288
		//		foreach ( $msgr_settings as $field => $value ) {
289
		//			$active_messengers[ $messenger->name ][ 'settings' ][ $field ] = $value;
290
		//		}
291
		//	}
292
		//
293
		//	EEH_MSG_Template::update_active_messengers_in_db( $active_messengers );
294
		//	update_option( 'ee_has_activated_messenger', $has_activated );
295
		//
296
		//	//make sure that the cached active_messengers is set on this object
297
		//	$this->_active_messengers[$messenger->name] = $messenger;
298
		//	$this->_active_message_types[$messenger->name] = $active_messengers[$messenger->name];
299
		//
300
		//	//might need to generate new templates
301
		//	if ( ! empty( $mts_to_activate ) ) {
302
		//		$templates = EEH_MSG_Template::generate_new_templates( $messenger->name, $mts_to_activate, 0, TRUE );
303
		//	}
304
		//}
305
		//
306
		//return $templates;
307
	}
308
309
310
311
	/**
312
	 * load the active files needed (key word... NEEDED)
313
	 *
314
	 * >>>>>>>>> 1 usage in \EE_Messages::_set_active_messengers_and_message_types()
315
	 *
316
	 * @param string $kind indicates what kind of files we are loading.
317
	 * @param array  $actives indicates what active types of the $kind are actually to be loaded.
318
	 * @return array|void
319
	 */
320
	//private function _load_files( $kind, $actives ) {
321
		//$active_names = array();
322
		//$base_path = EE_LIBRARIES . 'messages' . DS . $kind . DS;
323
		//if ( empty( $actives ) ) {
324
		//	return false;
325
		//}
326
		////make sure autoloaders are set (fail-safe)
327
		//EED_Messages::set_autoloaders();
328
		////make sure $actives is an array
329
		//$actives = (array)$actives;
330
		//EE_Registry::instance()->load_helper( 'File' );
331
		//foreach ( $actives as $active ) {
332
		//	$msg_name = 'EE_' . ucwords( str_replace( ' ', '_', $active ) ) . '_' . $kind;
333
		//	$filename = $msg_name . '.class.php';
334
		//	$load_file = $base_path . DS . $filename;
335
		//	if ( is_readable( $load_file ) ) {
336
		//		require_once( $load_file );
337
		//		$active_names[ $active ] = $msg_name;
338
		//	} else {
339
		//		$this->_unset_active( $active, $kind );
340
		//		//set WP_Error
341
		//		EE_Error::add_error(
342
		//			sprintf(
343
		//				__(
344
		//					'Missing messages system file set as inactive: (%1$s) %2$s has been made inactive.',
345
		//					'event_espresso'
346
		//				),
347
		//				$load_file,
348
		//				$msg_name
349
		//			),
350
		//			__FILE__,
351
		//			__FUNCTION__,
352
		//			__LINE__
353
		//		);
354
		//		return false;
355
		//	}
356
		//}
357
		//return $active_names;
358
	//}
359
360
361
362
	/**
363
	 * unsets the active if we can't find the file (fail-safe)
364
	 *
365
	 * @access private
366
	 * @param  string $active_name name of messenger or message type
367
	 * @param  string $kind        messenger or message_type?
368
	 * @return void
369
	 */
370
	//private function _unset_active( $active_name, $kind ) {
371
	//	//pluralize
372
	//	$active_messengers = EEH_MSG_Template::get_active_messengers_in_db();
373
	//	EE_Registry::instance()->load_helper( 'MSG_Template' );
374
	//	if ( $kind == 'messenger' ) {
375
	//		unset( $active_messengers[ $active_name ] );
376
	//		EEH_MSG_Template::update_to_inactive( $active_name );
377
	//		if ( isset( $this->_active_messengers[ $active_name ] ) ) {
378
	//			unset( $this->_active_messengers[ $active_name ] );
379
	//		}
380
	//	} else {
381
	//		foreach ( $active_messengers as $messenger => $settings ) {
382
	//			if ( ! empty( $settings[ 'settings' ][ $messenger . '-message_types' ][ $active_name ] ) ) {
383
	//				unset( $active_messengers[ $messenger ][ 'settings' ][ $messenger
384
	//																	   . '-message_types' ][ $active_name ] );
385
	//			}
386
	//		}
387
	//		EEH_MSG_Template::update_to_inactive( '', $active_name );
388
	//		if ( isset( $this->_active_message_types[ $active_name ] ) ) {
389
	//			unset( $this->_active_message_types[ $active_name ] );
390
	//		}
391
	//	}
392
	//	EEH_MSG_Template::update_active_messengers_in_db( $active_messengers );
393
	//}
394
395
396
397
	/**
398
	 * Used to verify if a message can be sent for the given messenger and message type and that it is a generating messenger (used for generating message templates).
399
	 *
400
	 * >>>>>>>>>>>> NO usages found
401
	 *
402
	 * @deprecated 4.9.0
403
	 * @param EE_Messenger    $messenger    messenger used in trigger
404
	 * @param EE_message_type $message_type message type used in trigger
405
	 *
406
	 * @return bool true is a generating messenger and can be sent OR FALSE meaning cannot send.
407
	 */
408
	public function is_generating_messenger_and_active( EE_Messenger $messenger, EE_message_type $message_type ) {
409
		return $this->_message_resource_manager->is_generating_messenger_and_active( $messenger, $message_type );
410
		//get the $messengers the message type says it can be used with.
411
		//$used_with = $message_type->with_messengers();
412
		//foreach ( $used_with as $generating_msgr => $secondary_msgrs ) {
413
		//	if (
414
		//		$messenger->name == $generating_msgr
415
		//		&& isset( $this->_active_message_types[$generating_msgr][$message_type->name] )
416
		//	) {
417
		//		return true;
418
		//	}
419
		//}
420
		//return false;
421
	}
422
423
424
	/**
425
	 * This returns the corresponding EE_Messenger object for the given string if it is active.
426
	 *
427
	 * >>>>>>>>>>>> 1 usage in \EE_Message_Generated_From_Token::get_EE_Message()
428
	 * >>>>>>>>>>>> 1 usage in \EE_Message_To_Generate_From_Request::__construct()
429
	 * >>>>>>>>>>>> 1 usage in \EE_Messages::validate_for_use()
430
	 * >>>>>>>>>>>> 2 usages in \EE_Messages_Queue::execute()
431
	 *
432
	 * @deprecated 4.9.0
433
	 * @param string    $messenger
434
	 * @return EE_Messenger | null
435
	 */
436
	public function get_messenger_if_active( $messenger ) {
437
		return $this->_message_resource_manager->get_active_messenger( $messenger );
438
		//return ! empty( $this->_active_messengers[$messenger] ) ? $this->_active_messengers[$messenger] : null;
439
	}
440
441
442
	/**
443
	 * This validates whether the given EE_Message object can be used for either sending or generation.
444
	 * This is done by grabbing the messenger and message type on the EE_Message and verifying that both are installed
445
	 * and active.
446
	 *
447
	 * >>>>>>>>>>>> 1 usage in \EE_Message_To_Generate::_set_valid()
448
	 * >>>>>>>>>>>> 1 usage in \EE_Messages_Generator::_validate_messenger_and_message_type()
449
	 *
450
	 * @deprecated 4.9.0
451
	 * @param EE_Message $message
452
	 * @return array  An array with 'messenger' and 'message_type' as the index and the corresponding valid object if
453
	 *                available.
454
	 *                Eg. Valid Messenger and Message Type:
455
	 *                array(
456
	 *                  'messenger' => new EE_Email_Messenger(),
457
	 *                  'message_type' => new EE_Registration_Approved_message_type()
458
	 *                )
459
	 *                Valid Messenger and Invalid Message Type:
460
	 *                array(
461
	 *                  'messenger' => new EE_Email_Messenger(),
462
	 *                  'message_type' => null
463
	 *                )
464
	 */
465
	public function validate_for_use( EE_Message $message ) {
466
		return array(
467
			'messenger' 	=> $message->messenger_object(),
468
			'message_type' 	=> $message->message_type_object(),
469
		);
470
		//$validated_for_use['messenger'] = $this->get_messenger_if_active($message->messenger());
471
		//$validated_for_use['message_type'] = $this->get_active_message_type( $message->messenger(), $message->message_type() );
472
		//return $validated_for_use;
473
	}
474
475
476
477
	/**
478
	 * Delegates message sending to messengers
479
	 *
480
	 * >>>>>>>>>>>> 1 usage in \EED_Ticketing::_generate_tickets()
481
	 * >>>>>>>>>>>> 1 usage in \EED_Ticketing::maybe_ticket_notice()
482
	 * >>>>>>>>>>>> 1 usage in \EED_Ticketing::process_resend_ticket_notice()
483
	 *
484
	 * @deprecated 4.9.0
485
	 * @param  string  $type    What type of message are we sending (corresponds to message types)
486
	 * @param  mixed  $vars    Data being sent for parsing in the message
487
	 * @param  string $sending_messenger if included then we ONLY use the specified messenger for delivery.  Otherwise we cycle through all active messengers.
488
	 * @param string $generating_messenger if included then this messenger is used for generating the message templates (but not for sending).
489
	 * @param string $context If included then only a message type for a specific context will be generated.
490
	 * @param bool  $send 			       Default TRUE.  If false, then this will just return the generated EE_Messages objects which might be used by the trigger to setup a batch message (typically html messenger uses it).
491
	 * @return bool
492
	 */
493
	public function send_message( $type, $vars, $sending_messenger = '', $generating_messenger='', $context='', $send = TRUE ) {
0 ignored issues
show
Unused Code introduced by
The parameter $context is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
494
		$processor = new EE_Messages_Processor( $this );
495
		$error = FALSE;
496
497
		//try to intelligently determine what method we'll call based on the incoming data.
498
		//if generating and sending are different then generate and send immediately.
499
		if ( ! empty( $sending_messenger ) && $sending_messenger != $generating_messenger && $send ) {
500
			//in the legacy system, when generating and sending were different, that means all the
501
			//vars are already in the request object.  So let's just use that.
502
			try {
503
				$mtg = new EE_Message_To_Generate_From_Request( $this, EE_Registry::instance()->REQ );
504
				$processor->generate_and_send_now( $mtg );
505
			} catch ( EE_Error $e ) {
506
				$error_msg = __( 'Please note that a system message failed to send due to a technical issue.', 'event_espresso' );
507
				// add specific message for developers if WP_DEBUG in on
508
				$error_msg .= '||' . $e->getMessage();
509
				EE_Error::add_error( $error_msg, __FILE__, __FUNCTION__, __LINE__ );
510
				$error = true;
511
			}
512
		} else {
513
			$processor->generate_for_all_active_messengers( $type, $vars, $send );
514
			//let's find out if there were any errors and how many successfully were queued.
515
			$count_errors = $processor->get_queue()->count_STS_in_queue( EEM_Message::status_failed );
516
			$count_queued = $processor->get_queue()->count_STS_in_queue( EEM_Message::status_incomplete );
517
			$count_retry = $processor->get_queue()->count_STS_in_queue( EEM_Message::status_retry );
518
			$count_errors = $count_errors + $count_retry;
519
			if ( $count_errors > 0 ) {
520
				$error = true;
521
				if ( $count_errors > 1 && $count_retry > 1 && $count_queued > 1  ) {
522
					$message = sprintf(
523
						__(
524
							'There were %d errors and %d messages successfully queued for generation and sending',
525
							'event_espresso'
526
						),
527
						$count_errors,
528
						$count_queued
529
					);
530
				} elseif ( $count_errors > 1 && $count_queued === 1 ) {
531
					$message = sprintf(
532
						__(
533
							'There were %d errors and %d message successfully queued for generation.',
534
							'event_espresso'
535
						),
536
						$count_errors,
537
						$count_queued
538
					);
539
				} elseif ( $count_errors === 1 && $count_queued > 1 ) {
540
					$message = sprintf(
541
						__(
542
							'There was %d error and %d messages successfully queued for generation.',
543
							'event_espresso'
544
						),
545
						$count_errors,
546
						$count_queued
547
					);
548
				} else {
549
					$message = sprintf(
550
						__(
551
							'There was %d message that failed to be queued for generation.',
552
							'event_espresso'
553
						),
554
						$count_errors
555
					);
556
				}
557
				EE_Error::add_error( $message, __FILE__, __FUNCTION__, __LINE__ );
558
			} else {
559
				if ( $count_queued === 1 ) {
560
					$message = sprintf(
561
						__(
562
							'%d message successfully queued for generation.',
563
							'event_espresso'
564
						),
565
						$count_queued
566
					);
567
				} else {
568
					$message = sprintf(
569
						__(
570
							'%d messages were successfully queued for generation.',
571
							'event_espresso'
572
						),
573
						$count_queued
574
					);
575
				}
576
				EE_Error::add_success( $message );
577
			}
578
		}
579
		//if no error then return the generated message(s).
580
		if ( ! $error && ! $send ) {
581
			$generated_queue = $processor->generate_queue( false );
582
			//get message and return.
583
			$generated_queue->get_queue()->rewind();
584
			$messages = array();
585
			while( $generated_queue->get_queue()->valid() ) {
586
				$message = $generated_queue->get_queue()->current();
587
				if ( $message instanceof EE_Message ) {
588
					//set properties that might be expected by add-ons (backward compat)
589
					$message->content = $message->content();
0 ignored issues
show
Documentation Bug introduced by
The property $content was declared of type string, but $message->content() is of type boolean. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
Deprecated Code introduced by
The property EE_Message::$content has been deprecated with message: 4.9.0 Added for backward compat with add-on's

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
590
					$message->template_pack = $message->get_template_pack();
0 ignored issues
show
Documentation Bug introduced by
It seems like $message->get_template_pack() can also be of type object<EE_Messages_Template_Pack>. However, the property $template_pack is declared as type null. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
Deprecated Code introduced by
The property EE_Message::$template_pack has been deprecated with message: 4.9.0 Added for backward compat with add-on's

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
591
					$message->template_variation = $message->get_template_pack_variation();
0 ignored issues
show
Documentation Bug introduced by
It seems like $message->get_template_pack_variation() of type string is incompatible with the declared type null of property $template_variation.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
Deprecated Code introduced by
The property EE_Message::$template_variation has been deprecated with message: 4.9.0 Added for backward compat with add-on's

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
592
					$messages[] = $message;
593
				}
594
				$generated_queue->get_queue()->next();
595
			}
596
597
			return $messages;
598
		}
599
		return $error ? false : true; //yeah backwards eh?  Really what we're returning is if there is a total success for all the messages or not.  We'll modify this once we get message recording in place.
600
	}
601
602
603
604
605
	/**
606
	 * Use to generate and return a message preview!
607
	 *
608
	 * >>>>>>>>>>>> NO usages found
609
	 *
610
	 * @deprecated 4.9.0
611
	 * @param  string $type    This should correspond with a valid message type
612
	 * @param  string $context This should correspond with a valid context for the message type
613
	 * @param  string $messenger This should correspond with a valid messenger.
614
	 * @param bool 	$send true we will do a test send using the messenger delivery, false we just do a regular preview
615
	 * @return string          The body of the message.
616
	 */
617
	public function preview_message( $type, $context, $messenger, $send = FALSE ) {
618
		return EED_Messages::preview_message( $type, $context, $messenger, $send );
619
	}
620
621
622
	/**
623
	 * This is a method that allows for sending a message using a messenger matching the string given and the provided EE_Message stdClass objects.
624
	 *
625
	 * >>>>>>>>>>>> 1 usage in \EED_Ticketing::_generate_tickets()
626
	 *
627
	 * @since 4.5.0
628
	 * @deprecated 4.9.0   Moved to EED_Messages Module
629
	 * @param string       $messenger a string matching a valid active messenger in the system
630
	 * @param string       $message_type   Although it seems contrary to the name of the method, a message type name is still required to send along the message type to the messenger because this is used for determining what specific variations might be loaded for the generated message.
631
	 * @param stdClass $message  a stdClass object in the format expected by the messenger.
632
	 *
633
	 * @return bool          success or fail.
634
	 */
635
	public function send_message_with_messenger_only( $messenger, $message_type, $message ) {
636
		//setup for sending to new method.
637
		$queue = new EE_Messages_Queue( $this );
638
		//make sure we have a proper message object
639
		if ( ! $message instanceof EE_Message && is_object( $message ) && isset( $message->content ) ) {
640
			$msg = EE_Message_Factory::create(
641
				array(
642
					'MSG_messenger' => $messenger,
643
					'MSG_message_type' => $message_type,
644
					'MSG_content' => $message->content,
645
					'MSG_subject' => $message->subject
646
				)
647
			);
648
		} else {
649
			$msg = $message;
650
		}
651
652
		if ( ! $msg instanceof EE_Message ) {
653
			return false;
654
		}
655
		//make sure any content in a content property (if not empty) is set on the MSG_content.
656
		if ( ! empty( $msg->content ) ) {
0 ignored issues
show
Deprecated Code introduced by
The property EE_Message::$content has been deprecated with message: 4.9.0 Added for backward compat with add-on's

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
657
			$msg->set( 'MSG_content', $msg->content );
0 ignored issues
show
Deprecated Code introduced by
The property EE_Message::$content has been deprecated with message: 4.9.0 Added for backward compat with add-on's

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
658
		}
659
		$queue->add( $msg );
660
		return EED_Messages::send_message_with_messenger_only( $messenger, $message_type, $queue );
661
	}
662
663
664
665
666
667
	/**
668
	 * _validate_setup
669
	 *
670
	 * >>>>>>>>>>>> 1 usage in \EE_Messages::create_new_templates()
671
	 * >>>>>>>>>>>> 1 usage in \EE_Messages::get_fields()
672
	 *
673
	 * @param  string $messenger_name    name of EE_Messenger
674
	 * @param  string $message_type_name name of EE_message_type
675
	 * @param  bool   $global       whether this is a global template or not.
676
	 * @throws EE_Error
677
	 * @return bool(true)|WP_Error
678
	 */
679
	//private function _validate_setup( $messenger_name, $message_type_name, $global = false ) {
680
		//$message_type = strtolower( str_replace( ' ', '_', $message_type ) );
681
		//$messenger = strtolower( str_replace( ' ', '_', $messenger ) );
682
		//$installed_message_types = $this->get_installed_message_types();
683
		////setup messenger and message_type object
684
		//$this->_messenger = isset( $this->_active_messengers[ $messenger ] ) ? $this->_active_messengers[ $messenger ]
685
		//	: null;
686
		////message type
687
		//$mt = isset( $installed_message_types[ $message_type ] ) ? $installed_message_types[ $message_type ]
688
		//	: 'message_type_not_existent';
689
		//$this->_message_type = is_object( $mt ) ? $mt : null;
690
		////do we have the necessary objects loaded?
691
		//if ( empty( $this->_messenger ) || empty( $this->_message_type ) ) {
692
		//	throw new EE_Error(
693
		//		sprintf(
694
		//			__(
695
		//				' The %s messenger or the %s message_type are not active. Are you sure they exist?',
696
		//				'event_espresso'
697
		//			),
698
		//			$messenger,
699
		//			$message_type
700
		//		)
701
		//	);
702
		//}
703
		////is given message_type valid for given messenger (if this is not a global save)
704
		//if ( ! $is_global ) {
705
		//	$has_active = EEM_Message_Template_Group::instance()->count(
706
		//		array(
707
		//			array(
708
		//				'MTP_is_active' => true, 'MTP_messenger' => $this->_messenger->name,
709
		//				'MTP_message_type' => $message_type
710
		//			)
711
		//		)
712
		//	);
713
		//	if ( $has_active == 0 ) {
714
		//		EE_Error::add_error(
715
		//			sprintf(
716
		//				__(
717
		//					' The %1$s message type is not registered with the %2$s messenger. Please visit the Messenger activation page to assign this message type first if you want to use it.',
718
		//					'event_espresso'
719
		//				),
720
		//				$message_type,
721
		//				$messenger
722
		//			),
723
		//			__FILE__,
724
		//			__FUNCTION__,
725
		//			__LINE__
726
		//		);
727
		//		return false;
728
		//	}
729
		//}
730
		//return true;
731
	//}
732
733
734
735
	/**
736
	 * This is a wrapper for the protected _create_new_templates function
737
	 *
738
	 * >>>>>>>>>>>> 1 usage in \EEH_MSG_Template::generate_new_templates()
739
	 *
740
	 * @deprecated 4.9.0
741
	 * @param         $messenger
742
	 * @param  string $message_type message type that the templates are being created for
743
	 * @param int     $GRP_ID
744
	 * @param bool    $is_global
745
	 * @return array|object if creation is successful then we return an array of info, otherwise an error_object is returned.
746
	 * @throws \EE_Error
747
	 */
748
	public function create_new_templates( $messenger, $message_type, $GRP_ID = 0, $is_global = false ) {
749
		/** @type EEH_MSG_Template $MSG_Template */
750
		$MSG_Template = EE_Registry::instance()->load_helper( 'MSG_Template' );
751
		return $MSG_Template->create_new_templates( $messenger, $message_type, $GRP_ID, $is_global );
752
		//$valid_mt = $this->_validate_setup($messenger, $message_type, $is_global);
753
		//
754
		//if ( is_wp_error($valid_mt) && $is_global ) {
755
		//	//we're setting up a brand new global templates (with messenger activation) so we're assuming that the message types sent in are valid.
756
		//	$valid_mt = true;
757
		//}
758
		//
759
		//if ( is_wp_error($valid_mt) ) {
760
		//	//if we've still got no valid_mt then bubble up error object
761
		//	return $valid_mt;
762
		//}
763
		//
764
		////whew made it this far!  Okay, let's go ahead and create the templates then
765
		//return $this->_create_new_templates($GRP_ID, $is_global);
766
	}
767
768
769
770
	/**
771
	 * @param $GRP_ID
772
	 * @param $is_global
773
	 * @return array|mixed
774
	 */
775
	//protected function _create_new_templates( $GRP_ID, $is_global) {
776
	//
777
	//	//if we're creating a custom template then we don't need to use the defaults class
778
	//	if ( ! $is_global )
779
	//		return $this->_create_custom_template_group( $GRP_ID );
780
	//
781
	//	$DFLT = new EE_Message_Template_Defaults( $this, $this->_messenger->name, $this->_message_type->name, $GRP_ID );
782
	//
783
	//	//generate templates
784
	//	$success = $DFLT->create_new_templates();
785
	//
786
	//	/**
787
	//	 * $success is in an array in the following format
788
	//	 * array(
789
	//	 * 	'GRP_ID' => $new_grp_id,
790
	//	 * 	'MTP_context' => $first_context_in_new_templates,
791
	//	 * )
792
	//	 */
793
	//	return $success;
794
	//}
795
796
797
798
	/**
799
	 * This creates a custom template using the incoming GRP_ID
800
	 *
801
	 * @param  int     $GRP_ID GRP_ID for the template_group being used as the base
802
	 * @return  array $success             This will be an array in the format:
803
	 *                                     			array(
804
	 *                                     				'GRP_ID' => $new_grp_id,
805
	 *                                     				'MTP_context' => $first_context_in_created_template
806
	 *                                     			)
807
	 * @access private
808
	 */
809
	//private function _create_custom_template_group( $GRP_ID ) {
810
	//	//defaults
811
	//	$success = array( 'GRP_ID' => NULL, 'MTP_context' => '' );
812
	//
813
	//	//get the template group to use as a template from the db.  If $GRP_ID is empty then we'll assume the base will be the global template matching the messenger and message type.
814
	//	$mtg = empty( $GRP_ID ) ? EEM_Message_Template_Group::instance()->get_one( array( array( 'MTP_messenger' => $this->_messenger->name, 'MTP_message_type' => $this->_message_type->name, 'MTP_is_global' => TRUE ) ) ) : EEM_Message_Template_Group::instance()->get_one_by_ID( $GRP_ID );
815
	//
816
	//	//if we don't have a mtg at this point then we need to bail.
817
	//	if ( ! $mtg instanceof EE_Message_Template_Group ) {
818
	//		EE_Error::add_error( sprintf( __('Something went wrong with generating the custom template from this group id: %s.  This usually happens when there is no matching message template group in the db.', 'event_espresso'), $GRP_ID ), __FILE__, __FUNCTION__, __LINE__ );
819
	//		return $success;
820
	//	}
821
	//
822
	//	//let's get all the related message_template objects for this group.
823
	//	$mtts = $mtg->message_templates();
824
	//
825
	//	//now we have what we need to setup the new template
826
	//	$new_mtg = clone $mtg;
827
	//	$new_mtg->set('GRP_ID', 0);
828
	//	$new_mtg->set('MTP_is_global', FALSE);
829
	//
830
	//	$template_name = defined('DOING_AJAX') && !empty( $_POST['templateName'] ) ? $_POST['templateName'] : __('New Custom Template', 'event_espresso');
831
	//	$template_description = defined("DOING_AJAX") && !empty( $_POST['templateDescription'] ) ? $_POST['templateDescription'] : sprintf( __('This is a custom template that was created for the %s messenger and %s message type.', 'event_espresso' ), $new_mtg->messenger_obj()->label['singular'], $new_mtg->message_type_obj()->label['singular'] );
832
	//
833
	//
834
	//	$new_mtg->set('MTP_name', $template_name );
835
	//	$new_mtg->set('MTP_description', $template_description );
836
	//	//remove ALL relations on this template group so they don't get saved!
837
	//	$new_mtg->_remove_relations( 'Message_Template' );
838
	//	$new_mtg->save();
839
	//	$success['GRP_ID'] = $new_mtg->ID();
840
	//	$success['template_name'] = $template_name;
841
	//
842
	//	//add new message templates and add relation to.
843
	//	foreach ( $mtts as $mtt ) {
844
	//		if ( ! $mtt instanceof EE_Message_Template )
845
	//			continue;
846
	//		$nmtt = clone $mtt;
847
	//		$nmtt->set('MTP_ID', 0);
848
	//		$nmtt->set( 'GRP_ID', $new_mtg->ID() ); //relation
849
	//		$nmtt->save();
850
	//		if ( empty( $success['MTP_context'] ) )
851
	//			$success['MTP_context'] = $nmtt->get('MTP_context');
852
	//	}
853
	//
854
	//	return $success;
855
	//
856
	//}
857
858
859
860
861
	/**
862
	 * get_fields
863
	 * This takes a given messenger and message type and returns all the template fields indexed by context (and with field type).
864
	 *
865
	 * >>>>>>>>>>>> 1 usage in \Messages_Admin_Page::_edit_message_template()
866
	 *
867
	 * @deprecated 4.9.0
868
	 * @param  string $messenger_name    name of EE_Messenger
869
	 * @param  string $message_type_name name of EE_message_type
870
	 * @return array
871
	 */
872
	public function get_fields( $messenger_name, $message_type_name ) {
873
		/** @type EEH_MSG_Template $MSG_Template */
874
		$MSG_Template = EE_Registry::instance()->load_helper( 'MSG_Template' );
875
		return $MSG_Template->get_fields( $messenger_name, $message_type_name );
876
		//$template_fields = array();
877
		///** @type EE_Message_Resource_Manager $Message_Resource_Manager */
878
		//$Message_Resource_Manager = EE_Registry::instance()->load_lib( 'Message_Resource_Manager' );
879
		//$messenger = $Message_Resource_Manager->valid_messenger( $messenger_name );
880
		//$message_type = $Message_Resource_Manager->valid_message_type( $message_type_name );
881
		//if ( $MSG_Template->message_type_has_active_templates_for_messenger( $messenger, $message_type ) ) {
882
		//	return array();
883
		//}
884
		////okay now let's assemble an array with the messenger template fields added to the message_type contexts.
885
		//foreach ( $message_type->get_contexts() as $context => $details ) {
886
		//	foreach ( $messenger->get_template_fields() as $field => $value ) {
887
		//		$template_fields[$context][$field] = $value;
888
		//	}
889
		//}
890
		//if ( empty( $template_fields ) ) {
891
		//	EE_Error::add_error(
892
		//		__( 'Something went wrong and we couldn\'t get any templates assembled', 'event_espresso' ),
893
		//		__FILE__,
894
		//		__FUNCTION__,
895
		//		__LINE__
896
		//	);
897
		//	return array();
898
		//}
899
		//return $template_fields;
900
	}
901
902
903
904
	/**
905
	 * gets an array of installed messengers and message types objects.
906
	 *
907
	 * >>>>>>>>>>>> 1 usage in \EEH_MSG_Template::get_installed_message_objects()
908
	 * >>>>>>>>>>>> 1 usage in \EE_Messages::get_installed_message_types()
909
	 * >>>>>>>>>>>> 1 usage in \EE_Messages::get_installed_messengers()
910
	 *
911
	 * @deprecated 4.9.0
912
	 * @access public
913
	 * @param string $type 				we can indicate just returning installed message types
914
	 *                     				or messengers (or both) via this parameter.
915
	 * @param bool 		$skip_cache 	if true then we skip the cache and retrieve via files.
916
	 * @return array                    multidimensional array of messenger and message_type objects
917
	 *                                    (messengers index, and message_type index);
918
	 */
919
	public function get_installed( $type = 'all', $skip_cache = false ) {
920
		if ( $skip_cache ) {
921
			$this->_message_resource_manager->reset_active_messengers_and_message_types();
0 ignored issues
show
Bug introduced by
The method reset_active_messengers_and_message_types() does not exist on EE_Message_Resource_Manager. Did you maybe mean active_messengers()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
922
		}
923
		switch ( $type ) {
924
925
			case 'messengers' :
926
				return array(
927
					'messenger'    => $this->_message_resource_manager->installed_messengers(),
928
				);
929
			break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
930
931
			case 'message_types' :
932
				return array(
933
					'message_type' => $this->_message_resource_manager->installed_message_types(),
934
				);
935
			break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
936
937
			case 'all' :
938
			default :
939
				return array(
940
					'messenger'    => $this->_message_resource_manager->installed_messengers(),
941
					'message_type' => $this->_message_resource_manager->installed_message_types(),
942
				);
943
			break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
944
945
		}
946
		//$installed = array();
947
		//
948
		////first let's account for caching
949
		//if ( $skip_cache ) {
950
		//	$message_base = EE_LIBRARIES . "messages" . DS;
951
		//
952
		//	$messenger_files = $type == 'all' || $type == 'messengers' ? scandir( $message_base . "messenger", 1) : NULL;
953
		//	$messagetype_files = $type == 'all' || $type == 'message_types' ? scandir( $message_base . "message_type", 1) : NULL;
954
		//
955
		//
956
		//	//allow plugins to filter in their messenger/message_type files
957
		//	$messenger_files = apply_filters('FHEE__EE_messages__get_installed__messenger_files', $messenger_files, $type );
958
		//	$messagetype_files = apply_filters('FHEE__EE_messages__get_installed__messagetype_files', $messagetype_files, $type );
959
		//
960
		//	$installed['messengers'] = !empty($messenger_files ) ? $this->_get_installed($messenger_files) : '';
961
		//	$installed['message_types'] = !empty($messagetype_files) ? $this->_get_installed($messagetype_files) : '';
962
		//} else {
963
		//	$installed['messengers'] = $this->get_installed_messengers();
964
		//	$installed['message_types'] = $this->get_installed_message_types();
965
		//}
966
		//
967
		//
968
		//if ( $type != 'all' ) {
969
		//	$installed = $type == 'messengers' ? $installed['messengers'] : $installed['message_types'];
970
		//}
971
		//
972
		//return $installed;
973
	}
974
975
976
	/**
977
	 * _get_installed
978
	 * takes an array of filenames and returns an array of objects instantiated from the class name found in the filename.
979
	 *
980
	 * @param  array $filenames and array of filenames
981
	 * @return array       array of objects
982
	 */
983
	//private function _get_installed($filenames) {
984
	//	//make sure incoming filenames are in an array.
985
	//	$the_goods = array();
986
	//	$filenames = (array) $filenames;
987
	//	$replace = ".class.php";
988
	//	foreach ( $filenames as $filename ) {
989
	//		$classname = preg_match("/" . $replace . "/", $filename ) ? str_replace($replace, "", $filename) : false;
990
	//
991
	//		//no classname? no match? move along, nothing to see here. note, the stripos is checking to make sure the filename (classname) begins with EE.
992
	//		if ( !$classname || 0 !== stripos($classname, 'EE') ) continue;
993
	//
994
	//		//note: I'm not sure if this will work without including the file.  We do have autoloaders so it "may" work.
995
	//		$object = new $classname();
996
	//		$the_goods[ $object->name ] = $object;
997
	//	}
998
	//	return $the_goods;
999
	//}
1000
1001
1002
1003
	/**
1004
	 * @deprecated 4.9.0
1005
	 * @return \EE_Messenger[]
1006
	 */
1007
	public function get_active_messengers() {
1008
		return $this->_message_resource_manager->active_messengers();
1009
		//return $this->_active_messengers;
1010
	}
1011
1012
1013
	/**
1014
	 * This does NOT return the _active_message_types property but
1015
	 * simply returns an array of active message types from that property.
1016
	 * (The _active_message_types property is indexed by messenger and active message_types per messenger).
1017
	 *
1018
	 * >>>>>>>>>>>> 1 usage in \Registrations_Admin_Page::_set_list_table_views_default()
1019
	 * >>>>>>>>>>>> 1 usage in \EEH_MSG_Template::is_mt_active()
1020
	 * >>>>>>>>>>>> 1 usage in \EE_Messages::get_active_message_type_objects()
1021
	 * >>>>>>>>>>>> 1 usage in \EED_Ticketing::process_resend_ticket_notice()
1022
	 *
1023
	 * @deprecated 4.9.0
1024
	 * @return array array of message_type references (string)
1025
	 */
1026
	public function get_active_message_types() {
1027
		return $this->_message_resource_manager->list_of_active_message_types();
1028
		//$message_types = array();
1029
		//foreach ( $this->_active_message_types as $messenger => $mtvalues ) {
1030
		//	foreach ( $mtvalues as $mt => $config ) {
1031
		//		if ( ! in_array( $mt, $message_types ) )
1032
		//			$message_types[] = $mt;
1033
		//	}
1034
		//}
1035
		//return $message_types;
1036
	}
1037
1038
1039
	/**
1040
	 * Same as get_active_message_types() except this returns actual EE_message_type objects
1041
	 *
1042
	 * >>>>>>>>>>>> 1 usage in \EE_Messages::get_all_contexts()
1043
	 *
1044
	 * @deprecated 4.9.0
1045
	 * @return EE_message_type[]
1046
	 */
1047
	public function get_active_message_type_objects() {
1048
		return $this->_message_resource_manager->get_active_message_type_objects();
1049
		//$message_types = array();
1050
		//$message_type_refs = $this->get_active_message_types();
1051
		//$installed_message_types = $this->get_installed_message_types();
1052
		//foreach ( $message_type_refs as $ref ) {
1053
		//	if ( isset( $installed_message_types[$ref] ) ) {
1054
		//		$message_types[] = $installed_message_types[$ref];
1055
		//	}
1056
		//}
1057
		//return $message_types;
1058
	}
1059
1060
1061
1062
1063
	/**
1064
	 * This checks the _active_message_types property for any active message types that are present for the given messenger and returns them.
1065
	 *
1066
	 * >>>>>>>>>>>> 1 usage in \espresso_events_Messages_Hooks_Extend::messages_metabox()
1067
	 *
1068
	 * @deprecated 4.9.0
1069
	 * @since 4.5.0
1070
	 * @param string $messenger The messenger being checked
1071
	 * @return EE_message_type[]    (or empty array if none present)
1072
	 */
1073
	public function get_active_message_types_per_messenger( $messenger ) {
1074
		return $this->_message_resource_manager->get_active_message_types_for_messenger( $messenger );
1075
		//$messenger = (string) $messenger;
1076
		//if ( empty( $this->_active_message_types[$messenger] ) ) {
1077
		//	return array();
1078
		//}
1079
		//
1080
		//$mts = array();
1081
		//$message_types = $this->_active_message_types[$messenger];
1082
		//$installed_message_types = $this->get_installed_message_types();
1083
		//foreach ( $message_types as $mt => $settings ) {
1084
		//	if ( ! empty( $installed_message_types[$mt] ) )  {
1085
		//		$mts[] = $installed_message_types[$mt];
1086
		//	}
1087
		//}
1088
		//return $mts;
1089
	}
1090
1091
1092
	/**
1093
	 * This returns the EE_message_type from the active message types array ( if present );
1094
	 *
1095
	 * >>>>>>>>>>>> 1 usage in \EE_Messages::validate_for_use()
1096
	 * >>>>>>>>>>>> 1 usage in \EE_Messages_Queue::execute()
1097
	 *
1098
	 * @deprecated 4.9.0
1099
	 * @param string $messenger      The string should correspond to the messenger (message types are
1100
	 * @param string $message_type The string should correspond to a message type.
1101
	 * @return EE_Message_Type|null
1102
	 */
1103
	public function get_active_message_type( $messenger, $message_type ) {
1104
		return $this->_message_resource_manager->get_active_message_type_for_messenger( $messenger, $message_type );
1105
		//$installed_message_types = $this->get_installed_message_types();
1106
		//if ( !empty( $this->_active_message_types[$messenger][$message_type] ) && !empty( $installed_message_types[$message_type] ) )  {
1107
		//	return $installed_message_types[$message_type];
1108
		//}
1109
		//return NULL;
1110
	}
1111
1112
1113
1114
	/**
1115
	 *
1116
	 * >>>>>>>>>>>> 1 usage in \Messages_Admin_Page::_get_installed_message_objects()
1117
	 * >>>>>>>>>>>> 1 usage in \EEH_MSG_Template::message_type_obj()
1118
	 * >>>>>>>>>>>> 1 usage in \EE_Message_Template_Defaults::_init()
1119
	 * >>>>>>>>>>>> 1 usage in \EE_Messages::_validate_setup()
1120
	 * >>>>>>>>>>>> 1 usage in \EE_Messages::activate_messenger()
1121
	 * >>>>>>>>>>>> 1 usage in \EE_Messages::get_active_message_type()
1122
	 * >>>>>>>>>>>> 1 usage in \EE_Messages::get_active_message_type_objects()
1123
	 * >>>>>>>>>>>> 1 usage in \EE_Messages::get_active_message_types_per_messenger()
1124
	 * >>>>>>>>>>>> 1 usage in \EE_Messages::get_installed()
1125
	 *
1126
	 * @deprecated 4.9.0
1127
	 * @return array|\EE_message_type[]
1128
	 */
1129
	public function get_installed_message_types() {
1130
		return $this->_message_resource_manager->installed_message_types();
1131
		//$this->_installed_message_types = empty( $this->_installed_message_types )
1132
		//	? $this->get_installed( 'message_types', true )
1133
		//	: $this->_installed_message_types;
1134
		//return $this->_installed_message_types;
1135
	}
1136
1137
1138
1139
	/**
1140
	 * >>>>>>>>>>>> 1 usage in \Messages_Admin_Page::_get_installed_message_objects()
1141
	 * >>>>>>>>>>>> 1 usage in \EEH_MSG_Template::messenger_obj()
1142
	 * >>>>>>>>>>>> 1 usage in \EE_Messages::activate_messenger()
1143
	 * >>>>>>>>>>>> 1 usage in \EE_Messages::ensure_message_type_is_active()
1144
	 * >>>>>>>>>>>> 1 usage in \EE_Messages::get_installed()
1145
	 *
1146
	 * @deprecated 4.9.0
1147
	 * @return array
1148
	 */
1149
	public function get_installed_messengers() {
1150
		return $this->_message_resource_manager->installed_messengers();
1151
		//$this->_installed_messengers = empty( $this->_installed_messengers )
1152
		//	? $this->get_installed( 'messengers', true )
1153
		//	: $this->_installed_messengers;
1154
		//return $this->_installed_messengers;
1155
	}
1156
1157
1158
1159
	/**
1160
	 * This returns all the contexts that are registered by all message types.
1161
	 *
1162
	 * If $slugs_only is true, then just an array indexed by unique context slugs with the latest label representation for that slug.
1163
	 * array(
1164
	 *      'context_slug' => 'localized label for context obtained from latest message type in the loop'.
1165
	 * );
1166
	 *
1167
	 * If $slugs_only is false, then the format is:
1168
	 * array(
1169
	 *      'message_type_name' => array(
1170
	 *          'context_slug' => array(
1171
	 *              'label' => 'localized label for context',
1172
	 *              'description' => 'localized description for context'
1173
	 *          )
1174
	 *      )
1175
	 * );
1176
	 *
1177
	 * Keep in mind that although different message types may share the same context slugs, it is possible that the context
1178
	 * is described differently by the message type.
1179
	 *
1180
	 * >>>>>>>>>>>> 1 usage in \EE_Message_List_Table::_get_table_filters()
1181
	 * >>>>>>>>>>>> 1 usage in \EE_Message::context_label()
1182
	 * >>>>>>>>>>>> 1 usage in \EE_messages_Test::test_get_all_contexts()
1183
	 *
1184
	 * @deprecated 4.9.0
1185
	 * @param   bool    $slugs_only     Whether to return an array of just slugs and labels (true) or all contexts indexed by message type.
1186
	 * @return array
1187
	 */
1188
	public function get_all_contexts( $slugs_only = true ) {
1189
		return $this->_message_resource_manager->get_all_contexts( $slugs_only );
1190
		//$key = $slugs_only ? 'slugs' : 'all';
1191
		//if ( ! empty( $this->_contexts[$key] ) ) {
1192
		//	return $this->_contexts[$key];
1193
		//}
1194
		//
1195
		////contexts has not been setup yet.  So let's get all active message type objects and loop through to get all
1196
		////unique contexts
1197
		//$contexts = array();
1198
		//foreach ( $this->get_active_message_type_objects() as $mt ) {
1199
		//	if ( $mt instanceof EE_message_type ) {
1200
		//		$mt_contexts = $mt->get_contexts();
1201
		//		if ( $slugs_only ) {
1202
		//			foreach ( $mt_contexts as $context => $context_details ) {
1203
		//				$contexts[ $context ] = $context_details['label'];
1204
		//			}
1205
		//		} else {
1206
		//			$contexts[$mt->name] = $mt_contexts;
1207
		//		}
1208
		//	}
1209
		//}
1210
		//
1211
		//$this->_contexts[$key] = $contexts;
1212
		//return $this->_contexts[$key];
1213
	}
1214
1215
1216
1217
}
1218
//end EE_Messages class
1219
// end of file:	includes/core/messages/EE_Messages.core.php
1220