Completed
Branch BUG-9951-10331-8793-pue-fixes (40e696)
by
unknown
27:52 queued 13:57
created
core/business/EE_Transaction_Payments.class.php 2 patches
Indentation   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -233,8 +233,8 @@
 block discarded – undo
233 233
 					if ( $registration instanceof EE_Registration ) {
234 234
 						$registration->set_paid( $registration->paid() - $amount_paid );
235 235
 						if ($registration->save() !== false) {
236
-						    $registration_payment->delete_permanently();
237
-                            $save_payment = true;
236
+							$registration_payment->delete_permanently();
237
+							$save_payment = true;
238 238
 						}
239 239
 					} else {
240 240
 						EE_Error::add_error(
Please login to merge, or discard this patch.
Spacing   +43 added lines, -43 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { exit('No direct script access allowed'); }
2
-EE_Registry::instance()->load_class( 'Processor_Base' );
2
+EE_Registry::instance()->load_class('Processor_Base');
3 3
 
4 4
 /**
5 5
  * Class EE_Transaction_Payments
@@ -42,7 +42,7 @@  discard block
 block discarded – undo
42 42
 	 */
43 43
 	public static function instance() {
44 44
 		// check if class object is instantiated
45
-		if ( ! self::$_instance instanceof EE_Transaction_Payments ) {
45
+		if ( ! self::$_instance instanceof EE_Transaction_Payments) {
46 46
 			self::$_instance = new self();
47 47
 		}
48 48
 		return self::$_instance;
@@ -59,18 +59,18 @@  discard block
 block discarded – undo
59 59
 	 * @return bool true if TXN total was updated, false if not
60 60
 	 * @throws \EE_Error
61 61
 	 */
62
-	public function recalculate_transaction_total( EE_Transaction $transaction, $update_txn = true ) {
62
+	public function recalculate_transaction_total(EE_Transaction $transaction, $update_txn = true) {
63 63
 		$total_line_item = $transaction->total_line_item();
64
-		if ( ! $total_line_item instanceof EE_Line_Item ) {
64
+		if ( ! $total_line_item instanceof EE_Line_Item) {
65 65
 			EE_Error::add_error(
66
-				sprintf( __( 'The Total Line Item for Transaction %1$d\'s was not found or is invalid.', 'event_espresso' ), $transaction->ID() ),
66
+				sprintf(__('The Total Line Item for Transaction %1$d\'s was not found or is invalid.', 'event_espresso'), $transaction->ID()),
67 67
 				__FILE__, __FUNCTION__, __LINE__
68 68
 			);
69 69
 			return false;
70 70
 		}
71 71
 		$new_total = $total_line_item->recalculate_total_including_taxes();
72
-		$transaction->set_total( $new_total );
73
-		if ( $update_txn ) {
72
+		$transaction->set_total($new_total);
73
+		if ($update_txn) {
74 74
 			return $transaction->save() ? true : false;
75 75
 		}
76 76
 		return false;
@@ -93,20 +93,20 @@  discard block
 block discarded – undo
93 93
 	 * @return    boolean        whether the TXN was saved
94 94
 	 * @throws \EE_Error
95 95
 	 */
96
-	public function calculate_total_payments_and_update_status( EE_Transaction $transaction, $update_txn = true ){
96
+	public function calculate_total_payments_and_update_status(EE_Transaction $transaction, $update_txn = true) {
97 97
 		// verify transaction
98
-		if ( ! $transaction instanceof EE_Transaction ) {
99
-			EE_Error::add_error( __( 'Please provide a valid EE_Transaction object.', 'event_espresso' ), __FILE__, __FUNCTION__, __LINE__ );
98
+		if ( ! $transaction instanceof EE_Transaction) {
99
+			EE_Error::add_error(__('Please provide a valid EE_Transaction object.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
100 100
 			return false;
101 101
 		}
102 102
 		// calculate total paid
103
-		$total_paid = $this->recalculate_total_payments_for_transaction( $transaction );
103
+		$total_paid = $this->recalculate_total_payments_for_transaction($transaction);
104 104
 		// if total paid has changed
105
-		if ( $total_paid !== false && (float)$total_paid !== $transaction->paid() ) {
106
-			$transaction->set_paid( $total_paid );
105
+		if ($total_paid !== false && (float) $total_paid !== $transaction->paid()) {
106
+			$transaction->set_paid($total_paid);
107 107
 			// maybe update status, and make sure to save transaction if not done already
108
-			if ( ! $transaction->update_status_based_on_total_paid( $update_txn ) ) {
109
-				if ( $update_txn ) {
108
+			if ( ! $transaction->update_status_based_on_total_paid($update_txn)) {
109
+				if ($update_txn) {
110 110
 					return $transaction->save() ? true : false;
111 111
 				}
112 112
 			} else {
@@ -130,18 +130,18 @@  discard block
 block discarded – undo
130 130
 	 * @return float|false   float on success, false on fail
131 131
 	 * @throws \EE_Error
132 132
 	 */
133
-	public function recalculate_total_payments_for_transaction( EE_Transaction $transaction, $payment_status = EEM_Payment::status_id_approved ) {
133
+	public function recalculate_total_payments_for_transaction(EE_Transaction $transaction, $payment_status = EEM_Payment::status_id_approved) {
134 134
 		// verify transaction
135
-		if ( ! $transaction instanceof EE_Transaction ) {
136
-			EE_Error::add_error( __( 'Please provide a valid EE_Transaction object.', 'event_espresso' ), __FILE__, __FUNCTION__, __LINE__ );
135
+		if ( ! $transaction instanceof EE_Transaction) {
136
+			EE_Error::add_error(__('Please provide a valid EE_Transaction object.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
137 137
 			return false;
138 138
 		}
139 139
 		// ensure Payment model is loaded
140
-		EE_Registry::instance()->load_model( 'Payment' );
140
+		EE_Registry::instance()->load_model('Payment');
141 141
 		// calls EEM_Base::sum()
142 142
 		return EEM_Payment::instance()->sum(
143 143
 			// query params
144
-			array( array( 'TXN_ID' => $transaction->ID(), 'STS_ID' => $payment_status )),
144
+			array(array('TXN_ID' => $transaction->ID(), 'STS_ID' => $payment_status)),
145 145
 			// field to sum
146 146
 			'PAY_amount'
147 147
 		);
@@ -159,17 +159,17 @@  discard block
 block discarded – undo
159 159
 	 * @return boolean
160 160
 	 * @throws \EE_Error
161 161
 	 */
162
-	public function delete_payment_and_update_transaction( EE_Payment $payment ) {
162
+	public function delete_payment_and_update_transaction(EE_Payment $payment) {
163 163
 		// verify payment
164
-		if ( ! $payment instanceof EE_Payment ) {
165
-			EE_Error::add_error( __( 'A valid Payment object was not received.', 'event_espresso' ), __FILE__, __FUNCTION__, __LINE__ );
164
+		if ( ! $payment instanceof EE_Payment) {
165
+			EE_Error::add_error(__('A valid Payment object was not received.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
166 166
 			return false;
167 167
 		}
168
-		if ( ! $this->delete_registration_payments_and_update_registrations( $payment ) ) {
168
+		if ( ! $this->delete_registration_payments_and_update_registrations($payment)) {
169 169
 			return false;
170 170
 		}
171
-		if ( ! $payment->delete() ) {
172
-			EE_Error::add_error( __( 'The payment could not be deleted.', 'event_espresso' ), __FILE__, __FUNCTION__, __LINE__ );
171
+		if ( ! $payment->delete()) {
172
+			EE_Error::add_error(__('The payment could not be deleted.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
173 173
 			return false;
174 174
 		}
175 175
 
@@ -180,14 +180,14 @@  discard block
 block discarded – undo
180 180
 			|| $TXN_status === EEM_Transaction::failed_status_code
181 181
 			|| $payment->amount() === 0
182 182
 		) {
183
-			EE_Error::add_success( __( 'The Payment was successfully deleted.', 'event_espresso' ) );
183
+			EE_Error::add_success(__('The Payment was successfully deleted.', 'event_espresso'));
184 184
 			return true;
185 185
 		}
186 186
 
187 187
 
188 188
 		//if this fails, that just means that the transaction didn't get its status changed and/or updated.
189 189
 		//however the payment was still deleted.
190
-		if ( ! $this->calculate_total_payments_and_update_status( $transaction ) ) {
190
+		if ( ! $this->calculate_total_payments_and_update_status($transaction)) {
191 191
 
192 192
 			EE_Error::add_attention(
193 193
 				__(
@@ -221,17 +221,17 @@  discard block
 block discarded – undo
221 221
 	 * @return bool
222 222
 	 * @throws \EE_Error
223 223
 	 */
224
-	public function delete_registration_payments_and_update_registrations( EE_Payment $payment, $reg_payment_query_params = array() ) {
224
+	public function delete_registration_payments_and_update_registrations(EE_Payment $payment, $reg_payment_query_params = array()) {
225 225
 		$save_payment = false;
226
-		$reg_payment_query_params = ! empty( $reg_payment_query_params ) ? $reg_payment_query_params : array( array( 'PAY_ID' => $payment->ID() ) );
227
-		$registration_payments = EEM_Registration_Payment::instance()->get_all( $reg_payment_query_params );
228
-		if ( ! empty( $registration_payments )) {
229
-			foreach ( $registration_payments as $registration_payment ) {
230
-				if ( $registration_payment instanceof EE_Registration_Payment ) {
226
+		$reg_payment_query_params = ! empty($reg_payment_query_params) ? $reg_payment_query_params : array(array('PAY_ID' => $payment->ID()));
227
+		$registration_payments = EEM_Registration_Payment::instance()->get_all($reg_payment_query_params);
228
+		if ( ! empty($registration_payments)) {
229
+			foreach ($registration_payments as $registration_payment) {
230
+				if ($registration_payment instanceof EE_Registration_Payment) {
231 231
 					$amount_paid = $registration_payment->amount();
232 232
 					$registration = $registration_payment->registration();
233
-					if ( $registration instanceof EE_Registration ) {
234
-						$registration->set_paid( $registration->paid() - $amount_paid );
233
+					if ($registration instanceof EE_Registration) {
234
+						$registration->set_paid($registration->paid() - $amount_paid);
235 235
 						if ($registration->save() !== false) {
236 236
 						    $registration_payment->delete_permanently();
237 237
                             $save_payment = true;
@@ -239,7 +239,7 @@  discard block
 block discarded – undo
239 239
 					} else {
240 240
 						EE_Error::add_error(
241 241
 							sprintf(
242
-								__( 'An invalid Registration object was associated with Registration Payment ID# %1$d.', 'event_espresso' ),
242
+								__('An invalid Registration object was associated with Registration Payment ID# %1$d.', 'event_espresso'),
243 243
 								$registration_payment->ID()
244 244
 							),
245 245
 							__FILE__, __FUNCTION__, __LINE__
@@ -249,7 +249,7 @@  discard block
 block discarded – undo
249 249
 				} else {
250 250
 					EE_Error::add_error(
251 251
 						sprintf(
252
-							__( 'An invalid Registration Payment object was associated with payment ID# %1$d.', 'event_espresso' ),
252
+							__('An invalid Registration Payment object was associated with payment ID# %1$d.', 'event_espresso'),
253 253
 							$payment->ID()
254 254
 						),
255 255
 						__FILE__, __FUNCTION__, __LINE__
@@ -258,7 +258,7 @@  discard block
 block discarded – undo
258 258
 				}
259 259
 			}
260 260
 		}
261
-		if ( $save_payment ) {
261
+		if ($save_payment) {
262 262
 			$payment->save();
263 263
 		}
264 264
 		return true;
@@ -282,7 +282,7 @@  discard block
 block discarded – undo
282 282
 	public function update_transaction_status_based_on_total_paid(EE_Transaction $transaction, $update_txn = true)
283 283
 	{
284 284
 		EE_Error::doing_it_wrong(
285
-			__CLASS__ . '::' . __FUNCTION__,
285
+			__CLASS__.'::'.__FUNCTION__,
286 286
 			sprintf(__('This method is deprecated. Please use "%s" instead', 'event_espresso'),
287 287
 				'EE_Transaction::update_status_based_on_total_paid()'),
288 288
 			'4.9.1',
@@ -324,7 +324,7 @@  discard block
 block discarded – undo
324 324
 	 * @deprecated 4.9.12
325 325
 	 * @param string $old_txn_status
326 326
 	 */
327
-	public function set_old_txn_status( $old_txn_status ) {
327
+	public function set_old_txn_status($old_txn_status) {
328 328
 		EE_Error::doing_it_wrong(
329 329
 			__METHOD__,
330 330
 			esc_html__(
@@ -334,7 +334,7 @@  discard block
 block discarded – undo
334 334
 			'4.9.12'
335 335
 		);
336 336
 		// only set the first time
337
-		if ( $this->_old_txn_status === null ) {
337
+		if ($this->_old_txn_status === null) {
338 338
 			$this->_old_txn_status = $old_txn_status;
339 339
 		}
340 340
 	}
@@ -363,7 +363,7 @@  discard block
 block discarded – undo
363 363
 	 * @deprecated 4.9.12
364 364
 	 * @param string $new_txn_status
365 365
 	 */
366
-	public function set_new_txn_status( $new_txn_status ) {
366
+	public function set_new_txn_status($new_txn_status) {
367 367
 		EE_Error::doing_it_wrong(
368 368
 			__METHOD__,
369 369
 			esc_html__(
Please login to merge, or discard this patch.
core/libraries/form_sections/strategies/filter/VsprintfFilter.php 2 patches
Indentation   +43 added lines, -43 removed lines patch added patch discarded remove patch
@@ -23,49 +23,49 @@
 block discarded – undo
23 23
 class VsprintfFilter extends FormHtmlFilter
24 24
 {
25 25
 
26
-    /**
27
-     * @var string $format
28
-     */
29
-    protected $format = '';
30
-
31
-
32
-    /**
33
-     * @var array $args
34
-     */
35
-    protected $args = array();
36
-
37
-
38
-
39
-    /**
40
-     * SprintfFormHtmlParser constructor.
41
-     *
42
-     * @param string $format
43
-     * @param array  $args
44
-     */
45
-    public function __construct($format, array $args)
46
-    {
47
-        $this->format = $format;
48
-        $this->args = $args;
49
-    }
50
-
51
-
52
-
53
-    /**
54
-     * @param                        $html
55
-     * @param EE_Form_Section_Validatable $form_section
56
-     * @return string
57
-     */
58
-    public function filterHtml($html, EE_Form_Section_Validatable $form_section)
59
-    {
60
-        $this->args[] = $html;
61
-        if ($form_section instanceof EE_Form_Section_Proper) {
62
-            $subsections = $form_section->subsections();
63
-            foreach ((array)$subsections as $subsection) {
64
-                $this->args[] = $subsection->get_html();
65
-            }
66
-        }
67
-        return vsprintf($this->format, $this->args);
68
-    }
26
+	/**
27
+	 * @var string $format
28
+	 */
29
+	protected $format = '';
30
+
31
+
32
+	/**
33
+	 * @var array $args
34
+	 */
35
+	protected $args = array();
36
+
37
+
38
+
39
+	/**
40
+	 * SprintfFormHtmlParser constructor.
41
+	 *
42
+	 * @param string $format
43
+	 * @param array  $args
44
+	 */
45
+	public function __construct($format, array $args)
46
+	{
47
+		$this->format = $format;
48
+		$this->args = $args;
49
+	}
50
+
51
+
52
+
53
+	/**
54
+	 * @param                        $html
55
+	 * @param EE_Form_Section_Validatable $form_section
56
+	 * @return string
57
+	 */
58
+	public function filterHtml($html, EE_Form_Section_Validatable $form_section)
59
+	{
60
+		$this->args[] = $html;
61
+		if ($form_section instanceof EE_Form_Section_Proper) {
62
+			$subsections = $form_section->subsections();
63
+			foreach ((array)$subsections as $subsection) {
64
+				$this->args[] = $subsection->get_html();
65
+			}
66
+		}
67
+		return vsprintf($this->format, $this->args);
68
+	}
69 69
 
70 70
 
71 71
 
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -60,7 +60,7 @@
 block discarded – undo
60 60
         $this->args[] = $html;
61 61
         if ($form_section instanceof EE_Form_Section_Proper) {
62 62
             $subsections = $form_section->subsections();
63
-            foreach ((array)$subsections as $subsection) {
63
+            foreach ((array) $subsections as $subsection) {
64 64
                 $this->args[] = $subsection->get_html();
65 65
             }
66 66
         }
Please login to merge, or discard this patch.
form_sections/strategies/display/EE_Select_Display_Strategy.strategy.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -84,7 +84,7 @@
 block discarded – undo
84 84
 	 * Checks if that value is the one selected
85 85
 	 *
86 86
 	 * @param string|int $option_value unnormalized value option (string). How it will appear in the HTML.
87
-	 * @return string
87
+	 * @return boolean
88 88
 	 */
89 89
 	protected function _check_if_option_selected($option_value ){
90 90
 		return $option_value === $this->_input->raw_value();
Please login to merge, or discard this patch.
Indentation   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -38,15 +38,15 @@  discard block
 block discarded – undo
38 38
 		if ( EEH_Array::is_multi_dimensional_array( $this->_input->options() )) {
39 39
 			EEH_HTML::indent( 1, 'optgroup' );
40 40
 			foreach( $this->_input->options() as $opt_group_label => $opt_group ){
41
-			    if ( ! empty($opt_group_label)) {
42
-                    $html .= EEH_HTML::nl(0, 'optgroup') . '<optgroup label="' . esc_attr($opt_group_label) . '">';
43
-                }
41
+				if ( ! empty($opt_group_label)) {
42
+					$html .= EEH_HTML::nl(0, 'optgroup') . '<optgroup label="' . esc_attr($opt_group_label) . '">';
43
+				}
44 44
 				EEH_HTML::indent( 1, 'option' );
45 45
 				$html .= $this->_display_options( $opt_group );
46 46
 				EEH_HTML::indent( -1, 'option' );
47
-                if ( ! empty($opt_group_label)) {
48
-                    $html .= EEH_HTML::nl( 0, 'optgroup' ) . '</optgroup>';
49
-			    }
47
+				if ( ! empty($opt_group_label)) {
48
+					$html .= EEH_HTML::nl( 0, 'optgroup' ) . '</optgroup>';
49
+				}
50 50
 			}
51 51
 			EEH_HTML::indent( -1, 'optgroup' );
52 52
 		} else {
@@ -68,11 +68,11 @@  discard block
 block discarded – undo
68 68
 		$html = '';
69 69
 		EEH_HTML::indent( 1, 'option' );
70 70
 		foreach( $options as $value => $display_text ){
71
-		    //even if this input uses EE_Text_Normalization if one of the array keys is a numeric string, like "123",
72
-            //PHP will have converted it to a PHP integer (eg 123). So we need to make sure it's a string
73
-            $unnormalized_value = $this->_input->get_normalization_strategy()->unnormalize_one( $value );
74
-            $selected = $this->_check_if_option_selected($unnormalized_value ) ? ' selected="selected"' : '';
75
-            $html.= EEH_HTML::nl( 0, 'option' ) . '<option value="' . esc_attr($unnormalized_value ) . '"' . $selected . '>' . $display_text . '</option>';
71
+			//even if this input uses EE_Text_Normalization if one of the array keys is a numeric string, like "123",
72
+			//PHP will have converted it to a PHP integer (eg 123). So we need to make sure it's a string
73
+			$unnormalized_value = $this->_input->get_normalization_strategy()->unnormalize_one( $value );
74
+			$selected = $this->_check_if_option_selected($unnormalized_value ) ? ' selected="selected"' : '';
75
+			$html.= EEH_HTML::nl( 0, 'option' ) . '<option value="' . esc_attr($unnormalized_value ) . '"' . $selected . '>' . $display_text . '</option>';
76 76
 		}
77 77
 		EEH_HTML::indent( -1, 'option' );
78 78
 		return $html;
Please login to merge, or discard this patch.
Spacing   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -11,49 +11,49 @@  discard block
 block discarded – undo
11 11
  * @since 				$VID:$
12 12
  *
13 13
  */
14
-class EE_Select_Display_Strategy extends EE_Display_Strategy_Base{
14
+class EE_Select_Display_Strategy extends EE_Display_Strategy_Base {
15 15
 
16 16
 	/**
17 17
 	 *
18 18
 	 * @throws EE_Error
19 19
 	 * @return string of html to display the field
20 20
 	 */
21
-	function display(){
22
-		if( ! $this->_input instanceof EE_Form_Input_With_Options_Base){
23
-			throw new EE_Error( sprintf( __( 'Cannot use Select Display Strategy with an input that doesn\'t have options', 'event_espresso' )));
21
+	function display() {
22
+		if ( ! $this->_input instanceof EE_Form_Input_With_Options_Base) {
23
+			throw new EE_Error(sprintf(__('Cannot use Select Display Strategy with an input that doesn\'t have options', 'event_espresso')));
24 24
 		}
25 25
 
26
-		$html = EEH_HTML::nl( 0, 'select' );
26
+		$html = EEH_HTML::nl(0, 'select');
27 27
 		$html .= '<select';
28
-		$html .= ' id="' . $this->_input->html_id() . '"';
29
-		$html .= ' name="' . $this->_input->html_name() . '"';
30
-		$class = $this->_input->required() ? $this->_input->required_css_class() . ' ' . $this->_input->html_class() : $this->_input->html_class();
31
-		$html .= ' class="' . $class . '"';
28
+		$html .= ' id="'.$this->_input->html_id().'"';
29
+		$html .= ' name="'.$this->_input->html_name().'"';
30
+		$class = $this->_input->required() ? $this->_input->required_css_class().' '.$this->_input->html_class() : $this->_input->html_class();
31
+		$html .= ' class="'.$class.'"';
32 32
 		// add html5 required
33 33
 		$html .= $this->_input->required() ? ' required' : '';
34
-		$html .= ' style="' . $this->_input->html_style() . '"';
35
-		$html .= ' ' . $this->_input->other_html_attributes();
34
+		$html .= ' style="'.$this->_input->html_style().'"';
35
+		$html .= ' '.$this->_input->other_html_attributes();
36 36
 		$html .= '>';
37 37
 
38
-		if ( EEH_Array::is_multi_dimensional_array( $this->_input->options() )) {
39
-			EEH_HTML::indent( 1, 'optgroup' );
40
-			foreach( $this->_input->options() as $opt_group_label => $opt_group ){
38
+		if (EEH_Array::is_multi_dimensional_array($this->_input->options())) {
39
+			EEH_HTML::indent(1, 'optgroup');
40
+			foreach ($this->_input->options() as $opt_group_label => $opt_group) {
41 41
 			    if ( ! empty($opt_group_label)) {
42
-                    $html .= EEH_HTML::nl(0, 'optgroup') . '<optgroup label="' . esc_attr($opt_group_label) . '">';
42
+                    $html .= EEH_HTML::nl(0, 'optgroup').'<optgroup label="'.esc_attr($opt_group_label).'">';
43 43
                 }
44
-				EEH_HTML::indent( 1, 'option' );
45
-				$html .= $this->_display_options( $opt_group );
44
+				EEH_HTML::indent(1, 'option');
45
+				$html .= $this->_display_options($opt_group);
46 46
 				EEH_HTML::indent( -1, 'option' );
47 47
                 if ( ! empty($opt_group_label)) {
48
-                    $html .= EEH_HTML::nl( 0, 'optgroup' ) . '</optgroup>';
48
+                    $html .= EEH_HTML::nl(0, 'optgroup').'</optgroup>';
49 49
 			    }
50 50
 			}
51 51
 			EEH_HTML::indent( -1, 'optgroup' );
52 52
 		} else {
53
-			$html.=$this->_display_options( $this->_input->options() );
53
+			$html .= $this->_display_options($this->_input->options());
54 54
 		}
55 55
 
56
-		$html.= EEH_HTML::nl( 0, 'select' ) . '</select>';
56
+		$html .= EEH_HTML::nl(0, 'select').'</select>';
57 57
 		return $html;
58 58
 	}
59 59
 
@@ -64,15 +64,15 @@  discard block
 block discarded – undo
64 64
 	 * @param array $options
65 65
 	 * @return string
66 66
 	 */
67
-	protected function _display_options($options){
67
+	protected function _display_options($options) {
68 68
 		$html = '';
69
-		EEH_HTML::indent( 1, 'option' );
70
-		foreach( $options as $value => $display_text ){
69
+		EEH_HTML::indent(1, 'option');
70
+		foreach ($options as $value => $display_text) {
71 71
 		    //even if this input uses EE_Text_Normalization if one of the array keys is a numeric string, like "123",
72 72
             //PHP will have converted it to a PHP integer (eg 123). So we need to make sure it's a string
73
-            $unnormalized_value = $this->_input->get_normalization_strategy()->unnormalize_one( $value );
74
-            $selected = $this->_check_if_option_selected($unnormalized_value ) ? ' selected="selected"' : '';
75
-            $html.= EEH_HTML::nl( 0, 'option' ) . '<option value="' . esc_attr($unnormalized_value ) . '"' . $selected . '>' . $display_text . '</option>';
73
+            $unnormalized_value = $this->_input->get_normalization_strategy()->unnormalize_one($value);
74
+            $selected = $this->_check_if_option_selected($unnormalized_value) ? ' selected="selected"' : '';
75
+            $html .= EEH_HTML::nl(0, 'option').'<option value="'.esc_attr($unnormalized_value).'"'.$selected.'>'.$display_text.'</option>';
76 76
 		}
77 77
 		EEH_HTML::indent( -1, 'option' );
78 78
 		return $html;
@@ -86,7 +86,7 @@  discard block
 block discarded – undo
86 86
 	 * @param string|int $option_value unnormalized value option (string). How it will appear in the HTML.
87 87
 	 * @return string
88 88
 	 */
89
-	protected function _check_if_option_selected($option_value ){
89
+	protected function _check_if_option_selected($option_value) {
90 90
 		return $option_value === $this->_input->raw_value();
91 91
 	}
92 92
 
Please login to merge, or discard this patch.
libraries/form_sections/inputs/EE_Form_Input_With_Options_Base.input.php 2 patches
Indentation   +315 added lines, -315 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php if ( ! defined('EVENT_ESPRESSO_VERSION')) {
2
-    exit('No direct script access allowed');
2
+	exit('No direct script access allowed');
3 3
 }
4 4
 
5 5
 
@@ -16,320 +16,320 @@  discard block
 block discarded – undo
16 16
 class EE_Form_Input_With_Options_Base extends EE_Form_Input_Base
17 17
 {
18 18
 
19
-    /**
20
-     * array of available options to choose as an answer
21
-     *
22
-     * @var array
23
-     */
24
-    protected $_options = array();
25
-
26
-    /**
27
-     * whether to display the html_label_text above the checkbox/radio button options
28
-     *
29
-     * @var boolean
30
-     */
31
-    protected $_display_html_label_text = true;
32
-
33
-    /**
34
-     * whether to display an question option description as part of the input label
35
-     *
36
-     * @var boolean
37
-     */
38
-    protected $_use_desc_in_label = true;
39
-
40
-    /**
41
-     * strlen() result for the longest input value (what gets displayed in the label)
42
-     * this is used to apply a css class to the input label
43
-     *
44
-     * @var int
45
-     */
46
-    protected $_label_size = 0;
47
-
48
-    /**
49
-     * whether to enforce the label size value passed in the constructor
50
-     *
51
-     * @var boolean
52
-     */
53
-    protected $_enforce_label_size = false;
54
-
55
-    /**
56
-     * whether to allow multiple selections (ie, the value of this input should be an array)
57
-     * or not (ie, the value should be a simple int, string, etc)
58
-     *
59
-     * @var boolean
60
-     */
61
-    protected $_multiple_selections = false;
62
-
63
-
64
-
65
-    /**
66
-     * @param array     $answer_options
67
-     * @param array     $input_settings {
68
-     * @type int|string $label_size
69
-     * @type boolean    $display_html_label_text
70
-     *                                  }
71
-     *                                  And all the options accepted by EE_Form_Input_Base
72
-     */
73
-    public function __construct($answer_options = array(), $input_settings = array())
74
-    {
75
-        if (isset($input_settings['label_size'])) {
76
-            $this->_set_label_size($input_settings['label_size']);
77
-            if (isset($input_settings['enforce_label_size']) && $input_settings['enforce_label_size']) {
78
-                $this->_enforce_label_size = true;
79
-            }
80
-        }
81
-        if (isset($input_settings['display_html_label_text'])) {
82
-            $this->set_display_html_label_text($input_settings['display_html_label_text']);
83
-        }
84
-        $this->set_select_options($answer_options);
85
-        parent::__construct($input_settings);
86
-    }
87
-
88
-
89
-
90
-    /**
91
-     * Sets the allowed options for this input. Also has the side-effect of
92
-     * updating the normalization strategy to match the keys provided in the array
93
-     *
94
-     * @param array $answer_options
95
-     * @return void  just has the side-effect of setting the options for this input
96
-     */
97
-    public function set_select_options($answer_options = array())
98
-    {
99
-        $answer_options = is_array($answer_options) ? $answer_options : array($answer_options);
100
-        //get the first item in the select options and check it's type
101
-        $this->_options = reset($answer_options) instanceof EE_Question_Option
102
-            ? $this->_process_question_options($answer_options)
103
-            : $answer_options;
104
-        //d( $this->_options );
105
-        $select_option_keys = array_keys($this->_options);
106
-        // attempt to determine data type for values in order to set normalization type
107
-        //purposefully only
108
-        if (
109
-            count($this->_options) === 2
110
-            && (
111
-                (in_array(true, $select_option_keys, true) && in_array(false, $select_option_keys, true))
112
-                || (in_array(1, $select_option_keys, true) && in_array(0, $select_option_keys, true))
113
-            )
114
-        ) {
115
-            // values appear to be boolean, like TRUE, FALSE, 1, 0
116
-            $normalization = new EE_Boolean_Normalization();
117
-        } else {
118
-            //are ALL the options ints (even if we're using a multi-dimensional array)? If so use int validation
119
-            $all_ints = true;
120
-            array_walk_recursive(
121
-                $this->_options,
122
-                function($value,$key) use (&$all_ints){
123
-                    //is this a top-level key? ignore it
124
-                    if(! is_array($value)
125
-                        && ! is_int($key)
126
-                       && $key !== ''
127
-                       && $key !== null){
128
-                        $all_ints = false;
129
-                    }
130
-                }
131
-            );
132
-            if ($all_ints) {
133
-                $normalization = new EE_Int_Normalization();
134
-            } else {
135
-                $normalization = new EE_Text_Normalization();
136
-            }
137
-        }
138
-        // does input type have multiple options ?
139
-        if ($this->_multiple_selections) {
140
-            $this->_set_normalization_strategy(new EE_Many_Valued_Normalization($normalization));
141
-        } else {
142
-            $this->_set_normalization_strategy($normalization);
143
-        }
144
-    }
145
-
146
-
147
-
148
-    /**
149
-     * @return array
150
-     */
151
-    public function options()
152
-    {
153
-        return $this->_options;
154
-    }
155
-
156
-
157
-
158
-    /**
159
-     * Returns an array which is guaranteed to not be multidimensional
160
-     *
161
-     * @return array
162
-     */
163
-    public function flat_options()
164
-    {
165
-        return $this->_flatten_select_options($this->options());
166
-    }
167
-
168
-
169
-
170
-    /**
171
-     * Makes sure $arr is a flat array, not a multidimensional one
172
-     *
173
-     * @param array $arr
174
-     * @return array
175
-     */
176
-    protected function _flatten_select_options($arr)
177
-    {
178
-        $flat_array = array();
179
-        if (EEH_Array::is_multi_dimensional_array($arr)) {
180
-            foreach ($arr as $sub_array) {
181
-                foreach ((array)$sub_array as $key => $value) {
182
-                    $flat_array[$key] = $value;
183
-                    $this->_set_label_size($value);
184
-                }
185
-            }
186
-        } else {
187
-            foreach ($arr as $key => $value) {
188
-                $flat_array[$key] = $value;
189
-                $this->_set_label_size($value);
190
-            }
191
-        }
192
-        return $flat_array;
193
-    }
194
-
195
-
196
-
197
-    /**
198
-     * @param EE_Question_Option[] $question_options_array
199
-     * @return array
200
-     */
201
-    protected function _process_question_options($question_options_array = array())
202
-    {
203
-        $flat_array = array();
204
-        foreach ($question_options_array as $question_option) {
205
-            if ($question_option instanceof EE_Question_Option) {
206
-                $desc = '';
207
-                if ($this->_use_desc_in_label) {
208
-                    $desc = $question_option->desc();
209
-                    $desc = ! empty($desc) ? '<span class="ee-question-option-desc">' . $desc . '</span>' : '';
210
-                }
211
-                $value = $question_option->value();
212
-                // add value even if it's empty
213
-                $flat_array[$value] = $value;
214
-                // if both value and desc are not empty, then separate with a dash
215
-                if ( ! empty($value) && ! empty($desc)) {
216
-                    $flat_array[$value] .= ' - ' . $desc;
217
-                } else {
218
-                    // otherwise, just add desc, since either or both of the vars is empty, and no dash is necessary
219
-                    $flat_array[$value] .= $desc;
220
-                }
221
-            } elseif (is_array($question_option)) {
222
-                $flat_array += $this->_flatten_select_options($question_option);
223
-            }
224
-        }
225
-        return $flat_array;
226
-    }
227
-
228
-
229
-
230
-    /**
231
-     *    set_label_sizes
232
-     *
233
-     * @return void
234
-     */
235
-    public function set_label_sizes()
236
-    {
237
-        // did the input settings specifically say to NOT set the label size dynamically ?
238
-        if ( ! $this->_enforce_label_size) {
239
-            foreach ($this->_options as $option) {
240
-                // calculate the strlen of the label
241
-                $this->_set_label_size($option);
242
-            }
243
-        }
244
-    }
245
-
246
-
247
-
248
-    /**
249
-     *    _set_label_size_class
250
-     *
251
-     * @param int|string $value
252
-     * @return void
253
-     */
254
-    private function _set_label_size($value = '')
255
-    {
256
-        // determine length of option value
257
-        $val_size = is_int($value) ? $value : strlen($value);
258
-        // use new value if bigger than existing
259
-        $this->_label_size = $val_size > $this->_label_size ? $val_size : $this->_label_size;
260
-    }
261
-
262
-
263
-
264
-    /**
265
-     *    get_label_size_class
266
-     *
267
-     * @return string
268
-     */
269
-    public function get_label_size_class()
270
-    {
271
-        $size = ' medium-lbl';
272
-        // use maximum option value length to determine label size
273
-        if ($this->_label_size < 3) {
274
-            $size = ' nano-lbl';
275
-        } else if ($this->_label_size < 6) {
276
-            $size = ' micro-lbl';
277
-        } else if ($this->_label_size < 12) {
278
-            $size = ' tiny-lbl';
279
-        } else if ($this->_label_size < 25) {
280
-            $size = ' small-lbl';
281
-        } else if ($this->_label_size < 50) {
282
-            $size = ' medium-lbl';
283
-        } else if ($this->_label_size >= 100) {
284
-            $size = ' big-lbl';
285
-        }
286
-        return $size;
287
-    }
288
-
289
-
290
-
291
-    /**
292
-     * Returns the pretty value for the normalized value
293
-     *
294
-     * @return string
295
-     */
296
-    public function pretty_value()
297
-    {
298
-        $options = $this->flat_options();
299
-        $unnormalized_value_choices = $this->get_normalization_strategy()->unnormalize($this->_normalized_value);
300
-        if ( ! $this->_multiple_selections) {
301
-            $unnormalized_value_choices = array($unnormalized_value_choices);
302
-        }
303
-        $pretty_strings = array();
304
-        foreach ((array)$unnormalized_value_choices as $unnormalized_value_choice) {
305
-            if (isset($options[$unnormalized_value_choice])) {
306
-                $pretty_strings[] = $options[$unnormalized_value_choice];
307
-            } else {
308
-                $pretty_strings[] = $this->normalized_value();
309
-            }
310
-        }
311
-        return implode(', ', $pretty_strings);
312
-    }
313
-
314
-
315
-
316
-    /**
317
-     * @return boolean
318
-     */
319
-    public function display_html_label_text()
320
-    {
321
-        return $this->_display_html_label_text;
322
-    }
323
-
324
-
325
-
326
-    /**
327
-     * @param boolean $display_html_label_text
328
-     */
329
-    public function set_display_html_label_text($display_html_label_text)
330
-    {
331
-        $this->_display_html_label_text = filter_var($display_html_label_text, FILTER_VALIDATE_BOOLEAN);
332
-    }
19
+	/**
20
+	 * array of available options to choose as an answer
21
+	 *
22
+	 * @var array
23
+	 */
24
+	protected $_options = array();
25
+
26
+	/**
27
+	 * whether to display the html_label_text above the checkbox/radio button options
28
+	 *
29
+	 * @var boolean
30
+	 */
31
+	protected $_display_html_label_text = true;
32
+
33
+	/**
34
+	 * whether to display an question option description as part of the input label
35
+	 *
36
+	 * @var boolean
37
+	 */
38
+	protected $_use_desc_in_label = true;
39
+
40
+	/**
41
+	 * strlen() result for the longest input value (what gets displayed in the label)
42
+	 * this is used to apply a css class to the input label
43
+	 *
44
+	 * @var int
45
+	 */
46
+	protected $_label_size = 0;
47
+
48
+	/**
49
+	 * whether to enforce the label size value passed in the constructor
50
+	 *
51
+	 * @var boolean
52
+	 */
53
+	protected $_enforce_label_size = false;
54
+
55
+	/**
56
+	 * whether to allow multiple selections (ie, the value of this input should be an array)
57
+	 * or not (ie, the value should be a simple int, string, etc)
58
+	 *
59
+	 * @var boolean
60
+	 */
61
+	protected $_multiple_selections = false;
62
+
63
+
64
+
65
+	/**
66
+	 * @param array     $answer_options
67
+	 * @param array     $input_settings {
68
+	 * @type int|string $label_size
69
+	 * @type boolean    $display_html_label_text
70
+	 *                                  }
71
+	 *                                  And all the options accepted by EE_Form_Input_Base
72
+	 */
73
+	public function __construct($answer_options = array(), $input_settings = array())
74
+	{
75
+		if (isset($input_settings['label_size'])) {
76
+			$this->_set_label_size($input_settings['label_size']);
77
+			if (isset($input_settings['enforce_label_size']) && $input_settings['enforce_label_size']) {
78
+				$this->_enforce_label_size = true;
79
+			}
80
+		}
81
+		if (isset($input_settings['display_html_label_text'])) {
82
+			$this->set_display_html_label_text($input_settings['display_html_label_text']);
83
+		}
84
+		$this->set_select_options($answer_options);
85
+		parent::__construct($input_settings);
86
+	}
87
+
88
+
89
+
90
+	/**
91
+	 * Sets the allowed options for this input. Also has the side-effect of
92
+	 * updating the normalization strategy to match the keys provided in the array
93
+	 *
94
+	 * @param array $answer_options
95
+	 * @return void  just has the side-effect of setting the options for this input
96
+	 */
97
+	public function set_select_options($answer_options = array())
98
+	{
99
+		$answer_options = is_array($answer_options) ? $answer_options : array($answer_options);
100
+		//get the first item in the select options and check it's type
101
+		$this->_options = reset($answer_options) instanceof EE_Question_Option
102
+			? $this->_process_question_options($answer_options)
103
+			: $answer_options;
104
+		//d( $this->_options );
105
+		$select_option_keys = array_keys($this->_options);
106
+		// attempt to determine data type for values in order to set normalization type
107
+		//purposefully only
108
+		if (
109
+			count($this->_options) === 2
110
+			&& (
111
+				(in_array(true, $select_option_keys, true) && in_array(false, $select_option_keys, true))
112
+				|| (in_array(1, $select_option_keys, true) && in_array(0, $select_option_keys, true))
113
+			)
114
+		) {
115
+			// values appear to be boolean, like TRUE, FALSE, 1, 0
116
+			$normalization = new EE_Boolean_Normalization();
117
+		} else {
118
+			//are ALL the options ints (even if we're using a multi-dimensional array)? If so use int validation
119
+			$all_ints = true;
120
+			array_walk_recursive(
121
+				$this->_options,
122
+				function($value,$key) use (&$all_ints){
123
+					//is this a top-level key? ignore it
124
+					if(! is_array($value)
125
+						&& ! is_int($key)
126
+					   && $key !== ''
127
+					   && $key !== null){
128
+						$all_ints = false;
129
+					}
130
+				}
131
+			);
132
+			if ($all_ints) {
133
+				$normalization = new EE_Int_Normalization();
134
+			} else {
135
+				$normalization = new EE_Text_Normalization();
136
+			}
137
+		}
138
+		// does input type have multiple options ?
139
+		if ($this->_multiple_selections) {
140
+			$this->_set_normalization_strategy(new EE_Many_Valued_Normalization($normalization));
141
+		} else {
142
+			$this->_set_normalization_strategy($normalization);
143
+		}
144
+	}
145
+
146
+
147
+
148
+	/**
149
+	 * @return array
150
+	 */
151
+	public function options()
152
+	{
153
+		return $this->_options;
154
+	}
155
+
156
+
157
+
158
+	/**
159
+	 * Returns an array which is guaranteed to not be multidimensional
160
+	 *
161
+	 * @return array
162
+	 */
163
+	public function flat_options()
164
+	{
165
+		return $this->_flatten_select_options($this->options());
166
+	}
167
+
168
+
169
+
170
+	/**
171
+	 * Makes sure $arr is a flat array, not a multidimensional one
172
+	 *
173
+	 * @param array $arr
174
+	 * @return array
175
+	 */
176
+	protected function _flatten_select_options($arr)
177
+	{
178
+		$flat_array = array();
179
+		if (EEH_Array::is_multi_dimensional_array($arr)) {
180
+			foreach ($arr as $sub_array) {
181
+				foreach ((array)$sub_array as $key => $value) {
182
+					$flat_array[$key] = $value;
183
+					$this->_set_label_size($value);
184
+				}
185
+			}
186
+		} else {
187
+			foreach ($arr as $key => $value) {
188
+				$flat_array[$key] = $value;
189
+				$this->_set_label_size($value);
190
+			}
191
+		}
192
+		return $flat_array;
193
+	}
194
+
195
+
196
+
197
+	/**
198
+	 * @param EE_Question_Option[] $question_options_array
199
+	 * @return array
200
+	 */
201
+	protected function _process_question_options($question_options_array = array())
202
+	{
203
+		$flat_array = array();
204
+		foreach ($question_options_array as $question_option) {
205
+			if ($question_option instanceof EE_Question_Option) {
206
+				$desc = '';
207
+				if ($this->_use_desc_in_label) {
208
+					$desc = $question_option->desc();
209
+					$desc = ! empty($desc) ? '<span class="ee-question-option-desc">' . $desc . '</span>' : '';
210
+				}
211
+				$value = $question_option->value();
212
+				// add value even if it's empty
213
+				$flat_array[$value] = $value;
214
+				// if both value and desc are not empty, then separate with a dash
215
+				if ( ! empty($value) && ! empty($desc)) {
216
+					$flat_array[$value] .= ' - ' . $desc;
217
+				} else {
218
+					// otherwise, just add desc, since either or both of the vars is empty, and no dash is necessary
219
+					$flat_array[$value] .= $desc;
220
+				}
221
+			} elseif (is_array($question_option)) {
222
+				$flat_array += $this->_flatten_select_options($question_option);
223
+			}
224
+		}
225
+		return $flat_array;
226
+	}
227
+
228
+
229
+
230
+	/**
231
+	 *    set_label_sizes
232
+	 *
233
+	 * @return void
234
+	 */
235
+	public function set_label_sizes()
236
+	{
237
+		// did the input settings specifically say to NOT set the label size dynamically ?
238
+		if ( ! $this->_enforce_label_size) {
239
+			foreach ($this->_options as $option) {
240
+				// calculate the strlen of the label
241
+				$this->_set_label_size($option);
242
+			}
243
+		}
244
+	}
245
+
246
+
247
+
248
+	/**
249
+	 *    _set_label_size_class
250
+	 *
251
+	 * @param int|string $value
252
+	 * @return void
253
+	 */
254
+	private function _set_label_size($value = '')
255
+	{
256
+		// determine length of option value
257
+		$val_size = is_int($value) ? $value : strlen($value);
258
+		// use new value if bigger than existing
259
+		$this->_label_size = $val_size > $this->_label_size ? $val_size : $this->_label_size;
260
+	}
261
+
262
+
263
+
264
+	/**
265
+	 *    get_label_size_class
266
+	 *
267
+	 * @return string
268
+	 */
269
+	public function get_label_size_class()
270
+	{
271
+		$size = ' medium-lbl';
272
+		// use maximum option value length to determine label size
273
+		if ($this->_label_size < 3) {
274
+			$size = ' nano-lbl';
275
+		} else if ($this->_label_size < 6) {
276
+			$size = ' micro-lbl';
277
+		} else if ($this->_label_size < 12) {
278
+			$size = ' tiny-lbl';
279
+		} else if ($this->_label_size < 25) {
280
+			$size = ' small-lbl';
281
+		} else if ($this->_label_size < 50) {
282
+			$size = ' medium-lbl';
283
+		} else if ($this->_label_size >= 100) {
284
+			$size = ' big-lbl';
285
+		}
286
+		return $size;
287
+	}
288
+
289
+
290
+
291
+	/**
292
+	 * Returns the pretty value for the normalized value
293
+	 *
294
+	 * @return string
295
+	 */
296
+	public function pretty_value()
297
+	{
298
+		$options = $this->flat_options();
299
+		$unnormalized_value_choices = $this->get_normalization_strategy()->unnormalize($this->_normalized_value);
300
+		if ( ! $this->_multiple_selections) {
301
+			$unnormalized_value_choices = array($unnormalized_value_choices);
302
+		}
303
+		$pretty_strings = array();
304
+		foreach ((array)$unnormalized_value_choices as $unnormalized_value_choice) {
305
+			if (isset($options[$unnormalized_value_choice])) {
306
+				$pretty_strings[] = $options[$unnormalized_value_choice];
307
+			} else {
308
+				$pretty_strings[] = $this->normalized_value();
309
+			}
310
+		}
311
+		return implode(', ', $pretty_strings);
312
+	}
313
+
314
+
315
+
316
+	/**
317
+	 * @return boolean
318
+	 */
319
+	public function display_html_label_text()
320
+	{
321
+		return $this->_display_html_label_text;
322
+	}
323
+
324
+
325
+
326
+	/**
327
+	 * @param boolean $display_html_label_text
328
+	 */
329
+	public function set_display_html_label_text($display_html_label_text)
330
+	{
331
+		$this->_display_html_label_text = filter_var($display_html_label_text, FILTER_VALIDATE_BOOLEAN);
332
+	}
333 333
 
334 334
 
335 335
 
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -119,12 +119,12 @@  discard block
 block discarded – undo
119 119
             $all_ints = true;
120 120
             array_walk_recursive(
121 121
                 $this->_options,
122
-                function($value,$key) use (&$all_ints){
122
+                function($value, $key) use (&$all_ints){
123 123
                     //is this a top-level key? ignore it
124
-                    if(! is_array($value)
124
+                    if ( ! is_array($value)
125 125
                         && ! is_int($key)
126 126
                        && $key !== ''
127
-                       && $key !== null){
127
+                       && $key !== null) {
128 128
                         $all_ints = false;
129 129
                     }
130 130
                 }
@@ -178,7 +178,7 @@  discard block
 block discarded – undo
178 178
         $flat_array = array();
179 179
         if (EEH_Array::is_multi_dimensional_array($arr)) {
180 180
             foreach ($arr as $sub_array) {
181
-                foreach ((array)$sub_array as $key => $value) {
181
+                foreach ((array) $sub_array as $key => $value) {
182 182
                     $flat_array[$key] = $value;
183 183
                     $this->_set_label_size($value);
184 184
                 }
@@ -206,14 +206,14 @@  discard block
 block discarded – undo
206 206
                 $desc = '';
207 207
                 if ($this->_use_desc_in_label) {
208 208
                     $desc = $question_option->desc();
209
-                    $desc = ! empty($desc) ? '<span class="ee-question-option-desc">' . $desc . '</span>' : '';
209
+                    $desc = ! empty($desc) ? '<span class="ee-question-option-desc">'.$desc.'</span>' : '';
210 210
                 }
211 211
                 $value = $question_option->value();
212 212
                 // add value even if it's empty
213 213
                 $flat_array[$value] = $value;
214 214
                 // if both value and desc are not empty, then separate with a dash
215 215
                 if ( ! empty($value) && ! empty($desc)) {
216
-                    $flat_array[$value] .= ' - ' . $desc;
216
+                    $flat_array[$value] .= ' - '.$desc;
217 217
                 } else {
218 218
                     // otherwise, just add desc, since either or both of the vars is empty, and no dash is necessary
219 219
                     $flat_array[$value] .= $desc;
@@ -301,7 +301,7 @@  discard block
 block discarded – undo
301 301
             $unnormalized_value_choices = array($unnormalized_value_choices);
302 302
         }
303 303
         $pretty_strings = array();
304
-        foreach ((array)$unnormalized_value_choices as $unnormalized_value_choice) {
304
+        foreach ((array) $unnormalized_value_choices as $unnormalized_value_choice) {
305 305
             if (isset($options[$unnormalized_value_choice])) {
306 306
                 $pretty_strings[] = $options[$unnormalized_value_choice];
307 307
             } else {
Please login to merge, or discard this patch.
form_sections/strategies/normalization/EE_Text_Normalization.strategy.php 2 patches
Indentation   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -15,26 +15,26 @@
 block discarded – undo
15 15
 	 */
16 16
 	public function normalize($value_to_normalize) {
17 17
 		if(is_array($value_to_normalize)) {
18
-            return (string)array_shift($value_to_normalize);
19
-        }
20
-        // consider `"null"` values to be equivalent to null.
21
-        if($value_to_normalize === '' || $value_to_normalize === null) {
22
-		    return null;
18
+			return (string)array_shift($value_to_normalize);
23 19
 		}
24
-        return (string)$value_to_normalize;
25
-    }
20
+		// consider `"null"` values to be equivalent to null.
21
+		if($value_to_normalize === '' || $value_to_normalize === null) {
22
+			return null;
23
+		}
24
+		return (string)$value_to_normalize;
25
+	}
26 26
 	/**
27 27
 	 * IF its a string in PHP, it will be a string in the HTML form. easy
28 28
 	 * @param string $normalized_value
29 29
 	 * @return string
30 30
 	 */
31 31
 	public function unnormalize( $normalized_value ){
32
-	    //account for default "select here" option values
33
-	    if ($normalized_value === null) {
34
-	        return '';
35
-        }
36
-        //double-check it's a string. It's possible this value was a question option that happened to be a numeric
37
-        //string, in which case PHP has automatically converted it to an integer!
32
+		//account for default "select here" option values
33
+		if ($normalized_value === null) {
34
+			return '';
35
+		}
36
+		//double-check it's a string. It's possible this value was a question option that happened to be a numeric
37
+		//string, in which case PHP has automatically converted it to an integer!
38 38
 		return (string)$normalized_value;
39 39
 	}
40 40
 }
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -7,35 +7,35 @@
 block discarded – undo
7 7
  * @subpackage
8 8
  * @author				Mike Nelson
9 9
  */
10
-class EE_Text_Normalization extends EE_Normalization_Strategy_Base{
10
+class EE_Text_Normalization extends EE_Normalization_Strategy_Base {
11 11
 
12 12
 	/**
13 13
 	 * @param string $value_to_normalize
14 14
 	 * @return array|mixed|string
15 15
 	 */
16 16
 	public function normalize($value_to_normalize) {
17
-		if(is_array($value_to_normalize)) {
18
-            return (string)array_shift($value_to_normalize);
17
+		if (is_array($value_to_normalize)) {
18
+            return (string) array_shift($value_to_normalize);
19 19
         }
20 20
         // consider `"null"` values to be equivalent to null.
21
-        if($value_to_normalize === '' || $value_to_normalize === null) {
21
+        if ($value_to_normalize === '' || $value_to_normalize === null) {
22 22
 		    return null;
23 23
 		}
24
-        return (string)$value_to_normalize;
24
+        return (string) $value_to_normalize;
25 25
     }
26 26
 	/**
27 27
 	 * IF its a string in PHP, it will be a string in the HTML form. easy
28 28
 	 * @param string $normalized_value
29 29
 	 * @return string
30 30
 	 */
31
-	public function unnormalize( $normalized_value ){
31
+	public function unnormalize($normalized_value) {
32 32
 	    //account for default "select here" option values
33 33
 	    if ($normalized_value === null) {
34 34
 	        return '';
35 35
         }
36 36
         //double-check it's a string. It's possible this value was a question option that happened to be a numeric
37 37
         //string, in which case PHP has automatically converted it to an integer!
38
-		return (string)$normalized_value;
38
+		return (string) $normalized_value;
39 39
 	}
40 40
 }
41 41
 
Please login to merge, or discard this patch.
admin_pages/support/Support_Admin_Page.core.php 2 patches
Indentation   +234 added lines, -234 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 if (! defined('EVENT_ESPRESSO_VERSION')) {
3
-    exit('NO direct script access allowed');
3
+	exit('NO direct script access allowed');
4 4
 }
5 5
 
6 6
 
@@ -19,263 +19,263 @@  discard block
 block discarded – undo
19 19
 
20 20
 
21 21
 
22
-    protected function _init_page_props()
23
-    {
24
-        $this->page_slug = EE_SUPPORT_PG_SLUG;
25
-        $this->page_label = esc_html__('Help & Support', 'event_espresso');
26
-        $this->_admin_base_url = EE_SUPPORT_ADMIN_URL;
27
-        $this->_admin_base_path = EE_SUPPORT_ADMIN;
28
-    }
22
+	protected function _init_page_props()
23
+	{
24
+		$this->page_slug = EE_SUPPORT_PG_SLUG;
25
+		$this->page_label = esc_html__('Help & Support', 'event_espresso');
26
+		$this->_admin_base_url = EE_SUPPORT_ADMIN_URL;
27
+		$this->_admin_base_path = EE_SUPPORT_ADMIN;
28
+	}
29 29
 
30 30
 
31 31
 
32
-    protected function _ajax_hooks()
33
-    {
34
-    }
32
+	protected function _ajax_hooks()
33
+	{
34
+	}
35 35
 
36 36
 
37 37
 
38
-    protected function _define_page_props()
39
-    {
40
-        $this->_labels = array();
41
-        $this->_admin_page_title = $this->page_label;
42
-    }
38
+	protected function _define_page_props()
39
+	{
40
+		$this->_labels = array();
41
+		$this->_admin_page_title = $this->page_label;
42
+	}
43 43
 
44 44
 
45 45
 
46
-    protected function _set_page_routes()
47
-    {
48
-        $this->_page_routes = array(
49
-            'default'    => array(
50
-                'func'       => '_contact_support',
51
-                'capability' => 'ee_read_ee',
52
-            ),
53
-            'developers' => array(
54
-                'func'       => '_developers',
55
-                'capability' => 'ee_read_ee',
56
-            ),
57
-            'shortcodes' => array(
58
-                'func'       => '_shortcodes',
59
-                'capability' => 'ee_read_ee',
60
-            ),
61
-        );
62
-    }
46
+	protected function _set_page_routes()
47
+	{
48
+		$this->_page_routes = array(
49
+			'default'    => array(
50
+				'func'       => '_contact_support',
51
+				'capability' => 'ee_read_ee',
52
+			),
53
+			'developers' => array(
54
+				'func'       => '_developers',
55
+				'capability' => 'ee_read_ee',
56
+			),
57
+			'shortcodes' => array(
58
+				'func'       => '_shortcodes',
59
+				'capability' => 'ee_read_ee',
60
+			),
61
+		);
62
+	}
63 63
 
64 64
 
65 65
 
66
-    protected function _set_page_config()
67
-    {
68
-        $this->_page_config = array(
69
-            'default'    => array(
70
-                'nav'           => array(
71
-                    'label' => esc_html__('Support', 'event_espresso'),
72
-                    'order' => 30,
73
-                ),
74
-                'metaboxes'     => array_merge($this->_default_espresso_metaboxes, array('_support_boxes')),
75
-                'require_nonce' => false,
76
-            ),
77
-            'developers' => array(
78
-                'nav'           => array(
79
-                    'label' => esc_html__('Developers', 'event_espresso'),
80
-                    'order' => 50,
81
-                ),
82
-                'metaboxes'     => $this->_default_espresso_metaboxes,
83
-                'require_nonce' => false,
84
-            ),
85
-            'shortcodes' => array(
86
-                'nav'           => array(
87
-                    'label' => esc_html__('Shortcodes', 'event_espresso'),
88
-                    'order' => 60,
89
-                ),
90
-                'metaboxes'     => array_merge($this->_default_espresso_metaboxes, array('_shortcodes_boxes')),
91
-                'require_nonce' => false,
92
-            ),
93
-        );
94
-    }
66
+	protected function _set_page_config()
67
+	{
68
+		$this->_page_config = array(
69
+			'default'    => array(
70
+				'nav'           => array(
71
+					'label' => esc_html__('Support', 'event_espresso'),
72
+					'order' => 30,
73
+				),
74
+				'metaboxes'     => array_merge($this->_default_espresso_metaboxes, array('_support_boxes')),
75
+				'require_nonce' => false,
76
+			),
77
+			'developers' => array(
78
+				'nav'           => array(
79
+					'label' => esc_html__('Developers', 'event_espresso'),
80
+					'order' => 50,
81
+				),
82
+				'metaboxes'     => $this->_default_espresso_metaboxes,
83
+				'require_nonce' => false,
84
+			),
85
+			'shortcodes' => array(
86
+				'nav'           => array(
87
+					'label' => esc_html__('Shortcodes', 'event_espresso'),
88
+					'order' => 60,
89
+				),
90
+				'metaboxes'     => array_merge($this->_default_espresso_metaboxes, array('_shortcodes_boxes')),
91
+				'require_nonce' => false,
92
+			),
93
+		);
94
+	}
95 95
 
96 96
 
97 97
 
98
-    //none of the below group are currently used for Support pages
99
-    protected function _add_screen_options()
100
-    {
101
-    }
102
-
98
+	//none of the below group are currently used for Support pages
99
+	protected function _add_screen_options()
100
+	{
101
+	}
102
+
103 103
 
104 104
 
105
-    protected function _add_feature_pointers()
106
-    {
107
-    }
105
+	protected function _add_feature_pointers()
106
+	{
107
+	}
108 108
 
109 109
 
110 110
 
111
-    public function admin_init()
112
-    {
113
-    }
111
+	public function admin_init()
112
+	{
113
+	}
114 114
 
115 115
 
116 116
 
117
-    public function admin_notices()
118
-    {
119
-    }
117
+	public function admin_notices()
118
+	{
119
+	}
120 120
 
121
-
122
-
123
-    public function admin_footer_scripts()
124
-    {
125
-    }
126
-
127
-
128
-
129
-    public function load_scripts_styles()
130
-    {
131
-    }
132
-
133
-
134
-
135
-    protected function _installation()
136
-    {
137
-        $template_path = EE_SUPPORT_ADMIN_TEMPLATE_PATH . 'support_admin_details_installation.template.php';
138
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
139
-            $template_path,
140
-            '',
141
-            true
142
-        );
143
-        $this->display_admin_page_with_sidebar();
144
-    }
145
-
146
-
147
-
148
-    protected function _resources()
149
-    {
150
-        $this->display_admin_page_with_sidebar();
151
-    }
152
-
153
-
154
-
155
-    protected function _add_settings_metabox($box, $label, array $args)
156
-    {
157
-        add_meta_box(
158
-            "espresso_{$box}_settings",
159
-            $label,
160
-            function ($post, $metabox) {
161
-                echo EEH_Template::display_template(
162
-                    $metabox['args']['template_path'],
163
-                    $metabox['args']['template_args'],
164
-                    true
165
-                );
166
-            },
167
-            $this->_current_screen->id,
168
-            'normal',
169
-            'high',
170
-            apply_filters(
171
-                "FHEE__Support_Admin_Page___add_settings_metabox__{$box}_args_array",
172
-                $args
173
-            )
174
-        );
175
-    }
176
-
177
-
178
-
179
-    protected function _resources_boxes()
180
-    {
181
-        $boxes = apply_filters(
182
-            'FHEE__Support_Admin_Page___resources_boxes__boxes_array',
183
-            array(
184
-                'favorite_theme_developers' => esc_html__('Favorite Theme Developers', 'event_espresso'),
185
-                'highly_recommended_themes' => esc_html__('Highly Recommended Themes', 'event_espresso'),
186
-                'hire_developer'            => esc_html__('Hire a Developer', 'event_espresso'),
187
-                'partners'                  => esc_html__('Partners', 'event_espresso'),
188
-                'recommended_plugins'       => esc_html__('Recommended Plugins', 'event_espresso'),
189
-                'other_resources'           => esc_html__('Other Resources', 'event_espresso'),
190
-            )
191
-        );
192
-        foreach ($boxes as $box => $label) {
193
-            $this->_add_settings_metabox(
194
-                $box,
195
-                $label,
196
-                array(
197
-                    'template_path' => EE_SUPPORT_ADMIN_TEMPLATE_PATH . "support_admin_details_{$box}.template.php",
198
-                    'template_args' => $this->_template_args,
199
-                )
200
-            );
201
-        }
202
-    }
203
-
204
-
205
-
206
-    protected function _shortcodes()
207
-    {
208
-        $this->display_admin_page_with_sidebar();
209
-    }
210
-
211
-
212
-
213
-    protected function _shortcodes_boxes()
214
-    {
215
-        $boxes = apply_filters(
216
-            'FHEE__Support_Admin_Page___shortcodes_boxes__boxes_array',
217
-            array(
218
-                'shortcodes_event_listings'  => esc_html__('Event Listings', 'event_espresso'),
219
-                'shortcodes_ticket_selector' => esc_html__('Event Ticket Selector', 'event_espresso'),
220
-                'shortcodes_category'        => esc_html__('Event Categories', 'event_espresso'),
221
-                'shortcodes_attendee'        => esc_html__('Event Attendees', 'event_espresso')
222
-                /*'shortcodes_single_events' => esc_html__('Single Events', 'event_espresso'),*/
223
-                /*'shortcodes_attendee_listings' => esc_html__('Attendee Listings', 'event_espresso'),*/
224
-            )
225
-        );
226
-        foreach ($boxes as $box => $label) {
227
-            $this->_add_settings_metabox(
228
-                $box,
229
-                $label,
230
-                array(
231
-                    'template_path' => EE_SUPPORT_ADMIN_TEMPLATE_PATH . "support_admin_details_{$box}.template.php",
232
-                    'template_args' => $this->_template_args,
233
-                )
234
-            );
235
-        }
236
-    }
237
-
238
-
239
-
240
-    protected function _contact_support()
241
-    {
242
-        $this->display_admin_page_with_sidebar();
243
-    }
244
-
245
-
246
-
247
-    protected function _support_boxes()
248
-    {
249
-        $boxes = apply_filters(
250
-            'FHEE__Support_Admin_Page___support_boxes__boxes_array',
251
-            array(
252
-                'contact_support'       => esc_html__('Contact Support', 'event_espresso'),
253
-                'important_information' => esc_html__('Important Information', 'event_espresso'),
254
-            )
255
-        );
256
-        foreach ($boxes as $box => $label) {
257
-            $this->_add_settings_metabox(
258
-                $box,
259
-                $label,
260
-                array(
261
-                    'template_path' => EE_SUPPORT_ADMIN_TEMPLATE_PATH . "support_admin_details_{$box}.template.php",
262
-                    'template_args' => $this->_template_args,
263
-                )
264
-            );
265
-        }
266
-    }
267
-
268
-
269
-
270
-    protected function _developers()
271
-    {
272
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
273
-            EE_SUPPORT_ADMIN_TEMPLATE_PATH . 'developers_admin_details.template.php',
274
-            array(),
275
-            true
276
-        );
277
-        $this->display_admin_page_with_sidebar();
278
-    }
121
+
122
+
123
+	public function admin_footer_scripts()
124
+	{
125
+	}
126
+
127
+
128
+
129
+	public function load_scripts_styles()
130
+	{
131
+	}
132
+
133
+
134
+
135
+	protected function _installation()
136
+	{
137
+		$template_path = EE_SUPPORT_ADMIN_TEMPLATE_PATH . 'support_admin_details_installation.template.php';
138
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
139
+			$template_path,
140
+			'',
141
+			true
142
+		);
143
+		$this->display_admin_page_with_sidebar();
144
+	}
145
+
146
+
147
+
148
+	protected function _resources()
149
+	{
150
+		$this->display_admin_page_with_sidebar();
151
+	}
152
+
153
+
154
+
155
+	protected function _add_settings_metabox($box, $label, array $args)
156
+	{
157
+		add_meta_box(
158
+			"espresso_{$box}_settings",
159
+			$label,
160
+			function ($post, $metabox) {
161
+				echo EEH_Template::display_template(
162
+					$metabox['args']['template_path'],
163
+					$metabox['args']['template_args'],
164
+					true
165
+				);
166
+			},
167
+			$this->_current_screen->id,
168
+			'normal',
169
+			'high',
170
+			apply_filters(
171
+				"FHEE__Support_Admin_Page___add_settings_metabox__{$box}_args_array",
172
+				$args
173
+			)
174
+		);
175
+	}
176
+
177
+
178
+
179
+	protected function _resources_boxes()
180
+	{
181
+		$boxes = apply_filters(
182
+			'FHEE__Support_Admin_Page___resources_boxes__boxes_array',
183
+			array(
184
+				'favorite_theme_developers' => esc_html__('Favorite Theme Developers', 'event_espresso'),
185
+				'highly_recommended_themes' => esc_html__('Highly Recommended Themes', 'event_espresso'),
186
+				'hire_developer'            => esc_html__('Hire a Developer', 'event_espresso'),
187
+				'partners'                  => esc_html__('Partners', 'event_espresso'),
188
+				'recommended_plugins'       => esc_html__('Recommended Plugins', 'event_espresso'),
189
+				'other_resources'           => esc_html__('Other Resources', 'event_espresso'),
190
+			)
191
+		);
192
+		foreach ($boxes as $box => $label) {
193
+			$this->_add_settings_metabox(
194
+				$box,
195
+				$label,
196
+				array(
197
+					'template_path' => EE_SUPPORT_ADMIN_TEMPLATE_PATH . "support_admin_details_{$box}.template.php",
198
+					'template_args' => $this->_template_args,
199
+				)
200
+			);
201
+		}
202
+	}
203
+
204
+
205
+
206
+	protected function _shortcodes()
207
+	{
208
+		$this->display_admin_page_with_sidebar();
209
+	}
210
+
211
+
212
+
213
+	protected function _shortcodes_boxes()
214
+	{
215
+		$boxes = apply_filters(
216
+			'FHEE__Support_Admin_Page___shortcodes_boxes__boxes_array',
217
+			array(
218
+				'shortcodes_event_listings'  => esc_html__('Event Listings', 'event_espresso'),
219
+				'shortcodes_ticket_selector' => esc_html__('Event Ticket Selector', 'event_espresso'),
220
+				'shortcodes_category'        => esc_html__('Event Categories', 'event_espresso'),
221
+				'shortcodes_attendee'        => esc_html__('Event Attendees', 'event_espresso')
222
+				/*'shortcodes_single_events' => esc_html__('Single Events', 'event_espresso'),*/
223
+				/*'shortcodes_attendee_listings' => esc_html__('Attendee Listings', 'event_espresso'),*/
224
+			)
225
+		);
226
+		foreach ($boxes as $box => $label) {
227
+			$this->_add_settings_metabox(
228
+				$box,
229
+				$label,
230
+				array(
231
+					'template_path' => EE_SUPPORT_ADMIN_TEMPLATE_PATH . "support_admin_details_{$box}.template.php",
232
+					'template_args' => $this->_template_args,
233
+				)
234
+			);
235
+		}
236
+	}
237
+
238
+
239
+
240
+	protected function _contact_support()
241
+	{
242
+		$this->display_admin_page_with_sidebar();
243
+	}
244
+
245
+
246
+
247
+	protected function _support_boxes()
248
+	{
249
+		$boxes = apply_filters(
250
+			'FHEE__Support_Admin_Page___support_boxes__boxes_array',
251
+			array(
252
+				'contact_support'       => esc_html__('Contact Support', 'event_espresso'),
253
+				'important_information' => esc_html__('Important Information', 'event_espresso'),
254
+			)
255
+		);
256
+		foreach ($boxes as $box => $label) {
257
+			$this->_add_settings_metabox(
258
+				$box,
259
+				$label,
260
+				array(
261
+					'template_path' => EE_SUPPORT_ADMIN_TEMPLATE_PATH . "support_admin_details_{$box}.template.php",
262
+					'template_args' => $this->_template_args,
263
+				)
264
+			);
265
+		}
266
+	}
267
+
268
+
269
+
270
+	protected function _developers()
271
+	{
272
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
273
+			EE_SUPPORT_ADMIN_TEMPLATE_PATH . 'developers_admin_details.template.php',
274
+			array(),
275
+			true
276
+		);
277
+		$this->display_admin_page_with_sidebar();
278
+	}
279 279
 
280 280
 
281 281
 
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if (! defined('EVENT_ESPRESSO_VERSION')) {
2
+if ( ! defined('EVENT_ESPRESSO_VERSION')) {
3 3
     exit('NO direct script access allowed');
4 4
 }
5 5
 
@@ -134,7 +134,7 @@  discard block
 block discarded – undo
134 134
 
135 135
     protected function _installation()
136 136
     {
137
-        $template_path = EE_SUPPORT_ADMIN_TEMPLATE_PATH . 'support_admin_details_installation.template.php';
137
+        $template_path = EE_SUPPORT_ADMIN_TEMPLATE_PATH.'support_admin_details_installation.template.php';
138 138
         $this->_template_args['admin_page_content'] = EEH_Template::display_template(
139 139
             $template_path,
140 140
             '',
@@ -157,7 +157,7 @@  discard block
 block discarded – undo
157 157
         add_meta_box(
158 158
             "espresso_{$box}_settings",
159 159
             $label,
160
-            function ($post, $metabox) {
160
+            function($post, $metabox) {
161 161
                 echo EEH_Template::display_template(
162 162
                     $metabox['args']['template_path'],
163 163
                     $metabox['args']['template_args'],
@@ -194,7 +194,7 @@  discard block
 block discarded – undo
194 194
                 $box,
195 195
                 $label,
196 196
                 array(
197
-                    'template_path' => EE_SUPPORT_ADMIN_TEMPLATE_PATH . "support_admin_details_{$box}.template.php",
197
+                    'template_path' => EE_SUPPORT_ADMIN_TEMPLATE_PATH."support_admin_details_{$box}.template.php",
198 198
                     'template_args' => $this->_template_args,
199 199
                 )
200 200
             );
@@ -228,7 +228,7 @@  discard block
 block discarded – undo
228 228
                 $box,
229 229
                 $label,
230 230
                 array(
231
-                    'template_path' => EE_SUPPORT_ADMIN_TEMPLATE_PATH . "support_admin_details_{$box}.template.php",
231
+                    'template_path' => EE_SUPPORT_ADMIN_TEMPLATE_PATH."support_admin_details_{$box}.template.php",
232 232
                     'template_args' => $this->_template_args,
233 233
                 )
234 234
             );
@@ -258,7 +258,7 @@  discard block
 block discarded – undo
258 258
                 $box,
259 259
                 $label,
260 260
                 array(
261
-                    'template_path' => EE_SUPPORT_ADMIN_TEMPLATE_PATH . "support_admin_details_{$box}.template.php",
261
+                    'template_path' => EE_SUPPORT_ADMIN_TEMPLATE_PATH."support_admin_details_{$box}.template.php",
262 262
                     'template_args' => $this->_template_args,
263 263
                 )
264 264
             );
@@ -270,7 +270,7 @@  discard block
 block discarded – undo
270 270
     protected function _developers()
271 271
     {
272 272
         $this->_template_args['admin_page_content'] = EEH_Template::display_template(
273
-            EE_SUPPORT_ADMIN_TEMPLATE_PATH . 'developers_admin_details.template.php',
273
+            EE_SUPPORT_ADMIN_TEMPLATE_PATH.'developers_admin_details.template.php',
274 274
             array(),
275 275
             true
276 276
         );
Please login to merge, or discard this patch.
form_sections/strategies/normalization/EE_Int_Normalization.strategy.php 3 patches
Indentation   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -20,8 +20,8 @@  discard block
 block discarded – undo
20 20
 		}
21 21
 
22 22
 		if ( is_null( $value_to_normalize ) || $value_to_normalize === '' ) {
23
-		    return null;
24
-        }
23
+			return null;
24
+		}
25 25
 
26 26
 		if( ! is_string( $value_to_normalize )){
27 27
 			throw new EE_Validation_Error( sprintf( __( 'The value "%s" must be a string submitted for normalization, it was %s', 'event_espresso' ), print_r( $value_to_normalize, TRUE), gettype( $value_to_normalize ) ) );
@@ -56,9 +56,9 @@  discard block
 block discarded – undo
56 56
 	 * @return string
57 57
 	 */
58 58
 	public function unnormalize( $normalized_value ) {
59
-	    if ($normalized_value === null || $normalized_value === '') {
60
-	        return '';
61
-        }elseif( empty( $normalized_value ) ){
59
+		if ($normalized_value === null || $normalized_value === '') {
60
+			return '';
61
+		}elseif( empty( $normalized_value ) ){
62 62
 			return '0';
63 63
 		}else{
64 64
 			return "$normalized_value";
Please login to merge, or discard this patch.
Spacing   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -7,7 +7,7 @@  discard block
 block discarded – undo
7 7
  * @subpackage
8 8
  * @author				Mike Nelson
9 9
  */
10
-class EE_Int_Normalization extends EE_Normalization_Strategy_Base{
10
+class EE_Int_Normalization extends EE_Normalization_Strategy_Base {
11 11
 
12 12
 	/**
13 13
 	 * @param string $value_to_normalize
@@ -15,38 +15,38 @@  discard block
 block discarded – undo
15 15
 	 * @throws \EE_Validation_Error
16 16
 	 */
17 17
 	public function normalize($value_to_normalize) {
18
-		if( is_int( $value_to_normalize ) ){
18
+		if (is_int($value_to_normalize)) {
19 19
 			return $value_to_normalize;
20 20
 		}
21 21
 
22
-		if ( is_null( $value_to_normalize ) || $value_to_normalize === '' ) {
22
+		if (is_null($value_to_normalize) || $value_to_normalize === '') {
23 23
 		    return null;
24 24
         }
25 25
 
26
-		if( ! is_string( $value_to_normalize )){
27
-			throw new EE_Validation_Error( sprintf( __( 'The value "%s" must be a string submitted for normalization, it was %s', 'event_espresso' ), print_r( $value_to_normalize, TRUE), gettype( $value_to_normalize ) ) );
26
+		if ( ! is_string($value_to_normalize)) {
27
+			throw new EE_Validation_Error(sprintf(__('The value "%s" must be a string submitted for normalization, it was %s', 'event_espresso'), print_r($value_to_normalize, TRUE), gettype($value_to_normalize)));
28 28
 		}
29 29
 		$thousands_separator = EE_Config::instance()->currency->thsnds;
30
-		$value_to_normalize = str_replace( $thousands_separator, "", $value_to_normalize );
31
-		$value_to_normalize = str_replace( array(" ","\t"), '', $value_to_normalize );
32
-		if ( preg_match( '/^\d+$/', $value_to_normalize )) {
33
-			return intval( $value_to_normalize );
30
+		$value_to_normalize = str_replace($thousands_separator, "", $value_to_normalize);
31
+		$value_to_normalize = str_replace(array(" ", "\t"), '', $value_to_normalize);
32
+		if (preg_match('/^\d+$/', $value_to_normalize)) {
33
+			return intval($value_to_normalize);
34 34
 		} else {
35 35
 			//find if this input has a int validation strategy
36 36
 			//in which case, use its message
37 37
 			$validation_error_message = NULL;
38
-			foreach( $this->_input->get_validation_strategies() as $validation_strategy ){
39
-				if( $validation_strategy instanceof EE_Int_Validation_Strategy ){
38
+			foreach ($this->_input->get_validation_strategies() as $validation_strategy) {
39
+				if ($validation_strategy instanceof EE_Int_Validation_Strategy) {
40 40
 					$validation_error_message = $validation_strategy->get_validation_error_message();
41 41
 				}
42 42
 			}
43 43
 			//this really shouldn't ever happen because fields with a int normalization strategy
44 44
 			//should also have a int validation strategy, but in case it doesnt use the default
45
-			if( ! $validation_error_message ){
45
+			if ( ! $validation_error_message) {
46 46
 				$default_validation_strategy = new EE_Int_Validation_Strategy();
47 47
 				$validation_error_message = $default_validation_strategy->get_validation_error_message();
48 48
 			}
49
-			throw new EE_Validation_Error( $validation_error_message, 'numeric_only' );
49
+			throw new EE_Validation_Error($validation_error_message, 'numeric_only');
50 50
 		}
51 51
 	}
52 52
 
@@ -55,12 +55,12 @@  discard block
 block discarded – undo
55 55
 	 * @param int $normalized_value
56 56
 	 * @return string
57 57
 	 */
58
-	public function unnormalize( $normalized_value ) {
58
+	public function unnormalize($normalized_value) {
59 59
 	    if ($normalized_value === null || $normalized_value === '') {
60 60
 	        return '';
61
-        }elseif( empty( $normalized_value ) ){
61
+        }elseif (empty($normalized_value)) {
62 62
 			return '0';
63
-		}else{
63
+		} else {
64 64
 			return "$normalized_value";
65 65
 		}
66 66
 	}
Please login to merge, or discard this patch.
Braces   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -58,9 +58,9 @@
 block discarded – undo
58 58
 	public function unnormalize( $normalized_value ) {
59 59
 	    if ($normalized_value === null || $normalized_value === '') {
60 60
 	        return '';
61
-        }elseif( empty( $normalized_value ) ){
61
+        } elseif( empty( $normalized_value ) ){
62 62
 			return '0';
63
-		}else{
63
+		} else{
64 64
 			return "$normalized_value";
65 65
 		}
66 66
 	}
Please login to merge, or discard this patch.
admin_pages/maintenance/Maintenance_Admin_Page.core.php 2 patches
Indentation   +616 added lines, -616 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 if ( ! defined('EVENT_ESPRESSO_VERSION')) {
3
-    exit('NO direct script access allowed');
3
+	exit('NO direct script access allowed');
4 4
 }
5 5
 
6 6
 
@@ -28,636 +28,636 @@  discard block
 block discarded – undo
28 28
 {
29 29
 
30 30
 
31
-    public function __construct($routing = true)
32
-    {
33
-        parent::__construct($routing);
34
-    }
35
-
36
-
37
-
38
-    protected function _init_page_props()
39
-    {
40
-        $this->page_slug = EE_MAINTENANCE_PG_SLUG;
41
-        $this->page_label = EE_MAINTENANCE_LABEL;
42
-        $this->_admin_base_url = EE_MAINTENANCE_ADMIN_URL;
43
-        $this->_admin_base_path = EE_MAINTENANCE_ADMIN;
44
-    }
45
-
46
-
47
-
48
-    protected function _ajax_hooks()
49
-    {
50
-        add_action('wp_ajax_migration_step', array($this, 'migration_step'));
51
-        add_action('wp_ajax_add_error_to_migrations_ran', array($this, 'add_error_to_migrations_ran'));
52
-    }
53
-
54
-
55
-
56
-    protected function _define_page_props()
57
-    {
58
-        $this->_admin_page_title = EE_MAINTENANCE_LABEL;
59
-        $this->_labels = array(
60
-            'buttons' => array(
61
-                'reset_reservations' => esc_html__('Reset Ticket and Datetime Reserved Counts', 'event_espresso'),
62
-                'reset_capabilities' => esc_html__('Reset Event Espresso Capabilities', 'event_espresso'),
63
-            ),
64
-        );
65
-    }
66
-
67
-
68
-
69
-    protected function _set_page_routes()
70
-    {
71
-        $this->_page_routes = array(
72
-            'default'                             => array(
73
-                'func'       => '_maintenance',
74
-                'capability' => 'manage_options',
75
-            ),
76
-            'change_maintenance_level'            => array(
77
-                'func'       => '_change_maintenance_level',
78
-                'capability' => 'manage_options',
79
-                'noheader'   => true,
80
-            ),
81
-            'system_status'                       => array(
82
-                'func'       => '_system_status',
83
-                'capability' => 'manage_options',
84
-            ),
85
-            'download_system_status' => array(
86
-                'func'       => '_download_system_status',
87
-                'capability' => 'manage_options',
88
-                'noheader'   => true,
89
-            ),
90
-            'send_migration_crash_report'         => array(
91
-                'func'       => '_send_migration_crash_report',
92
-                'capability' => 'manage_options',
93
-                'noheader'   => true,
94
-            ),
95
-            'confirm_migration_crash_report_sent' => array(
96
-                'func'       => '_confirm_migration_crash_report_sent',
97
-                'capability' => 'manage_options',
98
-            ),
99
-            'data_reset'                          => array(
100
-                'func'       => '_data_reset_and_delete',
101
-                'capability' => 'manage_options',
102
-            ),
103
-            'reset_db'                            => array(
104
-                'func'       => '_reset_db',
105
-                'capability' => 'manage_options',
106
-                'noheader'   => true,
107
-                'args'       => array('nuke_old_ee4_data' => true),
108
-            ),
109
-            'start_with_fresh_ee4_db'             => array(
110
-                'func'       => '_reset_db',
111
-                'capability' => 'manage_options',
112
-                'noheader'   => true,
113
-                'args'       => array('nuke_old_ee4_data' => false),
114
-            ),
115
-            'delete_db'                           => array(
116
-                'func'       => '_delete_db',
117
-                'capability' => 'manage_options',
118
-                'noheader'   => true,
119
-            ),
120
-            'rerun_migration_from_ee3'            => array(
121
-                'func'       => '_rerun_migration_from_ee3',
122
-                'capability' => 'manage_options',
123
-                'noheader'   => true,
124
-            ),
125
-            'reset_reservations'                  => array(
126
-                'func'       => '_reset_reservations',
127
-                'capability' => 'manage_options',
128
-                'noheader'   => true,
129
-            ),
130
-            'reset_capabilities'                  => array(
131
-                'func'       => '_reset_capabilities',
132
-                'capability' => 'manage_options',
133
-                'noheader'   => true,
134
-            ),
135
-            'reattempt_migration'                 => array(
136
-                'func'       => '_reattempt_migration',
137
-                'capability' => 'manage_options',
138
-                'noheader'   => true,
139
-            ),
140
-        );
141
-    }
142
-
143
-
144
-
145
-    protected function _set_page_config()
146
-    {
147
-        $this->_page_config = array(
148
-            'default'       => array(
149
-                'nav'           => array(
150
-                    'label' => esc_html__('Maintenance', 'event_espresso'),
151
-                    'order' => 10,
152
-                ),
153
-                'require_nonce' => false,
154
-            ),
155
-            'data_reset'    => array(
156
-                'nav'           => array(
157
-                    'label' => esc_html__('Reset/Delete Data', 'event_espresso'),
158
-                    'order' => 20,
159
-                ),
160
-                'require_nonce' => false,
161
-            ),
162
-            'system_status' => array(
163
-                'nav'           => array(
164
-                    'label' => esc_html__("System Information", "event_espresso"),
165
-                    'order' => 30,
166
-                ),
167
-                'require_nonce' => false,
168
-            ),
169
-        );
170
-    }
171
-
172
-
173
-
174
-    /**
175
-     * default maintenance page. If we're in maintenance mode level 2, then we need to show
176
-     * the migration scripts and all that UI.
177
-     */
178
-    public function _maintenance()
179
-    {
180
-        //it all depends if we're in maintenance model level 1 (frontend-only) or
181
-        //level 2 (everything except maintenance page)
182
-        try {
183
-            //get the current maintenance level and check if
184
-            //we are removed
185
-            $mm = EE_Maintenance_Mode::instance()->level();
186
-            $placed_in_mm = EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old();
187
-            if ($mm == EE_Maintenance_Mode::level_2_complete_maintenance && ! $placed_in_mm) {
188
-                //we just took the site out of maintenance mode, so notify the user.
189
-                //unfortunately this message appears to be echoed on the NEXT page load...
190
-                //oh well, we should really be checking for this on addon deactivation anyways
191
-                EE_Error::add_attention(__('Site taken out of maintenance mode because no data migration scripts are required',
192
-                    'event_espresso'));
193
-                $this->_process_notices(array('page' => 'espresso_maintenance_settings'), false);
194
-            }
195
-            //in case an exception is thrown while trying to handle migrations
196
-            switch (EE_Maintenance_Mode::instance()->level()) {
197
-                case EE_Maintenance_Mode::level_0_not_in_maintenance:
198
-                case EE_Maintenance_Mode::level_1_frontend_only_maintenance:
199
-                    $show_maintenance_switch = true;
200
-                    $show_backup_db_text = false;
201
-                    $show_migration_progress = false;
202
-                    $script_names = array();
203
-                    $addons_should_be_upgraded_first = false;
204
-                    break;
205
-                case EE_Maintenance_Mode::level_2_complete_maintenance:
206
-                    $show_maintenance_switch = false;
207
-                    $show_migration_progress = true;
208
-                    if (isset($this->_req_data['continue_migration'])) {
209
-                        $show_backup_db_text = false;
210
-                    } else {
211
-                        $show_backup_db_text = true;
212
-                    }
213
-                    $scripts_needing_to_run = EE_Data_Migration_Manager::instance()
214
-                                                                       ->check_for_applicable_data_migration_scripts();
215
-                    $addons_should_be_upgraded_first = EE_Data_Migration_Manager::instance()->addons_need_updating();
216
-                    $script_names = array();
217
-                    $current_script = null;
218
-                    foreach ($scripts_needing_to_run as $script) {
219
-                        if ($script instanceof EE_Data_Migration_Script_Base) {
220
-                            if ( ! $current_script) {
221
-                                $current_script = $script;
222
-                                $current_script->migration_page_hooks();
223
-                            }
224
-                            $script_names[] = $script->pretty_name();
225
-                        }
226
-                    }
227
-                    break;
228
-            }
229
-            $most_recent_migration = EE_Data_Migration_Manager::instance()->get_last_ran_script(true);
230
-            $exception_thrown = false;
231
-        } catch (EE_Error $e) {
232
-            EE_Data_Migration_Manager::instance()->add_error_to_migrations_ran($e->getMessage());
233
-            //now, just so we can display the page correctly, make a error migration script stage object
234
-            //and also put the error on it. It only persists for the duration of this request
235
-            $most_recent_migration = new EE_DMS_Unknown_1_0_0();
236
-            $most_recent_migration->add_error($e->getMessage());
237
-            $exception_thrown = true;
238
-        }
239
-        $current_db_state = EE_Data_Migration_Manager::instance()->ensure_current_database_state_is_set();
240
-        $current_db_state = str_replace('.decaf', '', $current_db_state);
241
-        if ($exception_thrown
242
-            || ($most_recent_migration
243
-                && $most_recent_migration instanceof EE_Data_Migration_Script_Base
244
-                && $most_recent_migration->is_broken()
245
-            )
246
-        ) {
247
-            $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_migration_was_borked_page.template.php';
248
-            $this->_template_args['support_url'] = 'http://eventespresso.com/support/forums/';
249
-            $this->_template_args['next_url'] = EEH_URL::add_query_args_and_nonce(array('action'  => 'confirm_migration_crash_report_sent',
250
-                                                                                        'success' => '0',
251
-            ), EE_MAINTENANCE_ADMIN_URL);
252
-        } elseif ($addons_should_be_upgraded_first) {
253
-            $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_upgrade_addons_before_migrating.template.php';
254
-        } else {
255
-            if ($most_recent_migration
256
-                && $most_recent_migration instanceof EE_Data_Migration_Script_Base
257
-                && $most_recent_migration->can_continue()
258
-            ) {
259
-                $show_backup_db_text = false;
260
-                $show_continue_current_migration_script = true;
261
-                $show_most_recent_migration = true;
262
-            } elseif (isset($this->_req_data['continue_migration'])) {
263
-                $show_most_recent_migration = true;
264
-                $show_continue_current_migration_script = false;
265
-            } else {
266
-                $show_most_recent_migration = false;
267
-                $show_continue_current_migration_script = false;
268
-            }
269
-            if (isset($current_script)) {
270
-                $migrates_to = $current_script->migrates_to_version();
271
-                $plugin_slug = $migrates_to['slug'];
272
-                $new_version = $migrates_to['version'];
273
-                $this->_template_args = array_merge($this->_template_args, array(
274
-                    'current_db_state' => sprintf(__("EE%s (%s)", "event_espresso"),
275
-                        isset($current_db_state[$plugin_slug]) ? $current_db_state[$plugin_slug] : 3, $plugin_slug),
276
-                    'next_db_state'    => isset($current_script) ? sprintf(__("EE%s (%s)", 'event_espresso'),
277
-                        $new_version, $plugin_slug) : null,
278
-                ));
279
-            } else {
280
-                $this->_template_args['current_db_state'] = null;
281
-                $this->_template_args['next_db_state'] = null;
282
-            }
283
-            $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_migration_page.template.php';
284
-            $this->_template_args = array_merge(
285
-                $this->_template_args,
286
-                array(
287
-                    'show_most_recent_migration'             => $show_most_recent_migration,
288
-                    //flag for showing the most recent migration's status and/or errors
289
-                    'show_migration_progress'                => $show_migration_progress,
290
-                    //flag for showing the option to run migrations and see their progress
291
-                    'show_backup_db_text'                    => $show_backup_db_text,
292
-                    //flag for showing text telling the user to backup their DB
293
-                    'show_maintenance_switch'                => $show_maintenance_switch,
294
-                    //flag for showing the option to change maintenance mode between levels 0 and 1
295
-                    'script_names'                           => $script_names,
296
-                    //array of names of scripts that have run
297
-                    'show_continue_current_migration_script' => $show_continue_current_migration_script,
298
-                    //flag to change wording to indicating that we're only CONTINUING a migration script (somehow it got interrupted0
299
-                    'reset_db_page_link'                     => EE_Admin_Page::add_query_args_and_nonce(array('action' => 'reset_db'),
300
-                        EE_MAINTENANCE_ADMIN_URL),
301
-                    'data_reset_page'                        => EE_Admin_Page::add_query_args_and_nonce(array('action' => 'data_reset'),
302
-                        EE_MAINTENANCE_ADMIN_URL),
303
-                    'update_migration_script_page_link'      => EE_Admin_Page::add_query_args_and_nonce(array('action' => 'change_maintenance_level'),
304
-                        EE_MAINTENANCE_ADMIN_URL),
305
-                    'ultimate_db_state'                      => sprintf(__("EE%s", 'event_espresso'),
306
-                        espresso_version()),
307
-                )
308
-            );
309
-            //make sure we have the form fields helper available. It usually is, but sometimes it isn't
310
-            //localize script stuff
311
-            wp_localize_script('ee-maintenance', 'ee_maintenance', array(
312
-                'migrating'                        => esc_html__("Updating Database...", "event_espresso"),
313
-                'next'                             => esc_html__("Next", "event_espresso"),
314
-                'fatal_error'                      => esc_html__("A Fatal Error Has Occurred", "event_espresso"),
315
-                'click_next_when_ready'            => esc_html__("The current Database Update has ended. Click 'next' when ready to proceed",
316
-                    "event_espresso"),
317
-                'status_no_more_migration_scripts' => EE_Data_Migration_Manager::status_no_more_migration_scripts,
318
-                'status_fatal_error'               => EE_Data_Migration_Manager::status_fatal_error,
319
-                'status_completed'                 => EE_Data_Migration_Manager::status_completed,
320
-            ));
321
-        }
322
-        $this->_template_args['most_recent_migration'] = $most_recent_migration;//the actual most recently ran migration
323
-        //now render the migration options part, and put it in a variable
324
-        $migration_options_template_file = apply_filters(
325
-            'FHEE__ee_migration_page__migration_options_template',
326
-            EE_MAINTENANCE_TEMPLATE_PATH . 'migration_options_from_ee4.template.php'
327
-        );
328
-        $migration_options_html = EEH_Template::display_template($migration_options_template_file, $this->_template_args,true);
329
-        $this->_template_args['migration_options_html'] = $migration_options_html;
330
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template($this->_template_path,
331
-            $this->_template_args, true);
332
-        $this->display_admin_page_with_sidebar();
333
-    }
334
-
335
-
336
-
337
-    /**
338
-     * returns JSON and executes another step of the currently-executing data migration (called via ajax)
339
-     */
340
-    public function migration_step()
341
-    {
342
-        $this->_template_args['data'] = EE_Data_Migration_Manager::instance()->response_to_migration_ajax_request();
343
-        $this->_return_json();
344
-    }
345
-
346
-
347
-
348
-    /**
349
-     * Can be used by js when it notices a response with HTML in it in order
350
-     * to log the malformed response
351
-     */
352
-    public function add_error_to_migrations_ran()
353
-    {
354
-        EE_Data_Migration_Manager::instance()->add_error_to_migrations_ran($this->_req_data['message']);
355
-        $this->_template_args['data'] = array('ok' => true);
356
-        $this->_return_json();
357
-    }
358
-
359
-
360
-
361
-    /**
362
-     * changes the maintenance level, provided there are still no migration scripts that should run
363
-     */
364
-    public function _change_maintenance_level()
365
-    {
366
-        $new_level = absint($this->_req_data['maintenance_mode_level']);
367
-        if ( ! EE_Data_Migration_Manager::instance()->check_for_applicable_data_migration_scripts()) {
368
-            EE_Maintenance_Mode::instance()->set_maintenance_level($new_level);
369
-            $success = true;
370
-        } else {
371
-            EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old();
372
-            $success = false;
373
-        }
374
-        $this->_redirect_after_action($success, 'Maintenance Mode', esc_html__("Updated", "event_espresso"));
375
-    }
376
-
377
-
378
-
379
-    /**
380
-     * a tab with options for resetting and/or deleting EE data
381
-     *
382
-     * @throws \EE_Error
383
-     * @throws \DomainException
384
-     */
385
-    public function _data_reset_and_delete()
386
-    {
387
-        $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_data_reset_and_delete.template.php';
388
-        $this->_template_args['reset_reservations_button'] = $this->get_action_link_or_button(
389
-            'reset_reservations',
390
-            'reset_reservations',
391
-            array(),
392
-            'button button-primary',
393
-            '',
394
-            false
395
-        );
396
-        $this->_template_args['reset_capabilities_button'] = $this->get_action_link_or_button(
397
-            'reset_capabilities',
398
-            'reset_capabilities',
399
-            array(),
400
-            'button button-primary',
401
-            '',
402
-            false
403
-        );
404
-        $this->_template_args['delete_db_url'] = EE_Admin_Page::add_query_args_and_nonce(
405
-            array('action' => 'delete_db'),
406
-            EE_MAINTENANCE_ADMIN_URL
407
-        );
408
-        $this->_template_args['reset_db_url'] = EE_Admin_Page::add_query_args_and_nonce(
409
-            array('action' => 'reset_db'),
410
-            EE_MAINTENANCE_ADMIN_URL
411
-        );
412
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
413
-            $this->_template_path,
414
-            $this->_template_args,
415
-            true
416
-        );
417
-        $this->display_admin_page_with_sidebar();
418
-    }
419
-
420
-
421
-
422
-    protected function _reset_reservations()
423
-    {
424
-        if(\EED_Ticket_Sales_Monitor::reset_reservation_counts()) {
425
-            EE_Error::add_success(
426
-                __(
427
-                    'Ticket and datetime reserved counts have been successfully reset.',
428
-                    'event_espresso'
429
-                )
430
-            );
431
-        } else {
432
-            EE_Error::add_success(
433
-                __(
434
-                    'Ticket and datetime reserved counts were correct and did not need resetting.',
435
-                    'event_espresso'
436
-                )
437
-            );
438
-        }
439
-        $this->_redirect_after_action(true, '', '', array('action' => 'data_reset'), true);
440
-    }
441
-
442
-
443
-
444
-    protected function _reset_capabilities()
445
-    {
446
-        EE_Registry::instance()->CAP->init_caps(true);
447
-        EE_Error::add_success(__('Default Event Espresso capabilities have been restored for all current roles.',
448
-            'event_espresso'));
449
-        $this->_redirect_after_action(false, '', '', array('action' => 'data_reset'), true);
450
-    }
451
-
452
-
453
-
454
-    /**
455
-     * resets the DMSs so we can attempt to continue migrating after a fatal error
456
-     * (only a good idea when someone has somehow tried ot fix whatever caused
457
-     * the fatal error in teh first place)
458
-     */
459
-    protected function _reattempt_migration()
460
-    {
461
-        EE_Data_Migration_Manager::instance()->reattempt();
462
-        $this->_redirect_after_action(false, '', '', array('action' => 'default'), true);
463
-    }
464
-
465
-
466
-
467
-    /**
468
-     * shows the big ol' System Information page
469
-     */
470
-    public function _system_status()
471
-    {
472
-        $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_system_stati_page.template.php';
473
-        $this->_template_args['system_stati'] = EEM_System_Status::instance()->get_system_stati();
474
-        $this->_template_args['download_system_status_url'] = EE_Admin_Page::add_query_args_and_nonce(
475
-            array(
476
-                'action' => 'download_system_status',
477
-            ),
478
-            EE_MAINTENANCE_ADMIN_URL
479
-        );
480
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template($this->_template_path,
481
-            $this->_template_args, true);
482
-        $this->display_admin_page_with_sidebar();
483
-    }
484
-
485
-    /**
486
-     * Downloads an HTML file of the system status that can be easily stored or emailed
487
-     */
488
-    public function _download_system_status()
489
-    {
490
-        $status_info = EEM_System_Status::instance()->get_system_stati();
491
-        header( 'Content-Disposition: attachment' );
492
-        header( "Content-Disposition: attachment; filename=system_status_" . sanitize_key( site_url() ) . ".html" );
493
-        echo "<style>table{border:1px solid darkgrey;}td{vertical-align:top}</style>";
494
-        echo "<h1>System Information for " . site_url() . "</h1>";
495
-        echo EEH_Template::layout_array_as_table( $status_info );
496
-        die;
497
-    }
498
-
499
-
500
-
501
-    public function _send_migration_crash_report()
502
-    {
503
-        $from = $this->_req_data['from'];
504
-        $from_name = $this->_req_data['from_name'];
505
-        $body = $this->_req_data['body'];
506
-        try {
507
-            $success = wp_mail(EE_SUPPORT_EMAIL,
508
-                'Migration Crash Report',
509
-                $body . "/r/n<br>" . print_r(EEM_System_Status::instance()->get_system_stati(), true),
510
-                array(
511
-                    "from:$from_name<$from>",
512
-                    //					'content-type:text/html charset=UTF-8'
513
-                ));
514
-        } catch (Exception $e) {
515
-            $success = false;
516
-        }
517
-        $this->_redirect_after_action($success, esc_html__("Migration Crash Report", "event_espresso"),
518
-            esc_html__("sent", "event_espresso"),
519
-            array('success' => $success, 'action' => 'confirm_migration_crash_report_sent'));
520
-    }
521
-
522
-
523
-
524
-    public function _confirm_migration_crash_report_sent()
525
-    {
526
-        try {
527
-            $most_recent_migration = EE_Data_Migration_Manager::instance()->get_last_ran_script(true);
528
-        } catch (EE_Error $e) {
529
-            EE_Data_Migration_Manager::instance()->add_error_to_migrations_ran($e->getMessage());
530
-            //now, just so we can display the page correctly, make a error migration script stage object
531
-            //and also put the error on it. It only persists for the duration of this request
532
-            $most_recent_migration = new EE_DMS_Unknown_1_0_0();
533
-            $most_recent_migration->add_error($e->getMessage());
534
-        }
535
-        $success = $this->_req_data['success'] == '1' ? true : false;
536
-        $this->_template_args['success'] = $success;
537
-        $this->_template_args['most_recent_migration'] = $most_recent_migration;
538
-        $this->_template_args['reset_db_action_url'] = EE_Admin_Page::add_query_args_and_nonce(array('action' => 'reset_db'),
539
-            EE_MAINTENANCE_ADMIN_URL);
540
-        $this->_template_args['reset_db_page_url'] = EE_Admin_Page::add_query_args_and_nonce(array('action' => 'data_reset'),
541
-            EE_MAINTENANCE_ADMIN_URL);
542
-        $this->_template_args['reattempt_action_url'] = EE_Admin_Page::add_query_args_and_nonce(array('action' => 'reattempt_migration'),
543
-            EE_MAINTENANCE_ADMIN_URL);
544
-        $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_confirm_migration_crash_report_sent.template.php';
545
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template($this->_template_path,
546
-            $this->_template_args, true);
547
-        $this->display_admin_page_with_sidebar();
548
-    }
549
-
550
-
551
-
552
-    /**
553
-     * Resets the entire EE4 database.
554
-     * Currently basically only sets up ee4 database for a fresh install- doesn't
555
-     * actually clean out the old wp options, or cpts (although does erase old ee table data)
556
-     *
557
-     * @param boolean $nuke_old_ee4_data controls whether or not we
558
-     *                                   destroy the old ee4 data, or just try initializing ee4 default data
559
-     */
560
-    public function _reset_db($nuke_old_ee4_data = true)
561
-    {
562
-        EE_Maintenance_Mode::instance()->set_maintenance_level(EE_Maintenance_Mode::level_0_not_in_maintenance);
563
-        if ($nuke_old_ee4_data) {
564
-            EEH_Activation::delete_all_espresso_cpt_data();
565
-            EEH_Activation::delete_all_espresso_tables_and_data(false);
566
-            EEH_Activation::remove_cron_tasks();
567
-        }
568
-        //make sure when we reset the registry's config that it
569
-        //switches to using the new singleton
570
-        EE_Registry::instance()->CFG = EE_Registry::instance()->CFG->reset(true);
571
-        EE_System::instance()->initialize_db_if_no_migrations_required(true);
572
-        EE_System::instance()->redirect_to_about_ee();
573
-    }
574
-
575
-
576
-
577
-    /**
578
-     * Deletes ALL EE tables, Records, and Options from the database.
579
-     */
580
-    public function _delete_db()
581
-    {
582
-        EE_Maintenance_Mode::instance()->set_maintenance_level(EE_Maintenance_Mode::level_0_not_in_maintenance);
583
-        EEH_Activation::delete_all_espresso_cpt_data();
584
-        EEH_Activation::delete_all_espresso_tables_and_data();
585
-        EEH_Activation::remove_cron_tasks();
586
-        EEH_Activation::deactivate_event_espresso();
587
-        wp_safe_redirect(admin_url('plugins.php'));
588
-        exit;
589
-    }
590
-
591
-
592
-
593
-    /**
594
-     * sets up EE4 to rerun the migrations from ee3 to ee4
595
-     */
596
-    public function _rerun_migration_from_ee3()
597
-    {
598
-        EE_Maintenance_Mode::instance()->set_maintenance_level(EE_Maintenance_Mode::level_0_not_in_maintenance);
599
-        EEH_Activation::delete_all_espresso_cpt_data();
600
-        EEH_Activation::delete_all_espresso_tables_and_data(false);
601
-        //set the db state to something that will require migrations
602
-        update_option(EE_Data_Migration_Manager::current_database_state, '3.1.36.0');
603
-        EE_Maintenance_Mode::instance()->set_maintenance_level(EE_Maintenance_Mode::level_2_complete_maintenance);
604
-        $this->_redirect_after_action(true, esc_html__("Database", 'event_espresso'), esc_html__("reset", 'event_espresso'));
605
-    }
606
-
607
-
608
-
609
-    //none of the below group are currently used for Gateway Settings
610
-    protected function _add_screen_options()
611
-    {
612
-    }
613
-
614
-
615
-
616
-    protected function _add_feature_pointers()
617
-    {
618
-    }
619
-
31
+	public function __construct($routing = true)
32
+	{
33
+		parent::__construct($routing);
34
+	}
35
+
36
+
37
+
38
+	protected function _init_page_props()
39
+	{
40
+		$this->page_slug = EE_MAINTENANCE_PG_SLUG;
41
+		$this->page_label = EE_MAINTENANCE_LABEL;
42
+		$this->_admin_base_url = EE_MAINTENANCE_ADMIN_URL;
43
+		$this->_admin_base_path = EE_MAINTENANCE_ADMIN;
44
+	}
45
+
46
+
47
+
48
+	protected function _ajax_hooks()
49
+	{
50
+		add_action('wp_ajax_migration_step', array($this, 'migration_step'));
51
+		add_action('wp_ajax_add_error_to_migrations_ran', array($this, 'add_error_to_migrations_ran'));
52
+	}
53
+
54
+
55
+
56
+	protected function _define_page_props()
57
+	{
58
+		$this->_admin_page_title = EE_MAINTENANCE_LABEL;
59
+		$this->_labels = array(
60
+			'buttons' => array(
61
+				'reset_reservations' => esc_html__('Reset Ticket and Datetime Reserved Counts', 'event_espresso'),
62
+				'reset_capabilities' => esc_html__('Reset Event Espresso Capabilities', 'event_espresso'),
63
+			),
64
+		);
65
+	}
66
+
67
+
68
+
69
+	protected function _set_page_routes()
70
+	{
71
+		$this->_page_routes = array(
72
+			'default'                             => array(
73
+				'func'       => '_maintenance',
74
+				'capability' => 'manage_options',
75
+			),
76
+			'change_maintenance_level'            => array(
77
+				'func'       => '_change_maintenance_level',
78
+				'capability' => 'manage_options',
79
+				'noheader'   => true,
80
+			),
81
+			'system_status'                       => array(
82
+				'func'       => '_system_status',
83
+				'capability' => 'manage_options',
84
+			),
85
+			'download_system_status' => array(
86
+				'func'       => '_download_system_status',
87
+				'capability' => 'manage_options',
88
+				'noheader'   => true,
89
+			),
90
+			'send_migration_crash_report'         => array(
91
+				'func'       => '_send_migration_crash_report',
92
+				'capability' => 'manage_options',
93
+				'noheader'   => true,
94
+			),
95
+			'confirm_migration_crash_report_sent' => array(
96
+				'func'       => '_confirm_migration_crash_report_sent',
97
+				'capability' => 'manage_options',
98
+			),
99
+			'data_reset'                          => array(
100
+				'func'       => '_data_reset_and_delete',
101
+				'capability' => 'manage_options',
102
+			),
103
+			'reset_db'                            => array(
104
+				'func'       => '_reset_db',
105
+				'capability' => 'manage_options',
106
+				'noheader'   => true,
107
+				'args'       => array('nuke_old_ee4_data' => true),
108
+			),
109
+			'start_with_fresh_ee4_db'             => array(
110
+				'func'       => '_reset_db',
111
+				'capability' => 'manage_options',
112
+				'noheader'   => true,
113
+				'args'       => array('nuke_old_ee4_data' => false),
114
+			),
115
+			'delete_db'                           => array(
116
+				'func'       => '_delete_db',
117
+				'capability' => 'manage_options',
118
+				'noheader'   => true,
119
+			),
120
+			'rerun_migration_from_ee3'            => array(
121
+				'func'       => '_rerun_migration_from_ee3',
122
+				'capability' => 'manage_options',
123
+				'noheader'   => true,
124
+			),
125
+			'reset_reservations'                  => array(
126
+				'func'       => '_reset_reservations',
127
+				'capability' => 'manage_options',
128
+				'noheader'   => true,
129
+			),
130
+			'reset_capabilities'                  => array(
131
+				'func'       => '_reset_capabilities',
132
+				'capability' => 'manage_options',
133
+				'noheader'   => true,
134
+			),
135
+			'reattempt_migration'                 => array(
136
+				'func'       => '_reattempt_migration',
137
+				'capability' => 'manage_options',
138
+				'noheader'   => true,
139
+			),
140
+		);
141
+	}
142
+
143
+
144
+
145
+	protected function _set_page_config()
146
+	{
147
+		$this->_page_config = array(
148
+			'default'       => array(
149
+				'nav'           => array(
150
+					'label' => esc_html__('Maintenance', 'event_espresso'),
151
+					'order' => 10,
152
+				),
153
+				'require_nonce' => false,
154
+			),
155
+			'data_reset'    => array(
156
+				'nav'           => array(
157
+					'label' => esc_html__('Reset/Delete Data', 'event_espresso'),
158
+					'order' => 20,
159
+				),
160
+				'require_nonce' => false,
161
+			),
162
+			'system_status' => array(
163
+				'nav'           => array(
164
+					'label' => esc_html__("System Information", "event_espresso"),
165
+					'order' => 30,
166
+				),
167
+				'require_nonce' => false,
168
+			),
169
+		);
170
+	}
171
+
172
+
173
+
174
+	/**
175
+	 * default maintenance page. If we're in maintenance mode level 2, then we need to show
176
+	 * the migration scripts and all that UI.
177
+	 */
178
+	public function _maintenance()
179
+	{
180
+		//it all depends if we're in maintenance model level 1 (frontend-only) or
181
+		//level 2 (everything except maintenance page)
182
+		try {
183
+			//get the current maintenance level and check if
184
+			//we are removed
185
+			$mm = EE_Maintenance_Mode::instance()->level();
186
+			$placed_in_mm = EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old();
187
+			if ($mm == EE_Maintenance_Mode::level_2_complete_maintenance && ! $placed_in_mm) {
188
+				//we just took the site out of maintenance mode, so notify the user.
189
+				//unfortunately this message appears to be echoed on the NEXT page load...
190
+				//oh well, we should really be checking for this on addon deactivation anyways
191
+				EE_Error::add_attention(__('Site taken out of maintenance mode because no data migration scripts are required',
192
+					'event_espresso'));
193
+				$this->_process_notices(array('page' => 'espresso_maintenance_settings'), false);
194
+			}
195
+			//in case an exception is thrown while trying to handle migrations
196
+			switch (EE_Maintenance_Mode::instance()->level()) {
197
+				case EE_Maintenance_Mode::level_0_not_in_maintenance:
198
+				case EE_Maintenance_Mode::level_1_frontend_only_maintenance:
199
+					$show_maintenance_switch = true;
200
+					$show_backup_db_text = false;
201
+					$show_migration_progress = false;
202
+					$script_names = array();
203
+					$addons_should_be_upgraded_first = false;
204
+					break;
205
+				case EE_Maintenance_Mode::level_2_complete_maintenance:
206
+					$show_maintenance_switch = false;
207
+					$show_migration_progress = true;
208
+					if (isset($this->_req_data['continue_migration'])) {
209
+						$show_backup_db_text = false;
210
+					} else {
211
+						$show_backup_db_text = true;
212
+					}
213
+					$scripts_needing_to_run = EE_Data_Migration_Manager::instance()
214
+																	   ->check_for_applicable_data_migration_scripts();
215
+					$addons_should_be_upgraded_first = EE_Data_Migration_Manager::instance()->addons_need_updating();
216
+					$script_names = array();
217
+					$current_script = null;
218
+					foreach ($scripts_needing_to_run as $script) {
219
+						if ($script instanceof EE_Data_Migration_Script_Base) {
220
+							if ( ! $current_script) {
221
+								$current_script = $script;
222
+								$current_script->migration_page_hooks();
223
+							}
224
+							$script_names[] = $script->pretty_name();
225
+						}
226
+					}
227
+					break;
228
+			}
229
+			$most_recent_migration = EE_Data_Migration_Manager::instance()->get_last_ran_script(true);
230
+			$exception_thrown = false;
231
+		} catch (EE_Error $e) {
232
+			EE_Data_Migration_Manager::instance()->add_error_to_migrations_ran($e->getMessage());
233
+			//now, just so we can display the page correctly, make a error migration script stage object
234
+			//and also put the error on it. It only persists for the duration of this request
235
+			$most_recent_migration = new EE_DMS_Unknown_1_0_0();
236
+			$most_recent_migration->add_error($e->getMessage());
237
+			$exception_thrown = true;
238
+		}
239
+		$current_db_state = EE_Data_Migration_Manager::instance()->ensure_current_database_state_is_set();
240
+		$current_db_state = str_replace('.decaf', '', $current_db_state);
241
+		if ($exception_thrown
242
+			|| ($most_recent_migration
243
+				&& $most_recent_migration instanceof EE_Data_Migration_Script_Base
244
+				&& $most_recent_migration->is_broken()
245
+			)
246
+		) {
247
+			$this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_migration_was_borked_page.template.php';
248
+			$this->_template_args['support_url'] = 'http://eventespresso.com/support/forums/';
249
+			$this->_template_args['next_url'] = EEH_URL::add_query_args_and_nonce(array('action'  => 'confirm_migration_crash_report_sent',
250
+																						'success' => '0',
251
+			), EE_MAINTENANCE_ADMIN_URL);
252
+		} elseif ($addons_should_be_upgraded_first) {
253
+			$this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_upgrade_addons_before_migrating.template.php';
254
+		} else {
255
+			if ($most_recent_migration
256
+				&& $most_recent_migration instanceof EE_Data_Migration_Script_Base
257
+				&& $most_recent_migration->can_continue()
258
+			) {
259
+				$show_backup_db_text = false;
260
+				$show_continue_current_migration_script = true;
261
+				$show_most_recent_migration = true;
262
+			} elseif (isset($this->_req_data['continue_migration'])) {
263
+				$show_most_recent_migration = true;
264
+				$show_continue_current_migration_script = false;
265
+			} else {
266
+				$show_most_recent_migration = false;
267
+				$show_continue_current_migration_script = false;
268
+			}
269
+			if (isset($current_script)) {
270
+				$migrates_to = $current_script->migrates_to_version();
271
+				$plugin_slug = $migrates_to['slug'];
272
+				$new_version = $migrates_to['version'];
273
+				$this->_template_args = array_merge($this->_template_args, array(
274
+					'current_db_state' => sprintf(__("EE%s (%s)", "event_espresso"),
275
+						isset($current_db_state[$plugin_slug]) ? $current_db_state[$plugin_slug] : 3, $plugin_slug),
276
+					'next_db_state'    => isset($current_script) ? sprintf(__("EE%s (%s)", 'event_espresso'),
277
+						$new_version, $plugin_slug) : null,
278
+				));
279
+			} else {
280
+				$this->_template_args['current_db_state'] = null;
281
+				$this->_template_args['next_db_state'] = null;
282
+			}
283
+			$this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_migration_page.template.php';
284
+			$this->_template_args = array_merge(
285
+				$this->_template_args,
286
+				array(
287
+					'show_most_recent_migration'             => $show_most_recent_migration,
288
+					//flag for showing the most recent migration's status and/or errors
289
+					'show_migration_progress'                => $show_migration_progress,
290
+					//flag for showing the option to run migrations and see their progress
291
+					'show_backup_db_text'                    => $show_backup_db_text,
292
+					//flag for showing text telling the user to backup their DB
293
+					'show_maintenance_switch'                => $show_maintenance_switch,
294
+					//flag for showing the option to change maintenance mode between levels 0 and 1
295
+					'script_names'                           => $script_names,
296
+					//array of names of scripts that have run
297
+					'show_continue_current_migration_script' => $show_continue_current_migration_script,
298
+					//flag to change wording to indicating that we're only CONTINUING a migration script (somehow it got interrupted0
299
+					'reset_db_page_link'                     => EE_Admin_Page::add_query_args_and_nonce(array('action' => 'reset_db'),
300
+						EE_MAINTENANCE_ADMIN_URL),
301
+					'data_reset_page'                        => EE_Admin_Page::add_query_args_and_nonce(array('action' => 'data_reset'),
302
+						EE_MAINTENANCE_ADMIN_URL),
303
+					'update_migration_script_page_link'      => EE_Admin_Page::add_query_args_and_nonce(array('action' => 'change_maintenance_level'),
304
+						EE_MAINTENANCE_ADMIN_URL),
305
+					'ultimate_db_state'                      => sprintf(__("EE%s", 'event_espresso'),
306
+						espresso_version()),
307
+				)
308
+			);
309
+			//make sure we have the form fields helper available. It usually is, but sometimes it isn't
310
+			//localize script stuff
311
+			wp_localize_script('ee-maintenance', 'ee_maintenance', array(
312
+				'migrating'                        => esc_html__("Updating Database...", "event_espresso"),
313
+				'next'                             => esc_html__("Next", "event_espresso"),
314
+				'fatal_error'                      => esc_html__("A Fatal Error Has Occurred", "event_espresso"),
315
+				'click_next_when_ready'            => esc_html__("The current Database Update has ended. Click 'next' when ready to proceed",
316
+					"event_espresso"),
317
+				'status_no_more_migration_scripts' => EE_Data_Migration_Manager::status_no_more_migration_scripts,
318
+				'status_fatal_error'               => EE_Data_Migration_Manager::status_fatal_error,
319
+				'status_completed'                 => EE_Data_Migration_Manager::status_completed,
320
+			));
321
+		}
322
+		$this->_template_args['most_recent_migration'] = $most_recent_migration;//the actual most recently ran migration
323
+		//now render the migration options part, and put it in a variable
324
+		$migration_options_template_file = apply_filters(
325
+			'FHEE__ee_migration_page__migration_options_template',
326
+			EE_MAINTENANCE_TEMPLATE_PATH . 'migration_options_from_ee4.template.php'
327
+		);
328
+		$migration_options_html = EEH_Template::display_template($migration_options_template_file, $this->_template_args,true);
329
+		$this->_template_args['migration_options_html'] = $migration_options_html;
330
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template($this->_template_path,
331
+			$this->_template_args, true);
332
+		$this->display_admin_page_with_sidebar();
333
+	}
334
+
335
+
336
+
337
+	/**
338
+	 * returns JSON and executes another step of the currently-executing data migration (called via ajax)
339
+	 */
340
+	public function migration_step()
341
+	{
342
+		$this->_template_args['data'] = EE_Data_Migration_Manager::instance()->response_to_migration_ajax_request();
343
+		$this->_return_json();
344
+	}
345
+
346
+
347
+
348
+	/**
349
+	 * Can be used by js when it notices a response with HTML in it in order
350
+	 * to log the malformed response
351
+	 */
352
+	public function add_error_to_migrations_ran()
353
+	{
354
+		EE_Data_Migration_Manager::instance()->add_error_to_migrations_ran($this->_req_data['message']);
355
+		$this->_template_args['data'] = array('ok' => true);
356
+		$this->_return_json();
357
+	}
358
+
359
+
360
+
361
+	/**
362
+	 * changes the maintenance level, provided there are still no migration scripts that should run
363
+	 */
364
+	public function _change_maintenance_level()
365
+	{
366
+		$new_level = absint($this->_req_data['maintenance_mode_level']);
367
+		if ( ! EE_Data_Migration_Manager::instance()->check_for_applicable_data_migration_scripts()) {
368
+			EE_Maintenance_Mode::instance()->set_maintenance_level($new_level);
369
+			$success = true;
370
+		} else {
371
+			EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old();
372
+			$success = false;
373
+		}
374
+		$this->_redirect_after_action($success, 'Maintenance Mode', esc_html__("Updated", "event_espresso"));
375
+	}
376
+
377
+
378
+
379
+	/**
380
+	 * a tab with options for resetting and/or deleting EE data
381
+	 *
382
+	 * @throws \EE_Error
383
+	 * @throws \DomainException
384
+	 */
385
+	public function _data_reset_and_delete()
386
+	{
387
+		$this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_data_reset_and_delete.template.php';
388
+		$this->_template_args['reset_reservations_button'] = $this->get_action_link_or_button(
389
+			'reset_reservations',
390
+			'reset_reservations',
391
+			array(),
392
+			'button button-primary',
393
+			'',
394
+			false
395
+		);
396
+		$this->_template_args['reset_capabilities_button'] = $this->get_action_link_or_button(
397
+			'reset_capabilities',
398
+			'reset_capabilities',
399
+			array(),
400
+			'button button-primary',
401
+			'',
402
+			false
403
+		);
404
+		$this->_template_args['delete_db_url'] = EE_Admin_Page::add_query_args_and_nonce(
405
+			array('action' => 'delete_db'),
406
+			EE_MAINTENANCE_ADMIN_URL
407
+		);
408
+		$this->_template_args['reset_db_url'] = EE_Admin_Page::add_query_args_and_nonce(
409
+			array('action' => 'reset_db'),
410
+			EE_MAINTENANCE_ADMIN_URL
411
+		);
412
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
413
+			$this->_template_path,
414
+			$this->_template_args,
415
+			true
416
+		);
417
+		$this->display_admin_page_with_sidebar();
418
+	}
419
+
420
+
421
+
422
+	protected function _reset_reservations()
423
+	{
424
+		if(\EED_Ticket_Sales_Monitor::reset_reservation_counts()) {
425
+			EE_Error::add_success(
426
+				__(
427
+					'Ticket and datetime reserved counts have been successfully reset.',
428
+					'event_espresso'
429
+				)
430
+			);
431
+		} else {
432
+			EE_Error::add_success(
433
+				__(
434
+					'Ticket and datetime reserved counts were correct and did not need resetting.',
435
+					'event_espresso'
436
+				)
437
+			);
438
+		}
439
+		$this->_redirect_after_action(true, '', '', array('action' => 'data_reset'), true);
440
+	}
441
+
442
+
443
+
444
+	protected function _reset_capabilities()
445
+	{
446
+		EE_Registry::instance()->CAP->init_caps(true);
447
+		EE_Error::add_success(__('Default Event Espresso capabilities have been restored for all current roles.',
448
+			'event_espresso'));
449
+		$this->_redirect_after_action(false, '', '', array('action' => 'data_reset'), true);
450
+	}
451
+
452
+
453
+
454
+	/**
455
+	 * resets the DMSs so we can attempt to continue migrating after a fatal error
456
+	 * (only a good idea when someone has somehow tried ot fix whatever caused
457
+	 * the fatal error in teh first place)
458
+	 */
459
+	protected function _reattempt_migration()
460
+	{
461
+		EE_Data_Migration_Manager::instance()->reattempt();
462
+		$this->_redirect_after_action(false, '', '', array('action' => 'default'), true);
463
+	}
464
+
465
+
466
+
467
+	/**
468
+	 * shows the big ol' System Information page
469
+	 */
470
+	public function _system_status()
471
+	{
472
+		$this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_system_stati_page.template.php';
473
+		$this->_template_args['system_stati'] = EEM_System_Status::instance()->get_system_stati();
474
+		$this->_template_args['download_system_status_url'] = EE_Admin_Page::add_query_args_and_nonce(
475
+			array(
476
+				'action' => 'download_system_status',
477
+			),
478
+			EE_MAINTENANCE_ADMIN_URL
479
+		);
480
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template($this->_template_path,
481
+			$this->_template_args, true);
482
+		$this->display_admin_page_with_sidebar();
483
+	}
484
+
485
+	/**
486
+	 * Downloads an HTML file of the system status that can be easily stored or emailed
487
+	 */
488
+	public function _download_system_status()
489
+	{
490
+		$status_info = EEM_System_Status::instance()->get_system_stati();
491
+		header( 'Content-Disposition: attachment' );
492
+		header( "Content-Disposition: attachment; filename=system_status_" . sanitize_key( site_url() ) . ".html" );
493
+		echo "<style>table{border:1px solid darkgrey;}td{vertical-align:top}</style>";
494
+		echo "<h1>System Information for " . site_url() . "</h1>";
495
+		echo EEH_Template::layout_array_as_table( $status_info );
496
+		die;
497
+	}
498
+
499
+
500
+
501
+	public function _send_migration_crash_report()
502
+	{
503
+		$from = $this->_req_data['from'];
504
+		$from_name = $this->_req_data['from_name'];
505
+		$body = $this->_req_data['body'];
506
+		try {
507
+			$success = wp_mail(EE_SUPPORT_EMAIL,
508
+				'Migration Crash Report',
509
+				$body . "/r/n<br>" . print_r(EEM_System_Status::instance()->get_system_stati(), true),
510
+				array(
511
+					"from:$from_name<$from>",
512
+					//					'content-type:text/html charset=UTF-8'
513
+				));
514
+		} catch (Exception $e) {
515
+			$success = false;
516
+		}
517
+		$this->_redirect_after_action($success, esc_html__("Migration Crash Report", "event_espresso"),
518
+			esc_html__("sent", "event_espresso"),
519
+			array('success' => $success, 'action' => 'confirm_migration_crash_report_sent'));
520
+	}
521
+
522
+
523
+
524
+	public function _confirm_migration_crash_report_sent()
525
+	{
526
+		try {
527
+			$most_recent_migration = EE_Data_Migration_Manager::instance()->get_last_ran_script(true);
528
+		} catch (EE_Error $e) {
529
+			EE_Data_Migration_Manager::instance()->add_error_to_migrations_ran($e->getMessage());
530
+			//now, just so we can display the page correctly, make a error migration script stage object
531
+			//and also put the error on it. It only persists for the duration of this request
532
+			$most_recent_migration = new EE_DMS_Unknown_1_0_0();
533
+			$most_recent_migration->add_error($e->getMessage());
534
+		}
535
+		$success = $this->_req_data['success'] == '1' ? true : false;
536
+		$this->_template_args['success'] = $success;
537
+		$this->_template_args['most_recent_migration'] = $most_recent_migration;
538
+		$this->_template_args['reset_db_action_url'] = EE_Admin_Page::add_query_args_and_nonce(array('action' => 'reset_db'),
539
+			EE_MAINTENANCE_ADMIN_URL);
540
+		$this->_template_args['reset_db_page_url'] = EE_Admin_Page::add_query_args_and_nonce(array('action' => 'data_reset'),
541
+			EE_MAINTENANCE_ADMIN_URL);
542
+		$this->_template_args['reattempt_action_url'] = EE_Admin_Page::add_query_args_and_nonce(array('action' => 'reattempt_migration'),
543
+			EE_MAINTENANCE_ADMIN_URL);
544
+		$this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_confirm_migration_crash_report_sent.template.php';
545
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template($this->_template_path,
546
+			$this->_template_args, true);
547
+		$this->display_admin_page_with_sidebar();
548
+	}
549
+
550
+
551
+
552
+	/**
553
+	 * Resets the entire EE4 database.
554
+	 * Currently basically only sets up ee4 database for a fresh install- doesn't
555
+	 * actually clean out the old wp options, or cpts (although does erase old ee table data)
556
+	 *
557
+	 * @param boolean $nuke_old_ee4_data controls whether or not we
558
+	 *                                   destroy the old ee4 data, or just try initializing ee4 default data
559
+	 */
560
+	public function _reset_db($nuke_old_ee4_data = true)
561
+	{
562
+		EE_Maintenance_Mode::instance()->set_maintenance_level(EE_Maintenance_Mode::level_0_not_in_maintenance);
563
+		if ($nuke_old_ee4_data) {
564
+			EEH_Activation::delete_all_espresso_cpt_data();
565
+			EEH_Activation::delete_all_espresso_tables_and_data(false);
566
+			EEH_Activation::remove_cron_tasks();
567
+		}
568
+		//make sure when we reset the registry's config that it
569
+		//switches to using the new singleton
570
+		EE_Registry::instance()->CFG = EE_Registry::instance()->CFG->reset(true);
571
+		EE_System::instance()->initialize_db_if_no_migrations_required(true);
572
+		EE_System::instance()->redirect_to_about_ee();
573
+	}
574
+
575
+
576
+
577
+	/**
578
+	 * Deletes ALL EE tables, Records, and Options from the database.
579
+	 */
580
+	public function _delete_db()
581
+	{
582
+		EE_Maintenance_Mode::instance()->set_maintenance_level(EE_Maintenance_Mode::level_0_not_in_maintenance);
583
+		EEH_Activation::delete_all_espresso_cpt_data();
584
+		EEH_Activation::delete_all_espresso_tables_and_data();
585
+		EEH_Activation::remove_cron_tasks();
586
+		EEH_Activation::deactivate_event_espresso();
587
+		wp_safe_redirect(admin_url('plugins.php'));
588
+		exit;
589
+	}
590
+
591
+
592
+
593
+	/**
594
+	 * sets up EE4 to rerun the migrations from ee3 to ee4
595
+	 */
596
+	public function _rerun_migration_from_ee3()
597
+	{
598
+		EE_Maintenance_Mode::instance()->set_maintenance_level(EE_Maintenance_Mode::level_0_not_in_maintenance);
599
+		EEH_Activation::delete_all_espresso_cpt_data();
600
+		EEH_Activation::delete_all_espresso_tables_and_data(false);
601
+		//set the db state to something that will require migrations
602
+		update_option(EE_Data_Migration_Manager::current_database_state, '3.1.36.0');
603
+		EE_Maintenance_Mode::instance()->set_maintenance_level(EE_Maintenance_Mode::level_2_complete_maintenance);
604
+		$this->_redirect_after_action(true, esc_html__("Database", 'event_espresso'), esc_html__("reset", 'event_espresso'));
605
+	}
606
+
607
+
608
+
609
+	//none of the below group are currently used for Gateway Settings
610
+	protected function _add_screen_options()
611
+	{
612
+	}
613
+
614
+
615
+
616
+	protected function _add_feature_pointers()
617
+	{
618
+	}
619
+
620 620
 
621 621
 
622
-    public function admin_init()
623
-    {
624
-    }
625
-
626
-
627
-
628
-    public function admin_notices()
629
-    {
630
-    }
631
-
622
+	public function admin_init()
623
+	{
624
+	}
625
+
626
+
627
+
628
+	public function admin_notices()
629
+	{
630
+	}
631
+
632 632
 
633 633
 
634
-    public function admin_footer_scripts()
635
-    {
636
-    }
634
+	public function admin_footer_scripts()
635
+	{
636
+	}
637 637
 
638 638
 
639 639
 
640
-    public function load_scripts_styles()
641
-    {
642
-        wp_enqueue_script('ee_admin_js');
640
+	public function load_scripts_styles()
641
+	{
642
+		wp_enqueue_script('ee_admin_js');
643 643
 //		wp_enqueue_media();
644 644
 //		wp_enqueue_script('media-upload');
645
-        wp_enqueue_script('ee-maintenance', EE_MAINTENANCE_ASSETS_URL . '/ee-maintenance.js', array('jquery'),
646
-            EVENT_ESPRESSO_VERSION, true);
647
-        wp_register_style('espresso_maintenance', EE_MAINTENANCE_ASSETS_URL . 'ee-maintenance.css', array(),
648
-            EVENT_ESPRESSO_VERSION);
649
-        wp_enqueue_style('espresso_maintenance');
650
-    }
645
+		wp_enqueue_script('ee-maintenance', EE_MAINTENANCE_ASSETS_URL . '/ee-maintenance.js', array('jquery'),
646
+			EVENT_ESPRESSO_VERSION, true);
647
+		wp_register_style('espresso_maintenance', EE_MAINTENANCE_ASSETS_URL . 'ee-maintenance.css', array(),
648
+			EVENT_ESPRESSO_VERSION);
649
+		wp_enqueue_style('espresso_maintenance');
650
+	}
651 651
 
652 652
 
653 653
 
654
-    public function load_scripts_styles_default()
655
-    {
656
-        //styles
654
+	public function load_scripts_styles_default()
655
+	{
656
+		//styles
657 657
 //		wp_enqueue_style('ee-text-links');
658 658
 //		//scripts
659 659
 //		wp_enqueue_script('ee-text-links');
660
-    }
660
+	}
661 661
 
662 662
 
663 663
 
Please login to merge, or discard this patch.
Spacing   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -244,13 +244,13 @@  discard block
 block discarded – undo
244 244
                 && $most_recent_migration->is_broken()
245 245
             )
246 246
         ) {
247
-            $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_migration_was_borked_page.template.php';
247
+            $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH.'ee_migration_was_borked_page.template.php';
248 248
             $this->_template_args['support_url'] = 'http://eventespresso.com/support/forums/';
249 249
             $this->_template_args['next_url'] = EEH_URL::add_query_args_and_nonce(array('action'  => 'confirm_migration_crash_report_sent',
250 250
                                                                                         'success' => '0',
251 251
             ), EE_MAINTENANCE_ADMIN_URL);
252 252
         } elseif ($addons_should_be_upgraded_first) {
253
-            $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_upgrade_addons_before_migrating.template.php';
253
+            $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH.'ee_upgrade_addons_before_migrating.template.php';
254 254
         } else {
255 255
             if ($most_recent_migration
256 256
                 && $most_recent_migration instanceof EE_Data_Migration_Script_Base
@@ -280,7 +280,7 @@  discard block
 block discarded – undo
280 280
                 $this->_template_args['current_db_state'] = null;
281 281
                 $this->_template_args['next_db_state'] = null;
282 282
             }
283
-            $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_migration_page.template.php';
283
+            $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH.'ee_migration_page.template.php';
284 284
             $this->_template_args = array_merge(
285 285
                 $this->_template_args,
286 286
                 array(
@@ -319,13 +319,13 @@  discard block
 block discarded – undo
319 319
                 'status_completed'                 => EE_Data_Migration_Manager::status_completed,
320 320
             ));
321 321
         }
322
-        $this->_template_args['most_recent_migration'] = $most_recent_migration;//the actual most recently ran migration
322
+        $this->_template_args['most_recent_migration'] = $most_recent_migration; //the actual most recently ran migration
323 323
         //now render the migration options part, and put it in a variable
324 324
         $migration_options_template_file = apply_filters(
325 325
             'FHEE__ee_migration_page__migration_options_template',
326
-            EE_MAINTENANCE_TEMPLATE_PATH . 'migration_options_from_ee4.template.php'
326
+            EE_MAINTENANCE_TEMPLATE_PATH.'migration_options_from_ee4.template.php'
327 327
         );
328
-        $migration_options_html = EEH_Template::display_template($migration_options_template_file, $this->_template_args,true);
328
+        $migration_options_html = EEH_Template::display_template($migration_options_template_file, $this->_template_args, true);
329 329
         $this->_template_args['migration_options_html'] = $migration_options_html;
330 330
         $this->_template_args['admin_page_content'] = EEH_Template::display_template($this->_template_path,
331 331
             $this->_template_args, true);
@@ -384,7 +384,7 @@  discard block
 block discarded – undo
384 384
      */
385 385
     public function _data_reset_and_delete()
386 386
     {
387
-        $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_data_reset_and_delete.template.php';
387
+        $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH.'ee_data_reset_and_delete.template.php';
388 388
         $this->_template_args['reset_reservations_button'] = $this->get_action_link_or_button(
389 389
             'reset_reservations',
390 390
             'reset_reservations',
@@ -421,7 +421,7 @@  discard block
 block discarded – undo
421 421
 
422 422
     protected function _reset_reservations()
423 423
     {
424
-        if(\EED_Ticket_Sales_Monitor::reset_reservation_counts()) {
424
+        if (\EED_Ticket_Sales_Monitor::reset_reservation_counts()) {
425 425
             EE_Error::add_success(
426 426
                 __(
427 427
                     'Ticket and datetime reserved counts have been successfully reset.',
@@ -469,7 +469,7 @@  discard block
 block discarded – undo
469 469
      */
470 470
     public function _system_status()
471 471
     {
472
-        $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_system_stati_page.template.php';
472
+        $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH.'ee_system_stati_page.template.php';
473 473
         $this->_template_args['system_stati'] = EEM_System_Status::instance()->get_system_stati();
474 474
         $this->_template_args['download_system_status_url'] = EE_Admin_Page::add_query_args_and_nonce(
475 475
             array(
@@ -488,11 +488,11 @@  discard block
 block discarded – undo
488 488
     public function _download_system_status()
489 489
     {
490 490
         $status_info = EEM_System_Status::instance()->get_system_stati();
491
-        header( 'Content-Disposition: attachment' );
492
-        header( "Content-Disposition: attachment; filename=system_status_" . sanitize_key( site_url() ) . ".html" );
491
+        header('Content-Disposition: attachment');
492
+        header("Content-Disposition: attachment; filename=system_status_".sanitize_key(site_url()).".html");
493 493
         echo "<style>table{border:1px solid darkgrey;}td{vertical-align:top}</style>";
494
-        echo "<h1>System Information for " . site_url() . "</h1>";
495
-        echo EEH_Template::layout_array_as_table( $status_info );
494
+        echo "<h1>System Information for ".site_url()."</h1>";
495
+        echo EEH_Template::layout_array_as_table($status_info);
496 496
         die;
497 497
     }
498 498
 
@@ -506,7 +506,7 @@  discard block
 block discarded – undo
506 506
         try {
507 507
             $success = wp_mail(EE_SUPPORT_EMAIL,
508 508
                 'Migration Crash Report',
509
-                $body . "/r/n<br>" . print_r(EEM_System_Status::instance()->get_system_stati(), true),
509
+                $body."/r/n<br>".print_r(EEM_System_Status::instance()->get_system_stati(), true),
510 510
                 array(
511 511
                     "from:$from_name<$from>",
512 512
                     //					'content-type:text/html charset=UTF-8'
@@ -541,7 +541,7 @@  discard block
 block discarded – undo
541 541
             EE_MAINTENANCE_ADMIN_URL);
542 542
         $this->_template_args['reattempt_action_url'] = EE_Admin_Page::add_query_args_and_nonce(array('action' => 'reattempt_migration'),
543 543
             EE_MAINTENANCE_ADMIN_URL);
544
-        $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_confirm_migration_crash_report_sent.template.php';
544
+        $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH.'ee_confirm_migration_crash_report_sent.template.php';
545 545
         $this->_template_args['admin_page_content'] = EEH_Template::display_template($this->_template_path,
546 546
             $this->_template_args, true);
547 547
         $this->display_admin_page_with_sidebar();
@@ -642,9 +642,9 @@  discard block
 block discarded – undo
642 642
         wp_enqueue_script('ee_admin_js');
643 643
 //		wp_enqueue_media();
644 644
 //		wp_enqueue_script('media-upload');
645
-        wp_enqueue_script('ee-maintenance', EE_MAINTENANCE_ASSETS_URL . '/ee-maintenance.js', array('jquery'),
645
+        wp_enqueue_script('ee-maintenance', EE_MAINTENANCE_ASSETS_URL.'/ee-maintenance.js', array('jquery'),
646 646
             EVENT_ESPRESSO_VERSION, true);
647
-        wp_register_style('espresso_maintenance', EE_MAINTENANCE_ASSETS_URL . 'ee-maintenance.css', array(),
647
+        wp_register_style('espresso_maintenance', EE_MAINTENANCE_ASSETS_URL.'ee-maintenance.css', array(),
648 648
             EVENT_ESPRESSO_VERSION);
649 649
         wp_enqueue_style('espresso_maintenance');
650 650
     }
Please login to merge, or discard this patch.
core/libraries/messages/EE_Message_Resource_Manager.lib.php 2 patches
Indentation   +1016 added lines, -1016 removed lines patch added patch discarded remove patch
@@ -1,7 +1,7 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3 3
 if (! defined('EVENT_ESPRESSO_VERSION')) {
4
-    exit('No direct script access allowed');
4
+	exit('No direct script access allowed');
5 5
 }
6 6
 
7 7
 
@@ -17,1021 +17,1021 @@  discard block
 block discarded – undo
17 17
 class EE_Message_Resource_Manager
18 18
 {
19 19
 
20
-    /**
21
-     * @type boolean $_initialized
22
-     */
23
-    protected $_initialized = false;
24
-
25
-    /**
26
-     * @type EE_Messenger_Collection $_messenger_collection_loader
27
-     */
28
-    protected $_messenger_collection_loader;
29
-
30
-    /**
31
-     * @type EE_Message_Type_Collection $_message_type_collection_loader
32
-     */
33
-    protected $_message_type_collection_loader;
34
-
35
-    /**
36
-     * @type EEM_Message_Template_Group $_message_template_group_model
37
-     */
38
-    protected $_message_template_group_model;
39
-
40
-    /**
41
-     * @type EE_messenger[]
42
-     */
43
-    protected $_installed_messengers = array();
44
-
45
-    /**
46
-     * @type EE_message_type[]
47
-     */
48
-    protected $_installed_message_types = array();
49
-
50
-    /**
51
-     * Array of active messengers.
52
-     * Format is this:
53
-     * array(
54
-     *      'messenger_name' => EE_messenger
55
-     * )
56
-     *
57
-     * @type EE_messenger[]
58
-     */
59
-    protected $_active_messengers = array();
60
-
61
-    /**
62
-     * Formatted array of active message types grouped per messenger.
63
-     * Format is this:
64
-     * array(
65
-     *      'messenger_name' => array(
66
-     *          'settings' => array(
67
-     *              '{messenger_name}-message_types' => array(
68
-     *                  'message_type_name' => array() //variable array of settings corresponding to message type.
69
-     *              )
70
-     *          )
71
-     *      )
72
-     * )
73
-     *
74
-     * @type array
75
-     */
76
-    protected $_active_message_types = array();
77
-
78
-
79
-    /**
80
-     * This holds the array of messengers and their corresponding message types that have
81
-     * been activated on a site at some point.  This is an important record that helps the messages system
82
-     * not accidentally reactivate something that was intentionally deactivated by a user.
83
-     *
84
-     * @type array
85
-     */
86
-    protected $_has_activated_messengers_and_message_types = array();
87
-
88
-    /**
89
-     * An array of unique message type contexts across all active message types.
90
-     * The array will be indexed by either 'slugs' or 'all'.
91
-     * The slugs index contains an array indexed by unique context slugs with the latest label representation for that
92
-     * slug. array(
93
-     *      'context_slug' => 'localized label for context obtained from latest message type in the loop'.
94
-     * );
95
-     * The all index returns an array in this format:
96
-     * array(
97
-     *      'message_type_name' => array(
98
-     *          'context_slug' => array(
99
-     *              'label' => 'localized label for context',
100
-     *              'description' => 'localized description for context'
101
-     *          )
102
-     *      )
103
-     * );
104
-     *
105
-     * @type array
106
-     */
107
-    protected $_contexts = array();
108
-
109
-
110
-    /**
111
-     * EE_Message_Resource_Manager constructor.
112
-     *
113
-     * @param \EE_Messenger_Collection_Loader    $Messenger_Collection_Loader
114
-     * @param \EE_Message_Type_Collection_Loader $Message_Type_Collection_Loader
115
-     * @param \EEM_Message_Template_Group        $Message_Template_Group_Model
116
-     */
117
-    function __construct(
118
-        EE_Messenger_Collection_Loader $Messenger_Collection_Loader,
119
-        EE_Message_Type_Collection_Loader $Message_Type_Collection_Loader,
120
-        EEM_Message_Template_Group $Message_Template_Group_Model
121
-    ) {
122
-        $this->_messenger_collection_loader    = $Messenger_Collection_Loader;
123
-        $this->_message_type_collection_loader = $Message_Type_Collection_Loader;
124
-        $this->_message_template_group_model   = $Message_Template_Group_Model;
125
-    }
126
-
127
-
128
-    /**
129
-     * @return void
130
-     */
131
-    protected function _initialize_collections()
132
-    {
133
-        if ($this->_initialized) {
134
-            return;
135
-        }
136
-        $this->_initialized = true;
137
-        $this->_messenger_collection_loader->load_messengers_from_folder();
138
-        $this->_message_type_collection_loader->load_message_types_from_folder();
139
-        $this->get_has_activated_messengers_option(true);
140
-        $this->_set_active_messengers_and_message_types();
141
-    }
142
-
143
-
144
-    /**
145
-     * @return EE_Messenger_Collection
146
-     */
147
-    public function messenger_collection()
148
-    {
149
-        $this->_initialize_collections();
150
-        return $this->_messenger_collection_loader->messenger_collection();
151
-    }
152
-
153
-
154
-    /**
155
-     * @return EE_messenger[]
156
-     */
157
-    public function active_messengers()
158
-    {
159
-        $this->_initialize_collections();
160
-        return $this->_active_messengers;
161
-    }
162
-
163
-
164
-    /**
165
-     * @param string $messenger_name
166
-     * @return \EE_messenger
167
-     */
168
-    public function get_messenger($messenger_name)
169
-    {
170
-        return $this->messenger_collection()->get_by_info($messenger_name);
171
-    }
172
-
173
-
174
-    /**
175
-     * This returns the corresponding EE_messenger object for the given string if it is active.
176
-     *
177
-     * @param string $messenger
178
-     * @return EE_messenger | null
179
-     */
180
-    public function get_active_messenger($messenger)
181
-    {
182
-        $this->_initialize_collections();
183
-        return ! empty($this->_active_messengers[$messenger]) ? $this->_active_messengers[$messenger] : null;
184
-    }
185
-
186
-
187
-    /**
188
-     * @return \EE_messenger[]
189
-     */
190
-    public function installed_messengers()
191
-    {
192
-        if (empty($this->_installed_messengers)) {
193
-            $this->_installed_messengers = array();
194
-            $this->messenger_collection()->rewind();
195
-            while ($this->messenger_collection()->valid()) {
196
-                $this->_installed_messengers[$this->messenger_collection()->current()->name] = $this->messenger_collection()->current();
197
-                $this->messenger_collection()->next();
198
-            }
199
-        }
200
-        return $this->_installed_messengers;
201
-    }
202
-
203
-
204
-    /**
205
-     * @param string $messenger_name
206
-     * @return \EE_messenger
207
-     * @throws \EE_Error
208
-     */
209
-    public function valid_messenger($messenger_name)
210
-    {
211
-        $messenger = $this->get_messenger($messenger_name);
212
-        if ($messenger instanceof EE_messenger) {
213
-            return $messenger;
214
-        }
215
-        throw new EE_Error(
216
-            sprintf(
217
-                __('The "%1$s" messenger is either invalid or not installed', 'event_espresso'),
218
-                $messenger_name
219
-            )
220
-        );
221
-    }
222
-
223
-
224
-    /**
225
-     * @return EE_Message_Type_Collection
226
-     */
227
-    public function message_type_collection()
228
-    {
229
-        $this->_initialize_collections();
230
-        return $this->_message_type_collection_loader->message_type_collection();
231
-    }
232
-
233
-
234
-    /**
235
-     * @return array
236
-     */
237
-    public function active_message_types()
238
-    {
239
-        $this->_initialize_collections();
240
-        return $this->_active_message_types;
241
-    }
242
-
243
-
244
-    /**
245
-     * @param string $message_type_name
246
-     * @return \EE_message_type
247
-     */
248
-    public function get_message_type($message_type_name)
249
-    {
250
-        return $this->message_type_collection()->get_by_info($message_type_name);
251
-    }
252
-
253
-
254
-    /**
255
-     * This returns the EE_message_type from the active message types array ( if present );
256
-     *
257
-     * @param string $messenger_name
258
-     * @param string $message_type_name
259
-     * @return \EE_message_type|null
260
-     */
261
-    public function get_active_message_type_for_messenger($messenger_name, $message_type_name)
262
-    {
263
-        return $this->is_message_type_active_for_messenger($messenger_name, $message_type_name)
264
-            ? $this->get_message_type($message_type_name)
265
-            : null;
266
-    }
267
-
268
-
269
-    /**
270
-     * Returns whether the given message type is active for the given messenger.
271
-     *
272
-     * @param string $messenger_name
273
-     * @param string $message_type_name
274
-     * @return bool
275
-     */
276
-    public function is_message_type_active_for_messenger($messenger_name, $message_type_name)
277
-    {
278
-        $this->_initialize_collections();
279
-        return ! empty($this->_active_message_types[$messenger_name]['settings'][$messenger_name . '-message_types'][$message_type_name]);
280
-    }
281
-
282
-
283
-    /**
284
-     * Returns whether the given messenger is active.
285
-     *
286
-     * @param string $messenger_name the name of the messenger to check if active.
287
-     * @return bool
288
-     */
289
-    public function is_messenger_active($messenger_name)
290
-    {
291
-        $this->_initialize_collections();
292
-        return ! empty($this->_active_message_types[$messenger_name]);
293
-    }
294
-
295
-
296
-    /**
297
-     * This returns any settings that might be on a message type for a messenger
298
-     *
299
-     * @param string $messenger_name    The slug of the messenger
300
-     * @param string $message_type_name The slug of the message type getting the settings for.
301
-     * @return array
302
-     */
303
-    public function get_message_type_settings_for_messenger($messenger_name, $message_type_name)
304
-    {
305
-        $settings = array();
306
-        if ($this->is_message_type_active_for_messenger($messenger_name, $message_type_name)) {
307
-            $settings = isset($this->_active_message_types[$messenger_name]['settings'][$messenger_name . '-message_types'][$message_type_name]['settings'])
308
-                ? $this->_active_message_types[$messenger_name]['settings'][$messenger_name . '-message_types'][$message_type_name]['settings']
309
-                : array();
310
-        }
311
-        return $settings;
312
-    }
313
-
314
-
315
-    /**
316
-     * Returns whether the given messenger name has active message types on it.
317
-     * Infers whether the messenger is active or not as well.
318
-     *
319
-     * @param string $messenger_name
320
-     * @return bool
321
-     */
322
-    public function messenger_has_active_message_types($messenger_name)
323
-    {
324
-        $this->_initialize_collections();
325
-        return
326
-            ! empty($this->_active_message_types[$messenger_name])
327
-            && ! empty($this->_active_message_types[$messenger_name]['settings'][$messenger_name . '-message_types']);
328
-    }
329
-
330
-
331
-    /**
332
-     * This checks the _active_message_types property for any active message types
333
-     * that are present for the given messenger and returns them.
334
-     *
335
-     * @since 4.9.0
336
-     * @param string $messenger_name The messenger being checked
337
-     * @return EE_message_type[]|array    (empty array if no active_message_types)
338
-     */
339
-    public function get_active_message_types_for_messenger($messenger_name)
340
-    {
341
-        $message_types = array();
342
-        if (! $this->messenger_has_active_message_types($messenger_name)) {
343
-            return $message_types;
344
-        }
345
-        $installed_message_types = $this->installed_message_types();
346
-        foreach ($installed_message_types as $message_type_name => $message_type) {
347
-            if ($this->is_message_type_active_for_messenger($messenger_name, $message_type_name)) {
348
-                $message_types[$message_type_name] = $message_type;
349
-            }
350
-        }
351
-        return $message_types;
352
-    }
353
-
354
-
355
-    /**
356
-     * This does NOT return the _active_message_types property but
357
-     * simply returns an array of active message type names from that property.
358
-     * (The _active_message_types property is indexed by messenger and active message_types per messenger).
359
-     *
360
-     * @return array message_type references (string)
361
-     */
362
-    public function list_of_active_message_types()
363
-    {
364
-        $active_message_type_names = array();
365
-        $this->_initialize_collections();
366
-        foreach ($this->_active_message_types as $messenger => $messenger_settings) {
367
-            if (! isset($messenger_settings['settings'][$messenger . '-message_types'])) {
368
-                continue;
369
-            }
370
-            foreach ($messenger_settings['settings'][$messenger . '-message_types'] as $message_type_name => $message_type_config) {
371
-                if (! in_array($message_type_name, $active_message_type_names)) {
372
-                    $active_message_type_names[] = $message_type_name;
373
-                }
374
-            }
375
-        }
376
-        return $active_message_type_names;
377
-    }
378
-
379
-
380
-    /**
381
-     * Same as list_of_active_message_types() except this returns actual EE_message_type objects
382
-     *
383
-     * @since 4.9.0
384
-     * @return \EE_message_type[]
385
-     */
386
-    public function get_active_message_type_objects()
387
-    {
388
-        $active_message_types      = array();
389
-        $installed_message_types   = $this->installed_message_types();
390
-        $active_message_type_names = $this->list_of_active_message_types();
391
-        foreach ($active_message_type_names as $active_message_type_name) {
392
-            if (isset($installed_message_types[$active_message_type_name])) {
393
-                $active_message_types[$active_message_type_name] = $installed_message_types[$active_message_type_name];
394
-            }
395
-        }
396
-        return $active_message_types;
397
-    }
398
-
399
-
400
-    /**
401
-     * @return \EE_message_type[]
402
-     */
403
-    public function installed_message_types()
404
-    {
405
-        if (empty($this->_installed_message_types)) {
406
-            $this->message_type_collection()->rewind();
407
-            while ($this->message_type_collection()->valid()) {
408
-                $this->_installed_message_types[$this->message_type_collection()->current()->name] = $this->message_type_collection()->current();
409
-                $this->message_type_collection()->next();
410
-            }
411
-        }
412
-        return $this->_installed_message_types;
413
-    }
414
-
415
-
416
-    /**
417
-     * @param string $message_type_name
418
-     * @return \EE_message_type
419
-     * @throws \EE_Error
420
-     */
421
-    public function valid_message_type($message_type_name)
422
-    {
423
-        $message_type = $this->get_message_type($message_type_name);
424
-        if ($message_type instanceof EE_message_type) {
425
-            return $message_type;
426
-        }
427
-        throw new EE_Error(
428
-            sprintf(
429
-                __('The "%1$s" message type is either invalid or not installed', 'event_espresso'),
430
-                $message_type_name
431
-            )
432
-        );
433
-    }
434
-
435
-
436
-    /**
437
-     * valid_message_type_for_messenger
438
-     *
439
-     * @param EE_messenger $messenger
440
-     * @param string       $message_type_name
441
-     * @return boolean
442
-     * @throws \EE_Error
443
-     */
444
-    public function valid_message_type_for_messenger(EE_messenger $messenger, $message_type_name)
445
-    {
446
-        $valid_message_types = $messenger->get_valid_message_types();
447
-        if (! in_array($message_type_name, $valid_message_types)) {
448
-            throw new EE_Error(
449
-                sprintf(
450
-                    __(
451
-                        '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.',
452
-                        'event_espresso'
453
-                    ),
454
-                    $message_type_name,
455
-                    __METHOD__,
456
-                    $messenger->name
457
-                )
458
-            );
459
-        }
460
-        return true;
461
-    }
462
-
463
-
464
-    /**
465
-     * Used to return active messengers array stored in the wp options table.
466
-     * If no value is present in the option then an empty array is returned.
467
-     *
468
-     * @param   bool $reset     If true then we ignore whether the option is cached on the _active_message_types
469
-     *                          property and pull directly from the db.  Otherwise whatever is currently on the
470
-     *                          $_active_message_types property is pulled.
471
-     * @return array
472
-     */
473
-    public function get_active_messengers_option($reset = false)
474
-    {
475
-        if ($reset) {
476
-            $this->_active_message_types = get_option('ee_active_messengers', array());
477
-        }
478
-        return $this->_active_message_types;
479
-    }
480
-
481
-
482
-    /**
483
-     * Used to update the active messengers array stored in the wp options table.
484
-     *
485
-     * @param array $active_messenger_settings Incoming data to save.  If empty, then the internal cached property
486
-     *                                         representing this data is used.
487
-     * @return bool FALSE if not updated, TRUE if updated.
488
-     */
489
-    public function update_active_messengers_option($active_messenger_settings = array())
490
-    {
491
-        $active_messenger_settings = empty($active_messenger_settings) ? $this->_active_message_types : $active_messenger_settings;
492
-        //make sure _active_message_types is updated (this is the internal cache for the settings).
493
-        $this->_active_message_types = $active_messenger_settings;
494
-        return update_option('ee_active_messengers', $active_messenger_settings);
495
-    }
496
-
497
-
498
-    /**
499
-     * Used to return active messengers array stored in the wp options table.
500
-     * If no value is present in the option then an empty array is returned.
501
-     * The value is cached on the $_has_activated_messengers_and_message_types property for future calls.
502
-     *
503
-     * @param   bool $reset Used to indicate that any cached value should be ignored.
504
-     * @return array
505
-     */
506
-    public function get_has_activated_messengers_option($reset = false)
507
-    {
508
-        if ($reset || empty($this->_has_activated_messengers_and_message_types)) {
509
-            $this->_has_activated_messengers_and_message_types = get_option('ee_has_activated_messenger', array());
510
-        }
511
-        return $this->_has_activated_messengers_and_message_types;
512
-    }
513
-
514
-
515
-    /**
516
-     * Used to update the active messengers array stored in the wp options table.
517
-     *
518
-     * @param array $has_activated_messengers Incoming data to save.  If empty, then the internal cached property
519
-     *                                        representing this data is used.
520
-     * @return bool FALSE if not updated, TRUE if updated.
521
-     */
522
-    public function update_has_activated_messengers_option($has_activated_messengers = array())
523
-    {
524
-        //make sure the option has been retrieved from first so we don't overwrite it accidentally.
525
-        if (empty($has_activated_messengers) && empty($this->_has_activated_messengers_and_message_types)) {
526
-            $this->get_has_activated_messengers_option();
527
-        }
528
-        $has_activated_messengers = empty($has_activated_messengers)
529
-            ? $this->_has_activated_messengers_and_message_types
530
-            : $has_activated_messengers;
531
-        return update_option('ee_has_activated_messenger', $has_activated_messengers);
532
-    }
533
-
534
-
535
-    /**
536
-     * wrapper for _set_active_messengers_and_message_types()
537
-     */
538
-    public function reset_active_messengers_and_message_types()
539
-    {
540
-        $this->_set_active_messengers_and_message_types();
541
-    }
542
-
543
-
544
-    /**
545
-     * Generate list of active messengers and message types from collection.
546
-     * This sets up the active messengers from what is present in the database.
547
-     */
548
-    protected function _set_active_messengers_and_message_types()
549
-    {
550
-        //echo "\n\n " . __LINE__ . ") " . __METHOD__ . "() \n";
551
-        // list of activated messengers as set via the admin
552
-        // note calling `get_active_messengers_options` also initializes the _active_message_types property.
553
-        $this->get_active_messengers_option(true);
554
-        $this->ensure_messengers_are_active(array(), false, true);
555
-        $this->update_active_messengers_option();
556
-        $this->update_has_activated_messengers_option();
557
-    }
558
-
559
-
560
-    /**
561
-     * Ensures that the specified messenger is currently active.
562
-     * If not, activates it and its default message types.
563
-     *
564
-     * @param string $messenger_name
565
-     * @param bool   $update_option Whether to update the option in the db or not.
566
-     * @return boolean true if either already active or successfully activated.
567
-     */
568
-    public function ensure_messenger_is_active($messenger_name, $update_option = true)
569
-    {
570
-        if (! isset($this->_active_messengers[$messenger_name])) {
571
-            try {
572
-                $this->activate_messenger($messenger_name, array(), $update_option);
573
-            } catch (EE_Error $e) {
574
-                EE_Error::add_error(
575
-                    $e->getMessage(),
576
-                    __FILE__,
577
-                    __FUNCTION__,
578
-                    __LINE__
579
-                );
580
-                return false;
581
-            }
582
-        }
583
-        return true;
584
-    }
585
-
586
-
587
-    /**
588
-     * This ensures the given array of messenger names is active in the system.
589
-     * Note, this method will not activate any NEW message types for the messenger when it is called. Instead,
590
-     * it will automatically activate the default message types for the messenger if its not active.
591
-     *
592
-     * @param array $messenger_names  Array of messenger names for messengers to be activated.  If an empty array
593
-     *                                (default) then will attempt to set the active messengers from the
594
-     *                                activated_messengers option
595
-     *                                (stored in $_active_message_types property).
596
-     * @param bool  $update_option    Whether to update the related active messengers option.
597
-     * @param bool  $verify           Whether to verify the messengers are installed before activating. Note if this is
598
-     *                                set to true and a messenger is indicated as active, but is NOT installed, then it
599
-     *                                will automatically be deactivated.
600
-     */
601
-    public function ensure_messengers_are_active($messenger_names = array(), $update_option = true, $verify = false)
602
-    {
603
-        $messenger_names = empty($messenger_names) ? array_keys($this->_active_message_types) : $messenger_names;
604
-
605
-        $not_installed = array();
606
-        foreach ($messenger_names as $messenger_name) {
607
-            if ($verify && ! $this->messenger_collection()->has_by_name($messenger_name)) {
608
-                $not_installed[] = $messenger_name;
609
-                $this->deactivate_messenger($messenger_name);
610
-                continue;
611
-            }
612
-            $this->ensure_messenger_is_active($messenger_name, $update_option);
613
-        }
614
-
615
-        if (! empty($not_installed_messenger)) {
616
-            EE_Error::add_error(
617
-                sprintf(
618
-                    __('The following messengers are either not installed or are invalid:%1$s %2$s', 'event_espresso'),
619
-                    '<br />',
620
-                    implode(', ', $not_installed_messenger)
621
-                ),
622
-                __FILE__, __FUNCTION__, __LINE__
623
-            );
624
-        }
625
-    }
626
-
627
-
628
-    /**
629
-     * Ensures that the specified message type for the given messenger is currently active, if not activates it.
630
-     * This ALSO ensures that the given messenger is active as well!
631
-     *
632
-     * @param string $message_type_name message type name.
633
-     * @param        $messenger_name
634
-     * @param bool   $update_option     Whether to update the option in the db or not.
635
-     * @return bool  Returns true if already is active or if was activated successfully.
636
-     * @throws \EE_Error
637
-     */
638
-    public function ensure_message_type_is_active($message_type_name, $messenger_name, $update_option = true)
639
-    {
640
-        // grab the messenger to work with.
641
-        $messenger = $this->valid_messenger($messenger_name);
642
-        if ($this->valid_message_type_for_messenger($messenger, $message_type_name)) {
643
-            //ensure messenger is active (that's an inherent coupling between active message types and the
644
-            //messenger they are being activated for.
645
-            try {
646
-                if (! $this->is_message_type_active_for_messenger($messenger_name, $message_type_name)) {
647
-                    //all is good so let's just get it active
648
-                    $this->activate_messenger($messenger_name, array($message_type_name), $update_option);
649
-                }
650
-            } catch (EE_Error $e) {
651
-                EE_Error::add_error(
652
-                    $e->getMessage(),
653
-                    __FILE__,
654
-                    __FUNCTION__,
655
-                    __LINE__
656
-                );
657
-                return false;
658
-            }
659
-        }
660
-        return true;
661
-    }
662
-
663
-
664
-    /**
665
-     * This is a wrapper for `ensure_message_type_is_active` that will handle ensuring multiple message types for a
666
-     * messenger are active in one go.
667
-     *
668
-     * @param array  $message_type_names Array of message type names to ensure are active.
669
-     * @param string $messenger_name     The name of the messenger that the message types are to be activated on.
670
-     * @param bool   $update_option      Whether to persist the activation to the database or not (default true).
671
-     */
672
-    public function ensure_message_types_are_active($message_type_names, $messenger_name, $update_option = true)
673
-    {
674
-        $message_type_names = (array)$message_type_names;
675
-        foreach ($message_type_names as $message_type_name) {
676
-            // note, intentionally not updating option here because we're in a loop.
677
-            // We'll follow the instructions of the incoming $update_option argument after the loop.
678
-            $this->ensure_message_type_is_active($message_type_name, $messenger_name, false);
679
-        }
680
-        if ($update_option) {
681
-            $this->update_active_messengers_option();
682
-            $this->update_has_activated_messengers_option();
683
-        }
684
-    }
685
-
686
-
687
-    /**
688
-     * Activates the specified messenger.
689
-     *
690
-     * @param string $messenger_name
691
-     * @param array  $message_type_names        An array of message type names to activate with this messenger.
692
-     *                                          If included we do NOT setup the default message types
693
-     *                                          (assuming they are already setup.)
694
-     * @param bool   $update_active_messengers_option
695
-     * @return array of generated templates
696
-     * @throws \EE_Error
697
-     */
698
-    public function activate_messenger(
699
-        $messenger_name,
700
-        $message_type_names = array(),
701
-        $update_active_messengers_option = true
702
-    ) {
703
-        $templates = array();
704
-        // grab the messenger to work with.
705
-        $messenger = $this->messenger_collection()->get_by_info($messenger_name);
706
-        // it's inactive. Activate it.
707
-        if ($messenger instanceof EE_messenger) {
708
-            $this->_active_messengers[$messenger->name] = $messenger;
709
-            //activate incoming message types set to be activated with messenger.
710
-            $message_type_names = $this->_activate_message_types($messenger, $message_type_names);
711
-            // setup any initial settings for the messenger if necessary.
712
-            $this->add_settings_for_messenger($messenger->name);
713
-            if ($update_active_messengers_option) {
714
-                $this->update_active_messengers_option();
715
-                $this->update_has_activated_messengers_option();
716
-            }
717
-            //generate new templates if necessary and ensure all related templates that are already in the database are
718
-            //marked active.  Note, this will also deactivate a message type for a messenger if the template
719
-            //cannot be successfully created during its attempt (only happens for global template attempts).
720
-            if (! empty($message_type_names)) {
721
-                $templates = EEH_MSG_Template::generate_new_templates($messenger->name, $message_type_names, 0, true);
722
-                EEH_MSG_Template::update_to_active(array($messenger->name), $message_type_names);
723
-            }
724
-        }
725
-        return $templates;
726
-    }
727
-
728
-
729
-    /**
730
-     * Activates given message types for the given EE_messenger object.
731
-     * Note: (very important) This method does not persist the activation to the database.
732
-     * See code implementing this method in this class for examples of how to persist.
733
-     *
734
-     * @param \EE_messenger $messenger
735
-     * @param  array        $message_type_names
736
-     * @return array
737
-     */
738
-    protected function _activate_message_types(EE_messenger $messenger, $message_type_names = array())
739
-    {
740
-        //If $message_type_names is empty, AND $this->_active_message_types is empty, then that means
741
-        //things have never been initialized (which should happen on EEH_Activation::generate_message_templates).
742
-        //So ONLY then do we need to actually grab defaults and cycle through them.  Otherwise we
743
-        //only override _active_message_types when an explicit array of $message_type_names has been provided.
744
-        $message_type_names = empty($message_type_names) && ! isset($this->_active_message_types[$messenger->name])
745
-            ? $messenger->get_default_message_types()
746
-            : (array)$message_type_names;
747
-
748
-        //now we ALWAYS need to make sure that the messenger is active for the message types we're activating!
749
-        if (! isset($this->_active_message_types[$messenger->name])) {
750
-            $this->_active_message_types[$messenger->name]['settings'] = array();
751
-        }
752
-
753
-        if ($message_type_names) {
754
-            // cycle thru message types
755
-            foreach ($message_type_names as $message_type_name) {
756
-                //only register the message type as active IF it isn't already active
757
-                //and if its actually installed.
758
-                if (
759
-                ! $this->is_message_type_active_for_messenger($messenger->name, $message_type_name)
760
-                ) {
761
-                    $this->add_settings_for_message_type($messenger->name, $message_type_name);
762
-                    $this->_set_messenger_has_activated_message_type(
763
-                        $messenger,
764
-                        $message_type_name
765
-                    );
766
-                }
767
-            }
768
-        }
769
-        return $message_type_names;
770
-    }
771
-
772
-
773
-    /**
774
-     * add_settings_for_message_type
775
-     * NOTE This does NOT automatically persist any settings to the db.  Client code should call
776
-     * $this->update_active_messengers_option to persist.
777
-     *
778
-     * @param  string $messenger_name    The name of the messenger adding the settings for
779
-     * @param  string $message_type_name The name of the message type adding the settings for
780
-     * @param  array  $new_settings      Any new settings being set for the message type and messenger
781
-     */
782
-    public function add_settings_for_message_type($messenger_name, $message_type_name, $new_settings = array())
783
-    {
784
-        // get installed message type from collection
785
-        $message_type      = $this->message_type_collection()->get_by_info($message_type_name);
786
-        $existing_settings = $this->get_message_type_settings_for_messenger($messenger_name, $message_type_name);
787
-        //we need to setup any initial settings for message types
788
-        if ($message_type instanceof EE_message_type) {
789
-            $default_settings = $message_type->get_admin_settings_fields();
790
-            foreach ($default_settings as $field => $values) {
791
-                if (isset($new_settings[$field])) {
792
-                    $existing_settings[$field] = $new_settings[$field];
793
-                    continue;
794
-                }
795
-                if (! isset($existing_settings[$field])) {
796
-                    $existing_settings[$field] = $values['default'];
797
-                }
798
-            }
799
-        }
800
-        $this->_active_message_types[$messenger_name]['settings'][$messenger_name . '-message_types'][$message_type_name]['settings'] = $existing_settings;
801
-    }
802
-
803
-
804
-    /**
805
-     * Updates the internal cached _has_activated_messengers_and_message_types property with the given messenger
806
-     * and message type.
807
-     *
808
-     * @access protected
809
-     * @param \EE_messenger $messenger
810
-     * @param string        $message_type_name
811
-     */
812
-    protected function _set_messenger_has_activated_message_type(EE_messenger $messenger, $message_type_name)
813
-    {
814
-
815
-        //if _has_activated_messengers_and_message_types is empty then lets ensure its initialized
816
-        if (empty($this->_has_activated_messengers_and_message_types)) {
817
-            $this->get_has_activated_messengers_option();
818
-        }
819
-
820
-        // make sure this messenger has a record in the has_activated array
821
-        if (! isset($this->_has_activated_messengers_and_message_types[$messenger->name])) {
822
-            $this->_has_activated_messengers_and_message_types[$messenger->name] = array();
823
-        }
824
-        // check if message type has already been added
825
-        if (! in_array($message_type_name, $this->_has_activated_messengers_and_message_types[$messenger->name])) {
826
-            $this->_has_activated_messengers_and_message_types[$messenger->name][] = $message_type_name;
827
-        }
828
-    }
829
-
830
-
831
-    /**
832
-     * add_settings_for_messenger
833
-     * NOTE This does NOT automatically persist any settings to the db.  Client code should call
834
-     * $this->update_active_messengers_option to persist.
835
-     *
836
-     * @param string $messenger_name The name of the messenger the settings is being added for.
837
-     * @param array  $new_settings   An array of settings to update the existing settings.
838
-     */
839
-    public function add_settings_for_messenger($messenger_name, $new_settings = array())
840
-    {
841
-        $messenger = $this->get_messenger($messenger_name);
842
-        if ($messenger instanceof EE_messenger) {
843
-            $msgr_settings = $messenger->get_admin_settings_fields();
844
-            if (! empty($msgr_settings)) {
845
-                foreach ($msgr_settings as $field => $value) {
846
-                    //is there a new setting for this?
847
-                    if (isset($new_settings[$field])) {
848
-                        $this->_active_message_types[$messenger->name]['settings'][$field] = $new_settings[$field];
849
-                        continue;
850
-                    }
851
-                    //only set the default if it isn't already set.
852
-                    if (! isset($this->_active_message_types[$messenger->name]['settings'][$field])) {
853
-                        $this->_active_message_types[$messenger->name]['settings'][$field] = $value;
854
-                    }
855
-                }
856
-            }
857
-        }
858
-    }
859
-
860
-
861
-    /**
862
-     * deactivate_messenger
863
-     *
864
-     * @param  string|EE_messenger $messenger_name name of messenger
865
-     * @return void
866
-     */
867
-    public function deactivate_messenger($messenger_name)
868
-    {
869
-        $this->_initialize_collections();
870
-        if ($messenger_name instanceof EE_messenger) {
871
-            $messenger_name = $messenger_name->name;
872
-        }
873
-        unset($this->_active_messengers[$messenger_name]);
874
-        unset($this->_active_message_types[$messenger_name]);
875
-        $this->_message_template_group_model->deactivate_message_template_groups_for($messenger_name);
876
-        $this->update_active_messengers_option();
877
-    }
878
-
879
-
880
-    /**
881
-     * Deactivates a message type (note this will deactivate across all messenger's it is active on.
882
-     *
883
-     * @param  string $message_type_name name of message type being deactivated
884
-     */
885
-    public function deactivate_message_type($message_type_name)
886
-    {
887
-        $this->_initialize_collections();
888
-        if ($message_type_name instanceof EE_message_type) {
889
-            $message_type_name = $message_type_name->name;
890
-        }
891
-        foreach ($this->_active_message_types as $messenger_name => $settings) {
892
-            unset(
893
-                $this->_active_message_types[$messenger_name]['settings'][$messenger_name . '-message_types'][$message_type_name]
894
-            );
895
-
896
-            //we always record (even on deactivation) that a message type has been activated because there should at
897
-            //least be a record in the "has_activated" option that it WAS active at one point.
898
-            $messenger = $this->get_messenger($messenger_name);
899
-            $this->_set_messenger_has_activated_message_type($messenger, $message_type_name);
900
-        }
901
-        $this->_message_template_group_model->deactivate_message_template_groups_for('', $message_type_name);
902
-        $this->update_active_messengers_option();
903
-        $this->update_has_activated_messengers_option();
904
-    }
905
-
906
-
907
-    /**
908
-     * Deactivates a message type for a specific messenger as opposed to all messengers.
909
-     *
910
-     * @param string $message_type_name Name of message type being deactivated.
911
-     * @param string $messenger_name    Name of messenger the message type is being deactivated for.
912
-     */
913
-    public function deactivate_message_type_for_messenger($message_type_name, $messenger_name)
914
-    {
915
-        $this->_initialize_collections();
916
-        if ($this->is_message_type_active_for_messenger($messenger_name, $message_type_name)) {
917
-            unset($this->_active_message_types[$messenger_name]['settings'][$messenger_name . '-message_types'][$message_type_name]);
918
-        }
919
-        $this->_message_template_group_model->deactivate_message_template_groups_for(array($messenger_name),
920
-            array($message_type_name));
921
-        $this->update_active_messengers_option();
922
-    }
923
-
924
-
925
-    /**
926
-     * Used to verify if a message can be sent for the given messenger and message type
927
-     * and that it is a generating messenger (used for generating message templates).
928
-     *
929
-     * @param EE_messenger    $messenger    messenger used in trigger
930
-     * @param EE_message_type $message_type message type used in trigger
931
-     * @return bool true is a generating messenger and can be sent OR FALSE meaning cannot send.
932
-     */
933
-    public function is_generating_messenger_and_active(EE_messenger $messenger, EE_message_type $message_type)
934
-    {
935
-        //get the $messengers the message type says it can be used with.
936
-        foreach ($message_type->with_messengers() as $generating_messenger => $secondary_messengers) {
937
-            if (
938
-                $messenger->name === $generating_messenger
939
-                && $this->is_message_type_active_for_messenger($messenger->name, $message_type->name)
940
-            ) {
941
-                return true;
942
-            }
943
-        }
944
-        return false;
945
-    }
946
-
947
-
948
-    /**
949
-     * This returns all the contexts that are registered by all message types.
950
-     * If $slugs_only is true,
951
-     * then just an array indexed by unique context slugs with the latest label representation for that slug.
952
-     * array(
953
-     *      'context_slug' => 'localized label for context obtained from latest message type in the loop'.
954
-     * );
955
-     * If $slugs_only is false, then the format is:
956
-     * array(
957
-     *      'message_type_name' => array(
958
-     *          'context_slug' => array(
959
-     *              'label' => 'localized label for context',
960
-     *              'description' => 'localized description for context'
961
-     *          )
962
-     *      )
963
-     * );
964
-     * Keep in mind that although different message types may share the same context slugs,
965
-     * it is possible that the context is described differently by the message type.
966
-     *
967
-     * @since 4.9.0
968
-     * @param   bool $slugs_only Whether to return an array of just slugs and labels (true)
969
-     *                           or all contexts indexed by message type.
970
-     * @return array
971
-     */
972
-    public function get_all_contexts($slugs_only = true)
973
-    {
974
-        $key = $slugs_only ? 'slugs' : 'all';
975
-        // check if contexts has been setup yet.
976
-        if (empty($this->_contexts[$key])) {
977
-            // So let's get all active message type objects and loop through to get all unique contexts
978
-            foreach ($this->get_active_message_type_objects() as $message_type) {
979
-                if ($message_type instanceof EE_message_type) {
980
-                    $message_type_contexts = $message_type->get_contexts();
981
-                    if ($slugs_only) {
982
-                        foreach ($message_type_contexts as $context => $context_details) {
983
-                            $this->_contexts[$key][$context] = $context_details['label'];
984
-                        }
985
-                    } else {
986
-                        $this->_contexts[$key][$message_type->name] = $message_type_contexts;
987
-                    }
988
-                }
989
-            }
990
-        }
991
-        return ! empty($this->_contexts[$key]) ? $this->_contexts[$key] : array();
992
-    }
993
-
994
-
995
-    /**
996
-     * This checks the internal record of what message types are considered "active" and verifies that
997
-     * there is an installed class definition for that message type.  If the active message type does not have a
998
-     * corresponding accessible message type class then it will be deactivated from all messengers it is active on and
999
-     * any related message templates will be inactivated as well.
1000
-     *
1001
-     * @return bool   true means all active message types are valid, false means at least one message type was
1002
-     *                deactivated.
1003
-     */
1004
-    public function validate_active_message_types_are_installed()
1005
-    {
1006
-        $list_of_active_message_type_names = $this->list_of_active_message_types();
1007
-        $installed_message_types           = $this->installed_message_types();
1008
-        $all_message_types_valid           = true;
1009
-        //loop through list of active message types and verify they are installed.
1010
-        foreach ($list_of_active_message_type_names as $message_type_name) {
1011
-            if (! isset($installed_message_types[$message_type_name])) {
1012
-                $this->deactivate_message_type($message_type_name);
1013
-                $all_message_types_valid = false;
1014
-            }
1015
-        }
1016
-        return $all_message_types_valid;
1017
-    }
1018
-
1019
-
1020
-    /**
1021
-     * This method checks the `ee_has_activated_messenger` option to see if the message type has ever been
1022
-     * activated for the given messenger.  This can be called by client code on plugin updates etc to determine whether
1023
-     * to attempt automatically reactivating message types that should be activated by default or not.
1024
-     *
1025
-     * @param $message_type_name
1026
-     * @param $messenger_name
1027
-     * @return bool
1028
-     */
1029
-    public function has_message_type_been_activated_for_messenger($message_type_name, $messenger_name)
1030
-    {
1031
-        $has_activated = $this->get_has_activated_messengers_option();
1032
-        return isset($has_activated[$messenger_name])
1033
-               && in_array($message_type_name, $has_activated[$messenger_name]);
1034
-    }
20
+	/**
21
+	 * @type boolean $_initialized
22
+	 */
23
+	protected $_initialized = false;
24
+
25
+	/**
26
+	 * @type EE_Messenger_Collection $_messenger_collection_loader
27
+	 */
28
+	protected $_messenger_collection_loader;
29
+
30
+	/**
31
+	 * @type EE_Message_Type_Collection $_message_type_collection_loader
32
+	 */
33
+	protected $_message_type_collection_loader;
34
+
35
+	/**
36
+	 * @type EEM_Message_Template_Group $_message_template_group_model
37
+	 */
38
+	protected $_message_template_group_model;
39
+
40
+	/**
41
+	 * @type EE_messenger[]
42
+	 */
43
+	protected $_installed_messengers = array();
44
+
45
+	/**
46
+	 * @type EE_message_type[]
47
+	 */
48
+	protected $_installed_message_types = array();
49
+
50
+	/**
51
+	 * Array of active messengers.
52
+	 * Format is this:
53
+	 * array(
54
+	 *      'messenger_name' => EE_messenger
55
+	 * )
56
+	 *
57
+	 * @type EE_messenger[]
58
+	 */
59
+	protected $_active_messengers = array();
60
+
61
+	/**
62
+	 * Formatted array of active message types grouped per messenger.
63
+	 * Format is this:
64
+	 * array(
65
+	 *      'messenger_name' => array(
66
+	 *          'settings' => array(
67
+	 *              '{messenger_name}-message_types' => array(
68
+	 *                  'message_type_name' => array() //variable array of settings corresponding to message type.
69
+	 *              )
70
+	 *          )
71
+	 *      )
72
+	 * )
73
+	 *
74
+	 * @type array
75
+	 */
76
+	protected $_active_message_types = array();
77
+
78
+
79
+	/**
80
+	 * This holds the array of messengers and their corresponding message types that have
81
+	 * been activated on a site at some point.  This is an important record that helps the messages system
82
+	 * not accidentally reactivate something that was intentionally deactivated by a user.
83
+	 *
84
+	 * @type array
85
+	 */
86
+	protected $_has_activated_messengers_and_message_types = array();
87
+
88
+	/**
89
+	 * An array of unique message type contexts across all active message types.
90
+	 * The array will be indexed by either 'slugs' or 'all'.
91
+	 * The slugs index contains an array indexed by unique context slugs with the latest label representation for that
92
+	 * slug. array(
93
+	 *      'context_slug' => 'localized label for context obtained from latest message type in the loop'.
94
+	 * );
95
+	 * The all index returns an array in this format:
96
+	 * array(
97
+	 *      'message_type_name' => array(
98
+	 *          'context_slug' => array(
99
+	 *              'label' => 'localized label for context',
100
+	 *              'description' => 'localized description for context'
101
+	 *          )
102
+	 *      )
103
+	 * );
104
+	 *
105
+	 * @type array
106
+	 */
107
+	protected $_contexts = array();
108
+
109
+
110
+	/**
111
+	 * EE_Message_Resource_Manager constructor.
112
+	 *
113
+	 * @param \EE_Messenger_Collection_Loader    $Messenger_Collection_Loader
114
+	 * @param \EE_Message_Type_Collection_Loader $Message_Type_Collection_Loader
115
+	 * @param \EEM_Message_Template_Group        $Message_Template_Group_Model
116
+	 */
117
+	function __construct(
118
+		EE_Messenger_Collection_Loader $Messenger_Collection_Loader,
119
+		EE_Message_Type_Collection_Loader $Message_Type_Collection_Loader,
120
+		EEM_Message_Template_Group $Message_Template_Group_Model
121
+	) {
122
+		$this->_messenger_collection_loader    = $Messenger_Collection_Loader;
123
+		$this->_message_type_collection_loader = $Message_Type_Collection_Loader;
124
+		$this->_message_template_group_model   = $Message_Template_Group_Model;
125
+	}
126
+
127
+
128
+	/**
129
+	 * @return void
130
+	 */
131
+	protected function _initialize_collections()
132
+	{
133
+		if ($this->_initialized) {
134
+			return;
135
+		}
136
+		$this->_initialized = true;
137
+		$this->_messenger_collection_loader->load_messengers_from_folder();
138
+		$this->_message_type_collection_loader->load_message_types_from_folder();
139
+		$this->get_has_activated_messengers_option(true);
140
+		$this->_set_active_messengers_and_message_types();
141
+	}
142
+
143
+
144
+	/**
145
+	 * @return EE_Messenger_Collection
146
+	 */
147
+	public function messenger_collection()
148
+	{
149
+		$this->_initialize_collections();
150
+		return $this->_messenger_collection_loader->messenger_collection();
151
+	}
152
+
153
+
154
+	/**
155
+	 * @return EE_messenger[]
156
+	 */
157
+	public function active_messengers()
158
+	{
159
+		$this->_initialize_collections();
160
+		return $this->_active_messengers;
161
+	}
162
+
163
+
164
+	/**
165
+	 * @param string $messenger_name
166
+	 * @return \EE_messenger
167
+	 */
168
+	public function get_messenger($messenger_name)
169
+	{
170
+		return $this->messenger_collection()->get_by_info($messenger_name);
171
+	}
172
+
173
+
174
+	/**
175
+	 * This returns the corresponding EE_messenger object for the given string if it is active.
176
+	 *
177
+	 * @param string $messenger
178
+	 * @return EE_messenger | null
179
+	 */
180
+	public function get_active_messenger($messenger)
181
+	{
182
+		$this->_initialize_collections();
183
+		return ! empty($this->_active_messengers[$messenger]) ? $this->_active_messengers[$messenger] : null;
184
+	}
185
+
186
+
187
+	/**
188
+	 * @return \EE_messenger[]
189
+	 */
190
+	public function installed_messengers()
191
+	{
192
+		if (empty($this->_installed_messengers)) {
193
+			$this->_installed_messengers = array();
194
+			$this->messenger_collection()->rewind();
195
+			while ($this->messenger_collection()->valid()) {
196
+				$this->_installed_messengers[$this->messenger_collection()->current()->name] = $this->messenger_collection()->current();
197
+				$this->messenger_collection()->next();
198
+			}
199
+		}
200
+		return $this->_installed_messengers;
201
+	}
202
+
203
+
204
+	/**
205
+	 * @param string $messenger_name
206
+	 * @return \EE_messenger
207
+	 * @throws \EE_Error
208
+	 */
209
+	public function valid_messenger($messenger_name)
210
+	{
211
+		$messenger = $this->get_messenger($messenger_name);
212
+		if ($messenger instanceof EE_messenger) {
213
+			return $messenger;
214
+		}
215
+		throw new EE_Error(
216
+			sprintf(
217
+				__('The "%1$s" messenger is either invalid or not installed', 'event_espresso'),
218
+				$messenger_name
219
+			)
220
+		);
221
+	}
222
+
223
+
224
+	/**
225
+	 * @return EE_Message_Type_Collection
226
+	 */
227
+	public function message_type_collection()
228
+	{
229
+		$this->_initialize_collections();
230
+		return $this->_message_type_collection_loader->message_type_collection();
231
+	}
232
+
233
+
234
+	/**
235
+	 * @return array
236
+	 */
237
+	public function active_message_types()
238
+	{
239
+		$this->_initialize_collections();
240
+		return $this->_active_message_types;
241
+	}
242
+
243
+
244
+	/**
245
+	 * @param string $message_type_name
246
+	 * @return \EE_message_type
247
+	 */
248
+	public function get_message_type($message_type_name)
249
+	{
250
+		return $this->message_type_collection()->get_by_info($message_type_name);
251
+	}
252
+
253
+
254
+	/**
255
+	 * This returns the EE_message_type from the active message types array ( if present );
256
+	 *
257
+	 * @param string $messenger_name
258
+	 * @param string $message_type_name
259
+	 * @return \EE_message_type|null
260
+	 */
261
+	public function get_active_message_type_for_messenger($messenger_name, $message_type_name)
262
+	{
263
+		return $this->is_message_type_active_for_messenger($messenger_name, $message_type_name)
264
+			? $this->get_message_type($message_type_name)
265
+			: null;
266
+	}
267
+
268
+
269
+	/**
270
+	 * Returns whether the given message type is active for the given messenger.
271
+	 *
272
+	 * @param string $messenger_name
273
+	 * @param string $message_type_name
274
+	 * @return bool
275
+	 */
276
+	public function is_message_type_active_for_messenger($messenger_name, $message_type_name)
277
+	{
278
+		$this->_initialize_collections();
279
+		return ! empty($this->_active_message_types[$messenger_name]['settings'][$messenger_name . '-message_types'][$message_type_name]);
280
+	}
281
+
282
+
283
+	/**
284
+	 * Returns whether the given messenger is active.
285
+	 *
286
+	 * @param string $messenger_name the name of the messenger to check if active.
287
+	 * @return bool
288
+	 */
289
+	public function is_messenger_active($messenger_name)
290
+	{
291
+		$this->_initialize_collections();
292
+		return ! empty($this->_active_message_types[$messenger_name]);
293
+	}
294
+
295
+
296
+	/**
297
+	 * This returns any settings that might be on a message type for a messenger
298
+	 *
299
+	 * @param string $messenger_name    The slug of the messenger
300
+	 * @param string $message_type_name The slug of the message type getting the settings for.
301
+	 * @return array
302
+	 */
303
+	public function get_message_type_settings_for_messenger($messenger_name, $message_type_name)
304
+	{
305
+		$settings = array();
306
+		if ($this->is_message_type_active_for_messenger($messenger_name, $message_type_name)) {
307
+			$settings = isset($this->_active_message_types[$messenger_name]['settings'][$messenger_name . '-message_types'][$message_type_name]['settings'])
308
+				? $this->_active_message_types[$messenger_name]['settings'][$messenger_name . '-message_types'][$message_type_name]['settings']
309
+				: array();
310
+		}
311
+		return $settings;
312
+	}
313
+
314
+
315
+	/**
316
+	 * Returns whether the given messenger name has active message types on it.
317
+	 * Infers whether the messenger is active or not as well.
318
+	 *
319
+	 * @param string $messenger_name
320
+	 * @return bool
321
+	 */
322
+	public function messenger_has_active_message_types($messenger_name)
323
+	{
324
+		$this->_initialize_collections();
325
+		return
326
+			! empty($this->_active_message_types[$messenger_name])
327
+			&& ! empty($this->_active_message_types[$messenger_name]['settings'][$messenger_name . '-message_types']);
328
+	}
329
+
330
+
331
+	/**
332
+	 * This checks the _active_message_types property for any active message types
333
+	 * that are present for the given messenger and returns them.
334
+	 *
335
+	 * @since 4.9.0
336
+	 * @param string $messenger_name The messenger being checked
337
+	 * @return EE_message_type[]|array    (empty array if no active_message_types)
338
+	 */
339
+	public function get_active_message_types_for_messenger($messenger_name)
340
+	{
341
+		$message_types = array();
342
+		if (! $this->messenger_has_active_message_types($messenger_name)) {
343
+			return $message_types;
344
+		}
345
+		$installed_message_types = $this->installed_message_types();
346
+		foreach ($installed_message_types as $message_type_name => $message_type) {
347
+			if ($this->is_message_type_active_for_messenger($messenger_name, $message_type_name)) {
348
+				$message_types[$message_type_name] = $message_type;
349
+			}
350
+		}
351
+		return $message_types;
352
+	}
353
+
354
+
355
+	/**
356
+	 * This does NOT return the _active_message_types property but
357
+	 * simply returns an array of active message type names from that property.
358
+	 * (The _active_message_types property is indexed by messenger and active message_types per messenger).
359
+	 *
360
+	 * @return array message_type references (string)
361
+	 */
362
+	public function list_of_active_message_types()
363
+	{
364
+		$active_message_type_names = array();
365
+		$this->_initialize_collections();
366
+		foreach ($this->_active_message_types as $messenger => $messenger_settings) {
367
+			if (! isset($messenger_settings['settings'][$messenger . '-message_types'])) {
368
+				continue;
369
+			}
370
+			foreach ($messenger_settings['settings'][$messenger . '-message_types'] as $message_type_name => $message_type_config) {
371
+				if (! in_array($message_type_name, $active_message_type_names)) {
372
+					$active_message_type_names[] = $message_type_name;
373
+				}
374
+			}
375
+		}
376
+		return $active_message_type_names;
377
+	}
378
+
379
+
380
+	/**
381
+	 * Same as list_of_active_message_types() except this returns actual EE_message_type objects
382
+	 *
383
+	 * @since 4.9.0
384
+	 * @return \EE_message_type[]
385
+	 */
386
+	public function get_active_message_type_objects()
387
+	{
388
+		$active_message_types      = array();
389
+		$installed_message_types   = $this->installed_message_types();
390
+		$active_message_type_names = $this->list_of_active_message_types();
391
+		foreach ($active_message_type_names as $active_message_type_name) {
392
+			if (isset($installed_message_types[$active_message_type_name])) {
393
+				$active_message_types[$active_message_type_name] = $installed_message_types[$active_message_type_name];
394
+			}
395
+		}
396
+		return $active_message_types;
397
+	}
398
+
399
+
400
+	/**
401
+	 * @return \EE_message_type[]
402
+	 */
403
+	public function installed_message_types()
404
+	{
405
+		if (empty($this->_installed_message_types)) {
406
+			$this->message_type_collection()->rewind();
407
+			while ($this->message_type_collection()->valid()) {
408
+				$this->_installed_message_types[$this->message_type_collection()->current()->name] = $this->message_type_collection()->current();
409
+				$this->message_type_collection()->next();
410
+			}
411
+		}
412
+		return $this->_installed_message_types;
413
+	}
414
+
415
+
416
+	/**
417
+	 * @param string $message_type_name
418
+	 * @return \EE_message_type
419
+	 * @throws \EE_Error
420
+	 */
421
+	public function valid_message_type($message_type_name)
422
+	{
423
+		$message_type = $this->get_message_type($message_type_name);
424
+		if ($message_type instanceof EE_message_type) {
425
+			return $message_type;
426
+		}
427
+		throw new EE_Error(
428
+			sprintf(
429
+				__('The "%1$s" message type is either invalid or not installed', 'event_espresso'),
430
+				$message_type_name
431
+			)
432
+		);
433
+	}
434
+
435
+
436
+	/**
437
+	 * valid_message_type_for_messenger
438
+	 *
439
+	 * @param EE_messenger $messenger
440
+	 * @param string       $message_type_name
441
+	 * @return boolean
442
+	 * @throws \EE_Error
443
+	 */
444
+	public function valid_message_type_for_messenger(EE_messenger $messenger, $message_type_name)
445
+	{
446
+		$valid_message_types = $messenger->get_valid_message_types();
447
+		if (! in_array($message_type_name, $valid_message_types)) {
448
+			throw new EE_Error(
449
+				sprintf(
450
+					__(
451
+						'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.',
452
+						'event_espresso'
453
+					),
454
+					$message_type_name,
455
+					__METHOD__,
456
+					$messenger->name
457
+				)
458
+			);
459
+		}
460
+		return true;
461
+	}
462
+
463
+
464
+	/**
465
+	 * Used to return active messengers array stored in the wp options table.
466
+	 * If no value is present in the option then an empty array is returned.
467
+	 *
468
+	 * @param   bool $reset     If true then we ignore whether the option is cached on the _active_message_types
469
+	 *                          property and pull directly from the db.  Otherwise whatever is currently on the
470
+	 *                          $_active_message_types property is pulled.
471
+	 * @return array
472
+	 */
473
+	public function get_active_messengers_option($reset = false)
474
+	{
475
+		if ($reset) {
476
+			$this->_active_message_types = get_option('ee_active_messengers', array());
477
+		}
478
+		return $this->_active_message_types;
479
+	}
480
+
481
+
482
+	/**
483
+	 * Used to update the active messengers array stored in the wp options table.
484
+	 *
485
+	 * @param array $active_messenger_settings Incoming data to save.  If empty, then the internal cached property
486
+	 *                                         representing this data is used.
487
+	 * @return bool FALSE if not updated, TRUE if updated.
488
+	 */
489
+	public function update_active_messengers_option($active_messenger_settings = array())
490
+	{
491
+		$active_messenger_settings = empty($active_messenger_settings) ? $this->_active_message_types : $active_messenger_settings;
492
+		//make sure _active_message_types is updated (this is the internal cache for the settings).
493
+		$this->_active_message_types = $active_messenger_settings;
494
+		return update_option('ee_active_messengers', $active_messenger_settings);
495
+	}
496
+
497
+
498
+	/**
499
+	 * Used to return active messengers array stored in the wp options table.
500
+	 * If no value is present in the option then an empty array is returned.
501
+	 * The value is cached on the $_has_activated_messengers_and_message_types property for future calls.
502
+	 *
503
+	 * @param   bool $reset Used to indicate that any cached value should be ignored.
504
+	 * @return array
505
+	 */
506
+	public function get_has_activated_messengers_option($reset = false)
507
+	{
508
+		if ($reset || empty($this->_has_activated_messengers_and_message_types)) {
509
+			$this->_has_activated_messengers_and_message_types = get_option('ee_has_activated_messenger', array());
510
+		}
511
+		return $this->_has_activated_messengers_and_message_types;
512
+	}
513
+
514
+
515
+	/**
516
+	 * Used to update the active messengers array stored in the wp options table.
517
+	 *
518
+	 * @param array $has_activated_messengers Incoming data to save.  If empty, then the internal cached property
519
+	 *                                        representing this data is used.
520
+	 * @return bool FALSE if not updated, TRUE if updated.
521
+	 */
522
+	public function update_has_activated_messengers_option($has_activated_messengers = array())
523
+	{
524
+		//make sure the option has been retrieved from first so we don't overwrite it accidentally.
525
+		if (empty($has_activated_messengers) && empty($this->_has_activated_messengers_and_message_types)) {
526
+			$this->get_has_activated_messengers_option();
527
+		}
528
+		$has_activated_messengers = empty($has_activated_messengers)
529
+			? $this->_has_activated_messengers_and_message_types
530
+			: $has_activated_messengers;
531
+		return update_option('ee_has_activated_messenger', $has_activated_messengers);
532
+	}
533
+
534
+
535
+	/**
536
+	 * wrapper for _set_active_messengers_and_message_types()
537
+	 */
538
+	public function reset_active_messengers_and_message_types()
539
+	{
540
+		$this->_set_active_messengers_and_message_types();
541
+	}
542
+
543
+
544
+	/**
545
+	 * Generate list of active messengers and message types from collection.
546
+	 * This sets up the active messengers from what is present in the database.
547
+	 */
548
+	protected function _set_active_messengers_and_message_types()
549
+	{
550
+		//echo "\n\n " . __LINE__ . ") " . __METHOD__ . "() \n";
551
+		// list of activated messengers as set via the admin
552
+		// note calling `get_active_messengers_options` also initializes the _active_message_types property.
553
+		$this->get_active_messengers_option(true);
554
+		$this->ensure_messengers_are_active(array(), false, true);
555
+		$this->update_active_messengers_option();
556
+		$this->update_has_activated_messengers_option();
557
+	}
558
+
559
+
560
+	/**
561
+	 * Ensures that the specified messenger is currently active.
562
+	 * If not, activates it and its default message types.
563
+	 *
564
+	 * @param string $messenger_name
565
+	 * @param bool   $update_option Whether to update the option in the db or not.
566
+	 * @return boolean true if either already active or successfully activated.
567
+	 */
568
+	public function ensure_messenger_is_active($messenger_name, $update_option = true)
569
+	{
570
+		if (! isset($this->_active_messengers[$messenger_name])) {
571
+			try {
572
+				$this->activate_messenger($messenger_name, array(), $update_option);
573
+			} catch (EE_Error $e) {
574
+				EE_Error::add_error(
575
+					$e->getMessage(),
576
+					__FILE__,
577
+					__FUNCTION__,
578
+					__LINE__
579
+				);
580
+				return false;
581
+			}
582
+		}
583
+		return true;
584
+	}
585
+
586
+
587
+	/**
588
+	 * This ensures the given array of messenger names is active in the system.
589
+	 * Note, this method will not activate any NEW message types for the messenger when it is called. Instead,
590
+	 * it will automatically activate the default message types for the messenger if its not active.
591
+	 *
592
+	 * @param array $messenger_names  Array of messenger names for messengers to be activated.  If an empty array
593
+	 *                                (default) then will attempt to set the active messengers from the
594
+	 *                                activated_messengers option
595
+	 *                                (stored in $_active_message_types property).
596
+	 * @param bool  $update_option    Whether to update the related active messengers option.
597
+	 * @param bool  $verify           Whether to verify the messengers are installed before activating. Note if this is
598
+	 *                                set to true and a messenger is indicated as active, but is NOT installed, then it
599
+	 *                                will automatically be deactivated.
600
+	 */
601
+	public function ensure_messengers_are_active($messenger_names = array(), $update_option = true, $verify = false)
602
+	{
603
+		$messenger_names = empty($messenger_names) ? array_keys($this->_active_message_types) : $messenger_names;
604
+
605
+		$not_installed = array();
606
+		foreach ($messenger_names as $messenger_name) {
607
+			if ($verify && ! $this->messenger_collection()->has_by_name($messenger_name)) {
608
+				$not_installed[] = $messenger_name;
609
+				$this->deactivate_messenger($messenger_name);
610
+				continue;
611
+			}
612
+			$this->ensure_messenger_is_active($messenger_name, $update_option);
613
+		}
614
+
615
+		if (! empty($not_installed_messenger)) {
616
+			EE_Error::add_error(
617
+				sprintf(
618
+					__('The following messengers are either not installed or are invalid:%1$s %2$s', 'event_espresso'),
619
+					'<br />',
620
+					implode(', ', $not_installed_messenger)
621
+				),
622
+				__FILE__, __FUNCTION__, __LINE__
623
+			);
624
+		}
625
+	}
626
+
627
+
628
+	/**
629
+	 * Ensures that the specified message type for the given messenger is currently active, if not activates it.
630
+	 * This ALSO ensures that the given messenger is active as well!
631
+	 *
632
+	 * @param string $message_type_name message type name.
633
+	 * @param        $messenger_name
634
+	 * @param bool   $update_option     Whether to update the option in the db or not.
635
+	 * @return bool  Returns true if already is active or if was activated successfully.
636
+	 * @throws \EE_Error
637
+	 */
638
+	public function ensure_message_type_is_active($message_type_name, $messenger_name, $update_option = true)
639
+	{
640
+		// grab the messenger to work with.
641
+		$messenger = $this->valid_messenger($messenger_name);
642
+		if ($this->valid_message_type_for_messenger($messenger, $message_type_name)) {
643
+			//ensure messenger is active (that's an inherent coupling between active message types and the
644
+			//messenger they are being activated for.
645
+			try {
646
+				if (! $this->is_message_type_active_for_messenger($messenger_name, $message_type_name)) {
647
+					//all is good so let's just get it active
648
+					$this->activate_messenger($messenger_name, array($message_type_name), $update_option);
649
+				}
650
+			} catch (EE_Error $e) {
651
+				EE_Error::add_error(
652
+					$e->getMessage(),
653
+					__FILE__,
654
+					__FUNCTION__,
655
+					__LINE__
656
+				);
657
+				return false;
658
+			}
659
+		}
660
+		return true;
661
+	}
662
+
663
+
664
+	/**
665
+	 * This is a wrapper for `ensure_message_type_is_active` that will handle ensuring multiple message types for a
666
+	 * messenger are active in one go.
667
+	 *
668
+	 * @param array  $message_type_names Array of message type names to ensure are active.
669
+	 * @param string $messenger_name     The name of the messenger that the message types are to be activated on.
670
+	 * @param bool   $update_option      Whether to persist the activation to the database or not (default true).
671
+	 */
672
+	public function ensure_message_types_are_active($message_type_names, $messenger_name, $update_option = true)
673
+	{
674
+		$message_type_names = (array)$message_type_names;
675
+		foreach ($message_type_names as $message_type_name) {
676
+			// note, intentionally not updating option here because we're in a loop.
677
+			// We'll follow the instructions of the incoming $update_option argument after the loop.
678
+			$this->ensure_message_type_is_active($message_type_name, $messenger_name, false);
679
+		}
680
+		if ($update_option) {
681
+			$this->update_active_messengers_option();
682
+			$this->update_has_activated_messengers_option();
683
+		}
684
+	}
685
+
686
+
687
+	/**
688
+	 * Activates the specified messenger.
689
+	 *
690
+	 * @param string $messenger_name
691
+	 * @param array  $message_type_names        An array of message type names to activate with this messenger.
692
+	 *                                          If included we do NOT setup the default message types
693
+	 *                                          (assuming they are already setup.)
694
+	 * @param bool   $update_active_messengers_option
695
+	 * @return array of generated templates
696
+	 * @throws \EE_Error
697
+	 */
698
+	public function activate_messenger(
699
+		$messenger_name,
700
+		$message_type_names = array(),
701
+		$update_active_messengers_option = true
702
+	) {
703
+		$templates = array();
704
+		// grab the messenger to work with.
705
+		$messenger = $this->messenger_collection()->get_by_info($messenger_name);
706
+		// it's inactive. Activate it.
707
+		if ($messenger instanceof EE_messenger) {
708
+			$this->_active_messengers[$messenger->name] = $messenger;
709
+			//activate incoming message types set to be activated with messenger.
710
+			$message_type_names = $this->_activate_message_types($messenger, $message_type_names);
711
+			// setup any initial settings for the messenger if necessary.
712
+			$this->add_settings_for_messenger($messenger->name);
713
+			if ($update_active_messengers_option) {
714
+				$this->update_active_messengers_option();
715
+				$this->update_has_activated_messengers_option();
716
+			}
717
+			//generate new templates if necessary and ensure all related templates that are already in the database are
718
+			//marked active.  Note, this will also deactivate a message type for a messenger if the template
719
+			//cannot be successfully created during its attempt (only happens for global template attempts).
720
+			if (! empty($message_type_names)) {
721
+				$templates = EEH_MSG_Template::generate_new_templates($messenger->name, $message_type_names, 0, true);
722
+				EEH_MSG_Template::update_to_active(array($messenger->name), $message_type_names);
723
+			}
724
+		}
725
+		return $templates;
726
+	}
727
+
728
+
729
+	/**
730
+	 * Activates given message types for the given EE_messenger object.
731
+	 * Note: (very important) This method does not persist the activation to the database.
732
+	 * See code implementing this method in this class for examples of how to persist.
733
+	 *
734
+	 * @param \EE_messenger $messenger
735
+	 * @param  array        $message_type_names
736
+	 * @return array
737
+	 */
738
+	protected function _activate_message_types(EE_messenger $messenger, $message_type_names = array())
739
+	{
740
+		//If $message_type_names is empty, AND $this->_active_message_types is empty, then that means
741
+		//things have never been initialized (which should happen on EEH_Activation::generate_message_templates).
742
+		//So ONLY then do we need to actually grab defaults and cycle through them.  Otherwise we
743
+		//only override _active_message_types when an explicit array of $message_type_names has been provided.
744
+		$message_type_names = empty($message_type_names) && ! isset($this->_active_message_types[$messenger->name])
745
+			? $messenger->get_default_message_types()
746
+			: (array)$message_type_names;
747
+
748
+		//now we ALWAYS need to make sure that the messenger is active for the message types we're activating!
749
+		if (! isset($this->_active_message_types[$messenger->name])) {
750
+			$this->_active_message_types[$messenger->name]['settings'] = array();
751
+		}
752
+
753
+		if ($message_type_names) {
754
+			// cycle thru message types
755
+			foreach ($message_type_names as $message_type_name) {
756
+				//only register the message type as active IF it isn't already active
757
+				//and if its actually installed.
758
+				if (
759
+				! $this->is_message_type_active_for_messenger($messenger->name, $message_type_name)
760
+				) {
761
+					$this->add_settings_for_message_type($messenger->name, $message_type_name);
762
+					$this->_set_messenger_has_activated_message_type(
763
+						$messenger,
764
+						$message_type_name
765
+					);
766
+				}
767
+			}
768
+		}
769
+		return $message_type_names;
770
+	}
771
+
772
+
773
+	/**
774
+	 * add_settings_for_message_type
775
+	 * NOTE This does NOT automatically persist any settings to the db.  Client code should call
776
+	 * $this->update_active_messengers_option to persist.
777
+	 *
778
+	 * @param  string $messenger_name    The name of the messenger adding the settings for
779
+	 * @param  string $message_type_name The name of the message type adding the settings for
780
+	 * @param  array  $new_settings      Any new settings being set for the message type and messenger
781
+	 */
782
+	public function add_settings_for_message_type($messenger_name, $message_type_name, $new_settings = array())
783
+	{
784
+		// get installed message type from collection
785
+		$message_type      = $this->message_type_collection()->get_by_info($message_type_name);
786
+		$existing_settings = $this->get_message_type_settings_for_messenger($messenger_name, $message_type_name);
787
+		//we need to setup any initial settings for message types
788
+		if ($message_type instanceof EE_message_type) {
789
+			$default_settings = $message_type->get_admin_settings_fields();
790
+			foreach ($default_settings as $field => $values) {
791
+				if (isset($new_settings[$field])) {
792
+					$existing_settings[$field] = $new_settings[$field];
793
+					continue;
794
+				}
795
+				if (! isset($existing_settings[$field])) {
796
+					$existing_settings[$field] = $values['default'];
797
+				}
798
+			}
799
+		}
800
+		$this->_active_message_types[$messenger_name]['settings'][$messenger_name . '-message_types'][$message_type_name]['settings'] = $existing_settings;
801
+	}
802
+
803
+
804
+	/**
805
+	 * Updates the internal cached _has_activated_messengers_and_message_types property with the given messenger
806
+	 * and message type.
807
+	 *
808
+	 * @access protected
809
+	 * @param \EE_messenger $messenger
810
+	 * @param string        $message_type_name
811
+	 */
812
+	protected function _set_messenger_has_activated_message_type(EE_messenger $messenger, $message_type_name)
813
+	{
814
+
815
+		//if _has_activated_messengers_and_message_types is empty then lets ensure its initialized
816
+		if (empty($this->_has_activated_messengers_and_message_types)) {
817
+			$this->get_has_activated_messengers_option();
818
+		}
819
+
820
+		// make sure this messenger has a record in the has_activated array
821
+		if (! isset($this->_has_activated_messengers_and_message_types[$messenger->name])) {
822
+			$this->_has_activated_messengers_and_message_types[$messenger->name] = array();
823
+		}
824
+		// check if message type has already been added
825
+		if (! in_array($message_type_name, $this->_has_activated_messengers_and_message_types[$messenger->name])) {
826
+			$this->_has_activated_messengers_and_message_types[$messenger->name][] = $message_type_name;
827
+		}
828
+	}
829
+
830
+
831
+	/**
832
+	 * add_settings_for_messenger
833
+	 * NOTE This does NOT automatically persist any settings to the db.  Client code should call
834
+	 * $this->update_active_messengers_option to persist.
835
+	 *
836
+	 * @param string $messenger_name The name of the messenger the settings is being added for.
837
+	 * @param array  $new_settings   An array of settings to update the existing settings.
838
+	 */
839
+	public function add_settings_for_messenger($messenger_name, $new_settings = array())
840
+	{
841
+		$messenger = $this->get_messenger($messenger_name);
842
+		if ($messenger instanceof EE_messenger) {
843
+			$msgr_settings = $messenger->get_admin_settings_fields();
844
+			if (! empty($msgr_settings)) {
845
+				foreach ($msgr_settings as $field => $value) {
846
+					//is there a new setting for this?
847
+					if (isset($new_settings[$field])) {
848
+						$this->_active_message_types[$messenger->name]['settings'][$field] = $new_settings[$field];
849
+						continue;
850
+					}
851
+					//only set the default if it isn't already set.
852
+					if (! isset($this->_active_message_types[$messenger->name]['settings'][$field])) {
853
+						$this->_active_message_types[$messenger->name]['settings'][$field] = $value;
854
+					}
855
+				}
856
+			}
857
+		}
858
+	}
859
+
860
+
861
+	/**
862
+	 * deactivate_messenger
863
+	 *
864
+	 * @param  string|EE_messenger $messenger_name name of messenger
865
+	 * @return void
866
+	 */
867
+	public function deactivate_messenger($messenger_name)
868
+	{
869
+		$this->_initialize_collections();
870
+		if ($messenger_name instanceof EE_messenger) {
871
+			$messenger_name = $messenger_name->name;
872
+		}
873
+		unset($this->_active_messengers[$messenger_name]);
874
+		unset($this->_active_message_types[$messenger_name]);
875
+		$this->_message_template_group_model->deactivate_message_template_groups_for($messenger_name);
876
+		$this->update_active_messengers_option();
877
+	}
878
+
879
+
880
+	/**
881
+	 * Deactivates a message type (note this will deactivate across all messenger's it is active on.
882
+	 *
883
+	 * @param  string $message_type_name name of message type being deactivated
884
+	 */
885
+	public function deactivate_message_type($message_type_name)
886
+	{
887
+		$this->_initialize_collections();
888
+		if ($message_type_name instanceof EE_message_type) {
889
+			$message_type_name = $message_type_name->name;
890
+		}
891
+		foreach ($this->_active_message_types as $messenger_name => $settings) {
892
+			unset(
893
+				$this->_active_message_types[$messenger_name]['settings'][$messenger_name . '-message_types'][$message_type_name]
894
+			);
895
+
896
+			//we always record (even on deactivation) that a message type has been activated because there should at
897
+			//least be a record in the "has_activated" option that it WAS active at one point.
898
+			$messenger = $this->get_messenger($messenger_name);
899
+			$this->_set_messenger_has_activated_message_type($messenger, $message_type_name);
900
+		}
901
+		$this->_message_template_group_model->deactivate_message_template_groups_for('', $message_type_name);
902
+		$this->update_active_messengers_option();
903
+		$this->update_has_activated_messengers_option();
904
+	}
905
+
906
+
907
+	/**
908
+	 * Deactivates a message type for a specific messenger as opposed to all messengers.
909
+	 *
910
+	 * @param string $message_type_name Name of message type being deactivated.
911
+	 * @param string $messenger_name    Name of messenger the message type is being deactivated for.
912
+	 */
913
+	public function deactivate_message_type_for_messenger($message_type_name, $messenger_name)
914
+	{
915
+		$this->_initialize_collections();
916
+		if ($this->is_message_type_active_for_messenger($messenger_name, $message_type_name)) {
917
+			unset($this->_active_message_types[$messenger_name]['settings'][$messenger_name . '-message_types'][$message_type_name]);
918
+		}
919
+		$this->_message_template_group_model->deactivate_message_template_groups_for(array($messenger_name),
920
+			array($message_type_name));
921
+		$this->update_active_messengers_option();
922
+	}
923
+
924
+
925
+	/**
926
+	 * Used to verify if a message can be sent for the given messenger and message type
927
+	 * and that it is a generating messenger (used for generating message templates).
928
+	 *
929
+	 * @param EE_messenger    $messenger    messenger used in trigger
930
+	 * @param EE_message_type $message_type message type used in trigger
931
+	 * @return bool true is a generating messenger and can be sent OR FALSE meaning cannot send.
932
+	 */
933
+	public function is_generating_messenger_and_active(EE_messenger $messenger, EE_message_type $message_type)
934
+	{
935
+		//get the $messengers the message type says it can be used with.
936
+		foreach ($message_type->with_messengers() as $generating_messenger => $secondary_messengers) {
937
+			if (
938
+				$messenger->name === $generating_messenger
939
+				&& $this->is_message_type_active_for_messenger($messenger->name, $message_type->name)
940
+			) {
941
+				return true;
942
+			}
943
+		}
944
+		return false;
945
+	}
946
+
947
+
948
+	/**
949
+	 * This returns all the contexts that are registered by all message types.
950
+	 * If $slugs_only is true,
951
+	 * then just an array indexed by unique context slugs with the latest label representation for that slug.
952
+	 * array(
953
+	 *      'context_slug' => 'localized label for context obtained from latest message type in the loop'.
954
+	 * );
955
+	 * If $slugs_only is false, then the format is:
956
+	 * array(
957
+	 *      'message_type_name' => array(
958
+	 *          'context_slug' => array(
959
+	 *              'label' => 'localized label for context',
960
+	 *              'description' => 'localized description for context'
961
+	 *          )
962
+	 *      )
963
+	 * );
964
+	 * Keep in mind that although different message types may share the same context slugs,
965
+	 * it is possible that the context is described differently by the message type.
966
+	 *
967
+	 * @since 4.9.0
968
+	 * @param   bool $slugs_only Whether to return an array of just slugs and labels (true)
969
+	 *                           or all contexts indexed by message type.
970
+	 * @return array
971
+	 */
972
+	public function get_all_contexts($slugs_only = true)
973
+	{
974
+		$key = $slugs_only ? 'slugs' : 'all';
975
+		// check if contexts has been setup yet.
976
+		if (empty($this->_contexts[$key])) {
977
+			// So let's get all active message type objects and loop through to get all unique contexts
978
+			foreach ($this->get_active_message_type_objects() as $message_type) {
979
+				if ($message_type instanceof EE_message_type) {
980
+					$message_type_contexts = $message_type->get_contexts();
981
+					if ($slugs_only) {
982
+						foreach ($message_type_contexts as $context => $context_details) {
983
+							$this->_contexts[$key][$context] = $context_details['label'];
984
+						}
985
+					} else {
986
+						$this->_contexts[$key][$message_type->name] = $message_type_contexts;
987
+					}
988
+				}
989
+			}
990
+		}
991
+		return ! empty($this->_contexts[$key]) ? $this->_contexts[$key] : array();
992
+	}
993
+
994
+
995
+	/**
996
+	 * This checks the internal record of what message types are considered "active" and verifies that
997
+	 * there is an installed class definition for that message type.  If the active message type does not have a
998
+	 * corresponding accessible message type class then it will be deactivated from all messengers it is active on and
999
+	 * any related message templates will be inactivated as well.
1000
+	 *
1001
+	 * @return bool   true means all active message types are valid, false means at least one message type was
1002
+	 *                deactivated.
1003
+	 */
1004
+	public function validate_active_message_types_are_installed()
1005
+	{
1006
+		$list_of_active_message_type_names = $this->list_of_active_message_types();
1007
+		$installed_message_types           = $this->installed_message_types();
1008
+		$all_message_types_valid           = true;
1009
+		//loop through list of active message types and verify they are installed.
1010
+		foreach ($list_of_active_message_type_names as $message_type_name) {
1011
+			if (! isset($installed_message_types[$message_type_name])) {
1012
+				$this->deactivate_message_type($message_type_name);
1013
+				$all_message_types_valid = false;
1014
+			}
1015
+		}
1016
+		return $all_message_types_valid;
1017
+	}
1018
+
1019
+
1020
+	/**
1021
+	 * This method checks the `ee_has_activated_messenger` option to see if the message type has ever been
1022
+	 * activated for the given messenger.  This can be called by client code on plugin updates etc to determine whether
1023
+	 * to attempt automatically reactivating message types that should be activated by default or not.
1024
+	 *
1025
+	 * @param $message_type_name
1026
+	 * @param $messenger_name
1027
+	 * @return bool
1028
+	 */
1029
+	public function has_message_type_been_activated_for_messenger($message_type_name, $messenger_name)
1030
+	{
1031
+		$has_activated = $this->get_has_activated_messengers_option();
1032
+		return isset($has_activated[$messenger_name])
1033
+			   && in_array($message_type_name, $has_activated[$messenger_name]);
1034
+	}
1035 1035
 }
1036 1036
 // End of file EE_Message_Resource_Manager.lib.php
1037 1037
 // Location: /EE_Message_Resource_Manager.lib.php
1038 1038
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-if (! defined('EVENT_ESPRESSO_VERSION')) {
3
+if ( ! defined('EVENT_ESPRESSO_VERSION')) {
4 4
     exit('No direct script access allowed');
5 5
 }
6 6
 
@@ -276,7 +276,7 @@  discard block
 block discarded – undo
276 276
     public function is_message_type_active_for_messenger($messenger_name, $message_type_name)
277 277
     {
278 278
         $this->_initialize_collections();
279
-        return ! empty($this->_active_message_types[$messenger_name]['settings'][$messenger_name . '-message_types'][$message_type_name]);
279
+        return ! empty($this->_active_message_types[$messenger_name]['settings'][$messenger_name.'-message_types'][$message_type_name]);
280 280
     }
281 281
 
282 282
 
@@ -304,8 +304,8 @@  discard block
 block discarded – undo
304 304
     {
305 305
         $settings = array();
306 306
         if ($this->is_message_type_active_for_messenger($messenger_name, $message_type_name)) {
307
-            $settings = isset($this->_active_message_types[$messenger_name]['settings'][$messenger_name . '-message_types'][$message_type_name]['settings'])
308
-                ? $this->_active_message_types[$messenger_name]['settings'][$messenger_name . '-message_types'][$message_type_name]['settings']
307
+            $settings = isset($this->_active_message_types[$messenger_name]['settings'][$messenger_name.'-message_types'][$message_type_name]['settings'])
308
+                ? $this->_active_message_types[$messenger_name]['settings'][$messenger_name.'-message_types'][$message_type_name]['settings']
309 309
                 : array();
310 310
         }
311 311
         return $settings;
@@ -324,7 +324,7 @@  discard block
 block discarded – undo
324 324
         $this->_initialize_collections();
325 325
         return
326 326
             ! empty($this->_active_message_types[$messenger_name])
327
-            && ! empty($this->_active_message_types[$messenger_name]['settings'][$messenger_name . '-message_types']);
327
+            && ! empty($this->_active_message_types[$messenger_name]['settings'][$messenger_name.'-message_types']);
328 328
     }
329 329
 
330 330
 
@@ -339,7 +339,7 @@  discard block
 block discarded – undo
339 339
     public function get_active_message_types_for_messenger($messenger_name)
340 340
     {
341 341
         $message_types = array();
342
-        if (! $this->messenger_has_active_message_types($messenger_name)) {
342
+        if ( ! $this->messenger_has_active_message_types($messenger_name)) {
343 343
             return $message_types;
344 344
         }
345 345
         $installed_message_types = $this->installed_message_types();
@@ -364,11 +364,11 @@  discard block
 block discarded – undo
364 364
         $active_message_type_names = array();
365 365
         $this->_initialize_collections();
366 366
         foreach ($this->_active_message_types as $messenger => $messenger_settings) {
367
-            if (! isset($messenger_settings['settings'][$messenger . '-message_types'])) {
367
+            if ( ! isset($messenger_settings['settings'][$messenger.'-message_types'])) {
368 368
                 continue;
369 369
             }
370
-            foreach ($messenger_settings['settings'][$messenger . '-message_types'] as $message_type_name => $message_type_config) {
371
-                if (! in_array($message_type_name, $active_message_type_names)) {
370
+            foreach ($messenger_settings['settings'][$messenger.'-message_types'] as $message_type_name => $message_type_config) {
371
+                if ( ! in_array($message_type_name, $active_message_type_names)) {
372 372
                     $active_message_type_names[] = $message_type_name;
373 373
                 }
374 374
             }
@@ -444,7 +444,7 @@  discard block
 block discarded – undo
444 444
     public function valid_message_type_for_messenger(EE_messenger $messenger, $message_type_name)
445 445
     {
446 446
         $valid_message_types = $messenger->get_valid_message_types();
447
-        if (! in_array($message_type_name, $valid_message_types)) {
447
+        if ( ! in_array($message_type_name, $valid_message_types)) {
448 448
             throw new EE_Error(
449 449
                 sprintf(
450 450
                     __(
@@ -567,7 +567,7 @@  discard block
 block discarded – undo
567 567
      */
568 568
     public function ensure_messenger_is_active($messenger_name, $update_option = true)
569 569
     {
570
-        if (! isset($this->_active_messengers[$messenger_name])) {
570
+        if ( ! isset($this->_active_messengers[$messenger_name])) {
571 571
             try {
572 572
                 $this->activate_messenger($messenger_name, array(), $update_option);
573 573
             } catch (EE_Error $e) {
@@ -612,7 +612,7 @@  discard block
 block discarded – undo
612 612
             $this->ensure_messenger_is_active($messenger_name, $update_option);
613 613
         }
614 614
 
615
-        if (! empty($not_installed_messenger)) {
615
+        if ( ! empty($not_installed_messenger)) {
616 616
             EE_Error::add_error(
617 617
                 sprintf(
618 618
                     __('The following messengers are either not installed or are invalid:%1$s %2$s', 'event_espresso'),
@@ -643,7 +643,7 @@  discard block
 block discarded – undo
643 643
             //ensure messenger is active (that's an inherent coupling between active message types and the
644 644
             //messenger they are being activated for.
645 645
             try {
646
-                if (! $this->is_message_type_active_for_messenger($messenger_name, $message_type_name)) {
646
+                if ( ! $this->is_message_type_active_for_messenger($messenger_name, $message_type_name)) {
647 647
                     //all is good so let's just get it active
648 648
                     $this->activate_messenger($messenger_name, array($message_type_name), $update_option);
649 649
                 }
@@ -671,7 +671,7 @@  discard block
 block discarded – undo
671 671
      */
672 672
     public function ensure_message_types_are_active($message_type_names, $messenger_name, $update_option = true)
673 673
     {
674
-        $message_type_names = (array)$message_type_names;
674
+        $message_type_names = (array) $message_type_names;
675 675
         foreach ($message_type_names as $message_type_name) {
676 676
             // note, intentionally not updating option here because we're in a loop.
677 677
             // We'll follow the instructions of the incoming $update_option argument after the loop.
@@ -717,7 +717,7 @@  discard block
 block discarded – undo
717 717
             //generate new templates if necessary and ensure all related templates that are already in the database are
718 718
             //marked active.  Note, this will also deactivate a message type for a messenger if the template
719 719
             //cannot be successfully created during its attempt (only happens for global template attempts).
720
-            if (! empty($message_type_names)) {
720
+            if ( ! empty($message_type_names)) {
721 721
                 $templates = EEH_MSG_Template::generate_new_templates($messenger->name, $message_type_names, 0, true);
722 722
                 EEH_MSG_Template::update_to_active(array($messenger->name), $message_type_names);
723 723
             }
@@ -743,10 +743,10 @@  discard block
 block discarded – undo
743 743
         //only override _active_message_types when an explicit array of $message_type_names has been provided.
744 744
         $message_type_names = empty($message_type_names) && ! isset($this->_active_message_types[$messenger->name])
745 745
             ? $messenger->get_default_message_types()
746
-            : (array)$message_type_names;
746
+            : (array) $message_type_names;
747 747
 
748 748
         //now we ALWAYS need to make sure that the messenger is active for the message types we're activating!
749
-        if (! isset($this->_active_message_types[$messenger->name])) {
749
+        if ( ! isset($this->_active_message_types[$messenger->name])) {
750 750
             $this->_active_message_types[$messenger->name]['settings'] = array();
751 751
         }
752 752
 
@@ -792,12 +792,12 @@  discard block
 block discarded – undo
792 792
                     $existing_settings[$field] = $new_settings[$field];
793 793
                     continue;
794 794
                 }
795
-                if (! isset($existing_settings[$field])) {
795
+                if ( ! isset($existing_settings[$field])) {
796 796
                     $existing_settings[$field] = $values['default'];
797 797
                 }
798 798
             }
799 799
         }
800
-        $this->_active_message_types[$messenger_name]['settings'][$messenger_name . '-message_types'][$message_type_name]['settings'] = $existing_settings;
800
+        $this->_active_message_types[$messenger_name]['settings'][$messenger_name.'-message_types'][$message_type_name]['settings'] = $existing_settings;
801 801
     }
802 802
 
803 803
 
@@ -818,11 +818,11 @@  discard block
 block discarded – undo
818 818
         }
819 819
 
820 820
         // make sure this messenger has a record in the has_activated array
821
-        if (! isset($this->_has_activated_messengers_and_message_types[$messenger->name])) {
821
+        if ( ! isset($this->_has_activated_messengers_and_message_types[$messenger->name])) {
822 822
             $this->_has_activated_messengers_and_message_types[$messenger->name] = array();
823 823
         }
824 824
         // check if message type has already been added
825
-        if (! in_array($message_type_name, $this->_has_activated_messengers_and_message_types[$messenger->name])) {
825
+        if ( ! in_array($message_type_name, $this->_has_activated_messengers_and_message_types[$messenger->name])) {
826 826
             $this->_has_activated_messengers_and_message_types[$messenger->name][] = $message_type_name;
827 827
         }
828 828
     }
@@ -841,7 +841,7 @@  discard block
 block discarded – undo
841 841
         $messenger = $this->get_messenger($messenger_name);
842 842
         if ($messenger instanceof EE_messenger) {
843 843
             $msgr_settings = $messenger->get_admin_settings_fields();
844
-            if (! empty($msgr_settings)) {
844
+            if ( ! empty($msgr_settings)) {
845 845
                 foreach ($msgr_settings as $field => $value) {
846 846
                     //is there a new setting for this?
847 847
                     if (isset($new_settings[$field])) {
@@ -849,7 +849,7 @@  discard block
 block discarded – undo
849 849
                         continue;
850 850
                     }
851 851
                     //only set the default if it isn't already set.
852
-                    if (! isset($this->_active_message_types[$messenger->name]['settings'][$field])) {
852
+                    if ( ! isset($this->_active_message_types[$messenger->name]['settings'][$field])) {
853 853
                         $this->_active_message_types[$messenger->name]['settings'][$field] = $value;
854 854
                     }
855 855
                 }
@@ -890,7 +890,7 @@  discard block
 block discarded – undo
890 890
         }
891 891
         foreach ($this->_active_message_types as $messenger_name => $settings) {
892 892
             unset(
893
-                $this->_active_message_types[$messenger_name]['settings'][$messenger_name . '-message_types'][$message_type_name]
893
+                $this->_active_message_types[$messenger_name]['settings'][$messenger_name.'-message_types'][$message_type_name]
894 894
             );
895 895
 
896 896
             //we always record (even on deactivation) that a message type has been activated because there should at
@@ -914,7 +914,7 @@  discard block
 block discarded – undo
914 914
     {
915 915
         $this->_initialize_collections();
916 916
         if ($this->is_message_type_active_for_messenger($messenger_name, $message_type_name)) {
917
-            unset($this->_active_message_types[$messenger_name]['settings'][$messenger_name . '-message_types'][$message_type_name]);
917
+            unset($this->_active_message_types[$messenger_name]['settings'][$messenger_name.'-message_types'][$message_type_name]);
918 918
         }
919 919
         $this->_message_template_group_model->deactivate_message_template_groups_for(array($messenger_name),
920 920
             array($message_type_name));
@@ -1008,7 +1008,7 @@  discard block
 block discarded – undo
1008 1008
         $all_message_types_valid           = true;
1009 1009
         //loop through list of active message types and verify they are installed.
1010 1010
         foreach ($list_of_active_message_type_names as $message_type_name) {
1011
-            if (! isset($installed_message_types[$message_type_name])) {
1011
+            if ( ! isset($installed_message_types[$message_type_name])) {
1012 1012
                 $this->deactivate_message_type($message_type_name);
1013 1013
                 $all_message_types_valid = false;
1014 1014
             }
Please login to merge, or discard this patch.