1: <?php
2: /**
3: * Plugin Name: Event Post
4: * Plugin URI: https://event-post.com?mtm_campaign=wp-plugin&mtm_kwd=event-post&mtm_medium=dashboard&mtm_source=plugin-uri
5: * Description: Add calendar and/or geolocation metadata on any posts.
6: * Version: 6.1.3
7: * Author: N.O.U.S. Open Useful and Simple
8: * Contributors: bastho, sabrinaleroy, unecologeek, agencenous
9: * Author URI: https://apps.avecnous.eu/?mtm_campaign=wp-plugin&mtm_kwd=event-post&mtm_medium=dashboard&mtm_source=author
10: * License: GPLv2
11: * Text Domain: event-post
12: * Domain Path: /languages/
13: * Tags: Post,posts,event,date,geolocalization,gps,widget,map,openstreetmap,EELV,calendar,agenda,blocks
14: *
15: * @package event-post
16: */
17:
18: if ( ! defined( 'ABSPATH' ) ) exit;
19:
20: global $EventPost;
21: $EventPost = new EventPost();
22:
23: $EventPost_cache=array();
24:
25: function EventPost(){
26: global $EventPost;
27: return $EventPost;
28: }
29: /**
30: * Hexadecimal color without its leading "#", or an empty string when the value is not a color.
31: *
32: * Every color printed by the plugin goes through here, so a stored value that is
33: * not a hex color can never reach a style or data attribute.
34: *
35: * @param mixed $color
36: * @return string
37: */
38: function event_post_format_color($color){
39: $color = ltrim(trim((string) $color), '#');
40: return preg_match('/^[0-9a-fA-F]{3}(?:[0-9a-fA-F]{3})?$/', $color) ? $color : '';
41: }
42: function event_post_get_all_terms($post_id){
43: $taxonomies= get_taxonomies('','names');
44:
45: return wp_get_post_terms($post_id, $taxonomies);
46: }
47:
48:
49: /**
50: * The main class where everything begins.
51: *
52: * Add calendar and/or geolocation metadata on posts
53: */
54: class EventPost {
55: /**
56: * The current version
57: *
58: * Must be kept in sync with the `Version:` plugin header above: `bin/bump`
59: * only rewrites header-style declarations, not this literal.
60: *
61: * @var string
62: */
63: public $version = '6.1.2';
64:
65: // --------------------------------------------------------------------------------
66: // Post metas
67:
68: /**
69: * The meta name for event start date
70: *
71: * @var string
72: */
73: public $META_START = 'event_begin';
74:
75: /**
76: * The meta name for event end date
77: *
78: * @var string
79: */
80: public $META_END = 'event_end';
81:
82: /**
83: * The meta name for event color
84: *
85: * @var string
86: */
87: public $META_COLOR = 'event_color';
88:
89: /**
90: * The meta name for event icon
91: *
92: * @var string
93: */
94: public $META_ICON = 'event_icon';
95:
96: // --------------------------------------------------------------------------------
97: // Post metas related to location
98:
99: /**
100: * The meta name for event address
101: *
102: * @var string
103: */
104: public $META_ADD = 'geo_address';
105:
106: /**
107: * The meta name for event latitude
108: *
109: * @var string
110: *
111: * @see http://codex.wordpress.org/Geodata
112: */
113: public $META_LAT = 'geo_latitude';
114:
115: /**
116: * The meta name for event longitude
117: *
118: * @var string
119: *
120: * @see http://codex.wordpress.org/Geodata
121: */
122: public $META_LONG = 'geo_longitude';
123:
124: /**
125: * The meta name for event location
126: *
127: * @var string
128: *
129: * @see https://schema.org/location
130: */
131: public $META_VIRTUAL_LOCATION = 'event_virtual_location';
132:
133: // --------------------------------------------------------------------------------
134: // Post metas related to status
135:
136: /**
137: * The meta name for event status
138: *
139: * @var string
140: *
141: * @see https://schema.org/eventStatus
142: */
143: public $META_STATUS = 'event_status';
144:
145: /**
146: * The meta name for event attendance mode
147: *
148: * @var string
149: *
150: * @see https://schema.org/eventAttendanceMode
151: */
152: public $META_ATTENDANCE_MODE = 'event_attendance_mode';
153:
154: /**
155: * The meta name for event organizer
156: *
157: * @var string
158: *
159: * @see https://schema.org/Organization
160: */
161: public $META_ORGANIZATION = 'event_organization';
162:
163: /**
164: * The meta name for event organizer
165: *
166: * @var string
167: * @see https://schema.org/Offer
168: */
169: public $META_OFFER = 'event_offer';
170:
171: // --------------------------------------------------------------------------------
172: // Usefull variables
173:
174: /**
175: * ID of the current list
176: *
177: * @var int
178: */
179: public $list_id;
180:
181: /**
182: * ID of the current map
183: *
184: * @var int
185: */
186: public $map_id=0;
187:
188: /**
189: * Schema as been outputed or not
190: *
191: * @var bool
192: */
193: private $is_schema_output=false;
194:
195: /**
196: * Month names
197: *
198: * @var array
199: */
200: public $NomDuMois;
201:
202: /**
203: * Week days
204: *
205: * @var array
206: */
207: public $Week;
208:
209: /**
210: * Currencies
211: *
212: * @var array
213: */
214: public $currencies = array();
215:
216: /**
217: * Date format
218: *
219: * @var string
220: */
221: public $dateformat;
222:
223: /**
224: * Pagination
225: *
226: * @var array
227: */
228: private $pagination;
229:
230: /**
231: * Plugin path
232: *
233: * @var string
234: */
235: public $plugin_path;
236:
237: /**
238: * Script suffix
239: *
240: * @var string
241: */
242: private $script_sufix;
243:
244: /**
245: * Settings values
246: *
247: * @var array
248: */
249: public $settings;
250:
251: // --------------------------------------------------------------------------------
252: // Option values
253:
254: /**
255: * Map interractions (from openlayers)
256: *
257: * @var array
258: */
259: public $map_interactions;
260:
261: /**
262: * Fields supported by quick-edit
263: *
264: * @var array
265: */
266: public $quick_edit_fields;
267:
268: /**
269: * Fields supported by bulk-edit
270: *
271: * @var array
272: */
273: public $bulk_edit_fields;
274:
275: /**
276: * Supported attendance modes
277: *
278: * @var array
279: */
280: public $attendance_modes;
281:
282: /**
283: * Supported statuses
284: *
285: * @var array
286: */
287: public $statuses;
288:
289: /**
290: * Default list schema (HTML template)
291: *
292: * @var string
293: */
294: public $default_list_shema;
295:
296: /**
297: * Default timeline schema (HTML template)
298: *
299: * @var string
300: */
301: public $default_timeline_shema;
302:
303: /**
304: * Current list schema (HTML template)
305: *
306: * @var string
307: */
308: public $list_shema;
309:
310: /**
311: * Current timeline schema (HTML template)
312: *
313: * @var string
314: */
315: public $timeline_shema;
316:
317: // Map variables
318: /**
319: * Map tiles
320: *
321: * @var array
322: */
323: public $maps;
324:
325: /**
326: * Dirpath for map tiles
327: *
328: * @var string
329: */
330: public $markpath;
331:
332: /**
333: * Base URL for map tiles
334: *
335: * @var string
336: */
337: public $markurl;
338:
339: // --------------------------------------------------------------------------------
340: // Classes
341:
342: /**
343: * Taxonomies object
344: *
345: * @var \EventPost\Taxonomies
346: */
347: public $Taxonomies;
348:
349: /**
350: * Icons object
351: *
352: * @var \EventPost\Icons
353: */
354: public $DashIcons;
355:
356: /**
357: * Settings object
358: *
359: * @var \EventPost\Settings
360: */
361: public $Settings;
362:
363: /**
364: * Shortcodes object
365: *
366: * @var \EventPost\Shortcodes
367: */
368: public $Shortcodes;
369:
370: /**
371: * Allowed tags in main outputs
372: *
373: * @var array
374: */
375: public $kses_tags;
376:
377:
378: public function __construct() {
379: add_action('init', array(&$this,'init'), 1);
380: add_action('init', array(&$this,'widgets_init'), 10);
381: add_action('init', array(&$this, 'register_widgets'), 30, 1);
382:
383: add_action('save_post', array(&$this, 'save_postdata'));
384: add_filter('dashboard_glance_items', array(&$this, 'dashboard_right_now'));
385:
386: // Scripts
387: add_action( 'admin_init', array(&$this, 'editor_styles'));
388: add_action('admin_enqueue_scripts', array(&$this, 'admin_head'));
389: add_action('admin_print_scripts', array(&$this, 'admin_scripts'));
390: add_action('admin_print_scripts', array(&$this, 'load_scripts'), 1);
391: add_action('wp_enqueue_scripts', array(&$this, 'load_scripts'), 1);
392: add_action('wp_enqueue_scripts', array(&$this, 'load_styles'));
393:
394: // Single
395: add_filter('the_content', array(&$this, 'display_single'), 9999);
396: add_filter('the_title', array(&$this, 'the_title'), 9999, 2);
397: add_action('the_event', array(&$this, 'print_single'));
398: add_action('wp_head', array(&$this, 'single_header'));
399: add_action('wpseo_schema_webpage', array(&$this, 'wpseo_schema_webpage'));
400:
401: // Ajax
402: add_action('wp_ajax_EventPostGetLatLong', array(&$this, 'GetLatLong'));
403: add_action('wp_ajax_EventPostHumanDate', array(&$this, 'HumanDate'));
404: add_action('wp_ajax_EventPostList', array(&$this, 'ajaxlist'));
405: add_action('wp_ajax_EventPostTimeline', array(&$this, 'ajaxTimeline'));
406: add_action('wp_ajax_EventPostNextPage', array(&$this, 'ajaxGetNextPage'));
407: add_action('wp_ajax_nopriv_EventPostNextPage', array(&$this, 'ajaxGetNextPage'));
408: add_action('wp_ajax_EventPostMap', array(&$this, 'ajaxmap'));
409: add_action('wp_ajax_EventPostCalendar', array(&$this, 'ajaxcal'));
410: add_action('wp_ajax_nopriv_EventPostCalendar', array(&$this, 'ajaxcal'));
411: add_action('wp_ajax_EventPostCalendarDate', array(&$this, 'ajaxdate'));
412: add_action('wp_ajax_nopriv_EventPostCalendarDate', array(&$this, 'ajaxdate'));
413:
414: // Calendar publishing
415: add_action('parse_request', array(&$this, 'parse_request'), 100);
416: add_action('wp_ajax_EventPostExport', array(&$this, 'export'));
417: add_action('wp_ajax_nopriv_EventPostExport', array(&$this, 'export'));
418: add_action('wp_ajax_EventPostFeed', array(&$this, 'feed'));
419: add_action('wp_ajax_nopriv_EventPostFeed', array(&$this, 'feed'));
420:
421: // Internal filters
422: add_filter('eventpost_list_shema',array(&$this, 'custom_shema'),10,1);
423:
424: // Quick edit
425: add_action( 'bulk_edit_custom_box', array( &$this, 'bulk_edit' ), 10, 2 );
426: add_action( 'quick_edit_custom_box', array( &$this, 'quick_edit' ), 10, 2 );
427: add_action( 'admin_print_scripts-edit.php', array(&$this, 'scripts_edit') );
428: add_action( 'wp_ajax_inline-save', array(&$this, 'inline_save'), 1 );
429: add_action( 'bulk_edit_posts', array(&$this, 'save_bulkdatas'), 10, 2 );
430: add_filter( 'eventpost_inline_field', array(&$this, 'inline_field_color'), 10, 3);
431: add_filter( 'eventpost_inline_field', array(&$this, 'inline_field_icon'), 10, 3);
432:
433: $inc_path = plugin_dir_path(__FILE__).'inc/';
434: $this->plugin_path = plugin_dir_path(__FILE__);
435: include_once ($inc_path . 'class-settings.php');
436: include_once ($inc_path . 'wrappers.php');
437: include_once ($inc_path . 'deprecated/widget.php');
438: include_once ($inc_path . 'deprecated/widget.cal.php');
439: include_once ($inc_path . 'deprecated/widget.map.php');
440: include_once ($inc_path . 'class-multisite.php');
441: include_once ($inc_path . 'class-shortcodes.php');
442: include_once ($inc_path . 'openweathermap.php');
443: include_once ($inc_path . 'class-children.php');
444: include_once ($inc_path . 'class-icons.php');
445: include_once ($inc_path . 'class-taxonomies.php');
446:
447: $this->DashIcons = new EventPost\Icons();
448: $this->Settings = new EventPost\Settings($this->DashIcons);
449: $this->Taxonomies = new EventPost\Taxonomies($this->DashIcons);
450: }
451:
452: /**
453: * PHP4 constructor
454: */
455: public function EventPost(){
456: $this->__construct();
457: }
458:
459: public function init(){
460: $admin_url = admin_url('admin-ajax.php?action=EventPostFeed');
461: $admin_url = str_replace(site_url(), '', $admin_url);
462: $plugins_url = plugins_url('export/ics.php', __FILE__);
463: $plugins_url = str_replace(site_url(), '', $plugins_url);
464: add_rewrite_rule('event-feed/?', $admin_url , 'top');
465: add_rewrite_rule('eventpost/([0-9]*)\.(ics|vcs)?',$plugins_url, 'top');
466:
467: $this->list_id = 0;
468: $this->NomDuMois = array('', __('Jan', 'event-post'), __('Feb', 'event-post'), __('Mar', 'event-post'), __('Apr', 'event-post'), __('May', 'event-post'), __('Jun', 'event-post'), __('Jul', 'event-post'), __('Aug', 'event-post'), __('Sept', 'event-post'), __('Oct', 'event-post'), __('Nov', 'event-post'), __('Dec', 'event-post'));
469: $this->Week = array(__('Sunday', 'event-post'), __('Monday', 'event-post'), __('Tuesday', 'event-post'), __('Wednesday', 'event-post'), __('Thursday', 'event-post'), __('Friday', 'event-post'), __('Saturday', 'event-post'));
470: $this->attendance_modes = array(
471: 'OfflineEventAttendanceMode' => _x('Physical', 'Attendance Mode', 'event-post'),
472: 'MixedEventAttendanceMode' => _x('Mixed', 'Attendance Mode', 'event-post'),
473: 'OnlineEventAttendanceMode' => _x('Online', 'Attendance Mode', 'event-post'),
474: );
475: $this->statuses = array(
476: 'EventScheduled' => _x('Scheduled', 'Event Status', 'event-post'),
477: 'EventCancelled' => _x('Cancelled', 'Event Status', 'event-post'),
478: 'EventMovedOnline' => _x('Moved Online', 'Event Status', 'event-post'),
479: 'EventPostponed' => _x('Postoned', 'Event Status', 'event-post'),
480: 'EventRescheduled' => _x('Rescheduled', 'Event Status', 'event-post'),
481: 'EventCompleted' => _x('Completed', 'Event Status', 'event-post'),
482: );
483:
484: $this->maps = $this->get_maps();
485: $this->settings = $this->get_settings();
486:
487: do_action('evenpost_init', $this);
488:
489: // Edit
490: add_action('add_meta_boxes', array(&$this, 'add_custom_box'));
491: foreach($this->settings['posttypes'] as $posttype){
492: add_filter('manage_'.$posttype.'_posts_columns', array(&$this, 'columns_head'), 2);
493: add_action('manage_'.$posttype.'_posts_custom_column', array(&$this, 'columns_content'), 10, 2);
494: }
495: $this->Taxonomies->add_fields_to_taxonomies($this->settings['posttypes']);
496:
497: $this->markpath = '';
498: $this->markurl = '';
499: if (!empty($this->settings['markpath']) && !empty($this->settings['markurl'])) {
500: $this->markpath = ABSPATH.'/'.$this->settings['markpath'];
501: $this->markurl = $this->settings['markurl'];
502: } else {
503: // $this->markpath = plugin_dir_path(__FILE__) . 'markers/';
504: // $this->markurl = plugins_url('/markers/', __FILE__);
505: }
506:
507: $this->currencies = include (plugin_dir_path(__FILE__) . 'inc/data/currencies.php');
508:
509: $this->dateformat = str_replace(array('yy', 'mm', 'dd'), array('Y', 'm', 'd'), __('yy-mm-dd', 'event-post'));
510:
511: $this->default_list_shema = apply_filters('eventpost_default_list_shema', array(
512: 'container' => '<%type% class="event_loop %id% %class%" id="%listid%" style="%style%" %attributes%>'.
513: '%list%'.
514: '%pagination%'.
515: '</%type%><!-- .event_loop -->',
516: 'item' => '<%child% class="event_item %class%" data-color="%color%" style="%style%">'.
517: '<a href="%event_link%">'.
518: '%event_thumbnail%'.
519: '<h5>%event_title% </h5>'.
520: '</a>'.
521: '%event_price%'.
522: '%event_date%'.
523: '%event_cat%'.
524: '%event_location%'.
525: '%event_excerpt%'.
526: '</%child%><!-- .event_item -->'
527: ));
528: $this->list_shema = apply_filters('eventpost_list_shema',$this->default_list_shema);
529:
530: $this->default_timeline_shema = apply_filters('eventpost_default_timeline_shema', array(
531: 'container' => '
532: <%type% class="event_loop %id% %class%" id="%listid%" style="%style%" %attributes%>
533: %prev_arrow%
534: <div class="track">
535: %list%
536: </div>
537: %next_arrow%
538: </%type%><!-- .event_loop -->',
539: 'item' => '<%child% class="event_item %class%" data-color="%color%" style="%style%">
540: <div class="anchor" style="background-color:#%color%"></div>
541: %event_date%
542: %event_location%
543: %event_cat%
544: %event_excerpt%
545: <a href="%event_link%">
546: %event_thumbnail%
547: <h5>%event_title%</h5>
548: </a>
549: %event_price%
550: </%child%><!-- .event_item -->'
551: ));
552: $this->timeline_shema = apply_filters('eventpost_timeline_shema',$this->default_timeline_shema);
553:
554: $this->map_interactions=array(
555: 'DragRotate'=>__('Drag Rotate', 'event-post'),
556: 'DoubleClickZoom'=>__('Double Click Zoom', 'event-post'),
557: 'DragPan'=>__('Drag Pan', 'event-post'),
558: 'PinchRotate'=>__('Pinch Rotate', 'event-post'),
559: 'PinchZoom'=>__('Pinch Zoom', 'event-post'),
560: 'KeyboardPan'=>__('Keyboard Pan', 'event-post'),
561: 'KeyboardZoom'=>__('Keyboard Zoom', 'event-post'),
562: 'MouseWheelZoom'=>__('Mouse Wheel Zoom', 'event-post'),
563: 'DragZoom'=>__('Drag Zoom', 'event-post'),
564: );
565:
566: $this->quick_edit_fields = apply_filters('eventpost_quick_edit_fields', array(
567: 'event'=>array(
568: $this->META_START=>__('Begin:', 'event-post'),
569: $this->META_END=>__('End:', 'event-post'),
570: $this->META_COLOR=>__('Color:', 'event-post'),
571: $this->META_ICON=>__('Icon:', 'event-post'),
572: ),
573: 'location'=>array(
574: $this->META_ADD=>__('Address:', 'event-post'),
575: $this->META_LAT=>__('Latitude:', 'event-post'),
576: $this->META_LONG=>__('Longitude:', 'event-post'),
577: ),
578: )
579: );
580: $this->bulk_edit_fields = apply_filters('eventpost_bulk_edit_fields', array(
581: 'event'=>array(
582: $this->META_COLOR=>__('Color:', 'event-post'),
583: $this->META_ICON=>__('Icon:', 'event-post'),
584: ),
585: )
586: );
587:
588: $this->kses_tags = apply_filters('eventpost_kses_tags', json_decode(
589: file_get_contents(plugin_dir_path(__FILE__).'inc/data/kses-tags.json'),
590: true
591: ));
592:
593:
594: }
595:
596: /**
597: * Init all variables when WP is ready
598: *
599: * @action evenpost_init
600: * @filter eventpost_default_list_shema
601: * @filter eventpost_list_shema
602: */
603: public function widgets_init(){
604: $this->Shortcodes = new EventPost\Shortcodes();
605:
606: if(function_exists('register_block_type')){
607: $block_path = plugin_dir_path(__FILE__).'inc/blocks/';
608: include_once ($block_path . 'eventslist.php');
609: include_once ($block_path . 'eventstimeline.php');
610: include_once ($block_path . 'eventsmap.php');
611: include_once ($block_path . 'eventscalendar.php');
612: include_once ($block_path . 'eventdetails.php');
613: }
614:
615:
616: // WooCommerce
617: if (class_exists('WooCommerce') && in_array('product', $this->settings['posttypes'])) {
618: include_once (plugin_dir_path(__FILE__).'inc/woocommerce.php');
619: }
620: }
621:
622: public function register_widgets(){
623: register_widget('EventPost_List');
624: register_widget('EventPost_Map');
625: register_widget('EventPost_Cal');
626: }
627:
628: /**
629: * Usefull hexadecimal to decimal converter. Returns an array of RGB from a given hexadecimal color.
630: *
631: * @param string $color
632: *
633: * @return array $color($R, $G, $B)
634: */
635: public function hex2dec($color = '000000') {
636: $tbl_color = array();
637: if(!is_string($color) || empty($color)){
638: $color = '000000';
639: }
640: if (substr($color, 0, 1)!='#'){
641: $color = '#' . $color;
642: }
643: $tbl_color['R'] = hexdec(substr($color, 1, 2));
644: $tbl_color['G'] = hexdec(substr($color, 3, 2));
645: $tbl_color['B'] = hexdec(substr($color, 5, 2));
646: return $tbl_color;
647: }
648:
649: /**
650: * Fetch all registered image sizes
651: *
652: * @global array $_wp_additional_image_sizes
653: *
654: * @return array
655: */
656: function get_thumbnail_sizes(){
657: global $_wp_additional_image_sizes;
658: $sizes = array('thumbnail', 'medium', 'large', 'full');
659: foreach(array_keys($_wp_additional_image_sizes) as $size){
660: $sizes[]=$size;
661: }
662: return $sizes;
663: }
664:
665: /**
666: * Get blog settings, load and saves default settings if needed. Can be filterred using
667: *
668: * @example `<?php add_filter('eventpost_getsettings', 'some_function'); ?>`
669: *
670: * @action eventpost_getsettings_action
671: * @filter eventpost_getsettings
672: *
673: * @return array
674: */
675: public function get_settings() {
676: $ep_settings = $this->Settings->get_settings();
677: return apply_filters('eventpost_getsettings', $ep_settings);
678: }
679:
680: /**
681: * Checks if HTML schemas are not empty
682: *
683: * @param array $shema
684: *
685: * @return array
686: */
687: public function custom_shema($shema){
688: if(!empty($this->settings['container_shema'])){
689: $shema['container']=$this->settings['container_shema'];
690: }
691: if(!empty($this->settings['item_shema'])){
692: $shema['item']=$this->settings['item_shema'];
693: }
694: return $shema;
695: }
696:
697: /**
698: * Parse the maps.json file. Custom maps can be added by using the `eventpost_getsettings` filter like the following example:
699: *
700: * ```
701: * <?php
702: * add_filter('eventpost_getsettings', 'map_function');
703: * function map_function($maps){
704: * array_push($maps, array(
705: * 'name'=>'Myt custom map',
706: * 'id'=>'custom_map',
707: * 'urls'=>array(
708: * 'http://a.customurl.org/{z}/{x}/{y}.png',
709: * 'http://b.customurl.org/{z}/{x}/{y}.png',
710: * 'http://c.customurl.org/{z}/{x}/{y}.png',
711: * )
712: * ));
713: * return $maps;
714: * }
715: * ?>
716: * ```
717: *
718: * @filter eventpost_maps
719: *
720: * @return array of map arrays ['name', 'id', 'urls']
721: */
722: public function get_maps() {
723: $maps = array();
724: $filename = plugin_dir_path(__FILE__) . 'maps.json';
725: if (is_file($filename) && (false !== $json = json_decode(file_get_contents($filename)))) {
726: // Convert objects to array to ensure retrocompatibility
727: $arrays = array();
728: foreach($json as $map){
729: $arrays[$map->id] = (array) $map;
730: }
731: $maps = apply_filters('eventpost_maps', $arrays);
732: }
733: return $maps;
734: }
735:
736: /**
737: * Get colors
738: *
739: * @return array
740: */
741: public function get_colors() {
742: $colors = array();
743: if (is_dir($this->markpath)) {
744: $files = scandir($this->markpath);
745: foreach ($files as $file) {
746: if (substr($file, -4) == '.png') {
747: $colors[substr($file, 0, -4)] = $this->markurl . $file;
748: }
749: }
750: }
751: return $colors;
752: }
753:
754: /**
755: * Get color of a post
756: *
757: * @param int $post_id
758: * @param bool $default
759: * @param bool $check_taxo
760: *
761: * @return string color
762: */
763: public function get_post_color($post_id, $default = false, $check_taxo = false) {
764: $color = get_post_meta($post_id, $this->META_COLOR,true);
765: if($color && !empty($color)){
766: return event_post_format_color($color);
767: }else{
768: if($check_taxo){
769: foreach(event_post_get_all_terms($post_id) as $term){
770: $taxo_color = $this->Taxonomies->get_taxonomy_color($term->term_id);
771: if($taxo_color){
772: return event_post_format_color($taxo_color);
773: }
774: }
775: }
776: }
777: return event_post_format_color($default);
778: }
779:
780: /**
781: * Get icon of a post
782: *
783: * @param int $post_id
784: * @param bool $default
785: * @param bool $check_taxo
786: *
787: * @return string|false icon
788: */
789: public function get_post_icon($post_id, $default = false, $check_taxo = false) {
790: $icon = get_post_meta($post_id, $this->META_ICON,true);
791: if($icon && !empty($icon)){
792: return $icon;
793: }else{
794: if($check_taxo){
795: foreach(event_post_get_all_terms($post_id) as $term){
796: $taxo_icon = $this->Taxonomies->get_taxonomy_icon($term->term_id);
797: if($taxo_icon){
798: return event_post_format_color($taxo_icon);
799: }
800: }
801: }
802: }
803: return $default;
804: }
805:
806: /**
807: * Get the URL of a marker
808: *
809: * @param string $color
810: *
811: * @return sring
812: */
813: public function get_marker($color) {
814: if (is_file($this->markpath . $color . '.png')) {
815: return $this->markurl . $color . '.png';
816: }
817: return "";
818: }
819:
820: /**
821: * Enqueue CSS files
822: */
823: public function load_styles($deps = null) {
824: //CSS
825: if(!empty($this->settings['customcss'])){
826: wp_enqueue_style('event-post-custom', $this->settings['customcss']);
827: }
828: elseif(is_file(get_stylesheet_directory().'/event-post.css') || is_file(get_template_directory().'/event-post.css')){
829: wp_enqueue_style('event-post-custom', get_theme_file_uri('event-post.css'));
830: }
831: else{
832: wp_register_style('event-post', plugins_url('/build/front/front.css', __FILE__), $deps, filemtime( "{$this->plugin_path}/build/front/front.css" ));
833: wp_enqueue_style('event-post');
834: }
835:
836: // Lib scripts
837: wp_enqueue_style('dashicons', includes_url('/css/dashicons.min.css'));
838: }
839:
840: /**
841: * Enqueue Editor style
842: */
843: public function editor_styles() {
844: add_editor_style( plugins_url('/build/front/front.css', __FILE__) );
845: }
846:
847: /**
848: * Enqueue JS files
849: */
850: public function load_scripts() {
851: wp_enqueue_script('event-post', plugins_url('/build/front/front.js', __FILE__), array(), filemtime( "{$this->plugin_path}/build/front/front.js" ), true);
852: $maps = $this->maps;
853: foreach($maps as $m=>$map){
854: if(isset($map['api_param']) && $this->settings['tile_api_key']){
855: foreach($map['urls'] as $i=>$url){
856: $maps[$m]['urls'][$i] = add_query_arg($map['api_param'], $this->settings['tile_api_key'], $url);
857: }
858: }
859: }
860: wp_add_inline_script('event-post', 'var EventPost = EventPost || {}; EventPost.front='.wp_json_encode(array(
861: 'scripts' => array(
862: 'map' => plugins_url('/build/map/event-map.js', __FILE__)
863: ),
864: 'imgpath' => plugins_url('/img/', __FILE__),
865: 'maptiles' => $maps,
866: 'defaulttile' => $this->settings['tile'],
867: 'zoom' => $this->settings['zoom'],
868: 'ajaxurl' => admin_url() . 'admin-ajax.php',
869: 'map_interactions'=>$this->map_interactions,
870: )), 'before');
871: }
872: /**
873: * Enqueue JS files for maps
874: */
875: public function load_map_scripts() {
876: $this->load_styles(array('event-post-map'));
877: // JS
878: if(is_admin()){
879: $this->admin_scripts(array('jquery', 'event-post-map'));
880: }
881: }
882:
883: /**
884: * Enqueue CSS files in admin
885: */
886: public function admin_head() {
887: $page = basename($_SERVER['SCRIPT_NAME']);
888: if( $page!='post-new.php' && $page!='edit-tags.php' && !($page=='post.php' && filter_input(INPUT_GET, 'action')=='edit') && !($page=='options-general.php' && filter_input(INPUT_GET, 'page')=='event-settings') ){
889: return;
890: }
891: wp_enqueue_style('event-post-admin', plugins_url('/build/admin/admin.css', __FILE__), false, filemtime( "{$this->plugin_path}/build/admin/admin.css" ));
892: }
893:
894: /**
895: * Enqueue JS files in admin
896: */
897: public function admin_scripts($deps = array('jquery'), $force=false) {
898: $page = basename($_SERVER['SCRIPT_NAME']);
899: if(!$force &&
900: $page!='post-new.php' &&
901: $page!='edit-tags.php' &&
902: $page!='term.php' &&
903: !($page=='post.php' && filter_input(INPUT_GET, 'action')=='edit') &&
904: !($page=='options-general.php' && filter_input(INPUT_GET, 'page')=='event-settings')
905: ){
906: return;
907: }
908: wp_enqueue_script('jquery');
909: wp_enqueue_script('jquery-effects-core');
910: wp_enqueue_script('jquery-effects-shake');
911: wp_enqueue_style( 'wp-color-picker');
912: wp_enqueue_script( 'wp-color-picker');
913: if(!is_array($deps)){
914: $deps = array('jquery','wp-color-picker');
915: }
916: if($this->settings['datepicker']=='simple' || !is_admin() || (isset($_GET['page']) && $_GET['page']=='event-settings')){
917: wp_enqueue_script('jquery-ui-datepicker');
918: $deps[] = 'jquery-ui-datepicker';
919: }
920: wp_enqueue_script('event-post-admin', plugins_url('/build/admin/admin.js', __FILE__), $deps, filemtime( "{$this->plugin_path}/build/admin/admin.js" ), true);
921: $language = get_bloginfo('language');
922: if (strpos($language, '-') > -1) {
923: $language = strtolower(substr($language, 0, 2));
924: }
925: wp_add_inline_script('event-post-admin', 'var EventPost = EventPost || {}; EventPost.admin='.wp_json_encode(array(
926: 'ajaxurl' => admin_url('admin-ajax.php'),
927: 'imgpath' => plugins_url('/img/', __FILE__),
928: 'date_choose' => __('Choose', 'event-post'),
929: 'date_format' => __('yy-mm-dd', 'event-post'),
930: 'more_icons' => __('More icons', 'event-post'),
931: 'pick_a_date'=>__('Pick a date','event-post'),
932: 'use_current_location'=>__('Use my current location','event-post'),
933: 'start_drag'=>__('Click to<br>drag the map<br>and change location','event-post'),
934: 'empty_address'=>__('Be kind to fill a non empty address:)', 'event-post'),
935: 'search'=>__('Type an address', 'event-post'),
936: 'search_button'=>__('Search', 'event-post'),
937: 'geocoding_attribution'=>__('Geocoding by <a href="https://nominatim.openstreetmap.org/" target="_blank">OpenStreetmap Nominatim</a>', 'event-post'),
938: 'stop_drag'=>_x('Done','Stop allowing to drag the map', 'event-post'),
939: 'datepickeri18n'=>array(
940: // Translators: %1$s is the month name, %2$s is the day number, %3$s is the year, %4$s is the hour, %5$s is the minute
941: 'order'=>__( '%1$s %2$s, %3$s @ %4$s:%5$s', 'event-post'),
942: 'day'=>__('Day', 'event-post'),
943: 'month'=>__('Month', 'event-post'),
944: 'year'=>__('Day', 'event-post'),
945: 'hour'=>__('Hour', 'event-post'),
946: 'minute'=>__('Minute', 'event-post'),
947: 'ok'=>__('OK', 'event-post'),
948: 'cancel'=>__('Cancel', 'event-post'),
949: 'remove'=>__('Remove', 'event-post'),
950: 'edit'=>__('Edit', 'event-post'),
951: 'months'=>$this->NomDuMois,
952: ),
953: 'META_START' => $this->META_START,
954: 'META_END' => $this->META_END,
955: 'META_ADD' => $this->META_ADD,
956: 'META_LAT' => $this->META_LAT,
957: 'META_LONG' => $this->META_LONG,
958: 'META_STATUS' => $this->META_STATUS,
959: 'META_ATTENDANCE_MODE' => $this->META_ATTENDANCE_MODE,
960: 'lang'=>$language,
961: 'maptiles' => $this->maps,
962: 'defaulttile' => $this->settings['tile'],
963: 'palette' => $this->get_theme_palette("hex"),
964: 'available_images' => $this->get_colors(),
965: )));
966: }
967: function scripts_edit() {
968: // load only when editing a supported post type
969: $current_post_type = isset($_GET['post_type']) ? $_GET['post_type'] : 'post';
970: if ( in_array( $current_post_type, $this->settings['posttypes'] ) ) {
971: wp_enqueue_script( 'eventpost-inline-edit', plugins_url( 'build/admin/inline-edit.js', __FILE__ ), array( 'jquery', 'inline-edit-post' ), '', true );
972: wp_add_inline_script('eventpost-inline-edit', 'var EventPost = EventPost || {}; EventPost.inlineEdit='.wp_json_encode(array(
973: 'quick'=>$this->quick_edit_fields,
974: 'bulk'=>$this->bulk_edit_fields,
975: )));
976: }
977: }
978:
979: function get_rich_result($event){
980: /*
981: * https://search.google.com/test/rich-results
982: {
983: "@context": "https://schema.org",
984: "@type": "Event",
985: "name": "The Adventures of Kira and Morrison",
986: "startDate": "2025-07-21T19:00",
987: "endDate": "2025-07-21T23:00",
988: "eventStatus": "https://schema.org/EventScheduled",
989: "eventAttendanceMode": "https://schema.org/OnlineEventAttendanceMode",
990: "location": {
991: "@type": "VirtualLocation",
992: "url": "https://operaonline.stream5.com/"
993: },
994: "image": [
995: "https://example.com/photos/1x1/photo.jpg",
996: "https://example.com/photos/4x3/photo.jpg",
997: "https://example.com/photos/16x9/photo.jpg"
998: ],
999: "description": "The Adventures of Kira and Morrison is coming to Snickertown in a can’t miss performance.",
1000: "offers": {
1001: "@type": "Offer",
1002: "url": "https://www.example.com/event_offer/12345_201803180430",
1003: "price": "30",
1004: "priceCurrency": "USD",
1005: "availability": "https://schema.org/InStock",
1006: "validFrom": "2024-05-21T12:00"
1007: },
1008: "performer": {
1009: "@type": "PerformingGroup",
1010: "name": "Kira and Morrison"
1011: }
1012: }
1013: */
1014: $location_virtual = array(
1015: '@type'=>'VirtualLocation',
1016: 'url'=>$event->virtual_location,
1017: );
1018: $physical_location = array(
1019: '@type'=>'place',
1020: 'name'=>$event->address,
1021: 'address'=>$event->address,
1022: 'geo'=>array(
1023: '@type'=>'GeoCoordinates',
1024: 'latitude'=>$event->lat,
1025: 'longitude'=>$event->long,
1026: ),
1027: );
1028: $min = 60 * get_option('gmt_offset');
1029: $sign = $min < 0 ? "-" : "+";
1030: $absmin = abs($min);
1031: $gmt_offset = sprintf("%s%02d:%02d", $sign, $absmin/60, $absmin%60);
1032: $time_format = (is_numeric($event->time_start) && is_numeric($event->time_end) && date('H:i', $event->time_start) != date('H:i', $event->time_end) && date('H:i', $event->time_start) != '00:00' && date('H:i', $event->time_end) != '00:00') ? 'Y-m-d\Th:i:00'.$gmt_offset : 'Y-m-d';
1033:
1034: $rich_data = array(
1035: '@context'=>'https://schema.org',
1036: '@type'=>'event',
1037: 'name'=>$event->post_title,
1038: 'datePublished'=>str_replace(' ', 'T', $event->post_date_gmt).$gmt_offset,
1039: 'dateModified'=>str_replace(' ', 'T', $event->post_modified_gmt).$gmt_offset,
1040: 'startDate'=>$event->time_start ? date($time_format, $event->time_start) : null,
1041: 'endDate'=>$event->time_end ? date($time_format, $event->time_end) : null,
1042: 'eventStatus'=>$event->status,
1043: 'eventAttendanceMode'=>$event->attendance_mode,
1044: 'location'=> ($event->attendance_mode == 'MixedEventAttendanceMode') ? array($location_virtual,$physical_location) : ($event->attendance_mode == 'OnlineEventAttendanceMode' ? $location_virtual : $physical_location),
1045: 'image'=> has_post_thumbnail($event->ID) ? array(
1046: get_the_post_thumbnail_url($event->ID, 'post-thumbnail'),
1047: get_the_post_thumbnail_url($event->ID, 'medium'),
1048: get_the_post_thumbnail_url($event->ID, 'large'),
1049: get_the_post_thumbnail_url($event->ID, 'full'),
1050: ) : null,
1051: 'description'=>$event->description,
1052: );
1053: if(!empty($event->organization)){
1054: $rich_data['organizer'] = array(
1055: '@type'=>'Organization',
1056: 'name'=>$event->organization,
1057: );
1058: }
1059: if(!empty($event->offer)){
1060: $rich_data['offers'] = array(
1061: '@type'=>'Offer',
1062: // 'availability'=>$event->availability,
1063: // 'validFrom'=>date($time_format, $event->time_start),
1064: );
1065: if(!empty($event->offer['url'])){
1066: $rich_data['offers']['url'] = $event->offer['url'];
1067: }
1068: if(!empty($event->offer['price'])){
1069: $rich_data['offers']['price'] = $event->offer['price'];
1070: }
1071: if(!empty($event->offer['currency'])){
1072: $rich_data['offers']['priceCurrency'] = $event->offer['currency'];
1073: }
1074: }
1075:
1076: return apply_filters('event-post-rich-result', $rich_data, $event);
1077: }
1078:
1079: function wpseo_schema_webpage($rich_result){
1080: $event = $this->retreive();
1081: if ($event != false){
1082: if ($event->time_start != '' && $event->time_end != '') {
1083: $rich_result = array_merge($rich_result, $this->get_rich_result($event));
1084: }
1085: $this->is_schema_output = true;
1086: }
1087: return $rich_result;
1088: }
1089:
1090: function get_theme_palette($return = "hex"){
1091: $theme_options = wp_get_global_settings();
1092: $colors = [];
1093: if(isset($theme_options['color']['palette']['theme'])){
1094: $colors = $theme_options['color']['palette']['theme'];
1095: }elseif(isset($theme_options['color']['palette']['default'])){
1096: $colors = $theme_options['color']['palette']['default'];
1097: }
1098: if($return == "hex"){
1099: $color_hexs = [];
1100: foreach($colors as $color){
1101: $color_hexs[] = $color["color"];
1102: }
1103: return $color_hexs;
1104: }
1105: return $colors;
1106: }
1107:
1108: /**
1109: * Add custom header meta for single events
1110: */
1111: public function single_header() {
1112: if (is_single()) {
1113: $twitter_label_id=0;
1114: $event = $this->retreive();
1115: $has_location = $has_time = false;
1116: if ($event != false) {
1117: if ($event->address != '' || ($event->lat != '' && $event->long != '')) {
1118: $twitter_label_id++;
1119: $has_location = true;
1120: ?>
1121: <meta name="geo.placename" content="<?php echo esc_attr($event->address) ?>" />
1122: <meta name="geo.position" content="<?php echo esc_attr($event->lat) ?>;<?php echo esc_attr($event->long) ?>" />
1123: <meta name="ICBM" content="<?php echo esc_attr($event->lat) ?>;<?php echo esc_attr($event->long) ?>" />
1124: <meta property="place:location:latitude" content="<?php echo esc_attr($event->lat) ?>" />
1125: <meta property="place:location:longitude" content="<?php echo esc_attr($event->long) ?>" />
1126: <meta name="twitter:label<?php echo esc_attr($twitter_label_id); ?>" content="<?php esc_attr_e('Location', 'event-post'); ?>"/>
1127: <meta name="twitter:data<?php echo esc_attr($twitter_label_id); ?>" content="<?php echo esc_attr($event->address) ?>"/>
1128: <?php
1129: }
1130: if ($event->start != '' && $event->end != '') {
1131: $has_time = true;
1132: $twitter_label_id++;
1133: ?>
1134: <meta name="datetime-coverage-start" content="<?php echo esc_attr(date('c', $event->time_start)) ?>" />
1135: <meta name="datetime-coverage-end" content="<?php echo esc_attr(date('c', $event->time_end)) ?>" />
1136: <meta name="twitter:label<?php echo esc_attr($twitter_label_id); ?>" content="<?php echo esc_attr('Date', 'event-post'); ?>"/>
1137: <meta name="twitter:data<?php echo esc_attr($twitter_label_id); ?>" content="<?php echo esc_attr($this->human_date($event->time_start)) ?>"/>
1138: <?php
1139: }
1140: if(($has_location || $has_time) && !$this->is_schema_output){
1141: $rich_result = $this->get_rich_result($event);
1142: $this->is_schema_output = true;
1143: ?>
1144: <script type="application/ld+json"><?php echo \wp_json_encode($rich_result); ?></script>
1145: <?php
1146: }
1147: }
1148: }
1149: }
1150:
1151: /**
1152: * Cleanups a date
1153: *
1154: * @param type $str
1155: *
1156: * @since 5.0.1
1157: *
1158: * @return string
1159: */
1160: public function date_cleanup($str){
1161: return trim(str_replace(array('0', ' ', ':', '-'), '', $str));
1162: }
1163:
1164: /**
1165: * Checks if a date is valid or not
1166: *
1167: * @param string $str
1168: *
1169: * @return boolean
1170: */
1171: public function dateisvalid($str) {
1172: return is_string($str) && $this->date_cleanup($str) != '';
1173: }
1174:
1175: /**
1176: * Parse a date from a string
1177: *
1178: * @param string $date
1179: * @param string $sep
1180: *
1181: * @return string
1182: */
1183: public function parsedate($date, $sep = '') {
1184: if (!empty($date)) {
1185: return substr($date, 0, 10) . $sep . substr($date, 11, 8);
1186: } else {
1187: return '';
1188: }
1189: }
1190:
1191: /**
1192: * Sanitize a coordinate string
1193: * Only keeps, numbers, dots and commas
1194: *
1195: * @param string $str
1196: *
1197: * @since 5.9.9
1198: *
1199: * @return string
1200: */
1201: public function sanitize_coordinate($str){
1202: return preg_replace('/[^0-9\.,-]/', '', $str);
1203: }
1204:
1205: /**
1206: * Format a date for humans
1207: *
1208: * @param mixed $date
1209: * @param string $format
1210: *
1211: * @return type
1212: */
1213: public function human_date($date, $format = 'l j F Y') {
1214: if($this->settings['dateforhumans']){
1215: if (is_numeric($date) && date('d/m/Y', $date) == date('d/m/Y')) {
1216: return __('today', 'event-post');
1217: } elseif (is_numeric($date) && date('d/m/Y', $date) == date('d/m/Y', strtotime('+1 day'))) {
1218: return __('tomorrow', 'event-post');
1219: } elseif (is_numeric($date) && date('d/m/Y', $date) == date('d/m/Y', strtotime('-1 day'))) {
1220: return __('yesterday', 'event-post');
1221: }
1222: }
1223: return date_i18n($format, $date);
1224: }
1225:
1226: /**
1227: * Returns a range of dates
1228: *
1229: * @param timestamp $time_start
1230: * @param timestamp $time_end
1231: *
1232: * @return string
1233: */
1234: public function delta_date($time_start, $time_end){
1235: if(!$time_start || !$time_end){
1236: return;
1237: }
1238:
1239: // Translators: %1$s, %4$s are opening tags, %2$s and %5$s are closing tag, %3$s is the first date, %6$s is the second date
1240: $from_to_days = _x('%1$sfrom%2$s %3$s %4$sto%5$s %6$s', 'Days', 'event-post');
1241: // Translators: %1$s is the first date, %4$s is the second date, %2$s is an opening tag, %3$s is a closing tag
1242: $single_day_at = _x('%1$s%2$s,%3$s %4$s', 'From/To single day at time', 'event-post');
1243: // Translators: %1$s, %4$s are opening tags, %2$s and %5$s are closing tag, %3$s is the first hour, %6$s is the second hour
1244: $from_to_hours = _x('%1$sfrom%2$s %3$s %4$sto%5$s %6$s', 'Hours', 'event-post');
1245: // Translators: %1$s is an opening tag, %2$s is a closing tag, %3$s is the time
1246: $at_time = _x('%1$sat%2$s %3$s', 'Time', 'event-post');
1247:
1248: //Display dates
1249: $dates="\t\t\t\t".'<div class="event_date" data-start="' . $this->human_date($time_start) . '" data-end="' . $this->human_date($time_end) . '">';
1250: // Same day
1251: if (date('Ymd', $time_start) == date('Ymd', $time_end)) {
1252: $dates.= "\n\t\t\t\t\t\t\t".'<time itemprop="dtstart" datetime="' . date_i18n('c', $time_start) . '">'
1253: . '<span class="date date-single">' . $this->human_date($time_end, $this->settings['dateformat']) . "</span>";
1254: if (date('H:i', $time_start) != date('H:i', $time_end) && date('H:i', $time_start) != '00:00' && date('H:i', $time_end) != '00:00') {
1255: $dates.= ' '.sprintf(
1256: $from_to_hours,
1257: '<span class="linking_word linking_word-from">',
1258: '</span>',
1259: '<span class="time time-start">' . date_i18n($this->settings['timeformat'], $time_start) . '</span>',
1260: '<span class="linking_word linking_word-to">',
1261: '</span>',
1262: '<span class="time time-end">' . date_i18n($this->settings['timeformat'], $time_end) . '</span>'
1263: );
1264: }
1265: elseif (date('H:i', $time_start) != '00:00') {
1266: $dates.= ' '.sprintf(
1267: $at_time,
1268: '<span class="linking_word">',
1269: '</span>',
1270: '<span class="time time-single">' . date_i18n($this->settings['timeformat'], $time_start) . '</span>'
1271: );
1272: }
1273: $dates.="\n\t\t\t\t\t\t\t".'</time>';
1274: }
1275: // Not same day
1276: else {
1277: $dates.= ' '.sprintf(
1278: $from_to_days,
1279: '<span class="linking_word linking_word-from">',
1280: '</span>',
1281: '<time class="date date-start" itemprop="dtstart" datetime="' . date('c', $time_start) . '">'
1282: . ((date('H:i:s', $time_start) != '00:00:00' || date('H:i:s', $time_end) != '00:00:00')
1283: ? sprintf($single_day_at, '<span class="date">'.$this->human_date($time_start, $this->settings['dateformat']).'</span>', '<span class="linking_word">', '</span>', '<span class="time">'.date_i18n($this->settings['timeformat'], $time_start).'</span>')
1284: : $this->human_date($time_start, $this->settings['dateformat'])
1285: )
1286: . '</time>',
1287: '<span class="linking_word linking_word-to">',
1288: '</span>',
1289: '<time class="date date-to" itemprop="dtend" datetime="' . date('c', $time_end) . '">'
1290: . ((date('H:i:s', $time_start) != '00:00:00' || date('H:i:s', $time_end) != '00:00:00')
1291: ? sprintf($single_day_at, '<span class="date">'.$this->human_date($time_end, $this->settings['dateformat']).'</span>', '<span class="linking_word">', '</span>', '<span class="time">'.date_i18n($this->settings['timeformat'], $time_end).'</span>')
1292: : $this->human_date($time_end, $this->settings['dateformat'])
1293: )
1294: . '</time>'
1295: );
1296: }
1297: $dates.="\n\t\t\t\t\t\t".'</div><!-- .event_date -->';
1298: return $dates;
1299: }
1300:
1301: /**
1302: * Displays a date
1303: *
1304: * @param WP_Post object $post
1305: * @param mixed $links
1306: *
1307: * @return string
1308: */
1309: public function print_date($post = null, $links = 'deprecated', $context='') {
1310: $dates = '';
1311: $event = $this->retreive($post);
1312: if ($event != false){
1313: if ($event->start != '' && $event->end != '') {
1314:
1315: $dates.=$this->delta_date($event->time_start, $event->time_end);
1316: if( // Status setting
1317: $this->settings['displaystatus'] == 'both' ||
1318: ($this->settings['displaystatus'] == 'single' && is_single() ) ||
1319: ($this->settings['displaystatus'] == 'list' && !is_single() )
1320: ){
1321: $dates.='<span class="eventpost-status">'.$this->statuses[$event->status].'</span>';
1322: }
1323: $timezone_string = get_option('timezone_string');
1324: $gmt_offset = $gmt = $this->get_gmt_offset();
1325:
1326: if (
1327: !is_admin()
1328: && ( // Export when setting
1329: $this->settings['export_when'] == 'both' ||
1330: ( $this->settings['export_when'] == 'future' && $this->is_future($event) ) ||
1331: ( $this->settings['export_when'] == 'past' && $this->is_past($event) )
1332: )
1333: && ( // Export setting
1334: $this->settings['export'] == 'both' ||
1335: ($this->settings['export'] == 'single' && is_single() ) ||
1336: ($this->settings['export'] == 'list' && !is_single() )
1337: )
1338: ) {
1339: // Export event
1340: $title = urlencode($post->post_title);
1341: $address = urlencode($post->address);
1342: $desc = urlencode($event->description."\n\n".$post->permalink);
1343: $allday = ($post->time_start && $post->time_end && date('H:i:s', $post->time_start) == '00:00:00' && date('H:i:s', $post->time_end) == '00:00:00');
1344: $d_s = date("Ymd", $event->time_start) . ($allday ? '' : 'T' . date("His", $event->time_start));
1345: $d_e = date("Ymd", $event->time_end) . ($allday ? '' : 'T' . date("His", $event->time_end));
1346: $uid = $post->ID . '-' . $post->blog_id;
1347: $url = $event->permalink;
1348:
1349: // format de date ICS
1350: $permalink_structure = get_option( 'permalink_structure' );
1351: if($permalink_structure != ""){
1352: $ics_url = site_url('eventpost/'.$event->ID.'.ics');
1353: $vcs_url = site_url('eventpost/'.$event->ID.'.vcs');
1354: }
1355: else{
1356: $ics_url = add_query_arg(array('action'=>'EventPostExport', 'event_id'=>$event->ID, 'format'=>'ics'), admin_url('admin-ajax.php'));
1357: $vcs_url = add_query_arg(array('action'=>'EventPostExport', 'event_id'=>$event->ID, 'format'=>'vcs'), admin_url('admin-ajax.php'));
1358:
1359: }
1360:
1361: // format de date Google cal
1362: //$google_url = 'https://www.google.com/calendar/event?action=TEMPLATE&amp;text=' . $title . '&amp;dates=' . $d_s . 'Z/' . $d_e . 'Z&amp;details=' . $url . '&amp;ctz='.$timezone_string.'&amp;location=' . $address . '&amp;trp=false&amp;sprop=&amp;sprop=name';
1363: $google_url = add_query_arg(array(
1364: 'action'=>'TEMPLATE',
1365: 'trp'=>'false',
1366: 'sprop'=>'name',
1367: 'text'=>$title,
1368: 'dates'=>$d_s.'/'.$d_e.'', // Removed Z to fix TZ issue
1369: 'location'=>$address,
1370: 'details'=>$desc,
1371: 'gmt'=> urlencode($gmt_offset)
1372: ), 'https://www.google.com/calendar/event');
1373: if(!empty($timezone_string)){
1374: $google_url = add_query_arg(array(
1375: 'ctz'=>$timezone_string,
1376: ), $google_url);
1377: }
1378:
1379: $dates.='
1380: <span class="eventpost-date-export">
1381: <a href="' . $ics_url . '" class="event_link event-export ics" target="_blank" title="' . __('Download ICS file', 'event-post') . '">ical</a>
1382: <a href="' . $google_url . '" class="event_link event-export gcal" target="_blank" title="' . __('Add to Google calendar', 'event-post') . '">Google</a>
1383: <a href="' . $vcs_url . '" class="event_link event-export vcs" target="_blank" title="' . __('Add to Outlook', 'event-post') . '">outlook</a>
1384: <i class="dashicons-before dashicons-calendar"></i>
1385: </span>';
1386: }
1387: }
1388: }
1389: return apply_filters('eventpost_printdate', $dates);
1390: }
1391:
1392: /**
1393: * Outputs location of an event
1394: *
1395: * @param WP_Post object $post
1396: *
1397: * @return string
1398: */
1399: public function print_location($post=null, $context='') {
1400: $location = '';
1401: if ($post == null)
1402: $post = get_post();
1403: elseif (is_numeric($post)) {
1404: $post = get_post($post);
1405: }
1406: if (!isset($post->start)) {
1407: $post = $this->retreive($post);
1408: }
1409: if ($post != false){
1410: $this->map_id++;
1411: $address = $post->address;
1412: $lat = $post->lat;
1413: $long = $post->long;
1414: $color = $this->get_post_color($post->ID, $this->settings['default_color'], true);
1415: $icon = $this->DashIcons->icons[$this->get_post_icon($post->ID, $this->settings['default_icon'], true)];
1416: $virtual_location = $post->virtual_location;
1417: $attendance_mode = $post->attendance_mode;
1418:
1419: if ($this->is_online($post) && $virtual_location) {
1420: $location.="\t\t\t\t".'<div><a href="'.esc_url($virtual_location).'" class="eventpost-virtual-location-link" target="_blank" rel="noopener">'
1421: .__('Join link', 'event-post')
1422: .'</a></div>'
1423: ."\n";
1424: }
1425: if ($this->is_offline($post) && ($address != '' || ($lat != '' && $long != ''))) {
1426: $location.="\t\t\t\t".'<address';
1427: if ($lat != '' && $long != '') {
1428: $geo_attributes = ' data-latitude="' . esc_attr($lat) . '"
1429: data-longitude="' . esc_attr($long) . '"
1430: data-marker="' . esc_attr($this->get_marker($color)) . '"
1431: data-iconcode="' .esc_attr($icon). '"
1432: data-icon="' . esc_attr(mb_convert_encoding('&#x'.$icon.';', 'UTF-8', 'HTML-ENTITIES')). '"
1433: data-color="#' . esc_attr($color). '"
1434: data-id="' . $post->ID . '-'.$this->map_id.'"';
1435: $location.=' '.$geo_attributes;
1436: }
1437: $location.=' itemprop="adr" class="eventpost-address">'
1438: . "\n\t\t\t\t\t\t\t".'<span>'
1439: . "\n".$address
1440: . "\n\t\t\t\t\t\t\t". '</span>';
1441: if ($context=='single' && $lat != '' && $long != '') {
1442: $location.="\n\t\t\t\t\t\t\t".'<a class="event_link gps dashicons-before dashicons-location-alt" href="https://www.openstreetmap.org/?lat=' . esc_attr($lat) .'&amp;lon=' . esc_attr($long) . '&amp;zoom=13" target="_blank" itemprop="geo" ' . $geo_attributes . '>' . __('Map', 'event-post') . '</a>';
1443: }
1444: $location.="\n\t\t\t\t\t\t".'</address>';
1445: if (wp_is_mobile() && $lat != '' && $long != '') {
1446: $location.="\n\t\t\t\t\t\t".'<a class="event_link gps-geo-link" href="geo:' . esc_attr($lat) . ',' . esc_attr($long) . '" target="_blank" itemprop="geo" ' . $geo_attributes . '><i class="dashicons-before dashicons-location"></i> ' . __('Open in app', 'event-post') . '</a>';
1447: }
1448: }
1449: }
1450: return apply_filters('eventpost_printlocation', $location);
1451: }
1452:
1453: /**
1454: * Compute darkness of the color
1455: *
1456: * @param string $color
1457: *
1458: * @return float
1459: */
1460: public function color_darkness($color){
1461: $color = str_replace('#', '', $color);
1462: $rgb = array();
1463: for ($x=0;$x<3;$x++) {
1464: $rgb[$x] = hexdec(substr($color,(2*$x),2));
1465: }
1466: return (max($rgb) + min($rgb)) / 510;
1467: }
1468:
1469: /**
1470: * Outputs categories of an event
1471: *
1472: * @param WP_Post object $post
1473: *
1474: * @return string
1475: */
1476: public function print_categories($post=null, $context='') {
1477: if ($post == null)
1478: $post = get_post();
1479: elseif (is_numeric($post)) {
1480: $post = get_post($post);
1481: }
1482: if (!isset($post->start)) {
1483: $post = $this->retreive($post);
1484: }
1485: $cats = '';
1486: if ($post != false){
1487: $categories = $post->Taxonomies;
1488: if ($categories) {
1489: $cats.="\t\t\t\t".'<span class="event_categories">';
1490:
1491: foreach ($categories as $category) {
1492: $cats.="\t\t\t\t\t".'<span ';
1493: $classes = array('event-term', 'event_term_category');
1494: $darkness = 0;
1495: $color = $this->Taxonomies->get_taxonomy_color($category->term_id);
1496: if ($color != '' && $color) {
1497: $cats.=' style="background-color:#' . $color . '"';
1498:
1499: $darkness = $this->color_darkness($color);
1500: if($darkness < 0.5){
1501: array_push($classes, 'event-post-bg-dark');
1502: }
1503: else{
1504: array_push($classes, 'event-post-bg-light');
1505: }
1506:
1507: }
1508: $cats.=' class="'.implode(' ', $classes).'">';
1509: $cats .= $category->name . ' ';
1510: $cats.='</span>';
1511: }
1512: $cats.='</span>';
1513: }
1514: }
1515: return $cats;
1516: }
1517:
1518: /**
1519: * Generate, return or output date event datas
1520: *
1521: * @param WP_Post object $post
1522: * @param string $class
1523: *
1524: * @filter eventpost_get_single
1525: *
1526: * @return string
1527: */
1528: public function get_single($post = null, $class = '', $context='') {
1529: if ($post == null) {
1530: $post = $this->retreive();
1531: }
1532: if ($post != null){
1533: $datas_date = $this->print_date($post, null, $context);
1534: $datas_cat = $this->print_categories($post, $context);
1535: $datas_loc = $this->print_location($post, $context);
1536: $classes = array(
1537: 'event_data',
1538: 'status-'.strtolower(str_replace('Event', '', $post->status)),
1539: 'location-type-'.strtolower(str_replace('EventAttendanceMode', '', $post->attendance_mode)),
1540: $class
1541: );
1542: if ($datas_date != '' || $datas_loc != '') {
1543: $rgb = $this->hex2dec($post->color);
1544: return '<div class="' . implode(' ', $classes) . '" style="border-left-color:#' . esc_attr($post->color) . ';background:rgba(' . (int) $rgb['R'] . ',' . (int) $rgb['G'] . ',' . (int) $rgb['B'] . ',0.1)" itemscope itemtype="http://microformats.org/profile/hcard">'
1545: . apply_filters('eventpost_get_single', $datas_date . $datas_cat . $datas_loc, $post)
1546: . '</div>';
1547: }
1548: }
1549: return '';
1550: }
1551:
1552: /**
1553: * Displays dates of a gieven post
1554: *
1555: * @param WP_Post object $post
1556: * @param string $class
1557: *
1558: * @return string
1559: */
1560: public function get_singledate($post = null, $class = '', $context='') {
1561: return '<div class="event_data event_date ' . $class . '" itemscope itemtype="http://microformats.org/profile/hcard">' . "\n\t\t".$this->print_date($post, null, $context) . "\n\t\t\t\t\t".'</div><!-- .event_date -->';
1562: }
1563:
1564: /**
1565: * Displays coloured terms of a given post
1566: *
1567: * @param WP_Post object $post
1568: * @param string $class
1569: *
1570: * @return string
1571: */
1572: public function get_singlecat($post = null, $class = '', $context='') {
1573: return '<div class="event_data event_category ' . $class . '" itemscope itemtype="http://microformats.org/profile/hcard">' . "\n\t\t".$this->print_categories($post, $context) . "\n\t\t\t\t\t".'</div><!-- .event_category -->';
1574: }
1575:
1576: /**
1577: * Displays location of a given post
1578: *
1579: * @param WP_Post object $post
1580: * @param string $class
1581: *
1582: * @return string
1583: */
1584: public function get_singleloc($post = null, $class = '', $context='') {
1585: return '<div class="event_data event_location ' . $class . '" itemscope itemtype="http://microformats.org/profile/hcard">' . "\n\t\t".$this->print_location($post, $context) . "\n\t\t\t\t\t".'</div><!-- .event_location -->';
1586: }
1587:
1588: /**
1589: * Uses `the_content` filter to add event details before or after the content of the current post
1590: *
1591: * @param string $content
1592: *
1593: * @return string
1594: */
1595: public function display_single($content) {
1596: if (is_page() || !is_single() || is_home() || !in_the_loop() || !is_main_query()){
1597: return $content;
1598: }
1599:
1600: $post = $this->retreive();
1601: if($post != false){
1602: // If the post is a product, don't display the event bar, use product tab instead
1603: if($post->post_type=='product'){
1604: return $content;
1605: }
1606:
1607: $eventbar = apply_filters('eventpost_contentbar', $this->get_single($post, 'event_single', 'single'), $post);
1608: if($this->settings['singlepos']=='before'){
1609: $content=$eventbar.$content;
1610: }
1611: elseif($this->settings['singlepos']=='after'){
1612: $content.=$eventbar;
1613: }
1614: $this->load_map_scripts();
1615: }
1616: return $content;
1617: }
1618:
1619: /**
1620: * Outputs events details (dates, geoloc, terms) of given post
1621: *
1622: * @param WP_Post object $post
1623: *
1624: * @return void
1625: */
1626: public function print_single($post = null) {
1627: echo wp_kses_post($this->get_single($post));
1628: }
1629:
1630: /**
1631: * Alter the post title in order to add icons if needed
1632: *
1633: * @param string $title
1634: *
1635: * @return string
1636: */
1637: public function the_title($title, $post_id = null){
1638: if(!$post_id || !in_the_loop() || !$this->settings['loopicons']){
1639: return $title;
1640: }
1641: $icons_ = array(
1642: // Emojis
1643: 1=>array('🗓', '🗺'),
1644: // Dashicons
1645: 2=>array('<span class="dashicons dashicons-calendar"></span>', '<span class="dashicons dashicons-location"></span>'),
1646: );
1647:
1648: $event = $this->retreive($post_id);
1649: if ($event !== false){
1650: if(!empty($event->start)){
1651: $title .= ' '.$icons_[$this->settings['loopicons']][0];
1652: }
1653: if(!empty($event->lat) && !empty($event->long)){
1654: $title .= ' '.$icons_[$this->settings['loopicons']][1];
1655: }
1656: }
1657: return $title;
1658: }
1659:
1660:
1661: function get_price($event,$html=false){
1662: $price = '';
1663: $text_price = $price;
1664: if($event->post_type == 'product'){
1665: $product_id = $event->ID;
1666: $product = wc_get_product($product_id);
1667: $price = $product->get_price();
1668: $currency = get_woocommerce_currency_symbol();
1669: if($product->get_sale_price() != ""){
1670: $old_price = $product->get_regular_price();
1671: $text_price = '<span class="event_price"><del>'.$old_price . $currency . '</del> '.$price. $currency. '</span>';
1672: } else {
1673: $text_price = '<span class="event_price"> '.$price . $currency.'</span>';
1674: }
1675: }
1676: if ($html == true) {
1677: return $text_price;
1678: } else {
1679: return $price;
1680: }
1681: }
1682:
1683: /**
1684: * Return an HTML list of events
1685: *
1686: * @param array $atts
1687: * @param string $id
1688: * @param string $context
1689: *
1690: * @filter eventpost_params($defaults, 'list_events')
1691: * @filter eventpost_listevents
1692: * @filter eventpost_item_scheme_entities
1693: * @filter eventpost_item_scheme_values
1694: *
1695: * @return string
1696: */
1697: public function list_events($atts, $id = 'event_list', $context='') {
1698: $ep_settings = $this->settings;
1699: $defaults = array(
1700: 'nb' => 0,
1701: 'nb_desktop' => 0,
1702: 'nb_tablet' => 0,
1703: 'nb_mobile' => 0,
1704: 'type' => 'div',
1705: 'future' => true,
1706: 'past' => false,
1707: 'geo' => 0,
1708: 'width' => '',
1709: 'height' => '',
1710: 'list' => 0,
1711: 'zoom' => '',
1712: 'map_position' => 'false',
1713: 'latitude' => '',
1714: 'longitude' => '',
1715: 'tile' => $ep_settings['tile'],
1716: 'pop_element_schema' => 'false',
1717: 'htmlPop_element_schema' => '',
1718: 'title' => '',
1719: 'before_title' => '<h3>',
1720: 'after_title' => '</h3>',
1721: 'cat' => '',
1722: 'tag' => '',
1723: 'tax_name' => '',
1724: 'tax_term' => '',
1725: 'events' => '',
1726: 'style' => '',
1727: 'thumbnail' => '',
1728: 'thumbnail_size' => '',
1729: 'excerpt' => '',
1730: 'orderby' => 'meta_value',
1731: 'order' => 'ASC',
1732: 'class' => '',
1733: 'align' => '',
1734: 'className' => '',
1735: 'container_schema' => $this->list_shema['container'],
1736: 'item_schema' => $this->list_shema['item'],
1737: 'pages' => false,
1738: 'paged' => '',
1739: 'separate_years' => false,
1740: 'separate_months' => false,
1741: );
1742: // Map UI options
1743: foreach($this->map_interactions as $int_key=>$int_name){
1744: $defaults[$int_key]=true;
1745: }
1746: $atts_old_nb = $defaults['nb'];
1747: if($id == "event_timeline"){
1748: $atts_old_nb = intval($atts['nb']);
1749: $atts['nb'] = -1;
1750: }
1751:
1752: $atts = shortcode_atts(apply_filters('eventpost_params', $defaults, 'list_events', $context), $atts);
1753:
1754: extract($atts);
1755: if (!is_array($events)) {
1756: $events = $this->get_events($atts);
1757: }
1758:
1759: $ret = '';
1760: $this->list_id++;
1761: if (sizeof($events) > 0) {
1762: if (!empty($title)) {
1763: $ret .= wp_kses_post($before_title . esc_html($title) . $after_title);
1764: }
1765:
1766: $type = in_array($type, ['div', 'ul', 'ol']) ? $type : 'div';
1767: $child = in_array($type, ['ul', 'ol']) ? 'li' : 'div';
1768:
1769: $html = '';
1770:
1771: if($id=='event_geolist'){
1772: $this->load_map_scripts();
1773: $html.=sprintf('<%1$s class="event_geolist_icon_loader"><p><span class="dashicons dashicons-location-alt"></span></p><p class="screen-reader-text">'.__('An events map', 'event-post').'</p></%1$s>', $type);
1774: }
1775: $attributes = '';
1776: $prev_arrow = "";
1777: $next_arrow = "";
1778: $item_child_style = "";
1779: if($id == "event_timeline"){
1780: $prev_arrow = '<div class="previous"><span class="screen-reader-text">'.__('« Previous Events', 'event-post')."</span></div>";
1781: $next_arrow = '<div class="next"><span class="screen-reader-text">'.__('Next Events »', 'event-post')."</span></div>";
1782: if($atts_old_nb != 0){
1783: $item_child_style = 'width : '.((100/$atts_old_nb) - 2).'%;';
1784: }
1785: $attributes .= ' data-nb="'.$atts_old_nb.'"';
1786: $attributes .= ' data-nb-desktop="'.intval($atts['nb_desktop'] ?? 0).'"';
1787: $attributes .= ' data-nb-tablet="'.intval($atts['nb_tablet'] ?? 0).'"';
1788: $attributes .= ' data-nb-mobile="'.intval($atts['nb_mobile'] ?? 0).'"';
1789: $attributes .= ' data-filter="'.esc_attr(http_build_query($atts)).'" ';
1790: }
1791:
1792: if($id === 'event_timeline'){
1793: $previous_year = $atts['separate_years'] ? true : false;
1794: $previous_month = $atts['separate_months'] ? true : false;
1795: }
1796:
1797: foreach ($events as $event) {
1798: if($id === 'event_timeline'){
1799: if($previous_year && $previous_year !== date('Y', $event->time_start)){
1800: $html.= '<div class="event-timeline-separator event-timeline-year"><span class="event-timeline-year-text">'.date_i18n('Y', $event->time_start).'</span></div>';
1801: $previous_year = date('Y', $event->time_start);
1802: }
1803: if($previous_month && $previous_month !== date('Ym', $event->time_start)){
1804: $html.= '<div class="event-timeline-separator event-timeline-month"><span class="event-timeline-month-text">'.date_i18n('F', $event->time_start).'</span>'.($previous_year ? '' : ' <span class="event-timeline-year-text">'.date_i18n('Y', $event->time_start).'</span>').'</div>';
1805: $previous_month = date('Ym', $event->time_start);
1806: }
1807: }
1808: $text_price = $this->get_price($event,true);
1809: $class_item = array(
1810: $this->is_future($event) ? 'event_future' : 'event_past',
1811: 'status-'.strtolower(str_replace('Event', '', $event->status)),
1812: 'location-type-'.strtolower(str_replace('EventAttendanceMode', '', $event->attendance_mode)),
1813: );
1814: $taxonomies= get_taxonomies('','names');
1815: $post_terms = [];
1816: $terms = wp_get_post_terms($event->ID, $taxonomies);
1817: foreach($terms as $term){
1818: $class_item[] = $term->taxonomy.'-'.$term->slug;
1819: }
1820: if ($ep_settings['emptylink'] == 0 && empty($event->post_content)) {
1821: $event->permalink = '#' . $id . $this->list_id;
1822: }
1823: elseif(empty($event->permalink)){
1824: $event->permalink=$event->guid;
1825: }
1826: $html.=str_replace(
1827: apply_filters('eventpost_item_scheme_entities', array(
1828: '%child%',
1829: '%class%',
1830: '%color%',
1831: '%event_link%',
1832: '%event_thumbnail%',
1833: '%event_title%',
1834: '%event_price%',
1835: '%event_date%',
1836: '%event_cat%',
1837: '%event_location%',
1838: '%event_excerpt%',
1839: '%style%',
1840: )), apply_filters('eventpost_item_scheme_values', array(
1841: $child,
1842: implode(' ', $class_item),
1843: esc_attr($this->get_post_color($event->ID, $this->settings['default_color'],true)),
1844: esc_url($event->permalink),
1845: $thumbnail == true ? '<span class="event_thumbnail_wrap">' . get_the_post_thumbnail($event->root_ID, !empty($thumbnail_size) ? $thumbnail_size : 'thumbnail', array('class' => 'attachment-thumbnail wp-post-image event_thumbnail')) . '</span>' : '',
1846: esc_html($event->post_title),
1847: $event->post_type == 'product' ? $text_price : '',
1848: $this->get_singledate($event, '', $context),
1849: $this->get_singlecat($event, '', $context),
1850: $this->get_singleloc($event, '', $context),
1851: $excerpt == true && $event->description!='' ? '<span class="event_exerpt">'.$event->description.'</span>' : '',
1852: $item_child_style,
1853: ), $event), $item_schema
1854: );
1855:
1856: }
1857: if($id == 'event_geolist'){
1858: if($height==''){
1859: $height = '300px';
1860: }
1861: if($width==''){
1862: $width = '100%';
1863: }
1864: $attributes .= ' data-tile="'.esc_attr($tile).'"
1865: data-width="'.esc_attr($width).'"
1866: data-height="'.esc_attr($height).'"
1867: data-zoom="'.esc_attr($zoom).'"
1868: data-map_position="'.esc_attr($map_position).'"
1869: data-latitude="'.esc_attr($latitude).'"
1870: data-longitude="'.esc_attr($longitude).'"
1871: data-pop_element_schema="'.esc_attr($pop_element_schema).'"
1872: data-htmlPop_element_schema="'.esc_attr($htmlPop_element_schema).'"
1873: data-list="'.esc_attr($list).'"
1874: data-disabled-interactions="';
1875: // add data-position avec ma variables
1876: foreach($this->map_interactions as $int_key=>$int_name){
1877: $attributes.=$atts[$int_key]==false ? esc_attr($int_key).', ' : '';
1878: }
1879: $attributes.='" ';
1880: }
1881: $pagination = '';
1882: if($pages && $this->pagination){
1883: global $wp_rewrite;
1884: $paged = ( get_query_var( 'page' ) ) ? absint( get_query_var( 'page' ) ) : 1;
1885: $pagination = paginate_links( array(
1886: 'prev_text' => __('« Previous Events', 'event-post'),
1887: 'next_text' => __('Next Events »', 'event-post'),
1888: 'current' => $paged,
1889: 'total' => $this->pagination['max_num_pages'],
1890: )
1891: );
1892: }
1893:
1894: if($context == 'events_only'){
1895: $ret = $html;
1896: }else{
1897: $classes = [
1898: $class,
1899: $className,
1900: 'className',
1901: $id == 'event_geolist' && $list ? ' has-list list-'.esc_attr($list) : ' no-list',
1902: ];
1903: if(!empty($align)){
1904: $classes[] = 'align'.esc_attr($align);
1905: }
1906: if($id === 'event_timeline' && ($previous_year || $previous_month)){
1907: $classes[] = 'has-time-separators';
1908: }
1909: $ret.=str_replace(
1910: array(
1911: '%type%',
1912: '%id%',
1913: '%class%',
1914: '%listid%',
1915: '%style%',
1916: '%attributes%',
1917: '%list%',
1918: '%pagination%',
1919: '%prev_arrow%',
1920: '%next_arrow%',
1921: '%number%'
1922: ), array(
1923: $type,
1924: $id,
1925: esc_attr(implode(' ', $classes)),
1926: $id . $this->list_id,
1927: (!empty($width) ? 'width:' . esc_attr($width) . ';' : '') . (!empty($height) ? 'height:' . esc_attr($height) . ';' : '') . esc_attr($style),
1928: $attributes,
1929: $html,
1930: $pagination,
1931: $prev_arrow,
1932: $next_arrow
1933: ), $container_schema
1934: );
1935: }
1936:
1937: }
1938: elseif(filter_input(INPUT_POST, 'action')=='bulk_do_shortcode'){
1939: return '<div class="event_geolist_icon_loader"><p><span class="dashicons dashicons-calendar"></span></p><p class="screen-reader-text">'.__('An empty list of events', 'event-post').'</p></div>';
1940: }
1941: return apply_filters('eventpost_listevents', $ret, $id.$this->list_id, $atts, $events, $context);
1942: }
1943:
1944:
1945: /**
1946: * Get events
1947: *
1948: * @param array $atts
1949: *
1950: * @filter eventpost_params
1951: * @filter eventpost_get_items
1952: *
1953: * @return array of post_ids which are events
1954: */
1955: public function get_events($atts) {
1956: if(isset($atts['future'])){
1957: $atts['future'] = filter_var( $atts['future'], FILTER_VALIDATE_BOOLEAN);
1958: }
1959: if(isset($atts['past'])){
1960: $atts['past'] = filter_var( $atts['past'], FILTER_VALIDATE_BOOLEAN);
1961: }
1962: if(isset($atts['geo'])){
1963: $atts['geo'] = filter_var( $atts['geo'], FILTER_VALIDATE_BOOLEAN);
1964: }
1965: if(isset($atts['pages'])){
1966: $atts['pages'] = filter_var( $atts['pages'], FILTER_VALIDATE_BOOLEAN);
1967: }
1968:
1969:
1970:
1971: $requete = (shortcode_atts(apply_filters('eventpost_params', array(
1972: 'nb' => 5,
1973: 'future' => true,
1974: 'past' => false,
1975: 'geo' => 0,
1976: 'cat' => '',
1977: 'tag' => '',
1978: 'date' => '',
1979: 'orderby' => 'meta_value',
1980: 'orderbykey' => $this->META_START,
1981: 'order' => 'ASC',
1982: 'tax_name' => '',
1983: 'tax_term' => '',
1984: 'paged' => 1,
1985: 'post_type'=> $this->settings['posttypes']
1986: ), 'get_events'), $atts));
1987: if(!isset($requete['paged']) || $requete['paged'] == ""){
1988: $requete['paged'] = ( get_query_var( 'page' ) ) ? absint( get_query_var( 'page' ) ) : 1;
1989: }
1990: extract($requete);
1991: wp_reset_query();
1992:
1993:
1994: $arg = array(
1995: 'post_status' => 'publish',
1996: 'post_type' => $post_type,
1997: 'posts_per_page' => $nb,
1998: 'paged' => $paged,
1999: 'meta_key' => $orderbykey,
2000: 'orderby' => $orderby,
2001: 'order' => $order
2002: );
2003:
2004: if($tax_name=='category'){
2005: $tax_name='';
2006: $cat=$tax_term;
2007: }
2008: elseif($tax_name=='post-tag'){
2009: $tax_name='';
2010: $tag=$tax_term;
2011: }
2012:
2013: // CUSTOM TAXONOMY
2014: if ($tax_name != '' && $tax_term != '') {
2015: $arg['tax_query'] = array(
2016: array(
2017: 'taxonomy' => $tax_name,
2018: 'field' => 'slug',
2019: 'terms' => $tax_term,
2020: ),
2021: );
2022: }
2023: // CAT
2024: if ($cat != '') {
2025: if (preg_match('/[a-zA-Z]/i', $cat)) {
2026: $arg['category_name'] = $cat;
2027: } else {
2028: $arg['cat'] = $cat;
2029: }
2030: }
2031: // TAG
2032: if ($tag != '') {
2033: $arg['tag'] = $tag;
2034: }
2035: // DATES
2036: $meta_query = array(
2037: array(
2038: 'key' => $this->META_END,
2039: 'value' => '',
2040: 'compare' => '!='
2041: ),
2042: array(
2043: 'key' => $this->META_END,
2044: 'value' => '0:0:00 0:',
2045: 'compare' => '!='
2046: ),
2047: array(
2048: 'key' => $this->META_END,
2049: 'value' => ':00',
2050: 'compare' => '!='
2051: ),
2052: array(
2053: 'key' => $this->META_START,
2054: 'value' => '',
2055: 'compare' => '!='
2056: ),
2057: array(
2058: 'key' => $this->META_START,
2059: 'value' => '0:0:00 0:',
2060: 'compare' => '!='
2061: )
2062: );
2063: if ($future == 0 && $past == 0) {
2064: $meta_query = array();
2065: $arg['meta_key'] = null;
2066: $arg['orderby'] = null;
2067: $arg['order'] = null;
2068: }
2069: elseif ($future == 1 && $past == 0) {
2070: $meta_query[] = array(
2071: 'key' => $this->META_END,
2072: 'value' => current_time('mysql'),
2073: 'compare' => '>=',
2074: //'type'=>'DATETIME'
2075: );
2076: }
2077: elseif ($future == 0 && $past == 1) {
2078: $meta_query[] = array(
2079: 'key' => $this->META_END,
2080: 'value' => current_time('mysql'),
2081: 'compare' => '<=',
2082: //'type'=>'DATETIME'
2083: );
2084: }
2085: if ($date != '') {
2086: $date = date('Y-m-d', $date);
2087:
2088: $meta_query = array(
2089: array(
2090: 'key' => $this->META_END,
2091: 'value' => $date . ' 00:00:00',
2092: 'compare' => '>=',
2093: 'type' => 'DATETIME'
2094: ),
2095: array(
2096: 'key' => $this->META_START,
2097: 'value' => $date . ' 23:59:59',
2098: 'compare' => '<=',
2099: 'type' => 'DATETIME'
2100: )
2101: );
2102: }
2103: // GEO
2104: if ($geo == 1) {
2105: $meta_query[] = array(
2106: 'key' => $this->META_LAT,
2107: 'value' => '',
2108: 'compare' => '!='
2109: );
2110: $meta_query[] = array(
2111: 'key' => $this->META_LONG,
2112: 'value' => '',
2113: 'compare' => '!='
2114: );
2115: $arg['meta_key'] = $this->META_LAT;
2116: $arg['orderby'] = 'meta_value';
2117: $arg['order'] = 'DESC';
2118: }
2119:
2120: $arg['meta_query'] = $meta_query;
2121:
2122: $query_md5 = 'eventpost_' . md5(wp_json_encode($requete, true));
2123: // Check if cache is activated
2124: if ($this->settings['cache'] == 1 && false !== ( $cached_events = get_transient($query_md5) )) {
2125: return apply_filters('eventpost_get_items', is_array($cached_events) ? $cached_events : array(), $requete, $arg);
2126: }
2127:
2128: $events = apply_filters('eventpost_get', '', $requete, $arg);
2129: if ('' === $events) {
2130: global $wpdb;
2131: $query = new WP_Query($arg);
2132: $events = $wpdb->get_col($query->request);
2133: $this->pagination = array(
2134: 'found_posts' => $query->found_posts,
2135: 'max_num_pages' => $query->max_num_pages,
2136: );
2137: foreach ($events as $k => $post) {
2138: $event = $this->retreive($post);
2139: if ($event != false){
2140: $events[$k] = $event;
2141: }
2142: }
2143: }
2144: if ($this->settings['cache'] == 1){
2145: set_transient($query_md5, $events, 5 * MINUTE_IN_SECONDS);
2146: }
2147: return apply_filters('eventpost_get_items', $events, $requete, $arg);
2148: }
2149:
2150: /**
2151: * Checks if the given event is in the future or not
2152: *
2153: * @param object $event
2154: * @param boolean $exact Future status has to be calculated against time or entire day
2155: *
2156: * @return boolean
2157: */
2158: function is_future($event, $exact=false){
2159: $match = current_time('timestamp');
2160: // if EXACT is false, end date is set to begining of the current day
2161: if(!$exact){
2162: $match = mktime(0, 0, 0, date('m', $match), date('d', $match), date('Y', $match));
2163: }
2164: return ($event->time_end >= $match);
2165: }
2166:
2167: /**
2168: * Checks if the given event is completed or not
2169: *
2170: * @param object $event
2171: * @param boolean $exact Past status has to be calculated against time or entire day
2172: *
2173: * @return boolean
2174: */
2175: function is_past($event, $exact=false){
2176: $match = current_time('timestamp');
2177: // if EXACT is false or full day event, end date is set to end of the current day
2178: if(!$exact || ( date('H:i:s', $event->time_start) == '00:00:00' && date('H:i:s', $event->time_end) == '00:00:00' )){
2179: $match = mktime(23, 59, 59, date('m', $match), date('d', $match), date('Y', $match));
2180: }
2181: return ($event->time_end < $match);
2182: }
2183:
2184: /**
2185: * Checks if an event is online
2186: *
2187: * @param $event
2188: *
2189: * @return boolean
2190: */
2191: function is_online($event){
2192: return (in_array($event->attendance_mode, array('MixedEventAttendanceMode', 'OnlineEventAttendanceMode')));
2193: }
2194:
2195: /**
2196: * Checks if an event is offline
2197: *
2198: * @param $event
2199: *
2200: * @return boolean
2201: */
2202: function is_offline($event){
2203: return (in_array($event->attendance_mode, array('MixedEventAttendanceMode', 'OfflineEventAttendanceMode')));
2204: }
2205:
2206: /**
2207: * Populates a WP_Post object with event datas
2208: *
2209: * @param object $event
2210: *
2211: * @return object
2212: */
2213: public function retreive($event = null) {
2214: global $EventPost_cache;
2215: $ob = get_post($event);
2216: if(!$ob){
2217: return false;
2218: }
2219: if(is_object($ob) && $ob->start){
2220: return $ob;
2221: }
2222: if(is_object($ob) && isset($EventPost_cache[$ob->ID])){
2223: return $EventPost_cache[$ob->ID];
2224: }
2225: $ob->start = get_post_meta($ob->ID, $this->META_START, true);
2226: $ob->end = get_post_meta($ob->ID, $this->META_END, true);
2227: if (!$this->dateisvalid($ob->start)){
2228: $ob->start = '';
2229: }
2230: if (!$this->dateisvalid($ob->end)){
2231: $ob->end = '';
2232: }
2233: $ob->root_ID = $ob->ID;
2234: $ob->time_start = !empty($ob->start) ? strtotime($ob->start) : '';
2235: $ob->time_end = !empty($ob->end) ? strtotime($ob->end) : '';
2236: $ob->virtual_location = get_post_meta($ob->ID, $this->META_VIRTUAL_LOCATION, true);
2237: $ob->virtual_location = esc_url($ob->virtual_location);
2238: $ob->organization = get_post_meta($ob->ID, $this->META_ORGANIZATION, true);
2239: $ob->offer = get_post_meta($ob->ID, $this->META_OFFER, true);
2240: if(empty($ob->offer)){
2241: $ob->offer = array(
2242: 'url' => null,
2243: 'price' => null,
2244: 'currency' => null,
2245: );
2246: }
2247: $ob->address = get_post_meta($ob->ID, $this->META_ADD, true);
2248: $ob->lat = $this->sanitize_coordinate(get_post_meta($ob->ID, $this->META_LAT, true));
2249: $ob->long = $this->sanitize_coordinate(get_post_meta($ob->ID, $this->META_LONG, true));
2250: $ob->attendance_mode = (null != $att_mod = get_post_meta($ob->ID, $this->META_ATTENDANCE_MODE, true)) ? $att_mod : array_keys($this->attendance_modes)[0];
2251: $ob->status = (null != $status = get_post_meta($ob->ID, $this->META_STATUS, true)) ? $status : array_keys($this->statuses)[0];
2252: $ob->color = $this->get_post_color($ob->ID);
2253: $ob->icon = $this->get_post_icon($ob->ID);
2254: $ob->Taxonomies = get_the_category($ob->ID);
2255: $ob->permalink = get_permalink($ob->ID);
2256: $ob->blog_id = get_current_blog_id();
2257: $ob->description = $ob->post_excerpt ? $ob->post_excerpt : str_replace('&nbsp;', ' ', preg_replace("/\n+/", "\n", trim(wp_strip_all_tags(excerpt_remove_blocks($ob->post_content)))));
2258: $EventPost_cache[$ob->ID] = apply_filters('eventpost_retreive', $ob);
2259: return $EventPost_cache[$ob->ID];
2260: }
2261:
2262: /**
2263: * Fetch terms of a post
2264: *
2265: * @param mixed $_term
2266: * @param string $taxonomy
2267: * @param string $post_type
2268: */
2269: public function retreive_term($_term=null, $taxonomy='category', $post_type='post') {
2270: $term = get_term($_term, $taxonomy);
2271:
2272: if(!$term){
2273: return $term;
2274: }
2275:
2276: $term->start = $term->end = $term->time_start = $term->time_end = Null;
2277:
2278: $request = array(
2279: 'post_type'=>$post_type,
2280: 'tax_name'=>$term->taxonomy,
2281: 'tax_term'=>$term->slug,
2282: 'future'=>true,
2283: 'past'=>true,
2284: 'nb'=>-1,
2285: 'order'=>'ASC'
2286: );
2287:
2288: $events = $this->get_events($request);
2289:
2290: $term->events_count = count($events);
2291: if($term->events_count){
2292: $term->start = $events[0]->start;
2293: $term->time_start = $events[0]->time_start;
2294: $term->end = $events[$term->events_count-1]->end;
2295: $term->time_end = $events[$term->events_count-1]->time_end;
2296: }
2297:
2298: $request['order']='DESC';
2299: $request['nb']=1;
2300: $request['orderbykey']=$this->META_END;
2301: $events = $this->get_events($request);
2302: if(count($events)){
2303: $term->end = $events[0]->end;
2304: $term->time_end = $events[0]->time_end;
2305: }
2306:
2307: return $term;
2308:
2309: }
2310:
2311: // ADMIN ISSUES
2312:
2313: /**
2314: * Add custom boxes in posts edit page
2315: */
2316: public function add_custom_box() {
2317: foreach($this->settings['posttypes'] as $posttype){
2318: add_meta_box(
2319: 'event_post_date',
2320: __('Event date', 'event-post'),
2321: array(&$this, 'inner_custom_box_date'),
2322: $posttype,
2323: apply_filters('eventpost_add_custom_box_position', $this->settings['adminpos'], $posttype),
2324: 'core',
2325: array(
2326: '__block_editor_compatible_meta_box' => true,
2327: )
2328: );
2329: add_meta_box(
2330: 'event_post_loc',
2331: __('Location', 'event-post'),
2332: array(&$this, 'inner_custom_box_loc'),
2333: $posttype,
2334: apply_filters('eventpost_add_custom_box_position', $this->settings['adminpos'], $posttype),
2335: 'core',
2336: array(
2337: '__block_editor_compatible_meta_box' => true,
2338: )
2339: );
2340: do_action('eventpost_add_custom_box', $posttype);
2341: }
2342: }
2343:
2344: /**
2345: * Displays the date custom box
2346: */
2347: public function inner_custom_box_date() {
2348:
2349:
2350:
2351: wp_nonce_field(plugin_basename(__FILE__), 'eventpost_nonce');
2352: $post_id = get_the_ID();
2353: $event = $this->retreive($post_id);
2354: if ($event != false){
2355: $start_date = $event->start;
2356: $end_date = $event->end;
2357: $eventcolor = $event->color;
2358: $eventicon = $event->icon;
2359:
2360: $language = get_bloginfo('language');
2361: if (strpos($language, '-') > -1) {
2362: $language = strtolower(substr($language, 0, 2));
2363: }
2364: $colors = $this->get_colors();
2365: include (plugin_dir_path(__FILE__) . 'views/admin/custombox-date.php');
2366: do_action ('eventpost_custom_box_date', $event);
2367: }
2368: }
2369:
2370: /**
2371: * Displays the location custom box
2372: */
2373: public function inner_custom_box_loc($post) {
2374: $event = $this->retreive($post);
2375: if ($event != false){
2376: include (plugin_dir_path(__FILE__) . 'views/admin/custombox-location.php');
2377: do_action ('eventpost_custom_box_loc', $event);
2378: $this->load_map_scripts();
2379: }
2380: }
2381:
2382: public function icon_color_fields($item_id, $meta_color,$value_color,$meta_icon,$value_icon ){
2383: ?>
2384: <div class="eventpost-misc-pub-section event-color-section">
2385: <span class="screen-reader-text"><?php esc_html_e('Color:', 'event-post'); ?></span>
2386:
2387: <input class="color-field-post eventpost-colorpicker"
2388: type="text"
2389: name="<?php echo esc_attr($meta_color); ?>"
2390: value="<?php echo esc_attr($value_color); ?>"
2391: id="color-field<?php echo esc_attr($item_id); ?>"/>
2392:
2393: <select style="font-family : dashicons;" class="eventpost-iconpicker" name="<?php echo esc_attr($meta_icon); ?>">
2394: <option value=""><?php esc_attr_e('None','event-post') ?></option>
2395: <?php
2396: foreach($this->DashIcons->icons as $class => $unicode){
2397: ?>
2398: <option value="<?php echo esc_attr($class) ?>" <?php selected($value_icon, $class, true); ?>>&#x<?php esc_attr_e($unicode) ?>; <?php echo esc_html($class) ?></option><?php // phpcs:ignore WordPress.WP.I18n ?>
2399: <?php
2400: }
2401: ?>
2402: </select>
2403: <div class="custom-marker-container">
2404: <p><?php esc_html_e('An image was found in your custom folder for this color', 'event-post')?> <span class="color-hex"></span> </p>
2405: <img src="" class="image-marker">
2406: </div>
2407: </div>
2408:
2409:
2410: <?php
2411: }
2412:
2413: /**
2414: * Quick edit
2415: *
2416: * @param string $column_name
2417: * @param boolean $bulk
2418: */
2419: function quick_edit( $column_name, $post_type, $bulk=false) {
2420:
2421: if ($bulk) {
2422: static $eventpostprintNonceBulk = TRUE;
2423: if ($eventpostprintNonceBulk) {
2424: $eventpostprintNonceBulk = FALSE;
2425: }
2426: $fields = $this->bulk_edit_fields;
2427: echo '<input type="hidden" name="eventpost-bulk-editor" id="eventpost-bulk-editor" value="eventpost-bulk-editor">';
2428: }
2429: else {
2430: static $eventpostprintNonce = TRUE;
2431: if ($eventpostprintNonce) {
2432: $eventpostprintNonce = FALSE;
2433: }
2434: $fields = $this->quick_edit_fields;
2435: }
2436: wp_nonce_field(plugin_basename(__FILE__), 'eventpost_nonce');
2437: if(isset($fields[$column_name])): ?>
2438: <fieldset class="inline-edit-col-left inline-edit-<?php echo esc_attr($column_name); ?>">
2439: <div class="inline-edit-group">
2440: <?php foreach ($fields[$column_name] as $fieldname=>$fieldlabel): ?>
2441: <fieldset class="inline-edit-col inline-edit-<?php echo esc_attr($fieldname); ?>">
2442: <div class="inline-edit-col column-<?php echo esc_attr($fieldname); ?>">
2443: <label class="inline-edit-group">
2444: <span class="title"><?php echo esc_html($fieldlabel); ?></span>
2445: <span class="input-text-wrap">
2446: <?php echo wp_kses($this->inline_field($fieldname, $bulk), $this->kses_tags); ?>
2447: </span>
2448: </label>
2449: </div>
2450: </fieldset>
2451: <?php endforeach; ?>
2452: </div>
2453: </fieldset>
2454: <?php endif;
2455: }
2456:
2457: /**
2458: * Inline field in bulk edit
2459: *
2460: * @param type $fieldname
2461: *
2462: * @return string
2463: */
2464: function inline_field($fieldname, $bulk){
2465: return apply_filters('eventpost_inline_field', '<input name="'.esc_attr($fieldname).'" class="eventpost-inline-'.esc_attr($fieldname).'" value="" type="text">', $fieldname, $bulk);
2466: }
2467:
2468: function inline_field_color($html, $fieldname, $bulk){
2469: if($fieldname==$this->META_COLOR){
2470: $html='';
2471: if($bulk){
2472: $html.= '<span class="eventpost-bulk-colorpicker-button link">'.esc_html(__('No Change', 'event-post')).'</span>';
2473: }
2474: $html .= '
2475:
2476: <input class="eventpost-inline-colorpicker eventpost-inline-'.esc_attr($fieldname).' '.($bulk?'is-bulk':'no-bulk').'" type="color" name="'.esc_attr($fieldname).'" >';
2477: }
2478: return $html;
2479: }
2480: function inline_field_icon($html, $fieldname, $bulk){
2481: if($fieldname==$this->META_ICON){
2482: if($bulk){
2483: $html.= '<span class="eventpost-bulk-icon-button link">'.__('No Change', 'event-post').'</span>';
2484: }
2485: $html = '<select class="eventpost-inline-colorpicker eventpost-inline-'.$fieldname.' '.($bulk?'is-bulk':'no-bulk').'"
2486: type="text"
2487: name="'.$fieldname.'"
2488: style="font-family : dashicons">
2489: <option value="">'.__("None", 'event-post').'</option>';
2490: foreach($this->DashIcons->icons as $class => $unicode){
2491: $html .= '<option value="'.$class.'">&#x'.$unicode.'; '.$class.'</option>';
2492: }
2493: $html .= '</select>';
2494:
2495: }
2496: return $html;
2497: }
2498:
2499:
2500: /**
2501: * Bulk edit
2502: *
2503: * @param type $column_name
2504: * @param type $post_type
2505: */
2506: function bulk_edit($column_name, $post_type){
2507: $this->quick_edit($column_name, $post_type, true);
2508: }
2509:
2510: /**
2511: * Saves data from quick-edit via `wp_ajax_inline-save` action
2512: *
2513: * @return void
2514: */
2515: function inline_save(){
2516: $post_id = absint(filter_input(INPUT_POST, 'post_ID', FILTER_SANITIZE_NUMBER_INT));
2517: $this->save_postdata($post_id);
2518: }
2519: /**
2520: * When the post is saved, saves our custom data
2521: *
2522: * @param int $post_id
2523: *
2524: * @return void
2525: */
2526: public function save_postdata($post_id) {
2527: if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE){
2528: return;
2529: }
2530:
2531: if (!wp_verify_nonce((string) filter_input(INPUT_POST, 'eventpost_nonce'), plugin_basename(__FILE__))){
2532: return;
2533: }
2534:
2535: $post_id = absint($post_id);
2536: if (!$post_id || !current_user_can('edit_post', $post_id)) {
2537: return;
2538: }
2539:
2540: // Only a hexadecimal color (with or without "#") is stored, anything else clears the color.
2541: if (false !== $color = filter_input(INPUT_POST, $this->META_COLOR)) {
2542: $clean_color = sanitize_hex_color(trim((string) $color));
2543: if (null === $clean_color) {
2544: $clean_color = sanitize_hex_color_no_hash(trim((string) $color));
2545: }
2546: update_post_meta($post_id, $this->META_COLOR, (string) $clean_color);
2547: }
2548: // Clean color or no color
2549: if (false !== $icon = filter_input(INPUT_POST, $this->META_ICON)) {
2550: update_post_meta($post_id, $this->META_ICON, sanitize_text_field($icon));
2551: }
2552: if (false !== $attendance_mode = filter_input(INPUT_POST, $this->META_ATTENDANCE_MODE)) {
2553: update_post_meta($post_id, $this->META_ATTENDANCE_MODE, sanitize_text_field($attendance_mode));
2554: }
2555: if (false !== $status = filter_input(INPUT_POST, $this->META_STATUS)) {
2556: update_post_meta($post_id, $this->META_STATUS, sanitize_text_field($status));
2557: }
2558: $virtual_location = filter_input(INPUT_POST, $this->META_VIRTUAL_LOCATION, FILTER_SANITIZE_URL);
2559: if ($virtual_location !== null && $virtual_location !== false) {
2560: update_post_meta($post_id, $this->META_VIRTUAL_LOCATION, sanitize_url($virtual_location));
2561: }
2562: if (false !== $organization = filter_input(INPUT_POST, $this->META_ORGANIZATION)) {
2563: update_post_meta($post_id, $this->META_ORGANIZATION, sanitize_text_field($organization));
2564: }
2565: $offer_url = filter_input(INPUT_POST, "{$this->META_OFFER}_url", FILTER_SANITIZE_URL);
2566: $offer_price = filter_input(INPUT_POST, "{$this->META_OFFER}_price");
2567: $offer_currency = filter_input(INPUT_POST, "{$this->META_OFFER}_currency");
2568: if ($offer_url || ($offer_price && $offer_currency) ) {
2569: // Format floating
2570: $offer_price = $offer_price ? str_replace(',', '.', $offer_price) : null;
2571: update_post_meta($post_id, $this->META_OFFER, array(
2572: 'url' => $offer_url ? sanitize_text_field($offer_url) : null,
2573: 'price' => $offer_price ? (float) $offer_price : null,
2574: 'currency' => $offer_currency ? sanitize_text_field($offer_currency) : null,
2575: ));
2576: }
2577: else{
2578: delete_post_meta($post_id, $this->META_OFFER);
2579: }
2580: // Clean date or no date
2581: if ((false !== $start = filter_input(INPUT_POST, $this->META_START)) &&
2582: (false !== $end = filter_input(INPUT_POST, $this->META_END)) &&
2583: '' != $start &&
2584: '' != $end) {
2585: update_post_meta($post_id, $this->META_START, sanitize_text_field(substr($start,0,16).':00'));
2586: update_post_meta($post_id, $this->META_END, sanitize_text_field(substr($end,0,16).':00'));
2587: }
2588: else {
2589: delete_post_meta($post_id, $this->META_START);
2590: delete_post_meta($post_id, $this->META_END);
2591: }
2592:
2593: // Clean location or no location
2594: if ((false !== $lat = filter_input(INPUT_POST, $this->META_LAT)) &&
2595: (false !== $long = filter_input(INPUT_POST, $this->META_LONG)) &&
2596: '' != $lat &&
2597: '' != $long) {
2598: update_post_meta($post_id, $this->META_ADD, sanitize_text_field(filter_input(INPUT_POST, $this->META_ADD)));
2599: update_post_meta($post_id, $this->META_LAT, $this->sanitize_coordinate(sanitize_text_field($lat)));
2600: update_post_meta($post_id, $this->META_LONG, $this->sanitize_coordinate(sanitize_text_field($long)));
2601: }
2602: else {
2603: delete_post_meta($post_id, $this->META_ADD);
2604: delete_post_meta($post_id, $this->META_LAT);
2605: delete_post_meta($post_id, $this->META_LONG);
2606: }
2607:
2608: $post_ids = (!empty($_POST['post_ids']) ) ? $_POST['post_ids'] : array();
2609: }
2610:
2611: /**
2612: * Saves data from bulk-edit
2613: * Uses bulk_edit_posts hook
2614: *
2615: * @see https://developer.wordpress.org/reference/hooks/bulk_edit_posts/
2616: *
2617: * @return void
2618: */
2619: function save_bulkdatas(array $post_ids, array $shared_post_data) {
2620: if (!wp_verify_nonce(filter_input(INPUT_GET, 'eventpost_nonce'), plugin_basename(__FILE__))){
2621: return;
2622: }
2623: $current_post_type = isset($shared_post_data['post_type']) ? $shared_post_data['post_type'] : 'post';
2624: if (in_array($current_post_type, $this->settings['posttypes'])) {
2625: if (!empty($post_ids) && is_array($post_ids)) {
2626: foreach ($post_ids as $post_id) {
2627: if(! current_user_can( 'edit_post', $post_id )){
2628: continue;
2629: }
2630: foreach ($this->bulk_edit_fields as $sets) {
2631: foreach ($sets as $fieldname => $fieldlabel) {
2632: if (isset($shared_post_data[$fieldname])) {
2633: update_post_meta($post_id, $fieldname, $shared_post_data[$fieldname]);
2634: }
2635: }
2636: }
2637: }
2638: }
2639: }
2640: }
2641:
2642: /**
2643: * Displays a date for calendar cell
2644: *
2645: * @param string $date
2646: * @param string $cat
2647: * @param boolean $display
2648: *
2649: * @return boolean
2650: */
2651: public function display_caldate($date, $cat = '', $display = false, $colored=true, $thumbnail='', $title='',$tax_name='' ,$tax_term='') {
2652: $events = $this->get_events(array('nb' => -1, 'date' => $date, 'cat' => $cat, 'retreive' => true,'tax_name' => $tax_name ,'tax_term' => $tax_term));
2653: $nb = count($events);
2654: $ret = "";
2655: $price = "";
2656: if(!$display && !$nb){
2657: $ret = date('j', $date);
2658: }
2659: $price = '';
2660: if($nb){
2661: if ($display || $title) {
2662: $ret='<ul>';
2663: foreach ($events as $event) {
2664: $price = $this->get_price($event, true);
2665: if ($this->settings['emptylink'] == 0 && empty($event->post_content)) {
2666: $event->guid = '#';
2667: }
2668: $ret.='<li>'
2669: // Translators: %s is the event title
2670: . '<a href="' . $event->permalink . '" title="'.esc_attr(sprintf(__('View event: %s', 'event-post'), $event->post_title)).'">'
2671: . '<h4>' . $event->post_title . '</h4>'
2672: . '<span class="event_price">' . $price . '</span>'
2673: .$this->get_single($event)
2674: . (!empty($thumbnail) ? '<span class="event_thumbnail_wrap">' . get_the_post_thumbnail($event->ID, $thumbnail) . '</span>' : '')
2675: .'</a>'
2676: . '</li>';
2677: }
2678: $ret.='</ul>';
2679: }
2680: if ($display) {
2681: // return $ret;
2682: }
2683: elseif($title) {
2684: $ret = '<span '.($colored?' style="color:#'.$events[0]->color.'"':'').'>'.date('j', $date).'</span>'.$ret;
2685: }
2686: else {
2687: $ret = '<button data-event="'. $tax_term .'" data-date="' . date('Y-m-d', $date).'"'
2688: .' class="'.apply_filters( 'event_post_class_calendar_link', 'eventpost_cal_link' ).'"'.($colored?' style="background-color:#'.$events[0]->color.'"':'')
2689: // Translators: %1$d is the number of events, %2$s is the date
2690: .' title="'.esc_attr(sprintf(_n('View %1$d event at date %2$s', 'View %1$d events at date %2$s', $nb, 'event-post'), $nb, $this->human_date($date, $this->settings['dateformat']))).'"'
2691: .'>'
2692: . date('j', $date)
2693: . '</button>';
2694: }
2695: }
2696: return apply_filters('eventpost_display_caldate', $ret, $events, $date, $cat ,$price, $display ,$colored ,$thumbnail ,$title ,$tax_name ,$tax_term );
2697: }
2698:
2699:
2700: /**
2701: * Returns a calendar HTML
2702: *
2703: * @param array $atts
2704: *
2705: * @filter eventpost_params
2706: *
2707: * @return string
2708: */
2709: public function calendar($atts) {
2710: extract(shortcode_atts(apply_filters('eventpost_params', array(
2711: 'date' => date('Y-n'),
2712: 'cat' => '',
2713: 'mondayfirst' => 0, //1 : weeks starts on monday
2714: 'datepicker' => 1,
2715: 'colored' => 1,
2716: 'display_title'=>0,
2717: 'tax_name' => '',
2718: 'tax_term' => '',
2719: 'thumbnail'=>'',
2720: ), 'calendar'), $atts));
2721:
2722: if($date && !preg_match('#[0-9][0-9][0-9][0-9]-[0-9][0-9]?#i', $date)){
2723: $date = date('Y-n', strtotime($date));
2724: }
2725: if(!$date){
2726: $date = date('Y-n');
2727: }
2728:
2729: $annee = substr($date, 0, 4);
2730: $mois = substr($date, 5);
2731:
2732: $time = mktime(0, 0, 0, $mois, 1, $annee);
2733:
2734: $prev_year = strtotime('-1 Year', $time);
2735: $next_year = strtotime('+1 Year', $time);
2736: $prev_month = strtotime('-1 Month', $time);
2737: $next_month = strtotime('+1 Month', $time);
2738:
2739: $JourMax = date("t", $time);
2740: $NoJour = -date("w", $time);
2741: if ($mondayfirst == 0) {
2742: $NoJour +=1;
2743: } else {
2744: $NoJour +=2;
2745: $this->Week[] = array_shift($this->Week);
2746: }
2747: if ($NoJour > 0 && $mondayfirst == 1) {
2748: $NoJour -=7;
2749: }
2750: $ret = '<table class="event-post-calendar-table">'
2751: . '<caption class="screen-reader-text">'
2752: . __('A calendar of events', 'event-post')
2753: . '</caption>';
2754: $ret.='<thead><tr><th colspan="7">';
2755: if ($datepicker == 1) {
2756: $ret.='<div class="eventpost-calendar-header">';
2757: // Translators: %s is the year
2758: $ret.='<span class="eventpost-cal-year"><button data-date="' . date('Y-n', $prev_year) . '" tabindex="0" title="'.sprintf(__('Switch to %s', 'event-post'), date('Y', $prev_year)).'" class="eventpost_cal_bt eventpost-cal-bt-prev">&laquo;</button><span class="eventpost-cal-header-text">';
2759: $ret.=$annee;
2760: // Translators: %s is the year
2761: $ret.='</span><button data-date="' . date('Y-n', $next_year) . '" title="'.sprintf(__('Switch to %s', 'event-post'), date('Y', $next_year)).'" class="eventpost_cal_bt eventpost-cal-bt-next">&raquo;</button></span>';
2762: // Translators: %s is the month name
2763: $ret.='<span class="eventpost-cal-month"><button data-date="' . date('Y-n', $prev_month) . '" title="'.sprintf(__('Switch to %s', 'event-post'), date_i18n('F Y', $prev_month)).'" class="eventpost_cal_bt eventpost-cal-bt-prev eventpost-cal-bt-prev-month">&laquo;</button><span class="eventpost-cal-header-text">';
2764: $ret.=$this->NomDuMois[abs($mois)];
2765: // Translators: %s is the month name
2766: $ret.='</span><button data-date="' . date('Y-n', $next_month) . '" title="'.sprintf(__('Switch to %s', 'event-post'), date_i18n('F Y', $next_month)).'" class="eventpost_cal_bt eventpost-cal-bt-next eventpost-cal-bt-next-month">&raquo;</button> </span>';
2767: $ret.='<span class="eventpost-cal-today"><button data-date="' . date('Y-n') . '" class="eventpost_cal_bt">' . __('Today', 'event-post') . '</button></span>';
2768: $ret.='</div>';
2769: }
2770: $ret.='</th></tr><tr class="event_post_cal_days">';
2771: for ($w = 0; $w < 7; $w++) {
2772: $ret.='<th scope="col">' . strtoupper(substr($this->Week[$w], 0, 1)) . '</th>';
2773: }
2774: $ret.='</tr>';
2775: $ret.='</thead>';
2776:
2777: $ret.='<tbody>';
2778: $sqldate = date('Y-m', $time);
2779: $cejour = date('Y-m-d');
2780: for ($semaine = 0; $semaine <= 5; $semaine++) { // 6 semaines par mois
2781: $tr_row_content ='';
2782: for ($journee = 0; $journee <= 6; $journee++) { // 7 jours par semaine
2783: if ($NoJour > 0 && $NoJour <= $JourMax) { // si le jour est valide a afficher
2784: $td = '<td class="event_post_day">';
2785: if ($sqldate . '-' . ($NoJour<10?'0':'').$NoJour == $cejour) {
2786: $td = '<td class="event_post_day_now">';
2787: }
2788: if ($sqldate . '-' . ($NoJour<10?'0':'').$NoJour < $cejour){
2789: $td = '<td class="event_post_day_over">'; // Patch ahf
2790: }
2791: $tr_row_content.=$td;
2792: $tr_row_content.= $this->display_caldate(mktime(0, 0, 0, $mois, $NoJour, $annee), $cat, false, $colored, $thumbnail, $display_title ,$tax_name ,$tax_term);
2793: $tr_row_content.='</td>';
2794: } else {
2795: $tr_row_content.='<td></td>';
2796: }
2797: $NoJour ++;
2798: }
2799: if($tr_row_content){
2800: $ret.='<tr>'.$tr_row_content.'</tr>';
2801: }
2802:
2803: }
2804: $ret.='</tbody></table>';
2805: return $ret;
2806: }
2807:
2808: /**
2809: * Echoes a list of event, should be called via AJAX
2810: *
2811: * @return void
2812: */
2813: public function ajaxlist(){
2814: echo wp_kses($this->list_events(array(
2815: 'nb' => esc_attr(FILTER_INPUT(INPUT_POST, 'nb')),
2816: 'future' => esc_attr(FILTER_INPUT(INPUT_POST, 'future')),
2817: 'past' => esc_attr(FILTER_INPUT(INPUT_POST, 'past')),
2818: 'geo' => esc_attr(FILTER_INPUT(INPUT_POST, 'geo')),
2819: 'width' => esc_attr(FILTER_INPUT(INPUT_POST, 'width')),
2820: 'height' => esc_attr(FILTER_INPUT(INPUT_POST, 'height')),
2821: 'zoom' => esc_attr(FILTER_INPUT(INPUT_POST, 'zoom')),
2822: 'tile' => esc_attr(FILTER_INPUT(INPUT_POST, 'tile')),
2823: 'title' => esc_attr(FILTER_INPUT(INPUT_POST, 'title')),
2824: 'before_title' => esc_attr(FILTER_INPUT(INPUT_POST, 'before_title')),
2825: 'after_title' => esc_attr(FILTER_INPUT(INPUT_POST, 'after_title')),
2826: 'cat' => esc_attr(FILTER_INPUT(INPUT_POST, 'cat')),
2827: 'tag' => esc_attr(FILTER_INPUT(INPUT_POST, 'tag')),
2828: 'events' => esc_attr(FILTER_INPUT(INPUT_POST, 'events')),
2829: 'style' => esc_attr(FILTER_INPUT(INPUT_POST, 'style')),
2830: 'thumbnail' => esc_attr(FILTER_INPUT(INPUT_POST, 'thumbnail')),
2831: 'thumbnail_size' => esc_attr(FILTER_INPUT(INPUT_POST, 'thumbnail_size')),
2832: 'excerpt' => esc_attr(FILTER_INPUT(INPUT_POST, 'excerpt')),
2833: 'orderby' => esc_attr(FILTER_INPUT(INPUT_POST, 'orderby')),
2834: 'order' => esc_attr(FILTER_INPUT(INPUT_POST, 'order')),
2835: 'class' => esc_attr(FILTER_INPUT(INPUT_POST, 'class')),
2836: 'pages' => esc_attr(FILTER_INPUT(INPUT_POST, 'pages')),
2837: ), esc_attr(FILTER_INPUT(INPUT_POST, 'list_type'))), $this->kses_tags);
2838: exit;
2839: }
2840:
2841: /**
2842: * Echoes a list of event, should be called via AJAX
2843: *
2844: * @return void
2845: */
2846: public function ajaxTimeline(){
2847: echo wp_kses($this->list_events(array(
2848: 'nb' => esc_attr(FILTER_INPUT(INPUT_POST, 'nb')),
2849: 'future' => esc_attr(FILTER_INPUT(INPUT_POST, 'future')),
2850: 'past' => esc_attr(FILTER_INPUT(INPUT_POST, 'past')),
2851: 'geo' => esc_attr(FILTER_INPUT(INPUT_POST, 'geo')),
2852: 'width' => esc_attr(FILTER_INPUT(INPUT_POST, 'width')),
2853: 'height' => esc_attr(FILTER_INPUT(INPUT_POST, 'height')),
2854: 'zoom' => esc_attr(FILTER_INPUT(INPUT_POST, 'zoom')),
2855: 'tile' => esc_attr(FILTER_INPUT(INPUT_POST, 'tile')),
2856: 'title' => esc_attr(FILTER_INPUT(INPUT_POST, 'title')),
2857: 'before_title' => esc_attr(FILTER_INPUT(INPUT_POST, 'before_title')),
2858: 'after_title' => esc_attr(FILTER_INPUT(INPUT_POST, 'after_title')),
2859: 'cat' => esc_attr(FILTER_INPUT(INPUT_POST, 'cat')),
2860: 'tag' => esc_attr(FILTER_INPUT(INPUT_POST, 'tag')),
2861: 'events' => esc_attr(FILTER_INPUT(INPUT_POST, 'events')),
2862: 'style' => esc_attr(FILTER_INPUT(INPUT_POST, 'style')),
2863: 'thumbnail' => esc_attr(FILTER_INPUT(INPUT_POST, 'thumbnail')),
2864: 'thumbnail_size' => esc_attr(FILTER_INPUT(INPUT_POST, 'thumbnail_size')),
2865: 'excerpt' => esc_attr(FILTER_INPUT(INPUT_POST, 'excerpt')),
2866: 'orderby' => esc_attr(FILTER_INPUT(INPUT_POST, 'orderby')),
2867: 'order' => esc_attr(FILTER_INPUT(INPUT_POST, 'order')),
2868: 'class' => esc_attr(FILTER_INPUT(INPUT_POST, 'class')),
2869: 'pages' => esc_attr(FILTER_INPUT(INPUT_POST, 'pages')),
2870: ), esc_attr(FILTER_INPUT(INPUT_POST, 'list_type'))), $this->kses_tags);
2871: exit;
2872: }
2873: /**
2874: * Echoes next page of events, should be called via AJAX
2875: *
2876: * @return void
2877: */
2878: public function ajaxGetNextPage(){
2879: $response = [
2880: "success" => false,
2881: "next_query" => false,
2882: ];
2883: if(isset($_POST['query'])){
2884: parse_str($_POST['query'],$query);
2885: foreach($query as $key => $value){
2886: $query[$key] = esc_attr($value);
2887: }
2888: if(isset($_POST['paged'])){
2889: $query["paged"] = esc_attr($_POST['paged']);
2890: }else{
2891: $response['message'] = __('Page number missing', 'event-post');
2892: }
2893: $query['container_schema'] = $this->timeline_shema['container'];
2894: $query['item_schema'] = $this->timeline_shema['item'];
2895: $html = $this->list_events($query,'event_timeline','events_only');
2896: if($html == ""){
2897: $response['message'] = __('No more to load', 'event-post');
2898: }else{
2899: $query["paged"] = $query["paged"] + 1;
2900: $next_html = $this->list_events($query,'event_timeline','events_only');
2901: $response = [
2902: "success" => true,
2903: "html" => $html,
2904: "next_query" => $next_html == "" ? false : true,
2905: ];
2906: }
2907: }else{
2908: $response['message'] = __('Query missing', 'event-post');
2909: }
2910: wp_send_json($response);
2911: exit;
2912: }
2913:
2914: /**
2915: * Echoes the content of the calendar in ajax context
2916: *
2917: * @return void
2918: */
2919: public function ajaxcal() {
2920: $method = isset($_GET['action']) ? INPUT_GET : INPUT_POST;
2921: echo wp_kses($this->calendar(array(
2922: 'date' => esc_attr(FILTER_INPUT($method, 'date')),
2923: 'cat' => esc_attr(FILTER_INPUT($method, 'cat')),
2924: 'mondayfirst' => esc_attr(FILTER_INPUT($method, 'mf')),
2925: 'datepicker' => esc_attr(FILTER_INPUT($method, 'dp')),
2926: 'colored' => esc_attr(FILTER_INPUT($method, 'color')),
2927: 'display_title' => esc_attr(FILTER_INPUT($method, 'display_title')),
2928: 'thumbnail' => esc_attr(FILTER_INPUT($method, 'thumbnail')),
2929: 'tax_name' => esc_attr(FILTER_INPUT($method, 'tax_name')),
2930: 'tax_term' => esc_attr(FILTER_INPUT($method, 'tax_term')),
2931: )), $this->kses_tags);
2932: exit();
2933: }
2934:
2935: /**
2936: * Echoes the date of the calendar in ajax context
2937: */
2938: public function ajaxdate() {
2939: echo wp_kses($this->display_caldate(
2940: strtotime(esc_attr(FILTER_INPUT(INPUT_GET, 'date'))),
2941: esc_attr(FILTER_INPUT(INPUT_GET, 'cat')),
2942: true,
2943: esc_attr(FILTER_INPUT(INPUT_GET, 'color')),
2944: esc_attr(FILTER_INPUT(INPUT_GET, 'thumbnail')),
2945: esc_attr(FILTER_INPUT(INPUT_GET, 'display_title')),
2946: esc_attr(FILTER_INPUT(INPUT_GET, 'tax_name')),
2947: esc_attr(FILTER_INPUT(INPUT_GET, 'tax_term'))
2948: ), $this->kses_tags);
2949: exit();
2950: }
2951:
2952: /**
2953: * Echoes a date in ajax context
2954: */
2955: public function HumanDate() {
2956: if (isset($_REQUEST['date']) && !empty($_REQUEST['date'])) {
2957: $date = strtotime($_REQUEST['date']);
2958: echo esc_html($this->human_date($date, $this->settings['dateformat']).(date('H:i', $date)=='00:00' ? '' : ' '. date($this->settings['timeformat'], $date)));
2959: exit();
2960: }
2961: }
2962:
2963: /**
2964: * Displays a search form
2965: *
2966: * @param type $atts
2967: *
2968: * @return type
2969: */
2970: public function search($atts) {
2971: $params = shortcode_atts(apply_filters('eventpost_params', array(
2972: 'dates' => true,
2973: 'q' => true,
2974: 'tax' => false,
2975: ), 'search'), $atts);
2976: $this->list_id++;
2977:
2978: $list_id = $this->list_id;
2979: $q = (false !== $q = filter_input(INPUT_GET, 'q')) ? $q : '';
2980: $from = (false !== $from = filter_input(INPUT_GET, 'from')) ? $from : '';
2981: $to = (false !== $to = filter_input(INPUT_GET, 'to')) ? $to : '';
2982: $tax = (false !== $tax = filter_input(INPUT_GET, 'tax')) ? $tax : '';
2983:
2984: $cleaned_from = $this->date_cleanup($from);
2985: $cleaned_to = $this->date_cleanup($to);
2986: if(empty($cleaned_from)){
2987: $from=false;
2988: }
2989: if(empty($cleaned_to)){
2990: $to=false;
2991: }
2992:
2993: // Search form
2994: $this->admin_scripts(null, true);
2995: wp_enqueue_style('jquery-ui', plugins_url('/css/jquery-ui.css', __FILE__), false, filemtime( "/$block_js" ));
2996: include (plugin_dir_path(__FILE__) . 'views/search-form.php');
2997:
2998: // Results
2999: if ($list_id == filter_input(INPUT_GET, 'evenpost_search')) {
3000: $arg = array(
3001: 'post_type' => $this->settings['posttypes'],
3002: 'meta_key' => $this->META_START,
3003: 'orderby' => 'meta_value',
3004: 'order' => 'ASC',
3005: 's' => $q
3006: );
3007: if ($tax) {
3008: $arg['cat'] = $tax;
3009: }
3010:
3011: if ($from || $to) {
3012:
3013: $arg['meta_query'] = array();
3014: if ($from) {
3015: $arg['meta_query'][] = array(
3016: 'key' => $this->META_START,
3017: 'value' => $from,
3018: 'compare' => '>=',
3019: 'type' => 'DATETIME'
3020: );
3021: }
3022: if ($to) {
3023: $arg['meta_query'][] = $meta_query = array(
3024: array(
3025: 'key' => $this->META_END,
3026: 'value' => $to,
3027: 'compare' => '<=',
3028: 'type' => 'DATETIME'
3029: ),
3030: );
3031: }
3032: }
3033: $events = new WP_Query($arg);
3034: include (plugin_dir_path(__FILE__) . 'views/search-results.php');
3035: wp_reset_query();
3036: }
3037: }
3038:
3039: /**
3040: * Geocodes an address using OpenStreetMap Nominatim API and cache the result in a transient for 30 days
3041: *
3042: * @param string $address
3043: * @param boolean $single_result Whether to return only the first result or all results
3044: *
3045: * @return array|false|string The geocoding result(s) or false on failure
3046: */
3047: public function geocode(string $address, bool $single_result = false){
3048: $transient_name = 'eventpost_osquery_' . $address;
3049: $val = get_transient($transient_name);
3050: if (false === $val || empty($val) || !is_string($val)) {
3051: $language = get_bloginfo('language');
3052: if (strpos($language, '-') > -1) {
3053: $language = strtolower(substr($language, 0, 2));
3054: }
3055: $remote_val = wp_safe_remote_request('https://nominatim.openstreetmap.org/search?q=' . rawurlencode($address) . '&format=json&accept-language=' . $language, [
3056: 'user-agent' => getenv('HTTP_USER_AGENT') ?? 'WordPress/' . get_bloginfo('version') . '; ' . get_bloginfo('url'),
3057: 'headers' => [
3058: 'Referer' => get_bloginfo('url'),
3059: ],
3060: 'timeout' => 5,
3061: ]);
3062: $remote_body = wp_remote_retrieve_body($remote_val);
3063: if(strstr($remote_body, '<html>')){
3064: $val = [
3065: [
3066: 'lat' => '',
3067: 'lon' => '',
3068: 'display_name' => strip_tags($remote_body),
3069: ]
3070: ];
3071: }
3072: else{
3073: $val = json_decode($remote_body);
3074: if($val){
3075: set_transient($transient_name, $val, 30 * DAY_IN_SECONDS);
3076: }
3077: }
3078: }
3079: if($single_result && is_array($val) && count($val) > 0){
3080: $val = $val[0];
3081: }
3082: return $val;
3083: }
3084:
3085: /**
3086: * AJAX Get lat long from address
3087: */
3088: public function GetLatLong() {
3089: if (isset($_REQUEST['q']) && !empty($_REQUEST['q'])) {
3090: // verifier le cache
3091: $q = $_REQUEST['q'];
3092: header('Content-Type: application/json');
3093: $val = $this->geocode($q);
3094: wp_send_json( $val );
3095: exit();
3096: }
3097: }
3098:
3099: /**
3100: * Alters columns
3101: *
3102: * @param array $defaults
3103: *
3104: * @filter eventpost_columns_head
3105: *
3106: * @return array
3107: */
3108: public function columns_head($defaults) {
3109: $defaults['event'] = __('Event', 'event-post');
3110: $defaults['location'] = __('Location', 'event-post');
3111: return apply_filters('eventpost_columns_head', $defaults);
3112: }
3113:
3114: /**
3115: * Echoes content of a row in a given column
3116: *
3117: * @param string $column_name
3118: * @param int $post_id
3119: *
3120: * @action eventpost_columns_content
3121: */
3122: public function columns_content($column_name, $post_id) {
3123: if ($column_name == 'location') {
3124: $lat = $this->sanitize_coordinate(get_post_meta($post_id, $this->META_LAT, true));
3125: $lon = $this->sanitize_coordinate(get_post_meta($post_id, $this->META_LONG, true));
3126:
3127: if (!empty($lat) && !empty($lon)) {
3128: add_thickbox();
3129: $color = $this->get_post_color($post_id, $this->settings['default_color'], true);
3130: $icon = $this->get_post_icon($post_id, $this->settings['default_icon'], true);
3131: if ($color == ''){
3132: $color = '777777';
3133: }
3134: if ($icon == ''){
3135: $icon = 'location';
3136: }
3137: echo wp_kses( '<a href="https://www.openstreetmap.org/export/embed.html?bbox='.($lon-0.005).'%2C'.($lat-0.005).'%2C'.($lon+0.005).'%2C'.($lat+0.005).'&TB_iframe=true&width=600&height=550" class="thickbox" target="_blank">'
3138: . '<i class="dashicons dashicons-'.$icon.'" style="color:#'.$color.';"></i>'
3139: . '<span class="screen-reader-text">'.__('View on a map', 'event-post').'</span>'
3140: . get_post_meta($post_id, $this->META_ADD, true)
3141: . '</a> ', $this->kses_tags);
3142: }
3143: $this->column_edit_hidden_fields($post_id, 'location');
3144: }
3145: if ($column_name == 'event') {
3146: echo wp_kses($this->print_date($post_id, false), $this->kses_tags);
3147: $this->column_edit_hidden_fields($post_id, 'event');
3148: }
3149: do_action('eventpost_columns_content', $column_name, $post_id);
3150: }
3151:
3152: function column_edit_hidden_fields($post_id, $set){
3153: $event = $this->retreive($post_id);
3154: $html = '<div class="hidden">';
3155: if ($event != false){
3156: foreach($this->quick_edit_fields[$set] as $fieldname=>$fieldlabel){
3157: $html .= '<span class="inline-edit-value '.$fieldname.'">'.esc_attr($event->$fieldname).'</span>';
3158: }
3159: }
3160: $html .= '</div>';
3161: echo wp_kses($html, $this->kses_tags);
3162: }
3163:
3164: // ADMIN PAGES
3165:
3166: /**
3167: * Adds items to the native "right now" dashboard widget
3168: *
3169: * @param array $elements
3170: *
3171: * @return array
3172: */
3173: public function dashboard_right_now($elements){
3174: $nb_date = count($this->get_events(array('future'=>1, 'past'=>1, 'nb'=>-1)));
3175: $nb_geo = count($this->get_events(array('future'=>1, 'past'=>1, 'geo'=>1, 'nb'=>-1)));
3176: if($nb_date){
3177: // Translators: %d is the number of events
3178: array_push($elements, '<i class="dashicons dashicons-calendar"></i> <i href="edit.php?post_type=post">'.sprintf(__('%d Events','event-post'), $nb_date)."</i>");
3179: }
3180: if($nb_geo){
3181: // Translators: %d is the number of geolocalized events
3182: array_push($elements, '<i class="dashicons dashicons-location"></i> <i href="edit.php?post_type=post">'.sprintf(__('%d Geolocalized events','event-post'), $nb_geo)."</i>");
3183: }
3184: return $elements;
3185: }
3186:
3187: /*
3188: * Feed
3189: * generate ICS or VCS files from a category
3190: */
3191:
3192: /**
3193: * Get a date formatted for ICS
3194: *
3195: * @param timestamp $timestamp
3196: *
3197: * @return string
3198: */
3199: public function ics_date($timestamp){
3200: return date("Ymd",$timestamp).'T'.date("His",$timestamp);
3201: }
3202:
3203: public function get_gmt_offset(){
3204: $gmt_offset = get_option('gmt_offset ');
3205: $codegmt = 0;
3206: if ($gmt_offset != 0 && substr($gmt_offset, 0, 1) != '-' && substr($gmt_offset, 0, 1) != '+') {
3207: $codegmt = $gmt_offset * -1;
3208: $gmt_offset = '+' . $gmt_offset;
3209: }
3210: if(abs($gmt_offset < 10)){
3211: $gmt_offset = substr($gmt_offset, 0, 1).'0'.substr($gmt_offset, 1);
3212: }
3213: return $gmt_offset;
3214: }
3215:
3216: /**
3217: * Outputs an ICS or VCS file for a given event
3218: *
3219: * @param int $event_id
3220: * @param string $format
3221: *
3222: * @return void
3223: */
3224: private function generate_ics($event_id, $format){
3225: $allowed_formats = array('ics', 'vcs');
3226: $event_id = intval($event_id);
3227: $format = sanitize_text_field($format);
3228: if (in_array($format, $allowed_formats)) {
3229: $export_file = plugin_dir_path(__FILE__) . 'inc/export/' . $format . '.php';
3230: if (is_numeric($event_id) && file_exists($export_file)) {
3231: $event = $this->retreive($event_id);
3232: if($event->post_status != 'publish'){
3233: wp_die(esc_html__('Event not found.', 'event-post'), 404);
3234: }
3235: include $export_file;
3236: exit;
3237: }
3238: }
3239: wp_die(esc_html__('Invalid request.', 'event-post'), 400);
3240: }
3241:
3242:
3243: public function parse_request(){
3244: global $wp;
3245: if (preg_match('#^event-feed#i', $wp->request, $match)) {
3246: $this->feed();
3247: exit;
3248: }
3249: if (preg_match('#^eventpost/([0-9]*)\.(ics|vcs)#i', $wp->request, $match)) {
3250: $this->generate_ics($match[1], $match[2]);
3251: }
3252: }
3253:
3254: public function export(){
3255: if(false !== $event_id=\filter_input(INPUT_GET, 'event_id',FILTER_SANITIZE_NUMBER_INT)){
3256: $format = \filter_input(INPUT_GET, 'format');
3257: $this->generate_ics($event_id, $format);
3258: }
3259: }
3260:
3261:
3262: /**
3263: * Outputs an ICS document
3264: *
3265: * Filters can be applied to the criteria used to retrieve events in GET parameters:
3266: * - cat : category slug
3267: * - tag : tag slug
3268: * - tax_name : custom taxonomy name
3269: * - tax_term : custom taxonomy term slug
3270: * - nb : number of events to retrieve (default 10)
3271: * - future : retreive future events
3272: * - past : retreive past events
3273: *
3274: * @return void
3275: */
3276: public function feed(){
3277: $criteria = array(
3278: 'nb'=>10,
3279: );
3280: if(false !== $cat=\filter_input(INPUT_GET, 'cat')){
3281: $criteria['cat'] = sanitize_text_field($cat);
3282: }
3283: if(false !== $tag=\filter_input(INPUT_GET, 'tag')){
3284: $criteria['tag'] = sanitize_text_field($tag);
3285: }
3286: if(false !== $tax_name=\filter_input(INPUT_GET, 'tax_name')){
3287: $criteria['tax_name'] = sanitize_text_field($tax_name);
3288: }
3289: if(false !== $tax_term=\filter_input(INPUT_GET, 'tax_term')){
3290: $criteria['tax_term'] = sanitize_text_field($tax_term);
3291: }
3292: if(false !== $nb=\filter_input(INPUT_GET, 'nb', FILTER_SANITIZE_NUMBER_INT)){
3293: $criteria['nb'] = sanitize_text_field($nb);
3294: }
3295: if(false !== $future=\filter_input(INPUT_GET, 'future', FILTER_SANITIZE_NUMBER_INT)){
3296: $criteria['future'] = sanitize_text_field($future);
3297: }
3298: if(false !== $past=\filter_input(INPUT_GET, 'past', FILTER_SANITIZE_NUMBER_INT)){
3299: $criteria['past'] = sanitize_text_field($past);
3300: }
3301: $vtz = get_option('timezone_string');
3302: $gmt = $this->get_gmt_offset();
3303: date_default_timezone_set($vtz);
3304: $separator = "\n";
3305:
3306: header("content-type:text/calendar");
3307: header("Pragma: public");
3308: header("Expires: 0");
3309: header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
3310: header("Cache-Control: public");
3311: header("Content-Disposition: attachment; filename=". str_replace('+','-',rawurlencode(get_option('blogname').'-'.$cat)).".ics;" );
3312:
3313: $props = array();
3314:
3315: // General
3316: $props[] = 'BEGIN:VCALENDAR';
3317: $props[] = 'PRODID://WordPress//Event-Post-V'.$this->version.'//EN';
3318: $props[] = 'VERSION:2.0';
3319: // Timezone
3320: if(!empty($vtz)){
3321: array_push($props,
3322: 'BEGIN:VTIMEZONE',
3323: 'TZID:'.$vtz,
3324: 'BEGIN:DAYLIGHT',
3325: 'TZOFFSETFROM:+0100',
3326: 'TZOFFSETTO:'.($gmt).'00',
3327: 'DTSTART:19700329T020000',
3328: 'RRULE:FREQ=YEARLY;BYDAY=-1SU;BYMONTH=3',
3329: 'END:DAYLIGHT',
3330: 'BEGIN:STANDARD',
3331: 'TZOFFSETFROM:'.($gmt).'00',
3332: 'TZOFFSETTO:+0100',
3333: 'TZNAME:CET',
3334: 'DTSTART:19701025T030000',
3335: 'RRULE:FREQ=YEARLY;BYDAY=-1SU;BYMONTH=10',
3336: 'END:STANDARD',
3337: 'END:VTIMEZONE'
3338: );
3339: }
3340:
3341: // Events
3342: $events=$this->get_events($criteria);
3343: foreach ($events as $event) {
3344: if($event->time_start && $event->time_end){
3345: $description = wordwrap(
3346: str_replace(
3347: ['\\', ';', ',', "\r", "\n"],
3348: ['\\\\', '\;', '\,', '', '\n'],
3349: wp_strip_all_tags($event->description . "\n\n" . $event->permalink)
3350: ),
3351: 70,
3352: "\n ",
3353: true
3354: );
3355: array_push($props,
3356: 'BEGIN:VEVENT',
3357: 'CREATED:'.$this->ics_date(strtotime($event->post_date)).'Z',
3358: 'LAST-MODIFIED:'.$this->ics_date(strtotime($event->post_modified)).'Z',
3359: 'SUMMARY:'.$event->post_title,
3360: 'UID:'.md5(site_url()."_eventpost_".$event->ID),
3361: 'LOCATION:'.str_replace(',','\,',$event->address),
3362: 'DTSTAMP:'.$this->ics_date($event->time_start).(!empty($vtz)?'':'Z'),
3363: 'DTSTART'.(!empty($vtz)?';TZID='.$vtz:'').':'.$this->ics_date($event->time_start).(!empty($vtz)?'':'Z'),
3364: 'DTEND'.(!empty($vtz)?';TZID='.$vtz:'').':'.$this->ics_date($event->time_end).(!empty($vtz)?'':'Z'),
3365: 'DESCRIPTION:'.$description,
3366: 'END:VEVENT'
3367: );
3368: }
3369: }
3370:
3371: // End
3372: $props[] = 'END:VCALENDAR';
3373:
3374: echo esc_html(implode($separator, $props));
3375: exit;
3376: }
3377: }
3378: