Completed
Branch models-cleanup/main (de94a1)
by
unknown
14:03 queued 11:37
created
core/db_classes/EE_Currency.class.php 1 patch
Indentation   +234 added lines, -234 removed lines patch added patch discarded remove patch
@@ -10,238 +10,238 @@
 block discarded – undo
10 10
 class EE_Currency extends EE_Base_Class
11 11
 {
12 12
 
13
-    /** Currency COde
14
-     *
15
-     * @var CUR_code
16
-     */
17
-    protected $_CUR_code = null;
18
-
19
-    /** Currency Name Singular
20
-     *
21
-     * @var CUR_single
22
-     */
23
-    protected $_CUR_single = null;
24
-
25
-    /** Currency Name Plural
26
-     *
27
-     * @var CUR_plural
28
-     */
29
-    protected $_CUR_plural = null;
30
-
31
-    /** Currency Sign
32
-     *
33
-     * @var CUR_sign
34
-     */
35
-    protected $_CUR_sign = null;
36
-
37
-    /** Currency Decimal Places
38
-     *
39
-     * @var CUR_dec_plc
40
-     */
41
-    protected $_CUR_dec_plc = null;
42
-
43
-    /** Active?
44
-     *
45
-     * @var CUR_active
46
-     */
47
-    protected $_CUR_active = null;
48
-
49
-    protected $_Payment_Method;
50
-
51
-
52
-    /**
53
-     * @param array  $props_n_values          incoming values
54
-     * @param string $timezone                incoming timezone
55
-     *                                        (if not set the timezone set for the website will be used.)
56
-     * @param array  $date_formats            incoming date_formats in an array where the first value is the
57
-     *                                        date_format and the second value is the time format
58
-     * @return EE_Currency
59
-     * @throws EE_Error
60
-     * @throws ReflectionException
61
-     */
62
-    public static function new_instance($props_n_values = [], $timezone = '', $date_formats = [])
63
-    {
64
-        $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats);
65
-        return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats);
66
-    }
67
-
68
-
69
-    /**
70
-     * @param array  $props_n_values  incoming values from the database
71
-     * @param string $timezone        incoming timezone as set by the model.
72
-     *                                If not set the timezone for the website will be used.
73
-     * @return EE_Currency
74
-     * @throws EE_Error
75
-     * @throws ReflectionException
76
-     */
77
-    public static function new_instance_from_db($props_n_values = [], $timezone = '')
78
-    {
79
-        return new self($props_n_values, true, $timezone);
80
-    }
81
-
82
-
83
-    /**
84
-     * Sets code
85
-     *
86
-     * @param string $code
87
-     * @throws EE_Error
88
-     * @throws ReflectionException
89
-     */
90
-    public function set_code($code)
91
-    {
92
-        $this->set('CUR_code', $code);
93
-    }
94
-
95
-
96
-    /**
97
-     * Gets active
98
-     *
99
-     * @return boolean
100
-     * @throws EE_Error
101
-     */
102
-    public function active()
103
-    {
104
-        return $this->get('CUR_active');
105
-    }
106
-
107
-
108
-    /**
109
-     * Sets active
110
-     *
111
-     * @param boolean $active
112
-     * @throws EE_Error
113
-     * @throws ReflectionException
114
-     */
115
-    public function set_active($active)
116
-    {
117
-        $this->set('CUR_active', $active);
118
-    }
119
-
120
-
121
-    /**
122
-     * Gets dec_plc
123
-     *
124
-     * @return int
125
-     * @throws EE_Error
126
-     */
127
-    public function dec_plc()
128
-    {
129
-        return $this->get('CUR_dec_plc');
130
-    }
131
-
132
-
133
-    /**
134
-     * Sets dec_plc
135
-     *
136
-     * @param int $dec_plc
137
-     * @throws EE_Error
138
-     * @throws ReflectionException
139
-     */
140
-    public function set_dec_plc($dec_plc)
141
-    {
142
-        $this->set('CUR_dec_plc', $dec_plc);
143
-    }
144
-
145
-
146
-    /**
147
-     * Sets plural
148
-     *
149
-     * @param string $plural
150
-     * @throws EE_Error
151
-     * @throws ReflectionException
152
-     */
153
-    public function set_plural_name($plural)
154
-    {
155
-        $this->set('CUR_plural', $plural);
156
-    }
157
-
158
-
159
-    /**
160
-     * Gets sign
161
-     *
162
-     * @return string
163
-     * @throws EE_Error
164
-     */
165
-    public function sign()
166
-    {
167
-        return $this->get('CUR_sign');
168
-    }
169
-
170
-
171
-    /**
172
-     * Sets sign
173
-     *
174
-     * @param string $sign
175
-     * @throws EE_Error
176
-     * @throws ReflectionException
177
-     */
178
-    public function set_sign($sign)
179
-    {
180
-        $this->set('CUR_sign', $sign);
181
-    }
182
-
183
-
184
-    /**
185
-     * Gets single
186
-     *
187
-     * @return string
188
-     * @throws EE_Error
189
-     */
190
-    public function singular_name()
191
-    {
192
-        return $this->get('CUR_single');
193
-    }
194
-
195
-
196
-    /**
197
-     * Sets single
198
-     *
199
-     * @param string $single
200
-     * @throws EE_Error
201
-     * @throws ReflectionException
202
-     */
203
-    public function set_singular_name($single)
204
-    {
205
-        $this->set('CUR_single', $single);
206
-    }
207
-
208
-
209
-    /**
210
-     * Gets a prettier name
211
-     *
212
-     * @return string
213
-     * @throws EE_Error
214
-     */
215
-    public function name()
216
-    {
217
-        return sprintf(
218
-            esc_html__("%s (%s)", "event_espresso"),
219
-            $this->code(),
220
-            $this->plural_name()
221
-        );
222
-    }
223
-
224
-
225
-    /**
226
-     * Gets code
227
-     *
228
-     * @return string
229
-     * @throws EE_Error
230
-     */
231
-    public function code()
232
-    {
233
-        return $this->get('CUR_code');
234
-    }
235
-
236
-
237
-    /**
238
-     * Gets plural
239
-     *
240
-     * @return string
241
-     * @throws EE_Error
242
-     */
243
-    public function plural_name()
244
-    {
245
-        return $this->get('CUR_plural');
246
-    }
13
+	/** Currency COde
14
+	 *
15
+	 * @var CUR_code
16
+	 */
17
+	protected $_CUR_code = null;
18
+
19
+	/** Currency Name Singular
20
+	 *
21
+	 * @var CUR_single
22
+	 */
23
+	protected $_CUR_single = null;
24
+
25
+	/** Currency Name Plural
26
+	 *
27
+	 * @var CUR_plural
28
+	 */
29
+	protected $_CUR_plural = null;
30
+
31
+	/** Currency Sign
32
+	 *
33
+	 * @var CUR_sign
34
+	 */
35
+	protected $_CUR_sign = null;
36
+
37
+	/** Currency Decimal Places
38
+	 *
39
+	 * @var CUR_dec_plc
40
+	 */
41
+	protected $_CUR_dec_plc = null;
42
+
43
+	/** Active?
44
+	 *
45
+	 * @var CUR_active
46
+	 */
47
+	protected $_CUR_active = null;
48
+
49
+	protected $_Payment_Method;
50
+
51
+
52
+	/**
53
+	 * @param array  $props_n_values          incoming values
54
+	 * @param string $timezone                incoming timezone
55
+	 *                                        (if not set the timezone set for the website will be used.)
56
+	 * @param array  $date_formats            incoming date_formats in an array where the first value is the
57
+	 *                                        date_format and the second value is the time format
58
+	 * @return EE_Currency
59
+	 * @throws EE_Error
60
+	 * @throws ReflectionException
61
+	 */
62
+	public static function new_instance($props_n_values = [], $timezone = '', $date_formats = [])
63
+	{
64
+		$has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats);
65
+		return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats);
66
+	}
67
+
68
+
69
+	/**
70
+	 * @param array  $props_n_values  incoming values from the database
71
+	 * @param string $timezone        incoming timezone as set by the model.
72
+	 *                                If not set the timezone for the website will be used.
73
+	 * @return EE_Currency
74
+	 * @throws EE_Error
75
+	 * @throws ReflectionException
76
+	 */
77
+	public static function new_instance_from_db($props_n_values = [], $timezone = '')
78
+	{
79
+		return new self($props_n_values, true, $timezone);
80
+	}
81
+
82
+
83
+	/**
84
+	 * Sets code
85
+	 *
86
+	 * @param string $code
87
+	 * @throws EE_Error
88
+	 * @throws ReflectionException
89
+	 */
90
+	public function set_code($code)
91
+	{
92
+		$this->set('CUR_code', $code);
93
+	}
94
+
95
+
96
+	/**
97
+	 * Gets active
98
+	 *
99
+	 * @return boolean
100
+	 * @throws EE_Error
101
+	 */
102
+	public function active()
103
+	{
104
+		return $this->get('CUR_active');
105
+	}
106
+
107
+
108
+	/**
109
+	 * Sets active
110
+	 *
111
+	 * @param boolean $active
112
+	 * @throws EE_Error
113
+	 * @throws ReflectionException
114
+	 */
115
+	public function set_active($active)
116
+	{
117
+		$this->set('CUR_active', $active);
118
+	}
119
+
120
+
121
+	/**
122
+	 * Gets dec_plc
123
+	 *
124
+	 * @return int
125
+	 * @throws EE_Error
126
+	 */
127
+	public function dec_plc()
128
+	{
129
+		return $this->get('CUR_dec_plc');
130
+	}
131
+
132
+
133
+	/**
134
+	 * Sets dec_plc
135
+	 *
136
+	 * @param int $dec_plc
137
+	 * @throws EE_Error
138
+	 * @throws ReflectionException
139
+	 */
140
+	public function set_dec_plc($dec_plc)
141
+	{
142
+		$this->set('CUR_dec_plc', $dec_plc);
143
+	}
144
+
145
+
146
+	/**
147
+	 * Sets plural
148
+	 *
149
+	 * @param string $plural
150
+	 * @throws EE_Error
151
+	 * @throws ReflectionException
152
+	 */
153
+	public function set_plural_name($plural)
154
+	{
155
+		$this->set('CUR_plural', $plural);
156
+	}
157
+
158
+
159
+	/**
160
+	 * Gets sign
161
+	 *
162
+	 * @return string
163
+	 * @throws EE_Error
164
+	 */
165
+	public function sign()
166
+	{
167
+		return $this->get('CUR_sign');
168
+	}
169
+
170
+
171
+	/**
172
+	 * Sets sign
173
+	 *
174
+	 * @param string $sign
175
+	 * @throws EE_Error
176
+	 * @throws ReflectionException
177
+	 */
178
+	public function set_sign($sign)
179
+	{
180
+		$this->set('CUR_sign', $sign);
181
+	}
182
+
183
+
184
+	/**
185
+	 * Gets single
186
+	 *
187
+	 * @return string
188
+	 * @throws EE_Error
189
+	 */
190
+	public function singular_name()
191
+	{
192
+		return $this->get('CUR_single');
193
+	}
194
+
195
+
196
+	/**
197
+	 * Sets single
198
+	 *
199
+	 * @param string $single
200
+	 * @throws EE_Error
201
+	 * @throws ReflectionException
202
+	 */
203
+	public function set_singular_name($single)
204
+	{
205
+		$this->set('CUR_single', $single);
206
+	}
207
+
208
+
209
+	/**
210
+	 * Gets a prettier name
211
+	 *
212
+	 * @return string
213
+	 * @throws EE_Error
214
+	 */
215
+	public function name()
216
+	{
217
+		return sprintf(
218
+			esc_html__("%s (%s)", "event_espresso"),
219
+			$this->code(),
220
+			$this->plural_name()
221
+		);
222
+	}
223
+
224
+
225
+	/**
226
+	 * Gets code
227
+	 *
228
+	 * @return string
229
+	 * @throws EE_Error
230
+	 */
231
+	public function code()
232
+	{
233
+		return $this->get('CUR_code');
234
+	}
235
+
236
+
237
+	/**
238
+	 * Gets plural
239
+	 *
240
+	 * @return string
241
+	 * @throws EE_Error
242
+	 */
243
+	public function plural_name()
244
+	{
245
+		return $this->get('CUR_plural');
246
+	}
247 247
 }
Please login to merge, or discard this patch.
core/db_classes/EE_Attendee.class.php 2 patches
Indentation   +803 added lines, -803 removed lines patch added patch discarded remove patch
@@ -13,807 +13,807 @@
 block discarded – undo
13 13
 class EE_Attendee extends EE_CPT_Base implements EEI_Contact, EEI_Address, EEI_Admin_Links, EEI_Attendee
14 14
 {
15 15
 
16
-    /**
17
-     * Sets some dynamic defaults
18
-     *
19
-     * @param array  $fieldValues
20
-     * @param bool   $bydb
21
-     * @param string $timezone
22
-     * @param array  $date_formats
23
-     * @throws EE_Error
24
-     * @throws ReflectionException
25
-     */
26
-    protected function __construct($fieldValues = null, $bydb = false, $timezone = '', $date_formats = [])
27
-    {
28
-        if (! isset($fieldValues['ATT_full_name'])) {
29
-            $fname                        = isset($fieldValues['ATT_fname']) ? $fieldValues['ATT_fname'] . ' ' : '';
30
-            $lname                        = isset($fieldValues['ATT_lname']) ? $fieldValues['ATT_lname'] : '';
31
-            $fieldValues['ATT_full_name'] = $fname . $lname;
32
-        }
33
-        if (! isset($fieldValues['ATT_slug'])) {
34
-            // $fieldValues['ATT_slug'] = sanitize_key(wp_generate_password(20));
35
-            $fieldValues['ATT_slug'] = sanitize_title($fieldValues['ATT_full_name']);
36
-        }
37
-        if (! isset($fieldValues['ATT_short_bio']) && isset($fieldValues['ATT_bio'])) {
38
-            $fieldValues['ATT_short_bio'] = substr($fieldValues['ATT_bio'], 0, 50);
39
-        }
40
-        parent::__construct($fieldValues, $bydb, $timezone, $date_formats);
41
-    }
42
-
43
-
44
-    /**
45
-     * @param array  $props_n_values    incoming values
46
-     * @param string $timezone          incoming timezone
47
-     *                                  (if not set the timezone set for the website will be used.)
48
-     * @param array  $date_formats      incoming date_formats in an array where the first value is the
49
-     *                                  date_format and the second value is the time format
50
-     * @return EE_Attendee
51
-     * @throws EE_Error
52
-     * @throws ReflectionException
53
-     */
54
-    public static function new_instance($props_n_values = [], $timezone = '', $date_formats = [])
55
-    {
56
-        $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats);
57
-        return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats);
58
-    }
59
-
60
-
61
-    /**
62
-     * @param array  $props_n_values  incoming values from the database
63
-     * @param string $timezone        incoming timezone as set by the model.
64
-     *                                If not set the timezone for the website will be used.
65
-     * @return EE_Attendee
66
-     * @throws EE_Error
67
-     * @throws EE_Error
68
-     * @throws ReflectionException
69
-     */
70
-    public static function new_instance_from_db($props_n_values = [], $timezone = '')
71
-    {
72
-        return new self($props_n_values, true, $timezone);
73
-    }
74
-
75
-
76
-    /**
77
-     * Set Attendee First Name
78
-     *
79
-     * @param string $fname
80
-     * @throws EE_Error
81
-     * @throws ReflectionException
82
-     */
83
-    public function set_fname($fname = '')
84
-    {
85
-        $this->set('ATT_fname', $fname);
86
-    }
87
-
88
-
89
-    /**
90
-     * Set Attendee Last Name
91
-     *
92
-     * @param string $lname
93
-     * @throws EE_Error
94
-     * @throws ReflectionException
95
-     */
96
-    public function set_lname($lname = '')
97
-    {
98
-        $this->set('ATT_lname', $lname);
99
-    }
100
-
101
-
102
-    /**
103
-     * Set Attendee Address
104
-     *
105
-     * @param string $address
106
-     * @throws EE_Error
107
-     * @throws ReflectionException
108
-     */
109
-    public function set_address($address = '')
110
-    {
111
-        $this->set('ATT_address', $address);
112
-    }
113
-
114
-
115
-    /**
116
-     * Set Attendee Address2
117
-     *
118
-     * @param string $address2
119
-     * @throws EE_Error
120
-     * @throws ReflectionException
121
-     */
122
-    public function set_address2($address2 = '')
123
-    {
124
-        $this->set('ATT_address2', $address2);
125
-    }
126
-
127
-
128
-    /**
129
-     * Set Attendee City
130
-     *
131
-     * @param string $city
132
-     * @throws EE_Error
133
-     * @throws ReflectionException
134
-     */
135
-    public function set_city($city = '')
136
-    {
137
-        $this->set('ATT_city', $city);
138
-    }
139
-
140
-
141
-    /**
142
-     * Set Attendee State ID
143
-     *
144
-     * @param int $STA_ID
145
-     * @throws EE_Error
146
-     * @throws ReflectionException
147
-     */
148
-    public function set_state($STA_ID = 0)
149
-    {
150
-        $this->set('STA_ID', $STA_ID);
151
-    }
152
-
153
-
154
-    /**
155
-     * Set Attendee Country ISO Code
156
-     *
157
-     * @param string $CNT_ISO
158
-     * @throws EE_Error
159
-     * @throws ReflectionException
160
-     */
161
-    public function set_country($CNT_ISO = '')
162
-    {
163
-        $this->set('CNT_ISO', $CNT_ISO);
164
-    }
165
-
166
-
167
-    /**
168
-     * Set Attendee Zip/Postal Code
169
-     *
170
-     * @param string $zip
171
-     * @throws EE_Error
172
-     * @throws ReflectionException
173
-     */
174
-    public function set_zip($zip = '')
175
-    {
176
-        $this->set('ATT_zip', $zip);
177
-    }
178
-
179
-
180
-    /**
181
-     * Set Attendee Email Address
182
-     *
183
-     * @param string $email
184
-     * @throws EE_Error
185
-     * @throws ReflectionException
186
-     */
187
-    public function set_email($email = '')
188
-    {
189
-        $this->set('ATT_email', $email);
190
-    }
191
-
192
-
193
-    /**
194
-     * Set Attendee Phone
195
-     *
196
-     * @param string $phone
197
-     * @throws EE_Error
198
-     * @throws ReflectionException
199
-     */
200
-    public function set_phone($phone = '')
201
-    {
202
-        $this->set('ATT_phone', $phone);
203
-    }
204
-
205
-
206
-    /**
207
-     * set deleted
208
-     *
209
-     * @param bool $ATT_deleted
210
-     * @throws EE_Error
211
-     * @throws ReflectionException
212
-     */
213
-    public function set_deleted($ATT_deleted = false)
214
-    {
215
-        $this->set('ATT_deleted', $ATT_deleted);
216
-    }
217
-
218
-
219
-    /**
220
-     * Returns the value for the post_author id saved with the cpt
221
-     *
222
-     * @return int
223
-     * @throws EE_Error
224
-     * @since 4.5.0
225
-     */
226
-    public function wp_user()
227
-    {
228
-        return $this->get('ATT_author');
229
-    }
230
-
231
-
232
-    /**
233
-     * echoes out the attendee's first name
234
-     *
235
-     * @return void
236
-     * @throws EE_Error
237
-     */
238
-    public function e_full_name()
239
-    {
240
-        echo $this->full_name();
241
-    }
242
-
243
-
244
-    /**
245
-     * Returns the first and last name concatenated together with a space.
246
-     *
247
-     * @param bool $apply_html_entities
248
-     * @return string
249
-     * @throws EE_Error
250
-     */
251
-    public function full_name($apply_html_entities = false)
252
-    {
253
-        $full_name = [
254
-            $this->fname(),
255
-            $this->lname(),
256
-        ];
257
-        $full_name = array_filter($full_name);
258
-        $full_name = implode(' ', $full_name);
259
-        return $apply_html_entities
260
-            ? htmlentities($full_name, ENT_QUOTES, 'UTF-8')
261
-            : $full_name;
262
-    }
263
-
264
-
265
-    /**
266
-     * get Attendee First Name
267
-     *
268
-     * @return string
269
-     * @throws EE_Error
270
-     */
271
-    public function fname()
272
-    {
273
-        return $this->get('ATT_fname');
274
-    }
275
-
276
-
277
-    /**
278
-     * get Attendee Last Name
279
-     *
280
-     * @return string
281
-     * @throws EE_Error
282
-     */
283
-    public function lname()
284
-    {
285
-        return $this->get('ATT_lname');
286
-    }
287
-
288
-
289
-    /**
290
-     * get Attendee Email Address
291
-     *
292
-     * @return string
293
-     * @throws EE_Error
294
-     */
295
-    public function email()
296
-    {
297
-        return $this->get('ATT_email');
298
-    }
299
-
300
-
301
-    /**
302
-     * get Attendee Phone #
303
-     *
304
-     * @return string
305
-     * @throws EE_Error
306
-     */
307
-    public function phone()
308
-    {
309
-        return $this->get('ATT_phone');
310
-    }
311
-
312
-
313
-    /**
314
-     * This returns the value of the `ATT_full_name` field
315
-     * which is usually equivalent to calling `full_name()`
316
-     * unless the post_title field has been directly modified
317
-     * in the db for the post (espresso_attendees post type)
318
-     * for this attendee.
319
-     *
320
-     * @param bool $apply_html_entities
321
-     * @return string
322
-     * @throws EE_Error
323
-     */
324
-    public function ATT_full_name($apply_html_entities = false)
325
-    {
326
-        return $apply_html_entities
327
-            ? htmlentities(
328
-                $this->get('ATT_full_name'),
329
-                ENT_QUOTES,
330
-                'UTF-8'
331
-            )
332
-            : $this->get('ATT_full_name');
333
-    }
334
-
335
-
336
-    /**
337
-     * get Attendee bio
338
-     *
339
-     * @return string
340
-     * @throws EE_Error
341
-     */
342
-    public function bio()
343
-    {
344
-        return $this->get('ATT_bio');
345
-    }
346
-
347
-
348
-    /**
349
-     * get Attendee short bio
350
-     *
351
-     * @return string
352
-     * @throws EE_Error
353
-     */
354
-    public function short_bio()
355
-    {
356
-        return $this->get('ATT_short_bio');
357
-    }
358
-
359
-
360
-    /**
361
-     * Gets the attendee's full address as an array
362
-     * so client code can decide hwo to display it
363
-     *
364
-     * @return array numerically indexed,
365
-     *               with each part of the address that is known.
366
-     *               Eg, if the user only responded to state and country,
367
-     *               it would be array(0=>'Alabama',1=>'USA')
368
-     * @return array
369
-     * @throws EE_Error
370
-     * @throws ReflectionException
371
-     */
372
-    public function full_address_as_array()
373
-    {
374
-        $full_address_array     = [];
375
-        $initial_address_fields = ['ATT_address', 'ATT_address2', 'ATT_city',];
376
-        foreach ($initial_address_fields as $address_field_name) {
377
-            $address_fields_value = $this->get($address_field_name);
378
-            if (! empty($address_fields_value)) {
379
-                $full_address_array[] = $address_fields_value;
380
-            }
381
-        }
382
-        // now handle state and country
383
-        $state_obj = $this->state_obj();
384
-        if ($state_obj instanceof EE_State) {
385
-            $full_address_array[] = $state_obj->name();
386
-        }
387
-        $country_obj = $this->country_obj();
388
-        if ($country_obj instanceof EE_Country) {
389
-            $full_address_array[] = $country_obj->name();
390
-        }
391
-        // lastly get the xip
392
-        $zip_value = $this->zip();
393
-        if (! empty($zip_value)) {
394
-            $full_address_array[] = $zip_value;
395
-        }
396
-        return $full_address_array;
397
-    }
398
-
399
-
400
-    /**
401
-     * Gets the state set to this attendee
402
-     *
403
-     * @return EE_Base_Class|EE_State
404
-     * @throws EE_Error
405
-     * @throws ReflectionException
406
-     */
407
-    public function state_obj()
408
-    {
409
-        return $this->get_first_related('State');
410
-    }
411
-
412
-
413
-    /**
414
-     * Gets country set for this attendee
415
-     *
416
-     * @return EE_Base_Class|EE_Country
417
-     * @throws EE_Error
418
-     * @throws ReflectionException
419
-     */
420
-    public function country_obj()
421
-    {
422
-        return $this->get_first_related('Country');
423
-    }
424
-
425
-
426
-    /**
427
-     * get Attendee Zip/Postal Code
428
-     *
429
-     * @return string
430
-     * @throws EE_Error
431
-     */
432
-    public function zip()
433
-    {
434
-        return $this->get('ATT_zip');
435
-    }
436
-
437
-
438
-    /**
439
-     * get deleted
440
-     *
441
-     * @return        bool
442
-     * @throws EE_Error
443
-     */
444
-    public function deleted()
445
-    {
446
-        return $this->get('ATT_deleted');
447
-    }
448
-
449
-
450
-    /**
451
-     * Gets registrations of this attendee
452
-     *
453
-     * @param array $query_params
454
-     * @return array[]|EE_Base_Class[]|EE_Registration[]
455
-     * @throws EE_Error
456
-     * @throws ReflectionException
457
-     */
458
-    public function get_registrations($query_params = [])
459
-    {
460
-        return $this->get_many_related('Registration', $query_params);
461
-    }
462
-
463
-
464
-    /**
465
-     * Gets the most recent registration of this attendee
466
-     *
467
-     * @return EE_Base_Class|EE_Registration
468
-     * @throws EE_Error
469
-     * @throws ReflectionException
470
-     */
471
-    public function get_most_recent_registration()
472
-    {
473
-        return $this->get_first_related(
474
-            'Registration',
475
-            ['order_by' => ['REG_date' => 'DESC']]
476
-        ); // null, 'REG_date', 'DESC', '=', 'OBJECT_K');
477
-    }
478
-
479
-
480
-    /**
481
-     * Gets the most recent registration for this attend at this event
482
-     *
483
-     * @param int $event_id
484
-     * @return EE_Base_Class|EE_Registration
485
-     * @throws EE_Error
486
-     * @throws ReflectionException
487
-     */
488
-    public function get_most_recent_registration_for_event($event_id)
489
-    {
490
-        return $this->get_first_related(
491
-            'Registration',
492
-            [['EVT_ID' => $event_id], 'order_by' => ['REG_date' => 'DESC']]
493
-        );
494
-    }
495
-
496
-
497
-    /**
498
-     * returns any events attached to this attendee ($_Event property);
499
-     *
500
-     * @return array
501
-     * @throws EE_Error
502
-     * @throws ReflectionException
503
-     */
504
-    public function events()
505
-    {
506
-        return $this->get_many_related('Event');
507
-    }
508
-
509
-
510
-    /**
511
-     * @return string
512
-     * @throws EE_Error
513
-     * @throws ReflectionException
514
-     */
515
-    public function state_abbrev()
516
-    {
517
-        return $this->state_obj() instanceof EE_State ? $this->state_obj()->abbrev() : '';
518
-    }
519
-
520
-
521
-    /**
522
-     * Gets the billing info array where keys match espresso_reg_page_billing_inputs(),
523
-     * and keys are their cleaned values.
524
-     *
525
-     * @param EE_Payment_Method $payment_method the _gateway_name property on the gateway class
526
-     * @return EE_Form_Section_Proper|null
527
-     * @throws EE_Error
528
-     * @see EE_Attendee::save_and_clean_billing_info_for_payment_method() which was
529
-     *                                          used to save the billing info
530
-     */
531
-    public function billing_info_for_payment_method($payment_method)
532
-    {
533
-        $pm_type = $payment_method->type_obj();
534
-        if (! $pm_type instanceof EE_PMT_Base) {
535
-            return null;
536
-        }
537
-        $billing_info = $this->get_post_meta($this->get_billing_info_postmeta_name($payment_method), true);
538
-        if (! $billing_info) {
539
-            return null;
540
-        }
541
-        $billing_form = $pm_type->billing_form();
542
-        // double-check the form isn't totally hidden, in which case pretend there is no form
543
-        $form_totally_hidden = true;
544
-        foreach ($billing_form->inputs_in_subsections() as $input) {
545
-            if (! $input->get_display_strategy() instanceof EE_Hidden_Display_Strategy) {
546
-                $form_totally_hidden = false;
547
-                break;
548
-            }
549
-        }
550
-        if ($form_totally_hidden) {
551
-            return null;
552
-        }
553
-        if ($billing_form instanceof EE_Form_Section_Proper) {
554
-            $billing_form->receive_form_submission([$billing_form->name() => $billing_info], false);
555
-        }
556
-
557
-        return $billing_form;
558
-    }
559
-
560
-
561
-    /**
562
-     * Gets the postmeta key that holds this attendee's billing info for the
563
-     * specified payment method
564
-     *
565
-     * @param EE_Payment_Method $payment_method
566
-     * @return string
567
-     * @throws EE_Error
568
-     */
569
-    public function get_billing_info_postmeta_name($payment_method)
570
-    {
571
-        if ($payment_method->type_obj() instanceof EE_PMT_Base) {
572
-            return 'billing_info_' . $payment_method->type_obj()->system_name();
573
-        }
574
-        return null;
575
-    }
576
-
577
-
578
-    /**
579
-     * Saves the billing info to the attendee. @param EE_Billing_Attendee_Info_Form $billing_form
580
-     *
581
-     * @param EE_Payment_Method $payment_method
582
-     * @return boolean
583
-     * @throws EE_Error
584
-     * @see EE_Attendee::billing_info_for_payment_method() which is used to
585
-     *      retrieve it
586
-     */
587
-    public function save_and_clean_billing_info_for_payment_method($billing_form, $payment_method)
588
-    {
589
-        if (! $billing_form instanceof EE_Billing_Attendee_Info_Form) {
590
-            EE_Error::add_error(
591
-                __('Cannot save billing info because there is none.', 'event_espresso'),
592
-                __FILE__,
593
-                __FUNCTION__,
594
-                __LINE__
595
-            );
596
-            return false;
597
-        }
598
-        $billing_form->clean_sensitive_data();
599
-        return update_post_meta(
600
-            $this->ID(),
601
-            $this->get_billing_info_postmeta_name($payment_method),
602
-            $billing_form->input_values(true)
603
-        );
604
-    }
605
-
606
-
607
-    /**
608
-     * Return the link to the admin details for the object.
609
-     *
610
-     * @return string
611
-     * @throws EE_Error
612
-     * @throws InvalidArgumentException
613
-     * @throws InvalidDataTypeException
614
-     * @throws InvalidInterfaceException
615
-     * @throws ReflectionException
616
-     */
617
-    public function get_admin_details_link()
618
-    {
619
-        return $this->get_admin_edit_link();
620
-    }
621
-
622
-
623
-    /**
624
-     * Returns the link to the editor for the object.  Sometimes this is the same as the details.
625
-     *
626
-     * @return string
627
-     * @throws EE_Error
628
-     * @throws InvalidArgumentException
629
-     * @throws ReflectionException
630
-     * @throws InvalidDataTypeException
631
-     * @throws InvalidInterfaceException
632
-     */
633
-    public function get_admin_edit_link()
634
-    {
635
-        EE_Registry::instance()->load_helper('URL');
636
-        return EEH_URL::add_query_args_and_nonce(
637
-            [
638
-                'page'   => 'espresso_registrations',
639
-                'action' => 'edit_attendee',
640
-                'post'   => $this->ID(),
641
-            ],
642
-            admin_url('admin.php')
643
-        );
644
-    }
645
-
646
-
647
-    /**
648
-     * get Attendee Address
649
-     *
650
-     * @return string
651
-     * @throws EE_Error
652
-     */
653
-    public function address()
654
-    {
655
-        return $this->get('ATT_address');
656
-    }
657
-
658
-
659
-    /**
660
-     * Returns the link to a settings page for the object.
661
-     *
662
-     * @return string
663
-     * @throws EE_Error
664
-     * @throws InvalidArgumentException
665
-     * @throws InvalidDataTypeException
666
-     * @throws InvalidInterfaceException
667
-     * @throws ReflectionException
668
-     */
669
-    public function get_admin_settings_link()
670
-    {
671
-        return $this->get_admin_edit_link();
672
-    }
673
-
674
-
675
-    /**
676
-     * Returns the link to the "overview" for the object (typically the "list table" view).
677
-     *
678
-     * @return string
679
-     * @throws EE_Error
680
-     * @throws InvalidArgumentException
681
-     * @throws ReflectionException
682
-     * @throws InvalidDataTypeException
683
-     * @throws InvalidInterfaceException
684
-     */
685
-    public function get_admin_overview_link()
686
-    {
687
-        EE_Registry::instance()->load_helper('URL');
688
-        return EEH_URL::add_query_args_and_nonce(
689
-            [
690
-                'page'   => 'espresso_registrations',
691
-                'action' => 'contact_list',
692
-            ],
693
-            admin_url('admin.php')
694
-        );
695
-    }
696
-
697
-
698
-
699
-
700
-
701
-
702
-
703
-
704
-    /**
705
-     * get Attendee Address2
706
-     *
707
-     * @return string
708
-     * @throws EE_Error
709
-     */
710
-    public function address2()
711
-    {
712
-        return $this->get('ATT_address2');
713
-    }
714
-
715
-
716
-    /**
717
-     * Returns the state's name, otherwise 'Unknown'
718
-     *
719
-     * @return string
720
-     * @throws EE_Error
721
-     * @throws ReflectionException
722
-     */
723
-    public function state_name()
724
-    {
725
-        if ($this->state_obj()) {
726
-            return $this->state_obj()->name();
727
-        } else {
728
-            return '';
729
-        }
730
-    }
731
-
732
-
733
-    /**
734
-     * get Attendee City
735
-     *
736
-     * @return string
737
-     * @throws EE_Error
738
-     */
739
-    public function city()
740
-    {
741
-        return $this->get('ATT_city');
742
-    }
743
-
744
-
745
-    /**
746
-     * either displays the state abbreviation or the state name, as determined
747
-     * by the "FHEE__EEI_Address__state__use_abbreviation" filter.
748
-     * defaults to abbreviation
749
-     *
750
-     * @return string
751
-     * @throws EE_Error
752
-     * @throws ReflectionException
753
-     */
754
-    public function state()
755
-    {
756
-        if (apply_filters('FHEE__EEI_Address__state__use_abbreviation', true, $this->state_obj())) {
757
-            return $this->state_abbrev();
758
-        }
759
-        return $this->state_name();
760
-    }
761
-
762
-
763
-    /**
764
-     * get Attendee State ID
765
-     *
766
-     * @return string
767
-     * @throws EE_Error
768
-     */
769
-    public function state_ID()
770
-    {
771
-        return $this->get('STA_ID');
772
-    }
773
-
774
-
775
-    /**
776
-     * get Attendee Country ISO Code
777
-     *
778
-     * @return string
779
-     * @throws EE_Error
780
-     */
781
-    public function country_ID()
782
-    {
783
-        return $this->get('CNT_ISO');
784
-    }
785
-
786
-
787
-    /**
788
-     * Returns the country's name if known, otherwise 'Unknown'
789
-     *
790
-     * @return string
791
-     * @throws EE_Error
792
-     * @throws ReflectionException
793
-     */
794
-    public function country_name()
795
-    {
796
-        if ($this->country_obj()) {
797
-            return $this->country_obj()->name();
798
-        }
799
-        return '';
800
-    }
801
-
802
-
803
-    /**
804
-     * either displays the country ISO2 code or the country name, as determined
805
-     * by the "FHEE__EEI_Address__country__use_abbreviation" filter.
806
-     * defaults to abbreviation
807
-     *
808
-     * @return string
809
-     * @throws EE_Error
810
-     * @throws ReflectionException
811
-     */
812
-    public function country()
813
-    {
814
-        if (apply_filters('FHEE__EEI_Address__country__use_abbreviation', true, $this->country_obj())) {
815
-            return $this->country_ID();
816
-        }
817
-        return $this->country_name();
818
-    }
16
+	/**
17
+	 * Sets some dynamic defaults
18
+	 *
19
+	 * @param array  $fieldValues
20
+	 * @param bool   $bydb
21
+	 * @param string $timezone
22
+	 * @param array  $date_formats
23
+	 * @throws EE_Error
24
+	 * @throws ReflectionException
25
+	 */
26
+	protected function __construct($fieldValues = null, $bydb = false, $timezone = '', $date_formats = [])
27
+	{
28
+		if (! isset($fieldValues['ATT_full_name'])) {
29
+			$fname                        = isset($fieldValues['ATT_fname']) ? $fieldValues['ATT_fname'] . ' ' : '';
30
+			$lname                        = isset($fieldValues['ATT_lname']) ? $fieldValues['ATT_lname'] : '';
31
+			$fieldValues['ATT_full_name'] = $fname . $lname;
32
+		}
33
+		if (! isset($fieldValues['ATT_slug'])) {
34
+			// $fieldValues['ATT_slug'] = sanitize_key(wp_generate_password(20));
35
+			$fieldValues['ATT_slug'] = sanitize_title($fieldValues['ATT_full_name']);
36
+		}
37
+		if (! isset($fieldValues['ATT_short_bio']) && isset($fieldValues['ATT_bio'])) {
38
+			$fieldValues['ATT_short_bio'] = substr($fieldValues['ATT_bio'], 0, 50);
39
+		}
40
+		parent::__construct($fieldValues, $bydb, $timezone, $date_formats);
41
+	}
42
+
43
+
44
+	/**
45
+	 * @param array  $props_n_values    incoming values
46
+	 * @param string $timezone          incoming timezone
47
+	 *                                  (if not set the timezone set for the website will be used.)
48
+	 * @param array  $date_formats      incoming date_formats in an array where the first value is the
49
+	 *                                  date_format and the second value is the time format
50
+	 * @return EE_Attendee
51
+	 * @throws EE_Error
52
+	 * @throws ReflectionException
53
+	 */
54
+	public static function new_instance($props_n_values = [], $timezone = '', $date_formats = [])
55
+	{
56
+		$has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats);
57
+		return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats);
58
+	}
59
+
60
+
61
+	/**
62
+	 * @param array  $props_n_values  incoming values from the database
63
+	 * @param string $timezone        incoming timezone as set by the model.
64
+	 *                                If not set the timezone for the website will be used.
65
+	 * @return EE_Attendee
66
+	 * @throws EE_Error
67
+	 * @throws EE_Error
68
+	 * @throws ReflectionException
69
+	 */
70
+	public static function new_instance_from_db($props_n_values = [], $timezone = '')
71
+	{
72
+		return new self($props_n_values, true, $timezone);
73
+	}
74
+
75
+
76
+	/**
77
+	 * Set Attendee First Name
78
+	 *
79
+	 * @param string $fname
80
+	 * @throws EE_Error
81
+	 * @throws ReflectionException
82
+	 */
83
+	public function set_fname($fname = '')
84
+	{
85
+		$this->set('ATT_fname', $fname);
86
+	}
87
+
88
+
89
+	/**
90
+	 * Set Attendee Last Name
91
+	 *
92
+	 * @param string $lname
93
+	 * @throws EE_Error
94
+	 * @throws ReflectionException
95
+	 */
96
+	public function set_lname($lname = '')
97
+	{
98
+		$this->set('ATT_lname', $lname);
99
+	}
100
+
101
+
102
+	/**
103
+	 * Set Attendee Address
104
+	 *
105
+	 * @param string $address
106
+	 * @throws EE_Error
107
+	 * @throws ReflectionException
108
+	 */
109
+	public function set_address($address = '')
110
+	{
111
+		$this->set('ATT_address', $address);
112
+	}
113
+
114
+
115
+	/**
116
+	 * Set Attendee Address2
117
+	 *
118
+	 * @param string $address2
119
+	 * @throws EE_Error
120
+	 * @throws ReflectionException
121
+	 */
122
+	public function set_address2($address2 = '')
123
+	{
124
+		$this->set('ATT_address2', $address2);
125
+	}
126
+
127
+
128
+	/**
129
+	 * Set Attendee City
130
+	 *
131
+	 * @param string $city
132
+	 * @throws EE_Error
133
+	 * @throws ReflectionException
134
+	 */
135
+	public function set_city($city = '')
136
+	{
137
+		$this->set('ATT_city', $city);
138
+	}
139
+
140
+
141
+	/**
142
+	 * Set Attendee State ID
143
+	 *
144
+	 * @param int $STA_ID
145
+	 * @throws EE_Error
146
+	 * @throws ReflectionException
147
+	 */
148
+	public function set_state($STA_ID = 0)
149
+	{
150
+		$this->set('STA_ID', $STA_ID);
151
+	}
152
+
153
+
154
+	/**
155
+	 * Set Attendee Country ISO Code
156
+	 *
157
+	 * @param string $CNT_ISO
158
+	 * @throws EE_Error
159
+	 * @throws ReflectionException
160
+	 */
161
+	public function set_country($CNT_ISO = '')
162
+	{
163
+		$this->set('CNT_ISO', $CNT_ISO);
164
+	}
165
+
166
+
167
+	/**
168
+	 * Set Attendee Zip/Postal Code
169
+	 *
170
+	 * @param string $zip
171
+	 * @throws EE_Error
172
+	 * @throws ReflectionException
173
+	 */
174
+	public function set_zip($zip = '')
175
+	{
176
+		$this->set('ATT_zip', $zip);
177
+	}
178
+
179
+
180
+	/**
181
+	 * Set Attendee Email Address
182
+	 *
183
+	 * @param string $email
184
+	 * @throws EE_Error
185
+	 * @throws ReflectionException
186
+	 */
187
+	public function set_email($email = '')
188
+	{
189
+		$this->set('ATT_email', $email);
190
+	}
191
+
192
+
193
+	/**
194
+	 * Set Attendee Phone
195
+	 *
196
+	 * @param string $phone
197
+	 * @throws EE_Error
198
+	 * @throws ReflectionException
199
+	 */
200
+	public function set_phone($phone = '')
201
+	{
202
+		$this->set('ATT_phone', $phone);
203
+	}
204
+
205
+
206
+	/**
207
+	 * set deleted
208
+	 *
209
+	 * @param bool $ATT_deleted
210
+	 * @throws EE_Error
211
+	 * @throws ReflectionException
212
+	 */
213
+	public function set_deleted($ATT_deleted = false)
214
+	{
215
+		$this->set('ATT_deleted', $ATT_deleted);
216
+	}
217
+
218
+
219
+	/**
220
+	 * Returns the value for the post_author id saved with the cpt
221
+	 *
222
+	 * @return int
223
+	 * @throws EE_Error
224
+	 * @since 4.5.0
225
+	 */
226
+	public function wp_user()
227
+	{
228
+		return $this->get('ATT_author');
229
+	}
230
+
231
+
232
+	/**
233
+	 * echoes out the attendee's first name
234
+	 *
235
+	 * @return void
236
+	 * @throws EE_Error
237
+	 */
238
+	public function e_full_name()
239
+	{
240
+		echo $this->full_name();
241
+	}
242
+
243
+
244
+	/**
245
+	 * Returns the first and last name concatenated together with a space.
246
+	 *
247
+	 * @param bool $apply_html_entities
248
+	 * @return string
249
+	 * @throws EE_Error
250
+	 */
251
+	public function full_name($apply_html_entities = false)
252
+	{
253
+		$full_name = [
254
+			$this->fname(),
255
+			$this->lname(),
256
+		];
257
+		$full_name = array_filter($full_name);
258
+		$full_name = implode(' ', $full_name);
259
+		return $apply_html_entities
260
+			? htmlentities($full_name, ENT_QUOTES, 'UTF-8')
261
+			: $full_name;
262
+	}
263
+
264
+
265
+	/**
266
+	 * get Attendee First Name
267
+	 *
268
+	 * @return string
269
+	 * @throws EE_Error
270
+	 */
271
+	public function fname()
272
+	{
273
+		return $this->get('ATT_fname');
274
+	}
275
+
276
+
277
+	/**
278
+	 * get Attendee Last Name
279
+	 *
280
+	 * @return string
281
+	 * @throws EE_Error
282
+	 */
283
+	public function lname()
284
+	{
285
+		return $this->get('ATT_lname');
286
+	}
287
+
288
+
289
+	/**
290
+	 * get Attendee Email Address
291
+	 *
292
+	 * @return string
293
+	 * @throws EE_Error
294
+	 */
295
+	public function email()
296
+	{
297
+		return $this->get('ATT_email');
298
+	}
299
+
300
+
301
+	/**
302
+	 * get Attendee Phone #
303
+	 *
304
+	 * @return string
305
+	 * @throws EE_Error
306
+	 */
307
+	public function phone()
308
+	{
309
+		return $this->get('ATT_phone');
310
+	}
311
+
312
+
313
+	/**
314
+	 * This returns the value of the `ATT_full_name` field
315
+	 * which is usually equivalent to calling `full_name()`
316
+	 * unless the post_title field has been directly modified
317
+	 * in the db for the post (espresso_attendees post type)
318
+	 * for this attendee.
319
+	 *
320
+	 * @param bool $apply_html_entities
321
+	 * @return string
322
+	 * @throws EE_Error
323
+	 */
324
+	public function ATT_full_name($apply_html_entities = false)
325
+	{
326
+		return $apply_html_entities
327
+			? htmlentities(
328
+				$this->get('ATT_full_name'),
329
+				ENT_QUOTES,
330
+				'UTF-8'
331
+			)
332
+			: $this->get('ATT_full_name');
333
+	}
334
+
335
+
336
+	/**
337
+	 * get Attendee bio
338
+	 *
339
+	 * @return string
340
+	 * @throws EE_Error
341
+	 */
342
+	public function bio()
343
+	{
344
+		return $this->get('ATT_bio');
345
+	}
346
+
347
+
348
+	/**
349
+	 * get Attendee short bio
350
+	 *
351
+	 * @return string
352
+	 * @throws EE_Error
353
+	 */
354
+	public function short_bio()
355
+	{
356
+		return $this->get('ATT_short_bio');
357
+	}
358
+
359
+
360
+	/**
361
+	 * Gets the attendee's full address as an array
362
+	 * so client code can decide hwo to display it
363
+	 *
364
+	 * @return array numerically indexed,
365
+	 *               with each part of the address that is known.
366
+	 *               Eg, if the user only responded to state and country,
367
+	 *               it would be array(0=>'Alabama',1=>'USA')
368
+	 * @return array
369
+	 * @throws EE_Error
370
+	 * @throws ReflectionException
371
+	 */
372
+	public function full_address_as_array()
373
+	{
374
+		$full_address_array     = [];
375
+		$initial_address_fields = ['ATT_address', 'ATT_address2', 'ATT_city',];
376
+		foreach ($initial_address_fields as $address_field_name) {
377
+			$address_fields_value = $this->get($address_field_name);
378
+			if (! empty($address_fields_value)) {
379
+				$full_address_array[] = $address_fields_value;
380
+			}
381
+		}
382
+		// now handle state and country
383
+		$state_obj = $this->state_obj();
384
+		if ($state_obj instanceof EE_State) {
385
+			$full_address_array[] = $state_obj->name();
386
+		}
387
+		$country_obj = $this->country_obj();
388
+		if ($country_obj instanceof EE_Country) {
389
+			$full_address_array[] = $country_obj->name();
390
+		}
391
+		// lastly get the xip
392
+		$zip_value = $this->zip();
393
+		if (! empty($zip_value)) {
394
+			$full_address_array[] = $zip_value;
395
+		}
396
+		return $full_address_array;
397
+	}
398
+
399
+
400
+	/**
401
+	 * Gets the state set to this attendee
402
+	 *
403
+	 * @return EE_Base_Class|EE_State
404
+	 * @throws EE_Error
405
+	 * @throws ReflectionException
406
+	 */
407
+	public function state_obj()
408
+	{
409
+		return $this->get_first_related('State');
410
+	}
411
+
412
+
413
+	/**
414
+	 * Gets country set for this attendee
415
+	 *
416
+	 * @return EE_Base_Class|EE_Country
417
+	 * @throws EE_Error
418
+	 * @throws ReflectionException
419
+	 */
420
+	public function country_obj()
421
+	{
422
+		return $this->get_first_related('Country');
423
+	}
424
+
425
+
426
+	/**
427
+	 * get Attendee Zip/Postal Code
428
+	 *
429
+	 * @return string
430
+	 * @throws EE_Error
431
+	 */
432
+	public function zip()
433
+	{
434
+		return $this->get('ATT_zip');
435
+	}
436
+
437
+
438
+	/**
439
+	 * get deleted
440
+	 *
441
+	 * @return        bool
442
+	 * @throws EE_Error
443
+	 */
444
+	public function deleted()
445
+	{
446
+		return $this->get('ATT_deleted');
447
+	}
448
+
449
+
450
+	/**
451
+	 * Gets registrations of this attendee
452
+	 *
453
+	 * @param array $query_params
454
+	 * @return array[]|EE_Base_Class[]|EE_Registration[]
455
+	 * @throws EE_Error
456
+	 * @throws ReflectionException
457
+	 */
458
+	public function get_registrations($query_params = [])
459
+	{
460
+		return $this->get_many_related('Registration', $query_params);
461
+	}
462
+
463
+
464
+	/**
465
+	 * Gets the most recent registration of this attendee
466
+	 *
467
+	 * @return EE_Base_Class|EE_Registration
468
+	 * @throws EE_Error
469
+	 * @throws ReflectionException
470
+	 */
471
+	public function get_most_recent_registration()
472
+	{
473
+		return $this->get_first_related(
474
+			'Registration',
475
+			['order_by' => ['REG_date' => 'DESC']]
476
+		); // null, 'REG_date', 'DESC', '=', 'OBJECT_K');
477
+	}
478
+
479
+
480
+	/**
481
+	 * Gets the most recent registration for this attend at this event
482
+	 *
483
+	 * @param int $event_id
484
+	 * @return EE_Base_Class|EE_Registration
485
+	 * @throws EE_Error
486
+	 * @throws ReflectionException
487
+	 */
488
+	public function get_most_recent_registration_for_event($event_id)
489
+	{
490
+		return $this->get_first_related(
491
+			'Registration',
492
+			[['EVT_ID' => $event_id], 'order_by' => ['REG_date' => 'DESC']]
493
+		);
494
+	}
495
+
496
+
497
+	/**
498
+	 * returns any events attached to this attendee ($_Event property);
499
+	 *
500
+	 * @return array
501
+	 * @throws EE_Error
502
+	 * @throws ReflectionException
503
+	 */
504
+	public function events()
505
+	{
506
+		return $this->get_many_related('Event');
507
+	}
508
+
509
+
510
+	/**
511
+	 * @return string
512
+	 * @throws EE_Error
513
+	 * @throws ReflectionException
514
+	 */
515
+	public function state_abbrev()
516
+	{
517
+		return $this->state_obj() instanceof EE_State ? $this->state_obj()->abbrev() : '';
518
+	}
519
+
520
+
521
+	/**
522
+	 * Gets the billing info array where keys match espresso_reg_page_billing_inputs(),
523
+	 * and keys are their cleaned values.
524
+	 *
525
+	 * @param EE_Payment_Method $payment_method the _gateway_name property on the gateway class
526
+	 * @return EE_Form_Section_Proper|null
527
+	 * @throws EE_Error
528
+	 * @see EE_Attendee::save_and_clean_billing_info_for_payment_method() which was
529
+	 *                                          used to save the billing info
530
+	 */
531
+	public function billing_info_for_payment_method($payment_method)
532
+	{
533
+		$pm_type = $payment_method->type_obj();
534
+		if (! $pm_type instanceof EE_PMT_Base) {
535
+			return null;
536
+		}
537
+		$billing_info = $this->get_post_meta($this->get_billing_info_postmeta_name($payment_method), true);
538
+		if (! $billing_info) {
539
+			return null;
540
+		}
541
+		$billing_form = $pm_type->billing_form();
542
+		// double-check the form isn't totally hidden, in which case pretend there is no form
543
+		$form_totally_hidden = true;
544
+		foreach ($billing_form->inputs_in_subsections() as $input) {
545
+			if (! $input->get_display_strategy() instanceof EE_Hidden_Display_Strategy) {
546
+				$form_totally_hidden = false;
547
+				break;
548
+			}
549
+		}
550
+		if ($form_totally_hidden) {
551
+			return null;
552
+		}
553
+		if ($billing_form instanceof EE_Form_Section_Proper) {
554
+			$billing_form->receive_form_submission([$billing_form->name() => $billing_info], false);
555
+		}
556
+
557
+		return $billing_form;
558
+	}
559
+
560
+
561
+	/**
562
+	 * Gets the postmeta key that holds this attendee's billing info for the
563
+	 * specified payment method
564
+	 *
565
+	 * @param EE_Payment_Method $payment_method
566
+	 * @return string
567
+	 * @throws EE_Error
568
+	 */
569
+	public function get_billing_info_postmeta_name($payment_method)
570
+	{
571
+		if ($payment_method->type_obj() instanceof EE_PMT_Base) {
572
+			return 'billing_info_' . $payment_method->type_obj()->system_name();
573
+		}
574
+		return null;
575
+	}
576
+
577
+
578
+	/**
579
+	 * Saves the billing info to the attendee. @param EE_Billing_Attendee_Info_Form $billing_form
580
+	 *
581
+	 * @param EE_Payment_Method $payment_method
582
+	 * @return boolean
583
+	 * @throws EE_Error
584
+	 * @see EE_Attendee::billing_info_for_payment_method() which is used to
585
+	 *      retrieve it
586
+	 */
587
+	public function save_and_clean_billing_info_for_payment_method($billing_form, $payment_method)
588
+	{
589
+		if (! $billing_form instanceof EE_Billing_Attendee_Info_Form) {
590
+			EE_Error::add_error(
591
+				__('Cannot save billing info because there is none.', 'event_espresso'),
592
+				__FILE__,
593
+				__FUNCTION__,
594
+				__LINE__
595
+			);
596
+			return false;
597
+		}
598
+		$billing_form->clean_sensitive_data();
599
+		return update_post_meta(
600
+			$this->ID(),
601
+			$this->get_billing_info_postmeta_name($payment_method),
602
+			$billing_form->input_values(true)
603
+		);
604
+	}
605
+
606
+
607
+	/**
608
+	 * Return the link to the admin details for the object.
609
+	 *
610
+	 * @return string
611
+	 * @throws EE_Error
612
+	 * @throws InvalidArgumentException
613
+	 * @throws InvalidDataTypeException
614
+	 * @throws InvalidInterfaceException
615
+	 * @throws ReflectionException
616
+	 */
617
+	public function get_admin_details_link()
618
+	{
619
+		return $this->get_admin_edit_link();
620
+	}
621
+
622
+
623
+	/**
624
+	 * Returns the link to the editor for the object.  Sometimes this is the same as the details.
625
+	 *
626
+	 * @return string
627
+	 * @throws EE_Error
628
+	 * @throws InvalidArgumentException
629
+	 * @throws ReflectionException
630
+	 * @throws InvalidDataTypeException
631
+	 * @throws InvalidInterfaceException
632
+	 */
633
+	public function get_admin_edit_link()
634
+	{
635
+		EE_Registry::instance()->load_helper('URL');
636
+		return EEH_URL::add_query_args_and_nonce(
637
+			[
638
+				'page'   => 'espresso_registrations',
639
+				'action' => 'edit_attendee',
640
+				'post'   => $this->ID(),
641
+			],
642
+			admin_url('admin.php')
643
+		);
644
+	}
645
+
646
+
647
+	/**
648
+	 * get Attendee Address
649
+	 *
650
+	 * @return string
651
+	 * @throws EE_Error
652
+	 */
653
+	public function address()
654
+	{
655
+		return $this->get('ATT_address');
656
+	}
657
+
658
+
659
+	/**
660
+	 * Returns the link to a settings page for the object.
661
+	 *
662
+	 * @return string
663
+	 * @throws EE_Error
664
+	 * @throws InvalidArgumentException
665
+	 * @throws InvalidDataTypeException
666
+	 * @throws InvalidInterfaceException
667
+	 * @throws ReflectionException
668
+	 */
669
+	public function get_admin_settings_link()
670
+	{
671
+		return $this->get_admin_edit_link();
672
+	}
673
+
674
+
675
+	/**
676
+	 * Returns the link to the "overview" for the object (typically the "list table" view).
677
+	 *
678
+	 * @return string
679
+	 * @throws EE_Error
680
+	 * @throws InvalidArgumentException
681
+	 * @throws ReflectionException
682
+	 * @throws InvalidDataTypeException
683
+	 * @throws InvalidInterfaceException
684
+	 */
685
+	public function get_admin_overview_link()
686
+	{
687
+		EE_Registry::instance()->load_helper('URL');
688
+		return EEH_URL::add_query_args_and_nonce(
689
+			[
690
+				'page'   => 'espresso_registrations',
691
+				'action' => 'contact_list',
692
+			],
693
+			admin_url('admin.php')
694
+		);
695
+	}
696
+
697
+
698
+
699
+
700
+
701
+
702
+
703
+
704
+	/**
705
+	 * get Attendee Address2
706
+	 *
707
+	 * @return string
708
+	 * @throws EE_Error
709
+	 */
710
+	public function address2()
711
+	{
712
+		return $this->get('ATT_address2');
713
+	}
714
+
715
+
716
+	/**
717
+	 * Returns the state's name, otherwise 'Unknown'
718
+	 *
719
+	 * @return string
720
+	 * @throws EE_Error
721
+	 * @throws ReflectionException
722
+	 */
723
+	public function state_name()
724
+	{
725
+		if ($this->state_obj()) {
726
+			return $this->state_obj()->name();
727
+		} else {
728
+			return '';
729
+		}
730
+	}
731
+
732
+
733
+	/**
734
+	 * get Attendee City
735
+	 *
736
+	 * @return string
737
+	 * @throws EE_Error
738
+	 */
739
+	public function city()
740
+	{
741
+		return $this->get('ATT_city');
742
+	}
743
+
744
+
745
+	/**
746
+	 * either displays the state abbreviation or the state name, as determined
747
+	 * by the "FHEE__EEI_Address__state__use_abbreviation" filter.
748
+	 * defaults to abbreviation
749
+	 *
750
+	 * @return string
751
+	 * @throws EE_Error
752
+	 * @throws ReflectionException
753
+	 */
754
+	public function state()
755
+	{
756
+		if (apply_filters('FHEE__EEI_Address__state__use_abbreviation', true, $this->state_obj())) {
757
+			return $this->state_abbrev();
758
+		}
759
+		return $this->state_name();
760
+	}
761
+
762
+
763
+	/**
764
+	 * get Attendee State ID
765
+	 *
766
+	 * @return string
767
+	 * @throws EE_Error
768
+	 */
769
+	public function state_ID()
770
+	{
771
+		return $this->get('STA_ID');
772
+	}
773
+
774
+
775
+	/**
776
+	 * get Attendee Country ISO Code
777
+	 *
778
+	 * @return string
779
+	 * @throws EE_Error
780
+	 */
781
+	public function country_ID()
782
+	{
783
+		return $this->get('CNT_ISO');
784
+	}
785
+
786
+
787
+	/**
788
+	 * Returns the country's name if known, otherwise 'Unknown'
789
+	 *
790
+	 * @return string
791
+	 * @throws EE_Error
792
+	 * @throws ReflectionException
793
+	 */
794
+	public function country_name()
795
+	{
796
+		if ($this->country_obj()) {
797
+			return $this->country_obj()->name();
798
+		}
799
+		return '';
800
+	}
801
+
802
+
803
+	/**
804
+	 * either displays the country ISO2 code or the country name, as determined
805
+	 * by the "FHEE__EEI_Address__country__use_abbreviation" filter.
806
+	 * defaults to abbreviation
807
+	 *
808
+	 * @return string
809
+	 * @throws EE_Error
810
+	 * @throws ReflectionException
811
+	 */
812
+	public function country()
813
+	{
814
+		if (apply_filters('FHEE__EEI_Address__country__use_abbreviation', true, $this->country_obj())) {
815
+			return $this->country_ID();
816
+		}
817
+		return $this->country_name();
818
+	}
819 819
 }
Please login to merge, or discard this patch.
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -25,16 +25,16 @@  discard block
 block discarded – undo
25 25
      */
26 26
     protected function __construct($fieldValues = null, $bydb = false, $timezone = '', $date_formats = [])
27 27
     {
28
-        if (! isset($fieldValues['ATT_full_name'])) {
29
-            $fname                        = isset($fieldValues['ATT_fname']) ? $fieldValues['ATT_fname'] . ' ' : '';
28
+        if ( ! isset($fieldValues['ATT_full_name'])) {
29
+            $fname                        = isset($fieldValues['ATT_fname']) ? $fieldValues['ATT_fname'].' ' : '';
30 30
             $lname                        = isset($fieldValues['ATT_lname']) ? $fieldValues['ATT_lname'] : '';
31
-            $fieldValues['ATT_full_name'] = $fname . $lname;
31
+            $fieldValues['ATT_full_name'] = $fname.$lname;
32 32
         }
33
-        if (! isset($fieldValues['ATT_slug'])) {
33
+        if ( ! isset($fieldValues['ATT_slug'])) {
34 34
             // $fieldValues['ATT_slug'] = sanitize_key(wp_generate_password(20));
35 35
             $fieldValues['ATT_slug'] = sanitize_title($fieldValues['ATT_full_name']);
36 36
         }
37
-        if (! isset($fieldValues['ATT_short_bio']) && isset($fieldValues['ATT_bio'])) {
37
+        if ( ! isset($fieldValues['ATT_short_bio']) && isset($fieldValues['ATT_bio'])) {
38 38
             $fieldValues['ATT_short_bio'] = substr($fieldValues['ATT_bio'], 0, 50);
39 39
         }
40 40
         parent::__construct($fieldValues, $bydb, $timezone, $date_formats);
@@ -372,10 +372,10 @@  discard block
 block discarded – undo
372 372
     public function full_address_as_array()
373 373
     {
374 374
         $full_address_array     = [];
375
-        $initial_address_fields = ['ATT_address', 'ATT_address2', 'ATT_city',];
375
+        $initial_address_fields = ['ATT_address', 'ATT_address2', 'ATT_city', ];
376 376
         foreach ($initial_address_fields as $address_field_name) {
377 377
             $address_fields_value = $this->get($address_field_name);
378
-            if (! empty($address_fields_value)) {
378
+            if ( ! empty($address_fields_value)) {
379 379
                 $full_address_array[] = $address_fields_value;
380 380
             }
381 381
         }
@@ -390,7 +390,7 @@  discard block
 block discarded – undo
390 390
         }
391 391
         // lastly get the xip
392 392
         $zip_value = $this->zip();
393
-        if (! empty($zip_value)) {
393
+        if ( ! empty($zip_value)) {
394 394
             $full_address_array[] = $zip_value;
395 395
         }
396 396
         return $full_address_array;
@@ -531,18 +531,18 @@  discard block
 block discarded – undo
531 531
     public function billing_info_for_payment_method($payment_method)
532 532
     {
533 533
         $pm_type = $payment_method->type_obj();
534
-        if (! $pm_type instanceof EE_PMT_Base) {
534
+        if ( ! $pm_type instanceof EE_PMT_Base) {
535 535
             return null;
536 536
         }
537 537
         $billing_info = $this->get_post_meta($this->get_billing_info_postmeta_name($payment_method), true);
538
-        if (! $billing_info) {
538
+        if ( ! $billing_info) {
539 539
             return null;
540 540
         }
541 541
         $billing_form = $pm_type->billing_form();
542 542
         // double-check the form isn't totally hidden, in which case pretend there is no form
543 543
         $form_totally_hidden = true;
544 544
         foreach ($billing_form->inputs_in_subsections() as $input) {
545
-            if (! $input->get_display_strategy() instanceof EE_Hidden_Display_Strategy) {
545
+            if ( ! $input->get_display_strategy() instanceof EE_Hidden_Display_Strategy) {
546 546
                 $form_totally_hidden = false;
547 547
                 break;
548 548
             }
@@ -569,7 +569,7 @@  discard block
 block discarded – undo
569 569
     public function get_billing_info_postmeta_name($payment_method)
570 570
     {
571 571
         if ($payment_method->type_obj() instanceof EE_PMT_Base) {
572
-            return 'billing_info_' . $payment_method->type_obj()->system_name();
572
+            return 'billing_info_'.$payment_method->type_obj()->system_name();
573 573
         }
574 574
         return null;
575 575
     }
@@ -586,7 +586,7 @@  discard block
 block discarded – undo
586 586
      */
587 587
     public function save_and_clean_billing_info_for_payment_method($billing_form, $payment_method)
588 588
     {
589
-        if (! $billing_form instanceof EE_Billing_Attendee_Info_Form) {
589
+        if ( ! $billing_form instanceof EE_Billing_Attendee_Info_Form) {
590 590
             EE_Error::add_error(
591 591
                 __('Cannot save billing info because there is none.', 'event_espresso'),
592 592
                 __FILE__,
Please login to merge, or discard this patch.
core/db_classes/EE_Datetime_Ticket.class.php 1 patch
Indentation   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -10,30 +10,30 @@
 block discarded – undo
10 10
 class EE_Datetime_Ticket extends EE_Base_Class
11 11
 {
12 12
 
13
-    /**
14
-     *
15
-     * @param array  $props_n_values          incoming values
16
-     * @param string $timezone                incoming timezone (if not set the timezone set for the website will be
17
-     *                                        used.)
18
-     * @param array  $date_formats            incoming date_formats in an array where the first value is the
19
-     *                                        date_format and the second value is the time format
20
-     * @return EE_Attendee
21
-     */
22
-    public static function new_instance($props_n_values = array(), $timezone = '', $date_formats = array())
23
-    {
24
-        $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats);
25
-        return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats);
26
-    }
13
+	/**
14
+	 *
15
+	 * @param array  $props_n_values          incoming values
16
+	 * @param string $timezone                incoming timezone (if not set the timezone set for the website will be
17
+	 *                                        used.)
18
+	 * @param array  $date_formats            incoming date_formats in an array where the first value is the
19
+	 *                                        date_format and the second value is the time format
20
+	 * @return EE_Attendee
21
+	 */
22
+	public static function new_instance($props_n_values = array(), $timezone = '', $date_formats = array())
23
+	{
24
+		$has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats);
25
+		return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats);
26
+	}
27 27
 
28 28
 
29
-    /**
30
-     * @param array  $props_n_values  incoming values from the database
31
-     * @param string $timezone        incoming timezone as set by the model.  If not set the timezone for
32
-     *                                the website will be used.
33
-     * @return EE_Attendee
34
-     */
35
-    public static function new_instance_from_db($props_n_values = array(), $timezone = '')
36
-    {
37
-        return new self($props_n_values, true, $timezone);
38
-    }
29
+	/**
30
+	 * @param array  $props_n_values  incoming values from the database
31
+	 * @param string $timezone        incoming timezone as set by the model.  If not set the timezone for
32
+	 *                                the website will be used.
33
+	 * @return EE_Attendee
34
+	 */
35
+	public static function new_instance_from_db($props_n_values = array(), $timezone = '')
36
+	{
37
+		return new self($props_n_values, true, $timezone);
38
+	}
39 39
 }
Please login to merge, or discard this patch.
core/db_classes/EE_Question_Option.class.php 1 patch
Indentation   +218 added lines, -218 removed lines patch added patch discarded remove patch
@@ -10,222 +10,222 @@
 block discarded – undo
10 10
 class EE_Question_Option extends EE_Soft_Delete_Base_Class implements EEI_Duplicatable
11 11
 {
12 12
 
13
-    /**
14
-     * Question Option Opt Group Name
15
-     *
16
-     * @access protected
17
-     * @var string
18
-     */
19
-    protected $_QSO_opt_group = null;
20
-
21
-
22
-    /**
23
-     *
24
-     * @param array  $props_n_values          incoming values
25
-     * @param string $timezone                incoming timezone (if not set the timezone set for the website will be
26
-     *                                        used.)
27
-     * @param array  $date_formats            incoming date_formats in an array where the first value is the
28
-     *                                        date_format and the second value is the time format
29
-     * @return EE_Attendee
30
-     */
31
-    public static function new_instance($props_n_values = array(), $timezone = '', $date_formats = array())
32
-    {
33
-        $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats);
34
-        return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats);
35
-    }
36
-
37
-
38
-    /**
39
-     * @param array  $props_n_values  incoming values from the database
40
-     * @param string $timezone        incoming timezone as set by the model.  If not set the timezone for
41
-     *                                the website will be used.
42
-     * @return EE_Attendee
43
-     */
44
-    public static function new_instance_from_db($props_n_values = array(), $timezone = '')
45
-    {
46
-        return new self($props_n_values, true, $timezone);
47
-    }
48
-
49
-
50
-    /**
51
-     * Sets the option's key value
52
-     *
53
-     * @param string $value
54
-     * @return bool success
55
-     */
56
-    public function set_value($value)
57
-    {
58
-        $this->set('QSO_value', $value);
59
-    }
60
-
61
-
62
-    /**
63
-     * Sets the option's Display Text
64
-     *
65
-     * @param string $text
66
-     * @return bool success
67
-     */
68
-    public function set_desc($text)
69
-    {
70
-        $this->set('QSO_desc', $text);
71
-    }
72
-
73
-
74
-    /**
75
-     * Sets the order for this option
76
-     *
77
-     * @access public
78
-     * @param integer $order
79
-     * @return bool      $success
80
-     */
81
-    public function set_order($order)
82
-    {
83
-        $this->set('QSO_order', $order);
84
-    }
85
-
86
-
87
-    /**
88
-     * Sets the ID of the related question
89
-     *
90
-     * @param int $question_ID
91
-     * @return bool success
92
-     */
93
-    public function set_question_ID($question_ID)
94
-    {
95
-        $this->set('QST_ID', $question_ID);
96
-    }
97
-
98
-
99
-    /**
100
-     * Sets the option's opt_group
101
-     *
102
-     * @param string $text
103
-     * @return bool success
104
-     */
105
-    public function set_opt_group($text)
106
-    {
107
-        return $this->_QSO_opt_group = $text;
108
-    }
109
-
110
-
111
-    /**
112
-     * Gets the option's key value
113
-     *
114
-     * @return string
115
-     */
116
-    public function value()
117
-    {
118
-        return $this->get('QSO_value');
119
-    }
120
-
121
-
122
-    /**
123
-     * Gets the option's display text
124
-     *
125
-     * @return string
126
-     */
127
-    public function desc()
128
-    {
129
-        return $this->get('QSO_desc');
130
-    }
131
-
132
-
133
-    /**
134
-     * Returns whether this option has been deleted or not
135
-     *
136
-     * @return boolean
137
-     */
138
-    public function deleted()
139
-    {
140
-        return $this->get('QSO_deleted');
141
-    }
142
-
143
-
144
-    /**
145
-     * Returns the order or the Question Option
146
-     *
147
-     * @access public
148
-     * @return integer
149
-     */
150
-    public function order()
151
-    {
152
-        return $this->get('QSO_option');
153
-    }
154
-
155
-
156
-    /**
157
-     * Gets the related question's ID
158
-     *
159
-     * @return int
160
-     */
161
-    public function question_ID()
162
-    {
163
-        return $this->get('QST_ID');
164
-    }
165
-
166
-
167
-    /**
168
-     * Returns the question related to this question option
169
-     *
170
-     * @return EE_Question
171
-     */
172
-    public function question()
173
-    {
174
-        return $this->get_first_related('Question');
175
-    }
176
-
177
-
178
-    /**
179
-     * Gets the option's opt_group
180
-     *
181
-     * @return string
182
-     */
183
-    public function opt_group()
184
-    {
185
-        return $this->_QSO_opt_group;
186
-    }
187
-
188
-    /**
189
-     * Duplicates this question option. By default the new question option will be for the same question,
190
-     * but that can be overriden by setting the 'QST_ID' option
191
-     *
192
-     * @param array $options {
193
-     * @type int    $QST_ID  the QST_ID attribute of this question option, otherwise it will be for the same question
194
-     *                       as the original
195
-     */
196
-    public function duplicate($options = array())
197
-    {
198
-        $new_question_option = clone $this;
199
-        $new_question_option->set('QSO_ID', null);
200
-        if (
201
-            array_key_exists(
202
-                'QST_ID',
203
-                $options
204
-            )
205
-        ) {// use array_key_exists instead of isset because NULL might be a valid value
206
-            $new_question_option->set_question_ID($options['QST_ID']);
207
-        }
208
-        $new_question_option->save();
209
-    }
210
-
211
-    /**
212
-     * Gets the QSO_system value
213
-     *
214
-     * @return string|null
215
-     */
216
-    public function system()
217
-    {
218
-        return $this->get('QSO_system');
219
-    }
220
-
221
-    /**
222
-     * Sets QSO_system
223
-     *
224
-     * @param string $QSO_system
225
-     * @return bool
226
-     */
227
-    public function set_system($QSO_system)
228
-    {
229
-        return $this->set('QSO_system', $QSO_system);
230
-    }
13
+	/**
14
+	 * Question Option Opt Group Name
15
+	 *
16
+	 * @access protected
17
+	 * @var string
18
+	 */
19
+	protected $_QSO_opt_group = null;
20
+
21
+
22
+	/**
23
+	 *
24
+	 * @param array  $props_n_values          incoming values
25
+	 * @param string $timezone                incoming timezone (if not set the timezone set for the website will be
26
+	 *                                        used.)
27
+	 * @param array  $date_formats            incoming date_formats in an array where the first value is the
28
+	 *                                        date_format and the second value is the time format
29
+	 * @return EE_Attendee
30
+	 */
31
+	public static function new_instance($props_n_values = array(), $timezone = '', $date_formats = array())
32
+	{
33
+		$has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats);
34
+		return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats);
35
+	}
36
+
37
+
38
+	/**
39
+	 * @param array  $props_n_values  incoming values from the database
40
+	 * @param string $timezone        incoming timezone as set by the model.  If not set the timezone for
41
+	 *                                the website will be used.
42
+	 * @return EE_Attendee
43
+	 */
44
+	public static function new_instance_from_db($props_n_values = array(), $timezone = '')
45
+	{
46
+		return new self($props_n_values, true, $timezone);
47
+	}
48
+
49
+
50
+	/**
51
+	 * Sets the option's key value
52
+	 *
53
+	 * @param string $value
54
+	 * @return bool success
55
+	 */
56
+	public function set_value($value)
57
+	{
58
+		$this->set('QSO_value', $value);
59
+	}
60
+
61
+
62
+	/**
63
+	 * Sets the option's Display Text
64
+	 *
65
+	 * @param string $text
66
+	 * @return bool success
67
+	 */
68
+	public function set_desc($text)
69
+	{
70
+		$this->set('QSO_desc', $text);
71
+	}
72
+
73
+
74
+	/**
75
+	 * Sets the order for this option
76
+	 *
77
+	 * @access public
78
+	 * @param integer $order
79
+	 * @return bool      $success
80
+	 */
81
+	public function set_order($order)
82
+	{
83
+		$this->set('QSO_order', $order);
84
+	}
85
+
86
+
87
+	/**
88
+	 * Sets the ID of the related question
89
+	 *
90
+	 * @param int $question_ID
91
+	 * @return bool success
92
+	 */
93
+	public function set_question_ID($question_ID)
94
+	{
95
+		$this->set('QST_ID', $question_ID);
96
+	}
97
+
98
+
99
+	/**
100
+	 * Sets the option's opt_group
101
+	 *
102
+	 * @param string $text
103
+	 * @return bool success
104
+	 */
105
+	public function set_opt_group($text)
106
+	{
107
+		return $this->_QSO_opt_group = $text;
108
+	}
109
+
110
+
111
+	/**
112
+	 * Gets the option's key value
113
+	 *
114
+	 * @return string
115
+	 */
116
+	public function value()
117
+	{
118
+		return $this->get('QSO_value');
119
+	}
120
+
121
+
122
+	/**
123
+	 * Gets the option's display text
124
+	 *
125
+	 * @return string
126
+	 */
127
+	public function desc()
128
+	{
129
+		return $this->get('QSO_desc');
130
+	}
131
+
132
+
133
+	/**
134
+	 * Returns whether this option has been deleted or not
135
+	 *
136
+	 * @return boolean
137
+	 */
138
+	public function deleted()
139
+	{
140
+		return $this->get('QSO_deleted');
141
+	}
142
+
143
+
144
+	/**
145
+	 * Returns the order or the Question Option
146
+	 *
147
+	 * @access public
148
+	 * @return integer
149
+	 */
150
+	public function order()
151
+	{
152
+		return $this->get('QSO_option');
153
+	}
154
+
155
+
156
+	/**
157
+	 * Gets the related question's ID
158
+	 *
159
+	 * @return int
160
+	 */
161
+	public function question_ID()
162
+	{
163
+		return $this->get('QST_ID');
164
+	}
165
+
166
+
167
+	/**
168
+	 * Returns the question related to this question option
169
+	 *
170
+	 * @return EE_Question
171
+	 */
172
+	public function question()
173
+	{
174
+		return $this->get_first_related('Question');
175
+	}
176
+
177
+
178
+	/**
179
+	 * Gets the option's opt_group
180
+	 *
181
+	 * @return string
182
+	 */
183
+	public function opt_group()
184
+	{
185
+		return $this->_QSO_opt_group;
186
+	}
187
+
188
+	/**
189
+	 * Duplicates this question option. By default the new question option will be for the same question,
190
+	 * but that can be overriden by setting the 'QST_ID' option
191
+	 *
192
+	 * @param array $options {
193
+	 * @type int    $QST_ID  the QST_ID attribute of this question option, otherwise it will be for the same question
194
+	 *                       as the original
195
+	 */
196
+	public function duplicate($options = array())
197
+	{
198
+		$new_question_option = clone $this;
199
+		$new_question_option->set('QSO_ID', null);
200
+		if (
201
+			array_key_exists(
202
+				'QST_ID',
203
+				$options
204
+			)
205
+		) {// use array_key_exists instead of isset because NULL might be a valid value
206
+			$new_question_option->set_question_ID($options['QST_ID']);
207
+		}
208
+		$new_question_option->save();
209
+	}
210
+
211
+	/**
212
+	 * Gets the QSO_system value
213
+	 *
214
+	 * @return string|null
215
+	 */
216
+	public function system()
217
+	{
218
+		return $this->get('QSO_system');
219
+	}
220
+
221
+	/**
222
+	 * Sets QSO_system
223
+	 *
224
+	 * @param string $QSO_system
225
+	 * @return bool
226
+	 */
227
+	public function set_system($QSO_system)
228
+	{
229
+		return $this->set('QSO_system', $QSO_system);
230
+	}
231 231
 }
Please login to merge, or discard this patch.
core/helpers/EEH_DTT_Helper.helper.php 1 patch
Indentation   +988 added lines, -988 removed lines patch added patch discarded remove patch
@@ -16,1052 +16,1052 @@
 block discarded – undo
16 16
 class EEH_DTT_Helper
17 17
 {
18 18
 
19
-    /**
20
-     * return the timezone set for the WP install
21
-     *
22
-     * @return string valid timezone string for PHP DateTimeZone() class
23
-     * @throws InvalidArgumentException
24
-     * @throws InvalidDataTypeException
25
-     * @throws InvalidInterfaceException
26
-     */
27
-    public static function get_timezone()
28
-    {
29
-        return EEH_DTT_Helper::get_valid_timezone_string();
30
-    }
19
+	/**
20
+	 * return the timezone set for the WP install
21
+	 *
22
+	 * @return string valid timezone string for PHP DateTimeZone() class
23
+	 * @throws InvalidArgumentException
24
+	 * @throws InvalidDataTypeException
25
+	 * @throws InvalidInterfaceException
26
+	 */
27
+	public static function get_timezone()
28
+	{
29
+		return EEH_DTT_Helper::get_valid_timezone_string();
30
+	}
31 31
 
32 32
 
33
-    /**
34
-     * get_valid_timezone_string
35
-     *    ensures that a valid timezone string is returned
36
-     *
37
-     * @param string $timezone_string
38
-     * @param bool   $throw_error
39
-     * @return string
40
-     * @throws InvalidArgumentException
41
-     * @throws InvalidDataTypeException
42
-     * @throws InvalidInterfaceException
43
-     */
44
-    public static function get_valid_timezone_string($timezone_string = '', $throw_error = false)
45
-    {
46
-        return self::getHelperAdapter()->getValidTimezoneString($timezone_string, $throw_error);
47
-    }
33
+	/**
34
+	 * get_valid_timezone_string
35
+	 *    ensures that a valid timezone string is returned
36
+	 *
37
+	 * @param string $timezone_string
38
+	 * @param bool   $throw_error
39
+	 * @return string
40
+	 * @throws InvalidArgumentException
41
+	 * @throws InvalidDataTypeException
42
+	 * @throws InvalidInterfaceException
43
+	 */
44
+	public static function get_valid_timezone_string($timezone_string = '', $throw_error = false)
45
+	{
46
+		return self::getHelperAdapter()->getValidTimezoneString($timezone_string, $throw_error);
47
+	}
48 48
 
49 49
 
50
-    public static function resetDefaultTimezoneString()
51
-    {
52
-        self::getHelperAdapter()->resetDefaultTimezoneString();
53
-    }
50
+	public static function resetDefaultTimezoneString()
51
+	{
52
+		self::getHelperAdapter()->resetDefaultTimezoneString();
53
+	}
54 54
 
55 55
 
56
-    /**
57
-     * This only purpose for this static method is to validate that the incoming timezone is a valid php timezone.
58
-     *
59
-     * @static
60
-     * @param  string $timezone_string Timezone string to check
61
-     * @param bool    $throw_error
62
-     * @return bool
63
-     * @throws InvalidArgumentException
64
-     * @throws InvalidDataTypeException
65
-     * @throws InvalidInterfaceException
66
-     */
67
-    public static function validate_timezone($timezone_string, $throw_error = true)
68
-    {
69
-        return self::getHelperAdapter()->validateTimezone($timezone_string, $throw_error);
70
-    }
56
+	/**
57
+	 * This only purpose for this static method is to validate that the incoming timezone is a valid php timezone.
58
+	 *
59
+	 * @static
60
+	 * @param  string $timezone_string Timezone string to check
61
+	 * @param bool    $throw_error
62
+	 * @return bool
63
+	 * @throws InvalidArgumentException
64
+	 * @throws InvalidDataTypeException
65
+	 * @throws InvalidInterfaceException
66
+	 */
67
+	public static function validate_timezone($timezone_string, $throw_error = true)
68
+	{
69
+		return self::getHelperAdapter()->validateTimezone($timezone_string, $throw_error);
70
+	}
71 71
 
72 72
 
73
-    /**
74
-     * This returns a string that can represent the provided gmt offset in format that can be passed into
75
-     * DateTimeZone.  This is NOT a string that can be passed as a value on the WordPress timezone_string option.
76
-     *
77
-     * @param float|string $gmt_offset
78
-     * @return string
79
-     * @throws InvalidArgumentException
80
-     * @throws InvalidDataTypeException
81
-     * @throws InvalidInterfaceException
82
-     */
83
-    public static function get_timezone_string_from_gmt_offset($gmt_offset = '')
84
-    {
85
-        return self::getHelperAdapter()->getTimezoneStringFromGmtOffset($gmt_offset);
86
-    }
73
+	/**
74
+	 * This returns a string that can represent the provided gmt offset in format that can be passed into
75
+	 * DateTimeZone.  This is NOT a string that can be passed as a value on the WordPress timezone_string option.
76
+	 *
77
+	 * @param float|string $gmt_offset
78
+	 * @return string
79
+	 * @throws InvalidArgumentException
80
+	 * @throws InvalidDataTypeException
81
+	 * @throws InvalidInterfaceException
82
+	 */
83
+	public static function get_timezone_string_from_gmt_offset($gmt_offset = '')
84
+	{
85
+		return self::getHelperAdapter()->getTimezoneStringFromGmtOffset($gmt_offset);
86
+	}
87 87
 
88 88
 
89
-    /**
90
-     * Gets the site's GMT offset based on either the timezone string
91
-     * (in which case teh gmt offset will vary depending on the location's
92
-     * observance of daylight savings time) or the gmt_offset wp option
93
-     *
94
-     * @return int seconds offset
95
-     * @throws InvalidArgumentException
96
-     * @throws InvalidDataTypeException
97
-     * @throws InvalidInterfaceException
98
-     */
99
-    public static function get_site_timezone_gmt_offset()
100
-    {
101
-        return self::getHelperAdapter()->getSiteTimezoneGmtOffset();
102
-    }
89
+	/**
90
+	 * Gets the site's GMT offset based on either the timezone string
91
+	 * (in which case teh gmt offset will vary depending on the location's
92
+	 * observance of daylight savings time) or the gmt_offset wp option
93
+	 *
94
+	 * @return int seconds offset
95
+	 * @throws InvalidArgumentException
96
+	 * @throws InvalidDataTypeException
97
+	 * @throws InvalidInterfaceException
98
+	 */
99
+	public static function get_site_timezone_gmt_offset()
100
+	{
101
+		return self::getHelperAdapter()->getSiteTimezoneGmtOffset();
102
+	}
103 103
 
104 104
 
105
-    /**
106
-     * Depending on PHP version,
107
-     * there might not be valid current timezone strings to match these gmt_offsets in its timezone tables.
108
-     * To get around that, for these fringe timezones we bump them to a known valid offset.
109
-     * This method should ONLY be called after first verifying an timezone_string cannot be retrieved for the offset.
110
-     *
111
-     * @deprecated 4.9.54.rc    Developers this was always meant to only be an internally used method.  This will be
112
-     *                          removed in a future version of EE.
113
-     * @param int $gmt_offset
114
-     * @return int
115
-     * @throws InvalidArgumentException
116
-     * @throws InvalidDataTypeException
117
-     * @throws InvalidInterfaceException
118
-     */
119
-    public static function adjust_invalid_gmt_offsets($gmt_offset = 0)
120
-    {
121
-        return self::getHelperAdapter()->adjustInvalidGmtOffsets($gmt_offset);
122
-    }
105
+	/**
106
+	 * Depending on PHP version,
107
+	 * there might not be valid current timezone strings to match these gmt_offsets in its timezone tables.
108
+	 * To get around that, for these fringe timezones we bump them to a known valid offset.
109
+	 * This method should ONLY be called after first verifying an timezone_string cannot be retrieved for the offset.
110
+	 *
111
+	 * @deprecated 4.9.54.rc    Developers this was always meant to only be an internally used method.  This will be
112
+	 *                          removed in a future version of EE.
113
+	 * @param int $gmt_offset
114
+	 * @return int
115
+	 * @throws InvalidArgumentException
116
+	 * @throws InvalidDataTypeException
117
+	 * @throws InvalidInterfaceException
118
+	 */
119
+	public static function adjust_invalid_gmt_offsets($gmt_offset = 0)
120
+	{
121
+		return self::getHelperAdapter()->adjustInvalidGmtOffsets($gmt_offset);
122
+	}
123 123
 
124 124
 
125
-    /**
126
-     * get_timezone_string_from_abbreviations_list
127
-     *
128
-     * @deprecated 4.9.54.rc  Developers, this was never intended to be public.  This is a soft deprecation for now.
129
-     *                        If you are using this, you'll want to work out an alternate way of getting the value.
130
-     * @param int  $gmt_offset
131
-     * @param bool $coerce If true, we attempt to coerce with our adjustment table @see self::adjust_invalid_gmt_offset.
132
-     * @return string
133
-     * @throws EE_Error
134
-     * @throws InvalidArgumentException
135
-     * @throws InvalidDataTypeException
136
-     * @throws InvalidInterfaceException
137
-     */
138
-    public static function get_timezone_string_from_abbreviations_list($gmt_offset = 0, $coerce = true)
139
-    {
140
-        $gmt_offset =  (int) $gmt_offset;
141
-        /** @var array[] $abbreviations */
142
-        $abbreviations = DateTimeZone::listAbbreviations();
143
-        foreach ($abbreviations as $abbreviation) {
144
-            foreach ($abbreviation as $timezone) {
145
-                if ((int) $timezone['offset'] === $gmt_offset && (bool) $timezone['dst'] === false) {
146
-                    try {
147
-                        $offset = self::get_timezone_offset(new DateTimeZone($timezone['timezone_id']));
148
-                        if ($offset !== $gmt_offset) {
149
-                            continue;
150
-                        }
151
-                        return $timezone['timezone_id'];
152
-                    } catch (Exception $e) {
153
-                        continue;
154
-                    }
155
-                }
156
-            }
157
-        }
158
-        // if $coerce is true, let's see if we can get a timezone string after the offset is adjusted
159
-        if ($coerce === true) {
160
-            $timezone_string = self::get_timezone_string_from_abbreviations_list(
161
-                self::adjust_invalid_gmt_offsets($gmt_offset),
162
-                false
163
-            );
164
-            if ($timezone_string) {
165
-                return $timezone_string;
166
-            }
167
-        }
168
-        throw new EE_Error(
169
-            sprintf(
170
-                esc_html__(
171
-                    'The provided GMT offset (%1$s), is invalid, please check with %2$sthis list%3$s for what valid timezones can be used',
172
-                    'event_espresso'
173
-                ),
174
-                $gmt_offset / HOUR_IN_SECONDS,
175
-                '<a href="http://www.php.net/manual/en/timezones.php">',
176
-                '</a>'
177
-            )
178
-        );
179
-    }
125
+	/**
126
+	 * get_timezone_string_from_abbreviations_list
127
+	 *
128
+	 * @deprecated 4.9.54.rc  Developers, this was never intended to be public.  This is a soft deprecation for now.
129
+	 *                        If you are using this, you'll want to work out an alternate way of getting the value.
130
+	 * @param int  $gmt_offset
131
+	 * @param bool $coerce If true, we attempt to coerce with our adjustment table @see self::adjust_invalid_gmt_offset.
132
+	 * @return string
133
+	 * @throws EE_Error
134
+	 * @throws InvalidArgumentException
135
+	 * @throws InvalidDataTypeException
136
+	 * @throws InvalidInterfaceException
137
+	 */
138
+	public static function get_timezone_string_from_abbreviations_list($gmt_offset = 0, $coerce = true)
139
+	{
140
+		$gmt_offset =  (int) $gmt_offset;
141
+		/** @var array[] $abbreviations */
142
+		$abbreviations = DateTimeZone::listAbbreviations();
143
+		foreach ($abbreviations as $abbreviation) {
144
+			foreach ($abbreviation as $timezone) {
145
+				if ((int) $timezone['offset'] === $gmt_offset && (bool) $timezone['dst'] === false) {
146
+					try {
147
+						$offset = self::get_timezone_offset(new DateTimeZone($timezone['timezone_id']));
148
+						if ($offset !== $gmt_offset) {
149
+							continue;
150
+						}
151
+						return $timezone['timezone_id'];
152
+					} catch (Exception $e) {
153
+						continue;
154
+					}
155
+				}
156
+			}
157
+		}
158
+		// if $coerce is true, let's see if we can get a timezone string after the offset is adjusted
159
+		if ($coerce === true) {
160
+			$timezone_string = self::get_timezone_string_from_abbreviations_list(
161
+				self::adjust_invalid_gmt_offsets($gmt_offset),
162
+				false
163
+			);
164
+			if ($timezone_string) {
165
+				return $timezone_string;
166
+			}
167
+		}
168
+		throw new EE_Error(
169
+			sprintf(
170
+				esc_html__(
171
+					'The provided GMT offset (%1$s), is invalid, please check with %2$sthis list%3$s for what valid timezones can be used',
172
+					'event_espresso'
173
+				),
174
+				$gmt_offset / HOUR_IN_SECONDS,
175
+				'<a href="http://www.php.net/manual/en/timezones.php">',
176
+				'</a>'
177
+			)
178
+		);
179
+	}
180 180
 
181 181
 
182
-    /**
183
-     * Get Timezone Transitions
184
-     *
185
-     * @param DateTimeZone $date_time_zone
186
-     * @param int|null     $time
187
-     * @param bool         $first_only
188
-     * @return array
189
-     * @throws InvalidArgumentException
190
-     * @throws InvalidDataTypeException
191
-     * @throws InvalidInterfaceException
192
-     */
193
-    public static function get_timezone_transitions(DateTimeZone $date_time_zone, $time = null, $first_only = true)
194
-    {
195
-        return self::getHelperAdapter()->getTimezoneTransitions($date_time_zone, $time, $first_only);
196
-    }
182
+	/**
183
+	 * Get Timezone Transitions
184
+	 *
185
+	 * @param DateTimeZone $date_time_zone
186
+	 * @param int|null     $time
187
+	 * @param bool         $first_only
188
+	 * @return array
189
+	 * @throws InvalidArgumentException
190
+	 * @throws InvalidDataTypeException
191
+	 * @throws InvalidInterfaceException
192
+	 */
193
+	public static function get_timezone_transitions(DateTimeZone $date_time_zone, $time = null, $first_only = true)
194
+	{
195
+		return self::getHelperAdapter()->getTimezoneTransitions($date_time_zone, $time, $first_only);
196
+	}
197 197
 
198 198
 
199
-    /**
200
-     * Get Timezone Offset for given timezone object.
201
-     *
202
-     * @param DateTimeZone $date_time_zone
203
-     * @param null         $time
204
-     * @return mixed
205
-     * @throws InvalidArgumentException
206
-     * @throws InvalidDataTypeException
207
-     * @throws InvalidInterfaceException
208
-     */
209
-    public static function get_timezone_offset(DateTimeZone $date_time_zone, $time = null)
210
-    {
211
-        return self::getHelperAdapter()->getTimezoneOffset($date_time_zone, $time);
212
-    }
199
+	/**
200
+	 * Get Timezone Offset for given timezone object.
201
+	 *
202
+	 * @param DateTimeZone $date_time_zone
203
+	 * @param null         $time
204
+	 * @return mixed
205
+	 * @throws InvalidArgumentException
206
+	 * @throws InvalidDataTypeException
207
+	 * @throws InvalidInterfaceException
208
+	 */
209
+	public static function get_timezone_offset(DateTimeZone $date_time_zone, $time = null)
210
+	{
211
+		return self::getHelperAdapter()->getTimezoneOffset($date_time_zone, $time);
212
+	}
213 213
 
214 214
 
215
-    /**
216
-     * Prints a select input for the given timezone string.
217
-     * @param string $timezone_string
218
-     * @deprecatd 4.9.54.rc   Soft deprecation.  Consider using \EEH_DTT_Helper::wp_timezone_choice instead.
219
-     * @throws InvalidArgumentException
220
-     * @throws InvalidDataTypeException
221
-     * @throws InvalidInterfaceException
222
-     */
223
-    public static function timezone_select_input($timezone_string = '')
224
-    {
225
-        self::getHelperAdapter()->timezoneSelectInput($timezone_string);
226
-    }
215
+	/**
216
+	 * Prints a select input for the given timezone string.
217
+	 * @param string $timezone_string
218
+	 * @deprecatd 4.9.54.rc   Soft deprecation.  Consider using \EEH_DTT_Helper::wp_timezone_choice instead.
219
+	 * @throws InvalidArgumentException
220
+	 * @throws InvalidDataTypeException
221
+	 * @throws InvalidInterfaceException
222
+	 */
223
+	public static function timezone_select_input($timezone_string = '')
224
+	{
225
+		self::getHelperAdapter()->timezoneSelectInput($timezone_string);
226
+	}
227 227
 
228 228
 
229
-    /**
230
-     * This method will take an incoming unix timestamp and add the offset to it for the given timezone_string.
231
-     * If no unix timestamp is given then time() is used.  If no timezone is given then the set timezone string for
232
-     * the site is used.
233
-     * This is used typically when using a Unix timestamp any core WP functions that expect their specially
234
-     * computed timestamp (i.e. date_i18n() )
235
-     *
236
-     * @param int    $unix_timestamp                  if 0, then time() will be used.
237
-     * @param string $timezone_string                 timezone_string. If empty, then the current set timezone for the
238
-     *                                                site will be used.
239
-     * @return int $unix_timestamp with the offset applied for the given timezone.
240
-     * @throws InvalidArgumentException
241
-     * @throws InvalidDataTypeException
242
-     * @throws InvalidInterfaceException
243
-     */
244
-    public static function get_timestamp_with_offset($unix_timestamp = 0, $timezone_string = '')
245
-    {
246
-        return self::getHelperAdapter()->getTimestampWithOffset($unix_timestamp, $timezone_string);
247
-    }
229
+	/**
230
+	 * This method will take an incoming unix timestamp and add the offset to it for the given timezone_string.
231
+	 * If no unix timestamp is given then time() is used.  If no timezone is given then the set timezone string for
232
+	 * the site is used.
233
+	 * This is used typically when using a Unix timestamp any core WP functions that expect their specially
234
+	 * computed timestamp (i.e. date_i18n() )
235
+	 *
236
+	 * @param int    $unix_timestamp                  if 0, then time() will be used.
237
+	 * @param string $timezone_string                 timezone_string. If empty, then the current set timezone for the
238
+	 *                                                site will be used.
239
+	 * @return int $unix_timestamp with the offset applied for the given timezone.
240
+	 * @throws InvalidArgumentException
241
+	 * @throws InvalidDataTypeException
242
+	 * @throws InvalidInterfaceException
243
+	 */
244
+	public static function get_timestamp_with_offset($unix_timestamp = 0, $timezone_string = '')
245
+	{
246
+		return self::getHelperAdapter()->getTimestampWithOffset($unix_timestamp, $timezone_string);
247
+	}
248 248
 
249 249
 
250
-    /**
251
-     *    _set_date_time_field
252
-     *    modifies EE_Base_Class EE_Datetime_Field objects
253
-     *
254
-     * @param  EE_Base_Class $obj                 EE_Base_Class object
255
-     * @param    DateTime    $DateTime            PHP DateTime object
256
-     * @param  string        $datetime_field_name the datetime fieldname to be manipulated
257
-     * @return EE_Base_Class
258
-     * @throws EE_Error
259
-     */
260
-    protected static function _set_date_time_field(EE_Base_Class $obj, DateTime $DateTime, $datetime_field_name)
261
-    {
262
-        // grab current datetime format
263
-        $current_format = $obj->get_format();
264
-        // set new full timestamp format
265
-        $obj->set_date_format(EE_Datetime_Field::mysql_date_format);
266
-        $obj->set_time_format(EE_Datetime_Field::mysql_time_format);
267
-        // set the new date value using a full timestamp format so that no data is lost
268
-        $obj->set($datetime_field_name, $DateTime->format(EE_Datetime_Field::mysql_timestamp_format));
269
-        // reset datetime formats
270
-        $obj->set_date_format($current_format[0]);
271
-        $obj->set_time_format($current_format[1]);
272
-        return $obj;
273
-    }
250
+	/**
251
+	 *    _set_date_time_field
252
+	 *    modifies EE_Base_Class EE_Datetime_Field objects
253
+	 *
254
+	 * @param  EE_Base_Class $obj                 EE_Base_Class object
255
+	 * @param    DateTime    $DateTime            PHP DateTime object
256
+	 * @param  string        $datetime_field_name the datetime fieldname to be manipulated
257
+	 * @return EE_Base_Class
258
+	 * @throws EE_Error
259
+	 */
260
+	protected static function _set_date_time_field(EE_Base_Class $obj, DateTime $DateTime, $datetime_field_name)
261
+	{
262
+		// grab current datetime format
263
+		$current_format = $obj->get_format();
264
+		// set new full timestamp format
265
+		$obj->set_date_format(EE_Datetime_Field::mysql_date_format);
266
+		$obj->set_time_format(EE_Datetime_Field::mysql_time_format);
267
+		// set the new date value using a full timestamp format so that no data is lost
268
+		$obj->set($datetime_field_name, $DateTime->format(EE_Datetime_Field::mysql_timestamp_format));
269
+		// reset datetime formats
270
+		$obj->set_date_format($current_format[0]);
271
+		$obj->set_time_format($current_format[1]);
272
+		return $obj;
273
+	}
274 274
 
275 275
 
276
-    /**
277
-     *    date_time_add
278
-     *    helper for doing simple datetime calculations on a given datetime from EE_Base_Class
279
-     *    and modifying it IN the EE_Base_Class so you don't have to do anything else.
280
-     *
281
-     * @param  EE_Base_Class $obj                 EE_Base_Class object
282
-     * @param  string        $datetime_field_name name of the EE_Datetime_Filed datatype db column to be manipulated
283
-     * @param  string        $period              what you are adding. The options are (years, months, days, hours,
284
-     *                                            minutes, seconds) defaults to years
285
-     * @param  integer       $value               what you want to increment the time by
286
-     * @return EE_Base_Class return the EE_Base_Class object so right away you can do something with it
287
-     *                                            (chaining)
288
-     * @throws EE_Error
289
-     * @throws Exception
290
-     */
291
-    public static function date_time_add(EE_Base_Class $obj, $datetime_field_name, $period = 'years', $value = 1)
292
-    {
293
-        // get the raw UTC date.
294
-        $DateTime = $obj->get_DateTime_object($datetime_field_name);
295
-        $DateTime = EEH_DTT_Helper::calc_date($DateTime, $period, $value);
296
-        return EEH_DTT_Helper::_set_date_time_field($obj, $DateTime, $datetime_field_name);
297
-    }
276
+	/**
277
+	 *    date_time_add
278
+	 *    helper for doing simple datetime calculations on a given datetime from EE_Base_Class
279
+	 *    and modifying it IN the EE_Base_Class so you don't have to do anything else.
280
+	 *
281
+	 * @param  EE_Base_Class $obj                 EE_Base_Class object
282
+	 * @param  string        $datetime_field_name name of the EE_Datetime_Filed datatype db column to be manipulated
283
+	 * @param  string        $period              what you are adding. The options are (years, months, days, hours,
284
+	 *                                            minutes, seconds) defaults to years
285
+	 * @param  integer       $value               what you want to increment the time by
286
+	 * @return EE_Base_Class return the EE_Base_Class object so right away you can do something with it
287
+	 *                                            (chaining)
288
+	 * @throws EE_Error
289
+	 * @throws Exception
290
+	 */
291
+	public static function date_time_add(EE_Base_Class $obj, $datetime_field_name, $period = 'years', $value = 1)
292
+	{
293
+		// get the raw UTC date.
294
+		$DateTime = $obj->get_DateTime_object($datetime_field_name);
295
+		$DateTime = EEH_DTT_Helper::calc_date($DateTime, $period, $value);
296
+		return EEH_DTT_Helper::_set_date_time_field($obj, $DateTime, $datetime_field_name);
297
+	}
298 298
 
299 299
 
300
-    /**
301
-     *    date_time_subtract
302
-     *    same as date_time_add except subtracting value instead of adding.
303
-     *
304
-     * @param EE_Base_Class $obj
305
-     * @param  string       $datetime_field_name name of the EE_Datetime_Filed datatype db column to be manipulated
306
-     * @param string        $period
307
-     * @param int           $value
308
-     * @return EE_Base_Class
309
-     * @throws EE_Error
310
-     * @throws Exception
311
-     */
312
-    public static function date_time_subtract(EE_Base_Class $obj, $datetime_field_name, $period = 'years', $value = 1)
313
-    {
314
-        // get the raw UTC date
315
-        $DateTime = $obj->get_DateTime_object($datetime_field_name);
316
-        $DateTime = EEH_DTT_Helper::calc_date($DateTime, $period, $value, '-');
317
-        return EEH_DTT_Helper::_set_date_time_field($obj, $DateTime, $datetime_field_name);
318
-    }
300
+	/**
301
+	 *    date_time_subtract
302
+	 *    same as date_time_add except subtracting value instead of adding.
303
+	 *
304
+	 * @param EE_Base_Class $obj
305
+	 * @param  string       $datetime_field_name name of the EE_Datetime_Filed datatype db column to be manipulated
306
+	 * @param string        $period
307
+	 * @param int           $value
308
+	 * @return EE_Base_Class
309
+	 * @throws EE_Error
310
+	 * @throws Exception
311
+	 */
312
+	public static function date_time_subtract(EE_Base_Class $obj, $datetime_field_name, $period = 'years', $value = 1)
313
+	{
314
+		// get the raw UTC date
315
+		$DateTime = $obj->get_DateTime_object($datetime_field_name);
316
+		$DateTime = EEH_DTT_Helper::calc_date($DateTime, $period, $value, '-');
317
+		return EEH_DTT_Helper::_set_date_time_field($obj, $DateTime, $datetime_field_name);
318
+	}
319 319
 
320 320
 
321
-    /**
322
-     * Simply takes an incoming DateTime object and does calculations on it based on the incoming parameters
323
-     *
324
-     * @param  DateTime   $DateTime DateTime object
325
-     * @param  string     $period   a value to indicate what interval is being used in the calculation. The options are
326
-     *                              'years', 'months', 'days', 'hours', 'minutes', 'seconds'. Defaults to years.
327
-     * @param  int|string $value    What you want to increment the date by
328
-     * @param  string     $operand  What operand you wish to use for the calculation
329
-     * @return DateTime return whatever type came in.
330
-     * @throws Exception
331
-     * @throws EE_Error
332
-     */
333
-    protected static function _modify_datetime_object(DateTime $DateTime, $period = 'years', $value = 1, $operand = '+')
334
-    {
335
-        if (! $DateTime instanceof DateTime) {
336
-            throw new EE_Error(
337
-                sprintf(
338
-                    esc_html__('Expected a PHP DateTime object, but instead received %1$s', 'event_espresso'),
339
-                    print_r($DateTime, true)
340
-                )
341
-            );
342
-        }
343
-        switch ($period) {
344
-            case 'years':
345
-                $value = 'P' . $value . 'Y';
346
-                break;
347
-            case 'months':
348
-                $value = 'P' . $value . 'M';
349
-                break;
350
-            case 'weeks':
351
-                $value = 'P' . $value . 'W';
352
-                break;
353
-            case 'days':
354
-                $value = 'P' . $value . 'D';
355
-                break;
356
-            case 'hours':
357
-                $value = 'PT' . $value . 'H';
358
-                break;
359
-            case 'minutes':
360
-                $value = 'PT' . $value . 'M';
361
-                break;
362
-            case 'seconds':
363
-                $value = 'PT' . $value . 'S';
364
-                break;
365
-        }
366
-        switch ($operand) {
367
-            case '+':
368
-                $DateTime->add(new DateInterval($value));
369
-                break;
370
-            case '-':
371
-                $DateTime->sub(new DateInterval($value));
372
-                break;
373
-        }
374
-        return $DateTime;
375
-    }
321
+	/**
322
+	 * Simply takes an incoming DateTime object and does calculations on it based on the incoming parameters
323
+	 *
324
+	 * @param  DateTime   $DateTime DateTime object
325
+	 * @param  string     $period   a value to indicate what interval is being used in the calculation. The options are
326
+	 *                              'years', 'months', 'days', 'hours', 'minutes', 'seconds'. Defaults to years.
327
+	 * @param  int|string $value    What you want to increment the date by
328
+	 * @param  string     $operand  What operand you wish to use for the calculation
329
+	 * @return DateTime return whatever type came in.
330
+	 * @throws Exception
331
+	 * @throws EE_Error
332
+	 */
333
+	protected static function _modify_datetime_object(DateTime $DateTime, $period = 'years', $value = 1, $operand = '+')
334
+	{
335
+		if (! $DateTime instanceof DateTime) {
336
+			throw new EE_Error(
337
+				sprintf(
338
+					esc_html__('Expected a PHP DateTime object, but instead received %1$s', 'event_espresso'),
339
+					print_r($DateTime, true)
340
+				)
341
+			);
342
+		}
343
+		switch ($period) {
344
+			case 'years':
345
+				$value = 'P' . $value . 'Y';
346
+				break;
347
+			case 'months':
348
+				$value = 'P' . $value . 'M';
349
+				break;
350
+			case 'weeks':
351
+				$value = 'P' . $value . 'W';
352
+				break;
353
+			case 'days':
354
+				$value = 'P' . $value . 'D';
355
+				break;
356
+			case 'hours':
357
+				$value = 'PT' . $value . 'H';
358
+				break;
359
+			case 'minutes':
360
+				$value = 'PT' . $value . 'M';
361
+				break;
362
+			case 'seconds':
363
+				$value = 'PT' . $value . 'S';
364
+				break;
365
+		}
366
+		switch ($operand) {
367
+			case '+':
368
+				$DateTime->add(new DateInterval($value));
369
+				break;
370
+			case '-':
371
+				$DateTime->sub(new DateInterval($value));
372
+				break;
373
+		}
374
+		return $DateTime;
375
+	}
376 376
 
377 377
 
378
-    /**
379
-     * Simply takes an incoming Unix timestamp and does calculations on it based on the incoming parameters
380
-     *
381
-     * @param  int     $timestamp Unix timestamp
382
-     * @param  string  $period    a value to indicate what interval is being used in the calculation. The options are
383
-     *                            'years', 'months', 'days', 'hours', 'minutes', 'seconds'. Defaults to years.
384
-     * @param  integer $value     What you want to increment the date by
385
-     * @param  string  $operand   What operand you wish to use for the calculation
386
-     * @return int
387
-     * @throws EE_Error
388
-     */
389
-    protected static function _modify_timestamp($timestamp, $period = 'years', $value = 1, $operand = '+')
390
-    {
391
-        if (! preg_match(EE_Datetime_Field::unix_timestamp_regex, $timestamp)) {
392
-            throw new EE_Error(
393
-                sprintf(
394
-                    esc_html__('Expected a Unix timestamp, but instead received %1$s', 'event_espresso'),
395
-                    print_r($timestamp, true)
396
-                )
397
-            );
398
-        }
399
-        switch ($period) {
400
-            case 'years':
401
-                $value = YEAR_IN_SECONDS * $value;
402
-                break;
403
-            case 'months':
404
-                $value = YEAR_IN_SECONDS / 12 * $value;
405
-                break;
406
-            case 'weeks':
407
-                $value = WEEK_IN_SECONDS * $value;
408
-                break;
409
-            case 'days':
410
-                $value = DAY_IN_SECONDS * $value;
411
-                break;
412
-            case 'hours':
413
-                $value = HOUR_IN_SECONDS * $value;
414
-                break;
415
-            case 'minutes':
416
-                $value = MINUTE_IN_SECONDS * $value;
417
-                break;
418
-        }
419
-        switch ($operand) {
420
-            case '+':
421
-                $timestamp += $value;
422
-                break;
423
-            case '-':
424
-                $timestamp -= $value;
425
-                break;
426
-        }
427
-        return $timestamp;
428
-    }
378
+	/**
379
+	 * Simply takes an incoming Unix timestamp and does calculations on it based on the incoming parameters
380
+	 *
381
+	 * @param  int     $timestamp Unix timestamp
382
+	 * @param  string  $period    a value to indicate what interval is being used in the calculation. The options are
383
+	 *                            'years', 'months', 'days', 'hours', 'minutes', 'seconds'. Defaults to years.
384
+	 * @param  integer $value     What you want to increment the date by
385
+	 * @param  string  $operand   What operand you wish to use for the calculation
386
+	 * @return int
387
+	 * @throws EE_Error
388
+	 */
389
+	protected static function _modify_timestamp($timestamp, $period = 'years', $value = 1, $operand = '+')
390
+	{
391
+		if (! preg_match(EE_Datetime_Field::unix_timestamp_regex, $timestamp)) {
392
+			throw new EE_Error(
393
+				sprintf(
394
+					esc_html__('Expected a Unix timestamp, but instead received %1$s', 'event_espresso'),
395
+					print_r($timestamp, true)
396
+				)
397
+			);
398
+		}
399
+		switch ($period) {
400
+			case 'years':
401
+				$value = YEAR_IN_SECONDS * $value;
402
+				break;
403
+			case 'months':
404
+				$value = YEAR_IN_SECONDS / 12 * $value;
405
+				break;
406
+			case 'weeks':
407
+				$value = WEEK_IN_SECONDS * $value;
408
+				break;
409
+			case 'days':
410
+				$value = DAY_IN_SECONDS * $value;
411
+				break;
412
+			case 'hours':
413
+				$value = HOUR_IN_SECONDS * $value;
414
+				break;
415
+			case 'minutes':
416
+				$value = MINUTE_IN_SECONDS * $value;
417
+				break;
418
+		}
419
+		switch ($operand) {
420
+			case '+':
421
+				$timestamp += $value;
422
+				break;
423
+			case '-':
424
+				$timestamp -= $value;
425
+				break;
426
+		}
427
+		return $timestamp;
428
+	}
429 429
 
430 430
 
431
-    /**
432
-     * Simply takes an incoming UTC timestamp or DateTime object and does calculations on it based on the incoming
433
-     * parameters and returns the new timestamp or DateTime.
434
-     *
435
-     * @param  int | DateTime $DateTime_or_timestamp DateTime object or Unix timestamp
436
-     * @param  string         $period                a value to indicate what interval is being used in the
437
-     *                                               calculation. The options are 'years', 'months', 'days', 'hours',
438
-     *                                               'minutes', 'seconds'. Defaults to years.
439
-     * @param  integer        $value                 What you want to increment the date by
440
-     * @param  string         $operand               What operand you wish to use for the calculation
441
-     * @return mixed string|DateTime          return whatever type came in.
442
-     * @throws Exception
443
-     * @throws EE_Error
444
-     */
445
-    public static function calc_date($DateTime_or_timestamp, $period = 'years', $value = 1, $operand = '+')
446
-    {
447
-        if ($DateTime_or_timestamp instanceof DateTime) {
448
-            return EEH_DTT_Helper::_modify_datetime_object(
449
-                $DateTime_or_timestamp,
450
-                $period,
451
-                $value,
452
-                $operand
453
-            );
454
-        }
455
-        if (preg_match(EE_Datetime_Field::unix_timestamp_regex, $DateTime_or_timestamp)) {
456
-            return EEH_DTT_Helper::_modify_timestamp(
457
-                $DateTime_or_timestamp,
458
-                $period,
459
-                $value,
460
-                $operand
461
-            );
462
-        }
463
-        // error
464
-        return $DateTime_or_timestamp;
465
-    }
431
+	/**
432
+	 * Simply takes an incoming UTC timestamp or DateTime object and does calculations on it based on the incoming
433
+	 * parameters and returns the new timestamp or DateTime.
434
+	 *
435
+	 * @param  int | DateTime $DateTime_or_timestamp DateTime object or Unix timestamp
436
+	 * @param  string         $period                a value to indicate what interval is being used in the
437
+	 *                                               calculation. The options are 'years', 'months', 'days', 'hours',
438
+	 *                                               'minutes', 'seconds'. Defaults to years.
439
+	 * @param  integer        $value                 What you want to increment the date by
440
+	 * @param  string         $operand               What operand you wish to use for the calculation
441
+	 * @return mixed string|DateTime          return whatever type came in.
442
+	 * @throws Exception
443
+	 * @throws EE_Error
444
+	 */
445
+	public static function calc_date($DateTime_or_timestamp, $period = 'years', $value = 1, $operand = '+')
446
+	{
447
+		if ($DateTime_or_timestamp instanceof DateTime) {
448
+			return EEH_DTT_Helper::_modify_datetime_object(
449
+				$DateTime_or_timestamp,
450
+				$period,
451
+				$value,
452
+				$operand
453
+			);
454
+		}
455
+		if (preg_match(EE_Datetime_Field::unix_timestamp_regex, $DateTime_or_timestamp)) {
456
+			return EEH_DTT_Helper::_modify_timestamp(
457
+				$DateTime_or_timestamp,
458
+				$period,
459
+				$value,
460
+				$operand
461
+			);
462
+		}
463
+		// error
464
+		return $DateTime_or_timestamp;
465
+	}
466 466
 
467 467
 
468
-    /**
469
-     * The purpose of this helper method is to receive an incoming format string in php date/time format
470
-     * and spit out the js and moment.js equivalent formats.
471
-     * Note, if no format string is given, then it is assumed the user wants what is set for WP.
472
-     * Note, js date and time formats are those used by the jquery-ui datepicker and the jquery-ui date-
473
-     * time picker.
474
-     *
475
-     * @see http://stackoverflow.com/posts/16725290/ for the code inspiration.
476
-     * @param string $date_format_string
477
-     * @param string $time_format_string
478
-     * @return array
479
-     *              array(
480
-     *              'js' => array (
481
-     *              'date' => //date format
482
-     *              'time' => //time format
483
-     *              ),
484
-     *              'moment' => //date and time format.
485
-     *              )
486
-     */
487
-    public static function convert_php_to_js_and_moment_date_formats(
488
-        $date_format_string = null,
489
-        $time_format_string = null
490
-    ) {
491
-        if ($date_format_string === null) {
492
-            $date_format_string = (string) get_option('date_format');
493
-        }
494
-        if ($time_format_string === null) {
495
-            $time_format_string = (string) get_option('time_format');
496
-        }
497
-        $date_format = self::_php_to_js_moment_converter($date_format_string);
498
-        $time_format = self::_php_to_js_moment_converter($time_format_string);
499
-        return array(
500
-            'js'     => array(
501
-                'date' => $date_format['js'],
502
-                'time' => $time_format['js'],
503
-            ),
504
-            'moment' => $date_format['moment'] . ' ' . $time_format['moment'],
505
-            'moment_split' => array(
506
-                'date' => $date_format['moment'],
507
-                'time' => $time_format['moment']
508
-            )
509
-        );
510
-    }
468
+	/**
469
+	 * The purpose of this helper method is to receive an incoming format string in php date/time format
470
+	 * and spit out the js and moment.js equivalent formats.
471
+	 * Note, if no format string is given, then it is assumed the user wants what is set for WP.
472
+	 * Note, js date and time formats are those used by the jquery-ui datepicker and the jquery-ui date-
473
+	 * time picker.
474
+	 *
475
+	 * @see http://stackoverflow.com/posts/16725290/ for the code inspiration.
476
+	 * @param string $date_format_string
477
+	 * @param string $time_format_string
478
+	 * @return array
479
+	 *              array(
480
+	 *              'js' => array (
481
+	 *              'date' => //date format
482
+	 *              'time' => //time format
483
+	 *              ),
484
+	 *              'moment' => //date and time format.
485
+	 *              )
486
+	 */
487
+	public static function convert_php_to_js_and_moment_date_formats(
488
+		$date_format_string = null,
489
+		$time_format_string = null
490
+	) {
491
+		if ($date_format_string === null) {
492
+			$date_format_string = (string) get_option('date_format');
493
+		}
494
+		if ($time_format_string === null) {
495
+			$time_format_string = (string) get_option('time_format');
496
+		}
497
+		$date_format = self::_php_to_js_moment_converter($date_format_string);
498
+		$time_format = self::_php_to_js_moment_converter($time_format_string);
499
+		return array(
500
+			'js'     => array(
501
+				'date' => $date_format['js'],
502
+				'time' => $time_format['js'],
503
+			),
504
+			'moment' => $date_format['moment'] . ' ' . $time_format['moment'],
505
+			'moment_split' => array(
506
+				'date' => $date_format['moment'],
507
+				'time' => $time_format['moment']
508
+			)
509
+		);
510
+	}
511 511
 
512 512
 
513
-    /**
514
-     * This converts incoming format string into js and moment variations.
515
-     *
516
-     * @param string $format_string incoming php format string
517
-     * @return array js and moment formats.
518
-     */
519
-    protected static function _php_to_js_moment_converter($format_string)
520
-    {
521
-        /**
522
-         * This is a map of symbols for formats.
523
-         * The index is the php symbol, the equivalent values are in the array.
524
-         *
525
-         * @var array
526
-         */
527
-        $symbols_map          = array(
528
-            // Day
529
-            // 01
530
-            'd' => array(
531
-                'js'     => 'dd',
532
-                'moment' => 'DD',
533
-            ),
534
-            // Mon
535
-            'D' => array(
536
-                'js'     => 'D',
537
-                'moment' => 'ddd',
538
-            ),
539
-            // 1,2,...31
540
-            'j' => array(
541
-                'js'     => 'd',
542
-                'moment' => 'D',
543
-            ),
544
-            // Monday
545
-            'l' => array(
546
-                'js'     => 'DD',
547
-                'moment' => 'dddd',
548
-            ),
549
-            // ISO numeric representation of the day of the week (1-6)
550
-            'N' => array(
551
-                'js'     => '',
552
-                'moment' => 'E',
553
-            ),
554
-            // st,nd.rd
555
-            'S' => array(
556
-                'js'     => '',
557
-                'moment' => 'o',
558
-            ),
559
-            // numeric representation of day of week (0-6)
560
-            'w' => array(
561
-                'js'     => '',
562
-                'moment' => 'd',
563
-            ),
564
-            // day of year starting from 0 (0-365)
565
-            'z' => array(
566
-                'js'     => 'o',
567
-                'moment' => 'DDD' // note moment does not start with 0 so will need to modify by subtracting 1
568
-            ),
569
-            // Week
570
-            // ISO-8601 week number of year (weeks starting on monday)
571
-            'W' => array(
572
-                'js'     => '',
573
-                'moment' => 'w',
574
-            ),
575
-            // Month
576
-            // January...December
577
-            'F' => array(
578
-                'js'     => 'MM',
579
-                'moment' => 'MMMM',
580
-            ),
581
-            // 01...12
582
-            'm' => array(
583
-                'js'     => 'mm',
584
-                'moment' => 'MM',
585
-            ),
586
-            // Jan...Dec
587
-            'M' => array(
588
-                'js'     => 'M',
589
-                'moment' => 'MMM',
590
-            ),
591
-            // 1-12
592
-            'n' => array(
593
-                'js'     => 'm',
594
-                'moment' => 'M',
595
-            ),
596
-            // number of days in given month
597
-            't' => array(
598
-                'js'     => '',
599
-                'moment' => '',
600
-            ),
601
-            // Year
602
-            // whether leap year or not 1/0
603
-            'L' => array(
604
-                'js'     => '',
605
-                'moment' => '',
606
-            ),
607
-            // ISO-8601 year number
608
-            'o' => array(
609
-                'js'     => '',
610
-                'moment' => 'GGGG',
611
-            ),
612
-            // 1999...2003
613
-            'Y' => array(
614
-                'js'     => 'yy',
615
-                'moment' => 'YYYY',
616
-            ),
617
-            // 99...03
618
-            'y' => array(
619
-                'js'     => 'y',
620
-                'moment' => 'YY',
621
-            ),
622
-            // Time
623
-            // am/pm
624
-            'a' => array(
625
-                'js'     => 'tt',
626
-                'moment' => 'a',
627
-            ),
628
-            // AM/PM
629
-            'A' => array(
630
-                'js'     => 'TT',
631
-                'moment' => 'A',
632
-            ),
633
-            // Swatch Internet Time?!?
634
-            'B' => array(
635
-                'js'     => '',
636
-                'moment' => '',
637
-            ),
638
-            // 1...12
639
-            'g' => array(
640
-                'js'     => 'h',
641
-                'moment' => 'h',
642
-            ),
643
-            // 0...23
644
-            'G' => array(
645
-                'js'     => 'H',
646
-                'moment' => 'H',
647
-            ),
648
-            // 01...12
649
-            'h' => array(
650
-                'js'     => 'hh',
651
-                'moment' => 'hh',
652
-            ),
653
-            // 00...23
654
-            'H' => array(
655
-                'js'     => 'HH',
656
-                'moment' => 'HH',
657
-            ),
658
-            // 00..59
659
-            'i' => array(
660
-                'js'     => 'mm',
661
-                'moment' => 'mm',
662
-            ),
663
-            // seconds... 00...59
664
-            's' => array(
665
-                'js'     => 'ss',
666
-                'moment' => 'ss',
667
-            ),
668
-            // microseconds
669
-            'u' => array(
670
-                'js'     => '',
671
-                'moment' => '',
672
-            ),
673
-        );
674
-        $jquery_ui_format     = '';
675
-        $moment_format        = '';
676
-        $escaping             = false;
677
-        $format_string_length = strlen($format_string);
678
-        for ($i = 0; $i < $format_string_length; $i++) {
679
-            $char = $format_string[ $i ];
680
-            if ($char === '\\') { // PHP date format escaping character
681
-                $i++;
682
-                if ($escaping) {
683
-                    $jquery_ui_format .= $format_string[ $i ];
684
-                    $moment_format    .= $format_string[ $i ];
685
-                } else {
686
-                    $jquery_ui_format .= '\'' . $format_string[ $i ];
687
-                    $moment_format    .= $format_string[ $i ];
688
-                }
689
-                $escaping = true;
690
-            } else {
691
-                if ($escaping) {
692
-                    $jquery_ui_format .= "'";
693
-                    $moment_format    .= "'";
694
-                    $escaping         = false;
695
-                }
696
-                if (isset($symbols_map[ $char ])) {
697
-                    $jquery_ui_format .= $symbols_map[ $char ]['js'];
698
-                    $moment_format    .= $symbols_map[ $char ]['moment'];
699
-                } else {
700
-                    $jquery_ui_format .= $char;
701
-                    $moment_format    .= $char;
702
-                }
703
-            }
704
-        }
705
-        return array('js' => $jquery_ui_format, 'moment' => $moment_format);
706
-    }
513
+	/**
514
+	 * This converts incoming format string into js and moment variations.
515
+	 *
516
+	 * @param string $format_string incoming php format string
517
+	 * @return array js and moment formats.
518
+	 */
519
+	protected static function _php_to_js_moment_converter($format_string)
520
+	{
521
+		/**
522
+		 * This is a map of symbols for formats.
523
+		 * The index is the php symbol, the equivalent values are in the array.
524
+		 *
525
+		 * @var array
526
+		 */
527
+		$symbols_map          = array(
528
+			// Day
529
+			// 01
530
+			'd' => array(
531
+				'js'     => 'dd',
532
+				'moment' => 'DD',
533
+			),
534
+			// Mon
535
+			'D' => array(
536
+				'js'     => 'D',
537
+				'moment' => 'ddd',
538
+			),
539
+			// 1,2,...31
540
+			'j' => array(
541
+				'js'     => 'd',
542
+				'moment' => 'D',
543
+			),
544
+			// Monday
545
+			'l' => array(
546
+				'js'     => 'DD',
547
+				'moment' => 'dddd',
548
+			),
549
+			// ISO numeric representation of the day of the week (1-6)
550
+			'N' => array(
551
+				'js'     => '',
552
+				'moment' => 'E',
553
+			),
554
+			// st,nd.rd
555
+			'S' => array(
556
+				'js'     => '',
557
+				'moment' => 'o',
558
+			),
559
+			// numeric representation of day of week (0-6)
560
+			'w' => array(
561
+				'js'     => '',
562
+				'moment' => 'd',
563
+			),
564
+			// day of year starting from 0 (0-365)
565
+			'z' => array(
566
+				'js'     => 'o',
567
+				'moment' => 'DDD' // note moment does not start with 0 so will need to modify by subtracting 1
568
+			),
569
+			// Week
570
+			// ISO-8601 week number of year (weeks starting on monday)
571
+			'W' => array(
572
+				'js'     => '',
573
+				'moment' => 'w',
574
+			),
575
+			// Month
576
+			// January...December
577
+			'F' => array(
578
+				'js'     => 'MM',
579
+				'moment' => 'MMMM',
580
+			),
581
+			// 01...12
582
+			'm' => array(
583
+				'js'     => 'mm',
584
+				'moment' => 'MM',
585
+			),
586
+			// Jan...Dec
587
+			'M' => array(
588
+				'js'     => 'M',
589
+				'moment' => 'MMM',
590
+			),
591
+			// 1-12
592
+			'n' => array(
593
+				'js'     => 'm',
594
+				'moment' => 'M',
595
+			),
596
+			// number of days in given month
597
+			't' => array(
598
+				'js'     => '',
599
+				'moment' => '',
600
+			),
601
+			// Year
602
+			// whether leap year or not 1/0
603
+			'L' => array(
604
+				'js'     => '',
605
+				'moment' => '',
606
+			),
607
+			// ISO-8601 year number
608
+			'o' => array(
609
+				'js'     => '',
610
+				'moment' => 'GGGG',
611
+			),
612
+			// 1999...2003
613
+			'Y' => array(
614
+				'js'     => 'yy',
615
+				'moment' => 'YYYY',
616
+			),
617
+			// 99...03
618
+			'y' => array(
619
+				'js'     => 'y',
620
+				'moment' => 'YY',
621
+			),
622
+			// Time
623
+			// am/pm
624
+			'a' => array(
625
+				'js'     => 'tt',
626
+				'moment' => 'a',
627
+			),
628
+			// AM/PM
629
+			'A' => array(
630
+				'js'     => 'TT',
631
+				'moment' => 'A',
632
+			),
633
+			// Swatch Internet Time?!?
634
+			'B' => array(
635
+				'js'     => '',
636
+				'moment' => '',
637
+			),
638
+			// 1...12
639
+			'g' => array(
640
+				'js'     => 'h',
641
+				'moment' => 'h',
642
+			),
643
+			// 0...23
644
+			'G' => array(
645
+				'js'     => 'H',
646
+				'moment' => 'H',
647
+			),
648
+			// 01...12
649
+			'h' => array(
650
+				'js'     => 'hh',
651
+				'moment' => 'hh',
652
+			),
653
+			// 00...23
654
+			'H' => array(
655
+				'js'     => 'HH',
656
+				'moment' => 'HH',
657
+			),
658
+			// 00..59
659
+			'i' => array(
660
+				'js'     => 'mm',
661
+				'moment' => 'mm',
662
+			),
663
+			// seconds... 00...59
664
+			's' => array(
665
+				'js'     => 'ss',
666
+				'moment' => 'ss',
667
+			),
668
+			// microseconds
669
+			'u' => array(
670
+				'js'     => '',
671
+				'moment' => '',
672
+			),
673
+		);
674
+		$jquery_ui_format     = '';
675
+		$moment_format        = '';
676
+		$escaping             = false;
677
+		$format_string_length = strlen($format_string);
678
+		for ($i = 0; $i < $format_string_length; $i++) {
679
+			$char = $format_string[ $i ];
680
+			if ($char === '\\') { // PHP date format escaping character
681
+				$i++;
682
+				if ($escaping) {
683
+					$jquery_ui_format .= $format_string[ $i ];
684
+					$moment_format    .= $format_string[ $i ];
685
+				} else {
686
+					$jquery_ui_format .= '\'' . $format_string[ $i ];
687
+					$moment_format    .= $format_string[ $i ];
688
+				}
689
+				$escaping = true;
690
+			} else {
691
+				if ($escaping) {
692
+					$jquery_ui_format .= "'";
693
+					$moment_format    .= "'";
694
+					$escaping         = false;
695
+				}
696
+				if (isset($symbols_map[ $char ])) {
697
+					$jquery_ui_format .= $symbols_map[ $char ]['js'];
698
+					$moment_format    .= $symbols_map[ $char ]['moment'];
699
+				} else {
700
+					$jquery_ui_format .= $char;
701
+					$moment_format    .= $char;
702
+				}
703
+			}
704
+		}
705
+		return array('js' => $jquery_ui_format, 'moment' => $moment_format);
706
+	}
707 707
 
708 708
 
709
-    /**
710
-     * This takes an incoming format string and validates it to ensure it will work fine with PHP.
711
-     *
712
-     * @param string $format_string   Incoming format string for php date().
713
-     * @return mixed bool|array  If all is okay then TRUE is returned.  Otherwise an array of validation
714
-     *                                errors is returned.  So for client code calling, check for is_array() to
715
-     *                                indicate failed validations.
716
-     */
717
-    public static function validate_format_string($format_string)
718
-    {
719
-        $error_msg = array();
720
-        // time format checks
721
-        switch (true) {
722
-            case strpos($format_string, 'h') !== false:
723
-            case strpos($format_string, 'g') !== false:
724
-                /**
725
-                 * if the time string has a lowercase 'h' which == 12 hour time format and there
726
-                 * is not any ante meridiem format ('a' or 'A').  Then throw an error because its
727
-                 * too ambiguous and PHP won't be able to figure out whether 1 = 1pm or 1am.
728
-                 */
729
-                if (stripos($format_string, 'A') === false) {
730
-                    $error_msg[] = esc_html__(
731
-                        'There is a  time format for 12 hour time but no  "a" or "A" to indicate am/pm.  Without this distinction, PHP is unable to determine if a "1" for the hour value equals "1pm" or "1am".',
732
-                        'event_espresso'
733
-                    );
734
-                }
735
-                break;
736
-        }
737
-        return empty($error_msg) ? true : $error_msg;
738
-    }
709
+	/**
710
+	 * This takes an incoming format string and validates it to ensure it will work fine with PHP.
711
+	 *
712
+	 * @param string $format_string   Incoming format string for php date().
713
+	 * @return mixed bool|array  If all is okay then TRUE is returned.  Otherwise an array of validation
714
+	 *                                errors is returned.  So for client code calling, check for is_array() to
715
+	 *                                indicate failed validations.
716
+	 */
717
+	public static function validate_format_string($format_string)
718
+	{
719
+		$error_msg = array();
720
+		// time format checks
721
+		switch (true) {
722
+			case strpos($format_string, 'h') !== false:
723
+			case strpos($format_string, 'g') !== false:
724
+				/**
725
+				 * if the time string has a lowercase 'h' which == 12 hour time format and there
726
+				 * is not any ante meridiem format ('a' or 'A').  Then throw an error because its
727
+				 * too ambiguous and PHP won't be able to figure out whether 1 = 1pm or 1am.
728
+				 */
729
+				if (stripos($format_string, 'A') === false) {
730
+					$error_msg[] = esc_html__(
731
+						'There is a  time format for 12 hour time but no  "a" or "A" to indicate am/pm.  Without this distinction, PHP is unable to determine if a "1" for the hour value equals "1pm" or "1am".',
732
+						'event_espresso'
733
+					);
734
+				}
735
+				break;
736
+		}
737
+		return empty($error_msg) ? true : $error_msg;
738
+	}
739 739
 
740 740
 
741
-    /**
742
-     *     If the the first date starts at midnight on one day, and the next date ends at midnight on the
743
-     *     very next day then this method will return true.
744
-     *    If $date_1 = 2015-12-15 00:00:00 and $date_2 = 2015-12-16 00:00:00 then this function will return true.
745
-     *    If $date_1 = 2015-12-15 03:00:00 and $date_2 = 2015-12_16 03:00:00 then this function will return false.
746
-     *    If $date_1 = 2015-12-15 00:00:00 and $date_2 = 2015-12-15 00:00:00 then this function will return true.
747
-     *
748
-     * @param mixed $date_1
749
-     * @param mixed $date_2
750
-     * @return bool
751
-     */
752
-    public static function dates_represent_one_24_hour_date($date_1, $date_2)
753
-    {
741
+	/**
742
+	 *     If the the first date starts at midnight on one day, and the next date ends at midnight on the
743
+	 *     very next day then this method will return true.
744
+	 *    If $date_1 = 2015-12-15 00:00:00 and $date_2 = 2015-12-16 00:00:00 then this function will return true.
745
+	 *    If $date_1 = 2015-12-15 03:00:00 and $date_2 = 2015-12_16 03:00:00 then this function will return false.
746
+	 *    If $date_1 = 2015-12-15 00:00:00 and $date_2 = 2015-12-15 00:00:00 then this function will return true.
747
+	 *
748
+	 * @param mixed $date_1
749
+	 * @param mixed $date_2
750
+	 * @return bool
751
+	 */
752
+	public static function dates_represent_one_24_hour_date($date_1, $date_2)
753
+	{
754 754
 
755
-        if (
756
-            (! $date_1 instanceof DateTime || ! $date_2 instanceof DateTime)
757
-            || ($date_1->format(EE_Datetime_Field::mysql_time_format) !== '00:00:00'
758
-                || $date_2->format(
759
-                    EE_Datetime_Field::mysql_time_format
760
-                ) !== '00:00:00')
761
-        ) {
762
-            return false;
763
-        }
764
-        return $date_2->format('U') - $date_1->format('U') === 86400;
765
-    }
755
+		if (
756
+			(! $date_1 instanceof DateTime || ! $date_2 instanceof DateTime)
757
+			|| ($date_1->format(EE_Datetime_Field::mysql_time_format) !== '00:00:00'
758
+				|| $date_2->format(
759
+					EE_Datetime_Field::mysql_time_format
760
+				) !== '00:00:00')
761
+		) {
762
+			return false;
763
+		}
764
+		return $date_2->format('U') - $date_1->format('U') === 86400;
765
+	}
766 766
 
767 767
 
768
-    /**
769
-     * This returns the appropriate query interval string that can be used in sql queries involving mysql Date
770
-     * Functions.
771
-     *
772
-     * @param string $timezone_string    A timezone string in a valid format to instantiate a DateTimeZone object.
773
-     * @param string $field_for_interval The Database field that is the interval is applied to in the query.
774
-     * @return string
775
-     */
776
-    public static function get_sql_query_interval_for_offset($timezone_string, $field_for_interval)
777
-    {
778
-        try {
779
-            /** need to account for timezone offset on the selects */
780
-            $DateTimeZone = new DateTimeZone($timezone_string);
781
-        } catch (Exception $e) {
782
-            $DateTimeZone = null;
783
-        }
784
-        /**
785
-         * Note get_option( 'gmt_offset') returns a value in hours, whereas DateTimeZone::getOffset returns values in seconds.
786
-         * Hence we do the calc for DateTimeZone::getOffset.
787
-         */
788
-        $offset         = $DateTimeZone instanceof DateTimeZone
789
-            ? $DateTimeZone->getOffset(new DateTime('now')) / HOUR_IN_SECONDS
790
-            : (float) get_option('gmt_offset');
791
-        $query_interval = $offset < 0
792
-            ? 'DATE_SUB(' . $field_for_interval . ', INTERVAL ' . $offset * -1 . ' HOUR)'
793
-            : 'DATE_ADD(' . $field_for_interval . ', INTERVAL ' . $offset . ' HOUR)';
794
-        return $query_interval;
795
-    }
768
+	/**
769
+	 * This returns the appropriate query interval string that can be used in sql queries involving mysql Date
770
+	 * Functions.
771
+	 *
772
+	 * @param string $timezone_string    A timezone string in a valid format to instantiate a DateTimeZone object.
773
+	 * @param string $field_for_interval The Database field that is the interval is applied to in the query.
774
+	 * @return string
775
+	 */
776
+	public static function get_sql_query_interval_for_offset($timezone_string, $field_for_interval)
777
+	{
778
+		try {
779
+			/** need to account for timezone offset on the selects */
780
+			$DateTimeZone = new DateTimeZone($timezone_string);
781
+		} catch (Exception $e) {
782
+			$DateTimeZone = null;
783
+		}
784
+		/**
785
+		 * Note get_option( 'gmt_offset') returns a value in hours, whereas DateTimeZone::getOffset returns values in seconds.
786
+		 * Hence we do the calc for DateTimeZone::getOffset.
787
+		 */
788
+		$offset         = $DateTimeZone instanceof DateTimeZone
789
+			? $DateTimeZone->getOffset(new DateTime('now')) / HOUR_IN_SECONDS
790
+			: (float) get_option('gmt_offset');
791
+		$query_interval = $offset < 0
792
+			? 'DATE_SUB(' . $field_for_interval . ', INTERVAL ' . $offset * -1 . ' HOUR)'
793
+			: 'DATE_ADD(' . $field_for_interval . ', INTERVAL ' . $offset . ' HOUR)';
794
+		return $query_interval;
795
+	}
796 796
 
797 797
 
798
-    /**
799
-     * Retrieves the site's default timezone and returns it formatted so it's ready for display
800
-     * to users. If you want to customize how its displayed feel free to fetch the 'timezone_string'
801
-     * and 'gmt_offset' WordPress options directly; or use the filter
802
-     * FHEE__EEH_DTT_Helper__get_timezone_string_for_display
803
-     * (although note that we remove any HTML that may be added)
804
-     *
805
-     * @return string
806
-     */
807
-    public static function get_timezone_string_for_display()
808
-    {
809
-        $pretty_timezone = apply_filters('FHEE__EEH_DTT_Helper__get_timezone_string_for_display', '');
810
-        if (! empty($pretty_timezone)) {
811
-            return esc_html($pretty_timezone);
812
-        }
813
-        $timezone_string = get_option('timezone_string');
814
-        if ($timezone_string) {
815
-            static $mo_loaded = false;
816
-            // Load translations for continents and cities just like wp_timezone_choice does
817
-            if (! $mo_loaded) {
818
-                $locale = get_locale();
819
-                $mofile = WP_LANG_DIR . '/continents-cities-' . $locale . '.mo';
820
-                load_textdomain('continents-cities', $mofile);
821
-                $mo_loaded = true;
822
-            }
823
-            // well that was easy.
824
-            $parts = explode('/', $timezone_string);
825
-            // remove the continent
826
-            unset($parts[0]);
827
-            $t_parts = array();
828
-            // phpcs:disable WordPress.WP.I18n.NonSingularStringLiteralText
829
-            // phpcs:disable WordPress.WP.I18n.TextDomainMismatch
830
-            // disabled because this code is copied from WordPress and is a WordPress domain
831
-            foreach ($parts as $part) {
832
-                $t_parts[] = translate(str_replace('_', ' ', $part), 'continents-cities');
833
-            }
834
-            return implode(' - ', $t_parts);
835
-            // phpcs:enable
836
-        }
837
-        // they haven't set the timezone string, so let's return a string like "UTC+1"
838
-        $gmt_offset = get_option('gmt_offset');
839
-        $prefix     = (int) $gmt_offset >= 0 ? '+' : '';
840
-        $parts      = explode('.', (string) $gmt_offset);
841
-        if (count($parts) === 1) {
842
-            $parts[1] = '00';
843
-        } else {
844
-            // convert the part after the decimal, eg "5" (from x.5) or "25" (from x.25)
845
-            // to minutes, eg 30 or 15, respectively
846
-            $hour_fraction = (float) ('0.' . $parts[1]);
847
-            $parts[1]      = (string) $hour_fraction * 60;
848
-        }
849
-        return sprintf(__('UTC%1$s', 'event_espresso'), $prefix . implode(':', $parts));
850
-    }
798
+	/**
799
+	 * Retrieves the site's default timezone and returns it formatted so it's ready for display
800
+	 * to users. If you want to customize how its displayed feel free to fetch the 'timezone_string'
801
+	 * and 'gmt_offset' WordPress options directly; or use the filter
802
+	 * FHEE__EEH_DTT_Helper__get_timezone_string_for_display
803
+	 * (although note that we remove any HTML that may be added)
804
+	 *
805
+	 * @return string
806
+	 */
807
+	public static function get_timezone_string_for_display()
808
+	{
809
+		$pretty_timezone = apply_filters('FHEE__EEH_DTT_Helper__get_timezone_string_for_display', '');
810
+		if (! empty($pretty_timezone)) {
811
+			return esc_html($pretty_timezone);
812
+		}
813
+		$timezone_string = get_option('timezone_string');
814
+		if ($timezone_string) {
815
+			static $mo_loaded = false;
816
+			// Load translations for continents and cities just like wp_timezone_choice does
817
+			if (! $mo_loaded) {
818
+				$locale = get_locale();
819
+				$mofile = WP_LANG_DIR . '/continents-cities-' . $locale . '.mo';
820
+				load_textdomain('continents-cities', $mofile);
821
+				$mo_loaded = true;
822
+			}
823
+			// well that was easy.
824
+			$parts = explode('/', $timezone_string);
825
+			// remove the continent
826
+			unset($parts[0]);
827
+			$t_parts = array();
828
+			// phpcs:disable WordPress.WP.I18n.NonSingularStringLiteralText
829
+			// phpcs:disable WordPress.WP.I18n.TextDomainMismatch
830
+			// disabled because this code is copied from WordPress and is a WordPress domain
831
+			foreach ($parts as $part) {
832
+				$t_parts[] = translate(str_replace('_', ' ', $part), 'continents-cities');
833
+			}
834
+			return implode(' - ', $t_parts);
835
+			// phpcs:enable
836
+		}
837
+		// they haven't set the timezone string, so let's return a string like "UTC+1"
838
+		$gmt_offset = get_option('gmt_offset');
839
+		$prefix     = (int) $gmt_offset >= 0 ? '+' : '';
840
+		$parts      = explode('.', (string) $gmt_offset);
841
+		if (count($parts) === 1) {
842
+			$parts[1] = '00';
843
+		} else {
844
+			// convert the part after the decimal, eg "5" (from x.5) or "25" (from x.25)
845
+			// to minutes, eg 30 or 15, respectively
846
+			$hour_fraction = (float) ('0.' . $parts[1]);
847
+			$parts[1]      = (string) $hour_fraction * 60;
848
+		}
849
+		return sprintf(__('UTC%1$s', 'event_espresso'), $prefix . implode(':', $parts));
850
+	}
851 851
 
852 852
 
853 853
 
854
-    /**
855
-     * So PHP does this awesome thing where if you are trying to get a timestamp
856
-     * for a month using a string like "February" or "February 2017",
857
-     * and you don't specify a day as part of your string,
858
-     * then PHP will use whatever the current day of the month is.
859
-     * IF the current day of the month happens to be the 30th or 31st,
860
-     * then PHP gets really confused by a date like February 30,
861
-     * so instead of saying
862
-     *      "Hey February only has 28 days (this year)...
863
-     *      ...you must have meant the last day of the month!"
864
-     * PHP does the next most logical thing, and bumps the date up to March 2nd,
865
-     * because someone requesting February 30th obviously meant March 1st!
866
-     * The way around this is to always set the day to the first,
867
-     * so that the month will stay on the month you wanted.
868
-     * this method will add that "1" into your date regardless of the format.
869
-     *
870
-     * @param string $month
871
-     * @return string
872
-     */
873
-    public static function first_of_month_timestamp($month = '')
874
-    {
875
-        $month = (string) $month;
876
-        $year  = '';
877
-        // check if the incoming string has a year in it or not
878
-        if (preg_match('/\b\d{4}\b/', $month, $matches)) {
879
-            $year = $matches[0];
880
-            // ten remove that from the month string as well as any spaces
881
-            $month = trim(str_replace($year, '', $month));
882
-            // add a space before the year
883
-            $year = " {$year}";
884
-        }
885
-        // return timestamp for something like "February 1 2017"
886
-        return strtotime("{$month} 1{$year}");
887
-    }
854
+	/**
855
+	 * So PHP does this awesome thing where if you are trying to get a timestamp
856
+	 * for a month using a string like "February" or "February 2017",
857
+	 * and you don't specify a day as part of your string,
858
+	 * then PHP will use whatever the current day of the month is.
859
+	 * IF the current day of the month happens to be the 30th or 31st,
860
+	 * then PHP gets really confused by a date like February 30,
861
+	 * so instead of saying
862
+	 *      "Hey February only has 28 days (this year)...
863
+	 *      ...you must have meant the last day of the month!"
864
+	 * PHP does the next most logical thing, and bumps the date up to March 2nd,
865
+	 * because someone requesting February 30th obviously meant March 1st!
866
+	 * The way around this is to always set the day to the first,
867
+	 * so that the month will stay on the month you wanted.
868
+	 * this method will add that "1" into your date regardless of the format.
869
+	 *
870
+	 * @param string $month
871
+	 * @return string
872
+	 */
873
+	public static function first_of_month_timestamp($month = '')
874
+	{
875
+		$month = (string) $month;
876
+		$year  = '';
877
+		// check if the incoming string has a year in it or not
878
+		if (preg_match('/\b\d{4}\b/', $month, $matches)) {
879
+			$year = $matches[0];
880
+			// ten remove that from the month string as well as any spaces
881
+			$month = trim(str_replace($year, '', $month));
882
+			// add a space before the year
883
+			$year = " {$year}";
884
+		}
885
+		// return timestamp for something like "February 1 2017"
886
+		return strtotime("{$month} 1{$year}");
887
+	}
888 888
 
889 889
 
890
-    /**
891
-     * This simply returns the timestamp for tomorrow (midnight next day) in this sites timezone.  So it may be midnight
892
-     * for this sites timezone, but the timestamp could be some other time GMT.
893
-     */
894
-    public static function tomorrow()
895
-    {
896
-        // The multiplication of -1 ensures that we switch positive offsets to negative and negative offsets to positive
897
-        // before adding to the timestamp.  Why? Because we want tomorrow to be for midnight the next day in THIS timezone
898
-        // not an offset from midnight in UTC.  So if we're starting with UTC 00:00:00, then we want to make sure the
899
-        // final timestamp is equivalent to midnight in this timezone as represented in GMT.
900
-        return strtotime('tomorrow') + (self::get_site_timezone_gmt_offset() * -1);
901
-    }
890
+	/**
891
+	 * This simply returns the timestamp for tomorrow (midnight next day) in this sites timezone.  So it may be midnight
892
+	 * for this sites timezone, but the timestamp could be some other time GMT.
893
+	 */
894
+	public static function tomorrow()
895
+	{
896
+		// The multiplication of -1 ensures that we switch positive offsets to negative and negative offsets to positive
897
+		// before adding to the timestamp.  Why? Because we want tomorrow to be for midnight the next day in THIS timezone
898
+		// not an offset from midnight in UTC.  So if we're starting with UTC 00:00:00, then we want to make sure the
899
+		// final timestamp is equivalent to midnight in this timezone as represented in GMT.
900
+		return strtotime('tomorrow') + (self::get_site_timezone_gmt_offset() * -1);
901
+	}
902 902
 
903 903
 
904
-    /**
905
-     * **
906
-     * Gives a nicely-formatted list of timezone strings.
907
-     * Copied from the core wp function by the same name so we could customize to remove UTC offsets.
908
-     *
909
-     * @since     4.9.40.rc.008
910
-     * @staticvar bool $mo_loaded
911
-     * @staticvar string $locale_loaded
912
-     * @param string $selected_zone Selected timezone.
913
-     * @param string $locale        Optional. Locale to load the timezones in. Default current site locale.
914
-     * @return string
915
-     */
916
-    public static function wp_timezone_choice($selected_zone, $locale = null)
917
-    {
918
-        static $mo_loaded = false, $locale_loaded = null;
919
-        $continents = array(
920
-            'Africa',
921
-            'America',
922
-            'Antarctica',
923
-            'Arctic',
924
-            'Asia',
925
-            'Atlantic',
926
-            'Australia',
927
-            'Europe',
928
-            'Indian',
929
-            'Pacific',
930
-        );
931
-        // Load translations for continents and cities.
932
-        if (! $mo_loaded || $locale !== $locale_loaded) {
933
-            $locale_loaded = $locale ? $locale : get_locale();
934
-            $mofile        = WP_LANG_DIR . '/continents-cities-' . $locale_loaded . '.mo';
935
-            unload_textdomain('continents-cities');
936
-            load_textdomain('continents-cities', $mofile);
937
-            $mo_loaded = true;
938
-        }
939
-        $zone_data = array();
940
-        foreach (timezone_identifiers_list() as $zone) {
941
-            $zone = explode('/', $zone);
942
-            if (! in_array($zone[0], $continents, true)) {
943
-                continue;
944
-            }
945
-            // This determines what gets set and translated - we don't translate Etc/* strings here, they are done later
946
-            $exists      = array(
947
-                0 => isset($zone[0]) && $zone[0],
948
-                1 => isset($zone[1]) && $zone[1],
949
-                2 => isset($zone[2]) && $zone[2],
950
-            );
951
-            $exists[3]   = $exists[0] && $zone[0] !== 'Etc';
952
-            $exists[4]   = $exists[1] && $exists[3];
953
-            $exists[5]   = $exists[2] && $exists[3];
954
-            // phpcs:disable WordPress.WP.I18n.NonSingularStringLiteralText
955
-            // phpcs:disable WordPress.WP.I18n.TextDomainMismatch
956
-            // disabled because this code is copied from WordPress and is a WordPress domain
957
-            $zone_data[] = array(
958
-                'continent'   => $exists[0] ? $zone[0] : '',
959
-                'city'        => $exists[1] ? $zone[1] : '',
960
-                'subcity'     => $exists[2] ? $zone[2] : '',
961
-                't_continent' => $exists[3]
962
-                    ? translate(str_replace('_', ' ', $zone[0]), 'continents-cities')
963
-                    : '',
964
-                't_city'      => $exists[4]
965
-                    ? translate(str_replace('_', ' ', $zone[1]), 'continents-cities')
966
-                    : '',
967
-                't_subcity'   => $exists[5]
968
-                    ? translate(str_replace('_', ' ', $zone[2]), 'continents-cities')
969
-                    : '',
970
-            );
971
-            // phpcs:enable
972
-        }
973
-        usort($zone_data, '_wp_timezone_choice_usort_callback');
974
-        $structure = array();
975
-        if (empty($selected_zone)) {
976
-            $structure[] = '<option selected="selected" value="">' . __('Select a city', 'event_espresso') . '</option>';
977
-        }
978
-        foreach ($zone_data as $key => $zone) {
979
-            // Build value in an array to join later
980
-            $value = array($zone['continent']);
981
-            if (empty($zone['city'])) {
982
-                // It's at the continent level (generally won't happen)
983
-                $display = $zone['t_continent'];
984
-            } else {
985
-                // It's inside a continent group
986
-                // Continent optgroup
987
-                if (! isset($zone_data[ $key - 1 ]) || $zone_data[ $key - 1 ]['continent'] !== $zone['continent']) {
988
-                    $label       = $zone['t_continent'];
989
-                    $structure[] = '<optgroup label="' . esc_attr($label) . '">';
990
-                }
991
-                // Add the city to the value
992
-                $value[] = $zone['city'];
993
-                $display = $zone['t_city'];
994
-                if (! empty($zone['subcity'])) {
995
-                    // Add the subcity to the value
996
-                    $value[] = $zone['subcity'];
997
-                    $display .= ' - ' . $zone['t_subcity'];
998
-                }
999
-            }
1000
-            // Build the value
1001
-            $value       = implode('/', $value);
1002
-            $selected    = $value === $selected_zone ? ' selected="selected"' : '';
1003
-            $structure[] = '<option value="' . esc_attr($value) . '"' . $selected . '>'
1004
-                           . esc_html($display)
1005
-                           . '</option>';
1006
-            // Close continent optgroup
1007
-            if (
1008
-                ! empty($zone['city'])
1009
-                && (
1010
-                    ! isset($zone_data[ $key + 1 ])
1011
-                    || (isset($zone_data[ $key + 1 ]) && $zone_data[ $key + 1 ]['continent'] !== $zone['continent'])
1012
-                )
1013
-            ) {
1014
-                $structure[] = '</optgroup>';
1015
-            }
1016
-        }
1017
-        return implode("\n", $structure);
1018
-    }
904
+	/**
905
+	 * **
906
+	 * Gives a nicely-formatted list of timezone strings.
907
+	 * Copied from the core wp function by the same name so we could customize to remove UTC offsets.
908
+	 *
909
+	 * @since     4.9.40.rc.008
910
+	 * @staticvar bool $mo_loaded
911
+	 * @staticvar string $locale_loaded
912
+	 * @param string $selected_zone Selected timezone.
913
+	 * @param string $locale        Optional. Locale to load the timezones in. Default current site locale.
914
+	 * @return string
915
+	 */
916
+	public static function wp_timezone_choice($selected_zone, $locale = null)
917
+	{
918
+		static $mo_loaded = false, $locale_loaded = null;
919
+		$continents = array(
920
+			'Africa',
921
+			'America',
922
+			'Antarctica',
923
+			'Arctic',
924
+			'Asia',
925
+			'Atlantic',
926
+			'Australia',
927
+			'Europe',
928
+			'Indian',
929
+			'Pacific',
930
+		);
931
+		// Load translations for continents and cities.
932
+		if (! $mo_loaded || $locale !== $locale_loaded) {
933
+			$locale_loaded = $locale ? $locale : get_locale();
934
+			$mofile        = WP_LANG_DIR . '/continents-cities-' . $locale_loaded . '.mo';
935
+			unload_textdomain('continents-cities');
936
+			load_textdomain('continents-cities', $mofile);
937
+			$mo_loaded = true;
938
+		}
939
+		$zone_data = array();
940
+		foreach (timezone_identifiers_list() as $zone) {
941
+			$zone = explode('/', $zone);
942
+			if (! in_array($zone[0], $continents, true)) {
943
+				continue;
944
+			}
945
+			// This determines what gets set and translated - we don't translate Etc/* strings here, they are done later
946
+			$exists      = array(
947
+				0 => isset($zone[0]) && $zone[0],
948
+				1 => isset($zone[1]) && $zone[1],
949
+				2 => isset($zone[2]) && $zone[2],
950
+			);
951
+			$exists[3]   = $exists[0] && $zone[0] !== 'Etc';
952
+			$exists[4]   = $exists[1] && $exists[3];
953
+			$exists[5]   = $exists[2] && $exists[3];
954
+			// phpcs:disable WordPress.WP.I18n.NonSingularStringLiteralText
955
+			// phpcs:disable WordPress.WP.I18n.TextDomainMismatch
956
+			// disabled because this code is copied from WordPress and is a WordPress domain
957
+			$zone_data[] = array(
958
+				'continent'   => $exists[0] ? $zone[0] : '',
959
+				'city'        => $exists[1] ? $zone[1] : '',
960
+				'subcity'     => $exists[2] ? $zone[2] : '',
961
+				't_continent' => $exists[3]
962
+					? translate(str_replace('_', ' ', $zone[0]), 'continents-cities')
963
+					: '',
964
+				't_city'      => $exists[4]
965
+					? translate(str_replace('_', ' ', $zone[1]), 'continents-cities')
966
+					: '',
967
+				't_subcity'   => $exists[5]
968
+					? translate(str_replace('_', ' ', $zone[2]), 'continents-cities')
969
+					: '',
970
+			);
971
+			// phpcs:enable
972
+		}
973
+		usort($zone_data, '_wp_timezone_choice_usort_callback');
974
+		$structure = array();
975
+		if (empty($selected_zone)) {
976
+			$structure[] = '<option selected="selected" value="">' . __('Select a city', 'event_espresso') . '</option>';
977
+		}
978
+		foreach ($zone_data as $key => $zone) {
979
+			// Build value in an array to join later
980
+			$value = array($zone['continent']);
981
+			if (empty($zone['city'])) {
982
+				// It's at the continent level (generally won't happen)
983
+				$display = $zone['t_continent'];
984
+			} else {
985
+				// It's inside a continent group
986
+				// Continent optgroup
987
+				if (! isset($zone_data[ $key - 1 ]) || $zone_data[ $key - 1 ]['continent'] !== $zone['continent']) {
988
+					$label       = $zone['t_continent'];
989
+					$structure[] = '<optgroup label="' . esc_attr($label) . '">';
990
+				}
991
+				// Add the city to the value
992
+				$value[] = $zone['city'];
993
+				$display = $zone['t_city'];
994
+				if (! empty($zone['subcity'])) {
995
+					// Add the subcity to the value
996
+					$value[] = $zone['subcity'];
997
+					$display .= ' - ' . $zone['t_subcity'];
998
+				}
999
+			}
1000
+			// Build the value
1001
+			$value       = implode('/', $value);
1002
+			$selected    = $value === $selected_zone ? ' selected="selected"' : '';
1003
+			$structure[] = '<option value="' . esc_attr($value) . '"' . $selected . '>'
1004
+						   . esc_html($display)
1005
+						   . '</option>';
1006
+			// Close continent optgroup
1007
+			if (
1008
+				! empty($zone['city'])
1009
+				&& (
1010
+					! isset($zone_data[ $key + 1 ])
1011
+					|| (isset($zone_data[ $key + 1 ]) && $zone_data[ $key + 1 ]['continent'] !== $zone['continent'])
1012
+				)
1013
+			) {
1014
+				$structure[] = '</optgroup>';
1015
+			}
1016
+		}
1017
+		return implode("\n", $structure);
1018
+	}
1019 1019
 
1020 1020
 
1021
-    /**
1022
-     * Shim for the WP function `get_user_locale` that was added in WordPress 4.7.0
1023
-     *
1024
-     * @param int|WP_User $user_id
1025
-     * @return string
1026
-     */
1027
-    public static function get_user_locale($user_id = 0)
1028
-    {
1029
-        if (function_exists('get_user_locale')) {
1030
-            return get_user_locale($user_id);
1031
-        }
1032
-        return get_locale();
1033
-    }
1021
+	/**
1022
+	 * Shim for the WP function `get_user_locale` that was added in WordPress 4.7.0
1023
+	 *
1024
+	 * @param int|WP_User $user_id
1025
+	 * @return string
1026
+	 */
1027
+	public static function get_user_locale($user_id = 0)
1028
+	{
1029
+		if (function_exists('get_user_locale')) {
1030
+			return get_user_locale($user_id);
1031
+		}
1032
+		return get_locale();
1033
+	}
1034 1034
 
1035 1035
 
1036
-    /**
1037
-     * Return the appropriate helper adapter for DTT related things.
1038
-     *
1039
-     * @return HelperInterface
1040
-     * @throws InvalidArgumentException
1041
-     * @throws InvalidDataTypeException
1042
-     * @throws InvalidInterfaceException
1043
-     */
1044
-    private static function getHelperAdapter()
1045
-    {
1046
-        $dtt_helper_fqcn = PHP_VERSION_ID < 50600
1047
-            ? 'EventEspresso\core\services\helpers\datetime\PhpCompatLessFiveSixHelper'
1048
-            : 'EventEspresso\core\services\helpers\datetime\PhpCompatGreaterFiveSixHelper';
1049
-        return LoaderFactory::getLoader()->getShared($dtt_helper_fqcn);
1050
-    }
1036
+	/**
1037
+	 * Return the appropriate helper adapter for DTT related things.
1038
+	 *
1039
+	 * @return HelperInterface
1040
+	 * @throws InvalidArgumentException
1041
+	 * @throws InvalidDataTypeException
1042
+	 * @throws InvalidInterfaceException
1043
+	 */
1044
+	private static function getHelperAdapter()
1045
+	{
1046
+		$dtt_helper_fqcn = PHP_VERSION_ID < 50600
1047
+			? 'EventEspresso\core\services\helpers\datetime\PhpCompatLessFiveSixHelper'
1048
+			: 'EventEspresso\core\services\helpers\datetime\PhpCompatGreaterFiveSixHelper';
1049
+		return LoaderFactory::getLoader()->getShared($dtt_helper_fqcn);
1050
+	}
1051 1051
 
1052 1052
 
1053
-    /**
1054
-     * Helper function for setting the timezone on a DateTime object.
1055
-     * This is implemented to standardize a workaround for a PHP bug outlined in
1056
-     * https://events.codebasehq.com/projects/event-espresso/tickets/11407 and
1057
-     * https://events.codebasehq.com/projects/event-espresso/tickets/11233
1058
-     *
1059
-     * @param DateTime     $datetime
1060
-     * @param DateTimeZone $timezone
1061
-     */
1062
-    public static function setTimezone(DateTime $datetime, DateTimeZone $timezone)
1063
-    {
1064
-        $datetime->setTimezone($timezone);
1065
-        $datetime->getTimestamp();
1066
-    }
1053
+	/**
1054
+	 * Helper function for setting the timezone on a DateTime object.
1055
+	 * This is implemented to standardize a workaround for a PHP bug outlined in
1056
+	 * https://events.codebasehq.com/projects/event-espresso/tickets/11407 and
1057
+	 * https://events.codebasehq.com/projects/event-espresso/tickets/11233
1058
+	 *
1059
+	 * @param DateTime     $datetime
1060
+	 * @param DateTimeZone $timezone
1061
+	 */
1062
+	public static function setTimezone(DateTime $datetime, DateTimeZone $timezone)
1063
+	{
1064
+		$datetime->setTimezone($timezone);
1065
+		$datetime->getTimestamp();
1066
+	}
1067 1067
 }
Please login to merge, or discard this patch.
core/EE_Data_Mapper.core.php 1 patch
Indentation   +95 added lines, -95 removed lines patch added patch discarded remove patch
@@ -16,99 +16,99 @@
 block discarded – undo
16 16
 {
17 17
 
18 18
 
19
-    /**
20
-     * instance of the EE_Data_Mapper Object
21
-     *
22
-     * @private _instance
23
-     */
24
-    private static $_instance;
25
-
26
-
27
-    public $data = array();
28
-
29
-
30
-    /**
31
-     *private constructor to prevent direct creation
32
-     *
33
-     * @Constructor
34
-     * @access private
35
-     * @return void
36
-     */
37
-    private function __construct()
38
-    {
39
-    }
40
-
41
-
42
-    /**
43
-     *@ singleton method used to instantiate class object
44
-     *@ access public
45
-     *@ return class instance
46
-     */
47
-    public function &instance()
48
-    {
49
-        // check if class object is instantiated
50
-        if (
51
-            self::$_instance === null
52
-            || ! is_object(self::$_instance)
53
-            || ! self::$_instance instanceof EE_Data_Mapper
54
-        ) {
55
-            self::$_instance = new self();
56
-        }
57
-        return self::$_instance;
58
-    }
59
-
60
-
61
-    /**
62
-     *        @ override magic methods
63
-     *        @ return void
64
-     */
65
-    final public function __destruct()
66
-    {
67
-    }
68
-
69
-    final public function __call($a, $b)
70
-    {
71
-    }
72
-
73
-    public static function __callStatic($a, $b)
74
-    {
75
-    }
76
-
77
-    final public function __get($a)
78
-    {
79
-    }
80
-
81
-    final public function __set($a, $b)
82
-    {
83
-    }
84
-
85
-    final public function __isset($a)
86
-    {
87
-    }
88
-
89
-    final public function __unset($a)
90
-    {
91
-    }
92
-
93
-    final public function __sleep()
94
-    {
95
-        return array();
96
-    }
97
-
98
-    final public function __wakeup()
99
-    {
100
-    }
101
-
102
-    final public function __toString()
103
-    {
104
-        return '';
105
-    }
106
-
107
-    final public function __invoke()
108
-    {
109
-    }
110
-
111
-    final public function __clone()
112
-    {
113
-    }
19
+	/**
20
+	 * instance of the EE_Data_Mapper Object
21
+	 *
22
+	 * @private _instance
23
+	 */
24
+	private static $_instance;
25
+
26
+
27
+	public $data = array();
28
+
29
+
30
+	/**
31
+	 *private constructor to prevent direct creation
32
+	 *
33
+	 * @Constructor
34
+	 * @access private
35
+	 * @return void
36
+	 */
37
+	private function __construct()
38
+	{
39
+	}
40
+
41
+
42
+	/**
43
+	 *@ singleton method used to instantiate class object
44
+	 *@ access public
45
+	 *@ return class instance
46
+	 */
47
+	public function &instance()
48
+	{
49
+		// check if class object is instantiated
50
+		if (
51
+			self::$_instance === null
52
+			|| ! is_object(self::$_instance)
53
+			|| ! self::$_instance instanceof EE_Data_Mapper
54
+		) {
55
+			self::$_instance = new self();
56
+		}
57
+		return self::$_instance;
58
+	}
59
+
60
+
61
+	/**
62
+	 *        @ override magic methods
63
+	 *        @ return void
64
+	 */
65
+	final public function __destruct()
66
+	{
67
+	}
68
+
69
+	final public function __call($a, $b)
70
+	{
71
+	}
72
+
73
+	public static function __callStatic($a, $b)
74
+	{
75
+	}
76
+
77
+	final public function __get($a)
78
+	{
79
+	}
80
+
81
+	final public function __set($a, $b)
82
+	{
83
+	}
84
+
85
+	final public function __isset($a)
86
+	{
87
+	}
88
+
89
+	final public function __unset($a)
90
+	{
91
+	}
92
+
93
+	final public function __sleep()
94
+	{
95
+		return array();
96
+	}
97
+
98
+	final public function __wakeup()
99
+	{
100
+	}
101
+
102
+	final public function __toString()
103
+	{
104
+		return '';
105
+	}
106
+
107
+	final public function __invoke()
108
+	{
109
+	}
110
+
111
+	final public function __clone()
112
+	{
113
+	}
114 114
 }
Please login to merge, or discard this patch.
core/helpers/EEH_Autoloader.helper.php 1 patch
Indentation   +271 added lines, -271 removed lines patch added patch discarded remove patch
@@ -15,275 +15,275 @@
 block discarded – undo
15 15
 {
16 16
 
17 17
 
18
-    /**
19
-     *    instance of the EE_System object
20
-     *
21
-     * @var    $_instance
22
-     */
23
-    private static $_instance;
24
-
25
-    /**
26
-     *   $_autoloaders
27
-     * @var array $_autoloaders
28
-     */
29
-    private static $_autoloaders;
30
-
31
-    /**
32
-     * set to "paths" to display autoloader class => path mappings
33
-     * set to "times" to display autoloader loading times
34
-     * set to "all" to display both
35
-     *
36
-     * @var string $debug
37
-     */
38
-    public static $debug = false;
39
-
40
-
41
-    /**
42
-     * @throws EE_Error
43
-     */
44
-    private function __construct()
45
-    {
46
-        if (EEH_Autoloader::$_autoloaders === null) {
47
-            EEH_Autoloader::$_autoloaders = [];
48
-            $this->_register_custom_autoloaders();
49
-            spl_autoload_register([$this, 'espresso_autoloader']);
50
-        }
51
-    }
52
-
53
-
54
-    /**
55
-     * @return EEH_Autoloader
56
-     */
57
-    public static function instance(): EEH_Autoloader
58
-    {
59
-        // check if class object is instantiated
60
-        if (! EEH_Autoloader::$_instance instanceof EEH_Autoloader) {
61
-            EEH_Autoloader::$_instance = new EEH_Autoloader();
62
-        }
63
-        return EEH_Autoloader::$_instance;
64
-    }
65
-
66
-
67
-    /**
68
-     * @param   $class_name
69
-     * @return  void
70
-     * @internal  param string $class_name - simple class name ie: session
71
-     * @internal  param $className
72
-     */
73
-    public static function espresso_autoloader($class_name)
74
-    {
75
-        if (isset(EEH_Autoloader::$_autoloaders[ $class_name ])) {
76
-            require_once(EEH_Autoloader::$_autoloaders[ $class_name ]);
77
-        }
78
-    }
79
-
80
-
81
-    /**
82
-     * @param array | string $class_paths - array of key => value pairings between class names and paths
83
-     * @param bool           $read_check  true if we need to check whether the file is readable or not.
84
-     * @param bool           $debug       **deprecated**
85
-     * @throws EE_Error
86
-     */
87
-    public static function register_autoloader($class_paths, $read_check = true, $debug = false)
88
-    {
89
-        $class_paths = is_array($class_paths) ? $class_paths : [$class_paths];
90
-        foreach ($class_paths as $class => $path) {
91
-            // skip all files that are not PHP
92
-            if (substr($path, strlen($path) - 3) !== 'php') {
93
-                continue;
94
-            }
95
-            // don't give up! you gotta...
96
-            // get some class
97
-            if (empty($class)) {
98
-                throw new EE_Error(
99
-                    sprintf(
100
-                        esc_html__(
101
-                            'No Class name was specified while registering an autoloader for the following path: %s.',
102
-                            'event_espresso'
103
-                        ),
104
-                        $path
105
-                    )
106
-                );
107
-            }
108
-            // one day you will find the path young grasshopper
109
-            if (empty($path)) {
110
-                throw new EE_Error(
111
-                    sprintf(
112
-                        esc_html__('No path was specified while registering an autoloader for the %s class.', 'event_espresso'),
113
-                        $class
114
-                    )
115
-                );
116
-            }
117
-            // is file readable ?
118
-            if ($read_check && ! is_readable($path)) {
119
-                throw new EE_Error(
120
-                    sprintf(
121
-                        esc_html__(
122
-                            'The file for the %s class could not be found or is not readable due to file permissions. Please ensure the following path is correct: %s',
123
-                            'event_espresso'
124
-                        ),
125
-                        $class,
126
-                        $path
127
-                    )
128
-                );
129
-            }
130
-            if (! isset(EEH_Autoloader::$_autoloaders[ $class ])) {
131
-                EEH_Autoloader::$_autoloaders[ $class ] = str_replace(['/', '\\'], '/', $path);
132
-                if (EE_DEBUG && (EEH_Autoloader::$debug === 'paths' || EEH_Autoloader::$debug === 'all' || $debug)) {
133
-                    EEH_Debug_Tools::printr(EEH_Autoloader::$_autoloaders[ $class ], $class, __FILE__, __LINE__);
134
-                }
135
-            }
136
-        }
137
-    }
138
-
139
-
140
-    /**
141
-     * @return array
142
-     */
143
-    public static function get_autoloaders(): array
144
-    {
145
-        return EEH_Autoloader::$_autoloaders;
146
-    }
147
-
148
-
149
-    /**
150
-     * @return void
151
-     * @throws EE_Error
152
-     */
153
-    private function _register_custom_autoloaders()
154
-    {
155
-        EEH_Autoloader::$debug = '';
156
-        EEH_Autoloader::register_helpers_autoloaders();
157
-        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE . 'interfaces');
158
-        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE);
159
-        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_INTERFACES, true);
160
-        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_MODELS, true);
161
-        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CLASSES);
162
-        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_FORM_SECTIONS, true);
163
-        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'messages');
164
-        if (EEH_Autoloader::$debug === 'times' || EEH_Autoloader::$debug === 'all') {
165
-            Benchmark::displayResults();
166
-        }
167
-    }
168
-
169
-
170
-    /**
171
-     * @throws EE_Error
172
-     */
173
-    public static function register_helpers_autoloaders()
174
-    {
175
-        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_HELPERS);
176
-    }
177
-
178
-
179
-    /**
180
-     * @return void
181
-     */
182
-    public static function register_form_sections_autoloaders()
183
-    {
184
-        // EEH_Autoloader::register_autoloaders_for_each_file_in_folder( EE_FORM_SECTIONS, true );
185
-    }
186
-
187
-
188
-    /**
189
-     * @return void
190
-     * @throws EE_Error
191
-     */
192
-    public static function register_line_item_display_autoloaders()
193
-    {
194
-        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'line_item_display', true);
195
-    }
196
-
197
-
198
-    /**
199
-     * @return void
200
-     * @throws EE_Error
201
-     */
202
-    public static function register_line_item_filter_autoloaders()
203
-    {
204
-        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'line_item_filters', true);
205
-    }
206
-
207
-
208
-    /**
209
-     * @return void
210
-     * @throws EE_Error
211
-     */
212
-    public static function register_template_part_autoloaders()
213
-    {
214
-        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'template_parts', true);
215
-    }
216
-
217
-
218
-    /**
219
-     * @return void
220
-     * @throws EE_Error
221
-     */
222
-    public static function register_business_classes()
223
-    {
224
-        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE . 'business');
225
-    }
226
-
227
-
228
-    /**
229
-     * Assumes all the files in this folder have the normal naming scheme (namely that their classname
230
-     * is the file's name, plus ".whatever.php".) and adds each of them to the autoloader list.
231
-     * If that's not the case, you'll need to improve this function or just use
232
-     * EEH_File::get_classname_from_filepath_with_standard_filename() directly. Yes this has to scan the directory for
233
-     * files, but it only does it once -- not on EACH time the autoloader is used
234
-     *
235
-     * @param string $folder name, with or without trailing /, doesn't matter
236
-     * @param bool   $recursive
237
-     * @param bool   $debug  **deprecated**
238
-     * @throws EE_Error
239
-     */
240
-    public static function register_autoloaders_for_each_file_in_folder(
241
-        string $folder,
242
-        bool $recursive = false,
243
-        bool $debug = false
244
-    ) {
245
-        if (EEH_Autoloader::$debug === 'times' || EEH_Autoloader::$debug === 'all' || $debug) {
246
-            Benchmark::startTimer(basename($folder));
247
-        }
248
-        // make sure last char is a /
249
-        $folder .= $folder[ strlen($folder) - 1 ] !== '/' ? '/' : '';
250
-        $class_to_filepath_map = [];
251
-        $exclude = ['index'];
252
-        // get all the files in that folder that end in php
253
-        $filepaths = glob($folder . '*');
254
-
255
-        if (empty($filepaths)) {
256
-            return;
257
-        }
258
-
259
-        foreach ($filepaths as $filepath) {
260
-            if (substr($filepath, -4, 4) === '.php') {
261
-                $class_name = EEH_File::get_classname_from_filepath_with_standard_filename($filepath);
262
-                if (! in_array($class_name, $exclude)) {
263
-                    $class_to_filepath_map [ $class_name ] = $filepath;
264
-                }
265
-            } elseif ($recursive) {
266
-                EEH_Autoloader::register_autoloaders_for_each_file_in_folder($filepath, $recursive, $debug);
267
-            }
268
-        }
269
-        // we remove the necessity to do a is_readable() check via the $read_check flag because glob by nature will not return non_readable files/directories.
270
-        EEH_Autoloader::register_autoloader($class_to_filepath_map, false, $debug);
271
-        if (EEH_Autoloader::$debug === 'times' || EEH_Autoloader::$debug === 'all') {
272
-            Benchmark::stopTimer(basename($folder));
273
-        }
274
-    }
275
-
276
-
277
-    /**
278
-     * register additional autoloader based on variation of the classname for an existing autoloader
279
-     *
280
-     * @param string $class_name - simple class name ie: EE_Session
281
-     * @param string $alias      - variation on class name ie: EE_session, session, etc
282
-     */
283
-    public static function add_alias(string $class_name, string $alias)
284
-    {
285
-        if (isset(EEH_Autoloader::$_autoloaders[ $class_name ])) {
286
-            EEH_Autoloader::$_autoloaders[ $alias ] = EEH_Autoloader::$_autoloaders[ $class_name ];
287
-        }
288
-    }
18
+	/**
19
+	 *    instance of the EE_System object
20
+	 *
21
+	 * @var    $_instance
22
+	 */
23
+	private static $_instance;
24
+
25
+	/**
26
+	 *   $_autoloaders
27
+	 * @var array $_autoloaders
28
+	 */
29
+	private static $_autoloaders;
30
+
31
+	/**
32
+	 * set to "paths" to display autoloader class => path mappings
33
+	 * set to "times" to display autoloader loading times
34
+	 * set to "all" to display both
35
+	 *
36
+	 * @var string $debug
37
+	 */
38
+	public static $debug = false;
39
+
40
+
41
+	/**
42
+	 * @throws EE_Error
43
+	 */
44
+	private function __construct()
45
+	{
46
+		if (EEH_Autoloader::$_autoloaders === null) {
47
+			EEH_Autoloader::$_autoloaders = [];
48
+			$this->_register_custom_autoloaders();
49
+			spl_autoload_register([$this, 'espresso_autoloader']);
50
+		}
51
+	}
52
+
53
+
54
+	/**
55
+	 * @return EEH_Autoloader
56
+	 */
57
+	public static function instance(): EEH_Autoloader
58
+	{
59
+		// check if class object is instantiated
60
+		if (! EEH_Autoloader::$_instance instanceof EEH_Autoloader) {
61
+			EEH_Autoloader::$_instance = new EEH_Autoloader();
62
+		}
63
+		return EEH_Autoloader::$_instance;
64
+	}
65
+
66
+
67
+	/**
68
+	 * @param   $class_name
69
+	 * @return  void
70
+	 * @internal  param string $class_name - simple class name ie: session
71
+	 * @internal  param $className
72
+	 */
73
+	public static function espresso_autoloader($class_name)
74
+	{
75
+		if (isset(EEH_Autoloader::$_autoloaders[ $class_name ])) {
76
+			require_once(EEH_Autoloader::$_autoloaders[ $class_name ]);
77
+		}
78
+	}
79
+
80
+
81
+	/**
82
+	 * @param array | string $class_paths - array of key => value pairings between class names and paths
83
+	 * @param bool           $read_check  true if we need to check whether the file is readable or not.
84
+	 * @param bool           $debug       **deprecated**
85
+	 * @throws EE_Error
86
+	 */
87
+	public static function register_autoloader($class_paths, $read_check = true, $debug = false)
88
+	{
89
+		$class_paths = is_array($class_paths) ? $class_paths : [$class_paths];
90
+		foreach ($class_paths as $class => $path) {
91
+			// skip all files that are not PHP
92
+			if (substr($path, strlen($path) - 3) !== 'php') {
93
+				continue;
94
+			}
95
+			// don't give up! you gotta...
96
+			// get some class
97
+			if (empty($class)) {
98
+				throw new EE_Error(
99
+					sprintf(
100
+						esc_html__(
101
+							'No Class name was specified while registering an autoloader for the following path: %s.',
102
+							'event_espresso'
103
+						),
104
+						$path
105
+					)
106
+				);
107
+			}
108
+			// one day you will find the path young grasshopper
109
+			if (empty($path)) {
110
+				throw new EE_Error(
111
+					sprintf(
112
+						esc_html__('No path was specified while registering an autoloader for the %s class.', 'event_espresso'),
113
+						$class
114
+					)
115
+				);
116
+			}
117
+			// is file readable ?
118
+			if ($read_check && ! is_readable($path)) {
119
+				throw new EE_Error(
120
+					sprintf(
121
+						esc_html__(
122
+							'The file for the %s class could not be found or is not readable due to file permissions. Please ensure the following path is correct: %s',
123
+							'event_espresso'
124
+						),
125
+						$class,
126
+						$path
127
+					)
128
+				);
129
+			}
130
+			if (! isset(EEH_Autoloader::$_autoloaders[ $class ])) {
131
+				EEH_Autoloader::$_autoloaders[ $class ] = str_replace(['/', '\\'], '/', $path);
132
+				if (EE_DEBUG && (EEH_Autoloader::$debug === 'paths' || EEH_Autoloader::$debug === 'all' || $debug)) {
133
+					EEH_Debug_Tools::printr(EEH_Autoloader::$_autoloaders[ $class ], $class, __FILE__, __LINE__);
134
+				}
135
+			}
136
+		}
137
+	}
138
+
139
+
140
+	/**
141
+	 * @return array
142
+	 */
143
+	public static function get_autoloaders(): array
144
+	{
145
+		return EEH_Autoloader::$_autoloaders;
146
+	}
147
+
148
+
149
+	/**
150
+	 * @return void
151
+	 * @throws EE_Error
152
+	 */
153
+	private function _register_custom_autoloaders()
154
+	{
155
+		EEH_Autoloader::$debug = '';
156
+		EEH_Autoloader::register_helpers_autoloaders();
157
+		EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE . 'interfaces');
158
+		EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE);
159
+		EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_INTERFACES, true);
160
+		EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_MODELS, true);
161
+		EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CLASSES);
162
+		EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_FORM_SECTIONS, true);
163
+		EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'messages');
164
+		if (EEH_Autoloader::$debug === 'times' || EEH_Autoloader::$debug === 'all') {
165
+			Benchmark::displayResults();
166
+		}
167
+	}
168
+
169
+
170
+	/**
171
+	 * @throws EE_Error
172
+	 */
173
+	public static function register_helpers_autoloaders()
174
+	{
175
+		EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_HELPERS);
176
+	}
177
+
178
+
179
+	/**
180
+	 * @return void
181
+	 */
182
+	public static function register_form_sections_autoloaders()
183
+	{
184
+		// EEH_Autoloader::register_autoloaders_for_each_file_in_folder( EE_FORM_SECTIONS, true );
185
+	}
186
+
187
+
188
+	/**
189
+	 * @return void
190
+	 * @throws EE_Error
191
+	 */
192
+	public static function register_line_item_display_autoloaders()
193
+	{
194
+		EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'line_item_display', true);
195
+	}
196
+
197
+
198
+	/**
199
+	 * @return void
200
+	 * @throws EE_Error
201
+	 */
202
+	public static function register_line_item_filter_autoloaders()
203
+	{
204
+		EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'line_item_filters', true);
205
+	}
206
+
207
+
208
+	/**
209
+	 * @return void
210
+	 * @throws EE_Error
211
+	 */
212
+	public static function register_template_part_autoloaders()
213
+	{
214
+		EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'template_parts', true);
215
+	}
216
+
217
+
218
+	/**
219
+	 * @return void
220
+	 * @throws EE_Error
221
+	 */
222
+	public static function register_business_classes()
223
+	{
224
+		EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE . 'business');
225
+	}
226
+
227
+
228
+	/**
229
+	 * Assumes all the files in this folder have the normal naming scheme (namely that their classname
230
+	 * is the file's name, plus ".whatever.php".) and adds each of them to the autoloader list.
231
+	 * If that's not the case, you'll need to improve this function or just use
232
+	 * EEH_File::get_classname_from_filepath_with_standard_filename() directly. Yes this has to scan the directory for
233
+	 * files, but it only does it once -- not on EACH time the autoloader is used
234
+	 *
235
+	 * @param string $folder name, with or without trailing /, doesn't matter
236
+	 * @param bool   $recursive
237
+	 * @param bool   $debug  **deprecated**
238
+	 * @throws EE_Error
239
+	 */
240
+	public static function register_autoloaders_for_each_file_in_folder(
241
+		string $folder,
242
+		bool $recursive = false,
243
+		bool $debug = false
244
+	) {
245
+		if (EEH_Autoloader::$debug === 'times' || EEH_Autoloader::$debug === 'all' || $debug) {
246
+			Benchmark::startTimer(basename($folder));
247
+		}
248
+		// make sure last char is a /
249
+		$folder .= $folder[ strlen($folder) - 1 ] !== '/' ? '/' : '';
250
+		$class_to_filepath_map = [];
251
+		$exclude = ['index'];
252
+		// get all the files in that folder that end in php
253
+		$filepaths = glob($folder . '*');
254
+
255
+		if (empty($filepaths)) {
256
+			return;
257
+		}
258
+
259
+		foreach ($filepaths as $filepath) {
260
+			if (substr($filepath, -4, 4) === '.php') {
261
+				$class_name = EEH_File::get_classname_from_filepath_with_standard_filename($filepath);
262
+				if (! in_array($class_name, $exclude)) {
263
+					$class_to_filepath_map [ $class_name ] = $filepath;
264
+				}
265
+			} elseif ($recursive) {
266
+				EEH_Autoloader::register_autoloaders_for_each_file_in_folder($filepath, $recursive, $debug);
267
+			}
268
+		}
269
+		// we remove the necessity to do a is_readable() check via the $read_check flag because glob by nature will not return non_readable files/directories.
270
+		EEH_Autoloader::register_autoloader($class_to_filepath_map, false, $debug);
271
+		if (EEH_Autoloader::$debug === 'times' || EEH_Autoloader::$debug === 'all') {
272
+			Benchmark::stopTimer(basename($folder));
273
+		}
274
+	}
275
+
276
+
277
+	/**
278
+	 * register additional autoloader based on variation of the classname for an existing autoloader
279
+	 *
280
+	 * @param string $class_name - simple class name ie: EE_Session
281
+	 * @param string $alias      - variation on class name ie: EE_session, session, etc
282
+	 */
283
+	public static function add_alias(string $class_name, string $alias)
284
+	{
285
+		if (isset(EEH_Autoloader::$_autoloaders[ $class_name ])) {
286
+			EEH_Autoloader::$_autoloaders[ $alias ] = EEH_Autoloader::$_autoloaders[ $class_name ];
287
+		}
288
+	}
289 289
 }
Please login to merge, or discard this patch.
core/helpers/EEH_Form_Fields.helper.php 2 patches
Indentation   +1464 added lines, -1464 removed lines patch added patch discarded remove patch
@@ -29,1034 +29,1034 @@  discard block
 block discarded – undo
29 29
 {
30 30
 
31 31
 
32
-    /**
33
-     *  Generates HTML for the forms used on admin pages
34
-     *
35
-     *
36
-     *  @static
37
-     *  @access public
38
-     *  @param  array $input_vars - array of input field details
39
-     *  format:
40
-     *  $template_form_fields['field-id'] = array(
41
-     *      'name' => 'name_attribute',
42
-     *      'label' => __('Field Label', 'event_espresso'), //or false
43
-     *      'input' => 'hidden', //field input type can be 'text', 'select', 'textarea', 'hidden', 'checkbox', 'wp_editor'
44
-     *      'type' => 'int', //what "type" the value is (i.e. string, int etc)
45
-     *      'required' => false, //boolean for whether the field is required
46
-     *      'validation' => true, //boolean, whether to validate the field (todo)
47
-     *      'value' => 'some_value_for_field', //what value is used for field
48
-     *      'format' => '%d', //what format the value is (%d, %f, or %s)
49
-     *      'db-col' => 'column_in_db' //used to indicate which column the field corresponds with in the db
50
-     *      'options' => optiona, optionb || array('value' => 'label', '') //if the input type is "select", this allows you to set the args for the different <option> tags.
51
-     *      'tabindex' => 1 //this allows you to set the tabindex for the field.
52
-     *      'append_content' => '' //this allows you to send in html content to append to the field.
53
-     *  )
54
-     *  @param  array $id - used for defining unique identifiers for the form.
55
-     *  @return string
56
-     *  @todo: at some point we can break this down into other static methods to abstract it a bit better.
57
-     */
58
-    public static function get_form_fields($input_vars = array(), $id = false)
59
-    {
60
-
61
-        if (empty($input_vars)) {
62
-            EE_Error::add_error(__('missing required variables for the form field generator', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
63
-            return false;
64
-        }
65
-
66
-        // if you don't behave - this is what you're gonna get !!!
67
-        $close = true;
68
-        $output = '<ul>'; // this is for using built-in wp styles... watch carefully...
69
-
70
-        // cycle thru inputs
71
-        foreach ($input_vars as $input_key => $input_value) {
72
-            $defaults = array(
73
-                'name' => $input_key,
74
-                'label' => __('No label', 'event_espresso'),
75
-                'input' => 'hidden',
76
-                'type' => 'int',
77
-                'required' => false,
78
-                'validation' => true,
79
-                'value' => 'some_value_for_field',
80
-                'format' => '%d',
81
-                'db-col' => 'column_in_db',
82
-                'options' => array(),
83
-                'tabindex' => '',
84
-                'append_content' => ''
85
-                );
86
-
87
-            $input_value = wp_parse_args($input_value, $defaults);
88
-
89
-            // required fields get a *
90
-            $required = isset($input_value['required']) && $input_value['required'] ? ' <span>*</span>: ' : ': ';
91
-            // and the css class "required"
92
-            $css_class = isset($input_value['css_class']) ? $input_value['css_class'] : '';
93
-            $styles = $input_value['required'] ? 'required ' . $css_class : $css_class;
94
-
95
-            $field_id = ($id) ? $id . '-' . $input_key : $input_key;
96
-            $tabindex = !empty($input_value['tabindex']) ? ' tabindex="' . $input_value['tabindex'] . '"' : '';
97
-
98
-            // rows or cols?
99
-            $rows = isset($input_value['rows']) ? $input_value['rows'] : '10';
100
-            $cols = isset($input_value['cols']) ? $input_value['cols'] : '80';
101
-
102
-            // any content?
103
-            $append_content = $input_value['append_content'];
104
-
105
-            $output .= (!$close) ? '<ul>' : '';
106
-            $output .= '<li>';
107
-
108
-            // what type of input are we dealing with ?
109
-            switch ($input_value['input']) {
110
-                // text inputs
111
-                case 'text':
112
-                    $output .= "\n\t\t\t" . '<label for="' . $field_id . '">' . $input_value['label'] . $required . '</label>';
113
-                    $output .= "\n\t\t\t" . '<input id="' . $field_id . '" class="' . $styles . '" type="text" value="' . esc_textarea($input_value['value']) . '" name="' . $input_value['name'] . '"' . $tabindex . '>';
114
-                    break;
115
-
116
-                // dropdowns
117
-                case 'select':
118
-                    $output .= "\n\t\t\t" . '<label for="' . $field_id . '">' . $input_value['label'] . $required . '</label>';
119
-                    $output .= "\n\t\t\t" . '<select id="' . $field_id . '" class="' . $styles . '" name="' . $input_value['name'] . '"' . $tabindex . '>';
120
-
121
-                    if (is_array($input_value['options'])) {
122
-                        $options = $input_value['options'];
123
-                    } else {
124
-                        $options = explode(',', $input_value['options']);
125
-                    }
126
-
127
-                    foreach ($options as $key => $value) {
128
-                        $selected = isset($input_value['value']) && $input_value['value'] == $key ? 'selected=selected' : '';
129
-                        // $key = str_replace( ' ', '_', sanitize_key( $value ));
130
-                        $output .= "\n\t\t\t\t" . '<option ' . $selected . ' value="' . $key . '">' . $value . '</option>';
131
-                    }
132
-                    $output .= "\n\t\t\t" . '</select>';
133
-
134
-                    break;
135
-
136
-                case 'textarea':
137
-                    $output .= "\n\t\t\t" . '<label for="' . $field_id . '">' . $input_value['label'] . $required . '</label>';
138
-                    $output .= "\n\t\t\t" . '<textarea id="' . $field_id . '" class="' . $styles . '" rows="' . $rows . '" cols="' . $cols . '" name="' . $input_value['name'] . '"' . $tabindex . '>' . esc_textarea($input_value['value']) . '</textarea>';
139
-                    break;
140
-
141
-                case 'hidden':
142
-                    $close = false;
143
-                    $output .= "</li></ul>";
144
-                    $output .= "\n\t\t\t" . '<input id="' . $field_id . '" type="hidden" name="' . $input_value['name'] . '" value="' . $input_value['value'] . '">';
145
-                    break;
146
-
147
-                case 'checkbox':
148
-                    $checked = ( $input_value['value'] == 1 ) ? 'checked="checked"' : '';
149
-                    $output .= "\n\t\t\t" . '<label for="' . $field_id . '">' . $input_value['label'] . $required . '</label>';
150
-                    $output .= "\n\t\t\t" . '<input id="' . $field_id . '" type="checkbox" name="' . $input_value['name'] . '" value="1"' . $checked . $tabindex . ' />';
151
-                    break;
152
-
153
-                case 'wp_editor':
154
-                    $close = false;
155
-                    $editor_settings = array(
156
-                        'textarea_name' => $input_value['name'],
157
-                        'textarea_rows' => $rows,
158
-                        'editor_class' => $styles,
159
-                        'tabindex' => $input_value['tabindex']
160
-                    );
161
-                    $output .= '</li>';
162
-                    $output .= '</ul>';
163
-                    $output .= '<h4>' . $input_value['label'] . '</h4>';
164
-                    if ($append_content) {
165
-                        $output .= $append_content;
166
-                    }
167
-                    ob_start();
168
-                    wp_editor($input_value['value'], $field_id, $editor_settings);
169
-                    $editor = ob_get_contents();
170
-                    ob_end_clean();
171
-                    $output .= $editor;
172
-                    break;
173
-            }
174
-            if ($append_content && $input_value['input'] !== 'wp_editor') {
175
-                $output .= $append_content;
176
-            }
177
-                $output .= ($close) ? '</li>' : '';
178
-        } // end foreach( $input_vars as $input_key => $input_value )
179
-        $output .= ($close) ? '</ul>' : '';
180
-
181
-        return $output;
182
-    }
183
-
184
-    /**
185
-     * form_fields_array
186
-     * This utility function assembles form fields from a given structured array with field information.
187
-     * //TODO: This is an alternate generator that we may want to use instead.
188
-     *
189
-     * @param  array $fields structured array of fields to assemble in the following format:
190
-     * [field_name] => array(
191
-     *      ['label'] => 'label for field',
192
-     *      ['labels'] => array('label_1', 'label_2'); //optional - if the field type is a multi select type of field you can indicated the labels for each option via this index
193
-     *      ['extra_desc'] => 'extra description for the field', //optional
194
-     *      ['type'] => 'textarea'|'text'|'wp_editor'|'checkbox'|'radio'|'hidden'|'select', //defaults to text
195
-     *      ['value'] => 'value that goes in the field', //(if multi then this is an array of values and the 'default' paramater will be used for what is selected)
196
-     *      ['default'] => 'default if the field type is multi (i.e. select or radios or checkboxes)',
197
-     *      ['class'] => 'name-of-class(es)-for-input',
198
-     *      ['classes'] => array('class_1', 'class_2'); //optional - if the field type is a multi select type of field you can indicate the css class for each option via this index.
199
-     *      ['id'] => 'css-id-for-input') //defaults to 'field_name'
200
-     *      ['unique_id'] => 1 //defaults to empty string.  This is useful for when the fields generated are going to be used in a loop and you want to make sure that the field identifiers are unique from each other.
201
-     *      ['dimensions'] => array(100,300), //defaults to empty array.  This is used by field types such as textarea to indicate cols/rows.
202
-     *      ['tabindex'] => '' //this allows you to set the tabindex for the field.
203
-     *      ['wpeditor_args'] => array() //if the type of field is wpeditor then this can optionally contain an array of arguments for the editor setup.
204
-     *
205
-     * @return array         an array of inputs for form indexed by field name, and in the following structure:
206
-     *     [field_name] => array( 'label' => '{label_html}', 'field' => '{input_html}'
207
-     */
208
-    public static function get_form_fields_array($fields)
209
-    {
210
-
211
-        $form_fields = array();
212
-        $fields = (array) $fields;
213
-
214
-        foreach ($fields as $field_name => $field_atts) {
215
-            // defaults:
216
-            $defaults = array(
217
-                'label' => '',
218
-                'labels' => '',
219
-                'extra_desc' => '',
220
-                'type' => 'text',
221
-                'value' => '',
222
-                'default' => '',
223
-                'class' => '',
224
-                'classes' => '',
225
-                'id' => $field_name,
226
-                'unique_id' => '',
227
-                'dimensions' => array('10', '5'),
228
-                'tabindex' => '',
229
-                'wpeditor_args' => array()
230
-                );
231
-            // merge defaults with passed arguments
232
-            $_fields = wp_parse_args($field_atts, $defaults);
233
-            extract($_fields);
234
-            // generate label
235
-            $label = empty($label) ? '' : '<label for="' . $id . '">' . $label . '</label>';
236
-            // generate field name
237
-            $f_name = !empty($unique_id) ? $field_name . '[' . $unique_id . ']' : $field_name;
238
-
239
-            // tabindex
240
-            $tabindex_str = !empty($tabindex) ? ' tabindex="' . $tabindex . '"' : '';
241
-
242
-            // we determine what we're building based on the type
243
-            switch ($type) {
244
-                case 'textarea':
245
-                        $fld = '<textarea id="' . $id . '" class="' . $class . '" rows="' . $dimensions[1] . '" cols="' . $dimensions[0] . '" name="' . $f_name . '"' . $tabindex_str . '>' . $value . '</textarea>';
246
-                        $fld .= $extra_desc;
247
-                    break;
248
-
249
-                case 'checkbox':
250
-                        $c_input = '';
251
-                    if (is_array($value)) {
252
-                        foreach ($value as $key => $val) {
253
-                            $c_id = $field_name . '_' . $value;
254
-                            $c_class = isset($classes[ $key ]) ? ' class="' . $classes[ $key ] . '" ' : '';
255
-                            $c_label = isset($labels[ $key ]) ? '<label for="' . $c_id . '">' . $labels[ $key ] . '</label>' : '';
256
-                            $checked = !empty($default) && $default == $val ? ' checked="checked" ' : '';
257
-                            $c_input .= '<input name="' . $f_name . '[]" type="checkbox" id="' . $c_id . '"' . $c_class . 'value="' . $val . '"' . $checked . $tabindex_str . ' />' . "\n" . $c_label;
258
-                        }
259
-                        $fld = $c_input;
260
-                    } else {
261
-                        $checked = !empty($default) && $default == $val ? 'checked="checked" ' : '';
262
-                        $fld = '<input name="' . $f_name . '" type="checkbox" id="' . $id . '" class="' . $class . '" value="' . $value . '"' . $checked . $tabindex_str . ' />' . "\n";
263
-                    }
264
-                    break;
265
-
266
-                case 'radio':
267
-                        $c_input = '';
268
-                    if (is_array($value)) {
269
-                        foreach ($value as $key => $val) {
270
-                            $c_id = $field_name . '_' . $value;
271
-                            $c_class = isset($classes[ $key ]) ? 'class="' . $classes[ $key ] . '" ' : '';
272
-                            $c_label = isset($labels[ $key ]) ? '<label for="' . $c_id . '">' . $labels[ $key ] . '</label>' : '';
273
-                            $checked = !empty($default) && $default == $val ? ' checked="checked" ' : '';
274
-                            $c_input .= '<input name="' . $f_name . '" type="checkbox" id="' . $c_id . '"' . $c_class . 'value="' . $val . '"' . $checked . $tabindex_str . ' />' . "\n" . $c_label;
275
-                        }
276
-                        $fld = $c_input;
277
-                    } else {
278
-                        $checked = !empty($default) && $default == $val ? 'checked="checked" ' : '';
279
-                        $fld = '<input name="' . $f_name . '" type="checkbox" id="' . $id . '" class="' . $class . '" value="' . $value . '"' . $checked . $tabindex_str . ' />' . "\n";
280
-                    }
281
-                    break;
282
-
283
-                case 'hidden':
284
-                        $fld = '<input name="' . $f_name . '" type="hidden" id="' . $id . '" class="' . $class . '" value="' . $value . '" />' . "\n";
285
-                    break;
286
-
287
-                case 'select':
288
-                        $fld = '<select name="' . $f_name . '" class="' . $class . '" id="' . $id . '"' . $tabindex_str . '>' . "\n";
289
-                    foreach ($value as $key => $val) {
290
-                        $checked = !empty($default) && $default == $val ? ' selected="selected"' : '';
291
-                        $fld .= "\t" . '<option value="' . $val . '"' . $checked . '>' . $labels[ $key ] . '</option>' . "\n";
292
-                    }
293
-                        $fld .= '</select>';
294
-                    break;
295
-
296
-                case 'wp_editor':
297
-                        $editor_settings = array(
298
-                            'textarea_name' => $f_name,
299
-                            'textarea_rows' => $dimensions[1],
300
-                            'editor_class' => $class,
301
-                            'tabindex' => $tabindex
302
-                            );
303
-                        $editor_settings = array_merge($wpeditor_args, $editor_settings);
304
-                        ob_start();
305
-                        wp_editor($value, $id, $editor_settings);
306
-                        $editor = ob_get_contents();
307
-                        ob_end_clean();
308
-                        $fld = $editor;
309
-                    break;
310
-
311
-                default: // 'text fields'
312
-                        $fld = '<input name="' . $f_name . '" type="text" id="' . $id . '" class="' . $class . '" value="' . $value . '"' . $tabindex_str . ' />' . "\n";
313
-                        $fld .= $extra_desc;
314
-            }
315
-
316
-            $form_fields[ $field_name ] = array( 'label' => $label, 'field' => $fld );
317
-        }
318
-
319
-        return $form_fields;
320
-    }
321
-
322
-
323
-
324
-
325
-
326
-
327
-    /**
328
-     * espresso admin page select_input
329
-     * Turns an array into a select fields
330
-     *
331
-     * @static
332
-     * @access public
333
-     * @param  string  $name       field name
334
-     * @param  array  $values     option values, numbered array starting at 0, where each value is an array with a key 'text' (meaning text to display' and 'id' (meaning the internal value)
335
-     * eg: array(1=>array('text'=>'Monday','id'=>1),2=>array('text'=>'Tuesday','id'=>2)...). or as an array of key-value pairs, where the key is to be used for the
336
-     * select input's name, and the value will be the text shown to the user.  Optionally you can also include an additional key of "class" which will add a specific class to the option for that value.
337
-     * @param  string  $default    default value
338
-     * @param  string  $parameters extra paramaters
339
-     * @param  string  $class      css class
340
-     * @param  boolean $autosize   whether to autosize the select or not
341
-     * @return string              html string for the select input
342
-     */
343
-    public static function select_input($name, $values, $default = '', $parameters = '', $class = '', $autosize = true)
344
-    {
345
-        // if $values was submitted in the wrong format, convert it over
346
-        if (!empty($values) && (!array_key_exists(0, $values) || !is_array($values[0]))) {
347
-            $converted_values = array();
348
-            foreach ($values as $id => $text) {
349
-                $converted_values[] = array('id' => $id,'text' => $text);
350
-            }
351
-            $values = $converted_values;
352
-        }
353
-
354
-        $field = '<select id="' . EEH_Formatter::ee_tep_output_string($name) . '" name="' . EEH_Formatter::ee_tep_output_string($name) . '"';
355
-        // Debug
356
-        // EEH_Debug_Tools::printr( $values, '$values  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' );
357
-        if (EEH_Formatter::ee_tep_not_null($parameters)) {
358
-            $field .= ' ' . $parameters;
359
-        }
360
-        if ($autosize) {
361
-            $size = 'med';
362
-            for ($ii = 0, $ni = sizeof($values); $ii < $ni; $ii++) {
363
-                if ($values[ $ii ]['text']) {
364
-                    if (strlen($values[ $ii ]['text']) > 5) {
365
-                        $size = 'wide';
366
-                    }
367
-                }
368
-            }
369
-        } else {
370
-            $size = '';
371
-        }
372
-
373
-        $field .= ' class="' . $class . ' ' . $size . '">';
374
-
375
-        if (empty($default) && isset($GLOBALS[ $name ])) {
376
-            $default = stripslashes($GLOBALS[ $name ]);
377
-        }
378
-
379
-
380
-        for ($i = 0, $n = sizeof($values); $i < $n; $i++) {
381
-            $field .= '<option value="' . $values[ $i ]['id'] . '"';
382
-            if ($default == $values[ $i ]['id']) {
383
-                $field .= ' selected = "selected"';
384
-            }
385
-            if (isset($values[ $i ]['class'])) {
386
-                $field .= ' class="' . $values[ $i ]['class'] . '"';
387
-            }
388
-            $field .= '>' . $values[ $i ]['text'] . '</option>';
389
-        }
390
-        $field .= '</select>';
391
-
392
-        return $field;
393
-    }
394
-
395
-
396
-
397
-
398
-
399
-
400
-    /**
401
-     * generate_question_groups_html
402
-     *
403
-     * @param string $question_groups
404
-     * @return string HTML
405
-     */
406
-    public static function generate_question_groups_html($question_groups = array(), $group_wrapper = 'fieldset')
407
-    {
408
-
409
-        $html = '';
410
-        $before_question_group_questions = apply_filters('FHEE__EEH_Form_Fields__generate_question_groups_html__before_question_group_questions', '');
411
-        $after_question_group_questions = apply_filters('FHEE__EEH_Form_Fields__generate_question_groups_html__after_question_group_questions', '');
412
-
413
-        if (! empty($question_groups)) {
414
-            // EEH_Debug_Tools::printr( $question_groups, '$question_groups  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' );
415
-            // loop thru question groups
416
-            foreach ($question_groups as $QSG) {
417
-                // check that questions exist
418
-                if (! empty($QSG['QSG_questions'])) {
419
-                    // use fieldsets
420
-                    $html .= "\n\t" . '<' . $group_wrapper . ' class="espresso-question-group-wrap" id="' . $QSG['QSG_identifier'] . '">';
421
-                    // group_name
422
-                    $html .= $QSG['QSG_show_group_name'] ? "\n\t\t" . '<h5 class="espresso-question-group-title-h5 section-title">' . self::prep_answer($QSG['QSG_name']) . '</h5>' : '';
423
-                    // group_desc
424
-                    $html .= $QSG['QSG_show_group_desc'] && ! empty($QSG['QSG_desc']) ? '<div class="espresso-question-group-desc-pg">' . self::prep_answer($QSG['QSG_desc']) . '</div>' : '';
425
-
426
-                    $html .= $before_question_group_questions;
427
-                    // loop thru questions
428
-                    foreach ($QSG['QSG_questions'] as $question) {
32
+	/**
33
+	 *  Generates HTML for the forms used on admin pages
34
+	 *
35
+	 *
36
+	 *  @static
37
+	 *  @access public
38
+	 *  @param  array $input_vars - array of input field details
39
+	 *  format:
40
+	 *  $template_form_fields['field-id'] = array(
41
+	 *      'name' => 'name_attribute',
42
+	 *      'label' => __('Field Label', 'event_espresso'), //or false
43
+	 *      'input' => 'hidden', //field input type can be 'text', 'select', 'textarea', 'hidden', 'checkbox', 'wp_editor'
44
+	 *      'type' => 'int', //what "type" the value is (i.e. string, int etc)
45
+	 *      'required' => false, //boolean for whether the field is required
46
+	 *      'validation' => true, //boolean, whether to validate the field (todo)
47
+	 *      'value' => 'some_value_for_field', //what value is used for field
48
+	 *      'format' => '%d', //what format the value is (%d, %f, or %s)
49
+	 *      'db-col' => 'column_in_db' //used to indicate which column the field corresponds with in the db
50
+	 *      'options' => optiona, optionb || array('value' => 'label', '') //if the input type is "select", this allows you to set the args for the different <option> tags.
51
+	 *      'tabindex' => 1 //this allows you to set the tabindex for the field.
52
+	 *      'append_content' => '' //this allows you to send in html content to append to the field.
53
+	 *  )
54
+	 *  @param  array $id - used for defining unique identifiers for the form.
55
+	 *  @return string
56
+	 *  @todo: at some point we can break this down into other static methods to abstract it a bit better.
57
+	 */
58
+	public static function get_form_fields($input_vars = array(), $id = false)
59
+	{
60
+
61
+		if (empty($input_vars)) {
62
+			EE_Error::add_error(__('missing required variables for the form field generator', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
63
+			return false;
64
+		}
65
+
66
+		// if you don't behave - this is what you're gonna get !!!
67
+		$close = true;
68
+		$output = '<ul>'; // this is for using built-in wp styles... watch carefully...
69
+
70
+		// cycle thru inputs
71
+		foreach ($input_vars as $input_key => $input_value) {
72
+			$defaults = array(
73
+				'name' => $input_key,
74
+				'label' => __('No label', 'event_espresso'),
75
+				'input' => 'hidden',
76
+				'type' => 'int',
77
+				'required' => false,
78
+				'validation' => true,
79
+				'value' => 'some_value_for_field',
80
+				'format' => '%d',
81
+				'db-col' => 'column_in_db',
82
+				'options' => array(),
83
+				'tabindex' => '',
84
+				'append_content' => ''
85
+				);
86
+
87
+			$input_value = wp_parse_args($input_value, $defaults);
88
+
89
+			// required fields get a *
90
+			$required = isset($input_value['required']) && $input_value['required'] ? ' <span>*</span>: ' : ': ';
91
+			// and the css class "required"
92
+			$css_class = isset($input_value['css_class']) ? $input_value['css_class'] : '';
93
+			$styles = $input_value['required'] ? 'required ' . $css_class : $css_class;
94
+
95
+			$field_id = ($id) ? $id . '-' . $input_key : $input_key;
96
+			$tabindex = !empty($input_value['tabindex']) ? ' tabindex="' . $input_value['tabindex'] . '"' : '';
97
+
98
+			// rows or cols?
99
+			$rows = isset($input_value['rows']) ? $input_value['rows'] : '10';
100
+			$cols = isset($input_value['cols']) ? $input_value['cols'] : '80';
101
+
102
+			// any content?
103
+			$append_content = $input_value['append_content'];
104
+
105
+			$output .= (!$close) ? '<ul>' : '';
106
+			$output .= '<li>';
107
+
108
+			// what type of input are we dealing with ?
109
+			switch ($input_value['input']) {
110
+				// text inputs
111
+				case 'text':
112
+					$output .= "\n\t\t\t" . '<label for="' . $field_id . '">' . $input_value['label'] . $required . '</label>';
113
+					$output .= "\n\t\t\t" . '<input id="' . $field_id . '" class="' . $styles . '" type="text" value="' . esc_textarea($input_value['value']) . '" name="' . $input_value['name'] . '"' . $tabindex . '>';
114
+					break;
115
+
116
+				// dropdowns
117
+				case 'select':
118
+					$output .= "\n\t\t\t" . '<label for="' . $field_id . '">' . $input_value['label'] . $required . '</label>';
119
+					$output .= "\n\t\t\t" . '<select id="' . $field_id . '" class="' . $styles . '" name="' . $input_value['name'] . '"' . $tabindex . '>';
120
+
121
+					if (is_array($input_value['options'])) {
122
+						$options = $input_value['options'];
123
+					} else {
124
+						$options = explode(',', $input_value['options']);
125
+					}
126
+
127
+					foreach ($options as $key => $value) {
128
+						$selected = isset($input_value['value']) && $input_value['value'] == $key ? 'selected=selected' : '';
129
+						// $key = str_replace( ' ', '_', sanitize_key( $value ));
130
+						$output .= "\n\t\t\t\t" . '<option ' . $selected . ' value="' . $key . '">' . $value . '</option>';
131
+					}
132
+					$output .= "\n\t\t\t" . '</select>';
133
+
134
+					break;
135
+
136
+				case 'textarea':
137
+					$output .= "\n\t\t\t" . '<label for="' . $field_id . '">' . $input_value['label'] . $required . '</label>';
138
+					$output .= "\n\t\t\t" . '<textarea id="' . $field_id . '" class="' . $styles . '" rows="' . $rows . '" cols="' . $cols . '" name="' . $input_value['name'] . '"' . $tabindex . '>' . esc_textarea($input_value['value']) . '</textarea>';
139
+					break;
140
+
141
+				case 'hidden':
142
+					$close = false;
143
+					$output .= "</li></ul>";
144
+					$output .= "\n\t\t\t" . '<input id="' . $field_id . '" type="hidden" name="' . $input_value['name'] . '" value="' . $input_value['value'] . '">';
145
+					break;
146
+
147
+				case 'checkbox':
148
+					$checked = ( $input_value['value'] == 1 ) ? 'checked="checked"' : '';
149
+					$output .= "\n\t\t\t" . '<label for="' . $field_id . '">' . $input_value['label'] . $required . '</label>';
150
+					$output .= "\n\t\t\t" . '<input id="' . $field_id . '" type="checkbox" name="' . $input_value['name'] . '" value="1"' . $checked . $tabindex . ' />';
151
+					break;
152
+
153
+				case 'wp_editor':
154
+					$close = false;
155
+					$editor_settings = array(
156
+						'textarea_name' => $input_value['name'],
157
+						'textarea_rows' => $rows,
158
+						'editor_class' => $styles,
159
+						'tabindex' => $input_value['tabindex']
160
+					);
161
+					$output .= '</li>';
162
+					$output .= '</ul>';
163
+					$output .= '<h4>' . $input_value['label'] . '</h4>';
164
+					if ($append_content) {
165
+						$output .= $append_content;
166
+					}
167
+					ob_start();
168
+					wp_editor($input_value['value'], $field_id, $editor_settings);
169
+					$editor = ob_get_contents();
170
+					ob_end_clean();
171
+					$output .= $editor;
172
+					break;
173
+			}
174
+			if ($append_content && $input_value['input'] !== 'wp_editor') {
175
+				$output .= $append_content;
176
+			}
177
+				$output .= ($close) ? '</li>' : '';
178
+		} // end foreach( $input_vars as $input_key => $input_value )
179
+		$output .= ($close) ? '</ul>' : '';
180
+
181
+		return $output;
182
+	}
183
+
184
+	/**
185
+	 * form_fields_array
186
+	 * This utility function assembles form fields from a given structured array with field information.
187
+	 * //TODO: This is an alternate generator that we may want to use instead.
188
+	 *
189
+	 * @param  array $fields structured array of fields to assemble in the following format:
190
+	 * [field_name] => array(
191
+	 *      ['label'] => 'label for field',
192
+	 *      ['labels'] => array('label_1', 'label_2'); //optional - if the field type is a multi select type of field you can indicated the labels for each option via this index
193
+	 *      ['extra_desc'] => 'extra description for the field', //optional
194
+	 *      ['type'] => 'textarea'|'text'|'wp_editor'|'checkbox'|'radio'|'hidden'|'select', //defaults to text
195
+	 *      ['value'] => 'value that goes in the field', //(if multi then this is an array of values and the 'default' paramater will be used for what is selected)
196
+	 *      ['default'] => 'default if the field type is multi (i.e. select or radios or checkboxes)',
197
+	 *      ['class'] => 'name-of-class(es)-for-input',
198
+	 *      ['classes'] => array('class_1', 'class_2'); //optional - if the field type is a multi select type of field you can indicate the css class for each option via this index.
199
+	 *      ['id'] => 'css-id-for-input') //defaults to 'field_name'
200
+	 *      ['unique_id'] => 1 //defaults to empty string.  This is useful for when the fields generated are going to be used in a loop and you want to make sure that the field identifiers are unique from each other.
201
+	 *      ['dimensions'] => array(100,300), //defaults to empty array.  This is used by field types such as textarea to indicate cols/rows.
202
+	 *      ['tabindex'] => '' //this allows you to set the tabindex for the field.
203
+	 *      ['wpeditor_args'] => array() //if the type of field is wpeditor then this can optionally contain an array of arguments for the editor setup.
204
+	 *
205
+	 * @return array         an array of inputs for form indexed by field name, and in the following structure:
206
+	 *     [field_name] => array( 'label' => '{label_html}', 'field' => '{input_html}'
207
+	 */
208
+	public static function get_form_fields_array($fields)
209
+	{
210
+
211
+		$form_fields = array();
212
+		$fields = (array) $fields;
213
+
214
+		foreach ($fields as $field_name => $field_atts) {
215
+			// defaults:
216
+			$defaults = array(
217
+				'label' => '',
218
+				'labels' => '',
219
+				'extra_desc' => '',
220
+				'type' => 'text',
221
+				'value' => '',
222
+				'default' => '',
223
+				'class' => '',
224
+				'classes' => '',
225
+				'id' => $field_name,
226
+				'unique_id' => '',
227
+				'dimensions' => array('10', '5'),
228
+				'tabindex' => '',
229
+				'wpeditor_args' => array()
230
+				);
231
+			// merge defaults with passed arguments
232
+			$_fields = wp_parse_args($field_atts, $defaults);
233
+			extract($_fields);
234
+			// generate label
235
+			$label = empty($label) ? '' : '<label for="' . $id . '">' . $label . '</label>';
236
+			// generate field name
237
+			$f_name = !empty($unique_id) ? $field_name . '[' . $unique_id . ']' : $field_name;
238
+
239
+			// tabindex
240
+			$tabindex_str = !empty($tabindex) ? ' tabindex="' . $tabindex . '"' : '';
241
+
242
+			// we determine what we're building based on the type
243
+			switch ($type) {
244
+				case 'textarea':
245
+						$fld = '<textarea id="' . $id . '" class="' . $class . '" rows="' . $dimensions[1] . '" cols="' . $dimensions[0] . '" name="' . $f_name . '"' . $tabindex_str . '>' . $value . '</textarea>';
246
+						$fld .= $extra_desc;
247
+					break;
248
+
249
+				case 'checkbox':
250
+						$c_input = '';
251
+					if (is_array($value)) {
252
+						foreach ($value as $key => $val) {
253
+							$c_id = $field_name . '_' . $value;
254
+							$c_class = isset($classes[ $key ]) ? ' class="' . $classes[ $key ] . '" ' : '';
255
+							$c_label = isset($labels[ $key ]) ? '<label for="' . $c_id . '">' . $labels[ $key ] . '</label>' : '';
256
+							$checked = !empty($default) && $default == $val ? ' checked="checked" ' : '';
257
+							$c_input .= '<input name="' . $f_name . '[]" type="checkbox" id="' . $c_id . '"' . $c_class . 'value="' . $val . '"' . $checked . $tabindex_str . ' />' . "\n" . $c_label;
258
+						}
259
+						$fld = $c_input;
260
+					} else {
261
+						$checked = !empty($default) && $default == $val ? 'checked="checked" ' : '';
262
+						$fld = '<input name="' . $f_name . '" type="checkbox" id="' . $id . '" class="' . $class . '" value="' . $value . '"' . $checked . $tabindex_str . ' />' . "\n";
263
+					}
264
+					break;
265
+
266
+				case 'radio':
267
+						$c_input = '';
268
+					if (is_array($value)) {
269
+						foreach ($value as $key => $val) {
270
+							$c_id = $field_name . '_' . $value;
271
+							$c_class = isset($classes[ $key ]) ? 'class="' . $classes[ $key ] . '" ' : '';
272
+							$c_label = isset($labels[ $key ]) ? '<label for="' . $c_id . '">' . $labels[ $key ] . '</label>' : '';
273
+							$checked = !empty($default) && $default == $val ? ' checked="checked" ' : '';
274
+							$c_input .= '<input name="' . $f_name . '" type="checkbox" id="' . $c_id . '"' . $c_class . 'value="' . $val . '"' . $checked . $tabindex_str . ' />' . "\n" . $c_label;
275
+						}
276
+						$fld = $c_input;
277
+					} else {
278
+						$checked = !empty($default) && $default == $val ? 'checked="checked" ' : '';
279
+						$fld = '<input name="' . $f_name . '" type="checkbox" id="' . $id . '" class="' . $class . '" value="' . $value . '"' . $checked . $tabindex_str . ' />' . "\n";
280
+					}
281
+					break;
282
+
283
+				case 'hidden':
284
+						$fld = '<input name="' . $f_name . '" type="hidden" id="' . $id . '" class="' . $class . '" value="' . $value . '" />' . "\n";
285
+					break;
286
+
287
+				case 'select':
288
+						$fld = '<select name="' . $f_name . '" class="' . $class . '" id="' . $id . '"' . $tabindex_str . '>' . "\n";
289
+					foreach ($value as $key => $val) {
290
+						$checked = !empty($default) && $default == $val ? ' selected="selected"' : '';
291
+						$fld .= "\t" . '<option value="' . $val . '"' . $checked . '>' . $labels[ $key ] . '</option>' . "\n";
292
+					}
293
+						$fld .= '</select>';
294
+					break;
295
+
296
+				case 'wp_editor':
297
+						$editor_settings = array(
298
+							'textarea_name' => $f_name,
299
+							'textarea_rows' => $dimensions[1],
300
+							'editor_class' => $class,
301
+							'tabindex' => $tabindex
302
+							);
303
+						$editor_settings = array_merge($wpeditor_args, $editor_settings);
304
+						ob_start();
305
+						wp_editor($value, $id, $editor_settings);
306
+						$editor = ob_get_contents();
307
+						ob_end_clean();
308
+						$fld = $editor;
309
+					break;
310
+
311
+				default: // 'text fields'
312
+						$fld = '<input name="' . $f_name . '" type="text" id="' . $id . '" class="' . $class . '" value="' . $value . '"' . $tabindex_str . ' />' . "\n";
313
+						$fld .= $extra_desc;
314
+			}
315
+
316
+			$form_fields[ $field_name ] = array( 'label' => $label, 'field' => $fld );
317
+		}
318
+
319
+		return $form_fields;
320
+	}
321
+
322
+
323
+
324
+
325
+
326
+
327
+	/**
328
+	 * espresso admin page select_input
329
+	 * Turns an array into a select fields
330
+	 *
331
+	 * @static
332
+	 * @access public
333
+	 * @param  string  $name       field name
334
+	 * @param  array  $values     option values, numbered array starting at 0, where each value is an array with a key 'text' (meaning text to display' and 'id' (meaning the internal value)
335
+	 * eg: array(1=>array('text'=>'Monday','id'=>1),2=>array('text'=>'Tuesday','id'=>2)...). or as an array of key-value pairs, where the key is to be used for the
336
+	 * select input's name, and the value will be the text shown to the user.  Optionally you can also include an additional key of "class" which will add a specific class to the option for that value.
337
+	 * @param  string  $default    default value
338
+	 * @param  string  $parameters extra paramaters
339
+	 * @param  string  $class      css class
340
+	 * @param  boolean $autosize   whether to autosize the select or not
341
+	 * @return string              html string for the select input
342
+	 */
343
+	public static function select_input($name, $values, $default = '', $parameters = '', $class = '', $autosize = true)
344
+	{
345
+		// if $values was submitted in the wrong format, convert it over
346
+		if (!empty($values) && (!array_key_exists(0, $values) || !is_array($values[0]))) {
347
+			$converted_values = array();
348
+			foreach ($values as $id => $text) {
349
+				$converted_values[] = array('id' => $id,'text' => $text);
350
+			}
351
+			$values = $converted_values;
352
+		}
353
+
354
+		$field = '<select id="' . EEH_Formatter::ee_tep_output_string($name) . '" name="' . EEH_Formatter::ee_tep_output_string($name) . '"';
355
+		// Debug
356
+		// EEH_Debug_Tools::printr( $values, '$values  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' );
357
+		if (EEH_Formatter::ee_tep_not_null($parameters)) {
358
+			$field .= ' ' . $parameters;
359
+		}
360
+		if ($autosize) {
361
+			$size = 'med';
362
+			for ($ii = 0, $ni = sizeof($values); $ii < $ni; $ii++) {
363
+				if ($values[ $ii ]['text']) {
364
+					if (strlen($values[ $ii ]['text']) > 5) {
365
+						$size = 'wide';
366
+					}
367
+				}
368
+			}
369
+		} else {
370
+			$size = '';
371
+		}
372
+
373
+		$field .= ' class="' . $class . ' ' . $size . '">';
374
+
375
+		if (empty($default) && isset($GLOBALS[ $name ])) {
376
+			$default = stripslashes($GLOBALS[ $name ]);
377
+		}
378
+
379
+
380
+		for ($i = 0, $n = sizeof($values); $i < $n; $i++) {
381
+			$field .= '<option value="' . $values[ $i ]['id'] . '"';
382
+			if ($default == $values[ $i ]['id']) {
383
+				$field .= ' selected = "selected"';
384
+			}
385
+			if (isset($values[ $i ]['class'])) {
386
+				$field .= ' class="' . $values[ $i ]['class'] . '"';
387
+			}
388
+			$field .= '>' . $values[ $i ]['text'] . '</option>';
389
+		}
390
+		$field .= '</select>';
391
+
392
+		return $field;
393
+	}
394
+
395
+
396
+
397
+
398
+
399
+
400
+	/**
401
+	 * generate_question_groups_html
402
+	 *
403
+	 * @param string $question_groups
404
+	 * @return string HTML
405
+	 */
406
+	public static function generate_question_groups_html($question_groups = array(), $group_wrapper = 'fieldset')
407
+	{
408
+
409
+		$html = '';
410
+		$before_question_group_questions = apply_filters('FHEE__EEH_Form_Fields__generate_question_groups_html__before_question_group_questions', '');
411
+		$after_question_group_questions = apply_filters('FHEE__EEH_Form_Fields__generate_question_groups_html__after_question_group_questions', '');
412
+
413
+		if (! empty($question_groups)) {
414
+			// EEH_Debug_Tools::printr( $question_groups, '$question_groups  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' );
415
+			// loop thru question groups
416
+			foreach ($question_groups as $QSG) {
417
+				// check that questions exist
418
+				if (! empty($QSG['QSG_questions'])) {
419
+					// use fieldsets
420
+					$html .= "\n\t" . '<' . $group_wrapper . ' class="espresso-question-group-wrap" id="' . $QSG['QSG_identifier'] . '">';
421
+					// group_name
422
+					$html .= $QSG['QSG_show_group_name'] ? "\n\t\t" . '<h5 class="espresso-question-group-title-h5 section-title">' . self::prep_answer($QSG['QSG_name']) . '</h5>' : '';
423
+					// group_desc
424
+					$html .= $QSG['QSG_show_group_desc'] && ! empty($QSG['QSG_desc']) ? '<div class="espresso-question-group-desc-pg">' . self::prep_answer($QSG['QSG_desc']) . '</div>' : '';
425
+
426
+					$html .= $before_question_group_questions;
427
+					// loop thru questions
428
+					foreach ($QSG['QSG_questions'] as $question) {
429 429
 //                      EEH_Debug_Tools::printr( $question, '$question  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' );
430
-                        $QFI = new EE_Question_Form_Input(
431
-                            $question['qst_obj'],
432
-                            $question['ans_obj'],
433
-                            $question
434
-                        );
435
-                        $html .= self::generate_form_input($QFI);
436
-                    }
437
-                    $html .= $after_question_group_questions;
438
-                    $html .= "\n\t" . '</' . $group_wrapper . '>';
439
-                }
440
-            }
441
-        }
442
-
443
-        return $html;
444
-    }
445
-
446
-
447
-
448
-    /**
449
-     * generate_question_groups_html
450
-     *
451
-     * @param array         $question_groups
452
-     * @param array        $q_meta
453
-     * @param bool         $from_admin
454
-     * @param string       $group_wrapper
455
-     * @return string HTML
456
-     */
457
-    public static function generate_question_groups_html2($question_groups = array(), $q_meta = array(), $from_admin = false, $group_wrapper = 'fieldset')
458
-    {
459
-
460
-        $html = '';
461
-        $before_question_group_questions = apply_filters('FHEE__EEH_Form_Fields__generate_question_groups_html__before_question_group_questions', '');
462
-        $after_question_group_questions = apply_filters('FHEE__EEH_Form_Fields__generate_question_groups_html__after_question_group_questions', '');
463
-
464
-        $default_q_meta = array(
465
-                'att_nmbr' => 1,
466
-                'ticket_id' => '',
467
-                'input_name' => '',
468
-                'input_id' => '',
469
-                'input_class' => ''
470
-        );
471
-        $q_meta = array_merge($default_q_meta, $q_meta);
472
-        // EEH_Debug_Tools::printr( $q_meta, '$q_meta  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' );
473
-
474
-        if (! empty($question_groups)) {
430
+						$QFI = new EE_Question_Form_Input(
431
+							$question['qst_obj'],
432
+							$question['ans_obj'],
433
+							$question
434
+						);
435
+						$html .= self::generate_form_input($QFI);
436
+					}
437
+					$html .= $after_question_group_questions;
438
+					$html .= "\n\t" . '</' . $group_wrapper . '>';
439
+				}
440
+			}
441
+		}
442
+
443
+		return $html;
444
+	}
445
+
446
+
447
+
448
+	/**
449
+	 * generate_question_groups_html
450
+	 *
451
+	 * @param array         $question_groups
452
+	 * @param array        $q_meta
453
+	 * @param bool         $from_admin
454
+	 * @param string       $group_wrapper
455
+	 * @return string HTML
456
+	 */
457
+	public static function generate_question_groups_html2($question_groups = array(), $q_meta = array(), $from_admin = false, $group_wrapper = 'fieldset')
458
+	{
459
+
460
+		$html = '';
461
+		$before_question_group_questions = apply_filters('FHEE__EEH_Form_Fields__generate_question_groups_html__before_question_group_questions', '');
462
+		$after_question_group_questions = apply_filters('FHEE__EEH_Form_Fields__generate_question_groups_html__after_question_group_questions', '');
463
+
464
+		$default_q_meta = array(
465
+				'att_nmbr' => 1,
466
+				'ticket_id' => '',
467
+				'input_name' => '',
468
+				'input_id' => '',
469
+				'input_class' => ''
470
+		);
471
+		$q_meta = array_merge($default_q_meta, $q_meta);
472
+		// EEH_Debug_Tools::printr( $q_meta, '$q_meta  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' );
473
+
474
+		if (! empty($question_groups)) {
475 475
 //          EEH_Debug_Tools::printr( $question_groups, '$question_groups  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' );
476
-            // loop thru question groups
477
-            foreach ($question_groups as $QSG) {
478
-                if ($QSG instanceof EE_Question_Group) {
479
-                    // check that questions exist
480
-
481
-                    $where = array( 'QST_deleted' => 0 );
482
-                    if (! $from_admin) {
483
-                        $where['QST_admin_only'] = 0;
484
-                    }
485
-                    $questions = $QSG->questions(array( $where, 'order_by' => array( 'Question_Group_Question.QGQ_order' => 'ASC' )));
486
-                    if (! empty($questions)) {
487
-                        // use fieldsets
488
-                        $html .= "\n\t" . '<' . $group_wrapper . ' class="espresso-question-group-wrap" id="' . $QSG->get('QSG_identifier') . '">';
489
-                        // group_name
490
-                        if ($QSG->show_group_name()) {
491
-                            $html .=  "\n\t\t" . '<h5 class="espresso-question-group-title-h5 section-title">' . $QSG->get_pretty('QSG_name') . '</h5>';
492
-                        }
493
-                        // group_desc
494
-                        if ($QSG->show_group_desc()) {
495
-                            $html .=  '<div class="espresso-question-group-desc-pg">' . $QSG->get_pretty('QSG_desc') . '</div>';
496
-                        }
497
-
498
-                        $html .= $before_question_group_questions;
499
-                        // loop thru questions
500
-                        foreach ($questions as $QST) {
501
-                            $qstn_id = $QST->is_system_question() ? $QST->system_ID() : $QST->ID();
502
-
503
-                            $answer = null;
504
-
505
-                            if (isset($_GET['qstn']) && isset($q_meta['input_id']) && isset($q_meta['att_nmbr'])) {
506
-                                // check for answer in $_GET in case we are reprocessing a form after an error
507
-                                if (isset($_GET['qstn'][ $q_meta['input_id'] ][ $qstn_id ])) {
508
-                                    $answer = is_array($_GET['qstn'][ $q_meta['input_id'] ][ $qstn_id ]) ? $_GET['qstn'][ $q_meta['input_id'] ][ $qstn_id ] : sanitize_text_field($_GET['qstn'][ $q_meta['input_id'] ][ $qstn_id ]);
509
-                                }
510
-                            } elseif (isset($q_meta['attendee']) && $q_meta['attendee']) {
511
-                                // attendee data from the session
512
-                                $answer = isset($q_meta['attendee'][ $qstn_id ]) ? $q_meta['attendee'][ $qstn_id ] : null;
513
-                            }
514
-
515
-
516
-
517
-                            $QFI = new EE_Question_Form_Input(
518
-                                $QST,
519
-                                EE_Answer::new_instance(array(
520
-                                            'ANS_ID' => 0,
521
-                                            'QST_ID' => 0,
522
-                                            'REG_ID' => 0,
523
-                                            'ANS_value' => $answer
524
-                                    )),
525
-                                $q_meta
526
-                            );
527
-                            // EEH_Debug_Tools::printr( $QFI, '$QFI  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' );
528
-                            $html .= self::generate_form_input($QFI);
529
-                        }
530
-                        $html .= $after_question_group_questions;
531
-                        $html .= "\n\t" . '</' . $group_wrapper . '>';
532
-                    }
533
-                }
534
-            }
535
-        }
536
-        return $html;
537
-    }
538
-
539
-
540
-
541
-
542
-
543
-
544
-    /**
545
-     * generate_form_input
546
-     *
547
-     * @param EE_Question_Form_Input $QFI
548
-     * @return string HTML
549
-     */
550
-    public static function generate_form_input(EE_Question_Form_Input $QFI)
551
-    {
552
-        if (isset($QFI->QST_admin_only) && $QFI->QST_admin_only && ! is_admin()) {
553
-            return '';
554
-        }
555
-
556
-        $QFI = self::_load_system_dropdowns($QFI);
557
-        $QFI = self::_load_specialized_dropdowns($QFI);
558
-
559
-        // we also need to verify
560
-
561
-        $display_text = $QFI->get('QST_display_text');
562
-        $input_name = $QFI->get('QST_input_name');
563
-        $answer = EE_Registry::instance()->REQ->is_set($input_name) ? EE_Registry::instance()->REQ->get($input_name) : $QFI->get('ANS_value');
564
-        $input_id = $QFI->get('QST_input_id');
565
-        $input_class = $QFI->get('QST_input_class');
476
+			// loop thru question groups
477
+			foreach ($question_groups as $QSG) {
478
+				if ($QSG instanceof EE_Question_Group) {
479
+					// check that questions exist
480
+
481
+					$where = array( 'QST_deleted' => 0 );
482
+					if (! $from_admin) {
483
+						$where['QST_admin_only'] = 0;
484
+					}
485
+					$questions = $QSG->questions(array( $where, 'order_by' => array( 'Question_Group_Question.QGQ_order' => 'ASC' )));
486
+					if (! empty($questions)) {
487
+						// use fieldsets
488
+						$html .= "\n\t" . '<' . $group_wrapper . ' class="espresso-question-group-wrap" id="' . $QSG->get('QSG_identifier') . '">';
489
+						// group_name
490
+						if ($QSG->show_group_name()) {
491
+							$html .=  "\n\t\t" . '<h5 class="espresso-question-group-title-h5 section-title">' . $QSG->get_pretty('QSG_name') . '</h5>';
492
+						}
493
+						// group_desc
494
+						if ($QSG->show_group_desc()) {
495
+							$html .=  '<div class="espresso-question-group-desc-pg">' . $QSG->get_pretty('QSG_desc') . '</div>';
496
+						}
497
+
498
+						$html .= $before_question_group_questions;
499
+						// loop thru questions
500
+						foreach ($questions as $QST) {
501
+							$qstn_id = $QST->is_system_question() ? $QST->system_ID() : $QST->ID();
502
+
503
+							$answer = null;
504
+
505
+							if (isset($_GET['qstn']) && isset($q_meta['input_id']) && isset($q_meta['att_nmbr'])) {
506
+								// check for answer in $_GET in case we are reprocessing a form after an error
507
+								if (isset($_GET['qstn'][ $q_meta['input_id'] ][ $qstn_id ])) {
508
+									$answer = is_array($_GET['qstn'][ $q_meta['input_id'] ][ $qstn_id ]) ? $_GET['qstn'][ $q_meta['input_id'] ][ $qstn_id ] : sanitize_text_field($_GET['qstn'][ $q_meta['input_id'] ][ $qstn_id ]);
509
+								}
510
+							} elseif (isset($q_meta['attendee']) && $q_meta['attendee']) {
511
+								// attendee data from the session
512
+								$answer = isset($q_meta['attendee'][ $qstn_id ]) ? $q_meta['attendee'][ $qstn_id ] : null;
513
+							}
514
+
515
+
516
+
517
+							$QFI = new EE_Question_Form_Input(
518
+								$QST,
519
+								EE_Answer::new_instance(array(
520
+											'ANS_ID' => 0,
521
+											'QST_ID' => 0,
522
+											'REG_ID' => 0,
523
+											'ANS_value' => $answer
524
+									)),
525
+								$q_meta
526
+							);
527
+							// EEH_Debug_Tools::printr( $QFI, '$QFI  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' );
528
+							$html .= self::generate_form_input($QFI);
529
+						}
530
+						$html .= $after_question_group_questions;
531
+						$html .= "\n\t" . '</' . $group_wrapper . '>';
532
+					}
533
+				}
534
+			}
535
+		}
536
+		return $html;
537
+	}
538
+
539
+
540
+
541
+
542
+
543
+
544
+	/**
545
+	 * generate_form_input
546
+	 *
547
+	 * @param EE_Question_Form_Input $QFI
548
+	 * @return string HTML
549
+	 */
550
+	public static function generate_form_input(EE_Question_Form_Input $QFI)
551
+	{
552
+		if (isset($QFI->QST_admin_only) && $QFI->QST_admin_only && ! is_admin()) {
553
+			return '';
554
+		}
555
+
556
+		$QFI = self::_load_system_dropdowns($QFI);
557
+		$QFI = self::_load_specialized_dropdowns($QFI);
558
+
559
+		// we also need to verify
560
+
561
+		$display_text = $QFI->get('QST_display_text');
562
+		$input_name = $QFI->get('QST_input_name');
563
+		$answer = EE_Registry::instance()->REQ->is_set($input_name) ? EE_Registry::instance()->REQ->get($input_name) : $QFI->get('ANS_value');
564
+		$input_id = $QFI->get('QST_input_id');
565
+		$input_class = $QFI->get('QST_input_class');
566 566
 //      $disabled = $QFI->get('QST_disabled') ? ' disabled="disabled"' : '';
567
-        $disabled = $QFI->get('QST_disabled') ? true : false;
568
-        $required_label = apply_filters(' FHEE__EEH_Form_Fields__generate_form_input__required_label', '<em>*</em>');
569
-        $QST_required = $QFI->get('QST_required');
570
-        $required = $QST_required ? array( 'label' => $required_label, 'class' => 'required needs-value', 'title' => $QST_required ) : array();
571
-        $use_html_entities = $QFI->get_meta('htmlentities');
572
-        $required_text = $QFI->get('QST_required_text') != '' ? $QFI->get('QST_required_text') : __('This field is required', 'event_espresso');
573
-        $required_text = $QST_required ? "\n\t\t\t" . '<div class="required-text hidden">' . self::prep_answer($required_text, $use_html_entities) . '</div>' : '';
574
-        $label_class = 'espresso-form-input-lbl';
575
-        $QST_options = $QFI->options(true, $answer);
576
-        $options = is_array($QST_options) ? self::prep_answer_options($QST_options) : array();
577
-        $system_ID = $QFI->get('QST_system');
578
-        $label_b4 = $QFI->get_meta('label_b4');
579
-        $use_desc_4_label = $QFI->get_meta('use_desc_4_label');
580
-
581
-
582
-        switch ($QFI->get('QST_type')) {
583
-            case 'TEXTAREA':
584
-                return EEH_Form_Fields::textarea($display_text, $answer, $input_name, $input_id, $input_class, array(), $required, $required_text, $label_class, $disabled, $system_ID, $use_html_entities);
585
-                break;
586
-
587
-            case 'DROPDOWN':
588
-                return EEH_Form_Fields::select($display_text, $answer, $options, $input_name, $input_id, $input_class, $required, $required_text, $label_class, $disabled, $system_ID, $use_html_entities, true);
589
-                break;
590
-
591
-
592
-            case 'RADIO_BTN':
593
-                return EEH_Form_Fields::radio($display_text, $answer, $options, $input_name, $input_id, $input_class, $required, $required_text, $label_class, $disabled, $system_ID, $use_html_entities, $label_b4, $use_desc_4_label);
594
-                break;
595
-
596
-            case 'CHECKBOX':
597
-                return EEH_Form_Fields::checkbox($display_text, $answer, $options, $input_name, $input_id, $input_class, $required, $required_text, $label_class, $disabled, $label_b4, $system_ID, $use_html_entities);
598
-                break;
599
-
600
-            case 'DATE':
601
-                return EEH_Form_Fields::datepicker($display_text, $answer, $input_name, $input_id, $input_class, $required, $required_text, $label_class, $disabled, $system_ID, $use_html_entities);
602
-                break;
603
-
604
-            case 'TEXT':
605
-            default:
606
-                return EEH_Form_Fields::text($display_text, $answer, $input_name, $input_id, $input_class, $required, $required_text, $label_class, $disabled, $system_ID, $use_html_entities);
607
-                break;
608
-        }
609
-    }
610
-
611
-
612
-
613
-
614
-
615
-
616
-    /**
617
-     * generates HTML for a form text input
618
-     *
619
-     * @param string $question  label content
620
-     * @param string $answer        form input value attribute
621
-     * @param string $name          form input name attribute
622
-     * @param string $id                form input css id attribute
623
-     * @param string $class             form input css class attribute
624
-     * @param array $required       'label', 'class', and 'msg' - array of values for required "label" content, css required 'class', and required 'msg' attribute
625
-     * @param string $label_class   css class attribute for the label
626
-     * @param string $disabled      disabled="disabled" or null
627
-     * @return string HTML
628
-     */
629
-    public static function text($question = false, $answer = null, $name = false, $id = '', $class = '', $required = false, $required_text = '', $label_class = '', $disabled = false, $system_ID = false, $use_html_entities = true)
630
-    {
631
-        // need these
632
-        if (! $question || ! $name) {
633
-            return null;
634
-        }
635
-        // prep the answer
636
-        $answer = is_array($answer) ? '' : self::prep_answer($answer, $use_html_entities);
637
-        // prep the required array
638
-        $required = self::prep_required($required);
639
-        // set disabled tag
640
-        $disabled = $answer === null || ! $disabled  ? '' : ' disabled="disabled"';
641
-        // ya gots ta have style man!!!
642
-        $txt_class = is_admin() ? 'regular-text' : 'espresso-text-inp';
643
-        $class = empty($class) ? $txt_class : $class;
644
-        $class .= ! empty($system_ID) ? ' ' . $system_ID : '';
645
-        $extra = apply_filters('FHEE__EEH_Form_Fields__additional_form_field_attributes', '');
646
-
647
-        $label_html = $required_text . "\n\t\t\t" . '<label for="' . $name . '" class="' . $label_class . '">' . self::prep_question($question) . $required['label'] . '</label><br/>';
648
-        // filter label but ensure required text comes before it
649
-        $label_html = apply_filters('FHEE__EEH_Form_Fields__label_html', $label_html, $required_text);
650
-
651
-        $input_html = "\n\t\t\t" . '<input type="text" name="' . $name . '" id="' . $id . '" class="' . $class . ' ' . $required['class'] . '" value="' . esc_attr($answer) . '"  title="' . esc_attr($required['msg']) . '" ' . $disabled . ' ' . $extra . '/>';
652
-
653
-        $input_html =  apply_filters('FHEE__EEH_Form_Fields__input_html', $input_html, $label_html, $id);
654
-        return  $label_html . $input_html;
655
-    }
656
-
657
-
658
-
659
-
660
-
661
-    /**
662
-     * generates HTML for a form textarea
663
-     *
664
-     * @param string $question      label content
665
-     * @param string $answer        form input value attribute
666
-     * @param string $name          form input name attribute
667
-     * @param string $id                form input css id attribute
668
-     * @param string $class             form input css class attribute
669
-     * @param array $dimensions array of form input rows and cols attributes : array( 'rows' => 3, 'cols' => 40 )
670
-     * @param array $required       'label', 'class', and 'msg' - array of values for required "label" content, css required 'class', and required 'msg' attribute
671
-     * @param string $label_class   css class attribute for the label
672
-     * @param string $disabled      disabled="disabled" or null
673
-     * @return string HTML
674
-     */
675
-    public static function textarea($question = false, $answer = null, $name = false, $id = '', $class = '', $dimensions = false, $required = false, $required_text = '', $label_class = '', $disabled = false, $system_ID = false, $use_html_entities = true)
676
-    {
677
-        // need these
678
-        if (! $question || ! $name) {
679
-            return null;
680
-        }
681
-        // prep the answer
682
-        $answer = is_array($answer) ? '' : self::prep_answer($answer, $use_html_entities);
683
-        // prep the required array
684
-        $required = self::prep_required($required);
685
-        // make sure $dimensions is an array
686
-        $dimensions = is_array($dimensions) ? $dimensions : array();
687
-        // and set some defaults
688
-        $dimensions = array_merge(array( 'rows' => 3, 'cols' => 40 ), $dimensions);
689
-        // set disabled tag
690
-        $disabled = $answer === null || ! $disabled  ? '' : ' disabled="disabled"';
691
-        // ya gots ta have style man!!!
692
-        $txt_class = is_admin() ? 'regular-text' : 'espresso-textarea-inp';
693
-        $class = empty($class) ? $txt_class : $class;
694
-        $class .= ! empty($system_ID) ? ' ' . $system_ID : '';
695
-        $extra = apply_filters('FHEE__EEH_Form_Fields__additional_form_field_attributes', '');
696
-
697
-        $label_html = $required_text . "\n\t\t\t" . '<label for="' . $name . '" class="' . $label_class . '">' . self::prep_question($question) . $required['label'] . '</label><br/>';
698
-        // filter label but ensure required text comes before it
699
-        $label_html = apply_filters('FHEE__EEH_Form_Fields__label_html', $label_html, $required_text);
700
-
701
-        $input_html = "\n\t\t\t" . '<textarea name="' . $name . '" id="' . $id . '" class="' . $class . ' ' . $required['class'] . '" rows="' . $dimensions['rows'] . '" cols="' . $dimensions['cols'] . '"  title="' . $required['msg'] . '" ' . $disabled . ' ' . $extra . '>' . $answer . '</textarea>';
702
-
703
-        $input_html =  apply_filters('FHEE__EEH_Form_Fields__input_html', $input_html, $label_html, $id);
704
-        return  $label_html . $input_html;
705
-    }
706
-
707
-
708
-
709
-
710
-
711
-
712
-    /**
713
-     * generates HTML for a form select input
714
-     *
715
-     * @param string $question      label content
716
-     * @param string $answer        form input value attribute
717
-     * @param array $options            array of answer options where array key = option value and array value = option display text
718
-     * @param string $name          form input name attribute
719
-     * @param string $id                form input css id attribute
720
-     * @param string $class             form input css class attribute
721
-     * @param array $required       'label', 'class', and 'msg' - array of values for required "label" content, css required 'class', and required 'msg' attribute
722
-     * @param string $label_class   css class attribute for the label
723
-     * @param string $disabled      disabled="disabled" or null
724
-     * @return string HTML
725
-     */
726
-    public static function select($question = false, $answer = null, $options = false, $name = false, $id = '', $class = '', $required = false, $required_text = '', $label_class = '', $disabled = false, $system_ID = false, $use_html_entities = true, $add_please_select_option = false)
727
-    {
728
-
729
-        // need these
730
-        if (! $question || ! $name || ! $options || empty($options) || ! is_array($options)) {
731
-            return null;
732
-        }
733
-        // prep the answer
734
-        $answer = is_array($answer) ? self::prep_answer(array_shift($answer), $use_html_entities) : self::prep_answer($answer, $use_html_entities);
735
-        // prep the required array
736
-        $required = self::prep_required($required);
737
-        // set disabled tag
738
-        $disabled = $answer === null || ! $disabled  ? '' : ' disabled="disabled"';
739
-        // ya gots ta have style man!!!
740
-        $txt_class = is_admin() ? 'wide' : 'espresso-select-inp';
741
-        $class = empty($class) ? $txt_class : $class;
742
-        $class .= ! empty($system_ID) ? ' ' . $system_ID : '';
743
-        $extra = apply_filters('FHEE__EEH_Form_Fields__additional_form_field_attributes', '');
744
-
745
-        $label_html = $required_text . "\n\t\t\t" . '<label for="' . $name . '" class="' . $label_class . '">' . self::prep_question($question) . $required['label'] . '</label><br/>';
746
-        // filter label but ensure required text comes before it
747
-        $label_html = apply_filters('FHEE__EEH_Form_Fields__label_html', $label_html, $required_text);
748
-
749
-        $input_html = "\n\t\t\t" . '<select name="' . $name . '" id="' . $id . '" class="' . $class . ' ' . $required['class'] . '" title="' . esc_attr($required['msg']) . '"' . $disabled . ' ' . $extra . '>';
750
-        // recursively count array elements, to determine total number of options
751
-        $only_option = count($options, 1) == 1 ? true : false;
752
-        if (! $only_option) {
753
-            // if there is NO answer set and there are multiple options to choose from, then set the "please select" message as selected
754
-            $selected = $answer === null ? ' selected="selected"' : '';
755
-            $input_html .= $add_please_select_option ? "\n\t\t\t\t" . '<option value=""' . $selected . '>' . __(' - please select - ', 'event_espresso') . '</option>' : '';
756
-        }
757
-        foreach ($options as $key => $value) {
758
-            // if value is an array, then create option groups, else create regular ol' options
759
-            $input_html .= is_array($value) ? self::_generate_select_option_group($key, $value, $answer, $use_html_entities) : self::_generate_select_option($value->value(), $value->desc(), $answer, $only_option, $use_html_entities);
760
-        }
761
-
762
-        $input_html .= "\n\t\t\t" . '</select>';
763
-
764
-        $input_html =  apply_filters('FHEE__EEH_Form_Fields__select__before_end_wrapper', $input_html, $question, $answer, $name, $id, $class, $system_ID);
765
-
766
-        $input_html =  apply_filters('FHEE__EEH_Form_Fields__input_html', $input_html, $label_html, $id);
767
-        return  $label_html . $input_html;
768
-    }
769
-
770
-
771
-
772
-    /**
773
-     *  _generate_select_option_group
774
-     *
775
-     *  if  $value for a select box is an array, then the key will be used as the optgroup label
776
-     *  and the value array will be looped thru and the elements sent to _generate_select_option
777
-     *
778
-     * @param mixed $opt_group
779
-     * @param mixed $QSOs
780
-     * @param mixed $answer
781
-     * @param boolean $use_html_entities
782
-     * @return string
783
-     */
784
-    private static function _generate_select_option_group($opt_group, $QSOs, $answer, $use_html_entities = true)
785
-    {
786
-        $html = "\n\t\t\t\t" . '<optgroup label="' . self::prep_option_value($opt_group) . '">';
787
-        foreach ($QSOs as $QSO) {
788
-            $html .= self::_generate_select_option($QSO->value(), $QSO->desc(), $answer, false, $use_html_entities);
789
-        }
790
-        $html .= "\n\t\t\t\t" . '</optgroup>';
791
-        return $html;
792
-    }
793
-
794
-
795
-
796
-    /**
797
-     *  _generate_select_option
798
-     * @param mixed $key
799
-     * @param mixed $value
800
-     * @param mixed $answer
801
-     * @param int $only_option
802
-     * @param boolean $use_html_entities
803
-     * @return string
804
-     */
805
-    private static function _generate_select_option($key, $value, $answer, $only_option = false, $use_html_entities = true)
806
-    {
807
-        $key = self::prep_answer($key, $use_html_entities);
808
-        $value = self::prep_answer($value, $use_html_entities);
809
-        $value = ! empty($value) ? $value : $key;
810
-        $selected = ( $answer == $key || $only_option ) ? ' selected="selected"' : '';
811
-        return "\n\t\t\t\t" . '<option value="' . self::prep_option_value($key) . '"' . $selected . '> ' . $value . '&nbsp;&nbsp;&nbsp;</option>';
812
-    }
813
-
814
-
815
-
816
-    /**
817
-     * generates HTML for form radio button inputs
818
-     *
819
-     * @param bool|string $question    label content
820
-     * @param string      $answer      form input value attribute
821
-     * @param array|bool  $options     array of answer options where array key = option value and array value = option display text
822
-     * @param bool|string $name        form input name attribute
823
-     * @param string      $id          form input css id attribute
824
-     * @param string      $class       form input css class attribute
825
-     * @param array|bool  $required    'label', 'class', and 'msg' - array of values for required "label" content, css required 'class', and required 'msg' attribute
826
-     * @param string      $required_text
827
-     * @param string      $label_class css class attribute for the label
828
-     * @param bool|string $disabled    disabled="disabled" or null
829
-     * @param bool        $system_ID
830
-     * @param bool        $use_html_entities
831
-     * @param bool        $label_b4
832
-     * @param bool        $use_desc_4_label
833
-     * @return string HTML
834
-     */
835
-    public static function radio($question = false, $answer = null, $options = false, $name = false, $id = '', $class = '', $required = false, $required_text = '', $label_class = '', $disabled = false, $system_ID = false, $use_html_entities = true, $label_b4 = false, $use_desc_4_label = false)
836
-    {
837
-        // need these
838
-        if (! $question || ! $name || ! $options || empty($options) || ! is_array($options)) {
839
-            return null;
840
-        }
841
-        // prep the answer
842
-        $answer = is_array($answer) ? '' : self::prep_answer($answer, $use_html_entities);
843
-        // prep the required array
844
-        $required = self::prep_required($required);
845
-        // set disabled tag
846
-        $disabled = $answer === null || ! $disabled  ? '' : ' disabled="disabled"';
847
-        // ya gots ta have style man!!!
848
-        $radio_class = is_admin() ? 'ee-admin-radio-lbl' : $label_class;
849
-        $class = ! empty($class) ? $class : 'espresso-radio-btn-inp';
850
-        $extra = apply_filters('FHEE__EEH_Form_Fields__additional_form_field_attributes', '');
851
-
852
-        $label_html = $required_text . "\n\t\t\t" . '<label class="' . $label_class . '">' . self::prep_question($question) . $required['label'] . '</label> ';
853
-        // filter label but ensure required text comes before it
854
-        $label_html = apply_filters('FHEE__EEH_Form_Fields__label_html', $label_html, $required_text);
855
-
856
-        $input_html = "\n\t\t\t" . '<ul id="' . $id . '-ul" class="espresso-radio-btn-options-ul ' . $label_class . ' ' . $class . '-ul">';
857
-
858
-        $class .= ! empty($system_ID) ? ' ' . $system_ID : '';
859
-        $class .= ! empty($required['class']) ? ' ' . $required['class'] : '';
860
-
861
-        foreach ($options as $OPT) {
862
-            if ($OPT instanceof EE_Question_Option) {
863
-                $value = self::prep_option_value($OPT->value());
864
-                $label = $use_desc_4_label ? $OPT->desc() : $OPT->value();
865
-                $size = $use_desc_4_label ? self::get_label_size_class($OPT->value() . ' ' . $OPT->desc()) : self::get_label_size_class($OPT->value());
866
-                $desc = $OPT->desc();// no self::prep_answer
867
-                $answer = is_numeric($value) && empty($answer) ? 0 : $answer;
868
-                $checked = (string) $value == (string) $answer ? ' checked="checked"' : '';
869
-                $opt = '-' . sanitize_key($value);
870
-
871
-                $input_html .= "\n\t\t\t\t" . '<li' . $size . '>';
872
-                $input_html .= "\n\t\t\t\t\t" . '<label class="' . $radio_class . ' espresso-radio-btn-lbl">';
873
-                $input_html .= $label_b4  ? "\n\t\t\t\t\t\t" . '<span>' . $label . '</span>' : '';
874
-                $input_html .= "\n\t\t\t\t\t\t" . '<input type="radio" name="' . $name . '" id="' . $id . $opt . '" class="' . $class . '" value="' . $value . '" title="' . esc_attr($required['msg']) . '" ' . $disabled . $checked . ' ' . $extra . '/>';
875
-                $input_html .= ! $label_b4  ? "\n\t\t\t\t\t\t" . '<span class="espresso-radio-btn-desc">' . $label . '</span>' : '';
876
-                $input_html .= "\n\t\t\t\t\t" . '</label>';
877
-                $input_html .= $use_desc_4_label ? '' : '<span class="espresso-radio-btn-option-desc small-text grey-text">' . $desc . '</span>';
878
-                $input_html .= "\n\t\t\t\t" . '</li>';
879
-            }
880
-        }
881
-
882
-        $input_html .= "\n\t\t\t" . '</ul>';
883
-
884
-        $input_html =  apply_filters('FHEE__EEH_Form_Fields__input_html', $input_html, $label_html, $id);
885
-        return  $label_html . $input_html;
886
-    }
887
-
888
-
889
-
890
-
891
-
892
-
893
-    /**
894
-     * generates HTML for form checkbox inputs
895
-     *
896
-     * @param string $question      label content
897
-     * @param string $answer        form input value attribute
898
-     * @param array $options            array of options where array key = option value and array value = option display text
899
-     * @param string $name          form input name attribute
900
-     * @param string $id                form input css id attribute
901
-     * @param string $class             form input css class attribute
902
-     * @param array $required       'label', 'class', and 'msg' - array of values for required "label" content, css required 'class', and required 'msg' attribute
903
-     * @param string $label_class   css class attribute for the label
904
-     * @param string $disabled      disabled="disabled" or null
905
-     * @return string HTML
906
-     */
907
-    public static function checkbox($question = false, $answer = null, $options = false, $name = false, $id = '', $class = '', $required = false, $required_text = '', $label_class = '', $disabled = false, $label_b4 = false, $system_ID = false, $use_html_entities = true)
908
-    {
909
-        // need these
910
-        if (! $question || ! $name || ! $options || empty($options) || ! is_array($options)) {
911
-            return null;
912
-        }
913
-        $answer = maybe_unserialize($answer);
914
-
915
-        // prep the answer(s)
916
-        $answer = is_array($answer) ? $answer : array( sanitize_key($answer) => $answer );
917
-
918
-        foreach ($answer as $key => $value) {
919
-            $key = self::prep_option_value($key);
920
-            $answer[ $key ] = self::prep_answer($value, $use_html_entities);
921
-        }
922
-
923
-        // prep the required array
924
-        $required = self::prep_required($required);
925
-        // set disabled tag
926
-        $disabled = $answer === null || ! $disabled  ? '' : ' disabled="disabled"';
927
-        // ya gots ta have style man!!!
928
-        $radio_class = is_admin() ? 'ee-admin-radio-lbl' : $label_class;
929
-        $class = empty($class) ? 'espresso-radio-btn-inp' : $class;
930
-        $extra = apply_filters('FHEE__EEH_Form_Fields__additional_form_field_attributes', '');
931
-
932
-        $label_html = $required_text . "\n\t\t\t" . '<label class="' . $label_class . '">' . self::prep_question($question) . $required['label'] . '</label> ';
933
-        // filter label but ensure required text comes before it
934
-        $label_html = apply_filters('FHEE__EEH_Form_Fields__label_html', $label_html, $required_text);
935
-
936
-        $input_html = "\n\t\t\t" . '<ul id="' . $id . '-ul" class="espresso-checkbox-options-ul ' . $label_class . ' ' . $class . '-ul">';
937
-
938
-        $class .= ! empty($system_ID) ? ' ' . $system_ID : '';
939
-        $class .= ! empty($required['class']) ? ' ' . $required['class'] : '';
940
-
941
-        foreach ($options as $OPT) {
942
-            $value = $OPT->value();// self::prep_option_value( $OPT->value() );
943
-            $size = self::get_label_size_class($OPT->value() . ' ' . $OPT->desc());
944
-            $text = self::prep_answer($OPT->value());
945
-            $desc = $OPT->desc() ;
946
-            $opt = '-' . sanitize_key($value);
947
-
948
-            $checked = is_array($answer) && in_array($text, $answer) ? ' checked="checked"' : '';
949
-
950
-            $input_html .= "\n\t\t\t\t" . '<li' . $size . '>';
951
-            $input_html .= "\n\t\t\t\t\t" . '<label class="' . $radio_class . ' espresso-checkbox-lbl">';
952
-            $input_html .= $label_b4  ? "\n\t\t\t\t\t\t" . '<span>' . $text . '</span>' : '';
953
-            $input_html .= "\n\t\t\t\t\t\t" . '<input type="checkbox" name="' . $name . '[' . $OPT->ID() . ']" id="' . $id . $opt . '" class="' . $class . '" value="' . $value . '" title="' . esc_attr($required['msg']) . '" ' . $disabled . $checked . ' ' . $extra . '/>';
954
-            $input_html .= ! $label_b4  ? "\n\t\t\t\t\t\t" . '<span>' . $text . '</span>' : '';
955
-            $input_html .= "\n\t\t\t\t\t" . '</label>';
956
-            if (! empty($desc) && $desc != $text) {
957
-                $input_html .= "\n\t\t\t\t\t" . ' &nbsp; <br/><div class="espresso-checkbox-option-desc small-text grey-text">' . $desc . '</div>';
958
-            }
959
-            $input_html .= "\n\t\t\t\t" . '</li>';
960
-        }
961
-
962
-        $input_html .= "\n\t\t\t" . '</ul>';
963
-
964
-        $input_html =  apply_filters('FHEE__EEH_Form_Fields__input_html', $input_html, $label_html, $id);
965
-        return  $label_html . $input_html;
966
-    }
967
-
968
-
969
-
970
-
971
-
972
-
973
-    /**
974
-     * generates HTML for a form datepicker input
975
-     *
976
-     * @param string $question  label content
977
-     * @param string $answer        form input value attribute
978
-     * @param string $name          form input name attribute
979
-     * @param string $id                form input css id attribute
980
-     * @param string $class             form input css class attribute
981
-     * @param array $required       'label', 'class', and 'msg' - array of values for required "label" content, css required 'class', and required 'msg' attribute
982
-     * @param string $label_class   css class attribute for the label
983
-     * @param string $disabled      disabled="disabled" or null
984
-     * @return string HTML
985
-     */
986
-    public static function datepicker($question = false, $answer = null, $name = false, $id = '', $class = '', $required = false, $required_text = '', $label_class = '', $disabled = false, $system_ID = false, $use_html_entities = true)
987
-    {
988
-        // need these
989
-        if (! $question || ! $name) {
990
-            return null;
991
-        }
992
-        // prep the answer
993
-        $answer = is_array($answer) ? '' : self::prep_answer($answer, $use_html_entities);
994
-        // prep the required array
995
-        $required = self::prep_required($required);
996
-        // set disabled tag
997
-        $disabled = $answer === null || ! $disabled  ? '' : ' disabled="disabled"';
998
-        // ya gots ta have style man!!!
999
-        $txt_class = is_admin() ? 'regular-text' : 'espresso-datepicker-inp';
1000
-        $class = empty($class) ? $txt_class : $class;
1001
-        $class .= ! empty($system_ID) ? ' ' . $system_ID : '';
1002
-        $extra = apply_filters('FHEE__EEH_Form_Fields__additional_form_field_attributes', '');
1003
-
1004
-        $label_html = $required_text . "\n\t\t\t" . '<label for="' . $name . '" class="' . $label_class . '">' . self::prep_question($question) . $required['label'] . '</label><br/>';
1005
-        // filter label but ensure required text comes before it
1006
-        $label_html = apply_filters('FHEE__EEH_Form_Fields__label_html', $label_html, $required_text);
1007
-
1008
-        $input_html = "\n\t\t\t" . '<input type="text" name="' . $name . '" id="' . $id . '" class="' . $class . ' ' . $required['class'] . ' datepicker" value="' . $answer . '"  title="' . esc_attr($required['msg']) . '" ' . $disabled . ' ' . $extra . '/>';
1009
-
1010
-        // enqueue scripts
1011
-        wp_register_style('espresso-ui-theme', EE_GLOBAL_ASSETS_URL . 'css/espresso-ui-theme/jquery-ui-1.10.3.custom.min.css', array(), EVENT_ESPRESSO_VERSION);
1012
-        wp_enqueue_style('espresso-ui-theme');
1013
-        wp_enqueue_script('jquery-ui-datepicker');
1014
-
1015
-        $input_html =  apply_filters('FHEE__EEH_Form_Fields__input_html', $input_html, $label_html, $id);
1016
-        return  $label_html . $input_html;
1017
-    }
1018
-
1019
-
1020
-
1021
-    /**
1022
-     *  remove_label_keep_required_msg
1023
-     *  this will strip out a form input's label HTML while keeping the required text HTML that MUST be before the label
1024
-     *  @access public
1025
-     *  @return     string
1026
-     */
1027
-    public static function remove_label_keep_required_msg($label_html, $required_text)
1028
-    {
1029
-        return $required_text;
1030
-    }
1031
-
1032
-
1033
-
1034
-
1035
-
1036
-    /**
1037
-     * Simply return sthe HTML for a hidden input of the given name and value.
1038
-     * @param string $name
1039
-     * @param string $value
1040
-     * @return string HTML
1041
-     */
1042
-    public static function hidden_input($name, $value, $id = '')
1043
-    {
1044
-        $id = ! empty($id) ? $id : $name;
1045
-        return '<input id="' . $id . '" type="hidden" name="' . $name . '" value="' .  $value . '"/>';
1046
-    }
1047
-
1048
-
1049
-
1050
-
1051
-
1052
-    /**
1053
-     * prep_question
1054
-     * @param string $question
1055
-     * @return string
1056
-     */
1057
-    public static function prep_question($question)
1058
-    {
1059
-        return $question;
567
+		$disabled = $QFI->get('QST_disabled') ? true : false;
568
+		$required_label = apply_filters(' FHEE__EEH_Form_Fields__generate_form_input__required_label', '<em>*</em>');
569
+		$QST_required = $QFI->get('QST_required');
570
+		$required = $QST_required ? array( 'label' => $required_label, 'class' => 'required needs-value', 'title' => $QST_required ) : array();
571
+		$use_html_entities = $QFI->get_meta('htmlentities');
572
+		$required_text = $QFI->get('QST_required_text') != '' ? $QFI->get('QST_required_text') : __('This field is required', 'event_espresso');
573
+		$required_text = $QST_required ? "\n\t\t\t" . '<div class="required-text hidden">' . self::prep_answer($required_text, $use_html_entities) . '</div>' : '';
574
+		$label_class = 'espresso-form-input-lbl';
575
+		$QST_options = $QFI->options(true, $answer);
576
+		$options = is_array($QST_options) ? self::prep_answer_options($QST_options) : array();
577
+		$system_ID = $QFI->get('QST_system');
578
+		$label_b4 = $QFI->get_meta('label_b4');
579
+		$use_desc_4_label = $QFI->get_meta('use_desc_4_label');
580
+
581
+
582
+		switch ($QFI->get('QST_type')) {
583
+			case 'TEXTAREA':
584
+				return EEH_Form_Fields::textarea($display_text, $answer, $input_name, $input_id, $input_class, array(), $required, $required_text, $label_class, $disabled, $system_ID, $use_html_entities);
585
+				break;
586
+
587
+			case 'DROPDOWN':
588
+				return EEH_Form_Fields::select($display_text, $answer, $options, $input_name, $input_id, $input_class, $required, $required_text, $label_class, $disabled, $system_ID, $use_html_entities, true);
589
+				break;
590
+
591
+
592
+			case 'RADIO_BTN':
593
+				return EEH_Form_Fields::radio($display_text, $answer, $options, $input_name, $input_id, $input_class, $required, $required_text, $label_class, $disabled, $system_ID, $use_html_entities, $label_b4, $use_desc_4_label);
594
+				break;
595
+
596
+			case 'CHECKBOX':
597
+				return EEH_Form_Fields::checkbox($display_text, $answer, $options, $input_name, $input_id, $input_class, $required, $required_text, $label_class, $disabled, $label_b4, $system_ID, $use_html_entities);
598
+				break;
599
+
600
+			case 'DATE':
601
+				return EEH_Form_Fields::datepicker($display_text, $answer, $input_name, $input_id, $input_class, $required, $required_text, $label_class, $disabled, $system_ID, $use_html_entities);
602
+				break;
603
+
604
+			case 'TEXT':
605
+			default:
606
+				return EEH_Form_Fields::text($display_text, $answer, $input_name, $input_id, $input_class, $required, $required_text, $label_class, $disabled, $system_ID, $use_html_entities);
607
+				break;
608
+		}
609
+	}
610
+
611
+
612
+
613
+
614
+
615
+
616
+	/**
617
+	 * generates HTML for a form text input
618
+	 *
619
+	 * @param string $question  label content
620
+	 * @param string $answer        form input value attribute
621
+	 * @param string $name          form input name attribute
622
+	 * @param string $id                form input css id attribute
623
+	 * @param string $class             form input css class attribute
624
+	 * @param array $required       'label', 'class', and 'msg' - array of values for required "label" content, css required 'class', and required 'msg' attribute
625
+	 * @param string $label_class   css class attribute for the label
626
+	 * @param string $disabled      disabled="disabled" or null
627
+	 * @return string HTML
628
+	 */
629
+	public static function text($question = false, $answer = null, $name = false, $id = '', $class = '', $required = false, $required_text = '', $label_class = '', $disabled = false, $system_ID = false, $use_html_entities = true)
630
+	{
631
+		// need these
632
+		if (! $question || ! $name) {
633
+			return null;
634
+		}
635
+		// prep the answer
636
+		$answer = is_array($answer) ? '' : self::prep_answer($answer, $use_html_entities);
637
+		// prep the required array
638
+		$required = self::prep_required($required);
639
+		// set disabled tag
640
+		$disabled = $answer === null || ! $disabled  ? '' : ' disabled="disabled"';
641
+		// ya gots ta have style man!!!
642
+		$txt_class = is_admin() ? 'regular-text' : 'espresso-text-inp';
643
+		$class = empty($class) ? $txt_class : $class;
644
+		$class .= ! empty($system_ID) ? ' ' . $system_ID : '';
645
+		$extra = apply_filters('FHEE__EEH_Form_Fields__additional_form_field_attributes', '');
646
+
647
+		$label_html = $required_text . "\n\t\t\t" . '<label for="' . $name . '" class="' . $label_class . '">' . self::prep_question($question) . $required['label'] . '</label><br/>';
648
+		// filter label but ensure required text comes before it
649
+		$label_html = apply_filters('FHEE__EEH_Form_Fields__label_html', $label_html, $required_text);
650
+
651
+		$input_html = "\n\t\t\t" . '<input type="text" name="' . $name . '" id="' . $id . '" class="' . $class . ' ' . $required['class'] . '" value="' . esc_attr($answer) . '"  title="' . esc_attr($required['msg']) . '" ' . $disabled . ' ' . $extra . '/>';
652
+
653
+		$input_html =  apply_filters('FHEE__EEH_Form_Fields__input_html', $input_html, $label_html, $id);
654
+		return  $label_html . $input_html;
655
+	}
656
+
657
+
658
+
659
+
660
+
661
+	/**
662
+	 * generates HTML for a form textarea
663
+	 *
664
+	 * @param string $question      label content
665
+	 * @param string $answer        form input value attribute
666
+	 * @param string $name          form input name attribute
667
+	 * @param string $id                form input css id attribute
668
+	 * @param string $class             form input css class attribute
669
+	 * @param array $dimensions array of form input rows and cols attributes : array( 'rows' => 3, 'cols' => 40 )
670
+	 * @param array $required       'label', 'class', and 'msg' - array of values for required "label" content, css required 'class', and required 'msg' attribute
671
+	 * @param string $label_class   css class attribute for the label
672
+	 * @param string $disabled      disabled="disabled" or null
673
+	 * @return string HTML
674
+	 */
675
+	public static function textarea($question = false, $answer = null, $name = false, $id = '', $class = '', $dimensions = false, $required = false, $required_text = '', $label_class = '', $disabled = false, $system_ID = false, $use_html_entities = true)
676
+	{
677
+		// need these
678
+		if (! $question || ! $name) {
679
+			return null;
680
+		}
681
+		// prep the answer
682
+		$answer = is_array($answer) ? '' : self::prep_answer($answer, $use_html_entities);
683
+		// prep the required array
684
+		$required = self::prep_required($required);
685
+		// make sure $dimensions is an array
686
+		$dimensions = is_array($dimensions) ? $dimensions : array();
687
+		// and set some defaults
688
+		$dimensions = array_merge(array( 'rows' => 3, 'cols' => 40 ), $dimensions);
689
+		// set disabled tag
690
+		$disabled = $answer === null || ! $disabled  ? '' : ' disabled="disabled"';
691
+		// ya gots ta have style man!!!
692
+		$txt_class = is_admin() ? 'regular-text' : 'espresso-textarea-inp';
693
+		$class = empty($class) ? $txt_class : $class;
694
+		$class .= ! empty($system_ID) ? ' ' . $system_ID : '';
695
+		$extra = apply_filters('FHEE__EEH_Form_Fields__additional_form_field_attributes', '');
696
+
697
+		$label_html = $required_text . "\n\t\t\t" . '<label for="' . $name . '" class="' . $label_class . '">' . self::prep_question($question) . $required['label'] . '</label><br/>';
698
+		// filter label but ensure required text comes before it
699
+		$label_html = apply_filters('FHEE__EEH_Form_Fields__label_html', $label_html, $required_text);
700
+
701
+		$input_html = "\n\t\t\t" . '<textarea name="' . $name . '" id="' . $id . '" class="' . $class . ' ' . $required['class'] . '" rows="' . $dimensions['rows'] . '" cols="' . $dimensions['cols'] . '"  title="' . $required['msg'] . '" ' . $disabled . ' ' . $extra . '>' . $answer . '</textarea>';
702
+
703
+		$input_html =  apply_filters('FHEE__EEH_Form_Fields__input_html', $input_html, $label_html, $id);
704
+		return  $label_html . $input_html;
705
+	}
706
+
707
+
708
+
709
+
710
+
711
+
712
+	/**
713
+	 * generates HTML for a form select input
714
+	 *
715
+	 * @param string $question      label content
716
+	 * @param string $answer        form input value attribute
717
+	 * @param array $options            array of answer options where array key = option value and array value = option display text
718
+	 * @param string $name          form input name attribute
719
+	 * @param string $id                form input css id attribute
720
+	 * @param string $class             form input css class attribute
721
+	 * @param array $required       'label', 'class', and 'msg' - array of values for required "label" content, css required 'class', and required 'msg' attribute
722
+	 * @param string $label_class   css class attribute for the label
723
+	 * @param string $disabled      disabled="disabled" or null
724
+	 * @return string HTML
725
+	 */
726
+	public static function select($question = false, $answer = null, $options = false, $name = false, $id = '', $class = '', $required = false, $required_text = '', $label_class = '', $disabled = false, $system_ID = false, $use_html_entities = true, $add_please_select_option = false)
727
+	{
728
+
729
+		// need these
730
+		if (! $question || ! $name || ! $options || empty($options) || ! is_array($options)) {
731
+			return null;
732
+		}
733
+		// prep the answer
734
+		$answer = is_array($answer) ? self::prep_answer(array_shift($answer), $use_html_entities) : self::prep_answer($answer, $use_html_entities);
735
+		// prep the required array
736
+		$required = self::prep_required($required);
737
+		// set disabled tag
738
+		$disabled = $answer === null || ! $disabled  ? '' : ' disabled="disabled"';
739
+		// ya gots ta have style man!!!
740
+		$txt_class = is_admin() ? 'wide' : 'espresso-select-inp';
741
+		$class = empty($class) ? $txt_class : $class;
742
+		$class .= ! empty($system_ID) ? ' ' . $system_ID : '';
743
+		$extra = apply_filters('FHEE__EEH_Form_Fields__additional_form_field_attributes', '');
744
+
745
+		$label_html = $required_text . "\n\t\t\t" . '<label for="' . $name . '" class="' . $label_class . '">' . self::prep_question($question) . $required['label'] . '</label><br/>';
746
+		// filter label but ensure required text comes before it
747
+		$label_html = apply_filters('FHEE__EEH_Form_Fields__label_html', $label_html, $required_text);
748
+
749
+		$input_html = "\n\t\t\t" . '<select name="' . $name . '" id="' . $id . '" class="' . $class . ' ' . $required['class'] . '" title="' . esc_attr($required['msg']) . '"' . $disabled . ' ' . $extra . '>';
750
+		// recursively count array elements, to determine total number of options
751
+		$only_option = count($options, 1) == 1 ? true : false;
752
+		if (! $only_option) {
753
+			// if there is NO answer set and there are multiple options to choose from, then set the "please select" message as selected
754
+			$selected = $answer === null ? ' selected="selected"' : '';
755
+			$input_html .= $add_please_select_option ? "\n\t\t\t\t" . '<option value=""' . $selected . '>' . __(' - please select - ', 'event_espresso') . '</option>' : '';
756
+		}
757
+		foreach ($options as $key => $value) {
758
+			// if value is an array, then create option groups, else create regular ol' options
759
+			$input_html .= is_array($value) ? self::_generate_select_option_group($key, $value, $answer, $use_html_entities) : self::_generate_select_option($value->value(), $value->desc(), $answer, $only_option, $use_html_entities);
760
+		}
761
+
762
+		$input_html .= "\n\t\t\t" . '</select>';
763
+
764
+		$input_html =  apply_filters('FHEE__EEH_Form_Fields__select__before_end_wrapper', $input_html, $question, $answer, $name, $id, $class, $system_ID);
765
+
766
+		$input_html =  apply_filters('FHEE__EEH_Form_Fields__input_html', $input_html, $label_html, $id);
767
+		return  $label_html . $input_html;
768
+	}
769
+
770
+
771
+
772
+	/**
773
+	 *  _generate_select_option_group
774
+	 *
775
+	 *  if  $value for a select box is an array, then the key will be used as the optgroup label
776
+	 *  and the value array will be looped thru and the elements sent to _generate_select_option
777
+	 *
778
+	 * @param mixed $opt_group
779
+	 * @param mixed $QSOs
780
+	 * @param mixed $answer
781
+	 * @param boolean $use_html_entities
782
+	 * @return string
783
+	 */
784
+	private static function _generate_select_option_group($opt_group, $QSOs, $answer, $use_html_entities = true)
785
+	{
786
+		$html = "\n\t\t\t\t" . '<optgroup label="' . self::prep_option_value($opt_group) . '">';
787
+		foreach ($QSOs as $QSO) {
788
+			$html .= self::_generate_select_option($QSO->value(), $QSO->desc(), $answer, false, $use_html_entities);
789
+		}
790
+		$html .= "\n\t\t\t\t" . '</optgroup>';
791
+		return $html;
792
+	}
793
+
794
+
795
+
796
+	/**
797
+	 *  _generate_select_option
798
+	 * @param mixed $key
799
+	 * @param mixed $value
800
+	 * @param mixed $answer
801
+	 * @param int $only_option
802
+	 * @param boolean $use_html_entities
803
+	 * @return string
804
+	 */
805
+	private static function _generate_select_option($key, $value, $answer, $only_option = false, $use_html_entities = true)
806
+	{
807
+		$key = self::prep_answer($key, $use_html_entities);
808
+		$value = self::prep_answer($value, $use_html_entities);
809
+		$value = ! empty($value) ? $value : $key;
810
+		$selected = ( $answer == $key || $only_option ) ? ' selected="selected"' : '';
811
+		return "\n\t\t\t\t" . '<option value="' . self::prep_option_value($key) . '"' . $selected . '> ' . $value . '&nbsp;&nbsp;&nbsp;</option>';
812
+	}
813
+
814
+
815
+
816
+	/**
817
+	 * generates HTML for form radio button inputs
818
+	 *
819
+	 * @param bool|string $question    label content
820
+	 * @param string      $answer      form input value attribute
821
+	 * @param array|bool  $options     array of answer options where array key = option value and array value = option display text
822
+	 * @param bool|string $name        form input name attribute
823
+	 * @param string      $id          form input css id attribute
824
+	 * @param string      $class       form input css class attribute
825
+	 * @param array|bool  $required    'label', 'class', and 'msg' - array of values for required "label" content, css required 'class', and required 'msg' attribute
826
+	 * @param string      $required_text
827
+	 * @param string      $label_class css class attribute for the label
828
+	 * @param bool|string $disabled    disabled="disabled" or null
829
+	 * @param bool        $system_ID
830
+	 * @param bool        $use_html_entities
831
+	 * @param bool        $label_b4
832
+	 * @param bool        $use_desc_4_label
833
+	 * @return string HTML
834
+	 */
835
+	public static function radio($question = false, $answer = null, $options = false, $name = false, $id = '', $class = '', $required = false, $required_text = '', $label_class = '', $disabled = false, $system_ID = false, $use_html_entities = true, $label_b4 = false, $use_desc_4_label = false)
836
+	{
837
+		// need these
838
+		if (! $question || ! $name || ! $options || empty($options) || ! is_array($options)) {
839
+			return null;
840
+		}
841
+		// prep the answer
842
+		$answer = is_array($answer) ? '' : self::prep_answer($answer, $use_html_entities);
843
+		// prep the required array
844
+		$required = self::prep_required($required);
845
+		// set disabled tag
846
+		$disabled = $answer === null || ! $disabled  ? '' : ' disabled="disabled"';
847
+		// ya gots ta have style man!!!
848
+		$radio_class = is_admin() ? 'ee-admin-radio-lbl' : $label_class;
849
+		$class = ! empty($class) ? $class : 'espresso-radio-btn-inp';
850
+		$extra = apply_filters('FHEE__EEH_Form_Fields__additional_form_field_attributes', '');
851
+
852
+		$label_html = $required_text . "\n\t\t\t" . '<label class="' . $label_class . '">' . self::prep_question($question) . $required['label'] . '</label> ';
853
+		// filter label but ensure required text comes before it
854
+		$label_html = apply_filters('FHEE__EEH_Form_Fields__label_html', $label_html, $required_text);
855
+
856
+		$input_html = "\n\t\t\t" . '<ul id="' . $id . '-ul" class="espresso-radio-btn-options-ul ' . $label_class . ' ' . $class . '-ul">';
857
+
858
+		$class .= ! empty($system_ID) ? ' ' . $system_ID : '';
859
+		$class .= ! empty($required['class']) ? ' ' . $required['class'] : '';
860
+
861
+		foreach ($options as $OPT) {
862
+			if ($OPT instanceof EE_Question_Option) {
863
+				$value = self::prep_option_value($OPT->value());
864
+				$label = $use_desc_4_label ? $OPT->desc() : $OPT->value();
865
+				$size = $use_desc_4_label ? self::get_label_size_class($OPT->value() . ' ' . $OPT->desc()) : self::get_label_size_class($OPT->value());
866
+				$desc = $OPT->desc();// no self::prep_answer
867
+				$answer = is_numeric($value) && empty($answer) ? 0 : $answer;
868
+				$checked = (string) $value == (string) $answer ? ' checked="checked"' : '';
869
+				$opt = '-' . sanitize_key($value);
870
+
871
+				$input_html .= "\n\t\t\t\t" . '<li' . $size . '>';
872
+				$input_html .= "\n\t\t\t\t\t" . '<label class="' . $radio_class . ' espresso-radio-btn-lbl">';
873
+				$input_html .= $label_b4  ? "\n\t\t\t\t\t\t" . '<span>' . $label . '</span>' : '';
874
+				$input_html .= "\n\t\t\t\t\t\t" . '<input type="radio" name="' . $name . '" id="' . $id . $opt . '" class="' . $class . '" value="' . $value . '" title="' . esc_attr($required['msg']) . '" ' . $disabled . $checked . ' ' . $extra . '/>';
875
+				$input_html .= ! $label_b4  ? "\n\t\t\t\t\t\t" . '<span class="espresso-radio-btn-desc">' . $label . '</span>' : '';
876
+				$input_html .= "\n\t\t\t\t\t" . '</label>';
877
+				$input_html .= $use_desc_4_label ? '' : '<span class="espresso-radio-btn-option-desc small-text grey-text">' . $desc . '</span>';
878
+				$input_html .= "\n\t\t\t\t" . '</li>';
879
+			}
880
+		}
881
+
882
+		$input_html .= "\n\t\t\t" . '</ul>';
883
+
884
+		$input_html =  apply_filters('FHEE__EEH_Form_Fields__input_html', $input_html, $label_html, $id);
885
+		return  $label_html . $input_html;
886
+	}
887
+
888
+
889
+
890
+
891
+
892
+
893
+	/**
894
+	 * generates HTML for form checkbox inputs
895
+	 *
896
+	 * @param string $question      label content
897
+	 * @param string $answer        form input value attribute
898
+	 * @param array $options            array of options where array key = option value and array value = option display text
899
+	 * @param string $name          form input name attribute
900
+	 * @param string $id                form input css id attribute
901
+	 * @param string $class             form input css class attribute
902
+	 * @param array $required       'label', 'class', and 'msg' - array of values for required "label" content, css required 'class', and required 'msg' attribute
903
+	 * @param string $label_class   css class attribute for the label
904
+	 * @param string $disabled      disabled="disabled" or null
905
+	 * @return string HTML
906
+	 */
907
+	public static function checkbox($question = false, $answer = null, $options = false, $name = false, $id = '', $class = '', $required = false, $required_text = '', $label_class = '', $disabled = false, $label_b4 = false, $system_ID = false, $use_html_entities = true)
908
+	{
909
+		// need these
910
+		if (! $question || ! $name || ! $options || empty($options) || ! is_array($options)) {
911
+			return null;
912
+		}
913
+		$answer = maybe_unserialize($answer);
914
+
915
+		// prep the answer(s)
916
+		$answer = is_array($answer) ? $answer : array( sanitize_key($answer) => $answer );
917
+
918
+		foreach ($answer as $key => $value) {
919
+			$key = self::prep_option_value($key);
920
+			$answer[ $key ] = self::prep_answer($value, $use_html_entities);
921
+		}
922
+
923
+		// prep the required array
924
+		$required = self::prep_required($required);
925
+		// set disabled tag
926
+		$disabled = $answer === null || ! $disabled  ? '' : ' disabled="disabled"';
927
+		// ya gots ta have style man!!!
928
+		$radio_class = is_admin() ? 'ee-admin-radio-lbl' : $label_class;
929
+		$class = empty($class) ? 'espresso-radio-btn-inp' : $class;
930
+		$extra = apply_filters('FHEE__EEH_Form_Fields__additional_form_field_attributes', '');
931
+
932
+		$label_html = $required_text . "\n\t\t\t" . '<label class="' . $label_class . '">' . self::prep_question($question) . $required['label'] . '</label> ';
933
+		// filter label but ensure required text comes before it
934
+		$label_html = apply_filters('FHEE__EEH_Form_Fields__label_html', $label_html, $required_text);
935
+
936
+		$input_html = "\n\t\t\t" . '<ul id="' . $id . '-ul" class="espresso-checkbox-options-ul ' . $label_class . ' ' . $class . '-ul">';
937
+
938
+		$class .= ! empty($system_ID) ? ' ' . $system_ID : '';
939
+		$class .= ! empty($required['class']) ? ' ' . $required['class'] : '';
940
+
941
+		foreach ($options as $OPT) {
942
+			$value = $OPT->value();// self::prep_option_value( $OPT->value() );
943
+			$size = self::get_label_size_class($OPT->value() . ' ' . $OPT->desc());
944
+			$text = self::prep_answer($OPT->value());
945
+			$desc = $OPT->desc() ;
946
+			$opt = '-' . sanitize_key($value);
947
+
948
+			$checked = is_array($answer) && in_array($text, $answer) ? ' checked="checked"' : '';
949
+
950
+			$input_html .= "\n\t\t\t\t" . '<li' . $size . '>';
951
+			$input_html .= "\n\t\t\t\t\t" . '<label class="' . $radio_class . ' espresso-checkbox-lbl">';
952
+			$input_html .= $label_b4  ? "\n\t\t\t\t\t\t" . '<span>' . $text . '</span>' : '';
953
+			$input_html .= "\n\t\t\t\t\t\t" . '<input type="checkbox" name="' . $name . '[' . $OPT->ID() . ']" id="' . $id . $opt . '" class="' . $class . '" value="' . $value . '" title="' . esc_attr($required['msg']) . '" ' . $disabled . $checked . ' ' . $extra . '/>';
954
+			$input_html .= ! $label_b4  ? "\n\t\t\t\t\t\t" . '<span>' . $text . '</span>' : '';
955
+			$input_html .= "\n\t\t\t\t\t" . '</label>';
956
+			if (! empty($desc) && $desc != $text) {
957
+				$input_html .= "\n\t\t\t\t\t" . ' &nbsp; <br/><div class="espresso-checkbox-option-desc small-text grey-text">' . $desc . '</div>';
958
+			}
959
+			$input_html .= "\n\t\t\t\t" . '</li>';
960
+		}
961
+
962
+		$input_html .= "\n\t\t\t" . '</ul>';
963
+
964
+		$input_html =  apply_filters('FHEE__EEH_Form_Fields__input_html', $input_html, $label_html, $id);
965
+		return  $label_html . $input_html;
966
+	}
967
+
968
+
969
+
970
+
971
+
972
+
973
+	/**
974
+	 * generates HTML for a form datepicker input
975
+	 *
976
+	 * @param string $question  label content
977
+	 * @param string $answer        form input value attribute
978
+	 * @param string $name          form input name attribute
979
+	 * @param string $id                form input css id attribute
980
+	 * @param string $class             form input css class attribute
981
+	 * @param array $required       'label', 'class', and 'msg' - array of values for required "label" content, css required 'class', and required 'msg' attribute
982
+	 * @param string $label_class   css class attribute for the label
983
+	 * @param string $disabled      disabled="disabled" or null
984
+	 * @return string HTML
985
+	 */
986
+	public static function datepicker($question = false, $answer = null, $name = false, $id = '', $class = '', $required = false, $required_text = '', $label_class = '', $disabled = false, $system_ID = false, $use_html_entities = true)
987
+	{
988
+		// need these
989
+		if (! $question || ! $name) {
990
+			return null;
991
+		}
992
+		// prep the answer
993
+		$answer = is_array($answer) ? '' : self::prep_answer($answer, $use_html_entities);
994
+		// prep the required array
995
+		$required = self::prep_required($required);
996
+		// set disabled tag
997
+		$disabled = $answer === null || ! $disabled  ? '' : ' disabled="disabled"';
998
+		// ya gots ta have style man!!!
999
+		$txt_class = is_admin() ? 'regular-text' : 'espresso-datepicker-inp';
1000
+		$class = empty($class) ? $txt_class : $class;
1001
+		$class .= ! empty($system_ID) ? ' ' . $system_ID : '';
1002
+		$extra = apply_filters('FHEE__EEH_Form_Fields__additional_form_field_attributes', '');
1003
+
1004
+		$label_html = $required_text . "\n\t\t\t" . '<label for="' . $name . '" class="' . $label_class . '">' . self::prep_question($question) . $required['label'] . '</label><br/>';
1005
+		// filter label but ensure required text comes before it
1006
+		$label_html = apply_filters('FHEE__EEH_Form_Fields__label_html', $label_html, $required_text);
1007
+
1008
+		$input_html = "\n\t\t\t" . '<input type="text" name="' . $name . '" id="' . $id . '" class="' . $class . ' ' . $required['class'] . ' datepicker" value="' . $answer . '"  title="' . esc_attr($required['msg']) . '" ' . $disabled . ' ' . $extra . '/>';
1009
+
1010
+		// enqueue scripts
1011
+		wp_register_style('espresso-ui-theme', EE_GLOBAL_ASSETS_URL . 'css/espresso-ui-theme/jquery-ui-1.10.3.custom.min.css', array(), EVENT_ESPRESSO_VERSION);
1012
+		wp_enqueue_style('espresso-ui-theme');
1013
+		wp_enqueue_script('jquery-ui-datepicker');
1014
+
1015
+		$input_html =  apply_filters('FHEE__EEH_Form_Fields__input_html', $input_html, $label_html, $id);
1016
+		return  $label_html . $input_html;
1017
+	}
1018
+
1019
+
1020
+
1021
+	/**
1022
+	 *  remove_label_keep_required_msg
1023
+	 *  this will strip out a form input's label HTML while keeping the required text HTML that MUST be before the label
1024
+	 *  @access public
1025
+	 *  @return     string
1026
+	 */
1027
+	public static function remove_label_keep_required_msg($label_html, $required_text)
1028
+	{
1029
+		return $required_text;
1030
+	}
1031
+
1032
+
1033
+
1034
+
1035
+
1036
+	/**
1037
+	 * Simply return sthe HTML for a hidden input of the given name and value.
1038
+	 * @param string $name
1039
+	 * @param string $value
1040
+	 * @return string HTML
1041
+	 */
1042
+	public static function hidden_input($name, $value, $id = '')
1043
+	{
1044
+		$id = ! empty($id) ? $id : $name;
1045
+		return '<input id="' . $id . '" type="hidden" name="' . $name . '" value="' .  $value . '"/>';
1046
+	}
1047
+
1048
+
1049
+
1050
+
1051
+
1052
+	/**
1053
+	 * prep_question
1054
+	 * @param string $question
1055
+	 * @return string
1056
+	 */
1057
+	public static function prep_question($question)
1058
+	{
1059
+		return $question;
1060 1060
 //      $link = '';
1061 1061
 //      // does this label have a help link attached ?
1062 1062
 //      if ( strpos( $question, '<a ' ) !== FALSE ) {
@@ -1068,449 +1068,449 @@  discard block
 block discarded – undo
1068 1068
 //          $link = '<a ' . $link;
1069 1069
 //      }
1070 1070
 //      return htmlspecialchars( trim( stripslashes( str_replace( '&#039;', "'", $question ))), ENT_QUOTES, 'UTF-8' ) . ' ' . $link;
1071
-    }
1072
-
1073
-
1074
-
1075
-
1076
-    /**
1077
-     *  prep_answer
1078
-     * @param mixed $answer
1079
-     * @return string
1080
-     */
1081
-    public static function prep_answer($answer, $use_html_entities = true)
1082
-    {
1083
-        // make sure we convert bools first.  Otherwise (bool) false becomes an empty string which is NOT desired, we want "0".
1084
-        if (is_bool($answer)) {
1085
-            $answer = $answer ? 1 : 0;
1086
-        }
1087
-        $answer = trim(stripslashes(str_replace('&#039;', "'", $answer)));
1088
-        return $use_html_entities ? htmlentities($answer, ENT_QUOTES, 'UTF-8') : $answer;
1089
-    }
1090
-
1091
-
1092
-
1093
-    /**
1094
-     *  prep_answer_options
1095
-     *  @param array $QSOs  array of EE_Question_Option objects
1096
-     *  @return array
1097
-     */
1098
-    public static function prep_answer_options($QSOs = array())
1099
-    {
1100
-        $prepped_answer_options = array();
1101
-        if (is_array($QSOs) && ! empty($QSOs)) {
1102
-            foreach ($QSOs as $key => $QSO) {
1103
-                if (! $QSO instanceof EE_Question_Option) {
1104
-                    $QSO = EE_Question_Option::new_instance(array(
1105
-                        'QSO_value' => is_array($QSO) && isset($QSO['id']) ? (string) $QSO['id'] : (string) $key,
1106
-                        'QSO_desc' => is_array($QSO) && isset($QSO['text']) ? (string) $QSO['text'] : (string) $QSO
1107
-                    ));
1108
-                }
1109
-                if ($QSO->opt_group()) {
1110
-                    $prepped_answer_options[ $QSO->opt_group() ][] = $QSO;
1111
-                } else {
1112
-                    $prepped_answer_options[] = $QSO;
1113
-                }
1114
-            }
1115
-        }
1071
+	}
1072
+
1073
+
1074
+
1075
+
1076
+	/**
1077
+	 *  prep_answer
1078
+	 * @param mixed $answer
1079
+	 * @return string
1080
+	 */
1081
+	public static function prep_answer($answer, $use_html_entities = true)
1082
+	{
1083
+		// make sure we convert bools first.  Otherwise (bool) false becomes an empty string which is NOT desired, we want "0".
1084
+		if (is_bool($answer)) {
1085
+			$answer = $answer ? 1 : 0;
1086
+		}
1087
+		$answer = trim(stripslashes(str_replace('&#039;', "'", $answer)));
1088
+		return $use_html_entities ? htmlentities($answer, ENT_QUOTES, 'UTF-8') : $answer;
1089
+	}
1090
+
1091
+
1092
+
1093
+	/**
1094
+	 *  prep_answer_options
1095
+	 *  @param array $QSOs  array of EE_Question_Option objects
1096
+	 *  @return array
1097
+	 */
1098
+	public static function prep_answer_options($QSOs = array())
1099
+	{
1100
+		$prepped_answer_options = array();
1101
+		if (is_array($QSOs) && ! empty($QSOs)) {
1102
+			foreach ($QSOs as $key => $QSO) {
1103
+				if (! $QSO instanceof EE_Question_Option) {
1104
+					$QSO = EE_Question_Option::new_instance(array(
1105
+						'QSO_value' => is_array($QSO) && isset($QSO['id']) ? (string) $QSO['id'] : (string) $key,
1106
+						'QSO_desc' => is_array($QSO) && isset($QSO['text']) ? (string) $QSO['text'] : (string) $QSO
1107
+					));
1108
+				}
1109
+				if ($QSO->opt_group()) {
1110
+					$prepped_answer_options[ $QSO->opt_group() ][] = $QSO;
1111
+				} else {
1112
+					$prepped_answer_options[] = $QSO;
1113
+				}
1114
+			}
1115
+		}
1116 1116
 //      d( $prepped_answer_options );
1117
-        return $prepped_answer_options;
1118
-    }
1119
-
1120
-
1121
-    /**
1122
-     *  prep_option_value
1123
-     * @param string $option_value
1124
-     * @return string
1125
-     */
1126
-    public static function prep_option_value($option_value)
1127
-    {
1128
-        return esc_attr(trim(stripslashes($option_value)));
1129
-    }
1130
-
1131
-
1132
-
1133
-
1134
-    /**
1135
-     *  prep_required
1136
-     * @param string|array  $required
1137
-     * @return array
1138
-     */
1139
-    public static function prep_required($required = array())
1140
-    {
1141
-        // make sure required is an array
1142
-        $required = is_array($required) ? $required : array();
1143
-        // and set some defaults
1144
-        $required = array_merge(array( 'label' => '', 'class' => '', 'msg' => '' ), $required);
1145
-        return $required;
1146
-    }
1147
-
1148
-
1149
-
1150
-    /**
1151
-     *  get_label_size_class
1152
-     * @param string    $value
1153
-     * @return string
1154
-     */
1155
-    public static function get_label_size_class($value = false)
1156
-    {
1157
-        if ($value === false || $value == '') {
1158
-            return ' class="medium-lbl"';
1159
-        }
1160
-            // determine length of option value
1161
-            $val_size = strlen($value);
1162
-        switch ($val_size) {
1163
-            case $val_size < 3:
1164
-                $size =  ' class="nano-lbl"';
1165
-                break;
1166
-            case $val_size < 6:
1167
-                $size =  ' class="micro-lbl"';
1168
-                break;
1169
-            case $val_size < 12:
1170
-                $size =  ' class="tiny-lbl"';
1171
-                break;
1172
-            case $val_size < 25:
1173
-                $size =  ' class="small-lbl"';
1174
-                break;
1175
-            case $val_size > 100:
1176
-                $size =  ' class="big-lbl"';
1177
-                break;
1178
-            default:
1179
-                $size =  ' class="medium-lbl"';
1180
-                break;
1181
-        }
1182
-        return $size;
1183
-    }
1184
-
1185
-
1186
-
1187
-
1188
-    /**
1189
-     *  _load_system_dropdowns
1190
-     * @param array     $QFI
1191
-     * @return array
1192
-     */
1193
-    private static function _load_system_dropdowns($QFI)
1194
-    {
1195
-        $QST_system = $QFI->get('QST_system');
1196
-        switch ($QST_system) {
1197
-            case 'state':
1198
-                $QFI = self::generate_state_dropdown($QFI);
1199
-                break;
1200
-            case 'country':
1201
-                $QFI = self::generate_country_dropdown($QFI);
1202
-                break;
1203
-            case 'admin-state':
1204
-                $QFI = self::generate_state_dropdown($QFI, true);
1205
-                break;
1206
-            case 'admin-country':
1207
-                $QFI = self::generate_country_dropdown($QFI, true);
1208
-                break;
1209
-        }
1210
-        return $QFI;
1211
-    }
1212
-
1213
-
1214
-
1215
-    /**
1216
-     * This preps dropdowns that are specialized.
1217
-     *
1218
-     * @since  4.6.0
1219
-     *
1220
-     * @param EE_Question_Form_Input $QFI
1221
-     *
1222
-     * @return EE_Question_Form_Input
1223
-     */
1224
-    protected static function _load_specialized_dropdowns($QFI)
1225
-    {
1226
-        switch ($QFI->get('QST_type')) {
1227
-            case 'STATE':
1228
-                $QFI = self::generate_state_dropdown($QFI);
1229
-                break;
1230
-            case 'COUNTRY':
1231
-                $QFI = self::generate_country_dropdown($QFI);
1232
-                break;
1233
-        }
1234
-        return $QFI;
1235
-    }
1236
-
1237
-
1238
-
1239
-    /**
1240
-     *    generate_state_dropdown
1241
-     * @param array $QST
1242
-     * @param bool  $get_all
1243
-     * @return array
1244
-     */
1245
-    public static function generate_state_dropdown($QST, $get_all = false)
1246
-    {
1247
-        $states = $get_all
1248
-            ? EEM_State::instance()->get_all_states()
1249
-            : EEM_State::instance()->get_all_states_of_active_countries();
1250
-        if (! empty($states) && count($states) != count($QST->options())) {
1251
-            $QST->set('QST_type', 'DROPDOWN');
1252
-            // if multiple countries, we'll create option groups within the dropdown
1253
-            foreach ($states as $state) {
1254
-                if ($state instanceof EE_State) {
1255
-                    $QSO = EE_Question_Option::new_instance(array (
1256
-                        'QSO_value' => $state->ID(),
1257
-                        'QSO_desc' => $state->name(),
1258
-                        'QST_ID' => $QST->get('QST_ID'),
1259
-                        'QSO_deleted' => false
1260
-                    ));
1261
-                    // set option group
1262
-                    $QSO->set_opt_group($state->country()->name());
1263
-                    // add option to question
1264
-                    $QST->add_temp_option($QSO);
1265
-                }
1266
-            }
1267
-        }
1268
-        return $QST;
1269
-    }
1270
-
1271
-
1272
-
1273
-    /**
1274
-     *    generate_country_dropdown
1275
-     * @param      $QST
1276
-     * @param bool $get_all
1277
-     * @internal param array $question
1278
-     * @return array
1279
-     */
1280
-    public static function generate_country_dropdown($QST, $get_all = false)
1281
-    {
1282
-        $countries = $get_all ? EEM_Country::instance()->get_all_countries() : EEM_Country::instance()->get_all_active_countries();
1283
-        if ($countries && count($countries) != count($QST->options())) {
1284
-            $QST->set('QST_type', 'DROPDOWN');
1285
-            // now add countries
1286
-            foreach ($countries as $country) {
1287
-                if ($country instanceof EE_Country) {
1288
-                    $QSO = EE_Question_Option::new_instance(array (
1289
-                        'QSO_value' => $country->ID(),
1290
-                        'QSO_desc' => $country->name(),
1291
-                        'QST_ID' => $QST->get('QST_ID'),
1292
-                        'QSO_deleted' => false
1293
-                    ));
1294
-                    $QST->add_temp_option($QSO);
1295
-                }
1296
-            }
1297
-        }
1298
-        return $QST;
1299
-    }
1300
-
1301
-
1302
-
1303
-
1304
-
1305
-    /**
1306
-     *  generates options for a month dropdown selector with numbers from 01 to 12
1307
-     *  @return array()
1308
-     */
1309
-    public static function two_digit_months_dropdown_options()
1310
-    {
1311
-        $options = array();
1312
-        for ($x = 1; $x <= 12; $x++) {
1313
-            $mm = str_pad($x, 2, '0', STR_PAD_LEFT);
1314
-            $options[ (string) $mm ] = (string) $mm;
1315
-        }
1316
-        return EEH_Form_Fields::prep_answer_options($options);
1317
-    }
1318
-
1319
-
1320
-
1321
-
1322
-
1323
-    /**
1324
-     *  generates a year dropdown selector with numbers for the next ten years
1325
-     *  @return object
1326
-     */
1327
-    public static function next_decade_two_digit_year_dropdown_options()
1328
-    {
1329
-        $options = array();
1330
-        $current_year = date('y');
1331
-        $next_decade = $current_year + 10;
1332
-        for ($x = $current_year; $x <= $next_decade; $x++) {
1333
-            $yy = str_pad($x, 2, '0', STR_PAD_LEFT);
1334
-            $options[ (string) $yy ] = (string) $yy;
1335
-        }
1336
-        return EEH_Form_Fields::prep_answer_options($options);
1337
-    }
1338
-
1339
-
1340
-
1341
-
1342
-
1343
-    /**
1344
-     * generates a month/year dropdown selector for all registrations matching the given criteria.  Typically used for list table filter.
1345
-     * @param  string  $cur_date     any currently selected date can be entered here.
1346
-     * @param  string  $status       Registration status
1347
-     * @param  integer $evt_category Event Category ID if the Event Category filter is selected
1348
-     * @return string                html
1349
-     */
1350
-    public static function generate_registration_months_dropdown($cur_date = '', $status = '', $evt_category = 0)
1351
-    {
1352
-        $_where = array();
1353
-        if (!empty($status)) {
1354
-            $_where['STS_ID'] = $status;
1355
-        }
1356
-
1357
-        if ($evt_category > 0) {
1358
-            $_where['Event.Term_Taxonomy.term_id'] = $evt_category;
1359
-        }
1360
-
1361
-        $regdtts = EEM_Registration::instance()->get_reg_months_and_years($_where);
1362
-
1363
-        // setup vals for select input helper
1364
-        $options = array(
1365
-            0 => array(
1366
-                'text' => __('Select a Month/Year', 'event_espresso'),
1367
-                'id' => ''
1368
-                )
1369
-            );
1370
-
1371
-        foreach ($regdtts as $regdtt) {
1372
-            $date = $regdtt->reg_month . ' ' . $regdtt->reg_year;
1373
-            $options[] = array(
1374
-                'text' => $date,
1375
-                'id' => $date
1376
-                );
1377
-        }
1378
-
1379
-        return self::select_input('month_range', $options, $cur_date, '', 'wide');
1380
-    }
1381
-
1382
-
1383
-
1384
-    /**
1385
-     * generates a month/year dropdown selector for all events matching the given criteria
1386
-     * Typically used for list table filter
1387
-     * @param  string $cur_date          any currently selected date can be entered here.
1388
-     * @param  string $status            "view" (i.e. all, today, month, draft)
1389
-     * @param  int    $evt_category      category event belongs to
1390
-     * @param  string $evt_active_status "upcoming", "expired", "active", or "inactive"
1391
-     * @return string                    html
1392
-     */
1393
-    public static function generate_event_months_dropdown($cur_date = '', $status = '', $evt_category = '', $evt_active_status = '')
1394
-    {
1395
-        // determine what post_status our condition will have for the query.
1396
-        // phpcs:disable PSR2.ControlStructures.SwitchDeclaration.TerminatingComment
1397
-        switch ($status) {
1398
-            case 'month':
1399
-            case 'today':
1400
-            case null:
1401
-            case 'all':
1402
-                $where['Event.status'] = array( 'NOT IN', array('trash') );
1403
-                break;
1404
-
1405
-            case 'draft':
1406
-                $where['Event.status'] = array( 'IN', array('draft', 'auto-draft') );
1407
-
1408
-            default:
1409
-                $where['Event.status'] = $status;
1410
-        }
1411
-
1412
-        // phpcs:enable
1413
-
1414
-        // categories?
1415
-
1117
+		return $prepped_answer_options;
1118
+	}
1119
+
1120
+
1121
+	/**
1122
+	 *  prep_option_value
1123
+	 * @param string $option_value
1124
+	 * @return string
1125
+	 */
1126
+	public static function prep_option_value($option_value)
1127
+	{
1128
+		return esc_attr(trim(stripslashes($option_value)));
1129
+	}
1130
+
1131
+
1132
+
1133
+
1134
+	/**
1135
+	 *  prep_required
1136
+	 * @param string|array  $required
1137
+	 * @return array
1138
+	 */
1139
+	public static function prep_required($required = array())
1140
+	{
1141
+		// make sure required is an array
1142
+		$required = is_array($required) ? $required : array();
1143
+		// and set some defaults
1144
+		$required = array_merge(array( 'label' => '', 'class' => '', 'msg' => '' ), $required);
1145
+		return $required;
1146
+	}
1147
+
1148
+
1149
+
1150
+	/**
1151
+	 *  get_label_size_class
1152
+	 * @param string    $value
1153
+	 * @return string
1154
+	 */
1155
+	public static function get_label_size_class($value = false)
1156
+	{
1157
+		if ($value === false || $value == '') {
1158
+			return ' class="medium-lbl"';
1159
+		}
1160
+			// determine length of option value
1161
+			$val_size = strlen($value);
1162
+		switch ($val_size) {
1163
+			case $val_size < 3:
1164
+				$size =  ' class="nano-lbl"';
1165
+				break;
1166
+			case $val_size < 6:
1167
+				$size =  ' class="micro-lbl"';
1168
+				break;
1169
+			case $val_size < 12:
1170
+				$size =  ' class="tiny-lbl"';
1171
+				break;
1172
+			case $val_size < 25:
1173
+				$size =  ' class="small-lbl"';
1174
+				break;
1175
+			case $val_size > 100:
1176
+				$size =  ' class="big-lbl"';
1177
+				break;
1178
+			default:
1179
+				$size =  ' class="medium-lbl"';
1180
+				break;
1181
+		}
1182
+		return $size;
1183
+	}
1184
+
1185
+
1186
+
1187
+
1188
+	/**
1189
+	 *  _load_system_dropdowns
1190
+	 * @param array     $QFI
1191
+	 * @return array
1192
+	 */
1193
+	private static function _load_system_dropdowns($QFI)
1194
+	{
1195
+		$QST_system = $QFI->get('QST_system');
1196
+		switch ($QST_system) {
1197
+			case 'state':
1198
+				$QFI = self::generate_state_dropdown($QFI);
1199
+				break;
1200
+			case 'country':
1201
+				$QFI = self::generate_country_dropdown($QFI);
1202
+				break;
1203
+			case 'admin-state':
1204
+				$QFI = self::generate_state_dropdown($QFI, true);
1205
+				break;
1206
+			case 'admin-country':
1207
+				$QFI = self::generate_country_dropdown($QFI, true);
1208
+				break;
1209
+		}
1210
+		return $QFI;
1211
+	}
1212
+
1213
+
1214
+
1215
+	/**
1216
+	 * This preps dropdowns that are specialized.
1217
+	 *
1218
+	 * @since  4.6.0
1219
+	 *
1220
+	 * @param EE_Question_Form_Input $QFI
1221
+	 *
1222
+	 * @return EE_Question_Form_Input
1223
+	 */
1224
+	protected static function _load_specialized_dropdowns($QFI)
1225
+	{
1226
+		switch ($QFI->get('QST_type')) {
1227
+			case 'STATE':
1228
+				$QFI = self::generate_state_dropdown($QFI);
1229
+				break;
1230
+			case 'COUNTRY':
1231
+				$QFI = self::generate_country_dropdown($QFI);
1232
+				break;
1233
+		}
1234
+		return $QFI;
1235
+	}
1236
+
1237
+
1238
+
1239
+	/**
1240
+	 *    generate_state_dropdown
1241
+	 * @param array $QST
1242
+	 * @param bool  $get_all
1243
+	 * @return array
1244
+	 */
1245
+	public static function generate_state_dropdown($QST, $get_all = false)
1246
+	{
1247
+		$states = $get_all
1248
+			? EEM_State::instance()->get_all_states()
1249
+			: EEM_State::instance()->get_all_states_of_active_countries();
1250
+		if (! empty($states) && count($states) != count($QST->options())) {
1251
+			$QST->set('QST_type', 'DROPDOWN');
1252
+			// if multiple countries, we'll create option groups within the dropdown
1253
+			foreach ($states as $state) {
1254
+				if ($state instanceof EE_State) {
1255
+					$QSO = EE_Question_Option::new_instance(array (
1256
+						'QSO_value' => $state->ID(),
1257
+						'QSO_desc' => $state->name(),
1258
+						'QST_ID' => $QST->get('QST_ID'),
1259
+						'QSO_deleted' => false
1260
+					));
1261
+					// set option group
1262
+					$QSO->set_opt_group($state->country()->name());
1263
+					// add option to question
1264
+					$QST->add_temp_option($QSO);
1265
+				}
1266
+			}
1267
+		}
1268
+		return $QST;
1269
+	}
1270
+
1271
+
1272
+
1273
+	/**
1274
+	 *    generate_country_dropdown
1275
+	 * @param      $QST
1276
+	 * @param bool $get_all
1277
+	 * @internal param array $question
1278
+	 * @return array
1279
+	 */
1280
+	public static function generate_country_dropdown($QST, $get_all = false)
1281
+	{
1282
+		$countries = $get_all ? EEM_Country::instance()->get_all_countries() : EEM_Country::instance()->get_all_active_countries();
1283
+		if ($countries && count($countries) != count($QST->options())) {
1284
+			$QST->set('QST_type', 'DROPDOWN');
1285
+			// now add countries
1286
+			foreach ($countries as $country) {
1287
+				if ($country instanceof EE_Country) {
1288
+					$QSO = EE_Question_Option::new_instance(array (
1289
+						'QSO_value' => $country->ID(),
1290
+						'QSO_desc' => $country->name(),
1291
+						'QST_ID' => $QST->get('QST_ID'),
1292
+						'QSO_deleted' => false
1293
+					));
1294
+					$QST->add_temp_option($QSO);
1295
+				}
1296
+			}
1297
+		}
1298
+		return $QST;
1299
+	}
1300
+
1301
+
1302
+
1303
+
1304
+
1305
+	/**
1306
+	 *  generates options for a month dropdown selector with numbers from 01 to 12
1307
+	 *  @return array()
1308
+	 */
1309
+	public static function two_digit_months_dropdown_options()
1310
+	{
1311
+		$options = array();
1312
+		for ($x = 1; $x <= 12; $x++) {
1313
+			$mm = str_pad($x, 2, '0', STR_PAD_LEFT);
1314
+			$options[ (string) $mm ] = (string) $mm;
1315
+		}
1316
+		return EEH_Form_Fields::prep_answer_options($options);
1317
+	}
1318
+
1319
+
1320
+
1321
+
1322
+
1323
+	/**
1324
+	 *  generates a year dropdown selector with numbers for the next ten years
1325
+	 *  @return object
1326
+	 */
1327
+	public static function next_decade_two_digit_year_dropdown_options()
1328
+	{
1329
+		$options = array();
1330
+		$current_year = date('y');
1331
+		$next_decade = $current_year + 10;
1332
+		for ($x = $current_year; $x <= $next_decade; $x++) {
1333
+			$yy = str_pad($x, 2, '0', STR_PAD_LEFT);
1334
+			$options[ (string) $yy ] = (string) $yy;
1335
+		}
1336
+		return EEH_Form_Fields::prep_answer_options($options);
1337
+	}
1338
+
1339
+
1340
+
1341
+
1342
+
1343
+	/**
1344
+	 * generates a month/year dropdown selector for all registrations matching the given criteria.  Typically used for list table filter.
1345
+	 * @param  string  $cur_date     any currently selected date can be entered here.
1346
+	 * @param  string  $status       Registration status
1347
+	 * @param  integer $evt_category Event Category ID if the Event Category filter is selected
1348
+	 * @return string                html
1349
+	 */
1350
+	public static function generate_registration_months_dropdown($cur_date = '', $status = '', $evt_category = 0)
1351
+	{
1352
+		$_where = array();
1353
+		if (!empty($status)) {
1354
+			$_where['STS_ID'] = $status;
1355
+		}
1356
+
1357
+		if ($evt_category > 0) {
1358
+			$_where['Event.Term_Taxonomy.term_id'] = $evt_category;
1359
+		}
1360
+
1361
+		$regdtts = EEM_Registration::instance()->get_reg_months_and_years($_where);
1362
+
1363
+		// setup vals for select input helper
1364
+		$options = array(
1365
+			0 => array(
1366
+				'text' => __('Select a Month/Year', 'event_espresso'),
1367
+				'id' => ''
1368
+				)
1369
+			);
1370
+
1371
+		foreach ($regdtts as $regdtt) {
1372
+			$date = $regdtt->reg_month . ' ' . $regdtt->reg_year;
1373
+			$options[] = array(
1374
+				'text' => $date,
1375
+				'id' => $date
1376
+				);
1377
+		}
1378
+
1379
+		return self::select_input('month_range', $options, $cur_date, '', 'wide');
1380
+	}
1381
+
1382
+
1383
+
1384
+	/**
1385
+	 * generates a month/year dropdown selector for all events matching the given criteria
1386
+	 * Typically used for list table filter
1387
+	 * @param  string $cur_date          any currently selected date can be entered here.
1388
+	 * @param  string $status            "view" (i.e. all, today, month, draft)
1389
+	 * @param  int    $evt_category      category event belongs to
1390
+	 * @param  string $evt_active_status "upcoming", "expired", "active", or "inactive"
1391
+	 * @return string                    html
1392
+	 */
1393
+	public static function generate_event_months_dropdown($cur_date = '', $status = '', $evt_category = '', $evt_active_status = '')
1394
+	{
1395
+		// determine what post_status our condition will have for the query.
1396
+		// phpcs:disable PSR2.ControlStructures.SwitchDeclaration.TerminatingComment
1397
+		switch ($status) {
1398
+			case 'month':
1399
+			case 'today':
1400
+			case null:
1401
+			case 'all':
1402
+				$where['Event.status'] = array( 'NOT IN', array('trash') );
1403
+				break;
1404
+
1405
+			case 'draft':
1406
+				$where['Event.status'] = array( 'IN', array('draft', 'auto-draft') );
1407
+
1408
+			default:
1409
+				$where['Event.status'] = $status;
1410
+		}
1411
+
1412
+		// phpcs:enable
1413
+
1414
+		// categories?
1415
+
1416 1416
 
1417
-        if (!empty($evt_category)) {
1418
-            $where['Event.Term_Taxonomy.taxonomy'] = 'espresso_event_categories';
1419
-            $where['Event.Term_Taxonomy.term_id'] = $evt_category;
1420
-        }
1417
+		if (!empty($evt_category)) {
1418
+			$where['Event.Term_Taxonomy.taxonomy'] = 'espresso_event_categories';
1419
+			$where['Event.Term_Taxonomy.term_id'] = $evt_category;
1420
+		}
1421 1421
 
1422 1422
 
1423 1423
 //      $where['DTT_is_primary'] = 1;
1424 1424
 
1425
-        $DTTS = EE_Registry::instance()->load_model('Datetime')->get_dtt_months_and_years($where, $evt_active_status);
1426
-
1427
-        // let's setup vals for select input helper
1428
-        $options = array(
1429
-            0 => array(
1430
-                'text' => __('Select a Month/Year', 'event_espresso'),
1431
-                'id' => ""
1432
-                )
1433
-            );
1434
-
1435
-
1436
-
1437
-        // translate month and date
1438
-        global $wp_locale;
1439
-
1440
-        foreach ($DTTS as $DTT) {
1441
-            $localized_date = $wp_locale->get_month($DTT->dtt_month_num) . ' ' . $DTT->dtt_year;
1442
-            $id = $DTT->dtt_month . ' ' . $DTT->dtt_year;
1443
-            $options[] = array(
1444
-                'text' => $localized_date,
1445
-                'id' => $id
1446
-                );
1447
-        }
1448
-
1449
-
1450
-        return self::select_input('month_range', $options, $cur_date, '', 'wide');
1451
-    }
1452
-
1453
-
1454
-
1455
-    /**
1456
-     * generates the dropdown selector for event categories
1457
-     * typically used as a filter on list tables.
1458
-     * @param  integer $current_cat currently selected category
1459
-     * @return string               html for dropdown
1460
-     */
1461
-    public static function generate_event_category_dropdown($current_cat = -1)
1462
-    {
1463
-        $categories = EEM_Term::instance()->get_all_ee_categories(true);
1464
-        $options = array(
1465
-            '0' => array(
1466
-                'text' => __('All Categories', 'event_espresso'),
1467
-                'id' => -1
1468
-                )
1469
-            );
1470
-
1471
-        // setup categories for dropdown
1472
-        foreach ($categories as $category) {
1473
-            $options[] = array(
1474
-                'text' => $category->get('name'),
1475
-                'id' => $category->ID()
1476
-                );
1477
-        }
1478
-
1479
-        return self::select_input('EVT_CAT', $options, $current_cat);
1480
-    }
1481
-
1482
-
1483
-
1484
-    /**
1485
-     *    generate a submit button with or without it's own microform
1486
-     *    this is the only way to create buttons that are compatible across all themes
1487
-     *
1488
-     * @access    public
1489
-     * @param    string   $url              - the form action
1490
-     * @param    string   $ID               - some kind of unique ID, appended with "-sbmt" for the input and "-frm" for the form
1491
-     * @param    string   $class            - css classes (separated by spaces if more than one)
1492
-     * @param    string   $text             - what appears on the button
1493
-     * @param    string   $nonce_action     - if using nonces
1494
-     * @param    bool|string $input_only       - whether to print form header and footer. TRUE returns the input without the form
1495
-     * @param    string   $extra_attributes - any extra attributes that need to be attached to the form input
1496
-     * @return    void
1497
-     */
1498
-    public static function submit_button($url = '', $ID = '', $class = '', $text = '', $nonce_action = '', $input_only = false, $extra_attributes = '')
1499
-    {
1500
-        $btn = '';
1501
-        if (empty($url) || empty($ID)) {
1502
-            return $btn;
1503
-        }
1504
-        $text = ! empty($text) ? $text : __('Submit', 'event_espresso');
1505
-        $btn .= '<input id="' . $ID . '-btn" class="' . $class . '" type="submit" value="' . $text . '" ' . $extra_attributes . '/>';
1506
-        if (! $input_only) {
1507
-            $btn_frm = '<form id="' . $ID . '-frm" method="POST" action="' . $url . '">';
1508
-            $btn_frm .= ! empty($nonce_action) ? wp_nonce_field($nonce_action, $nonce_action . '_nonce', true, false) : '';
1509
-            $btn_frm .= $btn;
1510
-            $btn_frm .= '</form>';
1511
-            $btn = $btn_frm;
1512
-            unset($btn_frm);
1513
-        }
1514
-        return $btn;
1515
-    }
1425
+		$DTTS = EE_Registry::instance()->load_model('Datetime')->get_dtt_months_and_years($where, $evt_active_status);
1426
+
1427
+		// let's setup vals for select input helper
1428
+		$options = array(
1429
+			0 => array(
1430
+				'text' => __('Select a Month/Year', 'event_espresso'),
1431
+				'id' => ""
1432
+				)
1433
+			);
1434
+
1435
+
1436
+
1437
+		// translate month and date
1438
+		global $wp_locale;
1439
+
1440
+		foreach ($DTTS as $DTT) {
1441
+			$localized_date = $wp_locale->get_month($DTT->dtt_month_num) . ' ' . $DTT->dtt_year;
1442
+			$id = $DTT->dtt_month . ' ' . $DTT->dtt_year;
1443
+			$options[] = array(
1444
+				'text' => $localized_date,
1445
+				'id' => $id
1446
+				);
1447
+		}
1448
+
1449
+
1450
+		return self::select_input('month_range', $options, $cur_date, '', 'wide');
1451
+	}
1452
+
1453
+
1454
+
1455
+	/**
1456
+	 * generates the dropdown selector for event categories
1457
+	 * typically used as a filter on list tables.
1458
+	 * @param  integer $current_cat currently selected category
1459
+	 * @return string               html for dropdown
1460
+	 */
1461
+	public static function generate_event_category_dropdown($current_cat = -1)
1462
+	{
1463
+		$categories = EEM_Term::instance()->get_all_ee_categories(true);
1464
+		$options = array(
1465
+			'0' => array(
1466
+				'text' => __('All Categories', 'event_espresso'),
1467
+				'id' => -1
1468
+				)
1469
+			);
1470
+
1471
+		// setup categories for dropdown
1472
+		foreach ($categories as $category) {
1473
+			$options[] = array(
1474
+				'text' => $category->get('name'),
1475
+				'id' => $category->ID()
1476
+				);
1477
+		}
1478
+
1479
+		return self::select_input('EVT_CAT', $options, $current_cat);
1480
+	}
1481
+
1482
+
1483
+
1484
+	/**
1485
+	 *    generate a submit button with or without it's own microform
1486
+	 *    this is the only way to create buttons that are compatible across all themes
1487
+	 *
1488
+	 * @access    public
1489
+	 * @param    string   $url              - the form action
1490
+	 * @param    string   $ID               - some kind of unique ID, appended with "-sbmt" for the input and "-frm" for the form
1491
+	 * @param    string   $class            - css classes (separated by spaces if more than one)
1492
+	 * @param    string   $text             - what appears on the button
1493
+	 * @param    string   $nonce_action     - if using nonces
1494
+	 * @param    bool|string $input_only       - whether to print form header and footer. TRUE returns the input without the form
1495
+	 * @param    string   $extra_attributes - any extra attributes that need to be attached to the form input
1496
+	 * @return    void
1497
+	 */
1498
+	public static function submit_button($url = '', $ID = '', $class = '', $text = '', $nonce_action = '', $input_only = false, $extra_attributes = '')
1499
+	{
1500
+		$btn = '';
1501
+		if (empty($url) || empty($ID)) {
1502
+			return $btn;
1503
+		}
1504
+		$text = ! empty($text) ? $text : __('Submit', 'event_espresso');
1505
+		$btn .= '<input id="' . $ID . '-btn" class="' . $class . '" type="submit" value="' . $text . '" ' . $extra_attributes . '/>';
1506
+		if (! $input_only) {
1507
+			$btn_frm = '<form id="' . $ID . '-frm" method="POST" action="' . $url . '">';
1508
+			$btn_frm .= ! empty($nonce_action) ? wp_nonce_field($nonce_action, $nonce_action . '_nonce', true, false) : '';
1509
+			$btn_frm .= $btn;
1510
+			$btn_frm .= '</form>';
1511
+			$btn = $btn_frm;
1512
+			unset($btn_frm);
1513
+		}
1514
+		return $btn;
1515
+	}
1516 1516
 }
Please login to merge, or discard this patch.
Spacing   +184 added lines, -184 removed lines patch added patch discarded remove patch
@@ -90,10 +90,10 @@  discard block
 block discarded – undo
90 90
             $required = isset($input_value['required']) && $input_value['required'] ? ' <span>*</span>: ' : ': ';
91 91
             // and the css class "required"
92 92
             $css_class = isset($input_value['css_class']) ? $input_value['css_class'] : '';
93
-            $styles = $input_value['required'] ? 'required ' . $css_class : $css_class;
93
+            $styles = $input_value['required'] ? 'required '.$css_class : $css_class;
94 94
 
95
-            $field_id = ($id) ? $id . '-' . $input_key : $input_key;
96
-            $tabindex = !empty($input_value['tabindex']) ? ' tabindex="' . $input_value['tabindex'] . '"' : '';
95
+            $field_id = ($id) ? $id.'-'.$input_key : $input_key;
96
+            $tabindex = ! empty($input_value['tabindex']) ? ' tabindex="'.$input_value['tabindex'].'"' : '';
97 97
 
98 98
             // rows or cols?
99 99
             $rows = isset($input_value['rows']) ? $input_value['rows'] : '10';
@@ -102,21 +102,21 @@  discard block
 block discarded – undo
102 102
             // any content?
103 103
             $append_content = $input_value['append_content'];
104 104
 
105
-            $output .= (!$close) ? '<ul>' : '';
105
+            $output .= ( ! $close) ? '<ul>' : '';
106 106
             $output .= '<li>';
107 107
 
108 108
             // what type of input are we dealing with ?
109 109
             switch ($input_value['input']) {
110 110
                 // text inputs
111 111
                 case 'text':
112
-                    $output .= "\n\t\t\t" . '<label for="' . $field_id . '">' . $input_value['label'] . $required . '</label>';
113
-                    $output .= "\n\t\t\t" . '<input id="' . $field_id . '" class="' . $styles . '" type="text" value="' . esc_textarea($input_value['value']) . '" name="' . $input_value['name'] . '"' . $tabindex . '>';
112
+                    $output .= "\n\t\t\t".'<label for="'.$field_id.'">'.$input_value['label'].$required.'</label>';
113
+                    $output .= "\n\t\t\t".'<input id="'.$field_id.'" class="'.$styles.'" type="text" value="'.esc_textarea($input_value['value']).'" name="'.$input_value['name'].'"'.$tabindex.'>';
114 114
                     break;
115 115
 
116 116
                 // dropdowns
117 117
                 case 'select':
118
-                    $output .= "\n\t\t\t" . '<label for="' . $field_id . '">' . $input_value['label'] . $required . '</label>';
119
-                    $output .= "\n\t\t\t" . '<select id="' . $field_id . '" class="' . $styles . '" name="' . $input_value['name'] . '"' . $tabindex . '>';
118
+                    $output .= "\n\t\t\t".'<label for="'.$field_id.'">'.$input_value['label'].$required.'</label>';
119
+                    $output .= "\n\t\t\t".'<select id="'.$field_id.'" class="'.$styles.'" name="'.$input_value['name'].'"'.$tabindex.'>';
120 120
 
121 121
                     if (is_array($input_value['options'])) {
122 122
                         $options = $input_value['options'];
@@ -127,27 +127,27 @@  discard block
 block discarded – undo
127 127
                     foreach ($options as $key => $value) {
128 128
                         $selected = isset($input_value['value']) && $input_value['value'] == $key ? 'selected=selected' : '';
129 129
                         // $key = str_replace( ' ', '_', sanitize_key( $value ));
130
-                        $output .= "\n\t\t\t\t" . '<option ' . $selected . ' value="' . $key . '">' . $value . '</option>';
130
+                        $output .= "\n\t\t\t\t".'<option '.$selected.' value="'.$key.'">'.$value.'</option>';
131 131
                     }
132
-                    $output .= "\n\t\t\t" . '</select>';
132
+                    $output .= "\n\t\t\t".'</select>';
133 133
 
134 134
                     break;
135 135
 
136 136
                 case 'textarea':
137
-                    $output .= "\n\t\t\t" . '<label for="' . $field_id . '">' . $input_value['label'] . $required . '</label>';
138
-                    $output .= "\n\t\t\t" . '<textarea id="' . $field_id . '" class="' . $styles . '" rows="' . $rows . '" cols="' . $cols . '" name="' . $input_value['name'] . '"' . $tabindex . '>' . esc_textarea($input_value['value']) . '</textarea>';
137
+                    $output .= "\n\t\t\t".'<label for="'.$field_id.'">'.$input_value['label'].$required.'</label>';
138
+                    $output .= "\n\t\t\t".'<textarea id="'.$field_id.'" class="'.$styles.'" rows="'.$rows.'" cols="'.$cols.'" name="'.$input_value['name'].'"'.$tabindex.'>'.esc_textarea($input_value['value']).'</textarea>';
139 139
                     break;
140 140
 
141 141
                 case 'hidden':
142 142
                     $close = false;
143 143
                     $output .= "</li></ul>";
144
-                    $output .= "\n\t\t\t" . '<input id="' . $field_id . '" type="hidden" name="' . $input_value['name'] . '" value="' . $input_value['value'] . '">';
144
+                    $output .= "\n\t\t\t".'<input id="'.$field_id.'" type="hidden" name="'.$input_value['name'].'" value="'.$input_value['value'].'">';
145 145
                     break;
146 146
 
147 147
                 case 'checkbox':
148
-                    $checked = ( $input_value['value'] == 1 ) ? 'checked="checked"' : '';
149
-                    $output .= "\n\t\t\t" . '<label for="' . $field_id . '">' . $input_value['label'] . $required . '</label>';
150
-                    $output .= "\n\t\t\t" . '<input id="' . $field_id . '" type="checkbox" name="' . $input_value['name'] . '" value="1"' . $checked . $tabindex . ' />';
148
+                    $checked = ($input_value['value'] == 1) ? 'checked="checked"' : '';
149
+                    $output .= "\n\t\t\t".'<label for="'.$field_id.'">'.$input_value['label'].$required.'</label>';
150
+                    $output .= "\n\t\t\t".'<input id="'.$field_id.'" type="checkbox" name="'.$input_value['name'].'" value="1"'.$checked.$tabindex.' />';
151 151
                     break;
152 152
 
153 153
                 case 'wp_editor':
@@ -160,7 +160,7 @@  discard block
 block discarded – undo
160 160
                     );
161 161
                     $output .= '</li>';
162 162
                     $output .= '</ul>';
163
-                    $output .= '<h4>' . $input_value['label'] . '</h4>';
163
+                    $output .= '<h4>'.$input_value['label'].'</h4>';
164 164
                     if ($append_content) {
165 165
                         $output .= $append_content;
166 166
                     }
@@ -232,17 +232,17 @@  discard block
 block discarded – undo
232 232
             $_fields = wp_parse_args($field_atts, $defaults);
233 233
             extract($_fields);
234 234
             // generate label
235
-            $label = empty($label) ? '' : '<label for="' . $id . '">' . $label . '</label>';
235
+            $label = empty($label) ? '' : '<label for="'.$id.'">'.$label.'</label>';
236 236
             // generate field name
237
-            $f_name = !empty($unique_id) ? $field_name . '[' . $unique_id . ']' : $field_name;
237
+            $f_name = ! empty($unique_id) ? $field_name.'['.$unique_id.']' : $field_name;
238 238
 
239 239
             // tabindex
240
-            $tabindex_str = !empty($tabindex) ? ' tabindex="' . $tabindex . '"' : '';
240
+            $tabindex_str = ! empty($tabindex) ? ' tabindex="'.$tabindex.'"' : '';
241 241
 
242 242
             // we determine what we're building based on the type
243 243
             switch ($type) {
244 244
                 case 'textarea':
245
-                        $fld = '<textarea id="' . $id . '" class="' . $class . '" rows="' . $dimensions[1] . '" cols="' . $dimensions[0] . '" name="' . $f_name . '"' . $tabindex_str . '>' . $value . '</textarea>';
245
+                        $fld = '<textarea id="'.$id.'" class="'.$class.'" rows="'.$dimensions[1].'" cols="'.$dimensions[0].'" name="'.$f_name.'"'.$tabindex_str.'>'.$value.'</textarea>';
246 246
                         $fld .= $extra_desc;
247 247
                     break;
248 248
 
@@ -250,16 +250,16 @@  discard block
 block discarded – undo
250 250
                         $c_input = '';
251 251
                     if (is_array($value)) {
252 252
                         foreach ($value as $key => $val) {
253
-                            $c_id = $field_name . '_' . $value;
254
-                            $c_class = isset($classes[ $key ]) ? ' class="' . $classes[ $key ] . '" ' : '';
255
-                            $c_label = isset($labels[ $key ]) ? '<label for="' . $c_id . '">' . $labels[ $key ] . '</label>' : '';
256
-                            $checked = !empty($default) && $default == $val ? ' checked="checked" ' : '';
257
-                            $c_input .= '<input name="' . $f_name . '[]" type="checkbox" id="' . $c_id . '"' . $c_class . 'value="' . $val . '"' . $checked . $tabindex_str . ' />' . "\n" . $c_label;
253
+                            $c_id = $field_name.'_'.$value;
254
+                            $c_class = isset($classes[$key]) ? ' class="'.$classes[$key].'" ' : '';
255
+                            $c_label = isset($labels[$key]) ? '<label for="'.$c_id.'">'.$labels[$key].'</label>' : '';
256
+                            $checked = ! empty($default) && $default == $val ? ' checked="checked" ' : '';
257
+                            $c_input .= '<input name="'.$f_name.'[]" type="checkbox" id="'.$c_id.'"'.$c_class.'value="'.$val.'"'.$checked.$tabindex_str.' />'."\n".$c_label;
258 258
                         }
259 259
                         $fld = $c_input;
260 260
                     } else {
261
-                        $checked = !empty($default) && $default == $val ? 'checked="checked" ' : '';
262
-                        $fld = '<input name="' . $f_name . '" type="checkbox" id="' . $id . '" class="' . $class . '" value="' . $value . '"' . $checked . $tabindex_str . ' />' . "\n";
261
+                        $checked = ! empty($default) && $default == $val ? 'checked="checked" ' : '';
262
+                        $fld = '<input name="'.$f_name.'" type="checkbox" id="'.$id.'" class="'.$class.'" value="'.$value.'"'.$checked.$tabindex_str.' />'."\n";
263 263
                     }
264 264
                     break;
265 265
 
@@ -267,28 +267,28 @@  discard block
 block discarded – undo
267 267
                         $c_input = '';
268 268
                     if (is_array($value)) {
269 269
                         foreach ($value as $key => $val) {
270
-                            $c_id = $field_name . '_' . $value;
271
-                            $c_class = isset($classes[ $key ]) ? 'class="' . $classes[ $key ] . '" ' : '';
272
-                            $c_label = isset($labels[ $key ]) ? '<label for="' . $c_id . '">' . $labels[ $key ] . '</label>' : '';
273
-                            $checked = !empty($default) && $default == $val ? ' checked="checked" ' : '';
274
-                            $c_input .= '<input name="' . $f_name . '" type="checkbox" id="' . $c_id . '"' . $c_class . 'value="' . $val . '"' . $checked . $tabindex_str . ' />' . "\n" . $c_label;
270
+                            $c_id = $field_name.'_'.$value;
271
+                            $c_class = isset($classes[$key]) ? 'class="'.$classes[$key].'" ' : '';
272
+                            $c_label = isset($labels[$key]) ? '<label for="'.$c_id.'">'.$labels[$key].'</label>' : '';
273
+                            $checked = ! empty($default) && $default == $val ? ' checked="checked" ' : '';
274
+                            $c_input .= '<input name="'.$f_name.'" type="checkbox" id="'.$c_id.'"'.$c_class.'value="'.$val.'"'.$checked.$tabindex_str.' />'."\n".$c_label;
275 275
                         }
276 276
                         $fld = $c_input;
277 277
                     } else {
278
-                        $checked = !empty($default) && $default == $val ? 'checked="checked" ' : '';
279
-                        $fld = '<input name="' . $f_name . '" type="checkbox" id="' . $id . '" class="' . $class . '" value="' . $value . '"' . $checked . $tabindex_str . ' />' . "\n";
278
+                        $checked = ! empty($default) && $default == $val ? 'checked="checked" ' : '';
279
+                        $fld = '<input name="'.$f_name.'" type="checkbox" id="'.$id.'" class="'.$class.'" value="'.$value.'"'.$checked.$tabindex_str.' />'."\n";
280 280
                     }
281 281
                     break;
282 282
 
283 283
                 case 'hidden':
284
-                        $fld = '<input name="' . $f_name . '" type="hidden" id="' . $id . '" class="' . $class . '" value="' . $value . '" />' . "\n";
284
+                        $fld = '<input name="'.$f_name.'" type="hidden" id="'.$id.'" class="'.$class.'" value="'.$value.'" />'."\n";
285 285
                     break;
286 286
 
287 287
                 case 'select':
288
-                        $fld = '<select name="' . $f_name . '" class="' . $class . '" id="' . $id . '"' . $tabindex_str . '>' . "\n";
288
+                        $fld = '<select name="'.$f_name.'" class="'.$class.'" id="'.$id.'"'.$tabindex_str.'>'."\n";
289 289
                     foreach ($value as $key => $val) {
290
-                        $checked = !empty($default) && $default == $val ? ' selected="selected"' : '';
291
-                        $fld .= "\t" . '<option value="' . $val . '"' . $checked . '>' . $labels[ $key ] . '</option>' . "\n";
290
+                        $checked = ! empty($default) && $default == $val ? ' selected="selected"' : '';
291
+                        $fld .= "\t".'<option value="'.$val.'"'.$checked.'>'.$labels[$key].'</option>'."\n";
292 292
                     }
293 293
                         $fld .= '</select>';
294 294
                     break;
@@ -309,11 +309,11 @@  discard block
 block discarded – undo
309 309
                     break;
310 310
 
311 311
                 default: // 'text fields'
312
-                        $fld = '<input name="' . $f_name . '" type="text" id="' . $id . '" class="' . $class . '" value="' . $value . '"' . $tabindex_str . ' />' . "\n";
312
+                        $fld = '<input name="'.$f_name.'" type="text" id="'.$id.'" class="'.$class.'" value="'.$value.'"'.$tabindex_str.' />'."\n";
313 313
                         $fld .= $extra_desc;
314 314
             }
315 315
 
316
-            $form_fields[ $field_name ] = array( 'label' => $label, 'field' => $fld );
316
+            $form_fields[$field_name] = array('label' => $label, 'field' => $fld);
317 317
         }
318 318
 
319 319
         return $form_fields;
@@ -343,25 +343,25 @@  discard block
 block discarded – undo
343 343
     public static function select_input($name, $values, $default = '', $parameters = '', $class = '', $autosize = true)
344 344
     {
345 345
         // if $values was submitted in the wrong format, convert it over
346
-        if (!empty($values) && (!array_key_exists(0, $values) || !is_array($values[0]))) {
346
+        if ( ! empty($values) && ( ! array_key_exists(0, $values) || ! is_array($values[0]))) {
347 347
             $converted_values = array();
348 348
             foreach ($values as $id => $text) {
349
-                $converted_values[] = array('id' => $id,'text' => $text);
349
+                $converted_values[] = array('id' => $id, 'text' => $text);
350 350
             }
351 351
             $values = $converted_values;
352 352
         }
353 353
 
354
-        $field = '<select id="' . EEH_Formatter::ee_tep_output_string($name) . '" name="' . EEH_Formatter::ee_tep_output_string($name) . '"';
354
+        $field = '<select id="'.EEH_Formatter::ee_tep_output_string($name).'" name="'.EEH_Formatter::ee_tep_output_string($name).'"';
355 355
         // Debug
356 356
         // EEH_Debug_Tools::printr( $values, '$values  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' );
357 357
         if (EEH_Formatter::ee_tep_not_null($parameters)) {
358
-            $field .= ' ' . $parameters;
358
+            $field .= ' '.$parameters;
359 359
         }
360 360
         if ($autosize) {
361 361
             $size = 'med';
362 362
             for ($ii = 0, $ni = sizeof($values); $ii < $ni; $ii++) {
363
-                if ($values[ $ii ]['text']) {
364
-                    if (strlen($values[ $ii ]['text']) > 5) {
363
+                if ($values[$ii]['text']) {
364
+                    if (strlen($values[$ii]['text']) > 5) {
365 365
                         $size = 'wide';
366 366
                     }
367 367
                 }
@@ -370,22 +370,22 @@  discard block
 block discarded – undo
370 370
             $size = '';
371 371
         }
372 372
 
373
-        $field .= ' class="' . $class . ' ' . $size . '">';
373
+        $field .= ' class="'.$class.' '.$size.'">';
374 374
 
375
-        if (empty($default) && isset($GLOBALS[ $name ])) {
376
-            $default = stripslashes($GLOBALS[ $name ]);
375
+        if (empty($default) && isset($GLOBALS[$name])) {
376
+            $default = stripslashes($GLOBALS[$name]);
377 377
         }
378 378
 
379 379
 
380 380
         for ($i = 0, $n = sizeof($values); $i < $n; $i++) {
381
-            $field .= '<option value="' . $values[ $i ]['id'] . '"';
382
-            if ($default == $values[ $i ]['id']) {
381
+            $field .= '<option value="'.$values[$i]['id'].'"';
382
+            if ($default == $values[$i]['id']) {
383 383
                 $field .= ' selected = "selected"';
384 384
             }
385
-            if (isset($values[ $i ]['class'])) {
386
-                $field .= ' class="' . $values[ $i ]['class'] . '"';
385
+            if (isset($values[$i]['class'])) {
386
+                $field .= ' class="'.$values[$i]['class'].'"';
387 387
             }
388
-            $field .= '>' . $values[ $i ]['text'] . '</option>';
388
+            $field .= '>'.$values[$i]['text'].'</option>';
389 389
         }
390 390
         $field .= '</select>';
391 391
 
@@ -410,18 +410,18 @@  discard block
 block discarded – undo
410 410
         $before_question_group_questions = apply_filters('FHEE__EEH_Form_Fields__generate_question_groups_html__before_question_group_questions', '');
411 411
         $after_question_group_questions = apply_filters('FHEE__EEH_Form_Fields__generate_question_groups_html__after_question_group_questions', '');
412 412
 
413
-        if (! empty($question_groups)) {
413
+        if ( ! empty($question_groups)) {
414 414
             // EEH_Debug_Tools::printr( $question_groups, '$question_groups  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' );
415 415
             // loop thru question groups
416 416
             foreach ($question_groups as $QSG) {
417 417
                 // check that questions exist
418
-                if (! empty($QSG['QSG_questions'])) {
418
+                if ( ! empty($QSG['QSG_questions'])) {
419 419
                     // use fieldsets
420
-                    $html .= "\n\t" . '<' . $group_wrapper . ' class="espresso-question-group-wrap" id="' . $QSG['QSG_identifier'] . '">';
420
+                    $html .= "\n\t".'<'.$group_wrapper.' class="espresso-question-group-wrap" id="'.$QSG['QSG_identifier'].'">';
421 421
                     // group_name
422
-                    $html .= $QSG['QSG_show_group_name'] ? "\n\t\t" . '<h5 class="espresso-question-group-title-h5 section-title">' . self::prep_answer($QSG['QSG_name']) . '</h5>' : '';
422
+                    $html .= $QSG['QSG_show_group_name'] ? "\n\t\t".'<h5 class="espresso-question-group-title-h5 section-title">'.self::prep_answer($QSG['QSG_name']).'</h5>' : '';
423 423
                     // group_desc
424
-                    $html .= $QSG['QSG_show_group_desc'] && ! empty($QSG['QSG_desc']) ? '<div class="espresso-question-group-desc-pg">' . self::prep_answer($QSG['QSG_desc']) . '</div>' : '';
424
+                    $html .= $QSG['QSG_show_group_desc'] && ! empty($QSG['QSG_desc']) ? '<div class="espresso-question-group-desc-pg">'.self::prep_answer($QSG['QSG_desc']).'</div>' : '';
425 425
 
426 426
                     $html .= $before_question_group_questions;
427 427
                     // loop thru questions
@@ -435,7 +435,7 @@  discard block
 block discarded – undo
435 435
                         $html .= self::generate_form_input($QFI);
436 436
                     }
437 437
                     $html .= $after_question_group_questions;
438
-                    $html .= "\n\t" . '</' . $group_wrapper . '>';
438
+                    $html .= "\n\t".'</'.$group_wrapper.'>';
439 439
                 }
440 440
             }
441 441
         }
@@ -471,28 +471,28 @@  discard block
 block discarded – undo
471 471
         $q_meta = array_merge($default_q_meta, $q_meta);
472 472
         // EEH_Debug_Tools::printr( $q_meta, '$q_meta  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' );
473 473
 
474
-        if (! empty($question_groups)) {
474
+        if ( ! empty($question_groups)) {
475 475
 //          EEH_Debug_Tools::printr( $question_groups, '$question_groups  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' );
476 476
             // loop thru question groups
477 477
             foreach ($question_groups as $QSG) {
478 478
                 if ($QSG instanceof EE_Question_Group) {
479 479
                     // check that questions exist
480 480
 
481
-                    $where = array( 'QST_deleted' => 0 );
482
-                    if (! $from_admin) {
481
+                    $where = array('QST_deleted' => 0);
482
+                    if ( ! $from_admin) {
483 483
                         $where['QST_admin_only'] = 0;
484 484
                     }
485
-                    $questions = $QSG->questions(array( $where, 'order_by' => array( 'Question_Group_Question.QGQ_order' => 'ASC' )));
486
-                    if (! empty($questions)) {
485
+                    $questions = $QSG->questions(array($where, 'order_by' => array('Question_Group_Question.QGQ_order' => 'ASC')));
486
+                    if ( ! empty($questions)) {
487 487
                         // use fieldsets
488
-                        $html .= "\n\t" . '<' . $group_wrapper . ' class="espresso-question-group-wrap" id="' . $QSG->get('QSG_identifier') . '">';
488
+                        $html .= "\n\t".'<'.$group_wrapper.' class="espresso-question-group-wrap" id="'.$QSG->get('QSG_identifier').'">';
489 489
                         // group_name
490 490
                         if ($QSG->show_group_name()) {
491
-                            $html .=  "\n\t\t" . '<h5 class="espresso-question-group-title-h5 section-title">' . $QSG->get_pretty('QSG_name') . '</h5>';
491
+                            $html .= "\n\t\t".'<h5 class="espresso-question-group-title-h5 section-title">'.$QSG->get_pretty('QSG_name').'</h5>';
492 492
                         }
493 493
                         // group_desc
494 494
                         if ($QSG->show_group_desc()) {
495
-                            $html .=  '<div class="espresso-question-group-desc-pg">' . $QSG->get_pretty('QSG_desc') . '</div>';
495
+                            $html .= '<div class="espresso-question-group-desc-pg">'.$QSG->get_pretty('QSG_desc').'</div>';
496 496
                         }
497 497
 
498 498
                         $html .= $before_question_group_questions;
@@ -504,12 +504,12 @@  discard block
 block discarded – undo
504 504
 
505 505
                             if (isset($_GET['qstn']) && isset($q_meta['input_id']) && isset($q_meta['att_nmbr'])) {
506 506
                                 // check for answer in $_GET in case we are reprocessing a form after an error
507
-                                if (isset($_GET['qstn'][ $q_meta['input_id'] ][ $qstn_id ])) {
508
-                                    $answer = is_array($_GET['qstn'][ $q_meta['input_id'] ][ $qstn_id ]) ? $_GET['qstn'][ $q_meta['input_id'] ][ $qstn_id ] : sanitize_text_field($_GET['qstn'][ $q_meta['input_id'] ][ $qstn_id ]);
507
+                                if (isset($_GET['qstn'][$q_meta['input_id']][$qstn_id])) {
508
+                                    $answer = is_array($_GET['qstn'][$q_meta['input_id']][$qstn_id]) ? $_GET['qstn'][$q_meta['input_id']][$qstn_id] : sanitize_text_field($_GET['qstn'][$q_meta['input_id']][$qstn_id]);
509 509
                                 }
510 510
                             } elseif (isset($q_meta['attendee']) && $q_meta['attendee']) {
511 511
                                 // attendee data from the session
512
-                                $answer = isset($q_meta['attendee'][ $qstn_id ]) ? $q_meta['attendee'][ $qstn_id ] : null;
512
+                                $answer = isset($q_meta['attendee'][$qstn_id]) ? $q_meta['attendee'][$qstn_id] : null;
513 513
                             }
514 514
 
515 515
 
@@ -528,7 +528,7 @@  discard block
 block discarded – undo
528 528
                             $html .= self::generate_form_input($QFI);
529 529
                         }
530 530
                         $html .= $after_question_group_questions;
531
-                        $html .= "\n\t" . '</' . $group_wrapper . '>';
531
+                        $html .= "\n\t".'</'.$group_wrapper.'>';
532 532
                     }
533 533
                 }
534 534
             }
@@ -567,10 +567,10 @@  discard block
 block discarded – undo
567 567
         $disabled = $QFI->get('QST_disabled') ? true : false;
568 568
         $required_label = apply_filters(' FHEE__EEH_Form_Fields__generate_form_input__required_label', '<em>*</em>');
569 569
         $QST_required = $QFI->get('QST_required');
570
-        $required = $QST_required ? array( 'label' => $required_label, 'class' => 'required needs-value', 'title' => $QST_required ) : array();
570
+        $required = $QST_required ? array('label' => $required_label, 'class' => 'required needs-value', 'title' => $QST_required) : array();
571 571
         $use_html_entities = $QFI->get_meta('htmlentities');
572 572
         $required_text = $QFI->get('QST_required_text') != '' ? $QFI->get('QST_required_text') : __('This field is required', 'event_espresso');
573
-        $required_text = $QST_required ? "\n\t\t\t" . '<div class="required-text hidden">' . self::prep_answer($required_text, $use_html_entities) . '</div>' : '';
573
+        $required_text = $QST_required ? "\n\t\t\t".'<div class="required-text hidden">'.self::prep_answer($required_text, $use_html_entities).'</div>' : '';
574 574
         $label_class = 'espresso-form-input-lbl';
575 575
         $QST_options = $QFI->options(true, $answer);
576 576
         $options = is_array($QST_options) ? self::prep_answer_options($QST_options) : array();
@@ -629,7 +629,7 @@  discard block
 block discarded – undo
629 629
     public static function text($question = false, $answer = null, $name = false, $id = '', $class = '', $required = false, $required_text = '', $label_class = '', $disabled = false, $system_ID = false, $use_html_entities = true)
630 630
     {
631 631
         // need these
632
-        if (! $question || ! $name) {
632
+        if ( ! $question || ! $name) {
633 633
             return null;
634 634
         }
635 635
         // prep the answer
@@ -637,21 +637,21 @@  discard block
 block discarded – undo
637 637
         // prep the required array
638 638
         $required = self::prep_required($required);
639 639
         // set disabled tag
640
-        $disabled = $answer === null || ! $disabled  ? '' : ' disabled="disabled"';
640
+        $disabled = $answer === null || ! $disabled ? '' : ' disabled="disabled"';
641 641
         // ya gots ta have style man!!!
642 642
         $txt_class = is_admin() ? 'regular-text' : 'espresso-text-inp';
643 643
         $class = empty($class) ? $txt_class : $class;
644
-        $class .= ! empty($system_ID) ? ' ' . $system_ID : '';
644
+        $class .= ! empty($system_ID) ? ' '.$system_ID : '';
645 645
         $extra = apply_filters('FHEE__EEH_Form_Fields__additional_form_field_attributes', '');
646 646
 
647
-        $label_html = $required_text . "\n\t\t\t" . '<label for="' . $name . '" class="' . $label_class . '">' . self::prep_question($question) . $required['label'] . '</label><br/>';
647
+        $label_html = $required_text."\n\t\t\t".'<label for="'.$name.'" class="'.$label_class.'">'.self::prep_question($question).$required['label'].'</label><br/>';
648 648
         // filter label but ensure required text comes before it
649 649
         $label_html = apply_filters('FHEE__EEH_Form_Fields__label_html', $label_html, $required_text);
650 650
 
651
-        $input_html = "\n\t\t\t" . '<input type="text" name="' . $name . '" id="' . $id . '" class="' . $class . ' ' . $required['class'] . '" value="' . esc_attr($answer) . '"  title="' . esc_attr($required['msg']) . '" ' . $disabled . ' ' . $extra . '/>';
651
+        $input_html = "\n\t\t\t".'<input type="text" name="'.$name.'" id="'.$id.'" class="'.$class.' '.$required['class'].'" value="'.esc_attr($answer).'"  title="'.esc_attr($required['msg']).'" '.$disabled.' '.$extra.'/>';
652 652
 
653
-        $input_html =  apply_filters('FHEE__EEH_Form_Fields__input_html', $input_html, $label_html, $id);
654
-        return  $label_html . $input_html;
653
+        $input_html = apply_filters('FHEE__EEH_Form_Fields__input_html', $input_html, $label_html, $id);
654
+        return  $label_html.$input_html;
655 655
     }
656 656
 
657 657
 
@@ -675,7 +675,7 @@  discard block
 block discarded – undo
675 675
     public static function textarea($question = false, $answer = null, $name = false, $id = '', $class = '', $dimensions = false, $required = false, $required_text = '', $label_class = '', $disabled = false, $system_ID = false, $use_html_entities = true)
676 676
     {
677 677
         // need these
678
-        if (! $question || ! $name) {
678
+        if ( ! $question || ! $name) {
679 679
             return null;
680 680
         }
681 681
         // prep the answer
@@ -685,23 +685,23 @@  discard block
 block discarded – undo
685 685
         // make sure $dimensions is an array
686 686
         $dimensions = is_array($dimensions) ? $dimensions : array();
687 687
         // and set some defaults
688
-        $dimensions = array_merge(array( 'rows' => 3, 'cols' => 40 ), $dimensions);
688
+        $dimensions = array_merge(array('rows' => 3, 'cols' => 40), $dimensions);
689 689
         // set disabled tag
690
-        $disabled = $answer === null || ! $disabled  ? '' : ' disabled="disabled"';
690
+        $disabled = $answer === null || ! $disabled ? '' : ' disabled="disabled"';
691 691
         // ya gots ta have style man!!!
692 692
         $txt_class = is_admin() ? 'regular-text' : 'espresso-textarea-inp';
693 693
         $class = empty($class) ? $txt_class : $class;
694
-        $class .= ! empty($system_ID) ? ' ' . $system_ID : '';
694
+        $class .= ! empty($system_ID) ? ' '.$system_ID : '';
695 695
         $extra = apply_filters('FHEE__EEH_Form_Fields__additional_form_field_attributes', '');
696 696
 
697
-        $label_html = $required_text . "\n\t\t\t" . '<label for="' . $name . '" class="' . $label_class . '">' . self::prep_question($question) . $required['label'] . '</label><br/>';
697
+        $label_html = $required_text."\n\t\t\t".'<label for="'.$name.'" class="'.$label_class.'">'.self::prep_question($question).$required['label'].'</label><br/>';
698 698
         // filter label but ensure required text comes before it
699 699
         $label_html = apply_filters('FHEE__EEH_Form_Fields__label_html', $label_html, $required_text);
700 700
 
701
-        $input_html = "\n\t\t\t" . '<textarea name="' . $name . '" id="' . $id . '" class="' . $class . ' ' . $required['class'] . '" rows="' . $dimensions['rows'] . '" cols="' . $dimensions['cols'] . '"  title="' . $required['msg'] . '" ' . $disabled . ' ' . $extra . '>' . $answer . '</textarea>';
701
+        $input_html = "\n\t\t\t".'<textarea name="'.$name.'" id="'.$id.'" class="'.$class.' '.$required['class'].'" rows="'.$dimensions['rows'].'" cols="'.$dimensions['cols'].'"  title="'.$required['msg'].'" '.$disabled.' '.$extra.'>'.$answer.'</textarea>';
702 702
 
703
-        $input_html =  apply_filters('FHEE__EEH_Form_Fields__input_html', $input_html, $label_html, $id);
704
-        return  $label_html . $input_html;
703
+        $input_html = apply_filters('FHEE__EEH_Form_Fields__input_html', $input_html, $label_html, $id);
704
+        return  $label_html.$input_html;
705 705
     }
706 706
 
707 707
 
@@ -727,7 +727,7 @@  discard block
 block discarded – undo
727 727
     {
728 728
 
729 729
         // need these
730
-        if (! $question || ! $name || ! $options || empty($options) || ! is_array($options)) {
730
+        if ( ! $question || ! $name || ! $options || empty($options) || ! is_array($options)) {
731 731
             return null;
732 732
         }
733 733
         // prep the answer
@@ -735,36 +735,36 @@  discard block
 block discarded – undo
735 735
         // prep the required array
736 736
         $required = self::prep_required($required);
737 737
         // set disabled tag
738
-        $disabled = $answer === null || ! $disabled  ? '' : ' disabled="disabled"';
738
+        $disabled = $answer === null || ! $disabled ? '' : ' disabled="disabled"';
739 739
         // ya gots ta have style man!!!
740 740
         $txt_class = is_admin() ? 'wide' : 'espresso-select-inp';
741 741
         $class = empty($class) ? $txt_class : $class;
742
-        $class .= ! empty($system_ID) ? ' ' . $system_ID : '';
742
+        $class .= ! empty($system_ID) ? ' '.$system_ID : '';
743 743
         $extra = apply_filters('FHEE__EEH_Form_Fields__additional_form_field_attributes', '');
744 744
 
745
-        $label_html = $required_text . "\n\t\t\t" . '<label for="' . $name . '" class="' . $label_class . '">' . self::prep_question($question) . $required['label'] . '</label><br/>';
745
+        $label_html = $required_text."\n\t\t\t".'<label for="'.$name.'" class="'.$label_class.'">'.self::prep_question($question).$required['label'].'</label><br/>';
746 746
         // filter label but ensure required text comes before it
747 747
         $label_html = apply_filters('FHEE__EEH_Form_Fields__label_html', $label_html, $required_text);
748 748
 
749
-        $input_html = "\n\t\t\t" . '<select name="' . $name . '" id="' . $id . '" class="' . $class . ' ' . $required['class'] . '" title="' . esc_attr($required['msg']) . '"' . $disabled . ' ' . $extra . '>';
749
+        $input_html = "\n\t\t\t".'<select name="'.$name.'" id="'.$id.'" class="'.$class.' '.$required['class'].'" title="'.esc_attr($required['msg']).'"'.$disabled.' '.$extra.'>';
750 750
         // recursively count array elements, to determine total number of options
751 751
         $only_option = count($options, 1) == 1 ? true : false;
752
-        if (! $only_option) {
752
+        if ( ! $only_option) {
753 753
             // if there is NO answer set and there are multiple options to choose from, then set the "please select" message as selected
754 754
             $selected = $answer === null ? ' selected="selected"' : '';
755
-            $input_html .= $add_please_select_option ? "\n\t\t\t\t" . '<option value=""' . $selected . '>' . __(' - please select - ', 'event_espresso') . '</option>' : '';
755
+            $input_html .= $add_please_select_option ? "\n\t\t\t\t".'<option value=""'.$selected.'>'.__(' - please select - ', 'event_espresso').'</option>' : '';
756 756
         }
757 757
         foreach ($options as $key => $value) {
758 758
             // if value is an array, then create option groups, else create regular ol' options
759 759
             $input_html .= is_array($value) ? self::_generate_select_option_group($key, $value, $answer, $use_html_entities) : self::_generate_select_option($value->value(), $value->desc(), $answer, $only_option, $use_html_entities);
760 760
         }
761 761
 
762
-        $input_html .= "\n\t\t\t" . '</select>';
762
+        $input_html .= "\n\t\t\t".'</select>';
763 763
 
764
-        $input_html =  apply_filters('FHEE__EEH_Form_Fields__select__before_end_wrapper', $input_html, $question, $answer, $name, $id, $class, $system_ID);
764
+        $input_html = apply_filters('FHEE__EEH_Form_Fields__select__before_end_wrapper', $input_html, $question, $answer, $name, $id, $class, $system_ID);
765 765
 
766
-        $input_html =  apply_filters('FHEE__EEH_Form_Fields__input_html', $input_html, $label_html, $id);
767
-        return  $label_html . $input_html;
766
+        $input_html = apply_filters('FHEE__EEH_Form_Fields__input_html', $input_html, $label_html, $id);
767
+        return  $label_html.$input_html;
768 768
     }
769 769
 
770 770
 
@@ -783,11 +783,11 @@  discard block
 block discarded – undo
783 783
      */
784 784
     private static function _generate_select_option_group($opt_group, $QSOs, $answer, $use_html_entities = true)
785 785
     {
786
-        $html = "\n\t\t\t\t" . '<optgroup label="' . self::prep_option_value($opt_group) . '">';
786
+        $html = "\n\t\t\t\t".'<optgroup label="'.self::prep_option_value($opt_group).'">';
787 787
         foreach ($QSOs as $QSO) {
788 788
             $html .= self::_generate_select_option($QSO->value(), $QSO->desc(), $answer, false, $use_html_entities);
789 789
         }
790
-        $html .= "\n\t\t\t\t" . '</optgroup>';
790
+        $html .= "\n\t\t\t\t".'</optgroup>';
791 791
         return $html;
792 792
     }
793 793
 
@@ -807,8 +807,8 @@  discard block
 block discarded – undo
807 807
         $key = self::prep_answer($key, $use_html_entities);
808 808
         $value = self::prep_answer($value, $use_html_entities);
809 809
         $value = ! empty($value) ? $value : $key;
810
-        $selected = ( $answer == $key || $only_option ) ? ' selected="selected"' : '';
811
-        return "\n\t\t\t\t" . '<option value="' . self::prep_option_value($key) . '"' . $selected . '> ' . $value . '&nbsp;&nbsp;&nbsp;</option>';
810
+        $selected = ($answer == $key || $only_option) ? ' selected="selected"' : '';
811
+        return "\n\t\t\t\t".'<option value="'.self::prep_option_value($key).'"'.$selected.'> '.$value.'&nbsp;&nbsp;&nbsp;</option>';
812 812
     }
813 813
 
814 814
 
@@ -835,7 +835,7 @@  discard block
 block discarded – undo
835 835
     public static function radio($question = false, $answer = null, $options = false, $name = false, $id = '', $class = '', $required = false, $required_text = '', $label_class = '', $disabled = false, $system_ID = false, $use_html_entities = true, $label_b4 = false, $use_desc_4_label = false)
836 836
     {
837 837
         // need these
838
-        if (! $question || ! $name || ! $options || empty($options) || ! is_array($options)) {
838
+        if ( ! $question || ! $name || ! $options || empty($options) || ! is_array($options)) {
839 839
             return null;
840 840
         }
841 841
         // prep the answer
@@ -843,46 +843,46 @@  discard block
 block discarded – undo
843 843
         // prep the required array
844 844
         $required = self::prep_required($required);
845 845
         // set disabled tag
846
-        $disabled = $answer === null || ! $disabled  ? '' : ' disabled="disabled"';
846
+        $disabled = $answer === null || ! $disabled ? '' : ' disabled="disabled"';
847 847
         // ya gots ta have style man!!!
848 848
         $radio_class = is_admin() ? 'ee-admin-radio-lbl' : $label_class;
849 849
         $class = ! empty($class) ? $class : 'espresso-radio-btn-inp';
850 850
         $extra = apply_filters('FHEE__EEH_Form_Fields__additional_form_field_attributes', '');
851 851
 
852
-        $label_html = $required_text . "\n\t\t\t" . '<label class="' . $label_class . '">' . self::prep_question($question) . $required['label'] . '</label> ';
852
+        $label_html = $required_text."\n\t\t\t".'<label class="'.$label_class.'">'.self::prep_question($question).$required['label'].'</label> ';
853 853
         // filter label but ensure required text comes before it
854 854
         $label_html = apply_filters('FHEE__EEH_Form_Fields__label_html', $label_html, $required_text);
855 855
 
856
-        $input_html = "\n\t\t\t" . '<ul id="' . $id . '-ul" class="espresso-radio-btn-options-ul ' . $label_class . ' ' . $class . '-ul">';
856
+        $input_html = "\n\t\t\t".'<ul id="'.$id.'-ul" class="espresso-radio-btn-options-ul '.$label_class.' '.$class.'-ul">';
857 857
 
858
-        $class .= ! empty($system_ID) ? ' ' . $system_ID : '';
859
-        $class .= ! empty($required['class']) ? ' ' . $required['class'] : '';
858
+        $class .= ! empty($system_ID) ? ' '.$system_ID : '';
859
+        $class .= ! empty($required['class']) ? ' '.$required['class'] : '';
860 860
 
861 861
         foreach ($options as $OPT) {
862 862
             if ($OPT instanceof EE_Question_Option) {
863 863
                 $value = self::prep_option_value($OPT->value());
864 864
                 $label = $use_desc_4_label ? $OPT->desc() : $OPT->value();
865
-                $size = $use_desc_4_label ? self::get_label_size_class($OPT->value() . ' ' . $OPT->desc()) : self::get_label_size_class($OPT->value());
866
-                $desc = $OPT->desc();// no self::prep_answer
865
+                $size = $use_desc_4_label ? self::get_label_size_class($OPT->value().' '.$OPT->desc()) : self::get_label_size_class($OPT->value());
866
+                $desc = $OPT->desc(); // no self::prep_answer
867 867
                 $answer = is_numeric($value) && empty($answer) ? 0 : $answer;
868 868
                 $checked = (string) $value == (string) $answer ? ' checked="checked"' : '';
869
-                $opt = '-' . sanitize_key($value);
870
-
871
-                $input_html .= "\n\t\t\t\t" . '<li' . $size . '>';
872
-                $input_html .= "\n\t\t\t\t\t" . '<label class="' . $radio_class . ' espresso-radio-btn-lbl">';
873
-                $input_html .= $label_b4  ? "\n\t\t\t\t\t\t" . '<span>' . $label . '</span>' : '';
874
-                $input_html .= "\n\t\t\t\t\t\t" . '<input type="radio" name="' . $name . '" id="' . $id . $opt . '" class="' . $class . '" value="' . $value . '" title="' . esc_attr($required['msg']) . '" ' . $disabled . $checked . ' ' . $extra . '/>';
875
-                $input_html .= ! $label_b4  ? "\n\t\t\t\t\t\t" . '<span class="espresso-radio-btn-desc">' . $label . '</span>' : '';
876
-                $input_html .= "\n\t\t\t\t\t" . '</label>';
877
-                $input_html .= $use_desc_4_label ? '' : '<span class="espresso-radio-btn-option-desc small-text grey-text">' . $desc . '</span>';
878
-                $input_html .= "\n\t\t\t\t" . '</li>';
869
+                $opt = '-'.sanitize_key($value);
870
+
871
+                $input_html .= "\n\t\t\t\t".'<li'.$size.'>';
872
+                $input_html .= "\n\t\t\t\t\t".'<label class="'.$radio_class.' espresso-radio-btn-lbl">';
873
+                $input_html .= $label_b4 ? "\n\t\t\t\t\t\t".'<span>'.$label.'</span>' : '';
874
+                $input_html .= "\n\t\t\t\t\t\t".'<input type="radio" name="'.$name.'" id="'.$id.$opt.'" class="'.$class.'" value="'.$value.'" title="'.esc_attr($required['msg']).'" '.$disabled.$checked.' '.$extra.'/>';
875
+                $input_html .= ! $label_b4 ? "\n\t\t\t\t\t\t".'<span class="espresso-radio-btn-desc">'.$label.'</span>' : '';
876
+                $input_html .= "\n\t\t\t\t\t".'</label>';
877
+                $input_html .= $use_desc_4_label ? '' : '<span class="espresso-radio-btn-option-desc small-text grey-text">'.$desc.'</span>';
878
+                $input_html .= "\n\t\t\t\t".'</li>';
879 879
             }
880 880
         }
881 881
 
882
-        $input_html .= "\n\t\t\t" . '</ul>';
882
+        $input_html .= "\n\t\t\t".'</ul>';
883 883
 
884
-        $input_html =  apply_filters('FHEE__EEH_Form_Fields__input_html', $input_html, $label_html, $id);
885
-        return  $label_html . $input_html;
884
+        $input_html = apply_filters('FHEE__EEH_Form_Fields__input_html', $input_html, $label_html, $id);
885
+        return  $label_html.$input_html;
886 886
     }
887 887
 
888 888
 
@@ -907,62 +907,62 @@  discard block
 block discarded – undo
907 907
     public static function checkbox($question = false, $answer = null, $options = false, $name = false, $id = '', $class = '', $required = false, $required_text = '', $label_class = '', $disabled = false, $label_b4 = false, $system_ID = false, $use_html_entities = true)
908 908
     {
909 909
         // need these
910
-        if (! $question || ! $name || ! $options || empty($options) || ! is_array($options)) {
910
+        if ( ! $question || ! $name || ! $options || empty($options) || ! is_array($options)) {
911 911
             return null;
912 912
         }
913 913
         $answer = maybe_unserialize($answer);
914 914
 
915 915
         // prep the answer(s)
916
-        $answer = is_array($answer) ? $answer : array( sanitize_key($answer) => $answer );
916
+        $answer = is_array($answer) ? $answer : array(sanitize_key($answer) => $answer);
917 917
 
918 918
         foreach ($answer as $key => $value) {
919 919
             $key = self::prep_option_value($key);
920
-            $answer[ $key ] = self::prep_answer($value, $use_html_entities);
920
+            $answer[$key] = self::prep_answer($value, $use_html_entities);
921 921
         }
922 922
 
923 923
         // prep the required array
924 924
         $required = self::prep_required($required);
925 925
         // set disabled tag
926
-        $disabled = $answer === null || ! $disabled  ? '' : ' disabled="disabled"';
926
+        $disabled = $answer === null || ! $disabled ? '' : ' disabled="disabled"';
927 927
         // ya gots ta have style man!!!
928 928
         $radio_class = is_admin() ? 'ee-admin-radio-lbl' : $label_class;
929 929
         $class = empty($class) ? 'espresso-radio-btn-inp' : $class;
930 930
         $extra = apply_filters('FHEE__EEH_Form_Fields__additional_form_field_attributes', '');
931 931
 
932
-        $label_html = $required_text . "\n\t\t\t" . '<label class="' . $label_class . '">' . self::prep_question($question) . $required['label'] . '</label> ';
932
+        $label_html = $required_text."\n\t\t\t".'<label class="'.$label_class.'">'.self::prep_question($question).$required['label'].'</label> ';
933 933
         // filter label but ensure required text comes before it
934 934
         $label_html = apply_filters('FHEE__EEH_Form_Fields__label_html', $label_html, $required_text);
935 935
 
936
-        $input_html = "\n\t\t\t" . '<ul id="' . $id . '-ul" class="espresso-checkbox-options-ul ' . $label_class . ' ' . $class . '-ul">';
936
+        $input_html = "\n\t\t\t".'<ul id="'.$id.'-ul" class="espresso-checkbox-options-ul '.$label_class.' '.$class.'-ul">';
937 937
 
938
-        $class .= ! empty($system_ID) ? ' ' . $system_ID : '';
939
-        $class .= ! empty($required['class']) ? ' ' . $required['class'] : '';
938
+        $class .= ! empty($system_ID) ? ' '.$system_ID : '';
939
+        $class .= ! empty($required['class']) ? ' '.$required['class'] : '';
940 940
 
941 941
         foreach ($options as $OPT) {
942
-            $value = $OPT->value();// self::prep_option_value( $OPT->value() );
943
-            $size = self::get_label_size_class($OPT->value() . ' ' . $OPT->desc());
942
+            $value = $OPT->value(); // self::prep_option_value( $OPT->value() );
943
+            $size = self::get_label_size_class($OPT->value().' '.$OPT->desc());
944 944
             $text = self::prep_answer($OPT->value());
945
-            $desc = $OPT->desc() ;
946
-            $opt = '-' . sanitize_key($value);
945
+            $desc = $OPT->desc();
946
+            $opt = '-'.sanitize_key($value);
947 947
 
948 948
             $checked = is_array($answer) && in_array($text, $answer) ? ' checked="checked"' : '';
949 949
 
950
-            $input_html .= "\n\t\t\t\t" . '<li' . $size . '>';
951
-            $input_html .= "\n\t\t\t\t\t" . '<label class="' . $radio_class . ' espresso-checkbox-lbl">';
952
-            $input_html .= $label_b4  ? "\n\t\t\t\t\t\t" . '<span>' . $text . '</span>' : '';
953
-            $input_html .= "\n\t\t\t\t\t\t" . '<input type="checkbox" name="' . $name . '[' . $OPT->ID() . ']" id="' . $id . $opt . '" class="' . $class . '" value="' . $value . '" title="' . esc_attr($required['msg']) . '" ' . $disabled . $checked . ' ' . $extra . '/>';
954
-            $input_html .= ! $label_b4  ? "\n\t\t\t\t\t\t" . '<span>' . $text . '</span>' : '';
955
-            $input_html .= "\n\t\t\t\t\t" . '</label>';
956
-            if (! empty($desc) && $desc != $text) {
957
-                $input_html .= "\n\t\t\t\t\t" . ' &nbsp; <br/><div class="espresso-checkbox-option-desc small-text grey-text">' . $desc . '</div>';
950
+            $input_html .= "\n\t\t\t\t".'<li'.$size.'>';
951
+            $input_html .= "\n\t\t\t\t\t".'<label class="'.$radio_class.' espresso-checkbox-lbl">';
952
+            $input_html .= $label_b4 ? "\n\t\t\t\t\t\t".'<span>'.$text.'</span>' : '';
953
+            $input_html .= "\n\t\t\t\t\t\t".'<input type="checkbox" name="'.$name.'['.$OPT->ID().']" id="'.$id.$opt.'" class="'.$class.'" value="'.$value.'" title="'.esc_attr($required['msg']).'" '.$disabled.$checked.' '.$extra.'/>';
954
+            $input_html .= ! $label_b4 ? "\n\t\t\t\t\t\t".'<span>'.$text.'</span>' : '';
955
+            $input_html .= "\n\t\t\t\t\t".'</label>';
956
+            if ( ! empty($desc) && $desc != $text) {
957
+                $input_html .= "\n\t\t\t\t\t".' &nbsp; <br/><div class="espresso-checkbox-option-desc small-text grey-text">'.$desc.'</div>';
958 958
             }
959
-            $input_html .= "\n\t\t\t\t" . '</li>';
959
+            $input_html .= "\n\t\t\t\t".'</li>';
960 960
         }
961 961
 
962
-        $input_html .= "\n\t\t\t" . '</ul>';
962
+        $input_html .= "\n\t\t\t".'</ul>';
963 963
 
964
-        $input_html =  apply_filters('FHEE__EEH_Form_Fields__input_html', $input_html, $label_html, $id);
965
-        return  $label_html . $input_html;
964
+        $input_html = apply_filters('FHEE__EEH_Form_Fields__input_html', $input_html, $label_html, $id);
965
+        return  $label_html.$input_html;
966 966
     }
967 967
 
968 968
 
@@ -986,7 +986,7 @@  discard block
 block discarded – undo
986 986
     public static function datepicker($question = false, $answer = null, $name = false, $id = '', $class = '', $required = false, $required_text = '', $label_class = '', $disabled = false, $system_ID = false, $use_html_entities = true)
987 987
     {
988 988
         // need these
989
-        if (! $question || ! $name) {
989
+        if ( ! $question || ! $name) {
990 990
             return null;
991 991
         }
992 992
         // prep the answer
@@ -994,26 +994,26 @@  discard block
 block discarded – undo
994 994
         // prep the required array
995 995
         $required = self::prep_required($required);
996 996
         // set disabled tag
997
-        $disabled = $answer === null || ! $disabled  ? '' : ' disabled="disabled"';
997
+        $disabled = $answer === null || ! $disabled ? '' : ' disabled="disabled"';
998 998
         // ya gots ta have style man!!!
999 999
         $txt_class = is_admin() ? 'regular-text' : 'espresso-datepicker-inp';
1000 1000
         $class = empty($class) ? $txt_class : $class;
1001
-        $class .= ! empty($system_ID) ? ' ' . $system_ID : '';
1001
+        $class .= ! empty($system_ID) ? ' '.$system_ID : '';
1002 1002
         $extra = apply_filters('FHEE__EEH_Form_Fields__additional_form_field_attributes', '');
1003 1003
 
1004
-        $label_html = $required_text . "\n\t\t\t" . '<label for="' . $name . '" class="' . $label_class . '">' . self::prep_question($question) . $required['label'] . '</label><br/>';
1004
+        $label_html = $required_text."\n\t\t\t".'<label for="'.$name.'" class="'.$label_class.'">'.self::prep_question($question).$required['label'].'</label><br/>';
1005 1005
         // filter label but ensure required text comes before it
1006 1006
         $label_html = apply_filters('FHEE__EEH_Form_Fields__label_html', $label_html, $required_text);
1007 1007
 
1008
-        $input_html = "\n\t\t\t" . '<input type="text" name="' . $name . '" id="' . $id . '" class="' . $class . ' ' . $required['class'] . ' datepicker" value="' . $answer . '"  title="' . esc_attr($required['msg']) . '" ' . $disabled . ' ' . $extra . '/>';
1008
+        $input_html = "\n\t\t\t".'<input type="text" name="'.$name.'" id="'.$id.'" class="'.$class.' '.$required['class'].' datepicker" value="'.$answer.'"  title="'.esc_attr($required['msg']).'" '.$disabled.' '.$extra.'/>';
1009 1009
 
1010 1010
         // enqueue scripts
1011
-        wp_register_style('espresso-ui-theme', EE_GLOBAL_ASSETS_URL . 'css/espresso-ui-theme/jquery-ui-1.10.3.custom.min.css', array(), EVENT_ESPRESSO_VERSION);
1011
+        wp_register_style('espresso-ui-theme', EE_GLOBAL_ASSETS_URL.'css/espresso-ui-theme/jquery-ui-1.10.3.custom.min.css', array(), EVENT_ESPRESSO_VERSION);
1012 1012
         wp_enqueue_style('espresso-ui-theme');
1013 1013
         wp_enqueue_script('jquery-ui-datepicker');
1014 1014
 
1015
-        $input_html =  apply_filters('FHEE__EEH_Form_Fields__input_html', $input_html, $label_html, $id);
1016
-        return  $label_html . $input_html;
1015
+        $input_html = apply_filters('FHEE__EEH_Form_Fields__input_html', $input_html, $label_html, $id);
1016
+        return  $label_html.$input_html;
1017 1017
     }
1018 1018
 
1019 1019
 
@@ -1042,7 +1042,7 @@  discard block
 block discarded – undo
1042 1042
     public static function hidden_input($name, $value, $id = '')
1043 1043
     {
1044 1044
         $id = ! empty($id) ? $id : $name;
1045
-        return '<input id="' . $id . '" type="hidden" name="' . $name . '" value="' .  $value . '"/>';
1045
+        return '<input id="'.$id.'" type="hidden" name="'.$name.'" value="'.$value.'"/>';
1046 1046
     }
1047 1047
 
1048 1048
 
@@ -1100,14 +1100,14 @@  discard block
 block discarded – undo
1100 1100
         $prepped_answer_options = array();
1101 1101
         if (is_array($QSOs) && ! empty($QSOs)) {
1102 1102
             foreach ($QSOs as $key => $QSO) {
1103
-                if (! $QSO instanceof EE_Question_Option) {
1103
+                if ( ! $QSO instanceof EE_Question_Option) {
1104 1104
                     $QSO = EE_Question_Option::new_instance(array(
1105 1105
                         'QSO_value' => is_array($QSO) && isset($QSO['id']) ? (string) $QSO['id'] : (string) $key,
1106 1106
                         'QSO_desc' => is_array($QSO) && isset($QSO['text']) ? (string) $QSO['text'] : (string) $QSO
1107 1107
                     ));
1108 1108
                 }
1109 1109
                 if ($QSO->opt_group()) {
1110
-                    $prepped_answer_options[ $QSO->opt_group() ][] = $QSO;
1110
+                    $prepped_answer_options[$QSO->opt_group()][] = $QSO;
1111 1111
                 } else {
1112 1112
                     $prepped_answer_options[] = $QSO;
1113 1113
                 }
@@ -1141,7 +1141,7 @@  discard block
 block discarded – undo
1141 1141
         // make sure required is an array
1142 1142
         $required = is_array($required) ? $required : array();
1143 1143
         // and set some defaults
1144
-        $required = array_merge(array( 'label' => '', 'class' => '', 'msg' => '' ), $required);
1144
+        $required = array_merge(array('label' => '', 'class' => '', 'msg' => ''), $required);
1145 1145
         return $required;
1146 1146
     }
1147 1147
 
@@ -1161,22 +1161,22 @@  discard block
 block discarded – undo
1161 1161
             $val_size = strlen($value);
1162 1162
         switch ($val_size) {
1163 1163
             case $val_size < 3:
1164
-                $size =  ' class="nano-lbl"';
1164
+                $size = ' class="nano-lbl"';
1165 1165
                 break;
1166 1166
             case $val_size < 6:
1167
-                $size =  ' class="micro-lbl"';
1167
+                $size = ' class="micro-lbl"';
1168 1168
                 break;
1169 1169
             case $val_size < 12:
1170
-                $size =  ' class="tiny-lbl"';
1170
+                $size = ' class="tiny-lbl"';
1171 1171
                 break;
1172 1172
             case $val_size < 25:
1173
-                $size =  ' class="small-lbl"';
1173
+                $size = ' class="small-lbl"';
1174 1174
                 break;
1175 1175
             case $val_size > 100:
1176
-                $size =  ' class="big-lbl"';
1176
+                $size = ' class="big-lbl"';
1177 1177
                 break;
1178 1178
             default:
1179
-                $size =  ' class="medium-lbl"';
1179
+                $size = ' class="medium-lbl"';
1180 1180
                 break;
1181 1181
         }
1182 1182
         return $size;
@@ -1247,12 +1247,12 @@  discard block
 block discarded – undo
1247 1247
         $states = $get_all
1248 1248
             ? EEM_State::instance()->get_all_states()
1249 1249
             : EEM_State::instance()->get_all_states_of_active_countries();
1250
-        if (! empty($states) && count($states) != count($QST->options())) {
1250
+        if ( ! empty($states) && count($states) != count($QST->options())) {
1251 1251
             $QST->set('QST_type', 'DROPDOWN');
1252 1252
             // if multiple countries, we'll create option groups within the dropdown
1253 1253
             foreach ($states as $state) {
1254 1254
                 if ($state instanceof EE_State) {
1255
-                    $QSO = EE_Question_Option::new_instance(array (
1255
+                    $QSO = EE_Question_Option::new_instance(array(
1256 1256
                         'QSO_value' => $state->ID(),
1257 1257
                         'QSO_desc' => $state->name(),
1258 1258
                         'QST_ID' => $QST->get('QST_ID'),
@@ -1285,7 +1285,7 @@  discard block
 block discarded – undo
1285 1285
             // now add countries
1286 1286
             foreach ($countries as $country) {
1287 1287
                 if ($country instanceof EE_Country) {
1288
-                    $QSO = EE_Question_Option::new_instance(array (
1288
+                    $QSO = EE_Question_Option::new_instance(array(
1289 1289
                         'QSO_value' => $country->ID(),
1290 1290
                         'QSO_desc' => $country->name(),
1291 1291
                         'QST_ID' => $QST->get('QST_ID'),
@@ -1311,7 +1311,7 @@  discard block
 block discarded – undo
1311 1311
         $options = array();
1312 1312
         for ($x = 1; $x <= 12; $x++) {
1313 1313
             $mm = str_pad($x, 2, '0', STR_PAD_LEFT);
1314
-            $options[ (string) $mm ] = (string) $mm;
1314
+            $options[(string) $mm] = (string) $mm;
1315 1315
         }
1316 1316
         return EEH_Form_Fields::prep_answer_options($options);
1317 1317
     }
@@ -1331,7 +1331,7 @@  discard block
 block discarded – undo
1331 1331
         $next_decade = $current_year + 10;
1332 1332
         for ($x = $current_year; $x <= $next_decade; $x++) {
1333 1333
             $yy = str_pad($x, 2, '0', STR_PAD_LEFT);
1334
-            $options[ (string) $yy ] = (string) $yy;
1334
+            $options[(string) $yy] = (string) $yy;
1335 1335
         }
1336 1336
         return EEH_Form_Fields::prep_answer_options($options);
1337 1337
     }
@@ -1350,7 +1350,7 @@  discard block
 block discarded – undo
1350 1350
     public static function generate_registration_months_dropdown($cur_date = '', $status = '', $evt_category = 0)
1351 1351
     {
1352 1352
         $_where = array();
1353
-        if (!empty($status)) {
1353
+        if ( ! empty($status)) {
1354 1354
             $_where['STS_ID'] = $status;
1355 1355
         }
1356 1356
 
@@ -1369,7 +1369,7 @@  discard block
 block discarded – undo
1369 1369
             );
1370 1370
 
1371 1371
         foreach ($regdtts as $regdtt) {
1372
-            $date = $regdtt->reg_month . ' ' . $regdtt->reg_year;
1372
+            $date = $regdtt->reg_month.' '.$regdtt->reg_year;
1373 1373
             $options[] = array(
1374 1374
                 'text' => $date,
1375 1375
                 'id' => $date
@@ -1399,11 +1399,11 @@  discard block
 block discarded – undo
1399 1399
             case 'today':
1400 1400
             case null:
1401 1401
             case 'all':
1402
-                $where['Event.status'] = array( 'NOT IN', array('trash') );
1402
+                $where['Event.status'] = array('NOT IN', array('trash'));
1403 1403
                 break;
1404 1404
 
1405 1405
             case 'draft':
1406
-                $where['Event.status'] = array( 'IN', array('draft', 'auto-draft') );
1406
+                $where['Event.status'] = array('IN', array('draft', 'auto-draft'));
1407 1407
 
1408 1408
             default:
1409 1409
                 $where['Event.status'] = $status;
@@ -1414,7 +1414,7 @@  discard block
 block discarded – undo
1414 1414
         // categories?
1415 1415
 
1416 1416
 
1417
-        if (!empty($evt_category)) {
1417
+        if ( ! empty($evt_category)) {
1418 1418
             $where['Event.Term_Taxonomy.taxonomy'] = 'espresso_event_categories';
1419 1419
             $where['Event.Term_Taxonomy.term_id'] = $evt_category;
1420 1420
         }
@@ -1438,8 +1438,8 @@  discard block
 block discarded – undo
1438 1438
         global $wp_locale;
1439 1439
 
1440 1440
         foreach ($DTTS as $DTT) {
1441
-            $localized_date = $wp_locale->get_month($DTT->dtt_month_num) . ' ' . $DTT->dtt_year;
1442
-            $id = $DTT->dtt_month . ' ' . $DTT->dtt_year;
1441
+            $localized_date = $wp_locale->get_month($DTT->dtt_month_num).' '.$DTT->dtt_year;
1442
+            $id = $DTT->dtt_month.' '.$DTT->dtt_year;
1443 1443
             $options[] = array(
1444 1444
                 'text' => $localized_date,
1445 1445
                 'id' => $id
@@ -1502,10 +1502,10 @@  discard block
 block discarded – undo
1502 1502
             return $btn;
1503 1503
         }
1504 1504
         $text = ! empty($text) ? $text : __('Submit', 'event_espresso');
1505
-        $btn .= '<input id="' . $ID . '-btn" class="' . $class . '" type="submit" value="' . $text . '" ' . $extra_attributes . '/>';
1506
-        if (! $input_only) {
1507
-            $btn_frm = '<form id="' . $ID . '-frm" method="POST" action="' . $url . '">';
1508
-            $btn_frm .= ! empty($nonce_action) ? wp_nonce_field($nonce_action, $nonce_action . '_nonce', true, false) : '';
1505
+        $btn .= '<input id="'.$ID.'-btn" class="'.$class.'" type="submit" value="'.$text.'" '.$extra_attributes.'/>';
1506
+        if ( ! $input_only) {
1507
+            $btn_frm = '<form id="'.$ID.'-frm" method="POST" action="'.$url.'">';
1508
+            $btn_frm .= ! empty($nonce_action) ? wp_nonce_field($nonce_action, $nonce_action.'_nonce', true, false) : '';
1509 1509
             $btn_frm .= $btn;
1510 1510
             $btn_frm .= '</form>';
1511 1511
             $btn = $btn_frm;
Please login to merge, or discard this patch.
core/db_classes/EE_Import.class.php 1 patch
Indentation   +954 added lines, -954 removed lines patch added patch discarded remove patch
@@ -14,91 +14,91 @@  discard block
 block discarded – undo
14 14
 class EE_Import implements ResettableInterface
15 15
 {
16 16
 
17
-    const do_insert = 'insert';
18
-    const do_update = 'update';
19
-    const do_nothing = 'nothing';
20
-
21
-
22
-    // instance of the EE_Import object
23
-    private static $_instance;
24
-
25
-    private static $_csv_array = array();
26
-
27
-    /**
28
-     *
29
-     * @var array of model names
30
-     */
31
-    private static $_model_list = array();
32
-
33
-    private static $_columns_to_save = array();
34
-
35
-    protected $_total_inserts = 0;
36
-    protected $_total_updates = 0;
37
-    protected $_total_insert_errors = 0;
38
-    protected $_total_update_errors = 0;
39
-
40
-
41
-    /**
42
-     *        private constructor to prevent direct creation
43
-     *
44
-     * @Constructor
45
-     * @access private
46
-     * @return void
47
-     */
48
-    private function __construct()
49
-    {
50
-        $this->_total_inserts = 0;
51
-        $this->_total_updates = 0;
52
-        $this->_total_insert_errors = 0;
53
-        $this->_total_update_errors = 0;
54
-    }
55
-
56
-
57
-    /**
58
-     *    @ singleton method used to instantiate class object
59
-     *    @ access public
60
-     *
61
-     * @return EE_Import
62
-     */
63
-    public static function instance()
64
-    {
65
-        // check if class object is instantiated
66
-        if (self::$_instance === null or ! is_object(self::$_instance) or ! (self::$_instance instanceof EE_Import)) {
67
-            self::$_instance = new self();
68
-        }
69
-        return self::$_instance;
70
-    }
71
-
72
-    /**
73
-     * Resets the importer
74
-     *
75
-     * @return EE_Import
76
-     */
77
-    public static function reset()
78
-    {
79
-        self::$_instance = null;
80
-        return self::instance();
81
-    }
82
-
83
-
84
-    /**
85
-     *    @ generates HTML for a file upload input and form
86
-     *    @ access    public
87
-     *
88
-     * @param    string $title  - heading for the form
89
-     * @param    string $intro  - additional text explaing what to do
90
-     * @param    string $page   - EE Admin page to direct form to - in the form "espresso_{pageslug}"
91
-     * @param    string $action - EE Admin page route array "action" that form will direct to
92
-     * @param    string $type   - type of file to import
93
-     *                          @ return    string
94
-     */
95
-    public function upload_form($title, $intro, $form_url, $action, $type)
96
-    {
97
-
98
-        $form_url = EE_Admin_Page::add_query_args_and_nonce(array('action' => $action), $form_url);
99
-
100
-        ob_start();
101
-        ?>
17
+	const do_insert = 'insert';
18
+	const do_update = 'update';
19
+	const do_nothing = 'nothing';
20
+
21
+
22
+	// instance of the EE_Import object
23
+	private static $_instance;
24
+
25
+	private static $_csv_array = array();
26
+
27
+	/**
28
+	 *
29
+	 * @var array of model names
30
+	 */
31
+	private static $_model_list = array();
32
+
33
+	private static $_columns_to_save = array();
34
+
35
+	protected $_total_inserts = 0;
36
+	protected $_total_updates = 0;
37
+	protected $_total_insert_errors = 0;
38
+	protected $_total_update_errors = 0;
39
+
40
+
41
+	/**
42
+	 *        private constructor to prevent direct creation
43
+	 *
44
+	 * @Constructor
45
+	 * @access private
46
+	 * @return void
47
+	 */
48
+	private function __construct()
49
+	{
50
+		$this->_total_inserts = 0;
51
+		$this->_total_updates = 0;
52
+		$this->_total_insert_errors = 0;
53
+		$this->_total_update_errors = 0;
54
+	}
55
+
56
+
57
+	/**
58
+	 *    @ singleton method used to instantiate class object
59
+	 *    @ access public
60
+	 *
61
+	 * @return EE_Import
62
+	 */
63
+	public static function instance()
64
+	{
65
+		// check if class object is instantiated
66
+		if (self::$_instance === null or ! is_object(self::$_instance) or ! (self::$_instance instanceof EE_Import)) {
67
+			self::$_instance = new self();
68
+		}
69
+		return self::$_instance;
70
+	}
71
+
72
+	/**
73
+	 * Resets the importer
74
+	 *
75
+	 * @return EE_Import
76
+	 */
77
+	public static function reset()
78
+	{
79
+		self::$_instance = null;
80
+		return self::instance();
81
+	}
82
+
83
+
84
+	/**
85
+	 *    @ generates HTML for a file upload input and form
86
+	 *    @ access    public
87
+	 *
88
+	 * @param    string $title  - heading for the form
89
+	 * @param    string $intro  - additional text explaing what to do
90
+	 * @param    string $page   - EE Admin page to direct form to - in the form "espresso_{pageslug}"
91
+	 * @param    string $action - EE Admin page route array "action" that form will direct to
92
+	 * @param    string $type   - type of file to import
93
+	 *                          @ return    string
94
+	 */
95
+	public function upload_form($title, $intro, $form_url, $action, $type)
96
+	{
97
+
98
+		$form_url = EE_Admin_Page::add_query_args_and_nonce(array('action' => $action), $form_url);
99
+
100
+		ob_start();
101
+		?>
102 102
         <div class="ee-upload-form-dv">
103 103
             <h3><?php echo $title; ?></h3>
104 104
             <p><?php echo $intro; ?></p>
@@ -114,878 +114,878 @@  discard block
 block discarded – undo
114 114
                 <b><?php _e('Attention', 'event_espresso'); ?></b><br/>
115 115
                 <?php echo sprintf(__('Accepts .%s file types only.', 'event_espresso'), $type); ?>
116 116
                 <?php echo __(
117
-                    'Please only import CSV files exported from Event Espresso, or compatible 3rd-party software.',
118
-                    'event_espresso'
119
-                ); ?>
117
+					'Please only import CSV files exported from Event Espresso, or compatible 3rd-party software.',
118
+					'event_espresso'
119
+				); ?>
120 120
             </p>
121 121
 
122 122
         </div>
123 123
 
124 124
         <?php
125
-        $uploader = ob_get_clean();
126
-        return $uploader;
127
-    }
128
-
129
-
130
-    /**
131
-     * @Import Event Espresso data - some code "borrowed" from event espresso csv_import.php
132
-     * @access public
133
-     * @return boolean success
134
-     */
135
-    public function import()
136
-    {
137
-
138
-        require_once(EE_CLASSES . 'EE_CSV.class.php');
139
-        $this->EE_CSV = EE_CSV::instance();
140
-
141
-        if (isset($_REQUEST['import'])) {
142
-            if (isset($_POST['csv_submitted'])) {
143
-                switch ($_FILES['file']['error'][0]) {
144
-                    case UPLOAD_ERR_OK:
145
-                        $error_msg = false;
146
-                        break;
147
-                    case UPLOAD_ERR_INI_SIZE:
148
-                        $error_msg = __(
149
-                            "'The uploaded file exceeds the upload_max_filesize directive in php.ini.'",
150
-                            "event_espresso"
151
-                        );
152
-                        break;
153
-                    case UPLOAD_ERR_FORM_SIZE:
154
-                        $error_msg = __(
155
-                            'The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form.',
156
-                            "event_espresso"
157
-                        );
158
-                        break;
159
-                    case UPLOAD_ERR_PARTIAL:
160
-                        $error_msg = __('The uploaded file was only partially uploaded.', "event_espresso");
161
-                        break;
162
-                    case UPLOAD_ERR_NO_FILE:
163
-                        $error_msg = __('No file was uploaded.', "event_espresso");
164
-                        break;
165
-                    case UPLOAD_ERR_NO_TMP_DIR:
166
-                        $error_msg = __('Missing a temporary folder.', "event_espresso");
167
-                        break;
168
-                    case UPLOAD_ERR_CANT_WRITE:
169
-                        $error_msg = __('Failed to write file to disk.', "event_espresso");
170
-                        break;
171
-                    case UPLOAD_ERR_EXTENSION:
172
-                        $error_msg = __('File upload stopped by extension.', "event_espresso");
173
-                        break;
174
-                    default:
175
-                        $error_msg = __(
176
-                            'An unknown error occurred and the file could not be uploaded',
177
-                            "event_espresso"
178
-                        );
179
-                        break;
180
-                }
181
-
182
-                if (! $error_msg) {
183
-                    $filename = $_FILES['file']['name'][0];
184
-                    $file_ext = substr(strrchr($filename, '.'), 1);
185
-                    $file_type = $_FILES['file']['type'][0];
186
-                    $temp_file = $_FILES['file']['tmp_name'][0];
187
-                    $filesize = $_FILES['file']['size'][0] / 1024;// convert from bytes to KB
188
-
189
-                    if ($file_ext == 'csv') {
190
-                        $max_upload = $this->EE_CSV->get_max_upload_size();// max upload size in KB
191
-                        if ($filesize < $max_upload || true) {
192
-                            $wp_upload_dir = str_replace(array('\\', '/'), '/', wp_upload_dir());
193
-                            $path_to_file = $wp_upload_dir['basedir'] . '/espresso/' . $filename;
194
-
195
-                            if (move_uploaded_file($temp_file, $path_to_file)) {
196
-                                // convert csv to array
197
-                                $this->csv_array = $this->EE_CSV->import_csv_to_model_data_array($path_to_file);
198
-
199
-                                // was data successfully stored in an array?
200
-                                if (is_array($this->csv_array)) {
201
-                                    $import_what = str_replace('csv_import_', '', $_REQUEST['action']);
202
-                                    $import_what = str_replace('_', ' ', ucwords($import_what));
203
-                                    $processed_data = $this->csv_array;
204
-                                    $this->columns_to_save = false;
205
-
206
-                                    // if any imports require funcky processing, we'll catch them in the switch
207
-                                    switch ($_REQUEST['action']) {
208
-                                        case "import_events":
209
-                                        case "event_list":
210
-                                            $import_what = 'Event Details';
211
-                                            break;
212
-
213
-                                        case 'groupon_import_csv':
214
-                                            $import_what = 'Groupon Codes';
215
-                                            $processed_data = $this->process_groupon_codes();
216
-                                            break;
217
-                                    }
218
-                                    // save processed codes to db
219
-                                    if ($this->save_csv_data_array_to_db($processed_data, $this->columns_to_save)) {
220
-                                        return true;
221
-                                    }
222
-                                } else {
223
-                                    // no array? must be an error
224
-                                    EE_Error::add_error(
225
-                                        sprintf(__("No file seems to have been uploaded", "event_espresso")),
226
-                                        __FILE__,
227
-                                        __FUNCTION__,
228
-                                        __LINE__
229
-                                    );
230
-                                    return false;
231
-                                }
232
-                            } else {
233
-                                EE_Error::add_error(
234
-                                    sprintf(__("%s was not successfully uploaded", "event_espresso"), $filename),
235
-                                    __FILE__,
236
-                                    __FUNCTION__,
237
-                                    __LINE__
238
-                                );
239
-                                return false;
240
-                            }
241
-                        } else {
242
-                            EE_Error::add_error(
243
-                                sprintf(
244
-                                    __(
245
-                                        "%s was too large of a file and could not be uploaded. The max filesize is %s' KB.",
246
-                                        "event_espresso"
247
-                                    ),
248
-                                    $filename,
249
-                                    $max_upload
250
-                                ),
251
-                                __FILE__,
252
-                                __FUNCTION__,
253
-                                __LINE__
254
-                            );
255
-                            return false;
256
-                        }
257
-                    } else {
258
-                        EE_Error::add_error(
259
-                            sprintf(__("%s  had an invalid file extension, not uploaded", "event_espresso"), $filename),
260
-                            __FILE__,
261
-                            __FUNCTION__,
262
-                            __LINE__
263
-                        );
264
-                        return false;
265
-                    }
266
-                } else {
267
-                    EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__);
268
-                    return false;
269
-                }
270
-            }
271
-        }
272
-        return;
273
-    }
274
-
275
-
276
-    /**
277
-     *    Given an array of data (usually from a CSV import) attempts to save that data to the db.
278
-     *    If $model_name ISN'T provided, assumes that this is a 3d array, with toplevel keys being model names,
279
-     *    next level being numeric indexes adn each value representing a model object, and the last layer down
280
-     *    being keys of model fields and their proposed values.
281
-     *    If $model_name IS provided, assumes a 2d array of the bottom two layers previously mentioned.
282
-     *    If the CSV data says (in the metadata row) that it's from the SAME database,
283
-     *    we treat the IDs in the CSV as the normal IDs, and try to update those records. However, if those
284
-     *    IDs DON'T exist in the database, they're treated as temporary IDs,
285
-     *    which can used elsewhere to refer to the same object. Once an item
286
-     *    with a temporary ID gets inserted, we record its mapping from temporary
287
-     *    ID to real ID, and use the real ID in place of the temporary ID
288
-     *    when that temporary ID was used as a foreign key.
289
-     *    If the CSV data says (in the metadata again) that it's from a DIFFERENT database,
290
-     *    we treat all the IDs in the CSV as temporary ID- eg, if the CSV specifies an event with
291
-     *    ID 1, and the database already has an event with ID 1, we assume that's just a coincidence,
292
-     *    and insert a new event, and map it's temporary ID of 1 over to its new real ID.
293
-     *    An important exception are non-auto-increment primary keys. If one entry in the
294
-     *    CSV file has the same ID as one in the DB, we assume they are meant to be
295
-     *    the same item, and instead update the item in the DB with that same ID.
296
-     *    Also note, we remember the mappings permanently. So the 2nd, 3rd, and 10000th
297
-     *    time you import a CSV from a different site, we remember their mappings, and
298
-     * will try to update the item in the DB instead of inserting another item (eg
299
-     * if we previously imported an event with temporary ID 1, and then it got a
300
-     * real ID of 123, we remember that. So the next time we import an event with
301
-     * temporary ID, from the same site, we know that it's real ID is 123, and will
302
-     * update that event, instead of adding a new event).
303
-     *
304
-     * @access public
305
-     * @param array $csv_data_array - the array containing the csv data produced from
306
-     *                              EE_CSV::import_csv_to_model_data_array()
307
-     * @param array $fields_to_save - an array containing the csv column names as keys with the corresponding db table
308
-     *                              fields they will be saved to
309
-     * @return TRUE on success, FALSE on fail
310
-     * @throws \EE_Error
311
-     */
312
-    public function save_csv_data_array_to_db($csv_data_array, $model_name = false)
313
-    {
314
-        $success = false;
315
-        $error = false;
316
-        // whther to treat this import as if it's data froma different database or not
317
-        // ie, if it IS from a different database, ignore foreign keys whihf
318
-        $export_from_site_a_to_b = true;
319
-        // first level of array is not table information but a table name was passed to the function
320
-        // array is only two levels deep, so let's fix that by adding a level, else the next steps will fail
321
-        if ($model_name) {
322
-            $csv_data_array = array($csv_data_array);
323
-        }
324
-        // begin looking through the $csv_data_array, expecting the toplevel key to be the model's name...
325
-        $old_site_url = 'none-specified';
326
-        // hanlde metadata
327
-        if (isset($csv_data_array[ EE_CSV::metadata_header ])) {
328
-            $csv_metadata = array_shift($csv_data_array[ EE_CSV::metadata_header ]);
329
-            // ok so its metadata, dont try to save it to ehte db obviously...
330
-            if (isset($csv_metadata['site_url']) && $csv_metadata['site_url'] == site_url()) {
331
-                EE_Error::add_attention(
332
-                    sprintf(
333
-                        __(
334
-                            "CSV Data appears to be from the same database, so attempting to update data",
335
-                            "event_espresso"
336
-                        )
337
-                    )
338
-                );
339
-                $export_from_site_a_to_b = false;
340
-            } else {
341
-                $old_site_url = isset($csv_metadata['site_url']) ? $csv_metadata['site_url'] : $old_site_url;
342
-                EE_Error::add_attention(
343
-                    sprintf(
344
-                        __(
345
-                            "CSV Data appears to be from a different database (%s instead of %s), so we assume IDs in the CSV data DO NOT correspond to IDs in this database",
346
-                            "event_espresso"
347
-                        ),
348
-                        $old_site_url,
349
-                        site_url()
350
-                    )
351
-                );
352
-            };
353
-            unset($csv_data_array[ EE_CSV::metadata_header ]);
354
-        }
355
-        /**
356
-         * @var $old_db_to_new_db_mapping 2d array: toplevel keys being model names, bottom-level keys being the original key, and
357
-         * the value will be the newly-inserted ID.
358
-         * If we have already imported data from the same website via CSV, it shoudl be kept in this wp option
359
-         */
360
-        $old_db_to_new_db_mapping = get_option('ee_id_mapping_from' . sanitize_title($old_site_url), array());
361
-        if ($old_db_to_new_db_mapping) {
362
-            EE_Error::add_attention(
363
-                sprintf(
364
-                    __(
365
-                        "We noticed you have imported data via CSV from %s before. Because of this, IDs in your CSV have been mapped to their new IDs in %s",
366
-                        "event_espresso"
367
-                    ),
368
-                    $old_site_url,
369
-                    site_url()
370
-                )
371
-            );
372
-        }
373
-        $old_db_to_new_db_mapping = $this->save_data_rows_to_db(
374
-            $csv_data_array,
375
-            $export_from_site_a_to_b,
376
-            $old_db_to_new_db_mapping
377
-        );
378
-
379
-        // save the mapping from old db to new db in case they try re-importing the same data from the same website again
380
-        update_option('ee_id_mapping_from' . sanitize_title($old_site_url), $old_db_to_new_db_mapping);
381
-
382
-        if ($this->_total_updates > 0) {
383
-            EE_Error::add_success(
384
-                sprintf(
385
-                    __("%s existing records in the database were updated.", "event_espresso"),
386
-                    $this->_total_updates
387
-                )
388
-            );
389
-            $success = true;
390
-        }
391
-        if ($this->_total_inserts > 0) {
392
-            EE_Error::add_success(
393
-                sprintf(__("%s new records were added to the database.", "event_espresso"), $this->_total_inserts)
394
-            );
395
-            $success = true;
396
-        }
397
-
398
-        if ($this->_total_update_errors > 0) {
399
-            EE_Error::add_error(
400
-                sprintf(
401
-                    __(
402
-                        "'One or more errors occurred, and a total of %s existing records in the database were <strong>not</strong> updated.'",
403
-                        "event_espresso"
404
-                    ),
405
-                    $this->_total_update_errors
406
-                ),
407
-                __FILE__,
408
-                __FUNCTION__,
409
-                __LINE__
410
-            );
411
-            $error = true;
412
-        }
413
-        if ($this->_total_insert_errors > 0) {
414
-            EE_Error::add_error(
415
-                sprintf(
416
-                    __(
417
-                        "One or more errors occurred, and a total of %s new records were <strong>not</strong> added to the database.'",
418
-                        "event_espresso"
419
-                    ),
420
-                    $this->_total_insert_errors
421
-                ),
422
-                __FILE__,
423
-                __FUNCTION__,
424
-                __LINE__
425
-            );
426
-            $error = true;
427
-        }
428
-
429
-        // lastly, we need to update the datetime and ticket sold amounts
430
-        // as those may have been affected by this
431
-        EEM_Ticket::instance()->update_tickets_sold(EEM_Ticket::instance()->get_all());
432
-
433
-        // if there was at least one success and absolutely no errors
434
-        if ($success && ! $error) {
435
-            return true;
436
-        } else {
437
-            return false;
438
-        }
439
-    }
440
-
441
-
442
-    /**
443
-     * Processes the array of data, given the knowledge that it's from the same database or a different one,
444
-     * and the mapping from temporary IDs to real IDs.
445
-     * If the data is from a different database, we treat the primary keys and their corresponding
446
-     * foreign keys as "temp Ids", basically identifiers that get mapped to real primary keys
447
-     * in the real target database. As items are inserted, their temporary primary keys
448
-     * are mapped to the real IDs in the target database. Also, before doing any update or
449
-     * insert, we replace all the temp ID which are foreign keys with their mapped real IDs.
450
-     * An exception: string primary keys are treated as real IDs, or else we'd need to
451
-     * dynamically generate new string primary keys which would be very awkard for the country table etc.
452
-     * Also, models with no primary key are strange too. We combine use their primar key INDEX (a
453
-     * combination of fields) to create a unique string identifying the row and store
454
-     * those in the mapping.
455
-     *
456
-     * If the data is from the same database, we usually treat primary keys as real IDs.
457
-     * An exception is if there is nothing in the database for that ID. If that's the case,
458
-     * we need to insert a new row for that ID, and then map from the non-existent ID
459
-     * to the newly-inserted real ID.
460
-     *
461
-     * @param type $csv_data_array
462
-     * @param type $export_from_site_a_to_b
463
-     * @param type $old_db_to_new_db_mapping
464
-     * @return array updated $old_db_to_new_db_mapping
465
-     */
466
-    public function save_data_rows_to_db($csv_data_array, $export_from_site_a_to_b, $old_db_to_new_db_mapping)
467
-    {
468
-        foreach ($csv_data_array as $model_name_in_csv_data => $model_data_from_import) {
469
-            // now check that assumption was correct. If
470
-            if (EE_Registry::instance()->is_model_name($model_name_in_csv_data)) {
471
-                $model_name = $model_name_in_csv_data;
472
-            } else {
473
-                // no table info in the array and no table name passed to the function?? FAIL
474
-                EE_Error::add_error(
475
-                    __(
476
-                        'No table information was specified and/or found, therefore the import could not be completed',
477
-                        'event_espresso'
478
-                    ),
479
-                    __FILE__,
480
-                    __FUNCTION__,
481
-                    __LINE__
482
-                );
483
-                return false;
484
-            }
485
-            /* @var $model EEM_Base */
486
-            $model = EE_Registry::instance()->load_model($model_name);
487
-
488
-            // so without further ado, scanning all the data provided for primary keys and their inital values
489
-            foreach ($model_data_from_import as $model_object_data) {
490
-                // before we do ANYTHING, make sure the csv row wasn't just completely blank
491
-                $row_is_completely_empty = true;
492
-                foreach ($model_object_data as $field) {
493
-                    if ($field) {
494
-                        $row_is_completely_empty = false;
495
-                    }
496
-                }
497
-                if ($row_is_completely_empty) {
498
-                    continue;
499
-                }
500
-                // find the PK in the row of data (or a combined key if
501
-                // there is no primary key)
502
-                if ($model->has_primary_key_field()) {
503
-                    $id_in_csv = $model_object_data[ $model->primary_key_name() ];
504
-                } else {
505
-                    $id_in_csv = $model->get_index_primary_key_string($model_object_data);
506
-                }
507
-
508
-
509
-                $model_object_data = $this->_replace_temp_ids_with_mappings(
510
-                    $model_object_data,
511
-                    $model,
512
-                    $old_db_to_new_db_mapping,
513
-                    $export_from_site_a_to_b
514
-                );
515
-                // now we need to decide if we're going to add a new model object given the $model_object_data,
516
-                // or just update.
517
-                if ($export_from_site_a_to_b) {
518
-                    $what_to_do = $this->_decide_whether_to_insert_or_update_given_data_from_other_db(
519
-                        $id_in_csv,
520
-                        $model_object_data,
521
-                        $model,
522
-                        $old_db_to_new_db_mapping
523
-                    );
524
-                } else {// this is just a re-import
525
-                    $what_to_do = $this->_decide_whether_to_insert_or_update_given_data_from_same_db(
526
-                        $id_in_csv,
527
-                        $model_object_data,
528
-                        $model,
529
-                        $old_db_to_new_db_mapping
530
-                    );
531
-                }
532
-                if ($what_to_do == self::do_nothing) {
533
-                    continue;
534
-                }
535
-
536
-                // double-check we actually want to insert, if that's what we're planning
537
-                // based on whether this item would be unique in the DB or not
538
-                if ($what_to_do == self::do_insert) {
539
-                    // we're supposed to be inserting. But wait, will this thing
540
-                    // be acceptable if inserted?
541
-                    $conflicting = $model->get_one_conflicting($model_object_data, false);
542
-                    if ($conflicting) {
543
-                        // ok, this item would conflict if inserted. Just update the item that it conflicts with.
544
-                        $what_to_do = self::do_update;
545
-                        // and if this model has a primary key, remember its mapping
546
-                        if ($model->has_primary_key_field()) {
547
-                            $old_db_to_new_db_mapping[ $model_name ][ $id_in_csv ] = $conflicting->ID();
548
-                            $model_object_data[ $model->primary_key_name() ] = $conflicting->ID();
549
-                        } else {
550
-                            // we want to update this conflicting item, instead of inserting a conflicting item
551
-                            // so we need to make sure they match entirely (its possible that they only conflicted on one field, but we need them to match on other fields
552
-                            // for the WHERE conditions in the update). At the time of this comment, there were no models like this
553
-                            foreach ($model->get_combined_primary_key_fields() as $key_field) {
554
-                                $model_object_data[ $key_field->get_name() ] = $conflicting->get(
555
-                                    $key_field->get_name()
556
-                                );
557
-                            }
558
-                        }
559
-                    }
560
-                }
561
-                if ($what_to_do == self::do_insert) {
562
-                    $old_db_to_new_db_mapping = $this->_insert_from_data_array(
563
-                        $id_in_csv,
564
-                        $model_object_data,
565
-                        $model,
566
-                        $old_db_to_new_db_mapping
567
-                    );
568
-                } elseif ($what_to_do == self::do_update) {
569
-                    $old_db_to_new_db_mapping = $this->_update_from_data_array(
570
-                        $id_in_csv,
571
-                        $model_object_data,
572
-                        $model,
573
-                        $old_db_to_new_db_mapping
574
-                    );
575
-                } else {
576
-                    throw new EE_Error(
577
-                        sprintf(
578
-                            __(
579
-                                'Programming error. We shoudl be inserting or updating, but instead we are being told to "%s", whifh is invalid',
580
-                                'event_espresso'
581
-                            ),
582
-                            $what_to_do
583
-                        )
584
-                    );
585
-                }
586
-            }
587
-        }
588
-        return $old_db_to_new_db_mapping;
589
-    }
590
-
591
-
592
-    /**
593
-     * Decides whether or not to insert, given that this data is from another database.
594
-     * So, if the primary key of this $model_object_data already exists in the database,
595
-     * it's just a coincidence and we should still insert. The only time we should
596
-     * update is when we know what it maps to, or there's something that would
597
-     * conflict (and we should instead just update that conflicting thing)
598
-     *
599
-     * @param string   $id_in_csv
600
-     * @param array    $model_object_data        by reference so it can be modified
601
-     * @param EEM_Base $model
602
-     * @param array    $old_db_to_new_db_mapping by reference so it can be modified
603
-     * @return string one of the consts on this class that starts with do_*
604
-     */
605
-    protected function _decide_whether_to_insert_or_update_given_data_from_other_db(
606
-        $id_in_csv,
607
-        $model_object_data,
608
-        $model,
609
-        $old_db_to_new_db_mapping
610
-    ) {
611
-        $model_name = $model->get_this_model_name();
612
-        // if it's a site-to-site export-and-import, see if this modelobject's id
613
-        // in the old data that we know of
614
-        if (isset($old_db_to_new_db_mapping[ $model_name ][ $id_in_csv ])) {
615
-            return self::do_update;
616
-        } else {
617
-            return self::do_insert;
618
-        }
619
-    }
620
-
621
-    /**
622
-     * If this thing basically already exists in the database, we want to update it;
623
-     * otherwise insert it (ie, someone tweaked the CSV file, or the item was
624
-     * deleted in the database so it should be re-inserted)
625
-     *
626
-     * @param type     $id_in_csv
627
-     * @param type     $model_object_data
628
-     * @param EEM_Base $model
629
-     * @param type     $old_db_to_new_db_mapping
630
-     * @return
631
-     */
632
-    protected function _decide_whether_to_insert_or_update_given_data_from_same_db(
633
-        $id_in_csv,
634
-        $model_object_data,
635
-        $model
636
-    ) {
637
-        // in this case, check if this thing ACTUALLY exists in the database
638
-        if ($model->get_one_conflicting($model_object_data)) {
639
-            return self::do_update;
640
-        } else {
641
-            return self::do_insert;
642
-        }
643
-    }
644
-
645
-    /**
646
-     * Using the $old_db_to_new_db_mapping array, replaces all the temporary IDs
647
-     * with their mapped real IDs. Eg, if importing from site A to B, the mapping
648
-     * file may indicate that the ID "my_event_id" maps to an actual event ID of 123.
649
-     * So this function searches for any event temp Ids called "my_event_id" and
650
-     * replaces them with 123.
651
-     * Also, if there is no temp ID for the INT foreign keys from another database,
652
-     * replaces them with 0 or the field's default.
653
-     *
654
-     * @param type     $model_object_data
655
-     * @param EEM_Base $model
656
-     * @param type     $old_db_to_new_db_mapping
657
-     * @param boolean  $export_from_site_a_to_b
658
-     * @return array updated model object data with temp IDs removed
659
-     */
660
-    protected function _replace_temp_ids_with_mappings(
661
-        $model_object_data,
662
-        $model,
663
-        $old_db_to_new_db_mapping,
664
-        $export_from_site_a_to_b
665
-    ) {
666
-        // if this model object's primary key is in the mapping, replace it
667
-        if (
668
-            $model->has_primary_key_field() &&
669
-            $model->get_primary_key_field()->is_auto_increment() &&
670
-            isset($old_db_to_new_db_mapping[ $model->get_this_model_name() ]) &&
671
-            isset(
672
-                $old_db_to_new_db_mapping[ $model->get_this_model_name() ][ $model_object_data[ $model->primary_key_name() ] ]
673
-            )
674
-        ) {
675
-            $model_object_data[ $model->primary_key_name() ] = $old_db_to_new_db_mapping[ $model->get_this_model_name(
676
-            ) ][ $model_object_data[ $model->primary_key_name() ] ];
677
-        }
678
-
679
-        try {
680
-            $model_name_field = $model->get_field_containing_related_model_name();
681
-            $models_pointed_to_by_model_name_field = $model_name_field->get_model_names_pointed_to();
682
-        } catch (EE_Error $e) {
683
-            $model_name_field = null;
684
-            $models_pointed_to_by_model_name_field = array();
685
-        }
686
-        foreach ($model->field_settings(true) as $field_obj) {
687
-            if ($field_obj instanceof EE_Foreign_Key_Int_Field) {
688
-                $models_pointed_to = $field_obj->get_model_names_pointed_to();
689
-                $found_a_mapping = false;
690
-                foreach ($models_pointed_to as $model_pointed_to_by_fk) {
691
-                    if ($model_name_field) {
692
-                        $value_of_model_name_field = $model_object_data[ $model_name_field->get_name() ];
693
-                        if ($value_of_model_name_field == $model_pointed_to_by_fk) {
694
-                            $model_object_data[ $field_obj->get_name() ] = $this->_find_mapping_in(
695
-                                $model_object_data[ $field_obj->get_name() ],
696
-                                $model_pointed_to_by_fk,
697
-                                $old_db_to_new_db_mapping,
698
-                                $export_from_site_a_to_b
699
-                            );
700
-                            $found_a_mapping = true;
701
-                            break;
702
-                        }
703
-                    } else {
704
-                        $model_object_data[ $field_obj->get_name() ] = $this->_find_mapping_in(
705
-                            $model_object_data[ $field_obj->get_name() ],
706
-                            $model_pointed_to_by_fk,
707
-                            $old_db_to_new_db_mapping,
708
-                            $export_from_site_a_to_b
709
-                        );
710
-                        $found_a_mapping = true;
711
-                    }
712
-                    // once we've found a mapping for this field no need to continue
713
-                    if ($found_a_mapping) {
714
-                        break;
715
-                    }
716
-                }
717
-            } else {
718
-                // it's a string foreign key (which we leave alone, because those are things
719
-                // like country names, which we'd really rather not make 2 USAs etc (we'd actually
720
-                // prefer to just update one)
721
-                // or it's just a regular value that ought to be replaced
722
-            }
723
-        }
724
-        //
725
-        if ($model instanceof EEM_Term_Taxonomy) {
726
-            $model_object_data = $this->_handle_split_term_ids($model_object_data);
727
-        }
728
-        return $model_object_data;
729
-    }
730
-
731
-    /**
732
-     * If the data was exported PRE-4.2, but then imported POST-4.2, then the term_id
733
-     * this term-taxonomy refers to may be out-of-date so we need to update it.
734
-     * see https://make.wordpress.org/core/2015/02/16/taxonomy-term-splitting-in-4-2-a-developer-guide/
735
-     *
736
-     * @param type $model_object_data
737
-     * @return array new model object data
738
-     */
739
-    protected function _handle_split_term_ids($model_object_data)
740
-    {
741
-        if (
742
-            isset($model_object_data['term_id'])
743
-            && isset($model_object_data['taxonomy'])
744
-            && apply_filters(
745
-                'FHEE__EE_Import__handle_split_term_ids__function_exists',
746
-                function_exists('wp_get_split_term'),
747
-                $model_object_data
748
-            )
749
-        ) {
750
-            $new_term_id = wp_get_split_term($model_object_data['term_id'], $model_object_data['taxonomy']);
751
-            if ($new_term_id) {
752
-                $model_object_data['term_id'] = $new_term_id;
753
-            }
754
-        }
755
-        return $model_object_data;
756
-    }
757
-
758
-    /**
759
-     * Given the object's ID and its model's name, find it int he mapping data,
760
-     * bearing in mind where it came from
761
-     *
762
-     * @param type   $object_id
763
-     * @param string $model_name
764
-     * @param array  $old_db_to_new_db_mapping
765
-     * @param type   $export_from_site_a_to_b
766
-     * @return int
767
-     */
768
-    protected function _find_mapping_in($object_id, $model_name, $old_db_to_new_db_mapping, $export_from_site_a_to_b)
769
-    {
770
-        if (isset($old_db_to_new_db_mapping[ $model_name ][ $object_id ])) {
771
-            return $old_db_to_new_db_mapping[ $model_name ][ $object_id ];
772
-        } elseif ($object_id == '0' || $object_id == '') {
773
-            // leave as-is
774
-            return $object_id;
775
-        } elseif ($export_from_site_a_to_b) {
776
-            // we couldn't find a mapping for this, and it's from a different site,
777
-            // so blank it out
778
-            return null;
779
-        } elseif (! $export_from_site_a_to_b) {
780
-            // we coudln't find a mapping for this, but it's from thsi DB anyway
781
-            // so let's just leave it as-is
782
-            return $object_id;
783
-        }
784
-    }
785
-
786
-    /**
787
-     *
788
-     * @param type     $id_in_csv
789
-     * @param type     $model_object_data
790
-     * @param EEM_Base $model
791
-     * @param type     $old_db_to_new_db_mapping
792
-     * @return array updated $old_db_to_new_db_mapping
793
-     */
794
-    protected function _insert_from_data_array($id_in_csv, $model_object_data, $model, $old_db_to_new_db_mapping)
795
-    {
796
-        // remove the primary key, if there is one (we don't want it for inserts OR updates)
797
-        // we'll put it back in if we need it
798
-        if ($model->has_primary_key_field() && $model->get_primary_key_field()->is_auto_increment()) {
799
-            $effective_id = $model_object_data[ $model->primary_key_name() ];
800
-            unset($model_object_data[ $model->primary_key_name() ]);
801
-        } else {
802
-            $effective_id = $model->get_index_primary_key_string($model_object_data);
803
-        }
804
-        // the model takes care of validating the CSV's input
805
-        try {
806
-            $new_id = $model->insert($model_object_data);
807
-            if ($new_id) {
808
-                $old_db_to_new_db_mapping[ $model->get_this_model_name() ][ $id_in_csv ] = $new_id;
809
-                $this->_total_inserts++;
810
-                EE_Error::add_success(
811
-                    sprintf(
812
-                        __("Successfully added new %s (with id %s) with csv data %s", "event_espresso"),
813
-                        $model->get_this_model_name(),
814
-                        $new_id,
815
-                        implode(",", $model_object_data)
816
-                    )
817
-                );
818
-            } else {
819
-                $this->_total_insert_errors++;
820
-                // put the ID used back in there for the error message
821
-                if ($model->has_primary_key_field()) {
822
-                    $model_object_data[ $model->primary_key_name() ] = $effective_id;
823
-                }
824
-                EE_Error::add_error(
825
-                    sprintf(
826
-                        __("Could not insert new %s with the csv data: %s", "event_espresso"),
827
-                        $model->get_this_model_name(),
828
-                        http_build_query($model_object_data)
829
-                    ),
830
-                    __FILE__,
831
-                    __FUNCTION__,
832
-                    __LINE__
833
-                );
834
-            }
835
-        } catch (EE_Error $e) {
836
-            $this->_total_insert_errors++;
837
-            if ($model->has_primary_key_field()) {
838
-                $model_object_data[ $model->primary_key_name() ] = $effective_id;
839
-            }
840
-            EE_Error::add_error(
841
-                sprintf(
842
-                    __("Could not insert new %s with the csv data: %s because %s", "event_espresso"),
843
-                    $model->get_this_model_name(),
844
-                    implode(",", $model_object_data),
845
-                    $e->getMessage()
846
-                ),
847
-                __FILE__,
848
-                __FUNCTION__,
849
-                __LINE__
850
-            );
851
-        }
852
-        return $old_db_to_new_db_mapping;
853
-    }
854
-
855
-    /**
856
-     * Given the model object data, finds the row to update and updates it
857
-     *
858
-     * @param string|int $id_in_csv
859
-     * @param array      $model_object_data
860
-     * @param EEM_Base   $model
861
-     * @param array      $old_db_to_new_db_mapping
862
-     * @return array updated $old_db_to_new_db_mapping
863
-     */
864
-    protected function _update_from_data_array($id_in_csv, $model_object_data, $model, $old_db_to_new_db_mapping)
865
-    {
866
-        try {
867
-            // let's keep two copies of the model object data:
868
-            // one for performing an update, one for everthing else
869
-            $model_object_data_for_update = $model_object_data;
870
-            if ($model->has_primary_key_field()) {
871
-                $conditions = array($model->primary_key_name() => $model_object_data[ $model->primary_key_name() ]);
872
-                // remove the primary key because we shouldn't use it for updating
873
-                unset($model_object_data_for_update[ $model->primary_key_name() ]);
874
-            } elseif ($model->get_combined_primary_key_fields() > 1) {
875
-                $conditions = array();
876
-                foreach ($model->get_combined_primary_key_fields() as $key_field) {
877
-                    $conditions[ $key_field->get_name() ] = $model_object_data[ $key_field->get_name() ];
878
-                }
879
-            } else {
880
-                $model->primary_key_name(
881
-                );// this shoudl just throw an exception, explaining that we dont have a primary key (or a combine dkey)
882
-            }
883
-
884
-            $success = $model->update($model_object_data_for_update, array($conditions));
885
-            if ($success) {
886
-                $this->_total_updates++;
887
-                EE_Error::add_success(
888
-                    sprintf(
889
-                        __("Successfully updated %s with csv data %s", "event_espresso"),
890
-                        $model->get_this_model_name(),
891
-                        implode(",", $model_object_data_for_update)
892
-                    )
893
-                );
894
-                // we should still record the mapping even though it was an update
895
-                // because if we were going to insert somethign but it was going to conflict
896
-                // we would have last-minute decided to update. So we'd like to know what we updated
897
-                // and so we record what record ended up being updated using the mapping
898
-                if ($model->has_primary_key_field()) {
899
-                    $new_key_for_mapping = $model_object_data[ $model->primary_key_name() ];
900
-                } else {
901
-                    // no primary key just a combined key
902
-                    $new_key_for_mapping = $model->get_index_primary_key_string($model_object_data);
903
-                }
904
-                $old_db_to_new_db_mapping[ $model->get_this_model_name() ][ $id_in_csv ] = $new_key_for_mapping;
905
-            } else {
906
-                $matched_items = $model->get_all(array($conditions));
907
-                if (! $matched_items) {
908
-                    // no items were matched (so we shouldn't have updated)... but then we should have inserted? what the heck?
909
-                    $this->_total_update_errors++;
910
-                    EE_Error::add_error(
911
-                        sprintf(
912
-                            __(
913
-                                "Could not update %s with the csv data: '%s' for an unknown reason (using WHERE conditions %s)",
914
-                                "event_espresso"
915
-                            ),
916
-                            $model->get_this_model_name(),
917
-                            http_build_query($model_object_data),
918
-                            http_build_query($conditions)
919
-                        ),
920
-                        __FILE__,
921
-                        __FUNCTION__,
922
-                        __LINE__
923
-                    );
924
-                } else {
925
-                    $this->_total_updates++;
926
-                    EE_Error::add_success(
927
-                        sprintf(
928
-                            __(
929
-                                "%s with csv data '%s' was found in the database and didn't need updating because all the data is identical.",
930
-                                "event_espresso"
931
-                            ),
932
-                            $model->get_this_model_name(),
933
-                            implode(",", $model_object_data)
934
-                        )
935
-                    );
936
-                }
937
-            }
938
-        } catch (EE_Error $e) {
939
-            $this->_total_update_errors++;
940
-            $basic_message = sprintf(
941
-                __("Could not update %s with the csv data: %s because %s", "event_espresso"),
942
-                $model->get_this_model_name(),
943
-                implode(",", $model_object_data),
944
-                $e->getMessage()
945
-            );
946
-            $debug_message = $basic_message . ' Stack trace: ' . $e->getTraceAsString();
947
-            EE_Error::add_error("$basic_message | $debug_message", __FILE__, __FUNCTION__, __LINE__);
948
-        }
949
-        return $old_db_to_new_db_mapping;
950
-    }
951
-
952
-    /**
953
-     * Gets the number of inserts performed since importer was instantiated or reset
954
-     *
955
-     * @return int
956
-     */
957
-    public function get_total_inserts()
958
-    {
959
-        return $this->_total_inserts;
960
-    }
961
-
962
-    /**
963
-     *  Gets the number of insert errors since importer was instantiated or reset
964
-     *
965
-     * @return int
966
-     */
967
-    public function get_total_insert_errors()
968
-    {
969
-        return $this->_total_insert_errors;
970
-    }
971
-
972
-    /**
973
-     *  Gets the number of updates performed since importer was instantiated or reset
974
-     *
975
-     * @return int
976
-     */
977
-    public function get_total_updates()
978
-    {
979
-        return $this->_total_updates;
980
-    }
981
-
982
-    /**
983
-     *  Gets the number of update errors since importer was instantiated or reset
984
-     *
985
-     * @return int
986
-     */
987
-    public function get_total_update_errors()
988
-    {
989
-        return $this->_total_update_errors;
990
-    }
125
+		$uploader = ob_get_clean();
126
+		return $uploader;
127
+	}
128
+
129
+
130
+	/**
131
+	 * @Import Event Espresso data - some code "borrowed" from event espresso csv_import.php
132
+	 * @access public
133
+	 * @return boolean success
134
+	 */
135
+	public function import()
136
+	{
137
+
138
+		require_once(EE_CLASSES . 'EE_CSV.class.php');
139
+		$this->EE_CSV = EE_CSV::instance();
140
+
141
+		if (isset($_REQUEST['import'])) {
142
+			if (isset($_POST['csv_submitted'])) {
143
+				switch ($_FILES['file']['error'][0]) {
144
+					case UPLOAD_ERR_OK:
145
+						$error_msg = false;
146
+						break;
147
+					case UPLOAD_ERR_INI_SIZE:
148
+						$error_msg = __(
149
+							"'The uploaded file exceeds the upload_max_filesize directive in php.ini.'",
150
+							"event_espresso"
151
+						);
152
+						break;
153
+					case UPLOAD_ERR_FORM_SIZE:
154
+						$error_msg = __(
155
+							'The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form.',
156
+							"event_espresso"
157
+						);
158
+						break;
159
+					case UPLOAD_ERR_PARTIAL:
160
+						$error_msg = __('The uploaded file was only partially uploaded.', "event_espresso");
161
+						break;
162
+					case UPLOAD_ERR_NO_FILE:
163
+						$error_msg = __('No file was uploaded.', "event_espresso");
164
+						break;
165
+					case UPLOAD_ERR_NO_TMP_DIR:
166
+						$error_msg = __('Missing a temporary folder.', "event_espresso");
167
+						break;
168
+					case UPLOAD_ERR_CANT_WRITE:
169
+						$error_msg = __('Failed to write file to disk.', "event_espresso");
170
+						break;
171
+					case UPLOAD_ERR_EXTENSION:
172
+						$error_msg = __('File upload stopped by extension.', "event_espresso");
173
+						break;
174
+					default:
175
+						$error_msg = __(
176
+							'An unknown error occurred and the file could not be uploaded',
177
+							"event_espresso"
178
+						);
179
+						break;
180
+				}
181
+
182
+				if (! $error_msg) {
183
+					$filename = $_FILES['file']['name'][0];
184
+					$file_ext = substr(strrchr($filename, '.'), 1);
185
+					$file_type = $_FILES['file']['type'][0];
186
+					$temp_file = $_FILES['file']['tmp_name'][0];
187
+					$filesize = $_FILES['file']['size'][0] / 1024;// convert from bytes to KB
188
+
189
+					if ($file_ext == 'csv') {
190
+						$max_upload = $this->EE_CSV->get_max_upload_size();// max upload size in KB
191
+						if ($filesize < $max_upload || true) {
192
+							$wp_upload_dir = str_replace(array('\\', '/'), '/', wp_upload_dir());
193
+							$path_to_file = $wp_upload_dir['basedir'] . '/espresso/' . $filename;
194
+
195
+							if (move_uploaded_file($temp_file, $path_to_file)) {
196
+								// convert csv to array
197
+								$this->csv_array = $this->EE_CSV->import_csv_to_model_data_array($path_to_file);
198
+
199
+								// was data successfully stored in an array?
200
+								if (is_array($this->csv_array)) {
201
+									$import_what = str_replace('csv_import_', '', $_REQUEST['action']);
202
+									$import_what = str_replace('_', ' ', ucwords($import_what));
203
+									$processed_data = $this->csv_array;
204
+									$this->columns_to_save = false;
205
+
206
+									// if any imports require funcky processing, we'll catch them in the switch
207
+									switch ($_REQUEST['action']) {
208
+										case "import_events":
209
+										case "event_list":
210
+											$import_what = 'Event Details';
211
+											break;
212
+
213
+										case 'groupon_import_csv':
214
+											$import_what = 'Groupon Codes';
215
+											$processed_data = $this->process_groupon_codes();
216
+											break;
217
+									}
218
+									// save processed codes to db
219
+									if ($this->save_csv_data_array_to_db($processed_data, $this->columns_to_save)) {
220
+										return true;
221
+									}
222
+								} else {
223
+									// no array? must be an error
224
+									EE_Error::add_error(
225
+										sprintf(__("No file seems to have been uploaded", "event_espresso")),
226
+										__FILE__,
227
+										__FUNCTION__,
228
+										__LINE__
229
+									);
230
+									return false;
231
+								}
232
+							} else {
233
+								EE_Error::add_error(
234
+									sprintf(__("%s was not successfully uploaded", "event_espresso"), $filename),
235
+									__FILE__,
236
+									__FUNCTION__,
237
+									__LINE__
238
+								);
239
+								return false;
240
+							}
241
+						} else {
242
+							EE_Error::add_error(
243
+								sprintf(
244
+									__(
245
+										"%s was too large of a file and could not be uploaded. The max filesize is %s' KB.",
246
+										"event_espresso"
247
+									),
248
+									$filename,
249
+									$max_upload
250
+								),
251
+								__FILE__,
252
+								__FUNCTION__,
253
+								__LINE__
254
+							);
255
+							return false;
256
+						}
257
+					} else {
258
+						EE_Error::add_error(
259
+							sprintf(__("%s  had an invalid file extension, not uploaded", "event_espresso"), $filename),
260
+							__FILE__,
261
+							__FUNCTION__,
262
+							__LINE__
263
+						);
264
+						return false;
265
+					}
266
+				} else {
267
+					EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__);
268
+					return false;
269
+				}
270
+			}
271
+		}
272
+		return;
273
+	}
274
+
275
+
276
+	/**
277
+	 *    Given an array of data (usually from a CSV import) attempts to save that data to the db.
278
+	 *    If $model_name ISN'T provided, assumes that this is a 3d array, with toplevel keys being model names,
279
+	 *    next level being numeric indexes adn each value representing a model object, and the last layer down
280
+	 *    being keys of model fields and their proposed values.
281
+	 *    If $model_name IS provided, assumes a 2d array of the bottom two layers previously mentioned.
282
+	 *    If the CSV data says (in the metadata row) that it's from the SAME database,
283
+	 *    we treat the IDs in the CSV as the normal IDs, and try to update those records. However, if those
284
+	 *    IDs DON'T exist in the database, they're treated as temporary IDs,
285
+	 *    which can used elsewhere to refer to the same object. Once an item
286
+	 *    with a temporary ID gets inserted, we record its mapping from temporary
287
+	 *    ID to real ID, and use the real ID in place of the temporary ID
288
+	 *    when that temporary ID was used as a foreign key.
289
+	 *    If the CSV data says (in the metadata again) that it's from a DIFFERENT database,
290
+	 *    we treat all the IDs in the CSV as temporary ID- eg, if the CSV specifies an event with
291
+	 *    ID 1, and the database already has an event with ID 1, we assume that's just a coincidence,
292
+	 *    and insert a new event, and map it's temporary ID of 1 over to its new real ID.
293
+	 *    An important exception are non-auto-increment primary keys. If one entry in the
294
+	 *    CSV file has the same ID as one in the DB, we assume they are meant to be
295
+	 *    the same item, and instead update the item in the DB with that same ID.
296
+	 *    Also note, we remember the mappings permanently. So the 2nd, 3rd, and 10000th
297
+	 *    time you import a CSV from a different site, we remember their mappings, and
298
+	 * will try to update the item in the DB instead of inserting another item (eg
299
+	 * if we previously imported an event with temporary ID 1, and then it got a
300
+	 * real ID of 123, we remember that. So the next time we import an event with
301
+	 * temporary ID, from the same site, we know that it's real ID is 123, and will
302
+	 * update that event, instead of adding a new event).
303
+	 *
304
+	 * @access public
305
+	 * @param array $csv_data_array - the array containing the csv data produced from
306
+	 *                              EE_CSV::import_csv_to_model_data_array()
307
+	 * @param array $fields_to_save - an array containing the csv column names as keys with the corresponding db table
308
+	 *                              fields they will be saved to
309
+	 * @return TRUE on success, FALSE on fail
310
+	 * @throws \EE_Error
311
+	 */
312
+	public function save_csv_data_array_to_db($csv_data_array, $model_name = false)
313
+	{
314
+		$success = false;
315
+		$error = false;
316
+		// whther to treat this import as if it's data froma different database or not
317
+		// ie, if it IS from a different database, ignore foreign keys whihf
318
+		$export_from_site_a_to_b = true;
319
+		// first level of array is not table information but a table name was passed to the function
320
+		// array is only two levels deep, so let's fix that by adding a level, else the next steps will fail
321
+		if ($model_name) {
322
+			$csv_data_array = array($csv_data_array);
323
+		}
324
+		// begin looking through the $csv_data_array, expecting the toplevel key to be the model's name...
325
+		$old_site_url = 'none-specified';
326
+		// hanlde metadata
327
+		if (isset($csv_data_array[ EE_CSV::metadata_header ])) {
328
+			$csv_metadata = array_shift($csv_data_array[ EE_CSV::metadata_header ]);
329
+			// ok so its metadata, dont try to save it to ehte db obviously...
330
+			if (isset($csv_metadata['site_url']) && $csv_metadata['site_url'] == site_url()) {
331
+				EE_Error::add_attention(
332
+					sprintf(
333
+						__(
334
+							"CSV Data appears to be from the same database, so attempting to update data",
335
+							"event_espresso"
336
+						)
337
+					)
338
+				);
339
+				$export_from_site_a_to_b = false;
340
+			} else {
341
+				$old_site_url = isset($csv_metadata['site_url']) ? $csv_metadata['site_url'] : $old_site_url;
342
+				EE_Error::add_attention(
343
+					sprintf(
344
+						__(
345
+							"CSV Data appears to be from a different database (%s instead of %s), so we assume IDs in the CSV data DO NOT correspond to IDs in this database",
346
+							"event_espresso"
347
+						),
348
+						$old_site_url,
349
+						site_url()
350
+					)
351
+				);
352
+			};
353
+			unset($csv_data_array[ EE_CSV::metadata_header ]);
354
+		}
355
+		/**
356
+		 * @var $old_db_to_new_db_mapping 2d array: toplevel keys being model names, bottom-level keys being the original key, and
357
+		 * the value will be the newly-inserted ID.
358
+		 * If we have already imported data from the same website via CSV, it shoudl be kept in this wp option
359
+		 */
360
+		$old_db_to_new_db_mapping = get_option('ee_id_mapping_from' . sanitize_title($old_site_url), array());
361
+		if ($old_db_to_new_db_mapping) {
362
+			EE_Error::add_attention(
363
+				sprintf(
364
+					__(
365
+						"We noticed you have imported data via CSV from %s before. Because of this, IDs in your CSV have been mapped to their new IDs in %s",
366
+						"event_espresso"
367
+					),
368
+					$old_site_url,
369
+					site_url()
370
+				)
371
+			);
372
+		}
373
+		$old_db_to_new_db_mapping = $this->save_data_rows_to_db(
374
+			$csv_data_array,
375
+			$export_from_site_a_to_b,
376
+			$old_db_to_new_db_mapping
377
+		);
378
+
379
+		// save the mapping from old db to new db in case they try re-importing the same data from the same website again
380
+		update_option('ee_id_mapping_from' . sanitize_title($old_site_url), $old_db_to_new_db_mapping);
381
+
382
+		if ($this->_total_updates > 0) {
383
+			EE_Error::add_success(
384
+				sprintf(
385
+					__("%s existing records in the database were updated.", "event_espresso"),
386
+					$this->_total_updates
387
+				)
388
+			);
389
+			$success = true;
390
+		}
391
+		if ($this->_total_inserts > 0) {
392
+			EE_Error::add_success(
393
+				sprintf(__("%s new records were added to the database.", "event_espresso"), $this->_total_inserts)
394
+			);
395
+			$success = true;
396
+		}
397
+
398
+		if ($this->_total_update_errors > 0) {
399
+			EE_Error::add_error(
400
+				sprintf(
401
+					__(
402
+						"'One or more errors occurred, and a total of %s existing records in the database were <strong>not</strong> updated.'",
403
+						"event_espresso"
404
+					),
405
+					$this->_total_update_errors
406
+				),
407
+				__FILE__,
408
+				__FUNCTION__,
409
+				__LINE__
410
+			);
411
+			$error = true;
412
+		}
413
+		if ($this->_total_insert_errors > 0) {
414
+			EE_Error::add_error(
415
+				sprintf(
416
+					__(
417
+						"One or more errors occurred, and a total of %s new records were <strong>not</strong> added to the database.'",
418
+						"event_espresso"
419
+					),
420
+					$this->_total_insert_errors
421
+				),
422
+				__FILE__,
423
+				__FUNCTION__,
424
+				__LINE__
425
+			);
426
+			$error = true;
427
+		}
428
+
429
+		// lastly, we need to update the datetime and ticket sold amounts
430
+		// as those may have been affected by this
431
+		EEM_Ticket::instance()->update_tickets_sold(EEM_Ticket::instance()->get_all());
432
+
433
+		// if there was at least one success and absolutely no errors
434
+		if ($success && ! $error) {
435
+			return true;
436
+		} else {
437
+			return false;
438
+		}
439
+	}
440
+
441
+
442
+	/**
443
+	 * Processes the array of data, given the knowledge that it's from the same database or a different one,
444
+	 * and the mapping from temporary IDs to real IDs.
445
+	 * If the data is from a different database, we treat the primary keys and their corresponding
446
+	 * foreign keys as "temp Ids", basically identifiers that get mapped to real primary keys
447
+	 * in the real target database. As items are inserted, their temporary primary keys
448
+	 * are mapped to the real IDs in the target database. Also, before doing any update or
449
+	 * insert, we replace all the temp ID which are foreign keys with their mapped real IDs.
450
+	 * An exception: string primary keys are treated as real IDs, or else we'd need to
451
+	 * dynamically generate new string primary keys which would be very awkard for the country table etc.
452
+	 * Also, models with no primary key are strange too. We combine use their primar key INDEX (a
453
+	 * combination of fields) to create a unique string identifying the row and store
454
+	 * those in the mapping.
455
+	 *
456
+	 * If the data is from the same database, we usually treat primary keys as real IDs.
457
+	 * An exception is if there is nothing in the database for that ID. If that's the case,
458
+	 * we need to insert a new row for that ID, and then map from the non-existent ID
459
+	 * to the newly-inserted real ID.
460
+	 *
461
+	 * @param type $csv_data_array
462
+	 * @param type $export_from_site_a_to_b
463
+	 * @param type $old_db_to_new_db_mapping
464
+	 * @return array updated $old_db_to_new_db_mapping
465
+	 */
466
+	public function save_data_rows_to_db($csv_data_array, $export_from_site_a_to_b, $old_db_to_new_db_mapping)
467
+	{
468
+		foreach ($csv_data_array as $model_name_in_csv_data => $model_data_from_import) {
469
+			// now check that assumption was correct. If
470
+			if (EE_Registry::instance()->is_model_name($model_name_in_csv_data)) {
471
+				$model_name = $model_name_in_csv_data;
472
+			} else {
473
+				// no table info in the array and no table name passed to the function?? FAIL
474
+				EE_Error::add_error(
475
+					__(
476
+						'No table information was specified and/or found, therefore the import could not be completed',
477
+						'event_espresso'
478
+					),
479
+					__FILE__,
480
+					__FUNCTION__,
481
+					__LINE__
482
+				);
483
+				return false;
484
+			}
485
+			/* @var $model EEM_Base */
486
+			$model = EE_Registry::instance()->load_model($model_name);
487
+
488
+			// so without further ado, scanning all the data provided for primary keys and their inital values
489
+			foreach ($model_data_from_import as $model_object_data) {
490
+				// before we do ANYTHING, make sure the csv row wasn't just completely blank
491
+				$row_is_completely_empty = true;
492
+				foreach ($model_object_data as $field) {
493
+					if ($field) {
494
+						$row_is_completely_empty = false;
495
+					}
496
+				}
497
+				if ($row_is_completely_empty) {
498
+					continue;
499
+				}
500
+				// find the PK in the row of data (or a combined key if
501
+				// there is no primary key)
502
+				if ($model->has_primary_key_field()) {
503
+					$id_in_csv = $model_object_data[ $model->primary_key_name() ];
504
+				} else {
505
+					$id_in_csv = $model->get_index_primary_key_string($model_object_data);
506
+				}
507
+
508
+
509
+				$model_object_data = $this->_replace_temp_ids_with_mappings(
510
+					$model_object_data,
511
+					$model,
512
+					$old_db_to_new_db_mapping,
513
+					$export_from_site_a_to_b
514
+				);
515
+				// now we need to decide if we're going to add a new model object given the $model_object_data,
516
+				// or just update.
517
+				if ($export_from_site_a_to_b) {
518
+					$what_to_do = $this->_decide_whether_to_insert_or_update_given_data_from_other_db(
519
+						$id_in_csv,
520
+						$model_object_data,
521
+						$model,
522
+						$old_db_to_new_db_mapping
523
+					);
524
+				} else {// this is just a re-import
525
+					$what_to_do = $this->_decide_whether_to_insert_or_update_given_data_from_same_db(
526
+						$id_in_csv,
527
+						$model_object_data,
528
+						$model,
529
+						$old_db_to_new_db_mapping
530
+					);
531
+				}
532
+				if ($what_to_do == self::do_nothing) {
533
+					continue;
534
+				}
535
+
536
+				// double-check we actually want to insert, if that's what we're planning
537
+				// based on whether this item would be unique in the DB or not
538
+				if ($what_to_do == self::do_insert) {
539
+					// we're supposed to be inserting. But wait, will this thing
540
+					// be acceptable if inserted?
541
+					$conflicting = $model->get_one_conflicting($model_object_data, false);
542
+					if ($conflicting) {
543
+						// ok, this item would conflict if inserted. Just update the item that it conflicts with.
544
+						$what_to_do = self::do_update;
545
+						// and if this model has a primary key, remember its mapping
546
+						if ($model->has_primary_key_field()) {
547
+							$old_db_to_new_db_mapping[ $model_name ][ $id_in_csv ] = $conflicting->ID();
548
+							$model_object_data[ $model->primary_key_name() ] = $conflicting->ID();
549
+						} else {
550
+							// we want to update this conflicting item, instead of inserting a conflicting item
551
+							// so we need to make sure they match entirely (its possible that they only conflicted on one field, but we need them to match on other fields
552
+							// for the WHERE conditions in the update). At the time of this comment, there were no models like this
553
+							foreach ($model->get_combined_primary_key_fields() as $key_field) {
554
+								$model_object_data[ $key_field->get_name() ] = $conflicting->get(
555
+									$key_field->get_name()
556
+								);
557
+							}
558
+						}
559
+					}
560
+				}
561
+				if ($what_to_do == self::do_insert) {
562
+					$old_db_to_new_db_mapping = $this->_insert_from_data_array(
563
+						$id_in_csv,
564
+						$model_object_data,
565
+						$model,
566
+						$old_db_to_new_db_mapping
567
+					);
568
+				} elseif ($what_to_do == self::do_update) {
569
+					$old_db_to_new_db_mapping = $this->_update_from_data_array(
570
+						$id_in_csv,
571
+						$model_object_data,
572
+						$model,
573
+						$old_db_to_new_db_mapping
574
+					);
575
+				} else {
576
+					throw new EE_Error(
577
+						sprintf(
578
+							__(
579
+								'Programming error. We shoudl be inserting or updating, but instead we are being told to "%s", whifh is invalid',
580
+								'event_espresso'
581
+							),
582
+							$what_to_do
583
+						)
584
+					);
585
+				}
586
+			}
587
+		}
588
+		return $old_db_to_new_db_mapping;
589
+	}
590
+
591
+
592
+	/**
593
+	 * Decides whether or not to insert, given that this data is from another database.
594
+	 * So, if the primary key of this $model_object_data already exists in the database,
595
+	 * it's just a coincidence and we should still insert. The only time we should
596
+	 * update is when we know what it maps to, or there's something that would
597
+	 * conflict (and we should instead just update that conflicting thing)
598
+	 *
599
+	 * @param string   $id_in_csv
600
+	 * @param array    $model_object_data        by reference so it can be modified
601
+	 * @param EEM_Base $model
602
+	 * @param array    $old_db_to_new_db_mapping by reference so it can be modified
603
+	 * @return string one of the consts on this class that starts with do_*
604
+	 */
605
+	protected function _decide_whether_to_insert_or_update_given_data_from_other_db(
606
+		$id_in_csv,
607
+		$model_object_data,
608
+		$model,
609
+		$old_db_to_new_db_mapping
610
+	) {
611
+		$model_name = $model->get_this_model_name();
612
+		// if it's a site-to-site export-and-import, see if this modelobject's id
613
+		// in the old data that we know of
614
+		if (isset($old_db_to_new_db_mapping[ $model_name ][ $id_in_csv ])) {
615
+			return self::do_update;
616
+		} else {
617
+			return self::do_insert;
618
+		}
619
+	}
620
+
621
+	/**
622
+	 * If this thing basically already exists in the database, we want to update it;
623
+	 * otherwise insert it (ie, someone tweaked the CSV file, or the item was
624
+	 * deleted in the database so it should be re-inserted)
625
+	 *
626
+	 * @param type     $id_in_csv
627
+	 * @param type     $model_object_data
628
+	 * @param EEM_Base $model
629
+	 * @param type     $old_db_to_new_db_mapping
630
+	 * @return
631
+	 */
632
+	protected function _decide_whether_to_insert_or_update_given_data_from_same_db(
633
+		$id_in_csv,
634
+		$model_object_data,
635
+		$model
636
+	) {
637
+		// in this case, check if this thing ACTUALLY exists in the database
638
+		if ($model->get_one_conflicting($model_object_data)) {
639
+			return self::do_update;
640
+		} else {
641
+			return self::do_insert;
642
+		}
643
+	}
644
+
645
+	/**
646
+	 * Using the $old_db_to_new_db_mapping array, replaces all the temporary IDs
647
+	 * with their mapped real IDs. Eg, if importing from site A to B, the mapping
648
+	 * file may indicate that the ID "my_event_id" maps to an actual event ID of 123.
649
+	 * So this function searches for any event temp Ids called "my_event_id" and
650
+	 * replaces them with 123.
651
+	 * Also, if there is no temp ID for the INT foreign keys from another database,
652
+	 * replaces them with 0 or the field's default.
653
+	 *
654
+	 * @param type     $model_object_data
655
+	 * @param EEM_Base $model
656
+	 * @param type     $old_db_to_new_db_mapping
657
+	 * @param boolean  $export_from_site_a_to_b
658
+	 * @return array updated model object data with temp IDs removed
659
+	 */
660
+	protected function _replace_temp_ids_with_mappings(
661
+		$model_object_data,
662
+		$model,
663
+		$old_db_to_new_db_mapping,
664
+		$export_from_site_a_to_b
665
+	) {
666
+		// if this model object's primary key is in the mapping, replace it
667
+		if (
668
+			$model->has_primary_key_field() &&
669
+			$model->get_primary_key_field()->is_auto_increment() &&
670
+			isset($old_db_to_new_db_mapping[ $model->get_this_model_name() ]) &&
671
+			isset(
672
+				$old_db_to_new_db_mapping[ $model->get_this_model_name() ][ $model_object_data[ $model->primary_key_name() ] ]
673
+			)
674
+		) {
675
+			$model_object_data[ $model->primary_key_name() ] = $old_db_to_new_db_mapping[ $model->get_this_model_name(
676
+			) ][ $model_object_data[ $model->primary_key_name() ] ];
677
+		}
678
+
679
+		try {
680
+			$model_name_field = $model->get_field_containing_related_model_name();
681
+			$models_pointed_to_by_model_name_field = $model_name_field->get_model_names_pointed_to();
682
+		} catch (EE_Error $e) {
683
+			$model_name_field = null;
684
+			$models_pointed_to_by_model_name_field = array();
685
+		}
686
+		foreach ($model->field_settings(true) as $field_obj) {
687
+			if ($field_obj instanceof EE_Foreign_Key_Int_Field) {
688
+				$models_pointed_to = $field_obj->get_model_names_pointed_to();
689
+				$found_a_mapping = false;
690
+				foreach ($models_pointed_to as $model_pointed_to_by_fk) {
691
+					if ($model_name_field) {
692
+						$value_of_model_name_field = $model_object_data[ $model_name_field->get_name() ];
693
+						if ($value_of_model_name_field == $model_pointed_to_by_fk) {
694
+							$model_object_data[ $field_obj->get_name() ] = $this->_find_mapping_in(
695
+								$model_object_data[ $field_obj->get_name() ],
696
+								$model_pointed_to_by_fk,
697
+								$old_db_to_new_db_mapping,
698
+								$export_from_site_a_to_b
699
+							);
700
+							$found_a_mapping = true;
701
+							break;
702
+						}
703
+					} else {
704
+						$model_object_data[ $field_obj->get_name() ] = $this->_find_mapping_in(
705
+							$model_object_data[ $field_obj->get_name() ],
706
+							$model_pointed_to_by_fk,
707
+							$old_db_to_new_db_mapping,
708
+							$export_from_site_a_to_b
709
+						);
710
+						$found_a_mapping = true;
711
+					}
712
+					// once we've found a mapping for this field no need to continue
713
+					if ($found_a_mapping) {
714
+						break;
715
+					}
716
+				}
717
+			} else {
718
+				// it's a string foreign key (which we leave alone, because those are things
719
+				// like country names, which we'd really rather not make 2 USAs etc (we'd actually
720
+				// prefer to just update one)
721
+				// or it's just a regular value that ought to be replaced
722
+			}
723
+		}
724
+		//
725
+		if ($model instanceof EEM_Term_Taxonomy) {
726
+			$model_object_data = $this->_handle_split_term_ids($model_object_data);
727
+		}
728
+		return $model_object_data;
729
+	}
730
+
731
+	/**
732
+	 * If the data was exported PRE-4.2, but then imported POST-4.2, then the term_id
733
+	 * this term-taxonomy refers to may be out-of-date so we need to update it.
734
+	 * see https://make.wordpress.org/core/2015/02/16/taxonomy-term-splitting-in-4-2-a-developer-guide/
735
+	 *
736
+	 * @param type $model_object_data
737
+	 * @return array new model object data
738
+	 */
739
+	protected function _handle_split_term_ids($model_object_data)
740
+	{
741
+		if (
742
+			isset($model_object_data['term_id'])
743
+			&& isset($model_object_data['taxonomy'])
744
+			&& apply_filters(
745
+				'FHEE__EE_Import__handle_split_term_ids__function_exists',
746
+				function_exists('wp_get_split_term'),
747
+				$model_object_data
748
+			)
749
+		) {
750
+			$new_term_id = wp_get_split_term($model_object_data['term_id'], $model_object_data['taxonomy']);
751
+			if ($new_term_id) {
752
+				$model_object_data['term_id'] = $new_term_id;
753
+			}
754
+		}
755
+		return $model_object_data;
756
+	}
757
+
758
+	/**
759
+	 * Given the object's ID and its model's name, find it int he mapping data,
760
+	 * bearing in mind where it came from
761
+	 *
762
+	 * @param type   $object_id
763
+	 * @param string $model_name
764
+	 * @param array  $old_db_to_new_db_mapping
765
+	 * @param type   $export_from_site_a_to_b
766
+	 * @return int
767
+	 */
768
+	protected function _find_mapping_in($object_id, $model_name, $old_db_to_new_db_mapping, $export_from_site_a_to_b)
769
+	{
770
+		if (isset($old_db_to_new_db_mapping[ $model_name ][ $object_id ])) {
771
+			return $old_db_to_new_db_mapping[ $model_name ][ $object_id ];
772
+		} elseif ($object_id == '0' || $object_id == '') {
773
+			// leave as-is
774
+			return $object_id;
775
+		} elseif ($export_from_site_a_to_b) {
776
+			// we couldn't find a mapping for this, and it's from a different site,
777
+			// so blank it out
778
+			return null;
779
+		} elseif (! $export_from_site_a_to_b) {
780
+			// we coudln't find a mapping for this, but it's from thsi DB anyway
781
+			// so let's just leave it as-is
782
+			return $object_id;
783
+		}
784
+	}
785
+
786
+	/**
787
+	 *
788
+	 * @param type     $id_in_csv
789
+	 * @param type     $model_object_data
790
+	 * @param EEM_Base $model
791
+	 * @param type     $old_db_to_new_db_mapping
792
+	 * @return array updated $old_db_to_new_db_mapping
793
+	 */
794
+	protected function _insert_from_data_array($id_in_csv, $model_object_data, $model, $old_db_to_new_db_mapping)
795
+	{
796
+		// remove the primary key, if there is one (we don't want it for inserts OR updates)
797
+		// we'll put it back in if we need it
798
+		if ($model->has_primary_key_field() && $model->get_primary_key_field()->is_auto_increment()) {
799
+			$effective_id = $model_object_data[ $model->primary_key_name() ];
800
+			unset($model_object_data[ $model->primary_key_name() ]);
801
+		} else {
802
+			$effective_id = $model->get_index_primary_key_string($model_object_data);
803
+		}
804
+		// the model takes care of validating the CSV's input
805
+		try {
806
+			$new_id = $model->insert($model_object_data);
807
+			if ($new_id) {
808
+				$old_db_to_new_db_mapping[ $model->get_this_model_name() ][ $id_in_csv ] = $new_id;
809
+				$this->_total_inserts++;
810
+				EE_Error::add_success(
811
+					sprintf(
812
+						__("Successfully added new %s (with id %s) with csv data %s", "event_espresso"),
813
+						$model->get_this_model_name(),
814
+						$new_id,
815
+						implode(",", $model_object_data)
816
+					)
817
+				);
818
+			} else {
819
+				$this->_total_insert_errors++;
820
+				// put the ID used back in there for the error message
821
+				if ($model->has_primary_key_field()) {
822
+					$model_object_data[ $model->primary_key_name() ] = $effective_id;
823
+				}
824
+				EE_Error::add_error(
825
+					sprintf(
826
+						__("Could not insert new %s with the csv data: %s", "event_espresso"),
827
+						$model->get_this_model_name(),
828
+						http_build_query($model_object_data)
829
+					),
830
+					__FILE__,
831
+					__FUNCTION__,
832
+					__LINE__
833
+				);
834
+			}
835
+		} catch (EE_Error $e) {
836
+			$this->_total_insert_errors++;
837
+			if ($model->has_primary_key_field()) {
838
+				$model_object_data[ $model->primary_key_name() ] = $effective_id;
839
+			}
840
+			EE_Error::add_error(
841
+				sprintf(
842
+					__("Could not insert new %s with the csv data: %s because %s", "event_espresso"),
843
+					$model->get_this_model_name(),
844
+					implode(",", $model_object_data),
845
+					$e->getMessage()
846
+				),
847
+				__FILE__,
848
+				__FUNCTION__,
849
+				__LINE__
850
+			);
851
+		}
852
+		return $old_db_to_new_db_mapping;
853
+	}
854
+
855
+	/**
856
+	 * Given the model object data, finds the row to update and updates it
857
+	 *
858
+	 * @param string|int $id_in_csv
859
+	 * @param array      $model_object_data
860
+	 * @param EEM_Base   $model
861
+	 * @param array      $old_db_to_new_db_mapping
862
+	 * @return array updated $old_db_to_new_db_mapping
863
+	 */
864
+	protected function _update_from_data_array($id_in_csv, $model_object_data, $model, $old_db_to_new_db_mapping)
865
+	{
866
+		try {
867
+			// let's keep two copies of the model object data:
868
+			// one for performing an update, one for everthing else
869
+			$model_object_data_for_update = $model_object_data;
870
+			if ($model->has_primary_key_field()) {
871
+				$conditions = array($model->primary_key_name() => $model_object_data[ $model->primary_key_name() ]);
872
+				// remove the primary key because we shouldn't use it for updating
873
+				unset($model_object_data_for_update[ $model->primary_key_name() ]);
874
+			} elseif ($model->get_combined_primary_key_fields() > 1) {
875
+				$conditions = array();
876
+				foreach ($model->get_combined_primary_key_fields() as $key_field) {
877
+					$conditions[ $key_field->get_name() ] = $model_object_data[ $key_field->get_name() ];
878
+				}
879
+			} else {
880
+				$model->primary_key_name(
881
+				);// this shoudl just throw an exception, explaining that we dont have a primary key (or a combine dkey)
882
+			}
883
+
884
+			$success = $model->update($model_object_data_for_update, array($conditions));
885
+			if ($success) {
886
+				$this->_total_updates++;
887
+				EE_Error::add_success(
888
+					sprintf(
889
+						__("Successfully updated %s with csv data %s", "event_espresso"),
890
+						$model->get_this_model_name(),
891
+						implode(",", $model_object_data_for_update)
892
+					)
893
+				);
894
+				// we should still record the mapping even though it was an update
895
+				// because if we were going to insert somethign but it was going to conflict
896
+				// we would have last-minute decided to update. So we'd like to know what we updated
897
+				// and so we record what record ended up being updated using the mapping
898
+				if ($model->has_primary_key_field()) {
899
+					$new_key_for_mapping = $model_object_data[ $model->primary_key_name() ];
900
+				} else {
901
+					// no primary key just a combined key
902
+					$new_key_for_mapping = $model->get_index_primary_key_string($model_object_data);
903
+				}
904
+				$old_db_to_new_db_mapping[ $model->get_this_model_name() ][ $id_in_csv ] = $new_key_for_mapping;
905
+			} else {
906
+				$matched_items = $model->get_all(array($conditions));
907
+				if (! $matched_items) {
908
+					// no items were matched (so we shouldn't have updated)... but then we should have inserted? what the heck?
909
+					$this->_total_update_errors++;
910
+					EE_Error::add_error(
911
+						sprintf(
912
+							__(
913
+								"Could not update %s with the csv data: '%s' for an unknown reason (using WHERE conditions %s)",
914
+								"event_espresso"
915
+							),
916
+							$model->get_this_model_name(),
917
+							http_build_query($model_object_data),
918
+							http_build_query($conditions)
919
+						),
920
+						__FILE__,
921
+						__FUNCTION__,
922
+						__LINE__
923
+					);
924
+				} else {
925
+					$this->_total_updates++;
926
+					EE_Error::add_success(
927
+						sprintf(
928
+							__(
929
+								"%s with csv data '%s' was found in the database and didn't need updating because all the data is identical.",
930
+								"event_espresso"
931
+							),
932
+							$model->get_this_model_name(),
933
+							implode(",", $model_object_data)
934
+						)
935
+					);
936
+				}
937
+			}
938
+		} catch (EE_Error $e) {
939
+			$this->_total_update_errors++;
940
+			$basic_message = sprintf(
941
+				__("Could not update %s with the csv data: %s because %s", "event_espresso"),
942
+				$model->get_this_model_name(),
943
+				implode(",", $model_object_data),
944
+				$e->getMessage()
945
+			);
946
+			$debug_message = $basic_message . ' Stack trace: ' . $e->getTraceAsString();
947
+			EE_Error::add_error("$basic_message | $debug_message", __FILE__, __FUNCTION__, __LINE__);
948
+		}
949
+		return $old_db_to_new_db_mapping;
950
+	}
951
+
952
+	/**
953
+	 * Gets the number of inserts performed since importer was instantiated or reset
954
+	 *
955
+	 * @return int
956
+	 */
957
+	public function get_total_inserts()
958
+	{
959
+		return $this->_total_inserts;
960
+	}
961
+
962
+	/**
963
+	 *  Gets the number of insert errors since importer was instantiated or reset
964
+	 *
965
+	 * @return int
966
+	 */
967
+	public function get_total_insert_errors()
968
+	{
969
+		return $this->_total_insert_errors;
970
+	}
971
+
972
+	/**
973
+	 *  Gets the number of updates performed since importer was instantiated or reset
974
+	 *
975
+	 * @return int
976
+	 */
977
+	public function get_total_updates()
978
+	{
979
+		return $this->_total_updates;
980
+	}
981
+
982
+	/**
983
+	 *  Gets the number of update errors since importer was instantiated or reset
984
+	 *
985
+	 * @return int
986
+	 */
987
+	public function get_total_update_errors()
988
+	{
989
+		return $this->_total_update_errors;
990
+	}
991 991
 }
Please login to merge, or discard this patch.