Completed
Branch BUG/3575-event-deletion-previe... (bbeda1)
by
unknown
06:40 queued 04:49
created
core/helpers/EEH_Qtip_Loader.helper.php 2 patches
Indentation   +226 added lines, -226 removed lines patch added patch discarded remove patch
@@ -12,230 +12,230 @@
 block discarded – undo
12 12
 class EEH_Qtip_Loader extends EEH_Base
13 13
 {
14 14
 
15
-    /**
16
-     * EEH_Qtip_Loader Object
17
-     * @var EEH_Qtip_Loader
18
-     * @access private
19
-     */
20
-    private static $_instance = null;
21
-
22
-    /**
23
-     * array of qtip config objects
24
-     * @var EE_Qtip_Config[]
25
-     */
26
-    private $_qtips = array();
27
-
28
-
29
-
30
-    /**
31
-     *@singleton method used to instantiate class object
32
-     *@access public
33
-     *@return EEH_Qtip_Loader instance
34
-     */
35
-    public static function instance()
36
-    {
37
-        // check if class object is instantiated
38
-        if (self::$_instance === null  or ! is_object(self::$_instance) or ! ( self::$_instance instanceof EEH_Qtip_Loader )) {
39
-            self::$_instance = new self();
40
-        }
41
-        return self::$_instance;
42
-    }
43
-
44
-
45
-
46
-    /**
47
-     *private constructor to prevent direct creation
48
-     * @Constructor
49
-     * @access private
50
-     * @return \EEH_Qtip_Loader
51
-     */
52
-    private function __construct()
53
-    {
54
-        // let's just make sure this is instantiated in the right place.
55
-        if (did_action('wp_print_styles') || did_action('admin_head')) {
56
-            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');
57
-        }
58
-    }
59
-
60
-
61
-    /**
62
-     * Call this from wp_enqueue_scripts or admin_enqueue_scripts to setup and enqueue the qtip library
63
-     *
64
-     * @access public
65
-     * @return void
66
-     */
67
-    public function register_and_enqueue()
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';
72
-
73
-        wp_register_script('qtip-map', $qtip_map, array(), '3', true);
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);
76
-
77
-        wp_register_style('qtip-css', $qtipcss, array(), '2.2');
78
-
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)) {
81
-            wp_enqueue_script('ee-qtip-helper');
82
-            wp_enqueue_style('qtip-css');
83
-            $qtips = array();
84
-            foreach ($this->_qtips as $qtip) {
85
-                $qts = $qtip->get_tips();
86
-                foreach ($qts as $qt) {
87
-                    if (! $qt instanceof EE_Qtip) {
88
-                        continue;
89
-                    }
90
-                    $qtips[] = array(
91
-                        'content_id' => $qt->content_id,
92
-                        'options' => $qt->options,
93
-                        'target' => $qt->target,
94
-                        );
95
-                }
96
-            }
97
-            if (!empty($qtips)) {
98
-                wp_localize_script('ee-qtip-helper', 'EE_QTIP_HELPER', array( 'qtips' => $qtips ));
99
-            }
100
-        } else {
101
-            // qtips has been requested without any registration (so assuming its just directly used in the admin).
102
-            wp_enqueue_script('qtip');
103
-            wp_enqueue_style('qtip-css');
104
-        }
105
-    }
106
-
107
-
108
-
109
-    /**
110
-     * This simply registers the given qtip config and:
111
-     * - adds it to the $_qtips property array.
112
-     * - sets up the content containers for all qtips in the config,
113
-     * - registers and enqueues the qtip scripts and styles.
114
-     *
115
-     * @access public
116
-     * @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.
117
-     * @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]
118
-     * @return void
119
-     */
120
-    public function register($configname, $paths = array())
121
-    {
122
-
123
-        // let's just make sure this is instantiated in the right place.
124
-        if (did_action('wp_enqueue_scripts') || did_action('admin_enqueue_scripts')) {
125
-            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');
126
-        }
127
-
128
-        $configname = (array) $configname; // typecast to array
129
-        foreach ($configname as $config) {
130
-            $this->_register($config, $paths);
131
-        }
132
-
133
-        // hook into appropriate footer
134
-        $footer_action = is_admin() ? 'admin_footer' : 'wp_footer';
135
-        add_action($footer_action, array($this, 'setup_qtip'), 10);
136
-
137
-        // make sure we "turn on" qtip js.
138
-        add_filter('FHEE_load_qtip', '__return_true');
139
-    }
140
-
141
-
142
-
143
-    /**
144
-     * private utility for registering and setting up qtip config objects
145
-     *
146
-     * @access private
147
-     * @param  string $config the short name of the class (will be used to generate the expected classname)
148
-     * @param  array  $paths  array of paths to check (or if empty we check core/libraries/qtips or assume its loaded)
149
-     * @throws EE_Error
150
-     * @return void
151
-     */
152
-    private function _register($config, $paths)
153
-    {
154
-        // before doing anything we have to make sure that EE_Qtip_Config parent is required.
155
-        EE_Registry::instance()->load_lib('Qtip_Config', array(), true);
156
-
157
-        if (!empty($paths)) {
158
-            $paths = (array) $paths;
159
-            foreach ($paths as $path) {
160
-                $path = $path . $config . '.lib.php';
161
-                if (!is_readable($path)) {
162
-                    continue;
163
-                } else {
164
-                    require_once $path;
165
-                }
166
-            }
167
-        }
168
-
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)) {
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
-            } else {
175
-                require_once $path;
176
-            }
177
-        }
178
-
179
-        // now we attempt a class_exists one more time.
180
-        if (!class_exists($config)) {
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
-        }
183
-
184
-        // made it HERE?  FINALLY, let's get things setup.
185
-        $a = new ReflectionClass($config);
186
-        $qtip = $a->newInstance();
187
-
188
-        // verify that $qtip is a valid object
189
-        if (! $qtip instanceof EE_Qtip_Config) {
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
-        }
192
-
193
-        $this->_qtips[] = $a->newInstance();
194
-    }
195
-
196
-
197
-
198
-    /**
199
-     * This takes care of generating the qtip content containers.
200
-     * Output gets put in the appropriate page footer (depending on context (either admin_footer or wp_footer) )
201
-     *
202
-     * @access public
203
-     * @return void
204
-     */
205
-    public function setup_qtip()
206
-    {
207
-        if (empty($this->_qtips)) {
208
-            return; // no qtips!
209
-        }
210
-
211
-        $content = array();
212
-
213
-        foreach ($this->_qtips as $qtip) {
214
-            $content[] = $this->_generate_content_container($qtip);
215
-        }
216
-
217
-        echo implode('<br />', $content);
218
-    }
219
-
220
-
221
-    /**
222
-     * Generates a content container from a given EE_Qtip_Config object.
223
-     *
224
-     * @param  EE_Qtip_Config $qtip
225
-     * @return string  (html content container for qtip);
226
-     */
227
-    private function _generate_content_container($qtip)
228
-    {
229
-        $qts = $qtip->get_tips();
230
-        $content = array();
231
-        foreach ($qts as $qt) {
232
-            if (! $qt instanceof EE_Qtip) {
233
-                continue;
234
-            }
235
-            $content[] = '<div class="ee-qtip-helper-content hidden" id="' . esc_attr($qt->content_id) . '">' .
236
-                         $qt->content . '</div>';
237
-        }
238
-
239
-        return implode('<br />', $content);
240
-    }
15
+	/**
16
+	 * EEH_Qtip_Loader Object
17
+	 * @var EEH_Qtip_Loader
18
+	 * @access private
19
+	 */
20
+	private static $_instance = null;
21
+
22
+	/**
23
+	 * array of qtip config objects
24
+	 * @var EE_Qtip_Config[]
25
+	 */
26
+	private $_qtips = array();
27
+
28
+
29
+
30
+	/**
31
+	 *@singleton method used to instantiate class object
32
+	 *@access public
33
+	 *@return EEH_Qtip_Loader instance
34
+	 */
35
+	public static function instance()
36
+	{
37
+		// check if class object is instantiated
38
+		if (self::$_instance === null  or ! is_object(self::$_instance) or ! ( self::$_instance instanceof EEH_Qtip_Loader )) {
39
+			self::$_instance = new self();
40
+		}
41
+		return self::$_instance;
42
+	}
43
+
44
+
45
+
46
+	/**
47
+	 *private constructor to prevent direct creation
48
+	 * @Constructor
49
+	 * @access private
50
+	 * @return \EEH_Qtip_Loader
51
+	 */
52
+	private function __construct()
53
+	{
54
+		// let's just make sure this is instantiated in the right place.
55
+		if (did_action('wp_print_styles') || did_action('admin_head')) {
56
+			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');
57
+		}
58
+	}
59
+
60
+
61
+	/**
62
+	 * Call this from wp_enqueue_scripts or admin_enqueue_scripts to setup and enqueue the qtip library
63
+	 *
64
+	 * @access public
65
+	 * @return void
66
+	 */
67
+	public function register_and_enqueue()
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';
72
+
73
+		wp_register_script('qtip-map', $qtip_map, array(), '3', true);
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);
76
+
77
+		wp_register_style('qtip-css', $qtipcss, array(), '2.2');
78
+
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)) {
81
+			wp_enqueue_script('ee-qtip-helper');
82
+			wp_enqueue_style('qtip-css');
83
+			$qtips = array();
84
+			foreach ($this->_qtips as $qtip) {
85
+				$qts = $qtip->get_tips();
86
+				foreach ($qts as $qt) {
87
+					if (! $qt instanceof EE_Qtip) {
88
+						continue;
89
+					}
90
+					$qtips[] = array(
91
+						'content_id' => $qt->content_id,
92
+						'options' => $qt->options,
93
+						'target' => $qt->target,
94
+						);
95
+				}
96
+			}
97
+			if (!empty($qtips)) {
98
+				wp_localize_script('ee-qtip-helper', 'EE_QTIP_HELPER', array( 'qtips' => $qtips ));
99
+			}
100
+		} else {
101
+			// qtips has been requested without any registration (so assuming its just directly used in the admin).
102
+			wp_enqueue_script('qtip');
103
+			wp_enqueue_style('qtip-css');
104
+		}
105
+	}
106
+
107
+
108
+
109
+	/**
110
+	 * This simply registers the given qtip config and:
111
+	 * - adds it to the $_qtips property array.
112
+	 * - sets up the content containers for all qtips in the config,
113
+	 * - registers and enqueues the qtip scripts and styles.
114
+	 *
115
+	 * @access public
116
+	 * @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.
117
+	 * @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]
118
+	 * @return void
119
+	 */
120
+	public function register($configname, $paths = array())
121
+	{
122
+
123
+		// let's just make sure this is instantiated in the right place.
124
+		if (did_action('wp_enqueue_scripts') || did_action('admin_enqueue_scripts')) {
125
+			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');
126
+		}
127
+
128
+		$configname = (array) $configname; // typecast to array
129
+		foreach ($configname as $config) {
130
+			$this->_register($config, $paths);
131
+		}
132
+
133
+		// hook into appropriate footer
134
+		$footer_action = is_admin() ? 'admin_footer' : 'wp_footer';
135
+		add_action($footer_action, array($this, 'setup_qtip'), 10);
136
+
137
+		// make sure we "turn on" qtip js.
138
+		add_filter('FHEE_load_qtip', '__return_true');
139
+	}
140
+
141
+
142
+
143
+	/**
144
+	 * private utility for registering and setting up qtip config objects
145
+	 *
146
+	 * @access private
147
+	 * @param  string $config the short name of the class (will be used to generate the expected classname)
148
+	 * @param  array  $paths  array of paths to check (or if empty we check core/libraries/qtips or assume its loaded)
149
+	 * @throws EE_Error
150
+	 * @return void
151
+	 */
152
+	private function _register($config, $paths)
153
+	{
154
+		// before doing anything we have to make sure that EE_Qtip_Config parent is required.
155
+		EE_Registry::instance()->load_lib('Qtip_Config', array(), true);
156
+
157
+		if (!empty($paths)) {
158
+			$paths = (array) $paths;
159
+			foreach ($paths as $path) {
160
+				$path = $path . $config . '.lib.php';
161
+				if (!is_readable($path)) {
162
+					continue;
163
+				} else {
164
+					require_once $path;
165
+				}
166
+			}
167
+		}
168
+
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)) {
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
+			} else {
175
+				require_once $path;
176
+			}
177
+		}
178
+
179
+		// now we attempt a class_exists one more time.
180
+		if (!class_exists($config)) {
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
+		}
183
+
184
+		// made it HERE?  FINALLY, let's get things setup.
185
+		$a = new ReflectionClass($config);
186
+		$qtip = $a->newInstance();
187
+
188
+		// verify that $qtip is a valid object
189
+		if (! $qtip instanceof EE_Qtip_Config) {
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
+		}
192
+
193
+		$this->_qtips[] = $a->newInstance();
194
+	}
195
+
196
+
197
+
198
+	/**
199
+	 * This takes care of generating the qtip content containers.
200
+	 * Output gets put in the appropriate page footer (depending on context (either admin_footer or wp_footer) )
201
+	 *
202
+	 * @access public
203
+	 * @return void
204
+	 */
205
+	public function setup_qtip()
206
+	{
207
+		if (empty($this->_qtips)) {
208
+			return; // no qtips!
209
+		}
210
+
211
+		$content = array();
212
+
213
+		foreach ($this->_qtips as $qtip) {
214
+			$content[] = $this->_generate_content_container($qtip);
215
+		}
216
+
217
+		echo implode('<br />', $content);
218
+	}
219
+
220
+
221
+	/**
222
+	 * Generates a content container from a given EE_Qtip_Config object.
223
+	 *
224
+	 * @param  EE_Qtip_Config $qtip
225
+	 * @return string  (html content container for qtip);
226
+	 */
227
+	private function _generate_content_container($qtip)
228
+	{
229
+		$qts = $qtip->get_tips();
230
+		$content = array();
231
+		foreach ($qts as $qt) {
232
+			if (! $qt instanceof EE_Qtip) {
233
+				continue;
234
+			}
235
+			$content[] = '<div class="ee-qtip-helper-content hidden" id="' . esc_attr($qt->content_id) . '">' .
236
+						 $qt->content . '</div>';
237
+		}
238
+
239
+		return implode('<br />', $content);
240
+	}
241 241
 }
Please login to merge, or discard this patch.
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.
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
@@ -10,630 +10,630 @@
 block discarded – undo
10 10
 class EEH_Venue_View extends EEH_Base
11 11
 {
12 12
 
13
-    /**
14
-     * @access    private
15
-     * @var EE_Venue
16
-     */
17
-    private static $_venue = null;
18
-
19
-
20
-    /**
21
-     *    get_venue
22
-     *    attempts to retrieve an EE_Venue object any way it can
23
-     *
24
-     * @access    public
25
-     * @param int  $VNU_ID
26
-     * @param bool $look_in_event
27
-     * @param bool $privacy_check   Defaults to true.
28
-     *                              When false, means even if the venue is private we return it regardless of access.
29
-     * @param bool $password_check
30
-     * @return EE_Venue|null
31
-     * @throws EE_Error
32
-     * @throws ReflectionException
33
-     */
34
-    public static function get_venue($VNU_ID = 0, $look_in_event = true, $privacy_check = true, $password_check = true)
35
-    {
36
-        $VNU_ID = absint($VNU_ID);
37
-        // do we already have the Venue you are looking for?
38
-        if (EEH_Venue_View::$_venue instanceof EE_Venue && $VNU_ID) {
39
-            // If the Venue ID matches $VNU_ID, return the venue.
40
-            if (EEH_Venue_View::$_venue->ID() === $VNU_ID) {
41
-                return EEH_Venue_View::_get_venue($privacy_check);
42
-            }
43
-            // If the Venue ID does not match, try pulling a venue using $VNU_ID.
44
-            $venue = EEM_Venue::instance()->get_one_by_ID($VNU_ID);
45
-            if ($venue instanceof EE_Venue) {
46
-                EEH_Venue_View::$_venue = $venue;
47
-                return EEH_Venue_View::_get_venue($privacy_check);
48
-            }
49
-        }
50
-        // international newspaper?
51
-        global $post;
52
-        if ($post instanceof WP_Post) {
53
-            switch ($post->post_type) {
54
-                // if this is being called from an EE_Venue post,
55
-                // and the EE_Venue post corresponds to the EE_Venue that is being asked for,
56
-                // then we can try to just grab the attached EE_Venue object
57
-                case 'espresso_venues':
58
-                    // the post already contains the related EE_Venue object AND one of the following is TRUE:
59
-                    // the requested Venue ID matches the post ID OR...
60
-                    // there was no specific Venue ID requested
61
-                    if (isset($post->EE_Venue) && ($VNU_ID == $post->ID || ! $VNU_ID)) {
62
-                        // use existing related EE_Venue object
63
-                        EEH_Venue_View::$_venue = $post->EE_Venue;
64
-                    } elseif ($VNU_ID) {
65
-                        // there WAS a specific Venue ID requested, but it's NOT the current post object
66
-                        EEH_Venue_View::$_venue = EEM_Venue::instance()->get_one_by_ID($VNU_ID);
67
-                    } else {
68
-                        // no specific Venue ID requested, so use post ID to generate EE_Venue object
69
-                        EEH_Venue_View::$_venue = EEM_Venue::instance()->get_one_by_ID($post->ID);
70
-                    }
71
-                    break;
72
-
73
-                case 'espresso_events':
74
-                    if ($look_in_event) {
75
-                        // grab the events related venues
76
-                        $venues = EEH_Venue_View::get_event_venues();
77
-                        // make sure the result is an array
78
-                        $venues = is_array($venues) ? $venues : [];
79
-                        // do we have an ID for a specific venue?
80
-                        if ($VNU_ID) {
81
-                            // loop thru the related venues
82
-                            foreach ($venues as $venue) {
83
-                                if ($venue instanceof EE_Venue) {
84
-                                    // until we find the venue we're looking for
85
-                                    if ($venue->ID() == $VNU_ID) {
86
-                                        EEH_Venue_View::$_venue = $venue;
87
-                                        break;
88
-                                    }
89
-                                }
90
-                            }
91
-                            // no venue ID ?
92
-                            // then the global post is an events post and this function was called with no argument
93
-                        } else {
94
-                            // just grab the first related event venue
95
-                            EEH_Venue_View::$_venue = reset($venues);
96
-                        }
97
-                    }
98
-                    break;
99
-            }
100
-        }
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) {
103
-            // sigh... pull it from the db
104
-            EEH_Venue_View::$_venue = EEM_Venue::instance()->get_one_by_ID($VNU_ID);
105
-        }
106
-        return EEH_Venue_View::_get_venue($privacy_check, $password_check);
107
-    }
108
-
109
-
110
-    /**
111
-     * return a single venue
112
-     *
113
-     * @param bool $privacy_check   Defaults to true.
114
-     *                              When false, means even if the venue is private we return it regardless of access.
115
-     * @param bool $password_check
116
-     * @return  EE_Venue
117
-     * @throws EE_Error
118
-     * @throws ReflectionException
119
-     */
120
-    protected static function _get_venue($privacy_check = true, $password_check = true)
121
-    {
122
-        // check for private venues.
123
-        if (
124
-            EEH_Venue_View::$_venue instanceof EE_Venue
125
-            && EEH_Venue_View::$_venue->status() == 'private'
126
-            && $privacy_check
127
-            && ! EE_Registry::instance()->CAP->current_user_can('ee_read_private_venues', 'get_venues')
128
-        ) {
129
-            return null;
130
-        }
131
-        // check for password protected venues
132
-        if (
133
-            EEH_Venue_View::$_venue instanceof EE_Venue
134
-            && $password_check
135
-            && post_password_required(EEH_Venue_View::$_venue->ID())
136
-        ) {
137
-            return null;
138
-        }
139
-        return EEH_Venue_View::$_venue instanceof EE_Venue ? EEH_Venue_View::$_venue : null;
140
-    }
141
-
142
-
143
-    /**
144
-     *  get_event_venues
145
-     *
146
-     * @access     public
147
-     * @return     EE_Venue[]
148
-     * @throws EE_Error
149
-     * @throws ReflectionException
150
-     */
151
-    public static function get_event_venues()
152
-    {
153
-        global $post;
154
-        if ($post->post_type == 'espresso_events') {
155
-            if (isset($post->EE_Event) && $post->EE_Event instanceof EE_Event) {
156
-                return $post->EE_Event->venues();
157
-            }
158
-        }
159
-        return [];
160
-    }
161
-
162
-
163
-    /**
164
-     * Simply checks whether a venue for the given ID (or the internally derived venue is private).
165
-     *
166
-     * Note: This will return true if its private, null if the venue doesn't exist, and false, if the venue exists but
167
-     * is not private.  So it is important to do explicit boolean checks when using this conditional.
168
-     *
169
-     * @param bool $VNU_ID venue to check (optional). If not included will use internally derived venue object.
170
-     *
171
-     * @return bool|null
172
-     * @throws EE_Error
173
-     * @throws ReflectionException
174
-     */
175
-    public static function is_venue_private($VNU_ID = false)
176
-    {
177
-        $venue = EEH_Venue_View::get_venue($VNU_ID);
178
-        if (! $venue instanceof EE_Venue) {
179
-            return null;
180
-        }
181
-
182
-        return $venue->status() == 'private';
183
-    }
184
-
185
-
186
-    /**
187
-     * returns true or false if a venue is password protected or not
188
-     *
189
-     * @param bool $VNU_ID venue to check (optional). If not included will use internally derived venue object.
190
-     * @return bool
191
-     * @throws EE_Error
192
-     * @throws ReflectionException
193
-     */
194
-    public static function is_venue_password_protected($VNU_ID = false)
195
-    {
196
-        $venue = EEH_Venue_View::get_venue($VNU_ID, true, true, false);
197
-        if (
198
-            $venue instanceof EE_Venue
199
-            && post_password_required($venue->ID())
200
-        ) {
201
-            return true;
202
-        }
203
-        return false;
204
-    }
205
-
206
-
207
-    /**
208
-     * If a venue is password protected, this will return the password form for gaining access
209
-     * returns an empty string otherwise
210
-     *
211
-     * @param bool $VNU_ID venue to check (optional). If not included will use internally derived venue object.
212
-     *
213
-     * @return string
214
-     * @throws EE_Error
215
-     * @throws ReflectionException
216
-     */
217
-    public static function password_protected_venue_form($VNU_ID = false)
218
-    {
219
-        $venue = EEH_Venue_View::get_venue($VNU_ID, true, true, false);
220
-        if (
221
-            $venue instanceof EE_Venue
222
-            && post_password_required($venue->ID())
223
-        ) {
224
-            return get_the_password_form($venue->ID());
225
-        }
226
-        return '';
227
-    }
228
-
229
-
230
-    /**
231
-     *    venue_description
232
-     *
233
-     * @access    public
234
-     * @param int $VNU_ID
235
-     * @return string
236
-     * @throws EE_Error
237
-     * @throws ReflectionException
238
-     */
239
-    public static function venue_description($VNU_ID = 0)
240
-    {
241
-        $venue = EEH_Venue_View::get_venue($VNU_ID);
242
-        if ($venue instanceof EE_Venue) {
243
-            return $venue->get_pretty('VNU_desc');
244
-        }
245
-        return '';
246
-    }
247
-
248
-
249
-    /**
250
-     *    venue_excerpt
251
-     *
252
-     * @access    public
253
-     * @param int $VNU_ID
254
-     * @return string
255
-     * @throws EE_Error
256
-     * @throws ReflectionException
257
-     */
258
-    public static function venue_excerpt($VNU_ID = 0)
259
-    {
260
-        $venue = EEH_Venue_View::get_venue($VNU_ID);
261
-        if ($venue instanceof EE_Venue) {
262
-            $excerpt    = $venue->excerpt() != null && $venue->excerpt() ? $venue->excerpt() : $venue->description();
263
-            $venue_link = ' ' . EEH_Venue_View::venue_details_link(
264
-                $venue->ID(),
265
-                esc_html__('more', 'event_espresso') . '&hellip;'
266
-            );
267
-            return ! empty($excerpt) ? wp_trim_words($excerpt, 25, '') . $venue_link : '';
268
-        }
269
-        return '';
270
-    }
271
-
272
-
273
-    /**
274
-     *    venue_categories
275
-     *
276
-     * @access    public
277
-     * @param int  $VNU_ID
278
-     * @param bool $hide_uncategorized
279
-     * @return string
280
-     * @throws EE_Error
281
-     * @throws ReflectionException
282
-     */
283
-    public static function venue_categories($VNU_ID = 0, $hide_uncategorized = true)
284
-    {
285
-        $category_links = [];
286
-        $venue          = EEH_Venue_View::get_venue($VNU_ID);
287
-        if ($venue instanceof EE_Venue) {
288
-            // get category terms
289
-            if ($venue_categories = get_the_terms($venue->ID(), 'espresso_venue_categories')) {
290
-                // loop thru terms and create links
291
-                foreach ($venue_categories as $term) {
292
-                    $url = get_term_link($term, 'espresso_venue_categories');
293
-                    if (
294
-                        ! is_wp_error($url)
295
-                        && (($hide_uncategorized
296
-                             && strtolower($term->name) != esc_html__(
297
-                                 'uncategorized',
298
-                                 'event_espresso'
299
-                             ))
300
-                            || ! $hide_uncategorized)
301
-                    ) {
302
-                        $category_links[] = '<a href="' . esc_url($url) . '" rel="tag">' . $term->name . '</a> ';
303
-                    }
304
-                }
305
-            }
306
-        }
307
-        return implode(', ', $category_links);
308
-    }
309
-
310
-
311
-    /**
312
-     *    venue_address
313
-     *
314
-     * @access    public
315
-     * @param string $type
316
-     * @param int    $VNU_ID
317
-     * @param bool   $use_schema
318
-     * @param bool   $add_wrapper
319
-     * @return string
320
-     * @throws EE_Error
321
-     * @throws ReflectionException
322
-     */
323
-    public static function venue_address($type = 'multiline', $VNU_ID = 0, $use_schema = true, $add_wrapper = true)
324
-    {
325
-        $venue = EEH_Venue_View::get_venue($VNU_ID);
326
-        if ($venue instanceof EE_Venue) {
327
-            return EEH_Address::format($venue, $type, $use_schema, $add_wrapper);
328
-        }
329
-        return '';
330
-    }
331
-
332
-
333
-    /**
334
-     *    venue_has_address
335
-     *
336
-     * @access    public
337
-     * @param int $VNU_ID
338
-     * @return bool|string
339
-     * @throws EE_Error
340
-     * @throws ReflectionException
341
-     */
342
-    public static function venue_has_address($VNU_ID = 0)
343
-    {
344
-        $venue = EEH_Venue_View::get_venue($VNU_ID);
345
-        if ($venue instanceof EE_Venue) {
346
-            return EEH_Address::format($venue, 'inline', false, false);
347
-        }
348
-        return false;
349
-    }
350
-
351
-
352
-    /**
353
-     *    venue_name
354
-     *
355
-     * @access    public
356
-     * @param string $link_to - options( details, website, none ) whether to turn Venue name into a clickable link to
357
-     *                        the Venue's details page or website
358
-     * @param int    $VNU_ID
359
-     * @return string
360
-     * @throws EE_Error
361
-     * @throws ReflectionException
362
-     */
363
-    public static function venue_name($link_to = 'details', $VNU_ID = 0)
364
-    {
365
-        $venue = EEH_Venue_View::get_venue($VNU_ID);
366
-        if ($venue instanceof EE_Venue) {
367
-            $venue_name = apply_filters(
368
-                'FHEE__EEH_Venue__venue_name__append_private_venue_name',
369
-                EEH_Venue_View::is_venue_private()
370
-                    ? EEH_Venue_View::$_venue->name() . "&nbsp;" . esc_html__('(Private)', 'event_espresso')
371
-                    : EEH_Venue_View::$_venue->name(),
372
-                EEH_Venue_View::$_venue
373
-            );
374
-            $venue_name = EEH_Schema::name($venue_name);
375
-
376
-            // if venue is trashed then ignore the "link to" setting because the venue is trashed.
377
-            if ($venue->get('status') == 'trash') {
378
-                $link_to = '';
379
-            }
380
-            switch ($link_to) {
381
-                case 'details':
382
-                    return EEH_Venue_View::venue_details_link($venue->ID(), $venue_name);
383
-
384
-                case 'website':
385
-                    return EEH_Venue_View::venue_website_link($venue->ID(), $venue_name);
386
-
387
-                default:
388
-                    return $venue_name;
389
-            }
390
-        }
391
-        return '';
392
-    }
393
-
394
-
395
-    /**
396
-     *    venue_details_link
397
-     *
398
-     * @access    public
399
-     * @param int    $VNU_ID
400
-     * @param string $text
401
-     * @return string
402
-     * @throws EE_Error
403
-     * @throws ReflectionException
404
-     */
405
-    public static function venue_details_link($VNU_ID = 0, $text = '')
406
-    {
407
-        $venue = EEH_Venue_View::get_venue($VNU_ID);
408
-        if ($venue instanceof EE_Venue) {
409
-            return EEH_Schema::url(get_permalink($venue->ID()), $text);
410
-        }
411
-        return '';
412
-    }
413
-
414
-
415
-    /**
416
-     *    venue_website_link
417
-     *
418
-     * @access    public
419
-     * @param int    $VNU_ID
420
-     * @param string $text
421
-     * @return string
422
-     * @throws EE_Error
423
-     * @throws ReflectionException
424
-     */
425
-    public static function venue_website_link($VNU_ID = 0, $text = '')
426
-    {
427
-        $venue = EEH_Venue_View::get_venue($VNU_ID);
428
-        if ($venue instanceof EE_Venue) {
429
-            $url  = $venue->venue_url();
430
-            $text = ! empty($text) ? $text : $url;
431
-            return ! empty($url) ? EEH_Schema::url($url, $text, ['target' => '_blank']) : '';
432
-        }
433
-        return '';
434
-    }
435
-
436
-
437
-    /**
438
-     *    venue_phone
439
-     *
440
-     * @access    public
441
-     * @param int $VNU_ID
442
-     * @return string
443
-     * @throws EE_Error
444
-     * @throws ReflectionException
445
-     */
446
-    public static function venue_phone($VNU_ID = 0)
447
-    {
448
-        $venue = EEH_Venue_View::get_venue($VNU_ID);
449
-        if ($venue instanceof EE_Venue) {
450
-            return EEH_Schema::telephone($venue->phone());
451
-        }
452
-        return '';
453
-    }
454
-
455
-
456
-    /**
457
-     *    venue_gmap
458
-     *
459
-     * @access    public
460
-     * @param int         $VNU_ID
461
-     * @param bool|string $map_ID a unique identifier for this map
462
-     * @param array       $gmap   map options
463
-     * @return string
464
-     * @throws EE_Error
465
-     * @throws ReflectionException
466
-     */
467
-    public static function venue_gmap($VNU_ID = 0, $map_ID = false, $gmap = [])
468
-    {
469
-
470
-        $venue = EEH_Venue_View::get_venue($VNU_ID);
471
-        if ($venue instanceof EE_Venue) {
472
-            // check for global espresso_events post and use it's ID if no map_ID is set
473
-            global $post;
474
-            $map_ID = empty($map_ID) && $post->post_type == 'espresso_events' ? $post->ID : $map_ID;
475
-            // grab map settings
476
-            $map_cfg = EE_Registry::instance()->CFG->map_settings;
477
-            // are maps enabled ?
478
-            if ($map_cfg->use_google_maps && $venue->enable_for_gmap()) {
479
-                $details_page = is_single();
480
-                $options      = [];
481
-
482
-                $options['map_ID'] = $map_ID && $map_ID != $venue->ID()
483
-                    ? $map_ID . '-' . $venue->ID()
484
-                    : $venue->ID();
485
-
486
-                $options['location'] = EEH_Address::format($venue, 'inline', false, false);
487
-
488
-                $options['ee_map_width'] = $details_page
489
-                    ? $map_cfg->event_details_map_width
490
-                    : $map_cfg->event_list_map_width;
491
-
492
-                $options['ee_map_width'] = isset($gmap['ee_map_width']) && ! empty($gmap['ee_map_width'])
493
-                    ? $gmap['ee_map_width']
494
-                    : $options['ee_map_width'];
495
-
496
-                $options['ee_map_height'] = $details_page
497
-                    ? $map_cfg->event_details_map_height
498
-                    : $map_cfg->event_list_map_height;
499
-
500
-                $options['ee_map_height'] = isset($gmap['ee_map_height']) && ! empty($gmap['ee_map_height'])
501
-                    ? $gmap['ee_map_height']
502
-                    : $options['ee_map_height'];
503
-
504
-                $options['ee_map_zoom'] = $details_page
505
-                    ? $map_cfg->event_details_map_zoom
506
-                    : $map_cfg->event_list_map_zoom;
507
-
508
-                $options['ee_map_zoom'] = isset($gmap['ee_map_zoom']) && ! empty($gmap['ee_map_zoom'])
509
-                    ? $gmap['ee_map_zoom']
510
-                    : $options['ee_map_zoom'];
511
-
512
-                $options['ee_map_nav_display'] = $details_page
513
-                    ? $map_cfg->event_details_display_nav
514
-                    : $map_cfg->event_list_display_nav;
515
-
516
-                $options['ee_map_nav_display'] =
517
-                    isset($gmap['ee_map_nav_display']) && ! empty($gmap['ee_map_nav_display'])
518
-                        ? 'true'
519
-                        : $options['ee_map_nav_display'];
520
-
521
-                $options['ee_map_nav_size'] = $details_page
522
-                    ? $map_cfg->event_details_nav_size
523
-                    : $map_cfg->event_list_nav_size;
524
-
525
-                $options['ee_map_nav_size'] = isset($gmap['ee_map_nav_size']) && ! empty($gmap['ee_map_nav_size'])
526
-                    ? $gmap['ee_map_nav_size']
527
-                    : $options['ee_map_nav_size'];
528
-
529
-                $options['ee_map_type_control'] = $details_page
530
-                    ? $map_cfg->event_details_control_type
531
-                    : $map_cfg->event_list_control_type;
532
-
533
-                $options['ee_map_type_control'] =
534
-                    isset($gmap['ee_map_type_control']) && ! empty($gmap['ee_map_type_control'])
535
-                        ? $gmap['ee_map_type_control']
536
-                        : $options['ee_map_type_control'];
537
-
538
-                $options['ee_map_align'] = $details_page
539
-                    ? $map_cfg->event_details_map_align
540
-                    : $map_cfg->event_list_map_align;
541
-
542
-                $options['ee_map_align'] = isset($gmap['ee_map_align']) && ! empty($gmap['ee_map_align'])
543
-                    ? $gmap['ee_map_align']
544
-                    : $options['ee_map_align'];
545
-
546
-                $options['ee_static_url'] = isset($gmap['ee_static_url']) && ! empty($gmap['ee_static_url'])
547
-                    ? (bool) absint($gmap['ee_static_url'])
548
-                    : $venue->google_map_link();
549
-
550
-                return EEH_Maps::google_map($options);
551
-            }
552
-        }
553
-
554
-        return '';
555
-    }
556
-
557
-
558
-    /**
559
-     * Gets the HTML to display a static map of the venue
560
-     *
561
-     * @param EE_Venue $venue
562
-     * @param array    $attributes like EEH_Maps::google_map_link
563
-     * @return string
564
-     * @throws EE_Error
565
-     * @throws ReflectionException
566
-     */
567
-    public static function espresso_google_static_map(EE_Venue $venue, $attributes = [])
568
-    {
569
-        $state      = $venue->state_obj();
570
-        $country    = $venue->country_obj();
571
-        $attributes = shortcode_atts(
572
-            [
573
-                'id'      => $venue->ID(),
574
-                'address' => $venue->get('VNU_address'),
575
-                'city'    => $venue->get('VNU_city'),
576
-                'state'   => $state instanceof EE_State ? $state->name() : '',
577
-                'zip'     => $venue->get('VNU_zip'),
578
-                'country' => $country instanceof EE_Country ? $country->name() : '',
579
-                'type'    => 'map',
580
-                'map_w'   => 200,
581
-                'map_h'   => 200,
582
-            ],
583
-            $attributes
584
-        );
585
-        return EEH_Maps::google_map_link($attributes);
586
-    }
587
-
588
-
589
-    /**
590
-     *    edit_venue_link
591
-     *
592
-     * @access    public
593
-     * @param int    $VNU_ID
594
-     * @param string $link
595
-     * @param string $before
596
-     * @param string $after
597
-     * @return string
598
-     * @throws EE_Error
599
-     * @throws ReflectionException
600
-     */
601
-    public static function edit_venue_link(
602
-        $VNU_ID = 0,
603
-        $link = '',
604
-        $before = '<p class="edit-venue-lnk small-txt">',
605
-        $after = '</p>'
606
-    ) {
607
-        $venue = EEH_Venue_View::get_venue($VNU_ID);
608
-        if ($venue instanceof EE_Venue) {
609
-            // can the user edit this post ?
610
-            if (current_user_can('edit_post', $venue->ID())) {
611
-                // set link text
612
-                $link = ! empty($link) ? $link : esc_html__('edit this venue', 'event_espresso');
613
-                // generate nonce
614
-                $nonce = wp_create_nonce('edit_nonce');
615
-                // generate url to venue editor for this venue
616
-                $url =
617
-                    add_query_arg(
618
-                        [
619
-                            'page'       => 'espresso_venues',
620
-                            'action'     => 'edit',
621
-                            'post'       => $venue->ID(),
622
-                            'edit_nonce' => $nonce,
623
-                        ],
624
-                        admin_url('admin.php')
625
-                    );
626
-                // get edit CPT text
627
-                $post_type_obj = get_post_type_object('espresso_venues');
628
-                // build final link html
629
-                $link =
630
-                    '<a class="post-edit-link" href="' . $url . '" title="' . esc_attr(
631
-                        $post_type_obj->labels->edit_item
632
-                    ) . '">' . $link . '</a>';
633
-                // put it all together
634
-                return $before . apply_filters('edit_post_link', $link, $venue->ID()) . $after;
635
-            }
636
-        }
637
-        return '';
638
-    }
13
+	/**
14
+	 * @access    private
15
+	 * @var EE_Venue
16
+	 */
17
+	private static $_venue = null;
18
+
19
+
20
+	/**
21
+	 *    get_venue
22
+	 *    attempts to retrieve an EE_Venue object any way it can
23
+	 *
24
+	 * @access    public
25
+	 * @param int  $VNU_ID
26
+	 * @param bool $look_in_event
27
+	 * @param bool $privacy_check   Defaults to true.
28
+	 *                              When false, means even if the venue is private we return it regardless of access.
29
+	 * @param bool $password_check
30
+	 * @return EE_Venue|null
31
+	 * @throws EE_Error
32
+	 * @throws ReflectionException
33
+	 */
34
+	public static function get_venue($VNU_ID = 0, $look_in_event = true, $privacy_check = true, $password_check = true)
35
+	{
36
+		$VNU_ID = absint($VNU_ID);
37
+		// do we already have the Venue you are looking for?
38
+		if (EEH_Venue_View::$_venue instanceof EE_Venue && $VNU_ID) {
39
+			// If the Venue ID matches $VNU_ID, return the venue.
40
+			if (EEH_Venue_View::$_venue->ID() === $VNU_ID) {
41
+				return EEH_Venue_View::_get_venue($privacy_check);
42
+			}
43
+			// If the Venue ID does not match, try pulling a venue using $VNU_ID.
44
+			$venue = EEM_Venue::instance()->get_one_by_ID($VNU_ID);
45
+			if ($venue instanceof EE_Venue) {
46
+				EEH_Venue_View::$_venue = $venue;
47
+				return EEH_Venue_View::_get_venue($privacy_check);
48
+			}
49
+		}
50
+		// international newspaper?
51
+		global $post;
52
+		if ($post instanceof WP_Post) {
53
+			switch ($post->post_type) {
54
+				// if this is being called from an EE_Venue post,
55
+				// and the EE_Venue post corresponds to the EE_Venue that is being asked for,
56
+				// then we can try to just grab the attached EE_Venue object
57
+				case 'espresso_venues':
58
+					// the post already contains the related EE_Venue object AND one of the following is TRUE:
59
+					// the requested Venue ID matches the post ID OR...
60
+					// there was no specific Venue ID requested
61
+					if (isset($post->EE_Venue) && ($VNU_ID == $post->ID || ! $VNU_ID)) {
62
+						// use existing related EE_Venue object
63
+						EEH_Venue_View::$_venue = $post->EE_Venue;
64
+					} elseif ($VNU_ID) {
65
+						// there WAS a specific Venue ID requested, but it's NOT the current post object
66
+						EEH_Venue_View::$_venue = EEM_Venue::instance()->get_one_by_ID($VNU_ID);
67
+					} else {
68
+						// no specific Venue ID requested, so use post ID to generate EE_Venue object
69
+						EEH_Venue_View::$_venue = EEM_Venue::instance()->get_one_by_ID($post->ID);
70
+					}
71
+					break;
72
+
73
+				case 'espresso_events':
74
+					if ($look_in_event) {
75
+						// grab the events related venues
76
+						$venues = EEH_Venue_View::get_event_venues();
77
+						// make sure the result is an array
78
+						$venues = is_array($venues) ? $venues : [];
79
+						// do we have an ID for a specific venue?
80
+						if ($VNU_ID) {
81
+							// loop thru the related venues
82
+							foreach ($venues as $venue) {
83
+								if ($venue instanceof EE_Venue) {
84
+									// until we find the venue we're looking for
85
+									if ($venue->ID() == $VNU_ID) {
86
+										EEH_Venue_View::$_venue = $venue;
87
+										break;
88
+									}
89
+								}
90
+							}
91
+							// no venue ID ?
92
+							// then the global post is an events post and this function was called with no argument
93
+						} else {
94
+							// just grab the first related event venue
95
+							EEH_Venue_View::$_venue = reset($venues);
96
+						}
97
+					}
98
+					break;
99
+			}
100
+		}
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) {
103
+			// sigh... pull it from the db
104
+			EEH_Venue_View::$_venue = EEM_Venue::instance()->get_one_by_ID($VNU_ID);
105
+		}
106
+		return EEH_Venue_View::_get_venue($privacy_check, $password_check);
107
+	}
108
+
109
+
110
+	/**
111
+	 * return a single venue
112
+	 *
113
+	 * @param bool $privacy_check   Defaults to true.
114
+	 *                              When false, means even if the venue is private we return it regardless of access.
115
+	 * @param bool $password_check
116
+	 * @return  EE_Venue
117
+	 * @throws EE_Error
118
+	 * @throws ReflectionException
119
+	 */
120
+	protected static function _get_venue($privacy_check = true, $password_check = true)
121
+	{
122
+		// check for private venues.
123
+		if (
124
+			EEH_Venue_View::$_venue instanceof EE_Venue
125
+			&& EEH_Venue_View::$_venue->status() == 'private'
126
+			&& $privacy_check
127
+			&& ! EE_Registry::instance()->CAP->current_user_can('ee_read_private_venues', 'get_venues')
128
+		) {
129
+			return null;
130
+		}
131
+		// check for password protected venues
132
+		if (
133
+			EEH_Venue_View::$_venue instanceof EE_Venue
134
+			&& $password_check
135
+			&& post_password_required(EEH_Venue_View::$_venue->ID())
136
+		) {
137
+			return null;
138
+		}
139
+		return EEH_Venue_View::$_venue instanceof EE_Venue ? EEH_Venue_View::$_venue : null;
140
+	}
141
+
142
+
143
+	/**
144
+	 *  get_event_venues
145
+	 *
146
+	 * @access     public
147
+	 * @return     EE_Venue[]
148
+	 * @throws EE_Error
149
+	 * @throws ReflectionException
150
+	 */
151
+	public static function get_event_venues()
152
+	{
153
+		global $post;
154
+		if ($post->post_type == 'espresso_events') {
155
+			if (isset($post->EE_Event) && $post->EE_Event instanceof EE_Event) {
156
+				return $post->EE_Event->venues();
157
+			}
158
+		}
159
+		return [];
160
+	}
161
+
162
+
163
+	/**
164
+	 * Simply checks whether a venue for the given ID (or the internally derived venue is private).
165
+	 *
166
+	 * Note: This will return true if its private, null if the venue doesn't exist, and false, if the venue exists but
167
+	 * is not private.  So it is important to do explicit boolean checks when using this conditional.
168
+	 *
169
+	 * @param bool $VNU_ID venue to check (optional). If not included will use internally derived venue object.
170
+	 *
171
+	 * @return bool|null
172
+	 * @throws EE_Error
173
+	 * @throws ReflectionException
174
+	 */
175
+	public static function is_venue_private($VNU_ID = false)
176
+	{
177
+		$venue = EEH_Venue_View::get_venue($VNU_ID);
178
+		if (! $venue instanceof EE_Venue) {
179
+			return null;
180
+		}
181
+
182
+		return $venue->status() == 'private';
183
+	}
184
+
185
+
186
+	/**
187
+	 * returns true or false if a venue is password protected or not
188
+	 *
189
+	 * @param bool $VNU_ID venue to check (optional). If not included will use internally derived venue object.
190
+	 * @return bool
191
+	 * @throws EE_Error
192
+	 * @throws ReflectionException
193
+	 */
194
+	public static function is_venue_password_protected($VNU_ID = false)
195
+	{
196
+		$venue = EEH_Venue_View::get_venue($VNU_ID, true, true, false);
197
+		if (
198
+			$venue instanceof EE_Venue
199
+			&& post_password_required($venue->ID())
200
+		) {
201
+			return true;
202
+		}
203
+		return false;
204
+	}
205
+
206
+
207
+	/**
208
+	 * If a venue is password protected, this will return the password form for gaining access
209
+	 * returns an empty string otherwise
210
+	 *
211
+	 * @param bool $VNU_ID venue to check (optional). If not included will use internally derived venue object.
212
+	 *
213
+	 * @return string
214
+	 * @throws EE_Error
215
+	 * @throws ReflectionException
216
+	 */
217
+	public static function password_protected_venue_form($VNU_ID = false)
218
+	{
219
+		$venue = EEH_Venue_View::get_venue($VNU_ID, true, true, false);
220
+		if (
221
+			$venue instanceof EE_Venue
222
+			&& post_password_required($venue->ID())
223
+		) {
224
+			return get_the_password_form($venue->ID());
225
+		}
226
+		return '';
227
+	}
228
+
229
+
230
+	/**
231
+	 *    venue_description
232
+	 *
233
+	 * @access    public
234
+	 * @param int $VNU_ID
235
+	 * @return string
236
+	 * @throws EE_Error
237
+	 * @throws ReflectionException
238
+	 */
239
+	public static function venue_description($VNU_ID = 0)
240
+	{
241
+		$venue = EEH_Venue_View::get_venue($VNU_ID);
242
+		if ($venue instanceof EE_Venue) {
243
+			return $venue->get_pretty('VNU_desc');
244
+		}
245
+		return '';
246
+	}
247
+
248
+
249
+	/**
250
+	 *    venue_excerpt
251
+	 *
252
+	 * @access    public
253
+	 * @param int $VNU_ID
254
+	 * @return string
255
+	 * @throws EE_Error
256
+	 * @throws ReflectionException
257
+	 */
258
+	public static function venue_excerpt($VNU_ID = 0)
259
+	{
260
+		$venue = EEH_Venue_View::get_venue($VNU_ID);
261
+		if ($venue instanceof EE_Venue) {
262
+			$excerpt    = $venue->excerpt() != null && $venue->excerpt() ? $venue->excerpt() : $venue->description();
263
+			$venue_link = ' ' . EEH_Venue_View::venue_details_link(
264
+				$venue->ID(),
265
+				esc_html__('more', 'event_espresso') . '&hellip;'
266
+			);
267
+			return ! empty($excerpt) ? wp_trim_words($excerpt, 25, '') . $venue_link : '';
268
+		}
269
+		return '';
270
+	}
271
+
272
+
273
+	/**
274
+	 *    venue_categories
275
+	 *
276
+	 * @access    public
277
+	 * @param int  $VNU_ID
278
+	 * @param bool $hide_uncategorized
279
+	 * @return string
280
+	 * @throws EE_Error
281
+	 * @throws ReflectionException
282
+	 */
283
+	public static function venue_categories($VNU_ID = 0, $hide_uncategorized = true)
284
+	{
285
+		$category_links = [];
286
+		$venue          = EEH_Venue_View::get_venue($VNU_ID);
287
+		if ($venue instanceof EE_Venue) {
288
+			// get category terms
289
+			if ($venue_categories = get_the_terms($venue->ID(), 'espresso_venue_categories')) {
290
+				// loop thru terms and create links
291
+				foreach ($venue_categories as $term) {
292
+					$url = get_term_link($term, 'espresso_venue_categories');
293
+					if (
294
+						! is_wp_error($url)
295
+						&& (($hide_uncategorized
296
+							 && strtolower($term->name) != esc_html__(
297
+								 'uncategorized',
298
+								 'event_espresso'
299
+							 ))
300
+							|| ! $hide_uncategorized)
301
+					) {
302
+						$category_links[] = '<a href="' . esc_url($url) . '" rel="tag">' . $term->name . '</a> ';
303
+					}
304
+				}
305
+			}
306
+		}
307
+		return implode(', ', $category_links);
308
+	}
309
+
310
+
311
+	/**
312
+	 *    venue_address
313
+	 *
314
+	 * @access    public
315
+	 * @param string $type
316
+	 * @param int    $VNU_ID
317
+	 * @param bool   $use_schema
318
+	 * @param bool   $add_wrapper
319
+	 * @return string
320
+	 * @throws EE_Error
321
+	 * @throws ReflectionException
322
+	 */
323
+	public static function venue_address($type = 'multiline', $VNU_ID = 0, $use_schema = true, $add_wrapper = true)
324
+	{
325
+		$venue = EEH_Venue_View::get_venue($VNU_ID);
326
+		if ($venue instanceof EE_Venue) {
327
+			return EEH_Address::format($venue, $type, $use_schema, $add_wrapper);
328
+		}
329
+		return '';
330
+	}
331
+
332
+
333
+	/**
334
+	 *    venue_has_address
335
+	 *
336
+	 * @access    public
337
+	 * @param int $VNU_ID
338
+	 * @return bool|string
339
+	 * @throws EE_Error
340
+	 * @throws ReflectionException
341
+	 */
342
+	public static function venue_has_address($VNU_ID = 0)
343
+	{
344
+		$venue = EEH_Venue_View::get_venue($VNU_ID);
345
+		if ($venue instanceof EE_Venue) {
346
+			return EEH_Address::format($venue, 'inline', false, false);
347
+		}
348
+		return false;
349
+	}
350
+
351
+
352
+	/**
353
+	 *    venue_name
354
+	 *
355
+	 * @access    public
356
+	 * @param string $link_to - options( details, website, none ) whether to turn Venue name into a clickable link to
357
+	 *                        the Venue's details page or website
358
+	 * @param int    $VNU_ID
359
+	 * @return string
360
+	 * @throws EE_Error
361
+	 * @throws ReflectionException
362
+	 */
363
+	public static function venue_name($link_to = 'details', $VNU_ID = 0)
364
+	{
365
+		$venue = EEH_Venue_View::get_venue($VNU_ID);
366
+		if ($venue instanceof EE_Venue) {
367
+			$venue_name = apply_filters(
368
+				'FHEE__EEH_Venue__venue_name__append_private_venue_name',
369
+				EEH_Venue_View::is_venue_private()
370
+					? EEH_Venue_View::$_venue->name() . "&nbsp;" . esc_html__('(Private)', 'event_espresso')
371
+					: EEH_Venue_View::$_venue->name(),
372
+				EEH_Venue_View::$_venue
373
+			);
374
+			$venue_name = EEH_Schema::name($venue_name);
375
+
376
+			// if venue is trashed then ignore the "link to" setting because the venue is trashed.
377
+			if ($venue->get('status') == 'trash') {
378
+				$link_to = '';
379
+			}
380
+			switch ($link_to) {
381
+				case 'details':
382
+					return EEH_Venue_View::venue_details_link($venue->ID(), $venue_name);
383
+
384
+				case 'website':
385
+					return EEH_Venue_View::venue_website_link($venue->ID(), $venue_name);
386
+
387
+				default:
388
+					return $venue_name;
389
+			}
390
+		}
391
+		return '';
392
+	}
393
+
394
+
395
+	/**
396
+	 *    venue_details_link
397
+	 *
398
+	 * @access    public
399
+	 * @param int    $VNU_ID
400
+	 * @param string $text
401
+	 * @return string
402
+	 * @throws EE_Error
403
+	 * @throws ReflectionException
404
+	 */
405
+	public static function venue_details_link($VNU_ID = 0, $text = '')
406
+	{
407
+		$venue = EEH_Venue_View::get_venue($VNU_ID);
408
+		if ($venue instanceof EE_Venue) {
409
+			return EEH_Schema::url(get_permalink($venue->ID()), $text);
410
+		}
411
+		return '';
412
+	}
413
+
414
+
415
+	/**
416
+	 *    venue_website_link
417
+	 *
418
+	 * @access    public
419
+	 * @param int    $VNU_ID
420
+	 * @param string $text
421
+	 * @return string
422
+	 * @throws EE_Error
423
+	 * @throws ReflectionException
424
+	 */
425
+	public static function venue_website_link($VNU_ID = 0, $text = '')
426
+	{
427
+		$venue = EEH_Venue_View::get_venue($VNU_ID);
428
+		if ($venue instanceof EE_Venue) {
429
+			$url  = $venue->venue_url();
430
+			$text = ! empty($text) ? $text : $url;
431
+			return ! empty($url) ? EEH_Schema::url($url, $text, ['target' => '_blank']) : '';
432
+		}
433
+		return '';
434
+	}
435
+
436
+
437
+	/**
438
+	 *    venue_phone
439
+	 *
440
+	 * @access    public
441
+	 * @param int $VNU_ID
442
+	 * @return string
443
+	 * @throws EE_Error
444
+	 * @throws ReflectionException
445
+	 */
446
+	public static function venue_phone($VNU_ID = 0)
447
+	{
448
+		$venue = EEH_Venue_View::get_venue($VNU_ID);
449
+		if ($venue instanceof EE_Venue) {
450
+			return EEH_Schema::telephone($venue->phone());
451
+		}
452
+		return '';
453
+	}
454
+
455
+
456
+	/**
457
+	 *    venue_gmap
458
+	 *
459
+	 * @access    public
460
+	 * @param int         $VNU_ID
461
+	 * @param bool|string $map_ID a unique identifier for this map
462
+	 * @param array       $gmap   map options
463
+	 * @return string
464
+	 * @throws EE_Error
465
+	 * @throws ReflectionException
466
+	 */
467
+	public static function venue_gmap($VNU_ID = 0, $map_ID = false, $gmap = [])
468
+	{
469
+
470
+		$venue = EEH_Venue_View::get_venue($VNU_ID);
471
+		if ($venue instanceof EE_Venue) {
472
+			// check for global espresso_events post and use it's ID if no map_ID is set
473
+			global $post;
474
+			$map_ID = empty($map_ID) && $post->post_type == 'espresso_events' ? $post->ID : $map_ID;
475
+			// grab map settings
476
+			$map_cfg = EE_Registry::instance()->CFG->map_settings;
477
+			// are maps enabled ?
478
+			if ($map_cfg->use_google_maps && $venue->enable_for_gmap()) {
479
+				$details_page = is_single();
480
+				$options      = [];
481
+
482
+				$options['map_ID'] = $map_ID && $map_ID != $venue->ID()
483
+					? $map_ID . '-' . $venue->ID()
484
+					: $venue->ID();
485
+
486
+				$options['location'] = EEH_Address::format($venue, 'inline', false, false);
487
+
488
+				$options['ee_map_width'] = $details_page
489
+					? $map_cfg->event_details_map_width
490
+					: $map_cfg->event_list_map_width;
491
+
492
+				$options['ee_map_width'] = isset($gmap['ee_map_width']) && ! empty($gmap['ee_map_width'])
493
+					? $gmap['ee_map_width']
494
+					: $options['ee_map_width'];
495
+
496
+				$options['ee_map_height'] = $details_page
497
+					? $map_cfg->event_details_map_height
498
+					: $map_cfg->event_list_map_height;
499
+
500
+				$options['ee_map_height'] = isset($gmap['ee_map_height']) && ! empty($gmap['ee_map_height'])
501
+					? $gmap['ee_map_height']
502
+					: $options['ee_map_height'];
503
+
504
+				$options['ee_map_zoom'] = $details_page
505
+					? $map_cfg->event_details_map_zoom
506
+					: $map_cfg->event_list_map_zoom;
507
+
508
+				$options['ee_map_zoom'] = isset($gmap['ee_map_zoom']) && ! empty($gmap['ee_map_zoom'])
509
+					? $gmap['ee_map_zoom']
510
+					: $options['ee_map_zoom'];
511
+
512
+				$options['ee_map_nav_display'] = $details_page
513
+					? $map_cfg->event_details_display_nav
514
+					: $map_cfg->event_list_display_nav;
515
+
516
+				$options['ee_map_nav_display'] =
517
+					isset($gmap['ee_map_nav_display']) && ! empty($gmap['ee_map_nav_display'])
518
+						? 'true'
519
+						: $options['ee_map_nav_display'];
520
+
521
+				$options['ee_map_nav_size'] = $details_page
522
+					? $map_cfg->event_details_nav_size
523
+					: $map_cfg->event_list_nav_size;
524
+
525
+				$options['ee_map_nav_size'] = isset($gmap['ee_map_nav_size']) && ! empty($gmap['ee_map_nav_size'])
526
+					? $gmap['ee_map_nav_size']
527
+					: $options['ee_map_nav_size'];
528
+
529
+				$options['ee_map_type_control'] = $details_page
530
+					? $map_cfg->event_details_control_type
531
+					: $map_cfg->event_list_control_type;
532
+
533
+				$options['ee_map_type_control'] =
534
+					isset($gmap['ee_map_type_control']) && ! empty($gmap['ee_map_type_control'])
535
+						? $gmap['ee_map_type_control']
536
+						: $options['ee_map_type_control'];
537
+
538
+				$options['ee_map_align'] = $details_page
539
+					? $map_cfg->event_details_map_align
540
+					: $map_cfg->event_list_map_align;
541
+
542
+				$options['ee_map_align'] = isset($gmap['ee_map_align']) && ! empty($gmap['ee_map_align'])
543
+					? $gmap['ee_map_align']
544
+					: $options['ee_map_align'];
545
+
546
+				$options['ee_static_url'] = isset($gmap['ee_static_url']) && ! empty($gmap['ee_static_url'])
547
+					? (bool) absint($gmap['ee_static_url'])
548
+					: $venue->google_map_link();
549
+
550
+				return EEH_Maps::google_map($options);
551
+			}
552
+		}
553
+
554
+		return '';
555
+	}
556
+
557
+
558
+	/**
559
+	 * Gets the HTML to display a static map of the venue
560
+	 *
561
+	 * @param EE_Venue $venue
562
+	 * @param array    $attributes like EEH_Maps::google_map_link
563
+	 * @return string
564
+	 * @throws EE_Error
565
+	 * @throws ReflectionException
566
+	 */
567
+	public static function espresso_google_static_map(EE_Venue $venue, $attributes = [])
568
+	{
569
+		$state      = $venue->state_obj();
570
+		$country    = $venue->country_obj();
571
+		$attributes = shortcode_atts(
572
+			[
573
+				'id'      => $venue->ID(),
574
+				'address' => $venue->get('VNU_address'),
575
+				'city'    => $venue->get('VNU_city'),
576
+				'state'   => $state instanceof EE_State ? $state->name() : '',
577
+				'zip'     => $venue->get('VNU_zip'),
578
+				'country' => $country instanceof EE_Country ? $country->name() : '',
579
+				'type'    => 'map',
580
+				'map_w'   => 200,
581
+				'map_h'   => 200,
582
+			],
583
+			$attributes
584
+		);
585
+		return EEH_Maps::google_map_link($attributes);
586
+	}
587
+
588
+
589
+	/**
590
+	 *    edit_venue_link
591
+	 *
592
+	 * @access    public
593
+	 * @param int    $VNU_ID
594
+	 * @param string $link
595
+	 * @param string $before
596
+	 * @param string $after
597
+	 * @return string
598
+	 * @throws EE_Error
599
+	 * @throws ReflectionException
600
+	 */
601
+	public static function edit_venue_link(
602
+		$VNU_ID = 0,
603
+		$link = '',
604
+		$before = '<p class="edit-venue-lnk small-txt">',
605
+		$after = '</p>'
606
+	) {
607
+		$venue = EEH_Venue_View::get_venue($VNU_ID);
608
+		if ($venue instanceof EE_Venue) {
609
+			// can the user edit this post ?
610
+			if (current_user_can('edit_post', $venue->ID())) {
611
+				// set link text
612
+				$link = ! empty($link) ? $link : esc_html__('edit this venue', 'event_espresso');
613
+				// generate nonce
614
+				$nonce = wp_create_nonce('edit_nonce');
615
+				// generate url to venue editor for this venue
616
+				$url =
617
+					add_query_arg(
618
+						[
619
+							'page'       => 'espresso_venues',
620
+							'action'     => 'edit',
621
+							'post'       => $venue->ID(),
622
+							'edit_nonce' => $nonce,
623
+						],
624
+						admin_url('admin.php')
625
+					);
626
+				// get edit CPT text
627
+				$post_type_obj = get_post_type_object('espresso_venues');
628
+				// build final link html
629
+				$link =
630
+					'<a class="post-edit-link" href="' . $url . '" title="' . esc_attr(
631
+						$post_type_obj->labels->edit_item
632
+					) . '">' . $link . '</a>';
633
+				// put it all together
634
+				return $before . apply_filters('edit_post_link', $link, $venue->ID()) . $after;
635
+			}
636
+		}
637
+		return '';
638
+	}
639 639
 }
Please login to merge, or discard this patch.
core/helpers/EEH_Event_View.helper.php 2 patches
Indentation   +614 added lines, -614 removed lines patch added patch discarded remove patch
@@ -10,364 +10,364 @@  discard block
 block discarded – undo
10 10
 class EEH_Event_View extends EEH_Base
11 11
 {
12 12
 
13
-    /**
14
-     * @var EE_Event $_event
15
-     */
16
-    private static $_event = null;
17
-
18
-
19
-    /**
20
-     * get_event
21
-     * attempts to retrieve an EE_Event object any way it can
22
-     *
23
-     * @param int|WP_Post $EVT_ID
24
-     * @return EE_Event|null
25
-     * @throws EE_Error
26
-     * @throws ReflectionException
27
-     */
28
-    public static function get_event($EVT_ID = 0)
29
-    {
30
-        // international newspaper?
31
-        global $post;
32
-        $EVT_ID = $EVT_ID instanceof WP_Post && $EVT_ID->post_type === 'espresso_events'
33
-            ? $EVT_ID->ID
34
-            : absint($EVT_ID);
35
-        // do we already have the Event  you are looking for?
36
-        if (EEH_Event_View::$_event instanceof EE_Event && $EVT_ID && EEH_Event_View::$_event->ID() === $EVT_ID) {
37
-            return EEH_Event_View::$_event;
38
-        }
39
-        // reset property so that the new event is cached.
40
-        EEH_Event_View::$_event = null;
41
-        if (! $EVT_ID && $post instanceof EE_Event) {
42
-            EEH_Event_View::$_event = $post;
43
-            return EEH_Event_View::$_event;
44
-        }
45
-        // if the post type is for an event and it has a cached event and we don't have a different incoming $EVT_ID
46
-        // then let's just use that cached event on the $post object.
47
-        if (
48
-            $post instanceof WP_Post
49
-            && $post->post_type === 'espresso_events'
50
-            && isset($post->EE_Event)
51
-            && (
52
-                $EVT_ID === 0
53
-                || $EVT_ID === $post->ID
54
-            )
55
-        ) {
56
-            EEH_Event_View::$_event = $post->EE_Event;
57
-            return EEH_Event_View::$_event;
58
-        }
59
-        // If the event we have isn't an event but we do have an EVT_ID, let's try getting the event using the ID.
60
-        if (! EEH_Event_View::$_event instanceof EE_Event && $EVT_ID) {
61
-            EEH_Event_View::$_event = EEM_Event::instance()->get_one_by_ID($EVT_ID);
62
-        }
63
-        return EEH_Event_View::$_event;
64
-    }
65
-
66
-
67
-    /**
68
-     *    display_ticket_selector
69
-     *
70
-     * @param int $EVT_ID
71
-     * @return    boolean
72
-     * @throws EE_Error
73
-     * @throws EE_Error
74
-     * @throws ReflectionException
75
-     */
76
-    public static function display_ticket_selector($EVT_ID = 0)
77
-    {
78
-        $event = EEH_Event_View::get_event($EVT_ID);
79
-        return $event instanceof EE_Event && $event->display_ticket_selector();
80
-    }
81
-
82
-
83
-    /**
84
-     *    event_status
85
-     *
86
-     * @param int $EVT_ID
87
-     * @return    string
88
-     * @throws EE_Error
89
-     * @throws EE_Error
90
-     * @throws ReflectionException
91
-     */
92
-    public static function event_status($EVT_ID = 0)
93
-    {
94
-        $event = EEH_Event_View::get_event($EVT_ID);
95
-        return $event instanceof EE_Event ? $event->pretty_active_status(false) : '';
96
-    }
97
-
98
-
99
-    /**
100
-     *  event_active_status
101
-     *
102
-     * @param int $EVT_ID
103
-     * @return     string
104
-     * @throws EE_Error
105
-     * @throws EE_Error
106
-     * @throws ReflectionException
107
-     */
108
-    public static function event_active_status($EVT_ID = 0, $echo = true)
109
-    {
110
-        $event = EEH_Event_View::get_event($EVT_ID);
111
-        return $event instanceof EE_Event ? $event->pretty_active_status($echo) : 'inactive';
112
-    }
113
-
114
-
115
-    /**
116
-     *  event_has_content_or_excerpt
117
-     *
118
-     * @param int $EVT_ID
119
-     * @return     bool
120
-     * @throws EE_Error
121
-     * @throws EE_Error
122
-     * @throws ReflectionException
123
-     */
124
-    public static function event_has_content_or_excerpt($EVT_ID = 0)
125
-    {
126
-        $event                  = EEH_Event_View::get_event($EVT_ID);
127
-        $has_content_or_excerpt = false;
128
-        if ($event instanceof EE_Event) {
129
-            $has_content_or_excerpt = $event->description() != '' || $event->short_description(null, null, true) != '';
130
-        }
131
-        if (
132
-            is_archive()
133
-            && ! (espresso_display_full_description_in_event_list()
134
-                  || espresso_display_excerpt_in_event_list())
135
-        ) {
136
-            $has_content_or_excerpt = false;
137
-        }
138
-        return $has_content_or_excerpt;
139
-    }
140
-
141
-
142
-    /**
143
-     *    event_active_status
144
-     *
145
-     * @param null $num_words
146
-     * @param null $more
147
-     * @return    string
148
-     */
149
-    public static function event_content_or_excerpt($num_words = null, $more = null)
150
-    {
151
-        global $post;
152
-        ob_start();
153
-        if ((is_single()) || (is_archive() && espresso_display_full_description_in_event_list())) {
154
-            // admin has chosen "full description"
155
-            // for the "Event Espresso - Events > Templates > Display Description" option
156
-            the_content();
157
-        } elseif ((is_archive() && espresso_display_excerpt_in_event_list())) {
158
-            if (has_excerpt($post->ID)) {
159
-                // admin has chosen "excerpt (short desc)"
160
-                // for the "Event Espresso - Events > Templates > Display Description" option
161
-                // AND an excerpt actually exists
162
-                the_excerpt();
163
-            } else {
164
-                // admin has chosen "excerpt (short desc)"
165
-                // for the "Event Espresso - Events > Templates > Display Description" option
166
-                // but NO excerpt actually exists, so we need to create one
167
-                if (! empty($num_words)) {
168
-                    if (empty($more)) {
169
-                        $more_link_text = esc_html__('(more&hellip;)', 'event_espresso');
170
-                        $more           = ' <a href="' . get_permalink() . '"';
171
-                        $more           .= ' class="more-link"';
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);
175
-                    }
176
-                    $content = str_replace('NOMORELINK', '', get_the_content('NOMORELINK'));
177
-
178
-                    $content = wp_trim_words($content, $num_words, ' ') . $more;
179
-                } else {
180
-                    $content = get_the_content();
181
-                }
182
-                global $allowedtags;
183
-                // make sure links are allowed
184
-                $allowedtags['a'] = isset($allowedtags['a'])
185
-                    ? $allowedtags['a']
186
-                    : [];
187
-                // as well as target attribute
188
-                $allowedtags['a']['target'] = isset($allowedtags['a']['target'])
189
-                    ? $allowedtags['a']['target']
190
-                    : false;
191
-                // but get previous value so we can reset it
192
-                $prev_value                 = $allowedtags['a']['target'];
193
-                $allowedtags['a']['target'] = true;
194
-                $content                    = wp_kses($content, $allowedtags);
195
-                $content                    = strip_shortcodes($content);
196
-                echo apply_filters('the_content', $content);
197
-                $allowedtags['a']['target'] = $prev_value;
198
-            }
199
-        } else {
200
-            // admin has chosen "none"
201
-            // for the "Event Espresso - Events > Templates > Display Description" option
202
-            echo apply_filters('the_content', '');
203
-        }
204
-        return ob_get_clean();
205
-    }
206
-
207
-
208
-    /**
209
-     *  event_tickets_available
210
-     *
211
-     * @param int $EVT_ID
212
-     * @return     EE_Ticket[]
213
-     * @throws EE_Error
214
-     * @throws ReflectionException
215
-     */
216
-    public static function event_tickets_available($EVT_ID = 0)
217
-    {
218
-        $event                          = EEH_Event_View::get_event($EVT_ID);
219
-        $tickets_available_for_purchase = [];
220
-        if ($event instanceof EE_Event) {
221
-            $datetimes = EEH_Event_View::get_all_date_obj($EVT_ID, false);
222
-            foreach ($datetimes as $datetime) {
223
-                $tickets_available_for_purchase =
224
-                    array_merge($tickets_available_for_purchase, $datetime->ticket_types_available_for_purchase());
225
-            }
226
-        }
227
-        return $tickets_available_for_purchase;
228
-    }
229
-
230
-
231
-    /**
232
-     *    the_event_date
233
-     *
234
-     * @param int  $EVT_ID
235
-     * @param bool $hide_uncategorized
236
-     * @return    string
237
-     * @throws EE_Error
238
-     * @throws ReflectionException
239
-     */
240
-    public static function event_categories($EVT_ID = 0, $hide_uncategorized = true)
241
-    {
242
-        $category_links = [];
243
-        $event          = EEH_Event_View::get_event($EVT_ID);
244
-        if ($event instanceof EE_Event) {
245
-            $event_categories = get_the_terms($event->ID(), 'espresso_event_categories');
246
-            if ($event_categories) {
247
-                // loop thru terms and create links
248
-                foreach ($event_categories as $term) {
249
-                    $url = get_term_link($term, 'espresso_venue_categories');
250
-                    if (
251
-                        ! is_wp_error($url)
252
-                        && (
253
-                            (
254
-                                $hide_uncategorized
255
-                                && strtolower($term->name) != esc_html__('uncategorized', 'event_espresso')
256
-                            )
257
-                            || ! $hide_uncategorized
258
-                        )
259
-                    ) {
260
-                        $category_links[] = '<a href="' . esc_url_raw($url) . '" '
261
-                                            . 'rel="tag" ' . EED_Events_Archive::link_target() . '>'
262
-                                            . esc_html($term->name)
263
-                                            . '</a>';
264
-                    }
265
-                }
266
-            }
267
-        }
268
-        return implode(', ', $category_links);
269
-    }
270
-
271
-
272
-    /**
273
-     *    the_event_date - first date by date order
274
-     *
275
-     * @param string $date_format
276
-     * @param string $time_format
277
-     * @param int    $EVT_ID
278
-     * @return    string
279
-     * @throws EE_Error
280
-     * @throws ReflectionException
281
-     */
282
-    public static function the_event_date($date_format = 'D M jS', $time_format = 'g:i a', $EVT_ID = 0)
283
-    {
284
-        $datetime = EEH_Event_View::get_primary_date_obj($EVT_ID);
285
-        $format   = ! empty($date_format) && ! empty($time_format)
286
-                ? $date_format . ' ' . $time_format
287
-                : $date_format . $time_format;
288
-        return $datetime instanceof EE_Datetime ? $datetime->get_i18n_datetime('DTT_EVT_start', $format) : '';
289
-    }
290
-
291
-
292
-    /**
293
-     *    the_event_end_date - last date by date order
294
-     *
295
-     * @param string $date_format
296
-     * @param string $time_format
297
-     * @param int    $EVT_ID
298
-     * @return    string
299
-     * @throws EE_Error
300
-     * @throws ReflectionException
301
-     */
302
-    public static function the_event_end_date($date_format = 'D M jS', $time_format = 'g:i a', $EVT_ID = 0)
303
-    {
304
-        $datetime = EEH_Event_View::get_last_date_obj($EVT_ID);
305
-        $format   =
306
-            ! empty($date_format) && ! empty($time_format)
307
-                ? $date_format . ' ' . $time_format
308
-                : $date_format
309
-                  . $time_format;
310
-        return $datetime instanceof EE_Datetime ? $datetime->get_i18n_datetime('DTT_EVT_end', $format) : '';
311
-    }
312
-
313
-
314
-    /**
315
-     *    the_earliest_event_date - first date chronologically
316
-     *
317
-     * @param string $date_format
318
-     * @param string $time_format
319
-     * @param int    $EVT_ID
320
-     * @return    string
321
-     * @throws EE_Error
322
-     * @throws ReflectionException
323
-     */
324
-    public static function the_earliest_event_date($date_format = 'D M jS', $time_format = 'g:i a', $EVT_ID = 0)
325
-    {
326
-        $datetime = EEH_Event_View::get_earliest_date_obj($EVT_ID);
327
-        $format   =
328
-            ! empty($date_format) && ! empty($time_format)
329
-                ? $date_format . ' ' . $time_format
330
-                : $date_format
331
-                  . $time_format;
332
-        return $datetime instanceof EE_Datetime ? $datetime->get_i18n_datetime('DTT_EVT_start', $format) : '';
333
-    }
334
-
335
-
336
-    /**
337
-     *    the_latest_event_date - latest date chronologically
338
-     *
339
-     * @param string $date_format
340
-     * @param string $time_format
341
-     * @param int    $EVT_ID
342
-     * @return    string
343
-     * @throws EE_Error
344
-     * @throws ReflectionException
345
-     */
346
-    public static function the_latest_event_date($date_format = 'D M jS', $time_format = 'g:i a', $EVT_ID = 0)
347
-    {
348
-        $datetime = EEH_Event_View::get_latest_date_obj($EVT_ID);
349
-        $format   =
350
-            ! empty($date_format) && ! empty($time_format)
351
-                ? $date_format . ' ' . $time_format
352
-                : $date_format
353
-                  . $time_format;
354
-        return $datetime instanceof EE_Datetime ? $datetime->get_i18n_datetime('DTT_EVT_end', $format) : '';
355
-    }
356
-
357
-
358
-    /**
359
-     *    event_date_as_calendar_page
360
-     *
361
-     * @param int $EVT_ID
362
-     * @return    void
363
-     * @throws EE_Error
364
-     * @throws ReflectionException
365
-     */
366
-    public static function event_date_as_calendar_page($EVT_ID = 0)
367
-    {
368
-        $datetime = EEH_Event_View::get_primary_date_obj($EVT_ID);
369
-        if ($datetime instanceof EE_Datetime) {
370
-            ?>
13
+	/**
14
+	 * @var EE_Event $_event
15
+	 */
16
+	private static $_event = null;
17
+
18
+
19
+	/**
20
+	 * get_event
21
+	 * attempts to retrieve an EE_Event object any way it can
22
+	 *
23
+	 * @param int|WP_Post $EVT_ID
24
+	 * @return EE_Event|null
25
+	 * @throws EE_Error
26
+	 * @throws ReflectionException
27
+	 */
28
+	public static function get_event($EVT_ID = 0)
29
+	{
30
+		// international newspaper?
31
+		global $post;
32
+		$EVT_ID = $EVT_ID instanceof WP_Post && $EVT_ID->post_type === 'espresso_events'
33
+			? $EVT_ID->ID
34
+			: absint($EVT_ID);
35
+		// do we already have the Event  you are looking for?
36
+		if (EEH_Event_View::$_event instanceof EE_Event && $EVT_ID && EEH_Event_View::$_event->ID() === $EVT_ID) {
37
+			return EEH_Event_View::$_event;
38
+		}
39
+		// reset property so that the new event is cached.
40
+		EEH_Event_View::$_event = null;
41
+		if (! $EVT_ID && $post instanceof EE_Event) {
42
+			EEH_Event_View::$_event = $post;
43
+			return EEH_Event_View::$_event;
44
+		}
45
+		// if the post type is for an event and it has a cached event and we don't have a different incoming $EVT_ID
46
+		// then let's just use that cached event on the $post object.
47
+		if (
48
+			$post instanceof WP_Post
49
+			&& $post->post_type === 'espresso_events'
50
+			&& isset($post->EE_Event)
51
+			&& (
52
+				$EVT_ID === 0
53
+				|| $EVT_ID === $post->ID
54
+			)
55
+		) {
56
+			EEH_Event_View::$_event = $post->EE_Event;
57
+			return EEH_Event_View::$_event;
58
+		}
59
+		// If the event we have isn't an event but we do have an EVT_ID, let's try getting the event using the ID.
60
+		if (! EEH_Event_View::$_event instanceof EE_Event && $EVT_ID) {
61
+			EEH_Event_View::$_event = EEM_Event::instance()->get_one_by_ID($EVT_ID);
62
+		}
63
+		return EEH_Event_View::$_event;
64
+	}
65
+
66
+
67
+	/**
68
+	 *    display_ticket_selector
69
+	 *
70
+	 * @param int $EVT_ID
71
+	 * @return    boolean
72
+	 * @throws EE_Error
73
+	 * @throws EE_Error
74
+	 * @throws ReflectionException
75
+	 */
76
+	public static function display_ticket_selector($EVT_ID = 0)
77
+	{
78
+		$event = EEH_Event_View::get_event($EVT_ID);
79
+		return $event instanceof EE_Event && $event->display_ticket_selector();
80
+	}
81
+
82
+
83
+	/**
84
+	 *    event_status
85
+	 *
86
+	 * @param int $EVT_ID
87
+	 * @return    string
88
+	 * @throws EE_Error
89
+	 * @throws EE_Error
90
+	 * @throws ReflectionException
91
+	 */
92
+	public static function event_status($EVT_ID = 0)
93
+	{
94
+		$event = EEH_Event_View::get_event($EVT_ID);
95
+		return $event instanceof EE_Event ? $event->pretty_active_status(false) : '';
96
+	}
97
+
98
+
99
+	/**
100
+	 *  event_active_status
101
+	 *
102
+	 * @param int $EVT_ID
103
+	 * @return     string
104
+	 * @throws EE_Error
105
+	 * @throws EE_Error
106
+	 * @throws ReflectionException
107
+	 */
108
+	public static function event_active_status($EVT_ID = 0, $echo = true)
109
+	{
110
+		$event = EEH_Event_View::get_event($EVT_ID);
111
+		return $event instanceof EE_Event ? $event->pretty_active_status($echo) : 'inactive';
112
+	}
113
+
114
+
115
+	/**
116
+	 *  event_has_content_or_excerpt
117
+	 *
118
+	 * @param int $EVT_ID
119
+	 * @return     bool
120
+	 * @throws EE_Error
121
+	 * @throws EE_Error
122
+	 * @throws ReflectionException
123
+	 */
124
+	public static function event_has_content_or_excerpt($EVT_ID = 0)
125
+	{
126
+		$event                  = EEH_Event_View::get_event($EVT_ID);
127
+		$has_content_or_excerpt = false;
128
+		if ($event instanceof EE_Event) {
129
+			$has_content_or_excerpt = $event->description() != '' || $event->short_description(null, null, true) != '';
130
+		}
131
+		if (
132
+			is_archive()
133
+			&& ! (espresso_display_full_description_in_event_list()
134
+				  || espresso_display_excerpt_in_event_list())
135
+		) {
136
+			$has_content_or_excerpt = false;
137
+		}
138
+		return $has_content_or_excerpt;
139
+	}
140
+
141
+
142
+	/**
143
+	 *    event_active_status
144
+	 *
145
+	 * @param null $num_words
146
+	 * @param null $more
147
+	 * @return    string
148
+	 */
149
+	public static function event_content_or_excerpt($num_words = null, $more = null)
150
+	{
151
+		global $post;
152
+		ob_start();
153
+		if ((is_single()) || (is_archive() && espresso_display_full_description_in_event_list())) {
154
+			// admin has chosen "full description"
155
+			// for the "Event Espresso - Events > Templates > Display Description" option
156
+			the_content();
157
+		} elseif ((is_archive() && espresso_display_excerpt_in_event_list())) {
158
+			if (has_excerpt($post->ID)) {
159
+				// admin has chosen "excerpt (short desc)"
160
+				// for the "Event Espresso - Events > Templates > Display Description" option
161
+				// AND an excerpt actually exists
162
+				the_excerpt();
163
+			} else {
164
+				// admin has chosen "excerpt (short desc)"
165
+				// for the "Event Espresso - Events > Templates > Display Description" option
166
+				// but NO excerpt actually exists, so we need to create one
167
+				if (! empty($num_words)) {
168
+					if (empty($more)) {
169
+						$more_link_text = esc_html__('(more&hellip;)', 'event_espresso');
170
+						$more           = ' <a href="' . get_permalink() . '"';
171
+						$more           .= ' class="more-link"';
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);
175
+					}
176
+					$content = str_replace('NOMORELINK', '', get_the_content('NOMORELINK'));
177
+
178
+					$content = wp_trim_words($content, $num_words, ' ') . $more;
179
+				} else {
180
+					$content = get_the_content();
181
+				}
182
+				global $allowedtags;
183
+				// make sure links are allowed
184
+				$allowedtags['a'] = isset($allowedtags['a'])
185
+					? $allowedtags['a']
186
+					: [];
187
+				// as well as target attribute
188
+				$allowedtags['a']['target'] = isset($allowedtags['a']['target'])
189
+					? $allowedtags['a']['target']
190
+					: false;
191
+				// but get previous value so we can reset it
192
+				$prev_value                 = $allowedtags['a']['target'];
193
+				$allowedtags['a']['target'] = true;
194
+				$content                    = wp_kses($content, $allowedtags);
195
+				$content                    = strip_shortcodes($content);
196
+				echo apply_filters('the_content', $content);
197
+				$allowedtags['a']['target'] = $prev_value;
198
+			}
199
+		} else {
200
+			// admin has chosen "none"
201
+			// for the "Event Espresso - Events > Templates > Display Description" option
202
+			echo apply_filters('the_content', '');
203
+		}
204
+		return ob_get_clean();
205
+	}
206
+
207
+
208
+	/**
209
+	 *  event_tickets_available
210
+	 *
211
+	 * @param int $EVT_ID
212
+	 * @return     EE_Ticket[]
213
+	 * @throws EE_Error
214
+	 * @throws ReflectionException
215
+	 */
216
+	public static function event_tickets_available($EVT_ID = 0)
217
+	{
218
+		$event                          = EEH_Event_View::get_event($EVT_ID);
219
+		$tickets_available_for_purchase = [];
220
+		if ($event instanceof EE_Event) {
221
+			$datetimes = EEH_Event_View::get_all_date_obj($EVT_ID, false);
222
+			foreach ($datetimes as $datetime) {
223
+				$tickets_available_for_purchase =
224
+					array_merge($tickets_available_for_purchase, $datetime->ticket_types_available_for_purchase());
225
+			}
226
+		}
227
+		return $tickets_available_for_purchase;
228
+	}
229
+
230
+
231
+	/**
232
+	 *    the_event_date
233
+	 *
234
+	 * @param int  $EVT_ID
235
+	 * @param bool $hide_uncategorized
236
+	 * @return    string
237
+	 * @throws EE_Error
238
+	 * @throws ReflectionException
239
+	 */
240
+	public static function event_categories($EVT_ID = 0, $hide_uncategorized = true)
241
+	{
242
+		$category_links = [];
243
+		$event          = EEH_Event_View::get_event($EVT_ID);
244
+		if ($event instanceof EE_Event) {
245
+			$event_categories = get_the_terms($event->ID(), 'espresso_event_categories');
246
+			if ($event_categories) {
247
+				// loop thru terms and create links
248
+				foreach ($event_categories as $term) {
249
+					$url = get_term_link($term, 'espresso_venue_categories');
250
+					if (
251
+						! is_wp_error($url)
252
+						&& (
253
+							(
254
+								$hide_uncategorized
255
+								&& strtolower($term->name) != esc_html__('uncategorized', 'event_espresso')
256
+							)
257
+							|| ! $hide_uncategorized
258
+						)
259
+					) {
260
+						$category_links[] = '<a href="' . esc_url_raw($url) . '" '
261
+											. 'rel="tag" ' . EED_Events_Archive::link_target() . '>'
262
+											. esc_html($term->name)
263
+											. '</a>';
264
+					}
265
+				}
266
+			}
267
+		}
268
+		return implode(', ', $category_links);
269
+	}
270
+
271
+
272
+	/**
273
+	 *    the_event_date - first date by date order
274
+	 *
275
+	 * @param string $date_format
276
+	 * @param string $time_format
277
+	 * @param int    $EVT_ID
278
+	 * @return    string
279
+	 * @throws EE_Error
280
+	 * @throws ReflectionException
281
+	 */
282
+	public static function the_event_date($date_format = 'D M jS', $time_format = 'g:i a', $EVT_ID = 0)
283
+	{
284
+		$datetime = EEH_Event_View::get_primary_date_obj($EVT_ID);
285
+		$format   = ! empty($date_format) && ! empty($time_format)
286
+				? $date_format . ' ' . $time_format
287
+				: $date_format . $time_format;
288
+		return $datetime instanceof EE_Datetime ? $datetime->get_i18n_datetime('DTT_EVT_start', $format) : '';
289
+	}
290
+
291
+
292
+	/**
293
+	 *    the_event_end_date - last date by date order
294
+	 *
295
+	 * @param string $date_format
296
+	 * @param string $time_format
297
+	 * @param int    $EVT_ID
298
+	 * @return    string
299
+	 * @throws EE_Error
300
+	 * @throws ReflectionException
301
+	 */
302
+	public static function the_event_end_date($date_format = 'D M jS', $time_format = 'g:i a', $EVT_ID = 0)
303
+	{
304
+		$datetime = EEH_Event_View::get_last_date_obj($EVT_ID);
305
+		$format   =
306
+			! empty($date_format) && ! empty($time_format)
307
+				? $date_format . ' ' . $time_format
308
+				: $date_format
309
+				  . $time_format;
310
+		return $datetime instanceof EE_Datetime ? $datetime->get_i18n_datetime('DTT_EVT_end', $format) : '';
311
+	}
312
+
313
+
314
+	/**
315
+	 *    the_earliest_event_date - first date chronologically
316
+	 *
317
+	 * @param string $date_format
318
+	 * @param string $time_format
319
+	 * @param int    $EVT_ID
320
+	 * @return    string
321
+	 * @throws EE_Error
322
+	 * @throws ReflectionException
323
+	 */
324
+	public static function the_earliest_event_date($date_format = 'D M jS', $time_format = 'g:i a', $EVT_ID = 0)
325
+	{
326
+		$datetime = EEH_Event_View::get_earliest_date_obj($EVT_ID);
327
+		$format   =
328
+			! empty($date_format) && ! empty($time_format)
329
+				? $date_format . ' ' . $time_format
330
+				: $date_format
331
+				  . $time_format;
332
+		return $datetime instanceof EE_Datetime ? $datetime->get_i18n_datetime('DTT_EVT_start', $format) : '';
333
+	}
334
+
335
+
336
+	/**
337
+	 *    the_latest_event_date - latest date chronologically
338
+	 *
339
+	 * @param string $date_format
340
+	 * @param string $time_format
341
+	 * @param int    $EVT_ID
342
+	 * @return    string
343
+	 * @throws EE_Error
344
+	 * @throws ReflectionException
345
+	 */
346
+	public static function the_latest_event_date($date_format = 'D M jS', $time_format = 'g:i a', $EVT_ID = 0)
347
+	{
348
+		$datetime = EEH_Event_View::get_latest_date_obj($EVT_ID);
349
+		$format   =
350
+			! empty($date_format) && ! empty($time_format)
351
+				? $date_format . ' ' . $time_format
352
+				: $date_format
353
+				  . $time_format;
354
+		return $datetime instanceof EE_Datetime ? $datetime->get_i18n_datetime('DTT_EVT_end', $format) : '';
355
+	}
356
+
357
+
358
+	/**
359
+	 *    event_date_as_calendar_page
360
+	 *
361
+	 * @param int $EVT_ID
362
+	 * @return    void
363
+	 * @throws EE_Error
364
+	 * @throws ReflectionException
365
+	 */
366
+	public static function event_date_as_calendar_page($EVT_ID = 0)
367
+	{
368
+		$datetime = EEH_Event_View::get_primary_date_obj($EVT_ID);
369
+		if ($datetime instanceof EE_Datetime) {
370
+			?>
371 371
             <div class="event-date-calendar-page-dv">
372 372
                 <div class="event-date-calendar-page-month-dv">
373 373
                     <?php echo $datetime->get_i18n_datetime('DTT_EVT_start', 'M'); // already escaped ?>
@@ -377,260 +377,260 @@  discard block
 block discarded – undo
377 377
                 </div>
378 378
             </div>
379 379
             <?php
380
-        }
381
-    }
382
-
383
-
384
-    /**
385
-     *    get_primary_date_obj - orders date by DTT_order
386
-     *
387
-     * @param int $EVT_ID
388
-     * @return EE_Datetime
389
-     * @throws EE_Error
390
-     * @throws ReflectionException
391
-     */
392
-    public static function get_primary_date_obj($EVT_ID = 0)
393
-    {
394
-        $event = EEH_Event_View::get_event($EVT_ID);
395
-        if ($event instanceof EE_Event) {
396
-            $datetimes = $event->get_many_related(
397
-                'Datetime',
398
-                [
399
-                    'limit'    => 1,
400
-                    'order_by' => ['DTT_order' => 'ASC'],
401
-                ]
402
-            );
403
-            return reset($datetimes);
404
-        }
405
-        return null;
406
-    }
407
-
408
-
409
-    /**
410
-     *    get_last_date_obj - orders date by DTT_order
411
-     *
412
-     * @param int $EVT_ID
413
-     * @return EE_Datetime
414
-     * @throws EE_Error
415
-     * @throws ReflectionException
416
-     */
417
-    public static function get_last_date_obj($EVT_ID = 0)
418
-    {
419
-        $event = EEH_Event_View::get_event($EVT_ID);
420
-        if ($event instanceof EE_Event) {
421
-            $datetimes = $event->get_many_related(
422
-                'Datetime',
423
-                [
424
-                    'limit'    => 1,
425
-                    'order_by' => ['DTT_order' => 'DESC'],
426
-                ]
427
-            );
428
-            return end($datetimes);
429
-        }
430
-        return null;
431
-    }
432
-
433
-
434
-    /**
435
-     *    get_earliest_date_obj - orders date chronologically
436
-     *
437
-     * @param int $EVT_ID
438
-     * @return EE_Datetime
439
-     * @throws EE_Error
440
-     * @throws ReflectionException
441
-     */
442
-    public static function get_earliest_date_obj($EVT_ID = 0)
443
-    {
444
-        $event = EEH_Event_View::get_event($EVT_ID);
445
-        if ($event instanceof EE_Event) {
446
-            $datetimes = $event->get_many_related(
447
-                'Datetime',
448
-                [
449
-                    'limit'    => 1,
450
-                    'order_by' => ['DTT_EVT_start' => 'ASC'],
451
-                ]
452
-            );
453
-            return reset($datetimes);
454
-        }
455
-        return null;
456
-    }
457
-
458
-
459
-    /**
460
-     *    get_latest_date_obj - orders date chronologically
461
-     *
462
-     * @param int $EVT_ID
463
-     * @return EE_Datetime
464
-     * @throws EE_Error
465
-     * @throws ReflectionException
466
-     */
467
-    public static function get_latest_date_obj($EVT_ID = 0)
468
-    {
469
-        $event = EEH_Event_View::get_event($EVT_ID);
470
-        if ($event instanceof EE_Event) {
471
-            $datetimes = $event->get_many_related(
472
-                'Datetime',
473
-                [
474
-                    'limit'    => 1,
475
-                    'order_by' => ['DTT_EVT_start' => 'DESC'],
476
-                ]
477
-            );
478
-            return end($datetimes);
479
-        }
480
-        return null;
481
-    }
482
-
483
-
484
-    /**
485
-     *    get_next_upcoming_date_obj - return the next upcoming datetime
486
-     *
487
-     * @param int $EVT_ID
488
-     * @return    EE_Datetime|null
489
-     * @throws EE_Error
490
-     * @throws EE_Error
491
-     */
492
-    public static function get_next_upcoming_date_obj($EVT_ID = 0)
493
-    {
494
-        $datetime = EEM_Datetime::instance()->get_one(
495
-            [
496
-                [
497
-                    'Event.EVT_ID'  => $EVT_ID,
498
-                    'DTT_EVT_start' => ['>=', current_time('mysql', true)],
499
-                ],
500
-                'order_by' => ['DTT_EVT_start' => 'asc'],
501
-            ]
502
-        );
503
-        return $datetime instanceof EE_Datetime ? $datetime : null;
504
-    }
505
-
506
-
507
-    /**
508
-     *    get_all_date_obj
509
-     *
510
-     * @param int  $EVT_ID
511
-     * @param null $include_expired
512
-     * @param bool $include_deleted
513
-     * @param null $limit
514
-     * @return EE_Datetime[]
515
-     * @throws EE_Error
516
-     * @throws EE_Error
517
-     * @throws ReflectionException
518
-     */
519
-    public static function get_all_date_obj(
520
-        $EVT_ID = 0,
521
-        $include_expired = null,
522
-        $include_deleted = false,
523
-        $limit = null
524
-    ) {
525
-        $event = EEH_Event_View::get_event($EVT_ID);
526
-        if ($include_expired === null) {
527
-            if ($event instanceof EE_Event && $event->is_expired()) {
528
-                $include_expired = true;
529
-            } else {
530
-                $include_expired = false;
531
-            }
532
-        }
533
-
534
-        if ($event instanceof EE_Event) {
535
-            return $event->datetimes_ordered($include_expired, $include_deleted, $limit);
536
-        }
537
-        return [];
538
-    }
539
-
540
-
541
-    /**
542
-     *    event_link_url
543
-     *
544
-     * @param int $EVT_ID
545
-     * @return string
546
-     * @throws EE_Error
547
-     * @throws ReflectionException
548
-     */
549
-    public static function event_link_url($EVT_ID = 0)
550
-    {
551
-        $event = EEH_Event_View::get_event($EVT_ID);
552
-        if ($event instanceof EE_Event) {
553
-            $url = $event->external_url() !== null && $event->external_url() !== ''
554
-                ? $event->external_url()
555
-                : get_permalink($event->ID());
556
-            $url = preg_match("~^(?:f|ht)tps?://~i", $url) ? $url : 'https://' . $url;
557
-            return esc_url_raw($url);
558
-        }
559
-        return '';
560
-    }
561
-
562
-
563
-    /**
564
-     *    event_phone
565
-     *
566
-     * @param int $EVT_ID
567
-     * @return    string
568
-     * @throws EE_Error
569
-     * @throws EE_Error
570
-     * @throws ReflectionException
571
-     */
572
-    public static function event_phone($EVT_ID = 0)
573
-    {
574
-        $event = EEH_Event_View::get_event($EVT_ID);
575
-        if ($event instanceof EE_Event) {
576
-            return EEH_Schema::telephone($event->phone());
577
-        }
578
-        return null;
579
-    }
580
-
581
-
582
-    /**
583
-     *    edit_event_link
584
-     *
585
-     * @param int    $EVT_ID
586
-     * @param string $link
587
-     * @param string $before
588
-     * @param string $after
589
-     * @return    string
590
-     * @throws EE_Error
591
-     * @throws ReflectionException
592
-     */
593
-    public static function edit_event_link($EVT_ID = 0, $link = '', $before = '', $after = '')
594
-    {
595
-        $event = EEH_Event_View::get_event($EVT_ID);
596
-        if ($event instanceof EE_Event) {
597
-            // can the user edit this post ?
598
-            if (current_user_can('edit_post', $event->ID())) {
599
-                // set link text
600
-                $link_text = ! empty($link) ? $link : esc_html__('edit this event', 'event_espresso');
601
-                // generate nonce
602
-                $nonce = wp_create_nonce('edit_nonce');
603
-                // generate url to event editor for this event
604
-                $url =
605
-                    add_query_arg(
606
-                        [
607
-                            'page'       => 'espresso_events',
608
-                            'action'     => 'edit',
609
-                            'post'       => $event->ID(),
610
-                            'edit_nonce' => $nonce,
611
-                        ],
612
-                        admin_url()
613
-                    );
614
-                // get edit CPT text
615
-                $post_type_obj = get_post_type_object('espresso_events');
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) . '"';
619
-                $link .= EED_Events_Archive::link_target();
620
-                $link .= '>' . $link_text . '</a>';
621
-                // put it all together
622
-                return $before . apply_filters('edit_post_link', $link, $event->ID()) . $after;
623
-            }
624
-        }
625
-        return '';
626
-    }
627
-
628
-
629
-    /**
630
-     * @return string
631
-     */
632
-    public static function event_archive_url()
633
-    {
634
-        return get_post_type_archive_link('espresso_events');
635
-    }
380
+		}
381
+	}
382
+
383
+
384
+	/**
385
+	 *    get_primary_date_obj - orders date by DTT_order
386
+	 *
387
+	 * @param int $EVT_ID
388
+	 * @return EE_Datetime
389
+	 * @throws EE_Error
390
+	 * @throws ReflectionException
391
+	 */
392
+	public static function get_primary_date_obj($EVT_ID = 0)
393
+	{
394
+		$event = EEH_Event_View::get_event($EVT_ID);
395
+		if ($event instanceof EE_Event) {
396
+			$datetimes = $event->get_many_related(
397
+				'Datetime',
398
+				[
399
+					'limit'    => 1,
400
+					'order_by' => ['DTT_order' => 'ASC'],
401
+				]
402
+			);
403
+			return reset($datetimes);
404
+		}
405
+		return null;
406
+	}
407
+
408
+
409
+	/**
410
+	 *    get_last_date_obj - orders date by DTT_order
411
+	 *
412
+	 * @param int $EVT_ID
413
+	 * @return EE_Datetime
414
+	 * @throws EE_Error
415
+	 * @throws ReflectionException
416
+	 */
417
+	public static function get_last_date_obj($EVT_ID = 0)
418
+	{
419
+		$event = EEH_Event_View::get_event($EVT_ID);
420
+		if ($event instanceof EE_Event) {
421
+			$datetimes = $event->get_many_related(
422
+				'Datetime',
423
+				[
424
+					'limit'    => 1,
425
+					'order_by' => ['DTT_order' => 'DESC'],
426
+				]
427
+			);
428
+			return end($datetimes);
429
+		}
430
+		return null;
431
+	}
432
+
433
+
434
+	/**
435
+	 *    get_earliest_date_obj - orders date chronologically
436
+	 *
437
+	 * @param int $EVT_ID
438
+	 * @return EE_Datetime
439
+	 * @throws EE_Error
440
+	 * @throws ReflectionException
441
+	 */
442
+	public static function get_earliest_date_obj($EVT_ID = 0)
443
+	{
444
+		$event = EEH_Event_View::get_event($EVT_ID);
445
+		if ($event instanceof EE_Event) {
446
+			$datetimes = $event->get_many_related(
447
+				'Datetime',
448
+				[
449
+					'limit'    => 1,
450
+					'order_by' => ['DTT_EVT_start' => 'ASC'],
451
+				]
452
+			);
453
+			return reset($datetimes);
454
+		}
455
+		return null;
456
+	}
457
+
458
+
459
+	/**
460
+	 *    get_latest_date_obj - orders date chronologically
461
+	 *
462
+	 * @param int $EVT_ID
463
+	 * @return EE_Datetime
464
+	 * @throws EE_Error
465
+	 * @throws ReflectionException
466
+	 */
467
+	public static function get_latest_date_obj($EVT_ID = 0)
468
+	{
469
+		$event = EEH_Event_View::get_event($EVT_ID);
470
+		if ($event instanceof EE_Event) {
471
+			$datetimes = $event->get_many_related(
472
+				'Datetime',
473
+				[
474
+					'limit'    => 1,
475
+					'order_by' => ['DTT_EVT_start' => 'DESC'],
476
+				]
477
+			);
478
+			return end($datetimes);
479
+		}
480
+		return null;
481
+	}
482
+
483
+
484
+	/**
485
+	 *    get_next_upcoming_date_obj - return the next upcoming datetime
486
+	 *
487
+	 * @param int $EVT_ID
488
+	 * @return    EE_Datetime|null
489
+	 * @throws EE_Error
490
+	 * @throws EE_Error
491
+	 */
492
+	public static function get_next_upcoming_date_obj($EVT_ID = 0)
493
+	{
494
+		$datetime = EEM_Datetime::instance()->get_one(
495
+			[
496
+				[
497
+					'Event.EVT_ID'  => $EVT_ID,
498
+					'DTT_EVT_start' => ['>=', current_time('mysql', true)],
499
+				],
500
+				'order_by' => ['DTT_EVT_start' => 'asc'],
501
+			]
502
+		);
503
+		return $datetime instanceof EE_Datetime ? $datetime : null;
504
+	}
505
+
506
+
507
+	/**
508
+	 *    get_all_date_obj
509
+	 *
510
+	 * @param int  $EVT_ID
511
+	 * @param null $include_expired
512
+	 * @param bool $include_deleted
513
+	 * @param null $limit
514
+	 * @return EE_Datetime[]
515
+	 * @throws EE_Error
516
+	 * @throws EE_Error
517
+	 * @throws ReflectionException
518
+	 */
519
+	public static function get_all_date_obj(
520
+		$EVT_ID = 0,
521
+		$include_expired = null,
522
+		$include_deleted = false,
523
+		$limit = null
524
+	) {
525
+		$event = EEH_Event_View::get_event($EVT_ID);
526
+		if ($include_expired === null) {
527
+			if ($event instanceof EE_Event && $event->is_expired()) {
528
+				$include_expired = true;
529
+			} else {
530
+				$include_expired = false;
531
+			}
532
+		}
533
+
534
+		if ($event instanceof EE_Event) {
535
+			return $event->datetimes_ordered($include_expired, $include_deleted, $limit);
536
+		}
537
+		return [];
538
+	}
539
+
540
+
541
+	/**
542
+	 *    event_link_url
543
+	 *
544
+	 * @param int $EVT_ID
545
+	 * @return string
546
+	 * @throws EE_Error
547
+	 * @throws ReflectionException
548
+	 */
549
+	public static function event_link_url($EVT_ID = 0)
550
+	{
551
+		$event = EEH_Event_View::get_event($EVT_ID);
552
+		if ($event instanceof EE_Event) {
553
+			$url = $event->external_url() !== null && $event->external_url() !== ''
554
+				? $event->external_url()
555
+				: get_permalink($event->ID());
556
+			$url = preg_match("~^(?:f|ht)tps?://~i", $url) ? $url : 'https://' . $url;
557
+			return esc_url_raw($url);
558
+		}
559
+		return '';
560
+	}
561
+
562
+
563
+	/**
564
+	 *    event_phone
565
+	 *
566
+	 * @param int $EVT_ID
567
+	 * @return    string
568
+	 * @throws EE_Error
569
+	 * @throws EE_Error
570
+	 * @throws ReflectionException
571
+	 */
572
+	public static function event_phone($EVT_ID = 0)
573
+	{
574
+		$event = EEH_Event_View::get_event($EVT_ID);
575
+		if ($event instanceof EE_Event) {
576
+			return EEH_Schema::telephone($event->phone());
577
+		}
578
+		return null;
579
+	}
580
+
581
+
582
+	/**
583
+	 *    edit_event_link
584
+	 *
585
+	 * @param int    $EVT_ID
586
+	 * @param string $link
587
+	 * @param string $before
588
+	 * @param string $after
589
+	 * @return    string
590
+	 * @throws EE_Error
591
+	 * @throws ReflectionException
592
+	 */
593
+	public static function edit_event_link($EVT_ID = 0, $link = '', $before = '', $after = '')
594
+	{
595
+		$event = EEH_Event_View::get_event($EVT_ID);
596
+		if ($event instanceof EE_Event) {
597
+			// can the user edit this post ?
598
+			if (current_user_can('edit_post', $event->ID())) {
599
+				// set link text
600
+				$link_text = ! empty($link) ? $link : esc_html__('edit this event', 'event_espresso');
601
+				// generate nonce
602
+				$nonce = wp_create_nonce('edit_nonce');
603
+				// generate url to event editor for this event
604
+				$url =
605
+					add_query_arg(
606
+						[
607
+							'page'       => 'espresso_events',
608
+							'action'     => 'edit',
609
+							'post'       => $event->ID(),
610
+							'edit_nonce' => $nonce,
611
+						],
612
+						admin_url()
613
+					);
614
+				// get edit CPT text
615
+				$post_type_obj = get_post_type_object('espresso_events');
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) . '"';
619
+				$link .= EED_Events_Archive::link_target();
620
+				$link .= '>' . $link_text . '</a>';
621
+				// put it all together
622
+				return $before . apply_filters('edit_post_link', $link, $event->ID()) . $after;
623
+			}
624
+		}
625
+		return '';
626
+	}
627
+
628
+
629
+	/**
630
+	 * @return string
631
+	 */
632
+	public static function event_archive_url()
633
+	{
634
+		return get_post_type_archive_link('espresso_events');
635
+	}
636 636
 }
Please login to merge, or discard this patch.
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.
core/helpers/EEH_Maps.helper.php 2 patches
Indentation   +194 added lines, -194 removed lines patch added patch discarded remove patch
@@ -12,69 +12,69 @@  discard block
 block discarded – undo
12 12
 class EEH_Maps
13 13
 {
14 14
 
15
-    // array of map settings
16
-    public static $gmap_vars = [];
17
-
18
-
19
-    /**
20
-     * google_map - creates a Google Map Link
21
-     *
22
-     * @param array $ee_gmaps_opts array of attributes required for the map link generation
23
-     * @return string (link to map!)
24
-     */
25
-    public static function google_map($ee_gmaps_opts)
26
-    {
27
-
28
-        $ee_map_width = ! empty($ee_gmaps_opts['ee_map_width'])
29
-            ? absint($ee_gmaps_opts['ee_map_width'])
30
-            : 300;
31
-
32
-        $ee_map_height = ! empty($ee_gmaps_opts['ee_map_height'])
33
-            ? absint($ee_gmaps_opts['ee_map_height'])
34
-            : 185;
35
-
36
-        $ee_map_zoom = ! empty($ee_gmaps_opts['ee_map_zoom'])
37
-            ? absint($ee_gmaps_opts['ee_map_zoom'])
38
-            : 12;
39
-
40
-        $ee_map_nav_display = ! empty($ee_gmaps_opts['ee_map_nav_display']) ? 'true' : 'false';
41
-
42
-        $ee_map_nav_size = ! empty($ee_gmaps_opts['ee_map_nav_size'])
43
-            ? sanitize_text_field($ee_gmaps_opts['ee_map_nav_size'])
44
-            : 'default';
45
-
46
-        $ee_map_type_control = ! empty($ee_gmaps_opts['ee_map_type_control'])
47
-            ? sanitize_text_field($ee_gmaps_opts['ee_map_type_control'])
48
-            : 'default';
49
-
50
-        $static_url = ! empty($ee_gmaps_opts['ee_static_url'])
51
-            ? esc_url_raw($ee_gmaps_opts['ee_static_url'])
52
-            : false;
53
-
54
-        if (! empty($ee_gmaps_opts['ee_map_align'])) {
55
-            switch ($ee_gmaps_opts['ee_map_align']) {
56
-                case "left":
57
-                    $map_align = 'ee-gmap-align-left left';
58
-                    break;
59
-                case "right":
60
-                    $map_align = 'ee-gmap-align-right right';
61
-                    break;
62
-                case "center":
63
-                    $map_align = 'ee-gmap-align-center center';
64
-                    break;
65
-                case "none":
66
-                default:
67
-                    $map_align = 'ee-gmap-align-none';
68
-            }
69
-        } else {
70
-            $map_align = 'ee-gmap-align-none';
71
-        }
72
-
73
-
74
-        // Determine whether user has set a hardcoded url to use and
75
-        // if so display a Google static iframe map else run V3 api
76
-        if ($static_url) {
77
-            $html = '
15
+	// array of map settings
16
+	public static $gmap_vars = [];
17
+
18
+
19
+	/**
20
+	 * google_map - creates a Google Map Link
21
+	 *
22
+	 * @param array $ee_gmaps_opts array of attributes required for the map link generation
23
+	 * @return string (link to map!)
24
+	 */
25
+	public static function google_map($ee_gmaps_opts)
26
+	{
27
+
28
+		$ee_map_width = ! empty($ee_gmaps_opts['ee_map_width'])
29
+			? absint($ee_gmaps_opts['ee_map_width'])
30
+			: 300;
31
+
32
+		$ee_map_height = ! empty($ee_gmaps_opts['ee_map_height'])
33
+			? absint($ee_gmaps_opts['ee_map_height'])
34
+			: 185;
35
+
36
+		$ee_map_zoom = ! empty($ee_gmaps_opts['ee_map_zoom'])
37
+			? absint($ee_gmaps_opts['ee_map_zoom'])
38
+			: 12;
39
+
40
+		$ee_map_nav_display = ! empty($ee_gmaps_opts['ee_map_nav_display']) ? 'true' : 'false';
41
+
42
+		$ee_map_nav_size = ! empty($ee_gmaps_opts['ee_map_nav_size'])
43
+			? sanitize_text_field($ee_gmaps_opts['ee_map_nav_size'])
44
+			: 'default';
45
+
46
+		$ee_map_type_control = ! empty($ee_gmaps_opts['ee_map_type_control'])
47
+			? sanitize_text_field($ee_gmaps_opts['ee_map_type_control'])
48
+			: 'default';
49
+
50
+		$static_url = ! empty($ee_gmaps_opts['ee_static_url'])
51
+			? esc_url_raw($ee_gmaps_opts['ee_static_url'])
52
+			: false;
53
+
54
+		if (! empty($ee_gmaps_opts['ee_map_align'])) {
55
+			switch ($ee_gmaps_opts['ee_map_align']) {
56
+				case "left":
57
+					$map_align = 'ee-gmap-align-left left';
58
+					break;
59
+				case "right":
60
+					$map_align = 'ee-gmap-align-right right';
61
+					break;
62
+				case "center":
63
+					$map_align = 'ee-gmap-align-center center';
64
+					break;
65
+				case "none":
66
+				default:
67
+					$map_align = 'ee-gmap-align-none';
68
+			}
69
+		} else {
70
+			$map_align = 'ee-gmap-align-none';
71
+		}
72
+
73
+
74
+		// Determine whether user has set a hardcoded url to use and
75
+		// if so display a Google static iframe map else run V3 api
76
+		if ($static_url) {
77
+			$html = '
78 78
             <div class="ee-gmap-iframewrap ee-gmap-wrapper ' . $map_align . '">
79 79
                 <iframe src="' . $static_url . '&output=embed"
80 80
                         style="width: ' . $ee_map_width . 'px; height: ' . $ee_map_height . 'px;"
@@ -85,18 +85,18 @@  discard block
 block discarded – undo
85 85
                 <a href="' . $static_url . '">' . esc_html__('View Large map', 'event_espresso') . '</a>
86 86
             </div>
87 87
 ';
88
-        } else {
89
-            EEH_Maps::$gmap_vars[ $ee_gmaps_opts['map_ID'] ] = [
90
-                'map_ID'              => $ee_gmaps_opts['map_ID'],
91
-                'ee_map_zoom'         => $ee_map_zoom,
92
-                'ee_map_nav_display'  => $ee_map_nav_display,
93
-                'ee_map_nav_size'     => $ee_map_nav_size,
94
-                'ee_map_type_control' => $ee_map_type_control,
95
-                'location'            => $ee_gmaps_opts['location'],
96
-            ];
97
-
98
-            $style = 'width: ' . $ee_map_width . 'px; height: ' . $ee_map_height . 'px;';
99
-            $html  = '
88
+		} else {
89
+			EEH_Maps::$gmap_vars[ $ee_gmaps_opts['map_ID'] ] = [
90
+				'map_ID'              => $ee_gmaps_opts['map_ID'],
91
+				'ee_map_zoom'         => $ee_map_zoom,
92
+				'ee_map_nav_display'  => $ee_map_nav_display,
93
+				'ee_map_nav_size'     => $ee_map_nav_size,
94
+				'ee_map_type_control' => $ee_map_type_control,
95
+				'location'            => $ee_gmaps_opts['location'],
96
+			];
97
+
98
+			$style = 'width: ' . $ee_map_width . 'px; height: ' . $ee_map_height . 'px;';
99
+			$html  = '
100 100
             <div class="ee-gmap-wrapper ' . esc_attr($map_align) . '">
101 101
                 <div class="ee-gmap" 
102 102
                      id="map_canvas_' . esc_attr($ee_gmaps_opts['map_ID']) . '"
@@ -104,109 +104,109 @@  discard block
 block discarded – undo
104 104
                  ></div>
105 105
             </div>';
106 106
 
107
-            wp_enqueue_script('gmap_api');
108
-            wp_enqueue_script('ee_gmap');
109
-            add_action('wp_footer', ['EEH_Maps', 'footer_enqueue_script']);
110
-        }
111
-        return $html; // end auto map or static url map check
112
-    }
113
-
114
-
115
-    /**
116
-     * enqueue_script
117
-     *
118
-     * @return void
119
-     */
120
-    public static function footer_enqueue_script()
121
-    {
122
-        wp_localize_script('ee_gmap', 'ee_gmap_vars', EEH_Maps::$gmap_vars);
123
-    }
124
-
125
-
126
-    /**
127
-     * registers scripts for maps
128
-     */
129
-    public static function espresso_google_map_js()
130
-    {
131
-        $api_url = sprintf(
132
-            "https://maps.googleapis.com/maps/api/js?key=%s",
133
-            apply_filters(
134
-                'FHEE__EEH_Maps__espresso_google_maps_js__api_key',
135
-                EE_Registry::instance()->CFG->map_settings->google_map_api_key
136
-            )
137
-        );
138
-        wp_register_script(
139
-            'gmap_api',
140
-            esc_url_raw($api_url),
141
-            ['jquery'],
142
-            null,
143
-            true
144
-        );
145
-        wp_register_script(
146
-            'ee_gmap',
147
-            plugin_dir_url(__FILE__) . 'assets/ee_gmap.js',
148
-            ['gmap_api'],
149
-            '1.0',
150
-            true
151
-        );
152
-    }
153
-
154
-
155
-    /**
156
-     * creates a Google Map Link
157
-     *
158
-     * @param array $atts array of attributes required for the map link generation
159
-     * @return string (link to map!)
160
-     */
161
-    public static function google_map_link($atts)
162
-    {
163
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
164
-        extract($atts);
165
-        /** @var string $address */
166
-        /** @var string $city */
167
-        /** @var string $state */
168
-        /** @var string $zip */
169
-        /** @var string $country */
170
-        $address         = "{$address}";
171
-        $city            = "{$city}";
172
-        $state           = "{$state}";
173
-        $zip             = "{$zip}";
174
-        $country         = "{$country}";
175
-        $text            = isset($text) ? "{$text}" : "";
176
-        $type            = isset($type) ? "{$type}" : "";
177
-        $map_w           = isset($map_w) ? "{$map_w}" : 400;
178
-        $map_h           = isset($map_h) ? "{$map_h}" : 400;
179
-        $id              = isset($id) ? $id : 'not_set';
180
-        $map_image_class = isset($map_image_class) ? $map_image_class : 'ee_google_map_view';
181
-
182
-        $address_string = ($address != '' ? $address : '')
183
-                          . ($city != '' ? ',' . $city : '')
184
-                          . ($state != '' ? ',' . $state : '')
185
-                          . ($zip != '' ? ',' . $zip : '')
186
-                          . ($country != '' ? ',' . $country : '');
187
-
188
-        $google_map = htmlentities2('https://maps.google.com/maps?q=' . urlencode($address_string));
189
-
190
-        switch ($type) {
191
-            case 'text':
192
-            default:
193
-                $text = $text == '' ? esc_html__('Map and Directions', 'event_espresso') : $text;
194
-                break;
195
-
196
-            case 'url_only':
197
-            case 'url':
198
-                $text = $google_map;
199
-                break;
200
-
201
-            case 'map':
202
-                $scheme = is_ssl() ? 'https://' : 'http://';
203
-
204
-                $api_key = apply_filters(
205
-                    'FHEE__EEH_Maps__espresso_google_maps_link__api_key',
206
-                    EE_Registry::instance()->CFG->map_settings->google_map_api_key
207
-                );
208
-
209
-                return '
107
+			wp_enqueue_script('gmap_api');
108
+			wp_enqueue_script('ee_gmap');
109
+			add_action('wp_footer', ['EEH_Maps', 'footer_enqueue_script']);
110
+		}
111
+		return $html; // end auto map or static url map check
112
+	}
113
+
114
+
115
+	/**
116
+	 * enqueue_script
117
+	 *
118
+	 * @return void
119
+	 */
120
+	public static function footer_enqueue_script()
121
+	{
122
+		wp_localize_script('ee_gmap', 'ee_gmap_vars', EEH_Maps::$gmap_vars);
123
+	}
124
+
125
+
126
+	/**
127
+	 * registers scripts for maps
128
+	 */
129
+	public static function espresso_google_map_js()
130
+	{
131
+		$api_url = sprintf(
132
+			"https://maps.googleapis.com/maps/api/js?key=%s",
133
+			apply_filters(
134
+				'FHEE__EEH_Maps__espresso_google_maps_js__api_key',
135
+				EE_Registry::instance()->CFG->map_settings->google_map_api_key
136
+			)
137
+		);
138
+		wp_register_script(
139
+			'gmap_api',
140
+			esc_url_raw($api_url),
141
+			['jquery'],
142
+			null,
143
+			true
144
+		);
145
+		wp_register_script(
146
+			'ee_gmap',
147
+			plugin_dir_url(__FILE__) . 'assets/ee_gmap.js',
148
+			['gmap_api'],
149
+			'1.0',
150
+			true
151
+		);
152
+	}
153
+
154
+
155
+	/**
156
+	 * creates a Google Map Link
157
+	 *
158
+	 * @param array $atts array of attributes required for the map link generation
159
+	 * @return string (link to map!)
160
+	 */
161
+	public static function google_map_link($atts)
162
+	{
163
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
164
+		extract($atts);
165
+		/** @var string $address */
166
+		/** @var string $city */
167
+		/** @var string $state */
168
+		/** @var string $zip */
169
+		/** @var string $country */
170
+		$address         = "{$address}";
171
+		$city            = "{$city}";
172
+		$state           = "{$state}";
173
+		$zip             = "{$zip}";
174
+		$country         = "{$country}";
175
+		$text            = isset($text) ? "{$text}" : "";
176
+		$type            = isset($type) ? "{$type}" : "";
177
+		$map_w           = isset($map_w) ? "{$map_w}" : 400;
178
+		$map_h           = isset($map_h) ? "{$map_h}" : 400;
179
+		$id              = isset($id) ? $id : 'not_set';
180
+		$map_image_class = isset($map_image_class) ? $map_image_class : 'ee_google_map_view';
181
+
182
+		$address_string = ($address != '' ? $address : '')
183
+						  . ($city != '' ? ',' . $city : '')
184
+						  . ($state != '' ? ',' . $state : '')
185
+						  . ($zip != '' ? ',' . $zip : '')
186
+						  . ($country != '' ? ',' . $country : '');
187
+
188
+		$google_map = htmlentities2('https://maps.google.com/maps?q=' . urlencode($address_string));
189
+
190
+		switch ($type) {
191
+			case 'text':
192
+			default:
193
+				$text = $text == '' ? esc_html__('Map and Directions', 'event_espresso') : $text;
194
+				break;
195
+
196
+			case 'url_only':
197
+			case 'url':
198
+				$text = $google_map;
199
+				break;
200
+
201
+			case 'map':
202
+				$scheme = is_ssl() ? 'https://' : 'http://';
203
+
204
+				$api_key = apply_filters(
205
+					'FHEE__EEH_Maps__espresso_google_maps_link__api_key',
206
+					EE_Registry::instance()->CFG->map_settings->google_map_api_key
207
+				);
208
+
209
+				return '
210 210
                 <a class="a_map_image_link" 
211 211
                    href="' . esc_url_raw($google_map) . '" 
212 212
                    target="_blank" 
@@ -216,23 +216,23 @@  discard block
 block discarded – undo
216 216
                          class="map_image_link" 
217 217
                          id="venue_map_' . $id . '" ' . $map_image_class . ' 
218 218
                          src="'
219
-                       . htmlentities2(
220
-                           $scheme
221
-                           . 'maps.googleapis.com/maps/api/staticmap?center='
222
-                           . urlencode($address_string)
223
-                           . '&amp;zoom=14&amp;size='
224
-                           . $map_w . 'x' . $map_h
225
-                           . '&amp;markers=color:green|label:|'
226
-                           . urlencode($address_string)
227
-                           . '&amp;sensor=false&amp;key='
228
-                           . $api_key
229
-                       ) . '"
219
+					   . htmlentities2(
220
+						   $scheme
221
+						   . 'maps.googleapis.com/maps/api/staticmap?center='
222
+						   . urlencode($address_string)
223
+						   . '&amp;zoom=14&amp;size='
224
+						   . $map_w . 'x' . $map_h
225
+						   . '&amp;markers=color:green|label:|'
226
+						   . urlencode($address_string)
227
+						   . '&amp;sensor=false&amp;key='
228
+						   . $api_key
229
+					   ) . '"
230 230
                      />
231 231
                  </a>';
232
-        }
232
+		}
233 233
 
234
-        return $type === 'url_only'
235
-            ? $text
236
-            : '<a href="' . esc_url_raw($google_map) . '" target="_blank" rel="noopener noreferrer">' . $text . '</a>';
237
-    }
234
+		return $type === 'url_only'
235
+			? $text
236
+			: '<a href="' . esc_url_raw($google_map) . '" target="_blank" rel="noopener noreferrer">' . $text . '</a>';
237
+	}
238 238
 }
Please login to merge, or discard this patch.
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.
core/helpers/EEH_Debug_Tools.helper.php 2 patches
Indentation   +682 added lines, -682 removed lines patch added patch discarded remove patch
@@ -15,673 +15,673 @@  discard block
 block discarded – undo
15 15
 class EEH_Debug_Tools
16 16
 {
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 $result;
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 $result;
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 $result;
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 $result;
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.
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.
core/db_classes/EE_Event.class.php 2 patches
Indentation   +1439 added lines, -1439 removed lines patch added patch discarded remove patch
@@ -15,1443 +15,1443 @@
 block discarded – undo
15 15
 class EE_Event extends EE_CPT_Base implements EEI_Line_Item_Object, EEI_Admin_Links, EEI_Has_Icon, EEI_Event
16 16
 {
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 $status; // already escaped
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 $status; // already escaped
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.
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.
core/services/helpers/datetime/AbstractHelper.php 2 patches
Indentation   +245 added lines, -245 removed lines patch added patch discarded remove patch
@@ -13,136 +13,136 @@  discard block
 block discarded – undo
13 13
 {
14 14
 
15 15
 
16
-    /**
17
-     * Ensures that a valid timezone string is returned.
18
-     *
19
-     * @param string $timezone_string  When not provided then attempt to use the timezone_string set in the WP Time
20
-     *                                 settings (or derive from set UTC offset).
21
-     * @return string
22
-     * @throws EE_Error
23
-     */
24
-    public function getValidTimezoneString($timezone_string = '')
25
-    {
26
-        $timezone_string = ! empty($timezone_string) ? $timezone_string : (string) get_option('timezone_string');
27
-        $timezone_string = ! empty($timezone_string)
28
-            ? $timezone_string
29
-            : $this->getTimezoneStringFromGmtOffset();
30
-        $this->validateTimezone($timezone_string);
31
-        return $timezone_string;
32
-    }
16
+	/**
17
+	 * Ensures that a valid timezone string is returned.
18
+	 *
19
+	 * @param string $timezone_string  When not provided then attempt to use the timezone_string set in the WP Time
20
+	 *                                 settings (or derive from set UTC offset).
21
+	 * @return string
22
+	 * @throws EE_Error
23
+	 */
24
+	public function getValidTimezoneString($timezone_string = '')
25
+	{
26
+		$timezone_string = ! empty($timezone_string) ? $timezone_string : (string) get_option('timezone_string');
27
+		$timezone_string = ! empty($timezone_string)
28
+			? $timezone_string
29
+			: $this->getTimezoneStringFromGmtOffset();
30
+		$this->validateTimezone($timezone_string);
31
+		return $timezone_string;
32
+	}
33 33
 
34 34
 
35 35
 
36
-    /**
37
-     * The only purpose for this static method is to validate that the incoming timezone is a valid php timezone.
38
-     *
39
-     * @param string $timezone_string
40
-     * @param bool   $throw_error
41
-     * @return bool
42
-     * @throws EE_Error
43
-     */
44
-    public function validateTimezone($timezone_string, $throw_error = true)
45
-    {
46
-        // easiest way to test a timezone string is just see if it throws an error when you try to create a
47
-        // DateTimeZone object with it
48
-        try {
49
-            new DateTimeZone($timezone_string);
50
-        } catch (Exception $e) {
51
-            // sometimes we take exception to exceptions
52
-            if (! $throw_error) {
53
-                return false;
54
-            }
55
-            throw new EE_Error(
56
-                sprintf(
57
-                    esc_html__(
58
-                        'The timezone given (%1$s), is invalid, please check with %2$sthis list%3$s for what valid timezones can be used',
59
-                        'event_espresso'
60
-                    ),
61
-                    $timezone_string,
62
-                    '<a href="http://www.php.net/manual/en/timezones.php">',
63
-                    '</a>'
64
-                )
65
-            );
66
-        }
67
-        return true;
68
-    }
36
+	/**
37
+	 * The only purpose for this static method is to validate that the incoming timezone is a valid php timezone.
38
+	 *
39
+	 * @param string $timezone_string
40
+	 * @param bool   $throw_error
41
+	 * @return bool
42
+	 * @throws EE_Error
43
+	 */
44
+	public function validateTimezone($timezone_string, $throw_error = true)
45
+	{
46
+		// easiest way to test a timezone string is just see if it throws an error when you try to create a
47
+		// DateTimeZone object with it
48
+		try {
49
+			new DateTimeZone($timezone_string);
50
+		} catch (Exception $e) {
51
+			// sometimes we take exception to exceptions
52
+			if (! $throw_error) {
53
+				return false;
54
+			}
55
+			throw new EE_Error(
56
+				sprintf(
57
+					esc_html__(
58
+						'The timezone given (%1$s), is invalid, please check with %2$sthis list%3$s for what valid timezones can be used',
59
+						'event_espresso'
60
+					),
61
+					$timezone_string,
62
+					'<a href="http://www.php.net/manual/en/timezones.php">',
63
+					'</a>'
64
+				)
65
+			);
66
+		}
67
+		return true;
68
+	}
69 69
 
70 70
 
71
-    /**
72
-     * Gets the site's GMT offset based on either the timezone string
73
-     * (in which case the gmt offset will vary depending on the location's
74
-     * observance of daylight savings time) or the gmt_offset wp option
75
-     *
76
-     * @return int  seconds offset
77
-     */
78
-    public function getSiteTimezoneGmtOffset()
79
-    {
80
-        $timezone_string = (string) get_option('timezone_string');
81
-        if ($timezone_string) {
82
-            try {
83
-                $timezone = new DateTimeZone($timezone_string);
84
-                return $timezone->getOffset(new DateTime()); // in WordPress DateTime defaults to UTC
85
-            } catch (Exception $e) {
86
-            }
87
-        }
88
-        $offset = get_option('gmt_offset');
89
-        return (int) ($offset * HOUR_IN_SECONDS);
90
-    }
71
+	/**
72
+	 * Gets the site's GMT offset based on either the timezone string
73
+	 * (in which case the gmt offset will vary depending on the location's
74
+	 * observance of daylight savings time) or the gmt_offset wp option
75
+	 *
76
+	 * @return int  seconds offset
77
+	 */
78
+	public function getSiteTimezoneGmtOffset()
79
+	{
80
+		$timezone_string = (string) get_option('timezone_string');
81
+		if ($timezone_string) {
82
+			try {
83
+				$timezone = new DateTimeZone($timezone_string);
84
+				return $timezone->getOffset(new DateTime()); // in WordPress DateTime defaults to UTC
85
+			} catch (Exception $e) {
86
+			}
87
+		}
88
+		$offset = get_option('gmt_offset');
89
+		return (int) ($offset * HOUR_IN_SECONDS);
90
+	}
91 91
 
92 92
 
93
-    /**
94
-     * Get Timezone offset for given timezone object
95
-     *
96
-     * @param DateTimeZone $date_time_zone
97
-     * @param null|int     $time
98
-     * @return int
99
-     * @throws DomainException
100
-     */
101
-    public function getTimezoneOffset(DateTimeZone $date_time_zone, $time = null)
102
-    {
103
-        $transition = $this->getTimezoneTransitions($date_time_zone, $time);
104
-        if (! isset($transition['offset'])) {
105
-            throw new DomainException(
106
-                sprintf(
107
-                    esc_html__('An invalid timezone transition was received %1$s', 'event_espresso'),
108
-                    print_r($transition, true)
109
-                )
110
-            );
111
-        }
112
-        return $transition['offset'];
113
-    }
93
+	/**
94
+	 * Get Timezone offset for given timezone object
95
+	 *
96
+	 * @param DateTimeZone $date_time_zone
97
+	 * @param null|int     $time
98
+	 * @return int
99
+	 * @throws DomainException
100
+	 */
101
+	public function getTimezoneOffset(DateTimeZone $date_time_zone, $time = null)
102
+	{
103
+		$transition = $this->getTimezoneTransitions($date_time_zone, $time);
104
+		if (! isset($transition['offset'])) {
105
+			throw new DomainException(
106
+				sprintf(
107
+					esc_html__('An invalid timezone transition was received %1$s', 'event_espresso'),
108
+					print_r($transition, true)
109
+				)
110
+			);
111
+		}
112
+		return $transition['offset'];
113
+	}
114 114
 
115 115
 
116
-    /**
117
-     * Provide a timezone select input
118
-     *
119
-     * @param string $timezone_string
120
-     * @return string
121
-     * @throws EE_Error
122
-     */
123
-    public function timezoneSelectInput($timezone_string = '')
124
-    {
125
-        // get WP date time format
126
-        $datetime_format = get_option('date_format') . ' ' . get_option('time_format');
127
-        // if passed a value, then use that, else get WP option
128
-        $timezone_string = ! empty($timezone_string) ? $timezone_string : (string) get_option('timezone_string');
129
-        // check if the timezone is valid but don't throw any errors if it isn't
130
-        $timezone_string = $this->validateTimezone($timezone_string, false)
131
-            ? $timezone_string
132
-            : '';
133
-        $gmt_offset      = get_option('gmt_offset');
134
-        $check_zone_info = true;
135
-        if (empty($timezone_string)) {
136
-            // Create a UTC+- zone if no timezone string exists
137
-            $timezone_string = 'UTC';
138
-            $check_zone_info = false;
139
-            if ($gmt_offset > 0) {
140
-                $timezone_string = 'UTC+' . $gmt_offset;
141
-            } elseif ($gmt_offset < 0) {
142
-                $timezone_string = 'UTC' . $gmt_offset;
143
-            }
144
-        }
145
-        ?>
116
+	/**
117
+	 * Provide a timezone select input
118
+	 *
119
+	 * @param string $timezone_string
120
+	 * @return string
121
+	 * @throws EE_Error
122
+	 */
123
+	public function timezoneSelectInput($timezone_string = '')
124
+	{
125
+		// get WP date time format
126
+		$datetime_format = get_option('date_format') . ' ' . get_option('time_format');
127
+		// if passed a value, then use that, else get WP option
128
+		$timezone_string = ! empty($timezone_string) ? $timezone_string : (string) get_option('timezone_string');
129
+		// check if the timezone is valid but don't throw any errors if it isn't
130
+		$timezone_string = $this->validateTimezone($timezone_string, false)
131
+			? $timezone_string
132
+			: '';
133
+		$gmt_offset      = get_option('gmt_offset');
134
+		$check_zone_info = true;
135
+		if (empty($timezone_string)) {
136
+			// Create a UTC+- zone if no timezone string exists
137
+			$timezone_string = 'UTC';
138
+			$check_zone_info = false;
139
+			if ($gmt_offset > 0) {
140
+				$timezone_string = 'UTC+' . $gmt_offset;
141
+			} elseif ($gmt_offset < 0) {
142
+				$timezone_string = 'UTC' . $gmt_offset;
143
+			}
144
+		}
145
+		?>
146 146
         <p>
147 147
             <label for="timezone_string"><?php esc_html_e('timezone', 'event_espresso'); ?></label>
148 148
             <select id="timezone_string" name="timezone_string">
@@ -155,150 +155,150 @@  discard block
 block discarded – undo
155 155
         <p>
156 156
         <span>
157 157
             <?php
158
-            printf(
159
-                esc_html__('%1$sUTC%2$s time is %3$s', 'event_espresso'),
160
-                '<abbr title="Coordinated Universal Time">',
161
-                '</abbr>',
162
-                '<code>' . date_i18n($datetime_format, false, true) . '</code>'
163
-            );
164
-            ?></span>
158
+			printf(
159
+				esc_html__('%1$sUTC%2$s time is %3$s', 'event_espresso'),
160
+				'<abbr title="Coordinated Universal Time">',
161
+				'</abbr>',
162
+				'<code>' . date_i18n($datetime_format, false, true) . '</code>'
163
+			);
164
+			?></span>
165 165
         <?php
166
-        if (! empty($timezone_string) || ! empty($gmt_offset)) : ?>
166
+		if (! empty($timezone_string) || ! empty($gmt_offset)) : ?>
167 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
-        endif; ?>
169
+		endif; ?>
170 170
 
171 171
         <?php
172
-        if ($check_zone_info && $timezone_string) : ?>
172
+		if ($check_zone_info && $timezone_string) : ?>
173 173
         <br/>
174 174
         <span>
175 175
                 <?php
176
-                // Set TZ so localtime works.
177
-                date_default_timezone_set($timezone_string);
178
-                $now = localtime(time(), true);
179
-                if ($now['tm_isdst']) {
180
-                    esc_html_e('This timezone is currently in daylight saving time.', 'event_espresso');
181
-                } else {
182
-                    esc_html_e('This timezone is currently in standard time.', 'event_espresso');
183
-                }
184
-                ?>
176
+				// Set TZ so localtime works.
177
+				date_default_timezone_set($timezone_string);
178
+				$now = localtime(time(), true);
179
+				if ($now['tm_isdst']) {
180
+					esc_html_e('This timezone is currently in daylight saving time.', 'event_espresso');
181
+				} else {
182
+					esc_html_e('This timezone is currently in standard time.', 'event_espresso');
183
+				}
184
+				?>
185 185
             <br/>
186 186
             <?php
187
-            if (function_exists('timezone_transitions_get')) {
188
-                $found                   = false;
189
-                $date_time_zone_selected = new DateTimeZone($timezone_string);
190
-                $tz_offset               = timezone_offset_get($date_time_zone_selected, date_create());
191
-                $right_now               = time();
192
-                $tr['isdst']             = false;
193
-                foreach (timezone_transitions_get($date_time_zone_selected) as $tr) {
194
-                    if ($tr['ts'] > $right_now) {
195
-                        $found = true;
196
-                        break;
197
-                    }
198
-                }
199
-                if ($found) {
200
-                    $message = $tr['isdst']
201
-                        ? esc_html__(' Daylight saving time begins on: %s.', 'event_espresso')
202
-                        : esc_html__(' Standard time begins  on: %s.', 'event_espresso');
203
-                    // Add the difference between the current offset and the new offset to ts to get the correct
204
-                    // transition time from date_i18n().
205
-                    printf(
206
-                        $message,
207
-                        '<code >' . date_i18n($datetime_format, $tr['ts'] + ($tz_offset - $tr['offset'])) . '</code >'
208
-                    );
209
-                } else {
210
-                    esc_html_e('This timezone does not observe daylight saving time.', 'event_espresso');
211
-                }
212
-            }
213
-            // Set back to UTC.
214
-            date_default_timezone_set('UTC');
215
-            ?>
187
+			if (function_exists('timezone_transitions_get')) {
188
+				$found                   = false;
189
+				$date_time_zone_selected = new DateTimeZone($timezone_string);
190
+				$tz_offset               = timezone_offset_get($date_time_zone_selected, date_create());
191
+				$right_now               = time();
192
+				$tr['isdst']             = false;
193
+				foreach (timezone_transitions_get($date_time_zone_selected) as $tr) {
194
+					if ($tr['ts'] > $right_now) {
195
+						$found = true;
196
+						break;
197
+					}
198
+				}
199
+				if ($found) {
200
+					$message = $tr['isdst']
201
+						? esc_html__(' Daylight saving time begins on: %s.', 'event_espresso')
202
+						: esc_html__(' Standard time begins  on: %s.', 'event_espresso');
203
+					// Add the difference between the current offset and the new offset to ts to get the correct
204
+					// transition time from date_i18n().
205
+					printf(
206
+						$message,
207
+						'<code >' . date_i18n($datetime_format, $tr['ts'] + ($tz_offset - $tr['offset'])) . '</code >'
208
+					);
209
+				} else {
210
+					esc_html_e('This timezone does not observe daylight saving time.', 'event_espresso');
211
+				}
212
+			}
213
+			// Set back to UTC.
214
+			date_default_timezone_set('UTC');
215
+			?>
216 216
         </span></p>
217 217
             <?php
218
-        endif;
219
-    }
218
+		endif;
219
+	}
220 220
 
221 221
 
222
-    /**
223
-     * This method will take an incoming unix timestamp and add the offset to it for the given timezone_string.
224
-     * If no unix timestamp is given then time() is used.  If no timezone is given then the set timezone string for
225
-     * the site is used.
226
-     * This is used typically when using a Unix timestamp any core WP functions that expect their specially
227
-     * computed timestamp (i.e. date_i18n() )
228
-     *
229
-     * @param int    $unix_timestamp  if 0, then time() will be used.
230
-     * @param string $timezone_string timezone_string. If empty, then the current set timezone for the
231
-     *                                site will be used.
232
-     * @return int      unix_timestamp value with the offset applied for the given timezone.
233
-     * @throws EE_Error
234
-     */
235
-    public function getTimestampWithOffset($unix_timestamp = 0, $timezone_string = '')
236
-    {
237
-        $unix_timestamp  = $unix_timestamp === 0 ? time() : (int) $unix_timestamp;
238
-        $timezone_string = $this->getValidTimezoneString($timezone_string);
239
-        $TimeZone        = new DateTimeZone($timezone_string);
240
-        $DateTime        = new DateTime('@' . $unix_timestamp, $TimeZone);
241
-        $offset          = timezone_offset_get($TimeZone, $DateTime);
242
-        return (int) $DateTime->format('U') + (int) $offset;
243
-    }
222
+	/**
223
+	 * This method will take an incoming unix timestamp and add the offset to it for the given timezone_string.
224
+	 * If no unix timestamp is given then time() is used.  If no timezone is given then the set timezone string for
225
+	 * the site is used.
226
+	 * This is used typically when using a Unix timestamp any core WP functions that expect their specially
227
+	 * computed timestamp (i.e. date_i18n() )
228
+	 *
229
+	 * @param int    $unix_timestamp  if 0, then time() will be used.
230
+	 * @param string $timezone_string timezone_string. If empty, then the current set timezone for the
231
+	 *                                site will be used.
232
+	 * @return int      unix_timestamp value with the offset applied for the given timezone.
233
+	 * @throws EE_Error
234
+	 */
235
+	public function getTimestampWithOffset($unix_timestamp = 0, $timezone_string = '')
236
+	{
237
+		$unix_timestamp  = $unix_timestamp === 0 ? time() : (int) $unix_timestamp;
238
+		$timezone_string = $this->getValidTimezoneString($timezone_string);
239
+		$TimeZone        = new DateTimeZone($timezone_string);
240
+		$DateTime        = new DateTime('@' . $unix_timestamp, $TimeZone);
241
+		$offset          = timezone_offset_get($TimeZone, $DateTime);
242
+		return (int) $DateTime->format('U') + (int) $offset;
243
+	}
244 244
 
245 245
 
246
-    /**
247
-     * Get Timezone Transitions
248
-     *
249
-     * @param DateTimeZone $date_time_zone
250
-     * @param int|null     $time
251
-     * @param bool         $first_only
252
-     * @return array|mixed
253
-     */
254
-    public function getTimezoneTransitions(DateTimeZone $date_time_zone, $time = null, $first_only = true)
255
-    {
256
-        $time        = is_int($time) || $time === null ? $time : (int) strtotime($time);
257
-        $time        = preg_match(EE_Datetime_Field::unix_timestamp_regex, $time) ? $time : time();
258
-        $transitions = $date_time_zone->getTransitions($time);
259
-        return $first_only && ! isset($transitions['ts']) ? reset($transitions) : $transitions;
260
-    }
246
+	/**
247
+	 * Get Timezone Transitions
248
+	 *
249
+	 * @param DateTimeZone $date_time_zone
250
+	 * @param int|null     $time
251
+	 * @param bool         $first_only
252
+	 * @return array|mixed
253
+	 */
254
+	public function getTimezoneTransitions(DateTimeZone $date_time_zone, $time = null, $first_only = true)
255
+	{
256
+		$time        = is_int($time) || $time === null ? $time : (int) strtotime($time);
257
+		$time        = preg_match(EE_Datetime_Field::unix_timestamp_regex, $time) ? $time : time();
258
+		$transitions = $date_time_zone->getTransitions($time);
259
+		return $first_only && ! isset($transitions['ts']) ? reset($transitions) : $transitions;
260
+	}
261 261
 
262 262
 
263 263
 
264
-    /**
265
-     * Default to just returning the provided $gmt_offset.  Children can override if adjustment needed.
266
-     *
267
-     * @param int $gmt_offset
268
-     * @return int
269
-     */
270
-    public function adjustInvalidGmtOffsets($gmt_offset = 0)
271
-    {
272
-        return $gmt_offset;
273
-    }
264
+	/**
265
+	 * Default to just returning the provided $gmt_offset.  Children can override if adjustment needed.
266
+	 *
267
+	 * @param int $gmt_offset
268
+	 * @return int
269
+	 */
270
+	public function adjustInvalidGmtOffsets($gmt_offset = 0)
271
+	{
272
+		return $gmt_offset;
273
+	}
274 274
 
275 275
 
276 276
 
277
-    /**
278
-     * This receives an incoming gmt_offset and santizes it.  If the provide value is an empty string, then this will
279
-     * attempt to get the offset from the timezone string.  If this returns a string, then a timezone string was
280
-     * successfully derived from existing timezone_string in the db.  If not, then a float is returned for the provided
281
-     * offset.
282
-     * @param  float|string $gmt_offset
283
-     * @return float|string
284
-     */
285
-    protected function sanitizeInitialIncomingGmtOffsetForGettingTimezoneString($gmt_offset)
286
-    {
287
-        // if there is no incoming gmt_offset, then because WP hooks in on timezone_string, we need to see if that is
288
-        // set because it will override `gmt_offset` via `pre_get_option` filter.  If that's set, then let's just use
289
-        // that!  Otherwise we'll leave timezone_string at the default of 'UTC' before doing other logic.
290
-        if ($gmt_offset === '') {
291
-            // autoloaded so no need to set to a variable.  There will not be multiple hits to the db.
292
-            if (get_option('timezone_string')) {
293
-                return (string) get_option('timezone_string');
294
-            }
295
-        }
296
-        $gmt_offset = $gmt_offset !== '' ? $gmt_offset : (string) get_option('gmt_offset');
297
-        $gmt_offset = (float) $gmt_offset;
298
-        // if $gmt_offset is 0 or is still an empty string, then just return UTC
299
-        if ($gmt_offset === (float) 0) {
300
-            return 'UTC';
301
-        }
302
-        return $gmt_offset;
303
-    }
277
+	/**
278
+	 * This receives an incoming gmt_offset and santizes it.  If the provide value is an empty string, then this will
279
+	 * attempt to get the offset from the timezone string.  If this returns a string, then a timezone string was
280
+	 * successfully derived from existing timezone_string in the db.  If not, then a float is returned for the provided
281
+	 * offset.
282
+	 * @param  float|string $gmt_offset
283
+	 * @return float|string
284
+	 */
285
+	protected function sanitizeInitialIncomingGmtOffsetForGettingTimezoneString($gmt_offset)
286
+	{
287
+		// if there is no incoming gmt_offset, then because WP hooks in on timezone_string, we need to see if that is
288
+		// set because it will override `gmt_offset` via `pre_get_option` filter.  If that's set, then let's just use
289
+		// that!  Otherwise we'll leave timezone_string at the default of 'UTC' before doing other logic.
290
+		if ($gmt_offset === '') {
291
+			// autoloaded so no need to set to a variable.  There will not be multiple hits to the db.
292
+			if (get_option('timezone_string')) {
293
+				return (string) get_option('timezone_string');
294
+			}
295
+		}
296
+		$gmt_offset = $gmt_offset !== '' ? $gmt_offset : (string) get_option('gmt_offset');
297
+		$gmt_offset = (float) $gmt_offset;
298
+		// if $gmt_offset is 0 or is still an empty string, then just return UTC
299
+		if ($gmt_offset === (float) 0) {
300
+			return 'UTC';
301
+		}
302
+		return $gmt_offset;
303
+	}
304 304
 }
Please login to merge, or discard this patch.
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.
core/services/request/ServerParams.php 2 patches
Indentation   +180 added lines, -180 removed lines patch added patch discarded remove patch
@@ -7,184 +7,184 @@
 block discarded – undo
7 7
 class ServerParams
8 8
 {
9 9
 
10
-    /**
11
-     * IP address for request
12
-     *
13
-     * @var string
14
-     */
15
-    protected $ip_address;
16
-
17
-
18
-    /**
19
-     * @var ServerSanitizer
20
-     */
21
-    protected $sanitizer;
22
-
23
-    /**
24
-     * sanitized $_SERVER parameters
25
-     *
26
-     * @var array
27
-     */
28
-    protected $server;
29
-
30
-    /**
31
-     * @var string
32
-     */
33
-    protected $request_uri;
34
-
35
-    /**
36
-     * @var string
37
-     */
38
-    protected $user_agent;
39
-
40
-
41
-    /**
42
-     * ServerParams constructor.
43
-     *
44
-     * @param ServerSanitizer $sanitizer
45
-     * @param array           $server
46
-     */
47
-    public function __construct(ServerSanitizer $sanitizer, array $server = [])
48
-    {
49
-        $this->sanitizer  = $sanitizer;
50
-        $this->server     = $this->cleanServerParams($server);
51
-        $this->ip_address = $this->setVisitorIp();
52
-    }
53
-
54
-
55
-    /**
56
-     * @return array
57
-     */
58
-    private function cleanServerParams(array $server)
59
-    {
60
-        $cleaned = [];
61
-        $server  = ! empty($server) ? $server : $_SERVER;
62
-        foreach ($server as $key => $value) {
63
-            $cleaned[ $key ] = $this->sanitizer->clean($key, $value);
64
-        }
65
-        return $cleaned;
66
-    }
67
-
68
-
69
-    /**
70
-     * @return array
71
-     */
72
-    public function getAllServerParams()
73
-    {
74
-        return $this->server;
75
-    }
76
-
77
-
78
-    /**
79
-     * @param string $key
80
-     * @param mixed|null $default
81
-     * @return array|int|float|string
82
-     */
83
-    public function getServerParam($key, $default = null)
84
-    {
85
-        return $this->serverParamIsSet($key) ? $this->server[ $key ] : $default;
86
-    }
87
-
88
-
89
-    /**
90
-     * @param string                 $key
91
-     * @param array|int|float|string $value
92
-     * @return void
93
-     */
94
-    public function setServerParam($key, $value)
95
-    {
96
-        $this->server[ $key ] = $this->sanitizer->clean($key, $value);
97
-    }
98
-
99
-
100
-    /**
101
-     * @return bool
102
-     */
103
-    public function serverParamIsSet($key)
104
-    {
105
-        return isset($this->server[ $key ]);
106
-    }
107
-
108
-
109
-    /**
110
-     * @return string
111
-     */
112
-    public function ipAddress()
113
-    {
114
-        return $this->ip_address;
115
-    }
116
-
117
-
118
-    /**
119
-     * attempt to get IP address of current visitor from server
120
-     * plz see: http://stackoverflow.com/a/2031935/1475279
121
-     *
122
-     * @access public
123
-     * @return string
124
-     */
125
-    private function setVisitorIp()
126
-    {
127
-        $visitor_ip  = '0.0.0.0';
128
-        $server_keys = [
129
-            'HTTP_CLIENT_IP',
130
-            'HTTP_FORWARDED',
131
-            'HTTP_FORWARDED_FOR',
132
-            'HTTP_X_CLUSTER_CLIENT_IP',
133
-            'HTTP_X_FORWARDED',
134
-            'HTTP_X_FORWARDED_FOR',
135
-            'REMOTE_ADDR',
136
-        ];
137
-        foreach ($server_keys as $key) {
138
-            if (isset($this->server[ $key ])) {
139
-                $potential_ip = array_map('trim', explode(',', $this->server[ $key ]));
140
-                foreach ($potential_ip as $ip) {
141
-                    if ($ip === '127.0.0.1' || filter_var($ip, FILTER_VALIDATE_IP) !== false) {
142
-                        $visitor_ip = $ip;
143
-                    }
144
-                }
145
-            }
146
-        }
147
-        return $visitor_ip;
148
-    }
149
-
150
-
151
-    /**
152
-     * Gets the request's literal URI. Related to `requestUriAfterSiteHomeUri`, see its description for a comparison.
153
-     *
154
-     * @param boolean $relativeToWpRoot If home_url() is "http://mysite.com/wp/", and a request comes to
155
-     *                                  "http://mysite.com/wp/wp-json", setting $relativeToWpRoot=true will return
156
-     *                                  "/wp-json", whereas $relativeToWpRoot=false will return "/wp/wp-json/".
157
-     * @return string
158
-     */
159
-    public function requestUri($relativeToWpRoot = false)
160
-    {
161
-        if ($relativeToWpRoot) {
162
-            $home_path = untrailingslashit(parse_url(home_url(), PHP_URL_PATH));
163
-            return str_replace($home_path, '', $this->server['REQUEST_URI']);
164
-        }
165
-        return $this->server['REQUEST_URI'];
166
-    }
167
-
168
-
169
-    /**
170
-     * @return string
171
-     */
172
-    public function userAgent()
173
-    {
174
-        if (empty($this->user_agent)) {
175
-            $this->setUserAgent();
176
-        }
177
-        return $this->user_agent;
178
-    }
179
-
180
-
181
-    /**
182
-     * @param string $user_agent
183
-     */
184
-    public function setUserAgent($user_agent = '')
185
-    {
186
-        $this->user_agent = $user_agent === '' || ! is_string($user_agent)
187
-            ? $this->getServerParam('HTTP_USER_AGENT')
188
-            : esc_attr($user_agent);
189
-    }
10
+	/**
11
+	 * IP address for request
12
+	 *
13
+	 * @var string
14
+	 */
15
+	protected $ip_address;
16
+
17
+
18
+	/**
19
+	 * @var ServerSanitizer
20
+	 */
21
+	protected $sanitizer;
22
+
23
+	/**
24
+	 * sanitized $_SERVER parameters
25
+	 *
26
+	 * @var array
27
+	 */
28
+	protected $server;
29
+
30
+	/**
31
+	 * @var string
32
+	 */
33
+	protected $request_uri;
34
+
35
+	/**
36
+	 * @var string
37
+	 */
38
+	protected $user_agent;
39
+
40
+
41
+	/**
42
+	 * ServerParams constructor.
43
+	 *
44
+	 * @param ServerSanitizer $sanitizer
45
+	 * @param array           $server
46
+	 */
47
+	public function __construct(ServerSanitizer $sanitizer, array $server = [])
48
+	{
49
+		$this->sanitizer  = $sanitizer;
50
+		$this->server     = $this->cleanServerParams($server);
51
+		$this->ip_address = $this->setVisitorIp();
52
+	}
53
+
54
+
55
+	/**
56
+	 * @return array
57
+	 */
58
+	private function cleanServerParams(array $server)
59
+	{
60
+		$cleaned = [];
61
+		$server  = ! empty($server) ? $server : $_SERVER;
62
+		foreach ($server as $key => $value) {
63
+			$cleaned[ $key ] = $this->sanitizer->clean($key, $value);
64
+		}
65
+		return $cleaned;
66
+	}
67
+
68
+
69
+	/**
70
+	 * @return array
71
+	 */
72
+	public function getAllServerParams()
73
+	{
74
+		return $this->server;
75
+	}
76
+
77
+
78
+	/**
79
+	 * @param string $key
80
+	 * @param mixed|null $default
81
+	 * @return array|int|float|string
82
+	 */
83
+	public function getServerParam($key, $default = null)
84
+	{
85
+		return $this->serverParamIsSet($key) ? $this->server[ $key ] : $default;
86
+	}
87
+
88
+
89
+	/**
90
+	 * @param string                 $key
91
+	 * @param array|int|float|string $value
92
+	 * @return void
93
+	 */
94
+	public function setServerParam($key, $value)
95
+	{
96
+		$this->server[ $key ] = $this->sanitizer->clean($key, $value);
97
+	}
98
+
99
+
100
+	/**
101
+	 * @return bool
102
+	 */
103
+	public function serverParamIsSet($key)
104
+	{
105
+		return isset($this->server[ $key ]);
106
+	}
107
+
108
+
109
+	/**
110
+	 * @return string
111
+	 */
112
+	public function ipAddress()
113
+	{
114
+		return $this->ip_address;
115
+	}
116
+
117
+
118
+	/**
119
+	 * attempt to get IP address of current visitor from server
120
+	 * plz see: http://stackoverflow.com/a/2031935/1475279
121
+	 *
122
+	 * @access public
123
+	 * @return string
124
+	 */
125
+	private function setVisitorIp()
126
+	{
127
+		$visitor_ip  = '0.0.0.0';
128
+		$server_keys = [
129
+			'HTTP_CLIENT_IP',
130
+			'HTTP_FORWARDED',
131
+			'HTTP_FORWARDED_FOR',
132
+			'HTTP_X_CLUSTER_CLIENT_IP',
133
+			'HTTP_X_FORWARDED',
134
+			'HTTP_X_FORWARDED_FOR',
135
+			'REMOTE_ADDR',
136
+		];
137
+		foreach ($server_keys as $key) {
138
+			if (isset($this->server[ $key ])) {
139
+				$potential_ip = array_map('trim', explode(',', $this->server[ $key ]));
140
+				foreach ($potential_ip as $ip) {
141
+					if ($ip === '127.0.0.1' || filter_var($ip, FILTER_VALIDATE_IP) !== false) {
142
+						$visitor_ip = $ip;
143
+					}
144
+				}
145
+			}
146
+		}
147
+		return $visitor_ip;
148
+	}
149
+
150
+
151
+	/**
152
+	 * Gets the request's literal URI. Related to `requestUriAfterSiteHomeUri`, see its description for a comparison.
153
+	 *
154
+	 * @param boolean $relativeToWpRoot If home_url() is "http://mysite.com/wp/", and a request comes to
155
+	 *                                  "http://mysite.com/wp/wp-json", setting $relativeToWpRoot=true will return
156
+	 *                                  "/wp-json", whereas $relativeToWpRoot=false will return "/wp/wp-json/".
157
+	 * @return string
158
+	 */
159
+	public function requestUri($relativeToWpRoot = false)
160
+	{
161
+		if ($relativeToWpRoot) {
162
+			$home_path = untrailingslashit(parse_url(home_url(), PHP_URL_PATH));
163
+			return str_replace($home_path, '', $this->server['REQUEST_URI']);
164
+		}
165
+		return $this->server['REQUEST_URI'];
166
+	}
167
+
168
+
169
+	/**
170
+	 * @return string
171
+	 */
172
+	public function userAgent()
173
+	{
174
+		if (empty($this->user_agent)) {
175
+			$this->setUserAgent();
176
+		}
177
+		return $this->user_agent;
178
+	}
179
+
180
+
181
+	/**
182
+	 * @param string $user_agent
183
+	 */
184
+	public function setUserAgent($user_agent = '')
185
+	{
186
+		$this->user_agent = $user_agent === '' || ! is_string($user_agent)
187
+			? $this->getServerParam('HTTP_USER_AGENT')
188
+			: esc_attr($user_agent);
189
+	}
190 190
 }
Please login to merge, or discard this patch.
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -60,7 +60,7 @@  discard block
 block discarded – undo
60 60
         $cleaned = [];
61 61
         $server  = ! empty($server) ? $server : $_SERVER;
62 62
         foreach ($server as $key => $value) {
63
-            $cleaned[ $key ] = $this->sanitizer->clean($key, $value);
63
+            $cleaned[$key] = $this->sanitizer->clean($key, $value);
64 64
         }
65 65
         return $cleaned;
66 66
     }
@@ -82,7 +82,7 @@  discard block
 block discarded – undo
82 82
      */
83 83
     public function getServerParam($key, $default = null)
84 84
     {
85
-        return $this->serverParamIsSet($key) ? $this->server[ $key ] : $default;
85
+        return $this->serverParamIsSet($key) ? $this->server[$key] : $default;
86 86
     }
87 87
 
88 88
 
@@ -93,7 +93,7 @@  discard block
 block discarded – undo
93 93
      */
94 94
     public function setServerParam($key, $value)
95 95
     {
96
-        $this->server[ $key ] = $this->sanitizer->clean($key, $value);
96
+        $this->server[$key] = $this->sanitizer->clean($key, $value);
97 97
     }
98 98
 
99 99
 
@@ -102,7 +102,7 @@  discard block
 block discarded – undo
102 102
      */
103 103
     public function serverParamIsSet($key)
104 104
     {
105
-        return isset($this->server[ $key ]);
105
+        return isset($this->server[$key]);
106 106
     }
107 107
 
108 108
 
@@ -135,8 +135,8 @@  discard block
 block discarded – undo
135 135
             'REMOTE_ADDR',
136 136
         ];
137 137
         foreach ($server_keys as $key) {
138
-            if (isset($this->server[ $key ])) {
139
-                $potential_ip = array_map('trim', explode(',', $this->server[ $key ]));
138
+            if (isset($this->server[$key])) {
139
+                $potential_ip = array_map('trim', explode(',', $this->server[$key]));
140 140
                 foreach ($potential_ip as $ip) {
141 141
                     if ($ip === '127.0.0.1' || filter_var($ip, FILTER_VALIDATE_IP) !== false) {
142 142
                         $visitor_ip = $ip;
Please login to merge, or discard this patch.
core/services/progress_steps/ProgressStep.php 2 patches
Indentation   +186 added lines, -186 removed lines patch added patch discarded remove patch
@@ -18,190 +18,190 @@
 block discarded – undo
18 18
 {
19 19
 
20 20
 
21
-    /**
22
-     * @var boolean $current
23
-     */
24
-    private $current = false;
25
-
26
-
27
-    /**
28
-     * @var boolean $completed
29
-     */
30
-    private $completed = false;
31
-
32
-
33
-    /**
34
-     * @var string $html_class
35
-     */
36
-    private $html_class;
37
-
38
-    /**
39
-     * @var string $id
40
-     */
41
-    private $id = '';
42
-
43
-    /**
44
-     * @var int $order
45
-     */
46
-    private $order = 0;
47
-
48
-    /**
49
-     * @var string $text
50
-     */
51
-    private $text = '';
52
-
53
-
54
-    /**
55
-     * ProgressStep constructor
56
-     *
57
-     * @param int    $order
58
-     * @param string $id
59
-     * @param string $html_class
60
-     * @param string $text
61
-     * @throws InvalidDataTypeException
62
-     */
63
-    public function __construct($order, $id, $html_class, $text)
64
-    {
65
-        $this->setOrder($order);
66
-        $this->setId($id);
67
-        $this->setHtmlClass($html_class);
68
-        $this->setText($text);
69
-    }
70
-
71
-
72
-    /**
73
-     * @return boolean
74
-     */
75
-    public function isCurrent()
76
-    {
77
-        return $this->current;
78
-    }
79
-
80
-
81
-    /**
82
-     * @param boolean $current
83
-     */
84
-    public function setIsCurrent($current = true)
85
-    {
86
-        $this->current = filter_var($current, FILTER_VALIDATE_BOOLEAN);
87
-    }
88
-
89
-
90
-    /**
91
-     * @return boolean
92
-     */
93
-    public function isCompleted()
94
-    {
95
-        return $this->completed;
96
-    }
97
-
98
-
99
-    /**
100
-     * @param boolean $completed
101
-     */
102
-    public function setIsCompleted($completed = true)
103
-    {
104
-        $this->completed = filter_var($completed, FILTER_VALIDATE_BOOLEAN);
105
-    }
106
-
107
-
108
-    /**
109
-     * @return string
110
-     */
111
-    public function id()
112
-    {
113
-        return $this->id;
114
-    }
115
-
116
-
117
-    /**
118
-     * @access protected
119
-     * @param string $id
120
-     * @throws InvalidDataTypeException
121
-     */
122
-    protected function setId($id = '')
123
-    {
124
-        if (! is_string($id)) {
125
-            throw new InvalidDataTypeException('$id', $id, 'string');
126
-        }
127
-        $this->id = $id;
128
-    }
129
-
130
-
131
-    /**
132
-     * @return int
133
-     */
134
-    public function order()
135
-    {
136
-        return $this->order;
137
-    }
138
-
139
-
140
-    /**
141
-     * @access protected
142
-     * @param int $order
143
-     * @throws InvalidDataTypeException
144
-     */
145
-    protected function setOrder($order = 0)
146
-    {
147
-        if (! is_int($order)) {
148
-            throw new InvalidDataTypeException('$order', $order, 'integer');
149
-        }
150
-        $this->order = absint($order);
151
-    }
152
-
153
-
154
-    /**
155
-     * @return string
156
-     */
157
-    public function htmlClass()
158
-    {
159
-        $html_class = $this->html_class;
160
-        if ($this->isCurrent()) {
161
-            $html_class .= ' progress-step-active';
162
-        } elseif ($this->isCompleted()) {
163
-            $html_class .= ' progress-step-completed';
164
-        }
165
-        return $html_class;
166
-    }
167
-
168
-
169
-    /**
170
-     * @access protected
171
-     * @param string $html_class
172
-     * @throws InvalidDataTypeException
173
-     */
174
-    protected function setHtmlClass($html_class)
175
-    {
176
-        if (! is_string($html_class)) {
177
-            throw new InvalidDataTypeException('$html_class', $html_class, 'string');
178
-        }
179
-        if (strpos($html_class, 'progress-step-') === false) {
180
-            $html_class = 'progress-step-' . $html_class;
181
-        }
182
-        $this->html_class = $html_class;
183
-    }
184
-
185
-
186
-    /**
187
-     * @return string
188
-     */
189
-    public function text()
190
-    {
191
-        return $this->text;
192
-    }
193
-
194
-
195
-    /**
196
-     * @access protected
197
-     * @param string $text
198
-     * @throws InvalidDataTypeException
199
-     */
200
-    protected function setText($text)
201
-    {
202
-        if (! is_string($text)) {
203
-            throw new InvalidDataTypeException('$text', $text, 'string');
204
-        }
205
-        $this->text = sanitize_text_field($text);
206
-    }
21
+	/**
22
+	 * @var boolean $current
23
+	 */
24
+	private $current = false;
25
+
26
+
27
+	/**
28
+	 * @var boolean $completed
29
+	 */
30
+	private $completed = false;
31
+
32
+
33
+	/**
34
+	 * @var string $html_class
35
+	 */
36
+	private $html_class;
37
+
38
+	/**
39
+	 * @var string $id
40
+	 */
41
+	private $id = '';
42
+
43
+	/**
44
+	 * @var int $order
45
+	 */
46
+	private $order = 0;
47
+
48
+	/**
49
+	 * @var string $text
50
+	 */
51
+	private $text = '';
52
+
53
+
54
+	/**
55
+	 * ProgressStep constructor
56
+	 *
57
+	 * @param int    $order
58
+	 * @param string $id
59
+	 * @param string $html_class
60
+	 * @param string $text
61
+	 * @throws InvalidDataTypeException
62
+	 */
63
+	public function __construct($order, $id, $html_class, $text)
64
+	{
65
+		$this->setOrder($order);
66
+		$this->setId($id);
67
+		$this->setHtmlClass($html_class);
68
+		$this->setText($text);
69
+	}
70
+
71
+
72
+	/**
73
+	 * @return boolean
74
+	 */
75
+	public function isCurrent()
76
+	{
77
+		return $this->current;
78
+	}
79
+
80
+
81
+	/**
82
+	 * @param boolean $current
83
+	 */
84
+	public function setIsCurrent($current = true)
85
+	{
86
+		$this->current = filter_var($current, FILTER_VALIDATE_BOOLEAN);
87
+	}
88
+
89
+
90
+	/**
91
+	 * @return boolean
92
+	 */
93
+	public function isCompleted()
94
+	{
95
+		return $this->completed;
96
+	}
97
+
98
+
99
+	/**
100
+	 * @param boolean $completed
101
+	 */
102
+	public function setIsCompleted($completed = true)
103
+	{
104
+		$this->completed = filter_var($completed, FILTER_VALIDATE_BOOLEAN);
105
+	}
106
+
107
+
108
+	/**
109
+	 * @return string
110
+	 */
111
+	public function id()
112
+	{
113
+		return $this->id;
114
+	}
115
+
116
+
117
+	/**
118
+	 * @access protected
119
+	 * @param string $id
120
+	 * @throws InvalidDataTypeException
121
+	 */
122
+	protected function setId($id = '')
123
+	{
124
+		if (! is_string($id)) {
125
+			throw new InvalidDataTypeException('$id', $id, 'string');
126
+		}
127
+		$this->id = $id;
128
+	}
129
+
130
+
131
+	/**
132
+	 * @return int
133
+	 */
134
+	public function order()
135
+	{
136
+		return $this->order;
137
+	}
138
+
139
+
140
+	/**
141
+	 * @access protected
142
+	 * @param int $order
143
+	 * @throws InvalidDataTypeException
144
+	 */
145
+	protected function setOrder($order = 0)
146
+	{
147
+		if (! is_int($order)) {
148
+			throw new InvalidDataTypeException('$order', $order, 'integer');
149
+		}
150
+		$this->order = absint($order);
151
+	}
152
+
153
+
154
+	/**
155
+	 * @return string
156
+	 */
157
+	public function htmlClass()
158
+	{
159
+		$html_class = $this->html_class;
160
+		if ($this->isCurrent()) {
161
+			$html_class .= ' progress-step-active';
162
+		} elseif ($this->isCompleted()) {
163
+			$html_class .= ' progress-step-completed';
164
+		}
165
+		return $html_class;
166
+	}
167
+
168
+
169
+	/**
170
+	 * @access protected
171
+	 * @param string $html_class
172
+	 * @throws InvalidDataTypeException
173
+	 */
174
+	protected function setHtmlClass($html_class)
175
+	{
176
+		if (! is_string($html_class)) {
177
+			throw new InvalidDataTypeException('$html_class', $html_class, 'string');
178
+		}
179
+		if (strpos($html_class, 'progress-step-') === false) {
180
+			$html_class = 'progress-step-' . $html_class;
181
+		}
182
+		$this->html_class = $html_class;
183
+	}
184
+
185
+
186
+	/**
187
+	 * @return string
188
+	 */
189
+	public function text()
190
+	{
191
+		return $this->text;
192
+	}
193
+
194
+
195
+	/**
196
+	 * @access protected
197
+	 * @param string $text
198
+	 * @throws InvalidDataTypeException
199
+	 */
200
+	protected function setText($text)
201
+	{
202
+		if (! is_string($text)) {
203
+			throw new InvalidDataTypeException('$text', $text, 'string');
204
+		}
205
+		$this->text = sanitize_text_field($text);
206
+	}
207 207
 }
Please login to merge, or discard this patch.
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.