Completed
Branch rest-authorization (c7240a)
by
unknown
02:23
created
core/helpers/EEH_Tabbed_Content.helper.php 2 patches
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -30,7 +30,7 @@  discard block
 block discarded – undo
30 30
     {
31 31
 
32 32
         // first check if $tabs_names is not empty then the count must match the count of $tabs_content otherwise we've got a problem houston
33
-        if (! empty($tabs_names) && (count((array) $tabs_names) != count((array) $tabs_content))) {
33
+        if ( ! empty($tabs_names) && (count((array) $tabs_names) != count((array) $tabs_content))) {
34 34
             throw new EE_Error(
35 35
                 esc_html__('The count for $tabs_names and $tabs_content does not match.', 'event_espresso')
36 36
             );
@@ -49,9 +49,9 @@  discard block
 block discarded – undo
49 49
 
50 50
         $index = 0;
51 51
         foreach ($tabs as $tab) {
52
-            $active            = $index === 0;
52
+            $active = $index === 0;
53 53
             $tabs_html         .= self::tab($tab, $active);
54
-            $tabs_content_html .= self::tab_content($tab, $tabs_content[ $tab ], $active);
54
+            $tabs_content_html .= self::tab_content($tab, $tabs_content[$tab], $active);
55 55
             $index++;
56 56
         }
57 57
 
@@ -118,9 +118,9 @@  discard block
 block discarded – undo
118 118
     {
119 119
         $nice_name = $nice_name ?: esc_html(ucwords(str_replace(['_', '-'], ' ', $name)));
120 120
         $name      = self::generateTadID($name);
121
-        $class     = $css ? ' ' . esc_attr($css) : '';
122
-        $class     .= $active ? ' nav-tab-active' : '';
123
-        $url       = $url ?: '#' . esc_attr($name);
121
+        $class     = $css ? ' '.esc_attr($css) : '';
122
+        $class .= $active ? ' nav-tab-active' : '';
123
+        $url       = $url ?: '#'.esc_attr($name);
124 124
         return "
125 125
         <a class='nav-tab{$class}' rel='{$name}' href='{$url}'>
126 126
             $nice_name
@@ -136,7 +136,7 @@  discard block
 block discarded – undo
136 136
      */
137 137
     private static function generateTadID($tab_name)
138 138
     {
139
-        return 'ee-tab-' . esc_attr(str_replace(' ', '-', $tab_name));
139
+        return 'ee-tab-'.esc_attr(str_replace(' ', '-', $tab_name));
140 140
     }
141 141
 
142 142
 
@@ -187,18 +187,18 @@  discard block
 block discarded – undo
187 187
     public static function tab_text_links(array $item_array, $container_class = '', $sep = '|', $default = '')
188 188
     {
189 189
         $item_array = apply_filters('FHEE__EEH_Tabbed_Content__tab_text_links', $item_array, $container_class);
190
-        if (! is_array($item_array) || empty($item_array)) {
190
+        if ( ! is_array($item_array) || empty($item_array)) {
191 191
             return false; // get out we don't have even the basic thing we need!
192 192
         }
193 193
 
194
-        $defaults        = [
194
+        $defaults = [
195 195
             'label' => esc_html__('Item', 'event_espresso'),
196 196
             'class' => '',
197 197
             'href'  => '',
198 198
             'title' => esc_attr__('Link for Item', 'event_espresso'),
199 199
             'slug'  => 'item_slug',
200 200
         ];
201
-        $container_class = ! empty($container_class) ? ' ' . esc_attr($container_class) : '';
201
+        $container_class = ! empty($container_class) ? ' '.esc_attr($container_class) : '';
202 202
         $list            = '';
203 203
         $list_length     = count($item_array);
204 204
         // if we're' adding separators, set $current to 1, otherwise set it to list length + 1
@@ -206,7 +206,7 @@  discard block
 block discarded – undo
206 206
         // (if we aren't adding separators $current will always be > list length cuz it started at list length + 1)
207 207
         $current = empty($sep) ? $list_length + 1 : 1;
208 208
         foreach ($item_array as $item) {
209
-            $item          = wp_parse_args($item, $defaults);
209
+            $item = wp_parse_args($item, $defaults);
210 210
             $item['class'] .= $default === $item['slug'] ? ' item_display' : '';
211 211
             $list          .= self::textLinkItem($item);
212 212
             $list          .= $current < $list_length ? self::textLinkSeparator($sep) : '';
Please login to merge, or discard this patch.
Indentation   +189 added lines, -189 removed lines patch added patch discarded remove patch
@@ -13,246 +13,246 @@
 block discarded – undo
13 13
  */
14 14
 class EEH_Tabbed_Content
15 15
 {
16
-    /**
17
-     * assembles and returns the html structure for tabs
18
-     *
19
-     * @static
20
-     * @param array $tabs_contents an array of the content for each tab [required]
21
-     * @param array $tabs_names    a numerically indexed array of names for each tab [optional]
22
-     *                             - if this isn't included then we use the indexes for $tabs_content as the tab names)
23
-     * @param bool  $small_tabs
24
-     * @param bool  $tabs_content
25
-     * @return string the assembled html string containing the tabbed content for display.
26
-     * @throws EE_Error
27
-     */
28
-    public static function display($tabs_contents, $tabs_names = [], $small_tabs = true, $tabs_content = true)
29
-    {
16
+	/**
17
+	 * assembles and returns the html structure for tabs
18
+	 *
19
+	 * @static
20
+	 * @param array $tabs_contents an array of the content for each tab [required]
21
+	 * @param array $tabs_names    a numerically indexed array of names for each tab [optional]
22
+	 *                             - if this isn't included then we use the indexes for $tabs_content as the tab names)
23
+	 * @param bool  $small_tabs
24
+	 * @param bool  $tabs_content
25
+	 * @return string the assembled html string containing the tabbed content for display.
26
+	 * @throws EE_Error
27
+	 */
28
+	public static function display($tabs_contents, $tabs_names = [], $small_tabs = true, $tabs_content = true)
29
+	{
30 30
 
31
-        // first check if $tabs_names is not empty then the count must match the count of $tabs_content otherwise we've got a problem houston
32
-        if (! empty($tabs_names) && (count((array) $tabs_names) != count((array) $tabs_content))) {
33
-            throw new EE_Error(
34
-                esc_html__('The count for $tabs_names and $tabs_content does not match.', 'event_espresso')
35
-            );
36
-        }
31
+		// first check if $tabs_names is not empty then the count must match the count of $tabs_content otherwise we've got a problem houston
32
+		if (! empty($tabs_names) && (count((array) $tabs_names) != count((array) $tabs_content))) {
33
+			throw new EE_Error(
34
+				esc_html__('The count for $tabs_names and $tabs_content does not match.', 'event_espresso')
35
+			);
36
+		}
37 37
 
38
-        // make sure we've got incoming data setup properly
39
-        $tabs         = ! empty($tabs_names)
40
-            ? (array) $tabs_names
41
-            : array_keys((array) $tabs_contents);
42
-        $tabs_content = ! empty($tabs_names)
43
-            ? array_combine((array) $tabs_names, (array) $tabs_content)
44
-            : $tabs_contents;
38
+		// make sure we've got incoming data setup properly
39
+		$tabs         = ! empty($tabs_names)
40
+			? (array) $tabs_names
41
+			: array_keys((array) $tabs_contents);
42
+		$tabs_content = ! empty($tabs_names)
43
+			? array_combine((array) $tabs_names, (array) $tabs_content)
44
+			: $tabs_contents;
45 45
 
46
-        $tabs_html         = '';
47
-        $tabs_content_html = '';
46
+		$tabs_html         = '';
47
+		$tabs_content_html = '';
48 48
 
49
-        $index = 0;
50
-        foreach ($tabs as $tab) {
51
-            $active            = $index === 0;
52
-            $tabs_html         .= self::tab($tab, $active);
53
-            $tabs_content_html .= self::tab_content($tab, $tabs_content[ $tab ], $active);
54
-            $index++;
55
-        }
49
+		$index = 0;
50
+		foreach ($tabs as $tab) {
51
+			$active            = $index === 0;
52
+			$tabs_html         .= self::tab($tab, $active);
53
+			$tabs_content_html .= self::tab_content($tab, $tabs_content[ $tab ], $active);
54
+			$index++;
55
+		}
56 56
 
57
-        $tabs_class = $small_tabs ? ' ee-nav-tabs-small' : '';
57
+		$tabs_class = $small_tabs ? ' ee-nav-tabs-small' : '';
58 58
 
59
-        return "
59
+		return "
60 60
     <div class='ee-nav-tabs{$tabs_class}'>
61 61
         <h2 class='nav-tab-wrapper'>{$tabs_html}</h2>
62 62
         {$tabs_content_html}
63 63
     </div>
64 64
     ";
65
-    }
65
+	}
66 66
 
67 67
 
68
-    /**
69
-     * display_admin_nav_tabs
70
-     * this returns the properly formatted tab html for EE_Admin_Pages.
71
-     * We are expecting an array of tabs in the following format
72
-     * array(
73
-     *    'nav_tab_name' => array(
74
-     *        'url' => 'url for tab',
75
-     *        'link_text' => 'tab text',
76
-     *        'css_class' => 'tab class' //including the nav-tab-active class if its active
77
-     *    )
78
-     * )
79
-     *
80
-     * @access public
81
-     * @static
82
-     * @param string[][] $nav_tabs tab array for nav tabs
83
-     * @return string
84
-     * @throws EE_Error
85
-     */
86
-    public static function display_admin_nav_tabs($nav_tabs = [])
87
-    {
88
-        if (empty($nav_tabs)) {
89
-            throw new EE_Error(
90
-                esc_html__('Nav Tabs cannot be generated because the tab array is missing', 'event_espresso')
91
-            );
92
-        }
93
-        $tab_content = '';
94
-        foreach ($nav_tabs as $slug => $tab) {
95
-            $tab_content .= self::tab($slug, false, $tab['link_text'], $tab['url'], $tab['css_class']);
96
-        }
97
-        $aria_label = esc_attr__('Secondary menu', 'event_espresso');
98
-        return "
68
+	/**
69
+	 * display_admin_nav_tabs
70
+	 * this returns the properly formatted tab html for EE_Admin_Pages.
71
+	 * We are expecting an array of tabs in the following format
72
+	 * array(
73
+	 *    'nav_tab_name' => array(
74
+	 *        'url' => 'url for tab',
75
+	 *        'link_text' => 'tab text',
76
+	 *        'css_class' => 'tab class' //including the nav-tab-active class if its active
77
+	 *    )
78
+	 * )
79
+	 *
80
+	 * @access public
81
+	 * @static
82
+	 * @param string[][] $nav_tabs tab array for nav tabs
83
+	 * @return string
84
+	 * @throws EE_Error
85
+	 */
86
+	public static function display_admin_nav_tabs($nav_tabs = [])
87
+	{
88
+		if (empty($nav_tabs)) {
89
+			throw new EE_Error(
90
+				esc_html__('Nav Tabs cannot be generated because the tab array is missing', 'event_espresso')
91
+			);
92
+		}
93
+		$tab_content = '';
94
+		foreach ($nav_tabs as $slug => $tab) {
95
+			$tab_content .= self::tab($slug, false, $tab['link_text'], $tab['url'], $tab['css_class']);
96
+		}
97
+		$aria_label = esc_attr__('Secondary menu', 'event_espresso');
98
+		return "
99 99
         <nav class='nav-tab-wrapper wp-clearfix' aria-label='{$aria_label}'>
100 100
             {$tab_content}
101 101
         </nav>
102 102
         ";
103
-    }
103
+	}
104 104
 
105 105
 
106
-    /**
107
-     * this simply returns a single tab given a tab name & content
108
-     *
109
-     * @param string      $name      name of tab
110
-     * @param bool        $active    true=tab active, false=tab not active
111
-     * @param bool|string $nice_name if string given then this value will be used for the tab link text.
112
-     * @param bool|string $url       If url given then tabs will be generated linking to the url.
113
-     * @param bool|string $css       If string given then the generated tab will include that as the class.
114
-     * @return string          html for tab
115
-     */
116
-    private static function tab($name, $active = false, $nice_name = false, $url = false, $css = false)
117
-    {
118
-        $nice_name = $nice_name ?: esc_html(ucwords(str_replace(['_', '-'], ' ', $name)));
119
-        $name      = self::generateTadID($name);
120
-        $class     = $css ? ' ' . esc_attr($css) : '';
121
-        $class     .= $active ? ' nav-tab-active' : '';
122
-        $url       = $url ?: '#' . esc_attr($name);
123
-        return "
106
+	/**
107
+	 * this simply returns a single tab given a tab name & content
108
+	 *
109
+	 * @param string      $name      name of tab
110
+	 * @param bool        $active    true=tab active, false=tab not active
111
+	 * @param bool|string $nice_name if string given then this value will be used for the tab link text.
112
+	 * @param bool|string $url       If url given then tabs will be generated linking to the url.
113
+	 * @param bool|string $css       If string given then the generated tab will include that as the class.
114
+	 * @return string          html for tab
115
+	 */
116
+	private static function tab($name, $active = false, $nice_name = false, $url = false, $css = false)
117
+	{
118
+		$nice_name = $nice_name ?: esc_html(ucwords(str_replace(['_', '-'], ' ', $name)));
119
+		$name      = self::generateTadID($name);
120
+		$class     = $css ? ' ' . esc_attr($css) : '';
121
+		$class     .= $active ? ' nav-tab-active' : '';
122
+		$url       = $url ?: '#' . esc_attr($name);
123
+		return "
124 124
         <a class='nav-tab{$class}' rel='{$name}' href='{$url}'>
125 125
             $nice_name
126 126
         </a>
127 127
         ";
128
-    }
128
+	}
129 129
 
130 130
 
131
-    /**
132
-     * @param string $tab_name
133
-     * @return string
134
-     * @since   4.10.14.p
135
-     */
136
-    private static function generateTadID($tab_name)
137
-    {
138
-        return 'ee-tab-' . esc_attr(str_replace(' ', '-', $tab_name));
139
-    }
131
+	/**
132
+	 * @param string $tab_name
133
+	 * @return string
134
+	 * @since   4.10.14.p
135
+	 */
136
+	private static function generateTadID($tab_name)
137
+	{
138
+		return 'ee-tab-' . esc_attr(str_replace(' ', '-', $tab_name));
139
+	}
140 140
 
141 141
 
142
-    /**
143
-     * this just returns the properly formatted tab content for our tab box.
144
-     *
145
-     * @param string $name        name of tab (used for selector)
146
-     * @param string $tab_content content of tab
147
-     * @param bool   $active
148
-     * @return string html for content area
149
-     */
150
-    private static function tab_content($name, $tab_content, $active = false)
151
-    {
152
-        $class = $active ? '' : ' hidden';
153
-        $name  = self::generateTadID($name);
154
-        return "
142
+	/**
143
+	 * this just returns the properly formatted tab content for our tab box.
144
+	 *
145
+	 * @param string $name        name of tab (used for selector)
146
+	 * @param string $tab_content content of tab
147
+	 * @param bool   $active
148
+	 * @return string html for content area
149
+	 */
150
+	private static function tab_content($name, $tab_content, $active = false)
151
+	{
152
+		$class = $active ? '' : ' hidden';
153
+		$name  = self::generateTadID($name);
154
+		return "
155 155
     <div class='nav-tab-content{$class}' id='{$name}'>
156 156
         {$tab_content}
157 157
         <div style='clear:both'></div>
158 158
     </div>";
159
-    }
159
+	}
160 160
 
161 161
 
162 162
 
163
-    /** HORIZONTAL TEXT LINKS **/
163
+	/** HORIZONTAL TEXT LINKS **/
164 164
 
165
-    /**
166
-     * This will take in an array of link items and spit out a formatted list of links that can be used to navigate to
167
-     * items. There is a corresponding js file that can be loaded to dynamically display containers with the same id as
168
-     * the href -ref.
169
-     *
170
-     * @param string[] $item_array      formatted array of items.  Format:
171
-     *                                  array(
172
-     *                                  'label' => esc_html__('localized label displayed'),
173
-     *                                  'class' => 'class_for_item',
174
-     *                                  'href' => '#some_item_id', //url/bookmark for item.  If you include a bookmark
175
-     *                                  the js will used this to show the container div.
176
-     *                                  'title' => esc_html__('localized text for the title attribute of the link'),
177
-     *                                  'slug' => 'slug_used_for_reference'
178
-     *                                  )
179
-     * @param string   $container_class class used for main container
180
-     * @param string   $sep             you can add in what is used as a separator between each link (or leave blank for
181
-     *                                  none)
182
-     * @param string   $default         You can include a string for the item that will receive the "item_display" class
183
-     *                                  for the js.
184
-     * @return string                  a html snippet of of all the formatted link elements.
185
-     */
186
-    public static function tab_text_links(array $item_array, $container_class = '', $sep = '|', $default = '')
187
-    {
188
-        $item_array = apply_filters('FHEE__EEH_Tabbed_Content__tab_text_links', $item_array, $container_class);
189
-        if (! is_array($item_array) || empty($item_array)) {
190
-            return false; // get out we don't have even the basic thing we need!
191
-        }
165
+	/**
166
+	 * This will take in an array of link items and spit out a formatted list of links that can be used to navigate to
167
+	 * items. There is a corresponding js file that can be loaded to dynamically display containers with the same id as
168
+	 * the href -ref.
169
+	 *
170
+	 * @param string[] $item_array      formatted array of items.  Format:
171
+	 *                                  array(
172
+	 *                                  'label' => esc_html__('localized label displayed'),
173
+	 *                                  'class' => 'class_for_item',
174
+	 *                                  'href' => '#some_item_id', //url/bookmark for item.  If you include a bookmark
175
+	 *                                  the js will used this to show the container div.
176
+	 *                                  'title' => esc_html__('localized text for the title attribute of the link'),
177
+	 *                                  'slug' => 'slug_used_for_reference'
178
+	 *                                  )
179
+	 * @param string   $container_class class used for main container
180
+	 * @param string   $sep             you can add in what is used as a separator between each link (or leave blank for
181
+	 *                                  none)
182
+	 * @param string   $default         You can include a string for the item that will receive the "item_display" class
183
+	 *                                  for the js.
184
+	 * @return string                  a html snippet of of all the formatted link elements.
185
+	 */
186
+	public static function tab_text_links(array $item_array, $container_class = '', $sep = '|', $default = '')
187
+	{
188
+		$item_array = apply_filters('FHEE__EEH_Tabbed_Content__tab_text_links', $item_array, $container_class);
189
+		if (! is_array($item_array) || empty($item_array)) {
190
+			return false; // get out we don't have even the basic thing we need!
191
+		}
192 192
 
193
-        $defaults        = [
194
-            'label' => esc_html__('Item', 'event_espresso'),
195
-            'class' => '',
196
-            'href'  => '',
197
-            'title' => esc_attr__('Link for Item', 'event_espresso'),
198
-            'slug'  => 'item_slug',
199
-        ];
200
-        $container_class = ! empty($container_class) ? ' ' . esc_attr($container_class) : '';
201
-        $list            = '';
202
-        $list_length     = count($item_array);
203
-        // if we're' adding separators, set $current to 1, otherwise set it to list length + 1
204
-        // then we'll increment $current while looping and only add separators if $current is < list length
205
-        // (if we aren't adding separators $current will always be > list length cuz it started at list length + 1)
206
-        $current = empty($sep) ? $list_length + 1 : 1;
207
-        foreach ($item_array as $item) {
208
-            $item          = wp_parse_args($item, $defaults);
209
-            $item['class'] .= $default === $item['slug'] ? ' item_display' : '';
210
-            $list          .= self::textLinkItem($item);
211
-            $list          .= $current < $list_length ? self::textLinkSeparator($sep) : '';
212
-            $current++;
213
-        }
193
+		$defaults        = [
194
+			'label' => esc_html__('Item', 'event_espresso'),
195
+			'class' => '',
196
+			'href'  => '',
197
+			'title' => esc_attr__('Link for Item', 'event_espresso'),
198
+			'slug'  => 'item_slug',
199
+		];
200
+		$container_class = ! empty($container_class) ? ' ' . esc_attr($container_class) : '';
201
+		$list            = '';
202
+		$list_length     = count($item_array);
203
+		// if we're' adding separators, set $current to 1, otherwise set it to list length + 1
204
+		// then we'll increment $current while looping and only add separators if $current is < list length
205
+		// (if we aren't adding separators $current will always be > list length cuz it started at list length + 1)
206
+		$current = empty($sep) ? $list_length + 1 : 1;
207
+		foreach ($item_array as $item) {
208
+			$item          = wp_parse_args($item, $defaults);
209
+			$item['class'] .= $default === $item['slug'] ? ' item_display' : '';
210
+			$list          .= self::textLinkItem($item);
211
+			$list          .= $current < $list_length ? self::textLinkSeparator($sep) : '';
212
+			$current++;
213
+		}
214 214
 
215
-        return "
215
+		return "
216 216
         <ul class='ee-text-links{$container_class}'>{$list}</ul>
217 217
         ";
218
-    }
218
+	}
219 219
 
220 220
 
221
-    /**
222
-     * @param string[] $item
223
-     * @return string
224
-     */
225
-    private static function textLinkItem(array $item)
226
-    {
227
-        $class = $item['class'] ? esc_attr($item['class']) : '';
228
-        $label = esc_html($item['label']);
229
-        $href  = $item['href'] ? esc_attr($item['href']) : '';
230
-        $title = esc_attr($item['title']);
221
+	/**
222
+	 * @param string[] $item
223
+	 * @return string
224
+	 */
225
+	private static function textLinkItem(array $item)
226
+	{
227
+		$class = $item['class'] ? esc_attr($item['class']) : '';
228
+		$label = esc_html($item['label']);
229
+		$href  = $item['href'] ? esc_attr($item['href']) : '';
230
+		$title = esc_attr($item['title']);
231 231
 
232 232
 
233
-        $link = ! empty($href)
234
-            ? "
233
+		$link = ! empty($href)
234
+			? "
235 235
             <a class='ee-text-link' href='#{$href}' title='{$title}'>
236 236
                 {$label}
237 237
             </a>
238 238
             "
239
-            : $label;
240
-        return "
239
+			: $label;
240
+		return "
241 241
         <li class='ee-text-link-li {$class}'>{$link}</li>
242 242
         ";
243
-    }
243
+	}
244 244
 
245 245
 
246
-    /**
247
-     * @param string $separator
248
-     * @return string
249
-     * @since   4.10.14.p
250
-     */
251
-    private static function textLinkSeparator($separator)
252
-    {
253
-        $separator = esc_html($separator);
254
-        return "
246
+	/**
247
+	 * @param string $separator
248
+	 * @return string
249
+	 * @since   4.10.14.p
250
+	 */
251
+	private static function textLinkSeparator($separator)
252
+	{
253
+		$separator = esc_html($separator);
254
+		return "
255 255
         <li class='ee-text-link-sep'>{$separator}</li>
256 256
         ";
257
-    }
257
+	}
258 258
 }
Please login to merge, or discard this patch.
core/helpers/EEH_Qtip_Loader.helper.php 2 patches
Spacing   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -35,7 +35,7 @@  discard block
 block discarded – undo
35 35
     public static function instance()
36 36
     {
37 37
         // check if class object is instantiated
38
-        if (self::$_instance === null  or ! is_object(self::$_instance) or ! ( self::$_instance instanceof EEH_Qtip_Loader )) {
38
+        if (self::$_instance === null or ! is_object(self::$_instance) or ! (self::$_instance instanceof EEH_Qtip_Loader)) {
39 39
             self::$_instance = new self();
40 40
         }
41 41
         return self::$_instance;
@@ -66,25 +66,25 @@  discard block
 block discarded – undo
66 66
      */
67 67
     public function register_and_enqueue()
68 68
     {
69
-        $qtips_js = !defined('SCRIPT_DEBUG') ? EE_THIRD_PARTY_URL . 'qtip/jquery.qtip.min.js' : EE_THIRD_PARTY_URL . 'qtip/jquery.qtip.js';
70
-        $qtip_map = EE_THIRD_PARTY_URL . 'qtip/jquery.qtip.min.map';
71
-        $qtipcss = !defined('SCRIPT_DEBUG') ? EE_THIRD_PARTY_URL . 'qtip/jquery.qtip.min.css' : EE_THIRD_PARTY_URL . 'qtip/jquery.qtip.css';
69
+        $qtips_js = ! defined('SCRIPT_DEBUG') ? EE_THIRD_PARTY_URL . 'qtip/jquery.qtip.min.js' : EE_THIRD_PARTY_URL.'qtip/jquery.qtip.js';
70
+        $qtip_map = EE_THIRD_PARTY_URL.'qtip/jquery.qtip.min.map';
71
+        $qtipcss = ! defined('SCRIPT_DEBUG') ? EE_THIRD_PARTY_URL . 'qtip/jquery.qtip.min.css' : EE_THIRD_PARTY_URL.'qtip/jquery.qtip.css';
72 72
 
73 73
         wp_register_script('qtip-map', $qtip_map, array(), '3', true);
74 74
         wp_register_script('qtip', $qtips_js, array('jquery'), '3.0.3', true);
75
-        wp_register_script('ee-qtip-helper', EE_HELPERS_ASSETS . 'ee-qtip-helper.js', array('qtip', 'jquery-cookie'), EVENT_ESPRESSO_VERSION, true);
75
+        wp_register_script('ee-qtip-helper', EE_HELPERS_ASSETS.'ee-qtip-helper.js', array('qtip', 'jquery-cookie'), EVENT_ESPRESSO_VERSION, true);
76 76
 
77 77
         wp_register_style('qtip-css', $qtipcss, array(), '2.2');
78 78
 
79 79
         // 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!)
80
-        if (!empty($this->_qtips)) {
80
+        if ( ! empty($this->_qtips)) {
81 81
             wp_enqueue_script('ee-qtip-helper');
82 82
             wp_enqueue_style('qtip-css');
83 83
             $qtips = array();
84 84
             foreach ($this->_qtips as $qtip) {
85 85
                 $qts = $qtip->get_tips();
86 86
                 foreach ($qts as $qt) {
87
-                    if (! $qt instanceof EE_Qtip) {
87
+                    if ( ! $qt instanceof EE_Qtip) {
88 88
                         continue;
89 89
                     }
90 90
                     $qtips[] = array(
@@ -94,8 +94,8 @@  discard block
 block discarded – undo
94 94
                         );
95 95
                 }
96 96
             }
97
-            if (!empty($qtips)) {
98
-                wp_localize_script('ee-qtip-helper', 'EE_QTIP_HELPER', array( 'qtips' => $qtips ));
97
+            if ( ! empty($qtips)) {
98
+                wp_localize_script('ee-qtip-helper', 'EE_QTIP_HELPER', array('qtips' => $qtips));
99 99
             }
100 100
         } else {
101 101
             // qtips has been requested without any registration (so assuming its just directly used in the admin).
@@ -154,11 +154,11 @@  discard block
 block discarded – undo
154 154
         // before doing anything we have to make sure that EE_Qtip_Config parent is required.
155 155
         EE_Registry::instance()->load_lib('Qtip_Config', array(), true);
156 156
 
157
-        if (!empty($paths)) {
157
+        if ( ! empty($paths)) {
158 158
             $paths = (array) $paths;
159 159
             foreach ($paths as $path) {
160
-                $path = $path . $config . '.lib.php';
161
-                if (!is_readable($path)) {
160
+                $path = $path.$config.'.lib.php';
161
+                if ( ! is_readable($path)) {
162 162
                     continue;
163 163
                 } else {
164 164
                     require_once $path;
@@ -167,9 +167,9 @@  discard block
 block discarded – undo
167 167
         }
168 168
 
169 169
         // does class exist at this point?  If it does then let's instantiate.  If it doesn't then let's continue with other paths.
170
-        if (!class_exists($config)) {
171
-            $path = EE_LIBRARIES . 'qtips/' . $config . '.lib.php';
172
-            if (!is_readable($path)) {
170
+        if ( ! class_exists($config)) {
171
+            $path = EE_LIBRARIES.'qtips/'.$config.'.lib.php';
172
+            if ( ! is_readable($path)) {
173 173
                 throw new EE_Error(sprintf(esc_html__('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));
174 174
             } else {
175 175
                 require_once $path;
@@ -177,7 +177,7 @@  discard block
 block discarded – undo
177 177
         }
178 178
 
179 179
         // now we attempt a class_exists one more time.
180
-        if (!class_exists($config)) {
180
+        if ( ! class_exists($config)) {
181 181
             throw new EE_Error(sprintf(esc_html__('The Qtip_Config class being registered (%s) does not exist, please check the spelling.', 'event_espresso'), $config));
182 182
         }
183 183
 
@@ -186,7 +186,7 @@  discard block
 block discarded – undo
186 186
         $qtip = $a->newInstance();
187 187
 
188 188
         // verify that $qtip is a valid object
189
-        if (! $qtip instanceof EE_Qtip_Config) {
189
+        if ( ! $qtip instanceof EE_Qtip_Config) {
190 190
             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>'));
191 191
         }
192 192
 
@@ -229,11 +229,11 @@  discard block
 block discarded – undo
229 229
         $qts = $qtip->get_tips();
230 230
         $content = array();
231 231
         foreach ($qts as $qt) {
232
-            if (! $qt instanceof EE_Qtip) {
232
+            if ( ! $qt instanceof EE_Qtip) {
233 233
                 continue;
234 234
             }
235
-            $content[] = '<div class="ee-qtip-helper-content hidden" id="' . esc_attr($qt->content_id) . '">' .
236
-                         $qt->content . '</div>';
235
+            $content[] = '<div class="ee-qtip-helper-content hidden" id="'.esc_attr($qt->content_id).'">'.
236
+                         $qt->content.'</div>';
237 237
         }
238 238
 
239 239
         return implode('<br />', $content);
Please login to merge, or discard this patch.
Indentation   +226 added lines, -226 removed lines patch added patch discarded remove patch
@@ -11,230 +11,230 @@
 block discarded – undo
11 11
  */
12 12
 class EEH_Qtip_Loader extends EEH_Base
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', esc_html__('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()', esc_html__('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(esc_html__('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(esc_html__('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="' . esc_attr($qt->content_id) . '">' .
235
-                         $qt->content . '</div>';
236
-        }
237
-
238
-        return implode('<br />', $content);
239
-    }
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', esc_html__('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()', esc_html__('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(esc_html__('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(esc_html__('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="' . esc_attr($qt->content_id) . '">' .
235
+						 $qt->content . '</div>';
236
+		}
237
+
238
+		return implode('<br />', $content);
239
+	}
240 240
 }
Please login to merge, or discard this patch.
core/helpers/EEH_Venue_View.helper.php 2 patches
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -99,7 +99,7 @@  discard block
 block discarded – undo
99 99
             }
100 100
         }
101 101
         // now if we STILL do NOT have an EE_Venue model object, BUT we have a Venue ID...
102
-        if (! EEH_Venue_View::$_venue instanceof EE_Venue && $VNU_ID) {
102
+        if ( ! EEH_Venue_View::$_venue instanceof EE_Venue && $VNU_ID) {
103 103
             // sigh... pull it from the db
104 104
             EEH_Venue_View::$_venue = EEM_Venue::instance()->get_one_by_ID($VNU_ID);
105 105
         }
@@ -175,7 +175,7 @@  discard block
 block discarded – undo
175 175
     public static function is_venue_private($VNU_ID = false)
176 176
     {
177 177
         $venue = EEH_Venue_View::get_venue($VNU_ID);
178
-        if (! $venue instanceof EE_Venue) {
178
+        if ( ! $venue instanceof EE_Venue) {
179 179
             return null;
180 180
         }
181 181
 
@@ -260,11 +260,11 @@  discard block
 block discarded – undo
260 260
         $venue = EEH_Venue_View::get_venue($VNU_ID);
261 261
         if ($venue instanceof EE_Venue) {
262 262
             $excerpt    = $venue->excerpt() != null && $venue->excerpt() ? $venue->excerpt() : $venue->description();
263
-            $venue_link = ' ' . EEH_Venue_View::venue_details_link(
263
+            $venue_link = ' '.EEH_Venue_View::venue_details_link(
264 264
                 $venue->ID(),
265
-                esc_html__('more', 'event_espresso') . '&hellip;'
265
+                esc_html__('more', 'event_espresso').'&hellip;'
266 266
             );
267
-            return ! empty($excerpt) ? wp_trim_words($excerpt, 25, '') . $venue_link : '';
267
+            return ! empty($excerpt) ? wp_trim_words($excerpt, 25, '').$venue_link : '';
268 268
         }
269 269
         return '';
270 270
     }
@@ -299,7 +299,7 @@  discard block
 block discarded – undo
299 299
                              ))
300 300
                             || ! $hide_uncategorized)
301 301
                     ) {
302
-                        $category_links[] = '<a href="' . esc_url($url) . '" rel="tag">' . $term->name . '</a> ';
302
+                        $category_links[] = '<a href="'.esc_url($url).'" rel="tag">'.$term->name.'</a> ';
303 303
                     }
304 304
                 }
305 305
             }
@@ -367,7 +367,7 @@  discard block
 block discarded – undo
367 367
             $venue_name = apply_filters(
368 368
                 'FHEE__EEH_Venue__venue_name__append_private_venue_name',
369 369
                 EEH_Venue_View::is_venue_private()
370
-                    ? EEH_Venue_View::$_venue->name() . "&nbsp;" . esc_html__('(Private)', 'event_espresso')
370
+                    ? EEH_Venue_View::$_venue->name()."&nbsp;".esc_html__('(Private)', 'event_espresso')
371 371
                     : EEH_Venue_View::$_venue->name(),
372 372
                 EEH_Venue_View::$_venue
373 373
             );
@@ -480,7 +480,7 @@  discard block
 block discarded – undo
480 480
                 $options      = [];
481 481
 
482 482
                 $options['map_ID'] = $map_ID && $map_ID != $venue->ID()
483
-                    ? $map_ID . '-' . $venue->ID()
483
+                    ? $map_ID.'-'.$venue->ID()
484 484
                     : $venue->ID();
485 485
 
486 486
                 $options['location'] = EEH_Address::format($venue, 'inline', false, false);
@@ -627,11 +627,11 @@  discard block
 block discarded – undo
627 627
                 $post_type_obj = get_post_type_object('espresso_venues');
628 628
                 // build final link html
629 629
                 $link =
630
-                    '<a class="post-edit-link" href="' . $url . '" title="' . esc_attr(
630
+                    '<a class="post-edit-link" href="'.$url.'" title="'.esc_attr(
631 631
                         $post_type_obj->labels->edit_item
632
-                    ) . '">' . $link . '</a>';
632
+                    ).'">'.$link.'</a>';
633 633
                 // put it all together
634
-                return $before . apply_filters('edit_post_link', $link, $venue->ID()) . $after;
634
+                return $before.apply_filters('edit_post_link', $link, $venue->ID()).$after;
635 635
             }
636 636
         }
637 637
         return '';
Please login to merge, or discard this patch.
Indentation   +626 added lines, -626 removed lines patch added patch discarded remove patch
@@ -9,630 +9,630 @@
 block discarded – undo
9 9
  */
10 10
 class EEH_Venue_View extends EEH_Base
11 11
 {
12
-    /**
13
-     * @access    private
14
-     * @var EE_Venue
15
-     */
16
-    private static $_venue = null;
17
-
18
-
19
-    /**
20
-     *    get_venue
21
-     *    attempts to retrieve an EE_Venue object any way it can
22
-     *
23
-     * @access    public
24
-     * @param int  $VNU_ID
25
-     * @param bool $look_in_event
26
-     * @param bool $privacy_check   Defaults to true.
27
-     *                              When false, means even if the venue is private we return it regardless of access.
28
-     * @param bool $password_check
29
-     * @return EE_Venue|null
30
-     * @throws EE_Error
31
-     * @throws ReflectionException
32
-     */
33
-    public static function get_venue($VNU_ID = 0, $look_in_event = true, $privacy_check = true, $password_check = true)
34
-    {
35
-        $VNU_ID = absint($VNU_ID);
36
-        // do we already have the Venue you are looking for?
37
-        if (EEH_Venue_View::$_venue instanceof EE_Venue && $VNU_ID) {
38
-            // If the Venue ID matches $VNU_ID, return the venue.
39
-            if (EEH_Venue_View::$_venue->ID() === $VNU_ID) {
40
-                return EEH_Venue_View::_get_venue($privacy_check);
41
-            }
42
-            // If the Venue ID does not match, try pulling a venue using $VNU_ID.
43
-            $venue = EEM_Venue::instance()->get_one_by_ID($VNU_ID);
44
-            if ($venue instanceof EE_Venue) {
45
-                EEH_Venue_View::$_venue = $venue;
46
-                return EEH_Venue_View::_get_venue($privacy_check);
47
-            }
48
-        }
49
-        // international newspaper?
50
-        global $post;
51
-        if ($post instanceof WP_Post) {
52
-            switch ($post->post_type) {
53
-                // if this is being called from an EE_Venue post,
54
-                // and the EE_Venue post corresponds to the EE_Venue that is being asked for,
55
-                // then we can try to just grab the attached EE_Venue object
56
-                case 'espresso_venues':
57
-                    // the post already contains the related EE_Venue object AND one of the following is TRUE:
58
-                    // the requested Venue ID matches the post ID OR...
59
-                    // there was no specific Venue ID requested
60
-                    if (isset($post->EE_Venue) && ($VNU_ID == $post->ID || ! $VNU_ID)) {
61
-                        // use existing related EE_Venue object
62
-                        EEH_Venue_View::$_venue = $post->EE_Venue;
63
-                    } elseif ($VNU_ID) {
64
-                        // there WAS a specific Venue ID requested, but it's NOT the current post object
65
-                        EEH_Venue_View::$_venue = EEM_Venue::instance()->get_one_by_ID($VNU_ID);
66
-                    } else {
67
-                        // no specific Venue ID requested, so use post ID to generate EE_Venue object
68
-                        EEH_Venue_View::$_venue = EEM_Venue::instance()->get_one_by_ID($post->ID);
69
-                    }
70
-                    break;
71
-
72
-                case 'espresso_events':
73
-                    if ($look_in_event) {
74
-                        // grab the events related venues
75
-                        $venues = EEH_Venue_View::get_event_venues();
76
-                        // make sure the result is an array
77
-                        $venues = is_array($venues) ? $venues : [];
78
-                        // do we have an ID for a specific venue?
79
-                        if ($VNU_ID) {
80
-                            // loop thru the related venues
81
-                            foreach ($venues as $venue) {
82
-                                if ($venue instanceof EE_Venue) {
83
-                                    // until we find the venue we're looking for
84
-                                    if ($venue->ID() == $VNU_ID) {
85
-                                        EEH_Venue_View::$_venue = $venue;
86
-                                        break;
87
-                                    }
88
-                                }
89
-                            }
90
-                            // no venue ID ?
91
-                            // then the global post is an events post and this function was called with no argument
92
-                        } else {
93
-                            // just grab the first related event venue
94
-                            EEH_Venue_View::$_venue = reset($venues);
95
-                        }
96
-                    }
97
-                    break;
98
-            }
99
-        }
100
-        // now if we STILL do NOT have an EE_Venue model object, BUT we have a Venue ID...
101
-        if (! EEH_Venue_View::$_venue instanceof EE_Venue && $VNU_ID) {
102
-            // sigh... pull it from the db
103
-            EEH_Venue_View::$_venue = EEM_Venue::instance()->get_one_by_ID($VNU_ID);
104
-        }
105
-        return EEH_Venue_View::_get_venue($privacy_check, $password_check);
106
-    }
107
-
108
-
109
-    /**
110
-     * return a single venue
111
-     *
112
-     * @param bool $privacy_check   Defaults to true.
113
-     *                              When false, means even if the venue is private we return it regardless of access.
114
-     * @param bool $password_check
115
-     * @return  EE_Venue
116
-     * @throws EE_Error
117
-     * @throws ReflectionException
118
-     */
119
-    protected static function _get_venue($privacy_check = true, $password_check = true)
120
-    {
121
-        // check for private venues.
122
-        if (
123
-            EEH_Venue_View::$_venue instanceof EE_Venue
124
-            && EEH_Venue_View::$_venue->status() == 'private'
125
-            && $privacy_check
126
-            && ! EE_Registry::instance()->CAP->current_user_can('ee_read_private_venues', 'get_venues')
127
-        ) {
128
-            return null;
129
-        }
130
-        // check for password protected venues
131
-        if (
132
-            EEH_Venue_View::$_venue instanceof EE_Venue
133
-            && $password_check
134
-            && post_password_required(EEH_Venue_View::$_venue->ID())
135
-        ) {
136
-            return null;
137
-        }
138
-        return EEH_Venue_View::$_venue instanceof EE_Venue ? EEH_Venue_View::$_venue : null;
139
-    }
140
-
141
-
142
-    /**
143
-     *  get_event_venues
144
-     *
145
-     * @access     public
146
-     * @return     EE_Venue[]
147
-     * @throws EE_Error
148
-     * @throws ReflectionException
149
-     */
150
-    public static function get_event_venues()
151
-    {
152
-        global $post;
153
-        if ($post->post_type == 'espresso_events') {
154
-            if (isset($post->EE_Event) && $post->EE_Event instanceof EE_Event) {
155
-                return $post->EE_Event->venues();
156
-            }
157
-        }
158
-        return [];
159
-    }
160
-
161
-
162
-    /**
163
-     * Simply checks whether a venue for the given ID (or the internally derived venue is private).
164
-     *
165
-     * Note: This will return true if its private, null if the venue doesn't exist, and false, if the venue exists but
166
-     * is not private.  So it is important to do explicit boolean checks when using this conditional.
167
-     *
168
-     * @param bool $VNU_ID venue to check (optional). If not included will use internally derived venue object.
169
-     *
170
-     * @return bool|null
171
-     * @throws EE_Error
172
-     * @throws ReflectionException
173
-     */
174
-    public static function is_venue_private($VNU_ID = false)
175
-    {
176
-        $venue = EEH_Venue_View::get_venue($VNU_ID);
177
-        if (! $venue instanceof EE_Venue) {
178
-            return null;
179
-        }
180
-
181
-        return $venue->status() == 'private';
182
-    }
183
-
184
-
185
-    /**
186
-     * returns true or false if a venue is password protected or not
187
-     *
188
-     * @param bool $VNU_ID venue to check (optional). If not included will use internally derived venue object.
189
-     * @return bool
190
-     * @throws EE_Error
191
-     * @throws ReflectionException
192
-     */
193
-    public static function is_venue_password_protected($VNU_ID = false)
194
-    {
195
-        $venue = EEH_Venue_View::get_venue($VNU_ID, true, true, false);
196
-        if (
197
-            $venue instanceof EE_Venue
198
-            && post_password_required($venue->ID())
199
-        ) {
200
-            return true;
201
-        }
202
-        return false;
203
-    }
204
-
205
-
206
-    /**
207
-     * If a venue is password protected, this will return the password form for gaining access
208
-     * returns an empty string otherwise
209
-     *
210
-     * @param bool $VNU_ID venue to check (optional). If not included will use internally derived venue object.
211
-     *
212
-     * @return string
213
-     * @throws EE_Error
214
-     * @throws ReflectionException
215
-     */
216
-    public static function password_protected_venue_form($VNU_ID = false)
217
-    {
218
-        $venue = EEH_Venue_View::get_venue($VNU_ID, true, true, false);
219
-        if (
220
-            $venue instanceof EE_Venue
221
-            && post_password_required($venue->ID())
222
-        ) {
223
-            return get_the_password_form($venue->ID());
224
-        }
225
-        return '';
226
-    }
227
-
228
-
229
-    /**
230
-     *    venue_description
231
-     *
232
-     * @access    public
233
-     * @param int $VNU_ID
234
-     * @return string
235
-     * @throws EE_Error
236
-     * @throws ReflectionException
237
-     */
238
-    public static function venue_description($VNU_ID = 0)
239
-    {
240
-        $venue = EEH_Venue_View::get_venue($VNU_ID);
241
-        if ($venue instanceof EE_Venue) {
242
-            return $venue->get_pretty('VNU_desc');
243
-        }
244
-        return '';
245
-    }
246
-
247
-
248
-    /**
249
-     *    venue_excerpt
250
-     *
251
-     * @access    public
252
-     * @param int $VNU_ID
253
-     * @return string
254
-     * @throws EE_Error
255
-     * @throws ReflectionException
256
-     */
257
-    public static function venue_excerpt($VNU_ID = 0)
258
-    {
259
-        $venue = EEH_Venue_View::get_venue($VNU_ID);
260
-        if ($venue instanceof EE_Venue) {
261
-            $excerpt    = $venue->excerpt() != null && $venue->excerpt() ? $venue->excerpt() : $venue->description();
262
-            $venue_link = ' ' . EEH_Venue_View::venue_details_link(
263
-                $venue->ID(),
264
-                esc_html__('more', 'event_espresso') . '&hellip;'
265
-            );
266
-            return ! empty($excerpt) ? wp_trim_words($excerpt, 25, '') . $venue_link : '';
267
-        }
268
-        return '';
269
-    }
270
-
271
-
272
-    /**
273
-     *    venue_categories
274
-     *
275
-     * @access    public
276
-     * @param int  $VNU_ID
277
-     * @param bool $hide_uncategorized
278
-     * @return string
279
-     * @throws EE_Error
280
-     * @throws ReflectionException
281
-     */
282
-    public static function venue_categories($VNU_ID = 0, $hide_uncategorized = true)
283
-    {
284
-        $category_links = [];
285
-        $venue          = EEH_Venue_View::get_venue($VNU_ID);
286
-        if ($venue instanceof EE_Venue) {
287
-            // get category terms
288
-            if ($venue_categories = get_the_terms($venue->ID(), 'espresso_venue_categories')) {
289
-                // loop thru terms and create links
290
-                foreach ($venue_categories as $term) {
291
-                    $url = get_term_link($term, 'espresso_venue_categories');
292
-                    if (
293
-                        ! is_wp_error($url)
294
-                        && (($hide_uncategorized
295
-                             && strtolower($term->name) != esc_html__(
296
-                                 'uncategorized',
297
-                                 'event_espresso'
298
-                             ))
299
-                            || ! $hide_uncategorized)
300
-                    ) {
301
-                        $category_links[] = '<a href="' . esc_url($url) . '" rel="tag">' . $term->name . '</a> ';
302
-                    }
303
-                }
304
-            }
305
-        }
306
-        return implode(', ', $category_links);
307
-    }
308
-
309
-
310
-    /**
311
-     *    venue_address
312
-     *
313
-     * @access    public
314
-     * @param string $type
315
-     * @param int    $VNU_ID
316
-     * @param bool   $use_schema
317
-     * @param bool   $add_wrapper
318
-     * @return string
319
-     * @throws EE_Error
320
-     * @throws ReflectionException
321
-     */
322
-    public static function venue_address($type = 'multiline', $VNU_ID = 0, $use_schema = true, $add_wrapper = true)
323
-    {
324
-        $venue = EEH_Venue_View::get_venue($VNU_ID);
325
-        if ($venue instanceof EE_Venue) {
326
-            return EEH_Address::format($venue, $type, $use_schema, $add_wrapper);
327
-        }
328
-        return '';
329
-    }
330
-
331
-
332
-    /**
333
-     *    venue_has_address
334
-     *
335
-     * @access    public
336
-     * @param int $VNU_ID
337
-     * @return bool|string
338
-     * @throws EE_Error
339
-     * @throws ReflectionException
340
-     */
341
-    public static function venue_has_address($VNU_ID = 0)
342
-    {
343
-        $venue = EEH_Venue_View::get_venue($VNU_ID);
344
-        if ($venue instanceof EE_Venue) {
345
-            return EEH_Address::format($venue, 'inline', false, false);
346
-        }
347
-        return false;
348
-    }
349
-
350
-
351
-    /**
352
-     *    venue_name
353
-     *
354
-     * @access    public
355
-     * @param string $link_to - options( details, website, none ) whether to turn Venue name into a clickable link to
356
-     *                        the Venue's details page or website
357
-     * @param int    $VNU_ID
358
-     * @return string
359
-     * @throws EE_Error
360
-     * @throws ReflectionException
361
-     */
362
-    public static function venue_name($link_to = 'details', $VNU_ID = 0)
363
-    {
364
-        $venue = EEH_Venue_View::get_venue($VNU_ID);
365
-        if ($venue instanceof EE_Venue) {
366
-            $venue_name = apply_filters(
367
-                'FHEE__EEH_Venue__venue_name__append_private_venue_name',
368
-                EEH_Venue_View::is_venue_private()
369
-                    ? EEH_Venue_View::$_venue->name() . "&nbsp;" . esc_html__('(Private)', 'event_espresso')
370
-                    : EEH_Venue_View::$_venue->name(),
371
-                EEH_Venue_View::$_venue
372
-            );
373
-            $venue_name = EEH_Schema::name($venue_name);
374
-
375
-            // if venue is trashed then ignore the "link to" setting because the venue is trashed.
376
-            if ($venue->get('status') == 'trash') {
377
-                $link_to = '';
378
-            }
379
-            switch ($link_to) {
380
-                case 'details':
381
-                    return EEH_Venue_View::venue_details_link($venue->ID(), $venue_name);
382
-
383
-                case 'website':
384
-                    return EEH_Venue_View::venue_website_link($venue->ID(), $venue_name);
385
-
386
-                default:
387
-                    return $venue_name;
388
-            }
389
-        }
390
-        return '';
391
-    }
392
-
393
-
394
-    /**
395
-     *    venue_details_link
396
-     *
397
-     * @access    public
398
-     * @param int    $VNU_ID
399
-     * @param string $text
400
-     * @return string
401
-     * @throws EE_Error
402
-     * @throws ReflectionException
403
-     */
404
-    public static function venue_details_link($VNU_ID = 0, $text = '')
405
-    {
406
-        $venue = EEH_Venue_View::get_venue($VNU_ID);
407
-        if ($venue instanceof EE_Venue) {
408
-            return EEH_Schema::url(get_permalink($venue->ID()), $text);
409
-        }
410
-        return '';
411
-    }
412
-
413
-
414
-    /**
415
-     *    venue_website_link
416
-     *
417
-     * @access    public
418
-     * @param int    $VNU_ID
419
-     * @param string $text
420
-     * @return string
421
-     * @throws EE_Error
422
-     * @throws ReflectionException
423
-     */
424
-    public static function venue_website_link($VNU_ID = 0, $text = '')
425
-    {
426
-        $venue = EEH_Venue_View::get_venue($VNU_ID);
427
-        if ($venue instanceof EE_Venue) {
428
-            $url  = $venue->venue_url();
429
-            $text = ! empty($text) ? $text : $url;
430
-            return ! empty($url) ? EEH_Schema::url($url, $text, ['target' => '_blank']) : '';
431
-        }
432
-        return '';
433
-    }
434
-
435
-
436
-    /**
437
-     *    venue_phone
438
-     *
439
-     * @access    public
440
-     * @param int $VNU_ID
441
-     * @return string
442
-     * @throws EE_Error
443
-     * @throws ReflectionException
444
-     */
445
-    public static function venue_phone($VNU_ID = 0)
446
-    {
447
-        $venue = EEH_Venue_View::get_venue($VNU_ID);
448
-        if ($venue instanceof EE_Venue) {
449
-            return EEH_Schema::telephone($venue->phone());
450
-        }
451
-        return '';
452
-    }
453
-
454
-
455
-    /**
456
-     *    venue_gmap
457
-     *
458
-     * @access    public
459
-     * @param int         $VNU_ID
460
-     * @param bool|string $map_ID a unique identifier for this map
461
-     * @param array       $gmap   map options
462
-     * @return string
463
-     * @throws EE_Error
464
-     * @throws ReflectionException
465
-     */
466
-    public static function venue_gmap($VNU_ID = 0, $map_ID = false, $gmap = [])
467
-    {
468
-
469
-        $venue = EEH_Venue_View::get_venue($VNU_ID);
470
-        if ($venue instanceof EE_Venue) {
471
-            // check for global espresso_events post and use it's ID if no map_ID is set
472
-            global $post;
473
-            $map_ID = empty($map_ID) && $post->post_type == 'espresso_events' ? $post->ID : $map_ID;
474
-            // grab map settings
475
-            $map_cfg = EE_Registry::instance()->CFG->map_settings;
476
-            // are maps enabled ?
477
-            if ($map_cfg->use_google_maps && $venue->enable_for_gmap()) {
478
-                $details_page = is_single();
479
-                $options      = [];
480
-
481
-                $options['map_ID'] = $map_ID && $map_ID != $venue->ID()
482
-                    ? $map_ID . '-' . $venue->ID()
483
-                    : $venue->ID();
484
-
485
-                $options['location'] = EEH_Address::format($venue, 'inline', false, false);
486
-
487
-                $options['ee_map_width'] = $details_page
488
-                    ? $map_cfg->event_details_map_width
489
-                    : $map_cfg->event_list_map_width;
490
-
491
-                $options['ee_map_width'] = isset($gmap['ee_map_width']) && ! empty($gmap['ee_map_width'])
492
-                    ? $gmap['ee_map_width']
493
-                    : $options['ee_map_width'];
494
-
495
-                $options['ee_map_height'] = $details_page
496
-                    ? $map_cfg->event_details_map_height
497
-                    : $map_cfg->event_list_map_height;
498
-
499
-                $options['ee_map_height'] = isset($gmap['ee_map_height']) && ! empty($gmap['ee_map_height'])
500
-                    ? $gmap['ee_map_height']
501
-                    : $options['ee_map_height'];
502
-
503
-                $options['ee_map_zoom'] = $details_page
504
-                    ? $map_cfg->event_details_map_zoom
505
-                    : $map_cfg->event_list_map_zoom;
506
-
507
-                $options['ee_map_zoom'] = isset($gmap['ee_map_zoom']) && ! empty($gmap['ee_map_zoom'])
508
-                    ? $gmap['ee_map_zoom']
509
-                    : $options['ee_map_zoom'];
510
-
511
-                $options['ee_map_nav_display'] = $details_page
512
-                    ? $map_cfg->event_details_display_nav
513
-                    : $map_cfg->event_list_display_nav;
514
-
515
-                $options['ee_map_nav_display'] =
516
-                    isset($gmap['ee_map_nav_display']) && ! empty($gmap['ee_map_nav_display'])
517
-                        ? 'true'
518
-                        : $options['ee_map_nav_display'];
519
-
520
-                $options['ee_map_nav_size'] = $details_page
521
-                    ? $map_cfg->event_details_nav_size
522
-                    : $map_cfg->event_list_nav_size;
523
-
524
-                $options['ee_map_nav_size'] = isset($gmap['ee_map_nav_size']) && ! empty($gmap['ee_map_nav_size'])
525
-                    ? $gmap['ee_map_nav_size']
526
-                    : $options['ee_map_nav_size'];
527
-
528
-                $options['ee_map_type_control'] = $details_page
529
-                    ? $map_cfg->event_details_control_type
530
-                    : $map_cfg->event_list_control_type;
531
-
532
-                $options['ee_map_type_control'] =
533
-                    isset($gmap['ee_map_type_control']) && ! empty($gmap['ee_map_type_control'])
534
-                        ? $gmap['ee_map_type_control']
535
-                        : $options['ee_map_type_control'];
536
-
537
-                $options['ee_map_align'] = $details_page
538
-                    ? $map_cfg->event_details_map_align
539
-                    : $map_cfg->event_list_map_align;
540
-
541
-                $options['ee_map_align'] = isset($gmap['ee_map_align']) && ! empty($gmap['ee_map_align'])
542
-                    ? $gmap['ee_map_align']
543
-                    : $options['ee_map_align'];
544
-
545
-                $options['ee_static_url'] = isset($gmap['ee_static_url']) && ! empty($gmap['ee_static_url'])
546
-                    ? (bool) absint($gmap['ee_static_url'])
547
-                    : $venue->google_map_link();
548
-
549
-                return EEH_Maps::google_map($options);
550
-            }
551
-        }
552
-
553
-        return '';
554
-    }
555
-
556
-
557
-    /**
558
-     * Gets the HTML to display a static map of the venue
559
-     *
560
-     * @param EE_Venue $venue
561
-     * @param array    $attributes like EEH_Maps::google_map_link
562
-     * @return string
563
-     * @throws EE_Error
564
-     * @throws ReflectionException
565
-     */
566
-    public static function espresso_google_static_map(EE_Venue $venue, $attributes = [])
567
-    {
568
-        $state      = $venue->state_obj();
569
-        $country    = $venue->country_obj();
570
-        $attributes = shortcode_atts(
571
-            [
572
-                'id'      => $venue->ID(),
573
-                'address' => $venue->get('VNU_address'),
574
-                'city'    => $venue->get('VNU_city'),
575
-                'state'   => $state instanceof EE_State ? $state->name() : '',
576
-                'zip'     => $venue->get('VNU_zip'),
577
-                'country' => $country instanceof EE_Country ? $country->name() : '',
578
-                'type'    => 'map',
579
-                'map_w'   => 200,
580
-                'map_h'   => 200,
581
-            ],
582
-            $attributes
583
-        );
584
-        return EEH_Maps::google_map_link($attributes);
585
-    }
586
-
587
-
588
-    /**
589
-     *    edit_venue_link
590
-     *
591
-     * @access    public
592
-     * @param int    $VNU_ID
593
-     * @param string $link
594
-     * @param string $before
595
-     * @param string $after
596
-     * @return string
597
-     * @throws EE_Error
598
-     * @throws ReflectionException
599
-     */
600
-    public static function edit_venue_link(
601
-        $VNU_ID = 0,
602
-        $link = '',
603
-        $before = '<p class="edit-venue-lnk small-txt">',
604
-        $after = '</p>'
605
-    ) {
606
-        $venue = EEH_Venue_View::get_venue($VNU_ID);
607
-        if ($venue instanceof EE_Venue) {
608
-            // can the user edit this post ?
609
-            if (current_user_can('edit_post', $venue->ID())) {
610
-                // set link text
611
-                $link = ! empty($link) ? $link : esc_html__('edit this venue', 'event_espresso');
612
-                // generate nonce
613
-                $nonce = wp_create_nonce('edit_nonce');
614
-                // generate url to venue editor for this venue
615
-                $url =
616
-                    add_query_arg(
617
-                        [
618
-                            'page'       => 'espresso_venues',
619
-                            'action'     => 'edit',
620
-                            'post'       => $venue->ID(),
621
-                            'edit_nonce' => $nonce,
622
-                        ],
623
-                        admin_url('admin.php')
624
-                    );
625
-                // get edit CPT text
626
-                $post_type_obj = get_post_type_object('espresso_venues');
627
-                // build final link html
628
-                $link =
629
-                    '<a class="post-edit-link" href="' . $url . '" title="' . esc_attr(
630
-                        $post_type_obj->labels->edit_item
631
-                    ) . '">' . $link . '</a>';
632
-                // put it all together
633
-                return $before . apply_filters('edit_post_link', $link, $venue->ID()) . $after;
634
-            }
635
-        }
636
-        return '';
637
-    }
12
+	/**
13
+	 * @access    private
14
+	 * @var EE_Venue
15
+	 */
16
+	private static $_venue = null;
17
+
18
+
19
+	/**
20
+	 *    get_venue
21
+	 *    attempts to retrieve an EE_Venue object any way it can
22
+	 *
23
+	 * @access    public
24
+	 * @param int  $VNU_ID
25
+	 * @param bool $look_in_event
26
+	 * @param bool $privacy_check   Defaults to true.
27
+	 *                              When false, means even if the venue is private we return it regardless of access.
28
+	 * @param bool $password_check
29
+	 * @return EE_Venue|null
30
+	 * @throws EE_Error
31
+	 * @throws ReflectionException
32
+	 */
33
+	public static function get_venue($VNU_ID = 0, $look_in_event = true, $privacy_check = true, $password_check = true)
34
+	{
35
+		$VNU_ID = absint($VNU_ID);
36
+		// do we already have the Venue you are looking for?
37
+		if (EEH_Venue_View::$_venue instanceof EE_Venue && $VNU_ID) {
38
+			// If the Venue ID matches $VNU_ID, return the venue.
39
+			if (EEH_Venue_View::$_venue->ID() === $VNU_ID) {
40
+				return EEH_Venue_View::_get_venue($privacy_check);
41
+			}
42
+			// If the Venue ID does not match, try pulling a venue using $VNU_ID.
43
+			$venue = EEM_Venue::instance()->get_one_by_ID($VNU_ID);
44
+			if ($venue instanceof EE_Venue) {
45
+				EEH_Venue_View::$_venue = $venue;
46
+				return EEH_Venue_View::_get_venue($privacy_check);
47
+			}
48
+		}
49
+		// international newspaper?
50
+		global $post;
51
+		if ($post instanceof WP_Post) {
52
+			switch ($post->post_type) {
53
+				// if this is being called from an EE_Venue post,
54
+				// and the EE_Venue post corresponds to the EE_Venue that is being asked for,
55
+				// then we can try to just grab the attached EE_Venue object
56
+				case 'espresso_venues':
57
+					// the post already contains the related EE_Venue object AND one of the following is TRUE:
58
+					// the requested Venue ID matches the post ID OR...
59
+					// there was no specific Venue ID requested
60
+					if (isset($post->EE_Venue) && ($VNU_ID == $post->ID || ! $VNU_ID)) {
61
+						// use existing related EE_Venue object
62
+						EEH_Venue_View::$_venue = $post->EE_Venue;
63
+					} elseif ($VNU_ID) {
64
+						// there WAS a specific Venue ID requested, but it's NOT the current post object
65
+						EEH_Venue_View::$_venue = EEM_Venue::instance()->get_one_by_ID($VNU_ID);
66
+					} else {
67
+						// no specific Venue ID requested, so use post ID to generate EE_Venue object
68
+						EEH_Venue_View::$_venue = EEM_Venue::instance()->get_one_by_ID($post->ID);
69
+					}
70
+					break;
71
+
72
+				case 'espresso_events':
73
+					if ($look_in_event) {
74
+						// grab the events related venues
75
+						$venues = EEH_Venue_View::get_event_venues();
76
+						// make sure the result is an array
77
+						$venues = is_array($venues) ? $venues : [];
78
+						// do we have an ID for a specific venue?
79
+						if ($VNU_ID) {
80
+							// loop thru the related venues
81
+							foreach ($venues as $venue) {
82
+								if ($venue instanceof EE_Venue) {
83
+									// until we find the venue we're looking for
84
+									if ($venue->ID() == $VNU_ID) {
85
+										EEH_Venue_View::$_venue = $venue;
86
+										break;
87
+									}
88
+								}
89
+							}
90
+							// no venue ID ?
91
+							// then the global post is an events post and this function was called with no argument
92
+						} else {
93
+							// just grab the first related event venue
94
+							EEH_Venue_View::$_venue = reset($venues);
95
+						}
96
+					}
97
+					break;
98
+			}
99
+		}
100
+		// now if we STILL do NOT have an EE_Venue model object, BUT we have a Venue ID...
101
+		if (! EEH_Venue_View::$_venue instanceof EE_Venue && $VNU_ID) {
102
+			// sigh... pull it from the db
103
+			EEH_Venue_View::$_venue = EEM_Venue::instance()->get_one_by_ID($VNU_ID);
104
+		}
105
+		return EEH_Venue_View::_get_venue($privacy_check, $password_check);
106
+	}
107
+
108
+
109
+	/**
110
+	 * return a single venue
111
+	 *
112
+	 * @param bool $privacy_check   Defaults to true.
113
+	 *                              When false, means even if the venue is private we return it regardless of access.
114
+	 * @param bool $password_check
115
+	 * @return  EE_Venue
116
+	 * @throws EE_Error
117
+	 * @throws ReflectionException
118
+	 */
119
+	protected static function _get_venue($privacy_check = true, $password_check = true)
120
+	{
121
+		// check for private venues.
122
+		if (
123
+			EEH_Venue_View::$_venue instanceof EE_Venue
124
+			&& EEH_Venue_View::$_venue->status() == 'private'
125
+			&& $privacy_check
126
+			&& ! EE_Registry::instance()->CAP->current_user_can('ee_read_private_venues', 'get_venues')
127
+		) {
128
+			return null;
129
+		}
130
+		// check for password protected venues
131
+		if (
132
+			EEH_Venue_View::$_venue instanceof EE_Venue
133
+			&& $password_check
134
+			&& post_password_required(EEH_Venue_View::$_venue->ID())
135
+		) {
136
+			return null;
137
+		}
138
+		return EEH_Venue_View::$_venue instanceof EE_Venue ? EEH_Venue_View::$_venue : null;
139
+	}
140
+
141
+
142
+	/**
143
+	 *  get_event_venues
144
+	 *
145
+	 * @access     public
146
+	 * @return     EE_Venue[]
147
+	 * @throws EE_Error
148
+	 * @throws ReflectionException
149
+	 */
150
+	public static function get_event_venues()
151
+	{
152
+		global $post;
153
+		if ($post->post_type == 'espresso_events') {
154
+			if (isset($post->EE_Event) && $post->EE_Event instanceof EE_Event) {
155
+				return $post->EE_Event->venues();
156
+			}
157
+		}
158
+		return [];
159
+	}
160
+
161
+
162
+	/**
163
+	 * Simply checks whether a venue for the given ID (or the internally derived venue is private).
164
+	 *
165
+	 * Note: This will return true if its private, null if the venue doesn't exist, and false, if the venue exists but
166
+	 * is not private.  So it is important to do explicit boolean checks when using this conditional.
167
+	 *
168
+	 * @param bool $VNU_ID venue to check (optional). If not included will use internally derived venue object.
169
+	 *
170
+	 * @return bool|null
171
+	 * @throws EE_Error
172
+	 * @throws ReflectionException
173
+	 */
174
+	public static function is_venue_private($VNU_ID = false)
175
+	{
176
+		$venue = EEH_Venue_View::get_venue($VNU_ID);
177
+		if (! $venue instanceof EE_Venue) {
178
+			return null;
179
+		}
180
+
181
+		return $venue->status() == 'private';
182
+	}
183
+
184
+
185
+	/**
186
+	 * returns true or false if a venue is password protected or not
187
+	 *
188
+	 * @param bool $VNU_ID venue to check (optional). If not included will use internally derived venue object.
189
+	 * @return bool
190
+	 * @throws EE_Error
191
+	 * @throws ReflectionException
192
+	 */
193
+	public static function is_venue_password_protected($VNU_ID = false)
194
+	{
195
+		$venue = EEH_Venue_View::get_venue($VNU_ID, true, true, false);
196
+		if (
197
+			$venue instanceof EE_Venue
198
+			&& post_password_required($venue->ID())
199
+		) {
200
+			return true;
201
+		}
202
+		return false;
203
+	}
204
+
205
+
206
+	/**
207
+	 * If a venue is password protected, this will return the password form for gaining access
208
+	 * returns an empty string otherwise
209
+	 *
210
+	 * @param bool $VNU_ID venue to check (optional). If not included will use internally derived venue object.
211
+	 *
212
+	 * @return string
213
+	 * @throws EE_Error
214
+	 * @throws ReflectionException
215
+	 */
216
+	public static function password_protected_venue_form($VNU_ID = false)
217
+	{
218
+		$venue = EEH_Venue_View::get_venue($VNU_ID, true, true, false);
219
+		if (
220
+			$venue instanceof EE_Venue
221
+			&& post_password_required($venue->ID())
222
+		) {
223
+			return get_the_password_form($venue->ID());
224
+		}
225
+		return '';
226
+	}
227
+
228
+
229
+	/**
230
+	 *    venue_description
231
+	 *
232
+	 * @access    public
233
+	 * @param int $VNU_ID
234
+	 * @return string
235
+	 * @throws EE_Error
236
+	 * @throws ReflectionException
237
+	 */
238
+	public static function venue_description($VNU_ID = 0)
239
+	{
240
+		$venue = EEH_Venue_View::get_venue($VNU_ID);
241
+		if ($venue instanceof EE_Venue) {
242
+			return $venue->get_pretty('VNU_desc');
243
+		}
244
+		return '';
245
+	}
246
+
247
+
248
+	/**
249
+	 *    venue_excerpt
250
+	 *
251
+	 * @access    public
252
+	 * @param int $VNU_ID
253
+	 * @return string
254
+	 * @throws EE_Error
255
+	 * @throws ReflectionException
256
+	 */
257
+	public static function venue_excerpt($VNU_ID = 0)
258
+	{
259
+		$venue = EEH_Venue_View::get_venue($VNU_ID);
260
+		if ($venue instanceof EE_Venue) {
261
+			$excerpt    = $venue->excerpt() != null && $venue->excerpt() ? $venue->excerpt() : $venue->description();
262
+			$venue_link = ' ' . EEH_Venue_View::venue_details_link(
263
+				$venue->ID(),
264
+				esc_html__('more', 'event_espresso') . '&hellip;'
265
+			);
266
+			return ! empty($excerpt) ? wp_trim_words($excerpt, 25, '') . $venue_link : '';
267
+		}
268
+		return '';
269
+	}
270
+
271
+
272
+	/**
273
+	 *    venue_categories
274
+	 *
275
+	 * @access    public
276
+	 * @param int  $VNU_ID
277
+	 * @param bool $hide_uncategorized
278
+	 * @return string
279
+	 * @throws EE_Error
280
+	 * @throws ReflectionException
281
+	 */
282
+	public static function venue_categories($VNU_ID = 0, $hide_uncategorized = true)
283
+	{
284
+		$category_links = [];
285
+		$venue          = EEH_Venue_View::get_venue($VNU_ID);
286
+		if ($venue instanceof EE_Venue) {
287
+			// get category terms
288
+			if ($venue_categories = get_the_terms($venue->ID(), 'espresso_venue_categories')) {
289
+				// loop thru terms and create links
290
+				foreach ($venue_categories as $term) {
291
+					$url = get_term_link($term, 'espresso_venue_categories');
292
+					if (
293
+						! is_wp_error($url)
294
+						&& (($hide_uncategorized
295
+							 && strtolower($term->name) != esc_html__(
296
+								 'uncategorized',
297
+								 'event_espresso'
298
+							 ))
299
+							|| ! $hide_uncategorized)
300
+					) {
301
+						$category_links[] = '<a href="' . esc_url($url) . '" rel="tag">' . $term->name . '</a> ';
302
+					}
303
+				}
304
+			}
305
+		}
306
+		return implode(', ', $category_links);
307
+	}
308
+
309
+
310
+	/**
311
+	 *    venue_address
312
+	 *
313
+	 * @access    public
314
+	 * @param string $type
315
+	 * @param int    $VNU_ID
316
+	 * @param bool   $use_schema
317
+	 * @param bool   $add_wrapper
318
+	 * @return string
319
+	 * @throws EE_Error
320
+	 * @throws ReflectionException
321
+	 */
322
+	public static function venue_address($type = 'multiline', $VNU_ID = 0, $use_schema = true, $add_wrapper = true)
323
+	{
324
+		$venue = EEH_Venue_View::get_venue($VNU_ID);
325
+		if ($venue instanceof EE_Venue) {
326
+			return EEH_Address::format($venue, $type, $use_schema, $add_wrapper);
327
+		}
328
+		return '';
329
+	}
330
+
331
+
332
+	/**
333
+	 *    venue_has_address
334
+	 *
335
+	 * @access    public
336
+	 * @param int $VNU_ID
337
+	 * @return bool|string
338
+	 * @throws EE_Error
339
+	 * @throws ReflectionException
340
+	 */
341
+	public static function venue_has_address($VNU_ID = 0)
342
+	{
343
+		$venue = EEH_Venue_View::get_venue($VNU_ID);
344
+		if ($venue instanceof EE_Venue) {
345
+			return EEH_Address::format($venue, 'inline', false, false);
346
+		}
347
+		return false;
348
+	}
349
+
350
+
351
+	/**
352
+	 *    venue_name
353
+	 *
354
+	 * @access    public
355
+	 * @param string $link_to - options( details, website, none ) whether to turn Venue name into a clickable link to
356
+	 *                        the Venue's details page or website
357
+	 * @param int    $VNU_ID
358
+	 * @return string
359
+	 * @throws EE_Error
360
+	 * @throws ReflectionException
361
+	 */
362
+	public static function venue_name($link_to = 'details', $VNU_ID = 0)
363
+	{
364
+		$venue = EEH_Venue_View::get_venue($VNU_ID);
365
+		if ($venue instanceof EE_Venue) {
366
+			$venue_name = apply_filters(
367
+				'FHEE__EEH_Venue__venue_name__append_private_venue_name',
368
+				EEH_Venue_View::is_venue_private()
369
+					? EEH_Venue_View::$_venue->name() . "&nbsp;" . esc_html__('(Private)', 'event_espresso')
370
+					: EEH_Venue_View::$_venue->name(),
371
+				EEH_Venue_View::$_venue
372
+			);
373
+			$venue_name = EEH_Schema::name($venue_name);
374
+
375
+			// if venue is trashed then ignore the "link to" setting because the venue is trashed.
376
+			if ($venue->get('status') == 'trash') {
377
+				$link_to = '';
378
+			}
379
+			switch ($link_to) {
380
+				case 'details':
381
+					return EEH_Venue_View::venue_details_link($venue->ID(), $venue_name);
382
+
383
+				case 'website':
384
+					return EEH_Venue_View::venue_website_link($venue->ID(), $venue_name);
385
+
386
+				default:
387
+					return $venue_name;
388
+			}
389
+		}
390
+		return '';
391
+	}
392
+
393
+
394
+	/**
395
+	 *    venue_details_link
396
+	 *
397
+	 * @access    public
398
+	 * @param int    $VNU_ID
399
+	 * @param string $text
400
+	 * @return string
401
+	 * @throws EE_Error
402
+	 * @throws ReflectionException
403
+	 */
404
+	public static function venue_details_link($VNU_ID = 0, $text = '')
405
+	{
406
+		$venue = EEH_Venue_View::get_venue($VNU_ID);
407
+		if ($venue instanceof EE_Venue) {
408
+			return EEH_Schema::url(get_permalink($venue->ID()), $text);
409
+		}
410
+		return '';
411
+	}
412
+
413
+
414
+	/**
415
+	 *    venue_website_link
416
+	 *
417
+	 * @access    public
418
+	 * @param int    $VNU_ID
419
+	 * @param string $text
420
+	 * @return string
421
+	 * @throws EE_Error
422
+	 * @throws ReflectionException
423
+	 */
424
+	public static function venue_website_link($VNU_ID = 0, $text = '')
425
+	{
426
+		$venue = EEH_Venue_View::get_venue($VNU_ID);
427
+		if ($venue instanceof EE_Venue) {
428
+			$url  = $venue->venue_url();
429
+			$text = ! empty($text) ? $text : $url;
430
+			return ! empty($url) ? EEH_Schema::url($url, $text, ['target' => '_blank']) : '';
431
+		}
432
+		return '';
433
+	}
434
+
435
+
436
+	/**
437
+	 *    venue_phone
438
+	 *
439
+	 * @access    public
440
+	 * @param int $VNU_ID
441
+	 * @return string
442
+	 * @throws EE_Error
443
+	 * @throws ReflectionException
444
+	 */
445
+	public static function venue_phone($VNU_ID = 0)
446
+	{
447
+		$venue = EEH_Venue_View::get_venue($VNU_ID);
448
+		if ($venue instanceof EE_Venue) {
449
+			return EEH_Schema::telephone($venue->phone());
450
+		}
451
+		return '';
452
+	}
453
+
454
+
455
+	/**
456
+	 *    venue_gmap
457
+	 *
458
+	 * @access    public
459
+	 * @param int         $VNU_ID
460
+	 * @param bool|string $map_ID a unique identifier for this map
461
+	 * @param array       $gmap   map options
462
+	 * @return string
463
+	 * @throws EE_Error
464
+	 * @throws ReflectionException
465
+	 */
466
+	public static function venue_gmap($VNU_ID = 0, $map_ID = false, $gmap = [])
467
+	{
468
+
469
+		$venue = EEH_Venue_View::get_venue($VNU_ID);
470
+		if ($venue instanceof EE_Venue) {
471
+			// check for global espresso_events post and use it's ID if no map_ID is set
472
+			global $post;
473
+			$map_ID = empty($map_ID) && $post->post_type == 'espresso_events' ? $post->ID : $map_ID;
474
+			// grab map settings
475
+			$map_cfg = EE_Registry::instance()->CFG->map_settings;
476
+			// are maps enabled ?
477
+			if ($map_cfg->use_google_maps && $venue->enable_for_gmap()) {
478
+				$details_page = is_single();
479
+				$options      = [];
480
+
481
+				$options['map_ID'] = $map_ID && $map_ID != $venue->ID()
482
+					? $map_ID . '-' . $venue->ID()
483
+					: $venue->ID();
484
+
485
+				$options['location'] = EEH_Address::format($venue, 'inline', false, false);
486
+
487
+				$options['ee_map_width'] = $details_page
488
+					? $map_cfg->event_details_map_width
489
+					: $map_cfg->event_list_map_width;
490
+
491
+				$options['ee_map_width'] = isset($gmap['ee_map_width']) && ! empty($gmap['ee_map_width'])
492
+					? $gmap['ee_map_width']
493
+					: $options['ee_map_width'];
494
+
495
+				$options['ee_map_height'] = $details_page
496
+					? $map_cfg->event_details_map_height
497
+					: $map_cfg->event_list_map_height;
498
+
499
+				$options['ee_map_height'] = isset($gmap['ee_map_height']) && ! empty($gmap['ee_map_height'])
500
+					? $gmap['ee_map_height']
501
+					: $options['ee_map_height'];
502
+
503
+				$options['ee_map_zoom'] = $details_page
504
+					? $map_cfg->event_details_map_zoom
505
+					: $map_cfg->event_list_map_zoom;
506
+
507
+				$options['ee_map_zoom'] = isset($gmap['ee_map_zoom']) && ! empty($gmap['ee_map_zoom'])
508
+					? $gmap['ee_map_zoom']
509
+					: $options['ee_map_zoom'];
510
+
511
+				$options['ee_map_nav_display'] = $details_page
512
+					? $map_cfg->event_details_display_nav
513
+					: $map_cfg->event_list_display_nav;
514
+
515
+				$options['ee_map_nav_display'] =
516
+					isset($gmap['ee_map_nav_display']) && ! empty($gmap['ee_map_nav_display'])
517
+						? 'true'
518
+						: $options['ee_map_nav_display'];
519
+
520
+				$options['ee_map_nav_size'] = $details_page
521
+					? $map_cfg->event_details_nav_size
522
+					: $map_cfg->event_list_nav_size;
523
+
524
+				$options['ee_map_nav_size'] = isset($gmap['ee_map_nav_size']) && ! empty($gmap['ee_map_nav_size'])
525
+					? $gmap['ee_map_nav_size']
526
+					: $options['ee_map_nav_size'];
527
+
528
+				$options['ee_map_type_control'] = $details_page
529
+					? $map_cfg->event_details_control_type
530
+					: $map_cfg->event_list_control_type;
531
+
532
+				$options['ee_map_type_control'] =
533
+					isset($gmap['ee_map_type_control']) && ! empty($gmap['ee_map_type_control'])
534
+						? $gmap['ee_map_type_control']
535
+						: $options['ee_map_type_control'];
536
+
537
+				$options['ee_map_align'] = $details_page
538
+					? $map_cfg->event_details_map_align
539
+					: $map_cfg->event_list_map_align;
540
+
541
+				$options['ee_map_align'] = isset($gmap['ee_map_align']) && ! empty($gmap['ee_map_align'])
542
+					? $gmap['ee_map_align']
543
+					: $options['ee_map_align'];
544
+
545
+				$options['ee_static_url'] = isset($gmap['ee_static_url']) && ! empty($gmap['ee_static_url'])
546
+					? (bool) absint($gmap['ee_static_url'])
547
+					: $venue->google_map_link();
548
+
549
+				return EEH_Maps::google_map($options);
550
+			}
551
+		}
552
+
553
+		return '';
554
+	}
555
+
556
+
557
+	/**
558
+	 * Gets the HTML to display a static map of the venue
559
+	 *
560
+	 * @param EE_Venue $venue
561
+	 * @param array    $attributes like EEH_Maps::google_map_link
562
+	 * @return string
563
+	 * @throws EE_Error
564
+	 * @throws ReflectionException
565
+	 */
566
+	public static function espresso_google_static_map(EE_Venue $venue, $attributes = [])
567
+	{
568
+		$state      = $venue->state_obj();
569
+		$country    = $venue->country_obj();
570
+		$attributes = shortcode_atts(
571
+			[
572
+				'id'      => $venue->ID(),
573
+				'address' => $venue->get('VNU_address'),
574
+				'city'    => $venue->get('VNU_city'),
575
+				'state'   => $state instanceof EE_State ? $state->name() : '',
576
+				'zip'     => $venue->get('VNU_zip'),
577
+				'country' => $country instanceof EE_Country ? $country->name() : '',
578
+				'type'    => 'map',
579
+				'map_w'   => 200,
580
+				'map_h'   => 200,
581
+			],
582
+			$attributes
583
+		);
584
+		return EEH_Maps::google_map_link($attributes);
585
+	}
586
+
587
+
588
+	/**
589
+	 *    edit_venue_link
590
+	 *
591
+	 * @access    public
592
+	 * @param int    $VNU_ID
593
+	 * @param string $link
594
+	 * @param string $before
595
+	 * @param string $after
596
+	 * @return string
597
+	 * @throws EE_Error
598
+	 * @throws ReflectionException
599
+	 */
600
+	public static function edit_venue_link(
601
+		$VNU_ID = 0,
602
+		$link = '',
603
+		$before = '<p class="edit-venue-lnk small-txt">',
604
+		$after = '</p>'
605
+	) {
606
+		$venue = EEH_Venue_View::get_venue($VNU_ID);
607
+		if ($venue instanceof EE_Venue) {
608
+			// can the user edit this post ?
609
+			if (current_user_can('edit_post', $venue->ID())) {
610
+				// set link text
611
+				$link = ! empty($link) ? $link : esc_html__('edit this venue', 'event_espresso');
612
+				// generate nonce
613
+				$nonce = wp_create_nonce('edit_nonce');
614
+				// generate url to venue editor for this venue
615
+				$url =
616
+					add_query_arg(
617
+						[
618
+							'page'       => 'espresso_venues',
619
+							'action'     => 'edit',
620
+							'post'       => $venue->ID(),
621
+							'edit_nonce' => $nonce,
622
+						],
623
+						admin_url('admin.php')
624
+					);
625
+				// get edit CPT text
626
+				$post_type_obj = get_post_type_object('espresso_venues');
627
+				// build final link html
628
+				$link =
629
+					'<a class="post-edit-link" href="' . $url . '" title="' . esc_attr(
630
+						$post_type_obj->labels->edit_item
631
+					) . '">' . $link . '</a>';
632
+				// put it all together
633
+				return $before . apply_filters('edit_post_link', $link, $venue->ID()) . $after;
634
+			}
635
+		}
636
+		return '';
637
+	}
638 638
 }
Please login to merge, or discard this patch.
core/helpers/EEH_Event_View.helper.php 2 patches
Spacing   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -38,7 +38,7 @@  discard block
 block discarded – undo
38 38
         }
39 39
         // reset property so that the new event is cached.
40 40
         EEH_Event_View::$_event = null;
41
-        if (! $EVT_ID && $post instanceof EE_Event) {
41
+        if ( ! $EVT_ID && $post instanceof EE_Event) {
42 42
             EEH_Event_View::$_event = $post;
43 43
             return EEH_Event_View::$_event;
44 44
         }
@@ -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;
@@ -164,18 +164,18 @@  discard block
 block discarded – undo
164 164
                 // admin has chosen "excerpt (short desc)"
165 165
                 // for the "Event Espresso - Events > Templates > Display Description" option
166 166
                 // but NO excerpt actually exists, so we need to create one
167
-                if (! empty($num_words)) {
167
+                if ( ! empty($num_words)) {
168 168
                     if (empty($more)) {
169 169
                         $more_link_text = esc_html__('(more&hellip;)', 'event_espresso');
170
-                        $more           = ' <a href="' . get_permalink() . '"';
170
+                        $more           = ' <a href="'.get_permalink().'"';
171 171
                         $more           .= ' class="more-link"';
172 172
                         $more           .= EED_Events_Archive::link_target();
173
-                        $more           .= '>' . $more_link_text . '</a>';
174
-                        $more           = apply_filters('the_content_more_link', $more, $more_link_text);
173
+                        $more           .= '>'.$more_link_text.'</a>';
174
+                        $more = apply_filters('the_content_more_link', $more, $more_link_text);
175 175
                     }
176 176
                     $content = str_replace('NOMORELINK', '', get_the_content('NOMORELINK'));
177 177
 
178
-                    $content = wp_trim_words($content, $num_words, ' ') . $more;
178
+                    $content = wp_trim_words($content, $num_words, ' ').$more;
179 179
                 } else {
180 180
                     $content = get_the_content();
181 181
                 }
@@ -257,8 +257,8 @@  discard block
 block discarded – undo
257 257
                             || ! $hide_uncategorized
258 258
                         )
259 259
                     ) {
260
-                        $category_links[] = '<a href="' . esc_url_raw($url) . '" '
261
-                                            . 'rel="tag" ' . EED_Events_Archive::link_target() . '>'
260
+                        $category_links[] = '<a href="'.esc_url_raw($url).'" '
261
+                                            . 'rel="tag" '.EED_Events_Archive::link_target().'>'
262 262
                                             . esc_html($term->name)
263 263
                                             . '</a>';
264 264
                     }
@@ -283,8 +283,8 @@  discard block
 block discarded – undo
283 283
     {
284 284
         $datetime = EEH_Event_View::get_primary_date_obj($EVT_ID);
285 285
         $format   = ! empty($date_format) && ! empty($time_format)
286
-                ? $date_format . ' ' . $time_format
287
-                : $date_format . $time_format;
286
+                ? $date_format.' '.$time_format
287
+                : $date_format.$time_format;
288 288
         return $datetime instanceof EE_Datetime ? $datetime->get_i18n_datetime('DTT_EVT_start', $format) : '';
289 289
     }
290 290
 
@@ -304,7 +304,7 @@  discard block
 block discarded – undo
304 304
         $datetime = EEH_Event_View::get_last_date_obj($EVT_ID);
305 305
         $format   =
306 306
             ! empty($date_format) && ! empty($time_format)
307
-                ? $date_format . ' ' . $time_format
307
+                ? $date_format.' '.$time_format
308 308
                 : $date_format
309 309
                   . $time_format;
310 310
         return $datetime instanceof EE_Datetime ? $datetime->get_i18n_datetime('DTT_EVT_end', $format) : '';
@@ -326,7 +326,7 @@  discard block
 block discarded – undo
326 326
         $datetime = EEH_Event_View::get_earliest_date_obj($EVT_ID);
327 327
         $format   =
328 328
             ! empty($date_format) && ! empty($time_format)
329
-                ? $date_format . ' ' . $time_format
329
+                ? $date_format.' '.$time_format
330 330
                 : $date_format
331 331
                   . $time_format;
332 332
         return $datetime instanceof EE_Datetime ? $datetime->get_i18n_datetime('DTT_EVT_start', $format) : '';
@@ -348,7 +348,7 @@  discard block
 block discarded – undo
348 348
         $datetime = EEH_Event_View::get_latest_date_obj($EVT_ID);
349 349
         $format   =
350 350
             ! empty($date_format) && ! empty($time_format)
351
-                ? $date_format . ' ' . $time_format
351
+                ? $date_format.' '.$time_format
352 352
                 : $date_format
353 353
                   . $time_format;
354 354
         return $datetime instanceof EE_Datetime ? $datetime->get_i18n_datetime('DTT_EVT_end', $format) : '';
@@ -553,7 +553,7 @@  discard block
 block discarded – undo
553 553
             $url = $event->external_url() !== null && $event->external_url() !== ''
554 554
                 ? $event->external_url()
555 555
                 : get_permalink($event->ID());
556
-            $url = preg_match("~^(?:f|ht)tps?://~i", $url) ? $url : 'https://' . $url;
556
+            $url = preg_match("~^(?:f|ht)tps?://~i", $url) ? $url : 'https://'.$url;
557 557
             return esc_url_raw($url);
558 558
         }
559 559
         return '';
@@ -614,12 +614,12 @@  discard block
 block discarded – undo
614 614
                 // get edit CPT text
615 615
                 $post_type_obj = get_post_type_object('espresso_events');
616 616
                 // build final link html
617
-                $link = '<a class="post-edit-link" href="' . $url . '" ';
618
-                $link .= ' title="' . esc_attr($post_type_obj->labels->edit_item) . '"';
617
+                $link = '<a class="post-edit-link" href="'.$url.'" ';
618
+                $link .= ' title="'.esc_attr($post_type_obj->labels->edit_item).'"';
619 619
                 $link .= EED_Events_Archive::link_target();
620
-                $link .= '>' . $link_text . '</a>';
620
+                $link .= '>'.$link_text.'</a>';
621 621
                 // put it all together
622
-                return $before . apply_filters('edit_post_link', $link, $event->ID()) . $after;
622
+                return $before.apply_filters('edit_post_link', $link, $event->ID()).$after;
623 623
             }
624 624
         }
625 625
         return '';
Please login to merge, or discard this patch.
Indentation   +614 added lines, -614 removed lines patch added patch discarded remove patch
@@ -9,364 +9,364 @@  discard block
 block discarded – undo
9 9
  */
10 10
 class EEH_Event_View extends EEH_Base
11 11
 {
12
-    /**
13
-     * @var EE_Event $_event
14
-     */
15
-    private static $_event = null;
16
-
17
-
18
-    /**
19
-     * get_event
20
-     * attempts to retrieve an EE_Event object any way it can
21
-     *
22
-     * @param int|WP_Post $EVT_ID
23
-     * @return EE_Event|null
24
-     * @throws EE_Error
25
-     * @throws ReflectionException
26
-     */
27
-    public static function get_event($EVT_ID = 0)
28
-    {
29
-        // international newspaper?
30
-        global $post;
31
-        $EVT_ID = $EVT_ID instanceof WP_Post && $EVT_ID->post_type === 'espresso_events'
32
-            ? $EVT_ID->ID
33
-            : absint($EVT_ID);
34
-        // do we already have the Event  you are looking for?
35
-        if (EEH_Event_View::$_event instanceof EE_Event && $EVT_ID && EEH_Event_View::$_event->ID() === $EVT_ID) {
36
-            return EEH_Event_View::$_event;
37
-        }
38
-        // reset property so that the new event is cached.
39
-        EEH_Event_View::$_event = null;
40
-        if (! $EVT_ID && $post instanceof EE_Event) {
41
-            EEH_Event_View::$_event = $post;
42
-            return EEH_Event_View::$_event;
43
-        }
44
-        // if the post type is for an event and it has a cached event and we don't have a different incoming $EVT_ID
45
-        // then let's just use that cached event on the $post object.
46
-        if (
47
-            $post instanceof WP_Post
48
-            && $post->post_type === 'espresso_events'
49
-            && isset($post->EE_Event)
50
-            && (
51
-                $EVT_ID === 0
52
-                || $EVT_ID === $post->ID
53
-            )
54
-        ) {
55
-            EEH_Event_View::$_event = $post->EE_Event;
56
-            return EEH_Event_View::$_event;
57
-        }
58
-        // 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.
59
-        if (! EEH_Event_View::$_event instanceof EE_Event && $EVT_ID) {
60
-            EEH_Event_View::$_event = EEM_Event::instance()->get_one_by_ID($EVT_ID);
61
-        }
62
-        return EEH_Event_View::$_event;
63
-    }
64
-
65
-
66
-    /**
67
-     *    display_ticket_selector
68
-     *
69
-     * @param int $EVT_ID
70
-     * @return    boolean
71
-     * @throws EE_Error
72
-     * @throws EE_Error
73
-     * @throws ReflectionException
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();
79
-    }
80
-
81
-
82
-    /**
83
-     *    event_status
84
-     *
85
-     * @param int $EVT_ID
86
-     * @return    string
87
-     * @throws EE_Error
88
-     * @throws EE_Error
89
-     * @throws ReflectionException
90
-     */
91
-    public static function event_status($EVT_ID = 0)
92
-    {
93
-        $event = EEH_Event_View::get_event($EVT_ID);
94
-        return $event instanceof EE_Event ? $event->pretty_active_status(false) : '';
95
-    }
96
-
97
-
98
-    /**
99
-     *  event_active_status
100
-     *
101
-     * @param int $EVT_ID
102
-     * @return     string
103
-     * @throws EE_Error
104
-     * @throws EE_Error
105
-     * @throws ReflectionException
106
-     */
107
-    public static function event_active_status($EVT_ID = 0, $echo = true)
108
-    {
109
-        $event = EEH_Event_View::get_event($EVT_ID);
110
-        return $event instanceof EE_Event ? $event->pretty_active_status($echo) : 'inactive';
111
-    }
112
-
113
-
114
-    /**
115
-     *  event_has_content_or_excerpt
116
-     *
117
-     * @param int $EVT_ID
118
-     * @return     bool
119
-     * @throws EE_Error
120
-     * @throws EE_Error
121
-     * @throws ReflectionException
122
-     */
123
-    public static function event_has_content_or_excerpt($EVT_ID = 0)
124
-    {
125
-        $event                  = EEH_Event_View::get_event($EVT_ID);
126
-        $has_content_or_excerpt = false;
127
-        if ($event instanceof EE_Event) {
128
-            $has_content_or_excerpt = $event->description() != '' || $event->short_description(null, null, true) != '';
129
-        }
130
-        if (
131
-            is_archive()
132
-            && ! (espresso_display_full_description_in_event_list()
133
-                  || espresso_display_excerpt_in_event_list())
134
-        ) {
135
-            $has_content_or_excerpt = false;
136
-        }
137
-        return $has_content_or_excerpt;
138
-    }
139
-
140
-
141
-    /**
142
-     *    event_active_status
143
-     *
144
-     * @param null $num_words
145
-     * @param null $more
146
-     * @return    string
147
-     */
148
-    public static function event_content_or_excerpt($num_words = null, $more = null)
149
-    {
150
-        global $post;
151
-        ob_start();
152
-        if ((is_single()) || (is_archive() && espresso_display_full_description_in_event_list())) {
153
-            // admin has chosen "full description"
154
-            // for the "Event Espresso - Events > Templates > Display Description" option
155
-            the_content();
156
-        } elseif ((is_archive() && espresso_display_excerpt_in_event_list())) {
157
-            if (has_excerpt($post->ID)) {
158
-                // admin has chosen "excerpt (short desc)"
159
-                // for the "Event Espresso - Events > Templates > Display Description" option
160
-                // AND an excerpt actually exists
161
-                the_excerpt();
162
-            } else {
163
-                // admin has chosen "excerpt (short desc)"
164
-                // for the "Event Espresso - Events > Templates > Display Description" option
165
-                // but NO excerpt actually exists, so we need to create one
166
-                if (! empty($num_words)) {
167
-                    if (empty($more)) {
168
-                        $more_link_text = esc_html__('(more&hellip;)', 'event_espresso');
169
-                        $more           = ' <a href="' . get_permalink() . '"';
170
-                        $more           .= ' class="more-link"';
171
-                        $more           .= EED_Events_Archive::link_target();
172
-                        $more           .= '>' . $more_link_text . '</a>';
173
-                        $more           = apply_filters('the_content_more_link', $more, $more_link_text);
174
-                    }
175
-                    $content = str_replace('NOMORELINK', '', get_the_content('NOMORELINK'));
176
-
177
-                    $content = wp_trim_words($content, $num_words, ' ') . $more;
178
-                } else {
179
-                    $content = get_the_content();
180
-                }
181
-                global $allowedtags;
182
-                // make sure links are allowed
183
-                $allowedtags['a'] = isset($allowedtags['a'])
184
-                    ? $allowedtags['a']
185
-                    : [];
186
-                // as well as target attribute
187
-                $allowedtags['a']['target'] = isset($allowedtags['a']['target'])
188
-                    ? $allowedtags['a']['target']
189
-                    : false;
190
-                // but get previous value so we can reset it
191
-                $prev_value                 = $allowedtags['a']['target'];
192
-                $allowedtags['a']['target'] = true;
193
-                $content                    = wp_kses($content, $allowedtags);
194
-                $content                    = strip_shortcodes($content);
195
-                echo apply_filters('the_content', $content);
196
-                $allowedtags['a']['target'] = $prev_value;
197
-            }
198
-        } else {
199
-            // admin has chosen "none"
200
-            // for the "Event Espresso - Events > Templates > Display Description" option
201
-            echo apply_filters('the_content', '');
202
-        }
203
-        return ob_get_clean();
204
-    }
205
-
206
-
207
-    /**
208
-     *  event_tickets_available
209
-     *
210
-     * @param int $EVT_ID
211
-     * @return     EE_Ticket[]
212
-     * @throws EE_Error
213
-     * @throws ReflectionException
214
-     */
215
-    public static function event_tickets_available($EVT_ID = 0)
216
-    {
217
-        $event                          = EEH_Event_View::get_event($EVT_ID);
218
-        $tickets_available_for_purchase = [];
219
-        if ($event instanceof EE_Event) {
220
-            $datetimes = EEH_Event_View::get_all_date_obj($EVT_ID, false);
221
-            foreach ($datetimes as $datetime) {
222
-                $tickets_available_for_purchase =
223
-                    array_merge($tickets_available_for_purchase, $datetime->ticket_types_available_for_purchase());
224
-            }
225
-        }
226
-        return $tickets_available_for_purchase;
227
-    }
228
-
229
-
230
-    /**
231
-     *    the_event_date
232
-     *
233
-     * @param int  $EVT_ID
234
-     * @param bool $hide_uncategorized
235
-     * @return    string
236
-     * @throws EE_Error
237
-     * @throws ReflectionException
238
-     */
239
-    public static function event_categories($EVT_ID = 0, $hide_uncategorized = true)
240
-    {
241
-        $category_links = [];
242
-        $event          = EEH_Event_View::get_event($EVT_ID);
243
-        if ($event instanceof EE_Event) {
244
-            $event_categories = get_the_terms($event->ID(), 'espresso_event_categories');
245
-            if ($event_categories) {
246
-                // loop thru terms and create links
247
-                foreach ($event_categories as $term) {
248
-                    $url = get_term_link($term, 'espresso_venue_categories');
249
-                    if (
250
-                        ! is_wp_error($url)
251
-                        && (
252
-                            (
253
-                                $hide_uncategorized
254
-                                && strtolower($term->name) != esc_html__('uncategorized', 'event_espresso')
255
-                            )
256
-                            || ! $hide_uncategorized
257
-                        )
258
-                    ) {
259
-                        $category_links[] = '<a href="' . esc_url_raw($url) . '" '
260
-                                            . 'rel="tag" ' . EED_Events_Archive::link_target() . '>'
261
-                                            . esc_html($term->name)
262
-                                            . '</a>';
263
-                    }
264
-                }
265
-            }
266
-        }
267
-        return implode(', ', $category_links);
268
-    }
269
-
270
-
271
-    /**
272
-     *    the_event_date - first date by date order
273
-     *
274
-     * @param string $date_format
275
-     * @param string $time_format
276
-     * @param int    $EVT_ID
277
-     * @return    string
278
-     * @throws EE_Error
279
-     * @throws ReflectionException
280
-     */
281
-    public static function the_event_date($date_format = 'D M jS', $time_format = 'g:i a', $EVT_ID = 0)
282
-    {
283
-        $datetime = EEH_Event_View::get_primary_date_obj($EVT_ID);
284
-        $format   = ! empty($date_format) && ! empty($time_format)
285
-                ? $date_format . ' ' . $time_format
286
-                : $date_format . $time_format;
287
-        return $datetime instanceof EE_Datetime ? $datetime->get_i18n_datetime('DTT_EVT_start', $format) : '';
288
-    }
289
-
290
-
291
-    /**
292
-     *    the_event_end_date - last date by date order
293
-     *
294
-     * @param string $date_format
295
-     * @param string $time_format
296
-     * @param int    $EVT_ID
297
-     * @return    string
298
-     * @throws EE_Error
299
-     * @throws ReflectionException
300
-     */
301
-    public static function the_event_end_date($date_format = 'D M jS', $time_format = 'g:i a', $EVT_ID = 0)
302
-    {
303
-        $datetime = EEH_Event_View::get_last_date_obj($EVT_ID);
304
-        $format   =
305
-            ! empty($date_format) && ! empty($time_format)
306
-                ? $date_format . ' ' . $time_format
307
-                : $date_format
308
-                  . $time_format;
309
-        return $datetime instanceof EE_Datetime ? $datetime->get_i18n_datetime('DTT_EVT_end', $format) : '';
310
-    }
311
-
312
-
313
-    /**
314
-     *    the_earliest_event_date - first date chronologically
315
-     *
316
-     * @param string $date_format
317
-     * @param string $time_format
318
-     * @param int    $EVT_ID
319
-     * @return    string
320
-     * @throws EE_Error
321
-     * @throws ReflectionException
322
-     */
323
-    public static function the_earliest_event_date($date_format = 'D M jS', $time_format = 'g:i a', $EVT_ID = 0)
324
-    {
325
-        $datetime = EEH_Event_View::get_earliest_date_obj($EVT_ID);
326
-        $format   =
327
-            ! empty($date_format) && ! empty($time_format)
328
-                ? $date_format . ' ' . $time_format
329
-                : $date_format
330
-                  . $time_format;
331
-        return $datetime instanceof EE_Datetime ? $datetime->get_i18n_datetime('DTT_EVT_start', $format) : '';
332
-    }
333
-
334
-
335
-    /**
336
-     *    the_latest_event_date - latest date chronologically
337
-     *
338
-     * @param string $date_format
339
-     * @param string $time_format
340
-     * @param int    $EVT_ID
341
-     * @return    string
342
-     * @throws EE_Error
343
-     * @throws ReflectionException
344
-     */
345
-    public static function the_latest_event_date($date_format = 'D M jS', $time_format = 'g:i a', $EVT_ID = 0)
346
-    {
347
-        $datetime = EEH_Event_View::get_latest_date_obj($EVT_ID);
348
-        $format   =
349
-            ! empty($date_format) && ! empty($time_format)
350
-                ? $date_format . ' ' . $time_format
351
-                : $date_format
352
-                  . $time_format;
353
-        return $datetime instanceof EE_Datetime ? $datetime->get_i18n_datetime('DTT_EVT_end', $format) : '';
354
-    }
355
-
356
-
357
-    /**
358
-     *    event_date_as_calendar_page
359
-     *
360
-     * @param int $EVT_ID
361
-     * @return    void
362
-     * @throws EE_Error
363
-     * @throws ReflectionException
364
-     */
365
-    public static function event_date_as_calendar_page($EVT_ID = 0)
366
-    {
367
-        $datetime = EEH_Event_View::get_primary_date_obj($EVT_ID);
368
-        if ($datetime instanceof EE_Datetime) {
369
-            ?>
12
+	/**
13
+	 * @var EE_Event $_event
14
+	 */
15
+	private static $_event = null;
16
+
17
+
18
+	/**
19
+	 * get_event
20
+	 * attempts to retrieve an EE_Event object any way it can
21
+	 *
22
+	 * @param int|WP_Post $EVT_ID
23
+	 * @return EE_Event|null
24
+	 * @throws EE_Error
25
+	 * @throws ReflectionException
26
+	 */
27
+	public static function get_event($EVT_ID = 0)
28
+	{
29
+		// international newspaper?
30
+		global $post;
31
+		$EVT_ID = $EVT_ID instanceof WP_Post && $EVT_ID->post_type === 'espresso_events'
32
+			? $EVT_ID->ID
33
+			: absint($EVT_ID);
34
+		// do we already have the Event  you are looking for?
35
+		if (EEH_Event_View::$_event instanceof EE_Event && $EVT_ID && EEH_Event_View::$_event->ID() === $EVT_ID) {
36
+			return EEH_Event_View::$_event;
37
+		}
38
+		// reset property so that the new event is cached.
39
+		EEH_Event_View::$_event = null;
40
+		if (! $EVT_ID && $post instanceof EE_Event) {
41
+			EEH_Event_View::$_event = $post;
42
+			return EEH_Event_View::$_event;
43
+		}
44
+		// if the post type is for an event and it has a cached event and we don't have a different incoming $EVT_ID
45
+		// then let's just use that cached event on the $post object.
46
+		if (
47
+			$post instanceof WP_Post
48
+			&& $post->post_type === 'espresso_events'
49
+			&& isset($post->EE_Event)
50
+			&& (
51
+				$EVT_ID === 0
52
+				|| $EVT_ID === $post->ID
53
+			)
54
+		) {
55
+			EEH_Event_View::$_event = $post->EE_Event;
56
+			return EEH_Event_View::$_event;
57
+		}
58
+		// 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.
59
+		if (! EEH_Event_View::$_event instanceof EE_Event && $EVT_ID) {
60
+			EEH_Event_View::$_event = EEM_Event::instance()->get_one_by_ID($EVT_ID);
61
+		}
62
+		return EEH_Event_View::$_event;
63
+	}
64
+
65
+
66
+	/**
67
+	 *    display_ticket_selector
68
+	 *
69
+	 * @param int $EVT_ID
70
+	 * @return    boolean
71
+	 * @throws EE_Error
72
+	 * @throws EE_Error
73
+	 * @throws ReflectionException
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();
79
+	}
80
+
81
+
82
+	/**
83
+	 *    event_status
84
+	 *
85
+	 * @param int $EVT_ID
86
+	 * @return    string
87
+	 * @throws EE_Error
88
+	 * @throws EE_Error
89
+	 * @throws ReflectionException
90
+	 */
91
+	public static function event_status($EVT_ID = 0)
92
+	{
93
+		$event = EEH_Event_View::get_event($EVT_ID);
94
+		return $event instanceof EE_Event ? $event->pretty_active_status(false) : '';
95
+	}
96
+
97
+
98
+	/**
99
+	 *  event_active_status
100
+	 *
101
+	 * @param int $EVT_ID
102
+	 * @return     string
103
+	 * @throws EE_Error
104
+	 * @throws EE_Error
105
+	 * @throws ReflectionException
106
+	 */
107
+	public static function event_active_status($EVT_ID = 0, $echo = true)
108
+	{
109
+		$event = EEH_Event_View::get_event($EVT_ID);
110
+		return $event instanceof EE_Event ? $event->pretty_active_status($echo) : 'inactive';
111
+	}
112
+
113
+
114
+	/**
115
+	 *  event_has_content_or_excerpt
116
+	 *
117
+	 * @param int $EVT_ID
118
+	 * @return     bool
119
+	 * @throws EE_Error
120
+	 * @throws EE_Error
121
+	 * @throws ReflectionException
122
+	 */
123
+	public static function event_has_content_or_excerpt($EVT_ID = 0)
124
+	{
125
+		$event                  = EEH_Event_View::get_event($EVT_ID);
126
+		$has_content_or_excerpt = false;
127
+		if ($event instanceof EE_Event) {
128
+			$has_content_or_excerpt = $event->description() != '' || $event->short_description(null, null, true) != '';
129
+		}
130
+		if (
131
+			is_archive()
132
+			&& ! (espresso_display_full_description_in_event_list()
133
+				  || espresso_display_excerpt_in_event_list())
134
+		) {
135
+			$has_content_or_excerpt = false;
136
+		}
137
+		return $has_content_or_excerpt;
138
+	}
139
+
140
+
141
+	/**
142
+	 *    event_active_status
143
+	 *
144
+	 * @param null $num_words
145
+	 * @param null $more
146
+	 * @return    string
147
+	 */
148
+	public static function event_content_or_excerpt($num_words = null, $more = null)
149
+	{
150
+		global $post;
151
+		ob_start();
152
+		if ((is_single()) || (is_archive() && espresso_display_full_description_in_event_list())) {
153
+			// admin has chosen "full description"
154
+			// for the "Event Espresso - Events > Templates > Display Description" option
155
+			the_content();
156
+		} elseif ((is_archive() && espresso_display_excerpt_in_event_list())) {
157
+			if (has_excerpt($post->ID)) {
158
+				// admin has chosen "excerpt (short desc)"
159
+				// for the "Event Espresso - Events > Templates > Display Description" option
160
+				// AND an excerpt actually exists
161
+				the_excerpt();
162
+			} else {
163
+				// admin has chosen "excerpt (short desc)"
164
+				// for the "Event Espresso - Events > Templates > Display Description" option
165
+				// but NO excerpt actually exists, so we need to create one
166
+				if (! empty($num_words)) {
167
+					if (empty($more)) {
168
+						$more_link_text = esc_html__('(more&hellip;)', 'event_espresso');
169
+						$more           = ' <a href="' . get_permalink() . '"';
170
+						$more           .= ' class="more-link"';
171
+						$more           .= EED_Events_Archive::link_target();
172
+						$more           .= '>' . $more_link_text . '</a>';
173
+						$more           = apply_filters('the_content_more_link', $more, $more_link_text);
174
+					}
175
+					$content = str_replace('NOMORELINK', '', get_the_content('NOMORELINK'));
176
+
177
+					$content = wp_trim_words($content, $num_words, ' ') . $more;
178
+				} else {
179
+					$content = get_the_content();
180
+				}
181
+				global $allowedtags;
182
+				// make sure links are allowed
183
+				$allowedtags['a'] = isset($allowedtags['a'])
184
+					? $allowedtags['a']
185
+					: [];
186
+				// as well as target attribute
187
+				$allowedtags['a']['target'] = isset($allowedtags['a']['target'])
188
+					? $allowedtags['a']['target']
189
+					: false;
190
+				// but get previous value so we can reset it
191
+				$prev_value                 = $allowedtags['a']['target'];
192
+				$allowedtags['a']['target'] = true;
193
+				$content                    = wp_kses($content, $allowedtags);
194
+				$content                    = strip_shortcodes($content);
195
+				echo apply_filters('the_content', $content);
196
+				$allowedtags['a']['target'] = $prev_value;
197
+			}
198
+		} else {
199
+			// admin has chosen "none"
200
+			// for the "Event Espresso - Events > Templates > Display Description" option
201
+			echo apply_filters('the_content', '');
202
+		}
203
+		return ob_get_clean();
204
+	}
205
+
206
+
207
+	/**
208
+	 *  event_tickets_available
209
+	 *
210
+	 * @param int $EVT_ID
211
+	 * @return     EE_Ticket[]
212
+	 * @throws EE_Error
213
+	 * @throws ReflectionException
214
+	 */
215
+	public static function event_tickets_available($EVT_ID = 0)
216
+	{
217
+		$event                          = EEH_Event_View::get_event($EVT_ID);
218
+		$tickets_available_for_purchase = [];
219
+		if ($event instanceof EE_Event) {
220
+			$datetimes = EEH_Event_View::get_all_date_obj($EVT_ID, false);
221
+			foreach ($datetimes as $datetime) {
222
+				$tickets_available_for_purchase =
223
+					array_merge($tickets_available_for_purchase, $datetime->ticket_types_available_for_purchase());
224
+			}
225
+		}
226
+		return $tickets_available_for_purchase;
227
+	}
228
+
229
+
230
+	/**
231
+	 *    the_event_date
232
+	 *
233
+	 * @param int  $EVT_ID
234
+	 * @param bool $hide_uncategorized
235
+	 * @return    string
236
+	 * @throws EE_Error
237
+	 * @throws ReflectionException
238
+	 */
239
+	public static function event_categories($EVT_ID = 0, $hide_uncategorized = true)
240
+	{
241
+		$category_links = [];
242
+		$event          = EEH_Event_View::get_event($EVT_ID);
243
+		if ($event instanceof EE_Event) {
244
+			$event_categories = get_the_terms($event->ID(), 'espresso_event_categories');
245
+			if ($event_categories) {
246
+				// loop thru terms and create links
247
+				foreach ($event_categories as $term) {
248
+					$url = get_term_link($term, 'espresso_venue_categories');
249
+					if (
250
+						! is_wp_error($url)
251
+						&& (
252
+							(
253
+								$hide_uncategorized
254
+								&& strtolower($term->name) != esc_html__('uncategorized', 'event_espresso')
255
+							)
256
+							|| ! $hide_uncategorized
257
+						)
258
+					) {
259
+						$category_links[] = '<a href="' . esc_url_raw($url) . '" '
260
+											. 'rel="tag" ' . EED_Events_Archive::link_target() . '>'
261
+											. esc_html($term->name)
262
+											. '</a>';
263
+					}
264
+				}
265
+			}
266
+		}
267
+		return implode(', ', $category_links);
268
+	}
269
+
270
+
271
+	/**
272
+	 *    the_event_date - first date by date order
273
+	 *
274
+	 * @param string $date_format
275
+	 * @param string $time_format
276
+	 * @param int    $EVT_ID
277
+	 * @return    string
278
+	 * @throws EE_Error
279
+	 * @throws ReflectionException
280
+	 */
281
+	public static function the_event_date($date_format = 'D M jS', $time_format = 'g:i a', $EVT_ID = 0)
282
+	{
283
+		$datetime = EEH_Event_View::get_primary_date_obj($EVT_ID);
284
+		$format   = ! empty($date_format) && ! empty($time_format)
285
+				? $date_format . ' ' . $time_format
286
+				: $date_format . $time_format;
287
+		return $datetime instanceof EE_Datetime ? $datetime->get_i18n_datetime('DTT_EVT_start', $format) : '';
288
+	}
289
+
290
+
291
+	/**
292
+	 *    the_event_end_date - last date by date order
293
+	 *
294
+	 * @param string $date_format
295
+	 * @param string $time_format
296
+	 * @param int    $EVT_ID
297
+	 * @return    string
298
+	 * @throws EE_Error
299
+	 * @throws ReflectionException
300
+	 */
301
+	public static function the_event_end_date($date_format = 'D M jS', $time_format = 'g:i a', $EVT_ID = 0)
302
+	{
303
+		$datetime = EEH_Event_View::get_last_date_obj($EVT_ID);
304
+		$format   =
305
+			! empty($date_format) && ! empty($time_format)
306
+				? $date_format . ' ' . $time_format
307
+				: $date_format
308
+				  . $time_format;
309
+		return $datetime instanceof EE_Datetime ? $datetime->get_i18n_datetime('DTT_EVT_end', $format) : '';
310
+	}
311
+
312
+
313
+	/**
314
+	 *    the_earliest_event_date - first date chronologically
315
+	 *
316
+	 * @param string $date_format
317
+	 * @param string $time_format
318
+	 * @param int    $EVT_ID
319
+	 * @return    string
320
+	 * @throws EE_Error
321
+	 * @throws ReflectionException
322
+	 */
323
+	public static function the_earliest_event_date($date_format = 'D M jS', $time_format = 'g:i a', $EVT_ID = 0)
324
+	{
325
+		$datetime = EEH_Event_View::get_earliest_date_obj($EVT_ID);
326
+		$format   =
327
+			! empty($date_format) && ! empty($time_format)
328
+				? $date_format . ' ' . $time_format
329
+				: $date_format
330
+				  . $time_format;
331
+		return $datetime instanceof EE_Datetime ? $datetime->get_i18n_datetime('DTT_EVT_start', $format) : '';
332
+	}
333
+
334
+
335
+	/**
336
+	 *    the_latest_event_date - latest date chronologically
337
+	 *
338
+	 * @param string $date_format
339
+	 * @param string $time_format
340
+	 * @param int    $EVT_ID
341
+	 * @return    string
342
+	 * @throws EE_Error
343
+	 * @throws ReflectionException
344
+	 */
345
+	public static function the_latest_event_date($date_format = 'D M jS', $time_format = 'g:i a', $EVT_ID = 0)
346
+	{
347
+		$datetime = EEH_Event_View::get_latest_date_obj($EVT_ID);
348
+		$format   =
349
+			! empty($date_format) && ! empty($time_format)
350
+				? $date_format . ' ' . $time_format
351
+				: $date_format
352
+				  . $time_format;
353
+		return $datetime instanceof EE_Datetime ? $datetime->get_i18n_datetime('DTT_EVT_end', $format) : '';
354
+	}
355
+
356
+
357
+	/**
358
+	 *    event_date_as_calendar_page
359
+	 *
360
+	 * @param int $EVT_ID
361
+	 * @return    void
362
+	 * @throws EE_Error
363
+	 * @throws ReflectionException
364
+	 */
365
+	public static function event_date_as_calendar_page($EVT_ID = 0)
366
+	{
367
+		$datetime = EEH_Event_View::get_primary_date_obj($EVT_ID);
368
+		if ($datetime instanceof EE_Datetime) {
369
+			?>
370 370
             <div class="event-date-calendar-page-dv">
371 371
                 <div class="event-date-calendar-page-month-dv">
372 372
                     <?php echo esc_html($datetime->get_i18n_datetime('DTT_EVT_start', 'M')); ?>
@@ -376,260 +376,260 @@  discard block
 block discarded – undo
376 376
                 </div>
377 377
             </div>
378 378
             <?php
379
-        }
380
-    }
381
-
382
-
383
-    /**
384
-     *    get_primary_date_obj - orders date by DTT_order
385
-     *
386
-     * @param int $EVT_ID
387
-     * @return EE_Datetime
388
-     * @throws EE_Error
389
-     * @throws ReflectionException
390
-     */
391
-    public static function get_primary_date_obj($EVT_ID = 0)
392
-    {
393
-        $event = EEH_Event_View::get_event($EVT_ID);
394
-        if ($event instanceof EE_Event) {
395
-            $datetimes = $event->get_many_related(
396
-                'Datetime',
397
-                [
398
-                    'limit'    => 1,
399
-                    'order_by' => ['DTT_order' => 'ASC'],
400
-                ]
401
-            );
402
-            return reset($datetimes);
403
-        }
404
-        return null;
405
-    }
406
-
407
-
408
-    /**
409
-     *    get_last_date_obj - orders date by DTT_order
410
-     *
411
-     * @param int $EVT_ID
412
-     * @return EE_Datetime
413
-     * @throws EE_Error
414
-     * @throws ReflectionException
415
-     */
416
-    public static function get_last_date_obj($EVT_ID = 0)
417
-    {
418
-        $event = EEH_Event_View::get_event($EVT_ID);
419
-        if ($event instanceof EE_Event) {
420
-            $datetimes = $event->get_many_related(
421
-                'Datetime',
422
-                [
423
-                    'limit'    => 1,
424
-                    'order_by' => ['DTT_order' => 'DESC'],
425
-                ]
426
-            );
427
-            return end($datetimes);
428
-        }
429
-        return null;
430
-    }
431
-
432
-
433
-    /**
434
-     *    get_earliest_date_obj - orders date chronologically
435
-     *
436
-     * @param int $EVT_ID
437
-     * @return EE_Datetime
438
-     * @throws EE_Error
439
-     * @throws ReflectionException
440
-     */
441
-    public static function get_earliest_date_obj($EVT_ID = 0)
442
-    {
443
-        $event = EEH_Event_View::get_event($EVT_ID);
444
-        if ($event instanceof EE_Event) {
445
-            $datetimes = $event->get_many_related(
446
-                'Datetime',
447
-                [
448
-                    'limit'    => 1,
449
-                    'order_by' => ['DTT_EVT_start' => 'ASC'],
450
-                ]
451
-            );
452
-            return reset($datetimes);
453
-        }
454
-        return null;
455
-    }
456
-
457
-
458
-    /**
459
-     *    get_latest_date_obj - orders date chronologically
460
-     *
461
-     * @param int $EVT_ID
462
-     * @return EE_Datetime
463
-     * @throws EE_Error
464
-     * @throws ReflectionException
465
-     */
466
-    public static function get_latest_date_obj($EVT_ID = 0)
467
-    {
468
-        $event = EEH_Event_View::get_event($EVT_ID);
469
-        if ($event instanceof EE_Event) {
470
-            $datetimes = $event->get_many_related(
471
-                'Datetime',
472
-                [
473
-                    'limit'    => 1,
474
-                    'order_by' => ['DTT_EVT_start' => 'DESC'],
475
-                ]
476
-            );
477
-            return end($datetimes);
478
-        }
479
-        return null;
480
-    }
481
-
482
-
483
-    /**
484
-     *    get_next_upcoming_date_obj - return the next upcoming datetime
485
-     *
486
-     * @param int $EVT_ID
487
-     * @return    EE_Datetime|null
488
-     * @throws EE_Error
489
-     * @throws EE_Error
490
-     */
491
-    public static function get_next_upcoming_date_obj($EVT_ID = 0)
492
-    {
493
-        $datetime = EEM_Datetime::instance()->get_one(
494
-            [
495
-                [
496
-                    'Event.EVT_ID'  => $EVT_ID,
497
-                    'DTT_EVT_start' => ['>=', current_time('mysql', true)],
498
-                ],
499
-                'order_by' => ['DTT_EVT_start' => 'asc'],
500
-            ]
501
-        );
502
-        return $datetime instanceof EE_Datetime ? $datetime : null;
503
-    }
504
-
505
-
506
-    /**
507
-     *    get_all_date_obj
508
-     *
509
-     * @param int  $EVT_ID
510
-     * @param null $include_expired
511
-     * @param bool $include_deleted
512
-     * @param null $limit
513
-     * @return EE_Datetime[]
514
-     * @throws EE_Error
515
-     * @throws EE_Error
516
-     * @throws ReflectionException
517
-     */
518
-    public static function get_all_date_obj(
519
-        $EVT_ID = 0,
520
-        $include_expired = null,
521
-        $include_deleted = false,
522
-        $limit = null
523
-    ) {
524
-        $event = EEH_Event_View::get_event($EVT_ID);
525
-        if ($include_expired === null) {
526
-            if ($event instanceof EE_Event && $event->is_expired()) {
527
-                $include_expired = true;
528
-            } else {
529
-                $include_expired = false;
530
-            }
531
-        }
532
-
533
-        if ($event instanceof EE_Event) {
534
-            return $event->datetimes_ordered($include_expired, $include_deleted, $limit);
535
-        }
536
-        return [];
537
-    }
538
-
539
-
540
-    /**
541
-     *    event_link_url
542
-     *
543
-     * @param int $EVT_ID
544
-     * @return string
545
-     * @throws EE_Error
546
-     * @throws ReflectionException
547
-     */
548
-    public static function event_link_url($EVT_ID = 0)
549
-    {
550
-        $event = EEH_Event_View::get_event($EVT_ID);
551
-        if ($event instanceof EE_Event) {
552
-            $url = $event->external_url() !== null && $event->external_url() !== ''
553
-                ? $event->external_url()
554
-                : get_permalink($event->ID());
555
-            $url = preg_match("~^(?:f|ht)tps?://~i", $url) ? $url : 'https://' . $url;
556
-            return esc_url_raw($url);
557
-        }
558
-        return '';
559
-    }
560
-
561
-
562
-    /**
563
-     *    event_phone
564
-     *
565
-     * @param int $EVT_ID
566
-     * @return    string
567
-     * @throws EE_Error
568
-     * @throws EE_Error
569
-     * @throws ReflectionException
570
-     */
571
-    public static function event_phone($EVT_ID = 0)
572
-    {
573
-        $event = EEH_Event_View::get_event($EVT_ID);
574
-        if ($event instanceof EE_Event) {
575
-            return EEH_Schema::telephone($event->phone());
576
-        }
577
-        return null;
578
-    }
579
-
580
-
581
-    /**
582
-     *    edit_event_link
583
-     *
584
-     * @param int    $EVT_ID
585
-     * @param string $link
586
-     * @param string $before
587
-     * @param string $after
588
-     * @return    string
589
-     * @throws EE_Error
590
-     * @throws ReflectionException
591
-     */
592
-    public static function edit_event_link($EVT_ID = 0, $link = '', $before = '', $after = '')
593
-    {
594
-        $event = EEH_Event_View::get_event($EVT_ID);
595
-        if ($event instanceof EE_Event) {
596
-            // can the user edit this post ?
597
-            if (current_user_can('edit_post', $event->ID())) {
598
-                // set link text
599
-                $link_text = ! empty($link) ? $link : esc_html__('edit this event', 'event_espresso');
600
-                // generate nonce
601
-                $nonce = wp_create_nonce('edit_nonce');
602
-                // generate url to event editor for this event
603
-                $url =
604
-                    add_query_arg(
605
-                        [
606
-                            'page'       => 'espresso_events',
607
-                            'action'     => 'edit',
608
-                            'post'       => $event->ID(),
609
-                            'edit_nonce' => $nonce,
610
-                        ],
611
-                        admin_url()
612
-                    );
613
-                // get edit CPT text
614
-                $post_type_obj = get_post_type_object('espresso_events');
615
-                // build final link html
616
-                $link = '<a class="post-edit-link" href="' . $url . '" ';
617
-                $link .= ' title="' . esc_attr($post_type_obj->labels->edit_item) . '"';
618
-                $link .= EED_Events_Archive::link_target();
619
-                $link .= '>' . $link_text . '</a>';
620
-                // put it all together
621
-                return $before . apply_filters('edit_post_link', $link, $event->ID()) . $after;
622
-            }
623
-        }
624
-        return '';
625
-    }
626
-
627
-
628
-    /**
629
-     * @return string
630
-     */
631
-    public static function event_archive_url()
632
-    {
633
-        return get_post_type_archive_link('espresso_events');
634
-    }
379
+		}
380
+	}
381
+
382
+
383
+	/**
384
+	 *    get_primary_date_obj - orders date by DTT_order
385
+	 *
386
+	 * @param int $EVT_ID
387
+	 * @return EE_Datetime
388
+	 * @throws EE_Error
389
+	 * @throws ReflectionException
390
+	 */
391
+	public static function get_primary_date_obj($EVT_ID = 0)
392
+	{
393
+		$event = EEH_Event_View::get_event($EVT_ID);
394
+		if ($event instanceof EE_Event) {
395
+			$datetimes = $event->get_many_related(
396
+				'Datetime',
397
+				[
398
+					'limit'    => 1,
399
+					'order_by' => ['DTT_order' => 'ASC'],
400
+				]
401
+			);
402
+			return reset($datetimes);
403
+		}
404
+		return null;
405
+	}
406
+
407
+
408
+	/**
409
+	 *    get_last_date_obj - orders date by DTT_order
410
+	 *
411
+	 * @param int $EVT_ID
412
+	 * @return EE_Datetime
413
+	 * @throws EE_Error
414
+	 * @throws ReflectionException
415
+	 */
416
+	public static function get_last_date_obj($EVT_ID = 0)
417
+	{
418
+		$event = EEH_Event_View::get_event($EVT_ID);
419
+		if ($event instanceof EE_Event) {
420
+			$datetimes = $event->get_many_related(
421
+				'Datetime',
422
+				[
423
+					'limit'    => 1,
424
+					'order_by' => ['DTT_order' => 'DESC'],
425
+				]
426
+			);
427
+			return end($datetimes);
428
+		}
429
+		return null;
430
+	}
431
+
432
+
433
+	/**
434
+	 *    get_earliest_date_obj - orders date chronologically
435
+	 *
436
+	 * @param int $EVT_ID
437
+	 * @return EE_Datetime
438
+	 * @throws EE_Error
439
+	 * @throws ReflectionException
440
+	 */
441
+	public static function get_earliest_date_obj($EVT_ID = 0)
442
+	{
443
+		$event = EEH_Event_View::get_event($EVT_ID);
444
+		if ($event instanceof EE_Event) {
445
+			$datetimes = $event->get_many_related(
446
+				'Datetime',
447
+				[
448
+					'limit'    => 1,
449
+					'order_by' => ['DTT_EVT_start' => 'ASC'],
450
+				]
451
+			);
452
+			return reset($datetimes);
453
+		}
454
+		return null;
455
+	}
456
+
457
+
458
+	/**
459
+	 *    get_latest_date_obj - orders date chronologically
460
+	 *
461
+	 * @param int $EVT_ID
462
+	 * @return EE_Datetime
463
+	 * @throws EE_Error
464
+	 * @throws ReflectionException
465
+	 */
466
+	public static function get_latest_date_obj($EVT_ID = 0)
467
+	{
468
+		$event = EEH_Event_View::get_event($EVT_ID);
469
+		if ($event instanceof EE_Event) {
470
+			$datetimes = $event->get_many_related(
471
+				'Datetime',
472
+				[
473
+					'limit'    => 1,
474
+					'order_by' => ['DTT_EVT_start' => 'DESC'],
475
+				]
476
+			);
477
+			return end($datetimes);
478
+		}
479
+		return null;
480
+	}
481
+
482
+
483
+	/**
484
+	 *    get_next_upcoming_date_obj - return the next upcoming datetime
485
+	 *
486
+	 * @param int $EVT_ID
487
+	 * @return    EE_Datetime|null
488
+	 * @throws EE_Error
489
+	 * @throws EE_Error
490
+	 */
491
+	public static function get_next_upcoming_date_obj($EVT_ID = 0)
492
+	{
493
+		$datetime = EEM_Datetime::instance()->get_one(
494
+			[
495
+				[
496
+					'Event.EVT_ID'  => $EVT_ID,
497
+					'DTT_EVT_start' => ['>=', current_time('mysql', true)],
498
+				],
499
+				'order_by' => ['DTT_EVT_start' => 'asc'],
500
+			]
501
+		);
502
+		return $datetime instanceof EE_Datetime ? $datetime : null;
503
+	}
504
+
505
+
506
+	/**
507
+	 *    get_all_date_obj
508
+	 *
509
+	 * @param int  $EVT_ID
510
+	 * @param null $include_expired
511
+	 * @param bool $include_deleted
512
+	 * @param null $limit
513
+	 * @return EE_Datetime[]
514
+	 * @throws EE_Error
515
+	 * @throws EE_Error
516
+	 * @throws ReflectionException
517
+	 */
518
+	public static function get_all_date_obj(
519
+		$EVT_ID = 0,
520
+		$include_expired = null,
521
+		$include_deleted = false,
522
+		$limit = null
523
+	) {
524
+		$event = EEH_Event_View::get_event($EVT_ID);
525
+		if ($include_expired === null) {
526
+			if ($event instanceof EE_Event && $event->is_expired()) {
527
+				$include_expired = true;
528
+			} else {
529
+				$include_expired = false;
530
+			}
531
+		}
532
+
533
+		if ($event instanceof EE_Event) {
534
+			return $event->datetimes_ordered($include_expired, $include_deleted, $limit);
535
+		}
536
+		return [];
537
+	}
538
+
539
+
540
+	/**
541
+	 *    event_link_url
542
+	 *
543
+	 * @param int $EVT_ID
544
+	 * @return string
545
+	 * @throws EE_Error
546
+	 * @throws ReflectionException
547
+	 */
548
+	public static function event_link_url($EVT_ID = 0)
549
+	{
550
+		$event = EEH_Event_View::get_event($EVT_ID);
551
+		if ($event instanceof EE_Event) {
552
+			$url = $event->external_url() !== null && $event->external_url() !== ''
553
+				? $event->external_url()
554
+				: get_permalink($event->ID());
555
+			$url = preg_match("~^(?:f|ht)tps?://~i", $url) ? $url : 'https://' . $url;
556
+			return esc_url_raw($url);
557
+		}
558
+		return '';
559
+	}
560
+
561
+
562
+	/**
563
+	 *    event_phone
564
+	 *
565
+	 * @param int $EVT_ID
566
+	 * @return    string
567
+	 * @throws EE_Error
568
+	 * @throws EE_Error
569
+	 * @throws ReflectionException
570
+	 */
571
+	public static function event_phone($EVT_ID = 0)
572
+	{
573
+		$event = EEH_Event_View::get_event($EVT_ID);
574
+		if ($event instanceof EE_Event) {
575
+			return EEH_Schema::telephone($event->phone());
576
+		}
577
+		return null;
578
+	}
579
+
580
+
581
+	/**
582
+	 *    edit_event_link
583
+	 *
584
+	 * @param int    $EVT_ID
585
+	 * @param string $link
586
+	 * @param string $before
587
+	 * @param string $after
588
+	 * @return    string
589
+	 * @throws EE_Error
590
+	 * @throws ReflectionException
591
+	 */
592
+	public static function edit_event_link($EVT_ID = 0, $link = '', $before = '', $after = '')
593
+	{
594
+		$event = EEH_Event_View::get_event($EVT_ID);
595
+		if ($event instanceof EE_Event) {
596
+			// can the user edit this post ?
597
+			if (current_user_can('edit_post', $event->ID())) {
598
+				// set link text
599
+				$link_text = ! empty($link) ? $link : esc_html__('edit this event', 'event_espresso');
600
+				// generate nonce
601
+				$nonce = wp_create_nonce('edit_nonce');
602
+				// generate url to event editor for this event
603
+				$url =
604
+					add_query_arg(
605
+						[
606
+							'page'       => 'espresso_events',
607
+							'action'     => 'edit',
608
+							'post'       => $event->ID(),
609
+							'edit_nonce' => $nonce,
610
+						],
611
+						admin_url()
612
+					);
613
+				// get edit CPT text
614
+				$post_type_obj = get_post_type_object('espresso_events');
615
+				// build final link html
616
+				$link = '<a class="post-edit-link" href="' . $url . '" ';
617
+				$link .= ' title="' . esc_attr($post_type_obj->labels->edit_item) . '"';
618
+				$link .= EED_Events_Archive::link_target();
619
+				$link .= '>' . $link_text . '</a>';
620
+				// put it all together
621
+				return $before . apply_filters('edit_post_link', $link, $event->ID()) . $after;
622
+			}
623
+		}
624
+		return '';
625
+	}
626
+
627
+
628
+	/**
629
+	 * @return string
630
+	 */
631
+	public static function event_archive_url()
632
+	{
633
+		return get_post_type_archive_link('espresso_events');
634
+	}
635 635
 }
Please login to merge, or discard this patch.
core/helpers/EEH_Maps.helper.php 2 patches
Spacing   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -51,7 +51,7 @@  discard block
 block discarded – undo
51 51
             ? esc_url_raw($ee_gmaps_opts['ee_static_url'])
52 52
             : false;
53 53
 
54
-        if (! empty($ee_gmaps_opts['ee_map_align'])) {
54
+        if ( ! empty($ee_gmaps_opts['ee_map_align'])) {
55 55
             switch ($ee_gmaps_opts['ee_map_align']) {
56 56
                 case "left":
57 57
                     $map_align = 'ee-gmap-align-left left';
@@ -75,18 +75,18 @@  discard block
 block discarded – undo
75 75
         // if so display a Google static iframe map else run V3 api
76 76
         if ($static_url) {
77 77
             $html = '
78
-            <div class="ee-gmap-iframewrap ee-gmap-wrapper ' . $map_align . '">
79
-                <iframe src="' . $static_url . '&output=embed"
80
-                        style="width: ' . $ee_map_width . 'px; height: ' . $ee_map_height . 'px;"
78
+            <div class="ee-gmap-iframewrap ee-gmap-wrapper ' . $map_align.'">
79
+                <iframe src="' . $static_url.'&output=embed"
80
+                        style="width: ' . $ee_map_width.'px; height: '.$ee_map_height.'px;"
81 81
                         frameborder="0" 
82 82
                         scrolling="no"
83 83
                     >
84 84
                 </iframe>
85
-                <a href="' . $static_url . '">' . esc_html__('View Large map', 'event_espresso') . '</a>
85
+                <a href="' . $static_url.'">'.esc_html__('View Large map', 'event_espresso').'</a>
86 86
             </div>
87 87
 ';
88 88
         } else {
89
-            EEH_Maps::$gmap_vars[ $ee_gmaps_opts['map_ID'] ] = [
89
+            EEH_Maps::$gmap_vars[$ee_gmaps_opts['map_ID']] = [
90 90
                 'map_ID'              => $ee_gmaps_opts['map_ID'],
91 91
                 'ee_map_zoom'         => $ee_map_zoom,
92 92
                 'ee_map_nav_display'  => $ee_map_nav_display,
@@ -95,12 +95,12 @@  discard block
 block discarded – undo
95 95
                 'location'            => $ee_gmaps_opts['location'],
96 96
             ];
97 97
 
98
-            $style = 'width: ' . $ee_map_width . 'px; height: ' . $ee_map_height . 'px;';
98
+            $style = 'width: '.$ee_map_width.'px; height: '.$ee_map_height.'px;';
99 99
             $html  = '
100
-            <div class="ee-gmap-wrapper ' . esc_attr($map_align) . '">
100
+            <div class="ee-gmap-wrapper ' . esc_attr($map_align).'">
101 101
                 <div class="ee-gmap" 
102
-                     id="map_canvas_' . esc_attr($ee_gmaps_opts['map_ID']) . '"
103
-                     style="' . esc_attr($style) . '"
102
+                     id="map_canvas_' . esc_attr($ee_gmaps_opts['map_ID']).'"
103
+                     style="' . esc_attr($style).'"
104 104
                  ></div>
105 105
             </div>';
106 106
 
@@ -144,7 +144,7 @@  discard block
 block discarded – undo
144 144
         );
145 145
         wp_register_script(
146 146
             'ee_gmap',
147
-            plugin_dir_url(__FILE__) . 'assets/ee_gmap.js',
147
+            plugin_dir_url(__FILE__).'assets/ee_gmap.js',
148 148
             ['gmap_api'],
149 149
             '1.0',
150 150
             true
@@ -180,12 +180,12 @@  discard block
 block discarded – undo
180 180
         $map_image_class = isset($map_image_class) ? $map_image_class : 'ee_google_map_view';
181 181
 
182 182
         $address_string = ($address != '' ? $address : '')
183
-                          . ($city != '' ? ',' . $city : '')
184
-                          . ($state != '' ? ',' . $state : '')
185
-                          . ($zip != '' ? ',' . $zip : '')
186
-                          . ($country != '' ? ',' . $country : '');
183
+                          . ($city != '' ? ','.$city : '')
184
+                          . ($state != '' ? ','.$state : '')
185
+                          . ($zip != '' ? ','.$zip : '')
186
+                          . ($country != '' ? ','.$country : '');
187 187
 
188
-        $google_map = htmlentities2('https://maps.google.com/maps?q=' . urlencode($address_string));
188
+        $google_map = htmlentities2('https://maps.google.com/maps?q='.urlencode($address_string));
189 189
 
190 190
         switch ($type) {
191 191
             case 'text':
@@ -208,31 +208,31 @@  discard block
 block discarded – undo
208 208
 
209 209
                 return '
210 210
                 <a class="a_map_image_link" 
211
-                   href="' . esc_url_raw($google_map) . '" 
211
+                   href="' . esc_url_raw($google_map).'" 
212 212
                    target="_blank" 
213 213
                    rel="noopener noreferrer"
214 214
                 >
215
-                    <img alt="' . esc_html__('Map and Directions', 'event_espresso') . '"
215
+                    <img alt="' . esc_html__('Map and Directions', 'event_espresso').'"
216 216
                          class="map_image_link" 
217
-                         id="venue_map_' . $id . '" ' . $map_image_class . ' 
217
+                         id="venue_map_' . $id.'" '.$map_image_class.' 
218 218
                          src="'
219 219
                        . htmlentities2(
220 220
                            $scheme
221 221
                            . 'maps.googleapis.com/maps/api/staticmap?center='
222 222
                            . urlencode($address_string)
223 223
                            . '&amp;zoom=14&amp;size='
224
-                           . $map_w . 'x' . $map_h
224
+                           . $map_w.'x'.$map_h
225 225
                            . '&amp;markers=color:green|label:|'
226 226
                            . urlencode($address_string)
227 227
                            . '&amp;sensor=false&amp;key='
228 228
                            . $api_key
229
-                       ) . '"
229
+                       ).'"
230 230
                      />
231 231
                  </a>';
232 232
         }
233 233
 
234 234
         return $type === 'url_only'
235 235
             ? $text
236
-            : '<a href="' . esc_url_raw($google_map) . '" target="_blank" rel="noopener noreferrer">' . $text . '</a>';
236
+            : '<a href="'.esc_url_raw($google_map).'" target="_blank" rel="noopener noreferrer">'.$text.'</a>';
237 237
     }
238 238
 }
Please login to merge, or discard this patch.
Indentation   +194 added lines, -194 removed lines patch added patch discarded remove patch
@@ -11,69 +11,69 @@  discard block
 block discarded – undo
11 11
  */
12 12
 class EEH_Maps
13 13
 {
14
-    // array of map settings
15
-    public static $gmap_vars = [];
16
-
17
-
18
-    /**
19
-     * google_map - creates a Google Map Link
20
-     *
21
-     * @param array $ee_gmaps_opts array of attributes required for the map link generation
22
-     * @return string (link to map!)
23
-     */
24
-    public static function google_map($ee_gmaps_opts)
25
-    {
26
-
27
-        $ee_map_width = ! empty($ee_gmaps_opts['ee_map_width'])
28
-            ? absint($ee_gmaps_opts['ee_map_width'])
29
-            : 300;
30
-
31
-        $ee_map_height = ! empty($ee_gmaps_opts['ee_map_height'])
32
-            ? absint($ee_gmaps_opts['ee_map_height'])
33
-            : 185;
34
-
35
-        $ee_map_zoom = ! empty($ee_gmaps_opts['ee_map_zoom'])
36
-            ? absint($ee_gmaps_opts['ee_map_zoom'])
37
-            : 12;
38
-
39
-        $ee_map_nav_display = ! empty($ee_gmaps_opts['ee_map_nav_display']) ? 'true' : 'false';
40
-
41
-        $ee_map_nav_size = ! empty($ee_gmaps_opts['ee_map_nav_size'])
42
-            ? sanitize_text_field($ee_gmaps_opts['ee_map_nav_size'])
43
-            : 'default';
44
-
45
-        $ee_map_type_control = ! empty($ee_gmaps_opts['ee_map_type_control'])
46
-            ? sanitize_text_field($ee_gmaps_opts['ee_map_type_control'])
47
-            : 'default';
48
-
49
-        $static_url = ! empty($ee_gmaps_opts['ee_static_url'])
50
-            ? esc_url_raw($ee_gmaps_opts['ee_static_url'])
51
-            : false;
52
-
53
-        if (! empty($ee_gmaps_opts['ee_map_align'])) {
54
-            switch ($ee_gmaps_opts['ee_map_align']) {
55
-                case "left":
56
-                    $map_align = 'ee-gmap-align-left left';
57
-                    break;
58
-                case "right":
59
-                    $map_align = 'ee-gmap-align-right right';
60
-                    break;
61
-                case "center":
62
-                    $map_align = 'ee-gmap-align-center center';
63
-                    break;
64
-                case "none":
65
-                default:
66
-                    $map_align = 'ee-gmap-align-none';
67
-            }
68
-        } else {
69
-            $map_align = 'ee-gmap-align-none';
70
-        }
71
-
72
-
73
-        // Determine whether user has set a hardcoded url to use and
74
-        // if so display a Google static iframe map else run V3 api
75
-        if ($static_url) {
76
-            $html = '
14
+	// array of map settings
15
+	public static $gmap_vars = [];
16
+
17
+
18
+	/**
19
+	 * google_map - creates a Google Map Link
20
+	 *
21
+	 * @param array $ee_gmaps_opts array of attributes required for the map link generation
22
+	 * @return string (link to map!)
23
+	 */
24
+	public static function google_map($ee_gmaps_opts)
25
+	{
26
+
27
+		$ee_map_width = ! empty($ee_gmaps_opts['ee_map_width'])
28
+			? absint($ee_gmaps_opts['ee_map_width'])
29
+			: 300;
30
+
31
+		$ee_map_height = ! empty($ee_gmaps_opts['ee_map_height'])
32
+			? absint($ee_gmaps_opts['ee_map_height'])
33
+			: 185;
34
+
35
+		$ee_map_zoom = ! empty($ee_gmaps_opts['ee_map_zoom'])
36
+			? absint($ee_gmaps_opts['ee_map_zoom'])
37
+			: 12;
38
+
39
+		$ee_map_nav_display = ! empty($ee_gmaps_opts['ee_map_nav_display']) ? 'true' : 'false';
40
+
41
+		$ee_map_nav_size = ! empty($ee_gmaps_opts['ee_map_nav_size'])
42
+			? sanitize_text_field($ee_gmaps_opts['ee_map_nav_size'])
43
+			: 'default';
44
+
45
+		$ee_map_type_control = ! empty($ee_gmaps_opts['ee_map_type_control'])
46
+			? sanitize_text_field($ee_gmaps_opts['ee_map_type_control'])
47
+			: 'default';
48
+
49
+		$static_url = ! empty($ee_gmaps_opts['ee_static_url'])
50
+			? esc_url_raw($ee_gmaps_opts['ee_static_url'])
51
+			: false;
52
+
53
+		if (! empty($ee_gmaps_opts['ee_map_align'])) {
54
+			switch ($ee_gmaps_opts['ee_map_align']) {
55
+				case "left":
56
+					$map_align = 'ee-gmap-align-left left';
57
+					break;
58
+				case "right":
59
+					$map_align = 'ee-gmap-align-right right';
60
+					break;
61
+				case "center":
62
+					$map_align = 'ee-gmap-align-center center';
63
+					break;
64
+				case "none":
65
+				default:
66
+					$map_align = 'ee-gmap-align-none';
67
+			}
68
+		} else {
69
+			$map_align = 'ee-gmap-align-none';
70
+		}
71
+
72
+
73
+		// Determine whether user has set a hardcoded url to use and
74
+		// if so display a Google static iframe map else run V3 api
75
+		if ($static_url) {
76
+			$html = '
77 77
             <div class="ee-gmap-iframewrap ee-gmap-wrapper ' . $map_align . '">
78 78
                 <iframe src="' . $static_url . '&output=embed"
79 79
                         style="width: ' . $ee_map_width . 'px; height: ' . $ee_map_height . 'px;"
@@ -84,18 +84,18 @@  discard block
 block discarded – undo
84 84
                 <a href="' . $static_url . '">' . esc_html__('View Large map', 'event_espresso') . '</a>
85 85
             </div>
86 86
 ';
87
-        } else {
88
-            EEH_Maps::$gmap_vars[ $ee_gmaps_opts['map_ID'] ] = [
89
-                'map_ID'              => $ee_gmaps_opts['map_ID'],
90
-                'ee_map_zoom'         => $ee_map_zoom,
91
-                'ee_map_nav_display'  => $ee_map_nav_display,
92
-                'ee_map_nav_size'     => $ee_map_nav_size,
93
-                'ee_map_type_control' => $ee_map_type_control,
94
-                'location'            => $ee_gmaps_opts['location'],
95
-            ];
96
-
97
-            $style = 'width: ' . $ee_map_width . 'px; height: ' . $ee_map_height . 'px;';
98
-            $html  = '
87
+		} else {
88
+			EEH_Maps::$gmap_vars[ $ee_gmaps_opts['map_ID'] ] = [
89
+				'map_ID'              => $ee_gmaps_opts['map_ID'],
90
+				'ee_map_zoom'         => $ee_map_zoom,
91
+				'ee_map_nav_display'  => $ee_map_nav_display,
92
+				'ee_map_nav_size'     => $ee_map_nav_size,
93
+				'ee_map_type_control' => $ee_map_type_control,
94
+				'location'            => $ee_gmaps_opts['location'],
95
+			];
96
+
97
+			$style = 'width: ' . $ee_map_width . 'px; height: ' . $ee_map_height . 'px;';
98
+			$html  = '
99 99
             <div class="ee-gmap-wrapper ' . esc_attr($map_align) . '">
100 100
                 <div class="ee-gmap" 
101 101
                      id="map_canvas_' . esc_attr($ee_gmaps_opts['map_ID']) . '"
@@ -103,109 +103,109 @@  discard block
 block discarded – undo
103 103
                  ></div>
104 104
             </div>';
105 105
 
106
-            wp_enqueue_script('gmap_api');
107
-            wp_enqueue_script('ee_gmap');
108
-            add_action('wp_footer', ['EEH_Maps', 'footer_enqueue_script']);
109
-        }
110
-        return $html; // end auto map or static url map check
111
-    }
112
-
113
-
114
-    /**
115
-     * enqueue_script
116
-     *
117
-     * @return void
118
-     */
119
-    public static function footer_enqueue_script()
120
-    {
121
-        wp_localize_script('ee_gmap', 'ee_gmap_vars', EEH_Maps::$gmap_vars);
122
-    }
123
-
124
-
125
-    /**
126
-     * registers scripts for maps
127
-     */
128
-    public static function espresso_google_map_js()
129
-    {
130
-        $api_url = sprintf(
131
-            "https://maps.googleapis.com/maps/api/js?key=%s",
132
-            apply_filters(
133
-                'FHEE__EEH_Maps__espresso_google_maps_js__api_key',
134
-                EE_Registry::instance()->CFG->map_settings->google_map_api_key
135
-            )
136
-        );
137
-        wp_register_script(
138
-            'gmap_api',
139
-            esc_url_raw($api_url),
140
-            ['jquery'],
141
-            null,
142
-            true
143
-        );
144
-        wp_register_script(
145
-            'ee_gmap',
146
-            plugin_dir_url(__FILE__) . 'assets/ee_gmap.js',
147
-            ['gmap_api'],
148
-            '1.0',
149
-            true
150
-        );
151
-    }
152
-
153
-
154
-    /**
155
-     * creates a Google Map Link
156
-     *
157
-     * @param array $atts array of attributes required for the map link generation
158
-     * @return string (link to map!)
159
-     */
160
-    public static function google_map_link($atts)
161
-    {
162
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
163
-        extract($atts);
164
-        /** @var string $address */
165
-        /** @var string $city */
166
-        /** @var string $state */
167
-        /** @var string $zip */
168
-        /** @var string $country */
169
-        $address         = "{$address}";
170
-        $city            = "{$city}";
171
-        $state           = "{$state}";
172
-        $zip             = "{$zip}";
173
-        $country         = "{$country}";
174
-        $text            = isset($text) ? "{$text}" : "";
175
-        $type            = isset($type) ? "{$type}" : "";
176
-        $map_w           = isset($map_w) ? "{$map_w}" : 400;
177
-        $map_h           = isset($map_h) ? "{$map_h}" : 400;
178
-        $id              = isset($id) ? $id : 'not_set';
179
-        $map_image_class = isset($map_image_class) ? $map_image_class : 'ee_google_map_view';
180
-
181
-        $address_string = ($address != '' ? $address : '')
182
-                          . ($city != '' ? ',' . $city : '')
183
-                          . ($state != '' ? ',' . $state : '')
184
-                          . ($zip != '' ? ',' . $zip : '')
185
-                          . ($country != '' ? ',' . $country : '');
186
-
187
-        $google_map = htmlentities2('https://maps.google.com/maps?q=' . urlencode($address_string));
188
-
189
-        switch ($type) {
190
-            case 'text':
191
-            default:
192
-                $text = $text == '' ? esc_html__('Map and Directions', 'event_espresso') : $text;
193
-                break;
194
-
195
-            case 'url_only':
196
-            case 'url':
197
-                $text = $google_map;
198
-                break;
199
-
200
-            case 'map':
201
-                $scheme = is_ssl() ? 'https://' : 'http://';
202
-
203
-                $api_key = apply_filters(
204
-                    'FHEE__EEH_Maps__espresso_google_maps_link__api_key',
205
-                    EE_Registry::instance()->CFG->map_settings->google_map_api_key
206
-                );
207
-
208
-                return '
106
+			wp_enqueue_script('gmap_api');
107
+			wp_enqueue_script('ee_gmap');
108
+			add_action('wp_footer', ['EEH_Maps', 'footer_enqueue_script']);
109
+		}
110
+		return $html; // end auto map or static url map check
111
+	}
112
+
113
+
114
+	/**
115
+	 * enqueue_script
116
+	 *
117
+	 * @return void
118
+	 */
119
+	public static function footer_enqueue_script()
120
+	{
121
+		wp_localize_script('ee_gmap', 'ee_gmap_vars', EEH_Maps::$gmap_vars);
122
+	}
123
+
124
+
125
+	/**
126
+	 * registers scripts for maps
127
+	 */
128
+	public static function espresso_google_map_js()
129
+	{
130
+		$api_url = sprintf(
131
+			"https://maps.googleapis.com/maps/api/js?key=%s",
132
+			apply_filters(
133
+				'FHEE__EEH_Maps__espresso_google_maps_js__api_key',
134
+				EE_Registry::instance()->CFG->map_settings->google_map_api_key
135
+			)
136
+		);
137
+		wp_register_script(
138
+			'gmap_api',
139
+			esc_url_raw($api_url),
140
+			['jquery'],
141
+			null,
142
+			true
143
+		);
144
+		wp_register_script(
145
+			'ee_gmap',
146
+			plugin_dir_url(__FILE__) . 'assets/ee_gmap.js',
147
+			['gmap_api'],
148
+			'1.0',
149
+			true
150
+		);
151
+	}
152
+
153
+
154
+	/**
155
+	 * creates a Google Map Link
156
+	 *
157
+	 * @param array $atts array of attributes required for the map link generation
158
+	 * @return string (link to map!)
159
+	 */
160
+	public static function google_map_link($atts)
161
+	{
162
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
163
+		extract($atts);
164
+		/** @var string $address */
165
+		/** @var string $city */
166
+		/** @var string $state */
167
+		/** @var string $zip */
168
+		/** @var string $country */
169
+		$address         = "{$address}";
170
+		$city            = "{$city}";
171
+		$state           = "{$state}";
172
+		$zip             = "{$zip}";
173
+		$country         = "{$country}";
174
+		$text            = isset($text) ? "{$text}" : "";
175
+		$type            = isset($type) ? "{$type}" : "";
176
+		$map_w           = isset($map_w) ? "{$map_w}" : 400;
177
+		$map_h           = isset($map_h) ? "{$map_h}" : 400;
178
+		$id              = isset($id) ? $id : 'not_set';
179
+		$map_image_class = isset($map_image_class) ? $map_image_class : 'ee_google_map_view';
180
+
181
+		$address_string = ($address != '' ? $address : '')
182
+						  . ($city != '' ? ',' . $city : '')
183
+						  . ($state != '' ? ',' . $state : '')
184
+						  . ($zip != '' ? ',' . $zip : '')
185
+						  . ($country != '' ? ',' . $country : '');
186
+
187
+		$google_map = htmlentities2('https://maps.google.com/maps?q=' . urlencode($address_string));
188
+
189
+		switch ($type) {
190
+			case 'text':
191
+			default:
192
+				$text = $text == '' ? esc_html__('Map and Directions', 'event_espresso') : $text;
193
+				break;
194
+
195
+			case 'url_only':
196
+			case 'url':
197
+				$text = $google_map;
198
+				break;
199
+
200
+			case 'map':
201
+				$scheme = is_ssl() ? 'https://' : 'http://';
202
+
203
+				$api_key = apply_filters(
204
+					'FHEE__EEH_Maps__espresso_google_maps_link__api_key',
205
+					EE_Registry::instance()->CFG->map_settings->google_map_api_key
206
+				);
207
+
208
+				return '
209 209
                 <a class="a_map_image_link" 
210 210
                    href="' . esc_url_raw($google_map) . '" 
211 211
                    target="_blank" 
@@ -215,23 +215,23 @@  discard block
 block discarded – undo
215 215
                          class="map_image_link" 
216 216
                          id="venue_map_' . $id . '" ' . $map_image_class . ' 
217 217
                          src="'
218
-                       . htmlentities2(
219
-                           $scheme
220
-                           . 'maps.googleapis.com/maps/api/staticmap?center='
221
-                           . urlencode($address_string)
222
-                           . '&amp;zoom=14&amp;size='
223
-                           . $map_w . 'x' . $map_h
224
-                           . '&amp;markers=color:green|label:|'
225
-                           . urlencode($address_string)
226
-                           . '&amp;sensor=false&amp;key='
227
-                           . $api_key
228
-                       ) . '"
218
+					   . htmlentities2(
219
+						   $scheme
220
+						   . 'maps.googleapis.com/maps/api/staticmap?center='
221
+						   . urlencode($address_string)
222
+						   . '&amp;zoom=14&amp;size='
223
+						   . $map_w . 'x' . $map_h
224
+						   . '&amp;markers=color:green|label:|'
225
+						   . urlencode($address_string)
226
+						   . '&amp;sensor=false&amp;key='
227
+						   . $api_key
228
+					   ) . '"
229 229
                      />
230 230
                  </a>';
231
-        }
231
+		}
232 232
 
233
-        return $type === 'url_only'
234
-            ? $text
235
-            : '<a href="' . esc_url_raw($google_map) . '" target="_blank" rel="noopener noreferrer">' . $text . '</a>';
236
-    }
233
+		return $type === 'url_only'
234
+			? $text
235
+			: '<a href="' . esc_url_raw($google_map) . '" target="_blank" rel="noopener noreferrer">' . $text . '</a>';
236
+	}
237 237
 }
Please login to merge, or discard this patch.
core/helpers/EEH_Debug_Tools.helper.php 2 patches
Spacing   +41 added lines, -41 removed lines patch added patch discarded remove patch
@@ -38,7 +38,7 @@  discard block
 block discarded – undo
38 38
     public static function instance()
39 39
     {
40 40
         // check if class object is instantiated, and instantiated properly
41
-        if (! self::$_instance instanceof EEH_Debug_Tools) {
41
+        if ( ! self::$_instance instanceof EEH_Debug_Tools) {
42 42
             self::$_instance = new self();
43 43
         }
44 44
         return self::$_instance;
@@ -55,14 +55,14 @@  discard block
 block discarded – undo
55 55
         if (
56 56
             defined('EE_LOAD_KINT')
57 57
             && ! class_exists('Kint')
58
-            && file_exists(EE_PLUGIN_DIR_PATH . 'tests/kint/Kint.class.php')
58
+            && file_exists(EE_PLUGIN_DIR_PATH.'tests/kint/Kint.class.php')
59 59
         ) {
60 60
             // despite EE4 having a check for an existing copy of the Kint debugging class,
61 61
             // if another plugin was loaded AFTER EE4 and they did NOT perform a similar check,
62 62
             // then hilarity would ensue as PHP throws a "Cannot redeclare class Kint" error
63 63
             // so we've moved it to our test folder so that it is not included with production releases
64 64
             // plz use https://wordpress.org/plugins/kint-debugger/  if testing production versions of EE
65
-            require_once(EE_PLUGIN_DIR_PATH . 'tests/kint/Kint.class.php');
65
+            require_once(EE_PLUGIN_DIR_PATH.'tests/kint/Kint.class.php');
66 66
         }
67 67
         $plugin = basename(EE_PLUGIN_DIR_PATH);
68 68
         add_action("activate_{$plugin}", array('EEH_Debug_Tools', 'ee_plugin_activation_errors'));
@@ -79,7 +79,7 @@  discard block
 block discarded – undo
79 79
      */
80 80
     public static function show_db_name()
81 81
     {
82
-        if (! defined('DOING_AJAX') && (defined('EE_ERROR_EMAILS') && EE_ERROR_EMAILS)) {
82
+        if ( ! defined('DOING_AJAX') && (defined('EE_ERROR_EMAILS') && EE_ERROR_EMAILS)) {
83 83
             echo '<p style="font-size:10px;font-weight:normal;color:#E76700;margin: 1em 2em; text-align: right;">DB_NAME: '
84 84
                  . DB_NAME
85 85
                  . '</p>';
@@ -129,12 +129,12 @@  discard block
 block discarded – undo
129 129
         global $wp_filter;
130 130
         echo '<br/><br/><br/><h3>Hooked Functions</h3>';
131 131
         if ($tag) {
132
-            $hook[ $tag ] = $wp_filter[ $tag ];
133
-            if (! is_array($hook[ $tag ])) {
132
+            $hook[$tag] = $wp_filter[$tag];
133
+            if ( ! is_array($hook[$tag])) {
134 134
                 trigger_error("Nothing found for '$tag' hook", E_USER_WARNING);
135 135
                 return;
136 136
             }
137
-            echo '<h5>For Tag: ' . esc_html($tag) . '</h5>';
137
+            echo '<h5>For Tag: '.esc_html($tag).'</h5>';
138 138
         } else {
139 139
             $hook = is_array($wp_filter) ? $wp_filter : array($wp_filter);
140 140
             ksort($hook);
@@ -164,12 +164,12 @@  discard block
 block discarded – undo
164 164
     {
165 165
         $filters = array();
166 166
         global $wp_filter;
167
-        if (isset($wp_filter[ $hook_name ])) {
168
-            $filters[ $hook_name ] = array();
169
-            foreach ($wp_filter[ $hook_name ] as $priority => $callbacks) {
170
-                $filters[ $hook_name ][ $priority ] = array();
167
+        if (isset($wp_filter[$hook_name])) {
168
+            $filters[$hook_name] = array();
169
+            foreach ($wp_filter[$hook_name] as $priority => $callbacks) {
170
+                $filters[$hook_name][$priority] = array();
171 171
                 foreach ($callbacks as $callback) {
172
-                    $filters[ $hook_name ][ $priority ][] = $callback['function'];
172
+                    $filters[$hook_name][$priority][] = $callback['function'];
173 173
                 }
174 174
             }
175 175
         }
@@ -188,17 +188,17 @@  discard block
 block discarded – undo
188 188
     {
189 189
         if (WP_DEBUG) {
190 190
             $activation_errors = ob_get_contents();
191
-            if (! empty($activation_errors)) {
192
-                $activation_errors = date('Y-m-d H:i:s') . "\n" . $activation_errors;
191
+            if ( ! empty($activation_errors)) {
192
+                $activation_errors = date('Y-m-d H:i:s')."\n".$activation_errors;
193 193
             }
194
-            espresso_load_required('EEH_File', EE_HELPERS . 'EEH_File.helper.php');
194
+            espresso_load_required('EEH_File', EE_HELPERS.'EEH_File.helper.php');
195 195
             if (class_exists('EEH_File')) {
196 196
                 try {
197 197
                     EEH_File::ensure_file_exists_and_is_writable(
198
-                        EVENT_ESPRESSO_UPLOAD_DIR . 'logs/espresso_plugin_activation_errors.html'
198
+                        EVENT_ESPRESSO_UPLOAD_DIR.'logs/espresso_plugin_activation_errors.html'
199 199
                     );
200 200
                     EEH_File::write_to_file(
201
-                        EVENT_ESPRESSO_UPLOAD_DIR . 'logs/espresso_plugin_activation_errors.html',
201
+                        EVENT_ESPRESSO_UPLOAD_DIR.'logs/espresso_plugin_activation_errors.html',
202 202
                         $activation_errors
203 203
                     );
204 204
                 } catch (EE_Error $e) {
@@ -218,11 +218,11 @@  discard block
 block discarded – undo
218 218
             } else {
219 219
                 // old school attempt
220 220
                 file_put_contents(
221
-                    EVENT_ESPRESSO_UPLOAD_DIR . 'logs/espresso_plugin_activation_errors.html',
221
+                    EVENT_ESPRESSO_UPLOAD_DIR.'logs/espresso_plugin_activation_errors.html',
222 222
                     $activation_errors
223 223
                 );
224 224
             }
225
-            $activation_errors = get_option('ee_plugin_activation_errors', '') . $activation_errors;
225
+            $activation_errors = get_option('ee_plugin_activation_errors', '').$activation_errors;
226 226
             update_option('ee_plugin_activation_errors', $activation_errors);
227 227
         }
228 228
     }
@@ -282,7 +282,7 @@  discard block
 block discarded – undo
282 282
         // don't trigger error if doing ajax,
283 283
         // instead we'll add a transient EE_Error notice that in theory should show on the next request.
284 284
         if (defined('DOING_AJAX') && DOING_AJAX) {
285
-            $error_message .= ' ' . esc_html__(
285
+            $error_message .= ' '.esc_html__(
286 286
                 'This is a doing_it_wrong message that was triggered during an ajax request.  The request params on this request were: ',
287 287
                 'event_espresso'
288 288
             );
@@ -325,18 +325,18 @@  discard block
 block discarded – undo
325 325
         $debug_key = 'EE_DEBUG_SPCO'
326 326
     ) {
327 327
         if (WP_DEBUG) {
328
-            $debug_key = $debug_key . '_' . EE_Session::instance()->id();
328
+            $debug_key = $debug_key.'_'.EE_Session::instance()->id();
329 329
             $debug_data = get_option($debug_key, array());
330 330
             $default_data = array(
331
-                $class => $func . '() : ' . $line,
331
+                $class => $func.'() : '.$line,
332 332
             );
333 333
             // don't serialize objects
334 334
             $info = self::strip_objects($info);
335 335
             $index = ! empty($debug_index) ? $debug_index : 0;
336
-            if (! isset($debug_data[ $index ])) {
337
-                $debug_data[ $index ] = array();
336
+            if ( ! isset($debug_data[$index])) {
337
+                $debug_data[$index] = array();
338 338
             }
339
-            $debug_data[ $index ][ microtime() ] = array_merge($default_data, $info);
339
+            $debug_data[$index][microtime()] = array_merge($default_data, $info);
340 340
             update_option($debug_key, $debug_data);
341 341
         }
342 342
     }
@@ -353,20 +353,20 @@  discard block
 block discarded – undo
353 353
     {
354 354
         foreach ($info as $key => $value) {
355 355
             if (is_array($value)) {
356
-                $info[ $key ] = self::strip_objects($value);
356
+                $info[$key] = self::strip_objects($value);
357 357
             } elseif (is_object($value)) {
358 358
                 $object_class = get_class($value);
359
-                $info[ $object_class ] = array();
360
-                $info[ $object_class ]['ID'] = method_exists($value, 'ID') ? $value->ID() : spl_object_hash($value);
359
+                $info[$object_class] = array();
360
+                $info[$object_class]['ID'] = method_exists($value, 'ID') ? $value->ID() : spl_object_hash($value);
361 361
                 if (method_exists($value, 'ID')) {
362
-                    $info[ $object_class ]['ID'] = $value->ID();
362
+                    $info[$object_class]['ID'] = $value->ID();
363 363
                 }
364 364
                 if (method_exists($value, 'status')) {
365
-                    $info[ $object_class ]['status'] = $value->status();
365
+                    $info[$object_class]['status'] = $value->status();
366 366
                 } elseif (method_exists($value, 'status_ID')) {
367
-                    $info[ $object_class ]['status'] = $value->status_ID();
367
+                    $info[$object_class]['status'] = $value->status_ID();
368 368
                 }
369
-                unset($info[ $key ]);
369
+                unset($info[$key]);
370 370
             }
371 371
         }
372 372
         return (array) $info;
@@ -400,8 +400,8 @@  discard block
 block discarded – undo
400 400
         $result = EEH_Debug_Tools::headingSpacer($heading_tag);
401 401
         $result .= EEH_Debug_Tools::heading($var_name, $heading_tag, $margin, $line);
402 402
         $result .= $is_method
403
-            ? EEH_Debug_Tools::grey_span('::') . EEH_Debug_Tools::orange_span($var . '()')
404
-            : EEH_Debug_Tools::grey_span(' : ') . EEH_Debug_Tools::orange_span($var);
403
+            ? EEH_Debug_Tools::grey_span('::').EEH_Debug_Tools::orange_span($var.'()')
404
+            : EEH_Debug_Tools::grey_span(' : ').EEH_Debug_Tools::orange_span($var);
405 405
         $result .= EEH_Debug_Tools::file_and_line($file, $line, $heading_tag);
406 406
         $result .= EEH_Debug_Tools::headingX($heading_tag);
407 407
         if ($die) {
@@ -456,11 +456,11 @@  discard block
 block discarded – undo
456 456
             if ($heading_tag === 'h1' || $heading_tag === 'h2') {
457 457
                 $heading .= self::lineBreak();
458 458
             }
459
-            $heading .= self::lineBreak() . "{$line}) {$var_name}";
459
+            $heading .= self::lineBreak()."{$line}) {$var_name}";
460 460
             return $heading;
461 461
         }
462 462
         $margin = "25px 0 0 {$margin}";
463
-        return '<' . $heading_tag . ' style="color:#2EA2CC; margin:' . $margin . ';"><b>' . $var_name . '</b>';
463
+        return '<'.$heading_tag.' style="color:#2EA2CC; margin:'.$margin.';"><b>'.$var_name.'</b>';
464 464
     }
465 465
 
466 466
 
@@ -474,7 +474,7 @@  discard block
 block discarded – undo
474 474
         if (EEH_Debug_Tools::plainOutput()) {
475 475
             return '';
476 476
         }
477
-        return '</' . $heading_tag . '>';
477
+        return '</'.$heading_tag.'>';
478 478
     }
479 479
 
480 480
 
@@ -488,7 +488,7 @@  discard block
 block discarded – undo
488 488
         if (EEH_Debug_Tools::plainOutput()) {
489 489
             return $content;
490 490
         }
491
-        return '<span style="color:#999">' . $content . '</span>';
491
+        return '<span style="color:#999">'.$content.'</span>';
492 492
     }
493 493
 
494 494
 
@@ -528,7 +528,7 @@  discard block
 block discarded – undo
528 528
         if (EEH_Debug_Tools::plainOutput()) {
529 529
             return $content;
530 530
         }
531
-        return '<span style="color:#E76700">' . $content . '</span>';
531
+        return '<span style="color:#E76700">'.$content.'</span>';
532 532
     }
533 533
 
534 534
 
@@ -545,7 +545,7 @@  discard block
 block discarded – undo
545 545
         if (EEH_Debug_Tools::plainOutput()) {
546 546
             return str_replace("\n", '', $var);
547 547
         }
548
-        return '<pre style="color:#999; padding:1em; background: #fff">' . $var . '</pre>';
548
+        return '<pre style="color:#999; padding:1em; background: #fff">'.$var.'</pre>';
549 549
     }
550 550
 
551 551
 
@@ -586,7 +586,7 @@  discard block
 block discarded – undo
586 586
         $heading_tag = EEH_Debug_Tools::headingTag($heading_tag);
587 587
         $result = EEH_Debug_Tools::headingSpacer($heading_tag);
588 588
         $result .= EEH_Debug_Tools::heading($var_name, $heading_tag, $margin, $line);
589
-        $result .= EEH_Debug_Tools::grey_span(' : ') . EEH_Debug_Tools::orange_span(
589
+        $result .= EEH_Debug_Tools::grey_span(' : ').EEH_Debug_Tools::orange_span(
590 590
             EEH_Debug_Tools::pre_span($var)
591 591
         );
592 592
         $result .= EEH_Debug_Tools::file_and_line($file, $line, $heading_tag);
Please login to merge, or discard this patch.
Indentation   +682 added lines, -682 removed lines patch added patch discarded remove patch
@@ -15,673 +15,673 @@  discard block
 block discarded – undo
15 15
  */
16 16
 class EEH_Debug_Tools
17 17
 {
18
-    /**
19
-     *    instance of the EEH_Autoloader object
20
-     *
21
-     * @var    $_instance
22
-     * @access    private
23
-     */
24
-    private static $_instance;
25
-
26
-    /**
27
-     * @var array
28
-     */
29
-    protected $_memory_usage_points = array();
30
-
31
-
32
-
33
-    /**
34
-     * @singleton method used to instantiate class object
35
-     * @access    public
36
-     * @return EEH_Debug_Tools
37
-     */
38
-    public static function instance()
39
-    {
40
-        // check if class object is instantiated, and instantiated properly
41
-        if (! self::$_instance instanceof EEH_Debug_Tools) {
42
-            self::$_instance = new self();
43
-        }
44
-        return self::$_instance;
45
-    }
46
-
47
-
48
-
49
-    /**
50
-     * private class constructor
51
-     */
52
-    private function __construct()
53
-    {
54
-        // load Kint PHP debugging library
55
-        if (
56
-            defined('EE_LOAD_KINT')
57
-            && ! class_exists('Kint')
58
-            && file_exists(EE_PLUGIN_DIR_PATH . 'tests/kint/Kint.class.php')
59
-        ) {
60
-            // despite EE4 having a check for an existing copy of the Kint debugging class,
61
-            // if another plugin was loaded AFTER EE4 and they did NOT perform a similar check,
62
-            // then hilarity would ensue as PHP throws a "Cannot redeclare class Kint" error
63
-            // so we've moved it to our test folder so that it is not included with production releases
64
-            // plz use https://wordpress.org/plugins/kint-debugger/  if testing production versions of EE
65
-            require_once(EE_PLUGIN_DIR_PATH . 'tests/kint/Kint.class.php');
66
-        }
67
-        $plugin = basename(EE_PLUGIN_DIR_PATH);
68
-        add_action("activate_{$plugin}", array('EEH_Debug_Tools', 'ee_plugin_activation_errors'));
69
-        add_action('activated_plugin', array('EEH_Debug_Tools', 'ee_plugin_activation_errors'));
70
-        add_action('shutdown', array('EEH_Debug_Tools', 'show_db_name'));
71
-    }
72
-
73
-
74
-
75
-    /**
76
-     *    show_db_name
77
-     *
78
-     * @return void
79
-     */
80
-    public static function show_db_name()
81
-    {
82
-        if (! defined('DOING_AJAX') && (defined('EE_ERROR_EMAILS') && EE_ERROR_EMAILS)) {
83
-            echo '<p style="font-size:10px;font-weight:normal;color:#E76700;margin: 1em 2em; text-align: right;">DB_NAME: '
84
-                 . DB_NAME
85
-                 . '</p>';
86
-        }
87
-        if (EE_DEBUG) {
88
-            Benchmark::displayResults();
89
-        }
90
-    }
91
-
92
-
93
-
94
-    /**
95
-     *    dump EE_Session object at bottom of page after everything else has happened
96
-     *
97
-     * @return void
98
-     */
99
-    public function espresso_session_footer_dump()
100
-    {
101
-        if (
102
-            (defined('WP_DEBUG') && WP_DEBUG)
103
-            && ! defined('DOING_AJAX')
104
-            && class_exists('Kint')
105
-            && function_exists('wp_get_current_user')
106
-            && current_user_can('update_core')
107
-            && class_exists('EE_Registry')
108
-        ) {
109
-            Kint::dump(EE_Registry::instance()->SSN->id());
110
-            Kint::dump(EE_Registry::instance()->SSN);
111
-            //          Kint::dump( EE_Registry::instance()->SSN->get_session_data('cart')->get_tickets() );
112
-            $this->espresso_list_hooked_functions();
113
-            Benchmark::displayResults();
114
-        }
115
-    }
116
-
117
-
118
-
119
-    /**
120
-     *    List All Hooked Functions
121
-     *    to list all functions for a specific hook, add ee_list_hooks={hook-name} to URL
122
-     *    http://wp.smashingmagazine.com/2009/08/18/10-useful-wordpress-hook-hacks/
123
-     *
124
-     * @param string $tag
125
-     * @return void
126
-     */
127
-    public function espresso_list_hooked_functions($tag = '')
128
-    {
129
-        global $wp_filter;
130
-        echo '<br/><br/><br/><h3>Hooked Functions</h3>';
131
-        if ($tag) {
132
-            $hook[ $tag ] = $wp_filter[ $tag ];
133
-            if (! is_array($hook[ $tag ])) {
134
-                trigger_error("Nothing found for '$tag' hook", E_USER_WARNING);
135
-                return;
136
-            }
137
-            echo '<h5>For Tag: ' . esc_html($tag) . '</h5>';
138
-        } else {
139
-            $hook = is_array($wp_filter) ? $wp_filter : array($wp_filter);
140
-            ksort($hook);
141
-        }
142
-        foreach ($hook as $tag_name => $priorities) {
143
-            echo "<br />&gt;&gt;&gt;&gt;&gt;\t<strong>esc_html($tag_name)</strong><br />";
144
-            ksort($priorities);
145
-            foreach ($priorities as $priority => $function) {
146
-                echo esc_html($priority);
147
-                foreach ($function as $name => $properties) {
148
-                    $name = esc_html($name);
149
-                    echo "\t$name<br />";
150
-                }
151
-            }
152
-        }
153
-    }
154
-
155
-
156
-
157
-    /**
158
-     *    registered_filter_callbacks
159
-     *
160
-     * @param string $hook_name
161
-     * @return array
162
-     */
163
-    public static function registered_filter_callbacks($hook_name = '')
164
-    {
165
-        $filters = array();
166
-        global $wp_filter;
167
-        if (isset($wp_filter[ $hook_name ])) {
168
-            $filters[ $hook_name ] = array();
169
-            foreach ($wp_filter[ $hook_name ] as $priority => $callbacks) {
170
-                $filters[ $hook_name ][ $priority ] = array();
171
-                foreach ($callbacks as $callback) {
172
-                    $filters[ $hook_name ][ $priority ][] = $callback['function'];
173
-                }
174
-            }
175
-        }
176
-        return $filters;
177
-    }
178
-
179
-
180
-
181
-    /**
182
-     *    captures plugin activation errors for debugging
183
-     *
184
-     * @return void
185
-     * @throws EE_Error
186
-     */
187
-    public static function ee_plugin_activation_errors()
188
-    {
189
-        if (WP_DEBUG) {
190
-            $activation_errors = ob_get_contents();
191
-            if (! empty($activation_errors)) {
192
-                $activation_errors = date('Y-m-d H:i:s') . "\n" . $activation_errors;
193
-            }
194
-            espresso_load_required('EEH_File', EE_HELPERS . 'EEH_File.helper.php');
195
-            if (class_exists('EEH_File')) {
196
-                try {
197
-                    EEH_File::ensure_file_exists_and_is_writable(
198
-                        EVENT_ESPRESSO_UPLOAD_DIR . 'logs/espresso_plugin_activation_errors.html'
199
-                    );
200
-                    EEH_File::write_to_file(
201
-                        EVENT_ESPRESSO_UPLOAD_DIR . 'logs/espresso_plugin_activation_errors.html',
202
-                        $activation_errors
203
-                    );
204
-                } catch (EE_Error $e) {
205
-                    EE_Error::add_error(
206
-                        sprintf(
207
-                            esc_html__(
208
-                                'The Event Espresso activation errors file could not be setup because: %s',
209
-                                'event_espresso'
210
-                            ),
211
-                            $e->getMessage()
212
-                        ),
213
-                        __FILE__,
214
-                        __FUNCTION__,
215
-                        __LINE__
216
-                    );
217
-                }
218
-            } else {
219
-                // old school attempt
220
-                file_put_contents(
221
-                    EVENT_ESPRESSO_UPLOAD_DIR . 'logs/espresso_plugin_activation_errors.html',
222
-                    $activation_errors
223
-                );
224
-            }
225
-            $activation_errors = get_option('ee_plugin_activation_errors', '') . $activation_errors;
226
-            update_option('ee_plugin_activation_errors', $activation_errors);
227
-        }
228
-    }
229
-
230
-
231
-
232
-    /**
233
-     * This basically mimics the WordPress _doing_it_wrong() function except adds our own messaging etc.
234
-     * Very useful for providing helpful messages to developers when the method of doing something has been deprecated,
235
-     * or we want to make sure they use something the right way.
236
-     *
237
-     * @access public
238
-     * @param string $function      The function that was called
239
-     * @param string $message       A message explaining what has been done incorrectly
240
-     * @param string $version       The version of Event Espresso where the error was added
241
-     * @param string $applies_when  a version string for when you want the doing_it_wrong notice to begin appearing
242
-     *                              for a deprecated function. This allows deprecation to occur during one version,
243
-     *                              but not have any notices appear until a later version. This allows developers
244
-     *                              extra time to update their code before notices appear.
245
-     * @param int    $error_type
246
-     * @uses   trigger_error()
247
-     */
248
-    public function doing_it_wrong(
249
-        $function,
250
-        $message,
251
-        $version,
252
-        $applies_when = '',
253
-        $error_type = null
254
-    ) {
255
-        $applies_when = ! empty($applies_when) ? $applies_when : espresso_version();
256
-        $error_type = $error_type !== null ? $error_type : E_USER_NOTICE;
257
-        // because we swapped the parameter order around for the last two params,
258
-        // let's verify that some third party isn't still passing an error type value for the third param
259
-        if (is_int($applies_when)) {
260
-            $error_type = $applies_when;
261
-            $applies_when = espresso_version();
262
-        }
263
-        // if not displaying notices yet, then just leave
264
-        if (version_compare(espresso_version(), $applies_when, '<')) {
265
-            return;
266
-        }
267
-        do_action('AHEE__EEH_Debug_Tools__doing_it_wrong_run', $function, $message, $version);
268
-        $version = $version === null
269
-            ? ''
270
-            : sprintf(
271
-                esc_html__('(This message was added in version %s of Event Espresso)', 'event_espresso'),
272
-                $version
273
-            );
274
-        $error_message = sprintf(
275
-            esc_html__('%1$s was called %2$sincorrectly%3$s. %4$s %5$s', 'event_espresso'),
276
-            $function,
277
-            '<strong>',
278
-            '</strong>',
279
-            $message,
280
-            $version
281
-        );
282
-        // don't trigger error if doing ajax,
283
-        // instead we'll add a transient EE_Error notice that in theory should show on the next request.
284
-        if (defined('DOING_AJAX') && DOING_AJAX) {
285
-            $error_message .= ' ' . esc_html__(
286
-                'This is a doing_it_wrong message that was triggered during an ajax request.  The request params on this request were: ',
287
-                'event_espresso'
288
-            );
289
-            $request = LoaderFactory::getLoader()->getShared(RequestInterface::class);
290
-            $error_message .= '<ul><li>';
291
-            $error_message .= implode('</li><li>', $request->requestParams());
292
-            $error_message .= '</ul>';
293
-            EE_Error::add_error($error_message, 'debug::doing_it_wrong', $function, '42');
294
-            // now we set this on the transient so it shows up on the next request.
295
-            EE_Error::get_notices(false, true);
296
-        } else {
297
-            trigger_error($error_message, $error_type);
298
-        }
299
-    }
300
-
301
-
302
-
303
-
304
-    /**
305
-     * Logger helpers
306
-     */
307
-    /**
308
-     * debug
309
-     *
310
-     * @param string $class
311
-     * @param string $func
312
-     * @param string $line
313
-     * @param array  $info
314
-     * @param bool   $display_request
315
-     * @param string $debug_index
316
-     * @param string $debug_key
317
-     */
318
-    public static function log(
319
-        $class = '',
320
-        $func = '',
321
-        $line = '',
322
-        $info = array(),
323
-        $display_request = false,
324
-        $debug_index = '',
325
-        $debug_key = 'EE_DEBUG_SPCO'
326
-    ) {
327
-        if (WP_DEBUG) {
328
-            $debug_key = $debug_key . '_' . EE_Session::instance()->id();
329
-            $debug_data = get_option($debug_key, array());
330
-            $default_data = array(
331
-                $class => $func . '() : ' . $line,
332
-            );
333
-            // don't serialize objects
334
-            $info = self::strip_objects($info);
335
-            $index = ! empty($debug_index) ? $debug_index : 0;
336
-            if (! isset($debug_data[ $index ])) {
337
-                $debug_data[ $index ] = array();
338
-            }
339
-            $debug_data[ $index ][ microtime() ] = array_merge($default_data, $info);
340
-            update_option($debug_key, $debug_data);
341
-        }
342
-    }
343
-
344
-
345
-
346
-    /**
347
-     * strip_objects
348
-     *
349
-     * @param array $info
350
-     * @return array
351
-     */
352
-    public static function strip_objects($info = array())
353
-    {
354
-        foreach ($info as $key => $value) {
355
-            if (is_array($value)) {
356
-                $info[ $key ] = self::strip_objects($value);
357
-            } elseif (is_object($value)) {
358
-                $object_class = get_class($value);
359
-                $info[ $object_class ] = array();
360
-                $info[ $object_class ]['ID'] = method_exists($value, 'ID') ? $value->ID() : spl_object_hash($value);
361
-                if (method_exists($value, 'ID')) {
362
-                    $info[ $object_class ]['ID'] = $value->ID();
363
-                }
364
-                if (method_exists($value, 'status')) {
365
-                    $info[ $object_class ]['status'] = $value->status();
366
-                } elseif (method_exists($value, 'status_ID')) {
367
-                    $info[ $object_class ]['status'] = $value->status_ID();
368
-                }
369
-                unset($info[ $key ]);
370
-            }
371
-        }
372
-        return (array) $info;
373
-    }
374
-
375
-
376
-
377
-    /**
378
-     * @param mixed      $var
379
-     * @param string     $var_name
380
-     * @param string     $file
381
-     * @param int|string $line
382
-     * @param int|string $heading_tag
383
-     * @param bool       $die
384
-     * @param string     $margin
385
-     */
386
-    public static function printv(
387
-        $var,
388
-        $var_name = '',
389
-        $file = '',
390
-        $line = '',
391
-        $heading_tag = 5,
392
-        $die = false,
393
-        $margin = ''
394
-    ) {
395
-        $var_name = ! $var_name ? 'string' : $var_name;
396
-        $var_name = ucwords(str_replace('$', '', $var_name));
397
-        $is_method = method_exists($var_name, $var);
398
-        $var_name = ucwords(str_replace('_', ' ', $var_name));
399
-        $heading_tag = EEH_Debug_Tools::headingTag($heading_tag);
400
-        $result = EEH_Debug_Tools::headingSpacer($heading_tag);
401
-        $result .= EEH_Debug_Tools::heading($var_name, $heading_tag, $margin, $line);
402
-        $result .= $is_method
403
-            ? EEH_Debug_Tools::grey_span('::') . EEH_Debug_Tools::orange_span($var . '()')
404
-            : EEH_Debug_Tools::grey_span(' : ') . EEH_Debug_Tools::orange_span($var);
405
-        $result .= EEH_Debug_Tools::file_and_line($file, $line, $heading_tag);
406
-        $result .= EEH_Debug_Tools::headingX($heading_tag);
407
-        if ($die) {
408
-            die($result);
409
-        }
410
-        echo wp_kses($result, AllowedTags::getWithFormTags());
411
-    }
412
-
413
-
414
-    protected static function headingTag($heading_tag)
415
-    {
416
-        $heading_tag = absint($heading_tag);
417
-        return $heading_tag > 0 && $heading_tag < 7 ? "h{$heading_tag}" : 'h5';
418
-    }
419
-
420
-    protected static function headingSpacer($heading_tag)
421
-    {
422
-        return EEH_Debug_Tools::plainOutput() && ($heading_tag === 'h1' || $heading_tag === 'h2')
423
-            ? self::lineBreak()
424
-            : '';
425
-    }
426
-
427
-
428
-    protected static function lineBreak()
429
-    {
430
-        return defined('DOING_AJAX') && DOING_AJAX ? '<br />' : "\n";
431
-    }
432
-
433
-
434
-    protected static function plainOutput()
435
-    {
436
-        return defined('EE_TESTS_DIR')
437
-               || (defined('DOING_AJAX') && DOING_AJAX)
438
-               || (
439
-                   isset($_SERVER['REQUEST_URI'])
440
-                   && strpos(parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH), 'wp-json') !== false
441
-               );
442
-    }
443
-
444
-
445
-    /**
446
-     * @param string $var_name
447
-     * @param string $heading_tag
448
-     * @param string $margin
449
-     * @param int    $line
450
-     * @return string
451
-     */
452
-    protected static function heading($var_name = '', $heading_tag = 'h5', $margin = '', $line = 0)
453
-    {
454
-        if (EEH_Debug_Tools::plainOutput()) {
455
-            $heading = '';
456
-            if ($heading_tag === 'h1' || $heading_tag === 'h2') {
457
-                $heading .= self::lineBreak();
458
-            }
459
-            $heading .= self::lineBreak() . "{$line}) {$var_name}";
460
-            return $heading;
461
-        }
462
-        $margin = "25px 0 0 {$margin}";
463
-        return '<' . $heading_tag . ' style="color:#2EA2CC; margin:' . $margin . ';"><b>' . $var_name . '</b>';
464
-    }
465
-
466
-
467
-
468
-    /**
469
-     * @param string $heading_tag
470
-     * @return string
471
-     */
472
-    protected static function headingX($heading_tag = 'h5')
473
-    {
474
-        if (EEH_Debug_Tools::plainOutput()) {
475
-            return '';
476
-        }
477
-        return '</' . $heading_tag . '>';
478
-    }
479
-
480
-
481
-
482
-    /**
483
-     * @param string $content
484
-     * @return string
485
-     */
486
-    protected static function grey_span($content = '')
487
-    {
488
-        if (EEH_Debug_Tools::plainOutput()) {
489
-            return $content;
490
-        }
491
-        return '<span style="color:#999">' . $content . '</span>';
492
-    }
493
-
494
-
495
-
496
-    /**
497
-     * @param string $file
498
-     * @param int    $line
499
-     * @return string
500
-     */
501
-    protected static function file_and_line($file, $line, $heading_tag)
502
-    {
503
-        if ($file === '' || $line === '') {
504
-            return '';
505
-        }
506
-        $file = str_replace(EE_PLUGIN_DIR_PATH, '/', $file);
507
-        if (EEH_Debug_Tools::plainOutput()) {
508
-            if ($heading_tag === 'h1' || $heading_tag === 'h2') {
509
-                return " ({$file})";
510
-            }
511
-            return '';
512
-        }
513
-        return '<br /><span style="font-size:9px;font-weight:normal;color:#666;line-height: 12px;">'
514
-               . $file
515
-               . '<br />line no: '
516
-               . $line
517
-               . '</span>';
518
-    }
519
-
520
-
521
-
522
-    /**
523
-     * @param string $content
524
-     * @return string
525
-     */
526
-    protected static function orange_span($content = '')
527
-    {
528
-        if (EEH_Debug_Tools::plainOutput()) {
529
-            return $content;
530
-        }
531
-        return '<span style="color:#E76700">' . $content . '</span>';
532
-    }
533
-
534
-
535
-
536
-    /**
537
-     * @param mixed $var
538
-     * @return string
539
-     */
540
-    protected static function pre_span($var)
541
-    {
542
-        ob_start();
543
-        var_dump($var);
544
-        $var = ob_get_clean();
545
-        if (EEH_Debug_Tools::plainOutput()) {
546
-            return str_replace("\n", '', $var);
547
-        }
548
-        return '<pre style="color:#999; padding:1em; background: #fff">' . $var . '</pre>';
549
-    }
550
-
551
-
552
-
553
-    /**
554
-     * @param mixed      $var
555
-     * @param string     $var_name
556
-     * @param string     $file
557
-     * @param int|string $line
558
-     * @param int|string $heading_tag
559
-     * @param bool       $die
560
-     */
561
-    public static function printr(
562
-        $var,
563
-        $var_name = '',
564
-        $file = '',
565
-        $line = '',
566
-        $heading_tag = 5,
567
-        $die = false
568
-    ) {
569
-        // return;
570
-        $file = str_replace(rtrim(ABSPATH, '\\/'), '', $file);
571
-        $margin = is_admin() ? ' 180px' : '0';
572
-        if (is_string($var)) {
573
-            EEH_Debug_Tools::printv($var, $var_name, $file, $line, $heading_tag, $die, $margin);
574
-            return;
575
-        }
576
-        if (is_object($var)) {
577
-            $var_name = ! $var_name ? 'object' : $var_name;
578
-        } elseif (is_array($var)) {
579
-            $var_name = ! $var_name ? 'array' : $var_name;
580
-        } elseif (is_numeric($var)) {
581
-            $var_name = ! $var_name ? 'numeric' : $var_name;
582
-        } elseif ($var === null) {
583
-            $var_name = ! $var_name ? 'null' : $var_name;
584
-        }
585
-        $var_name = ucwords(str_replace(array('$', '_'), array('', ' '), $var_name));
586
-        $heading_tag = EEH_Debug_Tools::headingTag($heading_tag);
587
-        $result = EEH_Debug_Tools::headingSpacer($heading_tag);
588
-        $result .= EEH_Debug_Tools::heading($var_name, $heading_tag, $margin, $line);
589
-        $result .= EEH_Debug_Tools::grey_span(' : ') . EEH_Debug_Tools::orange_span(
590
-            EEH_Debug_Tools::pre_span($var)
591
-        );
592
-        $result .= EEH_Debug_Tools::file_and_line($file, $line, $heading_tag);
593
-        $result .= EEH_Debug_Tools::headingX($heading_tag);
594
-        if ($die) {
595
-            die($result);
596
-        }
597
-        echo wp_kses($result, AllowedTags::getWithFormTags());
598
-    }
599
-
600
-
601
-
602
-    /******************** deprecated ********************/
603
-
604
-
605
-
606
-    /**
607
-     * @deprecated 4.9.39.rc.034
608
-     */
609
-    public function reset_times()
610
-    {
611
-        Benchmark::resetTimes();
612
-    }
613
-
614
-
615
-
616
-    /**
617
-     * @deprecated 4.9.39.rc.034
618
-     * @param null $timer_name
619
-     */
620
-    public function start_timer($timer_name = null)
621
-    {
622
-        Benchmark::startTimer($timer_name);
623
-    }
624
-
625
-
626
-
627
-    /**
628
-     * @deprecated 4.9.39.rc.034
629
-     * @param string $timer_name
630
-     */
631
-    public function stop_timer($timer_name = '')
632
-    {
633
-        Benchmark::stopTimer($timer_name);
634
-    }
635
-
636
-
637
-
638
-    /**
639
-     * @deprecated 4.9.39.rc.034
640
-     * @param string  $label      The label to show for this time eg "Start of calling Some_Class::some_function"
641
-     * @param boolean $output_now whether to echo now, or wait until EEH_Debug_Tools::show_times() is called
642
-     * @return void
643
-     */
644
-    public function measure_memory($label, $output_now = false)
645
-    {
646
-        Benchmark::measureMemory($label, $output_now);
647
-    }
648
-
649
-
650
-
651
-    /**
652
-     * @deprecated 4.9.39.rc.034
653
-     * @param int $size
654
-     * @return string
655
-     */
656
-    public function convert($size)
657
-    {
658
-        return Benchmark::convert($size);
659
-    }
660
-
661
-
662
-
663
-    /**
664
-     * @deprecated 4.9.39.rc.034
665
-     * @param bool $output_now
666
-     * @return string
667
-     */
668
-    public function show_times($output_now = true)
669
-    {
670
-        return Benchmark::displayResults($output_now);
671
-    }
672
-
673
-
674
-
675
-    /**
676
-     * @deprecated 4.9.39.rc.034
677
-     * @param string $timer_name
678
-     * @param float  $total_time
679
-     * @return string
680
-     */
681
-    public function format_time($timer_name, $total_time)
682
-    {
683
-        return Benchmark::formatTime($timer_name, $total_time);
684
-    }
18
+	/**
19
+	 *    instance of the EEH_Autoloader object
20
+	 *
21
+	 * @var    $_instance
22
+	 * @access    private
23
+	 */
24
+	private static $_instance;
25
+
26
+	/**
27
+	 * @var array
28
+	 */
29
+	protected $_memory_usage_points = array();
30
+
31
+
32
+
33
+	/**
34
+	 * @singleton method used to instantiate class object
35
+	 * @access    public
36
+	 * @return EEH_Debug_Tools
37
+	 */
38
+	public static function instance()
39
+	{
40
+		// check if class object is instantiated, and instantiated properly
41
+		if (! self::$_instance instanceof EEH_Debug_Tools) {
42
+			self::$_instance = new self();
43
+		}
44
+		return self::$_instance;
45
+	}
46
+
47
+
48
+
49
+	/**
50
+	 * private class constructor
51
+	 */
52
+	private function __construct()
53
+	{
54
+		// load Kint PHP debugging library
55
+		if (
56
+			defined('EE_LOAD_KINT')
57
+			&& ! class_exists('Kint')
58
+			&& file_exists(EE_PLUGIN_DIR_PATH . 'tests/kint/Kint.class.php')
59
+		) {
60
+			// despite EE4 having a check for an existing copy of the Kint debugging class,
61
+			// if another plugin was loaded AFTER EE4 and they did NOT perform a similar check,
62
+			// then hilarity would ensue as PHP throws a "Cannot redeclare class Kint" error
63
+			// so we've moved it to our test folder so that it is not included with production releases
64
+			// plz use https://wordpress.org/plugins/kint-debugger/  if testing production versions of EE
65
+			require_once(EE_PLUGIN_DIR_PATH . 'tests/kint/Kint.class.php');
66
+		}
67
+		$plugin = basename(EE_PLUGIN_DIR_PATH);
68
+		add_action("activate_{$plugin}", array('EEH_Debug_Tools', 'ee_plugin_activation_errors'));
69
+		add_action('activated_plugin', array('EEH_Debug_Tools', 'ee_plugin_activation_errors'));
70
+		add_action('shutdown', array('EEH_Debug_Tools', 'show_db_name'));
71
+	}
72
+
73
+
74
+
75
+	/**
76
+	 *    show_db_name
77
+	 *
78
+	 * @return void
79
+	 */
80
+	public static function show_db_name()
81
+	{
82
+		if (! defined('DOING_AJAX') && (defined('EE_ERROR_EMAILS') && EE_ERROR_EMAILS)) {
83
+			echo '<p style="font-size:10px;font-weight:normal;color:#E76700;margin: 1em 2em; text-align: right;">DB_NAME: '
84
+				 . DB_NAME
85
+				 . '</p>';
86
+		}
87
+		if (EE_DEBUG) {
88
+			Benchmark::displayResults();
89
+		}
90
+	}
91
+
92
+
93
+
94
+	/**
95
+	 *    dump EE_Session object at bottom of page after everything else has happened
96
+	 *
97
+	 * @return void
98
+	 */
99
+	public function espresso_session_footer_dump()
100
+	{
101
+		if (
102
+			(defined('WP_DEBUG') && WP_DEBUG)
103
+			&& ! defined('DOING_AJAX')
104
+			&& class_exists('Kint')
105
+			&& function_exists('wp_get_current_user')
106
+			&& current_user_can('update_core')
107
+			&& class_exists('EE_Registry')
108
+		) {
109
+			Kint::dump(EE_Registry::instance()->SSN->id());
110
+			Kint::dump(EE_Registry::instance()->SSN);
111
+			//          Kint::dump( EE_Registry::instance()->SSN->get_session_data('cart')->get_tickets() );
112
+			$this->espresso_list_hooked_functions();
113
+			Benchmark::displayResults();
114
+		}
115
+	}
116
+
117
+
118
+
119
+	/**
120
+	 *    List All Hooked Functions
121
+	 *    to list all functions for a specific hook, add ee_list_hooks={hook-name} to URL
122
+	 *    http://wp.smashingmagazine.com/2009/08/18/10-useful-wordpress-hook-hacks/
123
+	 *
124
+	 * @param string $tag
125
+	 * @return void
126
+	 */
127
+	public function espresso_list_hooked_functions($tag = '')
128
+	{
129
+		global $wp_filter;
130
+		echo '<br/><br/><br/><h3>Hooked Functions</h3>';
131
+		if ($tag) {
132
+			$hook[ $tag ] = $wp_filter[ $tag ];
133
+			if (! is_array($hook[ $tag ])) {
134
+				trigger_error("Nothing found for '$tag' hook", E_USER_WARNING);
135
+				return;
136
+			}
137
+			echo '<h5>For Tag: ' . esc_html($tag) . '</h5>';
138
+		} else {
139
+			$hook = is_array($wp_filter) ? $wp_filter : array($wp_filter);
140
+			ksort($hook);
141
+		}
142
+		foreach ($hook as $tag_name => $priorities) {
143
+			echo "<br />&gt;&gt;&gt;&gt;&gt;\t<strong>esc_html($tag_name)</strong><br />";
144
+			ksort($priorities);
145
+			foreach ($priorities as $priority => $function) {
146
+				echo esc_html($priority);
147
+				foreach ($function as $name => $properties) {
148
+					$name = esc_html($name);
149
+					echo "\t$name<br />";
150
+				}
151
+			}
152
+		}
153
+	}
154
+
155
+
156
+
157
+	/**
158
+	 *    registered_filter_callbacks
159
+	 *
160
+	 * @param string $hook_name
161
+	 * @return array
162
+	 */
163
+	public static function registered_filter_callbacks($hook_name = '')
164
+	{
165
+		$filters = array();
166
+		global $wp_filter;
167
+		if (isset($wp_filter[ $hook_name ])) {
168
+			$filters[ $hook_name ] = array();
169
+			foreach ($wp_filter[ $hook_name ] as $priority => $callbacks) {
170
+				$filters[ $hook_name ][ $priority ] = array();
171
+				foreach ($callbacks as $callback) {
172
+					$filters[ $hook_name ][ $priority ][] = $callback['function'];
173
+				}
174
+			}
175
+		}
176
+		return $filters;
177
+	}
178
+
179
+
180
+
181
+	/**
182
+	 *    captures plugin activation errors for debugging
183
+	 *
184
+	 * @return void
185
+	 * @throws EE_Error
186
+	 */
187
+	public static function ee_plugin_activation_errors()
188
+	{
189
+		if (WP_DEBUG) {
190
+			$activation_errors = ob_get_contents();
191
+			if (! empty($activation_errors)) {
192
+				$activation_errors = date('Y-m-d H:i:s') . "\n" . $activation_errors;
193
+			}
194
+			espresso_load_required('EEH_File', EE_HELPERS . 'EEH_File.helper.php');
195
+			if (class_exists('EEH_File')) {
196
+				try {
197
+					EEH_File::ensure_file_exists_and_is_writable(
198
+						EVENT_ESPRESSO_UPLOAD_DIR . 'logs/espresso_plugin_activation_errors.html'
199
+					);
200
+					EEH_File::write_to_file(
201
+						EVENT_ESPRESSO_UPLOAD_DIR . 'logs/espresso_plugin_activation_errors.html',
202
+						$activation_errors
203
+					);
204
+				} catch (EE_Error $e) {
205
+					EE_Error::add_error(
206
+						sprintf(
207
+							esc_html__(
208
+								'The Event Espresso activation errors file could not be setup because: %s',
209
+								'event_espresso'
210
+							),
211
+							$e->getMessage()
212
+						),
213
+						__FILE__,
214
+						__FUNCTION__,
215
+						__LINE__
216
+					);
217
+				}
218
+			} else {
219
+				// old school attempt
220
+				file_put_contents(
221
+					EVENT_ESPRESSO_UPLOAD_DIR . 'logs/espresso_plugin_activation_errors.html',
222
+					$activation_errors
223
+				);
224
+			}
225
+			$activation_errors = get_option('ee_plugin_activation_errors', '') . $activation_errors;
226
+			update_option('ee_plugin_activation_errors', $activation_errors);
227
+		}
228
+	}
229
+
230
+
231
+
232
+	/**
233
+	 * This basically mimics the WordPress _doing_it_wrong() function except adds our own messaging etc.
234
+	 * Very useful for providing helpful messages to developers when the method of doing something has been deprecated,
235
+	 * or we want to make sure they use something the right way.
236
+	 *
237
+	 * @access public
238
+	 * @param string $function      The function that was called
239
+	 * @param string $message       A message explaining what has been done incorrectly
240
+	 * @param string $version       The version of Event Espresso where the error was added
241
+	 * @param string $applies_when  a version string for when you want the doing_it_wrong notice to begin appearing
242
+	 *                              for a deprecated function. This allows deprecation to occur during one version,
243
+	 *                              but not have any notices appear until a later version. This allows developers
244
+	 *                              extra time to update their code before notices appear.
245
+	 * @param int    $error_type
246
+	 * @uses   trigger_error()
247
+	 */
248
+	public function doing_it_wrong(
249
+		$function,
250
+		$message,
251
+		$version,
252
+		$applies_when = '',
253
+		$error_type = null
254
+	) {
255
+		$applies_when = ! empty($applies_when) ? $applies_when : espresso_version();
256
+		$error_type = $error_type !== null ? $error_type : E_USER_NOTICE;
257
+		// because we swapped the parameter order around for the last two params,
258
+		// let's verify that some third party isn't still passing an error type value for the third param
259
+		if (is_int($applies_when)) {
260
+			$error_type = $applies_when;
261
+			$applies_when = espresso_version();
262
+		}
263
+		// if not displaying notices yet, then just leave
264
+		if (version_compare(espresso_version(), $applies_when, '<')) {
265
+			return;
266
+		}
267
+		do_action('AHEE__EEH_Debug_Tools__doing_it_wrong_run', $function, $message, $version);
268
+		$version = $version === null
269
+			? ''
270
+			: sprintf(
271
+				esc_html__('(This message was added in version %s of Event Espresso)', 'event_espresso'),
272
+				$version
273
+			);
274
+		$error_message = sprintf(
275
+			esc_html__('%1$s was called %2$sincorrectly%3$s. %4$s %5$s', 'event_espresso'),
276
+			$function,
277
+			'<strong>',
278
+			'</strong>',
279
+			$message,
280
+			$version
281
+		);
282
+		// don't trigger error if doing ajax,
283
+		// instead we'll add a transient EE_Error notice that in theory should show on the next request.
284
+		if (defined('DOING_AJAX') && DOING_AJAX) {
285
+			$error_message .= ' ' . esc_html__(
286
+				'This is a doing_it_wrong message that was triggered during an ajax request.  The request params on this request were: ',
287
+				'event_espresso'
288
+			);
289
+			$request = LoaderFactory::getLoader()->getShared(RequestInterface::class);
290
+			$error_message .= '<ul><li>';
291
+			$error_message .= implode('</li><li>', $request->requestParams());
292
+			$error_message .= '</ul>';
293
+			EE_Error::add_error($error_message, 'debug::doing_it_wrong', $function, '42');
294
+			// now we set this on the transient so it shows up on the next request.
295
+			EE_Error::get_notices(false, true);
296
+		} else {
297
+			trigger_error($error_message, $error_type);
298
+		}
299
+	}
300
+
301
+
302
+
303
+
304
+	/**
305
+	 * Logger helpers
306
+	 */
307
+	/**
308
+	 * debug
309
+	 *
310
+	 * @param string $class
311
+	 * @param string $func
312
+	 * @param string $line
313
+	 * @param array  $info
314
+	 * @param bool   $display_request
315
+	 * @param string $debug_index
316
+	 * @param string $debug_key
317
+	 */
318
+	public static function log(
319
+		$class = '',
320
+		$func = '',
321
+		$line = '',
322
+		$info = array(),
323
+		$display_request = false,
324
+		$debug_index = '',
325
+		$debug_key = 'EE_DEBUG_SPCO'
326
+	) {
327
+		if (WP_DEBUG) {
328
+			$debug_key = $debug_key . '_' . EE_Session::instance()->id();
329
+			$debug_data = get_option($debug_key, array());
330
+			$default_data = array(
331
+				$class => $func . '() : ' . $line,
332
+			);
333
+			// don't serialize objects
334
+			$info = self::strip_objects($info);
335
+			$index = ! empty($debug_index) ? $debug_index : 0;
336
+			if (! isset($debug_data[ $index ])) {
337
+				$debug_data[ $index ] = array();
338
+			}
339
+			$debug_data[ $index ][ microtime() ] = array_merge($default_data, $info);
340
+			update_option($debug_key, $debug_data);
341
+		}
342
+	}
343
+
344
+
345
+
346
+	/**
347
+	 * strip_objects
348
+	 *
349
+	 * @param array $info
350
+	 * @return array
351
+	 */
352
+	public static function strip_objects($info = array())
353
+	{
354
+		foreach ($info as $key => $value) {
355
+			if (is_array($value)) {
356
+				$info[ $key ] = self::strip_objects($value);
357
+			} elseif (is_object($value)) {
358
+				$object_class = get_class($value);
359
+				$info[ $object_class ] = array();
360
+				$info[ $object_class ]['ID'] = method_exists($value, 'ID') ? $value->ID() : spl_object_hash($value);
361
+				if (method_exists($value, 'ID')) {
362
+					$info[ $object_class ]['ID'] = $value->ID();
363
+				}
364
+				if (method_exists($value, 'status')) {
365
+					$info[ $object_class ]['status'] = $value->status();
366
+				} elseif (method_exists($value, 'status_ID')) {
367
+					$info[ $object_class ]['status'] = $value->status_ID();
368
+				}
369
+				unset($info[ $key ]);
370
+			}
371
+		}
372
+		return (array) $info;
373
+	}
374
+
375
+
376
+
377
+	/**
378
+	 * @param mixed      $var
379
+	 * @param string     $var_name
380
+	 * @param string     $file
381
+	 * @param int|string $line
382
+	 * @param int|string $heading_tag
383
+	 * @param bool       $die
384
+	 * @param string     $margin
385
+	 */
386
+	public static function printv(
387
+		$var,
388
+		$var_name = '',
389
+		$file = '',
390
+		$line = '',
391
+		$heading_tag = 5,
392
+		$die = false,
393
+		$margin = ''
394
+	) {
395
+		$var_name = ! $var_name ? 'string' : $var_name;
396
+		$var_name = ucwords(str_replace('$', '', $var_name));
397
+		$is_method = method_exists($var_name, $var);
398
+		$var_name = ucwords(str_replace('_', ' ', $var_name));
399
+		$heading_tag = EEH_Debug_Tools::headingTag($heading_tag);
400
+		$result = EEH_Debug_Tools::headingSpacer($heading_tag);
401
+		$result .= EEH_Debug_Tools::heading($var_name, $heading_tag, $margin, $line);
402
+		$result .= $is_method
403
+			? EEH_Debug_Tools::grey_span('::') . EEH_Debug_Tools::orange_span($var . '()')
404
+			: EEH_Debug_Tools::grey_span(' : ') . EEH_Debug_Tools::orange_span($var);
405
+		$result .= EEH_Debug_Tools::file_and_line($file, $line, $heading_tag);
406
+		$result .= EEH_Debug_Tools::headingX($heading_tag);
407
+		if ($die) {
408
+			die($result);
409
+		}
410
+		echo wp_kses($result, AllowedTags::getWithFormTags());
411
+	}
412
+
413
+
414
+	protected static function headingTag($heading_tag)
415
+	{
416
+		$heading_tag = absint($heading_tag);
417
+		return $heading_tag > 0 && $heading_tag < 7 ? "h{$heading_tag}" : 'h5';
418
+	}
419
+
420
+	protected static function headingSpacer($heading_tag)
421
+	{
422
+		return EEH_Debug_Tools::plainOutput() && ($heading_tag === 'h1' || $heading_tag === 'h2')
423
+			? self::lineBreak()
424
+			: '';
425
+	}
426
+
427
+
428
+	protected static function lineBreak()
429
+	{
430
+		return defined('DOING_AJAX') && DOING_AJAX ? '<br />' : "\n";
431
+	}
432
+
433
+
434
+	protected static function plainOutput()
435
+	{
436
+		return defined('EE_TESTS_DIR')
437
+			   || (defined('DOING_AJAX') && DOING_AJAX)
438
+			   || (
439
+				   isset($_SERVER['REQUEST_URI'])
440
+				   && strpos(parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH), 'wp-json') !== false
441
+			   );
442
+	}
443
+
444
+
445
+	/**
446
+	 * @param string $var_name
447
+	 * @param string $heading_tag
448
+	 * @param string $margin
449
+	 * @param int    $line
450
+	 * @return string
451
+	 */
452
+	protected static function heading($var_name = '', $heading_tag = 'h5', $margin = '', $line = 0)
453
+	{
454
+		if (EEH_Debug_Tools::plainOutput()) {
455
+			$heading = '';
456
+			if ($heading_tag === 'h1' || $heading_tag === 'h2') {
457
+				$heading .= self::lineBreak();
458
+			}
459
+			$heading .= self::lineBreak() . "{$line}) {$var_name}";
460
+			return $heading;
461
+		}
462
+		$margin = "25px 0 0 {$margin}";
463
+		return '<' . $heading_tag . ' style="color:#2EA2CC; margin:' . $margin . ';"><b>' . $var_name . '</b>';
464
+	}
465
+
466
+
467
+
468
+	/**
469
+	 * @param string $heading_tag
470
+	 * @return string
471
+	 */
472
+	protected static function headingX($heading_tag = 'h5')
473
+	{
474
+		if (EEH_Debug_Tools::plainOutput()) {
475
+			return '';
476
+		}
477
+		return '</' . $heading_tag . '>';
478
+	}
479
+
480
+
481
+
482
+	/**
483
+	 * @param string $content
484
+	 * @return string
485
+	 */
486
+	protected static function grey_span($content = '')
487
+	{
488
+		if (EEH_Debug_Tools::plainOutput()) {
489
+			return $content;
490
+		}
491
+		return '<span style="color:#999">' . $content . '</span>';
492
+	}
493
+
494
+
495
+
496
+	/**
497
+	 * @param string $file
498
+	 * @param int    $line
499
+	 * @return string
500
+	 */
501
+	protected static function file_and_line($file, $line, $heading_tag)
502
+	{
503
+		if ($file === '' || $line === '') {
504
+			return '';
505
+		}
506
+		$file = str_replace(EE_PLUGIN_DIR_PATH, '/', $file);
507
+		if (EEH_Debug_Tools::plainOutput()) {
508
+			if ($heading_tag === 'h1' || $heading_tag === 'h2') {
509
+				return " ({$file})";
510
+			}
511
+			return '';
512
+		}
513
+		return '<br /><span style="font-size:9px;font-weight:normal;color:#666;line-height: 12px;">'
514
+			   . $file
515
+			   . '<br />line no: '
516
+			   . $line
517
+			   . '</span>';
518
+	}
519
+
520
+
521
+
522
+	/**
523
+	 * @param string $content
524
+	 * @return string
525
+	 */
526
+	protected static function orange_span($content = '')
527
+	{
528
+		if (EEH_Debug_Tools::plainOutput()) {
529
+			return $content;
530
+		}
531
+		return '<span style="color:#E76700">' . $content . '</span>';
532
+	}
533
+
534
+
535
+
536
+	/**
537
+	 * @param mixed $var
538
+	 * @return string
539
+	 */
540
+	protected static function pre_span($var)
541
+	{
542
+		ob_start();
543
+		var_dump($var);
544
+		$var = ob_get_clean();
545
+		if (EEH_Debug_Tools::plainOutput()) {
546
+			return str_replace("\n", '', $var);
547
+		}
548
+		return '<pre style="color:#999; padding:1em; background: #fff">' . $var . '</pre>';
549
+	}
550
+
551
+
552
+
553
+	/**
554
+	 * @param mixed      $var
555
+	 * @param string     $var_name
556
+	 * @param string     $file
557
+	 * @param int|string $line
558
+	 * @param int|string $heading_tag
559
+	 * @param bool       $die
560
+	 */
561
+	public static function printr(
562
+		$var,
563
+		$var_name = '',
564
+		$file = '',
565
+		$line = '',
566
+		$heading_tag = 5,
567
+		$die = false
568
+	) {
569
+		// return;
570
+		$file = str_replace(rtrim(ABSPATH, '\\/'), '', $file);
571
+		$margin = is_admin() ? ' 180px' : '0';
572
+		if (is_string($var)) {
573
+			EEH_Debug_Tools::printv($var, $var_name, $file, $line, $heading_tag, $die, $margin);
574
+			return;
575
+		}
576
+		if (is_object($var)) {
577
+			$var_name = ! $var_name ? 'object' : $var_name;
578
+		} elseif (is_array($var)) {
579
+			$var_name = ! $var_name ? 'array' : $var_name;
580
+		} elseif (is_numeric($var)) {
581
+			$var_name = ! $var_name ? 'numeric' : $var_name;
582
+		} elseif ($var === null) {
583
+			$var_name = ! $var_name ? 'null' : $var_name;
584
+		}
585
+		$var_name = ucwords(str_replace(array('$', '_'), array('', ' '), $var_name));
586
+		$heading_tag = EEH_Debug_Tools::headingTag($heading_tag);
587
+		$result = EEH_Debug_Tools::headingSpacer($heading_tag);
588
+		$result .= EEH_Debug_Tools::heading($var_name, $heading_tag, $margin, $line);
589
+		$result .= EEH_Debug_Tools::grey_span(' : ') . EEH_Debug_Tools::orange_span(
590
+			EEH_Debug_Tools::pre_span($var)
591
+		);
592
+		$result .= EEH_Debug_Tools::file_and_line($file, $line, $heading_tag);
593
+		$result .= EEH_Debug_Tools::headingX($heading_tag);
594
+		if ($die) {
595
+			die($result);
596
+		}
597
+		echo wp_kses($result, AllowedTags::getWithFormTags());
598
+	}
599
+
600
+
601
+
602
+	/******************** deprecated ********************/
603
+
604
+
605
+
606
+	/**
607
+	 * @deprecated 4.9.39.rc.034
608
+	 */
609
+	public function reset_times()
610
+	{
611
+		Benchmark::resetTimes();
612
+	}
613
+
614
+
615
+
616
+	/**
617
+	 * @deprecated 4.9.39.rc.034
618
+	 * @param null $timer_name
619
+	 */
620
+	public function start_timer($timer_name = null)
621
+	{
622
+		Benchmark::startTimer($timer_name);
623
+	}
624
+
625
+
626
+
627
+	/**
628
+	 * @deprecated 4.9.39.rc.034
629
+	 * @param string $timer_name
630
+	 */
631
+	public function stop_timer($timer_name = '')
632
+	{
633
+		Benchmark::stopTimer($timer_name);
634
+	}
635
+
636
+
637
+
638
+	/**
639
+	 * @deprecated 4.9.39.rc.034
640
+	 * @param string  $label      The label to show for this time eg "Start of calling Some_Class::some_function"
641
+	 * @param boolean $output_now whether to echo now, or wait until EEH_Debug_Tools::show_times() is called
642
+	 * @return void
643
+	 */
644
+	public function measure_memory($label, $output_now = false)
645
+	{
646
+		Benchmark::measureMemory($label, $output_now);
647
+	}
648
+
649
+
650
+
651
+	/**
652
+	 * @deprecated 4.9.39.rc.034
653
+	 * @param int $size
654
+	 * @return string
655
+	 */
656
+	public function convert($size)
657
+	{
658
+		return Benchmark::convert($size);
659
+	}
660
+
661
+
662
+
663
+	/**
664
+	 * @deprecated 4.9.39.rc.034
665
+	 * @param bool $output_now
666
+	 * @return string
667
+	 */
668
+	public function show_times($output_now = true)
669
+	{
670
+		return Benchmark::displayResults($output_now);
671
+	}
672
+
673
+
674
+
675
+	/**
676
+	 * @deprecated 4.9.39.rc.034
677
+	 * @param string $timer_name
678
+	 * @param float  $total_time
679
+	 * @return string
680
+	 */
681
+	public function format_time($timer_name, $total_time)
682
+	{
683
+		return Benchmark::formatTime($timer_name, $total_time);
684
+	}
685 685
 }
686 686
 
687 687
 
@@ -691,31 +691,31 @@  discard block
 block discarded – undo
691 691
  * Plugin URI: http://upthemes.com/plugins/kint-debugger/
692 692
  */
693 693
 if (class_exists('Kint') && ! function_exists('dump_wp_query')) {
694
-    function dump_wp_query()
695
-    {
696
-        global $wp_query;
697
-        d($wp_query);
698
-    }
694
+	function dump_wp_query()
695
+	{
696
+		global $wp_query;
697
+		d($wp_query);
698
+	}
699 699
 }
700 700
 /**
701 701
  * borrowed from Kint Debugger
702 702
  * Plugin URI: http://upthemes.com/plugins/kint-debugger/
703 703
  */
704 704
 if (class_exists('Kint') && ! function_exists('dump_wp')) {
705
-    function dump_wp()
706
-    {
707
-        global $wp;
708
-        d($wp);
709
-    }
705
+	function dump_wp()
706
+	{
707
+		global $wp;
708
+		d($wp);
709
+	}
710 710
 }
711 711
 /**
712 712
  * borrowed from Kint Debugger
713 713
  * Plugin URI: http://upthemes.com/plugins/kint-debugger/
714 714
  */
715 715
 if (class_exists('Kint') && ! function_exists('dump_post')) {
716
-    function dump_post()
717
-    {
718
-        global $post;
719
-        d($post);
720
-    }
716
+	function dump_post()
717
+	{
718
+		global $post;
719
+		d($post);
720
+	}
721 721
 }
Please login to merge, or discard this patch.
core/db_classes/EE_Event.class.php 2 patches
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -73,7 +73,7 @@  discard block
 block discarded – undo
73 73
      */
74 74
     public function getAvailableSpacesCalculator()
75 75
     {
76
-        if (! $this->available_spaces_calculator instanceof EventSpacesCalculator) {
76
+        if ( ! $this->available_spaces_calculator instanceof EventSpacesCalculator) {
77 77
             $this->available_spaces_calculator = new EventSpacesCalculator($this);
78 78
         }
79 79
         return $this->available_spaces_calculator;
@@ -223,7 +223,7 @@  discard block
 block discarded – undo
223 223
      */
224 224
     public function primary_datetime($try_to_exclude_expired = true, $try_to_exclude_deleted = true)
225 225
     {
226
-        if (! empty($this->_Primary_Datetime)) {
226
+        if ( ! empty($this->_Primary_Datetime)) {
227 227
             return $this->_Primary_Datetime;
228 228
         }
229 229
         $this->_Primary_Datetime = EEM_Datetime::instance($this->_timezone)->get_primary_datetime_for_event(
@@ -248,7 +248,7 @@  discard block
 block discarded – undo
248 248
     {
249 249
         // first get all datetimes
250 250
         $datetimes = $this->datetimes_ordered();
251
-        if (! $datetimes) {
251
+        if ( ! $datetimes) {
252 252
             return array();
253 253
         }
254 254
         $datetime_ids = array();
@@ -456,7 +456,7 @@  discard block
 block discarded – undo
456 456
     public function short_description($num_words = 55, $more = null, $not_full_desc = false)
457 457
     {
458 458
         $short_desc = $this->get('EVT_short_desc');
459
-        if (! empty($short_desc) || $not_full_desc) {
459
+        if ( ! empty($short_desc) || $not_full_desc) {
460 460
             return $short_desc;
461 461
         }
462 462
         $full_desc = $this->get('EVT_desc');
@@ -924,7 +924,7 @@  discard block
 block discarded – undo
924 924
         );
925 925
         $all_expired = true;
926 926
         foreach ($tickets as $ticket) {
927
-            if (! $ticket->is_expired()) {
927
+            if ( ! $ticket->is_expired()) {
928 928
                 $all_expired = false;
929 929
                 break;
930 930
             }
@@ -1015,7 +1015,7 @@  discard block
 block discarded – undo
1015 1015
      */
1016 1016
     public function is_sold_out($actual = false)
1017 1017
     {
1018
-        if (! $actual) {
1018
+        if ( ! $actual) {
1019 1019
             return $this->status() === EEM_Event::sold_out;
1020 1020
         }
1021 1021
         return $this->perform_sold_out_status_check();
@@ -1061,11 +1061,11 @@  discard block
 block discarded – undo
1061 1061
     public function get_active_status($reset = false)
1062 1062
     {
1063 1063
         // if the active status has already been set, then just use that value (unless we are resetting it)
1064
-        if (! empty($this->_active_status) && ! $reset) {
1064
+        if ( ! empty($this->_active_status) && ! $reset) {
1065 1065
             return $this->_active_status;
1066 1066
         }
1067 1067
         // first check if event id is present on this object
1068
-        if (! $this->ID()) {
1068
+        if ( ! $this->ID()) {
1069 1069
             return false;
1070 1070
         }
1071 1071
         $where_params_for_event = array(array('EVT_ID' => $this->ID()));
@@ -1136,7 +1136,7 @@  discard block
 block discarded – undo
1136 1136
     public function pretty_active_status($echo = true)
1137 1137
     {
1138 1138
         $active_status = $this->get_active_status();
1139
-        $status = '<span class="ee-status event-active-status-' . esc_attr($active_status) . '">'
1139
+        $status = '<span class="ee-status event-active-status-'.esc_attr($active_status).'">'
1140 1140
                   . EEH_Template::pretty_status($active_status, false, 'sentence')
1141 1141
                   . '</span>';
1142 1142
         if ($echo) {
@@ -1155,7 +1155,7 @@  discard block
 block discarded – undo
1155 1155
     public function get_number_of_tickets_sold()
1156 1156
     {
1157 1157
         $tkt_sold = 0;
1158
-        if (! $this->ID()) {
1158
+        if ( ! $this->ID()) {
1159 1159
             return 0;
1160 1160
         }
1161 1161
         $datetimes = $this->datetimes();
@@ -1345,7 +1345,7 @@  discard block
 block discarded – undo
1345 1345
             ]
1346 1346
         );
1347 1347
         $field_to_update = EEM_Event_Question_Group::instance()->fieldNameForContext($for_primary);
1348
-        $other_field = EEM_Event_Question_Group::instance()->fieldNameForContext(! $for_primary);
1348
+        $other_field = EEM_Event_Question_Group::instance()->fieldNameForContext( ! $for_primary);
1349 1349
         if ($existing_relation->get($other_field) === false) {
1350 1350
             // Delete it. It's now no longer for primary or additional question groups.
1351 1351
             return $this->_remove_relation_to($question_group_id_or_obj, 'Question_Group');
Please login to merge, or discard this patch.
Indentation   +1439 added lines, -1439 removed lines patch added patch discarded remove patch
@@ -15,1443 +15,1443 @@
 block discarded – undo
15 15
  */
16 16
 class EE_Event extends EE_CPT_Base implements EEI_Line_Item_Object, EEI_Admin_Links, EEI_Has_Icon, EEI_Event
17 17
 {
18
-    /**
19
-     * cached value for the the logical active status for the event
20
-     *
21
-     * @see get_active_status()
22
-     * @var string
23
-     */
24
-    protected $_active_status = '';
25
-
26
-    /**
27
-     * This is just used for caching the Primary Datetime for the Event on initial retrieval
28
-     *
29
-     * @var EE_Datetime
30
-     */
31
-    protected $_Primary_Datetime;
32
-
33
-    /**
34
-     * @var EventSpacesCalculator $available_spaces_calculator
35
-     */
36
-    protected $available_spaces_calculator;
37
-
38
-
39
-    /**
40
-     * @param array  $props_n_values          incoming values
41
-     * @param string $timezone                incoming timezone (if not set the timezone set for the website will be
42
-     *                                        used.)
43
-     * @param array  $date_formats            incoming date_formats in an array where the first value is the
44
-     *                                        date_format and the second value is the time format
45
-     * @return EE_Event
46
-     * @throws EE_Error
47
-     * @throws ReflectionException
48
-     */
49
-    public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array())
50
-    {
51
-        $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats);
52
-        return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats);
53
-    }
54
-
55
-
56
-    /**
57
-     * @param array  $props_n_values  incoming values from the database
58
-     * @param string $timezone        incoming timezone as set by the model.  If not set the timezone for
59
-     *                                the website will be used.
60
-     * @return EE_Event
61
-     * @throws EE_Error
62
-     * @throws ReflectionException
63
-     */
64
-    public static function new_instance_from_db($props_n_values = array(), $timezone = null)
65
-    {
66
-        return new self($props_n_values, true, $timezone);
67
-    }
68
-
69
-
70
-    /**
71
-     * @return EventSpacesCalculator
72
-     * @throws \EE_Error
73
-     */
74
-    public function getAvailableSpacesCalculator()
75
-    {
76
-        if (! $this->available_spaces_calculator instanceof EventSpacesCalculator) {
77
-            $this->available_spaces_calculator = new EventSpacesCalculator($this);
78
-        }
79
-        return $this->available_spaces_calculator;
80
-    }
81
-
82
-
83
-    /**
84
-     * Overrides parent set() method so that all calls to set( 'status', $status ) can be routed to internal methods
85
-     *
86
-     * @param string $field_name
87
-     * @param mixed  $field_value
88
-     * @param bool   $use_default
89
-     * @throws EE_Error
90
-     * @throws ReflectionException
91
-     */
92
-    public function set($field_name, $field_value, $use_default = false)
93
-    {
94
-        switch ($field_name) {
95
-            case 'status':
96
-                $this->set_status($field_value, $use_default);
97
-                break;
98
-            default:
99
-                parent::set($field_name, $field_value, $use_default);
100
-        }
101
-    }
102
-
103
-
104
-    /**
105
-     *    set_status
106
-     * Checks if event status is being changed to SOLD OUT
107
-     * and updates event meta data with previous event status
108
-     * so that we can revert things if/when the event is no longer sold out
109
-     *
110
-     * @access public
111
-     * @param string $new_status
112
-     * @param bool   $use_default
113
-     * @return void
114
-     * @throws EE_Error
115
-     * @throws ReflectionException
116
-     */
117
-    public function set_status($new_status = null, $use_default = false)
118
-    {
119
-        // if nothing is set, and we aren't explicitly wanting to reset the status, then just leave
120
-        if (empty($new_status) && ! $use_default) {
121
-            return;
122
-        }
123
-        // get current Event status
124
-        $old_status = $this->status();
125
-        // if status has changed
126
-        if ($old_status !== $new_status) {
127
-            // TO sold_out
128
-            if ($new_status === EEM_Event::sold_out) {
129
-                // save the previous event status so that we can revert if the event is no longer sold out
130
-                $this->add_post_meta('_previous_event_status', $old_status);
131
-                do_action('AHEE__EE_Event__set_status__to_sold_out', $this, $old_status, $new_status);
132
-                // OR FROM  sold_out
133
-            } elseif ($old_status === EEM_Event::sold_out) {
134
-                $this->delete_post_meta('_previous_event_status');
135
-                do_action('AHEE__EE_Event__set_status__from_sold_out', $this, $old_status, $new_status);
136
-            }
137
-            // clear out the active status so that it gets reset the next time it is requested
138
-            $this->_active_status = null;
139
-            // update status
140
-            parent::set('status', $new_status, $use_default);
141
-            do_action('AHEE__EE_Event__set_status__after_update', $this);
142
-            return;
143
-        }
144
-        // even though the old value matches the new value, it's still good to
145
-        // allow the parent set method to have a say
146
-        parent::set('status', $new_status, $use_default);
147
-    }
148
-
149
-
150
-    /**
151
-     * Gets all the datetimes for this event
152
-     *
153
-     * @param array $query_params @see
154
-     *                            https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
155
-     * @return EE_Base_Class[]|EE_Datetime[]
156
-     * @throws EE_Error
157
-     * @throws ReflectionException
158
-     */
159
-    public function datetimes($query_params = array())
160
-    {
161
-        return $this->get_many_related('Datetime', $query_params);
162
-    }
163
-
164
-
165
-    /**
166
-     * Gets all the datetimes for this event, ordered by DTT_EVT_start in ascending order
167
-     *
168
-     * @return EE_Base_Class[]|EE_Datetime[]
169
-     * @throws EE_Error
170
-     * @throws ReflectionException
171
-     */
172
-    public function datetimes_in_chronological_order()
173
-    {
174
-        return $this->get_many_related('Datetime', array('order_by' => array('DTT_EVT_start' => 'ASC')));
175
-    }
176
-
177
-
178
-    /**
179
-     * Gets all the datetimes for this event, ordered by the DTT_order on the datetime.
180
-     * @darren, we should probably UNSET timezone on the EEM_Datetime model
181
-     * after running our query, so that this timezone isn't set for EVERY query
182
-     * on EEM_Datetime for the rest of the request, no?
183
-     *
184
-     * @param boolean $show_expired whether or not to include expired events
185
-     * @param boolean $show_deleted whether or not to include deleted events
186
-     * @param null    $limit
187
-     * @return EE_Datetime[]
188
-     * @throws EE_Error
189
-     * @throws ReflectionException
190
-     */
191
-    public function datetimes_ordered($show_expired = true, $show_deleted = false, $limit = null)
192
-    {
193
-        return EEM_Datetime::instance($this->_timezone)->get_datetimes_for_event_ordered_by_DTT_order(
194
-            $this->ID(),
195
-            $show_expired,
196
-            $show_deleted,
197
-            $limit
198
-        );
199
-    }
200
-
201
-
202
-    /**
203
-     * Returns one related datetime. Mostly only used by some legacy code.
204
-     *
205
-     * @return EE_Base_Class|EE_Datetime
206
-     * @throws EE_Error
207
-     * @throws ReflectionException
208
-     */
209
-    public function first_datetime()
210
-    {
211
-        return $this->get_first_related('Datetime');
212
-    }
213
-
214
-
215
-    /**
216
-     * Returns the 'primary' datetime for the event
217
-     *
218
-     * @param bool $try_to_exclude_expired
219
-     * @param bool $try_to_exclude_deleted
220
-     * @return EE_Datetime
221
-     * @throws EE_Error
222
-     * @throws ReflectionException
223
-     */
224
-    public function primary_datetime($try_to_exclude_expired = true, $try_to_exclude_deleted = true)
225
-    {
226
-        if (! empty($this->_Primary_Datetime)) {
227
-            return $this->_Primary_Datetime;
228
-        }
229
-        $this->_Primary_Datetime = EEM_Datetime::instance($this->_timezone)->get_primary_datetime_for_event(
230
-            $this->ID(),
231
-            $try_to_exclude_expired,
232
-            $try_to_exclude_deleted
233
-        );
234
-        return $this->_Primary_Datetime;
235
-    }
236
-
237
-
238
-    /**
239
-     * Gets all the tickets available for purchase of this event
240
-     *
241
-     * @param array $query_params @see
242
-     *                            https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
243
-     * @return EE_Base_Class[]|EE_Ticket[]
244
-     * @throws EE_Error
245
-     * @throws ReflectionException
246
-     */
247
-    public function tickets($query_params = array())
248
-    {
249
-        // first get all datetimes
250
-        $datetimes = $this->datetimes_ordered();
251
-        if (! $datetimes) {
252
-            return array();
253
-        }
254
-        $datetime_ids = array();
255
-        foreach ($datetimes as $datetime) {
256
-            $datetime_ids[] = $datetime->ID();
257
-        }
258
-        $where_params = array('Datetime.DTT_ID' => array('IN', $datetime_ids));
259
-        // if incoming $query_params has where conditions let's merge but not override existing.
260
-        if (is_array($query_params) && isset($query_params[0])) {
261
-            $where_params = array_merge($query_params[0], $where_params);
262
-            unset($query_params[0]);
263
-        }
264
-        // now add $where_params to $query_params
265
-        $query_params[0] = $where_params;
266
-        return EEM_Ticket::instance()->get_all($query_params);
267
-    }
268
-
269
-
270
-    /**
271
-     * get all unexpired untrashed tickets
272
-     *
273
-     * @return EE_Ticket[]
274
-     * @throws EE_Error
275
-     */
276
-    public function active_tickets()
277
-    {
278
-        return $this->tickets(
279
-            array(
280
-                array(
281
-                    'TKT_end_date' => array('>=', EEM_Ticket::instance()->current_time_for_query('TKT_end_date')),
282
-                    'TKT_deleted'  => false,
283
-                ),
284
-            )
285
-        );
286
-    }
287
-
288
-
289
-    /**
290
-     * @return bool
291
-     * @throws EE_Error
292
-     * @throws ReflectionException
293
-     */
294
-    public function additional_limit()
295
-    {
296
-        return $this->get('EVT_additional_limit');
297
-    }
298
-
299
-
300
-    /**
301
-     * @return bool
302
-     * @throws EE_Error
303
-     * @throws ReflectionException
304
-     */
305
-    public function allow_overflow()
306
-    {
307
-        return $this->get('EVT_allow_overflow');
308
-    }
309
-
310
-
311
-    /**
312
-     * @return bool
313
-     * @throws EE_Error
314
-     * @throws ReflectionException
315
-     */
316
-    public function created()
317
-    {
318
-        return $this->get('EVT_created');
319
-    }
320
-
321
-
322
-    /**
323
-     * @return bool
324
-     * @throws EE_Error
325
-     * @throws ReflectionException
326
-     */
327
-    public function description()
328
-    {
329
-        return $this->get('EVT_desc');
330
-    }
331
-
332
-
333
-    /**
334
-     * Runs do_shortcode and wpautop on the description
335
-     *
336
-     * @return string of html
337
-     * @throws EE_Error
338
-     * @throws ReflectionException
339
-     */
340
-    public function description_filtered()
341
-    {
342
-        return $this->get_pretty('EVT_desc');
343
-    }
344
-
345
-
346
-    /**
347
-     * @return bool
348
-     * @throws EE_Error
349
-     * @throws ReflectionException
350
-     */
351
-    public function display_description()
352
-    {
353
-        return $this->get('EVT_display_desc');
354
-    }
355
-
356
-
357
-    /**
358
-     * @return bool
359
-     * @throws EE_Error
360
-     * @throws ReflectionException
361
-     */
362
-    public function display_ticket_selector()
363
-    {
364
-        return (bool) $this->get('EVT_display_ticket_selector');
365
-    }
366
-
367
-
368
-    /**
369
-     * @return string
370
-     * @throws EE_Error
371
-     * @throws ReflectionException
372
-     */
373
-    public function external_url()
374
-    {
375
-        return $this->get('EVT_external_URL');
376
-    }
377
-
378
-
379
-    /**
380
-     * @return bool
381
-     * @throws EE_Error
382
-     * @throws ReflectionException
383
-     */
384
-    public function member_only()
385
-    {
386
-        return $this->get('EVT_member_only');
387
-    }
388
-
389
-
390
-    /**
391
-     * @return bool
392
-     * @throws EE_Error
393
-     * @throws ReflectionException
394
-     */
395
-    public function phone()
396
-    {
397
-        return $this->get('EVT_phone');
398
-    }
399
-
400
-
401
-    /**
402
-     * @return bool
403
-     * @throws EE_Error
404
-     * @throws ReflectionException
405
-     */
406
-    public function modified()
407
-    {
408
-        return $this->get('EVT_modified');
409
-    }
410
-
411
-
412
-    /**
413
-     * @return bool
414
-     * @throws EE_Error
415
-     * @throws ReflectionException
416
-     */
417
-    public function name()
418
-    {
419
-        return $this->get('EVT_name');
420
-    }
421
-
422
-
423
-    /**
424
-     * @return bool
425
-     * @throws EE_Error
426
-     * @throws ReflectionException
427
-     */
428
-    public function order()
429
-    {
430
-        return $this->get('EVT_order');
431
-    }
432
-
433
-
434
-    /**
435
-     * @return bool|string
436
-     * @throws EE_Error
437
-     * @throws ReflectionException
438
-     */
439
-    public function default_registration_status()
440
-    {
441
-        $event_default_registration_status = $this->get('EVT_default_registration_status');
442
-        return ! empty($event_default_registration_status)
443
-            ? $event_default_registration_status
444
-            : EE_Registry::instance()->CFG->registration->default_STS_ID;
445
-    }
446
-
447
-
448
-    /**
449
-     * @param int  $num_words
450
-     * @param null $more
451
-     * @param bool $not_full_desc
452
-     * @return bool|string
453
-     * @throws EE_Error
454
-     * @throws ReflectionException
455
-     */
456
-    public function short_description($num_words = 55, $more = null, $not_full_desc = false)
457
-    {
458
-        $short_desc = $this->get('EVT_short_desc');
459
-        if (! empty($short_desc) || $not_full_desc) {
460
-            return $short_desc;
461
-        }
462
-        $full_desc = $this->get('EVT_desc');
463
-        return wp_trim_words($full_desc, $num_words, $more);
464
-    }
465
-
466
-
467
-    /**
468
-     * @return bool
469
-     * @throws EE_Error
470
-     * @throws ReflectionException
471
-     */
472
-    public function slug()
473
-    {
474
-        return $this->get('EVT_slug');
475
-    }
476
-
477
-
478
-    /**
479
-     * @return bool
480
-     * @throws EE_Error
481
-     * @throws ReflectionException
482
-     */
483
-    public function timezone_string()
484
-    {
485
-        return $this->get('EVT_timezone_string');
486
-    }
487
-
488
-
489
-    /**
490
-     * @return bool
491
-     * @throws EE_Error
492
-     * @throws ReflectionException
493
-     */
494
-    public function visible_on()
495
-    {
496
-        return $this->get('EVT_visible_on');
497
-    }
498
-
499
-
500
-    /**
501
-     * @return int
502
-     * @throws EE_Error
503
-     * @throws ReflectionException
504
-     */
505
-    public function wp_user()
506
-    {
507
-        return $this->get('EVT_wp_user');
508
-    }
509
-
510
-
511
-    /**
512
-     * @return bool
513
-     * @throws EE_Error
514
-     * @throws ReflectionException
515
-     */
516
-    public function donations()
517
-    {
518
-        return $this->get('EVT_donations');
519
-    }
520
-
521
-
522
-    /**
523
-     * @param $limit
524
-     * @throws EE_Error
525
-     */
526
-    public function set_additional_limit($limit)
527
-    {
528
-        $this->set('EVT_additional_limit', $limit);
529
-    }
530
-
531
-
532
-    /**
533
-     * @param $created
534
-     * @throws EE_Error
535
-     */
536
-    public function set_created($created)
537
-    {
538
-        $this->set('EVT_created', $created);
539
-    }
540
-
541
-
542
-    /**
543
-     * @param $desc
544
-     * @throws EE_Error
545
-     */
546
-    public function set_description($desc)
547
-    {
548
-        $this->set('EVT_desc', $desc);
549
-    }
550
-
551
-
552
-    /**
553
-     * @param $display_desc
554
-     * @throws EE_Error
555
-     */
556
-    public function set_display_description($display_desc)
557
-    {
558
-        $this->set('EVT_display_desc', $display_desc);
559
-    }
560
-
561
-
562
-    /**
563
-     * @param $display_ticket_selector
564
-     * @throws EE_Error
565
-     */
566
-    public function set_display_ticket_selector($display_ticket_selector)
567
-    {
568
-        $this->set('EVT_display_ticket_selector', $display_ticket_selector);
569
-    }
570
-
571
-
572
-    /**
573
-     * @param $external_url
574
-     * @throws EE_Error
575
-     */
576
-    public function set_external_url($external_url)
577
-    {
578
-        $this->set('EVT_external_URL', $external_url);
579
-    }
580
-
581
-
582
-    /**
583
-     * @param $member_only
584
-     * @throws EE_Error
585
-     */
586
-    public function set_member_only($member_only)
587
-    {
588
-        $this->set('EVT_member_only', $member_only);
589
-    }
590
-
591
-
592
-    /**
593
-     * @param $event_phone
594
-     * @throws EE_Error
595
-     */
596
-    public function set_event_phone($event_phone)
597
-    {
598
-        $this->set('EVT_phone', $event_phone);
599
-    }
600
-
601
-
602
-    /**
603
-     * @param $modified
604
-     * @throws EE_Error
605
-     */
606
-    public function set_modified($modified)
607
-    {
608
-        $this->set('EVT_modified', $modified);
609
-    }
610
-
611
-
612
-    /**
613
-     * @param $name
614
-     * @throws EE_Error
615
-     */
616
-    public function set_name($name)
617
-    {
618
-        $this->set('EVT_name', $name);
619
-    }
620
-
621
-
622
-    /**
623
-     * @param $order
624
-     * @throws EE_Error
625
-     */
626
-    public function set_order($order)
627
-    {
628
-        $this->set('EVT_order', $order);
629
-    }
630
-
631
-
632
-    /**
633
-     * @param $short_desc
634
-     * @throws EE_Error
635
-     */
636
-    public function set_short_description($short_desc)
637
-    {
638
-        $this->set('EVT_short_desc', $short_desc);
639
-    }
640
-
641
-
642
-    /**
643
-     * @param $slug
644
-     * @throws EE_Error
645
-     */
646
-    public function set_slug($slug)
647
-    {
648
-        $this->set('EVT_slug', $slug);
649
-    }
650
-
651
-
652
-    /**
653
-     * @param $timezone_string
654
-     * @throws EE_Error
655
-     */
656
-    public function set_timezone_string($timezone_string)
657
-    {
658
-        $this->set('EVT_timezone_string', $timezone_string);
659
-    }
660
-
661
-
662
-    /**
663
-     * @param $visible_on
664
-     * @throws EE_Error
665
-     */
666
-    public function set_visible_on($visible_on)
667
-    {
668
-        $this->set('EVT_visible_on', $visible_on);
669
-    }
670
-
671
-
672
-    /**
673
-     * @param $wp_user
674
-     * @throws EE_Error
675
-     */
676
-    public function set_wp_user($wp_user)
677
-    {
678
-        $this->set('EVT_wp_user', $wp_user);
679
-    }
680
-
681
-
682
-    /**
683
-     * @param $default_registration_status
684
-     * @throws EE_Error
685
-     */
686
-    public function set_default_registration_status($default_registration_status)
687
-    {
688
-        $this->set('EVT_default_registration_status', $default_registration_status);
689
-    }
690
-
691
-
692
-    /**
693
-     * @param $donations
694
-     * @throws EE_Error
695
-     */
696
-    public function set_donations($donations)
697
-    {
698
-        $this->set('EVT_donations', $donations);
699
-    }
700
-
701
-
702
-    /**
703
-     * Adds a venue to this event
704
-     *
705
-     * @param EE_Venue /int $venue_id_or_obj
706
-     * @return EE_Base_Class|EE_Venue
707
-     * @throws EE_Error
708
-     * @throws ReflectionException
709
-     */
710
-    public function add_venue($venue_id_or_obj)
711
-    {
712
-        return $this->_add_relation_to($venue_id_or_obj, 'Venue');
713
-    }
714
-
715
-
716
-    /**
717
-     * Removes a venue from the event
718
-     *
719
-     * @param EE_Venue /int $venue_id_or_obj
720
-     * @return EE_Base_Class|EE_Venue
721
-     * @throws EE_Error
722
-     * @throws ReflectionException
723
-     */
724
-    public function remove_venue($venue_id_or_obj)
725
-    {
726
-        return $this->_remove_relation_to($venue_id_or_obj, 'Venue');
727
-    }
728
-
729
-
730
-    /**
731
-     * Gets all the venues related ot the event. May provide additional $query_params if desired
732
-     *
733
-     * @param array $query_params @see
734
-     *                            https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
735
-     * @return EE_Base_Class[]|EE_Venue[]
736
-     * @throws EE_Error
737
-     * @throws ReflectionException
738
-     */
739
-    public function venues($query_params = array())
740
-    {
741
-        return $this->get_many_related('Venue', $query_params);
742
-    }
743
-
744
-
745
-    /**
746
-     * check if event id is present and if event is published
747
-     *
748
-     * @access public
749
-     * @return boolean true yes, false no
750
-     * @throws EE_Error
751
-     * @throws ReflectionException
752
-     */
753
-    private function _has_ID_and_is_published()
754
-    {
755
-        // first check if event id is present and not NULL,
756
-        // then check if this event is published (or any of the equivalent "published" statuses)
757
-        return
758
-            $this->ID() && $this->ID() !== null
759
-            && (
760
-                $this->status() === 'publish'
761
-                || $this->status() === EEM_Event::sold_out
762
-                || $this->status() === EEM_Event::postponed
763
-                || $this->status() === EEM_Event::cancelled
764
-            );
765
-    }
766
-
767
-
768
-    /**
769
-     * This simply compares the internal dates with NOW and determines if the event is upcoming or not.
770
-     *
771
-     * @access public
772
-     * @return boolean true yes, false no
773
-     * @throws EE_Error
774
-     * @throws ReflectionException
775
-     */
776
-    public function is_upcoming()
777
-    {
778
-        // check if event id is present and if this event is published
779
-        if ($this->is_inactive()) {
780
-            return false;
781
-        }
782
-        // set initial value
783
-        $upcoming = false;
784
-        // next let's get all datetimes and loop through them
785
-        $datetimes = $this->datetimes_in_chronological_order();
786
-        foreach ($datetimes as $datetime) {
787
-            if ($datetime instanceof EE_Datetime) {
788
-                // if this dtt is expired then we continue cause one of the other datetimes might be upcoming.
789
-                if ($datetime->is_expired()) {
790
-                    continue;
791
-                }
792
-                // if this dtt is active then we return false.
793
-                if ($datetime->is_active()) {
794
-                    return false;
795
-                }
796
-                // otherwise let's check upcoming status
797
-                $upcoming = $datetime->is_upcoming();
798
-            }
799
-        }
800
-        return $upcoming;
801
-    }
802
-
803
-
804
-    /**
805
-     * @return bool
806
-     * @throws EE_Error
807
-     * @throws ReflectionException
808
-     */
809
-    public function is_active()
810
-    {
811
-        // check if event id is present and if this event is published
812
-        if ($this->is_inactive()) {
813
-            return false;
814
-        }
815
-        // set initial value
816
-        $active = false;
817
-        // next let's get all datetimes and loop through them
818
-        $datetimes = $this->datetimes_in_chronological_order();
819
-        foreach ($datetimes as $datetime) {
820
-            if ($datetime instanceof EE_Datetime) {
821
-                // if this dtt is expired then we continue cause one of the other datetimes might be active.
822
-                if ($datetime->is_expired()) {
823
-                    continue;
824
-                }
825
-                // if this dtt is upcoming then we return false.
826
-                if ($datetime->is_upcoming()) {
827
-                    return false;
828
-                }
829
-                // otherwise let's check active status
830
-                $active = $datetime->is_active();
831
-            }
832
-        }
833
-        return $active;
834
-    }
835
-
836
-
837
-    /**
838
-     * @return bool
839
-     * @throws EE_Error
840
-     * @throws ReflectionException
841
-     */
842
-    public function is_expired()
843
-    {
844
-        // check if event id is present and if this event is published
845
-        if ($this->is_inactive()) {
846
-            return false;
847
-        }
848
-        // set initial value
849
-        $expired = false;
850
-        // first let's get all datetimes and loop through them
851
-        $datetimes = $this->datetimes_in_chronological_order();
852
-        foreach ($datetimes as $datetime) {
853
-            if ($datetime instanceof EE_Datetime) {
854
-                // if this dtt is upcoming or active then we return false.
855
-                if ($datetime->is_upcoming() || $datetime->is_active()) {
856
-                    return false;
857
-                }
858
-                // otherwise let's check active status
859
-                $expired = $datetime->is_expired();
860
-            }
861
-        }
862
-        return $expired;
863
-    }
864
-
865
-
866
-    /**
867
-     * @return bool
868
-     * @throws EE_Error
869
-     */
870
-    public function is_inactive()
871
-    {
872
-        // check if event id is present and if this event is published
873
-        if ($this->_has_ID_and_is_published()) {
874
-            return false;
875
-        }
876
-        return true;
877
-    }
878
-
879
-
880
-    /**
881
-     * calculate spaces remaining based on "saleable" tickets
882
-     *
883
-     * @param array $tickets
884
-     * @param bool  $filtered
885
-     * @return int|float
886
-     * @throws EE_Error
887
-     * @throws DomainException
888
-     * @throws UnexpectedEntityException
889
-     */
890
-    public function spaces_remaining($tickets = array(), $filtered = true)
891
-    {
892
-        $this->getAvailableSpacesCalculator()->setActiveTickets($tickets);
893
-        $spaces_remaining = $this->getAvailableSpacesCalculator()->spacesRemaining();
894
-        return $filtered
895
-            ? apply_filters(
896
-                'FHEE_EE_Event__spaces_remaining',
897
-                $spaces_remaining,
898
-                $this,
899
-                $tickets
900
-            )
901
-            : $spaces_remaining;
902
-    }
903
-
904
-
905
-    /**
906
-     *    perform_sold_out_status_check
907
-     *    checks all of this events's datetime  reg_limit - sold values to determine if ANY datetimes have spaces
908
-     *    available... if NOT, then the event status will get toggled to 'sold_out'
909
-     *
910
-     * @return bool    return the ACTUAL sold out state.
911
-     * @throws EE_Error
912
-     * @throws DomainException
913
-     * @throws UnexpectedEntityException
914
-     * @throws ReflectionException
915
-     */
916
-    public function perform_sold_out_status_check()
917
-    {
918
-        // get all tickets
919
-        $tickets = $this->tickets(
920
-            array(
921
-                'default_where_conditions' => 'none',
922
-                'order_by' => array('TKT_qty' => 'ASC'),
923
-            )
924
-        );
925
-        $all_expired = true;
926
-        foreach ($tickets as $ticket) {
927
-            if (! $ticket->is_expired()) {
928
-                $all_expired = false;
929
-                break;
930
-            }
931
-        }
932
-        // if all the tickets are just expired, then don't update the event status to sold out
933
-        if ($all_expired) {
934
-            return true;
935
-        }
936
-        $spaces_remaining = $this->spaces_remaining($tickets);
937
-        if ($spaces_remaining < 1) {
938
-            if ($this->status() !== EEM_Event::post_status_private) {
939
-                $this->set_status(EEM_Event::sold_out);
940
-                $this->save();
941
-            }
942
-            $sold_out = true;
943
-        } else {
944
-            $sold_out = false;
945
-            // was event previously marked as sold out ?
946
-            if ($this->status() === EEM_Event::sold_out) {
947
-                // revert status to previous value, if it was set
948
-                $previous_event_status = $this->get_post_meta('_previous_event_status', true);
949
-                if ($previous_event_status) {
950
-                    $this->set_status($previous_event_status);
951
-                    $this->save();
952
-                }
953
-            }
954
-        }
955
-        do_action('AHEE__EE_Event__perform_sold_out_status_check__end', $this, $sold_out, $spaces_remaining, $tickets);
956
-        return $sold_out;
957
-    }
958
-
959
-
960
-    /**
961
-     * This returns the total remaining spaces for sale on this event.
962
-     *
963
-     * @uses EE_Event::total_available_spaces()
964
-     * @return float|int
965
-     * @throws EE_Error
966
-     * @throws DomainException
967
-     * @throws UnexpectedEntityException
968
-     */
969
-    public function spaces_remaining_for_sale()
970
-    {
971
-        return $this->total_available_spaces(true);
972
-    }
973
-
974
-
975
-    /**
976
-     * This returns the total spaces available for an event
977
-     * while considering all the qtys on the tickets and the reg limits
978
-     * on the datetimes attached to this event.
979
-     *
980
-     * @param   bool $consider_sold Whether to consider any tickets that have already sold in our calculation.
981
-     *                              If this is false, then we return the most tickets that could ever be sold
982
-     *                              for this event with the datetime and tickets setup on the event under optimal
983
-     *                              selling conditions.  Otherwise we return a live calculation of spaces available
984
-     *                              based on tickets sold.  Depending on setup and stage of sales, this
985
-     *                              may appear to equal remaining tickets.  However, the more tickets are
986
-     *                              sold out, the more accurate the "live" total is.
987
-     * @return float|int
988
-     * @throws EE_Error
989
-     * @throws DomainException
990
-     * @throws UnexpectedEntityException
991
-     */
992
-    public function total_available_spaces($consider_sold = false)
993
-    {
994
-        $spaces_available = $consider_sold
995
-            ? $this->getAvailableSpacesCalculator()->spacesRemaining()
996
-            : $this->getAvailableSpacesCalculator()->totalSpacesAvailable();
997
-        return apply_filters(
998
-            'FHEE_EE_Event__total_available_spaces__spaces_available',
999
-            $spaces_available,
1000
-            $this,
1001
-            $this->getAvailableSpacesCalculator()->getDatetimes(),
1002
-            $this->getAvailableSpacesCalculator()->getActiveTickets()
1003
-        );
1004
-    }
1005
-
1006
-
1007
-    /**
1008
-     * Checks if the event is set to sold out
1009
-     *
1010
-     * @param  bool $actual whether or not to perform calculations to not only figure the
1011
-     *                      actual status but also to flip the status if necessary to sold
1012
-     *                      out If false, we just check the existing status of the event
1013
-     * @return boolean
1014
-     * @throws EE_Error
1015
-     */
1016
-    public function is_sold_out($actual = false)
1017
-    {
1018
-        if (! $actual) {
1019
-            return $this->status() === EEM_Event::sold_out;
1020
-        }
1021
-        return $this->perform_sold_out_status_check();
1022
-    }
1023
-
1024
-
1025
-    /**
1026
-     * Checks if the event is marked as postponed
1027
-     *
1028
-     * @return boolean
1029
-     */
1030
-    public function is_postponed()
1031
-    {
1032
-        return $this->status() === EEM_Event::postponed;
1033
-    }
1034
-
1035
-
1036
-    /**
1037
-     * Checks if the event is marked as cancelled
1038
-     *
1039
-     * @return boolean
1040
-     */
1041
-    public function is_cancelled()
1042
-    {
1043
-        return $this->status() === EEM_Event::cancelled;
1044
-    }
1045
-
1046
-
1047
-    /**
1048
-     * Get the logical active status in a hierarchical order for all the datetimes.  Note
1049
-     * Basically, we order the datetimes by EVT_start_date.  Then first test on whether the event is published.  If its
1050
-     * NOT published then we test for whether its expired or not.  IF it IS published then we test first on whether an
1051
-     * event has any active dates.  If no active dates then we check for any upcoming dates.  If no upcoming dates then
1052
-     * the event is considered expired.
1053
-     * NOTE: this method does NOT calculate whether the datetimes are sold out when event is published.  Sold Out is a
1054
-     * status set on the EVENT when it is not published and thus is done
1055
-     *
1056
-     * @param bool $reset
1057
-     * @return bool | string - based on EE_Datetime active constants or FALSE if error.
1058
-     * @throws EE_Error
1059
-     * @throws ReflectionException
1060
-     */
1061
-    public function get_active_status($reset = false)
1062
-    {
1063
-        // if the active status has already been set, then just use that value (unless we are resetting it)
1064
-        if (! empty($this->_active_status) && ! $reset) {
1065
-            return $this->_active_status;
1066
-        }
1067
-        // first check if event id is present on this object
1068
-        if (! $this->ID()) {
1069
-            return false;
1070
-        }
1071
-        $where_params_for_event = array(array('EVT_ID' => $this->ID()));
1072
-        // if event is published:
1073
-        if ($this->status() === EEM_Event::post_status_publish || $this->status() === EEM_Event::post_status_private) {
1074
-            // active?
1075
-            if (
1076
-                EEM_Datetime::instance()->get_datetime_count_for_status(
1077
-                    EE_Datetime::active,
1078
-                    $where_params_for_event
1079
-                ) > 0
1080
-            ) {
1081
-                $this->_active_status = EE_Datetime::active;
1082
-            } else {
1083
-                // upcoming?
1084
-                if (
1085
-                    EEM_Datetime::instance()->get_datetime_count_for_status(
1086
-                        EE_Datetime::upcoming,
1087
-                        $where_params_for_event
1088
-                    ) > 0
1089
-                ) {
1090
-                    $this->_active_status = EE_Datetime::upcoming;
1091
-                } else {
1092
-                    // expired?
1093
-                    if (
1094
-                        EEM_Datetime::instance()->get_datetime_count_for_status(
1095
-                            EE_Datetime::expired,
1096
-                            $where_params_for_event
1097
-                        ) > 0
1098
-                    ) {
1099
-                        $this->_active_status = EE_Datetime::expired;
1100
-                    } else {
1101
-                        // it would be odd if things make it this far because it basically means there are no datetime's
1102
-                        // attached to the event.  So in this case it will just be considered inactive.
1103
-                        $this->_active_status = EE_Datetime::inactive;
1104
-                    }
1105
-                }
1106
-            }
1107
-        } else {
1108
-            // the event is not published, so let's just set it's active status according to its' post status
1109
-            switch ($this->status()) {
1110
-                case EEM_Event::sold_out:
1111
-                    $this->_active_status = EE_Datetime::sold_out;
1112
-                    break;
1113
-                case EEM_Event::cancelled:
1114
-                    $this->_active_status = EE_Datetime::cancelled;
1115
-                    break;
1116
-                case EEM_Event::postponed:
1117
-                    $this->_active_status = EE_Datetime::postponed;
1118
-                    break;
1119
-                default:
1120
-                    $this->_active_status = EE_Datetime::inactive;
1121
-            }
1122
-        }
1123
-        return $this->_active_status;
1124
-    }
1125
-
1126
-
1127
-    /**
1128
-     *    pretty_active_status
1129
-     *
1130
-     * @access public
1131
-     * @param boolean $echo whether to return (FALSE), or echo out the result (TRUE)
1132
-     * @return mixed void|string
1133
-     * @throws EE_Error
1134
-     * @throws ReflectionException
1135
-     */
1136
-    public function pretty_active_status($echo = true)
1137
-    {
1138
-        $active_status = $this->get_active_status();
1139
-        $status = '<span class="ee-status event-active-status-' . esc_attr($active_status) . '">'
1140
-                  . EEH_Template::pretty_status($active_status, false, 'sentence')
1141
-                  . '</span>';
1142
-        if ($echo) {
1143
-            echo wp_kses($status, AllowedTags::getAllowedTags());
1144
-            return '';
1145
-        }
1146
-        return $status; // already escaped
1147
-    }
1148
-
1149
-
1150
-    /**
1151
-     * @return bool|int
1152
-     * @throws EE_Error
1153
-     * @throws ReflectionException
1154
-     */
1155
-    public function get_number_of_tickets_sold()
1156
-    {
1157
-        $tkt_sold = 0;
1158
-        if (! $this->ID()) {
1159
-            return 0;
1160
-        }
1161
-        $datetimes = $this->datetimes();
1162
-        foreach ($datetimes as $datetime) {
1163
-            if ($datetime instanceof EE_Datetime) {
1164
-                $tkt_sold += $datetime->sold();
1165
-            }
1166
-        }
1167
-        return $tkt_sold;
1168
-    }
1169
-
1170
-
1171
-    /**
1172
-     * This just returns a count of all the registrations for this event
1173
-     *
1174
-     * @access  public
1175
-     * @return int
1176
-     * @throws EE_Error
1177
-     */
1178
-    public function get_count_of_all_registrations()
1179
-    {
1180
-        return EEM_Event::instance()->count_related($this, 'Registration');
1181
-    }
1182
-
1183
-
1184
-    /**
1185
-     * This returns the ticket with the earliest start time that is
1186
-     * available for this event (across all datetimes attached to the event)
1187
-     *
1188
-     * @return EE_Base_Class|EE_Ticket|null
1189
-     * @throws EE_Error
1190
-     * @throws ReflectionException
1191
-     */
1192
-    public function get_ticket_with_earliest_start_time()
1193
-    {
1194
-        $where['Datetime.EVT_ID'] = $this->ID();
1195
-        $query_params = array($where, 'order_by' => array('TKT_start_date' => 'ASC'));
1196
-        return EE_Registry::instance()->load_model('Ticket')->get_one($query_params);
1197
-    }
1198
-
1199
-
1200
-    /**
1201
-     * This returns the ticket with the latest end time that is available
1202
-     * for this event (across all datetimes attached to the event)
1203
-     *
1204
-     * @return EE_Base_Class|EE_Ticket|null
1205
-     * @throws EE_Error
1206
-     * @throws ReflectionException
1207
-     */
1208
-    public function get_ticket_with_latest_end_time()
1209
-    {
1210
-        $where['Datetime.EVT_ID'] = $this->ID();
1211
-        $query_params = array($where, 'order_by' => array('TKT_end_date' => 'DESC'));
1212
-        return EE_Registry::instance()->load_model('Ticket')->get_one($query_params);
1213
-    }
1214
-
1215
-
1216
-    /**
1217
-     * This returns the number of different ticket types currently on sale for this event.
1218
-     *
1219
-     * @return int
1220
-     * @throws EE_Error
1221
-     * @throws ReflectionException
1222
-     */
1223
-    public function countTicketsOnSale()
1224
-    {
1225
-        $where = array(
1226
-            'Datetime.EVT_ID' => $this->ID(),
1227
-            'TKT_start_date'  => array('<', time()),
1228
-            'TKT_end_date'    => array('>', time()),
1229
-        );
1230
-        return EEM_Ticket::instance()->count(array($where));
1231
-    }
1232
-
1233
-
1234
-    /**
1235
-     * This returns whether there are any tickets on sale for this event.
1236
-     *
1237
-     * @return bool true = YES tickets on sale.
1238
-     * @throws EE_Error
1239
-     */
1240
-    public function tickets_on_sale()
1241
-    {
1242
-        return $this->countTicketsOnSale() > 0;
1243
-    }
1244
-
1245
-
1246
-    /**
1247
-     * Gets the URL for viewing this event on the front-end. Overrides parent
1248
-     * to check for an external URL first
1249
-     *
1250
-     * @return string
1251
-     * @throws EE_Error
1252
-     */
1253
-    public function get_permalink()
1254
-    {
1255
-        if ($this->external_url()) {
1256
-            return $this->external_url();
1257
-        }
1258
-        return parent::get_permalink();
1259
-    }
1260
-
1261
-
1262
-    /**
1263
-     * Gets the first term for 'espresso_event_categories' we can find
1264
-     *
1265
-     * @param array $query_params @see
1266
-     *                            https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
1267
-     * @return EE_Base_Class|EE_Term|null
1268
-     * @throws EE_Error
1269
-     * @throws ReflectionException
1270
-     */
1271
-    public function first_event_category($query_params = array())
1272
-    {
1273
-        $query_params[0]['Term_Taxonomy.taxonomy'] = 'espresso_event_categories';
1274
-        $query_params[0]['Term_Taxonomy.Event.EVT_ID'] = $this->ID();
1275
-        return EEM_Term::instance()->get_one($query_params);
1276
-    }
1277
-
1278
-
1279
-    /**
1280
-     * Gets all terms for 'espresso_event_categories' we can find
1281
-     *
1282
-     * @param array $query_params
1283
-     * @return EE_Base_Class[]|EE_Term[]
1284
-     * @throws EE_Error
1285
-     * @throws ReflectionException
1286
-     */
1287
-    public function get_all_event_categories($query_params = array())
1288
-    {
1289
-        $query_params[0]['Term_Taxonomy.taxonomy'] = 'espresso_event_categories';
1290
-        $query_params[0]['Term_Taxonomy.Event.EVT_ID'] = $this->ID();
1291
-        return EEM_Term::instance()->get_all($query_params);
1292
-    }
1293
-
1294
-
1295
-    /**
1296
-     * Adds a question group to this event
1297
-     *
1298
-     * @param EE_Question_Group|int $question_group_id_or_obj
1299
-     * @param bool $for_primary if true, the question group will be added for the primary
1300
-     *                                           registrant, if false will be added for others. default: false
1301
-     * @return EE_Base_Class|EE_Question_Group
1302
-     * @throws EE_Error
1303
-     * @throws InvalidArgumentException
1304
-     * @throws InvalidDataTypeException
1305
-     * @throws InvalidInterfaceException
1306
-     * @throws ReflectionException
1307
-     */
1308
-    public function add_question_group($question_group_id_or_obj, $for_primary = false)
1309
-    {
1310
-        // If the row already exists, it will be updated. If it doesn't, it will be inserted.
1311
-        // That's in EE_HABTM_Relation::add_relation_to().
1312
-        return $this->_add_relation_to(
1313
-            $question_group_id_or_obj,
1314
-            'Question_Group',
1315
-            [
1316
-                EEM_Event_Question_Group::instance()->fieldNameForContext($for_primary) => true
1317
-            ]
1318
-        );
1319
-    }
1320
-
1321
-
1322
-    /**
1323
-     * Removes a question group from the event
1324
-     *
1325
-     * @param EE_Question_Group|int $question_group_id_or_obj
1326
-     * @param bool $for_primary if true, the question group will be removed from the primary
1327
-     *                                           registrant, if false will be removed from others. default: false
1328
-     * @return EE_Base_Class|EE_Question_Group
1329
-     * @throws EE_Error
1330
-     * @throws InvalidArgumentException
1331
-     * @throws ReflectionException
1332
-     * @throws InvalidDataTypeException
1333
-     * @throws InvalidInterfaceException
1334
-     */
1335
-    public function remove_question_group($question_group_id_or_obj, $for_primary = false)
1336
-    {
1337
-        // If the question group is used for the other type (primary or additional)
1338
-        // then just update it. If not, delete it outright.
1339
-        $existing_relation = $this->get_first_related(
1340
-            'Event_Question_Group',
1341
-            [
1342
-                [
1343
-                    'QSG_ID' => EEM_Question_Group::instance()->ensure_is_ID($question_group_id_or_obj)
1344
-                ]
1345
-            ]
1346
-        );
1347
-        $field_to_update = EEM_Event_Question_Group::instance()->fieldNameForContext($for_primary);
1348
-        $other_field = EEM_Event_Question_Group::instance()->fieldNameForContext(! $for_primary);
1349
-        if ($existing_relation->get($other_field) === false) {
1350
-            // Delete it. It's now no longer for primary or additional question groups.
1351
-            return $this->_remove_relation_to($question_group_id_or_obj, 'Question_Group');
1352
-        }
1353
-        // Just update it. They'll still use this question group for the other category
1354
-        $existing_relation->save(
1355
-            [
1356
-                $field_to_update => false
1357
-            ]
1358
-        );
1359
-    }
1360
-
1361
-
1362
-    /**
1363
-     * Gets all the question groups, ordering them by QSG_order ascending
1364
-     *
1365
-     * @param array $query_params @see
1366
-     *                            https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
1367
-     * @return EE_Base_Class[]|EE_Question_Group[]
1368
-     * @throws EE_Error
1369
-     * @throws ReflectionException
1370
-     */
1371
-    public function question_groups($query_params = array())
1372
-    {
1373
-        $query_params = ! empty($query_params) ? $query_params : array('order_by' => array('QSG_order' => 'ASC'));
1374
-        return $this->get_many_related('Question_Group', $query_params);
1375
-    }
1376
-
1377
-
1378
-    /**
1379
-     * Implementation for EEI_Has_Icon interface method.
1380
-     *
1381
-     * @see EEI_Visual_Representation for comments
1382
-     * @return string
1383
-     */
1384
-    public function get_icon()
1385
-    {
1386
-        return '<span class="dashicons dashicons-flag"></span>';
1387
-    }
1388
-
1389
-
1390
-    /**
1391
-     * Implementation for EEI_Admin_Links interface method.
1392
-     *
1393
-     * @see EEI_Admin_Links for comments
1394
-     * @return string
1395
-     * @throws EE_Error
1396
-     */
1397
-    public function get_admin_details_link()
1398
-    {
1399
-        return $this->get_admin_edit_link();
1400
-    }
1401
-
1402
-
1403
-    /**
1404
-     * Implementation for EEI_Admin_Links interface method.
1405
-     *
1406
-     * @return string
1407
-     * @throws EE_Error*@throws ReflectionException
1408
-     * @see EEI_Admin_Links for comments
1409
-     */
1410
-    public function get_admin_edit_link()
1411
-    {
1412
-        return EEH_URL::add_query_args_and_nonce(
1413
-            array(
1414
-                'page'   => 'espresso_events',
1415
-                'action' => 'edit',
1416
-                'post'   => $this->ID(),
1417
-            ),
1418
-            admin_url('admin.php')
1419
-        );
1420
-    }
1421
-
1422
-
1423
-    /**
1424
-     * Implementation for EEI_Admin_Links interface method.
1425
-     *
1426
-     * @see EEI_Admin_Links for comments
1427
-     * @return string
1428
-     */
1429
-    public function get_admin_settings_link()
1430
-    {
1431
-        return EEH_URL::add_query_args_and_nonce(
1432
-            array(
1433
-                'page'   => 'espresso_events',
1434
-                'action' => 'default_event_settings',
1435
-            ),
1436
-            admin_url('admin.php')
1437
-        );
1438
-    }
1439
-
1440
-
1441
-    /**
1442
-     * Implementation for EEI_Admin_Links interface method.
1443
-     *
1444
-     * @see EEI_Admin_Links for comments
1445
-     * @return string
1446
-     */
1447
-    public function get_admin_overview_link()
1448
-    {
1449
-        return EEH_URL::add_query_args_and_nonce(
1450
-            array(
1451
-                'page'   => 'espresso_events',
1452
-                'action' => 'default',
1453
-            ),
1454
-            admin_url('admin.php')
1455
-        );
1456
-    }
18
+	/**
19
+	 * cached value for the the logical active status for the event
20
+	 *
21
+	 * @see get_active_status()
22
+	 * @var string
23
+	 */
24
+	protected $_active_status = '';
25
+
26
+	/**
27
+	 * This is just used for caching the Primary Datetime for the Event on initial retrieval
28
+	 *
29
+	 * @var EE_Datetime
30
+	 */
31
+	protected $_Primary_Datetime;
32
+
33
+	/**
34
+	 * @var EventSpacesCalculator $available_spaces_calculator
35
+	 */
36
+	protected $available_spaces_calculator;
37
+
38
+
39
+	/**
40
+	 * @param array  $props_n_values          incoming values
41
+	 * @param string $timezone                incoming timezone (if not set the timezone set for the website will be
42
+	 *                                        used.)
43
+	 * @param array  $date_formats            incoming date_formats in an array where the first value is the
44
+	 *                                        date_format and the second value is the time format
45
+	 * @return EE_Event
46
+	 * @throws EE_Error
47
+	 * @throws ReflectionException
48
+	 */
49
+	public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array())
50
+	{
51
+		$has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats);
52
+		return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats);
53
+	}
54
+
55
+
56
+	/**
57
+	 * @param array  $props_n_values  incoming values from the database
58
+	 * @param string $timezone        incoming timezone as set by the model.  If not set the timezone for
59
+	 *                                the website will be used.
60
+	 * @return EE_Event
61
+	 * @throws EE_Error
62
+	 * @throws ReflectionException
63
+	 */
64
+	public static function new_instance_from_db($props_n_values = array(), $timezone = null)
65
+	{
66
+		return new self($props_n_values, true, $timezone);
67
+	}
68
+
69
+
70
+	/**
71
+	 * @return EventSpacesCalculator
72
+	 * @throws \EE_Error
73
+	 */
74
+	public function getAvailableSpacesCalculator()
75
+	{
76
+		if (! $this->available_spaces_calculator instanceof EventSpacesCalculator) {
77
+			$this->available_spaces_calculator = new EventSpacesCalculator($this);
78
+		}
79
+		return $this->available_spaces_calculator;
80
+	}
81
+
82
+
83
+	/**
84
+	 * Overrides parent set() method so that all calls to set( 'status', $status ) can be routed to internal methods
85
+	 *
86
+	 * @param string $field_name
87
+	 * @param mixed  $field_value
88
+	 * @param bool   $use_default
89
+	 * @throws EE_Error
90
+	 * @throws ReflectionException
91
+	 */
92
+	public function set($field_name, $field_value, $use_default = false)
93
+	{
94
+		switch ($field_name) {
95
+			case 'status':
96
+				$this->set_status($field_value, $use_default);
97
+				break;
98
+			default:
99
+				parent::set($field_name, $field_value, $use_default);
100
+		}
101
+	}
102
+
103
+
104
+	/**
105
+	 *    set_status
106
+	 * Checks if event status is being changed to SOLD OUT
107
+	 * and updates event meta data with previous event status
108
+	 * so that we can revert things if/when the event is no longer sold out
109
+	 *
110
+	 * @access public
111
+	 * @param string $new_status
112
+	 * @param bool   $use_default
113
+	 * @return void
114
+	 * @throws EE_Error
115
+	 * @throws ReflectionException
116
+	 */
117
+	public function set_status($new_status = null, $use_default = false)
118
+	{
119
+		// if nothing is set, and we aren't explicitly wanting to reset the status, then just leave
120
+		if (empty($new_status) && ! $use_default) {
121
+			return;
122
+		}
123
+		// get current Event status
124
+		$old_status = $this->status();
125
+		// if status has changed
126
+		if ($old_status !== $new_status) {
127
+			// TO sold_out
128
+			if ($new_status === EEM_Event::sold_out) {
129
+				// save the previous event status so that we can revert if the event is no longer sold out
130
+				$this->add_post_meta('_previous_event_status', $old_status);
131
+				do_action('AHEE__EE_Event__set_status__to_sold_out', $this, $old_status, $new_status);
132
+				// OR FROM  sold_out
133
+			} elseif ($old_status === EEM_Event::sold_out) {
134
+				$this->delete_post_meta('_previous_event_status');
135
+				do_action('AHEE__EE_Event__set_status__from_sold_out', $this, $old_status, $new_status);
136
+			}
137
+			// clear out the active status so that it gets reset the next time it is requested
138
+			$this->_active_status = null;
139
+			// update status
140
+			parent::set('status', $new_status, $use_default);
141
+			do_action('AHEE__EE_Event__set_status__after_update', $this);
142
+			return;
143
+		}
144
+		// even though the old value matches the new value, it's still good to
145
+		// allow the parent set method to have a say
146
+		parent::set('status', $new_status, $use_default);
147
+	}
148
+
149
+
150
+	/**
151
+	 * Gets all the datetimes for this event
152
+	 *
153
+	 * @param array $query_params @see
154
+	 *                            https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
155
+	 * @return EE_Base_Class[]|EE_Datetime[]
156
+	 * @throws EE_Error
157
+	 * @throws ReflectionException
158
+	 */
159
+	public function datetimes($query_params = array())
160
+	{
161
+		return $this->get_many_related('Datetime', $query_params);
162
+	}
163
+
164
+
165
+	/**
166
+	 * Gets all the datetimes for this event, ordered by DTT_EVT_start in ascending order
167
+	 *
168
+	 * @return EE_Base_Class[]|EE_Datetime[]
169
+	 * @throws EE_Error
170
+	 * @throws ReflectionException
171
+	 */
172
+	public function datetimes_in_chronological_order()
173
+	{
174
+		return $this->get_many_related('Datetime', array('order_by' => array('DTT_EVT_start' => 'ASC')));
175
+	}
176
+
177
+
178
+	/**
179
+	 * Gets all the datetimes for this event, ordered by the DTT_order on the datetime.
180
+	 * @darren, we should probably UNSET timezone on the EEM_Datetime model
181
+	 * after running our query, so that this timezone isn't set for EVERY query
182
+	 * on EEM_Datetime for the rest of the request, no?
183
+	 *
184
+	 * @param boolean $show_expired whether or not to include expired events
185
+	 * @param boolean $show_deleted whether or not to include deleted events
186
+	 * @param null    $limit
187
+	 * @return EE_Datetime[]
188
+	 * @throws EE_Error
189
+	 * @throws ReflectionException
190
+	 */
191
+	public function datetimes_ordered($show_expired = true, $show_deleted = false, $limit = null)
192
+	{
193
+		return EEM_Datetime::instance($this->_timezone)->get_datetimes_for_event_ordered_by_DTT_order(
194
+			$this->ID(),
195
+			$show_expired,
196
+			$show_deleted,
197
+			$limit
198
+		);
199
+	}
200
+
201
+
202
+	/**
203
+	 * Returns one related datetime. Mostly only used by some legacy code.
204
+	 *
205
+	 * @return EE_Base_Class|EE_Datetime
206
+	 * @throws EE_Error
207
+	 * @throws ReflectionException
208
+	 */
209
+	public function first_datetime()
210
+	{
211
+		return $this->get_first_related('Datetime');
212
+	}
213
+
214
+
215
+	/**
216
+	 * Returns the 'primary' datetime for the event
217
+	 *
218
+	 * @param bool $try_to_exclude_expired
219
+	 * @param bool $try_to_exclude_deleted
220
+	 * @return EE_Datetime
221
+	 * @throws EE_Error
222
+	 * @throws ReflectionException
223
+	 */
224
+	public function primary_datetime($try_to_exclude_expired = true, $try_to_exclude_deleted = true)
225
+	{
226
+		if (! empty($this->_Primary_Datetime)) {
227
+			return $this->_Primary_Datetime;
228
+		}
229
+		$this->_Primary_Datetime = EEM_Datetime::instance($this->_timezone)->get_primary_datetime_for_event(
230
+			$this->ID(),
231
+			$try_to_exclude_expired,
232
+			$try_to_exclude_deleted
233
+		);
234
+		return $this->_Primary_Datetime;
235
+	}
236
+
237
+
238
+	/**
239
+	 * Gets all the tickets available for purchase of this event
240
+	 *
241
+	 * @param array $query_params @see
242
+	 *                            https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
243
+	 * @return EE_Base_Class[]|EE_Ticket[]
244
+	 * @throws EE_Error
245
+	 * @throws ReflectionException
246
+	 */
247
+	public function tickets($query_params = array())
248
+	{
249
+		// first get all datetimes
250
+		$datetimes = $this->datetimes_ordered();
251
+		if (! $datetimes) {
252
+			return array();
253
+		}
254
+		$datetime_ids = array();
255
+		foreach ($datetimes as $datetime) {
256
+			$datetime_ids[] = $datetime->ID();
257
+		}
258
+		$where_params = array('Datetime.DTT_ID' => array('IN', $datetime_ids));
259
+		// if incoming $query_params has where conditions let's merge but not override existing.
260
+		if (is_array($query_params) && isset($query_params[0])) {
261
+			$where_params = array_merge($query_params[0], $where_params);
262
+			unset($query_params[0]);
263
+		}
264
+		// now add $where_params to $query_params
265
+		$query_params[0] = $where_params;
266
+		return EEM_Ticket::instance()->get_all($query_params);
267
+	}
268
+
269
+
270
+	/**
271
+	 * get all unexpired untrashed tickets
272
+	 *
273
+	 * @return EE_Ticket[]
274
+	 * @throws EE_Error
275
+	 */
276
+	public function active_tickets()
277
+	{
278
+		return $this->tickets(
279
+			array(
280
+				array(
281
+					'TKT_end_date' => array('>=', EEM_Ticket::instance()->current_time_for_query('TKT_end_date')),
282
+					'TKT_deleted'  => false,
283
+				),
284
+			)
285
+		);
286
+	}
287
+
288
+
289
+	/**
290
+	 * @return bool
291
+	 * @throws EE_Error
292
+	 * @throws ReflectionException
293
+	 */
294
+	public function additional_limit()
295
+	{
296
+		return $this->get('EVT_additional_limit');
297
+	}
298
+
299
+
300
+	/**
301
+	 * @return bool
302
+	 * @throws EE_Error
303
+	 * @throws ReflectionException
304
+	 */
305
+	public function allow_overflow()
306
+	{
307
+		return $this->get('EVT_allow_overflow');
308
+	}
309
+
310
+
311
+	/**
312
+	 * @return bool
313
+	 * @throws EE_Error
314
+	 * @throws ReflectionException
315
+	 */
316
+	public function created()
317
+	{
318
+		return $this->get('EVT_created');
319
+	}
320
+
321
+
322
+	/**
323
+	 * @return bool
324
+	 * @throws EE_Error
325
+	 * @throws ReflectionException
326
+	 */
327
+	public function description()
328
+	{
329
+		return $this->get('EVT_desc');
330
+	}
331
+
332
+
333
+	/**
334
+	 * Runs do_shortcode and wpautop on the description
335
+	 *
336
+	 * @return string of html
337
+	 * @throws EE_Error
338
+	 * @throws ReflectionException
339
+	 */
340
+	public function description_filtered()
341
+	{
342
+		return $this->get_pretty('EVT_desc');
343
+	}
344
+
345
+
346
+	/**
347
+	 * @return bool
348
+	 * @throws EE_Error
349
+	 * @throws ReflectionException
350
+	 */
351
+	public function display_description()
352
+	{
353
+		return $this->get('EVT_display_desc');
354
+	}
355
+
356
+
357
+	/**
358
+	 * @return bool
359
+	 * @throws EE_Error
360
+	 * @throws ReflectionException
361
+	 */
362
+	public function display_ticket_selector()
363
+	{
364
+		return (bool) $this->get('EVT_display_ticket_selector');
365
+	}
366
+
367
+
368
+	/**
369
+	 * @return string
370
+	 * @throws EE_Error
371
+	 * @throws ReflectionException
372
+	 */
373
+	public function external_url()
374
+	{
375
+		return $this->get('EVT_external_URL');
376
+	}
377
+
378
+
379
+	/**
380
+	 * @return bool
381
+	 * @throws EE_Error
382
+	 * @throws ReflectionException
383
+	 */
384
+	public function member_only()
385
+	{
386
+		return $this->get('EVT_member_only');
387
+	}
388
+
389
+
390
+	/**
391
+	 * @return bool
392
+	 * @throws EE_Error
393
+	 * @throws ReflectionException
394
+	 */
395
+	public function phone()
396
+	{
397
+		return $this->get('EVT_phone');
398
+	}
399
+
400
+
401
+	/**
402
+	 * @return bool
403
+	 * @throws EE_Error
404
+	 * @throws ReflectionException
405
+	 */
406
+	public function modified()
407
+	{
408
+		return $this->get('EVT_modified');
409
+	}
410
+
411
+
412
+	/**
413
+	 * @return bool
414
+	 * @throws EE_Error
415
+	 * @throws ReflectionException
416
+	 */
417
+	public function name()
418
+	{
419
+		return $this->get('EVT_name');
420
+	}
421
+
422
+
423
+	/**
424
+	 * @return bool
425
+	 * @throws EE_Error
426
+	 * @throws ReflectionException
427
+	 */
428
+	public function order()
429
+	{
430
+		return $this->get('EVT_order');
431
+	}
432
+
433
+
434
+	/**
435
+	 * @return bool|string
436
+	 * @throws EE_Error
437
+	 * @throws ReflectionException
438
+	 */
439
+	public function default_registration_status()
440
+	{
441
+		$event_default_registration_status = $this->get('EVT_default_registration_status');
442
+		return ! empty($event_default_registration_status)
443
+			? $event_default_registration_status
444
+			: EE_Registry::instance()->CFG->registration->default_STS_ID;
445
+	}
446
+
447
+
448
+	/**
449
+	 * @param int  $num_words
450
+	 * @param null $more
451
+	 * @param bool $not_full_desc
452
+	 * @return bool|string
453
+	 * @throws EE_Error
454
+	 * @throws ReflectionException
455
+	 */
456
+	public function short_description($num_words = 55, $more = null, $not_full_desc = false)
457
+	{
458
+		$short_desc = $this->get('EVT_short_desc');
459
+		if (! empty($short_desc) || $not_full_desc) {
460
+			return $short_desc;
461
+		}
462
+		$full_desc = $this->get('EVT_desc');
463
+		return wp_trim_words($full_desc, $num_words, $more);
464
+	}
465
+
466
+
467
+	/**
468
+	 * @return bool
469
+	 * @throws EE_Error
470
+	 * @throws ReflectionException
471
+	 */
472
+	public function slug()
473
+	{
474
+		return $this->get('EVT_slug');
475
+	}
476
+
477
+
478
+	/**
479
+	 * @return bool
480
+	 * @throws EE_Error
481
+	 * @throws ReflectionException
482
+	 */
483
+	public function timezone_string()
484
+	{
485
+		return $this->get('EVT_timezone_string');
486
+	}
487
+
488
+
489
+	/**
490
+	 * @return bool
491
+	 * @throws EE_Error
492
+	 * @throws ReflectionException
493
+	 */
494
+	public function visible_on()
495
+	{
496
+		return $this->get('EVT_visible_on');
497
+	}
498
+
499
+
500
+	/**
501
+	 * @return int
502
+	 * @throws EE_Error
503
+	 * @throws ReflectionException
504
+	 */
505
+	public function wp_user()
506
+	{
507
+		return $this->get('EVT_wp_user');
508
+	}
509
+
510
+
511
+	/**
512
+	 * @return bool
513
+	 * @throws EE_Error
514
+	 * @throws ReflectionException
515
+	 */
516
+	public function donations()
517
+	{
518
+		return $this->get('EVT_donations');
519
+	}
520
+
521
+
522
+	/**
523
+	 * @param $limit
524
+	 * @throws EE_Error
525
+	 */
526
+	public function set_additional_limit($limit)
527
+	{
528
+		$this->set('EVT_additional_limit', $limit);
529
+	}
530
+
531
+
532
+	/**
533
+	 * @param $created
534
+	 * @throws EE_Error
535
+	 */
536
+	public function set_created($created)
537
+	{
538
+		$this->set('EVT_created', $created);
539
+	}
540
+
541
+
542
+	/**
543
+	 * @param $desc
544
+	 * @throws EE_Error
545
+	 */
546
+	public function set_description($desc)
547
+	{
548
+		$this->set('EVT_desc', $desc);
549
+	}
550
+
551
+
552
+	/**
553
+	 * @param $display_desc
554
+	 * @throws EE_Error
555
+	 */
556
+	public function set_display_description($display_desc)
557
+	{
558
+		$this->set('EVT_display_desc', $display_desc);
559
+	}
560
+
561
+
562
+	/**
563
+	 * @param $display_ticket_selector
564
+	 * @throws EE_Error
565
+	 */
566
+	public function set_display_ticket_selector($display_ticket_selector)
567
+	{
568
+		$this->set('EVT_display_ticket_selector', $display_ticket_selector);
569
+	}
570
+
571
+
572
+	/**
573
+	 * @param $external_url
574
+	 * @throws EE_Error
575
+	 */
576
+	public function set_external_url($external_url)
577
+	{
578
+		$this->set('EVT_external_URL', $external_url);
579
+	}
580
+
581
+
582
+	/**
583
+	 * @param $member_only
584
+	 * @throws EE_Error
585
+	 */
586
+	public function set_member_only($member_only)
587
+	{
588
+		$this->set('EVT_member_only', $member_only);
589
+	}
590
+
591
+
592
+	/**
593
+	 * @param $event_phone
594
+	 * @throws EE_Error
595
+	 */
596
+	public function set_event_phone($event_phone)
597
+	{
598
+		$this->set('EVT_phone', $event_phone);
599
+	}
600
+
601
+
602
+	/**
603
+	 * @param $modified
604
+	 * @throws EE_Error
605
+	 */
606
+	public function set_modified($modified)
607
+	{
608
+		$this->set('EVT_modified', $modified);
609
+	}
610
+
611
+
612
+	/**
613
+	 * @param $name
614
+	 * @throws EE_Error
615
+	 */
616
+	public function set_name($name)
617
+	{
618
+		$this->set('EVT_name', $name);
619
+	}
620
+
621
+
622
+	/**
623
+	 * @param $order
624
+	 * @throws EE_Error
625
+	 */
626
+	public function set_order($order)
627
+	{
628
+		$this->set('EVT_order', $order);
629
+	}
630
+
631
+
632
+	/**
633
+	 * @param $short_desc
634
+	 * @throws EE_Error
635
+	 */
636
+	public function set_short_description($short_desc)
637
+	{
638
+		$this->set('EVT_short_desc', $short_desc);
639
+	}
640
+
641
+
642
+	/**
643
+	 * @param $slug
644
+	 * @throws EE_Error
645
+	 */
646
+	public function set_slug($slug)
647
+	{
648
+		$this->set('EVT_slug', $slug);
649
+	}
650
+
651
+
652
+	/**
653
+	 * @param $timezone_string
654
+	 * @throws EE_Error
655
+	 */
656
+	public function set_timezone_string($timezone_string)
657
+	{
658
+		$this->set('EVT_timezone_string', $timezone_string);
659
+	}
660
+
661
+
662
+	/**
663
+	 * @param $visible_on
664
+	 * @throws EE_Error
665
+	 */
666
+	public function set_visible_on($visible_on)
667
+	{
668
+		$this->set('EVT_visible_on', $visible_on);
669
+	}
670
+
671
+
672
+	/**
673
+	 * @param $wp_user
674
+	 * @throws EE_Error
675
+	 */
676
+	public function set_wp_user($wp_user)
677
+	{
678
+		$this->set('EVT_wp_user', $wp_user);
679
+	}
680
+
681
+
682
+	/**
683
+	 * @param $default_registration_status
684
+	 * @throws EE_Error
685
+	 */
686
+	public function set_default_registration_status($default_registration_status)
687
+	{
688
+		$this->set('EVT_default_registration_status', $default_registration_status);
689
+	}
690
+
691
+
692
+	/**
693
+	 * @param $donations
694
+	 * @throws EE_Error
695
+	 */
696
+	public function set_donations($donations)
697
+	{
698
+		$this->set('EVT_donations', $donations);
699
+	}
700
+
701
+
702
+	/**
703
+	 * Adds a venue to this event
704
+	 *
705
+	 * @param EE_Venue /int $venue_id_or_obj
706
+	 * @return EE_Base_Class|EE_Venue
707
+	 * @throws EE_Error
708
+	 * @throws ReflectionException
709
+	 */
710
+	public function add_venue($venue_id_or_obj)
711
+	{
712
+		return $this->_add_relation_to($venue_id_or_obj, 'Venue');
713
+	}
714
+
715
+
716
+	/**
717
+	 * Removes a venue from the event
718
+	 *
719
+	 * @param EE_Venue /int $venue_id_or_obj
720
+	 * @return EE_Base_Class|EE_Venue
721
+	 * @throws EE_Error
722
+	 * @throws ReflectionException
723
+	 */
724
+	public function remove_venue($venue_id_or_obj)
725
+	{
726
+		return $this->_remove_relation_to($venue_id_or_obj, 'Venue');
727
+	}
728
+
729
+
730
+	/**
731
+	 * Gets all the venues related ot the event. May provide additional $query_params if desired
732
+	 *
733
+	 * @param array $query_params @see
734
+	 *                            https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
735
+	 * @return EE_Base_Class[]|EE_Venue[]
736
+	 * @throws EE_Error
737
+	 * @throws ReflectionException
738
+	 */
739
+	public function venues($query_params = array())
740
+	{
741
+		return $this->get_many_related('Venue', $query_params);
742
+	}
743
+
744
+
745
+	/**
746
+	 * check if event id is present and if event is published
747
+	 *
748
+	 * @access public
749
+	 * @return boolean true yes, false no
750
+	 * @throws EE_Error
751
+	 * @throws ReflectionException
752
+	 */
753
+	private function _has_ID_and_is_published()
754
+	{
755
+		// first check if event id is present and not NULL,
756
+		// then check if this event is published (or any of the equivalent "published" statuses)
757
+		return
758
+			$this->ID() && $this->ID() !== null
759
+			&& (
760
+				$this->status() === 'publish'
761
+				|| $this->status() === EEM_Event::sold_out
762
+				|| $this->status() === EEM_Event::postponed
763
+				|| $this->status() === EEM_Event::cancelled
764
+			);
765
+	}
766
+
767
+
768
+	/**
769
+	 * This simply compares the internal dates with NOW and determines if the event is upcoming or not.
770
+	 *
771
+	 * @access public
772
+	 * @return boolean true yes, false no
773
+	 * @throws EE_Error
774
+	 * @throws ReflectionException
775
+	 */
776
+	public function is_upcoming()
777
+	{
778
+		// check if event id is present and if this event is published
779
+		if ($this->is_inactive()) {
780
+			return false;
781
+		}
782
+		// set initial value
783
+		$upcoming = false;
784
+		// next let's get all datetimes and loop through them
785
+		$datetimes = $this->datetimes_in_chronological_order();
786
+		foreach ($datetimes as $datetime) {
787
+			if ($datetime instanceof EE_Datetime) {
788
+				// if this dtt is expired then we continue cause one of the other datetimes might be upcoming.
789
+				if ($datetime->is_expired()) {
790
+					continue;
791
+				}
792
+				// if this dtt is active then we return false.
793
+				if ($datetime->is_active()) {
794
+					return false;
795
+				}
796
+				// otherwise let's check upcoming status
797
+				$upcoming = $datetime->is_upcoming();
798
+			}
799
+		}
800
+		return $upcoming;
801
+	}
802
+
803
+
804
+	/**
805
+	 * @return bool
806
+	 * @throws EE_Error
807
+	 * @throws ReflectionException
808
+	 */
809
+	public function is_active()
810
+	{
811
+		// check if event id is present and if this event is published
812
+		if ($this->is_inactive()) {
813
+			return false;
814
+		}
815
+		// set initial value
816
+		$active = false;
817
+		// next let's get all datetimes and loop through them
818
+		$datetimes = $this->datetimes_in_chronological_order();
819
+		foreach ($datetimes as $datetime) {
820
+			if ($datetime instanceof EE_Datetime) {
821
+				// if this dtt is expired then we continue cause one of the other datetimes might be active.
822
+				if ($datetime->is_expired()) {
823
+					continue;
824
+				}
825
+				// if this dtt is upcoming then we return false.
826
+				if ($datetime->is_upcoming()) {
827
+					return false;
828
+				}
829
+				// otherwise let's check active status
830
+				$active = $datetime->is_active();
831
+			}
832
+		}
833
+		return $active;
834
+	}
835
+
836
+
837
+	/**
838
+	 * @return bool
839
+	 * @throws EE_Error
840
+	 * @throws ReflectionException
841
+	 */
842
+	public function is_expired()
843
+	{
844
+		// check if event id is present and if this event is published
845
+		if ($this->is_inactive()) {
846
+			return false;
847
+		}
848
+		// set initial value
849
+		$expired = false;
850
+		// first let's get all datetimes and loop through them
851
+		$datetimes = $this->datetimes_in_chronological_order();
852
+		foreach ($datetimes as $datetime) {
853
+			if ($datetime instanceof EE_Datetime) {
854
+				// if this dtt is upcoming or active then we return false.
855
+				if ($datetime->is_upcoming() || $datetime->is_active()) {
856
+					return false;
857
+				}
858
+				// otherwise let's check active status
859
+				$expired = $datetime->is_expired();
860
+			}
861
+		}
862
+		return $expired;
863
+	}
864
+
865
+
866
+	/**
867
+	 * @return bool
868
+	 * @throws EE_Error
869
+	 */
870
+	public function is_inactive()
871
+	{
872
+		// check if event id is present and if this event is published
873
+		if ($this->_has_ID_and_is_published()) {
874
+			return false;
875
+		}
876
+		return true;
877
+	}
878
+
879
+
880
+	/**
881
+	 * calculate spaces remaining based on "saleable" tickets
882
+	 *
883
+	 * @param array $tickets
884
+	 * @param bool  $filtered
885
+	 * @return int|float
886
+	 * @throws EE_Error
887
+	 * @throws DomainException
888
+	 * @throws UnexpectedEntityException
889
+	 */
890
+	public function spaces_remaining($tickets = array(), $filtered = true)
891
+	{
892
+		$this->getAvailableSpacesCalculator()->setActiveTickets($tickets);
893
+		$spaces_remaining = $this->getAvailableSpacesCalculator()->spacesRemaining();
894
+		return $filtered
895
+			? apply_filters(
896
+				'FHEE_EE_Event__spaces_remaining',
897
+				$spaces_remaining,
898
+				$this,
899
+				$tickets
900
+			)
901
+			: $spaces_remaining;
902
+	}
903
+
904
+
905
+	/**
906
+	 *    perform_sold_out_status_check
907
+	 *    checks all of this events's datetime  reg_limit - sold values to determine if ANY datetimes have spaces
908
+	 *    available... if NOT, then the event status will get toggled to 'sold_out'
909
+	 *
910
+	 * @return bool    return the ACTUAL sold out state.
911
+	 * @throws EE_Error
912
+	 * @throws DomainException
913
+	 * @throws UnexpectedEntityException
914
+	 * @throws ReflectionException
915
+	 */
916
+	public function perform_sold_out_status_check()
917
+	{
918
+		// get all tickets
919
+		$tickets = $this->tickets(
920
+			array(
921
+				'default_where_conditions' => 'none',
922
+				'order_by' => array('TKT_qty' => 'ASC'),
923
+			)
924
+		);
925
+		$all_expired = true;
926
+		foreach ($tickets as $ticket) {
927
+			if (! $ticket->is_expired()) {
928
+				$all_expired = false;
929
+				break;
930
+			}
931
+		}
932
+		// if all the tickets are just expired, then don't update the event status to sold out
933
+		if ($all_expired) {
934
+			return true;
935
+		}
936
+		$spaces_remaining = $this->spaces_remaining($tickets);
937
+		if ($spaces_remaining < 1) {
938
+			if ($this->status() !== EEM_Event::post_status_private) {
939
+				$this->set_status(EEM_Event::sold_out);
940
+				$this->save();
941
+			}
942
+			$sold_out = true;
943
+		} else {
944
+			$sold_out = false;
945
+			// was event previously marked as sold out ?
946
+			if ($this->status() === EEM_Event::sold_out) {
947
+				// revert status to previous value, if it was set
948
+				$previous_event_status = $this->get_post_meta('_previous_event_status', true);
949
+				if ($previous_event_status) {
950
+					$this->set_status($previous_event_status);
951
+					$this->save();
952
+				}
953
+			}
954
+		}
955
+		do_action('AHEE__EE_Event__perform_sold_out_status_check__end', $this, $sold_out, $spaces_remaining, $tickets);
956
+		return $sold_out;
957
+	}
958
+
959
+
960
+	/**
961
+	 * This returns the total remaining spaces for sale on this event.
962
+	 *
963
+	 * @uses EE_Event::total_available_spaces()
964
+	 * @return float|int
965
+	 * @throws EE_Error
966
+	 * @throws DomainException
967
+	 * @throws UnexpectedEntityException
968
+	 */
969
+	public function spaces_remaining_for_sale()
970
+	{
971
+		return $this->total_available_spaces(true);
972
+	}
973
+
974
+
975
+	/**
976
+	 * This returns the total spaces available for an event
977
+	 * while considering all the qtys on the tickets and the reg limits
978
+	 * on the datetimes attached to this event.
979
+	 *
980
+	 * @param   bool $consider_sold Whether to consider any tickets that have already sold in our calculation.
981
+	 *                              If this is false, then we return the most tickets that could ever be sold
982
+	 *                              for this event with the datetime and tickets setup on the event under optimal
983
+	 *                              selling conditions.  Otherwise we return a live calculation of spaces available
984
+	 *                              based on tickets sold.  Depending on setup and stage of sales, this
985
+	 *                              may appear to equal remaining tickets.  However, the more tickets are
986
+	 *                              sold out, the more accurate the "live" total is.
987
+	 * @return float|int
988
+	 * @throws EE_Error
989
+	 * @throws DomainException
990
+	 * @throws UnexpectedEntityException
991
+	 */
992
+	public function total_available_spaces($consider_sold = false)
993
+	{
994
+		$spaces_available = $consider_sold
995
+			? $this->getAvailableSpacesCalculator()->spacesRemaining()
996
+			: $this->getAvailableSpacesCalculator()->totalSpacesAvailable();
997
+		return apply_filters(
998
+			'FHEE_EE_Event__total_available_spaces__spaces_available',
999
+			$spaces_available,
1000
+			$this,
1001
+			$this->getAvailableSpacesCalculator()->getDatetimes(),
1002
+			$this->getAvailableSpacesCalculator()->getActiveTickets()
1003
+		);
1004
+	}
1005
+
1006
+
1007
+	/**
1008
+	 * Checks if the event is set to sold out
1009
+	 *
1010
+	 * @param  bool $actual whether or not to perform calculations to not only figure the
1011
+	 *                      actual status but also to flip the status if necessary to sold
1012
+	 *                      out If false, we just check the existing status of the event
1013
+	 * @return boolean
1014
+	 * @throws EE_Error
1015
+	 */
1016
+	public function is_sold_out($actual = false)
1017
+	{
1018
+		if (! $actual) {
1019
+			return $this->status() === EEM_Event::sold_out;
1020
+		}
1021
+		return $this->perform_sold_out_status_check();
1022
+	}
1023
+
1024
+
1025
+	/**
1026
+	 * Checks if the event is marked as postponed
1027
+	 *
1028
+	 * @return boolean
1029
+	 */
1030
+	public function is_postponed()
1031
+	{
1032
+		return $this->status() === EEM_Event::postponed;
1033
+	}
1034
+
1035
+
1036
+	/**
1037
+	 * Checks if the event is marked as cancelled
1038
+	 *
1039
+	 * @return boolean
1040
+	 */
1041
+	public function is_cancelled()
1042
+	{
1043
+		return $this->status() === EEM_Event::cancelled;
1044
+	}
1045
+
1046
+
1047
+	/**
1048
+	 * Get the logical active status in a hierarchical order for all the datetimes.  Note
1049
+	 * Basically, we order the datetimes by EVT_start_date.  Then first test on whether the event is published.  If its
1050
+	 * NOT published then we test for whether its expired or not.  IF it IS published then we test first on whether an
1051
+	 * event has any active dates.  If no active dates then we check for any upcoming dates.  If no upcoming dates then
1052
+	 * the event is considered expired.
1053
+	 * NOTE: this method does NOT calculate whether the datetimes are sold out when event is published.  Sold Out is a
1054
+	 * status set on the EVENT when it is not published and thus is done
1055
+	 *
1056
+	 * @param bool $reset
1057
+	 * @return bool | string - based on EE_Datetime active constants or FALSE if error.
1058
+	 * @throws EE_Error
1059
+	 * @throws ReflectionException
1060
+	 */
1061
+	public function get_active_status($reset = false)
1062
+	{
1063
+		// if the active status has already been set, then just use that value (unless we are resetting it)
1064
+		if (! empty($this->_active_status) && ! $reset) {
1065
+			return $this->_active_status;
1066
+		}
1067
+		// first check if event id is present on this object
1068
+		if (! $this->ID()) {
1069
+			return false;
1070
+		}
1071
+		$where_params_for_event = array(array('EVT_ID' => $this->ID()));
1072
+		// if event is published:
1073
+		if ($this->status() === EEM_Event::post_status_publish || $this->status() === EEM_Event::post_status_private) {
1074
+			// active?
1075
+			if (
1076
+				EEM_Datetime::instance()->get_datetime_count_for_status(
1077
+					EE_Datetime::active,
1078
+					$where_params_for_event
1079
+				) > 0
1080
+			) {
1081
+				$this->_active_status = EE_Datetime::active;
1082
+			} else {
1083
+				// upcoming?
1084
+				if (
1085
+					EEM_Datetime::instance()->get_datetime_count_for_status(
1086
+						EE_Datetime::upcoming,
1087
+						$where_params_for_event
1088
+					) > 0
1089
+				) {
1090
+					$this->_active_status = EE_Datetime::upcoming;
1091
+				} else {
1092
+					// expired?
1093
+					if (
1094
+						EEM_Datetime::instance()->get_datetime_count_for_status(
1095
+							EE_Datetime::expired,
1096
+							$where_params_for_event
1097
+						) > 0
1098
+					) {
1099
+						$this->_active_status = EE_Datetime::expired;
1100
+					} else {
1101
+						// it would be odd if things make it this far because it basically means there are no datetime's
1102
+						// attached to the event.  So in this case it will just be considered inactive.
1103
+						$this->_active_status = EE_Datetime::inactive;
1104
+					}
1105
+				}
1106
+			}
1107
+		} else {
1108
+			// the event is not published, so let's just set it's active status according to its' post status
1109
+			switch ($this->status()) {
1110
+				case EEM_Event::sold_out:
1111
+					$this->_active_status = EE_Datetime::sold_out;
1112
+					break;
1113
+				case EEM_Event::cancelled:
1114
+					$this->_active_status = EE_Datetime::cancelled;
1115
+					break;
1116
+				case EEM_Event::postponed:
1117
+					$this->_active_status = EE_Datetime::postponed;
1118
+					break;
1119
+				default:
1120
+					$this->_active_status = EE_Datetime::inactive;
1121
+			}
1122
+		}
1123
+		return $this->_active_status;
1124
+	}
1125
+
1126
+
1127
+	/**
1128
+	 *    pretty_active_status
1129
+	 *
1130
+	 * @access public
1131
+	 * @param boolean $echo whether to return (FALSE), or echo out the result (TRUE)
1132
+	 * @return mixed void|string
1133
+	 * @throws EE_Error
1134
+	 * @throws ReflectionException
1135
+	 */
1136
+	public function pretty_active_status($echo = true)
1137
+	{
1138
+		$active_status = $this->get_active_status();
1139
+		$status = '<span class="ee-status event-active-status-' . esc_attr($active_status) . '">'
1140
+				  . EEH_Template::pretty_status($active_status, false, 'sentence')
1141
+				  . '</span>';
1142
+		if ($echo) {
1143
+			echo wp_kses($status, AllowedTags::getAllowedTags());
1144
+			return '';
1145
+		}
1146
+		return $status; // already escaped
1147
+	}
1148
+
1149
+
1150
+	/**
1151
+	 * @return bool|int
1152
+	 * @throws EE_Error
1153
+	 * @throws ReflectionException
1154
+	 */
1155
+	public function get_number_of_tickets_sold()
1156
+	{
1157
+		$tkt_sold = 0;
1158
+		if (! $this->ID()) {
1159
+			return 0;
1160
+		}
1161
+		$datetimes = $this->datetimes();
1162
+		foreach ($datetimes as $datetime) {
1163
+			if ($datetime instanceof EE_Datetime) {
1164
+				$tkt_sold += $datetime->sold();
1165
+			}
1166
+		}
1167
+		return $tkt_sold;
1168
+	}
1169
+
1170
+
1171
+	/**
1172
+	 * This just returns a count of all the registrations for this event
1173
+	 *
1174
+	 * @access  public
1175
+	 * @return int
1176
+	 * @throws EE_Error
1177
+	 */
1178
+	public function get_count_of_all_registrations()
1179
+	{
1180
+		return EEM_Event::instance()->count_related($this, 'Registration');
1181
+	}
1182
+
1183
+
1184
+	/**
1185
+	 * This returns the ticket with the earliest start time that is
1186
+	 * available for this event (across all datetimes attached to the event)
1187
+	 *
1188
+	 * @return EE_Base_Class|EE_Ticket|null
1189
+	 * @throws EE_Error
1190
+	 * @throws ReflectionException
1191
+	 */
1192
+	public function get_ticket_with_earliest_start_time()
1193
+	{
1194
+		$where['Datetime.EVT_ID'] = $this->ID();
1195
+		$query_params = array($where, 'order_by' => array('TKT_start_date' => 'ASC'));
1196
+		return EE_Registry::instance()->load_model('Ticket')->get_one($query_params);
1197
+	}
1198
+
1199
+
1200
+	/**
1201
+	 * This returns the ticket with the latest end time that is available
1202
+	 * for this event (across all datetimes attached to the event)
1203
+	 *
1204
+	 * @return EE_Base_Class|EE_Ticket|null
1205
+	 * @throws EE_Error
1206
+	 * @throws ReflectionException
1207
+	 */
1208
+	public function get_ticket_with_latest_end_time()
1209
+	{
1210
+		$where['Datetime.EVT_ID'] = $this->ID();
1211
+		$query_params = array($where, 'order_by' => array('TKT_end_date' => 'DESC'));
1212
+		return EE_Registry::instance()->load_model('Ticket')->get_one($query_params);
1213
+	}
1214
+
1215
+
1216
+	/**
1217
+	 * This returns the number of different ticket types currently on sale for this event.
1218
+	 *
1219
+	 * @return int
1220
+	 * @throws EE_Error
1221
+	 * @throws ReflectionException
1222
+	 */
1223
+	public function countTicketsOnSale()
1224
+	{
1225
+		$where = array(
1226
+			'Datetime.EVT_ID' => $this->ID(),
1227
+			'TKT_start_date'  => array('<', time()),
1228
+			'TKT_end_date'    => array('>', time()),
1229
+		);
1230
+		return EEM_Ticket::instance()->count(array($where));
1231
+	}
1232
+
1233
+
1234
+	/**
1235
+	 * This returns whether there are any tickets on sale for this event.
1236
+	 *
1237
+	 * @return bool true = YES tickets on sale.
1238
+	 * @throws EE_Error
1239
+	 */
1240
+	public function tickets_on_sale()
1241
+	{
1242
+		return $this->countTicketsOnSale() > 0;
1243
+	}
1244
+
1245
+
1246
+	/**
1247
+	 * Gets the URL for viewing this event on the front-end. Overrides parent
1248
+	 * to check for an external URL first
1249
+	 *
1250
+	 * @return string
1251
+	 * @throws EE_Error
1252
+	 */
1253
+	public function get_permalink()
1254
+	{
1255
+		if ($this->external_url()) {
1256
+			return $this->external_url();
1257
+		}
1258
+		return parent::get_permalink();
1259
+	}
1260
+
1261
+
1262
+	/**
1263
+	 * Gets the first term for 'espresso_event_categories' we can find
1264
+	 *
1265
+	 * @param array $query_params @see
1266
+	 *                            https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
1267
+	 * @return EE_Base_Class|EE_Term|null
1268
+	 * @throws EE_Error
1269
+	 * @throws ReflectionException
1270
+	 */
1271
+	public function first_event_category($query_params = array())
1272
+	{
1273
+		$query_params[0]['Term_Taxonomy.taxonomy'] = 'espresso_event_categories';
1274
+		$query_params[0]['Term_Taxonomy.Event.EVT_ID'] = $this->ID();
1275
+		return EEM_Term::instance()->get_one($query_params);
1276
+	}
1277
+
1278
+
1279
+	/**
1280
+	 * Gets all terms for 'espresso_event_categories' we can find
1281
+	 *
1282
+	 * @param array $query_params
1283
+	 * @return EE_Base_Class[]|EE_Term[]
1284
+	 * @throws EE_Error
1285
+	 * @throws ReflectionException
1286
+	 */
1287
+	public function get_all_event_categories($query_params = array())
1288
+	{
1289
+		$query_params[0]['Term_Taxonomy.taxonomy'] = 'espresso_event_categories';
1290
+		$query_params[0]['Term_Taxonomy.Event.EVT_ID'] = $this->ID();
1291
+		return EEM_Term::instance()->get_all($query_params);
1292
+	}
1293
+
1294
+
1295
+	/**
1296
+	 * Adds a question group to this event
1297
+	 *
1298
+	 * @param EE_Question_Group|int $question_group_id_or_obj
1299
+	 * @param bool $for_primary if true, the question group will be added for the primary
1300
+	 *                                           registrant, if false will be added for others. default: false
1301
+	 * @return EE_Base_Class|EE_Question_Group
1302
+	 * @throws EE_Error
1303
+	 * @throws InvalidArgumentException
1304
+	 * @throws InvalidDataTypeException
1305
+	 * @throws InvalidInterfaceException
1306
+	 * @throws ReflectionException
1307
+	 */
1308
+	public function add_question_group($question_group_id_or_obj, $for_primary = false)
1309
+	{
1310
+		// If the row already exists, it will be updated. If it doesn't, it will be inserted.
1311
+		// That's in EE_HABTM_Relation::add_relation_to().
1312
+		return $this->_add_relation_to(
1313
+			$question_group_id_or_obj,
1314
+			'Question_Group',
1315
+			[
1316
+				EEM_Event_Question_Group::instance()->fieldNameForContext($for_primary) => true
1317
+			]
1318
+		);
1319
+	}
1320
+
1321
+
1322
+	/**
1323
+	 * Removes a question group from the event
1324
+	 *
1325
+	 * @param EE_Question_Group|int $question_group_id_or_obj
1326
+	 * @param bool $for_primary if true, the question group will be removed from the primary
1327
+	 *                                           registrant, if false will be removed from others. default: false
1328
+	 * @return EE_Base_Class|EE_Question_Group
1329
+	 * @throws EE_Error
1330
+	 * @throws InvalidArgumentException
1331
+	 * @throws ReflectionException
1332
+	 * @throws InvalidDataTypeException
1333
+	 * @throws InvalidInterfaceException
1334
+	 */
1335
+	public function remove_question_group($question_group_id_or_obj, $for_primary = false)
1336
+	{
1337
+		// If the question group is used for the other type (primary or additional)
1338
+		// then just update it. If not, delete it outright.
1339
+		$existing_relation = $this->get_first_related(
1340
+			'Event_Question_Group',
1341
+			[
1342
+				[
1343
+					'QSG_ID' => EEM_Question_Group::instance()->ensure_is_ID($question_group_id_or_obj)
1344
+				]
1345
+			]
1346
+		);
1347
+		$field_to_update = EEM_Event_Question_Group::instance()->fieldNameForContext($for_primary);
1348
+		$other_field = EEM_Event_Question_Group::instance()->fieldNameForContext(! $for_primary);
1349
+		if ($existing_relation->get($other_field) === false) {
1350
+			// Delete it. It's now no longer for primary or additional question groups.
1351
+			return $this->_remove_relation_to($question_group_id_or_obj, 'Question_Group');
1352
+		}
1353
+		// Just update it. They'll still use this question group for the other category
1354
+		$existing_relation->save(
1355
+			[
1356
+				$field_to_update => false
1357
+			]
1358
+		);
1359
+	}
1360
+
1361
+
1362
+	/**
1363
+	 * Gets all the question groups, ordering them by QSG_order ascending
1364
+	 *
1365
+	 * @param array $query_params @see
1366
+	 *                            https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
1367
+	 * @return EE_Base_Class[]|EE_Question_Group[]
1368
+	 * @throws EE_Error
1369
+	 * @throws ReflectionException
1370
+	 */
1371
+	public function question_groups($query_params = array())
1372
+	{
1373
+		$query_params = ! empty($query_params) ? $query_params : array('order_by' => array('QSG_order' => 'ASC'));
1374
+		return $this->get_many_related('Question_Group', $query_params);
1375
+	}
1376
+
1377
+
1378
+	/**
1379
+	 * Implementation for EEI_Has_Icon interface method.
1380
+	 *
1381
+	 * @see EEI_Visual_Representation for comments
1382
+	 * @return string
1383
+	 */
1384
+	public function get_icon()
1385
+	{
1386
+		return '<span class="dashicons dashicons-flag"></span>';
1387
+	}
1388
+
1389
+
1390
+	/**
1391
+	 * Implementation for EEI_Admin_Links interface method.
1392
+	 *
1393
+	 * @see EEI_Admin_Links for comments
1394
+	 * @return string
1395
+	 * @throws EE_Error
1396
+	 */
1397
+	public function get_admin_details_link()
1398
+	{
1399
+		return $this->get_admin_edit_link();
1400
+	}
1401
+
1402
+
1403
+	/**
1404
+	 * Implementation for EEI_Admin_Links interface method.
1405
+	 *
1406
+	 * @return string
1407
+	 * @throws EE_Error*@throws ReflectionException
1408
+	 * @see EEI_Admin_Links for comments
1409
+	 */
1410
+	public function get_admin_edit_link()
1411
+	{
1412
+		return EEH_URL::add_query_args_and_nonce(
1413
+			array(
1414
+				'page'   => 'espresso_events',
1415
+				'action' => 'edit',
1416
+				'post'   => $this->ID(),
1417
+			),
1418
+			admin_url('admin.php')
1419
+		);
1420
+	}
1421
+
1422
+
1423
+	/**
1424
+	 * Implementation for EEI_Admin_Links interface method.
1425
+	 *
1426
+	 * @see EEI_Admin_Links for comments
1427
+	 * @return string
1428
+	 */
1429
+	public function get_admin_settings_link()
1430
+	{
1431
+		return EEH_URL::add_query_args_and_nonce(
1432
+			array(
1433
+				'page'   => 'espresso_events',
1434
+				'action' => 'default_event_settings',
1435
+			),
1436
+			admin_url('admin.php')
1437
+		);
1438
+	}
1439
+
1440
+
1441
+	/**
1442
+	 * Implementation for EEI_Admin_Links interface method.
1443
+	 *
1444
+	 * @see EEI_Admin_Links for comments
1445
+	 * @return string
1446
+	 */
1447
+	public function get_admin_overview_link()
1448
+	{
1449
+		return EEH_URL::add_query_args_and_nonce(
1450
+			array(
1451
+				'page'   => 'espresso_events',
1452
+				'action' => 'default',
1453
+			),
1454
+			admin_url('admin.php')
1455
+		);
1456
+	}
1457 1457
 }
Please login to merge, or discard this patch.
core/services/helpers/datetime/AbstractHelper.php 2 patches
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -49,7 +49,7 @@  discard block
 block discarded – undo
49 49
             new DateTimeZone($timezone_string);
50 50
         } catch (Exception $e) {
51 51
             // sometimes we take exception to exceptions
52
-            if (! $throw_error) {
52
+            if ( ! $throw_error) {
53 53
                 return false;
54 54
             }
55 55
             throw new EE_Error(
@@ -101,7 +101,7 @@  discard block
 block discarded – undo
101 101
     public function getTimezoneOffset(DateTimeZone $date_time_zone, $time = null)
102 102
     {
103 103
         $transition = $this->getTimezoneTransitions($date_time_zone, $time);
104
-        if (! isset($transition['offset'])) {
104
+        if ( ! isset($transition['offset'])) {
105 105
             throw new DomainException(
106 106
                 sprintf(
107 107
                     esc_html__('An invalid timezone transition was received %1$s', 'event_espresso'),
@@ -123,7 +123,7 @@  discard block
 block discarded – undo
123 123
     public function timezoneSelectInput($timezone_string = '')
124 124
     {
125 125
         // get WP date time format
126
-        $datetime_format = get_option('date_format') . ' ' . get_option('time_format');
126
+        $datetime_format = get_option('date_format').' '.get_option('time_format');
127 127
         // if passed a value, then use that, else get WP option
128 128
         $timezone_string = ! empty($timezone_string) ? $timezone_string : (string) get_option('timezone_string');
129 129
         // check if the timezone is valid but don't throw any errors if it isn't
@@ -137,9 +137,9 @@  discard block
 block discarded – undo
137 137
             $timezone_string = 'UTC';
138 138
             $check_zone_info = false;
139 139
             if ($gmt_offset > 0) {
140
-                $timezone_string = 'UTC+' . $gmt_offset;
140
+                $timezone_string = 'UTC+'.$gmt_offset;
141 141
             } elseif ($gmt_offset < 0) {
142
-                $timezone_string = 'UTC' . $gmt_offset;
142
+                $timezone_string = 'UTC'.$gmt_offset;
143 143
             }
144 144
         }
145 145
         ?>
@@ -159,12 +159,12 @@  discard block
 block discarded – undo
159 159
                 esc_html__('%1$sUTC%2$s time is %3$s', 'event_espresso'),
160 160
                 '<abbr title="Coordinated Universal Time">',
161 161
                 '</abbr>',
162
-                '<code>' . date_i18n($datetime_format, false, true) . '</code>'
162
+                '<code>'.date_i18n($datetime_format, false, true).'</code>'
163 163
             );
164 164
             ?></span>
165 165
         <?php
166
-        if (! empty($timezone_string) || ! empty($gmt_offset)) : ?>
167
-        <br/><span><?php printf(esc_html__('Local time is %1$s', 'event_espresso'), '<code>' . date_i18n($datetime_format) . '</code>'); ?></span>
166
+        if ( ! empty($timezone_string) || ! empty($gmt_offset)) : ?>
167
+        <br/><span><?php printf(esc_html__('Local time is %1$s', 'event_espresso'), '<code>'.date_i18n($datetime_format).'</code>'); ?></span>
168 168
             <?php
169 169
         endif; ?>
170 170
 
@@ -204,7 +204,7 @@  discard block
 block discarded – undo
204 204
                     // transition time from date_i18n().
205 205
                     printf(
206 206
                         $message,
207
-                        '<code >' . date_i18n($datetime_format, $tr['ts'] + ($tz_offset - $tr['offset'])) . '</code >'
207
+                        '<code >'.date_i18n($datetime_format, $tr['ts'] + ($tz_offset - $tr['offset'])).'</code >'
208 208
                     );
209 209
                 } else {
210 210
                     esc_html_e('This timezone does not observe daylight saving time.', 'event_espresso');
@@ -237,7 +237,7 @@  discard block
 block discarded – undo
237 237
         $unix_timestamp  = $unix_timestamp === 0 ? time() : (int) $unix_timestamp;
238 238
         $timezone_string = $this->getValidTimezoneString($timezone_string);
239 239
         $TimeZone        = new DateTimeZone($timezone_string);
240
-        $DateTime        = new DateTime('@' . $unix_timestamp, $TimeZone);
240
+        $DateTime        = new DateTime('@'.$unix_timestamp, $TimeZone);
241 241
         $offset          = timezone_offset_get($TimeZone, $DateTime);
242 242
         return (int) $DateTime->format('U') + (int) $offset;
243 243
     }
Please login to merge, or discard this patch.
Indentation   +245 added lines, -245 removed lines patch added patch discarded remove patch
@@ -11,136 +11,136 @@  discard block
 block discarded – undo
11 11
 
12 12
 abstract class AbstractHelper implements HelperInterface
13 13
 {
14
-    /**
15
-     * Ensures that a valid timezone string is returned.
16
-     *
17
-     * @param string $timezone_string  When not provided then attempt to use the timezone_string set in the WP Time
18
-     *                                 settings (or derive from set UTC offset).
19
-     * @return string
20
-     * @throws EE_Error
21
-     */
22
-    public function getValidTimezoneString($timezone_string = '')
23
-    {
24
-        $timezone_string = ! empty($timezone_string) ? $timezone_string : (string) get_option('timezone_string');
25
-        $timezone_string = ! empty($timezone_string)
26
-            ? $timezone_string
27
-            : $this->getTimezoneStringFromGmtOffset();
28
-        $this->validateTimezone($timezone_string);
29
-        return $timezone_string;
30
-    }
14
+	/**
15
+	 * Ensures that a valid timezone string is returned.
16
+	 *
17
+	 * @param string $timezone_string  When not provided then attempt to use the timezone_string set in the WP Time
18
+	 *                                 settings (or derive from set UTC offset).
19
+	 * @return string
20
+	 * @throws EE_Error
21
+	 */
22
+	public function getValidTimezoneString($timezone_string = '')
23
+	{
24
+		$timezone_string = ! empty($timezone_string) ? $timezone_string : (string) get_option('timezone_string');
25
+		$timezone_string = ! empty($timezone_string)
26
+			? $timezone_string
27
+			: $this->getTimezoneStringFromGmtOffset();
28
+		$this->validateTimezone($timezone_string);
29
+		return $timezone_string;
30
+	}
31 31
 
32 32
 
33 33
 
34
-    /**
35
-     * The only purpose for this static method is to validate that the incoming timezone is a valid php timezone.
36
-     *
37
-     * @param string $timezone_string
38
-     * @param bool   $throw_error
39
-     * @return bool
40
-     * @throws EE_Error
41
-     */
42
-    public function validateTimezone($timezone_string, $throw_error = true)
43
-    {
44
-        // easiest way to test a timezone string is just see if it throws an error when you try to create a
45
-        // DateTimeZone object with it
46
-        try {
47
-            new DateTimeZone($timezone_string);
48
-        } catch (Exception $e) {
49
-            // sometimes we take exception to exceptions
50
-            if (! $throw_error) {
51
-                return false;
52
-            }
53
-            throw new EE_Error(
54
-                sprintf(
55
-                    esc_html__(
56
-                        'The timezone given (%1$s), is invalid, please check with %2$sthis list%3$s for what valid timezones can be used',
57
-                        'event_espresso'
58
-                    ),
59
-                    $timezone_string,
60
-                    '<a href="http://www.php.net/manual/en/timezones.php">',
61
-                    '</a>'
62
-                )
63
-            );
64
-        }
65
-        return true;
66
-    }
34
+	/**
35
+	 * The only purpose for this static method is to validate that the incoming timezone is a valid php timezone.
36
+	 *
37
+	 * @param string $timezone_string
38
+	 * @param bool   $throw_error
39
+	 * @return bool
40
+	 * @throws EE_Error
41
+	 */
42
+	public function validateTimezone($timezone_string, $throw_error = true)
43
+	{
44
+		// easiest way to test a timezone string is just see if it throws an error when you try to create a
45
+		// DateTimeZone object with it
46
+		try {
47
+			new DateTimeZone($timezone_string);
48
+		} catch (Exception $e) {
49
+			// sometimes we take exception to exceptions
50
+			if (! $throw_error) {
51
+				return false;
52
+			}
53
+			throw new EE_Error(
54
+				sprintf(
55
+					esc_html__(
56
+						'The timezone given (%1$s), is invalid, please check with %2$sthis list%3$s for what valid timezones can be used',
57
+						'event_espresso'
58
+					),
59
+					$timezone_string,
60
+					'<a href="http://www.php.net/manual/en/timezones.php">',
61
+					'</a>'
62
+				)
63
+			);
64
+		}
65
+		return true;
66
+	}
67 67
 
68 68
 
69
-    /**
70
-     * Gets the site's GMT offset based on either the timezone string
71
-     * (in which case the gmt offset will vary depending on the location's
72
-     * observance of daylight savings time) or the gmt_offset wp option
73
-     *
74
-     * @return int  seconds offset
75
-     */
76
-    public function getSiteTimezoneGmtOffset()
77
-    {
78
-        $timezone_string = (string) get_option('timezone_string');
79
-        if ($timezone_string) {
80
-            try {
81
-                $timezone = new DateTimeZone($timezone_string);
82
-                return $timezone->getOffset(new DateTime()); // in WordPress DateTime defaults to UTC
83
-            } catch (Exception $e) {
84
-            }
85
-        }
86
-        $offset = get_option('gmt_offset');
87
-        return (int) ($offset * HOUR_IN_SECONDS);
88
-    }
69
+	/**
70
+	 * Gets the site's GMT offset based on either the timezone string
71
+	 * (in which case the gmt offset will vary depending on the location's
72
+	 * observance of daylight savings time) or the gmt_offset wp option
73
+	 *
74
+	 * @return int  seconds offset
75
+	 */
76
+	public function getSiteTimezoneGmtOffset()
77
+	{
78
+		$timezone_string = (string) get_option('timezone_string');
79
+		if ($timezone_string) {
80
+			try {
81
+				$timezone = new DateTimeZone($timezone_string);
82
+				return $timezone->getOffset(new DateTime()); // in WordPress DateTime defaults to UTC
83
+			} catch (Exception $e) {
84
+			}
85
+		}
86
+		$offset = get_option('gmt_offset');
87
+		return (int) ($offset * HOUR_IN_SECONDS);
88
+	}
89 89
 
90 90
 
91
-    /**
92
-     * Get Timezone offset for given timezone object
93
-     *
94
-     * @param DateTimeZone $date_time_zone
95
-     * @param null|int     $time
96
-     * @return int
97
-     * @throws DomainException
98
-     */
99
-    public function getTimezoneOffset(DateTimeZone $date_time_zone, $time = null)
100
-    {
101
-        $transition = $this->getTimezoneTransitions($date_time_zone, $time);
102
-        if (! isset($transition['offset'])) {
103
-            throw new DomainException(
104
-                sprintf(
105
-                    esc_html__('An invalid timezone transition was received %1$s', 'event_espresso'),
106
-                    print_r($transition, true)
107
-                )
108
-            );
109
-        }
110
-        return $transition['offset'];
111
-    }
91
+	/**
92
+	 * Get Timezone offset for given timezone object
93
+	 *
94
+	 * @param DateTimeZone $date_time_zone
95
+	 * @param null|int     $time
96
+	 * @return int
97
+	 * @throws DomainException
98
+	 */
99
+	public function getTimezoneOffset(DateTimeZone $date_time_zone, $time = null)
100
+	{
101
+		$transition = $this->getTimezoneTransitions($date_time_zone, $time);
102
+		if (! isset($transition['offset'])) {
103
+			throw new DomainException(
104
+				sprintf(
105
+					esc_html__('An invalid timezone transition was received %1$s', 'event_espresso'),
106
+					print_r($transition, true)
107
+				)
108
+			);
109
+		}
110
+		return $transition['offset'];
111
+	}
112 112
 
113 113
 
114
-    /**
115
-     * Provide a timezone select input
116
-     *
117
-     * @param string $timezone_string
118
-     * @return string
119
-     * @throws EE_Error
120
-     */
121
-    public function timezoneSelectInput($timezone_string = '')
122
-    {
123
-        // get WP date time format
124
-        $datetime_format = get_option('date_format') . ' ' . get_option('time_format');
125
-        // if passed a value, then use that, else get WP option
126
-        $timezone_string = ! empty($timezone_string) ? $timezone_string : (string) get_option('timezone_string');
127
-        // check if the timezone is valid but don't throw any errors if it isn't
128
-        $timezone_string = $this->validateTimezone($timezone_string, false)
129
-            ? $timezone_string
130
-            : '';
131
-        $gmt_offset      = get_option('gmt_offset');
132
-        $check_zone_info = true;
133
-        if (empty($timezone_string)) {
134
-            // Create a UTC+- zone if no timezone string exists
135
-            $timezone_string = 'UTC';
136
-            $check_zone_info = false;
137
-            if ($gmt_offset > 0) {
138
-                $timezone_string = 'UTC+' . $gmt_offset;
139
-            } elseif ($gmt_offset < 0) {
140
-                $timezone_string = 'UTC' . $gmt_offset;
141
-            }
142
-        }
143
-        ?>
114
+	/**
115
+	 * Provide a timezone select input
116
+	 *
117
+	 * @param string $timezone_string
118
+	 * @return string
119
+	 * @throws EE_Error
120
+	 */
121
+	public function timezoneSelectInput($timezone_string = '')
122
+	{
123
+		// get WP date time format
124
+		$datetime_format = get_option('date_format') . ' ' . get_option('time_format');
125
+		// if passed a value, then use that, else get WP option
126
+		$timezone_string = ! empty($timezone_string) ? $timezone_string : (string) get_option('timezone_string');
127
+		// check if the timezone is valid but don't throw any errors if it isn't
128
+		$timezone_string = $this->validateTimezone($timezone_string, false)
129
+			? $timezone_string
130
+			: '';
131
+		$gmt_offset      = get_option('gmt_offset');
132
+		$check_zone_info = true;
133
+		if (empty($timezone_string)) {
134
+			// Create a UTC+- zone if no timezone string exists
135
+			$timezone_string = 'UTC';
136
+			$check_zone_info = false;
137
+			if ($gmt_offset > 0) {
138
+				$timezone_string = 'UTC+' . $gmt_offset;
139
+			} elseif ($gmt_offset < 0) {
140
+				$timezone_string = 'UTC' . $gmt_offset;
141
+			}
142
+		}
143
+		?>
144 144
         <p>
145 145
             <label for="timezone_string"><?php esc_html_e('timezone', 'event_espresso'); ?></label>
146 146
             <select id="timezone_string" name="timezone_string">
@@ -153,150 +153,150 @@  discard block
 block discarded – undo
153 153
         <p>
154 154
         <span>
155 155
             <?php
156
-            printf(
157
-                esc_html__('%1$sUTC%2$s time is %3$s', 'event_espresso'),
158
-                '<abbr title="Coordinated Universal Time">',
159
-                '</abbr>',
160
-                '<code>' . date_i18n($datetime_format, false, true) . '</code>'
161
-            );
162
-            ?></span>
156
+			printf(
157
+				esc_html__('%1$sUTC%2$s time is %3$s', 'event_espresso'),
158
+				'<abbr title="Coordinated Universal Time">',
159
+				'</abbr>',
160
+				'<code>' . date_i18n($datetime_format, false, true) . '</code>'
161
+			);
162
+			?></span>
163 163
         <?php
164
-        if (! empty($timezone_string) || ! empty($gmt_offset)) : ?>
164
+		if (! empty($timezone_string) || ! empty($gmt_offset)) : ?>
165 165
         <br/><span><?php printf(esc_html__('Local time is %1$s', 'event_espresso'), '<code>' . date_i18n($datetime_format) . '</code>'); ?></span>
166 166
             <?php
167
-        endif; ?>
167
+		endif; ?>
168 168
 
169 169
         <?php
170
-        if ($check_zone_info && $timezone_string) : ?>
170
+		if ($check_zone_info && $timezone_string) : ?>
171 171
         <br/>
172 172
         <span>
173 173
                 <?php
174
-                // Set TZ so localtime works.
175
-                date_default_timezone_set($timezone_string);
176
-                $now = localtime(time(), true);
177
-                if ($now['tm_isdst']) {
178
-                    esc_html_e('This timezone is currently in daylight saving time.', 'event_espresso');
179
-                } else {
180
-                    esc_html_e('This timezone is currently in standard time.', 'event_espresso');
181
-                }
182
-                ?>
174
+				// Set TZ so localtime works.
175
+				date_default_timezone_set($timezone_string);
176
+				$now = localtime(time(), true);
177
+				if ($now['tm_isdst']) {
178
+					esc_html_e('This timezone is currently in daylight saving time.', 'event_espresso');
179
+				} else {
180
+					esc_html_e('This timezone is currently in standard time.', 'event_espresso');
181
+				}
182
+				?>
183 183
             <br/>
184 184
             <?php
185
-            if (function_exists('timezone_transitions_get')) {
186
-                $found                   = false;
187
-                $date_time_zone_selected = new DateTimeZone($timezone_string);
188
-                $tz_offset               = timezone_offset_get($date_time_zone_selected, date_create());
189
-                $right_now               = time();
190
-                $tr['isdst']             = false;
191
-                foreach (timezone_transitions_get($date_time_zone_selected) as $tr) {
192
-                    if ($tr['ts'] > $right_now) {
193
-                        $found = true;
194
-                        break;
195
-                    }
196
-                }
197
-                if ($found) {
198
-                    $message = $tr['isdst']
199
-                        ? esc_html__(' Daylight saving time begins on: %s.', 'event_espresso')
200
-                        : esc_html__(' Standard time begins  on: %s.', 'event_espresso');
201
-                    // Add the difference between the current offset and the new offset to ts to get the correct
202
-                    // transition time from date_i18n().
203
-                    printf(
204
-                        $message,
205
-                        '<code >' . date_i18n($datetime_format, $tr['ts'] + ($tz_offset - $tr['offset'])) . '</code >'
206
-                    );
207
-                } else {
208
-                    esc_html_e('This timezone does not observe daylight saving time.', 'event_espresso');
209
-                }
210
-            }
211
-            // Set back to UTC.
212
-            date_default_timezone_set('UTC');
213
-            ?>
185
+			if (function_exists('timezone_transitions_get')) {
186
+				$found                   = false;
187
+				$date_time_zone_selected = new DateTimeZone($timezone_string);
188
+				$tz_offset               = timezone_offset_get($date_time_zone_selected, date_create());
189
+				$right_now               = time();
190
+				$tr['isdst']             = false;
191
+				foreach (timezone_transitions_get($date_time_zone_selected) as $tr) {
192
+					if ($tr['ts'] > $right_now) {
193
+						$found = true;
194
+						break;
195
+					}
196
+				}
197
+				if ($found) {
198
+					$message = $tr['isdst']
199
+						? esc_html__(' Daylight saving time begins on: %s.', 'event_espresso')
200
+						: esc_html__(' Standard time begins  on: %s.', 'event_espresso');
201
+					// Add the difference between the current offset and the new offset to ts to get the correct
202
+					// transition time from date_i18n().
203
+					printf(
204
+						$message,
205
+						'<code >' . date_i18n($datetime_format, $tr['ts'] + ($tz_offset - $tr['offset'])) . '</code >'
206
+					);
207
+				} else {
208
+					esc_html_e('This timezone does not observe daylight saving time.', 'event_espresso');
209
+				}
210
+			}
211
+			// Set back to UTC.
212
+			date_default_timezone_set('UTC');
213
+			?>
214 214
         </span></p>
215 215
             <?php
216
-        endif;
217
-    }
216
+		endif;
217
+	}
218 218
 
219 219
 
220
-    /**
221
-     * This method will take an incoming unix timestamp and add the offset to it for the given timezone_string.
222
-     * If no unix timestamp is given then time() is used.  If no timezone is given then the set timezone string for
223
-     * the site is used.
224
-     * This is used typically when using a Unix timestamp any core WP functions that expect their specially
225
-     * computed timestamp (i.e. date_i18n() )
226
-     *
227
-     * @param int    $unix_timestamp  if 0, then time() will be used.
228
-     * @param string $timezone_string timezone_string. If empty, then the current set timezone for the
229
-     *                                site will be used.
230
-     * @return int      unix_timestamp value with the offset applied for the given timezone.
231
-     * @throws EE_Error
232
-     */
233
-    public function getTimestampWithOffset($unix_timestamp = 0, $timezone_string = '')
234
-    {
235
-        $unix_timestamp  = $unix_timestamp === 0 ? time() : (int) $unix_timestamp;
236
-        $timezone_string = $this->getValidTimezoneString($timezone_string);
237
-        $TimeZone        = new DateTimeZone($timezone_string);
238
-        $DateTime        = new DateTime('@' . $unix_timestamp, $TimeZone);
239
-        $offset          = timezone_offset_get($TimeZone, $DateTime);
240
-        return (int) $DateTime->format('U') + (int) $offset;
241
-    }
220
+	/**
221
+	 * This method will take an incoming unix timestamp and add the offset to it for the given timezone_string.
222
+	 * If no unix timestamp is given then time() is used.  If no timezone is given then the set timezone string for
223
+	 * the site is used.
224
+	 * This is used typically when using a Unix timestamp any core WP functions that expect their specially
225
+	 * computed timestamp (i.e. date_i18n() )
226
+	 *
227
+	 * @param int    $unix_timestamp  if 0, then time() will be used.
228
+	 * @param string $timezone_string timezone_string. If empty, then the current set timezone for the
229
+	 *                                site will be used.
230
+	 * @return int      unix_timestamp value with the offset applied for the given timezone.
231
+	 * @throws EE_Error
232
+	 */
233
+	public function getTimestampWithOffset($unix_timestamp = 0, $timezone_string = '')
234
+	{
235
+		$unix_timestamp  = $unix_timestamp === 0 ? time() : (int) $unix_timestamp;
236
+		$timezone_string = $this->getValidTimezoneString($timezone_string);
237
+		$TimeZone        = new DateTimeZone($timezone_string);
238
+		$DateTime        = new DateTime('@' . $unix_timestamp, $TimeZone);
239
+		$offset          = timezone_offset_get($TimeZone, $DateTime);
240
+		return (int) $DateTime->format('U') + (int) $offset;
241
+	}
242 242
 
243 243
 
244
-    /**
245
-     * Get Timezone Transitions
246
-     *
247
-     * @param DateTimeZone $date_time_zone
248
-     * @param int|null     $time
249
-     * @param bool         $first_only
250
-     * @return array|mixed
251
-     */
252
-    public function getTimezoneTransitions(DateTimeZone $date_time_zone, $time = null, $first_only = true)
253
-    {
254
-        $time        = is_int($time) || $time === null ? $time : (int) strtotime($time);
255
-        $time        = preg_match(EE_Datetime_Field::unix_timestamp_regex, $time) ? $time : time();
256
-        $transitions = $date_time_zone->getTransitions($time);
257
-        return $first_only && ! isset($transitions['ts']) ? reset($transitions) : $transitions;
258
-    }
244
+	/**
245
+	 * Get Timezone Transitions
246
+	 *
247
+	 * @param DateTimeZone $date_time_zone
248
+	 * @param int|null     $time
249
+	 * @param bool         $first_only
250
+	 * @return array|mixed
251
+	 */
252
+	public function getTimezoneTransitions(DateTimeZone $date_time_zone, $time = null, $first_only = true)
253
+	{
254
+		$time        = is_int($time) || $time === null ? $time : (int) strtotime($time);
255
+		$time        = preg_match(EE_Datetime_Field::unix_timestamp_regex, $time) ? $time : time();
256
+		$transitions = $date_time_zone->getTransitions($time);
257
+		return $first_only && ! isset($transitions['ts']) ? reset($transitions) : $transitions;
258
+	}
259 259
 
260 260
 
261 261
 
262
-    /**
263
-     * Default to just returning the provided $gmt_offset.  Children can override if adjustment needed.
264
-     *
265
-     * @param int $gmt_offset
266
-     * @return int
267
-     */
268
-    public function adjustInvalidGmtOffsets($gmt_offset = 0)
269
-    {
270
-        return $gmt_offset;
271
-    }
262
+	/**
263
+	 * Default to just returning the provided $gmt_offset.  Children can override if adjustment needed.
264
+	 *
265
+	 * @param int $gmt_offset
266
+	 * @return int
267
+	 */
268
+	public function adjustInvalidGmtOffsets($gmt_offset = 0)
269
+	{
270
+		return $gmt_offset;
271
+	}
272 272
 
273 273
 
274 274
 
275
-    /**
276
-     * This receives an incoming gmt_offset and santizes it.  If the provide value is an empty string, then this will
277
-     * attempt to get the offset from the timezone string.  If this returns a string, then a timezone string was
278
-     * successfully derived from existing timezone_string in the db.  If not, then a float is returned for the provided
279
-     * offset.
280
-     * @param  float|string $gmt_offset
281
-     * @return float|string
282
-     */
283
-    protected function sanitizeInitialIncomingGmtOffsetForGettingTimezoneString($gmt_offset)
284
-    {
285
-        // if there is no incoming gmt_offset, then because WP hooks in on timezone_string, we need to see if that is
286
-        // set because it will override `gmt_offset` via `pre_get_option` filter.  If that's set, then let's just use
287
-        // that!  Otherwise we'll leave timezone_string at the default of 'UTC' before doing other logic.
288
-        if ($gmt_offset === '') {
289
-            // autoloaded so no need to set to a variable.  There will not be multiple hits to the db.
290
-            if (get_option('timezone_string')) {
291
-                return (string) get_option('timezone_string');
292
-            }
293
-        }
294
-        $gmt_offset = $gmt_offset !== '' ? $gmt_offset : (string) get_option('gmt_offset');
295
-        $gmt_offset = (float) $gmt_offset;
296
-        // if $gmt_offset is 0 or is still an empty string, then just return UTC
297
-        if ($gmt_offset === (float) 0) {
298
-            return 'UTC';
299
-        }
300
-        return $gmt_offset;
301
-    }
275
+	/**
276
+	 * This receives an incoming gmt_offset and santizes it.  If the provide value is an empty string, then this will
277
+	 * attempt to get the offset from the timezone string.  If this returns a string, then a timezone string was
278
+	 * successfully derived from existing timezone_string in the db.  If not, then a float is returned for the provided
279
+	 * offset.
280
+	 * @param  float|string $gmt_offset
281
+	 * @return float|string
282
+	 */
283
+	protected function sanitizeInitialIncomingGmtOffsetForGettingTimezoneString($gmt_offset)
284
+	{
285
+		// if there is no incoming gmt_offset, then because WP hooks in on timezone_string, we need to see if that is
286
+		// set because it will override `gmt_offset` via `pre_get_option` filter.  If that's set, then let's just use
287
+		// that!  Otherwise we'll leave timezone_string at the default of 'UTC' before doing other logic.
288
+		if ($gmt_offset === '') {
289
+			// autoloaded so no need to set to a variable.  There will not be multiple hits to the db.
290
+			if (get_option('timezone_string')) {
291
+				return (string) get_option('timezone_string');
292
+			}
293
+		}
294
+		$gmt_offset = $gmt_offset !== '' ? $gmt_offset : (string) get_option('gmt_offset');
295
+		$gmt_offset = (float) $gmt_offset;
296
+		// if $gmt_offset is 0 or is still an empty string, then just return UTC
297
+		if ($gmt_offset === (float) 0) {
298
+			return 'UTC';
299
+		}
300
+		return $gmt_offset;
301
+	}
302 302
 }
Please login to merge, or discard this patch.
core/services/progress_steps/ProgressStep.php 2 patches
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -121,7 +121,7 @@  discard block
 block discarded – undo
121 121
      */
122 122
     protected function setId($id = '')
123 123
     {
124
-        if (! is_string($id)) {
124
+        if ( ! is_string($id)) {
125 125
             throw new InvalidDataTypeException('$id', $id, 'string');
126 126
         }
127 127
         $this->id = $id;
@@ -144,7 +144,7 @@  discard block
 block discarded – undo
144 144
      */
145 145
     protected function setOrder($order = 0)
146 146
     {
147
-        if (! is_int($order)) {
147
+        if ( ! is_int($order)) {
148 148
             throw new InvalidDataTypeException('$order', $order, 'integer');
149 149
         }
150 150
         $this->order = absint($order);
@@ -173,11 +173,11 @@  discard block
 block discarded – undo
173 173
      */
174 174
     protected function setHtmlClass($html_class)
175 175
     {
176
-        if (! is_string($html_class)) {
176
+        if ( ! is_string($html_class)) {
177 177
             throw new InvalidDataTypeException('$html_class', $html_class, 'string');
178 178
         }
179 179
         if (strpos($html_class, 'progress-step-') === false) {
180
-            $html_class = 'progress-step-' . $html_class;
180
+            $html_class = 'progress-step-'.$html_class;
181 181
         }
182 182
         $this->html_class = $html_class;
183 183
     }
@@ -199,7 +199,7 @@  discard block
 block discarded – undo
199 199
      */
200 200
     protected function setText($text)
201 201
     {
202
-        if (! is_string($text)) {
202
+        if ( ! is_string($text)) {
203 203
             throw new InvalidDataTypeException('$text', $text, 'string');
204 204
         }
205 205
         $this->text = sanitize_text_field($text);
Please login to merge, or discard this patch.
Indentation   +186 added lines, -186 removed lines patch added patch discarded remove patch
@@ -16,190 +16,190 @@
 block discarded – undo
16 16
  */
17 17
 class ProgressStep implements ProgressStepInterface
18 18
 {
19
-    /**
20
-     * @var boolean $current
21
-     */
22
-    private $current = false;
23
-
24
-
25
-    /**
26
-     * @var boolean $completed
27
-     */
28
-    private $completed = false;
29
-
30
-
31
-    /**
32
-     * @var string $html_class
33
-     */
34
-    private $html_class;
35
-
36
-    /**
37
-     * @var string $id
38
-     */
39
-    private $id = '';
40
-
41
-    /**
42
-     * @var int $order
43
-     */
44
-    private $order = 0;
45
-
46
-    /**
47
-     * @var string $text
48
-     */
49
-    private $text = '';
50
-
51
-
52
-    /**
53
-     * ProgressStep constructor
54
-     *
55
-     * @param int    $order
56
-     * @param string $id
57
-     * @param string $html_class
58
-     * @param string $text
59
-     * @throws InvalidDataTypeException
60
-     */
61
-    public function __construct($order, $id, $html_class, $text)
62
-    {
63
-        $this->setOrder($order);
64
-        $this->setId($id);
65
-        $this->setHtmlClass($html_class);
66
-        $this->setText($text);
67
-    }
68
-
69
-
70
-    /**
71
-     * @return boolean
72
-     */
73
-    public function isCurrent()
74
-    {
75
-        return $this->current;
76
-    }
77
-
78
-
79
-    /**
80
-     * @param boolean $current
81
-     */
82
-    public function setIsCurrent($current = true)
83
-    {
84
-        $this->current = filter_var($current, FILTER_VALIDATE_BOOLEAN);
85
-    }
86
-
87
-
88
-    /**
89
-     * @return boolean
90
-     */
91
-    public function isCompleted()
92
-    {
93
-        return $this->completed;
94
-    }
95
-
96
-
97
-    /**
98
-     * @param boolean $completed
99
-     */
100
-    public function setIsCompleted($completed = true)
101
-    {
102
-        $this->completed = filter_var($completed, FILTER_VALIDATE_BOOLEAN);
103
-    }
104
-
105
-
106
-    /**
107
-     * @return string
108
-     */
109
-    public function id()
110
-    {
111
-        return $this->id;
112
-    }
113
-
114
-
115
-    /**
116
-     * @access protected
117
-     * @param string $id
118
-     * @throws InvalidDataTypeException
119
-     */
120
-    protected function setId($id = '')
121
-    {
122
-        if (! is_string($id)) {
123
-            throw new InvalidDataTypeException('$id', $id, 'string');
124
-        }
125
-        $this->id = $id;
126
-    }
127
-
128
-
129
-    /**
130
-     * @return int
131
-     */
132
-    public function order()
133
-    {
134
-        return $this->order;
135
-    }
136
-
137
-
138
-    /**
139
-     * @access protected
140
-     * @param int $order
141
-     * @throws InvalidDataTypeException
142
-     */
143
-    protected function setOrder($order = 0)
144
-    {
145
-        if (! is_int($order)) {
146
-            throw new InvalidDataTypeException('$order', $order, 'integer');
147
-        }
148
-        $this->order = absint($order);
149
-    }
150
-
151
-
152
-    /**
153
-     * @return string
154
-     */
155
-    public function htmlClass()
156
-    {
157
-        $html_class = $this->html_class;
158
-        if ($this->isCurrent()) {
159
-            $html_class .= ' progress-step-active';
160
-        } elseif ($this->isCompleted()) {
161
-            $html_class .= ' progress-step-completed';
162
-        }
163
-        return $html_class;
164
-    }
165
-
166
-
167
-    /**
168
-     * @access protected
169
-     * @param string $html_class
170
-     * @throws InvalidDataTypeException
171
-     */
172
-    protected function setHtmlClass($html_class)
173
-    {
174
-        if (! is_string($html_class)) {
175
-            throw new InvalidDataTypeException('$html_class', $html_class, 'string');
176
-        }
177
-        if (strpos($html_class, 'progress-step-') === false) {
178
-            $html_class = 'progress-step-' . $html_class;
179
-        }
180
-        $this->html_class = $html_class;
181
-    }
182
-
183
-
184
-    /**
185
-     * @return string
186
-     */
187
-    public function text()
188
-    {
189
-        return $this->text;
190
-    }
191
-
192
-
193
-    /**
194
-     * @access protected
195
-     * @param string $text
196
-     * @throws InvalidDataTypeException
197
-     */
198
-    protected function setText($text)
199
-    {
200
-        if (! is_string($text)) {
201
-            throw new InvalidDataTypeException('$text', $text, 'string');
202
-        }
203
-        $this->text = sanitize_text_field($text);
204
-    }
19
+	/**
20
+	 * @var boolean $current
21
+	 */
22
+	private $current = false;
23
+
24
+
25
+	/**
26
+	 * @var boolean $completed
27
+	 */
28
+	private $completed = false;
29
+
30
+
31
+	/**
32
+	 * @var string $html_class
33
+	 */
34
+	private $html_class;
35
+
36
+	/**
37
+	 * @var string $id
38
+	 */
39
+	private $id = '';
40
+
41
+	/**
42
+	 * @var int $order
43
+	 */
44
+	private $order = 0;
45
+
46
+	/**
47
+	 * @var string $text
48
+	 */
49
+	private $text = '';
50
+
51
+
52
+	/**
53
+	 * ProgressStep constructor
54
+	 *
55
+	 * @param int    $order
56
+	 * @param string $id
57
+	 * @param string $html_class
58
+	 * @param string $text
59
+	 * @throws InvalidDataTypeException
60
+	 */
61
+	public function __construct($order, $id, $html_class, $text)
62
+	{
63
+		$this->setOrder($order);
64
+		$this->setId($id);
65
+		$this->setHtmlClass($html_class);
66
+		$this->setText($text);
67
+	}
68
+
69
+
70
+	/**
71
+	 * @return boolean
72
+	 */
73
+	public function isCurrent()
74
+	{
75
+		return $this->current;
76
+	}
77
+
78
+
79
+	/**
80
+	 * @param boolean $current
81
+	 */
82
+	public function setIsCurrent($current = true)
83
+	{
84
+		$this->current = filter_var($current, FILTER_VALIDATE_BOOLEAN);
85
+	}
86
+
87
+
88
+	/**
89
+	 * @return boolean
90
+	 */
91
+	public function isCompleted()
92
+	{
93
+		return $this->completed;
94
+	}
95
+
96
+
97
+	/**
98
+	 * @param boolean $completed
99
+	 */
100
+	public function setIsCompleted($completed = true)
101
+	{
102
+		$this->completed = filter_var($completed, FILTER_VALIDATE_BOOLEAN);
103
+	}
104
+
105
+
106
+	/**
107
+	 * @return string
108
+	 */
109
+	public function id()
110
+	{
111
+		return $this->id;
112
+	}
113
+
114
+
115
+	/**
116
+	 * @access protected
117
+	 * @param string $id
118
+	 * @throws InvalidDataTypeException
119
+	 */
120
+	protected function setId($id = '')
121
+	{
122
+		if (! is_string($id)) {
123
+			throw new InvalidDataTypeException('$id', $id, 'string');
124
+		}
125
+		$this->id = $id;
126
+	}
127
+
128
+
129
+	/**
130
+	 * @return int
131
+	 */
132
+	public function order()
133
+	{
134
+		return $this->order;
135
+	}
136
+
137
+
138
+	/**
139
+	 * @access protected
140
+	 * @param int $order
141
+	 * @throws InvalidDataTypeException
142
+	 */
143
+	protected function setOrder($order = 0)
144
+	{
145
+		if (! is_int($order)) {
146
+			throw new InvalidDataTypeException('$order', $order, 'integer');
147
+		}
148
+		$this->order = absint($order);
149
+	}
150
+
151
+
152
+	/**
153
+	 * @return string
154
+	 */
155
+	public function htmlClass()
156
+	{
157
+		$html_class = $this->html_class;
158
+		if ($this->isCurrent()) {
159
+			$html_class .= ' progress-step-active';
160
+		} elseif ($this->isCompleted()) {
161
+			$html_class .= ' progress-step-completed';
162
+		}
163
+		return $html_class;
164
+	}
165
+
166
+
167
+	/**
168
+	 * @access protected
169
+	 * @param string $html_class
170
+	 * @throws InvalidDataTypeException
171
+	 */
172
+	protected function setHtmlClass($html_class)
173
+	{
174
+		if (! is_string($html_class)) {
175
+			throw new InvalidDataTypeException('$html_class', $html_class, 'string');
176
+		}
177
+		if (strpos($html_class, 'progress-step-') === false) {
178
+			$html_class = 'progress-step-' . $html_class;
179
+		}
180
+		$this->html_class = $html_class;
181
+	}
182
+
183
+
184
+	/**
185
+	 * @return string
186
+	 */
187
+	public function text()
188
+	{
189
+		return $this->text;
190
+	}
191
+
192
+
193
+	/**
194
+	 * @access protected
195
+	 * @param string $text
196
+	 * @throws InvalidDataTypeException
197
+	 */
198
+	protected function setText($text)
199
+	{
200
+		if (! is_string($text)) {
201
+			throw new InvalidDataTypeException('$text', $text, 'string');
202
+		}
203
+		$this->text = sanitize_text_field($text);
204
+	}
205 205
 }
Please login to merge, or discard this patch.