Completed
Branch BUG-10504-spco-submit-lock (c0988b)
by
unknown
12:11 queued 11s
created
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.
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
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -17,7 +17,7 @@
 block discarded – undo
17 17
 
18 18
     /**
19 19
      * @param string $value_to_normalize
20
-     * @return int|mixed|string
20
+     * @return null|integer
21 21
      * @throws \EE_Validation_Error
22 22
      */
23 23
     public function normalize($value_to_normalize)
Please login to merge, or discard this patch.
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -1,4 +1,4 @@  discard block
 block discarded – undo
1
-<?php if (! defined('EVENT_ESPRESSO_VERSION')) {
1
+<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) {
2 2
     exit('No direct script access allowed');
3 3
 }
4 4
 
@@ -34,9 +34,9 @@  discard block
 block discarded – undo
34 34
             return null;
35 35
         }
36 36
         if (is_int($value_to_normalize) || is_float($value_to_normalize)) {
37
-            return (int)$value_to_normalize;
37
+            return (int) $value_to_normalize;
38 38
         }
39
-        if (! is_string($value_to_normalize)) {
39
+        if ( ! is_string($value_to_normalize)) {
40 40
             throw new EE_Validation_Error(
41 41
                 sprintf(
42 42
                     __('The value "%s" must be a string submitted for normalization, it was %s', 'event_espresso'),
@@ -59,8 +59,8 @@  discard block
 block discarded – undo
59 59
                 // if first match is the negative sign,
60 60
                 // then the number needs to be multiplied by -1 to remain negative
61 61
                 return $matches[1] === '-'
62
-                    ? (int)$matches[2] * -1
63
-                    : (int)$matches[2];
62
+                    ? (int) $matches[2] * -1
63
+                    : (int) $matches[2];
64 64
             }
65 65
         }
66 66
         //find if this input has a int validation strategy
@@ -73,7 +73,7 @@  discard block
 block discarded – undo
73 73
         }
74 74
         //this really shouldn't ever happen because fields with a int normalization strategy
75 75
         //should also have a int validation strategy, but in case it doesn't use the default
76
-        if (! $validation_error_message) {
76
+        if ( ! $validation_error_message) {
77 77
             $default_validation_strategy = new EE_Int_Validation_Strategy();
78 78
             $validation_error_message = $default_validation_strategy->get_validation_error_message();
79 79
         }
Please login to merge, or discard this patch.
Indentation   +75 added lines, -75 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
 
@@ -15,89 +15,89 @@  discard block
 block discarded – undo
15 15
 class EE_Int_Normalization extends EE_Normalization_Strategy_Base
16 16
 {
17 17
 
18
-    /*
18
+	/*
19 19
      * regex pattern that matches for the following:
20 20
      *      * optional negative sign
21 21
      *      * one or more digits
22 22
      */
23
-    const REGEX = '/^(-?)(\d+)(?:\.0+)?$/';
23
+	const REGEX = '/^(-?)(\d+)(?:\.0+)?$/';
24 24
 
25 25
 
26 26
 
27
-    /**
28
-     * @param string $value_to_normalize
29
-     * @return int|mixed|string
30
-     * @throws \EE_Validation_Error
31
-     */
32
-    public function normalize($value_to_normalize)
33
-    {
34
-        if ($value_to_normalize === null) {
35
-            return null;
36
-        }
37
-        if (is_int($value_to_normalize) || is_float($value_to_normalize)) {
38
-            return (int)$value_to_normalize;
39
-        }
40
-        if (! is_string($value_to_normalize)) {
41
-            throw new EE_Validation_Error(
42
-                sprintf(
43
-                    __('The value "%s" must be a string submitted for normalization, it was %s', 'event_espresso'),
44
-                    print_r($value_to_normalize, true),
45
-                    gettype($value_to_normalize)
46
-                )
47
-            );
48
-        }
49
-        $value_to_normalize = filter_var(
50
-            $value_to_normalize,
51
-            FILTER_SANITIZE_NUMBER_FLOAT,
52
-            FILTER_FLAG_ALLOW_FRACTION
53
-        );
54
-        if ($value_to_normalize === '') {
55
-            return null;
56
-        }
57
-        $matches = array();
58
-        if (preg_match(EE_Int_Normalization::REGEX, $value_to_normalize, $matches)) {
59
-            if (count($matches) === 3) {
60
-                // if first match is the negative sign,
61
-                // then the number needs to be multiplied by -1 to remain negative
62
-                return $matches[1] === '-'
63
-                    ? (int)$matches[2] * -1
64
-                    : (int)$matches[2];
65
-            }
66
-        }
67
-        //find if this input has a int validation strategy
68
-        //in which case, use its message
69
-        $validation_error_message = null;
70
-        foreach ($this->_input->get_validation_strategies() as $validation_strategy) {
71
-            if ($validation_strategy instanceof EE_Int_Validation_Strategy) {
72
-                $validation_error_message = $validation_strategy->get_validation_error_message();
73
-            }
74
-        }
75
-        //this really shouldn't ever happen because fields with a int normalization strategy
76
-        //should also have a int validation strategy, but in case it doesn't use the default
77
-        if (! $validation_error_message) {
78
-            $default_validation_strategy = new EE_Int_Validation_Strategy();
79
-            $validation_error_message = $default_validation_strategy->get_validation_error_message();
80
-        }
81
-        throw new EE_Validation_Error($validation_error_message, 'numeric_only');
82
-    }
27
+	/**
28
+	 * @param string $value_to_normalize
29
+	 * @return int|mixed|string
30
+	 * @throws \EE_Validation_Error
31
+	 */
32
+	public function normalize($value_to_normalize)
33
+	{
34
+		if ($value_to_normalize === null) {
35
+			return null;
36
+		}
37
+		if (is_int($value_to_normalize) || is_float($value_to_normalize)) {
38
+			return (int)$value_to_normalize;
39
+		}
40
+		if (! is_string($value_to_normalize)) {
41
+			throw new EE_Validation_Error(
42
+				sprintf(
43
+					__('The value "%s" must be a string submitted for normalization, it was %s', 'event_espresso'),
44
+					print_r($value_to_normalize, true),
45
+					gettype($value_to_normalize)
46
+				)
47
+			);
48
+		}
49
+		$value_to_normalize = filter_var(
50
+			$value_to_normalize,
51
+			FILTER_SANITIZE_NUMBER_FLOAT,
52
+			FILTER_FLAG_ALLOW_FRACTION
53
+		);
54
+		if ($value_to_normalize === '') {
55
+			return null;
56
+		}
57
+		$matches = array();
58
+		if (preg_match(EE_Int_Normalization::REGEX, $value_to_normalize, $matches)) {
59
+			if (count($matches) === 3) {
60
+				// if first match is the negative sign,
61
+				// then the number needs to be multiplied by -1 to remain negative
62
+				return $matches[1] === '-'
63
+					? (int)$matches[2] * -1
64
+					: (int)$matches[2];
65
+			}
66
+		}
67
+		//find if this input has a int validation strategy
68
+		//in which case, use its message
69
+		$validation_error_message = null;
70
+		foreach ($this->_input->get_validation_strategies() as $validation_strategy) {
71
+			if ($validation_strategy instanceof EE_Int_Validation_Strategy) {
72
+				$validation_error_message = $validation_strategy->get_validation_error_message();
73
+			}
74
+		}
75
+		//this really shouldn't ever happen because fields with a int normalization strategy
76
+		//should also have a int validation strategy, but in case it doesn't use the default
77
+		if (! $validation_error_message) {
78
+			$default_validation_strategy = new EE_Int_Validation_Strategy();
79
+			$validation_error_message = $default_validation_strategy->get_validation_error_message();
80
+		}
81
+		throw new EE_Validation_Error($validation_error_message, 'numeric_only');
82
+	}
83 83
 
84 84
 
85 85
 
86
-    /**
87
-     * Converts the int into a string for use in teh html form
88
-     *
89
-     * @param int $normalized_value
90
-     * @return string
91
-     */
92
-    public function unnormalize($normalized_value)
93
-    {
94
-        if ($normalized_value === null || $normalized_value === '') {
95
-            return '';
96
-        }
97
-        if (empty($normalized_value)) {
98
-            return '0';
99
-        }
100
-        return "$normalized_value";
101
-    }
86
+	/**
87
+	 * Converts the int into a string for use in teh html form
88
+	 *
89
+	 * @param int $normalized_value
90
+	 * @return string
91
+	 */
92
+	public function unnormalize($normalized_value)
93
+	{
94
+		if ($normalized_value === null || $normalized_value === '') {
95
+			return '';
96
+		}
97
+		if (empty($normalized_value)) {
98
+			return '0';
99
+		}
100
+		return "$normalized_value";
101
+	}
102 102
 }
103 103
 // End of file EE_Int_Normalization.strategy.php
Please login to merge, or discard this patch.
form_sections/strategies/validation/EE_Int_Validation_Strategy.strategy.php 2 patches
Indentation   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -33,14 +33,14 @@
 block discarded – undo
33 33
 	 * @return array
34 34
 	 */
35 35
 	function get_jquery_validation_rule_array(){
36
-        return array(
37
-            'number'=>true,
38
-            'step' => 1,
39
-            'messages' => array(
40
-                'number' => $this->get_validation_error_message(),
41
-                'step' => $this->get_validation_error_message()
42
-            )
43
-        );
36
+		return array(
37
+			'number'=>true,
38
+			'step' => 1,
39
+			'messages' => array(
40
+				'number' => $this->get_validation_error_message(),
41
+				'step' => $this->get_validation_error_message()
42
+			)
43
+		);
44 44
 	}
45 45
 }
46 46
 
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -6,16 +6,16 @@  discard block
 block discarded – undo
6 6
  * @subpackage	Expression package is undefined on line 19, column 19 in Templates/Scripting/PHPClass.php.
7 7
  * @author				Mike Nelson
8 8
  */
9
-class EE_Int_Validation_Strategy extends EE_Validation_Strategy_Base{
9
+class EE_Int_Validation_Strategy extends EE_Validation_Strategy_Base {
10 10
 
11 11
 	/**
12 12
 	 * @param null $validation_error_message
13 13
 	 */
14
-	public function __construct( $validation_error_message = NULL ) {
15
-		if( ! $validation_error_message ){
14
+	public function __construct($validation_error_message = NULL) {
15
+		if ( ! $validation_error_message) {
16 16
 			$validation_error_message = __("Only digits are allowed.", "event_espresso");
17 17
 		}
18
-		parent::__construct( $validation_error_message );
18
+		parent::__construct($validation_error_message);
19 19
 	}
20 20
 
21 21
 
@@ -32,7 +32,7 @@  discard block
 block discarded – undo
32 32
 	/**
33 33
 	 * @return array
34 34
 	 */
35
-	function get_jquery_validation_rule_array(){
35
+	function get_jquery_validation_rule_array() {
36 36
         return array(
37 37
             'number'=>true,
38 38
             'step' => 1,
Please login to merge, or discard this patch.
core/helpers/EEH_Money.helper.php 2 patches
Indentation   +88 added lines, -88 removed lines patch added patch discarded remove patch
@@ -8,62 +8,62 @@  discard block
 block discarded – undo
8 8
  */
9 9
 if ( ! defined('EVENT_ESPRESSO_VERSION')) exit('No direct script access allowed');
10 10
  /**
11
- *
12
- * Money helper class.
13
- * This class has helper methods that help with money related conversions and calculations.
14
- *
15
- * @since %VER%
16
- *
17
- * @package		Event Espresso
18
- * @subpackage	helpers
19
- * @author		Darren Ethier
20
- *
21
- * ------------------------------------------------------------------------
22
- */
11
+  *
12
+  * Money helper class.
13
+  * This class has helper methods that help with money related conversions and calculations.
14
+  *
15
+  * @since %VER%
16
+  *
17
+  * @package		Event Espresso
18
+  * @subpackage	helpers
19
+  * @author		Darren Ethier
20
+  *
21
+  * ------------------------------------------------------------------------
22
+  */
23 23
 class EEH_Money extends EEH_Base  {
24 24
 
25 25
 
26
-    /**
27
-     * This removes all localized money formatting from the incoming value
28
-     *
29
-     * @param int|float|string $money_value
30
-     * @param string           $CNT_ISO
31
-     * @return float
32
-     * @throws EE_Error
33
-     */
26
+	/**
27
+	 * This removes all localized money formatting from the incoming value
28
+	 *
29
+	 * @param int|float|string $money_value
30
+	 * @param string           $CNT_ISO
31
+	 * @return float
32
+	 * @throws EE_Error
33
+	 */
34 34
 	public static function strip_localized_money_formatting($money_value, $CNT_ISO = '') {
35
-        $currency_config = EEH_Money::get_currency_config($CNT_ISO);
36
-        $money_value = str_replace(
37
-		    array(
38
-                $currency_config->thsnds,
39
-                $currency_config->dec_mrk,
40
-            ),
41
-            array(
42
-                '', // remove thousands separator
43
-                '.', // convert decimal mark to what PHP expects
44
-            ),
45
-            $money_value
46
-        );
47
-        $money_value = filter_var(
48
-            $money_value,
49
-            FILTER_SANITIZE_NUMBER_FLOAT,
50
-            FILTER_FLAG_ALLOW_FRACTION
51
-        );
52
-        return $money_value;
53
-    }
54
-
55
-
56
-
57
-    /**
58
-     * This converts an incoming localized money value into a standard float item (to three decimal places)
59
-     *
60
-     * @param int|string $money_value
61
-     * @return float
62
-     * @throws EE_Error
63
-     */
35
+		$currency_config = EEH_Money::get_currency_config($CNT_ISO);
36
+		$money_value = str_replace(
37
+			array(
38
+				$currency_config->thsnds,
39
+				$currency_config->dec_mrk,
40
+			),
41
+			array(
42
+				'', // remove thousands separator
43
+				'.', // convert decimal mark to what PHP expects
44
+			),
45
+			$money_value
46
+		);
47
+		$money_value = filter_var(
48
+			$money_value,
49
+			FILTER_SANITIZE_NUMBER_FLOAT,
50
+			FILTER_FLAG_ALLOW_FRACTION
51
+		);
52
+		return $money_value;
53
+	}
54
+
55
+
56
+
57
+	/**
58
+	 * This converts an incoming localized money value into a standard float item (to three decimal places)
59
+	 *
60
+	 * @param int|string $money_value
61
+	 * @return float
62
+	 * @throws EE_Error
63
+	 */
64 64
 	public static function convert_to_float_from_localized_money($money_value ) {
65 65
 		//float it! and round to three decimal places
66
-        return round ( (float) EEH_Money::strip_localized_money_formatting($money_value), 3 );
66
+		return round ( (float) EEH_Money::strip_localized_money_formatting($money_value), 3 );
67 67
 	}
68 68
 
69 69
 
@@ -151,19 +151,19 @@  discard block
 block discarded – undo
151 151
 
152 152
 
153 153
 
154
-    /**
155
-     * This returns a localized format string suitable for jQplot.
156
-     *
157
-     * @param string $CNT_ISO  If this is provided, then will attempt to get the currency settings for the country.
158
-     *                         Otherwise will use currency settings for current active country on site.
159
-     * @return string
160
-     * @throws EE_Error
161
-     */
154
+	/**
155
+	 * This returns a localized format string suitable for jQplot.
156
+	 *
157
+	 * @param string $CNT_ISO  If this is provided, then will attempt to get the currency settings for the country.
158
+	 *                         Otherwise will use currency settings for current active country on site.
159
+	 * @return string
160
+	 * @throws EE_Error
161
+	 */
162 162
 	public static function get_format_for_jqplot( $CNT_ISO = '') {
163 163
 		//default format
164 164
 		$format = 'f';
165 165
 		$currency_config = $currency_config = EEH_Money::get_currency_config($CNT_ISO);
166
-        //first get the decimal place and number of places
166
+		//first get the decimal place and number of places
167 167
 		$format = "%'." . $currency_config->dec_plc . $format;
168 168
 		//currency symbol on right side.
169 169
 		$format = $currency_config->sign_b4 ? $currency_config->sign . $format : $format . $currency_config->sign;
@@ -172,16 +172,16 @@  discard block
 block discarded – undo
172 172
 
173 173
 
174 174
 
175
-    /**
176
-     * This returns a localized format string suitable for usage with the Google Charts API format param.
177
-     *
178
-     * @param string $CNT_ISO  If this is provided, then will attempt to get the currency settings for the country.
179
-     *                         Otherwise will use currency settings for current active country on site.
180
-     *                         Note: GoogleCharts uses ICU pattern set
181
-     *                         (@see http://icu-project.org/apiref/icu4c/classDecimalFormat.html#_details)
182
-     * @return string
183
-     * @throws EE_Error
184
-     */
175
+	/**
176
+	 * This returns a localized format string suitable for usage with the Google Charts API format param.
177
+	 *
178
+	 * @param string $CNT_ISO  If this is provided, then will attempt to get the currency settings for the country.
179
+	 *                         Otherwise will use currency settings for current active country on site.
180
+	 *                         Note: GoogleCharts uses ICU pattern set
181
+	 *                         (@see http://icu-project.org/apiref/icu4c/classDecimalFormat.html#_details)
182
+	 * @return string
183
+	 * @throws EE_Error
184
+	 */
185 185
 	public static function get_format_for_google_charts( $CNT_ISO = '' ) {
186 186
 		$currency_config = EEH_Money::get_currency_config($CNT_ISO);
187 187
 		$decimal_places_placeholder = str_pad( '', $currency_config->dec_plc, '0' );
@@ -208,24 +208,24 @@  discard block
 block discarded – undo
208 208
 
209 209
 
210 210
 
211
-    /**
212
-     * @param string $CNT_ISO
213
-     * @return EE_Currency_Config|null
214
-     * @throws EE_Error
215
-     */
216
-    public static function get_currency_config($CNT_ISO = '')
217
-    {
218
-        //if CNT_ISO passed lets try to get currency settings for it.
219
-        $currency_config = $CNT_ISO !== ''
220
-            ? new EE_Currency_Config($CNT_ISO)
221
-            : null;
222
-        //default currency settings for site if not set
223
-        if (! $currency_config instanceof EE_Currency_Config) {
224
-            $currency_config = EE_Registry::instance()->CFG->currency instanceof EE_Currency_Config
225
-                ? EE_Registry::instance()->CFG->currency
226
-                : new EE_Currency_Config();
227
-        }
228
-        return $currency_config;
229
-    }
211
+	/**
212
+	 * @param string $CNT_ISO
213
+	 * @return EE_Currency_Config|null
214
+	 * @throws EE_Error
215
+	 */
216
+	public static function get_currency_config($CNT_ISO = '')
217
+	{
218
+		//if CNT_ISO passed lets try to get currency settings for it.
219
+		$currency_config = $CNT_ISO !== ''
220
+			? new EE_Currency_Config($CNT_ISO)
221
+			: null;
222
+		//default currency settings for site if not set
223
+		if (! $currency_config instanceof EE_Currency_Config) {
224
+			$currency_config = EE_Registry::instance()->CFG->currency instanceof EE_Currency_Config
225
+				? EE_Registry::instance()->CFG->currency
226
+				: new EE_Currency_Config();
227
+		}
228
+		return $currency_config;
229
+	}
230 230
 
231 231
 } //end class EEH_Money
Please login to merge, or discard this patch.
Spacing   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -20,7 +20,7 @@  discard block
 block discarded – undo
20 20
  *
21 21
  * ------------------------------------------------------------------------
22 22
  */
23
-class EEH_Money extends EEH_Base  {
23
+class EEH_Money extends EEH_Base {
24 24
 
25 25
 
26 26
     /**
@@ -61,9 +61,9 @@  discard block
 block discarded – undo
61 61
      * @return float
62 62
      * @throws EE_Error
63 63
      */
64
-	public static function convert_to_float_from_localized_money($money_value ) {
64
+	public static function convert_to_float_from_localized_money($money_value) {
65 65
 		//float it! and round to three decimal places
66
-        return round ( (float) EEH_Money::strip_localized_money_formatting($money_value), 3 );
66
+        return round((float) EEH_Money::strip_localized_money_formatting($money_value), 3);
67 67
 	}
68 68
 
69 69
 
@@ -82,12 +82,12 @@  discard block
 block discarded – undo
82 82
 	 * @throws EE_Error
83 83
 	 */
84 84
 
85
-	public static function compare_floats( $float1, $float2, $operator='=' ) {
85
+	public static function compare_floats($float1, $float2, $operator = '=') {
86 86
 		// Check numbers to 5 digits of precision
87 87
 		$epsilon = 0.00001;
88 88
 
89
-		$float1 = (float)$float1;
90
-		$float2 = (float)$float2;
89
+		$float1 = (float) $float1;
90
+		$float2 = (float) $float2;
91 91
 
92 92
 		switch ($operator) {
93 93
 			// equal
@@ -143,7 +143,7 @@  discard block
 block discarded – undo
143 143
 				}
144 144
 				break;
145 145
 			default:
146
-				throw new EE_Error(__( "Unknown operator '" . $operator . "' in EEH_Money::compare_floats()", 'event_espresso' ) );
146
+				throw new EE_Error(__("Unknown operator '".$operator."' in EEH_Money::compare_floats()", 'event_espresso'));
147 147
 		}
148 148
 
149 149
 		return false;
@@ -159,14 +159,14 @@  discard block
 block discarded – undo
159 159
      * @return string
160 160
      * @throws EE_Error
161 161
      */
162
-	public static function get_format_for_jqplot( $CNT_ISO = '') {
162
+	public static function get_format_for_jqplot($CNT_ISO = '') {
163 163
 		//default format
164 164
 		$format = 'f';
165 165
 		$currency_config = $currency_config = EEH_Money::get_currency_config($CNT_ISO);
166 166
         //first get the decimal place and number of places
167
-		$format = "%'." . $currency_config->dec_plc . $format;
167
+		$format = "%'.".$currency_config->dec_plc.$format;
168 168
 		//currency symbol on right side.
169
-		$format = $currency_config->sign_b4 ? $currency_config->sign . $format : $format . $currency_config->sign;
169
+		$format = $currency_config->sign_b4 ? $currency_config->sign.$format : $format.$currency_config->sign;
170 170
 		return $format;
171 171
 	}
172 172
 
@@ -182,20 +182,20 @@  discard block
 block discarded – undo
182 182
      * @return string
183 183
      * @throws EE_Error
184 184
      */
185
-	public static function get_format_for_google_charts( $CNT_ISO = '' ) {
185
+	public static function get_format_for_google_charts($CNT_ISO = '') {
186 186
 		$currency_config = EEH_Money::get_currency_config($CNT_ISO);
187
-		$decimal_places_placeholder = str_pad( '', $currency_config->dec_plc, '0' );
187
+		$decimal_places_placeholder = str_pad('', $currency_config->dec_plc, '0');
188 188
 		//first get the decimal place and number of places
189
-		$format = '#,##0.' . $decimal_places_placeholder;
189
+		$format = '#,##0.'.$decimal_places_placeholder;
190 190
 
191 191
 		//currency symbol on right side.
192
-		$format = $currency_config->sign_b4 ? $currency_config->sign . $format : $format . $currency_config->sign;
192
+		$format = $currency_config->sign_b4 ? $currency_config->sign.$format : $format.$currency_config->sign;
193 193
 		$formatterObject = array(
194 194
 			'decimalSymbol' => $currency_config->dec_mrk,
195 195
 			'groupingSymbol' => $currency_config->thsnds,
196 196
 			'fractionDigits' => $currency_config->dec_plc,
197 197
 		);
198
-		if ( $currency_config->sign_b4 ) {
198
+		if ($currency_config->sign_b4) {
199 199
 			$formatterObject['prefix'] = $currency_config->sign;
200 200
 		} else {
201 201
 			$formatterObject['suffix'] = $currency_config->sign;
@@ -220,7 +220,7 @@  discard block
 block discarded – undo
220 220
             ? new EE_Currency_Config($CNT_ISO)
221 221
             : null;
222 222
         //default currency settings for site if not set
223
-        if (! $currency_config instanceof EE_Currency_Config) {
223
+        if ( ! $currency_config instanceof EE_Currency_Config) {
224 224
             $currency_config = EE_Registry::instance()->CFG->currency instanceof EE_Currency_Config
225 225
                 ? EE_Registry::instance()->CFG->currency
226 226
                 : new EE_Currency_Config();
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/services/loaders/CoreLoader.php 3 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -38,7 +38,7 @@
 block discarded – undo
38 38
      */
39 39
     public function __construct($generator)
40 40
     {
41
-        if(!($generator instanceof EE_Registry || $generator instanceof CoffeeShop)) {
41
+        if ( ! ($generator instanceof EE_Registry || $generator instanceof CoffeeShop)) {
42 42
             throw new InvalidArgumentException(
43 43
                 esc_html__(
44 44
                     'The CoreLoader class must receive an instance of EE_Registry or the CoffeeShop DI container.',
Please login to merge, or discard this patch.
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -33,7 +33,7 @@
 block discarded – undo
33 33
     /**
34 34
      * CoreLoader constructor.
35 35
      *
36
-     * @param EE_Registry|CoffeeShop $generator
36
+     * @param EE_Registry $generator
37 37
      * @throws InvalidArgumentException
38 38
      */
39 39
     public function __construct($generator)
Please login to merge, or discard this patch.
Indentation   +52 added lines, -52 removed lines patch added patch discarded remove patch
@@ -23,58 +23,58 @@
 block discarded – undo
23 23
 class CoreLoader implements LoaderInterface
24 24
 {
25 25
 
26
-    /**
27
-     * @var EE_Registry|CoffeeShop $generator
28
-     */
29
-    private $generator;
30
-
31
-
32
-
33
-    /**
34
-     * CoreLoader constructor.
35
-     *
36
-     * @param EE_Registry|CoffeeShop $generator
37
-     * @throws InvalidArgumentException
38
-     */
39
-    public function __construct($generator)
40
-    {
41
-        if(!($generator instanceof EE_Registry || $generator instanceof CoffeeShop)) {
42
-            throw new InvalidArgumentException(
43
-                esc_html__(
44
-                    'The CoreLoader class must receive an instance of EE_Registry or the CoffeeShop DI container.',
45
-                    'event_espresso'
46
-                )
47
-            );
48
-        }
49
-        $this->generator = $generator;
50
-    }
51
-
52
-
53
-
54
-    /**
55
-     * @param string $fqcn
56
-     * @param array  $arguments
57
-     * @return mixed
58
-     * @throws ServiceNotFoundException
59
-     */
60
-    public function load($fqcn, $arguments = array())
61
-    {
62
-        return $this->generator instanceof EE_Registry
63
-            ? $this->generator->create($fqcn, $arguments)
64
-            : $this->generator->brew($fqcn, $arguments);
65
-    }
66
-
67
-
68
-
69
-    /**
70
-     * calls reset() on generator if method exists
71
-     */
72
-    public function reset()
73
-    {
74
-        if (method_exists($this->generator, 'reset')) {
75
-            $this->generator->reset();
76
-        }
77
-    }
26
+	/**
27
+	 * @var EE_Registry|CoffeeShop $generator
28
+	 */
29
+	private $generator;
30
+
31
+
32
+
33
+	/**
34
+	 * CoreLoader constructor.
35
+	 *
36
+	 * @param EE_Registry|CoffeeShop $generator
37
+	 * @throws InvalidArgumentException
38
+	 */
39
+	public function __construct($generator)
40
+	{
41
+		if(!($generator instanceof EE_Registry || $generator instanceof CoffeeShop)) {
42
+			throw new InvalidArgumentException(
43
+				esc_html__(
44
+					'The CoreLoader class must receive an instance of EE_Registry or the CoffeeShop DI container.',
45
+					'event_espresso'
46
+				)
47
+			);
48
+		}
49
+		$this->generator = $generator;
50
+	}
51
+
52
+
53
+
54
+	/**
55
+	 * @param string $fqcn
56
+	 * @param array  $arguments
57
+	 * @return mixed
58
+	 * @throws ServiceNotFoundException
59
+	 */
60
+	public function load($fqcn, $arguments = array())
61
+	{
62
+		return $this->generator instanceof EE_Registry
63
+			? $this->generator->create($fqcn, $arguments)
64
+			: $this->generator->brew($fqcn, $arguments);
65
+	}
66
+
67
+
68
+
69
+	/**
70
+	 * calls reset() on generator if method exists
71
+	 */
72
+	public function reset()
73
+	{
74
+		if (method_exists($this->generator, 'reset')) {
75
+			$this->generator->reset();
76
+		}
77
+	}
78 78
 
79 79
 }
80 80
 // End of file CoreLoader.php
Please login to merge, or discard this patch.
core/services/loaders/LoaderDecorator.php 1 patch
Indentation   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -19,22 +19,22 @@
 block discarded – undo
19 19
 {
20 20
 
21 21
 
22
-    /**
23
-     * @var LoaderInterface $loader
24
-     */
25
-    protected $loader;
26
-
27
-
28
-
29
-    /**
30
-     * LoaderDecorator constructor.
31
-     *
32
-     * @param LoaderInterface $loader
33
-     */
34
-    public function __construct(LoaderInterface $loader)
35
-    {
36
-        $this->loader = $loader;
37
-    }
22
+	/**
23
+	 * @var LoaderInterface $loader
24
+	 */
25
+	protected $loader;
26
+
27
+
28
+
29
+	/**
30
+	 * LoaderDecorator constructor.
31
+	 *
32
+	 * @param LoaderInterface $loader
33
+	 */
34
+	public function __construct(LoaderInterface $loader)
35
+	{
36
+		$this->loader = $loader;
37
+	}
38 38
 
39 39
 
40 40
 
Please login to merge, or discard this patch.