@@ -23,311 +23,311 @@ |
||
23 | 23 | */ |
24 | 24 | class CurrentPage |
25 | 25 | { |
26 | - /** |
|
27 | - * @var EE_CPT_Strategy |
|
28 | - */ |
|
29 | - private $cpt_strategy; |
|
30 | - |
|
31 | - /** |
|
32 | - * @var bool |
|
33 | - */ |
|
34 | - private $initialized; |
|
35 | - |
|
36 | - /** |
|
37 | - * @var bool |
|
38 | - */ |
|
39 | - private $is_espresso_page = false; |
|
40 | - |
|
41 | - /** |
|
42 | - * @var int |
|
43 | - */ |
|
44 | - private $post_id = 0; |
|
45 | - |
|
46 | - /** |
|
47 | - * @var string |
|
48 | - */ |
|
49 | - private $post_name = ''; |
|
50 | - |
|
51 | - /** |
|
52 | - * @var array |
|
53 | - */ |
|
54 | - private $post_type = []; |
|
55 | - |
|
56 | - /** |
|
57 | - * @var RequestInterface $request |
|
58 | - */ |
|
59 | - private $request; |
|
60 | - |
|
61 | - |
|
62 | - /** |
|
63 | - * CurrentPage constructor. |
|
64 | - * |
|
65 | - * @param EE_CPT_Strategy $cpt_strategy |
|
66 | - * @param RequestInterface $request |
|
67 | - */ |
|
68 | - public function __construct(EE_CPT_Strategy $cpt_strategy, RequestInterface $request) |
|
69 | - { |
|
70 | - $this->cpt_strategy = $cpt_strategy; |
|
71 | - $this->request = $request; |
|
72 | - $this->initialized = is_admin(); |
|
73 | - // analyse the incoming WP request |
|
74 | - add_action('parse_request', [$this, 'parseQueryVars'], 2, 1); |
|
75 | - } |
|
76 | - |
|
77 | - |
|
78 | - /** |
|
79 | - * @param WP $WP |
|
80 | - * @return void |
|
81 | - */ |
|
82 | - public function parseQueryVars(WP $WP = null) |
|
83 | - { |
|
84 | - if ($this->initialized) { |
|
85 | - return; |
|
86 | - } |
|
87 | - // if somebody forgot to provide us with WP, that's ok because its global |
|
88 | - if (! $WP instanceof WP) { |
|
89 | - global $WP; |
|
90 | - } |
|
91 | - $this->post_id = $this->getPostId($WP); |
|
92 | - $this->post_name = $this->getPostName($WP); |
|
93 | - $this->post_type = $this->getPostType($WP); |
|
94 | - // true or false ? is this page being used by EE ? |
|
95 | - $this->setEspressoPage(); |
|
96 | - remove_action('parse_request', [$this, 'parseRequest'], 2); |
|
97 | - $this->initialized = true; |
|
98 | - } |
|
99 | - |
|
100 | - |
|
101 | - /** |
|
102 | - * Just a helper method for getting the url for the displayed page. |
|
103 | - * |
|
104 | - * @param WP|null $WP |
|
105 | - * @return string |
|
106 | - */ |
|
107 | - public function getPermalink(WP $WP = null) |
|
108 | - { |
|
109 | - $post_id = $this->post_id ?: $this->getPostId($WP); |
|
110 | - if ($post_id) { |
|
111 | - return get_permalink($post_id); |
|
112 | - } |
|
113 | - if (! $WP instanceof WP) { |
|
114 | - global $WP; |
|
115 | - } |
|
116 | - if ($WP instanceof WP && $WP->request) { |
|
117 | - return site_url($WP->request); |
|
118 | - } |
|
119 | - return esc_url_raw(site_url($_SERVER['REQUEST_URI'])); |
|
120 | - } |
|
121 | - |
|
122 | - |
|
123 | - /** |
|
124 | - * @return array |
|
125 | - */ |
|
126 | - public function espressoPostType() |
|
127 | - { |
|
128 | - return array_filter( |
|
129 | - $this->post_type, |
|
130 | - function ($post_type) { |
|
131 | - return strpos($post_type, 'espresso_') === 0; |
|
132 | - } |
|
133 | - ); |
|
134 | - } |
|
135 | - |
|
136 | - |
|
137 | - /** |
|
138 | - * pokes and prods the WP object query_vars in an attempt to shake out a page/post ID |
|
139 | - * |
|
140 | - * @param WP $WP |
|
141 | - * @return int |
|
142 | - */ |
|
143 | - private function getPostId(WP $WP = null) |
|
144 | - { |
|
145 | - $post_id = null; |
|
146 | - // look for the post ID in the aptly named 'p' query var |
|
147 | - if (isset($WP->query_vars['p'])) { |
|
148 | - $post_id = $WP->query_vars['p']; |
|
149 | - } |
|
150 | - // not a post? what about a page? |
|
151 | - if (! $post_id && isset($WP->query_vars['page_id'])) { |
|
152 | - $post_id = $WP->query_vars['page_id']; |
|
153 | - } |
|
154 | - // ok... maybe pretty permalinks are off and the ID is set in the raw request... |
|
155 | - // but hasn't been processed yet ie: this method is being called too early :\ |
|
156 | - if (! $post_id && $WP instanceof WP && $WP->request !== null && is_numeric(basename($WP->request))) { |
|
157 | - $post_id = basename($WP->request); |
|
158 | - } |
|
159 | - // none of the above? ok what about an explicit "post_id" URL parameter? |
|
160 | - if (! $post_id && $this->request->requestParamIsSet('post_id')) { |
|
161 | - $post_id = $this->request->getRequestParam('post_id'); |
|
162 | - } |
|
163 | - return $post_id; |
|
164 | - } |
|
165 | - |
|
166 | - |
|
167 | - /** |
|
168 | - * similar to getPostId() above but attempts to obtain the "name" for the current page/post |
|
169 | - * |
|
170 | - * @param WP $WP |
|
171 | - * @return string |
|
172 | - */ |
|
173 | - private function getPostName(WP $WP = null) |
|
174 | - { |
|
175 | - global $wpdb; |
|
176 | - $post_name = null; |
|
177 | - // if this is a post, then is the post name set? |
|
178 | - if (isset($WP->query_vars['name']) && ! empty($WP->query_vars['name'])) { |
|
179 | - $post_name = $WP->query_vars['name']; |
|
180 | - } |
|
181 | - // what about the page name? |
|
182 | - if (! $post_name && isset($WP->query_vars['pagename']) && ! empty($WP->query_vars['pagename'])) { |
|
183 | - $post_name = $WP->query_vars['pagename']; |
|
184 | - } |
|
185 | - // this stinks but let's run a query to try and get the post name from the URL |
|
186 | - // (assuming pretty permalinks are on) |
|
187 | - if (! $post_name && $WP instanceof WP && $WP->request !== null && ! empty($WP->request)) { |
|
188 | - $possible_post_name = basename($WP->request); |
|
189 | - if (! is_numeric($possible_post_name)) { |
|
190 | - $SQL = "SELECT ID from {$wpdb->posts}"; |
|
191 | - $SQL .= " WHERE post_status NOT IN ('auto-draft', 'inherit', 'trash')"; |
|
192 | - $SQL .= ' AND post_name=%s'; |
|
193 | - $possible_post_name = $wpdb->get_var($wpdb->prepare($SQL, $possible_post_name)); |
|
194 | - if ($possible_post_name) { |
|
195 | - $post_name = $possible_post_name; |
|
196 | - } |
|
197 | - } |
|
198 | - } |
|
199 | - // ug... ok... nothing yet... but do we have a post ID? |
|
200 | - // if so then... sigh... run a query to get the post name :\ |
|
201 | - if (! $post_name && $this->post_id) { |
|
202 | - $SQL = "SELECT post_name from {$wpdb->posts}"; |
|
203 | - $SQL .= " WHERE post_status NOT IN ('auto-draft', 'inherit', 'trash')"; |
|
204 | - $SQL .= ' AND ID=%d'; |
|
205 | - $possible_post_name = $wpdb->get_var($wpdb->prepare($SQL, $this->post_id)); |
|
206 | - if ($possible_post_name) { |
|
207 | - $post_name = $possible_post_name; |
|
208 | - } |
|
209 | - } |
|
210 | - // still nothing? ok what about an explicit 'post_name' URL parameter? |
|
211 | - if (! $post_name && $this->request->requestParamIsSet('post_name')) { |
|
212 | - $post_name = $this->request->getRequestParam('post_name'); |
|
213 | - } |
|
214 | - return $post_name; |
|
215 | - } |
|
216 | - |
|
217 | - |
|
218 | - /** |
|
219 | - * also similar to getPostId() and getPostName() above but not as insane |
|
220 | - * |
|
221 | - * @param WP $WP |
|
222 | - * @return array |
|
223 | - */ |
|
224 | - private function getPostType(WP $WP = null) |
|
225 | - { |
|
226 | - $post_types = isset($WP->query_vars['post_type']) |
|
227 | - ? (array) $WP->query_vars['post_type'] |
|
228 | - : []; |
|
229 | - if (empty($post_types) && $this->request->requestParamIsSet('post_type')) { |
|
230 | - $post_types = $this->request->getRequestParam('post_type'); |
|
231 | - } |
|
232 | - return (array) $post_types; |
|
233 | - } |
|
234 | - |
|
235 | - |
|
236 | - /** |
|
237 | - * if TRUE, then the current page is somehow utilizing EE logic |
|
238 | - * |
|
239 | - * @return bool |
|
240 | - */ |
|
241 | - public function isEspressoPage() |
|
242 | - { |
|
243 | - return $this->is_espresso_page; |
|
244 | - } |
|
245 | - |
|
246 | - |
|
247 | - /** |
|
248 | - * @return int |
|
249 | - */ |
|
250 | - public function postId() |
|
251 | - { |
|
252 | - return $this->post_id; |
|
253 | - } |
|
254 | - |
|
255 | - |
|
256 | - /** |
|
257 | - * @return string |
|
258 | - */ |
|
259 | - public function postName() |
|
260 | - { |
|
261 | - return $this->post_name; |
|
262 | - } |
|
263 | - |
|
264 | - |
|
265 | - /** |
|
266 | - * @return array |
|
267 | - */ |
|
268 | - public function postType() |
|
269 | - { |
|
270 | - return $this->post_type; |
|
271 | - } |
|
272 | - |
|
273 | - |
|
274 | - /** |
|
275 | - * for manually indicating the current page will utilize EE logic |
|
276 | - * |
|
277 | - * @param null|bool $value |
|
278 | - * @return void |
|
279 | - */ |
|
280 | - public function setEspressoPage($value = null) |
|
281 | - { |
|
282 | - $this->is_espresso_page = $value !== null |
|
283 | - ? filter_var($value, FILTER_VALIDATE_BOOLEAN) |
|
284 | - : $this->testForEspressoPage(); |
|
285 | - } |
|
286 | - |
|
287 | - |
|
288 | - /** |
|
289 | - * attempts to determine if the current page/post is an EE related page/post |
|
290 | - * because it utilizes one of our CPT taxonomies, endpoints, or post types |
|
291 | - * |
|
292 | - * @return bool |
|
293 | - */ |
|
294 | - private function testForEspressoPage() |
|
295 | - { |
|
296 | - // in case it has already been set |
|
297 | - if ($this->is_espresso_page) { |
|
298 | - return true; |
|
299 | - } |
|
300 | - global $WP; |
|
301 | - $espresso_CPT_taxonomies = $this->cpt_strategy->get_CPT_taxonomies(); |
|
302 | - if (is_array($espresso_CPT_taxonomies)) { |
|
303 | - foreach ($espresso_CPT_taxonomies as $espresso_CPT_taxonomy => $details) { |
|
304 | - if (isset($WP->query_vars, $WP->query_vars[ $espresso_CPT_taxonomy ])) { |
|
305 | - return true; |
|
306 | - } |
|
307 | - } |
|
308 | - } |
|
309 | - // load espresso CPT endpoints |
|
310 | - $espresso_CPT_endpoints = $this->cpt_strategy->get_CPT_endpoints(); |
|
311 | - $post_type_CPT_endpoints = array_flip($espresso_CPT_endpoints); |
|
312 | - foreach ($this->post_type as $post_type) { |
|
313 | - // was a post name passed ? |
|
314 | - if (isset($post_type_CPT_endpoints[ $post_type ])) { |
|
315 | - // kk we know this is an espresso page, but is it a specific post ? |
|
316 | - if (! $this->post_name) { |
|
317 | - $espresso_post_type = $this->request->getRequestParam('post_type'); |
|
318 | - // there's no specific post name set, so maybe it's one of our endpoints like www.domain.com/events |
|
319 | - // this essentially sets the post_name to "events" (or whatever EE CPT) |
|
320 | - $post_name = isset($post_type_CPT_endpoints[ $espresso_post_type ]) |
|
321 | - ? $post_type_CPT_endpoints[ $espresso_post_type ] |
|
322 | - : ''; |
|
323 | - // if the post type matches one of ours then set the post name to the endpoint |
|
324 | - if ($post_name) { |
|
325 | - $this->post_name = $post_name; |
|
326 | - } |
|
327 | - } |
|
328 | - return true; |
|
329 | - } |
|
330 | - } |
|
331 | - return false; |
|
332 | - } |
|
26 | + /** |
|
27 | + * @var EE_CPT_Strategy |
|
28 | + */ |
|
29 | + private $cpt_strategy; |
|
30 | + |
|
31 | + /** |
|
32 | + * @var bool |
|
33 | + */ |
|
34 | + private $initialized; |
|
35 | + |
|
36 | + /** |
|
37 | + * @var bool |
|
38 | + */ |
|
39 | + private $is_espresso_page = false; |
|
40 | + |
|
41 | + /** |
|
42 | + * @var int |
|
43 | + */ |
|
44 | + private $post_id = 0; |
|
45 | + |
|
46 | + /** |
|
47 | + * @var string |
|
48 | + */ |
|
49 | + private $post_name = ''; |
|
50 | + |
|
51 | + /** |
|
52 | + * @var array |
|
53 | + */ |
|
54 | + private $post_type = []; |
|
55 | + |
|
56 | + /** |
|
57 | + * @var RequestInterface $request |
|
58 | + */ |
|
59 | + private $request; |
|
60 | + |
|
61 | + |
|
62 | + /** |
|
63 | + * CurrentPage constructor. |
|
64 | + * |
|
65 | + * @param EE_CPT_Strategy $cpt_strategy |
|
66 | + * @param RequestInterface $request |
|
67 | + */ |
|
68 | + public function __construct(EE_CPT_Strategy $cpt_strategy, RequestInterface $request) |
|
69 | + { |
|
70 | + $this->cpt_strategy = $cpt_strategy; |
|
71 | + $this->request = $request; |
|
72 | + $this->initialized = is_admin(); |
|
73 | + // analyse the incoming WP request |
|
74 | + add_action('parse_request', [$this, 'parseQueryVars'], 2, 1); |
|
75 | + } |
|
76 | + |
|
77 | + |
|
78 | + /** |
|
79 | + * @param WP $WP |
|
80 | + * @return void |
|
81 | + */ |
|
82 | + public function parseQueryVars(WP $WP = null) |
|
83 | + { |
|
84 | + if ($this->initialized) { |
|
85 | + return; |
|
86 | + } |
|
87 | + // if somebody forgot to provide us with WP, that's ok because its global |
|
88 | + if (! $WP instanceof WP) { |
|
89 | + global $WP; |
|
90 | + } |
|
91 | + $this->post_id = $this->getPostId($WP); |
|
92 | + $this->post_name = $this->getPostName($WP); |
|
93 | + $this->post_type = $this->getPostType($WP); |
|
94 | + // true or false ? is this page being used by EE ? |
|
95 | + $this->setEspressoPage(); |
|
96 | + remove_action('parse_request', [$this, 'parseRequest'], 2); |
|
97 | + $this->initialized = true; |
|
98 | + } |
|
99 | + |
|
100 | + |
|
101 | + /** |
|
102 | + * Just a helper method for getting the url for the displayed page. |
|
103 | + * |
|
104 | + * @param WP|null $WP |
|
105 | + * @return string |
|
106 | + */ |
|
107 | + public function getPermalink(WP $WP = null) |
|
108 | + { |
|
109 | + $post_id = $this->post_id ?: $this->getPostId($WP); |
|
110 | + if ($post_id) { |
|
111 | + return get_permalink($post_id); |
|
112 | + } |
|
113 | + if (! $WP instanceof WP) { |
|
114 | + global $WP; |
|
115 | + } |
|
116 | + if ($WP instanceof WP && $WP->request) { |
|
117 | + return site_url($WP->request); |
|
118 | + } |
|
119 | + return esc_url_raw(site_url($_SERVER['REQUEST_URI'])); |
|
120 | + } |
|
121 | + |
|
122 | + |
|
123 | + /** |
|
124 | + * @return array |
|
125 | + */ |
|
126 | + public function espressoPostType() |
|
127 | + { |
|
128 | + return array_filter( |
|
129 | + $this->post_type, |
|
130 | + function ($post_type) { |
|
131 | + return strpos($post_type, 'espresso_') === 0; |
|
132 | + } |
|
133 | + ); |
|
134 | + } |
|
135 | + |
|
136 | + |
|
137 | + /** |
|
138 | + * pokes and prods the WP object query_vars in an attempt to shake out a page/post ID |
|
139 | + * |
|
140 | + * @param WP $WP |
|
141 | + * @return int |
|
142 | + */ |
|
143 | + private function getPostId(WP $WP = null) |
|
144 | + { |
|
145 | + $post_id = null; |
|
146 | + // look for the post ID in the aptly named 'p' query var |
|
147 | + if (isset($WP->query_vars['p'])) { |
|
148 | + $post_id = $WP->query_vars['p']; |
|
149 | + } |
|
150 | + // not a post? what about a page? |
|
151 | + if (! $post_id && isset($WP->query_vars['page_id'])) { |
|
152 | + $post_id = $WP->query_vars['page_id']; |
|
153 | + } |
|
154 | + // ok... maybe pretty permalinks are off and the ID is set in the raw request... |
|
155 | + // but hasn't been processed yet ie: this method is being called too early :\ |
|
156 | + if (! $post_id && $WP instanceof WP && $WP->request !== null && is_numeric(basename($WP->request))) { |
|
157 | + $post_id = basename($WP->request); |
|
158 | + } |
|
159 | + // none of the above? ok what about an explicit "post_id" URL parameter? |
|
160 | + if (! $post_id && $this->request->requestParamIsSet('post_id')) { |
|
161 | + $post_id = $this->request->getRequestParam('post_id'); |
|
162 | + } |
|
163 | + return $post_id; |
|
164 | + } |
|
165 | + |
|
166 | + |
|
167 | + /** |
|
168 | + * similar to getPostId() above but attempts to obtain the "name" for the current page/post |
|
169 | + * |
|
170 | + * @param WP $WP |
|
171 | + * @return string |
|
172 | + */ |
|
173 | + private function getPostName(WP $WP = null) |
|
174 | + { |
|
175 | + global $wpdb; |
|
176 | + $post_name = null; |
|
177 | + // if this is a post, then is the post name set? |
|
178 | + if (isset($WP->query_vars['name']) && ! empty($WP->query_vars['name'])) { |
|
179 | + $post_name = $WP->query_vars['name']; |
|
180 | + } |
|
181 | + // what about the page name? |
|
182 | + if (! $post_name && isset($WP->query_vars['pagename']) && ! empty($WP->query_vars['pagename'])) { |
|
183 | + $post_name = $WP->query_vars['pagename']; |
|
184 | + } |
|
185 | + // this stinks but let's run a query to try and get the post name from the URL |
|
186 | + // (assuming pretty permalinks are on) |
|
187 | + if (! $post_name && $WP instanceof WP && $WP->request !== null && ! empty($WP->request)) { |
|
188 | + $possible_post_name = basename($WP->request); |
|
189 | + if (! is_numeric($possible_post_name)) { |
|
190 | + $SQL = "SELECT ID from {$wpdb->posts}"; |
|
191 | + $SQL .= " WHERE post_status NOT IN ('auto-draft', 'inherit', 'trash')"; |
|
192 | + $SQL .= ' AND post_name=%s'; |
|
193 | + $possible_post_name = $wpdb->get_var($wpdb->prepare($SQL, $possible_post_name)); |
|
194 | + if ($possible_post_name) { |
|
195 | + $post_name = $possible_post_name; |
|
196 | + } |
|
197 | + } |
|
198 | + } |
|
199 | + // ug... ok... nothing yet... but do we have a post ID? |
|
200 | + // if so then... sigh... run a query to get the post name :\ |
|
201 | + if (! $post_name && $this->post_id) { |
|
202 | + $SQL = "SELECT post_name from {$wpdb->posts}"; |
|
203 | + $SQL .= " WHERE post_status NOT IN ('auto-draft', 'inherit', 'trash')"; |
|
204 | + $SQL .= ' AND ID=%d'; |
|
205 | + $possible_post_name = $wpdb->get_var($wpdb->prepare($SQL, $this->post_id)); |
|
206 | + if ($possible_post_name) { |
|
207 | + $post_name = $possible_post_name; |
|
208 | + } |
|
209 | + } |
|
210 | + // still nothing? ok what about an explicit 'post_name' URL parameter? |
|
211 | + if (! $post_name && $this->request->requestParamIsSet('post_name')) { |
|
212 | + $post_name = $this->request->getRequestParam('post_name'); |
|
213 | + } |
|
214 | + return $post_name; |
|
215 | + } |
|
216 | + |
|
217 | + |
|
218 | + /** |
|
219 | + * also similar to getPostId() and getPostName() above but not as insane |
|
220 | + * |
|
221 | + * @param WP $WP |
|
222 | + * @return array |
|
223 | + */ |
|
224 | + private function getPostType(WP $WP = null) |
|
225 | + { |
|
226 | + $post_types = isset($WP->query_vars['post_type']) |
|
227 | + ? (array) $WP->query_vars['post_type'] |
|
228 | + : []; |
|
229 | + if (empty($post_types) && $this->request->requestParamIsSet('post_type')) { |
|
230 | + $post_types = $this->request->getRequestParam('post_type'); |
|
231 | + } |
|
232 | + return (array) $post_types; |
|
233 | + } |
|
234 | + |
|
235 | + |
|
236 | + /** |
|
237 | + * if TRUE, then the current page is somehow utilizing EE logic |
|
238 | + * |
|
239 | + * @return bool |
|
240 | + */ |
|
241 | + public function isEspressoPage() |
|
242 | + { |
|
243 | + return $this->is_espresso_page; |
|
244 | + } |
|
245 | + |
|
246 | + |
|
247 | + /** |
|
248 | + * @return int |
|
249 | + */ |
|
250 | + public function postId() |
|
251 | + { |
|
252 | + return $this->post_id; |
|
253 | + } |
|
254 | + |
|
255 | + |
|
256 | + /** |
|
257 | + * @return string |
|
258 | + */ |
|
259 | + public function postName() |
|
260 | + { |
|
261 | + return $this->post_name; |
|
262 | + } |
|
263 | + |
|
264 | + |
|
265 | + /** |
|
266 | + * @return array |
|
267 | + */ |
|
268 | + public function postType() |
|
269 | + { |
|
270 | + return $this->post_type; |
|
271 | + } |
|
272 | + |
|
273 | + |
|
274 | + /** |
|
275 | + * for manually indicating the current page will utilize EE logic |
|
276 | + * |
|
277 | + * @param null|bool $value |
|
278 | + * @return void |
|
279 | + */ |
|
280 | + public function setEspressoPage($value = null) |
|
281 | + { |
|
282 | + $this->is_espresso_page = $value !== null |
|
283 | + ? filter_var($value, FILTER_VALIDATE_BOOLEAN) |
|
284 | + : $this->testForEspressoPage(); |
|
285 | + } |
|
286 | + |
|
287 | + |
|
288 | + /** |
|
289 | + * attempts to determine if the current page/post is an EE related page/post |
|
290 | + * because it utilizes one of our CPT taxonomies, endpoints, or post types |
|
291 | + * |
|
292 | + * @return bool |
|
293 | + */ |
|
294 | + private function testForEspressoPage() |
|
295 | + { |
|
296 | + // in case it has already been set |
|
297 | + if ($this->is_espresso_page) { |
|
298 | + return true; |
|
299 | + } |
|
300 | + global $WP; |
|
301 | + $espresso_CPT_taxonomies = $this->cpt_strategy->get_CPT_taxonomies(); |
|
302 | + if (is_array($espresso_CPT_taxonomies)) { |
|
303 | + foreach ($espresso_CPT_taxonomies as $espresso_CPT_taxonomy => $details) { |
|
304 | + if (isset($WP->query_vars, $WP->query_vars[ $espresso_CPT_taxonomy ])) { |
|
305 | + return true; |
|
306 | + } |
|
307 | + } |
|
308 | + } |
|
309 | + // load espresso CPT endpoints |
|
310 | + $espresso_CPT_endpoints = $this->cpt_strategy->get_CPT_endpoints(); |
|
311 | + $post_type_CPT_endpoints = array_flip($espresso_CPT_endpoints); |
|
312 | + foreach ($this->post_type as $post_type) { |
|
313 | + // was a post name passed ? |
|
314 | + if (isset($post_type_CPT_endpoints[ $post_type ])) { |
|
315 | + // kk we know this is an espresso page, but is it a specific post ? |
|
316 | + if (! $this->post_name) { |
|
317 | + $espresso_post_type = $this->request->getRequestParam('post_type'); |
|
318 | + // there's no specific post name set, so maybe it's one of our endpoints like www.domain.com/events |
|
319 | + // this essentially sets the post_name to "events" (or whatever EE CPT) |
|
320 | + $post_name = isset($post_type_CPT_endpoints[ $espresso_post_type ]) |
|
321 | + ? $post_type_CPT_endpoints[ $espresso_post_type ] |
|
322 | + : ''; |
|
323 | + // if the post type matches one of ours then set the post name to the endpoint |
|
324 | + if ($post_name) { |
|
325 | + $this->post_name = $post_name; |
|
326 | + } |
|
327 | + } |
|
328 | + return true; |
|
329 | + } |
|
330 | + } |
|
331 | + return false; |
|
332 | + } |
|
333 | 333 | } |
@@ -85,7 +85,7 @@ discard block |
||
85 | 85 | return; |
86 | 86 | } |
87 | 87 | // if somebody forgot to provide us with WP, that's ok because its global |
88 | - if (! $WP instanceof WP) { |
|
88 | + if ( ! $WP instanceof WP) { |
|
89 | 89 | global $WP; |
90 | 90 | } |
91 | 91 | $this->post_id = $this->getPostId($WP); |
@@ -94,7 +94,7 @@ discard block |
||
94 | 94 | // true or false ? is this page being used by EE ? |
95 | 95 | $this->setEspressoPage(); |
96 | 96 | remove_action('parse_request', [$this, 'parseRequest'], 2); |
97 | - $this->initialized = true; |
|
97 | + $this->initialized = true; |
|
98 | 98 | } |
99 | 99 | |
100 | 100 | |
@@ -110,7 +110,7 @@ discard block |
||
110 | 110 | if ($post_id) { |
111 | 111 | return get_permalink($post_id); |
112 | 112 | } |
113 | - if (! $WP instanceof WP) { |
|
113 | + if ( ! $WP instanceof WP) { |
|
114 | 114 | global $WP; |
115 | 115 | } |
116 | 116 | if ($WP instanceof WP && $WP->request) { |
@@ -127,7 +127,7 @@ discard block |
||
127 | 127 | { |
128 | 128 | return array_filter( |
129 | 129 | $this->post_type, |
130 | - function ($post_type) { |
|
130 | + function($post_type) { |
|
131 | 131 | return strpos($post_type, 'espresso_') === 0; |
132 | 132 | } |
133 | 133 | ); |
@@ -148,16 +148,16 @@ discard block |
||
148 | 148 | $post_id = $WP->query_vars['p']; |
149 | 149 | } |
150 | 150 | // not a post? what about a page? |
151 | - if (! $post_id && isset($WP->query_vars['page_id'])) { |
|
151 | + if ( ! $post_id && isset($WP->query_vars['page_id'])) { |
|
152 | 152 | $post_id = $WP->query_vars['page_id']; |
153 | 153 | } |
154 | 154 | // ok... maybe pretty permalinks are off and the ID is set in the raw request... |
155 | 155 | // but hasn't been processed yet ie: this method is being called too early :\ |
156 | - if (! $post_id && $WP instanceof WP && $WP->request !== null && is_numeric(basename($WP->request))) { |
|
156 | + if ( ! $post_id && $WP instanceof WP && $WP->request !== null && is_numeric(basename($WP->request))) { |
|
157 | 157 | $post_id = basename($WP->request); |
158 | 158 | } |
159 | 159 | // none of the above? ok what about an explicit "post_id" URL parameter? |
160 | - if (! $post_id && $this->request->requestParamIsSet('post_id')) { |
|
160 | + if ( ! $post_id && $this->request->requestParamIsSet('post_id')) { |
|
161 | 161 | $post_id = $this->request->getRequestParam('post_id'); |
162 | 162 | } |
163 | 163 | return $post_id; |
@@ -179,14 +179,14 @@ discard block |
||
179 | 179 | $post_name = $WP->query_vars['name']; |
180 | 180 | } |
181 | 181 | // what about the page name? |
182 | - if (! $post_name && isset($WP->query_vars['pagename']) && ! empty($WP->query_vars['pagename'])) { |
|
182 | + if ( ! $post_name && isset($WP->query_vars['pagename']) && ! empty($WP->query_vars['pagename'])) { |
|
183 | 183 | $post_name = $WP->query_vars['pagename']; |
184 | 184 | } |
185 | 185 | // this stinks but let's run a query to try and get the post name from the URL |
186 | 186 | // (assuming pretty permalinks are on) |
187 | - if (! $post_name && $WP instanceof WP && $WP->request !== null && ! empty($WP->request)) { |
|
187 | + if ( ! $post_name && $WP instanceof WP && $WP->request !== null && ! empty($WP->request)) { |
|
188 | 188 | $possible_post_name = basename($WP->request); |
189 | - if (! is_numeric($possible_post_name)) { |
|
189 | + if ( ! is_numeric($possible_post_name)) { |
|
190 | 190 | $SQL = "SELECT ID from {$wpdb->posts}"; |
191 | 191 | $SQL .= " WHERE post_status NOT IN ('auto-draft', 'inherit', 'trash')"; |
192 | 192 | $SQL .= ' AND post_name=%s'; |
@@ -198,7 +198,7 @@ discard block |
||
198 | 198 | } |
199 | 199 | // ug... ok... nothing yet... but do we have a post ID? |
200 | 200 | // if so then... sigh... run a query to get the post name :\ |
201 | - if (! $post_name && $this->post_id) { |
|
201 | + if ( ! $post_name && $this->post_id) { |
|
202 | 202 | $SQL = "SELECT post_name from {$wpdb->posts}"; |
203 | 203 | $SQL .= " WHERE post_status NOT IN ('auto-draft', 'inherit', 'trash')"; |
204 | 204 | $SQL .= ' AND ID=%d'; |
@@ -208,7 +208,7 @@ discard block |
||
208 | 208 | } |
209 | 209 | } |
210 | 210 | // still nothing? ok what about an explicit 'post_name' URL parameter? |
211 | - if (! $post_name && $this->request->requestParamIsSet('post_name')) { |
|
211 | + if ( ! $post_name && $this->request->requestParamIsSet('post_name')) { |
|
212 | 212 | $post_name = $this->request->getRequestParam('post_name'); |
213 | 213 | } |
214 | 214 | return $post_name; |
@@ -301,7 +301,7 @@ discard block |
||
301 | 301 | $espresso_CPT_taxonomies = $this->cpt_strategy->get_CPT_taxonomies(); |
302 | 302 | if (is_array($espresso_CPT_taxonomies)) { |
303 | 303 | foreach ($espresso_CPT_taxonomies as $espresso_CPT_taxonomy => $details) { |
304 | - if (isset($WP->query_vars, $WP->query_vars[ $espresso_CPT_taxonomy ])) { |
|
304 | + if (isset($WP->query_vars, $WP->query_vars[$espresso_CPT_taxonomy])) { |
|
305 | 305 | return true; |
306 | 306 | } |
307 | 307 | } |
@@ -311,14 +311,14 @@ discard block |
||
311 | 311 | $post_type_CPT_endpoints = array_flip($espresso_CPT_endpoints); |
312 | 312 | foreach ($this->post_type as $post_type) { |
313 | 313 | // was a post name passed ? |
314 | - if (isset($post_type_CPT_endpoints[ $post_type ])) { |
|
314 | + if (isset($post_type_CPT_endpoints[$post_type])) { |
|
315 | 315 | // kk we know this is an espresso page, but is it a specific post ? |
316 | - if (! $this->post_name) { |
|
316 | + if ( ! $this->post_name) { |
|
317 | 317 | $espresso_post_type = $this->request->getRequestParam('post_type'); |
318 | 318 | // there's no specific post name set, so maybe it's one of our endpoints like www.domain.com/events |
319 | 319 | // this essentially sets the post_name to "events" (or whatever EE CPT) |
320 | - $post_name = isset($post_type_CPT_endpoints[ $espresso_post_type ]) |
|
321 | - ? $post_type_CPT_endpoints[ $espresso_post_type ] |
|
320 | + $post_name = isset($post_type_CPT_endpoints[$espresso_post_type]) |
|
321 | + ? $post_type_CPT_endpoints[$espresso_post_type] |
|
322 | 322 | : ''; |
323 | 323 | // if the post type matches one of ours then set the post name to the endpoint |
324 | 324 | if ($post_name) { |
@@ -39,808 +39,808 @@ |
||
39 | 39 | */ |
40 | 40 | class DisplayTicketSelector |
41 | 41 | { |
42 | - /** |
|
43 | - * @var RequestInterface |
|
44 | - */ |
|
45 | - protected $request; |
|
46 | - |
|
47 | - /** |
|
48 | - * @var EE_Ticket_Selector_Config |
|
49 | - */ |
|
50 | - protected $config; |
|
51 | - |
|
52 | - /** |
|
53 | - * event that ticket selector is being generated for |
|
54 | - * |
|
55 | - * @access protected |
|
56 | - * @var EE_Event $event |
|
57 | - */ |
|
58 | - protected $event; |
|
59 | - |
|
60 | - /** |
|
61 | - * Used to flag when the ticket selector is being called from an external iframe. |
|
62 | - * |
|
63 | - * @var bool $iframe |
|
64 | - */ |
|
65 | - protected $iframe = false; |
|
66 | - |
|
67 | - /** |
|
68 | - * max attendees that can register for event at one time |
|
69 | - * |
|
70 | - * @var int $max_attendees |
|
71 | - */ |
|
72 | - private $max_attendees = EE_INF; |
|
73 | - |
|
74 | - /** |
|
75 | - * @var string $date_format |
|
76 | - */ |
|
77 | - private $date_format; |
|
78 | - |
|
79 | - /** |
|
80 | - * @var string $time_format |
|
81 | - */ |
|
82 | - private $time_format; |
|
83 | - |
|
84 | - /** |
|
85 | - * @var boolean $display_full_ui |
|
86 | - */ |
|
87 | - private $display_full_ui; |
|
88 | - |
|
89 | - |
|
90 | - /** |
|
91 | - * DisplayTicketSelector constructor. |
|
92 | - * |
|
93 | - * @param RequestInterface $request |
|
94 | - * @param EE_Ticket_Selector_Config $config |
|
95 | - * @param bool $iframe |
|
96 | - */ |
|
97 | - public function __construct(RequestInterface $request, EE_Ticket_Selector_Config $config, $iframe = false) |
|
98 | - { |
|
99 | - $this->request = $request; |
|
100 | - $this->config = $config; |
|
101 | - $this->iframe = $iframe; |
|
102 | - $this->date_format = apply_filters( |
|
103 | - 'FHEE__EED_Ticket_Selector__display_ticket_selector__date_format', |
|
104 | - get_option('date_format') |
|
105 | - ); |
|
106 | - $this->time_format = apply_filters( |
|
107 | - 'FHEE__EED_Ticket_Selector__display_ticket_selector__time_format', |
|
108 | - get_option('time_format') |
|
109 | - ); |
|
110 | - } |
|
111 | - |
|
112 | - |
|
113 | - /** |
|
114 | - * @return bool |
|
115 | - */ |
|
116 | - public function isIframe() |
|
117 | - { |
|
118 | - return $this->iframe; |
|
119 | - } |
|
120 | - |
|
121 | - |
|
122 | - /** |
|
123 | - * @param boolean $iframe |
|
124 | - */ |
|
125 | - public function setIframe($iframe = true) |
|
126 | - { |
|
127 | - $this->iframe = filter_var($iframe, FILTER_VALIDATE_BOOLEAN); |
|
128 | - } |
|
129 | - |
|
130 | - |
|
131 | - /** |
|
132 | - * finds and sets the \EE_Event object for use throughout class |
|
133 | - * |
|
134 | - * @param mixed $event |
|
135 | - * @return bool |
|
136 | - * @throws EE_Error |
|
137 | - * @throws InvalidDataTypeException |
|
138 | - * @throws InvalidInterfaceException |
|
139 | - * @throws InvalidArgumentException |
|
140 | - */ |
|
141 | - protected function setEvent($event = null) |
|
142 | - { |
|
143 | - if ($event === null) { |
|
144 | - global $post; |
|
145 | - $event = $post; |
|
146 | - } |
|
147 | - if ($event instanceof EE_Event) { |
|
148 | - $this->event = $event; |
|
149 | - } elseif ($event instanceof WP_Post) { |
|
150 | - if (isset($event->EE_Event) && $event->EE_Event instanceof EE_Event) { |
|
151 | - $this->event = $event->EE_Event; |
|
152 | - } elseif ($event->post_type === 'espresso_events') { |
|
153 | - $event->EE_Event = EEM_Event::instance()->instantiate_class_from_post_object($event); |
|
154 | - $this->event = $event->EE_Event; |
|
155 | - } |
|
156 | - } else { |
|
157 | - $user_msg = __('No Event object or an invalid Event object was supplied.', 'event_espresso'); |
|
158 | - $dev_msg = $user_msg . __( |
|
159 | - 'In order to generate a ticket selector, please ensure you are passing either an EE_Event object or a WP_Post object of the post type "espresso_event" to the EE_Ticket_Selector class constructor.', |
|
160 | - 'event_espresso' |
|
161 | - ); |
|
162 | - EE_Error::add_error($user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__); |
|
163 | - return false; |
|
164 | - } |
|
165 | - return true; |
|
166 | - } |
|
167 | - |
|
168 | - |
|
169 | - /** |
|
170 | - * @return int |
|
171 | - */ |
|
172 | - public function getMaxAttendees() |
|
173 | - { |
|
174 | - return $this->max_attendees; |
|
175 | - } |
|
176 | - |
|
177 | - |
|
178 | - /** |
|
179 | - * @param int $max_attendees |
|
180 | - */ |
|
181 | - public function setMaxAttendees($max_attendees) |
|
182 | - { |
|
183 | - $this->max_attendees = absint( |
|
184 | - apply_filters( |
|
185 | - 'FHEE__EE_Ticket_Selector__display_ticket_selector__max_tickets', |
|
186 | - $max_attendees |
|
187 | - ) |
|
188 | - ); |
|
189 | - } |
|
190 | - |
|
191 | - |
|
192 | - /** |
|
193 | - * Returns whether or not the full ticket selector should be shown or not. |
|
194 | - * Currently, it displays on the frontend (including ajax requests) but not the backend |
|
195 | - * |
|
196 | - * @return bool |
|
197 | - */ |
|
198 | - private function display_full_ui() |
|
199 | - { |
|
200 | - if ($this->display_full_ui === null) { |
|
201 | - $this->display_full_ui = ! is_admin() || (defined('DOING_AJAX') && DOING_AJAX); |
|
202 | - } |
|
203 | - return $this->display_full_ui; |
|
204 | - } |
|
205 | - |
|
206 | - |
|
207 | - /** |
|
208 | - * creates buttons for selecting number of attendees for an event |
|
209 | - * |
|
210 | - * @param WP_Post|int $event |
|
211 | - * @param bool $view_details |
|
212 | - * @return string |
|
213 | - * @throws EE_Error |
|
214 | - * @throws InvalidArgumentException |
|
215 | - * @throws InvalidDataTypeException |
|
216 | - * @throws InvalidInterfaceException |
|
217 | - * @throws ReflectionException |
|
218 | - * @throws Exception |
|
219 | - */ |
|
220 | - public function display($event = null, $view_details = false) |
|
221 | - { |
|
222 | - // reset filter for displaying submit button |
|
223 | - remove_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true'); |
|
224 | - // poke and prod incoming event till it tells us what it is |
|
225 | - if (! $this->setEvent($event)) { |
|
226 | - return $this->handleMissingEvent(); |
|
227 | - } |
|
228 | - // is the event expired ? |
|
229 | - $template_args['event_is_expired'] = ! is_admin() && $this->event->is_expired(); |
|
230 | - if ($template_args['event_is_expired']) { |
|
231 | - return is_single() |
|
232 | - ? $this->expiredEventMessage() |
|
233 | - : $this->expiredEventMessage() |
|
234 | - . $this->displayViewDetailsButton(); |
|
235 | - } |
|
236 | - // begin gathering template arguments by getting event status |
|
237 | - $template_args = ['event_status' => $this->event->get_active_status()]; |
|
238 | - if ($this->activeEventAndShowTicketSelector( |
|
239 | - $event, |
|
240 | - $template_args['event_status'], |
|
241 | - $view_details |
|
242 | - )) { |
|
243 | - return ! is_single() ? $this->displayViewDetailsButton() : ''; |
|
244 | - } |
|
245 | - // filter the maximum qty that can appear in the Ticket Selector qty dropdowns |
|
246 | - $this->setMaxAttendees($this->event->additional_limit()); |
|
247 | - if ($this->getMaxAttendees() < 1) { |
|
248 | - return $this->ticketSalesClosedMessage(); |
|
249 | - } |
|
250 | - // get all tickets for this event ordered by the datetime |
|
251 | - $tickets = $this->getTickets(); |
|
252 | - if (count($tickets) < 1) { |
|
253 | - return $this->noTicketAvailableMessage(); |
|
254 | - } |
|
255 | - // redirecting to another site for registration ?? |
|
256 | - $external_url = (string) $this->event->external_url() |
|
257 | - && $this->event->external_url() !== get_the_permalink() |
|
258 | - ? $this->event->external_url() |
|
259 | - : ''; |
|
260 | - // if redirecting to another site for registration, then we don't load the TS |
|
261 | - $ticket_selector = $external_url |
|
262 | - ? $this->externalEventRegistration() |
|
263 | - : $this->loadTicketSelector($tickets, $template_args); |
|
264 | - // now set up the form (but not for the admin) |
|
265 | - $ticket_selector = $this->display_full_ui() |
|
266 | - ? $this->formOpen($this->event->ID(), $external_url) . $ticket_selector |
|
267 | - : $ticket_selector; |
|
268 | - // submit button and form close tag |
|
269 | - $ticket_selector .= $this->display_full_ui() ? $this->displaySubmitButton($external_url) : ''; |
|
270 | - return $ticket_selector; |
|
271 | - } |
|
272 | - |
|
273 | - |
|
274 | - /** |
|
275 | - * displayTicketSelector |
|
276 | - * examines the event properties and determines whether a Ticket Selector should be displayed |
|
277 | - * |
|
278 | - * @param WP_Post|int $event |
|
279 | - * @param string $_event_active_status |
|
280 | - * @param bool $view_details |
|
281 | - * @return bool |
|
282 | - * @throws EE_Error |
|
283 | - * @throws ReflectionException |
|
284 | - */ |
|
285 | - protected function activeEventAndShowTicketSelector($event, $_event_active_status, $view_details) |
|
286 | - { |
|
287 | - $event_post = $this->event instanceof EE_Event ? $this->event->ID() : $event; |
|
288 | - return $this->display_full_ui() |
|
289 | - && ( |
|
290 | - ! $this->event->display_ticket_selector() |
|
291 | - || $view_details |
|
292 | - || post_password_required($event_post) |
|
293 | - || ( |
|
294 | - $_event_active_status !== EE_Datetime::active |
|
295 | - && $_event_active_status !== EE_Datetime::upcoming |
|
296 | - && $_event_active_status !== EE_Datetime::sold_out |
|
297 | - && ! ( |
|
298 | - $_event_active_status === EE_Datetime::inactive |
|
299 | - && is_user_logged_in() |
|
300 | - ) |
|
301 | - ) |
|
302 | - ); |
|
303 | - } |
|
304 | - |
|
305 | - |
|
306 | - /** |
|
307 | - * noTicketAvailableMessage |
|
308 | - * notice displayed if event is expired |
|
309 | - * |
|
310 | - * @return string |
|
311 | - */ |
|
312 | - protected function expiredEventMessage() |
|
313 | - { |
|
314 | - return '<div class="ee-event-expired-notice"><span class="important-notice">' . esc_html__( |
|
315 | - 'We\'re sorry, but all tickets sales have ended because the event is expired.', |
|
316 | - 'event_espresso' |
|
317 | - ) . '</span></div><!-- .ee-event-expired-notice -->'; |
|
318 | - } |
|
319 | - |
|
320 | - |
|
321 | - /** |
|
322 | - * noTicketAvailableMessage |
|
323 | - * notice displayed if event has no more tickets available |
|
324 | - * |
|
325 | - * @return string |
|
326 | - * @throws EE_Error |
|
327 | - * @throws ReflectionException |
|
328 | - */ |
|
329 | - protected function noTicketAvailableMessage() |
|
330 | - { |
|
331 | - $no_ticket_available_msg = esc_html__('We\'re sorry, but all ticket sales have ended.', 'event_espresso'); |
|
332 | - if (current_user_can('edit_post', $this->event->ID())) { |
|
333 | - $no_ticket_available_msg .= sprintf( |
|
334 | - esc_html__( |
|
335 | - '%1$sNote to Event Admin:%2$sNo tickets were found for this event. This effectively turns off ticket sales. Please ensure that at least one ticket is available for if you want people to be able to register.%3$s(click to edit this event)%4$s', |
|
336 | - 'event_espresso' |
|
337 | - ), |
|
338 | - '<div class="ee-attention" style="text-align: left;"><b>', |
|
339 | - '</b><br />', |
|
340 | - '<span class="edit-link"><a class="post-edit-link" href="' |
|
341 | - . get_edit_post_link($this->event->ID()) |
|
342 | - . '">', |
|
343 | - '</a></span></div><!-- .ee-attention noTicketAvailableMessage -->' |
|
344 | - ); |
|
345 | - } |
|
346 | - return ' |
|
42 | + /** |
|
43 | + * @var RequestInterface |
|
44 | + */ |
|
45 | + protected $request; |
|
46 | + |
|
47 | + /** |
|
48 | + * @var EE_Ticket_Selector_Config |
|
49 | + */ |
|
50 | + protected $config; |
|
51 | + |
|
52 | + /** |
|
53 | + * event that ticket selector is being generated for |
|
54 | + * |
|
55 | + * @access protected |
|
56 | + * @var EE_Event $event |
|
57 | + */ |
|
58 | + protected $event; |
|
59 | + |
|
60 | + /** |
|
61 | + * Used to flag when the ticket selector is being called from an external iframe. |
|
62 | + * |
|
63 | + * @var bool $iframe |
|
64 | + */ |
|
65 | + protected $iframe = false; |
|
66 | + |
|
67 | + /** |
|
68 | + * max attendees that can register for event at one time |
|
69 | + * |
|
70 | + * @var int $max_attendees |
|
71 | + */ |
|
72 | + private $max_attendees = EE_INF; |
|
73 | + |
|
74 | + /** |
|
75 | + * @var string $date_format |
|
76 | + */ |
|
77 | + private $date_format; |
|
78 | + |
|
79 | + /** |
|
80 | + * @var string $time_format |
|
81 | + */ |
|
82 | + private $time_format; |
|
83 | + |
|
84 | + /** |
|
85 | + * @var boolean $display_full_ui |
|
86 | + */ |
|
87 | + private $display_full_ui; |
|
88 | + |
|
89 | + |
|
90 | + /** |
|
91 | + * DisplayTicketSelector constructor. |
|
92 | + * |
|
93 | + * @param RequestInterface $request |
|
94 | + * @param EE_Ticket_Selector_Config $config |
|
95 | + * @param bool $iframe |
|
96 | + */ |
|
97 | + public function __construct(RequestInterface $request, EE_Ticket_Selector_Config $config, $iframe = false) |
|
98 | + { |
|
99 | + $this->request = $request; |
|
100 | + $this->config = $config; |
|
101 | + $this->iframe = $iframe; |
|
102 | + $this->date_format = apply_filters( |
|
103 | + 'FHEE__EED_Ticket_Selector__display_ticket_selector__date_format', |
|
104 | + get_option('date_format') |
|
105 | + ); |
|
106 | + $this->time_format = apply_filters( |
|
107 | + 'FHEE__EED_Ticket_Selector__display_ticket_selector__time_format', |
|
108 | + get_option('time_format') |
|
109 | + ); |
|
110 | + } |
|
111 | + |
|
112 | + |
|
113 | + /** |
|
114 | + * @return bool |
|
115 | + */ |
|
116 | + public function isIframe() |
|
117 | + { |
|
118 | + return $this->iframe; |
|
119 | + } |
|
120 | + |
|
121 | + |
|
122 | + /** |
|
123 | + * @param boolean $iframe |
|
124 | + */ |
|
125 | + public function setIframe($iframe = true) |
|
126 | + { |
|
127 | + $this->iframe = filter_var($iframe, FILTER_VALIDATE_BOOLEAN); |
|
128 | + } |
|
129 | + |
|
130 | + |
|
131 | + /** |
|
132 | + * finds and sets the \EE_Event object for use throughout class |
|
133 | + * |
|
134 | + * @param mixed $event |
|
135 | + * @return bool |
|
136 | + * @throws EE_Error |
|
137 | + * @throws InvalidDataTypeException |
|
138 | + * @throws InvalidInterfaceException |
|
139 | + * @throws InvalidArgumentException |
|
140 | + */ |
|
141 | + protected function setEvent($event = null) |
|
142 | + { |
|
143 | + if ($event === null) { |
|
144 | + global $post; |
|
145 | + $event = $post; |
|
146 | + } |
|
147 | + if ($event instanceof EE_Event) { |
|
148 | + $this->event = $event; |
|
149 | + } elseif ($event instanceof WP_Post) { |
|
150 | + if (isset($event->EE_Event) && $event->EE_Event instanceof EE_Event) { |
|
151 | + $this->event = $event->EE_Event; |
|
152 | + } elseif ($event->post_type === 'espresso_events') { |
|
153 | + $event->EE_Event = EEM_Event::instance()->instantiate_class_from_post_object($event); |
|
154 | + $this->event = $event->EE_Event; |
|
155 | + } |
|
156 | + } else { |
|
157 | + $user_msg = __('No Event object or an invalid Event object was supplied.', 'event_espresso'); |
|
158 | + $dev_msg = $user_msg . __( |
|
159 | + 'In order to generate a ticket selector, please ensure you are passing either an EE_Event object or a WP_Post object of the post type "espresso_event" to the EE_Ticket_Selector class constructor.', |
|
160 | + 'event_espresso' |
|
161 | + ); |
|
162 | + EE_Error::add_error($user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__); |
|
163 | + return false; |
|
164 | + } |
|
165 | + return true; |
|
166 | + } |
|
167 | + |
|
168 | + |
|
169 | + /** |
|
170 | + * @return int |
|
171 | + */ |
|
172 | + public function getMaxAttendees() |
|
173 | + { |
|
174 | + return $this->max_attendees; |
|
175 | + } |
|
176 | + |
|
177 | + |
|
178 | + /** |
|
179 | + * @param int $max_attendees |
|
180 | + */ |
|
181 | + public function setMaxAttendees($max_attendees) |
|
182 | + { |
|
183 | + $this->max_attendees = absint( |
|
184 | + apply_filters( |
|
185 | + 'FHEE__EE_Ticket_Selector__display_ticket_selector__max_tickets', |
|
186 | + $max_attendees |
|
187 | + ) |
|
188 | + ); |
|
189 | + } |
|
190 | + |
|
191 | + |
|
192 | + /** |
|
193 | + * Returns whether or not the full ticket selector should be shown or not. |
|
194 | + * Currently, it displays on the frontend (including ajax requests) but not the backend |
|
195 | + * |
|
196 | + * @return bool |
|
197 | + */ |
|
198 | + private function display_full_ui() |
|
199 | + { |
|
200 | + if ($this->display_full_ui === null) { |
|
201 | + $this->display_full_ui = ! is_admin() || (defined('DOING_AJAX') && DOING_AJAX); |
|
202 | + } |
|
203 | + return $this->display_full_ui; |
|
204 | + } |
|
205 | + |
|
206 | + |
|
207 | + /** |
|
208 | + * creates buttons for selecting number of attendees for an event |
|
209 | + * |
|
210 | + * @param WP_Post|int $event |
|
211 | + * @param bool $view_details |
|
212 | + * @return string |
|
213 | + * @throws EE_Error |
|
214 | + * @throws InvalidArgumentException |
|
215 | + * @throws InvalidDataTypeException |
|
216 | + * @throws InvalidInterfaceException |
|
217 | + * @throws ReflectionException |
|
218 | + * @throws Exception |
|
219 | + */ |
|
220 | + public function display($event = null, $view_details = false) |
|
221 | + { |
|
222 | + // reset filter for displaying submit button |
|
223 | + remove_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true'); |
|
224 | + // poke and prod incoming event till it tells us what it is |
|
225 | + if (! $this->setEvent($event)) { |
|
226 | + return $this->handleMissingEvent(); |
|
227 | + } |
|
228 | + // is the event expired ? |
|
229 | + $template_args['event_is_expired'] = ! is_admin() && $this->event->is_expired(); |
|
230 | + if ($template_args['event_is_expired']) { |
|
231 | + return is_single() |
|
232 | + ? $this->expiredEventMessage() |
|
233 | + : $this->expiredEventMessage() |
|
234 | + . $this->displayViewDetailsButton(); |
|
235 | + } |
|
236 | + // begin gathering template arguments by getting event status |
|
237 | + $template_args = ['event_status' => $this->event->get_active_status()]; |
|
238 | + if ($this->activeEventAndShowTicketSelector( |
|
239 | + $event, |
|
240 | + $template_args['event_status'], |
|
241 | + $view_details |
|
242 | + )) { |
|
243 | + return ! is_single() ? $this->displayViewDetailsButton() : ''; |
|
244 | + } |
|
245 | + // filter the maximum qty that can appear in the Ticket Selector qty dropdowns |
|
246 | + $this->setMaxAttendees($this->event->additional_limit()); |
|
247 | + if ($this->getMaxAttendees() < 1) { |
|
248 | + return $this->ticketSalesClosedMessage(); |
|
249 | + } |
|
250 | + // get all tickets for this event ordered by the datetime |
|
251 | + $tickets = $this->getTickets(); |
|
252 | + if (count($tickets) < 1) { |
|
253 | + return $this->noTicketAvailableMessage(); |
|
254 | + } |
|
255 | + // redirecting to another site for registration ?? |
|
256 | + $external_url = (string) $this->event->external_url() |
|
257 | + && $this->event->external_url() !== get_the_permalink() |
|
258 | + ? $this->event->external_url() |
|
259 | + : ''; |
|
260 | + // if redirecting to another site for registration, then we don't load the TS |
|
261 | + $ticket_selector = $external_url |
|
262 | + ? $this->externalEventRegistration() |
|
263 | + : $this->loadTicketSelector($tickets, $template_args); |
|
264 | + // now set up the form (but not for the admin) |
|
265 | + $ticket_selector = $this->display_full_ui() |
|
266 | + ? $this->formOpen($this->event->ID(), $external_url) . $ticket_selector |
|
267 | + : $ticket_selector; |
|
268 | + // submit button and form close tag |
|
269 | + $ticket_selector .= $this->display_full_ui() ? $this->displaySubmitButton($external_url) : ''; |
|
270 | + return $ticket_selector; |
|
271 | + } |
|
272 | + |
|
273 | + |
|
274 | + /** |
|
275 | + * displayTicketSelector |
|
276 | + * examines the event properties and determines whether a Ticket Selector should be displayed |
|
277 | + * |
|
278 | + * @param WP_Post|int $event |
|
279 | + * @param string $_event_active_status |
|
280 | + * @param bool $view_details |
|
281 | + * @return bool |
|
282 | + * @throws EE_Error |
|
283 | + * @throws ReflectionException |
|
284 | + */ |
|
285 | + protected function activeEventAndShowTicketSelector($event, $_event_active_status, $view_details) |
|
286 | + { |
|
287 | + $event_post = $this->event instanceof EE_Event ? $this->event->ID() : $event; |
|
288 | + return $this->display_full_ui() |
|
289 | + && ( |
|
290 | + ! $this->event->display_ticket_selector() |
|
291 | + || $view_details |
|
292 | + || post_password_required($event_post) |
|
293 | + || ( |
|
294 | + $_event_active_status !== EE_Datetime::active |
|
295 | + && $_event_active_status !== EE_Datetime::upcoming |
|
296 | + && $_event_active_status !== EE_Datetime::sold_out |
|
297 | + && ! ( |
|
298 | + $_event_active_status === EE_Datetime::inactive |
|
299 | + && is_user_logged_in() |
|
300 | + ) |
|
301 | + ) |
|
302 | + ); |
|
303 | + } |
|
304 | + |
|
305 | + |
|
306 | + /** |
|
307 | + * noTicketAvailableMessage |
|
308 | + * notice displayed if event is expired |
|
309 | + * |
|
310 | + * @return string |
|
311 | + */ |
|
312 | + protected function expiredEventMessage() |
|
313 | + { |
|
314 | + return '<div class="ee-event-expired-notice"><span class="important-notice">' . esc_html__( |
|
315 | + 'We\'re sorry, but all tickets sales have ended because the event is expired.', |
|
316 | + 'event_espresso' |
|
317 | + ) . '</span></div><!-- .ee-event-expired-notice -->'; |
|
318 | + } |
|
319 | + |
|
320 | + |
|
321 | + /** |
|
322 | + * noTicketAvailableMessage |
|
323 | + * notice displayed if event has no more tickets available |
|
324 | + * |
|
325 | + * @return string |
|
326 | + * @throws EE_Error |
|
327 | + * @throws ReflectionException |
|
328 | + */ |
|
329 | + protected function noTicketAvailableMessage() |
|
330 | + { |
|
331 | + $no_ticket_available_msg = esc_html__('We\'re sorry, but all ticket sales have ended.', 'event_espresso'); |
|
332 | + if (current_user_can('edit_post', $this->event->ID())) { |
|
333 | + $no_ticket_available_msg .= sprintf( |
|
334 | + esc_html__( |
|
335 | + '%1$sNote to Event Admin:%2$sNo tickets were found for this event. This effectively turns off ticket sales. Please ensure that at least one ticket is available for if you want people to be able to register.%3$s(click to edit this event)%4$s', |
|
336 | + 'event_espresso' |
|
337 | + ), |
|
338 | + '<div class="ee-attention" style="text-align: left;"><b>', |
|
339 | + '</b><br />', |
|
340 | + '<span class="edit-link"><a class="post-edit-link" href="' |
|
341 | + . get_edit_post_link($this->event->ID()) |
|
342 | + . '">', |
|
343 | + '</a></span></div><!-- .ee-attention noTicketAvailableMessage -->' |
|
344 | + ); |
|
345 | + } |
|
346 | + return ' |
|
347 | 347 | <div class="ee-event-expired-notice"> |
348 | 348 | <span class="important-notice">' . $no_ticket_available_msg . '</span> |
349 | 349 | </div><!-- .ee-event-expired-notice -->'; |
350 | - } |
|
351 | - |
|
352 | - |
|
353 | - /** |
|
354 | - * ticketSalesClosed |
|
355 | - * notice displayed if event ticket sales are turned off |
|
356 | - * |
|
357 | - * @return string |
|
358 | - * @throws EE_Error |
|
359 | - * @throws ReflectionException |
|
360 | - */ |
|
361 | - protected function ticketSalesClosedMessage() |
|
362 | - { |
|
363 | - $sales_closed_msg = esc_html__( |
|
364 | - 'We\'re sorry, but ticket sales have been closed at this time. Please check back again later.', |
|
365 | - 'event_espresso' |
|
366 | - ); |
|
367 | - if (current_user_can('edit_post', $this->event->ID())) { |
|
368 | - $sales_closed_msg .= sprintf( |
|
369 | - esc_html__( |
|
370 | - '%sNote to Event Admin:%sThe "Maximum number of tickets allowed per order for this event" in the Event Registration Options has been set to "0". This effectively turns off ticket sales. %s(click to edit this event)%s', |
|
371 | - 'event_espresso' |
|
372 | - ), |
|
373 | - '<div class="ee-attention" style="text-align: left;"><b>', |
|
374 | - '</b><br />', |
|
375 | - '<span class="edit-link"><a class="post-edit-link" href="' |
|
376 | - . get_edit_post_link($this->event->ID()) |
|
377 | - . '">', |
|
378 | - '</a></span></div><!-- .ee-attention ticketSalesClosedMessage -->' |
|
379 | - ); |
|
380 | - } |
|
381 | - return '<p><span class="important-notice">' . $sales_closed_msg . '</span></p>'; |
|
382 | - } |
|
383 | - |
|
384 | - |
|
385 | - /** |
|
386 | - * getTickets |
|
387 | - * |
|
388 | - * @return EE_Base_Class[]|EE_Ticket[] |
|
389 | - * @throws EE_Error |
|
390 | - * @throws InvalidDataTypeException |
|
391 | - * @throws InvalidInterfaceException |
|
392 | - * @throws InvalidArgumentException |
|
393 | - * @throws ReflectionException |
|
394 | - */ |
|
395 | - protected function getTickets() |
|
396 | - { |
|
397 | - $show_expired_tickets = is_admin() || $this->config->show_expired_tickets; |
|
398 | - |
|
399 | - $ticket_query_args = [ |
|
400 | - ['Datetime.EVT_ID' => $this->event->ID()], |
|
401 | - 'order_by' => [ |
|
402 | - 'TKT_order' => 'ASC', |
|
403 | - 'TKT_required' => 'DESC', |
|
404 | - 'TKT_start_date' => 'ASC', |
|
405 | - 'TKT_end_date' => 'ASC', |
|
406 | - 'Datetime.DTT_EVT_start' => 'DESC', |
|
407 | - ], |
|
408 | - ]; |
|
409 | - if (! $show_expired_tickets) { |
|
410 | - // use the correct applicable time query depending on what version of core is being run. |
|
411 | - $current_time = method_exists('EEM_Datetime', 'current_time_for_query') |
|
412 | - ? time() |
|
413 | - : current_time('timestamp'); |
|
414 | - $ticket_query_args[0]['TKT_end_date'] = ['>', $current_time]; |
|
415 | - } |
|
416 | - return EEM_Ticket::instance()->get_all($ticket_query_args); |
|
417 | - } |
|
418 | - |
|
419 | - |
|
420 | - /** |
|
421 | - * loadTicketSelector |
|
422 | - * begins to assemble template arguments |
|
423 | - * and decides whether to load a "simple" ticket selector, or the standard |
|
424 | - * |
|
425 | - * @param EE_Ticket[] $tickets |
|
426 | - * @param array $template_args |
|
427 | - * @return TicketSelectorSimple|TicketSelectorStandard |
|
428 | - * @throws EE_Error |
|
429 | - * @throws ReflectionException |
|
430 | - */ |
|
431 | - protected function loadTicketSelector(array $tickets, array $template_args) |
|
432 | - { |
|
433 | - $template_args['event'] = $this->event; |
|
434 | - $template_args['EVT_ID'] = $this->event->ID(); |
|
435 | - $template_args['event_is_expired'] = $this->event->is_expired(); |
|
436 | - $template_args['max_atndz'] = $this->getMaxAttendees(); |
|
437 | - $template_args['date_format'] = $this->date_format; |
|
438 | - $template_args['time_format'] = $this->time_format; |
|
439 | - /** |
|
440 | - * Filters the anchor ID used when redirecting to the Ticket Selector if no quantity selected |
|
441 | - * |
|
442 | - * @param string '#tkt-slctr-tbl-' . $EVT_ID The html ID to anchor to |
|
443 | - * @param int $EVT_ID The Event ID |
|
444 | - * @since 4.9.13 |
|
445 | - */ |
|
446 | - $template_args['anchor_id'] = apply_filters( |
|
447 | - 'FHEE__EE_Ticket_Selector__redirect_anchor_id', |
|
448 | - '#tkt-slctr-tbl-' . $this->event->ID(), |
|
449 | - $this->event->ID() |
|
450 | - ); |
|
451 | - $template_args['tickets'] = $tickets; |
|
452 | - $template_args['ticket_count'] = count($tickets); |
|
453 | - $ticket_selector = $this->simpleTicketSelector($tickets, $template_args); |
|
454 | - if ($ticket_selector instanceof TicketSelectorSimple) { |
|
455 | - return $ticket_selector; |
|
456 | - } |
|
457 | - return new TicketSelectorStandard( |
|
458 | - $this->config, |
|
459 | - $this->getTaxConfig(), |
|
460 | - $this->event, |
|
461 | - $tickets, |
|
462 | - $this->getMaxAttendees(), |
|
463 | - $template_args, |
|
464 | - $this->date_format, |
|
465 | - $this->time_format |
|
466 | - ); |
|
467 | - } |
|
468 | - |
|
469 | - |
|
470 | - /** |
|
471 | - * simpleTicketSelector |
|
472 | - * there's one ticket, and max attendees is set to one, |
|
473 | - * so if the event is free, then this is a "simple" ticket selector |
|
474 | - * a.k.a. "Dude Where's my Ticket Selector?" |
|
475 | - * |
|
476 | - * @param EE_Ticket[] $tickets |
|
477 | - * @param array $template_args |
|
478 | - * @return string |
|
479 | - * @throws EE_Error |
|
480 | - * @throws ReflectionException |
|
481 | - */ |
|
482 | - protected function simpleTicketSelector($tickets, array $template_args) |
|
483 | - { |
|
484 | - // if there is only ONE ticket with a max qty of ONE |
|
485 | - if (count($tickets) > 1 || $this->getMaxAttendees() !== 1) { |
|
486 | - return ''; |
|
487 | - } |
|
488 | - /** @var EE_Ticket $ticket */ |
|
489 | - $ticket = reset($tickets); |
|
490 | - // if the ticket is free... then not much need for the ticket selector |
|
491 | - if (apply_filters( |
|
492 | - 'FHEE__ticket_selector_chart_template__hide_ticket_selector', |
|
493 | - $ticket->is_free(), |
|
494 | - $this->event->ID() |
|
495 | - )) { |
|
496 | - return new TicketSelectorSimple( |
|
497 | - $this->event, |
|
498 | - $ticket, |
|
499 | - $this->getMaxAttendees(), |
|
500 | - $template_args |
|
501 | - ); |
|
502 | - } |
|
503 | - return ''; |
|
504 | - } |
|
505 | - |
|
506 | - |
|
507 | - /** |
|
508 | - * externalEventRegistration |
|
509 | - * |
|
510 | - * @return string |
|
511 | - */ |
|
512 | - public function externalEventRegistration() |
|
513 | - { |
|
514 | - // if not we still need to trigger the display of the submit button |
|
515 | - add_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true'); |
|
516 | - // display notice to admin that registration is external |
|
517 | - return $this->display_full_ui() |
|
518 | - ? esc_html__( |
|
519 | - 'Registration is at an external URL for this event.', |
|
520 | - 'event_espresso' |
|
521 | - ) |
|
522 | - : ''; |
|
523 | - } |
|
524 | - |
|
525 | - |
|
526 | - /** |
|
527 | - * formOpen |
|
528 | - * |
|
529 | - * @param int $ID |
|
530 | - * @param string $external_url |
|
531 | - * @return string |
|
532 | - */ |
|
533 | - public function formOpen($ID = 0, $external_url = '') |
|
534 | - { |
|
535 | - // if redirecting, we don't need any anything else |
|
536 | - if ($external_url) { |
|
537 | - $html = '<form method="GET" '; |
|
538 | - $html .= 'action="' . EEH_URL::refactor_url($external_url) . '" '; |
|
539 | - $html .= 'name="ticket-selector-form-' . $ID . '"'; |
|
540 | - // open link in new window ? |
|
541 | - $html .= apply_filters( |
|
542 | - 'FHEE__EventEspresso_modules_ticket_selector_DisplayTicketSelector__formOpen__external_url_target_blank', |
|
543 | - $this->isIframe(), |
|
544 | - $this |
|
545 | - ) |
|
546 | - ? ' target="_blank"' |
|
547 | - : ''; |
|
548 | - $html .= '>'; |
|
549 | - $query_args = EEH_URL::get_query_string($external_url); |
|
550 | - foreach ((array) $query_args as $query_arg => $value) { |
|
551 | - $html .= '<input type="hidden" name="' . $query_arg . '" value="' . $value . '">'; |
|
552 | - } |
|
553 | - return $html; |
|
554 | - } |
|
555 | - // if there is no submit button, then don't start building a form |
|
556 | - // because the "View Details" button will build its own form |
|
557 | - if (! apply_filters('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', false)) { |
|
558 | - return ''; |
|
559 | - } |
|
560 | - $checkout_url = EEH_Event_View::event_link_url($ID); |
|
561 | - if (! $checkout_url) { |
|
562 | - EE_Error::add_error( |
|
563 | - esc_html__('The URL for the Event Details page could not be retrieved.', 'event_espresso'), |
|
564 | - __FILE__, |
|
565 | - __FUNCTION__, |
|
566 | - __LINE__ |
|
567 | - ); |
|
568 | - } |
|
569 | - // set no cache headers and constants |
|
570 | - EE_System::do_not_cache(); |
|
571 | - $html = '<form method="POST" '; |
|
572 | - $html .= 'action="' . $checkout_url . '" '; |
|
573 | - $html .= 'name="ticket-selector-form-' . $ID . '"'; |
|
574 | - $html .= $this->iframe ? ' target="_blank"' : ''; |
|
575 | - $html .= '>'; |
|
576 | - $html .= '<input type="hidden" name="ee" value="process_ticket_selections">'; |
|
577 | - return apply_filters('FHEE__EE_Ticket_Selector__ticket_selector_form_open__html', $html, $this->event); |
|
578 | - } |
|
579 | - |
|
580 | - |
|
581 | - /** |
|
582 | - * displaySubmitButton |
|
583 | - * |
|
584 | - * @param string $external_url |
|
585 | - * @return string |
|
586 | - * @throws EE_Error |
|
587 | - * @throws ReflectionException |
|
588 | - */ |
|
589 | - public function displaySubmitButton($external_url = '') |
|
590 | - { |
|
591 | - $html = ''; |
|
592 | - if ($this->display_full_ui()) { |
|
593 | - // standard TS displayed with submit button, ie: "Register Now" |
|
594 | - if (apply_filters('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', false)) { |
|
595 | - $html .= $this->displayRegisterNowButton(); |
|
596 | - $html .= empty($external_url) |
|
597 | - ? $this->ticketSelectorEndDiv() |
|
598 | - : $this->clearTicketSelector(); |
|
599 | - $html .= '<br/>' . $this->formClose(); |
|
600 | - } elseif ($this->getMaxAttendees() === 1) { |
|
601 | - // its a "Dude Where's my Ticket Selector?" (DWMTS) type event (ie: $_max_atndz === 1) |
|
602 | - if ($this->event->is_sold_out()) { |
|
603 | - // then instead of a View Details or Submit button, just display a "Sold Out" message |
|
604 | - $html .= apply_filters( |
|
605 | - 'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__sold_out_msg', |
|
606 | - sprintf( |
|
607 | - __( |
|
608 | - '%1$s"%2$s" is currently sold out.%4$sPlease check back again later, as spots may become available.%3$s', |
|
609 | - 'event_espresso' |
|
610 | - ), |
|
611 | - '<p class="no-ticket-selector-msg clear-float">', |
|
612 | - $this->event->name(), |
|
613 | - '</p>', |
|
614 | - '<br />' |
|
615 | - ), |
|
616 | - $this->event |
|
617 | - ); |
|
618 | - if (apply_filters( |
|
619 | - 'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__no_tickets_but_display_register_now_button', |
|
620 | - false, |
|
621 | - $this->event |
|
622 | - )) { |
|
623 | - $html .= $this->displayRegisterNowButton(); |
|
624 | - } |
|
625 | - // sold out DWMTS event, no TS, no submit or view details button, but has additional content |
|
626 | - $html .= $this->ticketSelectorEndDiv(); |
|
627 | - } elseif (apply_filters('FHEE__EE_Ticket_Selector__hide_ticket_selector', false) |
|
628 | - && ! is_single() |
|
629 | - ) { |
|
630 | - // this is a "Dude Where's my Ticket Selector?" (DWMTS) type event, |
|
631 | - // but no tickets are available, so display event's "View Details" button. |
|
632 | - // it is being viewed via somewhere other than a single post |
|
633 | - $html .= $this->displayViewDetailsButton(true); |
|
634 | - } else { |
|
635 | - $html .= $this->ticketSelectorEndDiv(); |
|
636 | - } |
|
637 | - } elseif (is_archive()) { |
|
638 | - // event list, no tickets available so display event's "View Details" button |
|
639 | - $html .= $this->ticketSelectorEndDiv(); |
|
640 | - $html .= $this->displayViewDetailsButton(); |
|
641 | - } else { |
|
642 | - if (apply_filters( |
|
643 | - 'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__no_tickets_but_display_register_now_button', |
|
644 | - false, |
|
645 | - $this->event |
|
646 | - )) { |
|
647 | - $html .= $this->displayRegisterNowButton(); |
|
648 | - } |
|
649 | - // no submit or view details button, and no additional content |
|
650 | - $html .= $this->ticketSelectorEndDiv(); |
|
651 | - } |
|
652 | - if (! $this->iframe && ! is_archive()) { |
|
653 | - $html .= EEH_Template::powered_by_event_espresso('', '', ['utm_content' => 'ticket_selector']); |
|
654 | - } |
|
655 | - } |
|
656 | - return apply_filters( |
|
657 | - 'FHEE__EventEspresso_modules_ticket_selector_DisplayTicketSelector__displaySubmitButton__html', |
|
658 | - $html, |
|
659 | - $this->event, |
|
660 | - $this |
|
661 | - ); |
|
662 | - } |
|
663 | - |
|
664 | - |
|
665 | - /** |
|
666 | - * @return string |
|
667 | - * @throws EE_Error |
|
668 | - * @throws ReflectionException |
|
669 | - */ |
|
670 | - public function displayRegisterNowButton() |
|
671 | - { |
|
672 | - $btn_text = apply_filters( |
|
673 | - 'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__btn_text', |
|
674 | - __('Register Now', 'event_espresso'), |
|
675 | - $this->event |
|
676 | - ); |
|
677 | - $external_url = (string) $this->event->external_url() |
|
678 | - && $this->event->external_url() !== get_the_permalink() |
|
679 | - ? $this->event->external_url() |
|
680 | - : ''; |
|
681 | - $html = EEH_HTML::div( |
|
682 | - '', |
|
683 | - 'ticket-selector-submit-' . $this->event->ID() . '-btn-wrap', |
|
684 | - 'ticket-selector-submit-btn-wrap' |
|
685 | - ); |
|
686 | - $html .= '<input id="ticket-selector-submit-' . $this->event->ID() . '-btn"'; |
|
687 | - $html .= ' class="ticket-selector-submit-btn '; |
|
688 | - $html .= empty($external_url) ? 'ticket-selector-submit-ajax"' : '"'; |
|
689 | - $html .= ' type="submit" value="' . $btn_text . '" data-ee-disable-after-recaptcha="true" />'; |
|
690 | - $html .= EEH_HTML::divx() . '<!-- .ticket-selector-submit-btn-wrap -->'; |
|
691 | - $html .= apply_filters( |
|
692 | - 'FHEE__EE_Ticket_Selector__after_ticket_selector_submit', |
|
693 | - '', |
|
694 | - $this->event, |
|
695 | - $this->iframe |
|
696 | - ); |
|
697 | - return $html; |
|
698 | - } |
|
699 | - |
|
700 | - |
|
701 | - /** |
|
702 | - * displayViewDetailsButton |
|
703 | - * |
|
704 | - * @param bool $DWMTS indicates a "Dude Where's my Ticket Selector?" (DWMTS) type event |
|
705 | - * (ie: $_max_atndz === 1) where there are no available tickets, |
|
706 | - * either because they are sold out, expired, or not yet on sale. |
|
707 | - * In this case, we need to close the form BEFORE adding any closing divs |
|
708 | - * @return string |
|
709 | - * @throws EE_Error |
|
710 | - * @throws ReflectionException |
|
711 | - */ |
|
712 | - public function displayViewDetailsButton($DWMTS = false) |
|
713 | - { |
|
714 | - if (! $this->event->get_permalink()) { |
|
715 | - EE_Error::add_error( |
|
716 | - esc_html__('The URL for the Event Details page could not be retrieved.', 'event_espresso'), |
|
717 | - __FILE__, |
|
718 | - __FUNCTION__, |
|
719 | - __LINE__ |
|
720 | - ); |
|
721 | - } |
|
722 | - $view_details_btn = '<form method="GET" action="'; |
|
723 | - $view_details_btn .= apply_filters( |
|
724 | - 'FHEE__EE_Ticket_Selector__display_view_details_btn__btn_url', |
|
725 | - $this->event->get_permalink(), |
|
726 | - $this->event |
|
727 | - ); |
|
728 | - $view_details_btn .= '"'; |
|
729 | - // open link in new window ? |
|
730 | - $view_details_btn .= apply_filters( |
|
731 | - 'FHEE__EventEspresso_modules_ticket_selector_DisplayTicketSelector__displayViewDetailsButton__url_target_blank', |
|
732 | - $this->isIframe(), |
|
733 | - $this |
|
734 | - ) |
|
735 | - ? ' target="_blank"' |
|
736 | - : ''; |
|
737 | - $view_details_btn .= '>'; |
|
738 | - $btn_text = apply_filters( |
|
739 | - 'FHEE__EE_Ticket_Selector__display_view_details_btn__btn_text', |
|
740 | - esc_html__('View Details', 'event_espresso'), |
|
741 | - $this->event |
|
742 | - ); |
|
743 | - $view_details_btn .= '<input id="ticket-selector-submit-' |
|
744 | - . $this->event->ID() |
|
745 | - . '-btn" class="ticket-selector-submit-btn view-details-btn" type="submit" value="' |
|
746 | - . $btn_text |
|
747 | - . '" />'; |
|
748 | - $view_details_btn .= apply_filters('FHEE__EE_Ticket_Selector__after_view_details_btn', '', $this->event); |
|
749 | - if ($DWMTS) { |
|
750 | - $view_details_btn .= $this->formClose(); |
|
751 | - $view_details_btn .= $this->ticketSelectorEndDiv(); |
|
752 | - $view_details_btn .= '<br/>'; |
|
753 | - } else { |
|
754 | - $view_details_btn .= $this->clearTicketSelector(); |
|
755 | - $view_details_btn .= '<br/>'; |
|
756 | - $view_details_btn .= $this->formClose(); |
|
757 | - } |
|
758 | - return $view_details_btn; |
|
759 | - } |
|
760 | - |
|
761 | - |
|
762 | - /** |
|
763 | - * @return string |
|
764 | - */ |
|
765 | - public function ticketSelectorEndDiv() |
|
766 | - { |
|
767 | - return $this->clearTicketSelector() . '</div><!-- ticketSelectorEndDiv -->'; |
|
768 | - } |
|
769 | - |
|
770 | - |
|
771 | - /** |
|
772 | - * @return string |
|
773 | - */ |
|
774 | - public function clearTicketSelector() |
|
775 | - { |
|
776 | - // standard TS displayed, appears after a "Register Now" or "view Details" button |
|
777 | - return '<div class="clear"></div><!-- clearTicketSelector -->'; |
|
778 | - } |
|
779 | - |
|
780 | - |
|
781 | - /** |
|
782 | - * @access public |
|
783 | - * @return string |
|
784 | - */ |
|
785 | - public function formClose() |
|
786 | - { |
|
787 | - return '</form>'; |
|
788 | - } |
|
789 | - |
|
790 | - |
|
791 | - /** |
|
792 | - * handleMissingEvent |
|
793 | - * Returns either false or an error to display when no valid event is passed. |
|
794 | - * |
|
795 | - * @return string |
|
796 | - * @throws ExceptionStackTraceDisplay |
|
797 | - * @throws InvalidInterfaceException |
|
798 | - * @throws Exception |
|
799 | - */ |
|
800 | - protected function handleMissingEvent() |
|
801 | - { |
|
802 | - // If this is not an iFrame request, simply return false. |
|
803 | - if (! $this->isIframe()) { |
|
804 | - return ''; |
|
805 | - } |
|
806 | - // This is an iFrame so return an error. |
|
807 | - // Display stack trace if WP_DEBUG is enabled. |
|
808 | - if (WP_DEBUG === true && current_user_can('edit_pages')) { |
|
809 | - $event_id = $this->request->getRequestParam('event', 0, 'int'); |
|
810 | - new ExceptionStackTraceDisplay( |
|
811 | - new InvalidArgumentException( |
|
812 | - sprintf( |
|
813 | - esc_html__( |
|
814 | - 'A valid Event ID is required to display the ticket selector.%3$sAn Event with an ID of "%1$s" could not be found.%3$sPlease verify that the embed code added to this post\'s content includes an "%2$s" argument and that its value corresponds to a valid Event ID.', |
|
815 | - 'event_espresso' |
|
816 | - ), |
|
817 | - $event_id, |
|
818 | - 'event', |
|
819 | - '<br />' |
|
820 | - ) |
|
821 | - ) |
|
822 | - ); |
|
823 | - return ''; |
|
824 | - } |
|
825 | - // If WP_DEBUG is not enabled, display a message stating the event could not be found. |
|
826 | - return EEH_HTML::p( |
|
827 | - esc_html__( |
|
828 | - 'A valid Event could not be found. Please contact the event administrator for assistance.', |
|
829 | - 'event_espresso' |
|
830 | - ) |
|
831 | - ); |
|
832 | - } |
|
833 | - |
|
834 | - |
|
835 | - /** |
|
836 | - * @return EE_Tax_Config |
|
837 | - * @since $VID:$ |
|
838 | - */ |
|
839 | - protected function getTaxConfig() |
|
840 | - { |
|
841 | - return isset(EE_Registry::instance()->CFG->tax_settings) |
|
842 | - && EE_Registry::instance()->CFG->tax_settings instanceof EE_Tax_Config |
|
843 | - ? EE_Registry::instance()->CFG->tax_settings |
|
844 | - : new EE_Tax_Config(); |
|
845 | - } |
|
350 | + } |
|
351 | + |
|
352 | + |
|
353 | + /** |
|
354 | + * ticketSalesClosed |
|
355 | + * notice displayed if event ticket sales are turned off |
|
356 | + * |
|
357 | + * @return string |
|
358 | + * @throws EE_Error |
|
359 | + * @throws ReflectionException |
|
360 | + */ |
|
361 | + protected function ticketSalesClosedMessage() |
|
362 | + { |
|
363 | + $sales_closed_msg = esc_html__( |
|
364 | + 'We\'re sorry, but ticket sales have been closed at this time. Please check back again later.', |
|
365 | + 'event_espresso' |
|
366 | + ); |
|
367 | + if (current_user_can('edit_post', $this->event->ID())) { |
|
368 | + $sales_closed_msg .= sprintf( |
|
369 | + esc_html__( |
|
370 | + '%sNote to Event Admin:%sThe "Maximum number of tickets allowed per order for this event" in the Event Registration Options has been set to "0". This effectively turns off ticket sales. %s(click to edit this event)%s', |
|
371 | + 'event_espresso' |
|
372 | + ), |
|
373 | + '<div class="ee-attention" style="text-align: left;"><b>', |
|
374 | + '</b><br />', |
|
375 | + '<span class="edit-link"><a class="post-edit-link" href="' |
|
376 | + . get_edit_post_link($this->event->ID()) |
|
377 | + . '">', |
|
378 | + '</a></span></div><!-- .ee-attention ticketSalesClosedMessage -->' |
|
379 | + ); |
|
380 | + } |
|
381 | + return '<p><span class="important-notice">' . $sales_closed_msg . '</span></p>'; |
|
382 | + } |
|
383 | + |
|
384 | + |
|
385 | + /** |
|
386 | + * getTickets |
|
387 | + * |
|
388 | + * @return EE_Base_Class[]|EE_Ticket[] |
|
389 | + * @throws EE_Error |
|
390 | + * @throws InvalidDataTypeException |
|
391 | + * @throws InvalidInterfaceException |
|
392 | + * @throws InvalidArgumentException |
|
393 | + * @throws ReflectionException |
|
394 | + */ |
|
395 | + protected function getTickets() |
|
396 | + { |
|
397 | + $show_expired_tickets = is_admin() || $this->config->show_expired_tickets; |
|
398 | + |
|
399 | + $ticket_query_args = [ |
|
400 | + ['Datetime.EVT_ID' => $this->event->ID()], |
|
401 | + 'order_by' => [ |
|
402 | + 'TKT_order' => 'ASC', |
|
403 | + 'TKT_required' => 'DESC', |
|
404 | + 'TKT_start_date' => 'ASC', |
|
405 | + 'TKT_end_date' => 'ASC', |
|
406 | + 'Datetime.DTT_EVT_start' => 'DESC', |
|
407 | + ], |
|
408 | + ]; |
|
409 | + if (! $show_expired_tickets) { |
|
410 | + // use the correct applicable time query depending on what version of core is being run. |
|
411 | + $current_time = method_exists('EEM_Datetime', 'current_time_for_query') |
|
412 | + ? time() |
|
413 | + : current_time('timestamp'); |
|
414 | + $ticket_query_args[0]['TKT_end_date'] = ['>', $current_time]; |
|
415 | + } |
|
416 | + return EEM_Ticket::instance()->get_all($ticket_query_args); |
|
417 | + } |
|
418 | + |
|
419 | + |
|
420 | + /** |
|
421 | + * loadTicketSelector |
|
422 | + * begins to assemble template arguments |
|
423 | + * and decides whether to load a "simple" ticket selector, or the standard |
|
424 | + * |
|
425 | + * @param EE_Ticket[] $tickets |
|
426 | + * @param array $template_args |
|
427 | + * @return TicketSelectorSimple|TicketSelectorStandard |
|
428 | + * @throws EE_Error |
|
429 | + * @throws ReflectionException |
|
430 | + */ |
|
431 | + protected function loadTicketSelector(array $tickets, array $template_args) |
|
432 | + { |
|
433 | + $template_args['event'] = $this->event; |
|
434 | + $template_args['EVT_ID'] = $this->event->ID(); |
|
435 | + $template_args['event_is_expired'] = $this->event->is_expired(); |
|
436 | + $template_args['max_atndz'] = $this->getMaxAttendees(); |
|
437 | + $template_args['date_format'] = $this->date_format; |
|
438 | + $template_args['time_format'] = $this->time_format; |
|
439 | + /** |
|
440 | + * Filters the anchor ID used when redirecting to the Ticket Selector if no quantity selected |
|
441 | + * |
|
442 | + * @param string '#tkt-slctr-tbl-' . $EVT_ID The html ID to anchor to |
|
443 | + * @param int $EVT_ID The Event ID |
|
444 | + * @since 4.9.13 |
|
445 | + */ |
|
446 | + $template_args['anchor_id'] = apply_filters( |
|
447 | + 'FHEE__EE_Ticket_Selector__redirect_anchor_id', |
|
448 | + '#tkt-slctr-tbl-' . $this->event->ID(), |
|
449 | + $this->event->ID() |
|
450 | + ); |
|
451 | + $template_args['tickets'] = $tickets; |
|
452 | + $template_args['ticket_count'] = count($tickets); |
|
453 | + $ticket_selector = $this->simpleTicketSelector($tickets, $template_args); |
|
454 | + if ($ticket_selector instanceof TicketSelectorSimple) { |
|
455 | + return $ticket_selector; |
|
456 | + } |
|
457 | + return new TicketSelectorStandard( |
|
458 | + $this->config, |
|
459 | + $this->getTaxConfig(), |
|
460 | + $this->event, |
|
461 | + $tickets, |
|
462 | + $this->getMaxAttendees(), |
|
463 | + $template_args, |
|
464 | + $this->date_format, |
|
465 | + $this->time_format |
|
466 | + ); |
|
467 | + } |
|
468 | + |
|
469 | + |
|
470 | + /** |
|
471 | + * simpleTicketSelector |
|
472 | + * there's one ticket, and max attendees is set to one, |
|
473 | + * so if the event is free, then this is a "simple" ticket selector |
|
474 | + * a.k.a. "Dude Where's my Ticket Selector?" |
|
475 | + * |
|
476 | + * @param EE_Ticket[] $tickets |
|
477 | + * @param array $template_args |
|
478 | + * @return string |
|
479 | + * @throws EE_Error |
|
480 | + * @throws ReflectionException |
|
481 | + */ |
|
482 | + protected function simpleTicketSelector($tickets, array $template_args) |
|
483 | + { |
|
484 | + // if there is only ONE ticket with a max qty of ONE |
|
485 | + if (count($tickets) > 1 || $this->getMaxAttendees() !== 1) { |
|
486 | + return ''; |
|
487 | + } |
|
488 | + /** @var EE_Ticket $ticket */ |
|
489 | + $ticket = reset($tickets); |
|
490 | + // if the ticket is free... then not much need for the ticket selector |
|
491 | + if (apply_filters( |
|
492 | + 'FHEE__ticket_selector_chart_template__hide_ticket_selector', |
|
493 | + $ticket->is_free(), |
|
494 | + $this->event->ID() |
|
495 | + )) { |
|
496 | + return new TicketSelectorSimple( |
|
497 | + $this->event, |
|
498 | + $ticket, |
|
499 | + $this->getMaxAttendees(), |
|
500 | + $template_args |
|
501 | + ); |
|
502 | + } |
|
503 | + return ''; |
|
504 | + } |
|
505 | + |
|
506 | + |
|
507 | + /** |
|
508 | + * externalEventRegistration |
|
509 | + * |
|
510 | + * @return string |
|
511 | + */ |
|
512 | + public function externalEventRegistration() |
|
513 | + { |
|
514 | + // if not we still need to trigger the display of the submit button |
|
515 | + add_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true'); |
|
516 | + // display notice to admin that registration is external |
|
517 | + return $this->display_full_ui() |
|
518 | + ? esc_html__( |
|
519 | + 'Registration is at an external URL for this event.', |
|
520 | + 'event_espresso' |
|
521 | + ) |
|
522 | + : ''; |
|
523 | + } |
|
524 | + |
|
525 | + |
|
526 | + /** |
|
527 | + * formOpen |
|
528 | + * |
|
529 | + * @param int $ID |
|
530 | + * @param string $external_url |
|
531 | + * @return string |
|
532 | + */ |
|
533 | + public function formOpen($ID = 0, $external_url = '') |
|
534 | + { |
|
535 | + // if redirecting, we don't need any anything else |
|
536 | + if ($external_url) { |
|
537 | + $html = '<form method="GET" '; |
|
538 | + $html .= 'action="' . EEH_URL::refactor_url($external_url) . '" '; |
|
539 | + $html .= 'name="ticket-selector-form-' . $ID . '"'; |
|
540 | + // open link in new window ? |
|
541 | + $html .= apply_filters( |
|
542 | + 'FHEE__EventEspresso_modules_ticket_selector_DisplayTicketSelector__formOpen__external_url_target_blank', |
|
543 | + $this->isIframe(), |
|
544 | + $this |
|
545 | + ) |
|
546 | + ? ' target="_blank"' |
|
547 | + : ''; |
|
548 | + $html .= '>'; |
|
549 | + $query_args = EEH_URL::get_query_string($external_url); |
|
550 | + foreach ((array) $query_args as $query_arg => $value) { |
|
551 | + $html .= '<input type="hidden" name="' . $query_arg . '" value="' . $value . '">'; |
|
552 | + } |
|
553 | + return $html; |
|
554 | + } |
|
555 | + // if there is no submit button, then don't start building a form |
|
556 | + // because the "View Details" button will build its own form |
|
557 | + if (! apply_filters('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', false)) { |
|
558 | + return ''; |
|
559 | + } |
|
560 | + $checkout_url = EEH_Event_View::event_link_url($ID); |
|
561 | + if (! $checkout_url) { |
|
562 | + EE_Error::add_error( |
|
563 | + esc_html__('The URL for the Event Details page could not be retrieved.', 'event_espresso'), |
|
564 | + __FILE__, |
|
565 | + __FUNCTION__, |
|
566 | + __LINE__ |
|
567 | + ); |
|
568 | + } |
|
569 | + // set no cache headers and constants |
|
570 | + EE_System::do_not_cache(); |
|
571 | + $html = '<form method="POST" '; |
|
572 | + $html .= 'action="' . $checkout_url . '" '; |
|
573 | + $html .= 'name="ticket-selector-form-' . $ID . '"'; |
|
574 | + $html .= $this->iframe ? ' target="_blank"' : ''; |
|
575 | + $html .= '>'; |
|
576 | + $html .= '<input type="hidden" name="ee" value="process_ticket_selections">'; |
|
577 | + return apply_filters('FHEE__EE_Ticket_Selector__ticket_selector_form_open__html', $html, $this->event); |
|
578 | + } |
|
579 | + |
|
580 | + |
|
581 | + /** |
|
582 | + * displaySubmitButton |
|
583 | + * |
|
584 | + * @param string $external_url |
|
585 | + * @return string |
|
586 | + * @throws EE_Error |
|
587 | + * @throws ReflectionException |
|
588 | + */ |
|
589 | + public function displaySubmitButton($external_url = '') |
|
590 | + { |
|
591 | + $html = ''; |
|
592 | + if ($this->display_full_ui()) { |
|
593 | + // standard TS displayed with submit button, ie: "Register Now" |
|
594 | + if (apply_filters('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', false)) { |
|
595 | + $html .= $this->displayRegisterNowButton(); |
|
596 | + $html .= empty($external_url) |
|
597 | + ? $this->ticketSelectorEndDiv() |
|
598 | + : $this->clearTicketSelector(); |
|
599 | + $html .= '<br/>' . $this->formClose(); |
|
600 | + } elseif ($this->getMaxAttendees() === 1) { |
|
601 | + // its a "Dude Where's my Ticket Selector?" (DWMTS) type event (ie: $_max_atndz === 1) |
|
602 | + if ($this->event->is_sold_out()) { |
|
603 | + // then instead of a View Details or Submit button, just display a "Sold Out" message |
|
604 | + $html .= apply_filters( |
|
605 | + 'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__sold_out_msg', |
|
606 | + sprintf( |
|
607 | + __( |
|
608 | + '%1$s"%2$s" is currently sold out.%4$sPlease check back again later, as spots may become available.%3$s', |
|
609 | + 'event_espresso' |
|
610 | + ), |
|
611 | + '<p class="no-ticket-selector-msg clear-float">', |
|
612 | + $this->event->name(), |
|
613 | + '</p>', |
|
614 | + '<br />' |
|
615 | + ), |
|
616 | + $this->event |
|
617 | + ); |
|
618 | + if (apply_filters( |
|
619 | + 'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__no_tickets_but_display_register_now_button', |
|
620 | + false, |
|
621 | + $this->event |
|
622 | + )) { |
|
623 | + $html .= $this->displayRegisterNowButton(); |
|
624 | + } |
|
625 | + // sold out DWMTS event, no TS, no submit or view details button, but has additional content |
|
626 | + $html .= $this->ticketSelectorEndDiv(); |
|
627 | + } elseif (apply_filters('FHEE__EE_Ticket_Selector__hide_ticket_selector', false) |
|
628 | + && ! is_single() |
|
629 | + ) { |
|
630 | + // this is a "Dude Where's my Ticket Selector?" (DWMTS) type event, |
|
631 | + // but no tickets are available, so display event's "View Details" button. |
|
632 | + // it is being viewed via somewhere other than a single post |
|
633 | + $html .= $this->displayViewDetailsButton(true); |
|
634 | + } else { |
|
635 | + $html .= $this->ticketSelectorEndDiv(); |
|
636 | + } |
|
637 | + } elseif (is_archive()) { |
|
638 | + // event list, no tickets available so display event's "View Details" button |
|
639 | + $html .= $this->ticketSelectorEndDiv(); |
|
640 | + $html .= $this->displayViewDetailsButton(); |
|
641 | + } else { |
|
642 | + if (apply_filters( |
|
643 | + 'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__no_tickets_but_display_register_now_button', |
|
644 | + false, |
|
645 | + $this->event |
|
646 | + )) { |
|
647 | + $html .= $this->displayRegisterNowButton(); |
|
648 | + } |
|
649 | + // no submit or view details button, and no additional content |
|
650 | + $html .= $this->ticketSelectorEndDiv(); |
|
651 | + } |
|
652 | + if (! $this->iframe && ! is_archive()) { |
|
653 | + $html .= EEH_Template::powered_by_event_espresso('', '', ['utm_content' => 'ticket_selector']); |
|
654 | + } |
|
655 | + } |
|
656 | + return apply_filters( |
|
657 | + 'FHEE__EventEspresso_modules_ticket_selector_DisplayTicketSelector__displaySubmitButton__html', |
|
658 | + $html, |
|
659 | + $this->event, |
|
660 | + $this |
|
661 | + ); |
|
662 | + } |
|
663 | + |
|
664 | + |
|
665 | + /** |
|
666 | + * @return string |
|
667 | + * @throws EE_Error |
|
668 | + * @throws ReflectionException |
|
669 | + */ |
|
670 | + public function displayRegisterNowButton() |
|
671 | + { |
|
672 | + $btn_text = apply_filters( |
|
673 | + 'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__btn_text', |
|
674 | + __('Register Now', 'event_espresso'), |
|
675 | + $this->event |
|
676 | + ); |
|
677 | + $external_url = (string) $this->event->external_url() |
|
678 | + && $this->event->external_url() !== get_the_permalink() |
|
679 | + ? $this->event->external_url() |
|
680 | + : ''; |
|
681 | + $html = EEH_HTML::div( |
|
682 | + '', |
|
683 | + 'ticket-selector-submit-' . $this->event->ID() . '-btn-wrap', |
|
684 | + 'ticket-selector-submit-btn-wrap' |
|
685 | + ); |
|
686 | + $html .= '<input id="ticket-selector-submit-' . $this->event->ID() . '-btn"'; |
|
687 | + $html .= ' class="ticket-selector-submit-btn '; |
|
688 | + $html .= empty($external_url) ? 'ticket-selector-submit-ajax"' : '"'; |
|
689 | + $html .= ' type="submit" value="' . $btn_text . '" data-ee-disable-after-recaptcha="true" />'; |
|
690 | + $html .= EEH_HTML::divx() . '<!-- .ticket-selector-submit-btn-wrap -->'; |
|
691 | + $html .= apply_filters( |
|
692 | + 'FHEE__EE_Ticket_Selector__after_ticket_selector_submit', |
|
693 | + '', |
|
694 | + $this->event, |
|
695 | + $this->iframe |
|
696 | + ); |
|
697 | + return $html; |
|
698 | + } |
|
699 | + |
|
700 | + |
|
701 | + /** |
|
702 | + * displayViewDetailsButton |
|
703 | + * |
|
704 | + * @param bool $DWMTS indicates a "Dude Where's my Ticket Selector?" (DWMTS) type event |
|
705 | + * (ie: $_max_atndz === 1) where there are no available tickets, |
|
706 | + * either because they are sold out, expired, or not yet on sale. |
|
707 | + * In this case, we need to close the form BEFORE adding any closing divs |
|
708 | + * @return string |
|
709 | + * @throws EE_Error |
|
710 | + * @throws ReflectionException |
|
711 | + */ |
|
712 | + public function displayViewDetailsButton($DWMTS = false) |
|
713 | + { |
|
714 | + if (! $this->event->get_permalink()) { |
|
715 | + EE_Error::add_error( |
|
716 | + esc_html__('The URL for the Event Details page could not be retrieved.', 'event_espresso'), |
|
717 | + __FILE__, |
|
718 | + __FUNCTION__, |
|
719 | + __LINE__ |
|
720 | + ); |
|
721 | + } |
|
722 | + $view_details_btn = '<form method="GET" action="'; |
|
723 | + $view_details_btn .= apply_filters( |
|
724 | + 'FHEE__EE_Ticket_Selector__display_view_details_btn__btn_url', |
|
725 | + $this->event->get_permalink(), |
|
726 | + $this->event |
|
727 | + ); |
|
728 | + $view_details_btn .= '"'; |
|
729 | + // open link in new window ? |
|
730 | + $view_details_btn .= apply_filters( |
|
731 | + 'FHEE__EventEspresso_modules_ticket_selector_DisplayTicketSelector__displayViewDetailsButton__url_target_blank', |
|
732 | + $this->isIframe(), |
|
733 | + $this |
|
734 | + ) |
|
735 | + ? ' target="_blank"' |
|
736 | + : ''; |
|
737 | + $view_details_btn .= '>'; |
|
738 | + $btn_text = apply_filters( |
|
739 | + 'FHEE__EE_Ticket_Selector__display_view_details_btn__btn_text', |
|
740 | + esc_html__('View Details', 'event_espresso'), |
|
741 | + $this->event |
|
742 | + ); |
|
743 | + $view_details_btn .= '<input id="ticket-selector-submit-' |
|
744 | + . $this->event->ID() |
|
745 | + . '-btn" class="ticket-selector-submit-btn view-details-btn" type="submit" value="' |
|
746 | + . $btn_text |
|
747 | + . '" />'; |
|
748 | + $view_details_btn .= apply_filters('FHEE__EE_Ticket_Selector__after_view_details_btn', '', $this->event); |
|
749 | + if ($DWMTS) { |
|
750 | + $view_details_btn .= $this->formClose(); |
|
751 | + $view_details_btn .= $this->ticketSelectorEndDiv(); |
|
752 | + $view_details_btn .= '<br/>'; |
|
753 | + } else { |
|
754 | + $view_details_btn .= $this->clearTicketSelector(); |
|
755 | + $view_details_btn .= '<br/>'; |
|
756 | + $view_details_btn .= $this->formClose(); |
|
757 | + } |
|
758 | + return $view_details_btn; |
|
759 | + } |
|
760 | + |
|
761 | + |
|
762 | + /** |
|
763 | + * @return string |
|
764 | + */ |
|
765 | + public function ticketSelectorEndDiv() |
|
766 | + { |
|
767 | + return $this->clearTicketSelector() . '</div><!-- ticketSelectorEndDiv -->'; |
|
768 | + } |
|
769 | + |
|
770 | + |
|
771 | + /** |
|
772 | + * @return string |
|
773 | + */ |
|
774 | + public function clearTicketSelector() |
|
775 | + { |
|
776 | + // standard TS displayed, appears after a "Register Now" or "view Details" button |
|
777 | + return '<div class="clear"></div><!-- clearTicketSelector -->'; |
|
778 | + } |
|
779 | + |
|
780 | + |
|
781 | + /** |
|
782 | + * @access public |
|
783 | + * @return string |
|
784 | + */ |
|
785 | + public function formClose() |
|
786 | + { |
|
787 | + return '</form>'; |
|
788 | + } |
|
789 | + |
|
790 | + |
|
791 | + /** |
|
792 | + * handleMissingEvent |
|
793 | + * Returns either false or an error to display when no valid event is passed. |
|
794 | + * |
|
795 | + * @return string |
|
796 | + * @throws ExceptionStackTraceDisplay |
|
797 | + * @throws InvalidInterfaceException |
|
798 | + * @throws Exception |
|
799 | + */ |
|
800 | + protected function handleMissingEvent() |
|
801 | + { |
|
802 | + // If this is not an iFrame request, simply return false. |
|
803 | + if (! $this->isIframe()) { |
|
804 | + return ''; |
|
805 | + } |
|
806 | + // This is an iFrame so return an error. |
|
807 | + // Display stack trace if WP_DEBUG is enabled. |
|
808 | + if (WP_DEBUG === true && current_user_can('edit_pages')) { |
|
809 | + $event_id = $this->request->getRequestParam('event', 0, 'int'); |
|
810 | + new ExceptionStackTraceDisplay( |
|
811 | + new InvalidArgumentException( |
|
812 | + sprintf( |
|
813 | + esc_html__( |
|
814 | + 'A valid Event ID is required to display the ticket selector.%3$sAn Event with an ID of "%1$s" could not be found.%3$sPlease verify that the embed code added to this post\'s content includes an "%2$s" argument and that its value corresponds to a valid Event ID.', |
|
815 | + 'event_espresso' |
|
816 | + ), |
|
817 | + $event_id, |
|
818 | + 'event', |
|
819 | + '<br />' |
|
820 | + ) |
|
821 | + ) |
|
822 | + ); |
|
823 | + return ''; |
|
824 | + } |
|
825 | + // If WP_DEBUG is not enabled, display a message stating the event could not be found. |
|
826 | + return EEH_HTML::p( |
|
827 | + esc_html__( |
|
828 | + 'A valid Event could not be found. Please contact the event administrator for assistance.', |
|
829 | + 'event_espresso' |
|
830 | + ) |
|
831 | + ); |
|
832 | + } |
|
833 | + |
|
834 | + |
|
835 | + /** |
|
836 | + * @return EE_Tax_Config |
|
837 | + * @since $VID:$ |
|
838 | + */ |
|
839 | + protected function getTaxConfig() |
|
840 | + { |
|
841 | + return isset(EE_Registry::instance()->CFG->tax_settings) |
|
842 | + && EE_Registry::instance()->CFG->tax_settings instanceof EE_Tax_Config |
|
843 | + ? EE_Registry::instance()->CFG->tax_settings |
|
844 | + : new EE_Tax_Config(); |
|
845 | + } |
|
846 | 846 | } |