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