Modern Events Calendar Lite - Version 4.8.3

Version Description

  • 25 November 2019 =
  • Fixed: Headers already sent warning
Download this release

Release Info

Developer webnus
Plugin Icon 128x128 Modern Events Calendar Lite
Version 4.8.3
Comparing to
See all releases

Code changes from version 4.8.2 to 4.8.3

app/libraries/main.php CHANGED
@@ -1,5518 +1,5518 @@
1
- <?php
2
- /** no direct access **/
3
- defined('MECEXEC') or die();
4
-
5
- use ICal\ICal;
6
-
7
- /**
8
- * Webnus MEC main class.
9
- * @author Webnus <info@webnus.biz>
10
- */
11
- class MEC_main extends MEC_base
12
- {
13
- /**
14
- * Constructor method
15
- * @author Webnus <info@webnus.biz>
16
- */
17
- public function __construct()
18
- {
19
- }
20
-
21
- /**
22
- * Returns the archive URL of events for provided skin
23
- * @author Webnus <info@webnus.biz>
24
- * @param string $skin
25
- * @return string
26
- */
27
- public function archive_URL($skin)
28
- {
29
- return $this->URL('site').$this->get_main_slug().'/'.$skin.'/';
30
- }
31
-
32
- /**
33
- * Returns full current URL of WordPress
34
- * @author Webnus <info@webnus.biz>
35
- * @return string
36
- */
37
- public function get_full_url()
38
- {
39
- // get $_SERVER
40
- $server = $this->getRequest()->get('SERVER');
41
-
42
- // Check protocol
43
- $page_url = 'http';
44
- if(isset($server['HTTPS']) and $server['HTTPS'] == 'on') $page_url .= 's';
45
-
46
- // Get domain
47
- $site_domain = (isset($server['HTTP_HOST']) and trim($server['HTTP_HOST']) != '') ? $server['HTTP_HOST'] : $server['SERVER_NAME'];
48
-
49
- $page_url .= '://';
50
- $page_url .= $site_domain.$server['REQUEST_URI'];
51
-
52
- // Return full URL
53
- return $page_url;
54
- }
55
-
56
- /**
57
- * Get domain of a certain URL
58
- * @author Webnus <info@webnus.biz>
59
- * @param string $url
60
- * @return string
61
- */
62
- public function get_domain($url = NULL)
63
- {
64
- // Get current URL
65
- if(is_null($url)) $url = $this->get_full_url();
66
-
67
- $url = str_replace('http://', '', $url);
68
- $url = str_replace('https://', '', $url);
69
- $url = str_replace('ftp://', '', $url);
70
- $url = str_replace('svn://', '', $url);
71
- $url = str_replace('www.', '', $url);
72
-
73
- $ex = explode('/', $url);
74
- $ex2 = explode('?', $ex[0]);
75
-
76
- return $ex2[0];
77
- }
78
-
79
- /**
80
- * Remove query string from the URL
81
- * @author Webnus <info@webnus.biz>
82
- * @param string $key
83
- * @param string $url
84
- * @return string
85
- */
86
- public function remove_qs_var($key, $url = '')
87
- {
88
- if(trim($url) == '') $url = $this->get_full_url();
89
-
90
- $url = preg_replace('/(.*)(\?|&)'.$key.'=[^&]+?(&)(.*)/i', '$1$2$4', $url .'&');
91
- $url = substr($url, 0, -1);
92
-
93
- return $url;
94
- }
95
-
96
- /**
97
- * Add query string to the URL
98
- * @author Webnus <info@webnus.biz>
99
- * @param string $key
100
- * @param string $value
101
- * @param string $url
102
- * @return string
103
- */
104
- public function add_qs_var($key, $value, $url = '')
105
- {
106
- if(trim($url) == '') $url = $this->get_full_url();
107
-
108
- $url = preg_replace('/(.*)(\?|&)'.$key.'=[^&]+?(&)(.*)/i', '$1$2$4', $url.'&');
109
- $url = substr($url, 0, -1);
110
-
111
- if(strpos($url, '?') === false)
112
- return $url.'?'.$key.'='.$value;
113
- else
114
- return $url.'&'.$key.'='.$value;
115
- }
116
-
117
- /**
118
- * Add multiple query strings to the URL
119
- * @author Webnus <info@webnus.biz>
120
- * @param array $vars
121
- * @param string $url
122
- * @return string
123
- */
124
- public function add_qs_vars($vars, $url = '')
125
- {
126
- if(trim($url) == '') $url = $this->get_full_url();
127
-
128
- foreach($vars as $key=>$value) $url = $this->add_qs_var($key, $value, $url);
129
- return $url;
130
- }
131
-
132
- /**
133
- * Returns WordPress authors
134
- * @author Webnus <info@webnus.biz>
135
- * @param array $args
136
- * @return array
137
- */
138
- public function get_authors($args = array())
139
- {
140
- return get_users($args);
141
- }
142
-
143
- /**
144
- * Returns full URL of an asset
145
- * @author Webnus <info@webnus.biz>
146
- * @param string $asset
147
- * @return string
148
- */
149
- public function asset($asset)
150
- {
151
- return $this->URL('MEC').'assets/'.$asset;
152
- }
153
-
154
- /**
155
- * Returns URL of WordPress items such as site, admin, plugins, MEC plugin etc.
156
- * @author Webnus <info@webnus.biz>
157
- * @param string $type
158
- * @return string
159
- */
160
- public function URL($type = 'site')
161
- {
162
- // Make it lowercase
163
- $type = strtolower($type);
164
-
165
- // Frontend
166
- if(in_array($type, array('frontend','site'))) $url = home_url().'/';
167
- // Backend
168
- elseif(in_array($type, array('backend','admin'))) $url = admin_url();
169
- // WordPress Content directory URL
170
- elseif($type == 'content') $url = content_url().'/';
171
- // WordPress plugins directory URL
172
- elseif($type == 'plugin') $url = plugins_url().'/';
173
- // WordPress include directory URL
174
- elseif($type == 'include') $url = includes_url();
175
- // Webnus MEC plugin URL
176
- elseif($type == 'mec')
177
- {
178
- // If plugin installed regularly on plugins directory
179
- if(!defined('MEC_IN_THEME')) $url = plugins_url().'/'.MEC_DIRNAME.'/';
180
- // If plugin embeded into one theme
181
- else $url = get_template_directory_uri().'/plugins/'.MEC_DIRNAME.'/';
182
- }
183
-
184
- return $url;
185
- }
186
-
187
- /**
188
- * Returns plugin absolute path
189
- * @author Webnus <info@webnus.biz>
190
- * @return string
191
- */
192
- public function get_plugin_path()
193
- {
194
- return MEC_ABSPATH;
195
- }
196
-
197
- /**
198
- * Returns a WordPress option
199
- * @author Webnus <info@webnus.biz>
200
- * @param string $option
201
- * @param mixed $default
202
- * @return mixed
203
- */
204
- public function get_option($option, $default = NULL)
205
- {
206
- return get_option($option, $default);
207
- }
208
-
209
- /**
210
- * Returns WordPress categories based on arguments
211
- * @author Webnus <info@webnus.biz>
212
- * @param array $args
213
- * @return array
214
- */
215
- public function get_categories($args = array())
216
- {
217
- return get_categories($args);
218
- }
219
-
220
- /**
221
- * Returns WordPress tags based on arguments
222
- * @author Webnus <info@webnus.biz>
223
- * @param array $args
224
- * @return array
225
- */
226
- public function get_tags($args = array())
227
- {
228
- return get_tags($args);
229
- }
230
-
231
- /**
232
- * Convert location string to latitude and longitude
233
- * @author Webnus <info@webnus.biz>
234
- * @param string $address
235
- * @return array
236
- */
237
- public function get_lat_lng($address)
238
- {
239
- $address = urlencode($address);
240
- if(!trim($address)) return array(0, 0);
241
-
242
- // MEC Settings
243
- $settings = $this->get_settings();
244
-
245
- $url1 = "https://maps.googleapis.com/maps/api/geocode/json?address=".$address.((isset($settings['google_maps_api_key']) and trim($settings['google_maps_api_key']) != '') ? '&key='.$settings['google_maps_api_key'] : '');
246
- $url2 = 'http://www.datasciencetoolkit.org/maps/api/geocode/json?sensor=false&address='.$address;
247
-
248
- // Get Latitide and Longitude by First URL
249
- $JSON = wp_remote_retrieve_body(wp_remote_get($url1, array(
250
- 'body' => null,
251
- 'timeout' => '10',
252
- 'redirection' => '10',
253
- )));
254
-
255
- $data = json_decode($JSON, true);
256
-
257
- $location_point = isset($data['results'][0]) ? $data['results'][0]['geometry']['location'] : array();
258
- if((isset($location_point['lat']) and $location_point['lat']) and (isset($location_point['lng']) and $location_point['lng']))
259
- {
260
- return array($location_point['lat'], $location_point['lng']);
261
- }
262
-
263
- // Get Latitide and Longitude by Second URL
264
- $JSON = wp_remote_retrieve_body(wp_remote_get($url2, array(
265
- 'body' => null,
266
- 'timeout' => '10',
267
- 'redirection' => '10',
268
- )));
269
-
270
- $data = json_decode($JSON, true);
271
-
272
- $location_point = isset($data['results'][0]) ? $data['results'][0]['geometry']['location'] : array();
273
- if((isset($location_point['lat']) and $location_point['lat']) and (isset($location_point['lng']) and $location_point['lng']))
274
- {
275
- return array($location_point['lat'], $location_point['lng']);
276
- }
277
-
278
- return array(0, 0);
279
- }
280
-
281
- /**
282
- * @author Webnus <info@webnus.biz>
283
- * @return string
284
- */
285
- public function get_default_label_color()
286
- {
287
- return apply_filters('mec_default_label_color', '#fefefe');
288
- }
289
-
290
- /**
291
- * @author Webnus <info@webnus.biz>
292
- * @param int $post_id
293
- * @return string
294
- */
295
- public function get_post_content($post_id)
296
- {
297
- $post = get_post($post_id);
298
- if(!$post) return NULL;
299
-
300
- $content = apply_filters('the_content', $post->post_content);
301
- return str_replace(']]>', ']]&gt;', do_shortcode($content));
302
- }
303
-
304
- /**
305
- * @author Webnus <info@webnus.biz>
306
- * @param int $post_id
307
- * @return array
308
- */
309
- public function get_post_meta($post_id)
310
- {
311
- $raw_data = get_post_meta($post_id, '', true);
312
- $data = array();
313
-
314
- // Invalid Raw Data
315
- if(!is_array($raw_data)) return $data;
316
-
317
- foreach($raw_data as $key=>$val) $data[$key] = isset($val[0]) ? (!is_serialized($val[0]) ? $val[0] : unserialize($val[0])) : NULL;
318
-
319
- return $data;
320
- }
321
-
322
- /**
323
- * @author Webnus <info@webnus.biz>
324
- * @return array
325
- */
326
- public function get_skins()
327
- {
328
- $skins = array
329
- (
330
- 'list'=>__('List View', 'modern-events-calendar-lite'),
331
- 'grid'=>__('Grid View', 'modern-events-calendar-lite'),
332
- 'agenda'=>__('Agenda View', 'modern-events-calendar-lite'),
333
- 'full_calendar'=>__('Full Calendar', 'modern-events-calendar-lite'),
334
- 'yearly_view'=>__('Yearly View', 'modern-events-calendar-lite'),
335
- 'monthly_view'=>__('Calendar/Monthly View', 'modern-events-calendar-lite'),
336
- 'daily_view'=>__('Daily View', 'modern-events-calendar-lite'),
337
- 'weekly_view'=>__('Weekly View', 'modern-events-calendar-lite'),
338
- 'timetable'=>__('Timetable View', 'modern-events-calendar-lite'),
339
- 'masonry'=>__('Masonry View', 'modern-events-calendar-lite'),
340
- 'map'=>__('Map View', 'modern-events-calendar-lite'),
341
- 'cover'=>__('Cover View', 'modern-events-calendar-lite'),
342
- 'countdown'=>__('Countdown View', 'modern-events-calendar-lite'),
343
- 'available_spot'=>__('Available Spot', 'modern-events-calendar-lite'),
344
- 'carousel'=>__('Carousel View', 'modern-events-calendar-lite'),
345
- 'slider'=>__('Slider View', 'modern-events-calendar-lite'),
346
- 'timeline'=>__('Timeline View', 'modern-events-calendar-lite')
347
- );
348
-
349
- return apply_filters('mec_calendar_skins', $skins);
350
- }
351
-
352
- /**
353
- * Returns weekday labels
354
- * @author Webnus <info@webnus.biz>
355
- * @param integer $week_start
356
- * @return array
357
- */
358
- public function get_weekday_labels($week_start = NULL)
359
- {
360
- if(is_null($week_start)) $week_start = $this->get_first_day_of_week();
361
-
362
- /**
363
- * Please don't change it to translate-able strings
364
- */
365
- $raw = array('Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday');
366
-
367
- $labels = array_slice($raw, $week_start);
368
- $rest = array_slice($raw, 0, $week_start);
369
-
370
- foreach($rest as $label) array_push($labels, $label);
371
-
372
- return apply_filters('mec_weekday_labels', $labels);
373
- }
374
-
375
- /**
376
- * Returns abbr weekday labels
377
- * @author Webnus <info@webnus.biz>
378
- * @return array
379
- */
380
- public function get_weekday_abbr_labels()
381
- {
382
- $week_start = $this->get_first_day_of_week();
383
- $raw = array(
384
- $this->m('weekdays_su', __('SU', 'modern-events-calendar-lite')),
385
- $this->m('weekdays_mo', __('MO', 'modern-events-calendar-lite')),
386
- $this->m('weekdays_tu', __('TU', 'modern-events-calendar-lite')),
387
- $this->m('weekdays_we', __('WE', 'modern-events-calendar-lite')),
388
- $this->m('weekdays_th', __('TH', 'modern-events-calendar-lite')),
389
- $this->m('weekdays_fr', __('FR', 'modern-events-calendar-lite')),
390
- $this->m('weekdays_sa', __('SA', 'modern-events-calendar-lite'))
391
- );
392
-
393
- $labels = array_slice($raw, $week_start);
394
- $rest = array_slice($raw, 0, $week_start);
395
-
396
- foreach($rest as $label) array_push($labels, $label);
397
-
398
- return apply_filters('mec_weekday_abbr_labels', $labels);
399
- }
400
-
401
- /**
402
- * Returns translatable weekday labels
403
- * @author Webnus <info@webnus.biz>
404
- * @return array
405
- */
406
- public function get_weekday_i18n_labels()
407
- {
408
- $week_start = $this->get_first_day_of_week();
409
- $raw = array(array(7, __('Sunday', 'modern-events-calendar-lite')), array(1, __('Monday', 'modern-events-calendar-lite')), array(2, __('Tuesday', 'modern-events-calendar-lite')), array(3, __('Wednesday', 'modern-events-calendar-lite')), array(4, __('Thursday', 'modern-events-calendar-lite')), array(5, __('Friday', 'modern-events-calendar-lite')), array(6, __('Saturday', 'modern-events-calendar-lite')));
410
-
411
- $labels = array_slice($raw, $week_start);
412
- $rest = array_slice($raw, 0, $week_start);
413
-
414
- foreach($rest as $label) array_push($labels, $label);
415
-
416
- return apply_filters('mec_weekday_i18n_labels', $labels);
417
- }
418
-
419
- /**
420
- * Flush WordPress rewrite rules
421
- * @author Webnus <info@webnus.biz>
422
- */
423
- public function flush_rewrite_rules()
424
- {
425
- // Register Events Post Type
426
- $MEC_events = MEC::getInstance('app.features.events', 'MEC_feature_events');
427
- $MEC_events->register_post_type();
428
-
429
- flush_rewrite_rules();
430
- }
431
-
432
- /**
433
- * Get single slug of MEC
434
- * @author Webnus <info@webnus.biz>
435
- * @return string
436
- */
437
- public function get_single_slug()
438
- {
439
- $settings = $this->get_settings();
440
- $slug = (isset($settings['single_slug']) and trim($settings['single_slug']) != '') ? $settings['single_slug'] : 'event';
441
-
442
- return $slug;
443
- }
444
-
445
- /**
446
- * Returns main slug of MEC
447
- * @author Webnus <info@webnus.biz>
448
- * @return string
449
- */
450
- public function get_main_slug()
451
- {
452
- $settings = $this->get_settings();
453
- $slug = (isset($settings['slug']) and trim($settings['slug']) != '') ? $settings['slug'] : 'events';
454
-
455
- return strtolower($slug);
456
- }
457
-
458
- /**
459
- * Returns category slug of MEC
460
- * @author Webnus <info@webnus.biz>
461
- * @return string
462
- */
463
- public function get_category_slug()
464
- {
465
- $settings = $this->get_settings();
466
- $slug = (isset($settings['category_slug']) and trim($settings['category_slug']) != '') ? $settings['category_slug'] : 'mec-category';
467
-
468
- return strtolower($slug);
469
- }
470
-
471
- /**
472
- * Get archive page title
473
- * @author Webnus <info@webnus.biz>
474
- * @return string
475
- */
476
- public function get_archive_title()
477
- {
478
- $settings = $this->get_settings();
479
- $archive_title = (isset($settings['archive_title']) and trim($settings['archive_title']) != '') ? $settings['archive_title'] : 'Events';
480
-
481
- return apply_filters('mec_archive_title', $archive_title);
482
- }
483
-
484
- /**
485
- * @author Webnus <info@webnus.biz>
486
- * @return string
487
- */
488
- public function get_archive_thumbnail()
489
- {
490
- return apply_filters('mec_archive_thumbnail', '');
491
- }
492
-
493
- /**
494
- * @author Webnus <info@webnus.biz>
495
- * @return string
496
- */
497
- public function get_single_thumbnail()
498
- {
499
- return apply_filters('mec_single_thumbnail', '');
500
- }
501
-
502
- /**
503
- * @author Webnus <info@webnus.biz>
504
- * @return string
505
- */
506
- public function get_main_post_type()
507
- {
508
- return apply_filters('mec_post_type_name', 'mec-events');
509
- }
510
-
511
- /**
512
- * Returns main options of MEC
513
- * @author Webnus <info@webnus.biz>
514
- * @return array
515
- */
516
- public function get_options()
517
- {
518
- return get_option('mec_options', array());
519
- }
520
-
521
- /**
522
- * Returns MEC settings menus
523
- * @author Webnus <info@webnus.biz>
524
- * @return array
525
- */
526
- public function get_sidebar_menu($active_menu = 'settings')
527
- {
528
- $options = $this->get_settings();
529
- $settings = apply_filters('mec-settings-items-settings', array(
530
- __('General Options', 'modern-events-calendar-lite') => 'general_option',
531
- __('Archive Pages', 'modern-events-calendar-lite') => 'archive_options',
532
- __('Slugs/Permalinks', 'modern-events-calendar-lite') => 'slug_option',
533
- __('Currency Options', 'modern-events-calendar-lite') => 'currency_option',
534
- __('Google Recaptcha Options', 'modern-events-calendar-lite') => 'recaptcha_option',
535
- __('Frontend Event Submission', 'modern-events-calendar-lite') => 'fes_option',
536
- __('User Profile', 'modern-events-calendar-lite') => 'user_profile_options',
537
- __('Search Bar', 'modern-events-calendar-lite') => 'search_bar_options',
538
- __('Mailchimp Integration', 'modern-events-calendar-lite') => 'mailchimp_option',
539
- __('Upload Field', 'modern-events-calendar-lite') => 'uploadfield_option',
540
- ), $active_menu);
541
-
542
- $single_event = apply_filters('mec-settings-item-single_event', array(
543
- __('Single Event Page', 'modern-events-calendar-lite') => 'event_options',
544
- __('Countdown Options', 'modern-events-calendar-lite') => 'countdown_option',
545
- __('Exceptional Days', 'modern-events-calendar-lite') => 'exceptional_option',
546
- __('Additional Organizers', 'modern-events-calendar-lite') => 'additional_organizers',
547
- __('Additional Locations', 'modern-events-calendar-lite') => 'additional_locations',
548
- __('Related Events', 'modern-events-calendar-lite') => 'related_events',
549
- ), $active_menu);
550
-
551
- $booking = apply_filters('mec-settings-item-booking', array(
552
- __('Booking', 'modern-events-calendar-lite') => 'booking_option',
553
- __('Coupons', 'modern-events-calendar-lite') => 'coupon_option',
554
- __('Taxes / Fees', 'modern-events-calendar-lite') => 'taxes_option',
555
- __('Ticket Variations & Options', 'modern-events-calendar-lite') => 'ticket_variations_option',
556
- __('Booking Form', 'modern-events-calendar-lite') => 'booking_form_option',
557
- __('Payment Gateways', 'modern-events-calendar-lite') => 'payment_gateways_option',
558
- ), $active_menu);
559
-
560
- $modules = apply_filters('mec-settings-item-modules', array(
561
- __('Speakers', 'modern-events-calendar-lite') => 'speakers_option',
562
- __('Google Maps Options', 'modern-events-calendar-lite') => 'googlemap_option',
563
- __('Export Options', 'modern-events-calendar-lite') => 'export_module_option',
564
- __('Local Time', 'modern-events-calendar-lite') => 'time_module_option',
565
- __('QR Code', 'modern-events-calendar-lite') => 'qrcode_module_option',
566
- __('Weather', 'modern-events-calendar-lite') => 'weather_module_option',
567
- __('Social Networks', 'modern-events-calendar-lite') => 'social_options',
568
- __('Next Event', 'modern-events-calendar-lite') => 'next_event_option',
569
- __('BuddyPress Integration', 'modern-events-calendar-lite') => 'buddy_option',
570
- ), $active_menu);
571
-
572
- $notifications = apply_filters('mec-settings-item-notifications', array(
573
- __('Booking', 'modern-events-calendar-lite') => 'booking_notification',
574
- __('Booking Verification', 'modern-events-calendar-lite') => 'booking_verification',
575
- __('Booking Confirmation', 'modern-events-calendar-lite') => 'booking_confirmation',
576
- __('Booking Cancellation', 'modern-events-calendar-lite') => 'cancellation_notification',
577
- __('Booking Reminder', 'modern-events-calendar-lite') => 'booking_reminder',
578
- __('Admin', 'modern-events-calendar-lite') => 'admin_notification',
579
- __('New Event', 'modern-events-calendar-lite') => 'new_event',
580
- __('User Event Publishing', 'modern-events-calendar-lite') => 'user_event_publishing',
581
- ), $active_menu);
582
-
583
- ?>
584
- <ul class="wns-be-group-menu">
585
-
586
- <!-- Settings -->
587
- <li class="wns-be-group-menu-li mec-settings-menu <?php echo $active_menu == 'settings' ? 'active' : ''; ?>">
588
- <a href="<?php echo $this->remove_qs_var('tab'); ?>" id="" class="wns-be-group-tab-link-a">
589
- <i class="mec-sl-settings"></i>
590
- <span class="wns-be-group-menu-title"><?php _e('Settings', 'modern-events-calendar-lite'); ?></span>
591
- </a>
592
- <ul class="<?php echo $active_menu == 'settings' ? 'subsection' : 'mec-settings-submenu'; ?>">
593
- <?php foreach ($settings as $settings_name => $settings_link) : ?>
594
- <?php
595
- if ( $settings_link == 'mailchimp_option') :
596
- if ( $this->getPRO() ) : ?>
597
- <li>
598
- <a
599
- <?php if ( $active_menu == 'settings' ) : ?>
600
- data-id="<?php echo $settings_link; ?>" class="wns-be-group-tab-link-a WnTabLinks"
601
- <?php else: ?>
602
- href="<?php echo $this->remove_qs_var('tab') . '#' . $settings_link; ?>"
603
- <?php endif; ?>
604
- >
605
- <span class="pr-be-group-menu-title"><?php echo $settings_name; ?></span>
606
- </a>
607
- </li>
608
- <?php
609
- endif;
610
- else : ?>
611
- <li>
612
- <a
613
- <?php if ( $active_menu == 'settings' ) : ?>
614
- data-id="<?php echo $settings_link; ?>" class="wns-be-group-tab-link-a WnTabLinks"
615
- <?php else: ?>
616
- href="<?php echo $this->remove_qs_var('tab') . '#' . $settings_link; ?>"
617
- <?php endif; ?>
618
- >
619
- <span class="pr-be-group-menu-title"><?php echo $settings_name; ?></span>
620
- </a>
621
- </li>
622
- <?php endif; ?>
623
- <?php endforeach; ?>
624
- </ul>
625
- </li>
626
-
627
- <!-- Single Event -->
628
- <li class="wns-be-group-menu-li mec-settings-menu <?php echo $active_menu == 'single_event' ? 'active' : ''; ?>">
629
- <a href="<?php echo $this->add_qs_var('tab', 'MEC-single'); ?>" id="" class="wns-be-group-tab-link-a">
630
- <i class="mec-sl-note"></i>
631
- <span class="wns-be-group-menu-title"><?php _e('Single Event', 'modern-events-calendar-lite'); ?></span>
632
- </a>
633
- <ul class="<?php echo $active_menu == 'single_event' ? 'subsection' : 'mec-settings-submenu'; ?>">
634
- <?php foreach ($single_event as $single_event_name => $single_event_link) : ?>
635
- <li>
636
- <a
637
- <?php if ( $active_menu == 'single_event' ) : ?>
638
- data-id="<?php echo $single_event_link; ?>" class="wns-be-group-tab-link-a WnTabLinks"
639
- <?php else: ?>
640
- href="<?php echo $this->add_qs_var('tab', 'MEC-single') . '#' . $single_event_link; ?>"
641
- <?php endif; ?>
642
- >
643
- <span class="pr-be-group-menu-title"><?php echo $single_event_name; ?></span>
644
- </a>
645
- </li>
646
- <?php endforeach; ?>
647
- </ul>
648
- </li>
649
-
650
- <!-- Booking -->
651
- <?php if($this->getPRO()): ?>
652
- <li class="wns-be-group-menu-li mec-settings-menu <?php echo $active_menu == 'booking' ? 'active' : ''; ?>">
653
- <a href="<?php echo $this->add_qs_var('tab', 'MEC-booking'); ?>" id="" class="wns-be-group-tab-link-a">
654
- <i class="mec-sl-credit-card"></i>
655
- <span class="wns-be-group-menu-title"><?php _e('Booking', 'modern-events-calendar-lite'); ?></span>
656
- </a>
657
- <ul class="<?php echo $active_menu == 'booking' ? 'subsection' : 'mec-settings-submenu'; ?>">
658
-
659
- <?php foreach ($booking as $booking_name => $booking_link) : ?>
660
- <?php if ( $booking_link == 'coupon_option' || $booking_link == 'taxes_option' || $booking_link == 'ticket_variations_option' || $booking_link == 'booking_form_option' || $booking_link == 'payment_gateways_option' ): ?>
661
- <?php if ( isset($options['booking_status']) and $options['booking_status'] ) : ?>
662
- <li>
663
- <a
664
- <?php if ( $active_menu == 'booking' ) : ?>
665
- data-id="<?php echo $booking_link; ?>" class="wns-be-group-tab-link-a WnTabLinks"
666
- <?php else: ?>
667
- href="<?php echo $this->add_qs_var('tab', 'MEC-booking') . '#' . $booking_link; ?>"
668
- <?php endif; ?>
669
- >
670
- <span class="pr-be-group-menu-title"><?php echo $booking_name; ?></span>
671
- </a>
672
- </li>
673
- <?php endif; ?>
674
- <?php else: ?>
675
- <li>
676
- <a
677
- <?php if ( $active_menu == 'booking' ) : ?>
678
- data-id="<?php echo $booking_link; ?>" class="wns-be-group-tab-link-a WnTabLinks"
679
- <?php else: ?>
680
- href="<?php echo $this->add_qs_var('tab', 'MEC-booking') . '#' . $booking_link; ?>"
681
- <?php endif; ?>
682
- >
683
- <span class="pr-be-group-menu-title"><?php echo $booking_name; ?></span>
684
- </a>
685
- </li>
686
- <?php endif; ?>
687
-
688
- <?php endforeach; ?>
689
- </ul>
690
- </li>
691
- <?php endif; ?>
692
-
693
- <!-- Modules -->
694
- <li class="wns-be-group-menu-li mec-settings-menu <?php echo $active_menu == 'modules' ? 'active' : ''; ?>">
695
- <a href="<?php echo $this->add_qs_var('tab', 'MEC-modules'); ?>" id="" class="wns-be-group-tab-link-a">
696
- <i class="mec-sl-grid"></i>
697
- <span class="wns-be-group-menu-title"><?php _e('Modules', 'modern-events-calendar-lite'); ?></span>
698
- </a>
699
- <ul class="<?php echo $active_menu == 'modules' ? 'subsection' : 'mec-settings-submenu'; ?>">
700
-
701
- <?php foreach ($modules as $modules_name => $modules_link) : ?>
702
- <?php if ( $modules_link == 'googlemap_option' || $modules_link == 'qrcode_module_option' || $modules_link == 'weather_module_option' || $modules_link == 'buddy_option' ): ?>
703
- <?php if($this->getPRO()): ?>
704
- <li>
705
- <a
706
- <?php if ( $active_menu == 'modules' ) : ?>
707
- data-id="<?php echo $modules_link; ?>" class="wns-be-group-tab-link-a WnTabLinks"
708
- <?php else: ?>
709
- href="<?php echo $this->add_qs_var('tab', 'MEC-modules') . '#' . $modules_link; ?>"
710
- <?php endif; ?>
711
- >
712
- <span class="pr-be-group-menu-title"><?php echo $modules_name; ?></span>
713
- </a>
714
- </li>
715
- <?php endif; ?>
716
- <?php else: ?>
717
- <li>
718
- <a
719
- <?php if ( $active_menu == 'modules' ) : ?>
720
- data-id="<?php echo $modules_link; ?>" class="wns-be-group-tab-link-a WnTabLinks"
721
- <?php else: ?>
722
- href="<?php echo $this->add_qs_var('tab', 'MEC-modules') . '#' . $modules_link; ?>"
723
- <?php endif; ?>
724
- >
725
- <span class="pr-be-group-menu-title"><?php echo $modules_name; ?></span>
726
- </a>
727
- </li>
728
- <?php endif; ?>
729
-
730
- <?php endforeach; ?>
731
- </ul>
732
- </li>
733
-
734
- <!-- Notifications -->
735
- <li class="wns-be-group-menu-li mec-settings-menu <?php echo $active_menu == 'notifications' ? 'active' : ''; ?>">
736
- <a href="<?php echo $this->add_qs_var('tab', 'MEC-notifications'); ?>" id="" class="wns-be-group-tab-link-a">
737
- <i class="mec-sl-envelope"></i>
738
- <span class="wns-be-group-menu-title"><?php _e('Notifications', 'modern-events-calendar-lite'); ?></span>
739
- </a>
740
- <ul class="<?php echo $active_menu == 'notifications' ? 'subsection' : 'mec-settings-submenu'; ?>">
741
-
742
- <?php foreach ($notifications as $notifications_name => $notifications_link) : ?>
743
- <?php if ( $notifications_link != 'new_event' and $notifications_link != 'user_event_publishing' ): ?>
744
- <?php if(isset($options['booking_status']) and $options['booking_status']): ?>
745
- <li>
746
- <a
747
- <?php if ( $active_menu == 'notifications' ) : ?>
748
- data-id="<?php echo $notifications_link; ?>" class="wns-be-group-tab-link-a WnTabLinks"
749
- <?php else: ?>
750
- href="<?php echo $this->add_qs_var('tab', 'MEC-notifications') . '#' . $notifications_link; ?>"
751
- <?php endif; ?>
752
- >
753
- <span class="pr-be-group-menu-title"><?php echo $notifications_name; ?></span>
754
- </a>
755
- </li>
756
- <?php endif; ?>
757
- <?php else: ?>
758
- <li>
759
- <a
760
- <?php if ( $active_menu == 'notifications' ) : ?>
761
- data-id="<?php echo $notifications_link; ?>" class="wns-be-group-tab-link-a WnTabLinks"
762
- <?php else: ?>
763
- href="<?php echo $this->add_qs_var('tab', 'MEC-notifications') . '#' . $notifications_link; ?>"
764
- <?php endif; ?>
765
- >
766
- <span class="pr-be-group-menu-title"><?php echo $notifications_name; ?></span>
767
- </a>
768
- </li>
769
- <?php endif; ?>
770
- <?php endforeach; ?>
771
- </ul>
772
- </li>
773
-
774
- <li class="wns-be-group-menu-li mec-settings-menu <?php echo $active_menu == 'styling' ? 'active' : ''; ?>">
775
- <a href="<?php echo $this->add_qs_var('tab', 'MEC-styling'); ?>" id="" class="wns-be-group-tab-link-a">
776
- <i class="mec-sl-equalizer"></i>
777
- <span class="wns-be-group-menu-title"><?php _e('Styling Options', 'modern-events-calendar-lite'); ?></span>
778
- </a>
779
- </li>
780
-
781
- <li class="wns-be-group-menu-li mec-settings-menu <?php echo $active_menu == 'customcss' ? 'active' : ''; ?>">
782
- <a href="<?php echo $this->add_qs_var('tab', 'MEC-customcss'); ?>" id="" class="wns-be-group-tab-link-a">
783
- <i class="mec-sl-wrench"></i>
784
- <span class="wns-be-group-menu-title"><?php _e('Custom CSS', 'modern-events-calendar-lite'); ?></span>
785
- </a>
786
- </li>
787
-
788
- <li class="wns-be-group-menu-li mec-settings-menu <?php echo $active_menu == 'messages' ? 'active' : ''; ?>">
789
- <a href="<?php echo $this->add_qs_var('tab', 'MEC-messages'); ?>" id="" class="wns-be-group-tab-link-a">
790
- <i class="mec-sl-bubble"></i>
791
- <span class="wns-be-group-menu-title"><?php _e('Messages', 'modern-events-calendar-lite'); ?></span>
792
- </a>
793
- </li>
794
-
795
- <li class="wns-be-group-menu-li mec-settings-menu <?php echo $active_menu == 'ie' ? 'active' : ''; ?>">
796
- <a href="<?php echo $this->add_qs_var('tab', 'MEC-ie'); ?>" id="" class="wns-be-group-tab-link-a">
797
- <i class="mec-sl-refresh"></i>
798
- <span class="wns-be-group-menu-title"><?php _e('Import / Export', 'modern-events-calendar-lite'); ?></span>
799
- </a>
800
- </li>
801
- </ul> <!-- close wns-be-group-menu -->
802
- <script type="text/javascript">
803
- jQuery(document).ready(function()
804
- {
805
- if ( jQuery('.mec-settings-menu').hasClass('active') )
806
- {
807
- jQuery('.mec-settings-menu.active').find('ul li:first-of-type').addClass('active');
808
- }
809
-
810
- jQuery('.WnTabLinks').each(function()
811
- {
812
- var ContentId = jQuery(this).attr('data-id');
813
- jQuery(this).click(function()
814
- {
815
- jQuery('.wns-be-sidebar li ul li').removeClass('active');
816
- jQuery(this).parent().addClass('active');
817
- jQuery(".mec-options-fields").hide();
818
- jQuery(".mec-options-fields").removeClass('active');
819
- jQuery("#"+ContentId+"").show();
820
- jQuery("#"+ContentId+"").addClass('active');
821
- jQuery('html, body').animate({
822
- scrollTop: jQuery("#"+ContentId+"").offset().top - 140
823
- }, 300);
824
- });
825
- var hash = window.location.hash.replace('#', '');
826
- jQuery('[data-id="'+hash+'"]').trigger('click');
827
- });
828
-
829
-
830
-
831
- jQuery(".wns-be-sidebar li ul li").on('click', function(event)
832
- {
833
- jQuery(".wns-be-sidebar li ul li").removeClass('active');
834
- jQuery(this).addClass('active');
835
- });
836
-
837
- });
838
- </script>
839
- <?php
840
-
841
- }
842
-
843
- /**
844
- * Returns MEC settings
845
- * @author Webnus <info@webnus.biz>
846
- * @return array
847
- */
848
- public function get_settings()
849
- {
850
- $options = $this->get_options();
851
- return (isset($options['settings']) ? $options['settings'] : array());
852
- }
853
-
854
- /**
855
- * Returns MEC addons message
856
- * @author Webnus <info@webnus.biz>
857
- * @return array
858
- */
859
- public function addons_msg()
860
- {
861
- $get_n_option = get_option('mec_addons_notification_option');
862
- if ( $get_n_option == 'open' ) return;
863
- return '
864
- <div class="w-row mec-addons-notification-wrap">
865
- <div class="w-col-sm-12">
866
- <div class="w-clearfix w-box mec-addons-notification-box-wrap">
867
- <div class="w-box-head">'.__('New Addons For MEC! Now Customize MEC in Elementor', 'modern-events-calendar-lite').'<span><i class="mec-sl-close"></i></span></div>
868
- <div class="w-box-content">
869
- <div class="mec-addons-notification-box-image">
870
- <img src="'. plugin_dir_url(__FILE__ ) . '../../assets/img/mec-addons-teaser1.png" />
871
- </div>
872
- <div class="mec-addons-notification-box-content">
873
- <div class="w-box-content">
874
- <p>'.__('The time has come at last, and the new practical add-ons for MEC have been released. This is a revolution in the world of Event Calendars. We have provided you with a wide range of features only by having the 4 add-ons below:' , 'modern-events-calendar-lite').'</p>
875
- <ol>
876
- <li>'.__('<strong>WooCommerce Integration:</strong> You can now purchase ticket (as products) and Woo products at the same time.' , 'modern-events-calendar-lite').'</li>
877
- <li>'.__('<strong>Event API:</strong> display your events (shortcodes/single event) on other websites without MEC. Use JSON output features to make your Apps compatible with MEC.' , 'modern-events-calendar-lite').'</li>
878
- <li>'.__('<strong>Elementor Single Builder:</strong> Edit single event page using Elementor. Manage the position of all elements in the Single page and in desktops, mobiles and tablets as well.' , 'modern-events-calendar-lite').'</li>
879
- <li>'.__('<strong>Elementor Shortcode Builder:</strong> It enables you to create shortcodes in Elementor Live Editor.', 'modern-events-calendar-lite').'</li>
880
- </ol>
881
- <a href="https://webnus.net/modern-events-calendar/addons/?ref=17" target="_blank">'.esc_html('find out more', 'modern-events-calendar-lite').'</a>
882
- </div>
883
- </div>
884
- </div>
885
- </div>
886
- </div>
887
- </div>
888
- ';
889
- }
890
-
891
- /**
892
- * Returns MEC settings
893
- * @author Webnus <info@webnus.biz>
894
- * @return array
895
- */
896
- public function get_default_form()
897
- {
898
- $options = $this->get_options();
899
- return (isset($options['default_form']) ? $options['default_form'] : array());
900
- }
901
-
902
- /**
903
- * Returns registration form fields
904
- * @author Webnus <info@webnus.biz>
905
- * @param integer $event_id
906
- * @return array
907
- */
908
- public function get_reg_fields($event_id = NULL)
909
- {
910
- $options = $this->get_options();
911
- $reg_fields = isset($options['reg_fields']) ? $options['reg_fields'] : array();
912
-
913
- // Event Booking Fields
914
- if($event_id)
915
- {
916
- $global_inheritance = get_post_meta($event_id, 'mec_reg_fields_global_inheritance', true);
917
- if(trim($global_inheritance) == '') $global_inheritance = 1;
918
-
919
- if(!$global_inheritance)
920
- {
921
- $event_reg_fields = get_post_meta($event_id, 'mec_reg_fields', true);
922
- if(is_array($event_reg_fields)) $reg_fields = $event_reg_fields;
923
- }
924
- }
925
-
926
- return apply_filters( 'mec_get_reg_fields', $reg_fields, $event_id );
927
- }
928
-
929
- /**
930
- * Returns Ticket Variations
931
- * @author Webnus <info@webnus.biz>
932
- * @param integer $event_id
933
- * @return array
934
- */
935
- public function ticket_variations($event_id = NULL)
936
- {
937
- $settings = $this->get_settings();
938
- $ticket_variations = (isset($settings['ticket_variations']) and is_array($settings['ticket_variations'])) ? $settings['ticket_variations'] : array();
939
-
940
- // Event Ticket Variations
941
- if($event_id)
942
- {
943
- $global_inheritance = get_post_meta($event_id, 'mec_ticket_variations_global_inheritance', true);
944
- if(trim($global_inheritance) == '') $global_inheritance = 1;
945
-
946
- if(!$global_inheritance)
947
- {
948
- $event_ticket_variations = get_post_meta($event_id, 'mec_ticket_variations', true);
949
- if(is_array($event_ticket_variations)) $ticket_variations = $event_ticket_variations;
950
- }
951
- }
952
-
953
- return $ticket_variations;
954
- }
955
-
956
- /**
957
- * Returns Messages Options
958
- * @author Webnus <info@webnus.biz>
959
- * @return array
960
- */
961
- public function get_messages_options()
962
- {
963
- $options = $this->get_options();
964
- return (isset($options['messages']) ? $options['messages'] : array());
965
- }
966
-
967
- /**
968
- * Returns gateways options
969
- * @author Webnus <info@webnus.biz>
970
- * @return array
971
- */
972
- public function get_gateways_options()
973
- {
974
- $options = $this->get_options();
975
- return (isset($options['gateways']) ? $options['gateways'] : array());
976
- }
977
- /**
978
- * Returns notifications settings of MEC
979
- * @author Webnus <info@webnus.biz>
980
- * @return array
981
- */
982
- public function get_notifications()
983
- {
984
- $options = $this->get_options();
985
- return (isset($options['notifications']) ? $options['notifications'] : array());
986
- }
987
-
988
- /**
989
- * Returns Import/Export options of MEC
990
- * @author Webnus <info@webnus.biz>
991
- * @return array
992
- */
993
- public function get_ix_options()
994
- {
995
- $options = $this->get_options();
996
- return (isset($options['ix']) ? $options['ix'] : array());
997
- }
998
-
999
- /**
1000
- * Returns style settings of MEC
1001
- * @author Webnus <info@webnus.biz>
1002
- * @return array
1003
- */
1004
- public function get_styles()
1005
- {
1006
- $options = $this->get_options();
1007
- return (isset($options['styles']) ? $options['styles'] : array());
1008
- }
1009
-
1010
- /**
1011
- * Returns styling option of MEC
1012
- * @author Webnus <info@webnus.biz>
1013
- * @return array
1014
- */
1015
- public function get_styling()
1016
- {
1017
- $options = $this->get_options();
1018
- return (isset($options['styling']) ? $options['styling'] : array());
1019
- }
1020
-
1021
- /**
1022
- * Prints custom styles in the page header
1023
- * @author Webnus <info@webnus.biz>
1024
- * @return void
1025
- */
1026
- public function include_styles()
1027
- {
1028
- $styles = $this->get_styles();
1029
-
1030
- // Print custom styles
1031
- if(isset($styles['CSS']) and trim($styles['CSS']) != '')
1032
- {
1033
- $CSS = strip_tags($styles['CSS']);
1034
- echo '<style type="text/css">'.stripslashes($CSS).'</style>';
1035
- }
1036
- }
1037
-
1038
- /**
1039
- * Saves MEC settings
1040
- * @author Webnus <info@webnus.biz>
1041
- * @return void
1042
- */
1043
- public function save_options()
1044
- {
1045
- // MEC Request library
1046
- $request = $this->getRequest();
1047
-
1048
- $wpnonce = $request->getVar('_wpnonce', NULL);
1049
-
1050
- // Check if our nonce is set.
1051
- if(!trim($wpnonce)) $this->response(array('success'=>0, 'code'=>'NONCE_MISSING'));
1052
-
1053
- // Verify that the nonce is valid.
1054
- if(!wp_verify_nonce($wpnonce, 'mec_options_form')) $this->response(array('success'=>0, 'code'=>'NONCE_IS_INVALID'));
1055
-
1056
- // Get mec options
1057
- $mec = $request->getVar('mec', array());
1058
-
1059
- $filtered = array();
1060
- foreach($mec as $key=>$value) $filtered[$key] = (is_array($value) ? $value : array());
1061
-
1062
- // Get current MEC options
1063
- $current = get_option('mec_options', array());
1064
- if(is_string($current) and trim($current) == '') $current = array();
1065
-
1066
- // Validations
1067
- if(isset($filtered['settings']) and isset($filtered['settings']['slug'])) $filtered['settings']['slug'] = strtolower(str_replace(' ', '-', $filtered['settings']['slug']));
1068
- if(isset($filtered['settings']) and isset($filtered['settings']['category_slug'])) $filtered['settings']['category_slug'] = strtolower(str_replace(' ', '-', $filtered['settings']['category_slug']));
1069
- if(isset($filtered['settings']) and isset($filtered['settings']['custom_archive'])) $filtered['settings']['custom_archive'] = isset($filtered['settings']['custom_archive']) ? str_replace('\"','"',$filtered['settings']['custom_archive']) : '';
1070
-
1071
- if(isset($mec['reg_fields']) and !is_array($mec['reg_fields'])) $mec['reg_fields'] = array();
1072
- if(isset($current['reg_fields']) and isset($mec['reg_fields']) and count($current['reg_fields']) != count($mec['reg_fields']))
1073
- {
1074
- $current['reg_fields'] = array();
1075
- $current['reg_fields'] = $mec['reg_fields'];
1076
- }
1077
-
1078
- // Generate New Options
1079
- $final = $current;
1080
-
1081
- // Merge new options with previous options
1082
- foreach($filtered as $key=>$value)
1083
- {
1084
- if(is_array($value))
1085
- {
1086
- foreach($value as $k=>$v)
1087
- {
1088
- // Define New Array
1089
- if(!isset($final[$key])) $final[$key] = array();
1090
-
1091
- // Overwrite Old Value
1092
- $final[$key][$k] = $v;
1093
- }
1094
- }
1095
- // Overwrite Old Value
1096
- else $final[$key] = $value;
1097
- }
1098
-
1099
- // MEC Save Options
1100
- do_action('mec_save_options', $final);
1101
-
1102
- // Save final options
1103
- update_option('mec_options', $final);
1104
-
1105
- // Refresh WordPress rewrite rules
1106
- $this->flush_rewrite_rules();
1107
-
1108
- // Print the response
1109
- $this->response(array('success'=>1));
1110
- }
1111
-
1112
- /**
1113
- * Saves MEC Notifications
1114
- * @author Webnus <info@webnus.biz>
1115
- */
1116
- public function save_notifications()
1117
- {
1118
- // MEC Request library
1119
- $request = $this->getRequest();
1120
-
1121
- // Get mec options
1122
- $mec = $request->getVar('mec', 'POST');
1123
- $notifications = isset($mec['notifications']) ? $mec['notifications'] : array();
1124
-
1125
- // Get current MEC notifications
1126
- $current = $this->get_notifications();
1127
- if(is_string($current) and trim($current) == '') $current = array();
1128
-
1129
- // Merge new options with previous options
1130
- $final_notifications = array();
1131
- $final_notifications['notifications'] = array_merge($current, $notifications);
1132
-
1133
- // Get current MEC options
1134
- $options = get_option('mec_options', array());
1135
- if(is_string($options) and trim($options) == '') $options = array();
1136
-
1137
- // Merge new options with previous options
1138
- $final = array_merge($options, $final_notifications);
1139
-
1140
- // Save final options
1141
- update_option('mec_options', $final);
1142
-
1143
- // Print the response
1144
- $this->response(array('success'=>1));
1145
- }
1146
-
1147
- /**
1148
- * Saves MEC Import/Export options
1149
- * @author Webnus <info@webnus.biz>
1150
- */
1151
- public function save_ix_options($ix_options = array())
1152
- {
1153
- // Get current MEC ix options
1154
- $current = $this->get_ix_options();
1155
- if(is_string($current) and trim($current) == '') $current = array();
1156
-
1157
- // Merge new options with previous options
1158
- $final_ix = array();
1159
- $final_ix['ix'] = array_merge($current, $ix_options);
1160
-
1161
- // Get current MEC options
1162
- $options = get_option('mec_options', array());
1163
- if(is_string($options) and trim($options) == '') $options = array();
1164
-
1165
- // Merge new options with previous options
1166
- $final = array_merge($options, $final_ix);
1167
-
1168
- // Save final options
1169
- update_option('mec_options', $final);
1170
-
1171
- return true;
1172
- }
1173
-
1174
- /**
1175
- * Get first day of week from WordPress
1176
- * @author Webnus <info@webnus.biz>
1177
- * @return int
1178
- */
1179
- public function get_first_day_of_week()
1180
- {
1181
- return get_option('start_of_week', 1);
1182
- }
1183
-
1184
- /**
1185
- * @author Webnus <info@webnus.biz>
1186
- * @param array $response
1187
- * @return void
1188
- */
1189
- public function response($response)
1190
- {
1191
- echo json_encode($response);
1192
- exit;
1193
- }
1194
-
1195
- /**
1196
- * Check if a date passed or not
1197
- * @author Webnus <info@webnus.biz>
1198
- * @param mixed $end
1199
- * @param mixed $now
1200
- * @return int
1201
- */
1202
- public function is_past($end, $now)
1203
- {
1204
- if(!is_numeric($end)) $end = strtotime($end);
1205
- if(!is_numeric($now)) $now = strtotime($now);
1206
-
1207
- // Never End
1208
- if($end <= 0) return 0;
1209
-
1210
- return (int) ($now > $end);
1211
- }
1212
-
1213
- /**
1214
- * @author Webnus <info@webnus.biz>
1215
- * @param int $id
1216
- * @return string
1217
- */
1218
- public function get_weekday_name_by_day_id($id)
1219
- {
1220
- // These names will be used in PHP functions so they mustn't translate
1221
- $days = array(1=>'Monday', 2=>'Tuesday', 3=>'Wednesday', 4=>'Thursday', 5=>'Friday', 6=>'Saturday', 7=>'Sunday');
1222
- return $days[$id];
1223
- }
1224
-
1225
- /**
1226
- * Spilts 2 dates to weeks
1227
- * @author Webnus <info@webnus.biz>
1228
- * @param DateTime|String $start
1229
- * @param DateTime|String $end
1230
- * @param int $first_day_of_week
1231
- * @return array
1232
- */
1233
- public function split_to_weeks($start, $end, $first_day_of_week = NULL)
1234
- {
1235
- if(is_null($first_day_of_week)) $first_day_of_week = $this->get_first_day_of_week();
1236
-
1237
- $end_day_of_week = ($first_day_of_week-1 >= 0) ? $first_day_of_week-1 : 6;
1238
-
1239
- $start_time = strtotime($start);
1240
- $end_time = strtotime($end);
1241
-
1242
- $start = new DateTime(date('Y-m-d', $start_time));
1243
- $end = new DateTime(date('Y-m-d 23:59', $end_time));
1244
-
1245
- $interval = new DateInterval('P1D');
1246
- $dateRange = new DatePeriod($start, $interval, $end);
1247
-
1248
- $weekday = 0;
1249
- $weekNumber = 1;
1250
- $weeks = array();
1251
- foreach($dateRange as $date)
1252
- {
1253
- // Fix the PHP notice
1254
- if(!isset($weeks[$weekNumber])) $weeks[$weekNumber] = array();
1255
-
1256
- // It's first week and the week is not started from first weekday
1257
- if($weekNumber == 1 and $weekday == 0 and $date->format('w') != $first_day_of_week)
1258
- {
1259
- $remained_days = $date->format('w');
1260
-
1261
- if($first_day_of_week == 0) $remained_days = $date->format('w'); // Sunday
1262
- elseif($first_day_of_week == 1) // Monday
1263
- {
1264
- if($remained_days != 0) $remained_days = $remained_days - 1;
1265
- else $remained_days = 6;
1266
- }
1267
- elseif($first_day_of_week == 6) // Saturday
1268
- {
1269
- if($remained_days != 6) $remained_days = $remained_days + 1;
1270
- else $remained_days = 0;
1271
- }
1272
- elseif($first_day_of_week == 5) // Friday
1273
- {
1274
- if($remained_days < 4) $remained_days = $remained_days + 2;
1275
- elseif($remained_days == 5) $remained_days = 0;
1276
- elseif($remained_days == 6) $remained_days = 1;
1277
- }
1278
-
1279
- $interval = new DateInterval('P'.$remained_days.'D');
1280
- $interval->invert = 1;
1281
- $date->add($interval);
1282
-
1283
- for($i = $remained_days; $i > 0; $i--)
1284
- {
1285
- $weeks[$weekNumber][] = $date->format('Y-m-d');
1286
- $date->add(new DateInterval('P1D'));
1287
- }
1288
- }
1289
-
1290
- $weeks[$weekNumber][] = $date->format('Y-m-d');
1291
- $weekday++;
1292
-
1293
- if($date->format('w') == $end_day_of_week)
1294
- {
1295
- $weekNumber++;
1296
- $weekday = 0;
1297
- }
1298
- }
1299
-
1300
- // Month is finished but week is not finished
1301
- if($weekday > 0 and $weekday < 7)
1302
- {
1303
- $remained_days = (6 - $weekday);
1304
- for($i = 0; $i <= $remained_days; $i++)
1305
- {
1306
- $date->add(new DateInterval('P1D'));
1307
- $weeks[$weekNumber][] = $date->format('Y-m-d');
1308
- }
1309
- }
1310
-
1311
- return $weeks;
1312
- }
1313
-
1314
- /**
1315
- * Returns MEC Container Width
1316
- * @author Webnus <info@webnus.biz>
1317
- * @return array
1318
- */
1319
- public function get_container_width()
1320
- {
1321
- $settings = $this->get_settings();
1322
- $container_width = (isset($settings['container_width']) and trim($settings['container_width']) != '') ? $settings['container_width'] : '';
1323
- update_option('mec_container_width', $container_width);
1324
- }
1325
-
1326
- /**
1327
- * Returns MEC colors
1328
- * @author Webnus <info@webnus.biz>
1329
- * @return array
1330
- */
1331
- public function get_available_colors()
1332
- {
1333
- $colors = get_option('mec_colors', $this->get_default_colors());
1334
- return apply_filters('mec_available_colors', $colors);
1335
- }
1336
-
1337
- /**
1338
- * Returns MEC default colors
1339
- * @author Webnus <info@webnus.biz>
1340
- * @return array
1341
- */
1342
- public function get_default_colors()
1343
- {
1344
- return apply_filters('mec_default_colors', array('fdd700','00a0d2','e14d43','dd823b','a3b745'));
1345
- }
1346
-
1347
- /**
1348
- * Add a new color to MEC available colors
1349
- * @author Webnus <info@webnus.biz>
1350
- * @param string $color
1351
- */
1352
- public function add_to_available_colors($color)
1353
- {
1354
- $colors = $this->get_available_colors();
1355
- $colors[] = $color;
1356
-
1357
- $colors = array_unique($colors);
1358
- update_option('mec_colors', $colors);
1359
- }
1360
-
1361
- /**
1362
- * Returns available googlemap styles
1363
- * @author Webnus <info@webnus.biz>
1364
- * @return array
1365
- */
1366
- public function get_googlemap_styles()
1367
- {
1368
- $styles = array(
1369
- array('key'=>'light-dream.json', 'name'=>'Light Dream'),
1370
- array('key'=>'intown-map.json', 'name'=>'inTown Map'),
1371
- array('key'=>'midnight.json', 'name'=>'Midnight'),
1372
- array('key'=>'pale-down.json', 'name'=>'Pale Down'),
1373
- array('key'=>'blue-essence.json', 'name'=>'Blue Essence'),
1374
- array('key'=>'blue-water.json', 'name'=>'Blue Water'),
1375
- array('key'=>'apple-maps-esque.json', 'name'=>'Apple Maps Esque'),
1376
- array('key'=>'CDO.json', 'name'=>'CDO'),
1377
- array('key'=>'shades-of-grey.json', 'name'=>'Shades of Grey'),
1378
- array('key'=>'subtle-grayscale.json', 'name'=>'Subtle Grayscale'),
1379
- array('key'=>'ultra-light.json', 'name'=>'Ultra Light'),
1380
- array('key'=>'facebook.json', 'name'=>'Facebook'),
1381
- );
1382
-
1383
- return apply_filters('mec_googlemap_styles', $styles);
1384
- }
1385
-
1386
- /**
1387
- * Filters provided google map styles
1388
- * @author Webnus <info@webnus.biz>
1389
- * @param string $style
1390
- * @return string
1391
- */
1392
- public function get_googlemap_style($style)
1393
- {
1394
- return apply_filters('mec_get_googlemap_style', $style);
1395
- }
1396
-
1397
- /**
1398
- * Fetchs googlemap styles from file
1399
- * @author Webnus <info@webnus.biz>
1400
- * @param string $style
1401
- * @return string
1402
- */
1403
- public function fetch_googlemap_style($style)
1404
- {
1405
- $path = $this->get_plugin_path().'app'.DS.'modules'.DS.'googlemap'.DS.'styles'.DS.$style;
1406
-
1407
- // MEC file library
1408
- $file = $this->getFile();
1409
-
1410
- if($file->exists($path)) return trim($file->read($path));
1411
- else return '';
1412
- }
1413
-
1414
- /**
1415
- * Get marker infowindow for showing on the map
1416
- * @author Webnus <info@webnus.biz>
1417
- * @param array $marker
1418
- * @return string
1419
- */
1420
- public function get_marker_infowindow($marker)
1421
- {
1422
- $count = count($marker['event_ids']);
1423
-
1424
- $content = '
1425
- <div class="mec-marker-infowindow-wp">
1426
- <div class="mec-marker-infowindow-count">'.$count.'</div>
1427
- <div class="mec-marker-infowindow-content">
1428
- <span>'.($count > 1 ? __('Events at this location', 'modern-events-calendar-lite') : __('Event at this location', 'modern-events-calendar-lite')).'</span>
1429
- <span>'.(trim($marker['address']) ? $marker['address'] : $marker['name']).'</span>
1430
- </div>
1431
- </div>';
1432
-
1433
- return apply_filters('mec_get_marker_infowindow', $content);
1434
- }
1435
-
1436
- /**
1437
- * Get marker Lightbox for showing on the map
1438
- * @author Webnus <info@webnus.biz>
1439
- * @param object $event
1440
- * @param string $date_format
1441
- * @return string
1442
- */
1443
- public function get_marker_lightbox($event, $date_format = 'M d Y')
1444
- {
1445
- // $infowindow_thumb = trim($event->data->thumbnails['thumbnail']) ? '<div class="mec-event-image">'.$event->data->thumbnails['thumbnail'].'</div>' : '';
1446
- $infowindow_thumb = trim($event->data->featured_image['thumbnail']) ? '<div class="mec-event-image"><img src="'.$event->data->featured_image['thumbnail'].'" alt="'.$event->data->title.'" /></div>' : '';
1447
-
1448
- $content = '
1449
- <div class="mec-wrap">
1450
- <div class="mec-map-lightbox-wp mec-event-list-classic">
1451
- <article class="'.((isset($event->data->meta['event_past']) and trim($event->data->meta['event_past'])) ? 'mec-past-event ' : '').'mec-event-article mec-clear">
1452
- '.$infowindow_thumb.'
1453
- <a data-event-id="'.$event->data->ID.'" href="'.$this->get_event_date_permalink($event->data->permalink, $event->date['start']['date']).'"><div class="mec-event-date mec-color"><i class="mec-sl-calendar"></i> '.$this->date_label((isset($event->date['start']) ? $event->date['start'] : NULL), (isset($event->date['end']) ? $event->date['end'] : NULL), $date_format).'</div></a>
1454
- <h4 class="mec-event-title"><a data-event-id="'.$event->data->ID.'" class="mec-color-hover" href="'.$this->get_event_date_permalink($event->data->permalink, (isset($event->date['start']) ? $event->date['start']['date'] : NULL)).'">'.$event->data->title.'</a></h4>
1455
- </article>
1456
- </div>
1457
- </div>';
1458
-
1459
- return apply_filters('mec_get_marker_lightbox', $content);
1460
- }
1461
-
1462
- /**
1463
- * Returns available social networks
1464
- * @author Webnus <info@webnus.biz>
1465
- * @return array
1466
- */
1467
- public function get_social_networks()
1468
- {
1469
- $social_networks = array(
1470
- 'facebook'=>array('id'=>'facebook', 'name'=>__('Facebook', 'modern-events-calendar-lite'), 'function'=>array($this, 'sn_facebook')),
1471
- 'twitter'=>array('id'=>'twitter', 'name'=>__('Twitter', 'modern-events-calendar-lite'), 'function'=>array($this, 'sn_twitter')),
1472
- 'linkedin'=>array('id'=>'linkedin', 'name'=>__('Linkedin', 'modern-events-calendar-lite'), 'function'=>array($this, 'sn_linkedin')),
1473
- 'vk'=>array('id'=>'vk', 'name'=>__('VK', 'modern-events-calendar-lite'), 'function'=>array($this, 'sn_vk')),
1474
- 'email'=>array('id'=>'email', 'name'=>__('Email', 'modern-events-calendar-lite'), 'function'=>array($this, 'sn_email')),
1475
- );
1476
-
1477
- return apply_filters('mec_social_networks', $social_networks);
1478
- }
1479
-
1480
- /**
1481
- * Do facebook link for social networks
1482
- * @author Webnus <info@webnus.biz>
1483
- * @param string $url
1484
- * @param object $event
1485
- * @return string
1486
- */
1487
- public function sn_facebook($url, $event)
1488
- {
1489
- $occurrence = (isset($_GET['occurrence']) ? sanitize_text_field($_GET['occurrence']) : '');
1490
- if(trim($occurrence) != '') $url = $this->add_qs_var('occurrence', $occurrence, $url);
1491
-
1492
- return '<li class="mec-event-social-icon"><a class="facebook" href="https://www.facebook.com/sharer/sharer.php?u='.rawurlencode($url).'" onclick="javascript:window.open(this.href, \'\', \'menubar=no,toolbar=no,resizable=yes,scrollbars=yes,height=500,width=600\'); return false;" title="'.__('Share on Facebook', 'modern-events-calendar-lite').'"><i class="mec-fa-facebook"></i></a></li>';
1493
- }
1494
-
1495
- /**
1496
- * Do twitter link for social networks
1497
- * @author Webnus <info@webnus.biz>
1498
- * @param string $url
1499
- * @param object $event
1500
- * @return string
1501
- */
1502
- public function sn_twitter($url, $event)
1503
- {
1504
- $occurrence = (isset($_GET['occurrence']) ? sanitize_text_field($_GET['occurrence']) : '');
1505
- if(trim($occurrence) != '') $url = $this->add_qs_var('occurrence', $occurrence, $url);
1506
-
1507
- return '<li class="mec-event-social-icon"><a class="twitter" href="https://twitter.com/share?url='.rawurlencode($url).'" onclick="javascript:window.open(this.href, \'\', \'menubar=no,toolbar=no,resizable=yes,scrollbars=yes,height=600,width=500\'); return false;" target="_blank" title="'.__('Tweet', 'modern-events-calendar-lite').'"><i class="mec-fa-twitter"></i></a></li>';
1508
- }
1509
-
1510
- /**
1511
- * Do linkedin link for social networks
1512
- * @author Webnus <info@webnus.biz>
1513
- * @param string $url
1514
- * @param object $event
1515
- * @return string
1516
- */
1517
- public function sn_linkedin($url, $event)
1518
- {
1519
- $occurrence = (isset($_GET['occurrence']) ? sanitize_text_field($_GET['occurrence']) : '');
1520
- if(trim($occurrence) != '') $url = $this->add_qs_var('occurrence', $occurrence, $url);
1521
-
1522
- return '<li class="mec-event-social-icon"><a class="linkedin" href="https://www.linkedin.com/shareArticle?mini=true&url='.rawurlencode($url).'" onclick="javascript:window.open(this.href, \'\', \'menubar=no,toolbar=no,resizable=yes,scrollbars=yes,height=600,width=500\'); return false;" target="_blank" title="'.__('Linkedin', 'modern-events-calendar-lite').'"><i class="mec-fa-linkedin"></i></a></li>';
1523
- }
1524
-
1525
- /**
1526
- * Do email link for social networks
1527
- * @author Webnus <info@webnus.biz>
1528
- * @param string $url
1529
- * @param object $event
1530
- * @return string
1531
- */
1532
- public function sn_email($url, $event)
1533
- {
1534
- $occurrence = (isset($_GET['occurrence']) ? sanitize_text_field($_GET['occurrence']) : '');
1535
- if(trim($occurrence) != '') $url = $this->add_qs_var('occurrence', $occurrence, $url);
1536
-
1537
- $event->data->title = str_replace('&#8211;', '-', $event->data->title);
1538
- $event->data->title = str_replace('&#8221;', '’’', $event->data->title);
1539
- $event->data->title = str_replace('&#8217;', "’", $event->data->title);
1540
- $event->data->title = str_replace('&', '%26', $event->data->title);
1541
- $event->data->title = str_replace('#038;', '', $event->data->title);
1542
-
1543
- return '<li class="mec-event-social-icon"><a class="email" href="mailto:?subject='.wp_specialchars_decode($event->data->title).'&body='.rawurlencode($url).'" title="'.__('Email', 'modern-events-calendar-lite').'"><i class="mec-fa-envelope"></i></a></li>';
1544
- }
1545
-
1546
- /**
1547
- * Do VK link for social networks
1548
- * @author Webnus <info@webnus.biz>
1549
- * @param string $url
1550
- * @param object $event
1551
- * @return string
1552
- */
1553
- public function sn_vk($url, $event)
1554
- {
1555
- $occurrence = (isset($_GET['occurrence']) ? sanitize_text_field($_GET['occurrence']) : '');
1556
- if(trim($occurrence) != '') $url = $this->add_qs_var('occurrence', $occurrence, $url);
1557
-
1558
- return '<li class="mec-event-social-icon"><a class="vk" href=" http://vk.com/share.php?url='.rawurlencode($url).'" title="'.__('VK', 'modern-events-calendar-lite').'" target="_blank"><i class="mec-fa-vk"></i></a></li>';
1559
- }
1560
-
1561
- /**
1562
- * Get available skins for archive page
1563
- * @author Webnus <info@webnus.biz>
1564
- * @return array
1565
- */
1566
- public function get_archive_skins()
1567
- {
1568
- $archive_skins = array(
1569
- array('skin'=>'full_calendar', 'name'=>__('Full Calendar', 'modern-events-calendar-lite')),
1570
- array('skin'=>'yearly_view', 'name'=>__('Yearly View', 'modern-events-calendar-lite')),
1571
- array('skin'=>'monthly_view', 'name'=>__('Calendar/Monthly View', 'modern-events-calendar-lite')),
1572
- array('skin'=>'weekly_view', 'name'=>__('Weekly View', 'modern-events-calendar-lite')),
1573
- array('skin'=>'daily_view', 'name'=>__('Daily View', 'modern-events-calendar-lite')),
1574
- array('skin'=>'timetable', 'name'=>__('Timetable View', 'modern-events-calendar-lite')),
1575
- array('skin'=>'masonry', 'name'=>__('Masonry View', 'modern-events-calendar-lite')),
1576
- array('skin'=>'list', 'name'=>__('List View', 'modern-events-calendar-lite')),
1577
- array('skin'=>'grid', 'name'=>__('Grid View', 'modern-events-calendar-lite')),
1578
- array('skin'=>'agenda', 'name'=>__('Agenda View', 'modern-events-calendar-lite')),
1579
- array('skin'=>'map', 'name'=>__('Map View', 'modern-events-calendar-lite')),
1580
- array('skin'=>'custom', 'name'=>__('Custom Shortcode', 'modern-events-calendar-lite')),
1581
- );
1582
-
1583
- return apply_filters('mec_archive_skins', $archive_skins);
1584
- }
1585
-
1586
- /**
1587
- * Get available skins for archive page
1588
- * @author Webnus <info@webnus.biz>
1589
- * @return array
1590
- */
1591
- public function get_category_skins()
1592
- {
1593
- $category_skins = array(
1594
- array('skin'=>'full_calendar', 'name'=>__('Full Calendar', 'modern-events-calendar-lite')),
1595
- array('skin'=>'yearly_view', 'name'=>__('Yearly View', 'modern-events-calendar-lite')),
1596
- array('skin'=>'monthly_view', 'name'=>__('Calendar/Monthly View', 'modern-events-calendar-lite')),
1597
- array('skin'=>'weekly_view', 'name'=>__('Weekly View', 'modern-events-calendar-lite')),
1598
- array('skin'=>'daily_view', 'name'=>__('Daily View', 'modern-events-calendar-lite')),
1599
- array('skin'=>'timetable', 'name'=>__('Timetable View', 'modern-events-calendar-lite')),
1600
- array('skin'=>'masonry', 'name'=>__('Masonry View', 'modern-events-calendar-lite')),
1601
- array('skin'=>'list', 'name'=>__('List View', 'modern-events-calendar-lite')),
1602
- array('skin'=>'grid', 'name'=>__('Grid View', 'modern-events-calendar-lite')),
1603
- array('skin'=>'agenda', 'name'=>__('Agenda View', 'modern-events-calendar-lite')),
1604
- array('skin'=>'map', 'name'=>__('Map View', 'modern-events-calendar-lite')),
1605
- );
1606
-
1607
- return apply_filters('mec_category_skins', $category_skins);
1608
- }
1609
-
1610
- /**
1611
- * Get events posts
1612
- * @author Webnus <info@webnus.biz>
1613
- * @param int $limit
1614
- * @return array list of posts
1615
- */
1616
- public function get_events($limit = -1)
1617
- {
1618
- return get_posts(array('post_type'=>$this->get_main_post_type(), 'posts_per_page'=>$limit, 'post_status'=>'publish'));
1619
- }
1620
-
1621
- /**
1622
- * Get method of showing for multiple days events
1623
- * @author Webnus <info@webnus.biz>
1624
- * @return string
1625
- */
1626
- public function get_multiple_days_method()
1627
- {
1628
- $settings = $this->get_settings();
1629
-
1630
- $method = isset($settings['multiple_day_show_method']) ? $settings['multiple_day_show_method'] : 'first_day_listgrid';
1631
- return apply_filters('mec_multiple_days_method', $method);
1632
- }
1633
-
1634
- /**
1635
- * Get method of showing/hiding events based on event time
1636
- * @author Webnus <info@webnus.biz>
1637
- * @return string
1638
- */
1639
- public function get_hide_time_method()
1640
- {
1641
- $settings = $this->get_settings();
1642
-
1643
- $method = isset($settings['hide_time_method']) ? $settings['hide_time_method'] : 'start';
1644
- return apply_filters('mec_hide_time_method', $method);
1645
- }
1646
-
1647
- /**
1648
- * Get hour format of MEC
1649
- * @author Webnus <info@webnus.biz>
1650
- * @return int|string
1651
- */
1652
- public function get_hour_format()
1653
- {
1654
- $settings = $this->get_settings();
1655
-
1656
- $format = isset($settings['time_format']) ? $settings['time_format'] : 12;
1657
- return apply_filters('mec_hour_format', $format);
1658
- }
1659
-
1660
- /**
1661
- * Get formatted hour based on configurations
1662
- * @author Webnus <info@webnus.biz>
1663
- * @param int $hour
1664
- * @param int $minutes
1665
- * @param string $ampm
1666
- * @return string
1667
- */
1668
- public function get_formatted_hour($hour, $minutes, $ampm)
1669
- {
1670
- // Hour Format of MEC (12/24)
1671
- $hour_format = $this->get_hour_format();
1672
-
1673
- $formatted = '';
1674
- if($hour_format == '12')
1675
- {
1676
- $formatted = sprintf("%02d", $hour).':'.sprintf("%02d", $minutes).' '.__($ampm, 'modern-events-calendar-lite');
1677
- }
1678
- elseif($hour_format == '24')
1679
- {
1680
- if(strtoupper($ampm) == 'PM' and $hour != 12) $hour += 12;
1681
- if(strtoupper($ampm) == 'AM' and $hour == 12) $hour += 12;
1682
-
1683
- $formatted = sprintf("%02d", $hour).':'.sprintf("%02d", $minutes);
1684
- }
1685
-
1686
- return $formatted;
1687
- }
1688
-
1689
- /**
1690
- * Get formatted time based on WordPress Time Format
1691
- * @author Webnus <info@webnus.biz>
1692
- * @param int $seconds
1693
- * @return string
1694
- */
1695
- public function get_time($seconds)
1696
- {
1697
- $format = get_option('time_format');
1698
- return gmdate($format, $seconds);
1699
- }
1700
-
1701
- /**
1702
- * Renders a module such as links or googlemap
1703
- * @author Webnus <info@webnus.biz>
1704
- * @param string $module
1705
- * @param array $params
1706
- * @return string
1707
- */
1708
- public function module($module, $params = array())
1709
- {
1710
- // Get module path
1711
- $path = MEC::import('app.modules.'.$module, true, true);
1712
-
1713
- // MEC libraries
1714
- $render = $this->getRender();
1715
- $factory = $this->getFactory();
1716
-
1717
- // Extract Module Params
1718
- extract($params);
1719
-
1720
- ob_start();
1721
- include $path;
1722
- return $output = ob_get_clean();
1723
- }
1724
-
1725
- /**
1726
- * Returns MEC currencies
1727
- * @author Webnus <info@webnus.biz>
1728
- * @return array
1729
- */
1730
- public function get_currencies()
1731
- {
1732
- $currencies = array(
1733
- '$'=>'USD',
1734
- '€'=>'EUR',
1735
- '£'=>'GBP',
1736
- 'CHF'=>'CHF',
1737
- 'CAD'=>'CAD',
1738
- 'AUD'=>'AUD',
1739
- 'JPY'=>'JPY',
1740
- 'SEK'=>'SEK',
1741
- 'GEL'=>'GEL',
1742
- 'AFN'=>'AFN',
1743
- 'ALL'=>'ALL',
1744
- 'DZD'=>'DZD',
1745
- 'AOA'=>'AOA',
1746
- 'ARS'=>'ARS',
1747
- 'AMD'=>'AMD',
1748
- 'AWG'=>'AWG',
1749
- 'AZN'=>'AZN',
1750
- 'BSD'=>'BSD',
1751
- 'BHD'=>'BHD',
1752
- 'BBD'=>'BBD',
1753
- 'BYR'=>'BYR',
1754
- 'BZD'=>'BZD',
1755
- 'BMD'=>'BMD',
1756
- 'BTN'=>'BTN',
1757
- 'BOB'=>'BOB',
1758
- 'BAM'=>'BAM',
1759
- 'BWP'=>'BWP',
1760
- 'BRL'=>'BRL',
1761
- 'BND'=>'BND',
1762
- 'BGN'=>'BGN',
1763
- 'BIF'=>'BIF',
1764
- 'KHR'=>'KHR',
1765
- 'CVE'=>'CVE',
1766
- 'KYD'=>'KYD',
1767
- 'XAF'=>'XAF',
1768
- 'CLP'=>'CLP',
1769
- 'COP'=>'COP',
1770
- 'KMF'=>'KMF',
1771
- 'CDF'=>'CDF',
1772
- 'NZD'=>'NZD',
1773
- 'CRC'=>'CRC',
1774
- 'HRK'=>'HRK',
1775
- 'CUC'=>'CUC',
1776
- 'CUP'=>'CUP',
1777
- 'CZK'=>'CZK',
1778
- 'DKK'=>'DKK',
1779
- 'DJF'=>'DJF',
1780
- 'DOP'=>'DOP',
1781
- 'XCD'=>'XCD',
1782
- 'EGP'=>'EGP',
1783
- 'ERN'=>'ERN',
1784
- 'EEK'=>'EEK',
1785
- 'ETB'=>'ETB',
1786
- 'FKP'=>'FKP',
1787
- 'FJD'=>'FJD',
1788
- 'GMD'=>'GMD',
1789
- 'GHS'=>'GHS',
1790
- 'GIP'=>'GIP',
1791
- 'GTQ'=>'GTQ',
1792
- 'GNF'=>'GNF',
1793
- 'GYD'=>'GYD',
1794
- 'HTG'=>'HTG',
1795
- 'HNL'=>'HNL',
1796
- 'HKD'=>'HKD',
1797
- 'HUF'=>'HUF',
1798
- 'ISK'=>'ISK',
1799
- 'INR'=>'INR',
1800
- 'IDR'=>'IDR',
1801
- 'IRR'=>'IRR',
1802
- 'IQD'=>'IQD',
1803
- 'ILS'=>'ILS',
1804
- 'JMD'=>'JMD',
1805
- 'JOD'=>'JOD',
1806
- 'KZT'=>'KZT',
1807
- 'KES'=>'KES',
1808
- 'KWD'=>'KWD',
1809
- 'KGS'=>'KGS',
1810
- 'LAK'=>'LAK',
1811
- 'LVL'=>'LVL',
1812
- 'LBP'=>'LBP',
1813
- 'LSL'=>'LSL',
1814
- 'LRD'=>'LRD',
1815
- 'LYD'=>'LYD',
1816
- 'LTL'=>'LTL',
1817
- 'MOP'=>'MOP',
1818
- 'MKD'=>'MKD',
1819
- 'MGA'=>'MGA',
1820
- 'MWK'=>'MWK',
1821
- 'MYR'=>'MYR',
1822
- 'MVR'=>'MVR',
1823
- 'MRO'=>'MRO',
1824
- 'MUR'=>'MUR',
1825
- 'MXN'=>'MXN',
1826
- 'MDL'=>'MDL',
1827
- 'MNT'=>'MNT',
1828
- 'MAD'=>'MAD',
1829
- 'MZN'=>'MZN',
1830
- 'MMK'=>'MMK',
1831
- 'NAD'=>'NAD',
1832
- 'NPR'=>'NPR',
1833
- 'ANG'=>'ANG',
1834
- 'TWD'=>'TWD',
1835
- 'NIO'=>'NIO',
1836
- 'NGN'=>'NGN',
1837
- 'KPW'=>'KPW',
1838
- 'NOK'=>'NOK',
1839
- 'OMR'=>'OMR',
1840
- 'PKR'=>'PKR',
1841
- 'PAB'=>'PAB',
1842
- 'PGK'=>'PGK',
1843
- 'PYG'=>'PYG',
1844
- 'PEN'=>'PEN',
1845
- 'PHP'=>'PHP',
1846
- 'PLN'=>'PLN',
1847
- 'QAR'=>'QAR',
1848
- 'CNY'=>'CNY',
1849
- 'RON'=>'RON',
1850
- 'RUB'=>'RUB',
1851
- 'RWF'=>'RWF',
1852
- 'SHP'=>'SHP',
1853
- 'SVC'=>'SVC',
1854
- 'WST'=>'WST',
1855
- 'SAR'=>'SAR',
1856
- 'RSD'=>'RSD',
1857
- 'SCR'=>'SCR',
1858
- 'SLL'=>'SLL',
1859
- 'SGD'=>'SGD',
1860
- 'SBD'=>'SBD',
1861
- 'SOS'=>'SOS',
1862
- 'ZAR'=>'ZAR',
1863
- 'KRW'=>'KRW',
1864
- 'LKR'=>'LKR',
1865
- 'SDG'=>'SDG',
1866
- 'SRD'=>'SRD',
1867
- 'SZL'=>'SZL',
1868
- 'SYP'=>'SYP',
1869
- 'STD'=>'STD',
1870
- 'TJS'=>'TJS',
1871
- 'TZS'=>'TZS',
1872
- 'THB'=>'THB',
1873
- 'TOP'=>'TOP',
1874
- 'PRB'=>'PRB',
1875
- 'TTD'=>'TTD',
1876
- 'TND'=>'TND',
1877
- 'TRY'=>'TRY',
1878
- 'TMT'=>'TMT',
1879
- 'TVD'=>'TVD',
1880
- 'UGX'=>'UGX',
1881
- 'UAH'=>'UAH',
1882
- 'AED'=>'AED',
1883
- 'UYU'=>'UYU',
1884
- 'UZS'=>'UZS',
1885
- 'VUV'=>'VUV',
1886
- 'VEF'=>'VEF',
1887
- 'VND'=>'VND',
1888
- 'XOF'=>'XOF',
1889
- 'YER'=>'YER',
1890
- 'ZMK'=>'ZMK',
1891
- 'ZWL'=>'ZWL',
1892
- );
1893
-
1894
- return apply_filters('mec_currencies', $currencies);
1895
- }
1896
-
1897
- /**
1898
- * Returns MEC version
1899
- * @author Webnus <info@webnus.biz>
1900
- * @return string
1901
- */
1902
- public function get_version()
1903
- {
1904
- return MEC_VERSION;
1905
- }
1906
-
1907
- /**
1908
- * Set endpoint vars to true
1909
- * @author Webnus <info@webnus.biz>
1910
- * @param array $vars
1911
- * @return boolean
1912
- */
1913
- public function filter_request($vars)
1914
- {
1915
- if(isset($vars['gateway-cancel'])) $vars['gateway-cancel'] = true;
1916
- if(isset($vars['gateway-return'])) $vars['gateway-return'] = true;
1917
- if(isset($vars['gateway-notify'])) $vars['gateway-notify'] = true;
1918
-
1919
- return $vars;
1920
- }
1921
-
1922
- /**
1923
- * Do the jobs after endpoints and show related output
1924
- * @author Webnus <info@webnus.biz>
1925
- * @return boolean
1926
- */
1927
- public function do_endpoints()
1928
- {
1929
- if(get_query_var('verify'))
1930
- {
1931
- $key = sanitize_text_field(get_query_var('verify'));
1932
-
1933
- $db = $this->getDB();
1934
- $book_id = $db->select("SELECT `post_id` FROM `#__postmeta` WHERE `meta_key`='mec_verification_key' AND `meta_value`='$key'", 'loadResult');
1935
-
1936
- if(!$book_id) return false;
1937
-
1938
- $status = get_post_meta($book_id, 'mec_verified', true);
1939
- if($status == '1')
1940
- {
1941
- echo '<p class="mec-success">'.__('Your booking already verified!', 'modern-events-calendar-lite').'</p>';
1942
- return false;
1943
- }
1944
-
1945
- $book = $this->getBook();
1946
- if($book->verify($book_id)) echo '<p class="mec-success">'.__('Your booking successfully verified.', 'modern-events-calendar-lite').'</p>';
1947
- else echo '<p class="mec-error">'.__('Your booking cannot verify!', 'modern-events-calendar-lite').'</p>';
1948
- }
1949
- elseif(get_query_var('cancel'))
1950
- {
1951
- $key = sanitize_text_field(get_query_var('cancel'));
1952
-
1953
- $db = $this->getDB();
1954
- $book_id = $db->select("SELECT `post_id` FROM `#__postmeta` WHERE `meta_key`='mec_cancellation_key' AND `meta_value`='$key'", 'loadResult');
1955
-
1956
- if(!$book_id) return false;
1957
-
1958
- $status = get_post_meta($book_id, 'mec_verified', true);
1959
- if($status == '-1')
1960
- {
1961
- echo '<p class="mec-error">'.__('Your booking already canceled!', 'modern-events-calendar-lite').'</p>';
1962
- return false;
1963
- }
1964
-
1965
- $book = $this->getBook();
1966
- if($book->cancel($book_id)) echo '<p class="mec-success">'.__('Your booking successfully canceled.', 'modern-events-calendar-lite').'</p>';
1967
- else echo '<p class="mec-error">'.__('Your booking cannot be canceled.', 'modern-events-calendar-lite').'</p>';
1968
- }
1969
- elseif(get_query_var('gateway-cancel'))
1970
- {
1971
- echo '<p class="mec-success">'.__('You canceled the payment successfully.', 'modern-events-calendar-lite').'</p>';
1972
- }
1973
- elseif(get_query_var('gateway-return'))
1974
- {
1975
- echo '<p class="mec-success">'.__('You returned from payment gateway successfully.', 'modern-events-calendar-lite').'</p>';
1976
- }
1977
- elseif(get_query_var('gateway-notify'))
1978
- {
1979
- // TODO
1980
- }
1981
- }
1982
-
1983
- public function booking_invoice()
1984
- {
1985
- // Booking Invoice
1986
- if(isset($_GET['method']) and sanitize_text_field($_GET['method']) == 'mec-invoice')
1987
- {
1988
- $settings = $this->get_settings();
1989
- if(isset($settings['booking_invoice']) and !$settings['booking_invoice'])
1990
- {
1991
- wp_die(__('Cannot find the invoice!', 'modern-events-calendar-lite'), __('Invoice is invalid.', 'modern-events-calendar-lite'));
1992
- exit;
1993
- }
1994
-
1995
- $transaction_id = sanitize_text_field($_GET['id']);
1996
-
1997
- // Libraries
1998
- $book = $this->getBook();
1999
- $render = $this->getRender();
2000
- $db = $this->getDB();
2001
-
2002
- $transaction = $book->get_transaction($transaction_id);
2003
- $event_id = isset($transaction['event_id']) ? $transaction['event_id'] : 0;
2004
-
2005
- // Dont Show PDF If Booking Confirmation Status Equals Pending
2006
- $book_id = $db->select("SELECT `post_id` FROM `#__postmeta` WHERE `meta_value`='".$transaction_id."' AND `meta_key`='mec_transaction_id'", 'loadResult');
2007
- $mec_confirmed = get_post_meta($book_id, 'mec_confirmed', true);
2008
-
2009
- if(!$mec_confirmed and (!current_user_can('administrator') and !current_user_can('editor')))
2010
- {
2011
- wp_die(__('Your booking still is not confirmed. You able download it after confirmation!', 'modern-events-calendar-lite'), __('Booking Not Confirmed.', 'modern-events-calendar-lite'));
2012
- exit;
2013
- }
2014
-
2015
- if(!$event_id)
2016
- {
2017
- wp_die(__('Cannot find the booking!', 'modern-events-calendar-lite'), __('Booking is invalid.', 'modern-events-calendar-lite'));
2018
- exit;
2019
- }
2020
-
2021
- $event = $render->data($event_id);
2022
-
2023
- $location_id = isset($event->meta['mec_location_id']) ? $event->meta['mec_location_id'] : 0;
2024
- $location = isset($event->locations[$location_id]) ? (trim($event->locations[$location_id]['address']) ? $event->locations[$location_id]['address'] : $event->locations[$location_id]['name']) : '';
2025
-
2026
- $dates = isset($transaction['date']) ? explode(':', $transaction['date']) : array(date('Y-m-d'), date('Y-m-d'));
2027
-
2028
- // Get Booking Post
2029
- $booking = $book->get_bookings_by_transaction_id($transaction_id);
2030
-
2031
- $booking_time = isset($booking[0]) ? get_post_meta($booking[0]->ID, 'mec_booking_time', true) : NULL;
2032
- if(!$booking_time) $booking_time = $dates[0];
2033
-
2034
- $booking_time = date('Y-m-d', strtotime($booking_time));
2035
-
2036
- // Include the tFPDF Class
2037
- if(!class_exists('tFPDF')) require_once MEC_ABSPATH.'app'.DS.'api'.DS.'TFPDF'.DS.'tfpdf.php';
2038
-
2039
- $pdf = new tFPDF();
2040
- $pdf->AddPage();
2041
-
2042
- // Add a Unicode font (uses UTF-8)
2043
- $pdf->AddFont('DejaVu', '', 'DejaVuSansCondensed.ttf', true);
2044
- $pdf->AddFont('DejaVuBold', '', 'DejaVuSansCondensed-Bold.ttf', true);
2045
-
2046
- $pdf->SetTitle(sprintf(__('%s Invoice', 'modern-events-calendar-lite'), $transaction_id));
2047
- $pdf->SetAuthor(get_bloginfo('name'), true);
2048
-
2049
- // Event Information
2050
- $pdf->SetFont('DejaVuBold', '', 18);
2051
- $pdf->Write(25, html_entity_decode(get_the_title($event->ID)));
2052
- $pdf->Ln();
2053
-
2054
- $pdf->SetFont('DejaVuBold', '', 12);
2055
- $pdf->Write(6, __('Location', 'modern-events-calendar-lite').': ');
2056
- $pdf->SetFont('DejaVu', '', 12);
2057
- $pdf->Write(6, $location);
2058
- $pdf->Ln();
2059
-
2060
- $pdf->SetFont('DejaVuBold', '', 12);
2061
- $pdf->Write(6, __('Date', 'modern-events-calendar-lite').': ');
2062
- $pdf->SetFont('DejaVu', '', 12);
2063
- $pdf->Write(6, trim($dates[0].' '.(isset($event->time['start']) ? $event->time['start'] : '').' - '.(($dates[0] != $dates[1]) ? $dates[1].' ' : '').(isset($event->time['end']) ? $event->time['end'] : ''), '- '));
2064
- $pdf->Ln();
2065
-
2066
- $pdf->SetFont('DejaVuBold', '', 12);
2067
- $pdf->Write(6, __('Transaction ID', 'modern-events-calendar-lite').': ');
2068
- $pdf->SetFont('DejaVu', '', 12);
2069
- $pdf->Write(6, $transaction_id);
2070
- $pdf->Ln();
2071
-
2072
- // Attendees
2073
- if(isset($transaction['tickets']) and is_array($transaction['tickets']) and count($transaction['tickets']))
2074
- {
2075
- $pdf->SetFont('DejaVuBold', '', 16);
2076
- $pdf->Write(20, __('Attendees', 'modern-events-calendar-lite'));
2077
- $pdf->Ln();
2078
-
2079
- $i = 1;
2080
- foreach($transaction['tickets'] as $attendee)
2081
- {
2082
- $pdf->SetFont('DejaVuBold', '', 12);
2083
- $pdf->Write(6, $attendee['name']);
2084
- $pdf->Ln();
2085
-
2086
- $pdf->SetFont('DejaVu', '', 10);
2087
- $pdf->Write(6, $attendee['email']);
2088
- $pdf->Ln();
2089
-
2090
- $pdf->Write(6, ((isset($event->tickets[$attendee['id']]) ? __($this->m('ticket', __('Ticket', 'modern-events-calendar-lite'))).': '.$event->tickets[$attendee['id']]['name'] : '').' '.(isset($event->tickets[$attendee['id']]) ? $book->get_ticket_price_label($event->tickets[$attendee['id']], $booking_time) : '')));
2091
-
2092
- // Ticket Variations
2093
- if(isset($attendee['variations']) and is_array($attendee['variations']) and count($attendee['variations']))
2094
- {
2095
- $ticket_variations = $this->ticket_variations($event_id);
2096
-
2097
- foreach($attendee['variations'] as $variation_id=>$variation_count)
2098
- {
2099
- if(!$variation_count or ($variation_count and $variation_count < 0)) continue;
2100
-
2101
- $variation_title = (isset($ticket_variations[$variation_id]) and isset($ticket_variations[$variation_id]['title'])) ? $ticket_variations[$variation_id]['title'] : '';
2102
- if(!trim($variation_title)) continue;
2103
-
2104
- $pdf->Ln();
2105
- $pdf->Write(6, '+ '.$variation_title.' ('.$variation_count.')');
2106
- }
2107
- }
2108
-
2109
- if($i != count($transaction['tickets'])) $pdf->Ln(12);
2110
- else $pdf->Ln();
2111
-
2112
- $i++;
2113
- }
2114
- }
2115
-
2116
- // Billing Information
2117
- if(isset($transaction['price_details']) and isset($transaction['price_details']['details']) and is_array($transaction['price_details']['details']) and count($transaction['price_details']['details']))
2118
- {
2119
- $pdf->SetFont('DejaVuBold', '', 16);
2120
- $pdf->Write(20, __('Billing', 'modern-events-calendar-lite'));
2121
- $pdf->Ln();
2122
-
2123
- $pdf->SetFont('DejaVu', '', 12);
2124
- foreach($transaction['price_details']['details'] as $price_row)
2125
- {
2126
- $pdf->Write(6, $price_row['description'].": ".$this->render_price($price_row['amount']));
2127
- $pdf->Ln();
2128
- }
2129
-
2130
- $pdf->SetFont('DejaVuBold', '', 12);
2131
- $pdf->Write(10, __('Total', 'modern-events-calendar-lite').': ');
2132
- $pdf->Write(10, $this->render_price($transaction['price']));
2133
- $pdf->Ln();
2134
- }
2135
-
2136
- $image = $this->module('qrcode.invoice', array('event'=>$event));
2137
- if(trim($image))
2138
- {
2139
- // QR Code
2140
- $pdf->SetX(-50);
2141
- $pdf->Image($image);
2142
- $pdf->Ln();
2143
- }
2144
-
2145
- $pdf->Output();
2146
- exit;
2147
- }
2148
- }
2149
-
2150
- /**
2151
- * Generates ical output
2152
- * @author Webnus <info@webnus.biz>
2153
- */
2154
- public function ical()
2155
- {
2156
- // ical export
2157
- if(isset($_GET['method']) and sanitize_text_field($_GET['method']) == 'ical')
2158
- {
2159
- $id = sanitize_text_field($_GET['id']);
2160
- $occurrence = isset($_GET['occurrence']) ? sanitize_text_field($_GET['occurrence']) : '';
2161
-
2162
- $events = $this->ical_single($id, $occurrence);
2163
- $ical_calendar = $this->ical_calendar($events);
2164
-
2165
- header('Content-type: application/force-download; charset=utf-8');
2166
- header('Content-Disposition: attachment; filename="mec-event-'.$id.'.ics"');
2167
-
2168
- echo $ical_calendar;
2169
- exit;
2170
- }
2171
- }
2172
-
2173
- /**
2174
- * Generates ical output in email
2175
- * @author Webnus <info@webnus.biz>
2176
- */
2177
- public function ical_email()
2178
- {
2179
- // ical export
2180
- if(isset($_GET['method']) and sanitize_text_field($_GET['method']) == 'ical-email')
2181
- {
2182
- $id = sanitize_text_field($_GET['id']);
2183
- $book_id = sanitize_text_field($_GET['book_id']);
2184
- $key = sanitize_text_field($_GET['key']);
2185
-
2186
- if($key != md5($book_id))
2187
- {
2188
- wp_die(__('Request is not valid.', 'modern-events-calendar-lite'), __('iCal export stopped!', 'modern-events-calendar-lite'), array('back_link'=>true));
2189
- exit;
2190
- }
2191
-
2192
- $occurrence = isset($_GET['occurrence']) ? sanitize_text_field($_GET['occurrence']) : '';
2193
-
2194
- $events = $this->ical_single_email($id, $book_id, $occurrence);
2195
- $ical_calendar = $this->ical_calendar($events);
2196
-
2197
- header('Content-type: application/force-download; charset=utf-8');
2198
- header('Content-Disposition: attachment; filename="mec-booking-'.$book_id.'.ics"');
2199
-
2200
- echo $ical_calendar;
2201
- exit;
2202
- }
2203
- }
2204
-
2205
- /**
2206
- * Returns the iCal URL of event
2207
- * @author Webnus <info@webnus.biz>
2208
- * @param $event_id
2209
- * @param string $occurrence
2210
- * @return string
2211
- */
2212
- public function ical_URL($event_id, $occurrence = '')
2213
- {
2214
- $url = $this->URL('site');
2215
- $url = $this->add_qs_var('method', 'ical', $url);
2216
- $url = $this->add_qs_var('id', $event_id, $url);
2217
-
2218
- // Add Occurrence Date if passed
2219
- if(trim($occurrence)) $url = $this->add_qs_var('occurrence', $occurrence, $url);
2220
-
2221
- return $url;
2222
- }
2223
-
2224
- public function ical_URL_email($event_id, $book_id , $occurrence = '')
2225
- {
2226
- $url = $this->URL('site');
2227
- $url = $this->add_qs_var('method', 'ical-email', $url);
2228
- $url = $this->add_qs_var('id', $event_id, $url);
2229
- $url = $this->add_qs_var('book_id', $book_id, $url);
2230
- $url = $this->add_qs_var('key', md5($book_id), $url);
2231
-
2232
- // Add Occurrence Date if passed
2233
- if(trim($occurrence)) $url = $this->add_qs_var('occurrence', $occurrence, $url);
2234
-
2235
- return $url;
2236
- }
2237
-
2238
- /**
2239
- * Returns iCal export for one event
2240
- * @author Webnus <info@webnus.biz>
2241
- * @param int $event_id
2242
- * @param string $occurrence
2243
- * @return string
2244
- */
2245
- public function ical_single($event_id, $occurrence = '')
2246
- {
2247
- // MEC Render Library
2248
- $render = $this->getRender();
2249
-
2250
- $event = $render->data($event_id);
2251
- $dates = $render->dates($event_id, $event, 2, $occurrence);
2252
-
2253
- $location = isset($event->locations[$event->meta['mec_location_id']]) ? $event->locations[$event->meta['mec_location_id']]['address'] : '';
2254
-
2255
- $occurrence_end_date = trim($occurrence) ? $this->get_end_date_by_occurrence($event_id, (isset($dates[0]['start']['date']) ? $dates[0]['start']['date'] : $occurrence)) : '';
2256
- $start_time = strtotime((trim($occurrence) ? $occurrence : $dates[0]['start']['date']).' '.sprintf("%02d", $dates[0]['start']['hour']).':'.sprintf("%02d", $dates[0]['start']['minutes']).' '.$dates[0]['start']['ampm']);
2257
- $end_time = strtotime((trim($occurrence_end_date) ? $occurrence_end_date : $dates[0]['end']['date']).' '.sprintf("%02d", $dates[0]['end']['hour']).':'.sprintf("%02d", $dates[0]['end']['minutes']).' '.$dates[0]['end']['ampm']);
2258
-
2259
- $gmt_offset_seconds = $this->get_gmt_offset_seconds($start_time);
2260
- $stamp = strtotime($event->post->post_date);
2261
- $modified = strtotime($event->post->post_modified);
2262
-
2263
- $rrules = $this->get_ical_rrules($event);
2264
-
2265
- $ical = "BEGIN:VEVENT".PHP_EOL;
2266
- $ical .= "UID:MEC-".md5($event_id)."@".$this->get_domain().PHP_EOL;
2267
- $ical .= "DTSTART:".gmdate('Ymd\\THi00\\Z', ($start_time - $gmt_offset_seconds)).PHP_EOL;
2268
- $ical .= "DTEND:".gmdate('Ymd\\THi00\\Z', ($end_time - $gmt_offset_seconds)).PHP_EOL;
2269
- $ical .= "DTSTAMP:".gmdate('Ymd\\THi00\\Z', ($stamp - $gmt_offset_seconds)).PHP_EOL;
2270
-
2271
- if(is_array($rrules) and count($rrules))
2272
- {
2273
- foreach($rrules as $rrule) $ical .= $rrule.PHP_EOL;
2274
- }
2275
-
2276
- $ical .= "CREATED:".date('Ymd', $stamp).PHP_EOL;
2277
- $ical .= "LAST-MODIFIED:".date('Ymd', $modified).PHP_EOL;
2278
- $ical .= "SUMMARY:".html_entity_decode($event->title, ENT_NOQUOTES, 'UTF-8').PHP_EOL;
2279
- $ical .= "DESCRIPTION:".html_entity_decode(trim(strip_tags($event->content)), ENT_NOQUOTES, 'UTF-8').PHP_EOL;
2280
- $ical .= "URL:".$event->permalink.PHP_EOL;
2281
-
2282
- // Location
2283
- if(trim($location) != '') $ical .= "LOCATION:".$location.PHP_EOL;
2284
-
2285
- // Featured Image
2286
- if(trim($event->featured_image['full']) != '')
2287
- {
2288
- $ex = explode('/', $event->featured_image['full']);
2289
- $filename = end($ex);
2290
- $ical .= "ATTACH;FMTTYPE=".$this->get_mime_content_type($filename).":".$event->featured_image['full'].PHP_EOL;
2291
- }
2292
-
2293
- $ical .= "END:VEVENT".PHP_EOL;
2294
-
2295
- return $ical;
2296
- }
2297
-
2298
-
2299
- /**
2300
- * Returns iCal export for email
2301
- * @author Webnus <info@webnus.biz>
2302
- * @param int $event_id
2303
- * @param int $book_id
2304
- * @param string $occurrence
2305
- * @return string
2306
- */
2307
- public function ical_single_email($event_id, $book_id, $occurrence = '')
2308
- {
2309
- $ticket_ids_str = get_post_meta($book_id, 'mec_ticket_id', true);
2310
- $tickets = get_post_meta($event_id, 'mec_tickets', true);
2311
-
2312
- $ticket_start_hour = $ticket_start_minute = $ticket_end_hour = $ticket_end_minute = $ticket_start_ampm = $ticket_end_ampm = '';
2313
-
2314
- $ticket_ids = explode(',', $ticket_ids_str);
2315
- $ticket_ids = array_filter($ticket_ids);
2316
-
2317
- foreach($ticket_ids as $get_ticket_id=>$value)
2318
- {
2319
- foreach($tickets as $ticket=>$ticket_info)
2320
- {
2321
- if($ticket != $value) continue;
2322
-
2323
- $ticket_start_hour = $ticket_info['ticket_start_time_hour'];
2324
- $ticket_start_minute = $ticket_info['ticket_start_time_minute'];
2325
- $ticket_start_ampm = $ticket_info['ticket_start_time_ampm'];
2326
- $ticket_end_hour = $ticket_info['ticket_end_time_hour'];
2327
- $ticket_end_minute = $ticket_info['ticket_end_time_minute'];
2328
- $ticket_end_ampm = $ticket_info['ticket_end_time_ampm'];
2329
- }
2330
- }
2331
-
2332
- // MEC Render Library
2333
- $render = $this->getRender();
2334
- $event = $render->data($event_id);
2335
-
2336
- $location = isset($event->locations[$event->meta['mec_location_id']]) ? $event->locations[$event->meta['mec_location_id']]['address'] : '';
2337
-
2338
- $start_time = strtotime(get_the_date('Y-m-d', $book_id).' '.sprintf("%02d", $ticket_start_hour).':'.sprintf("%02d", $ticket_start_minute).' '.$ticket_start_ampm);
2339
- $end_time = strtotime(get_the_date('Y-m-d', $book_id).' '.sprintf("%02d", $ticket_end_hour).':'.sprintf("%02d", $ticket_end_minute).' '.$ticket_end_ampm);
2340
-
2341
- $gmt_offset_seconds = $this->get_gmt_offset_seconds($start_time);
2342
-
2343
- $stamp = strtotime($event->post->post_date);
2344
- $modified = strtotime($event->post->post_modified);
2345
-
2346
- $ical = "BEGIN:VEVENT".PHP_EOL;
2347
- $ical .= "UID:MEC-".md5($event_id)."@".$this->get_domain().PHP_EOL;
2348
- $ical .= "DTSTART:".gmdate('Ymd\\THi00\\Z', ($start_time - $gmt_offset_seconds)).PHP_EOL;
2349
- $ical .= "DTEND:".gmdate('Ymd\\THi00\\Z', ($end_time - $gmt_offset_seconds)).PHP_EOL;
2350
- $ical .= "DTSTAMP:".gmdate('Ymd\\THi00\\Z', ($stamp - $gmt_offset_seconds)).PHP_EOL;
2351
- $ical .= "CREATED:".date('Ymd', $stamp).PHP_EOL;
2352
- $ical .= "LAST-MODIFIED:".date('Ymd', $modified).PHP_EOL;
2353
- $ical .= "SUMMARY:".html_entity_decode($event->title, ENT_NOQUOTES, 'UTF-8').PHP_EOL;
2354
- $ical .= "DESCRIPTION:".html_entity_decode(trim(strip_tags($event->content)), ENT_NOQUOTES, 'UTF-8').PHP_EOL;
2355
- $ical .= "URL:".$event->permalink.PHP_EOL;
2356
-
2357
- // Location
2358
- if(trim($location) != '') $ical .= "LOCATION:".$location.PHP_EOL;
2359
-
2360
- // Featured Image
2361
- if(trim($event->featured_image['full']) != '')
2362
- {
2363
- $ex = explode('/', $event->featured_image['full']);
2364
- $filename = end($ex);
2365
- $ical .= "ATTACH;FMTTYPE=".$this->get_mime_content_type($filename).":".$event->featured_image['full'].PHP_EOL;
2366
- }
2367
-
2368
- $ical .= "END:VEVENT".PHP_EOL;
2369
-
2370
- return $ical;
2371
- }
2372
-
2373
- /**
2374
- * Returns iCal export for some events
2375
- * @author Webnus <info@webnus.biz>
2376
- * @param string $events
2377
- * @return string
2378
- */
2379
- public function ical_calendar($events)
2380
- {
2381
- $ical = "BEGIN:VCALENDAR".PHP_EOL;
2382
- $ical .= "VERSION:2.0".PHP_EOL;
2383
- $ical .= "METHOD:PUBLISH".PHP_EOL;
2384
- $ical .= "CALSCALE:GREGORIAN".PHP_EOL;
2385
- $ical .= "PRODID:-//WordPress - MECv".$this->get_version()."//EN".PHP_EOL;
2386
- $ical .= "X-WR-CALNAME:WordPress".PHP_EOL;
2387
- $ical .= "X-ORIGINAL-URL:".$this->URL('site').PHP_EOL;
2388
- $ical .= $events;
2389
- $ical .= "END:VCALENDAR";
2390
-
2391
- return $ical;
2392
- }
2393
-
2394
- /**
2395
- * Get mime type of a file
2396
- * @author Webnus <info@webnus.biz>
2397
- * @param string $filename
2398
- * @return string
2399
- */
2400
- public function get_mime_content_type($filename)
2401
- {
2402
- // Remove query string from the image name
2403
- if(strpos($filename, '?') !== false)
2404
- {
2405
- $ex = explode('?', $filename);
2406
- $filename = $ex[0];
2407
- }
2408
-
2409
- $mime_types = array
2410
- (
2411
- 'txt' => 'text/plain',
2412
- 'htm' => 'text/html',
2413
- 'html' => 'text/html',
2414
- 'php' => 'text/html',
2415
- 'css' => 'text/css',
2416
- 'js' => 'application/javascript',
2417
- 'json' => 'application/json',
2418
- 'xml' => 'application/xml',
2419
- 'swf' => 'application/x-shockwave-flash',
2420
- 'flv' => 'video/x-flv',
2421
-
2422
- // images
2423
- 'png' => 'image/png',
2424
- 'jpe' => 'image/jpeg',
2425
- 'jpeg' => 'image/jpeg',
2426
- 'jpg' => 'image/jpeg',
2427
- 'gif' => 'image/gif',
2428
- 'bmp' => 'image/bmp',
2429
- 'ico' => 'image/vnd.microsoft.icon',
2430
- 'tiff' => 'image/tiff',
2431
- 'tif' => 'image/tiff',
2432
- 'svg' => 'image/svg+xml',
2433
- 'svgz' => 'image/svg+xml',
2434
-
2435
- // archives
2436
- 'zip' => 'application/zip',
2437
- 'rar' => 'application/x-rar-compressed',
2438
- 'exe' => 'application/x-msdownload',
2439
- 'msi' => 'application/x-msdownload',
2440
- 'cab' => 'application/vnd.ms-cab-compressed',
2441
-
2442
- // audio/video
2443
- 'mp3' => 'audio/mpeg',
2444
- 'qt' => 'video/quicktime',
2445
- 'mov' => 'video/quicktime',
2446
-
2447
- // adobe
2448
- 'pdf' => 'application/pdf',
2449
- 'psd' => 'image/vnd.adobe.photoshop',
2450
- 'ai' => 'application/postscript',
2451
- 'eps' => 'application/postscript',
2452
- 'ps' => 'application/postscript',
2453
-
2454
- // ms office
2455
- 'doc' => 'application/msword',
2456
- 'rtf' => 'application/rtf',
2457
- 'xls' => 'application/vnd.ms-excel',
2458
- 'ppt' => 'application/vnd.ms-powerpoint',
2459
-
2460
- // open office
2461
- 'odt' => 'application/vnd.oasis.opendocument.text',
2462
- 'ods' => 'application/vnd.oasis.opendocument.spreadsheet',
2463
- );
2464
-
2465
- $ex = explode('.', $filename);
2466
- $ext = strtolower(array_pop($ex));
2467
- if(array_key_exists($ext, $mime_types))
2468
- {
2469
- return $mime_types[$ext];
2470
- }
2471
- elseif(function_exists('finfo_open'))
2472
- {
2473
- $finfo = finfo_open(FILEINFO_MIME);
2474
- $mimetype = finfo_file($finfo, $filename);
2475
- finfo_close($finfo);
2476
-
2477
- return $mimetype;
2478
- }
2479
- else
2480
- {
2481
- return 'application/octet-stream';
2482
- }
2483
- }
2484
-
2485
- /**
2486
- * Returns book post type slug
2487
- * @author Webnus <info@webnus.biz>
2488
- * @return string
2489
- */
2490
- public function get_book_post_type()
2491
- {
2492
- return apply_filters('mec_book_post_type_name', 'mec-books');
2493
- }
2494
-
2495
- /**
2496
- * Returns shortcode post type slug
2497
- * @author Webnus <info@webnus.biz>
2498
- * @return string
2499
- */
2500
- public function get_shortcode_post_type()
2501
- {
2502
- return apply_filters('mec_shortcode_post_type_name', 'mec_calendars');
2503
- }
2504
-
2505
- /**
2506
- * Show text field options in booking form
2507
- * @author Webnus <info@webnus.biz>
2508
- * @param string $key
2509
- * @param array $values
2510
- * @return string
2511
- */
2512
- public function field_text($key, $values = array())
2513
- {
2514
- $field = '<li id="mec_reg_fields_'.$key.'">
2515
- <span class="mec_reg_field_sort">'.__('Sort', 'modern-events-calendar-lite').'</span>
2516
- <span class="mec_reg_field_type">'.__('Text', 'modern-events-calendar-lite').'</span>
2517
- <p class="mec_reg_field_options">
2518
- <label for="mec_reg_fields_'.$key.'_mandatory">
2519
- <input type="hidden" name="mec[reg_fields]['.$key.'][mandatory]" value="0" />
2520
- <input type="checkbox" name="mec[reg_fields]['.$key.'][mandatory]" value="1" id="mec_reg_fields_'.$key.'_mandatory" '.((isset($values['mandatory']) and $values['mandatory']) ? 'checked="checked"' : '').' />
2521
- '.__('Required Field', 'modern-events-calendar-lite').'
2522
- </label>
2523
- </p>
2524
- <span onclick="mec_reg_fields_remove('.$key.');" class="mec_reg_field_remove">'.__('Remove', 'modern-events-calendar-lite').'</span>
2525
- <div>
2526
- <input type="hidden" name="mec[reg_fields]['.$key.'][type]" value="text" />
2527
- <input type="text" name="mec[reg_fields]['.$key.'][label]" placeholder="'.esc_attr__('Insert a label for this field', 'modern-events-calendar-lite').'" value="'.(isset($values['label']) ? $values['label'] : '').'" />
2528
- </div>
2529
- </li>';
2530
-
2531
- return $field;
2532
- }
2533
-
2534
-
2535
- /**
2536
- * Show text field options in booking form
2537
- * @author Webnus <info@webnus.biz>
2538
- * @param string $key
2539
- * @param array $values
2540
- * @return string
2541
- */
2542
- public function field_name($key, $values = array())
2543
- {
2544
- $field = '<li id="mec_reg_fields_'.$key.'">
2545
- <span class="mec_reg_field_sort">'.__('Sort', 'modern-events-calendar-lite').'</span>
2546
- <span class="mec_reg_field_type">'.__('MEC Name', 'modern-events-calendar-lite').'</span>
2547
- <p class="mec_reg_field_options" style="display:none">
2548
- <label for="mec_reg_fields_'.$key.'_mandatory">
2549
- <input type="hidden" name="mec[reg_fields]['.$key.'][mandatory]" value="1" />
2550
- <input type="checkbox" name="mec[reg_fields]['.$key.'][mandatory]" value="1" id="mec_reg_fields_'.$key.'_mandatory" checked="checked" disabled />
2551
- '.__('Required Field', 'modern-events-calendar-lite').'
2552
- </label>
2553
- </p>
2554
- <span onclick="mec_reg_fields_remove('.$key.');" class="mec_reg_field_remove">'.__('Remove', 'modern-events-calendar-lite').'</span>
2555
- <div>
2556
- <input type="hidden" name="mec[reg_fields]['.$key.'][type]" value="name" />
2557
- <input type="text" name="mec[reg_fields]['.$key.'][label]" placeholder="'.esc_attr__('Insert a label for this field', 'modern-events-calendar-lite').'" value="'.(isset($values['label']) ? $values['label'] : '').'" />
2558
- </div>
2559
- </li>';
2560
-
2561
- return $field;
2562
- }
2563
-
2564
- /**
2565
- * Show text field options in booking form
2566
- * @author Webnus <info@webnus.biz>
2567
- * @param string $key
2568
- * @param array $values
2569
- * @return string
2570
- */
2571
- public function field_mec_email($key, $values = array())
2572
- {
2573
- $field = '<li id="mec_reg_fields_'.$key.'">
2574
- <span class="mec_reg_field_sort">'.__('Sort', 'modern-events-calendar-lite').'</span>
2575
- <span class="mec_reg_field_type">'.__('MEC Email', 'modern-events-calendar-lite').'</span>
2576
- <p class="mec_reg_field_options" style="display:none">
2577
- <label for="mec_reg_fields_'.$key.'_mandatory">
2578
- <input type="hidden" name="mec[reg_fields]['.$key.'][mandatory]" value="1" />
2579
- <input type="checkbox" name="mec[reg_fields]['.$key.'][mandatory]" value="1" id="mec_reg_fields_'.$key.'_mandatory" checked="checked" disabled />
2580
- '.__('Required Field', 'modern-events-calendar-lite').'
2581
- </label>
2582
- </p>
2583
- <span onclick="mec_reg_fields_remove('.$key.');" class="mec_reg_field_remove">'.__('Remove', 'modern-events-calendar-lite').'</span>
2584
- <div>
2585
- <input type="hidden" name="mec[reg_fields]['.$key.'][type]" value="mec_email" />
2586
- <input type="text" name="mec[reg_fields]['.$key.'][label]" placeholder="'.esc_attr__('Insert a label for this field', 'modern-events-calendar-lite').'" value="'.(isset($values['label']) ? $values['label'] : '').'" />
2587
- </div>
2588
- </li>';
2589
-
2590
- return $field;
2591
- }
2592
-
2593
-
2594
- /**
2595
- * Show email field options in booking form
2596
- * @author Webnus <info@webnus.biz>
2597
- * @param string $key
2598
- * @param array $values
2599
- * @return string
2600
- */
2601
- public function field_email($key, $values = array())
2602
- {
2603
- $field = '<li id="mec_reg_fields_'.$key.'">
2604
- <span class="mec_reg_field_sort">'.__('Sort', 'modern-events-calendar-lite').'</span>
2605
- <span class="mec_reg_field_type">'.__('Email', 'modern-events-calendar-lite').'</span>
2606
- <p class="mec_reg_field_options">
2607
- <label for="mec_reg_fields_'.$key.'_mandatory">
2608
- <input type="hidden" name="mec[reg_fields]['.$key.'][mandatory]" value="0" />
2609
- <input type="checkbox" name="mec[reg_fields]['.$key.'][mandatory]" value="1" id="mec_reg_fields_'.$key.'_mandatory" '.((isset($values['mandatory']) and $values['mandatory']) ? 'checked="checked"' : '').' />
2610
- '.__('Required Field', 'modern-events-calendar-lite').'
2611
- </label>
2612
- </p>
2613
- <span onclick="mec_reg_fields_remove('.$key.');" class="mec_reg_field_remove">'.__('Remove', 'modern-events-calendar-lite').'</span>
2614
- <div>
2615
- <input type="hidden" name="mec[reg_fields]['.$key.'][type]" value="email" />
2616
- <input type="text" name="mec[reg_fields]['.$key.'][label]" placeholder="'.esc_attr__('Insert a label for this field', 'modern-events-calendar-lite').'" value="'.(isset($values['label']) ? $values['label'] : '').'" />
2617
- </div>
2618
- </li>';
2619
-
2620
- return $field;
2621
- }
2622
-
2623
- /**
2624
- * Show file field options in booking form
2625
- * @author Webnus <info@webnus.biz>
2626
- * @param string $key
2627
- * @param array $values
2628
- * @return string
2629
- */
2630
- public function field_file($key, $values = array())
2631
- {
2632
- $field = '<li id="mec_reg_fields_'.$key.'">
2633
- <span class="mec_reg_field_sort">'.__('Sort', 'modern-events-calendar-lite').'</span>
2634
- <span class="mec_reg_field_type">'.__('File', 'modern-events-calendar-lite').'</span>
2635
- <p class="mec_reg_field_options">
2636
- <label for="mec_reg_fields_'.$key.'_mandatory">
2637
- <input type="hidden" name="mec[reg_fields]['.$key.'][mandatory]" value="0" />
2638
- <input type="checkbox" name="mec[reg_fields]['.$key.'][mandatory]" value="1" id="mec_reg_fields_'.$key.'_mandatory" '.((isset($values['mandatory']) and $values['mandatory']) ? 'checked="checked"' : '').' />
2639
- '.__('Required Field', 'modern-events-calendar-lite').'
2640
- </label>
2641
- </p>
2642
- <span onclick="mec_reg_fields_remove('.$key.');" class="mec_reg_field_remove">'.__('Remove', 'modern-events-calendar-lite').'</span>
2643
- <div>
2644
- <input type="hidden" name="mec[reg_fields]['.$key.'][type]" value="file" />
2645
- <input type="text" name="mec[reg_fields]['.$key.'][label]" placeholder="'.esc_attr__('Insert a label for this field', 'modern-events-calendar-lite').'" value="'.(isset($values['label']) ? $values['label'] : '').'" />
2646
- </div>
2647
- </li>';
2648
-
2649
- return $field;
2650
- }
2651
-
2652
- /**
2653
- * Show date field options in booking form
2654
- * @author Webnus <info@webnus.biz>
2655
- * @param string $key
2656
- * @param array $values
2657
- * @return string
2658
- */
2659
- public function field_date($key, $values = array())
2660
- {
2661
- $field = '<li id="mec_reg_fields_'.$key.'">
2662
- <span class="mec_reg_field_sort">'.__('Sort', 'modern-events-calendar-lite').'</span>
2663
- <span class="mec_reg_field_type">'.__('Date', 'modern-events-calendar-lite').'</span>
2664
- <p class="mec_reg_field_options">
2665
- <label for="mec_reg_fields_'.$key.'_mandatory">
2666
- <input type="hidden" name="mec[reg_fields]['.$key.'][mandatory]" value="0" />
2667
- <input type="checkbox" name="mec[reg_fields]['.$key.'][mandatory]" value="1" id="mec_reg_fields_'.$key.'_mandatory" '.((isset($values['mandatory']) and $values['mandatory']) ? 'checked="checked"' : '').' />
2668
- '.__('Required Field', 'modern-events-calendar-lite').'
2669
- </label>
2670
- </p>
2671
- <span onclick="mec_reg_fields_remove('.$key.');" class="mec_reg_field_remove">'.__('Remove', 'modern-events-calendar-lite').'</span>
2672
- <div>
2673
- <input type="hidden" name="mec[reg_fields]['.$key.'][type]" value="date" />
2674
- <input type="text" name="mec[reg_fields]['.$key.'][label]" placeholder="'.esc_attr__('Insert a label for this field', 'modern-events-calendar-lite').'" value="'.(isset($values['label']) ? $values['label'] : '').'" />
2675
- </div>
2676
- </li>';
2677
-
2678
- return $field;
2679
- }
2680
-
2681
- /**
2682
- * Show tel field options in booking form
2683
- * @author Webnus <info@webnus.biz>
2684
- * @param string $key
2685
- * @param array $values
2686
- * @return string
2687
- */
2688
- public function field_tel($key, $values = array())
2689
- {
2690
- $field = '<li id="mec_reg_fields_'.$key.'">
2691
- <span class="mec_reg_field_sort">'.__('Sort', 'modern-events-calendar-lite').'</span>
2692
- <span class="mec_reg_field_type">'.__('Tel', 'modern-events-calendar-lite').'</span>
2693
- <p class="mec_reg_field_options">
2694
- <label for="mec_reg_fields_'.$key.'_mandatory">
2695
- <input type="hidden" name="mec[reg_fields]['.$key.'][mandatory]" value="0" />
2696
- <input type="checkbox" name="mec[reg_fields]['.$key.'][mandatory]" value="1" id="mec_reg_fields_'.$key.'_mandatory" '.((isset($values['mandatory']) and $values['mandatory']) ? 'checked="checked"' : '').' />
2697
- '.__('Required Field', 'modern-events-calendar-lite').'
2698
- </label>
2699
- </p>
2700
- <span onclick="mec_reg_fields_remove('.$key.');" class="mec_reg_field_remove">'.__('Remove', 'modern-events-calendar-lite').'</span>
2701
- <div>
2702
- <input type="hidden" name="mec[reg_fields]['.$key.'][type]" value="tel" />
2703
- <input type="text" name="mec[reg_fields]['.$key.'][label]" placeholder="'.esc_attr__('Insert a label for this field', 'modern-events-calendar-lite').'" value="'.(isset($values['label']) ? $values['label'] : '').'" />
2704
- </div>
2705
- </li>';
2706
-
2707
- return $field;
2708
- }
2709
-
2710
- /**
2711
- * Show textarea field options in booking form
2712
- * @author Webnus <info@webnus.biz>
2713
- * @param string $key
2714
- * @param array $values
2715
- * @return string
2716
- */
2717
- public function field_textarea($key, $values = array())
2718
- {
2719
- $field = '<li id="mec_reg_fields_'.$key.'">
2720
- <span class="mec_reg_field_sort">'.__('Sort', 'modern-events-calendar-lite').'</span>
2721
- <span class="mec_reg_field_type">'.__('Textarea', 'modern-events-calendar-lite').'</span>
2722
- <p class="mec_reg_field_options">
2723
- <label for="mec_reg_fields_'.$key.'_mandatory">
2724
- <input type="hidden" name="mec[reg_fields]['.$key.'][mandatory]" value="0" />
2725
- <input type="checkbox" name="mec[reg_fields]['.$key.'][mandatory]" value="1" id="mec_reg_fields_'.$key.'_mandatory" '.((isset($values['mandatory']) and $values['mandatory']) ? 'checked="checked"' : '').' />
2726
- '.__('Required Field', 'modern-events-calendar-lite').'
2727
- </label>
2728
- </p>
2729
- <span onclick="mec_reg_fields_remove('.$key.');" class="mec_reg_field_remove">'.__('Remove', 'modern-events-calendar-lite').'</span>
2730
- <div>
2731
- <input type="hidden" name="mec[reg_fields]['.$key.'][type]" value="textarea" />
2732
- <input type="text" name="mec[reg_fields]['.$key.'][label]" placeholder="'.esc_attr__('Insert a label for this field', 'modern-events-calendar-lite').'" value="'.(isset($values['label']) ? $values['label'] : '').'" />
2733
- </div>
2734
- </li>';
2735
-
2736
- return $field;
2737
- }
2738
-
2739
- /**
2740
- * Show paragraph field options in booking form
2741
- * @author Webnus <info@webnus.biz>
2742
- * @param string $key
2743
- * @param array $values
2744
- * @return string
2745
- */
2746
- public function field_p($key, $values = array())
2747
- {
2748
- $field = '<li id="mec_reg_fields_'.$key.'">
2749
- <span class="mec_reg_field_sort">'.__('Sort', 'modern-events-calendar-lite').'</span>
2750
- <span class="mec_reg_field_type">'.__('Paragraph', 'modern-events-calendar-lite').'</span>
2751
- <span onclick="mec_reg_fields_remove('.$key.');" class="mec_reg_field_remove">'.__('Remove', 'modern-events-calendar-lite').'</span>
2752
- <div>
2753
- <input type="hidden" name="mec[reg_fields]['.$key.'][type]" value="p" />
2754
- <textarea name="mec[reg_fields]['.$key.'][content]">'.(isset($values['content']) ? htmlentities(stripslashes($values['content'])) : '').'</textarea>
2755
- <p class="description">'.__('HTML and shortcode are allowed.').'</p>
2756
- </div>
2757
- </li>';
2758
-
2759
- return $field;
2760
- }
2761
-
2762
- /**
2763
- * Show checkbox field options in booking form
2764
- * @author Webnus <info@webnus.biz>
2765
- * @param string $key
2766
- * @param array $values
2767
- * @return string
2768
- */
2769
- public function field_checkbox($key, $values = array())
2770
- {
2771
- $i = 0;
2772
- $field = '<li id="mec_reg_fields_'.$key.'">
2773
- <span class="mec_reg_field_sort">'.__('Sort', 'modern-events-calendar-lite').'</span>
2774
- <span class="mec_reg_field_type">'.__('Checkboxes', 'modern-events-calendar-lite').'</span>
2775
- <p class="mec_reg_field_options">
2776
- <label for="mec_reg_fields_'.$key.'_mandatory">
2777
- <input type="hidden" name="mec[reg_fields]['.$key.'][mandatory]" value="0" />
2778
- <input type="checkbox" name="mec[reg_fields]['.$key.'][mandatory]" value="1" id="mec_reg_fields_'.$key.'_mandatory" '.((isset($values['mandatory']) and $values['mandatory']) ? 'checked="checked"' : '').' />
2779
- '.__('Required Field', 'modern-events-calendar-lite').'
2780
- </label>
2781
- </p>
2782
- <span onclick="mec_reg_fields_remove('.$key.');" class="mec_reg_field_remove">'.__('Remove', 'modern-events-calendar-lite').'</span>
2783
- <div>
2784
- <input type="hidden" name="mec[reg_fields]['.$key.'][type]" value="checkbox" />
2785
- <input type="text" name="mec[reg_fields]['.$key.'][label]" placeholder="'.esc_attr__('Insert a label for this field', 'modern-events-calendar-lite').'" value="'.(isset($values['label']) ? $values['label'] : '').'" />
2786
- <ul id="mec_reg_fields_'.$key.'_options_container" class="mec_reg_fields_options_container">';
2787
-
2788
- if(isset($values['options']) and is_array($values['options']) and count($values['options']))
2789
- {
2790
- foreach($values['options'] as $option_key=>$option)
2791
- {
2792
- $i = max($i, $option_key);
2793
- $field .= $this->field_option($key, $option_key, $values);
2794
- }
2795
- }
2796
-
2797
- $field .= '</ul>
2798
- <button type="button" class="mec-reg-field-add-option" data-field-id="'.$key.'">'.__('Option', 'modern-events-calendar-lite').'</button>
2799
- <input type="hidden" id="mec_new_reg_field_option_key_'.$key.'" value="'.($i+1).'" />
2800
- </div>
2801
- </li>';
2802
-
2803
- return $field;
2804
- }
2805
-
2806
- /**
2807
- * Show radio field options in booking form
2808
- * @author Webnus <info@webnus.biz>
2809
- * @param string $key
2810
- * @param array $values
2811
- * @return string
2812
- */
2813
- public function field_radio($key, $values = array())
2814
- {
2815
- $i = 0;
2816
- $field = '<li id="mec_reg_fields_'.$key.'">
2817
- <span class="mec_reg_field_sort">'.__('Sort', 'modern-events-calendar-lite').'</span>
2818
- <span class="mec_reg_field_type">'.__('Radio Buttons', 'modern-events-calendar-lite').'</span>
2819
- <p class="mec_reg_field_options">
2820
- <label for="mec_reg_fields_'.$key.'_mandatory">
2821
- <input type="hidden" name="mec[reg_fields]['.$key.'][mandatory]" value="0" />
2822
- <input type="checkbox" name="mec[reg_fields]['.$key.'][mandatory]" value="1" id="mec_reg_fields_'.$key.'_mandatory" '.((isset($values['mandatory']) and $values['mandatory']) ? 'checked="checked"' : '').' />
2823
- '.__('Required Field', 'modern-events-calendar-lite').'
2824
- </label>
2825
- </p>
2826
- <span onclick="mec_reg_fields_remove('.$key.');" class="mec_reg_field_remove">'.__('Remove', 'modern-events-calendar-lite').'</span>
2827
- <div>
2828
- <input type="hidden" name="mec[reg_fields]['.$key.'][type]" value="radio" />
2829
- <input type="text" name="mec[reg_fields]['.$key.'][label]" placeholder="'.esc_attr__('Insert a label for this field', 'modern-events-calendar-lite').'" value="'.(isset($values['label']) ? $values['label'] : '').'" />
2830
- <ul id="mec_reg_fields_'.$key.'_options_container" class="mec_reg_fields_options_container">';
2831
-
2832
- if(isset($values['options']) and is_array($values['options']) and count($values['options']))
2833
- {
2834
- foreach($values['options'] as $option_key=>$option)
2835
- {
2836
- $i = max($i, $option_key);
2837
- $field .= $this->field_option($key, $option_key, $values);
2838
- }
2839
- }
2840
-
2841
- $field .= '</ul>
2842
- <button type="button" class="mec-reg-field-add-option" data-field-id="'.$key.'">'.__('Option', 'modern-events-calendar-lite').'</button>
2843
- <input type="hidden" id="mec_new_reg_field_option_key_'.$key.'" value="'.($i+1).'" />
2844
- </div>
2845
- </li>';
2846
-
2847
- return $field;
2848
- }
2849
-
2850
- /**
2851
- * Show select field options in booking form
2852
- * @author Webnus <info@webnus.biz>
2853
- * @param string $key
2854
- * @param array $values
2855
- * @return string
2856
- */
2857
- public function field_select($key, $values = array())
2858
- {
2859
- $i = 0;
2860
- $field = '<li id="mec_reg_fields_'.$key.'">
2861
- <span class="mec_reg_field_sort">'.__('Sort', 'modern-events-calendar-lite').'</span>
2862
- <span class="mec_reg_field_type">'.__('Dropdown', 'modern-events-calendar-lite').'</span>
2863
- <p class="mec_reg_field_options">
2864
- <label for="mec_reg_fields_'.$key.'_mandatory">
2865
- <input type="hidden" name="mec[reg_fields]['.$key.'][mandatory]" value="0" />
2866
- <input type="checkbox" name="mec[reg_fields]['.$key.'][mandatory]" value="1" id="mec_reg_fields_'.$key.'_mandatory" '.((isset($values['mandatory']) and $values['mandatory']) ? 'checked="checked"' : '').' />
2867
- '.__('Required Field', 'modern-events-calendar-lite').'
2868
- </label>
2869
- </p>
2870
- <span onclick="mec_reg_fields_remove('.$key.');" class="mec_reg_field_remove">'.__('Remove', 'modern-events-calendar-lite').'</span>
2871
- <div>
2872
- <input type="hidden" name="mec[reg_fields]['.$key.'][type]" value="select" />
2873
- <input type="text" name="mec[reg_fields]['.$key.'][label]" placeholder="'.esc_attr__('Insert a label for this field', 'modern-events-calendar-lite').'" value="'.(isset($values['label']) ? $values['label'] : '').'" />
2874
- <ul id="mec_reg_fields_'.$key.'_options_container" class="mec_reg_fields_options_container">';
2875
-
2876
- if(isset($values['options']) and is_array($values['options']) and count($values['options']))
2877
- {
2878
- foreach($values['options'] as $option_key=>$option)
2879
- {
2880
- $i = max($i, $option_key);
2881
- $field .= $this->field_option($key, $option_key, $values);
2882
- }
2883
- }
2884
-
2885
- $field .= '</ul>
2886
- <button type="button" class="mec-reg-field-add-option" data-field-id="'.$key.'">'.__('Option', 'modern-events-calendar-lite').'</button>
2887
- <input type="hidden" id="mec_new_reg_field_option_key_'.$key.'" value="'.($i+1).'" />
2888
- </div>
2889
- </li>';
2890
-
2891
- return $field;
2892
- }
2893
-
2894
- /**
2895
- * Show agreement field options in booking form
2896
- * @author Webnus <info@webnus.biz>
2897
- * @param string $key
2898
- * @param array $values
2899
- * @return string
2900
- */
2901
- public function field_agreement($key, $values = array())
2902
- {
2903
- // WordPress Pages
2904
- $pages = get_pages();
2905
-
2906
- $i = 0;
2907
- $field = '<li id="mec_reg_fields_'.$key.'">
2908
- <span class="mec_reg_field_sort">'.__('Sort', 'modern-events-calendar-lite').'</span>
2909
- <span class="mec_reg_field_type">'.__('Agreement', 'modern-events-calendar-lite').'</span>
2910
- <p class="mec_reg_field_options">
2911
- <label for="mec_reg_fields_'.$key.'_mandatory">
2912
- <input type="hidden" name="mec[reg_fields]['.$key.'][mandatory]" value="0" />
2913
- <input type="checkbox" name="mec[reg_fields]['.$key.'][mandatory]" value="1" id="mec_reg_fields_'.$key.'_mandatory" '.((!isset($values['mandatory']) or (isset($values['mandatory']) and $values['mandatory'])) ? 'checked="checked"' : '').' />
2914
- '.__('Required Field', 'modern-events-calendar-lite').'
2915
- </label>
2916
- </p>
2917
- <span onclick="mec_reg_fields_remove('.$key.');" class="mec_reg_field_remove">'.__('Remove', 'modern-events-calendar-lite').'</span>
2918
- <div>
2919
- <input type="hidden" name="mec[reg_fields]['.$key.'][type]" value="agreement" />
2920
- <input type="text" name="mec[reg_fields]['.$key.'][label]" placeholder="'.esc_attr__('Insert a label for this field', 'modern-events-calendar-lite').'" value="'.(isset($values['label']) ? stripslashes($values['label']) : 'I agree with %s').'" /><p class="description">'.__('Instead of %s, the page title with a link will be show.', 'modern-events-calendar-lite').'</p>
2921
- <div>
2922
- <label for="mec_reg_fields_'.$key.'_page">'.__('Agreement Page', 'modern-events-calendar-lite').'</label>
2923
- <select id="mec_reg_fields_'.$key.'_page" name="mec[reg_fields]['.$key.'][page]">';
2924
-
2925
- $page_options = '';
2926
- foreach($pages as $page) $page_options .= '<option '.((isset($values['page']) and $values['page'] == $page->ID) ? 'selected="selected"' : '').' value="'.$page->ID.'">'.$page->post_title.'</option>';
2927
-
2928
- $field .= $page_options.'</select>
2929
- </div>
2930
- <div>
2931
- <label for="mec_reg_fields_'.$key.'_status">'.__('Status', 'modern-events-calendar-lite').'</label>
2932
- <select id="mec_reg_fields_'.$key.'_status" name="mec[reg_fields]['.$key.'][status]">
2933
- <option value="checked" '.((isset($values['status']) and $values['status'] == 'checked') ? 'selected="selected"' : '').'>'.__('Checked by default', 'modern-events-calendar-lite').'</option>
2934
- <option value="unchecked" '.((isset($values['status']) and $values['status'] == 'unchecked') ? 'selected="selected"' : '').'>'.__('Unchecked by default', 'modern-events-calendar-lite').'</option>
2935
- </select>
2936
- </div>
2937
- <input type="hidden" id="mec_new_reg_field_option_key_'.$key.'" value="'.($i+1).'" />
2938
- </div>
2939
- </li>';
2940
-
2941
- return $field;
2942
- }
2943
-
2944
- /**
2945
- * Show option tag parameters in booking form for select, checkbox and radio tags
2946
- * @author Webnus <info@webnus.biz>
2947
- * @param string $field_key
2948
- * @param string $key
2949
- * @param array $values
2950
- * @return string
2951
- */
2952
- public function field_option($field_key, $key, $values = array())
2953
- {
2954
- $field = '<li id="mec_reg_fields_option_'.$field_key.'_'.$key.'">
2955
- <span class="mec_reg_field_option_sort">'.__('Sort', 'modern-events-calendar-lite').'</span>
2956
- <span onclick="mec_reg_fields_option_remove('.$field_key.','.$key.');" class="mec_reg_field_remove">'.__('Remove', 'modern-events-calendar-lite').'</span>
2957
- <input type="text" name="mec[reg_fields]['.$field_key.'][options]['.$key.'][label]" placeholder="'.esc_attr__('Insert a label for this option', 'modern-events-calendar-lite').'" value="'.((isset($values['options']) and isset($values['options'][$key])) ? esc_attr(stripslashes($values['options'][$key]['label'])) : '').'" />
2958
- </li>';
2959
-
2960
- return $field;
2961
- }
2962
-
2963
- /**
2964
- * Render raw price and return its output
2965
- * @author Webnus <info@webnus.biz>
2966
- * @param int $price
2967
- * @return string
2968
- */
2969
- public function render_price($price)
2970
- {
2971
- // return Free if price is 0
2972
- if($price == '0') return __('Free', 'modern-events-calendar-lite');
2973
-
2974
- $thousand_separator = $this->get_thousand_separator();
2975
- $decimal_separator = $this->get_decimal_separator();
2976
-
2977
- $currency = $this->get_currency_sign();
2978
- $currency_sign_position = $this->get_currency_sign_position();
2979
-
2980
- // Force to double
2981
- if(is_string($price)) $price = (double) $price;
2982
-
2983
- $rendered = number_format($price, ($decimal_separator === false ? 0 : 2), ($decimal_separator === false ? '' : $decimal_separator), $thousand_separator);
2984
-
2985
- if($currency_sign_position == 'after') $rendered = $rendered.$currency;
2986
- else $rendered = $currency.$rendered;
2987
-
2988
- return $rendered;
2989
- }
2990
-
2991
- /**
2992
- * Returns thousand separator
2993
- * @author Webnus <info@webnus.biz>
2994
- * @return string
2995
- */
2996
- public function get_thousand_separator()
2997
- {
2998
- $settings = $this->get_settings();
2999
- return apply_filters('mec_thousand_separator', (isset($settings['thousand_separator']) ? $settings['thousand_separator'] : ','));
3000
- }
3001
-
3002
- /**
3003
- * Returns decimal separator
3004
- * @author Webnus <info@webnus.biz>
3005
- * @return string
3006
- */
3007
- public function get_decimal_separator()
3008
- {
3009
- $settings = $this->get_settings();
3010
- return apply_filters('mec_decimal_separator', ((isset($settings['decimal_separator_status']) and $settings['decimal_separator_status'] == 0) ? false : (isset($settings['decimal_separator']) ? $settings['decimal_separator'] : '.')));
3011
- }
3012
-
3013
- /**
3014
- * Returns currency of MEC
3015
- * @author Webnus <info@webnus.biz>
3016
- * @return string
3017
- */
3018
- public function get_currency()
3019
- {
3020
- $settings = $this->get_settings();
3021
- return apply_filters('mec_currency', (isset($settings['currency']) ? $settings['currency'] : ''));
3022
- }
3023
-
3024
- /**
3025
- * Returns currency sign of MEC
3026
- * @author Webnus <info@webnus.biz>
3027
- * @return string
3028
- */
3029
- public function get_currency_sign()
3030
- {
3031
- $settings = $this->get_settings();
3032
-
3033
- // Get Currency Symptom
3034
- $currency = isset($settings['currency']) ? $settings['currency'] : '';
3035
- if(isset($settings['currency_symptom']) and trim($settings['currency_symptom'])) $currency = $settings['currency_symptom'];
3036
-
3037
- return apply_filters('mec_currency_sign', $currency);
3038
- }
3039
-
3040
- /**
3041
- * Returns currency code of MEC
3042
- * @author Webnus <info@webnus.biz>
3043
- * @return string
3044
- */
3045
- public function get_currency_code()
3046
- {
3047
- $currency = $this->get_currency();
3048
- $currencies = $this->get_currencies();
3049
-
3050
- return isset($currencies[$currency]) ? $currencies[$currency] : 'USD';
3051
- }
3052
-
3053
- /**
3054
- * Returns currency sign position of MEC
3055
- * @author Webnus <info@webnus.biz>
3056
- * @return string
3057
- */
3058
- public function get_currency_sign_position()
3059
- {
3060
- $settings = $this->get_settings();
3061
- return apply_filters('mec_currency_sign_position', (isset($settings['currency_sign']) ? $settings['currency_sign'] : ''));
3062
- }
3063
-
3064
- /**
3065
- * Returns MEC Payment Gateways
3066
- * @author Webnus <info@webnus.biz>
3067
- * @return array
3068
- */
3069
- public function get_gateways()
3070
- {
3071
- return apply_filters('mec_gateways', array());
3072
- }
3073
-
3074
- /**
3075
- * Check to see if user exists by its username
3076
- * @author Webnus <info@webnus.biz>
3077
- * @param string $username
3078
- * @return boolean
3079
- */
3080
- public function username_exists($username)
3081
- {
3082
- /** first validation **/
3083
- if(!trim($username)) return true;
3084
-
3085
- return username_exists($username);
3086
- }
3087
-
3088
- /**
3089
- * Check to see if user exists by its email
3090
- * @author Webnus <info@webnus.biz>
3091
- * @param string $email
3092
- * @return boolean
3093
- */
3094
- public function email_exists($email)
3095
- {
3096
- /** first validation **/
3097
- if(!trim($email)) return true;
3098
-
3099
- return email_exists($email);
3100
- }
3101
-
3102
- /**
3103
- * Register a user in WordPress
3104
- * @author Webnus <info@webnus.biz>
3105
- * @param string $username
3106
- * @param string $email
3107
- * @param string $password
3108
- * @return boolean
3109
- */
3110
- public function register_user($username, $email, $password = NULL)
3111
- {
3112
- /** first validation **/
3113
- if(!trim($username) or !trim($email)) return false;
3114
-
3115
- return wp_create_user($username, $password, $email);
3116
- }
3117
-
3118
- /**
3119
- * Convert a formatted date into standard format
3120
- * @author Webnus <info@webnus.biz>
3121
- * @param string $date
3122
- * @return string
3123
- */
3124
- public function to_standard_date($date)
3125
- {
3126
- return date('Y-m-d', strtotime(str_replace('-', '/', $date)));
3127
- }
3128
-
3129
- /**
3130
- * Render the date
3131
- * @author Webnus <info@webnus.biz>
3132
- * @param string $date
3133
- * @return string
3134
- */
3135
- public function render_date($date)
3136
- {
3137
- return $date;
3138
- }
3139
-
3140
- /**
3141
- * Generate output of MEC Dashboard
3142
- * @author Webnus <info@webnus.biz>
3143
- */
3144
- public function dashboard()
3145
- {
3146
- // Import dashboard page of MEC
3147
- $path = $this->import('app.features.mec.dashboard', true, true);
3148
-
3149
- // Create mec_events table if it's removed for any reason
3150
- $this->create_mec_tables();
3151
-
3152
- ob_start();
3153
- include $path;
3154
- echo $output = ob_get_clean();
3155
- }
3156
-
3157
- /**
3158
- * Redirect on plugin activation
3159
- * @author Webnus <info@webnus.biz>
3160
- */
3161
- public function mec_redirect_after_activate()
3162
- {
3163
- $do_redirection = apply_filters('mec_do_redirection_after_activation', true);
3164
- if(!$do_redirection) return false;
3165
-
3166
- // No need to redirect
3167
- if(!get_option('mec_activation_redirect', false)) return true;
3168
-
3169
- // Delete the option to don't do it always
3170
- delete_option('mec_activation_redirect');
3171
-
3172
- // Redirect to MEC Dashboard
3173
- wp_redirect(admin_url('/admin.php?page=mec-intro'));
3174
- exit;
3175
- }
3176
-
3177
- /**
3178
- * Check if we can show booking module or not
3179
- * @author Webnus <info@webnus.biz>
3180
- * @param object $event
3181
- * @return boolean
3182
- */
3183
- public function can_show_booking_module($event)
3184
- {
3185
- // PRO Version is required
3186
- if(!$this->getPRO()) return false;
3187
-
3188
- // MEC Settings
3189
- $settings = $this->get_settings();
3190
-
3191
- // Booking on single page is disabled
3192
- if(!isset($settings['booking_status']) or (isset($settings['booking_status']) and !$settings['booking_status'])) return false;
3193
-
3194
- $tickets = isset($event->data->tickets) ? $event->data->tickets : array();
3195
- $dates = isset($event->dates) ? $event->dates : array();
3196
- $next_date = isset($dates[0]) ? $dates[0] : (isset($event->date) ? $event->date : array());
3197
-
3198
- // No Dates or no Tickets
3199
- if(!count($dates) or !count($tickets)) return false;
3200
-
3201
- $show_booking_form_interval = (isset($settings['show_booking_form_interval'])) ? $settings['show_booking_form_interval'] : 0;
3202
-
3203
- // Check Show Booking Form Time
3204
- if($show_booking_form_interval)
3205
- {
3206
- $render_date = (isset($next_date['start']['date']) ? trim($next_date['start']['date']) : date('Y-m-d')) .' '. (isset($next_date['start']['hour']) ? trim(sprintf('%02d', $next_date['start']['hour'])) : date('h', current_time('timestamp', 0))) .':'
3207
- . (isset($next_date['start']['minutes']) ? trim(sprintf('%02d', $next_date['start']['minutes'])) : date('i', current_time('timestamp', 0))) . (isset($next_date['start']['ampm']) ? trim($next_date['start']['ampm']) : date('a', current_time('timestamp', 0)));
3208
- if($this->check_date_time_validation('Y-m-d h:ia', strtolower($render_date)))
3209
- {
3210
- $date_diff = $this->date_diff(date('Y-m-d h:ia', current_time('timestamp', 0)), $render_date);
3211
- if(isset($date_diff->d) and !$date_diff->invert and $date_diff->d < 2)
3212
- {
3213
- $minute = $date_diff->d * 24 * 60;
3214
- $minute += $date_diff->h * 60;
3215
- $minute += $date_diff->i;
3216
-
3217
- if($minute > $show_booking_form_interval) return false;
3218
- }
3219
- }
3220
- }
3221
-
3222
- // Booking OnGoing Event Option
3223
- $ongoing_event_book = (isset($settings['booking_ongoing']) and $settings['booking_ongoing'] == '1') ? true : false;
3224
-
3225
- // The event is Expired/Passed
3226
- if($ongoing_event_book)
3227
- {
3228
- if(!isset($next_date['end']) or (isset($next_date['end']) and $this->is_past($next_date['end']['date'], current_time('Y-m-d')))) return false;
3229
- }
3230
- else
3231
- {
3232
- $time_format = 'Y-m-d';
3233
- $render_date = isset($next_date['start']) ? trim($next_date['start']['date']) : false;
3234
-
3235
- if(!trim($event->data->meta['mec_repeat_status']))
3236
- {
3237
- $render_date .= ' ' . sprintf('%02d', $next_date['start']['hour']) . ':' . sprintf('%02d', $next_date['start']['minutes']) . trim($next_date['start']['ampm']);
3238
- $time_format .= ' h:ia';
3239
- }
3240
-
3241
- if(!$render_date or ($render_date and $this->is_past($render_date, current_time($time_format)))) return false;
3242
- }
3243
-
3244
- // MEC payment gateways
3245
- $gateways = $this->get_gateways();
3246
- $is_gateway_enabled = false;
3247
-
3248
- foreach($gateways as $gateway)
3249
- {
3250
- if($gateway->enabled())
3251
- {
3252
- $is_gateway_enabled = true;
3253
- break;
3254
- }
3255
- }
3256
-
3257
- // No Payment gateway is enabled
3258
- if(!$is_gateway_enabled) return false;
3259
-
3260
- return true;
3261
- }
3262
-
3263
- /**
3264
- * Check if we can show countdown module or not
3265
- * @author Webnus <info@webnus.biz>
3266
- * @param object $event
3267
- * @return boolean
3268
- */
3269
- public function can_show_countdown_module($event)
3270
- {
3271
- // MEC Settings
3272
- $settings = $this->get_settings();
3273
-
3274
- // Countdown on single page is disabled
3275
- if(!isset($settings['countdown_status']) or (isset($settings['countdown_status']) and !$settings['countdown_status'])) return false;
3276
-
3277
- $date = $event->date;
3278
-
3279
- $start_date = (isset($date['start']) and isset($date['start']['date'])) ? $date['start']['date'] : date('Y-m-d');
3280
-
3281
- // The event is Expired/Passed
3282
- if($this->is_past($start_date, date('Y-m-d'))) return false;
3283
-
3284
- return true;
3285
- }
3286
-
3287
- /**
3288
- * Get default timezone of WordPress
3289
- * @author Webnus <info@webnus.biz>
3290
- * @return string
3291
- */
3292
- public function get_timezone()
3293
- {
3294
- $timezone_string = get_option('timezone_string');
3295
- $gmt_offset = get_option('gmt_offset');
3296
-
3297
- if(trim($timezone_string) == '' and trim($gmt_offset)) $timezone_string = $this->get_timezone_by_offset($gmt_offset);
3298
- elseif(trim($timezone_string) == '' and trim($gmt_offset) == '0')
3299
- {
3300
- $timezone_string = 'UTC';
3301
- }
3302
-
3303
- return $timezone_string;
3304
- }
3305
-
3306
- /**
3307
- * Get GMT offset based on hours:minutes
3308
- * @author Webnus <info@webnus.biz>
3309
- * @return string
3310
- */
3311
- public function get_gmt_offset()
3312
- {
3313
- $gmt_offset = get_option('gmt_offset');
3314
-
3315
- $minutes = $gmt_offset*60;
3316
- $hour_minutes = sprintf("%02d", $minutes%60);
3317
-
3318
- // Convert the hour into two digits format
3319
- $h = ($minutes-$hour_minutes)/60;
3320
- $hours = sprintf("%02d", abs($h));
3321
-
3322
- // Add - sign to the first of hour if it's negative
3323
- if($h < 0) $hours = '-'.$hours;
3324
-
3325
- return (substr($hours, 0, 1) == '-' ? '' : '+').$hours.':'.(((int) $hour_minutes < 0) ? abs($hour_minutes) : $hour_minutes);
3326
- }
3327
-
3328
- /**
3329
- * Get GMT offset based on seconds
3330
- * @author Webnus <info@webnus.biz>
3331
- * @param $date
3332
- * @return string
3333
- */
3334
- public function get_gmt_offset_seconds($date = NULL)
3335
- {
3336
- if($date)
3337
- {
3338
- $timezone = new DateTimeZone($this->get_timezone());
3339
-
3340
- // Convert to Date
3341
- if(is_numeric($date)) $date = date('Y-m-d', $date);
3342
-
3343
- $target = new DateTime($date, $timezone);
3344
- return $timezone->getOffset($target);
3345
- }
3346
- else
3347
- {
3348
- $gmt_offset = get_option('gmt_offset');
3349
- $seconds = $gmt_offset*3600;
3350
-
3351
- return (substr($gmt_offset, 0, 1) == '-' ? '' : '+').$seconds;
3352
- }
3353
- }
3354
-
3355
- public function get_timezone_by_offset($offset)
3356
- {
3357
- $seconds = $offset*3600;
3358
-
3359
- $timezone = timezone_name_from_abbr('', $seconds, 1);
3360
- if($timezone === false) $timezone = timezone_name_from_abbr('', $seconds, 0);
3361
-
3362
- if($timezone === false)
3363
- {
3364
- $timezones = array(
3365
- '-12' => 'Pacific/Auckland',
3366
- '-11.5' => 'Pacific/Auckland', // Approx
3367
- '-11' => 'Pacific/Apia',
3368
- '-10.5' => 'Pacific/Apia', // Approx
3369
- '-10' => 'Pacific/Honolulu',
3370
- '-9.5' => 'Pacific/Honolulu', // Approx
3371
- '-9' => 'America/Anchorage',
3372
- '-8.5' => 'America/Anchorage', // Approx
3373
- '-8' => 'America/Los_Angeles',
3374
- '-7.5' => 'America/Los_Angeles', // Approx
3375
- '-7' => 'America/Denver',
3376
- '-6.5' => 'America/Denver', // Approx
3377
- '-6' => 'America/Chicago',
3378
- '-5.5' => 'America/Chicago', // Approx
3379
- '-5' => 'America/New_York',
3380
- '-4.5' => 'America/New_York', // Approx
3381
- '-4' => 'America/Halifax',
3382
- '-3.5' => 'America/Halifax', // Approx
3383
- '-3' => 'America/Sao_Paulo',
3384
- '-2.5' => 'America/Sao_Paulo', // Approx
3385
- '-2' => 'America/Sao_Paulo',
3386
- '-1.5' => 'Atlantic/Azores', // Approx
3387
- '-1' => 'Atlantic/Azores',
3388
- '-0.5' => 'UTC', // Approx
3389
- '0' => 'UTC',
3390
- '0.5' => 'UTC', // Approx
3391
- '1' => 'Europe/Paris',
3392
- '1.5' => 'Europe/Paris', // Approx
3393
- '2' => 'Europe/Helsinki',
3394
- '2.5' => 'Europe/Helsinki', // Approx
3395
- '3' => 'Europe/Moscow',
3396
- '3.5' => 'Europe/Moscow', // Approx
3397
- '4' => 'Asia/Dubai',
3398
- '4.5' => 'Asia/Tehran',
3399
- '5' => 'Asia/Karachi',
3400
- '5.5' => 'Asia/Kolkata',
3401
- '5.75' => 'Asia/Katmandu',
3402
- '6' => 'Asia/Yekaterinburg',
3403
- '6.5' => 'Asia/Yekaterinburg', // Approx
3404
- '7' => 'Asia/Krasnoyarsk',
3405
- '7.5' => 'Asia/Krasnoyarsk', // Approx
3406
- '8' => 'Asia/Shanghai',
3407
- '8.5' => 'Asia/Shanghai', // Approx
3408
- '8.75' => 'Asia/Tokyo', // Approx
3409
- '9' => 'Asia/Tokyo',
3410
- '9.5' => 'Asia/Tokyo', // Approx
3411
- '10' => 'Australia/Melbourne',
3412
- '10.5' => 'Australia/Adelaide',
3413
- '11' => 'Australia/Melbourne', // Approx
3414
- '11.5' => 'Pacific/Auckland', // Approx
3415
- '12' => 'Pacific/Auckland',
3416
- '12.75' => 'Pacific/Apia', // Approx
3417
- '13' => 'Pacific/Apia',
3418
- '13.75' => 'Pacific/Honolulu', // Approx
3419
- '14' => 'Pacific/Honolulu',
3420
- );
3421
-
3422
- $timezone = isset($timezones[$offset]) ? $timezones[$offset] : NULL;
3423
- }
3424
-
3425
- return $timezone;
3426
- }
3427
-
3428
- /**
3429
- * Get status of Google recaptcha
3430
- * @author Webnus <info@webnus.biz>
3431
- * @param string $section
3432
- * @return boolean
3433
- */
3434
- public function get_recaptcha_status($section = '')
3435
- {
3436
- // MEC Settings
3437
- $settings = $this->get_settings();
3438
-
3439
- $status = false;
3440
-
3441
- // Check if the feature is enabled
3442
- if(isset($settings['google_recaptcha_status']) and $settings['google_recaptcha_status']) $status = true;
3443
-
3444
- // Check if the feature is enabled for certain section
3445
- if($status and trim($section) and (!isset($settings['google_recaptcha_'.$section]) or (isset($settings['google_recaptcha_'.$section]) and !$settings['google_recaptcha_'.$section]))) $status = false;
3446
-
3447
- // Check if site key and secret key is not empty
3448
- if($status and (!isset($settings['google_recaptcha_sitekey']) or (isset($settings['google_recaptcha_sitekey']) and trim($settings['google_recaptcha_sitekey']) == ''))) $status = false;
3449
- if($status and (!isset($settings['google_recaptcha_secretkey']) or (isset($settings['google_recaptcha_secretkey']) and trim($settings['google_recaptcha_secretkey']) == ''))) $status = false;
3450
-
3451
- return $status;
3452
- }
3453
-
3454
- /**
3455
- * Get re-captcha verification from Google servers
3456
- * @author Webnus <info@webnus.biz>
3457
- * @param string $remote_ip
3458
- * @param string $response
3459
- * @return boolean
3460
- */
3461
- public function get_recaptcha_response($response, $remote_ip = NULL)
3462
- {
3463
- // get the IP
3464
- if(is_null($remote_ip)) $remote_ip = (isset($_SERVER["REMOTE_ADDR"]) ? $_SERVER["REMOTE_ADDR"] : '');
3465
-
3466
- // MEC Settings
3467
- $settings = $this->get_settings();
3468
-
3469
- $data = array('secret'=>(isset($settings['google_recaptcha_secretkey']) ? $settings['google_recaptcha_secretkey'] : ''), 'remoteip'=>$remote_ip, 'v'=>'php_1.0', 'response'=>$response);
3470
-
3471
- $req = "";
3472
- foreach($data as $key=>$value) $req .= $key.'='.urlencode(stripslashes($value)).'&';
3473
-
3474
- // Validate the re-captcha
3475
- $getResponse = $this->get_web_page("https://www.google.com/recaptcha/api/siteverify?".trim($req, '& '));
3476
-
3477
- $answers = json_decode($getResponse, true);
3478
-
3479
- if(isset($answers['success']) and trim($answers['success'])) return true;
3480
- else return false;
3481
- }
3482
-
3483
- /**
3484
- * Get current language of WordPress
3485
- * @author Webnus <info@webnus.biz>
3486
- * @return string
3487
- */
3488
- public function get_current_language()
3489
- {
3490
- return apply_filters('plugin_locale', get_locale(), 'modern-events-calendar-lite');
3491
- }
3492
-
3493
- /**
3494
- * Write to a log file
3495
- * @author Webnus <info@webnus.biz>
3496
- * @param string $log_msg
3497
- * @param string $path
3498
- */
3499
- public function debug_log($log_msg, $path = '')
3500
- {
3501
- if(trim($path) == '') $path = MEC_ABSPATH. 'log.txt';
3502
-
3503
- $fh = fopen($path, 'a');
3504
- fwrite($fh, $log_msg);
3505
- }
3506
-
3507
- /**
3508
- * Filter Skin parameters to add taxonomy, etc filters that come from WordPress Query
3509
- * This used for taxonomy archive pages etc that are handled by WordPress itself
3510
- * @author Webnus <info@webnus.biz>
3511
- * @param array $atts
3512
- * @return array
3513
- */
3514
- public function add_search_filters($atts = array())
3515
- {
3516
- // Taxonomy Archive Page
3517
- if(is_tax())
3518
- {
3519
- $query = get_queried_object();
3520
- $term_id = $query->term_id;
3521
-
3522
- if(!isset($atts['category'])) $atts['category'] = '';
3523
-
3524
- $atts['category'] = trim(trim($atts['category'], ', ').','.$term_id, ', ');
3525
- }
3526
-
3527
- return $atts;
3528
- }
3529
-
3530
- /**
3531
- * Filter TinyMce Buttons
3532
- * @author Webnus <info@webnus.biz>
3533
- * @param array $buttons
3534
- * @return array
3535
- */
3536
- public function add_mce_buttons($buttons)
3537
- {
3538
- array_push($buttons, 'mec_mce_buttons');
3539
- return $buttons;
3540
- }
3541
-
3542
- /**
3543
- * Filter TinyMce plugins
3544
- * @author Webnus <info@webnus.biz>
3545
- * @param array $plugins
3546
- * @return array
3547
- */
3548
- public function add_mce_external_plugins($plugins)
3549
- {
3550
- $plugins['mec_mce_buttons'] = $this->asset('js/backend.js');
3551
- return $plugins;
3552
- }
3553
-
3554
- /**
3555
- * Return JSON output id and the name of a post type
3556
- * @author Webnus <info@webnus.biz>
3557
- * @param string $post_type
3558
- * @return string JSON
3559
- */
3560
- public function mce_get_shortcode_list($post_type = 'mec_calendars')
3561
- {
3562
- if(post_type_exists($post_type))
3563
- {
3564
- $args = array('post_type' => $post_type, 'post_status' => 'publish', 'posts_per_page' => -1, 'order' => 'DESC');
3565
- $shortcodes_list = get_posts($args);
3566
- if(count($shortcodes_list))
3567
- {
3568
- $shortcodes = array();
3569
- $shortcodes['shortcodes'] = array();
3570
- foreach($shortcodes_list as $shortcode)
3571
- {
3572
- $shortcode_item = array();
3573
- $shortcode_item['ID'] = $shortcode->ID;
3574
- // PostName
3575
- $shortcode_item['PN'] = $shortcode->post_name;
3576
- array_push($shortcodes['shortcodes'], $shortcode_item);
3577
- }
3578
- $shortcodes['mce_title'] = __('M.E. Calender', 'modern-events-calendar-lite');
3579
- return json_encode($shortcodes);
3580
- }
3581
- }
3582
- return false;
3583
- }
3584
-
3585
- /**
3586
- * Return date_diff
3587
- * @author Webnus <info@webnus.biz>
3588
- * @param string $start_date
3589
- * @param string $end_date
3590
- * @return object
3591
- */
3592
- public function date_diff($start_date, $end_date)
3593
- {
3594
- if(version_compare(PHP_VERSION, '5.3.0', '>=')) return date_diff(date_create($start_date), date_create($end_date));
3595
- else
3596
- {
3597
- $start = new DateTime($start_date);
3598
- $end = new DateTime($end_date);
3599
- $days = round(($end->format('U') - $start->format('U')) / (60*60*24));
3600
-
3601
- $interval = new stdClass();
3602
- $interval->days = abs($days);
3603
- $interval->invert = ($days >= 0 ? 0 : 1);
3604
-
3605
- return $interval;
3606
- }
3607
- }
3608
-
3609
- /**
3610
- * Convert a certain time into seconds (Hours should be in 24 hours format)
3611
- * @author Webnus <info@webnus.biz>
3612
- * @param int $hours
3613
- * @param int $minutes
3614
- * @param int $seconds
3615
- * @return int
3616
- */
3617
- public function time_to_seconds($hours, $minutes = 0, $seconds = 0)
3618
- {
3619
- return (($hours * 3600) + ($minutes * 60) + $seconds);
3620
- }
3621
-
3622
- /**
3623
- * Convert a 12 hour format hour to a 24 format hour
3624
- * @author Webnus <info@webnus.biz>
3625
- * @param int $hour
3626
- * @param string $ampm
3627
- * @return int
3628
- */
3629
- public function to_24hours($hour, $ampm = 'PM')
3630
- {
3631
- $ampm = strtoupper($ampm);
3632
-
3633
- if($ampm == 'AM' and $hour < 12) return $hour;
3634
- elseif($ampm == 'AM' and $hour == 12) return 24;
3635
- elseif($ampm == 'PM' and $hour < 12) return $hour+12;
3636
- elseif($ampm == 'PM' and $hour == 12) return 12;
3637
- elseif($ampm == 'PM' and $hour > 12) return $hour;
3638
- }
3639
-
3640
- /**
3641
- * Get rendered events based on a certain criteria
3642
- * @author Webnus <info@webnus.biz>
3643
- * @param array $args
3644
- * @return array
3645
- */
3646
- public function get_rendered_events($args = array())
3647
- {
3648
- $events = array();
3649
- $sorted = array();
3650
-
3651
- // Parse the args
3652
- $args = wp_parse_args($args, array(
3653
- 'post_type'=>$this->get_main_post_type(),
3654
- 'posts_per_page'=>'-1',
3655
- 'post_status'=>'publish'
3656
- )
3657
- );
3658
-
3659
- // The Query
3660
- $query = new WP_Query($args);
3661
-
3662
- if($query->have_posts())
3663
- {
3664
- // MEC Render Library
3665
- $render = $this->getRender();
3666
-
3667
- // The Loop
3668
- while($query->have_posts())
3669
- {
3670
- $query->the_post();
3671
-
3672
- $event_id = get_the_ID();
3673
- $rendered = $render->data($event_id);
3674
-
3675
- $data = new stdClass();
3676
- $data->ID = $event_id;
3677
- $data->data = $rendered;
3678
- $data->dates = $render->dates($event_id, $rendered, 6);
3679
- $data->date = isset($data->dates[0]) ? $data->dates[0] : array();
3680
-
3681
- // Caclculate event start time
3682
- $event_start_time = strtotime($data->date['start']['date']) + $rendered->meta['mec_start_day_seconds'];
3683
-
3684
- // Add the event into the to be sorted array
3685
- if(!isset($sorted[$event_start_time])) $sorted[$event_start_time] = array();
3686
- $sorted[$event_start_time][] = $data;
3687
- }
3688
-
3689
- ksort($sorted, SORT_NUMERIC);
3690
- }
3691
-
3692
- // Add sorted events to the results
3693
- foreach($sorted as $sorted_events)
3694
- {
3695
- if(!is_array($sorted_events)) continue;
3696
- foreach($sorted_events as $sorted_event) $events[$sorted_event->ID] = $sorted_event;
3697
- }
3698
-
3699
- // Restore original Post Data
3700
- wp_reset_postdata();
3701
-
3702
- return $events;
3703
- }
3704
-
3705
- /**
3706
- * Duplicate an event
3707
- * @author Webnus <info@webnus.biz>
3708
- * @param int $post_id
3709
- * @return boolean|int
3710
- */
3711
- public function duplicate($post_id)
3712
- {
3713
- // MEC DB Library
3714
- $db = $this->getDB();
3715
-
3716
- $post = get_post($post_id);
3717
-
3718
- // Post is not exists
3719
- if(!$post) return false;
3720
-
3721
- //new post data array
3722
- $args = array
3723
- (
3724
- 'comment_status'=>$post->comment_status,
3725
- 'ping_status'=>$post->ping_status,
3726
- 'post_author'=>$post->post_author,
3727
- 'post_content'=>$post->post_content,
3728
- 'post_excerpt'=>$post->post_excerpt,
3729
- 'post_name'=>$post->post_name,
3730
- 'post_parent'=>$post->post_parent,
3731
- 'post_password'=>$post->post_password,
3732
- 'post_status'=>'draft',
3733
- 'post_title'=>sprintf(__('Copy of %s', 'modern-events-calendar-lite'), $post->post_title),
3734
- 'post_type'=>$post->post_type,
3735
- 'to_ping'=>$post->to_ping,
3736
- 'menu_order'=>$post->menu_order
3737
- );
3738
-
3739
- // insert the new post
3740
- $new_post_id = wp_insert_post($args);
3741
-
3742
- // get all current post terms ad set them to the new post draft
3743
- $taxonomies = get_object_taxonomies($post->post_type);
3744
- foreach($taxonomies as $taxonomy)
3745
- {
3746
- $post_terms = wp_get_object_terms($post_id, $taxonomy, array('fields'=>'slugs'));
3747
- wp_set_object_terms($new_post_id, $post_terms, $taxonomy, false);
3748
- }
3749
-
3750
- // duplicate all post meta
3751
- $post_metas = $db->select("SELECT `meta_key`, `meta_value` FROM `#__postmeta` WHERE `post_id`='$post_id'", 'loadObjectList');
3752
- if(count($post_metas) != 0)
3753
- {
3754
- $sql_query = "INSERT INTO `#__postmeta` (post_id, meta_key, meta_value) ";
3755
-
3756
- foreach($post_metas as $meta_info)
3757
- {
3758
- $meta_key = $meta_info->meta_key;
3759
- $meta_value = addslashes($meta_info->meta_value);
3760
-
3761
- $sql_query_sel[] = "SELECT $new_post_id, '$meta_key', '$meta_value'";
3762
- }
3763
-
3764
- $sql_query .= implode(" UNION ALL ", $sql_query_sel);
3765
- $db->q($sql_query);
3766
- }
3767
-
3768
- // Duplicate MEC record
3769
- $mec_data = $db->select("SELECT * FROM `#__mec_events` WHERE `post_id`='$post_id'", 'loadAssoc');
3770
-
3771
- $q1 = "";
3772
- $q2 = "";
3773
- foreach($mec_data as $key=>$value)
3774
- {
3775
- if(in_array($key, array('id', 'post_id'))) continue;
3776
-
3777
- $q1 .= "`$key`,";
3778
- $q2 .= "'$value',";
3779
- }
3780
-
3781
- $db->q("INSERT INTO `#__mec_events` (`post_id`,".trim($q1, ', ').") VALUES ('$new_post_id',".trim($q2, ', ').")");
3782
-
3783
- // Update Schedule
3784
- $schedule = $this->getSchedule();
3785
- $schedule->reschedule($new_post_id);
3786
-
3787
- return $new_post_id;
3788
- }
3789
-
3790
- /**
3791
- * Returns start/end date label
3792
- * @author Webnus <info@webnus.biz>
3793
- * @param array $start
3794
- * @param array $end
3795
- * @param string $format
3796
- * @param string $separator
3797
- * @return string
3798
- */
3799
- public function date_label($start, $end, $format, $separator = ' - ')
3800
- {
3801
- $start_timestamp = strtotime($start['date']);
3802
- $end_timestamp = strtotime($end['date']);
3803
-
3804
- if($start_timestamp >= $end_timestamp) return '<span class="mec-start-date-label" itemprop="startDate">' . date_i18n($format, $start_timestamp) . '</span>';
3805
- elseif($start_timestamp < $end_timestamp)
3806
- {
3807
- $start_date = date_i18n($format, $start_timestamp);
3808
- $end_date = date_i18n($format, $end_timestamp);
3809
-
3810
- if($start_date == $end_date) return '<span class="mec-start-date-label" itemprop="startDate">' . $start_date . '</span>';
3811
- else return '<span class="mec-start-date-label" itemprop="startDate">' . date_i18n($format, $start_timestamp).'</span><span class="mec-end-date-label" itemprop="endDate">'.$separator.date_i18n($format, $end_timestamp).'</span>';
3812
- }
3813
- }
3814
-
3815
- /**
3816
- * Returns start/end time labels
3817
- * @author Webnus <info@webnus.biz>
3818
- * @param string $start
3819
- * @param string $end
3820
- * @param array $args
3821
- * @return string
3822
- */
3823
- public function mec_include_time_labels($start = '', $end = '', $args = array())
3824
- {
3825
- $class = isset($args['class']) ? esc_attr($args['class']) : 'mec-time-details';
3826
-
3827
- $return = "<div class='{$class}'>";
3828
- if(trim($start)) $return .= '<span class="mec-start-time">' . $start . '</span>';
3829
- if(trim($end)) $return .= ' - <span class="mec-end-time">' . $end . '</span>';
3830
- $return .= '</div>';
3831
-
3832
- return $return;
3833
- }
3834
-
3835
- /**
3836
- * Returns end date of an event based on start date
3837
- * @author Webnus <info@webnus.biz>
3838
- * @param string $date
3839
- * @param array $event
3840
- * @return string
3841
- */
3842
- public function get_end_date($date, $event = array())
3843
- {
3844
- $start_date = isset($event->meta['mec_date']['start']) ? $event->meta['mec_date']['start'] : array();
3845
- $end_date = isset($event->meta['mec_date']['end']) ? $event->meta['mec_date']['end'] : array();
3846
-
3847
- $event_period = $this->date_diff($start_date['date'], $end_date['date']);
3848
- $event_period_days = $event_period ? $event_period->days : 0;
3849
-
3850
- $finish_date = array('date'=>$event->mec->end, 'hour'=>$event->meta['mec_date']['end']['hour'], 'minutes'=>$event->meta['mec_date']['end']['minutes'], 'ampm'=>$event->meta['mec_date']['end']['ampm']);
3851
-
3852
- // Custom Dates
3853
- $db = $this->getDB();
3854
- $custom_date = $db->select("SELECT `dend` FROM `#__mec_dates` WHERE `post_id`='".$event->ID."' AND `dstart`<='".$date."' AND `dend`>='".$date."' ORDER BY `id` DESC LIMIT 1", 'loadResult');
3855
-
3856
- // Event Passed
3857
- $past = $this->is_past($finish_date['date'], $date);
3858
-
3859
- // Normal event
3860
- if(isset($event->mec->repeat) and $event->mec->repeat == '0')
3861
- {
3862
- return isset($end_date['date']) ? $end_date['date'] : $date;
3863
- }
3864
- // Custom Days
3865
- elseif($custom_date)
3866
- {
3867
- return $custom_date;
3868
- }
3869
- // Past Event
3870
- elseif($past)
3871
- {
3872
- return isset($end_date['date']) ? $end_date['date'] : $date;
3873
- }
3874
- elseif(!$past)
3875
- {
3876
- /**
3877
- * Multiple Day Event
3878
- * Check to see if today is between start day and end day.
3879
- * For example start day is 5 and end day is 15 but we're in 9th so only 6 days remained till ending the event not 10 days.
3880
- */
3881
- if($event_period_days)
3882
- {
3883
- $start_day = date('j', strtotime($start_date['date']));
3884
- $day = date('j', strtotime($date));
3885
-
3886
- $passed_days = 0;
3887
- if($day >= $start_day) $passed_days = $day - $start_day;
3888
- else $passed_days = ($day+date('t', strtotime($start_date['date']))) - $start_day;
3889
-
3890
- $event_period_days = $event_period_days - $passed_days;
3891
- }
3892
-
3893
- return date('Y-m-d', strtotime('+'.$event_period_days.' Days', strtotime($date)));
3894
- }
3895
- }
3896
-
3897
- /**
3898
- * Get Archive Status of MEC
3899
- * @author Webnus <info@webnus.biz>
3900
- * @return int
3901
- */
3902
- public function get_archive_status()
3903
- {
3904
- $settings = $this->get_settings();
3905
-
3906
- $status = isset($settings['archive_status']) ? $settings['archive_status'] : '1';
3907
- return apply_filters('mec_archive_status', $status);
3908
- }
3909
-
3910
- /**
3911
- * Check to see if a table exists or not
3912
- * @author Webnus <info@webnus.biz>
3913
- * @param string $table
3914
- * @return boolean
3915
- */
3916
- public function table_exists($table = 'mec_events')
3917
- {
3918
- // MEC DB library
3919
- $db = $this->getDB();
3920
-
3921
- return $db->q("SHOW TABLES LIKE '#__$table'");
3922
- }
3923
-
3924
- /**
3925
- * Create MEC Tables
3926
- * @author Webnus <info@webnus.biz>
3927
- * @return boolean
3928
- */
3929
- public function create_mec_tables()
3930
- {
3931
- // MEC Events table already exists
3932
- if($this->table_exists('mec_events') and $this->table_exists('mec_dates')) return true;
3933
-
3934
- // MEC File library
3935
- $file = $this->getFile();
3936
-
3937
- // MEC DB library
3938
- $db = $this->getDB();
3939
-
3940
- // Run Queries
3941
- $query_file = MEC_ABSPATH. 'assets' .DS. 'sql' .DS. 'tables.sql';
3942
- if($file->exists($query_file))
3943
- {
3944
- $queries = $file->read($query_file);
3945
- $sqls = explode(';', $queries);
3946
-
3947
- foreach($sqls as $sql)
3948
- {
3949
- $sql = trim($sql, '; ');
3950
- if(trim($sql) == '') continue;
3951
-
3952
- $sql .= ';';
3953
-
3954
- try
3955
- {
3956
- $db->q($sql);
3957
- }
3958
- catch (Exception $e){}
3959
- }
3960
- }
3961
-
3962
- return true;
3963
- }
3964
-
3965
- /**
3966
- * Return HTML email type
3967
- * @author Webnus <info@webnus.biz>
3968
- * @param string $content_type
3969
- * @return string
3970
- */
3971
- public function html_email_type($content_type)
3972
- {
3973
- return 'text/html';
3974
- }
3975
-
3976
- public function get_next_upcoming_event()
3977
- {
3978
- MEC::import('app.skins.list', true);
3979
-
3980
- // Get list skin
3981
- $list = new MEC_skin_list();
3982
-
3983
- // Attributes
3984
- $atts = array(
3985
- 'show_past_events'=>0,
3986
- 'start_date_type'=>'today',
3987
- 'sk-options'=> array(
3988
- 'list' => array('limit'=>1)
3989
- ),
3990
- );
3991
-
3992
- // Initialize the skin
3993
- $list->initialize($atts);
3994
-
3995
- // Fetch the events
3996
- $list->fetch();
3997
-
3998
- $events = $list->events;
3999
- $key = key($events);
4000
-
4001
- return (isset($events[$key][0]) ? $events[$key][0] : array());
4002
- }
4003
-
4004
- /**
4005
- * Return a web page
4006
- * @author Webnus <info@webnus.biz>
4007
- * @param string $url
4008
- * @return string
4009
- */
4010
- public function get_web_page($url)
4011
- {
4012
- $result = false;
4013
-
4014
- // Doing WordPress Remote
4015
- if(function_exists('wp_remote_get'))
4016
- {
4017
- $result = wp_remote_retrieve_body(wp_remote_get($url, array(
4018
- 'body' => null,
4019
- 'timeout' => '120',
4020
- 'redirection' => '10',
4021
- )));
4022
- }
4023
-
4024
- // Doing FGC
4025
- if($result == false)
4026
- {
4027
- $http = array();
4028
- $result = @file_get_contents($url, false, stream_context_create(array('http'=>$http)));
4029
- }
4030
-
4031
- return $result;
4032
- }
4033
-
4034
- public function save_events($events = array())
4035
- {
4036
- $ids = array();
4037
-
4038
- foreach($events as $event) $ids[] = $this->save_event($event, (isset($event['ID']) ? $event['ID'] : NULL));
4039
- return $ids;
4040
- }
4041
-
4042
- public function save_event($event = array(), $post_id = NULL)
4043
- {
4044
- $post = array('post_title'=>$event['title'], 'post_content'=>(isset($event['content']) ? $event['content'] : ''), 'post_type'=>$this->get_main_post_type(), 'post_status'=>(isset($event['status']) ? $event['status'] : 'publish'));
4045
-
4046
- // Update previously inserted post
4047
- if(!is_null($post_id)) $post['ID'] = $post_id;
4048
-
4049
- $post_id = wp_insert_post($post);
4050
-
4051
- update_post_meta($post_id, 'mec_location_id', (isset($event['location_id']) ? $event['location_id'] : 1));
4052
- update_post_meta($post_id, 'mec_dont_show_map', 0);
4053
- update_post_meta($post_id, 'mec_organizer_id', (isset($event['organizer_id']) ? $event['organizer_id'] : 1));
4054
-
4055
- $start_time_hour = (isset($event['start_time_hour']) ? $event['start_time_hour'] : 8);
4056
- $start_time_minutes = (isset($event['start_time_minutes']) ? $event['start_time_minutes'] : 0);
4057
- $start_time_ampm = (isset($event['start_time_ampm']) ? $event['start_time_ampm'] : 'AM');
4058
-
4059
- $end_time_hour = (isset($event['end_time_hour']) ? $event['end_time_hour'] : 6);
4060
- $end_time_minutes = (isset($event['end_time_minutes']) ? $event['end_time_minutes'] : 0);
4061
- $end_time_ampm = (isset($event['end_time_ampm']) ? $event['end_time_ampm'] : 'PM');
4062
-
4063
- $allday = (isset($event['allday']) ? $event['allday'] : 0);
4064
- $time_comment = (isset($event['time_comment']) ? $event['time_comment'] : '');
4065
- $hide_time = ((isset($event['date']) and isset($event['date']['hide_time'])) ? $event['date']['hide_time'] : 0);
4066
- $hide_end_time = ((isset($event['date']) and isset($event['date']['hide_end_time'])) ? $event['date']['hide_end_time'] : 0);
4067
-
4068
- $day_start_seconds = $this->time_to_seconds($this->to_24hours($start_time_hour, $start_time_ampm), $start_time_minutes);
4069
- $day_end_seconds = $this->time_to_seconds($this->to_24hours($end_time_hour, $end_time_ampm), $end_time_minutes);
4070
-
4071
- update_post_meta($post_id, 'mec_allday', $allday);
4072
- update_post_meta($post_id, 'mec_hide_time', $hide_time);
4073
- update_post_meta($post_id, 'mec_hide_end_time', $hide_end_time);
4074
-
4075
- update_post_meta($post_id, 'mec_start_date', $event['start']);
4076
- update_post_meta($post_id, 'mec_start_time_hour', $start_time_hour);
4077
- update_post_meta($post_id, 'mec_start_time_minutes', $start_time_minutes);
4078
- update_post_meta($post_id, 'mec_start_time_ampm', $start_time_ampm);
4079
- update_post_meta($post_id, 'mec_start_day_seconds', $day_start_seconds);
4080
-
4081
- update_post_meta($post_id, 'mec_end_date', $event['end']);
4082
- update_post_meta($post_id, 'mec_end_time_hour', $end_time_hour);
4083
- update_post_meta($post_id, 'mec_end_time_minutes', $end_time_minutes);
4084
- update_post_meta($post_id, 'mec_end_time_ampm', $end_time_ampm);
4085
- update_post_meta($post_id, 'mec_end_day_seconds', $day_end_seconds);
4086
-
4087
- update_post_meta($post_id, 'mec_repeat_status', $event['repeat_status']);
4088
- update_post_meta($post_id, 'mec_repeat_type', $event['repeat_type']);
4089
- update_post_meta($post_id, 'mec_repeat_interval', $event['interval']);
4090
-
4091
- update_post_meta($post_id, 'mec_certain_weekdays', explode(',', trim((isset($event['weekdays']) ? $event['weekdays'] : ''), ', ')));
4092
-
4093
- $date = array
4094
- (
4095
- 'start'=>array('date'=>$event['start'], 'hour'=>$start_time_hour, 'minutes'=>$start_time_minutes, 'ampm'=>$start_time_ampm),
4096
- 'end'=>array('date'=>$event['end'], 'hour'=>$end_time_hour, 'minutes'=>$end_time_minutes, 'ampm'=>$end_time_ampm),
4097
- 'repeat'=>((isset($event['date']) and isset($event['date']['repeat']) and is_array($event['date']['repeat'])) ? $event['date']['repeat'] : array()),
4098
- 'allday'=>$allday,
4099
- 'hide_time'=>((isset($event['date']) and isset($event['date']['hide_time'])) ? $event['date']['hide_time'] : 0),
4100
- 'hide_end_time'=>((isset($event['date']) and isset($event['date']['hide_end_time'])) ? $event['date']['hide_end_time'] : 0),
4101
- 'comment'=>$time_comment,
4102
- );
4103
-
4104
- update_post_meta($post_id, 'mec_date', $date);
4105
-
4106
- // Creating $mec array for inserting in mec_events table
4107
- $mec = array('post_id'=>$post_id, 'start'=>$event['start'], 'repeat'=>$event['repeat_status'], 'rinterval'=>$event['interval'], 'time_start'=>$day_start_seconds, 'time_end'=>$day_end_seconds);
4108
-
4109
- // Add parameters to the $mec
4110
- $mec['end'] = isset($event['finish']) ? $event['finish'] : '0000-00-00';
4111
- $mec['year'] = isset($event['year']) ? $event['year'] : NULL;
4112
- $mec['month'] = isset($event['month']) ? $event['month'] : NULL;
4113
- $mec['day'] = isset($event['day']) ? $event['day'] : NULL;
4114
- $mec['week'] = isset($event['week']) ? $event['week'] : NULL;
4115
- $mec['weekday'] = isset($event['weekday']) ? $event['weekday'] : NULL;
4116
- $mec['weekdays'] = isset($event['weekdays']) ? $event['weekdays'] : NULL;
4117
- $mec['days'] = isset($event['days']) ? $event['days'] : '';
4118
- $mec['not_in_days'] = isset($event['not_in_days']) ? $event['not_in_days'] : '';
4119
-
4120
- // MEC DB Library
4121
- $db = $this->getDB();
4122
-
4123
- // Update MEC Events Table
4124
- $mec_event_id = $db->select("SELECT `id` FROM `#__mec_events` WHERE `post_id`='$post_id'", 'loadResult');
4125
-
4126
- if(!$mec_event_id)
4127
- {
4128
- $q1 = "";
4129
- $q2 = "";
4130
-
4131
- foreach($mec as $key=>$value)
4132
- {
4133
- $q1 .= "`$key`,";
4134
-
4135
- if(is_null($value)) $q2 .= "NULL,";
4136
- else $q2 .= "'$value',";
4137
- }
4138
-
4139
- $db->q("INSERT INTO `#__mec_events` (".trim($q1, ', ').") VALUES (".trim($q2, ', ').")", 'INSERT');
4140
- }
4141
- else
4142
- {
4143
- $q = "";
4144
-
4145
- foreach($mec as $key=>$value)
4146
- {
4147
- if(is_null($value)) $q .= "`$key`=NULL,";
4148
- else $q .= "`$key`='$value',";
4149
- }
4150
-
4151
- $db->q("UPDATE `#__mec_events` SET ".trim($q, ', ')." WHERE `id`='$mec_event_id'");
4152
- }
4153
-
4154
- if(isset($event['meta']) and is_array($event['meta'])) foreach($event['meta'] as $key=>$value) update_post_meta($post_id, $key, $value);
4155
-
4156
- // Update Schedule
4157
- $schedule = $this->getSchedule();
4158
- $schedule->reschedule($post_id, $schedule->get_reschedule_maximum($event['repeat_type']));
4159
-
4160
- return $post_id;
4161
- }
4162
-
4163
- public function save_category($category = array())
4164
- {
4165
- $name = isset($category['name']) ? $category['name'] : '';
4166
- if(!trim($name)) return false;
4167
-
4168
- $term = get_term_by('name', $name, 'mec_category');
4169
-
4170
- // Term already exists
4171
- if(is_object($term) and isset($term->term_id)) return $term->term_id;
4172
-
4173
- $term = wp_insert_term($name, 'mec_category');
4174
-
4175
- // An error ocurred
4176
- if(is_wp_error($term)) return false;
4177
-
4178
- $category_id = $term['term_id'];
4179
- if(!$category_id) return false;
4180
-
4181
- return $category_id;
4182
- }
4183
-
4184
- public function save_tag($tag = array())
4185
- {
4186
- $name = isset($tag['name']) ? $tag['name'] : '';
4187
- if(!trim($name)) return false;
4188
-
4189
- $term = get_term_by('name', $name, 'post_tag');
4190
-
4191
- // Term already exists
4192
- if(is_object($term) and isset($term->term_id)) return $term->term_id;
4193
-
4194
- $term = wp_insert_term($name, 'post_tag');
4195
-
4196
- // An error ocurred
4197
- if(is_wp_error($term)) return false;
4198
-
4199
- $tag_id = $term['term_id'];
4200
- if(!$tag_id) return false;
4201
-
4202
- return $tag_id;
4203
- }
4204
-
4205
- public function save_label($label = array())
4206
- {
4207
- $name = isset($label['name']) ? $label['name'] : '';
4208
- if(!trim($name)) return false;
4209
-
4210
- $term = get_term_by('name', $name, 'mec_label');
4211
-
4212
- // Term already exists
4213
- if(is_object($term) and isset($term->term_id)) return $term->term_id;
4214
-
4215
- $term = wp_insert_term($name, 'mec_label');
4216
-
4217
- // An error ocurred
4218
- if(is_wp_error($term)) return false;
4219
-
4220
- $label_id = $term['term_id'];
4221
- if(!$label_id) return false;
4222
-
4223
- $color = isset($label['color']) ? $label['color'] : '';
4224
- update_term_meta($label_id, 'color', $color);
4225
-
4226
- return $label_id;
4227
- }
4228
-
4229
- public function save_organizer($organizer = array())
4230
- {
4231
- $name = isset($organizer['name']) ? $organizer['name'] : '';
4232
- if(!trim($name)) return false;
4233
-
4234
- $term = get_term_by('name', $name, 'mec_organizer');
4235
-
4236
- // Term already exists
4237
- if(is_object($term) and isset($term->term_id)) return $term->term_id;
4238
-
4239
- $term = wp_insert_term($name, 'mec_organizer');
4240
-
4241
- // An error ocurred
4242
- if(is_wp_error($term)) return false;
4243
-
4244
- $organizer_id = $term['term_id'];
4245
- if(!$organizer_id) return false;
4246
-
4247
- if ( isset($organizer['tel']) && strpos($organizer['tel'], '@') !== false )
4248
- {
4249
- // Just for EventON
4250
- $tel = '';
4251
- $email = (isset($organizer['tel']) and trim($organizer['tel'])) ? $organizer['tel'] : '';
4252
- } else {
4253
- $tel = (isset($organizer['tel']) and trim($organizer['tel'])) ? $organizer['tel'] : '';
4254
- $email = (isset($organizer['email']) and trim($organizer['email'])) ? $organizer['email'] : '';
4255
- }
4256
-
4257
- $url = (isset($organizer['url']) and trim($organizer['url'])) ? $organizer['url'] : '';
4258
- $thumbnail = isset($organizer['thumbnail']) ? $organizer['thumbnail'] : '';
4259
-
4260
- update_term_meta($organizer_id, 'tel', $tel);
4261
- update_term_meta($organizer_id, 'email', $email);
4262
- update_term_meta($organizer_id, 'url', $url);
4263
- if(trim($thumbnail)) update_term_meta($organizer_id, 'thumbnail', $thumbnail);
4264
-
4265
- return $organizer_id;
4266
- }
4267
-
4268
- public function save_location($location = array())
4269
- {
4270
- $name = isset($location['name']) ? $location['name'] : '';
4271
- if(!trim($name)) return false;
4272
-
4273
- $term = get_term_by('name', $name, 'mec_location');
4274
-
4275
- // Term already exists
4276
- if(is_object($term) and isset($term->term_id)) return $term->term_id;
4277
-
4278
- $term = wp_insert_term($name, 'mec_location');
4279
-
4280
- // An error ocurred
4281
- if(is_wp_error($term)) return false;
4282
-
4283
- $location_id = $term['term_id'];
4284
- if(!$location_id) return false;
4285
-
4286
- $latitude = (isset($location['latitude']) and trim($location['latitude'])) ? $location['latitude'] : 0;
4287
- $longitude = (isset($location['longitude']) and trim($location['longitude'])) ? $location['longitude'] : 0;
4288
- $address = isset($location['address']) ? $location['address'] : '';
4289
- $thumbnail = isset($location['thumbnail']) ? $location['thumbnail'] : '';
4290
-
4291
- if(!trim($latitude) or !trim($longitude))
4292
- {
4293
- $geo_point = $this->get_lat_lng($address);
4294
-
4295
- $latitude = $geo_point[0];
4296
- $longitude = $geo_point[1];
4297
- }
4298
-
4299
- update_term_meta($location_id, 'address', $address);
4300
- update_term_meta($location_id, 'latitude', $latitude);
4301
- update_term_meta($location_id, 'longitude', $longitude);
4302
- if(trim($thumbnail)) update_term_meta($location_id, 'thumbnail', $thumbnail);
4303
-
4304
- return $location_id;
4305
- }
4306
-
4307
- /**
4308
- * Returns data export array for one event
4309
- * @author Webnus <info@webnus.biz>
4310
- * @param int $event_id
4311
- * @return string
4312
- */
4313
- public function export_single($event_id)
4314
- {
4315
- // MEC Render Library
4316
- $render = $this->getRender();
4317
-
4318
- return $render->data($event_id);
4319
- }
4320
-
4321
- /**
4322
- * Converts array to XML string
4323
- * @author Webnus <info@webnus.biz>
4324
- * @param array $data
4325
- * @return string
4326
- */
4327
- public function xml_convert($data)
4328
- {
4329
- $main_node = array_keys($data);
4330
-
4331
- // Creating SimpleXMLElement object
4332
- $xml = new SimpleXMLElement('<?xml version="1.0"?><'.$main_node[0].'></'.$main_node[0].'>');
4333
-
4334
- // Convert array to xml
4335
- $this->array_to_xml($data[$main_node[0]], $xml);
4336
-
4337
- // Return XML String
4338
- return $xml->asXML();
4339
- }
4340
-
4341
- public function array_to_xml($data, &$xml)
4342
- {
4343
- foreach($data as $key=>$value)
4344
- {
4345
- if(is_numeric($key)) $key = 'item';
4346
-
4347
- if(is_array($value))
4348
- {
4349
- $subnode = $xml->addChild($key);
4350
- $this->array_to_xml($value, $subnode);
4351
- }
4352
- elseif(is_object($value))
4353
- {
4354
- $subnode = $xml->addChild($key);
4355
- $this->array_to_xml($value, $subnode);
4356
- }
4357
- else
4358
- {
4359
- $xml->addChild($key, htmlspecialchars($value));
4360
- }
4361
- }
4362
- }
4363
-
4364
- /**
4365
- * Returns Weekdays Day Numbers
4366
- * @author Webnus <info@webnus.biz>
4367
- * @return array
4368
- */
4369
- public function get_weekdays()
4370
- {
4371
- $weekdays = array(1,2,3,4,5);
4372
-
4373
- // Get weekdays from options
4374
- $settings = $this->get_settings();
4375
- if(isset($settings['weekdays']) and is_array($settings['weekdays']) and count($settings['weekdays'])) $weekdays = $settings['weekdays'];
4376
-
4377
- return apply_filters('mec_weekday_numbers', $weekdays);
4378
- }
4379
-
4380
- /**
4381
- * Returns Weekends Day Numbers
4382
- * @author Webnus <info@webnus.biz>
4383
- * @return array
4384
- */
4385
- public function get_weekends()
4386
- {
4387
- $weekends = array(6,7);
4388
-
4389
- // Get weekdays from options
4390
- $settings = $this->get_settings();
4391
- if(isset($settings['weekends']) and is_array($settings['weekends']) and count($settings['weekends'])) $weekends = $settings['weekends'];
4392
-
4393
- return apply_filters('mec_weekend_numbers', $weekends);
4394
- }
4395
-
4396
- /**
4397
- * Returns Event link with Occurrence Date
4398
- * @author Webnus <info@webnus.biz>
4399
- * @param string $url
4400
- * @param string $date
4401
- * @param boolean $force
4402
- * @return string
4403
- */
4404
- public function get_event_date_permalink($url, $date = NULL, $force = false)
4405
- {
4406
- if(is_null($date)) return $url;
4407
-
4408
- // Get MEC Options
4409
- $settings = $this->get_settings();
4410
-
4411
- // Single Page Date method is set to next date
4412
- if(!$force and (!isset($settings['single_date_method']) or (isset($settings['single_date_method']) and $settings['single_date_method'] == 'next'))) return $url;
4413
-
4414
- return $this->add_qs_var('occurrence', $date, $url);
4415
- }
4416
-
4417
- /**
4418
- * Register MEC Activity Action Type in BuddeyPress
4419
- * @return void
4420
- */
4421
- public function bp_register_activity_actions()
4422
- {
4423
- bp_activity_set_action(
4424
- 'mec',
4425
- 'booked_event',
4426
- __('Booked an event.', 'modern-events-calendar-lite')
4427
- );
4428
- }
4429
-
4430
- /**
4431
- * Add a new activity to BuddyPress when a user book an event
4432
- * @param int $book_id
4433
- * @return boolean|int
4434
- */
4435
- public function bp_add_activity($book_id)
4436
- {
4437
- // Get MEC Options
4438
- $settings = $this->get_settings();
4439
-
4440
- // BuddyPress integration is disabled
4441
- if(!isset($settings['bp_status']) or (isset($settings['bp_status']) and !$settings['bp_status'])) return false;
4442
-
4443
- // BuddyPress add activity is disabled
4444
- if(!isset($settings['bp_add_activity']) or (isset($settings['bp_add_activity']) and !$settings['bp_add_activity'])) return false;
4445
-
4446
- // BuddyPress is not installed or activated
4447
- if(!function_exists('bp_activity_add')) return false;
4448
-
4449
- $verification = get_post_meta($book_id, 'mec_verified', true);
4450
- $confirmation = get_post_meta($book_id, 'mec_confirmed', true);
4451
-
4452
- // Booking is not verified or confirmed
4453
- if($verification != 1 or $confirmation != 1) return false;
4454
-
4455
- $event_id = get_post_meta($book_id, 'mec_event_id', true);
4456
- $booker_id = get_post_field('post_author', $book_id);
4457
-
4458
- $event_title = get_the_title($event_id);
4459
- $event_link = get_the_permalink($event_id);
4460
-
4461
- $profile_link = bp_core_get_userlink($booker_id);
4462
- $bp_activity_id = get_post_meta($book_id, 'mec_bp_activity_id', true);
4463
-
4464
- $activity_id = bp_activity_add(array
4465
- (
4466
- 'id'=>$bp_activity_id,
4467
- 'action'=>sprintf(__('%s booked %s event.', 'modern-events-calendar-lite'), $profile_link, '<a href="'.$event_link.'">'.$event_title.'</a>'),
4468
- 'component'=>'mec',
4469
- 'type'=>'booked_event',
4470
- 'primary_link'=>$event_link,
4471
- 'user_id'=>$booker_id,
4472
- 'item_id'=>$book_id,
4473
- 'secondary_item_id'=>$event_id,
4474
- ));
4475
-
4476
- // Set Activity ID
4477
- update_post_meta($book_id, 'mec_bp_activity_id', $activity_id);
4478
-
4479
- return $activity_id;
4480
- }
4481
-
4482
- /**
4483
- * Add booker information to mailchim list
4484
- * @param int $book_id
4485
- * @return boolean}int
4486
- */
4487
- public function mailchimp_add_subscriber($book_id)
4488
- {
4489
- // Get MEC Options
4490
- $settings = $this->get_settings();
4491
-
4492
- // Mailchim integration is disabled
4493
- if(!isset($settings['mchimp_status']) or (isset($settings['mchimp_status']) and !$settings['mchimp_status'])) return false;
4494
-
4495
- $api_key = isset($settings['mchimp_api_key']) ? $settings['mchimp_api_key'] : '';
4496
- $list_id = isset($settings['mchimp_list_id']) ? $settings['mchimp_list_id'] : '';
4497
-
4498
- // Mailchim credentials are required
4499
- if(!trim($api_key) or !trim($list_id)) return false;
4500
-
4501
- $booker_id = get_post_field('post_author', $book_id);
4502
- $booker = get_userdata($booker_id);
4503
-
4504
- $data_center = substr($api_key, strpos($api_key, '-') + 1);
4505
- $url = 'https://' . $data_center . '.api.mailchimp.com/3.0/lists/' . $list_id . '/members/';
4506
-
4507
- $subscription_status = isset($settings['mchimp_subscription_status']) ? $settings['mchimp_subscription_status'] : 'subscribed';
4508
- $json = json_encode(array
4509
- (
4510
- 'email_address'=>$booker->user_email,
4511
- 'status'=>$subscription_status,
4512
- 'merge_fields'=>array
4513
- (
4514
- 'FNAME'=>$booker->first_name,
4515
- 'LNAME'=>$booker->last_name
4516
- )
4517
- ));
4518
-
4519
- // Execute the Request and Return the Response Code
4520
- return wp_remote_retrieve_response_code(wp_remote_post($url, array(
4521
- 'body' => $json,
4522
- 'timeout' => '10',
4523
- 'redirection' => '10',
4524
- 'headers' => array('Content-Type' => 'application/json', 'Authorization' => 'Basic ' . base64_encode('user:' . $api_key)),
4525
- )));
4526
- }
4527
-
4528
- /**
4529
- * Returns Booking of a certain event at certain date
4530
- * @param int $event_id
4531
- * @param string $date
4532
- * @return array
4533
- */
4534
- public function get_bookings($event_id, $date, $limit = '-1')
4535
- {
4536
- $time = strtotime($date);
4537
-
4538
- $q = new WP_Query();
4539
- return $q->query(array
4540
- (
4541
- 'post_type'=>$this->get_book_post_type(),
4542
- 'posts_per_page'=>$limit,
4543
- 'post_status'=>array('future', 'publish'),
4544
- 'meta_query'=>array
4545
- (
4546
- array(
4547
- 'key'=>'mec_event_id',
4548
- 'value'=>$event_id,
4549
- ),
4550
- array(
4551
- 'key'=>'mec_confirmed',
4552
- 'value'=>1,
4553
- ),
4554
- array(
4555
- 'key'=>'mec_verified',
4556
- 'value'=>1,
4557
- ),
4558
- ),
4559
- 'year'=>date('Y', $time),
4560
- 'monthnum'=>date('n', $time),
4561
- 'day'=>date('j', $time),
4562
- ));
4563
- }
4564
-
4565
- /**
4566
- * Check whether to show event note or not
4567
- * @param string $status
4568
- * @return boolean
4569
- */
4570
- public function is_note_visible($status)
4571
- {
4572
- // MEC Settings
4573
- $settings = $this->get_settings();
4574
-
4575
- // FES Note is not enabled
4576
- if(!isset($settings['fes_note']) or (isset($settings['fes_note']) and !$settings['fes_note'])) return false;
4577
-
4578
- // Return visibility status by post status and visibility method
4579
- return (isset($settings['fes_note_visibility']) ? ($settings['fes_note_visibility'] == 'always' ? true : $status != 'publish') : true);
4580
- }
4581
-
4582
- /**
4583
- * Get Next event based on datetime of current event
4584
- * @param array $atts
4585
- * @return array
4586
- */
4587
- public function get_next_event($atts = array())
4588
- {
4589
- MEC::import('app.skins.list', true);
4590
-
4591
- // Get list skin
4592
- $list = new MEC_skin_list();
4593
-
4594
- // Initialize the skin
4595
- $list->initialize($atts);
4596
-
4597
- // Fetch the events
4598
- $list->fetch();
4599
-
4600
- $events = $list->events;
4601
- $key = key($events);
4602
-
4603
- return (isset($events[$key][0]) ? $events[$key][0] : array());
4604
- }
4605
-
4606
- /**
4607
- * For getting event end date based on occurrence date
4608
- * @param int $event_id
4609
- * @param string $occurrence
4610
- * @return string
4611
- */
4612
- public function get_end_date_by_occurrence($event_id, $occurrence)
4613
- {
4614
- $event_date = get_post_meta($event_id, 'mec_date', true);
4615
-
4616
- $start_date = isset($event_date['start']) ? $event_date['start'] : array();
4617
- $end_date = isset($event_date['end']) ? $event_date['end'] : array();
4618
-
4619
- $event_period = $this->date_diff($start_date['date'], $end_date['date']);
4620
- $event_period_days = $event_period ? $event_period->days : 0;
4621
-
4622
- // Single Day Event
4623
- if(!$event_period_days) return $occurrence;
4624
-
4625
- return date('Y-m-d', strtotime('+'.$event_period_days.' days', strtotime($occurrence)));
4626
- }
4627
-
4628
- /**
4629
- * Add MEC Event CPT to Tags Archive Page
4630
- * @param object $query
4631
- */
4632
- public function add_events_to_tags_archive($query)
4633
- {
4634
- if($query->is_tag() and $query->is_main_query())
4635
- {
4636
- $pt = $this->get_main_post_type();
4637
- $query->set('post_type', array('post', $pt));
4638
- }
4639
- }
4640
-
4641
- /**
4642
- * Get Post ID by meta value and meta key
4643
- * @param string $meta_key
4644
- * @param string $meta_value
4645
- * @return string
4646
- */
4647
- public function get_post_id_by_meta($meta_key, $meta_value)
4648
- {
4649
- $db = $this->getDB();
4650
- return $db->select("SELECT `post_id` FROM `#__postmeta` WHERE `meta_value`='$meta_value' AND `meta_key`='$meta_key'", 'loadResult');
4651
- }
4652
-
4653
- /**
4654
- * Set Featured Image for a Post
4655
- * @param string $image_url
4656
- * @param int $post_id
4657
- * @return bool|int
4658
- */
4659
- public function set_featured_image($image_url, $post_id)
4660
- {
4661
- $attach_id = $this->get_attach_id($image_url);
4662
- if(!$attach_id)
4663
- {
4664
- $upload_dir = wp_upload_dir();
4665
- $filename = basename($image_url);
4666
-
4667
- if(wp_mkdir_p($upload_dir['path'])) $file = $upload_dir['path'].'/'.$filename;
4668
- else $file = $upload_dir['basedir'].'/'.$filename;
4669
-
4670
- if(!file_exists($file))
4671
- {
4672
- $image_data = $this->get_web_page($image_url);
4673
- file_put_contents($file, $image_data);
4674
- }
4675
-
4676
- $wp_filetype = wp_check_filetype($filename, null);
4677
- $attachment = array(
4678
- 'post_mime_type'=>$wp_filetype['type'],
4679
- 'post_title'=>sanitize_file_name($filename),
4680
- 'post_content'=>'',
4681
- 'post_status'=>'inherit'
4682
- );
4683
-
4684
- $attach_id = wp_insert_attachment($attachment, $file, $post_id);
4685
- require_once ABSPATH.'wp-admin/includes/image.php';
4686
-
4687
- $attach_data = wp_generate_attachment_metadata($attach_id, $file);
4688
- wp_update_attachment_metadata($attach_id, $attach_data);
4689
- }
4690
-
4691
- return set_post_thumbnail($post_id, $attach_id);
4692
- }
4693
-
4694
- /**
4695
- * Get Attachment ID by Image URL
4696
- * @param string $image_url
4697
- * @return int
4698
- */
4699
- public function get_attach_id($image_url)
4700
- {
4701
- $db = $this->getDB();
4702
- return $db->select("SELECT `ID` FROM `#__posts` WHERE `guid`='$image_url'", 'loadResult');
4703
- }
4704
-
4705
- /**
4706
- * Get Image Type by Buffer. Used in Facebook Importer
4707
- * @param string $buffer
4708
- * @return string
4709
- */
4710
- public function get_image_type_by_buffer($buffer)
4711
- {
4712
- $types = array('jpeg'=>"\xFF\xD8\xFF", 'gif'=>'GIF', 'png'=>"\x89\x50\x4e\x47\x0d\x0a", 'bmp'=>'BM', 'psd'=>'8BPS', 'swf'=>'FWS');
4713
- $found = 'other';
4714
-
4715
- foreach($types as $type=>$header)
4716
- {
4717
- if(strpos($buffer, $header) === 0)
4718
- {
4719
- $found = $type;
4720
- break;
4721
- }
4722
- }
4723
-
4724
- return $found;
4725
- }
4726
-
4727
- /**
4728
- * Load Google Maps assets
4729
- */
4730
- public function load_map_assets()
4731
- {
4732
- if($this->getPRO())
4733
- {
4734
- // MEC Settings
4735
- $settings = $this->get_settings();
4736
-
4737
- // Include Google Maps Javascript API
4738
- $gm_include = apply_filters('mec_gm_include', true);
4739
- if($gm_include) wp_enqueue_script('googlemap', '//maps.googleapis.com/maps/api/js?libraries=places'.((isset($settings['google_maps_api_key']) and trim($settings['google_maps_api_key']) != '') ? '&key='.$settings['google_maps_api_key'] : ''));
4740
-
4741
- // Google Maps Rich Marker
4742
- wp_enqueue_script('mec-richmarker-script', $this->asset('packages/richmarker/richmarker.min.js'));
4743
-
4744
- // Google Maps Clustering
4745
- wp_enqueue_script('mec-clustering-script', $this->asset('packages/clusterer/markerclusterer.min.js'));
4746
- }
4747
- }
4748
-
4749
- /**
4750
- * Load Owl Carousel assets
4751
- */
4752
- public function load_owl_assets()
4753
- {
4754
- // Include MEC frontend CSS files
4755
- wp_enqueue_style('mec-owl-carousel-style', $this->asset('packages/owl-carousel/owl.carousel.min.css'));
4756
- wp_enqueue_style('mec-owl-carousel-theme-style', $this->asset('packages/owl-carousel/owl.theme.min.css'));
4757
- }
4758
-
4759
- /**
4760
- * Load Isotope assets
4761
- */
4762
- public function load_isotope_assets()
4763
- {
4764
- // Isotope JS file
4765
- wp_enqueue_script('mec-isotope-script', $this->asset('js/isotope.pkgd.min.js'));
4766
- }
4767
-
4768
- function get_client_ip()
4769
- {
4770
- $ipaddress = '';
4771
-
4772
- if(isset($_SERVER['HTTP_CLIENT_IP'])) $ipaddress = $_SERVER['HTTP_CLIENT_IP'];
4773
- elseif(isset($_SERVER['HTTP_X_FORWARDED_FOR'])) $ipaddress = $_SERVER['HTTP_X_FORWARDED_FOR'];
4774
- elseif(isset($_SERVER['HTTP_X_FORWARDED'])) $ipaddress = $_SERVER['HTTP_X_FORWARDED'];
4775
- elseif(isset($_SERVER['HTTP_FORWARDED_FOR'])) $ipaddress = $_SERVER['HTTP_FORWARDED_FOR'];
4776
- elseif(isset($_SERVER['HTTP_FORWARDED'])) $ipaddress = $_SERVER['HTTP_FORWARDED'];
4777
- elseif(isset($_SERVER['REMOTE_ADDR'])) $ipaddress = $_SERVER['REMOTE_ADDR'];
4778
- else $ipaddress = 'UNKNOWN';
4779
-
4780
- return $ipaddress;
4781
- }
4782
-
4783
- public function get_timezone_by_ip()
4784
- {
4785
- // Client IP
4786
- $ip = $this->get_client_ip();
4787
-
4788
- // First Provider
4789
- $JSON = $this->get_web_page('http://ip-api.com/json/'.$ip);
4790
- $data = json_decode($JSON, true);
4791
-
4792
- // Second Provider
4793
- if(!trim($JSON) or (is_array($data) and !isset($data['timezone'])))
4794
- {
4795
- $JSON = $this->get_web_page('https://ipapi.co/'.$ip.'/json/');
4796
- $data = json_decode($JSON, true);
4797
- }
4798
-
4799
- // Second provide returns X instead of false in case of error!
4800
- return (isset($data['timezone']) and strtolower($data['timezone']) != 'x') ? $data['timezone'] : false;
4801
- }
4802
-
4803
- public function is_ajax()
4804
- {
4805
- return (defined('DOING_AJAX') && DOING_AJAX);
4806
- }
4807
-
4808
- public function load_sed_assets()
4809
- {
4810
- // Load Map assets
4811
- $this->load_map_assets();
4812
-
4813
- // Include FlipCount library
4814
- wp_enqueue_script('mec-flipcount-script', $this->asset('js/flipcount.js'));
4815
- }
4816
-
4817
- public function is_sold($event, $date)
4818
- {
4819
- $tickets = isset($event->data->tickets) ? $event->data->tickets : array();
4820
-
4821
- // No Tickets
4822
- if(!count($tickets)) return false;
4823
-
4824
- $bookings = $this->get_bookings($event->data->ID, $date);
4825
-
4826
- // No Bookings
4827
- if(!count($bookings)) return false;
4828
-
4829
- $available_spots = '0';
4830
- foreach($tickets as $ticket)
4831
- {
4832
- if((isset($ticket['unlimited']) and $ticket['unlimited']) or !trim($ticket['limit']))
4833
- {
4834
- $available_spots = '-1';
4835
- break;
4836
- }
4837
-
4838
- $available_spots += $ticket['limit'];
4839
- }
4840
-
4841
- // There are unlimitted spots
4842
- if($available_spots == '-1') return false;
4843
-
4844
- // Bookings are higher than available spots so event is sold
4845
- if(count($bookings) >= $available_spots) return true;
4846
-
4847
- return false;
4848
- }
4849
-
4850
- public function get_date_periods($date_start, $date_end, $type = 'daily')
4851
- {
4852
- $periods = array();
4853
-
4854
- $time_start = strtotime($date_start);
4855
- $time_end = strtotime($date_end);
4856
-
4857
- if($type == 'daily')
4858
- {
4859
- while($time_start < $time_end)
4860
- {
4861
- $periods[] = array('start'=>date("Y-m-d H:i:s", $time_start), 'end'=>date("Y-m-d H:i:s", ($time_start+86399)), 'label'=>date("Y-m-d", $time_start));
4862
- $time_start += 86400;
4863
- }
4864
- }
4865
- // @todo
4866
- elseif($type == 'weekly')
4867
- {
4868
- }
4869
- elseif($type == 'monthly')
4870
- {
4871
- $start_year = date('Y', $time_start);
4872
- $start_month = date('m', $time_start);
4873
- $start_id = (int) $start_year.$start_month;
4874
-
4875
- $end_year = date('Y', $time_end);
4876
- $end_month = date('m', $time_end);
4877
- $end_id = (int) $end_year.$end_month;
4878
-
4879
- while($start_id <= $end_id)
4880
- {
4881
- $periods[] = array('start'=>$start_year."-".$start_month."-01 00:00:00", 'end'=>$start_year."-".$start_month."-".date('t', strtotime($start_year."-".$start_month."-01 00:00:00"))." 23:59:59", 'label'=>date('Y F', strtotime($start_year."-".$start_month."-01 00:00:00")));
4882
-
4883
- if($start_month == '12')
4884
- {
4885
- $start_month = '01';
4886
- $start_year++;
4887
- }
4888
- else
4889
- {
4890
- $start_month = (int) $start_month+1;
4891
- if(strlen($start_month) == 1) $start_month = '0'.$start_month;
4892
- }
4893
-
4894
- $start_id = (int) $start_year.$start_month;
4895
- }
4896
- }
4897
- elseif($type == 'yearly')
4898
- {
4899
- $start_year = date('Y', $time_start);
4900
- $end_year = date('Y', $time_end);
4901
-
4902
- while($start_year <= $end_year)
4903
- {
4904
- $periods[] = array('start'=>$start_year."-01-01 00:00:00", 'end'=>$start_year."-12-31 23:59:59", 'label'=>$start_year);
4905
- $start_year++;
4906
- }
4907
- }
4908
-
4909
- return $periods;
4910
- }
4911
-
4912
- public function get_messages()
4913
- {
4914
- $messages = array(
4915
- 'taxonomies'=>array(
4916
- 'category'=>array('name'=>__('Taxonomies', 'modern-events-calendar-lite')),
4917
- 'messages'=>array(
4918
- 'taxonomy_categories'=>array('label'=>__('Category Plural Label', 'modern-events-calendar-lite'), 'default'=>__('Categories', 'modern-events-calendar-lite')),
4919
- 'taxonomy_category'=>array('label'=>__('Category Singular Label', 'modern-events-calendar-lite'), 'default'=>__('Category', 'modern-events-calendar-lite')),
4920
- 'taxonomy_labels'=>array('label'=>__('Label Plural Label', 'modern-events-calendar-lite'), 'default'=>__('Labels', 'modern-events-calendar-lite')),
4921
- 'taxonomy_label'=>array('label'=>__('Label Singular Label', 'modern-events-calendar-lite'), 'default'=>__('label', 'modern-events-calendar-lite')),
4922
- 'taxonomy_locations'=>array('label'=>__('Location Plural Label', 'modern-events-calendar-lite'), 'default'=>__('Locations', 'modern-events-calendar-lite')),
4923
- 'taxonomy_location'=>array('label'=>__('Location Singular Label', 'modern-events-calendar-lite'), 'default'=>__('Location', 'modern-events-calendar-lite')),
4924
- 'taxonomy_organizers'=>array('label'=>__('Organizer Plural Label', 'modern-events-calendar-lite'), 'default'=>__('Organizers', 'modern-events-calendar-lite')),
4925
- 'taxonomy_organizer'=>array('label'=>__('Organizer Singular Label', 'modern-events-calendar-lite'), 'default'=>__('Organizer', 'modern-events-calendar-lite')),
4926
- 'taxonomy_speakers'=>array('label'=>__('Speaker Plural Label', 'modern-events-calendar-lite'), 'default'=>__('Speakers', 'modern-events-calendar-lite')),
4927
- 'taxonomy_speaker'=>array('label'=>__('Speaker Singular Label', 'modern-events-calendar-lite'), 'default'=>__('Speaker', 'modern-events-calendar-lite')),
4928
- )
4929
- ),
4930
- 'weekdays'=>array(
4931
- 'category'=>array('name'=>__('Weekdays', 'modern-events-calendar-lite')),
4932
- 'messages'=>array(
4933
- 'weekdays_su'=>array('label'=>__('Sunday abbreviation', 'modern-events-calendar-lite'), 'default'=>__('SU', 'modern-events-calendar-lite')),
4934
- 'weekdays_mo'=>array('label'=>__('Monday abbreviation', 'modern-events-calendar-lite'), 'default'=>__('MO', 'modern-events-calendar-lite')),
4935
- 'weekdays_tu'=>array('label'=>__('Tuesday abbreviation', 'modern-events-calendar-lite'), 'default'=>__('TU', 'modern-events-calendar-lite')),
4936
- 'weekdays_we'=>array('label'=>__('Wednesday abbreviation', 'modern-events-calendar-lite'), 'default'=>__('WE', 'modern-events-calendar-lite')),
4937
- 'weekdays_th'=>array('label'=>__('Thursday abbreviation', 'modern-events-calendar-lite'), 'default'=>__('TH', 'modern-events-calendar-lite')),
4938
- 'weekdays_fr'=>array('label'=>__('Friday abbreviation', 'modern-events-calendar-lite'), 'default'=>__('FR', 'modern-events-calendar-lite')),
4939
- 'weekdays_sa'=>array('label'=>__('Saturday abbreviation', 'modern-events-calendar-lite'), 'default'=>__('SA', 'modern-events-calendar-lite')),
4940
- )
4941
- ),
4942
- 'others'=>array(
4943
- 'category'=>array('name'=>__('Others', 'modern-events-calendar-lite')),
4944
- 'messages'=>array(
4945
- 'book_success_message'=>array('label'=>__('Booking Success Message', 'modern-events-calendar-lite'), 'default'=>__('Thanks for your booking. Your tickets booked, booking verification might be needed, please check your email.', 'modern-events-calendar-lite')),
4946
- 'register_button'=>array('label'=>__('Register Button', 'modern-events-calendar-lite'), 'default'=>__('REGISTER', 'modern-events-calendar-lite')),
4947
- 'view_detail'=>array('label'=>__('View Detail Button', 'modern-events-calendar-lite'), 'default'=>__('View Detail', 'modern-events-calendar-lite')),
4948
- 'event_detail'=>array('label'=>__('Event Detail Button', 'modern-events-calendar-lite'), 'default'=>__('Event Detail', 'modern-events-calendar-lite')),
4949
- 'read_more_link'=>array('label'=>__('Event Link', 'modern-events-calendar-lite'), 'default'=>__('Event Link', 'modern-events-calendar-lite')),
4950
- 'more_info_link'=>array('label'=>__('More Info Link', 'modern-events-calendar-lite'), 'default'=>__('More Info', 'modern-events-calendar-lite')),
4951
- 'event_cost'=>array('label'=>__('Event Cost', 'modern-events-calendar-lite'), 'default'=>__('Event Cost', 'modern-events-calendar-lite')),
4952
- 'cost'=>array('label'=>__('Cost', 'modern-events-calendar-lite'), 'default'=>__('Cost', 'modern-events-calendar-lite')),
4953
- 'ticket'=>array('label'=>__('Ticket (Singular)', 'modern-events-calendar-lite'), 'default'=>__('Ticket', 'modern-events-calendar-lite')),
4954
- 'tickets'=>array('label'=>__('Tickets (Plural)', 'modern-events-calendar-lite'), 'default'=>__('Tickets', 'modern-events-calendar-lite')),
4955
- 'other_organizers'=>array('label'=>__('Other Organizers', 'modern-events-calendar-lite'), 'default'=>__('Other Organizers', 'modern-events-calendar-lite')),
4956
- 'other_locations'=>array('label'=>__('Other Locations', 'modern-events-calendar-lite'), 'default'=>__('Other Locations', 'modern-events-calendar-lite')),
4957
- )
4958
- ),
4959
- );
4960
-
4961
- return apply_filters('mec_messages', $messages);
4962
- }
4963
-
4964
- /**
4965
- * For showing dynamic messages based on their default value and the inserted value in backend (if any)
4966
- * @param $message_key string
4967
- * @param $default string
4968
- * @return string
4969
- */
4970
- public function m($message_key, $default)
4971
- {
4972
- $message_values = $this->get_messages_options();
4973
-
4974
- // Message is not set from backend
4975
- if(!isset($message_values[$message_key]) or (isset($message_values[$message_key]) and !trim($message_values[$message_key]))) return $default;
4976
-
4977
- // Return the dynamic message inserted in backend
4978
- return $message_values[$message_key];
4979
- }
4980
-
4981
- /**
4982
- * Get Weather from the data provider
4983
- * @param $lat
4984
- * @param $lng
4985
- * @param $datetime
4986
- * @return bool|array
4987
- */
4988
- public function get_weather($lat, $lng, $datetime)
4989
- {
4990
- // MEC Settings
4991
- $settings = $this->get_settings();
4992
-
4993
- // API KEY is required!
4994
- if(!isset($settings['weather_module_api_key']) or (isset($settings['weather_module_api_key']) and !trim($settings['weather_module_api_key']))) return false;
4995
-
4996
- $locale = substr(get_locale(), 0, 2);
4997
-
4998
- // Set the language to English if it's not included in available languages
4999
- if(!in_array($locale, array
5000
- (
5001
- 'ar', 'az', 'be', 'bg', 'bs', 'ca', 'cs', 'da', 'de', 'el', 'en', 'es', 'et',
5002
- 'fi', 'fr', 'hr', 'hu', 'id', 'is', 'it', 'ja', 'ka', 'ko', 'kw', 'nb', 'nl',
5003
- 'no', 'pl', 'pt', 'ro', 'ru', 'sk', 'sl', 'sr', 'sv', 'tet', 'tr', 'uk', 'x-pig-latin',
5004
- 'zh', 'zh-tw'
5005
- ))) $locale = 'en';
5006
-
5007
- // Dark Sky Provider
5008
- $JSON = $this->get_web_page('https://api.darksky.net/forecast/'.$settings['weather_module_api_key'].'/'.$lat.','.$lng.','.strtotime($datetime).'?exclude=minutely,hourly,daily,alerts&units=ca&lang='.$locale);
5009
- $data = json_decode($JSON, true);
5010
-
5011
- return (isset($data['currently']) ? $data['currently'] : false);
5012
- }
5013
-
5014
- /**
5015
- * Convert weather unit
5016
- * @author Webnus <info@webnus.biz>
5017
- * @param $value
5018
- * @param $mode
5019
- * @return string|boolean
5020
- */
5021
- function weather_unit_convert($value, $mode)
5022
- {
5023
- if(func_num_args() < 2) return;
5024
- $mode = strtoupper($mode);
5025
-
5026
- if($mode == 'F_TO_C') return (round(((floatval($value) -32) *5 /9)));
5027
- else if($mode == 'C_TO_F') return (round(((1.8 * floatval($value)) +32)));
5028
- else if($mode == 'M_TO_KM') return(round(1.609344 * floatval($value)));
5029
- else if($mode == 'KM_TO_M') return(round(0.6214 * floatval($value)));
5030
- return false;
5031
- }
5032
-
5033
- /**
5034
- * Get Integrated plugins to import events
5035
- * @return array
5036
- */
5037
- public function get_integrated_plugins_for_import()
5038
- {
5039
- return array(
5040
- 'eventon' => __('EventON', 'modern-events-calendar-lite'),
5041
- 'the-events-calendar' => __('The Events Calendar', 'modern-events-calendar-lite'),
5042
- 'weekly-class' => __('Events Schedule WP Plugin', 'modern-events-calendar-lite'),
5043
- 'calendarize-it' => __('Calendarize It', 'modern-events-calendar-lite'),
5044
- 'event-espresso' => __('Event Espresso', 'modern-events-calendar-lite'),
5045
- 'events-manager-recurring' => __('Events Manager (Recurring)', 'modern-events-calendar-lite'),
5046
- 'events-manager-single' => __('Events Manager (Single)', 'modern-events-calendar-lite'),
5047
- );
5048
- }
5049
-
5050
- public function get_original_event($event_id)
5051
- {
5052
- // If WPML Plugin is installed and activated
5053
- if(class_exists('SitePress'))
5054
- {
5055
- $trid = apply_filters('wpml_element_trid', NULL, $event_id, 'post_mec-events');
5056
- $translations = apply_filters('wpml_get_element_translations', NULL, $trid, 'post_mec-events');
5057
-
5058
- if(!is_array($translations) or (is_array($translations) and !count($translations))) return $event_id;
5059
-
5060
- $original_id = $event_id;
5061
- foreach($translations as $translation)
5062
- {
5063
- if(isset($translation->original) and $translation->original)
5064
- {
5065
- $original_id = $translation->element_id;
5066
- break;
5067
- }
5068
- }
5069
-
5070
- return $original_id;
5071
- }
5072
- else return $event_id;
5073
- }
5074
-
5075
- /**
5076
- * To check is a date is valid or not
5077
- * @param string $date
5078
- * @param string $format
5079
- * @return bool
5080
- */
5081
- public function validate_date($date, $format = 'Y-m-d')
5082
- {
5083
- $d = DateTime::createFromFormat($format, $date);
5084
- return $d && $d->format($format) == $date;
5085
- }
5086
-
5087
- public function parse_ics($feed)
5088
- {
5089
- try {
5090
- $ical = new ICal($feed, array(
5091
- 'defaultSpan' => 2, // Default value
5092
- 'defaultTimeZone' => 'UTC',
5093
- 'defaultWeekStart' => 'MO', // Default value
5094
- 'disableCharacterReplacement' => false, // Default value
5095
- 'skipRecurrence' => false, // Default value
5096
- 'useTimeZoneWithRRules' => false, // Default value
5097
- ));
5098
-
5099
- return $ical;
5100
- }
5101
- catch(\Exception $e)
5102
- {
5103
- return false;
5104
- }
5105
- }
5106
-
5107
- public function get_pro_link()
5108
- {
5109
- return 'https://webnus.net/mec-purchase/';
5110
- }
5111
-
5112
- /**
5113
- * Get Label for booking confirmation
5114
- * @author Webnus <info@webnus.biz>
5115
- * @param int $confirmed
5116
- * @return string
5117
- */
5118
- public function get_confirmation_label($confirmed = 1)
5119
- {
5120
- if($confirmed == '1') $label = __('Confirmed', 'modern-events-calendar-lite');
5121
- elseif($confirmed == '-1') $label = __('Rejected', 'modern-events-calendar-lite');
5122
- else $label = __('Pending', 'modern-events-calendar-lite');
5123
-
5124
- return $label;
5125
- }
5126
-
5127
- /**
5128
- * Get Label for events status
5129
- * @author Webnus <info@webnus.biz>
5130
- * @param string $label
5131
- * @param boolean $return_class
5132
- * @return string|array
5133
- */
5134
- public function get_event_label_status($label = 'empty', $return_class = true)
5135
- {
5136
- if(!trim($label)) $label = 'empty';
5137
- switch($label)
5138
- {
5139
- case 'publish':
5140
- $label = __('Confirmed', 'modern-events-calendar-lite');
5141
- $status_class = 'mec-book-confirmed';
5142
- break;
5143
- case 'pending':
5144
- $label = __('Pending', 'modern-events-calendar-lite');
5145
- $status_class = 'mec-book-pending';
5146
- break;
5147
- case 'trash':
5148
- $label = __('Rejected', 'modern-events-calendar-lite');
5149
- $status_class = 'mec-book-pending';
5150
- break;
5151
- default:
5152
- $label = __(ucwords($label), 'modern-events-calendar-lite');
5153
- $status_class = 'mec-book-other';
5154
- break;
5155
- }
5156
-
5157
- return !$return_class ? $label : array('label' => $label, 'status_class' => $status_class);
5158
- }
5159
-
5160
- /**
5161
- * Get Label for booking verification
5162
- * @author Webnus <info@webnus.biz>
5163
- * @param int $verified
5164
- * @return string
5165
- */
5166
- public function get_verification_label($verified = 1)
5167
- {
5168
- if($verified == '1') $label = __('Verified', 'modern-events-calendar-lite');
5169
- elseif($verified == '-1') $label = __('Canceled', 'modern-events-calendar-lite');
5170
- else $label = __('Waiting', 'modern-events-calendar-lite');
5171
-
5172
- return $label;
5173
- }
5174
-
5175
- /**
5176
- * Added Block Editor Custome Category
5177
- * @author Webnus <info@webnus.biz>
5178
- * @param array $categories
5179
- * @return array
5180
- */
5181
- public function add_custom_block_cateogry($categories)
5182
- {
5183
- $categories = array_merge(array(array('slug' => 'mec.block.category', 'title' => __('M.E. Calender', 'modern-events-calendar-lite'), 'icon' => 'calendar-alt')), $categories);
5184
- return $categories;
5185
- }
5186
-
5187
- /**
5188
- * Advanced Repeating MEC Active
5189
- * @author Webnus <info@webnus.biz>
5190
- * @param array $days
5191
- * @param string $item
5192
- */
5193
- public function mec_active($days = array(), $item = '')
5194
- {
5195
- if(is_array($days) and in_array($item, $days)) echo 'mec-active';
5196
- }
5197
-
5198
- /**
5199
- * Advanced repeat sorting by start of week day number
5200
- * @author Webnus <info@webnus.biz>
5201
- * @param int $start_of_week
5202
- * @param $day
5203
- * @return string|boolean
5204
- */
5205
- public function advanced_repeating_sort_day($start_of_week = 1, $day = 1)
5206
- {
5207
- if(func_num_args() < 2) return false;
5208
-
5209
- $start_of_week = intval($start_of_week);
5210
- $day = intval($day) == 0 ? intval($day) : intval($day) - 1;
5211
-
5212
- // Sorting days by start of week day number
5213
- $days = array('Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat');
5214
- $s1 = array_splice($days, $start_of_week, count($days));
5215
- $s2 = array_splice($days, 0, $start_of_week);
5216
- $merge = array_merge($s1, $s2);
5217
-
5218
- return $merge[$day];
5219
- }
5220
-
5221
- public function get_ical_rrules($event)
5222
- {
5223
- $recurrence = array();
5224
- if(isset($event->mec->repeat) and $event->mec->repeat)
5225
- {
5226
- $gmt_offset = $this->get_gmt_offset();
5227
- $finish = ($event->mec->end != '0000-00-00' ? date('Ymd\THis\Z', strtotime($event->mec->end.' '.$event->time['end'])) : '');
5228
- $freq = '';
5229
- $interval = '1';
5230
- $bysetpos = '';
5231
- $byday = '';
5232
- $wkst = '';
5233
-
5234
- $repeat_type = $event->meta['mec_repeat_type'];
5235
- $week_day_mapping = array('1'=>'MO', '2'=>'TU', '3'=>'WE', '4'=>'TH', '5'=>'FR', '6'=>'SA', '7'=>'SU');
5236
-
5237
- if($repeat_type == 'daily')
5238
- {
5239
- $freq = 'DAILY';
5240
- $interval = $event->mec->rinterval;
5241
- }
5242
- elseif($repeat_type == 'weekly')
5243
- {
5244
- $freq = 'WEEKLY';
5245
- $interval = ($event->mec->rinterval/7);
5246
- }
5247
- elseif($repeat_type == 'monthly') $freq = 'MONTHLY';
5248
- elseif($repeat_type == 'yearly') $freq = 'YEARLY';
5249
- elseif($repeat_type == 'weekday')
5250
- {
5251
- $mec_weekdays = explode(',', trim($event->mec->weekdays, ','));
5252
- foreach($mec_weekdays as $mec_weekday) $byday .= $week_day_mapping[$mec_weekday].',';
5253
-
5254
- $byday = trim($byday, ', ');
5255
- $freq = 'WEEKLY';
5256
- }
5257
- elseif($repeat_type == 'weekend')
5258
- {
5259
- $mec_weekdays = explode(',', trim($event->mec->weekdays, ','));
5260
- foreach($mec_weekdays as $mec_weekday) $byday .= $week_day_mapping[$mec_weekday].',';
5261
-
5262
- $byday = trim($byday, ', ');
5263
- $freq = 'WEEKLY';
5264
- }
5265
- elseif($repeat_type == 'certain_weekdays')
5266
- {
5267
- $mec_weekdays = explode(',', trim($event->mec->weekdays, ','));
5268
- foreach($mec_weekdays as $mec_weekday) $byday .= $week_day_mapping[$mec_weekday].',';
5269
-
5270
- $byday = trim($byday, ', ');
5271
- $freq = 'WEEKLY';
5272
- }
5273
- elseif($repeat_type == 'advanced')
5274
- {
5275
- $advanced_days = is_array($event->meta['mec_advanced_days']) ? $event->meta['mec_advanced_days'] : array();
5276
-
5277
- $first_rule = isset($advanced_days[0]) ? $advanced_days[0] : NULL;
5278
- $ex = explode('.', $first_rule);
5279
-
5280
- $bysetpos = isset($ex[1]) ? $ex[1] : NULL;
5281
- $byday_mapping = array('MON'=>'MO', 'TUE'=>'TU', 'WED'=>'WE', 'THU'=>'TH', 'FRI'=>'FR', 'SAT'=>'SA', 'SUN'=>'SU');
5282
- $byday = $byday_mapping[strtoupper($ex[0])];
5283
-
5284
- $freq = 'MONTHLY';
5285
- }
5286
- elseif($repeat_type == 'custom_days')
5287
- {
5288
- $freq = '';
5289
- $mec_periods = explode(',', trim($event->mec->days, ','));
5290
-
5291
- $days = '';
5292
- foreach($mec_periods as $mec_period)
5293
- {
5294
- $mec_days = explode(':', trim($mec_period, ': '));
5295
- $days .= date('Ymd\THis', strtotime($mec_days[0].' '.$event->time['start'])).$gmt_offset.'/'.date('Ymd\THis', strtotime($mec_days[1].' '.$event->time['end'])).$gmt_offset.',';
5296
- }
5297
-
5298
- // Add RDATE
5299
- $recurrence[] = trim('RDATE;VALUE=PERIOD:'.trim($days, ', '), '; ');
5300
- }
5301
-
5302
- // Add RRULE
5303
- if(trim($freq))
5304
- {
5305
- $rrule = 'RRULE:FREQ='.$freq.';'
5306
- .($interval > 1 ? 'INTERVAL='.$interval.';' : '')
5307
- .(($finish != '0000-00-00' and $finish != '') ? 'UNTIL='.$finish.';' : '')
5308
- .($wkst != '' ? 'WKST='.$wkst.';' : '')
5309
- .($bysetpos != '' ? 'BYSETPOS='.$bysetpos.';' : '')
5310
- .($byday != '' ? 'BYDAY='.$byday.';' : '');
5311
-
5312
- $recurrence[] = trim($rrule, '; ');
5313
- }
5314
-
5315
- if(trim($event->mec->not_in_days))
5316
- {
5317
- $mec_not_in_days = explode(',', trim($event->mec->not_in_days, ','));
5318
-
5319
- $not_in_days = '';
5320
- foreach($mec_not_in_days as $mec_not_in_day) $not_in_days .= date('Ymd', strtotime($mec_not_in_day)).',';
5321
-
5322
- // Add EXDATE
5323
- $recurrence[] = trim('EXDATE;VALUE=DATE:'.trim($not_in_days, ', '), '; ');
5324
- }
5325
- }
5326
-
5327
- return $recurrence;
5328
- }
5329
-
5330
- public static function get_upcoming_events($limit = 12)
5331
- {
5332
- MEC::import('app.skins.list', true);
5333
-
5334
- // Get list skin
5335
- $list = new MEC_skin_list();
5336
-
5337
- // Attributes
5338
- $atts = array(
5339
- 'show_past_events'=>0,
5340
- 'start_date_type'=>'today',
5341
- 'sk-options'=> array(
5342
- 'list' => array('limit'=>$limit)
5343
- ),
5344
- );
5345
-
5346
- // Initialize the skin
5347
- $list->initialize($atts);
5348
-
5349
- // Fetch the events
5350
- $list->fetch();
5351
-
5352
- return $list->events;
5353
- }
5354
-
5355
- /**
5356
- * Do the shortcode and return its output
5357
- * @author Webnus <info@webnus.biz>
5358
- * @param integer $shortcode_id
5359
- * @return string
5360
- */
5361
- public static function get_shortcode_events($shortcode_id)
5362
- {
5363
- // Get Render
5364
- $render = new MEC_render();
5365
- $atts = apply_filters('mec_calendar_atts', $render->parse($shortcode_id, array()));
5366
-
5367
- $skin = isset($atts['skin']) ? $atts['skin'] : $render->get_default_layout();
5368
-
5369
- $path = MEC::import('app.skins.'.$skin, true, true);
5370
- $skin_path = apply_filters('mec_skin_path', $skin);
5371
-
5372
- if($skin_path != $skin and $render->file->exists($skin_path)) $path = $skin_path;
5373
- if(!$render->file->exists($path))
5374
- {
5375
- return __('Skin controller does not exist.', 'modern-events-calendar-lite');
5376
- }
5377
-
5378
- include_once $path;
5379
-
5380
- $skin_class_name = 'MEC_skin_'.$skin;
5381
-
5382
- // Create Skin Object Class
5383
- $SKO = new $skin_class_name();
5384
-
5385
- // Initialize the skin
5386
- $SKO->initialize($atts);
5387
-
5388
- // Fetch the events
5389
- $SKO->fetch();
5390
-
5391
- // Return the Events
5392
- return $SKO->events;
5393
- }
5394
-
5395
- /**
5396
- * User limited for booking a event
5397
- * @author Webnus <info@webnus.biz>
5398
- * @param string $user_email
5399
- * @param array $ticket_info
5400
- * @param integer $limit
5401
- * @return array
5402
- */
5403
- public function booking_permitted($user_email, $ticket_info = array(), $limit, $booking_count = false)
5404
- {
5405
- if(!is_array($ticket_info) or is_array($ticket_info) and count($ticket_info) < 2) return false;
5406
-
5407
- $user_email = sanitize_email($user_email);
5408
- $user = get_user_by('email', $user_email);
5409
- $user_id = (isset($user->data) and isset($user->data->ID)) ? $user->data->ID : 0;
5410
-
5411
- // It's the first booking of this email
5412
- if(!$user_id) return true;
5413
-
5414
- $event_id = isset($ticket_info['event_id']) ? intval($ticket_info['event_id']) : 0;
5415
- $count = isset($ticket_info['count']) ? intval($ticket_info['count']) : 0;
5416
-
5417
- $date = isset($ticket_info['date']) ? $ticket_info['date'] : '';
5418
- list($year, $month, $day) = explode('-', $date);
5419
-
5420
- $permission = true;
5421
- $query = new WP_Query(array
5422
- (
5423
- 'post_type'=>$this->get_book_post_type(),
5424
- 'author'=>$user_id,
5425
- 'posts_per_page'=>-1,
5426
- 'post_status'=>array('publish', 'pending', 'draft', 'future', 'private'),
5427
- 'year'=>$year,
5428
- 'monthnum'=>$month,
5429
- 'day'=>$day,
5430
- 'meta_query'=>array
5431
- (
5432
- array('key'=>'mec_event_id', 'value'=>$event_id, 'compare'=>'='),
5433
- array('key'=>'mec_verified', 'value'=>'-1', 'compare'=>'!='), // Don't include canceled bookings
5434
- array('key'=>'mec_confirmed', 'value'=>'-1', 'compare'=>'!='), // Don't include rejected bookings
5435
- )
5436
- ));
5437
-
5438
- $bookings = 0;
5439
- if($query->have_posts())
5440
- {
5441
- while($query->have_posts())
5442
- {
5443
- $query->the_post();
5444
-
5445
- $ticket_ids_string = trim(get_post_meta(get_the_ID(), 'mec_ticket_id', true), ', ');
5446
- $ticket_ids_count = count(explode(',', $ticket_ids_string));
5447
-
5448
- $bookings += $ticket_ids_count;
5449
- }
5450
- }
5451
-
5452
- if(($bookings + $count) > $limit) $permission = false;
5453
-
5454
- return array("booking_count" => $bookings, "permission" => $permission);
5455
- }
5456
-
5457
- /**
5458
- * Check Has Sold Out Ticket
5459
- * @author Webnus <info@webnus.biz>
5460
- * @param string $user_id
5461
- * @param array $ticket_info
5462
- * @param string $mode
5463
- * @return boolean
5464
- */
5465
- public function is_soldout($event_id, $event_start_date)
5466
- {
5467
- if(func_num_args() < 2) return;
5468
-
5469
- $book = $this->getBook();
5470
-
5471
- $event_id = (isset($event_id)) ? intval($event_id) : 0;
5472
- $event_start_date = (isset($event_start_date) and trim($event_start_date)) ? trim($event_start_date) : '';
5473
-
5474
- $is_soldout = $book->get_tickets_availability($event_id, $event_start_date);
5475
-
5476
- return (isset($is_soldout) and current($is_soldout) === 0) ? true : false;
5477
- }
5478
-
5479
- /**
5480
- * Add Query String To URL
5481
- * @param string $url
5482
- * @param array $key
5483
- * @param string $value
5484
- * @resourse wp-mix.com
5485
- * @return string
5486
- */
5487
- public function add_query_string($url, $key, $value)
5488
- {
5489
- $url = preg_replace('/([?&])'. $key .'=.*?(&|$)/i', '$1$2$4', $url);
5490
-
5491
- if(substr($url, strlen($url) - 1) == "?" or substr($url, strlen($url) - 1) == "&")
5492
- $url = substr($url, 0, -1);
5493
-
5494
- if(strpos($url, '?') === false)
5495
- {
5496
- return ($url .'?'. $key .'='. $value);
5497
- }
5498
- else
5499
- {
5500
- return ($url .'&'. $key .'='. $value);
5501
- }
5502
- }
5503
-
5504
- /**
5505
- * Check Is DateTime Format Validation
5506
- * @param string $format
5507
- * @param string $date
5508
- * @return boolean
5509
- */
5510
- public function check_date_time_validation($format, $date)
5511
- {
5512
- if(func_num_args() < 2) return;
5513
-
5514
- $check = DateTime::createFromFormat($format, $date);
5515
-
5516
- return $check && $check->format($format) === $date;
5517
- }
5518
  }
1
+ <?php
2
+ /** no direct access **/
3
+ defined('MECEXEC') or die();
4
+
5
+ use ICal\ICal;
6
+
7
+ /**
8
+ * Webnus MEC main class.
9
+ * @author Webnus <info@webnus.biz>
10
+ */
11
+ class MEC_main extends MEC_base
12
+ {
13
+ /**
14
+ * Constructor method
15
+ * @author Webnus <info@webnus.biz>
16
+ */
17
+ public function __construct()
18
+ {
19
+ }
20
+
21
+ /**
22
+ * Returns the archive URL of events for provided skin
23
+ * @author Webnus <info@webnus.biz>
24
+ * @param string $skin
25
+ * @return string
26
+ */
27
+ public function archive_URL($skin)
28
+ {
29
+ return $this->URL('site').$this->get_main_slug().'/'.$skin.'/';
30
+ }
31
+
32
+ /**
33
+ * Returns full current URL of WordPress
34
+ * @author Webnus <info@webnus.biz>
35
+ * @return string
36
+ */
37
+ public function get_full_url()
38
+ {
39
+ // get $_SERVER
40
+ $server = $this->getRequest()->get('SERVER');
41
+
42
+ // Check protocol
43
+ $page_url = 'http';
44
+ if(isset($server['HTTPS']) and $server['HTTPS'] == 'on') $page_url .= 's';
45
+
46
+ // Get domain
47
+ $site_domain = (isset($server['HTTP_HOST']) and trim($server['HTTP_HOST']) != '') ? $server['HTTP_HOST'] : $server['SERVER_NAME'];
48
+
49
+ $page_url .= '://';
50
+ $page_url .= $site_domain.$server['REQUEST_URI'];
51
+
52
+ // Return full URL
53
+ return $page_url;
54
+ }
55
+
56
+ /**
57
+ * Get domain of a certain URL
58
+ * @author Webnus <info@webnus.biz>
59
+ * @param string $url
60
+ * @return string
61
+ */
62
+ public function get_domain($url = NULL)
63
+ {
64
+ // Get current URL
65
+ if(is_null($url)) $url = $this->get_full_url();
66
+
67
+ $url = str_replace('http://', '', $url);
68
+ $url = str_replace('https://', '', $url);
69
+ $url = str_replace('ftp://', '', $url);
70
+ $url = str_replace('svn://', '', $url);
71
+ $url = str_replace('www.', '', $url);
72
+
73
+ $ex = explode('/', $url);
74
+ $ex2 = explode('?', $ex[0]);
75
+
76
+ return $ex2[0];
77
+ }
78
+
79
+ /**
80
+ * Remove query string from the URL
81
+ * @author Webnus <info@webnus.biz>
82
+ * @param string $key
83
+ * @param string $url
84
+ * @return string
85
+ */
86
+ public function remove_qs_var($key, $url = '')
87
+ {
88
+ if(trim($url) == '') $url = $this->get_full_url();
89
+
90
+ $url = preg_replace('/(.*)(\?|&)'.$key.'=[^&]+?(&)(.*)/i', '$1$2$4', $url .'&');
91
+ $url = substr($url, 0, -1);
92
+
93
+ return $url;
94
+ }
95
+
96
+ /**
97
+ * Add query string to the URL
98
+ * @author Webnus <info@webnus.biz>
99
+ * @param string $key
100
+ * @param string $value
101
+ * @param string $url
102
+ * @return string
103
+ */
104
+ public function add_qs_var($key, $value, $url = '')
105
+ {
106
+ if(trim($url) == '') $url = $this->get_full_url();
107
+
108
+ $url = preg_replace('/(.*)(\?|&)'.$key.'=[^&]+?(&)(.*)/i', '$1$2$4', $url.'&');
109
+ $url = substr($url, 0, -1);
110
+
111
+ if(strpos($url, '?') === false)
112
+ return $url.'?'.$key.'='.$value;
113
+ else
114
+ return $url.'&'.$key.'='.$value;
115
+ }
116
+
117
+ /**
118
+ * Add multiple query strings to the URL
119
+ * @author Webnus <info@webnus.biz>
120
+ * @param array $vars
121
+ * @param string $url
122
+ * @return string
123
+ */
124
+ public function add_qs_vars($vars, $url = '')
125
+ {
126
+ if(trim($url) == '') $url = $this->get_full_url();
127
+
128
+ foreach($vars as $key=>$value) $url = $this->add_qs_var($key, $value, $url);
129
+ return $url;
130
+ }
131
+
132
+ /**
133
+ * Returns WordPress authors
134
+ * @author Webnus <info@webnus.biz>
135
+ * @param array $args
136
+ * @return array
137
+ */
138
+ public function get_authors($args = array())
139
+ {
140
+ return get_users($args);
141
+ }
142
+
143
+ /**
144
+ * Returns full URL of an asset
145
+ * @author Webnus <info@webnus.biz>
146
+ * @param string $asset
147
+ * @return string
148
+ */
149
+ public function asset($asset)
150
+ {
151
+ return $this->URL('MEC').'assets/'.$asset;
152
+ }
153
+
154
+ /**
155
+ * Returns URL of WordPress items such as site, admin, plugins, MEC plugin etc.
156
+ * @author Webnus <info@webnus.biz>
157
+ * @param string $type
158
+ * @return string
159
+ */
160
+ public function URL($type = 'site')
161
+ {
162
+ // Make it lowercase
163
+ $type = strtolower($type);
164
+
165
+ // Frontend
166
+ if(in_array($type, array('frontend','site'))) $url = home_url().'/';
167
+ // Backend
168
+ elseif(in_array($type, array('backend','admin'))) $url = admin_url();
169
+ // WordPress Content directory URL
170
+ elseif($type == 'content') $url = content_url().'/';
171
+ // WordPress plugins directory URL
172
+ elseif($type == 'plugin') $url = plugins_url().'/';
173
+ // WordPress include directory URL
174
+ elseif($type == 'include') $url = includes_url();
175
+ // Webnus MEC plugin URL
176
+ elseif($type == 'mec')
177
+ {
178
+ // If plugin installed regularly on plugins directory
179
+ if(!defined('MEC_IN_THEME')) $url = plugins_url().'/'.MEC_DIRNAME.'/';
180
+ // If plugin embeded into one theme
181
+ else $url = get_template_directory_uri().'/plugins/'.MEC_DIRNAME.'/';
182
+ }
183
+
184
+ return $url;
185
+ }
186
+
187
+ /**
188
+ * Returns plugin absolute path
189
+ * @author Webnus <info@webnus.biz>
190
+ * @return string
191
+ */
192
+ public function get_plugin_path()
193
+ {
194
+ return MEC_ABSPATH;
195
+ }
196
+
197
+ /**
198
+ * Returns a WordPress option
199
+ * @author Webnus <info@webnus.biz>
200
+ * @param string $option
201
+ * @param mixed $default
202
+ * @return mixed
203
+ */
204
+ public function get_option($option, $default = NULL)
205
+ {
206
+ return get_option($option, $default);
207
+ }
208
+
209
+ /**
210
+ * Returns WordPress categories based on arguments
211
+ * @author Webnus <info@webnus.biz>
212
+ * @param array $args
213
+ * @return array
214
+ */
215
+ public function get_categories($args = array())
216
+ {
217
+ return get_categories($args);
218
+ }
219
+
220
+ /**
221
+ * Returns WordPress tags based on arguments
222
+ * @author Webnus <info@webnus.biz>
223
+ * @param array $args
224
+ * @return array
225
+ */
226
+ public function get_tags($args = array())
227
+ {
228
+ return get_tags($args);
229
+ }
230
+
231
+ /**
232
+ * Convert location string to latitude and longitude
233
+ * @author Webnus <info@webnus.biz>
234
+ * @param string $address
235
+ * @return array
236
+ */
237
+ public function get_lat_lng($address)
238
+ {
239
+ $address = urlencode($address);
240
+ if(!trim($address)) return array(0, 0);
241
+
242
+ // MEC Settings
243
+ $settings = $this->get_settings();
244
+
245
+ $url1 = "https://maps.googleapis.com/maps/api/geocode/json?address=".$address.((isset($settings['google_maps_api_key']) and trim($settings['google_maps_api_key']) != '') ? '&key='.$settings['google_maps_api_key'] : '');
246
+ $url2 = 'http://www.datasciencetoolkit.org/maps/api/geocode/json?sensor=false&address='.$address;
247
+
248
+ // Get Latitide and Longitude by First URL
249
+ $JSON = wp_remote_retrieve_body(wp_remote_get($url1, array(
250
+ 'body' => null,
251
+ 'timeout' => '10',
252
+ 'redirection' => '10',
253
+ )));
254
+
255
+ $data = json_decode($JSON, true);
256
+
257
+ $location_point = isset($data['results'][0]) ? $data['results'][0]['geometry']['location'] : array();
258
+ if((isset($location_point['lat']) and $location_point['lat']) and (isset($location_point['lng']) and $location_point['lng']))
259
+ {
260
+ return array($location_point['lat'], $location_point['lng']);
261
+ }
262
+
263
+ // Get Latitide and Longitude by Second URL
264
+ $JSON = wp_remote_retrieve_body(wp_remote_get($url2, array(
265
+ 'body' => null,
266
+ 'timeout' => '10',
267
+ 'redirection' => '10',
268
+ )));
269
+
270
+ $data = json_decode($JSON, true);
271
+
272
+ $location_point = isset($data['results'][0]) ? $data['results'][0]['geometry']['location'] : array();
273
+ if((isset($location_point['lat']) and $location_point['lat']) and (isset($location_point['lng']) and $location_point['lng']))
274
+ {
275
+ return array($location_point['lat'], $location_point['lng']);
276
+ }
277
+
278
+ return array(0, 0);
279
+ }
280
+
281
+ /**
282
+ * @author Webnus <info@webnus.biz>
283
+ * @return string
284
+ */
285
+ public function get_default_label_color()
286
+ {
287
+ return apply_filters('mec_default_label_color', '#fefefe');
288
+ }
289
+
290
+ /**
291
+ * @author Webnus <info@webnus.biz>
292
+ * @param int $post_id
293
+ * @return string
294
+ */
295
+ public function get_post_content($post_id)
296
+ {
297
+ $post = get_post($post_id);
298
+ if(!$post) return NULL;
299
+
300
+ $content = apply_filters('the_content', $post->post_content);
301
+ return str_replace(']]>', ']]&gt;', do_shortcode($content));
302
+ }
303
+
304
+ /**
305
+ * @author Webnus <info@webnus.biz>
306
+ * @param int $post_id
307
+ * @return array
308
+ */
309
+ public function get_post_meta($post_id)
310
+ {
311
+ $raw_data = get_post_meta($post_id, '', true);
312
+ $data = array();
313
+
314
+ // Invalid Raw Data
315
+ if(!is_array($raw_data)) return $data;
316
+
317
+ foreach($raw_data as $key=>$val) $data[$key] = isset($val[0]) ? (!is_serialized($val[0]) ? $val[0] : unserialize($val[0])) : NULL;
318
+
319
+ return $data;
320
+ }
321
+
322
+ /**
323
+ * @author Webnus <info@webnus.biz>
324
+ * @return array
325
+ */
326
+ public function get_skins()
327
+ {
328
+ $skins = array
329
+ (
330
+ 'list'=>__('List View', 'modern-events-calendar-lite'),
331
+ 'grid'=>__('Grid View', 'modern-events-calendar-lite'),
332
+ 'agenda'=>__('Agenda View', 'modern-events-calendar-lite'),
333
+ 'full_calendar'=>__('Full Calendar', 'modern-events-calendar-lite'),
334
+ 'yearly_view'=>__('Yearly View', 'modern-events-calendar-lite'),
335
+ 'monthly_view'=>__('Calendar/Monthly View', 'modern-events-calendar-lite'),
336
+ 'daily_view'=>__('Daily View', 'modern-events-calendar-lite'),
337
+ 'weekly_view'=>__('Weekly View', 'modern-events-calendar-lite'),
338
+ 'timetable'=>__('Timetable View', 'modern-events-calendar-lite'),
339
+ 'masonry'=>__('Masonry View', 'modern-events-calendar-lite'),
340
+ 'map'=>__('Map View', 'modern-events-calendar-lite'),
341
+ 'cover'=>__('Cover View', 'modern-events-calendar-lite'),
342
+ 'countdown'=>__('Countdown View', 'modern-events-calendar-lite'),
343
+ 'available_spot'=>__('Available Spot', 'modern-events-calendar-lite'),
344
+ 'carousel'=>__('Carousel View', 'modern-events-calendar-lite'),
345
+ 'slider'=>__('Slider View', 'modern-events-calendar-lite'),
346
+ 'timeline'=>__('Timeline View', 'modern-events-calendar-lite')
347
+ );
348
+
349
+ return apply_filters('mec_calendar_skins', $skins);
350
+ }
351
+
352
+ /**
353
+ * Returns weekday labels
354
+ * @author Webnus <info@webnus.biz>
355
+ * @param integer $week_start
356
+ * @return array
357
+ */
358
+ public function get_weekday_labels($week_start = NULL)
359
+ {
360
+ if(is_null($week_start)) $week_start = $this->get_first_day_of_week();
361
+
362
+ /**
363
+ * Please don't change it to translate-able strings
364
+ */
365
+ $raw = array('Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday');
366
+
367
+ $labels = array_slice($raw, $week_start);
368
+ $rest = array_slice($raw, 0, $week_start);
369
+
370
+ foreach($rest as $label) array_push($labels, $label);
371
+
372
+ return apply_filters('mec_weekday_labels', $labels);
373
+ }
374
+
375
+ /**
376
+ * Returns abbr weekday labels
377
+ * @author Webnus <info@webnus.biz>
378
+ * @return array
379
+ */
380
+ public function get_weekday_abbr_labels()
381
+ {
382
+ $week_start = $this->get_first_day_of_week();
383
+ $raw = array(
384
+ $this->m('weekdays_su', __('SU', 'modern-events-calendar-lite')),
385
+ $this->m('weekdays_mo', __('MO', 'modern-events-calendar-lite')),
386
+ $this->m('weekdays_tu', __('TU', 'modern-events-calendar-lite')),
387
+ $this->m('weekdays_we', __('WE', 'modern-events-calendar-lite')),
388
+ $this->m('weekdays_th', __('TH', 'modern-events-calendar-lite')),
389
+ $this->m('weekdays_fr', __('FR', 'modern-events-calendar-lite')),
390
+ $this->m('weekdays_sa', __('SA', 'modern-events-calendar-lite'))
391
+ );
392
+
393
+ $labels = array_slice($raw, $week_start);
394
+ $rest = array_slice($raw, 0, $week_start);
395
+
396
+ foreach($rest as $label) array_push($labels, $label);
397
+
398
+ return apply_filters('mec_weekday_abbr_labels', $labels);
399
+ }
400
+
401
+ /**
402
+ * Returns translatable weekday labels
403
+ * @author Webnus <info@webnus.biz>
404
+ * @return array
405
+ */
406
+ public function get_weekday_i18n_labels()
407
+ {
408
+ $week_start = $this->get_first_day_of_week();
409
+ $raw = array(array(7, __('Sunday', 'modern-events-calendar-lite')), array(1, __('Monday', 'modern-events-calendar-lite')), array(2, __('Tuesday', 'modern-events-calendar-lite')), array(3, __('Wednesday', 'modern-events-calendar-lite')), array(4, __('Thursday', 'modern-events-calendar-lite')), array(5, __('Friday', 'modern-events-calendar-lite')), array(6, __('Saturday', 'modern-events-calendar-lite')));
410
+
411
+ $labels = array_slice($raw, $week_start);
412
+ $rest = array_slice($raw, 0, $week_start);
413
+
414
+ foreach($rest as $label) array_push($labels, $label);
415
+
416
+ return apply_filters('mec_weekday_i18n_labels', $labels);
417
+ }
418
+
419
+ /**
420
+ * Flush WordPress rewrite rules
421
+ * @author Webnus <info@webnus.biz>
422
+ */
423
+ public function flush_rewrite_rules()
424
+ {
425
+ // Register Events Post Type
426
+ $MEC_events = MEC::getInstance('app.features.events', 'MEC_feature_events');
427
+ $MEC_events->register_post_type();
428
+
429
+ flush_rewrite_rules();
430
+ }
431
+
432
+ /**
433
+ * Get single slug of MEC
434
+ * @author Webnus <info@webnus.biz>
435
+ * @return string
436
+ */
437
+ public function get_single_slug()
438
+ {
439
+ $settings = $this->get_settings();
440
+ $slug = (isset($settings['single_slug']) and trim($settings['single_slug']) != '') ? $settings['single_slug'] : 'event';
441
+
442
+ return $slug;
443
+ }
444
+
445
+ /**
446
+ * Returns main slug of MEC
447
+ * @author Webnus <info@webnus.biz>
448
+ * @return string
449
+ */
450
+ public function get_main_slug()
451
+ {
452
+ $settings = $this->get_settings();
453
+ $slug = (isset($settings['slug']) and trim($settings['slug']) != '') ? $settings['slug'] : 'events';
454
+
455
+ return strtolower($slug);
456
+ }
457
+
458
+ /**
459
+ * Returns category slug of MEC
460
+ * @author Webnus <info@webnus.biz>
461
+ * @return string
462
+ */
463
+ public function get_category_slug()
464
+ {
465
+ $settings = $this->get_settings();
466
+ $slug = (isset($settings['category_slug']) and trim($settings['category_slug']) != '') ? $settings['category_slug'] : 'mec-category';
467
+
468
+ return strtolower($slug);
469
+ }
470
+
471
+ /**
472
+ * Get archive page title
473
+ * @author Webnus <info@webnus.biz>
474
+ * @return string
475
+ */
476
+ public function get_archive_title()
477
+ {
478
+ $settings = $this->get_settings();
479
+ $archive_title = (isset($settings['archive_title']) and trim($settings['archive_title']) != '') ? $settings['archive_title'] : 'Events';
480
+
481
+ return apply_filters('mec_archive_title', $archive_title);
482
+ }
483
+
484
+ /**
485
+ * @author Webnus <info@webnus.biz>
486
+ * @return string
487
+ */
488
+ public function get_archive_thumbnail()
489
+ {
490
+ return apply_filters('mec_archive_thumbnail', '');
491
+ }
492
+
493
+ /**
494
+ * @author Webnus <info@webnus.biz>
495
+ * @return string
496
+ */
497
+ public function get_single_thumbnail()
498
+ {
499
+ return apply_filters('mec_single_thumbnail', '');
500
+ }
501
+
502
+ /**
503
+ * @author Webnus <info@webnus.biz>
504
+ * @return string
505
+ */
506
+ public function get_main_post_type()
507
+ {
508
+ return apply_filters('mec_post_type_name', 'mec-events');
509
+ }
510
+
511
+ /**
512
+ * Returns main options of MEC
513
+ * @author Webnus <info@webnus.biz>
514
+ * @return array
515
+ */
516
+ public function get_options()
517
+ {
518
+ return get_option('mec_options', array());
519
+ }
520
+
521
+ /**
522
+ * Returns MEC settings menus
523
+ * @author Webnus <info@webnus.biz>
524
+ * @return array
525
+ */
526
+ public function get_sidebar_menu($active_menu = 'settings')
527
+ {
528
+ $options = $this->get_settings();
529
+ $settings = apply_filters('mec-settings-items-settings', array(
530
+ __('General Options', 'modern-events-calendar-lite') => 'general_option',
531
+ __('Archive Pages', 'modern-events-calendar-lite') => 'archive_options',
532
+ __('Slugs/Permalinks', 'modern-events-calendar-lite') => 'slug_option',
533
+ __('Currency Options', 'modern-events-calendar-lite') => 'currency_option',
534
+ __('Google Recaptcha Options', 'modern-events-calendar-lite') => 'recaptcha_option',
535
+ __('Frontend Event Submission', 'modern-events-calendar-lite') => 'fes_option',
536
+ __('User Profile', 'modern-events-calendar-lite') => 'user_profile_options',
537
+ __('Search Bar', 'modern-events-calendar-lite') => 'search_bar_options',
538
+ __('Mailchimp Integration', 'modern-events-calendar-lite') => 'mailchimp_option',
539
+ __('Upload Field', 'modern-events-calendar-lite') => 'uploadfield_option',
540
+ ), $active_menu);
541
+
542
+ $single_event = apply_filters('mec-settings-item-single_event', array(
543
+ __('Single Event Page', 'modern-events-calendar-lite') => 'event_options',
544
+ __('Countdown Options', 'modern-events-calendar-lite') => 'countdown_option',
545
+ __('Exceptional Days', 'modern-events-calendar-lite') => 'exceptional_option',
546
+ __('Additional Organizers', 'modern-events-calendar-lite') => 'additional_organizers',
547
+ __('Additional Locations', 'modern-events-calendar-lite') => 'additional_locations',
548
+ __('Related Events', 'modern-events-calendar-lite') => 'related_events',
549
+ ), $active_menu);
550
+
551
+ $booking = apply_filters('mec-settings-item-booking', array(
552
+ __('Booking', 'modern-events-calendar-lite') => 'booking_option',
553
+ __('Coupons', 'modern-events-calendar-lite') => 'coupon_option',
554
+ __('Taxes / Fees', 'modern-events-calendar-lite') => 'taxes_option',
555
+ __('Ticket Variations & Options', 'modern-events-calendar-lite') => 'ticket_variations_option',
556
+ __('Booking Form', 'modern-events-calendar-lite') => 'booking_form_option',
557
+ __('Payment Gateways', 'modern-events-calendar-lite') => 'payment_gateways_option',
558
+ ), $active_menu);
559
+
560
+ $modules = apply_filters('mec-settings-item-modules', array(
561
+ __('Speakers', 'modern-events-calendar-lite') => 'speakers_option',
562
+ __('Google Maps Options', 'modern-events-calendar-lite') => 'googlemap_option',
563
+ __('Export Options', 'modern-events-calendar-lite') => 'export_module_option',
564
+ __('Local Time', 'modern-events-calendar-lite') => 'time_module_option',
565
+ __('QR Code', 'modern-events-calendar-lite') => 'qrcode_module_option',
566
+ __('Weather', 'modern-events-calendar-lite') => 'weather_module_option',
567
+ __('Social Networks', 'modern-events-calendar-lite') => 'social_options',
568
+ __('Next Event', 'modern-events-calendar-lite') => 'next_event_option',
569
+ __('BuddyPress Integration', 'modern-events-calendar-lite') => 'buddy_option',
570
+ ), $active_menu);
571
+
572
+ $notifications = apply_filters('mec-settings-item-notifications', array(
573
+ __('Booking', 'modern-events-calendar-lite') => 'booking_notification',
574
+ __('Booking Verification', 'modern-events-calendar-lite') => 'booking_verification',
575
+ __('Booking Confirmation', 'modern-events-calendar-lite') => 'booking_confirmation',
576
+ __('Booking Cancellation', 'modern-events-calendar-lite') => 'cancellation_notification',
577
+ __('Booking Reminder', 'modern-events-calendar-lite') => 'booking_reminder',
578
+ __('Admin', 'modern-events-calendar-lite') => 'admin_notification',
579
+ __('New Event', 'modern-events-calendar-lite') => 'new_event',
580
+ __('User Event Publishing', 'modern-events-calendar-lite') => 'user_event_publishing',
581
+ ), $active_menu);
582
+
583
+ ?>
584
+ <ul class="wns-be-group-menu">
585
+
586
+ <!-- Settings -->
587
+ <li class="wns-be-group-menu-li mec-settings-menu <?php echo $active_menu == 'settings' ? 'active' : ''; ?>">
588
+ <a href="<?php echo $this->remove_qs_var('tab'); ?>" id="" class="wns-be-group-tab-link-a">
589
+ <i class="mec-sl-settings"></i>
590
+ <span class="wns-be-group-menu-title"><?php _e('Settings', 'modern-events-calendar-lite'); ?></span>
591
+ </a>
592
+ <ul class="<?php echo $active_menu == 'settings' ? 'subsection' : 'mec-settings-submenu'; ?>">
593
+ <?php foreach ($settings as $settings_name => $settings_link) : ?>
594
+ <?php
595
+ if ( $settings_link == 'mailchimp_option') :
596
+ if ( $this->getPRO() ) : ?>
597
+ <li>
598
+ <a
599
+ <?php if ( $active_menu == 'settings' ) : ?>
600
+ data-id="<?php echo $settings_link; ?>" class="wns-be-group-tab-link-a WnTabLinks"
601
+ <?php else: ?>
602
+ href="<?php echo $this->remove_qs_var('tab') . '#' . $settings_link; ?>"
603
+ <?php endif; ?>
604
+ >
605
+ <span class="pr-be-group-menu-title"><?php echo $settings_name; ?></span>
606
+ </a>
607
+ </li>
608
+ <?php
609
+ endif;
610
+ else : ?>
611
+ <li>
612
+ <a
613
+ <?php if ( $active_menu == 'settings' ) : ?>
614
+ data-id="<?php echo $settings_link; ?>" class="wns-be-group-tab-link-a WnTabLinks"
615
+ <?php else: ?>
616
+ href="<?php echo $this->remove_qs_var('tab') . '#' . $settings_link; ?>"
617
+ <?php endif; ?>
618
+ >
619
+ <span class="pr-be-group-menu-title"><?php echo $settings_name; ?></span>
620
+ </a>
621
+ </li>
622
+ <?php endif; ?>
623
+ <?php endforeach; ?>
624
+ </ul>
625
+ </li>
626
+
627
+ <!-- Single Event -->
628
+ <li class="wns-be-group-menu-li mec-settings-menu <?php echo $active_menu == 'single_event' ? 'active' : ''; ?>">
629
+ <a href="<?php echo $this->add_qs_var('tab', 'MEC-single'); ?>" id="" class="wns-be-group-tab-link-a">
630
+ <i class="mec-sl-note"></i>
631
+ <span class="wns-be-group-menu-title"><?php _e('Single Event', 'modern-events-calendar-lite'); ?></span>
632
+ </a>
633
+ <ul class="<?php echo $active_menu == 'single_event' ? 'subsection' : 'mec-settings-submenu'; ?>">
634
+ <?php foreach ($single_event as $single_event_name => $single_event_link) : ?>
635
+ <li>
636
+ <a
637
+ <?php if ( $active_menu == 'single_event' ) : ?>
638
+ data-id="<?php echo $single_event_link; ?>" class="wns-be-group-tab-link-a WnTabLinks"
639
+ <?php else: ?>
640
+ href="<?php echo $this->add_qs_var('tab', 'MEC-single') . '#' . $single_event_link; ?>"
641
+ <?php endif; ?>
642
+ >
643
+ <span class="pr-be-group-menu-title"><?php echo $single_event_name; ?></span>
644
+ </a>
645
+ </li>
646
+ <?php endforeach; ?>
647
+ </ul>
648
+ </li>
649
+
650
+ <!-- Booking -->
651
+ <?php if($this->getPRO()): ?>
652
+ <li class="wns-be-group-menu-li mec-settings-menu <?php echo $active_menu == 'booking' ? 'active' : ''; ?>">
653
+ <a href="<?php echo $this->add_qs_var('tab', 'MEC-booking'); ?>" id="" class="wns-be-group-tab-link-a">
654
+ <i class="mec-sl-credit-card"></i>
655
+ <span class="wns-be-group-menu-title"><?php _e('Booking', 'modern-events-calendar-lite'); ?></span>
656
+ </a>
657
+ <ul class="<?php echo $active_menu == 'booking' ? 'subsection' : 'mec-settings-submenu'; ?>">
658
+
659
+ <?php foreach ($booking as $booking_name => $booking_link) : ?>
660
+ <?php if ( $booking_link == 'coupon_option' || $booking_link == 'taxes_option' || $booking_link == 'ticket_variations_option' || $booking_link == 'booking_form_option' || $booking_link == 'payment_gateways_option' ): ?>
661
+ <?php if ( isset($options['booking_status']) and $options['booking_status'] ) : ?>
662
+ <li>
663
+ <a
664
+ <?php if ( $active_menu == 'booking' ) : ?>
665
+ data-id="<?php echo $booking_link; ?>" class="wns-be-group-tab-link-a WnTabLinks"
666
+ <?php else: ?>
667
+ href="<?php echo $this->add_qs_var('tab', 'MEC-booking') . '#' . $booking_link; ?>"
668
+ <?php endif; ?>
669
+ >
670
+ <span class="pr-be-group-menu-title"><?php echo $booking_name; ?></span>
671
+ </a>
672
+ </li>
673
+ <?php endif; ?>
674
+ <?php else: ?>
675
+ <li>
676
+ <a
677
+ <?php if ( $active_menu == 'booking' ) : ?>
678
+ data-id="<?php echo $booking_link; ?>" class="wns-be-group-tab-link-a WnTabLinks"
679
+ <?php else: ?>
680
+ href="<?php echo $this->add_qs_var('tab', 'MEC-booking') . '#' . $booking_link; ?>"
681
+ <?php endif; ?>
682
+ >
683
+ <span class="pr-be-group-menu-title"><?php echo $booking_name; ?></span>
684
+ </a>
685
+ </li>
686
+ <?php endif; ?>
687
+
688
+ <?php endforeach; ?>
689
+ </ul>
690
+ </li>
691
+ <?php endif; ?>
692
+
693
+ <!-- Modules -->
694
+ <li class="wns-be-group-menu-li mec-settings-menu <?php echo $active_menu == 'modules' ? 'active' : ''; ?>">
695
+ <a href="<?php echo $this->add_qs_var('tab', 'MEC-modules'); ?>" id="" class="wns-be-group-tab-link-a">
696
+ <i class="mec-sl-grid"></i>
697
+ <span class="wns-be-group-menu-title"><?php _e('Modules', 'modern-events-calendar-lite'); ?></span>
698
+ </a>
699
+ <ul class="<?php echo $active_menu == 'modules' ? 'subsection' : 'mec-settings-submenu'; ?>">
700
+
701
+ <?php foreach ($modules as $modules_name => $modules_link) : ?>
702
+ <?php if ( $modules_link == 'googlemap_option' || $modules_link == 'qrcode_module_option' || $modules_link == 'weather_module_option' || $modules_link == 'buddy_option' ): ?>
703
+ <?php if($this->getPRO()): ?>
704
+ <li>
705
+ <a
706
+ <?php if ( $active_menu == 'modules' ) : ?>
707
+ data-id="<?php echo $modules_link; ?>" class="wns-be-group-tab-link-a WnTabLinks"
708
+ <?php else: ?>
709
+ href="<?php echo $this->add_qs_var('tab', 'MEC-modules') . '#' . $modules_link; ?>"
710
+ <?php endif; ?>
711
+ >
712
+ <span class="pr-be-group-menu-title"><?php echo $modules_name; ?></span>
713
+ </a>
714
+ </li>
715
+ <?php endif; ?>
716
+ <?php else: ?>
717
+ <li>
718
+ <a
719
+ <?php if ( $active_menu == 'modules' ) : ?>
720
+ data-id="<?php echo $modules_link; ?>" class="wns-be-group-tab-link-a WnTabLinks"
721
+ <?php else: ?>
722
+ href="<?php echo $this->add_qs_var('tab', 'MEC-modules') . '#' . $modules_link; ?>"
723
+ <?php endif; ?>
724
+ >
725
+ <span class="pr-be-group-menu-title"><?php echo $modules_name; ?></span>
726
+ </a>
727
+ </li>
728
+ <?php endif; ?>
729
+
730
+ <?php endforeach; ?>
731
+ </ul>
732
+ </li>
733
+
734
+ <!-- Notifications -->
735
+ <li class="wns-be-group-menu-li mec-settings-menu <?php echo $active_menu == 'notifications' ? 'active' : ''; ?>">
736
+ <a href="<?php echo $this->add_qs_var('tab', 'MEC-notifications'); ?>" id="" class="wns-be-group-tab-link-a">
737
+ <i class="mec-sl-envelope"></i>
738
+ <span class="wns-be-group-menu-title"><?php _e('Notifications', 'modern-events-calendar-lite'); ?></span>
739
+ </a>
740
+ <ul class="<?php echo $active_menu == 'notifications' ? 'subsection' : 'mec-settings-submenu'; ?>">
741
+
742
+ <?php foreach ($notifications as $notifications_name => $notifications_link) : ?>
743
+ <?php if ( $notifications_link != 'new_event' and $notifications_link != 'user_event_publishing' ): ?>
744
+ <?php if(isset($options['booking_status']) and $options['booking_status']): ?>
745
+ <li>
746
+ <a
747
+ <?php if ( $active_menu == 'notifications' ) : ?>
748
+ data-id="<?php echo $notifications_link; ?>" class="wns-be-group-tab-link-a WnTabLinks"
749
+ <?php else: ?>
750
+ href="<?php echo $this->add_qs_var('tab', 'MEC-notifications') . '#' . $notifications_link; ?>"
751
+ <?php endif; ?>
752
+ >
753
+ <span class="pr-be-group-menu-title"><?php echo $notifications_name; ?></span>
754
+ </a>
755
+ </li>
756
+ <?php endif; ?>
757
+ <?php else: ?>
758
+ <li>
759
+ <a
760
+ <?php if ( $active_menu == 'notifications' ) : ?>
761
+ data-id="<?php echo $notifications_link; ?>" class="wns-be-group-tab-link-a WnTabLinks"
762
+ <?php else: ?>
763
+ href="<?php echo $this->add_qs_var('tab', 'MEC-notifications') . '#' . $notifications_link; ?>"
764
+ <?php endif; ?>
765
+ >
766
+ <span class="pr-be-group-menu-title"><?php echo $notifications_name; ?></span>
767
+ </a>
768
+ </li>
769
+ <?php endif; ?>
770
+ <?php endforeach; ?>
771
+ </ul>
772
+ </li>
773
+
774
+ <li class="wns-be-group-menu-li mec-settings-menu <?php echo $active_menu == 'styling' ? 'active' : ''; ?>">
775
+ <a href="<?php echo $this->add_qs_var('tab', 'MEC-styling'); ?>" id="" class="wns-be-group-tab-link-a">
776
+ <i class="mec-sl-equalizer"></i>
777
+ <span class="wns-be-group-menu-title"><?php _e('Styling Options', 'modern-events-calendar-lite'); ?></span>
778
+ </a>
779
+ </li>
780
+
781
+ <li class="wns-be-group-menu-li mec-settings-menu <?php echo $active_menu == 'customcss' ? 'active' : ''; ?>">
782
+ <a href="<?php echo $this->add_qs_var('tab', 'MEC-customcss'); ?>" id="" class="wns-be-group-tab-link-a">
783
+ <i class="mec-sl-wrench"></i>
784
+ <span class="wns-be-group-menu-title"><?php _e('Custom CSS', 'modern-events-calendar-lite'); ?></span>
785
+ </a>
786
+ </li>
787
+
788
+ <li class="wns-be-group-menu-li mec-settings-menu <?php echo $active_menu == 'messages' ? 'active' : ''; ?>">
789
+ <a href="<?php echo $this->add_qs_var('tab', 'MEC-messages'); ?>" id="" class="wns-be-group-tab-link-a">
790
+ <i class="mec-sl-bubble"></i>
791
+ <span class="wns-be-group-menu-title"><?php _e('Messages', 'modern-events-calendar-lite'); ?></span>
792
+ </a>
793
+ </li>
794
+
795
+ <li class="wns-be-group-menu-li mec-settings-menu <?php echo $active_menu == 'ie' ? 'active' : ''; ?>">
796
+ <a href="<?php echo $this->add_qs_var('tab', 'MEC-ie'); ?>" id="" class="wns-be-group-tab-link-a">
797
+ <i class="mec-sl-refresh"></i>
798
+ <span class="wns-be-group-menu-title"><?php _e('Import / Export', 'modern-events-calendar-lite'); ?></span>
799
+ </a>
800
+ </li>
801
+ </ul> <!-- close wns-be-group-menu -->
802
+ <script type="text/javascript">
803
+ jQuery(document).ready(function()
804
+ {
805
+ if ( jQuery('.mec-settings-menu').hasClass('active') )
806
+ {
807
+ jQuery('.mec-settings-menu.active').find('ul li:first-of-type').addClass('active');
808
+ }
809
+
810
+ jQuery('.WnTabLinks').each(function()
811
+ {
812
+ var ContentId = jQuery(this).attr('data-id');
813
+ jQuery(this).click(function()
814
+ {
815
+ jQuery('.wns-be-sidebar li ul li').removeClass('active');
816
+ jQuery(this).parent().addClass('active');
817
+ jQuery(".mec-options-fields").hide();
818
+ jQuery(".mec-options-fields").removeClass('active');
819
+ jQuery("#"+ContentId+"").show();
820
+ jQuery("#"+ContentId+"").addClass('active');
821
+ jQuery('html, body').animate({
822
+ scrollTop: jQuery("#"+ContentId+"").offset().top - 140
823
+ }, 300);
824
+ });
825
+ var hash = window.location.hash.replace('#', '');
826
+ jQuery('[data-id="'+hash+'"]').trigger('click');
827
+ });
828
+
829
+
830
+
831
+ jQuery(".wns-be-sidebar li ul li").on('click', function(event)
832
+ {
833
+ jQuery(".wns-be-sidebar li ul li").removeClass('active');
834
+ jQuery(this).addClass('active');
835
+ });
836
+
837
+ });
838
+ </script>
839
+ <?php
840
+
841
+ }
842
+
843
+ /**
844
+ * Returns MEC settings
845
+ * @author Webnus <info@webnus.biz>
846
+ * @return array
847
+ */
848
+ public function get_settings()
849
+ {
850
+ $options = $this->get_options();
851
+ return (isset($options['settings']) ? $options['settings'] : array());
852
+ }
853
+
854
+ /**
855
+ * Returns MEC addons message
856
+ * @author Webnus <info@webnus.biz>
857
+ * @return array
858
+ */
859
+ public function addons_msg()
860
+ {
861
+ $get_n_option = get_option('mec_addons_notification_option');
862
+ if ( $get_n_option == 'open' ) return;
863
+ return '
864
+ <div class="w-row mec-addons-notification-wrap">
865
+ <div class="w-col-sm-12">
866
+ <div class="w-clearfix w-box mec-addons-notification-box-wrap">
867
+ <div class="w-box-head">'.__('New Addons For MEC! Now Customize MEC in Elementor', 'modern-events-calendar-lite').'<span><i class="mec-sl-close"></i></span></div>
868
+ <div class="w-box-content">
869
+ <div class="mec-addons-notification-box-image">
870
+ <img src="'. plugin_dir_url(__FILE__ ) . '../../assets/img/mec-addons-teaser1.png" />
871
+ </div>
872
+ <div class="mec-addons-notification-box-content">
873
+ <div class="w-box-content">
874
+ <p>'.__('The time has come at last, and the new practical add-ons for MEC have been released. This is a revolution in the world of Event Calendars. We have provided you with a wide range of features only by having the 4 add-ons below:' , 'modern-events-calendar-lite').'</p>
875
+ <ol>
876
+ <li>'.__('<strong>WooCommerce Integration:</strong> You can now purchase ticket (as products) and Woo products at the same time.' , 'modern-events-calendar-lite').'</li>
877
+ <li>'.__('<strong>Event API:</strong> display your events (shortcodes/single event) on other websites without MEC. Use JSON output features to make your Apps compatible with MEC.' , 'modern-events-calendar-lite').'</li>
878
+ <li>'.__('<strong>Elementor Single Builder:</strong> Edit single event page using Elementor. Manage the position of all elements in the Single page and in desktops, mobiles and tablets as well.' , 'modern-events-calendar-lite').'</li>
879
+ <li>'.__('<strong>Elementor Shortcode Builder:</strong> It enables you to create shortcodes in Elementor Live Editor.', 'modern-events-calendar-lite').'</li>
880
+ </ol>
881
+ <a href="https://webnus.net/modern-events-calendar/addons/?ref=17" target="_blank">'.esc_html('find out more', 'modern-events-calendar-lite').'</a>
882
+ </div>
883
+ </div>
884
+ </div>
885
+ </div>
886
+ </div>
887
+ </div>
888
+ ';
889
+ }
890
+
891
+ /**
892
+ * Returns MEC settings
893
+ * @author Webnus <info@webnus.biz>
894
+ * @return array
895
+ */
896
+ public function get_default_form()
897
+ {
898
+ $options = $this->get_options();
899
+ return (isset($options['default_form']) ? $options['default_form'] : array());
900
+ }
901
+
902
+ /**
903
+ * Returns registration form fields
904
+ * @author Webnus <info@webnus.biz>
905
+ * @param integer $event_id
906
+ * @return array
907
+ */
908
+ public function get_reg_fields($event_id = NULL)
909
+ {
910
+ $options = $this->get_options();
911
+ $reg_fields = isset($options['reg_fields']) ? $options['reg_fields'] : array();
912
+
913
+ // Event Booking Fields
914
+ if($event_id)
915
+ {
916
+ $global_inheritance = get_post_meta($event_id, 'mec_reg_fields_global_inheritance', true);
917
+ if(trim($global_inheritance) == '') $global_inheritance = 1;
918
+
919
+ if(!$global_inheritance)
920
+ {
921
+ $event_reg_fields = get_post_meta($event_id, 'mec_reg_fields', true);
922
+ if(is_array($event_reg_fields)) $reg_fields = $event_reg_fields;
923
+ }
924
+ }
925
+
926
+ return apply_filters( 'mec_get_reg_fields', $reg_fields, $event_id );
927
+ }
928
+
929
+ /**
930
+ * Returns Ticket Variations
931
+ * @author Webnus <info@webnus.biz>
932
+ * @param integer $event_id
933
+ * @return array
934
+ */
935
+ public function ticket_variations($event_id = NULL)
936
+ {
937
+ $settings = $this->get_settings();
938
+ $ticket_variations = (isset($settings['ticket_variations']) and is_array($settings['ticket_variations'])) ? $settings['ticket_variations'] : array();
939
+
940
+ // Event Ticket Variations
941
+ if($event_id)
942
+ {
943
+ $global_inheritance = get_post_meta($event_id, 'mec_ticket_variations_global_inheritance', true);
944
+ if(trim($global_inheritance) == '') $global_inheritance = 1;
945
+
946
+ if(!$global_inheritance)
947
+ {
948
+ $event_ticket_variations = get_post_meta($event_id, 'mec_ticket_variations', true);
949
+ if(is_array($event_ticket_variations)) $ticket_variations = $event_ticket_variations;
950
+ }
951
+ }
952
+
953
+ return $ticket_variations;
954
+ }
955
+
956
+ /**
957
+ * Returns Messages Options
958
+ * @author Webnus <info@webnus.biz>
959
+ * @return array
960
+ */
961
+ public function get_messages_options()
962
+ {
963
+ $options = $this->get_options();
964
+ return (isset($options['messages']) ? $options['messages'] : array());
965
+ }
966
+
967
+ /**
968
+ * Returns gateways options
969
+ * @author Webnus <info@webnus.biz>
970
+ * @return array
971
+ */
972
+ public function get_gateways_options()
973
+ {
974
+ $options = $this->get_options();
975
+ return (isset($options['gateways']) ? $options['gateways'] : array());
976
+ }
977
+ /**
978
+ * Returns notifications settings of MEC
979
+ * @author Webnus <info@webnus.biz>
980
+ * @return array
981
+ */
982
+ public function get_notifications()
983
+ {
984
+ $options = $this->get_options();
985
+ return (isset($options['notifications']) ? $options['notifications'] : array());
986
+ }
987
+
988
+ /**
989
+ * Returns Import/Export options of MEC
990
+ * @author Webnus <info@webnus.biz>
991
+ * @return array
992
+ */
993
+ public function get_ix_options()
994
+ {
995
+ $options = $this->get_options();
996
+ return (isset($options['ix']) ? $options['ix'] : array());
997
+ }
998
+
999
+ /**
1000
+ * Returns style settings of MEC
1001
+ * @author Webnus <info@webnus.biz>
1002
+ * @return array
1003
+ */
1004
+ public function get_styles()
1005
+ {
1006
+ $options = $this->get_options();
1007
+ return (isset($options['styles']) ? $options['styles'] : array());
1008
+ }
1009
+
1010
+ /**
1011
+ * Returns styling option of MEC
1012
+ * @author Webnus <info@webnus.biz>
1013
+ * @return array
1014
+ */
1015
+ public function get_styling()
1016
+ {
1017
+ $options = $this->get_options();
1018
+ return (isset($options['styling']) ? $options['styling'] : array());
1019
+ }
1020
+
1021
+ /**
1022
+ * Prints custom styles in the page header
1023
+ * @author Webnus <info@webnus.biz>
1024
+ * @return void
1025
+ */
1026
+ public function include_styles()
1027
+ {
1028
+ $styles = $this->get_styles();
1029
+
1030
+ // Print custom styles
1031
+ if(isset($styles['CSS']) and trim($styles['CSS']) != '')
1032
+ {
1033
+ $CSS = strip_tags($styles['CSS']);
1034
+ echo '<style type="text/css">'.stripslashes($CSS).'</style>';
1035
+ }
1036
+ }
1037
+
1038
+ /**
1039
+ * Saves MEC settings
1040
+ * @author Webnus <info@webnus.biz>
1041
+ * @return void
1042
+ */
1043
+ public function save_options()
1044
+ {
1045
+ // MEC Request library
1046
+ $request = $this->getRequest();
1047
+
1048
+ $wpnonce = $request->getVar('_wpnonce', NULL);
1049
+
1050
+ // Check if our nonce is set.
1051
+ if(!trim($wpnonce)) $this->response(array('success'=>0, 'code'=>'NONCE_MISSING'));
1052
+
1053
+ // Verify that the nonce is valid.
1054
+ if(!wp_verify_nonce($wpnonce, 'mec_options_form')) $this->response(array('success'=>0, 'code'=>'NONCE_IS_INVALID'));
1055
+
1056
+ // Get mec options
1057
+ $mec = $request->getVar('mec', array());
1058
+
1059
+ $filtered = array();
1060
+ foreach($mec as $key=>$value) $filtered[$key] = (is_array($value) ? $value : array());
1061
+
1062
+ // Get current MEC options
1063
+ $current = get_option('mec_options', array());
1064
+ if(is_string($current) and trim($current) == '') $current = array();
1065
+
1066
+ // Validations
1067
+ if(isset($filtered['settings']) and isset($filtered['settings']['slug'])) $filtered['settings']['slug'] = strtolower(str_replace(' ', '-', $filtered['settings']['slug']));
1068
+ if(isset($filtered['settings']) and isset($filtered['settings']['category_slug'])) $filtered['settings']['category_slug'] = strtolower(str_replace(' ', '-', $filtered['settings']['category_slug']));
1069
+ if(isset($filtered['settings']) and isset($filtered['settings']['custom_archive'])) $filtered['settings']['custom_archive'] = isset($filtered['settings']['custom_archive']) ? str_replace('\"','"',$filtered['settings']['custom_archive']) : '';
1070
+
1071
+ if(isset($mec['reg_fields']) and !is_array($mec['reg_fields'])) $mec['reg_fields'] = array();
1072
+ if(isset($current['reg_fields']) and isset($mec['reg_fields']) and count($current['reg_fields']) != count($mec['reg_fields']))
1073
+ {
1074
+ $current['reg_fields'] = array();
1075
+ $current['reg_fields'] = $mec['reg_fields'];
1076
+ }
1077
+
1078
+ // Generate New Options
1079
+ $final = $current;
1080
+
1081
+ // Merge new options with previous options
1082
+ foreach($filtered as $key=>$value)
1083
+ {
1084
+ if(is_array($value))
1085
+ {
1086
+ foreach($value as $k=>$v)
1087
+ {
1088
+ // Define New Array
1089
+ if(!isset($final[$key])) $final[$key] = array();
1090
+
1091
+ // Overwrite Old Value
1092
+ $final[$key][$k] = $v;
1093
+ }
1094
+ }
1095
+ // Overwrite Old Value
1096
+ else $final[$key] = $value;
1097
+ }
1098
+
1099
+ // MEC Save Options
1100
+ do_action('mec_save_options', $final);
1101
+
1102
+ // Save final options
1103
+ update_option('mec_options', $final);
1104
+
1105
+ // Refresh WordPress rewrite rules
1106
+ $this->flush_rewrite_rules();
1107
+
1108
+ // Print the response
1109
+ $this->response(array('success'=>1));
1110
+ }
1111
+
1112
+ /**
1113
+ * Saves MEC Notifications
1114
+ * @author Webnus <info@webnus.biz>
1115
+ */
1116
+ public function save_notifications()
1117
+ {
1118
+ // MEC Request library
1119
+ $request = $this->getRequest();
1120
+
1121
+ // Get mec options
1122
+ $mec = $request->getVar('mec', 'POST');
1123
+ $notifications = isset($mec['notifications']) ? $mec['notifications'] : array();
1124
+
1125
+ // Get current MEC notifications
1126
+ $current = $this->get_notifications();
1127
+ if(is_string($current) and trim($current) == '') $current = array();
1128
+
1129
+ // Merge new options with previous options
1130
+ $final_notifications = array();
1131
+ $final_notifications['notifications'] = array_merge($current, $notifications);
1132
+
1133
+ // Get current MEC options
1134
+ $options = get_option('mec_options', array());
1135
+ if(is_string($options) and trim($options) == '') $options = array();
1136
+
1137
+ // Merge new options with previous options
1138
+ $final = array_merge($options, $final_notifications);
1139
+
1140
+ // Save final options
1141
+ update_option('mec_options', $final);
1142
+
1143
+ // Print the response
1144
+ $this->response(array('success'=>1));
1145
+ }
1146
+
1147
+ /**
1148
+ * Saves MEC Import/Export options
1149
+ * @author Webnus <info@webnus.biz>
1150
+ */
1151
+ public function save_ix_options($ix_options = array())
1152
+ {
1153
+ // Get current MEC ix options
1154
+ $current = $this->get_ix_options();
1155
+ if(is_string($current) and trim($current) == '') $current = array();
1156
+
1157
+ // Merge new options with previous options
1158
+ $final_ix = array();
1159
+ $final_ix['ix'] = array_merge($current, $ix_options);
1160
+
1161
+ // Get current MEC options
1162
+ $options = get_option('mec_options', array());
1163
+ if(is_string($options) and trim($options) == '') $options = array();
1164
+
1165
+ // Merge new options with previous options
1166
+ $final = array_merge($options, $final_ix);
1167
+
1168
+ // Save final options
1169
+ update_option('mec_options', $final);
1170
+
1171
+ return true;
1172
+ }
1173
+
1174
+ /**
1175
+ * Get first day of week from WordPress
1176
+ * @author Webnus <info@webnus.biz>
1177
+ * @return int
1178
+ */
1179
+ public function get_first_day_of_week()
1180
+ {
1181
+ return get_option('start_of_week', 1);
1182
+ }
1183
+
1184
+ /**
1185
+ * @author Webnus <info@webnus.biz>
1186
+ * @param array $response
1187
+ * @return void
1188
+ */
1189
+ public function response($response)
1190
+ {
1191
+ echo json_encode($response);
1192
+ exit;
1193
+ }
1194
+
1195
+ /**
1196
+ * Check if a date passed or not
1197
+ * @author Webnus <info@webnus.biz>
1198
+ * @param mixed $end
1199
+ * @param mixed $now
1200
+ * @return int
1201
+ */
1202
+ public function is_past($end, $now)
1203
+ {
1204
+ if(!is_numeric($end)) $end = strtotime($end);
1205
+ if(!is_numeric($now)) $now = strtotime($now);
1206
+
1207
+ // Never End
1208
+ if($end <= 0) return 0;
1209
+
1210
+ return (int) ($now > $end);
1211
+ }
1212
+
1213
+ /**
1214
+ * @author Webnus <info@webnus.biz>
1215
+ * @param int $id
1216
+ * @return string
1217
+ */
1218
+ public function get_weekday_name_by_day_id($id)
1219
+ {
1220
+ // These names will be used in PHP functions so they mustn't translate
1221
+ $days = array(1=>'Monday', 2=>'Tuesday', 3=>'Wednesday', 4=>'Thursday', 5=>'Friday', 6=>'Saturday', 7=>'Sunday');
1222
+ return $days[$id];
1223
+ }
1224
+
1225
+ /**
1226
+ * Spilts 2 dates to weeks
1227
+ * @author Webnus <info@webnus.biz>
1228
+ * @param DateTime|String $start
1229
+ * @param DateTime|String $end
1230
+ * @param int $first_day_of_week
1231
+ * @return array
1232
+ */
1233
+ public function split_to_weeks($start, $end, $first_day_of_week = NULL)
1234
+ {
1235
+ if(is_null($first_day_of_week)) $first_day_of_week = $this->get_first_day_of_week();
1236
+
1237
+ $end_day_of_week = ($first_day_of_week-1 >= 0) ? $first_day_of_week-1 : 6;
1238
+
1239
+ $start_time = strtotime($start);
1240
+ $end_time = strtotime($end);
1241
+
1242
+ $start = new DateTime(date('Y-m-d', $start_time));
1243
+ $end = new DateTime(date('Y-m-d 23:59', $end_time));
1244
+
1245
+ $interval = new DateInterval('P1D');
1246
+ $dateRange = new DatePeriod($start, $interval, $end);
1247
+
1248
+ $weekday = 0;
1249
+ $weekNumber = 1;
1250
+ $weeks = array();
1251
+ foreach($dateRange as $date)
1252
+ {
1253
+ // Fix the PHP notice
1254
+ if(!isset($weeks[$weekNumber])) $weeks[$weekNumber] = array();
1255
+
1256
+ // It's first week and the week is not started from first weekday
1257
+ if($weekNumber == 1 and $weekday == 0 and $date->format('w') != $first_day_of_week)
1258
+ {
1259
+ $remained_days = $date->format('w');
1260
+
1261
+ if($first_day_of_week == 0) $remained_days = $date->format('w'); // Sunday
1262
+ elseif($first_day_of_week == 1) // Monday
1263
+ {
1264
+ if($remained_days != 0) $remained_days = $remained_days - 1;
1265
+ else $remained_days = 6;
1266
+ }
1267
+ elseif($first_day_of_week == 6) // Saturday
1268
+ {
1269
+ if($remained_days != 6) $remained_days = $remained_days + 1;
1270
+ else $remained_days = 0;
1271
+ }
1272
+ elseif($first_day_of_week == 5) // Friday
1273
+ {
1274
+ if($remained_days < 4) $remained_days = $remained_days + 2;
1275
+ elseif($remained_days == 5) $remained_days = 0;
1276
+ elseif($remained_days == 6) $remained_days = 1;
1277
+ }
1278
+
1279
+ $interval = new DateInterval('P'.$remained_days.'D');
1280
+ $interval->invert = 1;
1281
+ $date->add($interval);
1282
+
1283
+ for($i = $remained_days; $i > 0; $i--)
1284
+ {
1285
+ $weeks[$weekNumber][] = $date->format('Y-m-d');
1286
+ $date->add(new DateInterval('P1D'));
1287
+ }
1288
+ }
1289
+
1290
+ $weeks[$weekNumber][] = $date->format('Y-m-d');
1291
+ $weekday++;
1292
+
1293
+ if($date->format('w') == $end_day_of_week)
1294
+ {
1295
+ $weekNumber++;
1296
+ $weekday = 0;
1297
+ }
1298
+ }
1299
+
1300
+ // Month is finished but week is not finished
1301
+ if($weekday > 0 and $weekday < 7)
1302
+ {
1303
+ $remained_days = (6 - $weekday);
1304
+ for($i = 0; $i <= $remained_days; $i++)
1305
+ {
1306
+ $date->add(new DateInterval('P1D'));
1307
+ $weeks[$weekNumber][] = $date->format('Y-m-d');
1308
+ }
1309
+ }
1310
+
1311
+ return $weeks;
1312
+ }
1313
+
1314
+ /**
1315
+ * Returns MEC Container Width
1316
+ * @author Webnus <info@webnus.biz>
1317
+ * @return array
1318
+ */
1319
+ public function get_container_width()
1320
+ {
1321
+ $settings = $this->get_settings();
1322
+ $container_width = (isset($settings['container_width']) and trim($settings['container_width']) != '') ? $settings['container_width'] : '';
1323
+ update_option('mec_container_width', $container_width);
1324
+ }
1325
+
1326
+ /**
1327
+ * Returns MEC colors
1328
+ * @author Webnus <info@webnus.biz>
1329
+ * @return array
1330
+ */
1331
+ public function get_available_colors()
1332
+ {
1333
+ $colors = get_option('mec_colors', $this->get_default_colors());
1334
+ return apply_filters('mec_available_colors', $colors);
1335
+ }
1336
+
1337
+ /**
1338
+ * Returns MEC default colors
1339
+ * @author Webnus <info@webnus.biz>
1340
+ * @return array
1341
+ */
1342
+ public function get_default_colors()
1343
+ {
1344
+ return apply_filters('mec_default_colors', array('fdd700','00a0d2','e14d43','dd823b','a3b745'));
1345
+ }
1346
+
1347
+ /**
1348
+ * Add a new color to MEC available colors
1349
+ * @author Webnus <info@webnus.biz>
1350
+ * @param string $color
1351
+ */
1352
+ public function add_to_available_colors($color)
1353
+ {
1354
+ $colors = $this->get_available_colors();
1355
+ $colors[] = $color;
1356
+
1357
+ $colors = array_unique($colors);
1358
+ update_option('mec_colors', $colors);
1359
+ }
1360
+
1361
+ /**
1362
+ * Returns available googlemap styles
1363
+ * @author Webnus <info@webnus.biz>
1364
+ * @return array
1365
+ */
1366
+ public function get_googlemap_styles()
1367
+ {
1368
+ $styles = array(
1369
+ array('key'=>'light-dream.json', 'name'=>'Light Dream'),
1370
+ array('key'=>'intown-map.json', 'name'=>'inTown Map'),
1371
+ array('key'=>'midnight.json', 'name'=>'Midnight'),
1372
+ array('key'=>'pale-down.json', 'name'=>'Pale Down'),
1373
+ array('key'=>'blue-essence.json', 'name'=>'Blue Essence'),
1374
+ array('key'=>'blue-water.json', 'name'=>'Blue Water'),
1375
+ array('key'=>'apple-maps-esque.json', 'name'=>'Apple Maps Esque'),
1376
+ array('key'=>'CDO.json', 'name'=>'CDO'),
1377
+ array('key'=>'shades-of-grey.json', 'name'=>'Shades of Grey'),
1378
+ array('key'=>'subtle-grayscale.json', 'name'=>'Subtle Grayscale'),
1379
+ array('key'=>'ultra-light.json', 'name'=>'Ultra Light'),
1380
+ array('key'=>'facebook.json', 'name'=>'Facebook'),
1381
+ );
1382
+
1383
+ return apply_filters('mec_googlemap_styles', $styles);
1384
+ }
1385
+
1386
+ /**
1387
+ * Filters provided google map styles
1388
+ * @author Webnus <info@webnus.biz>
1389
+ * @param string $style
1390
+ * @return string
1391
+ */
1392
+ public function get_googlemap_style($style)
1393
+ {
1394
+ return apply_filters('mec_get_googlemap_style', $style);
1395
+ }
1396
+
1397
+ /**
1398
+ * Fetchs googlemap styles from file
1399
+ * @author Webnus <info@webnus.biz>
1400
+ * @param string $style
1401
+ * @return string
1402
+ */
1403
+ public function fetch_googlemap_style($style)
1404
+ {
1405
+ $path = $this->get_plugin_path().'app'.DS.'modules'.DS.'googlemap'.DS.'styles'.DS.$style;
1406
+
1407
+ // MEC file library
1408
+ $file = $this->getFile();
1409
+
1410
+ if($file->exists($path)) return trim($file->read($path));
1411
+ else return '';
1412
+ }
1413
+
1414
+ /**
1415
+ * Get marker infowindow for showing on the map
1416
+ * @author Webnus <info@webnus.biz>
1417
+ * @param array $marker
1418
+ * @return string
1419
+ */
1420
+ public function get_marker_infowindow($marker)
1421
+ {
1422
+ $count = count($marker['event_ids']);
1423
+
1424
+ $content = '
1425
+ <div class="mec-marker-infowindow-wp">
1426
+ <div class="mec-marker-infowindow-count">'.$count.'</div>
1427
+ <div class="mec-marker-infowindow-content">
1428
+ <span>'.($count > 1 ? __('Events at this location', 'modern-events-calendar-lite') : __('Event at this location', 'modern-events-calendar-lite')).'</span>
1429
+ <span>'.(trim($marker['address']) ? $marker['address'] : $marker['name']).'</span>
1430
+ </div>
1431
+ </div>';
1432
+
1433
+ return apply_filters('mec_get_marker_infowindow', $content);
1434
+ }
1435
+
1436
+ /**
1437
+ * Get marker Lightbox for showing on the map
1438
+ * @author Webnus <info@webnus.biz>
1439
+ * @param object $event
1440
+ * @param string $date_format
1441
+ * @return string
1442
+ */
1443
+ public function get_marker_lightbox($event, $date_format = 'M d Y')
1444
+ {
1445
+ // $infowindow_thumb = trim($event->data->thumbnails['thumbnail']) ? '<div class="mec-event-image">'.$event->data->thumbnails['thumbnail'].'</div>' : '';
1446
+ $infowindow_thumb = trim($event->data->featured_image['thumbnail']) ? '<div class="mec-event-image"><img src="'.$event->data->featured_image['thumbnail'].'" alt="'.$event->data->title.'" /></div>' : '';
1447
+
1448
+ $content = '
1449
+ <div class="mec-wrap">
1450
+ <div class="mec-map-lightbox-wp mec-event-list-classic">
1451
+ <article class="'.((isset($event->data->meta['event_past']) and trim($event->data->meta['event_past'])) ? 'mec-past-event ' : '').'mec-event-article mec-clear">
1452
+ '.$infowindow_thumb.'
1453
+ <a data-event-id="'.$event->data->ID.'" href="'.$this->get_event_date_permalink($event->data->permalink, $event->date['start']['date']).'"><div class="mec-event-date mec-color"><i class="mec-sl-calendar"></i> '.$this->date_label((isset($event->date['start']) ? $event->date['start'] : NULL), (isset($event->date['end']) ? $event->date['end'] : NULL), $date_format).'</div></a>
1454
+ <h4 class="mec-event-title"><a data-event-id="'.$event->data->ID.'" class="mec-color-hover" href="'.$this->get_event_date_permalink($event->data->permalink, (isset($event->date['start']) ? $event->date['start']['date'] : NULL)).'">'.$event->data->title.'</a></h4>
1455
+ </article>
1456
+ </div>
1457
+ </div>';
1458
+
1459
+ return apply_filters('mec_get_marker_lightbox', $content);
1460
+ }
1461
+
1462
+ /**
1463
+ * Returns available social networks
1464
+ * @author Webnus <info@webnus.biz>
1465
+ * @return array
1466
+ */
1467
+ public function get_social_networks()
1468
+ {
1469
+ $social_networks = array(
1470
+ 'facebook'=>array('id'=>'facebook', 'name'=>__('Facebook', 'modern-events-calendar-lite'), 'function'=>array($this, 'sn_facebook')),
1471
+ 'twitter'=>array('id'=>'twitter', 'name'=>__('Twitter', 'modern-events-calendar-lite'), 'function'=>array($this, 'sn_twitter')),
1472
+ 'linkedin'=>array('id'=>'linkedin', 'name'=>__('Linkedin', 'modern-events-calendar-lite'), 'function'=>array($this, 'sn_linkedin')),
1473
+ 'vk'=>array('id'=>'vk', 'name'=>__('VK', 'modern-events-calendar-lite'), 'function'=>array($this, 'sn_vk')),
1474
+ 'email'=>array('id'=>'email', 'name'=>__('Email', 'modern-events-calendar-lite'), 'function'=>array($this, 'sn_email')),
1475
+ );
1476
+
1477
+ return apply_filters('mec_social_networks', $social_networks);
1478
+ }
1479
+
1480
+ /**
1481
+ * Do facebook link for social networks
1482
+ * @author Webnus <info@webnus.biz>
1483
+ * @param string $url
1484
+ * @param object $event
1485
+ * @return string
1486
+ */
1487
+ public function sn_facebook($url, $event)
1488
+ {
1489
+ $occurrence = (isset($_GET['occurrence']) ? sanitize_text_field($_GET['occurrence']) : '');
1490
+ if(trim($occurrence) != '') $url = $this->add_qs_var('occurrence', $occurrence, $url);
1491
+
1492
+ return '<li class="mec-event-social-icon"><a class="facebook" href="https://www.facebook.com/sharer/sharer.php?u='.rawurlencode($url).'" onclick="javascript:window.open(this.href, \'\', \'menubar=no,toolbar=no,resizable=yes,scrollbars=yes,height=500,width=600\'); return false;" title="'.__('Share on Facebook', 'modern-events-calendar-lite').'"><i class="mec-fa-facebook"></i></a></li>';
1493
+ }
1494
+
1495
+ /**
1496
+ * Do twitter link for social networks
1497
+ * @author Webnus <info@webnus.biz>
1498
+ * @param string $url
1499
+ * @param object $event
1500
+ * @return string
1501
+ */
1502
+ public function sn_twitter($url, $event)
1503
+ {
1504
+ $occurrence = (isset($_GET['occurrence']) ? sanitize_text_field($_GET['occurrence']) : '');
1505
+ if(trim($occurrence) != '') $url = $this->add_qs_var('occurrence', $occurrence, $url);
1506
+
1507
+ return '<li class="mec-event-social-icon"><a class="twitter" href="https://twitter.com/share?url='.rawurlencode($url).'" onclick="javascript:window.open(this.href, \'\', \'menubar=no,toolbar=no,resizable=yes,scrollbars=yes,height=600,width=500\'); return false;" target="_blank" title="'.__('Tweet', 'modern-events-calendar-lite').'"><i class="mec-fa-twitter"></i></a></li>';
1508
+ }
1509
+
1510
+ /**
1511
+ * Do linkedin link for social networks
1512
+ * @author Webnus <info@webnus.biz>
1513
+ * @param string $url
1514
+ * @param object $event
1515
+ * @return string
1516
+ */
1517
+ public function sn_linkedin($url, $event)
1518
+ {
1519
+ $occurrence = (isset($_GET['occurrence']) ? sanitize_text_field($_GET['occurrence']) : '');
1520
+ if(trim($occurrence) != '') $url = $this->add_qs_var('occurrence', $occurrence, $url);
1521
+
1522
+ return '<li class="mec-event-social-icon"><a class="linkedin" href="https://www.linkedin.com/shareArticle?mini=true&url='.rawurlencode($url).'" onclick="javascript:window.open(this.href, \'\', \'menubar=no,toolbar=no,resizable=yes,scrollbars=yes,height=600,width=500\'); return false;" target="_blank" title="'.__('Linkedin', 'modern-events-calendar-lite').'"><i class="mec-fa-linkedin"></i></a></li>';
1523
+ }
1524
+
1525
+ /**
1526
+ * Do email link for social networks
1527
+ * @author Webnus <info@webnus.biz>
1528
+ * @param string $url
1529
+ * @param object $event
1530
+ * @return string
1531
+ */
1532
+ public function sn_email($url, $event)
1533
+ {
1534
+ $occurrence = (isset($_GET['occurrence']) ? sanitize_text_field($_GET['occurrence']) : '');
1535
+ if(trim($occurrence) != '') $url = $this->add_qs_var('occurrence', $occurrence, $url);
1536
+
1537
+ $event->data->title = str_replace('&#8211;', '-', $event->data->title);
1538
+ $event->data->title = str_replace('&#8221;', '’’', $event->data->title);
1539
+ $event->data->title = str_replace('&#8217;', "’", $event->data->title);
1540
+ $event->data->title = str_replace('&', '%26', $event->data->title);
1541
+ $event->data->title = str_replace('#038;', '', $event->data->title);
1542
+
1543
+ return '<li class="mec-event-social-icon"><a class="email" href="mailto:?subject='.wp_specialchars_decode($event->data->title).'&body='.rawurlencode($url).'" title="'.__('Email', 'modern-events-calendar-lite').'"><i class="mec-fa-envelope"></i></a></li>';
1544
+ }
1545
+
1546
+ /**
1547
+ * Do VK link for social networks
1548
+ * @author Webnus <info@webnus.biz>
1549
+ * @param string $url
1550
+ * @param object $event
1551
+ * @return string
1552
+ */
1553
+ public function sn_vk($url, $event)
1554
+ {
1555
+ $occurrence = (isset($_GET['occurrence']) ? sanitize_text_field($_GET['occurrence']) : '');
1556
+ if(trim($occurrence) != '') $url = $this->add_qs_var('occurrence', $occurrence, $url);
1557
+
1558
+ return '<li class="mec-event-social-icon"><a class="vk" href=" http://vk.com/share.php?url='.rawurlencode($url).'" title="'.__('VK', 'modern-events-calendar-lite').'" target="_blank"><i class="mec-fa-vk"></i></a></li>';
1559
+ }
1560
+
1561
+ /**
1562
+ * Get available skins for archive page
1563
+ * @author Webnus <info@webnus.biz>
1564
+ * @return array
1565
+ */
1566
+ public function get_archive_skins()
1567
+ {
1568
+ $archive_skins = array(
1569
+ array('skin'=>'full_calendar', 'name'=>__('Full Calendar', 'modern-events-calendar-lite')),
1570
+ array('skin'=>'yearly_view', 'name'=>__('Yearly View', 'modern-events-calendar-lite')),
1571
+ array('skin'=>'monthly_view', 'name'=>__('Calendar/Monthly View', 'modern-events-calendar-lite')),
1572
+ array('skin'=>'weekly_view', 'name'=>__('Weekly View', 'modern-events-calendar-lite')),
1573
+ array('skin'=>'daily_view', 'name'=>__('Daily View', 'modern-events-calendar-lite')),
1574
+ array('skin'=>'timetable', 'name'=>__('Timetable View', 'modern-events-calendar-lite')),
1575
+ array('skin'=>'masonry', 'name'=>__('Masonry View', 'modern-events-calendar-lite')),
1576
+ array('skin'=>'list', 'name'=>__('List View', 'modern-events-calendar-lite')),
1577
+ array('skin'=>'grid', 'name'=>__('Grid View', 'modern-events-calendar-lite')),
1578
+ array('skin'=>'agenda', 'name'=>__('Agenda View', 'modern-events-calendar-lite')),
1579
+ array('skin'=>'map', 'name'=>__('Map View', 'modern-events-calendar-lite')),
1580
+ array('skin'=>'custom', 'name'=>__('Custom Shortcode', 'modern-events-calendar-lite')),
1581
+ );
1582
+
1583
+ return apply_filters('mec_archive_skins', $archive_skins);
1584
+ }
1585
+
1586
+ /**
1587
+ * Get available skins for archive page
1588
+ * @author Webnus <info@webnus.biz>
1589
+ * @return array
1590
+ */
1591
+ public function get_category_skins()
1592
+ {
1593
+ $category_skins = array(
1594
+ array('skin'=>'full_calendar', 'name'=>__('Full Calendar', 'modern-events-calendar-lite')),
1595
+ array('skin'=>'yearly_view', 'name'=>__('Yearly View', 'modern-events-calendar-lite')),
1596
+ array('skin'=>'monthly_view', 'name'=>__('Calendar/Monthly View', 'modern-events-calendar-lite')),
1597
+ array('skin'=>'weekly_view', 'name'=>__('Weekly View', 'modern-events-calendar-lite')),
1598
+ array('skin'=>'daily_view', 'name'=>__('Daily View', 'modern-events-calendar-lite')),
1599
+ array('skin'=>'timetable', 'name'=>__('Timetable View', 'modern-events-calendar-lite')),
1600
+ array('skin'=>'masonry', 'name'=>__('Masonry View', 'modern-events-calendar-lite')),
1601
+ array('skin'=>'list', 'name'=>__('List View', 'modern-events-calendar-lite')),
1602
+ array('skin'=>'grid', 'name'=>__('Grid View', 'modern-events-calendar-lite')),
1603
+ array('skin'=>'agenda', 'name'=>__('Agenda View', 'modern-events-calendar-lite')),
1604
+ array('skin'=>'map', 'name'=>__('Map View', 'modern-events-calendar-lite')),
1605
+ );
1606
+
1607
+ return apply_filters('mec_category_skins', $category_skins);
1608
+ }
1609
+
1610
+ /**
1611
+ * Get events posts
1612
+ * @author Webnus <info@webnus.biz>
1613
+ * @param int $limit
1614
+ * @return array list of posts
1615
+ */
1616
+ public function get_events($limit = -1)
1617
+ {
1618
+ return get_posts(array('post_type'=>$this->get_main_post_type(), 'posts_per_page'=>$limit, 'post_status'=>'publish'));
1619
+ }
1620
+
1621
+ /**
1622
+ * Get method of showing for multiple days events
1623
+ * @author Webnus <info@webnus.biz>
1624
+ * @return string
1625
+ */
1626
+ public function get_multiple_days_method()
1627
+ {
1628
+ $settings = $this->get_settings();
1629
+
1630
+ $method = isset($settings['multiple_day_show_method']) ? $settings['multiple_day_show_method'] : 'first_day_listgrid';
1631
+ return apply_filters('mec_multiple_days_method', $method);
1632
+ }
1633
+
1634
+ /**
1635
+ * Get method of showing/hiding events based on event time
1636
+ * @author Webnus <info@webnus.biz>
1637
+ * @return string
1638
+ */
1639
+ public function get_hide_time_method()
1640
+ {
1641
+ $settings = $this->get_settings();
1642
+
1643
+ $method = isset($settings['hide_time_method']) ? $settings['hide_time_method'] : 'start';
1644
+ return apply_filters('mec_hide_time_method', $method);
1645
+ }
1646
+
1647
+ /**
1648
+ * Get hour format of MEC
1649
+ * @author Webnus <info@webnus.biz>
1650
+ * @return int|string
1651
+ */
1652
+ public function get_hour_format()
1653
+ {
1654
+ $settings = $this->get_settings();
1655
+
1656
+ $format = isset($settings['time_format']) ? $settings['time_format'] : 12;
1657
+ return apply_filters('mec_hour_format', $format);
1658
+ }
1659
+
1660
+ /**
1661
+ * Get formatted hour based on configurations
1662
+ * @author Webnus <info@webnus.biz>
1663
+ * @param int $hour
1664
+ * @param int $minutes
1665
+ * @param string $ampm
1666
+ * @return string
1667
+ */
1668
+ public function get_formatted_hour($hour, $minutes, $ampm)
1669
+ {
1670
+ // Hour Format of MEC (12/24)
1671
+ $hour_format = $this->get_hour_format();
1672
+
1673
+ $formatted = '';
1674
+ if($hour_format == '12')
1675
+ {
1676
+ $formatted = sprintf("%02d", $hour).':'.sprintf("%02d", $minutes).' '.__($ampm, 'modern-events-calendar-lite');
1677
+ }
1678
+ elseif($hour_format == '24')
1679
+ {
1680
+ if(strtoupper($ampm) == 'PM' and $hour != 12) $hour += 12;
1681
+ if(strtoupper($ampm) == 'AM' and $hour == 12) $hour += 12;
1682
+
1683
+ $formatted = sprintf("%02d", $hour).':'.sprintf("%02d", $minutes);
1684
+ }
1685
+
1686
+ return $formatted;
1687
+ }
1688
+
1689
+ /**
1690
+ * Get formatted time based on WordPress Time Format
1691
+ * @author Webnus <info@webnus.biz>
1692
+ * @param int $seconds
1693
+ * @return string
1694
+ */
1695
+ public function get_time($seconds)
1696
+ {
1697
+ $format = get_option('time_format');
1698
+ return gmdate($format, $seconds);
1699
+ }
1700
+
1701
+ /**
1702
+ * Renders a module such as links or googlemap
1703
+ * @author Webnus <info@webnus.biz>
1704
+ * @param string $module
1705
+ * @param array $params
1706
+ * @return string
1707
+ */
1708
+ public function module($module, $params = array())
1709
+ {
1710
+ // Get module path
1711
+ $path = MEC::import('app.modules.'.$module, true, true);
1712
+
1713
+ // MEC libraries
1714
+ $render = $this->getRender();
1715
+ $factory = $this->getFactory();
1716
+
1717
+ // Extract Module Params
1718
+ extract($params);
1719
+
1720
+ ob_start();
1721
+ include $path;
1722
+ return $output = ob_get_clean();
1723
+ }
1724
+
1725
+ /**
1726
+ * Returns MEC currencies
1727
+ * @author Webnus <info@webnus.biz>
1728
+ * @return array
1729
+ */
1730
+ public function get_currencies()
1731
+ {
1732
+ $currencies = array(
1733
+ '$'=>'USD',
1734
+ '€'=>'EUR',
1735
+ '£'=>'GBP',
1736
+ 'CHF'=>'CHF',
1737
+ 'CAD'=>'CAD',
1738
+ 'AUD'=>'AUD',
1739
+ 'JPY'=>'JPY',
1740
+ 'SEK'=>'SEK',
1741
+ 'GEL'=>'GEL',
1742
+ 'AFN'=>'AFN',
1743
+ 'ALL'=>'ALL',
1744
+ 'DZD'=>'DZD',
1745
+ 'AOA'=>'AOA',
1746
+ 'ARS'=>'ARS',
1747
+ 'AMD'=>'AMD',
1748
+ 'AWG'=>'AWG',
1749
+ 'AZN'=>'AZN',
1750
+ 'BSD'=>'BSD',
1751
+ 'BHD'=>'BHD',
1752
+ 'BBD'=>'BBD',
1753
+ 'BYR'=>'BYR',
1754
+ 'BZD'=>'BZD',
1755
+ 'BMD'=>'BMD',
1756
+ 'BTN'=>'BTN',
1757
+ 'BOB'=>'BOB',
1758
+ 'BAM'=>'BAM',
1759
+ 'BWP'=>'BWP',
1760
+ 'BRL'=>'BRL',
1761
+ 'BND'=>'BND',
1762
+ 'BGN'=>'BGN',
1763
+ 'BIF'=>'BIF',
1764
+ 'KHR'=>'KHR',
1765
+ 'CVE'=>'CVE',
1766
+ 'KYD'=>'KYD',
1767
+ 'XAF'=>'XAF',
1768
+ 'CLP'=>'CLP',
1769
+ 'COP'=>'COP',
1770
+ 'KMF'=>'KMF',
1771
+ 'CDF'=>'CDF',
1772
+ 'NZD'=>'NZD',
1773
+ 'CRC'=>'CRC',
1774
+ 'HRK'=>'HRK',
1775
+ 'CUC'=>'CUC',
1776
+ 'CUP'=>'CUP',
1777
+ 'CZK'=>'CZK',
1778
+ 'DKK'=>'DKK',
1779
+ 'DJF'=>'DJF',
1780
+ 'DOP'=>'DOP',
1781
+ 'XCD'=>'XCD',
1782
+ 'EGP'=>'EGP',
1783
+ 'ERN'=>'ERN',
1784
+ 'EEK'=>'EEK',
1785
+ 'ETB'=>'ETB',
1786
+ 'FKP'=>'FKP',
1787
+ 'FJD'=>'FJD',
1788
+ 'GMD'=>'GMD',
1789
+ 'GHS'=>'GHS',
1790
+ 'GIP'=>'GIP',
1791
+ 'GTQ'=>'GTQ',
1792
+ 'GNF'=>'GNF',
1793
+ 'GYD'=>'GYD',
1794
+ 'HTG'=>'HTG',
1795
+ 'HNL'=>'HNL',
1796
+ 'HKD'=>'HKD',
1797
+ 'HUF'=>'HUF',
1798
+ 'ISK'=>'ISK',
1799
+ 'INR'=>'INR',
1800
+ 'IDR'=>'IDR',
1801
+ 'IRR'=>'IRR',
1802
+ 'IQD'=>'IQD',
1803
+ 'ILS'=>'ILS',
1804
+ 'JMD'=>'JMD',
1805
+ 'JOD'=>'JOD',
1806
+ 'KZT'=>'KZT',
1807
+ 'KES'=>'KES',
1808
+ 'KWD'=>'KWD',
1809
+ 'KGS'=>'KGS',
1810
+ 'LAK'=>'LAK',
1811
+ 'LVL'=>'LVL',
1812
+ 'LBP'=>'LBP',
1813
+ 'LSL'=>'LSL',
1814
+ 'LRD'=>'LRD',
1815
+ 'LYD'=>'LYD',
1816
+ 'LTL'=>'LTL',
1817
+ 'MOP'=>'MOP',
1818
+ 'MKD'=>'MKD',
1819
+ 'MGA'=>'MGA',
1820
+ 'MWK'=>'MWK',
1821
+ 'MYR'=>'MYR',
1822
+ 'MVR'=>'MVR',
1823
+ 'MRO'=>'MRO',
1824
+ 'MUR'=>'MUR',
1825
+ 'MXN'=>'MXN',
1826
+ 'MDL'=>'MDL',
1827
+ 'MNT'=>'MNT',
1828
+ 'MAD'=>'MAD',
1829
+ 'MZN'=>'MZN',
1830
+ 'MMK'=>'MMK',
1831
+ 'NAD'=>'NAD',
1832
+ 'NPR'=>'NPR',
1833
+ 'ANG'=>'ANG',
1834
+ 'TWD'=>'TWD',
1835
+ 'NIO'=>'NIO',
1836
+ 'NGN'=>'NGN',
1837
+ 'KPW'=>'KPW',
1838
+ 'NOK'=>'NOK',
1839
+ 'OMR'=>'OMR',
1840
+ 'PKR'=>'PKR',
1841
+ 'PAB'=>'PAB',
1842
+ 'PGK'=>'PGK',
1843
+ 'PYG'=>'PYG',
1844
+ 'PEN'=>'PEN',
1845
+ 'PHP'=>'PHP',
1846
+ 'PLN'=>'PLN',
1847
+ 'QAR'=>'QAR',
1848
+ 'CNY'=>'CNY',
1849
+ 'RON'=>'RON',
1850
+ 'RUB'=>'RUB',
1851
+ 'RWF'=>'RWF',
1852
+ 'SHP'=>'SHP',
1853
+ 'SVC'=>'SVC',
1854
+ 'WST'=>'WST',
1855
+ 'SAR'=>'SAR',
1856
+ 'RSD'=>'RSD',
1857
+ 'SCR'=>'SCR',
1858
+ 'SLL'=>'SLL',
1859
+ 'SGD'=>'SGD',
1860
+ 'SBD'=>'SBD',
1861
+ 'SOS'=>'SOS',
1862
+ 'ZAR'=>'ZAR',
1863
+ 'KRW'=>'KRW',
1864
+ 'LKR'=>'LKR',
1865
+ 'SDG'=>'SDG',
1866
+ 'SRD'=>'SRD',
1867
+ 'SZL'=>'SZL',
1868
+ 'SYP'=>'SYP',
1869
+ 'STD'=>'STD',
1870
+ 'TJS'=>'TJS',
1871
+ 'TZS'=>'TZS',
1872
+ 'THB'=>'THB',
1873
+ 'TOP'=>'TOP',
1874
+ 'PRB'=>'PRB',
1875
+ 'TTD'=>'TTD',
1876
+ 'TND'=>'TND',
1877
+ 'TRY'=>'TRY',
1878
+ 'TMT'=>'TMT',
1879
+ 'TVD'=>'TVD',
1880
+ 'UGX'=>'UGX',
1881
+ 'UAH'=>'UAH',
1882
+ 'AED'=>'AED',
1883
+ 'UYU'=>'UYU',
1884
+ 'UZS'=>'UZS',
1885
+ 'VUV'=>'VUV',
1886
+ 'VEF'=>'VEF',
1887
+ 'VND'=>'VND',
1888
+ 'XOF'=>'XOF',
1889
+ 'YER'=>'YER',
1890
+ 'ZMK'=>'ZMK',
1891
+ 'ZWL'=>'ZWL',
1892
+ );
1893
+
1894
+ return apply_filters('mec_currencies', $currencies);
1895
+ }
1896
+
1897
+ /**
1898
+ * Returns MEC version
1899
+ * @author Webnus <info@webnus.biz>
1900
+ * @return string
1901
+ */
1902
+ public function get_version()
1903
+ {
1904
+ return MEC_VERSION;
1905
+ }
1906
+
1907
+ /**
1908
+ * Set endpoint vars to true
1909
+ * @author Webnus <info@webnus.biz>
1910
+ * @param array $vars
1911
+ * @return boolean
1912
+ */
1913
+ public function filter_request($vars)
1914
+ {
1915
+ if(isset($vars['gateway-cancel'])) $vars['gateway-cancel'] = true;
1916
+ if(isset($vars['gateway-return'])) $vars['gateway-return'] = true;
1917
+ if(isset($vars['gateway-notify'])) $vars['gateway-notify'] = true;
1918
+
1919
+ return $vars;
1920
+ }
1921
+
1922
+ /**
1923
+ * Do the jobs after endpoints and show related output
1924
+ * @author Webnus <info@webnus.biz>
1925
+ * @return boolean
1926
+ */
1927
+ public function do_endpoints()
1928
+ {
1929
+ if(get_query_var('verify'))
1930
+ {
1931
+ $key = sanitize_text_field(get_query_var('verify'));
1932
+
1933
+ $db = $this->getDB();
1934
+ $book_id = $db->select("SELECT `post_id` FROM `#__postmeta` WHERE `meta_key`='mec_verification_key' AND `meta_value`='$key'", 'loadResult');
1935
+
1936
+ if(!$book_id) return false;
1937
+
1938
+ $status = get_post_meta($book_id, 'mec_verified', true);
1939
+ if($status == '1')
1940
+ {
1941
+ echo '<p class="mec-success">'.__('Your booking already verified!', 'modern-events-calendar-lite').'</p>';
1942
+ return false;
1943
+ }
1944
+
1945
+ $book = $this->getBook();
1946
+ if($book->verify($book_id)) echo '<p class="mec-success">'.__('Your booking successfully verified.', 'modern-events-calendar-lite').'</p>';
1947
+ else echo '<p class="mec-error">'.__('Your booking cannot verify!', 'modern-events-calendar-lite').'</p>';
1948
+ }
1949
+ elseif(get_query_var('cancel'))
1950
+ {
1951
+ $key = sanitize_text_field(get_query_var('cancel'));
1952
+
1953
+ $db = $this->getDB();
1954
+ $book_id = $db->select("SELECT `post_id` FROM `#__postmeta` WHERE `meta_key`='mec_cancellation_key' AND `meta_value`='$key'", 'loadResult');
1955
+
1956
+ if(!$book_id) return false;
1957
+
1958
+ $status = get_post_meta($book_id, 'mec_verified', true);
1959
+ if($status == '-1')
1960
+ {
1961
+ echo '<p class="mec-error">'.__('Your booking already canceled!', 'modern-events-calendar-lite').'</p>';
1962
+ return false;
1963
+ }
1964
+
1965
+ $book = $this->getBook();
1966
+ if($book->cancel($book_id)) echo '<p class="mec-success">'.__('Your booking successfully canceled.', 'modern-events-calendar-lite').'</p>';
1967
+ else echo '<p class="mec-error">'.__('Your booking cannot be canceled.', 'modern-events-calendar-lite').'</p>';
1968
+ }
1969
+ elseif(get_query_var('gateway-cancel'))
1970
+ {
1971
+ echo '<p class="mec-success">'.__('You canceled the payment successfully.', 'modern-events-calendar-lite').'</p>';
1972
+ }
1973
+ elseif(get_query_var('gateway-return'))
1974
+ {
1975
+ echo '<p class="mec-success">'.__('You returned from payment gateway successfully.', 'modern-events-calendar-lite').'</p>';
1976
+ }
1977
+ elseif(get_query_var('gateway-notify'))
1978
+ {
1979
+ // TODO
1980
+ }
1981
+ }
1982
+
1983
+ public function booking_invoice()
1984
+ {
1985
+ // Booking Invoice
1986
+ if(isset($_GET['method']) and sanitize_text_field($_GET['method']) == 'mec-invoice')
1987
+ {
1988
+ $settings = $this->get_settings();
1989
+ if(isset($settings['booking_invoice']) and !$settings['booking_invoice'])
1990
+ {
1991
+ wp_die(__('Cannot find the invoice!', 'modern-events-calendar-lite'), __('Invoice is invalid.', 'modern-events-calendar-lite'));
1992
+ exit;
1993
+ }
1994
+
1995
+ $transaction_id = sanitize_text_field($_GET['id']);
1996
+
1997
+ // Libraries
1998
+ $book = $this->getBook();
1999
+ $render = $this->getRender();
2000
+ $db = $this->getDB();
2001
+
2002
+ $transaction = $book->get_transaction($transaction_id);
2003
+ $event_id = isset($transaction['event_id']) ? $transaction['event_id'] : 0;
2004
+
2005
+ // Dont Show PDF If Booking Confirmation Status Equals Pending
2006
+ $book_id = $db->select("SELECT `post_id` FROM `#__postmeta` WHERE `meta_value`='".$transaction_id."' AND `meta_key`='mec_transaction_id'", 'loadResult');
2007
+ $mec_confirmed = get_post_meta($book_id, 'mec_confirmed', true);
2008
+
2009
+ if(!$mec_confirmed and (!current_user_can('administrator') and !current_user_can('editor')))
2010
+ {
2011
+ wp_die(__('Your booking still is not confirmed. You able download it after confirmation!', 'modern-events-calendar-lite'), __('Booking Not Confirmed.', 'modern-events-calendar-lite'));
2012
+ exit;
2013
+ }
2014
+
2015
+ if(!$event_id)
2016
+ {
2017
+ wp_die(__('Cannot find the booking!', 'modern-events-calendar-lite'), __('Booking is invalid.', 'modern-events-calendar-lite'));
2018
+ exit;
2019
+ }
2020
+
2021
+ $event = $render->data($event_id);
2022
+
2023
+ $location_id = isset($event->meta['mec_location_id']) ? $event->meta['mec_location_id'] : 0;
2024
+ $location = isset($event->locations[$location_id]) ? (trim($event->locations[$location_id]['address']) ? $event->locations[$location_id]['address'] : $event->locations[$location_id]['name']) : '';
2025
+
2026
+ $dates = isset($transaction['date']) ? explode(':', $transaction['date']) : array(date('Y-m-d'), date('Y-m-d'));
2027
+
2028
+ // Get Booking Post
2029
+ $booking = $book->get_bookings_by_transaction_id($transaction_id);
2030
+
2031
+ $booking_time = isset($booking[0]) ? get_post_meta($booking[0]->ID, 'mec_booking_time', true) : NULL;
2032
+ if(!$booking_time) $booking_time = $dates[0];
2033
+
2034
+ $booking_time = date('Y-m-d', strtotime($booking_time));
2035
+
2036
+ // Include the tFPDF Class
2037
+ if(!class_exists('tFPDF')) require_once MEC_ABSPATH.'app'.DS.'api'.DS.'TFPDF'.DS.'tfpdf.php';
2038
+
2039
+ $pdf = new tFPDF();
2040
+ $pdf->AddPage();
2041
+
2042
+ // Add a Unicode font (uses UTF-8)
2043
+ $pdf->AddFont('DejaVu', '', 'DejaVuSansCondensed.ttf', true);
2044
+ $pdf->AddFont('DejaVuBold', '', 'DejaVuSansCondensed-Bold.ttf', true);
2045
+
2046
+ $pdf->SetTitle(sprintf(__('%s Invoice', 'modern-events-calendar-lite'), $transaction_id));
2047
+ $pdf->SetAuthor(get_bloginfo('name'), true);
2048
+
2049
+ // Event Information
2050
+ $pdf->SetFont('DejaVuBold', '', 18);
2051
+ $pdf->Write(25, html_entity_decode(get_the_title($event->ID)));
2052
+ $pdf->Ln();
2053
+
2054
+ $pdf->SetFont('DejaVuBold', '', 12);
2055
+ $pdf->Write(6, __('Location', 'modern-events-calendar-lite').': ');
2056
+ $pdf->SetFont('DejaVu', '', 12);
2057
+ $pdf->Write(6, $location);
2058
+ $pdf->Ln();
2059
+
2060
+ $pdf->SetFont('DejaVuBold', '', 12);
2061
+ $pdf->Write(6, __('Date', 'modern-events-calendar-lite').': ');
2062
+ $pdf->SetFont('DejaVu', '', 12);
2063
+ $pdf->Write(6, trim($dates[0].' '.(isset($event->time['start']) ? $event->time['start'] : '').' - '.(($dates[0] != $dates[1]) ? $dates[1].' ' : '').(isset($event->time['end']) ? $event->time['end'] : ''), '- '));
2064
+ $pdf->Ln();
2065
+
2066
+ $pdf->SetFont('DejaVuBold', '', 12);
2067
+ $pdf->Write(6, __('Transaction ID', 'modern-events-calendar-lite').': ');
2068
+ $pdf->SetFont('DejaVu', '', 12);
2069
+ $pdf->Write(6, $transaction_id);
2070
+ $pdf->Ln();
2071
+
2072
+ // Attendees
2073
+ if(isset($transaction['tickets']) and is_array($transaction['tickets']) and count($transaction['tickets']))
2074
+ {
2075
+ $pdf->SetFont('DejaVuBold', '', 16);
2076
+ $pdf->Write(20, __('Attendees', 'modern-events-calendar-lite'));
2077
+ $pdf->Ln();
2078
+
2079
+ $i = 1;
2080
+ foreach($transaction['tickets'] as $attendee)
2081
+ {
2082
+ $pdf->SetFont('DejaVuBold', '', 12);
2083
+ $pdf->Write(6, $attendee['name']);
2084
+ $pdf->Ln();
2085
+
2086
+ $pdf->SetFont('DejaVu', '', 10);
2087
+ $pdf->Write(6, $attendee['email']);
2088
+ $pdf->Ln();
2089
+
2090
+ $pdf->Write(6, ((isset($event->tickets[$attendee['id']]) ? __($this->m('ticket', __('Ticket', 'modern-events-calendar-lite'))).': '.$event->tickets[$attendee['id']]['name'] : '').' '.(isset($event->tickets[$attendee['id']]) ? $book->get_ticket_price_label($event->tickets[$attendee['id']], $booking_time) : '')));
2091
+
2092
+ // Ticket Variations
2093
+ if(isset($attendee['variations']) and is_array($attendee['variations']) and count($attendee['variations']))
2094
+ {
2095
+ $ticket_variations = $this->ticket_variations($event_id);
2096
+
2097
+ foreach($attendee['variations'] as $variation_id=>$variation_count)
2098
+ {
2099
+ if(!$variation_count or ($variation_count and $variation_count < 0)) continue;
2100
+
2101
+ $variation_title = (isset($ticket_variations[$variation_id]) and isset($ticket_variations[$variation_id]['title'])) ? $ticket_variations[$variation_id]['title'] : '';
2102
+ if(!trim($variation_title)) continue;
2103
+
2104
+ $pdf->Ln();
2105
+ $pdf->Write(6, '+ '.$variation_title.' ('.$variation_count.')');
2106
+ }
2107
+ }
2108
+
2109
+ if($i != count($transaction['tickets'])) $pdf->Ln(12);
2110
+ else $pdf->Ln();
2111
+
2112
+ $i++;
2113
+ }
2114
+ }
2115
+
2116
+ // Billing Information
2117
+ if(isset($transaction['price_details']) and isset($transaction['price_details']['details']) and is_array($transaction['price_details']['details']) and count($transaction['price_details']['details']))
2118
+ {
2119
+ $pdf->SetFont('DejaVuBold', '', 16);
2120
+ $pdf->Write(20, __('Billing', 'modern-events-calendar-lite'));
2121
+ $pdf->Ln();
2122
+
2123
+ $pdf->SetFont('DejaVu', '', 12);
2124
+ foreach($transaction['price_details']['details'] as $price_row)
2125
+ {
2126
+ $pdf->Write(6, $price_row['description'].": ".$this->render_price($price_row['amount']));
2127
+ $pdf->Ln();
2128
+ }
2129
+
2130
+ $pdf->SetFont('DejaVuBold', '', 12);
2131
+ $pdf->Write(10, __('Total', 'modern-events-calendar-lite').': ');
2132
+ $pdf->Write(10, $this->render_price($transaction['price']));
2133
+ $pdf->Ln();
2134
+ }
2135
+
2136
+ $image = $this->module('qrcode.invoice', array('event'=>$event));
2137
+ if(trim($image))
2138
+ {
2139
+ // QR Code
2140
+ $pdf->SetX(-50);
2141
+ $pdf->Image($image);
2142
+ $pdf->Ln();
2143
+ }
2144
+
2145
+ $pdf->Output();
2146
+ exit;
2147
+ }
2148
+ }
2149
+
2150
+ /**
2151
+ * Generates ical output
2152
+ * @author Webnus <info@webnus.biz>
2153
+ */
2154
+ public function ical()
2155
+ {
2156
+ // ical export
2157
+ if(isset($_GET['method']) and sanitize_text_field($_GET['method']) == 'ical')
2158
+ {
2159
+ $id = sanitize_text_field($_GET['id']);
2160
+ $occurrence = isset($_GET['occurrence']) ? sanitize_text_field($_GET['occurrence']) : '';
2161
+
2162
+ $events = $this->ical_single($id, $occurrence);
2163
+ $ical_calendar = $this->ical_calendar($events);
2164
+
2165
+ header('Content-type: application/force-download; charset=utf-8');
2166
+ header('Content-Disposition: attachment; filename="mec-event-'.$id.'.ics"');
2167
+
2168
+ echo $ical_calendar;
2169
+ exit;
2170
+ }
2171
+ }
2172
+
2173
+ /**
2174
+ * Generates ical output in email
2175
+ * @author Webnus <info@webnus.biz>
2176
+ */
2177
+ public function ical_email()
2178
+ {
2179
+ // ical export
2180
+ if(isset($_GET['method']) and sanitize_text_field($_GET['method']) == 'ical-email')
2181
+ {
2182
+ $id = sanitize_text_field($_GET['id']);
2183
+ $book_id = sanitize_text_field($_GET['book_id']);
2184
+ $key = sanitize_text_field($_GET['key']);
2185
+
2186
+ if($key != md5($book_id))
2187
+ {
2188
+ wp_die(__('Request is not valid.', 'modern-events-calendar-lite'), __('iCal export stopped!', 'modern-events-calendar-lite'), array('back_link'=>true));
2189
+ exit;
2190
+ }
2191
+
2192
+ $occurrence = isset($_GET['occurrence']) ? sanitize_text_field($_GET['occurrence']) : '';
2193
+
2194
+ $events = $this->ical_single_email($id, $book_id, $occurrence);
2195
+ $ical_calendar = $this->ical_calendar($events);
2196
+
2197
+ header('Content-type: application/force-download; charset=utf-8');
2198
+ header('Content-Disposition: attachment; filename="mec-booking-'.$book_id.'.ics"');
2199
+
2200
+ echo $ical_calendar;
2201
+ exit;
2202
+ }
2203
+ }
2204
+
2205
+ /**
2206
+ * Returns the iCal URL of event
2207
+ * @author Webnus <info@webnus.biz>
2208
+ * @param $event_id
2209
+ * @param string $occurrence
2210
+ * @return string
2211
+ */
2212
+ public function ical_URL($event_id, $occurrence = '')
2213
+ {
2214
+ $url = $this->URL('site');
2215
+ $url = $this->add_qs_var('method', 'ical', $url);
2216
+ $url = $this->add_qs_var('id', $event_id, $url);
2217
+
2218
+ // Add Occurrence Date if passed
2219
+ if(trim($occurrence)) $url = $this->add_qs_var('occurrence', $occurrence, $url);
2220
+
2221
+ return $url;
2222
+ }
2223
+
2224
+ public function ical_URL_email($event_id, $book_id , $occurrence = '')
2225
+ {
2226
+ $url = $this->URL('site');
2227
+ $url = $this->add_qs_var('method', 'ical-email', $url);
2228
+ $url = $this->add_qs_var('id', $event_id, $url);
2229
+ $url = $this->add_qs_var('book_id', $book_id, $url);
2230
+ $url = $this->add_qs_var('key', md5($book_id), $url);
2231
+
2232
+ // Add Occurrence Date if passed
2233
+ if(trim($occurrence)) $url = $this->add_qs_var('occurrence', $occurrence, $url);
2234
+
2235
+ return $url;
2236
+ }
2237
+
2238
+ /**
2239
+ * Returns iCal export for one event
2240
+ * @author Webnus <info@webnus.biz>
2241
+ * @param int $event_id
2242
+ * @param string $occurrence
2243
+ * @return string
2244
+ */
2245
+ public function ical_single($event_id, $occurrence = '')
2246
+ {
2247
+ // MEC Render Library
2248
+ $render = $this->getRender();
2249
+
2250
+ $event = $render->data($event_id);
2251
+ $dates = $render->dates($event_id, $event, 2, $occurrence);
2252
+
2253
+ $location = isset($event->locations[$event->meta['mec_location_id']]) ? $event->locations[$event->meta['mec_location_id']]['address'] : '';
2254
+
2255
+ $occurrence_end_date = trim($occurrence) ? $this->get_end_date_by_occurrence($event_id, (isset($dates[0]['start']['date']) ? $dates[0]['start']['date'] : $occurrence)) : '';
2256
+ $start_time = strtotime((trim($occurrence) ? $occurrence : $dates[0]['start']['date']).' '.sprintf("%02d", $dates[0]['start']['hour']).':'.sprintf("%02d", $dates[0]['start']['minutes']).' '.$dates[0]['start']['ampm']);
2257
+ $end_time = strtotime((trim($occurrence_end_date) ? $occurrence_end_date : $dates[0]['end']['date']).' '.sprintf("%02d", $dates[0]['end']['hour']).':'.sprintf("%02d", $dates[0]['end']['minutes']).' '.$dates[0]['end']['ampm']);
2258
+
2259
+ $gmt_offset_seconds = $this->get_gmt_offset_seconds($start_time);
2260
+ $stamp = strtotime($event->post->post_date);
2261
+ $modified = strtotime($event->post->post_modified);
2262
+
2263
+ $rrules = $this->get_ical_rrules($event);
2264
+
2265
+ $ical = "BEGIN:VEVENT".PHP_EOL;
2266
+ $ical .= "UID:MEC-".md5($event_id)."@".$this->get_domain().PHP_EOL;
2267
+ $ical .= "DTSTART:".gmdate('Ymd\\THi00\\Z', ($start_time - $gmt_offset_seconds)).PHP_EOL;
2268
+ $ical .= "DTEND:".gmdate('Ymd\\THi00\\Z', ($end_time - $gmt_offset_seconds)).PHP_EOL;
2269
+ $ical .= "DTSTAMP:".gmdate('Ymd\\THi00\\Z', ($stamp - $gmt_offset_seconds)).PHP_EOL;
2270
+
2271
+ if(is_array($rrules) and count($rrules))
2272
+ {
2273
+ foreach($rrules as $rrule) $ical .= $rrule.PHP_EOL;
2274
+ }
2275
+
2276
+ $ical .= "CREATED:".date('Ymd', $stamp).PHP_EOL;
2277
+ $ical .= "LAST-MODIFIED:".date('Ymd', $modified).PHP_EOL;
2278
+ $ical .= "SUMMARY:".html_entity_decode($event->title, ENT_NOQUOTES, 'UTF-8').PHP_EOL;
2279
+ $ical .= "DESCRIPTION:".html_entity_decode(trim(strip_tags($event->content)), ENT_NOQUOTES, 'UTF-8').PHP_EOL;
2280
+ $ical .= "URL:".$event->permalink.PHP_EOL;
2281
+
2282
+ // Location
2283
+ if(trim($location) != '') $ical .= "LOCATION:".$location.PHP_EOL;
2284
+
2285
+ // Featured Image
2286
+ if(trim($event->featured_image['full']) != '')
2287
+ {
2288
+ $ex = explode('/', $event->featured_image['full']);
2289
+ $filename = end($ex);
2290
+ $ical .= "ATTACH;FMTTYPE=".$this->get_mime_content_type($filename).":".$event->featured_image['full'].PHP_EOL;
2291
+ }
2292
+
2293
+ $ical .= "END:VEVENT".PHP_EOL;
2294
+
2295
+ return $ical;
2296
+ }
2297
+
2298
+
2299
+ /**
2300
+ * Returns iCal export for email
2301
+ * @author Webnus <info@webnus.biz>
2302
+ * @param int $event_id
2303
+ * @param int $book_id
2304
+ * @param string $occurrence
2305
+ * @return string
2306
+ */
2307
+ public function ical_single_email($event_id, $book_id, $occurrence = '')
2308
+ {
2309
+ $ticket_ids_str = get_post_meta($book_id, 'mec_ticket_id', true);
2310
+ $tickets = get_post_meta($event_id, 'mec_tickets', true);
2311
+
2312
+ $ticket_start_hour = $ticket_start_minute = $ticket_end_hour = $ticket_end_minute = $ticket_start_ampm = $ticket_end_ampm = '';
2313
+
2314
+ $ticket_ids = explode(',', $ticket_ids_str);
2315
+ $ticket_ids = array_filter($ticket_ids);
2316
+
2317
+ foreach($ticket_ids as $get_ticket_id=>$value)
2318
+ {
2319
+ foreach($tickets as $ticket=>$ticket_info)
2320
+ {
2321
+ if($ticket != $value) continue;
2322
+
2323
+ $ticket_start_hour = $ticket_info['ticket_start_time_hour'];
2324
+ $ticket_start_minute = $ticket_info['ticket_start_time_minute'];
2325
+ $ticket_start_ampm = $ticket_info['ticket_start_time_ampm'];
2326
+ $ticket_end_hour = $ticket_info['ticket_end_time_hour'];
2327
+ $ticket_end_minute = $ticket_info['ticket_end_time_minute'];
2328
+ $ticket_end_ampm = $ticket_info['ticket_end_time_ampm'];
2329
+ }
2330
+ }
2331
+
2332
+ // MEC Render Library
2333
+ $render = $this->getRender();
2334
+ $event = $render->data($event_id);
2335
+
2336
+ $location = isset($event->locations[$event->meta['mec_location_id']]) ? $event->locations[$event->meta['mec_location_id']]['address'] : '';
2337
+
2338
+ $start_time = strtotime(get_the_date('Y-m-d', $book_id).' '.sprintf("%02d", $ticket_start_hour).':'.sprintf("%02d", $ticket_start_minute).' '.$ticket_start_ampm);
2339
+ $end_time = strtotime(get_the_date('Y-m-d', $book_id).' '.sprintf("%02d", $ticket_end_hour).':'.sprintf("%02d", $ticket_end_minute).' '.$ticket_end_ampm);
2340
+
2341
+ $gmt_offset_seconds = $this->get_gmt_offset_seconds($start_time);
2342
+
2343
+ $stamp = strtotime($event->post->post_date);
2344
+ $modified = strtotime($event->post->post_modified);
2345
+
2346
+ $ical = "BEGIN:VEVENT".PHP_EOL;
2347
+ $ical .= "UID:MEC-".md5($event_id)."@".$this->get_domain().PHP_EOL;
2348
+ $ical .= "DTSTART:".gmdate('Ymd\\THi00\\Z', ($start_time - $gmt_offset_seconds)).PHP_EOL;
2349
+ $ical .= "DTEND:".gmdate('Ymd\\THi00\\Z', ($end_time - $gmt_offset_seconds)).PHP_EOL;
2350
+ $ical .= "DTSTAMP:".gmdate('Ymd\\THi00\\Z', ($stamp - $gmt_offset_seconds)).PHP_EOL;
2351
+ $ical .= "CREATED:".date('Ymd', $stamp).PHP_EOL;
2352
+ $ical .= "LAST-MODIFIED:".date('Ymd', $modified).PHP_EOL;
2353
+ $ical .= "SUMMARY:".html_entity_decode($event->title, ENT_NOQUOTES, 'UTF-8').PHP_EOL;
2354
+ $ical .= "DESCRIPTION:".html_entity_decode(trim(strip_tags($event->content)), ENT_NOQUOTES, 'UTF-8').PHP_EOL;
2355
+ $ical .= "URL:".$event->permalink.PHP_EOL;
2356
+
2357
+ // Location
2358
+ if(trim($location) != '') $ical .= "LOCATION:".$location.PHP_EOL;
2359
+
2360
+ // Featured Image
2361
+ if(trim($event->featured_image['full']) != '')
2362
+ {
2363
+ $ex = explode('/', $event->featured_image['full']);
2364
+ $filename = end($ex);
2365
+ $ical .= "ATTACH;FMTTYPE=".$this->get_mime_content_type($filename).":".$event->featured_image['full'].PHP_EOL;
2366
+ }
2367
+
2368
+ $ical .= "END:VEVENT".PHP_EOL;
2369
+
2370
+ return $ical;
2371
+ }
2372
+
2373
+ /**
2374
+ * Returns iCal export for some events
2375
+ * @author Webnus <info@webnus.biz>
2376
+ * @param string $events
2377
+ * @return string
2378
+ */
2379
+ public function ical_calendar($events)
2380
+ {
2381
+ $ical = "BEGIN:VCALENDAR".PHP_EOL;
2382
+ $ical .= "VERSION:2.0".PHP_EOL;
2383
+ $ical .= "METHOD:PUBLISH".PHP_EOL;
2384
+ $ical .= "CALSCALE:GREGORIAN".PHP_EOL;
2385
+ $ical .= "PRODID:-//WordPress - MECv".$this->get_version()."//EN".PHP_EOL;
2386
+ $ical .= "X-WR-CALNAME:WordPress".PHP_EOL;
2387
+ $ical .= "X-ORIGINAL-URL:".$this->URL('site').PHP_EOL;
2388
+ $ical .= $events;
2389
+ $ical .= "END:VCALENDAR";
2390
+
2391
+ return $ical;
2392
+ }
2393
+
2394
+ /**
2395
+ * Get mime type of a file
2396
+ * @author Webnus <info@webnus.biz>
2397
+ * @param string $filename
2398
+ * @return string
2399
+ */
2400
+ public function get_mime_content_type($filename)
2401
+ {
2402
+ // Remove query string from the image name
2403
+ if(strpos($filename, '?') !== false)
2404
+ {
2405
+ $ex = explode('?', $filename);
2406
+ $filename = $ex[0];
2407
+ }
2408
+
2409
+ $mime_types = array
2410
+ (
2411
+ 'txt' => 'text/plain',
2412
+ 'htm' => 'text/html',
2413
+ 'html' => 'text/html',
2414
+ 'php' => 'text/html',
2415
+ 'css' => 'text/css',
2416
+ 'js' => 'application/javascript',
2417
+ 'json' => 'application/json',
2418
+ 'xml' => 'application/xml',
2419
+ 'swf' => 'application/x-shockwave-flash',
2420
+ 'flv' => 'video/x-flv',
2421
+
2422
+ // images
2423
+ 'png' => 'image/png',
2424
+ 'jpe' => 'image/jpeg',
2425
+ 'jpeg' => 'image/jpeg',
2426
+ 'jpg' => 'image/jpeg',
2427
+ 'gif' => 'image/gif',
2428
+ 'bmp' => 'image/bmp',
2429
+ 'ico' => 'image/vnd.microsoft.icon',
2430
+ 'tiff' => 'image/tiff',
2431
+ 'tif' => 'image/tiff',
2432
+ 'svg' => 'image/svg+xml',
2433
+ 'svgz' => 'image/svg+xml',
2434
+
2435
+ // archives
2436
+ 'zip' => 'application/zip',
2437
+ 'rar' => 'application/x-rar-compressed',
2438
+ 'exe' => 'application/x-msdownload',
2439
+ 'msi' => 'application/x-msdownload',
2440
+ 'cab' => 'application/vnd.ms-cab-compressed',
2441
+
2442
+ // audio/video
2443
+ 'mp3' => 'audio/mpeg',
2444
+ 'qt' => 'video/quicktime',
2445
+ 'mov' => 'video/quicktime',
2446
+
2447
+ // adobe
2448
+ 'pdf' => 'application/pdf',
2449
+ 'psd' => 'image/vnd.adobe.photoshop',
2450
+ 'ai' => 'application/postscript',
2451
+ 'eps' => 'application/postscript',
2452
+ 'ps' => 'application/postscript',
2453
+
2454
+ // ms office
2455
+ 'doc' => 'application/msword',
2456
+ 'rtf' => 'application/rtf',
2457
+ 'xls' => 'application/vnd.ms-excel',
2458
+ 'ppt' => 'application/vnd.ms-powerpoint',
2459
+
2460
+ // open office
2461
+ 'odt' => 'application/vnd.oasis.opendocument.text',
2462
+ 'ods' => 'application/vnd.oasis.opendocument.spreadsheet',
2463
+ );
2464
+
2465
+ $ex = explode('.', $filename);
2466
+ $ext = strtolower(array_pop($ex));
2467
+ if(array_key_exists($ext, $mime_types))
2468
+ {
2469
+ return $mime_types[$ext];
2470
+ }
2471
+ elseif(function_exists('finfo_open'))
2472
+ {
2473
+ $finfo = finfo_open(FILEINFO_MIME);
2474
+ $mimetype = finfo_file($finfo, $filename);
2475
+ finfo_close($finfo);
2476
+
2477
+ return $mimetype;
2478
+ }
2479
+ else
2480
+ {
2481
+ return 'application/octet-stream';
2482
+ }
2483
+ }
2484
+
2485
+ /**
2486
+ * Returns book post type slug
2487
+ * @author Webnus <info@webnus.biz>
2488
+ * @return string
2489
+ */
2490
+ public function get_book_post_type()
2491
+ {
2492
+ return apply_filters('mec_book_post_type_name', 'mec-books');
2493
+ }
2494
+
2495
+ /**
2496
+ * Returns shortcode post type slug
2497
+ * @author Webnus <info@webnus.biz>
2498
+ * @return string
2499
+ */
2500
+ public function get_shortcode_post_type()
2501
+ {
2502
+ return apply_filters('mec_shortcode_post_type_name', 'mec_calendars');
2503
+ }
2504
+
2505
+ /**
2506
+ * Show text field options in booking form
2507
+ * @author Webnus <info@webnus.biz>
2508
+ * @param string $key
2509
+ * @param array $values
2510
+ * @return string
2511
+ */
2512
+ public function field_text($key, $values = array())
2513
+ {
2514
+ $field = '<li id="mec_reg_fields_'.$key.'">
2515
+ <span class="mec_reg_field_sort">'.__('Sort', 'modern-events-calendar-lite').'</span>
2516
+ <span class="mec_reg_field_type">'.__('Text', 'modern-events-calendar-lite').'</span>
2517
+ <p class="mec_reg_field_options">
2518
+ <label for="mec_reg_fields_'.$key.'_mandatory">
2519
+ <input type="hidden" name="mec[reg_fields]['.$key.'][mandatory]" value="0" />
2520
+ <input type="checkbox" name="mec[reg_fields]['.$key.'][mandatory]" value="1" id="mec_reg_fields_'.$key.'_mandatory" '.((isset($values['mandatory']) and $values['mandatory']) ? 'checked="checked"' : '').' />
2521
+ '.__('Required Field', 'modern-events-calendar-lite').'
2522
+ </label>
2523
+ </p>
2524
+ <span onclick="mec_reg_fields_remove('.$key.');" class="mec_reg_field_remove">'.__('Remove', 'modern-events-calendar-lite').'</span>
2525
+ <div>
2526
+ <input type="hidden" name="mec[reg_fields]['.$key.'][type]" value="text" />
2527
+ <input type="text" name="mec[reg_fields]['.$key.'][label]" placeholder="'.esc_attr__('Insert a label for this field', 'modern-events-calendar-lite').'" value="'.(isset($values['label']) ? $values['label'] : '').'" />
2528
+ </div>
2529
+ </li>';
2530
+
2531
+ return $field;
2532
+ }
2533
+
2534
+
2535
+ /**
2536
+ * Show text field options in booking form
2537
+ * @author Webnus <info@webnus.biz>
2538
+ * @param string $key
2539
+ * @param array $values
2540
+ * @return string
2541
+ */
2542
+ public function field_name($key, $values = array())
2543
+ {
2544
+ $field = '<li id="mec_reg_fields_'.$key.'">
2545
+ <span class="mec_reg_field_sort">'.__('Sort', 'modern-events-calendar-lite').'</span>
2546
+ <span class="mec_reg_field_type">'.__('MEC Name', 'modern-events-calendar-lite').'</span>
2547
+ <p class="mec_reg_field_options" style="display:none">
2548
+ <label for="mec_reg_fields_'.$key.'_mandatory">
2549
+ <input type="hidden" name="mec[reg_fields]['.$key.'][mandatory]" value="1" />
2550
+ <input type="checkbox" name="mec[reg_fields]['.$key.'][mandatory]" value="1" id="mec_reg_fields_'.$key.'_mandatory" checked="checked" disabled />
2551
+ '.__('Required Field', 'modern-events-calendar-lite').'
2552
+ </label>
2553
+ </p>
2554
+ <span onclick="mec_reg_fields_remove('.$key.');" class="mec_reg_field_remove">'.__('Remove', 'modern-events-calendar-lite').'</span>
2555
+ <div>
2556
+ <input type="hidden" name="mec[reg_fields]['.$key.'][type]" value="name" />
2557
+ <input type="text" name="mec[reg_fields]['.$key.'][label]" placeholder="'.esc_attr__('Insert a label for this field', 'modern-events-calendar-lite').'" value="'.(isset($values['label']) ? $values['label'] : '').'" />
2558
+ </div>
2559
+ </li>';
2560
+
2561
+ return $field;
2562
+ }
2563
+
2564
+ /**
2565
+ * Show text field options in booking form
2566
+ * @author Webnus <info@webnus.biz>
2567
+ * @param string $key
2568
+ * @param array $values
2569
+ * @return string
2570
+ */
2571
+ public function field_mec_email($key, $values = array())
2572
+ {
2573
+ $field = '<li id="mec_reg_fields_'.$key.'">
2574
+ <span class="mec_reg_field_sort">'.__('Sort', 'modern-events-calendar-lite').'</span>
2575
+ <span class="mec_reg_field_type">'.__('MEC Email', 'modern-events-calendar-lite').'</span>
2576
+ <p class="mec_reg_field_options" style="display:none">
2577
+ <label for="mec_reg_fields_'.$key.'_mandatory">
2578
+ <input type="hidden" name="mec[reg_fields]['.$key.'][mandatory]" value="1" />
2579
+ <input type="checkbox" name="mec[reg_fields]['.$key.'][mandatory]" value="1" id="mec_reg_fields_'.$key.'_mandatory" checked="checked" disabled />
2580
+ '.__('Required Field', 'modern-events-calendar-lite').'
2581
+ </label>
2582
+ </p>
2583
+ <span onclick="mec_reg_fields_remove('.$key.');" class="mec_reg_field_remove">'.__('Remove', 'modern-events-calendar-lite').'</span>
2584
+ <div>
2585
+ <input type="hidden" name="mec[reg_fields]['.$key.'][type]" value="mec_email" />
2586
+ <input type="text" name="mec[reg_fields]['.$key.'][label]" placeholder="'.esc_attr__('Insert a label for this field', 'modern-events-calendar-lite').'" value="'.(isset($values['label']) ? $values['label'] : '').'" />
2587
+ </div>
2588
+ </li>';
2589
+
2590
+ return $field;
2591
+ }
2592
+
2593
+
2594
+ /**
2595
+ * Show email field options in booking form
2596
+ * @author Webnus <info@webnus.biz>
2597
+ * @param string $key
2598
+ * @param array $values
2599
+ * @return string
2600
+ */
2601
+ public function field_email($key, $values = array())
2602
+ {
2603
+ $field = '<li id="mec_reg_fields_'.$key.'">
2604
+ <span class="mec_reg_field_sort">'.__('Sort', 'modern-events-calendar-lite').'</span>
2605
+ <span class="mec_reg_field_type">'.__('Email', 'modern-events-calendar-lite').'</span>
2606
+ <p class="mec_reg_field_options">
2607
+ <label for="mec_reg_fields_'.$key.'_mandatory">
2608
+ <input type="hidden" name="mec[reg_fields]['.$key.'][mandatory]" value="0" />
2609
+ <input type="checkbox" name="mec[reg_fields]['.$key.'][mandatory]" value="1" id="mec_reg_fields_'.$key.'_mandatory" '.((isset($values['mandatory']) and $values['mandatory']) ? 'checked="checked"' : '').' />
2610
+ '.__('Required Field', 'modern-events-calendar-lite').'
2611
+ </label>
2612
+ </p>
2613
+ <span onclick="mec_reg_fields_remove('.$key.');" class="mec_reg_field_remove">'.__('Remove', 'modern-events-calendar-lite').'</span>
2614
+ <div>
2615
+ <input type="hidden" name="mec[reg_fields]['.$key.'][type]" value="email" />
2616
+ <input type="text" name="mec[reg_fields]['.$key.'][label]" placeholder="'.esc_attr__('Insert a label for this field', 'modern-events-calendar-lite').'" value="'.(isset($values['label']) ? $values['label'] : '').'" />
2617
+ </div>
2618
+ </li>';
2619
+
2620
+ return $field;
2621
+ }
2622
+
2623
+ /**
2624
+ * Show file field options in booking form
2625
+ * @author Webnus <info@webnus.biz>
2626
+ * @param string $key
2627
+ * @param array $values
2628
+ * @return string
2629
+ */
2630
+ public function field_file($key, $values = array())
2631
+ {
2632
+ $field = '<li id="mec_reg_fields_'.$key.'">
2633
+ <span class="mec_reg_field_sort">'.__('Sort', 'modern-events-calendar-lite').'</span>
2634
+ <span class="mec_reg_field_type">'.__('File', 'modern-events-calendar-lite').'</span>
2635
+ <p class="mec_reg_field_options">
2636
+ <label for="mec_reg_fields_'.$key.'_mandatory">
2637
+ <input type="hidden" name="mec[reg_fields]['.$key.'][mandatory]" value="0" />
2638
+ <input type="checkbox" name="mec[reg_fields]['.$key.'][mandatory]" value="1" id="mec_reg_fields_'.$key.'_mandatory" '.((isset($values['mandatory']) and $values['mandatory']) ? 'checked="checked"' : '').' />
2639
+ '.__('Required Field', 'modern-events-calendar-lite').'
2640
+ </label>
2641
+ </p>
2642
+ <span onclick="mec_reg_fields_remove('.$key.');" class="mec_reg_field_remove">'.__('Remove', 'modern-events-calendar-lite').'</span>
2643
+ <div>
2644
+ <input type="hidden" name="mec[reg_fields]['.$key.'][type]" value="file" />
2645
+ <input type="text" name="mec[reg_fields]['.$key.'][label]" placeholder="'.esc_attr__('Insert a label for this field', 'modern-events-calendar-lite').'" value="'.(isset($values['label']) ? $values['label'] : '').'" />
2646
+ </div>
2647
+ </li>';
2648
+
2649
+ return $field;
2650
+ }
2651
+
2652
+ /**
2653
+ * Show date field options in booking form
2654
+ * @author Webnus <info@webnus.biz>
2655
+ * @param string $key
2656
+ * @param array $values
2657
+ * @return string
2658
+ */
2659
+ public function field_date($key, $values = array())
2660
+ {
2661
+ $field = '<li id="mec_reg_fields_'.$key.'">
2662
+ <span class="mec_reg_field_sort">'.__('Sort', 'modern-events-calendar-lite').'</span>
2663
+ <span class="mec_reg_field_type">'.__('Date', 'modern-events-calendar-lite').'</span>
2664
+ <p class="mec_reg_field_options">
2665
+ <label for="mec_reg_fields_'.$key.'_mandatory">
2666
+ <input type="hidden" name="mec[reg_fields]['.$key.'][mandatory]" value="0" />
2667
+ <input type="checkbox" name="mec[reg_fields]['.$key.'][mandatory]" value="1" id="mec_reg_fields_'.$key.'_mandatory" '.((isset($values['mandatory']) and $values['mandatory']) ? 'checked="checked"' : '').' />
2668
+ '.__('Required Field', 'modern-events-calendar-lite').'
2669
+ </label>
2670
+ </p>
2671
+ <span onclick="mec_reg_fields_remove('.$key.');" class="mec_reg_field_remove">'.__('Remove', 'modern-events-calendar-lite').'</span>
2672
+ <div>
2673
+ <input type="hidden" name="mec[reg_fields]['.$key.'][type]" value="date" />
2674
+ <input type="text" name="mec[reg_fields]['.$key.'][label]" placeholder="'.esc_attr__('Insert a label for this field', 'modern-events-calendar-lite').'" value="'.(isset($values['label']) ? $values['label'] : '').'" />
2675
+ </div>
2676
+ </li>';
2677
+
2678
+ return $field;
2679
+ }
2680
+
2681
+ /**
2682
+ * Show tel field options in booking form
2683
+ * @author Webnus <info@webnus.biz>
2684
+ * @param string $key
2685
+ * @param array $values
2686
+ * @return string
2687
+ */
2688
+ public function field_tel($key, $values = array())
2689
+ {
2690
+ $field = '<li id="mec_reg_fields_'.$key.'">
2691
+ <span class="mec_reg_field_sort">'.__('Sort', 'modern-events-calendar-lite').'</span>
2692
+ <span class="mec_reg_field_type">'.__('Tel', 'modern-events-calendar-lite').'</span>
2693
+ <p class="mec_reg_field_options">
2694
+ <label for="mec_reg_fields_'.$key.'_mandatory">
2695
+ <input type="hidden" name="mec[reg_fields]['.$key.'][mandatory]" value="0" />
2696
+ <input type="checkbox" name="mec[reg_fields]['.$key.'][mandatory]" value="1" id="mec_reg_fields_'.$key.'_mandatory" '.((isset($values['mandatory']) and $values['mandatory']) ? 'checked="checked"' : '').' />
2697
+ '.__('Required Field', 'modern-events-calendar-lite').'
2698
+ </label>
2699
+ </p>
2700
+ <span onclick="mec_reg_fields_remove('.$key.');" class="mec_reg_field_remove">'.__('Remove', 'modern-events-calendar-lite').'</span>
2701
+ <div>
2702
+ <input type="hidden" name="mec[reg_fields]['.$key.'][type]" value="tel" />
2703
+ <input type="text" name="mec[reg_fields]['.$key.'][label]" placeholder="'.esc_attr__('Insert a label for this field', 'modern-events-calendar-lite').'" value="'.(isset($values['label']) ? $values['label'] : '').'" />
2704
+ </div>
2705
+ </li>';
2706
+
2707
+ return $field;
2708
+ }
2709
+
2710
+ /**
2711
+ * Show textarea field options in booking form
2712
+ * @author Webnus <info@webnus.biz>
2713
+ * @param string $key
2714
+ * @param array $values
2715
+ * @return string
2716
+ */
2717
+ public function field_textarea($key, $values = array())
2718
+ {
2719
+ $field = '<li id="mec_reg_fields_'.$key.'">
2720
+ <span class="mec_reg_field_sort">'.__('Sort', 'modern-events-calendar-lite').'</span>
2721
+ <span class="mec_reg_field_type">'.__('Textarea', 'modern-events-calendar-lite').'</span>
2722
+ <p class="mec_reg_field_options">
2723
+ <label for="mec_reg_fields_'.$key.'_mandatory">
2724
+ <input type="hidden" name="mec[reg_fields]['.$key.'][mandatory]" value="0" />
2725
+ <input type="checkbox" name="mec[reg_fields]['.$key.'][mandatory]" value="1" id="mec_reg_fields_'.$key.'_mandatory" '.((isset($values['mandatory']) and $values['mandatory']) ? 'checked="checked"' : '').' />
2726
+ '.__('Required Field', 'modern-events-calendar-lite').'
2727
+ </label>
2728
+ </p>
2729
+ <span onclick="mec_reg_fields_remove('.$key.');" class="mec_reg_field_remove">'.__('Remove', 'modern-events-calendar-lite').'</span>
2730
+ <div>
2731
+ <input type="hidden" name="mec[reg_fields]['.$key.'][type]" value="textarea" />
2732
+ <input type="text" name="mec[reg_fields]['.$key.'][label]" placeholder="'.esc_attr__('Insert a label for this field', 'modern-events-calendar-lite').'" value="'.(isset($values['label']) ? $values['label'] : '').'" />
2733
+ </div>
2734
+ </li>';
2735
+
2736
+ return $field;
2737
+ }
2738
+
2739
+ /**
2740
+ * Show paragraph field options in booking form
2741
+ * @author Webnus <info@webnus.biz>
2742
+ * @param string $key
2743
+ * @param array $values
2744
+ * @return string
2745
+ */
2746
+ public function field_p($key, $values = array())
2747
+ {
2748
+ $field = '<li id="mec_reg_fields_'.$key.'">
2749
+ <span class="mec_reg_field_sort">'.__('Sort', 'modern-events-calendar-lite').'</span>
2750
+ <span class="mec_reg_field_type">'.__('Paragraph', 'modern-events-calendar-lite').'</span>
2751
+ <span onclick="mec_reg_fields_remove('.$key.');" class="mec_reg_field_remove">'.__('Remove', 'modern-events-calendar-lite').'</span>
2752
+ <div>
2753
+ <input type="hidden" name="mec[reg_fields]['.$key.'][type]" value="p" />
2754
+ <textarea name="mec[reg_fields]['.$key.'][content]">'.(isset($values['content']) ? htmlentities(stripslashes($values['content'])) : '').'</textarea>
2755
+ <p class="description">'.__('HTML and shortcode are allowed.').'</p>
2756
+ </div>
2757
+ </li>';
2758
+
2759
+ return $field;
2760
+ }
2761
+
2762
+ /**
2763
+ * Show checkbox field options in booking form
2764
+ * @author Webnus <info@webnus.biz>
2765
+ * @param string $key
2766
+ * @param array $values
2767
+ * @return string
2768
+ */
2769
+ public function field_checkbox($key, $values = array())
2770
+ {
2771
+ $i = 0;
2772
+ $field = '<li id="mec_reg_fields_'.$key.'">
2773
+ <span class="mec_reg_field_sort">'.__('Sort', 'modern-events-calendar-lite').'</span>
2774
+ <span class="mec_reg_field_type">'.__('Checkboxes', 'modern-events-calendar-lite').'</span>
2775
+ <p class="mec_reg_field_options">
2776
+ <label for="mec_reg_fields_'.$key.'_mandatory">
2777
+ <input type="hidden" name="mec[reg_fields]['.$key.'][mandatory]" value="0" />
2778
+ <input type="checkbox" name="mec[reg_fields]['.$key.'][mandatory]" value="1" id="mec_reg_fields_'.$key.'_mandatory" '.((isset($values['mandatory']) and $values['mandatory']) ? 'checked="checked"' : '').' />
2779
+ '.__('Required Field', 'modern-events-calendar-lite').'
2780
+ </label>
2781
+ </p>
2782
+ <span onclick="mec_reg_fields_remove('.$key.');" class="mec_reg_field_remove">'.__('Remove', 'modern-events-calendar-lite').'</span>
2783
+ <div>
2784
+ <input type="hidden" name="mec[reg_fields]['.$key.'][type]" value="checkbox" />
2785
+ <input type="text" name="mec[reg_fields]['.$key.'][label]" placeholder="'.esc_attr__('Insert a label for this field', 'modern-events-calendar-lite').'" value="'.(isset($values['label']) ? $values['label'] : '').'" />
2786
+ <ul id="mec_reg_fields_'.$key.'_options_container" class="mec_reg_fields_options_container">';
2787
+
2788
+ if(isset($values['options']) and is_array($values['options']) and count($values['options']))
2789
+ {
2790
+ foreach($values['options'] as $option_key=>$option)
2791
+ {
2792
+ $i = max($i, $option_key);
2793
+ $field .= $this->field_option($key, $option_key, $values);
2794
+ }
2795
+ }
2796
+
2797
+ $field .= '</ul>
2798
+ <button type="button" class="mec-reg-field-add-option" data-field-id="'.$key.'">'.__('Option', 'modern-events-calendar-lite').'</button>
2799
+ <input type="hidden" id="mec_new_reg_field_option_key_'.$key.'" value="'.($i+1).'" />
2800
+ </div>
2801
+ </li>';
2802
+
2803
+ return $field;
2804
+ }
2805
+
2806
+ /**
2807
+ * Show radio field options in booking form
2808
+ * @author Webnus <info@webnus.biz>
2809
+ * @param string $key
2810
+ * @param array $values
2811
+ * @return string
2812
+ */
2813
+ public function field_radio($key, $values = array())
2814
+ {
2815
+ $i = 0;
2816
+ $field = '<li id="mec_reg_fields_'.$key.'">
2817
+ <span class="mec_reg_field_sort">'.__('Sort', 'modern-events-calendar-lite').'</span>
2818
+ <span class="mec_reg_field_type">'.__('Radio Buttons', 'modern-events-calendar-lite').'</span>
2819
+ <p class="mec_reg_field_options">
2820
+ <label for="mec_reg_fields_'.$key.'_mandatory">
2821
+ <input type="hidden" name="mec[reg_fields]['.$key.'][mandatory]" value="0" />
2822
+ <input type="checkbox" name="mec[reg_fields]['.$key.'][mandatory]" value="1" id="mec_reg_fields_'.$key.'_mandatory" '.((isset($values['mandatory']) and $values['mandatory']) ? 'checked="checked"' : '').' />
2823
+ '.__('Required Field', 'modern-events-calendar-lite').'
2824
+ </label>
2825
+ </p>
2826
+ <span onclick="mec_reg_fields_remove('.$key.');" class="mec_reg_field_remove">'.__('Remove', 'modern-events-calendar-lite').'</span>
2827
+ <div>
2828
+ <input type="hidden" name="mec[reg_fields]['.$key.'][type]" value="radio" />
2829
+ <input type="text" name="mec[reg_fields]['.$key.'][label]" placeholder="'.esc_attr__('Insert a label for this field', 'modern-events-calendar-lite').'" value="'.(isset($values['label']) ? $values['label'] : '').'" />
2830
+ <ul id="mec_reg_fields_'.$key.'_options_container" class="mec_reg_fields_options_container">';
2831
+
2832
+ if(isset($values['options']) and is_array($values['options']) and count($values['options']))
2833
+ {
2834
+ foreach($values['options'] as $option_key=>$option)
2835
+ {
2836
+ $i = max($i, $option_key);
2837
+ $field .= $this->field_option($key, $option_key, $values);
2838
+ }
2839
+ }
2840
+
2841
+ $field .= '</ul>
2842
+ <button type="button" class="mec-reg-field-add-option" data-field-id="'.$key.'">'.__('Option', 'modern-events-calendar-lite').'</button>
2843
+ <input type="hidden" id="mec_new_reg_field_option_key_'.$key.'" value="'.($i+1).'" />
2844
+ </div>
2845
+ </li>';
2846
+
2847
+ return $field;
2848
+ }
2849
+
2850
+ /**
2851
+ * Show select field options in booking form
2852
+ * @author Webnus <info@webnus.biz>
2853
+ * @param string $key
2854
+ * @param array $values
2855
+ * @return string
2856
+ */
2857
+ public function field_select($key, $values = array())
2858
+ {
2859
+ $i = 0;
2860
+ $field = '<li id="mec_reg_fields_'.$key.'">
2861
+ <span class="mec_reg_field_sort">'.__('Sort', 'modern-events-calendar-lite').'</span>
2862
+ <span class="mec_reg_field_type">'.__('Dropdown', 'modern-events-calendar-lite').'</span>
2863
+ <p class="mec_reg_field_options">
2864
+ <label for="mec_reg_fields_'.$key.'_mandatory">
2865
+ <input type="hidden" name="mec[reg_fields]['.$key.'][mandatory]" value="0" />
2866
+ <input type="checkbox" name="mec[reg_fields]['.$key.'][mandatory]" value="1" id="mec_reg_fields_'.$key.'_mandatory" '.((isset($values['mandatory']) and $values['mandatory']) ? 'checked="checked"' : '').' />
2867
+ '.__('Required Field', 'modern-events-calendar-lite').'
2868
+ </label>
2869
+ </p>
2870
+ <span onclick="mec_reg_fields_remove('.$key.');" class="mec_reg_field_remove">'.__('Remove', 'modern-events-calendar-lite').'</span>
2871
+ <div>
2872
+ <input type="hidden" name="mec[reg_fields]['.$key.'][type]" value="select" />
2873
+ <input type="text" name="mec[reg_fields]['.$key.'][label]" placeholder="'.esc_attr__('Insert a label for this field', 'modern-events-calendar-lite').'" value="'.(isset($values['label']) ? $values['label'] : '').'" />
2874
+ <ul id="mec_reg_fields_'.$key.'_options_container" class="mec_reg_fields_options_container">';
2875
+
2876
+ if(isset($values['options']) and is_array($values['options']) and count($values['options']))
2877
+ {
2878
+ foreach($values['options'] as $option_key=>$option)
2879
+ {
2880
+ $i = max($i, $option_key);
2881
+ $field .= $this->field_option($key, $option_key, $values);
2882
+ }
2883
+ }
2884
+
2885
+ $field .= '</ul>
2886
+ <button type="button" class="mec-reg-field-add-option" data-field-id="'.$key.'">'.__('Option', 'modern-events-calendar-lite').'</button>
2887
+ <input type="hidden" id="mec_new_reg_field_option_key_'.$key.'" value="'.($i+1).'" />
2888
+ </div>
2889
+ </li>';
2890
+
2891
+ return $field;
2892
+ }
2893
+
2894
+ /**
2895
+ * Show agreement field options in booking form
2896
+ * @author Webnus <info@webnus.biz>
2897
+ * @param string $key
2898
+ * @param array $values
2899
+ * @return string
2900
+ */
2901
+ public function field_agreement($key, $values = array())
2902
+ {
2903
+ // WordPress Pages
2904
+ $pages = get_pages();
2905
+
2906
+ $i = 0;
2907
+ $field = '<li id="mec_reg_fields_'.$key.'">
2908
+ <span class="mec_reg_field_sort">'.__('Sort', 'modern-events-calendar-lite').'</span>
2909
+ <span class="mec_reg_field_type">'.__('Agreement', 'modern-events-calendar-lite').'</span>
2910
+ <p class="mec_reg_field_options">
2911
+ <label for="mec_reg_fields_'.$key.'_mandatory">
2912
+ <input type="hidden" name="mec[reg_fields]['.$key.'][mandatory]" value="0" />
2913
+ <input type="checkbox" name="mec[reg_fields]['.$key.'][mandatory]" value="1" id="mec_reg_fields_'.$key.'_mandatory" '.((!isset($values['mandatory']) or (isset($values['mandatory']) and $values['mandatory'])) ? 'checked="checked"' : '').' />
2914
+ '.__('Required Field', 'modern-events-calendar-lite').'
2915
+ </label>
2916
+ </p>
2917
+ <span onclick="mec_reg_fields_remove('.$key.');" class="mec_reg_field_remove">'.__('Remove', 'modern-events-calendar-lite').'</span>
2918
+ <div>
2919
+ <input type="hidden" name="mec[reg_fields]['.$key.'][type]" value="agreement" />
2920
+ <input type="text" name="mec[reg_fields]['.$key.'][label]" placeholder="'.esc_attr__('Insert a label for this field', 'modern-events-calendar-lite').'" value="'.(isset($values['label']) ? stripslashes($values['label']) : 'I agree with %s').'" /><p class="description">'.__('Instead of %s, the page title with a link will be show.', 'modern-events-calendar-lite').'</p>
2921
+ <div>
2922
+ <label for="mec_reg_fields_'.$key.'_page">'.__('Agreement Page', 'modern-events-calendar-lite').'</label>
2923
+ <select id="mec_reg_fields_'.$key.'_page" name="mec[reg_fields]['.$key.'][page]">';
2924
+
2925
+ $page_options = '';
2926
+ foreach($pages as $page) $page_options .= '<option '.((isset($values['page']) and $values['page'] == $page->ID) ? 'selected="selected"' : '').' value="'.$page->ID.'">'.$page->post_title.'</option>';
2927
+
2928
+ $field .= $page_options.'</select>
2929
+ </div>
2930
+ <div>
2931
+ <label for="mec_reg_fields_'.$key.'_status">'.__('Status', 'modern-events-calendar-lite').'</label>
2932
+ <select id="mec_reg_fields_'.$key.'_status" name="mec[reg_fields]['.$key.'][status]">
2933
+ <option value="checked" '.((isset($values['status']) and $values['status'] == 'checked') ? 'selected="selected"' : '').'>'.__('Checked by default', 'modern-events-calendar-lite').'</option>
2934
+ <option value="unchecked" '.((isset($values['status']) and $values['status'] == 'unchecked') ? 'selected="selected"' : '').'>'.__('Unchecked by default', 'modern-events-calendar-lite').'</option>
2935
+ </select>
2936
+ </div>
2937
+ <input type="hidden" id="mec_new_reg_field_option_key_'.$key.'" value="'.($i+1).'" />
2938
+ </div>
2939
+ </li>';
2940
+
2941
+ return $field;
2942
+ }
2943
+
2944
+ /**
2945
+ * Show option tag parameters in booking form for select, checkbox and radio tags
2946
+ * @author Webnus <info@webnus.biz>
2947
+ * @param string $field_key
2948
+ * @param string $key
2949
+ * @param array $values
2950
+ * @return string
2951
+ */
2952
+ public function field_option($field_key, $key, $values = array())
2953
+ {
2954
+ $field = '<li id="mec_reg_fields_option_'.$field_key.'_'.$key.'">
2955
+ <span class="mec_reg_field_option_sort">'.__('Sort', 'modern-events-calendar-lite').'</span>
2956
+ <span onclick="mec_reg_fields_option_remove('.$field_key.','.$key.');" class="mec_reg_field_remove">'.__('Remove', 'modern-events-calendar-lite').'</span>
2957
+ <input type="text" name="mec[reg_fields]['.$field_key.'][options]['.$key.'][label]" placeholder="'.esc_attr__('Insert a label for this option', 'modern-events-calendar-lite').'" value="'.((isset($values['options']) and isset($values['options'][$key])) ? esc_attr(stripslashes($values['options'][$key]['label'])) : '').'" />
2958
+ </li>';
2959
+
2960
+ return $field;
2961
+ }
2962
+
2963
+ /**
2964
+ * Render raw price and return its output
2965
+ * @author Webnus <info@webnus.biz>
2966
+ * @param int $price
2967
+ * @return string
2968
+ */
2969
+ public function render_price($price)
2970
+ {
2971
+ // return Free if price is 0
2972
+ if($price == '0') return __('Free', 'modern-events-calendar-lite');
2973
+
2974
+ $thousand_separator = $this->get_thousand_separator();
2975
+ $decimal_separator = $this->get_decimal_separator();
2976
+
2977
+ $currency = $this->get_currency_sign();
2978
+ $currency_sign_position = $this->get_currency_sign_position();
2979
+
2980
+ // Force to double
2981
+ if(is_string($price)) $price = (double) $price;
2982
+
2983
+ $rendered = number_format($price, ($decimal_separator === false ? 0 : 2), ($decimal_separator === false ? '' : $decimal_separator), $thousand_separator);
2984
+
2985
+ if($currency_sign_position == 'after') $rendered = $rendered.$currency;
2986
+ else $rendered = $currency.$rendered;
2987
+
2988
+ return $rendered;
2989
+ }
2990
+
2991
+ /**
2992
+ * Returns thousand separator
2993
+ * @author Webnus <info@webnus.biz>
2994
+ * @return string
2995
+ */
2996
+ public function get_thousand_separator()
2997
+ {
2998
+ $settings = $this->get_settings();
2999
+ return apply_filters('mec_thousand_separator', (isset($settings['thousand_separator']) ? $settings['thousand_separator'] : ','));
3000
+ }
3001
+
3002
+ /**
3003
+ * Returns decimal separator
3004
+ * @author Webnus <info@webnus.biz>
3005
+ * @return string
3006
+ */
3007
+ public function get_decimal_separator()
3008
+ {
3009
+ $settings = $this->get_settings();
3010
+ return apply_filters('mec_decimal_separator', ((isset($settings['decimal_separator_status']) and $settings['decimal_separator_status'] == 0) ? false : (isset($settings['decimal_separator']) ? $settings['decimal_separator'] : '.')));
3011
+ }
3012
+
3013
+ /**
3014
+ * Returns currency of MEC
3015
+ * @author Webnus <info@webnus.biz>
3016
+ * @return string
3017
+ */
3018
+ public function get_currency()
3019
+ {
3020
+ $settings = $this->get_settings();
3021
+ return apply_filters('mec_currency', (isset($settings['currency']) ? $settings['currency'] : ''));
3022
+ }
3023
+
3024
+ /**
3025
+ * Returns currency sign of MEC
3026
+ * @author Webnus <info@webnus.biz>
3027
+ * @return string
3028
+ */
3029
+ public function get_currency_sign()
3030
+ {
3031
+ $settings = $this->get_settings();
3032
+
3033
+ // Get Currency Symptom
3034
+ $currency = isset($settings['currency']) ? $settings['currency'] : '';
3035
+ if(isset($settings['currency_symptom']) and trim($settings['currency_symptom'])) $currency = $settings['currency_symptom'];
3036
+
3037
+ return apply_filters('mec_currency_sign', $currency);
3038
+ }
3039
+
3040
+ /**
3041
+ * Returns currency code of MEC
3042
+ * @author Webnus <info@webnus.biz>
3043
+ * @return string
3044
+ */
3045
+ public function get_currency_code()
3046
+ {
3047
+ $currency = $this->get_currency();
3048
+ $currencies = $this->get_currencies();
3049
+
3050
+ return isset($currencies[$currency]) ? $currencies[$currency] : 'USD';
3051
+ }
3052
+
3053
+ /**
3054
+ * Returns currency sign position of MEC
3055
+ * @author Webnus <info@webnus.biz>
3056
+ * @return string
3057
+ */
3058
+ public function get_currency_sign_position()
3059
+ {
3060
+ $settings = $this->get_settings();
3061
+ return apply_filters('mec_currency_sign_position', (isset($settings['currency_sign']) ? $settings['currency_sign'] : ''));
3062
+ }
3063
+
3064
+ /**
3065
+ * Returns MEC Payment Gateways
3066
+ * @author Webnus <info@webnus.biz>
3067
+ * @return array
3068
+ */
3069
+ public function get_gateways()
3070
+ {
3071
+ return apply_filters('mec_gateways', array());
3072
+ }
3073
+
3074
+ /**
3075
+ * Check to see if user exists by its username
3076
+ * @author Webnus <info@webnus.biz>
3077
+ * @param string $username
3078
+ * @return boolean
3079
+ */
3080
+ public function username_exists($username)
3081
+ {
3082
+ /** first validation **/
3083
+ if(!trim($username)) return true;
3084
+
3085
+ return username_exists($username);
3086
+ }
3087
+
3088
+ /**
3089
+ * Check to see if user exists by its email
3090
+ * @author Webnus <info@webnus.biz>
3091
+ * @param string $email
3092
+ * @return boolean
3093
+ */
3094
+ public function email_exists($email)
3095
+ {
3096
+ /** first validation **/
3097
+ if(!trim($email)) return true;
3098
+
3099
+ return email_exists($email);
3100
+ }
3101
+
3102
+ /**
3103
+ * Register a user in WordPress
3104
+ * @author Webnus <info@webnus.biz>
3105
+ * @param string $username
3106
+ * @param string $email
3107
+ * @param string $password
3108
+ * @return boolean
3109
+ */
3110
+ public function register_user($username, $email, $password = NULL)
3111
+ {
3112
+ /** first validation **/
3113
+ if(!trim($username) or !trim($email)) return false;
3114
+
3115
+ return wp_create_user($username, $password, $email);
3116
+ }
3117
+
3118
+ /**
3119
+ * Convert a formatted date into standard format
3120
+ * @author Webnus <info@webnus.biz>
3121
+ * @param string $date
3122
+ * @return string
3123
+ */
3124
+ public function to_standard_date($date)
3125
+ {
3126
+ return date('Y-m-d', strtotime(str_replace('-', '/', $date)));
3127
+ }
3128
+
3129
+ /**
3130
+ * Render the date
3131
+ * @author Webnus <info@webnus.biz>
3132
+ * @param string $date
3133
+ * @return string
3134
+ */
3135
+ public function render_date($date)
3136
+ {
3137
+ return $date;
3138
+ }
3139
+
3140
+ /**
3141
+ * Generate output of MEC Dashboard
3142
+ * @author Webnus <info@webnus.biz>
3143
+ */
3144
+ public function dashboard()
3145
+ {
3146
+ // Import dashboard page of MEC
3147
+ $path = $this->import('app.features.mec.dashboard', true, true);
3148
+
3149
+ // Create mec_events table if it's removed for any reason
3150
+ $this->create_mec_tables();
3151
+
3152
+ ob_start();
3153
+ include $path;
3154
+ echo $output = ob_get_clean();
3155
+ }
3156
+
3157
+ /**
3158
+ * Redirect on plugin activation
3159
+ * @author Webnus <info@webnus.biz>
3160
+ */
3161
+ public function mec_redirect_after_activate()
3162
+ {
3163
+ $do_redirection = apply_filters('mec_do_redirection_after_activation', true);
3164
+ if(!$do_redirection) return false;
3165
+
3166
+ // No need to redirect
3167
+ if(!get_option('mec_activation_redirect', false)) return true;
3168
+
3169
+ // Delete the option to don't do it always
3170
+ delete_option('mec_activation_redirect');
3171
+
3172
+ // Redirect to MEC Dashboard
3173
+ wp_redirect(admin_url('/admin.php?page=mec-intro'));
3174
+ exit;
3175
+ }
3176
+
3177
+ /**
3178
+ * Check if we can show booking module or not
3179
+ * @author Webnus <info@webnus.biz>
3180
+ * @param object $event
3181
+ * @return boolean
3182
+ */
3183
+ public function can_show_booking_module($event)
3184
+ {
3185
+ // PRO Version is required
3186
+ if(!$this->getPRO()) return false;
3187
+
3188
+ // MEC Settings
3189
+ $settings = $this->get_settings();
3190
+
3191
+ // Booking on single page is disabled
3192
+ if(!isset($settings['booking_status']) or (isset($settings['booking_status']) and !$settings['booking_status'])) return false;
3193
+
3194
+ $tickets = isset($event->data->tickets) ? $event->data->tickets : array();
3195
+ $dates = isset($event->dates) ? $event->dates : array();
3196
+ $next_date = isset($dates[0]) ? $dates[0] : (isset($event->date) ? $event->date : array());
3197
+
3198
+ // No Dates or no Tickets
3199
+ if(!count($dates) or !count($tickets)) return false;
3200
+
3201
+ $show_booking_form_interval = (isset($settings['show_booking_form_interval'])) ? $settings['show_booking_form_interval'] : 0;
3202
+
3203
+ // Check Show Booking Form Time
3204
+ if($show_booking_form_interval)
3205
+ {
3206
+ $render_date = (isset($next_date['start']['date']) ? trim($next_date['start']['date']) : date('Y-m-d')) .' '. (isset($next_date['start']['hour']) ? trim(sprintf('%02d', $next_date['start']['hour'])) : date('h', current_time('timestamp', 0))) .':'
3207
+ . (isset($next_date['start']['minutes']) ? trim(sprintf('%02d', $next_date['start']['minutes'])) : date('i', current_time('timestamp', 0))) . (isset($next_date['start']['ampm']) ? trim($next_date['start']['ampm']) : date('a', current_time('timestamp', 0)));
3208
+ if($this->check_date_time_validation('Y-m-d h:ia', strtolower($render_date)))
3209
+ {
3210
+ $date_diff = $this->date_diff(date('Y-m-d h:ia', current_time('timestamp', 0)), $render_date);
3211
+ if(isset($date_diff->d) and !$date_diff->invert and $date_diff->d < 2)
3212
+ {
3213
+ $minute = $date_diff->d * 24 * 60;
3214
+ $minute += $date_diff->h * 60;
3215
+ $minute += $date_diff->i;
3216
+
3217
+ if($minute > $show_booking_form_interval) return false;
3218
+ }
3219
+ }
3220
+ }
3221
+
3222
+ // Booking OnGoing Event Option
3223
+ $ongoing_event_book = (isset($settings['booking_ongoing']) and $settings['booking_ongoing'] == '1') ? true : false;
3224
+
3225
+ // The event is Expired/Passed
3226
+ if($ongoing_event_book)
3227
+ {
3228
+ if(!isset($next_date['end']) or (isset($next_date['end']) and $this->is_past($next_date['end']['date'], current_time('Y-m-d')))) return false;
3229
+ }
3230
+ else
3231
+ {
3232
+ $time_format = 'Y-m-d';
3233
+ $render_date = isset($next_date['start']) ? trim($next_date['start']['date']) : false;
3234
+
3235
+ if(!trim($event->data->meta['mec_repeat_status']))
3236
+ {
3237
+ $render_date .= ' ' . sprintf('%02d', $next_date['start']['hour']) . ':' . sprintf('%02d', $next_date['start']['minutes']) . trim($next_date['start']['ampm']);
3238
+ $time_format .= ' h:ia';
3239
+ }
3240
+
3241
+ if(!$render_date or ($render_date and $this->is_past($render_date, current_time($time_format)))) return false;
3242
+ }
3243
+
3244
+ // MEC payment gateways
3245
+ $gateways = $this->get_gateways();
3246
+ $is_gateway_enabled = false;
3247
+
3248
+ foreach($gateways as $gateway)
3249
+ {
3250
+ if($gateway->enabled())
3251
+ {
3252
+ $is_gateway_enabled = true;
3253
+ break;
3254
+ }
3255
+ }
3256
+
3257
+ // No Payment gateway is enabled
3258
+ if(!$is_gateway_enabled) return false;
3259
+
3260
+ return true;
3261
+ }
3262
+
3263
+ /**
3264
+ * Check if we can show countdown module or not
3265
+ * @author Webnus <info@webnus.biz>
3266
+ * @param object $event
3267
+ * @return boolean
3268
+ */
3269
+ public function can_show_countdown_module($event)
3270
+ {
3271
+ // MEC Settings
3272
+ $settings = $this->get_settings();
3273
+
3274
+ // Countdown on single page is disabled
3275
+ if(!isset($settings['countdown_status']) or (isset($settings['countdown_status']) and !$settings['countdown_status'])) return false;
3276
+
3277
+ $date = $event->date;
3278
+
3279
+ $start_date = (isset($date['start']) and isset($date['start']['date'])) ? $date['start']['date'] : date('Y-m-d');
3280
+
3281
+ // The event is Expired/Passed
3282
+ if($this->is_past($start_date, date('Y-m-d'))) return false;
3283
+
3284
+ return true;
3285
+ }
3286
+
3287
+ /**
3288
+ * Get default timezone of WordPress
3289
+ * @author Webnus <info@webnus.biz>
3290
+ * @return string
3291
+ */
3292
+ public function get_timezone()
3293
+ {
3294
+ $timezone_string = get_option('timezone_string');
3295
+ $gmt_offset = get_option('gmt_offset');
3296
+
3297
+ if(trim($timezone_string) == '' and trim($gmt_offset)) $timezone_string = $this->get_timezone_by_offset($gmt_offset);
3298
+ elseif(trim($timezone_string) == '' and trim($gmt_offset) == '0')
3299
+ {
3300
+ $timezone_string = 'UTC';
3301
+ }
3302
+
3303
+ return $timezone_string;
3304
+ }
3305
+
3306
+ /**
3307
+ * Get GMT offset based on hours:minutes
3308
+ * @author Webnus <info@webnus.biz>
3309
+ * @return string
3310
+ */
3311
+ public function get_gmt_offset()
3312
+ {
3313
+ $gmt_offset = get_option('gmt_offset');
3314
+
3315
+ $minutes = $gmt_offset*60;
3316
+ $hour_minutes = sprintf("%02d", $minutes%60);
3317
+
3318
+ // Convert the hour into two digits format
3319
+ $h = ($minutes-$hour_minutes)/60;
3320
+ $hours = sprintf("%02d", abs($h));
3321
+
3322
+ // Add - sign to the first of hour if it's negative
3323
+ if($h < 0) $hours = '-'.$hours;
3324
+
3325
+ return (substr($hours, 0, 1) == '-' ? '' : '+').$hours.':'.(((int) $hour_minutes < 0) ? abs($hour_minutes) : $hour_minutes);
3326
+ }
3327
+
3328
+ /**
3329
+ * Get GMT offset based on seconds
3330
+ * @author Webnus <info@webnus.biz>
3331
+ * @param $date
3332
+ * @return string
3333
+ */
3334
+ public function get_gmt_offset_seconds($date = NULL)
3335
+ {
3336
+ if($date)
3337
+ {
3338
+ $timezone = new DateTimeZone($this->get_timezone());
3339
+
3340
+ // Convert to Date
3341
+ if(is_numeric($date)) $date = date('Y-m-d', $date);
3342
+
3343
+ $target = new DateTime($date, $timezone);
3344
+ return $timezone->getOffset($target);
3345
+ }
3346
+ else
3347
+ {
3348
+ $gmt_offset = get_option('gmt_offset');
3349
+ $seconds = $gmt_offset*3600;
3350
+
3351
+ return (substr($gmt_offset, 0, 1) == '-' ? '' : '+').$seconds;
3352
+ }
3353
+ }
3354
+
3355
+ public function get_timezone_by_offset($offset)
3356
+ {
3357
+ $seconds = $offset*3600;
3358
+
3359
+ $timezone = timezone_name_from_abbr('', $seconds, 1);
3360
+ if($timezone === false) $timezone = timezone_name_from_abbr('', $seconds, 0);
3361
+
3362
+ if($timezone === false)
3363
+ {
3364
+ $timezones = array(
3365
+ '-12' => 'Pacific/Auckland',
3366
+ '-11.5' => 'Pacific/Auckland', // Approx
3367
+ '-11' => 'Pacific/Apia',
3368
+ '-10.5' => 'Pacific/Apia', // Approx
3369
+ '-10' => 'Pacific/Honolulu',
3370
+ '-9.5' => 'Pacific/Honolulu', // Approx
3371
+ '-9' => 'America/Anchorage',
3372
+ '-8.5' => 'America/Anchorage', // Approx
3373
+ '-8' => 'America/Los_Angeles',
3374
+ '-7.5' => 'America/Los_Angeles', // Approx
3375
+ '-7' => 'America/Denver',
3376
+ '-6.5' => 'America/Denver', // Approx
3377
+ '-6' => 'America/Chicago',
3378
+ '-5.5' => 'America/Chicago', // Approx
3379
+ '-5' => 'America/New_York',
3380
+ '-4.5' => 'America/New_York', // Approx
3381
+ '-4' => 'America/Halifax',
3382
+ '-3.5' => 'America/Halifax', // Approx
3383
+ '-3' => 'America/Sao_Paulo',
3384
+ '-2.5' => 'America/Sao_Paulo', // Approx
3385
+ '-2' => 'America/Sao_Paulo',
3386
+ '-1.5' => 'Atlantic/Azores', // Approx
3387
+ '-1' => 'Atlantic/Azores',
3388
+ '-0.5' => 'UTC', // Approx
3389
+ '0' => 'UTC',
3390
+ '0.5' => 'UTC', // Approx
3391
+ '1' => 'Europe/Paris',
3392
+ '1.5' => 'Europe/Paris', // Approx
3393
+ '2' => 'Europe/Helsinki',
3394
+ '2.5' => 'Europe/Helsinki', // Approx
3395
+ '3' => 'Europe/Moscow',
3396
+ '3.5' => 'Europe/Moscow', // Approx
3397
+ '4' => 'Asia/Dubai',
3398
+ '4.5' => 'Asia/Tehran',
3399
+ '5' => 'Asia/Karachi',
3400
+ '5.5' => 'Asia/Kolkata',
3401
+ '5.75' => 'Asia/Katmandu',
3402
+ '6' => 'Asia/Yekaterinburg',
3403
+ '6.5' => 'Asia/Yekaterinburg', // Approx
3404
+ '7' => 'Asia/Krasnoyarsk',
3405
+ '7.5' => 'Asia/Krasnoyarsk', // Approx
3406
+ '8' => 'Asia/Shanghai',
3407
+ '8.5' => 'Asia/Shanghai', // Approx
3408
+ '8.75' => 'Asia/Tokyo', // Approx
3409
+ '9' => 'Asia/Tokyo',
3410
+ '9.5' => 'Asia/Tokyo', // Approx
3411
+ '10' => 'Australia/Melbourne',
3412
+ '10.5' => 'Australia/Adelaide',
3413
+ '11' => 'Australia/Melbourne', // Approx
3414
+ '11.5' => 'Pacific/Auckland', // Approx
3415
+ '12' => 'Pacific/Auckland',
3416
+ '12.75' => 'Pacific/Apia', // Approx
3417
+ '13' => 'Pacific/Apia',
3418
+ '13.75' => 'Pacific/Honolulu', // Approx
3419
+ '14' => 'Pacific/Honolulu',
3420
+ );
3421
+
3422
+ $timezone = isset($timezones[$offset]) ? $timezones[$offset] : NULL;
3423
+ }
3424
+
3425
+ return $timezone;
3426
+ }
3427
+
3428
+ /**
3429
+ * Get status of Google recaptcha
3430
+ * @author Webnus <info@webnus.biz>
3431
+ * @param string $section
3432
+ * @return boolean
3433
+ */
3434
+ public function get_recaptcha_status($section = '')
3435
+ {
3436
+ // MEC Settings
3437
+ $settings = $this->get_settings();
3438
+
3439
+ $status = false;
3440
+
3441
+ // Check if the feature is enabled
3442
+ if(isset($settings['google_recaptcha_status']) and $settings['google_recaptcha_status']) $status = true;
3443
+
3444
+ // Check if the feature is enabled for certain section
3445
+ if($status and trim($section) and (!isset($settings['google_recaptcha_'.$section]) or (isset($settings['google_recaptcha_'.$section]) and !$settings['google_recaptcha_'.$section]))) $status = false;
3446
+
3447
+ // Check if site key and secret key is not empty
3448
+ if($status and (!isset($settings['google_recaptcha_sitekey']) or (isset($settings['google_recaptcha_sitekey']) and trim($settings['google_recaptcha_sitekey']) == ''))) $status = false;
3449
+ if($status and (!isset($settings['google_recaptcha_secretkey']) or (isset($settings['google_recaptcha_secretkey']) and trim($settings['google_recaptcha_secretkey']) == ''))) $status = false;
3450
+
3451
+ return $status;
3452
+ }
3453
+
3454
+ /**
3455
+ * Get re-captcha verification from Google servers
3456
+ * @author Webnus <info@webnus.biz>
3457
+ * @param string $remote_ip
3458
+ * @param string $response
3459
+ * @return boolean
3460
+ */
3461
+ public function get_recaptcha_response($response, $remote_ip = NULL)
3462
+ {
3463
+ // get the IP
3464
+ if(is_null($remote_ip)) $remote_ip = (isset($_SERVER["REMOTE_ADDR"]) ? $_SERVER["REMOTE_ADDR"] : '');
3465
+
3466
+ // MEC Settings
3467
+ $settings = $this->get_settings();
3468
+
3469
+ $data = array('secret'=>(isset($settings['google_recaptcha_secretkey']) ? $settings['google_recaptcha_secretkey'] : ''), 'remoteip'=>$remote_ip, 'v'=>'php_1.0', 'response'=>$response);
3470
+
3471
+ $req = "";
3472
+ foreach($data as $key=>$value) $req .= $key.'='.urlencode(stripslashes($value)).'&';
3473
+
3474
+ // Validate the re-captcha
3475
+ $getResponse = $this->get_web_page("https://www.google.com/recaptcha/api/siteverify?".trim($req, '& '));
3476
+
3477
+ $answers = json_decode($getResponse, true);
3478
+
3479
+ if(isset($answers['success']) and trim($answers['success'])) return true;
3480
+ else return false;
3481
+ }
3482
+
3483
+ /**
3484
+ * Get current language of WordPress
3485
+ * @author Webnus <info@webnus.biz>
3486
+ * @return string
3487
+ */
3488
+ public function get_current_language()
3489
+ {
3490
+ return apply_filters('plugin_locale', get_locale(), 'modern-events-calendar-lite');
3491
+ }
3492
+
3493
+ /**
3494
+ * Write to a log file
3495
+ * @author Webnus <info@webnus.biz>
3496
+ * @param string $log_msg
3497
+ * @param string $path
3498
+ */
3499
+ public function debug_log($log_msg, $path = '')
3500
+ {
3501
+ if(trim($path) == '') $path = MEC_ABSPATH. 'log.txt';
3502
+
3503
+ $fh = fopen($path, 'a');
3504
+ fwrite($fh, $log_msg);
3505
+ }
3506
+
3507
+ /**
3508
+ * Filter Skin parameters to add taxonomy, etc filters that come from WordPress Query
3509
+ * This used for taxonomy archive pages etc that are handled by WordPress itself
3510
+ * @author Webnus <info@webnus.biz>
3511
+ * @param array $atts
3512
+ * @return array
3513
+ */
3514
+ public function add_search_filters($atts = array())
3515
+ {
3516
+ // Taxonomy Archive Page
3517
+ if(is_tax())
3518
+ {
3519
+ $query = get_queried_object();
3520
+ $term_id = $query->term_id;
3521
+
3522
+ if(!isset($atts['category'])) $atts['category'] = '';
3523
+
3524
+ $atts['category'] = trim(trim($atts['category'], ', ').','.$term_id, ', ');
3525
+ }
3526
+
3527
+ return $atts;
3528
+ }
3529
+
3530
+ /**
3531
+ * Filter TinyMce Buttons
3532
+ * @author Webnus <info@webnus.biz>
3533
+ * @param array $buttons
3534
+ * @return array
3535
+ */
3536
+ public function add_mce_buttons($buttons)
3537
+ {
3538
+ array_push($buttons, 'mec_mce_buttons');
3539
+ return $buttons;
3540
+ }
3541
+
3542
+ /**
3543
+ * Filter TinyMce plugins
3544
+ * @author Webnus <info@webnus.biz>
3545
+ * @param array $plugins
3546
+ * @return array
3547
+ */
3548
+ public function add_mce_external_plugins($plugins)
3549
+ {
3550
+ $plugins['mec_mce_buttons'] = $this->asset('js/backend.js');
3551
+ return $plugins;
3552
+ }
3553
+
3554
+ /**
3555
+ * Return JSON output id and the name of a post type
3556
+ * @author Webnus <info@webnus.biz>
3557
+ * @param string $post_type
3558
+ * @return string JSON
3559
+ */
3560
+ public function mce_get_shortcode_list($post_type = 'mec_calendars')
3561
+ {
3562
+ if(post_type_exists($post_type))
3563
+ {
3564
+ $args = array('post_type' => $post_type, 'post_status' => 'publish', 'posts_per_page' => -1, 'order' => 'DESC');
3565
+ $shortcodes_list = get_posts($args);
3566
+ if(count($shortcodes_list))
3567
+ {
3568
+ $shortcodes = array();
3569
+ $shortcodes['shortcodes'] = array();
3570
+ foreach($shortcodes_list as $shortcode)
3571
+ {
3572
+ $shortcode_item = array();
3573
+ $shortcode_item['ID'] = $shortcode->ID;
3574
+ // PostName
3575
+ $shortcode_item['PN'] = $shortcode->post_name;
3576
+ array_push($shortcodes['shortcodes'], $shortcode_item);
3577
+ }
3578
+ $shortcodes['mce_title'] = __('M.E. Calender', 'modern-events-calendar-lite');
3579
+ return json_encode($shortcodes);
3580
+ }
3581
+ }
3582
+ return false;
3583
+ }
3584
+
3585
+ /**
3586
+ * Return date_diff
3587
+ * @author Webnus <info@webnus.biz>
3588
+ * @param string $start_date
3589
+ * @param string $end_date
3590
+ * @return object
3591
+ */
3592
+ public function date_diff($start_date, $end_date)
3593
+ {
3594
+ if(version_compare(PHP_VERSION, '5.3.0', '>=')) return date_diff(date_create($start_date), date_create($end_date));
3595
+ else
3596
+ {
3597
+ $start = new DateTime($start_date);
3598
+ $end = new DateTime($end_date);
3599
+ $days = round(($end->format('U') - $start->format('U')) / (60*60*24));
3600
+
3601
+ $interval = new stdClass();
3602
+ $interval->days = abs($days);
3603
+ $interval->invert = ($days >= 0 ? 0 : 1);
3604
+
3605
+ return $interval;
3606
+ }
3607
+ }
3608
+
3609
+ /**
3610
+ * Convert a certain time into seconds (Hours should be in 24 hours format)
3611
+ * @author Webnus <info@webnus.biz>
3612
+ * @param int $hours
3613
+ * @param int $minutes
3614
+ * @param int $seconds
3615
+ * @return int
3616
+ */
3617
+ public function time_to_seconds($hours, $minutes = 0, $seconds = 0)
3618
+ {
3619
+ return (($hours * 3600) + ($minutes * 60) + $seconds);
3620
+ }
3621
+
3622
+ /**
3623
+ * Convert a 12 hour format hour to a 24 format hour
3624
+ * @author Webnus <info@webnus.biz>
3625
+ * @param int $hour
3626
+ * @param string $ampm
3627
+ * @return int
3628
+ */
3629
+ public function to_24hours($hour, $ampm = 'PM')
3630
+ {
3631
+ $ampm = strtoupper($ampm);
3632
+
3633
+ if($ampm == 'AM' and $hour < 12) return $hour;
3634
+ elseif($ampm == 'AM' and $hour == 12) return 24;
3635
+ elseif($ampm == 'PM' and $hour < 12) return $hour+12;
3636
+ elseif($ampm == 'PM' and $hour == 12) return 12;
3637
+ elseif($ampm == 'PM' and $hour > 12) return $hour;
3638
+ }
3639
+
3640
+ /**
3641
+ * Get rendered events based on a certain criteria
3642
+ * @author Webnus <info@webnus.biz>
3643
+ * @param array $args
3644
+ * @return array
3645
+ */
3646
+ public function get_rendered_events($args = array())
3647
+ {
3648
+ $events = array();
3649
+ $sorted = array();
3650
+
3651
+ // Parse the args
3652
+ $args = wp_parse_args($args, array(
3653
+ 'post_type'=>$this->get_main_post_type(),
3654
+ 'posts_per_page'=>'-1',
3655
+ 'post_status'=>'publish'
3656
+ )
3657
+ );
3658
+
3659
+ // The Query
3660
+ $query = new WP_Query($args);
3661
+
3662
+ if($query->have_posts())
3663
+ {
3664
+ // MEC Render Library
3665
+ $render = $this->getRender();
3666
+
3667
+ // The Loop
3668
+ while($query->have_posts())
3669
+ {
3670
+ $query->the_post();
3671
+
3672
+ $event_id = get_the_ID();
3673
+ $rendered = $render->data($event_id);
3674
+
3675
+ $data = new stdClass();
3676
+ $data->ID = $event_id;
3677
+ $data->data = $rendered;
3678
+ $data->dates = $render->dates($event_id, $rendered, 6);
3679
+ $data->date = isset($data->dates[0]) ? $data->dates[0] : array();
3680
+
3681
+ // Caclculate event start time
3682
+ $event_start_time = strtotime($data->date['start']['date']) + $rendered->meta['mec_start_day_seconds'];
3683
+
3684
+ // Add the event into the to be sorted array
3685
+ if(!isset($sorted[$event_start_time])) $sorted[$event_start_time] = array();
3686
+ $sorted[$event_start_time][] = $data;
3687
+ }
3688
+
3689
+ ksort($sorted, SORT_NUMERIC);
3690
+ }
3691
+
3692
+ // Add sorted events to the results
3693
+ foreach($sorted as $sorted_events)
3694
+ {
3695
+ if(!is_array($sorted_events)) continue;
3696
+ foreach($sorted_events as $sorted_event) $events[$sorted_event->ID] = $sorted_event;
3697
+ }
3698
+
3699
+ // Restore original Post Data
3700
+ wp_reset_postdata();
3701
+
3702
+ return $events;
3703
+ }
3704
+
3705
+ /**
3706
+ * Duplicate an event
3707
+ * @author Webnus <info@webnus.biz>
3708
+ * @param int $post_id
3709
+ * @return boolean|int
3710
+ */
3711
+ public function duplicate($post_id)
3712
+ {
3713
+ // MEC DB Library
3714
+ $db = $this->getDB();
3715
+
3716
+ $post = get_post($post_id);
3717
+
3718
+ // Post is not exists
3719
+ if(!$post) return false;
3720
+
3721
+ //new post data array
3722
+ $args = array
3723
+ (
3724
+ 'comment_status'=>$post->comment_status,
3725
+ 'ping_status'=>$post->ping_status,
3726
+ 'post_author'=>$post->post_author,
3727
+ 'post_content'=>$post->post_content,
3728
+ 'post_excerpt'=>$post->post_excerpt,
3729
+ 'post_name'=>$post->post_name,
3730
+ 'post_parent'=>$post->post_parent,
3731
+ 'post_password'=>$post->post_password,
3732
+ 'post_status'=>'draft',
3733
+ 'post_title'=>sprintf(__('Copy of %s', 'modern-events-calendar-lite'), $post->post_title),
3734
+ 'post_type'=>$post->post_type,
3735
+ 'to_ping'=>$post->to_ping,
3736
+ 'menu_order'=>$post->menu_order
3737
+ );
3738
+
3739
+ // insert the new post
3740
+ $new_post_id = wp_insert_post($args);
3741
+
3742
+ // get all current post terms ad set them to the new post draft
3743
+ $taxonomies = get_object_taxonomies($post->post_type);
3744
+ foreach($taxonomies as $taxonomy)
3745
+ {
3746
+ $post_terms = wp_get_object_terms($post_id, $taxonomy, array('fields'=>'slugs'));
3747
+ wp_set_object_terms($new_post_id, $post_terms, $taxonomy, false);
3748
+ }
3749
+
3750
+ // duplicate all post meta
3751
+ $post_metas = $db->select("SELECT `meta_key`, `meta_value` FROM `#__postmeta` WHERE `post_id`='$post_id'", 'loadObjectList');
3752
+ if(count($post_metas) != 0)
3753
+ {
3754
+ $sql_query = "INSERT INTO `#__postmeta` (post_id, meta_key, meta_value) ";
3755
+
3756
+ foreach($post_metas as $meta_info)
3757
+ {
3758
+ $meta_key = $meta_info->meta_key;
3759
+ $meta_value = addslashes($meta_info->meta_value);
3760
+
3761
+ $sql_query_sel[] = "SELECT $new_post_id, '$meta_key', '$meta_value'";
3762
+ }
3763
+
3764
+ $sql_query .= implode(" UNION ALL ", $sql_query_sel);
3765
+ $db->q($sql_query);
3766
+ }
3767
+
3768
+ // Duplicate MEC record
3769
+ $mec_data = $db->select("SELECT * FROM `#__mec_events` WHERE `post_id`='$post_id'", 'loadAssoc');
3770
+
3771
+ $q1 = "";
3772
+ $q2 = "";
3773
+ foreach($mec_data as $key=>$value)
3774
+ {
3775
+ if(in_array($key, array('id', 'post_id'))) continue;
3776
+
3777
+ $q1 .= "`$key`,";
3778
+ $q2 .= "'$value',";
3779
+ }
3780
+
3781
+ $db->q("INSERT INTO `#__mec_events` (`post_id`,".trim($q1, ', ').") VALUES ('$new_post_id',".trim($q2, ', ').")");
3782
+
3783
+ // Update Schedule
3784
+ $schedule = $this->getSchedule();
3785
+ $schedule->reschedule($new_post_id);
3786
+
3787
+ return $new_post_id;
3788
+ }
3789
+
3790
+ /**
3791
+ * Returns start/end date label
3792
+ * @author Webnus <info@webnus.biz>
3793
+ * @param array $start
3794
+ * @param array $end
3795
+ * @param string $format
3796
+ * @param string $separator
3797
+ * @return string
3798
+ */
3799
+ public function date_label($start, $end, $format, $separator = ' - ')
3800
+ {
3801
+ $start_timestamp = strtotime($start['date']);
3802
+ $end_timestamp = strtotime($end['date']);
3803
+
3804
+ if($start_timestamp >= $end_timestamp) return '<span class="mec-start-date-label" itemprop="startDate">' . date_i18n($format, $start_timestamp) . '</span>';
3805
+ elseif($start_timestamp < $end_timestamp)
3806
+ {
3807
+ $start_date = date_i18n($format, $start_timestamp);
3808
+ $end_date = date_i18n($format, $end_timestamp);
3809
+
3810
+ if($start_date == $end_date) return '<span class="mec-start-date-label" itemprop="startDate">' . $start_date . '</span>';
3811
+ else return '<span class="mec-start-date-label" itemprop="startDate">' . date_i18n($format, $start_timestamp).'</span><span class="mec-end-date-label" itemprop="endDate">'.$separator.date_i18n($format, $end_timestamp).'</span>';
3812
+ }
3813
+ }
3814
+
3815
+ /**
3816
+ * Returns start/end time labels
3817
+ * @author Webnus <info@webnus.biz>
3818
+ * @param string $start
3819
+ * @param string $end
3820
+ * @param array $args
3821
+ * @return string
3822
+ */
3823
+ public function mec_include_time_labels($start = '', $end = '', $args = array())
3824
+ {
3825
+ $class = isset($args['class']) ? esc_attr($args['class']) : 'mec-time-details';
3826
+
3827
+ $return = "<div class='{$class}'>";
3828
+ if(trim($start)) $return .= '<span class="mec-start-time">' . $start . '</span>';
3829
+ if(trim($end)) $return .= ' - <span class="mec-end-time">' . $end . '</span>';
3830
+ $return .= '</div>';
3831
+
3832
+ return $return;
3833
+ }
3834
+
3835
+ /**
3836
+ * Returns end date of an event based on start date
3837
+ * @author Webnus <info@webnus.biz>
3838
+ * @param string $date
3839
+ * @param array $event
3840
+ * @return string
3841
+ */
3842
+ public function get_end_date($date, $event = array())
3843
+ {
3844
+ $start_date = isset($event->meta['mec_date']['start']) ? $event->meta['mec_date']['start'] : array();
3845
+ $end_date = isset($event->meta['mec_date']['end']) ? $event->meta['mec_date']['end'] : array();
3846
+
3847
+ $event_period = $this->date_diff($start_date['date'], $end_date['date']);
3848
+ $event_period_days = $event_period ? $event_period->days : 0;
3849
+
3850
+ $finish_date = array('date'=>$event->mec->end, 'hour'=>$event->meta['mec_date']['end']['hour'], 'minutes'=>$event->meta['mec_date']['end']['minutes'], 'ampm'=>$event->meta['mec_date']['end']['ampm']);
3851
+
3852
+ // Custom Dates
3853
+ $db = $this->getDB();
3854
+ $custom_date = $db->select("SELECT `dend` FROM `#__mec_dates` WHERE `post_id`='".$event->ID."' AND `dstart`<='".$date."' AND `dend`>='".$date."' ORDER BY `id` DESC LIMIT 1", 'loadResult');
3855
+
3856
+ // Event Passed
3857
+ $past = $this->is_past($finish_date['date'], $date);
3858
+
3859
+ // Normal event
3860
+ if(isset($event->mec->repeat) and $event->mec->repeat == '0')
3861
+ {
3862
+ return isset($end_date['date']) ? $end_date['date'] : $date;
3863
+ }
3864
+ // Custom Days
3865
+ elseif($custom_date)
3866
+ {
3867
+ return $custom_date;
3868
+ }
3869
+ // Past Event
3870
+ elseif($past)
3871
+ {
3872
+ return isset($end_date['date']) ? $end_date['date'] : $date;
3873
+ }
3874
+ elseif(!$past)
3875
+ {
3876
+ /**
3877
+ * Multiple Day Event
3878
+ * Check to see if today is between start day and end day.
3879
+ * For example start day is 5 and end day is 15 but we're in 9th so only 6 days remained till ending the event not 10 days.
3880
+ */
3881
+ if($event_period_days)
3882
+ {
3883
+ $start_day = date('j', strtotime($start_date['date']));
3884
+ $day = date('j', strtotime($date));
3885
+
3886
+ $passed_days = 0;
3887
+ if($day >= $start_day) $passed_days = $day - $start_day;
3888
+ else $passed_days = ($day+date('t', strtotime($start_date['date']))) - $start_day;
3889
+
3890
+ $event_period_days = $event_period_days - $passed_days;
3891
+ }
3892
+
3893
+ return date('Y-m-d', strtotime('+'.$event_period_days.' Days', strtotime($date)));
3894
+ }
3895
+ }
3896
+
3897
+ /**
3898
+ * Get Archive Status of MEC
3899
+ * @author Webnus <info@webnus.biz>
3900
+ * @return int
3901
+ */
3902
+ public function get_archive_status()
3903
+ {
3904
+ $settings = $this->get_settings();
3905
+
3906
+ $status = isset($settings['archive_status']) ? $settings['archive_status'] : '1';
3907
+ return apply_filters('mec_archive_status', $status);
3908
+ }
3909
+
3910
+ /**
3911
+ * Check to see if a table exists or not
3912
+ * @author Webnus <info@webnus.biz>
3913
+ * @param string $table
3914
+ * @return boolean
3915
+ */
3916
+ public function table_exists($table = 'mec_events')
3917
+ {
3918
+ // MEC DB library
3919
+ $db = $this->getDB();
3920
+
3921
+ return $db->q("SHOW TABLES LIKE '#__$table'");
3922
+ }
3923
+
3924
+ /**
3925
+ * Create MEC Tables
3926
+ * @author Webnus <info@webnus.biz>
3927
+ * @return boolean
3928
+ */
3929
+ public function create_mec_tables()
3930
+ {
3931
+ // MEC Events table already exists
3932
+ if($this->table_exists('mec_events') and $this->table_exists('mec_dates')) return true;
3933
+
3934
+ // MEC File library
3935
+ $file = $this->getFile();
3936
+
3937
+ // MEC DB library
3938
+ $db = $this->getDB();
3939
+
3940
+ // Run Queries
3941
+ $query_file = MEC_ABSPATH. 'assets' .DS. 'sql' .DS. 'tables.sql';
3942
+ if($file->exists($query_file))
3943
+ {
3944
+ $queries = $file->read($query_file);
3945
+ $sqls = explode(';', $queries);
3946
+
3947
+ foreach($sqls as $sql)
3948
+ {
3949
+ $sql = trim($sql, '; ');
3950
+ if(trim($sql) == '') continue;
3951
+
3952
+ $sql .= ';';
3953
+
3954
+ try
3955
+ {
3956
+ $db->q($sql);
3957
+ }
3958
+ catch (Exception $e){}
3959
+ }
3960
+ }
3961
+
3962
+ return true;
3963
+ }
3964
+
3965
+ /**
3966
+ * Return HTML email type
3967
+ * @author Webnus <info@webnus.biz>
3968
+ * @param string $content_type
3969
+ * @return string
3970
+ */
3971
+ public function html_email_type($content_type)
3972
+ {
3973
+ return 'text/html';
3974
+ }
3975
+
3976
+ public function get_next_upcoming_event()
3977
+ {
3978
+ MEC::import('app.skins.list', true);
3979
+
3980
+ // Get list skin
3981
+ $list = new MEC_skin_list();
3982
+
3983
+ // Attributes
3984
+ $atts = array(
3985
+ 'show_past_events'=>0,
3986
+ 'start_date_type'=>'today',
3987
+ 'sk-options'=> array(
3988
+ 'list' => array('limit'=>1)
3989
+ ),
3990
+ );
3991
+
3992
+ // Initialize the skin
3993
+ $list->initialize($atts);
3994
+
3995
+ // Fetch the events
3996
+ $list->fetch();
3997
+
3998
+ $events = $list->events;
3999
+ $key = key($events);
4000
+
4001
+ return (isset($events[$key][0]) ? $events[$key][0] : array());
4002
+ }
4003
+
4004
+ /**
4005
+ * Return a web page
4006
+ * @author Webnus <info@webnus.biz>
4007
+ * @param string $url
4008
+ * @return string
4009
+ */
4010
+ public function get_web_page($url)
4011
+ {
4012
+ $result = false;
4013
+
4014
+ // Doing WordPress Remote
4015
+ if(function_exists('wp_remote_get'))
4016
+ {
4017
+ $result = wp_remote_retrieve_body(wp_remote_get($url, array(
4018
+ 'body' => null,
4019
+ 'timeout' => '120',
4020
+ 'redirection' => '10',
4021
+ )));
4022
+ }
4023
+
4024
+ // Doing FGC
4025
+ if($result == false)
4026
+ {
4027
+ $http = array();
4028
+ $result = @file_get_contents($url, false, stream_context_create(array('http'=>$http)));
4029
+ }
4030
+
4031
+ return $result;
4032
+ }
4033
+
4034
+ public function save_events($events = array())
4035
+ {
4036
+ $ids = array();
4037
+
4038
+ foreach($events as $event) $ids[] = $this->save_event($event, (isset($event['ID']) ? $event['ID'] : NULL));
4039
+ return $ids;
4040
+ }
4041
+
4042
+ public function save_event($event = array(), $post_id = NULL)
4043
+ {
4044
+ $post = array('post_title'=>$event['title'], 'post_content'=>(isset($event['content']) ? $event['content'] : ''), 'post_type'=>$this->get_main_post_type(), 'post_status'=>(isset($event['status']) ? $event['status'] : 'publish'));
4045
+
4046
+ // Update previously inserted post
4047
+ if(!is_null($post_id)) $post['ID'] = $post_id;
4048
+
4049
+ $post_id = wp_insert_post($post);
4050
+
4051
+ update_post_meta($post_id, 'mec_location_id', (isset($event['location_id']) ? $event['location_id'] : 1));
4052
+ update_post_meta($post_id, 'mec_dont_show_map', 0);
4053
+ update_post_meta($post_id, 'mec_organizer_id', (isset($event['organizer_id']) ? $event['organizer_id'] : 1));
4054
+
4055
+ $start_time_hour = (isset($event['start_time_hour']) ? $event['start_time_hour'] : 8);
4056
+ $start_time_minutes = (isset($event['start_time_minutes']) ? $event['start_time_minutes'] : 0);
4057
+ $start_time_ampm = (isset($event['start_time_ampm']) ? $event['start_time_ampm'] : 'AM');
4058
+
4059
+ $end_time_hour = (isset($event['end_time_hour']) ? $event['end_time_hour'] : 6);
4060
+ $end_time_minutes = (isset($event['end_time_minutes']) ? $event['end_time_minutes'] : 0);
4061
+ $end_time_ampm = (isset($event['end_time_ampm']) ? $event['end_time_ampm'] : 'PM');
4062
+
4063
+ $allday = (isset($event['allday']) ? $event['allday'] : 0);
4064
+ $time_comment = (isset($event['time_comment']) ? $event['time_comment'] : '');
4065
+ $hide_time = ((isset($event['date']) and isset($event['date']['hide_time'])) ? $event['date']['hide_time'] : 0);
4066
+ $hide_end_time = ((isset($event['date']) and isset($event['date']['hide_end_time'])) ? $event['date']['hide_end_time'] : 0);
4067
+
4068
+ $day_start_seconds = $this->time_to_seconds($this->to_24hours($start_time_hour, $start_time_ampm), $start_time_minutes);
4069
+ $day_end_seconds = $this->time_to_seconds($this->to_24hours($end_time_hour, $end_time_ampm), $end_time_minutes);
4070
+
4071
+ update_post_meta($post_id, 'mec_allday', $allday);
4072
+ update_post_meta($post_id, 'mec_hide_time', $hide_time);
4073
+ update_post_meta($post_id, 'mec_hide_end_time', $hide_end_time);
4074
+
4075
+ update_post_meta($post_id, 'mec_start_date', $event['start']);
4076
+ update_post_meta($post_id, 'mec_start_time_hour', $start_time_hour);
4077
+ update_post_meta($post_id, 'mec_start_time_minutes', $start_time_minutes);
4078
+ update_post_meta($post_id, 'mec_start_time_ampm', $start_time_ampm);
4079
+ update_post_meta($post_id, 'mec_start_day_seconds', $day_start_seconds);
4080
+
4081
+ update_post_meta($post_id, 'mec_end_date', $event['end']);
4082
+ update_post_meta($post_id, 'mec_end_time_hour', $end_time_hour);
4083
+ update_post_meta($post_id, 'mec_end_time_minutes', $end_time_minutes);
4084
+ update_post_meta($post_id, 'mec_end_time_ampm', $end_time_ampm);
4085
+ update_post_meta($post_id, 'mec_end_day_seconds', $day_end_seconds);
4086
+
4087
+ update_post_meta($post_id, 'mec_repeat_status', $event['repeat_status']);
4088
+ update_post_meta($post_id, 'mec_repeat_type', $event['repeat_type']);
4089
+ update_post_meta($post_id, 'mec_repeat_interval', $event['interval']);
4090
+
4091
+ update_post_meta($post_id, 'mec_certain_weekdays', explode(',', trim((isset($event['weekdays']) ? $event['weekdays'] : ''), ', ')));
4092
+
4093
+ $date = array
4094
+ (
4095
+ 'start'=>array('date'=>$event['start'], 'hour'=>$start_time_hour, 'minutes'=>$start_time_minutes, 'ampm'=>$start_time_ampm),
4096
+ 'end'=>array('date'=>$event['end'], 'hour'=>$end_time_hour, 'minutes'=>$end_time_minutes, 'ampm'=>$end_time_ampm),
4097
+ 'repeat'=>((isset($event['date']) and isset($event['date']['repeat']) and is_array($event['date']['repeat'])) ? $event['date']['repeat'] : array()),
4098
+ 'allday'=>$allday,
4099
+ 'hide_time'=>((isset($event['date']) and isset($event['date']['hide_time'])) ? $event['date']['hide_time'] : 0),
4100
+ 'hide_end_time'=>((isset($event['date']) and isset($event['date']['hide_end_time'])) ? $event['date']['hide_end_time'] : 0),
4101
+ 'comment'=>$time_comment,
4102
+ );
4103
+
4104
+ update_post_meta($post_id, 'mec_date', $date);
4105
+
4106
+ // Creating $mec array for inserting in mec_events table
4107
+ $mec = array('post_id'=>$post_id, 'start'=>$event['start'], 'repeat'=>$event['repeat_status'], 'rinterval'=>$event['interval'], 'time_start'=>$day_start_seconds, 'time_end'=>$day_end_seconds);
4108
+
4109
+ // Add parameters to the $mec
4110
+ $mec['end'] = isset($event['finish']) ? $event['finish'] : '0000-00-00';
4111
+ $mec['year'] = isset($event['year']) ? $event['year'] : NULL;
4112
+ $mec['month'] = isset($event['month']) ? $event['month'] : NULL;
4113
+ $mec['day'] = isset($event['day']) ? $event['day'] : NULL;
4114
+ $mec['week'] = isset($event['week']) ? $event['week'] : NULL;
4115
+ $mec['weekday'] = isset($event['weekday']) ? $event['weekday'] : NULL;
4116
+ $mec['weekdays'] = isset($event['weekdays']) ? $event['weekdays'] : NULL;
4117
+ $mec['days'] = isset($event['days']) ? $event['days'] : '';
4118
+ $mec['not_in_days'] = isset($event['not_in_days']) ? $event['not_in_days'] : '';
4119
+
4120
+ // MEC DB Library
4121
+ $db = $this->getDB();
4122
+
4123
+ // Update MEC Events Table
4124
+ $mec_event_id = $db->select("SELECT `id` FROM `#__mec_events` WHERE `post_id`='$post_id'", 'loadResult');
4125
+
4126
+ if(!$mec_event_id)
4127
+ {
4128
+ $q1 = "";
4129
+ $q2 = "";
4130
+
4131
+ foreach($mec as $key=>$value)
4132
+ {
4133
+ $q1 .= "`$key`,";
4134
+
4135
+ if(is_null($value)) $q2 .= "NULL,";
4136
+ else $q2 .= "'$value',";
4137
+ }
4138
+
4139
+ $db->q("INSERT INTO `#__mec_events` (".trim($q1, ', ').") VALUES (".trim($q2, ', ').")", 'INSERT');
4140
+ }
4141
+ else
4142
+ {
4143
+ $q = "";
4144
+
4145
+ foreach($mec as $key=>$value)
4146
+ {
4147
+ if(is_null($value)) $q .= "`$key`=NULL,";
4148
+ else $q .= "`$key`='$value',";
4149
+ }
4150
+
4151
+ $db->q("UPDATE `#__mec_events` SET ".trim($q, ', ')." WHERE `id`='$mec_event_id'");
4152
+ }
4153
+
4154
+ if(isset($event['meta']) and is_array($event['meta'])) foreach($event['meta'] as $key=>$value) update_post_meta($post_id, $key, $value);
4155
+
4156
+ // Update Schedule
4157
+ $schedule = $this->getSchedule();
4158
+ $schedule->reschedule($post_id, $schedule->get_reschedule_maximum($event['repeat_type']));
4159
+
4160
+ return $post_id;
4161
+ }
4162
+
4163
+ public function save_category($category = array())
4164
+ {
4165
+ $name = isset($category['name']) ? $category['name'] : '';
4166
+ if(!trim($name)) return false;
4167
+
4168
+ $term = get_term_by('name', $name, 'mec_category');
4169
+
4170
+ // Term already exists
4171
+ if(is_object($term) and isset($term->term_id)) return $term->term_id;
4172
+
4173
+ $term = wp_insert_term($name, 'mec_category');
4174
+
4175
+ // An error ocurred
4176
+ if(is_wp_error($term)) return false;
4177
+
4178
+ $category_id = $term['term_id'];
4179
+ if(!$category_id) return false;
4180
+
4181
+ return $category_id;
4182
+ }
4183
+
4184
+ public function save_tag($tag = array())
4185
+ {
4186
+ $name = isset($tag['name']) ? $tag['name'] : '';
4187
+ if(!trim($name)) return false;
4188
+
4189
+ $term = get_term_by('name', $name, 'post_tag');
4190
+
4191
+ // Term already exists
4192
+ if(is_object($term) and isset($term->term_id)) return $term->term_id;
4193
+
4194
+ $term = wp_insert_term($name, 'post_tag');
4195
+
4196
+ // An error ocurred
4197
+ if(is_wp_error($term)) return false;
4198
+
4199
+ $tag_id = $term['term_id'];
4200
+ if(!$tag_id) return false;
4201
+
4202
+ return $tag_id;
4203
+ }
4204
+
4205
+ public function save_label($label = array())
4206
+ {
4207
+ $name = isset($label['name']) ? $label['name'] : '';
4208
+ if(!trim($name)) return false;
4209
+
4210
+ $term = get_term_by('name', $name, 'mec_label');
4211
+
4212
+ // Term already exists
4213
+ if(is_object($term) and isset($term->term_id)) return $term->term_id;
4214
+
4215
+ $term = wp_insert_term($name, 'mec_label');
4216
+
4217
+ // An error ocurred
4218
+ if(is_wp_error($term)) return false;
4219
+
4220
+ $label_id = $term['term_id'];
4221
+ if(!$label_id) return false;
4222
+
4223
+ $color = isset($label['color']) ? $label['color'] : '';
4224
+ update_term_meta($label_id, 'color', $color);
4225
+
4226
+ return $label_id;
4227
+ }
4228
+
4229
+ public function save_organizer($organizer = array())
4230
+ {
4231
+ $name = isset($organizer['name']) ? $organizer['name'] : '';
4232
+ if(!trim($name)) return false;
4233
+
4234
+ $term = get_term_by('name', $name, 'mec_organizer');
4235
+
4236
+ // Term already exists
4237
+ if(is_object($term) and isset($term->term_id)) return $term->term_id;
4238
+
4239
+ $term = wp_insert_term($name, 'mec_organizer');
4240
+
4241
+ // An error ocurred
4242
+ if(is_wp_error($term)) return false;
4243
+
4244
+ $organizer_id = $term['term_id'];
4245
+ if(!$organizer_id) return false;
4246
+
4247
+ if ( isset($organizer['tel']) && strpos($organizer['tel'], '@') !== false )
4248
+ {
4249
+ // Just for EventON
4250
+ $tel = '';
4251
+ $email = (isset($organizer['tel']) and trim($organizer['tel'])) ? $organizer['tel'] : '';
4252
+ } else {
4253
+ $tel = (isset($organizer['tel']) and trim($organizer['tel'])) ? $organizer['tel'] : '';
4254
+ $email = (isset($organizer['email']) and trim($organizer['email'])) ? $organizer['email'] : '';
4255
+ }
4256
+
4257
+ $url = (isset($organizer['url']) and trim($organizer['url'])) ? $organizer['url'] : '';
4258
+ $thumbnail = isset($organizer['thumbnail']) ? $organizer['thumbnail'] : '';
4259
+
4260
+ update_term_meta($organizer_id, 'tel', $tel);
4261
+ update_term_meta($organizer_id, 'email', $email);
4262
+ update_term_meta($organizer_id, 'url', $url);
4263
+ if(trim($thumbnail)) update_term_meta($organizer_id, 'thumbnail', $thumbnail);
4264
+
4265
+ return $organizer_id;
4266
+ }
4267
+
4268
+ public function save_location($location = array())
4269
+ {
4270
+ $name = isset($location['name']) ? $location['name'] : '';
4271
+ if(!trim($name)) return false;
4272
+
4273
+ $term = get_term_by('name', $name, 'mec_location');
4274
+
4275
+ // Term already exists
4276
+ if(is_object($term) and isset($term->term_id)) return $term->term_id;
4277
+
4278
+ $term = wp_insert_term($name, 'mec_location');
4279
+
4280
+ // An error ocurred
4281
+ if(is_wp_error($term)) return false;
4282
+
4283
+ $location_id = $term['term_id'];
4284
+ if(!$location_id) return false;
4285
+
4286
+ $latitude = (isset($location['latitude']) and trim($location['latitude'])) ? $location['latitude'] : 0;
4287
+ $longitude = (isset($location['longitude']) and trim($location['longitude'])) ? $location['longitude'] : 0;
4288
+ $address = isset($location['address']) ? $location['address'] : '';
4289
+ $thumbnail = isset($location['thumbnail']) ? $location['thumbnail'] : '';
4290
+
4291
+ if(!trim($latitude) or !trim($longitude))
4292
+ {
4293
+ $geo_point = $this->get_lat_lng($address);
4294
+
4295
+ $latitude = $geo_point[0];
4296
+ $longitude = $geo_point[1];
4297
+ }
4298
+
4299
+ update_term_meta($location_id, 'address', $address);
4300
+ update_term_meta($location_id, 'latitude', $latitude);
4301
+ update_term_meta($location_id, 'longitude', $longitude);
4302
+ if(trim($thumbnail)) update_term_meta($location_id, 'thumbnail', $thumbnail);
4303
+
4304
+ return $location_id;
4305
+ }
4306
+
4307
+ /**
4308
+ * Returns data export array for one event
4309
+ * @author Webnus <info@webnus.biz>
4310
+ * @param int $event_id
4311
+ * @return string
4312
+ */
4313
+ public function export_single($event_id)
4314
+ {
4315
+ // MEC Render Library
4316
+ $render = $this->getRender();
4317
+
4318
+ return $render->data($event_id);
4319
+ }
4320
+
4321
+ /**
4322
+ * Converts array to XML string
4323
+ * @author Webnus <info@webnus.biz>
4324
+ * @param array $data
4325
+ * @return string
4326
+ */
4327
+ public function xml_convert($data)
4328
+ {
4329
+ $main_node = array_keys($data);
4330
+
4331
+ // Creating SimpleXMLElement object
4332
+ $xml = new SimpleXMLElement('<?xml version="1.0"?><'.$main_node[0].'></'.$main_node[0].'>');
4333
+
4334
+ // Convert array to xml
4335
+ $this->array_to_xml($data[$main_node[0]], $xml);
4336
+
4337
+ // Return XML String
4338
+ return $xml->asXML();
4339
+ }
4340
+
4341
+ public function array_to_xml($data, &$xml)
4342
+ {
4343
+ foreach($data as $key=>$value)
4344
+ {
4345
+ if(is_numeric($key)) $key = 'item';
4346
+
4347
+ if(is_array($value))
4348
+ {
4349
+ $subnode = $xml->addChild($key);
4350
+ $this->array_to_xml($value, $subnode);
4351
+ }
4352
+ elseif(is_object($value))
4353
+ {
4354
+ $subnode = $xml->addChild($key);
4355
+ $this->array_to_xml($value, $subnode);
4356
+ }
4357
+ else
4358
+ {
4359
+ $xml->addChild($key, htmlspecialchars($value));
4360
+ }
4361
+ }
4362
+ }
4363
+
4364
+ /**
4365
+ * Returns Weekdays Day Numbers
4366
+ * @author Webnus <info@webnus.biz>
4367
+ * @return array
4368
+ */
4369
+ public function get_weekdays()
4370
+ {
4371
+ $weekdays = array(1,2,3,4,5);
4372
+
4373
+ // Get weekdays from options
4374
+ $settings = $this->get_settings();
4375
+ if(isset($settings['weekdays']) and is_array($settings['weekdays']) and count($settings['weekdays'])) $weekdays = $settings['weekdays'];
4376
+
4377
+ return apply_filters('mec_weekday_numbers', $weekdays);
4378
+ }
4379
+
4380
+ /**
4381
+ * Returns Weekends Day Numbers
4382
+ * @author Webnus <info@webnus.biz>
4383
+ * @return array
4384
+ */
4385
+ public function get_weekends()
4386
+ {
4387
+ $weekends = array(6,7);
4388
+
4389
+ // Get weekdays from options
4390
+ $settings = $this->get_settings();
4391
+ if(isset($settings['weekends']) and is_array($settings['weekends']) and count($settings['weekends'])) $weekends = $settings['weekends'];
4392
+
4393
+ return apply_filters('mec_weekend_numbers', $weekends);
4394
+ }
4395
+
4396
+ /**
4397
+ * Returns Event link with Occurrence Date
4398
+ * @author Webnus <info@webnus.biz>
4399
+ * @param string $url
4400
+ * @param string $date
4401
+ * @param boolean $force
4402
+ * @return string
4403
+ */
4404
+ public function get_event_date_permalink($url, $date = NULL, $force = false)
4405
+ {
4406
+ if(is_null($date)) return $url;
4407
+
4408
+ // Get MEC Options
4409
+ $settings = $this->get_settings();
4410
+
4411
+ // Single Page Date method is set to next date
4412
+ if(!$force and (!isset($settings['single_date_method']) or (isset($settings['single_date_method']) and $settings['single_date_method'] == 'next'))) return $url;
4413
+
4414
+ return $this->add_qs_var('occurrence', $date, $url);
4415
+ }
4416
+
4417
+ /**
4418
+ * Register MEC Activity Action Type in BuddeyPress
4419
+ * @return void
4420
+ */
4421
+ public function bp_register_activity_actions()
4422
+ {
4423
+ bp_activity_set_action(
4424
+ 'mec',
4425
+ 'booked_event',
4426
+ __('Booked an event.', 'modern-events-calendar-lite')
4427
+ );
4428
+ }
4429
+
4430
+ /**
4431
+ * Add a new activity to BuddyPress when a user book an event
4432
+ * @param int $book_id
4433
+ * @return boolean|int
4434
+ */
4435
+ public function bp_add_activity($book_id)
4436
+ {
4437
+ // Get MEC Options
4438
+ $settings = $this->get_settings();
4439
+
4440
+ // BuddyPress integration is disabled
4441
+ if(!isset($settings['bp_status']) or (isset($settings['bp_status']) and !$settings['bp_status'])) return false;
4442
+
4443
+ // BuddyPress add activity is disabled
4444
+ if(!isset($settings['bp_add_activity']) or (isset($settings['bp_add_activity']) and !$settings['bp_add_activity'])) return false;
4445
+
4446
+ // BuddyPress is not installed or activated
4447
+ if(!function_exists('bp_activity_add')) return false;
4448
+
4449
+ $verification = get_post_meta($book_id, 'mec_verified', true);
4450
+ $confirmation = get_post_meta($book_id, 'mec_confirmed', true);
4451
+
4452
+ // Booking is not verified or confirmed
4453
+ if($verification != 1 or $confirmation != 1) return false;
4454
+
4455
+ $event_id = get_post_meta($book_id, 'mec_event_id', true);
4456
+ $booker_id = get_post_field('post_author', $book_id);
4457
+
4458
+ $event_title = get_the_title($event_id);
4459
+ $event_link = get_the_permalink($event_id);
4460
+
4461
+ $profile_link = bp_core_get_userlink($booker_id);
4462
+ $bp_activity_id = get_post_meta($book_id, 'mec_bp_activity_id', true);
4463
+
4464
+ $activity_id = bp_activity_add(array
4465
+ (
4466
+ 'id'=>$bp_activity_id,
4467
+ 'action'=>sprintf(__('%s booked %s event.', 'modern-events-calendar-lite'), $profile_link, '<a href="'.$event_link.'">'.$event_title.'</a>'),
4468
+ 'component'=>'mec',
4469
+ 'type'=>'booked_event',
4470
+ 'primary_link'=>$event_link,
4471
+ 'user_id'=>$booker_id,
4472
+ 'item_id'=>$book_id,
4473
+ 'secondary_item_id'=>$event_id,
4474
+ ));
4475
+
4476
+ // Set Activity ID
4477
+ update_post_meta($book_id, 'mec_bp_activity_id', $activity_id);
4478
+
4479
+ return $activity_id;
4480
+ }
4481
+
4482
+ /**
4483
+ * Add booker information to mailchim list
4484
+ * @param int $book_id
4485
+ * @return boolean}int
4486
+ */
4487
+ public function mailchimp_add_subscriber($book_id)
4488
+ {
4489
+ // Get MEC Options
4490
+ $settings = $this->get_settings();
4491
+
4492
+ // Mailchim integration is disabled
4493
+ if(!isset($settings['mchimp_status']) or (isset($settings['mchimp_status']) and !$settings['mchimp_status'])) return false;
4494
+
4495
+ $api_key = isset($settings['mchimp_api_key']) ? $settings['mchimp_api_key'] : '';
4496
+ $list_id = isset($settings['mchimp_list_id']) ? $settings['mchimp_list_id'] : '';
4497
+
4498
+ // Mailchim credentials are required
4499
+ if(!trim($api_key) or !trim($list_id)) return false;
4500
+
4501
+ $booker_id = get_post_field('post_author', $book_id);
4502
+ $booker = get_userdata($booker_id);
4503
+
4504
+ $data_center = substr($api_key, strpos($api_key, '-') + 1);
4505
+ $url = 'https://' . $data_center . '.api.mailchimp.com/3.0/lists/' . $list_id . '/members/';
4506
+
4507
+ $subscription_status = isset($settings['mchimp_subscription_status']) ? $settings['mchimp_subscription_status'] : 'subscribed';
4508
+ $json = json_encode(array
4509
+ (
4510
+ 'email_address'=>$booker->user_email,
4511
+ 'status'=>$subscription_status,
4512
+ 'merge_fields'=>array
4513
+ (
4514
+ 'FNAME'=>$booker->first_name,
4515
+ 'LNAME'=>$booker->last_name
4516
+ )
4517
+ ));
4518
+
4519
+ // Execute the Request and Return the Response Code
4520
+ return wp_remote_retrieve_response_code(wp_remote_post($url, array(
4521
+ 'body' => $json,
4522
+ 'timeout' => '10',
4523
+ 'redirection' => '10',
4524
+ 'headers' => array('Content-Type' => 'application/json', 'Authorization' => 'Basic ' . base64_encode('user:' . $api_key)),
4525
+ )));
4526
+ }
4527
+
4528
+ /**
4529
+ * Returns Booking of a certain event at certain date
4530
+ * @param int $event_id
4531
+ * @param string $date
4532
+ * @return array
4533
+ */
4534
+ public function get_bookings($event_id, $date, $limit = '-1')
4535
+ {
4536
+ $time = strtotime($date);
4537
+
4538
+ $q = new WP_Query();
4539
+ return $q->query(array
4540
+ (
4541
+ 'post_type'=>$this->get_book_post_type(),
4542
+ 'posts_per_page'=>$limit,
4543
+ 'post_status'=>array('future', 'publish'),
4544
+ 'meta_query'=>array
4545
+ (
4546
+ array(
4547
+ 'key'=>'mec_event_id',
4548
+ 'value'=>$event_id,
4549
+ ),
4550
+ array(
4551
+ 'key'=>'mec_confirmed',
4552
+ 'value'=>1,
4553
+ ),
4554
+ array(
4555
+ 'key'=>'mec_verified',
4556
+ 'value'=>1,
4557
+ ),
4558
+ ),
4559
+ 'year'=>date('Y', $time),
4560
+ 'monthnum'=>date('n', $time),
4561
+ 'day'=>date('j', $time),
4562
+ ));
4563
+ }
4564
+
4565
+ /**
4566
+ * Check whether to show event note or not
4567
+ * @param string $status
4568
+ * @return boolean
4569
+ */
4570
+ public function is_note_visible($status)
4571
+ {
4572
+ // MEC Settings
4573
+ $settings = $this->get_settings();
4574
+
4575
+ // FES Note is not enabled
4576
+ if(!isset($settings['fes_note']) or (isset($settings['fes_note']) and !$settings['fes_note'])) return false;
4577
+
4578
+ // Return visibility status by post status and visibility method
4579
+ return (isset($settings['fes_note_visibility']) ? ($settings['fes_note_visibility'] == 'always' ? true : $status != 'publish') : true);
4580
+ }
4581
+
4582
+ /**
4583
+ * Get Next event based on datetime of current event
4584
+ * @param array $atts
4585
+ * @return array
4586
+ */
4587
+ public function get_next_event($atts = array())
4588
+ {
4589
+ MEC::import('app.skins.list', true);
4590
+
4591
+ // Get list skin
4592
+ $list = new MEC_skin_list();
4593
+
4594
+ // Initialize the skin
4595
+ $list->initialize($atts);
4596
+
4597
+ // Fetch the events
4598
+ $list->fetch();
4599
+
4600
+ $events = $list->events;
4601
+ $key = key($events);
4602
+
4603
+ return (isset($events[$key][0]) ? $events[$key][0] : array());
4604
+ }
4605
+
4606
+ /**
4607
+ * For getting event end date based on occurrence date
4608
+ * @param int $event_id
4609
+ * @param string $occurrence
4610
+ * @return string
4611
+ */
4612
+ public function get_end_date_by_occurrence($event_id, $occurrence)
4613
+ {
4614
+ $event_date = get_post_meta($event_id, 'mec_date', true);
4615
+
4616
+ $start_date = isset($event_date['start']) ? $event_date['start'] : array();
4617
+ $end_date = isset($event_date['end']) ? $event_date['end'] : array();
4618
+
4619
+ $event_period = $this->date_diff($start_date['date'], $end_date['date']);
4620
+ $event_period_days = $event_period ? $event_period->days : 0;
4621
+
4622
+ // Single Day Event
4623
+ if(!$event_period_days) return $occurrence;
4624
+
4625
+ return date('Y-m-d', strtotime('+'.$event_period_days.' days', strtotime($occurrence)));
4626
+ }
4627
+
4628
+ /**
4629
+ * Add MEC Event CPT to Tags Archive Page
4630
+ * @param object $query
4631
+ */
4632
+ public function add_events_to_tags_archive($query)
4633
+ {
4634
+ if($query->is_tag() and $query->is_main_query())
4635
+ {
4636
+ $pt = $this->get_main_post_type();
4637
+ $query->set('post_type', array('post', $pt));
4638
+ }
4639
+ }
4640
+
4641
+ /**
4642
+ * Get Post ID by meta value and meta key
4643
+ * @param string $meta_key
4644
+ * @param string $meta_value
4645
+ * @return string
4646
+ */
4647
+ public function get_post_id_by_meta($meta_key, $meta_value)
4648
+ {
4649
+ $db = $this->getDB();
4650
+ return $db->select("SELECT `post_id` FROM `#__postmeta` WHERE `meta_value`='$meta_value' AND `meta_key`='$meta_key'", 'loadResult');
4651
+ }
4652
+
4653
+ /**
4654
+ * Set Featured Image for a Post
4655
+ * @param string $image_url
4656
+ * @param int $post_id
4657
+ * @return bool|int
4658
+ */
4659
+ public function set_featured_image($image_url, $post_id)
4660
+ {
4661
+ $attach_id = $this->get_attach_id($image_url);
4662
+ if(!$attach_id)
4663
+ {
4664
+ $upload_dir = wp_upload_dir();
4665
+ $filename = basename($image_url);
4666
+
4667
+ if(wp_mkdir_p($upload_dir['path'])) $file = $upload_dir['path'].'/'.$filename;
4668
+ else $file = $upload_dir['basedir'].'/'.$filename;
4669
+
4670
+ if(!file_exists($file))
4671
+ {
4672
+ $image_data = $this->get_web_page($image_url);
4673
+ file_put_contents($file, $image_data);
4674
+ }
4675
+
4676
+ $wp_filetype = wp_check_filetype($filename, null);
4677
+ $attachment = array(
4678
+ 'post_mime_type'=>$wp_filetype['type'],
4679
+ 'post_title'=>sanitize_file_name($filename),
4680
+ 'post_content'=>'',
4681
+ 'post_status'=>'inherit'
4682
+ );
4683
+
4684
+ $attach_id = wp_insert_attachment($attachment, $file, $post_id);
4685
+ require_once ABSPATH.'wp-admin/includes/image.php';
4686
+
4687
+ $attach_data = wp_generate_attachment_metadata($attach_id, $file);
4688
+ wp_update_attachment_metadata($attach_id, $attach_data);
4689
+ }
4690
+
4691
+ return set_post_thumbnail($post_id, $attach_id);
4692
+ }
4693
+
4694
+ /**
4695
+ * Get Attachment ID by Image URL
4696
+ * @param string $image_url
4697
+ * @return int
4698
+ */
4699
+ public function get_attach_id($image_url)
4700
+ {
4701
+ $db = $this->getDB();
4702
+ return $db->select("SELECT `ID` FROM `#__posts` WHERE `guid`='$image_url'", 'loadResult');
4703
+ }
4704
+
4705
+ /**
4706
+ * Get Image Type by Buffer. Used in Facebook Importer
4707
+ * @param string $buffer
4708
+ * @return string
4709
+ */
4710
+ public function get_image_type_by_buffer($buffer)
4711
+ {
4712
+ $types = array('jpeg'=>"\xFF\xD8\xFF", 'gif'=>'GIF', 'png'=>"\x89\x50\x4e\x47\x0d\x0a", 'bmp'=>'BM', 'psd'=>'8BPS', 'swf'=>'FWS');
4713
+ $found = 'other';
4714
+
4715
+ foreach($types as $type=>$header)
4716
+ {
4717
+ if(strpos($buffer, $header) === 0)
4718
+ {
4719
+ $found = $type;
4720
+ break;
4721
+ }
4722
+ }
4723
+
4724
+ return $found;
4725
+ }
4726
+
4727
+ /**
4728
+ * Load Google Maps assets
4729
+ */
4730
+ public function load_map_assets()
4731
+ {
4732
+ if($this->getPRO())
4733
+ {
4734
+ // MEC Settings
4735
+ $settings = $this->get_settings();
4736
+
4737
+ // Include Google Maps Javascript API
4738
+ $gm_include = apply_filters('mec_gm_include', true);
4739
+ if($gm_include) wp_enqueue_script('googlemap', '//maps.googleapis.com/maps/api/js?libraries=places'.((isset($settings['google_maps_api_key']) and trim($settings['google_maps_api_key']) != '') ? '&key='.$settings['google_maps_api_key'] : ''));
4740
+
4741
+ // Google Maps Rich Marker
4742
+ wp_enqueue_script('mec-richmarker-script', $this->asset('packages/richmarker/richmarker.min.js'));
4743
+
4744
+ // Google Maps Clustering
4745
+ wp_enqueue_script('mec-clustering-script', $this->asset('packages/clusterer/markerclusterer.min.js'));
4746
+ }
4747
+ }
4748
+
4749
+ /**
4750
+ * Load Owl Carousel assets
4751
+ */
4752
+ public function load_owl_assets()
4753
+ {
4754
+ // Include MEC frontend CSS files
4755
+ wp_enqueue_style('mec-owl-carousel-style', $this->asset('packages/owl-carousel/owl.carousel.min.css'));
4756
+ wp_enqueue_style('mec-owl-carousel-theme-style', $this->asset('packages/owl-carousel/owl.theme.min.css'));
4757
+ }
4758
+
4759
+ /**
4760
+ * Load Isotope assets
4761
+ */
4762
+ public function load_isotope_assets()
4763
+ {
4764
+ // Isotope JS file
4765
+ wp_enqueue_script('mec-isotope-script', $this->asset('js/isotope.pkgd.min.js'));
4766
+ }
4767
+
4768
+ function get_client_ip()
4769
+ {
4770
+ $ipaddress = '';
4771
+
4772
+ if(isset($_SERVER['HTTP_CLIENT_IP'])) $ipaddress = $_SERVER['HTTP_CLIENT_IP'];
4773
+ elseif(isset($_SERVER['HTTP_X_FORWARDED_FOR'])) $ipaddress = $_SERVER['HTTP_X_FORWARDED_FOR'];
4774
+ elseif(isset($_SERVER['HTTP_X_FORWARDED'])) $ipaddress = $_SERVER['HTTP_X_FORWARDED'];
4775
+ elseif(isset($_SERVER['HTTP_FORWARDED_FOR'])) $ipaddress = $_SERVER['HTTP_FORWARDED_FOR'];
4776
+ elseif(isset($_SERVER['HTTP_FORWARDED'])) $ipaddress = $_SERVER['HTTP_FORWARDED'];
4777
+ elseif(isset($_SERVER['REMOTE_ADDR'])) $ipaddress = $_SERVER['REMOTE_ADDR'];
4778
+ else $ipaddress = 'UNKNOWN';
4779
+
4780
+ return $ipaddress;
4781
+ }
4782
+
4783
+ public function get_timezone_by_ip()
4784
+ {
4785
+ // Client IP
4786
+ $ip = $this->get_client_ip();
4787
+
4788
+ // First Provider
4789
+ $JSON = $this->get_web_page('http://ip-api.com/json/'.$ip);
4790
+ $data = json_decode($JSON, true);
4791
+
4792
+ // Second Provider
4793
+ if(!trim($JSON) or (is_array($data) and !isset($data['timezone'])))
4794
+ {
4795
+ $JSON = $this->get_web_page('https://ipapi.co/'.$ip.'/json/');
4796
+ $data = json_decode($JSON, true);
4797
+ }
4798
+
4799
+ // Second provide returns X instead of false in case of error!
4800
+ return (isset($data['timezone']) and strtolower($data['timezone']) != 'x') ? $data['timezone'] : false;
4801
+ }
4802
+
4803
+ public function is_ajax()
4804
+ {
4805
+ return (defined('DOING_AJAX') && DOING_AJAX);
4806
+ }
4807
+
4808
+ public function load_sed_assets()
4809
+ {
4810
+ // Load Map assets
4811
+ $this->load_map_assets();
4812
+
4813
+ // Include FlipCount library
4814
+ wp_enqueue_script('mec-flipcount-script', $this->asset('js/flipcount.js'));
4815
+ }
4816
+
4817
+ public function is_sold($event, $date)
4818
+ {
4819
+ $tickets = isset($event->data->tickets) ? $event->data->tickets : array();
4820
+
4821
+ // No Tickets
4822
+ if(!count($tickets)) return false;
4823
+
4824
+ $bookings = $this->get_bookings($event->data->ID, $date);
4825
+
4826
+ // No Bookings
4827
+ if(!count($bookings)) return false;
4828
+
4829
+ $available_spots = '0';
4830
+ foreach($tickets as $ticket)
4831
+ {
4832
+ if((isset($ticket['unlimited']) and $ticket['unlimited']) or !trim($ticket['limit']))
4833
+ {
4834
+ $available_spots = '-1';
4835
+ break;
4836
+ }
4837
+
4838
+ $available_spots += $ticket['limit'];
4839
+ }
4840
+
4841
+ // There are unlimitted spots
4842
+ if($available_spots == '-1') return false;
4843
+
4844
+ // Bookings are higher than available spots so event is sold
4845
+ if(count($bookings) >= $available_spots) return true;
4846
+
4847
+ return false;
4848
+ }
4849
+
4850
+ public function get_date_periods($date_start, $date_end, $type = 'daily')
4851
+ {
4852
+ $periods = array();
4853
+
4854
+ $time_start = strtotime($date_start);
4855
+ $time_end = strtotime($date_end);
4856
+
4857
+ if($type == 'daily')
4858
+ {
4859
+ while($time_start < $time_end)
4860
+ {
4861
+ $periods[] = array('start'=>date("Y-m-d H:i:s", $time_start), 'end'=>date("Y-m-d H:i:s", ($time_start+86399)), 'label'=>date("Y-m-d", $time_start));
4862
+ $time_start += 86400;
4863
+ }
4864
+ }
4865
+ // @todo
4866
+ elseif($type == 'weekly')
4867
+ {
4868
+ }
4869
+ elseif($type == 'monthly')
4870
+ {
4871
+ $start_year = date('Y', $time_start);
4872
+ $start_month = date('m', $time_start);
4873
+ $start_id = (int) $start_year.$start_month;
4874
+
4875
+ $end_year = date('Y', $time_end);
4876
+ $end_month = date('m', $time_end);
4877
+ $end_id = (int) $end_year.$end_month;
4878
+
4879
+ while($start_id <= $end_id)
4880
+ {
4881
+ $periods[] = array('start'=>$start_year."-".$start_month."-01 00:00:00", 'end'=>$start_year."-".$start_month."-".date('t', strtotime($start_year."-".$start_month."-01 00:00:00"))." 23:59:59", 'label'=>date('Y F', strtotime($start_year."-".$start_month."-01 00:00:00")));
4882
+
4883
+ if($start_month == '12')
4884
+ {
4885
+ $start_month = '01';
4886
+ $start_year++;
4887
+ }
4888
+ else
4889
+ {
4890
+ $start_month = (int) $start_month+1;
4891
+ if(strlen($start_month) == 1) $start_month = '0'.$start_month;
4892
+ }
4893
+
4894
+ $start_id = (int) $start_year.$start_month;
4895
+ }
4896
+ }
4897
+ elseif($type == 'yearly')
4898
+ {
4899
+ $start_year = date('Y', $time_start);
4900
+ $end_year = date('Y', $time_end);
4901
+
4902
+ while($start_year <= $end_year)
4903
+ {
4904
+ $periods[] = array('start'=>$start_year."-01-01 00:00:00", 'end'=>$start_year."-12-31 23:59:59", 'label'=>$start_year);
4905
+ $start_year++;
4906
+ }
4907
+ }
4908
+
4909
+ return $periods;
4910
+ }
4911
+
4912
+ public function get_messages()
4913
+ {
4914
+ $messages = array(
4915
+ 'taxonomies'=>array(
4916
+ 'category'=>array('name'=>__('Taxonomies', 'modern-events-calendar-lite')),
4917
+ 'messages'=>array(
4918
+ 'taxonomy_categories'=>array('label'=>__('Category Plural Label', 'modern-events-calendar-lite'), 'default'=>__('Categories', 'modern-events-calendar-lite')),
4919
+ 'taxonomy_category'=>array('label'=>__('Category Singular Label', 'modern-events-calendar-lite'), 'default'=>__('Category', 'modern-events-calendar-lite')),
4920
+ 'taxonomy_labels'=>array('label'=>__('Label Plural Label', 'modern-events-calendar-lite'), 'default'=>__('Labels', 'modern-events-calendar-lite')),
4921
+ 'taxonomy_label'=>array('label'=>__('Label Singular Label', 'modern-events-calendar-lite'), 'default'=>__('label', 'modern-events-calendar-lite')),
4922
+ 'taxonomy_locations'=>array('label'=>__('Location Plural Label', 'modern-events-calendar-lite'), 'default'=>__('Locations', 'modern-events-calendar-lite')),
4923
+ 'taxonomy_location'=>array('label'=>__('Location Singular Label', 'modern-events-calendar-lite'), 'default'=>__('Location', 'modern-events-calendar-lite')),
4924
+ 'taxonomy_organizers'=>array('label'=>__('Organizer Plural Label', 'modern-events-calendar-lite'), 'default'=>__('Organizers', 'modern-events-calendar-lite')),
4925
+ 'taxonomy_organizer'=>array('label'=>__('Organizer Singular Label', 'modern-events-calendar-lite'), 'default'=>__('Organizer', 'modern-events-calendar-lite')),
4926
+ 'taxonomy_speakers'=>array('label'=>__('Speaker Plural Label', 'modern-events-calendar-lite'), 'default'=>__('Speakers', 'modern-events-calendar-lite')),
4927
+ 'taxonomy_speaker'=>array('label'=>__('Speaker Singular Label', 'modern-events-calendar-lite'), 'default'=>__('Speaker', 'modern-events-calendar-lite')),
4928
+ )
4929
+ ),
4930
+ 'weekdays'=>array(
4931
+ 'category'=>array('name'=>__('Weekdays', 'modern-events-calendar-lite')),
4932
+ 'messages'=>array(
4933
+ 'weekdays_su'=>array('label'=>__('Sunday abbreviation', 'modern-events-calendar-lite'), 'default'=>__('SU', 'modern-events-calendar-lite')),
4934
+ 'weekdays_mo'=>array('label'=>__('Monday abbreviation', 'modern-events-calendar-lite'), 'default'=>__('MO', 'modern-events-calendar-lite')),
4935
+ 'weekdays_tu'=>array('label'=>__('Tuesday abbreviation', 'modern-events-calendar-lite'), 'default'=>__('TU', 'modern-events-calendar-lite')),
4936
+ 'weekdays_we'=>array('label'=>__('Wednesday abbreviation', 'modern-events-calendar-lite'), 'default'=>__('WE', 'modern-events-calendar-lite')),
4937
+ 'weekdays_th'=>array('label'=>__('Thursday abbreviation', 'modern-events-calendar-lite'), 'default'=>__('TH', 'modern-events-calendar-lite')),
4938
+ 'weekdays_fr'=>array('label'=>__('Friday abbreviation', 'modern-events-calendar-lite'), 'default'=>__('FR', 'modern-events-calendar-lite')),
4939
+ 'weekdays_sa'=>array('label'=>__('Saturday abbreviation', 'modern-events-calendar-lite'), 'default'=>__('SA', 'modern-events-calendar-lite')),
4940
+ )
4941
+ ),
4942
+ 'others'=>array(
4943
+ 'category'=>array('name'=>__('Others', 'modern-events-calendar-lite')),
4944
+ 'messages'=>array(
4945
+ 'book_success_message'=>array('label'=>__('Booking Success Message', 'modern-events-calendar-lite'), 'default'=>__('Thanks for your booking. Your tickets booked, booking verification might be needed, please check your email.', 'modern-events-calendar-lite')),
4946
+ 'register_button'=>array('label'=>__('Register Button', 'modern-events-calendar-lite'), 'default'=>__('REGISTER', 'modern-events-calendar-lite')),
4947
+ 'view_detail'=>array('label'=>__('View Detail Button', 'modern-events-calendar-lite'), 'default'=>__('View Detail', 'modern-events-calendar-lite')),
4948
+ 'event_detail'=>array('label'=>__('Event Detail Button', 'modern-events-calendar-lite'), 'default'=>__('Event Detail', 'modern-events-calendar-lite')),
4949
+ 'read_more_link'=>array('label'=>__('Event Link', 'modern-events-calendar-lite'), 'default'=>__('Event Link', 'modern-events-calendar-lite')),
4950
+ 'more_info_link'=>array('label'=>__('More Info Link', 'modern-events-calendar-lite'), 'default'=>__('More Info', 'modern-events-calendar-lite')),
4951
+ 'event_cost'=>array('label'=>__('Event Cost', 'modern-events-calendar-lite'), 'default'=>__('Event Cost', 'modern-events-calendar-lite')),
4952
+ 'cost'=>array('label'=>__('Cost', 'modern-events-calendar-lite'), 'default'=>__('Cost', 'modern-events-calendar-lite')),
4953
+ 'ticket'=>array('label'=>__('Ticket (Singular)', 'modern-events-calendar-lite'), 'default'=>__('Ticket', 'modern-events-calendar-lite')),
4954
+ 'tickets'=>array('label'=>__('Tickets (Plural)', 'modern-events-calendar-lite'), 'default'=>__('Tickets', 'modern-events-calendar-lite')),
4955
+ 'other_organizers'=>array('label'=>__('Other Organizers', 'modern-events-calendar-lite'), 'default'=>__('Other Organizers', 'modern-events-calendar-lite')),
4956
+ 'other_locations'=>array('label'=>__('Other Locations', 'modern-events-calendar-lite'), 'default'=>__('Other Locations', 'modern-events-calendar-lite')),
4957
+ )
4958
+ ),
4959
+ );
4960
+
4961
+ return apply_filters('mec_messages', $messages);
4962
+ }
4963
+
4964
+ /**
4965
+ * For showing dynamic messages based on their default value and the inserted value in backend (if any)
4966
+ * @param $message_key string
4967
+ * @param $default string
4968
+ * @return string
4969
+ */
4970
+ public function m($message_key, $default)
4971
+ {
4972
+ $message_values = $this->get_messages_options();
4973
+
4974
+ // Message is not set from backend
4975
+ if(!isset($message_values[$message_key]) or (isset($message_values[$message_key]) and !trim($message_values[$message_key]))) return $default;
4976
+
4977
+ // Return the dynamic message inserted in backend
4978
+ return $message_values[$message_key];
4979
+ }
4980
+
4981
+ /**
4982
+ * Get Weather from the data provider
4983
+ * @param $lat
4984
+ * @param $lng
4985
+ * @param $datetime
4986
+ * @return bool|array
4987
+ */
4988
+ public function get_weather($lat, $lng, $datetime)
4989
+ {
4990
+ // MEC Settings
4991
+ $settings = $this->get_settings();
4992
+
4993
+ // API KEY is required!
4994
+ if(!isset($settings['weather_module_api_key']) or (isset($settings['weather_module_api_key']) and !trim($settings['weather_module_api_key']))) return false;
4995
+
4996
+ $locale = substr(get_locale(), 0, 2);
4997
+
4998
+ // Set the language to English if it's not included in available languages
4999
+ if(!in_array($locale, array
5000
+ (
5001
+ 'ar', 'az', 'be', 'bg', 'bs', 'ca', 'cs', 'da', 'de', 'el', 'en', 'es', 'et',
5002
+ 'fi', 'fr', 'hr', 'hu', 'id', 'is', 'it', 'ja', 'ka', 'ko', 'kw', 'nb', 'nl',
5003
+ 'no', 'pl', 'pt', 'ro', 'ru', 'sk', 'sl', 'sr', 'sv', 'tet', 'tr', 'uk', 'x-pig-latin',
5004
+ 'zh', 'zh-tw'
5005
+ ))) $locale = 'en';
5006
+
5007
+ // Dark Sky Provider
5008
+ $JSON = $this->get_web_page('https://api.darksky.net/forecast/'.$settings['weather_module_api_key'].'/'.$lat.','.$lng.','.strtotime($datetime).'?exclude=minutely,hourly,daily,alerts&units=ca&lang='.$locale);
5009
+ $data = json_decode($JSON, true);
5010
+
5011
+ return (isset($data['currently']) ? $data['currently'] : false);
5012
+ }
5013
+
5014
+ /**
5015
+ * Convert weather unit
5016
+ * @author Webnus <info@webnus.biz>
5017
+ * @param $value
5018
+ * @param $mode
5019
+ * @return string|boolean
5020
+ */
5021
+ function weather_unit_convert($value, $mode)
5022
+ {
5023
+ if(func_num_args() < 2) return;
5024
+ $mode = strtoupper($mode);
5025
+
5026
+ if($mode == 'F_TO_C') return (round(((floatval($value) -32) *5 /9)));
5027
+ else if($mode == 'C_TO_F') return (round(((1.8 * floatval($value)) +32)));
5028
+ else if($mode == 'M_TO_KM') return(round(1.609344 * floatval($value)));
5029
+ else if($mode == 'KM_TO_M') return(round(0.6214 * floatval($value)));
5030
+ return false;
5031
+ }
5032
+
5033
+ /**
5034
+ * Get Integrated plugins to import events
5035
+ * @return array
5036
+ */
5037
+ public function get_integrated_plugins_for_import()
5038
+ {
5039
+ return array(
5040
+ 'eventon' => __('EventON', 'modern-events-calendar-lite'),
5041
+ 'the-events-calendar' => __('The Events Calendar', 'modern-events-calendar-lite'),
5042
+ 'weekly-class' => __('Events Schedule WP Plugin', 'modern-events-calendar-lite'),
5043
+ 'calendarize-it' => __('Calendarize It', 'modern-events-calendar-lite'),
5044
+ 'event-espresso' => __('Event Espresso', 'modern-events-calendar-lite'),
5045
+ 'events-manager-recurring' => __('Events Manager (Recurring)', 'modern-events-calendar-lite'),
5046
+ 'events-manager-single' => __('Events Manager (Single)', 'modern-events-calendar-lite'),
5047
+ );
5048
+ }
5049
+
5050
+ public function get_original_event($event_id)
5051
+ {
5052
+ // If WPML Plugin is installed and activated
5053
+ if(class_exists('SitePress'))
5054
+ {
5055
+ $trid = apply_filters('wpml_element_trid', NULL, $event_id, 'post_mec-events');
5056
+ $translations = apply_filters('wpml_get_element_translations', NULL, $trid, 'post_mec-events');
5057
+
5058
+ if(!is_array($translations) or (is_array($translations) and !count($translations))) return $event_id;
5059
+
5060
+ $original_id = $event_id;
5061
+ foreach($translations as $translation)
5062
+ {
5063
+ if(isset($translation->original) and $translation->original)
5064
+ {
5065
+ $original_id = $translation->element_id;
5066
+ break;
5067
+ }
5068
+ }
5069
+
5070
+ return $original_id;
5071
+ }
5072
+ else return $event_id;
5073
+ }
5074
+
5075
+ /**
5076
+ * To check is a date is valid or not
5077
+ * @param string $date
5078
+ * @param string $format
5079
+ * @return bool
5080
+ */
5081
+ public function validate_date($date, $format = 'Y-m-d')
5082
+ {
5083
+ $d = DateTime::createFromFormat($format, $date);
5084
+ return $d && $d->format($format) == $date;
5085
+ }
5086
+
5087
+ public function parse_ics($feed)
5088
+ {
5089
+ try {
5090
+ $ical = new ICal($feed, array(
5091
+ 'defaultSpan' => 2, // Default value
5092
+ 'defaultTimeZone' => 'UTC',
5093
+ 'defaultWeekStart' => 'MO', // Default value
5094
+ 'disableCharacterReplacement' => false, // Default value
5095
+ 'skipRecurrence' => false, // Default value
5096
+ 'useTimeZoneWithRRules' => false, // Default value
5097
+ ));
5098
+
5099
+ return $ical;
5100
+ }
5101
+ catch(\Exception $e)
5102
+ {
5103
+ return false;
5104
+ }
5105
+ }
5106
+
5107
+ public function get_pro_link()
5108
+ {
5109
+ return 'https://webnus.net/mec-purchase/';
5110
+ }
5111
+
5112
+ /**
5113
+ * Get Label for booking confirmation
5114
+ * @author Webnus <info@webnus.biz>
5115
+ * @param int $confirmed
5116
+ * @return string
5117
+ */
5118
+ public function get_confirmation_label($confirmed = 1)
5119
+ {
5120
+ if($confirmed == '1') $label = __('Confirmed', 'modern-events-calendar-lite');
5121
+ elseif($confirmed == '-1') $label = __('Rejected', 'modern-events-calendar-lite');
5122
+ else $label = __('Pending', 'modern-events-calendar-lite');
5123
+
5124
+ return $label;
5125
+ }
5126
+
5127
+ /**
5128
+ * Get Label for events status
5129
+ * @author Webnus <info@webnus.biz>
5130
+ * @param string $label
5131
+ * @param boolean $return_class
5132
+ * @return string|array
5133
+ */
5134
+ public function get_event_label_status($label = 'empty', $return_class = true)
5135
+ {
5136
+ if(!trim($label)) $label = 'empty';
5137
+ switch($label)
5138
+ {
5139
+ case 'publish':
5140
+ $label = __('Confirmed', 'modern-events-calendar-lite');
5141
+ $status_class = 'mec-book-confirmed';
5142
+ break;
5143
+ case 'pending':
5144
+ $label = __('Pending', 'modern-events-calendar-lite');
5145
+ $status_class = 'mec-book-pending';
5146
+ break;
5147
+ case 'trash':
5148
+ $label = __('Rejected', 'modern-events-calendar-lite');
5149
+ $status_class = 'mec-book-pending';
5150
+ break;
5151
+ default:
5152
+ $label = __(ucwords($label), 'modern-events-calendar-lite');
5153
+ $status_class = 'mec-book-other';
5154
+ break;
5155
+ }
5156
+
5157
+ return !$return_class ? $label : array('label' => $label, 'status_class' => $status_class);
5158
+ }
5159
+
5160
+ /**
5161
+ * Get Label for booking verification
5162
+ * @author Webnus <info@webnus.biz>
5163
+ * @param int $verified
5164
+ * @return string
5165
+ */
5166
+ public function get_verification_label($verified = 1)
5167
+ {
5168
+ if($verified == '1') $label = __('Verified', 'modern-events-calendar-lite');
5169
+ elseif($verified == '-1') $label = __('Canceled', 'modern-events-calendar-lite');
5170
+ else $label = __('Waiting', 'modern-events-calendar-lite');
5171
+
5172
+ return $label;
5173
+ }
5174
+
5175
+ /**
5176
+ * Added Block Editor Custome Category
5177
+ * @author Webnus <info@webnus.biz>
5178
+ * @param array $categories
5179
+ * @return array
5180
+ */
5181
+ public function add_custom_block_cateogry($categories)
5182
+ {
5183
+ $categories = array_merge(array(array('slug' => 'mec.block.category', 'title' => __('M.E. Calender', 'modern-events-calendar-lite'), 'icon' => 'calendar-alt')), $categories);
5184
+ return $categories;
5185
+ }
5186
+
5187
+ /**
5188
+ * Advanced Repeating MEC Active
5189
+ * @author Webnus <info@webnus.biz>
5190
+ * @param array $days
5191
+ * @param string $item
5192
+ */
5193
+ public function mec_active($days = array(), $item = '')
5194
+ {
5195
+ if(is_array($days) and in_array($item, $days)) echo 'mec-active';
5196
+ }
5197
+
5198
+ /**
5199
+ * Advanced repeat sorting by start of week day number
5200
+ * @author Webnus <info@webnus.biz>
5201
+ * @param int $start_of_week
5202
+ * @param $day
5203
+ * @return string|boolean
5204
+ */
5205
+ public function advanced_repeating_sort_day($start_of_week = 1, $day = 1)
5206
+ {
5207
+ if(func_num_args() < 2) return false;
5208
+
5209
+ $start_of_week = intval($start_of_week);
5210
+ $day = intval($day) == 0 ? intval($day) : intval($day) - 1;
5211
+
5212
+ // Sorting days by start of week day number
5213
+ $days = array('Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat');
5214
+ $s1 = array_splice($days, $start_of_week, count($days));
5215
+ $s2 = array_splice($days, 0, $start_of_week);
5216
+ $merge = array_merge($s1, $s2);
5217
+
5218
+ return $merge[$day];
5219
+ }
5220
+
5221
+ public function get_ical_rrules($event)
5222
+ {
5223
+ $recurrence = array();
5224
+ if(isset($event->mec->repeat) and $event->mec->repeat)
5225
+ {
5226
+ $gmt_offset = $this->get_gmt_offset();
5227
+ $finish = ($event->mec->end != '0000-00-00' ? date('Ymd\THis\Z', strtotime($event->mec->end.' '.$event->time['end'])) : '');
5228
+ $freq = '';
5229
+ $interval = '1';
5230
+ $bysetpos = '';
5231
+ $byday = '';
5232
+ $wkst = '';
5233
+
5234
+ $repeat_type = $event->meta['mec_repeat_type'];
5235
+ $week_day_mapping = array('1'=>'MO', '2'=>'TU', '3'=>'WE', '4'=>'TH', '5'=>'FR', '6'=>'SA', '7'=>'SU');
5236
+
5237
+ if($repeat_type == 'daily')
5238
+ {
5239
+ $freq = 'DAILY';
5240
+ $interval = $event->mec->rinterval;
5241
+ }
5242
+ elseif($repeat_type == 'weekly')
5243
+ {
5244
+ $freq = 'WEEKLY';
5245
+ $interval = ($event->mec->rinterval/7);
5246
+ }
5247
+ elseif($repeat_type == 'monthly') $freq = 'MONTHLY';
5248
+ elseif($repeat_type == 'yearly') $freq = 'YEARLY';
5249
+ elseif($repeat_type == 'weekday')
5250
+ {
5251
+ $mec_weekdays = explode(',', trim($event->mec->weekdays, ','));
5252
+ foreach($mec_weekdays as $mec_weekday) $byday .= $week_day_mapping[$mec_weekday].',';
5253
+
5254
+ $byday = trim($byday, ', ');
5255
+ $freq = 'WEEKLY';
5256
+ }
5257
+ elseif($repeat_type == 'weekend')
5258
+ {
5259
+ $mec_weekdays = explode(',', trim($event->mec->weekdays, ','));
5260
+ foreach($mec_weekdays as $mec_weekday) $byday .= $week_day_mapping[$mec_weekday].',';
5261
+
5262
+ $byday = trim($byday, ', ');
5263
+ $freq = 'WEEKLY';
5264
+ }
5265
+ elseif($repeat_type == 'certain_weekdays')
5266
+ {
5267
+ $mec_weekdays = explode(',', trim($event->mec->weekdays, ','));
5268
+ foreach($mec_weekdays as $mec_weekday) $byday .= $week_day_mapping[$mec_weekday].',';
5269
+
5270
+ $byday = trim($byday, ', ');
5271
+ $freq = 'WEEKLY';
5272
+ }
5273
+ elseif($repeat_type == 'advanced')
5274
+ {
5275
+ $advanced_days = is_array($event->meta['mec_advanced_days']) ? $event->meta['mec_advanced_days'] : array();
5276
+
5277
+ $first_rule = isset($advanced_days[0]) ? $advanced_days[0] : NULL;
5278
+ $ex = explode('.', $first_rule);
5279
+
5280
+ $bysetpos = isset($ex[1]) ? $ex[1] : NULL;
5281
+ $byday_mapping = array('MON'=>'MO', 'TUE'=>'TU', 'WED'=>'WE', 'THU'=>'TH', 'FRI'=>'FR', 'SAT'=>'SA', 'SUN'=>'SU');
5282
+ $byday = $byday_mapping[strtoupper($ex[0])];
5283
+
5284
+ $freq = 'MONTHLY';
5285
+ }
5286
+ elseif($repeat_type == 'custom_days')
5287
+ {
5288
+ $freq = '';
5289
+ $mec_periods = explode(',', trim($event->mec->days, ','));
5290
+
5291
+ $days = '';
5292
+ foreach($mec_periods as $mec_period)
5293
+ {
5294
+ $mec_days = explode(':', trim($mec_period, ': '));
5295
+ $days .= date('Ymd\THis', strtotime($mec_days[0].' '.$event->time['start'])).$gmt_offset.'/'.date('Ymd\THis', strtotime($mec_days[1].' '.$event->time['end'])).$gmt_offset.',';
5296
+ }
5297
+
5298
+ // Add RDATE
5299
+ $recurrence[] = trim('RDATE;VALUE=PERIOD:'.trim($days, ', '), '; ');
5300
+ }
5301
+
5302
+ // Add RRULE
5303
+ if(trim($freq))
5304
+ {
5305
+ $rrule = 'RRULE:FREQ='.$freq.';'
5306
+ .($interval > 1 ? 'INTERVAL='.$interval.';' : '')
5307
+ .(($finish != '0000-00-00' and $finish != '') ? 'UNTIL='.$finish.';' : '')
5308
+ .($wkst != '' ? 'WKST='.$wkst.';' : '')
5309
+ .($bysetpos != '' ? 'BYSETPOS='.$bysetpos.';' : '')
5310
+ .($byday != '' ? 'BYDAY='.$byday.';' : '');
5311
+
5312
+ $recurrence[] = trim($rrule, '; ');
5313
+ }
5314
+
5315
+ if(trim($event->mec->not_in_days))
5316
+ {
5317
+ $mec_not_in_days = explode(',', trim($event->mec->not_in_days, ','));
5318
+
5319
+ $not_in_days = '';
5320
+ foreach($mec_not_in_days as $mec_not_in_day) $not_in_days .= date('Ymd', strtotime($mec_not_in_day)).',';
5321
+
5322
+ // Add EXDATE
5323
+ $recurrence[] = trim('EXDATE;VALUE=DATE:'.trim($not_in_days, ', '), '; ');
5324
+ }
5325
+ }
5326
+
5327
+ return $recurrence;
5328
+ }
5329
+
5330
+ public static function get_upcoming_events($limit = 12)
5331
+ {
5332
+ MEC::import('app.skins.list', true);
5333
+
5334
+ // Get list skin
5335
+ $list = new MEC_skin_list();
5336
+
5337
+ // Attributes
5338
+ $atts = array(
5339
+ 'show_past_events'=>0,
5340
+ 'start_date_type'=>'today',
5341
+ 'sk-options'=> array(
5342
+ 'list' => array('limit'=>$limit)
5343
+ ),
5344
+ );
5345
+
5346
+ // Initialize the skin
5347
+ $list->initialize($atts);
5348
+
5349
+ // Fetch the events
5350
+ $list->fetch();
5351
+
5352
+ return $list->events;
5353
+ }
5354
+
5355
+ /**
5356
+ * Do the shortcode and return its output
5357
+ * @author Webnus <info@webnus.biz>
5358
+ * @param integer $shortcode_id
5359
+ * @return string
5360
+ */
5361
+ public static function get_shortcode_events($shortcode_id)
5362
+ {
5363
+ // Get Render
5364
+ $render = new MEC_render();
5365
+ $atts = apply_filters('mec_calendar_atts', $render->parse($shortcode_id, array()));
5366
+
5367
+ $skin = isset($atts['skin']) ? $atts['skin'] : $render->get_default_layout();
5368
+
5369
+ $path = MEC::import('app.skins.'.$skin, true, true);
5370
+ $skin_path = apply_filters('mec_skin_path', $skin);
5371
+
5372
+ if($skin_path != $skin and $render->file->exists($skin_path)) $path = $skin_path;
5373
+ if(!$render->file->exists($path))
5374
+ {
5375
+ return __('Skin controller does not exist.', 'modern-events-calendar-lite');
5376
+ }
5377
+
5378
+ include_once $path;
5379
+
5380
+ $skin_class_name = 'MEC_skin_'.$skin;
5381
+
5382
+ // Create Skin Object Class
5383
+ $SKO = new $skin_class_name();
5384
+
5385
+ // Initialize the skin
5386
+ $SKO->initialize($atts);
5387
+
5388
+ // Fetch the events
5389
+ $SKO->fetch();
5390
+
5391
+ // Return the Events
5392
+ return $SKO->events;
5393
+ }
5394
+
5395
+ /**
5396
+ * User limited for booking a event
5397
+ * @author Webnus <info@webnus.biz>
5398
+ * @param string $user_email
5399
+ * @param array $ticket_info
5400
+ * @param integer $limit
5401
+ * @return array
5402
+ */
5403
+ public function booking_permitted($user_email, $ticket_info = array(), $limit, $booking_count = false)
5404
+ {
5405
+ if(!is_array($ticket_info) or is_array($ticket_info) and count($ticket_info) < 2) return false;
5406
+
5407
+ $user_email = sanitize_email($user_email);
5408
+ $user = get_user_by('email', $user_email);
5409
+ $user_id = (isset($user->data) and isset($user->data->ID)) ? $user->data->ID : 0;
5410
+
5411
+ // It's the first booking of this email
5412
+ if(!$user_id) return true;
5413
+
5414
+ $event_id = isset($ticket_info['event_id']) ? intval($ticket_info['event_id']) : 0;
5415
+ $count = isset($ticket_info['count']) ? intval($ticket_info['count']) : 0;
5416
+
5417
+ $date = isset($ticket_info['date']) ? $ticket_info['date'] : '';
5418
+ list($year, $month, $day) = explode('-', $date);
5419
+
5420
+ $permission = true;
5421
+ $query = new WP_Query(array
5422
+ (
5423
+ 'post_type'=>$this->get_book_post_type(),
5424
+ 'author'=>$user_id,
5425
+ 'posts_per_page'=>-1,
5426
+ 'post_status'=>array('publish', 'pending', 'draft', 'future', 'private'),
5427
+ 'year'=>$year,
5428
+ 'monthnum'=>$month,
5429
+ 'day'=>$day,
5430
+ 'meta_query'=>array
5431
+ (
5432
+ array('key'=>'mec_event_id', 'value'=>$event_id, 'compare'=>'='),
5433
+ array('key'=>'mec_verified', 'value'=>'-1', 'compare'=>'!='), // Don't include canceled bookings
5434
+ array('key'=>'mec_confirmed', 'value'=>'-1', 'compare'=>'!='), // Don't include rejected bookings
5435
+ )
5436
+ ));
5437
+
5438
+ $bookings = 0;
5439
+ if($query->have_posts())
5440
+ {
5441
+ while($query->have_posts())
5442
+ {
5443
+ $query->the_post();
5444
+
5445
+ $ticket_ids_string = trim(get_post_meta(get_the_ID(), 'mec_ticket_id', true), ', ');
5446
+ $ticket_ids_count = count(explode(',', $ticket_ids_string));
5447
+
5448
+ $bookings += $ticket_ids_count;
5449
+ }
5450
+ }
5451
+
5452
+ if(($bookings + $count) > $limit) $permission = false;
5453
+
5454
+ return array("booking_count" => $bookings, "permission" => $permission);
5455
+ }
5456
+
5457
+ /**
5458
+ * Check Has Sold Out Ticket
5459
+ * @author Webnus <info@webnus.biz>
5460
+ * @param string $user_id
5461
+ * @param array $ticket_info
5462
+ * @param string $mode
5463
+ * @return boolean
5464
+ */
5465
+ public function is_soldout($event_id, $event_start_date)
5466
+ {
5467
+ if(func_num_args() < 2) return;
5468
+
5469
+ $book = $this->getBook();
5470
+
5471
+ $event_id = (isset($event_id)) ? intval($event_id) : 0;
5472
+ $event_start_date = (isset($event_start_date) and trim($event_start_date)) ? trim($event_start_date) : '';
5473
+
5474
+ $is_soldout = $book->get_tickets_availability($event_id, $event_start_date);
5475
+
5476
+ return (isset($is_soldout) and current($is_soldout) === 0) ? true : false;
5477
+ }
5478
+
5479
+ /**
5480
+ * Add Query String To URL
5481
+ * @param string $url
5482
+ * @param array $key
5483
+ * @param string $value
5484
+ * @resourse wp-mix.com
5485
+ * @return string
5486
+ */
5487
+ public function add_query_string($url, $key, $value)
5488
+ {
5489
+ $url = preg_replace('/([?&])'. $key .'=.*?(&|$)/i', '$1$2$4', $url);
5490
+
5491
+ if(substr($url, strlen($url) - 1) == "?" or substr($url, strlen($url) - 1) == "&")
5492
+ $url = substr($url, 0, -1);
5493
+
5494
+ if(strpos($url, '?') === false)
5495
+ {
5496
+ return ($url .'?'. $key .'='. $value);
5497
+ }
5498
+ else
5499
+ {
5500
+ return ($url .'&'. $key .'='. $value);
5501
+ }
5502
+ }
5503
+
5504
+ /**
5505
+ * Check Is DateTime Format Validation
5506
+ * @param string $format
5507
+ * @param string $date
5508
+ * @return boolean
5509
+ */
5510
+ public function check_date_time_validation($format, $date)
5511
+ {
5512
+ if(func_num_args() < 2) return;
5513
+
5514
+ $check = DateTime::createFromFormat($format, $date);
5515
+
5516
+ return $check && $check->format($format) === $date;
5517
+ }
5518
  }
changelog.txt CHANGED
@@ -1,4 +1,7 @@
1
- v 4.8.2 - 24 November 2019
 
 
 
2
  - Added: The ticket variations in CSV and Excel exports in Backend and "Front-end Event Submission" (pro)
3
  - Added: Timeline view
4
  - Added: Geolocation feature for map feature of list and grid skins (pro)
1
+ v 4.8.3 - 25 November 2019
2
+ - Fixed: Headers already sent warning
3
+
4
+ v 4.8.2 - 25 November 2019
5
  - Added: The ticket variations in CSV and Excel exports in Backend and "Front-end Event Submission" (pro)
6
  - Added: Timeline view
7
  - Added: Geolocation feature for map feature of list and grid skins (pro)
modern-events-calendar-lite.php CHANGED
@@ -4,7 +4,7 @@
4
  * Plugin URI: http://webnus.net/modern-events-calendar/
5
  * Description: An awesome plugin for events calendar
6
  * Author: Webnus Team
7
- * Version: 4.8.2
8
  * Text Domain: modern-events-calendar-lite
9
  * Domain Path: /languages
10
  * Author URI: http://webnus.net
@@ -31,7 +31,7 @@ if(!defined('MECEXEC'))
31
  define('MEC_BASENAME', plugin_basename(__FILE__)); // modern-events-calendar/mec.php
32
 
33
  /** Plugin Version **/
34
- define('MEC_VERSION', '4.8.2');
35
 
36
  /** Include Webnus MEC class if not included before **/
37
  if(!class_exists('MEC')) require_once MEC_ABSPATH.'mec-init.php';
4
  * Plugin URI: http://webnus.net/modern-events-calendar/
5
  * Description: An awesome plugin for events calendar
6
  * Author: Webnus Team
7
+ * Version: 4.8.3
8
  * Text Domain: modern-events-calendar-lite
9
  * Domain Path: /languages
10
  * Author URI: http://webnus.net
31
  define('MEC_BASENAME', plugin_basename(__FILE__)); // modern-events-calendar/mec.php
32
 
33
  /** Plugin Version **/
34
+ define('MEC_VERSION', '4.8.3');
35
 
36
  /** Include Webnus MEC class if not included before **/
37
  if(!class_exists('MEC')) require_once MEC_ABSPATH.'mec-init.php';
readme.txt CHANGED
@@ -4,7 +4,7 @@ Donate link: https://webnus.net
4
  Tags: Event, Events, Calendar, Booking, Schedule, Organizer, Venue
5
  Requires at least: 4.0.0
6
  Tested up to: 5.3.0
7
- Stable tag: 4.8.2
8
  Requires PHP: 5.6
9
  License: GPLv2 or later
10
  License URI: https://www.gnu.org/licenses/gpl-2.0.html
@@ -328,7 +328,10 @@ You can see [plugin documentation here](https://webnus.net/dox/modern-events-cal
328
  33. WordPress Event Calendar - Shortcode edit page
329
 
330
  == Changelog ==
331
- = 4.8.2 - 24 November 2019 =
 
 
 
332
  - Added: The ticket variations in CSV and Excel exports in Backend and "Front-end Event Submission" (pro)
333
  - Added: Timeline view
334
  - Added: Geolocation feature for map feature of list and grid skins (pro)
4
  Tags: Event, Events, Calendar, Booking, Schedule, Organizer, Venue
5
  Requires at least: 4.0.0
6
  Tested up to: 5.3.0
7
+ Stable tag: 4.8.3
8
  Requires PHP: 5.6
9
  License: GPLv2 or later
10
  License URI: https://www.gnu.org/licenses/gpl-2.0.html
328
  33. WordPress Event Calendar - Shortcode edit page
329
 
330
  == Changelog ==
331
+ = 4.8.3 - 25 November 2019 =
332
+ - Fixed: Headers already sent warning
333
+
334
+ = 4.8.2 - 25 November 2019 =
335
  - Added: The ticket variations in CSV and Excel exports in Backend and "Front-end Event Submission" (pro)
336
  - Added: Timeline view
337
  - Added: Geolocation feature for map feature of list and grid skins (pro)