Completed
Branch dependabot/npm_and_yarn/@wordp... (e9f48b)
by
unknown
60:52 queued 52:34
created
core/helpers/EEH_Event_View.helper.php 3 patches
Doc Comments   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -22,7 +22,7 @@  discard block
 block discarded – undo
22 22
      * get_event
23 23
      * attempts to retrieve an EE_Event object any way it can
24 24
      *
25
-     * @param int|WP_Post $EVT_ID
25
+     * @param integer $EVT_ID
26 26
      * @return EE_Event|null
27 27
      * @throws \EE_Error
28 28
      */
@@ -115,7 +115,7 @@  discard block
 block discarded – undo
115 115
      *
116 116
      *  @access     public
117 117
      * @param    int $EVT_ID
118
-     *  @return     string
118
+     *  @return     boolean
119 119
      */
120 120
     public static function event_has_content_or_excerpt($EVT_ID = 0)
121 121
     {
@@ -136,7 +136,7 @@  discard block
 block discarded – undo
136 136
      *    event_active_status
137 137
      *
138 138
      * @access    public
139
-     * @param null $num_words
139
+     * @param integer $num_words
140 140
      * @param null $more
141 141
      * @return    string
142 142
      */
@@ -478,7 +478,7 @@  discard block
 block discarded – undo
478 478
      *
479 479
      * @access    public
480 480
      * @param int $EVT_ID
481
-     * @param null $include_expired
481
+     * @param false|null $include_expired
482 482
      * @param bool $include_deleted
483 483
      * @param null $limit
484 484
      * @return EE_Datetime[]
Please login to merge, or discard this patch.
Spacing   +31 added lines, -31 removed lines patch added patch discarded remove patch
@@ -39,7 +39,7 @@  discard block
 block discarded – undo
39 39
         }
40 40
         // reset property so that the new event is cached.
41 41
         EEH_Event_View::$_event = null;
42
-        if (! $EVT_ID && $post instanceof EE_Event) {
42
+        if ( ! $EVT_ID && $post instanceof EE_Event) {
43 43
             EEH_Event_View::$_event = $post;
44 44
             return EEH_Event_View::$_event;
45 45
         }
@@ -57,7 +57,7 @@  discard block
 block discarded – undo
57 57
             return EEH_Event_View::$_event;
58 58
         }
59 59
         // If the event we have isn't an event but we do have an EVT_ID, let's try getting the event using the ID.
60
-        if (! EEH_Event_View::$_event instanceof EE_Event && $EVT_ID) {
60
+        if ( ! EEH_Event_View::$_event instanceof EE_Event && $EVT_ID) {
61 61
             EEH_Event_View::$_event = EEM_Event::instance()->get_one_by_ID($EVT_ID);
62 62
         }
63 63
         return EEH_Event_View::$_event;
@@ -124,7 +124,7 @@  discard block
 block discarded – undo
124 124
         if ($event instanceof EE_Event) {
125 125
             $has_content_or_excerpt = $event->description() != '' || $event->short_description(null, null, true) != '' ? true : false;
126 126
         }
127
-        if (is_archive() && ! ( espresso_display_full_description_in_event_list() || espresso_display_excerpt_in_event_list() )) {
127
+        if (is_archive() && ! (espresso_display_full_description_in_event_list() || espresso_display_excerpt_in_event_list())) {
128 128
             $has_content_or_excerpt = false;
129 129
         }
130 130
         return $has_content_or_excerpt;
@@ -144,11 +144,11 @@  discard block
 block discarded – undo
144 144
     {
145 145
         global $post;
146 146
         ob_start();
147
-        if (( is_single() ) || ( is_archive() && espresso_display_full_description_in_event_list() )) {
147
+        if ((is_single()) || (is_archive() && espresso_display_full_description_in_event_list())) {
148 148
             // admin has chosen "full description"
149 149
             // for the "Event Espresso - Events > Templates > Display Description" option
150 150
             the_content();
151
-        } elseif (( is_archive() && espresso_display_excerpt_in_event_list() )) {
151
+        } elseif ((is_archive() && espresso_display_excerpt_in_event_list())) {
152 152
             if (has_excerpt($post->ID)) {
153 153
                 // admin has chosen "excerpt (short desc)"
154 154
                 // for the "Event Espresso - Events > Templates > Display Description" option
@@ -158,20 +158,20 @@  discard block
 block discarded – undo
158 158
                 // admin has chosen "excerpt (short desc)"
159 159
                 // for the "Event Espresso - Events > Templates > Display Description" option
160 160
                 // but NO excerpt actually exists, so we need to create one
161
-                if (! empty($num_words)) {
161
+                if ( ! empty($num_words)) {
162 162
                     if (empty($more)) {
163 163
                         $more_link_text = __('(more…)', 'event_espresso');
164
-                        $more = ' <a href="' . get_permalink() . '"';
164
+                        $more = ' <a href="'.get_permalink().'"';
165 165
                         $more .= ' class="more-link"';
166 166
                         $more .= \EED_Events_Archive::link_target();
167
-                        $more .= '>' . $more_link_text . '</a>';
167
+                        $more .= '>'.$more_link_text.'</a>';
168 168
                         $more = apply_filters('the_content_more_link', $more, $more_link_text);
169 169
                     }
170 170
                     $content = str_replace('NOMORELINK', '', get_the_content('NOMORELINK'));
171 171
 
172
-                    $content =  wp_trim_words($content, $num_words, ' ') . $more;
172
+                    $content = wp_trim_words($content, $num_words, ' ').$more;
173 173
                 } else {
174
-                    $content =  get_the_content();
174
+                    $content = get_the_content();
175 175
                 }
176 176
                 global $allowedtags;
177 177
                 // make sure links are allowed
@@ -240,8 +240,8 @@  discard block
 block discarded – undo
240 240
                 // loop thru terms and create links
241 241
                 foreach ($event_categories as $term) {
242 242
                     $url = get_term_link($term, 'espresso_venue_categories');
243
-                    if (! is_wp_error($url) && (( $hide_uncategorized && strtolower($term->name) != __('uncategorized', 'event_espresso')) || ! $hide_uncategorized )) {
244
-                        $category_links[] = '<a href="' . esc_url($url)
243
+                    if ( ! is_wp_error($url) && (($hide_uncategorized && strtolower($term->name) != __('uncategorized', 'event_espresso')) || ! $hide_uncategorized)) {
244
+                        $category_links[] = '<a href="'.esc_url($url)
245 245
                                             . '" rel="tag"'
246 246
                                             . \EED_Events_Archive::link_target()
247 247
                                             .'>'
@@ -268,8 +268,8 @@  discard block
 block discarded – undo
268 268
     public static function the_event_date($dt_frmt = 'D M jS', $tm_frmt = 'g:i a', $EVT_ID = 0)
269 269
     {
270 270
         $datetime = EEH_Event_View::get_primary_date_obj($EVT_ID);
271
-        $format = ! empty($dt_frmt) && ! empty($tm_frmt) ? $dt_frmt . ' ' . $tm_frmt : $dt_frmt . $tm_frmt;
272
-        return $datetime instanceof EE_Datetime ? $datetime->get_i18n_datetime('DTT_EVT_start', $format) :  '';
271
+        $format = ! empty($dt_frmt) && ! empty($tm_frmt) ? $dt_frmt.' '.$tm_frmt : $dt_frmt.$tm_frmt;
272
+        return $datetime instanceof EE_Datetime ? $datetime->get_i18n_datetime('DTT_EVT_start', $format) : '';
273 273
     }
274 274
 
275 275
 
@@ -286,7 +286,7 @@  discard block
 block discarded – undo
286 286
     public static function the_event_end_date($dt_frmt = 'D M jS', $tm_frmt = 'g:i a', $EVT_ID = 0)
287 287
     {
288 288
         $datetime = EEH_Event_View::get_last_date_obj($EVT_ID);
289
-        $format = ! empty($dt_frmt) && ! empty($tm_frmt) ? $dt_frmt . ' ' . $tm_frmt : $dt_frmt . $tm_frmt;
289
+        $format = ! empty($dt_frmt) && ! empty($tm_frmt) ? $dt_frmt.' '.$tm_frmt : $dt_frmt.$tm_frmt;
290 290
         return $datetime instanceof EE_Datetime ? $datetime->get_i18n_datetime('DTT_EVT_end', $format) : '';
291 291
     }
292 292
 
@@ -304,8 +304,8 @@  discard block
 block discarded – undo
304 304
     public static function the_earliest_event_date($dt_frmt = 'D M jS', $tm_frmt = 'g:i a', $EVT_ID = 0)
305 305
     {
306 306
         $datetime = EEH_Event_View::get_earliest_date_obj($EVT_ID);
307
-        $format = ! empty($dt_frmt) && ! empty($tm_frmt) ? $dt_frmt . ' ' . $tm_frmt : $dt_frmt . $tm_frmt;
308
-        return $datetime instanceof EE_Datetime ?  $datetime->get_i18n_datetime('DTT_EVT_start', $format) : '';
307
+        $format = ! empty($dt_frmt) && ! empty($tm_frmt) ? $dt_frmt.' '.$tm_frmt : $dt_frmt.$tm_frmt;
308
+        return $datetime instanceof EE_Datetime ? $datetime->get_i18n_datetime('DTT_EVT_start', $format) : '';
309 309
     }
310 310
 
311 311
 
@@ -322,8 +322,8 @@  discard block
 block discarded – undo
322 322
     public static function the_latest_event_date($dt_frmt = 'D M jS', $tm_frmt = 'g:i a', $EVT_ID = 0)
323 323
     {
324 324
         $datetime = EEH_Event_View::get_latest_date_obj($EVT_ID);
325
-        $format = ! empty($dt_frmt) && ! empty($tm_frmt) ? $dt_frmt . ' ' . $tm_frmt : $dt_frmt . $tm_frmt;
326
-        return $datetime instanceof EE_Datetime ?  $datetime->get_i18n_datetime('DTT_EVT_end', $format) : '';
325
+        $format = ! empty($dt_frmt) && ! empty($tm_frmt) ? $dt_frmt.' '.$tm_frmt : $dt_frmt.$tm_frmt;
326
+        return $datetime instanceof EE_Datetime ? $datetime->get_i18n_datetime('DTT_EVT_end', $format) : '';
327 327
     }
328 328
 
329 329
 
@@ -341,8 +341,8 @@  discard block
 block discarded – undo
341 341
         if ($datetime instanceof EE_Datetime) {
342 342
     ?>
343 343
         <div class="event-date-calendar-page-dv">
344
-            <div class="event-date-calendar-page-month-dv"><?php echo $datetime->get_i18n_datetime('DTT_EVT_start', 'M');?></div>
345
-            <div class="event-date-calendar-page-day-dv"><?php echo $datetime->start_date('d');?></div>
344
+            <div class="event-date-calendar-page-month-dv"><?php echo $datetime->get_i18n_datetime('DTT_EVT_start', 'M'); ?></div>
345
+            <div class="event-date-calendar-page-day-dv"><?php echo $datetime->start_date('d'); ?></div>
346 346
         </div>
347 347
     <?php
348 348
         }
@@ -365,7 +365,7 @@  discard block
 block discarded – undo
365 365
                 'Datetime',
366 366
                 array(
367 367
                     'limit' => 1,
368
-                    'order_by' => array( 'DTT_order' => 'ASC' )
368
+                    'order_by' => array('DTT_order' => 'ASC')
369 369
                 )
370 370
             );
371 371
             return reset($datetimes);
@@ -391,7 +391,7 @@  discard block
 block discarded – undo
391 391
                 'Datetime',
392 392
                 array(
393 393
                     'limit' => 1,
394
-                    'order_by' => array( 'DTT_order' => 'DESC' )
394
+                    'order_by' => array('DTT_order' => 'DESC')
395 395
                 )
396 396
             );
397 397
             return end($datetimes);
@@ -417,7 +417,7 @@  discard block
 block discarded – undo
417 417
                 'Datetime',
418 418
                 array(
419 419
                     'limit' => 1,
420
-                    'order_by' => array( 'DTT_EVT_start' => 'ASC' )
420
+                    'order_by' => array('DTT_EVT_start' => 'ASC')
421 421
                 )
422 422
             );
423 423
             return reset($datetimes);
@@ -443,7 +443,7 @@  discard block
 block discarded – undo
443 443
                 'Datetime',
444 444
                 array(
445 445
                     'limit' => 1,
446
-                    'order_by' => array( 'DTT_EVT_start' => 'DESC' )
446
+                    'order_by' => array('DTT_EVT_start' => 'DESC')
447 447
                 )
448 448
             );
449 449
             return end($datetimes);
@@ -515,7 +515,7 @@  discard block
 block discarded – undo
515 515
         $event = EEH_Event_View::get_event($EVT_ID);
516 516
         if ($event instanceof EE_Event) {
517 517
             $url = $event->external_url() !== null && $event->external_url() !== '' ? $event->external_url() : get_permalink($event->ID());
518
-            return preg_match("~^(?:f|ht)tps?://~i", $url) ? $url : 'http://' . $url;
518
+            return preg_match("~^(?:f|ht)tps?://~i", $url) ? $url : 'http://'.$url;
519 519
         }
520 520
         return null;
521 521
     }
@@ -561,16 +561,16 @@  discard block
 block discarded – undo
561 561
                 // generate nonce
562 562
                 $nonce = wp_create_nonce('edit_nonce');
563 563
                 // generate url to event editor for this event
564
-                $url = add_query_arg(array( 'page' => 'espresso_events', 'action' => 'edit', 'post' => $event->ID(), 'edit_nonce' => $nonce ), admin_url());
564
+                $url = add_query_arg(array('page' => 'espresso_events', 'action' => 'edit', 'post' => $event->ID(), 'edit_nonce' => $nonce), admin_url());
565 565
                 // get edit CPT text
566 566
                 $post_type_obj = get_post_type_object('espresso_events');
567 567
                 // build final link html
568
-                $link = '<a class="post-edit-link" href="' . $url . '" ';
569
-                $link .= ' title="' . esc_attr($post_type_obj->labels->edit_item) . '"';
568
+                $link = '<a class="post-edit-link" href="'.$url.'" ';
569
+                $link .= ' title="'.esc_attr($post_type_obj->labels->edit_item).'"';
570 570
                 $link .= \EED_Events_Archive::link_target();
571
-                $link .='>' . $link_text . '</a>';
571
+                $link .= '>'.$link_text.'</a>';
572 572
                 // put it all together
573
-                return $before . apply_filters('edit_post_link', $link, $event->ID()) . $after;
573
+                return $before.apply_filters('edit_post_link', $link, $event->ID()).$after;
574 574
             }
575 575
         }
576 576
         return '';
Please login to merge, or discard this patch.
Indentation   +569 added lines, -569 removed lines patch added patch discarded remove patch
@@ -11,578 +11,578 @@
 block discarded – undo
11 11
 class EEH_Event_View extends EEH_Base
12 12
 {
13 13
 
14
-    /**
15
-     * @var EE_Event $_event
16
-     */
17
-    private static $_event = null;
18
-
19
-
20
-
21
-    /**
22
-     * get_event
23
-     * attempts to retrieve an EE_Event object any way it can
24
-     *
25
-     * @param int|WP_Post $EVT_ID
26
-     * @return EE_Event|null
27
-     * @throws \EE_Error
28
-     */
29
-    public static function get_event($EVT_ID = 0)
30
-    {
31
-        // international newspaper?
32
-        global $post;
33
-        $EVT_ID = $EVT_ID instanceof WP_Post && $EVT_ID->post_type === 'espresso_events'
34
-            ? $EVT_ID->ID
35
-            : absint($EVT_ID);
36
-        // do we already have the Event  you are looking for?
37
-        if (EEH_Event_View::$_event instanceof EE_Event && $EVT_ID && EEH_Event_View::$_event->ID() === $EVT_ID) {
38
-            return EEH_Event_View::$_event;
39
-        }
40
-        // reset property so that the new event is cached.
41
-        EEH_Event_View::$_event = null;
42
-        if (! $EVT_ID && $post instanceof EE_Event) {
43
-            EEH_Event_View::$_event = $post;
44
-            return EEH_Event_View::$_event;
45
-        }
46
-        // if the post type is for an event and it has a cached event and we don't have a different incoming $EVT_ID
47
-        // then let's just use that cached event on the $post object.
48
-        if ($post instanceof WP_Post
49
-            && $post->post_type === 'espresso_events'
50
-            && isset($post->EE_Event)
51
-            && (
52
-                $EVT_ID === 0
53
-                || $EVT_ID === $post->ID
54
-            )
55
-        ) {
56
-            EEH_Event_View::$_event = $post->EE_Event;
57
-            return EEH_Event_View::$_event;
58
-        }
59
-        // If the event we have isn't an event but we do have an EVT_ID, let's try getting the event using the ID.
60
-        if (! EEH_Event_View::$_event instanceof EE_Event && $EVT_ID) {
61
-            EEH_Event_View::$_event = EEM_Event::instance()->get_one_by_ID($EVT_ID);
62
-        }
63
-        return EEH_Event_View::$_event;
64
-    }
65
-
66
-
67
-
68
-    /**
69
-     *    display_ticket_selector
70
-     *
71
-     * @access    public
72
-     * @param    int $EVT_ID
73
-     * @return    boolean
74
-     */
75
-    public static function display_ticket_selector($EVT_ID = 0)
76
-    {
77
-        $event = EEH_Event_View::get_event($EVT_ID);
78
-        return $event instanceof EE_Event ? $event->display_ticket_selector() : false;
79
-    }
80
-
81
-
82
-
83
-    /**
84
-     *    event_status
85
-     *
86
-     * @access    public
87
-     * @param    int $EVT_ID
88
-     * @return    string
89
-     */
90
-    public static function event_status($EVT_ID = 0)
91
-    {
92
-        $event = EEH_Event_View::get_event($EVT_ID);
93
-        return $event instanceof EE_Event ? $event->pretty_active_status(false) : '';
94
-    }
95
-
96
-
97
-
98
-    /**
99
-     *  event_active_status
100
-     *
101
-     *  @access     public
102
-     * @param    int $EVT_ID
103
-     *  @return     string
104
-     */
105
-    public static function event_active_status($EVT_ID = 0, $echo = true)
106
-    {
107
-        $event = EEH_Event_View::get_event($EVT_ID);
108
-        return $event instanceof EE_Event ? $event->pretty_active_status($echo) : 'inactive';
109
-    }
110
-
111
-
112
-
113
-    /**
114
-     *  event_has_content_or_excerpt
115
-     *
116
-     *  @access     public
117
-     * @param    int $EVT_ID
118
-     *  @return     string
119
-     */
120
-    public static function event_has_content_or_excerpt($EVT_ID = 0)
121
-    {
122
-        $event = EEH_Event_View::get_event($EVT_ID);
123
-        $has_content_or_excerpt = false;
124
-        if ($event instanceof EE_Event) {
125
-            $has_content_or_excerpt = $event->description() != '' || $event->short_description(null, null, true) != '' ? true : false;
126
-        }
127
-        if (is_archive() && ! ( espresso_display_full_description_in_event_list() || espresso_display_excerpt_in_event_list() )) {
128
-            $has_content_or_excerpt = false;
129
-        }
130
-        return $has_content_or_excerpt;
131
-    }
132
-
133
-
134
-
135
-    /**
136
-     *    event_active_status
137
-     *
138
-     * @access    public
139
-     * @param null $num_words
140
-     * @param null $more
141
-     * @return    string
142
-     */
143
-    public static function event_content_or_excerpt($num_words = null, $more = null)
144
-    {
145
-        global $post;
146
-        ob_start();
147
-        if (( is_single() ) || ( is_archive() && espresso_display_full_description_in_event_list() )) {
148
-            // admin has chosen "full description"
149
-            // for the "Event Espresso - Events > Templates > Display Description" option
150
-            the_content();
151
-        } elseif (( is_archive() && espresso_display_excerpt_in_event_list() )) {
152
-            if (has_excerpt($post->ID)) {
153
-                // admin has chosen "excerpt (short desc)"
154
-                // for the "Event Espresso - Events > Templates > Display Description" option
155
-                // AND an excerpt actually exists
156
-                the_excerpt();
157
-            } else {
158
-                // admin has chosen "excerpt (short desc)"
159
-                // for the "Event Espresso - Events > Templates > Display Description" option
160
-                // but NO excerpt actually exists, so we need to create one
161
-                if (! empty($num_words)) {
162
-                    if (empty($more)) {
163
-                        $more_link_text = __('(more&hellip;)', 'event_espresso');
164
-                        $more = ' <a href="' . get_permalink() . '"';
165
-                        $more .= ' class="more-link"';
166
-                        $more .= \EED_Events_Archive::link_target();
167
-                        $more .= '>' . $more_link_text . '</a>';
168
-                        $more = apply_filters('the_content_more_link', $more, $more_link_text);
169
-                    }
170
-                    $content = str_replace('NOMORELINK', '', get_the_content('NOMORELINK'));
171
-
172
-                    $content =  wp_trim_words($content, $num_words, ' ') . $more;
173
-                } else {
174
-                    $content =  get_the_content();
175
-                }
176
-                global $allowedtags;
177
-                // make sure links are allowed
178
-                $allowedtags['a'] = isset($allowedtags['a'])
179
-                    ? $allowedtags['a']
180
-                    : array();
181
-                // as well as target attribute
182
-                $allowedtags['a']['target'] = isset($allowedtags['a']['target'])
183
-                    ? $allowedtags['a']['target']
184
-                    : false;
185
-                // but get previous value so we can reset it
186
-                $prev_value = $allowedtags['a']['target'];
187
-                $allowedtags['a']['target'] = true;
188
-                $content = wp_kses($content, $allowedtags);
189
-                $content = strip_shortcodes($content);
190
-                echo apply_filters('the_content', $content);
191
-                $allowedtags['a']['target'] = $prev_value;
192
-            }
193
-        } else {
194
-            // admin has chosen "none"
195
-            // for the "Event Espresso - Events > Templates > Display Description" option
196
-            echo apply_filters('the_content', '');
197
-        }
198
-        return ob_get_clean();
199
-    }
200
-
201
-
202
-
203
-    /**
204
-     *  event_tickets_available
205
-     *
206
-     *  @access     public
207
-     * @param    int $EVT_ID
208
-     *  @return     EE_Ticket[]
209
-     */
210
-    public static function event_tickets_available($EVT_ID = 0)
211
-    {
212
-        $event = EEH_Event_View::get_event($EVT_ID);
213
-        $tickets_available_for_purchase = array();
214
-        if ($event instanceof EE_Event) {
215
-            $datetimes = EEH_Event_View::get_all_date_obj($EVT_ID, false);
216
-            foreach ($datetimes as $datetime) {
217
-                $tickets_available_for_purchase = array_merge($tickets_available_for_purchase, $datetime->ticket_types_available_for_purchase());
218
-            }
219
-        }
220
-        return $tickets_available_for_purchase;
221
-    }
222
-
223
-
224
-
225
-    /**
226
-     *    the_event_date
227
-     *
228
-     * @access    public
229
-     * @param    int $EVT_ID
230
-     * @param     bool   $hide_uncategorized
231
-     * @return    string
232
-     */
233
-    public static function event_categories($EVT_ID = 0, $hide_uncategorized = true)
234
-    {
235
-        $category_links = array();
236
-        $event = EEH_Event_View::get_event($EVT_ID);
237
-        if ($event instanceof EE_Event) {
238
-            $event_categories = get_the_terms($event->ID(), 'espresso_event_categories');
239
-            if ($event_categories) {
240
-                // loop thru terms and create links
241
-                foreach ($event_categories as $term) {
242
-                    $url = get_term_link($term, 'espresso_venue_categories');
243
-                    if (! is_wp_error($url) && (( $hide_uncategorized && strtolower($term->name) != __('uncategorized', 'event_espresso')) || ! $hide_uncategorized )) {
244
-                        $category_links[] = '<a href="' . esc_url($url)
245
-                                            . '" rel="tag"'
246
-                                            . \EED_Events_Archive::link_target()
247
-                                            .'>'
248
-                                            . $term->name
249
-                                            . '</a>';
250
-                    }
251
-                }
252
-            }
253
-        }
254
-        return implode(', ', $category_links);
255
-    }
256
-
257
-
258
-
259
-    /**
260
-     *    the_event_date - first date by date order
261
-     *
262
-     * @access    public
263
-     * @param string $dt_frmt
264
-     * @param string $tm_frmt
265
-     * @param int    $EVT_ID
266
-     * @return    string
267
-     */
268
-    public static function the_event_date($dt_frmt = 'D M jS', $tm_frmt = 'g:i a', $EVT_ID = 0)
269
-    {
270
-        $datetime = EEH_Event_View::get_primary_date_obj($EVT_ID);
271
-        $format = ! empty($dt_frmt) && ! empty($tm_frmt) ? $dt_frmt . ' ' . $tm_frmt : $dt_frmt . $tm_frmt;
272
-        return $datetime instanceof EE_Datetime ? $datetime->get_i18n_datetime('DTT_EVT_start', $format) :  '';
273
-    }
274
-
275
-
276
-
277
-    /**
278
-     *    the_event_end_date - last date by date order
279
-     *
280
-     * @access    public
281
-     * @param string $dt_frmt
282
-     * @param string $tm_frmt
283
-     * @param int    $EVT_ID
284
-     * @return    string
285
-     */
286
-    public static function the_event_end_date($dt_frmt = 'D M jS', $tm_frmt = 'g:i a', $EVT_ID = 0)
287
-    {
288
-        $datetime = EEH_Event_View::get_last_date_obj($EVT_ID);
289
-        $format = ! empty($dt_frmt) && ! empty($tm_frmt) ? $dt_frmt . ' ' . $tm_frmt : $dt_frmt . $tm_frmt;
290
-        return $datetime instanceof EE_Datetime ? $datetime->get_i18n_datetime('DTT_EVT_end', $format) : '';
291
-    }
292
-
293
-
294
-
295
-    /**
296
-     *    the_earliest_event_date - first date chronologically
297
-     *
298
-     * @access    public
299
-     * @param string $dt_frmt
300
-     * @param string $tm_frmt
301
-     * @param int    $EVT_ID
302
-     * @return    string
303
-     */
304
-    public static function the_earliest_event_date($dt_frmt = 'D M jS', $tm_frmt = 'g:i a', $EVT_ID = 0)
305
-    {
306
-        $datetime = EEH_Event_View::get_earliest_date_obj($EVT_ID);
307
-        $format = ! empty($dt_frmt) && ! empty($tm_frmt) ? $dt_frmt . ' ' . $tm_frmt : $dt_frmt . $tm_frmt;
308
-        return $datetime instanceof EE_Datetime ?  $datetime->get_i18n_datetime('DTT_EVT_start', $format) : '';
309
-    }
310
-
311
-
312
-
313
-    /**
314
-     *    the_latest_event_date - latest date chronologically
315
-     *
316
-     * @access    public
317
-     * @param string $dt_frmt
318
-     * @param string $tm_frmt
319
-     * @param int    $EVT_ID
320
-     * @return    string
321
-     */
322
-    public static function the_latest_event_date($dt_frmt = 'D M jS', $tm_frmt = 'g:i a', $EVT_ID = 0)
323
-    {
324
-        $datetime = EEH_Event_View::get_latest_date_obj($EVT_ID);
325
-        $format = ! empty($dt_frmt) && ! empty($tm_frmt) ? $dt_frmt . ' ' . $tm_frmt : $dt_frmt . $tm_frmt;
326
-        return $datetime instanceof EE_Datetime ?  $datetime->get_i18n_datetime('DTT_EVT_end', $format) : '';
327
-    }
328
-
329
-
330
-
331
-    /**
332
-     *    event_date_as_calendar_page
333
-     *
334
-     * @access    public
335
-     * @param int $EVT_ID
336
-     * @return    string
337
-     */
338
-    public static function event_date_as_calendar_page($EVT_ID = 0)
339
-    {
340
-        $datetime = EEH_Event_View::get_primary_date_obj($EVT_ID);
341
-        if ($datetime instanceof EE_Datetime) {
342
-    ?>
14
+	/**
15
+	 * @var EE_Event $_event
16
+	 */
17
+	private static $_event = null;
18
+
19
+
20
+
21
+	/**
22
+	 * get_event
23
+	 * attempts to retrieve an EE_Event object any way it can
24
+	 *
25
+	 * @param int|WP_Post $EVT_ID
26
+	 * @return EE_Event|null
27
+	 * @throws \EE_Error
28
+	 */
29
+	public static function get_event($EVT_ID = 0)
30
+	{
31
+		// international newspaper?
32
+		global $post;
33
+		$EVT_ID = $EVT_ID instanceof WP_Post && $EVT_ID->post_type === 'espresso_events'
34
+			? $EVT_ID->ID
35
+			: absint($EVT_ID);
36
+		// do we already have the Event  you are looking for?
37
+		if (EEH_Event_View::$_event instanceof EE_Event && $EVT_ID && EEH_Event_View::$_event->ID() === $EVT_ID) {
38
+			return EEH_Event_View::$_event;
39
+		}
40
+		// reset property so that the new event is cached.
41
+		EEH_Event_View::$_event = null;
42
+		if (! $EVT_ID && $post instanceof EE_Event) {
43
+			EEH_Event_View::$_event = $post;
44
+			return EEH_Event_View::$_event;
45
+		}
46
+		// if the post type is for an event and it has a cached event and we don't have a different incoming $EVT_ID
47
+		// then let's just use that cached event on the $post object.
48
+		if ($post instanceof WP_Post
49
+			&& $post->post_type === 'espresso_events'
50
+			&& isset($post->EE_Event)
51
+			&& (
52
+				$EVT_ID === 0
53
+				|| $EVT_ID === $post->ID
54
+			)
55
+		) {
56
+			EEH_Event_View::$_event = $post->EE_Event;
57
+			return EEH_Event_View::$_event;
58
+		}
59
+		// If the event we have isn't an event but we do have an EVT_ID, let's try getting the event using the ID.
60
+		if (! EEH_Event_View::$_event instanceof EE_Event && $EVT_ID) {
61
+			EEH_Event_View::$_event = EEM_Event::instance()->get_one_by_ID($EVT_ID);
62
+		}
63
+		return EEH_Event_View::$_event;
64
+	}
65
+
66
+
67
+
68
+	/**
69
+	 *    display_ticket_selector
70
+	 *
71
+	 * @access    public
72
+	 * @param    int $EVT_ID
73
+	 * @return    boolean
74
+	 */
75
+	public static function display_ticket_selector($EVT_ID = 0)
76
+	{
77
+		$event = EEH_Event_View::get_event($EVT_ID);
78
+		return $event instanceof EE_Event ? $event->display_ticket_selector() : false;
79
+	}
80
+
81
+
82
+
83
+	/**
84
+	 *    event_status
85
+	 *
86
+	 * @access    public
87
+	 * @param    int $EVT_ID
88
+	 * @return    string
89
+	 */
90
+	public static function event_status($EVT_ID = 0)
91
+	{
92
+		$event = EEH_Event_View::get_event($EVT_ID);
93
+		return $event instanceof EE_Event ? $event->pretty_active_status(false) : '';
94
+	}
95
+
96
+
97
+
98
+	/**
99
+	 *  event_active_status
100
+	 *
101
+	 *  @access     public
102
+	 * @param    int $EVT_ID
103
+	 *  @return     string
104
+	 */
105
+	public static function event_active_status($EVT_ID = 0, $echo = true)
106
+	{
107
+		$event = EEH_Event_View::get_event($EVT_ID);
108
+		return $event instanceof EE_Event ? $event->pretty_active_status($echo) : 'inactive';
109
+	}
110
+
111
+
112
+
113
+	/**
114
+	 *  event_has_content_or_excerpt
115
+	 *
116
+	 *  @access     public
117
+	 * @param    int $EVT_ID
118
+	 *  @return     string
119
+	 */
120
+	public static function event_has_content_or_excerpt($EVT_ID = 0)
121
+	{
122
+		$event = EEH_Event_View::get_event($EVT_ID);
123
+		$has_content_or_excerpt = false;
124
+		if ($event instanceof EE_Event) {
125
+			$has_content_or_excerpt = $event->description() != '' || $event->short_description(null, null, true) != '' ? true : false;
126
+		}
127
+		if (is_archive() && ! ( espresso_display_full_description_in_event_list() || espresso_display_excerpt_in_event_list() )) {
128
+			$has_content_or_excerpt = false;
129
+		}
130
+		return $has_content_or_excerpt;
131
+	}
132
+
133
+
134
+
135
+	/**
136
+	 *    event_active_status
137
+	 *
138
+	 * @access    public
139
+	 * @param null $num_words
140
+	 * @param null $more
141
+	 * @return    string
142
+	 */
143
+	public static function event_content_or_excerpt($num_words = null, $more = null)
144
+	{
145
+		global $post;
146
+		ob_start();
147
+		if (( is_single() ) || ( is_archive() && espresso_display_full_description_in_event_list() )) {
148
+			// admin has chosen "full description"
149
+			// for the "Event Espresso - Events > Templates > Display Description" option
150
+			the_content();
151
+		} elseif (( is_archive() && espresso_display_excerpt_in_event_list() )) {
152
+			if (has_excerpt($post->ID)) {
153
+				// admin has chosen "excerpt (short desc)"
154
+				// for the "Event Espresso - Events > Templates > Display Description" option
155
+				// AND an excerpt actually exists
156
+				the_excerpt();
157
+			} else {
158
+				// admin has chosen "excerpt (short desc)"
159
+				// for the "Event Espresso - Events > Templates > Display Description" option
160
+				// but NO excerpt actually exists, so we need to create one
161
+				if (! empty($num_words)) {
162
+					if (empty($more)) {
163
+						$more_link_text = __('(more&hellip;)', 'event_espresso');
164
+						$more = ' <a href="' . get_permalink() . '"';
165
+						$more .= ' class="more-link"';
166
+						$more .= \EED_Events_Archive::link_target();
167
+						$more .= '>' . $more_link_text . '</a>';
168
+						$more = apply_filters('the_content_more_link', $more, $more_link_text);
169
+					}
170
+					$content = str_replace('NOMORELINK', '', get_the_content('NOMORELINK'));
171
+
172
+					$content =  wp_trim_words($content, $num_words, ' ') . $more;
173
+				} else {
174
+					$content =  get_the_content();
175
+				}
176
+				global $allowedtags;
177
+				// make sure links are allowed
178
+				$allowedtags['a'] = isset($allowedtags['a'])
179
+					? $allowedtags['a']
180
+					: array();
181
+				// as well as target attribute
182
+				$allowedtags['a']['target'] = isset($allowedtags['a']['target'])
183
+					? $allowedtags['a']['target']
184
+					: false;
185
+				// but get previous value so we can reset it
186
+				$prev_value = $allowedtags['a']['target'];
187
+				$allowedtags['a']['target'] = true;
188
+				$content = wp_kses($content, $allowedtags);
189
+				$content = strip_shortcodes($content);
190
+				echo apply_filters('the_content', $content);
191
+				$allowedtags['a']['target'] = $prev_value;
192
+			}
193
+		} else {
194
+			// admin has chosen "none"
195
+			// for the "Event Espresso - Events > Templates > Display Description" option
196
+			echo apply_filters('the_content', '');
197
+		}
198
+		return ob_get_clean();
199
+	}
200
+
201
+
202
+
203
+	/**
204
+	 *  event_tickets_available
205
+	 *
206
+	 *  @access     public
207
+	 * @param    int $EVT_ID
208
+	 *  @return     EE_Ticket[]
209
+	 */
210
+	public static function event_tickets_available($EVT_ID = 0)
211
+	{
212
+		$event = EEH_Event_View::get_event($EVT_ID);
213
+		$tickets_available_for_purchase = array();
214
+		if ($event instanceof EE_Event) {
215
+			$datetimes = EEH_Event_View::get_all_date_obj($EVT_ID, false);
216
+			foreach ($datetimes as $datetime) {
217
+				$tickets_available_for_purchase = array_merge($tickets_available_for_purchase, $datetime->ticket_types_available_for_purchase());
218
+			}
219
+		}
220
+		return $tickets_available_for_purchase;
221
+	}
222
+
223
+
224
+
225
+	/**
226
+	 *    the_event_date
227
+	 *
228
+	 * @access    public
229
+	 * @param    int $EVT_ID
230
+	 * @param     bool   $hide_uncategorized
231
+	 * @return    string
232
+	 */
233
+	public static function event_categories($EVT_ID = 0, $hide_uncategorized = true)
234
+	{
235
+		$category_links = array();
236
+		$event = EEH_Event_View::get_event($EVT_ID);
237
+		if ($event instanceof EE_Event) {
238
+			$event_categories = get_the_terms($event->ID(), 'espresso_event_categories');
239
+			if ($event_categories) {
240
+				// loop thru terms and create links
241
+				foreach ($event_categories as $term) {
242
+					$url = get_term_link($term, 'espresso_venue_categories');
243
+					if (! is_wp_error($url) && (( $hide_uncategorized && strtolower($term->name) != __('uncategorized', 'event_espresso')) || ! $hide_uncategorized )) {
244
+						$category_links[] = '<a href="' . esc_url($url)
245
+											. '" rel="tag"'
246
+											. \EED_Events_Archive::link_target()
247
+											.'>'
248
+											. $term->name
249
+											. '</a>';
250
+					}
251
+				}
252
+			}
253
+		}
254
+		return implode(', ', $category_links);
255
+	}
256
+
257
+
258
+
259
+	/**
260
+	 *    the_event_date - first date by date order
261
+	 *
262
+	 * @access    public
263
+	 * @param string $dt_frmt
264
+	 * @param string $tm_frmt
265
+	 * @param int    $EVT_ID
266
+	 * @return    string
267
+	 */
268
+	public static function the_event_date($dt_frmt = 'D M jS', $tm_frmt = 'g:i a', $EVT_ID = 0)
269
+	{
270
+		$datetime = EEH_Event_View::get_primary_date_obj($EVT_ID);
271
+		$format = ! empty($dt_frmt) && ! empty($tm_frmt) ? $dt_frmt . ' ' . $tm_frmt : $dt_frmt . $tm_frmt;
272
+		return $datetime instanceof EE_Datetime ? $datetime->get_i18n_datetime('DTT_EVT_start', $format) :  '';
273
+	}
274
+
275
+
276
+
277
+	/**
278
+	 *    the_event_end_date - last date by date order
279
+	 *
280
+	 * @access    public
281
+	 * @param string $dt_frmt
282
+	 * @param string $tm_frmt
283
+	 * @param int    $EVT_ID
284
+	 * @return    string
285
+	 */
286
+	public static function the_event_end_date($dt_frmt = 'D M jS', $tm_frmt = 'g:i a', $EVT_ID = 0)
287
+	{
288
+		$datetime = EEH_Event_View::get_last_date_obj($EVT_ID);
289
+		$format = ! empty($dt_frmt) && ! empty($tm_frmt) ? $dt_frmt . ' ' . $tm_frmt : $dt_frmt . $tm_frmt;
290
+		return $datetime instanceof EE_Datetime ? $datetime->get_i18n_datetime('DTT_EVT_end', $format) : '';
291
+	}
292
+
293
+
294
+
295
+	/**
296
+	 *    the_earliest_event_date - first date chronologically
297
+	 *
298
+	 * @access    public
299
+	 * @param string $dt_frmt
300
+	 * @param string $tm_frmt
301
+	 * @param int    $EVT_ID
302
+	 * @return    string
303
+	 */
304
+	public static function the_earliest_event_date($dt_frmt = 'D M jS', $tm_frmt = 'g:i a', $EVT_ID = 0)
305
+	{
306
+		$datetime = EEH_Event_View::get_earliest_date_obj($EVT_ID);
307
+		$format = ! empty($dt_frmt) && ! empty($tm_frmt) ? $dt_frmt . ' ' . $tm_frmt : $dt_frmt . $tm_frmt;
308
+		return $datetime instanceof EE_Datetime ?  $datetime->get_i18n_datetime('DTT_EVT_start', $format) : '';
309
+	}
310
+
311
+
312
+
313
+	/**
314
+	 *    the_latest_event_date - latest date chronologically
315
+	 *
316
+	 * @access    public
317
+	 * @param string $dt_frmt
318
+	 * @param string $tm_frmt
319
+	 * @param int    $EVT_ID
320
+	 * @return    string
321
+	 */
322
+	public static function the_latest_event_date($dt_frmt = 'D M jS', $tm_frmt = 'g:i a', $EVT_ID = 0)
323
+	{
324
+		$datetime = EEH_Event_View::get_latest_date_obj($EVT_ID);
325
+		$format = ! empty($dt_frmt) && ! empty($tm_frmt) ? $dt_frmt . ' ' . $tm_frmt : $dt_frmt . $tm_frmt;
326
+		return $datetime instanceof EE_Datetime ?  $datetime->get_i18n_datetime('DTT_EVT_end', $format) : '';
327
+	}
328
+
329
+
330
+
331
+	/**
332
+	 *    event_date_as_calendar_page
333
+	 *
334
+	 * @access    public
335
+	 * @param int $EVT_ID
336
+	 * @return    string
337
+	 */
338
+	public static function event_date_as_calendar_page($EVT_ID = 0)
339
+	{
340
+		$datetime = EEH_Event_View::get_primary_date_obj($EVT_ID);
341
+		if ($datetime instanceof EE_Datetime) {
342
+	?>
343 343
         <div class="event-date-calendar-page-dv">
344 344
             <div class="event-date-calendar-page-month-dv"><?php echo $datetime->get_i18n_datetime('DTT_EVT_start', 'M');?></div>
345 345
             <div class="event-date-calendar-page-day-dv"><?php echo $datetime->start_date('d');?></div>
346 346
         </div>
347 347
     <?php
348
-        }
349
-    }
350
-
351
-
352
-
353
-    /**
354
-     *    get_primary_date_obj - orders date by DTT_order
355
-     *
356
-     * @access    public
357
-     * @param int $EVT_ID
358
-     * @return    string
359
-     */
360
-    public static function get_primary_date_obj($EVT_ID = 0)
361
-    {
362
-        $event = EEH_Event_View::get_event($EVT_ID);
363
-        if ($event instanceof EE_Event) {
364
-            $datetimes = $event->get_many_related(
365
-                'Datetime',
366
-                array(
367
-                    'limit' => 1,
368
-                    'order_by' => array( 'DTT_order' => 'ASC' )
369
-                )
370
-            );
371
-            return reset($datetimes);
372
-        } else {
373
-             return false;
374
-        }
375
-    }
376
-
377
-
378
-
379
-    /**
380
-     *    get_last_date_obj - orders date by DTT_order
381
-     *
382
-     * @access    public
383
-     * @param int $EVT_ID
384
-     * @return    string
385
-     */
386
-    public static function get_last_date_obj($EVT_ID = 0)
387
-    {
388
-        $event = EEH_Event_View::get_event($EVT_ID);
389
-        if ($event instanceof EE_Event) {
390
-            $datetimes = $event->get_many_related(
391
-                'Datetime',
392
-                array(
393
-                    'limit' => 1,
394
-                    'order_by' => array( 'DTT_order' => 'DESC' )
395
-                )
396
-            );
397
-            return end($datetimes);
398
-        } else {
399
-            return false;
400
-        }
401
-    }
402
-
403
-
404
-
405
-    /**
406
-     *    get_earliest_date_obj - orders date chronologically
407
-     *
408
-     * @access    public
409
-     * @param int $EVT_ID
410
-     * @return    string
411
-     */
412
-    public static function get_earliest_date_obj($EVT_ID = 0)
413
-    {
414
-        $event = EEH_Event_View::get_event($EVT_ID);
415
-        if ($event instanceof EE_Event) {
416
-            $datetimes = $event->get_many_related(
417
-                'Datetime',
418
-                array(
419
-                    'limit' => 1,
420
-                    'order_by' => array( 'DTT_EVT_start' => 'ASC' )
421
-                )
422
-            );
423
-            return reset($datetimes);
424
-        } else {
425
-             return false;
426
-        }
427
-    }
428
-
429
-
430
-
431
-    /**
432
-     *    get_latest_date_obj - orders date chronologically
433
-     *
434
-     * @access    public
435
-     * @param int $EVT_ID
436
-     * @return    string
437
-     */
438
-    public static function get_latest_date_obj($EVT_ID = 0)
439
-    {
440
-        $event = EEH_Event_View::get_event($EVT_ID);
441
-        if ($event instanceof EE_Event) {
442
-            $datetimes = $event->get_many_related(
443
-                'Datetime',
444
-                array(
445
-                    'limit' => 1,
446
-                    'order_by' => array( 'DTT_EVT_start' => 'DESC' )
447
-                )
448
-            );
449
-            return end($datetimes);
450
-        } else {
451
-            return false;
452
-        }
453
-    }
454
-
455
-    /**
456
-     *    get_next_upcoming_date_obj - return the next upcoming datetime
457
-     *
458
-     * @access    public
459
-     * @param int $EVT_ID
460
-     * @return    EE_Datetime|null
461
-     */
462
-    public static function get_next_upcoming_date_obj($EVT_ID = 0)
463
-    {
464
-        $datetime = EEM_Datetime::instance()->get_one(
465
-            array(
466
-                array(
467
-                    'Event.EVT_ID' => $EVT_ID,
468
-                    'DTT_EVT_start' => array('>=', current_time('mysql', true))
469
-                ),
470
-                'order_by' => array('DTT_EVT_start' => 'asc')
471
-            )
472
-        );
473
-        return $datetime instanceof EE_Datetime ? $datetime : null;
474
-    }
475
-
476
-    /**
477
-     *    get_all_date_obj
478
-     *
479
-     * @access    public
480
-     * @param int $EVT_ID
481
-     * @param null $include_expired
482
-     * @param bool $include_deleted
483
-     * @param null $limit
484
-     * @return EE_Datetime[]
485
-     */
486
-    public static function get_all_date_obj($EVT_ID = 0, $include_expired = null, $include_deleted = false, $limit = null)
487
-    {
488
-        $event = EEH_Event_View::get_event($EVT_ID);
489
-        if ($include_expired === null) {
490
-            if ($event instanceof EE_Event && $event->is_expired()) {
491
-                $include_expired = true;
492
-            } else {
493
-                $include_expired = false;
494
-            }
495
-        }
496
-
497
-        if ($event instanceof EE_Event) {
498
-            return $event->datetimes_ordered($include_expired, $include_deleted, $limit);
499
-        } else {
500
-             return array();
501
-        }
502
-    }
503
-
504
-
505
-
506
-    /**
507
-     *    event_link_url
508
-     *
509
-     * @access    public
510
-     * @param int $EVT_ID
511
-     * @return    string
512
-     */
513
-    public static function event_link_url($EVT_ID = 0)
514
-    {
515
-        $event = EEH_Event_View::get_event($EVT_ID);
516
-        if ($event instanceof EE_Event) {
517
-            $url = $event->external_url() !== null && $event->external_url() !== '' ? $event->external_url() : get_permalink($event->ID());
518
-            return preg_match("~^(?:f|ht)tps?://~i", $url) ? $url : 'http://' . $url;
519
-        }
520
-        return null;
521
-    }
522
-
523
-
524
-
525
-    /**
526
-     *    event_phone
527
-     *
528
-     * @access    public
529
-     * @param int $EVT_ID
530
-     * @return    string
531
-     */
532
-    public static function event_phone($EVT_ID = 0)
533
-    {
534
-        $event = EEH_Event_View::get_event($EVT_ID);
535
-        if ($event instanceof EE_Event) {
536
-            return EEH_Schema::telephone($event->phone());
537
-        }
538
-        return null;
539
-    }
540
-
541
-
542
-
543
-    /**
544
-     *    edit_event_link
545
-     *
546
-     * @access    public
547
-     * @param int    $EVT_ID
548
-     * @param string $link
549
-     * @param string $before
550
-     * @param string $after
551
-     * @return    string
552
-     */
553
-    public static function edit_event_link($EVT_ID = 0, $link = '', $before = '', $after = '')
554
-    {
555
-        $event = EEH_Event_View::get_event($EVT_ID);
556
-        if ($event instanceof EE_Event) {
557
-            // can the user edit this post ?
558
-            if (current_user_can('edit_post', $event->ID())) {
559
-                // set link text
560
-                $link_text = ! empty($link) ? $link : __('edit this event', 'event_espresso');
561
-                // generate nonce
562
-                $nonce = wp_create_nonce('edit_nonce');
563
-                // generate url to event editor for this event
564
-                $url = add_query_arg(array( 'page' => 'espresso_events', 'action' => 'edit', 'post' => $event->ID(), 'edit_nonce' => $nonce ), admin_url());
565
-                // get edit CPT text
566
-                $post_type_obj = get_post_type_object('espresso_events');
567
-                // build final link html
568
-                $link = '<a class="post-edit-link" href="' . $url . '" ';
569
-                $link .= ' title="' . esc_attr($post_type_obj->labels->edit_item) . '"';
570
-                $link .= \EED_Events_Archive::link_target();
571
-                $link .='>' . $link_text . '</a>';
572
-                // put it all together
573
-                return $before . apply_filters('edit_post_link', $link, $event->ID()) . $after;
574
-            }
575
-        }
576
-        return '';
577
-    }
578
-
579
-
580
-
581
-    /**
582
-     * @return string
583
-     */
584
-    public static function event_archive_url()
585
-    {
586
-        return get_post_type_archive_link('espresso_events');
587
-    }
348
+		}
349
+	}
350
+
351
+
352
+
353
+	/**
354
+	 *    get_primary_date_obj - orders date by DTT_order
355
+	 *
356
+	 * @access    public
357
+	 * @param int $EVT_ID
358
+	 * @return    string
359
+	 */
360
+	public static function get_primary_date_obj($EVT_ID = 0)
361
+	{
362
+		$event = EEH_Event_View::get_event($EVT_ID);
363
+		if ($event instanceof EE_Event) {
364
+			$datetimes = $event->get_many_related(
365
+				'Datetime',
366
+				array(
367
+					'limit' => 1,
368
+					'order_by' => array( 'DTT_order' => 'ASC' )
369
+				)
370
+			);
371
+			return reset($datetimes);
372
+		} else {
373
+			 return false;
374
+		}
375
+	}
376
+
377
+
378
+
379
+	/**
380
+	 *    get_last_date_obj - orders date by DTT_order
381
+	 *
382
+	 * @access    public
383
+	 * @param int $EVT_ID
384
+	 * @return    string
385
+	 */
386
+	public static function get_last_date_obj($EVT_ID = 0)
387
+	{
388
+		$event = EEH_Event_View::get_event($EVT_ID);
389
+		if ($event instanceof EE_Event) {
390
+			$datetimes = $event->get_many_related(
391
+				'Datetime',
392
+				array(
393
+					'limit' => 1,
394
+					'order_by' => array( 'DTT_order' => 'DESC' )
395
+				)
396
+			);
397
+			return end($datetimes);
398
+		} else {
399
+			return false;
400
+		}
401
+	}
402
+
403
+
404
+
405
+	/**
406
+	 *    get_earliest_date_obj - orders date chronologically
407
+	 *
408
+	 * @access    public
409
+	 * @param int $EVT_ID
410
+	 * @return    string
411
+	 */
412
+	public static function get_earliest_date_obj($EVT_ID = 0)
413
+	{
414
+		$event = EEH_Event_View::get_event($EVT_ID);
415
+		if ($event instanceof EE_Event) {
416
+			$datetimes = $event->get_many_related(
417
+				'Datetime',
418
+				array(
419
+					'limit' => 1,
420
+					'order_by' => array( 'DTT_EVT_start' => 'ASC' )
421
+				)
422
+			);
423
+			return reset($datetimes);
424
+		} else {
425
+			 return false;
426
+		}
427
+	}
428
+
429
+
430
+
431
+	/**
432
+	 *    get_latest_date_obj - orders date chronologically
433
+	 *
434
+	 * @access    public
435
+	 * @param int $EVT_ID
436
+	 * @return    string
437
+	 */
438
+	public static function get_latest_date_obj($EVT_ID = 0)
439
+	{
440
+		$event = EEH_Event_View::get_event($EVT_ID);
441
+		if ($event instanceof EE_Event) {
442
+			$datetimes = $event->get_many_related(
443
+				'Datetime',
444
+				array(
445
+					'limit' => 1,
446
+					'order_by' => array( 'DTT_EVT_start' => 'DESC' )
447
+				)
448
+			);
449
+			return end($datetimes);
450
+		} else {
451
+			return false;
452
+		}
453
+	}
454
+
455
+	/**
456
+	 *    get_next_upcoming_date_obj - return the next upcoming datetime
457
+	 *
458
+	 * @access    public
459
+	 * @param int $EVT_ID
460
+	 * @return    EE_Datetime|null
461
+	 */
462
+	public static function get_next_upcoming_date_obj($EVT_ID = 0)
463
+	{
464
+		$datetime = EEM_Datetime::instance()->get_one(
465
+			array(
466
+				array(
467
+					'Event.EVT_ID' => $EVT_ID,
468
+					'DTT_EVT_start' => array('>=', current_time('mysql', true))
469
+				),
470
+				'order_by' => array('DTT_EVT_start' => 'asc')
471
+			)
472
+		);
473
+		return $datetime instanceof EE_Datetime ? $datetime : null;
474
+	}
475
+
476
+	/**
477
+	 *    get_all_date_obj
478
+	 *
479
+	 * @access    public
480
+	 * @param int $EVT_ID
481
+	 * @param null $include_expired
482
+	 * @param bool $include_deleted
483
+	 * @param null $limit
484
+	 * @return EE_Datetime[]
485
+	 */
486
+	public static function get_all_date_obj($EVT_ID = 0, $include_expired = null, $include_deleted = false, $limit = null)
487
+	{
488
+		$event = EEH_Event_View::get_event($EVT_ID);
489
+		if ($include_expired === null) {
490
+			if ($event instanceof EE_Event && $event->is_expired()) {
491
+				$include_expired = true;
492
+			} else {
493
+				$include_expired = false;
494
+			}
495
+		}
496
+
497
+		if ($event instanceof EE_Event) {
498
+			return $event->datetimes_ordered($include_expired, $include_deleted, $limit);
499
+		} else {
500
+			 return array();
501
+		}
502
+	}
503
+
504
+
505
+
506
+	/**
507
+	 *    event_link_url
508
+	 *
509
+	 * @access    public
510
+	 * @param int $EVT_ID
511
+	 * @return    string
512
+	 */
513
+	public static function event_link_url($EVT_ID = 0)
514
+	{
515
+		$event = EEH_Event_View::get_event($EVT_ID);
516
+		if ($event instanceof EE_Event) {
517
+			$url = $event->external_url() !== null && $event->external_url() !== '' ? $event->external_url() : get_permalink($event->ID());
518
+			return preg_match("~^(?:f|ht)tps?://~i", $url) ? $url : 'http://' . $url;
519
+		}
520
+		return null;
521
+	}
522
+
523
+
524
+
525
+	/**
526
+	 *    event_phone
527
+	 *
528
+	 * @access    public
529
+	 * @param int $EVT_ID
530
+	 * @return    string
531
+	 */
532
+	public static function event_phone($EVT_ID = 0)
533
+	{
534
+		$event = EEH_Event_View::get_event($EVT_ID);
535
+		if ($event instanceof EE_Event) {
536
+			return EEH_Schema::telephone($event->phone());
537
+		}
538
+		return null;
539
+	}
540
+
541
+
542
+
543
+	/**
544
+	 *    edit_event_link
545
+	 *
546
+	 * @access    public
547
+	 * @param int    $EVT_ID
548
+	 * @param string $link
549
+	 * @param string $before
550
+	 * @param string $after
551
+	 * @return    string
552
+	 */
553
+	public static function edit_event_link($EVT_ID = 0, $link = '', $before = '', $after = '')
554
+	{
555
+		$event = EEH_Event_View::get_event($EVT_ID);
556
+		if ($event instanceof EE_Event) {
557
+			// can the user edit this post ?
558
+			if (current_user_can('edit_post', $event->ID())) {
559
+				// set link text
560
+				$link_text = ! empty($link) ? $link : __('edit this event', 'event_espresso');
561
+				// generate nonce
562
+				$nonce = wp_create_nonce('edit_nonce');
563
+				// generate url to event editor for this event
564
+				$url = add_query_arg(array( 'page' => 'espresso_events', 'action' => 'edit', 'post' => $event->ID(), 'edit_nonce' => $nonce ), admin_url());
565
+				// get edit CPT text
566
+				$post_type_obj = get_post_type_object('espresso_events');
567
+				// build final link html
568
+				$link = '<a class="post-edit-link" href="' . $url . '" ';
569
+				$link .= ' title="' . esc_attr($post_type_obj->labels->edit_item) . '"';
570
+				$link .= \EED_Events_Archive::link_target();
571
+				$link .='>' . $link_text . '</a>';
572
+				// put it all together
573
+				return $before . apply_filters('edit_post_link', $link, $event->ID()) . $after;
574
+			}
575
+		}
576
+		return '';
577
+	}
578
+
579
+
580
+
581
+	/**
582
+	 * @return string
583
+	 */
584
+	public static function event_archive_url()
585
+	{
586
+		return get_post_type_archive_link('espresso_events');
587
+	}
588 588
 }
Please login to merge, or discard this patch.
core/helpers/EEH_File.helper.php 3 patches
Doc Comments   -2 removed lines patch added patch discarded remove patch
@@ -673,8 +673,6 @@
 block discarded – undo
673 673
      * converts it into a "remote" filepath (the filepath the currently-in-use
674 674
      * $wp_filesystem needs to use access the folder or file).
675 675
      * See http://wordpress.stackexchange.com/questions/124900/using-wp-filesystem-in-plugins
676
-     * @param WP_Filesystem_Base $wp_filesystem we aren't initially sure which one
677
-     * is in use, so you need to provide it
678 676
      * @param string $local_filepath the filepath to the folder/file locally
679 677
      * @throws EE_Error if filesystem credentials are required
680 678
      * @return string the remote filepath (eg the filepath the filesystem method, eg
Please login to merge, or discard this patch.
Indentation   +662 added lines, -662 removed lines patch added patch discarded remove patch
@@ -24,666 +24,666 @@
 block discarded – undo
24 24
 class EEH_File extends EEH_Base implements EEHI_File
25 25
 {
26 26
 
27
-    /**
28
-     * @var string $_credentials_form
29
-     */
30
-    private static $_credentials_form;
31
-
32
-    protected static $_wp_filesystem_direct;
33
-
34
-    /**
35
-     * @param string|null $filepath the filepath we want to work in. If its in the
36
-     * wp uploads directory, we'll want to just use the filesystem directly.
37
-     * If not provided, we have to assume its not in the uploads directory
38
-     * @throws EE_Error if filesystem credentials are required
39
-     * @return WP_Filesystem_Base
40
-     */
41
-    private static function _get_wp_filesystem($filepath = null)
42
-    {
43
-        if (apply_filters(
44
-            'FHEE__EEH_File___get_wp_filesystem__allow_using_filesystem_direct',
45
-            $filepath && EEH_File::is_in_uploads_folder($filepath),
46
-            $filepath
47
-        ) ) {
48
-            if (! EEH_File::$_wp_filesystem_direct instanceof WP_Filesystem_Direct) {
49
-                require_once(ABSPATH . 'wp-admin/includes/class-wp-filesystem-base.php');
50
-                $method = 'direct';
51
-                $wp_filesystem_direct_file = apply_filters('filesystem_method_file', ABSPATH . 'wp-admin/includes/class-wp-filesystem-' . $method . '.php', $method);
52
-                // check constants defined, just like in wp-admin/includes/file.php's WP_Filesystem()
53
-                if (! defined('FS_CHMOD_DIR')) {
54
-                    define('FS_CHMOD_DIR', ( fileperms(ABSPATH) & 0777 | 0755 ));
55
-                }
56
-                if (! defined('FS_CHMOD_FILE')) {
57
-                    define('FS_CHMOD_FILE', ( fileperms(ABSPATH . 'index.php') & 0777 | 0644 ));
58
-                }
59
-                require_once($wp_filesystem_direct_file);
60
-                EEH_File::$_wp_filesystem_direct = new WP_Filesystem_Direct(array());
61
-            }
62
-            return EEH_File::$_wp_filesystem_direct;
63
-        }
64
-        global $wp_filesystem;
65
-        // no filesystem setup ???
66
-        if (! $wp_filesystem instanceof WP_Filesystem_Base) {
67
-            // if some eager beaver's just trying to get in there too early...
68
-            // let them do it, because we are one of those eager beavers! :P
69
-            /**
70
-             * more explanations are probably merited. http://codex.wordpress.org/Filesystem_API#Initializing_WP_Filesystem_Base
71
-             * says WP_Filesystem should be used after 'wp_loaded', but currently EE's activation process
72
-             * is setup to mostly happen on 'init', and refactoring to have it happen on
73
-             * 'wp_loaded' is too much work on a BETA milestone.
74
-             * So this fix is expected to work if the WP files are owned by the server user,
75
-             * but probably not if the user needs to enter their FTP credentials to modify files
76
-             * and there may be troubles if the WP files are owned by a different user
77
-             * than the server user. But both of these issues should exist in 4.4 and earlier too
78
-             */
79
-            if (false && ! did_action('wp_loaded')) {
80
-                $msg = __('An attempt to access and/or write to a file on the server could not be completed due to a lack of sufficient credentials.', 'event_espresso');
81
-                if (WP_DEBUG) {
82
-                    $msg .= '<br />' .  __('The WP Filesystem can not be accessed until after the "wp_loaded" hook has run, so it\'s best not to attempt access until the "admin_init" hookpoint.', 'event_espresso');
83
-                }
84
-                throw new EE_Error($msg);
85
-            } else {
86
-                // should be loaded if we are past the wp_loaded hook...
87
-                if (! function_exists('WP_Filesystem')) {
88
-                    require_once(ABSPATH . 'wp-admin/includes/file.php');
89
-                    require_once(ABSPATH . 'wp-admin/includes/template.php');
90
-                }
91
-                // turn on output buffering so that we can capture the credentials form
92
-                ob_start();
93
-                $credentials = request_filesystem_credentials('');
94
-                // store credentials form for the time being
95
-                EEH_File::$_credentials_form = ob_get_clean();
96
-                // basically check for direct or previously configured access
97
-                if (! WP_Filesystem($credentials)) {
98
-                    // if credentials do NOT exist
99
-                    if ($credentials === false) {
100
-                        add_action('admin_notices', array( 'EEH_File', 'display_request_filesystem_credentials_form' ), 999);
101
-                        throw new EE_Error(__('An attempt to access and/or write to a file on the server could not be completed due to a lack of sufficient credentials.', 'event_espresso'));
102
-                    } elseif (is_wp_error($wp_filesystem->errors) && $wp_filesystem->errors->get_error_code()) {
103
-                        add_action('admin_notices', array( 'EEH_File', 'display_request_filesystem_credentials_form' ), 999);
104
-                        throw new EE_Error(
105
-                            sprintf(
106
-                                __('WP Filesystem Error: $1%s', 'event_espresso'),
107
-                                $wp_filesystem->errors->get_error_message()
108
-                            )
109
-                        );
110
-                    }
111
-                }
112
-            }
113
-        }
114
-        return $wp_filesystem;
115
-    }
116
-
117
-    /**
118
-     * display_request_filesystem_credentials_form
119
-     */
120
-    public static function display_request_filesystem_credentials_form()
121
-    {
122
-        if (! empty(EEH_File::$_credentials_form)) {
123
-            echo '<div class="updated espresso-notices-attention"><p>' . EEH_File::$_credentials_form . '</p></div>';
124
-        }
125
-    }
126
-
127
-
128
-
129
-    /**
130
-     *    verify_filepath_and_permissions
131
-     *    checks that a file is readable and has sufficient file permissions set to access
132
-     *
133
-     * @access public
134
-     * @param string $full_file_path - full server path to the folder or file
135
-     * @param string $file_name      - name of file if checking a file
136
-     * @param string $file_ext       - file extension (ie: "php") if checking a file
137
-     * @param string $type_of_file   - general type of file (ie: "module"), this is only used to improve error messages
138
-     * @throws EE_Error if filesystem credentials are required
139
-     * @return bool
140
-     */
141
-    public static function verify_filepath_and_permissions($full_file_path = '', $file_name = '', $file_ext = '', $type_of_file = '')
142
-    {
143
-        // load WP_Filesystem and set file permissions
144
-        $wp_filesystem = EEH_File::_get_wp_filesystem($full_file_path);
145
-        $full_file_path = EEH_File::standardise_directory_separators($full_file_path);
146
-        if (! $wp_filesystem->is_readable(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path))) {
147
-            $file_name = ! empty($type_of_file) ? $file_name . ' ' . $type_of_file : $file_name;
148
-            $file_name .= ! empty($file_ext) ? ' file' : ' folder';
149
-            $msg = sprintf(
150
-                __('The requested %1$s could not be found or is not readable, possibly due to an incorrect filepath, or incorrect file permissions.%2$s', 'event_espresso'),
151
-                $file_name,
152
-                '<br />'
153
-            );
154
-            if (EEH_File::exists($full_file_path)) {
155
-                $msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_file_path, $type_of_file);
156
-            } else {
157
-                // no file permissions means the file was not found
158
-                $msg .= sprintf(
159
-                    __('Please ensure the following path is correct: "%s".', 'event_espresso'),
160
-                    $full_file_path
161
-                );
162
-            }
163
-            if (defined('WP_DEBUG') && WP_DEBUG) {
164
-                throw new EE_Error($msg . '||' . $msg);
165
-            }
166
-            return false;
167
-        }
168
-        return true;
169
-    }
170
-
171
-
172
-
173
-    /**
174
-     * _permissions_error_for_unreadable_filepath - attempts to determine why permissions are set incorrectly for a file or folder
175
-     *
176
-     * @access private
177
-     * @param string $full_file_path - full server path to the folder or file
178
-     * @param string $type_of_file - general type of file (ie: "module"), this is only used to improve error messages
179
-     * @throws EE_Error if filesystem credentials are required
180
-     * @return string
181
-     */
182
-    private static function _permissions_error_for_unreadable_filepath($full_file_path = '', $type_of_file = '')
183
-    {
184
-        // load WP_Filesystem and set file permissions
185
-        $wp_filesystem = EEH_File::_get_wp_filesystem($full_file_path);
186
-        // check file permissions
187
-        $perms = $wp_filesystem->getchmod(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path));
188
-        if ($perms) {
189
-            // file permissions exist, but way be set incorrectly
190
-            $type_of_file = ! empty($type_of_file) ? $type_of_file . ' ' : '';
191
-            $type_of_file .= ! empty($type_of_file) ? 'file' : 'folder';
192
-            return sprintf(
193
-                __('File permissions for the requested %1$s are currently set at "%2$s". The recommended permissions are 644 for files and 755 for folders.', 'event_espresso'),
194
-                $type_of_file,
195
-                $perms
196
-            );
197
-        } else {
198
-            // file exists but file permissions could not be read ?!?!
199
-            return sprintf(
200
-                __('Please ensure that the server and/or PHP configuration allows the current process to access the following file: "%s".', 'event_espresso'),
201
-                $full_file_path
202
-            );
203
-        }
204
-    }
205
-
206
-
207
-
208
-    /**
209
-     * ensure_folder_exists_and_is_writable
210
-     * ensures that a folder exists and is writable, will attempt to create folder if it does not exist
211
-     * Also ensures all the parent folders exist, and if not tries to create them.
212
-     * Also, if this function creates the folder, adds a .htaccess file and index.html file
213
-     * @param string $folder
214
-     * @throws EE_Error if the folder exists and is writeable, but for some reason we
215
-     * can't write to it
216
-     * @return bool false if folder isn't writable; true if it exists and is writeable,
217
-     */
218
-    public static function ensure_folder_exists_and_is_writable($folder = '')
219
-    {
220
-        if (empty($folder)) {
221
-            return false;
222
-        }
223
-        // remove ending DS
224
-        $folder = EEH_File::standardise_directory_separators(rtrim($folder, '/\\'));
225
-        $parent_folder = EEH_File::get_parent_folder($folder);
226
-        // add DS to folder
227
-        $folder = EEH_File::end_with_directory_separator($folder);
228
-        $wp_filesystem = EEH_File::_get_wp_filesystem($folder);
229
-        if (! $wp_filesystem->is_dir(EEH_File::convert_local_filepath_to_remote_filepath($folder))) {
230
-            // ok so it doesn't exist. Does its parent? Can we write to it?
231
-            if (! EEH_File::ensure_folder_exists_and_is_writable($parent_folder)) {
232
-                return false;
233
-            }
234
-            if (! EEH_File::verify_is_writable($parent_folder, 'folder')) {
235
-                return false;
236
-            } else {
237
-                if (! $wp_filesystem->mkdir(EEH_File::convert_local_filepath_to_remote_filepath($folder))) {
238
-                    if (defined('WP_DEBUG') && WP_DEBUG) {
239
-                        $msg = sprintf(__('"%s" could not be created.', 'event_espresso'), $folder);
240
-                        $msg .= EEH_File::_permissions_error_for_unreadable_filepath($folder);
241
-                        throw new EE_Error($msg);
242
-                    }
243
-                    return false;
244
-                }
245
-                EEH_File::add_index_file($folder);
246
-            }
247
-        } elseif (! EEH_File::verify_is_writable($folder, 'folder')) {
248
-            return false;
249
-        }
250
-        return true;
251
-    }
252
-
253
-
254
-
255
-    /**
256
-     * verify_is_writable - checks if a file or folder is writable
257
-     * @param string $full_path      - full server path to file or folder
258
-     * @param string $file_or_folder - whether checking a file or folder
259
-     * @throws EE_Error if filesystem credentials are required
260
-     * @return bool
261
-     */
262
-    public static function verify_is_writable($full_path = '', $file_or_folder = 'folder')
263
-    {
264
-        // load WP_Filesystem and set file permissions
265
-        $wp_filesystem = EEH_File::_get_wp_filesystem($full_path);
266
-        $full_path = EEH_File::standardise_directory_separators($full_path);
267
-        if (! $wp_filesystem->is_writable(EEH_File::convert_local_filepath_to_remote_filepath($full_path))) {
268
-            if (defined('WP_DEBUG') && WP_DEBUG) {
269
-                $msg = sprintf(__('The "%1$s" %2$s is not writable.', 'event_espresso'), $full_path, $file_or_folder);
270
-                $msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_path);
271
-                throw new EE_Error($msg);
272
-            }
273
-            return false;
274
-        }
275
-        return true;
276
-    }
277
-
278
-
279
-
280
-    /**
281
-     * ensure_file_exists_and_is_writable
282
-     * ensures that a file exists and is writable, will attempt to create file if it does not exist.
283
-     * Also ensures all the parent folders exist, and if not tries to create them.
284
-     * @param string $full_file_path
285
-     * @throws EE_Error if filesystem credentials are required
286
-     * @return bool
287
-     */
288
-    public static function ensure_file_exists_and_is_writable($full_file_path = '')
289
-    {
290
-        // load WP_Filesystem and set file permissions
291
-        $wp_filesystem = EEH_File::_get_wp_filesystem($full_file_path);
292
-        $full_file_path = EEH_File::standardise_directory_separators($full_file_path);
293
-        $parent_folder = EEH_File::get_parent_folder($full_file_path);
294
-        if (! EEH_File::exists($full_file_path)) {
295
-            if (! EEH_File::ensure_folder_exists_and_is_writable($parent_folder)) {
296
-                return false;
297
-            }
298
-            if (! $wp_filesystem->touch(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path))) {
299
-                if (defined('WP_DEBUG') && WP_DEBUG) {
300
-                    $msg = sprintf(__('The "%s" file could not be created.', 'event_espresso'), $full_file_path);
301
-                    $msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_file_path);
302
-                    throw new EE_Error($msg);
303
-                }
304
-                return false;
305
-            }
306
-        }
307
-        if (! EEH_File::verify_is_writable($full_file_path, 'file')) {
308
-            return false;
309
-        }
310
-        return true;
311
-    }
312
-
313
-    /**
314
-     * Gets the parent folder. If provided with file, gets the folder that contains it.
315
-     * If provided a folder, gets its parent folder.
316
-     * @param string $file_or_folder_path
317
-     * @return string parent folder, ENDING with a directory separator
318
-     */
319
-    public static function get_parent_folder($file_or_folder_path)
320
-    {
321
-        // find the last DS, ignoring a DS on the very end
322
-        // eg if given "/var/something/somewhere/", we want to get "somewhere"'s
323
-        // parent folder, "/var/something/"
324
-        $ds = strlen($file_or_folder_path) > 1
325
-            ? strrpos($file_or_folder_path, DS, -2)
326
-            : strlen($file_or_folder_path);
327
-        return substr($file_or_folder_path, 0, $ds + 1);
328
-    }
329
-
330
-    // public static function ensure_folder_exists_recursively( $folder ) {
331
-    //
332
-    // }
333
-
334
-
335
-
336
-    /**
337
-     * get_file_contents
338
-     * @param string $full_file_path
339
-     * @throws EE_Error if filesystem credentials are required
340
-     * @return string
341
-     */
342
-    public static function get_file_contents($full_file_path = '')
343
-    {
344
-        $full_file_path = EEH_File::standardise_directory_separators($full_file_path);
345
-        if (EEH_File::verify_filepath_and_permissions($full_file_path, EEH_File::get_filename_from_filepath($full_file_path), EEH_File::get_file_extension($full_file_path))) {
346
-            // load WP_Filesystem and set file permissions
347
-            $wp_filesystem = EEH_File::_get_wp_filesystem($full_file_path);
348
-            return $wp_filesystem->get_contents(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path));
349
-        }
350
-        return '';
351
-    }
352
-
353
-
354
-
355
-    /**
356
-     * write_file
357
-     * @param string $full_file_path
358
-     * @param string $file_contents - the content to be written to the file
359
-     * @param string $file_type
360
-     * @throws EE_Error if filesystem credentials are required
361
-     * @return bool
362
-     */
363
-    public static function write_to_file($full_file_path = '', $file_contents = '', $file_type = '')
364
-    {
365
-        $full_file_path = EEH_File::standardise_directory_separators($full_file_path);
366
-        $file_type = ! empty($file_type) ? rtrim($file_type, ' ') . ' ' : '';
367
-        $folder = EEH_File::remove_filename_from_filepath($full_file_path);
368
-        if (! EEH_File::verify_is_writable($folder, 'folder')) {
369
-            if (defined('WP_DEBUG') && WP_DEBUG) {
370
-                $msg = sprintf(__('The %1$sfile located at "%2$s" is not writable.', 'event_espresso'), $file_type, $full_file_path);
371
-                $msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_file_path);
372
-                throw new EE_Error($msg);
373
-            }
374
-            return false;
375
-        }
376
-        // load WP_Filesystem and set file permissions
377
-        $wp_filesystem = EEH_File::_get_wp_filesystem($full_file_path);
378
-        // write the file
379
-        if (! $wp_filesystem->put_contents(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path), $file_contents)) {
380
-            if (defined('WP_DEBUG') && WP_DEBUG) {
381
-                $msg = sprintf(__('The %1$sfile located at "%2$s" could not be written to.', 'event_espresso'), $file_type, $full_file_path);
382
-                $msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_file_path, 'f');
383
-                throw new EE_Error($msg);
384
-            }
385
-            return false;
386
-        }
387
-        return true;
388
-    }
389
-
390
-    /**
391
-     * Wrapper for WP_Filesystem_Base::delete
392
-     *
393
-     * @param string $filepath
394
-     * @param boolean $recursive
395
-     * @param boolean|string $type 'd' for directory, 'f' for file
396
-     * @throws EE_Error if filesystem credentials are required
397
-     * @return boolean
398
-     */
399
-    public static function delete($filepath, $recursive = false, $type = false)
400
-    {
401
-        $wp_filesystem = EEH_File::_get_wp_filesystem();
402
-        return $wp_filesystem->delete($filepath, $recursive, $type) ? true : false;
403
-    }
404
-
405
-
406
-
407
-    /**
408
-     * exists
409
-     * checks if a file exists using the WP filesystem
410
-     * @param string $full_file_path
411
-     * @throws EE_Error if filesystem credentials are required
412
-     * @return bool
413
-     */
414
-    public static function exists($full_file_path = '')
415
-    {
416
-        $wp_filesystem = EEH_File::_get_wp_filesystem($full_file_path);
417
-        return $wp_filesystem->exists(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path)) ? true : false;
418
-    }
419
-
420
-
421
-
422
-    /**
423
-     * is_readable
424
-     * checks if a file is_readable using the WP filesystem
425
-     *
426
-     * @param string $full_file_path
427
-     * @throws EE_Error if filesystem credentials are required
428
-     * @return bool
429
-     */
430
-    public static function is_readable($full_file_path = '')
431
-    {
432
-        $wp_filesystem = EEH_File::_get_wp_filesystem($full_file_path);
433
-        if ($wp_filesystem->is_readable(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path))) {
434
-            return true;
435
-        } else {
436
-            return false;
437
-        }
438
-    }
439
-
440
-
441
-
442
-    /**
443
-     * remove_filename_from_filepath
444
-     * given a full path to a file including the filename itself, this removes  the filename and returns the path, up to, but NOT including the filename OR slash
445
-     *
446
-     * @param string $full_file_path
447
-     * @return string
448
-     */
449
-    public static function remove_filename_from_filepath($full_file_path = '')
450
-    {
451
-        return pathinfo($full_file_path, PATHINFO_DIRNAME);
452
-    }
453
-
454
-
455
-    /**
456
-     * get_filename_from_filepath. Arguably the same as basename()
457
-     *
458
-     * @param string $full_file_path
459
-     * @return string
460
-     */
461
-    public static function get_filename_from_filepath($full_file_path = '')
462
-    {
463
-        return pathinfo($full_file_path, PATHINFO_BASENAME);
464
-    }
465
-
466
-
467
-    /**
468
-     * get_file_extension
469
-     *
470
-     * @param string $full_file_path
471
-     * @return string
472
-     */
473
-    public static function get_file_extension($full_file_path = '')
474
-    {
475
-        return pathinfo($full_file_path, PATHINFO_EXTENSION);
476
-    }
477
-
478
-
479
-
480
-    /**
481
-     * add_htaccess_deny_from_all so the webserver cannot access this folder
482
-     * @param string $folder
483
-     * @throws EE_Error if filesystem credentials are required
484
-     * @return bool
485
-     */
486
-    public static function add_htaccess_deny_from_all($folder = '')
487
-    {
488
-        $folder = EEH_File::standardise_and_end_with_directory_separator($folder);
489
-        if (! EEH_File::exists($folder . '.htaccess')) {
490
-            if (! EEH_File::write_to_file($folder . '.htaccess', 'deny from all', '.htaccess')) {
491
-                return false;
492
-            }
493
-        }
494
-
495
-        return true;
496
-    }
497
-
498
-    /**
499
-     * Adds an index file to this folder, so folks can't list all the file's contents
500
-     * @param string $folder
501
-     * @throws EE_Error if filesystem credentials are required
502
-     * @return boolean
503
-     */
504
-    public static function add_index_file($folder)
505
-    {
506
-        $folder = EEH_File::standardise_and_end_with_directory_separator($folder);
507
-        if (! EEH_File::exists($folder . 'index.php')) {
508
-            if (! EEH_File::write_to_file($folder . 'index.php', 'You are not permitted to read from this folder', '.php')) {
509
-                return false;
510
-            }
511
-        }
512
-        return true;
513
-    }
514
-
515
-
516
-
517
-    /**
518
-     * Given that the file in $file_path has the normal name, (ie, CLASSNAME.whatever.php),
519
-     * extract that classname.
520
-     * @param string $file_path
521
-     * @return string
522
-     */
523
-    public static function get_classname_from_filepath_with_standard_filename($file_path)
524
-    {
525
-        // extract file from path
526
-        $filename = basename($file_path);
527
-        // now remove the first period and everything after
528
-        $pos_of_first_period = strpos($filename, '.');
529
-        return substr($filename, 0, $pos_of_first_period);
530
-    }
531
-
532
-
533
-
534
-    /**
535
-     * standardise_directory_separators
536
-     *  convert all directory separators in a file path to whatever is set for DS
537
-     * @param string $file_path
538
-     * @return string
539
-     */
540
-    public static function standardise_directory_separators($file_path)
541
-    {
542
-        return str_replace(array( '\\', '/' ), DS, $file_path);
543
-    }
544
-
545
-
546
-
547
-    /**
548
-     * end_with_directory_separator
549
-     *  ensures that file path ends with DS
550
-     * @param string $file_path
551
-     * @return string
552
-     */
553
-    public static function end_with_directory_separator($file_path)
554
-    {
555
-        return rtrim($file_path, '/\\') . DS;
556
-    }
557
-
558
-
559
-
560
-    /**
561
-     * shorthand for both EEH_FIle::end_with_directory_separator AND EEH_File::standardise_directory_separators
562
-     * @param $file_path
563
-     * @return string
564
-     */
565
-    public static function standardise_and_end_with_directory_separator($file_path)
566
-    {
567
-        return self::end_with_directory_separator(self::standardise_directory_separators($file_path));
568
-    }
569
-
570
-
571
-
572
-    /**
573
-     * takes the folder name (with or without trailing slash) and finds the files it in,
574
-     * and what the class's name inside of each should be.
575
-     * @param array $folder_paths
576
-     * @param boolean $index_numerically if TRUE, the returned array will be indexed numerically;
577
-     *      if FALSE (Default), returned array will be indexed by the filenames minus extensions.
578
-     *      Set it TRUE if you know there are files in the directory with the same name but different extensions
579
-     * @throws EE_Error if filesystem credentials are required
580
-     * @return array if $index_numerically == TRUE keys are numeric ,
581
-     *      if $index_numerically == FALSE (Default) keys are what the class names SHOULD be;
582
-     *       and values are their filepaths
583
-     */
584
-    public static function get_contents_of_folders($folder_paths = array(), $index_numerically = false)
585
-    {
586
-        $class_to_folder_path = array();
587
-        foreach ($folder_paths as $folder_path) {
588
-            $folder_path = self::standardise_and_end_with_directory_separator($folder_path);
589
-            // load WP_Filesystem and set file permissions
590
-            $files_in_folder = glob($folder_path . '*');
591
-            $class_to_folder_path = array();
592
-            if ($files_in_folder) {
593
-                foreach ($files_in_folder as $file_path) {
594
-                    // only add files, not folders
595
-                    if (! is_dir($file_path)) {
596
-                        if ($index_numerically) {
597
-                            $class_to_folder_path[] = $file_path;
598
-                        } else {
599
-                            $classname = self::get_classname_from_filepath_with_standard_filename($file_path);
600
-                            $class_to_folder_path[ $classname ] = $file_path;
601
-                        }
602
-                    }
603
-                }
604
-            }
605
-        }
606
-        return $class_to_folder_path;
607
-    }
608
-
609
-
610
-
611
-    /**
612
-     * Copies a file. Mostly a wrapper of WP_Filesystem::copy
613
-     * @param string $source_file
614
-     * @param string $destination_file
615
-     * @param boolean $overwrite
616
-     * @throws EE_Error if filesystem credentials are required
617
-     * @return boolean success
618
-     */
619
-    public static function copy($source_file, $destination_file, $overwrite = false)
620
-    {
621
-        $full_source_path = EEH_File::standardise_directory_separators($source_file);
622
-        if (! EEH_File::exists($full_source_path)) {
623
-            if (defined('WP_DEBUG') && WP_DEBUG) {
624
-                $msg = sprintf(__('The file located at "%2$s" is not readable or doesn\'t exist.', 'event_espresso'), $full_source_path);
625
-                $msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_source_path);
626
-                throw new EE_Error($msg);
627
-            }
628
-            return false;
629
-        }
630
-
631
-        $full_dest_path = EEH_File::standardise_directory_separators($destination_file);
632
-        $folder = EEH_File::remove_filename_from_filepath($full_dest_path);
633
-        EEH_File::ensure_folder_exists_and_is_writable($folder);
634
-        if (! EEH_File::verify_is_writable($folder, 'folder')) {
635
-            if (defined('WP_DEBUG') && WP_DEBUG) {
636
-                $msg = sprintf(__('The file located at "%2$s" is not writable.', 'event_espresso'), $full_dest_path);
637
-                $msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_dest_path);
638
-                throw new EE_Error($msg);
639
-            }
640
-            return false;
641
-        }
642
-
643
-        // load WP_Filesystem and set file permissions
644
-        $wp_filesystem = EEH_File::_get_wp_filesystem($destination_file);
645
-        // write the file
646
-        if (! $wp_filesystem->copy(
647
-            EEH_File::convert_local_filepath_to_remote_filepath($full_source_path),
648
-            EEH_File::convert_local_filepath_to_remote_filepath($full_dest_path),
649
-            $overwrite
650
-        )) {
651
-            if (defined('WP_DEBUG') && WP_DEBUG) {
652
-                $msg = sprintf(__('Attempted writing to file %1$s, but could not, probably because of permissions issues', 'event_espresso'), $full_source_path);
653
-                $msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_source_path, 'f');
654
-                throw new EE_Error($msg);
655
-            }
656
-            return false;
657
-        }
658
-        return true;
659
-    }
660
-
661
-    /**
662
-     * Reports whether or not the filepath is in the EE uploads folder or not
663
-     * @param string $filepath
664
-     * @return boolean
665
-     */
666
-    public static function is_in_uploads_folder($filepath)
667
-    {
668
-        $uploads = wp_upload_dir();
669
-        return strpos($filepath, $uploads['basedir']) === 0 ? true : false;
670
-    }
671
-
672
-    /**
673
-     * Given a "local" filepath (what you probably thought was the only filepath),
674
-     * converts it into a "remote" filepath (the filepath the currently-in-use
675
-     * $wp_filesystem needs to use access the folder or file).
676
-     * See http://wordpress.stackexchange.com/questions/124900/using-wp-filesystem-in-plugins
677
-     * @param WP_Filesystem_Base $wp_filesystem we aren't initially sure which one
678
-     * is in use, so you need to provide it
679
-     * @param string $local_filepath the filepath to the folder/file locally
680
-     * @throws EE_Error if filesystem credentials are required
681
-     * @return string the remote filepath (eg the filepath the filesystem method, eg
682
-     * ftp or ssh, will use to access the folder
683
-     */
684
-    public static function convert_local_filepath_to_remote_filepath($local_filepath)
685
-    {
686
-        $wp_filesystem = EEH_File::_get_wp_filesystem($local_filepath);
687
-        return str_replace(WP_CONTENT_DIR . DS, $wp_filesystem->wp_content_dir(), $local_filepath);
688
-    }
27
+	/**
28
+	 * @var string $_credentials_form
29
+	 */
30
+	private static $_credentials_form;
31
+
32
+	protected static $_wp_filesystem_direct;
33
+
34
+	/**
35
+	 * @param string|null $filepath the filepath we want to work in. If its in the
36
+	 * wp uploads directory, we'll want to just use the filesystem directly.
37
+	 * If not provided, we have to assume its not in the uploads directory
38
+	 * @throws EE_Error if filesystem credentials are required
39
+	 * @return WP_Filesystem_Base
40
+	 */
41
+	private static function _get_wp_filesystem($filepath = null)
42
+	{
43
+		if (apply_filters(
44
+			'FHEE__EEH_File___get_wp_filesystem__allow_using_filesystem_direct',
45
+			$filepath && EEH_File::is_in_uploads_folder($filepath),
46
+			$filepath
47
+		) ) {
48
+			if (! EEH_File::$_wp_filesystem_direct instanceof WP_Filesystem_Direct) {
49
+				require_once(ABSPATH . 'wp-admin/includes/class-wp-filesystem-base.php');
50
+				$method = 'direct';
51
+				$wp_filesystem_direct_file = apply_filters('filesystem_method_file', ABSPATH . 'wp-admin/includes/class-wp-filesystem-' . $method . '.php', $method);
52
+				// check constants defined, just like in wp-admin/includes/file.php's WP_Filesystem()
53
+				if (! defined('FS_CHMOD_DIR')) {
54
+					define('FS_CHMOD_DIR', ( fileperms(ABSPATH) & 0777 | 0755 ));
55
+				}
56
+				if (! defined('FS_CHMOD_FILE')) {
57
+					define('FS_CHMOD_FILE', ( fileperms(ABSPATH . 'index.php') & 0777 | 0644 ));
58
+				}
59
+				require_once($wp_filesystem_direct_file);
60
+				EEH_File::$_wp_filesystem_direct = new WP_Filesystem_Direct(array());
61
+			}
62
+			return EEH_File::$_wp_filesystem_direct;
63
+		}
64
+		global $wp_filesystem;
65
+		// no filesystem setup ???
66
+		if (! $wp_filesystem instanceof WP_Filesystem_Base) {
67
+			// if some eager beaver's just trying to get in there too early...
68
+			// let them do it, because we are one of those eager beavers! :P
69
+			/**
70
+			 * more explanations are probably merited. http://codex.wordpress.org/Filesystem_API#Initializing_WP_Filesystem_Base
71
+			 * says WP_Filesystem should be used after 'wp_loaded', but currently EE's activation process
72
+			 * is setup to mostly happen on 'init', and refactoring to have it happen on
73
+			 * 'wp_loaded' is too much work on a BETA milestone.
74
+			 * So this fix is expected to work if the WP files are owned by the server user,
75
+			 * but probably not if the user needs to enter their FTP credentials to modify files
76
+			 * and there may be troubles if the WP files are owned by a different user
77
+			 * than the server user. But both of these issues should exist in 4.4 and earlier too
78
+			 */
79
+			if (false && ! did_action('wp_loaded')) {
80
+				$msg = __('An attempt to access and/or write to a file on the server could not be completed due to a lack of sufficient credentials.', 'event_espresso');
81
+				if (WP_DEBUG) {
82
+					$msg .= '<br />' .  __('The WP Filesystem can not be accessed until after the "wp_loaded" hook has run, so it\'s best not to attempt access until the "admin_init" hookpoint.', 'event_espresso');
83
+				}
84
+				throw new EE_Error($msg);
85
+			} else {
86
+				// should be loaded if we are past the wp_loaded hook...
87
+				if (! function_exists('WP_Filesystem')) {
88
+					require_once(ABSPATH . 'wp-admin/includes/file.php');
89
+					require_once(ABSPATH . 'wp-admin/includes/template.php');
90
+				}
91
+				// turn on output buffering so that we can capture the credentials form
92
+				ob_start();
93
+				$credentials = request_filesystem_credentials('');
94
+				// store credentials form for the time being
95
+				EEH_File::$_credentials_form = ob_get_clean();
96
+				// basically check for direct or previously configured access
97
+				if (! WP_Filesystem($credentials)) {
98
+					// if credentials do NOT exist
99
+					if ($credentials === false) {
100
+						add_action('admin_notices', array( 'EEH_File', 'display_request_filesystem_credentials_form' ), 999);
101
+						throw new EE_Error(__('An attempt to access and/or write to a file on the server could not be completed due to a lack of sufficient credentials.', 'event_espresso'));
102
+					} elseif (is_wp_error($wp_filesystem->errors) && $wp_filesystem->errors->get_error_code()) {
103
+						add_action('admin_notices', array( 'EEH_File', 'display_request_filesystem_credentials_form' ), 999);
104
+						throw new EE_Error(
105
+							sprintf(
106
+								__('WP Filesystem Error: $1%s', 'event_espresso'),
107
+								$wp_filesystem->errors->get_error_message()
108
+							)
109
+						);
110
+					}
111
+				}
112
+			}
113
+		}
114
+		return $wp_filesystem;
115
+	}
116
+
117
+	/**
118
+	 * display_request_filesystem_credentials_form
119
+	 */
120
+	public static function display_request_filesystem_credentials_form()
121
+	{
122
+		if (! empty(EEH_File::$_credentials_form)) {
123
+			echo '<div class="updated espresso-notices-attention"><p>' . EEH_File::$_credentials_form . '</p></div>';
124
+		}
125
+	}
126
+
127
+
128
+
129
+	/**
130
+	 *    verify_filepath_and_permissions
131
+	 *    checks that a file is readable and has sufficient file permissions set to access
132
+	 *
133
+	 * @access public
134
+	 * @param string $full_file_path - full server path to the folder or file
135
+	 * @param string $file_name      - name of file if checking a file
136
+	 * @param string $file_ext       - file extension (ie: "php") if checking a file
137
+	 * @param string $type_of_file   - general type of file (ie: "module"), this is only used to improve error messages
138
+	 * @throws EE_Error if filesystem credentials are required
139
+	 * @return bool
140
+	 */
141
+	public static function verify_filepath_and_permissions($full_file_path = '', $file_name = '', $file_ext = '', $type_of_file = '')
142
+	{
143
+		// load WP_Filesystem and set file permissions
144
+		$wp_filesystem = EEH_File::_get_wp_filesystem($full_file_path);
145
+		$full_file_path = EEH_File::standardise_directory_separators($full_file_path);
146
+		if (! $wp_filesystem->is_readable(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path))) {
147
+			$file_name = ! empty($type_of_file) ? $file_name . ' ' . $type_of_file : $file_name;
148
+			$file_name .= ! empty($file_ext) ? ' file' : ' folder';
149
+			$msg = sprintf(
150
+				__('The requested %1$s could not be found or is not readable, possibly due to an incorrect filepath, or incorrect file permissions.%2$s', 'event_espresso'),
151
+				$file_name,
152
+				'<br />'
153
+			);
154
+			if (EEH_File::exists($full_file_path)) {
155
+				$msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_file_path, $type_of_file);
156
+			} else {
157
+				// no file permissions means the file was not found
158
+				$msg .= sprintf(
159
+					__('Please ensure the following path is correct: "%s".', 'event_espresso'),
160
+					$full_file_path
161
+				);
162
+			}
163
+			if (defined('WP_DEBUG') && WP_DEBUG) {
164
+				throw new EE_Error($msg . '||' . $msg);
165
+			}
166
+			return false;
167
+		}
168
+		return true;
169
+	}
170
+
171
+
172
+
173
+	/**
174
+	 * _permissions_error_for_unreadable_filepath - attempts to determine why permissions are set incorrectly for a file or folder
175
+	 *
176
+	 * @access private
177
+	 * @param string $full_file_path - full server path to the folder or file
178
+	 * @param string $type_of_file - general type of file (ie: "module"), this is only used to improve error messages
179
+	 * @throws EE_Error if filesystem credentials are required
180
+	 * @return string
181
+	 */
182
+	private static function _permissions_error_for_unreadable_filepath($full_file_path = '', $type_of_file = '')
183
+	{
184
+		// load WP_Filesystem and set file permissions
185
+		$wp_filesystem = EEH_File::_get_wp_filesystem($full_file_path);
186
+		// check file permissions
187
+		$perms = $wp_filesystem->getchmod(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path));
188
+		if ($perms) {
189
+			// file permissions exist, but way be set incorrectly
190
+			$type_of_file = ! empty($type_of_file) ? $type_of_file . ' ' : '';
191
+			$type_of_file .= ! empty($type_of_file) ? 'file' : 'folder';
192
+			return sprintf(
193
+				__('File permissions for the requested %1$s are currently set at "%2$s". The recommended permissions are 644 for files and 755 for folders.', 'event_espresso'),
194
+				$type_of_file,
195
+				$perms
196
+			);
197
+		} else {
198
+			// file exists but file permissions could not be read ?!?!
199
+			return sprintf(
200
+				__('Please ensure that the server and/or PHP configuration allows the current process to access the following file: "%s".', 'event_espresso'),
201
+				$full_file_path
202
+			);
203
+		}
204
+	}
205
+
206
+
207
+
208
+	/**
209
+	 * ensure_folder_exists_and_is_writable
210
+	 * ensures that a folder exists and is writable, will attempt to create folder if it does not exist
211
+	 * Also ensures all the parent folders exist, and if not tries to create them.
212
+	 * Also, if this function creates the folder, adds a .htaccess file and index.html file
213
+	 * @param string $folder
214
+	 * @throws EE_Error if the folder exists and is writeable, but for some reason we
215
+	 * can't write to it
216
+	 * @return bool false if folder isn't writable; true if it exists and is writeable,
217
+	 */
218
+	public static function ensure_folder_exists_and_is_writable($folder = '')
219
+	{
220
+		if (empty($folder)) {
221
+			return false;
222
+		}
223
+		// remove ending DS
224
+		$folder = EEH_File::standardise_directory_separators(rtrim($folder, '/\\'));
225
+		$parent_folder = EEH_File::get_parent_folder($folder);
226
+		// add DS to folder
227
+		$folder = EEH_File::end_with_directory_separator($folder);
228
+		$wp_filesystem = EEH_File::_get_wp_filesystem($folder);
229
+		if (! $wp_filesystem->is_dir(EEH_File::convert_local_filepath_to_remote_filepath($folder))) {
230
+			// ok so it doesn't exist. Does its parent? Can we write to it?
231
+			if (! EEH_File::ensure_folder_exists_and_is_writable($parent_folder)) {
232
+				return false;
233
+			}
234
+			if (! EEH_File::verify_is_writable($parent_folder, 'folder')) {
235
+				return false;
236
+			} else {
237
+				if (! $wp_filesystem->mkdir(EEH_File::convert_local_filepath_to_remote_filepath($folder))) {
238
+					if (defined('WP_DEBUG') && WP_DEBUG) {
239
+						$msg = sprintf(__('"%s" could not be created.', 'event_espresso'), $folder);
240
+						$msg .= EEH_File::_permissions_error_for_unreadable_filepath($folder);
241
+						throw new EE_Error($msg);
242
+					}
243
+					return false;
244
+				}
245
+				EEH_File::add_index_file($folder);
246
+			}
247
+		} elseif (! EEH_File::verify_is_writable($folder, 'folder')) {
248
+			return false;
249
+		}
250
+		return true;
251
+	}
252
+
253
+
254
+
255
+	/**
256
+	 * verify_is_writable - checks if a file or folder is writable
257
+	 * @param string $full_path      - full server path to file or folder
258
+	 * @param string $file_or_folder - whether checking a file or folder
259
+	 * @throws EE_Error if filesystem credentials are required
260
+	 * @return bool
261
+	 */
262
+	public static function verify_is_writable($full_path = '', $file_or_folder = 'folder')
263
+	{
264
+		// load WP_Filesystem and set file permissions
265
+		$wp_filesystem = EEH_File::_get_wp_filesystem($full_path);
266
+		$full_path = EEH_File::standardise_directory_separators($full_path);
267
+		if (! $wp_filesystem->is_writable(EEH_File::convert_local_filepath_to_remote_filepath($full_path))) {
268
+			if (defined('WP_DEBUG') && WP_DEBUG) {
269
+				$msg = sprintf(__('The "%1$s" %2$s is not writable.', 'event_espresso'), $full_path, $file_or_folder);
270
+				$msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_path);
271
+				throw new EE_Error($msg);
272
+			}
273
+			return false;
274
+		}
275
+		return true;
276
+	}
277
+
278
+
279
+
280
+	/**
281
+	 * ensure_file_exists_and_is_writable
282
+	 * ensures that a file exists and is writable, will attempt to create file if it does not exist.
283
+	 * Also ensures all the parent folders exist, and if not tries to create them.
284
+	 * @param string $full_file_path
285
+	 * @throws EE_Error if filesystem credentials are required
286
+	 * @return bool
287
+	 */
288
+	public static function ensure_file_exists_and_is_writable($full_file_path = '')
289
+	{
290
+		// load WP_Filesystem and set file permissions
291
+		$wp_filesystem = EEH_File::_get_wp_filesystem($full_file_path);
292
+		$full_file_path = EEH_File::standardise_directory_separators($full_file_path);
293
+		$parent_folder = EEH_File::get_parent_folder($full_file_path);
294
+		if (! EEH_File::exists($full_file_path)) {
295
+			if (! EEH_File::ensure_folder_exists_and_is_writable($parent_folder)) {
296
+				return false;
297
+			}
298
+			if (! $wp_filesystem->touch(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path))) {
299
+				if (defined('WP_DEBUG') && WP_DEBUG) {
300
+					$msg = sprintf(__('The "%s" file could not be created.', 'event_espresso'), $full_file_path);
301
+					$msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_file_path);
302
+					throw new EE_Error($msg);
303
+				}
304
+				return false;
305
+			}
306
+		}
307
+		if (! EEH_File::verify_is_writable($full_file_path, 'file')) {
308
+			return false;
309
+		}
310
+		return true;
311
+	}
312
+
313
+	/**
314
+	 * Gets the parent folder. If provided with file, gets the folder that contains it.
315
+	 * If provided a folder, gets its parent folder.
316
+	 * @param string $file_or_folder_path
317
+	 * @return string parent folder, ENDING with a directory separator
318
+	 */
319
+	public static function get_parent_folder($file_or_folder_path)
320
+	{
321
+		// find the last DS, ignoring a DS on the very end
322
+		// eg if given "/var/something/somewhere/", we want to get "somewhere"'s
323
+		// parent folder, "/var/something/"
324
+		$ds = strlen($file_or_folder_path) > 1
325
+			? strrpos($file_or_folder_path, DS, -2)
326
+			: strlen($file_or_folder_path);
327
+		return substr($file_or_folder_path, 0, $ds + 1);
328
+	}
329
+
330
+	// public static function ensure_folder_exists_recursively( $folder ) {
331
+	//
332
+	// }
333
+
334
+
335
+
336
+	/**
337
+	 * get_file_contents
338
+	 * @param string $full_file_path
339
+	 * @throws EE_Error if filesystem credentials are required
340
+	 * @return string
341
+	 */
342
+	public static function get_file_contents($full_file_path = '')
343
+	{
344
+		$full_file_path = EEH_File::standardise_directory_separators($full_file_path);
345
+		if (EEH_File::verify_filepath_and_permissions($full_file_path, EEH_File::get_filename_from_filepath($full_file_path), EEH_File::get_file_extension($full_file_path))) {
346
+			// load WP_Filesystem and set file permissions
347
+			$wp_filesystem = EEH_File::_get_wp_filesystem($full_file_path);
348
+			return $wp_filesystem->get_contents(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path));
349
+		}
350
+		return '';
351
+	}
352
+
353
+
354
+
355
+	/**
356
+	 * write_file
357
+	 * @param string $full_file_path
358
+	 * @param string $file_contents - the content to be written to the file
359
+	 * @param string $file_type
360
+	 * @throws EE_Error if filesystem credentials are required
361
+	 * @return bool
362
+	 */
363
+	public static function write_to_file($full_file_path = '', $file_contents = '', $file_type = '')
364
+	{
365
+		$full_file_path = EEH_File::standardise_directory_separators($full_file_path);
366
+		$file_type = ! empty($file_type) ? rtrim($file_type, ' ') . ' ' : '';
367
+		$folder = EEH_File::remove_filename_from_filepath($full_file_path);
368
+		if (! EEH_File::verify_is_writable($folder, 'folder')) {
369
+			if (defined('WP_DEBUG') && WP_DEBUG) {
370
+				$msg = sprintf(__('The %1$sfile located at "%2$s" is not writable.', 'event_espresso'), $file_type, $full_file_path);
371
+				$msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_file_path);
372
+				throw new EE_Error($msg);
373
+			}
374
+			return false;
375
+		}
376
+		// load WP_Filesystem and set file permissions
377
+		$wp_filesystem = EEH_File::_get_wp_filesystem($full_file_path);
378
+		// write the file
379
+		if (! $wp_filesystem->put_contents(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path), $file_contents)) {
380
+			if (defined('WP_DEBUG') && WP_DEBUG) {
381
+				$msg = sprintf(__('The %1$sfile located at "%2$s" could not be written to.', 'event_espresso'), $file_type, $full_file_path);
382
+				$msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_file_path, 'f');
383
+				throw new EE_Error($msg);
384
+			}
385
+			return false;
386
+		}
387
+		return true;
388
+	}
389
+
390
+	/**
391
+	 * Wrapper for WP_Filesystem_Base::delete
392
+	 *
393
+	 * @param string $filepath
394
+	 * @param boolean $recursive
395
+	 * @param boolean|string $type 'd' for directory, 'f' for file
396
+	 * @throws EE_Error if filesystem credentials are required
397
+	 * @return boolean
398
+	 */
399
+	public static function delete($filepath, $recursive = false, $type = false)
400
+	{
401
+		$wp_filesystem = EEH_File::_get_wp_filesystem();
402
+		return $wp_filesystem->delete($filepath, $recursive, $type) ? true : false;
403
+	}
404
+
405
+
406
+
407
+	/**
408
+	 * exists
409
+	 * checks if a file exists using the WP filesystem
410
+	 * @param string $full_file_path
411
+	 * @throws EE_Error if filesystem credentials are required
412
+	 * @return bool
413
+	 */
414
+	public static function exists($full_file_path = '')
415
+	{
416
+		$wp_filesystem = EEH_File::_get_wp_filesystem($full_file_path);
417
+		return $wp_filesystem->exists(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path)) ? true : false;
418
+	}
419
+
420
+
421
+
422
+	/**
423
+	 * is_readable
424
+	 * checks if a file is_readable using the WP filesystem
425
+	 *
426
+	 * @param string $full_file_path
427
+	 * @throws EE_Error if filesystem credentials are required
428
+	 * @return bool
429
+	 */
430
+	public static function is_readable($full_file_path = '')
431
+	{
432
+		$wp_filesystem = EEH_File::_get_wp_filesystem($full_file_path);
433
+		if ($wp_filesystem->is_readable(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path))) {
434
+			return true;
435
+		} else {
436
+			return false;
437
+		}
438
+	}
439
+
440
+
441
+
442
+	/**
443
+	 * remove_filename_from_filepath
444
+	 * given a full path to a file including the filename itself, this removes  the filename and returns the path, up to, but NOT including the filename OR slash
445
+	 *
446
+	 * @param string $full_file_path
447
+	 * @return string
448
+	 */
449
+	public static function remove_filename_from_filepath($full_file_path = '')
450
+	{
451
+		return pathinfo($full_file_path, PATHINFO_DIRNAME);
452
+	}
453
+
454
+
455
+	/**
456
+	 * get_filename_from_filepath. Arguably the same as basename()
457
+	 *
458
+	 * @param string $full_file_path
459
+	 * @return string
460
+	 */
461
+	public static function get_filename_from_filepath($full_file_path = '')
462
+	{
463
+		return pathinfo($full_file_path, PATHINFO_BASENAME);
464
+	}
465
+
466
+
467
+	/**
468
+	 * get_file_extension
469
+	 *
470
+	 * @param string $full_file_path
471
+	 * @return string
472
+	 */
473
+	public static function get_file_extension($full_file_path = '')
474
+	{
475
+		return pathinfo($full_file_path, PATHINFO_EXTENSION);
476
+	}
477
+
478
+
479
+
480
+	/**
481
+	 * add_htaccess_deny_from_all so the webserver cannot access this folder
482
+	 * @param string $folder
483
+	 * @throws EE_Error if filesystem credentials are required
484
+	 * @return bool
485
+	 */
486
+	public static function add_htaccess_deny_from_all($folder = '')
487
+	{
488
+		$folder = EEH_File::standardise_and_end_with_directory_separator($folder);
489
+		if (! EEH_File::exists($folder . '.htaccess')) {
490
+			if (! EEH_File::write_to_file($folder . '.htaccess', 'deny from all', '.htaccess')) {
491
+				return false;
492
+			}
493
+		}
494
+
495
+		return true;
496
+	}
497
+
498
+	/**
499
+	 * Adds an index file to this folder, so folks can't list all the file's contents
500
+	 * @param string $folder
501
+	 * @throws EE_Error if filesystem credentials are required
502
+	 * @return boolean
503
+	 */
504
+	public static function add_index_file($folder)
505
+	{
506
+		$folder = EEH_File::standardise_and_end_with_directory_separator($folder);
507
+		if (! EEH_File::exists($folder . 'index.php')) {
508
+			if (! EEH_File::write_to_file($folder . 'index.php', 'You are not permitted to read from this folder', '.php')) {
509
+				return false;
510
+			}
511
+		}
512
+		return true;
513
+	}
514
+
515
+
516
+
517
+	/**
518
+	 * Given that the file in $file_path has the normal name, (ie, CLASSNAME.whatever.php),
519
+	 * extract that classname.
520
+	 * @param string $file_path
521
+	 * @return string
522
+	 */
523
+	public static function get_classname_from_filepath_with_standard_filename($file_path)
524
+	{
525
+		// extract file from path
526
+		$filename = basename($file_path);
527
+		// now remove the first period and everything after
528
+		$pos_of_first_period = strpos($filename, '.');
529
+		return substr($filename, 0, $pos_of_first_period);
530
+	}
531
+
532
+
533
+
534
+	/**
535
+	 * standardise_directory_separators
536
+	 *  convert all directory separators in a file path to whatever is set for DS
537
+	 * @param string $file_path
538
+	 * @return string
539
+	 */
540
+	public static function standardise_directory_separators($file_path)
541
+	{
542
+		return str_replace(array( '\\', '/' ), DS, $file_path);
543
+	}
544
+
545
+
546
+
547
+	/**
548
+	 * end_with_directory_separator
549
+	 *  ensures that file path ends with DS
550
+	 * @param string $file_path
551
+	 * @return string
552
+	 */
553
+	public static function end_with_directory_separator($file_path)
554
+	{
555
+		return rtrim($file_path, '/\\') . DS;
556
+	}
557
+
558
+
559
+
560
+	/**
561
+	 * shorthand for both EEH_FIle::end_with_directory_separator AND EEH_File::standardise_directory_separators
562
+	 * @param $file_path
563
+	 * @return string
564
+	 */
565
+	public static function standardise_and_end_with_directory_separator($file_path)
566
+	{
567
+		return self::end_with_directory_separator(self::standardise_directory_separators($file_path));
568
+	}
569
+
570
+
571
+
572
+	/**
573
+	 * takes the folder name (with or without trailing slash) and finds the files it in,
574
+	 * and what the class's name inside of each should be.
575
+	 * @param array $folder_paths
576
+	 * @param boolean $index_numerically if TRUE, the returned array will be indexed numerically;
577
+	 *      if FALSE (Default), returned array will be indexed by the filenames minus extensions.
578
+	 *      Set it TRUE if you know there are files in the directory with the same name but different extensions
579
+	 * @throws EE_Error if filesystem credentials are required
580
+	 * @return array if $index_numerically == TRUE keys are numeric ,
581
+	 *      if $index_numerically == FALSE (Default) keys are what the class names SHOULD be;
582
+	 *       and values are their filepaths
583
+	 */
584
+	public static function get_contents_of_folders($folder_paths = array(), $index_numerically = false)
585
+	{
586
+		$class_to_folder_path = array();
587
+		foreach ($folder_paths as $folder_path) {
588
+			$folder_path = self::standardise_and_end_with_directory_separator($folder_path);
589
+			// load WP_Filesystem and set file permissions
590
+			$files_in_folder = glob($folder_path . '*');
591
+			$class_to_folder_path = array();
592
+			if ($files_in_folder) {
593
+				foreach ($files_in_folder as $file_path) {
594
+					// only add files, not folders
595
+					if (! is_dir($file_path)) {
596
+						if ($index_numerically) {
597
+							$class_to_folder_path[] = $file_path;
598
+						} else {
599
+							$classname = self::get_classname_from_filepath_with_standard_filename($file_path);
600
+							$class_to_folder_path[ $classname ] = $file_path;
601
+						}
602
+					}
603
+				}
604
+			}
605
+		}
606
+		return $class_to_folder_path;
607
+	}
608
+
609
+
610
+
611
+	/**
612
+	 * Copies a file. Mostly a wrapper of WP_Filesystem::copy
613
+	 * @param string $source_file
614
+	 * @param string $destination_file
615
+	 * @param boolean $overwrite
616
+	 * @throws EE_Error if filesystem credentials are required
617
+	 * @return boolean success
618
+	 */
619
+	public static function copy($source_file, $destination_file, $overwrite = false)
620
+	{
621
+		$full_source_path = EEH_File::standardise_directory_separators($source_file);
622
+		if (! EEH_File::exists($full_source_path)) {
623
+			if (defined('WP_DEBUG') && WP_DEBUG) {
624
+				$msg = sprintf(__('The file located at "%2$s" is not readable or doesn\'t exist.', 'event_espresso'), $full_source_path);
625
+				$msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_source_path);
626
+				throw new EE_Error($msg);
627
+			}
628
+			return false;
629
+		}
630
+
631
+		$full_dest_path = EEH_File::standardise_directory_separators($destination_file);
632
+		$folder = EEH_File::remove_filename_from_filepath($full_dest_path);
633
+		EEH_File::ensure_folder_exists_and_is_writable($folder);
634
+		if (! EEH_File::verify_is_writable($folder, 'folder')) {
635
+			if (defined('WP_DEBUG') && WP_DEBUG) {
636
+				$msg = sprintf(__('The file located at "%2$s" is not writable.', 'event_espresso'), $full_dest_path);
637
+				$msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_dest_path);
638
+				throw new EE_Error($msg);
639
+			}
640
+			return false;
641
+		}
642
+
643
+		// load WP_Filesystem and set file permissions
644
+		$wp_filesystem = EEH_File::_get_wp_filesystem($destination_file);
645
+		// write the file
646
+		if (! $wp_filesystem->copy(
647
+			EEH_File::convert_local_filepath_to_remote_filepath($full_source_path),
648
+			EEH_File::convert_local_filepath_to_remote_filepath($full_dest_path),
649
+			$overwrite
650
+		)) {
651
+			if (defined('WP_DEBUG') && WP_DEBUG) {
652
+				$msg = sprintf(__('Attempted writing to file %1$s, but could not, probably because of permissions issues', 'event_espresso'), $full_source_path);
653
+				$msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_source_path, 'f');
654
+				throw new EE_Error($msg);
655
+			}
656
+			return false;
657
+		}
658
+		return true;
659
+	}
660
+
661
+	/**
662
+	 * Reports whether or not the filepath is in the EE uploads folder or not
663
+	 * @param string $filepath
664
+	 * @return boolean
665
+	 */
666
+	public static function is_in_uploads_folder($filepath)
667
+	{
668
+		$uploads = wp_upload_dir();
669
+		return strpos($filepath, $uploads['basedir']) === 0 ? true : false;
670
+	}
671
+
672
+	/**
673
+	 * Given a "local" filepath (what you probably thought was the only filepath),
674
+	 * converts it into a "remote" filepath (the filepath the currently-in-use
675
+	 * $wp_filesystem needs to use access the folder or file).
676
+	 * See http://wordpress.stackexchange.com/questions/124900/using-wp-filesystem-in-plugins
677
+	 * @param WP_Filesystem_Base $wp_filesystem we aren't initially sure which one
678
+	 * is in use, so you need to provide it
679
+	 * @param string $local_filepath the filepath to the folder/file locally
680
+	 * @throws EE_Error if filesystem credentials are required
681
+	 * @return string the remote filepath (eg the filepath the filesystem method, eg
682
+	 * ftp or ssh, will use to access the folder
683
+	 */
684
+	public static function convert_local_filepath_to_remote_filepath($local_filepath)
685
+	{
686
+		$wp_filesystem = EEH_File::_get_wp_filesystem($local_filepath);
687
+		return str_replace(WP_CONTENT_DIR . DS, $wp_filesystem->wp_content_dir(), $local_filepath);
688
+	}
689 689
 }
Please login to merge, or discard this patch.
Spacing   +48 added lines, -48 removed lines patch added patch discarded remove patch
@@ -44,17 +44,17 @@  discard block
 block discarded – undo
44 44
             'FHEE__EEH_File___get_wp_filesystem__allow_using_filesystem_direct',
45 45
             $filepath && EEH_File::is_in_uploads_folder($filepath),
46 46
             $filepath
47
-        ) ) {
48
-            if (! EEH_File::$_wp_filesystem_direct instanceof WP_Filesystem_Direct) {
49
-                require_once(ABSPATH . 'wp-admin/includes/class-wp-filesystem-base.php');
47
+        )) {
48
+            if ( ! EEH_File::$_wp_filesystem_direct instanceof WP_Filesystem_Direct) {
49
+                require_once(ABSPATH.'wp-admin/includes/class-wp-filesystem-base.php');
50 50
                 $method = 'direct';
51
-                $wp_filesystem_direct_file = apply_filters('filesystem_method_file', ABSPATH . 'wp-admin/includes/class-wp-filesystem-' . $method . '.php', $method);
51
+                $wp_filesystem_direct_file = apply_filters('filesystem_method_file', ABSPATH.'wp-admin/includes/class-wp-filesystem-'.$method.'.php', $method);
52 52
                 // check constants defined, just like in wp-admin/includes/file.php's WP_Filesystem()
53
-                if (! defined('FS_CHMOD_DIR')) {
54
-                    define('FS_CHMOD_DIR', ( fileperms(ABSPATH) & 0777 | 0755 ));
53
+                if ( ! defined('FS_CHMOD_DIR')) {
54
+                    define('FS_CHMOD_DIR', (fileperms(ABSPATH) & 0777 | 0755));
55 55
                 }
56
-                if (! defined('FS_CHMOD_FILE')) {
57
-                    define('FS_CHMOD_FILE', ( fileperms(ABSPATH . 'index.php') & 0777 | 0644 ));
56
+                if ( ! defined('FS_CHMOD_FILE')) {
57
+                    define('FS_CHMOD_FILE', (fileperms(ABSPATH.'index.php') & 0777 | 0644));
58 58
                 }
59 59
                 require_once($wp_filesystem_direct_file);
60 60
                 EEH_File::$_wp_filesystem_direct = new WP_Filesystem_Direct(array());
@@ -63,7 +63,7 @@  discard block
 block discarded – undo
63 63
         }
64 64
         global $wp_filesystem;
65 65
         // no filesystem setup ???
66
-        if (! $wp_filesystem instanceof WP_Filesystem_Base) {
66
+        if ( ! $wp_filesystem instanceof WP_Filesystem_Base) {
67 67
             // if some eager beaver's just trying to get in there too early...
68 68
             // let them do it, because we are one of those eager beavers! :P
69 69
             /**
@@ -79,14 +79,14 @@  discard block
 block discarded – undo
79 79
             if (false && ! did_action('wp_loaded')) {
80 80
                 $msg = __('An attempt to access and/or write to a file on the server could not be completed due to a lack of sufficient credentials.', 'event_espresso');
81 81
                 if (WP_DEBUG) {
82
-                    $msg .= '<br />' .  __('The WP Filesystem can not be accessed until after the "wp_loaded" hook has run, so it\'s best not to attempt access until the "admin_init" hookpoint.', 'event_espresso');
82
+                    $msg .= '<br />'.__('The WP Filesystem can not be accessed until after the "wp_loaded" hook has run, so it\'s best not to attempt access until the "admin_init" hookpoint.', 'event_espresso');
83 83
                 }
84 84
                 throw new EE_Error($msg);
85 85
             } else {
86 86
                 // should be loaded if we are past the wp_loaded hook...
87
-                if (! function_exists('WP_Filesystem')) {
88
-                    require_once(ABSPATH . 'wp-admin/includes/file.php');
89
-                    require_once(ABSPATH . 'wp-admin/includes/template.php');
87
+                if ( ! function_exists('WP_Filesystem')) {
88
+                    require_once(ABSPATH.'wp-admin/includes/file.php');
89
+                    require_once(ABSPATH.'wp-admin/includes/template.php');
90 90
                 }
91 91
                 // turn on output buffering so that we can capture the credentials form
92 92
                 ob_start();
@@ -94,13 +94,13 @@  discard block
 block discarded – undo
94 94
                 // store credentials form for the time being
95 95
                 EEH_File::$_credentials_form = ob_get_clean();
96 96
                 // basically check for direct or previously configured access
97
-                if (! WP_Filesystem($credentials)) {
97
+                if ( ! WP_Filesystem($credentials)) {
98 98
                     // if credentials do NOT exist
99 99
                     if ($credentials === false) {
100
-                        add_action('admin_notices', array( 'EEH_File', 'display_request_filesystem_credentials_form' ), 999);
100
+                        add_action('admin_notices', array('EEH_File', 'display_request_filesystem_credentials_form'), 999);
101 101
                         throw new EE_Error(__('An attempt to access and/or write to a file on the server could not be completed due to a lack of sufficient credentials.', 'event_espresso'));
102 102
                     } elseif (is_wp_error($wp_filesystem->errors) && $wp_filesystem->errors->get_error_code()) {
103
-                        add_action('admin_notices', array( 'EEH_File', 'display_request_filesystem_credentials_form' ), 999);
103
+                        add_action('admin_notices', array('EEH_File', 'display_request_filesystem_credentials_form'), 999);
104 104
                         throw new EE_Error(
105 105
                             sprintf(
106 106
                                 __('WP Filesystem Error: $1%s', 'event_espresso'),
@@ -119,8 +119,8 @@  discard block
 block discarded – undo
119 119
      */
120 120
     public static function display_request_filesystem_credentials_form()
121 121
     {
122
-        if (! empty(EEH_File::$_credentials_form)) {
123
-            echo '<div class="updated espresso-notices-attention"><p>' . EEH_File::$_credentials_form . '</p></div>';
122
+        if ( ! empty(EEH_File::$_credentials_form)) {
123
+            echo '<div class="updated espresso-notices-attention"><p>'.EEH_File::$_credentials_form.'</p></div>';
124 124
         }
125 125
     }
126 126
 
@@ -143,8 +143,8 @@  discard block
 block discarded – undo
143 143
         // load WP_Filesystem and set file permissions
144 144
         $wp_filesystem = EEH_File::_get_wp_filesystem($full_file_path);
145 145
         $full_file_path = EEH_File::standardise_directory_separators($full_file_path);
146
-        if (! $wp_filesystem->is_readable(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path))) {
147
-            $file_name = ! empty($type_of_file) ? $file_name . ' ' . $type_of_file : $file_name;
146
+        if ( ! $wp_filesystem->is_readable(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path))) {
147
+            $file_name = ! empty($type_of_file) ? $file_name.' '.$type_of_file : $file_name;
148 148
             $file_name .= ! empty($file_ext) ? ' file' : ' folder';
149 149
             $msg = sprintf(
150 150
                 __('The requested %1$s could not be found or is not readable, possibly due to an incorrect filepath, or incorrect file permissions.%2$s', 'event_espresso'),
@@ -161,7 +161,7 @@  discard block
 block discarded – undo
161 161
                 );
162 162
             }
163 163
             if (defined('WP_DEBUG') && WP_DEBUG) {
164
-                throw new EE_Error($msg . '||' . $msg);
164
+                throw new EE_Error($msg.'||'.$msg);
165 165
             }
166 166
             return false;
167 167
         }
@@ -187,7 +187,7 @@  discard block
 block discarded – undo
187 187
         $perms = $wp_filesystem->getchmod(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path));
188 188
         if ($perms) {
189 189
             // file permissions exist, but way be set incorrectly
190
-            $type_of_file = ! empty($type_of_file) ? $type_of_file . ' ' : '';
190
+            $type_of_file = ! empty($type_of_file) ? $type_of_file.' ' : '';
191 191
             $type_of_file .= ! empty($type_of_file) ? 'file' : 'folder';
192 192
             return sprintf(
193 193
                 __('File permissions for the requested %1$s are currently set at "%2$s". The recommended permissions are 644 for files and 755 for folders.', 'event_espresso'),
@@ -226,15 +226,15 @@  discard block
 block discarded – undo
226 226
         // add DS to folder
227 227
         $folder = EEH_File::end_with_directory_separator($folder);
228 228
         $wp_filesystem = EEH_File::_get_wp_filesystem($folder);
229
-        if (! $wp_filesystem->is_dir(EEH_File::convert_local_filepath_to_remote_filepath($folder))) {
229
+        if ( ! $wp_filesystem->is_dir(EEH_File::convert_local_filepath_to_remote_filepath($folder))) {
230 230
             // ok so it doesn't exist. Does its parent? Can we write to it?
231
-            if (! EEH_File::ensure_folder_exists_and_is_writable($parent_folder)) {
231
+            if ( ! EEH_File::ensure_folder_exists_and_is_writable($parent_folder)) {
232 232
                 return false;
233 233
             }
234
-            if (! EEH_File::verify_is_writable($parent_folder, 'folder')) {
234
+            if ( ! EEH_File::verify_is_writable($parent_folder, 'folder')) {
235 235
                 return false;
236 236
             } else {
237
-                if (! $wp_filesystem->mkdir(EEH_File::convert_local_filepath_to_remote_filepath($folder))) {
237
+                if ( ! $wp_filesystem->mkdir(EEH_File::convert_local_filepath_to_remote_filepath($folder))) {
238 238
                     if (defined('WP_DEBUG') && WP_DEBUG) {
239 239
                         $msg = sprintf(__('"%s" could not be created.', 'event_espresso'), $folder);
240 240
                         $msg .= EEH_File::_permissions_error_for_unreadable_filepath($folder);
@@ -244,7 +244,7 @@  discard block
 block discarded – undo
244 244
                 }
245 245
                 EEH_File::add_index_file($folder);
246 246
             }
247
-        } elseif (! EEH_File::verify_is_writable($folder, 'folder')) {
247
+        } elseif ( ! EEH_File::verify_is_writable($folder, 'folder')) {
248 248
             return false;
249 249
         }
250 250
         return true;
@@ -264,7 +264,7 @@  discard block
 block discarded – undo
264 264
         // load WP_Filesystem and set file permissions
265 265
         $wp_filesystem = EEH_File::_get_wp_filesystem($full_path);
266 266
         $full_path = EEH_File::standardise_directory_separators($full_path);
267
-        if (! $wp_filesystem->is_writable(EEH_File::convert_local_filepath_to_remote_filepath($full_path))) {
267
+        if ( ! $wp_filesystem->is_writable(EEH_File::convert_local_filepath_to_remote_filepath($full_path))) {
268 268
             if (defined('WP_DEBUG') && WP_DEBUG) {
269 269
                 $msg = sprintf(__('The "%1$s" %2$s is not writable.', 'event_espresso'), $full_path, $file_or_folder);
270 270
                 $msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_path);
@@ -291,11 +291,11 @@  discard block
 block discarded – undo
291 291
         $wp_filesystem = EEH_File::_get_wp_filesystem($full_file_path);
292 292
         $full_file_path = EEH_File::standardise_directory_separators($full_file_path);
293 293
         $parent_folder = EEH_File::get_parent_folder($full_file_path);
294
-        if (! EEH_File::exists($full_file_path)) {
295
-            if (! EEH_File::ensure_folder_exists_and_is_writable($parent_folder)) {
294
+        if ( ! EEH_File::exists($full_file_path)) {
295
+            if ( ! EEH_File::ensure_folder_exists_and_is_writable($parent_folder)) {
296 296
                 return false;
297 297
             }
298
-            if (! $wp_filesystem->touch(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path))) {
298
+            if ( ! $wp_filesystem->touch(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path))) {
299 299
                 if (defined('WP_DEBUG') && WP_DEBUG) {
300 300
                     $msg = sprintf(__('The "%s" file could not be created.', 'event_espresso'), $full_file_path);
301 301
                     $msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_file_path);
@@ -304,7 +304,7 @@  discard block
 block discarded – undo
304 304
                 return false;
305 305
             }
306 306
         }
307
-        if (! EEH_File::verify_is_writable($full_file_path, 'file')) {
307
+        if ( ! EEH_File::verify_is_writable($full_file_path, 'file')) {
308 308
             return false;
309 309
         }
310 310
         return true;
@@ -363,9 +363,9 @@  discard block
 block discarded – undo
363 363
     public static function write_to_file($full_file_path = '', $file_contents = '', $file_type = '')
364 364
     {
365 365
         $full_file_path = EEH_File::standardise_directory_separators($full_file_path);
366
-        $file_type = ! empty($file_type) ? rtrim($file_type, ' ') . ' ' : '';
366
+        $file_type = ! empty($file_type) ? rtrim($file_type, ' ').' ' : '';
367 367
         $folder = EEH_File::remove_filename_from_filepath($full_file_path);
368
-        if (! EEH_File::verify_is_writable($folder, 'folder')) {
368
+        if ( ! EEH_File::verify_is_writable($folder, 'folder')) {
369 369
             if (defined('WP_DEBUG') && WP_DEBUG) {
370 370
                 $msg = sprintf(__('The %1$sfile located at "%2$s" is not writable.', 'event_espresso'), $file_type, $full_file_path);
371 371
                 $msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_file_path);
@@ -376,7 +376,7 @@  discard block
 block discarded – undo
376 376
         // load WP_Filesystem and set file permissions
377 377
         $wp_filesystem = EEH_File::_get_wp_filesystem($full_file_path);
378 378
         // write the file
379
-        if (! $wp_filesystem->put_contents(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path), $file_contents)) {
379
+        if ( ! $wp_filesystem->put_contents(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path), $file_contents)) {
380 380
             if (defined('WP_DEBUG') && WP_DEBUG) {
381 381
                 $msg = sprintf(__('The %1$sfile located at "%2$s" could not be written to.', 'event_espresso'), $file_type, $full_file_path);
382 382
                 $msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_file_path, 'f');
@@ -486,8 +486,8 @@  discard block
 block discarded – undo
486 486
     public static function add_htaccess_deny_from_all($folder = '')
487 487
     {
488 488
         $folder = EEH_File::standardise_and_end_with_directory_separator($folder);
489
-        if (! EEH_File::exists($folder . '.htaccess')) {
490
-            if (! EEH_File::write_to_file($folder . '.htaccess', 'deny from all', '.htaccess')) {
489
+        if ( ! EEH_File::exists($folder.'.htaccess')) {
490
+            if ( ! EEH_File::write_to_file($folder.'.htaccess', 'deny from all', '.htaccess')) {
491 491
                 return false;
492 492
             }
493 493
         }
@@ -504,8 +504,8 @@  discard block
 block discarded – undo
504 504
     public static function add_index_file($folder)
505 505
     {
506 506
         $folder = EEH_File::standardise_and_end_with_directory_separator($folder);
507
-        if (! EEH_File::exists($folder . 'index.php')) {
508
-            if (! EEH_File::write_to_file($folder . 'index.php', 'You are not permitted to read from this folder', '.php')) {
507
+        if ( ! EEH_File::exists($folder.'index.php')) {
508
+            if ( ! EEH_File::write_to_file($folder.'index.php', 'You are not permitted to read from this folder', '.php')) {
509 509
                 return false;
510 510
             }
511 511
         }
@@ -539,7 +539,7 @@  discard block
 block discarded – undo
539 539
      */
540 540
     public static function standardise_directory_separators($file_path)
541 541
     {
542
-        return str_replace(array( '\\', '/' ), DS, $file_path);
542
+        return str_replace(array('\\', '/'), DS, $file_path);
543 543
     }
544 544
 
545 545
 
@@ -552,7 +552,7 @@  discard block
 block discarded – undo
552 552
      */
553 553
     public static function end_with_directory_separator($file_path)
554 554
     {
555
-        return rtrim($file_path, '/\\') . DS;
555
+        return rtrim($file_path, '/\\').DS;
556 556
     }
557 557
 
558 558
 
@@ -587,17 +587,17 @@  discard block
 block discarded – undo
587 587
         foreach ($folder_paths as $folder_path) {
588 588
             $folder_path = self::standardise_and_end_with_directory_separator($folder_path);
589 589
             // load WP_Filesystem and set file permissions
590
-            $files_in_folder = glob($folder_path . '*');
590
+            $files_in_folder = glob($folder_path.'*');
591 591
             $class_to_folder_path = array();
592 592
             if ($files_in_folder) {
593 593
                 foreach ($files_in_folder as $file_path) {
594 594
                     // only add files, not folders
595
-                    if (! is_dir($file_path)) {
595
+                    if ( ! is_dir($file_path)) {
596 596
                         if ($index_numerically) {
597 597
                             $class_to_folder_path[] = $file_path;
598 598
                         } else {
599 599
                             $classname = self::get_classname_from_filepath_with_standard_filename($file_path);
600
-                            $class_to_folder_path[ $classname ] = $file_path;
600
+                            $class_to_folder_path[$classname] = $file_path;
601 601
                         }
602 602
                     }
603 603
                 }
@@ -619,7 +619,7 @@  discard block
 block discarded – undo
619 619
     public static function copy($source_file, $destination_file, $overwrite = false)
620 620
     {
621 621
         $full_source_path = EEH_File::standardise_directory_separators($source_file);
622
-        if (! EEH_File::exists($full_source_path)) {
622
+        if ( ! EEH_File::exists($full_source_path)) {
623 623
             if (defined('WP_DEBUG') && WP_DEBUG) {
624 624
                 $msg = sprintf(__('The file located at "%2$s" is not readable or doesn\'t exist.', 'event_espresso'), $full_source_path);
625 625
                 $msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_source_path);
@@ -631,7 +631,7 @@  discard block
 block discarded – undo
631 631
         $full_dest_path = EEH_File::standardise_directory_separators($destination_file);
632 632
         $folder = EEH_File::remove_filename_from_filepath($full_dest_path);
633 633
         EEH_File::ensure_folder_exists_and_is_writable($folder);
634
-        if (! EEH_File::verify_is_writable($folder, 'folder')) {
634
+        if ( ! EEH_File::verify_is_writable($folder, 'folder')) {
635 635
             if (defined('WP_DEBUG') && WP_DEBUG) {
636 636
                 $msg = sprintf(__('The file located at "%2$s" is not writable.', 'event_espresso'), $full_dest_path);
637 637
                 $msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_dest_path);
@@ -643,7 +643,7 @@  discard block
 block discarded – undo
643 643
         // load WP_Filesystem and set file permissions
644 644
         $wp_filesystem = EEH_File::_get_wp_filesystem($destination_file);
645 645
         // write the file
646
-        if (! $wp_filesystem->copy(
646
+        if ( ! $wp_filesystem->copy(
647 647
             EEH_File::convert_local_filepath_to_remote_filepath($full_source_path),
648 648
             EEH_File::convert_local_filepath_to_remote_filepath($full_dest_path),
649 649
             $overwrite
@@ -684,6 +684,6 @@  discard block
 block discarded – undo
684 684
     public static function convert_local_filepath_to_remote_filepath($local_filepath)
685 685
     {
686 686
         $wp_filesystem = EEH_File::_get_wp_filesystem($local_filepath);
687
-        return str_replace(WP_CONTENT_DIR . DS, $wp_filesystem->wp_content_dir(), $local_filepath);
687
+        return str_replace(WP_CONTENT_DIR.DS, $wp_filesystem->wp_content_dir(), $local_filepath);
688 688
     }
689 689
 }
Please login to merge, or discard this patch.
core/helpers/EEH_Form_Fields.helper.php 3 patches
Doc Comments   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -777,7 +777,7 @@  discard block
 block discarded – undo
777 777
      *
778 778
      * @param mixed $opt_group
779 779
      * @param mixed $QSOs
780
-     * @param mixed $answer
780
+     * @param string $answer
781 781
      * @param boolean $use_html_entities
782 782
      * @return string
783 783
      */
@@ -1134,7 +1134,7 @@  discard block
 block discarded – undo
1134 1134
     /**
1135 1135
      *  prep_required
1136 1136
      * @param string|array  $required
1137
-     * @return array
1137
+     * @return string
1138 1138
      */
1139 1139
     public static function prep_required($required = array())
1140 1140
     {
@@ -1187,8 +1187,8 @@  discard block
 block discarded – undo
1187 1187
 
1188 1188
     /**
1189 1189
      *  _load_system_dropdowns
1190
-     * @param array     $QFI
1191
-     * @return array
1190
+     * @param EE_Question_Form_Input     $QFI
1191
+     * @return EE_Question_Form_Input
1192 1192
      */
1193 1193
     private static function _load_system_dropdowns($QFI)
1194 1194
     {
@@ -1491,7 +1491,7 @@  discard block
 block discarded – undo
1491 1491
      * @param    string   $nonce_action     - if using nonces
1492 1492
      * @param    bool|string $input_only       - whether to print form header and footer. TRUE returns the input without the form
1493 1493
      * @param    string   $extra_attributes - any extra attributes that need to be attached to the form input
1494
-     * @return    void
1494
+     * @return    string
1495 1495
      */
1496 1496
     public static function submit_button($url = '', $ID = '', $class = '', $text = '', $nonce_action = '', $input_only = false, $extra_attributes = '')
1497 1497
     {
Please login to merge, or discard this patch.
Indentation   +1461 added lines, -1461 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
-    {
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 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) {
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,447 +1068,447 @@  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 ? EEM_State::instance()->get_all_states() : EEM_State::instance()->get_all_states_of_active_countries();
1248
-        if ($states && count($states) != count($QST->options())) {
1249
-            $QST->set('QST_type', 'DROPDOWN');
1250
-            // if multiple countries, we'll create option groups within the dropdown
1251
-            foreach ($states as $state) {
1252
-                if ($state instanceof EE_State) {
1253
-                    $QSO = EE_Question_Option::new_instance(array (
1254
-                        'QSO_value' => $state->ID(),
1255
-                        'QSO_desc' => $state->name(),
1256
-                        'QST_ID' => $QST->get('QST_ID'),
1257
-                        'QSO_deleted' => false
1258
-                    ));
1259
-                    // set option group
1260
-                    $QSO->set_opt_group($state->country()->name());
1261
-                    // add option to question
1262
-                    $QST->add_temp_option($QSO);
1263
-                }
1264
-            }
1265
-        }
1266
-        return $QST;
1267
-    }
1268
-
1269
-
1270
-
1271
-    /**
1272
-     *    generate_country_dropdown
1273
-     * @param      $QST
1274
-     * @param bool $get_all
1275
-     * @internal param array $question
1276
-     * @return array
1277
-     */
1278
-    public static function generate_country_dropdown($QST, $get_all = false)
1279
-    {
1280
-        $countries = $get_all ? EEM_Country::instance()->get_all_countries() : EEM_Country::instance()->get_all_active_countries();
1281
-        if ($countries && count($countries) != count($QST->options())) {
1282
-            $QST->set('QST_type', 'DROPDOWN');
1283
-            // now add countries
1284
-            foreach ($countries as $country) {
1285
-                if ($country instanceof EE_Country) {
1286
-                    $QSO = EE_Question_Option::new_instance(array (
1287
-                        'QSO_value' => $country->ID(),
1288
-                        'QSO_desc' => $country->name(),
1289
-                        'QST_ID' => $QST->get('QST_ID'),
1290
-                        'QSO_deleted' => false
1291
-                    ));
1292
-                    $QST->add_temp_option($QSO);
1293
-                }
1294
-            }
1295
-        }
1296
-        return $QST;
1297
-    }
1298
-
1299
-
1300
-
1301
-
1302
-
1303
-    /**
1304
-     *  generates options for a month dropdown selector with numbers from 01 to 12
1305
-     *  @return array()
1306
-     */
1307
-    public static function two_digit_months_dropdown_options()
1308
-    {
1309
-        $options = array();
1310
-        for ($x = 1; $x <= 12; $x++) {
1311
-            $mm = str_pad($x, 2, '0', STR_PAD_LEFT);
1312
-            $options[ (string) $mm ] = (string) $mm;
1313
-        }
1314
-        return EEH_Form_Fields::prep_answer_options($options);
1315
-    }
1316
-
1317
-
1318
-
1319
-
1320
-
1321
-    /**
1322
-     *  generates a year dropdown selector with numbers for the next ten years
1323
-     *  @return object
1324
-     */
1325
-    public static function next_decade_two_digit_year_dropdown_options()
1326
-    {
1327
-        $options = array();
1328
-        $current_year = date('y');
1329
-        $next_decade = $current_year + 10;
1330
-        for ($x = $current_year; $x <= $next_decade; $x++) {
1331
-            $yy = str_pad($x, 2, '0', STR_PAD_LEFT);
1332
-            $options[ (string) $yy ] = (string) $yy;
1333
-        }
1334
-        return EEH_Form_Fields::prep_answer_options($options);
1335
-    }
1336
-
1337
-
1338
-
1339
-
1340
-
1341
-    /**
1342
-     * generates a month/year dropdown selector for all registrations matching the given criteria.  Typically used for list table filter.
1343
-     * @param  string  $cur_date     any currently selected date can be entered here.
1344
-     * @param  string  $status       Registration status
1345
-     * @param  integer $evt_category Event Category ID if the Event Category filter is selected
1346
-     * @return string                html
1347
-     */
1348
-    public static function generate_registration_months_dropdown($cur_date = '', $status = '', $evt_category = 0)
1349
-    {
1350
-        $_where = array();
1351
-        if (!empty($status)) {
1352
-            $_where['STS_ID'] = $status;
1353
-        }
1354
-
1355
-        if ($evt_category > 0) {
1356
-            $_where['Event.Term_Taxonomy.term_id'] = $evt_category;
1357
-        }
1358
-
1359
-        $regdtts = EEM_Registration::instance()->get_reg_months_and_years($_where);
1360
-
1361
-        // setup vals for select input helper
1362
-        $options = array(
1363
-            0 => array(
1364
-                'text' => __('Select a Month/Year', 'event_espresso'),
1365
-                'id' => ''
1366
-                )
1367
-            );
1368
-
1369
-        foreach ($regdtts as $regdtt) {
1370
-            $date = $regdtt->reg_month. ' ' . $regdtt->reg_year;
1371
-            $options[] = array(
1372
-                'text' => $date,
1373
-                'id' => $date
1374
-                );
1375
-        }
1376
-
1377
-        return self::select_input('month_range', $options, $cur_date, '', 'wide');
1378
-    }
1379
-
1380
-
1381
-
1382
-    /**
1383
-     * generates a month/year dropdown selector for all events matching the given criteria
1384
-     * Typically used for list table filter
1385
-     * @param  string $cur_date          any currently selected date can be entered here.
1386
-     * @param  string $status            "view" (i.e. all, today, month, draft)
1387
-     * @param  int    $evt_category      category event belongs to
1388
-     * @param  string $evt_active_status "upcoming", "expired", "active", or "inactive"
1389
-     * @return string                    html
1390
-     */
1391
-    public static function generate_event_months_dropdown($cur_date = '', $status = null, $evt_category = null, $evt_active_status = null)
1392
-    {
1393
-        // determine what post_status our condition will have for the query.
1394
-        // phpcs:disable PSR2.ControlStructures.SwitchDeclaration.TerminatingComment
1395
-        switch ($status) {
1396
-            case 'month':
1397
-            case 'today':
1398
-            case null:
1399
-            case 'all':
1400
-                $where['Event.status'] = array( 'NOT IN', array('trash') );
1401
-                break;
1402
-
1403
-            case 'draft':
1404
-                $where['Event.status'] = array( 'IN', array('draft', 'auto-draft') );
1405
-
1406
-            default:
1407
-                $where['Event.status'] = $status;
1408
-        }
1409
-
1410
-        // phpcs:enable
1411
-
1412
-        // categories?
1413
-
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 ? EEM_State::instance()->get_all_states() : EEM_State::instance()->get_all_states_of_active_countries();
1248
+		if ($states && count($states) != count($QST->options())) {
1249
+			$QST->set('QST_type', 'DROPDOWN');
1250
+			// if multiple countries, we'll create option groups within the dropdown
1251
+			foreach ($states as $state) {
1252
+				if ($state instanceof EE_State) {
1253
+					$QSO = EE_Question_Option::new_instance(array (
1254
+						'QSO_value' => $state->ID(),
1255
+						'QSO_desc' => $state->name(),
1256
+						'QST_ID' => $QST->get('QST_ID'),
1257
+						'QSO_deleted' => false
1258
+					));
1259
+					// set option group
1260
+					$QSO->set_opt_group($state->country()->name());
1261
+					// add option to question
1262
+					$QST->add_temp_option($QSO);
1263
+				}
1264
+			}
1265
+		}
1266
+		return $QST;
1267
+	}
1268
+
1269
+
1270
+
1271
+	/**
1272
+	 *    generate_country_dropdown
1273
+	 * @param      $QST
1274
+	 * @param bool $get_all
1275
+	 * @internal param array $question
1276
+	 * @return array
1277
+	 */
1278
+	public static function generate_country_dropdown($QST, $get_all = false)
1279
+	{
1280
+		$countries = $get_all ? EEM_Country::instance()->get_all_countries() : EEM_Country::instance()->get_all_active_countries();
1281
+		if ($countries && count($countries) != count($QST->options())) {
1282
+			$QST->set('QST_type', 'DROPDOWN');
1283
+			// now add countries
1284
+			foreach ($countries as $country) {
1285
+				if ($country instanceof EE_Country) {
1286
+					$QSO = EE_Question_Option::new_instance(array (
1287
+						'QSO_value' => $country->ID(),
1288
+						'QSO_desc' => $country->name(),
1289
+						'QST_ID' => $QST->get('QST_ID'),
1290
+						'QSO_deleted' => false
1291
+					));
1292
+					$QST->add_temp_option($QSO);
1293
+				}
1294
+			}
1295
+		}
1296
+		return $QST;
1297
+	}
1298
+
1299
+
1300
+
1301
+
1302
+
1303
+	/**
1304
+	 *  generates options for a month dropdown selector with numbers from 01 to 12
1305
+	 *  @return array()
1306
+	 */
1307
+	public static function two_digit_months_dropdown_options()
1308
+	{
1309
+		$options = array();
1310
+		for ($x = 1; $x <= 12; $x++) {
1311
+			$mm = str_pad($x, 2, '0', STR_PAD_LEFT);
1312
+			$options[ (string) $mm ] = (string) $mm;
1313
+		}
1314
+		return EEH_Form_Fields::prep_answer_options($options);
1315
+	}
1316
+
1317
+
1318
+
1319
+
1320
+
1321
+	/**
1322
+	 *  generates a year dropdown selector with numbers for the next ten years
1323
+	 *  @return object
1324
+	 */
1325
+	public static function next_decade_two_digit_year_dropdown_options()
1326
+	{
1327
+		$options = array();
1328
+		$current_year = date('y');
1329
+		$next_decade = $current_year + 10;
1330
+		for ($x = $current_year; $x <= $next_decade; $x++) {
1331
+			$yy = str_pad($x, 2, '0', STR_PAD_LEFT);
1332
+			$options[ (string) $yy ] = (string) $yy;
1333
+		}
1334
+		return EEH_Form_Fields::prep_answer_options($options);
1335
+	}
1336
+
1337
+
1338
+
1339
+
1340
+
1341
+	/**
1342
+	 * generates a month/year dropdown selector for all registrations matching the given criteria.  Typically used for list table filter.
1343
+	 * @param  string  $cur_date     any currently selected date can be entered here.
1344
+	 * @param  string  $status       Registration status
1345
+	 * @param  integer $evt_category Event Category ID if the Event Category filter is selected
1346
+	 * @return string                html
1347
+	 */
1348
+	public static function generate_registration_months_dropdown($cur_date = '', $status = '', $evt_category = 0)
1349
+	{
1350
+		$_where = array();
1351
+		if (!empty($status)) {
1352
+			$_where['STS_ID'] = $status;
1353
+		}
1354
+
1355
+		if ($evt_category > 0) {
1356
+			$_where['Event.Term_Taxonomy.term_id'] = $evt_category;
1357
+		}
1358
+
1359
+		$regdtts = EEM_Registration::instance()->get_reg_months_and_years($_where);
1360
+
1361
+		// setup vals for select input helper
1362
+		$options = array(
1363
+			0 => array(
1364
+				'text' => __('Select a Month/Year', 'event_espresso'),
1365
+				'id' => ''
1366
+				)
1367
+			);
1368
+
1369
+		foreach ($regdtts as $regdtt) {
1370
+			$date = $regdtt->reg_month. ' ' . $regdtt->reg_year;
1371
+			$options[] = array(
1372
+				'text' => $date,
1373
+				'id' => $date
1374
+				);
1375
+		}
1376
+
1377
+		return self::select_input('month_range', $options, $cur_date, '', 'wide');
1378
+	}
1379
+
1380
+
1381
+
1382
+	/**
1383
+	 * generates a month/year dropdown selector for all events matching the given criteria
1384
+	 * Typically used for list table filter
1385
+	 * @param  string $cur_date          any currently selected date can be entered here.
1386
+	 * @param  string $status            "view" (i.e. all, today, month, draft)
1387
+	 * @param  int    $evt_category      category event belongs to
1388
+	 * @param  string $evt_active_status "upcoming", "expired", "active", or "inactive"
1389
+	 * @return string                    html
1390
+	 */
1391
+	public static function generate_event_months_dropdown($cur_date = '', $status = null, $evt_category = null, $evt_active_status = null)
1392
+	{
1393
+		// determine what post_status our condition will have for the query.
1394
+		// phpcs:disable PSR2.ControlStructures.SwitchDeclaration.TerminatingComment
1395
+		switch ($status) {
1396
+			case 'month':
1397
+			case 'today':
1398
+			case null:
1399
+			case 'all':
1400
+				$where['Event.status'] = array( 'NOT IN', array('trash') );
1401
+				break;
1402
+
1403
+			case 'draft':
1404
+				$where['Event.status'] = array( 'IN', array('draft', 'auto-draft') );
1405
+
1406
+			default:
1407
+				$where['Event.status'] = $status;
1408
+		}
1409
+
1410
+		// phpcs:enable
1411
+
1412
+		// categories?
1413
+
1414 1414
 
1415
-        if (!empty($evt_category)) {
1416
-            $where['Event.Term_Taxonomy.taxonomy'] = 'espresso_event_categories';
1417
-            $where['Event.Term_Taxonomy.term_id'] = $evt_category;
1418
-        }
1415
+		if (!empty($evt_category)) {
1416
+			$where['Event.Term_Taxonomy.taxonomy'] = 'espresso_event_categories';
1417
+			$where['Event.Term_Taxonomy.term_id'] = $evt_category;
1418
+		}
1419 1419
 
1420 1420
 
1421 1421
 //      $where['DTT_is_primary'] = 1;
1422 1422
 
1423
-        $DTTS = EE_Registry::instance()->load_model('Datetime')->get_dtt_months_and_years($where, $evt_active_status);
1424
-
1425
-        // let's setup vals for select input helper
1426
-        $options = array(
1427
-            0 => array(
1428
-                'text' => __('Select a Month/Year', 'event_espresso'),
1429
-                'id' => ""
1430
-                )
1431
-            );
1432
-
1433
-
1434
-
1435
-        // translate month and date
1436
-        global $wp_locale;
1437
-
1438
-        foreach ($DTTS as $DTT) {
1439
-            $localized_date = $wp_locale->get_month($DTT->dtt_month_num) . ' ' . $DTT->dtt_year;
1440
-            $id = $DTT->dtt_month . ' ' . $DTT->dtt_year;
1441
-            $options[] = array(
1442
-                'text' => $localized_date,
1443
-                'id' => $id
1444
-                );
1445
-        }
1446
-
1447
-
1448
-        return self::select_input('month_range', $options, $cur_date, '', 'wide');
1449
-    }
1450
-
1451
-
1452
-
1453
-    /**
1454
-     * generates the dropdown selector for event categories
1455
-     * typically used as a filter on list tables.
1456
-     * @param  integer $current_cat currently selected category
1457
-     * @return string               html for dropdown
1458
-     */
1459
-    public static function generate_event_category_dropdown($current_cat = -1)
1460
-    {
1461
-        $categories = EEM_Term::instance()->get_all_ee_categories(true);
1462
-        $options = array(
1463
-            '0' => array(
1464
-                'text' => __('All Categories', 'event_espresso'),
1465
-                'id' => -1
1466
-                )
1467
-            );
1468
-
1469
-        // setup categories for dropdown
1470
-        foreach ($categories as $category) {
1471
-            $options[] = array(
1472
-                'text' => $category->get('name'),
1473
-                'id' => $category->ID()
1474
-                );
1475
-        }
1476
-
1477
-        return self::select_input('EVT_CAT', $options, $current_cat);
1478
-    }
1479
-
1480
-
1481
-
1482
-    /**
1483
-     *    generate a submit button with or without it's own microform
1484
-     *    this is the only way to create buttons that are compatible across all themes
1485
-     *
1486
-     * @access    public
1487
-     * @param    string   $url              - the form action
1488
-     * @param    string   $ID               - some kind of unique ID, appended with "-sbmt" for the input and "-frm" for the form
1489
-     * @param    string   $class            - css classes (separated by spaces if more than one)
1490
-     * @param    string   $text             - what appears on the button
1491
-     * @param    string   $nonce_action     - if using nonces
1492
-     * @param    bool|string $input_only       - whether to print form header and footer. TRUE returns the input without the form
1493
-     * @param    string   $extra_attributes - any extra attributes that need to be attached to the form input
1494
-     * @return    void
1495
-     */
1496
-    public static function submit_button($url = '', $ID = '', $class = '', $text = '', $nonce_action = '', $input_only = false, $extra_attributes = '')
1497
-    {
1498
-        $btn = '';
1499
-        if (empty($url) || empty($ID)) {
1500
-            return $btn;
1501
-        }
1502
-        $text = ! empty($text) ? $text : __('Submit', 'event_espresso');
1503
-        $btn .= '<input id="' . $ID . '-btn" class="' . $class . '" type="submit" value="' . $text . '" ' . $extra_attributes . '/>';
1504
-        if (! $input_only) {
1505
-            $btn_frm = '<form id="' . $ID . '-frm" method="POST" action="' . $url . '">';
1506
-            $btn_frm .= ! empty($nonce_action) ? wp_nonce_field($nonce_action, $nonce_action . '_nonce', true, false) : '';
1507
-            $btn_frm .= $btn;
1508
-            $btn_frm .= '</form>';
1509
-            $btn = $btn_frm;
1510
-            unset($btn_frm);
1511
-        }
1512
-        return $btn;
1513
-    }
1423
+		$DTTS = EE_Registry::instance()->load_model('Datetime')->get_dtt_months_and_years($where, $evt_active_status);
1424
+
1425
+		// let's setup vals for select input helper
1426
+		$options = array(
1427
+			0 => array(
1428
+				'text' => __('Select a Month/Year', 'event_espresso'),
1429
+				'id' => ""
1430
+				)
1431
+			);
1432
+
1433
+
1434
+
1435
+		// translate month and date
1436
+		global $wp_locale;
1437
+
1438
+		foreach ($DTTS as $DTT) {
1439
+			$localized_date = $wp_locale->get_month($DTT->dtt_month_num) . ' ' . $DTT->dtt_year;
1440
+			$id = $DTT->dtt_month . ' ' . $DTT->dtt_year;
1441
+			$options[] = array(
1442
+				'text' => $localized_date,
1443
+				'id' => $id
1444
+				);
1445
+		}
1446
+
1447
+
1448
+		return self::select_input('month_range', $options, $cur_date, '', 'wide');
1449
+	}
1450
+
1451
+
1452
+
1453
+	/**
1454
+	 * generates the dropdown selector for event categories
1455
+	 * typically used as a filter on list tables.
1456
+	 * @param  integer $current_cat currently selected category
1457
+	 * @return string               html for dropdown
1458
+	 */
1459
+	public static function generate_event_category_dropdown($current_cat = -1)
1460
+	{
1461
+		$categories = EEM_Term::instance()->get_all_ee_categories(true);
1462
+		$options = array(
1463
+			'0' => array(
1464
+				'text' => __('All Categories', 'event_espresso'),
1465
+				'id' => -1
1466
+				)
1467
+			);
1468
+
1469
+		// setup categories for dropdown
1470
+		foreach ($categories as $category) {
1471
+			$options[] = array(
1472
+				'text' => $category->get('name'),
1473
+				'id' => $category->ID()
1474
+				);
1475
+		}
1476
+
1477
+		return self::select_input('EVT_CAT', $options, $current_cat);
1478
+	}
1479
+
1480
+
1481
+
1482
+	/**
1483
+	 *    generate a submit button with or without it's own microform
1484
+	 *    this is the only way to create buttons that are compatible across all themes
1485
+	 *
1486
+	 * @access    public
1487
+	 * @param    string   $url              - the form action
1488
+	 * @param    string   $ID               - some kind of unique ID, appended with "-sbmt" for the input and "-frm" for the form
1489
+	 * @param    string   $class            - css classes (separated by spaces if more than one)
1490
+	 * @param    string   $text             - what appears on the button
1491
+	 * @param    string   $nonce_action     - if using nonces
1492
+	 * @param    bool|string $input_only       - whether to print form header and footer. TRUE returns the input without the form
1493
+	 * @param    string   $extra_attributes - any extra attributes that need to be attached to the form input
1494
+	 * @return    void
1495
+	 */
1496
+	public static function submit_button($url = '', $ID = '', $class = '', $text = '', $nonce_action = '', $input_only = false, $extra_attributes = '')
1497
+	{
1498
+		$btn = '';
1499
+		if (empty($url) || empty($ID)) {
1500
+			return $btn;
1501
+		}
1502
+		$text = ! empty($text) ? $text : __('Submit', 'event_espresso');
1503
+		$btn .= '<input id="' . $ID . '-btn" class="' . $class . '" type="submit" value="' . $text . '" ' . $extra_attributes . '/>';
1504
+		if (! $input_only) {
1505
+			$btn_frm = '<form id="' . $ID . '-frm" method="POST" action="' . $url . '">';
1506
+			$btn_frm .= ! empty($nonce_action) ? wp_nonce_field($nonce_action, $nonce_action . '_nonce', true, false) : '';
1507
+			$btn_frm .= $btn;
1508
+			$btn_frm .= '</form>';
1509
+			$btn = $btn_frm;
1510
+			unset($btn_frm);
1511
+		}
1512
+		return $btn;
1513
+	}
1514 1514
 }
Please login to merge, or discard this patch.
Spacing   +185 added lines, -185 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]))) {
347
-            $converted_values=array();
346
+        if ( ! empty($values) && ( ! array_key_exists(0, $values) || ! is_array($values[0]))) {
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
-            $values=$converted_values;
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;
@@ -1250,7 +1250,7 @@  discard block
 block discarded – undo
1250 1250
             // if multiple countries, we'll create option groups within the dropdown
1251 1251
             foreach ($states as $state) {
1252 1252
                 if ($state instanceof EE_State) {
1253
-                    $QSO = EE_Question_Option::new_instance(array (
1253
+                    $QSO = EE_Question_Option::new_instance(array(
1254 1254
                         'QSO_value' => $state->ID(),
1255 1255
                         'QSO_desc' => $state->name(),
1256 1256
                         'QST_ID' => $QST->get('QST_ID'),
@@ -1283,7 +1283,7 @@  discard block
 block discarded – undo
1283 1283
             // now add countries
1284 1284
             foreach ($countries as $country) {
1285 1285
                 if ($country instanceof EE_Country) {
1286
-                    $QSO = EE_Question_Option::new_instance(array (
1286
+                    $QSO = EE_Question_Option::new_instance(array(
1287 1287
                         'QSO_value' => $country->ID(),
1288 1288
                         'QSO_desc' => $country->name(),
1289 1289
                         'QST_ID' => $QST->get('QST_ID'),
@@ -1309,7 +1309,7 @@  discard block
 block discarded – undo
1309 1309
         $options = array();
1310 1310
         for ($x = 1; $x <= 12; $x++) {
1311 1311
             $mm = str_pad($x, 2, '0', STR_PAD_LEFT);
1312
-            $options[ (string) $mm ] = (string) $mm;
1312
+            $options[(string) $mm] = (string) $mm;
1313 1313
         }
1314 1314
         return EEH_Form_Fields::prep_answer_options($options);
1315 1315
     }
@@ -1329,7 +1329,7 @@  discard block
 block discarded – undo
1329 1329
         $next_decade = $current_year + 10;
1330 1330
         for ($x = $current_year; $x <= $next_decade; $x++) {
1331 1331
             $yy = str_pad($x, 2, '0', STR_PAD_LEFT);
1332
-            $options[ (string) $yy ] = (string) $yy;
1332
+            $options[(string) $yy] = (string) $yy;
1333 1333
         }
1334 1334
         return EEH_Form_Fields::prep_answer_options($options);
1335 1335
     }
@@ -1348,7 +1348,7 @@  discard block
 block discarded – undo
1348 1348
     public static function generate_registration_months_dropdown($cur_date = '', $status = '', $evt_category = 0)
1349 1349
     {
1350 1350
         $_where = array();
1351
-        if (!empty($status)) {
1351
+        if ( ! empty($status)) {
1352 1352
             $_where['STS_ID'] = $status;
1353 1353
         }
1354 1354
 
@@ -1367,7 +1367,7 @@  discard block
 block discarded – undo
1367 1367
             );
1368 1368
 
1369 1369
         foreach ($regdtts as $regdtt) {
1370
-            $date = $regdtt->reg_month. ' ' . $regdtt->reg_year;
1370
+            $date = $regdtt->reg_month.' '.$regdtt->reg_year;
1371 1371
             $options[] = array(
1372 1372
                 'text' => $date,
1373 1373
                 'id' => $date
@@ -1397,11 +1397,11 @@  discard block
 block discarded – undo
1397 1397
             case 'today':
1398 1398
             case null:
1399 1399
             case 'all':
1400
-                $where['Event.status'] = array( 'NOT IN', array('trash') );
1400
+                $where['Event.status'] = array('NOT IN', array('trash'));
1401 1401
                 break;
1402 1402
 
1403 1403
             case 'draft':
1404
-                $where['Event.status'] = array( 'IN', array('draft', 'auto-draft') );
1404
+                $where['Event.status'] = array('IN', array('draft', 'auto-draft'));
1405 1405
 
1406 1406
             default:
1407 1407
                 $where['Event.status'] = $status;
@@ -1412,7 +1412,7 @@  discard block
 block discarded – undo
1412 1412
         // categories?
1413 1413
 
1414 1414
 
1415
-        if (!empty($evt_category)) {
1415
+        if ( ! empty($evt_category)) {
1416 1416
             $where['Event.Term_Taxonomy.taxonomy'] = 'espresso_event_categories';
1417 1417
             $where['Event.Term_Taxonomy.term_id'] = $evt_category;
1418 1418
         }
@@ -1436,8 +1436,8 @@  discard block
 block discarded – undo
1436 1436
         global $wp_locale;
1437 1437
 
1438 1438
         foreach ($DTTS as $DTT) {
1439
-            $localized_date = $wp_locale->get_month($DTT->dtt_month_num) . ' ' . $DTT->dtt_year;
1440
-            $id = $DTT->dtt_month . ' ' . $DTT->dtt_year;
1439
+            $localized_date = $wp_locale->get_month($DTT->dtt_month_num).' '.$DTT->dtt_year;
1440
+            $id = $DTT->dtt_month.' '.$DTT->dtt_year;
1441 1441
             $options[] = array(
1442 1442
                 'text' => $localized_date,
1443 1443
                 'id' => $id
@@ -1500,10 +1500,10 @@  discard block
 block discarded – undo
1500 1500
             return $btn;
1501 1501
         }
1502 1502
         $text = ! empty($text) ? $text : __('Submit', 'event_espresso');
1503
-        $btn .= '<input id="' . $ID . '-btn" class="' . $class . '" type="submit" value="' . $text . '" ' . $extra_attributes . '/>';
1504
-        if (! $input_only) {
1505
-            $btn_frm = '<form id="' . $ID . '-frm" method="POST" action="' . $url . '">';
1506
-            $btn_frm .= ! empty($nonce_action) ? wp_nonce_field($nonce_action, $nonce_action . '_nonce', true, false) : '';
1503
+        $btn .= '<input id="'.$ID.'-btn" class="'.$class.'" type="submit" value="'.$text.'" '.$extra_attributes.'/>';
1504
+        if ( ! $input_only) {
1505
+            $btn_frm = '<form id="'.$ID.'-frm" method="POST" action="'.$url.'">';
1506
+            $btn_frm .= ! empty($nonce_action) ? wp_nonce_field($nonce_action, $nonce_action.'_nonce', true, false) : '';
1507 1507
             $btn_frm .= $btn;
1508 1508
             $btn_frm .= '</form>';
1509 1509
             $btn = $btn_frm;
Please login to merge, or discard this patch.
core/helpers/EEH_Formatter.helper.php 3 patches
Doc Comments   +1 added lines patch added patch discarded remove patch
@@ -73,6 +73,7 @@
 block discarded – undo
73 73
      * [ee_tep_not_null description]
74 74
      *
75 75
      * @param  string | array $value [description]
76
+     * @param string $value
76 77
      * @return bool       [description]
77 78
      */
78 79
     public static function ee_tep_not_null($value)
Please login to merge, or discard this patch.
Indentation   +92 added lines, -92 removed lines patch added patch discarded remove patch
@@ -12,108 +12,108 @@
 block discarded – undo
12 12
 {
13 13
 
14 14
 
15
-    /**
16
-     * _admin_format_content
17
-     * Text formatting function for wp_editor.
18
-     * This should fix all of the formatting issues of text output from the database.
19
-     *
20
-     * @static
21
-     * @access public
22
-     * @param  string $content content to format
23
-     * @return string          formatted content
24
-     */
25
-    public static function admin_format_content($content = '')
26
-    {
27
-        return wpautop(stripslashes_deep(html_entity_decode($content, ENT_QUOTES, "UTF-8")));
28
-    }
15
+	/**
16
+	 * _admin_format_content
17
+	 * Text formatting function for wp_editor.
18
+	 * This should fix all of the formatting issues of text output from the database.
19
+	 *
20
+	 * @static
21
+	 * @access public
22
+	 * @param  string $content content to format
23
+	 * @return string          formatted content
24
+	 */
25
+	public static function admin_format_content($content = '')
26
+	{
27
+		return wpautop(stripslashes_deep(html_entity_decode($content, ENT_QUOTES, "UTF-8")));
28
+	}
29 29
 
30 30
 
31 31
 
32
-    /**
33
-     * ee_tep_output_string
34
-     * todo: we need a description for this.
35
-     *
36
-     * @static
37
-     * @access public
38
-     * @param  string  $string    string to handle
39
-     * @param  boolean $translate //todo what is this for?
40
-     * @param  boolean $protected true then we run htmlspecialchars and return
41
-     * @return string
42
-     */
43
-    public static function ee_tep_output_string($string, $translate = false, $protected = false)
44
-    {
45
-        if ($protected === true) {
46
-            return htmlspecialchars($string);
47
-        } else {
48
-            if ($translate === false) {
49
-                return self::ee_tep_parse_input_field_data($string, array( '"' => '&quot;' ));
50
-            } else {
51
-                return self::ee_tep_parse_input_field_data($string, $translate);
52
-            }
53
-        }
54
-    }
32
+	/**
33
+	 * ee_tep_output_string
34
+	 * todo: we need a description for this.
35
+	 *
36
+	 * @static
37
+	 * @access public
38
+	 * @param  string  $string    string to handle
39
+	 * @param  boolean $translate //todo what is this for?
40
+	 * @param  boolean $protected true then we run htmlspecialchars and return
41
+	 * @return string
42
+	 */
43
+	public static function ee_tep_output_string($string, $translate = false, $protected = false)
44
+	{
45
+		if ($protected === true) {
46
+			return htmlspecialchars($string);
47
+		} else {
48
+			if ($translate === false) {
49
+				return self::ee_tep_parse_input_field_data($string, array( '"' => '&quot;' ));
50
+			} else {
51
+				return self::ee_tep_parse_input_field_data($string, $translate);
52
+			}
53
+		}
54
+	}
55 55
 
56 56
 
57 57
 
58
-    /**
59
-     * ee_tep_parse_input_field_data
60
-     *
61
-     * @param  string $data string to be "translated"
62
-     * @param         array ] $parse array in the form array( 'from' => 'to', ... )
63
-     * @return string
64
-     */
65
-    public static function ee_tep_parse_input_field_data($data, $parse)
66
-    {
67
-        return strtr(trim($data), $parse);
68
-    }
58
+	/**
59
+	 * ee_tep_parse_input_field_data
60
+	 *
61
+	 * @param  string $data string to be "translated"
62
+	 * @param         array ] $parse array in the form array( 'from' => 'to', ... )
63
+	 * @return string
64
+	 */
65
+	public static function ee_tep_parse_input_field_data($data, $parse)
66
+	{
67
+		return strtr(trim($data), $parse);
68
+	}
69 69
 
70 70
 
71 71
 
72
-    /**
73
-     * [ee_tep_not_null description]
74
-     *
75
-     * @param  string | array $value [description]
76
-     * @return bool       [description]
77
-     */
78
-    public static function ee_tep_not_null($value)
79
-    {
80
-        if (is_array($value)) {
81
-            if (count($value) > 0) {
82
-                return true;
83
-            } else {
84
-                return false;
85
-            }
86
-        } else {
87
-            if (( $value !== '' ) && ( strtolower($value) !== 'null' ) && ( strlen(trim($value)) > 0 )) {
88
-                return true;
89
-            } else {
90
-                return false;
91
-            }
92
-        }
93
-    }
72
+	/**
73
+	 * [ee_tep_not_null description]
74
+	 *
75
+	 * @param  string | array $value [description]
76
+	 * @return bool       [description]
77
+	 */
78
+	public static function ee_tep_not_null($value)
79
+	{
80
+		if (is_array($value)) {
81
+			if (count($value) > 0) {
82
+				return true;
83
+			} else {
84
+				return false;
85
+			}
86
+		} else {
87
+			if (( $value !== '' ) && ( strtolower($value) !== 'null' ) && ( strlen(trim($value)) > 0 )) {
88
+				return true;
89
+			} else {
90
+				return false;
91
+			}
92
+		}
93
+	}
94 94
 
95 95
 
96 96
 
97
-    /**
98
-     * Formats a date
99
-     *
100
-     * @param string $date
101
-     * @param string $format - format for the date
102
-     * @deprecated 4.6.12  Note, a search revealed this was not used anywhere in core or in our
103
-     *                       addons at time of writing this.  So just deprecated in case of third party use.
104
-     * @return string
105
-     * @deprecated v4.6.21
106
-     */
107
-    public static function event_date_display($date, $format = '')
108
-    {
109
-        EE_Error::doing_it_wrong(
110
-            __METHOD__,
111
-            __(
112
-                'This method is deprecated as of EE 4.6.12.  Currently it does not reformat as with prior behaviour but just returns the incoming string.  Please use the EE_Datetime helpers for Datetime on the event to display as desired.',
113
-                'event_espresso'
114
-            ),
115
-            '4.6.21'
116
-        );
117
-        return $date;
118
-    }
97
+	/**
98
+	 * Formats a date
99
+	 *
100
+	 * @param string $date
101
+	 * @param string $format - format for the date
102
+	 * @deprecated 4.6.12  Note, a search revealed this was not used anywhere in core or in our
103
+	 *                       addons at time of writing this.  So just deprecated in case of third party use.
104
+	 * @return string
105
+	 * @deprecated v4.6.21
106
+	 */
107
+	public static function event_date_display($date, $format = '')
108
+	{
109
+		EE_Error::doing_it_wrong(
110
+			__METHOD__,
111
+			__(
112
+				'This method is deprecated as of EE 4.6.12.  Currently it does not reformat as with prior behaviour but just returns the incoming string.  Please use the EE_Datetime helpers for Datetime on the event to display as desired.',
113
+				'event_espresso'
114
+			),
115
+			'4.6.21'
116
+		);
117
+		return $date;
118
+	}
119 119
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -46,7 +46,7 @@  discard block
 block discarded – undo
46 46
             return htmlspecialchars($string);
47 47
         } else {
48 48
             if ($translate === false) {
49
-                return self::ee_tep_parse_input_field_data($string, array( '"' => '&quot;' ));
49
+                return self::ee_tep_parse_input_field_data($string, array('"' => '&quot;'));
50 50
             } else {
51 51
                 return self::ee_tep_parse_input_field_data($string, $translate);
52 52
             }
@@ -84,7 +84,7 @@  discard block
 block discarded – undo
84 84
                 return false;
85 85
             }
86 86
         } else {
87
-            if (( $value !== '' ) && ( strtolower($value) !== 'null' ) && ( strlen(trim($value)) > 0 )) {
87
+            if (($value !== '') && (strtolower($value) !== 'null') && (strlen(trim($value)) > 0)) {
88 88
                 return true;
89 89
             } else {
90 90
                 return false;
Please login to merge, or discard this patch.
core/helpers/EEH_Inflector.helper.php 3 patches
Doc Comments   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -51,7 +51,7 @@  discard block
 block discarded – undo
51 51
 
52 52
     /**
53 53
      * @param string $word
54
-     * @return mixed
54
+     * @return string
55 55
      */
56 56
     public static function singularize_and_upper($word)
57 57
     {
@@ -246,7 +246,7 @@  discard block
 block discarded – undo
246 246
     /**
247 247
      * Camelizes all but the first word. This is handy converting a method which followed EE4 legacy naming convention
248 248
      * with the new PSR-based naming conventions
249
-     * @param $word
249
+     * @param string $word
250 250
      * @return string
251 251
      */
252 252
     public static function camelize_all_but_first($word)
@@ -401,7 +401,7 @@  discard block
 block discarded – undo
401 401
 
402 402
 
403 403
     /**
404
-     * @param $string
404
+     * @param string $string
405 405
      * @return string
406 406
      */
407 407
     public static function add_indefinite_article($string)
Please login to merge, or discard this patch.
Indentation   +378 added lines, -378 removed lines patch added patch discarded remove patch
@@ -33,382 +33,382 @@
 block discarded – undo
33 33
  */
34 34
 class EEH_Inflector
35 35
 {
36
-    // ------ CLASS METHODS ------ //
37
-    // ---- Public methods ---- //
38
-    // {{{ pluralize()
39
-
40
-    /**
41
-     * Just calls self::pluralize and strtolower on $word and returns it
42
-     * @param string $word
43
-     * @return string
44
-     */
45
-    public static function pluralize_and_lower($word)
46
-    {
47
-        return strtolower(self::pluralize($word));
48
-    }
49
-
50
-
51
-
52
-    /**
53
-     * @param string $word
54
-     * @return mixed
55
-     */
56
-    public static function singularize_and_upper($word)
57
-    {
58
-        return str_replace(' ', '_', self::humanize(self::singularize($word), 'all'));
59
-    }
60
-
61
-
62
-
63
-    /**
64
-     * Pluralizes English nouns.
65
-     *
66
-     * @access public
67
-     * @static
68
-     * @param    string    $word    English noun to pluralize
69
-     * @return string Plural noun
70
-     */
71
-    public static function pluralize($word)
72
-    {
73
-        $plural = array(
74
-            '/(quiz)$/i'               => '\1zes',
75
-            '/^(ox)$/i'                => '\1en',
76
-            '/([m|l])ouse$/i'          => '\1ice',
77
-            '/(matr|vert|ind)ix|ex$/i' => '\1ices',
78
-            '/(x|ch|ss|sh)$/i'         => '\1es',
79
-            '/([^aeiouy]|qu)ies$/i'    => '\1y',
80
-            '/([^aeiouy]|qu)y$/i'      => '\1ies',
81
-            '/(hive)$/i'               => '\1s',
82
-            '/(?:([^f])fe|([lr])f)$/i' => '\1\2ves',
83
-            '/sis$/i'                  => 'ses',
84
-            '/([ti])um$/i'             => '\1a',
85
-            '/(buffal|tomat)o$/i'      => '\1oes',
86
-            '/(bu)s$/i'                => '\1ses',
87
-            '/(alias|status)/i'        => '\1es',
88
-            '/(octop|vir)us$/i'        => '\1i',
89
-            '/(ax|test)is$/i'          => '\1es',
90
-            '/s$/i'                    => 's',
91
-            '/$/'                      => 's');
92
-
93
-        $uncountable = array('equipment', 'information', 'rice', 'money', 'species', 'series', 'fish', 'sheep');
94
-
95
-        $irregular = array(
96
-            'person' => 'people',
97
-            'man'    => 'men',
98
-            'child'  => 'children',
99
-            'sex'    => 'sexes',
100
-            'move'   => 'moves');
101
-
102
-        $lowercased_word = strtolower($word);
103
-
104
-        foreach ($uncountable as $_uncountable) {
105
-            if (substr($lowercased_word, (-1 * strlen($_uncountable))) == $_uncountable && // even though the word "price" ends in "rice", it can be pluralized, so check the previous character isnt a letter
106
-                    ! ctype_alpha($lowercased_word[ strlen($lowercased_word) - strlen($_uncountable) ]) ) {
107
-                return $word;
108
-            }
109
-        }
110
-
111
-        foreach ($irregular as $_plural => $_singular) {
112
-            if (preg_match('/(' . $_plural . ')$/i', $word, $arr)) {
113
-                return preg_replace('/(' . $_plural . ')$/i', substr($arr[0], 0, 1) . substr($_singular, 1), $word);
114
-            }
115
-        }
116
-
117
-        foreach ($plural as $rule => $replacement) {
118
-            if (preg_match($rule, $word)) {
119
-                return preg_replace($rule, $replacement, $word);
120
-            }
121
-        }
122
-        return false;
123
-    }
124
-
125
-    // }}}
126
-    // {{{ singularize()
127
-
128
-    /**
129
-     * Singularizes English nouns.
130
-     *
131
-     * @access public
132
-     * @static
133
-     * @param    string    $word    English noun to singularize
134
-     * @return string Singular noun.
135
-     */
136
-    public static function singularize($word)
137
-    {
138
-        $singular = array(
139
-            '/(quiz)zes$/i'                                                    => '\1',
140
-            '/(matr)ices$/i'                                                   => '\1ix',
141
-            '/(vert|ind)ices$/i'                                               => '\1ex',
142
-            '/^(ox)en/i'                                                       => '\1',
143
-            '/(alias|status)es$/i'                                             => '\1',
144
-            '/([octop|vir])i$/i'                                               => '\1us',
145
-            '/(cris|ax|test)es$/i'                                             => '\1is',
146
-            '/(shoe)s$/i'                                                      => '\1',
147
-            '/(o)es$/i'                                                        => '\1',
148
-            '/(bus)es$/i'                                                      => '\1',
149
-            '/([m|l])ice$/i'                                                   => '\1ouse',
150
-            '/(x|ch|ss|sh)es$/i'                                               => '\1',
151
-            '/(m)ovies$/i'                                                     => '\1ovie',
152
-            '/(s)eries$/i'                                                     => '\1eries',
153
-            '/([^aeiouy]|qu)ies$/i'                                            => '\1y',
154
-            '/([lr])ves$/i'                                                    => '\1f',
155
-            '/(tive)s$/i'                                                      => '\1',
156
-            '/(hive)s$/i'                                                      => '\1',
157
-            '/([^f])ves$/i'                                                    => '\1fe',
158
-            '/(^analy)ses$/i'                                                  => '\1sis',
159
-            '/((a)naly|(b)a|(d)iagno|(p)arenthe|(p)rogno|(s)ynop|(t)he)ses$/i' => '\1\2sis',
160
-            '/([ti])a$/i'                                                      => '\1um',
161
-            '/(n)ews$/i'                                                       => '\1ews',
162
-            '/s$/i'                                                            => '',
163
-        );
164
-
165
-        $uncountable = array('equipment', 'information', 'rice', 'money', 'species', 'series', 'fish', 'sheep');
166
-
167
-        $irregular = array(
168
-            'person' => 'people',
169
-            'man'    => 'men',
170
-            'child'  => 'children',
171
-            'sex'    => 'sexes',
172
-            'move'   => 'moves');
173
-
174
-        $lowercased_word = strtolower($word);
175
-        foreach ($uncountable as $_uncountable) {
176
-            if (substr($lowercased_word, (-1 * strlen($_uncountable))) == $_uncountable) {
177
-                return $word;
178
-            }
179
-        }
180
-
181
-        foreach ($irregular as $_plural => $_singular) {
182
-            if (preg_match('/(' . $_singular . ')$/i', $word, $arr)) {
183
-                return preg_replace('/(' . $_singular . ')$/i', substr($arr[0], 0, 1) . substr($_plural, 1), $word);
184
-            }
185
-        }
186
-
187
-        foreach ($singular as $rule => $replacement) {
188
-            if (preg_match($rule, $word)) {
189
-                return preg_replace($rule, $replacement, $word);
190
-            }
191
-        }
192
-
193
-        return $word;
194
-    }
195
-
196
-    // }}}
197
-    // {{{ titleize()
198
-
199
-    /**
200
-     * Converts an underscored or CamelCase word into a English
201
-     * sentence.
202
-     *
203
-     * The titleize static function converts text like "WelcomePage",
204
-     * "welcome_page" or  "welcome page" to this "Welcome
205
-     * Page".
206
-     * If second parameter is set to 'first' it will only
207
-     * capitalize the first character of the title.
208
-     *
209
-     * @access public
210
-     * @static
211
-     * @param    string    $word    Word to format as tile
212
-     * @param    string    $uppercase    If set to 'first' it will only uppercase the
213
-     * first character. Otherwise it will uppercase all
214
-     * the words in the title.
215
-     * @return string Text formatted as title
216
-     */
217
-    public static function titleize($word, $uppercase = '')
218
-    {
219
-        $uppercase = $uppercase === 'first' ? 'ucfirst' : 'ucwords';
220
-        return $uppercase(EEH_Inflector::humanize(EEH_Inflector::underscore($word)));
221
-    }
222
-
223
-    // }}}
224
-    // {{{ camelize()
225
-
226
-    /**
227
-     * Returns given word as CamelCased
228
-     *
229
-     * Converts a word like "send_email" to "SendEmail". It
230
-     * will remove non alphanumeric character from the word, so
231
-     * "who's online" will be converted to "WhoSOnline"
232
-     *
233
-     * @access public
234
-     * @static
235
-     * @see variablize
236
-     * @param    string    $word    Word to convert to camel case
237
-     * @return string UpperCamelCasedWord
238
-     */
239
-    public static function camelize($word)
240
-    {
241
-        return str_replace(' ', '', ucwords(preg_replace('/[^A-Z^a-z^0-9]+/', ' ', $word)));
242
-    }
243
-
244
-
245
-
246
-    /**
247
-     * Camelizes all but the first word. This is handy converting a method which followed EE4 legacy naming convention
248
-     * with the new PSR-based naming conventions
249
-     * @param $word
250
-     * @return string
251
-     */
252
-    public static function camelize_all_but_first($word)
253
-    {
254
-        return lcfirst(EEH_Inflector::camelize($word));
255
-    }
256
-    // }}}
257
-    // {{{ underscore()
258
-
259
-    /**
260
-     * Converts a word "into_it_s_underscored_version"
261
-     *
262
-     * Convert any "CamelCased" or "ordinary Word" into an
263
-     * "underscored_word".
264
-     *
265
-     * This can be really useful for creating friendly URLs.
266
-     *
267
-     * @access public
268
-     * @static
269
-     * @param    string    $word    Word to underscore
270
-     * @return string Underscored word
271
-     */
272
-    public static function underscore($word)
273
-    {
274
-        return strtolower(preg_replace('/[^A-Z^a-z^0-9]+/', '_', preg_replace('/([a-zd])([A-Z])/', '1_2', preg_replace('/([A-Z]+)([A-Z][a-z])/', '1_2', $word))));
275
-    }
276
-
277
-    // }}}
278
-    // {{{ humanize()
279
-
280
-    /**
281
-     * Returns a human-readable string from $word
282
-     *
283
-     * Returns a human-readable string from $word, by replacing
284
-     * underscores with a space, and by upper-casing the initial
285
-     * character by default.
286
-     *
287
-     * If you need to uppercase all the words you just have to
288
-     * pass 'all' as a second parameter.
289
-     *
290
-     * @access public
291
-     * @static
292
-     * @param    string    $word    String to "humanize"
293
-     * @param    string    $uppercase    If set to 'all' it will uppercase all the words
294
-     * instead of just the first one.
295
-     * @return string Human-readable word
296
-     */
297
-    public static function humanize($word, $uppercase = '')
298
-    {
299
-        // make special exceptions for acronyms
300
-        $word = str_replace('wp_', 'WP_', $word);
301
-        $uppercase = $uppercase === 'all' ? 'ucwords' : 'ucfirst';
302
-        return $uppercase(str_replace('_', ' ', preg_replace('/_id$/', '', $word)));
303
-    }
304
-
305
-    // }}}
306
-    // {{{ variablize()
307
-
308
-    /**
309
-     * Same as camelize but first char is underscored
310
-     *
311
-     * Converts a word like "send_email" to "sendEmail". It
312
-     * will remove non alphanumeric character from the word, so
313
-     * "who's online" will be converted to "whoSOnline"
314
-     *
315
-     * @access public
316
-     * @static
317
-     * @see camelize
318
-     * @param    string    $word    Word to lowerCamelCase
319
-     * @return string Returns a lowerCamelCasedWord
320
-     */
321
-    public static function variablize($word)
322
-    {
323
-        $word = EEH_Inflector::camelize($word);
324
-        return strtolower($word[0]) . substr($word, 1);
325
-    }
326
-
327
-    // }}}
328
-    // {{{ tableize()
329
-
330
-    /**
331
-     * Converts a class name to its table name according to rails
332
-     * naming conventions.
333
-     *
334
-     * Converts "Person" to "people"
335
-     *
336
-     * @access public
337
-     * @static
338
-     * @see classify
339
-     * @param    string    $class_name    Class name for getting related table_name.
340
-     * @return string plural_table_name
341
-     */
342
-    public static function tableize($class_name)
343
-    {
344
-        return EEH_Inflector::pluralize(EEH_Inflector::underscore($class_name));
345
-    }
346
-
347
-    // }}}
348
-    // {{{ classify()
349
-
350
-    /**
351
-     * Converts a table name to its class name according to rails
352
-     * naming conventions.
353
-     *
354
-     * Converts "people" to "Person"
355
-     *
356
-     * @access public
357
-     * @static
358
-     * @see tableize
359
-     * @param    string    $table_name    Table name for getting related ClassName.
360
-     * @return string SingularClassName
361
-     */
362
-    public static function classify($table_name)
363
-    {
364
-        return EEH_Inflector::camelize(EEH_Inflector::singularize($table_name));
365
-    }
366
-
367
-    // }}}
368
-    // {{{ ordinalize()
369
-
370
-    /**
371
-     * Converts number to its ordinal English form.
372
-     *
373
-     * This method converts 13 to 13th, 2 to 2nd ...
374
-     *
375
-     * @access public
376
-     * @static
377
-     * @param    integer    $number    Number to get its ordinal value
378
-     * @return string Ordinal representation of given string.
379
-     */
380
-    public static function ordinalize($number)
381
-    {
382
-        if (in_array(($number % 100), range(11, 13))) {
383
-            return $number . 'th';
384
-        } else {
385
-            switch (($number % 10)) {
386
-                case 1:
387
-                    return $number . 'st';
388
-                    break;
389
-                case 2:
390
-                    return $number . 'nd';
391
-                    break;
392
-                case 3:
393
-                    return $number . 'rd';
394
-                default:
395
-                    return $number . 'th';
396
-                    break;
397
-            }
398
-        }
399
-    }
400
-
401
-
402
-
403
-    /**
404
-     * @param $string
405
-     * @return string
406
-     */
407
-    public static function add_indefinite_article($string)
408
-    {
409
-        if (strtolower($string) === 'null') {
410
-            return $string;
411
-        }
412
-        return (stripos('aeiou', $string[0]) !== false ? 'an ' : 'a ') . $string;
413
-    }
36
+	// ------ CLASS METHODS ------ //
37
+	// ---- Public methods ---- //
38
+	// {{{ pluralize()
39
+
40
+	/**
41
+	 * Just calls self::pluralize and strtolower on $word and returns it
42
+	 * @param string $word
43
+	 * @return string
44
+	 */
45
+	public static function pluralize_and_lower($word)
46
+	{
47
+		return strtolower(self::pluralize($word));
48
+	}
49
+
50
+
51
+
52
+	/**
53
+	 * @param string $word
54
+	 * @return mixed
55
+	 */
56
+	public static function singularize_and_upper($word)
57
+	{
58
+		return str_replace(' ', '_', self::humanize(self::singularize($word), 'all'));
59
+	}
60
+
61
+
62
+
63
+	/**
64
+	 * Pluralizes English nouns.
65
+	 *
66
+	 * @access public
67
+	 * @static
68
+	 * @param    string    $word    English noun to pluralize
69
+	 * @return string Plural noun
70
+	 */
71
+	public static function pluralize($word)
72
+	{
73
+		$plural = array(
74
+			'/(quiz)$/i'               => '\1zes',
75
+			'/^(ox)$/i'                => '\1en',
76
+			'/([m|l])ouse$/i'          => '\1ice',
77
+			'/(matr|vert|ind)ix|ex$/i' => '\1ices',
78
+			'/(x|ch|ss|sh)$/i'         => '\1es',
79
+			'/([^aeiouy]|qu)ies$/i'    => '\1y',
80
+			'/([^aeiouy]|qu)y$/i'      => '\1ies',
81
+			'/(hive)$/i'               => '\1s',
82
+			'/(?:([^f])fe|([lr])f)$/i' => '\1\2ves',
83
+			'/sis$/i'                  => 'ses',
84
+			'/([ti])um$/i'             => '\1a',
85
+			'/(buffal|tomat)o$/i'      => '\1oes',
86
+			'/(bu)s$/i'                => '\1ses',
87
+			'/(alias|status)/i'        => '\1es',
88
+			'/(octop|vir)us$/i'        => '\1i',
89
+			'/(ax|test)is$/i'          => '\1es',
90
+			'/s$/i'                    => 's',
91
+			'/$/'                      => 's');
92
+
93
+		$uncountable = array('equipment', 'information', 'rice', 'money', 'species', 'series', 'fish', 'sheep');
94
+
95
+		$irregular = array(
96
+			'person' => 'people',
97
+			'man'    => 'men',
98
+			'child'  => 'children',
99
+			'sex'    => 'sexes',
100
+			'move'   => 'moves');
101
+
102
+		$lowercased_word = strtolower($word);
103
+
104
+		foreach ($uncountable as $_uncountable) {
105
+			if (substr($lowercased_word, (-1 * strlen($_uncountable))) == $_uncountable && // even though the word "price" ends in "rice", it can be pluralized, so check the previous character isnt a letter
106
+					! ctype_alpha($lowercased_word[ strlen($lowercased_word) - strlen($_uncountable) ]) ) {
107
+				return $word;
108
+			}
109
+		}
110
+
111
+		foreach ($irregular as $_plural => $_singular) {
112
+			if (preg_match('/(' . $_plural . ')$/i', $word, $arr)) {
113
+				return preg_replace('/(' . $_plural . ')$/i', substr($arr[0], 0, 1) . substr($_singular, 1), $word);
114
+			}
115
+		}
116
+
117
+		foreach ($plural as $rule => $replacement) {
118
+			if (preg_match($rule, $word)) {
119
+				return preg_replace($rule, $replacement, $word);
120
+			}
121
+		}
122
+		return false;
123
+	}
124
+
125
+	// }}}
126
+	// {{{ singularize()
127
+
128
+	/**
129
+	 * Singularizes English nouns.
130
+	 *
131
+	 * @access public
132
+	 * @static
133
+	 * @param    string    $word    English noun to singularize
134
+	 * @return string Singular noun.
135
+	 */
136
+	public static function singularize($word)
137
+	{
138
+		$singular = array(
139
+			'/(quiz)zes$/i'                                                    => '\1',
140
+			'/(matr)ices$/i'                                                   => '\1ix',
141
+			'/(vert|ind)ices$/i'                                               => '\1ex',
142
+			'/^(ox)en/i'                                                       => '\1',
143
+			'/(alias|status)es$/i'                                             => '\1',
144
+			'/([octop|vir])i$/i'                                               => '\1us',
145
+			'/(cris|ax|test)es$/i'                                             => '\1is',
146
+			'/(shoe)s$/i'                                                      => '\1',
147
+			'/(o)es$/i'                                                        => '\1',
148
+			'/(bus)es$/i'                                                      => '\1',
149
+			'/([m|l])ice$/i'                                                   => '\1ouse',
150
+			'/(x|ch|ss|sh)es$/i'                                               => '\1',
151
+			'/(m)ovies$/i'                                                     => '\1ovie',
152
+			'/(s)eries$/i'                                                     => '\1eries',
153
+			'/([^aeiouy]|qu)ies$/i'                                            => '\1y',
154
+			'/([lr])ves$/i'                                                    => '\1f',
155
+			'/(tive)s$/i'                                                      => '\1',
156
+			'/(hive)s$/i'                                                      => '\1',
157
+			'/([^f])ves$/i'                                                    => '\1fe',
158
+			'/(^analy)ses$/i'                                                  => '\1sis',
159
+			'/((a)naly|(b)a|(d)iagno|(p)arenthe|(p)rogno|(s)ynop|(t)he)ses$/i' => '\1\2sis',
160
+			'/([ti])a$/i'                                                      => '\1um',
161
+			'/(n)ews$/i'                                                       => '\1ews',
162
+			'/s$/i'                                                            => '',
163
+		);
164
+
165
+		$uncountable = array('equipment', 'information', 'rice', 'money', 'species', 'series', 'fish', 'sheep');
166
+
167
+		$irregular = array(
168
+			'person' => 'people',
169
+			'man'    => 'men',
170
+			'child'  => 'children',
171
+			'sex'    => 'sexes',
172
+			'move'   => 'moves');
173
+
174
+		$lowercased_word = strtolower($word);
175
+		foreach ($uncountable as $_uncountable) {
176
+			if (substr($lowercased_word, (-1 * strlen($_uncountable))) == $_uncountable) {
177
+				return $word;
178
+			}
179
+		}
180
+
181
+		foreach ($irregular as $_plural => $_singular) {
182
+			if (preg_match('/(' . $_singular . ')$/i', $word, $arr)) {
183
+				return preg_replace('/(' . $_singular . ')$/i', substr($arr[0], 0, 1) . substr($_plural, 1), $word);
184
+			}
185
+		}
186
+
187
+		foreach ($singular as $rule => $replacement) {
188
+			if (preg_match($rule, $word)) {
189
+				return preg_replace($rule, $replacement, $word);
190
+			}
191
+		}
192
+
193
+		return $word;
194
+	}
195
+
196
+	// }}}
197
+	// {{{ titleize()
198
+
199
+	/**
200
+	 * Converts an underscored or CamelCase word into a English
201
+	 * sentence.
202
+	 *
203
+	 * The titleize static function converts text like "WelcomePage",
204
+	 * "welcome_page" or  "welcome page" to this "Welcome
205
+	 * Page".
206
+	 * If second parameter is set to 'first' it will only
207
+	 * capitalize the first character of the title.
208
+	 *
209
+	 * @access public
210
+	 * @static
211
+	 * @param    string    $word    Word to format as tile
212
+	 * @param    string    $uppercase    If set to 'first' it will only uppercase the
213
+	 * first character. Otherwise it will uppercase all
214
+	 * the words in the title.
215
+	 * @return string Text formatted as title
216
+	 */
217
+	public static function titleize($word, $uppercase = '')
218
+	{
219
+		$uppercase = $uppercase === 'first' ? 'ucfirst' : 'ucwords';
220
+		return $uppercase(EEH_Inflector::humanize(EEH_Inflector::underscore($word)));
221
+	}
222
+
223
+	// }}}
224
+	// {{{ camelize()
225
+
226
+	/**
227
+	 * Returns given word as CamelCased
228
+	 *
229
+	 * Converts a word like "send_email" to "SendEmail". It
230
+	 * will remove non alphanumeric character from the word, so
231
+	 * "who's online" will be converted to "WhoSOnline"
232
+	 *
233
+	 * @access public
234
+	 * @static
235
+	 * @see variablize
236
+	 * @param    string    $word    Word to convert to camel case
237
+	 * @return string UpperCamelCasedWord
238
+	 */
239
+	public static function camelize($word)
240
+	{
241
+		return str_replace(' ', '', ucwords(preg_replace('/[^A-Z^a-z^0-9]+/', ' ', $word)));
242
+	}
243
+
244
+
245
+
246
+	/**
247
+	 * Camelizes all but the first word. This is handy converting a method which followed EE4 legacy naming convention
248
+	 * with the new PSR-based naming conventions
249
+	 * @param $word
250
+	 * @return string
251
+	 */
252
+	public static function camelize_all_but_first($word)
253
+	{
254
+		return lcfirst(EEH_Inflector::camelize($word));
255
+	}
256
+	// }}}
257
+	// {{{ underscore()
258
+
259
+	/**
260
+	 * Converts a word "into_it_s_underscored_version"
261
+	 *
262
+	 * Convert any "CamelCased" or "ordinary Word" into an
263
+	 * "underscored_word".
264
+	 *
265
+	 * This can be really useful for creating friendly URLs.
266
+	 *
267
+	 * @access public
268
+	 * @static
269
+	 * @param    string    $word    Word to underscore
270
+	 * @return string Underscored word
271
+	 */
272
+	public static function underscore($word)
273
+	{
274
+		return strtolower(preg_replace('/[^A-Z^a-z^0-9]+/', '_', preg_replace('/([a-zd])([A-Z])/', '1_2', preg_replace('/([A-Z]+)([A-Z][a-z])/', '1_2', $word))));
275
+	}
276
+
277
+	// }}}
278
+	// {{{ humanize()
279
+
280
+	/**
281
+	 * Returns a human-readable string from $word
282
+	 *
283
+	 * Returns a human-readable string from $word, by replacing
284
+	 * underscores with a space, and by upper-casing the initial
285
+	 * character by default.
286
+	 *
287
+	 * If you need to uppercase all the words you just have to
288
+	 * pass 'all' as a second parameter.
289
+	 *
290
+	 * @access public
291
+	 * @static
292
+	 * @param    string    $word    String to "humanize"
293
+	 * @param    string    $uppercase    If set to 'all' it will uppercase all the words
294
+	 * instead of just the first one.
295
+	 * @return string Human-readable word
296
+	 */
297
+	public static function humanize($word, $uppercase = '')
298
+	{
299
+		// make special exceptions for acronyms
300
+		$word = str_replace('wp_', 'WP_', $word);
301
+		$uppercase = $uppercase === 'all' ? 'ucwords' : 'ucfirst';
302
+		return $uppercase(str_replace('_', ' ', preg_replace('/_id$/', '', $word)));
303
+	}
304
+
305
+	// }}}
306
+	// {{{ variablize()
307
+
308
+	/**
309
+	 * Same as camelize but first char is underscored
310
+	 *
311
+	 * Converts a word like "send_email" to "sendEmail". It
312
+	 * will remove non alphanumeric character from the word, so
313
+	 * "who's online" will be converted to "whoSOnline"
314
+	 *
315
+	 * @access public
316
+	 * @static
317
+	 * @see camelize
318
+	 * @param    string    $word    Word to lowerCamelCase
319
+	 * @return string Returns a lowerCamelCasedWord
320
+	 */
321
+	public static function variablize($word)
322
+	{
323
+		$word = EEH_Inflector::camelize($word);
324
+		return strtolower($word[0]) . substr($word, 1);
325
+	}
326
+
327
+	// }}}
328
+	// {{{ tableize()
329
+
330
+	/**
331
+	 * Converts a class name to its table name according to rails
332
+	 * naming conventions.
333
+	 *
334
+	 * Converts "Person" to "people"
335
+	 *
336
+	 * @access public
337
+	 * @static
338
+	 * @see classify
339
+	 * @param    string    $class_name    Class name for getting related table_name.
340
+	 * @return string plural_table_name
341
+	 */
342
+	public static function tableize($class_name)
343
+	{
344
+		return EEH_Inflector::pluralize(EEH_Inflector::underscore($class_name));
345
+	}
346
+
347
+	// }}}
348
+	// {{{ classify()
349
+
350
+	/**
351
+	 * Converts a table name to its class name according to rails
352
+	 * naming conventions.
353
+	 *
354
+	 * Converts "people" to "Person"
355
+	 *
356
+	 * @access public
357
+	 * @static
358
+	 * @see tableize
359
+	 * @param    string    $table_name    Table name for getting related ClassName.
360
+	 * @return string SingularClassName
361
+	 */
362
+	public static function classify($table_name)
363
+	{
364
+		return EEH_Inflector::camelize(EEH_Inflector::singularize($table_name));
365
+	}
366
+
367
+	// }}}
368
+	// {{{ ordinalize()
369
+
370
+	/**
371
+	 * Converts number to its ordinal English form.
372
+	 *
373
+	 * This method converts 13 to 13th, 2 to 2nd ...
374
+	 *
375
+	 * @access public
376
+	 * @static
377
+	 * @param    integer    $number    Number to get its ordinal value
378
+	 * @return string Ordinal representation of given string.
379
+	 */
380
+	public static function ordinalize($number)
381
+	{
382
+		if (in_array(($number % 100), range(11, 13))) {
383
+			return $number . 'th';
384
+		} else {
385
+			switch (($number % 10)) {
386
+				case 1:
387
+					return $number . 'st';
388
+					break;
389
+				case 2:
390
+					return $number . 'nd';
391
+					break;
392
+				case 3:
393
+					return $number . 'rd';
394
+				default:
395
+					return $number . 'th';
396
+					break;
397
+			}
398
+		}
399
+	}
400
+
401
+
402
+
403
+	/**
404
+	 * @param $string
405
+	 * @return string
406
+	 */
407
+	public static function add_indefinite_article($string)
408
+	{
409
+		if (strtolower($string) === 'null') {
410
+			return $string;
411
+		}
412
+		return (stripos('aeiou', $string[0]) !== false ? 'an ' : 'a ') . $string;
413
+	}
414 414
 }
Please login to merge, or discard this patch.
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -103,14 +103,14 @@  discard block
 block discarded – undo
103 103
 
104 104
         foreach ($uncountable as $_uncountable) {
105 105
             if (substr($lowercased_word, (-1 * strlen($_uncountable))) == $_uncountable && // even though the word "price" ends in "rice", it can be pluralized, so check the previous character isnt a letter
106
-                    ! ctype_alpha($lowercased_word[ strlen($lowercased_word) - strlen($_uncountable) ]) ) {
106
+                    ! ctype_alpha($lowercased_word[strlen($lowercased_word) - strlen($_uncountable)])) {
107 107
                 return $word;
108 108
             }
109 109
         }
110 110
 
111 111
         foreach ($irregular as $_plural => $_singular) {
112
-            if (preg_match('/(' . $_plural . ')$/i', $word, $arr)) {
113
-                return preg_replace('/(' . $_plural . ')$/i', substr($arr[0], 0, 1) . substr($_singular, 1), $word);
112
+            if (preg_match('/('.$_plural.')$/i', $word, $arr)) {
113
+                return preg_replace('/('.$_plural.')$/i', substr($arr[0], 0, 1).substr($_singular, 1), $word);
114 114
             }
115 115
         }
116 116
 
@@ -179,8 +179,8 @@  discard block
 block discarded – undo
179 179
         }
180 180
 
181 181
         foreach ($irregular as $_plural => $_singular) {
182
-            if (preg_match('/(' . $_singular . ')$/i', $word, $arr)) {
183
-                return preg_replace('/(' . $_singular . ')$/i', substr($arr[0], 0, 1) . substr($_plural, 1), $word);
182
+            if (preg_match('/('.$_singular.')$/i', $word, $arr)) {
183
+                return preg_replace('/('.$_singular.')$/i', substr($arr[0], 0, 1).substr($_plural, 1), $word);
184 184
             }
185 185
         }
186 186
 
@@ -321,7 +321,7 @@  discard block
 block discarded – undo
321 321
     public static function variablize($word)
322 322
     {
323 323
         $word = EEH_Inflector::camelize($word);
324
-        return strtolower($word[0]) . substr($word, 1);
324
+        return strtolower($word[0]).substr($word, 1);
325 325
     }
326 326
 
327 327
     // }}}
@@ -380,19 +380,19 @@  discard block
 block discarded – undo
380 380
     public static function ordinalize($number)
381 381
     {
382 382
         if (in_array(($number % 100), range(11, 13))) {
383
-            return $number . 'th';
383
+            return $number.'th';
384 384
         } else {
385 385
             switch (($number % 10)) {
386 386
                 case 1:
387
-                    return $number . 'st';
387
+                    return $number.'st';
388 388
                     break;
389 389
                 case 2:
390
-                    return $number . 'nd';
390
+                    return $number.'nd';
391 391
                     break;
392 392
                 case 3:
393
-                    return $number . 'rd';
393
+                    return $number.'rd';
394 394
                 default:
395
-                    return $number . 'th';
395
+                    return $number.'th';
396 396
                     break;
397 397
             }
398 398
         }
@@ -409,6 +409,6 @@  discard block
 block discarded – undo
409 409
         if (strtolower($string) === 'null') {
410 410
             return $string;
411 411
         }
412
-        return (stripos('aeiou', $string[0]) !== false ? 'an ' : 'a ') . $string;
412
+        return (stripos('aeiou', $string[0]) !== false ? 'an ' : 'a ').$string;
413 413
     }
414 414
 }
Please login to merge, or discard this patch.
core/helpers/EEH_MSG_Template.helper.php 3 patches
Doc Comments   +4 added lines, -3 removed lines patch added patch discarded remove patch
@@ -131,7 +131,7 @@  discard block
 block discarded – undo
131 131
      * Updates all message templates matching the incoming messengers and message types to active status.
132 132
      *
133 133
      * @static
134
-     * @param  array  $messenger_names     Messenger slug
134
+     * @param  string[]  $messenger_names     Messenger slug
135 135
      * @param  array  $message_type_names  Message type slug
136 136
      * @return  int                         count of updated records.
137 137
      */
@@ -451,6 +451,7 @@  discard block
 block discarded – undo
451 451
      * @param EE_Registration | null $registration  The registration object must be included if this
452 452
      *                                              is going to be a registration trigger url.
453 453
      * @param string $sending_messenger             The (optional) sending messenger for the url.
454
+     * @param EE_Registration $registration
454 455
      *
455 456
      * @return string
456 457
      * @throws EE_Error
@@ -1018,8 +1019,8 @@  discard block
 block discarded – undo
1018 1019
     /**
1019 1020
      * @param \EE_messenger    $messenger
1020 1021
      * @param \EE_message_type $message_type
1021
-     * @param                  $GRP_ID
1022
-     * @param                  $global
1022
+     * @param                  integer $GRP_ID
1023
+     * @param                  boolean $global
1023 1024
      * @return array|mixed
1024 1025
      */
1025 1026
     protected static function _create_new_templates(EE_messenger $messenger, EE_message_type $message_type, $GRP_ID, $global)
Please login to merge, or discard this patch.
Indentation   +1227 added lines, -1227 removed lines patch added patch discarded remove patch
@@ -14,1231 +14,1231 @@
 block discarded – undo
14 14
 {
15 15
 
16 16
 
17
-    /**
18
-     * Holds a collection of EE_Message_Template_Pack objects.
19
-     * @type EE_Messages_Template_Pack_Collection
20
-     */
21
-    protected static $_template_pack_collection;
22
-
23
-
24
-
25
-
26
-    private static function _set_autoloader()
27
-    {
28
-        EED_Messages::set_autoloaders();
29
-    }
30
-
31
-
32
-    /**
33
-     * generate_new_templates
34
-     * This will handle the messenger, message_type selection when "adding a new custom template" for an event and will automatically create the defaults for the event.  The user would then be redirected to edit the default context for the event.
35
-     *
36
-     * @access protected
37
-     * @param  string $messenger     the messenger we are generating templates for
38
-     * @param array   $message_types array of message types that the templates are generated for.
39
-     * @param int     $GRP_ID        If a non global template is being generated then it is expected we'll have a GRP_ID to use as the base for the new generated template.
40
-     * @param bool    $global        true indicates generating templates on messenger activation. false requires GRP_ID for event specific template generation.
41
-     * @throws \EE_Error
42
-     * @return array  @see EEH_MSG_Template::_create_new_templates for the return value of each element in the array for templates
43
-     *                that are generated.  If this is an empty array then it means no templates were generated which usually
44
-     *                means there was an error.  Anything in the array with an empty value for `MTP_context` means that it
45
-     *                was not a new generated template but just reactivated (which only happens for global templates that
46
-     *                already exist in the database.
47
-     */
48
-    public static function generate_new_templates($messenger, $message_types, $GRP_ID = 0, $global = false)
49
-    {
50
-        // make sure message_type is an array.
51
-        $message_types = (array) $message_types;
52
-        $templates = array();
53
-
54
-        if (empty($messenger)) {
55
-            throw new EE_Error(__('We need a messenger to generate templates!', 'event_espresso'));
56
-        }
57
-
58
-        // if we STILL have empty $message_types then we need to generate an error message b/c we NEED message types to do the template files.
59
-        if (empty($message_types)) {
60
-            throw new EE_Error(__('We need at least one message type to generate templates!', 'event_espresso'));
61
-        }
62
-
63
-        EEH_MSG_Template::_set_autoloader();
64
-        foreach ($message_types as $message_type) {
65
-            // if global then let's attempt to get the GRP_ID for this combo IF GRP_ID is empty.
66
-            if ($global && empty($GRP_ID)) {
67
-                $GRP_ID = EEM_Message_Template_Group::instance()->get_one(
68
-                    array(
69
-                        array(
70
-                            'MTP_messenger'    => $messenger,
71
-                            'MTP_message_type' => $message_type,
72
-                            'MTP_is_global'    => true,
73
-                        ),
74
-                    )
75
-                );
76
-                $GRP_ID = $GRP_ID instanceof EE_Message_Template_Group ? $GRP_ID->ID() : 0;
77
-            }
78
-            // if this is global template generation.
79
-            // First let's determine if we already HAVE global templates for this messenger and message_type combination.
80
-            //  If we do then NO generation!!
81
-            if ($global && EEH_MSG_Template::already_generated($messenger, $message_type, $GRP_ID)) {
82
-                $templates[] = array(
83
-                    'GRP_ID' => $GRP_ID,
84
-                    'MTP_context' => '',
85
-                );
86
-                // we already have generated templates for this so let's go to the next message type.
87
-                continue;
88
-            }
89
-            $new_message_template_group = EEH_MSG_Template::create_new_templates($messenger, $message_type, $GRP_ID, $global);
90
-
91
-            if (! $new_message_template_group) {
92
-                continue;
93
-            }
94
-            $templates[] = $new_message_template_group;
95
-        }
96
-
97
-        return $templates;
98
-    }
99
-
100
-
101
-    /**
102
-     * The purpose of this method is to determine if there are already generated templates in the database for the given variables.
103
-     * @param  string $messenger     messenger
104
-     * @param  string $message_type message type
105
-     * @param  int $GRP_ID        GRP ID ( if a custom template) (if not provided then we're just doing global template check)
106
-     * @return bool                true = generated, false = hasn't been generated.
107
-     */
108
-    public static function already_generated($messenger, $message_type, $GRP_ID = 0)
109
-    {
110
-        EEH_MSG_Template::_set_autoloader();
111
-        // what method we use depends on whether we have an GRP_ID or not
112
-        $count = empty($GRP_ID)
113
-            ? EEM_Message_Template::instance()->count(
114
-                array(
115
-                    array(
116
-                        'Message_Template_Group.MTP_messenger'    => $messenger,
117
-                        'Message_Template_Group.MTP_message_type' => $message_type,
118
-                        'Message_Template_Group.MTP_is_global'    => true
119
-                    )
120
-                )
121
-            )
122
-            : EEM_Message_Template::instance()->count(array( array( 'GRP_ID' => $GRP_ID ) ));
123
-
124
-        return $count > 0;
125
-    }
126
-
127
-
128
-
129
-
130
-    /**
131
-     * Updates all message templates matching the incoming messengers and message types to active status.
132
-     *
133
-     * @static
134
-     * @param  array  $messenger_names     Messenger slug
135
-     * @param  array  $message_type_names  Message type slug
136
-     * @return  int                         count of updated records.
137
-     */
138
-    public static function update_to_active($messenger_names, $message_type_names)
139
-    {
140
-        $messenger_names = is_array($messenger_names) ? $messenger_names : array( $messenger_names );
141
-        $message_type_names = is_array($message_type_names) ? $message_type_names : array( $message_type_names );
142
-        return EEM_Message_Template_Group::instance()->update(
143
-            array( 'MTP_is_active' => 1 ),
144
-            array(
145
-                array(
146
-                    'MTP_messenger'     => array( 'IN', $messenger_names ),
147
-                    'MTP_message_type'  => array( 'IN', $message_type_names )
148
-                )
149
-            )
150
-        );
151
-    }
152
-
153
-
154
-
155
-    /**
156
-     * Updates all message template groups matching the incoming arguments to inactive status.
157
-     *
158
-     * @static
159
-     * @param array $messenger_names    The messenger slugs.
160
-     *                              If empty then all templates matching the message types are marked inactive.
161
-     *                              Otherwise only templates matching the messengers and message types.
162
-     * @param array $message_type_names     The message type slugs.
163
-     *                              If empty then all templates matching the messengers are marked inactive.
164
-     *                              Otherwise only templates matching the messengers and message types.
165
-     *
166
-     * @return int  count of updated records.
167
-     */
168
-    public static function update_to_inactive($messenger_names = array(), $message_type_names = array())
169
-    {
170
-        return EEM_Message_Template_Group::instance()->deactivate_message_template_groups_for(
171
-            $messenger_names,
172
-            $message_type_names
173
-        );
174
-    }
175
-
176
-
177
-    /**
178
-     * The purpose of this function is to return all installed message objects
179
-     * (messengers and message type regardless of whether they are ACTIVE or not)
180
-     *
181
-     * @deprecated 4.9.0
182
-     * @static
183
-     * @param string $type
184
-     * @return array array consisting of installed messenger objects and installed message type objects.
185
-     */
186
-    public static function get_installed_message_objects($type = 'all')
187
-    {
188
-        self::_set_autoloader();
189
-        $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
190
-        return array(
191
-            'messenger' => $message_resource_manager->installed_messengers(),
192
-            'message_type' => $message_resource_manager->installed_message_types()
193
-        );
194
-    }
195
-
196
-
197
-    /**
198
-     * This will return an array of shortcodes => labels from the
199
-     * messenger and message_type objects associated with this
200
-     * template.
201
-     *
202
-     * @since 4.3.0
203
-     *
204
-     * @param string $message_type
205
-     * @param string $messenger
206
-     * @param array  $fields    What fields we're returning valid shortcodes for.
207
-     *                          If empty then we assume all fields are to be returned. Optional.
208
-     * @param string $context   What context we're going to return shortcodes for. Optional.
209
-     * @param bool $merged      If TRUE then we don't return shortcodes indexed by field,
210
-     *                          but instead an array of the unique shortcodes for all the given ( or all) fields.
211
-     *                          Optional.
212
-     * @throws \EE_Error
213
-     * @return mixed (array|bool) an array of shortcodes in the format
214
-     *                                              array( '[shortcode] => 'label')
215
-     *                                              OR
216
-     *                                              FALSE if no shortcodes found.
217
-     */
218
-    public static function get_shortcodes(
219
-        $message_type,
220
-        $messenger,
221
-        $fields = array(),
222
-        $context = 'admin',
223
-        $merged = false
224
-    ) {
225
-        $messenger_name = str_replace(' ', '_', ucwords(str_replace('_', ' ', $messenger)));
226
-        $mt_name = str_replace(' ', '_', ucwords(str_replace('_', ' ', $message_type)));
227
-        /** @var EE_Message_Resource_Manager $message_resource_manager */
228
-        $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
229
-        // convert slug to object
230
-        $messenger = $message_resource_manager->get_messenger($messenger);
231
-
232
-        // if messenger isn't a EE_messenger resource then bail.
233
-        if (! $messenger instanceof EE_messenger) {
234
-            return array();
235
-        }
236
-
237
-        // validate class for getting our list of shortcodes
238
-        $classname = 'EE_Messages_' . $messenger_name . '_' . $mt_name . '_Validator';
239
-        if (! class_exists($classname)) {
240
-            $msg[] = __('The Validator class was unable to load', 'event_espresso');
241
-            $msg[] = sprintf(
242
-                __('The class name compiled was %s. Please check and make sure the spelling and case is correct for the class name and that there is an autoloader in place for this class', 'event_espresso'),
243
-                $classname
244
-            );
245
-            throw new EE_Error(implode('||', $msg));
246
-        }
247
-
248
-        /** @type EE_Messages_Validator $_VLD */
249
-        $_VLD = new $classname(array(), $context);
250
-        $valid_shortcodes = $_VLD->get_validators();
251
-
252
-        // let's make sure we're only getting the shortcode part of the validators
253
-        $shortcodes = array();
254
-        foreach ($valid_shortcodes as $field => $validators) {
255
-            $shortcodes[ $field ] = $validators['shortcodes'];
256
-        }
257
-        $valid_shortcodes = $shortcodes;
258
-
259
-        // if not all fields let's make sure we ONLY include the shortcodes for the specified fields.
260
-        if (! empty($fields)) {
261
-            $specified_shortcodes = array();
262
-            foreach ($fields as $field) {
263
-                if (isset($valid_shortcodes[ $field ])) {
264
-                    $specified_shortcodes[ $field ] = $valid_shortcodes[ $field ];
265
-                }
266
-            }
267
-            $valid_shortcodes = $specified_shortcodes;
268
-        }
269
-
270
-        // if not merged then let's replace the fields with the localized fields
271
-        if (! $merged) {
272
-            // let's get all the fields for the set messenger so that we can get the localized label and use that in the returned array.
273
-            $field_settings = $messenger->get_template_fields();
274
-            $localized = array();
275
-            foreach ($valid_shortcodes as $field => $shortcodes) {
276
-                // get localized field label
277
-                if (isset($field_settings[ $field ])) {
278
-                    // possible that this is used as a main field.
279
-                    if (empty($field_settings[ $field ])) {
280
-                        if (isset($field_settings['extra'][ $field ])) {
281
-                            $_field = $field_settings['extra'][ $field ]['main']['label'];
282
-                        } else {
283
-                            $_field = $field;
284
-                        }
285
-                    } else {
286
-                        $_field = $field_settings[ $field ]['label'];
287
-                    }
288
-                } elseif (isset($field_settings['extra'])) {
289
-                    // loop through extra "main fields" and see if any of their children have our field
290
-                    foreach ($field_settings['extra'] as $main_field => $fields) {
291
-                        if (isset($fields[ $field ])) {
292
-                            $_field = $fields[ $field ]['label'];
293
-                        } else {
294
-                            $_field = $field;
295
-                        }
296
-                    }
297
-                } else {
298
-                    $_field = $field;
299
-                }
300
-                if (isset($_field)) {
301
-                    $localized[ (string) $_field ] = $shortcodes;
302
-                }
303
-            }
304
-            $valid_shortcodes = $localized;
305
-        }
306
-
307
-        // if $merged then let's merge all the shortcodes into one list NOT indexed by field.
308
-        if ($merged) {
309
-            $merged_codes = array();
310
-            foreach ($valid_shortcodes as $field => $shortcode) {
311
-                foreach ($shortcode as $code => $label) {
312
-                    if (isset($merged_codes[ $code ])) {
313
-                        continue;
314
-                    } else {
315
-                        $merged_codes[ $code ] = $label;
316
-                    }
317
-                }
318
-            }
319
-            $valid_shortcodes = $merged_codes;
320
-        }
321
-
322
-        return $valid_shortcodes;
323
-    }
324
-
325
-
326
-    /**
327
-     * Get Messenger object.
328
-     *
329
-     * @since 4.3.0
330
-     * @deprecated 4.9.0
331
-     * @param string $messenger messenger slug for the messenger object we want to retrieve.
332
-     * @throws \EE_Error
333
-     * @return EE_messenger
334
-     */
335
-    public static function messenger_obj($messenger)
336
-    {
337
-        /** @type EE_Message_Resource_Manager $Message_Resource_Manager */
338
-        $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
339
-        return $Message_Resource_Manager->get_messenger($messenger);
340
-    }
341
-
342
-
343
-    /**
344
-     * get Message type object
345
-     *
346
-     * @since 4.3.0
347
-     * @deprecated 4.9.0
348
-     * @param string $message_type the slug for the message type object to retrieve
349
-     * @throws \EE_Error
350
-     * @return EE_message_type
351
-     */
352
-    public static function message_type_obj($message_type)
353
-    {
354
-        /** @type EE_Message_Resource_Manager $Message_Resource_Manager */
355
-        $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
356
-        return $Message_Resource_Manager->get_message_type($message_type);
357
-    }
358
-
359
-
360
-
361
-
362
-
363
-    /**
364
-     * Given a message_type slug, will return whether that message type is active in the system or not.
365
-     *
366
-     * @since    4.3.0
367
-     * @param  string   $message_type message type to check for.
368
-     * @return boolean
369
-     */
370
-    public static function is_mt_active($message_type)
371
-    {
372
-        /** @type EE_Message_Resource_Manager $Message_Resource_Manager */
373
-        $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
374
-        $active_mts = $Message_Resource_Manager->list_of_active_message_types();
375
-        return in_array($message_type, $active_mts);
376
-    }
377
-
378
-
379
-
380
-    /**
381
-     * Given a messenger slug, will return whether that messenger is active in the system or not.
382
-     *
383
-     * @since    4.3.0
384
-     *
385
-     * @param  string  $messenger slug for messenger to check.
386
-     * @return boolean
387
-     */
388
-    public static function is_messenger_active($messenger)
389
-    {
390
-        /** @type EE_Message_Resource_Manager $Message_Resource_Manager */
391
-        $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
392
-        $active_messenger = $Message_Resource_Manager->get_active_messenger($messenger);
393
-        return $active_messenger instanceof EE_messenger ? true : false;
394
-    }
395
-
396
-
397
-
398
-    /**
399
-     * Used to return active messengers array stored in the wp options table.
400
-     * If no value is present in the option then an empty array is returned.
401
-     *
402
-     * @deprecated 4.9
403
-     * @since 4.3.1
404
-     *
405
-     * @return array
406
-     */
407
-    public static function get_active_messengers_in_db()
408
-    {
409
-        EE_Error::doing_it_wrong(
410
-            __METHOD__,
411
-            __('Please use EE_Message_Resource_Manager::get_active_messengers_option() instead.', 'event_espresso'),
412
-            '4.9.0'
413
-        );
414
-        /** @var EE_Message_Resource_Manager $Message_Resource_Manager */
415
-        $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
416
-        return $Message_Resource_Manager->get_active_messengers_option();
417
-    }
418
-
419
-
420
-
421
-
422
-    /**
423
-     * Used to update the active messengers array stored in the wp options table.
424
-     *
425
-     * @since 4.3.1
426
-     * @deprecated 4.9.0
427
-     *
428
-     * @param array $data_to_save Incoming data to save.
429
-     *
430
-     * @return bool FALSE if not updated, TRUE if updated.
431
-     */
432
-    public static function update_active_messengers_in_db($data_to_save)
433
-    {
434
-        EE_Error::doing_it_wrong(
435
-            __METHOD__,
436
-            __('Please use EE_Message_Resource_Manager::update_active_messengers_option() instead.', 'event_espresso'),
437
-            '4.9.0'
438
-        );
439
-        /** @var EE_Message_Resource_Manager $Message_Resource_Manager */
440
-        $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
441
-        return $Message_Resource_Manager->update_active_messengers_option($data_to_save);
442
-    }
443
-
444
-
445
-    /**
446
-     * This does some validation of incoming params, determines what type of url is being prepped and returns the
447
-     * appropriate url trigger
448
-     *
449
-     * @param EE_message_type $message_type
450
-     * @param EE_Message $message
451
-     * @param EE_Registration | null $registration  The registration object must be included if this
452
-     *                                              is going to be a registration trigger url.
453
-     * @param string $sending_messenger             The (optional) sending messenger for the url.
454
-     *
455
-     * @return string
456
-     * @throws EE_Error
457
-     */
458
-    public static function get_url_trigger(
459
-        EE_message_type $message_type,
460
-        EE_Message $message,
461
-        $registration = null,
462
-        $sending_messenger = ''
463
-    ) {
464
-        // first determine if the url can be to the EE_Message object.
465
-        if (! $message_type->always_generate()) {
466
-            return EEH_MSG_Template::generate_browser_trigger($message);
467
-        }
468
-
469
-        // if $registration object is not valid then exit early because there's nothing that can be generated.
470
-        if (! $registration instanceof EE_Registration) {
471
-            throw new EE_Error(
472
-                __('Incoming value for registration is not a valid EE_Registration object.', 'event_espresso')
473
-            );
474
-        }
475
-
476
-        // validate given context
477
-        $contexts = $message_type->get_contexts();
478
-        if ($message->context() !== '' && ! isset($contexts[ $message->context() ])) {
479
-            throw new EE_Error(
480
-                sprintf(
481
-                    __('The context %s is not a valid context for %s.', 'event_espresso'),
482
-                    $message->context(),
483
-                    get_class($message_type)
484
-                )
485
-            );
486
-        }
487
-
488
-        // valid sending messenger but only if sending messenger set.  Otherwise generating messenger is used.
489
-        if (! empty($sending_messenger)) {
490
-            $with_messengers = $message_type->with_messengers();
491
-            if (! isset($with_messengers[ $message->messenger() ])
492
-                 || ! in_array($sending_messenger, $with_messengers[ $message->messenger() ]) ) {
493
-                throw new EE_Error(
494
-                    sprintf(
495
-                        __(
496
-                            'The given sending messenger string (%1$s) does not match a valid sending messenger with the %2$s.  If this is incorrect, make sure that the message type has defined this messenger as a sending messenger in its $_with_messengers array.',
497
-                            'event_espresso'
498
-                        ),
499
-                        $sending_messenger,
500
-                        get_class($message_type)
501
-                    )
502
-                );
503
-            }
504
-        } else {
505
-            $sending_messenger = $message->messenger();
506
-        }
507
-        return EEH_MSG_Template::generate_url_trigger(
508
-            $sending_messenger,
509
-            $message->messenger(),
510
-            $message->context(),
511
-            $message->message_type(),
512
-            $registration,
513
-            $message->GRP_ID()
514
-        );
515
-    }
516
-
517
-
518
-    /**
519
-     * This returns the url for triggering a in browser view of a specific EE_Message object.
520
-     * @param EE_Message $message
521
-     * @return string.
522
-     */
523
-    public static function generate_browser_trigger(EE_Message $message)
524
-    {
525
-        $query_args = array(
526
-            'ee' => 'msg_browser_trigger',
527
-            'token' => $message->MSG_token()
528
-        );
529
-        return apply_filters(
530
-            'FHEE__EEH_MSG_Template__generate_browser_trigger',
531
-            add_query_arg($query_args, site_url()),
532
-            $message
533
-        );
534
-    }
535
-
536
-
537
-
538
-
539
-
540
-
541
-    /**
542
-     * This returns the url for triggering an in browser view of the error saved on the incoming message object.
543
-     * @param EE_Message $message
544
-     * @return string
545
-     */
546
-    public static function generate_error_display_trigger(EE_Message $message)
547
-    {
548
-        return apply_filters(
549
-            'FHEE__EEH_MSG_Template__generate_error_display_trigger',
550
-            add_query_arg(
551
-                array(
552
-                    'ee' => 'msg_browser_error_trigger',
553
-                    'token' => $message->MSG_token()
554
-                ),
555
-                site_url()
556
-            ),
557
-            $message
558
-        );
559
-    }
560
-
561
-
562
-
563
-
564
-
565
-
566
-    /**
567
-     * This generates a url trigger for the msg_url_trigger route using the given arguments
568
-     *
569
-     * @param string          $sending_messenger    The sending messenger slug.
570
-     * @param string          $generating_messenger The generating messenger slug.
571
-     * @param string          $context              The context for the template.
572
-     * @param string          $message_type         The message type slug
573
-     * @param EE_Registration $registration
574
-     * @param integer          $message_template_group id   The EE_Message_Template_Group ID for the template.
575
-     * @param integer          $data_id     The id to the EE_Base_Class for getting the data used by the trigger.
576
-     * @return string          The generated url.
577
-     */
578
-    public static function generate_url_trigger(
579
-        $sending_messenger,
580
-        $generating_messenger,
581
-        $context,
582
-        $message_type,
583
-        EE_Registration $registration,
584
-        $message_template_group,
585
-        $data_id = 0
586
-    ) {
587
-        $query_args = array(
588
-            'ee' => 'msg_url_trigger',
589
-            'snd_msgr' => $sending_messenger,
590
-            'gen_msgr' => $generating_messenger,
591
-            'message_type' => $message_type,
592
-            'context' => $context,
593
-            'token' => $registration->reg_url_link(),
594
-            'GRP_ID' => $message_template_group,
595
-            'id' => $data_id
596
-            );
597
-        $url = add_query_arg($query_args, get_home_url());
598
-
599
-        // made it here so now we can just get the url and filter it.  Filtered globally and by message type.
600
-        $url = apply_filters(
601
-            'FHEE__EEH_MSG_Template__generate_url_trigger',
602
-            $url,
603
-            $sending_messenger,
604
-            $generating_messenger,
605
-            $context,
606
-            $message_type,
607
-            $registration,
608
-            $message_template_group,
609
-            $data_id
610
-        );
611
-        return $url;
612
-    }
613
-
614
-
615
-
616
-
617
-    /**
618
-     * Return the specific css for the action icon given.
619
-     *
620
-     * @since 4.9.0
621
-     *
622
-     * @param string $type  What action to return.
623
-     * @return string
624
-     */
625
-    public static function get_message_action_icon($type)
626
-    {
627
-        $action_icons = self::get_message_action_icons();
628
-        return isset($action_icons[ $type ]) ? $action_icons[ $type ] : '';
629
-    }
630
-
631
-
632
-    /**
633
-     * This is used for retrieving the css classes used for the icons representing message actions.
634
-     *
635
-     * @since 4.9.0
636
-     *
637
-     * @return array
638
-     */
639
-    public static function get_message_action_icons()
640
-    {
641
-        return apply_filters(
642
-            'FHEE__EEH_MSG_Template__message_action_icons',
643
-            array(
644
-                'view' => array(
645
-                    'label' => __('View Message', 'event_espresso'),
646
-                    'css_class' => 'dashicons dashicons-welcome-view-site',
647
-                ),
648
-                'error' => array(
649
-                    'label' => __('View Error Message', 'event_espresso'),
650
-                    'css_class' => 'dashicons dashicons-info',
651
-                ),
652
-                'see_notifications_for' => array(
653
-                    'label' => __('View Related Messages', 'event_espresso'),
654
-                    'css_class' => 'dashicons dashicons-megaphone',
655
-                ),
656
-                'generate_now' => array(
657
-                    'label' => __('Generate the message now.', 'event_espresso'),
658
-                    'css_class' => 'dashicons dashicons-admin-tools',
659
-                ),
660
-                'send_now' => array(
661
-                    'label' => __('Send Immediately', 'event_espresso'),
662
-                    'css_class' => 'dashicons dashicons-controls-forward',
663
-                ),
664
-                'queue_for_resending' => array(
665
-                    'label' => __('Queue for Resending', 'event_espresso'),
666
-                    'css_class' => 'dashicons dashicons-controls-repeat',
667
-                ),
668
-                'view_transaction' => array(
669
-                    'label' => __('View related Transaction', 'event_espresso'),
670
-                    'css_class' => 'dashicons dashicons-cart',
671
-                )
672
-            )
673
-        );
674
-    }
675
-
676
-
677
-    /**
678
-     * This returns the url for a given action related to EE_Message.
679
-     *
680
-     * @since 4.9.0
681
-     *
682
-     * @param string $type  What type of action to return the url for.
683
-     * @param EE_Message $message   Required for generating the correct url for some types.
684
-     * @param array  $query_params   Any additional query params to be included with the generated url.
685
-     *
686
-     * @return string
687
-     */
688
-    public static function get_message_action_url($type, EE_Message $message = null, $query_params = array())
689
-    {
690
-        $action_urls = self::get_message_action_urls($message, $query_params);
691
-        return isset($action_urls[ $type ])  ? $action_urls[ $type ] : '';
692
-    }
693
-
694
-
695
-
696
-    /**
697
-     * This returns all the current urls for EE_Message actions.
698
-     *
699
-     * @since 4.9.0
700
-     *
701
-     * @param  EE_Message   $message    The EE_Message object required to generate correct urls for some types.
702
-     * @param  array    $query_params   Any additional query_params to be included with the generated url.
703
-     *
704
-     * @return array
705
-     */
706
-    public static function get_message_action_urls(EE_Message $message = null, $query_params = array())
707
-    {
708
-        EE_Registry::instance()->load_helper('URL');
709
-        // if $message is not an instance of EE_Message then let's just do a dummy.
710
-        $message = empty($message) ? EE_Message_Factory::create() : $message;
711
-        $action_urls =  apply_filters(
712
-            'FHEE__EEH_MSG_Template__get_message_action_url',
713
-            array(
714
-                'view' => EEH_MSG_Template::generate_browser_trigger($message),
715
-                'error' => EEH_MSG_Template::generate_error_display_trigger($message),
716
-                'see_notifications_for' => EEH_URL::add_query_args_and_nonce(
717
-                    array_merge(
718
-                        array(
719
-                            'page' => 'espresso_messages',
720
-                            'action' => 'default',
721
-                            'filterby' => 1,
722
-                        ),
723
-                        $query_params
724
-                    ),
725
-                    admin_url('admin.php')
726
-                ),
727
-                'generate_now' => EEH_URL::add_query_args_and_nonce(
728
-                    array(
729
-                        'page' => 'espresso_messages',
730
-                        'action' => 'generate_now',
731
-                        'MSG_ID' => $message->ID()
732
-                    ),
733
-                    admin_url('admin.php')
734
-                ),
735
-                'send_now' => EEH_URL::add_query_args_and_nonce(
736
-                    array(
737
-                        'page' => 'espresso_messages',
738
-                        'action' => 'send_now',
739
-                        'MSG_ID' => $message->ID()
740
-                    ),
741
-                    admin_url('admin.php')
742
-                ),
743
-                'queue_for_resending' => EEH_URL::add_query_args_and_nonce(
744
-                    array(
745
-                        'page' => 'espresso_messages',
746
-                        'action' => 'queue_for_resending',
747
-                        'MSG_ID' => $message->ID()
748
-                    ),
749
-                    admin_url('admin.php')
750
-                ),
751
-            )
752
-        );
753
-        if ($message->TXN_ID() > 0
754
-            && EE_Registry::instance()->CAP->current_user_can(
755
-                'ee_read_transaction',
756
-                'espresso_transactions_default',
757
-                $message->TXN_ID()
758
-            )
759
-        ) {
760
-            $action_urls['view_transaction'] = EEH_URL::add_query_args_and_nonce(
761
-                array(
762
-                    'page' => 'espresso_transactions',
763
-                    'action' => 'view_transaction',
764
-                    'TXN_ID' => $message->TXN_ID()
765
-                ),
766
-                admin_url('admin.php')
767
-            );
768
-        } else {
769
-            $action_urls['view_transaction'] = '';
770
-        }
771
-        return $action_urls;
772
-    }
773
-
774
-
775
-    /**
776
-     * This returns a generated link html including the icon used for the action link for EE_Message actions.
777
-     *
778
-     * @since 4.9.0
779
-     *
780
-     * @param string $type What type of action the link is for (if invalid type is passed in then an
781
-     *                     empty string is returned)
782
-     * @param EE_Message|null $message  The EE_Message object (required for some actions to generate correctly)
783
-     * @param array           $query_params Any extra query params to include in the generated link.
784
-     *
785
-     * @return string
786
-     */
787
-    public static function get_message_action_link($type, EE_Message $message = null, $query_params = array())
788
-    {
789
-        $url = EEH_MSG_Template::get_message_action_url($type, $message, $query_params);
790
-        $icon_css = EEH_MSG_Template::get_message_action_icon($type);
791
-        $title = isset($icon_css['label']) ? 'title="' . $icon_css['label'] . '"' : '';
792
-
793
-        if (empty($url) || empty($icon_css) || ! isset($icon_css['css_class'])) {
794
-            return '';
795
-        }
796
-
797
-        $icon_css['css_class'] .= esc_attr(
798
-            apply_filters(
799
-                'FHEE__EEH_MSG_Template__get_message_action_link__icon_css_class',
800
-                ' js-ee-message-action-link ee-message-action-link-' . $type,
801
-                $type,
802
-                $message,
803
-                $query_params
804
-            )
805
-        );
806
-
807
-        return '<a href="' . $url . '"' . $title . '><span class="' . esc_attr($icon_css['css_class']) . '"></span></a>';
808
-    }
809
-
810
-
811
-
812
-
813
-
814
-    /**
815
-     * This returns an array with keys as reg statuses and values as the corresponding message type slug (filtered).
816
-     *
817
-     * @since 4.9.0
818
-     * @return array
819
-     */
820
-    public static function reg_status_to_message_type_array()
821
-    {
822
-        return (array) apply_filters(
823
-            'FHEE__EEH_MSG_Template__reg_status_to_message_type_array',
824
-            array(
825
-                EEM_Registration::status_id_approved => 'registration',
826
-                EEM_Registration::status_id_pending_payment => 'pending_approval',
827
-                EEM_Registration::status_id_not_approved => 'not_approved_registration',
828
-                EEM_Registration::status_id_cancelled => 'cancelled_registration',
829
-                EEM_Registration::status_id_declined => 'declined_registration'
830
-            )
831
-        );
832
-    }
833
-
834
-
835
-
836
-
837
-    /**
838
-     * This returns the corresponding registration message type slug to the given reg status. If there isn't a
839
-     * match, then returns an empty string.
840
-     *
841
-     * @since 4.9.0
842
-     * @param $reg_status
843
-     * @return string
844
-     */
845
-    public static function convert_reg_status_to_message_type($reg_status)
846
-    {
847
-        $reg_status_array = self::reg_status_to_message_type_array();
848
-        return isset($reg_status_array[ $reg_status ]) ? $reg_status_array[ $reg_status ] : '';
849
-    }
850
-
851
-
852
-    /**
853
-     * This returns an array with keys as payment stati and values as the corresponding message type slug (filtered).
854
-     *
855
-     * @since 4.9.0
856
-     * @return array
857
-     */
858
-    public static function payment_status_to_message_type_array()
859
-    {
860
-        return (array) apply_filters(
861
-            'FHEE__EEH_MSG_Template__payment_status_to_message_type_array',
862
-            array(
863
-                EEM_Payment::status_id_approved => 'payment',
864
-                EEM_Payment::status_id_pending => 'payment_pending',
865
-                EEM_Payment::status_id_cancelled => 'payment_cancelled',
866
-                EEM_Payment::status_id_declined => 'payment_declined',
867
-                EEM_Payment::status_id_failed => 'payment_failed'
868
-            )
869
-        );
870
-    }
871
-
872
-
873
-
874
-
875
-    /**
876
-     * This returns the corresponding payment message type slug to the given payment status. If there isn't a match then
877
-     * an empty string is returned
878
-     *
879
-     * @since 4.9.0
880
-     * @param $payment_status
881
-     * @return string
882
-     */
883
-    public static function convert_payment_status_to_message_type($payment_status)
884
-    {
885
-        $payment_status_array = self::payment_status_to_message_type_array();
886
-        return isset($payment_status_array[ $payment_status ]) ? $payment_status_array[ $payment_status ] : '';
887
-    }
888
-
889
-
890
-    /**
891
-     * This is used to retrieve the template pack for the given name.
892
-     *
893
-     * @param string $template_pack_name  should match the set `dbref` property value on the EE_Messages_Template_Pack.
894
-     *
895
-     * @return EE_Messages_Template_Pack
896
-     */
897
-    public static function get_template_pack($template_pack_name)
898
-    {
899
-        if (! self::$_template_pack_collection instanceof EE_Object_Collection) {
900
-            self::$_template_pack_collection = new EE_Messages_Template_Pack_Collection();
901
-        }
902
-
903
-        // first see if in collection already
904
-        $template_pack = self::$_template_pack_collection->get_by_name($template_pack_name);
905
-
906
-        if ($template_pack instanceof EE_Messages_Template_Pack) {
907
-            return $template_pack;
908
-        }
909
-
910
-        // nope...let's get it.
911
-        // not set yet so let's attempt to get it.
912
-        $pack_class_name = 'EE_Messages_Template_Pack_' . str_replace(
913
-            ' ',
914
-            '_',
915
-            ucwords(
916
-                str_replace('_', ' ', $template_pack_name)
917
-            )
918
-        );
919
-        if (! class_exists($pack_class_name) && $template_pack_name !== 'default') {
920
-            return self::get_template_pack('default');
921
-        } else {
922
-            $template_pack = new $pack_class_name;
923
-            self::$_template_pack_collection->add($template_pack);
924
-            return $template_pack;
925
-        }
926
-    }
927
-
928
-
929
-
930
-
931
-    /**
932
-     * Globs template packs installed in core and returns the template pack collection with all installed template packs
933
-     * in it.
934
-     *
935
-     * @since 4.9.0
936
-     *
937
-     * @return EE_Messages_Template_Pack_Collection
938
-     */
939
-    public static function get_template_pack_collection()
940
-    {
941
-        $new_collection = false;
942
-        if (! self::$_template_pack_collection instanceof EE_Messages_Template_Pack_Collection) {
943
-            self::$_template_pack_collection = new EE_Messages_Template_Pack_Collection();
944
-            $new_collection = true;
945
-        }
946
-
947
-        // glob the defaults directory for messages
948
-        $templates = glob(EE_LIBRARIES . 'messages/defaults/*', GLOB_ONLYDIR);
949
-        foreach ($templates as $template_path) {
950
-            // grab folder name
951
-            $template = basename($template_path);
952
-
953
-            if (! $new_collection) {
954
-                // already have it?
955
-                if (self::$_template_pack_collection->get_by_name($template) instanceof EE_Messages_Template_Pack) {
956
-                    continue;
957
-                }
958
-            }
959
-
960
-            // setup classname.
961
-            $template_pack_class_name = 'EE_Messages_Template_Pack_' . str_replace(
962
-                ' ',
963
-                '_',
964
-                ucwords(
965
-                    str_replace(
966
-                        '_',
967
-                        ' ',
968
-                        $template
969
-                    )
970
-                )
971
-            );
972
-            if (! class_exists($template_pack_class_name)) {
973
-                continue;
974
-            }
975
-            self::$_template_pack_collection->add(new $template_pack_class_name);
976
-        }
977
-
978
-        /**
979
-         * Filter for plugins to add in any additional template packs
980
-         * Note the filter name here is for backward compat, this used to be found in EED_Messages.
981
-         */
982
-        $additional_template_packs = apply_filters('FHEE__EED_Messages__get_template_packs__template_packs', array());
983
-        foreach ((array) $additional_template_packs as $template_pack) {
984
-            if (self::$_template_pack_collection->get_by_name(
985
-                $template_pack->dbref
986
-            ) instanceof EE_Messages_Template_Pack
987
-            ) {
988
-                continue;
989
-            }
990
-            self::$_template_pack_collection->add($template_pack);
991
-        }
992
-        return self::$_template_pack_collection;
993
-    }
994
-
995
-
996
-
997
-    /**
998
-     * This is a wrapper for the protected _create_new_templates function
999
-     *
1000
-     * @param string $messenger_name
1001
-     * @param string $message_type_name message type that the templates are being created for
1002
-     * @param int    $GRP_ID
1003
-     * @param bool   $global
1004
-     * @return array
1005
-     * @throws \EE_Error
1006
-     */
1007
-    public static function create_new_templates($messenger_name, $message_type_name, $GRP_ID = 0, $global = false)
1008
-    {
1009
-        /** @type EE_Message_Resource_Manager $Message_Resource_Manager */
1010
-        $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
1011
-        $messenger = $Message_Resource_Manager->valid_messenger($messenger_name);
1012
-        $message_type = $Message_Resource_Manager->valid_message_type($message_type_name);
1013
-        if (! EEH_MSG_Template::message_type_has_active_templates_for_messenger($messenger, $message_type, $global)) {
1014
-            return array();
1015
-        }
1016
-        // whew made it this far!  Okay, let's go ahead and create the templates then
1017
-        return EEH_MSG_Template::_create_new_templates($messenger, $message_type, $GRP_ID, $global);
1018
-    }
1019
-
1020
-
1021
-
1022
-    /**
1023
-     * @param \EE_messenger    $messenger
1024
-     * @param \EE_message_type $message_type
1025
-     * @param                  $GRP_ID
1026
-     * @param                  $global
1027
-     * @return array|mixed
1028
-     */
1029
-    protected static function _create_new_templates(EE_messenger $messenger, EE_message_type $message_type, $GRP_ID, $global)
1030
-    {
1031
-        // if we're creating a custom template then we don't need to use the defaults class
1032
-        if (! $global) {
1033
-            return EEH_MSG_Template::_create_custom_template_group($messenger, $message_type, $GRP_ID);
1034
-        }
1035
-        /** @type EE_Messages_Template_Defaults $Message_Template_Defaults */
1036
-        $Message_Template_Defaults = EE_Registry::factory(
1037
-            'EE_Messages_Template_Defaults',
1038
-            array( $messenger, $message_type, $GRP_ID )
1039
-        );
1040
-        // generate templates
1041
-        $success = $Message_Template_Defaults->create_new_templates();
1042
-
1043
-        // if creating the template failed.  Then we should deactivate the related message_type for the messenger because
1044
-        // its not active if it doesn't have a template.  Note this is only happening for GLOBAL template creation
1045
-        // attempts.
1046
-        if (! $success) {
1047
-            /** @var EE_Message_Resource_Manager $message_resource_manager */
1048
-            $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
1049
-            $message_resource_manager->deactivate_message_type_for_messenger($message_type->name, $messenger->name);
1050
-        }
1051
-
1052
-        /**
1053
-         * $success is in an array in the following format
1054
-         * array(
1055
-         *    'GRP_ID' => $new_grp_id,
1056
-         *    'MTP_context' => $first_context_in_new_templates,
1057
-         * )
1058
-         */
1059
-        return $success;
1060
-    }
1061
-
1062
-
1063
-
1064
-    /**
1065
-     * This creates a custom template using the incoming GRP_ID
1066
-     *
1067
-     * @param \EE_messenger    $messenger
1068
-     * @param \EE_message_type $message_type
1069
-     * @param  int             $GRP_ID      GRP_ID for the template_group being used as the base
1070
-     * @return  array $success              This will be an array in the format:
1071
-     *                                      array(
1072
-     *                                          'GRP_ID' => $new_grp_id,
1073
-     *                                          'MTP_context' => $first_context_in_created_template
1074
-     *                                      )
1075
-     * @access private
1076
-     */
1077
-    private static function _create_custom_template_group(EE_messenger $messenger, EE_message_type $message_type, $GRP_ID)
1078
-    {
1079
-        // defaults
1080
-        $success = array( 'GRP_ID' => null, 'MTP_context' => '' );
1081
-        // get the template group to use as a template from the db.  If $GRP_ID is empty then we'll assume the base will be the global template matching the messenger and message type.
1082
-        $Message_Template_Group = empty($GRP_ID)
1083
-            ? EEM_Message_Template_Group::instance()->get_one(
1084
-                array(
1085
-                    array(
1086
-                        'MTP_messenger'    => $messenger->name,
1087
-                        'MTP_message_type' => $message_type->name,
1088
-                        'MTP_is_global'    => true
1089
-                    )
1090
-                )
1091
-            )
1092
-            : EEM_Message_Template_Group::instance()->get_one_by_ID($GRP_ID);
1093
-        // if we don't have a mtg at this point then we need to bail.
1094
-        if (! $Message_Template_Group instanceof EE_Message_Template_Group) {
1095
-            EE_Error::add_error(
1096
-                sprintf(
1097
-                    __(
1098
-                        'Something went wrong with generating the custom template from this group id: %s.  This usually happens when there is no matching message template group in the db.',
1099
-                        'event_espresso'
1100
-                    ),
1101
-                    $GRP_ID
1102
-                ),
1103
-                __FILE__,
1104
-                __FUNCTION__,
1105
-                __LINE__
1106
-            );
1107
-            return $success;
1108
-        }
1109
-        // let's get all the related message_template objects for this group.
1110
-        $message_templates = $Message_Template_Group->message_templates();
1111
-        // now we have what we need to setup the new template
1112
-        $new_mtg = clone $Message_Template_Group;
1113
-        $new_mtg->set('GRP_ID', 0);
1114
-        $new_mtg->set('MTP_is_global', false);
1115
-        $template_name = defined('DOING_AJAX') && ! empty($_POST['templateName'])
1116
-            ? $_POST['templateName']
1117
-            : __(
1118
-                'New Custom Template',
1119
-                'event_espresso'
1120
-            );
1121
-        $template_description = defined("DOING_AJAX") && ! empty($_POST['templateDescription'])
1122
-            ? $_POST['templateDescription']
1123
-            : sprintf(
1124
-                __(
1125
-                    'This is a custom template that was created for the %s messenger and %s message type.',
1126
-                    'event_espresso'
1127
-                ),
1128
-                $new_mtg->messenger_obj()->label['singular'],
1129
-                $new_mtg->message_type_obj()->label['singular']
1130
-            );
1131
-        $new_mtg->set('MTP_name', $template_name);
1132
-        $new_mtg->set('MTP_description', $template_description);
1133
-        // remove ALL relations on this template group so they don't get saved!
1134
-        $new_mtg->_remove_relations('Message_Template');
1135
-        $new_mtg->save();
1136
-        $success['GRP_ID'] = $new_mtg->ID();
1137
-        $success['template_name'] = $template_name;
1138
-        // add new message templates and add relation to.
1139
-        foreach ($message_templates as $message_template) {
1140
-            if (! $message_template instanceof EE_Message_Template) {
1141
-                continue;
1142
-            }
1143
-            $new_message_template = clone $message_template;
1144
-            $new_message_template->set('MTP_ID', 0);
1145
-            $new_message_template->set('GRP_ID', $new_mtg->ID()); // relation
1146
-            $new_message_template->save();
1147
-            if (empty($success['MTP_context'])) {
1148
-                $success['MTP_context'] = $new_message_template->get('MTP_context');
1149
-            }
1150
-        }
1151
-        return $success;
1152
-    }
1153
-
1154
-
1155
-
1156
-    /**
1157
-     * message_type_has_active_templates_for_messenger
1158
-     *
1159
-     * @param \EE_messenger    $messenger
1160
-     * @param \EE_message_type $message_type
1161
-     * @param bool             $global
1162
-     * @return bool
1163
-     */
1164
-    public static function message_type_has_active_templates_for_messenger(
1165
-        EE_messenger $messenger,
1166
-        EE_message_type $message_type,
1167
-        $global = false
1168
-    ) {
1169
-        // is given message_type valid for given messenger (if this is not a global save)
1170
-        if ($global) {
1171
-            return true;
1172
-        }
1173
-        $active_templates = EEM_Message_Template_Group::instance()->count(
1174
-            array(
1175
-                array(
1176
-                    'MTP_is_active'    => true,
1177
-                    'MTP_messenger'    => $messenger->name,
1178
-                    'MTP_message_type' => $message_type->name
1179
-                )
1180
-            )
1181
-        );
1182
-        if ($active_templates > 0) {
1183
-            return true;
1184
-        }
1185
-        EE_Error::add_error(
1186
-            sprintf(
1187
-                __(
1188
-                    'The %1$s message type is not registered with the %2$s messenger. Please visit the Messenger activation page to assign this message type first if you want to use it.',
1189
-                    'event_espresso'
1190
-                ),
1191
-                $message_type->name,
1192
-                $messenger->name
1193
-            ),
1194
-            __FILE__,
1195
-            __FUNCTION__,
1196
-            __LINE__
1197
-        );
1198
-        return false;
1199
-    }
1200
-
1201
-
1202
-
1203
-    /**
1204
-     * get_fields
1205
-     * This takes a given messenger and message type and returns all the template fields indexed by context (and with field type).
1206
-     *
1207
-     * @param  string $messenger_name    name of EE_messenger
1208
-     * @param  string $message_type_name name of EE_message_type
1209
-     * @return array
1210
-     */
1211
-    public static function get_fields($messenger_name, $message_type_name)
1212
-    {
1213
-        $template_fields = array();
1214
-        /** @type EE_Message_Resource_Manager $Message_Resource_Manager */
1215
-        $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
1216
-        $messenger = $Message_Resource_Manager->valid_messenger($messenger_name);
1217
-        $message_type = $Message_Resource_Manager->valid_message_type($message_type_name);
1218
-        if (! EEH_MSG_Template::message_type_has_active_templates_for_messenger($messenger, $message_type)) {
1219
-            return array();
1220
-        }
1221
-
1222
-        $excluded_fields_for_messenger = $message_type->excludedFieldsForMessenger($messenger_name);
1223
-
1224
-        // okay now let's assemble an array with the messenger template fields added to the message_type contexts.
1225
-        foreach ($message_type->get_contexts() as $context => $details) {
1226
-            foreach ($messenger->get_template_fields() as $field => $value) {
1227
-                if (in_array($field, $excluded_fields_for_messenger, true)) {
1228
-                    continue;
1229
-                }
1230
-                $template_fields[ $context ][ $field ] = $value;
1231
-            }
1232
-        }
1233
-        if (empty($template_fields)) {
1234
-            EE_Error::add_error(
1235
-                __('Something went wrong and we couldn\'t get any templates assembled', 'event_espresso'),
1236
-                __FILE__,
1237
-                __FUNCTION__,
1238
-                __LINE__
1239
-            );
1240
-            return array();
1241
-        }
1242
-        return $template_fields;
1243
-    }
17
+	/**
18
+	 * Holds a collection of EE_Message_Template_Pack objects.
19
+	 * @type EE_Messages_Template_Pack_Collection
20
+	 */
21
+	protected static $_template_pack_collection;
22
+
23
+
24
+
25
+
26
+	private static function _set_autoloader()
27
+	{
28
+		EED_Messages::set_autoloaders();
29
+	}
30
+
31
+
32
+	/**
33
+	 * generate_new_templates
34
+	 * This will handle the messenger, message_type selection when "adding a new custom template" for an event and will automatically create the defaults for the event.  The user would then be redirected to edit the default context for the event.
35
+	 *
36
+	 * @access protected
37
+	 * @param  string $messenger     the messenger we are generating templates for
38
+	 * @param array   $message_types array of message types that the templates are generated for.
39
+	 * @param int     $GRP_ID        If a non global template is being generated then it is expected we'll have a GRP_ID to use as the base for the new generated template.
40
+	 * @param bool    $global        true indicates generating templates on messenger activation. false requires GRP_ID for event specific template generation.
41
+	 * @throws \EE_Error
42
+	 * @return array  @see EEH_MSG_Template::_create_new_templates for the return value of each element in the array for templates
43
+	 *                that are generated.  If this is an empty array then it means no templates were generated which usually
44
+	 *                means there was an error.  Anything in the array with an empty value for `MTP_context` means that it
45
+	 *                was not a new generated template but just reactivated (which only happens for global templates that
46
+	 *                already exist in the database.
47
+	 */
48
+	public static function generate_new_templates($messenger, $message_types, $GRP_ID = 0, $global = false)
49
+	{
50
+		// make sure message_type is an array.
51
+		$message_types = (array) $message_types;
52
+		$templates = array();
53
+
54
+		if (empty($messenger)) {
55
+			throw new EE_Error(__('We need a messenger to generate templates!', 'event_espresso'));
56
+		}
57
+
58
+		// if we STILL have empty $message_types then we need to generate an error message b/c we NEED message types to do the template files.
59
+		if (empty($message_types)) {
60
+			throw new EE_Error(__('We need at least one message type to generate templates!', 'event_espresso'));
61
+		}
62
+
63
+		EEH_MSG_Template::_set_autoloader();
64
+		foreach ($message_types as $message_type) {
65
+			// if global then let's attempt to get the GRP_ID for this combo IF GRP_ID is empty.
66
+			if ($global && empty($GRP_ID)) {
67
+				$GRP_ID = EEM_Message_Template_Group::instance()->get_one(
68
+					array(
69
+						array(
70
+							'MTP_messenger'    => $messenger,
71
+							'MTP_message_type' => $message_type,
72
+							'MTP_is_global'    => true,
73
+						),
74
+					)
75
+				);
76
+				$GRP_ID = $GRP_ID instanceof EE_Message_Template_Group ? $GRP_ID->ID() : 0;
77
+			}
78
+			// if this is global template generation.
79
+			// First let's determine if we already HAVE global templates for this messenger and message_type combination.
80
+			//  If we do then NO generation!!
81
+			if ($global && EEH_MSG_Template::already_generated($messenger, $message_type, $GRP_ID)) {
82
+				$templates[] = array(
83
+					'GRP_ID' => $GRP_ID,
84
+					'MTP_context' => '',
85
+				);
86
+				// we already have generated templates for this so let's go to the next message type.
87
+				continue;
88
+			}
89
+			$new_message_template_group = EEH_MSG_Template::create_new_templates($messenger, $message_type, $GRP_ID, $global);
90
+
91
+			if (! $new_message_template_group) {
92
+				continue;
93
+			}
94
+			$templates[] = $new_message_template_group;
95
+		}
96
+
97
+		return $templates;
98
+	}
99
+
100
+
101
+	/**
102
+	 * The purpose of this method is to determine if there are already generated templates in the database for the given variables.
103
+	 * @param  string $messenger     messenger
104
+	 * @param  string $message_type message type
105
+	 * @param  int $GRP_ID        GRP ID ( if a custom template) (if not provided then we're just doing global template check)
106
+	 * @return bool                true = generated, false = hasn't been generated.
107
+	 */
108
+	public static function already_generated($messenger, $message_type, $GRP_ID = 0)
109
+	{
110
+		EEH_MSG_Template::_set_autoloader();
111
+		// what method we use depends on whether we have an GRP_ID or not
112
+		$count = empty($GRP_ID)
113
+			? EEM_Message_Template::instance()->count(
114
+				array(
115
+					array(
116
+						'Message_Template_Group.MTP_messenger'    => $messenger,
117
+						'Message_Template_Group.MTP_message_type' => $message_type,
118
+						'Message_Template_Group.MTP_is_global'    => true
119
+					)
120
+				)
121
+			)
122
+			: EEM_Message_Template::instance()->count(array( array( 'GRP_ID' => $GRP_ID ) ));
123
+
124
+		return $count > 0;
125
+	}
126
+
127
+
128
+
129
+
130
+	/**
131
+	 * Updates all message templates matching the incoming messengers and message types to active status.
132
+	 *
133
+	 * @static
134
+	 * @param  array  $messenger_names     Messenger slug
135
+	 * @param  array  $message_type_names  Message type slug
136
+	 * @return  int                         count of updated records.
137
+	 */
138
+	public static function update_to_active($messenger_names, $message_type_names)
139
+	{
140
+		$messenger_names = is_array($messenger_names) ? $messenger_names : array( $messenger_names );
141
+		$message_type_names = is_array($message_type_names) ? $message_type_names : array( $message_type_names );
142
+		return EEM_Message_Template_Group::instance()->update(
143
+			array( 'MTP_is_active' => 1 ),
144
+			array(
145
+				array(
146
+					'MTP_messenger'     => array( 'IN', $messenger_names ),
147
+					'MTP_message_type'  => array( 'IN', $message_type_names )
148
+				)
149
+			)
150
+		);
151
+	}
152
+
153
+
154
+
155
+	/**
156
+	 * Updates all message template groups matching the incoming arguments to inactive status.
157
+	 *
158
+	 * @static
159
+	 * @param array $messenger_names    The messenger slugs.
160
+	 *                              If empty then all templates matching the message types are marked inactive.
161
+	 *                              Otherwise only templates matching the messengers and message types.
162
+	 * @param array $message_type_names     The message type slugs.
163
+	 *                              If empty then all templates matching the messengers are marked inactive.
164
+	 *                              Otherwise only templates matching the messengers and message types.
165
+	 *
166
+	 * @return int  count of updated records.
167
+	 */
168
+	public static function update_to_inactive($messenger_names = array(), $message_type_names = array())
169
+	{
170
+		return EEM_Message_Template_Group::instance()->deactivate_message_template_groups_for(
171
+			$messenger_names,
172
+			$message_type_names
173
+		);
174
+	}
175
+
176
+
177
+	/**
178
+	 * The purpose of this function is to return all installed message objects
179
+	 * (messengers and message type regardless of whether they are ACTIVE or not)
180
+	 *
181
+	 * @deprecated 4.9.0
182
+	 * @static
183
+	 * @param string $type
184
+	 * @return array array consisting of installed messenger objects and installed message type objects.
185
+	 */
186
+	public static function get_installed_message_objects($type = 'all')
187
+	{
188
+		self::_set_autoloader();
189
+		$message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
190
+		return array(
191
+			'messenger' => $message_resource_manager->installed_messengers(),
192
+			'message_type' => $message_resource_manager->installed_message_types()
193
+		);
194
+	}
195
+
196
+
197
+	/**
198
+	 * This will return an array of shortcodes => labels from the
199
+	 * messenger and message_type objects associated with this
200
+	 * template.
201
+	 *
202
+	 * @since 4.3.0
203
+	 *
204
+	 * @param string $message_type
205
+	 * @param string $messenger
206
+	 * @param array  $fields    What fields we're returning valid shortcodes for.
207
+	 *                          If empty then we assume all fields are to be returned. Optional.
208
+	 * @param string $context   What context we're going to return shortcodes for. Optional.
209
+	 * @param bool $merged      If TRUE then we don't return shortcodes indexed by field,
210
+	 *                          but instead an array of the unique shortcodes for all the given ( or all) fields.
211
+	 *                          Optional.
212
+	 * @throws \EE_Error
213
+	 * @return mixed (array|bool) an array of shortcodes in the format
214
+	 *                                              array( '[shortcode] => 'label')
215
+	 *                                              OR
216
+	 *                                              FALSE if no shortcodes found.
217
+	 */
218
+	public static function get_shortcodes(
219
+		$message_type,
220
+		$messenger,
221
+		$fields = array(),
222
+		$context = 'admin',
223
+		$merged = false
224
+	) {
225
+		$messenger_name = str_replace(' ', '_', ucwords(str_replace('_', ' ', $messenger)));
226
+		$mt_name = str_replace(' ', '_', ucwords(str_replace('_', ' ', $message_type)));
227
+		/** @var EE_Message_Resource_Manager $message_resource_manager */
228
+		$message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
229
+		// convert slug to object
230
+		$messenger = $message_resource_manager->get_messenger($messenger);
231
+
232
+		// if messenger isn't a EE_messenger resource then bail.
233
+		if (! $messenger instanceof EE_messenger) {
234
+			return array();
235
+		}
236
+
237
+		// validate class for getting our list of shortcodes
238
+		$classname = 'EE_Messages_' . $messenger_name . '_' . $mt_name . '_Validator';
239
+		if (! class_exists($classname)) {
240
+			$msg[] = __('The Validator class was unable to load', 'event_espresso');
241
+			$msg[] = sprintf(
242
+				__('The class name compiled was %s. Please check and make sure the spelling and case is correct for the class name and that there is an autoloader in place for this class', 'event_espresso'),
243
+				$classname
244
+			);
245
+			throw new EE_Error(implode('||', $msg));
246
+		}
247
+
248
+		/** @type EE_Messages_Validator $_VLD */
249
+		$_VLD = new $classname(array(), $context);
250
+		$valid_shortcodes = $_VLD->get_validators();
251
+
252
+		// let's make sure we're only getting the shortcode part of the validators
253
+		$shortcodes = array();
254
+		foreach ($valid_shortcodes as $field => $validators) {
255
+			$shortcodes[ $field ] = $validators['shortcodes'];
256
+		}
257
+		$valid_shortcodes = $shortcodes;
258
+
259
+		// if not all fields let's make sure we ONLY include the shortcodes for the specified fields.
260
+		if (! empty($fields)) {
261
+			$specified_shortcodes = array();
262
+			foreach ($fields as $field) {
263
+				if (isset($valid_shortcodes[ $field ])) {
264
+					$specified_shortcodes[ $field ] = $valid_shortcodes[ $field ];
265
+				}
266
+			}
267
+			$valid_shortcodes = $specified_shortcodes;
268
+		}
269
+
270
+		// if not merged then let's replace the fields with the localized fields
271
+		if (! $merged) {
272
+			// let's get all the fields for the set messenger so that we can get the localized label and use that in the returned array.
273
+			$field_settings = $messenger->get_template_fields();
274
+			$localized = array();
275
+			foreach ($valid_shortcodes as $field => $shortcodes) {
276
+				// get localized field label
277
+				if (isset($field_settings[ $field ])) {
278
+					// possible that this is used as a main field.
279
+					if (empty($field_settings[ $field ])) {
280
+						if (isset($field_settings['extra'][ $field ])) {
281
+							$_field = $field_settings['extra'][ $field ]['main']['label'];
282
+						} else {
283
+							$_field = $field;
284
+						}
285
+					} else {
286
+						$_field = $field_settings[ $field ]['label'];
287
+					}
288
+				} elseif (isset($field_settings['extra'])) {
289
+					// loop through extra "main fields" and see if any of their children have our field
290
+					foreach ($field_settings['extra'] as $main_field => $fields) {
291
+						if (isset($fields[ $field ])) {
292
+							$_field = $fields[ $field ]['label'];
293
+						} else {
294
+							$_field = $field;
295
+						}
296
+					}
297
+				} else {
298
+					$_field = $field;
299
+				}
300
+				if (isset($_field)) {
301
+					$localized[ (string) $_field ] = $shortcodes;
302
+				}
303
+			}
304
+			$valid_shortcodes = $localized;
305
+		}
306
+
307
+		// if $merged then let's merge all the shortcodes into one list NOT indexed by field.
308
+		if ($merged) {
309
+			$merged_codes = array();
310
+			foreach ($valid_shortcodes as $field => $shortcode) {
311
+				foreach ($shortcode as $code => $label) {
312
+					if (isset($merged_codes[ $code ])) {
313
+						continue;
314
+					} else {
315
+						$merged_codes[ $code ] = $label;
316
+					}
317
+				}
318
+			}
319
+			$valid_shortcodes = $merged_codes;
320
+		}
321
+
322
+		return $valid_shortcodes;
323
+	}
324
+
325
+
326
+	/**
327
+	 * Get Messenger object.
328
+	 *
329
+	 * @since 4.3.0
330
+	 * @deprecated 4.9.0
331
+	 * @param string $messenger messenger slug for the messenger object we want to retrieve.
332
+	 * @throws \EE_Error
333
+	 * @return EE_messenger
334
+	 */
335
+	public static function messenger_obj($messenger)
336
+	{
337
+		/** @type EE_Message_Resource_Manager $Message_Resource_Manager */
338
+		$Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
339
+		return $Message_Resource_Manager->get_messenger($messenger);
340
+	}
341
+
342
+
343
+	/**
344
+	 * get Message type object
345
+	 *
346
+	 * @since 4.3.0
347
+	 * @deprecated 4.9.0
348
+	 * @param string $message_type the slug for the message type object to retrieve
349
+	 * @throws \EE_Error
350
+	 * @return EE_message_type
351
+	 */
352
+	public static function message_type_obj($message_type)
353
+	{
354
+		/** @type EE_Message_Resource_Manager $Message_Resource_Manager */
355
+		$Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
356
+		return $Message_Resource_Manager->get_message_type($message_type);
357
+	}
358
+
359
+
360
+
361
+
362
+
363
+	/**
364
+	 * Given a message_type slug, will return whether that message type is active in the system or not.
365
+	 *
366
+	 * @since    4.3.0
367
+	 * @param  string   $message_type message type to check for.
368
+	 * @return boolean
369
+	 */
370
+	public static function is_mt_active($message_type)
371
+	{
372
+		/** @type EE_Message_Resource_Manager $Message_Resource_Manager */
373
+		$Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
374
+		$active_mts = $Message_Resource_Manager->list_of_active_message_types();
375
+		return in_array($message_type, $active_mts);
376
+	}
377
+
378
+
379
+
380
+	/**
381
+	 * Given a messenger slug, will return whether that messenger is active in the system or not.
382
+	 *
383
+	 * @since    4.3.0
384
+	 *
385
+	 * @param  string  $messenger slug for messenger to check.
386
+	 * @return boolean
387
+	 */
388
+	public static function is_messenger_active($messenger)
389
+	{
390
+		/** @type EE_Message_Resource_Manager $Message_Resource_Manager */
391
+		$Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
392
+		$active_messenger = $Message_Resource_Manager->get_active_messenger($messenger);
393
+		return $active_messenger instanceof EE_messenger ? true : false;
394
+	}
395
+
396
+
397
+
398
+	/**
399
+	 * Used to return active messengers array stored in the wp options table.
400
+	 * If no value is present in the option then an empty array is returned.
401
+	 *
402
+	 * @deprecated 4.9
403
+	 * @since 4.3.1
404
+	 *
405
+	 * @return array
406
+	 */
407
+	public static function get_active_messengers_in_db()
408
+	{
409
+		EE_Error::doing_it_wrong(
410
+			__METHOD__,
411
+			__('Please use EE_Message_Resource_Manager::get_active_messengers_option() instead.', 'event_espresso'),
412
+			'4.9.0'
413
+		);
414
+		/** @var EE_Message_Resource_Manager $Message_Resource_Manager */
415
+		$Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
416
+		return $Message_Resource_Manager->get_active_messengers_option();
417
+	}
418
+
419
+
420
+
421
+
422
+	/**
423
+	 * Used to update the active messengers array stored in the wp options table.
424
+	 *
425
+	 * @since 4.3.1
426
+	 * @deprecated 4.9.0
427
+	 *
428
+	 * @param array $data_to_save Incoming data to save.
429
+	 *
430
+	 * @return bool FALSE if not updated, TRUE if updated.
431
+	 */
432
+	public static function update_active_messengers_in_db($data_to_save)
433
+	{
434
+		EE_Error::doing_it_wrong(
435
+			__METHOD__,
436
+			__('Please use EE_Message_Resource_Manager::update_active_messengers_option() instead.', 'event_espresso'),
437
+			'4.9.0'
438
+		);
439
+		/** @var EE_Message_Resource_Manager $Message_Resource_Manager */
440
+		$Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
441
+		return $Message_Resource_Manager->update_active_messengers_option($data_to_save);
442
+	}
443
+
444
+
445
+	/**
446
+	 * This does some validation of incoming params, determines what type of url is being prepped and returns the
447
+	 * appropriate url trigger
448
+	 *
449
+	 * @param EE_message_type $message_type
450
+	 * @param EE_Message $message
451
+	 * @param EE_Registration | null $registration  The registration object must be included if this
452
+	 *                                              is going to be a registration trigger url.
453
+	 * @param string $sending_messenger             The (optional) sending messenger for the url.
454
+	 *
455
+	 * @return string
456
+	 * @throws EE_Error
457
+	 */
458
+	public static function get_url_trigger(
459
+		EE_message_type $message_type,
460
+		EE_Message $message,
461
+		$registration = null,
462
+		$sending_messenger = ''
463
+	) {
464
+		// first determine if the url can be to the EE_Message object.
465
+		if (! $message_type->always_generate()) {
466
+			return EEH_MSG_Template::generate_browser_trigger($message);
467
+		}
468
+
469
+		// if $registration object is not valid then exit early because there's nothing that can be generated.
470
+		if (! $registration instanceof EE_Registration) {
471
+			throw new EE_Error(
472
+				__('Incoming value for registration is not a valid EE_Registration object.', 'event_espresso')
473
+			);
474
+		}
475
+
476
+		// validate given context
477
+		$contexts = $message_type->get_contexts();
478
+		if ($message->context() !== '' && ! isset($contexts[ $message->context() ])) {
479
+			throw new EE_Error(
480
+				sprintf(
481
+					__('The context %s is not a valid context for %s.', 'event_espresso'),
482
+					$message->context(),
483
+					get_class($message_type)
484
+				)
485
+			);
486
+		}
487
+
488
+		// valid sending messenger but only if sending messenger set.  Otherwise generating messenger is used.
489
+		if (! empty($sending_messenger)) {
490
+			$with_messengers = $message_type->with_messengers();
491
+			if (! isset($with_messengers[ $message->messenger() ])
492
+				 || ! in_array($sending_messenger, $with_messengers[ $message->messenger() ]) ) {
493
+				throw new EE_Error(
494
+					sprintf(
495
+						__(
496
+							'The given sending messenger string (%1$s) does not match a valid sending messenger with the %2$s.  If this is incorrect, make sure that the message type has defined this messenger as a sending messenger in its $_with_messengers array.',
497
+							'event_espresso'
498
+						),
499
+						$sending_messenger,
500
+						get_class($message_type)
501
+					)
502
+				);
503
+			}
504
+		} else {
505
+			$sending_messenger = $message->messenger();
506
+		}
507
+		return EEH_MSG_Template::generate_url_trigger(
508
+			$sending_messenger,
509
+			$message->messenger(),
510
+			$message->context(),
511
+			$message->message_type(),
512
+			$registration,
513
+			$message->GRP_ID()
514
+		);
515
+	}
516
+
517
+
518
+	/**
519
+	 * This returns the url for triggering a in browser view of a specific EE_Message object.
520
+	 * @param EE_Message $message
521
+	 * @return string.
522
+	 */
523
+	public static function generate_browser_trigger(EE_Message $message)
524
+	{
525
+		$query_args = array(
526
+			'ee' => 'msg_browser_trigger',
527
+			'token' => $message->MSG_token()
528
+		);
529
+		return apply_filters(
530
+			'FHEE__EEH_MSG_Template__generate_browser_trigger',
531
+			add_query_arg($query_args, site_url()),
532
+			$message
533
+		);
534
+	}
535
+
536
+
537
+
538
+
539
+
540
+
541
+	/**
542
+	 * This returns the url for triggering an in browser view of the error saved on the incoming message object.
543
+	 * @param EE_Message $message
544
+	 * @return string
545
+	 */
546
+	public static function generate_error_display_trigger(EE_Message $message)
547
+	{
548
+		return apply_filters(
549
+			'FHEE__EEH_MSG_Template__generate_error_display_trigger',
550
+			add_query_arg(
551
+				array(
552
+					'ee' => 'msg_browser_error_trigger',
553
+					'token' => $message->MSG_token()
554
+				),
555
+				site_url()
556
+			),
557
+			$message
558
+		);
559
+	}
560
+
561
+
562
+
563
+
564
+
565
+
566
+	/**
567
+	 * This generates a url trigger for the msg_url_trigger route using the given arguments
568
+	 *
569
+	 * @param string          $sending_messenger    The sending messenger slug.
570
+	 * @param string          $generating_messenger The generating messenger slug.
571
+	 * @param string          $context              The context for the template.
572
+	 * @param string          $message_type         The message type slug
573
+	 * @param EE_Registration $registration
574
+	 * @param integer          $message_template_group id   The EE_Message_Template_Group ID for the template.
575
+	 * @param integer          $data_id     The id to the EE_Base_Class for getting the data used by the trigger.
576
+	 * @return string          The generated url.
577
+	 */
578
+	public static function generate_url_trigger(
579
+		$sending_messenger,
580
+		$generating_messenger,
581
+		$context,
582
+		$message_type,
583
+		EE_Registration $registration,
584
+		$message_template_group,
585
+		$data_id = 0
586
+	) {
587
+		$query_args = array(
588
+			'ee' => 'msg_url_trigger',
589
+			'snd_msgr' => $sending_messenger,
590
+			'gen_msgr' => $generating_messenger,
591
+			'message_type' => $message_type,
592
+			'context' => $context,
593
+			'token' => $registration->reg_url_link(),
594
+			'GRP_ID' => $message_template_group,
595
+			'id' => $data_id
596
+			);
597
+		$url = add_query_arg($query_args, get_home_url());
598
+
599
+		// made it here so now we can just get the url and filter it.  Filtered globally and by message type.
600
+		$url = apply_filters(
601
+			'FHEE__EEH_MSG_Template__generate_url_trigger',
602
+			$url,
603
+			$sending_messenger,
604
+			$generating_messenger,
605
+			$context,
606
+			$message_type,
607
+			$registration,
608
+			$message_template_group,
609
+			$data_id
610
+		);
611
+		return $url;
612
+	}
613
+
614
+
615
+
616
+
617
+	/**
618
+	 * Return the specific css for the action icon given.
619
+	 *
620
+	 * @since 4.9.0
621
+	 *
622
+	 * @param string $type  What action to return.
623
+	 * @return string
624
+	 */
625
+	public static function get_message_action_icon($type)
626
+	{
627
+		$action_icons = self::get_message_action_icons();
628
+		return isset($action_icons[ $type ]) ? $action_icons[ $type ] : '';
629
+	}
630
+
631
+
632
+	/**
633
+	 * This is used for retrieving the css classes used for the icons representing message actions.
634
+	 *
635
+	 * @since 4.9.0
636
+	 *
637
+	 * @return array
638
+	 */
639
+	public static function get_message_action_icons()
640
+	{
641
+		return apply_filters(
642
+			'FHEE__EEH_MSG_Template__message_action_icons',
643
+			array(
644
+				'view' => array(
645
+					'label' => __('View Message', 'event_espresso'),
646
+					'css_class' => 'dashicons dashicons-welcome-view-site',
647
+				),
648
+				'error' => array(
649
+					'label' => __('View Error Message', 'event_espresso'),
650
+					'css_class' => 'dashicons dashicons-info',
651
+				),
652
+				'see_notifications_for' => array(
653
+					'label' => __('View Related Messages', 'event_espresso'),
654
+					'css_class' => 'dashicons dashicons-megaphone',
655
+				),
656
+				'generate_now' => array(
657
+					'label' => __('Generate the message now.', 'event_espresso'),
658
+					'css_class' => 'dashicons dashicons-admin-tools',
659
+				),
660
+				'send_now' => array(
661
+					'label' => __('Send Immediately', 'event_espresso'),
662
+					'css_class' => 'dashicons dashicons-controls-forward',
663
+				),
664
+				'queue_for_resending' => array(
665
+					'label' => __('Queue for Resending', 'event_espresso'),
666
+					'css_class' => 'dashicons dashicons-controls-repeat',
667
+				),
668
+				'view_transaction' => array(
669
+					'label' => __('View related Transaction', 'event_espresso'),
670
+					'css_class' => 'dashicons dashicons-cart',
671
+				)
672
+			)
673
+		);
674
+	}
675
+
676
+
677
+	/**
678
+	 * This returns the url for a given action related to EE_Message.
679
+	 *
680
+	 * @since 4.9.0
681
+	 *
682
+	 * @param string $type  What type of action to return the url for.
683
+	 * @param EE_Message $message   Required for generating the correct url for some types.
684
+	 * @param array  $query_params   Any additional query params to be included with the generated url.
685
+	 *
686
+	 * @return string
687
+	 */
688
+	public static function get_message_action_url($type, EE_Message $message = null, $query_params = array())
689
+	{
690
+		$action_urls = self::get_message_action_urls($message, $query_params);
691
+		return isset($action_urls[ $type ])  ? $action_urls[ $type ] : '';
692
+	}
693
+
694
+
695
+
696
+	/**
697
+	 * This returns all the current urls for EE_Message actions.
698
+	 *
699
+	 * @since 4.9.0
700
+	 *
701
+	 * @param  EE_Message   $message    The EE_Message object required to generate correct urls for some types.
702
+	 * @param  array    $query_params   Any additional query_params to be included with the generated url.
703
+	 *
704
+	 * @return array
705
+	 */
706
+	public static function get_message_action_urls(EE_Message $message = null, $query_params = array())
707
+	{
708
+		EE_Registry::instance()->load_helper('URL');
709
+		// if $message is not an instance of EE_Message then let's just do a dummy.
710
+		$message = empty($message) ? EE_Message_Factory::create() : $message;
711
+		$action_urls =  apply_filters(
712
+			'FHEE__EEH_MSG_Template__get_message_action_url',
713
+			array(
714
+				'view' => EEH_MSG_Template::generate_browser_trigger($message),
715
+				'error' => EEH_MSG_Template::generate_error_display_trigger($message),
716
+				'see_notifications_for' => EEH_URL::add_query_args_and_nonce(
717
+					array_merge(
718
+						array(
719
+							'page' => 'espresso_messages',
720
+							'action' => 'default',
721
+							'filterby' => 1,
722
+						),
723
+						$query_params
724
+					),
725
+					admin_url('admin.php')
726
+				),
727
+				'generate_now' => EEH_URL::add_query_args_and_nonce(
728
+					array(
729
+						'page' => 'espresso_messages',
730
+						'action' => 'generate_now',
731
+						'MSG_ID' => $message->ID()
732
+					),
733
+					admin_url('admin.php')
734
+				),
735
+				'send_now' => EEH_URL::add_query_args_and_nonce(
736
+					array(
737
+						'page' => 'espresso_messages',
738
+						'action' => 'send_now',
739
+						'MSG_ID' => $message->ID()
740
+					),
741
+					admin_url('admin.php')
742
+				),
743
+				'queue_for_resending' => EEH_URL::add_query_args_and_nonce(
744
+					array(
745
+						'page' => 'espresso_messages',
746
+						'action' => 'queue_for_resending',
747
+						'MSG_ID' => $message->ID()
748
+					),
749
+					admin_url('admin.php')
750
+				),
751
+			)
752
+		);
753
+		if ($message->TXN_ID() > 0
754
+			&& EE_Registry::instance()->CAP->current_user_can(
755
+				'ee_read_transaction',
756
+				'espresso_transactions_default',
757
+				$message->TXN_ID()
758
+			)
759
+		) {
760
+			$action_urls['view_transaction'] = EEH_URL::add_query_args_and_nonce(
761
+				array(
762
+					'page' => 'espresso_transactions',
763
+					'action' => 'view_transaction',
764
+					'TXN_ID' => $message->TXN_ID()
765
+				),
766
+				admin_url('admin.php')
767
+			);
768
+		} else {
769
+			$action_urls['view_transaction'] = '';
770
+		}
771
+		return $action_urls;
772
+	}
773
+
774
+
775
+	/**
776
+	 * This returns a generated link html including the icon used for the action link for EE_Message actions.
777
+	 *
778
+	 * @since 4.9.0
779
+	 *
780
+	 * @param string $type What type of action the link is for (if invalid type is passed in then an
781
+	 *                     empty string is returned)
782
+	 * @param EE_Message|null $message  The EE_Message object (required for some actions to generate correctly)
783
+	 * @param array           $query_params Any extra query params to include in the generated link.
784
+	 *
785
+	 * @return string
786
+	 */
787
+	public static function get_message_action_link($type, EE_Message $message = null, $query_params = array())
788
+	{
789
+		$url = EEH_MSG_Template::get_message_action_url($type, $message, $query_params);
790
+		$icon_css = EEH_MSG_Template::get_message_action_icon($type);
791
+		$title = isset($icon_css['label']) ? 'title="' . $icon_css['label'] . '"' : '';
792
+
793
+		if (empty($url) || empty($icon_css) || ! isset($icon_css['css_class'])) {
794
+			return '';
795
+		}
796
+
797
+		$icon_css['css_class'] .= esc_attr(
798
+			apply_filters(
799
+				'FHEE__EEH_MSG_Template__get_message_action_link__icon_css_class',
800
+				' js-ee-message-action-link ee-message-action-link-' . $type,
801
+				$type,
802
+				$message,
803
+				$query_params
804
+			)
805
+		);
806
+
807
+		return '<a href="' . $url . '"' . $title . '><span class="' . esc_attr($icon_css['css_class']) . '"></span></a>';
808
+	}
809
+
810
+
811
+
812
+
813
+
814
+	/**
815
+	 * This returns an array with keys as reg statuses and values as the corresponding message type slug (filtered).
816
+	 *
817
+	 * @since 4.9.0
818
+	 * @return array
819
+	 */
820
+	public static function reg_status_to_message_type_array()
821
+	{
822
+		return (array) apply_filters(
823
+			'FHEE__EEH_MSG_Template__reg_status_to_message_type_array',
824
+			array(
825
+				EEM_Registration::status_id_approved => 'registration',
826
+				EEM_Registration::status_id_pending_payment => 'pending_approval',
827
+				EEM_Registration::status_id_not_approved => 'not_approved_registration',
828
+				EEM_Registration::status_id_cancelled => 'cancelled_registration',
829
+				EEM_Registration::status_id_declined => 'declined_registration'
830
+			)
831
+		);
832
+	}
833
+
834
+
835
+
836
+
837
+	/**
838
+	 * This returns the corresponding registration message type slug to the given reg status. If there isn't a
839
+	 * match, then returns an empty string.
840
+	 *
841
+	 * @since 4.9.0
842
+	 * @param $reg_status
843
+	 * @return string
844
+	 */
845
+	public static function convert_reg_status_to_message_type($reg_status)
846
+	{
847
+		$reg_status_array = self::reg_status_to_message_type_array();
848
+		return isset($reg_status_array[ $reg_status ]) ? $reg_status_array[ $reg_status ] : '';
849
+	}
850
+
851
+
852
+	/**
853
+	 * This returns an array with keys as payment stati and values as the corresponding message type slug (filtered).
854
+	 *
855
+	 * @since 4.9.0
856
+	 * @return array
857
+	 */
858
+	public static function payment_status_to_message_type_array()
859
+	{
860
+		return (array) apply_filters(
861
+			'FHEE__EEH_MSG_Template__payment_status_to_message_type_array',
862
+			array(
863
+				EEM_Payment::status_id_approved => 'payment',
864
+				EEM_Payment::status_id_pending => 'payment_pending',
865
+				EEM_Payment::status_id_cancelled => 'payment_cancelled',
866
+				EEM_Payment::status_id_declined => 'payment_declined',
867
+				EEM_Payment::status_id_failed => 'payment_failed'
868
+			)
869
+		);
870
+	}
871
+
872
+
873
+
874
+
875
+	/**
876
+	 * This returns the corresponding payment message type slug to the given payment status. If there isn't a match then
877
+	 * an empty string is returned
878
+	 *
879
+	 * @since 4.9.0
880
+	 * @param $payment_status
881
+	 * @return string
882
+	 */
883
+	public static function convert_payment_status_to_message_type($payment_status)
884
+	{
885
+		$payment_status_array = self::payment_status_to_message_type_array();
886
+		return isset($payment_status_array[ $payment_status ]) ? $payment_status_array[ $payment_status ] : '';
887
+	}
888
+
889
+
890
+	/**
891
+	 * This is used to retrieve the template pack for the given name.
892
+	 *
893
+	 * @param string $template_pack_name  should match the set `dbref` property value on the EE_Messages_Template_Pack.
894
+	 *
895
+	 * @return EE_Messages_Template_Pack
896
+	 */
897
+	public static function get_template_pack($template_pack_name)
898
+	{
899
+		if (! self::$_template_pack_collection instanceof EE_Object_Collection) {
900
+			self::$_template_pack_collection = new EE_Messages_Template_Pack_Collection();
901
+		}
902
+
903
+		// first see if in collection already
904
+		$template_pack = self::$_template_pack_collection->get_by_name($template_pack_name);
905
+
906
+		if ($template_pack instanceof EE_Messages_Template_Pack) {
907
+			return $template_pack;
908
+		}
909
+
910
+		// nope...let's get it.
911
+		// not set yet so let's attempt to get it.
912
+		$pack_class_name = 'EE_Messages_Template_Pack_' . str_replace(
913
+			' ',
914
+			'_',
915
+			ucwords(
916
+				str_replace('_', ' ', $template_pack_name)
917
+			)
918
+		);
919
+		if (! class_exists($pack_class_name) && $template_pack_name !== 'default') {
920
+			return self::get_template_pack('default');
921
+		} else {
922
+			$template_pack = new $pack_class_name;
923
+			self::$_template_pack_collection->add($template_pack);
924
+			return $template_pack;
925
+		}
926
+	}
927
+
928
+
929
+
930
+
931
+	/**
932
+	 * Globs template packs installed in core and returns the template pack collection with all installed template packs
933
+	 * in it.
934
+	 *
935
+	 * @since 4.9.0
936
+	 *
937
+	 * @return EE_Messages_Template_Pack_Collection
938
+	 */
939
+	public static function get_template_pack_collection()
940
+	{
941
+		$new_collection = false;
942
+		if (! self::$_template_pack_collection instanceof EE_Messages_Template_Pack_Collection) {
943
+			self::$_template_pack_collection = new EE_Messages_Template_Pack_Collection();
944
+			$new_collection = true;
945
+		}
946
+
947
+		// glob the defaults directory for messages
948
+		$templates = glob(EE_LIBRARIES . 'messages/defaults/*', GLOB_ONLYDIR);
949
+		foreach ($templates as $template_path) {
950
+			// grab folder name
951
+			$template = basename($template_path);
952
+
953
+			if (! $new_collection) {
954
+				// already have it?
955
+				if (self::$_template_pack_collection->get_by_name($template) instanceof EE_Messages_Template_Pack) {
956
+					continue;
957
+				}
958
+			}
959
+
960
+			// setup classname.
961
+			$template_pack_class_name = 'EE_Messages_Template_Pack_' . str_replace(
962
+				' ',
963
+				'_',
964
+				ucwords(
965
+					str_replace(
966
+						'_',
967
+						' ',
968
+						$template
969
+					)
970
+				)
971
+			);
972
+			if (! class_exists($template_pack_class_name)) {
973
+				continue;
974
+			}
975
+			self::$_template_pack_collection->add(new $template_pack_class_name);
976
+		}
977
+
978
+		/**
979
+		 * Filter for plugins to add in any additional template packs
980
+		 * Note the filter name here is for backward compat, this used to be found in EED_Messages.
981
+		 */
982
+		$additional_template_packs = apply_filters('FHEE__EED_Messages__get_template_packs__template_packs', array());
983
+		foreach ((array) $additional_template_packs as $template_pack) {
984
+			if (self::$_template_pack_collection->get_by_name(
985
+				$template_pack->dbref
986
+			) instanceof EE_Messages_Template_Pack
987
+			) {
988
+				continue;
989
+			}
990
+			self::$_template_pack_collection->add($template_pack);
991
+		}
992
+		return self::$_template_pack_collection;
993
+	}
994
+
995
+
996
+
997
+	/**
998
+	 * This is a wrapper for the protected _create_new_templates function
999
+	 *
1000
+	 * @param string $messenger_name
1001
+	 * @param string $message_type_name message type that the templates are being created for
1002
+	 * @param int    $GRP_ID
1003
+	 * @param bool   $global
1004
+	 * @return array
1005
+	 * @throws \EE_Error
1006
+	 */
1007
+	public static function create_new_templates($messenger_name, $message_type_name, $GRP_ID = 0, $global = false)
1008
+	{
1009
+		/** @type EE_Message_Resource_Manager $Message_Resource_Manager */
1010
+		$Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
1011
+		$messenger = $Message_Resource_Manager->valid_messenger($messenger_name);
1012
+		$message_type = $Message_Resource_Manager->valid_message_type($message_type_name);
1013
+		if (! EEH_MSG_Template::message_type_has_active_templates_for_messenger($messenger, $message_type, $global)) {
1014
+			return array();
1015
+		}
1016
+		// whew made it this far!  Okay, let's go ahead and create the templates then
1017
+		return EEH_MSG_Template::_create_new_templates($messenger, $message_type, $GRP_ID, $global);
1018
+	}
1019
+
1020
+
1021
+
1022
+	/**
1023
+	 * @param \EE_messenger    $messenger
1024
+	 * @param \EE_message_type $message_type
1025
+	 * @param                  $GRP_ID
1026
+	 * @param                  $global
1027
+	 * @return array|mixed
1028
+	 */
1029
+	protected static function _create_new_templates(EE_messenger $messenger, EE_message_type $message_type, $GRP_ID, $global)
1030
+	{
1031
+		// if we're creating a custom template then we don't need to use the defaults class
1032
+		if (! $global) {
1033
+			return EEH_MSG_Template::_create_custom_template_group($messenger, $message_type, $GRP_ID);
1034
+		}
1035
+		/** @type EE_Messages_Template_Defaults $Message_Template_Defaults */
1036
+		$Message_Template_Defaults = EE_Registry::factory(
1037
+			'EE_Messages_Template_Defaults',
1038
+			array( $messenger, $message_type, $GRP_ID )
1039
+		);
1040
+		// generate templates
1041
+		$success = $Message_Template_Defaults->create_new_templates();
1042
+
1043
+		// if creating the template failed.  Then we should deactivate the related message_type for the messenger because
1044
+		// its not active if it doesn't have a template.  Note this is only happening for GLOBAL template creation
1045
+		// attempts.
1046
+		if (! $success) {
1047
+			/** @var EE_Message_Resource_Manager $message_resource_manager */
1048
+			$message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
1049
+			$message_resource_manager->deactivate_message_type_for_messenger($message_type->name, $messenger->name);
1050
+		}
1051
+
1052
+		/**
1053
+		 * $success is in an array in the following format
1054
+		 * array(
1055
+		 *    'GRP_ID' => $new_grp_id,
1056
+		 *    'MTP_context' => $first_context_in_new_templates,
1057
+		 * )
1058
+		 */
1059
+		return $success;
1060
+	}
1061
+
1062
+
1063
+
1064
+	/**
1065
+	 * This creates a custom template using the incoming GRP_ID
1066
+	 *
1067
+	 * @param \EE_messenger    $messenger
1068
+	 * @param \EE_message_type $message_type
1069
+	 * @param  int             $GRP_ID      GRP_ID for the template_group being used as the base
1070
+	 * @return  array $success              This will be an array in the format:
1071
+	 *                                      array(
1072
+	 *                                          'GRP_ID' => $new_grp_id,
1073
+	 *                                          'MTP_context' => $first_context_in_created_template
1074
+	 *                                      )
1075
+	 * @access private
1076
+	 */
1077
+	private static function _create_custom_template_group(EE_messenger $messenger, EE_message_type $message_type, $GRP_ID)
1078
+	{
1079
+		// defaults
1080
+		$success = array( 'GRP_ID' => null, 'MTP_context' => '' );
1081
+		// get the template group to use as a template from the db.  If $GRP_ID is empty then we'll assume the base will be the global template matching the messenger and message type.
1082
+		$Message_Template_Group = empty($GRP_ID)
1083
+			? EEM_Message_Template_Group::instance()->get_one(
1084
+				array(
1085
+					array(
1086
+						'MTP_messenger'    => $messenger->name,
1087
+						'MTP_message_type' => $message_type->name,
1088
+						'MTP_is_global'    => true
1089
+					)
1090
+				)
1091
+			)
1092
+			: EEM_Message_Template_Group::instance()->get_one_by_ID($GRP_ID);
1093
+		// if we don't have a mtg at this point then we need to bail.
1094
+		if (! $Message_Template_Group instanceof EE_Message_Template_Group) {
1095
+			EE_Error::add_error(
1096
+				sprintf(
1097
+					__(
1098
+						'Something went wrong with generating the custom template from this group id: %s.  This usually happens when there is no matching message template group in the db.',
1099
+						'event_espresso'
1100
+					),
1101
+					$GRP_ID
1102
+				),
1103
+				__FILE__,
1104
+				__FUNCTION__,
1105
+				__LINE__
1106
+			);
1107
+			return $success;
1108
+		}
1109
+		// let's get all the related message_template objects for this group.
1110
+		$message_templates = $Message_Template_Group->message_templates();
1111
+		// now we have what we need to setup the new template
1112
+		$new_mtg = clone $Message_Template_Group;
1113
+		$new_mtg->set('GRP_ID', 0);
1114
+		$new_mtg->set('MTP_is_global', false);
1115
+		$template_name = defined('DOING_AJAX') && ! empty($_POST['templateName'])
1116
+			? $_POST['templateName']
1117
+			: __(
1118
+				'New Custom Template',
1119
+				'event_espresso'
1120
+			);
1121
+		$template_description = defined("DOING_AJAX") && ! empty($_POST['templateDescription'])
1122
+			? $_POST['templateDescription']
1123
+			: sprintf(
1124
+				__(
1125
+					'This is a custom template that was created for the %s messenger and %s message type.',
1126
+					'event_espresso'
1127
+				),
1128
+				$new_mtg->messenger_obj()->label['singular'],
1129
+				$new_mtg->message_type_obj()->label['singular']
1130
+			);
1131
+		$new_mtg->set('MTP_name', $template_name);
1132
+		$new_mtg->set('MTP_description', $template_description);
1133
+		// remove ALL relations on this template group so they don't get saved!
1134
+		$new_mtg->_remove_relations('Message_Template');
1135
+		$new_mtg->save();
1136
+		$success['GRP_ID'] = $new_mtg->ID();
1137
+		$success['template_name'] = $template_name;
1138
+		// add new message templates and add relation to.
1139
+		foreach ($message_templates as $message_template) {
1140
+			if (! $message_template instanceof EE_Message_Template) {
1141
+				continue;
1142
+			}
1143
+			$new_message_template = clone $message_template;
1144
+			$new_message_template->set('MTP_ID', 0);
1145
+			$new_message_template->set('GRP_ID', $new_mtg->ID()); // relation
1146
+			$new_message_template->save();
1147
+			if (empty($success['MTP_context'])) {
1148
+				$success['MTP_context'] = $new_message_template->get('MTP_context');
1149
+			}
1150
+		}
1151
+		return $success;
1152
+	}
1153
+
1154
+
1155
+
1156
+	/**
1157
+	 * message_type_has_active_templates_for_messenger
1158
+	 *
1159
+	 * @param \EE_messenger    $messenger
1160
+	 * @param \EE_message_type $message_type
1161
+	 * @param bool             $global
1162
+	 * @return bool
1163
+	 */
1164
+	public static function message_type_has_active_templates_for_messenger(
1165
+		EE_messenger $messenger,
1166
+		EE_message_type $message_type,
1167
+		$global = false
1168
+	) {
1169
+		// is given message_type valid for given messenger (if this is not a global save)
1170
+		if ($global) {
1171
+			return true;
1172
+		}
1173
+		$active_templates = EEM_Message_Template_Group::instance()->count(
1174
+			array(
1175
+				array(
1176
+					'MTP_is_active'    => true,
1177
+					'MTP_messenger'    => $messenger->name,
1178
+					'MTP_message_type' => $message_type->name
1179
+				)
1180
+			)
1181
+		);
1182
+		if ($active_templates > 0) {
1183
+			return true;
1184
+		}
1185
+		EE_Error::add_error(
1186
+			sprintf(
1187
+				__(
1188
+					'The %1$s message type is not registered with the %2$s messenger. Please visit the Messenger activation page to assign this message type first if you want to use it.',
1189
+					'event_espresso'
1190
+				),
1191
+				$message_type->name,
1192
+				$messenger->name
1193
+			),
1194
+			__FILE__,
1195
+			__FUNCTION__,
1196
+			__LINE__
1197
+		);
1198
+		return false;
1199
+	}
1200
+
1201
+
1202
+
1203
+	/**
1204
+	 * get_fields
1205
+	 * This takes a given messenger and message type and returns all the template fields indexed by context (and with field type).
1206
+	 *
1207
+	 * @param  string $messenger_name    name of EE_messenger
1208
+	 * @param  string $message_type_name name of EE_message_type
1209
+	 * @return array
1210
+	 */
1211
+	public static function get_fields($messenger_name, $message_type_name)
1212
+	{
1213
+		$template_fields = array();
1214
+		/** @type EE_Message_Resource_Manager $Message_Resource_Manager */
1215
+		$Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
1216
+		$messenger = $Message_Resource_Manager->valid_messenger($messenger_name);
1217
+		$message_type = $Message_Resource_Manager->valid_message_type($message_type_name);
1218
+		if (! EEH_MSG_Template::message_type_has_active_templates_for_messenger($messenger, $message_type)) {
1219
+			return array();
1220
+		}
1221
+
1222
+		$excluded_fields_for_messenger = $message_type->excludedFieldsForMessenger($messenger_name);
1223
+
1224
+		// okay now let's assemble an array with the messenger template fields added to the message_type contexts.
1225
+		foreach ($message_type->get_contexts() as $context => $details) {
1226
+			foreach ($messenger->get_template_fields() as $field => $value) {
1227
+				if (in_array($field, $excluded_fields_for_messenger, true)) {
1228
+					continue;
1229
+				}
1230
+				$template_fields[ $context ][ $field ] = $value;
1231
+			}
1232
+		}
1233
+		if (empty($template_fields)) {
1234
+			EE_Error::add_error(
1235
+				__('Something went wrong and we couldn\'t get any templates assembled', 'event_espresso'),
1236
+				__FILE__,
1237
+				__FUNCTION__,
1238
+				__LINE__
1239
+			);
1240
+			return array();
1241
+		}
1242
+		return $template_fields;
1243
+	}
1244 1244
 }
Please login to merge, or discard this patch.
Spacing   +56 added lines, -56 removed lines patch added patch discarded remove patch
@@ -88,7 +88,7 @@  discard block
 block discarded – undo
88 88
             }
89 89
             $new_message_template_group = EEH_MSG_Template::create_new_templates($messenger, $message_type, $GRP_ID, $global);
90 90
 
91
-            if (! $new_message_template_group) {
91
+            if ( ! $new_message_template_group) {
92 92
                 continue;
93 93
             }
94 94
             $templates[] = $new_message_template_group;
@@ -119,7 +119,7 @@  discard block
 block discarded – undo
119 119
                     )
120 120
                 )
121 121
             )
122
-            : EEM_Message_Template::instance()->count(array( array( 'GRP_ID' => $GRP_ID ) ));
122
+            : EEM_Message_Template::instance()->count(array(array('GRP_ID' => $GRP_ID)));
123 123
 
124 124
         return $count > 0;
125 125
     }
@@ -137,14 +137,14 @@  discard block
 block discarded – undo
137 137
      */
138 138
     public static function update_to_active($messenger_names, $message_type_names)
139 139
     {
140
-        $messenger_names = is_array($messenger_names) ? $messenger_names : array( $messenger_names );
141
-        $message_type_names = is_array($message_type_names) ? $message_type_names : array( $message_type_names );
140
+        $messenger_names = is_array($messenger_names) ? $messenger_names : array($messenger_names);
141
+        $message_type_names = is_array($message_type_names) ? $message_type_names : array($message_type_names);
142 142
         return EEM_Message_Template_Group::instance()->update(
143
-            array( 'MTP_is_active' => 1 ),
143
+            array('MTP_is_active' => 1),
144 144
             array(
145 145
                 array(
146
-                    'MTP_messenger'     => array( 'IN', $messenger_names ),
147
-                    'MTP_message_type'  => array( 'IN', $message_type_names )
146
+                    'MTP_messenger'     => array('IN', $messenger_names),
147
+                    'MTP_message_type'  => array('IN', $message_type_names)
148 148
                 )
149 149
             )
150 150
         );
@@ -230,13 +230,13 @@  discard block
 block discarded – undo
230 230
         $messenger = $message_resource_manager->get_messenger($messenger);
231 231
 
232 232
         // if messenger isn't a EE_messenger resource then bail.
233
-        if (! $messenger instanceof EE_messenger) {
233
+        if ( ! $messenger instanceof EE_messenger) {
234 234
             return array();
235 235
         }
236 236
 
237 237
         // validate class for getting our list of shortcodes
238
-        $classname = 'EE_Messages_' . $messenger_name . '_' . $mt_name . '_Validator';
239
-        if (! class_exists($classname)) {
238
+        $classname = 'EE_Messages_'.$messenger_name.'_'.$mt_name.'_Validator';
239
+        if ( ! class_exists($classname)) {
240 240
             $msg[] = __('The Validator class was unable to load', 'event_espresso');
241 241
             $msg[] = sprintf(
242 242
                 __('The class name compiled was %s. Please check and make sure the spelling and case is correct for the class name and that there is an autoloader in place for this class', 'event_espresso'),
@@ -252,44 +252,44 @@  discard block
 block discarded – undo
252 252
         // let's make sure we're only getting the shortcode part of the validators
253 253
         $shortcodes = array();
254 254
         foreach ($valid_shortcodes as $field => $validators) {
255
-            $shortcodes[ $field ] = $validators['shortcodes'];
255
+            $shortcodes[$field] = $validators['shortcodes'];
256 256
         }
257 257
         $valid_shortcodes = $shortcodes;
258 258
 
259 259
         // if not all fields let's make sure we ONLY include the shortcodes for the specified fields.
260
-        if (! empty($fields)) {
260
+        if ( ! empty($fields)) {
261 261
             $specified_shortcodes = array();
262 262
             foreach ($fields as $field) {
263
-                if (isset($valid_shortcodes[ $field ])) {
264
-                    $specified_shortcodes[ $field ] = $valid_shortcodes[ $field ];
263
+                if (isset($valid_shortcodes[$field])) {
264
+                    $specified_shortcodes[$field] = $valid_shortcodes[$field];
265 265
                 }
266 266
             }
267 267
             $valid_shortcodes = $specified_shortcodes;
268 268
         }
269 269
 
270 270
         // if not merged then let's replace the fields with the localized fields
271
-        if (! $merged) {
271
+        if ( ! $merged) {
272 272
             // let's get all the fields for the set messenger so that we can get the localized label and use that in the returned array.
273 273
             $field_settings = $messenger->get_template_fields();
274 274
             $localized = array();
275 275
             foreach ($valid_shortcodes as $field => $shortcodes) {
276 276
                 // get localized field label
277
-                if (isset($field_settings[ $field ])) {
277
+                if (isset($field_settings[$field])) {
278 278
                     // possible that this is used as a main field.
279
-                    if (empty($field_settings[ $field ])) {
280
-                        if (isset($field_settings['extra'][ $field ])) {
281
-                            $_field = $field_settings['extra'][ $field ]['main']['label'];
279
+                    if (empty($field_settings[$field])) {
280
+                        if (isset($field_settings['extra'][$field])) {
281
+                            $_field = $field_settings['extra'][$field]['main']['label'];
282 282
                         } else {
283 283
                             $_field = $field;
284 284
                         }
285 285
                     } else {
286
-                        $_field = $field_settings[ $field ]['label'];
286
+                        $_field = $field_settings[$field]['label'];
287 287
                     }
288 288
                 } elseif (isset($field_settings['extra'])) {
289 289
                     // loop through extra "main fields" and see if any of their children have our field
290 290
                     foreach ($field_settings['extra'] as $main_field => $fields) {
291
-                        if (isset($fields[ $field ])) {
292
-                            $_field = $fields[ $field ]['label'];
291
+                        if (isset($fields[$field])) {
292
+                            $_field = $fields[$field]['label'];
293 293
                         } else {
294 294
                             $_field = $field;
295 295
                         }
@@ -298,7 +298,7 @@  discard block
 block discarded – undo
298 298
                     $_field = $field;
299 299
                 }
300 300
                 if (isset($_field)) {
301
-                    $localized[ (string) $_field ] = $shortcodes;
301
+                    $localized[(string) $_field] = $shortcodes;
302 302
                 }
303 303
             }
304 304
             $valid_shortcodes = $localized;
@@ -309,10 +309,10 @@  discard block
 block discarded – undo
309 309
             $merged_codes = array();
310 310
             foreach ($valid_shortcodes as $field => $shortcode) {
311 311
                 foreach ($shortcode as $code => $label) {
312
-                    if (isset($merged_codes[ $code ])) {
312
+                    if (isset($merged_codes[$code])) {
313 313
                         continue;
314 314
                     } else {
315
-                        $merged_codes[ $code ] = $label;
315
+                        $merged_codes[$code] = $label;
316 316
                     }
317 317
                 }
318 318
             }
@@ -462,12 +462,12 @@  discard block
 block discarded – undo
462 462
         $sending_messenger = ''
463 463
     ) {
464 464
         // first determine if the url can be to the EE_Message object.
465
-        if (! $message_type->always_generate()) {
465
+        if ( ! $message_type->always_generate()) {
466 466
             return EEH_MSG_Template::generate_browser_trigger($message);
467 467
         }
468 468
 
469 469
         // if $registration object is not valid then exit early because there's nothing that can be generated.
470
-        if (! $registration instanceof EE_Registration) {
470
+        if ( ! $registration instanceof EE_Registration) {
471 471
             throw new EE_Error(
472 472
                 __('Incoming value for registration is not a valid EE_Registration object.', 'event_espresso')
473 473
             );
@@ -475,7 +475,7 @@  discard block
 block discarded – undo
475 475
 
476 476
         // validate given context
477 477
         $contexts = $message_type->get_contexts();
478
-        if ($message->context() !== '' && ! isset($contexts[ $message->context() ])) {
478
+        if ($message->context() !== '' && ! isset($contexts[$message->context()])) {
479 479
             throw new EE_Error(
480 480
                 sprintf(
481 481
                     __('The context %s is not a valid context for %s.', 'event_espresso'),
@@ -486,10 +486,10 @@  discard block
 block discarded – undo
486 486
         }
487 487
 
488 488
         // valid sending messenger but only if sending messenger set.  Otherwise generating messenger is used.
489
-        if (! empty($sending_messenger)) {
489
+        if ( ! empty($sending_messenger)) {
490 490
             $with_messengers = $message_type->with_messengers();
491
-            if (! isset($with_messengers[ $message->messenger() ])
492
-                 || ! in_array($sending_messenger, $with_messengers[ $message->messenger() ]) ) {
491
+            if ( ! isset($with_messengers[$message->messenger()])
492
+                 || ! in_array($sending_messenger, $with_messengers[$message->messenger()])) {
493 493
                 throw new EE_Error(
494 494
                     sprintf(
495 495
                         __(
@@ -625,7 +625,7 @@  discard block
 block discarded – undo
625 625
     public static function get_message_action_icon($type)
626 626
     {
627 627
         $action_icons = self::get_message_action_icons();
628
-        return isset($action_icons[ $type ]) ? $action_icons[ $type ] : '';
628
+        return isset($action_icons[$type]) ? $action_icons[$type] : '';
629 629
     }
630 630
 
631 631
 
@@ -688,7 +688,7 @@  discard block
 block discarded – undo
688 688
     public static function get_message_action_url($type, EE_Message $message = null, $query_params = array())
689 689
     {
690 690
         $action_urls = self::get_message_action_urls($message, $query_params);
691
-        return isset($action_urls[ $type ])  ? $action_urls[ $type ] : '';
691
+        return isset($action_urls[$type]) ? $action_urls[$type] : '';
692 692
     }
693 693
 
694 694
 
@@ -708,7 +708,7 @@  discard block
 block discarded – undo
708 708
         EE_Registry::instance()->load_helper('URL');
709 709
         // if $message is not an instance of EE_Message then let's just do a dummy.
710 710
         $message = empty($message) ? EE_Message_Factory::create() : $message;
711
-        $action_urls =  apply_filters(
711
+        $action_urls = apply_filters(
712 712
             'FHEE__EEH_MSG_Template__get_message_action_url',
713 713
             array(
714 714
                 'view' => EEH_MSG_Template::generate_browser_trigger($message),
@@ -788,7 +788,7 @@  discard block
 block discarded – undo
788 788
     {
789 789
         $url = EEH_MSG_Template::get_message_action_url($type, $message, $query_params);
790 790
         $icon_css = EEH_MSG_Template::get_message_action_icon($type);
791
-        $title = isset($icon_css['label']) ? 'title="' . $icon_css['label'] . '"' : '';
791
+        $title = isset($icon_css['label']) ? 'title="'.$icon_css['label'].'"' : '';
792 792
 
793 793
         if (empty($url) || empty($icon_css) || ! isset($icon_css['css_class'])) {
794 794
             return '';
@@ -797,14 +797,14 @@  discard block
 block discarded – undo
797 797
         $icon_css['css_class'] .= esc_attr(
798 798
             apply_filters(
799 799
                 'FHEE__EEH_MSG_Template__get_message_action_link__icon_css_class',
800
-                ' js-ee-message-action-link ee-message-action-link-' . $type,
800
+                ' js-ee-message-action-link ee-message-action-link-'.$type,
801 801
                 $type,
802 802
                 $message,
803 803
                 $query_params
804 804
             )
805 805
         );
806 806
 
807
-        return '<a href="' . $url . '"' . $title . '><span class="' . esc_attr($icon_css['css_class']) . '"></span></a>';
807
+        return '<a href="'.$url.'"'.$title.'><span class="'.esc_attr($icon_css['css_class']).'"></span></a>';
808 808
     }
809 809
 
810 810
 
@@ -845,7 +845,7 @@  discard block
 block discarded – undo
845 845
     public static function convert_reg_status_to_message_type($reg_status)
846 846
     {
847 847
         $reg_status_array = self::reg_status_to_message_type_array();
848
-        return isset($reg_status_array[ $reg_status ]) ? $reg_status_array[ $reg_status ] : '';
848
+        return isset($reg_status_array[$reg_status]) ? $reg_status_array[$reg_status] : '';
849 849
     }
850 850
 
851 851
 
@@ -883,7 +883,7 @@  discard block
 block discarded – undo
883 883
     public static function convert_payment_status_to_message_type($payment_status)
884 884
     {
885 885
         $payment_status_array = self::payment_status_to_message_type_array();
886
-        return isset($payment_status_array[ $payment_status ]) ? $payment_status_array[ $payment_status ] : '';
886
+        return isset($payment_status_array[$payment_status]) ? $payment_status_array[$payment_status] : '';
887 887
     }
888 888
 
889 889
 
@@ -896,7 +896,7 @@  discard block
 block discarded – undo
896 896
      */
897 897
     public static function get_template_pack($template_pack_name)
898 898
     {
899
-        if (! self::$_template_pack_collection instanceof EE_Object_Collection) {
899
+        if ( ! self::$_template_pack_collection instanceof EE_Object_Collection) {
900 900
             self::$_template_pack_collection = new EE_Messages_Template_Pack_Collection();
901 901
         }
902 902
 
@@ -909,14 +909,14 @@  discard block
 block discarded – undo
909 909
 
910 910
         // nope...let's get it.
911 911
         // not set yet so let's attempt to get it.
912
-        $pack_class_name = 'EE_Messages_Template_Pack_' . str_replace(
912
+        $pack_class_name = 'EE_Messages_Template_Pack_'.str_replace(
913 913
             ' ',
914 914
             '_',
915 915
             ucwords(
916 916
                 str_replace('_', ' ', $template_pack_name)
917 917
             )
918 918
         );
919
-        if (! class_exists($pack_class_name) && $template_pack_name !== 'default') {
919
+        if ( ! class_exists($pack_class_name) && $template_pack_name !== 'default') {
920 920
             return self::get_template_pack('default');
921 921
         } else {
922 922
             $template_pack = new $pack_class_name;
@@ -939,18 +939,18 @@  discard block
 block discarded – undo
939 939
     public static function get_template_pack_collection()
940 940
     {
941 941
         $new_collection = false;
942
-        if (! self::$_template_pack_collection instanceof EE_Messages_Template_Pack_Collection) {
942
+        if ( ! self::$_template_pack_collection instanceof EE_Messages_Template_Pack_Collection) {
943 943
             self::$_template_pack_collection = new EE_Messages_Template_Pack_Collection();
944 944
             $new_collection = true;
945 945
         }
946 946
 
947 947
         // glob the defaults directory for messages
948
-        $templates = glob(EE_LIBRARIES . 'messages/defaults/*', GLOB_ONLYDIR);
948
+        $templates = glob(EE_LIBRARIES.'messages/defaults/*', GLOB_ONLYDIR);
949 949
         foreach ($templates as $template_path) {
950 950
             // grab folder name
951 951
             $template = basename($template_path);
952 952
 
953
-            if (! $new_collection) {
953
+            if ( ! $new_collection) {
954 954
                 // already have it?
955 955
                 if (self::$_template_pack_collection->get_by_name($template) instanceof EE_Messages_Template_Pack) {
956 956
                     continue;
@@ -958,7 +958,7 @@  discard block
 block discarded – undo
958 958
             }
959 959
 
960 960
             // setup classname.
961
-            $template_pack_class_name = 'EE_Messages_Template_Pack_' . str_replace(
961
+            $template_pack_class_name = 'EE_Messages_Template_Pack_'.str_replace(
962 962
                 ' ',
963 963
                 '_',
964 964
                 ucwords(
@@ -969,7 +969,7 @@  discard block
 block discarded – undo
969 969
                     )
970 970
                 )
971 971
             );
972
-            if (! class_exists($template_pack_class_name)) {
972
+            if ( ! class_exists($template_pack_class_name)) {
973 973
                 continue;
974 974
             }
975 975
             self::$_template_pack_collection->add(new $template_pack_class_name);
@@ -1010,7 +1010,7 @@  discard block
 block discarded – undo
1010 1010
         $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
1011 1011
         $messenger = $Message_Resource_Manager->valid_messenger($messenger_name);
1012 1012
         $message_type = $Message_Resource_Manager->valid_message_type($message_type_name);
1013
-        if (! EEH_MSG_Template::message_type_has_active_templates_for_messenger($messenger, $message_type, $global)) {
1013
+        if ( ! EEH_MSG_Template::message_type_has_active_templates_for_messenger($messenger, $message_type, $global)) {
1014 1014
             return array();
1015 1015
         }
1016 1016
         // whew made it this far!  Okay, let's go ahead and create the templates then
@@ -1029,13 +1029,13 @@  discard block
 block discarded – undo
1029 1029
     protected static function _create_new_templates(EE_messenger $messenger, EE_message_type $message_type, $GRP_ID, $global)
1030 1030
     {
1031 1031
         // if we're creating a custom template then we don't need to use the defaults class
1032
-        if (! $global) {
1032
+        if ( ! $global) {
1033 1033
             return EEH_MSG_Template::_create_custom_template_group($messenger, $message_type, $GRP_ID);
1034 1034
         }
1035 1035
         /** @type EE_Messages_Template_Defaults $Message_Template_Defaults */
1036 1036
         $Message_Template_Defaults = EE_Registry::factory(
1037 1037
             'EE_Messages_Template_Defaults',
1038
-            array( $messenger, $message_type, $GRP_ID )
1038
+            array($messenger, $message_type, $GRP_ID)
1039 1039
         );
1040 1040
         // generate templates
1041 1041
         $success = $Message_Template_Defaults->create_new_templates();
@@ -1043,7 +1043,7 @@  discard block
 block discarded – undo
1043 1043
         // if creating the template failed.  Then we should deactivate the related message_type for the messenger because
1044 1044
         // its not active if it doesn't have a template.  Note this is only happening for GLOBAL template creation
1045 1045
         // attempts.
1046
-        if (! $success) {
1046
+        if ( ! $success) {
1047 1047
             /** @var EE_Message_Resource_Manager $message_resource_manager */
1048 1048
             $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
1049 1049
             $message_resource_manager->deactivate_message_type_for_messenger($message_type->name, $messenger->name);
@@ -1077,7 +1077,7 @@  discard block
 block discarded – undo
1077 1077
     private static function _create_custom_template_group(EE_messenger $messenger, EE_message_type $message_type, $GRP_ID)
1078 1078
     {
1079 1079
         // defaults
1080
-        $success = array( 'GRP_ID' => null, 'MTP_context' => '' );
1080
+        $success = array('GRP_ID' => null, 'MTP_context' => '');
1081 1081
         // get the template group to use as a template from the db.  If $GRP_ID is empty then we'll assume the base will be the global template matching the messenger and message type.
1082 1082
         $Message_Template_Group = empty($GRP_ID)
1083 1083
             ? EEM_Message_Template_Group::instance()->get_one(
@@ -1091,7 +1091,7 @@  discard block
 block discarded – undo
1091 1091
             )
1092 1092
             : EEM_Message_Template_Group::instance()->get_one_by_ID($GRP_ID);
1093 1093
         // if we don't have a mtg at this point then we need to bail.
1094
-        if (! $Message_Template_Group instanceof EE_Message_Template_Group) {
1094
+        if ( ! $Message_Template_Group instanceof EE_Message_Template_Group) {
1095 1095
             EE_Error::add_error(
1096 1096
                 sprintf(
1097 1097
                     __(
@@ -1137,7 +1137,7 @@  discard block
 block discarded – undo
1137 1137
         $success['template_name'] = $template_name;
1138 1138
         // add new message templates and add relation to.
1139 1139
         foreach ($message_templates as $message_template) {
1140
-            if (! $message_template instanceof EE_Message_Template) {
1140
+            if ( ! $message_template instanceof EE_Message_Template) {
1141 1141
                 continue;
1142 1142
             }
1143 1143
             $new_message_template = clone $message_template;
@@ -1215,7 +1215,7 @@  discard block
 block discarded – undo
1215 1215
         $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
1216 1216
         $messenger = $Message_Resource_Manager->valid_messenger($messenger_name);
1217 1217
         $message_type = $Message_Resource_Manager->valid_message_type($message_type_name);
1218
-        if (! EEH_MSG_Template::message_type_has_active_templates_for_messenger($messenger, $message_type)) {
1218
+        if ( ! EEH_MSG_Template::message_type_has_active_templates_for_messenger($messenger, $message_type)) {
1219 1219
             return array();
1220 1220
         }
1221 1221
 
@@ -1227,7 +1227,7 @@  discard block
 block discarded – undo
1227 1227
                 if (in_array($field, $excluded_fields_for_messenger, true)) {
1228 1228
                     continue;
1229 1229
                 }
1230
-                $template_fields[ $context ][ $field ] = $value;
1230
+                $template_fields[$context][$field] = $value;
1231 1231
             }
1232 1232
         }
1233 1233
         if (empty($template_fields)) {
Please login to merge, or discard this patch.
core/helpers/EEH_Qtip_Loader.helper.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -112,7 +112,7 @@
 block discarded – undo
112 112
      * - registers and enqueues the qtip scripts and styles.
113 113
      *
114 114
      * @access public
115
-     * @param  array  $paths      Array of paths to check for the EE_Qtip class. If present we check these path(s) first.  If not present (empty array), then it's assumed it's either in core/libraries/qtips OR the file is already loaded.
115
+     * @param  string[]  $paths      Array of paths to check for the EE_Qtip class. If present we check these path(s) first.  If not present (empty array), then it's assumed it's either in core/libraries/qtips OR the file is already loaded.
116 116
      * @param  string|array $configname name of the Qtip class (full class name is expected and will be used for looking for file, Qtip config classes must extend EE_Qtip_Config) [if this is an array, then we loop through the array to instantiate and setup the qtips]
117 117
      * @return void
118 118
      */
Please login to merge, or discard this patch.
Indentation   +225 added lines, -225 removed lines patch added patch discarded remove patch
@@ -11,229 +11,229 @@
 block discarded – undo
11 11
 class EEH_Qtip_Loader extends EEH_Base
12 12
 {
13 13
 
14
-    /**
15
-     * EEH_Qtip_Loader Object
16
-     * @var EEH_Qtip_Loader
17
-     * @access private
18
-     */
19
-    private static $_instance = null;
20
-
21
-    /**
22
-     * array of qtip config objects
23
-     * @var EE_Qtip_Config[]
24
-     */
25
-    private $_qtips = array();
26
-
27
-
28
-
29
-    /**
30
-     *@singleton method used to instantiate class object
31
-     *@access public
32
-     *@return EEH_Qtip_Loader instance
33
-     */
34
-    public static function instance()
35
-    {
36
-        // check if class object is instantiated
37
-        if (self::$_instance === null  or ! is_object(self::$_instance) or ! ( self::$_instance instanceof EEH_Qtip_Loader )) {
38
-            self::$_instance = new self();
39
-        }
40
-        return self::$_instance;
41
-    }
42
-
43
-
44
-
45
-    /**
46
-     *private constructor to prevent direct creation
47
-     * @Constructor
48
-     * @access private
49
-     * @return \EEH_Qtip_Loader
50
-     */
51
-    private function __construct()
52
-    {
53
-        // let's just make sure this is instantiated in the right place.
54
-        if (did_action('wp_print_styles') || did_action('admin_head')) {
55
-            EE_Error::doing_it_wrong('EEH_Qtip_Loader', __('This helper must be instantiated before or within a callback for the WordPress wp_enqueue_scripts hook action hook.', 'event_espresso'), '4.1');
56
-        }
57
-    }
58
-
59
-
60
-    /**
61
-     * Call this from wp_enqueue_scripts or admin_enqueue_scripts to setup and enqueue the qtip library
62
-     *
63
-     * @access public
64
-     * @return void
65
-     */
66
-    public function register_and_enqueue()
67
-    {
68
-        $qtips_js = !defined('SCRIPT_DEBUG') ? EE_THIRD_PARTY_URL . 'qtip/jquery.qtip.min.js' : EE_THIRD_PARTY_URL . 'qtip/jquery.qtip.js';
69
-        $qtip_map = EE_THIRD_PARTY_URL . 'qtip/jquery.qtip.min.map';
70
-        $qtipcss = !defined('SCRIPT_DEBUG') ? EE_THIRD_PARTY_URL . 'qtip/jquery.qtip.min.css' : EE_THIRD_PARTY_URL . 'qtip/jquery.qtip.css';
71
-
72
-        wp_register_script('qtip-map', $qtip_map, array(), '3', true);
73
-        wp_register_script('qtip', $qtips_js, array('jquery'), '3.0.3', true);
74
-        wp_register_script('ee-qtip-helper', EE_HELPERS_ASSETS . 'ee-qtip-helper.js', array('qtip', 'jquery-cookie'), EVENT_ESPRESSO_VERSION, true);
75
-
76
-        wp_register_style('qtip-css', $qtipcss, array(), '2.2');
77
-
78
-        // k now let's see if there are any registered qtips.  If there are, then we need to setup the localized script for ee-qtip-helper.js (and enqueue ee-qtip-helper.js of course!)
79
-        if (!empty($this->_qtips)) {
80
-            wp_enqueue_script('ee-qtip-helper');
81
-            wp_enqueue_style('qtip-css');
82
-            $qtips = array();
83
-            foreach ($this->_qtips as $qtip) {
84
-                $qts = $qtip->get_tips();
85
-                foreach ($qts as $qt) {
86
-                    if (! $qt instanceof EE_Qtip) {
87
-                        continue;
88
-                    }
89
-                    $qtips[] = array(
90
-                        'content_id' => $qt->content_id,
91
-                        'options' => $qt->options,
92
-                        'target' => $qt->target,
93
-                        );
94
-                }
95
-            }
96
-            if (!empty($qtips)) {
97
-                wp_localize_script('ee-qtip-helper', 'EE_QTIP_HELPER', array( 'qtips' => $qtips ));
98
-            }
99
-        } else {
100
-            // qtips has been requested without any registration (so assuming its just directly used in the admin).
101
-            wp_enqueue_script('qtip');
102
-            wp_enqueue_style('qtip-css');
103
-        }
104
-    }
105
-
106
-
107
-
108
-    /**
109
-     * This simply registers the given qtip config and:
110
-     * - adds it to the $_qtips property array.
111
-     * - sets up the content containers for all qtips in the config,
112
-     * - registers and enqueues the qtip scripts and styles.
113
-     *
114
-     * @access public
115
-     * @param  array  $paths      Array of paths to check for the EE_Qtip class. If present we check these path(s) first.  If not present (empty array), then it's assumed it's either in core/libraries/qtips OR the file is already loaded.
116
-     * @param  string|array $configname name of the Qtip class (full class name is expected and will be used for looking for file, Qtip config classes must extend EE_Qtip_Config) [if this is an array, then we loop through the array to instantiate and setup the qtips]
117
-     * @return void
118
-     */
119
-    public function register($configname, $paths = array())
120
-    {
121
-
122
-        // let's just make sure this is instantiated in the right place.
123
-        if (did_action('wp_enqueue_scripts') || did_action('admin_enqueue_scripts')) {
124
-            EE_Error::doing_it_wrong('EEH_Qtip_Loader->register()', __('EE_Qtip_Config objects must be registered before wp_enqueue_scripts is called.', 'event_espresso'), '4.1');
125
-        }
126
-
127
-        $configname = (array) $configname; // typecast to array
128
-        foreach ($configname as $config) {
129
-            $this->_register($config, $paths);
130
-        }
131
-
132
-        // hook into appropriate footer
133
-        $footer_action = is_admin() ? 'admin_footer' : 'wp_footer';
134
-        add_action($footer_action, array($this, 'setup_qtip'), 10);
135
-
136
-        // make sure we "turn on" qtip js.
137
-        add_filter('FHEE_load_qtip', '__return_true');
138
-    }
139
-
140
-
141
-
142
-    /**
143
-     * private utility for registering and setting up qtip config objects
144
-     *
145
-     * @access private
146
-     * @param  string $config the short name of the class (will be used to generate the expected classname)
147
-     * @param  array  $paths  array of paths to check (or if empty we check core/libraries/qtips or assume its loaded)
148
-     * @throws EE_Error
149
-     * @return void
150
-     */
151
-    private function _register($config, $paths)
152
-    {
153
-        // before doing anything we have to make sure that EE_Qtip_Config parent is required.
154
-        EE_Registry::instance()->load_lib('Qtip_Config', array(), true);
155
-
156
-        if (!empty($paths)) {
157
-            $paths = (array) $paths;
158
-            foreach ($paths as $path) {
159
-                $path = $path . $config . '.lib.php';
160
-                if (!is_readable($path)) {
161
-                    continue;
162
-                } else {
163
-                    require_once $path;
164
-                }
165
-            }
166
-        }
167
-
168
-        // does class exist at this point?  If it does then let's instantiate.  If it doesn't then let's continue with other paths.
169
-        if (!class_exists($config)) {
170
-            $path = EE_LIBRARIES . 'qtips/' . $config . '.lib.php';
171
-            if (!is_readable($path)) {
172
-                throw new EE_Error(sprintf(__('Unable to load the Qtip Config registered for this page (%s) because none of the file paths attempted are readable.  Please check the spelling of the paths you\'ve used in the registration', 'event_espresso'), $config));
173
-            } else {
174
-                require_once $path;
175
-            }
176
-        }
177
-
178
-        // now we attempt a class_exists one more time.
179
-        if (!class_exists($config)) {
180
-            throw new EE_Error(sprintf(__('The Qtip_Config class being registered (%s) does not exist, please check the spelling.', 'event_espresso'), $config));
181
-        }
182
-
183
-        // made it HERE?  FINALLY, let's get things setup.
184
-        $a = new ReflectionClass($config);
185
-        $qtip = $a->newInstance();
186
-
187
-        // verify that $qtip is a valid object
188
-        if (! $qtip instanceof EE_Qtip_Config) {
189
-            throw new EE_Error(sprintf(esc_html__('The class given for the Qtip loader (%1$s) is not a child of the %2$sEE_Qtip_Config%3$s class. Please make sure you are extending EE_Qtip_Config.', 'event_espresso'), $config, '<strong>', '</strong>'));
190
-        }
191
-
192
-        $this->_qtips[] = $a->newInstance();
193
-    }
194
-
195
-
196
-
197
-    /**
198
-     * This takes care of generating the qtip content containers.
199
-     * Output gets put in the appropriate page footer (depending on context (either admin_footer or wp_footer) )
200
-     *
201
-     * @access public
202
-     * @return void
203
-     */
204
-    public function setup_qtip()
205
-    {
206
-        if (empty($this->_qtips)) {
207
-            return; // no qtips!
208
-        }
209
-
210
-        $content = array();
211
-
212
-        foreach ($this->_qtips as $qtip) {
213
-            $content[] = $this->_generate_content_container($qtip);
214
-        }
215
-
216
-        echo implode('<br />', $content);
217
-    }
218
-
219
-
220
-    /**
221
-     * Generates a content container from a given EE_Qtip_Config object.
222
-     *
223
-     * @param  EE_Qtip_Config $qtip
224
-     * @return string  (html content container for qtip);
225
-     */
226
-    private function _generate_content_container($qtip)
227
-    {
228
-        $qts = $qtip->get_tips();
229
-        $content = array();
230
-        foreach ($qts as $qt) {
231
-            if (! $qt instanceof EE_Qtip) {
232
-                continue;
233
-            }
234
-            $content[] = '<div class="ee-qtip-helper-content hidden" id="' . $qt->content_id . '">' . $qt->content . '</div>';
235
-        }
236
-
237
-        return implode('<br />', $content);
238
-    }
14
+	/**
15
+	 * EEH_Qtip_Loader Object
16
+	 * @var EEH_Qtip_Loader
17
+	 * @access private
18
+	 */
19
+	private static $_instance = null;
20
+
21
+	/**
22
+	 * array of qtip config objects
23
+	 * @var EE_Qtip_Config[]
24
+	 */
25
+	private $_qtips = array();
26
+
27
+
28
+
29
+	/**
30
+	 *@singleton method used to instantiate class object
31
+	 *@access public
32
+	 *@return EEH_Qtip_Loader instance
33
+	 */
34
+	public static function instance()
35
+	{
36
+		// check if class object is instantiated
37
+		if (self::$_instance === null  or ! is_object(self::$_instance) or ! ( self::$_instance instanceof EEH_Qtip_Loader )) {
38
+			self::$_instance = new self();
39
+		}
40
+		return self::$_instance;
41
+	}
42
+
43
+
44
+
45
+	/**
46
+	 *private constructor to prevent direct creation
47
+	 * @Constructor
48
+	 * @access private
49
+	 * @return \EEH_Qtip_Loader
50
+	 */
51
+	private function __construct()
52
+	{
53
+		// let's just make sure this is instantiated in the right place.
54
+		if (did_action('wp_print_styles') || did_action('admin_head')) {
55
+			EE_Error::doing_it_wrong('EEH_Qtip_Loader', __('This helper must be instantiated before or within a callback for the WordPress wp_enqueue_scripts hook action hook.', 'event_espresso'), '4.1');
56
+		}
57
+	}
58
+
59
+
60
+	/**
61
+	 * Call this from wp_enqueue_scripts or admin_enqueue_scripts to setup and enqueue the qtip library
62
+	 *
63
+	 * @access public
64
+	 * @return void
65
+	 */
66
+	public function register_and_enqueue()
67
+	{
68
+		$qtips_js = !defined('SCRIPT_DEBUG') ? EE_THIRD_PARTY_URL . 'qtip/jquery.qtip.min.js' : EE_THIRD_PARTY_URL . 'qtip/jquery.qtip.js';
69
+		$qtip_map = EE_THIRD_PARTY_URL . 'qtip/jquery.qtip.min.map';
70
+		$qtipcss = !defined('SCRIPT_DEBUG') ? EE_THIRD_PARTY_URL . 'qtip/jquery.qtip.min.css' : EE_THIRD_PARTY_URL . 'qtip/jquery.qtip.css';
71
+
72
+		wp_register_script('qtip-map', $qtip_map, array(), '3', true);
73
+		wp_register_script('qtip', $qtips_js, array('jquery'), '3.0.3', true);
74
+		wp_register_script('ee-qtip-helper', EE_HELPERS_ASSETS . 'ee-qtip-helper.js', array('qtip', 'jquery-cookie'), EVENT_ESPRESSO_VERSION, true);
75
+
76
+		wp_register_style('qtip-css', $qtipcss, array(), '2.2');
77
+
78
+		// k now let's see if there are any registered qtips.  If there are, then we need to setup the localized script for ee-qtip-helper.js (and enqueue ee-qtip-helper.js of course!)
79
+		if (!empty($this->_qtips)) {
80
+			wp_enqueue_script('ee-qtip-helper');
81
+			wp_enqueue_style('qtip-css');
82
+			$qtips = array();
83
+			foreach ($this->_qtips as $qtip) {
84
+				$qts = $qtip->get_tips();
85
+				foreach ($qts as $qt) {
86
+					if (! $qt instanceof EE_Qtip) {
87
+						continue;
88
+					}
89
+					$qtips[] = array(
90
+						'content_id' => $qt->content_id,
91
+						'options' => $qt->options,
92
+						'target' => $qt->target,
93
+						);
94
+				}
95
+			}
96
+			if (!empty($qtips)) {
97
+				wp_localize_script('ee-qtip-helper', 'EE_QTIP_HELPER', array( 'qtips' => $qtips ));
98
+			}
99
+		} else {
100
+			// qtips has been requested without any registration (so assuming its just directly used in the admin).
101
+			wp_enqueue_script('qtip');
102
+			wp_enqueue_style('qtip-css');
103
+		}
104
+	}
105
+
106
+
107
+
108
+	/**
109
+	 * This simply registers the given qtip config and:
110
+	 * - adds it to the $_qtips property array.
111
+	 * - sets up the content containers for all qtips in the config,
112
+	 * - registers and enqueues the qtip scripts and styles.
113
+	 *
114
+	 * @access public
115
+	 * @param  array  $paths      Array of paths to check for the EE_Qtip class. If present we check these path(s) first.  If not present (empty array), then it's assumed it's either in core/libraries/qtips OR the file is already loaded.
116
+	 * @param  string|array $configname name of the Qtip class (full class name is expected and will be used for looking for file, Qtip config classes must extend EE_Qtip_Config) [if this is an array, then we loop through the array to instantiate and setup the qtips]
117
+	 * @return void
118
+	 */
119
+	public function register($configname, $paths = array())
120
+	{
121
+
122
+		// let's just make sure this is instantiated in the right place.
123
+		if (did_action('wp_enqueue_scripts') || did_action('admin_enqueue_scripts')) {
124
+			EE_Error::doing_it_wrong('EEH_Qtip_Loader->register()', __('EE_Qtip_Config objects must be registered before wp_enqueue_scripts is called.', 'event_espresso'), '4.1');
125
+		}
126
+
127
+		$configname = (array) $configname; // typecast to array
128
+		foreach ($configname as $config) {
129
+			$this->_register($config, $paths);
130
+		}
131
+
132
+		// hook into appropriate footer
133
+		$footer_action = is_admin() ? 'admin_footer' : 'wp_footer';
134
+		add_action($footer_action, array($this, 'setup_qtip'), 10);
135
+
136
+		// make sure we "turn on" qtip js.
137
+		add_filter('FHEE_load_qtip', '__return_true');
138
+	}
139
+
140
+
141
+
142
+	/**
143
+	 * private utility for registering and setting up qtip config objects
144
+	 *
145
+	 * @access private
146
+	 * @param  string $config the short name of the class (will be used to generate the expected classname)
147
+	 * @param  array  $paths  array of paths to check (or if empty we check core/libraries/qtips or assume its loaded)
148
+	 * @throws EE_Error
149
+	 * @return void
150
+	 */
151
+	private function _register($config, $paths)
152
+	{
153
+		// before doing anything we have to make sure that EE_Qtip_Config parent is required.
154
+		EE_Registry::instance()->load_lib('Qtip_Config', array(), true);
155
+
156
+		if (!empty($paths)) {
157
+			$paths = (array) $paths;
158
+			foreach ($paths as $path) {
159
+				$path = $path . $config . '.lib.php';
160
+				if (!is_readable($path)) {
161
+					continue;
162
+				} else {
163
+					require_once $path;
164
+				}
165
+			}
166
+		}
167
+
168
+		// does class exist at this point?  If it does then let's instantiate.  If it doesn't then let's continue with other paths.
169
+		if (!class_exists($config)) {
170
+			$path = EE_LIBRARIES . 'qtips/' . $config . '.lib.php';
171
+			if (!is_readable($path)) {
172
+				throw new EE_Error(sprintf(__('Unable to load the Qtip Config registered for this page (%s) because none of the file paths attempted are readable.  Please check the spelling of the paths you\'ve used in the registration', 'event_espresso'), $config));
173
+			} else {
174
+				require_once $path;
175
+			}
176
+		}
177
+
178
+		// now we attempt a class_exists one more time.
179
+		if (!class_exists($config)) {
180
+			throw new EE_Error(sprintf(__('The Qtip_Config class being registered (%s) does not exist, please check the spelling.', 'event_espresso'), $config));
181
+		}
182
+
183
+		// made it HERE?  FINALLY, let's get things setup.
184
+		$a = new ReflectionClass($config);
185
+		$qtip = $a->newInstance();
186
+
187
+		// verify that $qtip is a valid object
188
+		if (! $qtip instanceof EE_Qtip_Config) {
189
+			throw new EE_Error(sprintf(esc_html__('The class given for the Qtip loader (%1$s) is not a child of the %2$sEE_Qtip_Config%3$s class. Please make sure you are extending EE_Qtip_Config.', 'event_espresso'), $config, '<strong>', '</strong>'));
190
+		}
191
+
192
+		$this->_qtips[] = $a->newInstance();
193
+	}
194
+
195
+
196
+
197
+	/**
198
+	 * This takes care of generating the qtip content containers.
199
+	 * Output gets put in the appropriate page footer (depending on context (either admin_footer or wp_footer) )
200
+	 *
201
+	 * @access public
202
+	 * @return void
203
+	 */
204
+	public function setup_qtip()
205
+	{
206
+		if (empty($this->_qtips)) {
207
+			return; // no qtips!
208
+		}
209
+
210
+		$content = array();
211
+
212
+		foreach ($this->_qtips as $qtip) {
213
+			$content[] = $this->_generate_content_container($qtip);
214
+		}
215
+
216
+		echo implode('<br />', $content);
217
+	}
218
+
219
+
220
+	/**
221
+	 * Generates a content container from a given EE_Qtip_Config object.
222
+	 *
223
+	 * @param  EE_Qtip_Config $qtip
224
+	 * @return string  (html content container for qtip);
225
+	 */
226
+	private function _generate_content_container($qtip)
227
+	{
228
+		$qts = $qtip->get_tips();
229
+		$content = array();
230
+		foreach ($qts as $qt) {
231
+			if (! $qt instanceof EE_Qtip) {
232
+				continue;
233
+			}
234
+			$content[] = '<div class="ee-qtip-helper-content hidden" id="' . $qt->content_id . '">' . $qt->content . '</div>';
235
+		}
236
+
237
+		return implode('<br />', $content);
238
+	}
239 239
 }
Please login to merge, or discard this patch.
Spacing   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -34,7 +34,7 @@  discard block
 block discarded – undo
34 34
     public static function instance()
35 35
     {
36 36
         // check if class object is instantiated
37
-        if (self::$_instance === null  or ! is_object(self::$_instance) or ! ( self::$_instance instanceof EEH_Qtip_Loader )) {
37
+        if (self::$_instance === null or ! is_object(self::$_instance) or ! (self::$_instance instanceof EEH_Qtip_Loader)) {
38 38
             self::$_instance = new self();
39 39
         }
40 40
         return self::$_instance;
@@ -65,25 +65,25 @@  discard block
 block discarded – undo
65 65
      */
66 66
     public function register_and_enqueue()
67 67
     {
68
-        $qtips_js = !defined('SCRIPT_DEBUG') ? EE_THIRD_PARTY_URL . 'qtip/jquery.qtip.min.js' : EE_THIRD_PARTY_URL . 'qtip/jquery.qtip.js';
69
-        $qtip_map = EE_THIRD_PARTY_URL . 'qtip/jquery.qtip.min.map';
70
-        $qtipcss = !defined('SCRIPT_DEBUG') ? EE_THIRD_PARTY_URL . 'qtip/jquery.qtip.min.css' : EE_THIRD_PARTY_URL . 'qtip/jquery.qtip.css';
68
+        $qtips_js = ! defined('SCRIPT_DEBUG') ? EE_THIRD_PARTY_URL . 'qtip/jquery.qtip.min.js' : EE_THIRD_PARTY_URL.'qtip/jquery.qtip.js';
69
+        $qtip_map = EE_THIRD_PARTY_URL.'qtip/jquery.qtip.min.map';
70
+        $qtipcss = ! defined('SCRIPT_DEBUG') ? EE_THIRD_PARTY_URL . 'qtip/jquery.qtip.min.css' : EE_THIRD_PARTY_URL.'qtip/jquery.qtip.css';
71 71
 
72 72
         wp_register_script('qtip-map', $qtip_map, array(), '3', true);
73 73
         wp_register_script('qtip', $qtips_js, array('jquery'), '3.0.3', true);
74
-        wp_register_script('ee-qtip-helper', EE_HELPERS_ASSETS . 'ee-qtip-helper.js', array('qtip', 'jquery-cookie'), EVENT_ESPRESSO_VERSION, true);
74
+        wp_register_script('ee-qtip-helper', EE_HELPERS_ASSETS.'ee-qtip-helper.js', array('qtip', 'jquery-cookie'), EVENT_ESPRESSO_VERSION, true);
75 75
 
76 76
         wp_register_style('qtip-css', $qtipcss, array(), '2.2');
77 77
 
78 78
         // k now let's see if there are any registered qtips.  If there are, then we need to setup the localized script for ee-qtip-helper.js (and enqueue ee-qtip-helper.js of course!)
79
-        if (!empty($this->_qtips)) {
79
+        if ( ! empty($this->_qtips)) {
80 80
             wp_enqueue_script('ee-qtip-helper');
81 81
             wp_enqueue_style('qtip-css');
82 82
             $qtips = array();
83 83
             foreach ($this->_qtips as $qtip) {
84 84
                 $qts = $qtip->get_tips();
85 85
                 foreach ($qts as $qt) {
86
-                    if (! $qt instanceof EE_Qtip) {
86
+                    if ( ! $qt instanceof EE_Qtip) {
87 87
                         continue;
88 88
                     }
89 89
                     $qtips[] = array(
@@ -93,8 +93,8 @@  discard block
 block discarded – undo
93 93
                         );
94 94
                 }
95 95
             }
96
-            if (!empty($qtips)) {
97
-                wp_localize_script('ee-qtip-helper', 'EE_QTIP_HELPER', array( 'qtips' => $qtips ));
96
+            if ( ! empty($qtips)) {
97
+                wp_localize_script('ee-qtip-helper', 'EE_QTIP_HELPER', array('qtips' => $qtips));
98 98
             }
99 99
         } else {
100 100
             // qtips has been requested without any registration (so assuming its just directly used in the admin).
@@ -153,11 +153,11 @@  discard block
 block discarded – undo
153 153
         // before doing anything we have to make sure that EE_Qtip_Config parent is required.
154 154
         EE_Registry::instance()->load_lib('Qtip_Config', array(), true);
155 155
 
156
-        if (!empty($paths)) {
156
+        if ( ! empty($paths)) {
157 157
             $paths = (array) $paths;
158 158
             foreach ($paths as $path) {
159
-                $path = $path . $config . '.lib.php';
160
-                if (!is_readable($path)) {
159
+                $path = $path.$config.'.lib.php';
160
+                if ( ! is_readable($path)) {
161 161
                     continue;
162 162
                 } else {
163 163
                     require_once $path;
@@ -166,9 +166,9 @@  discard block
 block discarded – undo
166 166
         }
167 167
 
168 168
         // does class exist at this point?  If it does then let's instantiate.  If it doesn't then let's continue with other paths.
169
-        if (!class_exists($config)) {
170
-            $path = EE_LIBRARIES . 'qtips/' . $config . '.lib.php';
171
-            if (!is_readable($path)) {
169
+        if ( ! class_exists($config)) {
170
+            $path = EE_LIBRARIES.'qtips/'.$config.'.lib.php';
171
+            if ( ! is_readable($path)) {
172 172
                 throw new EE_Error(sprintf(__('Unable to load the Qtip Config registered for this page (%s) because none of the file paths attempted are readable.  Please check the spelling of the paths you\'ve used in the registration', 'event_espresso'), $config));
173 173
             } else {
174 174
                 require_once $path;
@@ -176,7 +176,7 @@  discard block
 block discarded – undo
176 176
         }
177 177
 
178 178
         // now we attempt a class_exists one more time.
179
-        if (!class_exists($config)) {
179
+        if ( ! class_exists($config)) {
180 180
             throw new EE_Error(sprintf(__('The Qtip_Config class being registered (%s) does not exist, please check the spelling.', 'event_espresso'), $config));
181 181
         }
182 182
 
@@ -185,7 +185,7 @@  discard block
 block discarded – undo
185 185
         $qtip = $a->newInstance();
186 186
 
187 187
         // verify that $qtip is a valid object
188
-        if (! $qtip instanceof EE_Qtip_Config) {
188
+        if ( ! $qtip instanceof EE_Qtip_Config) {
189 189
             throw new EE_Error(sprintf(esc_html__('The class given for the Qtip loader (%1$s) is not a child of the %2$sEE_Qtip_Config%3$s class. Please make sure you are extending EE_Qtip_Config.', 'event_espresso'), $config, '<strong>', '</strong>'));
190 190
         }
191 191
 
@@ -228,10 +228,10 @@  discard block
 block discarded – undo
228 228
         $qts = $qtip->get_tips();
229 229
         $content = array();
230 230
         foreach ($qts as $qt) {
231
-            if (! $qt instanceof EE_Qtip) {
231
+            if ( ! $qt instanceof EE_Qtip) {
232 232
                 continue;
233 233
             }
234
-            $content[] = '<div class="ee-qtip-helper-content hidden" id="' . $qt->content_id . '">' . $qt->content . '</div>';
234
+            $content[] = '<div class="ee-qtip-helper-content hidden" id="'.$qt->content_id.'">'.$qt->content.'</div>';
235 235
         }
236 236
 
237 237
         return implode('<br />', $content);
Please login to merge, or discard this patch.
core/helpers/EEH_Template.helper.php 3 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -308,7 +308,7 @@  discard block
 block discarded – undo
308 308
      * _find_common_base_path
309 309
      * given two paths, this determines if there is a common base path between the two
310 310
      *
311
-     * @param array $paths
311
+     * @param string[] $paths
312 312
      * @return string
313 313
      */
314 314
     protected static function _find_common_base_path($paths)
@@ -338,7 +338,7 @@  discard block
 block discarded – undo
338 338
      * @param  boolean    $return_string whether to send output immediately to screen, or capture and return as a string
339 339
      * @param bool        $throw_exceptions if set to true, will throw an exception if the template is either
340 340
      *                                      not found or is not readable
341
-     * @return mixed string
341
+     * @return string string
342 342
      * @throws \DomainException
343 343
      */
344 344
     public static function display_template(
Please login to merge, or discard this patch.
Indentation   +962 added lines, -962 removed lines patch added patch discarded remove patch
@@ -5,35 +5,35 @@  discard block
 block discarded – undo
5 5
 use EventEspresso\core\services\loaders\LoaderFactory;
6 6
 
7 7
 if (! function_exists('espresso_get_template_part')) {
8
-    /**
9
-     * espresso_get_template_part
10
-     * basically a copy of the WordPress get_template_part() function but uses EEH_Template::locate_template() instead, and doesn't add base versions of files
11
-     * so not a very useful function at all except that it adds familiarity PLUS filtering based off of the entire template part name
12
-     *
13
-     * @param string $slug The slug name for the generic template.
14
-     * @param string $name The name of the specialised template.
15
-     * @return string        the html output for the formatted money value
16
-     */
17
-    function espresso_get_template_part($slug = null, $name = null)
18
-    {
19
-        EEH_Template::get_template_part($slug, $name);
20
-    }
8
+	/**
9
+	 * espresso_get_template_part
10
+	 * basically a copy of the WordPress get_template_part() function but uses EEH_Template::locate_template() instead, and doesn't add base versions of files
11
+	 * so not a very useful function at all except that it adds familiarity PLUS filtering based off of the entire template part name
12
+	 *
13
+	 * @param string $slug The slug name for the generic template.
14
+	 * @param string $name The name of the specialised template.
15
+	 * @return string        the html output for the formatted money value
16
+	 */
17
+	function espresso_get_template_part($slug = null, $name = null)
18
+	{
19
+		EEH_Template::get_template_part($slug, $name);
20
+	}
21 21
 }
22 22
 
23 23
 
24 24
 if (! function_exists('espresso_get_object_css_class')) {
25
-    /**
26
-     * espresso_get_object_css_class - attempts to generate a css class based on the type of EE object passed
27
-     *
28
-     * @param EE_Base_Class $object the EE object the css class is being generated for
29
-     * @param  string       $prefix added to the beginning of the generated class
30
-     * @param  string       $suffix added to the end of the generated class
31
-     * @return string
32
-     */
33
-    function espresso_get_object_css_class($object = null, $prefix = '', $suffix = '')
34
-    {
35
-        return EEH_Template::get_object_css_class($object, $prefix, $suffix);
36
-    }
25
+	/**
26
+	 * espresso_get_object_css_class - attempts to generate a css class based on the type of EE object passed
27
+	 *
28
+	 * @param EE_Base_Class $object the EE object the css class is being generated for
29
+	 * @param  string       $prefix added to the beginning of the generated class
30
+	 * @param  string       $suffix added to the end of the generated class
31
+	 * @return string
32
+	 */
33
+	function espresso_get_object_css_class($object = null, $prefix = '', $suffix = '')
34
+	{
35
+		return EEH_Template::get_object_css_class($object, $prefix, $suffix);
36
+	}
37 37
 }
38 38
 
39 39
 
@@ -48,672 +48,672 @@  discard block
 block discarded – undo
48 48
 class EEH_Template
49 49
 {
50 50
 
51
-    private static $_espresso_themes = array();
52
-
53
-
54
-    /**
55
-     *    is_espresso_theme - returns TRUE or FALSE on whether the currently active WP theme is an espresso theme
56
-     *
57
-     * @return boolean
58
-     */
59
-    public static function is_espresso_theme()
60
-    {
61
-        return wp_get_theme()->get('TextDomain') == 'event_espresso' ? true : false;
62
-    }
63
-
64
-    /**
65
-     *    load_espresso_theme_functions - if current theme is an espresso theme, or uses ee theme template parts, then
66
-     *    load it's functions.php file ( if not already loaded )
67
-     *
68
-     * @return void
69
-     */
70
-    public static function load_espresso_theme_functions()
71
-    {
72
-        if (! defined('EE_THEME_FUNCTIONS_LOADED')) {
73
-            if (is_readable(EE_PUBLIC . EE_Config::get_current_theme() . DS . 'functions.php')) {
74
-                require_once(EE_PUBLIC . EE_Config::get_current_theme() . DS . 'functions.php');
75
-            }
76
-        }
77
-    }
78
-
79
-
80
-    /**
81
-     *    get_espresso_themes - returns an array of Espresso Child themes located in the /templates/ directory
82
-     *
83
-     * @return array
84
-     */
85
-    public static function get_espresso_themes()
86
-    {
87
-        if (empty(EEH_Template::$_espresso_themes)) {
88
-            $espresso_themes = glob(EE_PUBLIC . '*', GLOB_ONLYDIR);
89
-            if (empty($espresso_themes)) {
90
-                return array();
91
-            }
92
-            if (($key = array_search('global_assets', $espresso_themes)) !== false) {
93
-                unset($espresso_themes[ $key ]);
94
-            }
95
-            EEH_Template::$_espresso_themes = array();
96
-            foreach ($espresso_themes as $espresso_theme) {
97
-                EEH_Template::$_espresso_themes[ basename($espresso_theme) ] = $espresso_theme;
98
-            }
99
-        }
100
-        return EEH_Template::$_espresso_themes;
101
-    }
102
-
103
-
104
-    /**
105
-     * EEH_Template::get_template_part
106
-     * basically a copy of the WordPress get_template_part() function but uses EEH_Template::locate_template() instead,
107
-     * and doesn't add base versions of files so not a very useful function at all except that it adds familiarity PLUS
108
-     * filtering based off of the entire template part name
109
-     *
110
-     * @param string $slug The slug name for the generic template.
111
-     * @param string $name The name of the specialised template.
112
-     * @param array  $template_args
113
-     * @param bool   $return_string
114
-     * @return string        the html output for the formatted money value
115
-     */
116
-    public static function get_template_part(
117
-        $slug = null,
118
-        $name = null,
119
-        $template_args = array(),
120
-        $return_string = false
121
-    ) {
122
-        do_action("get_template_part_{$slug}-{$name}", $slug, $name);
123
-        $templates = array();
124
-        $name      = (string) $name;
125
-        if ($name != '') {
126
-            $templates[] = "{$slug}-{$name}.php";
127
-        }
128
-        // allow template parts to be turned off via something like: add_filter( 'FHEE__content_espresso_events_tickets_template__display_datetimes', '__return_false' );
129
-        if (apply_filters("FHEE__EEH_Template__get_template_part__display__{$slug}_{$name}", true)) {
130
-            EEH_Template::locate_template($templates, $template_args, true, $return_string);
131
-        }
132
-    }
133
-
134
-
135
-    /**
136
-     *    locate_template
137
-     *    locate a template file by looking in the following places, in the following order:
138
-     *        <server path up to>/wp-content/themes/<current active WordPress theme>/
139
-     *        <assumed full absolute server path>
140
-     *        <server path up to>/wp-content/uploads/espresso/templates/<current EE theme>/
141
-     *        <server path up to>/wp-content/uploads/espresso/templates/
142
-     *        <server path up to>/wp-content/plugins/<EE4 folder>/public/<current EE theme>/
143
-     *        <server path up to>/wp-content/plugins/<EE4 folder>/core/templates/<current EE theme>/
144
-     *        <server path up to>/wp-content/plugins/<EE4 folder>/
145
-     *    as soon as the template is found in one of these locations, it will be returned or loaded
146
-     *        Example:
147
-     *          You are using the WordPress Twenty Sixteen theme,
148
-     *        and you want to customize the "some-event.template.php" template,
149
-     *          which is located in the "/relative/path/to/" folder relative to the main EE plugin folder.
150
-     *          Assuming WP is installed on your server in the "/home/public_html/" folder,
151
-     *        EEH_Template::locate_template() will look at the following paths in order until the template is found:
152
-     *        /home/public_html/wp-content/themes/twentysixteen/some-event.template.php
153
-     *        /relative/path/to/some-event.template.php
154
-     *        /home/public_html/wp-content/uploads/espresso/templates/Espresso_Arabica_2014/relative/path/to/some-event.template.php
155
-     *        /home/public_html/wp-content/uploads/espresso/templates/relative/path/to/some-event.template.php
156
-     *        /home/public_html/wp-content/plugins/event-espresso-core-reg/public/Espresso_Arabica_2014/relative/path/to/some-event.template.php
157
-     *        /home/public_html/wp-content/plugins/event-espresso-core-reg/core/templates/Espresso_Arabica_2014/relative/path/to/some-event.template.php
158
-     *        /home/public_html/wp-content/plugins/event-espresso-core-reg/relative/path/to/some-event.template.php
159
-     *          Had you passed an absolute path to your template that was in some other location,
160
-     *        ie: "/absolute/path/to/some-event.template.php"
161
-     *          then the search would have been :
162
-     *        /home/public_html/wp-content/themes/twentysixteen/some-event.template.php
163
-     *        /absolute/path/to/some-event.template.php
164
-     *          and stopped there upon finding it in the second location
165
-     *
166
-     * @param array|string $templates       array of template file names including extension (or just a single string)
167
-     * @param  array       $template_args   an array of arguments to be extracted for use in the template
168
-     * @param  boolean     $load            whether to pass the located template path on to the
169
-     *                                      EEH_Template::display_template() method or simply return it
170
-     * @param  boolean     $return_string   whether to send output immediately to screen, or capture and return as a
171
-     *                                      string
172
-     * @param boolean      $check_if_custom If TRUE, this flags this method to return boolean for whether this will
173
-     *                                      generate a custom template or not. Used in places where you don't actually
174
-     *                                      load the template, you just want to know if there's a custom version of it.
175
-     * @return mixed
176
-     * @throws DomainException
177
-     * @throws InvalidArgumentException
178
-     * @throws InvalidDataTypeException
179
-     * @throws InvalidInterfaceException
180
-     */
181
-    public static function locate_template(
182
-        $templates = array(),
183
-        $template_args = array(),
184
-        $load = true,
185
-        $return_string = true,
186
-        $check_if_custom = false
187
-    ) {
188
-        // first use WP locate_template to check for template in the current theme folder
189
-        $template_path = locate_template($templates);
190
-
191
-        if ($check_if_custom && ! empty($template_path)) {
192
-            return true;
193
-        }
194
-
195
-        // not in the theme
196
-        if (empty($template_path)) {
197
-            // not even a template to look for ?
198
-            if (empty($templates)) {
199
-                // get post_type
200
-                $post_type = EE_Registry::instance()->REQ->get('post_type');
201
-                /** @var EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions $custom_post_types */
202
-                $custom_post_types = LoaderFactory::getLoader()->getShared(
203
-                    'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions'
204
-                );
205
-                // get array of EE Custom Post Types
206
-                $EE_CPTs = $custom_post_types->getDefinitions();
207
-                // build template name based on request
208
-                if (isset($EE_CPTs[ $post_type ])) {
209
-                    $archive_or_single = is_archive() ? 'archive' : '';
210
-                    $archive_or_single = is_single() ? 'single' : $archive_or_single;
211
-                    $templates         = $archive_or_single . '-' . $post_type . '.php';
212
-                }
213
-            }
214
-            // currently active EE template theme
215
-            $current_theme = EE_Config::get_current_theme();
216
-
217
-            // array of paths to folders that may contain templates
218
-            $template_folder_paths = array(
219
-                // first check the /wp-content/uploads/espresso/templates/(current EE theme)/  folder for an EE theme template file
220
-                EVENT_ESPRESSO_TEMPLATE_DIR . $current_theme,
221
-                // then in the root of the /wp-content/uploads/espresso/templates/ folder
222
-                EVENT_ESPRESSO_TEMPLATE_DIR,
223
-            );
224
-
225
-            // add core plugin folders for checking only if we're not $check_if_custom
226
-            if (! $check_if_custom) {
227
-                $core_paths            = array(
228
-                    // in the  /wp-content/plugins/(EE4 folder)/public/(current EE theme)/ folder within the plugin
229
-                    EE_PUBLIC . $current_theme,
230
-                    // in the  /wp-content/plugins/(EE4 folder)/core/templates/(current EE theme)/ folder within the plugin
231
-                    EE_TEMPLATES . $current_theme,
232
-                    // or maybe relative from the plugin root: /wp-content/plugins/(EE4 folder)/
233
-                    EE_PLUGIN_DIR_PATH,
234
-                );
235
-                $template_folder_paths = array_merge($template_folder_paths, $core_paths);
236
-            }
237
-
238
-            // now filter that array
239
-            $template_folder_paths = apply_filters(
240
-                'FHEE__EEH_Template__locate_template__template_folder_paths',
241
-                $template_folder_paths
242
-            );
243
-            $templates             = is_array($templates) ? $templates : array($templates);
244
-            $template_folder_paths = is_array($template_folder_paths) ? $template_folder_paths : array($template_folder_paths);
245
-            // array to hold all possible template paths
246
-            $full_template_paths = array();
247
-
248
-            // loop through $templates
249
-            foreach ($templates as $template) {
250
-                // normalize directory separators
251
-                $template                      = EEH_File::standardise_directory_separators($template);
252
-                $file_name                     = basename($template);
253
-                $template_path_minus_file_name = substr($template, 0, (strlen($file_name) * -1));
254
-                // while looping through all template folder paths
255
-                foreach ($template_folder_paths as $template_folder_path) {
256
-                    // normalize directory separators
257
-                    $template_folder_path = EEH_File::standardise_directory_separators($template_folder_path);
258
-                    // determine if any common base path exists between the two paths
259
-                    $common_base_path = EEH_Template::_find_common_base_path(
260
-                        array($template_folder_path, $template_path_minus_file_name)
261
-                    );
262
-                    if ($common_base_path !== '') {
263
-                        // both paths have a common base, so just tack the filename onto our search path
264
-                        $resolved_path = EEH_File::end_with_directory_separator($template_folder_path) . $file_name;
265
-                    } else {
266
-                        // no common base path, so let's just concatenate
267
-                        $resolved_path = EEH_File::end_with_directory_separator($template_folder_path) . $template;
268
-                    }
269
-                    // build up our template locations array by adding our resolved paths
270
-                    $full_template_paths[] = $resolved_path;
271
-                }
272
-                // if $template is an absolute path, then we'll tack it onto the start of our array so that it gets searched first
273
-                array_unshift($full_template_paths, $template);
274
-                // path to the directory of the current theme: /wp-content/themes/(current WP theme)/
275
-                array_unshift($full_template_paths, get_stylesheet_directory() . DS . $file_name);
276
-            }
277
-            // filter final array of full template paths
278
-            $full_template_paths = apply_filters(
279
-                'FHEE__EEH_Template__locate_template__full_template_paths',
280
-                $full_template_paths,
281
-                $file_name
282
-            );
283
-            // now loop through our final array of template location paths and check each location
284
-            foreach ((array) $full_template_paths as $full_template_path) {
285
-                if (is_readable($full_template_path)) {
286
-                    $template_path = str_replace(array('\\', '/'), DIRECTORY_SEPARATOR, $full_template_path);
287
-                    break;
288
-                }
289
-            }
290
-        }
291
-
292
-        // hook that can be used to display the full template path that will be used
293
-        do_action('AHEE__EEH_Template__locate_template__full_template_path', $template_path);
294
-
295
-        // if we got it and you want to see it...
296
-        if ($template_path && $load && ! $check_if_custom) {
297
-            if ($return_string) {
298
-                return EEH_Template::display_template($template_path, $template_args, true);
299
-            } else {
300
-                EEH_Template::display_template($template_path, $template_args, false);
301
-            }
302
-        }
303
-        return $check_if_custom && ! empty($template_path) ? true : $template_path;
304
-    }
305
-
306
-
307
-    /**
308
-     * _find_common_base_path
309
-     * given two paths, this determines if there is a common base path between the two
310
-     *
311
-     * @param array $paths
312
-     * @return string
313
-     */
314
-    protected static function _find_common_base_path($paths)
315
-    {
316
-        $last_offset      = 0;
317
-        $common_base_path = '';
318
-        while (($index = strpos($paths[0], DS, $last_offset)) !== false) {
319
-            $dir_length = $index - $last_offset + 1;
320
-            $directory  = substr($paths[0], $last_offset, $dir_length);
321
-            foreach ($paths as $path) {
322
-                if (substr($path, $last_offset, $dir_length) != $directory) {
323
-                    return $common_base_path;
324
-                }
325
-            }
326
-            $common_base_path .= $directory;
327
-            $last_offset = $index + 1;
328
-        }
329
-        return substr($common_base_path, 0, -1);
330
-    }
331
-
332
-
333
-    /**
334
-     * load and display a template
335
-     *
336
-     * @param bool|string $template_path server path to the file to be loaded, including file name and extension
337
-     * @param  array      $template_args an array of arguments to be extracted for use in the template
338
-     * @param  boolean    $return_string whether to send output immediately to screen, or capture and return as a string
339
-     * @param bool        $throw_exceptions if set to true, will throw an exception if the template is either
340
-     *                                      not found or is not readable
341
-     * @return mixed string
342
-     * @throws \DomainException
343
-     */
344
-    public static function display_template(
345
-        $template_path = false,
346
-        $template_args = array(),
347
-        $return_string = false,
348
-        $throw_exceptions = false
349
-    ) {
350
-
351
-        /**
352
-         * These two filters are intended for last minute changes to templates being loaded and/or template arg
353
-         * modifications.  NOTE... modifying these things can cause breakage as most templates running through
354
-         * the display_template method are templates we DON'T want modified (usually because of js
355
-         * dependencies etc).  So unless you know what you are doing, do NOT filter templates or template args
356
-         * using this.
357
-         *
358
-         * @since 4.6.0
359
-         */
360
-        $template_path = (string) apply_filters('FHEE__EEH_Template__display_template__template_path', $template_path);
361
-        $template_args = (array) apply_filters('FHEE__EEH_Template__display_template__template_args', $template_args);
362
-
363
-        // you gimme nuttin - YOU GET NUTTIN !!
364
-        if (! $template_path || ! is_readable($template_path)) {
365
-            return '';
366
-        }
367
-        // if $template_args are not in an array, then make it so
368
-        if (! is_array($template_args) && ! is_object($template_args)) {
369
-            $template_args = array($template_args);
370
-        }
371
-        extract($template_args, EXTR_SKIP);
372
-        // ignore whether template is accessible ?
373
-        if ($throw_exceptions && ! is_readable($template_path)) {
374
-            throw new \DomainException(
375
-                esc_html__(
376
-                    'Invalid, unreadable, or missing file.',
377
-                    'event_espresso'
378
-                )
379
-            );
380
-        }
381
-
382
-
383
-        if ($return_string) {
384
-            // because we want to return a string, we are going to capture the output
385
-            ob_start();
386
-            include($template_path);
387
-            return ob_get_clean();
388
-        } else {
389
-            include($template_path);
390
-        }
391
-        return '';
392
-    }
393
-
394
-
395
-    /**
396
-     * get_object_css_class - attempts to generate a css class based on the type of EE object passed
397
-     *
398
-     * @param EE_Base_Class $object the EE object the css class is being generated for
399
-     * @param  string       $prefix added to the beginning of the generated class
400
-     * @param  string       $suffix added to the end of the generated class
401
-     * @return string
402
-     */
403
-    public static function get_object_css_class($object = null, $prefix = '', $suffix = '')
404
-    {
405
-        // in the beginning...
406
-        $prefix = ! empty($prefix) ? rtrim($prefix, '-') . '-' : '';
407
-        // da muddle
408
-        $class = '';
409
-        // the end
410
-        $suffix = ! empty($suffix) ? '-' . ltrim($suffix, '-') : '';
411
-        // is the passed object an EE object ?
412
-        if ($object instanceof EE_Base_Class) {
413
-            // grab the exact type of object
414
-            $obj_class = get_class($object);
415
-            // depending on the type of object...
416
-            switch ($obj_class) {
417
-                // no specifics just yet...
418
-                default:
419
-                    $class = strtolower(str_replace('_', '-', $obj_class));
420
-                    $class .= method_exists($obj_class, 'name') ? '-' . sanitize_title($object->name()) : '';
421
-            }
422
-        }
423
-        return $prefix . $class . $suffix;
424
-    }
425
-
426
-
427
-
428
-    /**
429
-     * EEH_Template::format_currency
430
-     * This helper takes a raw float value and formats it according to the default config country currency settings, or
431
-     * the country currency settings from the supplied country ISO code
432
-     *
433
-     * @param  float   $amount       raw money value
434
-     * @param  boolean $return_raw   whether to return the formatted float value only with no currency sign or code
435
-     * @param  boolean $display_code whether to display the country code (USD). Default = TRUE
436
-     * @param string   $CNT_ISO      2 letter ISO code for a country
437
-     * @param string   $cur_code_span_class
438
-     * @return string        the html output for the formatted money value
439
-     * @throws \EE_Error
440
-     */
441
-    public static function format_currency(
442
-        $amount = null,
443
-        $return_raw = false,
444
-        $display_code = true,
445
-        $CNT_ISO = '',
446
-        $cur_code_span_class = 'currency-code'
447
-    ) {
448
-        // ensure amount was received
449
-        if ($amount === null) {
450
-            $msg = __('In order to format currency, an amount needs to be passed.', 'event_espresso');
451
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
452
-            return '';
453
-        }
454
-        // ensure amount is float
455
-        $amount  = apply_filters('FHEE__EEH_Template__format_currency__raw_amount', (float) $amount);
456
-        $CNT_ISO = apply_filters('FHEE__EEH_Template__format_currency__CNT_ISO', $CNT_ISO, $amount);
457
-        // filter raw amount (allows 0.00 to be changed to "free" for example)
458
-        $amount_formatted = apply_filters('FHEE__EEH_Template__format_currency__amount', $amount, $return_raw);
459
-        // still a number or was amount converted to a string like "free" ?
460
-        if (is_float($amount_formatted)) {
461
-            // was a country ISO code passed ? if so generate currency config object for that country
462
-            $mny = $CNT_ISO !== '' ? new EE_Currency_Config($CNT_ISO) : null;
463
-            // verify results
464
-            if (! $mny instanceof EE_Currency_Config) {
465
-                // set default config country currency settings
466
-                $mny = EE_Registry::instance()->CFG->currency instanceof EE_Currency_Config
467
-                    ? EE_Registry::instance()->CFG->currency
468
-                    : new EE_Currency_Config();
469
-            }
470
-            // format float
471
-            $amount_formatted = number_format($amount, $mny->dec_plc, $mny->dec_mrk, $mny->thsnds);
472
-            // add formatting ?
473
-            if (! $return_raw) {
474
-                // add currency sign
475
-                if ($mny->sign_b4) {
476
-                    if ($amount >= 0) {
477
-                        $amount_formatted = $mny->sign . $amount_formatted;
478
-                    } else {
479
-                        $amount_formatted = '-' . $mny->sign . str_replace('-', '', $amount_formatted);
480
-                    }
481
-                } else {
482
-                    $amount_formatted = $amount_formatted . $mny->sign;
483
-                }
484
-
485
-                // filter to allow global setting of display_code
486
-                $display_code = apply_filters('FHEE__EEH_Template__format_currency__display_code', $display_code);
487
-
488
-                // add currency code ?
489
-                $amount_formatted = $display_code ? $amount_formatted . ' <span class="' . $cur_code_span_class . '">(' . $mny->code . ')</span>' : $amount_formatted;
490
-            }
491
-            // filter results
492
-            $amount_formatted = apply_filters(
493
-                'FHEE__EEH_Template__format_currency__amount_formatted',
494
-                $amount_formatted,
495
-                $mny,
496
-                $return_raw
497
-            );
498
-        }
499
-        // clean up vars
500
-        unset($mny);
501
-        // return formatted currency amount
502
-        return $amount_formatted;
503
-    }
504
-
505
-
506
-    /**
507
-     * This function is used for outputting the localized label for a given status id in the schema requested (and
508
-     * possibly plural).  The intended use of this function is only for cases where wanting a label outside of a
509
-     * related status model or model object (i.e. in documentation etc.)
510
-     *
511
-     * @param  string  $status_id Status ID matching a registered status in the esp_status table.  If there is no
512
-     *                            match, then 'Unknown' will be returned.
513
-     * @param  boolean $plural    Whether to return plural or not
514
-     * @param  string  $schema    'UPPER', 'lower', or 'Sentence'
515
-     * @return string             The localized label for the status id.
516
-     */
517
-    public static function pretty_status($status_id, $plural = false, $schema = 'upper')
518
-    {
519
-        /** @type EEM_Status $EEM_Status */
520
-        $EEM_Status = EE_Registry::instance()->load_model('Status');
521
-        $status     = $EEM_Status->localized_status(
522
-            array($status_id => __('unknown', 'event_espresso')),
523
-            $plural,
524
-            $schema
525
-        );
526
-        return $status[ $status_id ];
527
-    }
528
-
529
-
530
-    /**
531
-     * This helper just returns a button or link for the given parameters
532
-     *
533
-     * @param  string $url   the url for the link, note that `esc_url` will be called on it
534
-     * @param  string $label What is the label you want displayed for the button
535
-     * @param  string $class what class is used for the button (defaults to 'button-primary')
536
-     * @param string  $icon
537
-     * @param string  $title
538
-     * @return string the html output for the button
539
-     */
540
-    public static function get_button_or_link($url, $label, $class = 'button-primary', $icon = '', $title = '')
541
-    {
542
-        $icon_html = '';
543
-        if (! empty($icon)) {
544
-            $dashicons = preg_split("(ee-icon |dashicons )", $icon);
545
-            $dashicons = array_filter($dashicons);
546
-            $count     = count($dashicons);
547
-            $icon_html .= $count > 1 ? '<span class="ee-composite-dashicon">' : '';
548
-            foreach ($dashicons as $dashicon) {
549
-                $type = strpos($dashicon, 'ee-icon') !== false ? 'ee-icon ' : 'dashicons ';
550
-                $icon_html .= '<span class="' . $type . $dashicon . '"></span>';
551
-            }
552
-            $icon_html .= $count > 1 ? '</span>' : '';
553
-        }
554
-        $label  = ! empty($icon) ? $icon_html . $label : $label;
555
-        $button = '<a id="' . sanitize_title_with_dashes($label) . '" href="' . esc_url($url) . '" class="' . $class . '" title="' . $title . '">' . $label . '</a>';
556
-        return $button;
557
-    }
558
-
559
-
560
-    /**
561
-     * This returns a generated link that will load the related help tab on admin pages.
562
-     *
563
-     * @param  string     $help_tab_id the id for the connected help tab
564
-     * @param bool|string $page        The page identifier for the page the help tab is on
565
-     * @param bool|string $action      The action (route) for the admin page the help tab is on.
566
-     * @param bool|string $icon_style  (optional) include css class for the style you want to use for the help icon.
567
-     * @param bool|string $help_text   (optional) send help text you want to use for the link if default not to be used
568
-     * @return string              generated link
569
-     */
570
-    public static function get_help_tab_link(
571
-        $help_tab_id,
572
-        $page = false,
573
-        $action = false,
574
-        $icon_style = false,
575
-        $help_text = false
576
-    ) {
577
-
578
-        if (! $page) {
579
-            $page = isset($_REQUEST['page']) && ! empty($_REQUEST['page']) ? sanitize_key($_REQUEST['page']) : $page;
580
-        }
581
-
582
-        if (! $action) {
583
-            $action = isset($_REQUEST['action']) && ! empty($_REQUEST['action']) ? sanitize_key($_REQUEST['action']) : $action;
584
-        }
585
-
586
-        $action = empty($action) ? 'default' : $action;
587
-
588
-
589
-        $help_tab_lnk = $page . '-' . $action . '-' . $help_tab_id;
590
-        $icon         = ! $icon_style ? ' dashicons-editor-help' : $icon_style;
591
-        $help_text    = ! $help_text ? '' : $help_text;
592
-        return '<a id="' . $help_tab_lnk . '" class="ee-clickable dashicons espresso-help-tab-lnk ee-icon-size-22' . $icon . '" title="' . esc_attr__(
593
-            'Click to open the \'Help\' tab for more information about this feature.',
594
-            'event_espresso'
595
-        ) . '" > ' . $help_text . ' </a>';
596
-    }
597
-
598
-
599
-    /**
600
-     * This helper generates the html structure for the jquery joyride plugin with the given params.
601
-     *
602
-     * @link http://zurb.com/playground/jquery-joyride-feature-tour-plugin
603
-     * @see  EE_Admin_Page->_stop_callback() for the construct expected for the $stops param.
604
-     * @param EE_Help_Tour
605
-     * @return string         html
606
-     */
607
-    public static function help_tour_stops_generator(EE_Help_Tour $tour)
608
-    {
609
-        $id    = $tour->get_slug();
610
-        $stops = $tour->get_stops();
611
-
612
-        $content = '<ol style="display:none" id="' . $id . '">';
613
-
614
-        foreach ($stops as $stop) {
615
-            $data_id    = ! empty($stop['id']) ? ' data-id="' . $stop['id'] . '"' : '';
616
-            $data_class = empty($data_id) && ! empty($stop['class']) ? ' data-class="' . $stop['class'] . '"' : '';
617
-
618
-            // if container is set to modal then let's make sure we set the options accordingly
619
-            if (empty($data_id) && empty($data_class)) {
620
-                $stop['options']['modal']  = true;
621
-                $stop['options']['expose'] = true;
622
-            }
623
-
624
-            $custom_class  = ! empty($stop['custom_class']) ? ' class="' . $stop['custom_class'] . '"' : '';
625
-            $button_text   = ! empty($stop['button_text']) ? ' data-button="' . $stop['button_text'] . '"' : '';
626
-            $inner_content = isset($stop['content']) ? $stop['content'] : '';
627
-
628
-            // options
629
-            if (isset($stop['options']) && is_array($stop['options'])) {
630
-                $options = ' data-options="';
631
-                foreach ($stop['options'] as $option => $value) {
632
-                    $options .= $option . ':' . $value . ';';
633
-                }
634
-                $options .= '"';
635
-            } else {
636
-                $options = '';
637
-            }
638
-
639
-            // let's put all together
640
-            $content .= '<li' . $data_id . $data_class . $custom_class . $button_text . $options . '>' . $inner_content . '</li>';
641
-        }
642
-
643
-        $content .= '</ol>';
644
-        return $content;
645
-    }
646
-
647
-
648
-    /**
649
-     * This is a helper method to generate a status legend for a given status array.
650
-     * Note this will only work if the incoming statuses have a key in the EEM_Status->localized_status() methods
651
-     * status_array.
652
-     *
653
-     * @param  array  $status_array  array of statuses that will make up the legend. In format:
654
-     *                               array(
655
-     *                               'status_item' => 'status_name'
656
-     *                               )
657
-     * @param  string $active_status This is used to indicate what the active status is IF that is to be highlighted in
658
-     *                               the legend.
659
-     * @throws EE_Error
660
-     * @return string               html structure for status.
661
-     */
662
-    public static function status_legend($status_array, $active_status = '')
663
-    {
664
-        if (! is_array($status_array)) {
665
-            throw new EE_Error(esc_html__(
666
-                'The EEH_Template::status_legend helper required the incoming status_array argument to be an array!',
667
-                'event_espresso'
668
-            ));
669
-        }
670
-
671
-        $setup_array = array();
672
-        foreach ($status_array as $item => $status) {
673
-            $setup_array[ $item ] = array(
674
-                'class'  => 'ee-status-legend ee-status-legend-' . $status,
675
-                'desc'   => EEH_Template::pretty_status($status, false, 'sentence'),
676
-                'status' => $status,
677
-            );
678
-        }
679
-
680
-        $content = '<div class="ee-list-table-legend-container">' . "\n";
681
-        $content .= '<h4 class="status-legend-title">' . esc_html__('Status Legend', 'event_espresso') . '</h4>' . "\n";
682
-        $content .= '<dl class="ee-list-table-legend">' . "\n\t";
683
-        foreach ($setup_array as $item => $details) {
684
-            $active_class = $active_status == $details['status'] ? ' class="ee-is-active-status"' : '';
685
-            $content .= '<dt id="ee-legend-item-tooltip-' . $item . '"' . $active_class . '>' . "\n\t\t";
686
-            $content .= '<span class="' . $details['class'] . '"></span>' . "\n\t\t";
687
-            $content .= '<span class="ee-legend-description">' . $details['desc'] . '</span>' . "\n\t";
688
-            $content .= '</dt>' . "\n";
689
-        }
690
-        $content .= '</dl>' . "\n";
691
-        $content .= '</div>' . "\n";
692
-        return $content;
693
-    }
694
-
695
-
696
-    /**
697
-     * Gets HTML for laying out a deeply-nested array (and objects) in a format
698
-     * that's nice for presenting in the wp admin
699
-     *
700
-     * @param mixed $data
701
-     * @return string
702
-     */
703
-    public static function layout_array_as_table($data)
704
-    {
705
-        if (is_object($data) || $data instanceof __PHP_Incomplete_Class) {
706
-            $data = (array) $data;
707
-        }
708
-        ob_start();
709
-        if (is_array($data)) {
710
-            if (EEH_Array::is_associative_array($data)) {
711
-                ?>
51
+	private static $_espresso_themes = array();
52
+
53
+
54
+	/**
55
+	 *    is_espresso_theme - returns TRUE or FALSE on whether the currently active WP theme is an espresso theme
56
+	 *
57
+	 * @return boolean
58
+	 */
59
+	public static function is_espresso_theme()
60
+	{
61
+		return wp_get_theme()->get('TextDomain') == 'event_espresso' ? true : false;
62
+	}
63
+
64
+	/**
65
+	 *    load_espresso_theme_functions - if current theme is an espresso theme, or uses ee theme template parts, then
66
+	 *    load it's functions.php file ( if not already loaded )
67
+	 *
68
+	 * @return void
69
+	 */
70
+	public static function load_espresso_theme_functions()
71
+	{
72
+		if (! defined('EE_THEME_FUNCTIONS_LOADED')) {
73
+			if (is_readable(EE_PUBLIC . EE_Config::get_current_theme() . DS . 'functions.php')) {
74
+				require_once(EE_PUBLIC . EE_Config::get_current_theme() . DS . 'functions.php');
75
+			}
76
+		}
77
+	}
78
+
79
+
80
+	/**
81
+	 *    get_espresso_themes - returns an array of Espresso Child themes located in the /templates/ directory
82
+	 *
83
+	 * @return array
84
+	 */
85
+	public static function get_espresso_themes()
86
+	{
87
+		if (empty(EEH_Template::$_espresso_themes)) {
88
+			$espresso_themes = glob(EE_PUBLIC . '*', GLOB_ONLYDIR);
89
+			if (empty($espresso_themes)) {
90
+				return array();
91
+			}
92
+			if (($key = array_search('global_assets', $espresso_themes)) !== false) {
93
+				unset($espresso_themes[ $key ]);
94
+			}
95
+			EEH_Template::$_espresso_themes = array();
96
+			foreach ($espresso_themes as $espresso_theme) {
97
+				EEH_Template::$_espresso_themes[ basename($espresso_theme) ] = $espresso_theme;
98
+			}
99
+		}
100
+		return EEH_Template::$_espresso_themes;
101
+	}
102
+
103
+
104
+	/**
105
+	 * EEH_Template::get_template_part
106
+	 * basically a copy of the WordPress get_template_part() function but uses EEH_Template::locate_template() instead,
107
+	 * and doesn't add base versions of files so not a very useful function at all except that it adds familiarity PLUS
108
+	 * filtering based off of the entire template part name
109
+	 *
110
+	 * @param string $slug The slug name for the generic template.
111
+	 * @param string $name The name of the specialised template.
112
+	 * @param array  $template_args
113
+	 * @param bool   $return_string
114
+	 * @return string        the html output for the formatted money value
115
+	 */
116
+	public static function get_template_part(
117
+		$slug = null,
118
+		$name = null,
119
+		$template_args = array(),
120
+		$return_string = false
121
+	) {
122
+		do_action("get_template_part_{$slug}-{$name}", $slug, $name);
123
+		$templates = array();
124
+		$name      = (string) $name;
125
+		if ($name != '') {
126
+			$templates[] = "{$slug}-{$name}.php";
127
+		}
128
+		// allow template parts to be turned off via something like: add_filter( 'FHEE__content_espresso_events_tickets_template__display_datetimes', '__return_false' );
129
+		if (apply_filters("FHEE__EEH_Template__get_template_part__display__{$slug}_{$name}", true)) {
130
+			EEH_Template::locate_template($templates, $template_args, true, $return_string);
131
+		}
132
+	}
133
+
134
+
135
+	/**
136
+	 *    locate_template
137
+	 *    locate a template file by looking in the following places, in the following order:
138
+	 *        <server path up to>/wp-content/themes/<current active WordPress theme>/
139
+	 *        <assumed full absolute server path>
140
+	 *        <server path up to>/wp-content/uploads/espresso/templates/<current EE theme>/
141
+	 *        <server path up to>/wp-content/uploads/espresso/templates/
142
+	 *        <server path up to>/wp-content/plugins/<EE4 folder>/public/<current EE theme>/
143
+	 *        <server path up to>/wp-content/plugins/<EE4 folder>/core/templates/<current EE theme>/
144
+	 *        <server path up to>/wp-content/plugins/<EE4 folder>/
145
+	 *    as soon as the template is found in one of these locations, it will be returned or loaded
146
+	 *        Example:
147
+	 *          You are using the WordPress Twenty Sixteen theme,
148
+	 *        and you want to customize the "some-event.template.php" template,
149
+	 *          which is located in the "/relative/path/to/" folder relative to the main EE plugin folder.
150
+	 *          Assuming WP is installed on your server in the "/home/public_html/" folder,
151
+	 *        EEH_Template::locate_template() will look at the following paths in order until the template is found:
152
+	 *        /home/public_html/wp-content/themes/twentysixteen/some-event.template.php
153
+	 *        /relative/path/to/some-event.template.php
154
+	 *        /home/public_html/wp-content/uploads/espresso/templates/Espresso_Arabica_2014/relative/path/to/some-event.template.php
155
+	 *        /home/public_html/wp-content/uploads/espresso/templates/relative/path/to/some-event.template.php
156
+	 *        /home/public_html/wp-content/plugins/event-espresso-core-reg/public/Espresso_Arabica_2014/relative/path/to/some-event.template.php
157
+	 *        /home/public_html/wp-content/plugins/event-espresso-core-reg/core/templates/Espresso_Arabica_2014/relative/path/to/some-event.template.php
158
+	 *        /home/public_html/wp-content/plugins/event-espresso-core-reg/relative/path/to/some-event.template.php
159
+	 *          Had you passed an absolute path to your template that was in some other location,
160
+	 *        ie: "/absolute/path/to/some-event.template.php"
161
+	 *          then the search would have been :
162
+	 *        /home/public_html/wp-content/themes/twentysixteen/some-event.template.php
163
+	 *        /absolute/path/to/some-event.template.php
164
+	 *          and stopped there upon finding it in the second location
165
+	 *
166
+	 * @param array|string $templates       array of template file names including extension (or just a single string)
167
+	 * @param  array       $template_args   an array of arguments to be extracted for use in the template
168
+	 * @param  boolean     $load            whether to pass the located template path on to the
169
+	 *                                      EEH_Template::display_template() method or simply return it
170
+	 * @param  boolean     $return_string   whether to send output immediately to screen, or capture and return as a
171
+	 *                                      string
172
+	 * @param boolean      $check_if_custom If TRUE, this flags this method to return boolean for whether this will
173
+	 *                                      generate a custom template or not. Used in places where you don't actually
174
+	 *                                      load the template, you just want to know if there's a custom version of it.
175
+	 * @return mixed
176
+	 * @throws DomainException
177
+	 * @throws InvalidArgumentException
178
+	 * @throws InvalidDataTypeException
179
+	 * @throws InvalidInterfaceException
180
+	 */
181
+	public static function locate_template(
182
+		$templates = array(),
183
+		$template_args = array(),
184
+		$load = true,
185
+		$return_string = true,
186
+		$check_if_custom = false
187
+	) {
188
+		// first use WP locate_template to check for template in the current theme folder
189
+		$template_path = locate_template($templates);
190
+
191
+		if ($check_if_custom && ! empty($template_path)) {
192
+			return true;
193
+		}
194
+
195
+		// not in the theme
196
+		if (empty($template_path)) {
197
+			// not even a template to look for ?
198
+			if (empty($templates)) {
199
+				// get post_type
200
+				$post_type = EE_Registry::instance()->REQ->get('post_type');
201
+				/** @var EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions $custom_post_types */
202
+				$custom_post_types = LoaderFactory::getLoader()->getShared(
203
+					'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions'
204
+				);
205
+				// get array of EE Custom Post Types
206
+				$EE_CPTs = $custom_post_types->getDefinitions();
207
+				// build template name based on request
208
+				if (isset($EE_CPTs[ $post_type ])) {
209
+					$archive_or_single = is_archive() ? 'archive' : '';
210
+					$archive_or_single = is_single() ? 'single' : $archive_or_single;
211
+					$templates         = $archive_or_single . '-' . $post_type . '.php';
212
+				}
213
+			}
214
+			// currently active EE template theme
215
+			$current_theme = EE_Config::get_current_theme();
216
+
217
+			// array of paths to folders that may contain templates
218
+			$template_folder_paths = array(
219
+				// first check the /wp-content/uploads/espresso/templates/(current EE theme)/  folder for an EE theme template file
220
+				EVENT_ESPRESSO_TEMPLATE_DIR . $current_theme,
221
+				// then in the root of the /wp-content/uploads/espresso/templates/ folder
222
+				EVENT_ESPRESSO_TEMPLATE_DIR,
223
+			);
224
+
225
+			// add core plugin folders for checking only if we're not $check_if_custom
226
+			if (! $check_if_custom) {
227
+				$core_paths            = array(
228
+					// in the  /wp-content/plugins/(EE4 folder)/public/(current EE theme)/ folder within the plugin
229
+					EE_PUBLIC . $current_theme,
230
+					// in the  /wp-content/plugins/(EE4 folder)/core/templates/(current EE theme)/ folder within the plugin
231
+					EE_TEMPLATES . $current_theme,
232
+					// or maybe relative from the plugin root: /wp-content/plugins/(EE4 folder)/
233
+					EE_PLUGIN_DIR_PATH,
234
+				);
235
+				$template_folder_paths = array_merge($template_folder_paths, $core_paths);
236
+			}
237
+
238
+			// now filter that array
239
+			$template_folder_paths = apply_filters(
240
+				'FHEE__EEH_Template__locate_template__template_folder_paths',
241
+				$template_folder_paths
242
+			);
243
+			$templates             = is_array($templates) ? $templates : array($templates);
244
+			$template_folder_paths = is_array($template_folder_paths) ? $template_folder_paths : array($template_folder_paths);
245
+			// array to hold all possible template paths
246
+			$full_template_paths = array();
247
+
248
+			// loop through $templates
249
+			foreach ($templates as $template) {
250
+				// normalize directory separators
251
+				$template                      = EEH_File::standardise_directory_separators($template);
252
+				$file_name                     = basename($template);
253
+				$template_path_minus_file_name = substr($template, 0, (strlen($file_name) * -1));
254
+				// while looping through all template folder paths
255
+				foreach ($template_folder_paths as $template_folder_path) {
256
+					// normalize directory separators
257
+					$template_folder_path = EEH_File::standardise_directory_separators($template_folder_path);
258
+					// determine if any common base path exists between the two paths
259
+					$common_base_path = EEH_Template::_find_common_base_path(
260
+						array($template_folder_path, $template_path_minus_file_name)
261
+					);
262
+					if ($common_base_path !== '') {
263
+						// both paths have a common base, so just tack the filename onto our search path
264
+						$resolved_path = EEH_File::end_with_directory_separator($template_folder_path) . $file_name;
265
+					} else {
266
+						// no common base path, so let's just concatenate
267
+						$resolved_path = EEH_File::end_with_directory_separator($template_folder_path) . $template;
268
+					}
269
+					// build up our template locations array by adding our resolved paths
270
+					$full_template_paths[] = $resolved_path;
271
+				}
272
+				// if $template is an absolute path, then we'll tack it onto the start of our array so that it gets searched first
273
+				array_unshift($full_template_paths, $template);
274
+				// path to the directory of the current theme: /wp-content/themes/(current WP theme)/
275
+				array_unshift($full_template_paths, get_stylesheet_directory() . DS . $file_name);
276
+			}
277
+			// filter final array of full template paths
278
+			$full_template_paths = apply_filters(
279
+				'FHEE__EEH_Template__locate_template__full_template_paths',
280
+				$full_template_paths,
281
+				$file_name
282
+			);
283
+			// now loop through our final array of template location paths and check each location
284
+			foreach ((array) $full_template_paths as $full_template_path) {
285
+				if (is_readable($full_template_path)) {
286
+					$template_path = str_replace(array('\\', '/'), DIRECTORY_SEPARATOR, $full_template_path);
287
+					break;
288
+				}
289
+			}
290
+		}
291
+
292
+		// hook that can be used to display the full template path that will be used
293
+		do_action('AHEE__EEH_Template__locate_template__full_template_path', $template_path);
294
+
295
+		// if we got it and you want to see it...
296
+		if ($template_path && $load && ! $check_if_custom) {
297
+			if ($return_string) {
298
+				return EEH_Template::display_template($template_path, $template_args, true);
299
+			} else {
300
+				EEH_Template::display_template($template_path, $template_args, false);
301
+			}
302
+		}
303
+		return $check_if_custom && ! empty($template_path) ? true : $template_path;
304
+	}
305
+
306
+
307
+	/**
308
+	 * _find_common_base_path
309
+	 * given two paths, this determines if there is a common base path between the two
310
+	 *
311
+	 * @param array $paths
312
+	 * @return string
313
+	 */
314
+	protected static function _find_common_base_path($paths)
315
+	{
316
+		$last_offset      = 0;
317
+		$common_base_path = '';
318
+		while (($index = strpos($paths[0], DS, $last_offset)) !== false) {
319
+			$dir_length = $index - $last_offset + 1;
320
+			$directory  = substr($paths[0], $last_offset, $dir_length);
321
+			foreach ($paths as $path) {
322
+				if (substr($path, $last_offset, $dir_length) != $directory) {
323
+					return $common_base_path;
324
+				}
325
+			}
326
+			$common_base_path .= $directory;
327
+			$last_offset = $index + 1;
328
+		}
329
+		return substr($common_base_path, 0, -1);
330
+	}
331
+
332
+
333
+	/**
334
+	 * load and display a template
335
+	 *
336
+	 * @param bool|string $template_path server path to the file to be loaded, including file name and extension
337
+	 * @param  array      $template_args an array of arguments to be extracted for use in the template
338
+	 * @param  boolean    $return_string whether to send output immediately to screen, or capture and return as a string
339
+	 * @param bool        $throw_exceptions if set to true, will throw an exception if the template is either
340
+	 *                                      not found or is not readable
341
+	 * @return mixed string
342
+	 * @throws \DomainException
343
+	 */
344
+	public static function display_template(
345
+		$template_path = false,
346
+		$template_args = array(),
347
+		$return_string = false,
348
+		$throw_exceptions = false
349
+	) {
350
+
351
+		/**
352
+		 * These two filters are intended for last minute changes to templates being loaded and/or template arg
353
+		 * modifications.  NOTE... modifying these things can cause breakage as most templates running through
354
+		 * the display_template method are templates we DON'T want modified (usually because of js
355
+		 * dependencies etc).  So unless you know what you are doing, do NOT filter templates or template args
356
+		 * using this.
357
+		 *
358
+		 * @since 4.6.0
359
+		 */
360
+		$template_path = (string) apply_filters('FHEE__EEH_Template__display_template__template_path', $template_path);
361
+		$template_args = (array) apply_filters('FHEE__EEH_Template__display_template__template_args', $template_args);
362
+
363
+		// you gimme nuttin - YOU GET NUTTIN !!
364
+		if (! $template_path || ! is_readable($template_path)) {
365
+			return '';
366
+		}
367
+		// if $template_args are not in an array, then make it so
368
+		if (! is_array($template_args) && ! is_object($template_args)) {
369
+			$template_args = array($template_args);
370
+		}
371
+		extract($template_args, EXTR_SKIP);
372
+		// ignore whether template is accessible ?
373
+		if ($throw_exceptions && ! is_readable($template_path)) {
374
+			throw new \DomainException(
375
+				esc_html__(
376
+					'Invalid, unreadable, or missing file.',
377
+					'event_espresso'
378
+				)
379
+			);
380
+		}
381
+
382
+
383
+		if ($return_string) {
384
+			// because we want to return a string, we are going to capture the output
385
+			ob_start();
386
+			include($template_path);
387
+			return ob_get_clean();
388
+		} else {
389
+			include($template_path);
390
+		}
391
+		return '';
392
+	}
393
+
394
+
395
+	/**
396
+	 * get_object_css_class - attempts to generate a css class based on the type of EE object passed
397
+	 *
398
+	 * @param EE_Base_Class $object the EE object the css class is being generated for
399
+	 * @param  string       $prefix added to the beginning of the generated class
400
+	 * @param  string       $suffix added to the end of the generated class
401
+	 * @return string
402
+	 */
403
+	public static function get_object_css_class($object = null, $prefix = '', $suffix = '')
404
+	{
405
+		// in the beginning...
406
+		$prefix = ! empty($prefix) ? rtrim($prefix, '-') . '-' : '';
407
+		// da muddle
408
+		$class = '';
409
+		// the end
410
+		$suffix = ! empty($suffix) ? '-' . ltrim($suffix, '-') : '';
411
+		// is the passed object an EE object ?
412
+		if ($object instanceof EE_Base_Class) {
413
+			// grab the exact type of object
414
+			$obj_class = get_class($object);
415
+			// depending on the type of object...
416
+			switch ($obj_class) {
417
+				// no specifics just yet...
418
+				default:
419
+					$class = strtolower(str_replace('_', '-', $obj_class));
420
+					$class .= method_exists($obj_class, 'name') ? '-' . sanitize_title($object->name()) : '';
421
+			}
422
+		}
423
+		return $prefix . $class . $suffix;
424
+	}
425
+
426
+
427
+
428
+	/**
429
+	 * EEH_Template::format_currency
430
+	 * This helper takes a raw float value and formats it according to the default config country currency settings, or
431
+	 * the country currency settings from the supplied country ISO code
432
+	 *
433
+	 * @param  float   $amount       raw money value
434
+	 * @param  boolean $return_raw   whether to return the formatted float value only with no currency sign or code
435
+	 * @param  boolean $display_code whether to display the country code (USD). Default = TRUE
436
+	 * @param string   $CNT_ISO      2 letter ISO code for a country
437
+	 * @param string   $cur_code_span_class
438
+	 * @return string        the html output for the formatted money value
439
+	 * @throws \EE_Error
440
+	 */
441
+	public static function format_currency(
442
+		$amount = null,
443
+		$return_raw = false,
444
+		$display_code = true,
445
+		$CNT_ISO = '',
446
+		$cur_code_span_class = 'currency-code'
447
+	) {
448
+		// ensure amount was received
449
+		if ($amount === null) {
450
+			$msg = __('In order to format currency, an amount needs to be passed.', 'event_espresso');
451
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
452
+			return '';
453
+		}
454
+		// ensure amount is float
455
+		$amount  = apply_filters('FHEE__EEH_Template__format_currency__raw_amount', (float) $amount);
456
+		$CNT_ISO = apply_filters('FHEE__EEH_Template__format_currency__CNT_ISO', $CNT_ISO, $amount);
457
+		// filter raw amount (allows 0.00 to be changed to "free" for example)
458
+		$amount_formatted = apply_filters('FHEE__EEH_Template__format_currency__amount', $amount, $return_raw);
459
+		// still a number or was amount converted to a string like "free" ?
460
+		if (is_float($amount_formatted)) {
461
+			// was a country ISO code passed ? if so generate currency config object for that country
462
+			$mny = $CNT_ISO !== '' ? new EE_Currency_Config($CNT_ISO) : null;
463
+			// verify results
464
+			if (! $mny instanceof EE_Currency_Config) {
465
+				// set default config country currency settings
466
+				$mny = EE_Registry::instance()->CFG->currency instanceof EE_Currency_Config
467
+					? EE_Registry::instance()->CFG->currency
468
+					: new EE_Currency_Config();
469
+			}
470
+			// format float
471
+			$amount_formatted = number_format($amount, $mny->dec_plc, $mny->dec_mrk, $mny->thsnds);
472
+			// add formatting ?
473
+			if (! $return_raw) {
474
+				// add currency sign
475
+				if ($mny->sign_b4) {
476
+					if ($amount >= 0) {
477
+						$amount_formatted = $mny->sign . $amount_formatted;
478
+					} else {
479
+						$amount_formatted = '-' . $mny->sign . str_replace('-', '', $amount_formatted);
480
+					}
481
+				} else {
482
+					$amount_formatted = $amount_formatted . $mny->sign;
483
+				}
484
+
485
+				// filter to allow global setting of display_code
486
+				$display_code = apply_filters('FHEE__EEH_Template__format_currency__display_code', $display_code);
487
+
488
+				// add currency code ?
489
+				$amount_formatted = $display_code ? $amount_formatted . ' <span class="' . $cur_code_span_class . '">(' . $mny->code . ')</span>' : $amount_formatted;
490
+			}
491
+			// filter results
492
+			$amount_formatted = apply_filters(
493
+				'FHEE__EEH_Template__format_currency__amount_formatted',
494
+				$amount_formatted,
495
+				$mny,
496
+				$return_raw
497
+			);
498
+		}
499
+		// clean up vars
500
+		unset($mny);
501
+		// return formatted currency amount
502
+		return $amount_formatted;
503
+	}
504
+
505
+
506
+	/**
507
+	 * This function is used for outputting the localized label for a given status id in the schema requested (and
508
+	 * possibly plural).  The intended use of this function is only for cases where wanting a label outside of a
509
+	 * related status model or model object (i.e. in documentation etc.)
510
+	 *
511
+	 * @param  string  $status_id Status ID matching a registered status in the esp_status table.  If there is no
512
+	 *                            match, then 'Unknown' will be returned.
513
+	 * @param  boolean $plural    Whether to return plural or not
514
+	 * @param  string  $schema    'UPPER', 'lower', or 'Sentence'
515
+	 * @return string             The localized label for the status id.
516
+	 */
517
+	public static function pretty_status($status_id, $plural = false, $schema = 'upper')
518
+	{
519
+		/** @type EEM_Status $EEM_Status */
520
+		$EEM_Status = EE_Registry::instance()->load_model('Status');
521
+		$status     = $EEM_Status->localized_status(
522
+			array($status_id => __('unknown', 'event_espresso')),
523
+			$plural,
524
+			$schema
525
+		);
526
+		return $status[ $status_id ];
527
+	}
528
+
529
+
530
+	/**
531
+	 * This helper just returns a button or link for the given parameters
532
+	 *
533
+	 * @param  string $url   the url for the link, note that `esc_url` will be called on it
534
+	 * @param  string $label What is the label you want displayed for the button
535
+	 * @param  string $class what class is used for the button (defaults to 'button-primary')
536
+	 * @param string  $icon
537
+	 * @param string  $title
538
+	 * @return string the html output for the button
539
+	 */
540
+	public static function get_button_or_link($url, $label, $class = 'button-primary', $icon = '', $title = '')
541
+	{
542
+		$icon_html = '';
543
+		if (! empty($icon)) {
544
+			$dashicons = preg_split("(ee-icon |dashicons )", $icon);
545
+			$dashicons = array_filter($dashicons);
546
+			$count     = count($dashicons);
547
+			$icon_html .= $count > 1 ? '<span class="ee-composite-dashicon">' : '';
548
+			foreach ($dashicons as $dashicon) {
549
+				$type = strpos($dashicon, 'ee-icon') !== false ? 'ee-icon ' : 'dashicons ';
550
+				$icon_html .= '<span class="' . $type . $dashicon . '"></span>';
551
+			}
552
+			$icon_html .= $count > 1 ? '</span>' : '';
553
+		}
554
+		$label  = ! empty($icon) ? $icon_html . $label : $label;
555
+		$button = '<a id="' . sanitize_title_with_dashes($label) . '" href="' . esc_url($url) . '" class="' . $class . '" title="' . $title . '">' . $label . '</a>';
556
+		return $button;
557
+	}
558
+
559
+
560
+	/**
561
+	 * This returns a generated link that will load the related help tab on admin pages.
562
+	 *
563
+	 * @param  string     $help_tab_id the id for the connected help tab
564
+	 * @param bool|string $page        The page identifier for the page the help tab is on
565
+	 * @param bool|string $action      The action (route) for the admin page the help tab is on.
566
+	 * @param bool|string $icon_style  (optional) include css class for the style you want to use for the help icon.
567
+	 * @param bool|string $help_text   (optional) send help text you want to use for the link if default not to be used
568
+	 * @return string              generated link
569
+	 */
570
+	public static function get_help_tab_link(
571
+		$help_tab_id,
572
+		$page = false,
573
+		$action = false,
574
+		$icon_style = false,
575
+		$help_text = false
576
+	) {
577
+
578
+		if (! $page) {
579
+			$page = isset($_REQUEST['page']) && ! empty($_REQUEST['page']) ? sanitize_key($_REQUEST['page']) : $page;
580
+		}
581
+
582
+		if (! $action) {
583
+			$action = isset($_REQUEST['action']) && ! empty($_REQUEST['action']) ? sanitize_key($_REQUEST['action']) : $action;
584
+		}
585
+
586
+		$action = empty($action) ? 'default' : $action;
587
+
588
+
589
+		$help_tab_lnk = $page . '-' . $action . '-' . $help_tab_id;
590
+		$icon         = ! $icon_style ? ' dashicons-editor-help' : $icon_style;
591
+		$help_text    = ! $help_text ? '' : $help_text;
592
+		return '<a id="' . $help_tab_lnk . '" class="ee-clickable dashicons espresso-help-tab-lnk ee-icon-size-22' . $icon . '" title="' . esc_attr__(
593
+			'Click to open the \'Help\' tab for more information about this feature.',
594
+			'event_espresso'
595
+		) . '" > ' . $help_text . ' </a>';
596
+	}
597
+
598
+
599
+	/**
600
+	 * This helper generates the html structure for the jquery joyride plugin with the given params.
601
+	 *
602
+	 * @link http://zurb.com/playground/jquery-joyride-feature-tour-plugin
603
+	 * @see  EE_Admin_Page->_stop_callback() for the construct expected for the $stops param.
604
+	 * @param EE_Help_Tour
605
+	 * @return string         html
606
+	 */
607
+	public static function help_tour_stops_generator(EE_Help_Tour $tour)
608
+	{
609
+		$id    = $tour->get_slug();
610
+		$stops = $tour->get_stops();
611
+
612
+		$content = '<ol style="display:none" id="' . $id . '">';
613
+
614
+		foreach ($stops as $stop) {
615
+			$data_id    = ! empty($stop['id']) ? ' data-id="' . $stop['id'] . '"' : '';
616
+			$data_class = empty($data_id) && ! empty($stop['class']) ? ' data-class="' . $stop['class'] . '"' : '';
617
+
618
+			// if container is set to modal then let's make sure we set the options accordingly
619
+			if (empty($data_id) && empty($data_class)) {
620
+				$stop['options']['modal']  = true;
621
+				$stop['options']['expose'] = true;
622
+			}
623
+
624
+			$custom_class  = ! empty($stop['custom_class']) ? ' class="' . $stop['custom_class'] . '"' : '';
625
+			$button_text   = ! empty($stop['button_text']) ? ' data-button="' . $stop['button_text'] . '"' : '';
626
+			$inner_content = isset($stop['content']) ? $stop['content'] : '';
627
+
628
+			// options
629
+			if (isset($stop['options']) && is_array($stop['options'])) {
630
+				$options = ' data-options="';
631
+				foreach ($stop['options'] as $option => $value) {
632
+					$options .= $option . ':' . $value . ';';
633
+				}
634
+				$options .= '"';
635
+			} else {
636
+				$options = '';
637
+			}
638
+
639
+			// let's put all together
640
+			$content .= '<li' . $data_id . $data_class . $custom_class . $button_text . $options . '>' . $inner_content . '</li>';
641
+		}
642
+
643
+		$content .= '</ol>';
644
+		return $content;
645
+	}
646
+
647
+
648
+	/**
649
+	 * This is a helper method to generate a status legend for a given status array.
650
+	 * Note this will only work if the incoming statuses have a key in the EEM_Status->localized_status() methods
651
+	 * status_array.
652
+	 *
653
+	 * @param  array  $status_array  array of statuses that will make up the legend. In format:
654
+	 *                               array(
655
+	 *                               'status_item' => 'status_name'
656
+	 *                               )
657
+	 * @param  string $active_status This is used to indicate what the active status is IF that is to be highlighted in
658
+	 *                               the legend.
659
+	 * @throws EE_Error
660
+	 * @return string               html structure for status.
661
+	 */
662
+	public static function status_legend($status_array, $active_status = '')
663
+	{
664
+		if (! is_array($status_array)) {
665
+			throw new EE_Error(esc_html__(
666
+				'The EEH_Template::status_legend helper required the incoming status_array argument to be an array!',
667
+				'event_espresso'
668
+			));
669
+		}
670
+
671
+		$setup_array = array();
672
+		foreach ($status_array as $item => $status) {
673
+			$setup_array[ $item ] = array(
674
+				'class'  => 'ee-status-legend ee-status-legend-' . $status,
675
+				'desc'   => EEH_Template::pretty_status($status, false, 'sentence'),
676
+				'status' => $status,
677
+			);
678
+		}
679
+
680
+		$content = '<div class="ee-list-table-legend-container">' . "\n";
681
+		$content .= '<h4 class="status-legend-title">' . esc_html__('Status Legend', 'event_espresso') . '</h4>' . "\n";
682
+		$content .= '<dl class="ee-list-table-legend">' . "\n\t";
683
+		foreach ($setup_array as $item => $details) {
684
+			$active_class = $active_status == $details['status'] ? ' class="ee-is-active-status"' : '';
685
+			$content .= '<dt id="ee-legend-item-tooltip-' . $item . '"' . $active_class . '>' . "\n\t\t";
686
+			$content .= '<span class="' . $details['class'] . '"></span>' . "\n\t\t";
687
+			$content .= '<span class="ee-legend-description">' . $details['desc'] . '</span>' . "\n\t";
688
+			$content .= '</dt>' . "\n";
689
+		}
690
+		$content .= '</dl>' . "\n";
691
+		$content .= '</div>' . "\n";
692
+		return $content;
693
+	}
694
+
695
+
696
+	/**
697
+	 * Gets HTML for laying out a deeply-nested array (and objects) in a format
698
+	 * that's nice for presenting in the wp admin
699
+	 *
700
+	 * @param mixed $data
701
+	 * @return string
702
+	 */
703
+	public static function layout_array_as_table($data)
704
+	{
705
+		if (is_object($data) || $data instanceof __PHP_Incomplete_Class) {
706
+			$data = (array) $data;
707
+		}
708
+		ob_start();
709
+		if (is_array($data)) {
710
+			if (EEH_Array::is_associative_array($data)) {
711
+				?>
712 712
                 <table class="widefat">
713 713
                     <tbody>
714 714
                     <?php
715
-                    foreach ($data as $data_key => $data_values) {
716
-                        ?>
715
+					foreach ($data as $data_key => $data_values) {
716
+						?>
717 717
                         <tr>
718 718
                             <td>
719 719
                                 <?php echo $data_key; ?>
@@ -723,291 +723,291 @@  discard block
 block discarded – undo
723 723
                             </td>
724 724
                         </tr>
725 725
                         <?php
726
-                    } ?>
726
+					} ?>
727 727
                     </tbody>
728 728
                 </table>
729 729
                 <?php
730
-            } else {
731
-                ?>
730
+			} else {
731
+				?>
732 732
                 <ul>
733 733
                     <?php
734
-                    foreach ($data as $datum) {
735
-                        echo "<li>";
736
-                        echo self::layout_array_as_table($datum);
737
-                        echo "</li>";
738
-                    } ?>
734
+					foreach ($data as $datum) {
735
+						echo "<li>";
736
+						echo self::layout_array_as_table($datum);
737
+						echo "</li>";
738
+					} ?>
739 739
                 </ul>
740 740
                 <?php
741
-            }
742
-        } else {
743
-            // simple value
744
-            echo esc_html($data);
745
-        }
746
-        return ob_get_clean();
747
-    }
748
-
749
-
750
-    /**
751
-     * wrapper for self::get_paging_html() that simply echos the generated paging html
752
-     *
753
-     * @since 4.4.0
754
-     * @see   self:get_paging_html() for argument docs.
755
-     * @param        $total_items
756
-     * @param        $current
757
-     * @param        $per_page
758
-     * @param        $url
759
-     * @param bool   $show_num_field
760
-     * @param string $paged_arg_name
761
-     * @param array  $items_label
762
-     * @return string
763
-     */
764
-    public static function paging_html(
765
-        $total_items,
766
-        $current,
767
-        $per_page,
768
-        $url,
769
-        $show_num_field = true,
770
-        $paged_arg_name = 'paged',
771
-        $items_label = array()
772
-    ) {
773
-        echo self::get_paging_html(
774
-            $total_items,
775
-            $current,
776
-            $per_page,
777
-            $url,
778
-            $show_num_field,
779
-            $paged_arg_name,
780
-            $items_label
781
-        );
782
-    }
783
-
784
-
785
-    /**
786
-     * A method for generating paging similar to WP_List_Table
787
-     *
788
-     * @since    4.4.0
789
-     * @see      wp-admin/includes/class-wp-list-table.php WP_List_Table::pagination()
790
-     * @param  integer $total_items     How many total items there are to page.
791
-     * @param  integer $current         What the current page is.
792
-     * @param  integer $per_page        How many items per page.
793
-     * @param  string  $url             What the base url for page links is.
794
-     * @param  boolean $show_num_field  Whether to show the input for changing page number.
795
-     * @param  string  $paged_arg_name  The name of the key for the paged query argument.
796
-     * @param  array   $items_label     An array of singular/plural values for the items label:
797
-     *                                  array(
798
-     *                                  'single' => 'item',
799
-     *                                  'plural' => 'items'
800
-     *                                  )
801
-     * @return  string
802
-     */
803
-    public static function get_paging_html(
804
-        $total_items,
805
-        $current,
806
-        $per_page,
807
-        $url,
808
-        $show_num_field = true,
809
-        $paged_arg_name = 'paged',
810
-        $items_label = array()
811
-    ) {
812
-        $page_links     = array();
813
-        $disable_first  = $disable_last = '';
814
-        $total_items    = (int) $total_items;
815
-        $per_page       = (int) $per_page;
816
-        $current        = (int) $current;
817
-        $paged_arg_name = empty($paged_arg_name) ? 'paged' : sanitize_key($paged_arg_name);
818
-
819
-        // filter items_label
820
-        $items_label = apply_filters(
821
-            'FHEE__EEH_Template__get_paging_html__items_label',
822
-            $items_label
823
-        );
824
-
825
-        if (empty($items_label)
826
-            || ! is_array($items_label)
827
-            || ! isset($items_label['single'])
828
-            || ! isset($items_label['plural'])
829
-        ) {
830
-            $items_label = array(
831
-                'single' => __('1 item', 'event_espresso'),
832
-                'plural' => __('%s items', 'event_espresso'),
833
-            );
834
-        } else {
835
-            $items_label = array(
836
-                'single' => '1 ' . esc_html($items_label['single']),
837
-                'plural' => '%s ' . esc_html($items_label['plural']),
838
-            );
839
-        }
840
-
841
-        $total_pages = ceil($total_items / $per_page);
842
-
843
-        if ($total_pages <= 1) {
844
-            return '';
845
-        }
846
-
847
-        $item_label = $total_items > 1 ? sprintf($items_label['plural'], $total_items) : $items_label['single'];
848
-
849
-        $output = '<span class="displaying-num">' . $item_label . '</span>';
850
-
851
-        if ($current === 1) {
852
-            $disable_first = ' disabled';
853
-        }
854
-        if ($current == $total_pages) {
855
-            $disable_last = ' disabled';
856
-        }
857
-
858
-        $page_links[] = sprintf(
859
-            "<a class='%s' title='%s' href='%s'>%s</a>",
860
-            'first-page' . $disable_first,
861
-            esc_attr__('Go to the first page', 'event_espresso'),
862
-            esc_url(remove_query_arg($paged_arg_name, $url)),
863
-            '&laquo;'
864
-        );
865
-
866
-        $page_links[] = sprintf(
867
-            '<a class="%s" title="%s" href="%s">%s</a>',
868
-            'prev-page' . $disable_first,
869
-            esc_attr__('Go to the previous page', 'event_espresso'),
870
-            esc_url(add_query_arg($paged_arg_name, max(1, $current - 1), $url)),
871
-            '&lsaquo;'
872
-        );
873
-
874
-        if (! $show_num_field) {
875
-            $html_current_page = $current;
876
-        } else {
877
-            $html_current_page = sprintf(
878
-                "<input class='current-page' title='%s' type='text' name=$paged_arg_name value='%s' size='%d' />",
879
-                esc_attr__('Current page', 'event_espresso'),
880
-                $current,
881
-                strlen($total_pages)
882
-            );
883
-        }
884
-
885
-        $html_total_pages = sprintf(
886
-            '<span class="total-pages">%s</span>',
887
-            number_format_i18n($total_pages)
888
-        );
889
-        $page_links[]     = sprintf(
890
-            _x('%3$s%1$s of %2$s%4$s', 'paging', 'event_espresso'),
891
-            $html_current_page,
892
-            $html_total_pages,
893
-            '<span class="paging-input">',
894
-            '</span>'
895
-        );
896
-
897
-        $page_links[] = sprintf(
898
-            '<a class="%s" title="%s" href="%s">%s</a>',
899
-            'next-page' . $disable_last,
900
-            esc_attr__('Go to the next page', 'event_espresso'),
901
-            esc_url(add_query_arg($paged_arg_name, min($total_pages, $current + 1), $url)),
902
-            '&rsaquo;'
903
-        );
904
-
905
-        $page_links[] = sprintf(
906
-            '<a class="%s" title="%s" href="%s">%s</a>',
907
-            'last-page' . $disable_last,
908
-            esc_attr__('Go to the last page', 'event_espresso'),
909
-            esc_url(add_query_arg($paged_arg_name, $total_pages, $url)),
910
-            '&raquo;'
911
-        );
912
-
913
-        $output .= "\n" . '<span class="pagination-links">' . join("\n", $page_links) . '</span>';
914
-        // set page class
915
-        if ($total_pages) {
916
-            $page_class = $total_pages < 2 ? ' one-page' : '';
917
-        } else {
918
-            $page_class = ' no-pages';
919
-        }
920
-
921
-        return '<div class="tablenav"><div class="tablenav-pages' . $page_class . '">' . $output . '</div></div>';
922
-    }
923
-
924
-
925
-    /**
926
-     * @param string $wrap_class
927
-     * @param string $wrap_id
928
-     * @return string
929
-     */
930
-    public static function powered_by_event_espresso($wrap_class = '', $wrap_id = '', array $query_args = array())
931
-    {
932
-        $admin = is_admin() && ! (defined('DOING_AJAX') && DOING_AJAX);
933
-        if (! $admin &&
934
-            ! apply_filters(
935
-                'FHEE__EEH_Template__powered_by_event_espresso__show_reg_footer',
936
-                EE_Registry::instance()->CFG->admin->show_reg_footer
937
-            )
938
-        ) {
939
-            return '';
940
-        }
941
-        $tag        = $admin ? 'span' : 'div';
942
-        $attributes = ! empty($wrap_id) ? " id=\"{$wrap_id}\"" : '';
943
-        $wrap_class = $admin ? "{$wrap_class} float-left" : $wrap_class;
944
-        $attributes .= ! empty($wrap_class)
945
-            ? " class=\"{$wrap_class} powered-by-event-espresso-credit\""
946
-            : ' class="powered-by-event-espresso-credit"';
947
-        $query_args = array_merge(
948
-            array(
949
-                'ap_id'        => EE_Registry::instance()->CFG->admin->affiliate_id(),
950
-                'utm_source'   => 'powered_by_event_espresso',
951
-                'utm_medium'   => 'link',
952
-                'utm_campaign' => 'powered_by',
953
-            ),
954
-            $query_args
955
-        );
956
-        $powered_by = apply_filters(
957
-            'FHEE__EEH_Template__powered_by_event_espresso_text',
958
-            $admin ? 'Event Espresso - ' . EVENT_ESPRESSO_VERSION : 'Event Espresso'
959
-        );
960
-        $url        = add_query_arg($query_args, 'https://eventespresso.com/');
961
-        $url        = apply_filters('FHEE__EEH_Template__powered_by_event_espresso__url', $url);
962
-        return (string) apply_filters(
963
-            'FHEE__EEH_Template__powered_by_event_espresso__html',
964
-            sprintf(
965
-                esc_html_x(
966
-                    '%3$s%1$sOnline event registration and ticketing powered by %2$s%3$s',
967
-                    'Online event registration and ticketing powered by [link to eventespresso.com]',
968
-                    'event_espresso'
969
-                ),
970
-                "<{$tag}{$attributes}>",
971
-                "<a href=\"{$url}\" target=\"_blank\" rel=\"nofollow\">{$powered_by}</a></{$tag}>",
972
-                $admin ? '' : '<br />'
973
-            ),
974
-            $wrap_class,
975
-            $wrap_id
976
-        );
977
-    }
741
+			}
742
+		} else {
743
+			// simple value
744
+			echo esc_html($data);
745
+		}
746
+		return ob_get_clean();
747
+	}
748
+
749
+
750
+	/**
751
+	 * wrapper for self::get_paging_html() that simply echos the generated paging html
752
+	 *
753
+	 * @since 4.4.0
754
+	 * @see   self:get_paging_html() for argument docs.
755
+	 * @param        $total_items
756
+	 * @param        $current
757
+	 * @param        $per_page
758
+	 * @param        $url
759
+	 * @param bool   $show_num_field
760
+	 * @param string $paged_arg_name
761
+	 * @param array  $items_label
762
+	 * @return string
763
+	 */
764
+	public static function paging_html(
765
+		$total_items,
766
+		$current,
767
+		$per_page,
768
+		$url,
769
+		$show_num_field = true,
770
+		$paged_arg_name = 'paged',
771
+		$items_label = array()
772
+	) {
773
+		echo self::get_paging_html(
774
+			$total_items,
775
+			$current,
776
+			$per_page,
777
+			$url,
778
+			$show_num_field,
779
+			$paged_arg_name,
780
+			$items_label
781
+		);
782
+	}
783
+
784
+
785
+	/**
786
+	 * A method for generating paging similar to WP_List_Table
787
+	 *
788
+	 * @since    4.4.0
789
+	 * @see      wp-admin/includes/class-wp-list-table.php WP_List_Table::pagination()
790
+	 * @param  integer $total_items     How many total items there are to page.
791
+	 * @param  integer $current         What the current page is.
792
+	 * @param  integer $per_page        How many items per page.
793
+	 * @param  string  $url             What the base url for page links is.
794
+	 * @param  boolean $show_num_field  Whether to show the input for changing page number.
795
+	 * @param  string  $paged_arg_name  The name of the key for the paged query argument.
796
+	 * @param  array   $items_label     An array of singular/plural values for the items label:
797
+	 *                                  array(
798
+	 *                                  'single' => 'item',
799
+	 *                                  'plural' => 'items'
800
+	 *                                  )
801
+	 * @return  string
802
+	 */
803
+	public static function get_paging_html(
804
+		$total_items,
805
+		$current,
806
+		$per_page,
807
+		$url,
808
+		$show_num_field = true,
809
+		$paged_arg_name = 'paged',
810
+		$items_label = array()
811
+	) {
812
+		$page_links     = array();
813
+		$disable_first  = $disable_last = '';
814
+		$total_items    = (int) $total_items;
815
+		$per_page       = (int) $per_page;
816
+		$current        = (int) $current;
817
+		$paged_arg_name = empty($paged_arg_name) ? 'paged' : sanitize_key($paged_arg_name);
818
+
819
+		// filter items_label
820
+		$items_label = apply_filters(
821
+			'FHEE__EEH_Template__get_paging_html__items_label',
822
+			$items_label
823
+		);
824
+
825
+		if (empty($items_label)
826
+			|| ! is_array($items_label)
827
+			|| ! isset($items_label['single'])
828
+			|| ! isset($items_label['plural'])
829
+		) {
830
+			$items_label = array(
831
+				'single' => __('1 item', 'event_espresso'),
832
+				'plural' => __('%s items', 'event_espresso'),
833
+			);
834
+		} else {
835
+			$items_label = array(
836
+				'single' => '1 ' . esc_html($items_label['single']),
837
+				'plural' => '%s ' . esc_html($items_label['plural']),
838
+			);
839
+		}
840
+
841
+		$total_pages = ceil($total_items / $per_page);
842
+
843
+		if ($total_pages <= 1) {
844
+			return '';
845
+		}
846
+
847
+		$item_label = $total_items > 1 ? sprintf($items_label['plural'], $total_items) : $items_label['single'];
848
+
849
+		$output = '<span class="displaying-num">' . $item_label . '</span>';
850
+
851
+		if ($current === 1) {
852
+			$disable_first = ' disabled';
853
+		}
854
+		if ($current == $total_pages) {
855
+			$disable_last = ' disabled';
856
+		}
857
+
858
+		$page_links[] = sprintf(
859
+			"<a class='%s' title='%s' href='%s'>%s</a>",
860
+			'first-page' . $disable_first,
861
+			esc_attr__('Go to the first page', 'event_espresso'),
862
+			esc_url(remove_query_arg($paged_arg_name, $url)),
863
+			'&laquo;'
864
+		);
865
+
866
+		$page_links[] = sprintf(
867
+			'<a class="%s" title="%s" href="%s">%s</a>',
868
+			'prev-page' . $disable_first,
869
+			esc_attr__('Go to the previous page', 'event_espresso'),
870
+			esc_url(add_query_arg($paged_arg_name, max(1, $current - 1), $url)),
871
+			'&lsaquo;'
872
+		);
873
+
874
+		if (! $show_num_field) {
875
+			$html_current_page = $current;
876
+		} else {
877
+			$html_current_page = sprintf(
878
+				"<input class='current-page' title='%s' type='text' name=$paged_arg_name value='%s' size='%d' />",
879
+				esc_attr__('Current page', 'event_espresso'),
880
+				$current,
881
+				strlen($total_pages)
882
+			);
883
+		}
884
+
885
+		$html_total_pages = sprintf(
886
+			'<span class="total-pages">%s</span>',
887
+			number_format_i18n($total_pages)
888
+		);
889
+		$page_links[]     = sprintf(
890
+			_x('%3$s%1$s of %2$s%4$s', 'paging', 'event_espresso'),
891
+			$html_current_page,
892
+			$html_total_pages,
893
+			'<span class="paging-input">',
894
+			'</span>'
895
+		);
896
+
897
+		$page_links[] = sprintf(
898
+			'<a class="%s" title="%s" href="%s">%s</a>',
899
+			'next-page' . $disable_last,
900
+			esc_attr__('Go to the next page', 'event_espresso'),
901
+			esc_url(add_query_arg($paged_arg_name, min($total_pages, $current + 1), $url)),
902
+			'&rsaquo;'
903
+		);
904
+
905
+		$page_links[] = sprintf(
906
+			'<a class="%s" title="%s" href="%s">%s</a>',
907
+			'last-page' . $disable_last,
908
+			esc_attr__('Go to the last page', 'event_espresso'),
909
+			esc_url(add_query_arg($paged_arg_name, $total_pages, $url)),
910
+			'&raquo;'
911
+		);
912
+
913
+		$output .= "\n" . '<span class="pagination-links">' . join("\n", $page_links) . '</span>';
914
+		// set page class
915
+		if ($total_pages) {
916
+			$page_class = $total_pages < 2 ? ' one-page' : '';
917
+		} else {
918
+			$page_class = ' no-pages';
919
+		}
920
+
921
+		return '<div class="tablenav"><div class="tablenav-pages' . $page_class . '">' . $output . '</div></div>';
922
+	}
923
+
924
+
925
+	/**
926
+	 * @param string $wrap_class
927
+	 * @param string $wrap_id
928
+	 * @return string
929
+	 */
930
+	public static function powered_by_event_espresso($wrap_class = '', $wrap_id = '', array $query_args = array())
931
+	{
932
+		$admin = is_admin() && ! (defined('DOING_AJAX') && DOING_AJAX);
933
+		if (! $admin &&
934
+			! apply_filters(
935
+				'FHEE__EEH_Template__powered_by_event_espresso__show_reg_footer',
936
+				EE_Registry::instance()->CFG->admin->show_reg_footer
937
+			)
938
+		) {
939
+			return '';
940
+		}
941
+		$tag        = $admin ? 'span' : 'div';
942
+		$attributes = ! empty($wrap_id) ? " id=\"{$wrap_id}\"" : '';
943
+		$wrap_class = $admin ? "{$wrap_class} float-left" : $wrap_class;
944
+		$attributes .= ! empty($wrap_class)
945
+			? " class=\"{$wrap_class} powered-by-event-espresso-credit\""
946
+			: ' class="powered-by-event-espresso-credit"';
947
+		$query_args = array_merge(
948
+			array(
949
+				'ap_id'        => EE_Registry::instance()->CFG->admin->affiliate_id(),
950
+				'utm_source'   => 'powered_by_event_espresso',
951
+				'utm_medium'   => 'link',
952
+				'utm_campaign' => 'powered_by',
953
+			),
954
+			$query_args
955
+		);
956
+		$powered_by = apply_filters(
957
+			'FHEE__EEH_Template__powered_by_event_espresso_text',
958
+			$admin ? 'Event Espresso - ' . EVENT_ESPRESSO_VERSION : 'Event Espresso'
959
+		);
960
+		$url        = add_query_arg($query_args, 'https://eventespresso.com/');
961
+		$url        = apply_filters('FHEE__EEH_Template__powered_by_event_espresso__url', $url);
962
+		return (string) apply_filters(
963
+			'FHEE__EEH_Template__powered_by_event_espresso__html',
964
+			sprintf(
965
+				esc_html_x(
966
+					'%3$s%1$sOnline event registration and ticketing powered by %2$s%3$s',
967
+					'Online event registration and ticketing powered by [link to eventespresso.com]',
968
+					'event_espresso'
969
+				),
970
+				"<{$tag}{$attributes}>",
971
+				"<a href=\"{$url}\" target=\"_blank\" rel=\"nofollow\">{$powered_by}</a></{$tag}>",
972
+				$admin ? '' : '<br />'
973
+			),
974
+			$wrap_class,
975
+			$wrap_id
976
+		);
977
+	}
978 978
 }
979 979
 
980 980
 
981 981
 
982 982
 
983 983
 if (! function_exists('espresso_pagination')) {
984
-    /**
985
-     *    espresso_pagination
986
-     *
987
-     * @access    public
988
-     * @return    void
989
-     */
990
-    function espresso_pagination()
991
-    {
992
-        global $wp_query;
993
-        $big        = 999999999; // need an unlikely integer
994
-        $pagination = paginate_links(
995
-            array(
996
-                'base'         => str_replace($big, '%#%', esc_url(get_pagenum_link($big))),
997
-                'format'       => '?paged=%#%',
998
-                'current'      => max(1, get_query_var('paged')),
999
-                'total'        => $wp_query->max_num_pages,
1000
-                'show_all'     => true,
1001
-                'end_size'     => 10,
1002
-                'mid_size'     => 6,
1003
-                'prev_next'    => true,
1004
-                'prev_text'    => __('&lsaquo; PREV', 'event_espresso'),
1005
-                'next_text'    => __('NEXT &rsaquo;', 'event_espresso'),
1006
-                'type'         => 'plain',
1007
-                'add_args'     => false,
1008
-                'add_fragment' => '',
1009
-            )
1010
-        );
1011
-        echo ! empty($pagination) ? '<div class="ee-pagination-dv ee-clear-float">' . $pagination . '</div>' : '';
1012
-    }
984
+	/**
985
+	 *    espresso_pagination
986
+	 *
987
+	 * @access    public
988
+	 * @return    void
989
+	 */
990
+	function espresso_pagination()
991
+	{
992
+		global $wp_query;
993
+		$big        = 999999999; // need an unlikely integer
994
+		$pagination = paginate_links(
995
+			array(
996
+				'base'         => str_replace($big, '%#%', esc_url(get_pagenum_link($big))),
997
+				'format'       => '?paged=%#%',
998
+				'current'      => max(1, get_query_var('paged')),
999
+				'total'        => $wp_query->max_num_pages,
1000
+				'show_all'     => true,
1001
+				'end_size'     => 10,
1002
+				'mid_size'     => 6,
1003
+				'prev_next'    => true,
1004
+				'prev_text'    => __('&lsaquo; PREV', 'event_espresso'),
1005
+				'next_text'    => __('NEXT &rsaquo;', 'event_espresso'),
1006
+				'type'         => 'plain',
1007
+				'add_args'     => false,
1008
+				'add_fragment' => '',
1009
+			)
1010
+		);
1011
+		echo ! empty($pagination) ? '<div class="ee-pagination-dv ee-clear-float">' . $pagination . '</div>' : '';
1012
+	}
1013 1013
 }
1014 1014
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +74 added lines, -74 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
 use EventEspresso\core\exceptions\InvalidInterfaceException;
5 5
 use EventEspresso\core\services\loaders\LoaderFactory;
6 6
 
7
-if (! function_exists('espresso_get_template_part')) {
7
+if ( ! function_exists('espresso_get_template_part')) {
8 8
     /**
9 9
      * espresso_get_template_part
10 10
      * basically a copy of the WordPress get_template_part() function but uses EEH_Template::locate_template() instead, and doesn't add base versions of files
@@ -21,7 +21,7 @@  discard block
 block discarded – undo
21 21
 }
22 22
 
23 23
 
24
-if (! function_exists('espresso_get_object_css_class')) {
24
+if ( ! function_exists('espresso_get_object_css_class')) {
25 25
     /**
26 26
      * espresso_get_object_css_class - attempts to generate a css class based on the type of EE object passed
27 27
      *
@@ -69,9 +69,9 @@  discard block
 block discarded – undo
69 69
      */
70 70
     public static function load_espresso_theme_functions()
71 71
     {
72
-        if (! defined('EE_THEME_FUNCTIONS_LOADED')) {
73
-            if (is_readable(EE_PUBLIC . EE_Config::get_current_theme() . DS . 'functions.php')) {
74
-                require_once(EE_PUBLIC . EE_Config::get_current_theme() . DS . 'functions.php');
72
+        if ( ! defined('EE_THEME_FUNCTIONS_LOADED')) {
73
+            if (is_readable(EE_PUBLIC.EE_Config::get_current_theme().DS.'functions.php')) {
74
+                require_once(EE_PUBLIC.EE_Config::get_current_theme().DS.'functions.php');
75 75
             }
76 76
         }
77 77
     }
@@ -85,16 +85,16 @@  discard block
 block discarded – undo
85 85
     public static function get_espresso_themes()
86 86
     {
87 87
         if (empty(EEH_Template::$_espresso_themes)) {
88
-            $espresso_themes = glob(EE_PUBLIC . '*', GLOB_ONLYDIR);
88
+            $espresso_themes = glob(EE_PUBLIC.'*', GLOB_ONLYDIR);
89 89
             if (empty($espresso_themes)) {
90 90
                 return array();
91 91
             }
92 92
             if (($key = array_search('global_assets', $espresso_themes)) !== false) {
93
-                unset($espresso_themes[ $key ]);
93
+                unset($espresso_themes[$key]);
94 94
             }
95 95
             EEH_Template::$_espresso_themes = array();
96 96
             foreach ($espresso_themes as $espresso_theme) {
97
-                EEH_Template::$_espresso_themes[ basename($espresso_theme) ] = $espresso_theme;
97
+                EEH_Template::$_espresso_themes[basename($espresso_theme)] = $espresso_theme;
98 98
             }
99 99
         }
100 100
         return EEH_Template::$_espresso_themes;
@@ -205,10 +205,10 @@  discard block
 block discarded – undo
205 205
                 // get array of EE Custom Post Types
206 206
                 $EE_CPTs = $custom_post_types->getDefinitions();
207 207
                 // build template name based on request
208
-                if (isset($EE_CPTs[ $post_type ])) {
208
+                if (isset($EE_CPTs[$post_type])) {
209 209
                     $archive_or_single = is_archive() ? 'archive' : '';
210 210
                     $archive_or_single = is_single() ? 'single' : $archive_or_single;
211
-                    $templates         = $archive_or_single . '-' . $post_type . '.php';
211
+                    $templates         = $archive_or_single.'-'.$post_type.'.php';
212 212
                 }
213 213
             }
214 214
             // currently active EE template theme
@@ -217,18 +217,18 @@  discard block
 block discarded – undo
217 217
             // array of paths to folders that may contain templates
218 218
             $template_folder_paths = array(
219 219
                 // first check the /wp-content/uploads/espresso/templates/(current EE theme)/  folder for an EE theme template file
220
-                EVENT_ESPRESSO_TEMPLATE_DIR . $current_theme,
220
+                EVENT_ESPRESSO_TEMPLATE_DIR.$current_theme,
221 221
                 // then in the root of the /wp-content/uploads/espresso/templates/ folder
222 222
                 EVENT_ESPRESSO_TEMPLATE_DIR,
223 223
             );
224 224
 
225 225
             // add core plugin folders for checking only if we're not $check_if_custom
226
-            if (! $check_if_custom) {
227
-                $core_paths            = array(
226
+            if ( ! $check_if_custom) {
227
+                $core_paths = array(
228 228
                     // in the  /wp-content/plugins/(EE4 folder)/public/(current EE theme)/ folder within the plugin
229
-                    EE_PUBLIC . $current_theme,
229
+                    EE_PUBLIC.$current_theme,
230 230
                     // in the  /wp-content/plugins/(EE4 folder)/core/templates/(current EE theme)/ folder within the plugin
231
-                    EE_TEMPLATES . $current_theme,
231
+                    EE_TEMPLATES.$current_theme,
232 232
                     // or maybe relative from the plugin root: /wp-content/plugins/(EE4 folder)/
233 233
                     EE_PLUGIN_DIR_PATH,
234 234
                 );
@@ -261,10 +261,10 @@  discard block
 block discarded – undo
261 261
                     );
262 262
                     if ($common_base_path !== '') {
263 263
                         // both paths have a common base, so just tack the filename onto our search path
264
-                        $resolved_path = EEH_File::end_with_directory_separator($template_folder_path) . $file_name;
264
+                        $resolved_path = EEH_File::end_with_directory_separator($template_folder_path).$file_name;
265 265
                     } else {
266 266
                         // no common base path, so let's just concatenate
267
-                        $resolved_path = EEH_File::end_with_directory_separator($template_folder_path) . $template;
267
+                        $resolved_path = EEH_File::end_with_directory_separator($template_folder_path).$template;
268 268
                     }
269 269
                     // build up our template locations array by adding our resolved paths
270 270
                     $full_template_paths[] = $resolved_path;
@@ -272,7 +272,7 @@  discard block
 block discarded – undo
272 272
                 // if $template is an absolute path, then we'll tack it onto the start of our array so that it gets searched first
273 273
                 array_unshift($full_template_paths, $template);
274 274
                 // path to the directory of the current theme: /wp-content/themes/(current WP theme)/
275
-                array_unshift($full_template_paths, get_stylesheet_directory() . DS . $file_name);
275
+                array_unshift($full_template_paths, get_stylesheet_directory().DS.$file_name);
276 276
             }
277 277
             // filter final array of full template paths
278 278
             $full_template_paths = apply_filters(
@@ -361,11 +361,11 @@  discard block
 block discarded – undo
361 361
         $template_args = (array) apply_filters('FHEE__EEH_Template__display_template__template_args', $template_args);
362 362
 
363 363
         // you gimme nuttin - YOU GET NUTTIN !!
364
-        if (! $template_path || ! is_readable($template_path)) {
364
+        if ( ! $template_path || ! is_readable($template_path)) {
365 365
             return '';
366 366
         }
367 367
         // if $template_args are not in an array, then make it so
368
-        if (! is_array($template_args) && ! is_object($template_args)) {
368
+        if ( ! is_array($template_args) && ! is_object($template_args)) {
369 369
             $template_args = array($template_args);
370 370
         }
371 371
         extract($template_args, EXTR_SKIP);
@@ -403,11 +403,11 @@  discard block
 block discarded – undo
403 403
     public static function get_object_css_class($object = null, $prefix = '', $suffix = '')
404 404
     {
405 405
         // in the beginning...
406
-        $prefix = ! empty($prefix) ? rtrim($prefix, '-') . '-' : '';
406
+        $prefix = ! empty($prefix) ? rtrim($prefix, '-').'-' : '';
407 407
         // da muddle
408 408
         $class = '';
409 409
         // the end
410
-        $suffix = ! empty($suffix) ? '-' . ltrim($suffix, '-') : '';
410
+        $suffix = ! empty($suffix) ? '-'.ltrim($suffix, '-') : '';
411 411
         // is the passed object an EE object ?
412 412
         if ($object instanceof EE_Base_Class) {
413 413
             // grab the exact type of object
@@ -417,10 +417,10 @@  discard block
 block discarded – undo
417 417
                 // no specifics just yet...
418 418
                 default:
419 419
                     $class = strtolower(str_replace('_', '-', $obj_class));
420
-                    $class .= method_exists($obj_class, 'name') ? '-' . sanitize_title($object->name()) : '';
420
+                    $class .= method_exists($obj_class, 'name') ? '-'.sanitize_title($object->name()) : '';
421 421
             }
422 422
         }
423
-        return $prefix . $class . $suffix;
423
+        return $prefix.$class.$suffix;
424 424
     }
425 425
 
426 426
 
@@ -461,7 +461,7 @@  discard block
 block discarded – undo
461 461
             // was a country ISO code passed ? if so generate currency config object for that country
462 462
             $mny = $CNT_ISO !== '' ? new EE_Currency_Config($CNT_ISO) : null;
463 463
             // verify results
464
-            if (! $mny instanceof EE_Currency_Config) {
464
+            if ( ! $mny instanceof EE_Currency_Config) {
465 465
                 // set default config country currency settings
466 466
                 $mny = EE_Registry::instance()->CFG->currency instanceof EE_Currency_Config
467 467
                     ? EE_Registry::instance()->CFG->currency
@@ -470,23 +470,23 @@  discard block
 block discarded – undo
470 470
             // format float
471 471
             $amount_formatted = number_format($amount, $mny->dec_plc, $mny->dec_mrk, $mny->thsnds);
472 472
             // add formatting ?
473
-            if (! $return_raw) {
473
+            if ( ! $return_raw) {
474 474
                 // add currency sign
475 475
                 if ($mny->sign_b4) {
476 476
                     if ($amount >= 0) {
477
-                        $amount_formatted = $mny->sign . $amount_formatted;
477
+                        $amount_formatted = $mny->sign.$amount_formatted;
478 478
                     } else {
479
-                        $amount_formatted = '-' . $mny->sign . str_replace('-', '', $amount_formatted);
479
+                        $amount_formatted = '-'.$mny->sign.str_replace('-', '', $amount_formatted);
480 480
                     }
481 481
                 } else {
482
-                    $amount_formatted = $amount_formatted . $mny->sign;
482
+                    $amount_formatted = $amount_formatted.$mny->sign;
483 483
                 }
484 484
 
485 485
                 // filter to allow global setting of display_code
486 486
                 $display_code = apply_filters('FHEE__EEH_Template__format_currency__display_code', $display_code);
487 487
 
488 488
                 // add currency code ?
489
-                $amount_formatted = $display_code ? $amount_formatted . ' <span class="' . $cur_code_span_class . '">(' . $mny->code . ')</span>' : $amount_formatted;
489
+                $amount_formatted = $display_code ? $amount_formatted.' <span class="'.$cur_code_span_class.'">('.$mny->code.')</span>' : $amount_formatted;
490 490
             }
491 491
             // filter results
492 492
             $amount_formatted = apply_filters(
@@ -523,7 +523,7 @@  discard block
 block discarded – undo
523 523
             $plural,
524 524
             $schema
525 525
         );
526
-        return $status[ $status_id ];
526
+        return $status[$status_id];
527 527
     }
528 528
 
529 529
 
@@ -540,19 +540,19 @@  discard block
 block discarded – undo
540 540
     public static function get_button_or_link($url, $label, $class = 'button-primary', $icon = '', $title = '')
541 541
     {
542 542
         $icon_html = '';
543
-        if (! empty($icon)) {
543
+        if ( ! empty($icon)) {
544 544
             $dashicons = preg_split("(ee-icon |dashicons )", $icon);
545 545
             $dashicons = array_filter($dashicons);
546 546
             $count     = count($dashicons);
547 547
             $icon_html .= $count > 1 ? '<span class="ee-composite-dashicon">' : '';
548 548
             foreach ($dashicons as $dashicon) {
549 549
                 $type = strpos($dashicon, 'ee-icon') !== false ? 'ee-icon ' : 'dashicons ';
550
-                $icon_html .= '<span class="' . $type . $dashicon . '"></span>';
550
+                $icon_html .= '<span class="'.$type.$dashicon.'"></span>';
551 551
             }
552 552
             $icon_html .= $count > 1 ? '</span>' : '';
553 553
         }
554
-        $label  = ! empty($icon) ? $icon_html . $label : $label;
555
-        $button = '<a id="' . sanitize_title_with_dashes($label) . '" href="' . esc_url($url) . '" class="' . $class . '" title="' . $title . '">' . $label . '</a>';
554
+        $label  = ! empty($icon) ? $icon_html.$label : $label;
555
+        $button = '<a id="'.sanitize_title_with_dashes($label).'" href="'.esc_url($url).'" class="'.$class.'" title="'.$title.'">'.$label.'</a>';
556 556
         return $button;
557 557
     }
558 558
 
@@ -575,24 +575,24 @@  discard block
 block discarded – undo
575 575
         $help_text = false
576 576
     ) {
577 577
 
578
-        if (! $page) {
578
+        if ( ! $page) {
579 579
             $page = isset($_REQUEST['page']) && ! empty($_REQUEST['page']) ? sanitize_key($_REQUEST['page']) : $page;
580 580
         }
581 581
 
582
-        if (! $action) {
582
+        if ( ! $action) {
583 583
             $action = isset($_REQUEST['action']) && ! empty($_REQUEST['action']) ? sanitize_key($_REQUEST['action']) : $action;
584 584
         }
585 585
 
586 586
         $action = empty($action) ? 'default' : $action;
587 587
 
588 588
 
589
-        $help_tab_lnk = $page . '-' . $action . '-' . $help_tab_id;
589
+        $help_tab_lnk = $page.'-'.$action.'-'.$help_tab_id;
590 590
         $icon         = ! $icon_style ? ' dashicons-editor-help' : $icon_style;
591 591
         $help_text    = ! $help_text ? '' : $help_text;
592
-        return '<a id="' . $help_tab_lnk . '" class="ee-clickable dashicons espresso-help-tab-lnk ee-icon-size-22' . $icon . '" title="' . esc_attr__(
592
+        return '<a id="'.$help_tab_lnk.'" class="ee-clickable dashicons espresso-help-tab-lnk ee-icon-size-22'.$icon.'" title="'.esc_attr__(
593 593
             'Click to open the \'Help\' tab for more information about this feature.',
594 594
             'event_espresso'
595
-        ) . '" > ' . $help_text . ' </a>';
595
+        ).'" > '.$help_text.' </a>';
596 596
     }
597 597
 
598 598
 
@@ -609,11 +609,11 @@  discard block
 block discarded – undo
609 609
         $id    = $tour->get_slug();
610 610
         $stops = $tour->get_stops();
611 611
 
612
-        $content = '<ol style="display:none" id="' . $id . '">';
612
+        $content = '<ol style="display:none" id="'.$id.'">';
613 613
 
614 614
         foreach ($stops as $stop) {
615
-            $data_id    = ! empty($stop['id']) ? ' data-id="' . $stop['id'] . '"' : '';
616
-            $data_class = empty($data_id) && ! empty($stop['class']) ? ' data-class="' . $stop['class'] . '"' : '';
615
+            $data_id    = ! empty($stop['id']) ? ' data-id="'.$stop['id'].'"' : '';
616
+            $data_class = empty($data_id) && ! empty($stop['class']) ? ' data-class="'.$stop['class'].'"' : '';
617 617
 
618 618
             // if container is set to modal then let's make sure we set the options accordingly
619 619
             if (empty($data_id) && empty($data_class)) {
@@ -621,15 +621,15 @@  discard block
 block discarded – undo
621 621
                 $stop['options']['expose'] = true;
622 622
             }
623 623
 
624
-            $custom_class  = ! empty($stop['custom_class']) ? ' class="' . $stop['custom_class'] . '"' : '';
625
-            $button_text   = ! empty($stop['button_text']) ? ' data-button="' . $stop['button_text'] . '"' : '';
624
+            $custom_class  = ! empty($stop['custom_class']) ? ' class="'.$stop['custom_class'].'"' : '';
625
+            $button_text   = ! empty($stop['button_text']) ? ' data-button="'.$stop['button_text'].'"' : '';
626 626
             $inner_content = isset($stop['content']) ? $stop['content'] : '';
627 627
 
628 628
             // options
629 629
             if (isset($stop['options']) && is_array($stop['options'])) {
630 630
                 $options = ' data-options="';
631 631
                 foreach ($stop['options'] as $option => $value) {
632
-                    $options .= $option . ':' . $value . ';';
632
+                    $options .= $option.':'.$value.';';
633 633
                 }
634 634
                 $options .= '"';
635 635
             } else {
@@ -637,7 +637,7 @@  discard block
 block discarded – undo
637 637
             }
638 638
 
639 639
             // let's put all together
640
-            $content .= '<li' . $data_id . $data_class . $custom_class . $button_text . $options . '>' . $inner_content . '</li>';
640
+            $content .= '<li'.$data_id.$data_class.$custom_class.$button_text.$options.'>'.$inner_content.'</li>';
641 641
         }
642 642
 
643 643
         $content .= '</ol>';
@@ -661,7 +661,7 @@  discard block
 block discarded – undo
661 661
      */
662 662
     public static function status_legend($status_array, $active_status = '')
663 663
     {
664
-        if (! is_array($status_array)) {
664
+        if ( ! is_array($status_array)) {
665 665
             throw new EE_Error(esc_html__(
666 666
                 'The EEH_Template::status_legend helper required the incoming status_array argument to be an array!',
667 667
                 'event_espresso'
@@ -670,25 +670,25 @@  discard block
 block discarded – undo
670 670
 
671 671
         $setup_array = array();
672 672
         foreach ($status_array as $item => $status) {
673
-            $setup_array[ $item ] = array(
674
-                'class'  => 'ee-status-legend ee-status-legend-' . $status,
673
+            $setup_array[$item] = array(
674
+                'class'  => 'ee-status-legend ee-status-legend-'.$status,
675 675
                 'desc'   => EEH_Template::pretty_status($status, false, 'sentence'),
676 676
                 'status' => $status,
677 677
             );
678 678
         }
679 679
 
680
-        $content = '<div class="ee-list-table-legend-container">' . "\n";
681
-        $content .= '<h4 class="status-legend-title">' . esc_html__('Status Legend', 'event_espresso') . '</h4>' . "\n";
682
-        $content .= '<dl class="ee-list-table-legend">' . "\n\t";
680
+        $content = '<div class="ee-list-table-legend-container">'."\n";
681
+        $content .= '<h4 class="status-legend-title">'.esc_html__('Status Legend', 'event_espresso').'</h4>'."\n";
682
+        $content .= '<dl class="ee-list-table-legend">'."\n\t";
683 683
         foreach ($setup_array as $item => $details) {
684 684
             $active_class = $active_status == $details['status'] ? ' class="ee-is-active-status"' : '';
685
-            $content .= '<dt id="ee-legend-item-tooltip-' . $item . '"' . $active_class . '>' . "\n\t\t";
686
-            $content .= '<span class="' . $details['class'] . '"></span>' . "\n\t\t";
687
-            $content .= '<span class="ee-legend-description">' . $details['desc'] . '</span>' . "\n\t";
688
-            $content .= '</dt>' . "\n";
685
+            $content .= '<dt id="ee-legend-item-tooltip-'.$item.'"'.$active_class.'>'."\n\t\t";
686
+            $content .= '<span class="'.$details['class'].'"></span>'."\n\t\t";
687
+            $content .= '<span class="ee-legend-description">'.$details['desc'].'</span>'."\n\t";
688
+            $content .= '</dt>'."\n";
689 689
         }
690
-        $content .= '</dl>' . "\n";
691
-        $content .= '</div>' . "\n";
690
+        $content .= '</dl>'."\n";
691
+        $content .= '</div>'."\n";
692 692
         return $content;
693 693
     }
694 694
 
@@ -833,8 +833,8 @@  discard block
 block discarded – undo
833 833
             );
834 834
         } else {
835 835
             $items_label = array(
836
-                'single' => '1 ' . esc_html($items_label['single']),
837
-                'plural' => '%s ' . esc_html($items_label['plural']),
836
+                'single' => '1 '.esc_html($items_label['single']),
837
+                'plural' => '%s '.esc_html($items_label['plural']),
838 838
             );
839 839
         }
840 840
 
@@ -846,7 +846,7 @@  discard block
 block discarded – undo
846 846
 
847 847
         $item_label = $total_items > 1 ? sprintf($items_label['plural'], $total_items) : $items_label['single'];
848 848
 
849
-        $output = '<span class="displaying-num">' . $item_label . '</span>';
849
+        $output = '<span class="displaying-num">'.$item_label.'</span>';
850 850
 
851 851
         if ($current === 1) {
852 852
             $disable_first = ' disabled';
@@ -857,7 +857,7 @@  discard block
 block discarded – undo
857 857
 
858 858
         $page_links[] = sprintf(
859 859
             "<a class='%s' title='%s' href='%s'>%s</a>",
860
-            'first-page' . $disable_first,
860
+            'first-page'.$disable_first,
861 861
             esc_attr__('Go to the first page', 'event_espresso'),
862 862
             esc_url(remove_query_arg($paged_arg_name, $url)),
863 863
             '&laquo;'
@@ -865,13 +865,13 @@  discard block
 block discarded – undo
865 865
 
866 866
         $page_links[] = sprintf(
867 867
             '<a class="%s" title="%s" href="%s">%s</a>',
868
-            'prev-page' . $disable_first,
868
+            'prev-page'.$disable_first,
869 869
             esc_attr__('Go to the previous page', 'event_espresso'),
870 870
             esc_url(add_query_arg($paged_arg_name, max(1, $current - 1), $url)),
871 871
             '&lsaquo;'
872 872
         );
873 873
 
874
-        if (! $show_num_field) {
874
+        if ( ! $show_num_field) {
875 875
             $html_current_page = $current;
876 876
         } else {
877 877
             $html_current_page = sprintf(
@@ -886,7 +886,7 @@  discard block
 block discarded – undo
886 886
             '<span class="total-pages">%s</span>',
887 887
             number_format_i18n($total_pages)
888 888
         );
889
-        $page_links[]     = sprintf(
889
+        $page_links[] = sprintf(
890 890
             _x('%3$s%1$s of %2$s%4$s', 'paging', 'event_espresso'),
891 891
             $html_current_page,
892 892
             $html_total_pages,
@@ -896,7 +896,7 @@  discard block
 block discarded – undo
896 896
 
897 897
         $page_links[] = sprintf(
898 898
             '<a class="%s" title="%s" href="%s">%s</a>',
899
-            'next-page' . $disable_last,
899
+            'next-page'.$disable_last,
900 900
             esc_attr__('Go to the next page', 'event_espresso'),
901 901
             esc_url(add_query_arg($paged_arg_name, min($total_pages, $current + 1), $url)),
902 902
             '&rsaquo;'
@@ -904,13 +904,13 @@  discard block
 block discarded – undo
904 904
 
905 905
         $page_links[] = sprintf(
906 906
             '<a class="%s" title="%s" href="%s">%s</a>',
907
-            'last-page' . $disable_last,
907
+            'last-page'.$disable_last,
908 908
             esc_attr__('Go to the last page', 'event_espresso'),
909 909
             esc_url(add_query_arg($paged_arg_name, $total_pages, $url)),
910 910
             '&raquo;'
911 911
         );
912 912
 
913
-        $output .= "\n" . '<span class="pagination-links">' . join("\n", $page_links) . '</span>';
913
+        $output .= "\n".'<span class="pagination-links">'.join("\n", $page_links).'</span>';
914 914
         // set page class
915 915
         if ($total_pages) {
916 916
             $page_class = $total_pages < 2 ? ' one-page' : '';
@@ -918,7 +918,7 @@  discard block
 block discarded – undo
918 918
             $page_class = ' no-pages';
919 919
         }
920 920
 
921
-        return '<div class="tablenav"><div class="tablenav-pages' . $page_class . '">' . $output . '</div></div>';
921
+        return '<div class="tablenav"><div class="tablenav-pages'.$page_class.'">'.$output.'</div></div>';
922 922
     }
923 923
 
924 924
 
@@ -930,7 +930,7 @@  discard block
 block discarded – undo
930 930
     public static function powered_by_event_espresso($wrap_class = '', $wrap_id = '', array $query_args = array())
931 931
     {
932 932
         $admin = is_admin() && ! (defined('DOING_AJAX') && DOING_AJAX);
933
-        if (! $admin &&
933
+        if ( ! $admin &&
934 934
             ! apply_filters(
935 935
                 'FHEE__EEH_Template__powered_by_event_espresso__show_reg_footer',
936 936
                 EE_Registry::instance()->CFG->admin->show_reg_footer
@@ -955,7 +955,7 @@  discard block
 block discarded – undo
955 955
         );
956 956
         $powered_by = apply_filters(
957 957
             'FHEE__EEH_Template__powered_by_event_espresso_text',
958
-            $admin ? 'Event Espresso - ' . EVENT_ESPRESSO_VERSION : 'Event Espresso'
958
+            $admin ? 'Event Espresso - '.EVENT_ESPRESSO_VERSION : 'Event Espresso'
959 959
         );
960 960
         $url        = add_query_arg($query_args, 'https://eventespresso.com/');
961 961
         $url        = apply_filters('FHEE__EEH_Template__powered_by_event_espresso__url', $url);
@@ -980,7 +980,7 @@  discard block
 block discarded – undo
980 980
 
981 981
 
982 982
 
983
-if (! function_exists('espresso_pagination')) {
983
+if ( ! function_exists('espresso_pagination')) {
984 984
     /**
985 985
      *    espresso_pagination
986 986
      *
@@ -1008,6 +1008,6 @@  discard block
 block discarded – undo
1008 1008
                 'add_fragment' => '',
1009 1009
             )
1010 1010
         );
1011
-        echo ! empty($pagination) ? '<div class="ee-pagination-dv ee-clear-float">' . $pagination . '</div>' : '';
1011
+        echo ! empty($pagination) ? '<div class="ee-pagination-dv ee-clear-float">'.$pagination.'</div>' : '';
1012 1012
     }
1013 1013
 }
1014 1014
\ No newline at end of file
Please login to merge, or discard this patch.
core/helpers/EEH_Template_Validator.helper.php 3 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -130,7 +130,7 @@  discard block
 block discarded – undo
130 130
     /**
131 131
      * For verifying that a variable is indeed an array, else throw an EE_Error
132 132
      * @param type $variable_to_test
133
-     * @param type $variable_name
133
+     * @param string $variable_name
134 134
      * @param type $allow_empty one of 'allow_empty' or 'do_not_allow_empty'
135 135
      * @return void
136 136
      * @throws EE_Error
@@ -161,7 +161,7 @@  discard block
 block discarded – undo
161 161
      * for verifying that a variable is one of the string optiosn supplied
162 162
      * @param mixed $variable_to_test
163 163
      * @param mixed $variable_name the name you've given the variable. Eg, '$foo'. THis helps in producing better error messages
164
-     * @param array $string_options an array of acceptable values
164
+     * @param string[] $string_options an array of acceptable values
165 165
      * @return void
166 166
      * @throws EE_Error
167 167
      */
Please login to merge, or discard this patch.
Indentation   +148 added lines, -148 removed lines patch added patch discarded remove patch
@@ -28,152 +28,152 @@
 block discarded – undo
28 28
     
29 29
     
30 30
     
31
-    /**
32
-     * Throws an EE_Error if $variabel_to_test isn't an array of objects of class $class_name
33
-     * @param mixed $variable_to_test
34
-     * @param string $name_of_variable helpful in throwing intelligent errors
35
-     * @param string $class_name eg EE_Answer, EE_Transaction, etc.
36
-     * @param string $allow_null one of 'allow_null', or 'do_not_allow_null'
37
-     * @return void
38
-     * @throws EE_Error (indirectly)
39
-     */
40
-    public static function verify_is_array_of($variable_to_test, $name_of_variable, $class_name, $allow_null = 'allow_null')
41
-    {
42
-        if (!WP_DEBUG) {
43
-            return;
44
-        }
45
-        self::verify_argument_is_one_of($allow_null, 'allow_null', array('allow_null','do_not_allow_null'));
46
-        if ('allow_null' == $allow_null && is_null($variable_to_test)) {
47
-            return;
48
-        }
49
-        self::verify_is_array($variable_to_test, $name_of_variable);
50
-        foreach ($variable_to_test as $key => $array_element) {
51
-            self::verify_instanceof($array_element, $key, $class_name);
52
-        }
53
-    }
54
-    
55
-    
56
-    
57
-    
58
-    
59
-    /**
60
-     * throws an EE_Error if $variable_to_test is null
61
-     * @param mixed $variable_to_test
62
-     * @param string $name_of_variable helpful for throwing intelligent errors
63
-     * @return void
64
-     * @throws EE_Error
65
-     */
66
-    public static function verify_isnt_null($variable_to_test, $name_of_variable)
67
-    {
68
-        if (!WP_DEBUG) {
69
-            return;
70
-        }
71
-        if ($variable_to_test==null && $variable_to_test!=0 && $variable_to_test!=false) {
72
-            $error[]=__('Variable named %s is null.', 'event_espresso');
73
-            $error[]=__("Consider looking at the stack trace to see why it wasn't set.", 'event_espresso');
74
-            throw new EE_Error(sprintf(implode(",", $error), $name_of_variable, $name_of_variable));
75
-        }
76
-    }
77
-    
78
-    /**
79
-     * When WP_DEBUG is activted, throws an error if $expression_to_test is false.
80
-     * @param boolean $expression_to_test
81
-     * @param string $expression_string_representation a string representation of your expression
82
-     * for example, if your expression were $var1==23, then this should be '$var1==23'
83
-     * @return void
84
-     * @throws EE_Error
85
-     */
86
-    public static function verify_is_true($expression_to_test, $expression_string_representation)
87
-    {
88
-        if (!WP_DEBUG) {
89
-            return;
90
-        }
91
-        if (!$expression_to_test) {
92
-            $error[]=__('Template error.', 'event_espresso');
93
-            $error[]=__("%s evaluated to false, but it must be true!", 'event_espresso');
94
-            throw new EE_Error(sprintf(implode(",", $error), $expression_string_representation));
95
-        }
96
-    }
97
-    
98
-    
99
-    
100
-    
101
-    
102
-    /**
103
-     * For verifying that a variable is indeed an object of class $class_name
104
-     * @param mixed $variable_to_test
105
-     * @param string $name_of_variable helpful when throwing errors
106
-     * @param string $class_name eg, EE_Answer,
107
-     * @return void
108
-     * @throws EE_Error
109
-     */
110
-    public static function verify_instanceof($variable_to_test, $name_of_variable, $class_name, $allow_null = 'do_not_allow_null')
111
-    {
112
-        if (!WP_DEBUG) {
113
-            return;
114
-        }
115
-        self::verify_argument_is_one_of($allow_null, 'allow_null', array('allow_null','do_not_allow_null'));
116
-        if ($allow_null == 'allow_null' && is_null($variable_to_test)) {
117
-            return;
118
-        }
119
-        if ($variable_to_test == null ||  ! ( $variable_to_test instanceof $class_name )) {
120
-            $msg[]=__('Variable %s is not of the correct type.', 'event_espresso');
121
-            $msg[]=__("It should be of type %s", 'event_espresso');
122
-            throw new EE_Error(sprintf(implode(",", $msg), $name_of_variable, $name_of_variable, $class_name));
123
-        }
124
-    }
125
-    
126
-    
127
-    
128
-    
129
-    
130
-    /**
131
-     * For verifying that a variable is indeed an array, else throw an EE_Error
132
-     * @param type $variable_to_test
133
-     * @param type $variable_name
134
-     * @param type $allow_empty one of 'allow_empty' or 'do_not_allow_empty'
135
-     * @return void
136
-     * @throws EE_Error
137
-     */
138
-    public static function verify_is_array($variable_to_test, $variable_name, $allow_empty = 'allow_empty')
139
-    {
140
-        if (!WP_DEBUG) {
141
-            return;
142
-        }
143
-        self::verify_argument_is_one_of($allow_empty, $variable_name, array('allow_empty','do_not_allow_empty'));
144
-        if (empty($variable_to_test) && 'allow_empty'==$allow_empty) {
145
-            return;
146
-        }
147
-        if (!is_array($variable_to_test)) {
148
-            $error[]=__('Variable %s should be an array, but it is not.', 'event_espresso');
149
-            $error[]=__("Its value is, instead '%s'", 'event_espresso');
150
-            throw new EE_Error(sprintf(implode(",", $error), $variable_name, $variable_name, $variable_to_test));
151
-        }
152
-    }
153
-    
154
-    
155
-    
156
-    
157
-    
158
-    
159
-    
160
-    /**
161
-     * for verifying that a variable is one of the string optiosn supplied
162
-     * @param mixed $variable_to_test
163
-     * @param mixed $variable_name the name you've given the variable. Eg, '$foo'. THis helps in producing better error messages
164
-     * @param array $string_options an array of acceptable values
165
-     * @return void
166
-     * @throws EE_Error
167
-     */
168
-    public static function verify_argument_is_one_of($variable_to_test, $variable_name, $string_options)
169
-    {
170
-        if (!WP_DEBUG) {
171
-            return;
172
-        }
173
-        if (!in_array($variable_to_test, $string_options)) {
174
-            $msg[0]=__('Malconfigured template.', 'event_espresso');
175
-            $msg[1]=__("Variable named '%s' was set to '%s'. It can only be one of '%s'", 'event_espresso');
176
-            throw new EE_Error(sprintf(implode("||", $msg), $variable_name, $variable_to_test, implode("', '", $string_options)));
177
-        }
178
-    }
31
+	/**
32
+	 * Throws an EE_Error if $variabel_to_test isn't an array of objects of class $class_name
33
+	 * @param mixed $variable_to_test
34
+	 * @param string $name_of_variable helpful in throwing intelligent errors
35
+	 * @param string $class_name eg EE_Answer, EE_Transaction, etc.
36
+	 * @param string $allow_null one of 'allow_null', or 'do_not_allow_null'
37
+	 * @return void
38
+	 * @throws EE_Error (indirectly)
39
+	 */
40
+	public static function verify_is_array_of($variable_to_test, $name_of_variable, $class_name, $allow_null = 'allow_null')
41
+	{
42
+		if (!WP_DEBUG) {
43
+			return;
44
+		}
45
+		self::verify_argument_is_one_of($allow_null, 'allow_null', array('allow_null','do_not_allow_null'));
46
+		if ('allow_null' == $allow_null && is_null($variable_to_test)) {
47
+			return;
48
+		}
49
+		self::verify_is_array($variable_to_test, $name_of_variable);
50
+		foreach ($variable_to_test as $key => $array_element) {
51
+			self::verify_instanceof($array_element, $key, $class_name);
52
+		}
53
+	}
54
+    
55
+    
56
+    
57
+    
58
+    
59
+	/**
60
+	 * throws an EE_Error if $variable_to_test is null
61
+	 * @param mixed $variable_to_test
62
+	 * @param string $name_of_variable helpful for throwing intelligent errors
63
+	 * @return void
64
+	 * @throws EE_Error
65
+	 */
66
+	public static function verify_isnt_null($variable_to_test, $name_of_variable)
67
+	{
68
+		if (!WP_DEBUG) {
69
+			return;
70
+		}
71
+		if ($variable_to_test==null && $variable_to_test!=0 && $variable_to_test!=false) {
72
+			$error[]=__('Variable named %s is null.', 'event_espresso');
73
+			$error[]=__("Consider looking at the stack trace to see why it wasn't set.", 'event_espresso');
74
+			throw new EE_Error(sprintf(implode(",", $error), $name_of_variable, $name_of_variable));
75
+		}
76
+	}
77
+    
78
+	/**
79
+	 * When WP_DEBUG is activted, throws an error if $expression_to_test is false.
80
+	 * @param boolean $expression_to_test
81
+	 * @param string $expression_string_representation a string representation of your expression
82
+	 * for example, if your expression were $var1==23, then this should be '$var1==23'
83
+	 * @return void
84
+	 * @throws EE_Error
85
+	 */
86
+	public static function verify_is_true($expression_to_test, $expression_string_representation)
87
+	{
88
+		if (!WP_DEBUG) {
89
+			return;
90
+		}
91
+		if (!$expression_to_test) {
92
+			$error[]=__('Template error.', 'event_espresso');
93
+			$error[]=__("%s evaluated to false, but it must be true!", 'event_espresso');
94
+			throw new EE_Error(sprintf(implode(",", $error), $expression_string_representation));
95
+		}
96
+	}
97
+    
98
+    
99
+    
100
+    
101
+    
102
+	/**
103
+	 * For verifying that a variable is indeed an object of class $class_name
104
+	 * @param mixed $variable_to_test
105
+	 * @param string $name_of_variable helpful when throwing errors
106
+	 * @param string $class_name eg, EE_Answer,
107
+	 * @return void
108
+	 * @throws EE_Error
109
+	 */
110
+	public static function verify_instanceof($variable_to_test, $name_of_variable, $class_name, $allow_null = 'do_not_allow_null')
111
+	{
112
+		if (!WP_DEBUG) {
113
+			return;
114
+		}
115
+		self::verify_argument_is_one_of($allow_null, 'allow_null', array('allow_null','do_not_allow_null'));
116
+		if ($allow_null == 'allow_null' && is_null($variable_to_test)) {
117
+			return;
118
+		}
119
+		if ($variable_to_test == null ||  ! ( $variable_to_test instanceof $class_name )) {
120
+			$msg[]=__('Variable %s is not of the correct type.', 'event_espresso');
121
+			$msg[]=__("It should be of type %s", 'event_espresso');
122
+			throw new EE_Error(sprintf(implode(",", $msg), $name_of_variable, $name_of_variable, $class_name));
123
+		}
124
+	}
125
+    
126
+    
127
+    
128
+    
129
+    
130
+	/**
131
+	 * For verifying that a variable is indeed an array, else throw an EE_Error
132
+	 * @param type $variable_to_test
133
+	 * @param type $variable_name
134
+	 * @param type $allow_empty one of 'allow_empty' or 'do_not_allow_empty'
135
+	 * @return void
136
+	 * @throws EE_Error
137
+	 */
138
+	public static function verify_is_array($variable_to_test, $variable_name, $allow_empty = 'allow_empty')
139
+	{
140
+		if (!WP_DEBUG) {
141
+			return;
142
+		}
143
+		self::verify_argument_is_one_of($allow_empty, $variable_name, array('allow_empty','do_not_allow_empty'));
144
+		if (empty($variable_to_test) && 'allow_empty'==$allow_empty) {
145
+			return;
146
+		}
147
+		if (!is_array($variable_to_test)) {
148
+			$error[]=__('Variable %s should be an array, but it is not.', 'event_espresso');
149
+			$error[]=__("Its value is, instead '%s'", 'event_espresso');
150
+			throw new EE_Error(sprintf(implode(",", $error), $variable_name, $variable_name, $variable_to_test));
151
+		}
152
+	}
153
+    
154
+    
155
+    
156
+    
157
+    
158
+    
159
+    
160
+	/**
161
+	 * for verifying that a variable is one of the string optiosn supplied
162
+	 * @param mixed $variable_to_test
163
+	 * @param mixed $variable_name the name you've given the variable. Eg, '$foo'. THis helps in producing better error messages
164
+	 * @param array $string_options an array of acceptable values
165
+	 * @return void
166
+	 * @throws EE_Error
167
+	 */
168
+	public static function verify_argument_is_one_of($variable_to_test, $variable_name, $string_options)
169
+	{
170
+		if (!WP_DEBUG) {
171
+			return;
172
+		}
173
+		if (!in_array($variable_to_test, $string_options)) {
174
+			$msg[0]=__('Malconfigured template.', 'event_espresso');
175
+			$msg[1]=__("Variable named '%s' was set to '%s'. It can only be one of '%s'", 'event_espresso');
176
+			throw new EE_Error(sprintf(implode("||", $msg), $variable_name, $variable_to_test, implode("', '", $string_options)));
177
+		}
178
+	}
179 179
 }
Please login to merge, or discard this patch.
Spacing   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -39,10 +39,10 @@  discard block
 block discarded – undo
39 39
      */
40 40
     public static function verify_is_array_of($variable_to_test, $name_of_variable, $class_name, $allow_null = 'allow_null')
41 41
     {
42
-        if (!WP_DEBUG) {
42
+        if ( ! WP_DEBUG) {
43 43
             return;
44 44
         }
45
-        self::verify_argument_is_one_of($allow_null, 'allow_null', array('allow_null','do_not_allow_null'));
45
+        self::verify_argument_is_one_of($allow_null, 'allow_null', array('allow_null', 'do_not_allow_null'));
46 46
         if ('allow_null' == $allow_null && is_null($variable_to_test)) {
47 47
             return;
48 48
         }
@@ -65,12 +65,12 @@  discard block
 block discarded – undo
65 65
      */
66 66
     public static function verify_isnt_null($variable_to_test, $name_of_variable)
67 67
     {
68
-        if (!WP_DEBUG) {
68
+        if ( ! WP_DEBUG) {
69 69
             return;
70 70
         }
71
-        if ($variable_to_test==null && $variable_to_test!=0 && $variable_to_test!=false) {
72
-            $error[]=__('Variable named %s is null.', 'event_espresso');
73
-            $error[]=__("Consider looking at the stack trace to see why it wasn't set.", 'event_espresso');
71
+        if ($variable_to_test == null && $variable_to_test != 0 && $variable_to_test != false) {
72
+            $error[] = __('Variable named %s is null.', 'event_espresso');
73
+            $error[] = __("Consider looking at the stack trace to see why it wasn't set.", 'event_espresso');
74 74
             throw new EE_Error(sprintf(implode(",", $error), $name_of_variable, $name_of_variable));
75 75
         }
76 76
     }
@@ -85,12 +85,12 @@  discard block
 block discarded – undo
85 85
      */
86 86
     public static function verify_is_true($expression_to_test, $expression_string_representation)
87 87
     {
88
-        if (!WP_DEBUG) {
88
+        if ( ! WP_DEBUG) {
89 89
             return;
90 90
         }
91
-        if (!$expression_to_test) {
92
-            $error[]=__('Template error.', 'event_espresso');
93
-            $error[]=__("%s evaluated to false, but it must be true!", 'event_espresso');
91
+        if ( ! $expression_to_test) {
92
+            $error[] = __('Template error.', 'event_espresso');
93
+            $error[] = __("%s evaluated to false, but it must be true!", 'event_espresso');
94 94
             throw new EE_Error(sprintf(implode(",", $error), $expression_string_representation));
95 95
         }
96 96
     }
@@ -109,16 +109,16 @@  discard block
 block discarded – undo
109 109
      */
110 110
     public static function verify_instanceof($variable_to_test, $name_of_variable, $class_name, $allow_null = 'do_not_allow_null')
111 111
     {
112
-        if (!WP_DEBUG) {
112
+        if ( ! WP_DEBUG) {
113 113
             return;
114 114
         }
115
-        self::verify_argument_is_one_of($allow_null, 'allow_null', array('allow_null','do_not_allow_null'));
115
+        self::verify_argument_is_one_of($allow_null, 'allow_null', array('allow_null', 'do_not_allow_null'));
116 116
         if ($allow_null == 'allow_null' && is_null($variable_to_test)) {
117 117
             return;
118 118
         }
119
-        if ($variable_to_test == null ||  ! ( $variable_to_test instanceof $class_name )) {
120
-            $msg[]=__('Variable %s is not of the correct type.', 'event_espresso');
121
-            $msg[]=__("It should be of type %s", 'event_espresso');
119
+        if ($variable_to_test == null || ! ($variable_to_test instanceof $class_name)) {
120
+            $msg[] = __('Variable %s is not of the correct type.', 'event_espresso');
121
+            $msg[] = __("It should be of type %s", 'event_espresso');
122 122
             throw new EE_Error(sprintf(implode(",", $msg), $name_of_variable, $name_of_variable, $class_name));
123 123
         }
124 124
     }
@@ -137,16 +137,16 @@  discard block
 block discarded – undo
137 137
      */
138 138
     public static function verify_is_array($variable_to_test, $variable_name, $allow_empty = 'allow_empty')
139 139
     {
140
-        if (!WP_DEBUG) {
140
+        if ( ! WP_DEBUG) {
141 141
             return;
142 142
         }
143
-        self::verify_argument_is_one_of($allow_empty, $variable_name, array('allow_empty','do_not_allow_empty'));
144
-        if (empty($variable_to_test) && 'allow_empty'==$allow_empty) {
143
+        self::verify_argument_is_one_of($allow_empty, $variable_name, array('allow_empty', 'do_not_allow_empty'));
144
+        if (empty($variable_to_test) && 'allow_empty' == $allow_empty) {
145 145
             return;
146 146
         }
147
-        if (!is_array($variable_to_test)) {
148
-            $error[]=__('Variable %s should be an array, but it is not.', 'event_espresso');
149
-            $error[]=__("Its value is, instead '%s'", 'event_espresso');
147
+        if ( ! is_array($variable_to_test)) {
148
+            $error[] = __('Variable %s should be an array, but it is not.', 'event_espresso');
149
+            $error[] = __("Its value is, instead '%s'", 'event_espresso');
150 150
             throw new EE_Error(sprintf(implode(",", $error), $variable_name, $variable_name, $variable_to_test));
151 151
         }
152 152
     }
@@ -167,12 +167,12 @@  discard block
 block discarded – undo
167 167
      */
168 168
     public static function verify_argument_is_one_of($variable_to_test, $variable_name, $string_options)
169 169
     {
170
-        if (!WP_DEBUG) {
170
+        if ( ! WP_DEBUG) {
171 171
             return;
172 172
         }
173
-        if (!in_array($variable_to_test, $string_options)) {
174
-            $msg[0]=__('Malconfigured template.', 'event_espresso');
175
-            $msg[1]=__("Variable named '%s' was set to '%s'. It can only be one of '%s'", 'event_espresso');
173
+        if ( ! in_array($variable_to_test, $string_options)) {
174
+            $msg[0] = __('Malconfigured template.', 'event_espresso');
175
+            $msg[1] = __("Variable named '%s' was set to '%s'. It can only be one of '%s'", 'event_espresso');
176 176
             throw new EE_Error(sprintf(implode("||", $msg), $variable_name, $variable_to_test, implode("', '", $string_options)));
177 177
         }
178 178
     }
Please login to merge, or discard this patch.